Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev dwcmmc: set ciu clock rate rather than assuming fixe...
details: https://anonhg.NetBSD.org/src/rev/937c2b24d3cd
branches: trunk
changeset: 320019:937c2b24d3cd
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Tue Jun 19 22:44:33 2018 +0000
description:
dwcmmc: set ciu clock rate rather than assuming fixed input rate
diffstat:
sys/dev/fdt/dwcmmc_fdt.c | 39 ++++++++++++++++++++++++++++++++++-----
sys/dev/ic/dwc_mmc.c | 14 +++++++++++---
sys/dev/ic/dwc_mmc_var.h | 3 ++-
3 files changed, 47 insertions(+), 9 deletions(-)
diffs (156 lines):
diff -r 3ca60ea156ba -r 937c2b24d3cd sys/dev/fdt/dwcmmc_fdt.c
--- a/sys/dev/fdt/dwcmmc_fdt.c Tue Jun 19 21:47:28 2018 +0000
+++ b/sys/dev/fdt/dwcmmc_fdt.c Tue Jun 19 22:44:33 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dwcmmc_fdt.c,v 1.1 2018/06/16 00:19:04 jmcneill Exp $ */
+/* $NetBSD: dwcmmc_fdt.c,v 1.2 2018/06/19 22:44:33 jmcneill Exp $ */
/*-
* Copyright (c) 2015-2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dwcmmc_fdt.c,v 1.1 2018/06/16 00:19:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwcmmc_fdt.c,v 1.2 2018/06/19 22:44:33 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -46,6 +46,7 @@
static void dwcmmc_fdt_attach(device_t, device_t, void *);
static int dwcmmc_fdt_card_detect(struct dwc_mmc_softc *);
+static int dwcmmc_fdt_bus_clock(struct dwc_mmc_softc *, int);
struct dwcmmc_fdt_config {
u_int ciu_div;
@@ -66,6 +67,7 @@
struct clk *sc_clk_ciu;
struct fdtbus_gpio_pin *sc_pin_cd;
const struct dwcmmc_fdt_config *sc_conf;
+ u_int sc_ciu_div;
};
CFATTACH_DECL_NEW(dwcmmc_fdt, sizeof(struct dwc_mmc_softc),
@@ -86,10 +88,10 @@
struct dwc_mmc_softc *sc = &esc->sc;
struct fdt_attach_args * const faa = aux;
const int phandle = faa->faa_phandle;
+ u_int fifo_depth, max_freq;
char intrstr[128];
bus_addr_t addr;
bus_size_t size;
- u_int fifo_depth;
int error;
if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
@@ -135,9 +137,14 @@
const u_int ciu_div = esc->sc_conf->ciu_div > 0 ? esc->sc_conf->ciu_div : 1;
- sc->sc_clock_freq = clk_get_rate(esc->sc_clk_ciu) / (ciu_div + 1);
+ if (of_getprop_uint32(phandle, "max-frequency", &max_freq) == 0)
+ sc->sc_clock_freq = max_freq;
+ else
+ sc->sc_clock_freq = clk_get_rate(esc->sc_clk_ciu) / ciu_div;
+
sc->sc_fifo_depth = fifo_depth;
sc->sc_flags = DWC_MMC_F_USE_HOLD_REG | DWC_MMC_F_DMA;
+ sc->sc_bus_clock = dwcmmc_fdt_bus_clock;
esc->sc_pin_cd = fdtbus_gpio_acquire(phandle, "cd-gpios",
GPIO_PIN_INPUT);
@@ -145,7 +152,7 @@
sc->sc_card_detect = dwcmmc_fdt_card_detect;
aprint_naive("\n");
- aprint_normal(": SD/MMC controller (%u Hz)\n", sc->sc_clock_freq);
+ aprint_normal(": DesignWare SD/MMC\n");
if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
aprint_error_dev(self, "failed to decode interrupt\n");
@@ -174,3 +181,25 @@
return fdtbus_gpio_read(esc->sc_pin_cd);
}
+
+static int
+dwcmmc_fdt_bus_clock(struct dwc_mmc_softc *sc, int rate)
+{
+ struct dwcmmc_fdt_softc *esc = device_private(sc->sc_dev);
+ const u_int ciu_div = esc->sc_conf->ciu_div > 0 ? esc->sc_conf->ciu_div : 1;
+ int error;
+
+ error = clk_set_rate(esc->sc_clk_ciu, 1000 * rate * ciu_div);
+ if (error != 0) {
+ aprint_error_dev(sc->sc_dev, "failed to set rate to %u kHz: %d\n",
+ rate * ciu_div, error);
+ return error;
+ }
+
+ sc->sc_clock_freq = (clk_get_rate(esc->sc_clk_ciu) / ciu_div) / 1000;
+
+ aprint_debug_dev(sc->sc_dev, "set clock rate to %u kHz (target %u kHz)\n",
+ sc->sc_clock_freq, rate);
+
+ return 0;
+}
diff -r 3ca60ea156ba -r 937c2b24d3cd sys/dev/ic/dwc_mmc.c
--- a/sys/dev/ic/dwc_mmc.c Tue Jun 19 21:47:28 2018 +0000
+++ b/sys/dev/ic/dwc_mmc.c Tue Jun 19 22:44:33 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_mmc.c,v 1.12 2018/06/10 17:52:20 jmcneill Exp $ */
+/* $NetBSD: dwc_mmc.c,v 1.13 2018/06/19 22:44:33 jmcneill Exp $ */
/*-
* Copyright (c) 2014-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dwc_mmc.c,v 1.12 2018/06/10 17:52:20 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwc_mmc.c,v 1.13 2018/06/19 22:44:33 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -355,7 +355,12 @@
dwc_mmc_set_clock(struct dwc_mmc_softc *sc, u_int freq)
{
const u_int pll_freq = sc->sc_clock_freq / 1000;
- const u_int clk_div = howmany(pll_freq, freq * 2);
+ u_int clk_div;
+
+ if (freq != pll_freq)
+ clk_div = howmany(pll_freq, freq);
+ else
+ clk_div = 0;
MMC_WRITE(sc, DWC_MMC_CLKDIV, clk_div);
@@ -374,6 +379,9 @@
return 1;
if (freq) {
+ if (sc->sc_bus_clock && sc->sc_bus_clock(sc, freq) != 0)
+ return 1;
+
if (dwc_mmc_set_clock(sc, freq) != 0)
return 1;
diff -r 3ca60ea156ba -r 937c2b24d3cd sys/dev/ic/dwc_mmc_var.h
--- a/sys/dev/ic/dwc_mmc_var.h Tue Jun 19 21:47:28 2018 +0000
+++ b/sys/dev/ic/dwc_mmc_var.h Tue Jun 19 22:44:33 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_mmc_var.h,v 1.6 2017/06/19 22:03:02 jmcneill Exp $ */
+/* $NetBSD: dwc_mmc_var.h,v 1.7 2018/06/19 22:44:33 jmcneill Exp $ */
/*-
* Copyright (c) 2014-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -69,6 +69,7 @@
int (*sc_card_detect)(struct dwc_mmc_softc *);
int (*sc_write_protect)(struct dwc_mmc_softc *);
void (*sc_set_led)(struct dwc_mmc_softc *, int);
+ int (*sc_bus_clock)(struct dwc_mmc_softc *, int);
};
int dwc_mmc_init(struct dwc_mmc_softc *);
Home |
Main Index |
Thread Index |
Old Index