hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/irqchip/irq-gic-pm.c
....@@ -1,17 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2016 NVIDIA CORPORATION, All Rights Reserved.
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 as
6
- * published by the Free Software Foundation.
7
- *
8
- * This program is distributed in the hope that it will be useful,
9
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- * GNU General Public License for more details.
12
- *
13
- * You should have received a copy of the GNU General Public License
14
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
154 */
165 #include <linux/module.h>
176 #include <linux/clk.h>
....@@ -19,7 +8,6 @@
198 #include <linux/of_irq.h>
209 #include <linux/irqchip/arm-gic.h>
2110 #include <linux/platform_device.h>
22
-#include <linux/pm_clock.h>
2311 #include <linux/pm_runtime.h>
2412 #include <linux/slab.h>
2513
....@@ -28,17 +16,27 @@
2816 const char *const *clocks;
2917 };
3018
19
+struct gic_chip_pm {
20
+ struct gic_chip_data *chip_data;
21
+ const struct gic_clk_data *clk_data;
22
+ struct clk_bulk_data *clks;
23
+};
24
+
3125 static int gic_runtime_resume(struct device *dev)
3226 {
33
- struct gic_chip_data *gic = dev_get_drvdata(dev);
27
+ struct gic_chip_pm *chip_pm = dev_get_drvdata(dev);
28
+ struct gic_chip_data *gic = chip_pm->chip_data;
29
+ const struct gic_clk_data *data = chip_pm->clk_data;
3430 int ret;
3531
36
- ret = pm_clk_resume(dev);
37
- if (ret)
32
+ ret = clk_bulk_prepare_enable(data->num_clocks, chip_pm->clks);
33
+ if (ret) {
34
+ dev_err(dev, "clk_enable failed: %d\n", ret);
3835 return ret;
36
+ }
3937
4038 /*
41
- * On the very first resume, the pointer to the driver data
39
+ * On the very first resume, the pointer to chip_pm->chip_data
4240 * will be NULL and this is intentional, because we do not
4341 * want to restore the GIC on the very first resume. So if
4442 * the pointer is not valid just return.
....@@ -54,35 +52,14 @@
5452
5553 static int gic_runtime_suspend(struct device *dev)
5654 {
57
- struct gic_chip_data *gic = dev_get_drvdata(dev);
55
+ struct gic_chip_pm *chip_pm = dev_get_drvdata(dev);
56
+ struct gic_chip_data *gic = chip_pm->chip_data;
57
+ const struct gic_clk_data *data = chip_pm->clk_data;
5858
5959 gic_dist_save(gic);
6060 gic_cpu_save(gic);
6161
62
- return pm_clk_suspend(dev);
63
-}
64
-
65
-static int gic_get_clocks(struct device *dev, const struct gic_clk_data *data)
66
-{
67
- unsigned int i;
68
- int ret;
69
-
70
- if (!dev || !data)
71
- return -EINVAL;
72
-
73
- ret = pm_clk_create(dev);
74
- if (ret)
75
- return ret;
76
-
77
- for (i = 0; i < data->num_clocks; i++) {
78
- ret = of_pm_clk_add_clk(dev, data->clocks[i]);
79
- if (ret) {
80
- dev_err(dev, "failed to add clock %s\n",
81
- data->clocks[i]);
82
- pm_clk_destroy(dev);
83
- return ret;
84
- }
85
- }
62
+ clk_bulk_disable_unprepare(data->num_clocks, chip_pm->clks);
8663
8764 return 0;
8865 }
....@@ -91,8 +68,8 @@
9168 {
9269 struct device *dev = &pdev->dev;
9370 const struct gic_clk_data *data;
94
- struct gic_chip_data *gic;
95
- int ret, irq;
71
+ struct gic_chip_pm *chip_pm;
72
+ int ret, irq, i;
9673
9774 data = of_device_get_match_data(&pdev->dev);
9875 if (!data) {
....@@ -100,27 +77,40 @@
10077 return -ENODEV;
10178 }
10279
80
+ chip_pm = devm_kzalloc(dev, sizeof(*chip_pm), GFP_KERNEL);
81
+ if (!chip_pm)
82
+ return -ENOMEM;
83
+
10384 irq = irq_of_parse_and_map(dev->of_node, 0);
10485 if (!irq) {
10586 dev_err(dev, "no parent interrupt found!\n");
10687 return -EINVAL;
10788 }
10889
109
- ret = gic_get_clocks(dev, data);
90
+ chip_pm->clks = devm_kcalloc(dev, data->num_clocks,
91
+ sizeof(*chip_pm->clks), GFP_KERNEL);
92
+ if (!chip_pm->clks)
93
+ return -ENOMEM;
94
+
95
+ for (i = 0; i < data->num_clocks; i++)
96
+ chip_pm->clks[i].id = data->clocks[i];
97
+
98
+ ret = devm_clk_bulk_get(dev, data->num_clocks, chip_pm->clks);
11099 if (ret)
111100 goto irq_dispose;
112101
102
+ chip_pm->clk_data = data;
103
+ dev_set_drvdata(dev, chip_pm);
104
+
113105 pm_runtime_enable(dev);
114106
115
- ret = pm_runtime_get_sync(dev);
107
+ ret = pm_runtime_resume_and_get(dev);
116108 if (ret < 0)
117109 goto rpm_disable;
118110
119
- ret = gic_of_init_child(dev, &gic, irq);
111
+ ret = gic_of_init_child(dev, &chip_pm->chip_data, irq);
120112 if (ret)
121113 goto rpm_put;
122
-
123
- platform_set_drvdata(pdev, gic);
124114
125115 pm_runtime_put(dev);
126116
....@@ -132,7 +122,6 @@
132122 pm_runtime_put_sync(dev);
133123 rpm_disable:
134124 pm_runtime_disable(dev);
135
- pm_clk_destroy(dev);
136125 irq_dispose:
137126 irq_dispose_mapping(irq);
138127
....@@ -142,6 +131,8 @@
142131 static const struct dev_pm_ops gic_pm_ops = {
143132 SET_RUNTIME_PM_OPS(gic_runtime_suspend,
144133 gic_runtime_resume, NULL)
134
+ SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
135
+ pm_runtime_force_resume)
145136 };
146137
147138 static const char * const gic400_clocks[] = {