ixp425pci.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * IXP PCI Init
  3. * (C) Copyright 2004 eslab.whut.edu.cn
  4. * Yue Hu(huyue_whut@yahoo.com.cn), Ligong Xue(lgxue@hotmail.com)
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #ifndef _IXP425PCI_H_
  25. #define _IXP425PCI_H_
  26. #define TRUE 1
  27. #define FALSE 0
  28. #define OK 0
  29. #define ERROR -1
  30. #define BOOL int
  31. #define IXP425_PCI_MAX_BAR_PER_FUNC 6
  32. #define IXP425_PCI_MAX_BAR (IXP425_PCI_MAX_BAR_PER_FUNC * \
  33. IXP425_PCI_MAX_FUNC_ON_BUS)
  34. enum PciBarId
  35. {
  36. CSR_BAR=0,
  37. IO_BAR,
  38. SD_BAR,
  39. NO_BAR
  40. };
  41. /*Base address register descriptor*/
  42. typedef struct
  43. {
  44. unsigned int size;
  45. unsigned int address;
  46. } PciBar;
  47. typedef struct
  48. {
  49. unsigned int bus;
  50. unsigned int device;
  51. unsigned int func;
  52. unsigned int irq;
  53. BOOL error;
  54. unsigned short vendor_id;
  55. unsigned short device_id;
  56. /*We need an extra entry in this array for dummy placeholder*/
  57. PciBar bar[IXP425_PCI_MAX_BAR_PER_FUNC + 1];
  58. } PciDevice;
  59. /* Mask definitions*/
  60. #define IXP425_PCI_TOP_WORD_OF_LONG_MASK 0xffff0000
  61. #define IXP425_PCI_TOP_BYTE_OF_LONG_MASK 0xff000000
  62. #define IXP425_PCI_BOTTOM_WORD_OF_LONG_MASK 0x0000ffff
  63. #define IXP425_PCI_BOTTOM_TRIBYTES_OF_LONG_MASK 0x00ffffff
  64. #define IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK 0x0000000f
  65. #define IXP425_PCI_MAX_UINT32 0xffffffff
  66. #define IXP425_PCI_BAR_QUERY 0xffffffff
  67. #define IXP425_PCI_BAR_MEM_BASE 0x100000
  68. #define IXP425_PCI_BAR_IO_BASE 0x000000
  69. /*define the maximum number of bus segments - we support a single segment*/
  70. #define IXP425_PCI_MAX_BUS 1
  71. /*define the maximum number of cards per bus segment*/
  72. #define IXP425_PCI_MAX_DEV 4
  73. /*define the maximum number of functions per device*/
  74. #define IXP425_PCI_MAX_FUNC 8
  75. /* define the maximum number of separate functions that we can
  76. potentially have on the bus*/
  77. #define IXP425_PCI_MAX_FUNC_ON_BUS (1+ IXP425_PCI_MAX_FUNC * \
  78. IXP425_PCI_MAX_DEV * \
  79. IXP425_PCI_MAX_BUS)
  80. /*define the maximum number of BARs per function*/
  81. #define IXP425_PCI_MAX_BAR_PER_FUNC 6
  82. #define IXP425_PCI_MAX_BAR (IXP425_PCI_MAX_BAR_PER_FUNC * \
  83. IXP425_PCI_MAX_FUNC_ON_BUS)
  84. #define PCI_NP_CBE_BESL (4)
  85. #define PCI_NP_AD_FUNCSL (8)
  86. #define REG_WRITE(b,o,v) (*(volatile unsigned int*)((b+o))=(v))
  87. #define REG_READ(b,o,v) ((v)=(*(volatile unsigned int*)((b+o))))
  88. #define PCI_DELAY 500
  89. #define USEC_LOOP_COUNT 533
  90. #define PCI_SETTLE_USEC 200
  91. #define PCI_MIN_RESET_ASSERT_USEC 2000
  92. /*Register addressing definitions for PCI controller configuration
  93. and status registers*/
  94. #define PCI_CSR_BASE (0xC0000000)
  95. /*
  96. #define PCI_NP_AD_OFFSET (0x00)
  97. #define PCI_NP_CBE_OFFSET (0x04)
  98. #define PCI_NP_WDATA_OFFSET (0x08)
  99. #define PCI_NP_RDATA_OFFSET (0x0C)
  100. #define PCI_CRP_OFFSET (0x10)
  101. #define PCI_CRP_WDATA_OFFSET (0x14)
  102. #define PCI_CRP_RDATA_OFFSET (0x18)
  103. #define PCI_CSR_OFFSET (0x1C)
  104. #define PCI_ISR_OFFSET (0x20)
  105. #define PCI_INTEN_OFFSET (0x24)
  106. #define PCI_DMACTRL_OFFSET (0x28)
  107. #define PCI_AHBMEMBASE_OFFSET (0x2C)
  108. #define PCI_AHBIOBASE_OFFSET (0x30)
  109. #define PCI_PCIMEMBASE_OFFSET (0x34)
  110. #define PCI_AHBDOORBELL_OFFSET (0x38)
  111. #define PCI_PCIDOORBELL_OFFSET (0x3C)
  112. #define PCI_ATPDMA0_AHBADDR (0x40)
  113. #define PCI_ATPDMA0_PCIADDR (0x44)
  114. #define PCI_ATPDMA0_LENADDR (0x48)
  115. #define PCI_ATPDMA1_AHBADDR (0x4C)
  116. #define PCI_ATPDMA1_PCIADDR (0x50)
  117. #define PCI_ATPDMA1_LENADDR (0x54)
  118. #define PCI_PTADMA0_AHBADDR (0x58)
  119. #define PCI_PTADMA0_PCIADDR (0x5C)
  120. #define PCI_PTADMA0_LENADDR (0x60)
  121. #define PCI_PTADMA1_AHBADDR (0x64)
  122. #define PCI_PTADMA1_PCIADDR (0x68)
  123. #define PCI_PTADMA1_LENADDR (0x6C)
  124. */
  125. /*Non prefetch registers bit definitions*/
  126. /*
  127. #define NP_CMD_INTACK (0x0)
  128. #define NP_CMD_SPECIAL (0x1)
  129. #define NP_CMD_IOREAD (0x2)
  130. #define NP_CMD_IOWRITE (0x3)
  131. #define NP_CMD_MEMREAD (0x6)
  132. #define NP_CMD_MEMWRITE (0x7)
  133. #define NP_CMD_CONFIGREAD (0xa)
  134. #define NP_CMD_CONFIGWRITE (0xb)
  135. */
  136. /*define the default setting of the AHB memory base reg*/
  137. #define IXP425_PCI_AHBMEMBASE_DEFAULT 0x00010203
  138. #define IXP425_PCI_AHBIOBASE_DEFAULT 0x0
  139. #define IXP425_PCI_PCIMEMBASE_DEFAULT 0x0
  140. /*define the default settings for the controller's BARs*/
  141. #ifdef IXP425_PCI_SIMPLE_MAPPING
  142. #define IXP425_PCI_BAR_0_DEFAULT 0x00000000
  143. #define IXP425_PCI_BAR_1_DEFAULT 0x01000000
  144. #define IXP425_PCI_BAR_2_DEFAULT 0x02000000
  145. #define IXP425_PCI_BAR_3_DEFAULT 0x03000000
  146. #define IXP425_PCI_BAR_4_DEFAULT 0x00000000
  147. #define IXP425_PCI_BAR_5_DEFAULT 0x00000000
  148. #else
  149. #define IXP425_PCI_BAR_0_DEFAULT 0x40000000
  150. #define IXP425_PCI_BAR_1_DEFAULT 0x41000000
  151. #define IXP425_PCI_BAR_2_DEFAULT 0x42000000
  152. #define IXP425_PCI_BAR_3_DEFAULT 0x43000000
  153. #define IXP425_PCI_BAR_4_DEFAULT 0x00000000
  154. #define IXP425_PCI_BAR_5_DEFAULT 0x00000000
  155. #endif
  156. /*Configuration Port register bit definitions*/
  157. #define PCI_CRP_WRITE BIT(16)
  158. /*ISR (Interrupt status) Register bit definitions*/
  159. #define PCI_ISR_PSE BIT(0)
  160. #define PCI_ISR_PFE BIT(1)
  161. #define PCI_ISR_PPE BIT(2)
  162. #define PCI_ISR_AHBE BIT(3)
  163. #define PCI_ISR_APDC BIT(4)
  164. #define PCI_ISR_PADC BIT(5)
  165. #define PCI_ISR_ADB BIT(6)
  166. #define PCI_ISR_PDB BIT(7)
  167. /*INTEN (Interrupt Enable) Register bit definitions*/
  168. #define PCI_INTEN_PSE BIT(0)
  169. #define PCI_INTEN_PFE BIT(1)
  170. #define PCI_INTEN_PPE BIT(2)
  171. #define PCI_INTEN_AHBE BIT(3)
  172. #define PCI_INTEN_APDC BIT(4)
  173. #define PCI_INTEN_PADC BIT(5)
  174. #define PCI_INTEN_ADB BIT(6)
  175. #define PCI_INTEN_PDB BIT(7)
  176. /*PCI configuration regs.*/
  177. #define PCI_CFG_VENDOR_ID 0x00
  178. #define PCI_CFG_DEVICE_ID 0x02
  179. #define PCI_CFG_COMMAND 0x04
  180. #define PCI_CFG_STATUS 0x06
  181. #define PCI_CFG_REVISION 0x08
  182. #define PCI_CFG_PROGRAMMING_IF 0x09
  183. #define PCI_CFG_SUBCLASS 0x0a
  184. #define PCI_CFG_CLASS 0x0b
  185. #define PCI_CFG_CACHE_LINE_SIZE 0x0c
  186. #define PCI_CFG_LATENCY_TIMER 0x0d
  187. #define PCI_CFG_HEADER_TYPE 0x0e
  188. #define PCI_CFG_BIST 0x0f
  189. #define PCI_CFG_BASE_ADDRESS_0 0x10
  190. #define PCI_CFG_BASE_ADDRESS_1 0x14
  191. #define PCI_CFG_BASE_ADDRESS_2 0x18
  192. #define PCI_CFG_BASE_ADDRESS_3 0x1c
  193. #define PCI_CFG_BASE_ADDRESS_4 0x20
  194. #define PCI_CFG_BASE_ADDRESS_5 0x24
  195. #define PCI_CFG_CIS 0x28
  196. #define PCI_CFG_SUB_VENDOR_ID 0x2c
  197. #define PCI_CFG_SUB_SYSTEM_ID 0x2e
  198. #define PCI_CFG_EXPANSION_ROM 0x30
  199. #define PCI_CFG_RESERVED_0 0x34
  200. #define PCI_CFG_RESERVED_1 0x38
  201. #define PCI_CFG_DEV_INT_LINE 0x3c
  202. #define PCI_CFG_DEV_INT_PIN 0x3d
  203. #define PCI_CFG_MIN_GRANT 0x3e
  204. #define PCI_CFG_MAX_LATENCY 0x3f
  205. #define PCI_CFG_SPECIAL_USE 0x41
  206. #define PCI_CFG_MODE 0x43
  207. /*Specify the initial command we send to PCI devices*/
  208. #define INITIAL_PCI_CMD (PCI_CMD_IO_ENABLE \
  209. | PCI_CMD_MEM_ENABLE \
  210. | PCI_CMD_MASTER_ENABLE \
  211. | PCI_CMD_WI_ENABLE)
  212. /*define the sub vendor and subsystem to be used */
  213. #define IXP425_PCI_SUB_VENDOR_SYSTEM 0x00000000
  214. #define PCI_IRQ_LINES 4
  215. #define PCI_CMD_IO_ENABLE 0x0001 /* IO access enable */
  216. #define PCI_CMD_MEM_ENABLE 0x0002 /* memory access enable */
  217. #define PCI_CMD_MASTER_ENABLE 0x0004 /* bus master enable */
  218. #define PCI_CMD_MON_ENABLE 0x0008 /* monitor special cycles enable */
  219. #define PCI_CMD_WI_ENABLE 0x0010 /* write and invalidate enable */
  220. #define PCI_CMD_SNOOP_ENABLE 0x0020 /* palette snoop enable */
  221. #define PCI_CMD_PERR_ENABLE 0x0040 /* parity error enable */
  222. #define PCI_CMD_WC_ENABLE 0x0080 /* wait cycle enable */
  223. #define PCI_CMD_SERR_ENABLE 0x0100 /* system error enable */
  224. #define PCI_CMD_FBTB_ENABLE 0x0200 /* fast back to back enable */
  225. /*CSR Register bit definitions*/
  226. #define PCI_CSR_HOST BIT(0)
  227. #define PCI_CSR_ARBEN BIT(1)
  228. #define PCI_CSR_ADS BIT(2)
  229. #define PCI_CSR_PDS BIT(3)
  230. #define PCI_CSR_ABE BIT(4)
  231. #define PCI_CSR_DBT BIT(5)
  232. #define PCI_CSR_ASE BIT(8)
  233. #define PCI_CSR_IC BIT(15)
  234. /*Configuration command bit definitions*/
  235. #define PCI_CFG_CMD_IOAE BIT(0)
  236. #define PCI_CFG_CMD_MAE BIT(1)
  237. #define PCI_CFG_CMD_BME BIT(2)
  238. #define PCI_CFG_CMD_MWIE BIT(4)
  239. #define PCI_CFG_CMD_SER BIT(8)
  240. #define PCI_CFG_CMD_FBBE BIT(9)
  241. #define PCI_CFG_CMD_MDPE BIT(24)
  242. #define PCI_CFG_CMD_STA BIT(27)
  243. #define PCI_CFG_CMD_RTA BIT(28)
  244. #define PCI_CFG_CMD_RMA BIT(29)
  245. #define PCI_CFG_CMD_SSE BIT(30)
  246. #define PCI_CFG_CMD_DPE BIT(31)
  247. /*DMACTRL DMA Control and status Register*/
  248. #define PCI_DMACTRL_APDCEN BIT(0)
  249. #define PCI_DMACTRL_APDC0 BIT(4)
  250. #define PCI_DMACTRL_APDE0 BIT(5)
  251. #define PCI_DMACTRL_APDC1 BIT(6)
  252. #define PCI_DMACTRL_APDE1 BIT(7)
  253. #define PCI_DMACTRL_PADCEN BIT(8)
  254. #define PCI_DMACTRL_PADC0 BIT(12)
  255. #define PCI_DMACTRL_PADE0 BIT(13)
  256. #define PCI_DMACTRL_PADC1 BIT(14)
  257. #define PCI_DMACTRL_PADE1 BIT(15)
  258. /* GPIO related register */
  259. #undef IXP425_GPIO_GPOUTR
  260. #undef IXP425_GPIO_GPOER
  261. #undef IXP425_GPIO_GPINR
  262. #undef IXP425_GPIO_GPISR
  263. #undef IXP425_GPIO_GPIT1R
  264. #undef IXP425_GPIO_GPIT2R
  265. #undef IXP425_GPIO_GPCLKR
  266. #define IXP425_GPIO_GPOUTR 0xC8004000
  267. #define IXP425_GPIO_GPOER 0xC8004004
  268. #define IXP425_GPIO_GPINR 0xC8004008
  269. #define IXP425_GPIO_GPISR 0xC800400C
  270. #define IXP425_GPIO_GPIT1R 0xC8004010
  271. #define IXP425_GPIO_GPIT2R 0xC8004014
  272. #define IXP425_GPIO_GPCLKR 0xC8004018
  273. #define READ_GPIO_REG(addr,val) \
  274. (val) = *((volatile int *)(addr));
  275. #define WRITE_GPIO_REG(addr,val) \
  276. *((volatile int *)(addr)) = (val);
  277. #endif