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/consumer.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
22 #include "../dss/omapdss.h"
24 struct panel_drv_data
{
25 struct omap_dss_device dssdev
;
26 struct omap_dss_device
*in
;
28 struct gpio_desc
*enable_gpio
;
30 struct omap_video_timings timings
;
33 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
35 static int opa362_connect(struct omap_dss_device
*dssdev
,
36 struct omap_dss_device
*dst
)
38 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
39 struct omap_dss_device
*in
= ddata
->in
;
42 dev_dbg(dssdev
->dev
, "connect\n");
44 if (omapdss_device_is_connected(dssdev
))
47 r
= in
->ops
.atv
->connect(in
, dssdev
);
57 static void opa362_disconnect(struct omap_dss_device
*dssdev
,
58 struct omap_dss_device
*dst
)
60 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
61 struct omap_dss_device
*in
= ddata
->in
;
63 dev_dbg(dssdev
->dev
, "disconnect\n");
65 WARN_ON(!omapdss_device_is_connected(dssdev
));
66 if (!omapdss_device_is_connected(dssdev
))
69 WARN_ON(dst
!= dssdev
->dst
);
70 if (dst
!= dssdev
->dst
)
76 in
->ops
.atv
->disconnect(in
, &ddata
->dssdev
);
79 static int opa362_enable(struct omap_dss_device
*dssdev
)
81 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
82 struct omap_dss_device
*in
= ddata
->in
;
85 dev_dbg(dssdev
->dev
, "enable\n");
87 if (!omapdss_device_is_connected(dssdev
))
90 if (omapdss_device_is_enabled(dssdev
))
93 in
->ops
.atv
->set_timings(in
, &ddata
->timings
);
95 r
= in
->ops
.atv
->enable(in
);
99 if (ddata
->enable_gpio
)
100 gpiod_set_value_cansleep(ddata
->enable_gpio
, 1);
102 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
107 static void opa362_disable(struct omap_dss_device
*dssdev
)
109 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
110 struct omap_dss_device
*in
= ddata
->in
;
112 dev_dbg(dssdev
->dev
, "disable\n");
114 if (!omapdss_device_is_enabled(dssdev
))
117 if (ddata
->enable_gpio
)
118 gpiod_set_value_cansleep(ddata
->enable_gpio
, 0);
120 in
->ops
.atv
->disable(in
);
122 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
125 static void opa362_set_timings(struct omap_dss_device
*dssdev
,
126 struct omap_video_timings
*timings
)
128 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
129 struct omap_dss_device
*in
= ddata
->in
;
131 dev_dbg(dssdev
->dev
, "set_timings\n");
133 ddata
->timings
= *timings
;
134 dssdev
->panel
.timings
= *timings
;
136 in
->ops
.atv
->set_timings(in
, timings
);
139 static void opa362_get_timings(struct omap_dss_device
*dssdev
,
140 struct omap_video_timings
*timings
)
142 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
144 dev_dbg(dssdev
->dev
, "get_timings\n");
146 *timings
= ddata
->timings
;
149 static int opa362_check_timings(struct omap_dss_device
*dssdev
,
150 struct omap_video_timings
*timings
)
152 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
153 struct omap_dss_device
*in
= ddata
->in
;
155 dev_dbg(dssdev
->dev
, "check_timings\n");
157 return in
->ops
.atv
->check_timings(in
, timings
);
160 static void opa362_set_type(struct omap_dss_device
*dssdev
,
161 enum omap_dss_venc_type type
)
163 /* we can only drive a COMPOSITE output */
164 WARN_ON(type
!= OMAP_DSS_VENC_TYPE_COMPOSITE
);
168 static const struct omapdss_atv_ops opa362_atv_ops
= {
169 .connect
= opa362_connect
,
170 .disconnect
= opa362_disconnect
,
172 .enable
= opa362_enable
,
173 .disable
= opa362_disable
,
175 .check_timings
= opa362_check_timings
,
176 .set_timings
= opa362_set_timings
,
177 .get_timings
= opa362_get_timings
,
179 .set_type
= opa362_set_type
,
182 static int opa362_probe(struct platform_device
*pdev
)
184 struct device_node
*node
= pdev
->dev
.of_node
;
185 struct panel_drv_data
*ddata
;
186 struct omap_dss_device
*dssdev
, *in
;
187 struct gpio_desc
*gpio
;
190 dev_dbg(&pdev
->dev
, "probe\n");
193 dev_err(&pdev
->dev
, "Unable to find device tree\n");
197 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
201 platform_set_drvdata(pdev
, ddata
);
203 gpio
= devm_gpiod_get_optional(&pdev
->dev
, "enable", GPIOD_OUT_LOW
);
205 return PTR_ERR(gpio
);
207 ddata
->enable_gpio
= gpio
;
209 in
= omapdss_of_find_source_for_first_ep(node
);
211 dev_err(&pdev
->dev
, "failed to find video source\n");
217 dssdev
= &ddata
->dssdev
;
218 dssdev
->ops
.atv
= &opa362_atv_ops
;
219 dssdev
->dev
= &pdev
->dev
;
220 dssdev
->type
= OMAP_DISPLAY_TYPE_VENC
;
221 dssdev
->output_type
= OMAP_DISPLAY_TYPE_VENC
;
222 dssdev
->owner
= THIS_MODULE
;
224 r
= omapdss_register_output(dssdev
);
226 dev_err(&pdev
->dev
, "Failed to register output\n");
232 omap_dss_put_device(ddata
->in
);
236 static int __exit
opa362_remove(struct platform_device
*pdev
)
238 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
239 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
240 struct omap_dss_device
*in
= ddata
->in
;
242 omapdss_unregister_output(&ddata
->dssdev
);
244 WARN_ON(omapdss_device_is_enabled(dssdev
));
245 if (omapdss_device_is_enabled(dssdev
))
246 opa362_disable(dssdev
);
248 WARN_ON(omapdss_device_is_connected(dssdev
));
249 if (omapdss_device_is_connected(dssdev
))
250 opa362_disconnect(dssdev
, dssdev
->dst
);
252 omap_dss_put_device(in
);
257 static const struct of_device_id opa362_of_match
[] = {
258 { .compatible
= "omapdss,ti,opa362", },
261 MODULE_DEVICE_TABLE(of
, opa362_of_match
);
263 static struct platform_driver opa362_driver
= {
264 .probe
= opa362_probe
,
265 .remove
= __exit_p(opa362_remove
),
267 .name
= "amplifier-opa362",
268 .of_match_table
= opa362_of_match
,
269 .suppress_bind_attrs
= true,
273 module_platform_driver(opa362_driver
);
275 MODULE_AUTHOR("H. Nikolaus Schaller <hns@goldelico.com>");
276 MODULE_DESCRIPTION("OPA362 analog video amplifier with output/power control");
277 MODULE_LICENSE("GPL v2");