1
2
3
4
5
6
7
8#ifndef __LINUX_MIPI_DBI_H
9#define __LINUX_MIPI_DBI_H
10
11#include <linux/mutex.h>
12#include <drm/drm_device.h>
13#include <drm/drm_simple_kms_helper.h>
14
15struct drm_rect;
16struct spi_device;
17struct gpio_desc;
18struct regulator;
19
20
21
22
23struct mipi_dbi {
24
25
26
27 struct mutex cmdlock;
28
29
30
31
32 int (*command)(struct mipi_dbi *dbi, u8 *cmd, u8 *param, size_t num);
33
34
35
36
37
38 const u8 *read_commands;
39
40
41
42
43 bool swap_bytes;
44
45
46
47
48 struct gpio_desc *reset;
49
50
51
52
53
54
55 struct spi_device *spi;
56
57
58
59
60 struct gpio_desc *dc;
61
62
63
64
65 void *tx_buf9;
66
67
68
69
70 size_t tx_buf9_len;
71};
72
73
74
75
76struct mipi_dbi_dev {
77
78
79
80 struct drm_device drm;
81
82
83
84
85 struct drm_simple_display_pipe pipe;
86
87
88
89
90 struct drm_connector connector;
91
92
93
94
95 struct drm_display_mode mode;
96
97
98
99
100 u16 *tx_buf;
101
102
103
104
105 unsigned int rotation;
106
107
108
109
110
111 unsigned int left_offset;
112
113
114
115
116
117 unsigned int top_offset;
118
119
120
121
122 struct backlight_device *backlight;
123
124
125
126
127 struct regulator *regulator;
128
129
130
131
132 struct mipi_dbi dbi;
133
134
135
136
137
138
139
140 void *driver_private;
141};
142
143static inline struct mipi_dbi_dev *drm_to_mipi_dbi_dev(struct drm_device *drm)
144{
145 return container_of(drm, struct mipi_dbi_dev, drm);
146}
147
148int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
149 struct gpio_desc *dc);
150int 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);
155int 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);
158void mipi_dbi_pipe_update(struct drm_simple_display_pipe *pipe,
159 struct drm_plane_state *old_state);
160void mipi_dbi_enable_flush(struct mipi_dbi_dev *dbidev,
161 struct drm_crtc_state *crtc_state,
162 struct drm_plane_state *plan_state);
163void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
164void mipi_dbi_hw_reset(struct mipi_dbi *dbi);
165bool mipi_dbi_display_is_on(struct mipi_dbi *dbi);
166int mipi_dbi_poweron_reset(struct mipi_dbi_dev *dbidev);
167int mipi_dbi_poweron_conditional_reset(struct mipi_dbi_dev *dbidev);
168
169u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
170int mipi_dbi_spi_transfer(struct spi_device *spi, u32 speed_hz,
171 u8 bpw, const void *buf, size_t len);
172
173int mipi_dbi_command_read(struct mipi_dbi *dbi, u8 cmd, u8 *val);
174int mipi_dbi_command_buf(struct mipi_dbi *dbi, u8 cmd, u8 *data, size_t len);
175int mipi_dbi_command_stackbuf(struct mipi_dbi *dbi, u8 cmd, const u8 *data,
176 size_t len);
177int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
178 struct drm_rect *clip, bool swap);
179
180
181
182
183
184
185
186
187
188
189
190
191#define mipi_dbi_command(dbi, cmd, seq...) \
192({ \
193 const u8 d[] = { seq }; \
194 struct device *dev = &(dbi)->spi->dev; \
195 int ret; \
196 ret = mipi_dbi_command_stackbuf(dbi, cmd, d, ARRAY_SIZE(d)); \
197 if (ret) \
198 dev_err_ratelimited(dev, "error %d when sending command %#02x\n", ret, cmd); \
199 ret; \
200})
201
202#ifdef CONFIG_DEBUG_FS
203void mipi_dbi_debugfs_init(struct drm_minor *minor);
204#else
205static inline void mipi_dbi_debugfs_init(struct drm_minor *minor) {}
206#endif
207
208#endif
209