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 interface
25 * @cmdlock: Command lock
30 * @command: Bus specific callback executing commands.
32 int (*command)(struct mipi_dbi *dbi, u8 *cmd, u8 *param, size_t num);
35 * @read_commands: Array of read commands terminated by a zero entry.
36 * Reading is disabled if this is NULL.
38 const u8 *read_commands;
41 * @swap_bytes: Swap bytes in buffer before transfer
46 * @reset: Optional reset gpio
48 struct gpio_desc *reset;
55 struct spi_device *spi;
58 * @dc: Optional D/C gpio.
63 * @tx_buf9: Buffer used for Option 1 9-bit conversion
68 * @tx_buf9_len: Size of tx_buf9.
74 * struct mipi_dbi_dev - MIPI DBI device
80 struct drm_device drm;
83 * @pipe: Display pipe structure
85 struct drm_simple_display_pipe pipe;
88 * @connector: Connector
90 struct drm_connector connector;
93 * @mode: Fixed display mode
95 struct drm_display_mode mode;
98 * @tx_buf: Buffer used for transfer (copy clip rect area)
103 * @rotation: initial rotation in degrees Counter Clock Wise
105 unsigned int rotation;
108 * @left_offset: Horizontal offset of the display relative to the
109 * controller's driver array
111 unsigned int left_offset;
114 * @top_offset: Vertical offset of the display relative to the
115 * controller's driver array
117 unsigned int top_offset;
120 * @backlight: backlight device (optional)
122 struct backlight_device *backlight;
125 * @regulator: power regulator (optional)
127 struct regulator *regulator;
130 * @dbi: MIPI DBI interface
135 * @driver_private: Driver private data.
136 * Necessary for drivers with private data since devm_drm_dev_alloc()
137 * can't allocate structures that embed a structure which then again
140 void *driver_private;
143 static inline struct mipi_dbi_dev *drm_to_mipi_dbi_dev(struct drm_device *drm)
145 return container_of(drm, struct mipi_dbi_dev, drm);
148 int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
149 struct gpio_desc *dc);
150 int mipi_dbi_dev_init_with_formats(struct mipi_dbi_dev *dbidev,
151 const struct drm_simple_display_pipe_funcs *funcs,
152 const uint32_t *formats, unsigned int format_count,
153 const struct drm_display_mode *mode,
154 unsigned int rotation, size_t tx_buf_size);
155 int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev,
156 const struct drm_simple_display_pipe_funcs *funcs,
157 const struct drm_display_mode *mode, unsigned int rotation);
158 void mipi_dbi_pipe_update(struct drm_simple_display_pipe *pipe,
159 struct drm_plane_state *old_state);
160 void mipi_dbi_enable_flush(struct mipi_dbi_dev *dbidev,
161 struct drm_crtc_state *crtc_state,
162 struct drm_plane_state *plan_state);
163 void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
164 void mipi_dbi_hw_reset(struct mipi_dbi *dbi);
165 bool mipi_dbi_display_is_on(struct mipi_dbi *dbi);
166 int mipi_dbi_poweron_reset(struct mipi_dbi_dev *dbidev);
167 int mipi_dbi_poweron_conditional_reset(struct mipi_dbi_dev *dbidev);
169 u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
170 int mipi_dbi_spi_transfer(struct spi_device *spi, u32 speed_hz,
171 u8 bpw, const void *buf, size_t len);
173 int mipi_dbi_command_read(struct mipi_dbi *dbi, u8 cmd, u8 *val);
174 int mipi_dbi_command_buf(struct mipi_dbi *dbi, u8 cmd, u8 *data, size_t len);
175 int mipi_dbi_command_stackbuf(struct mipi_dbi *dbi, u8 cmd, const u8 *data,
177 int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
178 struct drm_rect *clip, bool swap);
180 * mipi_dbi_command - MIPI DCS command with optional parameter(s)
181 * @dbi: MIPI DBI structure
183 * @seq: Optional parameter(s)
185 * Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for
189 * Zero on success, negative error code on failure.
191 #define mipi_dbi_command(dbi, cmd, seq...) \
193 const u8 d[] = { seq }; \
194 struct device *dev = &(dbi)->spi->dev; \
196 ret = mipi_dbi_command_stackbuf(dbi, cmd, d, ARRAY_SIZE(d)); \
198 dev_err_ratelimited(dev, "error %d when sending command %#02x\n", ret, cmd); \
202 #ifdef CONFIG_DEBUG_FS
203 void mipi_dbi_debugfs_init(struct drm_minor *minor);
205 #define mipi_dbi_debugfs_init NULL
208 #endif /* __LINUX_MIPI_DBI_H */