blob: c8a7d3daefa11687e5d4d7a8f7d0314e2e97f67c [file] [log] [blame]
Yannick Fertréd08fb322019-10-07 15:29:04 +02001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * MIPI DSI Bus
4 *
5 * Copyright (C) 2012-2013, Samsung Electronics, Co., Ltd.
6 * Copyright (C) 2018 STMicroelectronics - All Rights Reserved
7 * Author(s): Andrzej Hajda <a.hajda@samsung.com>
8 * Yannick Fertre <yannick.fertre@st.com>
9 * Philippe Cornu <philippe.cornu@st.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15#ifndef MIPI_DSI_H
16#define MIPI_DSI_H
17
18#include <mipi_display.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060019#include <linux/bitops.h>
Yannick Fertréd08fb322019-10-07 15:29:04 +020020
21struct mipi_dsi_host;
22struct mipi_dsi_device;
23
24/* request ACK from peripheral */
25#define MIPI_DSI_MSG_REQ_ACK BIT(0)
26/* use Low Power Mode to transmit message */
27#define MIPI_DSI_MSG_USE_LPM BIT(1)
28
29/**
30 * struct mipi_dsi_msg - read/write DSI buffer
31 * @channel: virtual channel id
32 * @type: payload data type
33 * @flags: flags controlling this message transmission
34 * @tx_len: length of @tx_buf
35 * @tx_buf: data to be written
36 * @rx_len: length of @rx_buf
37 * @rx_buf: data to be read, or NULL
38 */
39struct mipi_dsi_msg {
40 u8 channel;
41 u8 type;
42 u16 flags;
43
44 size_t tx_len;
45 const void *tx_buf;
46
47 size_t rx_len;
48 void *rx_buf;
49};
50
51bool mipi_dsi_packet_format_is_short(u8 type);
52bool mipi_dsi_packet_format_is_long(u8 type);
53
54/**
55 * struct mipi_dsi_packet - represents a MIPI DSI packet in protocol format
56 * @size: size (in bytes) of the packet
57 * @header: the four bytes that make up the header (Data ID, Word Count or
58 * Packet Data, and ECC)
59 * @payload_length: number of bytes in the payload
60 * @payload: a pointer to a buffer containing the payload, if any
61 */
62struct mipi_dsi_packet {
63 size_t size;
64 u8 header[4];
65 size_t payload_length;
66 const u8 *payload;
67};
68
69int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
70 const struct mipi_dsi_msg *msg);
71
72/**
73 * struct mipi_dsi_host_ops - DSI bus operations
74 * @attach: attach DSI device to DSI host
75 * @detach: detach DSI device from DSI host
76 * @transfer: transmit a DSI packet
77 *
78 * DSI packets transmitted by .transfer() are passed in as mipi_dsi_msg
79 * structures. This structure contains information about the type of packet
80 * being transmitted as well as the transmit and receive buffers. When an
81 * error is encountered during transmission, this function will return a
82 * negative error code. On success it shall return the number of bytes
83 * transmitted for write packets or the number of bytes received for read
84 * packets.
85 *
86 * Note that typically DSI packet transmission is atomic, so the .transfer()
87 * function will seldomly return anything other than the number of bytes
88 * contained in the transmit buffer on success.
89 */
90struct mipi_dsi_host_ops {
91 int (*attach)(struct mipi_dsi_host *host,
92 struct mipi_dsi_device *dsi);
93 int (*detach)(struct mipi_dsi_host *host,
94 struct mipi_dsi_device *dsi);
95 ssize_t (*transfer)(struct mipi_dsi_host *host,
96 const struct mipi_dsi_msg *msg);
97};
98
99/**
100 * struct mipi_dsi_phy_ops - DSI host physical operations
101 * @init: initialized host physical part
102 * @get_lane_mbps: get lane bitrate per lane (mbps)
103 * @post_set_mode: operation that should after set mode
104 */
105struct mipi_dsi_phy_ops {
106 int (*init)(void *priv_data);
107 int (*get_lane_mbps)(void *priv_data, struct display_timing *timings,
108 u32 lanes, u32 format, unsigned int *lane_mbps);
109 void (*post_set_mode)(void *priv_data, unsigned long mode_flags);
110};
111
112/**
113 * struct mipi_dsi_host - DSI host device
114 * @dev: driver model device node for this DSI host
115 * @ops: DSI host operations
116 * @list: list management
117 */
118struct mipi_dsi_host {
119 struct device *dev;
120 const struct mipi_dsi_host_ops *ops;
121 struct list_head list;
122};
123
124/* DSI mode flags */
125
126/* video mode */
127#define MIPI_DSI_MODE_VIDEO BIT(0)
128/* video burst mode */
129#define MIPI_DSI_MODE_VIDEO_BURST BIT(1)
130/* video pulse mode */
131#define MIPI_DSI_MODE_VIDEO_SYNC_PULSE BIT(2)
132/* enable auto vertical count mode */
133#define MIPI_DSI_MODE_VIDEO_AUTO_VERT BIT(3)
134/* enable hsync-end packets in vsync-pulse and v-porch area */
135#define MIPI_DSI_MODE_VIDEO_HSE BIT(4)
136/* disable hfront-porch area */
137#define MIPI_DSI_MODE_VIDEO_HFP BIT(5)
138/* disable hback-porch area */
139#define MIPI_DSI_MODE_VIDEO_HBP BIT(6)
140/* disable hsync-active area */
141#define MIPI_DSI_MODE_VIDEO_HSA BIT(7)
142/* flush display FIFO on vsync pulse */
143#define MIPI_DSI_MODE_VSYNC_FLUSH BIT(8)
144/* disable EoT packets in HS mode */
145#define MIPI_DSI_MODE_EOT_PACKET BIT(9)
146/* device supports non-continuous clock behavior (DSI spec 5.6.1) */
147#define MIPI_DSI_CLOCK_NON_CONTINUOUS BIT(10)
148/* transmit data in low power */
149#define MIPI_DSI_MODE_LPM BIT(11)
150
151enum mipi_dsi_pixel_format {
152 MIPI_DSI_FMT_RGB888,
153 MIPI_DSI_FMT_RGB666,
154 MIPI_DSI_FMT_RGB666_PACKED,
155 MIPI_DSI_FMT_RGB565,
156};
157
158#define DSI_DEV_NAME_SIZE 20
159
160/**
161 * struct mipi_dsi_device_info - template for creating a mipi_dsi_device
162 * @type: DSI peripheral chip type
163 * @channel: DSI virtual channel assigned to peripheral
164 * @node: pointer to OF device node or NULL
165 *
166 * This is populated and passed to mipi_dsi_device_new to create a new
167 * DSI device
168 */
169struct mipi_dsi_device_info {
170 char type[DSI_DEV_NAME_SIZE];
171 u32 channel;
172 struct device_node *node;
173};
174
175/**
176 * struct mipi_dsi_device - DSI peripheral device
177 * @host: DSI host for this peripheral
178 * @dev: driver model device node for this peripheral
179 * @name: DSI peripheral chip type
180 * @channel: virtual channel assigned to the peripheral
181 * @format: pixel format for video mode
182 * @lanes: number of active data lanes
183 * @mode_flags: DSI operation mode related flags
184 */
185struct mipi_dsi_device {
186 struct mipi_dsi_host *host;
187 struct udevice *dev;
188
189 char name[DSI_DEV_NAME_SIZE];
190 unsigned int channel;
191 unsigned int lanes;
192 enum mipi_dsi_pixel_format format;
193 unsigned long mode_flags;
194};
195
196/**
197 * mipi_dsi_pixel_format_to_bpp - obtain the number of bits per pixel for any
198 * given pixel format defined by the MIPI DSI
199 * specification
200 * @fmt: MIPI DSI pixel format
201 *
202 * Returns: The number of bits per pixel of the given pixel format.
203 */
204static inline int mipi_dsi_pixel_format_to_bpp(enum mipi_dsi_pixel_format fmt)
205{
206 switch (fmt) {
207 case MIPI_DSI_FMT_RGB888:
208 case MIPI_DSI_FMT_RGB666:
209 return 24;
210
211 case MIPI_DSI_FMT_RGB666_PACKED:
212 return 18;
213
214 case MIPI_DSI_FMT_RGB565:
215 return 16;
216 }
217
218 return -EINVAL;
219}
220
221/**
222 * struct mipi_dsi_panel_plat - DSI panel platform data
223 * @device: DSI peripheral device
Yannick Fertre0b89a872020-06-24 10:45:39 +0200224 * @lanes: number of active data lanes
225 * @format: pixel format for video mode
226 * @mode_flags: DSI operation mode related flags
Yannick Fertréd08fb322019-10-07 15:29:04 +0200227 */
228struct mipi_dsi_panel_plat {
229 struct mipi_dsi_device *device;
Yannick Fertre0b89a872020-06-24 10:45:39 +0200230 unsigned int lanes;
231 enum mipi_dsi_pixel_format format;
232 unsigned long mode_flags;
Yannick Fertréd08fb322019-10-07 15:29:04 +0200233};
234
235/**
236 * mipi_dsi_attach - attach a DSI device to its DSI host
237 * @dsi: DSI peripheral
238 */
239int mipi_dsi_attach(struct mipi_dsi_device *dsi);
240
241/**
242 * mipi_dsi_detach - detach a DSI device from its DSI host
243 * @dsi: DSI peripheral
244 */
245int mipi_dsi_detach(struct mipi_dsi_device *dsi);
246int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi);
247int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi);
248int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
249 u16 value);
250
251ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
252 size_t size);
253ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
254 size_t num_params, void *data, size_t size);
255
256/**
257 * enum mipi_dsi_dcs_tear_mode - Tearing Effect Output Line mode
258 * @MIPI_DSI_DCS_TEAR_MODE_VBLANK: the TE output line consists of V-Blanking
259 * information only
260 * @MIPI_DSI_DCS_TEAR_MODE_VHBLANK : the TE output line consists of both
261 * V-Blanking and H-Blanking information
262 */
263enum mipi_dsi_dcs_tear_mode {
264 MIPI_DSI_DCS_TEAR_MODE_VBLANK,
265 MIPI_DSI_DCS_TEAR_MODE_VHBLANK,
266};
267
268#define MIPI_DSI_DCS_POWER_MODE_DISPLAY BIT(2)
269#define MIPI_DSI_DCS_POWER_MODE_NORMAL BIT(3)
270#define MIPI_DSI_DCS_POWER_MODE_SLEEP BIT(4)
271#define MIPI_DSI_DCS_POWER_MODE_PARTIAL BIT(5)
272#define MIPI_DSI_DCS_POWER_MODE_IDLE BIT(6)
273
274/**
275 * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload
276 * @dsi: DSI peripheral device
277 * @data: buffer containing data to be transmitted
278 * @len: size of transmission buffer
279 *
280 * This function will automatically choose the right data type depending on
281 * the command payload length.
282 *
283 * Return: The number of bytes successfully transmitted or a negative error
284 * code on failure.
285 */
286ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
287 const void *data, size_t len);
288
289/**
290 * mipi_dsi_dcs_write() - send DCS write command
291 * @dsi: DSI peripheral device
292 * @cmd: DCS command
293 * @data: buffer containing the command payload
294 * @len: command payload length
295 *
296 * This function will automatically choose the right data type depending on
297 * the command payload length.
298
299 * code on failure.
300 */
301ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
302 const void *data, size_t len);
303
304/**
305 * mipi_dsi_dcs_read() - send DCS read request command
306 * @dsi: DSI peripheral device
307 * @cmd: DCS command
308 * @data: buffer in which to receive data
309 * @len: size of receive buffer
310 *
311 * Return: The number of bytes read or a negative error code on failure.
312 */
313ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
314 size_t len);
315
316/**
317 * mipi_dsi_dcs_nop() - send DCS nop packet
318 * @dsi: DSI peripheral device
319 *
320 * Return: 0 on success or a negative error code on failure.
321 */
322int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi);
323
324/**
325 * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module
326 * @dsi: DSI peripheral device
327 *
328 * Return: 0 on success or a negative error code on failure.
329 */
330int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi);
331
332/**
333 * mipi_dsi_dcs_get_power_mode() - query the display module's current power
334 * mode
335 * @dsi: DSI peripheral device
336 * @mode: return location for the current power mode
337 *
338 * Return: 0 on success or a negative error code on failure.
339 */
340int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode);
341
342/**
343 * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image
344 * data used by the interface
345 * @dsi: DSI peripheral device
346 * @format: return location for the pixel format
347 *
348 * Return: 0 on success or a negative error code on failure.
349 */
350int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format);
351
352/**
353 * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the
354 * display module except interface communication
355 * @dsi: DSI peripheral device
356 *
357 * Return: 0 on success or a negative error code on failure.
358 */
359int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi);
360
361/**
362 * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
363 * module
364 * @dsi: DSI peripheral device
365 *
366 * Return: 0 on success or a negative error code on failure.
367 */
368int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi);
369
370/**
371 * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
372 * display device
373 * @dsi: DSI peripheral device
374 *
375 * Return: 0 on success or a negative error code on failure.
376 */
377int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi);
378
379/**
380 * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
381 * display device
382 * @dsi: DSI peripheral device
383 *
384 * Return: 0 on success or a negative error code on failure
385 */
386int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi);
387
388/**
389 * mipi_dsi_dcs_set_column_address() - define the column extent of the frame
390 * memory accessed by the host processor
391 * @dsi: DSI peripheral device
392 * @start: first column of frame memory
393 * @end: last column of frame memory
394 *
395 * Return: 0 on success or a negative error code on failure.
396 */
397int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
398 u16 end);
399/**
400 * mipi_dsi_dcs_set_page_address() - define the page extent of the frame
401 * memory accessed by the host processor
402 * @dsi: DSI peripheral device
403 * @start: first page of frame memory
404 * @end: last page of frame memory
405 *
406 * Return: 0 on success or a negative error code on failure.
407 */
408int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
409 u16 end);
410
411/**
412 * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect
413 * output signal on the TE signal line
414 * @dsi: DSI peripheral device
415 *
416 * Return: 0 on success or a negative error code on failure
417 */
418int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi);
419
420/**
421 * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect
422 * output signal on the TE signal line.
423 * @dsi: DSI peripheral device
424 * @mode: the Tearing Effect Output Line mode
425 *
426 * Return: 0 on success or a negative error code on failure
427 */
428int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
429 enum mipi_dsi_dcs_tear_mode mode);
430
431/**
432 * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image
433 * data used by the interface
434 * @dsi: DSI peripheral device
435 * @format: pixel format
436 *
437 * Return: 0 on success or a negative error code on failure.
438 */
439int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format);
440
441/**
442 * mipi_dsi_dcs_set_tear_scanline() - set the scanline to use as trigger for
443 * the Tearing Effect output signal of the display module
444 * @dsi: DSI peripheral device
445 * @scanline: scanline to use as trigger
446 *
447 * Return: 0 on success or a negative error code on failure
448 */
449int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline);
450
451/**
452 * mipi_dsi_dcs_set_display_brightness() - sets the brightness value of the
453 * display
454 * @dsi: DSI peripheral device
455 * @brightness: brightness value
456 *
457 * Return: 0 on success or a negative error code on failure.
458 */
459int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi,
460 u16 brightness);
461
462/**
463 * mipi_dsi_dcs_get_display_brightness() - gets the current brightness value
464 * of the display
465 * @dsi: DSI peripheral device
466 * @brightness: brightness value
467 *
468 * Return: 0 on success or a negative error code on failure.
469 */
470int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
471 u16 *brightness);
472
473#endif /* MIPI_DSI_H */