Advertisement
Guest User

Untitled

a guest
Oct 6th, 2014
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 29.46 KB | None | 0 0
  1. #ifndef _AR7240_H
  2. #define _AR7240_H
  3.  
  4. #include <asm/types.h>
  5. #include <asm/addrspace.h>
  6.  
  7. typedef unsigned int ar7240_reg_t;
  8.  
  9. #define ar7240_reg_rd(_phys)    (*(volatile ar7240_reg_t *)KSEG1ADDR(_phys))
  10. #define ar7240_reg_wr_nf(_phys, _val) \
  11.                     ((*(volatile ar7240_reg_t *)KSEG1ADDR(_phys)) = (_val))
  12.  
  13. #define ar7240_reg_wr(_phys, _val) do {     \
  14.          ar7240_reg_wr_nf(_phys, _val);     \
  15.          ar7240_reg_rd(_phys);       \
  16. }while(0);
  17.  
  18. #define ar7240_reg_rmw_set(_reg, _mask)  do {                        \
  19.     ar7240_reg_wr((_reg), (ar7240_reg_rd((_reg)) | (_mask)));      \
  20.     ar7240_reg_rd((_reg));                                           \
  21. }while(0);
  22.  
  23. #define ar7240_reg_rmw_clear(_reg, _mask)  do {                        \
  24.     ar7240_reg_wr((_reg), (ar7240_reg_rd((_reg)) & ~(_mask)));      \
  25.     ar7240_reg_rd((_reg));                                           \
  26. }while(0);
  27.  
  28. /*
  29.  * Address map
  30.  */
  31. #define AR7240_PCI_MEM_BASE             0x10000000  /* 128M */
  32. #define AR7240_APB_BASE                 0x18000000  /* 384M */
  33. #define AR7240_GE0_BASE                 0x19000000  /* 16M */
  34. #define AR7240_GE1_BASE                 0x1a000000  /* 16M */
  35. #define AR7240_USB_OHCI_BASE            0x1b000000
  36. #define AR7240_USB_EHCI_BASE            0x1b000000
  37. #define AR7240_SPI_BASE                 0x1f000000
  38.  
  39. /*
  40.  * Added the PCI LCL RESET register from u-boot
  41.  * ar7240_soc.h so that we can query the PCI LCL RESET
  42.  * register for the presence of WLAN H/W.
  43.  */
  44. #define AR7240_PCI_LCL_BASE             (AR7240_APB_BASE+0x000f0000)
  45. #define AR7240_PCI_LCL_APP              (AR7240_PCI_LCL_BASE+0x00)
  46. #define AR7240_PCI_LCL_RESET            (AR7240_PCI_LCL_BASE+0x18)
  47.  
  48. /*
  49.  * APB block
  50.  */
  51. #define AR7240_DDR_CTL_BASE             AR7240_APB_BASE+0x00000000
  52. #define AR7240_CPU_BASE                 AR7240_APB_BASE+0x00010000
  53. #define AR7240_UART_BASE                AR7240_APB_BASE+0x00020000
  54. #define AR7240_USB_CONFIG_BASE          AR7240_APB_BASE+0x00030000
  55. #define AR7240_GPIO_BASE                AR7240_APB_BASE+0x00040000
  56. #define AR7240_PLL_BASE                 AR7240_APB_BASE+0x00050000
  57. #define AR7240_RESET_BASE               AR7240_APB_BASE+0x00060000
  58. #define AR7240_SLIC_BASE                AR7240_APB_BASE+0x00090000
  59. #define AR7240_DMA_BASE                 AR7240_APB_BASE+0x000A0000
  60. #define AR7240_STEREO_BASE              AR7240_APB_BASE+0x000B0000
  61. #define AR7240_PCI_CTLR_BASE           AR7240_APB_BASE+0x000F0000
  62.  
  63. /*
  64.  * DDR block
  65.  */
  66. #define AR7240_DDR_CONFIG               AR7240_DDR_CTL_BASE+0
  67. #define AR7240_DDR_CONFIG2              AR7240_DDR_CTL_BASE+4
  68. #define AR7240_DDR_MODE                 AR7240_DDR_CTL_BASE+0x08
  69. #define AR7240_DDR_EXT_MODE             AR7240_DDR_CTL_BASE+0x0c
  70. #define AR7240_DDR_CONTROL              AR7240_DDR_CTL_BASE+0x10
  71. #define AR7240_DDR_REFRESH              AR7240_DDR_CTL_BASE+0x14
  72. #define AR7240_DDR_RD_DATA_THIS_CYCLE   AR7240_DDR_CTL_BASE+0x18
  73. #define AR7240_DDR_TAP_CONTROL0         AR7240_DDR_CTL_BASE+0x1c
  74. #define AR7240_DDR_TAP_CONTROL1         AR7240_DDR_CTL_BASE+0x20
  75. #define AR7240_DDR_TAP_CONTROL2         AR7240_DDR_CTL_BASE+0x24
  76. #define AR7240_DDR_TAP_CONTROL3         AR7240_DDR_CTL_BASE+0x28
  77.  
  78. /*
  79.  * DDR Config values
  80.  */
  81. #define AR7240_DDR_CONFIG_16BIT             (1 << 31)
  82. #define AR7240_DDR_CONFIG_PAGE_OPEN         (1 << 30)
  83. #define AR7240_DDR_CONFIG_CAS_LAT_SHIFT      27
  84. #define AR7240_DDR_CONFIG_TMRD_SHIFT         23
  85. #define AR7240_DDR_CONFIG_TRFC_SHIFT         17
  86. #define AR7240_DDR_CONFIG_TRRD_SHIFT         13
  87. #define AR7240_DDR_CONFIG_TRP_SHIFT          9
  88. #define AR7240_DDR_CONFIG_TRCD_SHIFT         5
  89. #define AR7240_DDR_CONFIG_TRAS_SHIFT         0
  90.  
  91. #define AR7240_DDR_CONFIG2_BL2          (2 << 0)
  92. #define AR7240_DDR_CONFIG2_BL4          (4 << 0)
  93. #define AR7240_DDR_CONFIG2_BL8          (8 << 0)
  94.  
  95. #define AR7240_DDR_CONFIG2_BT_IL        (1 << 4)
  96. #define AR7240_DDR_CONFIG2_CNTL_OE_EN   (1 << 5)
  97. #define AR7240_DDR_CONFIG2_PHASE_SEL    (1 << 6)
  98. #define AR7240_DDR_CONFIG2_DRAM_CKE     (1 << 7)
  99. #define AR7240_DDR_CONFIG2_TWR_SHIFT    8
  100. #define AR7240_DDR_CONFIG2_TRTW_SHIFT   12
  101. #define AR7240_DDR_CONFIG2_TRTP_SHIFT   17
  102. #define AR7240_DDR_CONFIG2_TWTR_SHIFT   21
  103. #define AR7240_DDR_CONFIG2_HALF_WIDTH_L (1 << 31)
  104.  
  105. #define AR7240_DDR_TAP_DEFAULT          0x18
  106.  
  107. /*
  108.  * DDR block, gmac flushing
  109.  */
  110. #define AR7240_DDR_GE0_FLUSH            AR7240_DDR_CTL_BASE+0x7c
  111. #define AR7240_DDR_GE1_FLUSH            AR7240_DDR_CTL_BASE+0x80
  112. #define AR7240_DDR_USB_FLUSH            AR7240_DDR_CTL_BASE+0xa4
  113. #define AR7240_DDR_PCIE_FLUSH           AR7240_DDR_CTL_BASE+0x88
  114.  
  115. #define AR7240_EEPROM_GE0_MAC_ADDR      0xbfff1000
  116. #define AR7240_EEPROM_GE1_MAC_ADDR      0xbfff1006
  117.  
  118. /*
  119.  * PLL block/CPU
  120.  */
  121.  
  122. #define AR7240_PLL_CONFIG               AR7240_PLL_BASE+0x0
  123.  
  124.  
  125. #define PLL_DIV_SHIFT   0
  126. #define PLL_DIV_MASK    0x3ff
  127. #define REF_DIV_SHIFT   10
  128. #define REF_DIV_MASK    0xf
  129. #define AHB_DIV_SHIFT   19
  130. #define AHB_DIV_MASK    0x1
  131. #define DDR_DIV_SHIFT   22
  132. #define DDR_DIV_MASK    0x1
  133. #define AR7240_ETH_PLL_CONFIG           AR7240_PLL_BASE+0x4
  134. #define AR7242_ETH_XMII_CONFIG          AR7240_PLL_BASE+0x2c
  135. #define AR7240_AUDIO_PLL_CONFIG         AR7240_PLL_BASE+0x30
  136.  
  137. #define AR7240_ETH_INT0_CLK             AR7240_PLL_BASE+0x14
  138. #define AR7240_ETH_INT1_CLK             AR7240_PLL_BASE+0x18
  139.  
  140.  
  141. /*
  142.  * USB block
  143.  */
  144. #define AR7240_USB_FLADJ_VAL            AR7240_USB_CONFIG_BASE
  145. #define AR7240_USB_CONFIG               AR7240_USB_CONFIG_BASE+0x4
  146. #define AR7240_USB_WINDOW               0x1000000
  147. #define AR7240_USB_MODE         AR7240_USB_EHCI_BASE+0x1a8
  148.  
  149. /*
  150.  * PCI block
  151.  */
  152. #define AR7240_PCI_WINDOW           0x8000000       /* 128MB */
  153. #define AR7240_PCI_WINDOW0_OFFSET   AR7240_DDR_CTL_BASE+0x7c
  154. #define AR7240_PCI_WINDOW1_OFFSET   AR7240_DDR_CTL_BASE+0x80
  155. #define AR7240_PCI_WINDOW2_OFFSET   AR7240_DDR_CTL_BASE+0x84
  156. #define AR7240_PCI_WINDOW3_OFFSET   AR7240_DDR_CTL_BASE+0x88
  157. #define AR7240_PCI_WINDOW4_OFFSET   AR7240_DDR_CTL_BASE+0x8c
  158. #define AR7240_PCI_WINDOW5_OFFSET   AR7240_DDR_CTL_BASE+0x90
  159. #define AR7240_PCI_WINDOW6_OFFSET   AR7240_DDR_CTL_BASE+0x94
  160. #define AR7240_PCI_WINDOW7_OFFSET   AR7240_DDR_CTL_BASE+0x98
  161.  
  162. #define AR7240_PCI_WINDOW0_VAL      0x10000000
  163. #define AR7240_PCI_WINDOW1_VAL      0x11000000
  164. #define AR7240_PCI_WINDOW2_VAL      0x12000000
  165. #define AR7240_PCI_WINDOW3_VAL      0x13000000
  166. #define AR7240_PCI_WINDOW4_VAL      0x14000000
  167. #define AR7240_PCI_WINDOW5_VAL      0x15000000
  168. #define AR7240_PCI_WINDOW6_VAL      0x16000000
  169. #define AR7240_PCI_WINDOW7_VAL      0x07000000
  170.  
  171. #define ar7240_write_pci_window(_no)             \
  172.   ar7240_reg_wr(AR7240_PCI_WINDOW##_no##_OFFSET, AR7240_PCI_WINDOW##_no##_VAL);
  173.  
  174. /*
  175.  * CRP. To access the host controller config and status registers
  176.  */
  177. #define AR7240_PCI_CRP   0x180c0000
  178. #define AR7240_PCI_DEV_CFGBASE     0x14000000
  179. #define AR7240_PCI_CRP_AD_CBE            AR7240_PCI_CRP
  180. #define AR7240_PCI_CRP_WRDATA            AR7240_PCI_CRP+0x4
  181. #define AR7240_PCI_CRP_RDDATA            AR7240_PCI_CRP+0x8
  182. #define AR7240_PCI_ERROR                 AR7240_PCI_CRP+0x1c
  183. #define AR7240_PCI_ERROR_ADDRESS         AR7240_PCI_CRP+0x20
  184. #define AR7240_PCI_AHB_ERROR             AR7240_PCI_CRP+0x24
  185. #define AR7240_PCI_AHB_ERROR_ADDRESS     AR7240_PCI_CRP+0x28
  186.  
  187. #define AR7240_CRP_CMD_WRITE             0x00010000
  188. #define AR7240_CRP_CMD_READ              0x00000000
  189.  
  190. /*
  191.  * PCI CFG. To generate config cycles
  192.  */
  193. #define AR7240_PCI_CFG_AD           AR7240_PCI_CRP+0xc
  194. #define AR7240_PCI_CFG_CBE          AR7240_PCI_CRP+0x10
  195. #define AR7240_PCI_CFG_WRDATA       AR7240_PCI_CRP+0x14
  196. #define AR7240_PCI_CFG_RDDATA       AR7240_PCI_CRP+0x18
  197. #define AR7240_CFG_CMD_READ         0x0000000a
  198. #define AR7240_CFG_CMD_WRITE        0x0000000b
  199.  
  200. #define AR7240_PCI_IDSEL_ADLINE_START           17
  201.  
  202.  
  203. /*
  204.  * gpio configs
  205.  */
  206. #define AR7240_GPIO_OE                  AR7240_GPIO_BASE+0x0
  207. #define AR7240_GPIO_IN                  AR7240_GPIO_BASE+0x4
  208. #define AR7240_GPIO_OUT                 AR7240_GPIO_BASE+0x8
  209. #define AR7240_GPIO_SET                 AR7240_GPIO_BASE+0xc
  210. #define AR7240_GPIO_CLEAR               AR7240_GPIO_BASE+0x10
  211. #define AR7240_GPIO_INT_ENABLE          AR7240_GPIO_BASE+0x14
  212. #define AR7240_GPIO_INT_TYPE            AR7240_GPIO_BASE+0x18
  213. #define AR7240_GPIO_INT_POLARITY        AR7240_GPIO_BASE+0x1c
  214. #define AR7240_GPIO_INT_PENDING         AR7240_GPIO_BASE+0x20
  215. #define AR7240_GPIO_INT_MASK            AR7240_GPIO_BASE+0x24
  216. #define AR7240_GPIO_FUNCTIONS           AR7240_GPIO_BASE+0x28
  217. #define AR7240_GPIO_FUNCTION_2          AR7240_GPIO_BASE+0x30
  218.  
  219. /*
  220.  * IRQ Map.
  221.  * There are 4 conceptual ICs in the system. We generally give a block of 16
  222.  * irqs to each IC.
  223.  * CPU:                     0    - 0xf
  224.  *      MISC:               0x10 - 0x1f
  225.  *          GPIO:           0x20 - 0x2f
  226.  *      PCI :               0x30 - 0x40
  227.  *
  228.  */
  229. #define AR7240_CPU_IRQ_BASE         0x00
  230. #define AR7240_MISC_IRQ_BASE        0x10
  231. #define AR7240_GPIO_IRQ_BASE        0x20
  232. #define AR7240_PCI_IRQ_BASE         0x30
  233.  
  234. /*
  235.  * The IPs. Connected to CPU (hardware IP's; the first two are software)
  236.  */
  237. #define AR7240_CPU_IRQ_PCI                  AR7240_CPU_IRQ_BASE+2
  238. #define AR7240_CPU_IRQ_USB                  AR7240_CPU_IRQ_BASE+3
  239. #define AR7240_CPU_IRQ_GE0                  AR7240_CPU_IRQ_BASE+4
  240. #define AR7240_CPU_IRQ_GE1                  AR7240_CPU_IRQ_BASE+5
  241. #define AR7240_CPU_IRQ_MISC                 AR7240_CPU_IRQ_BASE+6
  242. #define AR7240_CPU_IRQ_TIMER                AR7240_CPU_IRQ_BASE+7
  243.  
  244. /*
  245.  * Interrupts connected to the CPU->Misc line.
  246.  */
  247. #define AR7240_MISC_IRQ_TIMER               AR7240_MISC_IRQ_BASE+0
  248. #define AR7240_MISC_IRQ_ERROR               AR7240_MISC_IRQ_BASE+1
  249. #define AR7240_MISC_IRQ_GPIO                AR7240_MISC_IRQ_BASE+2
  250. #define AR7240_MISC_IRQ_UART                AR7240_MISC_IRQ_BASE+3
  251. #define AR7240_MISC_IRQ_WATCHDOG            AR7240_MISC_IRQ_BASE+4
  252. #define AR7240_MISC_IRQ_PERF_COUNTER        AR7240_MISC_IRQ_BASE+5
  253. #define AR7240_MISC_IRQ_USB_OHCI            AR7240_MISC_IRQ_BASE+6
  254. #define AR7240_MISC_IRQ_DMA                 AR7240_MISC_IRQ_BASE+7
  255. #define AR7240_MISC_IRQ_ENET_LINK           AR7240_MISC_IRQ_BASE+12
  256.  
  257. #define AR7240_MISC_IRQ_COUNT                 13
  258.  
  259. #define MIMR_TIMER                          0x01
  260. #define MIMR_ERROR                          0x02
  261. #define MIMR_GPIO                           0x04
  262. #define MIMR_UART                           0x08
  263. #define MIMR_WATCHDOG                       0x10
  264. #define MIMR_PERF_COUNTER                   0x20
  265. #define MIMR_OHCI_USB                       0x40
  266. #define MIMR_DMA                            0x80
  267. #define MIMR_ENET_LINK                      0x1000
  268.  
  269. #define MISR_TIMER                          MIMR_TIMER
  270. #define MISR_ERROR                          MIMR_ERROR
  271. #define MISR_GPIO                           MIMR_GPIO
  272. #define MISR_UART                           MIMR_UART
  273. #define MISR_WATCHDOG                       MIMR_WATCHDOG
  274. #define MISR_PERF_COUNTER                   MIMR_PERF_COUNTER
  275. #define MISR_OHCI_USB                       MIMR_OHCI_USB
  276. #define MISR_DMA                            MIMR_DMA
  277.  
  278. /*
  279.  * Interrupts connected to the Misc->GPIO line
  280.  */
  281. #define AR7240_GPIO_IRQn(_gpio)             AR7240_GPIO_IRQ_BASE+(_gpio)
  282. #define AR7240_GPIO_IRQ_COUNT                 16
  283.  
  284. void ar7240_init_irq(void);
  285.  
  286. void ar7240_gpio_irq_init(int irq_base);
  287.  
  288. void ar7240_misc_enable_irq (unsigned int mask);
  289. void ar7240_misc_disable_irq (unsigned int mask);
  290.  
  291. unsigned int ar7240_misc_get_irq_mask (void);
  292. unsigned int ar7240_misc_get_irq_status (void);
  293.  
  294.  
  295. /* Interrupts connected to CPU->PCI */
  296. #ifdef CONFIG_PERICOM
  297. #   define AR7240_PRI_BUS_NO    0u
  298. #   define AR7240_PORT0_BUS_NO  1u
  299. #   define AR7240_PORT1_BUS_NO  2u
  300. #   define AR7240_PCI_IRQ_DEV0  (AR7240_PCI_IRQ_BASE + 0)
  301. #   define AR7240_PCI_IRQ_DEV1  (AR7240_PCI_IRQ_BASE + 1)
  302. #   define AR7240_PCI_IRQ_COUNT 2
  303. #else
  304. #   define AR7240_PCI_IRQ_DEV0  AR7240_PCI_IRQ_BASE+0
  305. #   define AR7240_PCI_IRQ_COUNT 1
  306. #endif /* CONFIG_PERICOM */
  307.  
  308. /*
  309.  * PCI interrupt mask and status
  310.  */
  311. #define PIMR_DEV0                           0x01
  312. #define PIMR_DEV1                           0x02
  313. #define PIMR_DEV2                           0x04
  314. #define PIMR_CORE                           0x10
  315.  
  316. #define PISR_DEV0                           PIMR_DEV0
  317. #define PISR_DEV1                           PIMR_DEV1
  318. #define PISR_DEV2                           PIMR_DEV2
  319. #define PISR_CORE                           PIMR_CORE
  320.  
  321. void ar7240_pci_irq_init(int irq_base); /* ??? */
  322.  
  323.  
  324. #define AR7240_GPIO_COUNT                   16
  325.  
  326. /*
  327.  * GPIO Function Enables
  328.  */
  329. #define AR7240_GPIO_FUNCTION_SPDIF2TCK_EN       (1<<31)
  330. #define AR7240_GPIO_FUNCTION_SPDIF_EN           (1<<30)
  331. #define AR7240_GPIO_FUNCTION_I2S_GPIO_18_22_EN  (1<<29)
  332. #define AR7240_GPIO_FUNCTION_I2S_REFCLKEN       (1<<28)
  333. #define AR7240_GPIO_FUNCTION_I2S_MCKEN          (1<<27)
  334. #define AR7240_GPIO_FUNCTION_I2S0_EN            (1<<26)
  335. #define AR7240_GPIO_FUNCTION_ETH_SWITCH_LED_DUPL_EN (1<<25)
  336. #define AR7240_GPIO_FUNCTION_ETH_SWITCH_LED_COLL    (1<<24)
  337. #define AR7240_GPIO_FUNCTION_ETH_SWITCH_LED_ACTV    (1<<23)
  338. #define AR7240_GPIO_FUNCTION_PLL_SHIFT_EN       (1<<22)
  339. #define AR7240_GPIO_FUNCTION_EXT_MDIO_SEL       (1<<21)
  340. #define AR7240_GPIO_FUNCTION_CLK_OBS6_ENABLE    (1<<20)
  341. #define AR7240_GPIO_FUNCTION_CLK_OBS0_ENABLE    (1<<19)
  342. #define AR7240_GPIO_FUNCTION_SPI_EN             (1<<18)
  343. #define AR7240_GPIO_FUNCTION_DDR_DQOE_EN        (1<<17)
  344. #define AR7240_GPIO_FUNCTION_PCIEPHY_TST_EN     (1<<16)
  345. #define AR7240_GPIO_FUNCTION_S26_UART_DISABLE   (1<<15)
  346. #define AR7240_GPIO_FUNCTION_SPI_CS_1_EN        (1<<14)
  347. #define AR7240_GPIO_FUNCTION_SPI_CS_0_EN        (1<<13)
  348. #define AR7240_GPIO_FUNCTION_CLK_OBS5_ENABLE    (1<<12)
  349. #define AR7240_GPIO_FUNCTION_CLK_OBS4_ENABLE    (1<<11)
  350. #define AR7240_GPIO_FUNCTION_CLK_OBS3_ENABLE    (1<<10)
  351. #define AR7240_GPIO_FUNCTION_CLK_OBS2_ENABLE    (1<< 9)
  352. #define AR7240_GPIO_FUNCTION_CLK_OBS1_ENABLE    (1<< 8)
  353. #define AR7240_GPIO_FUNCTION_ETH_SWITCH_LED4_EN (1<< 7)
  354. #define AR7240_GPIO_FUNCTION_ETH_SWITCH_LED3_EN (1<< 6)
  355. #define AR7240_GPIO_FUNCTION_ETH_SWITCH_LED2_EN (1<< 5)
  356. #define AR7240_GPIO_FUNCTION_ETH_SWITCH_LED1_EN (1<< 4)
  357. #define AR7240_GPIO_FUNCTION_ETH_SWITCH_LED0_EN (1<< 3)
  358. #define AR7240_GPIO_FUNCTION_UART_RTS_CTS_EN    (1<< 2)
  359. #define AR7240_GPIO_FUNCTION_UART_EN            (1<< 1)
  360. #define AR7240_GPIO_FUNCTION_JTAG_DISABLE       (1<< 0)
  361.  
  362. #define AR7240_GPIO_FUNCTION_2_EN_I2WS_ON_0     (1<<4)
  363. #define AR7240_GPIO_FUNCTION_2_EN_I2SCK_ON_1    (1<<3)
  364. #define AR7240_GPIO_FUNCTION_2_I2S_ON_LED       (1<<1)
  365.  
  366.  
  367. /*
  368.  * GPIO Access & Control
  369.  */
  370. void ar7240_gpio_init(void);
  371. void ar7240_gpio_down(void);
  372. void ar7240_gpio_up(void);
  373.  
  374. /*
  375.  * GPIO Helper Functions
  376.  */
  377. void ar7240_gpio_enable_slic(void);
  378.  
  379. /* enable UART block, takes away GPIO 10 and 9 */
  380. void ar7240_gpio_enable_uart(void);
  381.  
  382. /* enable STEREO block, takes away GPIO 11,8,7, and 6 */
  383. void ar7240_gpio_enable_stereo(void);
  384.  
  385. /* allow CS0/CS1 to be controlled via SPI register, takes away GPIO0/GPIO1 */
  386. void ar7240_gpio_enable_spi_cs1_cs0(void);
  387.  
  388. /* allow GPIO0/GPIO1 to be used as SCL/SDA for software based i2c */
  389. void ar7240_gpio_enable_i2c_on_gpio_0_1(void);
  390.  
  391. /*
  392.  * GPIO General Functions
  393.  */
  394. void ar7240_gpio_drive_low(unsigned int mask);
  395. void ar7240_gpio_drive_high(unsigned int mask);
  396.  
  397. unsigned int ar7240_gpio_float_high_test(unsigned int mask);
  398.  
  399. /*
  400.  * Software support of i2c on gpio 0/1
  401.  */
  402. int ar7240_i2c_raw_write_bytes_to_addr(int addr, unsigned char *buffer, int count);
  403. int ar7240_i2c_raw_read_bytes_from_addr(int addr, unsigned char *buffer, int count);
  404.  
  405. /* SPI, SLIC and GPIO are all multiplexed on gpio pins */
  406. #define AR7240_SPI_FS           AR7240_SPI_BASE
  407. #define AR7240_SPI_READ         AR7240_SPI_BASE
  408. #define AR7240_SPI_CLOCK        AR7240_SPI_BASE+4
  409. #define AR7240_SPI_WRITE        AR7240_SPI_BASE+8
  410. #define AR7240_SPI_RD_STATUS    AR7240_SPI_BASE+12
  411. #define AR7240_SPI_D0_HIGH      (1<<0)             /* Pin spi_do   */
  412. #define AR7240_SPI_CLK_HIGH     (1<<8)             /* Pin spi_clk  */
  413.  
  414. #define AR7240_SPI_CS_ENABLE_0  (6<<16)            /* Pin gpio/cs0 (active low) */
  415. #define AR7240_SPI_CS_ENABLE_1  (5<<16)            /* Pin gpio/cs1 (active low) */
  416. #define AR7240_SPI_CS_ENABLE_2  (3<<16)            /* Pin gpio/cs2 (active low) */
  417. //#define AR7240_SPI_CS_DIS       (AR7240_SPI_CS_ENABLE_0|AR7240_SPI_CS_ENABLE_1|AR7240_SPI_CS_ENABLE_2)
  418. #define AR7240_SPI_CS_DIS       0x70000
  419.  
  420.  
  421. #define AR7240_SPI_RD_STATUS     AR7240_SPI_BASE+12 /* spi_di is clocked into register pos 0 every clock */
  422. /*
  423.  * SOC
  424.  */
  425. #define AR7240_SPI_CMD_WRITE_SR     0x01
  426. #define AR7240_SPI_CMD_WREN         0x06
  427. #define AR7240_SPI_CMD_RD_STATUS    0x05
  428. #define AR7240_SPI_CMD_FAST_READ    0x0b
  429. #define AR7240_SPI_CMD_PAGE_PROG    0x02
  430. #define AR7240_SPI_CMD_SECTOR_ERASE 0xd8
  431.  
  432. /*
  433.  * Reset block
  434.  */
  435. #define AR7240_GENERAL_TMR            AR7240_RESET_BASE+0
  436. #define AR7240_GENERAL_TMR_RELOAD     AR7240_RESET_BASE+4
  437. #define AR7240_WATCHDOG_TMR_CONTROL   AR7240_RESET_BASE+8
  438. #define AR7240_WATCHDOG_TMR           AR7240_RESET_BASE+0xc
  439. #define AR7240_MISC_INT_STATUS        AR7240_RESET_BASE+0x10
  440. #define AR7240_MISC_INT_MASK          AR7240_RESET_BASE+0x14
  441.  
  442. #define AR7240_PCI_INT_STATUS         AR7240_PCI_CTLR_BASE+0x4c
  443. #define AR7240_PCI_INT_MASK           AR7240_PCI_CTLR_BASE+0x50
  444. #define AR7240_PCI_INT_A_L      (1 << 14) /* INTA Level Trigger */
  445. #define AR7240_PCI_INT_B_L      (1 << 15) /* INTB Level Trigger */
  446. #define AR7240_PCI_INT_C_L      (1 << 16) /* INTC Level Trigger */
  447. #define AR7240_GLOBAL_INT_STATUS      AR7240_RESET_BASE+0x20
  448. #define AR7240_RESET                  AR7240_RESET_BASE+0x1c
  449. #define AR7240_OBSERVATION_ENABLE     AR7240_RESET_BASE+0x28
  450.  
  451.  
  452. #define AR7240_WD_ACT_MASK      3u
  453. #define AR7240_WD_ACT_NONE      0u /* No Action */
  454. #define AR7240_WD_ACT_GP_INTR   1u /* General purpose intr */
  455. #define AR7240_WD_ACT_NMI       2u /* NMI */
  456. #define AR7240_WD_ACT_RESET     3u /* Full Chip Reset */
  457.  
  458. #define AR7240_WD_LAST_SHIFT    31
  459. #define AR7240_WD_LAST_MASK     ((uint32_t)(1 << AR7240_WD_LAST_SHIFT))
  460.  
  461.  
  462.  
  463. /*
  464.  * Performace counters
  465.  */
  466. #define AR7240_PERF0_COUNTER          AR7240_GE0_BASE+0xa0
  467. #define AR7240_PERF1_COUNTER          AR7240_GE1_BASE+0xa0
  468.  
  469. /*
  470.  * SLIC/STEREO DMA Size Configurations
  471.  */
  472. #define AR7240_DMA_BUF_SIZE_4X2      0x00
  473. #define AR7240_DMA_BUF_SIZE_8X2      0x01
  474. #define AR7240_DMA_BUF_SIZE_16X2     0x02
  475. #define AR7240_DMA_BUF_SIZE_32X2     0x03
  476. #define AR7240_DMA_BUF_SIZE_64X2     0x04
  477. #define AR7240_DMA_BUF_SIZE_128X2    0x05
  478. #define AR7240_DMA_BUF_SIZE_256X2    0x06
  479. #define AR7240_DMA_BUF_SIZE_512X2    0x07
  480.  
  481. /*
  482.  * SLIC/STEREO DMA Assignments
  483.  */
  484. #define AR7240_DMA_CHAN_SLIC0_RX     0
  485. #define AR7240_DMA_CHAN_SLIC1_RX     1
  486. #define AR7240_DMA_CHAN_STEREO_RX    2
  487. #define AR7240_DMA_CHAN_SLIC0_TX     3
  488. #define AR7240_DMA_CHAN_SLIC1_TX     4
  489. #define AR7240_DMA_CHAN_STEREO_TX    5
  490.  
  491. /* Low-level routines */
  492. void ar7240_dma_addr_wr  (int chan, unsigned int val);
  493. void ar7240_dma_config_wr(int chan, unsigned int val);
  494. void ar7240_dma_update_wr(int chan, unsigned int val);
  495.  
  496. unsigned int ar7240_dma_addr_rd  (int chan);
  497. unsigned int ar7240_dma_config_rd(int chan);
  498.  
  499. /* Use this routine to configure DMA access. Example:
  500.  *
  501.  * ar7240_dma_config_buffer( AR7240_DMA_CHAN_SLIC0_TX,
  502.  *                           < address of buffer >,
  503.  *                           AR7240_DMA_BUF_SIZE_512X2
  504.  */
  505. void ar7240_dma_config_buffer(int chan, void *buffer, int sizeCfg);
  506.  
  507. /*
  508.  * SLIC register definitions
  509.  */
  510. #define AR7240_SLIC_STATUS                   (AR7240_SLIC_BASE+0x00)
  511. #define AR7240_SLIC_CNTRL                    (AR7240_SLIC_BASE+0x04)
  512. #define AR7240_SLIC_SLOT0_NUM                (AR7240_SLIC_BASE+0x08)
  513. #define AR7240_SLIC_SLOT1_NUM                (AR7240_SLIC_BASE+0x0c)
  514. #define AR7240_SLIC_SAM_POS                  (AR7240_SLIC_BASE+0x2c)
  515. #define AR7240_SLIC_FREQ_DIV                 (AR7240_SLIC_BASE+0x30)
  516.  
  517. /*
  518.  * SLIC Control bits
  519.  */
  520. #define AR7240_SLIC_CNTRL_ENABLE             (1<<0)
  521. #define AR7240_SLIC_CNTRL_SLOT0_ENABLE       (1<<1)
  522. #define AR7240_SLIC_CNTRL_SLOT1_ENABLE       (1<<2)
  523. #define AR7240_SLIC_CNTRL_IRQ_ENABLE         (1<<3)
  524.  
  525. /*
  526.  * SLIC Helper Functions
  527.  */
  528. unsigned int ar7240_slic_status_rd(void);
  529. unsigned int ar7240_slic_cntrl_rd(void);
  530.  
  531. void ar7240_slic_cntrl_wr(unsigned int val);
  532. void ar7240_slic_0_slot_pos_wr(unsigned int val);
  533. void ar7240_slic_1_slot_pos_wr(unsigned int val);
  534. void ar7240_slic_freq_div_wr(unsigned int val);
  535. void ar7240_slic_sample_pos_wr(unsigned int val);
  536.  
  537. void ar7240_slic_setup(int _sam, int _s0n, int _s1n);
  538.  
  539. /*
  540.  * STEREO register definitions
  541.  */
  542. #define AR7240_STEREO_CONFIG    (AR7240_STEREO_BASE+0x00)
  543. #define AR7240_STEREO_VOLUME    (AR7240_STEREO_BASE+0x08)
  544.  
  545. /*
  546.  * Stereo Configuration Bits
  547.  */
  548. #define AR7240_STEREO_CONFIG_SPDIF_ENABLE           (1<<23)
  549. #define AR7240_STEREO_CONFIG_ENABLE                 (1<<21)
  550. #define AR7240_STEREO_CONFIG_RESET                  (1<<19)
  551. #define AR7240_STEREO_CONFIG_DELAY                  (1<<18)
  552. #define AR7240_STEREO_CONFIG_PCM_SWAP               (1<<17)
  553. #define AR7240_STEREO_CONFIG_MIC_WORD_SIZE          (1<<16)
  554. #define AR7240_STEREO_CONFIG_MODE(x)                ((3&x)<<14)
  555. #define AR7240_STEREO_MODE_STEREO                   0
  556. #define AR7240_STEREO_MODE_LEFT                     1
  557. #define AR7240_STEREO_MODE_RIGHT                    2
  558. #define AR7240_STEREO_CONFIG_DATA_WORD_SIZE(x)      ((3&x)<<12)
  559. #define AR7240_STEREO_CONFIG_I2S_32B_WORD           (1<<11)
  560. #define AR7240_STEREO_CONFIG_I2S_MCLK_SEL           (1<<10)
  561. #define AR7240_STEREO_CONFIG_SAMPLE_CNT_CLEAR_TYPE  (1<<9)
  562. #define AR7240_STEREO_CONFIG_MASTER                 (1<<8)
  563. #define AR7240_STEREO_CONFIG_PSEDGE(x)              (0xff&x)
  564.  
  565. /*
  566.  * Word sizes to use with common configurations:
  567.  */
  568. #define AR7240_STEREO_WS_8B     0
  569. #define AR7240_STEREO_WS_16B    1
  570. #define AR7240_STEREO_WS_24B    2
  571. #define AR7240_STEREO_WS_32B    3
  572.  
  573. /*
  574.  * Audio data is little endian so 16b values must be swapped in the DMA buffers.
  575.  */
  576. static inline int ar7240_stereo_sample_16b_cvt(unsigned int _v) { return (((_v<<8)&0xff00)|((_v>>8)&0xff)) & 0xffff; }
  577.  
  578. /* Low level read/write of configuration */
  579. void ar7240_stereo_config_wr(unsigned int val);
  580. void ar7240_stereo_volume_wr(unsigned int val);
  581.  
  582. unsigned int ar7240_stereo_config_rd(void);
  583. unsigned int ar7240_stereo_volume_rd(void);
  584.  
  585. /*
  586.  * Common configurations for stereo block
  587.  */
  588. #define AR7240_STEREO_CFG_MASTER_STEREO_FS32_48KHZ(ws) ( \
  589.                AR7240_STEREO_CONFIG_DELAY   | \
  590.                AR7240_STEREO_CONFIG_RESET   | \
  591.                AR7240_STEREO_CONFIG_DATA_WORD_SIZE(ws) | \
  592.                        AR7240_STEREO_CONFIG_MODE(AR7240_STEREO_MODE_LEFT) | \
  593.                AR7240_STEREO_CONFIG_MASTER  | \
  594.                AR7240_STEREO_CONFIG_PSEDGE(26))
  595.  
  596. #define AR7240_STEREO_CFG_MASTER_STEREO_FS64_48KHZ(ws) ( \
  597.                AR7240_STEREO_CONFIG_DELAY   | \
  598.                AR7240_STEREO_CONFIG_RESET   | \
  599.                AR7240_STEREO_CONFIG_DATA_WORD_SIZE(ws) | \
  600.                        AR7240_STEREO_CONFIG_MODE(AR7240_STEREO_MODE_STEREO) | \
  601.                AR7240_STEREO_CONFIG_I2S_32B_WORD | \
  602.                AR7240_STEREO_CONFIG_MASTER  | \
  603.                AR7240_STEREO_CONFIG_PSEDGE(13))
  604.  
  605. #define AR7240_STEREO_CFG_SLAVE_STEREO_FS32_48KHZ(ws) ( \
  606.                AR7240_STEREO_CONFIG_RESET   | \
  607.                AR7240_STEREO_CONFIG_DATA_WORD_SIZE(ws) | \
  608.                        AR7240_STEREO_CONFIG_MODE(AR7240_STEREO_MODE_STEREO) | \
  609.                AR7240_STEREO_CONFIG_PSEDGE(26))
  610.  
  611. #define AR7240_STEREO_CFG_SLAVE_STEREO_FS64_48KHZ(ws) ( \
  612.                AR7240_STEREO_CONFIG_RESET   | \
  613.                AR7240_STEREO_CONFIG_I2S_32B_WORD | \
  614.                AR7240_STEREO_CONFIG_DATA_WORD_SIZE(ws) | \
  615.                        AR7240_STEREO_CONFIG_MODE(AR7240_STEREO_MODE_STEREO) | \
  616.                AR7240_STEREO_CONFIG_PSEDGE(13))
  617.  
  618. /* Routine sets up STEREO block for use. Use one of the predefined
  619.  * configurations. Example:
  620.  *
  621.  * ar7240_stereo_config_setup(
  622.  *   AR7240_STEREO_CFG_MASTER_STEREO_FS32_48KHZ(AR7240_STEREO_WS_16B))
  623.  *
  624.  */
  625. void ar7240_stereo_config_setup(unsigned int cfg);
  626.  
  627. /* 48 kHz, 16 bit data & i2s 32fs */
  628. static inline void ar7240_setup_for_stereo_master(int ws)
  629. { ar7240_stereo_config_setup(AR7240_STEREO_CFG_MASTER_STEREO_FS32_48KHZ(ws)); }
  630.  
  631. /* 48 kHz, 16 bit data & 32fs i2s */
  632. static inline void ar7240_setup_for_stereo_slave(int ws)
  633. { ar7240_stereo_config_setup(AR7240_STEREO_CFG_SLAVE_STEREO_FS32_48KHZ(ws)); }
  634.  
  635. /*
  636.  * PERF CTL bits
  637.  */
  638. #define PERF_CTL_PCI_AHB_0           ( 0)
  639. #define PERF_CTL_PCI_AHB_1           ( 1)
  640. #define PERF_CTL_USB_0               ( 2)
  641. #define PERF_CTL_USB_1               ( 3)
  642. #define PERF_CTL_GE0_PKT_CNT         ( 4)
  643. #define PERF_CTL_GEO_AHB_1           ( 5)
  644. #define PERF_CTL_GE1_PKT_CNT         ( 6)
  645. #define PERF_CTL_GE1_AHB_1           ( 7)
  646. #define PERF_CTL_PCI_DEV_0_BUSY      ( 8)
  647. #define PERF_CTL_PCI_DEV_1_BUSY      ( 9)
  648. #define PERF_CTL_PCI_DEV_2_BUSY      (10)
  649. #define PERF_CTL_PCI_HOST_BUSY       (11)
  650. #define PERF_CTL_PCI_DEV_0_ARB       (12)
  651. #define PERF_CTL_PCI_DEV_1_ARB       (13)
  652. #define PERF_CTL_PCI_DEV_2_ARB       (14)
  653. #define PERF_CTL_PCI_HOST_ARB        (15)
  654. #define PERF_CTL_PCI_DEV_0_ACTIVE    (16)
  655. #define PERF_CTL_PCI_DEV_1_ACTIVE    (17)
  656. #define PERF_CTL_PCI_DEV_2_ACTIVE    (18)
  657. #define PERF_CTL_HOST_ACTIVE         (19)
  658.  
  659. #define ar7240_perf0_ctl(_val) ar7240_reg_wr(AR7240_PERF_CTL, (_val))
  660. #define ar7240_perf1_ctl(_val) ar7240_reg_rmw_set(AR7240_PERF_CTL, ((_val) << 8))
  661.  
  662.  
  663. /* These are values used in platform.inc to select PLL settings */
  664.  
  665. #define AR7240_REV_ID           (AR7240_RESET_BASE + 0x90)
  666. #define AR7240_REV_ID_MASK      0xffff
  667. #define AR7240_REV_ID_AR7130    0xa0
  668. #define AR7240_REV_ID_AR7141    0xa1
  669. #define AR7240_REV_ID_AR7161    0xa2
  670. #define AR7240_REV_1_0          0xc0
  671. #define AR7240_REV_1_1          0xc1
  672. #define AR7240_REV_1_2          0xc2
  673. #define AR7241_REV_1_0          0x0100
  674. #define AR7242_REV_1_0          0x1100
  675. #define AR7241_REV_1_1          0x0101
  676. #define AR7242_REV_1_1          0x1101
  677.  
  678. #define is_ar7240()     (((ar7240_reg_rd(AR7240_REV_ID) & AR7240_REV_ID_MASK) == AR7240_REV_1_2) || \
  679.              ((ar7240_reg_rd(AR7240_REV_ID) & AR7240_REV_ID_MASK) == AR7240_REV_1_1) || \
  680.              ((ar7240_reg_rd(AR7240_REV_ID) & AR7240_REV_ID_MASK) == AR7240_REV_1_0))
  681.  
  682. #define is_ar7241()     (((ar7240_reg_rd(AR7240_REV_ID) & AR7240_REV_ID_MASK) == AR7241_REV_1_0) || \
  683.              ((ar7240_reg_rd(AR7240_REV_ID) & AR7240_REV_ID_MASK) == AR7241_REV_1_1))
  684.  
  685. #define is_ar7242()     (((ar7240_reg_rd(AR7240_REV_ID) & AR7240_REV_ID_MASK) == AR7242_REV_1_0) || \
  686.              ((ar7240_reg_rd(AR7240_REV_ID) & AR7240_REV_ID_MASK) == AR7242_REV_1_1))
  687.  
  688. #define AR7240_PLL_USE_REV_ID    0
  689. #define AR7240_PLL_200_200_100   1
  690. #define AR7240_PLL_300_300_150   2
  691. #define AR7240_PLL_333_333_166   3
  692. #define AR7240_PLL_266_266_133   4
  693. #define AR7240_PLL_266_266_66    5
  694. #define AR7240_PLL_400_400_200   6
  695. #define AR7240_PLL_600_400_150   7
  696.  
  697.  
  698. /*
  699.  * AR7240_RESET bit defines
  700.  */
  701. #define AR7240_RESET_EXTERNAL               (1 << 28)
  702. #define AR7240_RESET_FULL_CHIP              (1 << 24)
  703. #define AR7240_RESET_CPU_NMI                (1 << 21)
  704. #define AR7240_RESET_CPU_COLD_RESET_MASK    (1 << 20)
  705. #define AR7240_RESET_DMA                    (1 << 19)
  706. #define AR7240_RESET_SLIC                   (1 << 18)
  707. #define AR7240_RESET_STEREO                 (1 << 17)
  708. #define AR7240_RESET_DDR                    (1 << 16)
  709. #define AR7240_RESET_GE1_MAC                (1 << 13)
  710. #define AR7240_RESET_GE1_PHY                (1 << 12)
  711. #define AR7240_RESET_GE0_MAC                (1 << 9)
  712. #define AR7240_RESET_GE0_PHY                (1 << 8)
  713. #define AR7240_RESET_PCIE_PHY_SHIFT     (1 << 10)
  714. #define AR7240_RESET_USBSUS_OVRIDE      (1 << 3)
  715. #define AR7240_RESET_USB_OHCI_DLL           (1 << 3)
  716. #define AR7240_RESET_USB_HOST               (1 << 5)
  717. #define AR7240_RESET_USB_PHY                (1 << 4)
  718. #define AR7240_RESET_PCI_BUS                (1 << 1)
  719. #define AR7240_RESET_PCI_CORE               (1 << 0)
  720.  
  721.  
  722. void ar7240_reset(unsigned int mask);
  723. void ar7240_plat_setup(void);
  724.  
  725. /*
  726.  * Mii block
  727.  */
  728. #define AR7240_MII0_CTRL                    0x18070000
  729. #define AR7240_MII1_CTRL                    0x18070004
  730.  
  731. #define BIT(_x) (1 << (_x))
  732.  
  733. #define ar7240_get_bit(_reg, _bit)  (ar7240_reg_rd((_reg)) & (1 << (_bit)))
  734.  
  735. #define ar7240_flush_ge(_unit) do {                             \
  736.     u32     reg = (_unit) ? AR7240_DDR_GE1_FLUSH : AR7240_DDR_GE0_FLUSH;   \
  737.     ar7240_reg_wr(reg, 1);                 \
  738.     while((ar7240_reg_rd(reg) & 0x1));   \
  739.     ar7240_reg_wr(reg, 1);                 \
  740.     while((ar7240_reg_rd(reg) & 0x1));   \
  741. }while(0);
  742.  
  743. #define ar7240_flush_pcie() do {                             \
  744.     ar7240_reg_wr(AR7240_DDR_PCIE_FLUSH, 1);                 \
  745.     while((ar7240_reg_rd(AR7240_DDR_PCIE_FLUSH) & 0x1));   \
  746.     ar7240_reg_wr(AR7240_DDR_PCIE_FLUSH, 1);                 \
  747.     while((ar7240_reg_rd(AR7240_DDR_PCIE_FLUSH) & 0x1));   \
  748. }while(0);
  749.  
  750. #define ar7240_flush_USB() do {                             \
  751.     ar7240_reg_wr(AR7240_DDR_USB_FLUSH, 1);                 \
  752.     while((ar7240_reg_rd(AR7240_DDR_USB_FLUSH) & 0x1));   \
  753.     ar7240_reg_wr(AR7240_DDR_USB_FLUSH, 1);                 \
  754.     while((ar7240_reg_rd(AR7240_DDR_USB_FLUSH) & 0x1));   \
  755. }while(0);
  756.  
  757. int ar7240_local_read_config(int where, int size, u32 *value);
  758. int ar7240_local_write_config(int where, int size, u32 value);
  759. int ar7240_check_error(int verbose);
  760. unsigned char __ar7240_readb(const volatile void __iomem *p);
  761. unsigned short __ar7240_readw(const volatile void __iomem *p);
  762. void ap_usb_led_on(void);
  763. void ap_usb_led_off(void);
  764.  
  765. #define AR7240_WLAN0_CALDATA ((void *)0xbfff1000)
  766. #define AR7240_WLAN1_CALDATA ((void *)0xbfff5000)
  767.  
  768. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement