AT91: Add a driver for the ADC
Subsystems (4)
PATCH v9 1/1 AT91: Add a driver for the ADC
Hi all,
The last version had a bug in the error handling of the probe function of the adc driver, the free_irq call having the wrong dev_id. This version corrects it.
PATCH 1/3 ARM: AT91: Add platform data for the ADCs
--- arch/arm/mach-at91/include/mach/board.h | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-)
arch/arm/mach-at91/include/mach/board.h +18 -0
@@ -207,4 +207,22 @@ extern void __init at91_pwm_leds(struct gpio_led *leds, int nr);/* FIXME: this needs a better location, but gets stuff building again */ extern int at91_suspend_entering_slow_clock (void ); +/* ADC */ +struct at91_adc_data { +/* ADC Clock as specified by the datasheet, in Hz. */ +unsigned int adc_clock; +/* +* Global number of channels available (to specify which channels are +* indeed used on the board, see the channels_used bitmask). +*/ +u8 num_channels; +/* Channels in use on the board as a bitmask */ +unsigned long channels_used; +/* Startup time of the ADC, in microseconds. */ +u8 startup_time; +/* Reference voltage for the ADC in millivolts */ +unsigned short vref; +}; +extern void __init at91_add_device_adc (struct at91_adc_data *data); +#endif
Signature · 1 line
1.7.4.1
PATCH 1/3 ARM: AT91: Add platform data for the ADCs
Quoted 7 lines · Maxime Ripard
Cc Nicolas Ferre <[email protected]>Cc Patrice Vilchez <[email protected]>Cc Thomas Petazzoni <[email protected]>Signed-off-by Maxime Ripard <[email protected]>Acked-by Jonathan Cameron <[email protected]>Signed-off-by Nicolas Ferre <[email protected]>
Best Regards,
J.
PATCH 2/3 ARM: AT91: IIO: Add AT91 ADC driver.
In reply to Maxime Ripard--- drivers/iio/adc/Kconfig | 6 + drivers/iio/adc/Makefile | 4 +- drivers/iio/adc/at91adc.c | 326 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 335 insertions(+), 1 deletions(-) create mode 100644 drivers/iio/adc/at91adc.c
drivers/iio/adc/Kconfig +6 -0
@@ -14,6 +14,12 @@ config IIO_AD799X i2c analog to digital convertors (ADC). Provides direct access via sysfs. +config IIO_AT91ADC + tristate "Atmel AT91 ADC" + depends on SYSFS && ARCH_AT91 + help + Say yes here to build support for Atmel AT91 ADC. + config IIO_MAX1363 tristate "Maxim max1363 ADC driver" depends on I2C
drivers/iio/adc/Makefile +3 -1
@@ -6,4 +6,6 @@ iio_ad799x-y := ad799x_core.o obj-$(CONFIG_IIO_AD799X) += iio_ad799x.o iio_max1363-y := max1363_core.o -obj-$(CONFIG_IIO_MAX1363) += iio_max1363.o +obj-$(CONFIG_IIO_MAX1363) += iio_max1363.o + +obj-$(CONFIG_IIO_AT91ADC) += at91adc.o
drivers/iio/adc/at91adc.c new file +326 -0
326 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 2/3 ARM: AT91: IIO: Add AT91 ADC driver.
Quoted 8 lines · Maxime Ripard
Cc Nicolas Ferre <[email protected]>Cc Patrice Vilchez <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Thomas Petazzoni <[email protected]>Signed-off-by Maxime Ripard <[email protected]>Acked-by Jonathan Cameron <[email protected]>Acked-by Nicolas Ferre <[email protected]>
Quoted 1 line
Reviewed-by Marek Vasut <[email protected]>
please remove Cc
Best Regards,
J.
PATCH 3/3 ARM: AT91: Add the ADC to the sam9g20ek board
In reply to Maxime Ripard--- arch/arm/mach-at91/at91sam9260_devices.c | 55 ++++++++++++++++++++++++++++++ arch/arm/mach-at91/board-sam9g20ek.c | 11 ++++++ 2 files changed, 66 insertions(+), 0 deletions(-)
arch/arm/mach-at91/at91sam9260_devices.c +55 -0
@@ -1312,6 +1312,61 @@ void __init at91_add_device_cf(struct at91_cf_data *data)void __init at91_add_device_cf (struct at91_cf_data * data) {}#endif +/* -------------------------------------------------------------------- +* ADCs +* -------------------------------------------------------------------- */ + +#if defined(CONFIG_IIO_AT91ADC ) || defined(CONFIG_IIO_AT91ADC_MODULE ) +static struct at91_adc_data adc_data; + +static struct resource adc_resources[] = { + [0 ] = { + .start =AT91SAM9260_BASE_ADC , + .end =AT91SAM9260_BASE_ADC +SZ_16K -1 , + .flags =IORESOURCE_MEM , + }, + [1 ] = { + .start =AT91SAM9260_ID_ADC , + .end =AT91SAM9260_ID_ADC , + .flags =IORESOURCE_IRQ , + }, +}; + +static struct platform_device at91_adc_device = { + .name ="at91adc" , + .id =-1 , + .dev = { + .platform_data = &adc_data, + }, + .resource = adc_resources, + .num_resources =ARRAY_SIZE (adc_resources), +}; + +void __init at91_add_device_adc (struct at91_adc_data *data) +{ +if (!data) +return ; + +if (test_bit (0 , &data->channels_used)) +at91_set_A_periph (AT91_PIN_PC0 ,0 ); +if (test_bit (1 , &data->channels_used)) +at91_set_A_periph (AT91_PIN_PC1 ,0 ); +if (test_bit (2 , &data->channels_used)) +at91_set_A_periph (AT91_PIN_PC2 ,0 ); +if (test_bit (3 , &data->channels_used)) +at91_set_A_periph (AT91_PIN_PC3 ,0 ); + + data->adc_clock =5000000 ; + data->num_channels =4 ; + data->startup_time =10 ; + + adc_data = *data; +platform_device_register (&at91_adc_device); +} +#else +void __init at91_add_device_adc (struct at91_adc_data *data) {} +#endif +/* -------------------------------------------------------------------- */ /* * These devices are always present and don't need any board-specific
arch/arm/mach-at91/board-sam9g20ek.c +11 -0
@@ -314,6 +314,15 @@ static void __init ek_add_device_buttons(void)static void __init ek_add_device_buttons (void ) {}#endif +/* +* ADCs +*/ + +static struct at91_adc_data ek_adc_data = { + .channels_used =BIT (0 ) |BIT (1 ) |BIT (2 ) |BIT (3 ), + .vref =3300 , +}; +#if defined(CONFIG_REGULATOR_FIXED_VOLTAGE ) || defined(CONFIG_REGULATOR_FIXED_VOLTAGE_MODULE )static struct regulator_consumer_supply ek_audio_consumer_supplies[] = { REGULATOR_SUPPLY("AVDD", "0-001b"),
@@ -389,6 +398,8 @@ static void __init ek_board_init(void)ek_add_device_gpio_leds ();/* Push Buttons */ ek_add_device_buttons (); +/* ADCs */ +at91_add_device_adc (&ek_adc_data);/* PCK0 provides MCLK to the WM8731 */ at91_set_B_periph (AT91_PIN_PC1 ,0 );/* SSC (for WM8731) */
Signature · 1 line
1.7.4.1
PATCH 3/3 ARM: AT91: Add the ADC to the sam9g20ek board
Quoted 6 lines · Maxime Ripard
Cc Nicolas Ferre <[email protected]>Cc Patrice Vilchez <[email protected]>Cc Thomas Petazzoni <[email protected]>Signed-off-by Maxime Ripard <[email protected]>Signed-off-by Nicolas Ferre <[email protected]>
please update and u get
no need to Cc if sob
ditto for all patch
Quoted 25 lines
--- arch/arm/mach-at91/at91sam9260_devices.c | 55 ++++++++++++++++++++++++++++++ arch/arm/mach-at91/board-sam9g20ek.c | 11 ++++++ 2 files changed, 66 insertions(+), 0 deletions(-)arch/arm/mach-at91/at91sam9260_devices.c +12
-0@@ -1312,6 +1312,61 @@ void __init at91_add_device_cf(struct at91_cf_data *data)void __init at91_add_device_cf (struct at91_cf_data * data) {}#endif +/* -------------------------------------------------------------------- +* ADCs +* -------------------------------------------------------------------- */ + +#if defined(CONFIG_IIO_AT91ADC) || defined(CONFIG_IIO_AT91ADC_MODULE) +static struct at91_adc_data adc_data; + +static struct resource adc_resources[] = { + [0] = { + .start = AT91SAM9260_BASE_ADC, + .end = AT91SAM9260_BASE_ADC + SZ_16K - 1, + .flags = IORESOURCE_MEM,
arch/arm/mach-at91/at91sam9260_devices.c void __init at91_add_device_cf(struct at91_cf_data *data) · line 1336
Quoted 10 lines
arch/arm/mach-at91/at91sam9260_devices.c +10
-0+ }, + [1 ] = { + .start =AT91SAM9260_ID_ADC , + .end =AT91SAM9260_ID_ADC , + .flags =IORESOURCE_IRQ , + }, +}; + +static struct platform_device at91_adc_device = { + .name ="at91adc" ,
at91_adc please
Quoted 13 lines
arch/arm/mach-at91/at91sam9260_devices.c +13
-0+ .id = -1, + .dev = { + .platform_data = &adc_data, + }, + .resource = adc_resources, + .num_resources = ARRAY_SIZE(adc_resources), +}; + +void __init at91_add_device_adc (struct at91_adc_data *data) +{ +if (!data) +return ; +
arch/arm/mach-at91/at91sam9260_devices.c void __init at91_add_device_cf(struct at91_cf_data *data) · line 1359
Quoted 10 lines
arch/arm/mach-at91/at91sam9260_devices.c +10
-0+if (test_bit (0 , &data->channels_used)) +at91_set_A_periph (AT91_PIN_PC0 ,0 ); +if (test_bit (1 , &data->channels_used)) +at91_set_A_periph (AT91_PIN_PC1 ,0 ); +if (test_bit (2 , &data->channels_used)) +at91_set_A_periph (AT91_PIN_PC2 ,0 ); +if (test_bit (3 , &data->channels_used)) +at91_set_A_periph (AT91_PIN_PC3 ,0 ); + + data->adc_clock =5000000 ;
please put a comment here for the clock
Quoted 18 lines
arch/arm/mach-at91/at91sam9260_devices.c +10
-0+ data->num_channels =4 ; + data->startup_time =10 ; + + adc_data = *data; + platform_device_register(&at91_adc_device); +} +#else +void __init at91_add_device_adc (struct at91_adc_data *data) {} +#endif +/* -------------------------------------------------------------------- */ /* * These devices are always present and don't need any board-specific arch/arm/mach-at91/board-sam9g20ek.c +0
-0
arch/arm/mach-at91/board-sam9g20ek.c static void __init ek_add_device_buttons(void) · line 315
Quoted 2 lines
arch/arm/mach-at91/board-sam9g20ek.c +0
-0@@ -314,6 +314,15 @@ static void __init ek_add_device_buttons(void)static void __init ek_add_device_buttons (void ) {}#endif
Best Regards,
J.
Quoted 30 lines
arch/arm/mach-at91/board-sam9g20ek.c +11
-0+/* +* ADCs +*/ + +static struct at91_adc_data ek_adc_data = { + .channels_used =BIT (0 ) |BIT (1 ) |BIT (2 ) |BIT (3 ), + .vref =3300 , +}; +#if defined(CONFIG_REGULATOR_FIXED_VOLTAGE ) || defined(CONFIG_REGULATOR_FIXED_VOLTAGE_MODULE )static struct regulator_consumer_supply ek_audio_consumer_supplies[] = { REGULATOR_SUPPLY("AVDD", "0-001b"),@@ -389,6 +398,8 @@ static void __init ek_board_init(void)ek_add_device_gpio_leds ();/* Push Buttons */ ek_add_device_buttons (); +/* ADCs */ +at91_add_device_adc (&ek_adc_data);/* PCK0 provides MCLK to the WM8731 */ at91_set_B_periph (AT91_PIN_PC1 ,0 );/* SSC (for WM8731) */ Signature · 7 lines
1.7.4.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 3/3 ARM: AT91: Add the ADC to the sam9g20ek board
In reply to Maxime Ripardarch/arm/mach-at91/board-sam9g20ek.c static void __init ek_add_device_buttons(void) · line 324
Quoted 4 lines · Maxime Ripard
arch/arm/mach-at91/board-sam9g20ek.c +4
-0+static struct at91_adc_data ek_adc_data = { + ? ? ? .channels_used = BIT(0) | BIT(1) | BIT(2) | BIT(3), + ? ? ? .vref = 3300, +};
Don't you need to also pass adc_clock?
Otherwise the probe code will fail:
+
+ if (!pdata->adc_clock) {
+ dev_err(&pdev->dev, "No ADCClock available.\n");
+ ret = -EINVAL;
+ goto error_free_clk;
+ }
PATCH 3/3 ARM: AT91: Add the ADC to the sam9g20ek board
Hi,
Quoted 9 lines · Fabio Estevam
arch/arm/mach-at91/board-sam9g20ek.c static void __init ek_add_device_buttons(void) · line 324
Quoted 4 lines · Maxime Ripard
arch/arm/mach-at91/board-sam9g20ek.c +4
-0+static struct at91_adc_data ek_adc_data = { + .channels_used =BIT (0 ) |BIT (1 ) |BIT (2 ) |BIT (3 ), + .vref =3300 , +};Don't you need to also pass
adc_clock?
ADC Clock is SoC specific, while these variables are board-specific. It is thus set in the file arch/arm/mach-at91/at91sam9260_devices.c, in the same patch.
Maxime
Signature · 4 lines
Maxime Ripard, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com