From 3c1923b028afeeea4e5c59f8afcfc951f5f1dc72 Mon Sep 17 00:00:00 2001 From: Peter Li Date: Mon, 28 Aug 2017 22:39:33 +0800 Subject: [PATCH] update for non-irq case --- tas2557-core.c | 14 +++++++------- tas2557-regmap.c | 34 +++++++++++++++++++++++----------- tas2557.h | 2 +- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/tas2557-core.c b/tas2557-core.c index 7e9bab7..24495e1 100755 --- a/tas2557-core.c +++ b/tas2557-core.c @@ -295,7 +295,7 @@ static void failsafe(struct tas2557_priv *pTAS2557) pTAS2557->mnErrCode |= ERROR_FAILSAFE; if (hrtimer_active(&pTAS2557->mtimer)) hrtimer_cancel(&pTAS2557->mtimer); - pTAS2557->enableIRQ(pTAS2557, false); + pTAS2557->enableIRQ(pTAS2557, false, false); tas2557_dev_load_data(pTAS2557, p_tas2557_shutdown_data); pTAS2557->mbPowerUp = false; pTAS2557->hw_reset(pTAS2557); @@ -365,7 +365,7 @@ static int tas2557_load_coefficient(struct tas2557_priv *pTAS2557, hrtimer_cancel(&pTAS2557->mtimer); if (pProgram->mnAppMode == TAS2557_APP_TUNINGMODE) - pTAS2557->enableIRQ(pTAS2557, false); + pTAS2557->enableIRQ(pTAS2557, false, false); nResult = tas2557_dev_load_data(pTAS2557, p_tas2557_shutdown_data); if (nResult < 0) @@ -422,7 +422,7 @@ prog_coefficient: if (nResult < 0) goto end; if (pProgram->mnAppMode == TAS2557_APP_TUNINGMODE) { - pTAS2557->enableIRQ(pTAS2557, true); + pTAS2557->enableIRQ(pTAS2557, true, true); if (!hrtimer_active(&pTAS2557->mtimer)) { pTAS2557->mnDieTvReadCounter = 0; hrtimer_start(&pTAS2557->mtimer, @@ -490,7 +490,7 @@ int tas2557_enable(struct tas2557_priv *pTAS2557, bool bEnable) if (pProgram->mnAppMode == TAS2557_APP_TUNINGMODE) { /* turn on IRQ */ - pTAS2557->enableIRQ(pTAS2557, true); + pTAS2557->enableIRQ(pTAS2557, true, true); if (!hrtimer_active(&pTAS2557->mtimer)) { pTAS2557->mnDieTvReadCounter = 0; hrtimer_start(&pTAS2557->mtimer, @@ -507,7 +507,7 @@ int tas2557_enable(struct tas2557_priv *pTAS2557, bool bEnable) dev_dbg(pTAS2557->dev, "Enable: load shutdown sequence\n"); if (pProgram->mnAppMode == TAS2557_APP_TUNINGMODE) { /* turn off IRQ */ - pTAS2557->enableIRQ(pTAS2557, false); + pTAS2557->enableIRQ(pTAS2557, false, false); } nResult = tas2557_dev_load_data(pTAS2557, p_tas2557_shutdown_data); if (nResult < 0) @@ -1805,7 +1805,7 @@ int tas2557_set_program(struct tas2557_priv *pTAS2557, hrtimer_cancel(&pTAS2557->mtimer); if (pProgram->mnAppMode == TAS2557_APP_TUNINGMODE) - pTAS2557->enableIRQ(pTAS2557, false); + pTAS2557->enableIRQ(pTAS2557, false, false); nResult = tas2557_dev_load_data(pTAS2557, p_tas2557_shutdown_data); if (nResult < 0) @@ -1857,7 +1857,7 @@ int tas2557_set_program(struct tas2557_priv *pTAS2557, goto end; if (pProgram->mnAppMode == TAS2557_APP_TUNINGMODE) { - pTAS2557->enableIRQ(pTAS2557, true); + pTAS2557->enableIRQ(pTAS2557, true, true); if (!hrtimer_active(&pTAS2557->mtimer)) { pTAS2557->mnDieTvReadCounter = 0; hrtimer_start(&pTAS2557->mtimer, diff --git a/tas2557-regmap.c b/tas2557-regmap.c index e3c23fd..2810070 100755 --- a/tas2557-regmap.c +++ b/tas2557-regmap.c @@ -336,14 +336,16 @@ void tas2557_clearIRQ(struct tas2557_priv *pTAS2557) } -void tas2557_enableIRQ(struct tas2557_priv *pTAS2557, bool enable) +void tas2557_enableIRQ(struct tas2557_priv *pTAS2557, bool enable, bool startup_chk) { if (enable) { if (!pTAS2557->mbIRQEnable) { if (gpio_is_valid(pTAS2557->mnGpioINT)) { enable_irq(pTAS2557->mnIRQ); - /* check after 10 ms */ - schedule_delayed_work(&pTAS2557->irq_work, msecs_to_jiffies(10)); + if (startup_chk) { + /* check after 10 ms */ + schedule_delayed_work(&pTAS2557->irq_work, msecs_to_jiffies(10)); + } pTAS2557->mbIRQEnable = true; } } @@ -404,11 +406,12 @@ static void irq_work_routine(struct work_struct *work) dev_info(pTAS2557->dev, "%s, firmware not loaded\n", __func__); goto end; } - + nResult = tas2557_dev_write(pTAS2557, TAS2557_GPIO4_PIN_REG, 0x00); + if (nResult < 0) + goto program; nResult = tas2557_dev_read(pTAS2557, TAS2557_FLAGS_1, &nDevInt1Status); if (nResult >= 0) nResult = tas2557_dev_read(pTAS2557, TAS2557_FLAGS_2, &nDevInt2Status); - if (nResult < 0) goto program; @@ -500,10 +503,14 @@ static void irq_work_routine(struct work_struct *work) program: /* hardware reset and reload */ + nResult = -1; tas2557_set_program(pTAS2557, pTAS2557->mnCurrentProgram, pTAS2557->mnCurrentConfiguration); end: - + if (nResult >= 0) { + tas2557_dev_write(pTAS2557, TAS2557_GPIO4_PIN_REG, 0x07); + tas2557_enableIRQ(pTAS2557, true, false); + } #ifdef CONFIG_TAS2557_MISC mutex_unlock(&pTAS2557->file_lock); #endif @@ -517,7 +524,7 @@ static irqreturn_t tas2557_irq_handler(int irq, void *dev_id) { struct tas2557_priv *pTAS2557 = (struct tas2557_priv *)dev_id; - tas2557_enableIRQ(pTAS2557, false); + tas2557_enableIRQ(pTAS2557, false, false); /* get IRQ status after 100 ms */ schedule_delayed_work(&pTAS2557->irq_work, msecs_to_jiffies(100)); return IRQ_HANDLED; @@ -529,7 +536,10 @@ static enum hrtimer_restart temperature_timer_func(struct hrtimer *timer) if (pTAS2557->mbPowerUp) { schedule_work(&pTAS2557->mtimerwork); - schedule_delayed_work(&pTAS2557->irq_work, msecs_to_jiffies(1)); + if (gpio_is_valid(pTAS2557->mnGpioINT)) { + tas2557_enableIRQ(pTAS2557, false, false); + schedule_delayed_work(&pTAS2557->irq_work, msecs_to_jiffies(1)); + } } return HRTIMER_NORESTART; } @@ -630,9 +640,11 @@ static int tas2557_runtime_suspend(struct tas2557_priv *pTAS2557) dev_dbg(pTAS2557->dev, "cancel timer work\n"); cancel_work_sync(&pTAS2557->mtimerwork); } - if (delayed_work_pending(&pTAS2557->irq_work)) { - dev_dbg(pTAS2557->dev, "cancel IRQ work\n"); - cancel_delayed_work_sync(&pTAS2557->irq_work); + if (gpio_is_valid(pTAS2557->mnGpioINT)) { + if (delayed_work_pending(&pTAS2557->irq_work)) { + dev_dbg(pTAS2557->dev, "cancel IRQ work\n"); + cancel_delayed_work_sync(&pTAS2557->irq_work); + } } return 0; diff --git a/tas2557.h b/tas2557.h index d109454..33d91ef 100755 --- a/tas2557.h +++ b/tas2557.h @@ -440,7 +440,7 @@ struct tas2557_priv { int (*set_calibration)(struct tas2557_priv *pTAS2557, int calibration); void (*clearIRQ)(struct tas2557_priv *pTAS2557); - void (*enableIRQ)(struct tas2557_priv *pTAS2557, bool enable); + void (*enableIRQ)(struct tas2557_priv *pTAS2557, bool enable, bool startup_chk); void (*hw_reset)(struct tas2557_priv *pTAS2557); /* device is working, but system is suspended */ int (*runtime_suspend)(struct tas2557_priv *pTAS2557); -- 2.39.2