xref: /openbmc/linux/include/drm/drm_mipi_dsi.h (revision 8a10bc9d)
1 /*
2  * MIPI DSI Bus
3  *
4  * Copyright (C) 2012-2013, Samsung Electronics, Co., Ltd.
5  * Andrzej Hajda <a.hajda@samsung.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11 
12 #ifndef __DRM_MIPI_DSI_H__
13 #define __DRM_MIPI_DSI_H__
14 
15 #include <linux/device.h>
16 
17 struct mipi_dsi_host;
18 struct mipi_dsi_device;
19 
20 /**
21  * struct mipi_dsi_msg - read/write DSI buffer
22  * @channel: virtual channel id
23  * @type: payload data type
24  * @tx_len: length of @tx_buf
25  * @tx_buf: data to be written
26  * @rx_len: length of @rx_buf
27  * @rx_buf: data to be read, or NULL
28  */
29 struct mipi_dsi_msg {
30 	u8 channel;
31 	u8 type;
32 
33 	size_t tx_len;
34 	const void *tx_buf;
35 
36 	size_t rx_len;
37 	void *rx_buf;
38 };
39 
40 /**
41  * struct mipi_dsi_host_ops - DSI bus operations
42  * @attach: attach DSI device to DSI host
43  * @detach: detach DSI device from DSI host
44  * @transfer: send and/or receive DSI packet, return number of received bytes,
45  * 	      or error
46  */
47 struct mipi_dsi_host_ops {
48 	int (*attach)(struct mipi_dsi_host *host,
49 		      struct mipi_dsi_device *dsi);
50 	int (*detach)(struct mipi_dsi_host *host,
51 		      struct mipi_dsi_device *dsi);
52 	ssize_t (*transfer)(struct mipi_dsi_host *host,
53 			    struct mipi_dsi_msg *msg);
54 };
55 
56 /**
57  * struct mipi_dsi_host - DSI host device
58  * @dev: driver model device node for this DSI host
59  * @ops: DSI host operations
60  */
61 struct mipi_dsi_host {
62 	struct device *dev;
63 	const struct mipi_dsi_host_ops *ops;
64 };
65 
66 int mipi_dsi_host_register(struct mipi_dsi_host *host);
67 void mipi_dsi_host_unregister(struct mipi_dsi_host *host);
68 
69 /* DSI mode flags */
70 
71 /* video mode */
72 #define MIPI_DSI_MODE_VIDEO		BIT(0)
73 /* video burst mode */
74 #define MIPI_DSI_MODE_VIDEO_BURST	BIT(1)
75 /* video pulse mode */
76 #define MIPI_DSI_MODE_VIDEO_SYNC_PULSE	BIT(2)
77 /* enable auto vertical count mode */
78 #define MIPI_DSI_MODE_VIDEO_AUTO_VERT	BIT(3)
79 /* enable hsync-end packets in vsync-pulse and v-porch area */
80 #define MIPI_DSI_MODE_VIDEO_HSE		BIT(4)
81 /* disable hfront-porch area */
82 #define MIPI_DSI_MODE_VIDEO_HFP		BIT(5)
83 /* disable hback-porch area */
84 #define MIPI_DSI_MODE_VIDEO_HBP		BIT(6)
85 /* disable hsync-active area */
86 #define MIPI_DSI_MODE_VIDEO_HSA		BIT(7)
87 /* flush display FIFO on vsync pulse */
88 #define MIPI_DSI_MODE_VSYNC_FLUSH	BIT(8)
89 /* disable EoT packets in HS mode */
90 #define MIPI_DSI_MODE_EOT_PACKET	BIT(9)
91 
92 enum mipi_dsi_pixel_format {
93 	MIPI_DSI_FMT_RGB888,
94 	MIPI_DSI_FMT_RGB666,
95 	MIPI_DSI_FMT_RGB666_PACKED,
96 	MIPI_DSI_FMT_RGB565,
97 };
98 
99 /**
100  * struct mipi_dsi_device - DSI peripheral device
101  * @host: DSI host for this peripheral
102  * @dev: driver model device node for this peripheral
103  * @channel: virtual channel assigned to the peripheral
104  * @format: pixel format for video mode
105  * @lanes: number of active data lanes
106  * @mode_flags: DSI operation mode related flags
107  */
108 struct mipi_dsi_device {
109 	struct mipi_dsi_host *host;
110 	struct device dev;
111 
112 	unsigned int channel;
113 	unsigned int lanes;
114 	enum mipi_dsi_pixel_format format;
115 	unsigned long mode_flags;
116 };
117 
118 #define to_mipi_dsi_device(d) container_of(d, struct mipi_dsi_device, dev)
119 
120 int mipi_dsi_attach(struct mipi_dsi_device *dsi);
121 int mipi_dsi_detach(struct mipi_dsi_device *dsi);
122 int mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, unsigned int channel,
123 		       const void *data, size_t len);
124 ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, unsigned int channel,
125 			  u8 cmd, void *data, size_t len);
126 
127 /**
128  * struct mipi_dsi_driver - DSI driver
129  * @driver: device driver model driver
130  * @probe: callback for device binding
131  * @remove: callback for device unbinding
132  */
133 struct mipi_dsi_driver {
134 	struct device_driver driver;
135 	int(*probe)(struct mipi_dsi_device *dsi);
136 	int(*remove)(struct mipi_dsi_device *dsi);
137 };
138 
139 #define to_mipi_dsi_driver(d) container_of(d, struct mipi_dsi_driver, driver)
140 
141 static inline void *mipi_dsi_get_drvdata(const struct mipi_dsi_device *dsi)
142 {
143 	return dev_get_drvdata(&dsi->dev);
144 }
145 
146 static inline void mipi_dsi_set_drvdata(struct mipi_dsi_device *dsi, void *data)
147 {
148 	dev_set_drvdata(&dsi->dev, data);
149 }
150 
151 int mipi_dsi_driver_register(struct mipi_dsi_driver *driver);
152 void mipi_dsi_driver_unregister(struct mipi_dsi_driver *driver);
153 
154 #define module_mipi_dsi_driver(__mipi_dsi_driver) \
155 	module_driver(__mipi_dsi_driver, mipi_dsi_driver_register, \
156 			mipi_dsi_driver_unregister)
157 
158 #endif /* __DRM_MIPI_DSI__ */
159