Changeset View
Changeset View
Standalone View
Standalone View
sys/arm/ti/am335x/am335x_pwmss.c
Show All 40 Lines | |||||
#include <machine/bus.h> | #include <machine/bus.h> | ||||
#include <dev/fdt/simplebus.h> | #include <dev/fdt/simplebus.h> | ||||
#include <dev/ofw/openfirm.h> | #include <dev/ofw/openfirm.h> | ||||
#include <dev/ofw/ofw_bus.h> | #include <dev/ofw/ofw_bus.h> | ||||
#include <dev/ofw/ofw_bus_subr.h> | #include <dev/ofw/ofw_bus_subr.h> | ||||
#include <arm/ti/ti_prcm.h> | #include <arm/ti/ti_sysc.h> | ||||
#include <arm/ti/ti_hwmods.h> | |||||
#include <arm/ti/ti_scm.h> | |||||
#include <dev/extres/syscon/syscon.h> | |||||
#include "syscon_if.h" | |||||
#include "am335x_pwm.h" | #include "am335x_pwm.h" | ||||
#include "am335x_scm.h" | #include "am335x_scm.h" | ||||
#define PWMSS_IDVER 0x00 | #define PWMSS_IDVER 0x00 | ||||
#define PWMSS_SYSCONFIG 0x04 | #define PWMSS_SYSCONFIG 0x04 | ||||
#define PWMSS_CLKCONFIG 0x08 | #define PWMSS_CLKCONFIG 0x08 | ||||
#define CLKCONFIG_EPWMCLK_EN (1 << 8) | #define CLKCONFIG_EPWMCLK_EN (1 << 8) | ||||
#define PWMSS_CLKSTATUS 0x0C | #define PWMSS_CLKSTATUS 0x0C | ||||
/* TRM chapter 2 memory map table 2-3 + VER register location */ | |||||
#define PWMSS_REV_0 0x0000 | |||||
#define PWMSS_REV_1 0x2000 | |||||
#define PWMSS_REV_2 0x4000 | |||||
static device_probe_t am335x_pwmss_probe; | static device_probe_t am335x_pwmss_probe; | ||||
static device_attach_t am335x_pwmss_attach; | static device_attach_t am335x_pwmss_attach; | ||||
static device_detach_t am335x_pwmss_detach; | static device_detach_t am335x_pwmss_detach; | ||||
struct am335x_pwmss_softc { | struct am335x_pwmss_softc { | ||||
struct simplebus_softc sc_simplebus; | struct simplebus_softc sc_simplebus; | ||||
device_t sc_dev; | device_t sc_dev; | ||||
clk_ident_t sc_clk; | struct syscon *syscon; | ||||
}; | }; | ||||
static device_method_t am335x_pwmss_methods[] = { | static device_method_t am335x_pwmss_methods[] = { | ||||
DEVMETHOD(device_probe, am335x_pwmss_probe), | DEVMETHOD(device_probe, am335x_pwmss_probe), | ||||
DEVMETHOD(device_attach, am335x_pwmss_attach), | DEVMETHOD(device_attach, am335x_pwmss_attach), | ||||
DEVMETHOD(device_detach, am335x_pwmss_detach), | DEVMETHOD(device_detach, am335x_pwmss_detach), | ||||
DEVMETHOD_END | DEVMETHOD_END | ||||
Show All 14 Lines | am335x_pwmss_probe(device_t dev) | ||||
return (BUS_PROBE_DEFAULT); | return (BUS_PROBE_DEFAULT); | ||||
} | } | ||||
static int | static int | ||||
am335x_pwmss_attach(device_t dev) | am335x_pwmss_attach(device_t dev) | ||||
{ | { | ||||
struct am335x_pwmss_softc *sc; | struct am335x_pwmss_softc *sc; | ||||
uint32_t reg, id; | uint32_t reg, id; | ||||
phandle_t node; | uint64_t rev_address; | ||||
phandle_t node, opp_table; | |||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
sc->sc_dev = dev; | sc->sc_dev = dev; | ||||
sc->sc_clk = ti_hwmods_get_clock(dev); | /* FIXME: For now; Go and kidnap syscon from opp-table */ | ||||
if (sc->sc_clk == INVALID_CLK_IDENT) { | opp_table = OF_finddevice("/opp-table"); | ||||
device_printf(dev, "failed to get device id based on ti,hwmods\n"); | if (opp_table == -1) { | ||||
return (EINVAL); | device_printf(dev, "Cant find /opp-table\n"); | ||||
return (ENXIO); | |||||
} | } | ||||
if (!OF_hasprop(opp_table, "syscon")) { | |||||
device_printf(dev, "/opp-table doesnt have required syscon property\n"); | |||||
return (ENXIO); | |||||
} | |||||
if (syscon_get_by_ofw_property(dev, opp_table, "syscon", &sc->syscon) != 0) { | |||||
device_printf(dev, "Failed to get syscon\n"); | |||||
return (ENXIO); | |||||
} | |||||
ti_prcm_clk_enable(sc->sc_clk); | ti_sysc_clock_enable(device_get_parent(dev)); | ||||
ti_scm_reg_read_4(SCM_PWMSS_CTRL, ®); | |||||
switch (sc->sc_clk) { | rev_address = ti_sysc_get_rev_address(device_get_parent(dev)); | ||||
case PWMSS0_CLK: | switch (rev_address) { | ||||
case PWMSS_REV_0: | |||||
id = 0; | id = 0; | ||||
break; | break; | ||||
case PWMSS1_CLK: | case PWMSS_REV_1: | ||||
id = 1; | id = 1; | ||||
break; | break; | ||||
case PWMSS_REV_2: | |||||
case PWMSS2_CLK: | |||||
id = 2; | id = 2; | ||||
break; | break; | ||||
default: | |||||
device_printf(dev, "unknown pwmss clock id: %d\n", sc->sc_clk); | |||||
return (EINVAL); | |||||
} | } | ||||
reg = SYSCON_READ_4(sc->syscon, SCM_PWMSS_CTRL); | |||||
reg |= (1 << id); | reg |= (1 << id); | ||||
ti_scm_reg_write_4(SCM_PWMSS_CTRL, reg); | SYSCON_WRITE_4(sc->syscon, SCM_PWMSS_CTRL, reg); | ||||
node = ofw_bus_get_node(dev); | node = ofw_bus_get_node(dev); | ||||
if (node == -1) | if (node == -1) | ||||
return (ENXIO); | return (ENXIO); | ||||
simplebus_init(dev, node); | simplebus_init(dev, node); | ||||
Show All 18 Lines | am335x_pwmss_detach(device_t dev) | ||||
return (0); | return (0); | ||||
} | } | ||||
DEFINE_CLASS_1(am335x_pwmss, am335x_pwmss_driver, am335x_pwmss_methods, | DEFINE_CLASS_1(am335x_pwmss, am335x_pwmss_driver, am335x_pwmss_methods, | ||||
sizeof(struct am335x_pwmss_softc), simplebus_driver); | sizeof(struct am335x_pwmss_softc), simplebus_driver); | ||||
static devclass_t am335x_pwmss_devclass; | static devclass_t am335x_pwmss_devclass; | ||||
DRIVER_MODULE(am335x_pwmss, simplebus, am335x_pwmss_driver, am335x_pwmss_devclass, 0, 0); | DRIVER_MODULE(am335x_pwmss, simplebus, am335x_pwmss_driver, am335x_pwmss_devclass, 0, 0); | ||||
MODULE_VERSION(am335x_pwmss, 1); | MODULE_VERSION(am335x_pwmss, 1); | ||||
MODULE_DEPEND(am335x_pwmss, ti_sysc, 1, 1, 1); |