]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/omapdrm/displays/encoder-tfp410.c
drm/omap: Merge omap_dss_device type and output_type fields
[linux.git] / drivers / gpu / drm / omapdrm / displays / encoder-tfp410.c
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
17 #include "../dss/omapdss.h"
18
19 struct panel_drv_data {
20         struct omap_dss_device dssdev;
21
22         struct gpio_desc *pd_gpio;
23 };
24
25 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
26
27 static int tfp410_connect(struct omap_dss_device *src,
28                           struct omap_dss_device *dst)
29 {
30         return omapdss_device_connect(dst->dss, dst, dst->next);
31 }
32
33 static void tfp410_disconnect(struct omap_dss_device *src,
34                               struct omap_dss_device *dst)
35 {
36         omapdss_device_disconnect(dst, dst->next);
37 }
38
39 static void tfp410_enable(struct omap_dss_device *dssdev)
40 {
41         struct panel_drv_data *ddata = to_panel_data(dssdev);
42
43         if (ddata->pd_gpio)
44                 gpiod_set_value_cansleep(ddata->pd_gpio, 0);
45 }
46
47 static void tfp410_disable(struct omap_dss_device *dssdev)
48 {
49         struct panel_drv_data *ddata = to_panel_data(dssdev);
50
51         if (ddata->pd_gpio)
52                 gpiod_set_value_cansleep(ddata->pd_gpio, 0);
53 }
54
55 static const struct omap_dss_device_ops tfp410_ops = {
56         .connect        = tfp410_connect,
57         .disconnect     = tfp410_disconnect,
58         .enable         = tfp410_enable,
59         .disable        = tfp410_disable,
60 };
61
62 static int tfp410_probe(struct platform_device *pdev)
63 {
64         struct panel_drv_data *ddata;
65         struct omap_dss_device *dssdev;
66         struct gpio_desc *gpio;
67
68         ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
69         if (!ddata)
70                 return -ENOMEM;
71
72         platform_set_drvdata(pdev, ddata);
73
74         /* Powerdown GPIO */
75         gpio = devm_gpiod_get_optional(&pdev->dev, "powerdown", GPIOD_OUT_HIGH);
76         if (IS_ERR(gpio)) {
77                 dev_err(&pdev->dev, "failed to parse powerdown gpio\n");
78                 return PTR_ERR(gpio);
79         }
80
81         ddata->pd_gpio = gpio;
82
83         dssdev = &ddata->dssdev;
84         dssdev->ops = &tfp410_ops;
85         dssdev->dev = &pdev->dev;
86         dssdev->type = OMAP_DISPLAY_TYPE_DPI;
87         dssdev->owner = THIS_MODULE;
88         dssdev->of_ports = BIT(1) | BIT(0);
89         dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_SYNC_POSEDGE
90                           | DRM_BUS_FLAG_PIXDATA_POSEDGE;
91
92         dssdev->next = omapdss_of_find_connected_device(pdev->dev.of_node, 1);
93         if (IS_ERR(dssdev->next)) {
94                 if (PTR_ERR(dssdev->next) != -EPROBE_DEFER)
95                         dev_err(&pdev->dev, "failed to find video sink\n");
96                 return PTR_ERR(dssdev->next);
97         }
98
99         omapdss_device_register(dssdev);
100
101         return 0;
102 }
103
104 static int __exit tfp410_remove(struct platform_device *pdev)
105 {
106         struct panel_drv_data *ddata = platform_get_drvdata(pdev);
107         struct omap_dss_device *dssdev = &ddata->dssdev;
108
109         if (dssdev->next)
110                 omapdss_device_put(dssdev->next);
111         omapdss_device_unregister(&ddata->dssdev);
112
113         tfp410_disable(dssdev);
114
115         return 0;
116 }
117
118 static const struct of_device_id tfp410_of_match[] = {
119         { .compatible = "omapdss,ti,tfp410", },
120         {},
121 };
122
123 MODULE_DEVICE_TABLE(of, tfp410_of_match);
124
125 static struct platform_driver tfp410_driver = {
126         .probe  = tfp410_probe,
127         .remove = __exit_p(tfp410_remove),
128         .driver = {
129                 .name   = "tfp410",
130                 .of_match_table = tfp410_of_match,
131                 .suppress_bind_attrs = true,
132         },
133 };
134
135 module_platform_driver(tfp410_driver);
136
137 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
138 MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
139 MODULE_LICENSE("GPL");