diff options
Diffstat (limited to 'arch/arm/common/scoop.c')
-rw-r--r-- | arch/arm/common/scoop.c | 183 |
1 files changed, 147 insertions, 36 deletions
diff --git a/arch/arm/common/scoop.c b/arch/arm/common/scoop.c index 314ebd3a1d71..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 |
@@ -30,10 +31,9 @@ | |||
30 | struct scoop_pcmcia_config *platform_scoop_config; | 31 | struct scoop_pcmcia_config *platform_scoop_config; |
31 | EXPORT_SYMBOL(platform_scoop_config); | 32 | EXPORT_SYMBOL(platform_scoop_config); |
32 | 33 | ||
33 | #define SCOOP_REG(d,adr) (*(volatile unsigned short*)(d +(adr))) | ||
34 | |||
35 | struct scoop_dev { | 34 | struct scoop_dev { |
36 | void *base; | 35 | void __iomem *base; |
36 | struct gpio_chip gpio; | ||
37 | spinlock_t scoop_lock; | 37 | spinlock_t scoop_lock; |
38 | unsigned short suspend_clr; | 38 | unsigned short suspend_clr; |
39 | unsigned short suspend_set; | 39 | unsigned short suspend_set; |
@@ -44,13 +44,84 @@ void reset_scoop(struct device *dev) | |||
44 | { | 44 | { |
45 | struct scoop_dev *sdev = dev_get_drvdata(dev); | 45 | struct scoop_dev *sdev = dev_get_drvdata(dev); |
46 | 46 | ||
47 | SCOOP_REG(sdev->base,SCOOP_MCR) = 0x0100; // 00 | 47 | iowrite16(0x0100, sdev->base + SCOOP_MCR); // 00 |
48 | SCOOP_REG(sdev->base,SCOOP_CDR) = 0x0000; // 04 | 48 | iowrite16(0x0000, sdev->base + SCOOP_CDR); // 04 |
49 | SCOOP_REG(sdev->base,SCOOP_CCR) = 0x0000; // 10 | 49 | iowrite16(0x0000, sdev->base + SCOOP_CCR); // 10 |
50 | SCOOP_REG(sdev->base,SCOOP_IMR) = 0x0000; // 18 | 50 | iowrite16(0x0000, sdev->base + SCOOP_IMR); // 18 |
51 | SCOOP_REG(sdev->base,SCOOP_IRM) = 0x00FF; // 14 | 51 | iowrite16(0x00FF, sdev->base + SCOOP_IRM); // 14 |
52 | SCOOP_REG(sdev->base,SCOOP_ISR) = 0x0000; // 1C | 52 | iowrite16(0x0000, sdev->base + SCOOP_ISR); // 1C |
53 | SCOOP_REG(sdev->base,SCOOP_IRM) = 0x0000; | 53 | iowrite16(0x0000, sdev->base + SCOOP_IRM); |
54 | } | ||
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; | ||
54 | } | 125 | } |
55 | 126 | ||
56 | unsigned short set_scoop_gpio(struct device *dev, unsigned short bit) | 127 | unsigned short set_scoop_gpio(struct device *dev, unsigned short bit) |
@@ -60,8 +131,8 @@ unsigned short set_scoop_gpio(struct device *dev, unsigned short bit) | |||
60 | struct scoop_dev *sdev = dev_get_drvdata(dev); | 131 | struct scoop_dev *sdev = dev_get_drvdata(dev); |
61 | 132 | ||
62 | spin_lock_irqsave(&sdev->scoop_lock, flag); | 133 | spin_lock_irqsave(&sdev->scoop_lock, flag); |
63 | gpio_bit = SCOOP_REG(sdev->base, SCOOP_GPWR) | bit; | 134 | gpio_bit = ioread16(sdev->base + SCOOP_GPWR) | bit; |
64 | SCOOP_REG(sdev->base, SCOOP_GPWR) = gpio_bit; | 135 | iowrite16(gpio_bit, sdev->base + SCOOP_GPWR); |
65 | spin_unlock_irqrestore(&sdev->scoop_lock, flag); | 136 | spin_unlock_irqrestore(&sdev->scoop_lock, flag); |
66 | 137 | ||
67 | return gpio_bit; | 138 | return gpio_bit; |
@@ -74,8 +145,8 @@ unsigned short reset_scoop_gpio(struct device *dev, unsigned short bit) | |||
74 | struct scoop_dev *sdev = dev_get_drvdata(dev); | 145 | struct scoop_dev *sdev = dev_get_drvdata(dev); |
75 | 146 | ||
76 | spin_lock_irqsave(&sdev->scoop_lock, flag); | 147 | spin_lock_irqsave(&sdev->scoop_lock, flag); |
77 | gpio_bit = SCOOP_REG(sdev->base, SCOOP_GPWR) & ~bit; | 148 | gpio_bit = ioread16(sdev->base + SCOOP_GPWR) & ~bit; |
78 | SCOOP_REG(sdev->base,SCOOP_GPWR) = gpio_bit; | 149 | iowrite16(gpio_bit, sdev->base + SCOOP_GPWR); |
79 | spin_unlock_irqrestore(&sdev->scoop_lock, flag); | 150 | spin_unlock_irqrestore(&sdev->scoop_lock, flag); |
80 | 151 | ||
81 | return gpio_bit; | 152 | return gpio_bit; |
@@ -87,13 +158,13 @@ EXPORT_SYMBOL(reset_scoop_gpio); | |||
87 | unsigned short read_scoop_reg(struct device *dev, unsigned short reg) | 158 | unsigned short read_scoop_reg(struct device *dev, unsigned short reg) |
88 | { | 159 | { |
89 | struct scoop_dev *sdev = dev_get_drvdata(dev); | 160 | struct scoop_dev *sdev = dev_get_drvdata(dev); |
90 | return SCOOP_REG(sdev->base,reg); | 161 | return ioread16(sdev->base + reg); |
91 | } | 162 | } |
92 | 163 | ||
93 | void write_scoop_reg(struct device *dev, unsigned short reg, unsigned short data) | 164 | void write_scoop_reg(struct device *dev, unsigned short reg, unsigned short data) |
94 | { | 165 | { |
95 | struct scoop_dev *sdev = dev_get_drvdata(dev); | 166 | struct scoop_dev *sdev = dev_get_drvdata(dev); |
96 | SCOOP_REG(sdev->base,reg)=data; | 167 | iowrite16(data, sdev->base + reg); |
97 | } | 168 | } |
98 | 169 | ||
99 | EXPORT_SYMBOL(reset_scoop); | 170 | EXPORT_SYMBOL(reset_scoop); |
@@ -104,9 +175,9 @@ static void check_scoop_reg(struct scoop_dev *sdev) | |||
104 | { | 175 | { |
105 | unsigned short mcr; | 176 | unsigned short mcr; |
106 | 177 | ||
107 | mcr = SCOOP_REG(sdev->base, SCOOP_MCR); | 178 | mcr = ioread16(sdev->base + SCOOP_MCR); |
108 | if ((mcr & 0x100) == 0) | 179 | if ((mcr & 0x100) == 0) |
109 | SCOOP_REG(sdev->base, SCOOP_MCR) = 0x0101; | 180 | iowrite16(0x0101, sdev->base + SCOOP_MCR); |
110 | } | 181 | } |
111 | 182 | ||
112 | #ifdef CONFIG_PM | 183 | #ifdef CONFIG_PM |
@@ -115,8 +186,8 @@ static int scoop_suspend(struct platform_device *dev, pm_message_t state) | |||
115 | struct scoop_dev *sdev = platform_get_drvdata(dev); | 186 | struct scoop_dev *sdev = platform_get_drvdata(dev); |
116 | 187 | ||
117 | check_scoop_reg(sdev); | 188 | check_scoop_reg(sdev); |
118 | sdev->scoop_gpwr = SCOOP_REG(sdev->base, SCOOP_GPWR); | 189 | sdev->scoop_gpwr = ioread16(sdev->base + SCOOP_GPWR); |
119 | SCOOP_REG(sdev->base, SCOOP_GPWR) = (sdev->scoop_gpwr & ~sdev->suspend_clr) | sdev->suspend_set; | 190 | iowrite16((sdev->scoop_gpwr & ~sdev->suspend_clr) | sdev->suspend_set, sdev->base + SCOOP_GPWR); |
120 | 191 | ||
121 | return 0; | 192 | return 0; |
122 | } | 193 | } |
@@ -126,7 +197,7 @@ static int scoop_resume(struct platform_device *dev) | |||
126 | struct scoop_dev *sdev = platform_get_drvdata(dev); | 197 | struct scoop_dev *sdev = platform_get_drvdata(dev); |
127 | 198 | ||
128 | check_scoop_reg(sdev); | 199 | check_scoop_reg(sdev); |
129 | SCOOP_REG(sdev->base,SCOOP_GPWR) = sdev->scoop_gpwr; | 200 | iowrite16(sdev->scoop_gpwr, sdev->base + SCOOP_GPWR); |
130 | 201 | ||
131 | return 0; | 202 | return 0; |
132 | } | 203 | } |
@@ -135,11 +206,13 @@ static int scoop_resume(struct platform_device *dev) | |||
135 | #define scoop_resume NULL | 206 | #define scoop_resume NULL |
136 | #endif | 207 | #endif |
137 | 208 | ||
138 | int __init scoop_probe(struct platform_device *pdev) | 209 | static int __devinit scoop_probe(struct platform_device *pdev) |
139 | { | 210 | { |
140 | struct scoop_dev *devptr; | 211 | struct scoop_dev *devptr; |
141 | struct scoop_config *inf; | 212 | struct scoop_config *inf; |
142 | 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; | ||
143 | 216 | ||
144 | if (!mem) | 217 | if (!mem) |
145 | return -EINVAL; | 218 | return -EINVAL; |
@@ -154,40 +227,78 @@ int __init scoop_probe(struct platform_device *pdev) | |||
154 | devptr->base = ioremap(mem->start, mem->end - mem->start + 1); | 227 | devptr->base = ioremap(mem->start, mem->end - mem->start + 1); |
155 | 228 | ||
156 | if (!devptr->base) { | 229 | if (!devptr->base) { |
157 | kfree(devptr); | 230 | ret = -ENOMEM; |
158 | return -ENOMEM; | 231 | goto err_ioremap; |
159 | } | 232 | } |
160 | 233 | ||
161 | platform_set_drvdata(pdev, devptr); | 234 | platform_set_drvdata(pdev, devptr); |
162 | 235 | ||
163 | printk("Sharp Scoop Device found at 0x%08x -> 0x%08x\n",(unsigned int)mem->start,(unsigned int)devptr->base); | 236 | printk("Sharp Scoop Device found at 0x%08x -> 0x%8p\n",(unsigned int)mem->start, devptr->base); |
164 | 237 | ||
165 | SCOOP_REG(devptr->base, SCOOP_MCR) = 0x0140; | 238 | iowrite16(0x0140, devptr->base + SCOOP_MCR); |
166 | reset_scoop(&pdev->dev); | 239 | reset_scoop(&pdev->dev); |
167 | SCOOP_REG(devptr->base, SCOOP_CPR) = 0x0000; | 240 | iowrite16(0x0000, devptr->base + SCOOP_CPR); |
168 | SCOOP_REG(devptr->base, SCOOP_GPCR) = inf->io_dir & 0xffff; | 241 | iowrite16(inf->io_dir & 0xffff, devptr->base + SCOOP_GPCR); |
169 | SCOOP_REG(devptr->base, SCOOP_GPWR) = inf->io_out & 0xffff; | 242 | iowrite16(inf->io_out & 0xffff, devptr->base + SCOOP_GPWR); |
170 | 243 | ||
171 | devptr->suspend_clr = inf->suspend_clr; | 244 | devptr->suspend_clr = inf->suspend_clr; |
172 | devptr->suspend_set = inf->suspend_set; | 245 | devptr->suspend_set = inf->suspend_set; |
173 | 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 | |||
174 | 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; | ||
175 | } | 274 | } |
176 | 275 | ||
177 | static int scoop_remove(struct platform_device *pdev) | 276 | static int __devexit scoop_remove(struct platform_device *pdev) |
178 | { | 277 | { |
179 | struct scoop_dev *sdev = platform_get_drvdata(pdev); | 278 | struct scoop_dev *sdev = platform_get_drvdata(pdev); |
180 | if (sdev) { | 279 | int ret; |
181 | iounmap(sdev->base); | 280 | |
182 | kfree(sdev); | 281 | if (!sdev) |
183 | 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 | } | ||
184 | } | 290 | } |
291 | |||
292 | platform_set_drvdata(pdev, NULL); | ||
293 | iounmap(sdev->base); | ||
294 | kfree(sdev); | ||
295 | |||
185 | return 0; | 296 | return 0; |
186 | } | 297 | } |
187 | 298 | ||
188 | static struct platform_driver scoop_driver = { | 299 | static struct platform_driver scoop_driver = { |
189 | .probe = scoop_probe, | 300 | .probe = scoop_probe, |
190 | .remove = scoop_remove, | 301 | .remove = __devexit_p(scoop_remove), |
191 | .suspend = scoop_suspend, | 302 | .suspend = scoop_suspend, |
192 | .resume = scoop_resume, | 303 | .resume = scoop_resume, |
193 | .driver = { | 304 | .driver = { |
@@ -195,7 +306,7 @@ static struct platform_driver scoop_driver = { | |||
195 | }, | 306 | }, |
196 | }; | 307 | }; |
197 | 308 | ||
198 | int __init scoop_init(void) | 309 | static int __init scoop_init(void) |
199 | { | 310 | { |
200 | return platform_driver_register(&scoop_driver); | 311 | return platform_driver_register(&scoop_driver); |
201 | } | 312 | } |