Linux Audio

Check our new training course

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