| @@ -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 | |
43 | bus_space_handle_t rockchip_core0_bsh; | | 43 | bus_space_handle_t rockchip_core0_bsh; |
44 | bus_space_handle_t rockchip_core1_bsh; | | 44 | bus_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 | |
| | | 205 | u_int |
| | | 206 | rockchip_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 | } |