[PATCH] gpio: sx150x: correct and refine reset-on-probe behavior.

Previous thread: [PATCH] x86-64: Remove system_64.h by Brian Gerst on Saturday, August 28, 2010 - 10:11 am. (1 message)

Next thread: Re: [PATCH 2/7] drivers/usb/gadget: Remove double test by David Brownell on Saturday, August 28, 2010 - 11:11 am. (1 message)
From: Gregory Bean
Date: Saturday, August 28, 2010 - 10:15 am

Replace the arbitrary software-reset call from the device-probe
method, because:
- It is defective.  To work correctly, it should be two byte writes,
  not a single word write.  As it stands, it does nothing.
- Some devices with sx150x expanders installed have their NRESET pins
  ganged on the same line, so resetting one causes the others to reset -
  not a nice thing to do arbitrarily!
- The probe, usually taking place at boot, implies a recent hard-reset,
  so a software reset at this point is just a waste of energy anyway.

Therefore, make it optional, defaulting to off, as this will match the
common case of probing at powerup and also matches the current
broken no-op behavior.

Signed-off-by: Gregory Bean <gbean@codeaurora.org>
---
 drivers/gpio/sx150x.c      |   29 ++++++++++++++++++++++++-----
 include/linux/i2c/sx150x.h |    4 ++++
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/sx150x.c b/drivers/gpio/sx150x.c
index b42f42c..6d68018 100644
--- a/drivers/gpio/sx150x.c
+++ b/drivers/gpio/sx150x.c
@@ -459,17 +459,36 @@ static int sx150x_init_io(struct sx150x_chip *chip, u8 base, u16 cfg)
 	return err;
 }
 
-static int sx150x_init_hw(struct sx150x_chip *chip,
-			struct sx150x_platform_data *pdata)
+static int sx150x_reset(struct sx150x_chip *chip)
 {
-	int err = 0;
+	int err;
+
+	err = i2c_smbus_write_byte_data(chip->client,
+					chip->dev_cfg->reg_reset,
+					0x12);
+	if (err < 0)
+		return err;
 
-	err = i2c_smbus_write_word_data(chip->client,
+	err = i2c_smbus_write_byte_data(chip->client,
 					chip->dev_cfg->reg_reset,
-					0x3412);
+					0x34);
 	if (err < 0)
 		return err;
 
+	return 0;
+}
+
+static int sx150x_init_hw(struct sx150x_chip *chip,
+			struct sx150x_platform_data *pdata)
+{
+	int err = 0;
+
+	if (pdata->reset_during_probe) {
+		err = sx150x_reset(chip);
+		if (err < 0)
+			return err;
+	}
+
 	err = sx150x_i2c_write(chip->client,
 			chip->dev_cfg->reg_misc,
 			0x01);
diff --git ...
From: Jean Delvare
Date: Sunday, August 29, 2010 - 2:42 am

Hi Gregory,




-- 
Jean Delvare
--

Previous thread: [PATCH] x86-64: Remove system_64.h by Brian Gerst on Saturday, August 28, 2010 - 10:11 am. (1 message)

Next thread: Re: [PATCH 2/7] drivers/usb/gadget: Remove double test by David Brownell on Saturday, August 28, 2010 - 11:11 am. (1 message)