n2100.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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/slab.h>
  26. #include <linux/serial_core.h>
  27. #include <linux/serial_8250.h>
  28. #include <linux/mtd/physmap.h>
  29. #include <linux/i2c.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/reboot.h>
  32. #include <linux/io.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. static struct sys_timer n2100_timer = {
  52. .init = n2100_timer_init,
  53. .offset = iop_gettimeoffset,
  54. };
  55. /*
  56. * N2100 I/O.
  57. */
  58. static struct map_desc n2100_io_desc[] __initdata = {
  59. { /* on-board devices */
  60. .virtual = N2100_UART,
  61. .pfn = __phys_to_pfn(N2100_UART),
  62. .length = 0x00100000,
  63. .type = MT_DEVICE
  64. },
  65. };
  66. void __init n2100_map_io(void)
  67. {
  68. iop3xx_map_io();
  69. iotable_init(n2100_io_desc, ARRAY_SIZE(n2100_io_desc));
  70. }
  71. /*
  72. * N2100 PCI.
  73. */
  74. static int __init
  75. n2100_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  76. {
  77. int irq;
  78. if (PCI_SLOT(dev->devfn) == 1) {
  79. /* RTL8110SB #1 */
  80. irq = IRQ_IOP32X_XINT0;
  81. } else if (PCI_SLOT(dev->devfn) == 2) {
  82. /* RTL8110SB #2 */
  83. irq = IRQ_IOP32X_XINT3;
  84. } else if (PCI_SLOT(dev->devfn) == 3) {
  85. /* Sil3512 */
  86. irq = IRQ_IOP32X_XINT2;
  87. } else if (PCI_SLOT(dev->devfn) == 4 && pin == 1) {
  88. /* VT6212 INTA */
  89. irq = IRQ_IOP32X_XINT1;
  90. } else if (PCI_SLOT(dev->devfn) == 4 && pin == 2) {
  91. /* VT6212 INTB */
  92. irq = IRQ_IOP32X_XINT0;
  93. } else if (PCI_SLOT(dev->devfn) == 4 && pin == 3) {
  94. /* VT6212 INTC */
  95. irq = IRQ_IOP32X_XINT2;
  96. } else if (PCI_SLOT(dev->devfn) == 5) {
  97. /* Mini-PCI slot */
  98. irq = IRQ_IOP32X_XINT3;
  99. } else {
  100. printk(KERN_ERR "n2100_pci_map_irq() called for unknown "
  101. "device PCI:%d:%d:%d\n", dev->bus->number,
  102. PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
  103. irq = -1;
  104. }
  105. return irq;
  106. }
  107. static struct hw_pci n2100_pci __initdata = {
  108. .swizzle = pci_std_swizzle,
  109. .nr_controllers = 1,
  110. .setup = iop3xx_pci_setup,
  111. .preinit = iop3xx_pci_preinit,
  112. .scan = iop3xx_pci_scan_bus,
  113. .map_irq = n2100_pci_map_irq,
  114. };
  115. /*
  116. * Both r8169 chips on the n2100 exhibit PCI parity problems. Set
  117. * the ->broken_parity_status flag for both ports so that the r8169
  118. * driver knows it should ignore error interrupts.
  119. */
  120. static void n2100_fixup_r8169(struct pci_dev *dev)
  121. {
  122. if (dev->bus->number == 0 &&
  123. (dev->devfn == PCI_DEVFN(1, 0) ||
  124. dev->devfn == PCI_DEVFN(2, 0)))
  125. dev->broken_parity_status = 1;
  126. }
  127. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, PCI_ANY_ID, n2100_fixup_r8169);
  128. static int __init n2100_pci_init(void)
  129. {
  130. if (machine_is_n2100())
  131. pci_common_init(&n2100_pci);
  132. return 0;
  133. }
  134. subsys_initcall(n2100_pci_init);
  135. /*
  136. * N2100 machine initialisation.
  137. */
  138. static struct physmap_flash_data n2100_flash_data = {
  139. .width = 2,
  140. };
  141. static struct resource n2100_flash_resource = {
  142. .start = 0xf0000000,
  143. .end = 0xf0ffffff,
  144. .flags = IORESOURCE_MEM,
  145. };
  146. static struct platform_device n2100_flash_device = {
  147. .name = "physmap-flash",
  148. .id = 0,
  149. .dev = {
  150. .platform_data = &n2100_flash_data,
  151. },
  152. .num_resources = 1,
  153. .resource = &n2100_flash_resource,
  154. };
  155. static struct plat_serial8250_port n2100_serial_port[] = {
  156. {
  157. .mapbase = N2100_UART,
  158. .membase = (char *)N2100_UART,
  159. .irq = 0,
  160. .flags = UPF_SKIP_TEST,
  161. .iotype = UPIO_MEM,
  162. .regshift = 0,
  163. .uartclk = 1843200,
  164. },
  165. { },
  166. };
  167. static struct resource n2100_uart_resource = {
  168. .start = N2100_UART,
  169. .end = N2100_UART + 7,
  170. .flags = IORESOURCE_MEM,
  171. };
  172. static struct platform_device n2100_serial_device = {
  173. .name = "serial8250",
  174. .id = PLAT8250_DEV_PLATFORM,
  175. .dev = {
  176. .platform_data = n2100_serial_port,
  177. },
  178. .num_resources = 1,
  179. .resource = &n2100_uart_resource,
  180. };
  181. static struct f75375s_platform_data n2100_f75375s = {
  182. .pwm = { 255, 255 },
  183. .pwm_enable = { 0, 0 },
  184. };
  185. static struct pca9532_platform_data n2100_leds = {
  186. .leds = {
  187. { .name = "n2100:red:satafail0",
  188. .state = PCA9532_OFF,
  189. .type = PCA9532_TYPE_LED,
  190. },
  191. { .name = "n2100:red:satafail1",
  192. .state = PCA9532_OFF,
  193. .type = PCA9532_TYPE_LED,
  194. },
  195. { .name = "n2100:blue:usb",
  196. .state = PCA9532_OFF,
  197. .type = PCA9532_TYPE_LED,
  198. },
  199. { .type = PCA9532_TYPE_NONE },
  200. { .type = PCA9532_TYPE_NONE },
  201. { .type = PCA9532_TYPE_NONE },
  202. { .type = PCA9532_TYPE_NONE },
  203. { .name = "n2100:red:usb",
  204. .state = PCA9532_OFF,
  205. .type = PCA9532_TYPE_LED,
  206. },
  207. { .type = PCA9532_TYPE_NONE }, /* power OFF gpio */
  208. { .type = PCA9532_TYPE_NONE }, /* reset gpio */
  209. { .type = PCA9532_TYPE_NONE },
  210. { .type = PCA9532_TYPE_NONE },
  211. { .type = PCA9532_TYPE_NONE },
  212. { .name = "n2100:orange:system",
  213. .state = PCA9532_OFF,
  214. .type = PCA9532_TYPE_LED,
  215. },
  216. { .name = "n2100:red:system",
  217. .state = PCA9532_OFF,
  218. .type = PCA9532_TYPE_LED,
  219. },
  220. { .name = "N2100 beeper" ,
  221. .state = PCA9532_OFF,
  222. .type = PCA9532_TYPE_N2100_BEEP,
  223. },
  224. },
  225. .psc = { 0, 0 },
  226. .pwm = { 0, 0 },
  227. };
  228. static struct i2c_board_info __initdata n2100_i2c_devices[] = {
  229. {
  230. I2C_BOARD_INFO("rs5c372b", 0x32),
  231. },
  232. {
  233. I2C_BOARD_INFO("f75375", 0x2e),
  234. .platform_data = &n2100_f75375s,
  235. },
  236. {
  237. I2C_BOARD_INFO("pca9532", 0x60),
  238. .platform_data = &n2100_leds,
  239. },
  240. };
  241. /*
  242. * Pull PCA9532 GPIO #8 low to power off the machine.
  243. */
  244. static void n2100_power_off(void)
  245. {
  246. local_irq_disable();
  247. /* Start condition, I2C address of PCA9532, write transaction. */
  248. *IOP3XX_IDBR0 = 0xc0;
  249. *IOP3XX_ICR0 = 0xe9;
  250. mdelay(1);
  251. /* Write address 0x08. */
  252. *IOP3XX_IDBR0 = 0x08;
  253. *IOP3XX_ICR0 = 0xe8;
  254. mdelay(1);
  255. /* Write data 0x01, stop condition. */
  256. *IOP3XX_IDBR0 = 0x01;
  257. *IOP3XX_ICR0 = 0xea;
  258. while (1)
  259. ;
  260. }
  261. static struct timer_list power_button_poll_timer;
  262. static void power_button_poll(unsigned long dummy)
  263. {
  264. if (gpio_line_get(N2100_POWER_BUTTON) == 0) {
  265. ctrl_alt_del();
  266. return;
  267. }
  268. power_button_poll_timer.expires = jiffies + (HZ / 10);
  269. add_timer(&power_button_poll_timer);
  270. }
  271. static void __init n2100_init_machine(void)
  272. {
  273. platform_device_register(&iop3xx_i2c0_device);
  274. platform_device_register(&n2100_flash_device);
  275. platform_device_register(&n2100_serial_device);
  276. platform_device_register(&iop3xx_dma_0_channel);
  277. platform_device_register(&iop3xx_dma_1_channel);
  278. i2c_register_board_info(0, n2100_i2c_devices,
  279. ARRAY_SIZE(n2100_i2c_devices));
  280. pm_power_off = n2100_power_off;
  281. init_timer(&power_button_poll_timer);
  282. power_button_poll_timer.function = power_button_poll;
  283. power_button_poll_timer.expires = jiffies + (HZ / 10);
  284. add_timer(&power_button_poll_timer);
  285. }
  286. MACHINE_START(N2100, "Thecus N2100")
  287. /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */
  288. .phys_io = N2100_UART,
  289. .io_pg_offst = ((N2100_UART) >> 18) & 0xfffc,
  290. .boot_params = 0xa0000100,
  291. .map_io = n2100_map_io,
  292. .init_irq = iop32x_init_irq,
  293. .timer = &n2100_timer,
  294. .init_machine = n2100_init_machine,
  295. MACHINE_END