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/kernel.h>
14 #include <linux/gpio/machine.h>
15 #include <linux/gpio.h>
16 #include <linux/gpio_keys.h>
17 #include <linux/input.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/partitions.h>
20 #include <linux/platform_data/gpio-htc-egpio.h>
21 #include <linux/platform_data/sa11x0-serial.h>
22 #include <linux/platform_device.h>
23 #include <linux/serial_core.h>
25 #include <asm/mach/flash.h>
26 #include <asm/mach/map.h>
28 #include <mach/h3xxx.h>
29 #include <mach/irqs.h>
36 static struct mtd_partition h3xxx_partitions
[] = {
38 .name
= "H3XXX boot firmware",
41 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
43 .name
= "H3XXX rootfs",
44 .size
= MTDPART_SIZ_FULL
,
49 static void h3xxx_set_vpp(int vpp
)
51 gpio_set_value(H3XXX_EGPIO_VPP_ON
, vpp
);
54 static int h3xxx_flash_init(void)
56 int err
= gpio_request(H3XXX_EGPIO_VPP_ON
, "Flash Vpp");
58 pr_err("%s: can't request H3XXX_EGPIO_VPP_ON\n", __func__
);
62 err
= gpio_direction_output(H3XXX_EGPIO_VPP_ON
, 0);
64 gpio_free(H3XXX_EGPIO_VPP_ON
);
69 static void h3xxx_flash_exit(void)
71 gpio_free(H3XXX_EGPIO_VPP_ON
);
74 static struct flash_platform_data h3xxx_flash_data
= {
75 .map_name
= "cfi_probe",
76 .set_vpp
= h3xxx_set_vpp
,
77 .init
= h3xxx_flash_init
,
78 .exit
= h3xxx_flash_exit
,
79 .parts
= h3xxx_partitions
,
80 .nr_parts
= ARRAY_SIZE(h3xxx_partitions
),
83 static struct resource h3xxx_flash_resource
=
84 DEFINE_RES_MEM(SA1100_CS0_PHYS
, SZ_32M
);
90 static struct gpio h3xxx_uart_gpio
[] = {
91 { H3XXX_GPIO_COM_DCD
, GPIOF_IN
, "COM DCD" },
92 { H3XXX_GPIO_COM_CTS
, GPIOF_IN
, "COM CTS" },
93 { H3XXX_GPIO_COM_RTS
, GPIOF_OUT_INIT_LOW
, "COM RTS" },
96 static bool h3xxx_uart_request_gpios(void)
98 static bool h3xxx_uart_gpio_ok
;
101 if (h3xxx_uart_gpio_ok
)
104 rc
= gpio_request_array(h3xxx_uart_gpio
, ARRAY_SIZE(h3xxx_uart_gpio
));
106 pr_err("h3xxx_uart_request_gpios: error %d\n", rc
);
108 h3xxx_uart_gpio_ok
= true;
110 return h3xxx_uart_gpio_ok
;
113 static void h3xxx_uart_set_mctrl(struct uart_port
*port
, u_int mctrl
)
115 if (port
->mapbase
== _Ser3UTCR0
) {
116 if (!h3xxx_uart_request_gpios())
118 gpio_set_value(H3XXX_GPIO_COM_RTS
, !(mctrl
& TIOCM_RTS
));
122 static u_int
h3xxx_uart_get_mctrl(struct uart_port
*port
)
124 u_int ret
= TIOCM_CD
| TIOCM_CTS
| TIOCM_DSR
;
126 if (port
->mapbase
== _Ser3UTCR0
) {
127 if (!h3xxx_uart_request_gpios())
130 * DCD and CTS bits are inverted in GPLR by RS232 transceiver
132 if (gpio_get_value(H3XXX_GPIO_COM_DCD
))
134 if (gpio_get_value(H3XXX_GPIO_COM_CTS
))
141 static void h3xxx_uart_pm(struct uart_port
*port
, u_int state
, u_int oldstate
)
143 if (port
->mapbase
== _Ser3UTCR0
) {
144 if (!gpio_request(H3XXX_EGPIO_RS232_ON
, "RS232 transceiver")) {
145 gpio_direction_output(H3XXX_EGPIO_RS232_ON
, !state
);
146 gpio_free(H3XXX_EGPIO_RS232_ON
);
148 pr_err("%s: can't request H3XXX_EGPIO_RS232_ON\n",
155 * Enable/Disable wake up events for this serial port.
156 * Obviously, we only support this on the normal COM port.
158 static int h3xxx_uart_set_wake(struct uart_port
*port
, u_int enable
)
162 if (port
->mapbase
== _Ser3UTCR0
) {
164 PWER
|= PWER_GPIO23
| PWER_GPIO25
; /* DCD and CTS */
166 PWER
&= ~(PWER_GPIO23
| PWER_GPIO25
); /* DCD and CTS */
172 static struct sa1100_port_fns h3xxx_port_fns __initdata
= {
173 .set_mctrl
= h3xxx_uart_set_mctrl
,
174 .get_mctrl
= h3xxx_uart_get_mctrl
,
176 .set_wake
= h3xxx_uart_set_wake
,
183 static struct resource egpio_resources
[] = {
184 [0] = DEFINE_RES_MEM(H3600_EGPIO_PHYS
, 0x4),
187 static struct htc_egpio_chip egpio_chips
[] = {
190 .gpio_base
= H3XXX_EGPIO_BASE
,
192 .direction
= HTC_EGPIO_OUTPUT
,
193 .initial_values
= 0x0080, /* H3XXX_EGPIO_RS232_ON */
197 static struct htc_egpio_platform_data egpio_info
= {
201 .num_chips
= ARRAY_SIZE(egpio_chips
),
204 static struct platform_device h3xxx_egpio
= {
207 .resource
= egpio_resources
,
208 .num_resources
= ARRAY_SIZE(egpio_resources
),
210 .platform_data
= &egpio_info
,
218 static struct gpio_keys_button h3xxx_button_table
[] = {
221 .gpio
= H3XXX_GPIO_PWR_BUTTON
,
222 .desc
= "Power Button",
228 .gpio
= H3XXX_GPIO_ACTION_BUTTON
,
230 .desc
= "Action button",
236 static struct gpio_keys_platform_data h3xxx_keys_data
= {
237 .buttons
= h3xxx_button_table
,
238 .nbuttons
= ARRAY_SIZE(h3xxx_button_table
),
241 static struct platform_device h3xxx_keys
= {
245 .platform_data
= &h3xxx_keys_data
,
249 static struct resource h3xxx_micro_resources
[] = {
250 DEFINE_RES_MEM(0x80010000, SZ_4K
),
251 DEFINE_RES_MEM(0x80020000, SZ_4K
),
252 DEFINE_RES_IRQ(IRQ_Ser1UART
),
255 struct platform_device h3xxx_micro_asic
= {
256 .name
= "ipaq-h3xxx-micro",
258 .resource
= h3xxx_micro_resources
,
259 .num_resources
= ARRAY_SIZE(h3xxx_micro_resources
),
262 static struct platform_device
*h3xxx_devices
[] = {
268 static struct gpiod_lookup_table h3xxx_pcmcia_gpio_table
= {
269 .dev_id
= "sa11x0-pcmcia",
271 GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_CD0
,
272 "pcmcia0-detect", GPIO_ACTIVE_LOW
),
273 GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_IRQ0
,
274 "pcmcia0-ready", GPIO_ACTIVE_HIGH
),
275 GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_CD1
,
276 "pcmcia1-detect", GPIO_ACTIVE_LOW
),
277 GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_IRQ1
,
278 "pcmcia1-ready", GPIO_ACTIVE_HIGH
),
283 void __init
h3xxx_mach_init(void)
285 gpiod_add_lookup_table(&h3xxx_pcmcia_gpio_table
);
286 sa1100_register_uart_fns(&h3xxx_port_fns
);
287 sa11x0_register_mtd(&h3xxx_flash_data
, &h3xxx_flash_resource
, 1);
288 platform_add_devices(h3xxx_devices
, ARRAY_SIZE(h3xxx_devices
));
291 static struct map_desc h3600_io_desc
[] __initdata
= {
292 { /* static memory bank 2 CS#2 */
293 .virtual = H3600_BANK_2_VIRT
,
294 .pfn
= __phys_to_pfn(SA1100_CS2_PHYS
),
295 .length
= 0x02800000,
297 }, { /* static memory bank 4 CS#4 */
298 .virtual = H3600_BANK_4_VIRT
,
299 .pfn
= __phys_to_pfn(SA1100_CS4_PHYS
),
300 .length
= 0x00800000,
302 }, { /* EGPIO 0 CS#5 */
303 .virtual = H3600_EGPIO_VIRT
,
304 .pfn
= __phys_to_pfn(H3600_EGPIO_PHYS
),
305 .length
= 0x01000000,
311 * Common map_io initialization
314 void __init
h3xxx_map_io(void)
317 iotable_init(h3600_io_desc
, ARRAY_SIZE(h3600_io_desc
));
319 sa1100_register_uart(0, 3); /* Common serial port */
320 // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
322 /* Ensure those pins are outputs and driving low */
323 PPDR
|= PPC_TXD4
| PPC_SCLK
| PPC_SFRM
;
324 PPSR
&= ~(PPC_TXD4
| PPC_SCLK
| PPC_SFRM
);
326 /* Configure suspend conditions */
331 GPCR
= 0x0fffffff; /* All outputs are set low by default */
332 GPDR
= 0; /* Configure all GPIOs as input */