1*d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
286e5e38cSDmitry Artamonow /*
36e23fcb3SDmitry Artamonow * Support for Compaq iPAQ H3100 and H3600 handheld computers (common code)
486e5e38cSDmitry Artamonow *
56e23fcb3SDmitry Artamonow * Copyright (c) 2000,1 Compaq Computer Corporation. (Author: Jamey Hicks)
66e23fcb3SDmitry Artamonow * Copyright (c) 2009 Dmitry Artamonow <mad_soft@inbox.ru>
786e5e38cSDmitry Artamonow */
86e23fcb3SDmitry Artamonow
986e5e38cSDmitry Artamonow #include <linux/kernel.h>
10a00315d1SRussell King #include <linux/gpio/machine.h>
114aa97555SDmitry Artamonow #include <linux/gpio.h>
12c463eb62SDmitry Artamonow #include <linux/gpio_keys.h>
13c463eb62SDmitry Artamonow #include <linux/input.h>
1486e5e38cSDmitry Artamonow #include <linux/mtd/mtd.h>
1586e5e38cSDmitry Artamonow #include <linux/mtd/partitions.h>
163c6e8d05SLinus Walleij #include <linux/platform_data/gpio-htc-egpio.h>
176920b5a7SRussell King #include <linux/platform_data/sa11x0-serial.h>
1886e5e38cSDmitry Artamonow #include <linux/platform_device.h>
194aa97555SDmitry Artamonow #include <linux/serial_core.h>
2086e5e38cSDmitry Artamonow
2186e5e38cSDmitry Artamonow #include <asm/mach/flash.h>
2286e5e38cSDmitry Artamonow #include <asm/mach/map.h>
2386e5e38cSDmitry Artamonow
2486e5e38cSDmitry Artamonow #include <mach/h3xxx.h>
25abf38780SLinus Walleij #include <mach/irqs.h>
2686e5e38cSDmitry Artamonow
2786e5e38cSDmitry Artamonow #include "generic.h"
2886e5e38cSDmitry Artamonow
2986e5e38cSDmitry Artamonow /*
3086e5e38cSDmitry Artamonow * H3xxx flash support
3186e5e38cSDmitry Artamonow */
3286e5e38cSDmitry Artamonow static struct mtd_partition h3xxx_partitions[] = {
3386e5e38cSDmitry Artamonow {
3486e5e38cSDmitry Artamonow .name = "H3XXX boot firmware",
3586e5e38cSDmitry Artamonow .size = 0x00040000,
3686e5e38cSDmitry Artamonow .offset = 0,
3786e5e38cSDmitry Artamonow .mask_flags = MTD_WRITEABLE, /* force read-only */
3886e5e38cSDmitry Artamonow }, {
3986e5e38cSDmitry Artamonow .name = "H3XXX rootfs",
4086e5e38cSDmitry Artamonow .size = MTDPART_SIZ_FULL,
4186e5e38cSDmitry Artamonow .offset = 0x00040000,
4286e5e38cSDmitry Artamonow }
4386e5e38cSDmitry Artamonow };
4486e5e38cSDmitry Artamonow
h3xxx_set_vpp(int vpp)4586e5e38cSDmitry Artamonow static void h3xxx_set_vpp(int vpp)
4686e5e38cSDmitry Artamonow {
4786e5e38cSDmitry Artamonow gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
4886e5e38cSDmitry Artamonow }
4986e5e38cSDmitry Artamonow
h3xxx_flash_init(void)5086e5e38cSDmitry Artamonow static int h3xxx_flash_init(void)
5186e5e38cSDmitry Artamonow {
5286e5e38cSDmitry Artamonow int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
53729fae44SDmitry Artamonow if (err) {
54729fae44SDmitry Artamonow pr_err("%s: can't request H3XXX_EGPIO_VPP_ON\n", __func__);
5586e5e38cSDmitry Artamonow return err;
56729fae44SDmitry Artamonow }
5786e5e38cSDmitry Artamonow
5886e5e38cSDmitry Artamonow err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
5986e5e38cSDmitry Artamonow if (err)
6086e5e38cSDmitry Artamonow gpio_free(H3XXX_EGPIO_VPP_ON);
6186e5e38cSDmitry Artamonow
6286e5e38cSDmitry Artamonow return err;
6386e5e38cSDmitry Artamonow }
6486e5e38cSDmitry Artamonow
h3xxx_flash_exit(void)6586e5e38cSDmitry Artamonow static void h3xxx_flash_exit(void)
6686e5e38cSDmitry Artamonow {
6786e5e38cSDmitry Artamonow gpio_free(H3XXX_EGPIO_VPP_ON);
6886e5e38cSDmitry Artamonow }
6986e5e38cSDmitry Artamonow
7086e5e38cSDmitry Artamonow static struct flash_platform_data h3xxx_flash_data = {
7186e5e38cSDmitry Artamonow .map_name = "cfi_probe",
7286e5e38cSDmitry Artamonow .set_vpp = h3xxx_set_vpp,
7386e5e38cSDmitry Artamonow .init = h3xxx_flash_init,
7486e5e38cSDmitry Artamonow .exit = h3xxx_flash_exit,
7586e5e38cSDmitry Artamonow .parts = h3xxx_partitions,
7686e5e38cSDmitry Artamonow .nr_parts = ARRAY_SIZE(h3xxx_partitions),
7786e5e38cSDmitry Artamonow };
7886e5e38cSDmitry Artamonow
79a181099eSRussell King static struct resource h3xxx_flash_resource =
80a181099eSRussell King DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M);
8186e5e38cSDmitry Artamonow
8286e5e38cSDmitry Artamonow
8386e5e38cSDmitry Artamonow /*
8486e5e38cSDmitry Artamonow * H3xxx uart support
8586e5e38cSDmitry Artamonow */
h3xxx_uart_pm(struct uart_port * port,u_int state,u_int oldstate)8686e5e38cSDmitry Artamonow static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
8786e5e38cSDmitry Artamonow {
88729fae44SDmitry Artamonow if (port->mapbase == _Ser3UTCR0) {
8986e5e38cSDmitry Artamonow if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
9086e5e38cSDmitry Artamonow gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
9186e5e38cSDmitry Artamonow gpio_free(H3XXX_EGPIO_RS232_ON);
92729fae44SDmitry Artamonow } else {
93729fae44SDmitry Artamonow pr_err("%s: can't request H3XXX_EGPIO_RS232_ON\n",
94729fae44SDmitry Artamonow __func__);
95729fae44SDmitry Artamonow }
9686e5e38cSDmitry Artamonow }
9786e5e38cSDmitry Artamonow }
9886e5e38cSDmitry Artamonow
9986e5e38cSDmitry Artamonow /*
10086e5e38cSDmitry Artamonow * Enable/Disable wake up events for this serial port.
10186e5e38cSDmitry Artamonow * Obviously, we only support this on the normal COM port.
10286e5e38cSDmitry Artamonow */
h3xxx_uart_set_wake(struct uart_port * port,u_int enable)10386e5e38cSDmitry Artamonow static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
10486e5e38cSDmitry Artamonow {
10586e5e38cSDmitry Artamonow int err = -EINVAL;
10686e5e38cSDmitry Artamonow
10786e5e38cSDmitry Artamonow if (port->mapbase == _Ser3UTCR0) {
10886e5e38cSDmitry Artamonow if (enable)
10986e5e38cSDmitry Artamonow PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
11086e5e38cSDmitry Artamonow else
11186e5e38cSDmitry Artamonow PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
11286e5e38cSDmitry Artamonow err = 0;
11386e5e38cSDmitry Artamonow }
11486e5e38cSDmitry Artamonow return err;
11586e5e38cSDmitry Artamonow }
11686e5e38cSDmitry Artamonow
11786e5e38cSDmitry Artamonow static struct sa1100_port_fns h3xxx_port_fns __initdata = {
11886e5e38cSDmitry Artamonow .pm = h3xxx_uart_pm,
11986e5e38cSDmitry Artamonow .set_wake = h3xxx_uart_set_wake,
12086e5e38cSDmitry Artamonow };
12186e5e38cSDmitry Artamonow
1223fae166eSRussell King static struct gpiod_lookup_table h3xxx_uart3_gpio_table = {
1233fae166eSRussell King .dev_id = "sa11x0-uart.3",
1243fae166eSRussell King .table = {
1253fae166eSRussell King GPIO_LOOKUP("gpio", H3XXX_GPIO_COM_DCD, "dcd", GPIO_ACTIVE_LOW),
1263fae166eSRussell King GPIO_LOOKUP("gpio", H3XXX_GPIO_COM_CTS, "cts", GPIO_ACTIVE_LOW),
1273fae166eSRussell King GPIO_LOOKUP("gpio", H3XXX_GPIO_COM_RTS, "rts", GPIO_ACTIVE_LOW),
1283fae166eSRussell King { },
1293fae166eSRussell King },
1303fae166eSRussell King };
1313fae166eSRussell King
13286e5e38cSDmitry Artamonow /*
13386e5e38cSDmitry Artamonow * EGPIO
13486e5e38cSDmitry Artamonow */
13586e5e38cSDmitry Artamonow
13686e5e38cSDmitry Artamonow static struct resource egpio_resources[] = {
137a181099eSRussell King [0] = DEFINE_RES_MEM(H3600_EGPIO_PHYS, 0x4),
13886e5e38cSDmitry Artamonow };
13986e5e38cSDmitry Artamonow
14086e5e38cSDmitry Artamonow static struct htc_egpio_chip egpio_chips[] = {
14186e5e38cSDmitry Artamonow [0] = {
14286e5e38cSDmitry Artamonow .reg_start = 0,
14386e5e38cSDmitry Artamonow .gpio_base = H3XXX_EGPIO_BASE,
14486e5e38cSDmitry Artamonow .num_gpios = 16,
14586e5e38cSDmitry Artamonow .direction = HTC_EGPIO_OUTPUT,
14686e5e38cSDmitry Artamonow .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
14786e5e38cSDmitry Artamonow },
14886e5e38cSDmitry Artamonow };
14986e5e38cSDmitry Artamonow
15086e5e38cSDmitry Artamonow static struct htc_egpio_platform_data egpio_info = {
15186e5e38cSDmitry Artamonow .reg_width = 16,
15286e5e38cSDmitry Artamonow .bus_width = 16,
15386e5e38cSDmitry Artamonow .chip = egpio_chips,
15486e5e38cSDmitry Artamonow .num_chips = ARRAY_SIZE(egpio_chips),
15586e5e38cSDmitry Artamonow };
15686e5e38cSDmitry Artamonow
15786e5e38cSDmitry Artamonow static struct platform_device h3xxx_egpio = {
15886e5e38cSDmitry Artamonow .name = "htc-egpio",
15986e5e38cSDmitry Artamonow .id = -1,
16086e5e38cSDmitry Artamonow .resource = egpio_resources,
16186e5e38cSDmitry Artamonow .num_resources = ARRAY_SIZE(egpio_resources),
16286e5e38cSDmitry Artamonow .dev = {
16386e5e38cSDmitry Artamonow .platform_data = &egpio_info,
16486e5e38cSDmitry Artamonow },
16586e5e38cSDmitry Artamonow };
16686e5e38cSDmitry Artamonow
167c463eb62SDmitry Artamonow /*
168c463eb62SDmitry Artamonow * GPIO keys
169c463eb62SDmitry Artamonow */
170c463eb62SDmitry Artamonow
171c463eb62SDmitry Artamonow static struct gpio_keys_button h3xxx_button_table[] = {
172c463eb62SDmitry Artamonow {
173c463eb62SDmitry Artamonow .code = KEY_POWER,
174c463eb62SDmitry Artamonow .gpio = H3XXX_GPIO_PWR_BUTTON,
175c463eb62SDmitry Artamonow .desc = "Power Button",
176c463eb62SDmitry Artamonow .active_low = 1,
177c463eb62SDmitry Artamonow .type = EV_KEY,
178c463eb62SDmitry Artamonow .wakeup = 1,
179c463eb62SDmitry Artamonow }, {
180c463eb62SDmitry Artamonow .code = KEY_ENTER,
181c463eb62SDmitry Artamonow .gpio = H3XXX_GPIO_ACTION_BUTTON,
182c463eb62SDmitry Artamonow .active_low = 1,
183c463eb62SDmitry Artamonow .desc = "Action button",
184c463eb62SDmitry Artamonow .type = EV_KEY,
185c463eb62SDmitry Artamonow .wakeup = 0,
186c463eb62SDmitry Artamonow },
187c463eb62SDmitry Artamonow };
188c463eb62SDmitry Artamonow
189c463eb62SDmitry Artamonow static struct gpio_keys_platform_data h3xxx_keys_data = {
190c463eb62SDmitry Artamonow .buttons = h3xxx_button_table,
191c463eb62SDmitry Artamonow .nbuttons = ARRAY_SIZE(h3xxx_button_table),
192c463eb62SDmitry Artamonow };
193c463eb62SDmitry Artamonow
194c463eb62SDmitry Artamonow static struct platform_device h3xxx_keys = {
195c463eb62SDmitry Artamonow .name = "gpio-keys",
196c463eb62SDmitry Artamonow .id = -1,
197c463eb62SDmitry Artamonow .dev = {
198c463eb62SDmitry Artamonow .platform_data = &h3xxx_keys_data,
199c463eb62SDmitry Artamonow },
200c463eb62SDmitry Artamonow };
201c463eb62SDmitry Artamonow
202abf38780SLinus Walleij static struct resource h3xxx_micro_resources[] = {
203abf38780SLinus Walleij DEFINE_RES_MEM(0x80010000, SZ_4K),
204abf38780SLinus Walleij DEFINE_RES_MEM(0x80020000, SZ_4K),
205abf38780SLinus Walleij DEFINE_RES_IRQ(IRQ_Ser1UART),
206abf38780SLinus Walleij };
207abf38780SLinus Walleij
208abf38780SLinus Walleij struct platform_device h3xxx_micro_asic = {
209abf38780SLinus Walleij .name = "ipaq-h3xxx-micro",
210abf38780SLinus Walleij .id = -1,
211abf38780SLinus Walleij .resource = h3xxx_micro_resources,
212abf38780SLinus Walleij .num_resources = ARRAY_SIZE(h3xxx_micro_resources),
213abf38780SLinus Walleij };
214abf38780SLinus Walleij
21586e5e38cSDmitry Artamonow static struct platform_device *h3xxx_devices[] = {
21686e5e38cSDmitry Artamonow &h3xxx_egpio,
217c463eb62SDmitry Artamonow &h3xxx_keys,
218abf38780SLinus Walleij &h3xxx_micro_asic,
21986e5e38cSDmitry Artamonow };
22086e5e38cSDmitry Artamonow
221a00315d1SRussell King static struct gpiod_lookup_table h3xxx_pcmcia_gpio_table = {
222a00315d1SRussell King .dev_id = "sa11x0-pcmcia",
223a00315d1SRussell King .table = {
224a00315d1SRussell King GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_CD0,
225a00315d1SRussell King "pcmcia0-detect", GPIO_ACTIVE_LOW),
226a00315d1SRussell King GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_IRQ0,
227a00315d1SRussell King "pcmcia0-ready", GPIO_ACTIVE_HIGH),
228a00315d1SRussell King GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_CD1,
229a00315d1SRussell King "pcmcia1-detect", GPIO_ACTIVE_LOW),
230a00315d1SRussell King GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_IRQ1,
231a00315d1SRussell King "pcmcia1-ready", GPIO_ACTIVE_HIGH),
232a00315d1SRussell King { },
233a00315d1SRussell King },
234a00315d1SRussell King };
235a00315d1SRussell King
h3xxx_mach_init(void)23686e5e38cSDmitry Artamonow void __init h3xxx_mach_init(void)
23786e5e38cSDmitry Artamonow {
238a00315d1SRussell King gpiod_add_lookup_table(&h3xxx_pcmcia_gpio_table);
2393fae166eSRussell King gpiod_add_lookup_table(&h3xxx_uart3_gpio_table);
24086e5e38cSDmitry Artamonow sa1100_register_uart_fns(&h3xxx_port_fns);
24186e5e38cSDmitry Artamonow sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
24286e5e38cSDmitry Artamonow platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
24386e5e38cSDmitry Artamonow }
24486e5e38cSDmitry Artamonow
24586e5e38cSDmitry Artamonow static struct map_desc h3600_io_desc[] __initdata = {
24686e5e38cSDmitry Artamonow { /* static memory bank 2 CS#2 */
24786e5e38cSDmitry Artamonow .virtual = H3600_BANK_2_VIRT,
24886e5e38cSDmitry Artamonow .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
24986e5e38cSDmitry Artamonow .length = 0x02800000,
25086e5e38cSDmitry Artamonow .type = MT_DEVICE
25186e5e38cSDmitry Artamonow }, { /* static memory bank 4 CS#4 */
25286e5e38cSDmitry Artamonow .virtual = H3600_BANK_4_VIRT,
25386e5e38cSDmitry Artamonow .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
25486e5e38cSDmitry Artamonow .length = 0x00800000,
25586e5e38cSDmitry Artamonow .type = MT_DEVICE
25686e5e38cSDmitry Artamonow }, { /* EGPIO 0 CS#5 */
25786e5e38cSDmitry Artamonow .virtual = H3600_EGPIO_VIRT,
25886e5e38cSDmitry Artamonow .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
25986e5e38cSDmitry Artamonow .length = 0x01000000,
26086e5e38cSDmitry Artamonow .type = MT_DEVICE
26186e5e38cSDmitry Artamonow }
26286e5e38cSDmitry Artamonow };
26386e5e38cSDmitry Artamonow
26486e5e38cSDmitry Artamonow /*
26586e5e38cSDmitry Artamonow * Common map_io initialization
26686e5e38cSDmitry Artamonow */
26786e5e38cSDmitry Artamonow
h3xxx_map_io(void)26886e5e38cSDmitry Artamonow void __init h3xxx_map_io(void)
26986e5e38cSDmitry Artamonow {
27086e5e38cSDmitry Artamonow sa1100_map_io();
27186e5e38cSDmitry Artamonow iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
27286e5e38cSDmitry Artamonow
27386e5e38cSDmitry Artamonow sa1100_register_uart(0, 3); /* Common serial port */
27486e5e38cSDmitry Artamonow // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
27586e5e38cSDmitry Artamonow
27686e5e38cSDmitry Artamonow /* Ensure those pins are outputs and driving low */
27786e5e38cSDmitry Artamonow PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
27886e5e38cSDmitry Artamonow PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
27986e5e38cSDmitry Artamonow
28086e5e38cSDmitry Artamonow /* Configure suspend conditions */
28186e5e38cSDmitry Artamonow PGSR = 0;
28286e5e38cSDmitry Artamonow PCFR = PCFR_OPDE;
28386e5e38cSDmitry Artamonow PSDR = 0;
28486e5e38cSDmitry Artamonow
28586e5e38cSDmitry Artamonow GPCR = 0x0fffffff; /* All outputs are set low by default */
28686e5e38cSDmitry Artamonow GPDR = 0; /* Configure all GPIOs as input */
28786e5e38cSDmitry Artamonow }
28886e5e38cSDmitry Artamonow
289