IIO AD7923 iio_consumer support
Subsystems (2)
PATCH 1/1 IIO AD7923 iio_consumer support
This patch adds support for iio_consumer to Analog Devices AD7923 ADC driver.
drivers/iio/adc/ad7923.c +39 -2
@@ -19,11 +19,15 @@#include <linux/interrupt.h> #include <linux/iio/iio.h> +#include <linux/iio/driver.h> +#include <linux/iio/machine.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> #include <linux/iio/trigger_consumer.h> #include <linux/iio/triggered_buffer.h> +#define AD7923_NAME "ad7923" +#define AD7923_WRITE_CR (1 << 11)/* write control register */ #define AD7923_RANGE (1 << 1)/* range to REFin */ #define AD7923_CODING (1 << 0)/* coding is straight binary */
@@ -96,6 +100,7 @@ .storagebits = 16, \ .endianness = IIO_BE, \ }, \ + .datasheet_name = #index, \ }#define DECLARE_AD7923_CHANNELS (name, bits) \
@@ -195,6 +200,31 @@return IRQ_HANDLED ; } +/* default maps used by iio consumer */ +static struct iio_map ad7923_default_iio_maps[] = { + { + .consumer_dev_name =AD7923_NAME , + .consumer_channel ="channel_0" , + .adc_channel_label ="0" , + }, + { + .consumer_dev_name =AD7923_NAME , + .consumer_channel ="channel_1" , + .adc_channel_label ="1" , + }, + { + .consumer_dev_name =AD7923_NAME , + .consumer_channel ="channel_2" , + .adc_channel_label ="2" , + }, + { + .consumer_dev_name =AD7923_NAME , + .consumer_channel ="channel_3" , + .adc_channel_label ="3" , + }, + { } +}; +static int ad7923_scan_direct (struct ad7923_state *st,unsigned ch) {int ret, cmd;
@@ -325,12 +355,18 @@if (ret) goto error_disable_reg; - ret =iio_device_register (indio_dev); + ret =iio_map_array_register (indio_dev, ad7923_default_iio_maps);if (ret) goto error_cleanup_ring; + ret =iio_device_register (indio_dev); +if (ret) + goto error_unmap; +return 0 ; +error_unmap: +iio_map_array_unregister (indio_dev); error_cleanup_ring:iio_triggered_buffer_cleanup (indio_dev); error_disable_reg:
@@ -349,6 +385,7 @@struct ad7923_state *st =iio_priv (indio_dev);iio_device_unregister (indio_dev); +iio_map_array_unregister (indio_dev);iio_triggered_buffer_cleanup (indio_dev);regulator_disable (st->reg);regulator_put (st->reg);
@@ -368,7 +405,7 @@static struct spi_driver ad7923_driver = { .driver = { - .name ="ad7923" , + .name =AD7923_NAME , .owner =THIS_MODULE , }, .probe = ad7923_probe,
Quoted 9 lines · Christophe Leroy
This patch adds support for
iio_consumerto Analog Devices AD7923 ADC driver.Signed-off-by Christophe Leroy <[email protected]>Verified-by Patrick Vasseur <[email protected]>diff -urN
a/drivers/iio/adc/ad7923.cb/drivers/iio/adc/ad7923.c
drivers/iio/adc/ad7923.c line 23
Quoted 5 lines
drivers/iio/adc/ad7923.c +2
-0@@ -19,11 +19,15 @@#include <linux/interrupt.h> #include <linux/iio/iio.h> +#include <linux/iio/driver.h> +#include <linux/iio/machine.h>
The fact that you need to include machine.h here should ring some alarm bells. machine.h is meant to be included by machine or board drivers, not by device drivers.
Quoted 11 lines
drivers/iio/adc/ad7923.c +2
-0#include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> #include <linux/iio/trigger_consumer.h> #include <linux/iio/triggered_buffer.h> +#define AD7923_NAME "ad7923" +#define AD7923_WRITE_CR (1 << 11)/* write control register */ #define AD7923_RANGE (1 << 1)/* range to REFin */ #define AD7923_CODING (1 << 0)/* coding is straight binary */
drivers/iio/adc/ad7923.c line 103
Quoted 4 lines
drivers/iio/adc/ad7923.c +1
-0@@ -96,6 +100,7 @@ .storagebits = 16, \ .endianness = IIO_BE, \ }, \ + .datasheet_name = #index, \
The names for the pins in the datasheet are VINx
drivers/iio/adc/ad7923.c line 206
Quoted 11 lines
drivers/iio/adc/ad7923.c +4
-0}#define DECLARE_AD7923_CHANNELS (name, bits) \@@ -195,6 +200,31 @@return IRQ_HANDLED ; } +/* default maps used by iio consumer */ +static struct iio_map ad7923_default_iio_maps[] = { + { + .consumer_dev_name =AD7923_NAME ,
The consumer_dev_name field is the dev_name() of the device that is going to consume data from the channel. This device provides data on the channel.
Quoted 10 lines
drivers/iio/adc/ad7923.c +10
-0+ .consumer_channel = "channel_0", + .adc_channel_label = "0", + }, + { + .consumer_dev_name = AD7923_NAME, + .consumer_channel = "channel_1", + .adc_channel_label = "1", + }, + { + .consumer_dev_name = AD7923_NAME,
drivers/iio/adc/ad7923.c line 226
Quoted 10 lines
drivers/iio/adc/ad7923.c +10
-0+ .consumer_channel = "channel_2", + .adc_channel_label = "2", + }, + { + .consumer_dev_name = AD7923_NAME, + .consumer_channel = "channel_3", + .adc_channel_label = "3", + }, + { } +};
This is a mapping between channel names of the provider between the channel names of the consumer. So it is specific to a certain combination of consumer and provider and usually depend on how things are physically wired on your board. As such there can be no generic mapping and this needs to go into your machine/board driver. The mapping is usually passed to the IIO driver via its platform data.
So e.g. imagine you have a provider like this driver and you have a consumer that has a "voltage" channel. And on your board channel 3 of the ADC is what you want to route to that consumer. Then your mapping would look like this:
{
.consumer_dev_name = "your_consumer_device.1", .consumer_channel = "voltage", .adc_channel_label = "AIN3",
}
And in your consumer driver you'd do:
channel = iio_channel_get(dev, "voltage");
- Lars
Quoted 38 lines · Lars-Peter Clausen
Quoted 10 lines · Christophe Leroy
drivers/iio/adc/ad7923.c +10
-0+ .consumer_channel = "channel_0", + .adc_channel_label = "0", + }, + { + .consumer_dev_name = AD7923_NAME, + .consumer_channel = "channel_1", + .adc_channel_label = "1", + }, + { + .consumer_dev_name = AD7923_NAME,drivers/iio/adc/ad7923.c line 226
Quoted 10 lines
drivers/iio/adc/ad7923.c +10
-0+ .consumer_channel = "channel_2", + .adc_channel_label = "2", + }, + { + .consumer_dev_name = AD7923_NAME, + .consumer_channel = "channel_3", + .adc_channel_label = "3", + }, + { } +};This is a mapping between channel names of the provider between the channel names of the consumer. So it is specific to a certain combination of consumer and provider and usually depend on how things are physically wired on your board. As such there can be no generic mapping and this needs to go into your machine/board driver. The mapping is usually passed to the IIO driver via its platform data.
So e.g. imagine you have a provider like this driver and you have a consumer that has a "voltage" channel. And on your board channel 3 of the ADC is what you want to route to that consumer. Then your mapping would look like this:
{
.consumer_dev_name = "your_consumer_device.1", .consumer_channel = "voltage", .adc_channel_label = "AIN3",
}
Quoted 5 lines
And in your consumer driver you'd do:
channel =
iio_channel_get(dev, "voltage");
Thanks for the explanation.
Can the mapping be retrieved via of_platform ?
Indeed, the only exemple I found was in the lp8788_adc driver, which includes iio/machine.h and declares a default mapping, but it is based on platform_data, not of_platform.
Christophe
Quoted 45 lines · leroy christophe
Quoted 38 lines · Lars-Peter Clausen
Quoted 10 lines · Christophe Leroy
drivers/iio/adc/ad7923.c +10
-0+ .consumer_channel = "channel_0", + .adc_channel_label = "0", + }, + { + .consumer_dev_name = AD7923_NAME, + .consumer_channel = "channel_1", + .adc_channel_label = "1", + }, + { + .consumer_dev_name = AD7923_NAME,drivers/iio/adc/ad7923.c line 226
Quoted 10 lines
drivers/iio/adc/ad7923.c +10
-0+ .consumer_channel = "channel_2", + .adc_channel_label = "2", + }, + { + .consumer_dev_name = AD7923_NAME, + .consumer_channel = "channel_3", + .adc_channel_label = "3", + }, + { } +};This is a mapping between channel names of the provider between the channel names of the consumer. So it is specific to a certain combination of consumer and provider and usually depend on how things are physically wired on your board. As such there can be no generic mapping and this needs to go into your machine/board driver. The mapping is usually passed to the IIO driver via its platform data.
So e.g. imagine you have a provider like this driver and you have a consumer that has a "voltage" channel. And on your board channel 3 of the ADC is what you want to route to that consumer. Then your mapping would look like this:
{
.consumer_dev_name = "your_consumer_device.1", .consumer_channel = "voltage", .adc_channel_label = "AIN3",
}Quoted 5 lines
And in your consumer driver you'd do:
channel =
iio_channel_get(dev, "voltage");
Quoted 8 lines
Thanks for the explanation.
Can the mapping be retrieved via
of_platform?Indeed, the only exemple I found was in the
lp8788_adcdriver, which includesiio/machine.hand declares a default mapping, but it is based onplatform_data, notof_platform.
If you are using device tree you can specify the mapping inside the devicetree. Have a look at Documentation/devicetree/bindings/iio/iio-bindings.txt
- Lars
Quoted 49 lines · Lars-Peter Clausen
Quoted 48 lines · leroy christophe
Quoted 38 lines · Lars-Peter Clausen
Quoted 10 lines · Christophe Leroy
drivers/iio/adc/ad7923.c +10
-0+ .consumer_channel = "channel_0", + .adc_channel_label = "0", + }, + { + .consumer_dev_name = AD7923_NAME, + .consumer_channel = "channel_1", + .adc_channel_label = "1", + }, + { + .consumer_dev_name = AD7923_NAME,drivers/iio/adc/ad7923.c line 226
Quoted 10 lines
drivers/iio/adc/ad7923.c +10
-0+ .consumer_channel = "channel_2", + .adc_channel_label = "2", + }, + { + .consumer_dev_name = AD7923_NAME, + .consumer_channel = "channel_3", + .adc_channel_label = "3", + }, + { } +};This is a mapping between channel names of the provider between the channel names of the consumer. So it is specific to a certain combination of consumer and provider and usually depend on how things are physically wired on your board. As such there can be no generic mapping and this needs to go into your machine/board driver. The mapping is usually passed to the IIO driver via its platform data.
So e.g. imagine you have a provider like this driver and you have a consumer that has a "voltage" channel. And on your board channel 3 of the ADC is what you want to route to that consumer. Then your mapping would look like this:
{
.consumer_dev_name = "your_consumer_device.1", .consumer_channel = "voltage", .adc_channel_label = "AIN3",
}Quoted 5 lines
And in your consumer driver you'd do:
channel =
iio_channel_get(dev, "voltage");Thanks for the explanation.
Can the mapping be retrieved via
of_platform?
Quoted 9 lines
Quoted 4 lines
Indeed, the only exemple I found was in the
lp8788_adcdriver, which includesiio/machine.hand declares a default mapping, but it is based onplatform_data, notof_platform.If you are using device tree you can specify the mapping inside the devicetree. Have a look at
Documentation/devicetree/bindings/iio/iio-bindings.txt
Yes, I saw that. Is there anything that shall be done in the driver to support it, or is it automatic ?
Christophe
Quoted 57 lines · leroy christophe
Quoted 55 lines · Lars-Peter Clausen
Quoted 54 lines · leroy christophe
Quoted 40 lines · Lars-Peter Clausen
Quoted 10 lines · Christophe Leroy
drivers/iio/adc/ad7923.c +10
-0+ .consumer_channel = "channel_0", + .adc_channel_label = "0", + }, + { + .consumer_dev_name = AD7923_NAME, + .consumer_channel = "channel_1", + .adc_channel_label = "1", + }, + { + .consumer_dev_name = AD7923_NAME,drivers/iio/adc/ad7923.c line 226
Quoted 10 lines
drivers/iio/adc/ad7923.c +10
-0+ .consumer_channel = "channel_2", + .adc_channel_label = "2", + }, + { + .consumer_dev_name = AD7923_NAME, + .consumer_channel = "channel_3", + .adc_channel_label = "3", + }, + { } +};This is a mapping between channel names of the provider between the channel names of the consumer. So it is specific to a certain combination of consumer and provider and usually depend on how things are physically wired on your board. As such there can be no generic mapping and this needs to go into your machine/board driver. The mapping is usually passed to the IIO driver via its platform data.
So e.g. imagine you have a provider like this driver and you have a consumer
that has a "voltage" channel. And on your board channel 3 of the ADC is what
you want to route to that consumer. Then your mapping would look like this:{
.consumer_dev_name = "your_consumer_device.1", .consumer_channel = "voltage", .adc_channel_label = "AIN3",
}Quoted 5 lines
And in your consumer driver you'd do:
channel =
iio_channel_get(dev, "voltage");Thanks for the explanation.
Can the mapping be retrieved via
of_platform?Indeed, the only exemple I found was in the
lp8788_adcdriver, which includesiio/machine.hand declares a default mapping, but it is based onplatform_data, notof_platform.
Quoted 7 lines
Quoted 5 lines
If you are using device tree you can specify the mapping inside the devicetree. Have a look at
Documentation/devicetree/bindings/iio/iio-bindings.txtYes, I saw that. Is there anything that shall be done in the driver to support it, or is it automatic ?
It should work out of the box. Just make sure to set the #io-channel-cells property for the ADC device node in the devicetree.
- Lars