spi: sc18is602: Convert to let spi core validate transfer speed
PATCH 1/1 spi: sc18is602: Convert to let spi core validate transfer speed
Set master->max_speed_hz and master->min_speed_hz then spi core will handle checking transfer speed. So we can remove the same checking in this driver.
This patch also remove testing if hz is 0 because spi->max_speed_hz will be default set to master->min_speed_hz if it was not set. So the transfer speed will never set to 0.
--- drivers/spi/spi-sc18is602.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/spi/spi-sc18is602.c +3 -10
@@ -183,17 +183,9 @@ static int sc18is602_setup_transfer(struct sc18is602 *hw, u32 hz, u8 mode)static int sc18is602_check_transfer (struct spi_device *spi,struct spi_transfer *t,int tlen) { -uint32_t hz; -if (t && t->len + tlen >SC18IS602_BUFSIZ )return -EINVAL ; - hz = spi->max_speed_hz; -if (t && t->speed_hz) - hz = t->speed_hz; -if (hz ==0 ) -return -EINVAL ; -return 0 ; }
@@ -207,14 +199,13 @@ static int sc18is602_transfer_one(struct spi_master *master, hw->tlen =0 ;list_for_each_entry (t, &m->transfers, transfer_list) { -u32 hz = t->speed_hz ? : spi->max_speed_hz;bool do_transfer; status =sc18is602_check_transfer (spi, t, hw->tlen);if (status <0 )break ; - status =sc18is602_setup_transfer (hw, hz, spi->mode); + status =sc18is602_setup_transfer (hw, t->speed_hz, spi->mode);if (status <0 )break ;
@@ -305,6 +296,8 @@ static int sc18is602_probe(struct i2c_client *client, master->setup = sc18is602_setup; master->transfer_one_message = sc18is602_transfer_one; master->dev.of_node = np; + master->min_speed_hz = hw->freq /128 ; + master->max_speed_hz = hw->freq /4 ; error =devm_spi_register_master (dev, master);if (error)
Signature · 8 lines
1.8.1.2 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Brown
AppliedQuoted 6 lines · Axel Lin
Set
master->max_speed_hzandmaster->min_speed_hzthen spi core will handle checking transfer speed. So we can remove the same checking in this driver.This patch also remove testing if hz is 0 because
spi->max_speed_hzwill be default set tomaster->min_speed_hzif it was not set. So the transfer speed will never set to 0.
Applied, thanks.
Quoted 51 lines · Axel Lin
Set
master->max_speed_hzandmaster->min_speed_hzthen spi core will handle checking transfer speed. So we can remove the same checking in this driver.This patch also remove testing if hz is 0 because
spi->max_speed_hzwill be default set tomaster->min_speed_hzif it was not set. So the transfer speed will never set to 0.Signed-off-by Axel Lin <[email protected]>--- drivers/spi/spi-sc18is602.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)drivers/spi/spi-sc18is602.c +1
-10@@ -183,17 +183,9 @@ static int sc18is602_setup_transfer(struct sc18is602 *hw, u32 hz, u8 mode)static int sc18is602_check_transfer (struct spi_device *spi,struct spi_transfer *t,int tlen) { -uint32_t hz; -if (t && t->len + tlen >SC18IS602_BUFSIZ )return -EINVAL ; - hz = spi->max_speed_hz; -if (t && t->speed_hz) - hz = t->speed_hz; -if (hz ==0 ) -return -EINVAL ; -return 0 ; }@@ -207,14 +199,13 @@ static int sc18is602_transfer_one(struct spi_master *master, hw->tlen =0 ;list_for_each_entry (t, &m->transfers, transfer_list) { -u32 hz = t->speed_hz ? : spi->max_speed_hz;bool do_transfer; status =sc18is602_check_transfer (spi, t, hw->tlen);if (status <0 )break ; - status =sc18is602_setup_transfer (hw, hz, spi->mode); + status =sc18is602_setup_transfer (hw, t->speed_hz, spi->mode);if (status <0 )break ;
drivers/spi/spi-sc18is602.c static int sc18is602_probe(struct i2c_client *client, · line 301
Quoted 6 lines
drivers/spi/spi-sc18is602.c +2
-0@@ -305,6 +296,8 @@ static int sc18is602_probe(struct i2c_client *client, master->setup = sc18is602_setup; master->transfer_one_message = sc18is602_transfer_one; master->dev.of_node = np; + master->min_speed_hz = hw->freq /128 ; + master->max_speed_hz = hw->freq /4 ;
Turns out this results in a failure if the requested speed is higher than the supported speed. Previous code would simply update the speed to the maximum supported speed.
Since the patch was already accepted, I'll send a follow-up patch to make this less restrictive; I don't see the need to reject a transfer request at 2mbps because the chip can only support 1.843 mbps.
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html