diff options
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/altera_spi.c | 2 | ||||
-rw-r--r-- | drivers/spi/cf_spi.c | 12 | ||||
-rw-r--r-- | drivers/spi/fsl_dspi.c | 8 | ||||
-rw-r--r-- | drivers/spi/fsl_espi.c | 2 | ||||
-rw-r--r-- | drivers/spi/octeon_spi.c | 2 | ||||
-rw-r--r-- | drivers/spi/pic32_spi.c | 4 | ||||
-rw-r--r-- | drivers/spi/rk_spi.c | 1 | ||||
-rw-r--r-- | drivers/spi/sandbox_spi.c | 60 | ||||
-rw-r--r-- | drivers/spi/spi-uclass.c | 22 | ||||
-rw-r--r-- | drivers/spi/tegra114_spi.c | 2 | ||||
-rw-r--r-- | drivers/spi/tegra20_sflash.c | 2 | ||||
-rw-r--r-- | drivers/spi/tegra20_slink.c | 2 | ||||
-rw-r--r-- | drivers/spi/tegra210_qspi.c | 2 | ||||
-rw-r--r-- | drivers/spi/xilinx_spi.c | 2 | ||||
-rw-r--r-- | drivers/spi/zynq_qspi.c | 2 | ||||
-rw-r--r-- | drivers/spi/zynq_spi.c | 2 |
16 files changed, 78 insertions, 49 deletions
diff --git a/drivers/spi/altera_spi.c b/drivers/spi/altera_spi.c index fd01c8e..fadc9f3 100644 --- a/drivers/spi/altera_spi.c +++ b/drivers/spi/altera_spi.c @@ -98,7 +98,7 @@ static int altera_spi_xfer(struct udevice *dev, unsigned int bitlen, uint32_t reg, data, start; debug("%s: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n", __func__, - bus->seq, slave_plat->cs, bitlen, bytes, flags); + dev_seq(bus), slave_plat->cs, bitlen, bytes, flags); if (bitlen == 0) goto done; diff --git a/drivers/spi/cf_spi.c b/drivers/spi/cf_spi.c index cc934d1..8adff63 100644 --- a/drivers/spi/cf_spi.c +++ b/drivers/spi/cf_spi.c @@ -240,7 +240,7 @@ static int coldfire_spi_set_speed(struct udevice *bus, uint max_hz) cfspi->baudrate = max_hz; /* Read current setup */ - bus_setup = readl(&dspi->ctar[bus->seq]); + bus_setup = readl(&dspi->ctar[dev_seq(bus)]); tmp = (prescaler[3] * scaler[15]); /* Maximum and minimum baudrate it can handle */ @@ -294,7 +294,7 @@ static int coldfire_spi_set_speed(struct udevice *bus, uint max_hz) bus_setup &= ~(DSPI_CTAR_PBR(0x03) | DSPI_CTAR_BR(0x0f)); bus_setup |= (DSPI_CTAR_PBR(best_i) | DSPI_CTAR_BR(best_j)); - writel(bus_setup, &dspi->ctar[bus->seq]); + writel(bus_setup, &dspi->ctar[dev_seq(bus)]); return 0; } @@ -318,7 +318,7 @@ static int coldfire_spi_set_mode(struct udevice *bus, uint mode) if (cfspi->mode & SPI_MODE_MOD) { if ((cfspi->mode & SPI_MODE_XFER_SZ_MASK) == 0) bus_setup |= - readl(&dspi->ctar[bus->seq]) & MCF_FRM_SZ_16BIT; + readl(&dspi->ctar[dev_seq(bus)]) & MCF_FRM_SZ_16BIT; else bus_setup |= ((cfspi->mode & SPI_MODE_XFER_SZ_MASK) >> 1); @@ -329,14 +329,14 @@ static int coldfire_spi_set_mode(struct udevice *bus, uint mode) bus_setup |= (cfspi->mode & SPI_MODE_DLY_SCA_MASK) >> 4; } else { bus_setup |= - (readl(&dspi->ctar[bus->seq]) & MCF_CTAR_MODE_MASK); + (readl(&dspi->ctar[dev_seq(bus)]) & MCF_CTAR_MODE_MASK); } cfspi->charbit = - ((readl(&dspi->ctar[bus->seq]) & MCF_FRM_SZ_16BIT) == + ((readl(&dspi->ctar[dev_seq(bus)]) & MCF_FRM_SZ_16BIT) == MCF_FRM_SZ_16BIT) ? 16 : 8; - setbits_be32(&dspi->ctar[bus->seq], bus_setup); + setbits_be32(&dspi->ctar[dev_seq(bus)], bus_setup); return 0; } diff --git a/drivers/spi/fsl_dspi.c b/drivers/spi/fsl_dspi.c index fcaf2ba..ddf4a9e 100644 --- a/drivers/spi/fsl_dspi.c +++ b/drivers/spi/fsl_dspi.c @@ -511,7 +511,7 @@ static int fsl_dspi_probe(struct udevice *bus) DSPI_MCR_CRXF | DSPI_MCR_CTXF; fsl_dspi_init_mcr(priv, mcr_cfg_val); - debug("%s probe done, bus-num %d.\n", bus->name, bus->seq); + debug("%s probe done, bus-num %d.\n", bus->name, dev_seq(bus)); return 0; } @@ -527,7 +527,7 @@ static int fsl_dspi_claim_bus(struct udevice *dev) priv = dev_get_priv(bus); /* processor special preparation work */ - cpu_dspi_claim_bus(bus->seq, slave_plat->cs); + cpu_dspi_claim_bus(dev_seq(bus), slave_plat->cs); /* configure transfer mode */ fsl_dspi_cfg_ctar_mode(priv, slave_plat->cs, priv->mode); @@ -559,7 +559,7 @@ static int fsl_dspi_release_bus(struct udevice *dev) dspi_halt(priv, 1); /* processor special release work */ - cpu_dspi_release_bus(bus->seq, slave_plat->cs); + cpu_dspi_release_bus(dev_seq(bus), slave_plat->cs); return 0; } @@ -569,7 +569,7 @@ static int fsl_dspi_release_bus(struct udevice *dev) */ static int fsl_dspi_bind(struct udevice *bus) { - debug("%s assigned req_seq %d.\n", bus->name, bus->req_seq); + debug("%s assigned seq %d.\n", bus->name, dev_seq(bus)); return 0; } diff --git a/drivers/spi/fsl_espi.c b/drivers/spi/fsl_espi.c index 8545461..e9e7ffd 100644 --- a/drivers/spi/fsl_espi.c +++ b/drivers/spi/fsl_espi.c @@ -527,7 +527,7 @@ static int fsl_espi_probe(struct udevice *bus) fsl->max_transfer_length = ESPI_MAX_DATA_TRANSFER_LEN; fsl->speed_hz = plat->speed_hz; - debug("%s probe done, bus-num %d.\n", bus->name, bus->seq); + debug("%s probe done, bus-num %d.\n", bus->name, dev_seq(bus)); return 0; } diff --git a/drivers/spi/octeon_spi.c b/drivers/spi/octeon_spi.c index 6e02a99..6ac66d2 100644 --- a/drivers/spi/octeon_spi.c +++ b/drivers/spi/octeon_spi.c @@ -593,7 +593,7 @@ static int octeon_spi_probe(struct udevice *dev) if (ret) return ret; - debug("SPI bus %s %d at %p\n", dev->name, dev->seq, priv->base); + debug("SPI bus %s %d at %p\n", dev->name, dev_seq(dev), priv->base); return 0; } diff --git a/drivers/spi/pic32_spi.c b/drivers/spi/pic32_spi.c index cd83c11..34d7d3e 100644 --- a/drivers/spi/pic32_spi.c +++ b/drivers/spi/pic32_spi.c @@ -247,7 +247,7 @@ static int pic32_spi_xfer(struct udevice *slave, unsigned int bitlen, slave_plat = dev_get_parent_plat(slave); debug("spi_xfer: bus:%i cs:%i flags:%lx\n", - bus->seq, slave_plat->cs, flags); + dev_seq(bus), slave_plat->cs, flags); debug("msg tx %p, rx %p submitted of %d byte(s)\n", tx_buf, rx_buf, len); @@ -384,7 +384,7 @@ static int pic32_spi_probe(struct udevice *bus) fdt_size_t size; int ret; - debug("%s: %d, bus: %i\n", __func__, __LINE__, bus->seq); + debug("%s: %d, bus: %i\n", __func__, __LINE__, dev_seq(bus)); addr = fdtdec_get_addr_size(gd->fdt_blob, node, "reg", &size); if (addr == FDT_ADDR_T_NONE) return -EINVAL; diff --git a/drivers/spi/rk_spi.c b/drivers/spi/rk_spi.c index 64bb257..44ac475 100644 --- a/drivers/spi/rk_spi.c +++ b/drivers/spi/rk_spi.c @@ -186,7 +186,6 @@ static int conv_of_plat(struct udevice *dev) ret = clk_get_by_driver_info(dev, dtplat->clocks, &priv->clk); if (ret < 0) return ret; - dev->req_seq = 0; return 0; } diff --git a/drivers/spi/sandbox_spi.c b/drivers/spi/sandbox_spi.c index 755f176..0564d8b 100644 --- a/drivers/spi/sandbox_spi.c +++ b/drivers/spi/sandbox_spi.c @@ -28,21 +28,22 @@ # define CONFIG_SPI_IDLE_VAL 0xFF #endif -const char *sandbox_spi_parse_spec(const char *arg, unsigned long *bus, - unsigned long *cs) -{ - char *endp; - - *bus = simple_strtoul(arg, &endp, 0); - if (*endp != ':' || *bus >= CONFIG_SANDBOX_SPI_MAX_BUS) - return NULL; - - *cs = simple_strtoul(endp + 1, &endp, 0); - if (*endp != ':' || *cs >= CONFIG_SANDBOX_SPI_MAX_CS) - return NULL; - - return endp + 1; -} +/** + * struct sandbox_spi_priv - Sandbox SPI private data + * + * Helper struct to keep track of the sandbox SPI bus internal state. It is + * used in unit tests to verify that dm spi functions update the bus + * speed/mode properly (for instance, when jumping back and forth between spi + * slaves claiming the bus, we need to make sure that the bus speed is updated + * accordingly for each slave). + * + * @speed: Current bus speed. + * @mode: Current bus mode. + */ +struct sandbox_spi_priv { + uint speed; + uint mode; +}; __weak int sandbox_spi_get_emul(struct sandbox_state *state, struct udevice *bus, struct udevice *slave, @@ -51,6 +52,20 @@ __weak int sandbox_spi_get_emul(struct sandbox_state *state, return -ENOENT; } +uint sandbox_spi_get_speed(struct udevice *dev) +{ + struct sandbox_spi_priv *priv = dev_get_priv(dev); + + return priv->speed; +} + +uint sandbox_spi_get_mode(struct udevice *dev) +{ + struct sandbox_spi_priv *priv = dev_get_priv(dev); + + return priv->mode; +} + static int sandbox_spi_xfer(struct udevice *slave, unsigned int bitlen, const void *dout, void *din, unsigned long flags) { @@ -72,7 +87,7 @@ static int sandbox_spi_xfer(struct udevice *slave, unsigned int bitlen, return -EINVAL; } - busnum = bus->seq; + busnum = dev_seq(bus); cs = spi_chip_select(slave); if (busnum >= CONFIG_SANDBOX_SPI_MAX_BUS || cs >= CONFIG_SANDBOX_SPI_MAX_CS) { @@ -106,19 +121,27 @@ static int sandbox_spi_xfer(struct udevice *slave, unsigned int bitlen, static int sandbox_spi_set_speed(struct udevice *bus, uint speed) { + struct sandbox_spi_priv *priv = dev_get_priv(bus); + + priv->speed = speed; + return 0; } static int sandbox_spi_set_mode(struct udevice *bus, uint mode) { + struct sandbox_spi_priv *priv = dev_get_priv(bus); + + priv->mode = mode; + return 0; } static int sandbox_cs_info(struct udevice *bus, uint cs, struct spi_cs_info *info) { - /* Always allow activity on CS 0 */ - if (cs >= 1) + /* Always allow activity on CS 0, CS 1 */ + if (cs >= 2) return -EINVAL; return 0; @@ -152,4 +175,5 @@ U_BOOT_DRIVER(sandbox_spi) = { .id = UCLASS_SPI, .of_match = sandbox_spi_ids, .ops = &sandbox_spi_ops, + .priv_auto = sizeof(struct sandbox_spi_priv), }; diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index 9dd32ab..a392a93 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -51,23 +51,28 @@ int dm_spi_claim_bus(struct udevice *dev) struct dm_spi_ops *ops = spi_get_ops(bus); struct dm_spi_bus *spi = dev_get_uclass_priv(bus); struct spi_slave *slave = dev_get_parent_priv(dev); - int speed; + uint speed, mode; speed = slave->max_hz; + mode = slave->mode; + if (spi->max_hz) { if (speed) - speed = min(speed, (int)spi->max_hz); + speed = min(speed, spi->max_hz); else speed = spi->max_hz; } if (!speed) speed = SPI_DEFAULT_SPEED_HZ; - if (speed != slave->speed) { + + if (speed != spi->speed || mode != spi->mode) { int ret = spi_set_speed_mode(bus, speed, slave->mode); if (ret) return log_ret(ret); - slave->speed = speed; + + spi->speed = speed; + spi->mode = mode; } return log_ret(ops->claim_bus ? ops->claim_bus(dev) : 0); @@ -273,7 +278,7 @@ int spi_cs_is_valid(unsigned int busnum, unsigned int cs) struct udevice *bus; int ret; - ret = uclass_find_device_by_seq(UCLASS_SPI, busnum, false, &bus); + ret = uclass_find_device_by_seq(UCLASS_SPI, busnum, &bus); if (ret) { debug("%s: No bus %d\n", __func__, busnum); return ret; @@ -302,7 +307,7 @@ int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp, struct udevice *bus, *dev; int ret; - ret = uclass_find_device_by_seq(UCLASS_SPI, busnum, false, &bus); + ret = uclass_find_device_by_seq(UCLASS_SPI, busnum, &bus); if (ret) { debug("%s: No bus %d\n", __func__, busnum); return ret; @@ -324,6 +329,7 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, { struct udevice *bus, *dev; struct dm_spi_slave_plat *plat; + struct dm_spi_bus *bus_data; struct spi_slave *slave; bool created = false; int ret; @@ -381,12 +387,13 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, } slave = dev_get_parent_priv(dev); + bus_data = dev_get_uclass_priv(bus); /* * In case the operation speed is not yet established by * dm_spi_claim_bus() ensure the bus is configured properly. */ - if (!slave->speed) { + if (!bus_data->speed) { ret = spi_claim_bus(slave); if (ret) goto err; @@ -428,7 +435,6 @@ struct spi_slave *spi_setup_slave(unsigned int busnum, unsigned int cs, void spi_free_slave(struct spi_slave *slave) { device_remove(slave->dev, DM_REMOVE_NORMAL); - slave->dev = NULL; } int spi_slave_of_to_plat(struct udevice *dev, struct dm_spi_slave_plat *plat) diff --git a/drivers/spi/tegra114_spi.c b/drivers/spi/tegra114_spi.c index 2bfa262..e1fd82b 100644 --- a/drivers/spi/tegra114_spi.c +++ b/drivers/spi/tegra114_spi.c @@ -231,7 +231,7 @@ static int tegra114_spi_xfer(struct udevice *dev, unsigned int bitlen, int ret; debug("%s: slave %u:%u dout %p din %p bitlen %u\n", - __func__, bus->seq, spi_chip_select(dev), dout, din, bitlen); + __func__, dev_seq(bus), spi_chip_select(dev), dout, din, bitlen); if (bitlen % 8) return -1; num_bytes = bitlen / 8; diff --git a/drivers/spi/tegra20_sflash.c b/drivers/spi/tegra20_sflash.c index ad19a4e..d386061 100644 --- a/drivers/spi/tegra20_sflash.c +++ b/drivers/spi/tegra20_sflash.c @@ -217,7 +217,7 @@ static int tegra20_sflash_xfer(struct udevice *dev, unsigned int bitlen, int ret; debug("%s: slave %u:%u dout %p din %p bitlen %u\n", - __func__, bus->seq, spi_chip_select(dev), dout, din, bitlen); + __func__, dev_seq(bus), spi_chip_select(dev), dout, din, bitlen); if (bitlen % 8) return -1; num_bytes = bitlen / 8; diff --git a/drivers/spi/tegra20_slink.c b/drivers/spi/tegra20_slink.c index 57994d2..b99ef38 100644 --- a/drivers/spi/tegra20_slink.c +++ b/drivers/spi/tegra20_slink.c @@ -211,7 +211,7 @@ static int tegra30_spi_xfer(struct udevice *dev, unsigned int bitlen, int ret; debug("%s: slave %u:%u dout %p din %p bitlen %u\n", - __func__, bus->seq, spi_chip_select(dev), dout, din, bitlen); + __func__, dev_seq(bus), spi_chip_select(dev), dout, din, bitlen); if (bitlen % 8) return -1; num_bytes = bitlen / 8; diff --git a/drivers/spi/tegra210_qspi.c b/drivers/spi/tegra210_qspi.c index 2baa2ce..a2a7f46 100644 --- a/drivers/spi/tegra210_qspi.c +++ b/drivers/spi/tegra210_qspi.c @@ -223,7 +223,7 @@ static int tegra210_qspi_xfer(struct udevice *dev, unsigned int bitlen, int num_bytes, tm, ret; debug("%s: slave %u:%u dout %p din %p bitlen %u\n", - __func__, bus->seq, spi_chip_select(dev), dout, din, bitlen); + __func__, dev_seq(bus), spi_chip_select(dev), dout, din, bitlen); if (bitlen % 8) return -1; num_bytes = bitlen / 8; diff --git a/drivers/spi/xilinx_spi.c b/drivers/spi/xilinx_spi.c index b32cdac..0274afd 100644 --- a/drivers/spi/xilinx_spi.c +++ b/drivers/spi/xilinx_spi.c @@ -255,7 +255,7 @@ static int xilinx_spi_xfer(struct udevice *dev, unsigned int bitlen, int ret; debug("spi_xfer: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n", - bus->seq, slave_plat->cs, bitlen, bytes, flags); + dev_seq(bus), slave_plat->cs, bitlen, bytes, flags); if (bitlen == 0) goto done; diff --git a/drivers/spi/zynq_qspi.c b/drivers/spi/zynq_qspi.c index c2ae4e9..2fc28b6 100644 --- a/drivers/spi/zynq_qspi.c +++ b/drivers/spi/zynq_qspi.c @@ -568,7 +568,7 @@ static int zynq_qspi_xfer(struct udevice *dev, unsigned int bitlen, priv->len = bitlen / 8; debug("zynq_qspi_xfer: bus:%i cs:%i bitlen:%i len:%i flags:%lx\n", - bus->seq, slave_plat->cs, bitlen, priv->len, flags); + dev_seq(bus), slave_plat->cs, bitlen, priv->len, flags); /* * Festering sore. diff --git a/drivers/spi/zynq_spi.c b/drivers/spi/zynq_spi.c index 281db45..a6efa4a 100644 --- a/drivers/spi/zynq_spi.c +++ b/drivers/spi/zynq_spi.c @@ -242,7 +242,7 @@ static int zynq_spi_xfer(struct udevice *dev, unsigned int bitlen, u32 ts, status; debug("spi_xfer: bus:%i cs:%i bitlen:%i len:%i flags:%lx\n", - bus->seq, slave_plat->cs, bitlen, len, flags); + dev_seq(bus), slave_plat->cs, bitlen, len, flags); if (bitlen % 8) { debug("spi_xfer: Non byte aligned SPI transfer\n"); |