Merge branch 'exynos-drm-next' of git://git.kernel.org/pub/scm/linux/kernel/git/daein...
[cascardo/linux.git] / include / drm / drm_mipi_dsi.h
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 /* request ACK from peripheral */
21 #define MIPI_DSI_MSG_REQ_ACK    BIT(0)
22 /* use Low Power Mode to transmit message */
23 #define MIPI_DSI_MSG_USE_LPM    BIT(1)
24
25 /**
26  * struct mipi_dsi_msg - read/write DSI buffer
27  * @channel: virtual channel id
28  * @type: payload data type
29  * @tx_len: length of @tx_buf
30  * @tx_buf: data to be written
31  * @rx_len: length of @rx_buf
32  * @rx_buf: data to be read, or NULL
33  */
34 struct mipi_dsi_msg {
35         u8 channel;
36         u8 type;
37         u16 flags;
38
39         size_t tx_len;
40         const void *tx_buf;
41
42         size_t rx_len;
43         void *rx_buf;
44 };
45
46 /**
47  * struct mipi_dsi_host_ops - DSI bus operations
48  * @attach: attach DSI device to DSI host
49  * @detach: detach DSI device from DSI host
50  * @transfer: send and/or receive DSI packet, return number of received bytes,
51  *            or error
52  */
53 struct mipi_dsi_host_ops {
54         int (*attach)(struct mipi_dsi_host *host,
55                       struct mipi_dsi_device *dsi);
56         int (*detach)(struct mipi_dsi_host *host,
57                       struct mipi_dsi_device *dsi);
58         ssize_t (*transfer)(struct mipi_dsi_host *host,
59                             struct mipi_dsi_msg *msg);
60 };
61
62 /**
63  * struct mipi_dsi_host - DSI host device
64  * @dev: driver model device node for this DSI host
65  * @ops: DSI host operations
66  */
67 struct mipi_dsi_host {
68         struct device *dev;
69         const struct mipi_dsi_host_ops *ops;
70 };
71
72 int mipi_dsi_host_register(struct mipi_dsi_host *host);
73 void mipi_dsi_host_unregister(struct mipi_dsi_host *host);
74
75 /* DSI mode flags */
76
77 /* video mode */
78 #define MIPI_DSI_MODE_VIDEO             BIT(0)
79 /* video burst mode */
80 #define MIPI_DSI_MODE_VIDEO_BURST       BIT(1)
81 /* video pulse mode */
82 #define MIPI_DSI_MODE_VIDEO_SYNC_PULSE  BIT(2)
83 /* enable auto vertical count mode */
84 #define MIPI_DSI_MODE_VIDEO_AUTO_VERT   BIT(3)
85 /* enable hsync-end packets in vsync-pulse and v-porch area */
86 #define MIPI_DSI_MODE_VIDEO_HSE         BIT(4)
87 /* disable hfront-porch area */
88 #define MIPI_DSI_MODE_VIDEO_HFP         BIT(5)
89 /* disable hback-porch area */
90 #define MIPI_DSI_MODE_VIDEO_HBP         BIT(6)
91 /* disable hsync-active area */
92 #define MIPI_DSI_MODE_VIDEO_HSA         BIT(7)
93 /* flush display FIFO on vsync pulse */
94 #define MIPI_DSI_MODE_VSYNC_FLUSH       BIT(8)
95 /* disable EoT packets in HS mode */
96 #define MIPI_DSI_MODE_EOT_PACKET        BIT(9)
97 /* device supports non-continuous clock behavior (DSI spec 5.6.1) */
98 #define MIPI_DSI_CLOCK_NON_CONTINUOUS   BIT(10)
99 /* transmit data in low power */
100 #define MIPI_DSI_MODE_LPM               BIT(11)
101
102 enum mipi_dsi_pixel_format {
103         MIPI_DSI_FMT_RGB888,
104         MIPI_DSI_FMT_RGB666,
105         MIPI_DSI_FMT_RGB666_PACKED,
106         MIPI_DSI_FMT_RGB565,
107 };
108
109 /**
110  * struct mipi_dsi_device - DSI peripheral device
111  * @host: DSI host for this peripheral
112  * @dev: driver model device node for this peripheral
113  * @channel: virtual channel assigned to the peripheral
114  * @format: pixel format for video mode
115  * @lanes: number of active data lanes
116  * @mode_flags: DSI operation mode related flags
117  */
118 struct mipi_dsi_device {
119         struct mipi_dsi_host *host;
120         struct device dev;
121
122         unsigned int channel;
123         unsigned int lanes;
124         enum mipi_dsi_pixel_format format;
125         unsigned long mode_flags;
126 };
127
128 static inline struct mipi_dsi_device *to_mipi_dsi_device(struct device *dev)
129 {
130         return container_of(dev, struct mipi_dsi_device, dev);
131 }
132
133 int mipi_dsi_attach(struct mipi_dsi_device *dsi);
134 int mipi_dsi_detach(struct mipi_dsi_device *dsi);
135 ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, const void *data,
136                             size_t len);
137 ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
138                           size_t len);
139
140 /**
141  * struct mipi_dsi_driver - DSI driver
142  * @driver: device driver model driver
143  * @probe: callback for device binding
144  * @remove: callback for device unbinding
145  * @shutdown: called at shutdown time to quiesce the device
146  */
147 struct mipi_dsi_driver {
148         struct device_driver driver;
149         int(*probe)(struct mipi_dsi_device *dsi);
150         int(*remove)(struct mipi_dsi_device *dsi);
151         void (*shutdown)(struct mipi_dsi_device *dsi);
152 };
153
154 static inline struct mipi_dsi_driver *
155 to_mipi_dsi_driver(struct device_driver *driver)
156 {
157         return container_of(driver, struct mipi_dsi_driver, driver);
158 }
159
160 static inline void *mipi_dsi_get_drvdata(const struct mipi_dsi_device *dsi)
161 {
162         return dev_get_drvdata(&dsi->dev);
163 }
164
165 static inline void mipi_dsi_set_drvdata(struct mipi_dsi_device *dsi, void *data)
166 {
167         dev_set_drvdata(&dsi->dev, data);
168 }
169
170 int mipi_dsi_driver_register(struct mipi_dsi_driver *driver);
171 void mipi_dsi_driver_unregister(struct mipi_dsi_driver *driver);
172
173 #define module_mipi_dsi_driver(__mipi_dsi_driver) \
174         module_driver(__mipi_dsi_driver, mipi_dsi_driver_register, \
175                         mipi_dsi_driver_unregister)
176
177 #endif /* __DRM_MIPI_DSI__ */