Root/target/linux/ifxmips/files-2.6.33/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
14static int shadow = 0;
15static void __iomem *virt;
16
17static int
18ifxmips_ebu_direction_output(struct gpio_chip *chip, unsigned offset, int value)
19{
20    return 0;
21}
22
23static void
24ifxmips_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
38static struct gpio_chip
39ifxmips_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
50static int __devinit
51ifxmips_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
63static int
64ifxmips_ebu_remove(struct platform_device *dev)
65{
66    return gpiochip_remove(&ifxmips_ebu_chip);
67}
68
69static struct platform_driver
70ifxmips_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
79static int __init
80ifxmips_ebu_init(void)
81{
82    return platform_driver_register(&ifxmips_ebu_driver);
83}
84
85static void __exit
86ifxmips_ebu_exit(void)
87{
88    platform_driver_unregister(&ifxmips_ebu_driver);
89}
90
91module_init(ifxmips_ebu_init);
92module_exit(ifxmips_ebu_exit);
93
94MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
95MODULE_LICENSE("GPL v2");
96MODULE_DESCRIPTION("ifxmips - EBU Latch GPIO-Expander");
97

Archive Download this file



interactive