ixdp2351.c 8.5 KB

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