Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
parallel-display.c
Go to the documentation of this file.
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/module.h>
22 #include <drm/drmP.h>
23 #include <drm/drm_fb_helper.h>
24 #include <drm/drm_crtc_helper.h>
25 #include <linux/videodev2.h>
26 
27 #include "imx-drm.h"
28 
29 #define con_to_imxpd(x) container_of(x, struct imx_parallel_display, connector)
30 #define enc_to_imxpd(x) container_of(x, struct imx_parallel_display, encoder)
31 
37  struct device *dev;
38  void *edid;
39  int edid_len;
43 };
44 
45 static enum drm_connector_status imx_pd_connector_detect(
46  struct drm_connector *connector, bool force)
47 {
49 }
50 
51 static void imx_pd_connector_destroy(struct drm_connector *connector)
52 {
53  /* do not free here */
54 }
55 
56 static int imx_pd_connector_get_modes(struct drm_connector *connector)
57 {
58  struct imx_parallel_display *imxpd = con_to_imxpd(connector);
59  int num_modes = 0;
60 
61  if (imxpd->edid) {
63  num_modes = drm_add_edid_modes(connector, imxpd->edid);
64  }
65 
66  if (imxpd->mode_valid) {
67  struct drm_display_mode *mode = drm_mode_create(connector->dev);
68  drm_mode_copy(mode, &imxpd->mode);
70  drm_mode_probed_add(connector, mode);
71  num_modes++;
72  }
73 
74  return num_modes;
75 }
76 
77 static int imx_pd_connector_mode_valid(struct drm_connector *connector,
78  struct drm_display_mode *mode)
79 {
80  return 0;
81 }
82 
83 static struct drm_encoder *imx_pd_connector_best_encoder(
84  struct drm_connector *connector)
85 {
86  struct imx_parallel_display *imxpd = con_to_imxpd(connector);
87 
88  return &imxpd->encoder;
89 }
90 
91 static void imx_pd_encoder_dpms(struct drm_encoder *encoder, int mode)
92 {
93 }
94 
95 static bool imx_pd_encoder_mode_fixup(struct drm_encoder *encoder,
96  const struct drm_display_mode *mode,
97  struct drm_display_mode *adjusted_mode)
98 {
99  return true;
100 }
101 
102 static void imx_pd_encoder_prepare(struct drm_encoder *encoder)
103 {
104  struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
105 
107  imxpd->interface_pix_fmt);
108 }
109 
110 static void imx_pd_encoder_commit(struct drm_encoder *encoder)
111 {
112 }
113 
114 static void imx_pd_encoder_mode_set(struct drm_encoder *encoder,
115  struct drm_display_mode *mode,
116  struct drm_display_mode *adjusted_mode)
117 {
118 }
119 
120 static void imx_pd_encoder_disable(struct drm_encoder *encoder)
121 {
122 }
123 
124 static void imx_pd_encoder_destroy(struct drm_encoder *encoder)
125 {
126  /* do not free here */
127 }
128 
129 static struct drm_connector_funcs imx_pd_connector_funcs = {
132  .detect = imx_pd_connector_detect,
133  .destroy = imx_pd_connector_destroy,
134 };
135 
136 static struct drm_connector_helper_funcs imx_pd_connector_helper_funcs = {
137  .get_modes = imx_pd_connector_get_modes,
138  .best_encoder = imx_pd_connector_best_encoder,
139  .mode_valid = imx_pd_connector_mode_valid,
140 };
141 
142 static struct drm_encoder_funcs imx_pd_encoder_funcs = {
143  .destroy = imx_pd_encoder_destroy,
144 };
145 
146 static struct drm_encoder_helper_funcs imx_pd_encoder_helper_funcs = {
147  .dpms = imx_pd_encoder_dpms,
148  .mode_fixup = imx_pd_encoder_mode_fixup,
149  .prepare = imx_pd_encoder_prepare,
150  .commit = imx_pd_encoder_commit,
151  .mode_set = imx_pd_encoder_mode_set,
152  .disable = imx_pd_encoder_disable,
153 };
154 
155 static int imx_pd_register(struct imx_parallel_display *imxpd)
156 {
157  int ret;
158 
160 
161  imxpd->connector.funcs = &imx_pd_connector_funcs;
162  imxpd->encoder.funcs = &imx_pd_encoder_funcs;
163 
164  imxpd->encoder.encoder_type = DRM_MODE_ENCODER_NONE;
165  imxpd->connector.connector_type = DRM_MODE_CONNECTOR_VGA;
166 
167  drm_encoder_helper_add(&imxpd->encoder, &imx_pd_encoder_helper_funcs);
168  ret = imx_drm_add_encoder(&imxpd->encoder, &imxpd->imx_drm_encoder,
169  THIS_MODULE);
170  if (ret) {
171  dev_err(imxpd->dev, "adding encoder failed with %d\n", ret);
172  return ret;
173  }
174 
175  drm_connector_helper_add(&imxpd->connector,
176  &imx_pd_connector_helper_funcs);
177 
178  ret = imx_drm_add_connector(&imxpd->connector,
179  &imxpd->imx_drm_connector, THIS_MODULE);
180  if (ret) {
182  dev_err(imxpd->dev, "adding connector failed with %d\n", ret);
183  return ret;
184  }
185 
186  imxpd->connector.encoder = &imxpd->encoder;
187 
188  return 0;
189 }
190 
191 static int __devinit imx_pd_probe(struct platform_device *pdev)
192 {
193  struct device_node *np = pdev->dev.of_node;
194  const u8 *edidp;
195  struct imx_parallel_display *imxpd;
196  int ret;
197  const char *fmt;
198 
199  imxpd = devm_kzalloc(&pdev->dev, sizeof(*imxpd), GFP_KERNEL);
200  if (!imxpd)
201  return -ENOMEM;
202 
203  edidp = of_get_property(np, "edid", &imxpd->edid_len);
204  if (edidp)
205  imxpd->edid = kmemdup(edidp, imxpd->edid_len, GFP_KERNEL);
206 
207  ret = of_property_read_string(np, "interface-pix-fmt", &fmt);
208  if (!ret) {
209  if (!strcmp(fmt, "rgb24"))
211  else if (!strcmp(fmt, "rgb565"))
213  }
214 
215  imxpd->dev = &pdev->dev;
216 
217  ret = imx_pd_register(imxpd);
218  if (ret)
219  return ret;
220 
222 
223  platform_set_drvdata(pdev, imxpd);
224 
225  return 0;
226 }
227 
228 static int __devexit imx_pd_remove(struct platform_device *pdev)
229 {
230  struct imx_parallel_display *imxpd = platform_get_drvdata(pdev);
231  struct drm_connector *connector = &imxpd->connector;
232  struct drm_encoder *encoder = &imxpd->encoder;
233 
234  drm_mode_connector_detach_encoder(connector, encoder);
235 
238 
239  return 0;
240 }
241 
242 static const struct of_device_id imx_pd_dt_ids[] = {
243  { .compatible = "fsl,imx-parallel-display", },
244  { /* sentinel */ }
245 };
246 
247 static struct platform_driver imx_pd_driver = {
248  .probe = imx_pd_probe,
249  .remove = __devexit_p(imx_pd_remove),
250  .driver = {
251  .of_match_table = imx_pd_dt_ids,
252  .name = "imx-parallel-display",
253  .owner = THIS_MODULE,
254  },
255 };
256 
257 module_platform_driver(imx_pd_driver);
258 
259 MODULE_DESCRIPTION("i.MX parallel display driver");
260 MODULE_AUTHOR("Sascha Hauer, Pengutronix");
261 MODULE_LICENSE("GPL");