exynos5_pmu.c revision 269369
1/*- 2 * Copyright (c) 2014 Ruslan Bukin <br@bsdpad.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27/* 28 * Exynos 5 Power Management Unit (PMU) 29 */ 30 31#include <sys/cdefs.h> 32__FBSDID("$FreeBSD: head/sys/arm/samsung/exynos/exynos5_pmu.c 269369 2014-08-01 06:20:25Z br $"); 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/bus.h> 37#include <sys/kernel.h> 38#include <sys/module.h> 39#include <sys/malloc.h> 40#include <sys/rman.h> 41#include <sys/timeet.h> 42#include <sys/timetc.h> 43#include <sys/watchdog.h> 44 45#include <dev/fdt/fdt_common.h> 46#include <dev/ofw/openfirm.h> 47#include <dev/ofw/ofw_bus.h> 48#include <dev/ofw/ofw_bus_subr.h> 49 50#include <machine/bus.h> 51#include <machine/fdt.h> 52#include <machine/cpu.h> 53#include <machine/intr.h> 54 55#include <arm/samsung/exynos/exynos5_common.h> 56#include <arm/samsung/exynos/exynos5_pmu.h> 57 58#define EXYNOS5250 1 59#define EXYNOS5420 2 60 61/* PWR control */ 62#define EXYNOS5_PWR_USBHOST_PHY 0x708 63#define EXYNOS5_USBDRD_PHY_CTRL 0x704 64#define EXYNOS5420_USBDRD1_PHY_CTRL 0x708 65 66#define PHY_POWER_ON 1 67#define PHY_POWER_OFF 0 68 69struct pmu_softc { 70 struct resource *res[1]; 71 bus_space_tag_t bst; 72 bus_space_handle_t bsh; 73 device_t dev; 74 int model; 75}; 76 77struct pmu_softc *pmu_sc; 78 79static struct ofw_compat_data compat_data[] = { 80 {"samsung,exynos5420-pmu", EXYNOS5420}, 81 {"samsung,exynos5250-pmu", EXYNOS5250}, 82 {NULL, 0} 83}; 84 85static struct resource_spec pmu_spec[] = { 86 { SYS_RES_MEMORY, 0, RF_ACTIVE }, 87 { -1, 0 } 88}; 89 90static int 91pmu_probe(device_t dev) 92{ 93 94 if (!ofw_bus_status_okay(dev)) 95 return (ENXIO); 96 97 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data != 0) { 98 device_set_desc(dev, "Samsung Exynos 5 Power Management Unit"); 99 return (BUS_PROBE_DEFAULT); 100 } 101 102 return (ENXIO); 103} 104 105int 106usb2_phy_power_on(void) 107{ 108 struct pmu_softc *sc; 109 110 sc = pmu_sc; 111 if (sc == NULL) 112 return (-1); 113 114 /* EHCI */ 115 WRITE4(sc, EXYNOS5_PWR_USBHOST_PHY, PHY_POWER_ON); 116 117 return (0); 118} 119 120int 121usbdrd_phy_power_on(void) 122{ 123 struct pmu_softc *sc; 124 125 sc = pmu_sc; 126 if (sc == NULL) 127 return (-1); 128 129 /* 130 * First XHCI controller (left-side USB port on chromebook2) 131 */ 132 WRITE4(sc, EXYNOS5_USBDRD_PHY_CTRL, PHY_POWER_ON); 133 134 /* 135 * Second XHCI controller (right-side USB port on chrombook2) 136 * Only available on 5420. 137 */ 138 if (sc->model == EXYNOS5420) 139 WRITE4(sc, EXYNOS5420_USBDRD1_PHY_CTRL, PHY_POWER_ON); 140 141 return (0); 142} 143 144static int 145pmu_attach(device_t dev) 146{ 147 struct pmu_softc *sc; 148 149 sc = device_get_softc(dev); 150 sc->dev = dev; 151 sc->model = ofw_bus_search_compatible(dev, compat_data)->ocd_data; 152 153 if (bus_alloc_resources(dev, pmu_spec, sc->res)) { 154 device_printf(dev, "could not allocate resources\n"); 155 return (ENXIO); 156 } 157 158 /* Memory interface */ 159 sc->bst = rman_get_bustag(sc->res[0]); 160 sc->bsh = rman_get_bushandle(sc->res[0]); 161 162 pmu_sc = sc; 163 164 return (0); 165} 166 167static device_method_t pmu_methods[] = { 168 DEVMETHOD(device_probe, pmu_probe), 169 DEVMETHOD(device_attach, pmu_attach), 170 { 0, 0 } 171}; 172 173static driver_t pmu_driver = { 174 "pmu", 175 pmu_methods, 176 sizeof(struct pmu_softc), 177}; 178 179static devclass_t pmu_devclass; 180 181DRIVER_MODULE(pmu, simplebus, pmu_driver, pmu_devclass, 0, 0); 182