]> Git Repo - linux.git/blob - drivers/gpu/drm/omapdrm/displays/encoder-tfp410.c
Merge tag 'char-misc-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregk...
[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 <[email protected]>
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 int tfp410_enable(struct omap_dss_device *dssdev)
40 {
41         struct panel_drv_data *ddata = to_panel_data(dssdev);
42         struct omap_dss_device *src = dssdev->src;
43         int r;
44
45         if (!omapdss_device_is_connected(dssdev))
46                 return -ENODEV;
47
48         if (omapdss_device_is_enabled(dssdev))
49                 return 0;
50
51         r = src->ops->enable(src);
52         if (r)
53                 return r;
54
55         if (ddata->pd_gpio)
56                 gpiod_set_value_cansleep(ddata->pd_gpio, 0);
57
58         dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
59
60         return 0;
61 }
62
63 static void tfp410_disable(struct omap_dss_device *dssdev)
64 {
65         struct panel_drv_data *ddata = to_panel_data(dssdev);
66         struct omap_dss_device *src = dssdev->src;
67
68         if (!omapdss_device_is_enabled(dssdev))
69                 return;
70
71         if (ddata->pd_gpio)
72                 gpiod_set_value_cansleep(ddata->pd_gpio, 0);
73
74         src->ops->disable(src);
75
76         dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
77 }
78
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,
84 };
85
86 static int tfp410_probe(struct platform_device *pdev)
87 {
88         struct panel_drv_data *ddata;
89         struct omap_dss_device *dssdev;
90         struct gpio_desc *gpio;
91
92         ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
93         if (!ddata)
94                 return -ENOMEM;
95
96         platform_set_drvdata(pdev, ddata);
97
98         /* Powerdown GPIO */
99         gpio = devm_gpiod_get_optional(&pdev->dev, "powerdown", GPIOD_OUT_HIGH);
100         if (IS_ERR(gpio)) {
101                 dev_err(&pdev->dev, "failed to parse powerdown gpio\n");
102                 return PTR_ERR(gpio);
103         }
104
105         ddata->pd_gpio = gpio;
106
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;
116
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);
122         }
123
124         omapdss_device_register(dssdev);
125
126         return 0;
127 }
128
129 static int __exit tfp410_remove(struct platform_device *pdev)
130 {
131         struct panel_drv_data *ddata = platform_get_drvdata(pdev);
132         struct omap_dss_device *dssdev = &ddata->dssdev;
133
134         if (dssdev->next)
135                 omapdss_device_put(dssdev->next);
136         omapdss_device_unregister(&ddata->dssdev);
137
138         WARN_ON(omapdss_device_is_enabled(dssdev));
139         if (omapdss_device_is_enabled(dssdev))
140                 tfp410_disable(dssdev);
141
142         WARN_ON(omapdss_device_is_connected(dssdev));
143         if (omapdss_device_is_connected(dssdev))
144                 omapdss_device_disconnect(NULL, dssdev);
145
146         return 0;
147 }
148
149 static const struct of_device_id tfp410_of_match[] = {
150         { .compatible = "omapdss,ti,tfp410", },
151         {},
152 };
153
154 MODULE_DEVICE_TABLE(of, tfp410_of_match);
155
156 static struct platform_driver tfp410_driver = {
157         .probe  = tfp410_probe,
158         .remove = __exit_p(tfp410_remove),
159         .driver = {
160                 .name   = "tfp410",
161                 .of_match_table = tfp410_of_match,
162                 .suppress_bind_attrs = true,
163         },
164 };
165
166 module_platform_driver(tfp410_driver);
167
168 MODULE_AUTHOR("Tomi Valkeinen <[email protected]>");
169 MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
170 MODULE_LICENSE("GPL");
This page took 0.040385 seconds and 4 git commands to generate.