1 // SPDX-License-Identifier: GPL-2.0-only
3 * TFP410 DPI-to-DVI encoder driver
5 * Copyright (C) 2013 Texas Instruments
6 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
9 #include <linux/gpio.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/slab.h>
13 #include <linux/of_gpio.h>
15 #include <video/omapfb_dss.h>
17 struct panel_drv_data {
18 struct omap_dss_device dssdev;
19 struct omap_dss_device *in;
24 struct omap_video_timings timings;
27 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
29 static int tfp410_connect(struct omap_dss_device *dssdev,
30 struct omap_dss_device *dst)
32 struct panel_drv_data *ddata = to_panel_data(dssdev);
33 struct omap_dss_device *in = ddata->in;
36 if (omapdss_device_is_connected(dssdev))
39 r = in->ops.dpi->connect(in, dssdev);
49 static void tfp410_disconnect(struct omap_dss_device *dssdev,
50 struct omap_dss_device *dst)
52 struct panel_drv_data *ddata = to_panel_data(dssdev);
53 struct omap_dss_device *in = ddata->in;
55 WARN_ON(!omapdss_device_is_connected(dssdev));
56 if (!omapdss_device_is_connected(dssdev))
59 WARN_ON(dst != dssdev->dst);
60 if (dst != dssdev->dst)
66 in->ops.dpi->disconnect(in, &ddata->dssdev);
69 static int tfp410_enable(struct omap_dss_device *dssdev)
71 struct panel_drv_data *ddata = to_panel_data(dssdev);
72 struct omap_dss_device *in = ddata->in;
75 if (!omapdss_device_is_connected(dssdev))
78 if (omapdss_device_is_enabled(dssdev))
81 in->ops.dpi->set_timings(in, &ddata->timings);
82 if (ddata->data_lines)
83 in->ops.dpi->set_data_lines(in, ddata->data_lines);
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 omap_video_timings *timings)
115 timings->data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
116 timings->sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
117 timings->de_level = OMAPDSS_SIG_ACTIVE_HIGH;
120 static void tfp410_set_timings(struct omap_dss_device *dssdev,
121 struct omap_video_timings *timings)
123 struct panel_drv_data *ddata = to_panel_data(dssdev);
124 struct omap_dss_device *in = ddata->in;
126 tfp410_fix_timings(timings);
128 ddata->timings = *timings;
129 dssdev->panel.timings = *timings;
131 in->ops.dpi->set_timings(in, timings);
134 static void tfp410_get_timings(struct omap_dss_device *dssdev,
135 struct omap_video_timings *timings)
137 struct panel_drv_data *ddata = to_panel_data(dssdev);
139 *timings = ddata->timings;
142 static int tfp410_check_timings(struct omap_dss_device *dssdev,
143 struct omap_video_timings *timings)
145 struct panel_drv_data *ddata = to_panel_data(dssdev);
146 struct omap_dss_device *in = ddata->in;
148 tfp410_fix_timings(timings);
150 return in->ops.dpi->check_timings(in, timings);
153 static const struct omapdss_dvi_ops tfp410_dvi_ops = {
154 .connect = tfp410_connect,
155 .disconnect = tfp410_disconnect,
157 .enable = tfp410_enable,
158 .disable = tfp410_disable,
160 .check_timings = tfp410_check_timings,
161 .set_timings = tfp410_set_timings,
162 .get_timings = tfp410_get_timings,
165 static int tfp410_probe_of(struct platform_device *pdev)
167 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
168 struct device_node *node = pdev->dev.of_node;
169 struct omap_dss_device *in;
172 gpio = of_get_named_gpio(node, "powerdown-gpios", 0);
174 if (gpio_is_valid(gpio) || gpio == -ENOENT) {
175 ddata->pd_gpio = gpio;
177 dev_err(&pdev->dev, "failed to parse PD gpio\n");
181 in = omapdss_of_find_source_for_first_ep(node);
183 dev_err(&pdev->dev, "failed to find video source\n");
192 static int tfp410_probe(struct platform_device *pdev)
194 struct panel_drv_data *ddata;
195 struct omap_dss_device *dssdev;
198 if (!pdev->dev.of_node)
201 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
205 platform_set_drvdata(pdev, ddata);
207 r = tfp410_probe_of(pdev);
211 if (gpio_is_valid(ddata->pd_gpio)) {
212 r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
213 GPIOF_OUT_INIT_LOW, "tfp410 PD");
215 dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
221 dssdev = &ddata->dssdev;
222 dssdev->ops.dvi = &tfp410_dvi_ops;
223 dssdev->dev = &pdev->dev;
224 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
225 dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
226 dssdev->owner = THIS_MODULE;
227 dssdev->phy.dpi.data_lines = ddata->data_lines;
228 dssdev->port_num = 1;
230 r = omapdss_register_output(dssdev);
232 dev_err(&pdev->dev, "Failed to register output\n");
239 omap_dss_put_device(ddata->in);
243 static int __exit tfp410_remove(struct platform_device *pdev)
245 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
246 struct omap_dss_device *dssdev = &ddata->dssdev;
247 struct omap_dss_device *in = ddata->in;
249 omapdss_unregister_output(&ddata->dssdev);
251 WARN_ON(omapdss_device_is_enabled(dssdev));
252 if (omapdss_device_is_enabled(dssdev))
253 tfp410_disable(dssdev);
255 WARN_ON(omapdss_device_is_connected(dssdev));
256 if (omapdss_device_is_connected(dssdev))
257 tfp410_disconnect(dssdev, dssdev->dst);
259 omap_dss_put_device(in);
264 static const struct of_device_id tfp410_of_match[] = {
265 { .compatible = "omapdss,ti,tfp410", },
269 MODULE_DEVICE_TABLE(of, tfp410_of_match);
271 static struct platform_driver tfp410_driver = {
272 .probe = tfp410_probe,
273 .remove = __exit_p(tfp410_remove),
276 .of_match_table = tfp410_of_match,
277 .suppress_bind_attrs = true,
281 module_platform_driver(tfp410_driver);
283 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
284 MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
285 MODULE_LICENSE("GPL");