board-voiceblue.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * linux/arch/arm/mach-omap1/board-voiceblue.c
  3. *
  4. * Modified from board-generic.c
  5. *
  6. * Copyright (C) 2004 2N Telekomunikace, Ladislav Michl <michl@2n.cz>
  7. *
  8. * Code for OMAP5910 based VoiceBlue board (VoIP to GSM gateway).
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/gpio.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/irq.h>
  19. #include <linux/init.h>
  20. #include <linux/kernel.h>
  21. #include <linux/mtd/physmap.h>
  22. #include <linux/notifier.h>
  23. #include <linux/reboot.h>
  24. #include <linux/serial_8250.h>
  25. #include <linux/serial_reg.h>
  26. #include <linux/smc91x.h>
  27. #include <linux/export.h>
  28. #include <asm/mach-types.h>
  29. #include <asm/mach/arch.h>
  30. #include <asm/mach/map.h>
  31. #include <mach/board-voiceblue.h>
  32. #include <mach/flash.h>
  33. #include <mach/mux.h>
  34. #include <mach/tc.h>
  35. #include <mach/hardware.h>
  36. #include <mach/usb.h>
  37. #include "common.h"
  38. static struct plat_serial8250_port voiceblue_ports[] = {
  39. {
  40. .mapbase = (unsigned long)(OMAP_CS1_PHYS + 0x40000),
  41. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  42. .iotype = UPIO_MEM,
  43. .regshift = 1,
  44. .uartclk = 3686400,
  45. },
  46. {
  47. .mapbase = (unsigned long)(OMAP_CS1_PHYS + 0x50000),
  48. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  49. .iotype = UPIO_MEM,
  50. .regshift = 1,
  51. .uartclk = 3686400,
  52. },
  53. {
  54. .mapbase = (unsigned long)(OMAP_CS1_PHYS + 0x60000),
  55. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  56. .iotype = UPIO_MEM,
  57. .regshift = 1,
  58. .uartclk = 3686400,
  59. },
  60. {
  61. .mapbase = (unsigned long)(OMAP_CS1_PHYS + 0x70000),
  62. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  63. .iotype = UPIO_MEM,
  64. .regshift = 1,
  65. .uartclk = 3686400,
  66. },
  67. { },
  68. };
  69. static struct platform_device serial_device = {
  70. .name = "serial8250",
  71. .id = PLAT8250_DEV_PLATFORM1,
  72. };
  73. static int __init ext_uart_init(void)
  74. {
  75. if (!machine_is_voiceblue())
  76. return -ENODEV;
  77. voiceblue_ports[0].irq = gpio_to_irq(12);
  78. voiceblue_ports[1].irq = gpio_to_irq(13);
  79. voiceblue_ports[2].irq = gpio_to_irq(14);
  80. voiceblue_ports[3].irq = gpio_to_irq(15);
  81. serial_device.dev.platform_data = voiceblue_ports;
  82. return platform_device_register(&serial_device);
  83. }
  84. arch_initcall(ext_uart_init);
  85. static struct physmap_flash_data voiceblue_flash_data = {
  86. .width = 2,
  87. .set_vpp = omap1_set_vpp,
  88. };
  89. static struct resource voiceblue_flash_resource = {
  90. .start = OMAP_CS0_PHYS,
  91. .end = OMAP_CS0_PHYS + SZ_32M - 1,
  92. .flags = IORESOURCE_MEM,
  93. };
  94. static struct platform_device voiceblue_flash_device = {
  95. .name = "physmap-flash",
  96. .id = 0,
  97. .dev = {
  98. .platform_data = &voiceblue_flash_data,
  99. },
  100. .num_resources = 1,
  101. .resource = &voiceblue_flash_resource,
  102. };
  103. static struct smc91x_platdata voiceblue_smc91x_info = {
  104. .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
  105. .leda = RPC_LED_100_10,
  106. .ledb = RPC_LED_TX_RX,
  107. };
  108. static struct resource voiceblue_smc91x_resources[] = {
  109. [0] = {
  110. .start = OMAP_CS2_PHYS + 0x300,
  111. .end = OMAP_CS2_PHYS + 0x300 + 16,
  112. .flags = IORESOURCE_MEM,
  113. },
  114. [1] = {
  115. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  116. },
  117. };
  118. static struct platform_device voiceblue_smc91x_device = {
  119. .name = "smc91x",
  120. .id = 0,
  121. .dev = {
  122. .platform_data = &voiceblue_smc91x_info,
  123. },
  124. .num_resources = ARRAY_SIZE(voiceblue_smc91x_resources),
  125. .resource = voiceblue_smc91x_resources,
  126. };
  127. static struct platform_device *voiceblue_devices[] __initdata = {
  128. &voiceblue_flash_device,
  129. &voiceblue_smc91x_device,
  130. };
  131. static struct omap_usb_config voiceblue_usb_config __initdata = {
  132. .hmc_mode = 3,
  133. .register_host = 1,
  134. .register_dev = 1,
  135. .pins[0] = 2,
  136. .pins[1] = 6,
  137. .pins[2] = 6,
  138. };
  139. #define MACHINE_PANICED 1
  140. #define MACHINE_REBOOTING 2
  141. #define MACHINE_REBOOT 4
  142. static unsigned long machine_state;
  143. static int panic_event(struct notifier_block *this, unsigned long event,
  144. void *ptr)
  145. {
  146. if (test_and_set_bit(MACHINE_PANICED, &machine_state))
  147. return NOTIFY_DONE;
  148. /* Flash power LED */
  149. omap_writeb(0x78, OMAP_LPG1_LCR);
  150. omap_writeb(0x01, OMAP_LPG1_PMR); /* Enable clock */
  151. return NOTIFY_DONE;
  152. }
  153. static struct notifier_block panic_block = {
  154. .notifier_call = panic_event,
  155. };
  156. static int __init voiceblue_setup(void)
  157. {
  158. if (!machine_is_voiceblue())
  159. return -ENODEV;
  160. /* Setup panic notifier */
  161. atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
  162. return 0;
  163. }
  164. postcore_initcall(voiceblue_setup);
  165. static int wdt_gpio_state;
  166. void voiceblue_wdt_enable(void)
  167. {
  168. gpio_direction_output(0, 0);
  169. gpio_set_value(0, 1);
  170. gpio_set_value(0, 0);
  171. wdt_gpio_state = 0;
  172. }
  173. void voiceblue_wdt_disable(void)
  174. {
  175. gpio_set_value(0, 0);
  176. gpio_set_value(0, 1);
  177. gpio_set_value(0, 0);
  178. gpio_direction_input(0);
  179. }
  180. void voiceblue_wdt_ping(void)
  181. {
  182. if (test_bit(MACHINE_REBOOT, &machine_state))
  183. return;
  184. wdt_gpio_state = !wdt_gpio_state;
  185. gpio_set_value(0, wdt_gpio_state);
  186. }
  187. static void voiceblue_restart(char mode, const char *cmd)
  188. {
  189. /*
  190. * Workaround for 5912/1611b bug mentioned in sprz209d.pdf p. 28
  191. * "Global Software Reset Affects Traffic Controller Frequency".
  192. */
  193. if (cpu_is_omap5912()) {
  194. omap_writew(omap_readw(DPLL_CTL) & ~(1 << 4), DPLL_CTL);
  195. omap_writew(0x8, ARM_RSTCT1);
  196. }
  197. set_bit(MACHINE_REBOOT, &machine_state);
  198. voiceblue_wdt_enable();
  199. while (1) ;
  200. }
  201. EXPORT_SYMBOL(voiceblue_wdt_enable);
  202. EXPORT_SYMBOL(voiceblue_wdt_disable);
  203. EXPORT_SYMBOL(voiceblue_wdt_ping);
  204. static void __init voiceblue_init(void)
  205. {
  206. /* mux pins for uarts */
  207. omap_cfg_reg(UART1_TX);
  208. omap_cfg_reg(UART1_RTS);
  209. omap_cfg_reg(UART2_TX);
  210. omap_cfg_reg(UART2_RTS);
  211. omap_cfg_reg(UART3_TX);
  212. omap_cfg_reg(UART3_RX);
  213. /* Watchdog */
  214. gpio_request(0, "Watchdog");
  215. /* smc91x reset */
  216. gpio_request(7, "SMC91x reset");
  217. gpio_direction_output(7, 1);
  218. udelay(2); /* wait at least 100ns */
  219. gpio_set_value(7, 0);
  220. mdelay(50); /* 50ms until PHY ready */
  221. /* smc91x interrupt pin */
  222. gpio_request(8, "SMC91x irq");
  223. /* 16C554 reset*/
  224. gpio_request(6, "16C554 reset");
  225. gpio_direction_output(6, 0);
  226. /* 16C554 interrupt pins */
  227. gpio_request(12, "16C554 irq");
  228. gpio_request(13, "16C554 irq");
  229. gpio_request(14, "16C554 irq");
  230. gpio_request(15, "16C554 irq");
  231. irq_set_irq_type(gpio_to_irq(12), IRQ_TYPE_EDGE_RISING);
  232. irq_set_irq_type(gpio_to_irq(13), IRQ_TYPE_EDGE_RISING);
  233. irq_set_irq_type(gpio_to_irq(14), IRQ_TYPE_EDGE_RISING);
  234. irq_set_irq_type(gpio_to_irq(15), IRQ_TYPE_EDGE_RISING);
  235. voiceblue_smc91x_resources[1].start = gpio_to_irq(8);
  236. voiceblue_smc91x_resources[1].end = gpio_to_irq(8);
  237. platform_add_devices(voiceblue_devices, ARRAY_SIZE(voiceblue_devices));
  238. omap_serial_init();
  239. omap1_usb_init(&voiceblue_usb_config);
  240. omap_register_i2c_bus(1, 100, NULL, 0);
  241. /* There is a good chance board is going up, so enable power LED
  242. * (it is connected through invertor) */
  243. omap_writeb(0x00, OMAP_LPG1_LCR);
  244. omap_writeb(0x00, OMAP_LPG1_PMR); /* Disable clock */
  245. }
  246. MACHINE_START(VOICEBLUE, "VoiceBlue OMAP5910")
  247. /* Maintainer: Ladislav Michl <michl@2n.cz> */
  248. .atag_offset = 0x100,
  249. .map_io = omap15xx_map_io,
  250. .init_early = omap1_init_early,
  251. .init_irq = omap1_init_irq,
  252. .init_machine = voiceblue_init,
  253. .init_late = omap1_init_late,
  254. .init_time = omap1_timer_init,
  255. .restart = voiceblue_restart,
  256. MACHINE_END