Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v1 1/2] iio: magnetometer: ak8975: Get rid of platform data
@ 2020-01-15 17:44 Andy Shevchenko
  2020-01-15 17:44 ` [PATCH v1 2/2] iio: magnetometer: ak8975: Convert to use device_get_match_data() Andy Shevchenko
  2020-01-18 11:38 ` [PATCH v1 1/2] iio: magnetometer: ak8975: Get rid of platform data Jonathan Cameron
  0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2020-01-15 17:44 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler
  Cc: Andy Shevchenko

Since IIO framework supports device property API and driver has been moved
already to the use of GPIO descriptors the logical continuation is to
get rid of platform data completely. We are on the safe side here since
there are no users of it in the kernel.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/magnetometer/ak8975.c       | 14 +++-----------
 include/linux/iio/magnetometer/ak8975.h | 15 ---------------
 2 files changed, 3 insertions(+), 26 deletions(-)
 delete mode 100644 include/linux/iio/magnetometer/ak8975.h

diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index 55cffaa82456..8e50e073bcbf 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -28,8 +28,6 @@
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
 
-#include <linux/iio/magnetometer/ak8975.h>
-
 /*
  * Register definitions, as well as various shifts and masks to get at the
  * individual fields of the registers.
@@ -857,8 +855,6 @@ static int ak8975_probe(struct i2c_client *client,
 	int err;
 	const char *name = NULL;
 	enum asahi_compass_chipset chipset = AK_MAX_TYPE;
-	const struct ak8975_platform_data *pdata =
-		dev_get_platdata(&client->dev);
 
 	/*
 	 * Grab and set up the supplied GPIO.
@@ -883,13 +879,9 @@ static int ak8975_probe(struct i2c_client *client,
 	data->eoc_gpiod = eoc_gpiod;
 	data->eoc_irq = 0;
 
-	if (!pdata) {
-		err = iio_read_mount_matrix(&client->dev, "mount-matrix",
-					    &data->orientation);
-		if (err)
-			return err;
-	} else
-		data->orientation = pdata->orientation;
+	err = iio_read_mount_matrix(&client->dev, "mount-matrix", &data->orientation);
+	if (err)
+		return err;
 
 	/* id will be NULL when enumerated via ACPI */
 	if (id) {
diff --git a/include/linux/iio/magnetometer/ak8975.h b/include/linux/iio/magnetometer/ak8975.h
deleted file mode 100644
index df3697183800..000000000000
--- a/include/linux/iio/magnetometer/ak8975.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef __IIO_MAGNETOMETER_AK8975_H__
-#define __IIO_MAGNETOMETER_AK8975_H__
-
-#include <linux/iio/iio.h>
-
-/**
- * struct ak8975_platform_data - AK8975 magnetometer driver platform data
- * @orientation: mounting matrix relative to main hardware
- */
-struct ak8975_platform_data {
-	struct iio_mount_matrix orientation;
-};
-
-#endif
-- 
2.24.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v1 2/2] iio: magnetometer: ak8975: Convert to use device_get_match_data()
  2020-01-15 17:44 [PATCH v1 1/2] iio: magnetometer: ak8975: Get rid of platform data Andy Shevchenko
@ 2020-01-15 17:44 ` Andy Shevchenko
  2020-01-18 11:41   ` Jonathan Cameron
  2020-01-18 11:38 ` [PATCH v1 1/2] iio: magnetometer: ak8975: Get rid of platform data Jonathan Cameron
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2020-01-15 17:44 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler
  Cc: Andy Shevchenko

Convert to use device_get_match_data() instead of open coded variant.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/magnetometer/ak8975.c | 39 +++++++++++++------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index 8e50e073bcbf..3c881541ae72 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -203,11 +203,11 @@ static long ak09912_raw_to_gauss(u16 data)
 
 /* Compatible Asahi Kasei Compass parts */
 enum asahi_compass_chipset {
+	AKXXXX		= 0,
 	AK8975,
 	AK8963,
 	AK09911,
 	AK09912,
-	AK_MAX_TYPE
 };
 
 enum ak_ctrl_reg_addr {
@@ -245,7 +245,7 @@ struct ak_def {
 	u8 data_regs[3];
 };
 
-static const struct ak_def ak_def_array[AK_MAX_TYPE] = {
+static const struct ak_def ak_def_array[] = {
 	{
 		.type = AK8975,
 		.raw_to_gauss = ak8975_raw_to_gauss,
@@ -781,19 +781,6 @@ static const struct acpi_device_id ak_acpi_match[] = {
 MODULE_DEVICE_TABLE(acpi, ak_acpi_match);
 #endif
 
-static const char *ak8975_match_acpi_device(struct device *dev,
-					    enum asahi_compass_chipset *chipset)
-{
-	const struct acpi_device_id *id;
-
-	id = acpi_match_device(dev->driver->acpi_match_table, dev);
-	if (!id)
-		return NULL;
-	*chipset = (int)id->driver_data;
-
-	return dev_name(dev);
-}
-
 static void ak8975_fill_buffer(struct iio_dev *indio_dev)
 {
 	struct ak8975_data *data = iio_priv(indio_dev);
@@ -852,9 +839,11 @@ static int ak8975_probe(struct i2c_client *client,
 	struct ak8975_data *data;
 	struct iio_dev *indio_dev;
 	struct gpio_desc *eoc_gpiod;
+	const void *match;
+	unsigned int i;
 	int err;
+	enum asahi_compass_chipset chipset;
 	const char *name = NULL;
-	enum asahi_compass_chipset chipset = AK_MAX_TYPE;
 
 	/*
 	 * Grab and set up the supplied GPIO.
@@ -884,23 +873,27 @@ static int ak8975_probe(struct i2c_client *client,
 		return err;
 
 	/* id will be NULL when enumerated via ACPI */
-	if (id) {
+	match = device_get_match_data(&client->dev);
+	if (match) {
+		chipset = (enum asahi_compass_chipset)(match);
+		name = dev_name(&client->dev);
+	} else if (id) {
 		chipset = (enum asahi_compass_chipset)(id->driver_data);
 		name = id->name;
-	} else if (ACPI_HANDLE(&client->dev)) {
-		name = ak8975_match_acpi_device(&client->dev, &chipset);
-		if (!name)
-			return -ENODEV;
 	} else
 		return -ENOSYS;
 
-	if (chipset >= AK_MAX_TYPE) {
+	for (i = 0; i < ARRAY_SIZE(ak_def_array); i++)
+		if (ak_def_array[i].type == chipset)
+			break;
+
+	if (i == ARRAY_SIZE(ak_def_array)) {
 		dev_err(&client->dev, "AKM device type unsupported: %d\n",
 			chipset);
 		return -ENODEV;
 	}
 
-	data->def = &ak_def_array[chipset];
+	data->def = &ak_def_array[i];
 
 	/* Fetch the regulators */
 	data->vdd = devm_regulator_get(&client->dev, "vdd");
-- 
2.24.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/2] iio: magnetometer: ak8975: Get rid of platform data
  2020-01-15 17:44 [PATCH v1 1/2] iio: magnetometer: ak8975: Get rid of platform data Andy Shevchenko
  2020-01-15 17:44 ` [PATCH v1 2/2] iio: magnetometer: ak8975: Convert to use device_get_match_data() Andy Shevchenko
@ 2020-01-18 11:38 ` Jonathan Cameron
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2020-01-18 11:38 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler

On Wed, 15 Jan 2020 19:44:24 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Since IIO framework supports device property API and driver has been moved
> already to the use of GPIO descriptors the logical continuation is to
> get rid of platform data completely. We are on the safe side here since
> there are no users of it in the kernel.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Hmm. Fair enough I guess.

Applied to the togreg branch of iio.git and pushed out as testing

Thanks,

Jonathan

> ---
>  drivers/iio/magnetometer/ak8975.c       | 14 +++-----------
>  include/linux/iio/magnetometer/ak8975.h | 15 ---------------
>  2 files changed, 3 insertions(+), 26 deletions(-)
>  delete mode 100644 include/linux/iio/magnetometer/ak8975.h
> 
> diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
> index 55cffaa82456..8e50e073bcbf 100644
> --- a/drivers/iio/magnetometer/ak8975.c
> +++ b/drivers/iio/magnetometer/ak8975.c
> @@ -28,8 +28,6 @@
>  #include <linux/iio/trigger_consumer.h>
>  #include <linux/iio/triggered_buffer.h>
>  
> -#include <linux/iio/magnetometer/ak8975.h>
> -
>  /*
>   * Register definitions, as well as various shifts and masks to get at the
>   * individual fields of the registers.
> @@ -857,8 +855,6 @@ static int ak8975_probe(struct i2c_client *client,
>  	int err;
>  	const char *name = NULL;
>  	enum asahi_compass_chipset chipset = AK_MAX_TYPE;
> -	const struct ak8975_platform_data *pdata =
> -		dev_get_platdata(&client->dev);
>  
>  	/*
>  	 * Grab and set up the supplied GPIO.
> @@ -883,13 +879,9 @@ static int ak8975_probe(struct i2c_client *client,
>  	data->eoc_gpiod = eoc_gpiod;
>  	data->eoc_irq = 0;
>  
> -	if (!pdata) {
> -		err = iio_read_mount_matrix(&client->dev, "mount-matrix",
> -					    &data->orientation);
> -		if (err)
> -			return err;
> -	} else
> -		data->orientation = pdata->orientation;
> +	err = iio_read_mount_matrix(&client->dev, "mount-matrix", &data->orientation);
> +	if (err)
> +		return err;
>  
>  	/* id will be NULL when enumerated via ACPI */
>  	if (id) {
> diff --git a/include/linux/iio/magnetometer/ak8975.h b/include/linux/iio/magnetometer/ak8975.h
> deleted file mode 100644
> index df3697183800..000000000000
> --- a/include/linux/iio/magnetometer/ak8975.h
> +++ /dev/null
> @@ -1,15 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef __IIO_MAGNETOMETER_AK8975_H__
> -#define __IIO_MAGNETOMETER_AK8975_H__
> -
> -#include <linux/iio/iio.h>
> -
> -/**
> - * struct ak8975_platform_data - AK8975 magnetometer driver platform data
> - * @orientation: mounting matrix relative to main hardware
> - */
> -struct ak8975_platform_data {
> -	struct iio_mount_matrix orientation;
> -};
> -
> -#endif


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 2/2] iio: magnetometer: ak8975: Convert to use device_get_match_data()
  2020-01-15 17:44 ` [PATCH v1 2/2] iio: magnetometer: ak8975: Convert to use device_get_match_data() Andy Shevchenko
@ 2020-01-18 11:41   ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2020-01-18 11:41 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler

On Wed, 15 Jan 2020 19:44:25 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Convert to use device_get_match_data() instead of open coded variant.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Looks good to me.

Applied to the togreg branch of iio.git and pushed out as testing.

Thanks,

Jonathan


> ---
>  drivers/iio/magnetometer/ak8975.c | 39 +++++++++++++------------------
>  1 file changed, 16 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
> index 8e50e073bcbf..3c881541ae72 100644
> --- a/drivers/iio/magnetometer/ak8975.c
> +++ b/drivers/iio/magnetometer/ak8975.c
> @@ -203,11 +203,11 @@ static long ak09912_raw_to_gauss(u16 data)
>  
>  /* Compatible Asahi Kasei Compass parts */
>  enum asahi_compass_chipset {
> +	AKXXXX		= 0,
>  	AK8975,
>  	AK8963,
>  	AK09911,
>  	AK09912,
> -	AK_MAX_TYPE
>  };
>  
>  enum ak_ctrl_reg_addr {
> @@ -245,7 +245,7 @@ struct ak_def {
>  	u8 data_regs[3];
>  };
>  
> -static const struct ak_def ak_def_array[AK_MAX_TYPE] = {
> +static const struct ak_def ak_def_array[] = {
>  	{
>  		.type = AK8975,
>  		.raw_to_gauss = ak8975_raw_to_gauss,
> @@ -781,19 +781,6 @@ static const struct acpi_device_id ak_acpi_match[] = {
>  MODULE_DEVICE_TABLE(acpi, ak_acpi_match);
>  #endif
>  
> -static const char *ak8975_match_acpi_device(struct device *dev,
> -					    enum asahi_compass_chipset *chipset)
> -{
> -	const struct acpi_device_id *id;
> -
> -	id = acpi_match_device(dev->driver->acpi_match_table, dev);
> -	if (!id)
> -		return NULL;
> -	*chipset = (int)id->driver_data;
> -
> -	return dev_name(dev);
> -}
> -
>  static void ak8975_fill_buffer(struct iio_dev *indio_dev)
>  {
>  	struct ak8975_data *data = iio_priv(indio_dev);
> @@ -852,9 +839,11 @@ static int ak8975_probe(struct i2c_client *client,
>  	struct ak8975_data *data;
>  	struct iio_dev *indio_dev;
>  	struct gpio_desc *eoc_gpiod;
> +	const void *match;
> +	unsigned int i;
>  	int err;
> +	enum asahi_compass_chipset chipset;
>  	const char *name = NULL;
> -	enum asahi_compass_chipset chipset = AK_MAX_TYPE;
>  
>  	/*
>  	 * Grab and set up the supplied GPIO.
> @@ -884,23 +873,27 @@ static int ak8975_probe(struct i2c_client *client,
>  		return err;
>  
>  	/* id will be NULL when enumerated via ACPI */
> -	if (id) {
> +	match = device_get_match_data(&client->dev);
> +	if (match) {
> +		chipset = (enum asahi_compass_chipset)(match);
> +		name = dev_name(&client->dev);
> +	} else if (id) {
>  		chipset = (enum asahi_compass_chipset)(id->driver_data);
>  		name = id->name;
> -	} else if (ACPI_HANDLE(&client->dev)) {
> -		name = ak8975_match_acpi_device(&client->dev, &chipset);
> -		if (!name)
> -			return -ENODEV;
>  	} else
>  		return -ENOSYS;
>  
> -	if (chipset >= AK_MAX_TYPE) {
> +	for (i = 0; i < ARRAY_SIZE(ak_def_array); i++)
> +		if (ak_def_array[i].type == chipset)
> +			break;
> +
> +	if (i == ARRAY_SIZE(ak_def_array)) {
>  		dev_err(&client->dev, "AKM device type unsupported: %d\n",
>  			chipset);
>  		return -ENODEV;
>  	}
>  
> -	data->def = &ak_def_array[chipset];
> +	data->def = &ak_def_array[i];
>  
>  	/* Fetch the regulators */
>  	data->vdd = devm_regulator_get(&client->dev, "vdd");


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15 17:44 [PATCH v1 1/2] iio: magnetometer: ak8975: Get rid of platform data Andy Shevchenko
2020-01-15 17:44 ` [PATCH v1 2/2] iio: magnetometer: ak8975: Convert to use device_get_match_data() Andy Shevchenko
2020-01-18 11:41   ` Jonathan Cameron
2020-01-18 11:38 ` [PATCH v1 1/2] iio: magnetometer: ak8975: Get rid of platform data Jonathan Cameron

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org
	public-inbox-index linux-iio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git