1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2017 NXP Semiconductors.
4 * Author: Marco Franchi <marco.franchi@nxp.com>
6 * Based on Panel Simple driver by Thierry Reding <treding@nvidia.com>
9 #include <linux/delay.h>
10 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <linux/regulator/consumer.h>
15 #include <video/display_timing.h>
16 #include <video/videomode.h>
18 #include <drm/drm_crtc.h>
19 #include <drm/drm_device.h>
20 #include <drm/drm_panel.h>
22 struct seiko_panel_desc
{
23 const struct drm_display_mode
*modes
;
24 unsigned int num_modes
;
25 const struct display_timing
*timings
;
26 unsigned int num_timings
;
31 * @width: width (in millimeters) of the panel's active display area
32 * @height: height (in millimeters) of the panel's active display area
44 struct drm_panel base
;
47 const struct seiko_panel_desc
*desc
;
48 struct regulator
*dvdd
;
49 struct regulator
*avdd
;
52 static inline struct seiko_panel
*to_seiko_panel(struct drm_panel
*panel
)
54 return container_of(panel
, struct seiko_panel
, base
);
57 static int seiko_panel_get_fixed_modes(struct seiko_panel
*panel
,
58 struct drm_connector
*connector
)
60 struct drm_display_mode
*mode
;
61 unsigned int i
, num
= 0;
66 for (i
= 0; i
< panel
->desc
->num_timings
; i
++) {
67 const struct display_timing
*dt
= &panel
->desc
->timings
[i
];
70 videomode_from_timing(dt
, &vm
);
71 mode
= drm_mode_create(connector
->dev
);
73 dev_err(panel
->base
.dev
, "failed to add mode %ux%u\n",
74 dt
->hactive
.typ
, dt
->vactive
.typ
);
78 drm_display_mode_from_videomode(&vm
, mode
);
80 mode
->type
|= DRM_MODE_TYPE_DRIVER
;
82 if (panel
->desc
->num_timings
== 1)
83 mode
->type
|= DRM_MODE_TYPE_PREFERRED
;
85 drm_mode_probed_add(connector
, mode
);
89 for (i
= 0; i
< panel
->desc
->num_modes
; i
++) {
90 const struct drm_display_mode
*m
= &panel
->desc
->modes
[i
];
92 mode
= drm_mode_duplicate(connector
->dev
, m
);
94 dev_err(panel
->base
.dev
, "failed to add mode %ux%u@%u\n",
95 m
->hdisplay
, m
->vdisplay
,
96 drm_mode_vrefresh(m
));
100 mode
->type
|= DRM_MODE_TYPE_DRIVER
;
102 if (panel
->desc
->num_modes
== 1)
103 mode
->type
|= DRM_MODE_TYPE_PREFERRED
;
105 drm_mode_set_name(mode
);
107 drm_mode_probed_add(connector
, mode
);
111 connector
->display_info
.bpc
= panel
->desc
->bpc
;
112 connector
->display_info
.width_mm
= panel
->desc
->size
.width
;
113 connector
->display_info
.height_mm
= panel
->desc
->size
.height
;
114 if (panel
->desc
->bus_format
)
115 drm_display_info_set_bus_formats(&connector
->display_info
,
116 &panel
->desc
->bus_format
, 1);
117 connector
->display_info
.bus_flags
= panel
->desc
->bus_flags
;
122 static int seiko_panel_disable(struct drm_panel
*panel
)
124 struct seiko_panel
*p
= to_seiko_panel(panel
);
134 static int seiko_panel_unprepare(struct drm_panel
*panel
)
136 struct seiko_panel
*p
= to_seiko_panel(panel
);
141 regulator_disable(p
->avdd
);
143 /* Add a 100ms delay as per the panel datasheet */
146 regulator_disable(p
->dvdd
);
153 static int seiko_panel_prepare(struct drm_panel
*panel
)
155 struct seiko_panel
*p
= to_seiko_panel(panel
);
161 err
= regulator_enable(p
->dvdd
);
163 dev_err(panel
->dev
, "failed to enable dvdd: %d\n", err
);
167 /* Add a 100ms delay as per the panel datasheet */
170 err
= regulator_enable(p
->avdd
);
172 dev_err(panel
->dev
, "failed to enable avdd: %d\n", err
);
181 regulator_disable(p
->dvdd
);
185 static int seiko_panel_enable(struct drm_panel
*panel
)
187 struct seiko_panel
*p
= to_seiko_panel(panel
);
197 static int seiko_panel_get_modes(struct drm_panel
*panel
,
198 struct drm_connector
*connector
)
200 struct seiko_panel
*p
= to_seiko_panel(panel
);
202 /* add hard-coded panel modes */
203 return seiko_panel_get_fixed_modes(p
, connector
);
206 static int seiko_panel_get_timings(struct drm_panel
*panel
,
207 unsigned int num_timings
,
208 struct display_timing
*timings
)
210 struct seiko_panel
*p
= to_seiko_panel(panel
);
213 if (p
->desc
->num_timings
< num_timings
)
214 num_timings
= p
->desc
->num_timings
;
217 for (i
= 0; i
< num_timings
; i
++)
218 timings
[i
] = p
->desc
->timings
[i
];
220 return p
->desc
->num_timings
;
223 static const struct drm_panel_funcs seiko_panel_funcs
= {
224 .disable
= seiko_panel_disable
,
225 .unprepare
= seiko_panel_unprepare
,
226 .prepare
= seiko_panel_prepare
,
227 .enable
= seiko_panel_enable
,
228 .get_modes
= seiko_panel_get_modes
,
229 .get_timings
= seiko_panel_get_timings
,
232 static int seiko_panel_probe(struct device
*dev
,
233 const struct seiko_panel_desc
*desc
)
235 struct seiko_panel
*panel
;
238 panel
= devm_kzalloc(dev
, sizeof(*panel
), GFP_KERNEL
);
242 panel
->enabled
= false;
243 panel
->prepared
= false;
246 panel
->dvdd
= devm_regulator_get(dev
, "dvdd");
247 if (IS_ERR(panel
->dvdd
))
248 return PTR_ERR(panel
->dvdd
);
250 panel
->avdd
= devm_regulator_get(dev
, "avdd");
251 if (IS_ERR(panel
->avdd
))
252 return PTR_ERR(panel
->avdd
);
254 drm_panel_init(&panel
->base
, dev
, &seiko_panel_funcs
,
255 DRM_MODE_CONNECTOR_DPI
);
257 err
= drm_panel_of_backlight(&panel
->base
);
261 drm_panel_add(&panel
->base
);
263 dev_set_drvdata(dev
, panel
);
268 static int seiko_panel_remove(struct platform_device
*pdev
)
270 struct seiko_panel
*panel
= dev_get_drvdata(&pdev
->dev
);
272 drm_panel_remove(&panel
->base
);
273 drm_panel_disable(&panel
->base
);
278 static void seiko_panel_shutdown(struct platform_device
*pdev
)
280 struct seiko_panel
*panel
= dev_get_drvdata(&pdev
->dev
);
282 drm_panel_disable(&panel
->base
);
285 static const struct display_timing seiko_43wvf1g_timing
= {
286 .pixelclock
= { 33500000, 33500000, 33500000 },
287 .hactive
= { 800, 800, 800 },
288 .hfront_porch
= { 164, 164, 164 },
289 .hback_porch
= { 89, 89, 89 },
290 .hsync_len
= { 10, 10, 10 },
291 .vactive
= { 480, 480, 480 },
292 .vfront_porch
= { 10, 10, 10 },
293 .vback_porch
= { 23, 23, 23 },
294 .vsync_len
= { 10, 10, 10 },
295 .flags
= DISPLAY_FLAGS_DE_LOW
,
298 static const struct seiko_panel_desc seiko_43wvf1g
= {
299 .timings
= &seiko_43wvf1g_timing
,
306 .bus_format
= MEDIA_BUS_FMT_RGB888_1X24
,
307 .bus_flags
= DRM_BUS_FLAG_DE_HIGH
| DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE
,
310 static const struct of_device_id platform_of_match
[] = {
312 .compatible
= "sii,43wvf1g",
313 .data
= &seiko_43wvf1g
,
318 MODULE_DEVICE_TABLE(of
, platform_of_match
);
320 static int seiko_panel_platform_probe(struct platform_device
*pdev
)
322 const struct of_device_id
*id
;
324 id
= of_match_node(platform_of_match
, pdev
->dev
.of_node
);
328 return seiko_panel_probe(&pdev
->dev
, id
->data
);
331 static struct platform_driver seiko_panel_platform_driver
= {
333 .name
= "seiko_panel",
334 .of_match_table
= platform_of_match
,
336 .probe
= seiko_panel_platform_probe
,
337 .remove
= seiko_panel_remove
,
338 .shutdown
= seiko_panel_shutdown
,
340 module_platform_driver(seiko_panel_platform_driver
);
342 MODULE_AUTHOR("Marco Franchi <marco.franchi@nxp.com>");
343 MODULE_DESCRIPTION("Seiko 43WVF1G panel driver");
344 MODULE_LICENSE("GPL v2");