2 * OPA362 analog video amplifier with output/power control
4 * Copyright (C) 2014 Golden Delicious Computers
5 * Author: H. Nikolaus Schaller <hns@goldelico.com>
7 * based on encoder-tfp410
9 * Copyright (C) 2013 Texas Instruments
10 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published by
14 * the Free Software Foundation.
17 #include <linux/gpio.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
21 #include <linux/of_gpio.h>
23 #include <video/omapfb_dss.h>
25 struct panel_drv_data
{
26 struct omap_dss_device dssdev
;
27 struct omap_dss_device
*in
;
29 struct gpio_desc
*enable_gpio
;
31 struct omap_video_timings timings
;
34 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
36 static int opa362_connect(struct omap_dss_device
*dssdev
,
37 struct omap_dss_device
*dst
)
39 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
40 struct omap_dss_device
*in
= ddata
->in
;
43 dev_dbg(dssdev
->dev
, "connect\n");
45 if (omapdss_device_is_connected(dssdev
))
48 r
= in
->ops
.atv
->connect(in
, dssdev
);
58 static void opa362_disconnect(struct omap_dss_device
*dssdev
,
59 struct omap_dss_device
*dst
)
61 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
62 struct omap_dss_device
*in
= ddata
->in
;
64 dev_dbg(dssdev
->dev
, "disconnect\n");
66 WARN_ON(!omapdss_device_is_connected(dssdev
));
67 if (!omapdss_device_is_connected(dssdev
))
70 WARN_ON(dst
!= dssdev
->dst
);
71 if (dst
!= dssdev
->dst
)
77 in
->ops
.atv
->disconnect(in
, &ddata
->dssdev
);
80 static int opa362_enable(struct omap_dss_device
*dssdev
)
82 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
83 struct omap_dss_device
*in
= ddata
->in
;
86 dev_dbg(dssdev
->dev
, "enable\n");
88 if (!omapdss_device_is_connected(dssdev
))
91 if (omapdss_device_is_enabled(dssdev
))
94 in
->ops
.atv
->set_timings(in
, &ddata
->timings
);
96 r
= in
->ops
.atv
->enable(in
);
100 if (ddata
->enable_gpio
)
101 gpiod_set_value_cansleep(ddata
->enable_gpio
, 1);
103 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
108 static void opa362_disable(struct omap_dss_device
*dssdev
)
110 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
111 struct omap_dss_device
*in
= ddata
->in
;
113 dev_dbg(dssdev
->dev
, "disable\n");
115 if (!omapdss_device_is_enabled(dssdev
))
118 if (ddata
->enable_gpio
)
119 gpiod_set_value_cansleep(ddata
->enable_gpio
, 0);
121 in
->ops
.atv
->disable(in
);
123 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
126 static void opa362_set_timings(struct omap_dss_device
*dssdev
,
127 struct omap_video_timings
*timings
)
129 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
130 struct omap_dss_device
*in
= ddata
->in
;
132 dev_dbg(dssdev
->dev
, "set_timings\n");
134 ddata
->timings
= *timings
;
135 dssdev
->panel
.timings
= *timings
;
137 in
->ops
.atv
->set_timings(in
, timings
);
140 static void opa362_get_timings(struct omap_dss_device
*dssdev
,
141 struct omap_video_timings
*timings
)
143 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
145 dev_dbg(dssdev
->dev
, "get_timings\n");
147 *timings
= ddata
->timings
;
150 static int opa362_check_timings(struct omap_dss_device
*dssdev
,
151 struct omap_video_timings
*timings
)
153 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
154 struct omap_dss_device
*in
= ddata
->in
;
156 dev_dbg(dssdev
->dev
, "check_timings\n");
158 return in
->ops
.atv
->check_timings(in
, timings
);
161 static void opa362_set_type(struct omap_dss_device
*dssdev
,
162 enum omap_dss_venc_type type
)
164 /* we can only drive a COMPOSITE output */
165 WARN_ON(type
!= OMAP_DSS_VENC_TYPE_COMPOSITE
);
169 static const struct omapdss_atv_ops opa362_atv_ops
= {
170 .connect
= opa362_connect
,
171 .disconnect
= opa362_disconnect
,
173 .enable
= opa362_enable
,
174 .disable
= opa362_disable
,
176 .check_timings
= opa362_check_timings
,
177 .set_timings
= opa362_set_timings
,
178 .get_timings
= opa362_get_timings
,
180 .set_type
= opa362_set_type
,
183 static int opa362_probe(struct platform_device
*pdev
)
185 struct device_node
*node
= pdev
->dev
.of_node
;
186 struct panel_drv_data
*ddata
;
187 struct omap_dss_device
*dssdev
, *in
;
188 struct gpio_desc
*gpio
;
191 dev_dbg(&pdev
->dev
, "probe\n");
194 dev_err(&pdev
->dev
, "Unable to find device tree\n");
198 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
202 platform_set_drvdata(pdev
, ddata
);
204 gpio
= devm_gpiod_get_optional(&pdev
->dev
, "enable", GPIOD_OUT_LOW
);
206 return PTR_ERR(gpio
);
208 ddata
->enable_gpio
= gpio
;
210 in
= omapdss_of_find_source_for_first_ep(node
);
212 dev_err(&pdev
->dev
, "failed to find video source\n");
218 dssdev
= &ddata
->dssdev
;
219 dssdev
->ops
.atv
= &opa362_atv_ops
;
220 dssdev
->dev
= &pdev
->dev
;
221 dssdev
->type
= OMAP_DISPLAY_TYPE_VENC
;
222 dssdev
->output_type
= OMAP_DISPLAY_TYPE_VENC
;
223 dssdev
->owner
= THIS_MODULE
;
225 r
= omapdss_register_output(dssdev
);
227 dev_err(&pdev
->dev
, "Failed to register output\n");
233 omap_dss_put_device(ddata
->in
);
237 static int __exit
opa362_remove(struct platform_device
*pdev
)
239 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
240 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
241 struct omap_dss_device
*in
= ddata
->in
;
243 omapdss_unregister_output(&ddata
->dssdev
);
245 WARN_ON(omapdss_device_is_enabled(dssdev
));
246 if (omapdss_device_is_enabled(dssdev
))
247 opa362_disable(dssdev
);
249 WARN_ON(omapdss_device_is_connected(dssdev
));
250 if (omapdss_device_is_connected(dssdev
))
251 opa362_disconnect(dssdev
, dssdev
->dst
);
253 omap_dss_put_device(in
);
258 static const struct of_device_id opa362_of_match
[] = {
259 { .compatible
= "omapdss,ti,opa362", },
262 MODULE_DEVICE_TABLE(of
, opa362_of_match
);
264 static struct platform_driver opa362_driver
= {
265 .probe
= opa362_probe
,
266 .remove
= __exit_p(opa362_remove
),
268 .name
= "amplifier-opa362",
269 .of_match_table
= opa362_of_match
,
270 .suppress_bind_attrs
= true,
274 module_platform_driver(opa362_driver
);
276 MODULE_AUTHOR("H. Nikolaus Schaller <hns@goldelico.com>");
277 MODULE_DESCRIPTION("OPA362 analog video amplifier with output/power control");
278 MODULE_LICENSE("GPL v2");