core.h 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  1. /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
  2. /*
  3. * core.h - DesignWare HS OTG Controller common declarations
  4. *
  5. * Copyright (C) 2004-2013 Synopsys, Inc.
  6. */
  7. #ifndef __DWC2_CORE_H__
  8. #define __DWC2_CORE_H__
  9. #include <linux/acpi.h>
  10. #include <linux/phy/phy.h>
  11. #include <linux/regulator/consumer.h>
  12. #include <linux/usb/gadget.h>
  13. #include <linux/usb/otg.h>
  14. #include <linux/usb/phy.h>
  15. #include "hw.h"
  16. /*
  17. * Suggested defines for tracers:
  18. * - no_printk: Disable tracing
  19. * - pr_info: Print this info to the console
  20. * - trace_printk: Print this info to trace buffer (good for verbose logging)
  21. */
  22. #define DWC2_TRACE_SCHEDULER no_printk
  23. #define DWC2_TRACE_SCHEDULER_VB no_printk
  24. /* Detailed scheduler tracing, but won't overwhelm console */
  25. #define dwc2_sch_dbg(hsotg, fmt, ...) \
  26. DWC2_TRACE_SCHEDULER(pr_fmt("%s: SCH: " fmt), \
  27. dev_name(hsotg->dev), ##__VA_ARGS__)
  28. /* Verbose scheduler tracing */
  29. #define dwc2_sch_vdbg(hsotg, fmt, ...) \
  30. DWC2_TRACE_SCHEDULER_VB(pr_fmt("%s: SCH: " fmt), \
  31. dev_name(hsotg->dev), ##__VA_ARGS__)
  32. /* Maximum number of Endpoints/HostChannels */
  33. #define MAX_EPS_CHANNELS 16
  34. /* dwc2-hsotg declarations */
  35. static const char * const dwc2_hsotg_supply_names[] = {
  36. "vusb_d", /* digital USB supply, 1.2V */
  37. "vusb_a", /* analog USB supply, 1.1V */
  38. };
  39. #define DWC2_NUM_SUPPLIES ARRAY_SIZE(dwc2_hsotg_supply_names)
  40. /*
  41. * EP0_MPS_LIMIT
  42. *
  43. * Unfortunately there seems to be a limit of the amount of data that can
  44. * be transferred by IN transactions on EP0. This is either 127 bytes or 3
  45. * packets (which practically means 1 packet and 63 bytes of data) when the
  46. * MPS is set to 64.
  47. *
  48. * This means if we are wanting to move >127 bytes of data, we need to
  49. * split the transactions up, but just doing one packet at a time does
  50. * not work (this may be an implicit DATA0 PID on first packet of the
  51. * transaction) and doing 2 packets is outside the controller's limits.
  52. *
  53. * If we try to lower the MPS size for EP0, then no transfers work properly
  54. * for EP0, and the system will fail basic enumeration. As no cause for this
  55. * has currently been found, we cannot support any large IN transfers for
  56. * EP0.
  57. */
  58. #define EP0_MPS_LIMIT 64
  59. struct dwc2_hsotg;
  60. struct dwc2_hsotg_req;
  61. /**
  62. * struct dwc2_hsotg_ep - driver endpoint definition.
  63. * @ep: The gadget layer representation of the endpoint.
  64. * @name: The driver generated name for the endpoint.
  65. * @queue: Queue of requests for this endpoint.
  66. * @parent: Reference back to the parent device structure.
  67. * @req: The current request that the endpoint is processing. This is
  68. * used to indicate an request has been loaded onto the endpoint
  69. * and has yet to be completed (maybe due to data move, or simply
  70. * awaiting an ack from the core all the data has been completed).
  71. * @debugfs: File entry for debugfs file for this endpoint.
  72. * @dir_in: Set to true if this endpoint is of the IN direction, which
  73. * means that it is sending data to the Host.
  74. * @map_dir: Set to the value of dir_in when the DMA buffer is mapped.
  75. * @index: The index for the endpoint registers.
  76. * @mc: Multi Count - number of transactions per microframe
  77. * @interval: Interval for periodic endpoints, in frames or microframes.
  78. * @name: The name array passed to the USB core.
  79. * @halted: Set if the endpoint has been halted.
  80. * @periodic: Set if this is a periodic ep, such as Interrupt
  81. * @isochronous: Set if this is a isochronous ep
  82. * @send_zlp: Set if we need to send a zero-length packet.
  83. * @wedged: Set if ep is wedged.
  84. * @desc_list_dma: The DMA address of descriptor chain currently in use.
  85. * @desc_list: Pointer to descriptor DMA chain head currently in use.
  86. * @desc_count: Count of entries within the DMA descriptor chain of EP.
  87. * @next_desc: index of next free descriptor in the ISOC chain under SW control.
  88. * @compl_desc: index of next descriptor to be completed by xFerComplete
  89. * @total_data: The total number of data bytes done.
  90. * @fifo_size: The size of the FIFO (for periodic IN endpoints)
  91. * @fifo_index: For Dedicated FIFO operation, only FIFO0 can be used for EP0.
  92. * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
  93. * @last_load: The offset of data for the last start of request.
  94. * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
  95. * @target_frame: Targeted frame num to setup next ISOC transfer
  96. * @frame_overrun: Indicates SOF number overrun in DSTS
  97. *
  98. * This is the driver's state for each registered endpoint, allowing it
  99. * to keep track of transactions that need doing. Each endpoint has a
  100. * lock to protect the state, to try and avoid using an overall lock
  101. * for the host controller as much as possible.
  102. *
  103. * For periodic IN endpoints, we have fifo_size and fifo_load to try
  104. * and keep track of the amount of data in the periodic FIFO for each
  105. * of these as we don't have a status register that tells us how much
  106. * is in each of them. (note, this may actually be useless information
  107. * as in shared-fifo mode periodic in acts like a single-frame packet
  108. * buffer than a fifo)
  109. */
  110. struct dwc2_hsotg_ep {
  111. struct usb_ep ep;
  112. struct list_head queue;
  113. struct dwc2_hsotg *parent;
  114. struct dwc2_hsotg_req *req;
  115. struct dentry *debugfs;
  116. unsigned long total_data;
  117. unsigned int size_loaded;
  118. unsigned int last_load;
  119. unsigned int fifo_load;
  120. unsigned short fifo_size;
  121. unsigned short fifo_index;
  122. unsigned char dir_in;
  123. unsigned char map_dir;
  124. unsigned char index;
  125. unsigned char mc;
  126. u16 interval;
  127. unsigned int halted:1;
  128. unsigned int periodic:1;
  129. unsigned int isochronous:1;
  130. unsigned int send_zlp:1;
  131. unsigned int wedged:1;
  132. unsigned int target_frame;
  133. #define TARGET_FRAME_INITIAL 0xFFFFFFFF
  134. bool frame_overrun;
  135. dma_addr_t desc_list_dma;
  136. struct dwc2_dma_desc *desc_list;
  137. u8 desc_count;
  138. unsigned int next_desc;
  139. unsigned int compl_desc;
  140. char name[10];
  141. };
  142. /**
  143. * struct dwc2_hsotg_req - data transfer request
  144. * @req: The USB gadget request
  145. * @queue: The list of requests for the endpoint this is queued for.
  146. * @saved_req_buf: variable to save req.buf when bounce buffers are used.
  147. */
  148. struct dwc2_hsotg_req {
  149. struct usb_request req;
  150. struct list_head queue;
  151. void *saved_req_buf;
  152. };
  153. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
  154. IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  155. #define call_gadget(_hs, _entry) \
  156. do { \
  157. if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
  158. (_hs)->driver && (_hs)->driver->_entry) { \
  159. spin_unlock(&_hs->lock); \
  160. (_hs)->driver->_entry(&(_hs)->gadget); \
  161. spin_lock(&_hs->lock); \
  162. } \
  163. } while (0)
  164. #else
  165. #define call_gadget(_hs, _entry) do {} while (0)
  166. #endif
  167. struct dwc2_hsotg;
  168. struct dwc2_host_chan;
  169. /* Device States */
  170. enum dwc2_lx_state {
  171. DWC2_L0, /* On state */
  172. DWC2_L1, /* LPM sleep state */
  173. DWC2_L2, /* USB suspend state */
  174. DWC2_L3, /* Off state */
  175. };
  176. /* Gadget ep0 states */
  177. enum dwc2_ep0_state {
  178. DWC2_EP0_SETUP,
  179. DWC2_EP0_DATA_IN,
  180. DWC2_EP0_DATA_OUT,
  181. DWC2_EP0_STATUS_IN,
  182. DWC2_EP0_STATUS_OUT,
  183. };
  184. /**
  185. * struct dwc2_core_params - Parameters for configuring the core
  186. *
  187. * @otg_caps: Specifies the OTG capabilities. OTG caps from the platform parameters,
  188. * used to setup the:
  189. * - HNP and SRP capable
  190. * - SRP Only capable
  191. * - No HNP/SRP capable (always available)
  192. * Defaults to best available option
  193. * - OTG revision number the device is compliant with, in binary-coded
  194. * decimal (i.e. 2.0 is 0200H). (see struct usb_otg_caps)
  195. * @host_dma: Specifies whether to use slave or DMA mode for accessing
  196. * the data FIFOs. The driver will automatically detect the
  197. * value for this parameter if none is specified.
  198. * 0 - Slave (always available)
  199. * 1 - DMA (default, if available)
  200. * @dma_desc_enable: When DMA mode is enabled, specifies whether to use
  201. * address DMA mode or descriptor DMA mode for accessing
  202. * the data FIFOs. The driver will automatically detect the
  203. * value for this if none is specified.
  204. * 0 - Address DMA
  205. * 1 - Descriptor DMA (default, if available)
  206. * @dma_desc_fs_enable: When DMA mode is enabled, specifies whether to use
  207. * address DMA mode or descriptor DMA mode for accessing
  208. * the data FIFOs in Full Speed mode only. The driver
  209. * will automatically detect the value for this if none is
  210. * specified.
  211. * 0 - Address DMA
  212. * 1 - Descriptor DMA in FS (default, if available)
  213. * @speed: Specifies the maximum speed of operation in host and
  214. * device mode. The actual speed depends on the speed of
  215. * the attached device and the value of phy_type.
  216. * 0 - High Speed
  217. * (default when phy_type is UTMI+ or ULPI)
  218. * 1 - Full Speed
  219. * (default when phy_type is Full Speed)
  220. * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
  221. * 1 - Allow dynamic FIFO sizing (default, if available)
  222. * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
  223. * are enabled for non-periodic IN endpoints in device
  224. * mode.
  225. * @host_rx_fifo_size: Number of 4-byte words in the Rx FIFO in host mode when
  226. * dynamic FIFO sizing is enabled
  227. * 16 to 32768
  228. * Actual maximum value is autodetected and also
  229. * the default.
  230. * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
  231. * in host mode when dynamic FIFO sizing is enabled
  232. * 16 to 32768
  233. * Actual maximum value is autodetected and also
  234. * the default.
  235. * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
  236. * host mode when dynamic FIFO sizing is enabled
  237. * 16 to 32768
  238. * Actual maximum value is autodetected and also
  239. * the default.
  240. * @max_transfer_size: The maximum transfer size supported, in bytes
  241. * 2047 to 65,535
  242. * Actual maximum value is autodetected and also
  243. * the default.
  244. * @max_packet_count: The maximum number of packets in a transfer
  245. * 15 to 511
  246. * Actual maximum value is autodetected and also
  247. * the default.
  248. * @host_channels: The number of host channel registers to use
  249. * 1 to 16
  250. * Actual maximum value is autodetected and also
  251. * the default.
  252. * @phy_type: Specifies the type of PHY interface to use. By default,
  253. * the driver will automatically detect the phy_type.
  254. * 0 - Full Speed Phy
  255. * 1 - UTMI+ Phy
  256. * 2 - ULPI Phy
  257. * Defaults to best available option (2, 1, then 0)
  258. * @phy_utmi_width: Specifies the UTMI+ Data Width (in bits). This parameter
  259. * is applicable for a phy_type of UTMI+ or ULPI. (For a
  260. * ULPI phy_type, this parameter indicates the data width
  261. * between the MAC and the ULPI Wrapper.) Also, this
  262. * parameter is applicable only if the OTG_HSPHY_WIDTH cC
  263. * parameter was set to "8 and 16 bits", meaning that the
  264. * core has been configured to work at either data path
  265. * width.
  266. * 8 or 16 (default 16 if available)
  267. * @eusb2_disc: Specifies whether eUSB2 PHY disconnect support flow
  268. * applicable or no. Applicable in device mode of HSOTG
  269. * and HS IOT cores v5.00 or higher.
  270. * 0 - eUSB2 PHY disconnect support flow not applicable
  271. * 1 - eUSB2 PHY disconnect support flow applicable
  272. * @phy_ulpi_ddr: Specifies whether the ULPI operates at double or single
  273. * data rate. This parameter is only applicable if phy_type
  274. * is ULPI.
  275. * 0 - single data rate ULPI interface with 8 bit wide
  276. * data bus (default)
  277. * 1 - double data rate ULPI interface with 4 bit wide
  278. * data bus
  279. * @phy_ulpi_ext_vbus: For a ULPI phy, specifies whether to use the internal or
  280. * external supply to drive the VBus
  281. * 0 - Internal supply (default)
  282. * 1 - External supply
  283. * @i2c_enable: Specifies whether to use the I2Cinterface for a full
  284. * speed PHY. This parameter is only applicable if phy_type
  285. * is FS.
  286. * 0 - No (default)
  287. * 1 - Yes
  288. * @ipg_isoc_en: Indicates the IPG supports is enabled or disabled.
  289. * 0 - Disable (default)
  290. * 1 - Enable
  291. * @acg_enable: For enabling Active Clock Gating in the controller
  292. * 0 - No
  293. * 1 - Yes
  294. * @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
  295. * 0 - No (default)
  296. * 1 - Yes
  297. * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
  298. * when attached to a Full Speed or Low Speed device in
  299. * host mode.
  300. * 0 - Don't support low power mode (default)
  301. * 1 - Support low power mode
  302. * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
  303. * when connected to a Low Speed device in host
  304. * mode. This parameter is applicable only if
  305. * host_support_fs_ls_low_power is enabled.
  306. * 0 - 48 MHz
  307. * (default when phy_type is UTMI+ or ULPI)
  308. * 1 - 6 MHz
  309. * (default when phy_type is Full Speed)
  310. * @oc_disable: Flag to disable overcurrent condition.
  311. * 0 - Allow overcurrent condition to get detected
  312. * 1 - Disable overcurrent condtion to get detected
  313. * @ts_dline: Enable Term Select Dline pulsing
  314. * 0 - No (default)
  315. * 1 - Yes
  316. * @reload_ctl: Allow dynamic reloading of HFIR register during runtime
  317. * 0 - No (default for core < 2.92a)
  318. * 1 - Yes (default for core >= 2.92a)
  319. * @ahbcfg: This field allows the default value of the GAHBCFG
  320. * register to be overridden
  321. * -1 - GAHBCFG value will be set to 0x06
  322. * (INCR, default)
  323. * all others - GAHBCFG value will be overridden with
  324. * this value
  325. * Not all bits can be controlled like this, the
  326. * bits defined by GAHBCFG_CTRL_MASK are controlled
  327. * by the driver and are ignored in this
  328. * configuration value.
  329. * @uframe_sched: True to enable the microframe scheduler
  330. * @external_id_pin_ctl: Specifies whether ID pin is handled externally.
  331. * Disable CONIDSTSCHNG controller interrupt in such
  332. * case.
  333. * 0 - No (default)
  334. * 1 - Yes
  335. * @power_down: Specifies whether the controller support power_down.
  336. * If power_down is enabled, the controller will enter
  337. * power_down in both peripheral and host mode when
  338. * needed.
  339. * 0 - No (default)
  340. * 1 - Partial power down
  341. * 2 - Hibernation
  342. * @no_clock_gating: Specifies whether to avoid clock gating feature.
  343. * 0 - No (use clock gating)
  344. * 1 - Yes (avoid it)
  345. * @lpm: Enable LPM support.
  346. * 0 - No
  347. * 1 - Yes
  348. * @lpm_clock_gating: Enable core PHY clock gating.
  349. * 0 - No
  350. * 1 - Yes
  351. * @besl: Enable LPM Errata support.
  352. * 0 - No
  353. * 1 - Yes
  354. * @hird_threshold_en: HIRD or HIRD Threshold enable.
  355. * 0 - No
  356. * 1 - Yes
  357. * @hird_threshold: Value of BESL or HIRD Threshold.
  358. * @ref_clk_per: Indicates in terms of pico seconds the period
  359. * of ref_clk.
  360. * 62500 - 16MHz
  361. * 58823 - 17MHz
  362. * 52083 - 19.2MHz
  363. * 50000 - 20MHz
  364. * 41666 - 24MHz
  365. * 33333 - 30MHz (default)
  366. * 25000 - 40MHz
  367. * @sof_cnt_wkup_alert: Indicates in term of number of SOF's after which
  368. * the controller should generate an interrupt if the
  369. * device had been in L1 state until that period.
  370. * This is used by SW to initiate Remote WakeUp in the
  371. * controller so as to sync to the uF number from the host.
  372. * @activate_stm_fs_transceiver: Activate internal transceiver using GGPIO
  373. * register.
  374. * 0 - Deactivate the transceiver (default)
  375. * 1 - Activate the transceiver
  376. * @activate_stm_id_vb_detection: Activate external ID pin and Vbus level
  377. * detection using GGPIO register.
  378. * 0 - Deactivate the external level detection (default)
  379. * 1 - Activate the external level detection
  380. * @activate_ingenic_overcurrent_detection: Activate Ingenic overcurrent
  381. * detection.
  382. * 0 - Deactivate the overcurrent detection
  383. * 1 - Activate the overcurrent detection (default)
  384. * @g_dma: Enables gadget dma usage (default: autodetect).
  385. * @g_dma_desc: Enables gadget descriptor DMA (default: autodetect).
  386. * @g_rx_fifo_size: The periodic rx fifo size for the device, in
  387. * DWORDS from 16-32768 (default: 2048 if
  388. * possible, otherwise autodetect).
  389. * @g_np_tx_fifo_size: The non-periodic tx fifo size for the device in
  390. * DWORDS from 16-32768 (default: 1024 if
  391. * possible, otherwise autodetect).
  392. * @g_tx_fifo_size: An array of TX fifo sizes in dedicated fifo
  393. * mode. Each value corresponds to one EP
  394. * starting from EP1 (max 15 values). Sizes are
  395. * in DWORDS with possible values from
  396. * 16-32768 (default: 256, 256, 256, 256, 768,
  397. * 768, 768, 768, 0, 0, 0, 0, 0, 0, 0).
  398. * @change_speed_quirk: Change speed configuration to DWC2_SPEED_PARAM_FULL
  399. * while full&low speed device connect. And change speed
  400. * back to DWC2_SPEED_PARAM_HIGH while device is gone.
  401. * 0 - No (default)
  402. * 1 - Yes
  403. * @service_interval: Enable service interval based scheduling.
  404. * 0 - No
  405. * 1 - Yes
  406. *
  407. * The following parameters may be specified when starting the module. These
  408. * parameters define how the DWC_otg controller should be configured. A
  409. * value of -1 (or any other out of range value) for any parameter means
  410. * to read the value from hardware (if possible) or use the builtin
  411. * default described above.
  412. */
  413. struct dwc2_core_params {
  414. struct usb_otg_caps otg_caps;
  415. u8 phy_type;
  416. #define DWC2_PHY_TYPE_PARAM_FS 0
  417. #define DWC2_PHY_TYPE_PARAM_UTMI 1
  418. #define DWC2_PHY_TYPE_PARAM_ULPI 2
  419. u8 speed;
  420. #define DWC2_SPEED_PARAM_HIGH 0
  421. #define DWC2_SPEED_PARAM_FULL 1
  422. #define DWC2_SPEED_PARAM_LOW 2
  423. u8 phy_utmi_width;
  424. bool eusb2_disc;
  425. bool phy_ulpi_ddr;
  426. bool phy_ulpi_ext_vbus;
  427. bool enable_dynamic_fifo;
  428. bool en_multiple_tx_fifo;
  429. bool i2c_enable;
  430. bool acg_enable;
  431. bool ulpi_fs_ls;
  432. bool ts_dline;
  433. bool reload_ctl;
  434. bool uframe_sched;
  435. bool external_id_pin_ctl;
  436. int power_down;
  437. #define DWC2_POWER_DOWN_PARAM_NONE 0
  438. #define DWC2_POWER_DOWN_PARAM_PARTIAL 1
  439. #define DWC2_POWER_DOWN_PARAM_HIBERNATION 2
  440. bool no_clock_gating;
  441. bool lpm;
  442. bool lpm_clock_gating;
  443. bool besl;
  444. bool hird_threshold_en;
  445. bool service_interval;
  446. u8 hird_threshold;
  447. bool activate_stm_fs_transceiver;
  448. bool activate_stm_id_vb_detection;
  449. bool activate_ingenic_overcurrent_detection;
  450. bool ipg_isoc_en;
  451. u16 max_packet_count;
  452. u32 max_transfer_size;
  453. u32 ahbcfg;
  454. /* GREFCLK parameters */
  455. u32 ref_clk_per;
  456. u16 sof_cnt_wkup_alert;
  457. /* Host parameters */
  458. bool host_dma;
  459. bool dma_desc_enable;
  460. bool dma_desc_fs_enable;
  461. bool host_support_fs_ls_low_power;
  462. bool host_ls_low_power_phy_clk;
  463. bool oc_disable;
  464. u8 host_channels;
  465. u16 host_rx_fifo_size;
  466. u16 host_nperio_tx_fifo_size;
  467. u16 host_perio_tx_fifo_size;
  468. /* Gadget parameters */
  469. bool g_dma;
  470. bool g_dma_desc;
  471. u32 g_rx_fifo_size;
  472. u32 g_np_tx_fifo_size;
  473. u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
  474. bool change_speed_quirk;
  475. };
  476. /**
  477. * struct dwc2_hw_params - Autodetected parameters.
  478. *
  479. * These parameters are the various parameters read from hardware
  480. * registers during initialization. They typically contain the best
  481. * supported or maximum value that can be configured in the
  482. * corresponding dwc2_core_params value.
  483. *
  484. * The values that are not in dwc2_core_params are documented below.
  485. *
  486. * @op_mode: Mode of Operation
  487. * 0 - HNP- and SRP-Capable OTG (Host & Device)
  488. * 1 - SRP-Capable OTG (Host & Device)
  489. * 2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
  490. * 3 - SRP-Capable Device
  491. * 4 - Non-OTG Device
  492. * 5 - SRP-Capable Host
  493. * 6 - Non-OTG Host
  494. * @arch: Architecture
  495. * 0 - Slave only
  496. * 1 - External DMA
  497. * 2 - Internal DMA
  498. * @ipg_isoc_en: This feature indicates that the controller supports
  499. * the worst-case scenario of Rx followed by Rx
  500. * Interpacket Gap (IPG) (32 bitTimes) as per the utmi
  501. * specification for any token following ISOC OUT token.
  502. * 0 - Don't support
  503. * 1 - Support
  504. * @power_optimized: Are power optimizations enabled?
  505. * @num_dev_ep: Number of device endpoints available
  506. * @num_dev_in_eps: Number of device IN endpoints available
  507. * @num_dev_perio_in_ep: Number of device periodic IN endpoints
  508. * available
  509. * @dev_token_q_depth: Device Mode IN Token Sequence Learning Queue
  510. * Depth
  511. * 0 to 30
  512. * @host_perio_tx_q_depth:
  513. * Host Mode Periodic Request Queue Depth
  514. * 2, 4 or 8
  515. * @nperio_tx_q_depth:
  516. * Non-Periodic Request Queue Depth
  517. * 2, 4 or 8
  518. * @hs_phy_type: High-speed PHY interface type
  519. * 0 - High-speed interface not supported
  520. * 1 - UTMI+
  521. * 2 - ULPI
  522. * 3 - UTMI+ and ULPI
  523. * @fs_phy_type: Full-speed PHY interface type
  524. * 0 - Full speed interface not supported
  525. * 1 - Dedicated full speed interface
  526. * 2 - FS pins shared with UTMI+ pins
  527. * 3 - FS pins shared with ULPI pins
  528. * @total_fifo_size: Total internal RAM for FIFOs (bytes)
  529. * @hibernation: Is hibernation enabled?
  530. * @utmi_phy_data_width: UTMI+ PHY data width
  531. * 0 - 8 bits
  532. * 1 - 16 bits
  533. * 2 - 8 or 16 bits
  534. * @snpsid: Value from SNPSID register
  535. * @dev_ep_dirs: Direction of device endpoints (GHWCFG1)
  536. * @g_tx_fifo_size: Power-on values of TxFIFO sizes
  537. * @dma_desc_enable: When DMA mode is enabled, specifies whether to use
  538. * address DMA mode or descriptor DMA mode for accessing
  539. * the data FIFOs. The driver will automatically detect the
  540. * value for this if none is specified.
  541. * 0 - Address DMA
  542. * 1 - Descriptor DMA (default, if available)
  543. * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
  544. * 1 - Allow dynamic FIFO sizing (default, if available)
  545. * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
  546. * are enabled for non-periodic IN endpoints in device
  547. * mode.
  548. * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
  549. * in host mode when dynamic FIFO sizing is enabled
  550. * 16 to 32768
  551. * Actual maximum value is autodetected and also
  552. * the default.
  553. * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
  554. * host mode when dynamic FIFO sizing is enabled
  555. * 16 to 32768
  556. * Actual maximum value is autodetected and also
  557. * the default.
  558. * @max_transfer_size: The maximum transfer size supported, in bytes
  559. * 2047 to 65,535
  560. * Actual maximum value is autodetected and also
  561. * the default.
  562. * @max_packet_count: The maximum number of packets in a transfer
  563. * 15 to 511
  564. * Actual maximum value is autodetected and also
  565. * the default.
  566. * @host_channels: The number of host channel registers to use
  567. * 1 to 16
  568. * Actual maximum value is autodetected and also
  569. * the default.
  570. * @dev_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
  571. * in device mode when dynamic FIFO sizing is enabled
  572. * 16 to 32768
  573. * Actual maximum value is autodetected and also
  574. * the default.
  575. * @i2c_enable: Specifies whether to use the I2Cinterface for a full
  576. * speed PHY. This parameter is only applicable if phy_type
  577. * is FS.
  578. * 0 - No (default)
  579. * 1 - Yes
  580. * @acg_enable: For enabling Active Clock Gating in the controller
  581. * 0 - Disable
  582. * 1 - Enable
  583. * @lpm_mode: For enabling Link Power Management in the controller
  584. * 0 - Disable
  585. * 1 - Enable
  586. * @rx_fifo_size: Number of 4-byte words in the Rx FIFO when dynamic
  587. * FIFO sizing is enabled 16 to 32768
  588. * Actual maximum value is autodetected and also
  589. * the default.
  590. * @service_interval_mode: For enabling service interval based scheduling in the
  591. * controller.
  592. * 0 - Disable
  593. * 1 - Enable
  594. */
  595. struct dwc2_hw_params {
  596. unsigned op_mode:3;
  597. unsigned arch:2;
  598. unsigned dma_desc_enable:1;
  599. unsigned enable_dynamic_fifo:1;
  600. unsigned en_multiple_tx_fifo:1;
  601. unsigned rx_fifo_size:16;
  602. unsigned host_nperio_tx_fifo_size:16;
  603. unsigned dev_nperio_tx_fifo_size:16;
  604. unsigned host_perio_tx_fifo_size:16;
  605. unsigned nperio_tx_q_depth:3;
  606. unsigned host_perio_tx_q_depth:3;
  607. unsigned dev_token_q_depth:5;
  608. unsigned max_transfer_size:26;
  609. unsigned max_packet_count:11;
  610. unsigned host_channels:5;
  611. unsigned hs_phy_type:2;
  612. unsigned fs_phy_type:2;
  613. unsigned i2c_enable:1;
  614. unsigned acg_enable:1;
  615. unsigned num_dev_ep:4;
  616. unsigned num_dev_in_eps : 4;
  617. unsigned num_dev_perio_in_ep:4;
  618. unsigned total_fifo_size:16;
  619. unsigned power_optimized:1;
  620. unsigned hibernation:1;
  621. unsigned utmi_phy_data_width:2;
  622. unsigned lpm_mode:1;
  623. unsigned ipg_isoc_en:1;
  624. unsigned service_interval_mode:1;
  625. u32 snpsid;
  626. u32 dev_ep_dirs;
  627. u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
  628. };
  629. /* Size of control and EP0 buffers */
  630. #define DWC2_CTRL_BUFF_SIZE 8
  631. /**
  632. * struct dwc2_gregs_backup - Holds global registers state before
  633. * entering partial power down
  634. * @gotgctl: Backup of GOTGCTL register
  635. * @gintmsk: Backup of GINTMSK register
  636. * @gahbcfg: Backup of GAHBCFG register
  637. * @gusbcfg: Backup of GUSBCFG register
  638. * @grxfsiz: Backup of GRXFSIZ register
  639. * @gnptxfsiz: Backup of GNPTXFSIZ register
  640. * @gi2cctl: Backup of GI2CCTL register
  641. * @glpmcfg: Backup of GLPMCFG register
  642. * @gdfifocfg: Backup of GDFIFOCFG register
  643. * @pcgcctl: Backup of PCGCCTL register
  644. * @pcgcctl1: Backup of PCGCCTL1 register
  645. * @dtxfsiz: Backup of DTXFSIZ registers for each endpoint
  646. * @gpwrdn: Backup of GPWRDN register
  647. * @valid: True if registers values backuped.
  648. */
  649. struct dwc2_gregs_backup {
  650. u32 gotgctl;
  651. u32 gintmsk;
  652. u32 gahbcfg;
  653. u32 gusbcfg;
  654. u32 grxfsiz;
  655. u32 gnptxfsiz;
  656. u32 gi2cctl;
  657. u32 glpmcfg;
  658. u32 pcgcctl;
  659. u32 pcgcctl1;
  660. u32 gdfifocfg;
  661. u32 gpwrdn;
  662. bool valid;
  663. };
  664. /**
  665. * struct dwc2_dregs_backup - Holds device registers state before
  666. * entering partial power down
  667. * @dcfg: Backup of DCFG register
  668. * @dctl: Backup of DCTL register
  669. * @daintmsk: Backup of DAINTMSK register
  670. * @diepmsk: Backup of DIEPMSK register
  671. * @doepmsk: Backup of DOEPMSK register
  672. * @diepctl: Backup of DIEPCTL register
  673. * @dieptsiz: Backup of DIEPTSIZ register
  674. * @diepdma: Backup of DIEPDMA register
  675. * @doepctl: Backup of DOEPCTL register
  676. * @doeptsiz: Backup of DOEPTSIZ register
  677. * @doepdma: Backup of DOEPDMA register
  678. * @dtxfsiz: Backup of DTXFSIZ registers for each endpoint
  679. * @valid: True if registers values backuped.
  680. */
  681. struct dwc2_dregs_backup {
  682. u32 dcfg;
  683. u32 dctl;
  684. u32 daintmsk;
  685. u32 diepmsk;
  686. u32 doepmsk;
  687. u32 diepctl[MAX_EPS_CHANNELS];
  688. u32 dieptsiz[MAX_EPS_CHANNELS];
  689. u32 diepdma[MAX_EPS_CHANNELS];
  690. u32 doepctl[MAX_EPS_CHANNELS];
  691. u32 doeptsiz[MAX_EPS_CHANNELS];
  692. u32 doepdma[MAX_EPS_CHANNELS];
  693. u32 dtxfsiz[MAX_EPS_CHANNELS];
  694. bool valid;
  695. };
  696. /**
  697. * struct dwc2_hregs_backup - Holds host registers state before
  698. * entering partial power down
  699. * @hcfg: Backup of HCFG register
  700. * @hflbaddr: Backup of HFLBADDR register
  701. * @haintmsk: Backup of HAINTMSK register
  702. * @hcchar: Backup of HCCHAR register
  703. * @hcsplt: Backup of HCSPLT register
  704. * @hcintmsk: Backup of HCINTMSK register
  705. * @hctsiz: Backup of HCTSIZ register
  706. * @hdma: Backup of HCDMA register
  707. * @hcdmab: Backup of HCDMAB register
  708. * @hprt0: Backup of HPTR0 register
  709. * @hfir: Backup of HFIR register
  710. * @hptxfsiz: Backup of HPTXFSIZ register
  711. * @valid: True if registers values backuped.
  712. */
  713. struct dwc2_hregs_backup {
  714. u32 hcfg;
  715. u32 hflbaddr;
  716. u32 haintmsk;
  717. u32 hcchar[MAX_EPS_CHANNELS];
  718. u32 hcsplt[MAX_EPS_CHANNELS];
  719. u32 hcintmsk[MAX_EPS_CHANNELS];
  720. u32 hctsiz[MAX_EPS_CHANNELS];
  721. u32 hcidma[MAX_EPS_CHANNELS];
  722. u32 hcidmab[MAX_EPS_CHANNELS];
  723. u32 hprt0;
  724. u32 hfir;
  725. u32 hptxfsiz;
  726. bool valid;
  727. };
  728. /*
  729. * Constants related to high speed periodic scheduling
  730. *
  731. * We have a periodic schedule that is DWC2_HS_SCHEDULE_UFRAMES long. From a
  732. * reservation point of view it's assumed that the schedule goes right back to
  733. * the beginning after the end of the schedule.
  734. *
  735. * What does that mean for scheduling things with a long interval? It means
  736. * we'll reserve time for them in every possible microframe that they could
  737. * ever be scheduled in. ...but we'll still only actually schedule them as
  738. * often as they were requested.
  739. *
  740. * We keep our schedule in a "bitmap" structure. This simplifies having
  741. * to keep track of and merge intervals: we just let the bitmap code do most
  742. * of the heavy lifting. In a way scheduling is much like memory allocation.
  743. *
  744. * We schedule 100us per uframe or 80% of 125us (the maximum amount you're
  745. * supposed to schedule for periodic transfers). That's according to spec.
  746. *
  747. * Note that though we only schedule 80% of each microframe, the bitmap that we
  748. * keep the schedule in is tightly packed (AKA it doesn't have 100us worth of
  749. * space for each uFrame).
  750. *
  751. * Requirements:
  752. * - DWC2_HS_SCHEDULE_UFRAMES must even divide 0x4000 (HFNUM_MAX_FRNUM + 1)
  753. * - DWC2_HS_SCHEDULE_UFRAMES must be 8 times DWC2_LS_SCHEDULE_FRAMES (probably
  754. * could be any multiple of 8 times DWC2_LS_SCHEDULE_FRAMES, but there might
  755. * be bugs). The 8 comes from the USB spec: number of microframes per frame.
  756. */
  757. #define DWC2_US_PER_UFRAME 125
  758. #define DWC2_HS_PERIODIC_US_PER_UFRAME 100
  759. #define DWC2_HS_SCHEDULE_UFRAMES 8
  760. #define DWC2_HS_SCHEDULE_US (DWC2_HS_SCHEDULE_UFRAMES * \
  761. DWC2_HS_PERIODIC_US_PER_UFRAME)
  762. /*
  763. * Constants related to low speed scheduling
  764. *
  765. * For high speed we schedule every 1us. For low speed that's a bit overkill,
  766. * so we make up a unit called a "slice" that's worth 25us. There are 40
  767. * slices in a full frame and we can schedule 36 of those (90%) for periodic
  768. * transfers.
  769. *
  770. * Our low speed schedule can be as short as 1 frame or could be longer. When
  771. * we only schedule 1 frame it means that we'll need to reserve a time every
  772. * frame even for things that only transfer very rarely, so something that runs
  773. * every 2048 frames will get time reserved in every frame. Our low speed
  774. * schedule can be longer and we'll be able to handle more overlap, but that
  775. * will come at increased memory cost and increased time to schedule.
  776. *
  777. * Note: one other advantage of a short low speed schedule is that if we mess
  778. * up and miss scheduling we can jump in and use any of the slots that we
  779. * happened to reserve.
  780. *
  781. * With 25 us per slice and 1 frame in the schedule, we only need 4 bytes for
  782. * the schedule. There will be one schedule per TT.
  783. *
  784. * Requirements:
  785. * - DWC2_US_PER_SLICE must evenly divide DWC2_LS_PERIODIC_US_PER_FRAME.
  786. */
  787. #define DWC2_US_PER_SLICE 25
  788. #define DWC2_SLICES_PER_UFRAME (DWC2_US_PER_UFRAME / DWC2_US_PER_SLICE)
  789. #define DWC2_ROUND_US_TO_SLICE(us) \
  790. (DIV_ROUND_UP((us), DWC2_US_PER_SLICE) * \
  791. DWC2_US_PER_SLICE)
  792. #define DWC2_LS_PERIODIC_US_PER_FRAME \
  793. 900
  794. #define DWC2_LS_PERIODIC_SLICES_PER_FRAME \
  795. (DWC2_LS_PERIODIC_US_PER_FRAME / \
  796. DWC2_US_PER_SLICE)
  797. #define DWC2_LS_SCHEDULE_FRAMES 1
  798. #define DWC2_LS_SCHEDULE_SLICES (DWC2_LS_SCHEDULE_FRAMES * \
  799. DWC2_LS_PERIODIC_SLICES_PER_FRAME)
  800. /**
  801. * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
  802. * and periodic schedules
  803. *
  804. * These are common for both host and peripheral modes:
  805. *
  806. * @dev: The struct device pointer
  807. * @regs: Pointer to controller regs
  808. * @hw_params: Parameters that were autodetected from the
  809. * hardware registers
  810. * @params: Parameters that define how the core should be configured
  811. * @op_state: The operational State, during transitions (a_host=>
  812. * a_peripheral and b_device=>b_host) this may not match
  813. * the core, but allows the software to determine
  814. * transitions
  815. * @dr_mode: Requested mode of operation, one of following:
  816. * - USB_DR_MODE_PERIPHERAL
  817. * - USB_DR_MODE_HOST
  818. * - USB_DR_MODE_OTG
  819. * @role_sw: usb_role_switch handle
  820. * @role_sw_default_mode: default operation mode of controller while usb role
  821. * is USB_ROLE_NONE
  822. * @hcd_enabled: Host mode sub-driver initialization indicator.
  823. * @gadget_enabled: Peripheral mode sub-driver initialization indicator.
  824. * @ll_hw_enabled: Status of low-level hardware resources.
  825. * @hibernated: True if core is hibernated
  826. * @in_ppd: True if core is partial power down mode.
  827. * @bus_suspended: True if bus is suspended
  828. * @reset_phy_on_wake: Quirk saying that we should assert PHY reset on a
  829. * remote wakeup.
  830. * @phy_off_for_suspend: Status of whether we turned the PHY off at suspend.
  831. * @need_phy_for_wake: Quirk saying that we should keep the PHY on at
  832. * suspend if we need USB to wake us up.
  833. * @frame_number: Frame number read from the core. For both device
  834. * and host modes. The value ranges are from 0
  835. * to HFNUM_MAX_FRNUM.
  836. * @phy: The otg phy transceiver structure for phy control.
  837. * @uphy: The otg phy transceiver structure for old USB phy
  838. * control.
  839. * @plat: The platform specific configuration data. This can be
  840. * removed once all SoCs support usb transceiver.
  841. * @supplies: Definition of USB power supplies
  842. * @vbus_supply: Regulator supplying vbus.
  843. * @usb33d: Optional 3.3v regulator used on some stm32 devices to
  844. * supply ID and VBUS detection hardware.
  845. * @lock: Spinlock that protects all the driver data structures
  846. * @priv: Stores a pointer to the struct usb_hcd
  847. * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
  848. * transfer are in process of being queued
  849. * @srp_success: Stores status of SRP request in the case of a FS PHY
  850. * with an I2C interface
  851. * @wq_otg: Workqueue object used for handling of some interrupts
  852. * @wf_otg: Work object for handling Connector ID Status Change
  853. * interrupt
  854. * @wkp_timer: Timer object for handling Wakeup Detected interrupt
  855. * @lx_state: Lx state of connected device
  856. * @gr_backup: Backup of global registers during suspend
  857. * @dr_backup: Backup of device registers during suspend
  858. * @hr_backup: Backup of host registers during suspend
  859. * @needs_byte_swap: Specifies whether the opposite endianness.
  860. *
  861. * These are for host mode:
  862. *
  863. * @flags: Flags for handling root port state changes
  864. * @flags.d32: Contain all root port flags
  865. * @flags.b: Separate root port flags from each other
  866. * @flags.b.port_connect_status_change: True if root port connect status
  867. * changed
  868. * @flags.b.port_connect_status: True if device connected to root port
  869. * @flags.b.port_reset_change: True if root port reset status changed
  870. * @flags.b.port_enable_change: True if root port enable status changed
  871. * @flags.b.port_suspend_change: True if root port suspend status changed
  872. * @flags.b.port_over_current_change: True if root port over current state
  873. * changed.
  874. * @flags.b.port_l1_change: True if root port l1 status changed
  875. * @flags.b.reserved: Reserved bits of root port register
  876. * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
  877. * Transfers associated with these QHs are not currently
  878. * assigned to a host channel.
  879. * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
  880. * Transfers associated with these QHs are currently
  881. * assigned to a host channel.
  882. * @non_periodic_qh_ptr: Pointer to next QH to process in the active
  883. * non-periodic schedule
  884. * @non_periodic_sched_waiting: Waiting QHs in the non-periodic schedule.
  885. * Transfers associated with these QHs are not currently
  886. * assigned to a host channel.
  887. * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
  888. * list of QHs for periodic transfers that are _not_
  889. * scheduled for the next frame. Each QH in the list has an
  890. * interval counter that determines when it needs to be
  891. * scheduled for execution. This scheduling mechanism
  892. * allows only a simple calculation for periodic bandwidth
  893. * used (i.e. must assume that all periodic transfers may
  894. * need to execute in the same frame). However, it greatly
  895. * simplifies scheduling and should be sufficient for the
  896. * vast majority of OTG hosts, which need to connect to a
  897. * small number of peripherals at one time. Items move from
  898. * this list to periodic_sched_ready when the QH interval
  899. * counter is 0 at SOF.
  900. * @periodic_sched_ready: List of periodic QHs that are ready for execution in
  901. * the next frame, but have not yet been assigned to host
  902. * channels. Items move from this list to
  903. * periodic_sched_assigned as host channels become
  904. * available during the current frame.
  905. * @periodic_sched_assigned: List of periodic QHs to be executed in the next
  906. * frame that are assigned to host channels. Items move
  907. * from this list to periodic_sched_queued as the
  908. * transactions for the QH are queued to the DWC_otg
  909. * controller.
  910. * @periodic_sched_queued: List of periodic QHs that have been queued for
  911. * execution. Items move from this list to either
  912. * periodic_sched_inactive or periodic_sched_ready when the
  913. * channel associated with the transfer is released. If the
  914. * interval for the QH is 1, the item moves to
  915. * periodic_sched_ready because it must be rescheduled for
  916. * the next frame. Otherwise, the item moves to
  917. * periodic_sched_inactive.
  918. * @split_order: List keeping track of channels doing splits, in order.
  919. * @periodic_usecs: Total bandwidth claimed so far for periodic transfers.
  920. * This value is in microseconds per (micro)frame. The
  921. * assumption is that all periodic transfers may occur in
  922. * the same (micro)frame.
  923. * @hs_periodic_bitmap: Bitmap used by the microframe scheduler any time the
  924. * host is in high speed mode; low speed schedules are
  925. * stored elsewhere since we need one per TT.
  926. * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
  927. * SOF enable/disable.
  928. * @free_hc_list: Free host channels in the controller. This is a list of
  929. * struct dwc2_host_chan items.
  930. * @periodic_channels: Number of host channels assigned to periodic transfers.
  931. * Currently assuming that there is a dedicated host
  932. * channel for each periodic transaction and at least one
  933. * host channel is available for non-periodic transactions.
  934. * @non_periodic_channels: Number of host channels assigned to non-periodic
  935. * transfers
  936. * @available_host_channels: Number of host channels available for the
  937. * microframe scheduler to use
  938. * @hc_ptr_array: Array of pointers to the host channel descriptors.
  939. * Allows accessing a host channel descriptor given the
  940. * host channel number. This is useful in interrupt
  941. * handlers.
  942. * @status_buf: Buffer used for data received during the status phase of
  943. * a control transfer.
  944. * @status_buf_dma: DMA address for status_buf
  945. * @start_work: Delayed work for handling host A-cable connection
  946. * @reset_work: Delayed work for handling a port reset
  947. * @phy_reset_work: Work structure for doing a PHY reset
  948. * @otg_port: OTG port number
  949. * @frame_list: Frame list
  950. * @frame_list_dma: Frame list DMA address
  951. * @frame_list_sz: Frame list size
  952. * @desc_gen_cache: Kmem cache for generic descriptors
  953. * @desc_hsisoc_cache: Kmem cache for hs isochronous descriptors
  954. * @unaligned_cache: Kmem cache for DMA mode to handle non-aligned buf
  955. *
  956. * These are for peripheral mode:
  957. *
  958. * @driver: USB gadget driver
  959. * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
  960. * @num_of_eps: Number of available EPs (excluding EP0)
  961. * @debug_root: Root directrory for debugfs.
  962. * @ep0_reply: Request used for ep0 reply.
  963. * @ep0_buff: Buffer for EP0 reply data, if needed.
  964. * @ctrl_buff: Buffer for EP0 control requests.
  965. * @ctrl_req: Request for EP0 control packets.
  966. * @ep0_state: EP0 control transfers state
  967. * @delayed_status: true when gadget driver asks for delayed status
  968. * @test_mode: USB test mode requested by the host
  969. * @remote_wakeup_allowed: True if device is allowed to wake-up host by
  970. * remote-wakeup signalling
  971. * @setup_desc_dma: EP0 setup stage desc chain DMA address
  972. * @setup_desc: EP0 setup stage desc chain pointer
  973. * @ctrl_in_desc_dma: EP0 IN data phase desc chain DMA address
  974. * @ctrl_in_desc: EP0 IN data phase desc chain pointer
  975. * @ctrl_out_desc_dma: EP0 OUT data phase desc chain DMA address
  976. * @ctrl_out_desc: EP0 OUT data phase desc chain pointer
  977. * @irq: Interrupt request line number
  978. * @clk: Pointer to otg clock
  979. * @utmi_clk: Pointer to utmi_clk clock
  980. * @reset: Pointer to dwc2 reset controller
  981. * @reset_ecc: Pointer to dwc2 optional reset controller in Stratix10.
  982. * @regset: A pointer to a struct debugfs_regset32, which contains
  983. * a pointer to an array of register definitions, the
  984. * array size and the base address where the register bank
  985. * is to be found.
  986. * @last_frame_num: Number of last frame. Range from 0 to 32768
  987. * @frame_num_array: Used only if CONFIG_USB_DWC2_TRACK_MISSED_SOFS is
  988. * defined, for missed SOFs tracking. Array holds that
  989. * frame numbers, which not equal to last_frame_num +1
  990. * @last_frame_num_array: Used only if CONFIG_USB_DWC2_TRACK_MISSED_SOFS is
  991. * defined, for missed SOFs tracking.
  992. * If current_frame_number != last_frame_num+1
  993. * then last_frame_num added to this array
  994. * @frame_num_idx: Actual size of frame_num_array and last_frame_num_array
  995. * @dumped_frame_num_array: 1 - if missed SOFs frame numbers dumbed
  996. * 0 - if missed SOFs frame numbers not dumbed
  997. * @fifo_mem: Total internal RAM for FIFOs (bytes)
  998. * @fifo_map: Each bit intend for concrete fifo. If that bit is set,
  999. * then that fifo is used
  1000. * @gadget: Represents a usb gadget device
  1001. * @connected: Used in slave mode. True if device connected with host
  1002. * @eps_in: The IN endpoints being supplied to the gadget framework
  1003. * @eps_out: The OUT endpoints being supplied to the gadget framework
  1004. * @new_connection: Used in host mode. True if there are new connected
  1005. * device
  1006. * @enabled: Indicates the enabling state of controller
  1007. *
  1008. */
  1009. struct dwc2_hsotg {
  1010. struct device *dev;
  1011. void __iomem *regs;
  1012. void __iomem *sys_regs;
  1013. int usb_id_reg;
  1014. int usb_id_bit_offset;
  1015. struct gpio_desc *gpiod_reset;
  1016. /** Params detected from hardware */
  1017. struct dwc2_hw_params hw_params;
  1018. /** Params to actually use */
  1019. struct dwc2_core_params params;
  1020. enum usb_otg_state op_state;
  1021. enum usb_dr_mode dr_mode;
  1022. struct usb_role_switch *role_sw;
  1023. enum usb_dr_mode role_sw_default_mode;
  1024. unsigned int hcd_enabled:1;
  1025. unsigned int gadget_enabled:1;
  1026. unsigned int ll_hw_enabled:1;
  1027. unsigned int hibernated:1;
  1028. unsigned int in_ppd:1;
  1029. bool bus_suspended;
  1030. unsigned int reset_phy_on_wake:1;
  1031. unsigned int need_phy_for_wake:1;
  1032. unsigned int phy_off_for_suspend:1;
  1033. u16 frame_number;
  1034. struct phy *phy;
  1035. struct usb_phy *uphy;
  1036. struct dwc2_hsotg_plat *plat;
  1037. struct regulator_bulk_data supplies[DWC2_NUM_SUPPLIES];
  1038. struct regulator *vbus_supply;
  1039. struct regulator *usb33d;
  1040. spinlock_t lock;
  1041. void *priv;
  1042. int irq;
  1043. struct clk *clk;
  1044. struct clk *utmi_clk;
  1045. struct reset_control *reset;
  1046. struct reset_control *reset_ecc;
  1047. unsigned int queuing_high_bandwidth:1;
  1048. unsigned int srp_success:1;
  1049. struct workqueue_struct *wq_otg;
  1050. struct work_struct wf_otg;
  1051. struct timer_list wkp_timer;
  1052. enum dwc2_lx_state lx_state;
  1053. struct dwc2_gregs_backup gr_backup;
  1054. struct dwc2_dregs_backup dr_backup;
  1055. struct dwc2_hregs_backup hr_backup;
  1056. struct dentry *debug_root;
  1057. struct debugfs_regset32 *regset;
  1058. bool needs_byte_swap;
  1059. /* DWC OTG HW Release versions */
  1060. #define DWC2_CORE_REV_4_30a 0x4f54430a
  1061. #define DWC2_CORE_REV_2_71a 0x4f54271a
  1062. #define DWC2_CORE_REV_2_72a 0x4f54272a
  1063. #define DWC2_CORE_REV_2_80a 0x4f54280a
  1064. #define DWC2_CORE_REV_2_90a 0x4f54290a
  1065. #define DWC2_CORE_REV_2_91a 0x4f54291a
  1066. #define DWC2_CORE_REV_2_92a 0x4f54292a
  1067. #define DWC2_CORE_REV_2_94a 0x4f54294a
  1068. #define DWC2_CORE_REV_3_00a 0x4f54300a
  1069. #define DWC2_CORE_REV_3_10a 0x4f54310a
  1070. #define DWC2_CORE_REV_4_00a 0x4f54400a
  1071. #define DWC2_CORE_REV_4_20a 0x4f54420a
  1072. #define DWC2_CORE_REV_5_00a 0x4f54500a
  1073. #define DWC2_FS_IOT_REV_1_00a 0x5531100a
  1074. #define DWC2_HS_IOT_REV_1_00a 0x5532100a
  1075. #define DWC2_HS_IOT_REV_5_00a 0x5532500a
  1076. #define DWC2_CORE_REV_MASK 0x0000ffff
  1077. /* DWC OTG HW Core ID */
  1078. #define DWC2_OTG_ID 0x4f540000
  1079. #define DWC2_FS_IOT_ID 0x55310000
  1080. #define DWC2_HS_IOT_ID 0x55320000
  1081. #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  1082. union dwc2_hcd_internal_flags {
  1083. u32 d32;
  1084. struct {
  1085. unsigned port_connect_status_change:1;
  1086. unsigned port_connect_status:1;
  1087. unsigned port_reset_change:1;
  1088. unsigned port_enable_change:1;
  1089. unsigned port_suspend_change:1;
  1090. unsigned port_over_current_change:1;
  1091. unsigned port_l1_change:1;
  1092. unsigned reserved:25;
  1093. } b;
  1094. } flags;
  1095. struct list_head non_periodic_sched_inactive;
  1096. struct list_head non_periodic_sched_waiting;
  1097. struct list_head non_periodic_sched_active;
  1098. struct list_head *non_periodic_qh_ptr;
  1099. struct list_head periodic_sched_inactive;
  1100. struct list_head periodic_sched_ready;
  1101. struct list_head periodic_sched_assigned;
  1102. struct list_head periodic_sched_queued;
  1103. struct list_head split_order;
  1104. u16 periodic_usecs;
  1105. DECLARE_BITMAP(hs_periodic_bitmap, DWC2_HS_SCHEDULE_US);
  1106. u16 periodic_qh_count;
  1107. bool new_connection;
  1108. u16 last_frame_num;
  1109. #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
  1110. #define FRAME_NUM_ARRAY_SIZE 1000
  1111. u16 *frame_num_array;
  1112. u16 *last_frame_num_array;
  1113. int frame_num_idx;
  1114. int dumped_frame_num_array;
  1115. #endif
  1116. struct list_head free_hc_list;
  1117. int periodic_channels;
  1118. int non_periodic_channels;
  1119. int available_host_channels;
  1120. struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
  1121. u8 *status_buf;
  1122. dma_addr_t status_buf_dma;
  1123. #define DWC2_HCD_STATUS_BUF_SIZE 64
  1124. struct delayed_work start_work;
  1125. struct delayed_work reset_work;
  1126. struct work_struct phy_reset_work;
  1127. u8 otg_port;
  1128. u32 *frame_list;
  1129. dma_addr_t frame_list_dma;
  1130. u32 frame_list_sz;
  1131. struct kmem_cache *desc_gen_cache;
  1132. struct kmem_cache *desc_hsisoc_cache;
  1133. struct kmem_cache *unaligned_cache;
  1134. #define DWC2_KMEM_UNALIGNED_BUF_SIZE 1024
  1135. #endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
  1136. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
  1137. IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  1138. /* Gadget structures */
  1139. struct usb_gadget_driver *driver;
  1140. int fifo_mem;
  1141. unsigned int dedicated_fifos:1;
  1142. unsigned char num_of_eps;
  1143. u32 fifo_map;
  1144. struct usb_request *ep0_reply;
  1145. struct usb_request *ctrl_req;
  1146. void *ep0_buff;
  1147. void *ctrl_buff;
  1148. enum dwc2_ep0_state ep0_state;
  1149. unsigned delayed_status : 1;
  1150. u8 test_mode;
  1151. dma_addr_t setup_desc_dma[2];
  1152. struct dwc2_dma_desc *setup_desc[2];
  1153. dma_addr_t ctrl_in_desc_dma;
  1154. struct dwc2_dma_desc *ctrl_in_desc;
  1155. dma_addr_t ctrl_out_desc_dma;
  1156. struct dwc2_dma_desc *ctrl_out_desc;
  1157. struct usb_gadget gadget;
  1158. unsigned int enabled:1;
  1159. unsigned int connected:1;
  1160. unsigned int remote_wakeup_allowed:1;
  1161. struct dwc2_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
  1162. struct dwc2_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
  1163. #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
  1164. };
  1165. /* Normal architectures just use readl/write */
  1166. static inline u32 dwc2_readl(struct dwc2_hsotg *hsotg, u32 offset)
  1167. {
  1168. u32 val;
  1169. val = readl(hsotg->regs + offset);
  1170. if (hsotg->needs_byte_swap)
  1171. return swab32(val);
  1172. else
  1173. return val;
  1174. }
  1175. static inline void dwc2_writel(struct dwc2_hsotg *hsotg, u32 value, u32 offset)
  1176. {
  1177. if (hsotg->needs_byte_swap)
  1178. writel(swab32(value), hsotg->regs + offset);
  1179. else
  1180. writel(value, hsotg->regs + offset);
  1181. #ifdef DWC2_LOG_WRITES
  1182. pr_info("info:: wrote %08x to %p\n", value, hsotg->regs + offset);
  1183. #endif
  1184. }
  1185. static inline void dwc2_readl_rep(struct dwc2_hsotg *hsotg, u32 offset,
  1186. void *buffer, unsigned int count)
  1187. {
  1188. if (count) {
  1189. u32 *buf = buffer;
  1190. do {
  1191. u32 x = dwc2_readl(hsotg, offset);
  1192. *buf++ = x;
  1193. } while (--count);
  1194. }
  1195. }
  1196. static inline void dwc2_writel_rep(struct dwc2_hsotg *hsotg, u32 offset,
  1197. const void *buffer, unsigned int count)
  1198. {
  1199. if (count) {
  1200. const u32 *buf = buffer;
  1201. do {
  1202. dwc2_writel(hsotg, *buf++, offset);
  1203. } while (--count);
  1204. }
  1205. }
  1206. /* Reasons for halting a host channel */
  1207. enum dwc2_halt_status {
  1208. DWC2_HC_XFER_NO_HALT_STATUS,
  1209. DWC2_HC_XFER_COMPLETE,
  1210. DWC2_HC_XFER_URB_COMPLETE,
  1211. DWC2_HC_XFER_ACK,
  1212. DWC2_HC_XFER_NAK,
  1213. DWC2_HC_XFER_NYET,
  1214. DWC2_HC_XFER_STALL,
  1215. DWC2_HC_XFER_XACT_ERR,
  1216. DWC2_HC_XFER_FRAME_OVERRUN,
  1217. DWC2_HC_XFER_BABBLE_ERR,
  1218. DWC2_HC_XFER_DATA_TOGGLE_ERR,
  1219. DWC2_HC_XFER_AHB_ERR,
  1220. DWC2_HC_XFER_PERIODIC_INCOMPLETE,
  1221. DWC2_HC_XFER_URB_DEQUEUE,
  1222. };
  1223. /* Core version information */
  1224. static inline bool dwc2_is_iot(struct dwc2_hsotg *hsotg)
  1225. {
  1226. return (hsotg->hw_params.snpsid & 0xfff00000) == 0x55300000;
  1227. }
  1228. static inline bool dwc2_is_fs_iot(struct dwc2_hsotg *hsotg)
  1229. {
  1230. return (hsotg->hw_params.snpsid & 0xffff0000) == 0x55310000;
  1231. }
  1232. static inline bool dwc2_is_hs_iot(struct dwc2_hsotg *hsotg)
  1233. {
  1234. return (hsotg->hw_params.snpsid & 0xffff0000) == 0x55320000;
  1235. }
  1236. /*
  1237. * The following functions support initialization of the core driver component
  1238. * and the DWC_otg controller
  1239. */
  1240. int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait);
  1241. int dwc2_enter_partial_power_down(struct dwc2_hsotg *hsotg);
  1242. int dwc2_exit_partial_power_down(struct dwc2_hsotg *hsotg, int rem_wakeup,
  1243. bool restore);
  1244. int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg, int is_host);
  1245. int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup,
  1246. int reset, int is_host);
  1247. void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg);
  1248. int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy);
  1249. void dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host);
  1250. void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg);
  1251. bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
  1252. int dwc2_check_core_version(struct dwc2_hsotg *hsotg);
  1253. /*
  1254. * Common core Functions.
  1255. * The following functions support managing the DWC_otg controller in either
  1256. * device or host mode.
  1257. */
  1258. void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
  1259. void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
  1260. void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
  1261. void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
  1262. void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
  1263. void dwc2_hib_restore_common(struct dwc2_hsotg *hsotg, int rem_wakeup,
  1264. int is_host);
  1265. int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg);
  1266. int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg);
  1267. void dwc2_enable_acg(struct dwc2_hsotg *hsotg);
  1268. void dwc2_wakeup_from_lpm_l1(struct dwc2_hsotg *hsotg, bool remotewakeup);
  1269. /* This function should be called on every hardware interrupt. */
  1270. irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
  1271. /* The device ID match table */
  1272. extern const struct of_device_id dwc2_of_match_table[];
  1273. extern const struct acpi_device_id dwc2_acpi_match[];
  1274. extern const struct pci_device_id dwc2_pci_ids[];
  1275. int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg);
  1276. int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);
  1277. /* Common polling functions */
  1278. int dwc2_hsotg_wait_bit_set(struct dwc2_hsotg *hs_otg, u32 reg, u32 bit,
  1279. u32 timeout);
  1280. int dwc2_hsotg_wait_bit_clear(struct dwc2_hsotg *hs_otg, u32 reg, u32 bit,
  1281. u32 timeout);
  1282. /* Parameters */
  1283. int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
  1284. int dwc2_init_params(struct dwc2_hsotg *hsotg);
  1285. /*
  1286. * The following functions check the controller's OTG operation mode
  1287. * capability (GHWCFG2.OTG_MODE).
  1288. *
  1289. * These functions can be used before the internal hsotg->hw_params
  1290. * are read in and cached so they always read directly from the
  1291. * GHWCFG2 register.
  1292. */
  1293. unsigned int dwc2_op_mode(struct dwc2_hsotg *hsotg);
  1294. bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg);
  1295. bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg);
  1296. bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg);
  1297. /*
  1298. * Returns the mode of operation, host or device
  1299. */
  1300. static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg)
  1301. {
  1302. return (dwc2_readl(hsotg, GINTSTS) & GINTSTS_CURMODE_HOST) != 0;
  1303. }
  1304. static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg)
  1305. {
  1306. return (dwc2_readl(hsotg, GINTSTS) & GINTSTS_CURMODE_HOST) == 0;
  1307. }
  1308. int dwc2_drd_init(struct dwc2_hsotg *hsotg);
  1309. void dwc2_drd_suspend(struct dwc2_hsotg *hsotg);
  1310. void dwc2_drd_resume(struct dwc2_hsotg *hsotg);
  1311. void dwc2_drd_exit(struct dwc2_hsotg *hsotg);
  1312. /*
  1313. * Dump core registers and SPRAM
  1314. */
  1315. void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
  1316. void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
  1317. void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
  1318. /* Gadget defines */
  1319. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
  1320. IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  1321. int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg);
  1322. int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2);
  1323. int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2);
  1324. int dwc2_gadget_init(struct dwc2_hsotg *hsotg);
  1325. void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
  1326. bool reset);
  1327. void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg);
  1328. void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg);
  1329. void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2);
  1330. int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
  1331. #define dwc2_is_device_connected(hsotg) (hsotg->connected)
  1332. #define dwc2_is_device_enabled(hsotg) (hsotg->enabled)
  1333. int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg);
  1334. int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, int remote_wakeup);
  1335. int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg);
  1336. int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg,
  1337. int rem_wakeup, int reset);
  1338. int dwc2_gadget_enter_partial_power_down(struct dwc2_hsotg *hsotg);
  1339. int dwc2_gadget_exit_partial_power_down(struct dwc2_hsotg *hsotg,
  1340. bool restore);
  1341. void dwc2_gadget_enter_clock_gating(struct dwc2_hsotg *hsotg);
  1342. void dwc2_gadget_exit_clock_gating(struct dwc2_hsotg *hsotg,
  1343. int rem_wakeup);
  1344. int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg);
  1345. int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg);
  1346. int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg);
  1347. void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg);
  1348. void dwc2_gadget_program_ref_clk(struct dwc2_hsotg *hsotg);
  1349. static inline void dwc2_clear_fifo_map(struct dwc2_hsotg *hsotg)
  1350. { hsotg->fifo_map = 0; }
  1351. #else
  1352. static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2)
  1353. { return 0; }
  1354. static inline int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2)
  1355. { return 0; }
  1356. static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2)
  1357. { return 0; }
  1358. static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
  1359. { return 0; }
  1360. static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
  1361. bool reset) {}
  1362. static inline void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) {}
  1363. static inline void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
  1364. static inline void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
  1365. static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
  1366. int testmode)
  1367. { return 0; }
  1368. #define dwc2_is_device_connected(hsotg) (0)
  1369. #define dwc2_is_device_enabled(hsotg) (0)
  1370. static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
  1371. { return 0; }
  1372. static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg,
  1373. int remote_wakeup)
  1374. { return 0; }
  1375. static inline int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg)
  1376. { return 0; }
  1377. static inline int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg,
  1378. int rem_wakeup, int reset)
  1379. { return 0; }
  1380. static inline int dwc2_gadget_enter_partial_power_down(struct dwc2_hsotg *hsotg)
  1381. { return 0; }
  1382. static inline int dwc2_gadget_exit_partial_power_down(struct dwc2_hsotg *hsotg,
  1383. bool restore)
  1384. { return 0; }
  1385. static inline void dwc2_gadget_enter_clock_gating(struct dwc2_hsotg *hsotg) {}
  1386. static inline void dwc2_gadget_exit_clock_gating(struct dwc2_hsotg *hsotg,
  1387. int rem_wakeup) {}
  1388. static inline int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
  1389. { return 0; }
  1390. static inline int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
  1391. { return 0; }
  1392. static inline int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg)
  1393. { return 0; }
  1394. static inline void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg) {}
  1395. static inline void dwc2_gadget_program_ref_clk(struct dwc2_hsotg *hsotg) {}
  1396. static inline void dwc2_clear_fifo_map(struct dwc2_hsotg *hsotg) {}
  1397. #endif
  1398. #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  1399. int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
  1400. int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us);
  1401. void dwc2_hcd_connect(struct dwc2_hsotg *hsotg);
  1402. void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force);
  1403. void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
  1404. int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup);
  1405. int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex);
  1406. int dwc2_port_resume(struct dwc2_hsotg *hsotg);
  1407. int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg);
  1408. int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg);
  1409. int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg);
  1410. int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg,
  1411. int rem_wakeup, int reset);
  1412. int dwc2_host_enter_partial_power_down(struct dwc2_hsotg *hsotg);
  1413. int dwc2_host_exit_partial_power_down(struct dwc2_hsotg *hsotg,
  1414. int rem_wakeup, bool restore);
  1415. void dwc2_host_enter_clock_gating(struct dwc2_hsotg *hsotg);
  1416. void dwc2_host_exit_clock_gating(struct dwc2_hsotg *hsotg, int rem_wakeup);
  1417. bool dwc2_host_can_poweroff_phy(struct dwc2_hsotg *dwc2);
  1418. static inline void dwc2_host_schedule_phy_reset(struct dwc2_hsotg *hsotg)
  1419. { schedule_work(&hsotg->phy_reset_work); }
  1420. #else
  1421. static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
  1422. { return 0; }
  1423. static inline int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg,
  1424. int us)
  1425. { return 0; }
  1426. static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {}
  1427. static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {}
  1428. static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
  1429. static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
  1430. static inline int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup)
  1431. { return 0; }
  1432. static inline int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
  1433. { return 0; }
  1434. static inline int dwc2_port_resume(struct dwc2_hsotg *hsotg)
  1435. { return 0; }
  1436. static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg)
  1437. { return 0; }
  1438. static inline int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
  1439. { return 0; }
  1440. static inline int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
  1441. { return 0; }
  1442. static inline int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg)
  1443. { return 0; }
  1444. static inline int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg,
  1445. int rem_wakeup, int reset)
  1446. { return 0; }
  1447. static inline int dwc2_host_enter_partial_power_down(struct dwc2_hsotg *hsotg)
  1448. { return 0; }
  1449. static inline int dwc2_host_exit_partial_power_down(struct dwc2_hsotg *hsotg,
  1450. int rem_wakeup, bool restore)
  1451. { return 0; }
  1452. static inline void dwc2_host_enter_clock_gating(struct dwc2_hsotg *hsotg) {}
  1453. static inline void dwc2_host_exit_clock_gating(struct dwc2_hsotg *hsotg,
  1454. int rem_wakeup) {}
  1455. static inline bool dwc2_host_can_poweroff_phy(struct dwc2_hsotg *dwc2)
  1456. { return false; }
  1457. static inline void dwc2_host_schedule_phy_reset(struct dwc2_hsotg *hsotg) {}
  1458. #endif
  1459. #endif /* __DWC2_CORE_H__ */