mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / video / omap2 / displays-new / encoder-tfp410.c
blob4a291e756be944cfc0dcb647312d520891bca4e0
1 /*
2 * TFP410 DPI-to-DVI encoder driver
4 * Copyright (C) 2013 Texas Instruments
5 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
12 #include <linux/gpio.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/slab.h>
17 #include <video/omapdss.h>
18 #include <video/omap-panel-data.h>
20 struct panel_drv_data {
21 struct omap_dss_device dssdev;
22 struct omap_dss_device *in;
24 int pd_gpio;
25 int data_lines;
27 struct omap_video_timings timings;
30 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
32 static int tfp410_connect(struct omap_dss_device *dssdev,
33 struct omap_dss_device *dst)
35 struct panel_drv_data *ddata = to_panel_data(dssdev);
36 struct omap_dss_device *in = ddata->in;
37 int r;
39 if (omapdss_device_is_connected(dssdev))
40 return -EBUSY;
42 r = in->ops.dpi->connect(in, dssdev);
43 if (r)
44 return r;
46 dst->src = dssdev;
47 dssdev->dst = dst;
49 return 0;
52 static void tfp410_disconnect(struct omap_dss_device *dssdev,
53 struct omap_dss_device *dst)
55 struct panel_drv_data *ddata = to_panel_data(dssdev);
56 struct omap_dss_device *in = ddata->in;
58 WARN_ON(!omapdss_device_is_connected(dssdev));
59 if (!omapdss_device_is_connected(dssdev))
60 return;
62 WARN_ON(dst != dssdev->dst);
63 if (dst != dssdev->dst)
64 return;
66 dst->src = NULL;
67 dssdev->dst = NULL;
69 in->ops.dpi->disconnect(in, &ddata->dssdev);
72 static int tfp410_enable(struct omap_dss_device *dssdev)
74 struct panel_drv_data *ddata = to_panel_data(dssdev);
75 struct omap_dss_device *in = ddata->in;
76 int r;
78 if (!omapdss_device_is_connected(dssdev))
79 return -ENODEV;
81 if (omapdss_device_is_enabled(dssdev))
82 return 0;
84 in->ops.dpi->set_timings(in, &ddata->timings);
85 in->ops.dpi->set_data_lines(in, ddata->data_lines);
87 r = in->ops.dpi->enable(in);
88 if (r)
89 return r;
91 if (gpio_is_valid(ddata->pd_gpio))
92 gpio_set_value_cansleep(ddata->pd_gpio, 1);
94 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
96 return 0;
99 static void tfp410_disable(struct omap_dss_device *dssdev)
101 struct panel_drv_data *ddata = to_panel_data(dssdev);
102 struct omap_dss_device *in = ddata->in;
104 if (!omapdss_device_is_enabled(dssdev))
105 return;
107 if (gpio_is_valid(ddata->pd_gpio))
108 gpio_set_value_cansleep(ddata->pd_gpio, 0);
110 in->ops.dpi->disable(in);
112 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
115 static void tfp410_set_timings(struct omap_dss_device *dssdev,
116 struct omap_video_timings *timings)
118 struct panel_drv_data *ddata = to_panel_data(dssdev);
119 struct omap_dss_device *in = ddata->in;
121 ddata->timings = *timings;
122 dssdev->panel.timings = *timings;
124 in->ops.dpi->set_timings(in, timings);
127 static void tfp410_get_timings(struct omap_dss_device *dssdev,
128 struct omap_video_timings *timings)
130 struct panel_drv_data *ddata = to_panel_data(dssdev);
132 *timings = ddata->timings;
135 static int tfp410_check_timings(struct omap_dss_device *dssdev,
136 struct omap_video_timings *timings)
138 struct panel_drv_data *ddata = to_panel_data(dssdev);
139 struct omap_dss_device *in = ddata->in;
141 return in->ops.dpi->check_timings(in, timings);
144 static const struct omapdss_dvi_ops tfp410_dvi_ops = {
145 .connect = tfp410_connect,
146 .disconnect = tfp410_disconnect,
148 .enable = tfp410_enable,
149 .disable = tfp410_disable,
151 .check_timings = tfp410_check_timings,
152 .set_timings = tfp410_set_timings,
153 .get_timings = tfp410_get_timings,
156 static int tfp410_probe_pdata(struct platform_device *pdev)
158 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
159 struct encoder_tfp410_platform_data *pdata;
160 struct omap_dss_device *dssdev, *in;
162 pdata = dev_get_platdata(&pdev->dev);
164 ddata->pd_gpio = pdata->power_down_gpio;
166 ddata->data_lines = pdata->data_lines;
168 in = omap_dss_find_output(pdata->source);
169 if (in == NULL) {
170 dev_err(&pdev->dev, "Failed to find video source\n");
171 return -ENODEV;
174 ddata->in = in;
176 dssdev = &ddata->dssdev;
177 dssdev->name = pdata->name;
179 return 0;
182 static int tfp410_probe(struct platform_device *pdev)
184 struct panel_drv_data *ddata;
185 struct omap_dss_device *dssdev;
186 int r;
188 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
189 if (!ddata)
190 return -ENOMEM;
192 platform_set_drvdata(pdev, ddata);
194 if (dev_get_platdata(&pdev->dev)) {
195 r = tfp410_probe_pdata(pdev);
196 if (r)
197 return r;
198 } else {
199 return -ENODEV;
202 if (gpio_is_valid(ddata->pd_gpio)) {
203 r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
204 GPIOF_OUT_INIT_LOW, "tfp410 PD");
205 if (r) {
206 dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
207 ddata->pd_gpio);
208 goto err_gpio;
212 dssdev = &ddata->dssdev;
213 dssdev->ops.dvi = &tfp410_dvi_ops;
214 dssdev->dev = &pdev->dev;
215 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
216 dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
217 dssdev->owner = THIS_MODULE;
218 dssdev->phy.dpi.data_lines = ddata->data_lines;
220 r = omapdss_register_output(dssdev);
221 if (r) {
222 dev_err(&pdev->dev, "Failed to register output\n");
223 goto err_reg;
226 return 0;
227 err_reg:
228 err_gpio:
229 omap_dss_put_device(ddata->in);
230 return r;
233 static int __exit tfp410_remove(struct platform_device *pdev)
235 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
236 struct omap_dss_device *dssdev = &ddata->dssdev;
237 struct omap_dss_device *in = ddata->in;
239 omapdss_unregister_output(&ddata->dssdev);
241 WARN_ON(omapdss_device_is_enabled(dssdev));
242 if (omapdss_device_is_enabled(dssdev))
243 tfp410_disable(dssdev);
245 WARN_ON(omapdss_device_is_connected(dssdev));
246 if (omapdss_device_is_connected(dssdev))
247 tfp410_disconnect(dssdev, dssdev->dst);
249 omap_dss_put_device(in);
251 return 0;
254 static struct platform_driver tfp410_driver = {
255 .probe = tfp410_probe,
256 .remove = __exit_p(tfp410_remove),
257 .driver = {
258 .name = "tfp410",
259 .owner = THIS_MODULE,
263 module_platform_driver(tfp410_driver);
265 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
266 MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
267 MODULE_LICENSE("GPL");