Skip to content

Commit 47c969e

Browse files
ffainelliralfbaechle
authored andcommitted
MIPS: Au1000: convert to using gpiolib
This patch converts the GPIO board code to use gpiolib. Signed-off-by: Florian Fainelli <florian@openwrt.org> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 12e22e8 commit 47c969e

3 files changed

Lines changed: 146 additions & 128 deletions

File tree

‎arch/mips/alchemy/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,4 @@ config SOC_AU1X00
135135
select SYS_SUPPORTS_32BIT_KERNEL
136136
select SYS_SUPPORTS_APM_EMULATION
137137
select GENERIC_HARDIRQS_NO__DO_IRQ
138+
select ARCH_REQUIRE_GPIOLIB

‎arch/mips/alchemy/common/gpio.c‎

Lines changed: 128 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2007, OpenWrt.org, Florian Fainelli <florian@openwrt.org>
2+
* Copyright (C) 2007-2009, OpenWrt.org, Florian Fainelli <florian@openwrt.org>
33
* Architecture specific GPIO support
44
*
55
* This program is free software; you can redistribute it and/or modify it
@@ -27,122 +27,175 @@
2727
* others have a second one : GPIO2
2828
*/
2929

30+
#include <linux/kernel.h>
3031
#include <linux/module.h>
32+
#include <linux/types.h>
33+
#include <linux/platform_device.h>
34+
#include <linux/gpio.h>
3135

3236
#include <asm/mach-au1x00/au1000.h>
3337
#include <asm/gpio.h>
3438

35-
#define gpio1 sys
36-
#if !defined(CONFIG_SOC_AU1000)
37-
38-
static struct au1x00_gpio2 *const gpio2 = (struct au1x00_gpio2 *) GPIO2_BASE;
39-
#define GPIO2_OUTPUT_ENABLE_MASK 0x00010000
39+
struct au1000_gpio_chip {
40+
struct gpio_chip chip;
41+
void __iomem *regbase;
42+
};
4043

41-
static int au1xxx_gpio2_read(unsigned gpio)
44+
#if !defined(CONFIG_SOC_AU1000)
45+
static int au1000_gpio2_get(struct gpio_chip *chip, unsigned offset)
4246
{
43-
gpio -= AU1XXX_GPIO_BASE;
44-
return ((gpio2->pinstate >> gpio) & 0x01);
47+
u32 mask = 1 << offset;
48+
struct au1000_gpio_chip *gpch;
49+
50+
gpch = container_of(chip, struct au1000_gpio_chip, chip);
51+
return readl(gpch->regbase + AU1000_GPIO2_ST) & mask;
4552
}
4653

47-
static void au1xxx_gpio2_write(unsigned gpio, int value)
54+
static void au1000_gpio2_set(struct gpio_chip *chip,
55+
unsigned offset, int value)
4856
{
49-
gpio -= AU1XXX_GPIO_BASE;
57+
u32 mask = ((GPIO2_OUT_EN_MASK << offset) | (!!value << offset));
58+
struct au1000_gpio_chip *gpch;
59+
unsigned long flags;
60+
61+
gpch = container_of(chip, struct au1000_gpio_chip, chip);
5062

51-
gpio2->output = (GPIO2_OUTPUT_ENABLE_MASK << gpio) | ((!!value) << gpio);
63+
local_irq_save(flags);
64+
writel(mask, gpch->regbase + AU1000_GPIO2_OUT);
65+
local_irq_restore(flags);
5266
}
5367

54-
static int au1xxx_gpio2_direction_input(unsigned gpio)
68+
static int au1000_gpio2_direction_input(struct gpio_chip *chip, unsigned offset)
5569
{
56-
gpio -= AU1XXX_GPIO_BASE;
57-
gpio2->dir &= ~(0x01 << gpio);
70+
u32 mask = 1 << offset;
71+
u32 tmp;
72+
struct au1000_gpio_chip *gpch;
73+
unsigned long flags;
74+
75+
gpch = container_of(chip, struct au1000_gpio_chip, chip);
76+
77+
local_irq_save(flags);
78+
tmp = readl(gpch->regbase + AU1000_GPIO2_DIR);
79+
tmp &= ~mask;
80+
writel(tmp, gpch->regbase + AU1000_GPIO2_DIR);
81+
local_irq_restore(flags);
82+
5883
return 0;
5984
}
6085

61-
static int au1xxx_gpio2_direction_output(unsigned gpio, int value)
86+
static int au1000_gpio2_direction_output(struct gpio_chip *chip,
87+
unsigned offset, int value)
6288
{
63-
gpio -= AU1XXX_GPIO_BASE;
64-
gpio2->dir |= 0x01 << gpio;
65-
gpio2->output = (GPIO2_OUTPUT_ENABLE_MASK << gpio) | ((!!value) << gpio);
89+
u32 mask = 1 << offset;
90+
u32 out_mask = ((GPIO2_OUT_EN_MASK << offset) | (!!value << offset));
91+
u32 tmp;
92+
struct au1000_gpio_chip *gpch;
93+
unsigned long flags;
94+
95+
gpch = container_of(chip, struct au1000_gpio_chip, chip);
96+
97+
local_irq_save(flags);
98+
tmp = readl(gpch->regbase + AU1000_GPIO2_DIR);
99+
tmp |= mask;
100+
writel(tmp, gpch->regbase + AU1000_GPIO2_DIR);
101+
writel(out_mask, gpch->regbase + AU1000_GPIO2_OUT);
102+
local_irq_restore(flags);
103+
66104
return 0;
67105
}
68-
69106
#endif /* !defined(CONFIG_SOC_AU1000) */
70107

71-
static int au1xxx_gpio1_read(unsigned gpio)
108+
static int au1000_gpio1_get(struct gpio_chip *chip, unsigned offset)
72109
{
73-
return (gpio1->pinstaterd >> gpio) & 0x01;
110+
u32 mask = 1 << offset;
111+
struct au1000_gpio_chip *gpch;
112+
113+
gpch = container_of(chip, struct au1000_gpio_chip, chip);
114+
return readl(gpch->regbase + AU1000_GPIO1_ST) & mask;
74115
}
75116

76-
static void au1xxx_gpio1_write(unsigned gpio, int value)
117+
static void au1000_gpio1_set(struct gpio_chip *chip,
118+
unsigned offset, int value)
77119
{
120+
u32 mask = 1 << offset;
121+
u32 reg_offset;
122+
struct au1000_gpio_chip *gpch;
123+
unsigned long flags;
124+
125+
gpch = container_of(chip, struct au1000_gpio_chip, chip);
126+
78127
if (value)
79-
gpio1->outputset = (0x01 << gpio);
128+
reg_offset = AU1000_GPIO1_OUT;
80129
else
81-
/* Output a zero */
82-
gpio1->outputclr = (0x01 << gpio);
83-
}
130+
reg_offset = AU1000_GPIO1_CLR;
84131

85-
static int au1xxx_gpio1_direction_input(unsigned gpio)
86-
{
87-
gpio1->pininputen = (0x01 << gpio);
88-
return 0;
132+
local_irq_save(flags);
133+
writel(mask, gpch->regbase + reg_offset);
134+
local_irq_restore(flags);
89135
}
90136

91-
static int au1xxx_gpio1_direction_output(unsigned gpio, int value)
137+
static int au1000_gpio1_direction_input(struct gpio_chip *chip, unsigned offset)
92138
{
93-
gpio1->trioutclr = (0x01 & gpio);
94-
au1xxx_gpio1_write(gpio, value);
139+
u32 mask = 1 << offset;
140+
struct au1000_gpio_chip *gpch;
141+
142+
gpch = container_of(chip, struct au1000_gpio_chip, chip);
143+
writel(mask, gpch->regbase + AU1000_GPIO1_ST);
144+
95145
return 0;
96146
}
97147

98-
int au1xxx_gpio_get_value(unsigned gpio)
148+
static int au1000_gpio1_direction_output(struct gpio_chip *chip,
149+
unsigned offset, int value)
99150
{
100-
if (gpio >= AU1XXX_GPIO_BASE)
101-
#if defined(CONFIG_SOC_AU1000)
102-
return 0;
103-
#else
104-
return au1xxx_gpio2_read(gpio);
105-
#endif
106-
else
107-
return au1xxx_gpio1_read(gpio);
108-
}
109-
EXPORT_SYMBOL(au1xxx_gpio_get_value);
151+
u32 mask = 1 << offset;
152+
struct au1000_gpio_chip *gpch;
110153

111-
void au1xxx_gpio_set_value(unsigned gpio, int value)
112-
{
113-
if (gpio >= AU1XXX_GPIO_BASE)
114-
#if defined(CONFIG_SOC_AU1000)
115-
;
116-
#else
117-
au1xxx_gpio2_write(gpio, value);
118-
#endif
119-
else
120-
au1xxx_gpio1_write(gpio, value);
121-
}
122-
EXPORT_SYMBOL(au1xxx_gpio_set_value);
154+
gpch = container_of(chip, struct au1000_gpio_chip, chip);
123155

124-
int au1xxx_gpio_direction_input(unsigned gpio)
125-
{
126-
if (gpio >= AU1XXX_GPIO_BASE)
127-
#if defined(CONFIG_SOC_AU1000)
128-
return -ENODEV;
129-
#else
130-
return au1xxx_gpio2_direction_input(gpio);
131-
#endif
156+
writel(mask, gpch->regbase + AU1000_GPIO1_TRI_OUT);
157+
au1000_gpio1_set(chip, offset, value);
132158

133-
return au1xxx_gpio1_direction_input(gpio);
159+
return 0;
134160
}
135-
EXPORT_SYMBOL(au1xxx_gpio_direction_input);
136161

137-
int au1xxx_gpio_direction_output(unsigned gpio, int value)
162+
struct au1000_gpio_chip au1000_gpio_chip[] = {
163+
[0] = {
164+
.regbase = (void __iomem *)SYS_BASE,
165+
.chip = {
166+
.label = "au1000-gpio1",
167+
.direction_input = au1000_gpio1_direction_input,
168+
.direction_output = au1000_gpio1_direction_output,
169+
.get = au1000_gpio1_get,
170+
.set = au1000_gpio1_set,
171+
.base = 0,
172+
.ngpio = 32,
173+
},
174+
},
175+
#if !defined(CONFIG_SOC_AU1000)
176+
[1] = {
177+
.regbase = (void __iomem *)GPIO2_BASE,
178+
.chip = {
179+
.label = "au1000-gpio2",
180+
.direction_input = au1000_gpio2_direction_input,
181+
.direction_output = au1000_gpio2_direction_output,
182+
.get = au1000_gpio2_get,
183+
.set = au1000_gpio2_set,
184+
.base = AU1XXX_GPIO_BASE,
185+
.ngpio = 32,
186+
},
187+
},
188+
#endif
189+
};
190+
191+
static int __init au1000_gpio_init(void)
138192
{
139-
if (gpio >= AU1XXX_GPIO_BASE)
140-
#if defined(CONFIG_SOC_AU1000)
141-
return -ENODEV;
142-
#else
143-
return au1xxx_gpio2_direction_output(gpio, value);
193+
gpiochip_add(&au1000_gpio_chip[0].chip);
194+
#if !defined(CONFIG_SOC_AU1000)
195+
gpiochip_add(&au1000_gpio_chip[1].chip);
144196
#endif
145197

146-
return au1xxx_gpio1_direction_output(gpio, value);
198+
return 0;
147199
}
148-
EXPORT_SYMBOL(au1xxx_gpio_direction_output);
200+
arch_initcall(au1000_gpio_init);
201+

‎arch/mips/include/asm/mach-au1x00/gpio.h‎

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,29 @@
55

66
#define AU1XXX_GPIO_BASE 200
77

8-
struct au1x00_gpio2 {
9-
u32 dir;
10-
u32 reserved;
11-
u32 output;
12-
u32 pinstate;
13-
u32 inten;
14-
u32 enable;
15-
};
8+
/* GPIO bank 1 offsets */
9+
#define AU1000_GPIO1_TRI_OUT 0x0100
10+
#define AU1000_GPIO1_OUT 0x0108
11+
#define AU1000_GPIO1_ST 0x0110
12+
#define AU1000_GPIO1_CLR 0x010C
1613

17-
extern int au1xxx_gpio_get_value(unsigned gpio);
18-
extern void au1xxx_gpio_set_value(unsigned gpio, int value);
19-
extern int au1xxx_gpio_direction_input(unsigned gpio);
20-
extern int au1xxx_gpio_direction_output(unsigned gpio, int value);
14+
/* GPIO bank 2 offsets */
15+
#define AU1000_GPIO2_DIR 0x00
16+
#define AU1000_GPIO2_RSVD 0x04
17+
#define AU1000_GPIO2_OUT 0x08
18+
#define AU1000_GPIO2_ST 0x0C
19+
#define AU1000_GPIO2_INT 0x10
20+
#define AU1000_GPIO2_EN 0x14
2121

22+
#define GPIO2_OUT_EN_MASK 0x00010000
2223

23-
/* Wrappers for the arch-neutral GPIO API */
24+
#define gpio_to_irq(gpio) NULL
2425

25-
static inline int gpio_request(unsigned gpio, const char *label)
26-
{
27-
/* Not yet implemented */
28-
return 0;
29-
}
26+
#define gpio_get_value __gpio_get_value
27+
#define gpio_set_value __gpio_set_value
3028

31-
static inline void gpio_free(unsigned gpio)
32-
{
33-
/* Not yet implemented */
34-
}
29+
#define gpio_cansleep __gpio_cansleep
3530

36-
static inline int gpio_direction_input(unsigned gpio)
37-
{
38-
return au1xxx_gpio_direction_input(gpio);
39-
}
40-
41-
static inline int gpio_direction_output(unsigned gpio, int value)
42-
{
43-
return au1xxx_gpio_direction_output(gpio, value);
44-
}
45-
46-
static inline int gpio_get_value(unsigned gpio)
47-
{
48-
return au1xxx_gpio_get_value(gpio);
49-
}
50-
51-
static inline void gpio_set_value(unsigned gpio, int value)
52-
{
53-
au1xxx_gpio_set_value(gpio, value);
54-
}
55-
56-
static inline int gpio_to_irq(unsigned gpio)
57-
{
58-
return gpio;
59-
}
60-
61-
static inline int irq_to_gpio(unsigned irq)
62-
{
63-
return irq;
64-
}
65-
66-
/* For cansleep */
6731
#include <asm-generic/gpio.h>
6832

6933
#endif /* _AU1XXX_GPIO_H_ */

0 commit comments

Comments
 (0)