aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/rb532/gpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mips/rb532/gpio.c')
-rw-r--r--arch/mips/rb532/gpio.c90
1 files changed, 9 insertions, 81 deletions
diff --git a/arch/mips/rb532/gpio.c b/arch/mips/rb532/gpio.c
index 0e84c8ab6a39..37de05d595e7 100644
--- a/arch/mips/rb532/gpio.c
+++ b/arch/mips/rb532/gpio.c
@@ -41,8 +41,6 @@ struct rb532_gpio_chip {
41 void __iomem *regbase; 41 void __iomem *regbase;
42}; 42};
43 43
44struct mpmc_device dev3;
45
46static struct resource rb532_gpio_reg0_res[] = { 44static struct resource rb532_gpio_reg0_res[] = {
47 { 45 {
48 .name = "gpio_reg0", 46 .name = "gpio_reg0",
@@ -52,61 +50,6 @@ static struct resource rb532_gpio_reg0_res[] = {
52 } 50 }
53}; 51};
54 52
55static struct resource rb532_dev3_ctl_res[] = {
56 {
57 .name = "dev3_ctl",
58 .start = REGBASE + DEV3BASE,
59 .end = REGBASE + DEV3BASE + sizeof(struct dev_reg) - 1,
60 .flags = IORESOURCE_MEM,
61 }
62};
63
64void set_434_reg(unsigned reg_offs, unsigned bit, unsigned len, unsigned val)
65{
66 unsigned long flags;
67 unsigned data;
68 unsigned i = 0;
69
70 spin_lock_irqsave(&dev3.lock, flags);
71
72 data = readl(IDT434_REG_BASE + reg_offs);
73 for (i = 0; i != len; ++i) {
74 if (val & (1 << i))
75 data |= (1 << (i + bit));
76 else
77 data &= ~(1 << (i + bit));
78 }
79 writel(data, (IDT434_REG_BASE + reg_offs));
80
81 spin_unlock_irqrestore(&dev3.lock, flags);
82}
83EXPORT_SYMBOL(set_434_reg);
84
85unsigned get_434_reg(unsigned reg_offs)
86{
87 return readl(IDT434_REG_BASE + reg_offs);
88}
89EXPORT_SYMBOL(get_434_reg);
90
91void set_latch_u5(unsigned char or_mask, unsigned char nand_mask)
92{
93 unsigned long flags;
94
95 spin_lock_irqsave(&dev3.lock, flags);
96
97 dev3.state = (dev3.state | or_mask) & ~nand_mask;
98 writel(dev3.state, &dev3.base);
99
100 spin_unlock_irqrestore(&dev3.lock, flags);
101}
102EXPORT_SYMBOL(set_latch_u5);
103
104unsigned char get_latch_u5(void)
105{
106 return dev3.state;
107}
108EXPORT_SYMBOL(get_latch_u5);
109
110/* rb532_set_bit - sanely set a bit 53/* rb532_set_bit - sanely set a bit
111 * 54 *
112 * bitval: new value for the bit 55 * bitval: new value for the bit
@@ -119,13 +62,11 @@ static inline void rb532_set_bit(unsigned bitval,
119 unsigned long flags; 62 unsigned long flags;
120 u32 val; 63 u32 val;
121 64
122 bitval = !!bitval; /* map parameter to {0,1} */
123
124 local_irq_save(flags); 65 local_irq_save(flags);
125 66
126 val = readl(ioaddr); 67 val = readl(ioaddr);
127 val &= ~( ~bitval << offset ); /* unset bit if bitval == 0 */ 68 val &= ~(!bitval << offset); /* unset bit if bitval == 0 */
128 val |= ( bitval << offset ); /* set bit if bitval == 1 */ 69 val |= (!!bitval << offset); /* set bit if bitval == 1 */
129 writel(val, ioaddr); 70 writel(val, ioaddr);
130 71
131 local_irq_restore(flags); 72 local_irq_restore(flags);
@@ -171,8 +112,8 @@ static int rb532_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
171 112
172 gpch = container_of(chip, struct rb532_gpio_chip, chip); 113 gpch = container_of(chip, struct rb532_gpio_chip, chip);
173 114
174 if (rb532_get_bit(offset, gpch->regbase + GPIOFUNC)) 115 /* disable alternate function in case it's set */
175 return 1; /* alternate function, GPIOCFG is ignored */ 116 rb532_set_bit(0, offset, gpch->regbase + GPIOFUNC);
176 117
177 rb532_set_bit(0, offset, gpch->regbase + GPIOCFG); 118 rb532_set_bit(0, offset, gpch->regbase + GPIOCFG);
178 return 0; 119 return 0;
@@ -188,8 +129,8 @@ static int rb532_gpio_direction_output(struct gpio_chip *chip,
188 129
189 gpch = container_of(chip, struct rb532_gpio_chip, chip); 130 gpch = container_of(chip, struct rb532_gpio_chip, chip);
190 131
191 if (rb532_get_bit(offset, gpch->regbase + GPIOFUNC)) 132 /* disable alternate function in case it's set */
192 return 1; /* alternate function, GPIOCFG is ignored */ 133 rb532_set_bit(0, offset, gpch->regbase + GPIOFUNC);
193 134
194 /* set the initial output value */ 135 /* set the initial output value */
195 rb532_set_bit(value, offset, gpch->regbase + GPIOD); 136 rb532_set_bit(value, offset, gpch->regbase + GPIOD);
@@ -233,10 +174,11 @@ EXPORT_SYMBOL(rb532_gpio_set_istat);
233/* 174/*
234 * Configure GPIO alternate function 175 * Configure GPIO alternate function
235 */ 176 */
236static void rb532_gpio_set_func(int bit, unsigned gpio) 177void rb532_gpio_set_func(unsigned gpio)
237{ 178{
238 rb532_set_bit(bit, gpio, rb532_gpio_chip->regbase + GPIOFUNC); 179 rb532_set_bit(1, gpio, rb532_gpio_chip->regbase + GPIOFUNC);
239} 180}
181EXPORT_SYMBOL(rb532_gpio_set_func);
240 182
241int __init rb532_gpio_init(void) 183int __init rb532_gpio_init(void)
242{ 184{
@@ -253,20 +195,6 @@ int __init rb532_gpio_init(void)
253 /* Register our GPIO chip */ 195 /* Register our GPIO chip */
254 gpiochip_add(&rb532_gpio_chip->chip); 196 gpiochip_add(&rb532_gpio_chip->chip);
255 197
256 r = rb532_dev3_ctl_res;
257 dev3.base = ioremap_nocache(r->start, r->end - r->start);
258
259 if (!dev3.base) {
260 printk(KERN_ERR "rb532: cannot remap device controller 3\n");
261 return -ENXIO;
262 }
263
264 /* configure CF_GPIO_NUM as CFRDY IRQ source */
265 rb532_gpio_set_func(0, CF_GPIO_NUM);
266 rb532_gpio_direction_input(&rb532_gpio_chip->chip, CF_GPIO_NUM);
267 rb532_gpio_set_ilevel(1, CF_GPIO_NUM);
268 rb532_gpio_set_istat(0, CF_GPIO_NUM);
269
270 return 0; 198 return 0;
271} 199}
272arch_initcall(rb532_gpio_init); 200arch_initcall(rb532_gpio_init);