ixdp2x01.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /*
  2. * arch/arm/mach-ixp2000/ixdp2x01.c
  3. *
  4. * Code common to Intel IXDP2401 and IXDP2801 platforms
  5. *
  6. * Original Author: Andrzej Mialkowski <andrzej.mialkowski@intel.com>
  7. * Maintainer: Deepak Saxena <dsaxena@plexity.net>
  8. *
  9. * Copyright (C) 2002-2003 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/config.h>
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/mm.h>
  21. #include <linux/sched.h>
  22. #include <linux/interrupt.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 <linux/serial.h>
  29. #include <linux/tty.h>
  30. #include <linux/serial_core.h>
  31. #include <linux/platform_device.h>
  32. #include <asm/io.h>
  33. #include <asm/irq.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/page.h>
  36. #include <asm/system.h>
  37. #include <asm/hardware.h>
  38. #include <asm/mach-types.h>
  39. #include <asm/mach/pci.h>
  40. #include <asm/mach/map.h>
  41. #include <asm/mach/irq.h>
  42. #include <asm/mach/time.h>
  43. #include <asm/mach/arch.h>
  44. #include <asm/mach/flash.h>
  45. /*************************************************************************
  46. * IXDP2x01 IRQ Handling
  47. *************************************************************************/
  48. static void ixdp2x01_irq_mask(unsigned int irq)
  49. {
  50. ixp2000_reg_wrb(IXDP2X01_INT_MASK_SET_REG,
  51. IXP2000_BOARD_IRQ_MASK(irq));
  52. }
  53. static void ixdp2x01_irq_unmask(unsigned int irq)
  54. {
  55. ixp2000_reg_write(IXDP2X01_INT_MASK_CLR_REG,
  56. IXP2000_BOARD_IRQ_MASK(irq));
  57. }
  58. static u32 valid_irq_mask;
  59. static void ixdp2x01_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
  60. {
  61. u32 ex_interrupt;
  62. int i;
  63. desc->chip->mask(irq);
  64. ex_interrupt = *IXDP2X01_INT_STAT_REG & valid_irq_mask;
  65. if (!ex_interrupt) {
  66. printk(KERN_ERR "Spurious IXDP2X01 CPLD interrupt!\n");
  67. return;
  68. }
  69. for (i = 0; i < IXP2000_BOARD_IRQS; i++) {
  70. if (ex_interrupt & (1 << i)) {
  71. struct irqdesc *cpld_desc;
  72. int cpld_irq = IXP2000_BOARD_IRQ(0) + i;
  73. cpld_desc = irq_desc + cpld_irq;
  74. desc_handle_irq(cpld_irq, cpld_desc, regs);
  75. }
  76. }
  77. desc->chip->unmask(irq);
  78. }
  79. static struct irqchip ixdp2x01_irq_chip = {
  80. .mask = ixdp2x01_irq_mask,
  81. .ack = ixdp2x01_irq_mask,
  82. .unmask = ixdp2x01_irq_unmask
  83. };
  84. /*
  85. * We only do anything if we are the master NPU on the board.
  86. * The slave NPU only has the ethernet chip going directly to
  87. * the PCIB interrupt input.
  88. */
  89. void __init ixdp2x01_init_irq(void)
  90. {
  91. int irq = 0;
  92. /* initialize chip specific interrupts */
  93. ixp2000_init_irq();
  94. if (machine_is_ixdp2401())
  95. valid_irq_mask = IXDP2401_VALID_IRQ_MASK;
  96. else
  97. valid_irq_mask = IXDP2801_VALID_IRQ_MASK;
  98. /* Mask all interrupts from CPLD, disable simulation */
  99. ixp2000_reg_write(IXDP2X01_INT_MASK_SET_REG, 0xffffffff);
  100. ixp2000_reg_wrb(IXDP2X01_INT_SIM_REG, 0);
  101. for (irq = NR_IXP2000_IRQS; irq < NR_IXDP2X01_IRQS; irq++) {
  102. if (irq & valid_irq_mask) {
  103. set_irq_chip(irq, &ixdp2x01_irq_chip);
  104. set_irq_handler(irq, do_level_IRQ);
  105. set_irq_flags(irq, IRQF_VALID);
  106. } else {
  107. set_irq_flags(irq, 0);
  108. }
  109. }
  110. /* Hook into PCI interrupts */
  111. set_irq_chained_handler(IRQ_IXP2000_PCIB, &ixdp2x01_irq_handler);
  112. }
  113. /*************************************************************************
  114. * IXDP2x01 memory map and serial ports
  115. *************************************************************************/
  116. static struct map_desc ixdp2x01_io_desc __initdata = {
  117. .virtual = IXDP2X01_VIRT_CPLD_BASE,
  118. .pfn = __phys_to_pfn(IXDP2X01_PHYS_CPLD_BASE),
  119. .length = IXDP2X01_CPLD_REGION_SIZE,
  120. .type = MT_DEVICE
  121. };
  122. static struct uart_port ixdp2x01_serial_ports[2] = {
  123. {
  124. .membase = (char *)(IXDP2X01_UART1_VIRT_BASE),
  125. .mapbase = (unsigned long)IXDP2X01_UART1_PHYS_BASE,
  126. .irq = IRQ_IXDP2X01_UART1,
  127. .flags = UPF_SKIP_TEST,
  128. .iotype = UPIO_MEM32,
  129. .regshift = 2,
  130. .uartclk = IXDP2X01_UART_CLK,
  131. .line = 1,
  132. .type = PORT_16550A,
  133. .fifosize = 16
  134. }, {
  135. .membase = (char *)(IXDP2X01_UART2_VIRT_BASE),
  136. .mapbase = (unsigned long)IXDP2X01_UART2_PHYS_BASE,
  137. .irq = IRQ_IXDP2X01_UART2,
  138. .flags = UPF_SKIP_TEST,
  139. .iotype = UPIO_MEM32,
  140. .regshift = 2,
  141. .uartclk = IXDP2X01_UART_CLK,
  142. .line = 2,
  143. .type = PORT_16550A,
  144. .fifosize = 16
  145. },
  146. };
  147. static void __init ixdp2x01_map_io(void)
  148. {
  149. ixp2000_map_io();
  150. iotable_init(&ixdp2x01_io_desc, 1);
  151. early_serial_setup(&ixdp2x01_serial_ports[0]);
  152. early_serial_setup(&ixdp2x01_serial_ports[1]);
  153. }
  154. /*************************************************************************
  155. * IXDP2x01 timer tick configuration
  156. *************************************************************************/
  157. static unsigned int ixdp2x01_clock;
  158. static int __init ixdp2x01_clock_setup(char *str)
  159. {
  160. ixdp2x01_clock = simple_strtoul(str, NULL, 10);
  161. return 1;
  162. }
  163. __setup("ixdp2x01_clock=", ixdp2x01_clock_setup);
  164. static void __init ixdp2x01_timer_init(void)
  165. {
  166. if (!ixdp2x01_clock)
  167. ixdp2x01_clock = 50000000;
  168. ixp2000_init_time(ixdp2x01_clock);
  169. }
  170. static struct sys_timer ixdp2x01_timer = {
  171. .init = ixdp2x01_timer_init,
  172. .offset = ixp2000_gettimeoffset,
  173. };
  174. /*************************************************************************
  175. * IXDP2x01 PCI
  176. *************************************************************************/
  177. void __init ixdp2x01_pci_preinit(void)
  178. {
  179. ixp2000_reg_write(IXP2000_PCI_ADDR_EXT, 0x00000000);
  180. ixp2000_pci_preinit();
  181. pcibios_setup("firmware");
  182. }
  183. #define DEVPIN(dev, pin) ((pin) | ((dev) << 3))
  184. static int __init ixdp2x01_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  185. {
  186. u8 bus = dev->bus->number;
  187. u32 devpin = DEVPIN(PCI_SLOT(dev->devfn), pin);
  188. struct pci_bus *tmp_bus = dev->bus;
  189. /* Primary bus, no interrupts here */
  190. if (bus == 0) {
  191. return -1;
  192. }
  193. /* Lookup first leaf in bus tree */
  194. while ((tmp_bus->parent != NULL) && (tmp_bus->parent->parent != NULL)) {
  195. tmp_bus = tmp_bus->parent;
  196. }
  197. /* Select between known bridges */
  198. switch (tmp_bus->self->devfn | (tmp_bus->self->bus->number << 8)) {
  199. /* Device is located after first MB bridge */
  200. case 0x0008:
  201. if (tmp_bus == dev->bus) {
  202. /* Device is located directy after first MB bridge */
  203. switch (devpin) {
  204. case DEVPIN(1, 1): /* Onboard 82546 ch 0 */
  205. if (machine_is_ixdp2401())
  206. return IRQ_IXDP2401_INTA_82546;
  207. return -1;
  208. case DEVPIN(1, 2): /* Onboard 82546 ch 1 */
  209. if (machine_is_ixdp2401())
  210. return IRQ_IXDP2401_INTB_82546;
  211. return -1;
  212. case DEVPIN(0, 1): /* PMC INTA# */
  213. return IRQ_IXDP2X01_SPCI_PMC_INTA;
  214. case DEVPIN(0, 2): /* PMC INTB# */
  215. return IRQ_IXDP2X01_SPCI_PMC_INTB;
  216. case DEVPIN(0, 3): /* PMC INTC# */
  217. return IRQ_IXDP2X01_SPCI_PMC_INTC;
  218. case DEVPIN(0, 4): /* PMC INTD# */
  219. return IRQ_IXDP2X01_SPCI_PMC_INTD;
  220. }
  221. }
  222. break;
  223. case 0x0010:
  224. if (tmp_bus == dev->bus) {
  225. /* Device is located directy after second MB bridge */
  226. /* Secondary bus of second bridge */
  227. switch (devpin) {
  228. case DEVPIN(0, 1): /* DB#0 */
  229. return IRQ_IXDP2X01_SPCI_DB_0;
  230. case DEVPIN(1, 1): /* DB#1 */
  231. return IRQ_IXDP2X01_SPCI_DB_1;
  232. }
  233. } else {
  234. /* Device is located indirectly after second MB bridge */
  235. /* Not supported now */
  236. }
  237. break;
  238. }
  239. return -1;
  240. }
  241. static int ixdp2x01_pci_setup(int nr, struct pci_sys_data *sys)
  242. {
  243. sys->mem_offset = 0xe0000000;
  244. if (machine_is_ixdp2801() || machine_is_ixdp28x5())
  245. sys->mem_offset -= ((*IXP2000_PCI_ADDR_EXT & 0xE000) << 16);
  246. return ixp2000_pci_setup(nr, sys);
  247. }
  248. struct hw_pci ixdp2x01_pci __initdata = {
  249. .nr_controllers = 1,
  250. .setup = ixdp2x01_pci_setup,
  251. .preinit = ixdp2x01_pci_preinit,
  252. .scan = ixp2000_pci_scan_bus,
  253. .map_irq = ixdp2x01_pci_map_irq,
  254. };
  255. int __init ixdp2x01_pci_init(void)
  256. {
  257. if (machine_is_ixdp2401() || machine_is_ixdp2801() ||\
  258. machine_is_ixdp28x5())
  259. pci_common_init(&ixdp2x01_pci);
  260. return 0;
  261. }
  262. subsys_initcall(ixdp2x01_pci_init);
  263. /*************************************************************************
  264. * IXDP2x01 Machine Intialization
  265. *************************************************************************/
  266. static struct flash_platform_data ixdp2x01_flash_platform_data = {
  267. .map_name = "cfi_probe",
  268. .width = 1,
  269. };
  270. static unsigned long ixdp2x01_flash_bank_setup(unsigned long ofs)
  271. {
  272. ixp2000_reg_wrb(IXDP2X01_CPLD_FLASH_REG,
  273. ((ofs >> IXDP2X01_FLASH_WINDOW_BITS) | IXDP2X01_CPLD_FLASH_INTERN));
  274. return (ofs & IXDP2X01_FLASH_WINDOW_MASK);
  275. }
  276. static struct ixp2000_flash_data ixdp2x01_flash_data = {
  277. .platform_data = &ixdp2x01_flash_platform_data,
  278. .bank_setup = ixdp2x01_flash_bank_setup
  279. };
  280. static struct resource ixdp2x01_flash_resource = {
  281. .start = 0xc4000000,
  282. .end = 0xc4000000 + 0x01ffffff,
  283. .flags = IORESOURCE_MEM,
  284. };
  285. static struct platform_device ixdp2x01_flash = {
  286. .name = "IXP2000-Flash",
  287. .id = 0,
  288. .dev = {
  289. .platform_data = &ixdp2x01_flash_data,
  290. },
  291. .num_resources = 1,
  292. .resource = &ixdp2x01_flash_resource,
  293. };
  294. static struct ixp2000_i2c_pins ixdp2x01_i2c_gpio_pins = {
  295. .sda_pin = IXDP2X01_GPIO_SDA,
  296. .scl_pin = IXDP2X01_GPIO_SCL,
  297. };
  298. static struct platform_device ixdp2x01_i2c_controller = {
  299. .name = "IXP2000-I2C",
  300. .id = 0,
  301. .dev = {
  302. .platform_data = &ixdp2x01_i2c_gpio_pins,
  303. },
  304. .num_resources = 0
  305. };
  306. static struct platform_device *ixdp2x01_devices[] __initdata = {
  307. &ixdp2x01_flash,
  308. &ixdp2x01_i2c_controller
  309. };
  310. static void __init ixdp2x01_init_machine(void)
  311. {
  312. ixp2000_reg_wrb(IXDP2X01_CPLD_FLASH_REG,
  313. (IXDP2X01_CPLD_FLASH_BANK_MASK | IXDP2X01_CPLD_FLASH_INTERN));
  314. ixdp2x01_flash_data.nr_banks =
  315. ((*IXDP2X01_CPLD_FLASH_REG & IXDP2X01_CPLD_FLASH_BANK_MASK) + 1);
  316. platform_add_devices(ixdp2x01_devices, ARRAY_SIZE(ixdp2x01_devices));
  317. ixp2000_uart_init();
  318. }
  319. #ifdef CONFIG_ARCH_IXDP2401
  320. MACHINE_START(IXDP2401, "Intel IXDP2401 Development Platform")
  321. /* Maintainer: MontaVista Software, Inc. */
  322. .phys_io = IXP2000_UART_PHYS_BASE,
  323. .io_pg_offst = ((IXP2000_UART_VIRT_BASE) >> 18) & 0xfffc,
  324. .boot_params = 0x00000100,
  325. .map_io = ixdp2x01_map_io,
  326. .init_irq = ixdp2x01_init_irq,
  327. .timer = &ixdp2x01_timer,
  328. .init_machine = ixdp2x01_init_machine,
  329. MACHINE_END
  330. #endif
  331. #ifdef CONFIG_ARCH_IXDP2801
  332. MACHINE_START(IXDP2801, "Intel IXDP2801 Development Platform")
  333. /* Maintainer: MontaVista Software, Inc. */
  334. .phys_io = IXP2000_UART_PHYS_BASE,
  335. .io_pg_offst = ((IXP2000_UART_VIRT_BASE) >> 18) & 0xfffc,
  336. .boot_params = 0x00000100,
  337. .map_io = ixdp2x01_map_io,
  338. .init_irq = ixdp2x01_init_irq,
  339. .timer = &ixdp2x01_timer,
  340. .init_machine = ixdp2x01_init_machine,
  341. MACHINE_END
  342. /*
  343. * IXDP28x5 is basically an IXDP2801 with a different CPU but Intel
  344. * changed the machine ID in the bootloader
  345. */
  346. MACHINE_START(IXDP28X5, "Intel IXDP2805/2855 Development Platform")
  347. /* Maintainer: MontaVista Software, Inc. */
  348. .phys_io = IXP2000_UART_PHYS_BASE,
  349. .io_pg_offst = ((IXP2000_UART_VIRT_BASE) >> 18) & 0xfffc,
  350. .boot_params = 0x00000100,
  351. .map_io = ixdp2x01_map_io,
  352. .init_irq = ixdp2x01_init_irq,
  353. .timer = &ixdp2x01_timer,
  354. .init_machine = ixdp2x01_init_machine,
  355. MACHINE_END
  356. #endif