From 2f2096432aa4490ae527dc1ae373a5947d1f95d2 Mon Sep 17 00:00:00 2001 From: Tracy Yi Date: Thu, 25 Apr 2019 17:32:10 +0800 Subject: [PATCH] Correct IRQ issues Signed-off-by: Tracy Yi --- tas2562-codec.c | 30 ++++++++++++++++++++---------- tas2562-regmap.c | 38 +++++++++++++++++++++++++++++++++++++- tas2562.h | 11 ++++------- 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/tas2562-codec.c b/tas2562-codec.c index 542876c..e77b2b7 100644 --- a/tas2562-codec.c +++ b/tas2562-codec.c @@ -47,9 +47,8 @@ #define TAS2562_MDELAY 0xFFFFFFFE #define TAS2562_MSLEEP 0xFFFFFFFD -static char pICN[] = {0x00, 0x03, 0x46, 0xdc}; static char const *iv_enable_text[] = {"Off", "On"}; -static int tas2562iv_enable; +static int tas2562iv_enable = 1; static int mbMute; static const struct soc_enum tas2562_enum[] = { SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(iv_enable_text), iv_enable_text), @@ -268,6 +267,7 @@ static int tas2562_set_power_state(struct tas2562_priv *pTAS2562, int state) { int nResult = 0; /*unsigned int nValue;*/ + int irqreg; if ((pTAS2562->mbMute) && (state == TAS2562_POWER_ACTIVE)) state = TAS2562_POWER_MUTE; @@ -284,16 +284,18 @@ static int tas2562_set_power_state(struct tas2562_priv *pTAS2562, int state) if (nResult < 0) return nResult; - nResult = pTAS2562->update_bits(pTAS2562, TAS2562_PowerControl, - TAS2562_PowerControl_OperationalMode10_Mask, - TAS2562_PowerControl_OperationalMode10_Active); - if (nResult < 0) - return nResult; +//Clear latched IRQ before power on + + pTAS2562->update_bits(pTAS2562, TAS2562_InterruptConfiguration, + TAS2562_InterruptConfiguration_LTCHINTClear_Mask, + TAS2562_InterruptConfiguration_LTCHINTClear); + + pTAS2562->read(pTAS2562, TAS2562_LatchedInterruptReg0, &irqreg); + dev_info(pTAS2562->dev, "IRQ reg is: %s %d, %d\n", __func__, irqreg, __LINE__); + pTAS2562->mbPowerUp = true; - dev_info(pTAS2562->dev, "set ICN to -80dB\n"); - nResult = pTAS2562->bulk_write(pTAS2562, TAS2562_ICN_REG, pICN, 4); pTAS2562->mnPowerState = TAS2562_POWER_ACTIVE; - pTAS2562->enableIRQ(pTAS2562, true); + schedule_delayed_work(&pTAS2562->irq_work, msecs_to_jiffies(10)); break; case TAS2562_POWER_MUTE: @@ -772,6 +774,13 @@ static int tas2562_load_init(struct tas2562_priv *pTAS2562) 0x7); if(ret < 0) return ret; + + ret = pTAS2562->update_bits(pTAS2562, TAS2562_PlaybackConfigurationReg0, + TAS2562_PlaybackConfigurationReg0_AmplifierLevel51_Mask, + 0xd << 1); + if(ret < 0) + return ret; + #endif ret = pTAS2562->write(pTAS2562, TAS2562_MiscConfigurationReg0, 0xcf); @@ -877,6 +886,7 @@ void tas2562_LoadConfig(struct tas2562_priv *pTAS2562) msleep(3); tas2562_load_init(pTAS2562); + tas2562_iv_enable(pTAS2562, tas2562iv_enable); ret = tas2562_set_slot(pTAS2562->codec, pTAS2562->mnSlot_width); if (ret < 0) diff --git a/tas2562-regmap.c b/tas2562-regmap.c index daac3ba..948125e 100644 --- a/tas2562-regmap.c +++ b/tas2562-regmap.c @@ -39,6 +39,8 @@ #include "tas2562-codec.h" #include "tas2562-misc.h" +static char pICN[] = {0x00, 0x03, 0x46, 0xdc}; + static int tas2562_change_book_page(struct tas2562_priv *pTAS2562, int book, int page) { @@ -269,6 +271,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(pTAS2562->dev, "%s\n", __func__); #ifdef CONFIG_TAS2562_CODEC @@ -285,6 +288,15 @@ static void irq_work_routine(struct work_struct *work) goto end; } + nResult = tas2562_dev_write(pTAS2562, TAS2562_InterruptMaskReg0, + TAS2562_InterruptMaskReg0_Disable); + if (nResult < 0) + goto reload; + nResult = tas2562_dev_write(pTAS2562, TAS2562_InterruptMaskReg1, + TAS2562_InterruptMaskReg1_Disable); + if (nResult < 0) + goto reload; + nResult = tas2562_dev_read(pTAS2562, TAS2562_LatchedInterruptReg0, &nDevInt1Status); if (nResult >= 0) nResult = tas2562_dev_read(pTAS2562, TAS2562_LatchedInterruptReg1, &nDevInt2Status); @@ -294,7 +306,7 @@ static void irq_work_routine(struct work_struct *work) dev_dbg(pTAS2562->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 & TAS2562_LatchedInterruptReg0_OCEFlagSticky_Interrupt) { @@ -341,6 +353,21 @@ static void irq_work_routine(struct work_struct *work) != TAS2562_PowerControl_OperationalMode10_Shutdown) break; + pTAS2562->read(pTAS2562, TAS2562_LatchedInterruptReg0, &irqreg); + dev_info(pTAS2562->dev, "IRQ reg is: %s %d, %d\n", __func__, irqreg, __LINE__); + + nResult = pTAS2562->update_bits(pTAS2562, TAS2562_PowerControl, + TAS2562_PowerControl_OperationalMode10_Mask, + TAS2562_PowerControl_OperationalMode10_Active); + if (nResult < 0) + goto reload; + + dev_info(pTAS2562->dev, "set ICN to -80dB\n"); + nResult = pTAS2562->bulk_write(pTAS2562, TAS2562_ICN_REG, pICN, 4); + + pTAS2562->read(pTAS2562, TAS2562_LatchedInterruptReg0, &irqreg); + dev_info(pTAS2562->dev, "IRQ reg is: %s, %d, %d\n", __func__, irqreg, __LINE__); + nCounter--; if (nCounter > 0) { /* in case check pow status just after power on TAS2562 */ @@ -362,6 +389,14 @@ static void irq_work_routine(struct work_struct *work) pTAS2562->mnErrCode &= ~ERROR_CLASSD_PWR; } + nResult = tas2562_dev_write(pTAS2562, TAS2562_InterruptMaskReg0, 0xf8); + if (nResult < 0) + goto reload; + + nResult = tas2562_dev_write(pTAS2562, TAS2562_InterruptMaskReg1, 0xb1); + if (nResult < 0) + goto reload; + goto end; reload: @@ -492,6 +527,7 @@ static int tas2562_i2c_probe(struct i2c_client *pClient, struct tas2562_priv *pTAS2562; int nResult; + dev_err(&pClient->dev, "Driver ID: %s\n", TAS2562_DRIVER_ID); dev_info(&pClient->dev, "%s enter\n", __func__); pTAS2562 = devm_kzalloc(&pClient->dev, diff --git a/tas2562.h b/tas2562.h index fd59716..587ad9b 100644 --- a/tas2562.h +++ b/tas2562.h @@ -2,8 +2,10 @@ #ifndef __TAS2562_ #define __TAS2562_ +#define TAS2562_DRIVER_ID "1.0.1" + /* Page Control Register */ -#define TAS2560_PAGECTL_REG 0 +#define TAS2562_PAGECTL_REG 0 /* Book Control Register (available in page0 of each book) */ #define TAS2562_BOOKCTL_PAGE 0 @@ -12,11 +14,6 @@ #define TAS2562_REG(book, page, reg) (((book * 256 * 128) + \ (page * 128)) + reg) -#if 0 - /* Page */ -#define TAS2562_Page TAS2562_REG(0x0, 0x0, 0x0) -#define TAS2562_Page_Page_Mask (0xff << 0) -#endif #define TAS2562_BOOK_ID(reg) (reg / (256 * 128)) @@ -528,7 +525,7 @@ TAS2562_InterruptConfiguration_PININTConfig10_Assert2msOnLatchedInterrupts \ #define TAS2562_VBatFilter TAS2562_REG(0x0, 0x0, 0x3b) #define TAS2562_ClassHReleaseTimer TAS2562_REG(0x0, 0x0, 0x3c) -#define TAS2562_ICN_REG TAS2562_REG(0x0, 0x2, 0x5c) +#define TAS2562_ICN_REG TAS2562_REG(0x0, 0x2, 0x64) #define TAS2562_TestPageConfiguration TAS2562_REG(0x0, 0xfd, 0xd) #define TAS2562_ClassDConfiguration1 TAS2562_REG(0x0, 0xfd, 0x19) -- 2.39.2