alarmDataOperation.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * arch/arm/mach-orion5x/pci.c
  3. *
  4. * PCI and PCIe functions for Marvell Orion System On Chip
  5. *
  6. * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/pci.h>
  14. #include <linux/slab.h>
  15. #include <linux/mbus.h>
  16. #include <video/vga.h>
  17. #include <asm/irq.h>
  18. #include <asm/mach/pci.h>
  19. #include <plat/pcie.h>
  20. #include <plat/addr-map.h>
  21. #include <mach/orion5x.h>
  22. #include "common.h"
  23. /*****************************************************************************
  24. * Orion has one PCIe controller and one PCI controller.
  25. *
  26. * Note1: The local PCIe bus number is '0'. The local PCI bus number
  27. * follows the scanned PCIe bridged busses, if any.
  28. *
  29. * Note2: It is possible for PCI/PCIe agents to access many subsystem's
  30. * space, by configuring BARs and Address Decode Windows, e.g. flashes on
  31. * device bus, Orion registers, etc. However this code only enable the
  32. * access to DDR banks.
  33. ****************************************************************************/
  34. /*****************************************************************************
  35. * PCIe controller
  36. ****************************************************************************/
  37. #define PCIE_BASE (ORION5X_PCIE_VIRT_BASE)
  38. void __init orion5x_pcie_id(u32 *dev, u32 *rev)
  39. {
  40. *dev = orion_pcie_dev_id(PCIE_BASE);
  41. *rev = orion_pcie_rev(PCIE_BASE);
  42. }
  43. static int pcie_valid_config(int bus, int dev)
  44. {
  45. /*
  46. * Don't go out when trying to access --
  47. * 1. nonexisting device on local bus
  48. * 2. where there's no device connected (no link)
  49. */
  50. if (bus == 0 && dev == 0)
  51. return 1;
  52. if (!orion_pcie_link_up(PCIE_BASE))
  53. return 0;
  54. if (bus == 0 && dev != 1)
  55. return 0;
  56. return 1;
  57. }
  58. /*
  59. * PCIe config cycles are done by programming the PCIE_CONF_ADDR register
  60. * and then reading the PCIE_CONF_DATA register. Need to make sure these
  61. * transactions are atomic.
  62. */
  63. static DEFINE_SPINLOCK(orion5x_pcie_lock);
  64. static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
  65. int size, u32 *val)
  66. {
  67. unsigned long flags;
  68. int ret;
  69. if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) {
  70. *val = 0xffffffff;
  71. return PCIBIOS_DEVICE_NOT_FOUND;
  72. }
  73. spin_lock_irqsave(&orion5x_pcie_lock, flags);
  74. ret = orion_pcie_rd_conf(PCIE_BASE, bus, devfn, where, size, val);
  75. spin_unlock_irqrestore(&orion5x_pcie_lock, flags);
  76. return ret;
  77. }
  78. static int pcie_rd_conf_wa(struct pci_bus *bus, u32 devfn,
  79. int where, int size, u32 *val)
  80. {
  81. int ret;
  82. if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) {
  83. *val = 0xffffffff;
  84. return PCIBIOS_DEVICE_NOT_FOUND;
  85. }
  86. /*
  87. * We only support access to the non-extended configuration
  88. * space when using the WA access method (or we would have to
  89. * sacrifice 256M of CPU virtual address space.)
  90. */
  91. if (where >= 0x100) {
  92. *val = 0xffffffff;
  93. return PCIBIOS_DEVICE_NOT_FOUND;
  94. }
  95. ret = orion_pcie_rd_conf_wa(ORION5X_PCIE_WA_VIRT_BASE,
  96. bus, devfn, where, size, val);
  97. return ret;
  98. }
  99. static int pcie_wr_conf(struct pci_bus *bus, u32 devfn,
  100. int where, int size, u32 val)
  101. {
  102. unsigned long flags;
  103. int ret;
  104. if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0)
  105. return PCIBIOS_DEVICE_NOT_FOUND;
  106. spin_lock_irqsave(&orion5x_pcie_lock, flags);
  107. ret = orion_pcie_wr_conf(PCIE_BASE, bus, devfn, where, size, val);
  108. spin_unlock_irqrestore(&orion5x_pcie_lock, flags);
  109. return ret;
  110. }
  111. static struct pci_ops pcie_ops = {
  112. .read = pcie_rd_conf,
  113. .write = pcie_wr_conf,
  114. };
  115. static int __init pcie_setup(struct pci_sys_data *sys)
  116. {
  117. struct resource *res;
  118. int dev;
  119. /*
  120. * Generic PCIe unit setup.
  121. */
  122. orion_pcie_setup(PCIE_BASE);
  123. /*
  124. * Check whether to apply Orion-1/Orion-NAS PCIe config
  125. * read transaction workaround.
  126. */
  127. dev = orion_pcie_dev_id(PCIE_BASE);
  128. if (dev == MV88F5181_DEV_ID || dev == MV88F5182_DEV_ID) {
  129. printk(KERN_NOTICE "Applying Orion-1/Orion-NAS PCIe config "
  130. "read transaction workaround\n");
  131. orion5x_setup_pcie_wa_win(ORION5X_PCIE_WA_PHYS_BASE,
  132. ORION5X_PCIE_WA_SIZE);
  133. pcie_ops.read = pcie_rd_conf_wa;
  134. }
  135. pci_ioremap_io(sys->busnr * SZ_64K, ORION5X_PCIE_IO_PHYS_BASE);
  136. /*
  137. * Request resources.
  138. */
  139. res = kzalloc(sizeof(struct resource), GFP_KERNEL);
  140. if (!res)
  141. panic("pcie_setup unable to alloc resources");
  142. /*
  143. * IORESOURCE_MEM
  144. */
  145. res->name = "PCIe Memory Space";
  146. res->flags = IORESOURCE_MEM;
  147. res->start = ORION5X_PCIE_MEM_PHYS_BASE;
  148. res->end = res->start + ORION5X_PCIE_MEM_SIZE - 1;
  149. if (request_resource(&iomem_resource, res))
  150. panic("Request PCIe Memory resource failed\n");
  151. pci_add_resource_offset(&sys->resources, res, sys->mem_offset);
  152. return 1;
  153. }
  154. /*****************************************************************************
  155. * PCI controller
  156. ****************************************************************************/
  157. #define ORION5X_PCI_REG(x) (ORION5X_PCI_VIRT_BASE + (x))
  158. #define PCI_MODE ORION5X_PCI_REG(0xd00)
  159. #define PCI_CMD ORION5X_PCI_REG(0xc00)
  160. #define PCI_P2P_CONF ORION5X_PCI_REG(0x1d14)
  161. #define PCI_CONF_ADDR ORION5X_PCI_REG(0xc78)
  162. #define PCI_CONF_DATA ORION5X_PCI_REG(0xc7c)
  163. /*
  164. * PCI_MODE bits
  165. */
  166. #define PCI_MODE_64BIT (1 << 2)
  167. #define PCI_MODE_PCIX ((1 << 4) | (1 << 5))
  168. /*
  169. * PCI_CMD bits
  170. */
  171. #define PCI_CMD_HOST_REORDER (1 << 29)
  172. /*
  173. * PCI_P2P_CONF bits
  174. */
  175. #define PCI_P2P_BUS_OFFS 16
  176. #define PCI_P2P_BUS_MASK (0xff << PCI_P2P_BUS_OFFS)
  177. #define PCI_P2P_DEV_OFFS 24
  178. #define PCI_P2P_DEV_MASK (0x1f << PCI_P2P_DEV_OFFS)
  179. /*
  180. * PCI_CONF_ADDR bits
  181. */
  182. #define PCI_CONF_REG(reg) ((reg) & 0xfc)
  183. #define PCI_CONF_FUNC(func) (((func) & 0x3) << 8)
  184. #define PCI_CONF_DEV(dev) (((dev) & 0x1f) << 11)
  185. #define PCI_CONF_BUS(bus) (((bus) & 0xff) << 16)
  186. #define PCI_CONF_ADDR_EN (1 << 31)
  187. /*
  188. * Internal configuration space
  189. */
  190. #define PCI_CONF_FUNC_STAT_CMD 0
  191. #define PCI_CONF_REG_STAT_CMD 4
  192. #define PCIX_STAT 0x64
  193. #define PCIX_STAT_BUS_OFFS 8
  194. #define PCIX_STAT_BUS_MASK (0xff << PCIX_STAT_BUS_OFFS)
  195. /*
  196. * PCI Address Decode Windows registers
  197. */
  198. #define PCI_BAR_SIZE_DDR_CS(n) (((n) == 0) ? ORION5X_PCI_REG(0xc08) : \
  199. ((n) == 1) ? ORION5X_PCI_REG(0xd08) : \
  200. ((n) == 2) ? ORION5X_PCI_REG(0xc0c) : \
  201. ((n) == 3) ? ORION5X_PCI_REG(0xd0c) : 0)
  202. #define PCI_BAR_REMAP_DDR_CS(n) (((n) == 0) ? ORION5X_PCI_REG(0xc48) : \
  203. ((n) == 1) ? ORION5X_PCI_REG(0xd48) : \
  204. ((n) == 2) ? ORION5X_PCI_REG(0xc4c) : \
  205. ((n) == 3) ? ORION5X_PCI_REG(0xd4c) : 0)
  206. #define PCI_BAR_ENABLE ORION5X_PCI_REG(0xc3c)
  207. #define PCI_ADDR_DECODE_CTRL ORION5X_PCI_REG(0xd3c)
  208. /*
  209. * PCI configuration helpers for BAR settings
  210. */
  211. #define PCI_CONF_FUNC_BAR_CS(n) ((n) >> 1)
  212. #define PCI_CONF_REG_BAR_LO_CS(n) (((n) & 1) ? 0x18 : 0x10)
  213. #define PCI_CONF_REG_BAR_HI_CS(n) (((n) & 1) ? 0x1c : 0x14)
  214. /*
  215. * PCI config cycles are done by programming the PCI_CONF_ADDR register
  216. * and then reading the PCI_CONF_DATA register. Need to make sure these
  217. * transactions are atomic.
  218. */
  219. static DEFINE_SPINLOCK(orion5x_pci_lock);
  220. static int orion5x_pci_cardbus_mode;
  221. static int orion5x_pci_local_bus_nr(void)
  222. {
  223. u32 conf = readl(PCI_P2P_CONF);
  224. return((conf & PCI_P2P_BUS_MASK) >> PCI_P2P_BUS_OFFS);
  225. }
  226. static int orion5x_pci_hw_rd_conf(int bus, int dev, u32 func,
  227. u32 where, u32 size, u32 *val)
  228. {