drm/msm/hdmi: Enable HPD after HDMI IRQ is set up
[linux/fpc-iii.git] / drivers / gpu / drm / panel / panel-seiko-43wvf1g.c
blob75f92539055104c14aba1fa9e42f39b71c1f3467
1 /*
2 * Copyright (C) 2017 NXP Semiconductors.
3 * Author: Marco Franchi <marco.franchi@nxp.com>
5 * Based on Panel Simple driver by Thierry Reding <treding@nvidia.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation.
12 #include <linux/backlight.h>
13 #include <linux/module.h>
14 #include <linux/of.h>
15 #include <linux/regulator/consumer.h>
17 #include <drm/drmP.h>
18 #include <drm/drm_crtc.h>
19 #include <drm/drm_panel.h>
21 #include <video/display_timing.h>
22 #include <video/videomode.h>
24 struct seiko_panel_desc {
25 const struct drm_display_mode *modes;
26 unsigned int num_modes;
27 const struct display_timing *timings;
28 unsigned int num_timings;
30 unsigned int bpc;
32 /**
33 * @width: width (in millimeters) of the panel's active display area
34 * @height: height (in millimeters) of the panel's active display area
36 struct {
37 unsigned int width;
38 unsigned int height;
39 } size;
41 u32 bus_format;
42 u32 bus_flags;
45 struct seiko_panel {
46 struct drm_panel base;
47 bool prepared;
48 bool enabled;
49 const struct seiko_panel_desc *desc;
50 struct backlight_device *backlight;
51 struct regulator *dvdd;
52 struct regulator *avdd;
55 static inline struct seiko_panel *to_seiko_panel(struct drm_panel *panel)
57 return container_of(panel, struct seiko_panel, base);
60 static int seiko_panel_get_fixed_modes(struct seiko_panel *panel)
62 struct drm_connector *connector = panel->base.connector;
63 struct drm_device *drm = panel->base.drm;
64 struct drm_display_mode *mode;
65 unsigned int i, num = 0;
67 if (!panel->desc)
68 return 0;
70 for (i = 0; i < panel->desc->num_timings; i++) {
71 const struct display_timing *dt = &panel->desc->timings[i];
72 struct videomode vm;
74 videomode_from_timing(dt, &vm);
75 mode = drm_mode_create(drm);
76 if (!mode) {
77 dev_err(drm->dev, "failed to add mode %ux%u\n",
78 dt->hactive.typ, dt->vactive.typ);
79 continue;
82 drm_display_mode_from_videomode(&vm, mode);
84 mode->type |= DRM_MODE_TYPE_DRIVER;
86 if (panel->desc->num_timings == 1)
87 mode->type |= DRM_MODE_TYPE_PREFERRED;
89 drm_mode_probed_add(connector, mode);
90 num++;
93 for (i = 0; i < panel->desc->num_modes; i++) {
94 const struct drm_display_mode *m = &panel->desc->modes[i];
96 mode = drm_mode_duplicate(drm, m);
97 if (!mode) {
98 dev_err(drm->dev, "failed to add mode %ux%u@%u\n",
99 m->hdisplay, m->vdisplay, m->vrefresh);
100 continue;
103 mode->type |= DRM_MODE_TYPE_DRIVER;
105 if (panel->desc->num_modes == 1)
106 mode->type |= DRM_MODE_TYPE_PREFERRED;
108 drm_mode_set_name(mode);
110 drm_mode_probed_add(connector, mode);
111 num++;
114 connector->display_info.bpc = panel->desc->bpc;
115 connector->display_info.width_mm = panel->desc->size.width;
116 connector->display_info.height_mm = panel->desc->size.height;
117 if (panel->desc->bus_format)
118 drm_display_info_set_bus_formats(&connector->display_info,
119 &panel->desc->bus_format, 1);
120 connector->display_info.bus_flags = panel->desc->bus_flags;
122 return num;
125 static int seiko_panel_disable(struct drm_panel *panel)
127 struct seiko_panel *p = to_seiko_panel(panel);
129 if (!p->enabled)
130 return 0;
132 if (p->backlight) {
133 p->backlight->props.power = FB_BLANK_POWERDOWN;
134 p->backlight->props.state |= BL_CORE_FBBLANK;
135 backlight_update_status(p->backlight);
138 p->enabled = false;
140 return 0;
143 static int seiko_panel_unprepare(struct drm_panel *panel)
145 struct seiko_panel *p = to_seiko_panel(panel);
147 if (!p->prepared)
148 return 0;
150 regulator_disable(p->avdd);
152 /* Add a 100ms delay as per the panel datasheet */
153 msleep(100);
155 regulator_disable(p->dvdd);
157 p->prepared = false;
159 return 0;
162 static int seiko_panel_prepare(struct drm_panel *panel)
164 struct seiko_panel *p = to_seiko_panel(panel);
165 int err;
167 if (p->prepared)
168 return 0;
170 err = regulator_enable(p->dvdd);
171 if (err < 0) {
172 dev_err(panel->dev, "failed to enable dvdd: %d\n", err);
173 return err;
176 /* Add a 100ms delay as per the panel datasheet */
177 msleep(100);
179 err = regulator_enable(p->avdd);
180 if (err < 0) {
181 dev_err(panel->dev, "failed to enable avdd: %d\n", err);
182 goto disable_dvdd;
185 p->prepared = true;
187 return 0;
189 disable_dvdd:
190 regulator_disable(p->dvdd);
191 return err;
194 static int seiko_panel_enable(struct drm_panel *panel)
196 struct seiko_panel *p = to_seiko_panel(panel);
198 if (p->enabled)
199 return 0;
201 if (p->backlight) {
202 p->backlight->props.state &= ~BL_CORE_FBBLANK;
203 p->backlight->props.power = FB_BLANK_UNBLANK;
204 backlight_update_status(p->backlight);
207 p->enabled = true;
209 return 0;
212 static int seiko_panel_get_modes(struct drm_panel *panel)
214 struct seiko_panel *p = to_seiko_panel(panel);
216 /* add hard-coded panel modes */
217 return seiko_panel_get_fixed_modes(p);
220 static int seiko_panel_get_timings(struct drm_panel *panel,
221 unsigned int num_timings,
222 struct display_timing *timings)
224 struct seiko_panel *p = to_seiko_panel(panel);
225 unsigned int i;
227 if (p->desc->num_timings < num_timings)
228 num_timings = p->desc->num_timings;
230 if (timings)
231 for (i = 0; i < num_timings; i++)
232 timings[i] = p->desc->timings[i];
234 return p->desc->num_timings;
237 static const struct drm_panel_funcs seiko_panel_funcs = {
238 .disable = seiko_panel_disable,
239 .unprepare = seiko_panel_unprepare,
240 .prepare = seiko_panel_prepare,
241 .enable = seiko_panel_enable,
242 .get_modes = seiko_panel_get_modes,
243 .get_timings = seiko_panel_get_timings,
246 static int seiko_panel_probe(struct device *dev,
247 const struct seiko_panel_desc *desc)
249 struct device_node *backlight;
250 struct seiko_panel *panel;
251 int err;
253 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
254 if (!panel)
255 return -ENOMEM;
257 panel->enabled = false;
258 panel->prepared = false;
259 panel->desc = desc;
261 panel->dvdd = devm_regulator_get(dev, "dvdd");
262 if (IS_ERR(panel->dvdd))
263 return PTR_ERR(panel->dvdd);
265 panel->avdd = devm_regulator_get(dev, "avdd");
266 if (IS_ERR(panel->avdd))
267 return PTR_ERR(panel->avdd);
269 backlight = of_parse_phandle(dev->of_node, "backlight", 0);
270 if (backlight) {
271 panel->backlight = of_find_backlight_by_node(backlight);
272 of_node_put(backlight);
274 if (!panel->backlight)
275 return -EPROBE_DEFER;
278 drm_panel_init(&panel->base);
279 panel->base.dev = dev;
280 panel->base.funcs = &seiko_panel_funcs;
282 err = drm_panel_add(&panel->base);
283 if (err < 0)
284 return err;
286 dev_set_drvdata(dev, panel);
288 return 0;
291 static int seiko_panel_remove(struct platform_device *pdev)
293 struct seiko_panel *panel = dev_get_drvdata(&pdev->dev);
295 drm_panel_remove(&panel->base);
297 seiko_panel_disable(&panel->base);
299 if (panel->backlight)
300 put_device(&panel->backlight->dev);
302 return 0;
305 static void seiko_panel_shutdown(struct platform_device *pdev)
307 struct seiko_panel *panel = dev_get_drvdata(&pdev->dev);
309 seiko_panel_disable(&panel->base);
312 static const struct display_timing seiko_43wvf1g_timing = {
313 .pixelclock = { 33500000, 33500000, 33500000 },
314 .hactive = { 800, 800, 800 },
315 .hfront_porch = { 164, 164, 164 },
316 .hback_porch = { 89, 89, 89 },
317 .hsync_len = { 10, 10, 10 },
318 .vactive = { 480, 480, 480 },
319 .vfront_porch = { 10, 10, 10 },
320 .vback_porch = { 23, 23, 23 },
321 .vsync_len = { 10, 10, 10 },
322 .flags = DISPLAY_FLAGS_DE_LOW,
325 static const struct seiko_panel_desc seiko_43wvf1g = {
326 .timings = &seiko_43wvf1g_timing,
327 .num_timings = 1,
328 .bpc = 8,
329 .size = {
330 .width = 93,
331 .height = 57,
333 .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
334 .bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_PIXDATA_NEGEDGE,
337 static const struct of_device_id platform_of_match[] = {
339 .compatible = "sii,43wvf1g",
340 .data = &seiko_43wvf1g,
341 }, {
342 /* sentinel */
345 MODULE_DEVICE_TABLE(of, platform_of_match);
347 static int seiko_panel_platform_probe(struct platform_device *pdev)
349 const struct of_device_id *id;
351 id = of_match_node(platform_of_match, pdev->dev.of_node);
352 if (!id)
353 return -ENODEV;
355 return seiko_panel_probe(&pdev->dev, id->data);
358 static struct platform_driver seiko_panel_platform_driver = {
359 .driver = {
360 .name = "seiko_panel",
361 .of_match_table = platform_of_match,
363 .probe = seiko_panel_platform_probe,
364 .remove = seiko_panel_remove,
365 .shutdown = seiko_panel_shutdown,
367 module_platform_driver(seiko_panel_platform_driver);
369 MODULE_AUTHOR("Marco Franchi <marco.franchi@nxp.com");
370 MODULE_DESCRIPTION("Seiko 43WVF1G panel driver");
371 MODULE_LICENSE("GPL v2");