dm: spi: Change cs_info op to return -EINVAL for invalid cs num

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>
Tested-by: Jagan Teki <jagan@amarulasolutions.com> # SoPine
Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>
This commit is contained in:
Bin Meng 2019-09-09 06:00:01 -07:00 committed by Jagan Teki
parent 4dd520b36b
commit 4b06000395
7 changed files with 8 additions and 8 deletions

View File

@ -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, static int exynos_cs_info(struct udevice *bus, uint cs,
struct spi_cs_info *info) struct spi_cs_info *info)
{ {
return -ENODEV; return -EINVAL;
} }
static const struct dm_spi_ops exynos_spi_ops = { 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 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. 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 If you don't provide the cs_info() method, 0 is assumed for all chip selects
that do not appear in the device tree. that do not appear in the device tree.

View File

@ -198,7 +198,7 @@ static int ath79_cs_info(struct udevice *bus, uint cs,
{ {
/* Always allow activity on CS 0/1/2 */ /* Always allow activity on CS 0/1/2 */
if (cs >= 3) if (cs >= 3)
return -ENODEV; return -EINVAL;
return 0; return 0;
} }

View File

@ -108,7 +108,7 @@ static int bcm63xx_hsspi_cs_info(struct udevice *bus, uint cs,
if (cs >= priv->num_cs) { if (cs >= priv->num_cs) {
printf("no cs %u\n", cs); printf("no cs %u\n", cs);
return -ENODEV; return -EINVAL;
} }
return 0; return 0;

View File

@ -130,7 +130,7 @@ static int bcm63xx_spi_cs_info(struct udevice *bus, uint cs,
if (cs >= priv->num_cs) { if (cs >= priv->num_cs) {
printf("no cs %u\n", cs); printf("no cs %u\n", cs);
return -ENODEV; return -EINVAL;
} }
return 0; return 0;

View File

@ -117,7 +117,7 @@ static int sandbox_cs_info(struct udevice *bus, uint cs,
{ {
/* Always allow activity on CS 0 */ /* Always allow activity on CS 0 */
if (cs >= 1) if (cs >= 1)
return -ENODEV; return -EINVAL;
return 0; return 0;
} }

View File

@ -78,7 +78,7 @@ int tegra20_sflash_cs_info(struct udevice *bus, unsigned int cs,
{ {
/* Tegra20 SPI-Flash - only 1 device ('bus/cs') */ /* Tegra20 SPI-Flash - only 1 device ('bus/cs') */
if (cs != 0) if (cs != 0)
return -ENODEV; return -EINVAL;
else else
return 0; return 0;
} }

View File

@ -458,7 +458,7 @@ struct dm_spi_ops {
* @cs: The chip select (0..n-1) * @cs: The chip select (0..n-1)
* @info: Returns information about the chip select, if valid. * @info: Returns information about the chip select, if valid.
* On entry info->dev is NULL * 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 * is invalid, other -ve value on error
*/ */
int (*cs_info)(struct udevice *bus, uint cs, struct spi_cs_info *info); int (*cs_info)(struct udevice *bus, uint cs, struct spi_cs_info *info);