dwc_otg_cil.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478
  1. /* ==========================================================================
  2. * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  3. * $Revision: #122 $
  4. * $Date: 2011/10/24 $
  5. * $Change: 1871160 $
  6. *
  7. * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  8. * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  9. * otherwise expressly agreed to in writing between Synopsys and you.
  10. *
  11. * The Software IS NOT an item of Licensed Software or Licensed Product under
  12. * any End User Software License Agreement or Agreement for Licensed Product
  13. * with Synopsys or any supplement thereto. You are permitted to use and
  14. * redistribute this Software in source and binary forms, with or without
  15. * modification, provided that redistributions of source code must retain this
  16. * notice. You may not view, use, disclose, copy or distribute this file or
  17. * any information contained herein except pursuant to this license grant from
  18. * Synopsys. If you do not agree with this notice, including the disclaimer
  19. * below, then you are not authorized to use the Software.
  20. *
  21. * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  25. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  26. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  31. * DAMAGE.
  32. * ========================================================================== */
  33. #if !defined(__DWC_CIL_H__)
  34. #define __DWC_CIL_H__
  35. #include "dwc_list.h"
  36. #include "dwc_otg_dbg.h"
  37. #include "dwc_otg_regs.h"
  38. #include "dwc_otg_core_if.h"
  39. #include "dwc_otg_adp.h"
  40. #include <linux/device.h>
  41. #include <linux/ioport.h>
  42. #include <plat/lm.h>
  43. #include <mach/usbclock.h>
  44. /**
  45. * @file
  46. * This file contains the interface to the Core Interface Layer.
  47. */
  48. #ifdef DWC_UTE_CFI
  49. #define MAX_DMA_DESCS_PER_EP 256
  50. /**
  51. * Enumeration for the data buffer mode
  52. */
  53. typedef enum _data_buffer_mode {
  54. BM_STANDARD = 0, /* data buffer is in normal mode */
  55. BM_SG = 1, /* data buffer uses the scatter/gather mode */
  56. BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  57. BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  58. BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  59. } data_buffer_mode_e;
  60. #endif //DWC_UTE_CFI
  61. /** Macros defined for DWC OTG HW Release version */
  62. #define OTG_CORE_REV_2_60a 0x4F54260A
  63. #define OTG_CORE_REV_2_71a 0x4F54271A
  64. #define OTG_CORE_REV_2_72a 0x4F54272A
  65. #define OTG_CORE_REV_2_80a 0x4F54280A
  66. #define OTG_CORE_REV_2_81a 0x4F54281A
  67. #define OTG_CORE_REV_2_90a 0x4F54290A
  68. #define OTG_CORE_REV_2_91a 0x4F54291A
  69. #define OTG_CORE_REV_2_92a 0x4F54292A
  70. #define OTG_CORE_REV_2_93a 0x4F54293A
  71. #define OTG_CORE_REV_2_94a 0x4F54294A
  72. /**
  73. * Information for each ISOC packet.
  74. */
  75. typedef struct iso_pkt_info {
  76. uint32_t offset;
  77. uint32_t length;
  78. int32_t status;
  79. } iso_pkt_info_t;
  80. /**
  81. * The <code>dwc_ep</code> structure represents the state of a single
  82. * endpoint when acting in device mode. It contains the data items
  83. * needed for an endpoint to be activated and transfer packets.
  84. */
  85. typedef struct dwc_ep {
  86. /** EP number used for register address lookup */
  87. uint8_t num;
  88. /** EP direction 0 = OUT */
  89. unsigned is_in:1;
  90. /** EP active. */
  91. unsigned active:1;
  92. /**
  93. * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  94. * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  95. unsigned tx_fifo_num:4;
  96. /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  97. unsigned type:2;
  98. #define DWC_OTG_EP_TYPE_CONTROL 0
  99. #define DWC_OTG_EP_TYPE_ISOC 1
  100. #define DWC_OTG_EP_TYPE_BULK 2
  101. #define DWC_OTG_EP_TYPE_INTR 3
  102. /** DATA start PID for INTR and BULK EP */
  103. unsigned data_pid_start:1;
  104. /** Frame (even/odd) for ISOC EP */
  105. unsigned even_odd_frame:1;
  106. /** Max Packet bytes */
  107. unsigned maxpacket:11;
  108. /** Max Transfer size */
  109. uint32_t maxxfer;
  110. /** @name Transfer state */
  111. /** @{ */
  112. /**
  113. * Pointer to the beginning of the transfer buffer -- do not modify
  114. * during transfer.
  115. */
  116. dwc_dma_t dma_addr;
  117. dwc_dma_t dma_desc_addr;
  118. dwc_otg_dev_dma_desc_t *desc_addr;
  119. uint8_t *start_xfer_buff;
  120. /** pointer to the transfer buffer */
  121. uint8_t *xfer_buff;
  122. /** Number of bytes to transfer */
  123. unsigned xfer_len:19;
  124. /** Number of bytes transferred. */
  125. unsigned xfer_count:19;
  126. /** Sent ZLP */
  127. unsigned sent_zlp:1;
  128. /** Total len for control transfer */
  129. unsigned total_len:19;
  130. /** stall clear flag */
  131. unsigned stall_clear_flag:1;
  132. #ifdef DWC_UTE_CFI
  133. /* The buffer mode */
  134. data_buffer_mode_e buff_mode;
  135. /* The chain of DMA descriptors.
  136. * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  137. */
  138. dwc_otg_dma_desc_t *descs;
  139. /* The DMA address of the descriptors chain start */
  140. dma_addr_t descs_dma_addr;
  141. /** This variable stores the length of the last enqueued request */
  142. uint32_t cfi_req_len;
  143. #endif //DWC_UTE_CFI
  144. /** Max DMA Descriptor count for any EP */
  145. #define MAX_DMA_DESC_CNT 256
  146. /** Allocated DMA Desc count */
  147. uint32_t desc_cnt;
  148. /** bInterval */
  149. uint32_t bInterval;
  150. /** Next frame num to setup next ISOC transfer */
  151. uint32_t frame_num;
  152. /** Indicates SOF number overrun in DSTS */
  153. uint8_t frm_overrun;
  154. #ifdef DWC_UTE_PER_IO
  155. /** Next frame num for which will be setup DMA Desc */
  156. uint32_t xiso_frame_num;
  157. /** bInterval */
  158. uint32_t xiso_bInterval;
  159. /** Count of currently active transfers - shall be either 0 or 1 */
  160. int xiso_active_xfers;
  161. int xiso_queued_xfers;
  162. #endif
  163. #ifdef DWC_EN_ISOC
  164. /**
  165. * Variables specific for ISOC EPs
  166. *
  167. */
  168. /** DMA addresses of ISOC buffers */
  169. dwc_dma_t dma_addr0;
  170. dwc_dma_t dma_addr1;
  171. dwc_dma_t iso_dma_desc_addr;
  172. dwc_otg_dev_dma_desc_t *iso_desc_addr;
  173. /** pointer to the transfer buffers */
  174. uint8_t *xfer_buff0;
  175. uint8_t *xfer_buff1;
  176. /** number of ISOC Buffer is processing */
  177. uint32_t proc_buf_num;
  178. /** Interval of ISOC Buffer processing */
  179. uint32_t buf_proc_intrvl;
  180. /** Data size for regular frame */
  181. uint32_t data_per_frame;
  182. /* todo - pattern data support is to be implemented in the future */
  183. /** Data size for pattern frame */
  184. uint32_t data_pattern_frame;
  185. /** Frame number of pattern data */
  186. uint32_t sync_frame;
  187. /** bInterval */
  188. uint32_t bInterval;
  189. /** ISO Packet number per frame */
  190. uint32_t pkt_per_frm;
  191. /** Next frame num for which will be setup DMA Desc */
  192. uint32_t next_frame;
  193. /** Number of packets per buffer processing */
  194. uint32_t pkt_cnt;
  195. /** Info for all isoc packets */
  196. iso_pkt_info_t *pkt_info;
  197. /** current pkt number */
  198. uint32_t cur_pkt;
  199. /** current pkt number */
  200. uint8_t *cur_pkt_addr;
  201. /** current pkt number */
  202. uint32_t cur_pkt_dma_addr;
  203. #endif /* DWC_EN_ISOC */
  204. /** @} */
  205. } dwc_ep_t;
  206. /*
  207. * Reasons for halting a host channel.
  208. */
  209. typedef enum dwc_otg_halt_status {
  210. DWC_OTG_HC_XFER_NO_HALT_STATUS,
  211. DWC_OTG_HC_XFER_COMPLETE,
  212. DWC_OTG_HC_XFER_URB_COMPLETE,
  213. DWC_OTG_HC_XFER_ACK,
  214. DWC_OTG_HC_XFER_NAK,
  215. DWC_OTG_HC_XFER_NYET,
  216. DWC_OTG_HC_XFER_STALL,
  217. DWC_OTG_HC_XFER_XACT_ERR,
  218. DWC_OTG_HC_XFER_FRAME_OVERRUN,
  219. DWC_OTG_HC_XFER_BABBLE_ERR,
  220. DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  221. DWC_OTG_HC_XFER_AHB_ERR,
  222. DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  223. DWC_OTG_HC_XFER_URB_DEQUEUE
  224. } dwc_otg_halt_status_e;
  225. /**
  226. * Host channel descriptor. This structure represents the state of a single
  227. * host channel when acting in host mode. It contains the data items needed to
  228. * transfer packets to an endpoint via a host channel.
  229. */
  230. typedef struct dwc_hc {
  231. /** Host channel number used for register address lookup */
  232. uint8_t hc_num;
  233. /** Device to access */
  234. unsigned dev_addr:7;
  235. /** EP to access */
  236. unsigned ep_num:4;
  237. /** EP direction. 0: OUT, 1: IN */
  238. unsigned ep_is_in:1;
  239. /**
  240. * EP speed.
  241. * One of the following values:
  242. * - DWC_OTG_EP_SPEED_LOW
  243. * - DWC_OTG_EP_SPEED_FULL
  244. * - DWC_OTG_EP_SPEED_HIGH
  245. */
  246. unsigned speed:2;
  247. #define DWC_OTG_EP_SPEED_LOW 0
  248. #define DWC_OTG_EP_SPEED_FULL 1
  249. #define DWC_OTG_EP_SPEED_HIGH 2
  250. /**
  251. * Endpoint type.
  252. * One of the following values:
  253. * - DWC_OTG_EP_TYPE_CONTROL: 0
  254. * - DWC_OTG_EP_TYPE_ISOC: 1
  255. * - DWC_OTG_EP_TYPE_BULK: 2
  256. * - DWC_OTG_EP_TYPE_INTR: 3
  257. */
  258. unsigned ep_type:2;
  259. /** Max packet size in bytes */
  260. unsigned max_packet:11;
  261. /**
  262. * PID for initial transaction.
  263. * 0: DATA0,<br>
  264. * 1: DATA2,<br>
  265. * 2: DATA1,<br>
  266. * 3: MDATA (non-Control EP),
  267. * SETUP (Control EP)
  268. */
  269. unsigned data_pid_start:2;
  270. #define DWC_OTG_HC_PID_DATA0 0
  271. #define DWC_OTG_HC_PID_DATA2 1
  272. #define DWC_OTG_HC_PID_DATA1 2
  273. #define DWC_OTG_HC_PID_MDATA 3
  274. #define DWC_OTG_HC_PID_SETUP 3
  275. /** Number of periodic transactions per (micro)frame */
  276. unsigned multi_count:2;
  277. /** @name Transfer State */
  278. /** @{ */
  279. /** Pointer to the current transfer buffer position. */
  280. uint8_t *xfer_buff;
  281. /**
  282. * In Buffer DMA mode this buffer will be used
  283. * if xfer_buff is not DWORD aligned.
  284. */
  285. dwc_dma_t align_buff;
  286. /** Total number of bytes to transfer. */
  287. uint32_t xfer_len;
  288. /** Number of bytes transferred so far. */
  289. uint32_t xfer_count;
  290. /** Packet count at start of transfer.*/
  291. uint16_t start_pkt_count;
  292. /**
  293. * Flag to indicate whether the transfer has been started. Set to 1 if
  294. * it has been started, 0 otherwise.
  295. */
  296. uint8_t xfer_started;
  297. /**
  298. * Set to 1 to indicate that a PING request should be issued on this
  299. * channel. If 0, process normally.
  300. */
  301. uint8_t do_ping;
  302. /**
  303. * Set to 1 to indicate that the error count for this transaction is
  304. * non-zero. Set to 0 if the error count is 0.
  305. */
  306. uint8_t error_state;
  307. /**
  308. * Set to 1 to indicate that this channel should be halted the next
  309. * time a request is queued for the channel. This is necessary in
  310. * slave mode if no request queue space is available when an attempt
  311. * is made to halt the channel.
  312. */
  313. uint8_t halt_on_queue;
  314. /**
  315. * Set to 1 if the host channel has been halted, but the core is not
  316. * finished flushing queued requests. Otherwise 0.
  317. */
  318. uint8_t halt_pending;
  319. /**
  320. * Reason for halting the host channel.
  321. */
  322. dwc_otg_halt_status_e halt_status;
  323. /*
  324. * Split settings for the host channel
  325. */
  326. uint8_t do_split; /**< Enable split for the channel */
  327. uint8_t complete_split; /**< Enable complete split */
  328. uint8_t hub_addr; /**< Address of high speed hub */
  329. uint8_t port_addr; /**< Port of the low/full speed device */
  330. /** Split transaction position
  331. * One of the following values:
  332. * - DWC_HCSPLIT_XACTPOS_MID
  333. * - DWC_HCSPLIT_XACTPOS_BEGIN
  334. * - DWC_HCSPLIT_XACTPOS_END
  335. * - DWC_HCSPLIT_XACTPOS_ALL */
  336. uint8_t xact_pos;
  337. /** Set when the host channel does a short read. */
  338. uint8_t short_read;
  339. /**
  340. * Number of requests issued for this channel since it was assigned to
  341. * the current transfer (not counting PINGs).
  342. */
  343. uint8_t requests;
  344. /**
  345. * Queue Head for the transfer being processed by this channel.
  346. */
  347. struct dwc_otg_qh *qh;
  348. /** @} */
  349. /** Entry in list of host channels. */
  350. DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  351. /** @name Descriptor DMA support */
  352. /** @{ */
  353. /** Number of Transfer Descriptors */
  354. uint16_t ntd;
  355. /** Descriptor List DMA address */
  356. dwc_dma_t desc_list_addr;
  357. /** Scheduling micro-frame bitmap. */
  358. uint8_t schinfo;
  359. /** @} */
  360. } dwc_hc_t;
  361. /**
  362. * The following parameters may be specified when starting the module. These
  363. * parameters define how the DWC_otg controller should be configured.
  364. */
  365. typedef struct dwc_otg_core_params {
  366. int32_t opt;
  367. /**
  368. * Specifies the OTG capabilities. The driver will automatically
  369. * detect the value for this parameter if none is specified.
  370. * 0 - HNP and SRP capable (default)
  371. * 1 - SRP Only capable
  372. * 2 - No HNP/SRP capable
  373. */
  374. int32_t otg_cap;
  375. /**
  376. * Specifies whether to use slave or DMA mode for accessing the data
  377. * FIFOs. The driver will automatically detect the value for this
  378. * parameter if none is specified.
  379. * 0 - Slave
  380. * 1 - DMA (default, if available)
  381. */
  382. int32_t dma_enable;
  383. /**
  384. * When DMA mode is enabled specifies whether to use address DMA or DMA
  385. * Descriptor mode for accessing the data FIFOs in device mode. The driver
  386. * will automatically detect the value for this if none is specified.
  387. * 0 - address DMA
  388. * 1 - DMA Descriptor(default, if available)
  389. */
  390. int32_t dma_desc_enable;
  391. /** The DMA Burst size (applicable only for External DMA
  392. * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  393. */
  394. int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  395. /**
  396. * Specifies the maximum speed of operation in host and device mode.
  397. * The actual speed depends on the speed of the attached device and
  398. * the value of phy_type. The actual speed depends on the speed of the
  399. * attached device.
  400. * 0 - High Speed (default)
  401. * 1 - Full Speed
  402. */
  403. int32_t speed;
  404. /** Specifies whether low power mode is supported when attached
  405. * to a Full Speed or Low Speed device in host mode.
  406. * 0 - Don't support low power mode (default)
  407. * 1 - Support low power mode
  408. */
  409. int32_t host_support_fs_ls_low_power;
  410. /** Specifies the PHY clock rate in low power mode when connected to a
  411. * Low Speed device in host mode. This parameter is applicable only if
  412. * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  413. * then defaults to 6 MHZ otherwise 48 MHZ.
  414. *
  415. * 0 - 48 MHz
  416. * 1 - 6 MHz
  417. */
  418. int32_t host_ls_low_power_phy_clk;
  419. /**
  420. * 0 - Use cC FIFO size parameters
  421. * 1 - Allow dynamic FIFO sizing (default)
  422. */
  423. int32_t enable_dynamic_fifo;
  424. /** Total number of 4-byte words in the data FIFO memory. This
  425. * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  426. * Tx FIFOs.
  427. * 32 to 32768 (default 8192)
  428. * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  429. */
  430. int32_t data_fifo_size;
  431. /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  432. * FIFO sizing is enabled.
  433. * 16 to 32768 (default 1064)
  434. */
  435. int32_t dev_rx_fifo_size;
  436. /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  437. * when dynamic FIFO sizing is enabled.
  438. * 16 to 32768 (default 1024)
  439. */
  440. int32_t dev_nperio_tx_fifo_size;
  441. /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  442. * mode when dynamic FIFO sizing is enabled.
  443. * 4 to 768 (default 256)
  444. */
  445. uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  446. /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  447. * FIFO sizing is enabled.
  448. * 16 to 32768 (default 1024)
  449. */
  450. int32_t host_rx_fifo_size;
  451. /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  452. * when Dynamic FIFO sizing is enabled in the core.
  453. * 16 to 32768 (default 1024)
  454. */
  455. int32_t host_nperio_tx_fifo_size;
  456. /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  457. * FIFO sizing is enabled.
  458. * 16 to 32768 (default 1024)
  459. */
  460. int32_t host_perio_tx_fifo_size;
  461. /** The maximum transfer size supported in bytes.
  462. * 2047 to 65,535 (default 65,535)
  463. */
  464. int32_t max_transfer_size;
  465. /** The maximum number of packets in a transfer.
  466. * 15 to 511 (default 511)
  467. */
  468. int32_t max_packet_count;
  469. /** The number of host channel registers to use.
  470. * 1 to 16 (default 12)
  471. * Note: The FPGA configuration supports a maximum of 12 host channels.
  472. */
  473. int32_t host_channels;
  474. /** The number of endpoints in addition to EP0 available for device
  475. * mode operations.
  476. * 1 to 15 (default 6 IN and OUT)
  477. * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  478. * endpoints in addition to EP0.
  479. */
  480. int32_t dev_endpoints;
  481. /**
  482. * Specifies the type of PHY interface to use. By default, the driver
  483. * will automatically detect the phy_type.
  484. *
  485. * 0 - Full Speed PHY
  486. * 1 - UTMI+ (default)
  487. * 2 - ULPI
  488. */
  489. int32_t phy_type;
  490. /**
  491. * Specifies the UTMI+ Data Width. This parameter is
  492. * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  493. * PHY_TYPE, this parameter indicates the data width between
  494. * the MAC and the ULPI Wrapper.) Also, this parameter is
  495. * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  496. * to "8 and 16 bits", meaning that the core has been
  497. * configured to work at either data path width.
  498. *
  499. * 8 or 16 bits (default 16)
  500. */
  501. int32_t phy_utmi_width;
  502. /**
  503. * Specifies whether the ULPI operates at double or single
  504. * data rate. This parameter is only applicable if PHY_TYPE is
  505. * ULPI.
  506. *
  507. * 0 - single data rate ULPI interface with 8 bit wide data
  508. * bus (default)
  509. * 1 - double data rate ULPI interface with 4 bit wide data
  510. * bus
  511. */
  512. int32_t phy_ulpi_ddr;
  513. /**
  514. * Specifies whether to use the internal or external supply to
  515. * drive the vbus with a ULPI phy.
  516. */
  517. int32_t phy_ulpi_ext_vbus;
  518. /**
  519. * Specifies whether to use the I2Cinterface for full speed PHY. This
  520. * parameter is only applicable if PHY_TYPE is FS.
  521. * 0 - No (default)
  522. * 1 - Yes
  523. */
  524. int32_t i2c_enable;
  525. int32_t ulpi_fs_ls;
  526. int32_t ts_dline;
  527. /**
  528. * Specifies whether dedicated transmit FIFOs are
  529. * enabled for non periodic IN endpoints in device mode
  530. * 0 - No
  531. * 1 - Yes
  532. */
  533. int32_t en_multiple_tx_fifo;
  534. /** Number of 4-byte words in each of the Tx FIFOs in device
  535. * mode when dynamic FIFO sizing is enabled.
  536. * 4 to 768 (default 256)
  537. */
  538. uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  539. /** Thresholding enable flag-
  540. * bit 0 - enable non-ISO Tx thresholding
  541. * bit 1 - enable ISO Tx thresholding
  542. * bit 2 - enable Rx thresholding
  543. */
  544. uint32_t thr_ctl;
  545. /** Thresholding length for Tx
  546. * FIFOs in 32 bit DWORDs
  547. */
  548. uint32_t tx_thr_length;
  549. /** Thresholding length for Rx
  550. * FIFOs in 32 bit DWORDs
  551. */
  552. uint32_t rx_thr_length;
  553. /**
  554. * Specifies whether LPM (Link Power Management) support is enabled
  555. */
  556. int32_t lpm_enable;
  557. /** Per Transfer Interrupt
  558. * mode enable flag
  559. * 1 - Enabled
  560. * 0 - Disabled
  561. */
  562. int32_t pti_enable;
  563. /** Multi Processor Interrupt
  564. * mode enable flag
  565. * 1 - Enabled
  566. * 0 - Disabled
  567. */
  568. int32_t mpi_enable;
  569. /** IS_USB Capability
  570. * 1 - Enabled
  571. * 0 - Disabled
  572. */
  573. int32_t ic_usb_cap;
  574. /** AHB Threshold Ratio
  575. * 2'b00 AHB Threshold = MAC Threshold
  576. * 2'b01 AHB Threshold = 1/2 MAC Threshold
  577. * 2'b10 AHB Threshold = 1/4 MAC Threshold
  578. * 2'b11 AHB Threshold = 1/8 MAC Threshold
  579. */
  580. int32_t ahb_thr_ratio;
  581. /** ADP Support
  582. * 1 - Enabled
  583. * 0 - Disabled
  584. */
  585. int32_t adp_supp_enable;
  586. /** HFIR Reload Control
  587. * 0 - The HFIR cannot be reloaded dynamically.
  588. * 1 - Allow dynamic reloading of the HFIR register during runtime.
  589. */
  590. int32_t reload_ctl;
  591. /** DCFG: Enable device Out NAK
  592. * 0 - The core does not set NAK after Bulk Out transfer complete.
  593. * 1 - The core sets NAK after Bulk OUT transfer complete.
  594. */
  595. int32_t dev_out_nak;
  596. /** DCFG: Enable Continue on BNA
  597. * After receiving BNA interrupt the core disables the endpoint,when the
  598. * endpoint is re-enabled by the application the core starts processing
  599. * 0 - from the DOEPDMA descriptor
  600. * 1 - from the descriptor which received the BNA.
  601. */
  602. int32_t cont_on_bna;
  603. /** GAHBCFG: AHB Single Support
  604. * This bit when programmed supports SINGLE transfers for remainder
  605. * data in a transfer for DMA mode of operation.
  606. * 0 - in this case the remainder data will be sent using INCR burst size.
  607. * 1 - in this case the remainder data will be sent using SINGLE burst size.
  608. */
  609. int32_t ahb_single;
  610. /** Core Power down mode
  611. * 0 - No Power Down is enabled
  612. * 1 - Reserved
  613. * 2 - Complete Power Down (Hibernation)
  614. */
  615. int32_t power_down;
  616. /** OTG revision supported
  617. * 0 - OTG 1.3 revision
  618. * 1 - OTG 2.0 revision
  619. */
  620. int32_t otg_ver;
  621. } dwc_otg_core_params_t;
  622. #ifdef DEBUG
  623. struct dwc_otg_core_if;
  624. typedef struct hc_xfer_info {
  625. struct dwc_otg_core_if *core_if;
  626. dwc_hc_t *hc;
  627. } hc_xfer_info_t;
  628. #endif
  629. typedef struct ep_xfer_info {
  630. struct dwc_otg_core_if *core_if;
  631. dwc_ep_t *ep;
  632. uint8_t state;
  633. } ep_xfer_info_t;
  634. /*
  635. * Device States
  636. */
  637. typedef enum dwc_otg_lx_state {
  638. /** On state */
  639. DWC_OTG_L0,
  640. /** LPM sleep state*/
  641. DWC_OTG_L1,
  642. /** USB suspend state*/
  643. DWC_OTG_L2,
  644. /** Off state*/
  645. DWC_OTG_L3
  646. } dwc_otg_lx_state_e;
  647. struct dwc_otg_global_regs_backup {
  648. uint32_t gotgctl_local;
  649. uint32_t gintmsk_local;
  650. uint32_t gahbcfg_local;
  651. uint32_t gusbcfg_local;
  652. uint32_t grxfsiz_local;
  653. uint32_t gnptxfsiz_local;
  654. #ifdef CONFIG_USB_DWC_OTG_LPM
  655. uint32_t glpmcfg_local;
  656. #endif
  657. uint32_t gi2cctl_local;
  658. uint32_t hptxfsiz_local;
  659. uint32_t pcgcctl_local;
  660. uint32_t gdfifocfg_local;
  661. uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  662. uint32_t gpwrdn_local;
  663. };
  664. struct dwc_otg_host_regs_backup {
  665. uint32_t hcfg_local;
  666. uint32_t haintmsk_local;
  667. uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  668. uint32_t hprt0_local;
  669. uint32_t hfir_local;
  670. };
  671. struct dwc_otg_dev_regs_backup {
  672. uint32_t dcfg;
  673. uint32_t dctl;
  674. uint32_t daintmsk;
  675. uint32_t diepmsk;
  676. uint32_t doepmsk;
  677. uint32_t diepctl[MAX_EPS_CHANNELS];
  678. uint32_t dieptsiz[MAX_EPS_CHANNELS];
  679. uint32_t diepdma[MAX_EPS_CHANNELS];
  680. };
  681. /**
  682. * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  683. * the DWC_otg controller acting in either host or device mode. It
  684. * represents the programming view of the controller as a whole.
  685. */
  686. struct dwc_otg_core_if {
  687. /** Parameters that define how the core should be configured.*/
  688. dwc_otg_core_params_t *core_params;
  689. /** Core Global registers starting at offset 000h. */
  690. dwc_otg_core_global_regs_t *core_global_regs;
  691. /** Device-specific information */
  692. dwc_otg_dev_if_t *dev_if;
  693. /** Host-specific information */
  694. dwc_otg_host_if_t *host_if;
  695. /** PHY tune register address */
  696. usb_peri_reg_t * usb_peri_reg;
  697. /** Value from SNPSID register */
  698. uint32_t snpsid;
  699. /*
  700. * Set to 1 if the core PHY interface bits in USBCFG have been
  701. * initialized.
  702. */
  703. uint8_t phy_init_done;
  704. /*
  705. * SRP Success flag, set by srp success interrupt in FS I2C mode
  706. */
  707. uint8_t srp_success;
  708. uint8_t srp_timer_started;
  709. /** Timer for SRP. If it expires before SRP is successful
  710. * clear the SRP. */
  711. dwc_timer_t *srp_timer;
  712. #ifdef DWC_DEV_SRPCAP
  713. /* This timer is needed to power on the hibernated host core if SRP is not
  714. * initiated on connected SRP capable device for limited period of time
  715. */
  716. uint8_t pwron_timer_started;
  717. dwc_timer_t *pwron_timer;
  718. #endif
  719. /* Common configuration information */
  720. /** Power and Clock Gating Control Register */
  721. volatile uint32_t *pcgcctl;
  722. #define DWC_OTG_PCGCCTL_OFFSET 0xE00
  723. /** Push/pop addresses for endpoints or host channels.*/
  724. uint32_t *data_fifo[MAX_EPS_CHANNELS];
  725. #define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  726. #define DWC_OTG_DATA_FIFO_SIZE 0x1000
  727. /** Total RAM for FIFOs (Bytes) */
  728. uint16_t total_fifo_size;
  729. /** Size of Rx FIFO (Bytes) */
  730. uint16_t rx_fifo_size;
  731. /** Size of Non-periodic Tx FIFO (Bytes) */
  732. uint16_t nperio_tx_fifo_size;
  733. /** 1 if DMA is enabled, 0 otherwise. */
  734. uint8_t dma_enable;
  735. /** 1 if DMA descriptor is enabled, 0 otherwise. */
  736. uint8_t dma_desc_enable;
  737. /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  738. uint8_t pti_enh_enable;
  739. /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  740. uint8_t multiproc_int_enable;
  741. /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  742. uint8_t en_multiple_tx_fifo;
  743. /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  744. * process of being queued */
  745. uint8_t queuing_high_bandwidth;
  746. /** Hardware Configuration -- stored here for convenience.*/
  747. hwcfg1_data_t hwcfg1;
  748. hwcfg2_data_t hwcfg2;
  749. hwcfg3_data_t hwcfg3;
  750. hwcfg4_data_t hwcfg4;
  751. fifosize_data_t hptxfsiz;
  752. /** Host and Device Configuration -- stored here for convenience.*/
  753. hcfg_data_t hcfg;
  754. dcfg_data_t dcfg;
  755. /** The operational State, during transations
  756. * (a_host>>a_peripherial and b_device=>b_host) this may not
  757. * match the core but allows the software to determine
  758. * transitions.
  759. */
  760. uint8_t op_state;
  761. /**
  762. * Set to 1 if the HCD needs to be restarted on a session request
  763. * interrupt. This is required if no connector ID status change has
  764. * occurred since the HCD was last disconnected.
  765. */
  766. uint8_t restart_hcd_on_session_req;
  767. /** HCD callbacks */
  768. /** A-Device is a_host */
  769. #define A_HOST (1)
  770. /** A-Device is a_suspend */
  771. #define A_SUSPEND (2)
  772. /** A-Device is a_peripherial */
  773. #define A_PERIPHERAL (3)
  774. /** B-Device is operating as a Peripheral. */
  775. #define B_PERIPHERAL (4)
  776. /** B-Device is operating as a Host. */
  777. #define B_HOST (5)
  778. /** HCD callbacks */
  779. struct dwc_otg_cil_callbacks *hcd_cb;
  780. void *hcd_cb_p;
  781. /** PCD callbacks */
  782. struct dwc_otg_cil_callbacks *pcd_cb;
  783. void *pcd_cb_p;
  784. /* Set VBus Power though GPIO */
  785. void (*set_vbus_power) (char is_power_on);
  786. /* Charger Detect Call back*/
  787. void (*charger_detect_cb) (int bc_mode);
  788. /* BC mode record*/
  789. int bc_mode;
  790. /* Session Valid */
  791. int session_valid;
  792. /** Device mode Periodic Tx FIFO Mask */
  793. uint32_t p_tx_msk;
  794. /** Device mode Periodic Tx FIFO Mask */
  795. uint32_t tx_msk;
  796. /** Workqueue object used for handling several interrupts */
  797. dwc_workq_t *wq_otg;
  798. /** Timer object used for handling "Wakeup Detected" Interrupt */
  799. dwc_timer_t *wkp_timer;
  800. /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  801. uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  802. ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  803. dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  804. #ifdef DEBUG
  805. uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  806. hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  807. dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  808. uint32_t hfnum_7_samples;
  809. uint64_t hfnum_7_frrem_accum;
  810. uint32_t hfnum_0_samples;
  811. uint64_t hfnum_0_frrem_accum;
  812. uint32_t hfnum_other_samples;
  813. uint64_t hfnum_other_frrem_accum;
  814. #endif
  815. #ifdef DWC_UTE_CFI
  816. uint16_t pwron_rxfsiz;
  817. uint16_t pwron_gnptxfsiz;
  818. uint16_t pwron_txfsiz[15];
  819. uint16_t init_rxfsiz;
  820. uint16_t init_gnptxfsiz;
  821. uint16_t init_txfsiz[15];
  822. #endif
  823. /** Lx state of device */
  824. dwc_otg_lx_state_e lx_state;
  825. /** Saved Core Global registers */
  826. struct dwc_otg_global_regs_backup *gr_backup;
  827. /** Saved Host registers */
  828. struct dwc_otg_host_regs_backup *hr_backup;
  829. /** Saved Device registers */
  830. struct dwc_otg_dev_regs_backup *dr_backup;
  831. /** Power Down Enable */
  832. uint32_t power_down;
  833. /** ADP support Enable */
  834. uint32_t adp_enable;
  835. /** ADP structure object */
  836. dwc_otg_adp_t adp;
  837. /** hibernation/suspend flag */
  838. int hibernation_suspend;
  839. /** OTG revision supported */
  840. uint32_t otg_ver;
  841. /** OTG status flag used for HNP polling */
  842. uint8_t otg_sts;
  843. /** Pointer to either hcd->lock or pcd->lock */
  844. dwc_spinlock_t *lock;
  845. /** Start predict NextEP based on Learning Queue if equal 1,
  846. * also used as counter of disabled NP IN EP's */
  847. uint8_t start_predict;
  848. /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  849. * active, 0xff otherwise */
  850. uint8_t nextep_seq[MAX_EPS_CHANNELS];
  851. /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  852. uint8_t first_in_nextep_seq;
  853. /** Frame number while entering to ISR - needed for ISOCs **/
  854. uint32_t frame_num;
  855. };
  856. #ifdef DEBUG
  857. /*
  858. * This function is called when transfer is timed out.
  859. */
  860. extern void hc_xfer_timeout(void *ptr);
  861. #endif
  862. /*
  863. * This function is called when transfer is timed out on endpoint.
  864. */
  865. extern void ep_xfer_timeout(void *ptr);
  866. /*
  867. * The following functions are functions for works
  868. * using during handling some interrupts
  869. */
  870. extern void w_conn_id_status_change(void *p);
  871. extern void w_wakeup_detected(void *p);
  872. /** Saves global register values into system memory. */
  873. extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  874. /** Saves device register values into system memory. */
  875. extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  876. /** Saves host register values into system memory. */
  877. extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  878. /** Restore global register values. */
  879. extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  880. /** Restore host register values. */
  881. extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  882. /** Restore device register values. */
  883. extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  884. int rem_wakeup);
  885. extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  886. extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  887. int is_host);
  888. extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  889. int restore_mode, int reset);
  890. extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  891. int rem_wakeup, int reset);
  892. /*
  893. * The following functions support initialization of the CIL driver component
  894. * and the DWC_otg controller.
  895. */
  896. extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  897. extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  898. /** @name Device CIL Functions
  899. * The following functions support managing the DWC_otg controller in device
  900. * mode.
  901. */
  902. /**@{*/
  903. extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  904. extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  905. uint32_t * _dest);
  906. extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  907. extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  908. extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  909. extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  910. extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  911. dwc_ep_t * _ep);
  912. extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  913. dwc_ep_t * _ep);
  914. extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  915. dwc_ep_t * _ep);
  916. extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  917. dwc_ep_t * _ep);
  918. extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  919. dwc_ep_t * _ep, int _dma);
  920. extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  921. extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  922. dwc_ep_t * _ep);
  923. extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  924. #ifdef DWC_EN_ISOC
  925. extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  926. dwc_ep_t * ep);
  927. extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  928. dwc_ep_t * ep);
  929. #endif /* DWC_EN_ISOC */
  930. /**@}*/
  931. /** @name Host CIL Functions
  932. * The following functions support managing the DWC_otg controller in host
  933. * mode.
  934. */
  935. /**@{*/
  936. extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  937. extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  938. dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  939. extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  940. extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  941. dwc_hc_t * _hc);
  942. extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  943. dwc_hc_t * _hc);
  944. extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  945. extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  946. dwc_hc_t * _hc);
  947. extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  948. extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  949. extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  950. dwc_hc_t * hc);
  951. extern void dwc_otg_set_vbus_power(dwc_otg_core_if_t * _core_if,
  952. char is_power_on);
  953. extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  954. /* Macro used to clear one channel interrupt */
  955. #define clear_hc_int(_hc_regs_, _intr_) \
  956. do { \
  957. hcint_data_t hcint_clear = {.d32 = 0}; \
  958. hcint_clear.b._intr_ = 1; \
  959. DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  960. } while (0)
  961. /*
  962. * Macro used to disable one channel interrupt. Channel interrupts are
  963. * disabled when the channel is halted or released by the interrupt handler.
  964. * There is no need to handle further interrupts of that type until the
  965. * channel is re-assigned. In fact, subsequent handling may cause crashes
  966. * because the channel structures are cleaned up when the channel is released.
  967. */
  968. #define disable_hc_int(_hc_regs_, _intr_) \
  969. do { \
  970. hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  971. hcintmsk.b._intr_ = 1; \
  972. DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  973. } while (0)
  974. /**
  975. * This function Reads HPRT0 in preparation to modify. It keeps the
  976. * WC bits 0 so that if they are read as 1, they won't clear when you
  977. * write it back
  978. */
  979. static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  980. {
  981. hprt0_data_t hprt0;
  982. hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  983. hprt0.b.prtena = 0;
  984. hprt0.b.prtconndet = 0;
  985. hprt0.b.prtenchng = 0;
  986. hprt0.b.prtovrcurrchng = 0;
  987. return hprt0.d32;
  988. }
  989. /**@}*/
  990. /** @name Common CIL Functions
  991. * The following functions support managing the DWC_otg controller in either
  992. * device or host mode.
  993. */
  994. /**@{*/
  995. extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  996. uint8_t * dest, uint16_t bytes);
  997. extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  998. extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  999. extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  1000. /**
  1001. * This function returns the Core Interrupt register.
  1002. */
  1003. static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  1004. {
  1005. return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  1006. DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  1007. }
  1008. /**
  1009. * This function returns the OTG Interrupt register.
  1010. */
  1011. static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  1012. {
  1013. return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  1014. }
  1015. /**
  1016. * This function reads the Device All Endpoints Interrupt register and
  1017. * returns the IN endpoint interrupt bits.
  1018. */
  1019. static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  1020. core_if)
  1021. {
  1022. uint32_t v;
  1023. if (core_if->multiproc_int_enable) {
  1024. v = DWC_READ_REG32(&core_if->dev_if->
  1025. dev_global_regs->deachint) &
  1026. DWC_READ_REG32(&core_if->
  1027. dev_if->dev_global_regs->deachintmsk);
  1028. } else {
  1029. v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  1030. DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  1031. }
  1032. return (v & 0xffff);
  1033. }
  1034. /**
  1035. * This function reads the Device All Endpoints Interrupt register and
  1036. * returns the OUT endpoint interrupt bits.
  1037. */
  1038. static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  1039. core_if)
  1040. {
  1041. uint32_t v;
  1042. if (core_if->multiproc_int_enable) {
  1043. v = DWC_READ_REG32(&core_if->dev_if->
  1044. dev_global_regs->deachint) &
  1045. DWC_READ_REG32(&core_if->
  1046. dev_if->dev_global_regs->deachintmsk);
  1047. } else {
  1048. v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  1049. DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  1050. }
  1051. return ((v & 0xffff0000) >> 16);
  1052. }
  1053. /**
  1054. * This function returns the Device IN EP Interrupt register
  1055. */
  1056. static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  1057. dwc_ep_t * ep)
  1058. {
  1059. dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  1060. uint32_t v, msk, emp;
  1061. if (core_if->multiproc_int_enable) {
  1062. msk =
  1063. DWC_READ_REG32(&dev_if->
  1064. dev_global_regs->diepeachintmsk[ep->num]);
  1065. emp =
  1066. DWC_READ_REG32(&dev_if->
  1067. dev_global_regs->dtknqr4_fifoemptymsk);
  1068. msk |= ((emp >> ep->num) & 0x1) << 7;
  1069. v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  1070. } else {
  1071. msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  1072. emp =
  1073. DWC_READ_REG32(&dev_if->
  1074. dev_global_regs->dtknqr4_fifoemptymsk);
  1075. msk |= ((emp >> ep->num) & 0x1) << 7;
  1076. v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  1077. }
  1078. return v;
  1079. }
  1080. /**
  1081. * This function returns the Device OUT EP Interrupt register
  1082. */
  1083. static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  1084. _core_if, dwc_ep_t * _ep)
  1085. {
  1086. dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  1087. uint32_t v;
  1088. doepmsk_data_t msk = {.d32 = 0 };
  1089. if (_core_if->multiproc_int_enable) {
  1090. msk.d32 =
  1091. DWC_READ_REG32(&dev_if->
  1092. dev_global_regs->doepeachintmsk[_ep->num]);
  1093. if (_core_if->pti_enh_enable) {
  1094. msk.b.pktdrpsts = 1;
  1095. }
  1096. v = DWC_READ_REG32(&dev_if->
  1097. out_ep_regs[_ep->num]->doepint) & msk.d32;
  1098. } else {
  1099. msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  1100. if (_core_if->pti_enh_enable) {
  1101. msk.b.pktdrpsts = 1;
  1102. }
  1103. v = DWC_READ_REG32(&dev_if->
  1104. out_ep_regs[_ep->num]->doepint) & msk.d32;
  1105. }
  1106. return v;
  1107. }
  1108. /**
  1109. * This function returns the Host All Channel Interrupt register
  1110. */
  1111. static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  1112. _core_if)
  1113. {
  1114. return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  1115. }
  1116. static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  1117. _core_if, dwc_hc_t * _hc)
  1118. {
  1119. return (DWC_READ_REG32
  1120. (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  1121. }
  1122. /**
  1123. * This function returns the mode of the operation, host or device.
  1124. *
  1125. * @return 0 - Device Mode, 1 - Host Mode
  1126. */
  1127. static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  1128. {
  1129. return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  1130. }
  1131. /**@}*/
  1132. /**
  1133. * DWC_otg CIL callback structure. This structure allows the HCD and
  1134. * PCD to register functions used for starting and stopping the PCD
  1135. * and HCD for role change on for a DRD.
  1136. */
  1137. typedef struct dwc_otg_cil_callbacks {
  1138. /** Start function for role change */
  1139. int (*start) (void *_p);
  1140. /** Stop Function for role change */
  1141. int (*stop) (void *_p);
  1142. /** Disconnect Function for role change */
  1143. int (*disconnect) (void *_p);
  1144. /** Resume/Remote wakeup Function */
  1145. int (*resume_wakeup) (void *_p);
  1146. /** Suspend function */
  1147. int (*suspend) (void *_p);
  1148. /** Session Start (SRP) */
  1149. int (*session_start) (void *_p);
  1150. #ifdef CONFIG_USB_DWC_OTG_LPM
  1151. /** Sleep (switch to L0 state) */
  1152. int (*sleep) (void *_p);
  1153. #endif
  1154. } dwc_otg_cil_callbacks_t;
  1155. extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  1156. dwc_otg_cil_callbacks_t * _cb,
  1157. void *_p);
  1158. extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  1159. dwc_otg_cil_callbacks_t * _cb,
  1160. void *_p);
  1161. void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  1162. //////////////////////////////////////////////////////////////////////
  1163. /** Start the HCD. Helper function for using the HCD callbacks.
  1164. *
  1165. * @param core_if Programming view of DWC_otg controller.
  1166. */
  1167. static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  1168. {
  1169. if (core_if->hcd_cb && core_if->hcd_cb->start) {
  1170. core_if->hcd_cb->start(core_if->hcd_cb_p);
  1171. }
  1172. }
  1173. /** Stop the HCD. Helper function for using the HCD callbacks.
  1174. *
  1175. * @param core_if Programming view of DWC_otg controller.
  1176. */
  1177. static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  1178. {
  1179. if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  1180. core_if->hcd_cb->stop(core_if->hcd_cb_p);
  1181. }
  1182. }
  1183. /** Disconnect the HCD. Helper function for using the HCD callbacks.
  1184. *
  1185. * @param core_if Programming view of DWC_otg controller.
  1186. */
  1187. static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  1188. {
  1189. if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  1190. core_if->hcd_cb->disconnect(core_if->hcd_cb_p);
  1191. }
  1192. }
  1193. /** Inform the HCD the a New Session has begun. Helper function for
  1194. * using the HCD callbacks.
  1195. *
  1196. * @param core_if Programming view of DWC_otg controller.
  1197. */
  1198. static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  1199. {
  1200. if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  1201. core_if->hcd_cb->session_start(core_if->hcd_cb_p);
  1202. }
  1203. }
  1204. #ifdef CONFIG_USB_DWC_OTG_LPM
  1205. /**
  1206. * Inform the HCD about LPM sleep.
  1207. * Helper function for using the HCD callbacks.
  1208. *
  1209. * @param core_if Programming view of DWC_otg controller.
  1210. */
  1211. static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  1212. {
  1213. if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  1214. core_if->hcd_cb->sleep(core_if->hcd_cb_p);
  1215. }
  1216. }
  1217. #endif
  1218. /** Resume the HCD. Helper function for using the HCD callbacks.
  1219. *
  1220. * @param core_if Programming view of DWC_otg controller.
  1221. */
  1222. static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  1223. {
  1224. if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  1225. core_if->hcd_cb->resume_wakeup(core_if->hcd_cb_p);
  1226. }
  1227. }
  1228. /** Start the PCD. Helper function for using the PCD callbacks.
  1229. *
  1230. * @param core_if Programming view of DWC_otg controller.
  1231. */
  1232. static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  1233. {
  1234. if (core_if->pcd_cb && core_if->pcd_cb->start) {
  1235. core_if->pcd_cb->start(core_if->pcd_cb_p);
  1236. }
  1237. }
  1238. /** Stop the PCD. Helper function for using the PCD callbacks.
  1239. *
  1240. * @param core_if Programming view of DWC_otg controller.
  1241. */
  1242. static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  1243. {
  1244. if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  1245. core_if->pcd_cb->stop(core_if->pcd_cb_p);
  1246. }
  1247. }
  1248. /** Suspend the PCD. Helper function for using the PCD callbacks.
  1249. *
  1250. * @param core_if Programming view of DWC_otg controller.
  1251. */
  1252. static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  1253. {
  1254. if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  1255. core_if->pcd_cb->suspend(core_if->pcd_cb_p);
  1256. }
  1257. }
  1258. /** Resume the PCD. Helper function for using the PCD callbacks.
  1259. *
  1260. * @param core_if Programming view of DWC_otg controller.
  1261. */
  1262. static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  1263. {
  1264. if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  1265. core_if->pcd_cb->resume_wakeup(core_if->pcd_cb_p);
  1266. }
  1267. }
  1268. //////////////////////////////////////////////////////////////////////
  1269. #endif