forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 61598093bbdd283a7edc367d900f223070ead8d2
kernel/drivers/clk/samsung/clk-cpu.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
34 * Author: Thomas Abraham <thomas.ab@samsung.com>
45 *
56 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
67 * Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 *
129 * This file contains the utility function to register CPU clock for Samsung
1310 * Exynos platforms. A CPU clock is defined as a clock supplied to a CPU or a
....@@ -33,6 +30,7 @@
3330 */
3431
3532 #include <linux/errno.h>
33
+#include <linux/io.h>
3634 #include <linux/slab.h>
3735 #include <linux/clk.h>
3836 #include <linux/clk-provider.h>
....@@ -403,26 +401,34 @@
403401
404402 /* helper function to register a CPU clock */
405403 int __init exynos_register_cpu_clock(struct samsung_clk_provider *ctx,
406
- unsigned int lookup_id, const char *name, const char *parent,
407
- const char *alt_parent, unsigned long offset,
408
- const struct exynos_cpuclk_cfg_data *cfg,
404
+ unsigned int lookup_id, const char *name,
405
+ const struct clk_hw *parent, const struct clk_hw *alt_parent,
406
+ unsigned long offset, const struct exynos_cpuclk_cfg_data *cfg,
409407 unsigned long num_cfgs, unsigned long flags)
410408 {
411409 struct exynos_cpuclk *cpuclk;
412
- struct clk_init_data init = {};
413
- struct clk *parent_clk;
410
+ struct clk_init_data init;
411
+ const char *parent_name;
414412 int ret = 0;
413
+
414
+ if (IS_ERR(parent) || IS_ERR(alt_parent)) {
415
+ pr_err("%s: invalid parent clock(s)\n", __func__);
416
+ return -EINVAL;
417
+ }
415418
416419 cpuclk = kzalloc(sizeof(*cpuclk), GFP_KERNEL);
417420 if (!cpuclk)
418421 return -ENOMEM;
419422
423
+ parent_name = clk_hw_get_name(parent);
424
+
420425 init.name = name;
421426 init.flags = CLK_SET_RATE_PARENT;
422
- init.parent_names = &parent;
427
+ init.parent_names = &parent_name;
423428 init.num_parents = 1;
424429 init.ops = &exynos_cpuclk_clk_ops;
425430
431
+ cpuclk->alt_parent = alt_parent;
426432 cpuclk->hw.init = &init;
427433 cpuclk->ctrl_base = ctx->reg_base + offset;
428434 cpuclk->lock = &ctx->lock;
....@@ -432,23 +438,8 @@
432438 else
433439 cpuclk->clk_nb.notifier_call = exynos_cpuclk_notifier_cb;
434440
435
- cpuclk->alt_parent = __clk_get_hw(__clk_lookup(alt_parent));
436
- if (!cpuclk->alt_parent) {
437
- pr_err("%s: could not lookup alternate parent %s\n",
438
- __func__, alt_parent);
439
- ret = -EINVAL;
440
- goto free_cpuclk;
441
- }
442441
443
- parent_clk = __clk_lookup(parent);
444
- if (!parent_clk) {
445
- pr_err("%s: could not lookup parent clock %s\n",
446
- __func__, parent);
447
- ret = -EINVAL;
448
- goto free_cpuclk;
449
- }
450
-
451
- ret = clk_notifier_register(parent_clk, &cpuclk->clk_nb);
442
+ ret = clk_notifier_register(parent->clk, &cpuclk->clk_nb);
452443 if (ret) {
453444 pr_err("%s: failed to register clock notifier for %s\n",
454445 __func__, name);
....@@ -473,7 +464,7 @@
473464 free_cpuclk_data:
474465 kfree(cpuclk->cfg);
475466 unregister_clk_nb:
476
- clk_notifier_unregister(parent_clk, &cpuclk->clk_nb);
467
+ clk_notifier_unregister(parent->clk, &cpuclk->clk_nb);
477468 free_cpuclk:
478469 kfree(cpuclk);
479470 return ret;