Changeset View
Changeset View
Standalone View
Standalone View
sys/arm/ti/ti_gpio.c
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
#include <machine/bus.h> | #include <machine/bus.h> | ||||
#include <machine/intr.h> | #include <machine/intr.h> | ||||
#include <machine/resource.h> | #include <machine/resource.h> | ||||
#include <arm/ti/ti_cpuid.h> | #include <arm/ti/ti_cpuid.h> | ||||
#include <arm/ti/ti_gpio.h> | #include <arm/ti/ti_gpio.h> | ||||
#include <arm/ti/ti_scm.h> | #include <arm/ti/ti_scm.h> | ||||
#include <arm/ti/ti_prcm.h> | #include <arm/ti/ti_sysc.h> | ||||
#include <arm/ti/ti_hwmods.h> | |||||
#include <dev/gpio/gpiobusvar.h> | #include <dev/gpio/gpiobusvar.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 "gpio_if.h" | #include "gpio_if.h" | ||||
#include "ti_gpio_if.h" | #include "ti_gpio_if.h" | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
#define OMAP4_INTR_PER_BANK 1 | #define OMAP4_INTR_PER_BANK 1 | ||||
#define OMAP4_GPIO_REV 0x50600801 | #define OMAP4_GPIO_REV 0x50600801 | ||||
#define AM335X_FIRST_GPIO_BANK 0 | #define AM335X_FIRST_GPIO_BANK 0 | ||||
#define AM335X_INTR_PER_BANK 2 | #define AM335X_INTR_PER_BANK 2 | ||||
#define AM335X_GPIO_REV 0x50600801 | #define AM335X_GPIO_REV 0x50600801 | ||||
#define PINS_PER_BANK 32 | #define PINS_PER_BANK 32 | ||||
#define TI_GPIO_MASK(p) (1U << ((p) % PINS_PER_BANK)) | #define TI_GPIO_MASK(p) (1U << ((p) % PINS_PER_BANK)) | ||||
#define OMAP4_GPIO1_REV 0x00000 | |||||
#define OMAP4_GPIO2_REV 0x55000 | |||||
#define OMAP4_GPIO3_REV 0x57000 | |||||
#define OMAP4_GPIO4_REV 0x59000 | |||||
#define OMAP4_GPIO5_REV 0x5b000 | |||||
#define OMAP4_GPIO6_REV 0x5d000 | |||||
#define AM335X_GPIO0_REV 0x07000 | |||||
#define AM335X_GPIO1_REV 0x4C000 | |||||
#define AM335X_GPIO2_REV 0xAC000 | |||||
#define AM335X_GPIO3_REV 0xAE000 | |||||
static int ti_gpio_intr(void *arg); | static int ti_gpio_intr(void *arg); | ||||
static int ti_gpio_detach(device_t); | static int ti_gpio_detach(device_t); | ||||
static int ti_gpio_pic_attach(struct ti_gpio_softc *sc); | static int ti_gpio_pic_attach(struct ti_gpio_softc *sc); | ||||
static int ti_gpio_pic_detach(struct ti_gpio_softc *sc); | static int ti_gpio_pic_detach(struct ti_gpio_softc *sc); | ||||
static u_int | static u_int | ||||
ti_first_gpio_bank(void) | ti_first_gpio_bank(void) | ||||
▲ Show 20 Lines • Show All 420 Lines • ▼ Show 20 Lines | ti_gpio_pin_toggle(device_t dev, uint32_t pin) | ||||
TI_GPIO_UNLOCK(sc); | TI_GPIO_UNLOCK(sc); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
ti_gpio_bank_init(device_t dev) | ti_gpio_bank_init(device_t dev) | ||||
{ | { | ||||
int pin; | int pin, err; | ||||
struct ti_gpio_softc *sc; | struct ti_gpio_softc *sc; | ||||
uint32_t flags, reg_oe, reg_set, rev; | uint32_t flags, reg_oe, reg_set, rev; | ||||
clk_ident_t clk; | uint64_t rev_address; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
/* Enable the interface and functional clocks for the module. */ | /* Enable the interface and functional clocks for the module. */ | ||||
clk = ti_hwmods_get_clock(dev); | rev_address = ti_sysc_get_rev_address(device_get_parent(dev)); | ||||
if (clk == INVALID_CLK_IDENT) { | /* AM335x | ||||
device_printf(dev, "failed to get device id based on ti,hwmods\n"); | * sc->sc_bank used in am335x/am335x_gpio.c and omap4/omap4_gpio.c */ | ||||
switch(ti_chip()) { | |||||
#ifdef SOC_OMAP4 | |||||
case CHIP_OMAP_4: | |||||
switch (rev_address) { | |||||
case OMAP4_GPIO1_REV: | |||||
sc->sc_bank = 0; | |||||
break; | |||||
case OMAP4_GPIO2_REV: | |||||
sc->sc_bank = 1; | |||||
break; | |||||
case OMAP4_GPIO3_REV: | |||||
sc->sc_bank = 2; | |||||
break; | |||||
case OMAP4_GPIO4_REV: | |||||
sc->sc_bank = 3; | |||||
break; | |||||
case OMAP4_GPIO5_REV: | |||||
sc->sc_bank = 4; | |||||
break; | |||||
case OMAP4_GPIO6_REV: | |||||
sc->sc_bank = 5; | |||||
break; | |||||
} | |||||
#endif | |||||
#ifdef SOC_TI_AM335X | |||||
case CHIP_AM335X: | |||||
switch (rev_address) { | |||||
case AM335X_GPIO0_REV: | |||||
sc->sc_bank = 0; | |||||
break; | |||||
case AM335X_GPIO1_REV: | |||||
sc->sc_bank = 1; | |||||
break; | |||||
case AM335X_GPIO2_REV: | |||||
sc->sc_bank = 2; | |||||
break; | |||||
case AM335X_GPIO3_REV: | |||||
sc->sc_bank = 3; | |||||
break; | |||||
} | |||||
#endif | |||||
} | |||||
err = ti_sysc_clock_enable(device_get_parent(dev)); | |||||
if (err) { | |||||
device_printf(dev, "Failed to enable clock\n"); | |||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
sc->sc_bank = clk - GPIO1_CLK + ti_first_gpio_bank(); | |||||
ti_prcm_clk_enable(clk); | |||||
/* | /* | ||||
* Read the revision number of the module. TI don't publish the | * Read the revision number of the module. TI don't publish the | ||||
* actual revision numbers, so instead the values have been | * actual revision numbers, so instead the values have been | ||||
* determined by experimentation. | * determined by experimentation. | ||||
*/ | */ | ||||
rev = ti_gpio_read_4(sc, TI_GPIO_REVISION); | rev = ti_gpio_read_4(sc, | ||||
ti_sysc_get_rev_address_offset_host(device_get_parent(dev))); | |||||
/* Check the revision. */ | /* Check the revision. */ | ||||
if (rev != ti_gpio_rev()) { | if (rev != ti_gpio_rev()) { | ||||
device_printf(dev, "Warning: could not determine the revision " | device_printf(dev, "Warning: could not determine the revision " | ||||
"of GPIO module (revision:0x%08x)\n", rev); | "of GPIO module (revision:0x%08x)\n", rev); | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 501 Lines • Show Last 20 Lines |