]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/spi/kirkwood_spi.c
Merge branch 'u-boot-marvell/master' into 'u-boot-arm/master'
[karo-tx-uboot.git] / drivers / spi / kirkwood_spi.c
index de81064b9defbff63f15b2975f5271d976e2a1ee..3d58bcc1b955d140b8dc4a3937eba4db59dc6d35 100644 (file)
@@ -5,23 +5,7 @@
  *
  * Derived from drivers/spi/mpc8xxx_spi.c
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -34,7 +18,7 @@
 
 static struct kwspi_registers *spireg = (struct kwspi_registers *)KW_SPI_BASE;
 
-u32 cs_spi_mpp_back[2];
+static u32 cs_spi_mpp_back[2];
 
 struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
                                unsigned int max_hz, unsigned int mode)
@@ -49,14 +33,11 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
        if (!spi_cs_is_valid(bus, cs))
                return NULL;
 
-       slave = malloc(sizeof(struct spi_slave));
+       slave = spi_alloc_slave_base(bus, cs);
        if (!slave)
                return NULL;
 
-       slave->bus = bus;
-       slave->cs = cs;
-
-       writel(~KWSPI_CSN_ACT | KWSPI_SMEMRDY, &spireg->ctrl);
+       writel(KWSPI_SMEMRDY, &spireg->ctrl);
 
        /* calculate spi clock prescaller using max_hz */
        data = ((CONFIG_SYS_TCLK / 2) / max_hz) + 0x10;
@@ -65,7 +46,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 
        /* program spi clock prescaller using max_hz */
        writel(KWSPI_ADRLEN_3BYTE | data, &spireg->cfg);
-       debug("data = 0x%08x \n", data);
+       debug("data = 0x%08x\n", data);
 
        writel(KWSPI_SMEMRDIRQ, &spireg->irq_cause);
        writel(KWSPI_IRQMASK, &spireg->irq_mask);
@@ -119,7 +100,6 @@ int spi_claim_bus(struct spi_slave *slave)
 
        /* set new spi mpp and save current mpp config */
        kirkwood_mpp_conf(spi_mpp_config, spi_mpp_backup);
-
 #endif
 
        return board_spi_claim_bus(slave);
@@ -146,7 +126,7 @@ void spi_release_bus(struct spi_slave *slave)
  */
 int spi_cs_is_valid(unsigned int bus, unsigned int cs)
 {
-       return (bus == 0 && (cs == 0 || cs == 1));
+       return bus == 0 && (cs == 0 || cs == 1);
 }
 #endif
 
@@ -156,12 +136,12 @@ void spi_init(void)
 
 void spi_cs_activate(struct spi_slave *slave)
 {
-       writel(readl(&spireg->ctrl) | KWSPI_IRQUNMASK, &spireg->ctrl);
+       setbits_le32(&spireg->ctrl, KWSPI_CSN_ACT);
 }
 
 void spi_cs_deactivate(struct spi_slave *slave)
 {
-       writel(readl(&spireg->ctrl) & KWSPI_IRQMASK, &spireg->ctrl);
+       clrbits_le32(&spireg->ctrl, KWSPI_CSN_ACT);
 }
 
 int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
@@ -180,8 +160,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
         * handle data in 8-bit chunks
         * TBD: 2byte xfer mode to be enabled
         */
-       writel(((readl(&spireg->cfg) & ~KWSPI_XFERLEN_MASK) |
-               KWSPI_XFERLEN_1BYTE), &spireg->cfg);
+       clrsetbits_le32(&spireg->cfg, KWSPI_XFERLEN_MASK, KWSPI_XFERLEN_1BYTE);
 
        while (bitlen > 4) {
                debug("loopstart bitlen %d\n", bitlen);
@@ -189,9 +168,9 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 
                /* Shift data so it's msb-justified */
                if (dout)
-                       tmpdout = *(u32 *) dout & 0x0ff;
+                       tmpdout = *(u32 *)dout & 0xff;
 
-               writel(~KWSPI_SMEMRDIRQ, &spireg->irq_cause);
+               clrbits_le32(&spireg->irq_cause, KWSPI_SMEMRDIRQ);
                writel(tmpdout, &spireg->dout); /* Write the data out */
                debug("*** spi_xfer: ... %08x written, bitlen %d\n",
                      tmpdout, bitlen);
@@ -205,12 +184,11 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
                        if (readl(&spireg->irq_cause) & KWSPI_SMEMRDIRQ) {
                                isread = 1;
                                tmpdin = readl(&spireg->din);
-                               debug
-                                       ("spi_xfer: din %p..%08x read\n",
-                                       din, tmpdin);
+                               debug("spi_xfer: din %p..%08x read\n",
+                                     din, tmpdin);
 
                                if (din) {
-                                       *((u8 *) din) = (u8) tmpdin;
+                                       *((u8 *)din) = (u8)tmpdin;
                                        din += 1;
                                }
                                if (dout)