Andrzej Hajda | 068a002 | 2013-12-04 16:35:12 +0100 | [diff] [blame] | 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 | |
Andrzej Hajda | 1d96d4a | 2014-03-28 12:52:36 +0100 | [diff] [blame] | 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 | |
Andrzej Hajda | 068a002 | 2013-12-04 16:35:12 +0100 | [diff] [blame] | 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; |
Andrzej Hajda | 1d96d4a | 2014-03-28 12:52:36 +0100 | [diff] [blame] | 37 | u16 flags; |
Andrzej Hajda | 068a002 | 2013-12-04 16:35:12 +0100 | [diff] [blame] | 38 | |
| 39 | size_t tx_len; |
| 40 | const void *tx_buf; |
| 41 | |
| 42 | size_t rx_len; |
| 43 | void *rx_buf; |
| 44 | }; |
| 45 | |
Thierry Reding | 02acb76 | 2014-11-04 14:59:14 +0100 | [diff] [blame] | 46 | bool mipi_dsi_packet_format_is_short(u8 type); |
| 47 | bool mipi_dsi_packet_format_is_long(u8 type); |
| 48 | |
Andrzej Hajda | 068a002 | 2013-12-04 16:35:12 +0100 | [diff] [blame] | 49 | /** |
Thierry Reding | a52879e | 2014-10-16 13:44:02 +0200 | [diff] [blame^] | 50 | * struct mipi_dsi_packet - represents a MIPI DSI packet in protocol format |
| 51 | * @size: size (in bytes) of the packet |
| 52 | * @header: the four bytes that make up the header (Data ID, Word Count or |
| 53 | * Packet Data, and ECC) |
| 54 | * @payload_length: number of bytes in the payload |
| 55 | * @payload: a pointer to a buffer containing the payload, if any |
| 56 | */ |
| 57 | struct mipi_dsi_packet { |
| 58 | size_t size; |
| 59 | u8 header[4]; |
| 60 | size_t payload_length; |
| 61 | const u8 *payload; |
| 62 | }; |
| 63 | |
| 64 | int mipi_dsi_create_packet(struct mipi_dsi_packet *packet, |
| 65 | const struct mipi_dsi_msg *msg); |
| 66 | |
| 67 | /** |
Andrzej Hajda | 068a002 | 2013-12-04 16:35:12 +0100 | [diff] [blame] | 68 | * struct mipi_dsi_host_ops - DSI bus operations |
| 69 | * @attach: attach DSI device to DSI host |
| 70 | * @detach: detach DSI device from DSI host |
| 71 | * @transfer: send and/or receive DSI packet, return number of received bytes, |
| 72 | * or error |
| 73 | */ |
| 74 | struct mipi_dsi_host_ops { |
| 75 | int (*attach)(struct mipi_dsi_host *host, |
| 76 | struct mipi_dsi_device *dsi); |
| 77 | int (*detach)(struct mipi_dsi_host *host, |
| 78 | struct mipi_dsi_device *dsi); |
| 79 | ssize_t (*transfer)(struct mipi_dsi_host *host, |
| 80 | struct mipi_dsi_msg *msg); |
| 81 | }; |
| 82 | |
| 83 | /** |
| 84 | * struct mipi_dsi_host - DSI host device |
| 85 | * @dev: driver model device node for this DSI host |
| 86 | * @ops: DSI host operations |
| 87 | */ |
| 88 | struct mipi_dsi_host { |
| 89 | struct device *dev; |
| 90 | const struct mipi_dsi_host_ops *ops; |
| 91 | }; |
| 92 | |
| 93 | int mipi_dsi_host_register(struct mipi_dsi_host *host); |
| 94 | void mipi_dsi_host_unregister(struct mipi_dsi_host *host); |
| 95 | |
| 96 | /* DSI mode flags */ |
| 97 | |
| 98 | /* video mode */ |
| 99 | #define MIPI_DSI_MODE_VIDEO BIT(0) |
| 100 | /* video burst mode */ |
| 101 | #define MIPI_DSI_MODE_VIDEO_BURST BIT(1) |
| 102 | /* video pulse mode */ |
| 103 | #define MIPI_DSI_MODE_VIDEO_SYNC_PULSE BIT(2) |
| 104 | /* enable auto vertical count mode */ |
| 105 | #define MIPI_DSI_MODE_VIDEO_AUTO_VERT BIT(3) |
| 106 | /* enable hsync-end packets in vsync-pulse and v-porch area */ |
| 107 | #define MIPI_DSI_MODE_VIDEO_HSE BIT(4) |
| 108 | /* disable hfront-porch area */ |
| 109 | #define MIPI_DSI_MODE_VIDEO_HFP BIT(5) |
| 110 | /* disable hback-porch area */ |
| 111 | #define MIPI_DSI_MODE_VIDEO_HBP BIT(6) |
| 112 | /* disable hsync-active area */ |
| 113 | #define MIPI_DSI_MODE_VIDEO_HSA BIT(7) |
| 114 | /* flush display FIFO on vsync pulse */ |
| 115 | #define MIPI_DSI_MODE_VSYNC_FLUSH BIT(8) |
| 116 | /* disable EoT packets in HS mode */ |
| 117 | #define MIPI_DSI_MODE_EOT_PACKET BIT(9) |
Alexandre Courbot | 884d6a0 | 2014-07-08 21:32:11 +0900 | [diff] [blame] | 118 | /* device supports non-continuous clock behavior (DSI spec 5.6.1) */ |
| 119 | #define MIPI_DSI_CLOCK_NON_CONTINUOUS BIT(10) |
Inki Dae | d87f09a | 2014-08-13 16:38:23 +0900 | [diff] [blame] | 120 | /* transmit data in low power */ |
| 121 | #define MIPI_DSI_MODE_LPM BIT(11) |
Andrzej Hajda | 068a002 | 2013-12-04 16:35:12 +0100 | [diff] [blame] | 122 | |
| 123 | enum mipi_dsi_pixel_format { |
| 124 | MIPI_DSI_FMT_RGB888, |
| 125 | MIPI_DSI_FMT_RGB666, |
| 126 | MIPI_DSI_FMT_RGB666_PACKED, |
| 127 | MIPI_DSI_FMT_RGB565, |
| 128 | }; |
| 129 | |
| 130 | /** |
| 131 | * struct mipi_dsi_device - DSI peripheral device |
| 132 | * @host: DSI host for this peripheral |
| 133 | * @dev: driver model device node for this peripheral |
| 134 | * @channel: virtual channel assigned to the peripheral |
| 135 | * @format: pixel format for video mode |
| 136 | * @lanes: number of active data lanes |
| 137 | * @mode_flags: DSI operation mode related flags |
| 138 | */ |
| 139 | struct mipi_dsi_device { |
| 140 | struct mipi_dsi_host *host; |
| 141 | struct device dev; |
| 142 | |
| 143 | unsigned int channel; |
| 144 | unsigned int lanes; |
| 145 | enum mipi_dsi_pixel_format format; |
| 146 | unsigned long mode_flags; |
| 147 | }; |
| 148 | |
Thierry Reding | 77df01d | 2014-08-05 09:01:32 +0200 | [diff] [blame] | 149 | static inline struct mipi_dsi_device *to_mipi_dsi_device(struct device *dev) |
| 150 | { |
| 151 | return container_of(dev, struct mipi_dsi_device, dev); |
| 152 | } |
Andrzej Hajda | 068a002 | 2013-12-04 16:35:12 +0100 | [diff] [blame] | 153 | |
| 154 | int mipi_dsi_attach(struct mipi_dsi_device *dsi); |
| 155 | int mipi_dsi_detach(struct mipi_dsi_device *dsi); |
Thierry Reding | 3c523d7 | 2014-07-21 12:28:25 +0200 | [diff] [blame] | 156 | ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, const void *data, |
| 157 | size_t len); |
| 158 | ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data, |
| 159 | size_t len); |
Andrzej Hajda | 068a002 | 2013-12-04 16:35:12 +0100 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * struct mipi_dsi_driver - DSI driver |
| 163 | * @driver: device driver model driver |
| 164 | * @probe: callback for device binding |
| 165 | * @remove: callback for device unbinding |
Thierry Reding | d162180 | 2014-04-29 17:19:57 +0200 | [diff] [blame] | 166 | * @shutdown: called at shutdown time to quiesce the device |
Andrzej Hajda | 068a002 | 2013-12-04 16:35:12 +0100 | [diff] [blame] | 167 | */ |
| 168 | struct mipi_dsi_driver { |
| 169 | struct device_driver driver; |
| 170 | int(*probe)(struct mipi_dsi_device *dsi); |
| 171 | int(*remove)(struct mipi_dsi_device *dsi); |
Thierry Reding | d162180 | 2014-04-29 17:19:57 +0200 | [diff] [blame] | 172 | void (*shutdown)(struct mipi_dsi_device *dsi); |
Andrzej Hajda | 068a002 | 2013-12-04 16:35:12 +0100 | [diff] [blame] | 173 | }; |
| 174 | |
Thierry Reding | 77df01d | 2014-08-05 09:01:32 +0200 | [diff] [blame] | 175 | static inline struct mipi_dsi_driver * |
| 176 | to_mipi_dsi_driver(struct device_driver *driver) |
| 177 | { |
| 178 | return container_of(driver, struct mipi_dsi_driver, driver); |
| 179 | } |
Andrzej Hajda | 068a002 | 2013-12-04 16:35:12 +0100 | [diff] [blame] | 180 | |
| 181 | static inline void *mipi_dsi_get_drvdata(const struct mipi_dsi_device *dsi) |
| 182 | { |
| 183 | return dev_get_drvdata(&dsi->dev); |
| 184 | } |
| 185 | |
| 186 | static inline void mipi_dsi_set_drvdata(struct mipi_dsi_device *dsi, void *data) |
| 187 | { |
| 188 | dev_set_drvdata(&dsi->dev, data); |
| 189 | } |
| 190 | |
| 191 | int mipi_dsi_driver_register(struct mipi_dsi_driver *driver); |
| 192 | void mipi_dsi_driver_unregister(struct mipi_dsi_driver *driver); |
| 193 | |
| 194 | #define module_mipi_dsi_driver(__mipi_dsi_driver) \ |
| 195 | module_driver(__mipi_dsi_driver, mipi_dsi_driver_register, \ |
| 196 | mipi_dsi_driver_unregister) |
| 197 | |
| 198 | #endif /* __DRM_MIPI_DSI__ */ |