Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/bhnd/cores/pmu/bhnd_pmu.c
Show All 38 Lines | |||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <machine/bus.h> | #include <machine/bus.h> | ||||
#include <machine/resource.h> | #include <machine/resource.h> | ||||
#include <dev/bhnd/bhnd.h> | #include <dev/bhnd/bhnd.h> | ||||
#include <dev/bhnd/cores/chipc/chipc.h> | |||||
#include "bhnd_nvram_map.h" | #include "bhnd_nvram_map.h" | ||||
#include "bhnd_pmureg.h" | #include "bhnd_pmureg.h" | ||||
#include "bhnd_pmuvar.h" | #include "bhnd_pmuvar.h" | ||||
#include "bhnd_pmu_private.h" | #include "bhnd_pmu_private.h" | ||||
Show All 9 Lines | |||||
*/ | */ | ||||
devclass_t bhnd_pmu_devclass; /**< bhnd(4) PMU device class */ | devclass_t bhnd_pmu_devclass; /**< bhnd(4) PMU device class */ | ||||
static int bhnd_pmu_sysctl_bus_freq(SYSCTL_HANDLER_ARGS); | static int bhnd_pmu_sysctl_bus_freq(SYSCTL_HANDLER_ARGS); | ||||
static int bhnd_pmu_sysctl_cpu_freq(SYSCTL_HANDLER_ARGS); | static int bhnd_pmu_sysctl_cpu_freq(SYSCTL_HANDLER_ARGS); | ||||
static int bhnd_pmu_sysctl_mem_freq(SYSCTL_HANDLER_ARGS); | static int bhnd_pmu_sysctl_mem_freq(SYSCTL_HANDLER_ARGS); | ||||
static uint32_t bhnd_pmu_read_4(bus_size_t reg, void *ctx); | |||||
static void bhnd_pmu_write_4(bus_size_t reg, uint32_t val, void *ctx); | |||||
static uint32_t bhnd_pmu_read_chipst(void *ctx); | |||||
static const struct bhnd_pmu_io bhnd_pmu_res_io = { | |||||
.rd4 = bhnd_pmu_read_4, | |||||
.wr4 = bhnd_pmu_write_4, | |||||
.rd_chipst = bhnd_pmu_read_chipst | |||||
}; | |||||
#define BPMU_CLKCTL_READ_4(_pinfo) \ | #define BPMU_CLKCTL_READ_4(_pinfo) \ | ||||
bhnd_bus_read_4((_pinfo)->pm_res, (_pinfo)->pm_regs) | bhnd_bus_read_4((_pinfo)->pm_res, (_pinfo)->pm_regs) | ||||
#define BPMU_CLKCTL_WRITE_4(_pinfo, _val) \ | #define BPMU_CLKCTL_WRITE_4(_pinfo, _val) \ | ||||
bhnd_bus_write_4((_pinfo)->pm_res, (_pinfo)->pm_regs, (_val)) | bhnd_bus_write_4((_pinfo)->pm_res, (_pinfo)->pm_regs, (_val)) | ||||
#define BPMU_CLKCTL_SET_4(_pinfo, _val, _mask) \ | #define BPMU_CLKCTL_SET_4(_pinfo, _val, _mask) \ | ||||
BPMU_CLKCTL_WRITE_4((_pinfo), \ | BPMU_CLKCTL_WRITE_4((_pinfo), \ | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | bhnd_pmu_attach(device_t dev, struct bhnd_resource *res) | ||||
/* Locate ChipCommon device */ | /* Locate ChipCommon device */ | ||||
sc->chipc_dev = bhnd_find_child(bus, BHND_DEVCLASS_CC, 0); | sc->chipc_dev = bhnd_find_child(bus, BHND_DEVCLASS_CC, 0); | ||||
if (sc->chipc_dev == NULL) { | if (sc->chipc_dev == NULL) { | ||||
device_printf(sc->dev, "chipcommon device not found\n"); | device_printf(sc->dev, "chipcommon device not found\n"); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
/* Initialize query state */ | |||||
error = bhnd_pmu_query_init(&sc->query, dev, sc->cid, &bhnd_pmu_res_io, | |||||
sc); | |||||
if (error) | |||||
return (error); | |||||
sc->io = sc->query.io; | |||||
sc->io_ctx = sc->query.io_ctx; | |||||
BPMU_LOCK_INIT(sc); | BPMU_LOCK_INIT(sc); | ||||
/* Set quirk flags */ | /* Set quirk flags */ | ||||
switch (sc->cid.chip_id) { | switch (sc->cid.chip_id) { | ||||
case BHND_CHIPID_BCM4328: | case BHND_CHIPID_BCM4328: | ||||
case BHND_CHIPID_BCM5354: | case BHND_CHIPID_BCM5354: | ||||
/* HTAVAIL/ALPAVAIL are bitswapped in CLKCTL */ | /* HTAVAIL/ALPAVAIL are bitswapped in CLKCTL */ | ||||
sc->quirks |= BPMU_QUIRK_CLKCTL_CCS0; | sc->quirks |= BPMU_QUIRK_CLKCTL_CCS0; | ||||
Show All 23 Lines | bhnd_pmu_attach(device_t dev, struct bhnd_resource *res) | ||||
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, | SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, | ||||
"mem_freq", CTLTYPE_UINT | CTLFLAG_RD, sc, 0, | "mem_freq", CTLTYPE_UINT | CTLFLAG_RD, sc, 0, | ||||
bhnd_pmu_sysctl_mem_freq, "IU", "Memory clock frequency"); | bhnd_pmu_sysctl_mem_freq, "IU", "Memory clock frequency"); | ||||
return (0); | return (0); | ||||
failed: | failed: | ||||
BPMU_LOCK_DESTROY(sc); | BPMU_LOCK_DESTROY(sc); | ||||
bhnd_pmu_query_fini(&sc->query); | |||||
return (error); | return (error); | ||||
} | } | ||||
/** | /** | ||||
* Default bhnd_pmu driver implementation of DEVICE_DETACH(). | * Default bhnd_pmu driver implementation of DEVICE_DETACH(). | ||||
*/ | */ | ||||
int | int | ||||
bhnd_pmu_detach(device_t dev) | bhnd_pmu_detach(device_t dev) | ||||
{ | { | ||||
struct bhnd_pmu_softc *sc; | struct bhnd_pmu_softc *sc; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
BPMU_LOCK_DESTROY(sc); | BPMU_LOCK_DESTROY(sc); | ||||
bhnd_pmu_query_fini(&sc->query); | |||||
return (0); | return (0); | ||||
} | } | ||||
/** | /** | ||||
* Default bhnd_pmu driver implementation of DEVICE_SUSPEND(). | * Default bhnd_pmu driver implementation of DEVICE_SUSPEND(). | ||||
*/ | */ | ||||
int | int | ||||
Show All 26 Lines | |||||
bhnd_pmu_sysctl_bus_freq(SYSCTL_HANDLER_ARGS) | bhnd_pmu_sysctl_bus_freq(SYSCTL_HANDLER_ARGS) | ||||
{ | { | ||||
struct bhnd_pmu_softc *sc; | struct bhnd_pmu_softc *sc; | ||||
uint32_t freq; | uint32_t freq; | ||||
sc = arg1; | sc = arg1; | ||||
BPMU_LOCK(sc); | BPMU_LOCK(sc); | ||||
freq = bhnd_pmu_si_clock(sc); | freq = bhnd_pmu_si_clock(&sc->query); | ||||
BPMU_UNLOCK(sc); | BPMU_UNLOCK(sc); | ||||
return (sysctl_handle_32(oidp, NULL, freq, req)); | return (sysctl_handle_32(oidp, NULL, freq, req)); | ||||
} | } | ||||
static int | static int | ||||
bhnd_pmu_sysctl_cpu_freq(SYSCTL_HANDLER_ARGS) | bhnd_pmu_sysctl_cpu_freq(SYSCTL_HANDLER_ARGS) | ||||
{ | { | ||||
struct bhnd_pmu_softc *sc; | struct bhnd_pmu_softc *sc; | ||||
uint32_t freq; | uint32_t freq; | ||||
sc = arg1; | sc = arg1; | ||||
BPMU_LOCK(sc); | BPMU_LOCK(sc); | ||||
freq = bhnd_pmu_cpu_clock(sc); | freq = bhnd_pmu_cpu_clock(&sc->query); | ||||
BPMU_UNLOCK(sc); | BPMU_UNLOCK(sc); | ||||
return (sysctl_handle_32(oidp, NULL, freq, req)); | return (sysctl_handle_32(oidp, NULL, freq, req)); | ||||
} | } | ||||
static int | static int | ||||
bhnd_pmu_sysctl_mem_freq(SYSCTL_HANDLER_ARGS) | bhnd_pmu_sysctl_mem_freq(SYSCTL_HANDLER_ARGS) | ||||
{ | { | ||||
struct bhnd_pmu_softc *sc; | struct bhnd_pmu_softc *sc; | ||||
uint32_t freq; | uint32_t freq; | ||||
sc = arg1; | sc = arg1; | ||||
BPMU_LOCK(sc); | BPMU_LOCK(sc); | ||||
freq = bhnd_pmu_mem_clock(sc); | freq = bhnd_pmu_mem_clock(&sc->query); | ||||
BPMU_UNLOCK(sc); | BPMU_UNLOCK(sc); | ||||
return (sysctl_handle_32(oidp, NULL, freq, req)); | return (sysctl_handle_32(oidp, NULL, freq, req)); | ||||
} | } | ||||
static int | static int | ||||
bhnd_pmu_core_req_clock(device_t dev, struct bhnd_core_pmu_info *pinfo, | bhnd_pmu_core_req_clock(device_t dev, struct bhnd_core_pmu_info *pinfo, | ||||
bhnd_clock clock) | bhnd_clock clock) | ||||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | bhnd_pmu_core_release(device_t dev, struct bhnd_core_pmu_info *pinfo) | ||||
/* Clear all FORCE, AREQ, and ERSRC flags */ | /* Clear all FORCE, AREQ, and ERSRC flags */ | ||||
BPMU_CLKCTL_SET_4(pinfo, 0x0, | BPMU_CLKCTL_SET_4(pinfo, 0x0, | ||||
BHND_CCS_FORCE_MASK | BHND_CCS_AREQ_MASK | BHND_CCS_ERSRC_REQ_MASK); | BHND_CCS_FORCE_MASK | BHND_CCS_AREQ_MASK | BHND_CCS_ERSRC_REQ_MASK); | ||||
BPMU_UNLOCK(sc); | BPMU_UNLOCK(sc); | ||||
return (0); | return (0); | ||||
} | |||||
static uint32_t | |||||
bhnd_pmu_read_4(bus_size_t reg, void *ctx) | |||||
{ | |||||
struct bhnd_pmu_softc *sc = ctx; | |||||
return (bhnd_bus_read_4(sc->res, reg)); | |||||
} | |||||
static void | |||||
bhnd_pmu_write_4(bus_size_t reg, uint32_t val, void *ctx) | |||||
{ | |||||
struct bhnd_pmu_softc *sc = ctx; | |||||
return (bhnd_bus_write_4(sc->res, reg, val)); | |||||
} | |||||
static uint32_t | |||||
bhnd_pmu_read_chipst(void *ctx) | |||||
{ | |||||
struct bhnd_pmu_softc *sc = ctx; | |||||
return (BHND_CHIPC_READ_CHIPST(sc->chipc_dev)); | |||||
} | } | ||||
static device_method_t bhnd_pmu_methods[] = { | static device_method_t bhnd_pmu_methods[] = { | ||||
/* Device interface */ | /* Device interface */ | ||||
DEVMETHOD(device_probe, bhnd_pmu_probe), | DEVMETHOD(device_probe, bhnd_pmu_probe), | ||||
DEVMETHOD(device_detach, bhnd_pmu_detach), | DEVMETHOD(device_detach, bhnd_pmu_detach), | ||||
DEVMETHOD(device_suspend, bhnd_pmu_suspend), | DEVMETHOD(device_suspend, bhnd_pmu_suspend), | ||||
DEVMETHOD(device_resume, bhnd_pmu_resume), | DEVMETHOD(device_resume, bhnd_pmu_resume), | ||||
Show All 13 Lines |