return back the modification
[tas256xsw-android/tas2563-android-driver.git] / tas2563-regmap.c
index a9c580f4bcb35fa2ddb65dea4e5d92bed83257b7..a461828381972e3c68041f6ffb41c4e6fe84f04a 100755 (executable)
@@ -56,6 +56,8 @@
 
 #define LOW_TEMPERATURE_GAIN 6
 #define LOW_TEMPERATURE_COUNTER 12
+static char pICN[] = {0x00, 0x00, 0x2f, 0x2c};
+static char pICNDelay[] = {0x00, 0x00, 0x70, 0x80};
 
 static int tas2563_change_book_page(struct tas2563_priv *pTAS2563,
        int book, int page)
@@ -115,9 +117,9 @@ static int tas2563_dev_read(struct tas2563_priv *pTAS2563,
                dev_err(pTAS2563->dev, "%s, ERROR, L=%d, E=%d\n",
                        __func__, __LINE__, nResult);
        else
-               dev_dbg(pTAS2563->dev, "%s: BOOK:PAGE:REG %u:%u:%u\n", __func__,
+               dev_dbg(pTAS2563->dev, "%s: BOOK:PAGE:REG %u:%u:%u,%x\n", __func__,
                        TAS2563_BOOK_ID(reg), TAS2563_PAGE_ID(reg),
-                       TAS2563_PAGE_REG(reg));
+                       TAS2563_PAGE_REG(reg), *pValue);
 
 end:
        mutex_unlock(&pTAS2563->dev_lock);
@@ -262,7 +264,7 @@ static const struct reg_default tas2563_reg_defaults[] = {
        { TAS2563_TDMConfigurationReg3, 0x10 },
        { TAS2563_InterruptMaskReg0, 0xfc },
        { TAS2563_InterruptMaskReg1, 0xb1 },
-       { TAS2563_InterruptConfiguration, 0x05 },
+       { TAS2563_InterruptConfiguration, 0x1d },
        { TAS2563_MiscIRQ, 0x81 },
        { TAS2563_ClockConfiguration, 0x0c },
 
@@ -328,6 +330,7 @@ static void irq_work_routine(struct work_struct *work)
        unsigned int nDevInt1Status = 0, nDevInt2Status = 0;
        int nCounter = 2;
        int nResult = 0;
+       int irqreg;
 
        dev_info(pTAS2563->dev, "%s\n", __func__);
 #ifdef CONFIG_TAS2563_CODEC
@@ -344,24 +347,24 @@ static void irq_work_routine(struct work_struct *work)
                goto end;
        }
 
-       nResult = regmap_write(pTAS2563->regmap, TAS2563_InterruptMaskReg0,
+       nResult = tas2563_dev_write(pTAS2563, TAS2563_InterruptMaskReg0,
                                TAS2563_InterruptMaskReg0_Disable);
-       nResult = regmap_write(pTAS2563->regmap, TAS2563_InterruptMaskReg1,
+       nResult = tas2563_dev_write(pTAS2563, TAS2563_InterruptMaskReg1,
                                TAS2563_InterruptMaskReg1_Disable);
 
        if (nResult < 0)
                goto reload;
 
-       nResult = regmap_read(pTAS2563->regmap, TAS2563_LatchedInterruptReg0, &nDevInt1Status);
+       nResult = tas2563_dev_read(pTAS2563, TAS2563_LatchedInterruptReg0, &nDevInt1Status);
        if (nResult >= 0)
-               nResult = regmap_read(pTAS2563->regmap, TAS2563_LatchedInterruptReg1, &nDevInt2Status);
+               nResult = tas2563_dev_read(pTAS2563, TAS2563_LatchedInterruptReg1, &nDevInt2Status);
        else
                goto reload;
 
-       dev_dbg(pTAS2563->dev, "IRQ status : 0x%x, 0x%x\n",
+       dev_info(pTAS2563->dev, "IRQ status : 0x%x, 0x%x\n",
                        nDevInt1Status, nDevInt2Status);
 
-       if (((nDevInt1Status & 0x3) != 0) || ((nDevInt2Status & 0x0f) != 0)) {
+       if (((nDevInt1Status & 0x7) != 0) || ((nDevInt2Status & 0x0f) != 0)) {
                /* in case of INT_OC, INT_OT, INT_OVLT, INT_UVLT, INT_BO */
 
                if (nDevInt1Status & TAS2563_LatchedInterruptReg0_OCEFlagSticky_Interrupt) {
@@ -399,7 +402,7 @@ static void irq_work_routine(struct work_struct *work)
                nCounter = 2;
 
                while (nCounter > 0) {
-                       nResult = regmap_read(pTAS2563->regmap, TAS2563_PowerControl, &nDevInt1Status);
+                       nResult = tas2563_dev_read(pTAS2563, TAS2563_PowerControl, &nDevInt1Status);
                        if (nResult < 0)
                                goto reload;
 
@@ -407,12 +410,42 @@ static void irq_work_routine(struct work_struct *work)
                                != TAS2563_PowerControl_OperationalMode10_Shutdown)
                                break;
 
+                       pTAS2563->read(pTAS2563, TAS2563_LatchedInterruptReg0, &irqreg);
+                       dev_info(pTAS2563->dev, "IRQ reg is: %s %d, %d\n", __func__, irqreg, __LINE__);
+
+                       nResult = pTAS2563->update_bits(pTAS2563, TAS2563_PowerControl,
+                               TAS2563_PowerControl_OperationalMode10_Mask |
+                               TAS2563_PowerControl_ISNSPower_Mask |
+                               TAS2563_PowerControl_VSNSPower_Mask,
+                               TAS2563_PowerControl_OperationalMode10_Active |
+                               TAS2563_PowerControl_VSNSPower_Active |
+                               TAS2563_PowerControl_ISNSPower_Active);
+                       if (nResult < 0)
+                               goto reload;
+
+                       pTAS2563->read(pTAS2563, TAS2563_LatchedInterruptReg0, &irqreg);
+                       dev_info(pTAS2563->dev, "IRQ reg is: %s, %d, %d\n", __func__, irqreg, __LINE__);
+
+                       dev_info(pTAS2563->dev, "set ICN to -90dB\n");
+                       nResult = pTAS2563->bulk_write(pTAS2563, TAS2563_ICN_REG, pICN, 4);
+                       if(nResult < 0)
+                               goto reload;
+
+                       pTAS2563->read(pTAS2563, TAS2563_LatchedInterruptReg0, &irqreg);
+                       dev_info(pTAS2563->dev, "IRQ reg is: %d, %d\n", irqreg, __LINE__);
+
+                       dev_info(pTAS2563->dev, "set ICN delay\n");
+                       nResult = pTAS2563->bulk_write(pTAS2563, TAS2563_ICN_DELAY, pICNDelay, 4);
+
+                       pTAS2563->read(pTAS2563, TAS2563_LatchedInterruptReg0, &irqreg);
+                       dev_info(pTAS2563->dev, "IRQ reg is: %d, %d\n", irqreg, __LINE__);
+
                        nCounter--;
                        if (nCounter > 0) {
-                               /* in case check pow status just after power on TAS2563 */
+                               /* in case check power status just after power on TAS2563 */
                                dev_dbg(pTAS2563->dev, "PowSts B: 0x%x, check again after 10ms\n",
                                        nDevInt1Status);
-                               msleep(10);
+                               msleep(20);
                        }
                }
 
@@ -428,11 +461,11 @@ static void irq_work_routine(struct work_struct *work)
                pTAS2563->mnErrCode &= ~ERROR_CLASSD_PWR;
        }
 
-       nResult = regmap_write(pTAS2563->regmap, TAS2563_InterruptMaskReg0, 0xfc);
+       nResult = tas2563_dev_write(pTAS2563, TAS2563_InterruptMaskReg0, 0xf8);
        if (nResult < 0)
                goto reload;
 
-       nResult = regmap_write(pTAS2563->regmap, TAS2563_InterruptMaskReg1, 0xb1);
+       nResult = tas2563_dev_write(pTAS2563, TAS2563_InterruptMaskReg1, 0xb1);
        if (nResult < 0)
                goto reload;
 
@@ -444,11 +477,11 @@ reload:
        //tas2563_LoadConfig(pTAS2563);
        tas2563_set_program(pTAS2563, pTAS2563->mnCurrentProgram, pTAS2563->mnCurrentConfiguration);
 
+end:
        if (nResult >= 0) {
                tas2563_enableIRQ(pTAS2563, true);
        }
-       
-end:
+
 #ifdef CONFIG_TAS2563_CODEC
        mutex_unlock(&pTAS2563->codec_lock);
 #endif
@@ -602,6 +635,7 @@ static int tas2563_i2c_probe(struct i2c_client *pClient,
        unsigned int nValue = 0;
        const char *pFWName;
 
+       dev_err(&pClient->dev, "Driver ID: %s\n", TAS2563_DRIVER_ID);
        dev_info(&pClient->dev, "%s enter\n", __func__);
 
        pTAS2563 = devm_kzalloc(&pClient->dev, sizeof(struct tas2563_priv), GFP_KERNEL);
@@ -677,7 +711,7 @@ static int tas2563_i2c_probe(struct i2c_client *pClient,
                dev_dbg(pTAS2563->dev, "irq = %d\n", pTAS2563->mnIRQ);
                INIT_DELAYED_WORK(&pTAS2563->irq_work, irq_work_routine);
                nResult = request_threaded_irq(pTAS2563->mnIRQ, tas2563_irq_handler,
-                                       NULL, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+                                       NULL, IRQF_TRIGGER_LOW | IRQF_ONESHOT,
                                        pClient->name, pTAS2563);
                if (nResult < 0) {
                        dev_err(pTAS2563->dev,
@@ -790,4 +824,4 @@ MODULE_AUTHOR("Texas Instruments Inc.");
 MODULE_DESCRIPTION("TAS2563 I2C Smart Amplifier driver");
 MODULE_LICENSE("GPL v2");
 
-#endif
+#endif
\ No newline at end of file