diff options
author | Kelvin Cheung <keguang.zhang@gmail.com> | 2016-09-19 00:38:54 -0400 |
---|---|---|
committer | Stephen Boyd <sboyd@codeaurora.org> | 2016-09-23 17:48:56 -0400 |
commit | a8e3ced421c1cd24221543a2bfda3134d46a6f21 (patch) | |
tree | ce7977ec79ce5544dfac628d57f057166f2b7e0a | |
parent | 5963f19ca2b7e46cafc9647c8390bb20563b91cc (diff) |
clk: Loongson1: Refactor Loongson1 clock
Factor out the common functions into loongson1/clk.c
to support both Loongson1B and Loongson1C. And, put
the rest into loongson1/clk-loongson1b.c.
Signed-off-by: Kelvin Cheung <keguang.zhang@gmail.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
-rw-r--r-- | drivers/clk/Makefile | 2 | ||||
-rw-r--r-- | drivers/clk/loongson1/Makefile | 2 | ||||
-rw-r--r-- | drivers/clk/loongson1/clk-loongson1b.c (renamed from drivers/clk/clk-ls1x.c) | 51 | ||||
-rw-r--r-- | drivers/clk/loongson1/clk.c | 43 | ||||
-rw-r--r-- | drivers/clk/loongson1/clk.h | 19 |
5 files changed, 69 insertions, 48 deletions
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index 8264d81af5a9..925081ec14c0 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile | |||
@@ -26,7 +26,6 @@ obj-$(CONFIG_ARCH_CLPS711X) += clk-clps711x.o | |||
26 | obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.o | 26 | obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.o |
27 | obj-$(CONFIG_ARCH_EFM32) += clk-efm32gg.o | 27 | obj-$(CONFIG_ARCH_EFM32) += clk-efm32gg.o |
28 | obj-$(CONFIG_ARCH_HIGHBANK) += clk-highbank.o | 28 | obj-$(CONFIG_ARCH_HIGHBANK) += clk-highbank.o |
29 | obj-$(CONFIG_MACH_LOONGSON32) += clk-ls1x.o | ||
30 | obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o | 29 | obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o |
31 | obj-$(CONFIG_ARCH_MB86S7X) += clk-mb86s7x.o | 30 | obj-$(CONFIG_ARCH_MB86S7X) += clk-mb86s7x.o |
32 | obj-$(CONFIG_ARCH_MOXART) += clk-moxart.o | 31 | obj-$(CONFIG_ARCH_MOXART) += clk-moxart.o |
@@ -61,6 +60,7 @@ obj-$(CONFIG_ARCH_HISI) += hisilicon/ | |||
61 | obj-$(CONFIG_ARCH_MXC) += imx/ | 60 | obj-$(CONFIG_ARCH_MXC) += imx/ |
62 | obj-$(CONFIG_MACH_INGENIC) += ingenic/ | 61 | obj-$(CONFIG_MACH_INGENIC) += ingenic/ |
63 | obj-$(CONFIG_COMMON_CLK_KEYSTONE) += keystone/ | 62 | obj-$(CONFIG_COMMON_CLK_KEYSTONE) += keystone/ |
63 | obj-$(CONFIG_MACH_LOONGSON32) += loongson1/ | ||
64 | obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/ | 64 | obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/ |
65 | obj-$(CONFIG_COMMON_CLK_AMLOGIC) += meson/ | 65 | obj-$(CONFIG_COMMON_CLK_AMLOGIC) += meson/ |
66 | obj-$(CONFIG_MACH_PIC32) += microchip/ | 66 | obj-$(CONFIG_MACH_PIC32) += microchip/ |
diff --git a/drivers/clk/loongson1/Makefile b/drivers/clk/loongson1/Makefile new file mode 100644 index 000000000000..5a162a1b9bf6 --- /dev/null +++ b/drivers/clk/loongson1/Makefile | |||
@@ -0,0 +1,2 @@ | |||
1 | obj-y += clk.o | ||
2 | obj-$(CONFIG_LOONGSON1_LS1B) += clk-loongson1b.o | ||
diff --git a/drivers/clk/clk-ls1x.c b/drivers/clk/loongson1/clk-loongson1b.c index 8430e45427f4..5b6817ee594d 100644 --- a/drivers/clk/clk-ls1x.c +++ b/drivers/clk/loongson1/clk-loongson1b.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2012 Zhang, Keguang <keguang.zhang@gmail.com> | 2 | * Copyright (c) 2012-2016 Zhang, Keguang <keguang.zhang@gmail.com> |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or modify it | 4 | * This program is free software; you can redistribute it and/or modify it |
5 | * under the terms of the GNU General Public License as published by the | 5 | * under the terms of the GNU General Public License as published by the |
@@ -10,25 +10,16 @@ | |||
10 | #include <linux/clkdev.h> | 10 | #include <linux/clkdev.h> |
11 | #include <linux/clk-provider.h> | 11 | #include <linux/clk-provider.h> |
12 | #include <linux/io.h> | 12 | #include <linux/io.h> |
13 | #include <linux/slab.h> | ||
14 | #include <linux/err.h> | 13 | #include <linux/err.h> |
15 | 14 | ||
16 | #include <loongson1.h> | 15 | #include <loongson1.h> |
16 | #include "clk.h" | ||
17 | 17 | ||
18 | #define OSC (33 * 1000000) | 18 | #define OSC (33 * 1000000) |
19 | #define DIV_APB 2 | 19 | #define DIV_APB 2 |
20 | 20 | ||
21 | static DEFINE_SPINLOCK(_lock); | 21 | static DEFINE_SPINLOCK(_lock); |
22 | 22 | ||
23 | static int ls1x_pll_clk_enable(struct clk_hw *hw) | ||
24 | { | ||
25 | return 0; | ||
26 | } | ||
27 | |||
28 | static void ls1x_pll_clk_disable(struct clk_hw *hw) | ||
29 | { | ||
30 | } | ||
31 | |||
32 | static unsigned long ls1x_pll_recalc_rate(struct clk_hw *hw, | 23 | static unsigned long ls1x_pll_recalc_rate(struct clk_hw *hw, |
33 | unsigned long parent_rate) | 24 | unsigned long parent_rate) |
34 | { | 25 | { |
@@ -43,44 +34,9 @@ static unsigned long ls1x_pll_recalc_rate(struct clk_hw *hw, | |||
43 | } | 34 | } |
44 | 35 | ||
45 | static const struct clk_ops ls1x_pll_clk_ops = { | 36 | static const struct clk_ops ls1x_pll_clk_ops = { |
46 | .enable = ls1x_pll_clk_enable, | ||
47 | .disable = ls1x_pll_clk_disable, | ||
48 | .recalc_rate = ls1x_pll_recalc_rate, | 37 | .recalc_rate = ls1x_pll_recalc_rate, |
49 | }; | 38 | }; |
50 | 39 | ||
51 | static struct clk_hw *__init clk_hw_register_pll(struct device *dev, | ||
52 | const char *name, | ||
53 | const char *parent_name, | ||
54 | unsigned long flags) | ||
55 | { | ||
56 | int ret; | ||
57 | struct clk_hw *hw; | ||
58 | struct clk_init_data init; | ||
59 | |||
60 | /* allocate the divider */ | ||
61 | hw = kzalloc(sizeof(struct clk_hw), GFP_KERNEL); | ||
62 | if (!hw) { | ||
63 | pr_err("%s: could not allocate clk_hw\n", __func__); | ||
64 | return ERR_PTR(-ENOMEM); | ||
65 | } | ||
66 | |||
67 | init.name = name; | ||
68 | init.ops = &ls1x_pll_clk_ops; | ||
69 | init.flags = flags | CLK_IS_BASIC; | ||
70 | init.parent_names = (parent_name ? &parent_name : NULL); | ||
71 | init.num_parents = (parent_name ? 1 : 0); | ||
72 | hw->init = &init; | ||
73 | |||
74 | /* register the clock */ | ||
75 | ret = clk_hw_register(dev, hw); | ||
76 | if (ret) { | ||
77 | kfree(hw); | ||
78 | hw = ERR_PTR(ret); | ||
79 | } | ||
80 | |||
81 | return hw; | ||
82 | } | ||
83 | |||
84 | static const char * const cpu_parents[] = { "cpu_clk_div", "osc_33m_clk", }; | 40 | static const char * const cpu_parents[] = { "cpu_clk_div", "osc_33m_clk", }; |
85 | static const char * const ahb_parents[] = { "ahb_clk_div", "osc_33m_clk", }; | 41 | static const char * const ahb_parents[] = { "ahb_clk_div", "osc_33m_clk", }; |
86 | static const char * const dc_parents[] = { "dc_clk_div", "osc_33m_clk", }; | 42 | static const char * const dc_parents[] = { "dc_clk_div", "osc_33m_clk", }; |
@@ -93,7 +49,8 @@ void __init ls1x_clk_init(void) | |||
93 | clk_hw_register_clkdev(hw, "osc_33m_clk", NULL); | 49 | clk_hw_register_clkdev(hw, "osc_33m_clk", NULL); |
94 | 50 | ||
95 | /* clock derived from 33 MHz OSC clk */ | 51 | /* clock derived from 33 MHz OSC clk */ |
96 | hw = clk_hw_register_pll(NULL, "pll_clk", "osc_33m_clk", 0); | 52 | hw = clk_hw_register_pll(NULL, "pll_clk", "osc_33m_clk", |
53 | &ls1x_pll_clk_ops, 0); | ||
97 | clk_hw_register_clkdev(hw, "pll_clk", NULL); | 54 | clk_hw_register_clkdev(hw, "pll_clk", NULL); |
98 | 55 | ||
99 | /* clock derived from PLL clk */ | 56 | /* clock derived from PLL clk */ |
diff --git a/drivers/clk/loongson1/clk.c b/drivers/clk/loongson1/clk.c new file mode 100644 index 000000000000..cfcfd143fccb --- /dev/null +++ b/drivers/clk/loongson1/clk.c | |||
@@ -0,0 +1,43 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2012-2016 Zhang, Keguang <keguang.zhang@gmail.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms of the GNU General Public License as published by the | ||
6 | * Free Software Foundation; either version 2 of the License, or (at your | ||
7 | * option) any later version. | ||
8 | */ | ||
9 | |||
10 | #include <linux/clk-provider.h> | ||
11 | #include <linux/slab.h> | ||
12 | |||
13 | struct clk_hw *__init clk_hw_register_pll(struct device *dev, | ||
14 | const char *name, | ||
15 | const char *parent_name, | ||
16 | const struct clk_ops *ops, | ||
17 | unsigned long flags) | ||
18 | { | ||
19 | int ret; | ||
20 | struct clk_hw *hw; | ||
21 | struct clk_init_data init; | ||
22 | |||
23 | /* allocate the divider */ | ||
24 | hw = kzalloc(sizeof(*hw), GFP_KERNEL); | ||
25 | if (!hw) | ||
26 | return ERR_PTR(-ENOMEM); | ||
27 | |||
28 | init.name = name; | ||
29 | init.ops = ops; | ||
30 | init.flags = flags | CLK_IS_BASIC; | ||
31 | init.parent_names = (parent_name ? &parent_name : NULL); | ||
32 | init.num_parents = (parent_name ? 1 : 0); | ||
33 | hw->init = &init; | ||
34 | |||
35 | /* register the clock */ | ||
36 | ret = clk_hw_register(dev, hw); | ||
37 | if (ret) { | ||
38 | kfree(hw); | ||
39 | hw = ERR_PTR(ret); | ||
40 | } | ||
41 | |||
42 | return hw; | ||
43 | } | ||
diff --git a/drivers/clk/loongson1/clk.h b/drivers/clk/loongson1/clk.h new file mode 100644 index 000000000000..085d74b5d496 --- /dev/null +++ b/drivers/clk/loongson1/clk.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2012-2016 Zhang, Keguang <keguang.zhang@gmail.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms of the GNU General Public License as published by the | ||
6 | * Free Software Foundation; either version 2 of the License, or (at your | ||
7 | * option) any later version. | ||
8 | */ | ||
9 | |||
10 | #ifndef __LOONGSON1_CLK_H | ||
11 | #define __LOONGSON1_CLK_H | ||
12 | |||
13 | struct clk_hw *clk_hw_register_pll(struct device *dev, | ||
14 | const char *name, | ||
15 | const char *parent_name, | ||
16 | const struct clk_ops *ops, | ||
17 | unsigned long flags); | ||
18 | |||
19 | #endif /* __LOONGSON1_CLK_H */ | ||