badge4.c 7.7 KB

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