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

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         .mode_valid = imx_drm_connector_mode_valid,
152 };
153 
154 static struct drm_encoder_funcs imx_pd_encoder_funcs = {
155         .destroy = imx_drm_encoder_destroy,
156 };
157 
158 static struct drm_encoder_helper_funcs imx_pd_encoder_helper_funcs = {
159         .dpms = imx_pd_encoder_dpms,
160         .mode_fixup = imx_pd_encoder_mode_fixup,
161         .prepare = imx_pd_encoder_prepare,
162         .commit = imx_pd_encoder_commit,
163         .mode_set = imx_pd_encoder_mode_set,
164         .disable = imx_pd_encoder_disable,
165 };
166 
167 static int imx_pd_register(struct drm_device *drm,
168         struct imx_parallel_display *imxpd)
169 {
170         int ret;
171 
172         ret = imx_drm_encoder_parse_of(drm, &imxpd->encoder,
173                                        imxpd->dev->of_node);
174         if (ret)
175                 return ret;
176 
177         drm_encoder_helper_add(&imxpd->encoder, &imx_pd_encoder_helper_funcs);
178         drm_encoder_init(drm, &imxpd->encoder, &imx_pd_encoder_funcs,
179                          DRM_MODE_ENCODER_NONE);
180 
181         drm_connector_helper_add(&imxpd->connector,
182                         &imx_pd_connector_helper_funcs);
183         drm_connector_init(drm, &imxpd->connector, &imx_pd_connector_funcs,
184                            DRM_MODE_CONNECTOR_VGA);
185 
186         if (imxpd->panel)
187                 drm_panel_attach(imxpd->panel, &imxpd->connector);
188 
189         drm_mode_connector_attach_encoder(&imxpd->connector, &imxpd->encoder);
190 
191         imxpd->connector.encoder = &imxpd->encoder;
192 
193         return 0;
194 }
195 
196 static int imx_pd_bind(struct device *dev, struct device *master, void *data)
197 {
198         struct drm_device *drm = data;
199         struct device_node *np = dev->of_node;
200         struct device_node *panel_node;
201         const u8 *edidp;
202         struct imx_parallel_display *imxpd;
203         int ret;
204         const char *fmt;
205 
206         imxpd = devm_kzalloc(dev, sizeof(*imxpd), GFP_KERNEL);
207         if (!imxpd)
208                 return -ENOMEM;
209 
210         edidp = of_get_property(np, "edid", &imxpd->edid_len);
211         if (edidp)
212                 imxpd->edid = kmemdup(edidp, imxpd->edid_len, GFP_KERNEL);
213 
214         ret = of_property_read_string(np, "interface-pix-fmt", &fmt);
215         if (!ret) {
216                 if (!strcmp(fmt, "rgb24"))
217                         imxpd->interface_pix_fmt = V4L2_PIX_FMT_RGB24;
218                 else if (!strcmp(fmt, "rgb565"))
219                         imxpd->interface_pix_fmt = V4L2_PIX_FMT_RGB565;
220                 else if (!strcmp(fmt, "bgr666"))
221                         imxpd->interface_pix_fmt = V4L2_PIX_FMT_BGR666;
222         }
223 
224         panel_node = of_parse_phandle(np, "fsl,panel", 0);
225         if (panel_node)
226                 imxpd->panel = of_drm_find_panel(panel_node);
227 
228         imxpd->dev = dev;
229 
230         ret = imx_pd_register(drm, imxpd);
231         if (ret)
232                 return ret;
233 
234         dev_set_drvdata(dev, imxpd);
235 
236         return 0;
237 }
238 
239 static void imx_pd_unbind(struct device *dev, struct device *master,
240         void *data)
241 {
242         struct imx_parallel_display *imxpd = dev_get_drvdata(dev);
243 
244         imxpd->encoder.funcs->destroy(&imxpd->encoder);
245         imxpd->connector.funcs->destroy(&imxpd->connector);
246 }
247 
248 static const struct component_ops imx_pd_ops = {
249         .bind   = imx_pd_bind,
250         .unbind = imx_pd_unbind,
251 };
252 
253 static int imx_pd_probe(struct platform_device *pdev)
254 {
255         return component_add(&pdev->dev, &imx_pd_ops);
256 }
257 
258 static int imx_pd_remove(struct platform_device *pdev)
259 {
260         component_del(&pdev->dev, &imx_pd_ops);
261         return 0;
262 }
263 
264 static const struct of_device_id imx_pd_dt_ids[] = {
265         { .compatible = "fsl,imx-parallel-display", },
266         { /* sentinel */ }
267 };
268 MODULE_DEVICE_TABLE(of, imx_pd_dt_ids);
269 
270 static struct platform_driver imx_pd_driver = {
271         .probe          = imx_pd_probe,
272         .remove         = imx_pd_remove,
273         .driver         = {
274                 .of_match_table = imx_pd_dt_ids,
275                 .name   = "imx-parallel-display",
276                 .owner  = THIS_MODULE,
277         },
278 };
279 
280 module_platform_driver(imx_pd_driver);
281 
282 MODULE_DESCRIPTION("i.MX parallel display driver");
283 MODULE_AUTHOR("Sascha Hauer, Pengutronix");
284 MODULE_LICENSE("GPL");
285 MODULE_ALIAS("platform:imx-parallel-display");
286 

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