Skip to contentSkip to conversation

ACPI match adc128s052 to ADC on UP Squared

PATCH In review Javier Arteaga 3 participants 9 messages Apr 19, 2018 – Apr 24, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ACPI match adc128s052 to ADC on UP Squared

Hi all,

On AAEON's UP Squared board, there is an ADC124S101 enumerated via ACPI. This patchset enables ACPI matching by compatible string and by AAEON's allocated HID.

Dan O'Donovan (1):
iio: adc128s052: allow driver to be matched using ACPI

Nicola Lunghi (1):
iio: adc128s052: add ACPI _HID AANT1280

 drivers/iio/adc/ti-adc128s052.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/2 iio: adc128s052: allow driver to be matched using ACPI

From: Dan O'Donovan <[email protected]>

Allow driver to be matched by compatible string in ACPI device properties.

---
 drivers/iio/adc/ti-adc128s052.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ti-adc128s052.c +1 -1
index 7cf39b3e2416..56ec04d1c68f 100644
@@ -202,7 +202,7 @@ MODULE_DEVICE_TABLE(spi, adc128_id);
 static struct spi_driver adc128_driver = {
 	.driver = {
 		.name = "adc128s052",
-		.of_match_table = of_match_ptr(adc128_of_match),
+		.of_match_table = adc128_of_match,
 	},
 	.probe = adc128_probe,
 	.remove = adc128_remove,
Signature · 1 line
2.17.0
maintainer
#2 lore raw

Re: [PATCH 1/2] iio: adc128s052: allow driver to be matched using ACPI

Quoted 6 lines · On Thu, 19 Apr 2018 14:20:35 +0100 Javier Arteaga <[email protected]> wrote:

From: Dan O'Donovan <[email protected]>

Allow driver to be matched by compatible string in ACPI device properties.

Hi Javier,

I don't really see the connection between the change in here and what the description says...

If you are probing from ACPI then there is no need to ensure a valid of table is supplied (even if we aren't building with OF) which is what I think this patch is trying to do...

Jonathan

Quoted 17 lines
---
 drivers/iio/adc/ti-adc128s052.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ti-adc128s052.c +1 -1
index 7cf39b3e2416..56ec04d1c68f 100644
@@ -202,7 +202,7 @@ MODULE_DEVICE_TABLE(spi, adc128_id);
 static struct spi_driver adc128_driver = {
 	.driver = {
 		.name = "adc128s052",
-		.of_match_table = of_match_ptr(adc128_of_match),
+		.of_match_table = adc128_of_match,
 	},
 	.probe = adc128_probe,
 	.remove = adc128_remove,
#3 lore raw

Re: [PATCH 1/2] iio: adc128s052: allow driver to be matched using ACPI

Hi Jonathan,

Quoted 2 lines · Jonathan Cameron

I don't really see the connection between the change in here and what the description says...

I think you're right, we didn't make our intent clear here.

Quoted 3 lines

If you are probing from ACPI then there is no need to ensure a valid of table is supplied (even if we aren't building with OF) which is what I think this patch is trying to do...

The patch enables ACPI _DSD to reuse existing DT "compatible" strings, as described in Documentation/acpi/enumeration.txt, even without OF. This kind of patch has some precedent, like for example:

01427fe7c4b9 ("Input: adxl34x - make it enumerable in ACPI environment")

To clarify, for the UP2 board we don't actually need this patch as we have an ACPI _HID - just thought it would might be an improvement for others.

I'll improve the description and perhaps reorder this patch last for v2. Or I can send separately if you prefer.

Thanks for your review!

#4 lore raw

Re: [PATCH 1/2] iio: adc128s052: allow driver to be matched using ACPI

Quoted 18 lines · On Sat, 21 Apr 2018 21:41:57 +0100 Javier Arteaga <[email protected]> wrote:

Hi Jonathan,

Quoted 2 lines · Jonathan Cameron

I don't really see the connection between the change in here and what the description says...

I think you're right, we didn't make our intent clear here.

Quoted 3 lines

If you are probing from ACPI then there is no need to ensure a valid of table is supplied (even if we aren't building with OF) which is what I think this patch is trying to do...

The patch enables ACPI _DSD to reuse existing DT "compatible" strings, as described in Documentation/acpi/enumeration.txt, even without OF. This kind of patch has some precedent, like for example:

01427fe7c4b9 ("Input: adxl34x - make it enumerable in ACPI environment")

Quoted 8 lines

To clarify, for the UP2 board we don't actually need this patch as we have an ACPI _HID - just thought it would might be an improvement for others.

I'll improve the description and perhaps reorder this patch last for v2. Or I can send separately if you prefer.

Thanks for your review!

Unless we know of ACPI firmwares out there that are doing this, drop the patch for now. I don't want to see a flood of these based on a 'you can do it that' way argument.

Jonathan

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

Re: [PATCH 1/2] iio: adc128s052: allow driver to be matched using ACPI

Quoted 3 lines · Jonathan Cameron

Unless we know of ACPI firmwares out there that are doing this, drop the patch for now. I don't want to see a flood of these based on a 'you can do it that' way argument.

Fair enough. I'll drop it for v3.

#6 lore raw

PATCH 2/2 iio: adc128s052: add ACPI _HID AANT1280

In reply to Javier Arteaga

From: Nicola Lunghi <[email protected]>

ACPI _HID AANT1280 matches an ADC124S101 present on the UP Squared board that is compatible with adc128s052.

Add it to the driver.

[[email protected]: fix up commit message and one checkpatch warning]
---
 drivers/iio/adc/ti-adc128s052.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/iio/adc/ti-adc128s052.c +24 -1
index 56ec04d1c68f..917273f1268c 100644
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/iio/iio.h>
 #include <linux/regulator/consumer.h>
+#include <linux/acpi.h>
 
 struct adc128_configuration {
 	const struct iio_chan_spec	*channels;
@@ -136,9 +137,22 @@ static int adc128_probe(struct spi_device *spi)
 {
 	struct iio_dev *indio_dev;
 	struct adc128 *adc;
-	int config = spi_get_device_id(spi)->driver_data;
+	int config;
 	int ret;
 
+	if (ACPI_COMPANION(&spi->dev)) {
+		const struct acpi_device_id *ad_id;
+
+		ad_id = acpi_match_device(spi->dev.driver->acpi_match_table,
+					  &spi->dev);
+		if (!ad_id)
+			return -ENODEV;
+
+		config = ad_id->driver_data;
+	} else {
+		config = spi_get_device_id(spi)->driver_data;
+	}
+
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc));
 	if (!indio_dev)
 		return -ENOMEM;
@@ -199,10 +213,19 @@ 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", 2 }, /* ADC124S021 compatible ACPI ID */
+	{ }
+};
+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),
 	},
 	.probe = adc128_probe,
 	.remove = adc128_remove,
Signature · 1 line
2.17.0
maintainer
#7 lore raw

Re: [PATCH 2/2] iio: adc128s052: add ACPI _HID AANT1280

Quoted 10 lines · On Thu, 19 Apr 2018 14:20:36 +0100 Javier Arteaga <[email protected]> wrote:

From: Nicola Lunghi <[email protected]>

ACPI _HID AANT1280 matches an ADC124S101 present on the UP Squared board that is compatible with adc128s052.

Add it to the driver.

[[email protected]: fix up commit message and one checkpatch warning]

Hi Javier,

This is in principle fine, but I'd like to see it done somewhat more explicitly.

1) Add the adc124s101 and similar families to the driver first. I think this is just a case of IDs for all of
adc124s051 and adc124s101.

2) Add the ACPI ID as you have done here.

That way we at least reflect clearly that the part is supported rather than just in a comment on the ACPI ID.

Hmm. Looking at it, we should perhaps revisit whether some of these TI parts are similar enough that their drivers can be cleanly combined. A job for another day!

Jonathan

Quoted 60 lines
---
 drivers/iio/adc/ti-adc128s052.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/iio/adc/ti-adc128s052.c +24 -1
index 56ec04d1c68f..917273f1268c 100644
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/iio/iio.h>
 #include <linux/regulator/consumer.h>
+#include <linux/acpi.h>
 
 struct adc128_configuration {
 	const struct iio_chan_spec	*channels;
@@ -136,9 +137,22 @@ static int adc128_probe(struct spi_device *spi)
 {
 	struct iio_dev *indio_dev;
 	struct adc128 *adc;
-	int config = spi_get_device_id(spi)->driver_data;
+	int config;
 	int ret;
 
+	if (ACPI_COMPANION(&spi->dev)) {
+		const struct acpi_device_id *ad_id;
+
+		ad_id = acpi_match_device(spi->dev.driver->acpi_match_table,
+					  &spi->dev);
+		if (!ad_id)
+			return -ENODEV;
+
+		config = ad_id->driver_data;
+	} else {
+		config = spi_get_device_id(spi)->driver_data;
+	}
+
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc));
 	if (!indio_dev)
 		return -ENOMEM;
@@ -199,10 +213,19 @@ 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", 2 }, /* ADC124S021 compatible ACPI ID */
+	{ }
+};
+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),
 	},
 	.probe = adc128_probe,
 	.remove = adc128_remove,
#8 lore raw

Re: [PATCH 2/2] iio: adc128s052: add ACPI _HID AANT1280

Hi Jonathan,

Quoted 11 lines · Jonathan Cameron

This is in principle fine, but I'd like to see it done somewhat more explicitly.

1) Add the adc124s101 and similar families to the driver first. I think this is just a case of IDs for all of
adc124s051 and adc124s101.

2) Add the ACPI ID as you have done here.

That way we at least reflect clearly that the part is supported rather than just in a comment on the ACPI ID.

Will do for v2.

Thank you!