mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] staging: sm750fb: remove ineffective sw_i2c_wait() busy loop
@ 2026-11-15 21:54 Leon Pelzmann
  0 siblings, 0 replies; only message in thread
From: Leon Pelzmann @ 2026-11-15 21:54 UTC (permalink / raw)
  To: gregkh
  Cc: sudipm.mukherjee, teddy.wang, linux-fbdev, linux-staging,
	linux-kernel, Leon Pelzmann

sw_i2c_wait() is meant to insert a delay between the bit-banged I2C
operations, but it only consists of a loop that computes a value into
a local variable which is never read. The loop has no side effects, so
the compiler removes it entirely and the function compiles to nothing.
With W=1 this also triggers:

  ddk750_swi2c.c:95:16: error: variable 'tmp' set but not used
  [-Werror=unused-but-set-variable=]

Remove the function and all of its call sites. The I2C timing is not
changed by this: the object code of ddk750_swi2c.o (x86_64, gcc,
allmodconfig) is identical before and after this change.

The W=1 warning was found by building the driver, and the change was
prepared with the help of an AI coding assistant (Claude); it was
verified by comparing the objdump output before and after the change.

Signed-off-by: Leon Pelzmann <brunonick1801@gmail.com>
---
 drivers/staging/sm750fb/ddk750_swi2c.c | 34 --------------------------
 1 file changed, 34 deletions(-)

diff --git a/drivers/staging/sm750fb/ddk750_swi2c.c b/drivers/staging/sm750fb/ddk750_swi2c.c
index e63f3b00ec..e298bf3128 100644
--- a/drivers/staging/sm750fb/ddk750_swi2c.c
+++ b/drivers/staging/sm750fb/ddk750_swi2c.c
@@ -75,31 +75,6 @@ static unsigned long sw_i2c_data_gpio_mux_reg = GPIO_MUX;
 static unsigned long sw_i2c_data_gpio_data_reg = GPIO_DATA;
 static unsigned long sw_i2c_data_gpio_data_dir_reg = GPIO_DATA_DIRECTION;
 
-/*
- *  This function puts a delay between command
- */
-static void sw_i2c_wait(void)
-{
-	/* find a bug:
-	 * peekIO method works well before suspend/resume
-	 * but after suspend, peekIO(0x3ce,0x61) & 0x10
-	 * always be non-zero,which makes the while loop
-	 * never finish.
-	 * use non-ultimate for loop below is safe
-	 */
-
-    /* Change wait algorithm to use PCI bus clock,
-     * it's more reliable than counter loop ..
-     * write 0x61 to 0x3ce and read from 0x3cf
-     */
-	int i, tmp;
-
-	for (i = 0; i < 600; i++) {
-		tmp = i;
-		tmp += i;
-	}
-}
-
 /*
  *  This function set/reset the SCL GPIO pin
  *
@@ -257,11 +232,8 @@ static long sw_i2c_write_byte(unsigned char data)
 		else
 			sw_i2c_sda(0);
 
-		sw_i2c_wait();
-
 		/* Toggle clk line to one */
 		sw_i2c_scl(1);
-		sw_i2c_wait();
 
 		/* Shift byte to be sent */
 		value = value << 1;
@@ -272,9 +244,7 @@ static long sw_i2c_write_byte(unsigned char data)
 	sw_i2c_sda(1);
 
 	/* Set the SCL High for ack */
-	sw_i2c_wait();
 	sw_i2c_scl(1);
-	sw_i2c_wait();
 
 	/* Read SDA, until SDA==0 */
 	for (i = 0; i < 0xff; i++) {
@@ -282,9 +252,7 @@ static long sw_i2c_write_byte(unsigned char data)
 			break;
 
 		sw_i2c_scl(0);
-		sw_i2c_wait();
 		sw_i2c_scl(1);
-		sw_i2c_wait();
 	}
 
 	/* Set the SCL Low and SDA High */
@@ -316,11 +284,9 @@ static unsigned char sw_i2c_read_byte(unsigned char ack)
 		/* Set the SCL to Low and SDA to High (Input) */
 		sw_i2c_scl(0);
 		sw_i2c_sda(1);
-		sw_i2c_wait();
 
 		/* Set the SCL High */
 		sw_i2c_scl(1);
-		sw_i2c_wait();
 
 		/* Read data bits from SDA */
 		data |= (sw_i2c_read_sda() << i);
-- 
2.56.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-15 21:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15 21:54 [PATCH] staging: sm750fb: remove ineffective sw_i2c_wait() busy loop Leon Pelzmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®