Changeset View
Changeset View
Standalone View
Standalone View
sys/arm/ti/ti_prm.c
Show All 36 Lines | |||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <dev/fdt/simplebus.h> | #include <dev/fdt/simplebus.h> | ||||
#include <dev/ofw/ofw_bus_subr.h> | #include <dev/ofw/ofw_bus_subr.h> | ||||
#include <dev/extres/syscon/syscon.h> | |||||
#include <arm/ti/ti_prcm.h> | #include <arm/ti/ti_prcm.h> | ||||
#include <arm/ti/ti_prm.h> | #include <arm/ti/ti_prm.h> | ||||
#include "syscon_if.h" | |||||
#if 0 | #if 0 | ||||
#define DPRINTF(dev, msg...) device_printf(dev, msg) | #define DPRINTF(dev, msg...) device_printf(dev, msg) | ||||
#else | #else | ||||
#define DPRINTF(dev, msg...) | #define DPRINTF(dev, msg...) | ||||
#endif | #endif | ||||
/* relative to prcm address range */ | /* relative to prcm address range */ | ||||
#define TI_PRM_PER_RSTCTRL 0xC00 | #define TI_PRM_PER_RSTCTRL 0xC00 | ||||
struct ti_prm_softc { | struct ti_prm_softc { | ||||
device_t dev; | device_t dev; | ||||
uint8_t type; | uint8_t type; | ||||
bool has_reset; | bool has_reset; | ||||
struct syscon *syscon; | |||||
}; | }; | ||||
/* Device */ | /* Device */ | ||||
#define TI_OMAP_PRM_INST 10 | #define TI_OMAP_PRM_INST 10 | ||||
#define TI_AM3_PRM_INST 5 | #define TI_AM3_PRM_INST 5 | ||||
#define TI_AM4_PRM_INST 4 | #define TI_AM4_PRM_INST 4 | ||||
#define TI_OMAP4_PRM_INST 3 | #define TI_OMAP4_PRM_INST 3 | ||||
Show All 32 Lines | ti_prm_probe(device_t dev) | ||||
return(BUS_PROBE_DEFAULT); | return(BUS_PROBE_DEFAULT); | ||||
} | } | ||||
static int | static int | ||||
ti_prm_attach(device_t dev) | ti_prm_attach(device_t dev) | ||||
{ | { | ||||
struct ti_prm_softc *sc; | struct ti_prm_softc *sc; | ||||
phandle_t node; | phandle_t node; | ||||
int err; | |||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
sc->dev = dev; | sc->dev = dev; | ||||
sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data; | sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data; | ||||
node = ofw_bus_get_node(sc->dev); | node = ofw_bus_get_node(sc->dev); | ||||
if (OF_hasprop(node, "#reset-cells")) { | err = SYSCON_GET_HANDLE(dev, &sc->syscon); | ||||
if (err != 0) | |||||
panic("Cannot get syscon handle.\n"); | |||||
if (OF_hasprop(node, "#reset-cells") == 1) | |||||
sc->has_reset = true; | sc->has_reset = true; | ||||
} else | else | ||||
sc->has_reset = false; | sc->has_reset = false; | ||||
/* Make device visible for other drivers */ | /* Make device visible for other drivers */ | ||||
OF_device_register_xref(OF_xref_from_node(node), sc->dev); | OF_device_register_xref(OF_xref_from_node(node), sc->dev); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
ti_prm_detach(device_t dev) { | ti_prm_detach(device_t dev) { | ||||
return (EBUSY); | return (EBUSY); | ||||
} | } | ||||
int | int | ||||
ti_prm_reset(device_t dev) | ti_prm_reset(device_t dev) | ||||
{ | { | ||||
struct ti_prm_softc *sc; | struct ti_prm_softc *sc; | ||||
int err; | int err; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
if (sc->has_reset == false) | if (sc->has_reset == false) | ||||
return 1; | return 1; | ||||
err = ti_prm_modify_4(dev, TI_PRM_PER_RSTCTRL, 0x2, 0x00); | err = SYSCON_MODIFY_4(sc->syscon, TI_PRM_PER_RSTCTRL, 0x2, 0x00); | ||||
return (err); | |||||
} | |||||
int | return (err); | ||||
ti_prm_write_4(device_t dev, bus_addr_t addr, uint32_t val) | |||||
{ | |||||
struct ti_prm_softc *sc; | |||||
device_t parent; | |||||
parent = device_get_parent(dev); | |||||
sc = device_get_softc(dev); | |||||
DPRINTF(sc->dev, "offset=%lx write %x\n", addr, val); | |||||
ti_prcm_device_lock(parent); | |||||
ti_prcm_write_4(parent, addr, val); | |||||
ti_prcm_device_unlock(parent); | |||||
return (0); | |||||
} | |||||
int | |||||
ti_prm_read_4(device_t dev, bus_addr_t addr, uint32_t *val) | |||||
{ | |||||
struct ti_prm_softc *sc; | |||||
device_t parent; | |||||
parent = device_get_parent(dev); | |||||
sc = device_get_softc(dev); | |||||
ti_prcm_device_lock(parent); | |||||
ti_prcm_read_4(parent, addr, val); | |||||
ti_prcm_device_unlock(parent); | |||||
DPRINTF(sc->dev, "offset=%lx Read %x\n", addr, *val); | |||||
return (0); | |||||
} | |||||
int | |||||
ti_prm_modify_4(device_t dev, bus_addr_t addr, uint32_t clr, uint32_t set) | |||||
{ | |||||
struct ti_prm_softc *sc; | |||||
device_t parent; | |||||
parent = device_get_parent(dev); | |||||
sc = device_get_softc(dev); | |||||
ti_prcm_device_lock(parent); | |||||
ti_prcm_modify_4(parent, addr, clr, set); | |||||
ti_prcm_device_unlock(parent); | |||||
DPRINTF(sc->dev, "offset=%lx (clr %x set %x)\n", addr, clr, set); | |||||
return (0); | |||||
} | } | ||||
static device_method_t ti_prm_methods[] = { | static device_method_t ti_prm_methods[] = { | ||||
DEVMETHOD(device_probe, ti_prm_probe), | DEVMETHOD(device_probe, ti_prm_probe), | ||||
DEVMETHOD(device_attach, ti_prm_attach), | DEVMETHOD(device_attach, ti_prm_attach), | ||||
DEVMETHOD(device_detach, ti_prm_detach), | DEVMETHOD(device_detach, ti_prm_detach), | ||||
DEVMETHOD_END | DEVMETHOD_END | ||||
Show All 11 Lines |