core.h 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  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 <linux/phy/phy.h>
  39. #include <linux/regulator/consumer.h>
  40. #include <linux/usb/gadget.h>
  41. #include <linux/usb/otg.h>
  42. #include <linux/usb/phy.h>
  43. #include "hw.h"
  44. static inline u32 dwc2_readl(const void __iomem *addr)
  45. {
  46. u32 value = __raw_readl(addr);
  47. /* In order to preserve endianness __raw_* operation is used. Therefore
  48. * a barrier is needed to ensure IO access is not re-ordered across
  49. * reads or writes
  50. */
  51. mb();
  52. return value;
  53. }
  54. static inline void dwc2_writel(u32 value, void __iomem *addr)
  55. {
  56. __raw_writel(value, addr);
  57. /*
  58. * In order to preserve endianness __raw_* operation is used. Therefore
  59. * a barrier is needed to ensure IO access is not re-ordered across
  60. * reads or writes
  61. */
  62. mb();
  63. #ifdef DWC2_LOG_WRITES
  64. pr_info("INFO:: wrote %08x to %p\n", value, addr);
  65. #endif
  66. }
  67. /* Maximum number of Endpoints/HostChannels */
  68. #define MAX_EPS_CHANNELS 16
  69. /* dwc2-hsotg declarations */
  70. static const char * const dwc2_hsotg_supply_names[] = {
  71. "vusb_d", /* digital USB supply, 1.2V */
  72. "vusb_a", /* analog USB supply, 1.1V */
  73. };
  74. /*
  75. * EP0_MPS_LIMIT
  76. *
  77. * Unfortunately there seems to be a limit of the amount of data that can
  78. * be transferred by IN transactions on EP0. This is either 127 bytes or 3
  79. * packets (which practically means 1 packet and 63 bytes of data) when the
  80. * MPS is set to 64.
  81. *
  82. * This means if we are wanting to move >127 bytes of data, we need to
  83. * split the transactions up, but just doing one packet at a time does
  84. * not work (this may be an implicit DATA0 PID on first packet of the
  85. * transaction) and doing 2 packets is outside the controller's limits.
  86. *
  87. * If we try to lower the MPS size for EP0, then no transfers work properly
  88. * for EP0, and the system will fail basic enumeration. As no cause for this
  89. * has currently been found, we cannot support any large IN transfers for
  90. * EP0.
  91. */
  92. #define EP0_MPS_LIMIT 64
  93. struct dwc2_hsotg;
  94. struct dwc2_hsotg_req;
  95. /**
  96. * struct dwc2_hsotg_ep - driver endpoint definition.
  97. * @ep: The gadget layer representation of the endpoint.
  98. * @name: The driver generated name for the endpoint.
  99. * @queue: Queue of requests for this endpoint.
  100. * @parent: Reference back to the parent device structure.
  101. * @req: The current request that the endpoint is processing. This is
  102. * used to indicate an request has been loaded onto the endpoint
  103. * and has yet to be completed (maybe due to data move, or simply
  104. * awaiting an ack from the core all the data has been completed).
  105. * @debugfs: File entry for debugfs file for this endpoint.
  106. * @lock: State lock to protect contents of endpoint.
  107. * @dir_in: Set to true if this endpoint is of the IN direction, which
  108. * means that it is sending data to the Host.
  109. * @index: The index for the endpoint registers.
  110. * @mc: Multi Count - number of transactions per microframe
  111. * @interval - Interval for periodic endpoints
  112. * @name: The name array passed to the USB core.
  113. * @halted: Set if the endpoint has been halted.
  114. * @periodic: Set if this is a periodic ep, such as Interrupt
  115. * @isochronous: Set if this is a isochronous ep
  116. * @send_zlp: Set if we need to send a zero-length packet.
  117. * @total_data: The total number of data bytes done.
  118. * @fifo_size: The size of the FIFO (for periodic IN endpoints)
  119. * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
  120. * @last_load: The offset of data for the last start of request.
  121. * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
  122. *
  123. * This is the driver's state for each registered enpoint, allowing it
  124. * to keep track of transactions that need doing. Each endpoint has a
  125. * lock to protect the state, to try and avoid using an overall lock
  126. * for the host controller as much as possible.
  127. *
  128. * For periodic IN endpoints, we have fifo_size and fifo_load to try
  129. * and keep track of the amount of data in the periodic FIFO for each
  130. * of these as we don't have a status register that tells us how much
  131. * is in each of them. (note, this may actually be useless information
  132. * as in shared-fifo mode periodic in acts like a single-frame packet
  133. * buffer than a fifo)
  134. */
  135. struct dwc2_hsotg_ep {
  136. struct usb_ep ep;
  137. struct list_head queue;
  138. struct dwc2_hsotg *parent;
  139. struct dwc2_hsotg_req *req;
  140. struct dentry *debugfs;
  141. unsigned long total_data;
  142. unsigned int size_loaded;
  143. unsigned int last_load;
  144. unsigned int fifo_load;
  145. unsigned short fifo_size;
  146. unsigned short fifo_index;
  147. unsigned char dir_in;
  148. unsigned char index;
  149. unsigned char mc;
  150. unsigned char interval;
  151. unsigned int halted:1;
  152. unsigned int periodic:1;
  153. unsigned int isochronous:1;
  154. unsigned int send_zlp:1;
  155. unsigned int has_correct_parity:1;
  156. char name[10];
  157. };
  158. /**
  159. * struct dwc2_hsotg_req - data transfer request
  160. * @req: The USB gadget request
  161. * @queue: The list of requests for the endpoint this is queued for.
  162. * @saved_req_buf: variable to save req.buf when bounce buffers are used.
  163. */
  164. struct dwc2_hsotg_req {
  165. struct usb_request req;
  166. struct list_head queue;
  167. void *saved_req_buf;
  168. };
  169. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  170. #define call_gadget(_hs, _entry) \
  171. do { \
  172. if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
  173. (_hs)->driver && (_hs)->driver->_entry) { \
  174. spin_unlock(&_hs->lock); \
  175. (_hs)->driver->_entry(&(_hs)->gadget); \
  176. spin_lock(&_hs->lock); \
  177. } \
  178. } while (0)
  179. #else
  180. #define call_gadget(_hs, _entry) do {} while (0)
  181. #endif
  182. struct dwc2_hsotg;
  183. struct dwc2_host_chan;
  184. /* Device States */
  185. enum dwc2_lx_state {
  186. DWC2_L0, /* On state */
  187. DWC2_L1, /* LPM sleep state */
  188. DWC2_L2, /* USB suspend state */
  189. DWC2_L3, /* Off state */
  190. };
  191. /*
  192. * Gadget periodic tx fifo sizes as used by legacy driver
  193. * EP0 is not included
  194. */
  195. #define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 256, 256, 256, 768, 768, 768, \
  196. 768, 0, 0, 0, 0, 0, 0, 0}
  197. /* Gadget ep0 states */
  198. enum dwc2_ep0_state {
  199. DWC2_EP0_SETUP,
  200. DWC2_EP0_DATA_IN,
  201. DWC2_EP0_DATA_OUT,
  202. DWC2_EP0_STATUS_IN,
  203. DWC2_EP0_STATUS_OUT,
  204. };
  205. /**
  206. * struct dwc2_core_params - Parameters for configuring the core
  207. *
  208. * @otg_cap: Specifies the OTG capabilities.
  209. * 0 - HNP and SRP capable
  210. * 1 - SRP Only capable
  211. * 2 - No HNP/SRP capable (always available)
  212. * Defaults to best available option (0, 1, then 2)
  213. * @otg_ver: OTG version supported
  214. * 0 - 1.3 (default)
  215. * 1 - 2.0
  216. * @dma_enable: Specifies whether to use slave or DMA mode for accessing
  217. * the data FIFOs. The driver will automatically detect the
  218. * value for this parameter if none is specified.
  219. * 0 - Slave (always available)
  220. * 1 - DMA (default, if available)
  221. * @dma_desc_enable: When DMA mode is enabled, specifies whether to use
  222. * address DMA mode or descriptor DMA mode for accessing
  223. * the data FIFOs. The driver will automatically detect the
  224. * value for this if none is specified.
  225. * 0 - Address DMA
  226. * 1 - Descriptor DMA (default, if available)
  227. * @dma_desc_fs_enable: When DMA mode is enabled, specifies whether to use
  228. * address DMA mode or descriptor DMA mode for accessing
  229. * the data FIFOs in Full Speed mode only. The driver
  230. * will automatically detect the value for this if none is
  231. * specified.
  232. * 0 - Address DMA
  233. * 1 - Descriptor DMA in FS (default, if available)
  234. * @speed: Specifies the maximum speed of operation in host and
  235. * device mode. The actual speed depends on the speed of
  236. * the attached device and the value of phy_type.
  237. * 0 - High Speed
  238. * (default when phy_type is UTMI+ or ULPI)
  239. * 1 - Full Speed
  240. * (default when phy_type is Full Speed)
  241. * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
  242. * 1 - Allow dynamic FIFO sizing (default, if available)
  243. * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
  244. * are enabled
  245. * @host_rx_fifo_size: Number of 4-byte words in the Rx FIFO in host mode when
  246. * dynamic FIFO sizing is enabled
  247. * 16 to 32768
  248. * Actual maximum value is autodetected and also
  249. * the default.
  250. * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
  251. * in host mode when dynamic FIFO sizing is enabled
  252. * 16 to 32768
  253. * Actual maximum value is autodetected and also
  254. * the default.
  255. * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
  256. * host mode when dynamic FIFO sizing is enabled
  257. * 16 to 32768
  258. * Actual maximum value is autodetected and also
  259. * the default.
  260. * @max_transfer_size: The maximum transfer size supported, in bytes
  261. * 2047 to 65,535
  262. * Actual maximum value is autodetected and also
  263. * the default.
  264. * @max_packet_count: The maximum number of packets in a transfer
  265. * 15 to 511
  266. * Actual maximum value is autodetected and also
  267. * the default.
  268. * @host_channels: The number of host channel registers to use
  269. * 1 to 16
  270. * Actual maximum value is autodetected and also
  271. * the default.
  272. * @phy_type: Specifies the type of PHY interface to use. By default,
  273. * the driver will automatically detect the phy_type.
  274. * 0 - Full Speed Phy
  275. * 1 - UTMI+ Phy
  276. * 2 - ULPI Phy
  277. * Defaults to best available option (2, 1, then 0)
  278. * @phy_utmi_width: Specifies the UTMI+ Data Width (in bits). This parameter
  279. * is applicable for a phy_type of UTMI+ or ULPI. (For a
  280. * ULPI phy_type, this parameter indicates the data width
  281. * between the MAC and the ULPI Wrapper.) Also, this
  282. * parameter is applicable only if the OTG_HSPHY_WIDTH cC
  283. * parameter was set to "8 and 16 bits", meaning that the
  284. * core has been configured to work at either data path
  285. * width.
  286. * 8 or 16 (default 16 if available)
  287. * @phy_ulpi_ddr: Specifies whether the ULPI operates at double or single
  288. * data rate. This parameter is only applicable if phy_type
  289. * is ULPI.
  290. * 0 - single data rate ULPI interface with 8 bit wide
  291. * data bus (default)
  292. * 1 - double data rate ULPI interface with 4 bit wide
  293. * data bus
  294. * @phy_ulpi_ext_vbus: For a ULPI phy, specifies whether to use the internal or
  295. * external supply to drive the VBus
  296. * 0 - Internal supply (default)
  297. * 1 - External supply
  298. * @i2c_enable: Specifies whether to use the I2Cinterface for a full
  299. * speed PHY. This parameter is only applicable if phy_type
  300. * is FS.
  301. * 0 - No (default)
  302. * 1 - Yes
  303. * @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
  304. * 0 - No (default)
  305. * 1 - Yes
  306. * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
  307. * when attached to a Full Speed or Low Speed device in
  308. * host mode.
  309. * 0 - Don't support low power mode (default)
  310. * 1 - Support low power mode
  311. * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
  312. * when connected to a Low Speed device in host
  313. * mode. This parameter is applicable only if
  314. * host_support_fs_ls_low_power is enabled.
  315. * 0 - 48 MHz
  316. * (default when phy_type is UTMI+ or ULPI)
  317. * 1 - 6 MHz
  318. * (default when phy_type is Full Speed)
  319. * @ts_dline: Enable Term Select Dline pulsing
  320. * 0 - No (default)
  321. * 1 - Yes
  322. * @reload_ctl: Allow dynamic reloading of HFIR register during runtime
  323. * 0 - No (default for core < 2.92a)
  324. * 1 - Yes (default for core >= 2.92a)
  325. * @ahbcfg: This field allows the default value of the GAHBCFG
  326. * register to be overridden
  327. * -1 - GAHBCFG value will be set to 0x06
  328. * (INCR4, default)
  329. * all others - GAHBCFG value will be overridden with
  330. * this value
  331. * Not all bits can be controlled like this, the
  332. * bits defined by GAHBCFG_CTRL_MASK are controlled
  333. * by the driver and are ignored in this
  334. * configuration value.
  335. * @uframe_sched: True to enable the microframe scheduler
  336. * @external_id_pin_ctl: Specifies whether ID pin is handled externally.
  337. * Disable CONIDSTSCHNG controller interrupt in such
  338. * case.
  339. * 0 - No (default)
  340. * 1 - Yes
  341. * @hibernation: Specifies whether the controller support hibernation.
  342. * If hibernation is enabled, the controller will enter
  343. * hibernation in both peripheral and host mode when
  344. * needed.
  345. * 0 - No (default)
  346. * 1 - Yes
  347. *
  348. * The following parameters may be specified when starting the module. These
  349. * parameters define how the DWC_otg controller should be configured. A
  350. * value of -1 (or any other out of range value) for any parameter means
  351. * to read the value from hardware (if possible) or use the builtin
  352. * default described above.
  353. */
  354. struct dwc2_core_params {
  355. /*
  356. * Don't add any non-int members here, this will break
  357. * dwc2_set_all_params!
  358. */
  359. int otg_cap;
  360. int otg_ver;
  361. int dma_enable;
  362. int dma_desc_enable;
  363. int dma_desc_fs_enable;
  364. int speed;
  365. int enable_dynamic_fifo;
  366. int en_multiple_tx_fifo;
  367. int host_rx_fifo_size;
  368. int host_nperio_tx_fifo_size;
  369. int host_perio_tx_fifo_size;
  370. int max_transfer_size;
  371. int max_packet_count;
  372. int host_channels;
  373. int phy_type;
  374. int phy_utmi_width;
  375. int phy_ulpi_ddr;
  376. int phy_ulpi_ext_vbus;
  377. int i2c_enable;
  378. int ulpi_fs_ls;
  379. int host_support_fs_ls_low_power;
  380. int host_ls_low_power_phy_clk;
  381. int ts_dline;
  382. int reload_ctl;
  383. int ahbcfg;
  384. int uframe_sched;
  385. int external_id_pin_ctl;
  386. int hibernation;
  387. };
  388. /**
  389. * struct dwc2_hw_params - Autodetected parameters.
  390. *
  391. * These parameters are the various parameters read from hardware
  392. * registers during initialization. They typically contain the best
  393. * supported or maximum value that can be configured in the
  394. * corresponding dwc2_core_params value.
  395. *
  396. * The values that are not in dwc2_core_params are documented below.
  397. *
  398. * @op_mode Mode of Operation
  399. * 0 - HNP- and SRP-Capable OTG (Host & Device)
  400. * 1 - SRP-Capable OTG (Host & Device)
  401. * 2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
  402. * 3 - SRP-Capable Device
  403. * 4 - Non-OTG Device
  404. * 5 - SRP-Capable Host
  405. * 6 - Non-OTG Host
  406. * @arch Architecture
  407. * 0 - Slave only
  408. * 1 - External DMA
  409. * 2 - Internal DMA
  410. * @power_optimized Are power optimizations enabled?
  411. * @num_dev_ep Number of device endpoints available
  412. * @num_dev_perio_in_ep Number of device periodic IN endpoints
  413. * available
  414. * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
  415. * Depth
  416. * 0 to 30
  417. * @host_perio_tx_q_depth
  418. * Host Mode Periodic Request Queue Depth
  419. * 2, 4 or 8
  420. * @nperio_tx_q_depth
  421. * Non-Periodic Request Queue Depth
  422. * 2, 4 or 8
  423. * @hs_phy_type High-speed PHY interface type
  424. * 0 - High-speed interface not supported
  425. * 1 - UTMI+
  426. * 2 - ULPI
  427. * 3 - UTMI+ and ULPI
  428. * @fs_phy_type Full-speed PHY interface type
  429. * 0 - Full speed interface not supported
  430. * 1 - Dedicated full speed interface
  431. * 2 - FS pins shared with UTMI+ pins
  432. * 3 - FS pins shared with ULPI pins
  433. * @total_fifo_size: Total internal RAM for FIFOs (bytes)
  434. * @utmi_phy_data_width UTMI+ PHY data width
  435. * 0 - 8 bits
  436. * 1 - 16 bits
  437. * 2 - 8 or 16 bits
  438. * @snpsid: Value from SNPSID register
  439. */
  440. struct dwc2_hw_params {
  441. unsigned op_mode:3;
  442. unsigned arch:2;
  443. unsigned dma_desc_enable:1;
  444. unsigned dma_desc_fs_enable:1;
  445. unsigned enable_dynamic_fifo:1;
  446. unsigned en_multiple_tx_fifo:1;
  447. unsigned host_rx_fifo_size:16;
  448. unsigned host_nperio_tx_fifo_size:16;
  449. unsigned host_perio_tx_fifo_size:16;
  450. unsigned nperio_tx_q_depth:3;
  451. unsigned host_perio_tx_q_depth:3;
  452. unsigned dev_token_q_depth:5;
  453. unsigned max_transfer_size:26;
  454. unsigned max_packet_count:11;
  455. unsigned host_channels:5;
  456. unsigned hs_phy_type:2;
  457. unsigned fs_phy_type:2;
  458. unsigned i2c_enable:1;
  459. unsigned num_dev_ep:4;
  460. unsigned num_dev_perio_in_ep:4;
  461. unsigned total_fifo_size:16;
  462. unsigned power_optimized:1;
  463. unsigned utmi_phy_data_width:2;
  464. u32 snpsid;
  465. };
  466. /* Size of control and EP0 buffers */
  467. #define DWC2_CTRL_BUFF_SIZE 8
  468. /**
  469. * struct dwc2_gregs_backup - Holds global registers state before entering partial
  470. * power down
  471. * @gotgctl: Backup of GOTGCTL register
  472. * @gintmsk: Backup of GINTMSK register
  473. * @gahbcfg: Backup of GAHBCFG register
  474. * @gusbcfg: Backup of GUSBCFG register
  475. * @grxfsiz: Backup of GRXFSIZ register
  476. * @gnptxfsiz: Backup of GNPTXFSIZ register
  477. * @gi2cctl: Backup of GI2CCTL register
  478. * @hptxfsiz: Backup of HPTXFSIZ register
  479. * @gdfifocfg: Backup of GDFIFOCFG register
  480. * @dtxfsiz: Backup of DTXFSIZ registers for each endpoint
  481. * @gpwrdn: Backup of GPWRDN register
  482. */
  483. struct dwc2_gregs_backup {
  484. u32 gotgctl;
  485. u32 gintmsk;
  486. u32 gahbcfg;
  487. u32 gusbcfg;
  488. u32 grxfsiz;
  489. u32 gnptxfsiz;
  490. u32 gi2cctl;
  491. u32 hptxfsiz;
  492. u32 pcgcctl;
  493. u32 gdfifocfg;
  494. u32 dtxfsiz[MAX_EPS_CHANNELS];
  495. u32 gpwrdn;
  496. bool valid;
  497. };
  498. /**
  499. * struct dwc2_dregs_backup - Holds device registers state before entering partial
  500. * power down
  501. * @dcfg: Backup of DCFG register
  502. * @dctl: Backup of DCTL register
  503. * @daintmsk: Backup of DAINTMSK register
  504. * @diepmsk: Backup of DIEPMSK register
  505. * @doepmsk: Backup of DOEPMSK register
  506. * @diepctl: Backup of DIEPCTL register
  507. * @dieptsiz: Backup of DIEPTSIZ register
  508. * @diepdma: Backup of DIEPDMA register
  509. * @doepctl: Backup of DOEPCTL register
  510. * @doeptsiz: Backup of DOEPTSIZ register
  511. * @doepdma: Backup of DOEPDMA register
  512. */
  513. struct dwc2_dregs_backup {
  514. u32 dcfg;
  515. u32 dctl;
  516. u32 daintmsk;
  517. u32 diepmsk;
  518. u32 doepmsk;
  519. u32 diepctl[MAX_EPS_CHANNELS];
  520. u32 dieptsiz[MAX_EPS_CHANNELS];
  521. u32 diepdma[MAX_EPS_CHANNELS];
  522. u32 doepctl[MAX_EPS_CHANNELS];
  523. u32 doeptsiz[MAX_EPS_CHANNELS];
  524. u32 doepdma[MAX_EPS_CHANNELS];
  525. bool valid;
  526. };
  527. /**
  528. * struct dwc2_hregs_backup - Holds host registers state before entering partial
  529. * power down
  530. * @hcfg: Backup of HCFG register
  531. * @haintmsk: Backup of HAINTMSK register
  532. * @hcintmsk: Backup of HCINTMSK register
  533. * @hptr0: Backup of HPTR0 register
  534. * @hfir: Backup of HFIR register
  535. */
  536. struct dwc2_hregs_backup {
  537. u32 hcfg;
  538. u32 haintmsk;
  539. u32 hcintmsk[MAX_EPS_CHANNELS];
  540. u32 hprt0;
  541. u32 hfir;
  542. bool valid;
  543. };
  544. /**
  545. * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
  546. * and periodic schedules
  547. *
  548. * These are common for both host and peripheral modes:
  549. *
  550. * @dev: The struct device pointer
  551. * @regs: Pointer to controller regs
  552. * @hw_params: Parameters that were autodetected from the
  553. * hardware registers
  554. * @core_params: Parameters that define how the core should be configured
  555. * @op_state: The operational State, during transitions (a_host=>
  556. * a_peripheral and b_device=>b_host) this may not match
  557. * the core, but allows the software to determine
  558. * transitions
  559. * @dr_mode: Requested mode of operation, one of following:
  560. * - USB_DR_MODE_PERIPHERAL
  561. * - USB_DR_MODE_HOST
  562. * - USB_DR_MODE_OTG
  563. * @hcd_enabled Host mode sub-driver initialization indicator.
  564. * @gadget_enabled Peripheral mode sub-driver initialization indicator.
  565. * @ll_hw_enabled Status of low-level hardware resources.
  566. * @phy: The otg phy transceiver structure for phy control.
  567. * @uphy: The otg phy transceiver structure for old USB phy control.
  568. * @plat: The platform specific configuration data. This can be removed once
  569. * all SoCs support usb transceiver.
  570. * @supplies: Definition of USB power supplies
  571. * @phyif: PHY interface width
  572. * @lock: Spinlock that protects all the driver data structures
  573. * @priv: Stores a pointer to the struct usb_hcd
  574. * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
  575. * transfer are in process of being queued
  576. * @srp_success: Stores status of SRP request in the case of a FS PHY
  577. * with an I2C interface
  578. * @wq_otg: Workqueue object used for handling of some interrupts
  579. * @wf_otg: Work object for handling Connector ID Status Change
  580. * interrupt
  581. * @wkp_timer: Timer object for handling Wakeup Detected interrupt
  582. * @lx_state: Lx state of connected device
  583. * @gregs_backup: Backup of global registers during suspend
  584. * @dregs_backup: Backup of device registers during suspend
  585. * @hregs_backup: Backup of host registers during suspend
  586. *
  587. * These are for host mode:
  588. *
  589. * @flags: Flags for handling root port state changes
  590. * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
  591. * Transfers associated with these QHs are not currently
  592. * assigned to a host channel.
  593. * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
  594. * Transfers associated with these QHs are currently
  595. * assigned to a host channel.
  596. * @non_periodic_qh_ptr: Pointer to next QH to process in the active
  597. * non-periodic schedule
  598. * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
  599. * list of QHs for periodic transfers that are _not_
  600. * scheduled for the next frame. Each QH in the list has an
  601. * interval counter that determines when it needs to be
  602. * scheduled for execution. This scheduling mechanism
  603. * allows only a simple calculation for periodic bandwidth
  604. * used (i.e. must assume that all periodic transfers may
  605. * need to execute in the same frame). However, it greatly
  606. * simplifies scheduling and should be sufficient for the
  607. * vast majority of OTG hosts, which need to connect to a
  608. * small number of peripherals at one time. Items move from
  609. * this list to periodic_sched_ready when the QH interval
  610. * counter is 0 at SOF.
  611. * @periodic_sched_ready: List of periodic QHs that are ready for execution in
  612. * the next frame, but have not yet been assigned to host
  613. * channels. Items move from this list to
  614. * periodic_sched_assigned as host channels become
  615. * available during the current frame.
  616. * @periodic_sched_assigned: List of periodic QHs to be executed in the next
  617. * frame that are assigned to host channels. Items move
  618. * from this list to periodic_sched_queued as the
  619. * transactions for the QH are queued to the DWC_otg
  620. * controller.
  621. * @periodic_sched_queued: List of periodic QHs that have been queued for
  622. * execution. Items move from this list to either
  623. * periodic_sched_inactive or periodic_sched_ready when the
  624. * channel associated with the transfer is released. If the
  625. * interval for the QH is 1, the item moves to
  626. * periodic_sched_ready because it must be rescheduled for
  627. * the next frame. Otherwise, the item moves to
  628. * periodic_sched_inactive.
  629. * @periodic_usecs: Total bandwidth claimed so far for periodic transfers.
  630. * This value is in microseconds per (micro)frame. The
  631. * assumption is that all periodic transfers may occur in
  632. * the same (micro)frame.
  633. * @frame_usecs: Internal variable used by the microframe scheduler
  634. * @frame_number: Frame number read from the core at SOF. The value ranges
  635. * from 0 to HFNUM_MAX_FRNUM.
  636. * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
  637. * SOF enable/disable.
  638. * @free_hc_list: Free host channels in the controller. This is a list of
  639. * struct dwc2_host_chan items.
  640. * @periodic_channels: Number of host channels assigned to periodic transfers.
  641. * Currently assuming that there is a dedicated host
  642. * channel for each periodic transaction and at least one
  643. * host channel is available for non-periodic transactions.
  644. * @non_periodic_channels: Number of host channels assigned to non-periodic
  645. * transfers
  646. * @available_host_channels Number of host channels available for the microframe
  647. * scheduler to use
  648. * @hc_ptr_array: Array of pointers to the host channel descriptors.
  649. * Allows accessing a host channel descriptor given the
  650. * host channel number. This is useful in interrupt
  651. * handlers.
  652. * @status_buf: Buffer used for data received during the status phase of
  653. * a control transfer.
  654. * @status_buf_dma: DMA address for status_buf
  655. * @start_work: Delayed work for handling host A-cable connection
  656. * @reset_work: Delayed work for handling a port reset
  657. * @otg_port: OTG port number
  658. * @frame_list: Frame list
  659. * @frame_list_dma: Frame list DMA address
  660. *
  661. * These are for peripheral mode:
  662. *
  663. * @driver: USB gadget driver
  664. * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
  665. * @num_of_eps: Number of available EPs (excluding EP0)
  666. * @debug_root: Root directrory for debugfs.
  667. * @debug_file: Main status file for debugfs.
  668. * @debug_testmode: Testmode status file for debugfs.
  669. * @debug_fifo: FIFO status file for debugfs.
  670. * @ep0_reply: Request used for ep0 reply.
  671. * @ep0_buff: Buffer for EP0 reply data, if needed.
  672. * @ctrl_buff: Buffer for EP0 control requests.
  673. * @ctrl_req: Request for EP0 control packets.
  674. * @ep0_state: EP0 control transfers state
  675. * @test_mode: USB test mode requested by the host
  676. * @eps: The endpoints being supplied to the gadget framework
  677. * @g_using_dma: Indicate if dma usage is enabled
  678. * @g_rx_fifo_sz: Contains rx fifo size value
  679. * @g_np_g_tx_fifo_sz: Contains Non-Periodic tx fifo size value
  680. * @g_tx_fifo_sz: Contains tx fifo size value per endpoints
  681. */
  682. struct dwc2_hsotg {
  683. struct device *dev;
  684. void __iomem *regs;
  685. /** Params detected from hardware */
  686. struct dwc2_hw_params hw_params;
  687. /** Params to actually use */
  688. struct dwc2_core_params *core_params;
  689. enum usb_otg_state op_state;
  690. enum usb_dr_mode dr_mode;
  691. unsigned int hcd_enabled:1;
  692. unsigned int gadget_enabled:1;
  693. unsigned int ll_hw_enabled:1;
  694. struct phy *phy;
  695. struct usb_phy *uphy;
  696. struct dwc2_hsotg_plat *plat;
  697. struct regulator_bulk_data supplies[ARRAY_SIZE(dwc2_hsotg_supply_names)];
  698. u32 phyif;
  699. spinlock_t lock;
  700. void *priv;
  701. int irq;
  702. struct clk *clk;
  703. unsigned int queuing_high_bandwidth:1;
  704. unsigned int srp_success:1;
  705. struct workqueue_struct *wq_otg;
  706. struct work_struct wf_otg;
  707. struct timer_list wkp_timer;
  708. enum dwc2_lx_state lx_state;
  709. struct dwc2_gregs_backup gr_backup;
  710. struct dwc2_dregs_backup dr_backup;
  711. struct dwc2_hregs_backup hr_backup;
  712. struct dentry *debug_root;
  713. struct debugfs_regset32 *regset;
  714. /* DWC OTG HW Release versions */
  715. #define DWC2_CORE_REV_2_71a 0x4f54271a
  716. #define DWC2_CORE_REV_2_90a 0x4f54290a
  717. #define DWC2_CORE_REV_2_92a 0x4f54292a
  718. #define DWC2_CORE_REV_2_94a 0x4f54294a
  719. #define DWC2_CORE_REV_3_00a 0x4f54300a
  720. #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  721. union dwc2_hcd_internal_flags {
  722. u32 d32;
  723. struct {
  724. unsigned port_connect_status_change:1;
  725. unsigned port_connect_status:1;
  726. unsigned port_reset_change:1;
  727. unsigned port_enable_change:1;
  728. unsigned port_suspend_change:1;
  729. unsigned port_over_current_change:1;
  730. unsigned port_l1_change:1;
  731. unsigned reserved:25;
  732. } b;
  733. } flags;
  734. struct list_head non_periodic_sched_inactive;
  735. struct list_head non_periodic_sched_active;
  736. struct list_head *non_periodic_qh_ptr;
  737. struct list_head periodic_sched_inactive;
  738. struct list_head periodic_sched_ready;
  739. struct list_head periodic_sched_assigned;
  740. struct list_head periodic_sched_queued;
  741. u16 periodic_usecs;
  742. u16 frame_usecs[8];
  743. u16 frame_number;
  744. u16 periodic_qh_count;
  745. bool bus_suspended;
  746. bool new_connection;
  747. #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
  748. #define FRAME_NUM_ARRAY_SIZE 1000
  749. u16 last_frame_num;
  750. u16 *frame_num_array;
  751. u16 *last_frame_num_array;
  752. int frame_num_idx;
  753. int dumped_frame_num_array;
  754. #endif
  755. struct list_head free_hc_list;
  756. int periodic_channels;
  757. int non_periodic_channels;
  758. int available_host_channels;
  759. struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
  760. u8 *status_buf;
  761. dma_addr_t status_buf_dma;
  762. #define DWC2_HCD_STATUS_BUF_SIZE 64
  763. struct delayed_work start_work;
  764. struct delayed_work reset_work;
  765. u8 otg_port;
  766. u32 *frame_list;
  767. dma_addr_t frame_list_dma;
  768. #ifdef DEBUG
  769. u32 frrem_samples;
  770. u64 frrem_accum;
  771. u32 hfnum_7_samples_a;
  772. u64 hfnum_7_frrem_accum_a;
  773. u32 hfnum_0_samples_a;
  774. u64 hfnum_0_frrem_accum_a;
  775. u32 hfnum_other_samples_a;
  776. u64 hfnum_other_frrem_accum_a;
  777. u32 hfnum_7_samples_b;
  778. u64 hfnum_7_frrem_accum_b;
  779. u32 hfnum_0_samples_b;
  780. u64 hfnum_0_frrem_accum_b;
  781. u32 hfnum_other_samples_b;
  782. u64 hfnum_other_frrem_accum_b;
  783. #endif
  784. #endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
  785. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  786. /* Gadget structures */
  787. struct usb_gadget_driver *driver;
  788. int fifo_mem;
  789. unsigned int dedicated_fifos:1;
  790. unsigned char num_of_eps;
  791. u32 fifo_map;
  792. struct usb_request *ep0_reply;
  793. struct usb_request *ctrl_req;
  794. void *ep0_buff;
  795. void *ctrl_buff;
  796. enum dwc2_ep0_state ep0_state;
  797. u8 test_mode;
  798. struct usb_gadget gadget;
  799. unsigned int enabled:1;
  800. unsigned int connected:1;
  801. struct dwc2_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
  802. struct dwc2_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
  803. u32 g_using_dma;
  804. u32 g_rx_fifo_sz;
  805. u32 g_np_g_tx_fifo_sz;
  806. u32 g_tx_fifo_sz[MAX_EPS_CHANNELS];
  807. #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
  808. };
  809. /* Reasons for halting a host channel */
  810. enum dwc2_halt_status {
  811. DWC2_HC_XFER_NO_HALT_STATUS,
  812. DWC2_HC_XFER_COMPLETE,
  813. DWC2_HC_XFER_URB_COMPLETE,
  814. DWC2_HC_XFER_ACK,
  815. DWC2_HC_XFER_NAK,
  816. DWC2_HC_XFER_NYET,
  817. DWC2_HC_XFER_STALL,
  818. DWC2_HC_XFER_XACT_ERR,
  819. DWC2_HC_XFER_FRAME_OVERRUN,
  820. DWC2_HC_XFER_BABBLE_ERR,
  821. DWC2_HC_XFER_DATA_TOGGLE_ERR,
  822. DWC2_HC_XFER_AHB_ERR,
  823. DWC2_HC_XFER_PERIODIC_INCOMPLETE,
  824. DWC2_HC_XFER_URB_DEQUEUE,
  825. };
  826. /*
  827. * The following functions support initialization of the core driver component
  828. * and the DWC_otg controller
  829. */
  830. extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
  831. extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
  832. extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
  833. /*
  834. * Host core Functions.
  835. * The following functions support managing the DWC_otg controller in host
  836. * mode.
  837. */
  838. extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
  839. extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
  840. enum dwc2_halt_status halt_status);
  841. extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
  842. struct dwc2_host_chan *chan);
  843. extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
  844. struct dwc2_host_chan *chan);
  845. extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
  846. struct dwc2_host_chan *chan);
  847. extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
  848. struct dwc2_host_chan *chan);
  849. extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
  850. struct dwc2_host_chan *chan);
  851. extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
  852. extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
  853. extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
  854. extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
  855. /*
  856. * Common core Functions.
  857. * The following functions support managing the DWC_otg controller in either
  858. * device or host mode.
  859. */
  860. extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
  861. extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
  862. extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
  863. extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq);
  864. extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
  865. extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
  866. /* This function should be called on every hardware interrupt. */
  867. extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
  868. /* OTG Core Parameters */
  869. /*
  870. * Specifies the OTG capabilities. The driver will automatically
  871. * detect the value for this parameter if none is specified.
  872. * 0 - HNP and SRP capable (default)
  873. * 1 - SRP Only capable
  874. * 2 - No HNP/SRP capable
  875. */
  876. extern void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
  877. #define DWC2_CAP_PARAM_HNP_SRP_CAPABLE 0
  878. #define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE 1
  879. #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  880. /*
  881. * Specifies whether to use slave or DMA mode for accessing the data
  882. * FIFOs. The driver will automatically detect the value for this
  883. * parameter if none is specified.
  884. * 0 - Slave
  885. * 1 - DMA (default, if available)
  886. */
  887. extern void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
  888. /*
  889. * When DMA mode is enabled specifies whether to use
  890. * address DMA or DMA Descritor mode for accessing the data
  891. * FIFOs in device mode. The driver will automatically detect
  892. * the value for this parameter if none is specified.
  893. * 0 - address DMA
  894. * 1 - DMA Descriptor(default, if available)
  895. */
  896. extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
  897. /*
  898. * When DMA mode is enabled specifies whether to use
  899. * address DMA or DMA Descritor mode with full speed devices
  900. * for accessing the data FIFOs in host mode.
  901. * 0 - address DMA
  902. * 1 - FS DMA Descriptor(default, if available)
  903. */
  904. extern void dwc2_set_param_dma_desc_fs_enable(struct dwc2_hsotg *hsotg,
  905. int val);
  906. /*
  907. * Specifies the maximum speed of operation in host and device mode.
  908. * The actual speed depends on the speed of the attached device and
  909. * the value of phy_type. The actual speed depends on the speed of the
  910. * attached device.
  911. * 0 - High Speed (default)
  912. * 1 - Full Speed
  913. */
  914. extern void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
  915. #define DWC2_SPEED_PARAM_HIGH 0
  916. #define DWC2_SPEED_PARAM_FULL 1
  917. /*
  918. * Specifies whether low power mode is supported when attached
  919. * to a Full Speed or Low Speed device in host mode.
  920. *
  921. * 0 - Don't support low power mode (default)
  922. * 1 - Support low power mode
  923. */
  924. extern void dwc2_set_param_host_support_fs_ls_low_power(
  925. struct dwc2_hsotg *hsotg, int val);
  926. /*
  927. * Specifies the PHY clock rate in low power mode when connected to a
  928. * Low Speed device in host mode. This parameter is applicable only if
  929. * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  930. * then defaults to 6 MHZ otherwise 48 MHZ.
  931. *
  932. * 0 - 48 MHz
  933. * 1 - 6 MHz
  934. */
  935. extern void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
  936. int val);
  937. #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  938. #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  939. /*
  940. * 0 - Use cC FIFO size parameters
  941. * 1 - Allow dynamic FIFO sizing (default)
  942. */
  943. extern void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
  944. int val);
  945. /*
  946. * Number of 4-byte words in the Rx FIFO in host mode when dynamic
  947. * FIFO sizing is enabled.
  948. * 16 to 32768 (default 1024)
  949. */
  950. extern void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
  951. /*
  952. * Number of 4-byte words in the non-periodic Tx FIFO in host mode
  953. * when Dynamic FIFO sizing is enabled in the core.
  954. * 16 to 32768 (default 256)
  955. */
  956. extern void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
  957. int val);
  958. /*
  959. * Number of 4-byte words in the host periodic Tx FIFO when dynamic
  960. * FIFO sizing is enabled.
  961. * 16 to 32768 (default 256)
  962. */
  963. extern void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
  964. int val);
  965. /*
  966. * The maximum transfer size supported in bytes.
  967. * 2047 to 65,535 (default 65,535)
  968. */
  969. extern void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
  970. /*
  971. * The maximum number of packets in a transfer.
  972. * 15 to 511 (default 511)
  973. */
  974. extern void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
  975. /*
  976. * The number of host channel registers to use.
  977. * 1 to 16 (default 11)
  978. * Note: The FPGA configuration supports a maximum of 11 host channels.
  979. */
  980. extern void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
  981. /*
  982. * Specifies the type of PHY interface to use. By default, the driver
  983. * will automatically detect the phy_type.
  984. *
  985. * 0 - Full Speed PHY
  986. * 1 - UTMI+ (default)
  987. * 2 - ULPI
  988. */
  989. extern void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
  990. #define DWC2_PHY_TYPE_PARAM_FS 0
  991. #define DWC2_PHY_TYPE_PARAM_UTMI 1
  992. #define DWC2_PHY_TYPE_PARAM_ULPI 2
  993. /*
  994. * Specifies the UTMI+ Data Width. This parameter is
  995. * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  996. * PHY_TYPE, this parameter indicates the data width between
  997. * the MAC and the ULPI Wrapper.) Also, this parameter is
  998. * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  999. * to "8 and 16 bits", meaning that the core has been
  1000. * configured to work at either data path width.
  1001. *
  1002. * 8 or 16 bits (default 16)
  1003. */
  1004. extern void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
  1005. /*
  1006. * Specifies whether the ULPI operates at double or single
  1007. * data rate. This parameter is only applicable if PHY_TYPE is
  1008. * ULPI.
  1009. *
  1010. * 0 - single data rate ULPI interface with 8 bit wide data
  1011. * bus (default)
  1012. * 1 - double data rate ULPI interface with 4 bit wide data
  1013. * bus
  1014. */
  1015. extern void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
  1016. /*
  1017. * Specifies whether to use the internal or external supply to
  1018. * drive the vbus with a ULPI phy.
  1019. */
  1020. extern void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
  1021. #define DWC2_PHY_ULPI_INTERNAL_VBUS 0
  1022. #define DWC2_PHY_ULPI_EXTERNAL_VBUS 1
  1023. /*
  1024. * Specifies whether to use the I2Cinterface for full speed PHY. This
  1025. * parameter is only applicable if PHY_TYPE is FS.
  1026. * 0 - No (default)
  1027. * 1 - Yes
  1028. */
  1029. extern void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
  1030. extern void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
  1031. extern void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
  1032. /*
  1033. * Specifies whether dedicated transmit FIFOs are
  1034. * enabled for non periodic IN endpoints in device mode
  1035. * 0 - No
  1036. * 1 - Yes
  1037. */
  1038. extern void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
  1039. int val);
  1040. extern void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
  1041. extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
  1042. extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
  1043. extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
  1044. const struct dwc2_core_params *params);
  1045. extern void dwc2_set_all_params(struct dwc2_core_params *params, int value);
  1046. extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
  1047. extern int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg);
  1048. extern int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);
  1049. /*
  1050. * Dump core registers and SPRAM
  1051. */
  1052. extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
  1053. extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
  1054. extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
  1055. /*
  1056. * Return OTG version - either 1.3 or 2.0
  1057. */
  1058. extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
  1059. /* Gadget defines */
  1060. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  1061. extern int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg);
  1062. extern int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2);
  1063. extern int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2);
  1064. extern int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq);
  1065. extern void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
  1066. bool reset);
  1067. extern void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg);
  1068. extern void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2);
  1069. extern int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
  1070. #define dwc2_is_device_connected(hsotg) (hsotg->connected)
  1071. #else
  1072. static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2)
  1073. { return 0; }
  1074. static inline int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2)
  1075. { return 0; }
  1076. static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2)
  1077. { return 0; }
  1078. static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
  1079. { return 0; }
  1080. static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
  1081. bool reset) {}
  1082. static inline void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
  1083. static inline void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
  1084. static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
  1085. int testmode)
  1086. { return 0; }
  1087. #define dwc2_is_device_connected(hsotg) (0)
  1088. #endif
  1089. #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  1090. extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
  1091. extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
  1092. extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
  1093. #else
  1094. static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
  1095. { return 0; }
  1096. static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {}
  1097. static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
  1098. static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
  1099. static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
  1100. { return 0; }
  1101. #endif
  1102. #endif /* __DWC2_CORE_H__ */