[PATCH 4/4] media: sunxi-cir: Implement suspend/resume/shutdown callbacks

36 views
Skip to first unread message

Samuel Holland

unread,
Jan 12, 2021, 11:51:39 PM1/12/21
to Sean Young, Mauro Carvalho Chehab, Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Samuel Holland
To save power, gate/reset the hardware block while the system is
asleep or powered off.

Signed-off-by: Samuel Holland <sam...@sholland.org>
---
drivers/media/rc/sunxi-cir.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
index ccb9d6b4225d..a0bdbf6f66c9 100644
--- a/drivers/media/rc/sunxi-cir.c
+++ b/drivers/media/rc/sunxi-cir.c
@@ -234,6 +234,20 @@ static void sunxi_ir_hw_exit(struct device *dev)
reset_control_assert(ir->rst);
}

+static int __maybe_unused sunxi_ir_suspend(struct device *dev)
+{
+ sunxi_ir_hw_exit(dev);
+
+ return 0;
+}
+
+static int __maybe_unused sunxi_ir_resume(struct device *dev)
+{
+ return sunxi_ir_hw_init(dev);
+}
+
+static SIMPLE_DEV_PM_OPS(sunxi_ir_pm_ops, sunxi_ir_suspend, sunxi_ir_resume);
+
static int sunxi_ir_probe(struct platform_device *pdev)
{
int ret = 0;
@@ -362,6 +376,11 @@ static int sunxi_ir_remove(struct platform_device *pdev)
return 0;
}

+static void sunxi_ir_shutdown(struct platform_device *pdev)
+{
+ sunxi_ir_hw_exit(&pdev->dev);
+}
+
static const struct sunxi_ir_quirks sun4i_a10_ir_quirks = {
.has_reset = false,
.fifo_size = 16,
@@ -397,9 +416,11 @@ MODULE_DEVICE_TABLE(of, sunxi_ir_match);
static struct platform_driver sunxi_ir_driver = {
.probe = sunxi_ir_probe,
.remove = sunxi_ir_remove,
+ .shutdown = sunxi_ir_shutdown,
.driver = {
.name = SUNXI_IR_DEV,
.of_match_table = sunxi_ir_match,
+ .pm = &sunxi_ir_pm_ops,
},
};

--
2.26.2

Samuel Holland

unread,
Jan 12, 2021, 11:51:39 PM1/12/21
to Sean Young, Mauro Carvalho Chehab, Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Samuel Holland
The register writes during driver removal occur after the device is
already put back in reset, so they never had any effect.

Signed-off-by: Samuel Holland <sam...@sholland.org>
---
drivers/media/rc/sunxi-cir.c | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
index 8555c7798706..0a7f7eab3cc3 100644
--- a/drivers/media/rc/sunxi-cir.c
+++ b/drivers/media/rc/sunxi-cir.c
@@ -342,22 +342,12 @@ static int sunxi_ir_probe(struct platform_device *pdev)

static int sunxi_ir_remove(struct platform_device *pdev)
{
- unsigned long flags;
struct sunxi_ir *ir = platform_get_drvdata(pdev);

clk_disable_unprepare(ir->clk);
clk_disable_unprepare(ir->apb_clk);
reset_control_assert(ir->rst);

- spin_lock_irqsave(&ir->ir_lock, flags);
- /* disable IR IRQ */
- writel(0, ir->base + SUNXI_IR_RXINT_REG);
- /* clear All Rx Interrupt Status */
- writel(REG_RXSTA_CLEARALL, ir->base + SUNXI_IR_RXSTA_REG);
- /* disable IR */
- writel(0, ir->base + SUNXI_IR_CTL_REG);
- spin_unlock_irqrestore(&ir->ir_lock, flags);
-
rc_unregister_device(ir->rc);
return 0;
}
--
2.26.2

Samuel Holland

unread,
Jan 12, 2021, 11:51:39 PM1/12/21
to Sean Young, Mauro Carvalho Chehab, Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Samuel Holland
This series cleans up some dead code in the sunxi-cir driver and adds
system power management hooks.

Samuel Holland (4):
media: sunxi-cir: Clean up dead register writes
media: sunxi-cir: Remove unnecessary spinlock
media: sunxi-cir: Factor out hardware initialization
media: sunxi-cir: Implement suspend/resume/shutdown callbacks

drivers/media/rc/sunxi-cir.c | 167 ++++++++++++++++++++---------------
1 file changed, 94 insertions(+), 73 deletions(-)

--
2.26.2

Samuel Holland

unread,
Jan 12, 2021, 11:51:39 PM1/12/21
to Sean Young, Mauro Carvalho Chehab, Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Samuel Holland
Only one register, SUNXI_IR_CIR_REG, is accessed from outside the
interrupt handler, and that register is not accessed from inside it.
As there is no overlap between different contexts, no lock is needed.

Signed-off-by: Samuel Holland <sam...@sholland.org>
---
drivers/media/rc/sunxi-cir.c | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
index 0a7f7eab3cc3..48be400421cd 100644
--- a/drivers/media/rc/sunxi-cir.c
+++ b/drivers/media/rc/sunxi-cir.c
@@ -86,7 +86,6 @@ struct sunxi_ir_quirks {
};

struct sunxi_ir {
- spinlock_t ir_lock;
struct rc_dev *rc;
void __iomem *base;
int irq;
@@ -105,8 +104,6 @@ static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id)
struct sunxi_ir *ir = dev_id;
struct ir_raw_event rawir = {};

- spin_lock(&ir->ir_lock);
-
status = readl(ir->base + SUNXI_IR_RXSTA_REG);

/* clean all pending statuses */
@@ -137,8 +134,6 @@ static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id)
ir_raw_event_handle(ir->rc);
}

- spin_unlock(&ir->ir_lock);
-
return IRQ_HANDLED;
}

@@ -160,17 +155,14 @@ static int sunxi_ir_set_timeout(struct rc_dev *rc_dev, unsigned int timeout)
{
struct sunxi_ir *ir = rc_dev->priv;
unsigned int base_clk = clk_get_rate(ir->clk);
- unsigned long flags;

unsigned int ithr = sunxi_usec_to_ithr(base_clk, timeout);

dev_dbg(rc_dev->dev.parent, "setting idle threshold to %u\n", ithr);

- spin_lock_irqsave(&ir->ir_lock, flags);
/* Set noise threshold and idle threshold */
writel(REG_CIR_NTHR(SUNXI_IR_RXNOISE) | REG_CIR_ITHR(ithr),
ir->base + SUNXI_IR_CIR_REG);
- spin_unlock_irqrestore(&ir->ir_lock, flags);

rc_dev->timeout = sunxi_ithr_to_usec(base_clk, ithr);

@@ -199,8 +191,6 @@ static int sunxi_ir_probe(struct platform_device *pdev)
return -ENODEV;
}

- spin_lock_init(&ir->ir_lock);
-
ir->fifo_size = quirks->fifo_size;

/* Clock */
--
2.26.2

Maxime Ripard

unread,
Jan 13, 2021, 3:26:48 AM1/13/21
to Samuel Holland, Sean Young, Mauro Carvalho Chehab, Chen-Yu Tsai, Jernej Skrabec, linux...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com
On Tue, Jan 12, 2021 at 10:51:28PM -0600, Samuel Holland wrote:
> This series cleans up some dead code in the sunxi-cir driver and adds
> system power management hooks.

Acked-by: Maxime Ripard <mri...@kernel.org>

Thanks!
Maxime
signature.asc

Samuel Holland

unread,
Jan 18, 2021, 1:00:55 AM1/18/21
to Sean Young, Mauro Carvalho Chehab, Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Samuel Holland
To save power, gate/reset the hardware block while the system is
asleep or powered off.

Signed-off-by: Samuel Holland <sam...@sholland.org>
---
drivers/media/rc/sunxi-cir.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
index 2d099da8d3cc..168e1d2c876a 100644
--- a/drivers/media/rc/sunxi-cir.c
+++ b/drivers/media/rc/sunxi-cir.c
@@ -234,6 +234,20 @@ static void sunxi_ir_hw_exit(struct device *dev)
reset_control_assert(ir->rst);
}

+static int __maybe_unused sunxi_ir_suspend(struct device *dev)
+{
+ sunxi_ir_hw_exit(dev);
+
+ return 0;
+}
+
+static int __maybe_unused sunxi_ir_resume(struct device *dev)
+{
+ return sunxi_ir_hw_init(dev);
+}
+
+static SIMPLE_DEV_PM_OPS(sunxi_ir_pm_ops, sunxi_ir_suspend, sunxi_ir_resume);
+
static int sunxi_ir_probe(struct platform_device *pdev)

Samuel Holland

unread,
Jan 18, 2021, 1:00:55 AM1/18/21
to Sean Young, Mauro Carvalho Chehab, Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Samuel Holland
The register writes during driver removal occur after the device is
already put back in reset, so they never had any effect.

Signed-off-by: Samuel Holland <sam...@sholland.org>
---
drivers/media/rc/sunxi-cir.c | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
index 8555c7798706..0a7f7eab3cc3 100644
--- a/drivers/media/rc/sunxi-cir.c
+++ b/drivers/media/rc/sunxi-cir.c
@@ -342,22 +342,12 @@ static int sunxi_ir_probe(struct platform_device *pdev)

static int sunxi_ir_remove(struct platform_device *pdev)

Samuel Holland

unread,
Jan 18, 2021, 1:00:55 AM1/18/21
to Sean Young, Mauro Carvalho Chehab, Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Samuel Holland
This series cleans up some dead code in the sunxi-cir driver and adds
system power management hooks.

---
Changes from v1:
- Unregister the RC device first thing in sunxi_ir_remove() [3]

Samuel Holland (4):
media: sunxi-cir: Clean up dead register writes
media: sunxi-cir: Remove unnecessary spinlock
media: sunxi-cir: Factor out hardware initialization
media: sunxi-cir: Implement suspend/resume/shutdown callbacks

drivers/media/rc/sunxi-cir.c | 169 ++++++++++++++++++++---------------
1 file changed, 95 insertions(+), 74 deletions(-)

--
2.26.2

Samuel Holland

unread,
Jan 18, 2021, 1:00:55 AM1/18/21
to Sean Young, Mauro Carvalho Chehab, Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Samuel Holland
Only one register, SUNXI_IR_CIR_REG, is accessed from outside the
interrupt handler, and that register is not accessed from inside it.
As there is no overlap between different contexts, no lock is needed.

Signed-off-by: Samuel Holland <sam...@sholland.org>
---
drivers/media/rc/sunxi-cir.c | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
index 0a7f7eab3cc3..48be400421cd 100644
--- a/drivers/media/rc/sunxi-cir.c
+++ b/drivers/media/rc/sunxi-cir.c

Samuel Holland

unread,
Jan 18, 2021, 1:04:26 AM1/18/21
to Sean Young, Mauro Carvalho Chehab, Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com
On 1/18/21 12:00 AM, Samuel Holland wrote:
> This series cleans up some dead code in the sunxi-cir driver and adds
> system power management hooks.
>
> ---
> Changes from v1:
> - Unregister the RC device first thing in sunxi_ir_remove() [3]

I forgot to add:

Acked-by: Maxime Ripard <mri...@kernel.org>

from v1.
Reply all
Reply to author
Forward
0 new messages