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

iio: sx9310: Enable vdd and svdd regulators at probe

Enable the main power supply (vdd) and digital IO power supply (svdd)
during probe so that the i2c communication and device works properly on
boards that aggressively power gate these supplies.

Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Daniel Campello <campello@chromium.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Stephen Boyd and committed by
Jonathan Cameron
f86ff748 2756db5e

+26
+26
drivers/iio/proximity/sx9310.c
··· 20 20 #include <linux/module.h> 21 21 #include <linux/pm.h> 22 22 #include <linux/regmap.h> 23 + #include <linux/regulator/consumer.h> 23 24 #include <linux/slab.h> 24 25 25 26 #include <linux/iio/buffer.h> ··· 121 120 struct i2c_client *client; 122 121 struct iio_trigger *trig; 123 122 struct regmap *regmap; 123 + struct regulator_bulk_data supplies[2]; 124 124 /* 125 125 * Last reading of the proximity status for each channel. 126 126 * We only send an event to user space when this changes. ··· 876 874 return 0; 877 875 } 878 876 877 + static void sx9310_regulator_disable(void *_data) 878 + { 879 + struct sx9310_data *data = _data; 880 + 881 + regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies); 882 + } 883 + 879 884 static int sx9310_probe(struct i2c_client *client) 880 885 { 881 886 int ret; ··· 896 887 897 888 data = iio_priv(indio_dev); 898 889 data->client = client; 890 + data->supplies[0].supply = "vdd"; 891 + data->supplies[1].supply = "svdd"; 899 892 mutex_init(&data->mutex); 900 893 init_completion(&data->completion); 901 894 902 895 data->regmap = devm_regmap_init_i2c(client, &sx9310_regmap_config); 903 896 if (IS_ERR(data->regmap)) 904 897 return PTR_ERR(data->regmap); 898 + 899 + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->supplies), 900 + data->supplies); 901 + if (ret) 902 + return ret; 903 + 904 + ret = regulator_bulk_enable(ARRAY_SIZE(data->supplies), data->supplies); 905 + if (ret) 906 + return ret; 907 + /* Must wait for Tpor time after initial power up */ 908 + usleep_range(1000, 1100); 909 + 910 + ret = devm_add_action_or_reset(dev, sx9310_regulator_disable, data); 911 + if (ret) 912 + return ret; 905 913 906 914 ret = regmap_read(data->regmap, SX9310_REG_WHOAMI, &data->whoami); 907 915 if (ret) {