blob: c79bf467fb7f8efea5b70f7e2d278e3f30c52864 [file] [log] [blame]
Dmitry Artamonow86e5e382009-11-27 12:10:55 +01001/*
Dmitry Artamonow6e23fcb2009-11-27 12:11:48 +01002 * Support for Compaq iPAQ H3100 and H3600 handheld computers (common code)
Dmitry Artamonow86e5e382009-11-27 12:10:55 +01003 *
Dmitry Artamonow6e23fcb2009-11-27 12:11:48 +01004 * Copyright (c) 2000,1 Compaq Computer Corporation. (Author: Jamey Hicks)
5 * Copyright (c) 2009 Dmitry Artamonow <mad_soft@inbox.ru>
Dmitry Artamonow86e5e382009-11-27 12:10:55 +01006 *
Dmitry Artamonow6e23fcb2009-11-27 12:11:48 +01007 * 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.
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010010 *
11 */
Dmitry Artamonow6e23fcb2009-11-27 12:11:48 +010012
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010013#include <linux/kernel.h>
Dmitry Artamonow4aa97552009-11-27 12:12:25 +010014#include <linux/gpio.h>
Dmitry Artamonowc463eb62009-11-27 12:13:01 +010015#include <linux/gpio_keys.h>
16#include <linux/input.h>
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010017#include <linux/mfd/htc-egpio.h>
18#include <linux/mtd/mtd.h>
19#include <linux/mtd/partitions.h>
Russell King6920b5a2012-09-21 10:18:58 +010020#include <linux/platform_data/sa11x0-serial.h>
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010021#include <linux/platform_device.h>
Dmitry Artamonow4aa97552009-11-27 12:12:25 +010022#include <linux/serial_core.h>
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010023
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010024#include <asm/mach/flash.h>
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010025#include <asm/mach/map.h>
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010026
27#include <mach/h3xxx.h>
28
29#include "generic.h"
30
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010031/*
32 * H3xxx flash support
33 */
34static struct mtd_partition h3xxx_partitions[] = {
35 {
36 .name = "H3XXX boot firmware",
37 .size = 0x00040000,
38 .offset = 0,
39 .mask_flags = MTD_WRITEABLE, /* force read-only */
40 }, {
41 .name = "H3XXX rootfs",
42 .size = MTDPART_SIZ_FULL,
43 .offset = 0x00040000,
44 }
45};
46
47static void h3xxx_set_vpp(int vpp)
48{
49 gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
50}
51
52static int h3xxx_flash_init(void)
53{
54 int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
Dmitry Artamonow729fae42009-11-27 12:22:32 +010055 if (err) {
56 pr_err("%s: can't request H3XXX_EGPIO_VPP_ON\n", __func__);
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010057 return err;
Dmitry Artamonow729fae42009-11-27 12:22:32 +010058 }
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010059
60 err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
61 if (err)
62 gpio_free(H3XXX_EGPIO_VPP_ON);
63
64 return err;
65}
66
67static void h3xxx_flash_exit(void)
68{
69 gpio_free(H3XXX_EGPIO_VPP_ON);
70}
71
72static struct flash_platform_data h3xxx_flash_data = {
73 .map_name = "cfi_probe",
74 .set_vpp = h3xxx_set_vpp,
75 .init = h3xxx_flash_init,
76 .exit = h3xxx_flash_exit,
77 .parts = h3xxx_partitions,
78 .nr_parts = ARRAY_SIZE(h3xxx_partitions),
79};
80
Russell Kinga1810992012-01-12 10:25:29 +000081static struct resource h3xxx_flash_resource =
82 DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M);
Dmitry Artamonow86e5e382009-11-27 12:10:55 +010083
84
85/*
86 * H3xxx uart support
87 */
Dmitry Eremin-Solenikoveb023132013-11-26 11:11:00 +010088static struct gpio h3xxx_uart_gpio[] = {
89 { H3XXX_GPIO_COM_DCD, GPIOF_IN, "COM DCD" },
90 { H3XXX_GPIO_COM_CTS, GPIOF_IN, "COM CTS" },
91 { H3XXX_GPIO_COM_RTS, GPIOF_OUT_INIT_LOW, "COM RTS" },
92};
93
94static bool h3xxx_uart_request_gpios(void)
95{
96 static bool h3xxx_uart_gpio_ok;
97 int rc;
98
99 if (h3xxx_uart_gpio_ok)
100 return true;
101
102 rc = gpio_request_array(h3xxx_uart_gpio, ARRAY_SIZE(h3xxx_uart_gpio));
103 if (rc)
104 pr_err("h3xxx_uart_request_gpios: error %d\n", rc);
105 else
106 h3xxx_uart_gpio_ok = true;
107
108 return h3xxx_uart_gpio_ok;
109}
110
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100111static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
112{
113 if (port->mapbase == _Ser3UTCR0) {
Dmitry Eremin-Solenikoveb023132013-11-26 11:11:00 +0100114 if (!h3xxx_uart_request_gpios())
115 return;
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100116 gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
117 }
118}
119
120static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
121{
122 u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
123
124 if (port->mapbase == _Ser3UTCR0) {
Dmitry Eremin-Solenikoveb023132013-11-26 11:11:00 +0100125 if (!h3xxx_uart_request_gpios())
126 return ret;
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100127 /*
128 * DCD and CTS bits are inverted in GPLR by RS232 transceiver
129 */
130 if (gpio_get_value(H3XXX_GPIO_COM_DCD))
131 ret &= ~TIOCM_CD;
132 if (gpio_get_value(H3XXX_GPIO_COM_CTS))
133 ret &= ~TIOCM_CTS;
134 }
135
136 return ret;
137}
138
139static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
140{
Dmitry Artamonow729fae42009-11-27 12:22:32 +0100141 if (port->mapbase == _Ser3UTCR0) {
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100142 if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
143 gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
144 gpio_free(H3XXX_EGPIO_RS232_ON);
Dmitry Artamonow729fae42009-11-27 12:22:32 +0100145 } else {
146 pr_err("%s: can't request H3XXX_EGPIO_RS232_ON\n",
147 __func__);
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100148 }
Dmitry Artamonow729fae42009-11-27 12:22:32 +0100149 }
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100150}
151
152/*
153 * Enable/Disable wake up events for this serial port.
154 * Obviously, we only support this on the normal COM port.
155 */
156static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
157{
158 int err = -EINVAL;
159
160 if (port->mapbase == _Ser3UTCR0) {
161 if (enable)
162 PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
163 else
164 PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
165 err = 0;
166 }
167 return err;
168}
169
170static struct sa1100_port_fns h3xxx_port_fns __initdata = {
171 .set_mctrl = h3xxx_uart_set_mctrl,
172 .get_mctrl = h3xxx_uart_get_mctrl,
173 .pm = h3xxx_uart_pm,
174 .set_wake = h3xxx_uart_set_wake,
175};
176
177/*
178 * EGPIO
179 */
180
181static struct resource egpio_resources[] = {
Russell Kinga1810992012-01-12 10:25:29 +0000182 [0] = DEFINE_RES_MEM(H3600_EGPIO_PHYS, 0x4),
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100183};
184
185static struct htc_egpio_chip egpio_chips[] = {
186 [0] = {
187 .reg_start = 0,
188 .gpio_base = H3XXX_EGPIO_BASE,
189 .num_gpios = 16,
190 .direction = HTC_EGPIO_OUTPUT,
191 .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
192 },
193};
194
195static struct htc_egpio_platform_data egpio_info = {
196 .reg_width = 16,
197 .bus_width = 16,
198 .chip = egpio_chips,
199 .num_chips = ARRAY_SIZE(egpio_chips),
200};
201
202static struct platform_device h3xxx_egpio = {
203 .name = "htc-egpio",
204 .id = -1,
205 .resource = egpio_resources,
206 .num_resources = ARRAY_SIZE(egpio_resources),
207 .dev = {
208 .platform_data = &egpio_info,
209 },
210};
211
Dmitry Artamonowc463eb62009-11-27 12:13:01 +0100212/*
213 * GPIO keys
214 */
215
216static struct gpio_keys_button h3xxx_button_table[] = {
217 {
218 .code = KEY_POWER,
219 .gpio = H3XXX_GPIO_PWR_BUTTON,
220 .desc = "Power Button",
221 .active_low = 1,
222 .type = EV_KEY,
223 .wakeup = 1,
224 }, {
225 .code = KEY_ENTER,
226 .gpio = H3XXX_GPIO_ACTION_BUTTON,
227 .active_low = 1,
228 .desc = "Action button",
229 .type = EV_KEY,
230 .wakeup = 0,
231 },
232};
233
234static struct gpio_keys_platform_data h3xxx_keys_data = {
235 .buttons = h3xxx_button_table,
236 .nbuttons = ARRAY_SIZE(h3xxx_button_table),
237};
238
239static struct platform_device h3xxx_keys = {
240 .name = "gpio-keys",
241 .id = -1,
242 .dev = {
243 .platform_data = &h3xxx_keys_data,
244 },
245};
246
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100247static struct platform_device *h3xxx_devices[] = {
248 &h3xxx_egpio,
Dmitry Artamonowc463eb62009-11-27 12:13:01 +0100249 &h3xxx_keys,
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100250};
251
252void __init h3xxx_mach_init(void)
253{
254 sa1100_register_uart_fns(&h3xxx_port_fns);
255 sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
256 platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
257}
258
259static struct map_desc h3600_io_desc[] __initdata = {
260 { /* static memory bank 2 CS#2 */
261 .virtual = H3600_BANK_2_VIRT,
262 .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
263 .length = 0x02800000,
264 .type = MT_DEVICE
265 }, { /* static memory bank 4 CS#4 */
266 .virtual = H3600_BANK_4_VIRT,
267 .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
268 .length = 0x00800000,
269 .type = MT_DEVICE
270 }, { /* EGPIO 0 CS#5 */
271 .virtual = H3600_EGPIO_VIRT,
272 .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
273 .length = 0x01000000,
274 .type = MT_DEVICE
275 }
276};
277
278/*
279 * Common map_io initialization
280 */
281
282void __init h3xxx_map_io(void)
283{
284 sa1100_map_io();
285 iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
286
287 sa1100_register_uart(0, 3); /* Common serial port */
288// sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
289
290 /* Ensure those pins are outputs and driving low */
291 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
292 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
293
294 /* Configure suspend conditions */
295 PGSR = 0;
Dmitry Artamonow86e5e382009-11-27 12:10:55 +0100296 PCFR = PCFR_OPDE;
297 PSDR = 0;
298
299 GPCR = 0x0fffffff; /* All outputs are set low by default */
300 GPDR = 0; /* Configure all GPIOs as input */
301}
302