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: imu: st_lsm6dsx: add vdd-vddio voltage regulator

Like all other ST sensors, st_lsm6dsx devices have VDD and VDDIO power
lines. Introduce voltage regulators to control them.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Link: https://lore.kernel.org/r/a0427a66360bdec73c3b1fb536a46240f96b2ae7.1605631305.git.lorenzo@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Lorenzo Bianconi and committed by
Jonathan Cameron
f346b16f 99ff938f

+43
+3
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
··· 13 13 14 14 #include <linux/device.h> 15 15 #include <linux/iio/iio.h> 16 + #include <linux/regulator/consumer.h> 16 17 17 18 #define ST_LSM6DS3_DEV_NAME "lsm6ds3" 18 19 #define ST_LSM6DS3H_DEV_NAME "lsm6ds3h" ··· 369 368 * struct st_lsm6dsx_hw - ST IMU MEMS hw instance 370 369 * @dev: Pointer to instance of struct device (I2C or SPI). 371 370 * @regmap: Register map of the device. 371 + * @regulators: VDD/VDDIO voltage regulators. 372 372 * @irq: Device interrupt line (I2C or SPI). 373 373 * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO. 374 374 * @conf_lock: Mutex to prevent concurrent FIFO configuration update. ··· 392 390 struct st_lsm6dsx_hw { 393 391 struct device *dev; 394 392 struct regmap *regmap; 393 + struct regulator_bulk_data regulators[2]; 395 394 int irq; 396 395 397 396 struct mutex fifo_lock;
+40
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 2533 2533 return 0; 2534 2534 } 2535 2535 2536 + static int st_lsm6dsx_init_regulators(struct device *dev) 2537 + { 2538 + struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev); 2539 + int err; 2540 + 2541 + /* vdd-vddio power regulators */ 2542 + hw->regulators[0].supply = "vdd"; 2543 + hw->regulators[1].supply = "vddio"; 2544 + err = devm_regulator_bulk_get(dev, ARRAY_SIZE(hw->regulators), 2545 + hw->regulators); 2546 + if (err) 2547 + return dev_err_probe(dev, err, "failed to get regulators\n"); 2548 + 2549 + err = regulator_bulk_enable(ARRAY_SIZE(hw->regulators), 2550 + hw->regulators); 2551 + if (err) { 2552 + dev_err(dev, "failed to enable regulators: %d\n", err); 2553 + return err; 2554 + } 2555 + 2556 + msleep(50); 2557 + 2558 + return 0; 2559 + } 2560 + 2561 + static void st_lsm6dsx_chip_uninit(void *data) 2562 + { 2563 + struct st_lsm6dsx_hw *hw = data; 2564 + 2565 + regulator_bulk_disable(ARRAY_SIZE(hw->regulators), hw->regulators); 2566 + } 2567 + 2536 2568 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, 2537 2569 struct regmap *regmap) 2538 2570 { ··· 2583 2551 mutex_init(&hw->fifo_lock); 2584 2552 mutex_init(&hw->conf_lock); 2585 2553 mutex_init(&hw->page_lock); 2554 + 2555 + err = st_lsm6dsx_init_regulators(dev); 2556 + if (err) 2557 + return err; 2558 + 2559 + err = devm_add_action_or_reset(dev, st_lsm6dsx_chip_uninit, hw); 2560 + if (err) 2561 + return err; 2586 2562 2587 2563 hw->buff = devm_kzalloc(dev, ST_LSM6DSX_BUFF_SIZE, GFP_KERNEL); 2588 2564 if (!hw->buff)