All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org, Rob Herring <robh+dt@kernel.org>
Cc: Michael.Hennerich@analog.com, lars@metafoo.de,
	devicetree@vger.kernel.org, Nuno Sa <Nuno.Sa@analog.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: [PATCH 14/17] staging:iio:adc:ad7280a: Use device properties to replace platform data.
Date: Mon, 14 Jun 2021 12:35:04 +0100	[thread overview]
Message-ID: <20210614113507.897732-15-jic23@kernel.org> (raw)
In-Reply-To: <20210614113507.897732-1-jic23@kernel.org>

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Convert all the device specific info that was previously in platform data
over to generic firmware query interfaces.

dt-bindings to follow shortly.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/staging/iio/adc/ad7280a.c | 100 +++++++++++++++++++++++++-----
 drivers/staging/iio/adc/ad7280a.h |  31 ---------
 2 files changed, 86 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
index acaae1b33986..0806238debe3 100644
--- a/drivers/staging/iio/adc/ad7280a.c
+++ b/drivers/staging/iio/adc/ad7280a.c
@@ -23,8 +23,6 @@
 #include <linux/iio/events.h>
 #include <linux/iio/iio.h>
 
-#include "ad7280a.h"
-
 /* Registers */
 
 #define AD7280A_CELL_VOLTAGE_1_REG		0x0  /* D11 to D0, Read only */
@@ -81,6 +79,11 @@
 #define AD7280A_AUX_ADC_UNDERVOLTAGE_REG	0x12 /* D7 to D0, Read/write */
 
 #define AD7280A_ALERT_REG			0x13 /* D7 to D0, Read/write */
+#define   AD7280A_ALERT_REMOVE_MSK			GENMASK(3, 0)
+#define     AD7280A_ALERT_REMOVE_AUX5			BIT(0)
+#define     AD7280A_ALERT_REMOVE_AUX4_AUX5		BIT(1)
+#define     AD7280A_ALERT_REMOVE_VIN5			BIT(2)
+#define     AD7280A_ALERT_REMOVE_VIN4_VIN5		BIT(3)
 #define   AD7280A_ALERT_GEN_STATIC_HIGH			BIT(6)
 #define   AD7280A_ALERT_RELAY_SIG_CHAIN_DOWN		(BIT(7) | BIT(6))
 
@@ -163,6 +166,8 @@ static unsigned int ad7280a_devaddr(unsigned int addr)
 struct ad7280_state {
 	struct spi_device		*spi;
 	struct iio_chan_spec		*channels;
+	unsigned int			chain_last_alert_ignore;
+	bool				thermistor_term_en;
 	int				slave_num;
 	int				scan_cnt;
 	int				readback_delay_us;
@@ -932,14 +937,8 @@ static const struct iio_info ad7280_info_no_irq = {
 	.write_event_value = &ad7280a_write_thresh,
 };
 
-static const struct ad7280_platform_data ad7793_default_pdata = {
-	.acquisition_time = AD7280A_ACQ_TIME_400ns,
-	.thermistor_term_en = true,
-};
-
 static int ad7280_probe(struct spi_device *spi)
 {
-	const struct ad7280_platform_data *pdata = dev_get_platdata(&spi->dev);
 	struct device *dev = &spi->dev;
 	struct ad7280_state *st;
 	int ret;
@@ -954,17 +953,90 @@ static int ad7280_probe(struct spi_device *spi)
 	st->spi = spi;
 	mutex_init(&st->lock);
 
-	if (!pdata)
-		pdata = &ad7793_default_pdata;
+	st->thermistor_term_en =
+		device_property_read_bool(dev, "adi,thermistor-termination");
+
+	if (device_property_present(dev, "adi,acquistion-time-ns")) {
+		u32 val;
+
+		ret = device_property_read_u32(dev, "adi,acquisition-time-ns", &val);
+		if (ret)
+			return ret;
+
+		switch (val) {
+		case 400:
+			st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_400ns;
+			break;
+		case 800:
+			st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_800ns;
+			break;
+		case 1200:
+			st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_1200ns;
+			break;
+		case 1600:
+			st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_1600ns;
+			break;
+		default:
+			dev_err(dev, "Firmware provided acquisition time is invalid\n");
+			return -EINVAL;
+		}
+	} else {
+		st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_400ns;
+	}
+
+	/* Alert masks are intended for when particular inputs are not wired up */
+	if (device_property_present(dev, "adi,voltage-alert-last-chan")) {
+		u8 val;
 
+		ret = device_property_read_u8(dev, "adi,voltage-alert-last-chan", &val);
+		if (ret)
+			return ret;
+
+		switch (val) {
+		case 3:
+			st->chain_last_alert_ignore |= AD7280A_ALERT_REMOVE_VIN4_VIN5;
+			break;
+		case 4:
+			st->chain_last_alert_ignore |= AD7280A_ALERT_REMOVE_VIN5;
+			break;
+		case 5:
+			break;
+		default:
+			dev_err(dev,
+				"Firmware provided last voltage alert channel invalid\n");
+			break;
+		}
+	}
+	if (device_property_present(dev, "adi,temp-alert-last-chan")) {
+		u8 val;
+
+		ret = device_property_read_u8(dev, "adi,temp-alert-last-chan", &val);
+		if (ret)
+			return ret;
+
+		switch (val) {
+		case 3:
+			st->chain_last_alert_ignore |= AD7280A_ALERT_REMOVE_AUX4_AUX5;
+			break;
+		case 4:
+			st->chain_last_alert_ignore |= AD7280A_ALERT_REMOVE_AUX5;
+			break;
+		case 5:
+			break;
+		default:
+			dev_err(dev,
+				"Firmware provided last temp alert channel invalid\n");
+			break;
+		}
+	}
 	crc8_populate_msb(st->crc_tab, POLYNOM);
 
 	st->spi->max_speed_hz = AD7280A_MAX_SPI_CLK_HZ;
 	st->spi->mode = SPI_MODE_1;
 	spi_setup(st->spi);
 
-	st->ctrl_lb = FIELD_PREP(AD7280A_CTRL_LB_ACQ_TIME_MSK, pdata->acquisition_time) |
-		FIELD_PREP(AD7280A_CTRL_LB_THERMISTOR_MSK, pdata->thermistor_term_en);
+	st->ctrl_lb = FIELD_PREP(AD7280A_CTRL_LB_ACQ_TIME_MSK, st->acquisition_time) |
+		FIELD_PREP(AD7280A_CTRL_LB_THERMISTOR_MSK, st->thermistor_term_en);
 	st->oversampling_ratio = 0; /* No oversampling */
 
 	ret = ad7280_chain_setup(st);
@@ -975,7 +1047,6 @@ static int ad7280_probe(struct spi_device *spi)
 	st->scan_cnt = (st->slave_num + 1) * AD7280A_NUM_CH;
 	st->cell_threshhigh = 0xFF;
 	st->aux_threshhigh = 0xFF;
-	st->acquisition_time = pdata->acquisition_time;
 
 	ret = devm_add_action_or_reset(dev, ad7280_sw_power_down, st);
 	if (ret)
@@ -1002,7 +1073,8 @@ static int ad7280_probe(struct spi_device *spi)
 		ret = ad7280_write(st, ad7280a_devaddr(st->slave_num),
 				   AD7280A_ALERT_REG, 0,
 				   AD7280A_ALERT_GEN_STATIC_HIGH |
-				   (pdata->chain_last_alert_ignore & 0xF));
+				   FIELD_PREP(AD7280A_ALERT_REMOVE_MSK,
+					      st->chain_last_alert_ignore));
 		if (ret)
 			return ret;
 
diff --git a/drivers/staging/iio/adc/ad7280a.h b/drivers/staging/iio/adc/ad7280a.h
deleted file mode 100644
index 99297789a46d..000000000000
--- a/drivers/staging/iio/adc/ad7280a.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * AD7280A Lithium Ion Battery Monitoring System
- *
- * Copyright 2011 Analog Devices Inc.
- */
-
-#ifndef IIO_ADC_AD7280_H_
-#define IIO_ADC_AD7280_H_
-
-/*
- * TODO: struct ad7280_platform_data needs to go into include/linux/iio
- */
-
-#define AD7280A_ACQ_TIME_400ns			0
-#define AD7280A_ACQ_TIME_800ns			1
-#define AD7280A_ACQ_TIME_1200ns			2
-#define AD7280A_ACQ_TIME_1600ns			3
-
-#define AD7280A_ALERT_REMOVE_VIN5		BIT(2)
-#define AD7280A_ALERT_REMOVE_VIN4_VIN5		BIT(3)
-#define AD7280A_ALERT_REMOVE_AUX5		BIT(0)
-#define AD7280A_ALERT_REMOVE_AUX4_AUX5		BIT(1)
-
-struct ad7280_platform_data {
-	unsigned int		acquisition_time;
-	unsigned int		chain_last_alert_ignore;
-	bool			thermistor_term_en;
-};
-
-#endif /* IIO_ADC_AD7280_H_ */
-- 
2.32.0


  parent reply	other threads:[~2021-06-14 11:39 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-14 11:34 [PATCH 00/17] iio:adc:ad7280a Cleanup and proposed staging graduation Jonathan Cameron
2021-06-14 11:34 ` [PATCH 01/17] staging:iio:adc:ad7280a: Fix handing of device address bit reversing Jonathan Cameron
2021-06-14 11:34 ` [PATCH 02/17] staging:iio:adc:ad7280a: Register define cleanup Jonathan Cameron
2021-06-14 11:34 ` [PATCH 03/17] staging:iio:adc:ad7280a: rename _read() to _read_reg() Jonathan Cameron
2021-06-14 11:34 ` [PATCH 04/17] staging:iio:adc:ad7280a: Split buff[2] into tx and rx parts Jonathan Cameron
2021-06-14 11:34 ` [PATCH 05/17] staging:iio:adc:ad7280a: Use bitfield ops to managed fields in transfers Jonathan Cameron
2021-06-14 11:34 ` [PATCH 06/17] staging:iio:adc:ad7280a: Switch to standard event control Jonathan Cameron
2021-06-14 11:34 ` [PATCH 07/17] staging:iio:adc:ad7280a: Standardize extended ABI naming Jonathan Cameron
2021-06-14 11:34 ` [PATCH 08/17] staging:iio:adc:ad7280a: Drop unused timestamp channel Jonathan Cameron
2021-06-14 11:34 ` [PATCH 09/17] staging:iio:adc:ad7280a: Trivial comment formatting cleanup Jonathan Cameron
2021-06-14 11:35 ` [PATCH 10/17] staging:iio:adc:ad7280a: Make oversampling_ratio a runtime control Jonathan Cameron
2021-06-14 11:35 ` [PATCH 11/17] staging:iio:adc:ad7280a: Cleanup includes Jonathan Cameron
2021-06-14 11:35 ` [PATCH 12/17] staging:iio:ad7280a: Reflect optionality of irq in ABI Jonathan Cameron
2021-06-14 11:35 ` [PATCH 13/17] staging:iio:adc:ad7280a: Use a local dev pointer to avoid &spi->dev Jonathan Cameron
2021-06-14 11:35 ` Jonathan Cameron [this message]
2021-06-14 11:35 ` [PATCH 15/17] dt-bindings:iio:adc:ad7280a: Add binding Jonathan Cameron
2021-06-24 20:28   ` Rob Herring
2021-06-14 11:35 ` [PATCH 16/17] iio:adc:ad7280a: Document ABI for cell balance switches Jonathan Cameron
2021-06-14 11:35 ` [PATCH 17/17] iio:adc:ad7280a: Move out of staging Jonathan Cameron
2021-06-22 17:36 ` [PATCH 00/17] iio:adc:ad7280a Cleanup and proposed staging graduation Marcelo Schmitt
2021-06-23  8:37   ` Jonathan Cameron
2021-07-11 14:50     ` Jonathan Cameron
2021-07-12 18:08       ` Marcelo Schmitt
2021-08-05  3:52         ` Marcelo Schmitt
2021-08-05 12:51           ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210614113507.897732-15-jic23@kernel.org \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=Nuno.Sa@analog.com \
    --cc=devicetree@vger.kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --subject='Re: [PATCH 14/17] staging:iio:adc:ad7280a: Use device properties to replace platform data.' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.