1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright 2024 Freebox SAS 4 */ 5 6 #include <linux/gpio/consumer.h> 7 #include <linux/i2c.h> 8 9 #include <drm/drm_atomic_helper.h> 10 #include <drm/drm_bridge.h> 11 12 struct tdp158 { 13 struct drm_bridge bridge; 14 struct drm_bridge *next; 15 struct gpio_desc *enable; // Operation Enable - pin 36 16 struct regulator *vcc; // 3.3V 17 struct regulator *vdd; // 1.1V 18 struct device *dev; 19 }; 20 21 static void tdp158_enable(struct drm_bridge *bridge, struct drm_bridge_state *prev) 22 { 23 int err; 24 struct tdp158 *tdp158 = bridge->driver_private; 25 26 err = regulator_enable(tdp158->vcc); 27 if (err) 28 dev_err(tdp158->dev, "failed to enable vcc: %d", err); 29 30 err = regulator_enable(tdp158->vdd); 31 if (err) 32 dev_err(tdp158->dev, "failed to enable vdd: %d", err); 33 34 gpiod_set_value_cansleep(tdp158->enable, 1); 35 } 36 37 static void tdp158_disable(struct drm_bridge *bridge, struct drm_bridge_state *prev) 38 { 39 struct tdp158 *tdp158 = bridge->driver_private; 40 41 gpiod_set_value_cansleep(tdp158->enable, 0); 42 regulator_disable(tdp158->vdd); 43 regulator_disable(tdp158->vcc); 44 } 45 46 static int tdp158_attach(struct drm_bridge *bridge, enum drm_bridge_attach_flags flags) 47 { 48 struct tdp158 *tdp158 = bridge->driver_private; 49 50 return drm_bridge_attach(bridge->encoder, tdp158->next, bridge, flags); 51 } 52 53 static const struct drm_bridge_funcs tdp158_bridge_funcs = { 54 .attach = tdp158_attach, 55 .atomic_enable = tdp158_enable, 56 .atomic_disable = tdp158_disable, 57 .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, 58 .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, 59 .atomic_reset = drm_atomic_helper_bridge_reset, 60 }; 61 62 static int tdp158_probe(struct i2c_client *client) 63 { 64 struct tdp158 *tdp158; 65 struct device *dev = &client->dev; 66 67 tdp158 = devm_kzalloc(dev, sizeof(*tdp158), GFP_KERNEL); 68 if (!tdp158) 69 return -ENOMEM; 70 71 tdp158->next = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0); 72 if (IS_ERR(tdp158->next)) 73 return dev_err_probe(dev, PTR_ERR(tdp158->next), "missing bridge"); 74 75 tdp158->vcc = devm_regulator_get(dev, "vcc"); 76 if (IS_ERR(tdp158->vcc)) 77 return dev_err_probe(dev, PTR_ERR(tdp158->vcc), "vcc"); 78 79 tdp158->vdd = devm_regulator_get(dev, "vdd"); 80 if (IS_ERR(tdp158->vdd)) 81 return dev_err_probe(dev, PTR_ERR(tdp158->vdd), "vdd"); 82 83 tdp158->enable = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW); 84 if (IS_ERR(tdp158->enable)) 85 return dev_err_probe(dev, PTR_ERR(tdp158->enable), "enable"); 86 87 tdp158->bridge.of_node = dev->of_node; 88 tdp158->bridge.funcs = &tdp158_bridge_funcs; 89 tdp158->bridge.driver_private = tdp158; 90 tdp158->dev = dev; 91 92 return devm_drm_bridge_add(dev, &tdp158->bridge); 93 } 94 95 static const struct of_device_id tdp158_match_table[] = { 96 { .compatible = "ti,tdp158" }, 97 { } 98 }; 99 MODULE_DEVICE_TABLE(of, tdp158_match_table); 100 101 static struct i2c_driver tdp158_driver = { 102 .probe = tdp158_probe, 103 .driver = { 104 .name = "tdp158", 105 .of_match_table = tdp158_match_table, 106 }, 107 }; 108 module_i2c_driver(tdp158_driver); 109 110 MODULE_DESCRIPTION("TI TDP158 driver"); 111 MODULE_LICENSE("GPL"); 112