Sat Dec 27 19:14:05 2014 UTC ()
mmc0 on rk3188 is based on ahb clk, not gpll. add a function to control mmc0 clock as well.


(jmcneill)
diff -r1.4 -r1.5 src/sys/arch/arm/rockchip/rockchip_board.c
diff -r1.5 -r1.6 src/sys/arch/arm/rockchip/rockchip_var.h

cvs diff -r1.4 -r1.5 src/sys/arch/arm/rockchip/Attic/rockchip_board.c (expand / switch to unified diff)

--- src/sys/arch/arm/rockchip/Attic/rockchip_board.c 2014/12/27 16:18:50 1.4
+++ src/sys/arch/arm/rockchip/Attic/rockchip_board.c 2014/12/27 19:14:05 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rockchip_board.c,v 1.4 2014/12/27 16:18:50 jmcneill Exp $ */ 1/* $NetBSD: rockchip_board.c,v 1.5 2014/12/27 19:14:05 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2014 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include "opt_rockchip.h" 29#include "opt_rockchip.h"
30 30
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__KERNEL_RCSID(0, "$NetBSD: rockchip_board.c,v 1.4 2014/12/27 16:18:50 jmcneill Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: rockchip_board.c,v 1.5 2014/12/27 19:14:05 jmcneill Exp $");
33 33
34#include <sys/param.h> 34#include <sys/param.h>
35#include <sys/bus.h> 35#include <sys/bus.h>
36#include <sys/cpu.h> 36#include <sys/cpu.h>
37#include <sys/device.h> 37#include <sys/device.h>
38 38
39#include <arm/rockchip/rockchip_reg.h> 39#include <arm/rockchip/rockchip_reg.h>
40#include <arm/rockchip/rockchip_crureg.h> 40#include <arm/rockchip/rockchip_crureg.h>
41#include <arm/rockchip/rockchip_var.h> 41#include <arm/rockchip/rockchip_var.h>
42 42
43bus_space_handle_t rockchip_core0_bsh; 43bus_space_handle_t rockchip_core0_bsh;
44bus_space_handle_t rockchip_core1_bsh; 44bus_space_handle_t rockchip_core1_bsh;
45 45
@@ -189,15 +189,51 @@ rockchip_mmc0_get_rate(void) @@ -189,15 +189,51 @@ rockchip_mmc0_get_rate(void)
189{ 189{
190 bus_space_tag_t bst = &rockchip_bs_tag; 190 bus_space_tag_t bst = &rockchip_bs_tag;
191 bus_space_handle_t bsh; 191 bus_space_handle_t bsh;
192 uint32_t clksel_con11; 192 uint32_t clksel_con11;
193 uint32_t mmc0_div_con; 193 uint32_t mmc0_div_con;
194 194
195 rockchip_get_cru_bsh(&bsh); 195 rockchip_get_cru_bsh(&bsh);
196 196
197 clksel_con11 = bus_space_read_4(bst, bsh, CRU_CLKSEL_CON_REG(11)); 197 clksel_con11 = bus_space_read_4(bst, bsh, CRU_CLKSEL_CON_REG(11));
198 198
199 mmc0_div_con = __SHIFTOUT(clksel_con11, 199 mmc0_div_con = __SHIFTOUT(clksel_con11,
200 CRU_CLKSEL_CON11_MMC0_DIV_CON); 200 CRU_CLKSEL_CON11_MMC0_DIV_CON);
201 201
202 return rockchip_gpll_get_rate() / (mmc0_div_con + 1); 202 return rockchip_ahb_get_rate() / (mmc0_div_con + 1);
 203}
 204
 205u_int
 206rockchip_mmc0_set_div(u_int div)
 207{
 208 bus_space_tag_t bst = &rockchip_bs_tag;
 209 bus_space_handle_t bsh;
 210 uint32_t clksel_con11;
 211
 212 if (div == 0 || div > 0x40)
 213 return EINVAL;
 214
 215 rockchip_get_cru_bsh(&bsh);
 216
 217 clksel_con11 = CRU_CLKSEL_CON11_MMC0_PLL_SEL_MASK |
 218 CRU_CLKSEL_CON11_MMC0_DIV_CON_MASK;
 219 //clksel_con11 |= CRU_CLKSEL_CON11_MMC0_PLL_SEL; /* GPLL */
 220 clksel_con11 |= __SHIFTIN(div - 1, CRU_CLKSEL_CON11_MMC0_DIV_CON);
 221
 222#ifdef ROCKCHIP_CLOCK_DEBUG
 223 const u_int old_rate = rockchip_mmc0_get_rate();
 224#endif
 225
 226 bus_space_write_4(bst, bsh, CRU_CLKSEL_CON_REG(11), clksel_con11);
 227
 228#ifdef ROCKCHIP_CLOCK_DEBUG
 229 const u_int new_rate = rockchip_mmc0_get_rate();
 230
 231 printf("%s: update %u Hz -> %u Hz\n", __func__, old_rate, new_rate);
 232
 233 const uint32_t clkgate2 = bus_space_read_4(bst, bsh,
 234 CRU_CLKGATE_CON_REG(2));
 235 printf("%s: clkgate2 = %#x\n", __func__, clkgate2);
 236#endif
 237
 238 return 0;
203} 239}

cvs diff -r1.5 -r1.6 src/sys/arch/arm/rockchip/Attic/rockchip_var.h (expand / switch to unified diff)

--- src/sys/arch/arm/rockchip/Attic/rockchip_var.h 2014/12/27 16:18:50 1.5
+++ src/sys/arch/arm/rockchip/Attic/rockchip_var.h 2014/12/27 19:14:05 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rockchip_var.h,v 1.5 2014/12/27 16:18:50 jmcneill Exp $ */ 1/* $NetBSD: rockchip_var.h,v 1.6 2014/12/27 19:14:05 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Hiroshi Tokuda 8 * by Hiroshi Tokuda
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -54,15 +54,16 @@ extern struct bus_space rockchip_bs_tag; @@ -54,15 +54,16 @@ extern struct bus_space rockchip_bs_tag;
54extern struct bus_space rockchip_a4x_bs_tag; 54extern struct bus_space rockchip_a4x_bs_tag;
55extern struct arm32_bus_dma_tag rockchip_bus_dma_tag; 55extern struct arm32_bus_dma_tag rockchip_bus_dma_tag;
56extern bus_space_handle_t rockchip_core0_bsh; 56extern bus_space_handle_t rockchip_core0_bsh;
57extern bus_space_handle_t rockchip_core1_bsh; 57extern bus_space_handle_t rockchip_core1_bsh;
58 58
59void rockchip_bootstrap(void); 59void rockchip_bootstrap(void);
60 60
61u_int rockchip_apll_get_rate(void); 61u_int rockchip_apll_get_rate(void);
62u_int rockchip_gpll_get_rate(void); 62u_int rockchip_gpll_get_rate(void);
63u_int rockchip_cpu_get_rate(void); 63u_int rockchip_cpu_get_rate(void);
64u_int rockchip_ahb_get_rate(void); 64u_int rockchip_ahb_get_rate(void);
65u_int rockchip_a9periph_get_rate(void); 65u_int rockchip_a9periph_get_rate(void);
66u_int rockchip_mmc0_get_rate(void); 66u_int rockchip_mmc0_get_rate(void);
 67u_int rockchip_mmc0_set_div(u_int);
67 68
68#endif /* _ARM_ROCKCHIP_ROCKCHIP_VAR_H_ */ 69#endif /* _ARM_ROCKCHIP_ROCKCHIP_VAR_H_ */