From 1473c6848f4732c0d56bb50ca07ab3b6fedee90a Mon Sep 17 00:00:00 2001 From: Brennan Ashton Date: Thu, 17 Sep 2020 22:57:45 -0700 Subject: [PATCH] nRF52: Add hooks for missing SPI register callbacks This implements the missing callback hooks nrf52_spi0/1/2/3register that are usually used with mmcsd for card detection. This also stubs out the missing spi trigger function which is not used on this platform. The card detect was tested with the nRF52-feather board and a modified KeyBoard FeatherWing. Signed-off-by: Brennan Ashton --- arch/arm/src/nrf52/nrf52_spi.c | 55 ++++++++++++++++++++++++++++++++++ arch/arm/src/nrf52/nrf52_spi.h | 42 ++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/arch/arm/src/nrf52/nrf52_spi.c b/arch/arm/src/nrf52/nrf52_spi.c index dd03f417de..20b77c8d43 100644 --- a/arch/arm/src/nrf52/nrf52_spi.c +++ b/arch/arm/src/nrf52/nrf52_spi.c @@ -175,6 +175,14 @@ static const struct spi_ops_s g_spi0ops = .sendlock = nrf52_spi_sendblock, .recvblock = nrf52_spi_recvblock # endif +#ifdef CONFIG_SPI_TRIGGER + .trigger = nrf52_spi_trigger, +#endif +#ifdef CONFIG_SPI_CALLBACK + .registercallback = nrf52_spi0register, /* Provided externally */ +#else + .registercallback = 0, /* Not implemented */ +#endif }; static struct nrf52_spidev_s g_spi0dev = @@ -220,6 +228,14 @@ static const struct spi_ops_s g_spi1ops = .sendlock = nrf52_spi_sendblock, .recvblock = nrf52_spi_recvblock # endif +#ifdef CONFIG_SPI_TRIGGER + .trigger = nrf52_spi_trigger, +#endif +#ifdef CONFIG_SPI_CALLBACK + .registercallback = nrf52_spi1register, /* Provided externally */ +#else + .registercallback = 0, /* Not implemented */ +#endif }; static struct nrf52_spidev_s g_spi1dev = @@ -265,6 +281,14 @@ static const struct spi_ops_s g_spi2ops = .sendlock = nrf52_spi_sendblock, .recvblock = nrf52_spi_recvblock # endif +#ifdef CONFIG_SPI_TRIGGER + .trigger = nrf52_spi_trigger, +#endif +#ifdef CONFIG_SPI_CALLBACK + .registercallback = nrf52_spi2register, /* Provided externally */ +#else + .registercallback = 0, /* Not implemented */ +#endif }; static struct nrf52_spidev_s g_spi2dev = @@ -310,6 +334,14 @@ static const struct spi_ops_s g_spi3ops = .sendlock = nrf52_spi_sendblock, .recvblock = nrf52_spi_recvblock # endif +#ifdef CONFIG_SPI_TRIGGER + .trigger = nrf52_spi_trigger, +#endif +#ifdef CONFIG_SPI_CALLBACK + .registercallback = nrf52_spi3register, /* Provided externally */ +#else + .registercallback = 0, /* Not implemented */ +#endif }; static struct nrf52_spidev_s g_spi3dev = @@ -1029,6 +1061,29 @@ static void nrf52_spi_recvblock(FAR struct spi_dev_s *dev, } #endif /* CONFIG_SPI_EXCHANGE */ +/**************************************************************************** + * Name: nrf52_spi_trigger + * + * Description: + * Trigger a previously configured DMA transfer. + * + * Input Parameters: + * dev - Device-specific state data + * + * Returned Value: + * OK - Trigger was fired + * -ENOSYS - Trigger not fired due to lack of DMA or low level support + * -EIO - Trigger not fired because not previously primed + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_TRIGGER +static int nrf52_spi_trigger(FAR struct spi_dev_s *dev) +{ + return -ENOSYS; +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/arm/src/nrf52/nrf52_spi.h b/arch/arm/src/nrf52/nrf52_spi.h index 07a9ad5740..5a13e957dd 100644 --- a/arch/arm/src/nrf52/nrf52_spi.h +++ b/arch/arm/src/nrf52/nrf52_spi.h @@ -123,4 +123,46 @@ uint8_t nrf52_spi3status(FAR struct spi_dev_s *dev, uint32_t devid); int nrf52_spi3cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd); #endif +/**************************************************************************** + * Name: nrf52_spi0/1/2/3register + * + * Description: + * If the board supports a card detect callback to inform the SPI-based + * MMC/SD driver when an SD card is inserted or removed, then + * CONFIG_SPI_CALLBACK should be defined and the following function(s) must + * be implemented. These functions implements the registercallback method + * of the SPI interface (see include/nuttx/spi/spi.h for details) + * + * Input Parameters: + * dev - Device-specific state data + * callback - The function to call on the media change + * arg - A caller provided value to return with the callback + * + * Returned Value: + * 0 on success; negated errno on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_CALLBACK +#ifdef CONFIG_NRF52_SPI0_MASTER +int nrf52_spi0register(FAR struct spi_dev_s *dev, spi_mediachange_t callback, + FAR void *arg); +#endif + +#ifdef CONFIG_NRF52_SPI1_MASTER +int nrf52_spi1register(FAR struct spi_dev_s *dev, spi_mediachange_t callback, + FAR void *arg); +#endif + +#ifdef CONFIG_NRF52_SPI2_MASTER +int nrf52_spi2register(FAR struct spi_dev_s *dev, spi_mediachange_t callback, + FAR void *arg); +#endif + +#ifdef CONFIG_NRF52_SPI3_MASTER +int nrf52_spi3register(FAR struct spi_dev_s *dev, spi_mediachange_t callback, + FAR void *arg); +#endif +#endif + #endif /* __ARCH_ARM_SRC_NRF52_NRF52_SPI_H */