1
2
3
4
5
6
7
8
9
10
11
12#ifndef __DRM_MIPI_DSI_H__
13#define __DRM_MIPI_DSI_H__
14
15#include <linux/device.h>
16
17struct mipi_dsi_host;
18struct mipi_dsi_device;
19
20
21#define MIPI_DSI_MSG_REQ_ACK BIT(0)
22
23#define MIPI_DSI_MSG_USE_LPM BIT(1)
24
25
26
27
28
29
30
31
32
33
34
35struct mipi_dsi_msg {
36 u8 channel;
37 u8 type;
38 u16 flags;
39
40 size_t tx_len;
41 const void *tx_buf;
42
43 size_t rx_len;
44 void *rx_buf;
45};
46
47bool mipi_dsi_packet_format_is_short(u8 type);
48bool mipi_dsi_packet_format_is_long(u8 type);
49
50
51
52
53
54
55
56
57
58struct mipi_dsi_packet {
59 size_t size;
60 u8 header[4];
61 size_t payload_length;
62 const u8 *payload;
63};
64
65int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
66 const struct mipi_dsi_msg *msg);
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86struct mipi_dsi_host_ops {
87 int (*attach)(struct mipi_dsi_host *host,
88 struct mipi_dsi_device *dsi);
89 int (*detach)(struct mipi_dsi_host *host,
90 struct mipi_dsi_device *dsi);
91 ssize_t (*transfer)(struct mipi_dsi_host *host,
92 const struct mipi_dsi_msg *msg);
93};
94
95
96
97
98
99
100
101struct mipi_dsi_host {
102 struct device *dev;
103 const struct mipi_dsi_host_ops *ops;
104 struct list_head list;
105};
106
107int mipi_dsi_host_register(struct mipi_dsi_host *host);
108void mipi_dsi_host_unregister(struct mipi_dsi_host *host);
109struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node);
110
111
112
113
114#define MIPI_DSI_MODE_VIDEO BIT(0)
115
116#define MIPI_DSI_MODE_VIDEO_BURST BIT(1)
117
118#define MIPI_DSI_MODE_VIDEO_SYNC_PULSE BIT(2)
119
120#define MIPI_DSI_MODE_VIDEO_AUTO_VERT BIT(3)
121
122#define MIPI_DSI_MODE_VIDEO_HSE BIT(4)
123
124#define MIPI_DSI_MODE_VIDEO_HFP BIT(5)
125
126#define MIPI_DSI_MODE_VIDEO_HBP BIT(6)
127
128#define MIPI_DSI_MODE_VIDEO_HSA BIT(7)
129
130#define MIPI_DSI_MODE_VSYNC_FLUSH BIT(8)
131
132#define MIPI_DSI_MODE_EOT_PACKET BIT(9)
133
134#define MIPI_DSI_CLOCK_NON_CONTINUOUS BIT(10)
135
136#define MIPI_DSI_MODE_LPM BIT(11)
137
138enum mipi_dsi_pixel_format {
139 MIPI_DSI_FMT_RGB888,
140 MIPI_DSI_FMT_RGB666,
141 MIPI_DSI_FMT_RGB666_PACKED,
142 MIPI_DSI_FMT_RGB565,
143};
144
145#define DSI_DEV_NAME_SIZE 20
146
147
148
149
150
151
152
153
154
155
156struct mipi_dsi_device_info {
157 char type[DSI_DEV_NAME_SIZE];
158 u32 channel;
159 struct device_node *node;
160};
161
162
163
164
165
166
167
168
169
170
171
172struct mipi_dsi_device {
173 struct mipi_dsi_host *host;
174 struct device dev;
175
176 char name[DSI_DEV_NAME_SIZE];
177 unsigned int channel;
178 unsigned int lanes;
179 enum mipi_dsi_pixel_format format;
180 unsigned long mode_flags;
181};
182
183#define MIPI_DSI_MODULE_PREFIX "mipi-dsi:"
184
185static inline struct mipi_dsi_device *to_mipi_dsi_device(struct device *dev)
186{
187 return container_of(dev, struct mipi_dsi_device, dev);
188}
189
190
191
192
193
194
195
196
197
198static inline int mipi_dsi_pixel_format_to_bpp(enum mipi_dsi_pixel_format fmt)
199{
200 switch (fmt) {
201 case MIPI_DSI_FMT_RGB888:
202 case MIPI_DSI_FMT_RGB666:
203 return 24;
204
205 case MIPI_DSI_FMT_RGB666_PACKED:
206 return 18;
207
208 case MIPI_DSI_FMT_RGB565:
209 return 16;
210 }
211
212 return -EINVAL;
213}
214
215struct mipi_dsi_device *
216mipi_dsi_device_register_full(struct mipi_dsi_host *host,
217 const struct mipi_dsi_device_info *info);
218void mipi_dsi_device_unregister(struct mipi_dsi_device *dsi);
219struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np);
220int mipi_dsi_attach(struct mipi_dsi_device *dsi);
221int mipi_dsi_detach(struct mipi_dsi_device *dsi);
222int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi);
223int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi);
224int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
225 u16 value);
226
227ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
228 size_t size);
229ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
230 size_t num_params, void *data, size_t size);
231
232
233
234
235
236
237
238
239enum mipi_dsi_dcs_tear_mode {
240 MIPI_DSI_DCS_TEAR_MODE_VBLANK,
241 MIPI_DSI_DCS_TEAR_MODE_VHBLANK,
242};
243
244#define MIPI_DSI_DCS_POWER_MODE_DISPLAY (1 << 2)
245#define MIPI_DSI_DCS_POWER_MODE_NORMAL (1 << 3)
246#define MIPI_DSI_DCS_POWER_MODE_SLEEP (1 << 4)
247#define MIPI_DSI_DCS_POWER_MODE_PARTIAL (1 << 5)
248#define MIPI_DSI_DCS_POWER_MODE_IDLE (1 << 6)
249
250ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
251 const void *data, size_t len);
252ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
253 const void *data, size_t len);
254ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
255 size_t len);
256int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi);
257int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi);
258int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode);
259int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format);
260int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi);
261int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi);
262int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi);
263int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi);
264int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
265 u16 end);
266int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
267 u16 end);
268int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi);
269int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
270 enum mipi_dsi_dcs_tear_mode mode);
271int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format);
272int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline);
273int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi,
274 u16 brightness);
275int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
276 u16 *brightness);
277
278
279
280
281
282
283
284
285struct mipi_dsi_driver {
286 struct device_driver driver;
287 int(*probe)(struct mipi_dsi_device *dsi);
288 int(*remove)(struct mipi_dsi_device *dsi);
289 void (*shutdown)(struct mipi_dsi_device *dsi);
290};
291
292static inline struct mipi_dsi_driver *
293to_mipi_dsi_driver(struct device_driver *driver)
294{
295 return container_of(driver, struct mipi_dsi_driver, driver);
296}
297
298static inline void *mipi_dsi_get_drvdata(const struct mipi_dsi_device *dsi)
299{
300 return dev_get_drvdata(&dsi->dev);
301}
302
303static inline void mipi_dsi_set_drvdata(struct mipi_dsi_device *dsi, void *data)
304{
305 dev_set_drvdata(&dsi->dev, data);
306}
307
308int mipi_dsi_driver_register_full(struct mipi_dsi_driver *driver,
309 struct module *owner);
310void mipi_dsi_driver_unregister(struct mipi_dsi_driver *driver);
311
312#define mipi_dsi_driver_register(driver) \
313 mipi_dsi_driver_register_full(driver, THIS_MODULE)
314
315#define module_mipi_dsi_driver(__mipi_dsi_driver) \
316 module_driver(__mipi_dsi_driver, mipi_dsi_driver_register, \
317 mipi_dsi_driver_unregister)
318
319#endif
320