Linux 4.19.133
[linux/fpc-iii.git] / drivers / video / fbdev / omap2 / omapfb / displays / encoder-tpd12s015.c
blob47f0459e3551b3a493bd94e7ebb26e8ab6cfc622
1 /*
2 * TPD12S015 HDMI ESD protection & level shifter chip driver
4 * Copyright (C) 2013 Texas Instruments
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/completion.h>
13 #include <linux/delay.h>
14 #include <linux/module.h>
15 #include <linux/mod_devicetable.h>
16 #include <linux/slab.h>
17 #include <linux/platform_device.h>
18 #include <linux/gpio/consumer.h>
20 #include <video/omapfb_dss.h>
22 struct panel_drv_data {
23 struct omap_dss_device dssdev;
24 struct omap_dss_device *in;
26 struct gpio_desc *ct_cp_hpd_gpio;
27 struct gpio_desc *ls_oe_gpio;
28 struct gpio_desc *hpd_gpio;
30 struct omap_video_timings timings;
33 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
35 static int tpd_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;
40 int r;
42 r = in->ops.hdmi->connect(in, dssdev);
43 if (r)
44 return r;
46 dst->src = dssdev;
47 dssdev->dst = dst;
49 if (ddata->ct_cp_hpd_gpio) {
50 gpiod_set_value_cansleep(ddata->ct_cp_hpd_gpio, 1);
51 /* DC-DC converter needs at max 300us to get to 90% of 5V */
52 udelay(300);
55 return 0;
58 static void tpd_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 WARN_ON(dst != dssdev->dst);
66 if (dst != dssdev->dst)
67 return;
69 gpiod_set_value_cansleep(ddata->ct_cp_hpd_gpio, 0);
71 dst->src = NULL;
72 dssdev->dst = NULL;
74 in->ops.hdmi->disconnect(in, &ddata->dssdev);
77 static int tpd_enable(struct omap_dss_device *dssdev)
79 struct panel_drv_data *ddata = to_panel_data(dssdev);
80 struct omap_dss_device *in = ddata->in;
81 int r;
83 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
84 return 0;
86 in->ops.hdmi->set_timings(in, &ddata->timings);
88 r = in->ops.hdmi->enable(in);
89 if (r)
90 return r;
92 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
94 return r;
97 static void tpd_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 (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
103 return;
105 in->ops.hdmi->disable(in);
107 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
110 static void tpd_set_timings(struct omap_dss_device *dssdev,
111 struct omap_video_timings *timings)
113 struct panel_drv_data *ddata = to_panel_data(dssdev);
114 struct omap_dss_device *in = ddata->in;
116 ddata->timings = *timings;
117 dssdev->panel.timings = *timings;
119 in->ops.hdmi->set_timings(in, timings);
122 static void tpd_get_timings(struct omap_dss_device *dssdev,
123 struct omap_video_timings *timings)
125 struct panel_drv_data *ddata = to_panel_data(dssdev);
127 *timings = ddata->timings;
130 static int tpd_check_timings(struct omap_dss_device *dssdev,
131 struct omap_video_timings *timings)
133 struct panel_drv_data *ddata = to_panel_data(dssdev);
134 struct omap_dss_device *in = ddata->in;
135 int r;
137 r = in->ops.hdmi->check_timings(in, timings);
139 return r;
142 static int tpd_read_edid(struct omap_dss_device *dssdev,
143 u8 *edid, int len)
145 struct panel_drv_data *ddata = to_panel_data(dssdev);
146 struct omap_dss_device *in = ddata->in;
147 int r;
149 if (!gpiod_get_value_cansleep(ddata->hpd_gpio))
150 return -ENODEV;
152 gpiod_set_value_cansleep(ddata->ls_oe_gpio, 1);
154 r = in->ops.hdmi->read_edid(in, edid, len);
156 gpiod_set_value_cansleep(ddata->ls_oe_gpio, 0);
158 return r;
161 static bool tpd_detect(struct omap_dss_device *dssdev)
163 struct panel_drv_data *ddata = to_panel_data(dssdev);
165 return gpiod_get_value_cansleep(ddata->hpd_gpio);
168 static int tpd_set_infoframe(struct omap_dss_device *dssdev,
169 const struct hdmi_avi_infoframe *avi)
171 struct panel_drv_data *ddata = to_panel_data(dssdev);
172 struct omap_dss_device *in = ddata->in;
174 return in->ops.hdmi->set_infoframe(in, avi);
177 static int tpd_set_hdmi_mode(struct omap_dss_device *dssdev,
178 bool hdmi_mode)
180 struct panel_drv_data *ddata = to_panel_data(dssdev);
181 struct omap_dss_device *in = ddata->in;
183 return in->ops.hdmi->set_hdmi_mode(in, hdmi_mode);
186 static const struct omapdss_hdmi_ops tpd_hdmi_ops = {
187 .connect = tpd_connect,
188 .disconnect = tpd_disconnect,
190 .enable = tpd_enable,
191 .disable = tpd_disable,
193 .check_timings = tpd_check_timings,
194 .set_timings = tpd_set_timings,
195 .get_timings = tpd_get_timings,
197 .read_edid = tpd_read_edid,
198 .detect = tpd_detect,
199 .set_infoframe = tpd_set_infoframe,
200 .set_hdmi_mode = tpd_set_hdmi_mode,
203 static int tpd_probe_of(struct platform_device *pdev)
205 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
206 struct device_node *node = pdev->dev.of_node;
207 struct omap_dss_device *in;
209 in = omapdss_of_find_source_for_first_ep(node);
210 if (IS_ERR(in)) {
211 dev_err(&pdev->dev, "failed to find video source\n");
212 return PTR_ERR(in);
215 ddata->in = in;
217 return 0;
220 static int tpd_probe(struct platform_device *pdev)
222 struct omap_dss_device *dssdev;
223 struct panel_drv_data *ddata;
224 int r;
225 struct gpio_desc *gpio;
227 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
228 if (!ddata)
229 return -ENOMEM;
231 platform_set_drvdata(pdev, ddata);
233 if (pdev->dev.of_node) {
234 r = tpd_probe_of(pdev);
235 if (r)
236 return r;
237 } else {
238 return -ENODEV;
241 gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 0,
242 GPIOD_OUT_LOW);
243 if (IS_ERR(gpio)) {
244 r = PTR_ERR(gpio);
245 goto err_gpio;
248 ddata->ct_cp_hpd_gpio = gpio;
250 gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 1,
251 GPIOD_OUT_LOW);
252 if (IS_ERR(gpio)) {
253 r = PTR_ERR(gpio);
254 goto err_gpio;
257 ddata->ls_oe_gpio = gpio;
259 gpio = devm_gpiod_get_index(&pdev->dev, NULL, 2,
260 GPIOD_IN);
261 if (IS_ERR(gpio)) {
262 r = PTR_ERR(gpio);
263 goto err_gpio;
266 ddata->hpd_gpio = gpio;
268 dssdev = &ddata->dssdev;
269 dssdev->ops.hdmi = &tpd_hdmi_ops;
270 dssdev->dev = &pdev->dev;
271 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
272 dssdev->output_type = OMAP_DISPLAY_TYPE_HDMI;
273 dssdev->owner = THIS_MODULE;
274 dssdev->port_num = 1;
276 r = omapdss_register_output(dssdev);
277 if (r) {
278 dev_err(&pdev->dev, "Failed to register output\n");
279 goto err_reg;
282 return 0;
283 err_reg:
284 err_gpio:
285 omap_dss_put_device(ddata->in);
286 return r;
289 static int __exit tpd_remove(struct platform_device *pdev)
291 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
292 struct omap_dss_device *dssdev = &ddata->dssdev;
293 struct omap_dss_device *in = ddata->in;
295 omapdss_unregister_output(&ddata->dssdev);
297 WARN_ON(omapdss_device_is_enabled(dssdev));
298 if (omapdss_device_is_enabled(dssdev))
299 tpd_disable(dssdev);
301 WARN_ON(omapdss_device_is_connected(dssdev));
302 if (omapdss_device_is_connected(dssdev))
303 tpd_disconnect(dssdev, dssdev->dst);
305 omap_dss_put_device(in);
307 return 0;
310 static const struct of_device_id tpd_of_match[] = {
311 { .compatible = "omapdss,ti,tpd12s015", },
315 MODULE_DEVICE_TABLE(of, tpd_of_match);
317 static struct platform_driver tpd_driver = {
318 .probe = tpd_probe,
319 .remove = __exit_p(tpd_remove),
320 .driver = {
321 .name = "tpd12s015",
322 .of_match_table = tpd_of_match,
323 .suppress_bind_attrs = true,
327 module_platform_driver(tpd_driver);
329 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
330 MODULE_DESCRIPTION("TPD12S015 driver");
331 MODULE_LICENSE("GPL");