drivers: cc13xx_cc26xx: use DT_INST_FOREACH to reduce code duplication
Use DT_INST_FOREACH macro to combine code used for multiple instances. Remove unnecessary Kconfig options for UART instances. Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
This commit is contained in:
parent
984988285b
commit
0915ccca46
3 changed files with 229 additions and 339 deletions
|
@ -284,142 +284,94 @@ static const struct spi_driver_api spi_cc13xx_cc26xx_driver_api = {
|
|||
#warning "No SPI port configured"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SPI_0
|
||||
static int spi_cc13xx_cc26xx_init_0(struct device *dev)
|
||||
{
|
||||
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
|
||||
get_dev_data(dev)->pm_state = DEVICE_PM_ACTIVE_STATE;
|
||||
#endif
|
||||
#define SPI_CC13XX_CC26XX_DOMAIN_0 PRCM_DOMAIN_SERIAL
|
||||
#define SPI_CC13XX_CC26XX_DOMAIN_1 PRCM_DOMAIN_PERIPH
|
||||
|
||||
#ifdef CONFIG_SYS_POWER_MANAGEMENT
|
||||
/* Set Power dependencies & constraints */
|
||||
Power_setDependency(PowerCC26XX_PERIPH_SSI0);
|
||||
#define SPI_CC13XX_CC26XX_POWER_SPI(n) \
|
||||
/* Set Power dependencies & constraints */ \
|
||||
Power_setDependency(PowerCC26XX_PERIPH_SSI##n)
|
||||
#else
|
||||
/* Enable SSI0 power domain */
|
||||
PRCMPowerDomainOn(PRCM_DOMAIN_SERIAL);
|
||||
|
||||
/* Enable SSI0 peripherals */
|
||||
PRCMPeripheralRunEnable(PRCM_PERIPH_SSI0);
|
||||
/* Enable in sleep mode until proper power management is added */
|
||||
PRCMPeripheralSleepEnable(PRCM_PERIPH_SSI0);
|
||||
PRCMPeripheralDeepSleepEnable(PRCM_PERIPH_SSI0);
|
||||
|
||||
/* Load PRCM settings */
|
||||
PRCMLoadSet();
|
||||
while (!PRCMLoadGet()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* SSI should not be accessed until power domain is on. */
|
||||
while (PRCMPowerDomainStatus(PRCM_DOMAIN_SERIAL) !=
|
||||
PRCM_DOMAIN_POWER_ON) {
|
||||
continue;
|
||||
}
|
||||
#define SPI_CC13XX_CC26XX_POWER_SPI(n) \
|
||||
do { \
|
||||
/* Enable SSI##n power domain */ \
|
||||
PRCMPowerDomainOn(SPI_CC13XX_CC26XX_DOMAIN_##n); \
|
||||
\
|
||||
/* Enable SSI##n peripherals */ \
|
||||
PRCMPeripheralRunEnable(PRCM_PERIPH_SSI##n); \
|
||||
PRCMPeripheralSleepEnable(PRCM_PERIPH_SSI##n); \
|
||||
PRCMPeripheralDeepSleepEnable(PRCM_PERIPH_SSI##n); \
|
||||
\
|
||||
/* Load PRCM settings */ \
|
||||
PRCMLoadSet(); \
|
||||
while (!PRCMLoadGet()) { \
|
||||
continue; \
|
||||
} \
|
||||
\
|
||||
/* SSI should not be accessed until power domain is on. */\
|
||||
while (PRCMPowerDomainStatus( \
|
||||
SPI_CC13XX_CC26XX_DOMAIN_##n) != \
|
||||
PRCM_DOMAIN_POWER_ON) { \
|
||||
continue; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
spi_context_unlock_unconditionally(&get_dev_data(dev)->ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct spi_cc13xx_cc26xx_config spi_cc13xx_cc26xx_config_0 = {
|
||||
.base = DT_INST_REG_ADDR(0),
|
||||
.sck_pin = DT_PROP(DT_NODELABEL(spi0), sck_pin),
|
||||
.mosi_pin = DT_PROP(DT_NODELABEL(spi0), mosi_pin),
|
||||
.miso_pin = DT_PROP(DT_NODELABEL(spi0), miso_pin),
|
||||
#ifdef DT_TI_CC13XX_CC26XX_SPI_40000000_CS_PIN
|
||||
.cs_pin = DT_PROP(DT_NODELABEL(spi0), cs_pin),
|
||||
#else
|
||||
.cs_pin = IOID_UNUSED,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct spi_cc13xx_cc26xx_data spi_cc13xx_cc26xx_data_0 = {
|
||||
SPI_CONTEXT_INIT_LOCK(spi_cc13xx_cc26xx_data_0, ctx),
|
||||
SPI_CONTEXT_INIT_SYNC(spi_cc13xx_cc26xx_data_0, ctx),
|
||||
};
|
||||
|
||||
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
|
||||
DEVICE_DEFINE(spi_cc13xx_cc26xx_0, DT_INST_LABEL(0),
|
||||
spi_cc13xx_cc26xx_init_0,
|
||||
spi_cc13xx_cc26xx_pm_control,
|
||||
&spi_cc13xx_cc26xx_data_0, &spi_cc13xx_cc26xx_config_0,
|
||||
POST_KERNEL, CONFIG_SPI_INIT_PRIORITY,
|
||||
&spi_cc13xx_cc26xx_driver_api);
|
||||
#else
|
||||
DEVICE_AND_API_INIT(spi_cc13xx_cc26xx_0, DT_INST_LABEL(0),
|
||||
spi_cc13xx_cc26xx_init_0, &spi_cc13xx_cc26xx_data_0,
|
||||
&spi_cc13xx_cc26xx_config_0, POST_KERNEL,
|
||||
CONFIG_SPI_INIT_PRIORITY, &spi_cc13xx_cc26xx_driver_api);
|
||||
#endif
|
||||
#endif /* CONFIG_SPI_0 */
|
||||
#define SPI_CC13XX_CC26XX_DEVICE_INIT(n) \
|
||||
DEVICE_DEFINE(spi_cc13xx_cc26xx_##n, DT_INST_LABEL(n), \
|
||||
spi_cc13xx_cc26xx_init_##n, \
|
||||
spi_cc13xx_cc26xx_pm_control, \
|
||||
&spi_cc13xx_cc26xx_data_##n, &spi_cc13xx_cc26xx_config_##n, \
|
||||
POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \
|
||||
&spi_cc13xx_cc26xx_driver_api)
|
||||
|
||||
#ifdef CONFIG_SPI_1
|
||||
static int spi_cc13xx_cc26xx_init_1(struct device *dev)
|
||||
{
|
||||
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
|
||||
get_dev_data(dev)->pm_state = DEVICE_PM_ACTIVE_STATE;
|
||||
#define SPI_CC13XX_CC26XX_INIT_PM_STATE \
|
||||
do { \
|
||||
get_dev_data(dev)->pm_state = DEVICE_PM_ACTIVE_STATE; \
|
||||
} while (0)
|
||||
#else
|
||||
#define SPI_CC13XX_CC26XX_DEVICE_INIT(n) \
|
||||
DEVICE_AND_API_INIT(spi_cc13xx_cc26xx_##n, DT_INST_LABEL(n), \
|
||||
spi_cc13xx_cc26xx_init_##n, &spi_cc13xx_cc26xx_data_##n,\
|
||||
&spi_cc13xx_cc26xx_config_##n, POST_KERNEL, \
|
||||
CONFIG_SPI_INIT_PRIORITY, \
|
||||
&spi_cc13xx_cc26xx_driver_api)
|
||||
|
||||
#define SPI_CC13XX_CC26XX_INIT_PM_STATE
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SYS_POWER_MANAGEMENT
|
||||
/* Set Power dependencies & constraints */
|
||||
Power_setDependency(PowerCC26XX_PERIPH_SSI1);
|
||||
#else
|
||||
/* Enable SSI1 power domain */
|
||||
PRCMPowerDomainOn(PRCM_DOMAIN_PERIPH);
|
||||
|
||||
/* Enable SSI1 peripherals */
|
||||
PRCMPeripheralRunEnable(PRCM_PERIPH_SSI1);
|
||||
/* Enable in sleep mode until proper power management is added */
|
||||
PRCMPeripheralSleepEnable(PRCM_PERIPH_SSI1);
|
||||
PRCMPeripheralDeepSleepEnable(PRCM_PERIPH_SSI1);
|
||||
|
||||
/* Load PRCM settings */
|
||||
PRCMLoadSet();
|
||||
while (!PRCMLoadGet()) {
|
||||
continue;
|
||||
#define SPI_CC13XX_CC26XX_INIT_FUNC(n) \
|
||||
static int spi_cc13xx_cc26xx_init_##n(struct device *dev) \
|
||||
{ \
|
||||
SPI_CC13XX_CC26XX_INIT_PM_STATE; \
|
||||
\
|
||||
SPI_CC13XX_CC26XX_POWER_SPI(n); \
|
||||
\
|
||||
spi_context_unlock_unconditionally(&get_dev_data(dev)->ctx);\
|
||||
\
|
||||
return 0; \
|
||||
}
|
||||
|
||||
/* SSI should not be accessed until power domain is on. */
|
||||
while (PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) !=
|
||||
PRCM_DOMAIN_POWER_ON) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
#define SPI_CC13XX_CC26XX_INIT(n) \
|
||||
SPI_CC13XX_CC26XX_INIT_FUNC(n) \
|
||||
\
|
||||
static const struct spi_cc13xx_cc26xx_config \
|
||||
spi_cc13xx_cc26xx_config_##n = { \
|
||||
.base = DT_INST_REG_ADDR(n), \
|
||||
.sck_pin = DT_INST_PROP(n, sck_pin), \
|
||||
.mosi_pin = DT_INST_PROP(n, mosi_pin), \
|
||||
.miso_pin = DT_INST_PROP(n, miso_pin), \
|
||||
.cs_pin = COND_CODE_1(DT_INST_NODE_HAS_PROP(n, cs_pin), \
|
||||
(DT_INST_PROP(n, cs_pin)), (IOID_UNUSED)) \
|
||||
}; \
|
||||
\
|
||||
static struct spi_cc13xx_cc26xx_data \
|
||||
spi_cc13xx_cc26xx_data_##n = { \
|
||||
SPI_CONTEXT_INIT_LOCK(spi_cc13xx_cc26xx_data_##n, ctx), \
|
||||
SPI_CONTEXT_INIT_SYNC(spi_cc13xx_cc26xx_data_##n, ctx), \
|
||||
}; \
|
||||
\
|
||||
SPI_CC13XX_CC26XX_DEVICE_INIT(n)
|
||||
|
||||
spi_context_unlock_unconditionally(&get_dev_data(dev)->ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct spi_cc13xx_cc26xx_config spi_cc13xx_cc26xx_config_1 = {
|
||||
.base = DT_INST_REG_ADDR(1),
|
||||
.sck_pin = DT_PROP(DT_NODELABEL(spi1), sck_pin),
|
||||
.mosi_pin = DT_PROP(DT_NODELABEL(spi1), mosi_pin),
|
||||
.miso_pin = DT_PROP(DT_NODELABEL(spi1), miso_pin),
|
||||
#ifdef DT_TI_CC13XX_CC26XX_SPI_40008000_CS_PIN
|
||||
.cs_pin = DT_PROP(DT_NODELABEL(spi1), cs_pin),
|
||||
#else
|
||||
.cs_pin = IOID_UNUSED,
|
||||
#endif /* DT_TI_CC13XX_CC26XX_SPI_1_CS_PIN */
|
||||
};
|
||||
|
||||
static struct spi_cc13xx_cc26xx_data spi_cc13xx_cc26xx_data_1 = {
|
||||
SPI_CONTEXT_INIT_LOCK(spi_cc13xx_cc26xx_data_1, ctx),
|
||||
SPI_CONTEXT_INIT_SYNC(spi_cc13xx_cc26xx_data_1, ctx),
|
||||
};
|
||||
|
||||
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
|
||||
DEVICE_DEFINE(spi_cc13xx_cc26xx_1, DT_INST_LABEL(1),
|
||||
spi_cc13xx_cc26xx_init_1,
|
||||
spi_cc13xx_cc26xx_pm_control,
|
||||
&spi_cc13xx_cc26xx_data_1, &spi_cc13xx_cc26xx_config_1,
|
||||
POST_KERNEL, CONFIG_SPI_INIT_PRIORITY,
|
||||
&spi_cc13xx_cc26xx_driver_api);
|
||||
#else
|
||||
DEVICE_AND_API_INIT(spi_cc13xx_cc26xx_1, DT_INST_LABEL(1),
|
||||
spi_cc13xx_cc26xx_init_1, &spi_cc13xx_cc26xx_data_1,
|
||||
&spi_cc13xx_cc26xx_config_1, POST_KERNEL,
|
||||
CONFIG_SPI_INIT_PRIORITY, &spi_cc13xx_cc26xx_driver_api);
|
||||
#endif
|
||||
#endif /* CONFIG_SPI_1 */
|
||||
DT_INST_FOREACH(SPI_CC13XX_CC26XX_INIT)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue