Commit 2e373952 authored by Phil Sutter's avatar Phil Sutter Committed by Ralf Baechle

MIPS: RB532: Provide functions for gpio configuration

As gpiolib doesn't support pin multiplexing, it provides no way to
access the GPIOFUNC register. Also there is no support for setting
interrupt status and level. These functions provide access to them and
are needed by the CompactFlash driver.
Signed-off-by: default avatarPhil Sutter <n0-1@freewrt.org>
Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent f43909df
...@@ -84,5 +84,7 @@ extern void set_434_reg(unsigned reg_offs, unsigned bit, unsigned len, unsigned ...@@ -84,5 +84,7 @@ extern void set_434_reg(unsigned reg_offs, unsigned bit, unsigned len, unsigned
extern unsigned get_434_reg(unsigned reg_offs); extern unsigned get_434_reg(unsigned reg_offs);
extern void set_latch_u5(unsigned char or_mask, unsigned char nand_mask); extern void set_latch_u5(unsigned char or_mask, unsigned char nand_mask);
extern unsigned char get_latch_u5(void); extern unsigned char get_latch_u5(void);
extern void rb532_gpio_set_ilevel(int bit, unsigned gpio);
extern void rb532_gpio_set_istat(int bit, unsigned gpio);
#endif /* _RC32434_GPIO_H_ */ #endif /* _RC32434_GPIO_H_ */
...@@ -39,10 +39,6 @@ ...@@ -39,10 +39,6 @@
struct rb532_gpio_chip { struct rb532_gpio_chip {
struct gpio_chip chip; struct gpio_chip chip;
void __iomem *regbase; void __iomem *regbase;
void (*set_int_level)(struct gpio_chip *chip, unsigned offset, int value);
int (*get_int_level)(struct gpio_chip *chip, unsigned offset);
void (*set_int_status)(struct gpio_chip *chip, unsigned offset, int value);
int (*get_int_status)(struct gpio_chip *chip, unsigned offset);
}; };
struct mpmc_device dev3; struct mpmc_device dev3;
...@@ -111,162 +107,95 @@ unsigned char get_latch_u5(void) ...@@ -111,162 +107,95 @@ unsigned char get_latch_u5(void)
} }
EXPORT_SYMBOL(get_latch_u5); EXPORT_SYMBOL(get_latch_u5);
/* /* rb532_set_bit - sanely set a bit
* Return GPIO level */ *
static int rb532_gpio_get(struct gpio_chip *chip, unsigned offset) * bitval: new value for the bit
{ * offset: bit index in the 4 byte address range
u32 mask = 1 << offset; * ioaddr: 4 byte aligned address being altered
struct rb532_gpio_chip *gpch;
gpch = container_of(chip, struct rb532_gpio_chip, chip);
return readl(gpch->regbase + GPIOD) & mask;
}
/*
* Set output GPIO level
*/ */
static void rb532_gpio_set(struct gpio_chip *chip, static inline void rb532_set_bit(unsigned bitval,
unsigned offset, int value) unsigned offset, void __iomem *ioaddr)
{ {
unsigned long flags; unsigned long flags;
u32 mask = 1 << offset; u32 val;
u32 tmp;
struct rb532_gpio_chip *gpch;
void __iomem *gpvr;
gpch = container_of(chip, struct rb532_gpio_chip, chip); bitval = !!bitval; /* map parameter to {0,1} */
gpvr = gpch->regbase + GPIOD;
local_irq_save(flags); local_irq_save(flags);
tmp = readl(gpvr);
if (value) val = readl(ioaddr);
tmp |= mask; val &= ~( ~bitval << offset ); /* unset bit if bitval == 0 */
else val |= ( bitval << offset ); /* set bit if bitval == 1 */
tmp &= ~mask; writel(val, ioaddr);
writel(tmp, gpvr);
local_irq_restore(flags); local_irq_restore(flags);
} }
/* /* rb532_get_bit - read a bit
* Set GPIO direction to input *
* returns the boolean state of the bit, which may be > 1
*/ */
static int rb532_gpio_direction_input(struct gpio_chip *chip, unsigned offset) static inline int rb532_get_bit(unsigned offset, void __iomem *ioaddr)
{ {
unsigned long flags; return (readl(ioaddr) & (1 << offset));
u32 mask = 1 << offset;
u32 value;
struct rb532_gpio_chip *gpch;
void __iomem *gpdr;
gpch = container_of(chip, struct rb532_gpio_chip, chip);
gpdr = gpch->regbase + GPIOCFG;
local_irq_save(flags);
value = readl(gpdr);
value &= ~mask;
writel(value, gpdr);
local_irq_restore(flags);
return 0;
} }
/* /*
* Set GPIO direction to output * Return GPIO level */
*/ static int rb532_gpio_get(struct gpio_chip *chip, unsigned offset)
static int rb532_gpio_direction_output(struct gpio_chip *chip,
unsigned offset, int value)
{ {
unsigned long flags;
u32 mask = 1 << offset;
u32 tmp;
struct rb532_gpio_chip *gpch; struct rb532_gpio_chip *gpch;
void __iomem *gpdr;
gpch = container_of(chip, struct rb532_gpio_chip, chip); gpch = container_of(chip, struct rb532_gpio_chip, chip);
writel(mask, gpch->regbase + GPIOD); return rb532_get_bit(offset, gpch->regbase + GPIOD);
gpdr = gpch->regbase + GPIOCFG;
local_irq_save(flags);
tmp = readl(gpdr);
tmp |= mask;
writel(tmp, gpdr);
local_irq_restore(flags);
return 0;
} }
/* /*
* Set the GPIO interrupt level * Set output GPIO level
*/ */
static void rb532_gpio_set_int_level(struct gpio_chip *chip, static void rb532_gpio_set(struct gpio_chip *chip,
unsigned offset, int value) unsigned offset, int value)
{ {
unsigned long flags;
u32 mask = 1 << offset;
u32 tmp;
struct rb532_gpio_chip *gpch; struct rb532_gpio_chip *gpch;
void __iomem *gpil;
gpch = container_of(chip, struct rb532_gpio_chip, chip); gpch = container_of(chip, struct rb532_gpio_chip, chip);
gpil = gpch->regbase + GPIOILEVEL; rb532_set_bit(value, offset, gpch->regbase + GPIOD);
local_irq_save(flags);
tmp = readl(gpil);
if (value)
tmp |= mask;
else
tmp &= ~mask;
writel(tmp, gpil);
local_irq_restore(flags);
} }
/* /*
* Get the GPIO interrupt level * Set GPIO direction to input
*/ */
static int rb532_gpio_get_int_level(struct gpio_chip *chip, unsigned offset) static int rb532_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
{ {
u32 mask = 1 << offset;
struct rb532_gpio_chip *gpch; struct rb532_gpio_chip *gpch;
gpch = container_of(chip, struct rb532_gpio_chip, chip); gpch = container_of(chip, struct rb532_gpio_chip, chip);
return readl(gpch->regbase + GPIOILEVEL) & mask;
if (rb532_get_bit(offset, gpch->regbase + GPIOFUNC))
return 1; /* alternate function, GPIOCFG is ignored */
rb532_set_bit(0, offset, gpch->regbase + GPIOCFG);
return 0;
} }
/* /*
* Set the GPIO interrupt status * Set GPIO direction to output
*/ */
static void rb532_gpio_set_int_status(struct gpio_chip *chip, static int rb532_gpio_direction_output(struct gpio_chip *chip,
unsigned offset, int value) unsigned offset, int value)
{ {
unsigned long flags;
u32 mask = 1 << offset;
u32 tmp;
struct rb532_gpio_chip *gpch; struct rb532_gpio_chip *gpch;
void __iomem *gpis;
gpch = container_of(chip, struct rb532_gpio_chip, chip); gpch = container_of(chip, struct rb532_gpio_chip, chip);
gpis = gpch->regbase + GPIOISTAT;
local_irq_save(flags); if (rb532_get_bit(offset, gpch->regbase + GPIOFUNC))
tmp = readl(gpis); return 1; /* alternate function, GPIOCFG is ignored */
if (value)
tmp |= mask;
else
tmp &= ~mask;
writel(tmp, gpis);
local_irq_restore(flags);
}
/* /* set the initial output value */
* Get the GPIO interrupt status rb532_set_bit(value, offset, gpch->regbase + GPIOD);
*/
static int rb532_gpio_get_int_status(struct gpio_chip *chip, unsigned offset)
{
u32 mask = 1 << offset;
struct rb532_gpio_chip *gpch;
gpch = container_of(chip, struct rb532_gpio_chip, chip); rb532_set_bit(1, offset, gpch->regbase + GPIOCFG);
return readl(gpch->regbase + GPIOISTAT) & mask; return 0;
} }
static struct rb532_gpio_chip rb532_gpio_chip[] = { static struct rb532_gpio_chip rb532_gpio_chip[] = {
...@@ -280,13 +209,35 @@ static struct rb532_gpio_chip rb532_gpio_chip[] = { ...@@ -280,13 +209,35 @@ static struct rb532_gpio_chip rb532_gpio_chip[] = {
.base = 0, .base = 0,
.ngpio = 32, .ngpio = 32,
}, },
.get_int_level = rb532_gpio_get_int_level,
.set_int_level = rb532_gpio_set_int_level,
.get_int_status = rb532_gpio_get_int_status,
.set_int_status = rb532_gpio_set_int_status,
}, },
}; };
/*
* Set GPIO interrupt level
*/
void rb532_gpio_set_ilevel(int bit, unsigned gpio)
{
rb532_set_bit(bit, gpio, rb532_gpio_chip->regbase + GPIOILEVEL);
}
EXPORT_SYMBOL(rb532_gpio_set_ilevel);
/*
* Set GPIO interrupt status
*/
void rb532_gpio_set_istat(int bit, unsigned gpio)
{
rb532_set_bit(bit, gpio, rb532_gpio_chip->regbase + GPIOISTAT);
}
EXPORT_SYMBOL(rb532_gpio_set_istat);
/*
* Configure GPIO alternate function
*/
static void rb532_gpio_set_func(int bit, unsigned gpio)
{
rb532_set_bit(bit, gpio, rb532_gpio_chip->regbase + GPIOFUNC);
}
int __init rb532_gpio_init(void) int __init rb532_gpio_init(void)
{ {
struct resource *r; struct resource *r;
...@@ -310,9 +261,11 @@ int __init rb532_gpio_init(void) ...@@ -310,9 +261,11 @@ int __init rb532_gpio_init(void)
return -ENXIO; return -ENXIO;
} }
/* Set the interrupt status and level for the CF pin */ /* configure CF_GPIO_NUM as CFRDY IRQ source */
rb532_gpio_set_int_level(&rb532_gpio_chip->chip, CF_GPIO_NUM, 1); rb532_gpio_set_func(0, CF_GPIO_NUM);
rb532_gpio_set_int_status(&rb532_gpio_chip->chip, CF_GPIO_NUM, 0); rb532_gpio_direction_input(&rb532_gpio_chip->chip, CF_GPIO_NUM);
rb532_gpio_set_ilevel(1, CF_GPIO_NUM);
rb532_gpio_set_istat(0, CF_GPIO_NUM);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment