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