From: Bin Meng <bmeng.cn@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/4] dm: spi: Change cs_info op to return -EINVAL for invalid cs num
Date: Mon, 9 Sep 2019 06:00:01 -0700 [thread overview]
Message-ID: <1568034003-14675-2-git-send-email-bmeng.cn@gmail.com> (raw)
In-Reply-To: <1568034003-14675-1-git-send-email-bmeng.cn@gmail.com>
We need distinguish the following two situations in various SPI APIs:
- given chip select num is invalid
- given chip select num is valid, but no device is attached
Currently -ENODEV is returned for both cases.
For the first case, it's more reasonable to return -EINVAL instead of
-ENODEV for invalid chip select numbers.
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---
Changes in v2:
- new patch to change cs_info op to return -EINVAL for invalid cs num
doc/driver-model/spi-howto.rst | 4 ++--
drivers/spi/ath79_spi.c | 2 +-
drivers/spi/bcm63xx_hsspi.c | 2 +-
drivers/spi/bcm63xx_spi.c | 2 +-
drivers/spi/sandbox_spi.c | 2 +-
drivers/spi/tegra20_sflash.c | 2 +-
include/spi.h | 2 +-
7 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/doc/driver-model/spi-howto.rst b/doc/driver-model/spi-howto.rst
index 7e64fae..451dc08 100644
--- a/doc/driver-model/spi-howto.rst
+++ b/doc/driver-model/spi-howto.rst
@@ -116,7 +116,7 @@ Put this code at the bottom of your existing driver file:
static int exynos_cs_info(struct udevice *bus, uint cs,
struct spi_cs_info *info)
{
- return -ENODEV;
+ return -EINVAL;
}
static const struct dm_spi_ops exynos_spi_ops = {
@@ -633,7 +633,7 @@ is not obvious from outside the driver. In this case you can provide a
method for cs_info() to deal with this. If you don't provide it, then the
device tree will be used to determine what chip selects are valid.
-Return -ENODEV if the supplied chip select is invalid, or 0 if it is valid.
+Return -EINVAL if the supplied chip select is invalid, or 0 if it is valid.
If you don't provide the cs_info() method, 0 is assumed for all chip selects
that do not appear in the device tree.
diff --git a/drivers/spi/ath79_spi.c b/drivers/spi/ath79_spi.c
index 4fd3c05..2070692 100644
--- a/drivers/spi/ath79_spi.c
+++ b/drivers/spi/ath79_spi.c
@@ -198,7 +198,7 @@ static int ath79_cs_info(struct udevice *bus, uint cs,
{
/* Always allow activity on CS 0/1/2 */
if (cs >= 3)
- return -ENODEV;
+ return -EINVAL;
return 0;
}
diff --git a/drivers/spi/bcm63xx_hsspi.c b/drivers/spi/bcm63xx_hsspi.c
index 4f527fa7..f1e246e 100644
--- a/drivers/spi/bcm63xx_hsspi.c
+++ b/drivers/spi/bcm63xx_hsspi.c
@@ -108,7 +108,7 @@ static int bcm63xx_hsspi_cs_info(struct udevice *bus, uint cs,
if (cs >= priv->num_cs) {
printf("no cs %u\n", cs);
- return -ENODEV;
+ return -EINVAL;
}
return 0;
diff --git a/drivers/spi/bcm63xx_spi.c b/drivers/spi/bcm63xx_spi.c
index 4d19e03..69f88c9 100644
--- a/drivers/spi/bcm63xx_spi.c
+++ b/drivers/spi/bcm63xx_spi.c
@@ -130,7 +130,7 @@ static int bcm63xx_spi_cs_info(struct udevice *bus, uint cs,
if (cs >= priv->num_cs) {
printf("no cs %u\n", cs);
- return -ENODEV;
+ return -EINVAL;
}
return 0;
diff --git a/drivers/spi/sandbox_spi.c b/drivers/spi/sandbox_spi.c
index 906401e..16473ec 100644
--- a/drivers/spi/sandbox_spi.c
+++ b/drivers/spi/sandbox_spi.c
@@ -117,7 +117,7 @@ static int sandbox_cs_info(struct udevice *bus, uint cs,
{
/* Always allow activity on CS 0 */
if (cs >= 1)
- return -ENODEV;
+ return -EINVAL;
return 0;
}
diff --git a/drivers/spi/tegra20_sflash.c b/drivers/spi/tegra20_sflash.c
index a54b10f..567e33f 100644
--- a/drivers/spi/tegra20_sflash.c
+++ b/drivers/spi/tegra20_sflash.c
@@ -78,7 +78,7 @@ int tegra20_sflash_cs_info(struct udevice *bus, unsigned int cs,
{
/* Tegra20 SPI-Flash - only 1 device ('bus/cs') */
if (cs != 0)
- return -ENODEV;
+ return -EINVAL;
else
return 0;
}
diff --git a/include/spi.h b/include/spi.h
index 3785941..cc344de 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -438,7 +438,7 @@ struct dm_spi_ops {
* @cs: The chip select (0..n-1)
* @info: Returns information about the chip select, if valid.
* On entry info->dev is NULL
- * @return 0 if OK (and @info is set up), -ENODEV if the chip select
+ * @return 0 if OK (and @info is set up), -EINVAL if the chip select
* is invalid, other -ve value on error
*/
int (*cs_info)(struct udevice *bus, uint cs, struct spi_cs_info *info);
--
2.7.4
next prev parent reply other threads:[~2019-09-09 13:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-09 13:00 [U-Boot] [PATCH v2 1/4] dm: spi: Return 0 if driver does not implement ops->cs_info Bin Meng
2019-09-09 13:00 ` Bin Meng [this message]
2019-09-09 13:00 ` [U-Boot] [PATCH v2 3/4] dm: spi: Check cs number before accessing slaves Bin Meng
2019-10-16 14:05 ` Jagan Teki
2019-10-16 15:21 ` Jagan Teki
2019-10-29 10:15 ` Bin Meng
2019-11-18 7:15 ` Bin Meng
2020-01-09 13:47 ` Bin Meng
2020-01-09 13:48 ` Jagan Teki
2019-09-09 13:00 ` [U-Boot] [PATCH v2 4/4] test: dm: spi: Fix sandbox dm_test_spi_find() Bin Meng
2019-10-16 14:07 ` Jagan Teki
2019-09-29 8:04 ` [U-Boot] [PATCH v2 1/4] dm: spi: Return 0 if driver does not implement ops->cs_info Bin Meng
2019-10-08 12:59 ` Bin Meng
2019-10-14 2:33 ` Bin Meng
2019-10-16 10:14 ` Jagan Teki
2019-10-16 13:58 ` Jagan Teki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1568034003-14675-2-git-send-email-bmeng.cn@gmail.com \
--to=bmeng.cn@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox