blob: dd39f90db0dba343e82e6a3e1f15949b6f34f8f4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Hardware definitions for Compaq iPAQ H3xxx Handheld Computers
3 *
4 * Copyright 2000,1 Compaq Computer Corporation.
5 *
6 * Use consistent with the GNU GPL is permitted,
7 * provided that this copyright notice is
8 * preserved in its entirety in all copies and derived works.
9 *
10 * COMPAQ COMPUTER CORPORATION MAKES NO WARRANTIES, EXPRESSED OR IMPLIED,
11 * AS TO THE USEFULNESS OR CORRECTNESS OF THIS CODE OR ITS
12 * FITNESS FOR ANY PARTICULAR PURPOSE.
13 *
14 * Author: Jamey Hicks.
15 *
16 * History:
17 *
18 * 2001-10-?? Andrew Christian Added support for iPAQ H3800
19 * and abstracted EGPIO interface.
20 *
21 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/kernel.h>
25#include <linux/tty.h>
26#include <linux/pm.h>
27#include <linux/device.h>
Dmitry Artamonow2eec62d2009-11-27 12:00:00 +010028#include <linux/mfd/htc-egpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/mtd/mtd.h>
30#include <linux/mtd/partitions.h>
31#include <linux/serial_core.h>
Russell King0831e3e2009-10-06 14:35:16 +010032#include <linux/gpio.h>
Dmitry Artamonow2eec62d2009-11-27 12:00:00 +010033#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010036#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/mach-types.h>
38#include <asm/setup.h>
39
40#include <asm/mach/irq.h>
41#include <asm/mach/arch.h>
42#include <asm/mach/flash.h>
43#include <asm/mach/irda.h>
44#include <asm/mach/map.h>
45#include <asm/mach/serial_sa1100.h>
46
Dmitry Artamonow8715b292009-11-27 12:09:25 +010047#include <mach/h3xxx.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#include "generic.h"
50
Russell King0831e3e2009-10-06 14:35:16 +010051struct gpio_default_state {
52 int gpio;
53 int mode;
54 const char *name;
55};
56
57#define GPIO_MODE_IN -1
58#define GPIO_MODE_OUT0 0
59#define GPIO_MODE_OUT1 1
60
61static void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
62{
63 while (n--) {
64 const char *name = s->name;
65 int err;
66
67 if (!name)
68 name = "[init]";
69 err = gpio_request(s->gpio, name);
70 if (err) {
71 printk(KERN_ERR "gpio%u: unable to request: %d\n",
72 s->gpio, err);
73 continue;
74 }
75 if (s->mode >= 0) {
76 err = gpio_direction_output(s->gpio, s->mode);
77 } else {
78 err = gpio_direction_input(s->gpio);
79 }
80 if (err) {
81 printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
82 s->gpio, err);
83 continue;
84 }
85 if (!s->name)
86 gpio_free(s->gpio);
87 s++;
88 }
89}
90
91
Russell King6e21ee62009-10-06 15:16:27 +010092/*
93 * H3xxx flash support
94 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095static struct mtd_partition h3xxx_partitions[] = {
96 {
97 .name = "H3XXX boot firmware",
98 .size = 0x00040000,
99 .offset = 0,
100 .mask_flags = MTD_WRITEABLE, /* force read-only */
101 }, {
Dmitry Artamonowf110b3f2009-03-15 19:09:50 +0100102 .name = "H3XXX rootfs",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 .size = MTDPART_SIZ_FULL,
104 .offset = 0x00040000,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 }
106};
107
108static void h3xxx_set_vpp(int vpp)
109{
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100110 gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
111}
112
113static int h3xxx_flash_init(void)
114{
115 int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
116 if (err)
117 return err;
118
119 err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
120 if (err)
121 gpio_free(H3XXX_EGPIO_VPP_ON);
122
123 return err;
124}
125
126static void h3xxx_flash_exit(void)
127{
128 gpio_free(H3XXX_EGPIO_VPP_ON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
131static struct flash_platform_data h3xxx_flash_data = {
132 .map_name = "cfi_probe",
133 .set_vpp = h3xxx_set_vpp,
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100134 .init = h3xxx_flash_init,
135 .exit = h3xxx_flash_exit,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 .parts = h3xxx_partitions,
137 .nr_parts = ARRAY_SIZE(h3xxx_partitions),
138};
139
140static struct resource h3xxx_flash_resource = {
141 .start = SA1100_CS0_PHYS,
142 .end = SA1100_CS0_PHYS + SZ_32M - 1,
143 .flags = IORESOURCE_MEM,
144};
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147/*
Russell King6e21ee62009-10-06 15:16:27 +0100148 * H3xxx uart support
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 */
Russell King6e21ee62009-10-06 15:16:27 +0100150static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
152 if (port->mapbase == _Ser3UTCR0) {
Russell King6e21ee62009-10-06 15:16:27 +0100153 gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155}
156
Russell King6e21ee62009-10-06 15:16:27 +0100157static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
160
161 if (port->mapbase == _Ser3UTCR0) {
Russell King6e21ee62009-10-06 15:16:27 +0100162 /*
163 * DCD and CTS bits are inverted in GPLR by RS232 transceiver
164 */
165 if (gpio_get_value(H3XXX_GPIO_COM_DCD))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 ret &= ~TIOCM_CD;
Russell King6e21ee62009-10-06 15:16:27 +0100167 if (gpio_get_value(H3XXX_GPIO_COM_CTS))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 ret &= ~TIOCM_CTS;
169 }
170
171 return ret;
172}
173
Russell King6e21ee62009-10-06 15:16:27 +0100174static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
Dmitry Artamonow2a151a02009-11-27 11:10:58 +0100176 if (port->mapbase == _Ser3UTCR0)
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100177 if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
178 gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
179 gpio_free(H3XXX_EGPIO_RS232_ON);
180 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
183/*
184 * Enable/Disable wake up events for this serial port.
185 * Obviously, we only support this on the normal COM port.
186 */
Russell King6e21ee62009-10-06 15:16:27 +0100187static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
189 int err = -EINVAL;
190
191 if (port->mapbase == _Ser3UTCR0) {
192 if (enable)
193 PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
194 else
195 PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
196 err = 0;
197 }
198 return err;
199}
200
Russell King6e21ee62009-10-06 15:16:27 +0100201static struct sa1100_port_fns h3xxx_port_fns __initdata = {
202 .set_mctrl = h3xxx_uart_set_mctrl,
203 .get_mctrl = h3xxx_uart_get_mctrl,
204 .pm = h3xxx_uart_pm,
205 .set_wake = h3xxx_uart_set_wake,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206};
207
Dmitry Artamonow2eec62d2009-11-27 12:00:00 +0100208/*
209 * EGPIO
210 */
211
212static struct resource egpio_resources[] = {
213 [0] = {
214 .start = H3600_EGPIO_PHYS,
215 .end = H3600_EGPIO_PHYS + 0x4 - 1,
216 .flags = IORESOURCE_MEM,
217 },
218};
219
220static struct htc_egpio_chip egpio_chips[] = {
221 [0] = {
222 .reg_start = 0,
223 .gpio_base = H3XXX_EGPIO_BASE,
224 .num_gpios = 16,
225 .direction = HTC_EGPIO_OUTPUT,
226 .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
227 },
228};
229
230static struct htc_egpio_platform_data egpio_info = {
231 .reg_width = 16,
232 .bus_width = 16,
233 .chip = egpio_chips,
234 .num_chips = ARRAY_SIZE(egpio_chips),
235};
236
237static struct platform_device h3xxx_egpio = {
238 .name = "htc-egpio",
239 .id = -1,
240 .resource = egpio_resources,
241 .num_resources = ARRAY_SIZE(egpio_resources),
242 .dev = {
243 .platform_data = &egpio_info,
244 },
245};
246
247static struct platform_device *h3xxx_devices[] = {
248 &h3xxx_egpio,
249};
Russell King6e21ee62009-10-06 15:16:27 +0100250
Dmitry Artamonowe55b20e2009-11-27 11:06:46 +0100251static void __init h3xxx_mach_init(void)
Russell King6e21ee62009-10-06 15:16:27 +0100252{
253 sa1100_register_uart_fns(&h3xxx_port_fns);
254 sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
Dmitry Artamonow2eec62d2009-11-27 12:00:00 +0100255 platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
Russell King6e21ee62009-10-06 15:16:27 +0100256}
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258static struct map_desc h3600_io_desc[] __initdata = {
Deepak Saxena92519d82005-10-28 15:19:04 +0100259 { /* static memory bank 2 CS#2 */
260 .virtual = H3600_BANK_2_VIRT,
261 .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
262 .length = 0x02800000,
263 .type = MT_DEVICE
264 }, { /* static memory bank 4 CS#4 */
265 .virtual = H3600_BANK_4_VIRT,
266 .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
267 .length = 0x00800000,
268 .type = MT_DEVICE
269 }, { /* EGPIO 0 CS#5 */
270 .virtual = H3600_EGPIO_VIRT,
271 .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
272 .length = 0x01000000,
273 .type = MT_DEVICE
274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275};
276
277/*
278 * Common map_io initialization
279 */
280
281static void __init h3xxx_map_io(void)
282{
283 sa1100_map_io();
284 iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 sa1100_register_uart(0, 3); /* Common serial port */
287// sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
288
289 /* Ensure those pins are outputs and driving low */
290 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
291 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
292
293 /* Configure suspend conditions */
294 PGSR = 0;
Russell King0fb85a52009-10-06 16:40:24 +0100295 PWER = PWER_GPIO0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 PCFR = PCFR_OPDE;
297 PSDR = 0;
298
Dmitry Artamonow51834902009-11-27 12:07:11 +0100299 GPCR = 0x0fffffff; /* All outputs are set low by default */
300 GPDR = 0; /* Configure all GPIOs as input */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303/************************* H3100 *************************/
304
305#ifdef CONFIG_SA1100_H3100
306
Dmitry Artamonowcf5a87d2009-11-27 11:58:35 +0100307/*
308 * helper for sa1100fb
309 */
310static void h3100_lcd_power(int enable)
311{
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100312 if (!gpio_request(H3XXX_EGPIO_LCD_ON, "LCD ON")) {
313 gpio_set_value(H3100_GPIO_LCD_3V_ON, enable);
314 gpio_direction_output(H3XXX_EGPIO_LCD_ON, enable);
315 gpio_free(H3XXX_EGPIO_LCD_ON);
316 }
Dmitry Artamonowcf5a87d2009-11-27 11:58:35 +0100317}
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320static void __init h3100_map_io(void)
321{
322 h3xxx_map_io();
323
Dmitry Artamonowcf5a87d2009-11-27 11:58:35 +0100324 sa1100fb_lcd_power = h3100_lcd_power;
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 /* Older bootldrs put GPIO2-9 in alternate mode on the
327 assumption that they are used for video */
Dmitry Artamonow51834902009-11-27 12:07:11 +0100328 GAFR &= ~0x000001fb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329}
330
Russell Kinga5d176a2009-10-06 14:22:23 +0100331/*
332 * This turns the IRDA power on or off on the Compaq H3100
333 */
334static int h3100_irda_set_power(struct device *dev, unsigned int state)
335{
Russell King9c196f02009-10-06 14:36:05 +0100336 gpio_set_value(H3100_GPIO_IR_ON, state);
Russell Kinga5d176a2009-10-06 14:22:23 +0100337 return 0;
338}
339
340static void h3100_irda_set_speed(struct device *dev, unsigned int speed)
341{
Russell King9c196f02009-10-06 14:36:05 +0100342 gpio_set_value(H3100_GPIO_IR_FSEL, !(speed < 4000000));
Russell Kinga5d176a2009-10-06 14:22:23 +0100343}
344
345static struct irda_platform_data h3100_irda_data = {
346 .set_power = h3100_irda_set_power,
347 .set_speed = h3100_irda_set_speed,
348};
349
Russell King9c196f02009-10-06 14:36:05 +0100350static struct gpio_default_state h3100_default_gpio[] = {
351 { H3100_GPIO_IR_ON, GPIO_MODE_OUT0, "IrDA power" },
352 { H3100_GPIO_IR_FSEL, GPIO_MODE_OUT0, "IrDA fsel" },
Russell King6e21ee62009-10-06 15:16:27 +0100353 { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
354 { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
355 { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100356 { H3100_GPIO_LCD_3V_ON, GPIO_MODE_OUT0, "LCD 3v" },
Russell King9c196f02009-10-06 14:36:05 +0100357};
358
Dmitry Artamonowe55b20e2009-11-27 11:06:46 +0100359static void __init h3100_mach_init(void)
Russell King898e8102009-10-06 14:19:44 +0100360{
Russell King9c196f02009-10-06 14:36:05 +0100361 h3xxx_init_gpio(h3100_default_gpio, ARRAY_SIZE(h3100_default_gpio));
Russell King898e8102009-10-06 14:19:44 +0100362 h3xxx_mach_init();
Russell Kinga5d176a2009-10-06 14:22:23 +0100363 sa11x0_register_irda(&h3100_irda_data);
Russell King898e8102009-10-06 14:19:44 +0100364}
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366MACHINE_START(H3100, "Compaq iPAQ H3100")
Russell Kinge9dea0c2005-07-03 17:38:58 +0100367 .phys_io = 0x80000000,
368 .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
369 .boot_params = 0xc0000100,
370 .map_io = h3100_map_io,
371 .init_irq = sa1100_init_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 .timer = &sa1100_timer,
Russell King898e8102009-10-06 14:19:44 +0100373 .init_machine = h3100_mach_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374MACHINE_END
375
376#endif /* CONFIG_SA1100_H3100 */
377
378/************************* H3600 *************************/
379
380#ifdef CONFIG_SA1100_H3600
381
Dmitry Artamonowcf5a87d2009-11-27 11:58:35 +0100382/*
383 * helper for sa1100fb
384 */
385static void h3600_lcd_power(int enable)
386{
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100387 if (gpio_request(H3XXX_EGPIO_LCD_ON, "LCD power"))
388 goto err1;
389 if (gpio_request(H3600_EGPIO_LCD_PCI, "LCD control"))
390 goto err2;
391 if (gpio_request(H3600_EGPIO_LCD_5V_ON, "LCD 5v"))
392 goto err3;
393 if (gpio_request(H3600_EGPIO_LVDD_ON, "LCD 9v/-6.5v"))
394 goto err4;
395
396 gpio_direction_output(H3XXX_EGPIO_LCD_ON, enable);
397 gpio_direction_output(H3600_EGPIO_LCD_PCI, enable);
398 gpio_direction_output(H3600_EGPIO_LCD_5V_ON, enable);
399 gpio_direction_output(H3600_EGPIO_LVDD_ON, enable);
400
401 gpio_free(H3600_EGPIO_LVDD_ON);
402err4: gpio_free(H3600_EGPIO_LCD_5V_ON);
403err3: gpio_free(H3600_EGPIO_LCD_PCI);
404err2: gpio_free(H3XXX_EGPIO_LCD_ON);
405err1: return;
Dmitry Artamonowcf5a87d2009-11-27 11:58:35 +0100406}
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408static void __init h3600_map_io(void)
409{
410 h3xxx_map_io();
411
Dmitry Artamonowcf5a87d2009-11-27 11:58:35 +0100412 sa1100fb_lcd_power = h3600_lcd_power;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
Russell Kinga5d176a2009-10-06 14:22:23 +0100415/*
416 * This turns the IRDA power on or off on the Compaq H3600
417 */
418static int h3600_irda_set_power(struct device *dev, unsigned int state)
419{
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100420 gpio_set_value(H3600_EGPIO_IR_ON, state);
Russell Kinga5d176a2009-10-06 14:22:23 +0100421 return 0;
422}
423
424static void h3600_irda_set_speed(struct device *dev, unsigned int speed)
425{
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100426 gpio_set_value(H3600_EGPIO_IR_FSEL, !(speed < 4000000));
427}
428
429static int h3600_irda_startup(struct device *dev)
430{
431 int err = gpio_request(H3600_EGPIO_IR_ON, "IrDA power");
432 if (err)
433 goto err1;
434 err = gpio_direction_output(H3600_EGPIO_IR_ON, 0);
435 if (err)
436 goto err2;
437 err = gpio_request(H3600_EGPIO_IR_FSEL, "IrDA fsel");
438 if (err)
439 goto err2;
440 err = gpio_direction_output(H3600_EGPIO_IR_FSEL, 0);
441 if (err)
442 goto err3;
443 return 0;
444
445err3: gpio_free(H3600_EGPIO_IR_FSEL);
446err2: gpio_free(H3600_EGPIO_IR_ON);
447err1: return err;
448}
449
450static void h3600_irda_shutdown(struct device *dev)
451{
452 gpio_free(H3600_EGPIO_IR_ON);
453 gpio_free(H3600_EGPIO_IR_FSEL);
Russell Kinga5d176a2009-10-06 14:22:23 +0100454}
455
456static struct irda_platform_data h3600_irda_data = {
457 .set_power = h3600_irda_set_power,
458 .set_speed = h3600_irda_set_speed,
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100459 .startup = h3600_irda_startup,
460 .shutdown = h3600_irda_shutdown,
Russell Kinga5d176a2009-10-06 14:22:23 +0100461};
462
Russell King6e21ee62009-10-06 15:16:27 +0100463static struct gpio_default_state h3600_default_gpio[] = {
464 { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
465 { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
466 { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
467};
468
Dmitry Artamonowe55b20e2009-11-27 11:06:46 +0100469static void __init h3600_mach_init(void)
Russell King898e8102009-10-06 14:19:44 +0100470{
Russell King6e21ee62009-10-06 15:16:27 +0100471 h3xxx_init_gpio(h3600_default_gpio, ARRAY_SIZE(h3600_default_gpio));
Russell King898e8102009-10-06 14:19:44 +0100472 h3xxx_mach_init();
Russell Kinga5d176a2009-10-06 14:22:23 +0100473 sa11x0_register_irda(&h3600_irda_data);
Russell King898e8102009-10-06 14:19:44 +0100474}
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476MACHINE_START(H3600, "Compaq iPAQ H3600")
Russell Kinge9dea0c2005-07-03 17:38:58 +0100477 .phys_io = 0x80000000,
478 .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
479 .boot_params = 0xc0000100,
480 .map_io = h3600_map_io,
481 .init_irq = sa1100_init_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 .timer = &sa1100_timer,
Russell King898e8102009-10-06 14:19:44 +0100483 .init_machine = h3600_mach_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484MACHINE_END
485
486#endif /* CONFIG_SA1100_H3600 */
487