summaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-uclass.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi/spi-uclass.c')
-rw-r--r--drivers/spi/spi-uclass.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index d5a1e3a676..3fe351f8a7 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -54,23 +54,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);
@@ -158,12 +163,12 @@ int spi_write_then_read(struct spi_slave *slave, const u8 *opcode,
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static int spi_child_post_bind(struct udevice *dev)
{
- struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
+ struct dm_spi_slave_plat *plat = dev_get_parent_plat(dev);
- if (!dev_of_valid(dev))
+ if (!dev_has_ofnode(dev))
return 0;
- return spi_slave_ofdata_to_platdata(dev, plat);
+ return spi_slave_of_to_plat(dev, plat);
}
#endif
@@ -202,7 +207,7 @@ static int spi_post_probe(struct udevice *bus)
static int spi_child_pre_probe(struct udevice *dev)
{
- struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
+ struct dm_spi_slave_plat *plat = dev_get_parent_plat(dev);
struct spi_slave *slave = dev_get_parent_priv(dev);
/*
@@ -223,7 +228,7 @@ static int spi_child_pre_probe(struct udevice *dev)
int spi_chip_select(struct udevice *dev)
{
- struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
+ struct dm_spi_slave_plat *plat = dev_get_parent_plat(dev);
return plat ? plat->cs : -ENOENT;
}
@@ -259,9 +264,9 @@ int spi_find_chip_select(struct udevice *bus, int cs, struct udevice **devp)
for (device_find_first_child(bus, &dev); dev;
device_find_next_child(&dev)) {
- struct dm_spi_slave_platdata *plat;
+ struct dm_spi_slave_plat *plat;
- plat = dev_get_parent_platdata(dev);
+ plat = dev_get_parent_plat(dev);
dev_dbg(bus, "%s: plat=%p, cs=%d\n", __func__, plat, plat->cs);
if (plat->cs == cs) {
*devp = dev;
@@ -278,7 +283,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) {
log_debug("%s: No bus %d\n", __func__, busnum);
return ret;
@@ -307,7 +312,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) {
log_debug("%s: No bus %d\n", __func__, busnum);
return ret;
@@ -328,7 +333,8 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
struct udevice **busp, struct spi_slave **devp)
{
struct udevice *bus, *dev;
- struct dm_spi_slave_platdata *plat;
+ struct dm_spi_slave_plat *plat;
+ struct dm_spi_bus *bus_data;
struct spi_slave *slave;
bool created = false;
int ret;
@@ -358,7 +364,7 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
__func__, ret);
return ret;
}
- plat = dev_get_parent_platdata(dev);
+ plat = dev_get_parent_plat(dev);
plat->cs = cs;
if (speed) {
plat->max_hz = speed;
@@ -386,12 +392,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;
@@ -433,11 +440,9 @@ 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_ofdata_to_platdata(struct udevice *dev,
- struct dm_spi_slave_platdata *plat)
+int spi_slave_of_to_plat(struct udevice *dev, struct dm_spi_slave_plat *plat)
{
int mode = 0;
int value;
@@ -507,10 +512,9 @@ UCLASS_DRIVER(spi) = {
#endif
.post_probe = spi_post_probe,
.child_pre_probe = spi_child_pre_probe,
- .per_device_auto_alloc_size = sizeof(struct dm_spi_bus),
- .per_child_auto_alloc_size = sizeof(struct spi_slave),
- .per_child_platdata_auto_alloc_size =
- sizeof(struct dm_spi_slave_platdata),
+ .per_device_auto = sizeof(struct dm_spi_bus),
+ .per_child_auto = sizeof(struct spi_slave),
+ .per_child_plat_auto = sizeof(struct dm_spi_slave_plat),
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
.child_post_bind = spi_child_post_bind,
#endif