drm/tinydrm: Rename variable mipi -> dbi
[platform/kernel/linux-rpi.git] / include / drm / tinydrm / mipi-dbi.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * MIPI Display Bus Interface (DBI) LCD controller support
4  *
5  * Copyright 2016 Noralf Trønnes
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
15 struct drm_rect;
16 struct spi_device;
17 struct gpio_desc;
18 struct regulator;
19
20 /**
21  * struct mipi_dbi - MIPI DBI controller
22  * @spi: SPI device
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)
37  */
38 struct mipi_dbi {
39         /**
40          * @drm: DRM device
41          */
42         struct drm_device drm;
43
44         /**
45          * @pipe: Display pipe structure
46          */
47         struct drm_simple_display_pipe pipe;
48
49         /**
50          * @connector: Connector
51          */
52         struct drm_connector connector;
53
54         /**
55          * @mode: Fixed display mode
56          */
57         struct drm_display_mode mode;
58
59         struct spi_device *spi;
60         bool enabled;
61         struct mutex cmdlock;
62         int (*command)(struct mipi_dbi *dbi, u8 *cmd, u8 *param, size_t num);
63         const u8 *read_commands;
64         struct gpio_desc *dc;
65         u16 *tx_buf;
66         void *tx_buf9;
67         size_t tx_buf9_len;
68         bool swap_bytes;
69         struct gpio_desc *reset;
70         unsigned int rotation;
71         struct backlight_device *backlight;
72         struct regulator *regulator;
73 };
74
75 static inline struct mipi_dbi *drm_to_mipi_dbi(struct drm_device *drm)
76 {
77         return container_of(drm, struct mipi_dbi, drm);
78 }
79
80 int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
81                       struct gpio_desc *dc);
82 int mipi_dbi_init_with_formats(struct mipi_dbi *mipi,
83                                const struct drm_simple_display_pipe_funcs *funcs,
84                                const uint32_t *formats, unsigned int format_count,
85                                const struct drm_display_mode *mode,
86                                unsigned int rotation, size_t tx_buf_size);
87 int mipi_dbi_init(struct mipi_dbi *mipi,
88                   const struct drm_simple_display_pipe_funcs *funcs,
89                   const struct drm_display_mode *mode, unsigned int rotation);
90 void mipi_dbi_release(struct drm_device *drm);
91 void mipi_dbi_pipe_update(struct drm_simple_display_pipe *pipe,
92                           struct drm_plane_state *old_state);
93 void mipi_dbi_enable_flush(struct mipi_dbi *mipi,
94                            struct drm_crtc_state *crtc_state,
95                            struct drm_plane_state *plan_state);
96 void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
97 void mipi_dbi_hw_reset(struct mipi_dbi *dbi);
98 bool mipi_dbi_display_is_on(struct mipi_dbi *dbi);
99 int mipi_dbi_poweron_reset(struct mipi_dbi *mipi);
100 int mipi_dbi_poweron_conditional_reset(struct mipi_dbi *mipi);
101
102 u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
103 int mipi_dbi_spi_transfer(struct spi_device *spi, u32 speed_hz,
104                           u8 bpw, const void *buf, size_t len);
105
106 int mipi_dbi_command_read(struct mipi_dbi *dbi, u8 cmd, u8 *val);
107 int mipi_dbi_command_buf(struct mipi_dbi *dbi, u8 cmd, u8 *data, size_t len);
108 int mipi_dbi_command_stackbuf(struct mipi_dbi *dbi, u8 cmd, u8 *data, size_t len);
109 int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
110                       struct drm_rect *clip, bool swap);
111 /**
112  * mipi_dbi_command - MIPI DCS command with optional parameter(s)
113  * @dbi: MIPI DBI structure
114  * @cmd: Command
115  * @seq...: Optional parameter(s)
116  *
117  * Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for
118  * get/read.
119  *
120  * Returns:
121  * Zero on success, negative error code on failure.
122  */
123 #define mipi_dbi_command(dbi, cmd, seq...) \
124 ({ \
125         u8 d[] = { seq }; \
126         mipi_dbi_command_stackbuf(dbi, cmd, d, ARRAY_SIZE(d)); \
127 })
128
129 #ifdef CONFIG_DEBUG_FS
130 int mipi_dbi_debugfs_init(struct drm_minor *minor);
131 #else
132 #define mipi_dbi_debugfs_init           NULL
133 #endif
134
135 #endif /* __LINUX_MIPI_DBI_H */