blob: 4d29c9dc3bab20168dfbc6aca8b17dc29cd6ee78 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2015 MediaTek Inc.
3 * Author: James Liao <jamesjj.liao@mediatek.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <linux/clk.h>
16#include <linux/clk-provider.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/of.h>
20#include <linux/of_platform.h>
21
22static const struct of_device_id bring_up_id_table[] = {
23 { .compatible = "mediatek,clk-bring-up", .data = (void *)300},
24 { .compatible = "mediatek,mt2731-bring-up", .data = (void *)120},
25 { .compatible = "mediatek,mt8163-bring-up", .data = (void *)300},
26 { .compatible = "mediatek,mt8173-bring-up", .data = (void *)300},
27 { },
28};
29MODULE_DEVICE_TABLE(of, bring_up_id_table);
30
31static int bring_up_probe(struct platform_device *pdev)
32{
33 struct device *dev = &pdev->dev;
34 unsigned int nr_clks;
35 char clk_name_buf[10];
36 struct clk *clk, *last_ok_clk = NULL;
37 int i, r = 0;
38
39 nr_clks = (unsigned long)of_device_get_match_data(dev); /* clk nr */
40 if (!nr_clks)
41 return -EINVAL;
42
43 for (i = 0; i < nr_clks; i++) {
44 memset(clk_name_buf, 0, 10);
45 sprintf(clk_name_buf, "%d", i);
46
47 clk = devm_clk_get(dev, clk_name_buf);
48 if (!IS_ERR(clk)) {
49 r = clk_prepare_enable(clk);
50 if (r)
51 dev_warn(dev, "clk_prepare_enable(%s): %d\n",
52 __clk_get_name(clk), r);
53 else
54 last_ok_clk = clk;
55 }
56 }
57 if (!r)
58 dev_info(dev, "clk enable(nr%d) suc. the end clk is: %s\n",
59 nr_clks, __clk_get_name(last_ok_clk));
60
61 return 0;
62}
63
64static int bring_up_remove(struct platform_device *pdev)
65{
66 return 0;
67}
68
69static struct platform_driver bring_up = {
70 .probe = bring_up_probe,
71 .remove = bring_up_remove,
72 .driver = {
73 .name = "bring_up",
74 .owner = THIS_MODULE,
75 .of_match_table = bring_up_id_table,
76 },
77};
78
79module_platform_driver(bring_up);