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);
{
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;
}
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;
#define SPI_DEFAULT_WORDLEN 8
-/* TODO(sjg@chromium.org): Remove this and use max_hz from struct spi_slave */
+/**
+ * struct dm_spi_bus - SPI bus info
+ *
+ * This contains information about a SPI bus. To obtain this structure, use
+ * dev_get_uclass_priv(bus) where bus is the SPI bus udevice.
+ *
+ * @max_hz: Maximum speed that the bus can tolerate.
+ * @speed: Current bus speed. This is 0 until the bus is first claimed.
+ * @mode: Current bus mode. This is 0 until the bus is first claimed.
+ *
+ * TODO(sjg@chromium.org): Remove this and use max_hz from struct spi_slave.
+ */
struct dm_spi_bus {
uint max_hz;
+ uint speed;
+ uint mode;
};
/**
*
* @dev: SPI slave device
* @max_hz: Maximum speed for this slave
- * @speed: Current bus speed. This is 0 until the bus is first
- * claimed.
* @bus: ID of the bus that the slave is attached to. For
* driver model this is the sequence number of the SPI
* bus (dev_seq(bus)) so does not need to be stored
#if CONFIG_IS_ENABLED(DM_SPI)
struct udevice *dev; /* struct spi_slave is dev->parentdata */
uint max_hz;
- uint speed;
#else
unsigned int bus;
unsigned int cs;