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

Configure Feed

Select the types of activity you want to include in your feed.

iio: light: bh1750: Add hardware reset support via GPIO

Some BH1750 sensors require a hardware reset before they can be
detected on the I2C bus. This implementation adds support for an
optional reset GPIO that can be specified in the device tree.

The reset sequence pulls the GPIO low and then high before initializing
the sensor, which enables proper detection with tools like i2cdetect.
This is particularly important for sensors that power on in an
undefined state.

Signed-off-by: Sergio Perez <sergio@pereznus.es>
Link: https://patch.msgid.link/20250324135920.6802-2-sergio@pereznus.es
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Sergio Perez and committed by
Jonathan Cameron
61f013df 3e09eb53

+24
+24
drivers/iio/light/bh1750.c
··· 22 22 #include <linux/iio/iio.h> 23 23 #include <linux/iio/sysfs.h> 24 24 #include <linux/module.h> 25 + #include <linux/gpio/consumer.h> 25 26 26 27 #define BH1750_POWER_DOWN 0x00 27 28 #define BH1750_ONE_TIME_H_RES_MODE 0x20 /* auto-mode for BH1721 */ 28 29 #define BH1750_CHANGE_INT_TIME_H_BIT 0x40 29 30 #define BH1750_CHANGE_INT_TIME_L_BIT 0x60 31 + 32 + /* Define the reset delay time in microseconds */ 33 + #define BH1750_RESET_DELAY_US 10000 /* 10ms */ 30 34 31 35 enum { 32 36 BH1710, ··· 44 40 struct mutex lock; 45 41 const struct bh1750_chip_info *chip_info; 46 42 u16 mtreg; 43 + struct gpio_desc *reset_gpio; 47 44 }; 48 45 49 46 struct bh1750_chip_info { ··· 252 247 i2c_set_clientdata(client, indio_dev); 253 248 data->client = client; 254 249 data->chip_info = &bh1750_chip_info_tbl[id->driver_data]; 250 + 251 + /* Get reset GPIO from device tree */ 252 + data->reset_gpio = devm_gpiod_get_optional(&client->dev, 253 + "reset", GPIOD_OUT_HIGH); 254 + 255 + if (IS_ERR(data->reset_gpio)) 256 + return dev_err_probe(&client->dev, PTR_ERR(data->reset_gpio), 257 + "Failed to get reset GPIO\n"); 258 + 259 + /* Perform hardware reset if GPIO is provided */ 260 + if (data->reset_gpio) { 261 + /* Perform reset sequence: low-high */ 262 + gpiod_set_value_cansleep(data->reset_gpio, 1); 263 + fsleep(BH1750_RESET_DELAY_US); 264 + gpiod_set_value_cansleep(data->reset_gpio, 0); 265 + fsleep(BH1750_RESET_DELAY_US); 266 + 267 + dev_dbg(&client->dev, "BH1750 reset completed via GPIO\n"); 268 + } 255 269 256 270 usec = data->chip_info->mtreg_to_usec * data->chip_info->mtreg_default; 257 271 ret = bh1750_change_int_time(data, usec);