blob: 0ef0040017757716663b0d6702f2ef00fe41c4c4 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Noralf Trønnes02dd95f2017-01-22 00:30:47 +01002/*
3 * MIPI Display Bus Interface (DBI) LCD controller support
4 *
5 * Copyright 2016 Noralf Trønnes
Noralf Trønnes02dd95f2017-01-22 00:30:47 +01006 */
7
8#ifndef __LINUX_MIPI_DBI_H
9#define __LINUX_MIPI_DBI_H
10
Noralf Trønnes3eba3922019-02-25 15:42:30 +010011#include <linux/mutex.h>
12#include <drm/drm_device.h>
13#include <drm/drm_simple_kms_helper.h>
Noralf Trønnes02dd95f2017-01-22 00:30:47 +010014
Noralf Trønnesb051b342019-01-15 05:36:41 +010015struct drm_rect;
Noralf Trønnes02dd95f2017-01-22 00:30:47 +010016struct spi_device;
17struct gpio_desc;
18struct regulator;
19
20/**
Noralf Trønnes84137b82019-07-22 12:43:07 +020021 * struct mipi_dbi - MIPI DBI interface
Noralf Trønnes02dd95f2017-01-22 00:30:47 +010022 */
23struct mipi_dbi {
Noralf Trønnes3eba3922019-02-25 15:42:30 +010024 /**
Noralf Trønnes84137b82019-07-22 12:43:07 +020025 * @cmdlock: Command lock
26 */
27 struct mutex cmdlock;
28
29 /**
30 * @command: Bus specific callback executing commands.
31 */
32 int (*command)(struct mipi_dbi *dbi, u8 *cmd, u8 *param, size_t num);
33
34 /**
35 * @read_commands: Array of read commands terminated by a zero entry.
36 * Reading is disabled if this is NULL.
37 */
38 const u8 *read_commands;
39
40 /**
41 * @swap_bytes: Swap bytes in buffer before transfer
42 */
43 bool swap_bytes;
44
45 /**
46 * @reset: Optional reset gpio
47 */
48 struct gpio_desc *reset;
49
50 /* Type C specific */
51
52 /**
53 * @spi: SPI device
54 */
55 struct spi_device *spi;
56
57 /**
58 * @dc: Optional D/C gpio.
59 */
60 struct gpio_desc *dc;
61
62 /**
63 * @tx_buf9: Buffer used for Option 1 9-bit conversion
64 */
65 void *tx_buf9;
66
67 /**
68 * @tx_buf9_len: Size of tx_buf9.
69 */
70 size_t tx_buf9_len;
71};
72
73/**
74 * struct mipi_dbi_dev - MIPI DBI device
75 */
76struct mipi_dbi_dev {
77 /**
Noralf Trønnes3eba3922019-02-25 15:42:30 +010078 * @drm: DRM device
79 */
80 struct drm_device drm;
81
82 /**
83 * @pipe: Display pipe structure
84 */
85 struct drm_simple_display_pipe pipe;
86
Noralf Trønnes710ae472019-07-19 17:59:16 +020087 /**
88 * @connector: Connector
89 */
90 struct drm_connector connector;
91
92 /**
93 * @mode: Fixed display mode
94 */
95 struct drm_display_mode mode;
96
Noralf Trønnes84137b82019-07-22 12:43:07 +020097 /**
98 * @enabled: Pipeline is enabled
99 */
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100100 bool enabled;
Noralf Trønnes84137b82019-07-22 12:43:07 +0200101
102 /**
103 * @tx_buf: Buffer used for transfer (copy clip rect area)
104 */
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100105 u16 *tx_buf;
Noralf Trønnes84137b82019-07-22 12:43:07 +0200106
107 /**
108 * @rotation: initial rotation in degrees Counter Clock Wise
109 */
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100110 unsigned int rotation;
Noralf Trønnes84137b82019-07-22 12:43:07 +0200111
112 /**
Geert Uytterhoevenf41a8a62020-01-15 13:45:46 +0100113 * @left_offset: Horizontal offset of the display relative to the
114 * controller's driver array
115 */
116 unsigned int left_offset;
117
118 /**
119 * @top_offset: Vertical offset of the display relative to the
120 * controller's driver array
121 */
122 unsigned int top_offset;
123
124 /**
Noralf Trønnes84137b82019-07-22 12:43:07 +0200125 * @backlight: backlight device (optional)
126 */
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100127 struct backlight_device *backlight;
Noralf Trønnes84137b82019-07-22 12:43:07 +0200128
129 /**
130 * @regulator: power regulator (optional)
131 */
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100132 struct regulator *regulator;
Noralf Trønnes84137b82019-07-22 12:43:07 +0200133
134 /**
135 * @dbi: MIPI DBI interface
136 */
137 struct mipi_dbi dbi;
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100138};
139
Noralf Trønnes84137b82019-07-22 12:43:07 +0200140static inline struct mipi_dbi_dev *drm_to_mipi_dbi_dev(struct drm_device *drm)
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100141{
Noralf Trønnes84137b82019-07-22 12:43:07 +0200142 return container_of(drm, struct mipi_dbi_dev, drm);
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100143}
144
Noralf Trønnes36b50572019-07-22 12:43:05 +0200145int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
David Lechnerace98812017-08-03 17:33:45 -0500146 struct gpio_desc *dc);
Noralf Trønnes84137b82019-07-22 12:43:07 +0200147int 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);
152int 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);
Noralf Trønnes3eba3922019-02-25 15:42:30 +0100155void mipi_dbi_release(struct drm_device *drm);
Noralf Trønnesaf741382019-01-15 05:36:42 +0100156void mipi_dbi_pipe_update(struct drm_simple_display_pipe *pipe,
157 struct drm_plane_state *old_state);
Noralf Trønnes84137b82019-07-22 12:43:07 +0200158void mipi_dbi_enable_flush(struct mipi_dbi_dev *dbidev,
Ville Syrjäläe85d3002018-03-23 17:35:09 +0200159 struct drm_crtc_state *crtc_state,
160 struct drm_plane_state *plan_state);
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100161void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
Noralf Trønnes36b50572019-07-22 12:43:05 +0200162void mipi_dbi_hw_reset(struct mipi_dbi *dbi);
163bool mipi_dbi_display_is_on(struct mipi_dbi *dbi);
Noralf Trønnes84137b82019-07-22 12:43:07 +0200164int mipi_dbi_poweron_reset(struct mipi_dbi_dev *dbidev);
165int mipi_dbi_poweron_conditional_reset(struct mipi_dbi_dev *dbidev);
Noralf Trønnesd23d4d42019-07-19 17:59:12 +0200166
David Lechner13deee82017-11-19 14:12:07 -0600167u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
Noralf Trønnesd23d4d42019-07-19 17:59:12 +0200168int mipi_dbi_spi_transfer(struct spi_device *spi, u32 speed_hz,
169 u8 bpw, const void *buf, size_t len);
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100170
Noralf Trønnes36b50572019-07-22 12:43:05 +0200171int mipi_dbi_command_read(struct mipi_dbi *dbi, u8 cmd, u8 *val);
172int mipi_dbi_command_buf(struct mipi_dbi *dbi, u8 cmd, u8 *data, size_t len);
Geert Uytterhoevenf0191902020-03-16 17:42:49 +0100173int mipi_dbi_command_stackbuf(struct mipi_dbi *dbi, u8 cmd, const u8 *data,
174 size_t len);
David Lechner13deee82017-11-19 14:12:07 -0600175int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
Noralf Trønnesb051b342019-01-15 05:36:41 +0100176 struct drm_rect *clip, bool swap);
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100177/**
178 * mipi_dbi_command - MIPI DCS command with optional parameter(s)
Noralf Trønnes36b50572019-07-22 12:43:05 +0200179 * @dbi: MIPI DBI structure
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100180 * @cmd: Command
181 * @seq...: Optional parameter(s)
182 *
183 * Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for
184 * get/read.
185 *
186 * Returns:
187 * Zero on success, negative error code on failure.
188 */
Noralf Trønnes36b50572019-07-22 12:43:05 +0200189#define mipi_dbi_command(dbi, cmd, seq...) \
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100190({ \
Geert Uytterhoevenf0191902020-03-16 17:42:49 +0100191 const u8 d[] = { seq }; \
Noralf Trønnes36b50572019-07-22 12:43:05 +0200192 mipi_dbi_command_stackbuf(dbi, cmd, d, ARRAY_SIZE(d)); \
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100193})
194
195#ifdef CONFIG_DEBUG_FS
Wambui Karuga7ce844712020-03-10 16:31:21 +0300196void mipi_dbi_debugfs_init(struct drm_minor *minor);
Noralf Trønnes02dd95f2017-01-22 00:30:47 +0100197#else
198#define mipi_dbi_debugfs_init NULL
199#endif
200
201#endif /* __LINUX_MIPI_DBI_H */