This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / arm / common / scoop.c
1 /*
2  * Support code for the SCOOP interface found on various Sharp PDAs
3  *
4  * Copyright (c) 2004 Richard Purdie
5  *
6  *      Based on code written by Sharp/Lineo for 2.4 kernels
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  *
12  */
13
14 #include <linux/device.h>
15 #include <asm/io.h>
16 #include <asm/hardware/scoop.h>
17
18 static void __iomem *scoop_io_base;
19
20 #define SCOOP_REG(adr) (*(volatile unsigned short*)(scoop_io_base+(adr)))
21
22 void reset_scoop(void)
23 {
24         SCOOP_REG(SCOOP_MCR) = 0x0100;  // 00
25         SCOOP_REG(SCOOP_CDR) = 0x0000;  // 04
26         SCOOP_REG(SCOOP_CPR) = 0x0000;  // 0C
27         SCOOP_REG(SCOOP_CCR) = 0x0000;  // 10
28         SCOOP_REG(SCOOP_IMR) = 0x0000;  // 18
29         SCOOP_REG(SCOOP_IRM) = 0x00FF;  // 14
30         SCOOP_REG(SCOOP_ISR) = 0x0000;  // 1C
31         SCOOP_REG(SCOOP_IRM) = 0x0000;
32 }
33
34 static DEFINE_SPINLOCK(scoop_lock);
35 static u32 scoop_gpwr;
36
37 unsigned short set_scoop_gpio(unsigned short bit)
38 {
39         unsigned short gpio_bit;
40         unsigned long flag;
41
42         spin_lock_irqsave(&scoop_lock, flag);
43         gpio_bit = SCOOP_REG(SCOOP_GPWR) | bit;
44         SCOOP_REG(SCOOP_GPWR) = gpio_bit;
45         spin_unlock_irqrestore(&scoop_lock, flag);
46
47         return gpio_bit;
48 }
49
50 unsigned short reset_scoop_gpio(unsigned short bit)
51 {
52         unsigned short gpio_bit;
53         unsigned long flag;
54
55         spin_lock_irqsave(&scoop_lock, flag);
56         gpio_bit = SCOOP_REG(SCOOP_GPWR) & ~bit;
57         SCOOP_REG(SCOOP_GPWR) = gpio_bit;
58         spin_unlock_irqrestore(&scoop_lock, flag);
59
60         return gpio_bit;
61 }
62
63 EXPORT_SYMBOL(set_scoop_gpio);
64 EXPORT_SYMBOL(reset_scoop_gpio);
65
66 unsigned short read_scoop_reg(unsigned short reg)
67 {
68         return SCOOP_REG(reg);
69 }
70
71 void write_scoop_reg(unsigned short reg, unsigned short data)
72 {
73         SCOOP_REG(reg)=data;
74 }
75
76 EXPORT_SYMBOL(reset_scoop);
77 EXPORT_SYMBOL(read_scoop_reg);
78 EXPORT_SYMBOL(write_scoop_reg);
79
80 static int scoop_suspend(struct device *dev, uint32_t state, uint32_t level)
81 {
82         if (level == SUSPEND_POWER_DOWN) {
83                 scoop_gpwr = SCOOP_REG(SCOOP_GPWR);
84                 SCOOP_REG(SCOOP_GPWR) = 0;
85         }
86         return 0;
87 }
88
89 static int scoop_resume(struct device *dev, uint32_t level)
90 {
91         if (level == RESUME_POWER_ON) {
92                 SCOOP_REG(SCOOP_GPWR) = scoop_gpwr;
93         }
94         return 0;
95 }
96
97 int __init scoop_probe(struct device *dev)
98 {
99         struct scoop_config *inf;
100         struct platform_device *pdev = to_platform_device(dev);
101         struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
102
103         if (!mem)
104                 return -EINVAL;
105
106         inf = dev->platform_data;
107         scoop_io_base = ioremap(mem->start, 0x1000);
108         if (!scoop_io_base)
109                 return -ENOMEM;
110
111         SCOOP_REG(SCOOP_MCR) = 0x0140;
112
113         reset_scoop();
114
115         SCOOP_REG(SCOOP_GPCR) = inf->io_dir & 0xffff;
116         SCOOP_REG(SCOOP_GPWR) = inf->io_out & 0xffff;
117
118         return 0;
119 }
120
121 static struct device_driver scoop_driver = {
122         .name           = "sharp-scoop",
123         .bus            = &platform_bus_type,
124         .probe          = scoop_probe,
125         .suspend        = scoop_suspend,
126         .resume         = scoop_resume,
127 };
128
129 int __init scoop_init(void)
130 {
131         return driver_register(&scoop_driver);
132 }
133
134 subsys_initcall(scoop_init);