ARM: 5818/1: SA1100: h3100/h3600: drop old GPIO definitions
[deliverable/linux.git] / arch / arm / mach-sa1100 / h3600.c
CommitLineData
1da177e4
LT
1/*
2 * Hardware definitions for Compaq iPAQ H3xxx Handheld Computers
3 *
4 * Copyright 2000,1 Compaq Computer Corporation.
5 *
6 * Use consistent with the GNU GPL is permitted,
7 * provided that this copyright notice is
8 * preserved in its entirety in all copies and derived works.
9 *
10 * COMPAQ COMPUTER CORPORATION MAKES NO WARRANTIES, EXPRESSED OR IMPLIED,
11 * AS TO THE USEFULNESS OR CORRECTNESS OF THIS CODE OR ITS
12 * FITNESS FOR ANY PARTICULAR PURPOSE.
13 *
14 * Author: Jamey Hicks.
15 *
16 * History:
17 *
18 * 2001-10-?? Andrew Christian Added support for iPAQ H3800
19 * and abstracted EGPIO interface.
20 *
21 */
1da177e4
LT
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/kernel.h>
25#include <linux/tty.h>
26#include <linux/pm.h>
27#include <linux/device.h>
2eec62d7 28#include <linux/mfd/htc-egpio.h>
1da177e4
LT
29#include <linux/mtd/mtd.h>
30#include <linux/mtd/partitions.h>
31#include <linux/serial_core.h>
0831e3e4 32#include <linux/gpio.h>
2eec62d7 33#include <linux/platform_device.h>
1da177e4
LT
34
35#include <asm/irq.h>
a09e64fb 36#include <mach/hardware.h>
1da177e4
LT
37#include <asm/mach-types.h>
38#include <asm/setup.h>
39
40#include <asm/mach/irq.h>
41#include <asm/mach/arch.h>
42#include <asm/mach/flash.h>
43#include <asm/mach/irda.h>
44#include <asm/mach/map.h>
45#include <asm/mach/serial_sa1100.h>
46
a09e64fb 47#include <mach/h3600.h>
a09e64fb 48#include <mach/h3600_gpio.h>
1da177e4
LT
49
50#include "generic.h"
51
0831e3e4
RK
52struct gpio_default_state {
53 int gpio;
54 int mode;
55 const char *name;
56};
57
58#define GPIO_MODE_IN -1
59#define GPIO_MODE_OUT0 0
60#define GPIO_MODE_OUT1 1
61
62static void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
63{
64 while (n--) {
65 const char *name = s->name;
66 int err;
67
68 if (!name)
69 name = "[init]";
70 err = gpio_request(s->gpio, name);
71 if (err) {
72 printk(KERN_ERR "gpio%u: unable to request: %d\n",
73 s->gpio, err);
74 continue;
75 }
76 if (s->mode >= 0) {
77 err = gpio_direction_output(s->gpio, s->mode);
78 } else {
79 err = gpio_direction_input(s->gpio);
80 }
81 if (err) {
82 printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
83 s->gpio, err);
84 continue;
85 }
86 if (!s->name)
87 gpio_free(s->gpio);
88 s++;
89 }
90}
91
92
6e21ee6a
RK
93/*
94 * H3xxx flash support
95 */
1da177e4
LT
96static struct mtd_partition h3xxx_partitions[] = {
97 {
98 .name = "H3XXX boot firmware",
99 .size = 0x00040000,
100 .offset = 0,
101 .mask_flags = MTD_WRITEABLE, /* force read-only */
102 }, {
f110b3f2 103 .name = "H3XXX rootfs",
1da177e4
LT
104 .size = MTDPART_SIZ_FULL,
105 .offset = 0x00040000,
1da177e4
LT
106 }
107};
108
109static void h3xxx_set_vpp(int vpp)
110{
22f97405
DA
111 gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
112}
113
114static int h3xxx_flash_init(void)
115{
116 int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
117 if (err)
118 return err;
119
120 err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
121 if (err)
122 gpio_free(H3XXX_EGPIO_VPP_ON);
123
124 return err;
125}
126
127static void h3xxx_flash_exit(void)
128{
129 gpio_free(H3XXX_EGPIO_VPP_ON);
1da177e4
LT
130}
131
132static struct flash_platform_data h3xxx_flash_data = {
133 .map_name = "cfi_probe",
134 .set_vpp = h3xxx_set_vpp,
22f97405
DA
135 .init = h3xxx_flash_init,
136 .exit = h3xxx_flash_exit,
1da177e4
LT
137 .parts = h3xxx_partitions,
138 .nr_parts = ARRAY_SIZE(h3xxx_partitions),
139};
140
141static struct resource h3xxx_flash_resource = {
142 .start = SA1100_CS0_PHYS,
143 .end = SA1100_CS0_PHYS + SZ_32M - 1,
144 .flags = IORESOURCE_MEM,
145};
146
1da177e4
LT
147
148/*
6e21ee6a 149 * H3xxx uart support
1da177e4 150 */
6e21ee6a 151static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
1da177e4
LT
152{
153 if (port->mapbase == _Ser3UTCR0) {
6e21ee6a 154 gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
1da177e4
LT
155 }
156}
157
6e21ee6a 158static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
1da177e4
LT
159{
160 u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
161
162 if (port->mapbase == _Ser3UTCR0) {
6e21ee6a
RK
163 /*
164 * DCD and CTS bits are inverted in GPLR by RS232 transceiver
165 */
166 if (gpio_get_value(H3XXX_GPIO_COM_DCD))
1da177e4 167 ret &= ~TIOCM_CD;
6e21ee6a 168 if (gpio_get_value(H3XXX_GPIO_COM_CTS))
1da177e4
LT
169 ret &= ~TIOCM_CTS;
170 }
171
172 return ret;
173}
174
6e21ee6a 175static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
1da177e4 176{
2a151a0f 177 if (port->mapbase == _Ser3UTCR0)
22f97405
DA
178 if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
179 gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
180 gpio_free(H3XXX_EGPIO_RS232_ON);
181 }
1da177e4
LT
182}
183
184/*
185 * Enable/Disable wake up events for this serial port.
186 * Obviously, we only support this on the normal COM port.
187 */
6e21ee6a 188static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
1da177e4
LT
189{
190 int err = -EINVAL;
191
192 if (port->mapbase == _Ser3UTCR0) {
193 if (enable)
194 PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
195 else
196 PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
197 err = 0;
198 }
199 return err;
200}
201
6e21ee6a
RK
202static struct sa1100_port_fns h3xxx_port_fns __initdata = {
203 .set_mctrl = h3xxx_uart_set_mctrl,
204 .get_mctrl = h3xxx_uart_get_mctrl,
205 .pm = h3xxx_uart_pm,
206 .set_wake = h3xxx_uart_set_wake,
1da177e4
LT
207};
208
2eec62d7
DA
209/*
210 * EGPIO
211 */
212
213static struct resource egpio_resources[] = {
214 [0] = {
215 .start = H3600_EGPIO_PHYS,
216 .end = H3600_EGPIO_PHYS + 0x4 - 1,
217 .flags = IORESOURCE_MEM,
218 },
219};
220
221static struct htc_egpio_chip egpio_chips[] = {
222 [0] = {
223 .reg_start = 0,
224 .gpio_base = H3XXX_EGPIO_BASE,
225 .num_gpios = 16,
226 .direction = HTC_EGPIO_OUTPUT,
227 .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
228 },
229};
230
231static struct htc_egpio_platform_data egpio_info = {
232 .reg_width = 16,
233 .bus_width = 16,
234 .chip = egpio_chips,
235 .num_chips = ARRAY_SIZE(egpio_chips),
236};
237
238static struct platform_device h3xxx_egpio = {
239 .name = "htc-egpio",
240 .id = -1,
241 .resource = egpio_resources,
242 .num_resources = ARRAY_SIZE(egpio_resources),
243 .dev = {
244 .platform_data = &egpio_info,
245 },
246};
247
248static struct platform_device *h3xxx_devices[] = {
249 &h3xxx_egpio,
250};
6e21ee6a 251
e55b20e8 252static void __init h3xxx_mach_init(void)
6e21ee6a
RK
253{
254 sa1100_register_uart_fns(&h3xxx_port_fns);
255 sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
2eec62d7 256 platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
6e21ee6a
RK
257}
258
1da177e4 259static struct map_desc h3600_io_desc[] __initdata = {
92519d82
DS
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 }
1da177e4
LT
276};
277
278/*
279 * Common map_io initialization
280 */
281
282static void __init h3xxx_map_io(void)
283{
284 sa1100_map_io();
285 iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
286
1da177e4
LT
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;
0fb85a5a 296 PWER = PWER_GPIO0;
1da177e4
LT
297 PCFR = PCFR_OPDE;
298 PSDR = 0;
299
51834901
DA
300 GPCR = 0x0fffffff; /* All outputs are set low by default */
301 GPDR = 0; /* Configure all GPIOs as input */
1da177e4
LT
302}
303
1da177e4
LT
304/************************* H3100 *************************/
305
306#ifdef CONFIG_SA1100_H3100
307
cf5a87d8
DA
308/*
309 * helper for sa1100fb
310 */
311static void h3100_lcd_power(int enable)
312{
22f97405
DA
313 if (!gpio_request(H3XXX_EGPIO_LCD_ON, "LCD ON")) {
314 gpio_set_value(H3100_GPIO_LCD_3V_ON, enable);
315 gpio_direction_output(H3XXX_EGPIO_LCD_ON, enable);
316 gpio_free(H3XXX_EGPIO_LCD_ON);
317 }
cf5a87d8
DA
318}
319
1da177e4
LT
320
321static void __init h3100_map_io(void)
322{
323 h3xxx_map_io();
324
cf5a87d8
DA
325 sa1100fb_lcd_power = h3100_lcd_power;
326
1da177e4
LT
327 /* Older bootldrs put GPIO2-9 in alternate mode on the
328 assumption that they are used for video */
51834901 329 GAFR &= ~0x000001fb;
1da177e4
LT
330}
331
a5d176a1
RK
332/*
333 * This turns the IRDA power on or off on the Compaq H3100
334 */
335static int h3100_irda_set_power(struct device *dev, unsigned int state)
336{
9c196f0f 337 gpio_set_value(H3100_GPIO_IR_ON, state);
a5d176a1
RK
338 return 0;
339}
340
341static void h3100_irda_set_speed(struct device *dev, unsigned int speed)
342{
9c196f0f 343 gpio_set_value(H3100_GPIO_IR_FSEL, !(speed < 4000000));
a5d176a1
RK
344}
345
346static struct irda_platform_data h3100_irda_data = {
347 .set_power = h3100_irda_set_power,
348 .set_speed = h3100_irda_set_speed,
349};
350
9c196f0f
RK
351static struct gpio_default_state h3100_default_gpio[] = {
352 { H3100_GPIO_IR_ON, GPIO_MODE_OUT0, "IrDA power" },
353 { H3100_GPIO_IR_FSEL, GPIO_MODE_OUT0, "IrDA fsel" },
6e21ee6a
RK
354 { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
355 { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
356 { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
22f97405 357 { H3100_GPIO_LCD_3V_ON, GPIO_MODE_OUT0, "LCD 3v" },
9c196f0f
RK
358};
359
e55b20e8 360static void __init h3100_mach_init(void)
898e810e 361{
9c196f0f 362 h3xxx_init_gpio(h3100_default_gpio, ARRAY_SIZE(h3100_default_gpio));
898e810e 363 h3xxx_mach_init();
a5d176a1 364 sa11x0_register_irda(&h3100_irda_data);
898e810e
RK
365}
366
1da177e4 367MACHINE_START(H3100, "Compaq iPAQ H3100")
e9dea0c6
RK
368 .phys_io = 0x80000000,
369 .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
370 .boot_params = 0xc0000100,
371 .map_io = h3100_map_io,
372 .init_irq = sa1100_init_irq,
1da177e4 373 .timer = &sa1100_timer,
898e810e 374 .init_machine = h3100_mach_init,
1da177e4
LT
375MACHINE_END
376
377#endif /* CONFIG_SA1100_H3100 */
378
379/************************* H3600 *************************/
380
381#ifdef CONFIG_SA1100_H3600
382
cf5a87d8
DA
383/*
384 * helper for sa1100fb
385 */
386static void h3600_lcd_power(int enable)
387{
22f97405
DA
388 if (gpio_request(H3XXX_EGPIO_LCD_ON, "LCD power"))
389 goto err1;
390 if (gpio_request(H3600_EGPIO_LCD_PCI, "LCD control"))
391 goto err2;
392 if (gpio_request(H3600_EGPIO_LCD_5V_ON, "LCD 5v"))
393 goto err3;
394 if (gpio_request(H3600_EGPIO_LVDD_ON, "LCD 9v/-6.5v"))
395 goto err4;
396
397 gpio_direction_output(H3XXX_EGPIO_LCD_ON, enable);
398 gpio_direction_output(H3600_EGPIO_LCD_PCI, enable);
399 gpio_direction_output(H3600_EGPIO_LCD_5V_ON, enable);
400 gpio_direction_output(H3600_EGPIO_LVDD_ON, enable);
401
402 gpio_free(H3600_EGPIO_LVDD_ON);
403err4: gpio_free(H3600_EGPIO_LCD_5V_ON);
404err3: gpio_free(H3600_EGPIO_LCD_PCI);
405err2: gpio_free(H3XXX_EGPIO_LCD_ON);
406err1: return;
cf5a87d8
DA
407}
408
1da177e4
LT
409static void __init h3600_map_io(void)
410{
411 h3xxx_map_io();
412
cf5a87d8 413 sa1100fb_lcd_power = h3600_lcd_power;
1da177e4
LT
414}
415
a5d176a1
RK
416/*
417 * This turns the IRDA power on or off on the Compaq H3600
418 */
419static int h3600_irda_set_power(struct device *dev, unsigned int state)
420{
22f97405 421 gpio_set_value(H3600_EGPIO_IR_ON, state);
a5d176a1
RK
422 return 0;
423}
424
425static void h3600_irda_set_speed(struct device *dev, unsigned int speed)
426{
22f97405
DA
427 gpio_set_value(H3600_EGPIO_IR_FSEL, !(speed < 4000000));
428}
429
430static int h3600_irda_startup(struct device *dev)
431{
432 int err = gpio_request(H3600_EGPIO_IR_ON, "IrDA power");
433 if (err)
434 goto err1;
435 err = gpio_direction_output(H3600_EGPIO_IR_ON, 0);
436 if (err)
437 goto err2;
438 err = gpio_request(H3600_EGPIO_IR_FSEL, "IrDA fsel");
439 if (err)
440 goto err2;
441 err = gpio_direction_output(H3600_EGPIO_IR_FSEL, 0);
442 if (err)
443 goto err3;
444 return 0;
445
446err3: gpio_free(H3600_EGPIO_IR_FSEL);
447err2: gpio_free(H3600_EGPIO_IR_ON);
448err1: return err;
449}
450
451static void h3600_irda_shutdown(struct device *dev)
452{
453 gpio_free(H3600_EGPIO_IR_ON);
454 gpio_free(H3600_EGPIO_IR_FSEL);
a5d176a1
RK
455}
456
457static struct irda_platform_data h3600_irda_data = {
458 .set_power = h3600_irda_set_power,
459 .set_speed = h3600_irda_set_speed,
22f97405
DA
460 .startup = h3600_irda_startup,
461 .shutdown = h3600_irda_shutdown,
a5d176a1
RK
462};
463
6e21ee6a
RK
464static struct gpio_default_state h3600_default_gpio[] = {
465 { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
466 { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
467 { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
468};
469
e55b20e8 470static void __init h3600_mach_init(void)
898e810e 471{
6e21ee6a 472 h3xxx_init_gpio(h3600_default_gpio, ARRAY_SIZE(h3600_default_gpio));
898e810e 473 h3xxx_mach_init();
a5d176a1 474 sa11x0_register_irda(&h3600_irda_data);
898e810e
RK
475}
476
1da177e4 477MACHINE_START(H3600, "Compaq iPAQ H3600")
e9dea0c6
RK
478 .phys_io = 0x80000000,
479 .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
480 .boot_params = 0xc0000100,
481 .map_io = h3600_map_io,
482 .init_irq = sa1100_init_irq,
1da177e4 483 .timer = &sa1100_timer,
898e810e 484 .init_machine = h3600_mach_init,
1da177e4
LT
485MACHINE_END
486
487#endif /* CONFIG_SA1100_H3600 */
488
This page took 0.432613 seconds and 5 git commands to generate.