Skip to content

Commit

Permalink
drivers: spi: cc13xx_cc26xx: set power config based on SPI base addr
Browse files Browse the repository at this point in the history
The power configuration is dependent on which SPI is physically used.
In order to allow DT_INST_FOREACH_STATUS_OKAY() to iterate through
instances without the assumption that index 0 corresponds to SPI0
(which would be incorrect in the case when only SPI1 is enabled),
we need to check the base address to identify which SPI is being dealt
with.

Fixes zephyrproject-rtos#25673

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
  • Loading branch information
vanti committed May 27, 2020
1 parent 2972cdc commit 9149518
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions drivers/spi/spi_cc13xx_cc26xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,23 +282,36 @@ static const struct spi_driver_api spi_cc13xx_cc26xx_driver_api = {
.release = spi_cc13xx_cc26xx_release,
};

#define SPI_CC13XX_CC26XX_DOMAIN_0 PRCM_DOMAIN_SERIAL
#define SPI_CC13XX_CC26XX_DOMAIN_1 PRCM_DOMAIN_PERIPH

#ifdef CONFIG_SYS_POWER_MANAGEMENT
#define SPI_CC13XX_CC26XX_POWER_SPI(n) \
/* Set Power dependencies & constraints */ \
Power_setDependency(PowerCC26XX_PERIPH_SSI##n)
#define SPI_CC13XX_CC26XX_POWER_SPI(n) \
do { \
/* Set Power dependencies & constraints */ \
if (DT_INST_REG_ADDR(n) == 0x40000000) { \
Power_setDependency(PowerCC26XX_PERIPH_SSI0); \
} else { \
Power_setDependency(PowerCC26XX_PERIPH_SSI1); \
} \
} while (0)
#else
#define SPI_CC13XX_CC26XX_POWER_SPI(n) \
do { \
u32_t domain, periph; \
\
/* Enable UART power domain */ \
if (DT_INST_REG_ADDR(n) == 0x40000000) { \
domain = PRCM_DOMAIN_SERIAL; \
periph = PRCM_PERIPH_SSI0; \
} else { \
domain = PRCM_DOMAIN_PERIPH; \
periph = PRCM_PERIPH_SSI1; \
} \
/* Enable SSI##n power domain */ \
PRCMPowerDomainOn(SPI_CC13XX_CC26XX_DOMAIN_##n); \
PRCMPowerDomainOn(domain); \
\
/* Enable SSI##n peripherals */ \
PRCMPeripheralRunEnable(PRCM_PERIPH_SSI##n); \
PRCMPeripheralSleepEnable(PRCM_PERIPH_SSI##n); \
PRCMPeripheralDeepSleepEnable(PRCM_PERIPH_SSI##n); \
PRCMPeripheralRunEnable(periph); \
PRCMPeripheralSleepEnable(periph); \
PRCMPeripheralDeepSleepEnable(periph); \
\
/* Load PRCM settings */ \
PRCMLoadSet(); \
Expand All @@ -307,8 +320,7 @@ static const struct spi_driver_api spi_cc13xx_cc26xx_driver_api = {
} \
\
/* SSI should not be accessed until power domain is on. */\
while (PRCMPowerDomainStatus( \
SPI_CC13XX_CC26XX_DOMAIN_##n) != \
while (PRCMPowerDomainStatus(domain) != \
PRCM_DOMAIN_POWER_ON) { \
continue; \
} \
Expand Down

0 comments on commit 9149518

Please sign in to comment.