Skip to content

Commit

Permalink
drivers: adc: sam: Convert to DT_INST defines
Browse files Browse the repository at this point in the history
Convert driver to use DT_INST_ defines.

see zephyrproject-rtos#23107

Signed-off-by: Gerson Fernando Budke <[email protected]>
  • Loading branch information
nandojve committed Mar 7, 2020
1 parent 834dc24 commit 1bec98a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 80 deletions.
87 changes: 32 additions & 55 deletions drivers/adc/adc_sam_afec.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,60 +347,37 @@ static void adc_sam_isr(void *arg)
}
}

#ifdef CONFIG_ADC_0
static void adc0_sam_cfg_func(struct device *dev);

static const struct adc_sam_cfg adc0_sam_cfg = {
.regs = (Afec *)DT_ADC_0_BASE_ADDRESS,
.cfg_func = adc0_sam_cfg_func,
.periph_id = DT_ADC_0_PERIPHERAL_ID,
.afec_trg_pin = PIN_AFE0_ADTRG,
};

static struct adc_sam_data adc0_sam_data = {
ADC_CONTEXT_INIT_TIMER(adc0_sam_data, ctx),
ADC_CONTEXT_INIT_LOCK(adc0_sam_data, ctx),
ADC_CONTEXT_INIT_SYNC(adc0_sam_data, ctx),
};

DEVICE_AND_API_INIT(adc0_sam, DT_ADC_0_NAME, adc_sam_init,
&adc0_sam_data, &adc0_sam_cfg, POST_KERNEL,
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &adc_sam_api);

static void adc0_sam_cfg_func(struct device *dev)
{
IRQ_CONNECT(DT_ADC_0_IRQ, DT_ADC_0_IRQ_PRI, adc_sam_isr,
DEVICE_GET(adc0_sam), 0);
irq_enable(DT_ADC_0_IRQ);
}

#endif /* CONFIG_ADC_0 */

#ifdef CONFIG_ADC_1
static void adc1_sam_cfg_func(struct device *dev);

static const struct adc_sam_cfg adc1_sam_cfg = {
.regs = (Afec *)DT_ADC_1_BASE_ADDRESS,
.cfg_func = adc1_sam_cfg_func,
.periph_id = DT_ADC_1_PERIPHERAL_ID,
.afec_trg_pin = PIN_AFE1_ADTRG,
};

static struct adc_sam_data adc1_sam_data = {
ADC_CONTEXT_INIT_TIMER(adc1_sam_data, ctx),
ADC_CONTEXT_INIT_LOCK(adc1_sam_data, ctx),
ADC_CONTEXT_INIT_SYNC(adc1_sam_data, ctx),
};

DEVICE_AND_API_INIT(adc1_sam, DT_ADC_1_NAME, adc_sam_init,
&adc1_sam_data, &adc1_sam_cfg, POST_KERNEL,
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &adc_sam_api);
#define ADC_SAM_DEVICE(n) \
static void adc_sam_config_func_##n(struct device *dev); \
static const struct adc_sam_cfg adc_sam_cfg_##n = { \
.regs = (Afec *)DT_INST_##n##_ATMEL_SAM_AFEC_BASE_ADDRESS, \
.cfg_func = adc_sam_config_func_##n, \
.periph_id = DT_INST_##n##_ATMEL_SAM_AFEC_PERIPHERAL_ID, \
.afec_trg_pin = PIN_AFE1_ADTRG, \
}; \
static struct adc_sam_data adc_sam_data_##n = { \
ADC_CONTEXT_INIT_TIMER(adc_sam_data_##n, ctx), \
ADC_CONTEXT_INIT_LOCK(adc_sam_data_##n, ctx), \
ADC_CONTEXT_INIT_SYNC(adc_sam_data_##n, ctx), \
}; \
DEVICE_AND_API_INIT(adc_sam_##n, DT_INST_##n##_ATMEL_SAM_AFEC_LABEL, \
adc_sam_init, &adc_sam_data_##n, &adc_sam_cfg_##n,\
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
&adc_sam_api); \
static void adc_sam_config_func_##n(struct device *dev) \
{ \
IRQ_CONNECT(DT_INST_##n##_ATMEL_SAM_AFEC_IRQ_0, \
DT_INST_##n##_ATMEL_SAM_AFEC_IRQ_0_PRIORITY, \
adc_sam_isr, \
DEVICE_GET(adc_sam_##n), \
0); \
irq_enable(DT_INST_##n##_ATMEL_SAM_AFEC_IRQ_0); \
}

static void adc1_sam_cfg_func(struct device *dev)
{
IRQ_CONNECT(DT_ADC_1_IRQ, DT_ADC_1_IRQ_PRI, adc_sam_isr,
DEVICE_GET(adc1_sam), 0);
irq_enable(DT_ADC_1_IRQ);
}
#if DT_INST_0_ATMEL_SAM_AFEC
ADC_SAM_DEVICE(0);
#endif

#endif /* CONFIG_ADC_1 */
#if DT_INST_1_ATMEL_SAM_AFEC
ADC_SAM_DEVICE(1);
#endif
12 changes: 0 additions & 12 deletions soc/arm/atmel_sam/same70/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,6 @@
#define DT_USART_SAM_PORT_2_IRQ_PRIO DT_ATMEL_SAM_USART_4002C000_IRQ_0_PRIORITY
#define DT_USART_SAM_PORT_2_PERIPHERAL_ID DT_ATMEL_SAM_USART_4002C000_PERIPHERAL_ID

#define DT_ADC_0_BASE_ADDRESS DT_ATMEL_SAM_AFEC_4003C000_BASE_ADDRESS
#define DT_ADC_0_IRQ DT_ATMEL_SAM_AFEC_4003C000_IRQ_0
#define DT_ADC_0_IRQ_PRI DT_ATMEL_SAM_AFEC_4003C000_IRQ_0_PRIORITY
#define DT_ADC_0_NAME DT_ATMEL_SAM_AFEC_4003C000_LABEL
#define DT_ADC_0_PERIPHERAL_ID DT_ATMEL_SAM_AFEC_4003C000_PERIPHERAL_ID

#define DT_ADC_1_BASE_ADDRESS DT_ATMEL_SAM_AFEC_40064000_BASE_ADDRESS
#define DT_ADC_1_IRQ DT_ATMEL_SAM_AFEC_40064000_IRQ_0
#define DT_ADC_1_IRQ_PRI DT_ATMEL_SAM_AFEC_40064000_IRQ_0_PRIORITY
#define DT_ADC_1_NAME DT_ATMEL_SAM_AFEC_40064000_LABEL
#define DT_ADC_1_PERIPHERAL_ID DT_ATMEL_SAM_AFEC_40064000_PERIPHERAL_ID

#define DT_USBHS_IRQ DT_ATMEL_SAM_USBHS_40038000_IRQ_0
#define DT_USBHS_IRQ_PRI DT_ATMEL_SAM_USBHS_40038000_IRQ_0_PRIORITY
#define DT_USBHS_MAXIMUM_SPEED DT_ATMEL_SAM_USBHS_40038000_MAXIMUM_SPEED
Expand Down
12 changes: 0 additions & 12 deletions soc/arm/atmel_sam/samv71/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,6 @@
#define DT_USART_SAM_PORT_2_IRQ_PRIO DT_ATMEL_SAM_USART_4002C000_IRQ_0_PRIORITY
#define DT_USART_SAM_PORT_2_PERIPHERAL_ID DT_ATMEL_SAM_USART_4002C000_PERIPHERAL_ID

#define DT_ADC_0_BASE_ADDRESS DT_ATMEL_SAM_AFEC_4003C000_BASE_ADDRESS
#define DT_ADC_0_IRQ DT_ATMEL_SAM_AFEC_4003C000_IRQ_0
#define DT_ADC_0_IRQ_PRI DT_ATMEL_SAM_AFEC_4003C000_IRQ_0_PRIORITY
#define DT_ADC_0_NAME DT_ATMEL_SAM_AFEC_4003C000_LABEL
#define DT_ADC_0_PERIPHERAL_ID DT_ATMEL_SAM_AFEC_4003C000_PERIPHERAL_ID

#define DT_ADC_1_BASE_ADDRESS DT_ATMEL_SAM_AFEC_40064000_BASE_ADDRESS
#define DT_ADC_1_IRQ DT_ATMEL_SAM_AFEC_40064000_IRQ_0
#define DT_ADC_1_IRQ_PRI DT_ATMEL_SAM_AFEC_40064000_IRQ_0_PRIORITY
#define DT_ADC_1_NAME DT_ATMEL_SAM_AFEC_40064000_LABEL
#define DT_ADC_1_PERIPHERAL_ID DT_ATMEL_SAM_AFEC_40064000_PERIPHERAL_ID

#define DT_USBHS_IRQ DT_ATMEL_SAM_USBHS_40038000_IRQ_0
#define DT_USBHS_IRQ_PRI DT_ATMEL_SAM_USBHS_40038000_IRQ_0_PRIORITY
#define DT_USBHS_MAXIMUM_SPEED DT_ATMEL_SAM_USBHS_40038000_MAXIMUM_SPEED
Expand Down
2 changes: 1 addition & 1 deletion tests/drivers/adc/adc_api/src/test_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
#elif defined(CONFIG_BOARD_SAM_E70_XPLAINED) || \
defined(CONFIG_BOARD_SAM_V71_XULT)

#define ADC_DEVICE_NAME DT_ADC_0_NAME
#define ADC_DEVICE_NAME DT_INST_0_ATMEL_SAM_AFEC_LABEL
#define ADC_RESOLUTION 12
#define ADC_GAIN ADC_GAIN_1
#define ADC_REFERENCE ADC_REF_EXTERNAL0
Expand Down

0 comments on commit 1bec98a

Please sign in to comment.