diff options
author | Boris BREZILLON <b.brezillon@overkiz.com> | 2013-10-11 05:41:41 -0400 |
---|---|---|
committer | Nicolas Ferre <nicolas.ferre@atmel.com> | 2013-12-02 09:31:23 -0500 |
commit | 5fba62ea2648f89cbd7f0ed32069f03b179d05e9 (patch) | |
tree | 08615954736896eb8f9e07e26ebce6e330754177 | |
parent | e442d234405ad75e2d3d2baf15b364ee2c3573c9 (diff) |
clk: at91: add PMC system clocks
This patch adds new at91 system clock implementation using common clk
framework.
Some peripherals need to enable a "system" clock in order to work properly.
Each system clock is given an id based on the bit position in SCER/SCDR
registers.
Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>
Acked-by: Mike Turquette <mturquette@linaro.org>
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
-rw-r--r-- | drivers/clk/at91/Makefile | 1 | ||||
-rw-r--r-- | drivers/clk/at91/clk-system.c | 135 | ||||
-rw-r--r-- | drivers/clk/at91/pmc.c | 5 | ||||
-rw-r--r-- | drivers/clk/at91/pmc.h | 3 |
4 files changed, 144 insertions, 0 deletions
diff --git a/drivers/clk/at91/Makefile b/drivers/clk/at91/Makefile index e28fb2bbb198..c2b70683e4e0 100644 --- a/drivers/clk/at91/Makefile +++ b/drivers/clk/at91/Makefile | |||
@@ -4,3 +4,4 @@ | |||
4 | 4 | ||
5 | obj-y += pmc.o | 5 | obj-y += pmc.o |
6 | obj-y += clk-main.o clk-pll.o clk-plldiv.o clk-master.o | 6 | obj-y += clk-main.o clk-pll.o clk-plldiv.o clk-master.o |
7 | obj-y += clk-system.o | ||
diff --git a/drivers/clk/at91/clk-system.c b/drivers/clk/at91/clk-system.c new file mode 100644 index 000000000000..8f7c0434a09f --- /dev/null +++ b/drivers/clk/at91/clk-system.c | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | */ | ||
10 | |||
11 | #include <linux/clk-provider.h> | ||
12 | #include <linux/clkdev.h> | ||
13 | #include <linux/clk/at91_pmc.h> | ||
14 | #include <linux/of.h> | ||
15 | #include <linux/of_address.h> | ||
16 | #include <linux/io.h> | ||
17 | |||
18 | #include "pmc.h" | ||
19 | |||
20 | #define SYSTEM_MAX_ID 31 | ||
21 | |||
22 | #define SYSTEM_MAX_NAME_SZ 32 | ||
23 | |||
24 | #define to_clk_system(hw) container_of(hw, struct clk_system, hw) | ||
25 | struct clk_system { | ||
26 | struct clk_hw hw; | ||
27 | struct at91_pmc *pmc; | ||
28 | u8 id; | ||
29 | }; | ||
30 | |||
31 | static int clk_system_enable(struct clk_hw *hw) | ||
32 | { | ||
33 | struct clk_system *sys = to_clk_system(hw); | ||
34 | struct at91_pmc *pmc = sys->pmc; | ||
35 | |||
36 | pmc_write(pmc, AT91_PMC_SCER, 1 << sys->id); | ||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | static void clk_system_disable(struct clk_hw *hw) | ||
41 | { | ||
42 | struct clk_system *sys = to_clk_system(hw); | ||
43 | struct at91_pmc *pmc = sys->pmc; | ||
44 | |||
45 | pmc_write(pmc, AT91_PMC_SCDR, 1 << sys->id); | ||
46 | } | ||
47 | |||
48 | static int clk_system_is_enabled(struct clk_hw *hw) | ||
49 | { | ||
50 | struct clk_system *sys = to_clk_system(hw); | ||
51 | struct at91_pmc *pmc = sys->pmc; | ||
52 | |||
53 | return !!(pmc_read(pmc, AT91_PMC_SCSR) & (1 << sys->id)); | ||
54 | } | ||
55 | |||
56 | static const struct clk_ops system_ops = { | ||
57 | .enable = clk_system_enable, | ||
58 | .disable = clk_system_disable, | ||
59 | .is_enabled = clk_system_is_enabled, | ||
60 | }; | ||
61 | |||
62 | static struct clk * __init | ||
63 | at91_clk_register_system(struct at91_pmc *pmc, const char *name, | ||
64 | const char *parent_name, u8 id) | ||
65 | { | ||
66 | struct clk_system *sys; | ||
67 | struct clk *clk = NULL; | ||
68 | struct clk_init_data init; | ||
69 | |||
70 | if (!parent_name || id > SYSTEM_MAX_ID) | ||
71 | return ERR_PTR(-EINVAL); | ||
72 | |||
73 | sys = kzalloc(sizeof(*sys), GFP_KERNEL); | ||
74 | if (!sys) | ||
75 | return ERR_PTR(-ENOMEM); | ||
76 | |||
77 | init.name = name; | ||
78 | init.ops = &system_ops; | ||
79 | init.parent_names = &parent_name; | ||
80 | init.num_parents = 1; | ||
81 | /* | ||
82 | * CLK_IGNORE_UNUSED is used to avoid ddrck switch off. | ||
83 | * TODO : we should implement a driver supporting at91 ddr controller | ||
84 | * (see drivers/memory) which would request and enable the ddrck clock. | ||
85 | * When this is done we will be able to remove CLK_IGNORE_UNUSED flag. | ||
86 | */ | ||
87 | init.flags = CLK_IGNORE_UNUSED; | ||
88 | |||
89 | sys->id = id; | ||
90 | sys->hw.init = &init; | ||
91 | sys->pmc = pmc; | ||
92 | |||
93 | clk = clk_register(NULL, &sys->hw); | ||
94 | if (IS_ERR(clk)) | ||
95 | kfree(sys); | ||
96 | |||
97 | return clk; | ||
98 | } | ||
99 | |||
100 | static void __init | ||
101 | of_at91_clk_sys_setup(struct device_node *np, struct at91_pmc *pmc) | ||
102 | { | ||
103 | int num; | ||
104 | u32 id; | ||
105 | struct clk *clk; | ||
106 | const char *name; | ||
107 | struct device_node *sysclknp; | ||
108 | const char *parent_name; | ||
109 | |||
110 | num = of_get_child_count(np); | ||
111 | if (num > (SYSTEM_MAX_ID + 1)) | ||
112 | return; | ||
113 | |||
114 | for_each_child_of_node(np, sysclknp) { | ||
115 | if (of_property_read_u32(sysclknp, "reg", &id)) | ||
116 | continue; | ||
117 | |||
118 | if (of_property_read_string(np, "clock-output-names", &name)) | ||
119 | name = sysclknp->name; | ||
120 | |||
121 | parent_name = of_clk_get_parent_name(sysclknp, 0); | ||
122 | |||
123 | clk = at91_clk_register_system(pmc, name, parent_name, id); | ||
124 | if (IS_ERR(clk)) | ||
125 | continue; | ||
126 | |||
127 | of_clk_add_provider(sysclknp, of_clk_src_simple_get, clk); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | void __init of_at91rm9200_clk_sys_setup(struct device_node *np, | ||
132 | struct at91_pmc *pmc) | ||
133 | { | ||
134 | of_at91_clk_sys_setup(np, pmc); | ||
135 | } | ||
diff --git a/drivers/clk/at91/pmc.c b/drivers/clk/at91/pmc.c index a311cf3d5358..a97554f943e4 100644 --- a/drivers/clk/at91/pmc.c +++ b/drivers/clk/at91/pmc.c | |||
@@ -264,6 +264,11 @@ static const struct of_device_id pmc_clk_ids[] __initdata = { | |||
264 | .compatible = "atmel,at91sam9x5-clk-master", | 264 | .compatible = "atmel,at91sam9x5-clk-master", |
265 | .data = of_at91sam9x5_clk_master_setup, | 265 | .data = of_at91sam9x5_clk_master_setup, |
266 | }, | 266 | }, |
267 | /* System clocks */ | ||
268 | { | ||
269 | .compatible = "atmel,at91rm9200-clk-system", | ||
270 | .data = of_at91rm9200_clk_sys_setup, | ||
271 | }, | ||
267 | { /*sentinel*/ } | 272 | { /*sentinel*/ } |
268 | }; | 273 | }; |
269 | 274 | ||
diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h index be5c964accad..9c8a397cb850 100644 --- a/drivers/clk/at91/pmc.h +++ b/drivers/clk/at91/pmc.h | |||
@@ -77,4 +77,7 @@ extern void __init of_at91rm9200_clk_master_setup(struct device_node *np, | |||
77 | extern void __init of_at91sam9x5_clk_master_setup(struct device_node *np, | 77 | extern void __init of_at91sam9x5_clk_master_setup(struct device_node *np, |
78 | struct at91_pmc *pmc); | 78 | struct at91_pmc *pmc); |
79 | 79 | ||
80 | extern void __init of_at91rm9200_clk_sys_setup(struct device_node *np, | ||
81 | struct at91_pmc *pmc); | ||
82 | |||
80 | #endif /* __PMC_H_ */ | 83 | #endif /* __PMC_H_ */ |