Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / video / fbdev / omap2 / omapfb / displays / encoder-tfp410.c
blob458e65771cbb76b1b64b353c5e4b686dc1b0a6f0
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * TFP410 DPI-to-DVI encoder driver
5 * Copyright (C) 2013 Texas Instruments
6 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
7 */
9 #include <linux/err.h>
10 #include <linux/gpio/consumer.h>
11 #include <linux/module.h>
12 #include <linux/mod_devicetable.h>
13 #include <linux/platform_device.h>
14 #include <linux/slab.h>
16 #include <video/omapfb_dss.h>
18 struct panel_drv_data {
19 struct omap_dss_device dssdev;
20 struct omap_dss_device *in;
22 struct gpio_desc *pd_gpio;
24 int data_lines;
26 struct omap_video_timings timings;
29 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
31 static int tfp410_connect(struct omap_dss_device *dssdev,
32 struct omap_dss_device *dst)
34 struct panel_drv_data *ddata = to_panel_data(dssdev);
35 struct omap_dss_device *in = ddata->in;
36 int r;
38 if (omapdss_device_is_connected(dssdev))
39 return -EBUSY;
41 r = in->ops.dpi->connect(in, dssdev);
42 if (r)
43 return r;
45 dst->src = dssdev;
46 dssdev->dst = dst;
48 return 0;
51 static void tfp410_disconnect(struct omap_dss_device *dssdev,
52 struct omap_dss_device *dst)
54 struct panel_drv_data *ddata = to_panel_data(dssdev);
55 struct omap_dss_device *in = ddata->in;
57 WARN_ON(!omapdss_device_is_connected(dssdev));
58 if (!omapdss_device_is_connected(dssdev))
59 return;
61 WARN_ON(dst != dssdev->dst);
62 if (dst != dssdev->dst)
63 return;
65 dst->src = NULL;
66 dssdev->dst = NULL;
68 in->ops.dpi->disconnect(in, &ddata->dssdev);
71 static int tfp410_enable(struct omap_dss_device *dssdev)
73 struct panel_drv_data *ddata = to_panel_data(dssdev);
74 struct omap_dss_device *in = ddata->in;
75 int r;
77 if (!omapdss_device_is_connected(dssdev))
78 return -ENODEV;
80 if (omapdss_device_is_enabled(dssdev))
81 return 0;
83 in->ops.dpi->set_timings(in, &ddata->timings);
84 if (ddata->data_lines)
85 in->ops.dpi->set_data_lines(in, ddata->data_lines);
87 r = in->ops.dpi->enable(in);
88 if (r)
89 return r;
91 if (ddata->pd_gpio)
92 gpiod_set_value_cansleep(ddata->pd_gpio, 0);
94 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
96 return 0;
99 static void tfp410_disable(struct omap_dss_device *dssdev)
101 struct panel_drv_data *ddata = to_panel_data(dssdev);
102 struct omap_dss_device *in = ddata->in;
104 if (!omapdss_device_is_enabled(dssdev))
105 return;
107 if (ddata->pd_gpio)
108 gpiod_set_value_cansleep(ddata->pd_gpio, 1);
110 in->ops.dpi->disable(in);
112 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
115 static void tfp410_fix_timings(struct omap_video_timings *timings)
117 timings->data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
118 timings->sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
119 timings->de_level = OMAPDSS_SIG_ACTIVE_HIGH;
122 static void tfp410_set_timings(struct omap_dss_device *dssdev,
123 struct omap_video_timings *timings)
125 struct panel_drv_data *ddata = to_panel_data(dssdev);
126 struct omap_dss_device *in = ddata->in;
128 tfp410_fix_timings(timings);
130 ddata->timings = *timings;
131 dssdev->panel.timings = *timings;
133 in->ops.dpi->set_timings(in, timings);
136 static void tfp410_get_timings(struct omap_dss_device *dssdev,
137 struct omap_video_timings *timings)
139 struct panel_drv_data *ddata = to_panel_data(dssdev);
141 *timings = ddata->timings;
144 static int tfp410_check_timings(struct omap_dss_device *dssdev,
145 struct omap_video_timings *timings)
147 struct panel_drv_data *ddata = to_panel_data(dssdev);
148 struct omap_dss_device *in = ddata->in;
150 tfp410_fix_timings(timings);
152 return in->ops.dpi->check_timings(in, timings);
155 static const struct omapdss_dvi_ops tfp410_dvi_ops = {
156 .connect = tfp410_connect,
157 .disconnect = tfp410_disconnect,
159 .enable = tfp410_enable,
160 .disable = tfp410_disable,
162 .check_timings = tfp410_check_timings,
163 .set_timings = tfp410_set_timings,
164 .get_timings = tfp410_get_timings,
167 static int tfp410_probe(struct platform_device *pdev)
169 struct panel_drv_data *ddata;
170 struct omap_dss_device *dssdev;
171 int r;
173 if (!pdev->dev.of_node)
174 return -ENODEV;
176 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
177 if (!ddata)
178 return -ENOMEM;
180 platform_set_drvdata(pdev, ddata);
182 ddata->pd_gpio = devm_gpiod_get_optional(&pdev->dev, "powerdown",
183 GPIOD_OUT_HIGH);
184 r = PTR_ERR_OR_ZERO(ddata->pd_gpio);
185 if (r) {
186 dev_err(&pdev->dev, "Failed to request PD GPIO: %d\n", r);
187 return r;
190 gpiod_set_consumer_name(ddata->pd_gpio, "tfp410 PD");
192 ddata->in = omapdss_of_find_source_for_first_ep(pdev->dev.of_node);
193 r = PTR_ERR_OR_ZERO(ddata->in);
194 if (r) {
195 dev_err(&pdev->dev, "failed to find video source: %d\n", r);
196 return r;
199 dssdev = &ddata->dssdev;
200 dssdev->ops.dvi = &tfp410_dvi_ops;
201 dssdev->dev = &pdev->dev;
202 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
203 dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
204 dssdev->owner = THIS_MODULE;
205 dssdev->phy.dpi.data_lines = ddata->data_lines;
206 dssdev->port_num = 1;
208 r = omapdss_register_output(dssdev);
209 if (r) {
210 dev_err(&pdev->dev, "Failed to register output\n");
211 goto err_reg;
214 return 0;
215 err_reg:
216 omap_dss_put_device(ddata->in);
217 return r;
220 static void tfp410_remove(struct platform_device *pdev)
222 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
223 struct omap_dss_device *dssdev = &ddata->dssdev;
224 struct omap_dss_device *in = ddata->in;
226 omapdss_unregister_output(&ddata->dssdev);
228 WARN_ON(omapdss_device_is_enabled(dssdev));
229 if (omapdss_device_is_enabled(dssdev))
230 tfp410_disable(dssdev);
232 WARN_ON(omapdss_device_is_connected(dssdev));
233 if (omapdss_device_is_connected(dssdev))
234 tfp410_disconnect(dssdev, dssdev->dst);
236 omap_dss_put_device(in);
239 static const struct of_device_id tfp410_of_match[] = {
240 { .compatible = "omapdss,ti,tfp410", },
244 MODULE_DEVICE_TABLE(of, tfp410_of_match);
246 static struct platform_driver tfp410_driver = {
247 .probe = tfp410_probe,
248 .remove = tfp410_remove,
249 .driver = {
250 .name = "tfp410",
251 .of_match_table = tfp410_of_match,
255 module_platform_driver(tfp410_driver);
257 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
258 MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
259 MODULE_LICENSE("GPL");