core.h 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. /*
  2. * core.h - DesignWare HS OTG Controller common declarations
  3. *
  4. * Copyright (C) 2004-2013 Synopsys, Inc.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions, and the following disclaimer,
  11. * without modification.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. The names of the above-listed copyright holders may not be used
  16. * to endorse or promote products derived from this software without
  17. * specific prior written permission.
  18. *
  19. * ALTERNATIVELY, this software may be distributed under the terms of the
  20. * GNU General Public License ("GPL") as published by the Free Software
  21. * Foundation; either version 2 of the License, or (at your option) any
  22. * later version.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  25. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  26. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #ifndef __DWC2_CORE_H__
  37. #define __DWC2_CORE_H__
  38. #include "board.h"
  39. #include "dwc2_compat.h"
  40. //#include <linux/compat.h>
  41. #include "usb_os_adapter.h"
  42. #include "queue.h"
  43. #include "timers.h"
  44. #include "hw.h"
  45. /*
  46. * Suggested defines for tracers:
  47. * - no_printk: Disable tracing
  48. * - pr_info: Print this info to the console
  49. * - trace_printk: Print this info to trace buffer (good for verbose logging)
  50. */
  51. #ifndef NO_GNU
  52. #define DWC2_TRACE_SCHEDULER no_printk
  53. #define DWC2_TRACE_SCHEDULER_VB no_printk
  54. /* Detailed scheduler tracing, but won't overwhelm console */
  55. #define dwc2_sch_dbg(hsotg, fmt, ...) \
  56. DWC2_TRACE_SCHEDULER(pr_fmt("%s: SCH: " fmt), \
  57. dev_name(hsotg->dev), ##__VA_ARGS__)
  58. /* Verbose scheduler tracing */
  59. #define dwc2_sch_vdbg(hsotg, fmt, ...) \
  60. DWC2_TRACE_SCHEDULER_VB(pr_fmt("%s: SCH: " fmt), \
  61. dev_name(hsotg->dev), ##__VA_ARGS__)
  62. #else
  63. #define dwc2_sch_dbg(hsotg, fmt, ...)
  64. #define dwc2_sch_vdbg(hsotg, fmt, ...)
  65. #endif
  66. #ifdef CONFIG_MIPS
  67. /*
  68. * There are some MIPS machines that can run in either big-endian
  69. * or little-endian mode and that use the dwc2 register without
  70. * a byteswap in both ways.
  71. * Unlike other architectures, MIPS apparently does not require a
  72. * barrier before the __raw_writel() to synchronize with DMA but does
  73. * require the barrier after the __raw_writel() to serialize a set of
  74. * writes. This set of operations was added specifically for MIPS and
  75. * should only be used there.
  76. */
  77. static inline u32 dwc2_readl(const void __iomem *addr)
  78. {
  79. u32 value = __raw_readl(addr);
  80. /* In order to preserve endianness __raw_* operation is used. Therefore
  81. * a barrier is needed to ensure IO access is not re-ordered across
  82. * reads or writes
  83. */
  84. mb();
  85. return value;
  86. }
  87. static inline void dwc2_writel(u32 value, void __iomem *addr)
  88. {
  89. __raw_writel(value, addr);
  90. /*
  91. * In order to preserve endianness __raw_* operation is used. Therefore
  92. * a barrier is needed to ensure IO access is not re-ordered across
  93. * reads or writes
  94. */
  95. mb();
  96. #ifdef DWC2_LOG_WRITES
  97. pr_info("INFO:: wrote %08x to %p\n", value, addr);
  98. #endif
  99. }
  100. #else
  101. /* Normal architectures just use readl/write */
  102. #ifndef NO_GNU
  103. static inline u32 dwc2_readl(const void __iomem *addr)
  104. #else
  105. static inline u32 dwc2_readl(u32 addr)
  106. #endif
  107. {
  108. return readl(addr);
  109. }
  110. #ifndef NO_GNU
  111. static inline void dwc2_writel(u32 value, void __iomem *addr)
  112. #else
  113. static inline void dwc2_writel(u32 value, u32 addr)
  114. #endif
  115. {
  116. writel(value, addr);
  117. #ifdef DWC2_LOG_WRITES
  118. pr_info("info:: wrote %08x to %p\n", value, addr);
  119. #endif
  120. }
  121. #endif
  122. /* Maximum number of Endpoints/HostChannels */
  123. #define MAX_EPS_CHANNELS 16
  124. /* dwc2-hsotg declarations */
  125. static const char * const dwc2_hsotg_supply_names[] = {
  126. "vusb_d", /* digital USB supply, 1.2V */
  127. "vusb_a", /* analog USB supply, 1.1V */
  128. };
  129. #define DWC2_NUM_SUPPLIES ARRAY_SIZE(dwc2_hsotg_supply_names)
  130. /*
  131. * EP0_MPS_LIMIT
  132. *
  133. * Unfortunately there seems to be a limit of the amount of data that can
  134. * be transferred by IN transactions on EP0. This is either 127 bytes or 3
  135. * packets (which practically means 1 packet and 63 bytes of data) when the
  136. * MPS is set to 64.
  137. *
  138. * This means if we are wanting to move >127 bytes of data, we need to
  139. * split the transactions up, but just doing one packet at a time does
  140. * not work (this may be an implicit DATA0 PID on first packet of the
  141. * transaction) and doing 2 packets is outside the controller's limits.
  142. *
  143. * If we try to lower the MPS size for EP0, then no transfers work properly
  144. * for EP0, and the system will fail basic enumeration. As no cause for this
  145. * has currently been found, we cannot support any large IN transfers for
  146. * EP0.
  147. */
  148. #define EP0_MPS_LIMIT 64
  149. struct dwc2_hsotg;
  150. struct dwc2_hsotg_req;
  151. /**
  152. * struct dwc2_hsotg_ep - driver endpoint definition.
  153. * @ep: The gadget layer representation of the endpoint.
  154. * @name: The driver generated name for the endpoint.
  155. * @queue: Queue of requests for this endpoint.
  156. * @parent: Reference back to the parent device structure.
  157. * @req: The current request that the endpoint is processing. This is
  158. * used to indicate an request has been loaded onto the endpoint
  159. * and has yet to be completed (maybe due to data move, or simply
  160. * awaiting an ack from the core all the data has been completed).
  161. * @debugfs: File entry for debugfs file for this endpoint.
  162. * @lock: State lock to protect contents of endpoint.
  163. * @dir_in: Set to true if this endpoint is of the IN direction, which
  164. * means that it is sending data to the Host.
  165. * @index: The index for the endpoint registers.
  166. * @mc: Multi Count - number of transactions per microframe
  167. * @interval - Interval for periodic endpoints, in frames or microframes.
  168. * @name: The name array passed to the USB core.
  169. * @halted: Set if the endpoint has been halted.
  170. * @periodic: Set if this is a periodic ep, such as Interrupt
  171. * @isochronous: Set if this is a isochronous ep
  172. * @send_zlp: Set if we need to send a zero-length packet.
  173. * @desc_list_dma: The DMA address of descriptor chain currently in use.
  174. * @desc_list: Pointer to descriptor DMA chain head currently in use.
  175. * @desc_count: Count of entries within the DMA descriptor chain of EP.
  176. * @isoc_chain_num: Number of ISOC chain currently in use - either 0 or 1.
  177. * @next_desc: index of next free descriptor in the ISOC chain under SW control.
  178. * @total_data: The total number of data bytes done.
  179. * @fifo_size: The size of the FIFO (for periodic IN endpoints)
  180. * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
  181. * @last_load: The offset of data for the last start of request.
  182. * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
  183. * @target_frame: Targeted frame num to setup next ISOC transfer
  184. * @frame_overrun: Indicates SOF number overrun in DSTS
  185. *
  186. * This is the driver's state for each registered enpoint, allowing it
  187. * to keep track of transactions that need doing. Each endpoint has a
  188. * lock to protect the state, to try and avoid using an overall lock
  189. * for the host controller as much as possible.
  190. *
  191. * For periodic IN endpoints, we have fifo_size and fifo_load to try
  192. * and keep track of the amount of data in the periodic FIFO for each
  193. * of these as we don't have a status register that tells us how much
  194. * is in each of them. (note, this may actually be useless information
  195. * as in shared-fifo mode periodic in acts like a single-frame packet
  196. * buffer than a fifo)
  197. */
  198. struct dwc2_hsotg_ep {
  199. struct usb_ep ep;
  200. #ifndef NO_GNU
  201. struct list_head queue;
  202. #else
  203. List_t queue;
  204. #endif
  205. struct dwc2_hsotg *parent;
  206. struct dwc2_hsotg_req *req;
  207. struct dentry *debugfs;
  208. unsigned long total_data;
  209. unsigned int size_loaded;
  210. unsigned int last_load;
  211. unsigned int fifo_load;
  212. unsigned short fifo_size;
  213. unsigned short fifo_index;
  214. unsigned char dir_in;
  215. unsigned char index;
  216. unsigned char mc;
  217. u16 interval;
  218. unsigned int halted:1;
  219. unsigned int periodic:1;
  220. unsigned int isochronous:1;
  221. unsigned int send_zlp:1;
  222. unsigned int target_frame;
  223. #define TARGET_FRAME_INITIAL 0xFFFFFFFF
  224. bool frame_overrun;
  225. dma_addr_t desc_list_dma;
  226. struct dwc2_dma_desc *desc_list;
  227. u8 desc_count;
  228. #ifdef NO_GNU
  229. u32 desc_list_offset;
  230. #endif
  231. unsigned char isoc_chain_num;
  232. unsigned int next_desc;
  233. char name[10];
  234. };
  235. /**
  236. * struct dwc2_hsotg_req - data transfer request
  237. * @req: The USB gadget request
  238. * @queue: The list of requests for the endpoint this is queued for.
  239. * @saved_req_buf: variable to save req.buf when bounce buffers are used.
  240. */
  241. struct dwc2_hsotg_req {
  242. struct usb_request req;
  243. #ifndef NO_GNU
  244. struct list_head queue;
  245. #else
  246. ListItem_t queue;
  247. ListItem_t free_list_entry;
  248. #endif
  249. void *saved_req_buf;
  250. };
  251. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
  252. IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  253. #define call_gadget(_hs, _entry) \
  254. do { \
  255. if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
  256. (_hs)->driver && (_hs)->driver->_entry) { \
  257. spin_unlock(&_hs->lock); \
  258. (_hs)->driver->_entry(&(_hs)->gadget); \
  259. spin_lock(&_hs->lock); \
  260. } \
  261. } while (0)
  262. #else
  263. #define call_gadget(_hs, _entry) do {} while (0)
  264. #endif
  265. struct dwc2_hsotg;
  266. struct dwc2_host_chan;
  267. /* Device States */
  268. enum dwc2_lx_state {
  269. DWC2_L0, /* On state */
  270. DWC2_L1, /* LPM sleep state */
  271. DWC2_L2, /* USB suspend state */
  272. DWC2_L3, /* Off state */
  273. };
  274. /* Gadget ep0 states */
  275. enum dwc2_ep0_state {
  276. DWC2_EP0_SETUP,
  277. DWC2_EP0_DATA_IN,
  278. DWC2_EP0_DATA_OUT,
  279. DWC2_EP0_STATUS_IN,
  280. DWC2_EP0_STATUS_OUT,
  281. };
  282. /**
  283. * struct dwc2_core_params - Parameters for configuring the core
  284. *
  285. * @otg_cap: Specifies the OTG capabilities.
  286. * 0 - HNP and SRP capable
  287. * 1 - SRP Only capable
  288. * 2 - No HNP/SRP capable (always available)
  289. * Defaults to best available option (0, 1, then 2)
  290. * @host_dma: Specifies whether to use slave or DMA mode for accessing
  291. * the data FIFOs. The driver will automatically detect the
  292. * value for this parameter if none is specified.
  293. * 0 - Slave (always available)
  294. * 1 - DMA (default, if available)
  295. * @dma_desc_enable: When DMA mode is enabled, specifies whether to use
  296. * address DMA mode or descriptor DMA mode for accessing
  297. * the data FIFOs. The driver will automatically detect the
  298. * value for this if none is specified.
  299. * 0 - Address DMA
  300. * 1 - Descriptor DMA (default, if available)
  301. * @dma_desc_fs_enable: When DMA mode is enabled, specifies whether to use
  302. * address DMA mode or descriptor DMA mode for accessing
  303. * the data FIFOs in Full Speed mode only. The driver
  304. * will automatically detect the value for this if none is
  305. * specified.
  306. * 0 - Address DMA
  307. * 1 - Descriptor DMA in FS (default, if available)
  308. * @speed: Specifies the maximum speed of operation in host and
  309. * device mode. The actual speed depends on the speed of
  310. * the attached device and the value of phy_type.
  311. * 0 - High Speed
  312. * (default when phy_type is UTMI+ or ULPI)
  313. * 1 - Full Speed
  314. * (default when phy_type is Full Speed)
  315. * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
  316. * 1 - Allow dynamic FIFO sizing (default, if available)
  317. * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
  318. * are enabled for non-periodic IN endpoints in device
  319. * mode.
  320. * @host_rx_fifo_size: Number of 4-byte words in the Rx FIFO in host mode when
  321. * dynamic FIFO sizing is enabled
  322. * 16 to 32768
  323. * Actual maximum value is autodetected and also
  324. * the default.
  325. * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
  326. * in host mode when dynamic FIFO sizing is enabled
  327. * 16 to 32768
  328. * Actual maximum value is autodetected and also
  329. * the default.
  330. * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
  331. * host mode when dynamic FIFO sizing is enabled
  332. * 16 to 32768
  333. * Actual maximum value is autodetected and also
  334. * the default.
  335. * @max_transfer_size: The maximum transfer size supported, in bytes
  336. * 2047 to 65,535
  337. * Actual maximum value is autodetected and also
  338. * the default.
  339. * @max_packet_count: The maximum number of packets in a transfer
  340. * 15 to 511
  341. * Actual maximum value is autodetected and also
  342. * the default.
  343. * @host_channels: The number of host channel registers to use
  344. * 1 to 16
  345. * Actual maximum value is autodetected and also
  346. * the default.
  347. * @phy_type: Specifies the type of PHY interface to use. By default,
  348. * the driver will automatically detect the phy_type.
  349. * 0 - Full Speed Phy
  350. * 1 - UTMI+ Phy
  351. * 2 - ULPI Phy
  352. * Defaults to best available option (2, 1, then 0)
  353. * @phy_utmi_width: Specifies the UTMI+ Data Width (in bits). This parameter
  354. * is applicable for a phy_type of UTMI+ or ULPI. (For a
  355. * ULPI phy_type, this parameter indicates the data width
  356. * between the MAC and the ULPI Wrapper.) Also, this
  357. * parameter is applicable only if the OTG_HSPHY_WIDTH cC
  358. * parameter was set to "8 and 16 bits", meaning that the
  359. * core has been configured to work at either data path
  360. * width.
  361. * 8 or 16 (default 16 if available)
  362. * @phy_ulpi_ddr: Specifies whether the ULPI operates at double or single
  363. * data rate. This parameter is only applicable if phy_type
  364. * is ULPI.
  365. * 0 - single data rate ULPI interface with 8 bit wide
  366. * data bus (default)
  367. * 1 - double data rate ULPI interface with 4 bit wide
  368. * data bus
  369. * @phy_ulpi_ext_vbus: For a ULPI phy, specifies whether to use the internal or
  370. * external supply to drive the VBus
  371. * 0 - Internal supply (default)
  372. * 1 - External supply
  373. * @i2c_enable: Specifies whether to use the I2Cinterface for a full
  374. * speed PHY. This parameter is only applicable if phy_type
  375. * is FS.
  376. * 0 - No (default)
  377. * 1 - Yes
  378. * @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
  379. * 0 - No (default)
  380. * 1 - Yes
  381. * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
  382. * when attached to a Full Speed or Low Speed device in
  383. * host mode.
  384. * 0 - Don't support low power mode (default)
  385. * 1 - Support low power mode
  386. * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
  387. * when connected to a Low Speed device in host
  388. * mode. This parameter is applicable only if
  389. * host_support_fs_ls_low_power is enabled.
  390. * 0 - 48 MHz
  391. * (default when phy_type is UTMI+ or ULPI)
  392. * 1 - 6 MHz
  393. * (default when phy_type is Full Speed)
  394. * @ts_dline: Enable Term Select Dline pulsing
  395. * 0 - No (default)
  396. * 1 - Yes
  397. * @reload_ctl: Allow dynamic reloading of HFIR register during runtime
  398. * 0 - No (default for core < 2.92a)
  399. * 1 - Yes (default for core >= 2.92a)
  400. * @ahbcfg: This field allows the default value of the GAHBCFG
  401. * register to be overridden
  402. * -1 - GAHBCFG value will be set to 0x06
  403. * (INCR4, default)
  404. * all others - GAHBCFG value will be overridden with
  405. * this value
  406. * Not all bits can be controlled like this, the
  407. * bits defined by GAHBCFG_CTRL_MASK are controlled
  408. * by the driver and are ignored in this
  409. * configuration value.
  410. * @uframe_sched: True to enable the microframe scheduler
  411. * @external_id_pin_ctl: Specifies whether ID pin is handled externally.
  412. * Disable CONIDSTSCHNG controller interrupt in such
  413. * case.
  414. * 0 - No (default)
  415. * 1 - Yes
  416. * @hibernation: Specifies whether the controller support hibernation.
  417. * If hibernation is enabled, the controller will enter
  418. * hibernation in both peripheral and host mode when
  419. * needed.
  420. * 0 - No (default)
  421. * 1 - Yes
  422. * @activate_stm_fs_transceiver: Activate internal transceiver using GGPIO
  423. * register.
  424. * 0 - Deactivate the transceiver (default)
  425. * 1 - Activate the transceiver
  426. * @g_dma: Enables gadget dma usage (default: autodetect).
  427. * @g_dma_desc: Enables gadget descriptor DMA (default: autodetect).
  428. * @g_rx_fifo_size: The periodic rx fifo size for the device, in
  429. * DWORDS from 16-32768 (default: 2048 if
  430. * possible, otherwise autodetect).
  431. * @g_np_tx_fifo_size: The non-periodic tx fifo size for the device in
  432. * DWORDS from 16-32768 (default: 1024 if
  433. * possible, otherwise autodetect).
  434. * @g_tx_fifo_size: An array of TX fifo sizes in dedicated fifo
  435. * mode. Each value corresponds to one EP
  436. * starting from EP1 (max 15 values). Sizes are
  437. * in DWORDS with possible values from from
  438. * 16-32768 (default: 256, 256, 256, 256, 768,
  439. * 768, 768, 768, 0, 0, 0, 0, 0, 0, 0).
  440. * @change_speed_quirk: Change speed configuration to DWC2_SPEED_PARAM_FULL
  441. * while full&low speed device connect. And change speed
  442. * back to DWC2_SPEED_PARAM_HIGH while device is gone.
  443. * 0 - No (default)
  444. * 1 - Yes
  445. *
  446. * The following parameters may be specified when starting the module. These
  447. * parameters define how the DWC_otg controller should be configured. A
  448. * value of -1 (or any other out of range value) for any parameter means
  449. * to read the value from hardware (if possible) or use the builtin
  450. * default described above.
  451. */
  452. struct dwc2_core_params {
  453. u8 otg_cap;
  454. #define DWC2_CAP_PARAM_HNP_SRP_CAPABLE 0
  455. #define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE 1
  456. #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  457. u8 phy_type;
  458. #define DWC2_PHY_TYPE_PARAM_FS 0
  459. #define DWC2_PHY_TYPE_PARAM_UTMI 1
  460. #define DWC2_PHY_TYPE_PARAM_ULPI 2
  461. u8 speed;
  462. #define DWC2_SPEED_PARAM_HIGH 0
  463. #define DWC2_SPEED_PARAM_FULL 1
  464. #define DWC2_SPEED_PARAM_LOW 2
  465. u8 phy_utmi_width;
  466. bool phy_ulpi_ddr;
  467. bool phy_ulpi_ext_vbus;
  468. bool enable_dynamic_fifo;
  469. bool en_multiple_tx_fifo;
  470. bool i2c_enable;
  471. bool ulpi_fs_ls;
  472. bool ts_dline;
  473. bool reload_ctl;
  474. bool uframe_sched;
  475. bool external_id_pin_ctl;
  476. bool hibernation;
  477. bool activate_stm_fs_transceiver;
  478. u16 max_packet_count;
  479. u32 max_transfer_size;
  480. u32 ahbcfg;
  481. /* Host parameters */
  482. bool host_dma;
  483. bool dma_desc_enable;
  484. bool dma_desc_fs_enable;
  485. bool host_support_fs_ls_low_power;
  486. bool host_ls_low_power_phy_clk;
  487. u8 host_channels;
  488. u16 host_rx_fifo_size;
  489. u16 host_nperio_tx_fifo_size;
  490. u16 host_perio_tx_fifo_size;
  491. /* Gadget parameters */
  492. bool g_dma;
  493. bool g_dma_desc;
  494. u32 g_rx_fifo_size;
  495. u32 g_np_tx_fifo_size;
  496. u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
  497. bool change_speed_quirk;
  498. };
  499. /**
  500. * struct dwc2_hw_params - Autodetected parameters.
  501. *
  502. * These parameters are the various parameters read from hardware
  503. * registers during initialization. They typically contain the best
  504. * supported or maximum value that can be configured in the
  505. * corresponding dwc2_core_params value.
  506. *
  507. * The values that are not in dwc2_core_params are documented below.
  508. *
  509. * @op_mode Mode of Operation
  510. * 0 - HNP- and SRP-Capable OTG (Host & Device)
  511. * 1 - SRP-Capable OTG (Host & Device)
  512. * 2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
  513. * 3 - SRP-Capable Device
  514. * 4 - Non-OTG Device
  515. * 5 - SRP-Capable Host
  516. * 6 - Non-OTG Host
  517. * @arch Architecture
  518. * 0 - Slave only
  519. * 1 - External DMA
  520. * 2 - Internal DMA
  521. * @power_optimized Are power optimizations enabled?
  522. * @num_dev_ep Number of device endpoints available
  523. * @num_dev_perio_in_ep Number of device periodic IN endpoints
  524. * available
  525. * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
  526. * Depth
  527. * 0 to 30
  528. * @host_perio_tx_q_depth
  529. * Host Mode Periodic Request Queue Depth
  530. * 2, 4 or 8
  531. * @nperio_tx_q_depth
  532. * Non-Periodic Request Queue Depth
  533. * 2, 4 or 8
  534. * @hs_phy_type High-speed PHY interface type
  535. * 0 - High-speed interface not supported
  536. * 1 - UTMI+
  537. * 2 - ULPI
  538. * 3 - UTMI+ and ULPI
  539. * @fs_phy_type Full-speed PHY interface type
  540. * 0 - Full speed interface not supported
  541. * 1 - Dedicated full speed interface
  542. * 2 - FS pins shared with UTMI+ pins
  543. * 3 - FS pins shared with ULPI pins
  544. * @total_fifo_size: Total internal RAM for FIFOs (bytes)
  545. * @utmi_phy_data_width UTMI+ PHY data width
  546. * 0 - 8 bits
  547. * 1 - 16 bits
  548. * 2 - 8 or 16 bits
  549. * @snpsid: Value from SNPSID register
  550. * @dev_ep_dirs: Direction of device endpoints (GHWCFG1)
  551. */
  552. struct dwc2_hw_params {
  553. unsigned op_mode:3;
  554. unsigned arch:2;
  555. unsigned dma_desc_enable:1;
  556. unsigned enable_dynamic_fifo:1;
  557. unsigned en_multiple_tx_fifo:1;
  558. unsigned rx_fifo_size:16;
  559. unsigned host_nperio_tx_fifo_size:16;
  560. unsigned dev_nperio_tx_fifo_size:16;
  561. unsigned host_perio_tx_fifo_size:16;
  562. unsigned nperio_tx_q_depth:3;
  563. unsigned host_perio_tx_q_depth:3;
  564. unsigned dev_token_q_depth:5;
  565. unsigned max_transfer_size:26;
  566. unsigned max_packet_count:11;
  567. unsigned host_channels:5;
  568. unsigned hs_phy_type:2;
  569. unsigned fs_phy_type:2;
  570. unsigned i2c_enable:1;
  571. unsigned num_dev_ep:4;
  572. unsigned num_dev_perio_in_ep:4;
  573. unsigned total_fifo_size:16;
  574. unsigned power_optimized:1;
  575. unsigned utmi_phy_data_width:2;
  576. u32 snpsid;
  577. u32 dev_ep_dirs;
  578. };
  579. /* Size of control and EP0 buffers */
  580. #define DWC2_CTRL_BUFF_SIZE 8
  581. /**
  582. * struct dwc2_gregs_backup - Holds global registers state before
  583. * entering partial power down
  584. * @gotgctl: Backup of GOTGCTL register
  585. * @gintmsk: Backup of GINTMSK register
  586. * @gahbcfg: Backup of GAHBCFG register
  587. * @gusbcfg: Backup of GUSBCFG register
  588. * @grxfsiz: Backup of GRXFSIZ register
  589. * @gnptxfsiz: Backup of GNPTXFSIZ register
  590. * @gi2cctl: Backup of GI2CCTL register
  591. * @hptxfsiz: Backup of HPTXFSIZ register
  592. * @gdfifocfg: Backup of GDFIFOCFG register
  593. * @dtxfsiz: Backup of DTXFSIZ registers for each endpoint
  594. * @gpwrdn: Backup of GPWRDN register
  595. */
  596. struct dwc2_gregs_backup {
  597. u32 gotgctl;
  598. u32 gintmsk;
  599. u32 gahbcfg;
  600. u32 gusbcfg;
  601. u32 grxfsiz;
  602. u32 gnptxfsiz;
  603. u32 gi2cctl;
  604. u32 hptxfsiz;
  605. u32 pcgcctl;
  606. u32 gdfifocfg;
  607. u32 dtxfsiz[MAX_EPS_CHANNELS];
  608. u32 gpwrdn;
  609. bool valid;
  610. };
  611. /**
  612. * struct dwc2_dregs_backup - Holds device registers state before
  613. * entering partial power down
  614. * @dcfg: Backup of DCFG register
  615. * @dctl: Backup of DCTL register
  616. * @daintmsk: Backup of DAINTMSK register
  617. * @diepmsk: Backup of DIEPMSK register
  618. * @doepmsk: Backup of DOEPMSK register
  619. * @diepctl: Backup of DIEPCTL register
  620. * @dieptsiz: Backup of DIEPTSIZ register
  621. * @diepdma: Backup of DIEPDMA register
  622. * @doepctl: Backup of DOEPCTL register
  623. * @doeptsiz: Backup of DOEPTSIZ register
  624. * @doepdma: Backup of DOEPDMA register
  625. */
  626. struct dwc2_dregs_backup {
  627. u32 dcfg;
  628. u32 dctl;
  629. u32 daintmsk;
  630. u32 diepmsk;
  631. u32 doepmsk;
  632. u32 diepctl[MAX_EPS_CHANNELS];
  633. u32 dieptsiz[MAX_EPS_CHANNELS];
  634. u32 diepdma[MAX_EPS_CHANNELS];
  635. u32 doepctl[MAX_EPS_CHANNELS];
  636. u32 doeptsiz[MAX_EPS_CHANNELS];
  637. u32 doepdma[MAX_EPS_CHANNELS];
  638. bool valid;
  639. };
  640. /**
  641. * struct dwc2_hregs_backup - Holds host registers state before
  642. * entering partial power down
  643. * @hcfg: Backup of HCFG register
  644. * @haintmsk: Backup of HAINTMSK register
  645. * @hcintmsk: Backup of HCINTMSK register
  646. * @hptr0: Backup of HPTR0 register
  647. * @hfir: Backup of HFIR register
  648. */
  649. struct dwc2_hregs_backup {
  650. u32 hcfg;
  651. u32 haintmsk;
  652. u32 hcintmsk[MAX_EPS_CHANNELS];
  653. u32 hprt0;
  654. u32 hfir;
  655. bool valid;
  656. };
  657. /*
  658. * Constants related to high speed periodic scheduling
  659. *
  660. * We have a periodic schedule that is DWC2_HS_SCHEDULE_UFRAMES long. From a
  661. * reservation point of view it's assumed that the schedule goes right back to
  662. * the beginning after the end of the schedule.
  663. *
  664. * What does that mean for scheduling things with a long interval? It means
  665. * we'll reserve time for them in every possible microframe that they could
  666. * ever be scheduled in. ...but we'll still only actually schedule them as
  667. * often as they were requested.
  668. *
  669. * We keep our schedule in a "bitmap" structure. This simplifies having
  670. * to keep track of and merge intervals: we just let the bitmap code do most
  671. * of the heavy lifting. In a way scheduling is much like memory allocation.
  672. *
  673. * We schedule 100us per uframe or 80% of 125us (the maximum amount you're
  674. * supposed to schedule for periodic transfers). That's according to spec.
  675. *
  676. * Note that though we only schedule 80% of each microframe, the bitmap that we
  677. * keep the schedule in is tightly packed (AKA it doesn't have 100us worth of
  678. * space for each uFrame).
  679. *
  680. * Requirements:
  681. * - DWC2_HS_SCHEDULE_UFRAMES must even divide 0x4000 (HFNUM_MAX_FRNUM + 1)
  682. * - DWC2_HS_SCHEDULE_UFRAMES must be 8 times DWC2_LS_SCHEDULE_FRAMES (probably
  683. * could be any multiple of 8 times DWC2_LS_SCHEDULE_FRAMES, but there might
  684. * be bugs). The 8 comes from the USB spec: number of microframes per frame.
  685. */
  686. #define DWC2_US_PER_UFRAME 125
  687. #define DWC2_HS_PERIODIC_US_PER_UFRAME 100
  688. #define DWC2_HS_SCHEDULE_UFRAMES 8
  689. #define DWC2_HS_SCHEDULE_US (DWC2_HS_SCHEDULE_UFRAMES * \
  690. DWC2_HS_PERIODIC_US_PER_UFRAME)
  691. /*
  692. * Constants related to low speed scheduling
  693. *
  694. * For high speed we schedule every 1us. For low speed that's a bit overkill,
  695. * so we make up a unit called a "slice" that's worth 25us. There are 40
  696. * slices in a full frame and we can schedule 36 of those (90%) for periodic
  697. * transfers.
  698. *
  699. * Our low speed schedule can be as short as 1 frame or could be longer. When
  700. * we only schedule 1 frame it means that we'll need to reserve a time every
  701. * frame even for things that only transfer very rarely, so something that runs
  702. * every 2048 frames will get time reserved in every frame. Our low speed
  703. * schedule can be longer and we'll be able to handle more overlap, but that
  704. * will come at increased memory cost and increased time to schedule.
  705. *
  706. * Note: one other advantage of a short low speed schedule is that if we mess
  707. * up and miss scheduling we can jump in and use any of the slots that we
  708. * happened to reserve.
  709. *
  710. * With 25 us per slice and 1 frame in the schedule, we only need 4 bytes for
  711. * the schedule. There will be one schedule per TT.
  712. *
  713. * Requirements:
  714. * - DWC2_US_PER_SLICE must evenly divide DWC2_LS_PERIODIC_US_PER_FRAME.
  715. */
  716. #define DWC2_US_PER_SLICE 25
  717. #define DWC2_SLICES_PER_UFRAME (DWC2_US_PER_UFRAME / DWC2_US_PER_SLICE)
  718. #define DWC2_ROUND_US_TO_SLICE(us) \
  719. (DIV_ROUND_UP((us), DWC2_US_PER_SLICE) * \
  720. DWC2_US_PER_SLICE)
  721. #define DWC2_LS_PERIODIC_US_PER_FRAME \
  722. 900
  723. #define DWC2_LS_PERIODIC_SLICES_PER_FRAME \
  724. (DWC2_LS_PERIODIC_US_PER_FRAME / \
  725. DWC2_US_PER_SLICE)
  726. #define DWC2_LS_SCHEDULE_FRAMES 1
  727. #define DWC2_LS_SCHEDULE_SLICES (DWC2_LS_SCHEDULE_FRAMES * \
  728. DWC2_LS_PERIODIC_SLICES_PER_FRAME)
  729. /**
  730. * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
  731. * and periodic schedules
  732. *
  733. * These are common for both host and peripheral modes:
  734. *
  735. * @dev: The struct device pointer
  736. * @regs: Pointer to controller regs
  737. * @hw_params: Parameters that were autodetected from the
  738. * hardware registers
  739. * @core_params: Parameters that define how the core should be configured
  740. * @op_state: The operational State, during transitions (a_host=>
  741. * a_peripheral and b_device=>b_host) this may not match
  742. * the core, but allows the software to determine
  743. * transitions
  744. * @dr_mode: Requested mode of operation, one of following:
  745. * - USB_DR_MODE_PERIPHERAL
  746. * - USB_DR_MODE_HOST
  747. * - USB_DR_MODE_OTG
  748. * @hcd_enabled Host mode sub-driver initialization indicator.
  749. * @gadget_enabled Peripheral mode sub-driver initialization indicator.
  750. * @ll_hw_enabled Status of low-level hardware resources.
  751. * @phy: The otg phy transceiver structure for phy control.
  752. * @uphy: The otg phy transceiver structure for old USB phy
  753. * control.
  754. * @plat: The platform specific configuration data. This can be
  755. * removed once all SoCs support usb transceiver.
  756. * @supplies: Definition of USB power supplies
  757. * @phyif: PHY interface width
  758. * @lock: Spinlock that protects all the driver data structures
  759. * @priv: Stores a pointer to the struct usb_hcd
  760. * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
  761. * transfer are in process of being queued
  762. * @srp_success: Stores status of SRP request in the case of a FS PHY
  763. * with an I2C interface
  764. * @wq_otg: Workqueue object used for handling of some interrupts
  765. * @wf_otg: Work object for handling Connector ID Status Change
  766. * interrupt
  767. * @wkp_timer: Timer object for handling Wakeup Detected interrupt
  768. * @lx_state: Lx state of connected device
  769. * @gregs_backup: Backup of global registers during suspend
  770. * @dregs_backup: Backup of device registers during suspend
  771. * @hregs_backup: Backup of host registers during suspend
  772. *
  773. * These are for host mode:
  774. *
  775. * @flags: Flags for handling root port state changes
  776. * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
  777. * Transfers associated with these QHs are not currently
  778. * assigned to a host channel.
  779. * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
  780. * Transfers associated with these QHs are currently
  781. * assigned to a host channel.
  782. * @non_periodic_qh_ptr: Pointer to next QH to process in the active
  783. * non-periodic schedule
  784. * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
  785. * list of QHs for periodic transfers that are _not_
  786. * scheduled for the next frame. Each QH in the list has an
  787. * interval counter that determines when it needs to be
  788. * scheduled for execution. This scheduling mechanism
  789. * allows only a simple calculation for periodic bandwidth
  790. * used (i.e. must assume that all periodic transfers may
  791. * need to execute in the same frame). However, it greatly
  792. * simplifies scheduling and should be sufficient for the
  793. * vast majority of OTG hosts, which need to connect to a
  794. * small number of peripherals at one time. Items move from
  795. * this list to periodic_sched_ready when the QH interval
  796. * counter is 0 at SOF.
  797. * @periodic_sched_ready: List of periodic QHs that are ready for execution in
  798. * the next frame, but have not yet been assigned to host
  799. * channels. Items move from this list to
  800. * periodic_sched_assigned as host channels become
  801. * available during the current frame.
  802. * @periodic_sched_assigned: List of periodic QHs to be executed in the next
  803. * frame that are assigned to host channels. Items move
  804. * from this list to periodic_sched_queued as the
  805. * transactions for the QH are queued to the DWC_otg
  806. * controller.
  807. * @periodic_sched_queued: List of periodic QHs that have been queued for
  808. * execution. Items move from this list to either
  809. * periodic_sched_inactive or periodic_sched_ready when the
  810. * channel associated with the transfer is released. If the
  811. * interval for the QH is 1, the item moves to
  812. * periodic_sched_ready because it must be rescheduled for
  813. * the next frame. Otherwise, the item moves to
  814. * periodic_sched_inactive.
  815. * @split_order: List keeping track of channels doing splits, in order.
  816. * @periodic_usecs: Total bandwidth claimed so far for periodic transfers.
  817. * This value is in microseconds per (micro)frame. The
  818. * assumption is that all periodic transfers may occur in
  819. * the same (micro)frame.
  820. * @hs_periodic_bitmap: Bitmap used by the microframe scheduler any time the
  821. * host is in high speed mode; low speed schedules are
  822. * stored elsewhere since we need one per TT.
  823. * @frame_number: Frame number read from the core at SOF. The value ranges
  824. * from 0 to HFNUM_MAX_FRNUM.
  825. * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
  826. * SOF enable/disable.
  827. * @free_hc_list: Free host channels in the controller. This is a list of
  828. * struct dwc2_host_chan items.
  829. * @periodic_channels: Number of host channels assigned to periodic transfers.
  830. * Currently assuming that there is a dedicated host
  831. * channel for each periodic transaction and at least one
  832. * host channel is available for non-periodic transactions.
  833. * @non_periodic_channels: Number of host channels assigned to non-periodic
  834. * transfers
  835. * @available_host_channels Number of host channels available for the microframe
  836. * scheduler to use
  837. * @hc_ptr_array: Array of pointers to the host channel descriptors.
  838. * Allows accessing a host channel descriptor given the
  839. * host channel number. This is useful in interrupt
  840. * handlers.
  841. * @status_buf: Buffer used for data received during the status phase of
  842. * a control transfer.
  843. * @status_buf_dma: DMA address for status_buf
  844. * @start_work: Delayed work for handling host A-cable connection
  845. * @reset_work: Delayed work for handling a port reset
  846. * @otg_port: OTG port number
  847. * @frame_list: Frame list
  848. * @frame_list_dma: Frame list DMA address
  849. * @frame_list_sz: Frame list size
  850. * @desc_gen_cache: Kmem cache for generic descriptors
  851. * @desc_hsisoc_cache: Kmem cache for hs isochronous descriptors
  852. * @unaligned_cache: Kmem cache for DMA mode to handle non-aligned buf
  853. *
  854. * These are for peripheral mode:
  855. *
  856. * @driver: USB gadget driver
  857. * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
  858. * @num_of_eps: Number of available EPs (excluding EP0)
  859. * @debug_root: Root directrory for debugfs.
  860. * @debug_file: Main status file for debugfs.
  861. * @debug_testmode: Testmode status file for debugfs.
  862. * @debug_fifo: FIFO status file for debugfs.
  863. * @ep0_reply: Request used for ep0 reply.
  864. * @ep0_buff: Buffer for EP0 reply data, if needed.
  865. * @ctrl_buff: Buffer for EP0 control requests.
  866. * @ctrl_req: Request for EP0 control packets.
  867. * @ep0_state: EP0 control transfers state
  868. * @test_mode: USB test mode requested by the host
  869. * @setup_desc_dma: EP0 setup stage desc chain DMA address
  870. * @setup_desc: EP0 setup stage desc chain pointer
  871. * @ctrl_in_desc_dma: EP0 IN data phase desc chain DMA address
  872. * @ctrl_in_desc: EP0 IN data phase desc chain pointer
  873. * @ctrl_out_desc_dma: EP0 OUT data phase desc chain DMA address
  874. * @ctrl_out_desc: EP0 OUT data phase desc chain pointer
  875. * @eps: The endpoints being supplied to the gadget framework
  876. */
  877. struct wq_msg
  878. {
  879. char id;
  880. int delay;//ms
  881. //char data[20];
  882. };
  883. #define OTG_WQ_MSG_RESET 0
  884. #define OTG_WQ_MSG_START 1
  885. #define OTG_WQ_MSG_ID_STATE_CHANGE 2
  886. #define OTG_WQ_MSG_ID_DEV_RESET 3
  887. #define OTG_WQ_MSG_ID_HOST_RESET 4
  888. #define OTG_WQ_MSG_DEV 5
  889. struct dwc2_hsotg {
  890. struct device *dev;
  891. #ifndef NO_GNU
  892. void __iomem *regs;
  893. #else
  894. u32 regs; //addr
  895. #endif
  896. /** Params detected from hardware */
  897. struct dwc2_hw_params hw_params;
  898. /** Params to actually use */
  899. struct dwc2_core_params params;
  900. enum usb_otg_state op_state;
  901. enum usb_dr_mode dr_mode;
  902. unsigned int hcd_enabled:1;
  903. unsigned int gadget_enabled:1;
  904. unsigned int ll_hw_enabled:1;
  905. u32 phyif;
  906. TimerHandle_t enumtimer;
  907. int enumtimer_start;
  908. spinlock_t lock;
  909. void *priv;
  910. int irq;
  911. struct clk *clk;
  912. struct reset_control *reset;
  913. unsigned int queuing_high_bandwidth:1;
  914. unsigned int srp_success:1;
  915. QueueHandle_t wq_otg;
  916. TaskHandle_t wq_otg_task;
  917. struct wq_msg xmsg;
  918. struct work_struct wf_otg;
  919. struct timer_list wkp_timer;
  920. enum dwc2_lx_state lx_state;
  921. struct dwc2_gregs_backup gr_backup;
  922. struct dwc2_dregs_backup dr_backup;
  923. struct dwc2_hregs_backup hr_backup;
  924. /* DWC OTG HW Release versions */
  925. #define DWC2_CORE_REV_2_71a 0x4f54271a
  926. #define DWC2_CORE_REV_2_90a 0x4f54290a
  927. #define DWC2_CORE_REV_2_91a 0x4f54291a
  928. #define DWC2_CORE_REV_2_92a 0x4f54292a
  929. #define DWC2_CORE_REV_2_94a 0x4f54294a
  930. #define DWC2_CORE_REV_3_00a 0x4f54300a
  931. #define DWC2_CORE_REV_3_10a 0x4f54310a
  932. #define DWC2_FS_IOT_REV_1_00a 0x5531100a
  933. #define DWC2_HS_IOT_REV_1_00a 0x5532100a
  934. #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) || IS_ENABLED(CONFIG_USB_NEW_DWC2_HOST)
  935. union dwc2_hcd_internal_flags {
  936. u32 d32;
  937. struct {
  938. unsigned port_connect_status_change:1;
  939. unsigned port_connect_status:1;
  940. unsigned port_reset_change:1;
  941. unsigned port_enable_change:1;
  942. unsigned port_suspend_change:1;
  943. unsigned port_over_current_change:1;
  944. unsigned port_l1_change:1;
  945. unsigned reserved:25;
  946. } b;
  947. } flags;
  948. #ifndef NO_GNU
  949. struct list_head non_periodic_sched_inactive;
  950. struct list_head non_periodic_sched_active;
  951. struct list_head *non_periodic_qh_ptr;
  952. struct list_head periodic_sched_inactive;
  953. struct list_head periodic_sched_ready;
  954. struct list_head periodic_sched_assigned;
  955. struct list_head periodic_sched_queued;
  956. struct list_head split_order;
  957. #else
  958. List_t non_periodic_sched_inactive;
  959. List_t non_periodic_sched_active;
  960. ListItem_t *non_periodic_qh_ptr;
  961. List_t periodic_sched_inactive;
  962. List_t periodic_sched_ready;
  963. List_t periodic_sched_assigned;
  964. List_t periodic_sched_queued;
  965. List_t split_order;
  966. #endif
  967. u16 periodic_usecs;
  968. unsigned long hs_periodic_bitmap[
  969. DIV_ROUND_UP(DWC2_HS_SCHEDULE_US, BITS_PER_LONG)];
  970. u16 frame_number;
  971. u16 periodic_qh_count;
  972. bool bus_suspended;
  973. bool new_connection;
  974. u16 last_frame_num;
  975. #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
  976. #define FRAME_NUM_ARRAY_SIZE 1000
  977. u16 *frame_num_array;
  978. u16 *last_frame_num_array;
  979. int frame_num_idx;
  980. int dumped_frame_num_array;
  981. #endif
  982. #ifndef NO_GNU
  983. struct list_head free_hc_list;
  984. #else
  985. List_t free_hc_list;
  986. List_t free_qtd_list;
  987. List_t free_urb_list;
  988. #endif
  989. int periodic_channels;
  990. int non_periodic_channels;
  991. int available_host_channels;
  992. struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
  993. u8 *status_buf;
  994. dma_addr_t status_buf_dma;
  995. #ifdef NO_GNU
  996. u32 status_offset;
  997. #endif
  998. #define DWC2_HCD_STATUS_BUF_SIZE 6
  999. u8 otg_port;
  1000. u32 *frame_list;
  1001. dma_addr_t frame_list_dma;
  1002. u32 frame_list_sz;
  1003. struct kmem_cache *desc_gen_cache;
  1004. struct kmem_cache *desc_hsisoc_cache;
  1005. struct kmem_cache *unaligned_cache;
  1006. #define DWC2_KMEM_UNALIGNED_BUF_SIZE 1024
  1007. #ifdef DEBUG
  1008. u32 frrem_samples;
  1009. u64 frrem_accum;
  1010. u32 hfnum_7_samples_a;
  1011. u64 hfnum_7_frrem_accum_a;
  1012. u32 hfnum_0_samples_a;
  1013. u64 hfnum_0_frrem_accum_a;
  1014. u32 hfnum_other_samples_a;
  1015. u64 hfnum_other_frrem_accum_a;
  1016. u32 hfnum_7_samples_b;
  1017. u64 hfnum_7_frrem_accum_b;
  1018. u32 hfnum_0_samples_b;
  1019. u64 hfnum_0_frrem_accum_b;
  1020. u32 hfnum_other_samples_b;
  1021. u64 hfnum_other_frrem_accum_b;
  1022. #endif
  1023. #endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
  1024. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
  1025. IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) || \
  1026. IS_ENABLED(CONFIG_USB_NEW_DWC2_GADGET)
  1027. /* Gadget structures */
  1028. struct usb_gadget_driver *driver;
  1029. int fifo_mem;
  1030. unsigned int dedicated_fifos:1;
  1031. unsigned char num_of_eps;
  1032. u32 fifo_map;
  1033. struct usb_request *ep0_reply;
  1034. struct usb_request *ctrl_req;
  1035. void *ep0_buff;
  1036. void *ctrl_buff;
  1037. enum dwc2_ep0_state ep0_state;
  1038. u8 test_mode;
  1039. dma_addr_t setup_desc_dma[2];
  1040. struct dwc2_dma_desc *setup_desc[2];
  1041. dma_addr_t ctrl_in_desc_dma;
  1042. struct dwc2_dma_desc *ctrl_in_desc;
  1043. dma_addr_t ctrl_out_desc_dma;
  1044. struct dwc2_dma_desc *ctrl_out_desc;
  1045. #ifdef NO_GNU
  1046. u32 setup_desc_dma_offset[2];
  1047. u32 ctrl_in_desc_offset;
  1048. u32 ctrl_out_desc_offset;
  1049. #endif
  1050. struct usb_gadget gadget;
  1051. unsigned int enabled:1;
  1052. unsigned int connected:1;
  1053. struct dwc2_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
  1054. struct dwc2_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
  1055. #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
  1056. };
  1057. /* Reasons for halting a host channel */
  1058. enum dwc2_halt_status {
  1059. DWC2_HC_XFER_NO_HALT_STATUS,
  1060. DWC2_HC_XFER_COMPLETE,
  1061. DWC2_HC_XFER_URB_COMPLETE,
  1062. DWC2_HC_XFER_ACK,
  1063. DWC2_HC_XFER_NAK,
  1064. DWC2_HC_XFER_NYET,
  1065. DWC2_HC_XFER_STALL,
  1066. DWC2_HC_XFER_XACT_ERR,
  1067. DWC2_HC_XFER_FRAME_OVERRUN,
  1068. DWC2_HC_XFER_BABBLE_ERR,
  1069. DWC2_HC_XFER_DATA_TOGGLE_ERR,
  1070. DWC2_HC_XFER_AHB_ERR,
  1071. DWC2_HC_XFER_PERIODIC_INCOMPLETE,
  1072. DWC2_HC_XFER_URB_DEQUEUE,
  1073. };
  1074. /* Core version information */
  1075. static inline bool dwc2_is_iot(struct dwc2_hsotg *hsotg)
  1076. {
  1077. return (hsotg->hw_params.snpsid & 0xfff00000) == 0x55300000;
  1078. }
  1079. static inline bool dwc2_is_fs_iot(struct dwc2_hsotg *hsotg)
  1080. {
  1081. return (hsotg->hw_params.snpsid & 0xffff0000) == 0x55310000;
  1082. }
  1083. static inline bool dwc2_is_hs_iot(struct dwc2_hsotg *hsotg)
  1084. {
  1085. return (hsotg->hw_params.snpsid & 0xffff0000) == 0x55320000;
  1086. }
  1087. /*
  1088. * The following functions support initialization of the core driver component
  1089. * and the DWC_otg controller
  1090. */
  1091. int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait);
  1092. int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg);
  1093. int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
  1094. int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
  1095. bool dwc2_force_mode_if_needed(struct dwc2_hsotg *hsotg, bool host);
  1096. void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg);
  1097. void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg);
  1098. bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
  1099. /*
  1100. * Common core Functions.
  1101. * The following functions support managing the DWC_otg controller in either
  1102. * device or host mode.
  1103. */
  1104. void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
  1105. void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
  1106. void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
  1107. void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
  1108. void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
  1109. /* This function should be called on every hardware interrupt. */
  1110. irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
  1111. int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg);
  1112. int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);
  1113. /* Parameters */
  1114. int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
  1115. int dwc2_init_params(struct dwc2_hsotg *hsotg);
  1116. /*
  1117. * The following functions check the controller's OTG operation mode
  1118. * capability (GHWCFG2.OTG_MODE).
  1119. *
  1120. * These functions can be used before the internal hsotg->hw_params
  1121. * are read in and cached so they always read directly from the
  1122. * GHWCFG2 register.
  1123. */
  1124. unsigned int dwc2_op_mode(struct dwc2_hsotg *hsotg);
  1125. bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg);
  1126. bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg);
  1127. bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg);
  1128. /*
  1129. * Returns the mode of operation, host or device
  1130. */
  1131. static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg)
  1132. {
  1133. return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) != 0;
  1134. }
  1135. static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg)
  1136. {
  1137. return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) == 0;
  1138. }
  1139. /*
  1140. * Dump core registers and SPRAM
  1141. */
  1142. void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
  1143. void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
  1144. void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
  1145. /* Gadget defines */
  1146. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
  1147. IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) || \
  1148. IS_ENABLED(CONFIG_USB_NEW_DWC2_GADGET)
  1149. int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg);
  1150. int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2);
  1151. int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2);
  1152. int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq);
  1153. void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
  1154. bool reset);
  1155. void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg);
  1156. void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2);
  1157. int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
  1158. #define dwc2_is_device_connected(hsotg) (hsotg->connected)
  1159. int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg);
  1160. int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg);
  1161. int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg);
  1162. int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg);
  1163. int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg);
  1164. #else
  1165. static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2)
  1166. { return 0; }
  1167. static inline int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2)
  1168. { return 0; }
  1169. static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2)
  1170. { return 0; }
  1171. static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
  1172. { return 0; }
  1173. static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
  1174. bool reset) {}
  1175. static inline void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
  1176. static inline void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
  1177. static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
  1178. int testmode)
  1179. { return 0; }
  1180. #define dwc2_is_device_connected(hsotg) (0)
  1181. static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
  1182. { return 0; }
  1183. static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg)
  1184. { return 0; }
  1185. static inline int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
  1186. { return 0; }
  1187. static inline int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
  1188. { return 0; }
  1189. static inline int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg)
  1190. { return 0; }
  1191. #endif
  1192. #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) || IS_ENABLED(CONFIG_USB_NEW_DWC2_HOST)
  1193. int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
  1194. int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us);
  1195. void dwc2_hcd_connect(struct dwc2_hsotg *hsotg);
  1196. void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force);
  1197. void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
  1198. int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg);
  1199. int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg);
  1200. #else
  1201. static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
  1202. { return 0; }
  1203. static inline int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg,
  1204. int us)
  1205. { return 0; }
  1206. static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {}
  1207. static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {}
  1208. static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
  1209. static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
  1210. static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, struct usb_hcd *hcd)
  1211. { return 0; }
  1212. static inline int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
  1213. { return 0; }
  1214. static inline int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
  1215. { return 0; }
  1216. #endif
  1217. #endif /* __DWC2_CORE_H__ */