Skip to contentSkip to conversation

spi: xcomm: Remove duplicate code to set default bits_per_word and max speed

PATCH Applied Axel Lin 3 participants 3 messages Mar 2, 2014 – Mar 4, 2014 SPI

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 spi: xcomm: Remove duplicate code to set default bits_per_word and max speed

In the implementation of __spi_validate(), spi core will set transfer bits_per_word and max speed as spi device default if it is not set for this transfer. So we can remove the same logic in spi_xcomm_setup_transfer(). Also remove a redundant code to initialize is_first variable.

---
 drivers/spi/spi-xcomm.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/spi/spi-xcomm.c +4 -8
index 350a76b..bb478dc 100644
@@ -73,15 +73,13 @@ static void spi_xcomm_chipselect(struct spi_xcomm *spi_xcomm,
 static int spi_xcomm_setup_transfer(struct spi_xcomm *spi_xcomm,
 	struct spi_device *spi, struct spi_transfer *t, unsigned int *settings)
 {
-	unsigned int speed;
-
 	if (t->len > 62)
 		return -EINVAL;
 
-	speed = t->speed_hz ? t->speed_hz : spi->max_speed_hz;
+	if (t->speed_hz != spi_xcomm->current_speed) {
+		unsigned int divider;
 
-	if (speed != spi_xcomm->current_speed) {
-		unsigned int divider = DIV_ROUND_UP(SPI_XCOMM_CLOCK, speed);
+		divider = DIV_ROUND_UP(SPI_XCOMM_CLOCK, t->speed_hz);
 		if (divider >= 64)
 			*settings |= SPI_XCOMM_SETTINGS_CLOCK_DIV_64;
 		else if (divider >= 16)
@@ -89,7 +87,7 @@ static int spi_xcomm_setup_transfer(struct spi_xcomm *spi_xcomm,
 		else
 			*settings |= SPI_XCOMM_SETTINGS_CLOCK_DIV_4;
 
-		spi_xcomm->current_speed = speed;
+		spi_xcomm->current_speed = t->speed_hz;
 	}
 
 	if (spi->mode & SPI_CPOL)
@@ -147,8 +145,6 @@ static int spi_xcomm_transfer_one(struct spi_master *master,
 	int status = 0;
 	bool is_last;
 
-	is_first = true;
-
 	spi_xcomm_chipselect(spi_xcomm, spi, true);
 
 	list_for_each_entry(t, &msg->transfers, transfer_list) {
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
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Axel Lin

In the implementation of __spi_validate(), spi core will set transfer bits_per_word and max speed as spi device default if it is not set for this transfer. So we can remove the same logic in spi_xcomm_setup_transfer(). Also remove a redundant code to initialize is_first variable.

Quoted 38 lines
---
  drivers/spi/spi-xcomm.c | 12 ++++--------
  1 file changed, 4 insertions(+), 8 deletions(-)
drivers/spi/spi-xcomm.c +4 -6
index 350a76b..bb478dc 100644
@@ -73,15 +73,13 @@ static void spi_xcomm_chipselect(struct spi_xcomm *spi_xcomm,
  static int spi_xcomm_setup_transfer(struct spi_xcomm *spi_xcomm,
  	struct spi_device *spi, struct spi_transfer *t, unsigned int *settings)
  {
-	unsigned int speed;
-
  	if (t->len > 62)
  		return -EINVAL;
 
-	speed = t->speed_hz ? t->speed_hz : spi->max_speed_hz;
+	if (t->speed_hz != spi_xcomm->current_speed) {
+		unsigned int divider;
 
-	if (speed != spi_xcomm->current_speed) {
-		unsigned int divider = DIV_ROUND_UP(SPI_XCOMM_CLOCK, speed);
+		divider = DIV_ROUND_UP(SPI_XCOMM_CLOCK, t->speed_hz);
  		if (divider >= 64)
  			*settings |= SPI_XCOMM_SETTINGS_CLOCK_DIV_64;
  		else if (divider >= 16)
@@ -89,7 +87,7 @@ static int spi_xcomm_setup_transfer(struct spi_xcomm *spi_xcomm,
  		else
  			*settings |= SPI_XCOMM_SETTINGS_CLOCK_DIV_4;
 
-		spi_xcomm->current_speed = speed;
+		spi_xcomm->current_speed = t->speed_hz;
  	}
 
  	if (spi->mode & SPI_CPOL)

drivers/spi/spi-xcomm.c static int spi_xcomm_transfer_one(struct spi_master *master, · line 150

Quoted 8 lines
drivers/spi/spi-xcomm.c +0 -2
@@ -147,8 +145,6 @@ static int spi_xcomm_transfer_one(struct spi_master *master,
  	int status = 0;
  	bool is_last;
 
-	is_first = true;
-
  	spi_xcomm_chipselect(spi_xcomm, spi, true);
 
  	list_for_each_entry(t, &msg->transfers, transfer_list) {

--
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

Applied
#2 lore raw
In reply to Axel Lin
Quoted 4 lines · Axel Lin

In the implementation of __spi_validate(), spi core will set transfer bits_per_word and max speed as spi device default if it is not set for this transfer. So we can remove the same logic in spi_xcomm_setup_transfer(). Also remove a redundant code to initialize is_first variable.

Applied, thanks.