badge4.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. * linux/arch/arm/mach-sa1100/badge4.c
  3. *
  4. * BadgePAD 4 specific initialization
  5. *
  6. * Tim Connors <connors@hpl.hp.com>
  7. * Christopher Hoover <ch@hpl.hp.com>
  8. *
  9. * Copyright (C) 2002 Hewlett-Packard Company
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. *
  15. */
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/platform_data/sa11x0-serial.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/delay.h>
  22. #include <linux/tty.h>
  23. #include <linux/mtd/mtd.h>
  24. #include <linux/mtd/partitions.h>
  25. #include <linux/errno.h>
  26. #include <linux/gpio.h>
  27. #include <linux/leds.h>
  28. #include <mach/hardware.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/setup.h>
  31. #include <mach/irqs.h>
  32. #include <asm/mach/arch.h>
  33. #include <asm/mach/flash.h>
  34. #include <asm/mach/map.h>
  35. #include <asm/hardware/sa1111.h>
  36. #include <mach/badge4.h>
  37. #include "generic.h"
  38. static struct resource sa1111_resources[] = {
  39. [0] = DEFINE_RES_MEM(BADGE4_SA1111_BASE, 0x2000),
  40. [1] = DEFINE_RES_IRQ(BADGE4_IRQ_GPIO_SA1111),
  41. };
  42. static int badge4_sa1111_enable(void *data, unsigned devid)
  43. {
  44. if (devid == SA1111_DEVID_USB)
  45. badge4_set_5V(BADGE4_5V_USB, 1);
  46. return 0;
  47. }
  48. static void badge4_sa1111_disable(void *data, unsigned devid)
  49. {
  50. if (devid == SA1111_DEVID_USB)
  51. badge4_set_5V(BADGE4_5V_USB, 0);
  52. }
  53. static struct sa1111_platform_data sa1111_info = {
  54. .disable_devs = SA1111_DEVID_PS2_MSE,
  55. .enable = badge4_sa1111_enable,
  56. .disable = badge4_sa1111_disable,
  57. };
  58. static u64 sa1111_dmamask = 0xffffffffUL;
  59. static struct platform_device sa1111_device = {
  60. .name = "sa1111",
  61. .id = 0,
  62. .dev = {
  63. .dma_mask = &sa1111_dmamask,
  64. .coherent_dma_mask = 0xffffffff,
  65. .platform_data = &sa1111_info,
  66. },
  67. .num_resources = ARRAY_SIZE(sa1111_resources),
  68. .resource = sa1111_resources,
  69. };
  70. /* LEDs */
  71. struct gpio_led badge4_gpio_leds[] = {
  72. {
  73. .name = "badge4:red",
  74. .default_trigger = "heartbeat",
  75. .gpio = 7,
  76. },
  77. {
  78. .name = "badge4:green",
  79. .default_trigger = "cpu0",
  80. .gpio = 9,
  81. },
  82. };
  83. static struct gpio_led_platform_data badge4_gpio_led_info = {
  84. .leds = badge4_gpio_leds,
  85. .num_leds = ARRAY_SIZE(badge4_gpio_leds),
  86. };
  87. static struct platform_device badge4_leds = {
  88. .name = "leds-gpio",
  89. .id = -1,
  90. .dev = {
  91. .platform_data = &badge4_gpio_led_info,
  92. }
  93. };
  94. static struct platform_device *devices[] __initdata = {
  95. &sa1111_device,
  96. &badge4_leds,
  97. };
  98. static int __init badge4_sa1111_init(void)
  99. {
  100. /*
  101. * Ensure that the memory bus request/grant signals are setup,
  102. * and the grant is held in its inactive state
  103. */
  104. sa1110_mb_disable();
  105. /*
  106. * Probe for SA1111.
  107. */
  108. return platform_add_devices(devices, ARRAY_SIZE(devices));
  109. }
  110. /*
  111. * 1 x Intel 28F320C3 Advanced+ Boot Block Flash (32 Mi bit)
  112. * Eight 4 KiW Parameter Bottom Blocks (64 KiB)
  113. * Sixty-three 32 KiW Main Blocks (4032 Ki b)
  114. *
  115. * <or>
  116. *
  117. * 1 x Intel 28F640C3 Advanced+ Boot Block Flash (64 Mi bit)
  118. * Eight 4 KiW Parameter Bottom Blocks (64 KiB)
  119. * One-hundred-twenty-seven 32 KiW Main Blocks (8128 Ki b)
  120. */
  121. static struct mtd_partition badge4_partitions[] = {
  122. {
  123. .name = "BLOB boot loader",
  124. .offset = 0,
  125. .size = 0x0000A000
  126. }, {
  127. .name = "params",
  128. .offset = MTDPART_OFS_APPEND,
  129. .size = 0x00006000
  130. }, {
  131. .name = "root",
  132. .offset = MTDPART_OFS_APPEND,
  133. .size = MTDPART_SIZ_FULL
  134. }
  135. };
  136. static struct flash_platform_data badge4_flash_data = {
  137. .map_name = "cfi_probe",
  138. .parts = badge4_partitions,
  139. .nr_parts = ARRAY_SIZE(badge4_partitions),
  140. };
  141. static struct resource badge4_flash_resource =
  142. DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_64M);
  143. static int five_v_on __initdata = 0;
  144. static int __init five_v_on_setup(char *ignore)
  145. {
  146. five_v_on = 1;
  147. return 1;
  148. }
  149. __setup("five_v_on", five_v_on_setup);
  150. static int __init badge4_init(void)
  151. {
  152. int ret;
  153. if (!machine_is_badge4())
  154. return -ENODEV;
  155. /* LCD */
  156. GPCR = (BADGE4_GPIO_LGP2 | BADGE4_GPIO_LGP3 |
  157. BADGE4_GPIO_LGP4 | BADGE4_GPIO_LGP5 |
  158. BADGE4_GPIO_LGP6 | BADGE4_GPIO_LGP7 |
  159. BADGE4_GPIO_LGP8 | BADGE4_GPIO_LGP9 |
  160. BADGE4_GPIO_GPA_VID | BADGE4_GPIO_GPB_VID |
  161. BADGE4_GPIO_GPC_VID);
  162. GPDR &= ~BADGE4_GPIO_INT_VID;
  163. GPDR |= (BADGE4_GPIO_LGP2 | BADGE4_GPIO_LGP3 |
  164. BADGE4_GPIO_LGP4 | BADGE4_GPIO_LGP5 |
  165. BADGE4_GPIO_LGP6 | BADGE4_GPIO_LGP7 |
  166. BADGE4_GPIO_LGP8 | BADGE4_GPIO_LGP9 |
  167. BADGE4_GPIO_GPA_VID | BADGE4_GPIO_GPB_VID |
  168. BADGE4_GPIO_GPC_VID);
  169. /* SDRAM SPD i2c */
  170. GPCR = (BADGE4_GPIO_SDSDA | BADGE4_GPIO_SDSCL);
  171. GPDR |= (BADGE4_GPIO_SDSDA | BADGE4_GPIO_SDSCL);
  172. /* uart */
  173. GPCR = (BADGE4_GPIO_UART_HS1 | BADGE4_GPIO_UART_HS2);
  174. GPDR |= (BADGE4_GPIO_UART_HS1 | BADGE4_GPIO_UART_HS2);
  175. /* CPLD muxsel0 input for mux/adc chip select */
  176. GPCR = BADGE4_GPIO_MUXSEL0;
  177. GPDR |= BADGE4_GPIO_MUXSEL0;
  178. /* test points: J5, J6 as inputs, J7 outputs */
  179. GPDR &= ~(BADGE4_GPIO_TESTPT_J5 | BADGE4_GPIO_TESTPT_J6);
  180. GPCR = BADGE4_GPIO_TESTPT_J7;
  181. GPDR |= BADGE4_GPIO_TESTPT_J7;
  182. /* 5V supply rail. */
  183. GPCR = BADGE4_GPIO_PCMEN5V; /* initially off */
  184. GPDR |= BADGE4_GPIO_PCMEN5V;
  185. /* CPLD sdram type inputs; set up by blob */
  186. //GPDR |= (BADGE4_GPIO_SDTYP1 | BADGE4_GPIO_SDTYP0);
  187. printk(KERN_DEBUG __FILE__ ": SDRAM CPLD typ1=%d typ0=%d\n",
  188. !!(GPLR & BADGE4_GPIO_SDTYP1),
  189. !!(GPLR & BADGE4_GPIO_SDTYP0));
  190. /* SA1111 reset pin; set up by blob */
  191. //GPSR = BADGE4_GPIO_SA1111_NRST;
  192. //GPDR |= BADGE4_GPIO_SA1111_NRST;
  193. /* power management cruft */
  194. PGSR = 0;
  195. PWER = 0;
  196. PCFR = 0;
  197. PSDR = 0;
  198. PWER |= PWER_GPIO26; /* wake up on an edge from TESTPT_J5 */
  199. PWER |= PWER_RTC; /* wake up if rtc fires */
  200. /* drive sa1111_nrst during sleep */
  201. PGSR |= BADGE4_GPIO_SA1111_NRST;
  202. /* drive CPLD as is during sleep */
  203. PGSR |= (GPLR & (BADGE4_GPIO_SDTYP0|BADGE4_GPIO_SDTYP1));
  204. /* Now bring up the SA-1111. */
  205. ret = badge4_sa1111_init();
  206. if (ret < 0)
  207. printk(KERN_ERR
  208. "%s: SA-1111 initialization failed (%d)\n",
  209. __func__, ret);
  210. /* maybe turn on 5v0 from the start */
  211. badge4_set_5V(BADGE4_5V_INITIALLY, five_v_on);
  212. sa11x0_register_mtd(&badge4_flash_data, &badge4_flash_resource, 1);
  213. return 0;
  214. }
  215. arch_initcall(badge4_init);
  216. static unsigned badge4_5V_bitmap = 0;
  217. void badge4_set_5V(unsigned subsystem, int on)
  218. {
  219. unsigned long flags;
  220. unsigned old_5V_bitmap;
  221. local_irq_save(flags);
  222. old_5V_bitmap = badge4_5V_bitmap;
  223. if (on) {
  224. badge4_5V_bitmap |= subsystem;
  225. } else {
  226. badge4_5V_bitmap &= ~subsystem;
  227. }
  228. /* detect on->off and off->on transitions */
  229. if ((!old_5V_bitmap) && (badge4_5V_bitmap)) {
  230. /* was off, now on */
  231. printk(KERN_INFO "%s: enabling 5V supply rail\n", __func__);
  232. GPSR = BADGE4_GPIO_PCMEN5V;
  233. } else if ((old_5V_bitmap) && (!badge4_5V_bitmap)) {
  234. /* was on, now off */
  235. printk(KERN_INFO "%s: disabling 5V supply rail\n", __func__);
  236. GPCR = BADGE4_GPIO_PCMEN5V;
  237. }
  238. local_irq_restore(flags);
  239. }
  240. EXPORT_SYMBOL(badge4_set_5V);
  241. static struct map_desc badge4_io_desc[] __initdata = {
  242. { /* SRAM bank 1 */
  243. .virtual = 0xf1000000,
  244. .pfn = __phys_to_pfn(0x08000000),
  245. .length = 0x00100000,
  246. .type = MT_DEVICE
  247. }, { /* SRAM bank 2 */
  248. .virtual = 0xf2000000,
  249. .pfn = __phys_to_pfn(0x10000000),
  250. .length = 0x00100000,
  251. .type = MT_DEVICE
  252. }
  253. };
  254. static void
  255. badge4_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  256. {
  257. if (!state) {
  258. Ser1SDCR0 |= SDCR0_UART;
  259. }
  260. }
  261. static struct sa1100_port_fns badge4_port_fns __initdata = {
  262. //.get_mctrl = badge4_get_mctrl,
  263. //.set_mctrl = badge4_set_mctrl,
  264. .pm = badge4_uart_pm,
  265. };
  266. static void __init badge4_map_io(void)
  267. {
  268. sa1100_map_io();
  269. iotable_init(badge4_io_desc, ARRAY_SIZE(badge4_io_desc));
  270. sa1100_register_uart_fns(&badge4_port_fns);
  271. sa1100_register_uart(0, 3);
  272. sa1100_register_uart(1, 1);
  273. }
  274. MACHINE_START(BADGE4, "Hewlett-Packard Laboratories BadgePAD 4")
  275. .atag_offset = 0x100,
  276. .map_io = badge4_map_io,
  277. .nr_irqs = SA1100_NR_IRQS,
  278. .init_irq = sa1100_init_irq,
  279. .init_late = sa11x0_init_late,
  280. .init_time = sa1100_timer_init,
  281. #ifdef CONFIG_SA1111
  282. .dma_zone_size = SZ_1M,
  283. #endif
  284. .restart = sa11x0_restart,
  285. MACHINE_END