From 8b85dfc675f12de8d04126c07f3c796965b990c2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 16 Dec 2020 21:20:07 -0700 Subject: dm: Avoid accessing seq directly At present various drivers etc. access the device's 'seq' member directly. This makes it harder to change the meaning of that member. Change access to go through a function instead. The drivers/i2c/lpc32xx_i2c.c file is left unchanged for now. Signed-off-by: Simon Glass --- drivers/spi/sandbox_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/spi/sandbox_spi.c') diff --git a/drivers/spi/sandbox_spi.c b/drivers/spi/sandbox_spi.c index 755f1768614..3c780bae71b 100644 --- a/drivers/spi/sandbox_spi.c +++ b/drivers/spi/sandbox_spi.c @@ -72,7 +72,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) { -- cgit v1.2.3 From 1f6d618bb16e10bdba5cb08733e228367662b12c Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Mon, 14 Dec 2020 19:06:46 +0200 Subject: sandbox: spi: Drop unused sandbox_spi_parse_spec function Commit 1289e96797bf ("sandbox: spi: Drop command-line SPI option") dropped support for specifying SPI devices on the command line, removing the only user of sandbox_spi_parse_spec(). Remove the function too. Fixes: 1289e96797bf ("sandbox: spi: Drop command-line SPI option") Signed-off-by: Ovidiu Panait Reviewed-by: Simon Glass --- drivers/spi/sandbox_spi.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'drivers/spi/sandbox_spi.c') diff --git a/drivers/spi/sandbox_spi.c b/drivers/spi/sandbox_spi.c index 3c780bae71b..6adddd77b87 100644 --- a/drivers/spi/sandbox_spi.c +++ b/drivers/spi/sandbox_spi.c @@ -28,22 +28,6 @@ # 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; -} - __weak int sandbox_spi_get_emul(struct sandbox_state *state, struct udevice *bus, struct udevice *slave, struct udevice **emulp) -- cgit v1.2.3 From 1dc53ce71d961a0404c0d785fb0b66f351a7b730 Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Mon, 14 Dec 2020 19:06:47 +0200 Subject: sandbox: test: Add a second SPI slave on sandbox_spi bus Place a second spi slave on the sandbox_spi bus, to be used by the spi_claim_bus() testcase we are about to introduce. We need to make sure that jumping between slaves calling spi_claim_bus() sets the bus speed and mode appropriately. Use different max-hz and mode properties for this new slave. Also, update sandbox_spi cs_info call to allow activity on CS0/CS1 and adapt dm_test_spi_find() testcase for this new setup. Signed-off-by: Ovidiu Panait Reviewed-by: Simon Glass --- drivers/spi/sandbox_spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/spi/sandbox_spi.c') diff --git a/drivers/spi/sandbox_spi.c b/drivers/spi/sandbox_spi.c index 6adddd77b87..58f80c60ac3 100644 --- a/drivers/spi/sandbox_spi.c +++ b/drivers/spi/sandbox_spi.c @@ -101,8 +101,8 @@ static int sandbox_spi_set_mode(struct udevice *bus, uint mode) 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; -- cgit v1.2.3 From 2da1800456909944b393ad8539edb0bf3e997e2d Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Mon, 14 Dec 2020 19:06:48 +0200 Subject: spi: sandbox_spi: Implement speed/mode setup Implement sandbox_spi_set_{speed, mode} routines, to be able to keep track of the current bus speed/mode. This will help determine whether the values passed from dm_spi_claim_bus() are valid. Signed-off-by: Ovidiu Panait --- drivers/spi/sandbox_spi.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'drivers/spi/sandbox_spi.c') diff --git a/drivers/spi/sandbox_spi.c b/drivers/spi/sandbox_spi.c index 58f80c60ac3..be516d5aa62 100644 --- a/drivers/spi/sandbox_spi.c +++ b/drivers/spi/sandbox_spi.c @@ -28,6 +28,23 @@ # define CONFIG_SPI_IDLE_VAL 0xFF #endif +/** + * 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, struct udevice **emulp) @@ -90,11 +107,19 @@ 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; } @@ -136,4 +161,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), }; -- cgit v1.2.3 From add685fb6d8de91723d006a0382f76041320b529 Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Mon, 14 Dec 2020 19:06:49 +0200 Subject: test: spi: Add sandbox_spi_get_{speed, mode} interface Introduce sandbox_spi_get_{speed, mode} public interface to retrieve the sandbox spi bus internal state. They are meant to be used in sandbox spi testcases. Signed-off-by: Ovidiu Panait Reviewed-by: Simon Glass --- drivers/spi/sandbox_spi.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'drivers/spi/sandbox_spi.c') diff --git a/drivers/spi/sandbox_spi.c b/drivers/spi/sandbox_spi.c index be516d5aa62..0564d8b55e7 100644 --- a/drivers/spi/sandbox_spi.c +++ b/drivers/spi/sandbox_spi.c @@ -52,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) { -- cgit v1.2.3