1 // SPDX-License-Identifier: GPL-2.0
3 * THC63LVD1024 LVDS to parallel data DRM bridge driver.
5 * Copyright (C) 2018 Jacopo Mondi <jacopo+renesas@jmondi.org>
9 #include <drm/drm_bridge.h>
10 #include <drm/drm_panel.h>
12 #include <linux/gpio/consumer.h>
13 #include <linux/of_graph.h>
14 #include <linux/regulator/consumer.h>
15 #include <linux/slab.h>
27 struct regulator *vcc;
29 struct gpio_desc *pdwn;
32 struct drm_bridge bridge;
33 struct drm_bridge *next;
36 static inline struct thc63_dev *to_thc63(struct drm_bridge *bridge)
38 return container_of(bridge, struct thc63_dev, bridge);
41 static int thc63_attach(struct drm_bridge *bridge)
43 struct thc63_dev *thc63 = to_thc63(bridge);
45 return drm_bridge_attach(bridge->encoder, thc63->next, bridge);
48 static void thc63_enable(struct drm_bridge *bridge)
50 struct thc63_dev *thc63 = to_thc63(bridge);
53 ret = regulator_enable(thc63->vcc);
56 "Failed to enable regulator \"vcc\": %d\n", ret);
60 gpiod_set_value(thc63->pdwn, 0);
61 gpiod_set_value(thc63->oe, 1);
64 static void thc63_disable(struct drm_bridge *bridge)
66 struct thc63_dev *thc63 = to_thc63(bridge);
69 gpiod_set_value(thc63->oe, 0);
70 gpiod_set_value(thc63->pdwn, 1);
72 ret = regulator_disable(thc63->vcc);
75 "Failed to disable regulator \"vcc\": %d\n", ret);
78 static const struct drm_bridge_funcs thc63_bridge_func = {
79 .attach = thc63_attach,
80 .enable = thc63_enable,
81 .disable = thc63_disable,
84 static int thc63_parse_dt(struct thc63_dev *thc63)
86 struct device_node *thc63_out;
87 struct device_node *remote;
89 thc63_out = of_graph_get_endpoint_by_regs(thc63->dev->of_node,
92 dev_err(thc63->dev, "Missing endpoint in port@%u\n",
97 remote = of_graph_get_remote_port_parent(thc63_out);
98 of_node_put(thc63_out);
100 dev_err(thc63->dev, "Endpoint in port@%u unconnected\n",
105 if (!of_device_is_available(remote)) {
106 dev_err(thc63->dev, "port@%u remote endpoint is disabled\n",
112 thc63->next = of_drm_find_bridge(remote);
115 return -EPROBE_DEFER;
120 static int thc63_gpio_init(struct thc63_dev *thc63)
122 thc63->oe = devm_gpiod_get_optional(thc63->dev, "oe", GPIOD_OUT_LOW);
123 if (IS_ERR(thc63->oe)) {
124 dev_err(thc63->dev, "Unable to get \"oe-gpios\": %ld\n",
126 return PTR_ERR(thc63->oe);
129 thc63->pdwn = devm_gpiod_get_optional(thc63->dev, "powerdown",
131 if (IS_ERR(thc63->pdwn)) {
132 dev_err(thc63->dev, "Unable to get \"powerdown-gpios\": %ld\n",
133 PTR_ERR(thc63->pdwn));
134 return PTR_ERR(thc63->pdwn);
140 static int thc63_probe(struct platform_device *pdev)
142 struct thc63_dev *thc63;
145 thc63 = devm_kzalloc(&pdev->dev, sizeof(*thc63), GFP_KERNEL);
149 thc63->dev = &pdev->dev;
150 platform_set_drvdata(pdev, thc63);
152 thc63->vcc = devm_regulator_get_optional(thc63->dev, "vcc");
153 if (IS_ERR(thc63->vcc)) {
154 if (PTR_ERR(thc63->vcc) == -EPROBE_DEFER)
155 return -EPROBE_DEFER;
157 dev_err(thc63->dev, "Unable to get \"vcc\" supply: %ld\n",
158 PTR_ERR(thc63->vcc));
159 return PTR_ERR(thc63->vcc);
162 ret = thc63_gpio_init(thc63);
166 ret = thc63_parse_dt(thc63);
170 thc63->bridge.driver_private = thc63;
171 thc63->bridge.of_node = pdev->dev.of_node;
172 thc63->bridge.funcs = &thc63_bridge_func;
174 drm_bridge_add(&thc63->bridge);
179 static int thc63_remove(struct platform_device *pdev)
181 struct thc63_dev *thc63 = platform_get_drvdata(pdev);
183 drm_bridge_remove(&thc63->bridge);
188 static const struct of_device_id thc63_match[] = {
189 { .compatible = "thine,thc63lvd1024", },
192 MODULE_DEVICE_TABLE(of, thc63_match);
194 static struct platform_driver thc63_driver = {
195 .probe = thc63_probe,
196 .remove = thc63_remove,
198 .name = "thc63lvd1024",
199 .of_match_table = thc63_match,
202 module_platform_driver(thc63_driver);
204 MODULE_AUTHOR("Jacopo Mondi <jacopo@jmondi.org>");
205 MODULE_DESCRIPTION("Thine THC63LVD1024 LVDS decoder DRM bridge driver");
206 MODULE_LICENSE("GPL v2");