]> bbs.cooldavid.org Git - net-next-2.6.git/blob - arch/arm/mach-sa1100/h3xxx.c
ARM: 5821/1: SA1100: h3100/h3600: revise copyright boilerplates
[net-next-2.6.git] / arch / arm / mach-sa1100 / h3xxx.c
1 /*
2  * Support for Compaq iPAQ H3100 and H3600 handheld computers (common code)
3  *
4  * Copyright (c) 2000,1 Compaq Computer Corporation. (Author: Jamey Hicks)
5  * Copyright (c) 2009 Dmitry Artamonow <mad_soft@inbox.ru>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  */
12
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/tty.h>
17 #include <linux/pm.h>
18 #include <linux/device.h>
19 #include <linux/mfd/htc-egpio.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/partitions.h>
22 #include <linux/serial_core.h>
23 #include <linux/gpio.h>
24 #include <linux/platform_device.h>
25
26 #include <asm/irq.h>
27 #include <mach/hardware.h>
28 #include <asm/mach-types.h>
29 #include <asm/setup.h>
30
31 #include <asm/mach/irq.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/flash.h>
34 #include <asm/mach/irda.h>
35 #include <asm/mach/map.h>
36 #include <asm/mach/serial_sa1100.h>
37
38 #include <mach/h3xxx.h>
39
40 #include "generic.h"
41
42 void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
43 {
44         while (n--) {
45                 const char *name = s->name;
46                 int err;
47
48                 if (!name)
49                         name = "[init]";
50                 err = gpio_request(s->gpio, name);
51                 if (err) {
52                         printk(KERN_ERR "gpio%u: unable to request: %d\n",
53                                 s->gpio, err);
54                         continue;
55                 }
56                 if (s->mode >= 0) {
57                         err = gpio_direction_output(s->gpio, s->mode);
58                 } else {
59                         err = gpio_direction_input(s->gpio);
60                 }
61                 if (err) {
62                         printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
63                                 s->gpio, err);
64                         continue;
65                 }
66                 if (!s->name)
67                         gpio_free(s->gpio);
68                 s++;
69         }
70 }
71
72
73 /*
74  * H3xxx flash support
75  */
76 static struct mtd_partition h3xxx_partitions[] = {
77         {
78                 .name           = "H3XXX boot firmware",
79                 .size           = 0x00040000,
80                 .offset         = 0,
81                 .mask_flags     = MTD_WRITEABLE,  /* force read-only */
82         }, {
83                 .name           = "H3XXX rootfs",
84                 .size           = MTDPART_SIZ_FULL,
85                 .offset         = 0x00040000,
86         }
87 };
88
89 static void h3xxx_set_vpp(int vpp)
90 {
91         gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
92 }
93
94 static int h3xxx_flash_init(void)
95 {
96         int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
97         if (err)
98                 return err;
99
100         err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
101         if (err)
102                 gpio_free(H3XXX_EGPIO_VPP_ON);
103
104         return err;
105 }
106
107 static void h3xxx_flash_exit(void)
108 {
109         gpio_free(H3XXX_EGPIO_VPP_ON);
110 }
111
112 static struct flash_platform_data h3xxx_flash_data = {
113         .map_name       = "cfi_probe",
114         .set_vpp        = h3xxx_set_vpp,
115         .init           = h3xxx_flash_init,
116         .exit           = h3xxx_flash_exit,
117         .parts          = h3xxx_partitions,
118         .nr_parts       = ARRAY_SIZE(h3xxx_partitions),
119 };
120
121 static struct resource h3xxx_flash_resource = {
122         .start          = SA1100_CS0_PHYS,
123         .end            = SA1100_CS0_PHYS + SZ_32M - 1,
124         .flags          = IORESOURCE_MEM,
125 };
126
127
128 /*
129  * H3xxx uart support
130  */
131 static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
132 {
133         if (port->mapbase == _Ser3UTCR0) {
134                 gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
135         }
136 }
137
138 static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
139 {
140         u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
141
142         if (port->mapbase == _Ser3UTCR0) {
143                 /*
144                  * DCD and CTS bits are inverted in GPLR by RS232 transceiver
145                  */
146                 if (gpio_get_value(H3XXX_GPIO_COM_DCD))
147                         ret &= ~TIOCM_CD;
148                 if (gpio_get_value(H3XXX_GPIO_COM_CTS))
149                         ret &= ~TIOCM_CTS;
150         }
151
152         return ret;
153 }
154
155 static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
156 {
157         if (port->mapbase == _Ser3UTCR0)
158                 if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
159                         gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
160                         gpio_free(H3XXX_EGPIO_RS232_ON);
161                 }
162 }
163
164 /*
165  * Enable/Disable wake up events for this serial port.
166  * Obviously, we only support this on the normal COM port.
167  */
168 static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
169 {
170         int err = -EINVAL;
171
172         if (port->mapbase == _Ser3UTCR0) {
173                 if (enable)
174                         PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
175                 else
176                         PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
177                 err = 0;
178         }
179         return err;
180 }
181
182 static struct sa1100_port_fns h3xxx_port_fns __initdata = {
183         .set_mctrl      = h3xxx_uart_set_mctrl,
184         .get_mctrl      = h3xxx_uart_get_mctrl,
185         .pm             = h3xxx_uart_pm,
186         .set_wake       = h3xxx_uart_set_wake,
187 };
188
189 /*
190  * EGPIO
191  */
192
193 static struct resource egpio_resources[] = {
194         [0] = {
195                 .start  = H3600_EGPIO_PHYS,
196                 .end    = H3600_EGPIO_PHYS + 0x4 - 1,
197                 .flags  = IORESOURCE_MEM,
198         },
199 };
200
201 static struct htc_egpio_chip egpio_chips[] = {
202         [0] = {
203                 .reg_start      = 0,
204                 .gpio_base      = H3XXX_EGPIO_BASE,
205                 .num_gpios      = 16,
206                 .direction      = HTC_EGPIO_OUTPUT,
207                 .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
208         },
209 };
210
211 static struct htc_egpio_platform_data egpio_info = {
212         .reg_width      = 16,
213         .bus_width      = 16,
214         .chip           = egpio_chips,
215         .num_chips      = ARRAY_SIZE(egpio_chips),
216 };
217
218 static struct platform_device h3xxx_egpio = {
219         .name           = "htc-egpio",
220         .id             = -1,
221         .resource       = egpio_resources,
222         .num_resources  = ARRAY_SIZE(egpio_resources),
223         .dev            = {
224                 .platform_data = &egpio_info,
225         },
226 };
227
228 static struct platform_device *h3xxx_devices[] = {
229         &h3xxx_egpio,
230 };
231
232 void __init h3xxx_mach_init(void)
233 {
234         sa1100_register_uart_fns(&h3xxx_port_fns);
235         sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
236         platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
237 }
238
239 static struct map_desc h3600_io_desc[] __initdata = {
240         {       /* static memory bank 2  CS#2 */
241                 .virtual        =  H3600_BANK_2_VIRT,
242                 .pfn            = __phys_to_pfn(SA1100_CS2_PHYS),
243                 .length         = 0x02800000,
244                 .type           = MT_DEVICE
245         }, {    /* static memory bank 4  CS#4 */
246                 .virtual        =  H3600_BANK_4_VIRT,
247                 .pfn            = __phys_to_pfn(SA1100_CS4_PHYS),
248                 .length         = 0x00800000,
249                 .type           = MT_DEVICE
250         }, {    /* EGPIO 0              CS#5 */
251                 .virtual        =  H3600_EGPIO_VIRT,
252                 .pfn            = __phys_to_pfn(H3600_EGPIO_PHYS),
253                 .length         = 0x01000000,
254                 .type           = MT_DEVICE
255         }
256 };
257
258 /*
259  * Common map_io initialization
260  */
261
262 void __init h3xxx_map_io(void)
263 {
264         sa1100_map_io();
265         iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
266
267         sa1100_register_uart(0, 3); /* Common serial port */
268 //      sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
269
270         /* Ensure those pins are outputs and driving low  */
271         PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
272         PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
273
274         /* Configure suspend conditions */
275         PGSR = 0;
276         PWER = PWER_GPIO0;
277         PCFR = PCFR_OPDE;
278         PSDR = 0;
279
280         GPCR = 0x0fffffff;      /* All outputs are set low by default */
281         GPDR = 0;               /* Configure all GPIOs as input */
282 }
283