ixdp2351.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 <asm/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. struct irq_desc *cpld_desc;
  64. int cpld_irq =
  65. IXP23XX_MACH_IRQ(IXDP2351_INTA_IRQ_BASE + i);
  66. cpld_desc = irq_desc + cpld_irq;
  67. desc_handle_irq(cpld_irq, cpld_desc);
  68. }
  69. }
  70. desc->chip->unmask(irq);
  71. }
  72. static struct irq_chip ixdp2351_inta_chip = {
  73. .ack = ixdp2351_inta_mask,
  74. .mask = ixdp2351_inta_mask,
  75. .unmask = ixdp2351_inta_unmask
  76. };
  77. static void ixdp2351_intb_mask(unsigned int irq)
  78. {
  79. *IXDP2351_CPLD_INTB_MASK_SET_REG = IXDP2351_INTB_IRQ_MASK(irq);
  80. }
  81. static void ixdp2351_intb_unmask(unsigned int irq)
  82. {
  83. *IXDP2351_CPLD_INTB_MASK_CLR_REG = IXDP2351_INTB_IRQ_MASK(irq);
  84. }
  85. static void ixdp2351_intb_handler(unsigned int irq, struct irq_desc *desc)
  86. {
  87. u16 ex_interrupt =
  88. *IXDP2351_CPLD_INTB_STAT_REG & IXDP2351_INTB_IRQ_VALID;
  89. int i;
  90. desc->chip->ack(irq);
  91. for (i = 0; i < IXDP2351_INTB_IRQ_NUM; i++) {
  92. if (ex_interrupt & (1 << i)) {
  93. struct irq_desc *cpld_desc;
  94. int cpld_irq =
  95. IXP23XX_MACH_IRQ(IXDP2351_INTB_IRQ_BASE + i);
  96. cpld_desc = irq_desc + cpld_irq;
  97. desc_handle_irq(cpld_irq, cpld_desc);
  98. }
  99. }
  100. desc->chip->unmask(irq);
  101. }
  102. static struct irq_chip ixdp2351_intb_chip = {
  103. .ack = ixdp2351_intb_mask,
  104. .mask = ixdp2351_intb_mask,
  105. .unmask = ixdp2351_intb_unmask
  106. };
  107. void __init ixdp2351_init_irq(void)
  108. {
  109. int irq;
  110. /* Mask all interrupts from CPLD, disable simulation */
  111. *IXDP2351_CPLD_INTA_MASK_SET_REG = (u16) -1;
  112. *IXDP2351_CPLD_INTB_MASK_SET_REG = (u16) -1;
  113. *IXDP2351_CPLD_INTA_SIM_REG = 0;
  114. *IXDP2351_CPLD_INTB_SIM_REG = 0;
  115. ixp23xx_init_irq();
  116. for (irq = IXP23XX_MACH_IRQ(IXDP2351_INTA_IRQ_BASE);
  117. irq <
  118. IXP23XX_MACH_IRQ(IXDP2351_INTA_IRQ_BASE + IXDP2351_INTA_IRQ_NUM);
  119. irq++) {
  120. if (IXDP2351_INTA_IRQ_MASK(irq) & IXDP2351_INTA_IRQ_VALID) {
  121. set_irq_flags(irq, IRQF_VALID);
  122. set_irq_handler(irq, handle_level_irq);
  123. set_irq_chip(irq, &ixdp2351_inta_chip);
  124. }
  125. }
  126. for (irq = IXP23XX_MACH_IRQ(IXDP2351_INTB_IRQ_BASE);
  127. irq <
  128. IXP23XX_MACH_IRQ(IXDP2351_INTB_IRQ_BASE + IXDP2351_INTB_IRQ_NUM);
  129. irq++) {
  130. if (IXDP2351_INTB_IRQ_MASK(irq) & IXDP2351_INTB_IRQ_VALID) {
  131. set_irq_flags(irq, IRQF_VALID);
  132. set_irq_handler(irq, handle_level_irq);
  133. set_irq_chip(irq, &ixdp2351_intb_chip);
  134. }
  135. }
  136. set_irq_chained_handler(IRQ_IXP23XX_INTA, ixdp2351_inta_handler);
  137. set_irq_chained_handler(IRQ_IXP23XX_INTB, ixdp2351_intb_handler);
  138. }
  139. /*
  140. * IXDP2351 PCI
  141. */
  142. /*
  143. * This board does not do normal PCI IRQ routing, or any
  144. * sort of swizzling, so we just need to check where on the
  145. * bus the device is and figure out what CPLD pin it is
  146. * being routed to.
  147. */
  148. #define DEVPIN(dev, pin) ((pin) | ((dev) << 3))
  149. static int __init ixdp2351_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  150. {
  151. u8 bus = dev->bus->number;
  152. u32 devpin = DEVPIN(PCI_SLOT(dev->devfn), pin);
  153. struct pci_bus *tmp_bus = dev->bus;
  154. /* Primary bus, no interrupts here */
  155. if (!bus)
  156. return -1;
  157. /* Lookup first leaf in bus tree */
  158. while ((tmp_bus->parent != NULL) && (tmp_bus->parent->parent != NULL))
  159. tmp_bus = tmp_bus->parent;
  160. /* Select between known bridges */
  161. switch (tmp_bus->self->devfn | (tmp_bus->self->bus->number << 8)) {
  162. /* Device is located after first bridge */
  163. case 0x0008:
  164. if (tmp_bus == dev->bus) {
  165. /* Device is located directy after first bridge */
  166. switch (devpin) {
  167. /* Onboard 82546 */
  168. case DEVPIN(1, 1): /* Onboard 82546 ch 0 */
  169. return IRQ_IXDP2351_INTA_82546;
  170. case DEVPIN(1, 2): /* Onboard 82546 ch 1 */
  171. return IRQ_IXDP2351_INTB_82546;
  172. /* PMC SLOT */
  173. case DEVPIN(0, 1): /* PMCP INTA# */
  174. case DEVPIN(2, 4): /* PMCS INTD# */
  175. return IRQ_IXDP2351_SPCI_PMC_INTA;
  176. case DEVPIN(0, 2): /* PMCP INTB# */
  177. case DEVPIN(2, 1): /* PMCS INTA# */
  178. return IRQ_IXDP2351_SPCI_PMC_INTB;
  179. case DEVPIN(0, 3): /* PMCP INTC# */
  180. case DEVPIN(2, 2): /* PMCS INTB# */
  181. return IRQ_IXDP2351_SPCI_PMC_INTC;
  182. case DEVPIN(0, 4): /* PMCP INTD# */
  183. case DEVPIN(2, 3): /* PMCS INTC# */
  184. return IRQ_IXDP2351_SPCI_PMC_INTD;
  185. }
  186. } else {
  187. /* Device is located indirectly after first bridge */
  188. /* Not supported now */
  189. return -1;
  190. }
  191. break;
  192. case 0x0010:
  193. if (tmp_bus == dev->bus) {
  194. /* Device is located directy after second bridge */
  195. /* Secondary bus of second bridge */
  196. switch (devpin) {
  197. case DEVPIN(0, 1): /* DB#0 */
  198. case DEVPIN(0, 2):
  199. case DEVPIN(0, 3):
  200. case DEVPIN(0, 4):
  201. return IRQ_IXDP2351_SPCI_DB_0;
  202. case DEVPIN(1, 1): /* DB#1 */
  203. case DEVPIN(1, 2):
  204. case DEVPIN(1, 3):
  205. case DEVPIN(1, 4):
  206. return IRQ_IXDP2351_SPCI_DB_1;
  207. case DEVPIN(2, 1): /* FIC1 */
  208. case DEVPIN(2, 2):
  209. case DEVPIN(2, 3):
  210. case DEVPIN(2, 4):
  211. case DEVPIN(3, 1): /* FIC2 */
  212. case DEVPIN(3, 2):
  213. case DEVPIN(3, 3):
  214. case DEVPIN(3, 4):
  215. return IRQ_IXDP2351_SPCI_FIC;
  216. }
  217. } else {
  218. /* Device is located indirectly after second bridge */
  219. /* Not supported now */
  220. return -1;
  221. }
  222. break;
  223. }
  224. return -1;
  225. }
  226. struct hw_pci ixdp2351_pci __initdata = {
  227. .nr_controllers = 1,
  228. .preinit = ixp23xx_pci_preinit,
  229. .setup = ixp23xx_pci_setup,
  230. .scan = ixp23xx_pci_scan_bus,
  231. .map_irq = ixdp2351_map_irq,
  232. };
  233. int __init ixdp2351_pci_init(void)
  234. {
  235. if (machine_is_ixdp2351())
  236. pci_common_init(&ixdp2351_pci);
  237. return 0;
  238. }
  239. subsys_initcall(ixdp2351_pci_init);
  240. /*
  241. * IXDP2351 Static Mapped I/O
  242. */
  243. static struct map_desc ixdp2351_io_desc[] __initdata = {
  244. {
  245. .virtual = IXDP2351_NP_VIRT_BASE,
  246. .pfn = __phys_to_pfn((u64)IXDP2351_NP_PHYS_BASE),
  247. .length = IXDP2351_NP_PHYS_SIZE,
  248. .type = MT_DEVICE
  249. }, {
  250. .virtual = IXDP2351_BB_BASE_VIRT,
  251. .pfn = __phys_to_pfn((u64)IXDP2351_BB_BASE_PHYS),
  252. .length = IXDP2351_BB_SIZE,
  253. .type = MT_DEVICE
  254. }
  255. };
  256. static void __init ixdp2351_map_io(void)
  257. {
  258. ixp23xx_map_io();
  259. iotable_init(ixdp2351_io_desc, ARRAY_SIZE(ixdp2351_io_desc));
  260. }
  261. static struct physmap_flash_data ixdp2351_flash_data = {
  262. .width = 1,
  263. };
  264. static struct resource ixdp2351_flash_resource = {
  265. .start = 0x90000000,
  266. .end = 0x93ffffff,
  267. .flags = IORESOURCE_MEM,
  268. };
  269. static struct platform_device ixdp2351_flash = {
  270. .name = "physmap-flash",
  271. .id = 0,
  272. .dev = {
  273. .platform_data = &ixdp2351_flash_data,
  274. },
  275. .num_resources = 1,
  276. .resource = &ixdp2351_flash_resource,
  277. };
  278. static void __init ixdp2351_init(void)
  279. {
  280. platform_device_register(&ixdp2351_flash);
  281. /*
  282. * Mark flash as writeable
  283. */
  284. IXP23XX_EXP_CS0[0] |= IXP23XX_FLASH_WRITABLE;
  285. IXP23XX_EXP_CS0[1] |= IXP23XX_FLASH_WRITABLE;
  286. IXP23XX_EXP_CS0[2] |= IXP23XX_FLASH_WRITABLE;
  287. IXP23XX_EXP_CS0[3] |= IXP23XX_FLASH_WRITABLE;
  288. ixp23xx_sys_init();
  289. }
  290. MACHINE_START(IXDP2351, "Intel IXDP2351 Development Platform")
  291. /* Maintainer: MontaVista Software, Inc. */
  292. .phys_io = IXP23XX_PERIPHERAL_PHYS,
  293. .io_pg_offst = ((IXP23XX_PERIPHERAL_VIRT >> 18)) & 0xfffc,
  294. .map_io = ixdp2351_map_io,
  295. .init_irq = ixdp2351_init_irq,
  296. .timer = &ixp23xx_timer,
  297. .boot_params = 0x00000100,
  298. .init_machine = ixdp2351_init,
  299. MACHINE_END