X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/344d167a94913324cabd9aa3f3ff9407e00b9901..8b65736401eb7cc9d7a64067f3a5487e395aeb38:/target/linux/ramips/files/arch/mips/ralink/common/gpio.c diff --git a/target/linux/ramips/files/arch/mips/ralink/common/gpio.c b/target/linux/ramips/files/arch/mips/ralink/common/gpio.c index f882b925a..e350fc173 100644 --- a/target/linux/ramips/files/arch/mips/ralink/common/gpio.c +++ b/target/linux/ramips/files/arch/mips/ralink/common/gpio.c @@ -10,7 +10,7 @@ #include #include - +#include #include #include @@ -52,6 +52,7 @@ enum ramips_pio_reg { RAMIPS_GPIO_REG_INT, /* Interrupt status */ RAMIPS_GPIO_REG_EDGE, RAMIPS_GPIO_REG_RENA, + RAMIPS_GPIO_REG_FENA, RAMIPS_GPIO_REG_DATA, RAMIPS_GPIO_REG_DIR, /* Direction, 0:in, 1: out */ RAMIPS_GPIO_REG_POL, /* Polarity, 0: normal, 1: invert */ @@ -63,6 +64,7 @@ enum ramips_pio_reg { struct ramips_gpio_chip { struct gpio_chip chip; + spinlock_t lock; u8 regs[RAMIPS_GPIO_REG_MAX]; }; @@ -89,11 +91,14 @@ static inline u32 ramips_gpio_rr(struct ramips_gpio_chip *rg, u8 reg) static int ramips_gpio_direction_input(struct gpio_chip *chip, unsigned offset) { struct ramips_gpio_chip *rg = to_ramips_gpio(chip); + unsigned long flags; u32 t; + spin_lock_irqsave(&rg->lock, flags); t = ramips_gpio_rr(rg, RAMIPS_GPIO_REG_DIR); t &= ~(1 << offset); ramips_gpio_wr(rg, RAMIPS_GPIO_REG_DIR, t); + spin_unlock_irqrestore(&rg->lock, flags); return 0; } @@ -102,15 +107,19 @@ static int ramips_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value) { struct ramips_gpio_chip *rg = to_ramips_gpio(chip); + unsigned long flags; u32 reg; u32 t; reg = (value) ? RAMIPS_GPIO_REG_SET : RAMIPS_GPIO_REG_RESET; + + spin_lock_irqsave(&rg->lock, flags); ramips_gpio_wr(rg, reg, 1 << offset); t = ramips_gpio_rr(rg, RAMIPS_GPIO_REG_DIR); t |= 1 << offset; ramips_gpio_wr(rg, RAMIPS_GPIO_REG_DIR, t); + spin_unlock_irqrestore(&rg->lock, flags); return 0; } @@ -130,7 +139,7 @@ static int ramips_gpio_get(struct gpio_chip *chip, unsigned offset) u32 t; t = ramips_gpio_rr(rg, RAMIPS_GPIO_REG_DATA); - return (t & (1 << offset)); + return !!(t & (1 << offset)); } static struct ramips_gpio_chip ramips_gpio_chip0 = { @@ -147,6 +156,7 @@ static struct ramips_gpio_chip ramips_gpio_chip0 = { [RAMIPS_GPIO_REG_INT] = GPIO0_REG_INT, [RAMIPS_GPIO_REG_EDGE] = GPIO0_REG_EDGE, [RAMIPS_GPIO_REG_RENA] = GPIO0_REG_RENA, + [RAMIPS_GPIO_REG_FENA] = GPIO0_REG_FENA, [RAMIPS_GPIO_REG_DATA] = GPIO0_REG_DATA, [RAMIPS_GPIO_REG_DIR] = GPIO0_REG_DIR, [RAMIPS_GPIO_REG_POL] = GPIO0_REG_POL, @@ -170,6 +180,7 @@ static struct ramips_gpio_chip ramips_gpio_chip1 = { [RAMIPS_GPIO_REG_INT] = GPIO1_REG_INT, [RAMIPS_GPIO_REG_EDGE] = GPIO1_REG_EDGE, [RAMIPS_GPIO_REG_RENA] = GPIO1_REG_RENA, + [RAMIPS_GPIO_REG_FENA] = GPIO1_REG_FENA, [RAMIPS_GPIO_REG_DATA] = GPIO1_REG_DATA, [RAMIPS_GPIO_REG_DIR] = GPIO1_REG_DIR, [RAMIPS_GPIO_REG_POL] = GPIO1_REG_POL, @@ -193,6 +204,7 @@ static struct ramips_gpio_chip ramips_gpio_chip2 = { [RAMIPS_GPIO_REG_INT] = GPIO2_REG_INT, [RAMIPS_GPIO_REG_EDGE] = GPIO2_REG_EDGE, [RAMIPS_GPIO_REG_RENA] = GPIO2_REG_RENA, + [RAMIPS_GPIO_REG_FENA] = GPIO2_REG_FENA, [RAMIPS_GPIO_REG_DATA] = GPIO2_REG_DATA, [RAMIPS_GPIO_REG_DIR] = GPIO2_REG_DIR, [RAMIPS_GPIO_REG_POL] = GPIO2_REG_POL, @@ -204,6 +216,8 @@ static struct ramips_gpio_chip ramips_gpio_chip2 = { static __init void ramips_gpio_chip_add(struct ramips_gpio_chip *rg) { + spin_lock_init(&rg->lock); + /* set polarity to low for all lines */ ramips_gpio_wr(rg, RAMIPS_GPIO_REG_POL, 0); @@ -220,5 +234,3 @@ __init int ramips_gpio_init(void) return 0; } - -arch_initcall(ramips_gpio_init);