2 * TFP410 DPI-to-DVI encoder driver
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.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/gpio/consumer.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/slab.h>
17 #include "../dss/omapdss.h"
19 struct panel_drv_data {
20 struct omap_dss_device dssdev;
22 struct gpio_desc *pd_gpio;
25 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
27 static int tfp410_connect(struct omap_dss_device *src,
28 struct omap_dss_device *dst)
30 return omapdss_device_connect(dst->dss, dst, dst->next);
33 static void tfp410_disconnect(struct omap_dss_device *src,
34 struct omap_dss_device *dst)
36 omapdss_device_disconnect(dst, dst->next);
39 static int tfp410_enable(struct omap_dss_device *dssdev)
41 struct panel_drv_data *ddata = to_panel_data(dssdev);
42 struct omap_dss_device *src = dssdev->src;
45 if (!omapdss_device_is_connected(dssdev))
48 if (omapdss_device_is_enabled(dssdev))
51 r = src->ops->enable(src);
56 gpiod_set_value_cansleep(ddata->pd_gpio, 0);
58 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
63 static void tfp410_disable(struct omap_dss_device *dssdev)
65 struct panel_drv_data *ddata = to_panel_data(dssdev);
66 struct omap_dss_device *src = dssdev->src;
68 if (!omapdss_device_is_enabled(dssdev))
72 gpiod_set_value_cansleep(ddata->pd_gpio, 0);
74 src->ops->disable(src);
76 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
79 static const struct omap_dss_device_ops tfp410_ops = {
80 .connect = tfp410_connect,
81 .disconnect = tfp410_disconnect,
82 .enable = tfp410_enable,
83 .disable = tfp410_disable,
86 static int tfp410_probe(struct platform_device *pdev)
88 struct panel_drv_data *ddata;
89 struct omap_dss_device *dssdev;
90 struct gpio_desc *gpio;
92 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
96 platform_set_drvdata(pdev, ddata);
99 gpio = devm_gpiod_get_optional(&pdev->dev, "powerdown", GPIOD_OUT_HIGH);
101 dev_err(&pdev->dev, "failed to parse powerdown gpio\n");
102 return PTR_ERR(gpio);
105 ddata->pd_gpio = gpio;
107 dssdev = &ddata->dssdev;
108 dssdev->ops = &tfp410_ops;
109 dssdev->dev = &pdev->dev;
110 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
111 dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
112 dssdev->owner = THIS_MODULE;
113 dssdev->of_ports = BIT(1) | BIT(0);
114 dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_SYNC_POSEDGE
115 | DRM_BUS_FLAG_PIXDATA_POSEDGE;
117 dssdev->next = omapdss_of_find_connected_device(pdev->dev.of_node, 1);
118 if (IS_ERR(dssdev->next)) {
119 if (PTR_ERR(dssdev->next) != -EPROBE_DEFER)
120 dev_err(&pdev->dev, "failed to find video sink\n");
121 return PTR_ERR(dssdev->next);
124 omapdss_device_register(dssdev);
129 static int __exit tfp410_remove(struct platform_device *pdev)
131 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
132 struct omap_dss_device *dssdev = &ddata->dssdev;
135 omapdss_device_put(dssdev->next);
136 omapdss_device_unregister(&ddata->dssdev);
138 WARN_ON(omapdss_device_is_enabled(dssdev));
139 if (omapdss_device_is_enabled(dssdev))
140 tfp410_disable(dssdev);
142 WARN_ON(omapdss_device_is_connected(dssdev));
143 if (omapdss_device_is_connected(dssdev))
144 omapdss_device_disconnect(NULL, dssdev);
149 static const struct of_device_id tfp410_of_match[] = {
150 { .compatible = "omapdss,ti,tfp410", },
154 MODULE_DEVICE_TABLE(of, tfp410_of_match);
156 static struct platform_driver tfp410_driver = {
157 .probe = tfp410_probe,
158 .remove = __exit_p(tfp410_remove),
161 .of_match_table = tfp410_of_match,
162 .suppress_bind_attrs = true,
166 module_platform_driver(tfp410_driver);
169 MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
170 MODULE_LICENSE("GPL");