diff mbox series

[4/7,v4] hwmon: ab8500: convert to IIO ADC

Message ID 20191011071805.5554-5-linus.walleij@linaro.org (mailing list archive)
State New, archived
Headers show
Series AB8500 GPADC MFD to IIO conversion | expand

Commit Message

Linus Walleij Oct. 11, 2019, 7:18 a.m. UTC
This switches the AB8500 hardware monitor driver to using
the standard IIO ADC channel lookup and conversion routines.

Acked-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v3->v4:
- No changes just resending
ChangeLog v2->v3:
- Depend on (IIO = y) since we are bool and need it compiled
  in.
- Rebased on v5.4-rc1
ChangeLog v1->v2:
- Collected ACKs.
- Rebased on v5.3-rc5
- Add a Kconfig dependency on IIO
- Fix some whitespace issues

This should not be applied to the hwmon tree right now, it
will be applied along with the other changes in ARM SoC.
---
 drivers/hwmon/Kconfig  |  3 +-
 drivers/hwmon/ab8500.c | 65 ++++++++++++++++++++++++++----------------
 2 files changed, 43 insertions(+), 25 deletions(-)

Comments

Guenter Roeck Oct. 11, 2019, 1:13 p.m. UTC | #1
On 10/11/19 12:18 AM, Linus Walleij wrote:
> This switches the AB8500 hardware monitor driver to using
> the standard IIO ADC channel lookup and conversion routines.
> 
> Acked-by: Guenter Roeck <linux@roeck-us.net>
> Acked-by: Jonathan Cameron <jic23@kernel.org>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> ChangeLog v3->v4:
> - No changes just resending
> ChangeLog v2->v3:
> - Depend on (IIO = y) since we are bool and need it compiled
>    in.
> - Rebased on v5.4-rc1
> ChangeLog v1->v2:
> - Collected ACKs.
> - Rebased on v5.3-rc5
> - Add a Kconfig dependency on IIO
> - Fix some whitespace issues
> 
> This should not be applied to the hwmon tree right now, it
> will be applied along with the other changes in ARM SoC.

I assume this is still true ?

Guenter

> ---
>   drivers/hwmon/Kconfig  |  3 +-
>   drivers/hwmon/ab8500.c | 65 ++++++++++++++++++++++++++----------------
>   2 files changed, 43 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 13a6b4afb4b3..5308c59d7001 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -40,7 +40,8 @@ comment "Native drivers"
>   
>   config SENSORS_AB8500
>   	tristate "AB8500 thermal monitoring"
> -	depends on AB8500_GPADC && AB8500_BM
> +	depends on AB8500_GPADC && AB8500_BM && (IIO = y)
> +	default n
>   	help
>   	  If you say yes here you get support for the thermal sensor part
>   	  of the AB8500 chip. The driver includes thermal management for
> diff --git a/drivers/hwmon/ab8500.c b/drivers/hwmon/ab8500.c
> index 207f77f85a40..53f3379d799d 100644
> --- a/drivers/hwmon/ab8500.c
> +++ b/drivers/hwmon/ab8500.c
> @@ -17,20 +17,24 @@
>   #include <linux/hwmon-sysfs.h>
>   #include <linux/mfd/abx500.h>
>   #include <linux/mfd/abx500/ab8500-bm.h>
> -#include <linux/mfd/abx500/ab8500-gpadc.h>
>   #include <linux/module.h>
>   #include <linux/platform_device.h>
>   #include <linux/power/ab8500.h>
>   #include <linux/reboot.h>
>   #include <linux/slab.h>
>   #include <linux/sysfs.h>
> +#include <linux/iio/consumer.h>
>   #include "abx500.h"
>   
>   #define DEFAULT_POWER_OFF_DELAY	(HZ * 10)
>   #define THERMAL_VCC		1800
>   #define PULL_UP_RESISTOR	47000
> -/* Number of monitored sensors should not greater than NUM_SENSORS */
> -#define NUM_MONITORED_SENSORS	4
> +
> +#define AB8500_SENSOR_AUX1		0
> +#define AB8500_SENSOR_AUX2		1
> +#define AB8500_SENSOR_BTEMP_BALL	2
> +#define AB8500_SENSOR_BAT_CTRL		3
> +#define NUM_MONITORED_SENSORS		4
>   
>   struct ab8500_gpadc_cfg {
>   	const struct abx500_res_to_temp *temp_tbl;
> @@ -40,7 +44,8 @@ struct ab8500_gpadc_cfg {
>   };
>   
>   struct ab8500_temp {
> -	struct ab8500_gpadc *gpadc;
> +	struct iio_channel *aux1;
> +	struct iio_channel *aux2;
>   	struct ab8500_btemp *btemp;
>   	struct delayed_work power_off_work;
>   	struct ab8500_gpadc_cfg cfg;
> @@ -82,15 +87,21 @@ static int ab8500_read_sensor(struct abx500_temp *data, u8 sensor, int *temp)
>   	int voltage, ret;
>   	struct ab8500_temp *ab8500_data = data->plat_data;
>   
> -	if (sensor == BAT_CTRL) {
> -		*temp = ab8500_btemp_get_batctrl_temp(ab8500_data->btemp);
> -	} else if (sensor == BTEMP_BALL) {
> +	if (sensor == AB8500_SENSOR_BTEMP_BALL) {
>   		*temp = ab8500_btemp_get_temp(ab8500_data->btemp);
> -	} else {
> -		voltage = ab8500_gpadc_convert(ab8500_data->gpadc, sensor);
> -		if (voltage < 0)
> -			return voltage;
> -
> +	} else if (sensor == AB8500_SENSOR_BAT_CTRL) {
> +		*temp = ab8500_btemp_get_batctrl_temp(ab8500_data->btemp);
> +	} else if (sensor == AB8500_SENSOR_AUX1) {
> +		ret = iio_read_channel_processed(ab8500_data->aux1, &voltage);
> +		if (ret < 0)
> +			return ret;
> +		ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp);
> +		if (ret < 0)
> +			return ret;
> +	} else if (sensor == AB8500_SENSOR_AUX2) {
> +		ret = iio_read_channel_processed(ab8500_data->aux2, &voltage);
> +		if (ret < 0)
> +			return ret;
>   		ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp);
>   		if (ret < 0)
>   			return ret;
> @@ -164,10 +175,6 @@ int abx500_hwmon_init(struct abx500_temp *data)
>   	if (!ab8500_data)
>   		return -ENOMEM;
>   
> -	ab8500_data->gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
> -	if (IS_ERR(ab8500_data->gpadc))
> -		return PTR_ERR(ab8500_data->gpadc);
> -
>   	ab8500_data->btemp = ab8500_btemp_get();
>   	if (IS_ERR(ab8500_data->btemp))
>   		return PTR_ERR(ab8500_data->btemp);
> @@ -181,15 +188,25 @@ int abx500_hwmon_init(struct abx500_temp *data)
>   	ab8500_data->cfg.tbl_sz = ab8500_temp_tbl_a_size;
>   
>   	data->plat_data = ab8500_data;
> +	ab8500_data->aux1 = devm_iio_channel_get(&data->pdev->dev, "aux1");
> +	if (IS_ERR(ab8500_data->aux1)) {
> +		if (PTR_ERR(ab8500_data->aux1) == -ENODEV)
> +			return -EPROBE_DEFER;
> +		dev_err(&data->pdev->dev, "failed to get AUX1 ADC channel\n");
> +		return PTR_ERR(ab8500_data->aux1);
> +	}
> +	ab8500_data->aux2 = devm_iio_channel_get(&data->pdev->dev, "aux2");
> +	if (IS_ERR(ab8500_data->aux2)) {
> +		if (PTR_ERR(ab8500_data->aux2) == -ENODEV)
> +			return -EPROBE_DEFER;
> +		dev_err(&data->pdev->dev, "failed to get AUX2 ADC channel\n");
> +		return PTR_ERR(ab8500_data->aux2);
> +	}
>   
> -	/*
> -	 * ADC_AUX1 and ADC_AUX2, connected to external NTC
> -	 * BTEMP_BALL and BAT_CTRL, fixed usage
> -	 */
> -	data->gpadc_addr[0] = ADC_AUX1;
> -	data->gpadc_addr[1] = ADC_AUX2;
> -	data->gpadc_addr[2] = BTEMP_BALL;
> -	data->gpadc_addr[3] = BAT_CTRL;
> +	data->gpadc_addr[0] = AB8500_SENSOR_AUX1;
> +	data->gpadc_addr[1] = AB8500_SENSOR_AUX2;
> +	data->gpadc_addr[2] = AB8500_SENSOR_BTEMP_BALL;
> +	data->gpadc_addr[3] = AB8500_SENSOR_BAT_CTRL;
>   	data->monitored_sensors = NUM_MONITORED_SENSORS;
>   
>   	data->ops.read_sensor = ab8500_read_sensor;
>
Linus Walleij Oct. 11, 2019, 8:48 p.m. UTC | #2
On Fri, Oct 11, 2019 at 3:13 PM Guenter Roeck <linux@roeck-us.net> wrote:
> On 10/11/19 12:18 AM, Linus Walleij wrote:

> > This should not be applied to the hwmon tree right now, it
> > will be applied along with the other changes in ARM SoC.
>
> I assume this is still true ?

Yeah the plan is to merge all patches through the IIO tree.

Thanks,
Linus Walleij
Jonathan Cameron Oct. 17, 2019, 9:08 p.m. UTC | #3
On Fri, 11 Oct 2019 22:48:24 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:

> On Fri, Oct 11, 2019 at 3:13 PM Guenter Roeck <linux@roeck-us.net> wrote:
> > On 10/11/19 12:18 AM, Linus Walleij wrote:  
> 
> > > This should not be applied to the hwmon tree right now, it
> > > will be applied along with the other changes in ARM SoC.  
> >
> > I assume this is still true ?  
> 
> Yeah the plan is to merge all patches through the IIO tree.

Immutable branch created based on 5.4-rc1 at:
https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/log/?h=ib-ab8500-5.4-rc1

This is an overly fiddly set to actually build so Linus if you could
do a quick sanity check that would be great.  Even better if you could
take a look at relaxing some of the build constraints so this
gets some decent build coverage from the various autobuilders.

I plan on pulling this into my togreg branch in a few minutes, which will
then be pushed out as testing for the autobuilders to maybe figure out
how to build this.

Thanks,

Jonathan

> 
> Thanks,
> Linus Walleij
diff mbox series

Patch

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 13a6b4afb4b3..5308c59d7001 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -40,7 +40,8 @@  comment "Native drivers"
 
 config SENSORS_AB8500
 	tristate "AB8500 thermal monitoring"
-	depends on AB8500_GPADC && AB8500_BM
+	depends on AB8500_GPADC && AB8500_BM && (IIO = y)
+	default n
 	help
 	  If you say yes here you get support for the thermal sensor part
 	  of the AB8500 chip. The driver includes thermal management for
diff --git a/drivers/hwmon/ab8500.c b/drivers/hwmon/ab8500.c
index 207f77f85a40..53f3379d799d 100644
--- a/drivers/hwmon/ab8500.c
+++ b/drivers/hwmon/ab8500.c
@@ -17,20 +17,24 @@ 
 #include <linux/hwmon-sysfs.h>
 #include <linux/mfd/abx500.h>
 #include <linux/mfd/abx500/ab8500-bm.h>
-#include <linux/mfd/abx500/ab8500-gpadc.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/power/ab8500.h>
 #include <linux/reboot.h>
 #include <linux/slab.h>
 #include <linux/sysfs.h>
+#include <linux/iio/consumer.h>
 #include "abx500.h"
 
 #define DEFAULT_POWER_OFF_DELAY	(HZ * 10)
 #define THERMAL_VCC		1800
 #define PULL_UP_RESISTOR	47000
-/* Number of monitored sensors should not greater than NUM_SENSORS */
-#define NUM_MONITORED_SENSORS	4
+
+#define AB8500_SENSOR_AUX1		0
+#define AB8500_SENSOR_AUX2		1
+#define AB8500_SENSOR_BTEMP_BALL	2
+#define AB8500_SENSOR_BAT_CTRL		3
+#define NUM_MONITORED_SENSORS		4
 
 struct ab8500_gpadc_cfg {
 	const struct abx500_res_to_temp *temp_tbl;
@@ -40,7 +44,8 @@  struct ab8500_gpadc_cfg {
 };
 
 struct ab8500_temp {
-	struct ab8500_gpadc *gpadc;
+	struct iio_channel *aux1;
+	struct iio_channel *aux2;
 	struct ab8500_btemp *btemp;
 	struct delayed_work power_off_work;
 	struct ab8500_gpadc_cfg cfg;
@@ -82,15 +87,21 @@  static int ab8500_read_sensor(struct abx500_temp *data, u8 sensor, int *temp)
 	int voltage, ret;
 	struct ab8500_temp *ab8500_data = data->plat_data;
 
-	if (sensor == BAT_CTRL) {
-		*temp = ab8500_btemp_get_batctrl_temp(ab8500_data->btemp);
-	} else if (sensor == BTEMP_BALL) {
+	if (sensor == AB8500_SENSOR_BTEMP_BALL) {
 		*temp = ab8500_btemp_get_temp(ab8500_data->btemp);
-	} else {
-		voltage = ab8500_gpadc_convert(ab8500_data->gpadc, sensor);
-		if (voltage < 0)
-			return voltage;
-
+	} else if (sensor == AB8500_SENSOR_BAT_CTRL) {
+		*temp = ab8500_btemp_get_batctrl_temp(ab8500_data->btemp);
+	} else if (sensor == AB8500_SENSOR_AUX1) {
+		ret = iio_read_channel_processed(ab8500_data->aux1, &voltage);
+		if (ret < 0)
+			return ret;
+		ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp);
+		if (ret < 0)
+			return ret;
+	} else if (sensor == AB8500_SENSOR_AUX2) {
+		ret = iio_read_channel_processed(ab8500_data->aux2, &voltage);
+		if (ret < 0)
+			return ret;
 		ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp);
 		if (ret < 0)
 			return ret;
@@ -164,10 +175,6 @@  int abx500_hwmon_init(struct abx500_temp *data)
 	if (!ab8500_data)
 		return -ENOMEM;
 
-	ab8500_data->gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
-	if (IS_ERR(ab8500_data->gpadc))
-		return PTR_ERR(ab8500_data->gpadc);
-
 	ab8500_data->btemp = ab8500_btemp_get();
 	if (IS_ERR(ab8500_data->btemp))
 		return PTR_ERR(ab8500_data->btemp);
@@ -181,15 +188,25 @@  int abx500_hwmon_init(struct abx500_temp *data)
 	ab8500_data->cfg.tbl_sz = ab8500_temp_tbl_a_size;
 
 	data->plat_data = ab8500_data;
+	ab8500_data->aux1 = devm_iio_channel_get(&data->pdev->dev, "aux1");
+	if (IS_ERR(ab8500_data->aux1)) {
+		if (PTR_ERR(ab8500_data->aux1) == -ENODEV)
+			return -EPROBE_DEFER;
+		dev_err(&data->pdev->dev, "failed to get AUX1 ADC channel\n");
+		return PTR_ERR(ab8500_data->aux1);
+	}
+	ab8500_data->aux2 = devm_iio_channel_get(&data->pdev->dev, "aux2");
+	if (IS_ERR(ab8500_data->aux2)) {
+		if (PTR_ERR(ab8500_data->aux2) == -ENODEV)
+			return -EPROBE_DEFER;
+		dev_err(&data->pdev->dev, "failed to get AUX2 ADC channel\n");
+		return PTR_ERR(ab8500_data->aux2);
+	}
 
-	/*
-	 * ADC_AUX1 and ADC_AUX2, connected to external NTC
-	 * BTEMP_BALL and BAT_CTRL, fixed usage
-	 */
-	data->gpadc_addr[0] = ADC_AUX1;
-	data->gpadc_addr[1] = ADC_AUX2;
-	data->gpadc_addr[2] = BTEMP_BALL;
-	data->gpadc_addr[3] = BAT_CTRL;
+	data->gpadc_addr[0] = AB8500_SENSOR_AUX1;
+	data->gpadc_addr[1] = AB8500_SENSOR_AUX2;
+	data->gpadc_addr[2] = AB8500_SENSOR_BTEMP_BALL;
+	data->gpadc_addr[3] = AB8500_SENSOR_BAT_CTRL;
 	data->monitored_sensors = NUM_MONITORED_SENSORS;
 
 	data->ops.read_sensor = ab8500_read_sensor;