1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2068a0023SAndrzej Hajda /*
3068a0023SAndrzej Hajda * MIPI DSI Bus
4068a0023SAndrzej Hajda *
5068a0023SAndrzej Hajda * Copyright (C) 2012-2013, Samsung Electronics, Co., Ltd.
6068a0023SAndrzej Hajda * Andrzej Hajda <a.hajda@samsung.com>
7068a0023SAndrzej Hajda */
8068a0023SAndrzej Hajda
9068a0023SAndrzej Hajda #ifndef __DRM_MIPI_DSI_H__
10068a0023SAndrzej Hajda #define __DRM_MIPI_DSI_H__
11068a0023SAndrzej Hajda
12068a0023SAndrzej Hajda #include <linux/device.h>
13068a0023SAndrzej Hajda
14068a0023SAndrzej Hajda struct mipi_dsi_host;
15068a0023SAndrzej Hajda struct mipi_dsi_device;
16f4dea1aaSJani Nikula struct drm_dsc_picture_parameter_set;
17068a0023SAndrzej Hajda
181d96d4a6SAndrzej Hajda /* request ACK from peripheral */
191d96d4a6SAndrzej Hajda #define MIPI_DSI_MSG_REQ_ACK BIT(0)
201d96d4a6SAndrzej Hajda /* use Low Power Mode to transmit message */
211d96d4a6SAndrzej Hajda #define MIPI_DSI_MSG_USE_LPM BIT(1)
221d96d4a6SAndrzej Hajda
23068a0023SAndrzej Hajda /**
24068a0023SAndrzej Hajda * struct mipi_dsi_msg - read/write DSI buffer
25068a0023SAndrzej Hajda * @channel: virtual channel id
26068a0023SAndrzej Hajda * @type: payload data type
27009081e0SThierry Reding * @flags: flags controlling this message transmission
28068a0023SAndrzej Hajda * @tx_len: length of @tx_buf
29068a0023SAndrzej Hajda * @tx_buf: data to be written
30068a0023SAndrzej Hajda * @rx_len: length of @rx_buf
31068a0023SAndrzej Hajda * @rx_buf: data to be read, or NULL
32068a0023SAndrzej Hajda */
33068a0023SAndrzej Hajda struct mipi_dsi_msg {
34068a0023SAndrzej Hajda u8 channel;
35068a0023SAndrzej Hajda u8 type;
361d96d4a6SAndrzej Hajda u16 flags;
37068a0023SAndrzej Hajda
38068a0023SAndrzej Hajda size_t tx_len;
39068a0023SAndrzej Hajda const void *tx_buf;
40068a0023SAndrzej Hajda
41068a0023SAndrzej Hajda size_t rx_len;
42068a0023SAndrzej Hajda void *rx_buf;
43068a0023SAndrzej Hajda };
44068a0023SAndrzej Hajda
4502acb76dSThierry Reding bool mipi_dsi_packet_format_is_short(u8 type);
4602acb76dSThierry Reding bool mipi_dsi_packet_format_is_long(u8 type);
4702acb76dSThierry Reding
48068a0023SAndrzej Hajda /**
49a52879e8SThierry Reding * struct mipi_dsi_packet - represents a MIPI DSI packet in protocol format
50a52879e8SThierry Reding * @size: size (in bytes) of the packet
51a52879e8SThierry Reding * @header: the four bytes that make up the header (Data ID, Word Count or
52a52879e8SThierry Reding * Packet Data, and ECC)
53a52879e8SThierry Reding * @payload_length: number of bytes in the payload
54a52879e8SThierry Reding * @payload: a pointer to a buffer containing the payload, if any
55a52879e8SThierry Reding */
56a52879e8SThierry Reding struct mipi_dsi_packet {
57a52879e8SThierry Reding size_t size;
58a52879e8SThierry Reding u8 header[4];
59a52879e8SThierry Reding size_t payload_length;
60a52879e8SThierry Reding const u8 *payload;
61a52879e8SThierry Reding };
62a52879e8SThierry Reding
63a52879e8SThierry Reding int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
64a52879e8SThierry Reding const struct mipi_dsi_msg *msg);
65a52879e8SThierry Reding
66a52879e8SThierry Reding /**
67068a0023SAndrzej Hajda * struct mipi_dsi_host_ops - DSI bus operations
68068a0023SAndrzej Hajda * @attach: attach DSI device to DSI host
69068a0023SAndrzej Hajda * @detach: detach DSI device from DSI host
70009081e0SThierry Reding * @transfer: transmit a DSI packet
71009081e0SThierry Reding *
72009081e0SThierry Reding * DSI packets transmitted by .transfer() are passed in as mipi_dsi_msg
73009081e0SThierry Reding * structures. This structure contains information about the type of packet
74009081e0SThierry Reding * being transmitted as well as the transmit and receive buffers. When an
75009081e0SThierry Reding * error is encountered during transmission, this function will return a
76009081e0SThierry Reding * negative error code. On success it shall return the number of bytes
77009081e0SThierry Reding * transmitted for write packets or the number of bytes received for read
78009081e0SThierry Reding * packets.
79009081e0SThierry Reding *
80009081e0SThierry Reding * Note that typically DSI packet transmission is atomic, so the .transfer()
81009081e0SThierry Reding * function will seldomly return anything other than the number of bytes
82009081e0SThierry Reding * contained in the transmit buffer on success.
83bacbab58SMaxime Ripard *
84bacbab58SMaxime Ripard * Also note that those callbacks can be called no matter the state the
85bacbab58SMaxime Ripard * host is in. Drivers that need the underlying device to be powered to
86bacbab58SMaxime Ripard * perform these operations will first need to make sure it's been
87bacbab58SMaxime Ripard * properly enabled.
88068a0023SAndrzej Hajda */
89068a0023SAndrzej Hajda struct mipi_dsi_host_ops {
90068a0023SAndrzej Hajda int (*attach)(struct mipi_dsi_host *host,
91068a0023SAndrzej Hajda struct mipi_dsi_device *dsi);
92068a0023SAndrzej Hajda int (*detach)(struct mipi_dsi_host *host,
93068a0023SAndrzej Hajda struct mipi_dsi_device *dsi);
94068a0023SAndrzej Hajda ssize_t (*transfer)(struct mipi_dsi_host *host,
95ed6ff40eSThierry Reding const struct mipi_dsi_msg *msg);
96068a0023SAndrzej Hajda };
97068a0023SAndrzej Hajda
98068a0023SAndrzej Hajda /**
99068a0023SAndrzej Hajda * struct mipi_dsi_host - DSI host device
100068a0023SAndrzej Hajda * @dev: driver model device node for this DSI host
101068a0023SAndrzej Hajda * @ops: DSI host operations
10297b6ae50SArchit Taneja * @list: list management
103068a0023SAndrzej Hajda */
104068a0023SAndrzej Hajda struct mipi_dsi_host {
105068a0023SAndrzej Hajda struct device *dev;
106068a0023SAndrzej Hajda const struct mipi_dsi_host_ops *ops;
10797b6ae50SArchit Taneja struct list_head list;
108068a0023SAndrzej Hajda };
109068a0023SAndrzej Hajda
110068a0023SAndrzej Hajda int mipi_dsi_host_register(struct mipi_dsi_host *host);
111068a0023SAndrzej Hajda void mipi_dsi_host_unregister(struct mipi_dsi_host *host);
11297b6ae50SArchit Taneja struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node);
113068a0023SAndrzej Hajda
114068a0023SAndrzej Hajda /* DSI mode flags */
115068a0023SAndrzej Hajda
116068a0023SAndrzej Hajda /* video mode */
117068a0023SAndrzej Hajda #define MIPI_DSI_MODE_VIDEO BIT(0)
118068a0023SAndrzej Hajda /* video burst mode */
119068a0023SAndrzej Hajda #define MIPI_DSI_MODE_VIDEO_BURST BIT(1)
120068a0023SAndrzej Hajda /* video pulse mode */
121068a0023SAndrzej Hajda #define MIPI_DSI_MODE_VIDEO_SYNC_PULSE BIT(2)
122068a0023SAndrzej Hajda /* enable auto vertical count mode */
123068a0023SAndrzej Hajda #define MIPI_DSI_MODE_VIDEO_AUTO_VERT BIT(3)
124068a0023SAndrzej Hajda /* enable hsync-end packets in vsync-pulse and v-porch area */
125068a0023SAndrzej Hajda #define MIPI_DSI_MODE_VIDEO_HSE BIT(4)
126068a0023SAndrzej Hajda /* disable hfront-porch area */
1270f3b68b6SNicolas Boichat #define MIPI_DSI_MODE_VIDEO_NO_HFP BIT(5)
128068a0023SAndrzej Hajda /* disable hback-porch area */
1290f3b68b6SNicolas Boichat #define MIPI_DSI_MODE_VIDEO_NO_HBP BIT(6)
130068a0023SAndrzej Hajda /* disable hsync-active area */
1310f3b68b6SNicolas Boichat #define MIPI_DSI_MODE_VIDEO_NO_HSA BIT(7)
132068a0023SAndrzej Hajda /* flush display FIFO on vsync pulse */
133068a0023SAndrzej Hajda #define MIPI_DSI_MODE_VSYNC_FLUSH BIT(8)
134068a0023SAndrzej Hajda /* disable EoT packets in HS mode */
1350f3b68b6SNicolas Boichat #define MIPI_DSI_MODE_NO_EOT_PACKET BIT(9)
136884d6a0bSAlexandre Courbot /* device supports non-continuous clock behavior (DSI spec 5.6.1) */
137884d6a0bSAlexandre Courbot #define MIPI_DSI_CLOCK_NON_CONTINUOUS BIT(10)
138d87f09abSInki Dae /* transmit data in low power */
139d87f09abSInki Dae #define MIPI_DSI_MODE_LPM BIT(11)
14014989152SRex-BC Chen /* transmit data ending at the same time for all lanes within one hsync */
14114989152SRex-BC Chen #define MIPI_DSI_HS_PKT_END_ALIGNED BIT(12)
142068a0023SAndrzej Hajda
143068a0023SAndrzej Hajda enum mipi_dsi_pixel_format {
144068a0023SAndrzej Hajda MIPI_DSI_FMT_RGB888,
145068a0023SAndrzej Hajda MIPI_DSI_FMT_RGB666,
146068a0023SAndrzej Hajda MIPI_DSI_FMT_RGB666_PACKED,
147068a0023SAndrzej Hajda MIPI_DSI_FMT_RGB565,
148068a0023SAndrzej Hajda };
149068a0023SAndrzej Hajda
150bf4363ceSArchit Taneja #define DSI_DEV_NAME_SIZE 20
151bf4363ceSArchit Taneja
152068a0023SAndrzej Hajda /**
153c63ae8a9SArchit Taneja * struct mipi_dsi_device_info - template for creating a mipi_dsi_device
154bf4363ceSArchit Taneja * @type: DSI peripheral chip type
155c63ae8a9SArchit Taneja * @channel: DSI virtual channel assigned to peripheral
156bf4363ceSArchit Taneja * @node: pointer to OF device node or NULL
157c63ae8a9SArchit Taneja *
158c63ae8a9SArchit Taneja * This is populated and passed to mipi_dsi_device_new to create a new
159c63ae8a9SArchit Taneja * DSI device
160c63ae8a9SArchit Taneja */
161c63ae8a9SArchit Taneja struct mipi_dsi_device_info {
162bf4363ceSArchit Taneja char type[DSI_DEV_NAME_SIZE];
163c63ae8a9SArchit Taneja u32 channel;
164c63ae8a9SArchit Taneja struct device_node *node;
165c63ae8a9SArchit Taneja };
166c63ae8a9SArchit Taneja
167c63ae8a9SArchit Taneja /**
168068a0023SAndrzej Hajda * struct mipi_dsi_device - DSI peripheral device
169068a0023SAndrzej Hajda * @host: DSI host for this peripheral
170068a0023SAndrzej Hajda * @dev: driver model device node for this peripheral
171daf57c5cSTomi Valkeinen * @attached: the DSI device has been successfully attached
172bf4363ceSArchit Taneja * @name: DSI peripheral chip type
173068a0023SAndrzej Hajda * @channel: virtual channel assigned to the peripheral
174068a0023SAndrzej Hajda * @format: pixel format for video mode
175068a0023SAndrzej Hajda * @lanes: number of active data lanes
176068a0023SAndrzej Hajda * @mode_flags: DSI operation mode related flags
177e982e3f0SLinus Walleij * @hs_rate: maximum lane frequency for high speed mode in hertz, this should
178e982e3f0SLinus Walleij * be set to the real limits of the hardware, zero is only accepted for
179e982e3f0SLinus Walleij * legacy drivers
180e982e3f0SLinus Walleij * @lp_rate: maximum lane frequency for low power mode in hertz, this should
181e982e3f0SLinus Walleij * be set to the real limits of the hardware, zero is only accepted for
182e982e3f0SLinus Walleij * legacy drivers
18302c830b3SDmitry Baryshkov * @dsc: panel/bridge DSC pps payload to be sent
184068a0023SAndrzej Hajda */
185068a0023SAndrzej Hajda struct mipi_dsi_device {
186068a0023SAndrzej Hajda struct mipi_dsi_host *host;
187068a0023SAndrzej Hajda struct device dev;
188daf57c5cSTomi Valkeinen bool attached;
189068a0023SAndrzej Hajda
190bf4363ceSArchit Taneja char name[DSI_DEV_NAME_SIZE];
191068a0023SAndrzej Hajda unsigned int channel;
192068a0023SAndrzej Hajda unsigned int lanes;
193068a0023SAndrzej Hajda enum mipi_dsi_pixel_format format;
194068a0023SAndrzej Hajda unsigned long mode_flags;
195e982e3f0SLinus Walleij unsigned long hs_rate;
196e982e3f0SLinus Walleij unsigned long lp_rate;
19702c830b3SDmitry Baryshkov struct drm_dsc_config *dsc;
198068a0023SAndrzej Hajda };
199068a0023SAndrzej Hajda
200babb24feSThierry Reding #define MIPI_DSI_MODULE_PREFIX "mipi-dsi:"
201babb24feSThierry Reding
202dad1b442SGreg Kroah-Hartman #define to_mipi_dsi_device(__dev) container_of_const(__dev, struct mipi_dsi_device, dev)
203068a0023SAndrzej Hajda
204ec26d9e9SLiu Ying /**
205ec26d9e9SLiu Ying * mipi_dsi_pixel_format_to_bpp - obtain the number of bits per pixel for any
206ec26d9e9SLiu Ying * given pixel format defined by the MIPI DSI
207ec26d9e9SLiu Ying * specification
208ec26d9e9SLiu Ying * @fmt: MIPI DSI pixel format
209ec26d9e9SLiu Ying *
210ec26d9e9SLiu Ying * Returns: The number of bits per pixel of the given pixel format.
211ec26d9e9SLiu Ying */
mipi_dsi_pixel_format_to_bpp(enum mipi_dsi_pixel_format fmt)212ec26d9e9SLiu Ying static inline int mipi_dsi_pixel_format_to_bpp(enum mipi_dsi_pixel_format fmt)
213ec26d9e9SLiu Ying {
214ec26d9e9SLiu Ying switch (fmt) {
215ec26d9e9SLiu Ying case MIPI_DSI_FMT_RGB888:
216ec26d9e9SLiu Ying case MIPI_DSI_FMT_RGB666:
217ec26d9e9SLiu Ying return 24;
218ec26d9e9SLiu Ying
219ec26d9e9SLiu Ying case MIPI_DSI_FMT_RGB666_PACKED:
220ec26d9e9SLiu Ying return 18;
221ec26d9e9SLiu Ying
222ec26d9e9SLiu Ying case MIPI_DSI_FMT_RGB565:
223ec26d9e9SLiu Ying return 16;
224ec26d9e9SLiu Ying }
225ec26d9e9SLiu Ying
226ec26d9e9SLiu Ying return -EINVAL;
227ec26d9e9SLiu Ying }
228ec26d9e9SLiu Ying
229c63ae8a9SArchit Taneja struct mipi_dsi_device *
230c63ae8a9SArchit Taneja mipi_dsi_device_register_full(struct mipi_dsi_host *host,
231c63ae8a9SArchit Taneja const struct mipi_dsi_device_info *info);
232509e42ceSArchit Taneja void mipi_dsi_device_unregister(struct mipi_dsi_device *dsi);
233a1419fb4SMaxime Ripard struct mipi_dsi_device *
234a1419fb4SMaxime Ripard devm_mipi_dsi_device_register_full(struct device *dev, struct mipi_dsi_host *host,
235a1419fb4SMaxime Ripard const struct mipi_dsi_device_info *info);
2363ef05924SThierry Reding struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np);
237068a0023SAndrzej Hajda int mipi_dsi_attach(struct mipi_dsi_device *dsi);
238068a0023SAndrzej Hajda int mipi_dsi_detach(struct mipi_dsi_device *dsi);
239db656849SMaxime Ripard int devm_mipi_dsi_attach(struct device *dev, struct mipi_dsi_device *dsi);
2406e8c9e33SWerner Johansson int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi);
2416e8c9e33SWerner Johansson int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi);
242dbf30b69SYoungJun Cho int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
243dbf30b69SYoungJun Cho u16 value);
244dda6efaeSDmitry Baryshkov int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable);
245dda6efaeSDmitry Baryshkov int mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
246f4dea1aaSJani Nikula const struct drm_dsc_picture_parameter_set *pps);
247550ab848SThierry Reding
248550ab848SThierry Reding ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
249550ab848SThierry Reding size_t size);
250550ab848SThierry Reding ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
251550ab848SThierry Reding size_t num_params, void *data, size_t size);
252550ab848SThierry Reding
25342fe1e75SYoungJun Cho /**
25442fe1e75SYoungJun Cho * enum mipi_dsi_dcs_tear_mode - Tearing Effect Output Line mode
25542fe1e75SYoungJun Cho * @MIPI_DSI_DCS_TEAR_MODE_VBLANK: the TE output line consists of V-Blanking
25642fe1e75SYoungJun Cho * information only
25742fe1e75SYoungJun Cho * @MIPI_DSI_DCS_TEAR_MODE_VHBLANK : the TE output line consists of both
25842fe1e75SYoungJun Cho * V-Blanking and H-Blanking information
25942fe1e75SYoungJun Cho */
26042fe1e75SYoungJun Cho enum mipi_dsi_dcs_tear_mode {
26142fe1e75SYoungJun Cho MIPI_DSI_DCS_TEAR_MODE_VBLANK,
26242fe1e75SYoungJun Cho MIPI_DSI_DCS_TEAR_MODE_VHBLANK,
26342fe1e75SYoungJun Cho };
26442fe1e75SYoungJun Cho
2653d9a8fcfSThierry Reding #define MIPI_DSI_DCS_POWER_MODE_DISPLAY (1 << 2)
2663d9a8fcfSThierry Reding #define MIPI_DSI_DCS_POWER_MODE_NORMAL (1 << 3)
2673d9a8fcfSThierry Reding #define MIPI_DSI_DCS_POWER_MODE_SLEEP (1 << 4)
2683d9a8fcfSThierry Reding #define MIPI_DSI_DCS_POWER_MODE_PARTIAL (1 << 5)
2693d9a8fcfSThierry Reding #define MIPI_DSI_DCS_POWER_MODE_IDLE (1 << 6)
2703d9a8fcfSThierry Reding
271960dd616SThierry Reding ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
272960dd616SThierry Reding const void *data, size_t len);
273960dd616SThierry Reding ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
274960dd616SThierry Reding const void *data, size_t len);
2753c523d7dSThierry Reding ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
2763c523d7dSThierry Reding size_t len);
277083d573fSThierry Reding int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi);
2782f16b897SThierry Reding int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi);
2793d9a8fcfSThierry Reding int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode);
2805cc0af16SThierry Reding int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format);
28142fe1e75SYoungJun Cho int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi);
28242fe1e75SYoungJun Cho int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi);
28342fe1e75SYoungJun Cho int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi);
28442fe1e75SYoungJun Cho int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi);
2853b46d4a0SThierry Reding int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
2863b46d4a0SThierry Reding u16 end);
2873b46d4a0SThierry Reding int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
2883b46d4a0SThierry Reding u16 end);
28942fe1e75SYoungJun Cho int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi);
29042fe1e75SYoungJun Cho int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
29142fe1e75SYoungJun Cho enum mipi_dsi_dcs_tear_mode mode);
2925cc0af16SThierry Reding int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format);
293bbdcf516SThierry Reding int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline);
2941a9d7593SVinay Simha BN int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi,
2951a9d7593SVinay Simha BN u16 brightness);
2961a9d7593SVinay Simha BN int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
2971a9d7593SVinay Simha BN u16 *brightness);
298c9d27c6bSDaniel Mentz int mipi_dsi_dcs_set_display_brightness_large(struct mipi_dsi_device *dsi,
299c9d27c6bSDaniel Mentz u16 brightness);
300c9d27c6bSDaniel Mentz int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi,
301c9d27c6bSDaniel Mentz u16 *brightness);
302068a0023SAndrzej Hajda
303068a0023SAndrzej Hajda /**
304a9015ce5SJavier Martinez Canillas * mipi_dsi_generic_write_seq - transmit data using a generic write packet
305a9015ce5SJavier Martinez Canillas * @dsi: DSI peripheral device
306a9015ce5SJavier Martinez Canillas * @seq: buffer containing the payload
307a9015ce5SJavier Martinez Canillas */
308a9015ce5SJavier Martinez Canillas #define mipi_dsi_generic_write_seq(dsi, seq...) \
309a9015ce5SJavier Martinez Canillas do { \
310a9015ce5SJavier Martinez Canillas static const u8 d[] = { seq }; \
311a9015ce5SJavier Martinez Canillas struct device *dev = &dsi->dev; \
312*8d869d02SDouglas Anderson ssize_t ret; \
313a9015ce5SJavier Martinez Canillas ret = mipi_dsi_generic_write(dsi, d, ARRAY_SIZE(d)); \
314a9015ce5SJavier Martinez Canillas if (ret < 0) { \
315*8d869d02SDouglas Anderson dev_err_ratelimited(dev, "transmit data failed: %zd\n", \
316a9015ce5SJavier Martinez Canillas ret); \
317a9015ce5SJavier Martinez Canillas return ret; \
318a9015ce5SJavier Martinez Canillas } \
319a9015ce5SJavier Martinez Canillas } while (0)
320a9015ce5SJavier Martinez Canillas
321a9015ce5SJavier Martinez Canillas /**
3222a9e9dafSJoel Selvaraj * mipi_dsi_dcs_write_seq - transmit a DCS command with payload
3232a9e9dafSJoel Selvaraj * @dsi: DSI peripheral device
3242a9e9dafSJoel Selvaraj * @cmd: Command
3252a9e9dafSJoel Selvaraj * @seq: buffer containing data to be transmitted
3262a9e9dafSJoel Selvaraj */
32751d3c0e7SJavier Martinez Canillas #define mipi_dsi_dcs_write_seq(dsi, cmd, seq...) \
32851d3c0e7SJavier Martinez Canillas do { \
3292a9e9dafSJoel Selvaraj static const u8 d[] = { cmd, seq }; \
3302a9e9dafSJoel Selvaraj struct device *dev = &dsi->dev; \
3314e9d95a1SDouglas Anderson ssize_t ret; \
3322a9e9dafSJoel Selvaraj ret = mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \
3332a9e9dafSJoel Selvaraj if (ret < 0) { \
33451d3c0e7SJavier Martinez Canillas dev_err_ratelimited( \
3354e9d95a1SDouglas Anderson dev, "sending command %#02x failed: %zd\n", \
33651d3c0e7SJavier Martinez Canillas cmd, ret); \
3372a9e9dafSJoel Selvaraj return ret; \
3382a9e9dafSJoel Selvaraj } \
3392a9e9dafSJoel Selvaraj } while (0)
3402a9e9dafSJoel Selvaraj
3412a9e9dafSJoel Selvaraj /**
342068a0023SAndrzej Hajda * struct mipi_dsi_driver - DSI driver
343068a0023SAndrzej Hajda * @driver: device driver model driver
344068a0023SAndrzej Hajda * @probe: callback for device binding
345068a0023SAndrzej Hajda * @remove: callback for device unbinding
346d1621803SThierry Reding * @shutdown: called at shutdown time to quiesce the device
347068a0023SAndrzej Hajda */
348068a0023SAndrzej Hajda struct mipi_dsi_driver {
349068a0023SAndrzej Hajda struct device_driver driver;
350068a0023SAndrzej Hajda int(*probe)(struct mipi_dsi_device *dsi);
35179abca2bSUwe Kleine-König void (*remove)(struct mipi_dsi_device *dsi);
352d1621803SThierry Reding void (*shutdown)(struct mipi_dsi_device *dsi);
353068a0023SAndrzej Hajda };
354068a0023SAndrzej Hajda
35577df01dcSThierry Reding static inline struct mipi_dsi_driver *
to_mipi_dsi_driver(struct device_driver * driver)35677df01dcSThierry Reding to_mipi_dsi_driver(struct device_driver *driver)
35777df01dcSThierry Reding {
35877df01dcSThierry Reding return container_of(driver, struct mipi_dsi_driver, driver);
35977df01dcSThierry Reding }
360068a0023SAndrzej Hajda
mipi_dsi_get_drvdata(const struct mipi_dsi_device * dsi)361068a0023SAndrzej Hajda static inline void *mipi_dsi_get_drvdata(const struct mipi_dsi_device *dsi)
362068a0023SAndrzej Hajda {
363068a0023SAndrzej Hajda return dev_get_drvdata(&dsi->dev);
364068a0023SAndrzej Hajda }
365068a0023SAndrzej Hajda
mipi_dsi_set_drvdata(struct mipi_dsi_device * dsi,void * data)366068a0023SAndrzej Hajda static inline void mipi_dsi_set_drvdata(struct mipi_dsi_device *dsi, void *data)
367068a0023SAndrzej Hajda {
368068a0023SAndrzej Hajda dev_set_drvdata(&dsi->dev, data);
369068a0023SAndrzej Hajda }
370068a0023SAndrzej Hajda
37199035e99SThierry Reding int mipi_dsi_driver_register_full(struct mipi_dsi_driver *driver,
37299035e99SThierry Reding struct module *owner);
373068a0023SAndrzej Hajda void mipi_dsi_driver_unregister(struct mipi_dsi_driver *driver);
374068a0023SAndrzej Hajda
37599035e99SThierry Reding #define mipi_dsi_driver_register(driver) \
37699035e99SThierry Reding mipi_dsi_driver_register_full(driver, THIS_MODULE)
37799035e99SThierry Reding
378068a0023SAndrzej Hajda #define module_mipi_dsi_driver(__mipi_dsi_driver) \
379068a0023SAndrzej Hajda module_driver(__mipi_dsi_driver, mipi_dsi_driver_register, \
380068a0023SAndrzej Hajda mipi_dsi_driver_unregister)
381068a0023SAndrzej Hajda
382068a0023SAndrzej Hajda #endif /* __DRM_MIPI_DSI__ */
383