]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/omapdrm/displays/encoder-tfp410.c
drm: Use new DRM_BUS_FLAG_*_(DRIVE|SAMPLE)_(POS|NEG)EDGE flags
[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
90                           | DRM_BUS_FLAG_SYNC_DRIVE_POSEDGE
91                           | DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE;
92
93         dssdev->next = omapdss_of_find_connected_device(pdev->dev.of_node, 1);
94         if (IS_ERR(dssdev->next)) {
95                 if (PTR_ERR(dssdev->next) != -EPROBE_DEFER)
96                         dev_err(&pdev->dev, "failed to find video sink\n");
97                 return PTR_ERR(dssdev->next);
98         }
99
100         omapdss_device_register(dssdev);
101
102         return 0;
103 }
104
105 static int __exit tfp410_remove(struct platform_device *pdev)
106 {
107         struct panel_drv_data *ddata = platform_get_drvdata(pdev);
108         struct omap_dss_device *dssdev = &ddata->dssdev;
109
110         if (dssdev->next)
111                 omapdss_device_put(dssdev->next);
112         omapdss_device_unregister(&ddata->dssdev);
113
114         tfp410_disable(dssdev);
115
116         return 0;
117 }
118
119 static const struct of_device_id tfp410_of_match[] = {
120         { .compatible = "omapdss,ti,tfp410", },
121         {},
122 };
123
124 MODULE_DEVICE_TABLE(of, tfp410_of_match);
125
126 static struct platform_driver tfp410_driver = {
127         .probe  = tfp410_probe,
128         .remove = __exit_p(tfp410_remove),
129         .driver = {
130                 .name   = "tfp410",
131                 .of_match_table = tfp410_of_match,
132                 .suppress_bind_attrs = true,
133         },
134 };
135
136 module_platform_driver(tfp410_driver);
137
138 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
139 MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
140 MODULE_LICENSE("GPL");