[PATCH RFC 3/3] usb: twl6030: remove the twl6030_readb function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently upon the read errors twl6030_readb returns a negative number.
The return value may be wrongly interpreted as the read value. Call
twl_i2c_read_u8 directly and in case of errors return thus preventing a
possible spurious detection.

Signed-off-by: Shubhrajyoti D <shubhrajyoti@xxxxxx>
---
untested.

 drivers/usb/otg/twl6030-usb.c |   39 +++++++++++++++++++++------------------
 1 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/otg/twl6030-usb.c b/drivers/usb/otg/twl6030-usb.c
index 11c22f3..8be63bf 100644
--- a/drivers/usb/otg/twl6030-usb.c
+++ b/drivers/usb/otg/twl6030-usb.c
@@ -124,20 +124,6 @@ static inline int twl6030_writeb(struct twl6030_usb *twl, u8 module,
 	return ret;
 }
 
-static inline u8 twl6030_readb(struct twl6030_usb *twl, u8 module, u8 address)
-{
-	u8 data, ret = 0;
-
-	ret = twl_i2c_read_u8(module, &data, address);
-	if (ret >= 0)
-		ret = data;
-	else
-		dev_err(twl->dev,
-			"readb[0x%x,0x%x] Error %d\n",
-					module, address, ret);
-	return ret;
-}
-
 static int twl6030_start_srp(struct phy_companion *comparator)
 {
 	struct twl6030_usb *twl = comparator_to_twl(comparator);
@@ -211,11 +197,22 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
 	struct twl6030_usb *twl = _twl;
 	enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN;
 	u8 vbus_state, hw_state;
+	int ret;
 
-	hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
+	ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, &hw_state, STS_HW_CONDITIONS);
+	if (ret < 0) {
+		dev_err(twl->dev, "readb[0x%x,0x%x] Error %d\n",
+			TWL6030_MODULE_ID0, STS_HW_CONDITIONS, ret);
+		return IRQ_HANDLED;
+	}
 
-	vbus_state = twl6030_readb(twl, TWL_MODULE_MAIN_CHARGE,
-						CONTROLLER_STAT1);
+	ret = twl_i2c_read_u8(TWL_MODULE_MAIN_CHARGE, &vbus_state,
+					CONTROLLER_STAT1);
+	if (ret < 0) {
+		dev_err(twl->dev, "readb[0x%x,0x%x] Error %d\n",
+			TWL_MODULE_MAIN_CHARGE, CONTROLLER_STAT1, ret);
+		return IRQ_HANDLED;
+	}
 	if (!(hw_state & STS_USB_ID)) {
 		if (vbus_state & VBUS_DET) {
 			regulator_enable(twl->usb3v3);
@@ -245,8 +242,14 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
 	struct twl6030_usb *twl = _twl;
 	enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN;
 	u8 hw_state;
+	int ret;
 
-	hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
+	ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, &hw_state, STS_HW_CONDITIONS);
+	if (ret < 0) {
+		dev_err(twl->dev, "readb[0x%x,0x%x] Error %d\n",
+			TWL6030_MODULE_ID0, STS_HW_CONDITIONS, ret);
+		return IRQ_HANDLED;
+	}
 
 	if (hw_state & STS_USB_ID) {
 
-- 
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux