| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: awin_mmc.c,v 1.21 2015/08/08 17:21:19 jmcneill Exp $ */ | | 1 | /* $NetBSD: awin_mmc.c,v 1.22 2015/10/16 14:22:25 bouyer 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 "locators.h" | | 29 | #include "locators.h" |
30 | | | 30 | |
31 | #include <sys/cdefs.h> | | 31 | #include <sys/cdefs.h> |
32 | __KERNEL_RCSID(0, "$NetBSD: awin_mmc.c,v 1.21 2015/08/08 17:21:19 jmcneill Exp $"); | | 32 | __KERNEL_RCSID(0, "$NetBSD: awin_mmc.c,v 1.22 2015/10/16 14:22:25 bouyer 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/device.h> | | 36 | #include <sys/device.h> |
37 | #include <sys/intr.h> | | 37 | #include <sys/intr.h> |
38 | #include <sys/systm.h> | | 38 | #include <sys/systm.h> |
39 | #include <sys/kernel.h> | | 39 | #include <sys/kernel.h> |
40 | | | 40 | |
41 | #include <dev/sdmmc/sdmmcvar.h> | | 41 | #include <dev/sdmmc/sdmmcvar.h> |
42 | #include <dev/sdmmc/sdmmcchip.h> | | 42 | #include <dev/sdmmc/sdmmcchip.h> |
43 | #include <dev/sdmmc/sdmmc_ioreg.h> | | 43 | #include <dev/sdmmc/sdmmc_ioreg.h> |
44 | | | 44 | |
45 | #include <arm/allwinner/awin_reg.h> | | 45 | #include <arm/allwinner/awin_reg.h> |
| @@ -336,27 +336,30 @@ awin_mmc_set_clock(struct awin_mmc_softc | | | @@ -336,27 +336,30 @@ awin_mmc_set_clock(struct awin_mmc_softc |
336 | pll_freq = awin_pll6_get_rate() / 1000; | | 336 | pll_freq = awin_pll6_get_rate() / 1000; |
337 | } | | 337 | } |
338 | | | 338 | |
339 | #ifdef AWIN_MMC_DEBUG | | 339 | #ifdef AWIN_MMC_DEBUG |
340 | aprint_normal_dev(sc->sc_dev, "freq = %d, pll_freq = %d\n", | | 340 | aprint_normal_dev(sc->sc_dev, "freq = %d, pll_freq = %d\n", |
341 | freq, pll_freq); | | 341 | freq, pll_freq); |
342 | #endif | | 342 | #endif |
343 | | | 343 | |
344 | if (freq <= 400) { | | 344 | if (freq <= 400) { |
345 | odly = 0; | | 345 | odly = 0; |
346 | sdly = 0; | | 346 | sdly = 0; |
347 | clksrc = AWIN_SD_CLK_SRC_SEL_OSC24M; | | 347 | clksrc = AWIN_SD_CLK_SRC_SEL_OSC24M; |
348 | n = 2; | | 348 | n = 2; |
349 | m = ((osc24m_freq / (1 << n)) / freq) - 1; | | 349 | if (freq > 0) |
| | | 350 | m = ((osc24m_freq / (1 << n)) / freq) - 1; |
| | | 351 | else |
| | | 352 | m = 15; |
350 | } else if (freq <= 25000) { | | 353 | } else if (freq <= 25000) { |
351 | odly = 0; | | 354 | odly = 0; |
352 | sdly = 5; | | 355 | sdly = 5; |
353 | clksrc = AWIN_SD_CLK_SRC_SEL_PLL6; | | 356 | clksrc = AWIN_SD_CLK_SRC_SEL_PLL6; |
354 | n = awin_chip_id() == AWIN_CHIP_ID_A80 ? 2 : 0; | | 357 | n = awin_chip_id() == AWIN_CHIP_ID_A80 ? 2 : 0; |
355 | m = ((pll_freq / freq) / (1 << n)) - 1; | | 358 | m = ((pll_freq / freq) / (1 << n)) - 1; |
356 | } else if (freq <= 50000) { | | 359 | } else if (freq <= 50000) { |
357 | odly = awin_chip_id() == AWIN_CHIP_ID_A80 ? 5 : 3; | | 360 | odly = awin_chip_id() == AWIN_CHIP_ID_A80 ? 5 : 3; |
358 | sdly = awin_chip_id() == AWIN_CHIP_ID_A80 ? 4 : 5; | | 361 | sdly = awin_chip_id() == AWIN_CHIP_ID_A80 ? 4 : 5; |
359 | clksrc = AWIN_SD_CLK_SRC_SEL_PLL6; | | 362 | clksrc = AWIN_SD_CLK_SRC_SEL_PLL6; |
360 | n = awin_chip_id() == AWIN_CHIP_ID_A80 ? 2 : 0; | | 363 | n = awin_chip_id() == AWIN_CHIP_ID_A80 ? 2 : 0; |
361 | m = ((pll_freq / freq) / (1 << n)) - 1; | | 364 | m = ((pll_freq / freq) / (1 << n)) - 1; |
362 | } else { | | 365 | } else { |