blob: a7a1982d84118764a1ef9a7febc418f22d14f576 [file] [log] [blame]
Dmitry Artamonow86e5e382009-11-27 12:10:55 +01001/*
Dmitry Artamonow6e23fcb2009-11-27 12:11:48 +01002 * Support for Compaq iPAQ H3100 and H3600 handheld computers (common code)
Dmitry Artamonow86e5e382009-11-27 12:10:55 +01003 *
Dmitry Artamonow6e23fcb2009-11-27 12:11:48 +01004 * Copyright (c) 2000,1 Compaq Computer Corporation. (Author: Jamey Hicks)
5 * Copyright (c) 2009 Dmitry Artamonow <mad_soft@inbox.ru>
Dmitry Artamonow86e5e382009-11-27 12:10:55 +01006 *
Dmitry Artamonow6e23fcb2009-11-27 12:11:48 +01007 * 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.
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010010 *
11 */
Dmitry Artamonow6e23fcb2009-11-27 12:11:48 +010012
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010013#include <linux/kernel.h>
Dmitry Artamonow4aa97552009-11-27 12:12:25 +010014#include <linux/gpio.h>
Dmitry Artamonowc463eb62009-11-27 12:13:01 +010015#include <linux/gpio_keys.h>
16#include <linux/input.h>
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010017#include <linux/mfd/htc-egpio.h>
18#include <linux/mtd/mtd.h>
19#include <linux/mtd/partitions.h>
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010020#include <linux/platform_device.h>
Dmitry Artamonow4aa97552009-11-27 12:12:25 +010021#include <linux/serial_core.h>
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010022
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010023#include <asm/mach/flash.h>
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010024#include <asm/mach/map.h>
25#include <asm/mach/serial_sa1100.h>
26
27#include <mach/h3xxx.h>
28
29#include "generic.h"
30
31void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
32{
33 while (n--) {
34 const char *name = s->name;
35 int err;
36
37 if (!name)
38 name = "[init]";
39 err = gpio_request(s->gpio, name);
40 if (err) {
41 printk(KERN_ERR "gpio%u: unable to request: %d\n",
42 s->gpio, err);
43 continue;
44 }
45 if (s->mode >= 0) {
46 err = gpio_direction_output(s->gpio, s->mode);
47 } else {
48 err = gpio_direction_input(s->gpio);
49 }
50 if (err) {
51 printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
52 s->gpio, err);
53 continue;
54 }
55 if (!s->name)
56 gpio_free(s->gpio);
57 s++;
58 }
59}
60
61
62/*
63 * H3xxx flash support
64 */
65static struct mtd_partition h3xxx_partitions[] = {
66 {
67 .name = "H3XXX boot firmware",
68 .size = 0x00040000,
69 .offset = 0,
70 .mask_flags = MTD_WRITEABLE, /* force read-only */
71 }, {
72 .name = "H3XXX rootfs",
73 .size = MTDPART_SIZ_FULL,
74 .offset = 0x00040000,
75 }
76};
77
78static void h3xxx_set_vpp(int vpp)
79{
80 gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
81}
82
83static int h3xxx_flash_init(void)
84{
85 int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
86 if (err)
87 return err;
88
89 err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
90 if (err)
91 gpio_free(H3XXX_EGPIO_VPP_ON);
92
93 return err;
94}
95
96static void h3xxx_flash_exit(void)
97{
98 gpio_free(H3XXX_EGPIO_VPP_ON);
99}
100
101static struct flash_platform_data h3xxx_flash_data = {
102 .map_name = "cfi_probe",
103 .set_vpp = h3xxx_set_vpp,
104 .init = h3xxx_flash_init,
105 .exit = h3xxx_flash_exit,
106 .parts = h3xxx_partitions,
107 .nr_parts = ARRAY_SIZE(h3xxx_partitions),
108};
109
110static struct resource h3xxx_flash_resource = {
111 .start = SA1100_CS0_PHYS,
112 .end = SA1100_CS0_PHYS + SZ_32M - 1,
113 .flags = IORESOURCE_MEM,
114};
115
116
117/*
118 * H3xxx uart support
119 */
120static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
121{
122 if (port->mapbase == _Ser3UTCR0) {
123 gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
124 }
125}
126
127static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
128{
129 u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
130
131 if (port->mapbase == _Ser3UTCR0) {
132 /*
133 * DCD and CTS bits are inverted in GPLR by RS232 transceiver
134 */
135 if (gpio_get_value(H3XXX_GPIO_COM_DCD))
136 ret &= ~TIOCM_CD;
137 if (gpio_get_value(H3XXX_GPIO_COM_CTS))
138 ret &= ~TIOCM_CTS;
139 }
140
141 return ret;
142}
143
144static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
145{
146 if (port->mapbase == _Ser3UTCR0)
147 if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
148 gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
149 gpio_free(H3XXX_EGPIO_RS232_ON);
150 }
151}
152
153/*
154 * Enable/Disable wake up events for this serial port.
155 * Obviously, we only support this on the normal COM port.
156 */
157static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
158{
159 int err = -EINVAL;
160
161 if (port->mapbase == _Ser3UTCR0) {
162 if (enable)
163 PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
164 else
165 PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
166 err = 0;
167 }
168 return err;
169}
170
171static struct sa1100_port_fns h3xxx_port_fns __initdata = {
172 .set_mctrl = h3xxx_uart_set_mctrl,
173 .get_mctrl = h3xxx_uart_get_mctrl,
174 .pm = h3xxx_uart_pm,
175 .set_wake = h3xxx_uart_set_wake,
176};
177
178/*
179 * EGPIO
180 */
181
182static struct resource egpio_resources[] = {
183 [0] = {
184 .start = H3600_EGPIO_PHYS,
185 .end = H3600_EGPIO_PHYS + 0x4 - 1,
186 .flags = IORESOURCE_MEM,
187 },
188};
189
190static struct htc_egpio_chip egpio_chips[] = {
191 [0] = {
192 .reg_start = 0,
193 .gpio_base = H3XXX_EGPIO_BASE,
194 .num_gpios = 16,
195 .direction = HTC_EGPIO_OUTPUT,
196 .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
197 },
198};
199
200static struct htc_egpio_platform_data egpio_info = {
201 .reg_width = 16,
202 .bus_width = 16,
203 .chip = egpio_chips,
204 .num_chips = ARRAY_SIZE(egpio_chips),
205};
206
207static struct platform_device h3xxx_egpio = {
208 .name = "htc-egpio",
209 .id = -1,
210 .resource = egpio_resources,
211 .num_resources = ARRAY_SIZE(egpio_resources),
212 .dev = {
213 .platform_data = &egpio_info,
214 },
215};
216
Dmitry Artamonowc463eb62009-11-27 12:13:01 +0100217/*
218 * GPIO keys
219 */
220
221static struct gpio_keys_button h3xxx_button_table[] = {
222 {
223 .code = KEY_POWER,
224 .gpio = H3XXX_GPIO_PWR_BUTTON,
225 .desc = "Power Button",
226 .active_low = 1,
227 .type = EV_KEY,
228 .wakeup = 1,
229 }, {
230 .code = KEY_ENTER,
231 .gpio = H3XXX_GPIO_ACTION_BUTTON,
232 .active_low = 1,
233 .desc = "Action button",
234 .type = EV_KEY,
235 .wakeup = 0,
236 },
237};
238
239static struct gpio_keys_platform_data h3xxx_keys_data = {
240 .buttons = h3xxx_button_table,
241 .nbuttons = ARRAY_SIZE(h3xxx_button_table),
242};
243
244static struct platform_device h3xxx_keys = {
245 .name = "gpio-keys",
246 .id = -1,
247 .dev = {
248 .platform_data = &h3xxx_keys_data,
249 },
250};
251
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100252static struct platform_device *h3xxx_devices[] = {
253 &h3xxx_egpio,
Dmitry Artamonowc463eb62009-11-27 12:13:01 +0100254 &h3xxx_keys,
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100255};
256
257void __init h3xxx_mach_init(void)
258{
259 sa1100_register_uart_fns(&h3xxx_port_fns);
260 sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
261 platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
262}
263
264static struct map_desc h3600_io_desc[] __initdata = {
265 { /* static memory bank 2 CS#2 */
266 .virtual = H3600_BANK_2_VIRT,
267 .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
268 .length = 0x02800000,
269 .type = MT_DEVICE
270 }, { /* static memory bank 4 CS#4 */
271 .virtual = H3600_BANK_4_VIRT,
272 .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
273 .length = 0x00800000,
274 .type = MT_DEVICE
275 }, { /* EGPIO 0 CS#5 */
276 .virtual = H3600_EGPIO_VIRT,
277 .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
278 .length = 0x01000000,
279 .type = MT_DEVICE
280 }
281};
282
283/*
284 * Common map_io initialization
285 */
286
287void __init h3xxx_map_io(void)
288{
289 sa1100_map_io();
290 iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
291
292 sa1100_register_uart(0, 3); /* Common serial port */
293// sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
294
295 /* Ensure those pins are outputs and driving low */
296 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
297 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
298
299 /* Configure suspend conditions */
300 PGSR = 0;
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100301 PCFR = PCFR_OPDE;
302 PSDR = 0;
303
304 GPCR = 0x0fffffff; /* All outputs are set low by default */
305 GPDR = 0; /* Configure all GPIOs as input */
306}
307