ixdp2x01.c 12 KB

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