ixdp2351.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. * arch/arm/mach-ixp23xx/ixdp2351.c
  3. *
  4. * IXDP2351 board-specific routines
  5. *
  6. * Author: Deepak Saxena <dsaxena@plexity.net>
  7. *
  8. * Copyright 2005 (c) MontaVista Software, Inc.
  9. *
  10. * Based on 2.4 code Copyright 2004 (c) Intel Corporation
  11. *
  12. * This file is licensed under the terms of the GNU General Public
  13. * License version 2. This program is licensed "as is" without any
  14. * warranty of any kind, whether express or implied.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/sched.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/irq.h>
  22. #include <linux/serial.h>
  23. #include <linux/tty.h>
  24. #include <linux/bitops.h>
  25. #include <linux/ioport.h>
  26. #include <linux/serial_8250.h>
  27. #include <linux/serial_core.h>
  28. #include <linux/device.h>
  29. #include <linux/mm.h>
  30. #include <linux/pci.h>
  31. #include <linux/mtd/physmap.h>
  32. #include <asm/types.h>
  33. #include <asm/setup.h>
  34. #include <asm/memory.h>
  35. #include <mach/hardware.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/system.h>
  38. #include <asm/tlbflush.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/mach/map.h>
  41. #include <asm/mach/irq.h>
  42. #include <asm/mach/arch.h>
  43. #include <asm/mach/pci.h>
  44. /*
  45. * IXDP2351 Interrupt Handling
  46. */
  47. static void ixdp2351_inta_mask(unsigned int irq)
  48. {
  49. *IXDP2351_CPLD_INTA_MASK_SET_REG = IXDP2351_INTA_IRQ_MASK(irq);
  50. }
  51. static void ixdp2351_inta_unmask(unsigned int irq)
  52. {
  53. *IXDP2351_CPLD_INTA_MASK_CLR_REG = IXDP2351_INTA_IRQ_MASK(irq);
  54. }
  55. static void ixdp2351_inta_handler(unsigned int irq, struct irq_desc *desc)
  56. {
  57. u16 ex_interrupt =
  58. *IXDP2351_CPLD_INTA_STAT_REG & IXDP2351_INTA_IRQ_VALID;
  59. int i;
  60. desc->chip->mask(irq);
  61. for (i = 0; i < IXDP2351_INTA_IRQ_NUM; i++) {
  62. if (ex_interrupt & (1 << i)) {
  63. int cpld_irq =
  64. IXP23XX_MACH_IRQ(IXDP2351_INTA_IRQ_BASE + i);
  65. generic_handle_irq(cpld_irq);
  66. }
  67. }
  68. desc->chip->unmask(irq);
  69. }
  70. static struct irq_chip ixdp2351_inta_chip = {
  71. .ack = ixdp2351_inta_mask,
  72. .mask = ixdp2351_inta_mask,
  73. .unmask = ixdp2351_inta_unmask
  74. };
  75. static void ixdp2351_intb_mask(unsigned int irq)
  76. {
  77. *IXDP2351_CPLD_INTB_MASK_SET_REG = IXDP2351_INTB_IRQ_MASK(irq);
  78. }
  79. static void ixdp2351_intb_unmask(unsigned int irq)
  80. {
  81. *IXDP2351_CPLD_INTB_MASK_CLR_REG = IXDP2351_INTB_IRQ_MASK(irq);
  82. }
  83. static void ixdp2351_intb_handler(unsigned int irq, struct irq_desc *desc)
  84. {
  85. u16 ex_interrupt =
  86. *IXDP2351_CPLD_INTB_STAT_REG & IXDP2351_INTB_IRQ_VALID;
  87. int i;
  88. desc->chip->ack(irq);
  89. for (i = 0; i < IXDP2351_INTB_IRQ_NUM; i++) {
  90. if (ex_interrupt & (1 << i)) {
  91. int cpld_irq =
  92. IXP23XX_MACH_IRQ(IXDP2351_INTB_IRQ_BASE + i);
  93. generic_handle_irq(cpld_irq);
  94. }
  95. }
  96. desc->chip->unmask(irq);
  97. }
  98. static struct irq_chip ixdp2351_intb_chip = {
  99. .ack = ixdp2351_intb_mask,
  100. .mask = ixdp2351_intb_mask,
  101. .unmask = ixdp2351_intb_unmask
  102. };
  103. void __init ixdp2351_init_irq(void)
  104. {
  105. int irq;
  106. /* Mask all interrupts from CPLD, disable simulation */
  107. *IXDP2351_CPLD_INTA_MASK_SET_REG = (u16) -1;
  108. *IXDP2351_CPLD_INTB_MASK_SET_REG = (u16) -1;
  109. *IXDP2351_CPLD_INTA_SIM_REG = 0;
  110. *IXDP2351_CPLD_INTB_SIM_REG = 0;
  111. ixp23xx_init_irq();
  112. for (irq = IXP23XX_MACH_IRQ(IXDP2351_INTA_IRQ_BASE);
  113. irq <
  114. IXP23XX_MACH_IRQ(IXDP2351_INTA_IRQ_BASE + IXDP2351_INTA_IRQ_NUM);
  115. irq++) {
  116. if (IXDP2351_INTA_IRQ_MASK(irq) & IXDP2351_INTA_IRQ_VALID) {
  117. set_irq_flags(irq, IRQF_VALID);
  118. set_irq_handler(irq, handle_level_irq);
  119. set_irq_chip(irq, &ixdp2351_inta_chip);
  120. }
  121. }
  122. for (irq = IXP23XX_MACH_IRQ(IXDP2351_INTB_IRQ_BASE);
  123. irq <
  124. IXP23XX_MACH_IRQ(IXDP2351_INTB_IRQ_BASE + IXDP2351_INTB_IRQ_NUM);
  125. irq++) {
  126. if (IXDP2351_INTB_IRQ_MASK(irq) & IXDP2351_INTB_IRQ_VALID) {
  127. set_irq_flags(irq, IRQF_VALID);
  128. set_irq_handler(irq, handle_level_irq);
  129. set_irq_chip(irq, &ixdp2351_intb_chip);
  130. }
  131. }
  132. set_irq_chained_handler(IRQ_IXP23XX_INTA, ixdp2351_inta_handler);
  133. set_irq_chained_handler(IRQ_IXP23XX_INTB, ixdp2351_intb_handler);
  134. }
  135. /*
  136. * IXDP2351 PCI
  137. */
  138. /*
  139. * This board does not do normal PCI IRQ routing, or any
  140. * sort of swizzling, so we just need to check where on the
  141. * bus the device is and figure out what CPLD pin it is
  142. * being routed to.
  143. */
  144. #define DEVPIN(dev, pin) ((pin) | ((dev) << 3))
  145. static int __init ixdp2351_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  146. {
  147. u8 bus = dev->bus->number;
  148. u32 devpin = DEVPIN(PCI_SLOT(dev->devfn), pin);
  149. struct pci_bus *tmp_bus = dev->bus;
  150. /* Primary bus, no interrupts here */
  151. if (!bus)
  152. return -1;
  153. /* Lookup first leaf in bus tree */
  154. while ((tmp_bus->parent != NULL) && (tmp_bus->parent->parent != NULL))
  155. tmp_bus = tmp_bus->parent;
  156. /* Select between known bridges */
  157. switch (tmp_bus->self->devfn | (tmp_bus->self->bus->number << 8)) {
  158. /* Device is located after first bridge */
  159. case 0x0008:
  160. if (tmp_bus == dev->bus) {
  161. /* Device is located directy after first bridge */
  162. switch (devpin) {
  163. /* Onboard 82546 */
  164. case DEVPIN(1, 1): /* Onboard 82546 ch 0 */
  165. return IRQ_IXDP2351_INTA_82546;
  166. case DEVPIN(1, 2): /* Onboard 82546 ch 1 */
  167. return IRQ_IXDP2351_INTB_82546;
  168. /* PMC SLOT */
  169. case DEVPIN(0, 1): /* PMCP INTA# */
  170. case DEVPIN(2, 4): /* PMCS INTD# */
  171. return IRQ_IXDP2351_SPCI_PMC_INTA;
  172. case DEVPIN(0, 2): /* PMCP INTB# */
  173. case DEVPIN(2, 1): /* PMCS INTA# */
  174. return IRQ_IXDP2351_SPCI_PMC_INTB;
  175. case DEVPIN(0, 3): /* PMCP INTC# */
  176. case DEVPIN(2, 2): /* PMCS INTB# */
  177. return IRQ_IXDP2351_SPCI_PMC_INTC;
  178. case DEVPIN(0, 4): /* PMCP INTD# */
  179. case DEVPIN(2, 3): /* PMCS INTC# */
  180. return IRQ_IXDP2351_SPCI_PMC_INTD;
  181. }
  182. } else {
  183. /* Device is located indirectly after first bridge */
  184. /* Not supported now */
  185. return -1;
  186. }
  187. break;
  188. case 0x0010:
  189. if (tmp_bus == dev->bus) {
  190. /* Device is located directy after second bridge */
  191. /* Secondary bus of second bridge */
  192. switch (devpin) {
  193. case DEVPIN(0, 1): /* DB#0 */
  194. case DEVPIN(0, 2):
  195. case DEVPIN(0, 3):
  196. case DEVPIN(0, 4):
  197. return IRQ_IXDP2351_SPCI_DB_0;
  198. case DEVPIN(1, 1): /* DB#1 */
  199. case DEVPIN(1, 2):
  200. case DEVPIN(1, 3):
  201. case DEVPIN(1, 4):
  202. return IRQ_IXDP2351_SPCI_DB_1;
  203. case DEVPIN(2, 1): /* FIC1 */
  204. case DEVPIN(2, 2):
  205. case DEVPIN(2, 3):
  206. case DEVPIN(2, 4):
  207. case DEVPIN(3, 1): /* FIC2 */
  208. case DEVPIN(3, 2):
  209. case DEVPIN(3, 3):
  210. case DEVPIN(3, 4):
  211. return IRQ_IXDP2351_SPCI_FIC;
  212. }
  213. } else {
  214. /* Device is located indirectly after second bridge */
  215. /* Not supported now */
  216. return -1;
  217. }
  218. break;
  219. }
  220. return -1;
  221. }
  222. struct hw_pci ixdp2351_pci __initdata = {
  223. .nr_controllers = 1,
  224. .preinit = ixp23xx_pci_preinit,
  225. .setup = ixp23xx_pci_setup,
  226. .scan = ixp23xx_pci_scan_bus,
  227. .map_irq = ixdp2351_map_irq,
  228. };
  229. int __init ixdp2351_pci_init(void)
  230. {
  231. if (machine_is_ixdp2351())
  232. pci_common_init(&ixdp2351_pci);
  233. return 0;
  234. }
  235. subsys_initcall(ixdp2351_pci_init);
  236. /*
  237. * IXDP2351 Static Mapped I/O
  238. */
  239. static struct map_desc ixdp2351_io_desc[] __initdata = {
  240. {
  241. .virtual = IXDP2351_NP_VIRT_BASE,
  242. .pfn = __phys_to_pfn((u64)IXDP2351_NP_PHYS_BASE),
  243. .length = IXDP2351_NP_PHYS_SIZE,
  244. .type = MT_DEVICE
  245. }, {
  246. .virtual = IXDP2351_BB_BASE_VIRT,
  247. .pfn = __phys_to_pfn((u64)IXDP2351_BB_BASE_PHYS),
  248. .length = IXDP2351_BB_SIZE,
  249. .type = MT_DEVICE
  250. }
  251. };
  252. static void __init ixdp2351_map_io(void)
  253. {
  254. ixp23xx_map_io();
  255. iotable_init(ixdp2351_io_desc, ARRAY_SIZE(ixdp2351_io_desc));
  256. }
  257. static struct physmap_flash_data ixdp2351_flash_data = {
  258. .width = 1,
  259. };
  260. static struct resource ixdp2351_flash_resource = {
  261. .start = 0x90000000,
  262. .end = 0x93ffffff,
  263. .flags = IORESOURCE_MEM,
  264. };
  265. static struct platform_device ixdp2351_flash = {
  266. .name = "physmap-flash",
  267. .id = 0,
  268. .dev = {
  269. .platform_data = &ixdp2351_flash_data,
  270. },
  271. .num_resources = 1,
  272. .resource = &ixdp2351_flash_resource,
  273. };
  274. static void __init ixdp2351_init(void)
  275. {
  276. platform_device_register(&ixdp2351_flash);
  277. /*
  278. * Mark flash as writeable
  279. */
  280. IXP23XX_EXP_CS0[0] |= IXP23XX_FLASH_WRITABLE;
  281. IXP23XX_EXP_CS0[1] |= IXP23XX_FLASH_WRITABLE;
  282. IXP23XX_EXP_CS0[2] |= IXP23XX_FLASH_WRITABLE;
  283. IXP23XX_EXP_CS0[3] |= IXP23XX_FLASH_WRITABLE;
  284. ixp23xx_sys_init();
  285. }
  286. MACHINE_START(IXDP2351, "Intel IXDP2351 Development Platform")
  287. /* Maintainer: MontaVista Software, Inc. */
  288. .phys_io = IXP23XX_PERIPHERAL_PHYS,
  289. .io_pg_offst = ((IXP23XX_PERIPHERAL_VIRT >> 18)) & 0xfffc,
  290. .map_io = ixdp2351_map_io,
  291. .init_irq = ixdp2351_init_irq,
  292. .timer = &ixp23xx_timer,
  293. .boot_params = 0x00000100,
  294. .init_machine = ixdp2351_init,
  295. MACHINE_END