iio: adc: ti-adc128s052: Some refactorings
Subsystems (2)
v2 cover iio: adc: ti-adc128s052: Some refactorings
Refactor driver to use newest API and drop ACPI_PTR() which is rather useless.
Changelog v2:
- united two previously sent series into a single one
- dropped for now the endianess patch
- fixed compilation issues (Jonathan, LKP)
Andy Shevchenko (3):
iio: adc: ti-adc128s052: Switch to use spi_get_device_match_data()
iio: adc: ti-adc128s052: Drop anti-pattern of ACPI_PTR() use
iio: adc: ti-adc128s052: Sort headers
drivers/iio/adc/ti-adc128s052.c | 54 +++++++++++++++------------------ 1 file changed, 24 insertions(+), 30 deletions(-)
Signature · 1 line
2.35.1
PATCH v2 1/3 iio: adc: ti-adc128s052: Switch to use spi_get_device_match_data()
The spi_get_device_match_data() helps to get driver data from the firmware node or SPI ID table. Use it instead of open coding.
While at it, switch ID tables to provide an acrual pointers to the configuration data.
--- drivers/iio/adc/ti-adc128s052.c | 43 +++++++++++++++------------------ 1 file changed, 20 insertions(+), 23 deletions(-)
drivers/iio/adc/ti-adc128s052.c +20 -23
@@ -139,16 +139,11 @@ static void adc128_disable_regulator(void *reg)static int adc128_probe (struct spi_device *spi) { +const struct adc128_configuration *config;struct iio_dev *indio_dev; -unsigned int config;struct adc128 *adc;int ret; -if (dev_fwnode (&spi->dev)) - config = (unsigned long )device_get_match_data (&spi->dev); -else - config =spi_get_device_id (spi)->driver_data; - indio_dev =devm_iio_device_alloc (&spi->dev,sizeof (*adc));if (!indio_dev)return -ENOMEM ;
@@ -160,8 +155,10 @@ static int adc128_probe(struct spi_device *spi) indio_dev->modes =INDIO_DIRECT_MODE ; indio_dev->info = &adc128_info; - indio_dev->channels = adc128_config[config].channels; - indio_dev->num_channels = adc128_config[config].num_channels; + config =spi_get_device_match_data (spi); + + indio_dev->channels = config->channels; + indio_dev->num_channels = config->num_channels; adc->reg =devm_regulator_get (&spi->dev,"vref" );if (IS_ERR (adc->reg))
@@ -181,32 +178,32 @@ static int adc128_probe(struct spi_device *spi) }static const struct of_device_id adc128_of_match[] = { - { .compatible ="ti,adc128s052" , .data = (void *)0L , }, - { .compatible ="ti,adc122s021" , .data = (void *)1L , }, - { .compatible ="ti,adc122s051" , .data = (void *)1L , }, - { .compatible ="ti,adc122s101" , .data = (void *)1L , }, - { .compatible ="ti,adc124s021" , .data = (void *)2L , }, - { .compatible ="ti,adc124s051" , .data = (void *)2L , }, - { .compatible ="ti,adc124s101" , .data = (void *)2L , }, + { .compatible ="ti,adc128s052" , .data = &adc128_config[0 ] }, + { .compatible ="ti,adc122s021" , .data = &adc128_config[1 ] }, + { .compatible ="ti,adc122s051" , .data = &adc128_config[1 ] }, + { .compatible ="ti,adc122s101" , .data = &adc128_config[1 ] }, + { .compatible ="ti,adc124s021" , .data = &adc128_config[2 ] }, + { .compatible ="ti,adc124s051" , .data = &adc128_config[2 ] }, + { .compatible ="ti,adc124s101" , .data = &adc128_config[2 ] }, {/* sentinel */ }, };MODULE_DEVICE_TABLE (of, adc128_of_match);static const struct spi_device_id adc128_id[] = { - {"adc128s052" ,0 },/* index into adc128_config */ - {"adc122s021" ,1 }, - {"adc122s051" ,1 }, - {"adc122s101" ,1 }, - {"adc124s021" ,2 }, - {"adc124s051" ,2 }, - {"adc124s101" ,2 }, + {"adc128s052" , (kernel_ulong_t)&adc128_config[0 ] }, + {"adc122s021" , (kernel_ulong_t)&adc128_config[1 ] }, + {"adc122s051" , (kernel_ulong_t)&adc128_config[1 ] }, + {"adc122s101" , (kernel_ulong_t)&adc128_config[1 ] }, + {"adc124s021" , (kernel_ulong_t)&adc128_config[2 ] }, + {"adc124s051" , (kernel_ulong_t)&adc128_config[2 ] }, + {"adc124s101" , (kernel_ulong_t)&adc128_config[2 ] }, { } };MODULE_DEVICE_TABLE (spi, adc128_id);#ifdef CONFIG_ACPI static const struct acpi_device_id adc128_acpi_match[] = { - {"AANT1280" ,2 },/* ADC124S021 compatible ACPI ID */ + {"AANT1280" , (kernel_ulong_t)&adc128_config[2 ] }, { } };MODULE_DEVICE_TABLE (acpi, adc128_acpi_match);
Signature · 1 line
2.35.1
PATCH v2 2/3 iio: adc: ti-adc128s052: Drop anti-pattern of ACPI_PTR() use
In reply to Andy ShevchenkoACPI_PTR() is more harmful than helpful. For example, in this case if CONFIG_ACPI=n, the ID table left unused and code is obfuscated by ifdeffery.
Drop anti-pattern of ACPI_PTR() use.
--- drivers/iio/adc/ti-adc128s052.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/iio/adc/ti-adc128s052.c +1 -4
@@ -9,7 +9,6 @@* https://www.ti.com/lit/ds/symlink/adc124s021.pdf */ -#include <linux/acpi.h> #include <linux/err.h> #include <linux/spi/spi.h> #include <linux/module.h>
@@ -201,19 +200,17 @@ static const struct spi_device_id adc128_id[] = { };MODULE_DEVICE_TABLE (spi, adc128_id); -#ifdef CONFIG_ACPI static const struct acpi_device_id adc128_acpi_match[] = { {"AANT1280" , (kernel_ulong_t)&adc128_config[2 ] }, { } };MODULE_DEVICE_TABLE (acpi, adc128_acpi_match); -#endif static struct spi_driver adc128_driver = { .driver = { .name ="adc128s052" , .of_match_table = adc128_of_match, - .acpi_match_table =ACPI_PTR (adc128_acpi_match), + .acpi_match_table = adc128_acpi_match, }, .probe = adc128_probe, .id_table = adc128_id,
Signature · 1 line
2.35.1
PATCH v2 3/3 iio: adc: ti-adc128s052: Sort headers
In reply to Andy ShevchenkoSort the headers in alphabetic order in order to ease the maintenance for this part.
--- drivers/iio/adc/ti-adc128s052.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/adc/ti-adc128s052.c +3 -3
@@ -10,12 +10,12 @@*/ #include <linux/err.h> -#include <linux/spi/spi.h> -#include <linux/module.h> -#include <linux/mod_devicetable.h> #include <linux/iio/iio.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> #include <linux/property.h> #include <linux/regulator/consumer.h> +#include <linux/spi/spi.h> struct adc128_configuration {const struct iio_chan_spec *channels;
Signature · 1 line
2.35.1
Quoted 2 lines · On Mon, 2 Jan 2023 19:34:47 +0200 Andy Shevchenko…
Refactor driver to use newest API and drop
ACPI_PTR()which is rather useless.
Applied.
Thanks,
Jonathan
Quoted 14 lines
Changelog v2:
- united two previously sent series into a single one
- dropped for now the endianess patch
- fixed compilation issues (Jonathan, LKP)Andy Shevchenko (3):
iio: adc: ti-adc128s052: Switch to usespi_get_device_match_data()
iio: adc: ti-adc128s052: Drop anti-pattern ofACPI_PTR()use
iio: adc: ti-adc128s052: Sort headersdrivers/iio/adc/ti-adc128s052.c | 54 +++++++++++++++------------------ 1 file changed, 24 insertions(+), 30 deletions(-)