cm-x2xx-pci.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 <asm/mach-types.h>
  24. #include <asm/hardware/it8152.h>
  25. void __iomem *it8152_base_address;
  26. static int cmx2xx_it8152_irq_gpio;
  27. static void cmx2xx_it8152_irq_demux(struct irq_desc *desc)
  28. {
  29. /* clear our parent irq */
  30. desc->irq_data.chip->irq_ack(&desc->irq_data);
  31. it8152_irq_demux(desc);
  32. }
  33. void __cmx2xx_pci_init_irq(int irq_gpio)
  34. {
  35. it8152_init_irq();
  36. cmx2xx_it8152_irq_gpio = irq_gpio;
  37. irq_set_irq_type(gpio_to_irq(irq_gpio), IRQ_TYPE_EDGE_RISING);
  38. irq_set_chained_handler(gpio_to_irq(irq_gpio),
  39. cmx2xx_it8152_irq_demux);
  40. }
  41. #ifdef CONFIG_PM
  42. static unsigned long sleep_save_ite[10];
  43. void __cmx2xx_pci_suspend(void)
  44. {
  45. /* save ITE state */
  46. sleep_save_ite[0] = __raw_readl(IT8152_INTC_PDCNIMR);
  47. sleep_save_ite[1] = __raw_readl(IT8152_INTC_LPCNIMR);
  48. sleep_save_ite[2] = __raw_readl(IT8152_INTC_LPNIAR);
  49. /* Clear ITE IRQ's */
  50. __raw_writel((0), IT8152_INTC_PDCNIRR);
  51. __raw_writel((0), IT8152_INTC_LPCNIRR);
  52. }
  53. void __cmx2xx_pci_resume(void)
  54. {
  55. /* restore IT8152 state */
  56. __raw_writel((sleep_save_ite[0]), IT8152_INTC_PDCNIMR);
  57. __raw_writel((sleep_save_ite[1]), IT8152_INTC_LPCNIMR);
  58. __raw_writel((sleep_save_ite[2]), IT8152_INTC_LPNIAR);
  59. }
  60. #else
  61. void cmx2xx_pci_suspend(void) {}
  62. void cmx2xx_pci_resume(void) {}
  63. #endif
  64. /* PCI IRQ mapping*/
  65. static int __init cmx2xx_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  66. {
  67. int irq;
  68. dev_dbg(&dev->dev, "%s: slot=%x, pin=%x\n", __func__, slot, pin);
  69. irq = it8152_pci_map_irq(dev, slot, pin);
  70. if (irq)
  71. return irq;
  72. /*
  73. Here comes the ugly part. The routing is baseboard specific,
  74. but defining a platform for each possible base of CM-X2XX is
  75. unrealistic. Here we keep mapping for ATXBase and SB-X2XX.
  76. */
  77. /* ATXBASE PCI slot */
  78. if (slot == 7)
  79. return IT8152_PCI_INTA;
  80. /* ATXBase/SB-X2XX CardBus */
  81. if (slot == 8 || slot == 0)
  82. return IT8152_PCI_INTB;
  83. /* ATXBase Ethernet */
  84. if (slot == 9)
  85. return IT8152_PCI_INTA;
  86. /* CM-x255 Onboard Ethernet */
  87. if (slot == 15)
  88. return IT8152_PCI_INTC;
  89. /* SB-x2xx Ethernet */
  90. if (slot == 16)
  91. return IT8152_PCI_INTA;
  92. /* PC104+ interrupt routing */
  93. if ((slot == 17) || (slot == 19))
  94. return IT8152_PCI_INTA;
  95. if ((slot == 18) || (slot == 20))
  96. return IT8152_PCI_INTB;
  97. return(0);
  98. }
  99. static void cmx2xx_pci_preinit(void)
  100. {
  101. pr_info("Initializing CM-X2XX PCI subsystem\n");
  102. pcibios_min_io = 0;
  103. pcibios_min_mem = 0;
  104. __raw_writel(0x800, IT8152_PCI_CFG_ADDR);
  105. if (__raw_readl(IT8152_PCI_CFG_DATA) == 0x81521283) {
  106. pr_info("PCI Bridge found.\n");
  107. /* set PCI I/O base at 0 */
  108. writel(0x848, IT8152_PCI_CFG_ADDR);
  109. writel(0, IT8152_PCI_CFG_DATA);
  110. /* set PCI memory base at 0 */
  111. writel(0x840, IT8152_PCI_CFG_ADDR);
  112. writel(0, IT8152_PCI_CFG_DATA);
  113. writel(0x20, IT8152_GPIO_GPDR);
  114. /* CardBus Controller on ATXbase baseboard */
  115. writel(0x4000, IT8152_PCI_CFG_ADDR);
  116. if (readl(IT8152_PCI_CFG_DATA) == 0xAC51104C) {
  117. pr_info("CardBus Bridge found.\n");
  118. /* Configure socket 0 */
  119. writel(0x408C, IT8152_PCI_CFG_ADDR);
  120. writel(0x1022, IT8152_PCI_CFG_DATA);
  121. writel(0x4080, IT8152_PCI_CFG_ADDR);
  122. writel(0x3844d060, IT8152_PCI_CFG_DATA);
  123. writel(0x4090, IT8152_PCI_CFG_ADDR);
  124. writel(((readl(IT8152_PCI_CFG_DATA) & 0xffff) |
  125. 0x60440000),
  126. IT8152_PCI_CFG_DATA);
  127. writel(0x4018, IT8152_PCI_CFG_ADDR);
  128. writel(0xb0000000, IT8152_PCI_CFG_DATA);
  129. /* Configure socket 1 */
  130. writel(0x418C, IT8152_PCI_CFG_ADDR);
  131. writel(0x1022, IT8152_PCI_CFG_DATA);
  132. writel(0x4180, IT8152_PCI_CFG_ADDR);
  133. writel(0x3844d060, IT8152_PCI_CFG_DATA);
  134. writel(0x4190, IT8152_PCI_CFG_ADDR);
  135. writel(((readl(IT8152_PCI_CFG_DATA) & 0xffff) |
  136. 0x60440000),
  137. IT8152_PCI_CFG_DATA);
  138. writel(0x4118, IT8152_PCI_CFG_ADDR);
  139. writel(0xb0000000, IT8152_PCI_CFG_DATA);
  140. }
  141. }
  142. }
  143. static struct hw_pci cmx2xx_pci __initdata = {
  144. .map_irq = cmx2xx_pci_map_irq,
  145. .nr_controllers = 1,
  146. .ops = &it8152_ops,
  147. .setup = it8152_pci_setup,
  148. .preinit = cmx2xx_pci_preinit,
  149. };
  150. static int __init cmx2xx_init_pci(void)
  151. {
  152. if (machine_is_armcore())
  153. pci_common_init(&cmx2xx_pci);
  154. return 0;
  155. }
  156. subsys_initcall(cmx2xx_init_pci);