Version:  2.0.40 2.2.26 2.4.37 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16

Linux/drivers/staging/imx-drm/parallel-display.c

  1 /*
  2  * i.MX drm driver - parallel display implementation
  3  *
  4  * Copyright (C) 2012 Sascha Hauer, Pengutronix
  5  *
  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.
 14  *
 15  * You should have received a copy of the GNU General Public License
 16  * along with this program; if not, write to the Free Software
 17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 18  * MA 02110-1301, USA.
 19  */
 20 
 21 #include <linux/component.h>
 22 #include <linux/module.h>
 23 #include <drm/drmP.h>
 24 #include <drm/drm_fb_helper.h>
 25 #include <drm/drm_crtc_helper.h>
 26 #include <drm/drm_panel.h>
 27 #include <linux/videodev2.h>
 28 #include <video/of_display_timing.h>
 29 
 30 #include "imx-drm.h"
 31 
 32 #define con_to_imxpd(x) container_of(x, struct imx_parallel_display, connector)
 33 #define enc_to_imxpd(x) container_of(x, struct imx_parallel_display, encoder)
 34 
 35 struct imx_parallel_display {
 36         struct drm_connector connector;
 37         struct drm_encoder encoder;
 38         struct device *dev;
 39         void *edid;
 40         int edid_len;
 41         u32 interface_pix_fmt;
 42         int mode_valid;
 43         struct drm_display_mode mode;
 44         struct drm_panel *panel;
 45 };
 46 
 47 static enum drm_connector_status imx_pd_connector_detect(
 48                 struct drm_connector *connector, bool force)
 49 {
 50         return connector_status_connected;
 51 }
 52 
 53 static int imx_pd_connector_get_modes(struct drm_connector *connector)
 54 {
 55         struct imx_parallel_display *imxpd = con_to_imxpd(connector);
 56         struct device_node *np = imxpd->dev->of_node;
 57         int num_modes = 0;
 58 
 59         if (imxpd->panel && imxpd->panel->funcs &&
 60             imxpd->panel->funcs->get_modes) {
 61                 num_modes = imxpd->panel->funcs->get_modes(imxpd->panel);
 62                 if (num_modes > 0)
 63                         return num_modes;
 64         }
 65 
 66         if (imxpd->edid) {
 67                 drm_mode_connector_update_edid_property(connector, imxpd->edid);
 68                 num_modes = drm_add_edid_modes(connector, imxpd->edid);
 69         }
 70 
 71         if (imxpd->mode_valid) {
 72                 struct drm_display_mode *mode = drm_mode_create(connector->dev);
 73                 if (!mode)
 74                         return -EINVAL;
 75                 drm_mode_copy(mode, &imxpd->mode);
 76                 mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
 77                 drm_mode_probed_add(connector, mode);
 78                 num_modes++;
 79         }
 80 
 81         if (np) {
 82                 struct drm_display_mode *mode = drm_mode_create(connector->dev);
 83                 if (!mode)
 84                         return -EINVAL;
 85                 of_get_drm_display_mode(np, &imxpd->mode, OF_USE_NATIVE_MODE);
 86                 drm_mode_copy(mode, &imxpd->mode);
 87                 mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
 88                 drm_mode_probed_add(connector, mode);
 89                 num_modes++;
 90         }
 91 
 92         return num_modes;
 93 }
 94 
 95 static struct drm_encoder *imx_pd_connector_best_encoder(
 96                 struct drm_connector *connector)
 97 {
 98         struct imx_parallel_display *imxpd = con_to_imxpd(connector);
 99 
100         return &imxpd->encoder;
101 }
102 
103 static void imx_pd_encoder_dpms(struct drm_encoder *encoder, int mode)
104 {
105         struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
106 
107         if (mode != DRM_MODE_DPMS_ON)
108                 drm_panel_disable(imxpd->panel);
109         else
110                 drm_panel_enable(imxpd->panel);
111 }
112 
113 static bool imx_pd_encoder_mode_fixup(struct drm_encoder *encoder,
114                            const struct drm_display_mode *mode,
115                            struct drm_display_mode *adjusted_mode)
116 {
117         return true;
118 }
119 
120 static void imx_pd_encoder_prepare(struct drm_encoder *encoder)
121 {
122         struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
123 
124         imx_drm_panel_format(encoder, imxpd->interface_pix_fmt);
125 }
126 
127 static void imx_pd_encoder_commit(struct drm_encoder *encoder)
128 {
129 }
130 
131 static void imx_pd_encoder_mode_set(struct drm_encoder *encoder,
132                          struct drm_display_mode *mode,
133                          struct drm_display_mode *adjusted_mode)
134 {
135 }
136 
137 static void imx_pd_encoder_disable(struct drm_encoder *encoder)
138 {
139 }
140 
141 static struct drm_connector_funcs imx_pd_connector_funcs = {
142         .dpms = drm_helper_connector_dpms,
143         .fill_modes = drm_helper_probe_single_connector_modes,
144         .detect = imx_pd_connector_detect,
145         .destroy = imx_drm_connector_destroy,
146 };
147 
148 static struct drm_connector_helper_funcs imx_pd_connector_helper_funcs = {
149         .get_modes = imx_pd_connector_get_modes,
150         .best_encoder = imx_pd_connector_best_encoder,
151 };
152 
153 static struct drm_encoder_funcs imx_pd_encoder_funcs = {
154         .destroy = imx_drm_encoder_destroy,
155 };
156 
157 static struct drm_encoder_helper_funcs imx_pd_encoder_helper_funcs = {
158         .dpms = imx_pd_encoder_dpms,
159         .mode_fixup = imx_pd_encoder_mode_fixup,
160         .prepare = imx_pd_encoder_prepare,
161         .commit = imx_pd_encoder_commit,
162         .mode_set = imx_pd_encoder_mode_set,
163         .disable = imx_pd_encoder_disable,
164 };
165 
166 static int imx_pd_register(struct drm_device *drm,
167         struct imx_parallel_display *imxpd)
168 {
169         int ret;
170 
171         ret = imx_drm_encoder_parse_of(drm, &imxpd->encoder,
172                                        imxpd->dev->of_node);
173         if (ret)
174                 return ret;
175 
176         /* set the connector's dpms to OFF so that
177          * drm_helper_connector_dpms() won't return
178          * immediately since the current state is ON
179          * at this point.
180          */
181         imxpd->connector.dpms = DRM_MODE_DPMS_OFF;
182 
183         drm_encoder_helper_add(&imxpd->encoder, &imx_pd_encoder_helper_funcs);
184         drm_encoder_init(drm, &imxpd->encoder, &imx_pd_encoder_funcs,
185                          DRM_MODE_ENCODER_NONE);
186 
187         drm_connector_helper_add(&imxpd->connector,
188                         &imx_pd_connector_helper_funcs);
189         drm_connector_init(drm, &imxpd->connector, &imx_pd_connector_funcs,
190                            DRM_MODE_CONNECTOR_VGA);
191 
192         if (imxpd->panel)
193                 drm_panel_attach(imxpd->panel, &imxpd->connector);
194 
195         drm_mode_connector_attach_encoder(&imxpd->connector, &imxpd->encoder);
196 
197         imxpd->connector.encoder = &imxpd->encoder;
198 
199         return 0;
200 }
201 
202 static int imx_pd_bind(struct device *dev, struct device *master, void *data)
203 {
204         struct drm_device *drm = data;
205         struct device_node *np = dev->of_node;
206         struct device_node *panel_node;
207         const u8 *edidp;
208         struct imx_parallel_display *imxpd;
209         int ret;
210         const char *fmt;
211 
212         imxpd = devm_kzalloc(dev, sizeof(*imxpd), GFP_KERNEL);
213         if (!imxpd)
214                 return -ENOMEM;
215 
216         edidp = of_get_property(np, "edid", &imxpd->edid_len);
217         if (edidp)
218                 imxpd->edid = kmemdup(edidp, imxpd->edid_len, GFP_KERNEL);
219 
220         ret = of_property_read_string(np, "interface-pix-fmt", &fmt);
221         if (!ret) {
222                 if (!strcmp(fmt, "rgb24"))
223                         imxpd->interface_pix_fmt = V4L2_PIX_FMT_RGB24;
224                 else if (!strcmp(fmt, "rgb565"))
225                         imxpd->interface_pix_fmt = V4L2_PIX_FMT_RGB565;
226                 else if (!strcmp(fmt, "bgr666"))
227                         imxpd->interface_pix_fmt = V4L2_PIX_FMT_BGR666;
228                 else if (!strcmp(fmt, "lvds666"))
229                         imxpd->interface_pix_fmt = v4l2_fourcc('L', 'V', 'D', '6');
230         }
231 
232         panel_node = of_parse_phandle(np, "fsl,panel", 0);
233         if (panel_node)
234                 imxpd->panel = of_drm_find_panel(panel_node);
235 
236         imxpd->dev = dev;
237 
238         ret = imx_pd_register(drm, imxpd);
239         if (ret)
240                 return ret;
241 
242         dev_set_drvdata(dev, imxpd);
243 
244         return 0;
245 }
246 
247 static void imx_pd_unbind(struct device *dev, struct device *master,
248         void *data)
249 {
250         struct imx_parallel_display *imxpd = dev_get_drvdata(dev);
251 
252         imxpd->encoder.funcs->destroy(&imxpd->encoder);
253         imxpd->connector.funcs->destroy(&imxpd->connector);
254 }
255 
256 static const struct component_ops imx_pd_ops = {
257         .bind   = imx_pd_bind,
258         .unbind = imx_pd_unbind,
259 };
260 
261 static int imx_pd_probe(struct platform_device *pdev)
262 {
263         return component_add(&pdev->dev, &imx_pd_ops);
264 }
265 
266 static int imx_pd_remove(struct platform_device *pdev)
267 {
268         component_del(&pdev->dev, &imx_pd_ops);
269         return 0;
270 }
271 
272 static const struct of_device_id imx_pd_dt_ids[] = {
273         { .compatible = "fsl,imx-parallel-display", },
274         { /* sentinel */ }
275 };
276 MODULE_DEVICE_TABLE(of, imx_pd_dt_ids);
277 
278 static struct platform_driver imx_pd_driver = {
279         .probe          = imx_pd_probe,
280         .remove         = imx_pd_remove,
281         .driver         = {
282                 .of_match_table = imx_pd_dt_ids,
283                 .name   = "imx-parallel-display",
284                 .owner  = THIS_MODULE,
285         },
286 };
287 
288 module_platform_driver(imx_pd_driver);
289 
290 MODULE_DESCRIPTION("i.MX parallel display driver");
291 MODULE_AUTHOR("Sascha Hauer, Pengutronix");
292 MODULE_LICENSE("GPL");
293 MODULE_ALIAS("platform:imx-parallel-display");
294 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us