[PATCH 1/5] irqchip/gic-pm: add driver remove support

From: Sameer Pujar
Date: Wed Mar 13 2019 - 07:02:52 EST


This is a preparatory patch for using irq-gic-pm driver as module and thus
implement remove() call for the driver. Details of remove() are as below,

* pm_runtime_force_suspend() is added to balance runtime PM, otherwise
following is seen: "agic-controller: Unbalanced pm_runtime_enable!"
* Function gic_teardown() is exported from gic driver and called in remove
to perform io unmap.
* pm_clk_destroy() to free clock resources
* irq is unmapped and freed with irq_dispose_mapping()

Signed-off-by: Sameer Pujar <spujar@xxxxxxxxxx>
---
drivers/irqchip/irq-gic-pm.c | 37 ++++++++++++++++++++++++++++++++-----
drivers/irqchip/irq-gic.c | 3 ++-
include/linux/irqchip/arm-gic.h | 2 ++
3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/drivers/irqchip/irq-gic-pm.c b/drivers/irqchip/irq-gic-pm.c
index ecafd29..56a785f 100644
--- a/drivers/irqchip/irq-gic-pm.c
+++ b/drivers/irqchip/irq-gic-pm.c
@@ -28,9 +28,15 @@ struct gic_clk_data {
const char *const *clocks;
};

+struct gic_chip_pm {
+ struct gic_chip_data *chip_data;
+ int irq;
+};
+
static int gic_runtime_resume(struct device *dev)
{
- struct gic_chip_data *gic = dev_get_drvdata(dev);
+ struct gic_chip_pm *chip_pm = dev_get_drvdata(dev);
+ struct gic_chip_data *gic = chip_pm->chip_data;
int ret;

ret = pm_clk_resume(dev);
@@ -54,7 +60,8 @@ static int gic_runtime_resume(struct device *dev)

static int gic_runtime_suspend(struct device *dev)
{
- struct gic_chip_data *gic = dev_get_drvdata(dev);
+ struct gic_chip_pm *chip_pm = dev_get_drvdata(dev);
+ struct gic_chip_data *gic = chip_pm->chip_data;

gic_dist_save(gic);
gic_cpu_save(gic);
@@ -91,9 +98,14 @@ static int gic_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
const struct gic_clk_data *data;
- struct gic_chip_data *gic;
+ struct gic_chip_pm *chip_pm;
int ret, irq;

+ chip_pm = devm_kzalloc(dev, sizeof(struct gic_chip_pm),
+ GFP_KERNEL);
+ if (!chip_pm)
+ return -ENOMEM;
+
data = of_device_get_match_data(&pdev->dev);
if (!data) {
dev_err(&pdev->dev, "no device match found\n");
@@ -116,14 +128,15 @@ static int gic_probe(struct platform_device *pdev)
if (ret < 0)
goto rpm_disable;

- ret = gic_of_init_child(dev, &gic, irq);
+ ret = gic_of_init_child(dev, &chip_pm->chip_data, irq);
if (ret)
goto rpm_put;

- platform_set_drvdata(pdev, gic);
+ platform_set_drvdata(pdev, chip_pm);

pm_runtime_put(dev);

+ chip_pm->irq = irq;
dev_info(dev, "GIC IRQ controller registered\n");

return 0;
@@ -139,6 +152,19 @@ static int gic_probe(struct platform_device *pdev)
return ret;
}

+static int gic_remove(struct platform_device *pdev)
+{
+ struct gic_chip_pm *chip_pm = dev_get_drvdata(&pdev->dev);
+ struct gic_chip_data *gic = chip_pm->chip_data;
+
+ pm_runtime_force_suspend(&pdev->dev);
+ gic_teardown(gic);
+ pm_clk_destroy(&pdev->dev);
+ irq_dispose_mapping(chip_pm->irq);
+
+ return 0;
+}
+
static const struct dev_pm_ops gic_pm_ops = {
SET_RUNTIME_PM_OPS(gic_runtime_suspend,
gic_runtime_resume, NULL)
@@ -161,6 +187,7 @@ MODULE_DEVICE_TABLE(of, gic_match);

static struct platform_driver gic_driver = {
.probe = gic_probe,
+ .remove = gic_remove,
.driver = {
.name = "gic",
.of_match_table = gic_match,
diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index ba2a37a..f88018b 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -1259,7 +1259,7 @@ void __init gic_init(unsigned int gic_nr, int irq_start,
__gic_init_bases(gic, irq_start, NULL);
}

-static void gic_teardown(struct gic_chip_data *gic)
+void gic_teardown(struct gic_chip_data *gic)
{
if (WARN_ON(!gic))
return;
@@ -1269,6 +1269,7 @@ static void gic_teardown(struct gic_chip_data *gic)
if (gic->raw_cpu_base)
iounmap(gic->raw_cpu_base);
}
+EXPORT_SYMBOL_GPL(gic_teardown);

#ifdef CONFIG_OF
static int gic_cnt __initdata;
diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
index 6261790..f790232 100644
--- a/include/linux/irqchip/arm-gic.h
+++ b/include/linux/irqchip/arm-gic.h
@@ -161,6 +161,8 @@ int gic_of_init_child(struct device *dev, struct gic_chip_data **gic, int irq);
void gic_init(unsigned int nr, int start,
void __iomem *dist , void __iomem *cpu);

+void gic_teardown(struct gic_chip_data *gic);
+
int gicv2m_init(struct fwnode_handle *parent_handle,
struct irq_domain *parent);

--
2.7.4