blob: 5724bdf53a4280380d04bde9d78e9fab439dd888 [file] [log] [blame]
Marek Belisko0e878732014-12-03 22:33:20 +01001/*
2 * OPA362 analog video amplifier with output/power control
3 *
4 * Copyright (C) 2014 Golden Delicious Computers
5 * Author: H. Nikolaus Schaller <hns@goldelico.com>
6 *
7 * based on encoder-tfp410
8 *
Andrew F. Davisbb5cdf82017-12-05 14:29:31 -06009 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
Marek Belisko0e878732014-12-03 22:33:20 +010010 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
11 *
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.
15 */
16
Tomi Valkeinend9e32ec2016-03-18 09:02:18 +020017#include <linux/gpio/consumer.h>
Marek Belisko0e878732014-12-03 22:33:20 +010018#include <linux/module.h>
19#include <linux/platform_device.h>
20#include <linux/slab.h>
Marek Belisko0e878732014-12-03 22:33:20 +010021
Peter Ujfalusi32043da2016-05-27 14:40:49 +030022#include "../dss/omapdss.h"
Marek Belisko0e878732014-12-03 22:33:20 +010023
24struct panel_drv_data {
25 struct omap_dss_device dssdev;
26 struct omap_dss_device *in;
27
28 struct gpio_desc *enable_gpio;
29
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030030 struct videomode vm;
Marek Belisko0e878732014-12-03 22:33:20 +010031};
32
33#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
34
35static int opa362_connect(struct omap_dss_device *dssdev,
36 struct omap_dss_device *dst)
37{
38 struct panel_drv_data *ddata = to_panel_data(dssdev);
Laurent Pincharte28cea02018-02-11 15:07:41 +020039 struct omap_dss_device *in;
Marek Belisko0e878732014-12-03 22:33:20 +010040 int r;
41
Laurent Pincharte28cea02018-02-11 15:07:41 +020042 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
43 if (IS_ERR(in)) {
44 dev_err(dssdev->dev, "failed to find video source\n");
45 return PTR_ERR(in);
46 }
47
Laurent Pinchartec727e32018-02-28 17:30:30 +020048 r = omapdss_device_connect(in, dssdev);
Laurent Pincharte28cea02018-02-11 15:07:41 +020049 if (r) {
50 omap_dss_put_device(in);
Marek Belisko0e878732014-12-03 22:33:20 +010051 return r;
Laurent Pincharte28cea02018-02-11 15:07:41 +020052 }
Marek Belisko0e878732014-12-03 22:33:20 +010053
54 dst->src = dssdev;
55 dssdev->dst = dst;
56
Laurent Pincharte28cea02018-02-11 15:07:41 +020057 ddata->in = in;
Marek Belisko0e878732014-12-03 22:33:20 +010058 return 0;
59}
60
61static void opa362_disconnect(struct omap_dss_device *dssdev,
62 struct omap_dss_device *dst)
63{
64 struct panel_drv_data *ddata = to_panel_data(dssdev);
65 struct omap_dss_device *in = ddata->in;
66
Marek Belisko0e878732014-12-03 22:33:20 +010067 WARN_ON(dst != dssdev->dst);
68 if (dst != dssdev->dst)
69 return;
70
71 dst->src = NULL;
72 dssdev->dst = NULL;
73
Laurent Pinchartec727e32018-02-28 17:30:30 +020074 omapdss_device_disconnect(in, &ddata->dssdev);
Laurent Pincharte28cea02018-02-11 15:07:41 +020075
76 omap_dss_put_device(in);
77 ddata->in = NULL;
Marek Belisko0e878732014-12-03 22:33:20 +010078}
79
80static int opa362_enable(struct omap_dss_device *dssdev)
81{
82 struct panel_drv_data *ddata = to_panel_data(dssdev);
83 struct omap_dss_device *in = ddata->in;
84 int r;
85
86 dev_dbg(dssdev->dev, "enable\n");
87
88 if (!omapdss_device_is_connected(dssdev))
89 return -ENODEV;
90
91 if (omapdss_device_is_enabled(dssdev))
92 return 0;
93
Laurent Pinchartb93109d2018-02-28 15:58:13 +020094 in->ops->set_timings(in, &ddata->vm);
Marek Belisko0e878732014-12-03 22:33:20 +010095
Laurent Pinchartb93109d2018-02-28 15:58:13 +020096 r = in->ops->enable(in);
Marek Belisko0e878732014-12-03 22:33:20 +010097 if (r)
98 return r;
99
100 if (ddata->enable_gpio)
101 gpiod_set_value_cansleep(ddata->enable_gpio, 1);
102
103 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
104
105 return 0;
106}
107
108static void opa362_disable(struct omap_dss_device *dssdev)
109{
110 struct panel_drv_data *ddata = to_panel_data(dssdev);
111 struct omap_dss_device *in = ddata->in;
112
113 dev_dbg(dssdev->dev, "disable\n");
114
115 if (!omapdss_device_is_enabled(dssdev))
116 return;
117
118 if (ddata->enable_gpio)
119 gpiod_set_value_cansleep(ddata->enable_gpio, 0);
120
Laurent Pinchartb93109d2018-02-28 15:58:13 +0200121 in->ops->disable(in);
Marek Belisko0e878732014-12-03 22:33:20 +0100122
123 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
124}
125
126static void opa362_set_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300127 struct videomode *vm)
Marek Belisko0e878732014-12-03 22:33:20 +0100128{
129 struct panel_drv_data *ddata = to_panel_data(dssdev);
130 struct omap_dss_device *in = ddata->in;
131
132 dev_dbg(dssdev->dev, "set_timings\n");
133
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300134 ddata->vm = *vm;
Marek Belisko0e878732014-12-03 22:33:20 +0100135
Laurent Pinchartb93109d2018-02-28 15:58:13 +0200136 in->ops->set_timings(in, vm);
Marek Belisko0e878732014-12-03 22:33:20 +0100137}
138
Marek Belisko0e878732014-12-03 22:33:20 +0100139static int opa362_check_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300140 struct videomode *vm)
Marek Belisko0e878732014-12-03 22:33:20 +0100141{
142 struct panel_drv_data *ddata = to_panel_data(dssdev);
143 struct omap_dss_device *in = ddata->in;
144
145 dev_dbg(dssdev->dev, "check_timings\n");
146
Laurent Pinchartb93109d2018-02-28 15:58:13 +0200147 return in->ops->check_timings(in, vm);
Marek Belisko0e878732014-12-03 22:33:20 +0100148}
149
Laurent Pinchartb93109d2018-02-28 15:58:13 +0200150static const struct omap_dss_device_ops opa362_ops = {
Marek Belisko0e878732014-12-03 22:33:20 +0100151 .connect = opa362_connect,
152 .disconnect = opa362_disconnect,
Marek Belisko0e878732014-12-03 22:33:20 +0100153 .enable = opa362_enable,
154 .disable = opa362_disable,
Marek Belisko0e878732014-12-03 22:33:20 +0100155 .check_timings = opa362_check_timings,
156 .set_timings = opa362_set_timings,
Marek Belisko0e878732014-12-03 22:33:20 +0100157};
158
159static int opa362_probe(struct platform_device *pdev)
160{
Marek Belisko0e878732014-12-03 22:33:20 +0100161 struct panel_drv_data *ddata;
Laurent Pincharte28cea02018-02-11 15:07:41 +0200162 struct omap_dss_device *dssdev;
Marek Belisko0e878732014-12-03 22:33:20 +0100163 struct gpio_desc *gpio;
164 int r;
165
166 dev_dbg(&pdev->dev, "probe\n");
167
Marek Belisko0e878732014-12-03 22:33:20 +0100168 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
169 if (!ddata)
170 return -ENOMEM;
171
172 platform_set_drvdata(pdev, ddata);
173
Uwe Kleine-Königca8c67d2015-05-28 10:05:15 +0200174 gpio = devm_gpiod_get_optional(&pdev->dev, "enable", GPIOD_OUT_LOW);
175 if (IS_ERR(gpio))
176 return PTR_ERR(gpio);
Marek Belisko0e878732014-12-03 22:33:20 +0100177
178 ddata->enable_gpio = gpio;
179
Marek Belisko0e878732014-12-03 22:33:20 +0100180 dssdev = &ddata->dssdev;
Laurent Pinchartb93109d2018-02-28 15:58:13 +0200181 dssdev->ops = &opa362_ops;
Marek Belisko0e878732014-12-03 22:33:20 +0100182 dssdev->dev = &pdev->dev;
183 dssdev->type = OMAP_DISPLAY_TYPE_VENC;
184 dssdev->output_type = OMAP_DISPLAY_TYPE_VENC;
185 dssdev->owner = THIS_MODULE;
186
187 r = omapdss_register_output(dssdev);
188 if (r) {
189 dev_err(&pdev->dev, "Failed to register output\n");
Laurent Pincharte28cea02018-02-11 15:07:41 +0200190 return r;
Marek Belisko0e878732014-12-03 22:33:20 +0100191 }
192
193 return 0;
Marek Belisko0e878732014-12-03 22:33:20 +0100194}
195
196static int __exit opa362_remove(struct platform_device *pdev)
197{
198 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
199 struct omap_dss_device *dssdev = &ddata->dssdev;
Marek Belisko0e878732014-12-03 22:33:20 +0100200
201 omapdss_unregister_output(&ddata->dssdev);
202
203 WARN_ON(omapdss_device_is_enabled(dssdev));
204 if (omapdss_device_is_enabled(dssdev))
205 opa362_disable(dssdev);
206
207 WARN_ON(omapdss_device_is_connected(dssdev));
208 if (omapdss_device_is_connected(dssdev))
Laurent Pinchart73fc0ac2018-08-04 22:10:44 +0300209 omapdss_device_disconnect(dssdev, dssdev->dst);
Marek Belisko0e878732014-12-03 22:33:20 +0100210
Marek Belisko0e878732014-12-03 22:33:20 +0100211 return 0;
212}
213
214static const struct of_device_id opa362_of_match[] = {
215 { .compatible = "omapdss,ti,opa362", },
216 {},
217};
218MODULE_DEVICE_TABLE(of, opa362_of_match);
219
220static struct platform_driver opa362_driver = {
221 .probe = opa362_probe,
222 .remove = __exit_p(opa362_remove),
223 .driver = {
224 .name = "amplifier-opa362",
Marek Belisko0e878732014-12-03 22:33:20 +0100225 .of_match_table = opa362_of_match,
226 .suppress_bind_attrs = true,
227 },
228};
229
230module_platform_driver(opa362_driver);
231
232MODULE_AUTHOR("H. Nikolaus Schaller <hns@goldelico.com>");
233MODULE_DESCRIPTION("OPA362 analog video amplifier with output/power control");
234MODULE_LICENSE("GPL v2");