Re: [U-Boot] [PATCH v3 18/26] dm: spi: Move slave details to child platdata

2015-01-26 Thread Simon Glass
On 25 January 2015 at 08:27, Simon Glass s...@chromium.org wrote:
 At present we go through various contortions to store the SPI slave's chip
 select in its private data. This only exists when the slave is active so
 must be set up when it is probed. Until the device is probed we don't
 actually know what chip select it will appear on.

 However, now that we can support per-child platform data, we can use that
 instead. This allows us to set up the chip select when the child is bound,
 and avoid the messy contortions.

 Unfortunately this is a fairly large change and it seems to be difficult to
 break it down further.

 Signed-off-by: Simon Glass s...@chromium.org

Applied to -u-boot-dm
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 18/26] dm: spi: Move slave details to child platdata

2015-01-25 Thread Simon Glass
At present we go through various contortions to store the SPI slave's chip
select in its private data. This only exists when the slave is active so
must be set up when it is probed. Until the device is probed we don't
actually know what chip select it will appear on.

However, now that we can support per-child platform data, we can use that
instead. This allows us to set up the chip select when the child is bound,
and avoid the messy contortions.

Unfortunately this is a fairly large change and it seems to be difficult to
break it down further.

Signed-off-by: Simon Glass s...@chromium.org
---

Changes in v3: None
Changes in v2:
- Add a TODO to remove struct dm_spi_bus
- Add additional comments to spi.h
- Copy max_hz and mode from platdata to spi_slave when probing
- Tidy up soft_spi driver also

 drivers/misc/cros_ec_spi.c | 19 ---
 drivers/mtd/spi/sandbox.c  |  5 +++
 drivers/mtd/spi/sf_probe.c |  3 +-
 drivers/spi/soft_spi.c |  9 -
 drivers/spi/spi-uclass.c   | 83 +++---
 include/spi.h  | 42 +--
 test/dm/spi.c  |  6 ++--
 7 files changed, 91 insertions(+), 76 deletions(-)

diff --git a/drivers/misc/cros_ec_spi.c b/drivers/misc/cros_ec_spi.c
index e6dba29..25a5a04 100644
--- a/drivers/misc/cros_ec_spi.c
+++ b/drivers/misc/cros_ec_spi.c
@@ -202,25 +202,6 @@ int cros_ec_spi_init(struct cros_ec_dev *dev, const void 
*blob)
 #ifdef CONFIG_DM_CROS_EC
 int cros_ec_probe(struct udevice *dev)
 {
-   struct spi_slave *slave = dev_get_parentdata(dev);
-   int ret;
-
-   /*
-* TODO(s...@chromium.org)
-*
-* This is really horrible at present. It is an artifact of removing
-* the child_pre_probe() method for SPI. Everything here could go in
-* an automatic function, except that spi_get_bus_and_cs() wants to
-* set it up manually and call device_probe_child().
-*
-* The solution may be to re-enable the child_pre_probe() method for
-* SPI and have it do nothing if the child is already passed in via
-* device_probe_child().
-*/
-   slave-dev = dev;
-   ret = spi_ofdata_to_platdata(gd-fdt_blob, dev-of_offset, slave);
-   if (ret)
-   return ret;
return cros_ec_register(dev);
 }
 
diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c
index 106dda9..d576d31 100644
--- a/drivers/mtd/spi/sandbox.c
+++ b/drivers/mtd/spi/sandbox.c
@@ -590,6 +590,11 @@ int sandbox_sf_bind_emul(struct sandbox_state *state, int 
busnum, int cs,
 
 void sandbox_sf_unbind_emul(struct sandbox_state *state, int busnum, int cs)
 {
+   struct udevice *dev;
+
+   dev = state-spi[busnum][cs].emul;
+   device_remove(dev);
+   device_unbind(dev);
state-spi[busnum][cs].emul = NULL;
 }
 
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index ce9987f..4103723 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -481,11 +481,12 @@ int spi_flash_std_erase(struct udevice *dev, u32 offset, 
size_t len)
 int spi_flash_std_probe(struct udevice *dev)
 {
struct spi_slave *slave = dev_get_parentdata(dev);
+   struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
struct spi_flash *flash;
 
flash = dev-uclass_priv;
flash-dev = dev;
-   debug(%s: slave=%p, cs=%d\n, __func__, slave, slave-cs);
+   debug(%s: slave=%p, cs=%d\n, __func__, slave, plat-cs);
return spi_flash_probe_slave(slave, flash);
 }
 
diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c
index 9f7d80e..6ae45f5 100644
--- a/drivers/spi/soft_spi.c
+++ b/drivers/spi/soft_spi.c
@@ -179,14 +179,6 @@ static int soft_spi_set_mode(struct udevice *dev, unsigned 
int mode)
return 0;
 }
 
-static int soft_spi_child_pre_probe(struct udevice *dev)
-{
-   struct spi_slave *slave = dev_get_parentdata(dev);
-
-   slave-dev = dev;
-   return spi_ofdata_to_platdata(gd-fdt_blob, dev-of_offset, slave);
-}
-
 static const struct dm_spi_ops soft_spi_ops = {
.claim_bus  = soft_spi_claim_bus,
.release_bus= soft_spi_release_bus,
@@ -241,5 +233,4 @@ U_BOOT_DRIVER(soft_spi) = {
.platdata_auto_alloc_size = sizeof(struct soft_spi_platdata),
.priv_auto_alloc_size = sizeof(struct soft_spi_priv),
.probe  = soft_spi_probe,
-   .child_pre_probe= soft_spi_child_pre_probe,
 };
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index 2c134eb..63a6217 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -98,11 +98,21 @@ int spi_post_bind(struct udevice *dev)
return dm_scan_fdt_node(dev, gd-fdt_blob, dev-of_offset, false);
 }
 
-int spi_post_probe(struct udevice *dev)
+int spi_child_post_bind(struct udevice *dev)
 {
-   struct dm_spi_bus *spi = dev-uclass_priv;
+   struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
 
-