2 * Hardware definitions for HTC Himalaya
4 * Copyright 2004 Xanadux.org
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.
10 * Authors: w4xy@xanadux.org
14 * 2004-02-07 W4XY Initial port heavily based on h1900.c
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/platform_device.h>
20 #include <linux/tty.h>
21 #include <linux/sched.h>
23 #include <linux/bootmem.h>
26 #include <asm/mach-types.h>
27 #include <asm/hardware.h>
28 #include <asm/setup.h>
29 #include <asm/types.h>
30 #include <asm/delay.h>
32 #include <asm/mach/irq.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35 #include <asm/arch/pxa-regs.h>
36 #include <asm/arch/irq.h>
37 #include <asm/arch/ipaq.h>
38 #include <asm/arch/pxafb.h>
39 #include <asm/arch/udc.h>
41 #include <asm/hardware/ipaq-ops.h>
42 #include <asm/arch/himalaya-gpio.h>
43 #include <asm/hardware/ipaq-asic3.h>
44 #include <asm/arch-pxa/himalaya_asic.h>
46 #include <linux/serial_core.h>
48 #include "../generic.h"
50 #include <linux/lcd.h>
51 #include <linux/backlight.h>
53 #include <linux/soc/asic3_base.h>
54 #include <asm-arm/arch-pxa/serial.h>
56 struct ipaq_model_ops ipaq_model_ops
;
57 EXPORT_SYMBOL(ipaq_model_ops
);
59 extern struct platform_device himalaya_asic3
;
60 struct platform_pxa_serial_funcs pxa_serial_funcs
[] = {
61 {}, /* No special FFUART options */
62 {}, /* No special BTUART options */
63 {}, /* No special STUART options */
65 /* Machine-specific code may want to replace the functions */
66 EXPORT_SYMBOL (pxa_serial_funcs
);
68 static void msleep(unsigned int msec
)
70 current
->state
= TASK_INTERRUPTIBLE
;
71 schedule_timeout( (msec
* HZ
+ 999) / 1000);
74 static struct ipaq_model_ops himalaya_model_ops __initdata
= {
75 .generic_name
= "himalaya",
79 static irqreturn_t
himalaya_rs232_irq(int irq
, void *dev_id
)
83 if ((GPLR(GPIO_NR_HIMALAYA_RS232_IN
) & GPIO_bit(GPIO_NR_HIMALAYA_RS232_IN
)))
87 printk("Himalaya: RS232 connected\n");
88 GPDR(GPIO_NR_HIMALAYA_UART_POWER
) |= GPIO_bit(GPIO_NR_HIMALAYA_UART_POWER
);
89 GPSR(GPIO_NR_HIMALAYA_UART_POWER
) = GPIO_bit(GPIO_NR_HIMALAYA_UART_POWER
);
90 asic3_set_gpio_dir_a(&himalaya_asic3
.dev
, GPIOA_RS232_ON
, GPIOA_RS232_ON
);
91 asic3_set_gpio_out_a(&himalaya_asic3
.dev
, GPIOA_RS232_ON
, GPIOA_RS232_ON
);
93 printk("Himalaya: RS232 disconnected\n");
94 GPDR(GPIO_NR_HIMALAYA_UART_POWER
) |= GPIO_bit(GPIO_NR_HIMALAYA_UART_POWER
);
95 GPCR(GPIO_NR_HIMALAYA_UART_POWER
) = GPIO_bit(GPIO_NR_HIMALAYA_UART_POWER
);
96 asic3_set_gpio_dir_a(&himalaya_asic3
.dev
, GPIOA_RS232_ON
, GPIOA_RS232_ON
);
97 asic3_set_gpio_out_a(&himalaya_asic3
.dev
, GPIOA_RS232_ON
, 0);
102 static struct irqaction himalaya_rs232_irqaction
= {
103 name
: "himalaya_rs232",
104 handler
: himalaya_rs232_irq
,
109 static void __init
himalaya_init_irq( void )
111 /* Initialize standard IRQs */
115 setup_irq (IRQ_NR_HIMALAYA_RS232_IN
, &himalaya_rs232_irqaction
);
116 set_irq_type (IRQ_NR_HIMALAYA_RS232_IN
, IRQT_BOTHEDGE
);
120 static void ser_ffuart_gpio_config(int mode
)
123 * full-function uart initialisation: set this up too.
125 * even though the bootloader (xscale.S) loads them up,
126 * we blatted them all, above!
129 GPDR(GPIO_NR_HIMALAYA_UART_POWER
) |= GPIO_bit(GPIO_NR_HIMALAYA_UART_POWER
);
130 GPSR(GPIO_NR_HIMALAYA_UART_POWER
) = GPIO_bit(GPIO_NR_HIMALAYA_UART_POWER
);
132 /* for good measure, power on the rs232 uart */
133 asic3_set_gpio_dir_a(&himalaya_asic3
.dev
, GPIOA_RS232_ON
, GPIOA_RS232_ON
);
134 asic3_set_gpio_out_a(&himalaya_asic3
.dev
, GPIOA_RS232_ON
, GPIOA_RS232_ON
);
136 /* okay. from radio_extbootldr, we have to clear the
137 * gpio36 alt-gpio, set the direction to out,
138 * and set the gpio36 line high.
140 * lkcl01jan2006: the pxa_gpio_op() function is what i used
141 * to get this sequence right. what was replaced here -
142 * a call to pxa_gpio_mode() and a manual GADR(...) call -
143 * was complete rubbish.
145 * using pxa_gpio_op() is _so_ much more obvious and simple.
148 printk("gsm reset\n");
149 pxa_gpio_op(GPIO36_FFDCD
, GPIO_MD_MASK_NR
|
150 GPIO_MD_MASK_DIR
| GPIO_MD_MASK_FN
,
153 // set GPIO 36 to high.
154 pxa_gpio_op(GPIO36_FFDCD
, GPIO_MD_MASK_SET
, GPIO_MD_HIGH
);
156 /* then power on the gsm (and out direction for good measure) */
157 printk("gsm reset gpio off\n");
158 asic3_set_gpio_dir_a(&himalaya_asic3
.dev
, GPIOA_USB_ON_N
, 0);
160 asic3_set_gpio_out_b(&himalaya_asic3
.dev
, GPIOB_GSM_RESET
, 0);
163 /* then switch it off... */
164 printk("gsm reset gpio on\n");
165 asic3_set_gpio_out_b(&himalaya_asic3
.dev
, GPIOB_GSM_RESET
, GPIOB_GSM_RESET
);
168 /* then switch it on again... */
169 printk("gsm reset gpio off\n");
170 asic3_set_gpio_out_b(&himalaya_asic3
.dev
, GPIOB_GSM_RESET
, 0);
173 /* and finally, enable the gpio thingy. set all of them just for fun */
174 //pxa_gpio_mode(GPIO34_FFRXD_MD);
175 //pxa_gpio_mode(GPIO35_FFCTS_MD);
176 pxa_gpio_mode(GPIO36_FFDCD_MD
);
177 //pxa_gpio_mode(GPIO37_FFDSR_MD);
178 //pxa_gpio_mode(GPIO38_FFRI_MD);
179 //pxa_gpio_mode(GPIO39_FFTXD_MD);
180 //pxa_gpio_mode(GPIO40_FFDTR_MD);
181 //pxa_gpio_mode(GPIO41_FFRTS_MD);
182 //pxa_gpio_op(GPIO36_FFDCD, GPIO_MD_MASK_SET, 0);
184 asic3_set_gpio_out_b(&himalaya_asic3
.dev
, GPIOB_GSM_RESET
, GPIOB_GSM_RESET
);
185 asic3_set_gpio_dir_a(&himalaya_asic3
.dev
, GPIOA_USB_ON_N
, GPIOA_USB_ON_N
);
186 asic3_set_gpio_out_a(&himalaya_asic3
.dev
, GPIOA_USB_ON_N
, GPIOA_USB_ON_N
);
190 static void ser_stuart_gpio_config(int mode
)
192 /* standard uart initialisation: might as well get it over with, here... */
193 /* the standard uart apparently deals with GSM commands */
194 //pxa_gpio_mode(GPIO46_STRXD_MD); // STD_UART receive data
195 //pxa_gpio_mode(GPIO47_STTXD_MD); // STD_UART transmit data
197 GPDR(GPIO_NR_HIMALAYA_UART_POWER
) |= GPIO_bit(GPIO_NR_HIMALAYA_UART_POWER
);
198 GPSR(GPIO_NR_HIMALAYA_UART_POWER
) = GPIO_bit(GPIO_NR_HIMALAYA_UART_POWER
);
200 asic3_set_gpio_dir_a(&himalaya_asic3
.dev
, GPIOA_RS232_ON
, GPIOA_RS232_ON
);
201 asic3_set_gpio_out_a(&himalaya_asic3
.dev
, GPIOA_RS232_ON
, GPIOA_RS232_ON
);
203 asic3_set_gpio_dir_b(&himalaya_asic3
.dev
, GPIOB_GSM_RESET
, GPIOB_GSM_RESET
);
205 pxa_gpio_op(GPIO36_FFDCD
, GPIO_MD_MASK_NR
|
206 GPIO_MD_MASK_DIR
| GPIO_MD_MASK_FN
,
209 // set GPIO36 to high
210 pxa_gpio_op(GPIO36_FFDCD
, GPIO_MD_MASK_SET
, GPIO_MD_HIGH
);
212 /* okay. from radio_extbootldr, we have to clear the
213 * gpio36 alt-gpio, set the direction to out,
214 * and set the gpio36 line high.
217 printk("gsm reset\n");
218 //asic3_set_gpio_dir_a(&himalaya_asic3.dev, 1<<2, 1<<2);
219 //asic3_set_gpio_out_a(&himalaya_asic3.dev, 1<<2, 1<<2);
221 asic3_set_gpio_dir_a(&himalaya_asic3
.dev
, 1<<2, 1<<2);
222 asic3_set_gpio_out_a(&himalaya_asic3
.dev
, 1<<2, 0);
224 /* then power on the gsm */
225 printk("gsm reset gpio off\n");
226 asic3_set_gpio_out_b(&himalaya_asic3
.dev
, GPIOB_GSM_RESET
, 0);
229 /* then switch it off... */
230 printk("gsm reset gpio on\n");
231 asic3_set_gpio_out_b(&himalaya_asic3
.dev
, GPIOB_GSM_RESET
, GPIOB_GSM_RESET
);
234 /* then switch it on again... */
235 printk("gsm reset gpio off\n");
236 asic3_set_gpio_out_b(&himalaya_asic3
.dev
, GPIOB_GSM_RESET
, 0);
239 //asic3_set_gpio_out_b(&himalaya_asic3.dev, GPIOB_GSM_RESET, GPIOB_GSM_RESET);
240 //asic3_set_gpio_dir_a(&himalaya_asic3.dev, 1<<2, 1<<2);
241 //asic3_set_gpio_out_a(&himalaya_asic3.dev, 1<<2, 1<<2);
243 pxa_gpio_op(GPIO36_FFDCD
, GPIO_MD_MASK_NR
|
247 //asic3_set_gpio_dir_a(&himalaya_asic3.dev, GPIOA_USB_ON_N, GPIOA_USB_ON_N);
248 //asic3_set_gpio_out_a(&himalaya_asic3.dev, GPIOA_RS232_ON, GPIOA_RS232_ON);
250 //asic3_set_gpio_out_b(&himalaya_asic3.dev, GPIOB_GSM_RESET, GPIOB_GSM_RESET);
254 #define H3900_ASIC3_VIRT 0xf3800000
255 static struct map_desc himalaya_io_desc
[] __initdata
= {
256 /* virtual physical length domain */
257 { 0xf5000000, 0x08000000, 0x00020000, MT_DEVICE
}, /* ATI chip */
258 { 0xfd000000, 0x04000000, 0x00010000, MT_DEVICE
}, /* ATI chip */
259 { H3900_ASIC3_VIRT
, HIMALAYA_ASIC3_PHYS
, 0x02000000, MT_DEVICE
}, /* static memory bank 3 CS#3 */
261 { 0xfb000000, 0x41000000, 0x01000000, MT_DEVICE
}, /* SPI interface? */
267 int himalaya_boardid
;
268 EXPORT_SYMBOL(himalaya_boardid
);
270 static void himalaya_get_boardid(void)
272 unsigned int *ptr
= (unsigned int *) (H3900_ASIC3_VIRT
+ _IPAQ_ASIC3_GPIO_C_Base
+ _IPAQ_ASIC3_GPIO_Status
);
273 unsigned int gpioc
= *ptr
;
276 if( gpioc
& GPIOC_BOARDID0
) {
277 himalaya_boardid
|= 1;
279 if( gpioc
& GPIOC_BOARDID1
) {
280 himalaya_boardid
|= 2;
282 if( gpioc
& GPIOC_BOARDID2
) {
283 himalaya_boardid
|= 4;
285 printk("Himalaya Board ID 0x%x\n", himalaya_boardid
);
290 * Common map_io initialization
292 static void __init
himalaya_map_io(void)
298 iotable_init(himalaya_io_desc
, ARRAY_SIZE(himalaya_io_desc
));
299 himalaya_get_boardid();
302 PGSR0
= GPSRx_SleepValue
;
303 PGSR1
= GPSRy_SleepValue
;
304 PGSR2
= GPSRz_SleepValue
;
308 GAFR0_L
= 0x98000000;
309 GAFR0_U
= 0x494A8110;
310 GAFR1_L
= 0x699A8159;
311 GAFR1_U
= 0x0005AAAA;
312 GAFR2_L
= 0xA0000000;
313 GAFR2_U
= 0x00000002;
315 /* don't do these for now because one of them turns the screen to mush */
316 /* reason: the ATI chip gets reset / LCD gets disconnected:
317 * a fade-to-white means that the ati 3200 registers are set incorrectly */
344 /* power up the UARTs which likely got switched off, above */
345 GPDR(GPIO_NR_HIMALAYA_UART_POWER
) |= GPIO_bit(GPIO_NR_HIMALAYA_UART_POWER
);
346 GPSR(GPIO_NR_HIMALAYA_UART_POWER
) = GPIO_bit(GPIO_NR_HIMALAYA_UART_POWER
);
349 pxa_serial_funcs
[2].configure
= (void *) ser_stuart_gpio_config
;
350 pxa_serial_funcs
[0].configure
= (void *) ser_ffuart_gpio_config
;
351 stuart_device
.dev
.platform_data
= &pxa_serial_funcs
[2];
352 ffuart_device
.dev
.platform_data
= &pxa_serial_funcs
[0];
354 /* guess about the STUART and FFUART being 22 power!
355 GPDR(22) |= GPIO_bit(22);
356 GPSR(22) = GPIO_bit(22);
359 /* disable all ongoing DMA */
360 for(i
= 0; i
< 16; i
++) DCSR(i
) = 7;
364 /* Add wakeup on AC plug/unplug (and resume button) */
365 PWER
= PWER_RTC
| PWER_GPIO4
| PWER_GPIO0
;
366 PFER
= PWER_RTC
| PWER_GPIO4
| PWER_GPIO0
;
367 PRER
= PWER_GPIO4
| PWER_GPIO0
;
371 ipaq_model_ops
= himalaya_model_ops
;
376 static struct platform_device himalaya_lcd
= {
377 .name
= "himalaya-lcd",
380 .platform_data
= NULL
,
385 static struct platform_device
*himalaya_asic3_devices
[] __initdata
= {
390 * the ASIC3 should really only be referenced via the asic3_base
391 * module. it contains functions something like asic3_gpio_b_out()
392 * which should really be used rather than macros.
394 * TODO: divorce dependence on h3900 naming.
396 static struct asic3_platform_data asic3_platform_data
= {
399 .init
= 0x406b, /* ou 4063 */
401 .batt_fault_out
= 0x4001,
402 .sleep_conf
= 0x000c, /* or 0x0008 */
403 .alt_function
= 0x9800, /* Caution: need to be set to a correct value */ /* Old : 0000 */
407 .dir
= 0xffff, /* All outputs */
410 .batt_fault_out
= 0x0220,
411 .sleep_conf
= 0x000c, /* or 0x000c */
412 .alt_function
= 0x0000, /* Caution: need to be set to a correct value */
413 /*.init = GPIO3_IR_ON_N | GPIO3_RS232_ON | GPIO3_TEST_POINT_123,
415 .batt_fault_out = 0x0220,
424 .batt_fault_out
= 0xfe00,
425 .sleep_conf
= 0x0008,
426 .alt_function
= 0x0000, /* or 0x0003 */ /* Caution: need to be set to a correct value */
433 .sleep_mask
= 0x0000,
435 .batt_fault_out
= 0x6927,
436 .sleep_conf
= 0x0008,
437 .alt_function
= 0x0000, /* Caution: need to be set to a correct value */
440 .child_platform_devs
= himalaya_asic3_devices
,
441 .num_child_platform_devs
= ARRAY_SIZE(himalaya_asic3_devices
),
445 static struct resource asic3_resources
[] = {
447 .start
= HIMALAYA_ASIC3_PHYS
,
448 .end
= HIMALAYA_ASIC3_PHYS
+ 0xfffff,
449 .flags
= IORESOURCE_MEM
,
452 .start
= IRQ_NR_HIMALAYA_ASIC3
,
453 .end
= IRQ_NR_HIMALAYA_ASIC3
,
454 .flags
= IORESOURCE_IRQ
,
459 /* FIXME: rename h3900_asic to something more generic, in all modules,
460 * or use the same technique like ipaq_model_ops to have a specific
461 * and also a generic name for the same thing
463 struct platform_device himalaya_asic3
= {
466 .num_resources
= ARRAY_SIZE(asic3_resources
),
467 .resource
= asic3_resources
,
469 .platform_data
= &asic3_platform_data
472 EXPORT_SYMBOL(himalaya_asic3
);
475 static struct resource himalayafb_resources
[] = {
479 .flags
= IORESOURCE_MEM
,
484 .flags
= IORESOURCE_IRQ
,
488 static u64 fb_dma_mask
= ~(u64
)0;
490 static struct platform_device himalayafb_device
= {
491 .name
= "himalaya-fb",
494 // Previously, this was &pxa_fb_info.
495 // Since we give priority to platform_data in the driver, this does not make sense.
496 // So, we'll set this to NULL here, and then assign it down in set_pxa_fb_info.
498 .dma_mask
= &fb_dma_mask
,
499 .coherent_dma_mask
= 0xffffffff,
501 .num_resources
= ARRAY_SIZE(himalayafb_resources
),
502 .resource
= himalayafb_resources
,
506 static struct platform_device
*devices
[] __initdata
= {
513 void himalaya_hereiam(void) {
514 // asic3_set_gpio_out_b(&himalaya_asic3.dev, 0x8, 0xfb0);
517 static int himalaya_udc_is_connected(void) {
518 printk("udc_is_connected: request returns %x\n", !(GPLR(GPIO_NR_HIMALAYA_USB_DETECT_N
) & GPIO_bit(GPIO_NR_HIMALAYA_USB_DETECT_N
)));
519 if ((GPLR(GPIO_NR_HIMALAYA_USB_DETECT_N
) & GPIO_bit(GPIO_NR_HIMALAYA_USB_DETECT_N
))) {
520 asic3_set_gpio_dir_a(&himalaya_asic3
.dev
, GPIOA_USB_ON_N
, GPIOA_USB_ON_N
);
521 asic3_set_gpio_out_a(&himalaya_asic3
.dev
, GPIOA_USB_ON_N
, GPIOA_USB_ON_N
);
523 asic3_set_gpio_dir_a(&himalaya_asic3
.dev
, GPIOA_USB_ON_N
, GPIOA_USB_ON_N
);
524 asic3_set_gpio_out_a(&himalaya_asic3
.dev
, GPIOA_USB_ON_N
, 0);
526 return (!(GPLR(GPIO_NR_HIMALAYA_USB_DETECT_N
) & GPIO_bit(GPIO_NR_HIMALAYA_USB_DETECT_N
)));
529 static void himalaya_udc_command(int cmd
) {
531 case PXA2XX_UDC_CMD_DISCONNECT
:
532 printk("_udc_control: disconnect\n");
533 GPDR(GPIO_NR_HIMALAYA_USB_PULLUP_N
) |= GPIO_bit(GPIO_NR_HIMALAYA_USB_PULLUP_N
);
534 GPDR(GPIO_NR_HIMALAYA_CHARGER_EN
) |= GPIO_bit(GPIO_NR_HIMALAYA_CHARGER_EN
);
535 GPSR(GPIO_NR_HIMALAYA_USB_PULLUP_N
) = GPIO_bit(GPIO_NR_HIMALAYA_USB_PULLUP_N
);
536 GPCR(GPIO_NR_HIMALAYA_CHARGER_EN
) = GPIO_bit(GPIO_NR_HIMALAYA_CHARGER_EN
);
537 asic3_set_gpio_dir_a(&himalaya_asic3
.dev
, GPIOA_USB_ON_N
, GPIOA_USB_ON_N
);
538 asic3_set_gpio_out_a(&himalaya_asic3
.dev
, GPIOA_USB_ON_N
, GPIOA_USB_ON_N
);
540 case PXA2XX_UDC_CMD_CONNECT
:
541 printk("_udc_control: connect\n");
542 GPDR(GPIO_NR_HIMALAYA_USB_PULLUP_N
) |= GPIO_bit(GPIO_NR_HIMALAYA_USB_PULLUP_N
);
543 GPDR(GPIO_NR_HIMALAYA_CHARGER_EN
) |= GPIO_bit(GPIO_NR_HIMALAYA_CHARGER_EN
);
544 GPSR(GPIO_NR_HIMALAYA_USB_PULLUP_N
) = GPIO_bit(GPIO_NR_HIMALAYA_USB_PULLUP_N
);
546 GPCR(GPIO_NR_HIMALAYA_USB_PULLUP_N
) = GPIO_bit(GPIO_NR_HIMALAYA_USB_PULLUP_N
);
547 GPSR(GPIO_NR_HIMALAYA_CHARGER_EN
) = GPIO_bit(GPIO_NR_HIMALAYA_CHARGER_EN
);
548 asic3_set_gpio_dir_a(&himalaya_asic3
.dev
, GPIOA_USB_ON_N
, GPIOA_USB_ON_N
);
549 asic3_set_gpio_out_a(&himalaya_asic3
.dev
, GPIOA_USB_ON_N
, 0);
552 printk("_udc_control: unknown command!\n");
557 static struct pxa2xx_udc_mach_info himalaya_udc_mach_info
= {
558 .udc_is_connected
= himalaya_udc_is_connected
,
559 .udc_command
= himalaya_udc_command
,
562 static void __init
himalaya_init(void)
564 platform_add_devices (devices
, ARRAY_SIZE (devices
));
567 himalaya_dump_asic_gpio(0x000);
568 himalaya_dump_asic_gpio(0x100);
569 himalaya_dump_asic_gpio(0x200);
570 himalaya_dump_asic_gpio(0x300);
573 pxa_set_udc_info(&himalaya_udc_mach_info
);
577 MACHINE_START(HIMALAYA
, "HTC Himalaya")
578 /* MAINTAINER("Xanadux.org")*/
579 .phys_io
= 0x40000000,
580 .io_pg_offst
= (io_p2v(0x40000000) >> 18) & 0xfffc,
581 .boot_params
= 0xa0000100,
582 .map_io
= himalaya_map_io
,
583 .init_irq
= himalaya_init_irq
,
585 .init_machine
= himalaya_init
,