diff options
author | Dinh Nguyen <dinguyen@altera.com> | 2014-01-06 13:17:24 -0500 |
---|---|---|
committer | Mike Turquette <mturquette@linaro.org> | 2014-02-18 17:08:14 -0500 |
commit | 044abbde7bef2726489b5e11ec3fcdc012a4de4a (patch) | |
tree | c4d78dceb33f2b1450f37a778f1af8946f82c9ae | |
parent | 97259e99bdc9144d071815536f1dbc2e41c6b5a8 (diff) |
clk: socfpga: Add a clk-phase property to the "altr,socfpga-gate-clk"
The clk-phase property is used to represent the 2 clock phase values that is
needed for the SD/MMC driver. Add a prepare function to the clk_ops, that will
use the syscon driver to set sdmmc_clk's phase shift that is located in the
system manager.
Signed-off-by: Dinh Nguyen <dinguyen@altera.com>
Acked-by: Zhangfei Gao <zhangfei.gao@linaro.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
---
v9: none
v8: Use degrees in the clk-phase binding property
v7: Add dts property to represent the clk phase of the sdmmc_clk. Add a
prepare function to the gate clk that will toggle clock phase setting.
Remove the "altr,socfpga-sdmmc-sdr-clk" clock type.
v6: Add a new clock type "altr,socfpga-sdmmc-sdr-clk" that will be used to
set the phase shift settings.
v5: Use the "snps,dw-mshc" binding
v4: Use the sdmmc_clk prepare function to set the phase shift settings
v3: Not use the syscon driver because as of 3.13-rc1, the syscon driver is
loaded after the clock driver.
v2: Use the syscon driver
-rw-r--r-- | Documentation/devicetree/bindings/clock/altr_socfpga.txt | 5 | ||||
-rw-r--r-- | arch/arm/boot/dts/socfpga.dtsi | 1 | ||||
-rw-r--r-- | drivers/clk/socfpga/clk-gate.c | 68 |
3 files changed, 74 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/clock/altr_socfpga.txt b/Documentation/devicetree/bindings/clock/altr_socfpga.txt index 0045433eae1f..5dfd145d3ccf 100644 --- a/Documentation/devicetree/bindings/clock/altr_socfpga.txt +++ b/Documentation/devicetree/bindings/clock/altr_socfpga.txt | |||
@@ -23,3 +23,8 @@ Optional properties: | |||
23 | and the bit index. | 23 | and the bit index. |
24 | - div-reg : For "socfpga-gate-clk", div-reg contains the divider register, bit shift, | 24 | - div-reg : For "socfpga-gate-clk", div-reg contains the divider register, bit shift, |
25 | and width. | 25 | and width. |
26 | - clk-phase : For the sdmmc_clk, contains the value of the clock phase that controls | ||
27 | the SDMMC CIU clock. The first value is the clk_sample(smpsel), and the second | ||
28 | value is the cclk_in_drv(drvsel). The clk-phase is used to enable the correct | ||
29 | hold/delay times that is needed for the SD/MMC CIU clock. The values of both | ||
30 | can be 0-315 degrees, in 45 degree increments. | ||
diff --git a/arch/arm/boot/dts/socfpga.dtsi b/arch/arm/boot/dts/socfpga.dtsi index 537f1a5c07f5..3d62f47bead2 100644 --- a/arch/arm/boot/dts/socfpga.dtsi +++ b/arch/arm/boot/dts/socfpga.dtsi | |||
@@ -415,6 +415,7 @@ | |||
415 | compatible = "altr,socfpga-gate-clk"; | 415 | compatible = "altr,socfpga-gate-clk"; |
416 | clocks = <&f2s_periph_ref_clk>, <&main_nand_sdmmc_clk>, <&per_nand_mmc_clk>; | 416 | clocks = <&f2s_periph_ref_clk>, <&main_nand_sdmmc_clk>, <&per_nand_mmc_clk>; |
417 | clk-gate = <0xa0 8>; | 417 | clk-gate = <0xa0 8>; |
418 | clk-phase = <0 135>; | ||
418 | }; | 419 | }; |
419 | 420 | ||
420 | nand_x_clk: nand_x_clk { | 421 | nand_x_clk: nand_x_clk { |
diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c index 4efcf4e33a82..501d513bf890 100644 --- a/drivers/clk/socfpga/clk-gate.c +++ b/drivers/clk/socfpga/clk-gate.c | |||
@@ -19,7 +19,9 @@ | |||
19 | #include <linux/clkdev.h> | 19 | #include <linux/clkdev.h> |
20 | #include <linux/clk-provider.h> | 20 | #include <linux/clk-provider.h> |
21 | #include <linux/io.h> | 21 | #include <linux/io.h> |
22 | #include <linux/mfd/syscon.h> | ||
22 | #include <linux/of.h> | 23 | #include <linux/of.h> |
24 | #include <linux/regmap.h> | ||
23 | 25 | ||
24 | #include "clk.h" | 26 | #include "clk.h" |
25 | 27 | ||
@@ -35,6 +37,11 @@ | |||
35 | 37 | ||
36 | #define to_socfpga_gate_clk(p) container_of(p, struct socfpga_gate_clk, hw.hw) | 38 | #define to_socfpga_gate_clk(p) container_of(p, struct socfpga_gate_clk, hw.hw) |
37 | 39 | ||
40 | /* SDMMC Group for System Manager defines */ | ||
41 | #define SYSMGR_SDMMCGRP_CTRL_OFFSET 0x108 | ||
42 | #define SYSMGR_SDMMC_CTRL_SET(smplsel, drvsel) \ | ||
43 | ((((smplsel) & 0x7) << 3) | (((drvsel) & 0x7) << 0)) | ||
44 | |||
38 | static u8 socfpga_clk_get_parent(struct clk_hw *hwclk) | 45 | static u8 socfpga_clk_get_parent(struct clk_hw *hwclk) |
39 | { | 46 | { |
40 | u32 l4_src; | 47 | u32 l4_src; |
@@ -115,7 +122,61 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk, | |||
115 | return parent_rate / div; | 122 | return parent_rate / div; |
116 | } | 123 | } |
117 | 124 | ||
125 | static int socfpga_clk_prepare(struct clk_hw *hwclk) | ||
126 | { | ||
127 | struct socfpga_gate_clk *socfpgaclk = to_socfpga_gate_clk(hwclk); | ||
128 | struct regmap *sys_mgr_base_addr; | ||
129 | int i; | ||
130 | u32 hs_timing; | ||
131 | u32 clk_phase[2]; | ||
132 | |||
133 | if (socfpgaclk->clk_phase[0] || socfpgaclk->clk_phase[1]) { | ||
134 | sys_mgr_base_addr = syscon_regmap_lookup_by_compatible("altr,sys-mgr"); | ||
135 | if (IS_ERR(sys_mgr_base_addr)) { | ||
136 | pr_err("%s: failed to find altr,sys-mgr regmap!\n", __func__); | ||
137 | return -EINVAL; | ||
138 | } | ||
139 | |||
140 | for (i = 0; i < 2; i++) { | ||
141 | switch (socfpgaclk->clk_phase[i]) { | ||
142 | case 0: | ||
143 | clk_phase[i] = 0; | ||
144 | break; | ||
145 | case 45: | ||
146 | clk_phase[i] = 1; | ||
147 | break; | ||
148 | case 90: | ||
149 | clk_phase[i] = 2; | ||
150 | break; | ||
151 | case 135: | ||
152 | clk_phase[i] = 3; | ||
153 | break; | ||
154 | case 180: | ||
155 | clk_phase[i] = 4; | ||
156 | break; | ||
157 | case 225: | ||
158 | clk_phase[i] = 5; | ||
159 | break; | ||
160 | case 270: | ||
161 | clk_phase[i] = 6; | ||
162 | break; | ||
163 | case 315: | ||
164 | clk_phase[i] = 7; | ||
165 | break; | ||
166 | default: | ||
167 | clk_phase[i] = 0; | ||
168 | break; | ||
169 | } | ||
170 | } | ||
171 | hs_timing = SYSMGR_SDMMC_CTRL_SET(clk_phase[0], clk_phase[1]); | ||
172 | regmap_write(sys_mgr_base_addr, SYSMGR_SDMMCGRP_CTRL_OFFSET, | ||
173 | hs_timing); | ||
174 | } | ||
175 | return 0; | ||
176 | } | ||
177 | |||
118 | static struct clk_ops gateclk_ops = { | 178 | static struct clk_ops gateclk_ops = { |
179 | .prepare = socfpga_clk_prepare, | ||
119 | .recalc_rate = socfpga_clk_recalc_rate, | 180 | .recalc_rate = socfpga_clk_recalc_rate, |
120 | .get_parent = socfpga_clk_get_parent, | 181 | .get_parent = socfpga_clk_get_parent, |
121 | .set_parent = socfpga_clk_set_parent, | 182 | .set_parent = socfpga_clk_set_parent, |
@@ -126,6 +187,7 @@ static void __init __socfpga_gate_init(struct device_node *node, | |||
126 | { | 187 | { |
127 | u32 clk_gate[2]; | 188 | u32 clk_gate[2]; |
128 | u32 div_reg[3]; | 189 | u32 div_reg[3]; |
190 | u32 clk_phase[2]; | ||
129 | u32 fixed_div; | 191 | u32 fixed_div; |
130 | struct clk *clk; | 192 | struct clk *clk; |
131 | struct socfpga_gate_clk *socfpga_clk; | 193 | struct socfpga_gate_clk *socfpga_clk; |
@@ -166,6 +228,12 @@ static void __init __socfpga_gate_init(struct device_node *node, | |||
166 | socfpga_clk->div_reg = 0; | 228 | socfpga_clk->div_reg = 0; |
167 | } | 229 | } |
168 | 230 | ||
231 | rc = of_property_read_u32_array(node, "clk-phase", clk_phase, 2); | ||
232 | if (!rc) { | ||
233 | socfpga_clk->clk_phase[0] = clk_phase[0]; | ||
234 | socfpga_clk->clk_phase[1] = clk_phase[1]; | ||
235 | } | ||
236 | |||
169 | of_property_read_string(node, "clock-output-names", &clk_name); | 237 | of_property_read_string(node, "clock-output-names", &clk_name); |
170 | 238 | ||
171 | init.name = clk_name; | 239 | init.name = clk_name; |