[PATCH 1/3] [raspberrypi] Fix chip select configuration in spi-driver

Jan Sommer soja-lists at aries.uberspace.de
Sun Jun 12 18:45:01 UTC 2016


Write the selected CS line to the CS-bits and not to the CSPOL-bits (which only switch the polarity of a CS line)
---
 c/src/lib/libbsp/arm/raspberrypi/spi/spi.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/c/src/lib/libbsp/arm/raspberrypi/spi/spi.c b/c/src/lib/libbsp/arm/raspberrypi/spi/spi.c
index ae77f62..c595ca1 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/spi/spi.c
+++ b/c/src/lib/libbsp/arm/raspberrypi/spi/spi.c
@@ -493,18 +493,9 @@ static rtems_status_code rpi_libi2c_spi_stop(rtems_libi2c_bus_t * bushdl)
 
   /* Set SPI transfer as not active. */
   BCM2835_REG(BCM2835_SPI_CS) &= ~(1 << 7);
-
-  /* Unselect the active SPI slave. */
-  switch ( addr ) {
-    case 0:
-    case 1:
-      BCM2835_REG(BCM2835_SPI_CS) |= (1 << chip_select_bit);
-
-      break;
-
-    default:
-      return RTEMS_INVALID_ADDRESS;
-  }
+  
+  /* Deselect CS line */
+  BCM2835_REG(BCM2835_SPI_CS) &= 3;
 
   return RTEMS_SUCCESSFUL;
 }
@@ -528,10 +519,6 @@ static rtems_status_code rpi_libi2c_spi_send_addr(
 ) {
   rpi_spi_softc_t *softc_ptr = &(((rpi_spi_desc_t *)(bushdl))->softc);
 
-  /* Calculates the bit corresponding to the received address
-   * on the SPI control register. */
-  uint32_t chip_select_bit = 21 + addr;
-
   /* Save which slave will be currently addressed,
    * so it can be unselected later. */
   softc_ptr->current_slave_addr = addr;
@@ -540,7 +527,8 @@ static rtems_status_code rpi_libi2c_spi_send_addr(
   switch ( addr ) {
     case 0:
     case 1:
-      BCM2835_REG(BCM2835_SPI_CS) &= ~(1 << chip_select_bit);
+        /* Clear the last 2 bits (CS) and set them to addr */
+        BCM2835_REG(BCM2835_SPI_CS) = (BCM2835_REG(BCM2835_SPI_CS) & (~3) ) | addr;
       break;
 
     default:
-- 
2.7.4



More information about the devel mailing list