iio:magnetometer:ak8975: power regulator support

Add support for an optional regulator which, if found into device-tree,
will power on device at probing time.
The regulator is declared into ak8975 DTS entry as a "vdd-supply" property.

Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
Gregor Boirie 2016-03-03 11:44:05 +01:00 коммит произвёл Jonathan Cameron
Родитель d3546af67f
Коммит 63d5d525cb
2 изменённых файлов: 18 добавлений и 0 удалений

Просмотреть файл

@ -8,6 +8,7 @@ Required properties:
Optional properties: Optional properties:
- gpios : should be device tree identifier of the magnetometer DRDY pin - gpios : should be device tree identifier of the magnetometer DRDY pin
- vdd-supply: an optional regulator that needs to be on to provide VDD
Example: Example:
@ -15,4 +16,5 @@ ak8975@0c {
compatible = "asahi-kasei,ak8975"; compatible = "asahi-kasei,ak8975";
reg = <0x0c>; reg = <0x0c>;
gpios = <&gpj0 7 0>; gpios = <&gpj0 7 0>;
vdd-supply = <&ldo_3v3_gnss>;
}; };

Просмотреть файл

@ -32,6 +32,7 @@
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/regulator/consumer.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
@ -379,8 +380,23 @@ static int ak8975_who_i_am(struct i2c_client *client,
enum asahi_compass_chipset type) enum asahi_compass_chipset type)
{ {
u8 wia_val[2]; u8 wia_val[2];
struct regulator *vdd = devm_regulator_get_optional(&client->dev,
"vdd");
int ret; int ret;
/* Enable attached regulator if any. */
if (!IS_ERR(vdd)) {
ret = regulator_enable(vdd);
if (ret) {
dev_err(&client->dev, "Failed to enable Vdd supply\n");
return ret;
}
} else {
ret = PTR_ERR(vdd);
if (ret != -ENODEV)
return ret;
}
/* /*
* Signature for each device: * Signature for each device:
* Device | WIA1 | WIA2 * Device | WIA1 | WIA2