ifxusb_cif_d.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /*****************************************************************************
  2. ** FILE NAME : ifxusb_cif_d.c
  3. ** PROJECT : IFX USB sub-system V3
  4. ** MODULES : IFX USB sub-system Host and Device driver
  5. ** SRC VERSION : 3.2
  6. ** DATE : 1/Jan/2011
  7. ** AUTHOR : Chen, Howard
  8. ** DESCRIPTION : The Core Interface provides basic services for accessing and
  9. ** managing the IFX USB hardware. These services are used by the
  10. ** Peripheral Controller Driver only.
  11. ** FUNCTIONS :
  12. ** COMPILER : gcc
  13. ** REFERENCE : Synopsys DWC-OTG Driver 2.7
  14. ** COPYRIGHT : Copyright (c) 2010
  15. ** LANTIQ DEUTSCHLAND GMBH,
  16. ** Am Campeon 3, 85579 Neubiberg, Germany
  17. **
  18. ** This program is free software; you can redistribute it and/or modify
  19. ** it under the terms of the GNU General Public License as published by
  20. ** the Free Software Foundation; either version 2 of the License, or
  21. ** (at your option) any later version.
  22. **
  23. ** Version Control Section **
  24. ** $Author$
  25. ** $Date$
  26. ** $Revisions$
  27. ** $Log$ Revision history
  28. *****************************************************************************/
  29. /*
  30. * This file contains code fragments from Synopsys HS OTG Linux Software Driver.
  31. * For this code the following notice is applicable:
  32. *
  33. * ==========================================================================
  34. *
  35. * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  36. * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  37. * otherwise expressly agreed to in writing between Synopsys and you.
  38. *
  39. * The Software IS NOT an item of Licensed Software or Licensed Product under
  40. * any End User Software License Agreement or Agreement for Licensed Product
  41. * with Synopsys or any supplement thereto. You are permitted to use and
  42. * redistribute this Software in source and binary forms, with or without
  43. * modification, provided that redistributions of source code must retain this
  44. * notice. You may not view, use, disclose, copy or distribute this file or
  45. * any information contained herein except pursuant to this license grant from
  46. * Synopsys. If you do not agree with this notice, including the disclaimer
  47. * below, then you are not authorized to use the Software.
  48. *
  49. * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  50. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52. * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  53. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  54. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  55. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  56. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  57. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  58. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  59. * DAMAGE.
  60. * ========================================================================== */
  61. /*!
  62. \file ifxusb_cif_d.c
  63. \ingroup IFXUSB_DRIVER_V3
  64. \brief This file contains the interface to the IFX USB Core.
  65. */
  66. #include <linux/version.h>
  67. #include "ifxusb_version.h"
  68. #include <asm/byteorder.h>
  69. #include <asm/unaligned.h>
  70. #ifdef __DEBUG__
  71. #include <linux/jiffies.h>
  72. #endif
  73. #include "ifxusb_plat.h"
  74. #include "ifxusb_regs.h"
  75. #include "ifxusb_cif.h"
  76. #include "ifxpcd.h"
  77. /*!
  78. \brief Initializes the DevSpd field of the DCFG register depending on the PHY type
  79. and the enumeration speed of the device.
  80. \param _core_if Pointer of core_if structure
  81. */
  82. void ifxusb_dev_init_spd(ifxusb_core_if_t *_core_if)
  83. {
  84. uint32_t val;
  85. dcfg_data_t dcfg;
  86. IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
  87. if (_core_if->params.speed == IFXUSB_PARAM_SPEED_FULL)
  88. /* High speed PHY running at full speed */
  89. val = 0x1;
  90. else
  91. /* High speed PHY running at high speed and full speed*/
  92. val = 0x0;
  93. IFX_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  94. dcfg.d32 = ifxusb_rreg(&_core_if->dev_global_regs->dcfg);
  95. dcfg.b.devspd = val;
  96. ifxusb_wreg(&_core_if->dev_global_regs->dcfg, dcfg.d32);
  97. }
  98. /*!
  99. \brief This function enables the Device mode interrupts.
  100. \param _core_if Pointer of core_if structure
  101. */
  102. void ifxusb_dev_enable_interrupts(ifxusb_core_if_t *_core_if)
  103. {
  104. gint_data_t intr_mask ={ .d32 = 0};
  105. ifxusb_core_global_regs_t *global_regs = _core_if->core_global_regs;
  106. IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
  107. IFX_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  108. /* Clear any pending OTG Interrupts */
  109. ifxusb_wreg( &global_regs->gotgint, 0xFFFFFFFF);
  110. /* Clear any pending interrupts */
  111. ifxusb_wreg( &global_regs->gintsts, 0xFFFFFFFF);
  112. /* Enable the interrupts in the GINTMSK.*/
  113. intr_mask.b.modemismatch = 1;
  114. intr_mask.b.conidstschng = 1;
  115. intr_mask.b.wkupintr = 1;
  116. intr_mask.b.disconnect = 1;
  117. intr_mask.b.usbsuspend = 1;
  118. intr_mask.b.usbreset = 1;
  119. intr_mask.b.enumdone = 1;
  120. intr_mask.b.inepintr = 1;
  121. intr_mask.b.outepintr = 1;
  122. intr_mask.b.erlysuspend = 1;
  123. #ifndef __DED_FIFO__
  124. #ifndef __DED_INTR__
  125. intr_mask.b.epmismatch = 1;
  126. #endif
  127. #endif
  128. ifxusb_mreg( &global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  129. IFX_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__, ifxusb_rreg( &global_regs->gintmsk));
  130. }
  131. /*!
  132. \brief Gets the current USB frame number. This is the frame number from the last SOF packet.
  133. \param _core_if Pointer of core_if structure
  134. */
  135. uint32_t ifxusb_dev_get_frame_number(ifxusb_core_if_t *_core_if)
  136. {
  137. dsts_data_t dsts;
  138. IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
  139. dsts.d32 = ifxusb_rreg(&_core_if->dev_global_regs->dsts);
  140. /* read current frame/microfreme number from DSTS register */
  141. return dsts.b.soffn;
  142. }
  143. /*!
  144. \brief Set the EP STALL.
  145. */
  146. void ifxusb_dev_ep_set_stall(ifxusb_core_if_t *_core_if, uint8_t _epno, uint8_t _is_in)
  147. {
  148. depctl_data_t depctl;
  149. volatile uint32_t *depctl_addr;
  150. IFX_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, _epno, (_is_in?"IN":"OUT"));
  151. depctl_addr = (_is_in)? (&(_core_if->in_ep_regs [_epno]->diepctl)):
  152. (&(_core_if->out_ep_regs[_epno]->doepctl));
  153. depctl.d32 = ifxusb_rreg(depctl_addr);
  154. depctl.b.stall = 1;
  155. if (_is_in && depctl.b.epena)
  156. depctl.b.epdis = 1;
  157. ifxusb_wreg(depctl_addr, depctl.d32);
  158. IFX_DEBUGPL(DBG_PCD,"DEPCTL=%0x\n",ifxusb_rreg(depctl_addr));
  159. return;
  160. }
  161. /*!
  162. \brief Clear the EP STALL.
  163. */
  164. void ifxusb_dev_ep_clear_stall(ifxusb_core_if_t *_core_if, uint8_t _epno, uint8_t _ep_type, uint8_t _is_in)
  165. {
  166. depctl_data_t depctl;
  167. volatile uint32_t *depctl_addr;
  168. IFX_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, _epno, (_is_in?"IN":"OUT"));
  169. depctl_addr = (_is_in)? (&(_core_if->in_ep_regs [_epno]->diepctl)):
  170. (&(_core_if->out_ep_regs[_epno]->doepctl));
  171. depctl.d32 = ifxusb_rreg(depctl_addr);
  172. /* clear the stall bits */
  173. depctl.b.stall = 0;
  174. /*
  175. * USB Spec 9.4.5: For endpoints using data toggle, regardless
  176. * of whether an endpoint has the Halt feature set, a
  177. * ClearFeature(ENDPOINT_HALT) request always results in the
  178. * data toggle being reinitialized to DATA0.
  179. */
  180. if (_ep_type == IFXUSB_EP_TYPE_INTR || _ep_type == IFXUSB_EP_TYPE_BULK)
  181. depctl.b.setd0pid = 1; /* DATA0 */
  182. ifxusb_wreg(depctl_addr, depctl.d32);
  183. IFX_DEBUGPL(DBG_PCD,"DEPCTL=%0x\n",ifxusb_rreg(depctl_addr));
  184. return;
  185. }
  186. /*!
  187. \brief This function initializes the IFXUSB controller registers for Device mode.
  188. This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  189. request queues.
  190. \param _core_if Pointer of core_if structure
  191. \param _params parameters to be set
  192. */
  193. void ifxusb_dev_core_init(ifxusb_core_if_t *_core_if, ifxusb_params_t *_params)
  194. {
  195. ifxusb_core_global_regs_t *global_regs = _core_if->core_global_regs;
  196. gusbcfg_data_t usbcfg ={.d32 = 0};
  197. gahbcfg_data_t ahbcfg ={.d32 = 0};
  198. dcfg_data_t dcfg ={.d32 = 0};
  199. grstctl_t resetctl ={.d32 = 0};
  200. gotgctl_data_t gotgctl ={.d32 = 0};
  201. uint32_t dir;
  202. int i;
  203. IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
  204. IFX_DEBUGPL(DBG_CILV, "%s(%p)\n",__func__,_core_if);
  205. /* Copy Params */
  206. _core_if->params.dma_burst_size = _params->dma_burst_size;
  207. _core_if->params.speed = _params->speed;
  208. if(_params->max_transfer_size < 2048 || _params->max_transfer_size > ((1 << (_core_if->hwcfg3.b.xfer_size_cntr_width + 11)) - 1) )
  209. _core_if->params.max_transfer_size = ((1 << (_core_if->hwcfg3.b.xfer_size_cntr_width + 11)) - 1);
  210. else
  211. _core_if->params.max_transfer_size = _params->max_transfer_size;
  212. if(_params->max_packet_count < 16 || _params->max_packet_count > ((1 << (_core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1) )
  213. _core_if->params.max_packet_count= ((1 << (_core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  214. else
  215. _core_if->params.max_packet_count= _params->max_packet_count;
  216. _core_if->params.phy_utmi_width = _params->phy_utmi_width;
  217. _core_if->params.turn_around_time_hs = _params->turn_around_time_hs;
  218. _core_if->params.turn_around_time_fs = _params->turn_around_time_fs;
  219. _core_if->params.timeout_cal_hs = _params->timeout_cal_hs;
  220. _core_if->params.timeout_cal_fs = _params->timeout_cal_fs;
  221. #ifdef __DED_FIFO__
  222. _core_if->params.thr_ctl = _params->thr_ctl;
  223. _core_if->params.tx_thr_length = _params->tx_thr_length;
  224. _core_if->params.rx_thr_length = _params->rx_thr_length;
  225. #endif
  226. /* Reset the Controller */
  227. do
  228. {
  229. while(ifxusb_core_soft_reset_d( _core_if ))
  230. ifxusb_hard_reset_d(_core_if);
  231. } while (ifxusb_is_host_mode(_core_if));
  232. usbcfg.d32 = ifxusb_rreg(&global_regs->gusbcfg);
  233. usbcfg.b.ForceDevMode = 1;
  234. usbcfg.b.ForceHstMode = 0;
  235. usbcfg.b.term_sel_dl_pulse = 0;
  236. ifxusb_wreg (&global_regs->gusbcfg, usbcfg.d32);
  237. /* This programming sequence needs to happen in FS mode before any other
  238. * programming occurs */
  239. /* High speed PHY. */
  240. if (!_core_if->phy_init_done)
  241. {
  242. _core_if->phy_init_done = 1;
  243. /* HS PHY parameters. These parameters are preserved
  244. * during soft reset so only program the first time. Do
  245. * a soft reset immediately after setting phyif. */
  246. usbcfg.b.ulpi_utmi_sel = 0; //UTMI+
  247. usbcfg.b.phyif = ( _core_if->params.phy_utmi_width == 16)?1:0;
  248. ifxusb_wreg( &global_regs->gusbcfg, usbcfg.d32);
  249. /* Reset after setting the PHY parameters */
  250. ifxusb_core_soft_reset_d( _core_if );
  251. }
  252. /* Program the GAHBCFG Register.*/
  253. switch (_core_if->params.dma_burst_size)
  254. {
  255. case 0 :
  256. ahbcfg.b.hburstlen = IFXUSB_GAHBCFG_INT_DMA_BURST_SINGLE;
  257. break;
  258. case 1 :
  259. ahbcfg.b.hburstlen = IFXUSB_GAHBCFG_INT_DMA_BURST_INCR;
  260. break;
  261. case 4 :
  262. ahbcfg.b.hburstlen = IFXUSB_GAHBCFG_INT_DMA_BURST_INCR4;
  263. break;
  264. case 8 :
  265. ahbcfg.b.hburstlen = IFXUSB_GAHBCFG_INT_DMA_BURST_INCR8;
  266. break;
  267. case 16:
  268. ahbcfg.b.hburstlen = IFXUSB_GAHBCFG_INT_DMA_BURST_INCR16;
  269. break;
  270. }
  271. #if defined(__UNALIGNED_BUF_ADJ__) || defined(__UNALIGNED_BUF_CHK__)
  272. _core_if->unaligned_mask=3;
  273. #if defined(__UNALIGNED_BUF_BURST__)
  274. switch (_core_if->params.dma_burst_size)
  275. {
  276. case 4 :
  277. _core_if->unaligned_mask=15;
  278. break;
  279. case 8 :
  280. _core_if->unaligned_mask=31;
  281. break;
  282. case 16:
  283. _core_if->unaligned_mask=63;
  284. break;
  285. case 0 :
  286. case 1 :
  287. break;
  288. }
  289. #endif //defined(__UNALIGNED_BUF_BURST__)
  290. #endif //defined(__UNALIGNED_BUF_ADJ__) || defined(__UNALIGNED_BUF_CHK__)
  291. ahbcfg.b.dmaenable = 1;
  292. ifxusb_wreg(&global_regs->gahbcfg, ahbcfg.d32);
  293. /* Program the GUSBCFG register. */
  294. usbcfg.d32 = ifxusb_rreg( &global_regs->gusbcfg );
  295. usbcfg.b.hnpcap = 0;
  296. usbcfg.b.srpcap = 0;
  297. ifxusb_wreg( &global_regs->gusbcfg, usbcfg.d32);
  298. {
  299. dctl_data_t dctl = {.d32=0};
  300. dctl.d32=ifxusb_rreg(&_core_if->dev_global_regs->dctl);
  301. dctl.b.sftdiscon=1;
  302. ifxusb_wreg(&_core_if->dev_global_regs->dctl,dctl.d32);
  303. }
  304. /* Restart the Phy Clock */
  305. ifxusb_wreg(_core_if->pcgcctl, 0);
  306. /* Device configuration register */
  307. ifxusb_dev_init_spd(_core_if);
  308. dcfg.d32 = ifxusb_rreg( &_core_if->dev_global_regs->dcfg);
  309. dcfg.b.perfrint = IFXUSB_DCFG_FRAME_INTERVAL_80;
  310. #if defined(__DED_FIFO__)
  311. #if defined(__DESC_DMA__)
  312. dcfg.b.descdma = 1;
  313. #else
  314. dcfg.b.descdma = 0;
  315. #endif
  316. #endif
  317. ifxusb_wreg( &_core_if->dev_global_regs->dcfg, dcfg.d32 );
  318. /* Configure data FIFO sizes */
  319. _core_if->params.data_fifo_size = _core_if->hwcfg3.b.dfifo_depth;
  320. _core_if->params.rx_fifo_size = ifxusb_rreg(&global_regs->grxfsiz);
  321. IFX_DEBUGPL(DBG_CIL, "Initial: FIFO Size=0x%06X\n" , _core_if->params.data_fifo_size);
  322. IFX_DEBUGPL(DBG_CIL, " Rx FIFO Size=0x%06X\n", _core_if->params.rx_fifo_size);
  323. _core_if->params.tx_fifo_size[0]= ifxusb_rreg(&global_regs->gnptxfsiz) >> 16;
  324. #ifdef __DED_FIFO__
  325. for (i=1; i <= _core_if->hwcfg4.b.num_in_eps; i++)
  326. _core_if->params.tx_fifo_size[i] =
  327. ifxusb_rreg(&global_regs->dptxfsiz_dieptxf[i-1]) >> 16;
  328. #else
  329. for (i=0; i < _core_if->hwcfg4.b.num_dev_perio_in_ep; i++)
  330. _core_if->params.tx_fifo_size[i+1] =
  331. ifxusb_rreg(&global_regs->dptxfsiz_dieptxf[i]) >> 16;
  332. #endif
  333. #ifdef __DEBUG__
  334. #ifdef __DED_FIFO__
  335. for (i=0; i <= _core_if->hwcfg4.b.num_in_eps; i++)
  336. IFX_DEBUGPL(DBG_CIL, " Tx[%02d] FIFO Size=0x%06X\n",i, _core_if->params.tx_fifo_size[i]);
  337. #else
  338. IFX_DEBUGPL(DBG_CIL, " NPTx FIFO Size=0x%06X\n", _core_if->params.tx_fifo_size[0]);
  339. for (i=0; i < _core_if->hwcfg4.b.num_dev_perio_in_ep; i++)
  340. IFX_DEBUGPL(DBG_CIL, " PTx[%02d] FIFO Size=0x%06X\n",i, _core_if->params.tx_fifo_size[i+1]);
  341. #endif
  342. #endif
  343. {
  344. fifosize_data_t txfifosize;
  345. if(_params->data_fifo_size >=0 && _params->data_fifo_size < _core_if->params.data_fifo_size)
  346. _core_if->params.data_fifo_size = _params->data_fifo_size;
  347. if(_params->rx_fifo_size >=0 && _params->rx_fifo_size < _core_if->params.rx_fifo_size)
  348. _core_if->params.rx_fifo_size = _params->rx_fifo_size;
  349. if(_core_if->params.data_fifo_size < _core_if->params.rx_fifo_size)
  350. _core_if->params.rx_fifo_size = _core_if->params.data_fifo_size;
  351. ifxusb_wreg( &global_regs->grxfsiz, _core_if->params.rx_fifo_size);
  352. for (i=0; i < MAX_EPS_CHANNELS; i++)
  353. if(_params->tx_fifo_size[i] >=0 && _params->tx_fifo_size[i] < _core_if->params.tx_fifo_size[i])
  354. _core_if->params.tx_fifo_size[i] = _params->tx_fifo_size[i];
  355. txfifosize.b.startaddr = _core_if->params.rx_fifo_size;
  356. #ifdef __DED_FIFO__
  357. if(txfifosize.b.startaddr + _core_if->params.tx_fifo_size[0] > _core_if->params.data_fifo_size)
  358. _core_if->params.tx_fifo_size[0]= _core_if->params.data_fifo_size - txfifosize.b.startaddr;
  359. txfifosize.b.depth=_core_if->params.tx_fifo_size[0];
  360. ifxusb_wreg( &global_regs->gnptxfsiz, txfifosize.d32);
  361. txfifosize.b.startaddr += _core_if->params.tx_fifo_size[0];
  362. for (i=1; i <= _core_if->hwcfg4.b.num_in_eps; i++)
  363. {
  364. if(txfifosize.b.startaddr + _core_if->params.tx_fifo_size[i] > _core_if->params.data_fifo_size)
  365. _core_if->params.tx_fifo_size[i]= _core_if->params.data_fifo_size - txfifosize.b.startaddr;
  366. txfifosize.b.depth=_core_if->params.tx_fifo_size[i];
  367. ifxusb_wreg( &global_regs->dptxfsiz_dieptxf[i-1], txfifosize.d32);
  368. txfifosize.b.startaddr += _core_if->params.tx_fifo_size[i];
  369. }
  370. #else
  371. if(txfifosize.b.startaddr + _core_if->params.tx_fifo_size[0] > _core_if->params.data_fifo_size)
  372. _core_if->params.tx_fifo_size[0]= _core_if->params.data_fifo_size - txfifosize.b.startaddr;
  373. txfifosize.b.depth=_core_if->params.tx_fifo_size[0];
  374. ifxusb_wreg( &global_regs->gnptxfsiz, txfifosize.d32);
  375. txfifosize.b.startaddr += _core_if->params.tx_fifo_size[0];
  376. for (i=0; i < _core_if->hwcfg4.b.num_dev_perio_in_ep; i++)
  377. {
  378. if(txfifosize.b.startaddr + _core_if->params.tx_fifo_size[i+1] > _core_if->params.data_fifo_size)
  379. _core_if->params.tx_fifo_size[i+1]= _core_if->params.data_fifo_size - txfifosize.b.startaddr;
  380. //txfifosize.b.depth=_core_if->params.tx_fifo_size[i+1];
  381. ifxusb_wreg( &global_regs->dptxfsiz_dieptxf[i], txfifosize.d32);
  382. txfifosize.b.startaddr += _core_if->params.tx_fifo_size[i+1];
  383. }
  384. #endif
  385. }
  386. #ifdef __DEBUG__
  387. {
  388. fifosize_data_t fifosize;
  389. IFX_DEBUGPL(DBG_CIL, "Result : FIFO Size=0x%06X\n" , _core_if->params.data_fifo_size);
  390. IFX_DEBUGPL(DBG_CIL, " Rx FIFO =0x%06X Sz=0x%06X\n", 0,ifxusb_rreg(&global_regs->grxfsiz));
  391. #ifdef __DED_FIFO__
  392. fifosize.d32=ifxusb_rreg(&global_regs->gnptxfsiz);
  393. IFX_DEBUGPL(DBG_CIL, " Tx[00] FIFO =0x%06X Sz=0x%06X\n", fifosize.b.startaddr,fifosize.b.depth);
  394. for (i=1; i <= _core_if->hwcfg4.b.num_in_eps; i++)
  395. {
  396. fifosize.d32=ifxusb_rreg(&global_regs->dptxfsiz_dieptxf[i-1]);
  397. IFX_DEBUGPL(DBG_CIL, " Tx[%02d] FIFO 0x%06X Sz=0x%06X\n",i, fifosize.b.startaddr,fifosize.b.depth);
  398. }
  399. #else
  400. fifosize.d32=ifxusb_rreg(&global_regs->gnptxfsiz);
  401. IFX_DEBUGPL(DBG_CIL, " NPTx FIFO =0x%06X Sz=0x%06X\n", fifosize.b.startaddr,fifosize.b.depth);
  402. for (i=0; i < _core_if->hwcfg4.b.num_dev_perio_in_ep; i++)
  403. {
  404. fifosize.d32=ifxusb_rreg(&global_regs->dptxfsiz_dieptxf[i]);
  405. IFX_DEBUGPL(DBG_CIL, " PTx[%02d] FIFO 0x%06X Sz=0x%06X\n",i, fifosize.b.startaddr,fifosize.b.depth);
  406. }
  407. #endif
  408. }
  409. #endif
  410. /* Clear Host Set HNP Enable in the OTG Control Register */
  411. gotgctl.b.hstsethnpen = 1;
  412. ifxusb_mreg( &global_regs->gotgctl, gotgctl.d32, 0);
  413. /* Flush the FIFOs */
  414. ifxusb_flush_tx_fifo_d(_core_if, 0x10); /* all Tx FIFOs */
  415. ifxusb_flush_rx_fifo_d(_core_if);
  416. /* Flush the Learning Queue. */
  417. resetctl.b.intknqflsh = 1;
  418. ifxusb_wreg( &global_regs->grstctl, resetctl.d32);
  419. /* Clear all pending Device Interrupts */
  420. ifxusb_wreg( &_core_if->dev_global_regs->diepmsk , 0 );
  421. ifxusb_wreg( &_core_if->dev_global_regs->doepmsk , 0 );
  422. ifxusb_wreg( &_core_if->dev_global_regs->daint , 0xFFFFFFFF );
  423. ifxusb_wreg( &_core_if->dev_global_regs->daintmsk, 0 );
  424. dir=_core_if->hwcfg1.d32;
  425. for (i=0; i <= _core_if->hwcfg2.b.num_dev_ep ; i++,dir>>=2)
  426. {
  427. depctl_data_t depctl;
  428. if((dir&0x03)==0 || (dir&0x03) ==1)
  429. {
  430. depctl.d32 = ifxusb_rreg(&_core_if->in_ep_regs[i]->diepctl);
  431. if (depctl.b.epena)
  432. {
  433. depctl.d32 = 0;
  434. depctl.b.epdis = 1;
  435. depctl.b.snak = 1;
  436. }
  437. else
  438. depctl.d32 = 0;
  439. ifxusb_wreg( &_core_if->in_ep_regs[i]->diepctl, depctl.d32);
  440. #ifndef __DESC_DMA__
  441. ifxusb_wreg( &_core_if->in_ep_regs[i]->dieptsiz, 0);
  442. #endif
  443. ifxusb_wreg( &_core_if->in_ep_regs[i]->diepdma, 0);
  444. ifxusb_wreg( &_core_if->in_ep_regs[i]->diepint, 0xFF);
  445. }
  446. if((dir&0x03)==0 || (dir&0x03) ==2)
  447. {
  448. depctl.d32 = ifxusb_rreg(&_core_if->out_ep_regs[i]->doepctl);
  449. if (depctl.b.epena)
  450. {
  451. depctl.d32 = 0;
  452. depctl.b.epdis = 1;
  453. depctl.b.snak = 1;
  454. }
  455. else
  456. depctl.d32 = 0;
  457. ifxusb_wreg( &_core_if->out_ep_regs[i]->doepctl, depctl.d32);
  458. #ifndef __DESC_DMA__
  459. ifxusb_wreg( &_core_if->out_ep_regs[i]->doeptsiz, 0);
  460. #endif
  461. ifxusb_wreg( &_core_if->out_ep_regs[i]->doepdma, 0);
  462. ifxusb_wreg( &_core_if->out_ep_regs[i]->doepint, 0xFF);
  463. }
  464. }
  465. }