audio: a2220: Handle probe failure
Vijay Mali [Thu, 4 Apr 2013 15:15:00 +0000 (20:15 +0530)]
- Avoid unwanted i2c write calls if probe fails.
- Add seperate function for sending boot message.
- Reduce i2c retry count to 1.
- This ensures graceful exit in case of failure.
- Boot log does not show lot of i2c failure messages after the fix.

Bug 1263841

Change-Id: I8a5f4c335e42aea69647f50afc48494084967825
Signed-off-by: Vijay Mali <vmali@nvidia.com>
Reviewed-on: http://git-master/r/216528
GVS: Gerrit_Virtual_Submit
Reviewed-by: Scott Peterson <speterson@nvidia.com>

drivers/misc/a2220.c
include/linux/a2220.h

index a3e9fbc..7eacbe6 100644 (file)
@@ -305,13 +305,10 @@ static int hpt_longCmd_execute(unsigned char *i2c_cmds, int size)
 }
 #endif
 
-static ssize_t a2220_bootup_init(struct a2220img *pImg)
+static int a2220_set_boot_mode()
 {
-       struct a2220img *vp = pImg;
-       int rc, pass = 0;
-       int remaining;
+       int rc;
        int retry = RETRY_CNT;
-       unsigned char *index;
        char buf[2];
 
        mdelay(100);
@@ -335,19 +332,39 @@ static ssize_t a2220_bootup_init(struct a2220img *pImg)
                buf[1] = A2220_msg_BOOT & 0xff;
                rc = a2220_i2c_write(buf, 2);
                if (rc < 0) {
-                       printk(KERN_ERR "%s: set boot mode error (%d retries left)\n",
+                       printk(KERN_ERR "%s: write error (%d retries left)\n",
                               __func__, retry);
-                       continue;
+                       if (retry > 0)
+                               continue;
+                       else
+                               return rc;
                }
 
                mdelay(1);
                rc = a2220_i2c_read(buf, 1);
 
                if (rc < 0) {
-                       printk(KERN_ERR "%s: boot mode ack error (%d retries left)\n",
+                       printk(KERN_ERR "%s: ack error (%d retries left)\n",
                               __func__, retry);
                        continue;
                }
+       }
+
+       return rc;
+}
+
+static ssize_t a2220_bootup_init(struct a2220img *pImg)
+{
+       struct a2220img *vp = pImg;
+       int rc, pass = 0;
+       int remaining;
+       int retry = RETRY_CNT;
+       unsigned char *index;
+       char buf[2];
+
+       mdelay(10);
+
+       while (retry--) {
                remaining = vp->img_size / 32;
                index = vp->buf;
                pr_info("%s: starting to load image (%d passes)...\n",
@@ -1321,6 +1338,13 @@ static int a2220_probe(struct i2c_client *client,
                goto err_free_gpio_all;
        }
 
+       /* send boot msg */
+       rc = a2220_set_boot_mode();
+       if (rc < 0) {
+               printk(KERN_ERR "%s: failed %d\n", __func__, rc);
+               goto err_free_gpio_all;
+       }
+
        /* A2220 firmware download start .. */
        a2220_ioctl2(A2220_BOOTUP_INIT, 0);
 
@@ -1351,7 +1375,7 @@ static int a2220_probe(struct i2c_client *client,
        if (pdata->gpio_a2220_micsel)
                gpio_free(pdata->gpio_a2220_micsel);
  err_free_gpio_clk:
-       if (control_a2220_clk)
+       if (pdata->gpio_a2220_clk)
                gpio_free(pdata->gpio_a2220_clk);
  err_alloc_data_failed:
 
index 78f6404..de2af47 100644 (file)
@@ -251,7 +251,7 @@ on = 0x0001 (Default) */
 
 /* general definitions */
 #define TIMEOUT                        20      /* ms */
-#define RETRY_CNT              5
+#define RETRY_CNT              1
 #define POLLING_RETRY_CNT      3
 #define A2220_ERROR_CODE       0xffff
 #define A2220_SLEEP            0