1 // SPDX-License-Identifier: GPL-2.0-only
3 * Support for Compaq iPAQ H3100 and H3600 handheld computers (common code)
5 * Copyright (c) 2000,1 Compaq Computer Corporation. (Author: Jamey Hicks)
6 * Copyright (c) 2009 Dmitry Artamonow <mad_soft@inbox.ru>
9 #include <linux/kernel.h>
10 #include <linux/gpio/machine.h>
11 #include <linux/gpio.h>
12 #include <linux/gpio_keys.h>
13 #include <linux/input.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/partitions.h>
16 #include <linux/platform_data/gpio-htc-egpio.h>
17 #include <linux/platform_data/sa11x0-serial.h>
18 #include <linux/platform_device.h>
19 #include <linux/serial_core.h>
21 #include <asm/mach/flash.h>
22 #include <asm/mach/map.h>
24 #include <mach/h3xxx.h>
25 #include <mach/irqs.h>
32 static struct mtd_partition h3xxx_partitions[] = {
34 .name = "H3XXX boot firmware",
37 .mask_flags = MTD_WRITEABLE, /* force read-only */
39 .name = "H3XXX rootfs",
40 .size = MTDPART_SIZ_FULL,
45 static void h3xxx_set_vpp(int vpp)
47 gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
50 static int h3xxx_flash_init(void)
52 int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
54 pr_err("%s: can't request H3XXX_EGPIO_VPP_ON\n", __func__);
58 err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
60 gpio_free(H3XXX_EGPIO_VPP_ON);
65 static void h3xxx_flash_exit(void)
67 gpio_free(H3XXX_EGPIO_VPP_ON);
70 static struct flash_platform_data h3xxx_flash_data = {
71 .map_name = "cfi_probe",
72 .set_vpp = h3xxx_set_vpp,
73 .init = h3xxx_flash_init,
74 .exit = h3xxx_flash_exit,
75 .parts = h3xxx_partitions,
76 .nr_parts = ARRAY_SIZE(h3xxx_partitions),
79 static struct resource h3xxx_flash_resource =
80 DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M);
86 static struct gpio h3xxx_uart_gpio[] = {
87 { H3XXX_GPIO_COM_DCD, GPIOF_IN, "COM DCD" },
88 { H3XXX_GPIO_COM_CTS, GPIOF_IN, "COM CTS" },
89 { H3XXX_GPIO_COM_RTS, GPIOF_OUT_INIT_LOW, "COM RTS" },
92 static bool h3xxx_uart_request_gpios(void)
94 static bool h3xxx_uart_gpio_ok;
97 if (h3xxx_uart_gpio_ok)
100 rc = gpio_request_array(h3xxx_uart_gpio, ARRAY_SIZE(h3xxx_uart_gpio));
102 pr_err("h3xxx_uart_request_gpios: error %d\n", rc);
104 h3xxx_uart_gpio_ok = true;
106 return h3xxx_uart_gpio_ok;
109 static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
111 if (port->mapbase == _Ser3UTCR0) {
112 if (!h3xxx_uart_request_gpios())
114 gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
118 static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
120 u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
122 if (port->mapbase == _Ser3UTCR0) {
123 if (!h3xxx_uart_request_gpios())
126 * DCD and CTS bits are inverted in GPLR by RS232 transceiver
128 if (gpio_get_value(H3XXX_GPIO_COM_DCD))
130 if (gpio_get_value(H3XXX_GPIO_COM_CTS))
137 static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
139 if (port->mapbase == _Ser3UTCR0) {
140 if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
141 gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
142 gpio_free(H3XXX_EGPIO_RS232_ON);
144 pr_err("%s: can't request H3XXX_EGPIO_RS232_ON\n",
151 * Enable/Disable wake up events for this serial port.
152 * Obviously, we only support this on the normal COM port.
154 static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
158 if (port->mapbase == _Ser3UTCR0) {
160 PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
162 PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
168 static struct sa1100_port_fns h3xxx_port_fns __initdata = {
169 .set_mctrl = h3xxx_uart_set_mctrl,
170 .get_mctrl = h3xxx_uart_get_mctrl,
172 .set_wake = h3xxx_uart_set_wake,
179 static struct resource egpio_resources[] = {
180 [0] = DEFINE_RES_MEM(H3600_EGPIO_PHYS, 0x4),
183 static struct htc_egpio_chip egpio_chips[] = {
186 .gpio_base = H3XXX_EGPIO_BASE,
188 .direction = HTC_EGPIO_OUTPUT,
189 .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
193 static struct htc_egpio_platform_data egpio_info = {
197 .num_chips = ARRAY_SIZE(egpio_chips),
200 static struct platform_device h3xxx_egpio = {
203 .resource = egpio_resources,
204 .num_resources = ARRAY_SIZE(egpio_resources),
206 .platform_data = &egpio_info,
214 static struct gpio_keys_button h3xxx_button_table[] = {
217 .gpio = H3XXX_GPIO_PWR_BUTTON,
218 .desc = "Power Button",
224 .gpio = H3XXX_GPIO_ACTION_BUTTON,
226 .desc = "Action button",
232 static struct gpio_keys_platform_data h3xxx_keys_data = {
233 .buttons = h3xxx_button_table,
234 .nbuttons = ARRAY_SIZE(h3xxx_button_table),
237 static struct platform_device h3xxx_keys = {
241 .platform_data = &h3xxx_keys_data,
245 static struct resource h3xxx_micro_resources[] = {
246 DEFINE_RES_MEM(0x80010000, SZ_4K),
247 DEFINE_RES_MEM(0x80020000, SZ_4K),
248 DEFINE_RES_IRQ(IRQ_Ser1UART),
251 struct platform_device h3xxx_micro_asic = {
252 .name = "ipaq-h3xxx-micro",
254 .resource = h3xxx_micro_resources,
255 .num_resources = ARRAY_SIZE(h3xxx_micro_resources),
258 static struct platform_device *h3xxx_devices[] = {
264 static struct gpiod_lookup_table h3xxx_pcmcia_gpio_table = {
265 .dev_id = "sa11x0-pcmcia",
267 GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_CD0,
268 "pcmcia0-detect", GPIO_ACTIVE_LOW),
269 GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_IRQ0,
270 "pcmcia0-ready", GPIO_ACTIVE_HIGH),
271 GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_CD1,
272 "pcmcia1-detect", GPIO_ACTIVE_LOW),
273 GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_IRQ1,
274 "pcmcia1-ready", GPIO_ACTIVE_HIGH),
279 void __init h3xxx_mach_init(void)
281 gpiod_add_lookup_table(&h3xxx_pcmcia_gpio_table);
282 sa1100_register_uart_fns(&h3xxx_port_fns);
283 sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
284 platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
287 static struct map_desc h3600_io_desc[] __initdata = {
288 { /* static memory bank 2 CS#2 */
289 .virtual = H3600_BANK_2_VIRT,
290 .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
291 .length = 0x02800000,
293 }, { /* static memory bank 4 CS#4 */
294 .virtual = H3600_BANK_4_VIRT,
295 .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
296 .length = 0x00800000,
298 }, { /* EGPIO 0 CS#5 */
299 .virtual = H3600_EGPIO_VIRT,
300 .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
301 .length = 0x01000000,
307 * Common map_io initialization
310 void __init h3xxx_map_io(void)
313 iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
315 sa1100_register_uart(0, 3); /* Common serial port */
316 // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
318 /* Ensure those pins are outputs and driving low */
319 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
320 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
322 /* Configure suspend conditions */
327 GPCR = 0x0fffffff; /* All outputs are set low by default */
328 GPDR = 0; /* Configure all GPIOs as input */