1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * MIPI Display Bus Interface (DBI) LCD controller support
5 * Copyright 2016 Noralf Trønnes
8 #ifndef __LINUX_MIPI_DBI_H
9 #define __LINUX_MIPI_DBI_H
11 #include <linux/mutex.h>
12 #include <drm/drm_device.h>
13 #include <drm/drm_simple_kms_helper.h>
21 * struct mipi_dbi - MIPI DBI controller
23 * @enabled: Pipeline is enabled
24 * @cmdlock: Command lock
25 * @command: Bus specific callback executing commands.
26 * @read_commands: Array of read commands terminated by a zero entry.
27 * Reading is disabled if this is NULL.
28 * @dc: Optional D/C gpio.
29 * @tx_buf: Buffer used for transfer (copy clip rect area)
30 * @tx_buf9: Buffer used for Option 1 9-bit conversion
31 * @tx_buf9_len: Size of tx_buf9.
32 * @swap_bytes: Swap bytes in buffer before transfer
33 * @reset: Optional reset gpio
34 * @rotation: initial rotation in degrees Counter Clock Wise
35 * @backlight: backlight device (optional)
36 * @regulator: power regulator (optional)
42 struct drm_device drm;
45 * @pipe: Display pipe structure
47 struct drm_simple_display_pipe pipe;
49 struct spi_device *spi;
52 int (*command)(struct mipi_dbi *mipi, u8 *cmd, u8 *param, size_t num);
53 const u8 *read_commands;
59 struct gpio_desc *reset;
60 unsigned int rotation;
61 struct backlight_device *backlight;
62 struct regulator *regulator;
65 static inline struct mipi_dbi *drm_to_mipi_dbi(struct drm_device *drm)
67 return container_of(drm, struct mipi_dbi, drm);
70 int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi,
71 struct gpio_desc *dc);
72 int mipi_dbi_init(struct mipi_dbi *mipi,
73 const struct drm_simple_display_pipe_funcs *funcs,
74 const struct drm_display_mode *mode, unsigned int rotation);
75 void mipi_dbi_release(struct drm_device *drm);
76 void mipi_dbi_pipe_update(struct drm_simple_display_pipe *pipe,
77 struct drm_plane_state *old_state);
78 void mipi_dbi_enable_flush(struct mipi_dbi *mipi,
79 struct drm_crtc_state *crtc_state,
80 struct drm_plane_state *plan_state);
81 void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
82 void mipi_dbi_hw_reset(struct mipi_dbi *mipi);
83 bool mipi_dbi_display_is_on(struct mipi_dbi *mipi);
84 int mipi_dbi_poweron_reset(struct mipi_dbi *mipi);
85 int mipi_dbi_poweron_conditional_reset(struct mipi_dbi *mipi);
86 u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
88 int mipi_dbi_command_read(struct mipi_dbi *mipi, u8 cmd, u8 *val);
89 int mipi_dbi_command_buf(struct mipi_dbi *mipi, u8 cmd, u8 *data, size_t len);
90 int mipi_dbi_command_stackbuf(struct mipi_dbi *mipi, u8 cmd, u8 *data, size_t len);
91 int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
92 struct drm_rect *clip, bool swap);
94 * mipi_dbi_command - MIPI DCS command with optional parameter(s)
95 * @mipi: MIPI structure
97 * @seq...: Optional parameter(s)
99 * Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for
103 * Zero on success, negative error code on failure.
105 #define mipi_dbi_command(mipi, cmd, seq...) \
108 mipi_dbi_command_stackbuf(mipi, cmd, d, ARRAY_SIZE(d)); \
111 #ifdef CONFIG_DEBUG_FS
112 int mipi_dbi_debugfs_init(struct drm_minor *minor);
114 #define mipi_dbi_debugfs_init NULL
117 #endif /* __LINUX_MIPI_DBI_H */