2 * OPA362 analog video amplifier with output/power control
4 * Copyright (C) 2014 Golden Delicious Computers
5 * Author: H. Nikolaus Schaller <hns@goldelico.com>
7 * based on encoder-tfp410
9 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
10 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
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.
17 #include <linux/gpio/consumer.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
22 #include "../dss/omapdss.h"
24 struct panel_drv_data {
25 struct omap_dss_device dssdev;
27 struct gpio_desc *enable_gpio;
30 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
32 static int opa362_connect(struct omap_dss_device *src,
33 struct omap_dss_device *dst)
35 return omapdss_device_connect(dst->dss, dst, dst->next);
38 static void opa362_disconnect(struct omap_dss_device *src,
39 struct omap_dss_device *dst)
41 omapdss_device_disconnect(dst, dst->next);
44 static void opa362_enable(struct omap_dss_device *dssdev)
46 struct panel_drv_data *ddata = to_panel_data(dssdev);
48 if (ddata->enable_gpio)
49 gpiod_set_value_cansleep(ddata->enable_gpio, 1);
52 static void opa362_disable(struct omap_dss_device *dssdev)
54 struct panel_drv_data *ddata = to_panel_data(dssdev);
56 if (ddata->enable_gpio)
57 gpiod_set_value_cansleep(ddata->enable_gpio, 0);
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,
67 static int opa362_probe(struct platform_device *pdev)
69 struct panel_drv_data *ddata;
70 struct omap_dss_device *dssdev;
71 struct gpio_desc *gpio;
73 dev_dbg(&pdev->dev, "probe\n");
75 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
79 platform_set_drvdata(pdev, ddata);
81 gpio = devm_gpiod_get_optional(&pdev->dev, "enable", GPIOD_OUT_LOW);
85 ddata->enable_gpio = gpio;
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);
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);
101 omapdss_device_register(dssdev);
106 static int __exit opa362_remove(struct platform_device *pdev)
108 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
109 struct omap_dss_device *dssdev = &ddata->dssdev;
112 omapdss_device_put(dssdev->next);
113 omapdss_device_unregister(&ddata->dssdev);
115 opa362_disable(dssdev);
120 static const struct of_device_id opa362_of_match[] = {
121 { .compatible = "omapdss,ti,opa362", },
124 MODULE_DEVICE_TABLE(of, opa362_of_match);
126 static struct platform_driver opa362_driver = {
127 .probe = opa362_probe,
128 .remove = __exit_p(opa362_remove),
130 .name = "amplifier-opa362",
131 .of_match_table = opa362_of_match,
132 .suppress_bind_attrs = true,
136 module_platform_driver(opa362_driver);
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");