spi: atmel_dataflash: Simplify AT91F_SpiEnable implementation
authorAxel Lin <axel.lin@ingics.com>
Fri, 21 Feb 2014 00:55:47 +0000 (08:55 +0800)
committerJagannadha Sutradharudu Teki <jaganna@xilinx.com>
Mon, 17 Mar 2014 16:24:57 +0000 (21:54 +0530)
Refactor the code a bit to make it better in readability.
Remove the comments because now the intention of the code is pretty clear.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jaganna@xilinx.com>
drivers/spi/atmel_dataflash_spi.c

index 8a5eddc..a2e9c00 100644 (file)
@@ -102,33 +102,26 @@ void AT91F_SpiEnable(int cs)
 {
        unsigned long mode;
 
 {
        unsigned long mode;
 
+       mode = readl(ATMEL_BASE_SPI0 + AT91_SPI_MR);
+       mode &= ~AT91_SPI_PCS;
+
        switch (cs) {
        switch (cs) {
-       case 0: /* Configure SPI CS0 for Serial DataFlash AT45DBxx */
-               mode = readl(ATMEL_BASE_SPI0 + AT91_SPI_MR);
-               mode &= 0xFFF0FFFF;
-               writel(mode | ((AT91_SPI_PCS0_DATAFLASH_CARD<<16) & AT91_SPI_PCS),
-                      ATMEL_BASE_SPI0 + AT91_SPI_MR);
+       case 0:
+               mode |= AT91_SPI_PCS0_DATAFLASH_CARD << 16;
                break;
                break;
-       case 1: /* Configure SPI CS1 for Serial DataFlash AT45DBxx */
-               mode = readl(ATMEL_BASE_SPI0 + AT91_SPI_MR);
-               mode &= 0xFFF0FFFF;
-               writel(mode | ((AT91_SPI_PCS1_DATAFLASH_CARD<<16) & AT91_SPI_PCS),
-                      ATMEL_BASE_SPI0 + AT91_SPI_MR);
+       case 1:
+               mode |= AT91_SPI_PCS1_DATAFLASH_CARD << 16;
                break;
                break;
-       case 2: /* Configure SPI CS2 for Serial DataFlash AT45DBxx */
-               mode = readl(ATMEL_BASE_SPI0 + AT91_SPI_MR);
-               mode &= 0xFFF0FFFF;
-               writel(mode | ((AT91_SPI_PCS2_DATAFLASH_CARD<<16) & AT91_SPI_PCS),
-                      ATMEL_BASE_SPI0 + AT91_SPI_MR);
+       case 2:
+               mode |= AT91_SPI_PCS2_DATAFLASH_CARD << 16;
                break;
        case 3:
                break;
        case 3:
-               mode = readl(ATMEL_BASE_SPI0 + AT91_SPI_MR);
-               mode &= 0xFFF0FFFF;
-               writel(mode | ((AT91_SPI_PCS3_DATAFLASH_CARD<<16) & AT91_SPI_PCS),
-                      ATMEL_BASE_SPI0 + AT91_SPI_MR);
+               mode |= AT91_SPI_PCS3_DATAFLASH_CARD << 16;
                break;
        }
 
                break;
        }
 
+       writel(mode, ATMEL_BASE_SPI0 + AT91_SPI_MR);
+
        /* SPI_Enable */
        writel(AT91_SPI_SPIEN, ATMEL_BASE_SPI0 + AT91_SPI_CR);
 }
        /* SPI_Enable */
        writel(AT91_SPI_SPIEN, ATMEL_BASE_SPI0 + AT91_SPI_CR);
 }