ixdp2x01.c 12 KB

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