ARC: [plat-hsdk]: unify memory apertures configuration
[linux-2.6-microblaze.git] / drivers / gpu / drm / omapdrm / displays / encoder-opa362.c
1 /*
2  * OPA362 analog video amplifier with output/power control
3  *
4  * Copyright (C) 2014 Golden Delicious Computers
5  * Author: H. Nikolaus Schaller <hns@goldelico.com>
6  *
7  * based on encoder-tfp410
8  *
9  * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
10  * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License version 2 as published by
14  * the Free Software Foundation.
15  */
16
17 #include <linux/gpio/consumer.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
21
22 #include "../dss/omapdss.h"
23
24 struct panel_drv_data {
25         struct omap_dss_device dssdev;
26
27         struct gpio_desc *enable_gpio;
28 };
29
30 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
31
32 static int opa362_connect(struct omap_dss_device *src,
33                           struct omap_dss_device *dst)
34 {
35         return omapdss_device_connect(dst->dss, dst, dst->next);
36 }
37
38 static void opa362_disconnect(struct omap_dss_device *src,
39                               struct omap_dss_device *dst)
40 {
41         omapdss_device_disconnect(dst, dst->next);
42 }
43
44 static void opa362_enable(struct omap_dss_device *dssdev)
45 {
46         struct panel_drv_data *ddata = to_panel_data(dssdev);
47
48         if (ddata->enable_gpio)
49                 gpiod_set_value_cansleep(ddata->enable_gpio, 1);
50 }
51
52 static void opa362_disable(struct omap_dss_device *dssdev)
53 {
54         struct panel_drv_data *ddata = to_panel_data(dssdev);
55
56         if (ddata->enable_gpio)
57                 gpiod_set_value_cansleep(ddata->enable_gpio, 0);
58 }
59
60 static const struct omap_dss_device_ops opa362_ops = {
61         .connect        = opa362_connect,
62         .disconnect     = opa362_disconnect,
63         .enable         = opa362_enable,
64         .disable        = opa362_disable,
65 };
66
67 static int opa362_probe(struct platform_device *pdev)
68 {
69         struct panel_drv_data *ddata;
70         struct omap_dss_device *dssdev;
71         struct gpio_desc *gpio;
72
73         dev_dbg(&pdev->dev, "probe\n");
74
75         ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
76         if (!ddata)
77                 return -ENOMEM;
78
79         platform_set_drvdata(pdev, ddata);
80
81         gpio = devm_gpiod_get_optional(&pdev->dev, "enable", GPIOD_OUT_LOW);
82         if (IS_ERR(gpio))
83                 return PTR_ERR(gpio);
84
85         ddata->enable_gpio = gpio;
86
87         dssdev = &ddata->dssdev;
88         dssdev->ops = &opa362_ops;
89         dssdev->dev = &pdev->dev;
90         dssdev->type = OMAP_DISPLAY_TYPE_VENC;
91         dssdev->owner = THIS_MODULE;
92         dssdev->of_ports = BIT(1) | BIT(0);
93
94         dssdev->next = omapdss_of_find_connected_device(pdev->dev.of_node, 1);
95         if (IS_ERR(dssdev->next)) {
96                 if (PTR_ERR(dssdev->next) != -EPROBE_DEFER)
97                         dev_err(&pdev->dev, "failed to find video sink\n");
98                 return PTR_ERR(dssdev->next);
99         }
100
101         omapdss_device_register(dssdev);
102
103         return 0;
104 }
105
106 static int __exit opa362_remove(struct platform_device *pdev)
107 {
108         struct panel_drv_data *ddata = platform_get_drvdata(pdev);
109         struct omap_dss_device *dssdev = &ddata->dssdev;
110
111         if (dssdev->next)
112                 omapdss_device_put(dssdev->next);
113         omapdss_device_unregister(&ddata->dssdev);
114
115         opa362_disable(dssdev);
116
117         return 0;
118 }
119
120 static const struct of_device_id opa362_of_match[] = {
121         { .compatible = "omapdss,ti,opa362", },
122         {},
123 };
124 MODULE_DEVICE_TABLE(of, opa362_of_match);
125
126 static struct platform_driver opa362_driver = {
127         .probe  = opa362_probe,
128         .remove = __exit_p(opa362_remove),
129         .driver = {
130                 .name   = "amplifier-opa362",
131                 .of_match_table = opa362_of_match,
132                 .suppress_bind_attrs = true,
133         },
134 };
135
136 module_platform_driver(opa362_driver);
137
138 MODULE_AUTHOR("H. Nikolaus Schaller <hns@goldelico.com>");
139 MODULE_DESCRIPTION("OPA362 analog video amplifier with output/power control");
140 MODULE_LICENSE("GPL v2");