Version:  2.0.40 2.2.26 2.4.37 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 3.17 3.18

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 
 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++;
 80         }
 81 
 82         if (np) {
 83                 struct drm_display_mode *mode = drm_mode_create(connector->dev);
 84 
 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++;
 92         }
 93 
 94         return num_modes;
 95 }
 96 
 97 static struct drm_encoder *imx_pd_connector_best_encoder(
 98                 struct drm_connector *connector)
 99 {
100         struct imx_parallel_display *imxpd = con_to_imxpd(connector);
101 
102         return &imxpd->encoder;
103 }
104 
105 static void imx_pd_encoder_dpms(struct drm_encoder *encoder, int mode)
106 {
107         struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
108 
109         if (mode != DRM_MODE_DPMS_ON)
110                 drm_panel_disable(imxpd->panel);
111         else
112                 drm_panel_enable(imxpd->panel);
113 }
114 
115 static bool imx_pd_encoder_mode_fixup(struct drm_encoder *encoder,
116                            const struct drm_display_mode *mode,
117                            struct drm_display_mode *adjusted_mode)
118 {
119         return true;
120 }
121 
122 static void imx_pd_encoder_prepare(struct drm_encoder *encoder)
123 {
124         struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
125 
126         imx_drm_panel_format(encoder, imxpd->interface_pix_fmt);
127 }
128 
129 static void imx_pd_encoder_commit(struct drm_encoder *encoder)
130 {
131 }
132 
133 static void imx_pd_encoder_mode_set(struct drm_encoder *encoder,
134                          struct drm_display_mode *mode,
135                          struct drm_display_mode *adjusted_mode)
136 {
137 }
138 
139 static void imx_pd_encoder_disable(struct drm_encoder *encoder)
140 {
141 }
142 
143 static struct drm_connector_funcs imx_pd_connector_funcs = {
144         .dpms = drm_helper_connector_dpms,
145         .fill_modes = drm_helper_probe_single_connector_modes,
146         .detect = imx_pd_connector_detect,
147         .destroy = imx_drm_connector_destroy,
148 };
149 
150 static struct drm_connector_helper_funcs imx_pd_connector_helper_funcs = {
151         .get_modes = imx_pd_connector_get_modes,
152         .best_encoder = imx_pd_connector_best_encoder,
153 };
154 
155 static struct drm_encoder_funcs imx_pd_encoder_funcs = {
156         .destroy = imx_drm_encoder_destroy,
157 };
158 
159 static struct drm_encoder_helper_funcs imx_pd_encoder_helper_funcs = {
160         .dpms = imx_pd_encoder_dpms,
161         .mode_fixup = imx_pd_encoder_mode_fixup,
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,
166 };
167 
168 static int imx_pd_register(struct drm_device *drm,
169         struct imx_parallel_display *imxpd)
170 {
171         int ret;
172 
173         ret = imx_drm_encoder_parse_of(drm, &imxpd->encoder,
174                                        imxpd->dev->of_node);
175         if (ret)
176                 return ret;
177 
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.
182          */
183         imxpd->connector.dpms = DRM_MODE_DPMS_OFF;
184 
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);
188 
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);
193 
194         if (imxpd->panel)
195                 drm_panel_attach(imxpd->panel, &imxpd->connector);
196 
197         drm_mode_connector_attach_encoder(&imxpd->connector, &imxpd->encoder);
198 
199         imxpd->connector.encoder = &imxpd->encoder;
200 
201         return 0;
202 }
203 
204 static int imx_pd_bind(struct device *dev, struct device *master, void *data)
205 {
206         struct drm_device *drm = data;
207         struct device_node *np = dev->of_node;
208         struct device_node *panel_node;
209         const u8 *edidp;
210         struct imx_parallel_display *imxpd;
211         int ret;
212         const char *fmt;
213 
214         imxpd = devm_kzalloc(dev, sizeof(*imxpd), GFP_KERNEL);
215         if (!imxpd)
216                 return -ENOMEM;
217 
218         edidp = of_get_property(np, "edid", &imxpd->edid_len);
219         if (edidp)
220                 imxpd->edid = kmemdup(edidp, imxpd->edid_len, GFP_KERNEL);
221 
222         ret = of_property_read_string(np, "interface-pix-fmt", &fmt);
223         if (!ret) {
224                 if (!strcmp(fmt, "rgb24"))
225                         imxpd->interface_pix_fmt = V4L2_PIX_FMT_RGB24;
226                 else if (!strcmp(fmt, "rgb565"))
227                         imxpd->interface_pix_fmt = V4L2_PIX_FMT_RGB565;
228                 else if (!strcmp(fmt, "bgr666"))
229                         imxpd->interface_pix_fmt = V4L2_PIX_FMT_BGR666;
230                 else if (!strcmp(fmt, "lvds666"))
231                         imxpd->interface_pix_fmt =
232                                         v4l2_fourcc('L', 'V', 'D', '6');
233         }
234 
235         panel_node = of_parse_phandle(np, "fsl,panel", 0);
236         if (panel_node)
237                 imxpd->panel = of_drm_find_panel(panel_node);
238 
239         imxpd->dev = dev;
240 
241         ret = imx_pd_register(drm, imxpd);
242         if (ret)
243                 return ret;
244 
245         dev_set_drvdata(dev, imxpd);
246 
247         return 0;
248 }
249 
250 static void imx_pd_unbind(struct device *dev, struct device *master,
251         void *data)
252 {
253         struct imx_parallel_display *imxpd = dev_get_drvdata(dev);
254 
255         imxpd->encoder.funcs->destroy(&imxpd->encoder);
256         imxpd->connector.funcs->destroy(&imxpd->connector);
257 }
258 
259 static const struct component_ops imx_pd_ops = {
260         .bind   = imx_pd_bind,
261         .unbind = imx_pd_unbind,
262 };
263 
264 static int imx_pd_probe(struct platform_device *pdev)
265 {
266         return component_add(&pdev->dev, &imx_pd_ops);
267 }
268 
269 static int imx_pd_remove(struct platform_device *pdev)
270 {
271         component_del(&pdev->dev, &imx_pd_ops);
272         return 0;
273 }
274 
275 static const struct of_device_id imx_pd_dt_ids[] = {
276         { .compatible = "fsl,imx-parallel-display", },
277         { /* sentinel */ }
278 };
279 MODULE_DEVICE_TABLE(of, imx_pd_dt_ids);
280 
281 static struct platform_driver imx_pd_driver = {
282         .probe          = imx_pd_probe,
283         .remove         = imx_pd_remove,
284         .driver         = {
285                 .of_match_table = imx_pd_dt_ids,
286                 .name   = "imx-parallel-display",
287                 .owner  = THIS_MODULE,
288         },
289 };
290 
291 module_platform_driver(imx_pd_driver);
292 
293 MODULE_DESCRIPTION("i.MX parallel display driver");
294 MODULE_AUTHOR("Sascha Hauer, Pengutronix");
295 MODULE_LICENSE("GPL");
296 MODULE_ALIAS("platform:imx-parallel-display");
297 

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