RDMA/rtrs: server: Fix some error return code
[linux/fpc-iii.git] / include / drm / drm_mipi_dbi.h
blob33f325f5af2b921f6fd9b6f693c78257ea6f3cac
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * MIPI Display Bus Interface (DBI) LCD controller support
5 * Copyright 2016 Noralf Trønnes
6 */
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>
15 struct drm_rect;
16 struct spi_device;
17 struct gpio_desc;
18 struct regulator;
20 /**
21 * struct mipi_dbi - MIPI DBI interface
23 struct mipi_dbi {
24 /**
25 * @cmdlock: Command lock
27 struct mutex cmdlock;
29 /**
30 * @command: Bus specific callback executing commands.
32 int (*command)(struct mipi_dbi *dbi, u8 *cmd, u8 *param, size_t num);
34 /**
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;
40 /**
41 * @swap_bytes: Swap bytes in buffer before transfer
43 bool swap_bytes;
45 /**
46 * @reset: Optional reset gpio
48 struct gpio_desc *reset;
50 /* Type C specific */
52 /**
53 * @spi: SPI device
55 struct spi_device *spi;
57 /**
58 * @dc: Optional D/C gpio.
60 struct gpio_desc *dc;
62 /**
63 * @tx_buf9: Buffer used for Option 1 9-bit conversion
65 void *tx_buf9;
67 /**
68 * @tx_buf9_len: Size of tx_buf9.
70 size_t tx_buf9_len;
73 /**
74 * struct mipi_dbi_dev - MIPI DBI device
76 struct mipi_dbi_dev {
77 /**
78 * @drm: DRM device
80 struct drm_device drm;
82 /**
83 * @pipe: Display pipe structure
85 struct drm_simple_display_pipe pipe;
87 /**
88 * @connector: Connector
90 struct drm_connector connector;
92 /**
93 * @mode: Fixed display mode
95 struct drm_display_mode mode;
97 /**
98 * @enabled: Pipeline is enabled
100 bool enabled;
103 * @tx_buf: Buffer used for transfer (copy clip rect area)
105 u16 *tx_buf;
108 * @rotation: initial rotation in degrees Counter Clock Wise
110 unsigned int rotation;
113 * @left_offset: Horizontal offset of the display relative to the
114 * controller's driver array
116 unsigned int left_offset;
119 * @top_offset: Vertical offset of the display relative to the
120 * controller's driver array
122 unsigned int top_offset;
125 * @backlight: backlight device (optional)
127 struct backlight_device *backlight;
130 * @regulator: power regulator (optional)
132 struct regulator *regulator;
135 * @dbi: MIPI DBI interface
137 struct mipi_dbi dbi;
140 static inline struct mipi_dbi_dev *drm_to_mipi_dbi_dev(struct drm_device *drm)
142 return container_of(drm, struct mipi_dbi_dev, drm);
145 int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
146 struct gpio_desc *dc);
147 int mipi_dbi_dev_init_with_formats(struct mipi_dbi_dev *dbidev,
148 const struct drm_simple_display_pipe_funcs *funcs,
149 const uint32_t *formats, unsigned int format_count,
150 const struct drm_display_mode *mode,
151 unsigned int rotation, size_t tx_buf_size);
152 int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev,
153 const struct drm_simple_display_pipe_funcs *funcs,
154 const struct drm_display_mode *mode, unsigned int rotation);
155 void mipi_dbi_release(struct drm_device *drm);
156 void mipi_dbi_pipe_update(struct drm_simple_display_pipe *pipe,
157 struct drm_plane_state *old_state);
158 void mipi_dbi_enable_flush(struct mipi_dbi_dev *dbidev,
159 struct drm_crtc_state *crtc_state,
160 struct drm_plane_state *plan_state);
161 void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
162 void mipi_dbi_hw_reset(struct mipi_dbi *dbi);
163 bool mipi_dbi_display_is_on(struct mipi_dbi *dbi);
164 int mipi_dbi_poweron_reset(struct mipi_dbi_dev *dbidev);
165 int mipi_dbi_poweron_conditional_reset(struct mipi_dbi_dev *dbidev);
167 u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
168 int mipi_dbi_spi_transfer(struct spi_device *spi, u32 speed_hz,
169 u8 bpw, const void *buf, size_t len);
171 int mipi_dbi_command_read(struct mipi_dbi *dbi, u8 cmd, u8 *val);
172 int mipi_dbi_command_buf(struct mipi_dbi *dbi, u8 cmd, u8 *data, size_t len);
173 int mipi_dbi_command_stackbuf(struct mipi_dbi *dbi, u8 cmd, u8 *data, size_t len);
174 int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
175 struct drm_rect *clip, bool swap);
177 * mipi_dbi_command - MIPI DCS command with optional parameter(s)
178 * @dbi: MIPI DBI structure
179 * @cmd: Command
180 * @seq...: Optional parameter(s)
182 * Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for
183 * get/read.
185 * Returns:
186 * Zero on success, negative error code on failure.
188 #define mipi_dbi_command(dbi, cmd, seq...) \
189 ({ \
190 u8 d[] = { seq }; \
191 mipi_dbi_command_stackbuf(dbi, cmd, d, ARRAY_SIZE(d)); \
194 #ifdef CONFIG_DEBUG_FS
195 int mipi_dbi_debugfs_init(struct drm_minor *minor);
196 #else
197 #define mipi_dbi_debugfs_init NULL
198 #endif
200 #endif /* __LINUX_MIPI_DBI_H */