diff options
author | Dmitry Baryshkov <dbaryshkov@gmail.com> | 2008-04-10 08:36:53 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2008-04-10 10:31:38 -0400 |
commit | b43a9e60873ebe16502061961ca3f3b7bc6f69d2 (patch) | |
tree | e8bfe4fc09592010dbd007576f5eeeddc494f7d8 | |
parent | 45528e38173e7d8c03821850e8fd1ddbf16f2b3d (diff) |
[ARM] 4962/1: Introduce standard gpio interface for Scoop2.
This deprecates old set/reset_scoop_gpio interfacein favour of
support for generic gpio interface.
It requires gpiolib, so it depends on the previous patch
(gpiolib for SA-1100).
Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r-- | arch/arm/common/scoop.c | 125 | ||||
-rw-r--r-- | include/asm-arm/hardware/scoop.h | 5 |
2 files changed, 122 insertions, 8 deletions
diff --git a/arch/arm/common/scoop.c b/arch/arm/common/scoop.c index fc08577cdd6c..bc299b07a6fa 100644 --- a/arch/arm/common/scoop.c +++ b/arch/arm/common/scoop.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
17 | #include <linux/platform_device.h> | 17 | #include <linux/platform_device.h> |
18 | #include <asm/io.h> | 18 | #include <asm/io.h> |
19 | #include <asm/gpio.h> | ||
19 | #include <asm/hardware/scoop.h> | 20 | #include <asm/hardware/scoop.h> |
20 | 21 | ||
21 | /* PCMCIA to Scoop linkage | 22 | /* PCMCIA to Scoop linkage |
@@ -32,6 +33,7 @@ EXPORT_SYMBOL(platform_scoop_config); | |||
32 | 33 | ||
33 | struct scoop_dev { | 34 | struct scoop_dev { |
34 | void __iomem *base; | 35 | void __iomem *base; |
36 | struct gpio_chip gpio; | ||
35 | spinlock_t scoop_lock; | 37 | spinlock_t scoop_lock; |
36 | unsigned short suspend_clr; | 38 | unsigned short suspend_clr; |
37 | unsigned short suspend_set; | 39 | unsigned short suspend_set; |
@@ -51,6 +53,77 @@ void reset_scoop(struct device *dev) | |||
51 | iowrite16(0x0000, sdev->base + SCOOP_IRM); | 53 | iowrite16(0x0000, sdev->base + SCOOP_IRM); |
52 | } | 54 | } |
53 | 55 | ||
56 | static void __scoop_gpio_set(struct scoop_dev *sdev, | ||
57 | unsigned offset, int value) | ||
58 | { | ||
59 | unsigned short gpwr; | ||
60 | |||
61 | gpwr = ioread16(sdev->base + SCOOP_GPWR); | ||
62 | if (value) | ||
63 | gpwr |= 1 << (offset + 1); | ||
64 | else | ||
65 | gpwr &= ~(1 << (offset + 1)); | ||
66 | iowrite16(gpwr, sdev->base + SCOOP_GPWR); | ||
67 | } | ||
68 | |||
69 | static void scoop_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
70 | { | ||
71 | struct scoop_dev *sdev = container_of(chip, struct scoop_dev, gpio); | ||
72 | unsigned long flags; | ||
73 | |||
74 | spin_lock_irqsave(&sdev->scoop_lock, flags); | ||
75 | |||
76 | __scoop_gpio_set(sdev, offset, value); | ||
77 | |||
78 | spin_unlock_irqrestore(&sdev->scoop_lock, flags); | ||
79 | } | ||
80 | |||
81 | static int scoop_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
82 | { | ||
83 | struct scoop_dev *sdev = container_of(chip, struct scoop_dev, gpio); | ||
84 | |||
85 | /* XXX: I'm usure, but it seems so */ | ||
86 | return ioread16(sdev->base + SCOOP_GPRR) & (1 << (offset + 1)); | ||
87 | } | ||
88 | |||
89 | static int scoop_gpio_direction_input(struct gpio_chip *chip, | ||
90 | unsigned offset) | ||
91 | { | ||
92 | struct scoop_dev *sdev = container_of(chip, struct scoop_dev, gpio); | ||
93 | unsigned long flags; | ||
94 | unsigned short gpcr; | ||
95 | |||
96 | spin_lock_irqsave(&sdev->scoop_lock, flags); | ||
97 | |||
98 | gpcr = ioread16(sdev->base + SCOOP_GPCR); | ||
99 | gpcr &= ~(1 << (offset + 1)); | ||
100 | iowrite16(gpcr, sdev->base + SCOOP_GPCR); | ||
101 | |||
102 | spin_unlock_irqrestore(&sdev->scoop_lock, flags); | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static int scoop_gpio_direction_output(struct gpio_chip *chip, | ||
108 | unsigned offset, int value) | ||
109 | { | ||
110 | struct scoop_dev *sdev = container_of(chip, struct scoop_dev, gpio); | ||
111 | unsigned long flags; | ||
112 | unsigned short gpcr; | ||
113 | |||
114 | spin_lock_irqsave(&sdev->scoop_lock, flags); | ||
115 | |||
116 | __scoop_gpio_set(sdev, offset, value); | ||
117 | |||
118 | gpcr = ioread16(sdev->base + SCOOP_GPCR); | ||
119 | gpcr |= 1 << (offset + 1); | ||
120 | iowrite16(gpcr, sdev->base + SCOOP_GPCR); | ||
121 | |||
122 | spin_unlock_irqrestore(&sdev->scoop_lock, flags); | ||
123 | |||
124 | return 0; | ||
125 | } | ||
126 | |||
54 | unsigned short set_scoop_gpio(struct device *dev, unsigned short bit) | 127 | unsigned short set_scoop_gpio(struct device *dev, unsigned short bit) |
55 | { | 128 | { |
56 | unsigned short gpio_bit; | 129 | unsigned short gpio_bit; |
@@ -138,6 +211,8 @@ static int __devinit scoop_probe(struct platform_device *pdev) | |||
138 | struct scoop_dev *devptr; | 211 | struct scoop_dev *devptr; |
139 | struct scoop_config *inf; | 212 | struct scoop_config *inf; |
140 | struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 213 | struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
214 | int ret; | ||
215 | int temp; | ||
141 | 216 | ||
142 | if (!mem) | 217 | if (!mem) |
143 | return -EINVAL; | 218 | return -EINVAL; |
@@ -152,8 +227,8 @@ static int __devinit scoop_probe(struct platform_device *pdev) | |||
152 | devptr->base = ioremap(mem->start, mem->end - mem->start + 1); | 227 | devptr->base = ioremap(mem->start, mem->end - mem->start + 1); |
153 | 228 | ||
154 | if (!devptr->base) { | 229 | if (!devptr->base) { |
155 | kfree(devptr); | 230 | ret = -ENOMEM; |
156 | return -ENOMEM; | 231 | goto err_ioremap; |
157 | } | 232 | } |
158 | 233 | ||
159 | platform_set_drvdata(pdev, devptr); | 234 | platform_set_drvdata(pdev, devptr); |
@@ -169,17 +244,55 @@ static int __devinit scoop_probe(struct platform_device *pdev) | |||
169 | devptr->suspend_clr = inf->suspend_clr; | 244 | devptr->suspend_clr = inf->suspend_clr; |
170 | devptr->suspend_set = inf->suspend_set; | 245 | devptr->suspend_set = inf->suspend_set; |
171 | 246 | ||
247 | devptr->gpio.base = -1; | ||
248 | |||
249 | if (inf->gpio_base != 0) { | ||
250 | devptr->gpio.label = pdev->dev.bus_id; | ||
251 | devptr->gpio.base = inf->gpio_base; | ||
252 | devptr->gpio.ngpio = 12; /* PA11 = 0, PA12 = 1, etc. up to PA22 = 11 */ | ||
253 | devptr->gpio.set = scoop_gpio_set; | ||
254 | devptr->gpio.get = scoop_gpio_get; | ||
255 | devptr->gpio.direction_input = scoop_gpio_direction_input; | ||
256 | devptr->gpio.direction_output = scoop_gpio_direction_output; | ||
257 | |||
258 | ret = gpiochip_add(&devptr->gpio); | ||
259 | if (ret) | ||
260 | goto err_gpio; | ||
261 | } | ||
262 | |||
172 | return 0; | 263 | return 0; |
264 | |||
265 | if (devptr->gpio.base != -1) | ||
266 | temp = gpiochip_remove(&devptr->gpio); | ||
267 | err_gpio: | ||
268 | platform_set_drvdata(pdev, NULL); | ||
269 | err_ioremap: | ||
270 | iounmap(devptr->base); | ||
271 | kfree(devptr); | ||
272 | |||
273 | return ret; | ||
173 | } | 274 | } |
174 | 275 | ||
175 | static int __devexit scoop_remove(struct platform_device *pdev) | 276 | static int __devexit scoop_remove(struct platform_device *pdev) |
176 | { | 277 | { |
177 | struct scoop_dev *sdev = platform_get_drvdata(pdev); | 278 | struct scoop_dev *sdev = platform_get_drvdata(pdev); |
178 | if (sdev) { | 279 | int ret; |
179 | iounmap(sdev->base); | 280 | |
180 | kfree(sdev); | 281 | if (!sdev) |
181 | platform_set_drvdata(pdev, NULL); | 282 | return -EINVAL; |
283 | |||
284 | if (sdev->gpio.base != -1) { | ||
285 | ret = gpiochip_remove(&sdev->gpio); | ||
286 | if (ret) { | ||
287 | dev_err(&pdev->dev, "Can't remove gpio chip: %d\n", ret); | ||
288 | return ret; | ||
289 | } | ||
182 | } | 290 | } |
291 | |||
292 | platform_set_drvdata(pdev, NULL); | ||
293 | iounmap(sdev->base); | ||
294 | kfree(sdev); | ||
295 | |||
183 | return 0; | 296 | return 0; |
184 | } | 297 | } |
185 | 298 | ||
diff --git a/include/asm-arm/hardware/scoop.h b/include/asm-arm/hardware/scoop.h index d37bf7443264..dfb8330599f9 100644 --- a/include/asm-arm/hardware/scoop.h +++ b/include/asm-arm/hardware/scoop.h | |||
@@ -40,6 +40,7 @@ struct scoop_config { | |||
40 | unsigned short io_dir; | 40 | unsigned short io_dir; |
41 | unsigned short suspend_clr; | 41 | unsigned short suspend_clr; |
42 | unsigned short suspend_set; | 42 | unsigned short suspend_set; |
43 | int gpio_base; | ||
43 | }; | 44 | }; |
44 | 45 | ||
45 | /* Structure for linking scoop devices to PCMCIA sockets */ | 46 | /* Structure for linking scoop devices to PCMCIA sockets */ |
@@ -62,7 +63,7 @@ struct scoop_pcmcia_config { | |||
62 | extern struct scoop_pcmcia_config *platform_scoop_config; | 63 | extern struct scoop_pcmcia_config *platform_scoop_config; |
63 | 64 | ||
64 | void reset_scoop(struct device *dev); | 65 | void reset_scoop(struct device *dev); |
65 | unsigned short set_scoop_gpio(struct device *dev, unsigned short bit); | 66 | unsigned short __deprecated set_scoop_gpio(struct device *dev, unsigned short bit); |
66 | unsigned short reset_scoop_gpio(struct device *dev, unsigned short bit); | 67 | unsigned short __deprecated reset_scoop_gpio(struct device *dev, unsigned short bit); |
67 | unsigned short read_scoop_reg(struct device *dev, unsigned short reg); | 68 | unsigned short read_scoop_reg(struct device *dev, unsigned short reg); |
68 | void write_scoop_reg(struct device *dev, unsigned short reg, unsigned short data); | 69 | void write_scoop_reg(struct device *dev, unsigned short reg, unsigned short data); |