2
0

ifxmips_ptm_amazon_se.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /******************************************************************************
  2. **
  3. ** FILE NAME : ifxmips_ptm_amazon_se.c
  4. ** PROJECT : UEIP
  5. ** MODULES : PTM
  6. **
  7. ** DATE : 7 Jul 2009
  8. ** AUTHOR : Xu Liang
  9. ** DESCRIPTION : PTM 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 <linux/reset.h>
  41. #include <asm/delay.h>
  42. /*
  43. * Chip Specific Head File
  44. */
  45. #include <asm/ifx/ifx_types.h>
  46. #include <asm/ifx/ifx_regs.h>
  47. #include <asm/ifx/common_routines.h>
  48. #include <asm/ifx/ifx_pmu.h>
  49. #include <asm/ifx/ifx_rcu.h>
  50. #include "ifxmips_ptm_adsl.h"
  51. #include "ifxmips_ptm_fw_amazon_se.h"
  52. /*
  53. * ####################################
  54. * Definition
  55. * ####################################
  56. */
  57. /*
  58. * EMA Settings
  59. */
  60. #define EMA_CMD_BUF_LEN 0x0040
  61. #define EMA_CMD_BASE_ADDR (0x00001580 << 2)
  62. #define EMA_DATA_BUF_LEN 0x0100
  63. #define EMA_DATA_BASE_ADDR (0x00000B00 << 2)
  64. #define EMA_WRITE_BURST 0x2
  65. #define EMA_READ_BURST 0x2
  66. /*
  67. * ####################################
  68. * Declaration
  69. * ####################################
  70. */
  71. /*
  72. * Hardware Init/Uninit Functions
  73. */
  74. static inline void init_pmu(void);
  75. static inline void uninit_pmu(void);
  76. static inline void reset_ppe(struct platform_device *pdev);
  77. static inline void init_ema(void);
  78. static inline void init_mailbox(void);
  79. static inline void init_atm_tc(void);
  80. static inline void clear_share_buffer(void);
  81. /*
  82. * ####################################
  83. * Local Variable
  84. * ####################################
  85. */
  86. /*
  87. * ####################################
  88. * Local Function
  89. * ####################################
  90. */
  91. static inline void init_pmu(void)
  92. {
  93. //*(unsigned long *)0xBF10201C &= ~((1 << 15) | (1 << 13) | (1 << 9));
  94. //PPE_TOP_PMU_SETUP(IFX_PMU_ENABLE);
  95. PPE_SLL01_PMU_SETUP(IFX_PMU_ENABLE);
  96. PPE_TC_PMU_SETUP(IFX_PMU_ENABLE);
  97. PPE_EMA_PMU_SETUP(IFX_PMU_ENABLE);
  98. //PPE_QSB_PMU_SETUP(IFX_PMU_ENABLE);
  99. PPE_TPE_PMU_SETUP(IFX_PMU_ENABLE);
  100. DSL_DFE_PMU_SETUP(IFX_PMU_ENABLE);
  101. }
  102. static inline void uninit_pmu(void)
  103. {
  104. PPE_SLL01_PMU_SETUP(IFX_PMU_DISABLE);
  105. PPE_TC_PMU_SETUP(IFX_PMU_DISABLE);
  106. PPE_EMA_PMU_SETUP(IFX_PMU_DISABLE);
  107. //PPE_QSB_PMU_SETUP(IFX_PMU_DISABLE);
  108. PPE_TPE_PMU_SETUP(IFX_PMU_DISABLE);
  109. DSL_DFE_PMU_SETUP(IFX_PMU_DISABLE);
  110. //PPE_TOP_PMU_SETUP(IFX_PMU_DISABLE);
  111. }
  112. static inline void reset_ppe(struct platform_device *pdev)
  113. {
  114. #ifdef MODULE
  115. unsigned int etop_cfg;
  116. unsigned int etop_mdio_cfg;
  117. unsigned int etop_ig_plen_ctrl;
  118. unsigned int enet_mac_cfg;
  119. etop_cfg = *IFX_PP32_ETOP_CFG;
  120. etop_mdio_cfg = *IFX_PP32_ETOP_MDIO_CFG;
  121. etop_ig_plen_ctrl = *IFX_PP32_ETOP_IG_PLEN_CTRL;
  122. enet_mac_cfg = *IFX_PP32_ENET_MAC_CFG;
  123. *IFX_PP32_ETOP_CFG = (*IFX_PP32_ETOP_CFG & ~0x03C0) | 0x0001;
  124. // reset PPE
  125. ifx_rcu_rst(IFX_RCU_DOMAIN_PPE, IFX_RCU_MODULE_PTM);
  126. *IFX_PP32_ETOP_MDIO_CFG = etop_mdio_cfg;
  127. *IFX_PP32_ETOP_IG_PLEN_CTRL = etop_ig_plen_ctrl;
  128. *IFX_PP32_ENET_MAC_CFG = enet_mac_cfg;
  129. *IFX_PP32_ETOP_CFG = etop_cfg;
  130. #endif
  131. }
  132. static inline void init_ema(void)
  133. {
  134. // Configure share buffer master selection
  135. *SB_MST_PRI0 = 1;
  136. *SB_MST_PRI1 = 1;
  137. // EMA Settings
  138. IFX_REG_W32((EMA_CMD_BUF_LEN << 16) | (EMA_CMD_BASE_ADDR >> 2), EMA_CMDCFG);
  139. IFX_REG_W32((EMA_DATA_BUF_LEN << 16) | (EMA_DATA_BASE_ADDR >> 2), EMA_DATACFG);
  140. IFX_REG_W32(0x000000FF, EMA_IER);
  141. IFX_REG_W32(EMA_READ_BURST | (EMA_WRITE_BURST << 2), EMA_CFG);
  142. }
  143. static inline void init_mailbox(void)
  144. {
  145. IFX_REG_W32(0xFFFFFFFF, MBOX_IGU1_ISRC);
  146. IFX_REG_W32(0x00000000, MBOX_IGU1_IER);
  147. IFX_REG_W32(0xFFFFFFFF, MBOX_IGU3_ISRC);
  148. IFX_REG_W32(0x00000000, MBOX_IGU3_IER);
  149. }
  150. static inline void init_atm_tc(void)
  151. {
  152. IFX_REG_W32(0x0F00, DREG_AT_CTRL);
  153. IFX_REG_W32(0x3C00, DREG_AR_CTRL);
  154. IFX_REG_W32(0x0, DREG_AT_IDLE0);
  155. IFX_REG_W32(0x0, DREG_AT_IDLE1);
  156. IFX_REG_W32(0x0, DREG_AR_IDLE0);
  157. IFX_REG_W32(0x0, DREG_AR_IDLE1);
  158. IFX_REG_W32(0x0, RFBI_CFG);
  159. IFX_REG_W32(0x0200, SFSM_DBA0);
  160. IFX_REG_W32(0x0800, SFSM_DBA1);
  161. IFX_REG_W32(0x0321, SFSM_CBA0);
  162. IFX_REG_W32(0x0921, SFSM_CBA1);
  163. IFX_REG_W32(0x14011, SFSM_CFG0);
  164. IFX_REG_W32(0x14011, SFSM_CFG1);
  165. IFX_REG_W32(0x0332, FFSM_DBA0);
  166. IFX_REG_W32(0x0932, FFSM_DBA1);
  167. IFX_REG_W32(0x3000C, FFSM_CFG0);
  168. IFX_REG_W32(0x3000C, FFSM_CFG1);
  169. IFX_REG_W32(0xF0D10000, FFSM_IDLE_HEAD_BC0);
  170. IFX_REG_W32(0xF0D10000, FFSM_IDLE_HEAD_BC1);
  171. }
  172. static inline void clear_share_buffer(void)
  173. {
  174. volatile u32 *p = SB_RAM0_ADDR(0);
  175. unsigned int i;
  176. for ( i = 0; i < SB_RAM0_DWLEN + SB_RAM1_DWLEN; i++ )
  177. IFX_REG_W32(0, p++);
  178. }
  179. /*
  180. * Description:
  181. * Download PPE firmware binary code.
  182. * Input:
  183. * src --- u32 *, binary code buffer
  184. * dword_len --- unsigned int, binary code length in DWORD (32-bit)
  185. * Output:
  186. * int --- 0: Success
  187. * else: Error Code
  188. */
  189. static inline int pp32_download_code(u32 *code_src, unsigned int code_dword_len, u32 *data_src, unsigned int data_dword_len)
  190. {
  191. volatile u32 *dest;
  192. if ( code_src == 0 || ((unsigned long)code_src & 0x03) != 0
  193. || data_src == 0 || ((unsigned long)data_src & 0x03) != 0 )
  194. return -1;
  195. if ( code_dword_len <= CDM_CODE_MEMORYn_DWLEN(0) )
  196. IFX_REG_W32(0x00, CDM_CFG);
  197. else
  198. IFX_REG_W32(0x04, CDM_CFG);
  199. /* copy code */
  200. dest = CDM_CODE_MEMORY(0, 0);
  201. while ( code_dword_len-- > 0 )
  202. IFX_REG_W32(*code_src++, dest++);
  203. /* copy data */
  204. dest = CDM_DATA_MEMORY(0, 0);
  205. while ( data_dword_len-- > 0 )
  206. IFX_REG_W32(*data_src++, dest++);
  207. return 0;
  208. }
  209. /*
  210. * ####################################
  211. * Global Function
  212. * ####################################
  213. */
  214. extern void ifx_ptm_get_fw_ver(unsigned int *major, unsigned int *minor)
  215. {
  216. ASSERT(major != NULL, "pointer is NULL");
  217. ASSERT(minor != NULL, "pointer is NULL");
  218. *major = FW_VER_ID->major;
  219. *minor = FW_VER_ID->minor;
  220. }
  221. void ifx_ptm_init_chip(struct platform_device *pdev)
  222. {
  223. init_pmu();
  224. reset_ppe(pdev);
  225. init_ema();
  226. init_mailbox();
  227. init_atm_tc();
  228. clear_share_buffer();
  229. }
  230. void ifx_ptm_uninit_chip(void)
  231. {
  232. uninit_pmu();
  233. }
  234. /*
  235. * Description:
  236. * Initialize and start up PP32.
  237. * Input:
  238. * none
  239. * Output:
  240. * int --- 0: Success
  241. * else: Error Code
  242. */
  243. int ifx_pp32_start(int pp32)
  244. {
  245. int ret;
  246. /* download firmware */
  247. 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));
  248. if ( ret != 0 )
  249. return ret;
  250. /* run PP32 */
  251. IFX_REG_W32(DBG_CTRL_RESTART, PP32_DBG_CTRL(pp32));
  252. /* idle for a while to let PP32 init itself */
  253. udelay(10);
  254. return 0;
  255. }
  256. /*
  257. * Description:
  258. * Halt PP32.
  259. * Input:
  260. * none
  261. * Output:
  262. * none
  263. */
  264. void ifx_pp32_stop(int pp32)
  265. {
  266. /* halt PP32 */
  267. IFX_REG_W32(DBG_CTRL_STOP, PP32_DBG_CTRL(pp32));
  268. }