From d720db181410ae899a9c44deca2d0a2d6d1751ff Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 3 Dec 2010 01:37:56 +0000 Subject: [PATCH] Add cmddata method to the SPI interface git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3157 42af7a65-404d-4744-a932-0658087f49c3 --- arch/arm/src/imx/chip.h | 2 +- arch/arm/src/imx/imx_cspi.h | 23 +++++++++------ arch/arm/src/imx/imx_memorymap.h | 2 +- arch/arm/src/imx/imx_spi.c | 3 ++ arch/arm/src/imx/imx_system.h | 2 +- arch/arm/src/lm3s/lm3s_internal.h | 18 ++++++++---- arch/arm/src/lm3s/lm3s_ssi.c | 5 +++- arch/arm/src/lpc17xx/lpc17_internal.h | 29 +++++++++++++------ arch/arm/src/lpc17xx/lpc17_spi.c | 3 ++ arch/arm/src/lpc17xx/lpc17_ssp.c | 6 ++++ arch/arm/src/lpc313x/lpc313x_internal.h | 23 +++++++++------ arch/arm/src/lpc313x/lpc313x_spi.c | 3 ++ arch/arm/src/stm32/stm32_internal.h | 25 ++++++++++------ arch/arm/src/stm32/stm32_spi.c | 9 ++++++ arch/z80/src/ez80/ez80_spi.c | 3 ++ arch/z80/src/ez80/ez80f91_spi.h | 21 ++++++++------ configs/mcu123-lpc214x/src/up_spi.c | 38 +++++++++++++++++++++++++ configs/olimex-strp711/src/up_spi.c | 38 +++++++++++++++++++++++++ include/nuttx/spi.h | 31 ++++++++++++++++++++ 19 files changed, 234 insertions(+), 50 deletions(-) diff --git a/arch/arm/src/imx/chip.h b/arch/arm/src/imx/chip.h index 00272ccdb8..c8a6615d7e 100644 --- a/arch/arm/src/imx/chip.h +++ b/arch/arm/src/imx/chip.h @@ -1,7 +1,7 @@ /************************************************************************************ * arch/arm/src/imx/chip.h * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/arch/arm/src/imx/imx_cspi.h b/arch/arm/src/imx/imx_cspi.h index e0d97f2d44..421b6a4e31 100755 --- a/arch/arm/src/imx/imx_cspi.h +++ b/arch/arm/src/imx/imx_cspi.h @@ -1,7 +1,7 @@ /************************************************************************************ * arch/arm/src/imx/imx_cspi.h * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -176,23 +176,30 @@ extern "C" { * Public Functions ************************************************************************************/ -/* The external functions, imx_spiselect and imx_spistatus must be provided by - * board-specific logic. The are implementations of the select and status methods - * SPI interface defined by struct spi_ops_s (see include/nuttx/spi.h). All other - * methods (including up_spiinitialize()) are provided by common logic. To use this - * common SPI logic on your board: +/* The external functions, imx_spiselect, imx_spistatus, and imx_cmddaa must be + * provided by board-specific logic. These are implementations of the select and + * status methods of the SPI interface defined by struct spi_ops_s (see + * include/nuttx/spi.h). All other methods (including up_spiinitialize()) are + * provided by common logic. To use this common SPI logic on your board: * * 1. Provide imx_spiselect() and imx_spistatus() functions in your board-specific * logic. This function will perform chip selection and status operations using * GPIOs in the way your board is configured. - * 2. Add a call to up_spiinitialize() in your low level initialization logic - * 3. The handle returned by up_spiinitialize() may then be used to bind the + * 2. If CONFIG_SPI_CMDDATA is defined in your NuttX configuration, provide the + * imx_spicmddata() function 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 initialization logic + * 4. The handle returned by up_spiinitialize() may then be used to bind the * SPI driver to higher level logic (e.g., calling mmcsd_spislotinitialize(), * for example, will bind the SPI driver to the SPI MMC/SD driver). */ EXTERN void imx_spiselect(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); EXTERN uint8_t imx_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +#ifdef CONFIG_SPI_CMDDATA +EXTERN int imx_spicmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif #undef EXTERN #ifdef __cplusplus diff --git a/arch/arm/src/imx/imx_memorymap.h b/arch/arm/src/imx/imx_memorymap.h index d656b2f808..0b7603befb 100644 --- a/arch/arm/src/imx/imx_memorymap.h +++ b/arch/arm/src/imx/imx_memorymap.h @@ -1,7 +1,7 @@ /************************************************************************************ * arch/arm/src/imx/imx_memorymap.h * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/arch/arm/src/imx/imx_spi.c b/arch/arm/src/imx/imx_spi.c index 578e274cd2..e07cd5d32e 100755 --- a/arch/arm/src/imx/imx_spi.c +++ b/arch/arm/src/imx/imx_spi.c @@ -197,6 +197,9 @@ static const struct spi_ops_s g_spiops = .setmode = spi_setmode, .setbits = spi_setbits, .status = imx_spistatus, /* Provided externally by board logic */ +#ifdef CONFIG_SPI_CMDDATA + .cmddata = imx_spicmddata, +#endif .send = spi_send, #ifdef CONFIG_SPI_EXCHANGE .exchange = spi_exchange, diff --git a/arch/arm/src/imx/imx_system.h b/arch/arm/src/imx/imx_system.h index fe575cf414..a3a4b4c549 100755 --- a/arch/arm/src/imx/imx_system.h +++ b/arch/arm/src/imx/imx_system.h @@ -1,7 +1,7 @@ /************************************************************************************ * arch/arm/src/imx/imx_system.h * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/arch/arm/src/lm3s/lm3s_internal.h b/arch/arm/src/lm3s/lm3s_internal.h index 38a079743b..43bcf2d6f5 100644 --- a/arch/arm/src/lm3s/lm3s_internal.h +++ b/arch/arm/src/lm3s/lm3s_internal.h @@ -474,9 +474,10 @@ EXTERN int lm3s_ethinitialize(int intf); #endif /**************************************************************************** - * The external functions, lm3s_spiselect and lm3s_spistatus must be provided - * by board-specific logic. The are implementations of the select and status - * methods SPI interface defined by struct spi_ops_s (see include/nuttx/spi.h). + * The external functions, lm3s_spiselect, lm3s_spistatus, and + * lm3s_spicmddata must be provided by board-specific logic. These are + * implementations of the select, status, and cmddaa methods of the SPI + * interface defined by struct spi_ops_s (see include/nuttx/spi.h). * All other methods (including up_spiinitialize()) are provided by common * logic. To use this common SPI logic on your board: * @@ -485,9 +486,13 @@ EXTERN int lm3s_ethinitialize(int intf); * 2. Provide lm3s_spiselect() and lm3s_spistatus() functions in your * board-specific logic. These functions will perform chip selection and * status operations using GPIOs in the way your board is configured. - * 3. Add a call to up_spiinitialize() in your low level application + * 3. If CONFIG_SPI_CMDDATA is defined in your NuttX configuration, provide + * the lm3s_spicmddata() function in your board-specific logic. This + * functions will perform cmd/data selection operations using GPIOs in + * the way your board is configured. + * 4. Add a call to up_spiinitialize() in your low level application * initialization logic - * 4. The handle returned by up_spiinitialize() may then be used to bind the + * 5. The handle returned by up_spiinitialize() may then be used to bind the * SPI driver to higher level logic (e.g., calling * mmcsd_spislotinitialize(), for example, will bind the SPI driver to * the SPI MMC/SD driver). @@ -498,6 +503,9 @@ struct spi_dev_s; enum spi_dev_e; EXTERN void lm3s_spiselect(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); EXTERN uint8_t lm3s_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +#ifdef CONFIG_SPI_CMDDATA +EXTERN int lm3s_spicmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif #undef EXTERN #if defined(__cplusplus) diff --git a/arch/arm/src/lm3s/lm3s_ssi.c b/arch/arm/src/lm3s/lm3s_ssi.c index 8c3929ad72..3b6abab2c9 100755 --- a/arch/arm/src/lm3s/lm3s_ssi.c +++ b/arch/arm/src/lm3s/lm3s_ssi.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/lm32/lm3s_spi.c + * arch/arm/src/lm32/lm3s_ssi.c * * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -279,6 +279,9 @@ static const struct spi_ops_s g_spiops = .setmode = ssi_setmode, .setbits = ssi_setbits, .status = lm3s_spistatus, /* Provided externally by board logic */ +#ifdef CONFIG_SPI_CMDDATA + .cmddata = lm3s_spicmddata, +#endif .send = ssi_send, #ifdef CONFIG_SPI_EXCHANGE .exchange = ssi_exchange, diff --git a/arch/arm/src/lpc17xx/lpc17_internal.h b/arch/arm/src/lpc17xx/lpc17_internal.h index 41fe549b4b..2c684767c8 100755 --- a/arch/arm/src/lpc17xx/lpc17_internal.h +++ b/arch/arm/src/lpc17xx/lpc17_internal.h @@ -555,22 +555,26 @@ EXTERN int lpc17_dumpgpio(uint16_t pinset, const char *msg); EXTERN void lpc17_clrpend(int irq); /************************************************************************************ - * Name: lpc17_spi/ssp0/ssp1select and lpc17_spi/ssp0/ssp1status + * Name: lpc17_spi/ssp0/ssp1select, lpc17_spi/ssp0/ssp1status, and + * lpc17_spi/ssp0/ssp1cmddata * * Description: - * The external functions, lpc17_spi/ssp0/ssp1select and lpc17_spi/ssp0/ssp1status - * must be provided by board-specific logic. They are implementations of the select - * and status methods of the SPI interface defined by struct spi_ops_s (see - * include/nuttx/spi.h). All other methods (including up_spiinitialize()) - * are provided by common LPC17xx logic. To use this common SPI logic on your - * board: + * These external functions must be provided by board-specific logic. They are + * implementations of the select, status, and cmddata methods of the SPI interface + * defined by struct spi_ops_s (see include/nuttx/spi.h). All other methods + * including up_spiinitialize()) are provided by common LPC17xx logic. To use + * this common SPI logic on your board: * * 1. Provide logic in lpc17_boardinitialize() to configure SPI/SSP chip select * pins. * 2. Provide lpc17_spi/ssp0/ssp1select() and lpc17_spi/ssp0/ssp1status() functions * in your board-specific logic. These functions will perform chip selection * and status operations using GPIOs in the way your board is configured. - * 3. Add a calls to up_spiinitialize() in your low level application + * 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide + * lpc17_spi/ssp0/ssp1cmddata() functions in your board-specific logic. These + * functions 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 * initialization logic * 4. The handle returned by up_spiinitialize() may then be used to bind the * SPI driver to higher level logic (e.g., calling @@ -585,14 +589,23 @@ enum spi_dev_e; #ifdef CONFIG_LPC17_SPI EXTERN void lpc17_spiselect(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); EXTERN uint8_t lpc17_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +#ifdef CONFIG_SPI_CMDDATA +EXTERN int lpc17_spicmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif #endif #ifdef CONFIG_LPC17_SSP0 EXTERN void lpc17_ssp0select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); EXTERN uint8_t lpc17_ssp0status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +#ifdef CONFIG_SPI_CMDDATA +EXTERN int lpc17_ssp0cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif #endif #ifdef CONFIG_LPC17_SSP1 EXTERN void lpc17_ssp1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); EXTERN uint8_t lpc17_ssp1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +#ifdef CONFIG_SPI_CMDDATA +EXTERN int lpc17_ssp1cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif #endif /**************************************************************************** diff --git a/arch/arm/src/lpc17xx/lpc17_spi.c b/arch/arm/src/lpc17xx/lpc17_spi.c index 0525879b90..e5cc2b3e3f 100755 --- a/arch/arm/src/lpc17xx/lpc17_spi.c +++ b/arch/arm/src/lpc17xx/lpc17_spi.c @@ -147,6 +147,9 @@ static const struct spi_ops_s g_spiops = .setmode = spi_setmode, .setbits = spi_setbits, .status = lpc17_spistatus, +#ifdef CONFIG_SPI_CMDDATA + .cmddata = lpc17_spicmddata, +#endif .send = spi_send, .sndblock = spi_sndblock, .recvblock = spi_recvblock, diff --git a/arch/arm/src/lpc17xx/lpc17_ssp.c b/arch/arm/src/lpc17xx/lpc17_ssp.c index e0331f09ea..4512cbd285 100755 --- a/arch/arm/src/lpc17xx/lpc17_ssp.c +++ b/arch/arm/src/lpc17xx/lpc17_ssp.c @@ -171,6 +171,9 @@ static const struct spi_ops_s g_spi0ops = .setmode = ssp_setmode, .setbits = ssp_setbits, .status = lpc17_ssp0status, +#ifdef CONFIG_SPI_CMDDATA + .cmddata = lpc17_ssp0cmddata, +#endif .send = ssp_send, .sndblock = ssp_sndblock, .recvblock = ssp_recvblock, @@ -198,6 +201,9 @@ static const struct spi_ops_s g_spi1ops = .setmode = ssp_setmode, .setbits = ssp_setbits, .status = lpc17_ssp1status, +#ifdef CONFIG_SPI_CMDDATA + .cmddata = lpc17_ssp1cmddata, +#endif .send = ssp_send, .sndblock = ssp_sndblock, .recvblock = ssp_recvblock, diff --git a/arch/arm/src/lpc313x/lpc313x_internal.h b/arch/arm/src/lpc313x/lpc313x_internal.h index ab8e3caf9a..6fdbe9b377 100755 --- a/arch/arm/src/lpc313x/lpc313x_internal.h +++ b/arch/arm/src/lpc313x/lpc313x_internal.h @@ -173,21 +173,25 @@ EXTERN void lpc313x_clockconfig(void); * Name: lpc313x_spiselect and lpc313x_spistatus * * Description: - * The external functions, lpc313x_spiselect and lpc313x_spistatus must be - * provided by board-specific logic. They are implementations of the select - * and status methods of the SPI interface defined by struct spi_ops_s (see - * include/nuttx/spi.h). All other methods (including up_spiinitialize()) - * are provided by common LPC313X logic. To use this common SPI logic on your - * board: + * The external functions, lpc313x_spiselect, lpc313x_spistatus, and + * lpc313x_spicmddata must be provided by board-specific logic. These are + * implementations of the select, status, and cmddata methods of the SPI interface + * defined by struct spi_ops_s (see include/nuttx/spi.h). All other methods + * (including up_spiinitialize()) are provided by common LPC313X logic. To use + * this common SPI logic on your board: * * 1. Provide logic in lpc313x_boardinitialize() to configure SPI chip select * pins. * 2. Provide lpc313x_spiselect() and lpc313x_spistatus() functions in your * board-specific logic. These functions will perform chip selection and * status operations using GPIOs in the way your board is configured. - * 3. Add a calls to up_spiinitialize() in your low level application + * 3. If CONFIG_SPI_CMDDATA is selected in your NuttX configuration, provide + * the lpc313x_spicmddata() function in your board-specific logic. This + * function will perform cmd/data selection operations using GPIOs in the + * way your board is configured. + * 4. Add a calls to up_spiinitialize() in your low level application * initialization logic - * 4. The handle returned by up_spiinitialize() may then be used to bind the + * 5. The handle returned by up_spiinitialize() may then be used to bind the * SPI driver to higher level logic (e.g., calling * mmcsd_spislotinitialize(), for example, will bind the SPI driver to * the SPI MMC/SD driver). @@ -198,6 +202,9 @@ struct spi_dev_s; enum spi_dev_e; EXTERN void lpc313x_spiselect(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); EXTERN uint8_t lpc313x_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +#ifdef CONFIG_SPI_CMDDATA +EXTERN int lpc313x_spicmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif /************************************************************************************ * Name: lpc313x_usbpullup diff --git a/arch/arm/src/lpc313x/lpc313x_spi.c b/arch/arm/src/lpc313x/lpc313x_spi.c index a089c5543c..af4c9ce09e 100644 --- a/arch/arm/src/lpc313x/lpc313x_spi.c +++ b/arch/arm/src/lpc313x/lpc313x_spi.c @@ -145,6 +145,9 @@ static const struct spi_ops_s g_spiops = .setmode = spi_setmode, .setbits = spi_setbits, .status = spi_status, +#ifdef CONFIG_SPI_CMDDATA + .cmddata = lpc313x_spicmddata, +#endif .send = spi_send, #ifdef CONFIG_SPI_EXCHANGE .exchange = spi_exchange, diff --git a/arch/arm/src/stm32/stm32_internal.h b/arch/arm/src/stm32/stm32_internal.h index d7e40ba63e..9c13f04ef2 100755 --- a/arch/arm/src/stm32/stm32_internal.h +++ b/arch/arm/src/stm32/stm32_internal.h @@ -1,7 +1,7 @@ /************************************************************************************ * arch/arm/src/stm32/stm32_internal.h * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -445,21 +445,25 @@ EXTERN int stm32_ethinitialize(int intf); * Name: stm32_spi1/2/3select and stm32_spi1/2/3status * * Description: - * The external functions, stm32_spi1/2/3select and stm32_spi1/2/3status must be - * provided by board-specific logic. They are implementations of the select - * and status methods of the SPI interface defined by struct spi_ops_s (see - * include/nuttx/spi.h). All other methods (including up_spiinitialize()) - * are provided by common STM32 logic. To use this common SPI logic on your - * board: + * The external functions, stm32_spi1/2/3select, stm32_spi1/2/3status, and + * stm32_spi1/2/3cmddata must be provided by board-specific logic. These are + * implementations of the select, status, and cmddata methods of the SPI interface + * defined by struct spi_ops_s (see include/nuttx/spi.h). All other methods + * (including up_spiinitialize()) are provided by common STM32 logic. To use this + * common SPI logic on your board: * * 1. Provide logic in stm32_boardinitialize() to configure SPI chip select * pins. * 2. Provide stm32_spi1/2/3select() and stm32_spi1/2/3status() functions in your * board-specific logic. These functions will perform chip selection and * status operations using GPIOs in the way your board is configured. - * 3. Add a calls to up_spiinitialize() in your low level application + * 3. If CONFIG_SPI_CMDDATA is defined in your NuttX configuration file, then + * provide stm32_spi1/2/3cmddata() functions in your board-specific logic. + * These functions will perform cmd/data selection operations using GPIOs in the + * way your board is configured. + * 4. Add a calls to up_spiinitialize() in your low level application * initialization logic - * 4. The handle returned by up_spiinitialize() may then be used to bind the + * 5. The handle returned by up_spiinitialize() may then be used to bind the * SPI driver to higher level logic (e.g., calling * mmcsd_spislotinitialize(), for example, will bind the SPI driver to * the SPI MMC/SD driver). @@ -470,10 +474,13 @@ struct spi_dev_s; enum spi_dev_e; EXTERN void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); EXTERN uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +EXTERN int stm32_spi1cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); EXTERN void stm32_spi2select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); EXTERN uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +EXTERN int stm32_spi2cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); EXTERN void stm32_spi3select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); EXTERN uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +EXTERN int stm32_spi3cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); /************************************************************************************ * Name: stm32_usbpullup diff --git a/arch/arm/src/stm32/stm32_spi.c b/arch/arm/src/stm32/stm32_spi.c index 4605f8a306..5e28ee8792 100755 --- a/arch/arm/src/stm32/stm32_spi.c +++ b/arch/arm/src/stm32/stm32_spi.c @@ -209,6 +209,9 @@ static const struct spi_ops_s g_sp1iops = .setmode = spi_setmode, .setbits = spi_setbits, .status = stm32_spi1status, +#ifdef CONFIG_SPI_CMDDATA + .cmddata = stm32_spi1cmddata, +#endif .send = spi_send, #ifdef CONFIG_SPI_EXCHANGE .exchange = spi_exchange, @@ -245,6 +248,9 @@ static const struct spi_ops_s g_sp2iops = .setmode = spi_setmode, .setbits = spi_setbits, .status = stm32_spi2status, +#ifdef CONFIG_SPI_CMDDATA + .cmddata = stm32_spi2cmddata, +#endif .send = spi_send, #ifdef CONFIG_SPI_EXCHANGE .exchange = spi_exchange, @@ -281,6 +287,9 @@ static const struct spi_ops_s g_sp3iops = .setmode = spi_setmode, .setbits = spi_setbits, .status = stm32_spi3status, +#ifdef CONFIG_SPI_CMDDATA + .cmddata = stm32_spi3cmddata, +#endif .send = spi_send, #ifdef CONFIG_SPI_EXCHANGE .exchange = spi_exchange, diff --git a/arch/z80/src/ez80/ez80_spi.c b/arch/z80/src/ez80/ez80_spi.c index d701d55484..0c238f663e 100755 --- a/arch/z80/src/ez80/ez80_spi.c +++ b/arch/z80/src/ez80/ez80_spi.c @@ -94,6 +94,9 @@ static const struct spi_ops_s g_spiops = spi_setmode, NULL, /* Variable number of bits not implemented */ ez80_spistatus, /* Provided externally by board logic */ +#ifdef CONFIG_SPI_CMDDATA + ez80_spicmddata, +#endif spi_send, spi_sndblock, spi_recvblock, diff --git a/arch/z80/src/ez80/ez80f91_spi.h b/arch/z80/src/ez80/ez80f91_spi.h index 9e697cbbea..e27df2693a 100644 --- a/arch/z80/src/ez80/ez80f91_spi.h +++ b/arch/z80/src/ez80/ez80f91_spi.h @@ -2,7 +2,7 @@ * arch/z80/src/ez80/ez80f91_spi.h * arch/z80/src/chip/ez80f91_spi.h * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -99,23 +99,28 @@ extern "C" { * Public Functions ************************************************************************************/ -/* The external functions, ez80_spiselect and ez80_spistatus must be provided by - * board-specific logic. The are implementations of the select and status methods - * SPI interface defined by struct spi_ops_s (see include/nuttx/spi.h). All other - * methods (including up_spiinitialize()) are provided by common logic. To use this - * common SPI logic on your board: +/* The external functions, ez80_spiselect, ez80_spistatus, ans ez80_spicmddata must + * be provided by board-specific logic. These are implementations of the select, + * status, and cmddata methods of the SPI interface defined by struct spi_ops_s (see + * include/nuttx/spi.h). All other methods (including up_spiinitialize()) are + * provided by common logic. To use this common SPI logic on your board: * * 1. Provide ez80_spiselect() and ez80_spistatus() functions in your board-specific * logic. This function will perform chip selection and status operations using * GPIOs in the way your board is configured. - * 2. Add a call to up_spiinitialize() in your low level initialization logic - * 3. The handle returned by up_spiinitialize() may then be used to bind the + * 2. If CONFIG_SPI_CMDDATA is defined in your NuttX configuration, provide the + * ez80_spiscmddata() function 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 initialization logic + * 4. The handle returned by up_spiinitialize() may then be used to bind the * SPI driver to higher level logic (e.g., calling mmcsd_spislotinitialize(), * for example, will bind the SPI driver to the SPI MMC/SD driver). */ EXTERN void ez80_spiselect(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); EXTERN uint8_t ez80_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +EXTERN int ez80_spicmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); #undef EXTERN #ifdef __cplusplus diff --git a/configs/mcu123-lpc214x/src/up_spi.c b/configs/mcu123-lpc214x/src/up_spi.c index d8ae8baf8c..0c32fc6db2 100644 --- a/configs/mcu123-lpc214x/src/up_spi.c +++ b/configs/mcu123-lpc214x/src/up_spi.c @@ -129,6 +129,9 @@ static int spi_lock(FAR struct spi_dev_s *dev, bool lock); static void spi_select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev, uint32_t frequency); static uint8_t spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +#ifdef CONFIG_SPI_CMDDATA +static int spi_cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif static uint16_t spi_send(FAR struct spi_dev_s *dev, uint16_t ch); static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer, size_t nwords); static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer, size_t nwords); @@ -145,6 +148,9 @@ static const struct spi_ops_s g_spiops = .select = spi_select, .setfrequency = spi_setfrequency, .status = spi_status, +#ifdef CONFIG_SPI_CMDDATA + .cmddata = spi_cmddata, +#endif .send = spi_send, .sndblock = spi_sndblock, .recvblock = spi_recvblock, @@ -310,6 +316,38 @@ static uint8_t spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) return SPI_STATUS_PRESENT; } +/**************************************************************************** + * Name: spi_cmddata + * + * Description: + * Some devices require and additional out-of-band bit to specify if the + * next word sent to the device is a command or data. This is typical, for + * example, in "9-bit" displays where the 9th bit is the CMD/DATA bit. + * This function provides selection of command or data. + * + * This "latches" the CMD/DATA state. It does not have to be called before + * every word is transferred; only when the CMD/DATA state changes. This + * method is required if CONFIG_SPI_CMDDATA is selected in the NuttX + * configuration + * + * Input Parameters: + * dev - Device-specific state data + * cmd - TRUE: The following word is a command; FALSE: the following words + * are data. + * + * Returned Value: + * OK unless an error occurs. Then a negated errno value is returned + * + ****************************************************************************/ + + #ifdef CONFIG_SPI_CMDDATA +static int spi_cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd) +{ +# error "spi_cmddata not implemented" + return -ENOSYS; +} +#endif + /**************************************************************************** * Name: spi_send * diff --git a/configs/olimex-strp711/src/up_spi.c b/configs/olimex-strp711/src/up_spi.c index 5ca35b72e6..bbd046df70 100644 --- a/configs/olimex-strp711/src/up_spi.c +++ b/configs/olimex-strp711/src/up_spi.c @@ -396,6 +396,9 @@ static int spi_lock(FAR struct spi_dev_s *dev, bool lock); static void spi_select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev, uint32_t frequency); static uint8_t spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +#ifdef CONFIG_SPI_CMDDATA +static int spi_cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif static uint16_t spi_send(FAR struct spi_dev_s *dev, uint16_t wd); static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer, size_t buflen); static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer, size_t buflen); @@ -412,6 +415,9 @@ static const struct spi_ops_s g_spiops = .select = spi_select, .setfrequency = spi_setfrequency, .status = spi_status, +#ifdef CONFIG_SPI_CMDDATA + .cmddata = spi_cmddata, +#endif .send = spi_send, .sndblock = spi_sndblock, .recvblock = spi_recvblock, @@ -702,6 +708,38 @@ static uint8_t spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) return ret; } +/**************************************************************************** + * Name: spi_cmddata + * + * Description: + * Some devices require and additional out-of-band bit to specify if the + * next word sent to the device is a command or data. This is typical, for + * example, in "9-bit" displays where the 9th bit is the CMD/DATA bit. + * This function provides selection of command or data. + * + * This "latches" the CMD/DATA state. It does not have to be called before + * every word is transferred; only when the CMD/DATA state changes. This + * method is required if CONFIG_SPI_CMDDATA is selected in the NuttX + * configuration + * + * Input Parameters: + * dev - Device-specific state data + * cmd - TRUE: The following word is a command; FALSE: the following words + * are data. + * + * Returned Value: + * OK unless an error occurs. Then a negated errno value is returned + * + ****************************************************************************/ + + #ifdef CONFIG_SPI_CMDDATA +static int spi_cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd) +{ +# error "spi_cmddata not implemented" + return -ENOSYS; +} +#endif + /**************************************************************************** * Name: spi_send * diff --git a/include/nuttx/spi.h b/include/nuttx/spi.h index 12d9b0aee7..a29fd0a78a 100644 --- a/include/nuttx/spi.h +++ b/include/nuttx/spi.h @@ -187,6 +187,34 @@ #define SPI_STATUS_PRESENT 0x01 /* Bit 0=1: MMC/SD card present */ #define SPI_STATUS_WRPROTECTED 0x02 /* Bit 1=1: MMC/SD card write protected */ +/**************************************************************************** + * Name: SPI_CMDDATA + * + * Description: + * Some devices require and additional out-of-band bit to specify if the + * next word sent to the device is a command or data. This is typical, for + * example, in "9-bit" displays where the 9th bit is the CMD/DATA bit. + * This function provides selection of command or data. + * + * This "latches" the CMD/DATA state. It does not have to be called before + * every word is transferred; only when the CMD/DATA state changes. This + * method is required if CONFIG_SPI_CMDDATA is selected in the NuttX + * configuration + * + * Input Parameters: + * dev - Device-specific state data + * cmd - TRUE: The following word is a command; FALSE: the following words + * are data. + * + * Returned Value: + * OK unless an error occurs. Then a negated errno value is returned + * + ****************************************************************************/ + +#ifndef CONFIG_SPI_CMDDATA +# define SPI_CMDDATA(d,id,cmd) ((d)->ops->cmddata(d,id,cmd)) +#endif + /**************************************************************************** * Name: SPI_SEND * @@ -348,6 +376,9 @@ struct spi_ops_s void (*setmode)(FAR struct spi_dev_s *dev, enum spi_mode_e mode); void (*setbits)(FAR struct spi_dev_s *dev, int nbits); uint8_t (*status)(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +#ifndef CONFIG_SPI_CMDDATA + int (*cmddata)(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif uint16_t (*send)(FAR struct spi_dev_s *dev, uint16_t wd); #ifdef CONFIG_SPI_EXCHANGE void (*exchange)(FAR struct spi_dev_s *dev, FAR const void *txbuffer,