core.h 52 KB

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