n2100.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * arch/arm/mach-iop32x/n2100.c
  3. *
  4. * Board support code for the Thecus N2100 platform.
  5. *
  6. * Author: Rory Bolt <rorybolt@pacbell.net>
  7. * Copyright (C) 2002 Rory Bolt
  8. * Copyright 2003 (c) MontaVista, Software, Inc.
  9. * Copyright (C) 2004 Intel Corp.
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. */
  16. #include <linux/mm.h>
  17. #include <linux/init.h>
  18. #include <linux/f75375s.h>
  19. #include <linux/leds-pca9532.h>
  20. #include <linux/delay.h>
  21. #include <linux/kernel.h>
  22. #include <linux/pci.h>
  23. #include <linux/pm.h>
  24. #include <linux/string.h>
  25. #include <linux/serial_core.h>
  26. #include <linux/serial_8250.h>
  27. #include <linux/mtd/physmap.h>
  28. #include <linux/i2c.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/reboot.h>
  31. #include <linux/io.h>
  32. #include <linux/gpio.h>
  33. #include <mach/hardware.h>
  34. #include <asm/irq.h>
  35. #include <asm/mach/arch.h>
  36. #include <asm/mach/map.h>
  37. #include <asm/mach/pci.h>
  38. #include <asm/mach/time.h>
  39. #include <asm/mach-types.h>
  40. #include <asm/page.h>
  41. #include <asm/pgtable.h>
  42. #include <mach/time.h>
  43. /*
  44. * N2100 timer tick configuration.
  45. */
  46. static void __init n2100_timer_init(void)
  47. {
  48. /* 33.000 MHz crystal. */
  49. iop_init_time(198000000);
  50. }
  51. /*
  52. * N2100 I/O.
  53. */
  54. static struct map_desc n2100_io_desc[] __initdata = {
  55. { /* on-board devices */
  56. .virtual = N2100_UART,
  57. .pfn = __phys_to_pfn(N2100_UART),
  58. .length = 0x00100000,
  59. .type = MT_DEVICE
  60. },
  61. };
  62. void __init n2100_map_io(void)
  63. {
  64. iop3xx_map_io();
  65. iotable_init(n2100_io_desc, ARRAY_SIZE(n2100_io_desc));
  66. }
  67. /*
  68. * N2100 PCI.
  69. */
  70. static int __init
  71. n2100_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  72. {
  73. int irq;
  74. if (PCI_SLOT(dev->devfn) == 1) {
  75. /* RTL8110SB #1 */
  76. irq = IRQ_IOP32X_XINT0;
  77. } else if (PCI_SLOT(dev->devfn) == 2) {
  78. /* RTL8110SB #2 */
  79. irq = IRQ_IOP32X_XINT3;
  80. } else if (PCI_SLOT(dev->devfn) == 3) {
  81. /* Sil3512 */
  82. irq = IRQ_IOP32X_XINT2;
  83. } else if (PCI_SLOT(dev->devfn) == 4 && pin == 1) {
  84. /* VT6212 INTA */
  85. irq = IRQ_IOP32X_XINT1;
  86. } else if (PCI_SLOT(dev->devfn) == 4 && pin == 2) {
  87. /* VT6212 INTB */
  88. irq = IRQ_IOP32X_XINT0;
  89. } else if (PCI_SLOT(dev->devfn) == 4 && pin == 3) {
  90. /* VT6212 INTC */
  91. irq = IRQ_IOP32X_XINT2;
  92. } else if (PCI_SLOT(dev->devfn) == 5) {
  93. /* Mini-PCI slot */
  94. irq = IRQ_IOP32X_XINT3;
  95. } else {
  96. printk(KERN_ERR "n2100_pci_map_irq() called for unknown "
  97. "device PCI:%d:%d:%d\n", dev->bus->number,
  98. PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
  99. irq = -1;
  100. }
  101. return irq;
  102. }
  103. static struct hw_pci n2100_pci __initdata = {
  104. .nr_controllers = 1,
  105. .ops = &iop3xx_ops,
  106. .setup = iop3xx_pci_setup,
  107. .preinit = iop3xx_pci_preinit,
  108. .map_irq = n2100_pci_map_irq,
  109. };
  110. /*
  111. * Both r8169 chips on the n2100 exhibit PCI parity problems. Set
  112. * the ->broken_parity_status flag for both ports so that the r8169
  113. * driver knows it should ignore error interrupts.
  114. */
  115. static void n2100_fixup_r8169(struct pci_dev *dev)
  116. {
  117. if (dev->bus->number == 0 &&
  118. (dev->devfn == PCI_DEVFN(1, 0) ||
  119. dev->devfn == PCI_DEVFN(2, 0)))
  120. dev->broken_parity_status = 1;
  121. }
  122. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, PCI_ANY_ID, n2100_fixup_r8169);
  123. static int __init n2100_pci_init(void)
  124. {
  125. if (machine_is_n2100())
  126. pci_common_init(&n2100_pci);
  127. return 0;
  128. }
  129. subsys_initcall(n2100_pci_init);
  130. /*
  131. * N2100 machine initialisation.
  132. */
  133. static struct physmap_flash_data n2100_flash_data = {
  134. .width = 2,
  135. };
  136. static struct resource n2100_flash_resource = {
  137. .start = 0xf0000000,
  138. .end = 0xf0ffffff,
  139. .flags = IORESOURCE_MEM,
  140. };
  141. static struct platform_device n2100_flash_device = {
  142. .name = "physmap-flash",
  143. .id = 0,
  144. .dev = {
  145. .platform_data = &n2100_flash_data,
  146. },
  147. .num_resources = 1,
  148. .resource = &n2100_flash_resource,
  149. };
  150. static struct plat_serial8250_port n2100_serial_port[] = {
  151. {
  152. .mapbase = N2100_UART,
  153. .membase = (char *)N2100_UART,
  154. .irq = 0,
  155. .flags = UPF_SKIP_TEST | UPF_AUTO_IRQ | UPF_SHARE_IRQ,
  156. .iotype = UPIO_MEM,
  157. .regshift = 0,
  158. .uartclk = 1843200,
  159. },
  160. { },
  161. };
  162. static struct resource n2100_uart_resource = {
  163. .start = N2100_UART,
  164. .end = N2100_UART + 7,
  165. .flags = IORESOURCE_MEM,
  166. };
  167. static struct platform_device n2100_serial_device = {
  168. .name = "serial8250",
  169. .id = PLAT8250_DEV_PLATFORM,
  170. .dev = {
  171. .platform_data = n2100_serial_port,
  172. },
  173. .num_resources = 1,
  174. .resource = &n2100_uart_resource,
  175. };
  176. static struct f75375s_platform_data n2100_f75375s = {
  177. .pwm = { 255, 255 },
  178. .pwm_enable = { 0, 0 },
  179. };
  180. static struct pca9532_platform_data n2100_leds = {
  181. .leds = {
  182. { .name = "n2100:red:satafail0",
  183. .state = PCA9532_OFF,
  184. .type = PCA9532_TYPE_LED,
  185. },
  186. { .name = "n2100:red:satafail1",
  187. .state = PCA9532_OFF,
  188. .type = PCA9532_TYPE_LED,
  189. },
  190. { .name = "n2100:blue:usb",
  191. .state = PCA9532_OFF,
  192. .type = PCA9532_TYPE_LED,
  193. },
  194. { .type = PCA9532_TYPE_NONE },
  195. { .type = PCA9532_TYPE_NONE },
  196. { .type = PCA9532_TYPE_NONE },
  197. { .type = PCA9532_TYPE_NONE },
  198. { .name = "n2100:red:usb",
  199. .state = PCA9532_OFF,
  200. .type = PCA9532_TYPE_LED,
  201. },
  202. { .type = PCA9532_TYPE_NONE }, /* power OFF gpio */
  203. { .type = PCA9532_TYPE_NONE }, /* reset gpio */
  204. { .type = PCA9532_TYPE_NONE },
  205. { .type = PCA9532_TYPE_NONE },
  206. { .type = PCA9532_TYPE_NONE },
  207. { .name = "n2100:orange:system",
  208. .state = PCA9532_OFF,
  209. .type = PCA9532_TYPE_LED,
  210. },
  211. { .name = "n2100:red:system",
  212. .state = PCA9532_OFF,
  213. .type = PCA9532_TYPE_LED,
  214. },
  215. { .name = "N2100 beeper" ,
  216. .state = PCA9532_OFF,
  217. .type = PCA9532_TYPE_N2100_BEEP,
  218. },
  219. },
  220. .psc = { 0, 0 },
  221. .pwm = { 0, 0 },
  222. };
  223. static struct i2c_board_info __initdata n2100_i2c_devices[] = {
  224. {
  225. I2C_BOARD_INFO("rs5c372b", 0x32),
  226. },
  227. {
  228. I2C_BOARD_INFO("f75375", 0x2e),
  229. .platform_data = &n2100_f75375s,
  230. },
  231. {
  232. I2C_BOARD_INFO("pca9532", 0x60),
  233. .platform_data = &n2100_leds,
  234. },
  235. };
  236. /*
  237. * Pull PCA9532 GPIO #8 low to power off the machine.
  238. */
  239. static void n2100_power_off(void)
  240. {
  241. local_irq_disable();
  242. /* Start condition, I2C address of PCA9532, write transaction. */
  243. *IOP3XX_IDBR0 = 0xc0;
  244. *IOP3XX_ICR0 = 0xe9;
  245. mdelay(1);
  246. /* Write address 0x08. */
  247. *IOP3XX_IDBR0 = 0x08;
  248. *IOP3XX_ICR0 = 0xe8;
  249. mdelay(1);
  250. /* Write data 0x01, stop condition. */
  251. *IOP3XX_IDBR0 = 0x01;
  252. *IOP3XX_ICR0 = 0xea;
  253. while (1)
  254. ;
  255. }
  256. static void n2100_restart(enum reboot_mode mode, const char *cmd)
  257. {
  258. int ret;
  259. ret = gpio_direction_output(N2100_HARDWARE_RESET, 0);
  260. if (ret) {
  261. pr_crit("could not drive reset GPIO low\n");
  262. return;
  263. }
  264. /* Wait for reset to happen */
  265. while (1)
  266. ;
  267. }
  268. static struct timer_list power_button_poll_timer;
  269. static void power_button_poll(unsigned long dummy)
  270. {
  271. if (gpio_line_get(N2100_POWER_BUTTON) == 0) {
  272. ctrl_alt_del();
  273. return;
  274. }
  275. power_button_poll_timer.expires = jiffies + (HZ / 10);
  276. add_timer(&power_button_poll_timer);
  277. }
  278. static int __init n2100_request_gpios(void)
  279. {
  280. int ret;
  281. if (!machine_is_n2100())
  282. return 0;
  283. ret = gpio_request(N2100_HARDWARE_RESET, "reset");
  284. if (ret)
  285. pr_err("could not request reset GPIO\n");
  286. return 0;
  287. }
  288. device_initcall(n2100_request_gpios);
  289. static void __init n2100_init_machine(void)
  290. {
  291. platform_device_register(&iop3xx_i2c0_device);
  292. platform_device_register(&n2100_flash_device);
  293. platform_device_register(&n2100_serial_device);
  294. platform_device_register(&iop3xx_dma_0_channel);
  295. platform_device_register(&iop3xx_dma_1_channel);
  296. i2c_register_board_info(0, n2100_i2c_devices,
  297. ARRAY_SIZE(n2100_i2c_devices));
  298. pm_power_off = n2100_power_off;
  299. init_timer(&power_button_poll_timer);
  300. power_button_poll_timer.function = power_button_poll;
  301. power_button_poll_timer.expires = jiffies + (HZ / 10);
  302. add_timer(&power_button_poll_timer);
  303. }
  304. MACHINE_START(N2100, "Thecus N2100")
  305. /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */
  306. .atag_offset = 0x100,
  307. .map_io = n2100_map_io,
  308. .init_irq = iop32x_init_irq,
  309. .init_time = n2100_timer_init,
  310. .init_machine = n2100_init_machine,
  311. .restart = n2100_restart,
  312. MACHINE_END