2 * Support for Compaq iPAQ H3100 and H3600 handheld computers (common code)
4 * Copyright (c) 2000,1 Compaq Computer Corporation. (Author: Jamey Hicks)
5 * Copyright (c) 2009 Dmitry Artamonow <mad_soft@inbox.ru>
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.
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/tty.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>
27 #include <mach/hardware.h>
28 #include <asm/mach-types.h>
29 #include <asm/setup.h>
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>
38 #include <mach/h3xxx.h>
42 void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
45 const char *name = s->name;
50 err = gpio_request(s->gpio, name);
52 printk(KERN_ERR "gpio%u: unable to request: %d\n",
57 err = gpio_direction_output(s->gpio, s->mode);
59 err = gpio_direction_input(s->gpio);
62 printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
76 static struct mtd_partition h3xxx_partitions[] = {
78 .name = "H3XXX boot firmware",
81 .mask_flags = MTD_WRITEABLE, /* force read-only */
83 .name = "H3XXX rootfs",
84 .size = MTDPART_SIZ_FULL,
89 static void h3xxx_set_vpp(int vpp)
91 gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
94 static int h3xxx_flash_init(void)
96 int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
100 err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
102 gpio_free(H3XXX_EGPIO_VPP_ON);
107 static void h3xxx_flash_exit(void)
109 gpio_free(H3XXX_EGPIO_VPP_ON);
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),
121 static struct resource h3xxx_flash_resource = {
122 .start = SA1100_CS0_PHYS,
123 .end = SA1100_CS0_PHYS + SZ_32M - 1,
124 .flags = IORESOURCE_MEM,
131 static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
133 if (port->mapbase == _Ser3UTCR0) {
134 gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
138 static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
140 u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
142 if (port->mapbase == _Ser3UTCR0) {
144 * DCD and CTS bits are inverted in GPLR by RS232 transceiver
146 if (gpio_get_value(H3XXX_GPIO_COM_DCD))
148 if (gpio_get_value(H3XXX_GPIO_COM_CTS))
155 static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
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);
165 * Enable/Disable wake up events for this serial port.
166 * Obviously, we only support this on the normal COM port.
168 static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
172 if (port->mapbase == _Ser3UTCR0) {
174 PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
176 PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
182 static struct sa1100_port_fns h3xxx_port_fns __initdata = {
183 .set_mctrl = h3xxx_uart_set_mctrl,
184 .get_mctrl = h3xxx_uart_get_mctrl,
186 .set_wake = h3xxx_uart_set_wake,
193 static struct resource egpio_resources[] = {
195 .start = H3600_EGPIO_PHYS,
196 .end = H3600_EGPIO_PHYS + 0x4 - 1,
197 .flags = IORESOURCE_MEM,
201 static struct htc_egpio_chip egpio_chips[] = {
204 .gpio_base = H3XXX_EGPIO_BASE,
206 .direction = HTC_EGPIO_OUTPUT,
207 .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
211 static struct htc_egpio_platform_data egpio_info = {
215 .num_chips = ARRAY_SIZE(egpio_chips),
218 static struct platform_device h3xxx_egpio = {
221 .resource = egpio_resources,
222 .num_resources = ARRAY_SIZE(egpio_resources),
224 .platform_data = &egpio_info,
228 static struct platform_device *h3xxx_devices[] = {
232 void __init h3xxx_mach_init(void)
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));
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,
245 }, { /* static memory bank 4 CS#4 */
246 .virtual = H3600_BANK_4_VIRT,
247 .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
248 .length = 0x00800000,
250 }, { /* EGPIO 0 CS#5 */
251 .virtual = H3600_EGPIO_VIRT,
252 .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
253 .length = 0x01000000,
259 * Common map_io initialization
262 void __init h3xxx_map_io(void)
265 iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
267 sa1100_register_uart(0, 3); /* Common serial port */
268 // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
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);
274 /* Configure suspend conditions */
280 GPCR = 0x0fffffff; /* All outputs are set low by default */
281 GPDR = 0; /* Configure all GPIOs as input */