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