diff options
author | ganbold <ganbold@FreeBSD.org> | 2014-03-03 11:00:52 +0000 |
---|---|---|
committer | ganbold <ganbold@FreeBSD.org> | 2014-03-03 11:00:52 +0000 |
commit | e1bf6a5f62b63db8dcbe88e0de8f5c5aff176070 (patch) | |
tree | c1f64267c17526915f9f12b51519611613b91559 /sys/arm/allwinner | |
parent | c7ed23130a9d3bd99ad49c207482e6a41091d780 (diff) | |
download | FreeBSD-src-e1bf6a5f62b63db8dcbe88e0de8f5c5aff176070.zip FreeBSD-src-e1bf6a5f62b63db8dcbe88e0de8f5c5aff176070.tar.gz |
Add gpio and clock bits for A10/A20's EMAC ethernet controller driver, such as:
- EMAC gpio configuration
- EMAC clock activation
Approved by: stas (mentor)
Diffstat (limited to 'sys/arm/allwinner')
-rw-r--r-- | sys/arm/allwinner/a10_clk.c | 20 | ||||
-rw-r--r-- | sys/arm/allwinner/a10_clk.h | 2 | ||||
-rw-r--r-- | sys/arm/allwinner/a10_gpio.c | 22 | ||||
-rw-r--r-- | sys/arm/allwinner/a10_gpio.h | 34 |
4 files changed, 76 insertions, 2 deletions
diff --git a/sys/arm/allwinner/a10_clk.c b/sys/arm/allwinner/a10_clk.c index aca137d..3354c02 100644 --- a/sys/arm/allwinner/a10_clk.c +++ b/sys/arm/allwinner/a10_clk.c @@ -127,7 +127,7 @@ a10_clk_usb_activate(void) uint32_t reg_value; if (sc == NULL) - return ENXIO; + return (ENXIO); /* Gating AHB clock for USB */ reg_value = ccm_read_4(sc, CCM_AHB_GATING0); @@ -154,7 +154,7 @@ a10_clk_usb_deactivate(void) uint32_t reg_value; if (sc == NULL) - return ENXIO; + return (ENXIO); /* Disable clock for USB */ reg_value = ccm_read_4(sc, CCM_USB_CLK); @@ -173,3 +173,19 @@ a10_clk_usb_deactivate(void) return (0); } +int +a10_clk_emac_activate(void) { + struct a10_ccm_softc *sc = a10_ccm_sc; + uint32_t reg_value; + + if (sc == NULL) + return (ENXIO); + + /* Gating AHB clock for EMAC */ + reg_value = ccm_read_4(sc, CCM_AHB_GATING0); + reg_value |= CCM_AHB_GATING_EMAC; + ccm_write_4(sc, CCM_AHB_GATING0, reg_value); + + return (0); +} + diff --git a/sys/arm/allwinner/a10_clk.h b/sys/arm/allwinner/a10_clk.h index a2a6bc9..6bc8ac9 100644 --- a/sys/arm/allwinner/a10_clk.h +++ b/sys/arm/allwinner/a10_clk.h @@ -103,6 +103,7 @@ #define CCM_AHB_GATING_USB0 (1 << 0) #define CCM_AHB_GATING_EHCI0 (1 << 1) #define CCM_AHB_GATING_EHCI1 (1 << 3) +#define CCM_AHB_GATING_EMAC (1 << 17) #define CCM_USB_PHY (1 << 8) #define CCM_USB0_RESET (1 << 0) @@ -111,5 +112,6 @@ int a10_clk_usb_activate(void); int a10_clk_usb_deactivate(void); +int a10_clk_emac_activate(void); #endif /* _A10_CLK_H_ */ diff --git a/sys/arm/allwinner/a10_gpio.c b/sys/arm/allwinner/a10_gpio.c index 1ecb27b..be269d8 100644 --- a/sys/arm/allwinner/a10_gpio.c +++ b/sys/arm/allwinner/a10_gpio.c @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); #include <dev/ofw/ofw_bus_subr.h> #include "gpio_if.h" +#include "a10_gpio.h" /* * A10 have 9 banks of gpio. @@ -102,6 +103,8 @@ struct a10_gpio_softc { #define A10_GPIO_GP_INT_STA 0x214 #define A10_GPIO_GP_INT_DEB 0x218 +static struct a10_gpio_softc *a10_gpio_sc; + #define A10_GPIO_WRITE(_sc, _off, _val) \ bus_space_write_4(_sc->sc_bst, _sc->sc_bsh, _off, _val) #define A10_GPIO_READ(_sc, _off) \ @@ -473,6 +476,9 @@ a10_gpio_attach(device_t dev) device_add_child(dev, "gpioc", device_get_unit(dev)); device_add_child(dev, "gpiobus", device_get_unit(dev)); + + a10_gpio_sc = sc; + return (bus_generic_attach(dev)); fail: @@ -518,3 +524,19 @@ static driver_t a10_gpio_driver = { }; DRIVER_MODULE(a10_gpio, simplebus, a10_gpio_driver, a10_gpio_devclass, 0, 0); + +int +a10_emac_gpio_config(uint32_t pin) +{ + struct a10_gpio_softc *sc = a10_gpio_sc; + + if (sc == NULL) + return (ENXIO); + + /* Configure pin mux settings for MII. */ + A10_GPIO_LOCK(sc); + a10_gpio_set_function(sc, pin, A10_GPIO_PULLDOWN); + A10_GPIO_UNLOCK(sc); + + return (0); +} diff --git a/sys/arm/allwinner/a10_gpio.h b/sys/arm/allwinner/a10_gpio.h new file mode 100644 index 0000000..b637985 --- /dev/null +++ b/sys/arm/allwinner/a10_gpio.h @@ -0,0 +1,34 @@ +/*- + * Copyright (c) 2013 Ganbold Tsagaankhuu <ganbold@gmail.com> + * 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 _A10_GPIO_H_ +#define _A10_GPIO_H_ + +int a10_emac_gpio_config(uint32_t pin); + +#endif |