blob: 37327cf3a8f0281bcf87a9cd3c882ee0057984cd [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001// SPDX-License-Identifier: GPL-2.0
2
3/*
4
5 * Copyright (c) 2020 MediaTek Inc.
6
7 */
8#include <linux/clk.h>
9#include <linux/clk-provider.h>
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/of.h>
13#include <linux/of_platform.h>
14static const struct of_device_id bring_up_id_table[] = {
15 { .compatible = "mediatek,clk-bring-up",},
16 { .compatible = "mediatek,mt8163-bring-up",},
17 { .compatible = "mediatek,mt8173-bring-up",},
18 { },
19};
20MODULE_DEVICE_TABLE(of, bring_up_id_table);
21static int bring_up_probe(struct platform_device *pdev)
22{
23 struct clk *clk;
24 int clk_con, i;
25 int ret = 0;
26 clk_con = of_count_phandle_with_args(pdev->dev.of_node, "clocks",
27 "#clock-cells");
28 pr_notice("sum: %d\n", clk_con);
29 for (i = 0; i < clk_con; i++) {
30 clk = of_clk_get(pdev->dev.of_node, i);
31 if (IS_ERR(clk)) {
32 long ret = PTR_ERR(clk);
33 if (ret == -EPROBE_DEFER)
34 pr_notice("clk %d is not ready\n", i);
35 else
36 pr_notice("get clk %d fail, ret=%d, clk_con=%d\n",
37 i, (int)ret, clk_con);
38 } else {
39 pr_notice("get clk [%d]: %s ok\n", i,
40 __clk_get_name(clk));
41 ret = clk_prepare_enable(clk);
42 if (ret) {
43 pr_err("cannot force-on bringup clk node\n");
44 pr_notice("enable clk %d fail, ret=%d, clk_con=%d\n",
45 i, (int)ret, clk_con);
46 }
47 }
48 }
49 return ret;
50}
51static int bring_up_remove(struct platform_device *pdev)
52{
53 return 0;
54}
55static struct platform_driver clk_bring_up = {
56 .probe = bring_up_probe,
57 .remove = bring_up_remove,
58 .driver = {
59 .name = "clk_bring_up",
60 .owner = THIS_MODULE,
61 .of_match_table = bring_up_id_table,
62 },
63};
64module_platform_driver(clk_bring_up);