ixdp2x00.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * arch/arm/mach-ixp2000/ixdp2x00.c
  3. *
  4. * Code common to IXDP2400 and IXDP2800 platforms.
  5. *
  6. * Original Author: Naeem Afzal <naeem.m.afzal@intel.com>
  7. * Maintainer: Deepak Saxena <dsaxena@plexity.net>
  8. *
  9. * Copyright (C) 2002 Intel Corp.
  10. * Copyright (C) 2003-2004 MontaVista Software, Inc.
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/mm.h>
  20. #include <linux/sched.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/bitops.h>
  24. #include <linux/pci.h>
  25. #include <linux/ioport.h>
  26. #include <linux/slab.h>
  27. #include <linux/delay.h>
  28. #include <asm/io.h>
  29. #include <asm/irq.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/page.h>
  32. #include <asm/system.h>
  33. #include <asm/hardware.h>
  34. #include <asm/mach-types.h>
  35. #include <asm/mach/pci.h>
  36. #include <asm/mach/map.h>
  37. #include <asm/mach/irq.h>
  38. #include <asm/mach/time.h>
  39. #include <asm/mach/flash.h>
  40. #include <asm/mach/arch.h>
  41. #include <asm/arch/gpio.h>
  42. /*************************************************************************
  43. * IXDP2x00 IRQ Initialization
  44. *************************************************************************/
  45. static volatile unsigned long *board_irq_mask;
  46. static volatile unsigned long *board_irq_stat;
  47. static unsigned long board_irq_count;
  48. #ifdef CONFIG_ARCH_IXDP2400
  49. /*
  50. * Slowport configuration for accessing CPLD registers on IXDP2x00
  51. */
  52. static struct slowport_cfg slowport_cpld_cfg = {
  53. .CCR = SLOWPORT_CCR_DIV_2,
  54. .WTC = 0x00000070,
  55. .RTC = 0x00000070,
  56. .PCR = SLOWPORT_MODE_FLASH,
  57. .ADC = SLOWPORT_ADDR_WIDTH_24 | SLOWPORT_DATA_WIDTH_8
  58. };
  59. #endif
  60. static void ixdp2x00_irq_mask(unsigned int irq)
  61. {
  62. unsigned long dummy;
  63. static struct slowport_cfg old_cfg;
  64. /*
  65. * This is ugly in common code but really don't know
  66. * of a better way to handle it. :(
  67. */
  68. #ifdef CONFIG_ARCH_IXDP2400
  69. if (machine_is_ixdp2400())
  70. ixp2000_acquire_slowport(&slowport_cpld_cfg, &old_cfg);
  71. #endif
  72. dummy = *board_irq_mask;
  73. dummy |= IXP2000_BOARD_IRQ_MASK(irq);
  74. ixp2000_reg_wrb(board_irq_mask, dummy);
  75. #ifdef CONFIG_ARCH_IXDP2400
  76. if (machine_is_ixdp2400())
  77. ixp2000_release_slowport(&old_cfg);
  78. #endif
  79. }
  80. static void ixdp2x00_irq_unmask(unsigned int irq)
  81. {
  82. unsigned long dummy;
  83. static struct slowport_cfg old_cfg;
  84. #ifdef CONFIG_ARCH_IXDP2400
  85. if (machine_is_ixdp2400())
  86. ixp2000_acquire_slowport(&slowport_cpld_cfg, &old_cfg);
  87. #endif
  88. dummy = *board_irq_mask;
  89. dummy &= ~IXP2000_BOARD_IRQ_MASK(irq);
  90. ixp2000_reg_wrb(board_irq_mask, dummy);
  91. if (machine_is_ixdp2400())
  92. ixp2000_release_slowport(&old_cfg);
  93. }
  94. static void ixdp2x00_irq_handler(unsigned int irq, struct irq_desc *desc)
  95. {
  96. volatile u32 ex_interrupt = 0;
  97. static struct slowport_cfg old_cfg;
  98. int i;
  99. desc->chip->mask(irq);
  100. #ifdef CONFIG_ARCH_IXDP2400
  101. if (machine_is_ixdp2400())
  102. ixp2000_acquire_slowport(&slowport_cpld_cfg, &old_cfg);
  103. #endif
  104. ex_interrupt = *board_irq_stat & 0xff;
  105. if (machine_is_ixdp2400())
  106. ixp2000_release_slowport(&old_cfg);
  107. if(!ex_interrupt) {
  108. printk(KERN_ERR "Spurious IXDP2x00 CPLD interrupt!\n");
  109. return;
  110. }
  111. for(i = 0; i < board_irq_count; i++) {
  112. if(ex_interrupt & (1 << i)) {
  113. struct irq_desc *cpld_desc;
  114. int cpld_irq = IXP2000_BOARD_IRQ(0) + i;
  115. cpld_desc = irq_desc + cpld_irq;
  116. desc_handle_irq(cpld_irq, cpld_desc);
  117. }
  118. }
  119. desc->chip->unmask(irq);
  120. }
  121. static struct irq_chip ixdp2x00_cpld_irq_chip = {
  122. .ack = ixdp2x00_irq_mask,
  123. .mask = ixdp2x00_irq_mask,
  124. .unmask = ixdp2x00_irq_unmask
  125. };
  126. void ixdp2x00_init_irq(volatile unsigned long *stat_reg, volatile unsigned long *mask_reg, unsigned long nr_irqs)
  127. {
  128. unsigned int irq;
  129. ixp2000_init_irq();
  130. if (!ixdp2x00_master_npu())
  131. return;
  132. board_irq_stat = stat_reg;
  133. board_irq_mask = mask_reg;
  134. board_irq_count = nr_irqs;
  135. *board_irq_mask = 0xffffffff;
  136. for(irq = IXP2000_BOARD_IRQ(0); irq < IXP2000_BOARD_IRQ(board_irq_count); irq++) {
  137. set_irq_chip(irq, &ixdp2x00_cpld_irq_chip);
  138. set_irq_handler(irq, handle_level_irq);
  139. set_irq_flags(irq, IRQF_VALID);
  140. }
  141. /* Hook into PCI interrupt */
  142. set_irq_chained_handler(IRQ_IXP2000_PCIB, ixdp2x00_irq_handler);
  143. }
  144. /*************************************************************************
  145. * IXDP2x00 memory map
  146. *************************************************************************/
  147. static struct map_desc ixdp2x00_io_desc __initdata = {
  148. .virtual = IXDP2X00_VIRT_CPLD_BASE,
  149. .pfn = __phys_to_pfn(IXDP2X00_PHYS_CPLD_BASE),
  150. .length = IXDP2X00_CPLD_SIZE,
  151. .type = MT_DEVICE
  152. };
  153. void __init ixdp2x00_map_io(void)
  154. {
  155. ixp2000_map_io();
  156. iotable_init(&ixdp2x00_io_desc, 1);
  157. }
  158. /*************************************************************************
  159. * IXDP2x00-common PCI init
  160. *
  161. * The IXDP2[48]00 has a horrid PCI bus layout. Basically the board
  162. * contains two NPUs (ingress and egress) connected over PCI, both running
  163. * instances of the kernel. So far so good. Peers on the PCI bus running
  164. * Linux is a common design in telecom systems. The problem is that instead
  165. * of all the devices being controlled by a single host, different
  166. * devices are controlles by different NPUs on the same bus, leading to
  167. * multiple hosts on the bus. The exact bus layout looks like:
  168. *
  169. * Bus 0
  170. * Master NPU <-------------------+-------------------> Slave NPU
  171. * |
  172. * |
  173. * P2P
  174. * |
  175. *
  176. * Bus 1 |
  177. * <--+------+---------+---------+------+-->
  178. * | | | | |
  179. * | | | | |
  180. * ... Dev PMC Media Eth0 Eth1 ...
  181. *
  182. * The master controlls all but Eth1, which is controlled by the
  183. * slave. What this means is that the both the master and the slave
  184. * have to scan the bus, but only one of them can enumerate the bus.
  185. * In addition, after the bus is scanned, each kernel must remove
  186. * the device(s) it does not control from the PCI dev list otherwise
  187. * a driver on each NPU will try to manage it and we will have horrible
  188. * conflicts. Oh..and the slave NPU needs to see the master NPU
  189. * for Intel's drivers to work properly. Closed source drivers...
  190. *
  191. * The way we deal with this is fairly simple but ugly:
  192. *
  193. * 1) Let master scan and enumerate the bus completely.
  194. * 2) Master deletes Eth1 from device list.
  195. * 3) Slave scans bus and then deletes all but Eth1 (Eth0 on slave)
  196. * from device list.
  197. * 4) Find HW designers and LART them.
  198. *
  199. * The boards also do not do normal PCI IRQ routing, or any sort of
  200. * sensical swizzling, so we just need to check where on the bus a
  201. * device sits and figure out to which CPLD pin the interrupt is routed.
  202. * See ixdp2[48]00.c files.
  203. *
  204. *************************************************************************/
  205. void ixdp2x00_slave_pci_postinit(void)
  206. {
  207. struct pci_dev *dev;
  208. /*
  209. * Remove PMC device is there is one
  210. */
  211. if((dev = pci_get_bus_and_slot(1, IXDP2X00_PMC_DEVFN))) {
  212. pci_remove_bus_device(dev);
  213. pci_dev_put(dev);
  214. }
  215. dev = pci_get_bus_and_slot(0, IXDP2X00_21555_DEVFN);
  216. pci_remove_bus_device(dev);
  217. pci_dev_put(dev);
  218. }
  219. /**************************************************************************
  220. * IXDP2x00 Machine Setup
  221. *************************************************************************/
  222. static struct flash_platform_data ixdp2x00_platform_data = {
  223. .map_name = "cfi_probe",
  224. .width = 1,
  225. };
  226. static struct ixp2000_flash_data ixdp2x00_flash_data = {
  227. .platform_data = &ixdp2x00_platform_data,
  228. .nr_banks = 1
  229. };
  230. static struct resource ixdp2x00_flash_resource = {
  231. .start = 0xc4000000,
  232. .end = 0xc4000000 + 0x00ffffff,
  233. .flags = IORESOURCE_MEM,
  234. };
  235. static struct platform_device ixdp2x00_flash = {
  236. .name = "IXP2000-Flash",
  237. .id = 0,
  238. .dev = {
  239. .platform_data = &ixdp2x00_flash_data,
  240. },
  241. .num_resources = 1,
  242. .resource = &ixdp2x00_flash_resource,
  243. };
  244. static struct ixp2000_i2c_pins ixdp2x00_i2c_gpio_pins = {
  245. .sda_pin = IXDP2X00_GPIO_SDA,
  246. .scl_pin = IXDP2X00_GPIO_SCL,
  247. };
  248. static struct platform_device ixdp2x00_i2c_controller = {
  249. .name = "IXP2000-I2C",
  250. .id = 0,
  251. .dev = {
  252. .platform_data = &ixdp2x00_i2c_gpio_pins,
  253. },
  254. .num_resources = 0
  255. };
  256. static struct platform_device *ixdp2x00_devices[] __initdata = {
  257. &ixdp2x00_flash,
  258. &ixdp2x00_i2c_controller
  259. };
  260. void __init ixdp2x00_init_machine(void)
  261. {
  262. gpio_line_set(IXDP2X00_GPIO_I2C_ENABLE, 1);
  263. gpio_line_config(IXDP2X00_GPIO_I2C_ENABLE, GPIO_OUT);
  264. platform_add_devices(ixdp2x00_devices, ARRAY_SIZE(ixdp2x00_devices));
  265. ixp2000_uart_init();
  266. }