• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * TFP410 DPI-to-DVI encoder driver
3  *
4  * Copyright (C) 2013 Texas Instruments
5  * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
6  *
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.
10  */
11 
12 #include <linux/gpio/consumer.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/slab.h>
16 #include <linux/of_gpio.h>
17 
18 #include "../dss/omapdss.h"
19 
20 struct panel_drv_data {
21 	struct omap_dss_device dssdev;
22 	struct omap_dss_device *in;
23 
24 	int pd_gpio;
25 
26 	struct videomode vm;
27 };
28 
29 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
30 
tfp410_connect(struct omap_dss_device * dssdev,struct omap_dss_device * dst)31 static int tfp410_connect(struct omap_dss_device *dssdev,
32 		struct omap_dss_device *dst)
33 {
34 	struct panel_drv_data *ddata = to_panel_data(dssdev);
35 	struct omap_dss_device *in = ddata->in;
36 	int r;
37 
38 	if (omapdss_device_is_connected(dssdev))
39 		return -EBUSY;
40 
41 	r = in->ops.dpi->connect(in, dssdev);
42 	if (r)
43 		return r;
44 
45 	dst->src = dssdev;
46 	dssdev->dst = dst;
47 
48 	return 0;
49 }
50 
tfp410_disconnect(struct omap_dss_device * dssdev,struct omap_dss_device * dst)51 static void tfp410_disconnect(struct omap_dss_device *dssdev,
52 		struct omap_dss_device *dst)
53 {
54 	struct panel_drv_data *ddata = to_panel_data(dssdev);
55 	struct omap_dss_device *in = ddata->in;
56 
57 	WARN_ON(!omapdss_device_is_connected(dssdev));
58 	if (!omapdss_device_is_connected(dssdev))
59 		return;
60 
61 	WARN_ON(dst != dssdev->dst);
62 	if (dst != dssdev->dst)
63 		return;
64 
65 	dst->src = NULL;
66 	dssdev->dst = NULL;
67 
68 	in->ops.dpi->disconnect(in, &ddata->dssdev);
69 }
70 
tfp410_enable(struct omap_dss_device * dssdev)71 static int tfp410_enable(struct omap_dss_device *dssdev)
72 {
73 	struct panel_drv_data *ddata = to_panel_data(dssdev);
74 	struct omap_dss_device *in = ddata->in;
75 	int r;
76 
77 	if (!omapdss_device_is_connected(dssdev))
78 		return -ENODEV;
79 
80 	if (omapdss_device_is_enabled(dssdev))
81 		return 0;
82 
83 	in->ops.dpi->set_timings(in, &ddata->vm);
84 
85 	r = in->ops.dpi->enable(in);
86 	if (r)
87 		return r;
88 
89 	if (gpio_is_valid(ddata->pd_gpio))
90 		gpio_set_value_cansleep(ddata->pd_gpio, 1);
91 
92 	dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
93 
94 	return 0;
95 }
96 
tfp410_disable(struct omap_dss_device * dssdev)97 static void tfp410_disable(struct omap_dss_device *dssdev)
98 {
99 	struct panel_drv_data *ddata = to_panel_data(dssdev);
100 	struct omap_dss_device *in = ddata->in;
101 
102 	if (!omapdss_device_is_enabled(dssdev))
103 		return;
104 
105 	if (gpio_is_valid(ddata->pd_gpio))
106 		gpio_set_value_cansleep(ddata->pd_gpio, 0);
107 
108 	in->ops.dpi->disable(in);
109 
110 	dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
111 }
112 
tfp410_fix_timings(struct videomode * vm)113 static void tfp410_fix_timings(struct videomode *vm)
114 {
115 	vm->flags |= DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_PIXDATA_POSEDGE |
116 		     DISPLAY_FLAGS_SYNC_POSEDGE;
117 }
118 
tfp410_set_timings(struct omap_dss_device * dssdev,struct videomode * vm)119 static void tfp410_set_timings(struct omap_dss_device *dssdev,
120 			       struct videomode *vm)
121 {
122 	struct panel_drv_data *ddata = to_panel_data(dssdev);
123 	struct omap_dss_device *in = ddata->in;
124 
125 	tfp410_fix_timings(vm);
126 
127 	ddata->vm = *vm;
128 	dssdev->panel.vm = *vm;
129 
130 	in->ops.dpi->set_timings(in, vm);
131 }
132 
tfp410_get_timings(struct omap_dss_device * dssdev,struct videomode * vm)133 static void tfp410_get_timings(struct omap_dss_device *dssdev,
134 			       struct videomode *vm)
135 {
136 	struct panel_drv_data *ddata = to_panel_data(dssdev);
137 
138 	*vm = ddata->vm;
139 }
140 
tfp410_check_timings(struct omap_dss_device * dssdev,struct videomode * vm)141 static int tfp410_check_timings(struct omap_dss_device *dssdev,
142 				struct videomode *vm)
143 {
144 	struct panel_drv_data *ddata = to_panel_data(dssdev);
145 	struct omap_dss_device *in = ddata->in;
146 
147 	tfp410_fix_timings(vm);
148 
149 	return in->ops.dpi->check_timings(in, vm);
150 }
151 
152 static const struct omapdss_dvi_ops tfp410_dvi_ops = {
153 	.connect	= tfp410_connect,
154 	.disconnect	= tfp410_disconnect,
155 
156 	.enable		= tfp410_enable,
157 	.disable	= tfp410_disable,
158 
159 	.check_timings	= tfp410_check_timings,
160 	.set_timings	= tfp410_set_timings,
161 	.get_timings	= tfp410_get_timings,
162 };
163 
tfp410_probe_of(struct platform_device * pdev)164 static int tfp410_probe_of(struct platform_device *pdev)
165 {
166 	struct panel_drv_data *ddata = platform_get_drvdata(pdev);
167 	struct device_node *node = pdev->dev.of_node;
168 	struct omap_dss_device *in;
169 	int gpio;
170 
171 	gpio = of_get_named_gpio(node, "powerdown-gpios", 0);
172 
173 	if (gpio_is_valid(gpio) || gpio == -ENOENT) {
174 		ddata->pd_gpio = gpio;
175 	} else {
176 		dev_err(&pdev->dev, "failed to parse PD gpio\n");
177 		return gpio;
178 	}
179 
180 	in = omapdss_of_find_source_for_first_ep(node);
181 	if (IS_ERR(in)) {
182 		dev_err(&pdev->dev, "failed to find video source\n");
183 		return PTR_ERR(in);
184 	}
185 
186 	ddata->in = in;
187 
188 	return 0;
189 }
190 
tfp410_probe(struct platform_device * pdev)191 static int tfp410_probe(struct platform_device *pdev)
192 {
193 	struct panel_drv_data *ddata;
194 	struct omap_dss_device *dssdev;
195 	int r;
196 
197 	ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
198 	if (!ddata)
199 		return -ENOMEM;
200 
201 	platform_set_drvdata(pdev, ddata);
202 
203 	if (!pdev->dev.of_node)
204 		return -ENODEV;
205 
206 	r = tfp410_probe_of(pdev);
207 	if (r)
208 		return r;
209 
210 	if (gpio_is_valid(ddata->pd_gpio)) {
211 		r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
212 				GPIOF_OUT_INIT_LOW, "tfp410 PD");
213 		if (r) {
214 			dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
215 					ddata->pd_gpio);
216 			goto err_gpio;
217 		}
218 	}
219 
220 	dssdev = &ddata->dssdev;
221 	dssdev->ops.dvi = &tfp410_dvi_ops;
222 	dssdev->dev = &pdev->dev;
223 	dssdev->type = OMAP_DISPLAY_TYPE_DPI;
224 	dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
225 	dssdev->owner = THIS_MODULE;
226 	dssdev->port_num = 1;
227 
228 	r = omapdss_register_output(dssdev);
229 	if (r) {
230 		dev_err(&pdev->dev, "Failed to register output\n");
231 		goto err_reg;
232 	}
233 
234 	return 0;
235 err_reg:
236 err_gpio:
237 	omap_dss_put_device(ddata->in);
238 	return r;
239 }
240 
tfp410_remove(struct platform_device * pdev)241 static int __exit tfp410_remove(struct platform_device *pdev)
242 {
243 	struct panel_drv_data *ddata = platform_get_drvdata(pdev);
244 	struct omap_dss_device *dssdev = &ddata->dssdev;
245 	struct omap_dss_device *in = ddata->in;
246 
247 	omapdss_unregister_output(&ddata->dssdev);
248 
249 	WARN_ON(omapdss_device_is_enabled(dssdev));
250 	if (omapdss_device_is_enabled(dssdev))
251 		tfp410_disable(dssdev);
252 
253 	WARN_ON(omapdss_device_is_connected(dssdev));
254 	if (omapdss_device_is_connected(dssdev))
255 		tfp410_disconnect(dssdev, dssdev->dst);
256 
257 	omap_dss_put_device(in);
258 
259 	return 0;
260 }
261 
262 static const struct of_device_id tfp410_of_match[] = {
263 	{ .compatible = "omapdss,ti,tfp410", },
264 	{},
265 };
266 
267 MODULE_DEVICE_TABLE(of, tfp410_of_match);
268 
269 static struct platform_driver tfp410_driver = {
270 	.probe	= tfp410_probe,
271 	.remove	= __exit_p(tfp410_remove),
272 	.driver	= {
273 		.name	= "tfp410",
274 		.of_match_table = tfp410_of_match,
275 		.suppress_bind_attrs = true,
276 	},
277 };
278 
279 module_platform_driver(tfp410_driver);
280 
281 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
282 MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
283 MODULE_LICENSE("GPL");
284