Commit adbe6cfe authored by Michał Winiarski's avatar Michał Winiarski Committed by Mauro Carvalho Chehab

media: rc: nuvoton: Keep track of users on CIR enable/disable

Core rc keeps track of the users - let's use it to tweak the code and
use the common code path on suspend/resume.
Signed-off-by: default avatarMichał Winiarski <michal.winiarski@intel.com>
Cc: Jarod Wilson <jarod@redhat.com>
Signed-off-by: default avatarSean Young <sean@mess.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 70c30b1e
...@@ -543,27 +543,9 @@ static void nvt_cir_regs_init(struct nvt_dev *nvt) ...@@ -543,27 +543,9 @@ static void nvt_cir_regs_init(struct nvt_dev *nvt)
nvt_cir_reg_write(nvt, CIR_FIFOCON_TX_TRIGGER_LEV | nvt_cir_reg_write(nvt, CIR_FIFOCON_TX_TRIGGER_LEV |
CIR_FIFOCON_RX_TRIGGER_LEV, CIR_FIFOCON); CIR_FIFOCON_RX_TRIGGER_LEV, CIR_FIFOCON);
/*
* Enable TX and RX, specify carrier on = low, off = high, and set
* sample period (currently 50us)
*/
nvt_cir_reg_write(nvt,
CIR_IRCON_TXEN | CIR_IRCON_RXEN |
CIR_IRCON_RXINV | CIR_IRCON_SAMPLE_PERIOD_SEL,
CIR_IRCON);
/* clear hardware rx and tx fifos */ /* clear hardware rx and tx fifos */
nvt_clear_cir_fifo(nvt); nvt_clear_cir_fifo(nvt);
nvt_clear_tx_fifo(nvt); nvt_clear_tx_fifo(nvt);
/* clear any and all stray interrupts */
nvt_cir_reg_write(nvt, 0xff, CIR_IRSTS);
/* and finally, enable interrupts */
nvt_set_cir_iren(nvt);
/* enable the CIR logical device */
nvt_enable_logical_dev(nvt, LOGICAL_DEV_CIR);
} }
static void nvt_cir_wake_regs_init(struct nvt_dev *nvt) static void nvt_cir_wake_regs_init(struct nvt_dev *nvt)
...@@ -892,6 +874,32 @@ static irqreturn_t nvt_cir_isr(int irq, void *data) ...@@ -892,6 +874,32 @@ static irqreturn_t nvt_cir_isr(int irq, void *data)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static void nvt_enable_cir(struct nvt_dev *nvt)
{
unsigned long flags;
/* enable the CIR logical device */
nvt_enable_logical_dev(nvt, LOGICAL_DEV_CIR);
spin_lock_irqsave(&nvt->lock, flags);
/*
* Enable TX and RX, specify carrier on = low, off = high, and set
* sample period (currently 50us)
*/
nvt_cir_reg_write(nvt, CIR_IRCON_TXEN | CIR_IRCON_RXEN |
CIR_IRCON_RXINV | CIR_IRCON_SAMPLE_PERIOD_SEL,
CIR_IRCON);
/* clear all pending interrupts */
nvt_cir_reg_write(nvt, 0xff, CIR_IRSTS);
/* enable interrupts */
nvt_set_cir_iren(nvt);
spin_unlock_irqrestore(&nvt->lock, flags);
}
static void nvt_disable_cir(struct nvt_dev *nvt) static void nvt_disable_cir(struct nvt_dev *nvt)
{ {
unsigned long flags; unsigned long flags;
...@@ -920,25 +928,8 @@ static void nvt_disable_cir(struct nvt_dev *nvt) ...@@ -920,25 +928,8 @@ static void nvt_disable_cir(struct nvt_dev *nvt)
static int nvt_open(struct rc_dev *dev) static int nvt_open(struct rc_dev *dev)
{ {
struct nvt_dev *nvt = dev->priv; struct nvt_dev *nvt = dev->priv;
unsigned long flags;
/* enable the CIR logical device */ nvt_enable_cir(nvt);
nvt_enable_logical_dev(nvt, LOGICAL_DEV_CIR);
spin_lock_irqsave(&nvt->lock, flags);
/* set function enable flags */
nvt_cir_reg_write(nvt, CIR_IRCON_TXEN | CIR_IRCON_RXEN |
CIR_IRCON_RXINV | CIR_IRCON_SAMPLE_PERIOD_SEL,
CIR_IRCON);
/* clear all pending interrupts */
nvt_cir_reg_write(nvt, 0xff, CIR_IRSTS);
/* enable interrupts */
nvt_set_cir_iren(nvt);
spin_unlock_irqrestore(&nvt->lock, flags);
return 0; return 0;
} }
...@@ -1093,19 +1084,13 @@ static void nvt_remove(struct pnp_dev *pdev) ...@@ -1093,19 +1084,13 @@ static void nvt_remove(struct pnp_dev *pdev)
static int nvt_suspend(struct pnp_dev *pdev, pm_message_t state) static int nvt_suspend(struct pnp_dev *pdev, pm_message_t state)
{ {
struct nvt_dev *nvt = pnp_get_drvdata(pdev); struct nvt_dev *nvt = pnp_get_drvdata(pdev);
unsigned long flags;
nvt_dbg("%s called", __func__); nvt_dbg("%s called", __func__);
spin_lock_irqsave(&nvt->lock, flags); mutex_lock(&nvt->rdev->lock);
if (nvt->rdev->users)
/* disable all CIR interrupts */ nvt_disable_cir(nvt);
nvt_cir_reg_write(nvt, 0, CIR_IREN); mutex_unlock(&nvt->rdev->lock);
spin_unlock_irqrestore(&nvt->lock, flags);
/* disable cir logical dev */
nvt_disable_logical_dev(nvt, LOGICAL_DEV_CIR);
/* make sure wake is enabled */ /* make sure wake is enabled */
nvt_enable_wake(nvt); nvt_enable_wake(nvt);
...@@ -1122,6 +1107,11 @@ static int nvt_resume(struct pnp_dev *pdev) ...@@ -1122,6 +1107,11 @@ static int nvt_resume(struct pnp_dev *pdev)
nvt_cir_regs_init(nvt); nvt_cir_regs_init(nvt);
nvt_cir_wake_regs_init(nvt); nvt_cir_wake_regs_init(nvt);
mutex_lock(&nvt->rdev->lock);
if (nvt->rdev->users)
nvt_enable_cir(nvt);
mutex_unlock(&nvt->rdev->lock);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment