1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2015 Red Hat
4 * Copyright (C) 2015 Sony Mobile Communications Inc.
5 * Author: Werner Johansson <werner.johansson@sonymobile.com>
7 * Based on AUO panel driver by Rob Clark <robdclark@gmail.com>
10 #include <linux/delay.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/module.h>
14 #include <linux/regulator/consumer.h>
16 #include <video/mipi_display.h>
18 #include <drm/drm_crtc.h>
19 #include <drm/drm_device.h>
20 #include <drm/drm_mipi_dsi.h>
21 #include <drm/drm_panel.h>
23 struct sharp_nt_panel
{
24 struct drm_panel base
;
25 struct mipi_dsi_device
*dsi
;
27 struct regulator
*supply
;
28 struct gpio_desc
*reset_gpio
;
33 const struct drm_display_mode
*mode
;
36 static inline struct sharp_nt_panel
*to_sharp_nt_panel(struct drm_panel
*panel
)
38 return container_of(panel
, struct sharp_nt_panel
, base
);
41 static int sharp_nt_panel_init(struct sharp_nt_panel
*sharp_nt
)
43 struct mipi_dsi_device
*dsi
= sharp_nt
->dsi
;
46 dsi
->mode_flags
|= MIPI_DSI_MODE_LPM
;
48 ret
= mipi_dsi_dcs_exit_sleep_mode(dsi
);
54 /* Novatek two-lane operation */
55 ret
= mipi_dsi_dcs_write(dsi
, 0xae, (u8
[]){ 0x03 }, 1);
59 /* Set both MCU and RGB I/F to 24bpp */
60 ret
= mipi_dsi_dcs_set_pixel_format(dsi
, MIPI_DCS_PIXEL_FMT_24BIT
|
61 (MIPI_DCS_PIXEL_FMT_24BIT
<< 4));
68 static int sharp_nt_panel_on(struct sharp_nt_panel
*sharp_nt
)
70 struct mipi_dsi_device
*dsi
= sharp_nt
->dsi
;
73 dsi
->mode_flags
|= MIPI_DSI_MODE_LPM
;
75 ret
= mipi_dsi_dcs_set_display_on(dsi
);
82 static int sharp_nt_panel_off(struct sharp_nt_panel
*sharp_nt
)
84 struct mipi_dsi_device
*dsi
= sharp_nt
->dsi
;
87 dsi
->mode_flags
&= ~MIPI_DSI_MODE_LPM
;
89 ret
= mipi_dsi_dcs_set_display_off(dsi
);
93 ret
= mipi_dsi_dcs_enter_sleep_mode(dsi
);
101 static int sharp_nt_panel_disable(struct drm_panel
*panel
)
103 struct sharp_nt_panel
*sharp_nt
= to_sharp_nt_panel(panel
);
105 if (!sharp_nt
->enabled
)
108 sharp_nt
->enabled
= false;
113 static int sharp_nt_panel_unprepare(struct drm_panel
*panel
)
115 struct sharp_nt_panel
*sharp_nt
= to_sharp_nt_panel(panel
);
118 if (!sharp_nt
->prepared
)
121 ret
= sharp_nt_panel_off(sharp_nt
);
123 dev_err(panel
->dev
, "failed to set panel off: %d\n", ret
);
127 regulator_disable(sharp_nt
->supply
);
128 if (sharp_nt
->reset_gpio
)
129 gpiod_set_value(sharp_nt
->reset_gpio
, 0);
131 sharp_nt
->prepared
= false;
136 static int sharp_nt_panel_prepare(struct drm_panel
*panel
)
138 struct sharp_nt_panel
*sharp_nt
= to_sharp_nt_panel(panel
);
141 if (sharp_nt
->prepared
)
144 ret
= regulator_enable(sharp_nt
->supply
);
150 if (sharp_nt
->reset_gpio
) {
151 gpiod_set_value(sharp_nt
->reset_gpio
, 1);
153 gpiod_set_value(sharp_nt
->reset_gpio
, 0);
155 gpiod_set_value(sharp_nt
->reset_gpio
, 1);
159 ret
= sharp_nt_panel_init(sharp_nt
);
161 dev_err(panel
->dev
, "failed to init panel: %d\n", ret
);
165 ret
= sharp_nt_panel_on(sharp_nt
);
167 dev_err(panel
->dev
, "failed to set panel on: %d\n", ret
);
171 sharp_nt
->prepared
= true;
176 regulator_disable(sharp_nt
->supply
);
177 if (sharp_nt
->reset_gpio
)
178 gpiod_set_value(sharp_nt
->reset_gpio
, 0);
182 static int sharp_nt_panel_enable(struct drm_panel
*panel
)
184 struct sharp_nt_panel
*sharp_nt
= to_sharp_nt_panel(panel
);
186 if (sharp_nt
->enabled
)
189 sharp_nt
->enabled
= true;
194 static const struct drm_display_mode default_mode
= {
197 .hsync_start
= 540 + 48,
198 .hsync_end
= 540 + 48 + 80,
199 .htotal
= 540 + 48 + 80 + 32,
201 .vsync_start
= 960 + 3,
202 .vsync_end
= 960 + 3 + 15,
203 .vtotal
= 960 + 3 + 15 + 1,
206 static int sharp_nt_panel_get_modes(struct drm_panel
*panel
,
207 struct drm_connector
*connector
)
209 struct drm_display_mode
*mode
;
211 mode
= drm_mode_duplicate(connector
->dev
, &default_mode
);
213 dev_err(panel
->dev
, "failed to add mode %ux%u@%u\n",
214 default_mode
.hdisplay
, default_mode
.vdisplay
,
215 drm_mode_vrefresh(&default_mode
));
219 drm_mode_set_name(mode
);
221 drm_mode_probed_add(connector
, mode
);
223 connector
->display_info
.width_mm
= 54;
224 connector
->display_info
.height_mm
= 95;
229 static const struct drm_panel_funcs sharp_nt_panel_funcs
= {
230 .disable
= sharp_nt_panel_disable
,
231 .unprepare
= sharp_nt_panel_unprepare
,
232 .prepare
= sharp_nt_panel_prepare
,
233 .enable
= sharp_nt_panel_enable
,
234 .get_modes
= sharp_nt_panel_get_modes
,
237 static int sharp_nt_panel_add(struct sharp_nt_panel
*sharp_nt
)
239 struct device
*dev
= &sharp_nt
->dsi
->dev
;
242 sharp_nt
->mode
= &default_mode
;
244 sharp_nt
->supply
= devm_regulator_get(dev
, "avdd");
245 if (IS_ERR(sharp_nt
->supply
))
246 return PTR_ERR(sharp_nt
->supply
);
248 sharp_nt
->reset_gpio
= devm_gpiod_get(dev
, "reset", GPIOD_OUT_LOW
);
249 if (IS_ERR(sharp_nt
->reset_gpio
)) {
250 dev_err(dev
, "cannot get reset-gpios %ld\n",
251 PTR_ERR(sharp_nt
->reset_gpio
));
252 sharp_nt
->reset_gpio
= NULL
;
254 gpiod_set_value(sharp_nt
->reset_gpio
, 0);
257 drm_panel_init(&sharp_nt
->base
, &sharp_nt
->dsi
->dev
,
258 &sharp_nt_panel_funcs
, DRM_MODE_CONNECTOR_DSI
);
260 ret
= drm_panel_of_backlight(&sharp_nt
->base
);
264 drm_panel_add(&sharp_nt
->base
);
269 static void sharp_nt_panel_del(struct sharp_nt_panel
*sharp_nt
)
271 if (sharp_nt
->base
.dev
)
272 drm_panel_remove(&sharp_nt
->base
);
275 static int sharp_nt_panel_probe(struct mipi_dsi_device
*dsi
)
277 struct sharp_nt_panel
*sharp_nt
;
281 dsi
->format
= MIPI_DSI_FMT_RGB888
;
282 dsi
->mode_flags
= MIPI_DSI_MODE_VIDEO
|
283 MIPI_DSI_MODE_VIDEO_HSE
|
284 MIPI_DSI_CLOCK_NON_CONTINUOUS
|
285 MIPI_DSI_MODE_EOT_PACKET
;
287 sharp_nt
= devm_kzalloc(&dsi
->dev
, sizeof(*sharp_nt
), GFP_KERNEL
);
291 mipi_dsi_set_drvdata(dsi
, sharp_nt
);
295 ret
= sharp_nt_panel_add(sharp_nt
);
299 return mipi_dsi_attach(dsi
);
302 static int sharp_nt_panel_remove(struct mipi_dsi_device
*dsi
)
304 struct sharp_nt_panel
*sharp_nt
= mipi_dsi_get_drvdata(dsi
);
307 ret
= drm_panel_disable(&sharp_nt
->base
);
309 dev_err(&dsi
->dev
, "failed to disable panel: %d\n", ret
);
311 ret
= mipi_dsi_detach(dsi
);
313 dev_err(&dsi
->dev
, "failed to detach from DSI host: %d\n", ret
);
315 sharp_nt_panel_del(sharp_nt
);
320 static void sharp_nt_panel_shutdown(struct mipi_dsi_device
*dsi
)
322 struct sharp_nt_panel
*sharp_nt
= mipi_dsi_get_drvdata(dsi
);
324 drm_panel_disable(&sharp_nt
->base
);
327 static const struct of_device_id sharp_nt_of_match
[] = {
328 { .compatible
= "sharp,ls043t1le01-qhd", },
331 MODULE_DEVICE_TABLE(of
, sharp_nt_of_match
);
333 static struct mipi_dsi_driver sharp_nt_panel_driver
= {
335 .name
= "panel-sharp-ls043t1le01-qhd",
336 .of_match_table
= sharp_nt_of_match
,
338 .probe
= sharp_nt_panel_probe
,
339 .remove
= sharp_nt_panel_remove
,
340 .shutdown
= sharp_nt_panel_shutdown
,
342 module_mipi_dsi_driver(sharp_nt_panel_driver
);
344 MODULE_AUTHOR("Werner Johansson <werner.johansson@sonymobile.com>");
345 MODULE_DESCRIPTION("Sharp LS043T1LE01 NT35565-based qHD (540x960) video mode panel driver");
346 MODULE_LICENSE("GPL v2");