Add retry for safe failure
authorTracy Yi <tracy-yi@ti.com>
Mon, 4 Dec 2017 08:44:51 +0000 (16:44 +0800)
committerTracy Yi <tracy-yi@ti.com>
Mon, 4 Dec 2017 08:44:51 +0000 (16:44 +0800)
Signed-off-by: Tracy Yi <tracy-yi@ti.com>
tas2557-core.c
tas2557-regmap.c
tas2557.h

index 24495e17b11d27d86312c4641a5fda5bd89338e5..a0d55e5e97012dabcf24b3d9aae4b3abeff975ed 100755 (executable)
@@ -47,7 +47,7 @@
 #define        PPC_DRIVER_CFGDEV_NONCRC        0x00000101
 
 #define TAS2557_CAL_NAME    "/data/tas2557_cal.bin"
-
+#define RESTART_MAX 3
 
 static int tas2557_load_calibration(struct tas2557_priv *pTAS2557,
        char *pFileName);
@@ -295,6 +295,15 @@ static void failsafe(struct tas2557_priv *pTAS2557)
        pTAS2557->mnErrCode |= ERROR_FAILSAFE;
        if (hrtimer_active(&pTAS2557->mtimer))
                hrtimer_cancel(&pTAS2557->mtimer);
+
+       if(pTAS2557->mnRestart < RESTART_MAX)
+       {
+               pTAS2557->mnRestart ++;
+               msleep(100);
+               dev_err(pTAS2557->dev, "I2C COMM error, restart SmartAmp.\n");
+               schedule_delayed_work(&pTAS2557->irq_work, msecs_to_jiffies(100));
+               return;
+       }
        pTAS2557->enableIRQ(pTAS2557, false, false);
        tas2557_dev_load_data(pTAS2557, p_tas2557_shutdown_data);
        pTAS2557->mbPowerUp = false;
@@ -455,6 +464,8 @@ int tas2557_enable(struct tas2557_priv *pTAS2557, bool bEnable)
        if ((nValue&0xff) != TAS2557_SAFE_GUARD_PATTERN) {
                dev_err(pTAS2557->dev, "ERROR safe guard failure!\n");
                nResult = -EPIPE;
+               pTAS2557->mnErrCode = ERROR_SAFE_GUARD;
+               pTAS2557->mbPowerUp = true;
                goto end;
        }
 
@@ -498,6 +509,7 @@ int tas2557_enable(struct tas2557_priv *pTAS2557, bool bEnable)
                                }
                        }
                        pTAS2557->mbPowerUp = true;
+                       pTAS2557->mnRestart = 0;
                }
        } else {
                if (pTAS2557->mbPowerUp) {
@@ -514,6 +526,7 @@ int tas2557_enable(struct tas2557_priv *pTAS2557, bool bEnable)
                                goto end;
 
                        pTAS2557->mbPowerUp = false;
+                       pTAS2557->mnRestart = 0;
                }
        }
 
@@ -521,7 +534,7 @@ int tas2557_enable(struct tas2557_priv *pTAS2557, bool bEnable)
 
 end:
        if (nResult < 0) {
-               if (pTAS2557->mnErrCode & (ERROR_DEVA_I2C_COMM | ERROR_PRAM_CRCCHK | ERROR_YRAM_CRCCHK))
+               if (pTAS2557->mnErrCode & (ERROR_DEVA_I2C_COMM | ERROR_PRAM_CRCCHK | ERROR_YRAM_CRCCHK | ERROR_SAFE_GUARD))
                        failsafe(pTAS2557);
        }
 
@@ -2018,4 +2031,4 @@ end:
 
 MODULE_AUTHOR("Texas Instruments Inc.");
 MODULE_DESCRIPTION("TAS2557 common functions for Android Linux");
-MODULE_LICENSE("GPL v2");
\ No newline at end of file
+MODULE_LICENSE("GPL v2");
index 281007072882cfbff836c71daf193fa392457a64..7aed6d3cba9417e79228b2aaf63e0ed1d8a466dd 100755 (executable)
@@ -350,11 +350,9 @@ void tas2557_enableIRQ(struct tas2557_priv *pTAS2557, bool enable, bool startup_
                        }
                }
        } else {
-               if (pTAS2557->mbIRQEnable) {
-                       if (gpio_is_valid(pTAS2557->mnGpioINT))
-                               disable_irq_nosync(pTAS2557->mnIRQ);
-                       pTAS2557->mbIRQEnable = false;
-               }
+               if (gpio_is_valid(pTAS2557->mnGpioINT))
+                       disable_irq_nosync(pTAS2557->mnIRQ);
+               pTAS2557->mbIRQEnable = false;
        }
 }
 
@@ -391,6 +389,9 @@ static void irq_work_routine(struct work_struct *work)
        mutex_lock(&pTAS2557->file_lock);
 #endif
 
+       if(pTAS2557->mnErrCode & ERROR_FAILSAFE)
+               goto program;
+
        if (pTAS2557->mbRuntimeSuspend) {
                dev_info(pTAS2557->dev, "%s, Runtime Suspended\n", __func__);
                goto end;
@@ -757,6 +758,7 @@ static int tas2557_i2c_probe(struct i2c_client *pClient,
        pTAS2557->hw_reset = tas2557_hw_reset;
        pTAS2557->runtime_suspend = tas2557_runtime_suspend;
        pTAS2557->runtime_resume = tas2557_runtime_resume;
+       pTAS2557->mnRestart = 0;
 
        mutex_init(&pTAS2557->dev_lock);
 
@@ -899,4 +901,4 @@ MODULE_AUTHOR("Texas Instruments Inc.");
 MODULE_DESCRIPTION("TAS2557 I2C Smart Amplifier driver");
 MODULE_LICENSE("GPL v2");
 
-#endif
\ No newline at end of file
+#endif
index 33d91efee12589c08832d5627b25755b5a9bb6af..3f44f27b23782f10950d9b795c0dbdc6e72b51a1 100755 (executable)
--- a/tas2557.h
+++ b/tas2557.h
 #define        ERROR_UNDER_VOLTAGE     0x00000800
 #define        ERROR_OVER_CURRENT      0x00001000
 #define        ERROR_CLASSD_PWR        0x00002000
+#define        ERROR_SAFE_GUARD        0x00004000
 #define        ERROR_FAILSAFE          0x40000000
 
 struct TBlock {
@@ -464,6 +465,7 @@ struct tas2557_priv {
        bool mbRuntimeSuspend;
 
        unsigned int mnErrCode;
+       unsigned int mnRestart;
 
        /* for configurations with maximum TLimit 0x7fffffff,
         * bypass calibration update, usually used in factory test