1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2024 Waveshare International Limited
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
*/
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/gpio/consumer.h>
#include <linux/regulator/consumer.h>
#include <drm/drm_mipi_dsi.h>
#include <drm/drm_modes.h>
#include <drm/drm_panel.h>
#include <drm/drm_probe_helper.h>
struct ota7290b {
struct drm_panel panel;
struct mipi_dsi_device *dsi;
struct regulator *power;
struct gpio_desc *reset;
struct regulator *avdd;
struct regulator *vdd;
struct regulator *vcc;
enum drm_panel_orientation orientation;
};
static inline struct ota7290b *panel_to_ota(struct drm_panel *panel)
{
return container_of(panel, struct ota7290b, panel);
}
static int ota7290b_prepare(struct drm_panel *panel)
{
struct ota7290b *ctx = panel_to_ota(panel);
struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi };
int ret;
if (ctx->vcc) {
ret = regulator_enable(ctx->vcc);
if (ret)
dev_err(panel->dev, "failed to enable VCC regulator: %d\n", ret);
}
if (ctx->reset) {
gpiod_set_value_cansleep(ctx->reset, 0);
msleep(60);
gpiod_set_value_cansleep(ctx->reset, 1);
msleep(60);
}
if (ctx->vdd) {
ret = regulator_enable(ctx->vdd);
if (ret)
dev_err(panel->dev, "failed to enable VDD regulator: %d\n", ret);
}
if (ctx->reset) {
gpiod_set_value_cansleep(ctx->reset, 0);
msleep(60);
}
if (ctx->avdd) {
ret = regulator_enable(ctx->avdd);
if (ret)
dev_err(panel->dev, "failed to enable AVDD regulator: %d\n", ret);
}
mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
mipi_dsi_msleep(&dsi_ctx, 120);
mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
mipi_dsi_msleep(&dsi_ctx, 50);
if (dsi_ctx.accum_err < 0)
dev_err(panel->dev, "failed to init panel: %d\n", dsi_ctx.accum_err);
return dsi_ctx.accum_err;
}
static int ota7290b_unprepare(struct drm_panel *panel)
{
struct ota7290b *ctx = panel_to_ota(panel);
struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi };
mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
if (ctx->avdd)
regulator_disable(ctx->avdd);
if (ctx->reset) {
gpiod_set_value_cansleep(ctx->reset, 1);
msleep(5);
}
if (ctx->vdd)
regulator_disable(ctx->vdd);
if (ctx->vcc)
regulator_disable(ctx->vcc);
return 0;
}
static const struct drm_display_mode waveshare_dsi_touch_8_8_a_mode = {
.clock = 75000,
.hdisplay = 480,
.hsync_start = 480 + 50,
.hsync_end = 480 + 50 + 50,
.htotal = 480 + 50 + 50 + 50,
.vdisplay = 1920,
.vsync_start = 1920 + 20,
.vsync_end = 1920 + 20 + 20,
.vtotal = 1920 + 20 + 20 + 20,
.width_mm = 68,
.height_mm = 219,
.type = DRM_MODE_TYPE_DRIVER,
};
static int ota7290b_get_modes(struct drm_panel *panel,
struct drm_connector *connector)
{
return drm_connector_helper_get_modes_fixed(connector, &waveshare_dsi_touch_8_8_a_mode);
}
static enum drm_panel_orientation ota7290b_get_orientation(struct drm_panel *panel)
{
struct ota7290b *ctx = panel_to_ota(panel);
return ctx->orientation;
}
static const struct drm_panel_funcs ota7290b_funcs = {
.prepare = ota7290b_prepare,
.unprepare = ota7290b_unprepare,
.get_modes = ota7290b_get_modes,
.get_orientation = ota7290b_get_orientation,
};
static int ota7290b_probe(struct mipi_dsi_device *dsi)
{
struct ota7290b *ctx;
int ret;
ctx = devm_drm_panel_alloc(&dsi->dev, struct ota7290b, panel,
&ota7290b_funcs,
DRM_MODE_CONNECTOR_DSI);
if (IS_ERR(ctx))
return PTR_ERR(ctx);
mipi_dsi_set_drvdata(dsi, ctx);
ctx->dsi = dsi;
ctx->reset = devm_gpiod_get_optional(&dsi->dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(ctx->reset))
return dev_err_probe(&dsi->dev, PTR_ERR(ctx->reset),
"Couldn't get our reset GPIO\n");
ctx->vcc = devm_regulator_get_optional(&dsi->dev, "vcc");
if (IS_ERR(ctx->vcc))
return dev_err_probe(&dsi->dev, PTR_ERR(ctx->vcc),
"Couldn't get our VCC supply\n");
ctx->avdd = devm_regulator_get_optional(&dsi->dev, "avdd");
if (IS_ERR(ctx->avdd))
return dev_err_probe(&dsi->dev, PTR_ERR(ctx->avdd),
"Couldn't get our AVDD supply\n");
ctx->vdd = devm_regulator_get_optional(&dsi->dev, "vdd");
if (IS_ERR(ctx->vdd))
return dev_err_probe(&dsi->dev, PTR_ERR(ctx->vdd),
"Couldn't get our VDD supply\n");
ret = of_drm_get_panel_orientation(dsi->dev.of_node, &ctx->orientation);
if (ret) {
dev_err(&dsi->dev, "%pOF: failed to get orientation: %d\n",
dsi->dev.of_node, ret);
return ret;
}
ret = drm_panel_of_backlight(&ctx->panel);
if (ret)
return ret;
ctx->panel.prepare_prev_first = true;
ret = devm_drm_panel_add(&dsi->dev, &ctx->panel);
if (ret)
return ret;
dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_HSE |
MIPI_DSI_MODE_LPM | MIPI_DSI_CLOCK_NON_CONTINUOUS,
dsi->format = MIPI_DSI_FMT_RGB888,
dsi->lanes = 2;
return devm_mipi_dsi_attach(&dsi->dev, dsi);
}
static const struct of_device_id ota7290b_of_match[] = {
{ .compatible = "waveshare,8.8-dsi-touch-a", },
{}
};
MODULE_DEVICE_TABLE(of, ota7290b_of_match);
static struct mipi_dsi_driver ota7290b_driver = {
.probe = ota7290b_probe,
.driver = {
.name = "focaltech-ota7290b",
.of_match_table = ota7290b_of_match,
},
};
module_mipi_dsi_driver(ota7290b_driver);
MODULE_DESCRIPTION("Panel driver for Focaltech OTA7290B panels");
MODULE_LICENSE("GPL");
|