drivers: counter: sam0_tc32: rework devicetree support
Rework the devicetree to utilize new DT_INST macros and extract per instance data for clocks from devicetree. Move the prescaler setting from Kconfig to devicetree as well. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
fe573b6e23
commit
8eafcc32db
4 changed files with 66 additions and 108 deletions
|
@ -1,26 +1,10 @@
|
||||||
# Copyright (c) 2019 Derek Hageman <hageman@inthat.cloud>
|
# Copyright (c) 2019 Derek Hageman <hageman@inthat.cloud>
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
menuconfig COUNTER_SAM0_TC32
|
config COUNTER_SAM0_TC32
|
||||||
bool "SAM0 series 32-bit basic timer driver"
|
bool "SAM0 series 32-bit basic timer driver"
|
||||||
default y
|
default y
|
||||||
depends on SOC_FAMILY_SAM0
|
depends on SOC_FAMILY_SAM0
|
||||||
help
|
help
|
||||||
Enable the SAM0 series timer counter (TC) driver in 32-bit wide
|
Enable the SAM0 series timer counter (TC) driver in 32-bit wide
|
||||||
mode.
|
mode.
|
||||||
|
|
||||||
if COUNTER_SAM0_TC32
|
|
||||||
|
|
||||||
index = 0
|
|
||||||
source "drivers/counter/Kconfig.template.sam0_tc32"
|
|
||||||
|
|
||||||
index = 2
|
|
||||||
source "drivers/counter/Kconfig.template.sam0_tc32"
|
|
||||||
|
|
||||||
index = 4
|
|
||||||
source "drivers/counter/Kconfig.template.sam0_tc32"
|
|
||||||
|
|
||||||
index = 6
|
|
||||||
source "drivers/counter/Kconfig.template.sam0_tc32"
|
|
||||||
|
|
||||||
endif # COUNTER_SAM0_TC32
|
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
# Copyright (c) 2019 Derek Hageman <hageman@inthat.cloud>
|
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
choice
|
|
||||||
bool "Timer $(index) prescaler"
|
|
||||||
|
|
||||||
config COUNTER_SAM0_TC32_$(index)_PRESCALER_1
|
|
||||||
bool "clock / 1"
|
|
||||||
config COUNTER_SAM0_TC32_$(index)_PRESCALER_2
|
|
||||||
bool "clock / 2"
|
|
||||||
config COUNTER_SAM0_TC32_$(index)_PRESCALER_4
|
|
||||||
bool "clock / 4"
|
|
||||||
config COUNTER_SAM0_TC32_$(index)_PRESCALER_8
|
|
||||||
bool "clock / 8"
|
|
||||||
config COUNTER_SAM0_TC32_$(index)_PRESCALER_16
|
|
||||||
bool "clock / 16"
|
|
||||||
config COUNTER_SAM0_TC32_$(index)_PRESCALER_64
|
|
||||||
bool "clock / 64"
|
|
||||||
config COUNTER_SAM0_TC32_$(index)_PRESCALER_256
|
|
||||||
bool "clock / 256"
|
|
||||||
config COUNTER_SAM0_TC32_$(index)_PRESCALER_1024
|
|
||||||
bool "clock / 1024"
|
|
||||||
|
|
||||||
endchoice
|
|
||||||
|
|
||||||
config COUNTER_SAM0_TC32_$(index)_DIVISOR
|
|
||||||
int
|
|
||||||
default 1 if COUNTER_SAM0_TC32_$(index)_PRESCALER_1
|
|
||||||
default 2 if COUNTER_SAM0_TC32_$(index)_PRESCALER_2
|
|
||||||
default 4 if COUNTER_SAM0_TC32_$(index)_PRESCALER_4
|
|
||||||
default 8 if COUNTER_SAM0_TC32_$(index)_PRESCALER_8
|
|
||||||
default 16 if COUNTER_SAM0_TC32_$(index)_PRESCALER_16
|
|
||||||
default 64 if COUNTER_SAM0_TC32_$(index)_PRESCALER_64
|
|
||||||
default 256 if COUNTER_SAM0_TC32_$(index)_PRESCALER_256
|
|
||||||
default 1024 if COUNTER_SAM0_TC32_$(index)_PRESCALER_1024
|
|
|
@ -4,6 +4,8 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define DT_DRV_COMPAT atmel_sam0_tc32
|
||||||
|
|
||||||
#include <drivers/counter.h>
|
#include <drivers/counter.h>
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
#include <soc.h>
|
#include <soc.h>
|
||||||
|
@ -402,64 +404,57 @@ static const struct counter_driver_api counter_sam0_tc32_driver_api = {
|
||||||
|
|
||||||
|
|
||||||
#ifdef MCLK
|
#ifdef MCLK
|
||||||
#define COUNTER_SAM0_TC32_CLOCK_CONTROL(n) \
|
#define COUNTER_SAM0_TC32_CLOCK_CONTROL(n) \
|
||||||
.mclk = MCLK_TC##n, \
|
.mclk = (volatile uint32_t *)MCLK_MASK_DT_INT_REG_ADDR(n), \
|
||||||
.mclk_mask = MCLK_TC##n##_MASK, \
|
.mclk_mask = BIT(DT_INST_CLOCKS_CELL_BY_NAME(n, mclk, bit)), \
|
||||||
.gclk_id = TC##n##_GCLK_ID,
|
.gclk_id = DT_INST_CLOCKS_CELL_BY_NAME(n, gclk, periph_ch),
|
||||||
#else
|
#else
|
||||||
#define COUNTER_SAM0_TC32_CLOCK_CONTROL(n) \
|
#define COUNTER_SAM0_TC32_CLOCK_CONTROL(n) \
|
||||||
.pm_apbcmask = PM_APBCMASK_TC##n, \
|
.pm_apbcmask = BIT(DT_INST_CLOCKS_CELL_BY_NAME(n, pm, bit)), \
|
||||||
.gclk_clkctrl_id = UTIL_CAT(GCLK_CLKCTRL_ID_TC ## n ## _TC, \
|
.gclk_clkctrl_id = DT_INST_CLOCKS_CELL_BY_NAME(n, gclk, clkctrl_id),
|
||||||
UTIL_INC(n)),
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define COUNTER_SAM0_TC32_DEVICE(n) \
|
#define SAM0_TC32_PRESCALER(n) \
|
||||||
static void counter_sam0_tc32_config_##n(struct device *dev); \
|
COND_CODE_1(DT_INST_NODE_HAS_PROP(n, prescaler), \
|
||||||
static const struct counter_sam0_tc32_config \
|
(DT_INST_PROP(n, prescaler)), (1))
|
||||||
counter_sam0_tc32_dev_config_##n = { \
|
|
||||||
.info = { \
|
#define COUNTER_SAM0_TC32_DEVICE(n) \
|
||||||
.max_top_value = UINT32_MAX, \
|
static void counter_sam0_tc32_config_##n(struct device *dev); \
|
||||||
.freq = SOC_ATMEL_SAM0_GCLK0_FREQ_HZ / \
|
static const struct counter_sam0_tc32_config \
|
||||||
CONFIG_COUNTER_SAM0_TC32_##n##_DIVISOR, \
|
\
|
||||||
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \
|
counter_sam0_tc32_dev_config_##n = { \
|
||||||
.channels = 1 \
|
.info = { \
|
||||||
}, \
|
.max_top_value = UINT32_MAX, \
|
||||||
.regs = (TcCount32 *)DT_ATMEL_SAM0_TC32_TC_##n##_BASE_ADDRESS,\
|
.freq = SOC_ATMEL_SAM0_GCLK0_FREQ_HZ / \
|
||||||
COUNTER_SAM0_TC32_CLOCK_CONTROL(n) \
|
SAM0_TC32_PRESCALER(n), \
|
||||||
.prescaler = UTIL_CAT(TC_CTRLA_PRESCALER_DIV, \
|
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \
|
||||||
CONFIG_COUNTER_SAM0_TC32_##n##_DIVISOR), \
|
.channels = 1 \
|
||||||
.irq_config_func = &counter_sam0_tc32_config_##n, \
|
}, \
|
||||||
}; \
|
.regs = (TcCount32 *)DT_INST_REG_ADDR(n), \
|
||||||
static struct counter_sam0_tc32_data counter_sam0_tc32_dev_data_##n; \
|
COUNTER_SAM0_TC32_CLOCK_CONTROL(n) \
|
||||||
DEVICE_AND_API_INIT(counter_sam0_tc32_##n, \
|
.prescaler = UTIL_CAT(TC_CTRLA_PRESCALER_DIV, \
|
||||||
DT_ATMEL_SAM0_TC32_TC_##n##_LABEL, \
|
SAM0_TC32_PRESCALER(n)), \
|
||||||
&counter_sam0_tc32_initialize, \
|
.irq_config_func = &counter_sam0_tc32_config_##n, \
|
||||||
&counter_sam0_tc32_dev_data_##n, \
|
}; \
|
||||||
&counter_sam0_tc32_dev_config_##n, PRE_KERNEL_1, \
|
\
|
||||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
static struct counter_sam0_tc32_data counter_sam0_tc32_dev_data_##n;\
|
||||||
&counter_sam0_tc32_driver_api); \
|
\
|
||||||
static void counter_sam0_tc32_config_##n(struct device *dev) \
|
DEVICE_AND_API_INIT(counter_sam0_tc32_##n, \
|
||||||
{ \
|
DT_INST_LABEL(n), \
|
||||||
IRQ_CONNECT(DT_ATMEL_SAM0_TC32_TC_##n##_IRQ_0, \
|
&counter_sam0_tc32_initialize, \
|
||||||
DT_ATMEL_SAM0_TC32_TC_##n##_IRQ_0_PRIORITY, \
|
&counter_sam0_tc32_dev_data_##n, \
|
||||||
counter_sam0_tc32_isr, \
|
&counter_sam0_tc32_dev_config_##n, \
|
||||||
DEVICE_GET(counter_sam0_tc32_##n), \
|
PRE_KERNEL_1, \
|
||||||
0); \
|
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
||||||
irq_enable(DT_ATMEL_SAM0_TC32_TC_##n##_IRQ_0); \
|
&counter_sam0_tc32_driver_api); \
|
||||||
|
\
|
||||||
|
static void counter_sam0_tc32_config_##n(struct device *dev) \
|
||||||
|
{ \
|
||||||
|
IRQ_CONNECT(DT_INST_IRQN(n), \
|
||||||
|
DT_INST_IRQ(n, priority), \
|
||||||
|
counter_sam0_tc32_isr, \
|
||||||
|
DEVICE_GET(counter_sam0_tc32_##n), 0); \
|
||||||
|
irq_enable(DT_INST_IRQN(n)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DT_ATMEL_SAM0_TC32_TC_0_BASE_ADDRESS
|
DT_INST_FOREACH(COUNTER_SAM0_TC32_DEVICE)
|
||||||
COUNTER_SAM0_TC32_DEVICE(0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if DT_ATMEL_SAM0_TC32_TC_2_BASE_ADDRESS
|
|
||||||
COUNTER_SAM0_TC32_DEVICE(2);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if DT_ATMEL_SAM0_TC32_TC_4_BASE_ADDRESS
|
|
||||||
COUNTER_SAM0_TC32_DEVICE(4);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if DT_ATMEL_SAM0_TC32_TC_6_BASE_ADDRESS
|
|
||||||
COUNTER_SAM0_TC32_DEVICE(6);
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -22,3 +22,17 @@ properties:
|
||||||
|
|
||||||
label:
|
label:
|
||||||
required: true
|
required: true
|
||||||
|
|
||||||
|
prescaler:
|
||||||
|
type: int
|
||||||
|
required: false
|
||||||
|
description: Timer prescaler
|
||||||
|
enum:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 4
|
||||||
|
- 8
|
||||||
|
- 16
|
||||||
|
- 64
|
||||||
|
- 256
|
||||||
|
- 1024
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue