1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Amarula Solutions
4 * Author: Jagan Teki <jagan@amarulasolutions.com>
7 #include <drm/drm_mipi_dsi.h>
8 #include <drm/drm_modes.h>
9 #include <drm/drm_panel.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/delay.h>
13 #include <linux/module.h>
14 #include <linux/of_device.h>
15 #include <linux/regulator/consumer.h>
17 #define FEIYANG_INIT_CMD_LEN 2
20 struct drm_panel panel
;
21 struct mipi_dsi_device
*dsi
;
23 struct regulator
*dvdd
;
24 struct regulator
*avdd
;
25 struct gpio_desc
*reset
;
28 static inline struct feiyang
*panel_to_feiyang(struct drm_panel
*panel
)
30 return container_of(panel
, struct feiyang
, panel
);
33 struct feiyang_init_cmd
{
34 u8 data
[FEIYANG_INIT_CMD_LEN
];
37 static const struct feiyang_init_cmd feiyang_init_cmds
[] = {
38 { .data
= { 0x80, 0x58 } },
39 { .data
= { 0x81, 0x47 } },
40 { .data
= { 0x82, 0xD4 } },
41 { .data
= { 0x83, 0x88 } },
42 { .data
= { 0x84, 0xA9 } },
43 { .data
= { 0x85, 0xC3 } },
44 { .data
= { 0x86, 0x82 } },
47 static int feiyang_prepare(struct drm_panel
*panel
)
49 struct feiyang
*ctx
= panel_to_feiyang(panel
);
50 struct mipi_dsi_device
*dsi
= ctx
->dsi
;
54 ret
= regulator_enable(ctx
->dvdd
);
58 /* T1 (dvdd start + dvdd rise) 0 < T1 <= 10ms */
61 ret
= regulator_enable(ctx
->avdd
);
65 /* T3 (dvdd rise + avdd start + avdd rise) T3 >= 20ms */
68 gpiod_set_value(ctx
->reset
, 0);
71 * T5 + T6 (avdd rise + video & logic signal rise)
72 * T5 >= 10ms, 0 < T6 <= 10ms
76 gpiod_set_value(ctx
->reset
, 1);
78 /* T12 (video & logic signal rise + backlight rise) T12 >= 200ms */
81 for (i
= 0; i
< ARRAY_SIZE(feiyang_init_cmds
); i
++) {
82 const struct feiyang_init_cmd
*cmd
=
83 &feiyang_init_cmds
[i
];
85 ret
= mipi_dsi_dcs_write_buffer(dsi
, cmd
->data
,
86 FEIYANG_INIT_CMD_LEN
);
94 static int feiyang_enable(struct drm_panel
*panel
)
96 struct feiyang
*ctx
= panel_to_feiyang(panel
);
98 /* T12 (video & logic signal rise + backlight rise) T12 >= 200ms */
101 mipi_dsi_dcs_set_display_on(ctx
->dsi
);
106 static int feiyang_disable(struct drm_panel
*panel
)
108 struct feiyang
*ctx
= panel_to_feiyang(panel
);
110 return mipi_dsi_dcs_set_display_off(ctx
->dsi
);
113 static int feiyang_unprepare(struct drm_panel
*panel
)
115 struct feiyang
*ctx
= panel_to_feiyang(panel
);
118 ret
= mipi_dsi_dcs_set_display_off(ctx
->dsi
);
120 dev_err(panel
->dev
, "failed to set display off: %d\n", ret
);
122 ret
= mipi_dsi_dcs_enter_sleep_mode(ctx
->dsi
);
124 dev_err(panel
->dev
, "failed to enter sleep mode: %d\n", ret
);
126 /* T13 (backlight fall + video & logic signal fall) T13 >= 200ms */
129 gpiod_set_value(ctx
->reset
, 0);
131 regulator_disable(ctx
->avdd
);
133 /* T11 (dvdd rise to fall) 0 < T11 <= 10ms */
136 regulator_disable(ctx
->dvdd
);
141 static const struct drm_display_mode feiyang_default_mode
= {
145 .hsync_start
= 1024 + 310,
146 .hsync_end
= 1024 + 310 + 20,
147 .htotal
= 1024 + 310 + 20 + 90,
150 .vsync_start
= 600 + 12,
151 .vsync_end
= 600 + 12 + 2,
152 .vtotal
= 600 + 12 + 2 + 21,
154 .type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
,
157 static int feiyang_get_modes(struct drm_panel
*panel
,
158 struct drm_connector
*connector
)
160 struct feiyang
*ctx
= panel_to_feiyang(panel
);
161 struct drm_display_mode
*mode
;
163 mode
= drm_mode_duplicate(connector
->dev
, &feiyang_default_mode
);
165 dev_err(&ctx
->dsi
->dev
, "failed to add mode %ux%u@%u\n",
166 feiyang_default_mode
.hdisplay
,
167 feiyang_default_mode
.vdisplay
,
168 drm_mode_vrefresh(&feiyang_default_mode
));
172 drm_mode_set_name(mode
);
174 drm_mode_probed_add(connector
, mode
);
179 static const struct drm_panel_funcs feiyang_funcs
= {
180 .disable
= feiyang_disable
,
181 .unprepare
= feiyang_unprepare
,
182 .prepare
= feiyang_prepare
,
183 .enable
= feiyang_enable
,
184 .get_modes
= feiyang_get_modes
,
187 static int feiyang_dsi_probe(struct mipi_dsi_device
*dsi
)
192 ctx
= devm_kzalloc(&dsi
->dev
, sizeof(*ctx
), GFP_KERNEL
);
196 mipi_dsi_set_drvdata(dsi
, ctx
);
199 drm_panel_init(&ctx
->panel
, &dsi
->dev
, &feiyang_funcs
,
200 DRM_MODE_CONNECTOR_DSI
);
202 ctx
->dvdd
= devm_regulator_get(&dsi
->dev
, "dvdd");
203 if (IS_ERR(ctx
->dvdd
)) {
204 dev_err(&dsi
->dev
, "Couldn't get dvdd regulator\n");
205 return PTR_ERR(ctx
->dvdd
);
208 ctx
->avdd
= devm_regulator_get(&dsi
->dev
, "avdd");
209 if (IS_ERR(ctx
->avdd
)) {
210 dev_err(&dsi
->dev
, "Couldn't get avdd regulator\n");
211 return PTR_ERR(ctx
->avdd
);
214 ctx
->reset
= devm_gpiod_get(&dsi
->dev
, "reset", GPIOD_OUT_LOW
);
215 if (IS_ERR(ctx
->reset
)) {
216 dev_err(&dsi
->dev
, "Couldn't get our reset GPIO\n");
217 return PTR_ERR(ctx
->reset
);
220 ret
= drm_panel_of_backlight(&ctx
->panel
);
224 drm_panel_add(&ctx
->panel
);
226 dsi
->mode_flags
= MIPI_DSI_MODE_VIDEO_BURST
;
227 dsi
->format
= MIPI_DSI_FMT_RGB888
;
230 return mipi_dsi_attach(dsi
);
233 static int feiyang_dsi_remove(struct mipi_dsi_device
*dsi
)
235 struct feiyang
*ctx
= mipi_dsi_get_drvdata(dsi
);
237 mipi_dsi_detach(dsi
);
238 drm_panel_remove(&ctx
->panel
);
243 static const struct of_device_id feiyang_of_match
[] = {
244 { .compatible
= "feiyang,fy07024di26a30d", },
247 MODULE_DEVICE_TABLE(of
, feiyang_of_match
);
249 static struct mipi_dsi_driver feiyang_driver
= {
250 .probe
= feiyang_dsi_probe
,
251 .remove
= feiyang_dsi_remove
,
253 .name
= "feiyang-fy07024di26a30d",
254 .of_match_table
= feiyang_of_match
,
257 module_mipi_dsi_driver(feiyang_driver
);
259 MODULE_AUTHOR("Jagan Teki <jagan@amarulasolutions.com>");
260 MODULE_DESCRIPTION("Feiyang FY07024DI26A30-D MIPI-DSI LCD panel");
261 MODULE_LICENSE("GPL");