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>
16 #include <linux/of_gpio.h>
18 #include <video/omapdss.h>
19 #include <video/omap-panel-data.h>
21 struct panel_drv_data {
22 struct omap_dss_device dssdev;
23 struct omap_dss_device *in;
28 struct omap_video_timings timings;
31 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
33 static int tfp410_connect(struct omap_dss_device *dssdev,
34 struct omap_dss_device *dst)
36 struct panel_drv_data *ddata = to_panel_data(dssdev);
37 struct omap_dss_device *in = ddata->in;
40 if (omapdss_device_is_connected(dssdev))
43 r = in->ops.dpi->connect(in, dssdev);
53 static void tfp410_disconnect(struct omap_dss_device *dssdev,
54 struct omap_dss_device *dst)
56 struct panel_drv_data *ddata = to_panel_data(dssdev);
57 struct omap_dss_device *in = ddata->in;
59 WARN_ON(!omapdss_device_is_connected(dssdev));
60 if (!omapdss_device_is_connected(dssdev))
63 WARN_ON(dst != dssdev->dst);
64 if (dst != dssdev->dst)
70 in->ops.dpi->disconnect(in, &ddata->dssdev);
73 static int tfp410_enable(struct omap_dss_device *dssdev)
75 struct panel_drv_data *ddata = to_panel_data(dssdev);
76 struct omap_dss_device *in = ddata->in;
79 if (!omapdss_device_is_connected(dssdev))
82 if (omapdss_device_is_enabled(dssdev))
85 in->ops.dpi->set_timings(in, &ddata->timings);
86 if (ddata->data_lines)
87 in->ops.dpi->set_data_lines(in, ddata->data_lines);
89 r = in->ops.dpi->enable(in);
93 if (gpio_is_valid(ddata->pd_gpio))
94 gpio_set_value_cansleep(ddata->pd_gpio, 1);
96 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
101 static void tfp410_disable(struct omap_dss_device *dssdev)
103 struct panel_drv_data *ddata = to_panel_data(dssdev);
104 struct omap_dss_device *in = ddata->in;
106 if (!omapdss_device_is_enabled(dssdev))
109 if (gpio_is_valid(ddata->pd_gpio))
110 gpio_set_value_cansleep(ddata->pd_gpio, 0);
112 in->ops.dpi->disable(in);
114 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
117 static void tfp410_set_timings(struct omap_dss_device *dssdev,
118 struct omap_video_timings *timings)
120 struct panel_drv_data *ddata = to_panel_data(dssdev);
121 struct omap_dss_device *in = ddata->in;
123 ddata->timings = *timings;
124 dssdev->panel.timings = *timings;
126 in->ops.dpi->set_timings(in, timings);
129 static void tfp410_get_timings(struct omap_dss_device *dssdev,
130 struct omap_video_timings *timings)
132 struct panel_drv_data *ddata = to_panel_data(dssdev);
134 *timings = ddata->timings;
137 static int tfp410_check_timings(struct omap_dss_device *dssdev,
138 struct omap_video_timings *timings)
140 struct panel_drv_data *ddata = to_panel_data(dssdev);
141 struct omap_dss_device *in = ddata->in;
143 return in->ops.dpi->check_timings(in, timings);
146 static const struct omapdss_dvi_ops tfp410_dvi_ops = {
147 .connect = tfp410_connect,
148 .disconnect = tfp410_disconnect,
150 .enable = tfp410_enable,
151 .disable = tfp410_disable,
153 .check_timings = tfp410_check_timings,
154 .set_timings = tfp410_set_timings,
155 .get_timings = tfp410_get_timings,
158 static int tfp410_probe_pdata(struct platform_device *pdev)
160 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
161 struct encoder_tfp410_platform_data *pdata;
162 struct omap_dss_device *dssdev, *in;
164 pdata = dev_get_platdata(&pdev->dev);
166 ddata->pd_gpio = pdata->power_down_gpio;
168 ddata->data_lines = pdata->data_lines;
170 in = omap_dss_find_output(pdata->source);
172 dev_err(&pdev->dev, "Failed to find video source\n");
178 dssdev = &ddata->dssdev;
179 dssdev->name = pdata->name;
184 static int tfp410_probe_of(struct platform_device *pdev)
186 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
187 struct device_node *node = pdev->dev.of_node;
188 struct omap_dss_device *in;
191 gpio = of_get_named_gpio(node, "powerdown-gpios", 0);
193 if (gpio_is_valid(gpio) || gpio == -ENOENT) {
194 ddata->pd_gpio = gpio;
196 dev_err(&pdev->dev, "failed to parse PD gpio\n");
200 in = omapdss_of_find_source_for_first_ep(node);
202 dev_err(&pdev->dev, "failed to find video source\n");
211 static int tfp410_probe(struct platform_device *pdev)
213 struct panel_drv_data *ddata;
214 struct omap_dss_device *dssdev;
217 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
221 platform_set_drvdata(pdev, ddata);
223 if (dev_get_platdata(&pdev->dev)) {
224 r = tfp410_probe_pdata(pdev);
227 } else if (pdev->dev.of_node) {
228 r = tfp410_probe_of(pdev);
235 if (gpio_is_valid(ddata->pd_gpio)) {
236 r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
237 GPIOF_OUT_INIT_LOW, "tfp410 PD");
239 dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
245 dssdev = &ddata->dssdev;
246 dssdev->ops.dvi = &tfp410_dvi_ops;
247 dssdev->dev = &pdev->dev;
248 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
249 dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
250 dssdev->owner = THIS_MODULE;
251 dssdev->phy.dpi.data_lines = ddata->data_lines;
253 r = omapdss_register_output(dssdev);
255 dev_err(&pdev->dev, "Failed to register output\n");
262 omap_dss_put_device(ddata->in);
266 static int __exit tfp410_remove(struct platform_device *pdev)
268 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
269 struct omap_dss_device *dssdev = &ddata->dssdev;
270 struct omap_dss_device *in = ddata->in;
272 omapdss_unregister_output(&ddata->dssdev);
274 WARN_ON(omapdss_device_is_enabled(dssdev));
275 if (omapdss_device_is_enabled(dssdev))
276 tfp410_disable(dssdev);
278 WARN_ON(omapdss_device_is_connected(dssdev));
279 if (omapdss_device_is_connected(dssdev))
280 tfp410_disconnect(dssdev, dssdev->dst);
282 omap_dss_put_device(in);
287 static const struct of_device_id tfp410_of_match[] = {
288 { .compatible = "omapdss,ti,tfp410", },
292 MODULE_DEVICE_TABLE(of, tfp410_of_match);
294 static struct platform_driver tfp410_driver = {
295 .probe = tfp410_probe,
296 .remove = __exit_p(tfp410_remove),
299 .owner = THIS_MODULE,
300 .of_match_table = tfp410_of_match,
301 .suppress_bind_attrs = true,
305 module_platform_driver(tfp410_driver);
307 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
308 MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
309 MODULE_LICENSE("GPL");