Skip to contentSkip to conversation

spi: ignore set speed and mode if not available

PATCH New Thomas Chou 4 participants 7 messages Sep 22, 2015 – Oct 4, 2015 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: ignore set speed and mode if not available

Some cores, such as Altera SPI and QuadSPI, can not change speed and mode at runtime. Ignore the operation which is not available.

---
 drivers/spi/spi-uclass.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/spi/spi-uclass.c +1 -5
index d666272..5298073 100644
@@ -21,13 +21,11 @@ DECLARE_GLOBAL_DATA_PTR;
 static int spi_set_speed_mode(struct udevice *bus, int speed, int mode)
 {
 	struct dm_spi_ops *ops;
-	int ret;
+	int ret = 0;
 
 	ops = spi_get_ops(bus);
 	if (ops->set_speed)
 		ret = ops->set_speed(bus, speed);
-	else
-		ret = -EINVAL;
 	if (ret) {
 		printf("Cannot set speed (err=%d)\n", ret);
 		return ret;
@@ -35,8 +33,6 @@ static int spi_set_speed_mode(struct udevice *bus, int speed, int mode)
 
 	if (ops->set_mode)
 		ret = ops->set_mode(bus, mode);
-	else
-		ret = -EINVAL;
 	if (ret) {
 		printf("Cannot set mode (err=%d)\n", ret);
 		return ret;
Signature · 1 line
2.1.4
#3 lore raw

PATCH 1/1 spi: ignore set speed and mode if not available

In reply to Thomas Chou

Hi Thomas,

Quoted 8 lines · Thomas Chou

Some cores, such as Altera SPI and QuadSPI, can not change speed and mode at runtime. Ignore the operation which is not available.

---
 drivers/spi/spi-uclass.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

This looks OK, but can you please update the method documentation for set_speed() and set_mode() to indicate that they are optional in the case where the hardware does not support it.

drivers/spi/spi-uclass.c DECLARE_GLOBAL_DATA_PTR; · line 21

Quoted 7 lines
drivers/spi/spi-uclass.c +0 -0
index d666272..5298073 100644
@@ -21,13 +21,11 @@ DECLARE_GLOBAL_DATA_PTR;
 static int spi_set_speed_mode(struct udevice *bus, int speed, int mode)

Please add a comment to this function indicated that missing set_speed() and set_mode() methods are OK.

Quoted 23 lines
drivers/spi/spi-uclass.c +1 -6
 {
        struct dm_spi_ops *ops;
-       int ret;
+       int ret = 0;
 
        ops = spi_get_ops(bus);
        if (ops->set_speed)
                ret = ops->set_speed(bus, speed);
-       else
-               ret = -EINVAL;
        if (ret) {
                printf("Cannot set speed (err=%d)\n", ret);
                return ret;
@@ -35,8 +33,6 @@ static int spi_set_speed_mode(struct udevice *bus, int speed, int mode)
 
        if (ops->set_mode)
                ret = ops->set_mode(bus, mode);
-       else
-               ret = -EINVAL;
        if (ret) {
                printf("Cannot set mode (err=%d)\n", ret);
                return ret;
--
Quoted 2 lines

2.1.4

Regards,
Simon

#4 lore raw

PATCH 1/1 spi: ignore set speed and mode if not available

Hi Simon,

Quoted 17 lines · Simon Glass

Hi Thomas,

Quoted 8 lines · Thomas Chou

Some cores, such as Altera SPI and QuadSPI, can not change speed and mode at runtime. Ignore the operation which is not available.

---
  drivers/spi/spi-uclass.c | 6 +-----
  1 file changed, 1 insertion(+), 5 deletions(-)

This looks OK, but can you please update the method documentation for set_speed() and set_mode() to indicate that they are optional in the case where the hardware does not support it.

Quoted 1 line
Quoted 9 lines

drivers/spi/spi-uclass.c DECLARE_GLOBAL_DATA_PTR; · line 21

Quoted 6 lines
drivers/spi/spi-uclass.c +0 -0
index d666272..5298073 100644
@@ -21,13 +21,11 @@ DECLARE_GLOBAL_DATA_PTR;
  static int spi_set_speed_mode(struct udevice *bus, int speed, int mode)

Please add a comment to this function indicated that missing set_speed() and set_mode() methods are OK.

Thanks a lot for your review. The comments will be added.

Best regards,
Thomas Chou

#5 lore raw

PATCH v2 1/1 spi: ignore set speed and mode if not available

In reply to Thomas Chou

Some cores, such as Altera SPI and QuadSPI, can not change speed and mode at runtime. Ignore the operation which is not available.

---
v2
add comments as Simon sugggested.

 drivers/spi/spi-uclass.c | 7 ++-----
 include/spi.h            | 5 +++++
 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/spi/spi-uclass.c +2 -5
index d666272..50e3553 100644
@@ -21,13 +21,12 @@ DECLARE_GLOBAL_DATA_PTR;
 static int spi_set_speed_mode(struct udevice *bus, int speed, int mode)
 {
 	struct dm_spi_ops *ops;
-	int ret;
+	int ret = 0;
 
 	ops = spi_get_ops(bus);
+	/* missing get_speed() and set_mode() methods are OK */
 	if (ops->set_speed)
 		ret = ops->set_speed(bus, speed);
-	else
-		ret = -EINVAL;
 	if (ret) {
 		printf("Cannot set speed (err=%d)\n", ret);
 		return ret;
@@ -35,8 +34,6 @@ static int spi_set_speed_mode(struct udevice *bus, int speed, int mode)
 
 	if (ops->set_mode)
 		ret = ops->set_mode(bus, mode);
-	else
-		ret = -EINVAL;
 	if (ret) {
 		printf("Cannot set mode (err=%d)\n", ret);
 		return ret;
include/spi.h +5 -0
index 51fdfd6..a418509 100644
@@ -451,6 +451,9 @@ struct dm_spi_ops {
 	/**
 	 * Set transfer speed.
 	 * This sets a new speed to be applied for next spi_xfer().
+	 *
+	 * It is optional in the case where the hardware does not support it.
+	 *
 	 * @bus:	The SPI bus
 	 * @hz:		The transfer speed
 	 * @return 0 if OK, -ve on error
@@ -463,6 +466,8 @@ struct dm_spi_ops {
 	 * It is unclear if we want to set speed and mode together instead
 	 * of separately.
 	 *
+	 * It is optional in the case where the hardware does not support it.
+	 *
 	 * @bus:	The SPI bus
 	 * @mode:	Requested SPI mode (SPI_... flags)
 	 * @return 0 if OK, -ve on error
Signature · 1 line
2.1.4
#6 lore raw

PATCH v2 1/1 spi: ignore set speed and mode if not available

Quoted 7 lines · Thomas Chou

Some cores, such as Altera SPI and QuadSPI, can not change speed and mode at runtime. Ignore the operation which is not available.

Quoted 8 lines

---
v2
add comments as Simon sugggested.

 drivers/spi/spi-uclass.c | 7 ++-----
 include/spi.h            | 5 +++++
 2 files changed, 7 insertions(+), 5 deletions(-)