aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/cs5535-gpio.c
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/gpio/cs5535-gpio.c
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'drivers/gpio/cs5535-gpio.c')
-rw-r--r--drivers/gpio/cs5535-gpio.c172
1 files changed, 108 insertions, 64 deletions
diff --git a/drivers/gpio/cs5535-gpio.c b/drivers/gpio/cs5535-gpio.c
index e23c06893d19..6e16cba56ad2 100644
--- a/drivers/gpio/cs5535-gpio.c
+++ b/drivers/gpio/cs5535-gpio.c
@@ -11,13 +11,13 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/spinlock.h> 12#include <linux/spinlock.h>
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/pci.h> 14#include <linux/platform_device.h>
15#include <linux/gpio.h> 15#include <linux/gpio.h>
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/cs5535.h> 17#include <linux/cs5535.h>
18#include <asm/msr.h>
18 19
19#define DRV_NAME "cs5535-gpio" 20#define DRV_NAME "cs5535-gpio"
20#define GPIO_BAR 1
21 21
22/* 22/*
23 * Some GPIO pins 23 * Some GPIO pins
@@ -46,7 +46,7 @@ static struct cs5535_gpio_chip {
46 struct gpio_chip chip; 46 struct gpio_chip chip;
47 resource_size_t base; 47 resource_size_t base;
48 48
49 struct pci_dev *pdev; 49 struct platform_device *pdev;
50 spinlock_t lock; 50 spinlock_t lock;
51} cs5535_gpio_chip; 51} cs5535_gpio_chip;
52 52
@@ -56,6 +56,29 @@ static struct cs5535_gpio_chip {
56 * registers, see include/linux/cs5535.h. 56 * registers, see include/linux/cs5535.h.
57 */ 57 */
58 58
59static void errata_outl(struct cs5535_gpio_chip *chip, u32 val,
60 unsigned int reg)
61{
62 unsigned long addr = chip->base + 0x80 + reg;
63
64 /*
65 * According to the CS5536 errata (#36), after suspend
66 * a write to the high bank GPIO register will clear all
67 * non-selected bits; the recommended workaround is a
68 * read-modify-write operation.
69 *
70 * Don't apply this errata to the edge status GPIOs, as writing
71 * to their lower bits will clear them.
72 */
73 if (reg != GPIO_POSITIVE_EDGE_STS && reg != GPIO_NEGATIVE_EDGE_STS) {
74 if (val & 0xffff)
75 val |= (inl(addr) & 0xffff); /* ignore the high bits */
76 else
77 val |= (inl(addr) ^ (val >> 16));
78 }
79 outl(val, addr);
80}
81
59static void __cs5535_gpio_set(struct cs5535_gpio_chip *chip, unsigned offset, 82static void __cs5535_gpio_set(struct cs5535_gpio_chip *chip, unsigned offset,
60 unsigned int reg) 83 unsigned int reg)
61{ 84{
@@ -64,7 +87,7 @@ static void __cs5535_gpio_set(struct cs5535_gpio_chip *chip, unsigned offset,
64 outl(1 << offset, chip->base + reg); 87 outl(1 << offset, chip->base + reg);
65 else 88 else
66 /* high bank register */ 89 /* high bank register */
67 outl(1 << (offset - 16), chip->base + 0x80 + reg); 90 errata_outl(chip, 1 << (offset - 16), reg);
68} 91}
69 92
70void cs5535_gpio_set(unsigned offset, unsigned int reg) 93void cs5535_gpio_set(unsigned offset, unsigned int reg)
@@ -86,7 +109,7 @@ static void __cs5535_gpio_clear(struct cs5535_gpio_chip *chip, unsigned offset,
86 outl(1 << (offset + 16), chip->base + reg); 109 outl(1 << (offset + 16), chip->base + reg);
87 else 110 else
88 /* high bank register */ 111 /* high bank register */
89 outl(1 << offset, chip->base + 0x80 + reg); 112 errata_outl(chip, 1 << offset, reg);
90} 113}
91 114
92void cs5535_gpio_clear(unsigned offset, unsigned int reg) 115void cs5535_gpio_clear(unsigned offset, unsigned int reg)
@@ -121,6 +144,57 @@ int cs5535_gpio_isset(unsigned offset, unsigned int reg)
121} 144}
122EXPORT_SYMBOL_GPL(cs5535_gpio_isset); 145EXPORT_SYMBOL_GPL(cs5535_gpio_isset);
123 146
147int cs5535_gpio_set_irq(unsigned group, unsigned irq)
148{
149 uint32_t lo, hi;
150
151 if (group > 7 || irq > 15)
152 return -EINVAL;
153
154 rdmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
155
156 lo &= ~(0xF << (group * 4));
157 lo |= (irq & 0xF) << (group * 4);
158
159 wrmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
160 return 0;
161}
162EXPORT_SYMBOL_GPL(cs5535_gpio_set_irq);
163
164void cs5535_gpio_setup_event(unsigned offset, int pair, int pme)
165{
166 struct cs5535_gpio_chip *chip = &cs5535_gpio_chip;
167 uint32_t shift = (offset % 8) * 4;
168 unsigned long flags;
169 uint32_t val;
170
171 if (offset >= 24)
172 offset = GPIO_MAP_W;
173 else if (offset >= 16)
174 offset = GPIO_MAP_Z;
175 else if (offset >= 8)
176 offset = GPIO_MAP_Y;
177 else
178 offset = GPIO_MAP_X;
179
180 spin_lock_irqsave(&chip->lock, flags);
181 val = inl(chip->base + offset);
182
183 /* Clear whatever was there before */
184 val &= ~(0xF << shift);
185
186 /* Set the new value */
187 val |= ((pair & 7) << shift);
188
189 /* Set the PME bit if this is a PME event */
190 if (pme)
191 val |= (1 << (shift + 3));
192
193 outl(val, chip->base + offset);
194 spin_unlock_irqrestore(&chip->lock, flags);
195}
196EXPORT_SYMBOL_GPL(cs5535_gpio_setup_event);
197
124/* 198/*
125 * Generic gpio_chip API support. 199 * Generic gpio_chip API support.
126 */ 200 */
@@ -226,10 +300,10 @@ static struct cs5535_gpio_chip cs5535_gpio_chip = {
226 }, 300 },
227}; 301};
228 302
229static int __init cs5535_gpio_probe(struct pci_dev *pdev, 303static int __devinit cs5535_gpio_probe(struct platform_device *pdev)
230 const struct pci_device_id *pci_id)
231{ 304{
232 int err; 305 struct resource *res;
306 int err = -EIO;
233 ulong mask_orig = mask; 307 ulong mask_orig = mask;
234 308
235 /* There are two ways to get the GPIO base address; one is by 309 /* There are two ways to get the GPIO base address; one is by
@@ -239,25 +313,23 @@ static int __init cs5535_gpio_probe(struct pci_dev *pdev,
239 * it turns out to be unreliable in the face of crappy BIOSes, we 313 * it turns out to be unreliable in the face of crappy BIOSes, we
240 * can always go back to using MSRs.. */ 314 * can always go back to using MSRs.. */
241 315
242 err = pci_enable_device_io(pdev); 316 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
243 if (err) { 317 if (!res) {
244 dev_err(&pdev->dev, "can't enable device IO\n"); 318 dev_err(&pdev->dev, "can't fetch device resource info\n");
245 goto done; 319 goto done;
246 } 320 }
247 321
248 err = pci_request_region(pdev, GPIO_BAR, DRV_NAME); 322 if (!request_region(res->start, resource_size(res), pdev->name)) {
249 if (err) { 323 dev_err(&pdev->dev, "can't request region\n");
250 dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", GPIO_BAR);
251 goto done; 324 goto done;
252 } 325 }
253 326
254 /* set up the driver-specific struct */ 327 /* set up the driver-specific struct */
255 cs5535_gpio_chip.base = pci_resource_start(pdev, GPIO_BAR); 328 cs5535_gpio_chip.base = res->start;
256 cs5535_gpio_chip.pdev = pdev; 329 cs5535_gpio_chip.pdev = pdev;
257 spin_lock_init(&cs5535_gpio_chip.lock); 330 spin_lock_init(&cs5535_gpio_chip.lock);
258 331
259 dev_info(&pdev->dev, "allocated PCI BAR #%d: base 0x%llx\n", GPIO_BAR, 332 dev_info(&pdev->dev, "reserved resource region %pR\n", res);
260 (unsigned long long) cs5535_gpio_chip.base);
261 333
262 /* mask out reserved pins */ 334 /* mask out reserved pins */
263 mask &= 0x1F7FFFFF; 335 mask &= 0x1F7FFFFF;
@@ -275,78 +347,49 @@ static int __init cs5535_gpio_probe(struct pci_dev *pdev,
275 if (err) 347 if (err)
276 goto release_region; 348 goto release_region;
277 349
278 dev_info(&pdev->dev, DRV_NAME ": GPIO support successfully loaded.\n"); 350 dev_info(&pdev->dev, "GPIO support successfully loaded.\n");
279 return 0; 351 return 0;
280 352
281release_region: 353release_region:
282 pci_release_region(pdev, GPIO_BAR); 354 release_region(res->start, resource_size(res));
283done: 355done:
284 return err; 356 return err;
285} 357}
286 358
287static void __exit cs5535_gpio_remove(struct pci_dev *pdev) 359static int __devexit cs5535_gpio_remove(struct platform_device *pdev)
288{ 360{
361 struct resource *r;
289 int err; 362 int err;
290 363
291 err = gpiochip_remove(&cs5535_gpio_chip.chip); 364 err = gpiochip_remove(&cs5535_gpio_chip.chip);
292 if (err) { 365 if (err) {
293 /* uhh? */ 366 /* uhh? */
294 dev_err(&pdev->dev, "unable to remove gpio_chip?\n"); 367 dev_err(&pdev->dev, "unable to remove gpio_chip?\n");
368 return err;
295 } 369 }
296 pci_release_region(pdev, GPIO_BAR);
297}
298
299static struct pci_device_id cs5535_gpio_pci_tbl[] = {
300 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
301 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
302 { 0, },
303};
304MODULE_DEVICE_TABLE(pci, cs5535_gpio_pci_tbl);
305 370
306/* 371 r = platform_get_resource(pdev, IORESOURCE_IO, 0);
307 * We can't use the standard PCI driver registration stuff here, since 372 release_region(r->start, resource_size(r));
308 * that allows only one driver to bind to each PCI device (and we want 373 return 0;
309 * multiple drivers to be able to bind to the device). Instead, manually
310 * scan for the PCI device, request a single region, and keep track of the
311 * devices that we're using.
312 */
313
314static int __init cs5535_gpio_scan_pci(void)
315{
316 struct pci_dev *pdev;
317 int err = -ENODEV;
318 int i;
319
320 for (i = 0; i < ARRAY_SIZE(cs5535_gpio_pci_tbl); i++) {
321 pdev = pci_get_device(cs5535_gpio_pci_tbl[i].vendor,
322 cs5535_gpio_pci_tbl[i].device, NULL);
323 if (pdev) {
324 err = cs5535_gpio_probe(pdev, &cs5535_gpio_pci_tbl[i]);
325 if (err)
326 pci_dev_put(pdev);
327
328 /* we only support a single CS5535/6 southbridge */
329 break;
330 }
331 }
332
333 return err;
334} 374}
335 375
336static void __exit cs5535_gpio_free_pci(void) 376static struct platform_driver cs5535_gpio_driver = {
337{ 377 .driver = {
338 cs5535_gpio_remove(cs5535_gpio_chip.pdev); 378 .name = DRV_NAME,
339 pci_dev_put(cs5535_gpio_chip.pdev); 379 .owner = THIS_MODULE,
340} 380 },
381 .probe = cs5535_gpio_probe,
382 .remove = __devexit_p(cs5535_gpio_remove),
383};
341 384
342static int __init cs5535_gpio_init(void) 385static int __init cs5535_gpio_init(void)
343{ 386{
344 return cs5535_gpio_scan_pci(); 387 return platform_driver_register(&cs5535_gpio_driver);
345} 388}
346 389
347static void __exit cs5535_gpio_exit(void) 390static void __exit cs5535_gpio_exit(void)
348{ 391{
349 cs5535_gpio_free_pci(); 392 platform_driver_unregister(&cs5535_gpio_driver);
350} 393}
351 394
352module_init(cs5535_gpio_init); 395module_init(cs5535_gpio_init);
@@ -355,3 +398,4 @@ module_exit(cs5535_gpio_exit);
355MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>"); 398MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>");
356MODULE_DESCRIPTION("AMD CS5535/CS5536 GPIO driver"); 399MODULE_DESCRIPTION("AMD CS5535/CS5536 GPIO driver");
357MODULE_LICENSE("GPL"); 400MODULE_LICENSE("GPL");
401MODULE_ALIAS("platform:" DRV_NAME);