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/consumer.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 "../dss/omapdss.h"
20 struct panel_drv_data {
21 struct omap_dss_device dssdev;
22 struct omap_dss_device *in;
29 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
31 static int tfp410_connect(struct omap_dss_device *dssdev,
32 struct omap_dss_device *dst)
34 struct panel_drv_data *ddata = to_panel_data(dssdev);
35 struct omap_dss_device *in = ddata->in;
38 if (omapdss_device_is_connected(dssdev))
41 r = in->ops.dpi->connect(in, dssdev);
51 static void tfp410_disconnect(struct omap_dss_device *dssdev,
52 struct omap_dss_device *dst)
54 struct panel_drv_data *ddata = to_panel_data(dssdev);
55 struct omap_dss_device *in = ddata->in;
57 WARN_ON(!omapdss_device_is_connected(dssdev));
58 if (!omapdss_device_is_connected(dssdev))
61 WARN_ON(dst != dssdev->dst);
62 if (dst != dssdev->dst)
68 in->ops.dpi->disconnect(in, &ddata->dssdev);
71 static int tfp410_enable(struct omap_dss_device *dssdev)
73 struct panel_drv_data *ddata = to_panel_data(dssdev);
74 struct omap_dss_device *in = ddata->in;
77 if (!omapdss_device_is_connected(dssdev))
80 if (omapdss_device_is_enabled(dssdev))
83 in->ops.dpi->set_timings(in, &ddata->vm);
85 r = in->ops.dpi->enable(in);
89 if (gpio_is_valid(ddata->pd_gpio))
90 gpio_set_value_cansleep(ddata->pd_gpio, 1);
92 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
97 static void tfp410_disable(struct omap_dss_device *dssdev)
99 struct panel_drv_data *ddata = to_panel_data(dssdev);
100 struct omap_dss_device *in = ddata->in;
102 if (!omapdss_device_is_enabled(dssdev))
105 if (gpio_is_valid(ddata->pd_gpio))
106 gpio_set_value_cansleep(ddata->pd_gpio, 0);
108 in->ops.dpi->disable(in);
110 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
113 static void tfp410_fix_timings(struct videomode *vm)
115 vm->flags |= DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_PIXDATA_POSEDGE |
116 DISPLAY_FLAGS_SYNC_POSEDGE;
119 static void tfp410_set_timings(struct omap_dss_device *dssdev,
120 struct videomode *vm)
122 struct panel_drv_data *ddata = to_panel_data(dssdev);
123 struct omap_dss_device *in = ddata->in;
125 tfp410_fix_timings(vm);
128 dssdev->panel.vm = *vm;
130 in->ops.dpi->set_timings(in, vm);
133 static void tfp410_get_timings(struct omap_dss_device *dssdev,
134 struct videomode *vm)
136 struct panel_drv_data *ddata = to_panel_data(dssdev);
141 static int tfp410_check_timings(struct omap_dss_device *dssdev,
142 struct videomode *vm)
144 struct panel_drv_data *ddata = to_panel_data(dssdev);
145 struct omap_dss_device *in = ddata->in;
147 tfp410_fix_timings(vm);
149 return in->ops.dpi->check_timings(in, vm);
152 static const struct omapdss_dvi_ops tfp410_dvi_ops = {
153 .connect = tfp410_connect,
154 .disconnect = tfp410_disconnect,
156 .enable = tfp410_enable,
157 .disable = tfp410_disable,
159 .check_timings = tfp410_check_timings,
160 .set_timings = tfp410_set_timings,
161 .get_timings = tfp410_get_timings,
164 static int tfp410_probe_of(struct platform_device *pdev)
166 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
167 struct device_node *node = pdev->dev.of_node;
168 struct omap_dss_device *in;
171 gpio = of_get_named_gpio(node, "powerdown-gpios", 0);
173 if (gpio_is_valid(gpio) || gpio == -ENOENT) {
174 ddata->pd_gpio = gpio;
176 dev_err(&pdev->dev, "failed to parse PD gpio\n");
180 in = omapdss_of_find_source_for_first_ep(node);
182 dev_err(&pdev->dev, "failed to find video source\n");
191 static int tfp410_probe(struct platform_device *pdev)
193 struct panel_drv_data *ddata;
194 struct omap_dss_device *dssdev;
197 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
201 platform_set_drvdata(pdev, ddata);
203 if (!pdev->dev.of_node)
206 r = tfp410_probe_of(pdev);
210 if (gpio_is_valid(ddata->pd_gpio)) {
211 r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
212 GPIOF_OUT_INIT_LOW, "tfp410 PD");
214 dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
220 dssdev = &ddata->dssdev;
221 dssdev->ops.dvi = &tfp410_dvi_ops;
222 dssdev->dev = &pdev->dev;
223 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
224 dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
225 dssdev->owner = THIS_MODULE;
226 dssdev->port_num = 1;
228 r = omapdss_register_output(dssdev);
230 dev_err(&pdev->dev, "Failed to register output\n");
237 omap_dss_put_device(ddata->in);
241 static int __exit tfp410_remove(struct platform_device *pdev)
243 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
244 struct omap_dss_device *dssdev = &ddata->dssdev;
245 struct omap_dss_device *in = ddata->in;
247 omapdss_unregister_output(&ddata->dssdev);
249 WARN_ON(omapdss_device_is_enabled(dssdev));
250 if (omapdss_device_is_enabled(dssdev))
251 tfp410_disable(dssdev);
253 WARN_ON(omapdss_device_is_connected(dssdev));
254 if (omapdss_device_is_connected(dssdev))
255 tfp410_disconnect(dssdev, dssdev->dst);
257 omap_dss_put_device(in);
262 static const struct of_device_id tfp410_of_match[] = {
263 { .compatible = "omapdss,ti,tfp410", },
267 MODULE_DEVICE_TABLE(of, tfp410_of_match);
269 static struct platform_driver tfp410_driver = {
270 .probe = tfp410_probe,
271 .remove = __exit_p(tfp410_remove),
274 .of_match_table = tfp410_of_match,
275 .suppress_bind_attrs = true,
279 module_platform_driver(tfp410_driver);
281 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
282 MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
283 MODULE_LICENSE("GPL");