EDAC: i7core, sb_edac: Don't return NOTIFY_BAD from mce_decoder callback
[linux/fpc-iii.git] / drivers / gpu / drm / imx / parallel-display.c
blob363e2c7741e2ea736e1cea604323116dc4ae0d75
1 /*
2 * i.MX drm driver - parallel display implementation
4 * Copyright (C) 2012 Sascha Hauer, Pengutronix
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/component.h>
17 #include <linux/module.h>
18 #include <drm/drmP.h>
19 #include <drm/drm_fb_helper.h>
20 #include <drm/drm_crtc_helper.h>
21 #include <drm/drm_panel.h>
22 #include <linux/videodev2.h>
23 #include <video/of_display_timing.h>
24 #include <linux/of_graph.h>
26 #include "imx-drm.h"
28 #define con_to_imxpd(x) container_of(x, struct imx_parallel_display, connector)
29 #define enc_to_imxpd(x) container_of(x, struct imx_parallel_display, encoder)
31 struct imx_parallel_display {
32 struct drm_connector connector;
33 struct drm_encoder encoder;
34 struct device *dev;
35 void *edid;
36 int edid_len;
37 u32 bus_format;
38 int mode_valid;
39 struct drm_display_mode mode;
40 struct drm_panel *panel;
43 static enum drm_connector_status imx_pd_connector_detect(
44 struct drm_connector *connector, bool force)
46 return connector_status_connected;
49 static int imx_pd_connector_get_modes(struct drm_connector *connector)
51 struct imx_parallel_display *imxpd = con_to_imxpd(connector);
52 struct device_node *np = imxpd->dev->of_node;
53 int num_modes = 0;
55 if (imxpd->panel && imxpd->panel->funcs &&
56 imxpd->panel->funcs->get_modes) {
57 struct drm_display_info *di = &connector->display_info;
59 num_modes = imxpd->panel->funcs->get_modes(imxpd->panel);
60 if (!imxpd->bus_format && di->num_bus_formats)
61 imxpd->bus_format = di->bus_formats[0];
62 if (num_modes > 0)
63 return num_modes;
66 if (imxpd->edid) {
67 drm_mode_connector_update_edid_property(connector, imxpd->edid);
68 num_modes = drm_add_edid_modes(connector, imxpd->edid);
71 if (imxpd->mode_valid) {
72 struct drm_display_mode *mode = drm_mode_create(connector->dev);
74 if (!mode)
75 return -EINVAL;
76 drm_mode_copy(mode, &imxpd->mode);
77 mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
78 drm_mode_probed_add(connector, mode);
79 num_modes++;
82 if (np) {
83 struct drm_display_mode *mode = drm_mode_create(connector->dev);
85 if (!mode)
86 return -EINVAL;
87 of_get_drm_display_mode(np, &imxpd->mode, OF_USE_NATIVE_MODE);
88 drm_mode_copy(mode, &imxpd->mode);
89 mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
90 drm_mode_probed_add(connector, mode);
91 num_modes++;
94 return num_modes;
97 static struct drm_encoder *imx_pd_connector_best_encoder(
98 struct drm_connector *connector)
100 struct imx_parallel_display *imxpd = con_to_imxpd(connector);
102 return &imxpd->encoder;
105 static void imx_pd_encoder_dpms(struct drm_encoder *encoder, int mode)
107 struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
109 if (mode != DRM_MODE_DPMS_ON)
110 drm_panel_disable(imxpd->panel);
111 else
112 drm_panel_enable(imxpd->panel);
115 static void imx_pd_encoder_prepare(struct drm_encoder *encoder)
117 struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
119 imx_drm_set_bus_format(encoder, imxpd->bus_format);
122 static void imx_pd_encoder_commit(struct drm_encoder *encoder)
124 struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
126 drm_panel_prepare(imxpd->panel);
127 drm_panel_enable(imxpd->panel);
130 static void imx_pd_encoder_mode_set(struct drm_encoder *encoder,
131 struct drm_display_mode *orig_mode,
132 struct drm_display_mode *mode)
136 static void imx_pd_encoder_disable(struct drm_encoder *encoder)
138 struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
140 drm_panel_disable(imxpd->panel);
141 drm_panel_unprepare(imxpd->panel);
144 static const struct drm_connector_funcs imx_pd_connector_funcs = {
145 .dpms = drm_helper_connector_dpms,
146 .fill_modes = drm_helper_probe_single_connector_modes,
147 .detect = imx_pd_connector_detect,
148 .destroy = imx_drm_connector_destroy,
151 static const struct drm_connector_helper_funcs imx_pd_connector_helper_funcs = {
152 .get_modes = imx_pd_connector_get_modes,
153 .best_encoder = imx_pd_connector_best_encoder,
156 static const struct drm_encoder_funcs imx_pd_encoder_funcs = {
157 .destroy = imx_drm_encoder_destroy,
160 static const struct drm_encoder_helper_funcs imx_pd_encoder_helper_funcs = {
161 .dpms = imx_pd_encoder_dpms,
162 .prepare = imx_pd_encoder_prepare,
163 .commit = imx_pd_encoder_commit,
164 .mode_set = imx_pd_encoder_mode_set,
165 .disable = imx_pd_encoder_disable,
168 static int imx_pd_register(struct drm_device *drm,
169 struct imx_parallel_display *imxpd)
171 int ret;
173 ret = imx_drm_encoder_parse_of(drm, &imxpd->encoder,
174 imxpd->dev->of_node);
175 if (ret)
176 return ret;
178 /* set the connector's dpms to OFF so that
179 * drm_helper_connector_dpms() won't return
180 * immediately since the current state is ON
181 * at this point.
183 imxpd->connector.dpms = DRM_MODE_DPMS_OFF;
185 drm_encoder_helper_add(&imxpd->encoder, &imx_pd_encoder_helper_funcs);
186 drm_encoder_init(drm, &imxpd->encoder, &imx_pd_encoder_funcs,
187 DRM_MODE_ENCODER_NONE, NULL);
189 drm_connector_helper_add(&imxpd->connector,
190 &imx_pd_connector_helper_funcs);
191 drm_connector_init(drm, &imxpd->connector, &imx_pd_connector_funcs,
192 DRM_MODE_CONNECTOR_VGA);
194 if (imxpd->panel)
195 drm_panel_attach(imxpd->panel, &imxpd->connector);
197 drm_mode_connector_attach_encoder(&imxpd->connector, &imxpd->encoder);
199 return 0;
202 static int imx_pd_bind(struct device *dev, struct device *master, void *data)
204 struct drm_device *drm = data;
205 struct device_node *np = dev->of_node;
206 struct device_node *port;
207 const u8 *edidp;
208 struct imx_parallel_display *imxpd;
209 int ret;
210 const char *fmt;
212 imxpd = devm_kzalloc(dev, sizeof(*imxpd), GFP_KERNEL);
213 if (!imxpd)
214 return -ENOMEM;
216 edidp = of_get_property(np, "edid", &imxpd->edid_len);
217 if (edidp)
218 imxpd->edid = kmemdup(edidp, imxpd->edid_len, GFP_KERNEL);
220 ret = of_property_read_string(np, "interface-pix-fmt", &fmt);
221 if (!ret) {
222 if (!strcmp(fmt, "rgb24"))
223 imxpd->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
224 else if (!strcmp(fmt, "rgb565"))
225 imxpd->bus_format = MEDIA_BUS_FMT_RGB565_1X16;
226 else if (!strcmp(fmt, "bgr666"))
227 imxpd->bus_format = MEDIA_BUS_FMT_RGB666_1X18;
228 else if (!strcmp(fmt, "lvds666"))
229 imxpd->bus_format = MEDIA_BUS_FMT_RGB666_1X24_CPADHI;
232 /* port@1 is the output port */
233 port = of_graph_get_port_by_id(np, 1);
234 if (port) {
235 struct device_node *endpoint, *remote;
237 endpoint = of_get_child_by_name(port, "endpoint");
238 if (endpoint) {
239 remote = of_graph_get_remote_port_parent(endpoint);
240 if (remote)
241 imxpd->panel = of_drm_find_panel(remote);
242 if (!imxpd->panel)
243 return -EPROBE_DEFER;
247 imxpd->dev = dev;
249 ret = imx_pd_register(drm, imxpd);
250 if (ret)
251 return ret;
253 dev_set_drvdata(dev, imxpd);
255 return 0;
258 static void imx_pd_unbind(struct device *dev, struct device *master,
259 void *data)
261 struct imx_parallel_display *imxpd = dev_get_drvdata(dev);
263 imxpd->encoder.funcs->destroy(&imxpd->encoder);
264 imxpd->connector.funcs->destroy(&imxpd->connector);
266 kfree(imxpd->edid);
269 static const struct component_ops imx_pd_ops = {
270 .bind = imx_pd_bind,
271 .unbind = imx_pd_unbind,
274 static int imx_pd_probe(struct platform_device *pdev)
276 return component_add(&pdev->dev, &imx_pd_ops);
279 static int imx_pd_remove(struct platform_device *pdev)
281 component_del(&pdev->dev, &imx_pd_ops);
283 return 0;
286 static const struct of_device_id imx_pd_dt_ids[] = {
287 { .compatible = "fsl,imx-parallel-display", },
288 { /* sentinel */ }
290 MODULE_DEVICE_TABLE(of, imx_pd_dt_ids);
292 static struct platform_driver imx_pd_driver = {
293 .probe = imx_pd_probe,
294 .remove = imx_pd_remove,
295 .driver = {
296 .of_match_table = imx_pd_dt_ids,
297 .name = "imx-parallel-display",
301 module_platform_driver(imx_pd_driver);
303 MODULE_DESCRIPTION("i.MX parallel display driver");
304 MODULE_AUTHOR("Sascha Hauer, Pengutronix");
305 MODULE_LICENSE("GPL");
306 MODULE_ALIAS("platform:imx-parallel-display");