cm-x2xx-pci.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * linux/arch/arm/mach-pxa/cm-x2xx-pci.c
  3. *
  4. * PCI bios-type initialisation for PCI machines
  5. *
  6. * Bits taken from various places.
  7. *
  8. * Copyright (C) 2007, 2008 Compulab, Ltd.
  9. * Mike Rapoport <mike@compulab.co.il>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/pci.h>
  17. #include <linux/init.h>
  18. #include <linux/device.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/irq.h>
  21. #include <linux/gpio.h>
  22. #include <asm/mach/pci.h>
  23. #include <mach/pxa-regs.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/hardware/it8152.h>
  26. unsigned long it8152_base_address;
  27. static int cmx2xx_it8152_irq_gpio;
  28. /*
  29. * Only first 64MB of memory can be accessed via PCI.
  30. * We use GFP_DMA to allocate safe buffers to do map/unmap.
  31. * This is really ugly and we need a better way of specifying
  32. * DMA-capable regions of memory.
  33. */
  34. void __init cmx2xx_pci_adjust_zones(int node, unsigned long *zone_size,
  35. unsigned long *zhole_size)
  36. {
  37. unsigned int sz = SZ_64M >> PAGE_SHIFT;
  38. if (machine_is_armcore()) {
  39. pr_info("Adjusting zones for CM-X2XX\n");
  40. /*
  41. * Only adjust if > 64M on current system
  42. */
  43. if (node || (zone_size[0] <= sz))
  44. return;
  45. zone_size[1] = zone_size[0] - sz;
  46. zone_size[0] = sz;
  47. zhole_size[1] = zhole_size[0];
  48. zhole_size[0] = 0;
  49. }
  50. }
  51. static void cmx2xx_it8152_irq_demux(unsigned int irq, struct irq_desc *desc)
  52. {
  53. /* clear our parent irq */
  54. GEDR(cmx2xx_it8152_irq_gpio) = GPIO_bit(cmx2xx_it8152_irq_gpio);
  55. it8152_irq_demux(irq, desc);
  56. }
  57. void __cmx2xx_pci_init_irq(int irq_gpio)
  58. {
  59. it8152_init_irq();
  60. cmx2xx_it8152_irq_gpio = irq_gpio;
  61. set_irq_type(gpio_to_irq(irq_gpio), IRQ_TYPE_EDGE_RISING);
  62. set_irq_chained_handler(gpio_to_irq(irq_gpio), cmx2xx_it8152_irq_demux);
  63. }
  64. #ifdef CONFIG_PM
  65. static unsigned long sleep_save_ite[10];
  66. void __cmx2xx_pci_suspend(void)
  67. {
  68. /* save ITE state */
  69. sleep_save_ite[0] = __raw_readl(IT8152_INTC_PDCNIMR);
  70. sleep_save_ite[1] = __raw_readl(IT8152_INTC_LPCNIMR);
  71. sleep_save_ite[2] = __raw_readl(IT8152_INTC_LPNIAR);
  72. /* Clear ITE IRQ's */
  73. __raw_writel((0), IT8152_INTC_PDCNIRR);
  74. __raw_writel((0), IT8152_INTC_LPCNIRR);
  75. }
  76. void __cmx2xx_pci_resume(void)
  77. {
  78. /* restore IT8152 state */
  79. __raw_writel((sleep_save_ite[0]), IT8152_INTC_PDCNIMR);
  80. __raw_writel((sleep_save_ite[1]), IT8152_INTC_LPCNIMR);
  81. __raw_writel((sleep_save_ite[2]), IT8152_INTC_LPNIAR);
  82. }
  83. #else
  84. void cmx2xx_pci_suspend(void) {}
  85. void cmx2xx_pci_resume(void) {}
  86. #endif
  87. /* PCI IRQ mapping*/
  88. static int __init cmx2xx_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  89. {
  90. int irq;
  91. dev_dbg(&dev->dev, "%s: slot=%x, pin=%x\n", __func__, slot, pin);
  92. irq = it8152_pci_map_irq(dev, slot, pin);
  93. if (irq)
  94. return irq;
  95. /*
  96. Here comes the ugly part. The routing is baseboard specific,
  97. but defining a platform for each possible base of CM-X2XX is
  98. unrealistic. Here we keep mapping for ATXBase and SB-X2XX.
  99. */
  100. /* ATXBASE PCI slot */
  101. if (slot == 7)
  102. return IT8152_PCI_INTA;
  103. /* ATXBase/SB-X2XX CardBus */
  104. if (slot == 8 || slot == 0)
  105. return IT8152_PCI_INTB;
  106. /* ATXBase Ethernet */
  107. if (slot == 9)
  108. return IT8152_PCI_INTA;
  109. /* CM-x255 Onboard Ethernet */
  110. if (slot == 15)
  111. return IT8152_PCI_INTC;
  112. /* SB-x2xx Ethernet */
  113. if (slot == 16)
  114. return IT8152_PCI_INTA;
  115. /* PC104+ interrupt routing */
  116. if ((slot == 17) || (slot == 19))
  117. return IT8152_PCI_INTA;
  118. if ((slot == 18) || (slot == 20))
  119. return IT8152_PCI_INTB;
  120. return(0);
  121. }
  122. static void cmx2xx_pci_preinit(void)
  123. {
  124. pr_info("Initializing CM-X2XX PCI subsystem\n");
  125. __raw_writel(0x800, IT8152_PCI_CFG_ADDR);
  126. if (__raw_readl(IT8152_PCI_CFG_DATA) == 0x81521283) {
  127. pr_info("PCI Bridge found.\n");
  128. /* set PCI I/O base at 0 */
  129. writel(0x848, IT8152_PCI_CFG_ADDR);
  130. writel(0, IT8152_PCI_CFG_DATA);
  131. /* set PCI memory base at 0 */
  132. writel(0x840, IT8152_PCI_CFG_ADDR);
  133. writel(0, IT8152_PCI_CFG_DATA);
  134. writel(0x20, IT8152_GPIO_GPDR);
  135. /* CardBus Controller on ATXbase baseboard */
  136. writel(0x4000, IT8152_PCI_CFG_ADDR);
  137. if (readl(IT8152_PCI_CFG_DATA) == 0xAC51104C) {
  138. pr_info("CardBus Bridge found.\n");
  139. /* Configure socket 0 */
  140. writel(0x408C, IT8152_PCI_CFG_ADDR);
  141. writel(0x1022, IT8152_PCI_CFG_DATA);
  142. writel(0x4080, IT8152_PCI_CFG_ADDR);
  143. writel(0x3844d060, IT8152_PCI_CFG_DATA);
  144. writel(0x4090, IT8152_PCI_CFG_ADDR);
  145. writel(((readl(IT8152_PCI_CFG_DATA) & 0xffff) |
  146. 0x60440000),
  147. IT8152_PCI_CFG_DATA);
  148. writel(0x4018, IT8152_PCI_CFG_ADDR);
  149. writel(0xb0000000, IT8152_PCI_CFG_DATA);
  150. /* Configure socket 1 */
  151. writel(0x418C, IT8152_PCI_CFG_ADDR);
  152. writel(0x1022, IT8152_PCI_CFG_DATA);
  153. writel(0x4180, IT8152_PCI_CFG_ADDR);
  154. writel(0x3844d060, IT8152_PCI_CFG_DATA);
  155. writel(0x4190, IT8152_PCI_CFG_ADDR);
  156. writel(((readl(IT8152_PCI_CFG_DATA) & 0xffff) |
  157. 0x60440000),
  158. IT8152_PCI_CFG_DATA);
  159. writel(0x4118, IT8152_PCI_CFG_ADDR);
  160. writel(0xb0000000, IT8152_PCI_CFG_DATA);
  161. }
  162. }
  163. }
  164. static struct hw_pci cmx2xx_pci __initdata = {
  165. .swizzle = pci_std_swizzle,
  166. .map_irq = cmx2xx_pci_map_irq,
  167. .nr_controllers = 1,
  168. .setup = it8152_pci_setup,
  169. .scan = it8152_pci_scan_bus,
  170. .preinit = cmx2xx_pci_preinit,
  171. };
  172. static int __init cmx2xx_init_pci(void)
  173. {
  174. if (machine_is_armcore())
  175. pci_common_init(&cmx2xx_pci);
  176. return 0;
  177. }
  178. subsys_initcall(cmx2xx_init_pci);