[ifxmips]:
[openwrt/svn-archive/archive.git] / target / linux / ifxmips / files / arch / mips / ifxmips / danube / ebu.c
1 #include <linux/init.h>
2 #include <linux/module.h>
3 #include <linux/types.h>
4 #include <linux/platform_device.h>
5 #include <linux/mutex.h>
6 #include <linux/gpio.h>
7
8 #include <ifxmips.h>
9 #include <ifxmips_ebu.h>
10
11 #define IFXMIPS_EBU_BUSCON 0x1e7ff
12 #define IFXMIPS_EBU_WP 0x80000000
13
14 static int shadow = 0;
15 static void __iomem *virt;
16
17 static int
18 ifxmips_ebu_direction_output(struct gpio_chip *chip, unsigned offset, int value)
19 {
20 return 0;
21 }
22
23 static void
24 ifxmips_ebu_set(struct gpio_chip *chip, unsigned offset, int value)
25 {
26 unsigned long flags;
27 if(value)
28 shadow |= (1 << offset);
29 else
30 shadow &= ~(1 << offset);
31 spin_lock_irqsave(&ebu_lock, flags);
32 ifxmips_w32(IFXMIPS_EBU_BUSCON, IFXMIPS_EBU_BUSCON1);
33 *((__u16*)virt) = shadow;
34 ifxmips_w32(IFXMIPS_EBU_BUSCON | IFXMIPS_EBU_WP, IFXMIPS_EBU_BUSCON1);
35 spin_unlock_irqrestore(&ebu_lock, flags);
36 }
37
38 static struct gpio_chip
39 ifxmips_ebu_chip =
40 {
41 .label = "ifxmips_ebu",
42 .direction_output = ifxmips_ebu_direction_output,
43 .set = ifxmips_ebu_set,
44 .base = 32,
45 .ngpio = 16,
46 .can_sleep = 1,
47 .owner = THIS_MODULE,
48 };
49
50 static int __devinit
51 ifxmips_ebu_probe(struct platform_device *pdev)
52 {
53 ifxmips_w32(pdev->resource->start | 0x1, IFXMIPS_EBU_ADDRSEL1);
54 ifxmips_w32(IFXMIPS_EBU_BUSCON | IFXMIPS_EBU_WP, IFXMIPS_EBU_BUSCON1);
55 virt = ioremap_nocache(pdev->resource->start, pdev->resource->end);
56 if(gpiochip_add(&ifxmips_ebu_chip))
57 return -EINVAL;
58 shadow = (int) pdev->dev.platform_data;
59 printk("IFXMIPS: ebu-gpio loaded\n");
60 return 0;
61 }
62
63 static int
64 ifxmips_ebu_remove(struct platform_device *dev)
65 {
66 return gpiochip_remove(&ifxmips_ebu_chip);
67 }
68
69 static struct platform_driver
70 ifxmips_ebu_driver = {
71 .probe = ifxmips_ebu_probe,
72 .remove = ifxmips_ebu_remove,
73 .driver = {
74 .name = "ifxmips_ebu",
75 .owner = THIS_MODULE,
76 },
77 };
78
79 static int __init
80 ifxmips_ebu_init(void)
81 {
82 return platform_driver_register(&ifxmips_ebu_driver);
83 }
84
85 static void __exit
86 ifxmips_ebu_exit(void)
87 {
88 platform_driver_unregister(&ifxmips_ebu_driver);
89 }
90
91 module_init(ifxmips_ebu_init);
92 module_exit(ifxmips_ebu_exit);
93
94 MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
95 MODULE_LICENSE("GPL v2");
96 MODULE_DESCRIPTION("ifxmips - EBU Latch GPIO-Expander");