2 * Copyright (C) 2015 Red Hat
3 * Copyright (C) 2015 Sony Mobile Communications Inc.
4 * Author: Werner Johansson <werner.johansson@sonymobile.com>
6 * Based on AUO panel driver by Rob Clark <robdclark@gmail.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <linux/backlight.h>
22 #include <linux/gpio/consumer.h>
23 #include <linux/module.h>
25 #include <linux/regulator/consumer.h>
28 #include <drm/drm_crtc.h>
29 #include <drm/drm_mipi_dsi.h>
30 #include <drm/drm_panel.h>
32 #include <video/mipi_display.h>
34 struct sharp_nt_panel
{
35 struct drm_panel base
;
36 struct mipi_dsi_device
*dsi
;
38 struct backlight_device
*backlight
;
39 struct regulator
*supply
;
40 struct gpio_desc
*reset_gpio
;
45 const struct drm_display_mode
*mode
;
48 static inline struct sharp_nt_panel
*to_sharp_nt_panel(struct drm_panel
*panel
)
50 return container_of(panel
, struct sharp_nt_panel
, base
);
53 static int sharp_nt_panel_init(struct sharp_nt_panel
*sharp_nt
)
55 struct mipi_dsi_device
*dsi
= sharp_nt
->dsi
;
58 dsi
->mode_flags
|= MIPI_DSI_MODE_LPM
;
60 ret
= mipi_dsi_dcs_exit_sleep_mode(dsi
);
66 /* Novatek two-lane operation */
67 ret
= mipi_dsi_dcs_write(dsi
, 0xae, (u8
[]){ 0x03 }, 1);
71 /* Set both MCU and RGB I/F to 24bpp */
72 ret
= mipi_dsi_dcs_set_pixel_format(dsi
, MIPI_DCS_PIXEL_FMT_24BIT
|
73 (MIPI_DCS_PIXEL_FMT_24BIT
<< 4));
80 static int sharp_nt_panel_on(struct sharp_nt_panel
*sharp_nt
)
82 struct mipi_dsi_device
*dsi
= sharp_nt
->dsi
;
85 dsi
->mode_flags
|= MIPI_DSI_MODE_LPM
;
87 ret
= mipi_dsi_dcs_set_display_on(dsi
);
94 static int sharp_nt_panel_off(struct sharp_nt_panel
*sharp_nt
)
96 struct mipi_dsi_device
*dsi
= sharp_nt
->dsi
;
99 dsi
->mode_flags
&= ~MIPI_DSI_MODE_LPM
;
101 ret
= mipi_dsi_dcs_set_display_off(dsi
);
105 ret
= mipi_dsi_dcs_enter_sleep_mode(dsi
);
113 static int sharp_nt_panel_disable(struct drm_panel
*panel
)
115 struct sharp_nt_panel
*sharp_nt
= to_sharp_nt_panel(panel
);
117 if (!sharp_nt
->enabled
)
120 if (sharp_nt
->backlight
) {
121 sharp_nt
->backlight
->props
.power
= FB_BLANK_POWERDOWN
;
122 backlight_update_status(sharp_nt
->backlight
);
125 sharp_nt
->enabled
= false;
130 static int sharp_nt_panel_unprepare(struct drm_panel
*panel
)
132 struct sharp_nt_panel
*sharp_nt
= to_sharp_nt_panel(panel
);
135 if (!sharp_nt
->prepared
)
138 ret
= sharp_nt_panel_off(sharp_nt
);
140 dev_err(panel
->dev
, "failed to set panel off: %d\n", ret
);
144 regulator_disable(sharp_nt
->supply
);
145 if (sharp_nt
->reset_gpio
)
146 gpiod_set_value(sharp_nt
->reset_gpio
, 0);
148 sharp_nt
->prepared
= false;
153 static int sharp_nt_panel_prepare(struct drm_panel
*panel
)
155 struct sharp_nt_panel
*sharp_nt
= to_sharp_nt_panel(panel
);
158 if (sharp_nt
->prepared
)
161 ret
= regulator_enable(sharp_nt
->supply
);
167 if (sharp_nt
->reset_gpio
) {
168 gpiod_set_value(sharp_nt
->reset_gpio
, 1);
170 gpiod_set_value(sharp_nt
->reset_gpio
, 0);
172 gpiod_set_value(sharp_nt
->reset_gpio
, 1);
176 ret
= sharp_nt_panel_init(sharp_nt
);
178 dev_err(panel
->dev
, "failed to init panel: %d\n", ret
);
182 ret
= sharp_nt_panel_on(sharp_nt
);
184 dev_err(panel
->dev
, "failed to set panel on: %d\n", ret
);
188 sharp_nt
->prepared
= true;
193 regulator_disable(sharp_nt
->supply
);
194 if (sharp_nt
->reset_gpio
)
195 gpiod_set_value(sharp_nt
->reset_gpio
, 0);
199 static int sharp_nt_panel_enable(struct drm_panel
*panel
)
201 struct sharp_nt_panel
*sharp_nt
= to_sharp_nt_panel(panel
);
203 if (sharp_nt
->enabled
)
206 if (sharp_nt
->backlight
) {
207 sharp_nt
->backlight
->props
.power
= FB_BLANK_UNBLANK
;
208 backlight_update_status(sharp_nt
->backlight
);
211 sharp_nt
->enabled
= true;
216 static const struct drm_display_mode default_mode
= {
219 .hsync_start
= 540 + 48,
220 .hsync_end
= 540 + 48 + 80,
221 .htotal
= 540 + 48 + 80 + 32,
223 .vsync_start
= 960 + 3,
224 .vsync_end
= 960 + 3 + 15,
225 .vtotal
= 960 + 3 + 15 + 1,
229 static int sharp_nt_panel_get_modes(struct drm_panel
*panel
)
231 struct drm_display_mode
*mode
;
233 mode
= drm_mode_duplicate(panel
->drm
, &default_mode
);
235 dev_err(panel
->drm
->dev
, "failed to add mode %ux%ux@%u\n",
236 default_mode
.hdisplay
, default_mode
.vdisplay
,
237 default_mode
.vrefresh
);
241 drm_mode_set_name(mode
);
243 drm_mode_probed_add(panel
->connector
, mode
);
245 panel
->connector
->display_info
.width_mm
= 54;
246 panel
->connector
->display_info
.height_mm
= 95;
251 static const struct drm_panel_funcs sharp_nt_panel_funcs
= {
252 .disable
= sharp_nt_panel_disable
,
253 .unprepare
= sharp_nt_panel_unprepare
,
254 .prepare
= sharp_nt_panel_prepare
,
255 .enable
= sharp_nt_panel_enable
,
256 .get_modes
= sharp_nt_panel_get_modes
,
259 static int sharp_nt_panel_add(struct sharp_nt_panel
*sharp_nt
)
261 struct device
*dev
= &sharp_nt
->dsi
->dev
;
262 struct device_node
*np
;
265 sharp_nt
->mode
= &default_mode
;
267 sharp_nt
->supply
= devm_regulator_get(dev
, "avdd");
268 if (IS_ERR(sharp_nt
->supply
))
269 return PTR_ERR(sharp_nt
->supply
);
271 sharp_nt
->reset_gpio
= devm_gpiod_get(dev
, "reset", GPIOD_OUT_LOW
);
272 if (IS_ERR(sharp_nt
->reset_gpio
)) {
273 dev_err(dev
, "cannot get reset-gpios %ld\n",
274 PTR_ERR(sharp_nt
->reset_gpio
));
275 sharp_nt
->reset_gpio
= NULL
;
277 gpiod_set_value(sharp_nt
->reset_gpio
, 0);
280 np
= of_parse_phandle(dev
->of_node
, "backlight", 0);
282 sharp_nt
->backlight
= of_find_backlight_by_node(np
);
285 if (!sharp_nt
->backlight
)
286 return -EPROBE_DEFER
;
289 drm_panel_init(&sharp_nt
->base
);
290 sharp_nt
->base
.funcs
= &sharp_nt_panel_funcs
;
291 sharp_nt
->base
.dev
= &sharp_nt
->dsi
->dev
;
293 ret
= drm_panel_add(&sharp_nt
->base
);
300 if (sharp_nt
->backlight
)
301 put_device(&sharp_nt
->backlight
->dev
);
306 static void sharp_nt_panel_del(struct sharp_nt_panel
*sharp_nt
)
308 if (sharp_nt
->base
.dev
)
309 drm_panel_remove(&sharp_nt
->base
);
311 if (sharp_nt
->backlight
)
312 put_device(&sharp_nt
->backlight
->dev
);
315 static int sharp_nt_panel_probe(struct mipi_dsi_device
*dsi
)
317 struct sharp_nt_panel
*sharp_nt
;
321 dsi
->format
= MIPI_DSI_FMT_RGB888
;
322 dsi
->mode_flags
= MIPI_DSI_MODE_VIDEO
|
323 MIPI_DSI_MODE_VIDEO_HSE
|
324 MIPI_DSI_CLOCK_NON_CONTINUOUS
|
325 MIPI_DSI_MODE_EOT_PACKET
;
327 sharp_nt
= devm_kzalloc(&dsi
->dev
, sizeof(*sharp_nt
), GFP_KERNEL
);
331 mipi_dsi_set_drvdata(dsi
, sharp_nt
);
335 ret
= sharp_nt_panel_add(sharp_nt
);
339 return mipi_dsi_attach(dsi
);
342 static int sharp_nt_panel_remove(struct mipi_dsi_device
*dsi
)
344 struct sharp_nt_panel
*sharp_nt
= mipi_dsi_get_drvdata(dsi
);
347 ret
= sharp_nt_panel_disable(&sharp_nt
->base
);
349 dev_err(&dsi
->dev
, "failed to disable panel: %d\n", ret
);
351 ret
= mipi_dsi_detach(dsi
);
353 dev_err(&dsi
->dev
, "failed to detach from DSI host: %d\n", ret
);
355 drm_panel_detach(&sharp_nt
->base
);
356 sharp_nt_panel_del(sharp_nt
);
361 static void sharp_nt_panel_shutdown(struct mipi_dsi_device
*dsi
)
363 struct sharp_nt_panel
*sharp_nt
= mipi_dsi_get_drvdata(dsi
);
365 sharp_nt_panel_disable(&sharp_nt
->base
);
368 static const struct of_device_id sharp_nt_of_match
[] = {
369 { .compatible
= "sharp,ls043t1le01-qhd", },
372 MODULE_DEVICE_TABLE(of
, sharp_nt_of_match
);
374 static struct mipi_dsi_driver sharp_nt_panel_driver
= {
376 .name
= "panel-sharp-ls043t1le01-qhd",
377 .of_match_table
= sharp_nt_of_match
,
379 .probe
= sharp_nt_panel_probe
,
380 .remove
= sharp_nt_panel_remove
,
381 .shutdown
= sharp_nt_panel_shutdown
,
383 module_mipi_dsi_driver(sharp_nt_panel_driver
);
385 MODULE_AUTHOR("Werner Johansson <werner.johansson@sonymobile.com>");
386 MODULE_DESCRIPTION("Sharp LS043T1LE01 NT35565-based qHD (540x960) video mode panel driver");
387 MODULE_LICENSE("GPL v2");