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
;
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
;
39 if (omapdss_device_is_connected(dssdev
))
42 r
= in
->ops
.dpi
->connect(in
, dssdev
);
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
))
62 WARN_ON(dst
!= dssdev
->dst
);
63 if (dst
!= dssdev
->dst
)
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
;
78 if (!omapdss_device_is_connected(dssdev
))
81 if (omapdss_device_is_enabled(dssdev
))
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
);
91 if (gpio_is_valid(ddata
->pd_gpio
))
92 gpio_set_value_cansleep(ddata
->pd_gpio
, 1);
94 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
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
))
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
);
170 dev_err(&pdev
->dev
, "Failed to find video source\n");
176 dssdev
= &ddata
->dssdev
;
177 dssdev
->name
= pdata
->name
;
182 static int tfp410_probe(struct platform_device
*pdev
)
184 struct panel_drv_data
*ddata
;
185 struct omap_dss_device
*dssdev
;
188 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
192 platform_set_drvdata(pdev
, ddata
);
194 if (dev_get_platdata(&pdev
->dev
)) {
195 r
= tfp410_probe_pdata(pdev
);
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");
206 dev_err(&pdev
->dev
, "Failed to request PD GPIO %d\n",
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
);
222 dev_err(&pdev
->dev
, "Failed to register output\n");
229 omap_dss_put_device(ddata
->in
);
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
);
254 static struct platform_driver tfp410_driver
= {
255 .probe
= tfp410_probe
,
256 .remove
= __exit_p(tfp410_remove
),
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");