2 * TFP410 DPI-to-DVI encoder driver
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
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 if (gpio
!= -EPROBE_DEFER
)
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 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
202 platform_set_drvdata(pdev
, ddata
);
204 if (!pdev
->dev
.of_node
)
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
->port_num
= 1;
229 r
= omapdss_register_output(dssdev
);
231 dev_err(&pdev
->dev
, "Failed to register output\n");
238 omap_dss_put_device(ddata
->in
);
242 static int __exit
tfp410_remove(struct platform_device
*pdev
)
244 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
245 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
246 struct omap_dss_device
*in
= ddata
->in
;
248 omapdss_unregister_output(&ddata
->dssdev
);
250 WARN_ON(omapdss_device_is_enabled(dssdev
));
251 if (omapdss_device_is_enabled(dssdev
))
252 tfp410_disable(dssdev
);
254 WARN_ON(omapdss_device_is_connected(dssdev
));
255 if (omapdss_device_is_connected(dssdev
))
256 tfp410_disconnect(dssdev
, dssdev
->dst
);
258 omap_dss_put_device(in
);
263 static const struct of_device_id tfp410_of_match
[] = {
264 { .compatible
= "omapdss,ti,tfp410", },
268 MODULE_DEVICE_TABLE(of
, tfp410_of_match
);
270 static struct platform_driver tfp410_driver
= {
271 .probe
= tfp410_probe
,
272 .remove
= __exit_p(tfp410_remove
),
275 .of_match_table
= tfp410_of_match
,
276 .suppress_bind_attrs
= true,
280 module_platform_driver(tfp410_driver
);
282 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
283 MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
284 MODULE_LICENSE("GPL");