]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - arch/arm/mach-sa1100/h3600.c
ebb3b8dcee563e30874be779b27377a878e39a45
[mirror_ubuntu-eoan-kernel.git] / arch / arm / mach-sa1100 / h3600.c
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 */
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>
28 #include <linux/mtd/mtd.h>
29 #include <linux/mtd/partitions.h>
30 #include <linux/serial_core.h>
31 #include <linux/gpio.h>
32
33 #include <asm/irq.h>
34 #include <mach/hardware.h>
35 #include <asm/mach-types.h>
36 #include <asm/setup.h>
37
38 #include <asm/mach/irq.h>
39 #include <asm/mach/arch.h>
40 #include <asm/mach/flash.h>
41 #include <asm/mach/irda.h>
42 #include <asm/mach/map.h>
43 #include <asm/mach/serial_sa1100.h>
44
45 #include <mach/h3600.h>
46 #include <mach/h3600_gpio.h>
47
48 #include "generic.h"
49
50 void (*assign_h3600_egpio)(enum ipaq_egpio_type x, int level);
51 EXPORT_SYMBOL(assign_h3600_egpio);
52
53 struct gpio_default_state {
54 int gpio;
55 int mode;
56 const char *name;
57 };
58
59 #define GPIO_MODE_IN -1
60 #define GPIO_MODE_OUT0 0
61 #define GPIO_MODE_OUT1 1
62
63 static void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
64 {
65 while (n--) {
66 const char *name = s->name;
67 int err;
68
69 if (!name)
70 name = "[init]";
71 err = gpio_request(s->gpio, name);
72 if (err) {
73 printk(KERN_ERR "gpio%u: unable to request: %d\n",
74 s->gpio, err);
75 continue;
76 }
77 if (s->mode >= 0) {
78 err = gpio_direction_output(s->gpio, s->mode);
79 } else {
80 err = gpio_direction_input(s->gpio);
81 }
82 if (err) {
83 printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
84 s->gpio, err);
85 continue;
86 }
87 if (!s->name)
88 gpio_free(s->gpio);
89 s++;
90 }
91 }
92
93
94 /*
95 * H3xxx flash support
96 */
97 static struct mtd_partition h3xxx_partitions[] = {
98 {
99 .name = "H3XXX boot firmware",
100 .size = 0x00040000,
101 .offset = 0,
102 .mask_flags = MTD_WRITEABLE, /* force read-only */
103 }, {
104 .name = "H3XXX rootfs",
105 .size = MTDPART_SIZ_FULL,
106 .offset = 0x00040000,
107 }
108 };
109
110 static void h3xxx_set_vpp(int vpp)
111 {
112 assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, vpp);
113 }
114
115 static struct flash_platform_data h3xxx_flash_data = {
116 .map_name = "cfi_probe",
117 .set_vpp = h3xxx_set_vpp,
118 .parts = h3xxx_partitions,
119 .nr_parts = ARRAY_SIZE(h3xxx_partitions),
120 };
121
122 static struct resource h3xxx_flash_resource = {
123 .start = SA1100_CS0_PHYS,
124 .end = SA1100_CS0_PHYS + SZ_32M - 1,
125 .flags = IORESOURCE_MEM,
126 };
127
128
129 /*
130 * H3xxx uart support
131 */
132 static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
133 {
134 if (port->mapbase == _Ser3UTCR0) {
135 gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
136 }
137 }
138
139 static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
140 {
141 u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
142
143 if (port->mapbase == _Ser3UTCR0) {
144 /*
145 * DCD and CTS bits are inverted in GPLR by RS232 transceiver
146 */
147 if (gpio_get_value(H3XXX_GPIO_COM_DCD))
148 ret &= ~TIOCM_CD;
149 if (gpio_get_value(H3XXX_GPIO_COM_CTS))
150 ret &= ~TIOCM_CTS;
151 }
152
153 return ret;
154 }
155
156 static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
157 {
158 if (port->mapbase == _Ser2UTCR0) { /* TODO: REMOVE THIS */
159 assign_h3600_egpio(IPAQ_EGPIO_IR_ON, !state);
160 } else if (port->mapbase == _Ser3UTCR0) {
161 assign_h3600_egpio(IPAQ_EGPIO_RS232_ON, !state);
162 }
163 }
164
165 /*
166 * Enable/Disable wake up events for this serial port.
167 * Obviously, we only support this on the normal COM port.
168 */
169 static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
170 {
171 int err = -EINVAL;
172
173 if (port->mapbase == _Ser3UTCR0) {
174 if (enable)
175 PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
176 else
177 PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
178 err = 0;
179 }
180 return err;
181 }
182
183 static struct sa1100_port_fns h3xxx_port_fns __initdata = {
184 .set_mctrl = h3xxx_uart_set_mctrl,
185 .get_mctrl = h3xxx_uart_get_mctrl,
186 .pm = h3xxx_uart_pm,
187 .set_wake = h3xxx_uart_set_wake,
188 };
189
190
191 static void __init h3xxx_mach_init(void)
192 {
193 sa1100_register_uart_fns(&h3xxx_port_fns);
194 sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
195 }
196
197 /*
198 * helper for sa1100fb
199 */
200 static void h3xxx_lcd_power(int enable)
201 {
202 assign_h3600_egpio(IPAQ_EGPIO_LCD_POWER, enable);
203 }
204
205 static struct map_desc h3600_io_desc[] __initdata = {
206 { /* static memory bank 2 CS#2 */
207 .virtual = H3600_BANK_2_VIRT,
208 .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
209 .length = 0x02800000,
210 .type = MT_DEVICE
211 }, { /* static memory bank 4 CS#4 */
212 .virtual = H3600_BANK_4_VIRT,
213 .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
214 .length = 0x00800000,
215 .type = MT_DEVICE
216 }, { /* EGPIO 0 CS#5 */
217 .virtual = H3600_EGPIO_VIRT,
218 .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
219 .length = 0x01000000,
220 .type = MT_DEVICE
221 }
222 };
223
224 /*
225 * Common map_io initialization
226 */
227
228 static void __init h3xxx_map_io(void)
229 {
230 sa1100_map_io();
231 iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
232
233 sa1100_register_uart(0, 3); /* Common serial port */
234 // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
235
236 /* Ensure those pins are outputs and driving low */
237 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
238 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
239
240 /* Configure suspend conditions */
241 PGSR = 0;
242 PWER = PWER_GPIO0;
243 PCFR = PCFR_OPDE;
244 PSDR = 0;
245
246 sa1100fb_lcd_power = h3xxx_lcd_power;
247 }
248
249 /************************* H3100 *************************/
250
251 #ifdef CONFIG_SA1100_H3100
252
253 #define H3100_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
254 static unsigned int h3100_egpio = 0;
255
256 static void h3100_control_egpio(enum ipaq_egpio_type x, int setp)
257 {
258 unsigned int egpio = 0;
259 long gpio = 0;
260 unsigned long flags;
261
262 switch (x) {
263 case IPAQ_EGPIO_LCD_POWER:
264 egpio |= EGPIO_H3600_LCD_ON;
265 gpio |= GPIO_H3100_LCD_3V_ON;
266 break;
267 case IPAQ_EGPIO_LCD_ENABLE:
268 break;
269 case IPAQ_EGPIO_CODEC_NRESET:
270 egpio |= EGPIO_H3600_CODEC_NRESET;
271 break;
272 case IPAQ_EGPIO_AUDIO_ON:
273 gpio |= GPIO_H3100_AUD_PWR_ON
274 | GPIO_H3100_AUD_ON;
275 break;
276 case IPAQ_EGPIO_QMUTE:
277 gpio |= GPIO_H3100_QMUTE;
278 break;
279 case IPAQ_EGPIO_OPT_NVRAM_ON:
280 egpio |= EGPIO_H3600_OPT_NVRAM_ON;
281 break;
282 case IPAQ_EGPIO_OPT_ON:
283 egpio |= EGPIO_H3600_OPT_ON;
284 break;
285 case IPAQ_EGPIO_CARD_RESET:
286 egpio |= EGPIO_H3600_CARD_RESET;
287 break;
288 case IPAQ_EGPIO_OPT_RESET:
289 egpio |= EGPIO_H3600_OPT_RESET;
290 break;
291 case IPAQ_EGPIO_IR_ON:
292 gpio |= GPIO_H3100_IR_ON;
293 break;
294 case IPAQ_EGPIO_IR_FSEL:
295 gpio |= GPIO_H3100_IR_FSEL;
296 break;
297 case IPAQ_EGPIO_RS232_ON:
298 egpio |= EGPIO_H3600_RS232_ON;
299 break;
300 case IPAQ_EGPIO_VPP_ON:
301 egpio |= EGPIO_H3600_VPP_ON;
302 break;
303 }
304
305 if (egpio || gpio) {
306 local_irq_save(flags);
307 if (setp) {
308 h3100_egpio |= egpio;
309 GPSR = gpio;
310 } else {
311 h3100_egpio &= ~egpio;
312 GPCR = gpio;
313 }
314 H3100_EGPIO = h3100_egpio;
315 local_irq_restore(flags);
316 }
317 }
318
319 #define H3100_DIRECT_EGPIO (GPIO_H3100_BT_ON \
320 | GPIO_H3100_GPIO3 \
321 | GPIO_H3100_QMUTE \
322 | GPIO_H3100_LCD_3V_ON \
323 | GPIO_H3100_AUD_ON \
324 | GPIO_H3100_AUD_PWR_ON \
325 | GPIO_H3100_IR_ON \
326 | GPIO_H3100_IR_FSEL)
327
328 static void __init h3100_map_io(void)
329 {
330 h3xxx_map_io();
331
332 /* Initialize h3100-specific values here */
333 GPCR = 0x0fffffff; /* All outputs are set low by default */
334 GPDR = GPIO_H3600_L3_CLOCK |
335 GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
336 GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
337 H3100_DIRECT_EGPIO;
338
339 /* Older bootldrs put GPIO2-9 in alternate mode on the
340 assumption that they are used for video */
341 GAFR &= ~H3100_DIRECT_EGPIO;
342
343 H3100_EGPIO = h3100_egpio;
344 assign_h3600_egpio = h3100_control_egpio;
345 }
346
347 /*
348 * This turns the IRDA power on or off on the Compaq H3100
349 */
350 static int h3100_irda_set_power(struct device *dev, unsigned int state)
351 {
352 gpio_set_value(H3100_GPIO_IR_ON, state);
353 return 0;
354 }
355
356 static void h3100_irda_set_speed(struct device *dev, unsigned int speed)
357 {
358 gpio_set_value(H3100_GPIO_IR_FSEL, !(speed < 4000000));
359 }
360
361 static struct irda_platform_data h3100_irda_data = {
362 .set_power = h3100_irda_set_power,
363 .set_speed = h3100_irda_set_speed,
364 };
365
366 static struct gpio_default_state h3100_default_gpio[] = {
367 { H3100_GPIO_IR_ON, GPIO_MODE_OUT0, "IrDA power" },
368 { H3100_GPIO_IR_FSEL, GPIO_MODE_OUT0, "IrDA fsel" },
369 { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
370 { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
371 { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
372 };
373
374 static void __init h3100_mach_init(void)
375 {
376 h3xxx_init_gpio(h3100_default_gpio, ARRAY_SIZE(h3100_default_gpio));
377 h3xxx_mach_init();
378 sa11x0_register_irda(&h3100_irda_data);
379 }
380
381 MACHINE_START(H3100, "Compaq iPAQ H3100")
382 .phys_io = 0x80000000,
383 .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
384 .boot_params = 0xc0000100,
385 .map_io = h3100_map_io,
386 .init_irq = sa1100_init_irq,
387 .timer = &sa1100_timer,
388 .init_machine = h3100_mach_init,
389 MACHINE_END
390
391 #endif /* CONFIG_SA1100_H3100 */
392
393 /************************* H3600 *************************/
394
395 #ifdef CONFIG_SA1100_H3600
396
397 #define H3600_EGPIO (*(volatile unsigned int *)H3600_EGPIO_VIRT)
398 static unsigned int h3600_egpio = EGPIO_H3600_RS232_ON;
399
400 static void h3600_control_egpio(enum ipaq_egpio_type x, int setp)
401 {
402 unsigned int egpio = 0;
403 unsigned long flags;
404
405 switch (x) {
406 case IPAQ_EGPIO_LCD_POWER:
407 egpio |= EGPIO_H3600_LCD_ON |
408 EGPIO_H3600_LCD_PCI |
409 EGPIO_H3600_LCD_5V_ON |
410 EGPIO_H3600_LVDD_ON;
411 break;
412 case IPAQ_EGPIO_LCD_ENABLE:
413 break;
414 case IPAQ_EGPIO_CODEC_NRESET:
415 egpio |= EGPIO_H3600_CODEC_NRESET;
416 break;
417 case IPAQ_EGPIO_AUDIO_ON:
418 egpio |= EGPIO_H3600_AUD_AMP_ON |
419 EGPIO_H3600_AUD_PWR_ON;
420 break;
421 case IPAQ_EGPIO_QMUTE:
422 egpio |= EGPIO_H3600_QMUTE;
423 break;
424 case IPAQ_EGPIO_OPT_NVRAM_ON:
425 egpio |= EGPIO_H3600_OPT_NVRAM_ON;
426 break;
427 case IPAQ_EGPIO_OPT_ON:
428 egpio |= EGPIO_H3600_OPT_ON;
429 break;
430 case IPAQ_EGPIO_CARD_RESET:
431 egpio |= EGPIO_H3600_CARD_RESET;
432 break;
433 case IPAQ_EGPIO_OPT_RESET:
434 egpio |= EGPIO_H3600_OPT_RESET;
435 break;
436 case IPAQ_EGPIO_IR_ON:
437 egpio |= EGPIO_H3600_IR_ON;
438 break;
439 case IPAQ_EGPIO_IR_FSEL:
440 egpio |= EGPIO_H3600_IR_FSEL;
441 break;
442 case IPAQ_EGPIO_RS232_ON:
443 egpio |= EGPIO_H3600_RS232_ON;
444 break;
445 case IPAQ_EGPIO_VPP_ON:
446 egpio |= EGPIO_H3600_VPP_ON;
447 break;
448 }
449
450 if (egpio) {
451 local_irq_save(flags);
452 if (setp)
453 h3600_egpio |= egpio;
454 else
455 h3600_egpio &= ~egpio;
456 H3600_EGPIO = h3600_egpio;
457 local_irq_restore(flags);
458 }
459 }
460
461 static void __init h3600_map_io(void)
462 {
463 h3xxx_map_io();
464
465 /* Initialize h3600-specific values here */
466
467 GPCR = 0x0fffffff; /* All outputs are set low by default */
468 GPDR = GPIO_H3600_L3_CLOCK |
469 GPIO_H3600_L3_MODE | GPIO_H3600_L3_DATA |
470 GPIO_H3600_CLK_SET1 | GPIO_H3600_CLK_SET0 |
471 GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12 |
472 GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
473
474 H3600_EGPIO = h3600_egpio; /* Maintains across sleep? */
475 assign_h3600_egpio = h3600_control_egpio;
476 }
477
478 /*
479 * This turns the IRDA power on or off on the Compaq H3600
480 */
481 static int h3600_irda_set_power(struct device *dev, unsigned int state)
482 {
483 assign_h3600_egpio(IPAQ_EGPIO_IR_ON, state);
484 return 0;
485 }
486
487 static void h3600_irda_set_speed(struct device *dev, unsigned int speed)
488 {
489 assign_h3600_egpio(IPAQ_EGPIO_IR_FSEL, !(speed < 4000000));
490 }
491
492 static struct irda_platform_data h3600_irda_data = {
493 .set_power = h3600_irda_set_power,
494 .set_speed = h3600_irda_set_speed,
495 };
496
497 static struct gpio_default_state h3600_default_gpio[] = {
498 { H3XXX_GPIO_COM_DCD, GPIO_MODE_IN, "COM DCD" },
499 { H3XXX_GPIO_COM_CTS, GPIO_MODE_IN, "COM CTS" },
500 { H3XXX_GPIO_COM_RTS, GPIO_MODE_OUT0, "COM RTS" },
501 };
502
503 static void __init h3600_mach_init(void)
504 {
505 h3xxx_init_gpio(h3600_default_gpio, ARRAY_SIZE(h3600_default_gpio));
506 h3xxx_mach_init();
507 sa11x0_register_irda(&h3600_irda_data);
508 }
509
510 MACHINE_START(H3600, "Compaq iPAQ H3600")
511 .phys_io = 0x80000000,
512 .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
513 .boot_params = 0xc0000100,
514 .map_io = h3600_map_io,
515 .init_irq = sa1100_init_irq,
516 .timer = &sa1100_timer,
517 .init_machine = h3600_mach_init,
518 MACHINE_END
519
520 #endif /* CONFIG_SA1100_H3600 */
521