ifxmips_atm_amazon_se.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /******************************************************************************
  2. **
  3. ** FILE NAME : ifxmips_atm_amazon_se.c
  4. ** PROJECT : UEIP
  5. ** MODULES : ATM
  6. **
  7. ** DATE : 7 Jul 2009
  8. ** AUTHOR : Xu Liang
  9. ** DESCRIPTION : ATM driver common source file (core functions)
  10. ** COPYRIGHT : Copyright (c) 2006
  11. ** Infineon Technologies AG
  12. ** Am Campeon 1-12, 85579 Neubiberg, Germany
  13. **
  14. ** This program is free software; you can redistribute it and/or modify
  15. ** it under the terms of the GNU General Public License as published by
  16. ** the Free Software Foundation; either version 2 of the License, or
  17. ** (at your option) any later version.
  18. **
  19. ** HISTORY
  20. ** $Date $Author $Comment
  21. ** 07 JUL 2009 Xu Liang Init Version
  22. *******************************************************************************/
  23. /*
  24. * ####################################
  25. * Head File
  26. * ####################################
  27. */
  28. /*
  29. * Common Head File
  30. */
  31. #include <linux/kernel.h>
  32. #include <linux/module.h>
  33. #include <linux/version.h>
  34. #include <linux/types.h>
  35. #include <linux/errno.h>
  36. #include <linux/proc_fs.h>
  37. #include <linux/init.h>
  38. #include <linux/ioctl.h>
  39. #include <linux/platform_device.h>
  40. #include <asm/delay.h>
  41. /*
  42. * Chip Specific Head File
  43. */
  44. #include "ifxmips_atm_core.h"
  45. #include "ifxmips_atm_fw_amazon_se.h"
  46. #include <lantiq_soc.h>
  47. /*
  48. * ####################################
  49. * Definition
  50. * ####################################
  51. */
  52. /*
  53. * EMA Settings
  54. */
  55. #define EMA_CMD_BUF_LEN 0x0040
  56. #define EMA_CMD_BASE_ADDR (0x00001580 << 2)
  57. #define EMA_DATA_BUF_LEN 0x0100
  58. #define EMA_DATA_BASE_ADDR (0x00000B00 << 2)
  59. #define EMA_WRITE_BURST 0x2
  60. #define EMA_READ_BURST 0x2
  61. /*
  62. * ####################################
  63. * Declaration
  64. * ####################################
  65. */
  66. /*
  67. * Hardware Init/Uninit Functions
  68. */
  69. static inline void init_pmu(void);
  70. static inline void uninit_pmu(void);
  71. static inline void reset_ppe(struct platform_device *pdev);
  72. static inline void init_ema(void);
  73. static inline void init_mailbox(void);
  74. static inline void init_atm_tc(void);
  75. static inline void clear_share_buffer(void);
  76. /*
  77. * ####################################
  78. * Local Variable
  79. * ####################################
  80. */
  81. /*
  82. * ####################################
  83. * Local Function
  84. * ####################################
  85. */
  86. #define IFX_PMU_MODULE_PPE_SLL01 BIT(19)
  87. #define IFX_PMU_MODULE_PPE_TC BIT(21)
  88. #define IFX_PMU_MODULE_PPE_EMA BIT(22)
  89. #define IFX_PMU_MODULE_PPE_QSB BIT(18)
  90. #define IFX_PMU_MODULE_TPE BIT(13)
  91. #define IFX_PMU_MODULE_DSL_DFE BIT(9)
  92. static inline void init_pmu(void)
  93. {
  94. //*(unsigned long *)0xBF10201C &= ~((1 << 15) | (1 << 13) | (1 << 9));
  95. //PPE_TOP_PMU_SETUP(IFX_PMU_ENABLE);
  96. /* PPE_SLL01_PMU_SETUP(IFX_PMU_ENABLE);
  97. PPE_TC_PMU_SETUP(IFX_PMU_ENABLE);
  98. PPE_EMA_PMU_SETUP(IFX_PMU_ENABLE);
  99. //PPE_QSB_PMU_SETUP(IFX_PMU_ENABLE);
  100. PPE_TPE_PMU_SETUP(IFX_PMU_ENABLE);
  101. DSL_DFE_PMU_SETUP(IFX_PMU_ENABLE);*/
  102. ltq_pmu_enable(IFX_PMU_MODULE_PPE_SLL01 |
  103. IFX_PMU_MODULE_PPE_TC |
  104. IFX_PMU_MODULE_PPE_EMA |
  105. IFX_PMU_MODULE_TPE |
  106. IFX_PMU_MODULE_DSL_DFE);
  107. }
  108. static inline void uninit_pmu(void)
  109. {
  110. /*PPE_SLL01_PMU_SETUP(IFX_PMU_DISABLE);
  111. PPE_TC_PMU_SETUP(IFX_PMU_DISABLE);
  112. PPE_EMA_PMU_SETUP(IFX_PMU_DISABLE);
  113. //PPE_QSB_PMU_SETUP(IFX_PMU_DISABLE);
  114. PPE_TPE_PMU_SETUP(IFX_PMU_DISABLE);
  115. DSL_DFE_PMU_SETUP(IFX_PMU_DISABLE);
  116. //PPE_TOP_PMU_SETUP(IFX_PMU_DISABLE);*/
  117. }
  118. static inline void reset_ppe(struct platform_device *pdev)
  119. {
  120. #if 0 //MODULE
  121. unsigned int etop_cfg;
  122. unsigned int etop_mdio_cfg;
  123. unsigned int etop_ig_plen_ctrl;
  124. unsigned int enet_mac_cfg;
  125. etop_cfg = *IFX_PP32_ETOP_CFG;
  126. etop_mdio_cfg = *IFX_PP32_ETOP_MDIO_CFG;
  127. etop_ig_plen_ctrl = *IFX_PP32_ETOP_IG_PLEN_CTRL;
  128. enet_mac_cfg = *IFX_PP32_ENET_MAC_CFG;
  129. *IFX_PP32_ETOP_CFG = (*IFX_PP32_ETOP_CFG & ~0x03C0) | 0x0001;
  130. // reset PPE
  131. ifx_rcu_rst(IFX_RCU_DOMAIN_PPE, IFX_RCU_MODULE_ATM);
  132. *IFX_PP32_ETOP_MDIO_CFG = etop_mdio_cfg;
  133. *IFX_PP32_ETOP_IG_PLEN_CTRL = etop_ig_plen_ctrl;
  134. *IFX_PP32_ENET_MAC_CFG = enet_mac_cfg;
  135. *IFX_PP32_ETOP_CFG = etop_cfg;
  136. #endif
  137. }
  138. static inline void init_ema(void)
  139. {
  140. IFX_REG_W32((EMA_CMD_BUF_LEN << 16) | (EMA_CMD_BASE_ADDR >> 2), EMA_CMDCFG);
  141. IFX_REG_W32((EMA_DATA_BUF_LEN << 16) | (EMA_DATA_BASE_ADDR >> 2), EMA_DATACFG);
  142. IFX_REG_W32(0x000000FF, EMA_IER);
  143. IFX_REG_W32(EMA_READ_BURST | (EMA_WRITE_BURST << 2), EMA_CFG);
  144. }
  145. static inline void init_mailbox(void)
  146. {
  147. IFX_REG_W32(0xFFFFFFFF, MBOX_IGU1_ISRC);
  148. IFX_REG_W32(0x00000000, MBOX_IGU1_IER);
  149. IFX_REG_W32(0xFFFFFFFF, MBOX_IGU3_ISRC);
  150. IFX_REG_W32(0x00000000, MBOX_IGU3_IER);
  151. }
  152. static inline void init_atm_tc(void)
  153. {
  154. IFX_REG_W32(0x0000, DREG_AT_CTRL);
  155. IFX_REG_W32(0x0000, DREG_AR_CTRL);
  156. IFX_REG_W32(0x0, DREG_AT_IDLE0);
  157. IFX_REG_W32(0x0, DREG_AT_IDLE1);
  158. IFX_REG_W32(0x0, DREG_AR_IDLE0);
  159. IFX_REG_W32(0x0, DREG_AR_IDLE1);
  160. IFX_REG_W32(0x40, RFBI_CFG);
  161. IFX_REG_W32(0x0700, SFSM_DBA0);
  162. IFX_REG_W32(0x0818, SFSM_DBA1);
  163. IFX_REG_W32(0x0930, SFSM_CBA0);
  164. IFX_REG_W32(0x0944, SFSM_CBA1);
  165. IFX_REG_W32(0x14014, SFSM_CFG0);
  166. IFX_REG_W32(0x14014, SFSM_CFG1);
  167. IFX_REG_W32(0x0958, FFSM_DBA0);
  168. IFX_REG_W32(0x09AC, FFSM_DBA1);
  169. IFX_REG_W32(0x10006, FFSM_CFG0);
  170. IFX_REG_W32(0x10006, FFSM_CFG1);
  171. IFX_REG_W32(0x00000001, FFSM_IDLE_HEAD_BC0);
  172. IFX_REG_W32(0x00000001, FFSM_IDLE_HEAD_BC1);
  173. }
  174. static inline void clear_share_buffer(void)
  175. {
  176. volatile u32 *p = SB_RAM0_ADDR(0);
  177. unsigned int i;
  178. for ( i = 0; i < SB_RAM0_DWLEN + SB_RAM1_DWLEN; i++ )
  179. IFX_REG_W32(0, p++);
  180. }
  181. /*
  182. * Description:
  183. * Download PPE firmware binary code.
  184. * Input:
  185. * src --- u32 *, binary code buffer
  186. * dword_len --- unsigned int, binary code length in DWORD (32-bit)
  187. * Output:
  188. * int --- 0: Success
  189. * else: Error Code
  190. */
  191. static inline int pp32_download_code(u32 *code_src, unsigned int code_dword_len, u32 *data_src, unsigned int data_dword_len)
  192. {
  193. volatile u32 *dest;
  194. if ( code_src == 0 || ((unsigned long)code_src & 0x03) != 0
  195. || data_src == 0 || ((unsigned long)data_src & 0x03) != 0 )
  196. return -1;
  197. if ( code_dword_len <= CDM_CODE_MEMORYn_DWLEN(0) )
  198. IFX_REG_W32(0x00, CDM_CFG);
  199. else
  200. IFX_REG_W32(0x04, CDM_CFG);
  201. /* copy code */
  202. dest = CDM_CODE_MEMORY(0, 0);
  203. while ( code_dword_len-- > 0 )
  204. IFX_REG_W32(*code_src++, dest++);
  205. /* copy data */
  206. dest = CDM_DATA_MEMORY(0, 0);
  207. while ( data_dword_len-- > 0 )
  208. IFX_REG_W32(*data_src++, dest++);
  209. return 0;
  210. }
  211. /*
  212. * ####################################
  213. * Global Function
  214. * ####################################
  215. */
  216. extern void ase_fw_ver(unsigned int *major, unsigned int *minor)
  217. {
  218. ASSERT(major != NULL, "pointer is NULL");
  219. ASSERT(minor != NULL, "pointer is NULL");
  220. *major = FW_VER_ID->major;
  221. *minor = FW_VER_ID->minor;
  222. }
  223. void ase_init(struct platform_device *pdev)
  224. {
  225. init_pmu();
  226. reset_ppe(pdev);
  227. init_ema();
  228. init_mailbox();
  229. init_atm_tc();
  230. clear_share_buffer();
  231. }
  232. void ase_shutdown(void)
  233. {
  234. uninit_pmu();
  235. }
  236. /*
  237. * Description:
  238. * Initialize and start up PP32.
  239. * Input:
  240. * none
  241. * Output:
  242. * int --- 0: Success
  243. * else: Error Code
  244. */
  245. int ase_start(int pp32)
  246. {
  247. int ret;
  248. /* download firmware */
  249. ret = pp32_download_code(firmware_binary_code, sizeof(firmware_binary_code) / sizeof(*firmware_binary_code), firmware_binary_data, sizeof(firmware_binary_data) / sizeof(*firmware_binary_data));
  250. if ( ret != 0 )
  251. return ret;
  252. /* run PP32 */
  253. IFX_REG_W32(DBG_CTRL_RESTART, PP32_DBG_CTRL);
  254. /* idle for a while to let PP32 init itself */
  255. udelay(10);
  256. return 0;
  257. }
  258. /*
  259. * Description:
  260. * Halt PP32.
  261. * Input:
  262. * none
  263. * Output:
  264. * none
  265. */
  266. void ase_stop(int pp32)
  267. {
  268. /* halt PP32 */
  269. IFX_REG_W32(DBG_CTRL_STOP, PP32_DBG_CTRL);
  270. }
  271. struct ltq_atm_ops ase_ops = {
  272. .init = ase_init,
  273. .shutdown = ase_shutdown,
  274. .start = ase_start,
  275. .stop = ase_stop,
  276. .fw_ver = ase_fw_ver,
  277. };