cm-x270-pci.c 5.2 KB

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