From: Gregor Boirie Date: Thu, 3 Mar 2016 10:44:05 +0000 (+0100) Subject: iio:magnetometer:ak8975: power regulator support X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=63d5d525cbbc8938d9fa3d6d6fbd4183e784b6e9;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git 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 Signed-off-by: Jonathan Cameron --- diff --git a/Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt b/Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt index 011679f1a425..34a3206eefdf 100644 --- a/Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt +++ b/Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt @@ -8,6 +8,7 @@ Required properties: Optional properties: - 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: @@ -15,4 +16,5 @@ ak8975@0c { compatible = "asahi-kasei,ak8975"; reg = <0x0c>; gpios = <&gpj0 7 0>; + vdd-supply = <&ldo_3v3_gnss>; }; diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index 896b13e39dae..72c03d9fbeb2 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -379,8 +380,23 @@ static int ak8975_who_i_am(struct i2c_client *client, enum asahi_compass_chipset type) { u8 wia_val[2]; + struct regulator *vdd = devm_regulator_get_optional(&client->dev, + "vdd"); 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: * Device | WIA1 | WIA2