Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tps6105x: add optional devicetree support

This driver currently requires platform data to specify the
operational mode and regulator init data (in case of regulator
mode).

Optionally specify the operational mode by looking at the name
of the devicetree child node.

Example: put chip in regulator mode:

i2c0 {
tps61052@33 {
compatible = "ti,tps61052";
reg = <0x33>;

regulator {
regulator-min-microvolt = <5000000>;
regulator-max-microvolt = <5000000>;
regulator-always-on;
};
};
};

Tree: linux-next
Signed-off-by: Sven Van Asbroeck <TheSven73@gmail.com>
Link: https://lore.kernel.org/r/20191119154611.29625-2-TheSven73@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Sven Van Asbroeck and committed by
Mark Brown
62f7f3ec 1d7c4c11

+31 -3
+31 -3
drivers/mfd/tps6105x.c
··· 91 91 PLATFORM_DEVID_AUTO, cell, 1, NULL, 0, NULL); 92 92 } 93 93 94 + static struct tps6105x_platform_data *tps6105x_parse_dt(struct device *dev) 95 + { 96 + struct device_node *np = dev->of_node; 97 + struct tps6105x_platform_data *pdata; 98 + struct device_node *child; 99 + 100 + if (!np) 101 + return ERR_PTR(-EINVAL); 102 + if (of_get_available_child_count(np) > 1) { 103 + dev_err(dev, "cannot support multiple operational modes"); 104 + return ERR_PTR(-EINVAL); 105 + } 106 + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 107 + if (!pdata) 108 + return ERR_PTR(-ENOMEM); 109 + pdata->mode = TPS6105X_MODE_SHUTDOWN; 110 + for_each_available_child_of_node(np, child) { 111 + if (child->name && !of_node_cmp(child->name, "regulator")) 112 + pdata->mode = TPS6105X_MODE_VOLTAGE; 113 + else if (child->name && !of_node_cmp(child->name, "led")) 114 + pdata->mode = TPS6105X_MODE_TORCH; 115 + } 116 + 117 + return pdata; 118 + } 119 + 94 120 static int tps6105x_probe(struct i2c_client *client, 95 121 const struct i2c_device_id *id) 96 122 { ··· 125 99 int ret; 126 100 127 101 pdata = dev_get_platdata(&client->dev); 128 - if (!pdata) { 129 - dev_err(&client->dev, "missing platform data\n"); 130 - return -ENODEV; 102 + if (!pdata) 103 + pdata = tps6105x_parse_dt(&client->dev); 104 + if (IS_ERR(pdata)) { 105 + dev_err(&client->dev, "No platform data or DT found"); 106 + return PTR_ERR(pdata); 131 107 } 132 108 133 109 tps6105x = devm_kmalloc(&client->dev, sizeof(*tps6105x), GFP_KERNEL);