]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/gpu/drm/omapdrm/displays/encoder-opa362.c
drm/omap: venc: remove set_type & invert_vid_out_polarity
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / omapdrm / displays / encoder-opa362.c
CommitLineData
0e878731
MB
1/*
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 *
9 * Copyright (C) 2013 Texas Instruments
10 * 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
d9e32ecd 17#include <linux/gpio/consumer.h>
0e878731
MB
18#include <linux/module.h>
19#include <linux/platform_device.h>
20#include <linux/slab.h>
0e878731 21
32043da7 22#include "../dss/omapdss.h"
0e878731
MB
23
24struct panel_drv_data {
25 struct omap_dss_device dssdev;
26 struct omap_dss_device *in;
27
28 struct gpio_desc *enable_gpio;
29
da11bbbb 30 struct videomode vm;
0e878731
MB
31};
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);
39 struct omap_dss_device *in = ddata->in;
40 int r;
41
42 dev_dbg(dssdev->dev, "connect\n");
43
44 if (omapdss_device_is_connected(dssdev))
45 return -EBUSY;
46
47 r = in->ops.atv->connect(in, dssdev);
48 if (r)
49 return r;
50
51 dst->src = dssdev;
52 dssdev->dst = dst;
53
54 return 0;
55}
56
57static void opa362_disconnect(struct omap_dss_device *dssdev,
58 struct omap_dss_device *dst)
59{
60 struct panel_drv_data *ddata = to_panel_data(dssdev);
61 struct omap_dss_device *in = ddata->in;
62
63 dev_dbg(dssdev->dev, "disconnect\n");
64
65 WARN_ON(!omapdss_device_is_connected(dssdev));
66 if (!omapdss_device_is_connected(dssdev))
67 return;
68
69 WARN_ON(dst != dssdev->dst);
70 if (dst != dssdev->dst)
71 return;
72
73 dst->src = NULL;
74 dssdev->dst = NULL;
75
76 in->ops.atv->disconnect(in, &ddata->dssdev);
77}
78
79static int opa362_enable(struct omap_dss_device *dssdev)
80{
81 struct panel_drv_data *ddata = to_panel_data(dssdev);
82 struct omap_dss_device *in = ddata->in;
83 int r;
84
85 dev_dbg(dssdev->dev, "enable\n");
86
87 if (!omapdss_device_is_connected(dssdev))
88 return -ENODEV;
89
90 if (omapdss_device_is_enabled(dssdev))
91 return 0;
92
da11bbbb 93 in->ops.atv->set_timings(in, &ddata->vm);
0e878731
MB
94
95 r = in->ops.atv->enable(in);
96 if (r)
97 return r;
98
99 if (ddata->enable_gpio)
100 gpiod_set_value_cansleep(ddata->enable_gpio, 1);
101
102 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
103
104 return 0;
105}
106
107static void opa362_disable(struct omap_dss_device *dssdev)
108{
109 struct panel_drv_data *ddata = to_panel_data(dssdev);
110 struct omap_dss_device *in = ddata->in;
111
112 dev_dbg(dssdev->dev, "disable\n");
113
114 if (!omapdss_device_is_enabled(dssdev))
115 return;
116
117 if (ddata->enable_gpio)
118 gpiod_set_value_cansleep(ddata->enable_gpio, 0);
119
120 in->ops.atv->disable(in);
121
122 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
123}
124
125static void opa362_set_timings(struct omap_dss_device *dssdev,
da11bbbb 126 struct videomode *vm)
0e878731
MB
127{
128 struct panel_drv_data *ddata = to_panel_data(dssdev);
129 struct omap_dss_device *in = ddata->in;
130
131 dev_dbg(dssdev->dev, "set_timings\n");
132
da11bbbb
PU
133 ddata->vm = *vm;
134 dssdev->panel.vm = *vm;
0e878731 135
da11bbbb 136 in->ops.atv->set_timings(in, vm);
0e878731
MB
137}
138
139static void opa362_get_timings(struct omap_dss_device *dssdev,
da11bbbb 140 struct videomode *vm)
0e878731
MB
141{
142 struct panel_drv_data *ddata = to_panel_data(dssdev);
143
144 dev_dbg(dssdev->dev, "get_timings\n");
145
da11bbbb 146 *vm = ddata->vm;
0e878731
MB
147}
148
149static int opa362_check_timings(struct omap_dss_device *dssdev,
da11bbbb 150 struct videomode *vm)
0e878731
MB
151{
152 struct panel_drv_data *ddata = to_panel_data(dssdev);
153 struct omap_dss_device *in = ddata->in;
154
155 dev_dbg(dssdev->dev, "check_timings\n");
156
da11bbbb 157 return in->ops.atv->check_timings(in, vm);
0e878731
MB
158}
159
0e878731
MB
160static const struct omapdss_atv_ops opa362_atv_ops = {
161 .connect = opa362_connect,
162 .disconnect = opa362_disconnect,
163
164 .enable = opa362_enable,
165 .disable = opa362_disable,
166
167 .check_timings = opa362_check_timings,
168 .set_timings = opa362_set_timings,
169 .get_timings = opa362_get_timings,
0e878731
MB
170};
171
172static int opa362_probe(struct platform_device *pdev)
173{
174 struct device_node *node = pdev->dev.of_node;
175 struct panel_drv_data *ddata;
176 struct omap_dss_device *dssdev, *in;
177 struct gpio_desc *gpio;
178 int r;
179
180 dev_dbg(&pdev->dev, "probe\n");
181
182 if (node == NULL) {
183 dev_err(&pdev->dev, "Unable to find device tree\n");
184 return -EINVAL;
185 }
186
187 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
188 if (!ddata)
189 return -ENOMEM;
190
191 platform_set_drvdata(pdev, ddata);
192
ca8c67da
UKK
193 gpio = devm_gpiod_get_optional(&pdev->dev, "enable", GPIOD_OUT_LOW);
194 if (IS_ERR(gpio))
195 return PTR_ERR(gpio);
0e878731
MB
196
197 ddata->enable_gpio = gpio;
198
199 in = omapdss_of_find_source_for_first_ep(node);
200 if (IS_ERR(in)) {
201 dev_err(&pdev->dev, "failed to find video source\n");
202 return PTR_ERR(in);
203 }
204
205 ddata->in = in;
206
207 dssdev = &ddata->dssdev;
208 dssdev->ops.atv = &opa362_atv_ops;
209 dssdev->dev = &pdev->dev;
210 dssdev->type = OMAP_DISPLAY_TYPE_VENC;
211 dssdev->output_type = OMAP_DISPLAY_TYPE_VENC;
212 dssdev->owner = THIS_MODULE;
213
214 r = omapdss_register_output(dssdev);
215 if (r) {
216 dev_err(&pdev->dev, "Failed to register output\n");
217 goto err_reg;
218 }
219
220 return 0;
221err_reg:
222 omap_dss_put_device(ddata->in);
223 return r;
224}
225
226static int __exit opa362_remove(struct platform_device *pdev)
227{
228 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
229 struct omap_dss_device *dssdev = &ddata->dssdev;
230 struct omap_dss_device *in = ddata->in;
231
232 omapdss_unregister_output(&ddata->dssdev);
233
234 WARN_ON(omapdss_device_is_enabled(dssdev));
235 if (omapdss_device_is_enabled(dssdev))
236 opa362_disable(dssdev);
237
238 WARN_ON(omapdss_device_is_connected(dssdev));
239 if (omapdss_device_is_connected(dssdev))
240 opa362_disconnect(dssdev, dssdev->dst);
241
242 omap_dss_put_device(in);
243
244 return 0;
245}
246
247static const struct of_device_id opa362_of_match[] = {
248 { .compatible = "omapdss,ti,opa362", },
249 {},
250};
251MODULE_DEVICE_TABLE(of, opa362_of_match);
252
253static struct platform_driver opa362_driver = {
254 .probe = opa362_probe,
255 .remove = __exit_p(opa362_remove),
256 .driver = {
257 .name = "amplifier-opa362",
0e878731
MB
258 .of_match_table = opa362_of_match,
259 .suppress_bind_attrs = true,
260 },
261};
262
263module_platform_driver(opa362_driver);
264
265MODULE_AUTHOR("H. Nikolaus Schaller <hns@goldelico.com>");
266MODULE_DESCRIPTION("OPA362 analog video amplifier with output/power control");
267MODULE_LICENSE("GPL v2");