aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKelvin Cheung <keguang.zhang@gmail.com>2016-09-19 00:38:54 -0400
committerStephen Boyd <sboyd@codeaurora.org>2016-09-23 17:48:56 -0400
commita8e3ced421c1cd24221543a2bfda3134d46a6f21 (patch)
treece7977ec79ce5544dfac628d57f057166f2b7e0a
parent5963f19ca2b7e46cafc9647c8390bb20563b91cc (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/Makefile2
-rw-r--r--drivers/clk/loongson1/Makefile2
-rw-r--r--drivers/clk/loongson1/clk-loongson1b.c (renamed from drivers/clk/clk-ls1x.c)51
-rw-r--r--drivers/clk/loongson1/clk.c43
-rw-r--r--drivers/clk/loongson1/clk.h19
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
26obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.o 26obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.o
27obj-$(CONFIG_ARCH_EFM32) += clk-efm32gg.o 27obj-$(CONFIG_ARCH_EFM32) += clk-efm32gg.o
28obj-$(CONFIG_ARCH_HIGHBANK) += clk-highbank.o 28obj-$(CONFIG_ARCH_HIGHBANK) += clk-highbank.o
29obj-$(CONFIG_MACH_LOONGSON32) += clk-ls1x.o
30obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o 29obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o
31obj-$(CONFIG_ARCH_MB86S7X) += clk-mb86s7x.o 30obj-$(CONFIG_ARCH_MB86S7X) += clk-mb86s7x.o
32obj-$(CONFIG_ARCH_MOXART) += clk-moxart.o 31obj-$(CONFIG_ARCH_MOXART) += clk-moxart.o
@@ -61,6 +60,7 @@ obj-$(CONFIG_ARCH_HISI) += hisilicon/
61obj-$(CONFIG_ARCH_MXC) += imx/ 60obj-$(CONFIG_ARCH_MXC) += imx/
62obj-$(CONFIG_MACH_INGENIC) += ingenic/ 61obj-$(CONFIG_MACH_INGENIC) += ingenic/
63obj-$(CONFIG_COMMON_CLK_KEYSTONE) += keystone/ 62obj-$(CONFIG_COMMON_CLK_KEYSTONE) += keystone/
63obj-$(CONFIG_MACH_LOONGSON32) += loongson1/
64obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/ 64obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
65obj-$(CONFIG_COMMON_CLK_AMLOGIC) += meson/ 65obj-$(CONFIG_COMMON_CLK_AMLOGIC) += meson/
66obj-$(CONFIG_MACH_PIC32) += microchip/ 66obj-$(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 @@
1obj-y += clk.o
2obj-$(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
21static DEFINE_SPINLOCK(_lock); 21static DEFINE_SPINLOCK(_lock);
22 22
23static int ls1x_pll_clk_enable(struct clk_hw *hw)
24{
25 return 0;
26}
27
28static void ls1x_pll_clk_disable(struct clk_hw *hw)
29{
30}
31
32static unsigned long ls1x_pll_recalc_rate(struct clk_hw *hw, 23static 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
45static const struct clk_ops ls1x_pll_clk_ops = { 36static 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
51static 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
84static const char * const cpu_parents[] = { "cpu_clk_div", "osc_33m_clk", }; 40static const char * const cpu_parents[] = { "cpu_clk_div", "osc_33m_clk", };
85static const char * const ahb_parents[] = { "ahb_clk_div", "osc_33m_clk", }; 41static const char * const ahb_parents[] = { "ahb_clk_div", "osc_33m_clk", };
86static const char * const dc_parents[] = { "dc_clk_div", "osc_33m_clk", }; 42static 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
13struct 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
13struct 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 */