forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/clk/renesas/clk-mstp.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * R-Car MSTP clocks
34 *
....@@ -5,10 +6,6 @@
56 * Copyright (C) 2015 Glider bvba
67 *
78 * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; version 2 of the License.
129 */
1310
1411 #include <linux/clk.h>
....@@ -33,11 +30,12 @@
3330 /**
3431 * struct mstp_clock_group - MSTP gating clocks group
3532 *
36
- * @data: clocks in this group
33
+ * @data: clock specifier translation for clocks in this group
3734 * @smstpcr: module stop control register
3835 * @mstpsr: module stop status register (optional)
3936 * @lock: protects writes to SMSTPCR
4037 * @width_8bit: registers are 8-bit, not 32-bit
38
+ * @clks: clocks in this group
4139 */
4240 struct mstp_clock_group {
4341 struct clk_onecell_data data;
....@@ -45,6 +43,7 @@
4543 void __iomem *mstpsr;
4644 spinlock_t lock;
4745 bool width_8bit;
46
+ struct clk *clks[];
4847 };
4948
5049 /**
....@@ -151,7 +150,7 @@
151150 const char *parent_name, unsigned int index,
152151 struct mstp_clock_group *group)
153152 {
154
- struct clk_init_data init = {};
153
+ struct clk_init_data init;
155154 struct mstp_clock *clock;
156155 struct clk *clk;
157156
....@@ -161,7 +160,7 @@
161160
162161 init.name = name;
163162 init.ops = &cpg_mstp_clock_ops;
164
- init.flags = CLK_IS_BASIC | CLK_SET_RATE_PARENT;
163
+ init.flags = CLK_SET_RATE_PARENT;
165164 /* INTC-SYS is the module clock of the GIC, and must not be disabled */
166165 if (!strcmp(name, "intc-sys")) {
167166 pr_debug("MSTP %s setting CLK_IS_CRITICAL\n", name);
....@@ -189,14 +188,11 @@
189188 struct clk **clks;
190189 unsigned int i;
191190
192
- group = kzalloc(sizeof(*group), GFP_KERNEL);
193
- clks = kmalloc_array(MSTP_MAX_CLOCKS, sizeof(*clks), GFP_KERNEL);
194
- if (group == NULL || clks == NULL) {
195
- kfree(group);
196
- kfree(clks);
191
+ group = kzalloc(struct_size(group, clks, MSTP_MAX_CLOCKS), GFP_KERNEL);
192
+ if (!group)
197193 return;
198
- }
199194
195
+ clks = group->clks;
200196 spin_lock_init(&group->lock);
201197 group->data.clks = clks;
202198
....@@ -206,7 +202,6 @@
206202 if (group->smstpcr == NULL) {
207203 pr_err("%s: failed to remap SMSTPCR\n", __func__);
208204 kfree(group);
209
- kfree(clks);
210205 return;
211206 }
212207
....@@ -239,8 +234,8 @@
239234 break;
240235
241236 if (clkidx >= MSTP_MAX_CLOCKS) {
242
- pr_err("%s: invalid clock %s %s index %u\n",
243
- __func__, np->name, name, clkidx);
237
+ pr_err("%s: invalid clock %pOFn %s index %u\n",
238
+ __func__, np, name, clkidx);
244239 continue;
245240 }
246241
....@@ -259,8 +254,8 @@
259254 */
260255 clk_register_clkdev(clks[clkidx], name, NULL);
261256 } else {
262
- pr_err("%s: failed to register %s %s clock (%ld)\n",
263
- __func__, np->name, name, PTR_ERR(clks[clkidx]));
257
+ pr_err("%s: failed to register %pOFn %s clock (%ld)\n",
258
+ __func__, np, name, PTR_ERR(clks[clkidx]));
264259 }
265260 }
266261
....@@ -283,7 +278,7 @@
283278 goto found;
284279
285280 /* BSC on r8a73a4/sh73a0 uses zb_clk instead of an mstp clock */
286
- if (!strcmp(clkspec.np->name, "zb_clk"))
281
+ if (of_node_name_eq(clkspec.np, "zb_clk"))
287282 goto found;
288283
289284 of_node_put(clkspec.np);
....@@ -300,16 +295,12 @@
300295 return PTR_ERR(clk);
301296
302297 error = pm_clk_create(dev);
303
- if (error) {
304
- dev_err(dev, "pm_clk_create failed %d\n", error);
298
+ if (error)
305299 goto fail_put;
306
- }
307300
308301 error = pm_clk_add_clk(dev, clk);
309
- if (error) {
310
- dev_err(dev, "pm_clk_add_clk %pC failed %d\n", clk, error);
302
+ if (error)
311303 goto fail_destroy;
312
- }
313304
314305 return 0;
315306