From 1c1e821b342598093dc08472f271d40ec1147b04 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Mar 2014 10:34:35 -0600 Subject: [PATCH] Backport SPI driver enhancements from SAMA5 to SAM3/4 --- configs/sam3u-ek/src/up_spi.c | 18 +++++++++--------- configs/sam4e-ek/src/Makefile | 6 +++++- configs/sam4e-ek/src/sam4e-ek.h | 6 +++--- configs/sam4e-ek/src/sam_spi.c | 26 +++++++++++++------------- configs/sam4l-xplained/src/sam_spi.c | 22 +++++++++++----------- 5 files changed, 41 insertions(+), 37 deletions(-) diff --git a/configs/sam3u-ek/src/up_spi.c b/configs/sam3u-ek/src/up_spi.c index 20423200da..bdedc91ac8 100644 --- a/configs/sam3u-ek/src/up_spi.c +++ b/configs/sam3u-ek/src/up_spi.c @@ -107,14 +107,14 @@ void weak_function sam_spiinitialize(void) } /**************************************************************************** - * Name: sam_spiselect, sam_spistatus, and sam_spicmddata + * Name: sam_spi0select, sam_spi0status, and sam_spic0mddata * * Description: * These external functions must be provided by board-specific logic. They * include: * - * o sam_spiselect is a functions tomanage the board-specific chip selects - * o sam_spistatus and sam_spicmddata: Implementations of the status + * o sam_spi0select is a functions tomanage the board-specific chip selects + * o sam_spi0status and sam_spic0mddata: Implementations of the status * and cmddata methods of the SPI interface defined by struct spi_ops_ * (see include/nuttx/spi/spi.h). All other methods including * up_spiinitialize()) are provided by common SAM3/4 logic. @@ -123,11 +123,11 @@ void weak_function sam_spiinitialize(void) * * 1. Provide logic in sam_boardinitialize() to configure SPI chip select * pins. - * 2. Provide sam_spiselect() and sam_spistatus() functions in your board- + * 2. Provide sam_spi0select() and sam_spi0status() functions in your board- * specific logic. These functions will perform chip selection and * status operations using GPIOs in the way your board is configured. * 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide - * sam_spicmddata() functions in your board-specific logic. This + * sam_spic0mddata() functions in your board-specific logic. This * function will perform cmd/data selection operations using GPIOs in * the way your board is configured. * 3. Add a call to up_spiinitialize() in your low level application @@ -140,7 +140,7 @@ void weak_function sam_spiinitialize(void) ****************************************************************************/ /**************************************************************************** - * Name: sam_spiselect + * Name: sam_spi0select * * Description: * PIO chip select pins may be programmed by the board specific logic in @@ -164,7 +164,7 @@ void weak_function sam_spiinitialize(void) * ****************************************************************************/ -void sam_spiselect(enum spi_dev_e devid, bool selected) +void sam_spi0select(enum spi_dev_e devid, bool selected) { /* The touchscreen chip select is implemented as a GPIO OUTPUT that must * be controlled by this function. This is because the ADS7843E driver @@ -183,7 +183,7 @@ void sam_spiselect(enum spi_dev_e devid, bool selected) } /**************************************************************************** - * Name: sam_spistatus + * Name: sam_spi0status * * Description: * Return status information associated with the SPI device. @@ -196,7 +196,7 @@ void sam_spiselect(enum spi_dev_e devid, bool selected) * ****************************************************************************/ -uint8_t sam_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid) +uint8_t sam_spi0status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) { return 0; } diff --git a/configs/sam4e-ek/src/Makefile b/configs/sam4e-ek/src/Makefile index 75d9029d33..975269671b 100644 --- a/configs/sam4e-ek/src/Makefile +++ b/configs/sam4e-ek/src/Makefile @@ -40,7 +40,7 @@ CFLAGS += -I$(TOPDIR)/sched ASRCS = AOBJS = $(ASRCS:.S=$(OBJEXT)) -CSRCS = sam_boot.c sam_leds.c sam_buttons.c sam_spi.c sam_usbdev.c +CSRCS = sam_boot.c sam_leds.c sam_buttons.c sam_usbdev.c ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y) CSRCS += sam_cxxinitialize.c @@ -58,6 +58,10 @@ ifeq ($(CONFIG_SAM34_HSMCI),y) CSRCS += sam_mmcsd.c endif +ifeq ($(CONFIG_SAM34_SPI0),y) +CSRCS += sam_spi.c +endif + ifeq ($(CONFIG_USBMSC),y) CSRCS += sam_usbmsc.c endif diff --git a/configs/sam4e-ek/src/sam4e-ek.h b/configs/sam4e-ek/src/sam4e-ek.h index f878268296..0e6c29358b 100644 --- a/configs/sam4e-ek/src/sam4e-ek.h +++ b/configs/sam4e-ek/src/sam4e-ek.h @@ -268,9 +268,9 @@ * it low throughout the SPI transfer. */ -#define GPIO_TSC_NPCS2 (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_SET | \ - GPIO_PORT_PIOA | GPIO_PIN11) -#define TSC_CSNUM 0 +#define GPIO_TSC_CS (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_SET | \ + GPIO_PORT_PIOA | GPIO_PIN11) +#define TSC_CSNUM 0 /************************************************************************************ * Public Types diff --git a/configs/sam4e-ek/src/sam_spi.c b/configs/sam4e-ek/src/sam_spi.c index 5338d1ffe5..714a643ed5 100644 --- a/configs/sam4e-ek/src/sam_spi.c +++ b/configs/sam4e-ek/src/sam_spi.c @@ -53,7 +53,7 @@ #include "sam_spi.h" #include "sam4e-ek.h" -#if defined(CONFIG_SAM34_SPI0) || defined(CONFIG_SAM34_SPI1) +#if defined(CONFIG_SAM34_SPI0) /************************************************************************************ * Definitions @@ -99,22 +99,22 @@ void weak_function sam_spiinitialize(void) * ZigBee support. */ - /* The touchscreen connects using NPCS2 (PC14). */ + /* The touchscreen connects using NPCS0 (PA11). */ #if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E) - sam_configgpio(GPIO_TSC_NPCS2); + sam_configgpio(GPIO_TSC_CS); #endif } /**************************************************************************** - * Name: sam_spiselect, sam_spistatus, and sam_spicmddata + * Name: sam_spi0select, sam_spi0status, and sam_spic0mddata * * Description: * These external functions must be provided by board-specific logic. They * include: * - * o sam_spiselect is a functions tomanage the board-specific chip selects - * o sam_spistatus and sam_spicmddata: Implementations of the status + * o sam_spi0select is a functions tomanage the board-specific chip selects + * o sam_spi0status and sam_spic0mddata: Implementations of the status * and cmddata methods of the SPI interface defined by struct spi_ops_ * (see include/nuttx/spi/spi.h). All other methods including * up_spiinitialize()) are provided by common SAM3/4 logic. @@ -123,11 +123,11 @@ void weak_function sam_spiinitialize(void) * * 1. Provide logic in sam_boardinitialize() to configure SPI chip select * pins. - * 2. Provide sam_spiselect() and sam_spistatus() functions in your board- + * 2. Provide sam_spi0select() and sam_spi0status() functions in your board- * specific logic. These functions will perform chip selection and * status operations using GPIOs in the way your board is configured. * 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide - * sam_spicmddata() functions in your board-specific logic. This + * sam_spic0mddata() functions in your board-specific logic. This * function will perform cmd/data selection operations using GPIOs in * the way your board is configured. * 3. Add a call to up_spiinitialize() in your low level application @@ -140,7 +140,7 @@ void weak_function sam_spiinitialize(void) ****************************************************************************/ /**************************************************************************** - * Name: sam_spiselect + * Name: sam_spi0select * * Description: * PIO chip select pins may be programmed by the board specific logic in @@ -164,7 +164,7 @@ void weak_function sam_spiinitialize(void) * ****************************************************************************/ -void sam_spiselect(enum spi_dev_e devid, bool selected) +void sam_spi0select(enum spi_dev_e devid, bool selected) { /* The touchscreen chip select is implemented as a GPIO OUTPUT that must * be controlled by this function. This is because the ADS7843E driver @@ -177,13 +177,13 @@ void sam_spiselect(enum spi_dev_e devid, bool selected) #if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E) if (devid == SPIDEV_TOUCHSCREEN) { - sam_gpiowrite(GPIO_TSC_NPCS2, !selected); + sam_gpiowrite(GPIO_TSC_CS, !selected); } #endif } /**************************************************************************** - * Name: sam_spistatus + * Name: sam_spi0status * * Description: * Return status information associated with the SPI device. @@ -196,7 +196,7 @@ void sam_spiselect(enum spi_dev_e devid, bool selected) * ****************************************************************************/ -uint8_t sam_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid) +uint8_t sam_spi0status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) { return 0; } diff --git a/configs/sam4l-xplained/src/sam_spi.c b/configs/sam4l-xplained/src/sam_spi.c index 7fe719320b..129e72aecc 100644 --- a/configs/sam4l-xplained/src/sam_spi.c +++ b/configs/sam4l-xplained/src/sam_spi.c @@ -115,14 +115,14 @@ void weak_function sam_spiinitialize(void) } /**************************************************************************** - * Name: sam_spiselect, sam_spistatus, and sam_spicmddata + * Name: sam_spi0select, sam_spi0status, and sam_spic0mddata * * Description: * These external functions must be provided by board-specific logic. They * include: * - * o sam_spiselect is a functions tomanage the board-specific chip selects - * o sam_spistatus and sam_spicmddata: Implementations of the status + * o sam_spi0select is a functions tomanage the board-specific chip selects + * o sam_spi0status and sam_spic0mddata: Implementations of the status * and cmddata methods of the SPI interface defined by struct spi_ops_ * (see include/nuttx/spi/spi.h). All other methods including * up_spiinitialize()) are provided by common SAM3/4 logic. @@ -131,11 +131,11 @@ void weak_function sam_spiinitialize(void) * * 1. Provide logic in sam_boardinitialize() to configure SPI chip select * pins. - * 2. Provide sam_spiselect() and sam_spistatus() functions in your board- + * 2. Provide sam_spi0select() and sam_spi0status() functions in your board- * specific logic. These functions will perform chip selection and * status operations using GPIOs in the way your board is configured. * 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide - * sam_spicmddata() functions in your board-specific logic. This + * sam_spic0mddata() functions in your board-specific logic. This * function will perform cmd/data selection operations using GPIOs in * the way your board is configured. * 3. Add a call to up_spiinitialize() in your low level application @@ -148,7 +148,7 @@ void weak_function sam_spiinitialize(void) ****************************************************************************/ /**************************************************************************** - * Name: sam_spiselect + * Name: sam_spi0select * * Description: * PIO chip select pins may be programmed by the board specific logic in @@ -172,7 +172,7 @@ void weak_function sam_spiinitialize(void) * ****************************************************************************/ -void sam_spiselect(enum spi_dev_e devid, bool selected) +void sam_spi0select(enum spi_dev_e devid, bool selected) { #ifdef CONFIG_SAM4L_XPLAINED_IOMODULE /* Select/de-select the SD card */ @@ -202,7 +202,7 @@ void sam_spiselect(enum spi_dev_e devid, bool selected) } /**************************************************************************** - * Name: sam_spistatus + * Name: sam_spi0status * * Description: * Return status information associated with the SPI device. @@ -215,7 +215,7 @@ void sam_spiselect(enum spi_dev_e devid, bool selected) * ****************************************************************************/ -uint8_t sam_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid) +uint8_t sam_spi0status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) { uint8_t ret = 0; @@ -239,7 +239,7 @@ uint8_t sam_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid) #endif /* CONFIG_SAM34_SPI0 */ /**************************************************************************** - * Name: sam_spicmddata + * Name: sam_spic0mddata * * Description: * Some SPI devices require an additional control to determine if the SPI @@ -263,7 +263,7 @@ uint8_t sam_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid) ****************************************************************************/ #ifdef CONFIG_SPI_CMDDATA -int sam_spicmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd) +int sam_spic0mddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd) { #ifdef CONFIG_SAM4L_XPLAINED_OLED1MODULE if (devid == SPIDEV_DISPLAY)