From a7fa939bb3564122505b0b6b66fdf00e13bffe01 Mon Sep 17 00:00:00 2001 From: Ian Lepore Date: Sat, 26 Apr 2014 16:48:09 +0000 Subject: [PATCH] Stop calling imx51_ccm_foo() clock functions from imx6 code. Instead define a few imx_ccm_foo() functions that are implemented by the imx51 or imx6 ccm code. Of course, the imx6 ccm code is still more a wish than reality, so for now its implementations just return hard-coded numbers. --- sys/arm/freescale/imx/imx51_ccm.c | 28 +++++++++++++ sys/arm/freescale/imx/imx6_ccm.c | 54 +++++++++++++++----------- sys/arm/freescale/imx/imx6_usbphy.c | 2 +- sys/arm/freescale/imx/imx_ccmvar.h | 54 ++++++++++++++++++++++++++ sys/arm/freescale/imx/imx_gpt.c | 6 +-- sys/arm/freescale/imx/imx_machdep.h | 16 -------- sys/arm/freescale/imx/imx_nop_usbphy.c | 2 +- sys/arm/freescale/imx/imx_sdhci.c | 9 +---- sys/dev/usb/controller/ehci_imx.c | 2 +- 9 files changed, 122 insertions(+), 51 deletions(-) create mode 100644 sys/arm/freescale/imx/imx_ccmvar.h diff --git a/sys/arm/freescale/imx/imx51_ccm.c b/sys/arm/freescale/imx/imx51_ccm.c index 61fdfdc75b3..e0043644ad0 100644 --- a/sys/arm/freescale/imx/imx51_ccm.c +++ b/sys/arm/freescale/imx/imx51_ccm.c @@ -83,6 +83,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #define IMXCCMDEBUG @@ -552,3 +553,30 @@ imx_ccm_usbphy_enable(device_t dev) } } +uint32_t +imx_ccm_ipg_hz(void) +{ + + return (imx51_get_clock(IMX51CLK_IPG_CLK_ROOT)); +} + +uint32_t +imx_ccm_sdhci_hz(void) +{ + + return (imx51_get_clock(IMX51CLK_ESDHC1_CLK_ROOT)); +} + +uint32_t +imx_ccm_perclk_hz(void) +{ + + return (imx51_get_clock(IMX51CLK_PERCLK_ROOT)); +} + +uint32_t +imx_ccm_uart_hz(void) +{ + + return (imx51_get_clock(IMX51CLK_UART_CLK_ROOT)); +} diff --git a/sys/arm/freescale/imx/imx6_ccm.c b/sys/arm/freescale/imx/imx6_ccm.c index 2ed301f435c..132c31c3a79 100644 --- a/sys/arm/freescale/imx/imx6_ccm.c +++ b/sys/arm/freescale/imx/imx6_ccm.c @@ -45,13 +45,15 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include +#include +#include - -/* XXX temp kludge for imx51_get_clock. */ -#include -#include +#ifndef CCGR_CLK_MODE_ALWAYS +#define CCGR_CLK_MODE_OFF 0 +#define CCGR_CLK_MODE_RUNMODE 1 +#define CCGR_CLK_MODE_ALWAYS 3 +#endif struct ccm_softc { device_t dev; @@ -208,24 +210,32 @@ imx_ccm_usbphy_enable(device_t _phydev) #endif } - - - - -// XXX Fix this. This has to be here for other code to link, -// but it doesn't have to return anything useful for imx6 right now. -u_int -imx51_get_clock(enum imx51_clock clk) +uint32_t +imx_ccm_ipg_hz(void) { - switch (clk) - { - case IMX51CLK_IPG_CLK_ROOT: - return 66000000; - default: - printf("imx51_get_clock() on imx6 doesn't know about clock %d\n", clk); - break; - } - return 0; + + return (66000000); +} + +uint32_t +imx_ccm_perclk_hz(void) +{ + + return (66000000); +} + +uint32_t +imx_ccm_sdhci_hz(void) +{ + + return (200000000); +} + +uint32_t +imx_ccm_uart_hz(void) +{ + + return (80000000); } static device_method_t ccm_methods[] = { diff --git a/sys/arm/freescale/imx/imx6_usbphy.c b/sys/arm/freescale/imx/imx6_usbphy.c index 7f3e362a563..a338737a63d 100644 --- a/sys/arm/freescale/imx/imx6_usbphy.c +++ b/sys/arm/freescale/imx/imx6_usbphy.c @@ -45,7 +45,7 @@ __FBSDID("$FreeBSD$"); #include -#include +#include #include #include diff --git a/sys/arm/freescale/imx/imx_ccmvar.h b/sys/arm/freescale/imx/imx_ccmvar.h new file mode 100644 index 00000000000..bb41a026851 --- /dev/null +++ b/sys/arm/freescale/imx/imx_ccmvar.h @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2014 Ian Lepore + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef IMX_CCMVAR_H +#define IMX_CCMVAR_H + +/* + * We need a clock management system that works across unrelated SoCs and + * devices. For now, to keep imx development moving, define some barebones + * functionality that can be shared within the imx family by having each SoC + * implement functions with a common name. + * + * The usb enable functions are best-effort. They turn on the usb otg, host, + * and phy clocks in a SoC-specific manner, but it may take a lot more than that + * to make usb work on a given board. In particular, it can require specific + * pinmux setup of gpio pins connected to external phy parts, voltage regulators + * and overcurrent detectors, and so on. On such boards, u-boot or other early + * board setup code has to handle those things. + */ + +uint32_t imx_ccm_ipg_hz(void); +uint32_t imx_ccm_perclk_hz(void); +uint32_t imx_ccm_sdhci_hz(void); +uint32_t imx_ccm_uart_hz(void); + +void imx_ccm_usb_enable(device_t _usbdev); +void imx_ccm_usbphy_enable(device_t _phydev); + +#endif diff --git a/sys/arm/freescale/imx/imx_gpt.c b/sys/arm/freescale/imx/imx_gpt.c index 73bc8ece31f..abbb1409996 100644 --- a/sys/arm/freescale/imx/imx_gpt.c +++ b/sys/arm/freescale/imx/imx_gpt.c @@ -54,7 +54,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include #define WRITE4(_sc, _r, _v) \ bus_space_write_4((_sc)->sc_iot, (_sc)->sc_ioh, (_r), (_v)) @@ -164,10 +164,10 @@ imx_gpt_attach(device_t dev) basefreq = 32768; break; case GPT_CR_CLKSRC_IPG: - basefreq = imx51_get_clock(IMX51CLK_IPG_CLK_ROOT); + basefreq = imx_ccm_ipg_hz(); break; case GPT_CR_CLKSRC_IPG_HIGH: - basefreq = imx51_get_clock(IMX51CLK_IPG_CLK_ROOT) * 2; + basefreq = imx_ccm_ipg_hz() * 2; break; case GPT_CR_CLKSRC_24M: ctlreg |= GPT_CR_24MEN; diff --git a/sys/arm/freescale/imx/imx_machdep.h b/sys/arm/freescale/imx/imx_machdep.h index b78f0da288b..6909e51504b 100644 --- a/sys/arm/freescale/imx/imx_machdep.h +++ b/sys/arm/freescale/imx/imx_machdep.h @@ -56,21 +56,5 @@ void imx_wdog_cpu_reset(vm_offset_t _wdcr_phys) __attribute__((__noreturn__)); u_int imx_soc_type(void); u_int imx_soc_family(void); -/* - * We need a clock management system that works across unrelated SoCs and - * devices. For now, to keep imx development moving, define some barebones - * functionality that can be shared within the imx family by having each SoC - * implement functions with a common name. - * - * The usb enable functions are best-effort. They turn on the usb otg, host, - * and phy clocks in a SoC-specific manner, but it may take a lot more than that - * to make usb work on a given board. In particular, it can require specific - * pinmux setup of gpio pins connected to external phy parts, voltage regulators - * and overcurrent detectors, and so on. On such boards, u-boot or other early - * board setup code has to handle those things. - */ -void imx_ccm_usb_enable(device_t _usbdev); -void imx_ccm_usbphy_enable(device_t _phydev); - #endif diff --git a/sys/arm/freescale/imx/imx_nop_usbphy.c b/sys/arm/freescale/imx/imx_nop_usbphy.c index 38473dd7696..49bebfcd573 100644 --- a/sys/arm/freescale/imx/imx_nop_usbphy.c +++ b/sys/arm/freescale/imx/imx_nop_usbphy.c @@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$"); #include -#include +#include /* * Table of supported FDT compat strings. diff --git a/sys/arm/freescale/imx/imx_sdhci.c b/sys/arm/freescale/imx/imx_sdhci.c index 2e3d1a5b5b0..a476cb75cee 100644 --- a/sys/arm/freescale/imx/imx_sdhci.c +++ b/sys/arm/freescale/imx/imx_sdhci.c @@ -52,7 +52,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include #include #include @@ -723,12 +723,7 @@ imx_sdhci_attach(device_t dev) */ WR4(sc, SDHC_WTMK_LVL, 0x08800880); - /* XXX get imx6 clock frequency from CCM */ - if (sc->hwtype == HWTYPE_USDHC) { - sc->baseclk_hz = 200000000; - } else if (sc->hwtype == HWTYPE_ESDHC) { - sc->baseclk_hz = imx51_get_clock(IMX51CLK_PERCLK_ROOT); - } + sc->baseclk_hz = imx_ccm_sdhci_hz(); /* * If the slot is flagged with the non-removable property, set our flag diff --git a/sys/dev/usb/controller/ehci_imx.c b/sys/dev/usb/controller/ehci_imx.c index d40f18d8c42..b36e7e65aca 100644 --- a/sys/dev/usb/controller/ehci_imx.c +++ b/sys/dev/usb/controller/ehci_imx.c @@ -60,7 +60,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include #include "opt_platform.h"