core.h 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  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. /*
  237. * Gadget periodic tx fifo sizes as used by legacy driver
  238. * EP0 is not included
  239. */
  240. #define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 256, 256, 256, 768, 768, 768, \
  241. 768, 0, 0, 0, 0, 0, 0, 0}
  242. /* Gadget ep0 states */
  243. enum dwc2_ep0_state {
  244. DWC2_EP0_SETUP,
  245. DWC2_EP0_DATA_IN,
  246. DWC2_EP0_DATA_OUT,
  247. DWC2_EP0_STATUS_IN,
  248. DWC2_EP0_STATUS_OUT,
  249. };
  250. /**
  251. * struct dwc2_core_params - Parameters for configuring the core
  252. *
  253. * @otg_cap: Specifies the OTG capabilities.
  254. * 0 - HNP and SRP capable
  255. * 1 - SRP Only capable
  256. * 2 - No HNP/SRP capable (always available)
  257. * Defaults to best available option (0, 1, then 2)
  258. * @otg_ver: OTG version supported
  259. * 0 - 1.3 (default)
  260. * 1 - 2.0
  261. * @host_dma: Specifies whether to use slave or DMA mode for accessing
  262. * the data FIFOs. The driver will automatically detect the
  263. * value for this parameter if none is specified.
  264. * 0 - Slave (always available)
  265. * 1 - DMA (default, if available)
  266. * @dma_desc_enable: When DMA mode is enabled, specifies whether to use
  267. * address DMA mode or descriptor DMA mode for accessing
  268. * the data FIFOs. The driver will automatically detect the
  269. * value for this if none is specified.
  270. * 0 - Address DMA
  271. * 1 - Descriptor DMA (default, if available)
  272. * @dma_desc_fs_enable: When DMA mode is enabled, specifies whether to use
  273. * address DMA mode or descriptor DMA mode for accessing
  274. * the data FIFOs in Full Speed mode only. The driver
  275. * will automatically detect the value for this if none is
  276. * specified.
  277. * 0 - Address DMA
  278. * 1 - Descriptor DMA in FS (default, if available)
  279. * @speed: Specifies the maximum speed of operation in host and
  280. * device mode. The actual speed depends on the speed of
  281. * the attached device and the value of phy_type.
  282. * 0 - High Speed
  283. * (default when phy_type is UTMI+ or ULPI)
  284. * 1 - Full Speed
  285. * (default when phy_type is Full Speed)
  286. * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
  287. * 1 - Allow dynamic FIFO sizing (default, if available)
  288. * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
  289. * are enabled for non-periodic IN endpoints in device
  290. * mode.
  291. * @host_rx_fifo_size: Number of 4-byte words in the Rx FIFO in host mode when
  292. * dynamic FIFO sizing is enabled
  293. * 16 to 32768
  294. * Actual maximum value is autodetected and also
  295. * the default.
  296. * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
  297. * in host mode when dynamic FIFO sizing is enabled
  298. * 16 to 32768
  299. * Actual maximum value is autodetected and also
  300. * the default.
  301. * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
  302. * host mode when dynamic FIFO sizing is enabled
  303. * 16 to 32768
  304. * Actual maximum value is autodetected and also
  305. * the default.
  306. * @max_transfer_size: The maximum transfer size supported, in bytes
  307. * 2047 to 65,535
  308. * Actual maximum value is autodetected and also
  309. * the default.
  310. * @max_packet_count: The maximum number of packets in a transfer
  311. * 15 to 511
  312. * Actual maximum value is autodetected and also
  313. * the default.
  314. * @host_channels: The number of host channel registers to use
  315. * 1 to 16
  316. * Actual maximum value is autodetected and also
  317. * the default.
  318. * @phy_type: Specifies the type of PHY interface to use. By default,
  319. * the driver will automatically detect the phy_type.
  320. * 0 - Full Speed Phy
  321. * 1 - UTMI+ Phy
  322. * 2 - ULPI Phy
  323. * Defaults to best available option (2, 1, then 0)
  324. * @phy_utmi_width: Specifies the UTMI+ Data Width (in bits). This parameter
  325. * is applicable for a phy_type of UTMI+ or ULPI. (For a
  326. * ULPI phy_type, this parameter indicates the data width
  327. * between the MAC and the ULPI Wrapper.) Also, this
  328. * parameter is applicable only if the OTG_HSPHY_WIDTH cC
  329. * parameter was set to "8 and 16 bits", meaning that the
  330. * core has been configured to work at either data path
  331. * width.
  332. * 8 or 16 (default 16 if available)
  333. * @phy_ulpi_ddr: Specifies whether the ULPI operates at double or single
  334. * data rate. This parameter is only applicable if phy_type
  335. * is ULPI.
  336. * 0 - single data rate ULPI interface with 8 bit wide
  337. * data bus (default)
  338. * 1 - double data rate ULPI interface with 4 bit wide
  339. * data bus
  340. * @phy_ulpi_ext_vbus: For a ULPI phy, specifies whether to use the internal or
  341. * external supply to drive the VBus
  342. * 0 - Internal supply (default)
  343. * 1 - External supply
  344. * @i2c_enable: Specifies whether to use the I2Cinterface for a full
  345. * speed PHY. This parameter is only applicable if phy_type
  346. * is FS.
  347. * 0 - No (default)
  348. * 1 - Yes
  349. * @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
  350. * 0 - No (default)
  351. * 1 - Yes
  352. * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
  353. * when attached to a Full Speed or Low Speed device in
  354. * host mode.
  355. * 0 - Don't support low power mode (default)
  356. * 1 - Support low power mode
  357. * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
  358. * when connected to a Low Speed device in host
  359. * mode. This parameter is applicable only if
  360. * host_support_fs_ls_low_power is enabled.
  361. * 0 - 48 MHz
  362. * (default when phy_type is UTMI+ or ULPI)
  363. * 1 - 6 MHz
  364. * (default when phy_type is Full Speed)
  365. * @ts_dline: Enable Term Select Dline pulsing
  366. * 0 - No (default)
  367. * 1 - Yes
  368. * @reload_ctl: Allow dynamic reloading of HFIR register during runtime
  369. * 0 - No (default for core < 2.92a)
  370. * 1 - Yes (default for core >= 2.92a)
  371. * @ahbcfg: This field allows the default value of the GAHBCFG
  372. * register to be overridden
  373. * -1 - GAHBCFG value will be set to 0x06
  374. * (INCR4, default)
  375. * all others - GAHBCFG value will be overridden with
  376. * this value
  377. * Not all bits can be controlled like this, the
  378. * bits defined by GAHBCFG_CTRL_MASK are controlled
  379. * by the driver and are ignored in this
  380. * configuration value.
  381. * @uframe_sched: True to enable the microframe scheduler
  382. * @external_id_pin_ctl: Specifies whether ID pin is handled externally.
  383. * Disable CONIDSTSCHNG controller interrupt in such
  384. * case.
  385. * 0 - No (default)
  386. * 1 - Yes
  387. * @hibernation: Specifies whether the controller support hibernation.
  388. * If hibernation is enabled, the controller will enter
  389. * hibernation in both peripheral and host mode when
  390. * needed.
  391. * 0 - No (default)
  392. * 1 - Yes
  393. * @g_dma: If true, enables dma usage on the device. This
  394. * setting is not auto-detected. It must be
  395. * explicitly enabled (default: false).
  396. * @g_rx_fifo_size: The periodic rx fifo size for the device, in
  397. * DWORDS from 16-32768 (default: 2048 if
  398. * possible, otherwise autodetect).
  399. * @g_np_tx_fifo_size: The non-periodic tx fifo size for the device in
  400. * DWORDS from 16-32768 (default: 1024 if
  401. * possible, otherwise autodetect).
  402. * @g_tx_fifo_size: An array of TX fifo sizes in dedicated fifo
  403. * mode. Each value corresponds to one EP
  404. * starting from EP1 (max 15 values). Sizes are
  405. * in DWORDS with possible values from from
  406. * 16-32768 (default: 256, 256, 256, 256, 768,
  407. * 768, 768, 768, 0, 0, 0, 0, 0, 0, 0).
  408. *
  409. * The following parameters may be specified when starting the module. These
  410. * parameters define how the DWC_otg controller should be configured. A
  411. * value of -1 (or any other out of range value) for any parameter means
  412. * to read the value from hardware (if possible) or use the builtin
  413. * default described above.
  414. */
  415. struct dwc2_core_params {
  416. /*
  417. * Don't add any non-int members here, this will break
  418. * dwc2_set_all_params!
  419. */
  420. int otg_cap;
  421. #define DWC2_CAP_PARAM_HNP_SRP_CAPABLE 0
  422. #define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE 1
  423. #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  424. int otg_ver;
  425. int dma_desc_enable;
  426. int dma_desc_fs_enable;
  427. int speed;
  428. #define DWC2_SPEED_PARAM_HIGH 0
  429. #define DWC2_SPEED_PARAM_FULL 1
  430. int enable_dynamic_fifo;
  431. int en_multiple_tx_fifo;
  432. int host_rx_fifo_size;
  433. int host_nperio_tx_fifo_size;
  434. int host_perio_tx_fifo_size;
  435. int max_transfer_size;
  436. int max_packet_count;
  437. int host_channels;
  438. int phy_type;
  439. #define DWC2_PHY_TYPE_PARAM_FS 0
  440. #define DWC2_PHY_TYPE_PARAM_UTMI 1
  441. #define DWC2_PHY_TYPE_PARAM_ULPI 2
  442. int phy_utmi_width;
  443. int phy_ulpi_ddr;
  444. int phy_ulpi_ext_vbus;
  445. #define DWC2_PHY_ULPI_INTERNAL_VBUS 0
  446. #define DWC2_PHY_ULPI_EXTERNAL_VBUS 1
  447. int i2c_enable;
  448. int ulpi_fs_ls;
  449. int host_support_fs_ls_low_power;
  450. int host_ls_low_power_phy_clk;
  451. #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  452. #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  453. int ts_dline;
  454. int reload_ctl;
  455. int ahbcfg;
  456. int uframe_sched;
  457. int external_id_pin_ctl;
  458. int hibernation;
  459. /*
  460. * The following parameters are *only* set via device
  461. * properties and cannot be set directly in this structure.
  462. */
  463. /* Host parameters */
  464. bool host_dma;
  465. /* Gadget parameters */
  466. bool g_dma;
  467. u16 g_rx_fifo_size;
  468. u16 g_np_tx_fifo_size;
  469. u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
  470. };
  471. /**
  472. * struct dwc2_hw_params - Autodetected parameters.
  473. *
  474. * These parameters are the various parameters read from hardware
  475. * registers during initialization. They typically contain the best
  476. * supported or maximum value that can be configured in the
  477. * corresponding dwc2_core_params value.
  478. *
  479. * The values that are not in dwc2_core_params are documented below.
  480. *
  481. * @op_mode Mode of Operation
  482. * 0 - HNP- and SRP-Capable OTG (Host & Device)
  483. * 1 - SRP-Capable OTG (Host & Device)
  484. * 2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
  485. * 3 - SRP-Capable Device
  486. * 4 - Non-OTG Device
  487. * 5 - SRP-Capable Host
  488. * 6 - Non-OTG Host
  489. * @arch Architecture
  490. * 0 - Slave only
  491. * 1 - External DMA
  492. * 2 - Internal DMA
  493. * @power_optimized Are power optimizations enabled?
  494. * @num_dev_ep Number of device endpoints available
  495. * @num_dev_perio_in_ep Number of device periodic IN endpoints
  496. * available
  497. * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
  498. * Depth
  499. * 0 to 30
  500. * @host_perio_tx_q_depth
  501. * Host Mode Periodic Request Queue Depth
  502. * 2, 4 or 8
  503. * @nperio_tx_q_depth
  504. * Non-Periodic Request Queue Depth
  505. * 2, 4 or 8
  506. * @hs_phy_type High-speed PHY interface type
  507. * 0 - High-speed interface not supported
  508. * 1 - UTMI+
  509. * 2 - ULPI
  510. * 3 - UTMI+ and ULPI
  511. * @fs_phy_type Full-speed PHY interface type
  512. * 0 - Full speed interface not supported
  513. * 1 - Dedicated full speed interface
  514. * 2 - FS pins shared with UTMI+ pins
  515. * 3 - FS pins shared with ULPI pins
  516. * @total_fifo_size: Total internal RAM for FIFOs (bytes)
  517. * @utmi_phy_data_width UTMI+ PHY data width
  518. * 0 - 8 bits
  519. * 1 - 16 bits
  520. * 2 - 8 or 16 bits
  521. * @snpsid: Value from SNPSID register
  522. * @dev_ep_dirs: Direction of device endpoints (GHWCFG1)
  523. */
  524. struct dwc2_hw_params {
  525. unsigned op_mode:3;
  526. unsigned arch:2;
  527. unsigned dma_desc_enable:1;
  528. unsigned enable_dynamic_fifo:1;
  529. unsigned en_multiple_tx_fifo:1;
  530. unsigned rx_fifo_size:16;
  531. unsigned host_nperio_tx_fifo_size:16;
  532. unsigned dev_nperio_tx_fifo_size:16;
  533. unsigned host_perio_tx_fifo_size:16;
  534. unsigned nperio_tx_q_depth:3;
  535. unsigned host_perio_tx_q_depth:3;
  536. unsigned dev_token_q_depth:5;
  537. unsigned max_transfer_size:26;
  538. unsigned max_packet_count:11;
  539. unsigned host_channels:5;
  540. unsigned hs_phy_type:2;
  541. unsigned fs_phy_type:2;
  542. unsigned i2c_enable:1;
  543. unsigned num_dev_ep:4;
  544. unsigned num_dev_perio_in_ep:4;
  545. unsigned total_fifo_size:16;
  546. unsigned power_optimized:1;
  547. unsigned utmi_phy_data_width:2;
  548. u32 snpsid;
  549. u32 dev_ep_dirs;
  550. };
  551. /* Size of control and EP0 buffers */
  552. #define DWC2_CTRL_BUFF_SIZE 8
  553. /**
  554. * struct dwc2_gregs_backup - Holds global registers state before entering partial
  555. * power down
  556. * @gotgctl: Backup of GOTGCTL register
  557. * @gintmsk: Backup of GINTMSK register
  558. * @gahbcfg: Backup of GAHBCFG register
  559. * @gusbcfg: Backup of GUSBCFG register
  560. * @grxfsiz: Backup of GRXFSIZ register
  561. * @gnptxfsiz: Backup of GNPTXFSIZ register
  562. * @gi2cctl: Backup of GI2CCTL register
  563. * @hptxfsiz: Backup of HPTXFSIZ register
  564. * @gdfifocfg: Backup of GDFIFOCFG register
  565. * @dtxfsiz: Backup of DTXFSIZ registers for each endpoint
  566. * @gpwrdn: Backup of GPWRDN register
  567. */
  568. struct dwc2_gregs_backup {
  569. u32 gotgctl;
  570. u32 gintmsk;
  571. u32 gahbcfg;
  572. u32 gusbcfg;
  573. u32 grxfsiz;
  574. u32 gnptxfsiz;
  575. u32 gi2cctl;
  576. u32 hptxfsiz;
  577. u32 pcgcctl;
  578. u32 gdfifocfg;
  579. u32 dtxfsiz[MAX_EPS_CHANNELS];
  580. u32 gpwrdn;
  581. bool valid;
  582. };
  583. /**
  584. * struct dwc2_dregs_backup - Holds device registers state before entering partial
  585. * power down
  586. * @dcfg: Backup of DCFG register
  587. * @dctl: Backup of DCTL register
  588. * @daintmsk: Backup of DAINTMSK register
  589. * @diepmsk: Backup of DIEPMSK register
  590. * @doepmsk: Backup of DOEPMSK register
  591. * @diepctl: Backup of DIEPCTL register
  592. * @dieptsiz: Backup of DIEPTSIZ register
  593. * @diepdma: Backup of DIEPDMA register
  594. * @doepctl: Backup of DOEPCTL register
  595. * @doeptsiz: Backup of DOEPTSIZ register
  596. * @doepdma: Backup of DOEPDMA register
  597. */
  598. struct dwc2_dregs_backup {
  599. u32 dcfg;
  600. u32 dctl;
  601. u32 daintmsk;
  602. u32 diepmsk;
  603. u32 doepmsk;
  604. u32 diepctl[MAX_EPS_CHANNELS];
  605. u32 dieptsiz[MAX_EPS_CHANNELS];
  606. u32 diepdma[MAX_EPS_CHANNELS];
  607. u32 doepctl[MAX_EPS_CHANNELS];
  608. u32 doeptsiz[MAX_EPS_CHANNELS];
  609. u32 doepdma[MAX_EPS_CHANNELS];
  610. bool valid;
  611. };
  612. /**
  613. * struct dwc2_hregs_backup - Holds host registers state before entering partial
  614. * power down
  615. * @hcfg: Backup of HCFG register
  616. * @haintmsk: Backup of HAINTMSK register
  617. * @hcintmsk: Backup of HCINTMSK register
  618. * @hptr0: Backup of HPTR0 register
  619. * @hfir: Backup of HFIR register
  620. */
  621. struct dwc2_hregs_backup {
  622. u32 hcfg;
  623. u32 haintmsk;
  624. u32 hcintmsk[MAX_EPS_CHANNELS];
  625. u32 hprt0;
  626. u32 hfir;
  627. bool valid;
  628. };
  629. /*
  630. * Constants related to high speed periodic scheduling
  631. *
  632. * We have a periodic schedule that is DWC2_HS_SCHEDULE_UFRAMES long. From a
  633. * reservation point of view it's assumed that the schedule goes right back to
  634. * the beginning after the end of the schedule.
  635. *
  636. * What does that mean for scheduling things with a long interval? It means
  637. * we'll reserve time for them in every possible microframe that they could
  638. * ever be scheduled in. ...but we'll still only actually schedule them as
  639. * often as they were requested.
  640. *
  641. * We keep our schedule in a "bitmap" structure. This simplifies having
  642. * to keep track of and merge intervals: we just let the bitmap code do most
  643. * of the heavy lifting. In a way scheduling is much like memory allocation.
  644. *
  645. * We schedule 100us per uframe or 80% of 125us (the maximum amount you're
  646. * supposed to schedule for periodic transfers). That's according to spec.
  647. *
  648. * Note that though we only schedule 80% of each microframe, the bitmap that we
  649. * keep the schedule in is tightly packed (AKA it doesn't have 100us worth of
  650. * space for each uFrame).
  651. *
  652. * Requirements:
  653. * - DWC2_HS_SCHEDULE_UFRAMES must even divide 0x4000 (HFNUM_MAX_FRNUM + 1)
  654. * - DWC2_HS_SCHEDULE_UFRAMES must be 8 times DWC2_LS_SCHEDULE_FRAMES (probably
  655. * could be any multiple of 8 times DWC2_LS_SCHEDULE_FRAMES, but there might
  656. * be bugs). The 8 comes from the USB spec: number of microframes per frame.
  657. */
  658. #define DWC2_US_PER_UFRAME 125
  659. #define DWC2_HS_PERIODIC_US_PER_UFRAME 100
  660. #define DWC2_HS_SCHEDULE_UFRAMES 8
  661. #define DWC2_HS_SCHEDULE_US (DWC2_HS_SCHEDULE_UFRAMES * \
  662. DWC2_HS_PERIODIC_US_PER_UFRAME)
  663. /*
  664. * Constants related to low speed scheduling
  665. *
  666. * For high speed we schedule every 1us. For low speed that's a bit overkill,
  667. * so we make up a unit called a "slice" that's worth 25us. There are 40
  668. * slices in a full frame and we can schedule 36 of those (90%) for periodic
  669. * transfers.
  670. *
  671. * Our low speed schedule can be as short as 1 frame or could be longer. When
  672. * we only schedule 1 frame it means that we'll need to reserve a time every
  673. * frame even for things that only transfer very rarely, so something that runs
  674. * every 2048 frames will get time reserved in every frame. Our low speed
  675. * schedule can be longer and we'll be able to handle more overlap, but that
  676. * will come at increased memory cost and increased time to schedule.
  677. *
  678. * Note: one other advantage of a short low speed schedule is that if we mess
  679. * up and miss scheduling we can jump in and use any of the slots that we
  680. * happened to reserve.
  681. *
  682. * With 25 us per slice and 1 frame in the schedule, we only need 4 bytes for
  683. * the schedule. There will be one schedule per TT.
  684. *
  685. * Requirements:
  686. * - DWC2_US_PER_SLICE must evenly divide DWC2_LS_PERIODIC_US_PER_FRAME.
  687. */
  688. #define DWC2_US_PER_SLICE 25
  689. #define DWC2_SLICES_PER_UFRAME (DWC2_US_PER_UFRAME / DWC2_US_PER_SLICE)
  690. #define DWC2_ROUND_US_TO_SLICE(us) \
  691. (DIV_ROUND_UP((us), DWC2_US_PER_SLICE) * \
  692. DWC2_US_PER_SLICE)
  693. #define DWC2_LS_PERIODIC_US_PER_FRAME \
  694. 900
  695. #define DWC2_LS_PERIODIC_SLICES_PER_FRAME \
  696. (DWC2_LS_PERIODIC_US_PER_FRAME / \
  697. DWC2_US_PER_SLICE)
  698. #define DWC2_LS_SCHEDULE_FRAMES 1
  699. #define DWC2_LS_SCHEDULE_SLICES (DWC2_LS_SCHEDULE_FRAMES * \
  700. DWC2_LS_PERIODIC_SLICES_PER_FRAME)
  701. /**
  702. * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
  703. * and periodic schedules
  704. *
  705. * These are common for both host and peripheral modes:
  706. *
  707. * @dev: The struct device pointer
  708. * @regs: Pointer to controller regs
  709. * @hw_params: Parameters that were autodetected from the
  710. * hardware registers
  711. * @core_params: Parameters that define how the core should be configured
  712. * @op_state: The operational State, during transitions (a_host=>
  713. * a_peripheral and b_device=>b_host) this may not match
  714. * the core, but allows the software to determine
  715. * transitions
  716. * @dr_mode: Requested mode of operation, one of following:
  717. * - USB_DR_MODE_PERIPHERAL
  718. * - USB_DR_MODE_HOST
  719. * - USB_DR_MODE_OTG
  720. * @hcd_enabled Host mode sub-driver initialization indicator.
  721. * @gadget_enabled Peripheral mode sub-driver initialization indicator.
  722. * @ll_hw_enabled Status of low-level hardware resources.
  723. * @phy: The otg phy transceiver structure for phy control.
  724. * @uphy: The otg phy transceiver structure for old USB phy control.
  725. * @plat: The platform specific configuration data. This can be removed once
  726. * all SoCs support usb transceiver.
  727. * @supplies: Definition of USB power supplies
  728. * @phyif: PHY interface width
  729. * @lock: Spinlock that protects all the driver data structures
  730. * @priv: Stores a pointer to the struct usb_hcd
  731. * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
  732. * transfer are in process of being queued
  733. * @srp_success: Stores status of SRP request in the case of a FS PHY
  734. * with an I2C interface
  735. * @wq_otg: Workqueue object used for handling of some interrupts
  736. * @wf_otg: Work object for handling Connector ID Status Change
  737. * interrupt
  738. * @wkp_timer: Timer object for handling Wakeup Detected interrupt
  739. * @lx_state: Lx state of connected device
  740. * @gregs_backup: Backup of global registers during suspend
  741. * @dregs_backup: Backup of device registers during suspend
  742. * @hregs_backup: Backup of host registers during suspend
  743. *
  744. * These are for host mode:
  745. *
  746. * @flags: Flags for handling root port state changes
  747. * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
  748. * Transfers associated with these QHs are not currently
  749. * assigned to a host channel.
  750. * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
  751. * Transfers associated with these QHs are currently
  752. * assigned to a host channel.
  753. * @non_periodic_qh_ptr: Pointer to next QH to process in the active
  754. * non-periodic schedule
  755. * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
  756. * list of QHs for periodic transfers that are _not_
  757. * scheduled for the next frame. Each QH in the list has an
  758. * interval counter that determines when it needs to be
  759. * scheduled for execution. This scheduling mechanism
  760. * allows only a simple calculation for periodic bandwidth
  761. * used (i.e. must assume that all periodic transfers may
  762. * need to execute in the same frame). However, it greatly
  763. * simplifies scheduling and should be sufficient for the
  764. * vast majority of OTG hosts, which need to connect to a
  765. * small number of peripherals at one time. Items move from
  766. * this list to periodic_sched_ready when the QH interval
  767. * counter is 0 at SOF.
  768. * @periodic_sched_ready: List of periodic QHs that are ready for execution in
  769. * the next frame, but have not yet been assigned to host
  770. * channels. Items move from this list to
  771. * periodic_sched_assigned as host channels become
  772. * available during the current frame.
  773. * @periodic_sched_assigned: List of periodic QHs to be executed in the next
  774. * frame that are assigned to host channels. Items move
  775. * from this list to periodic_sched_queued as the
  776. * transactions for the QH are queued to the DWC_otg
  777. * controller.
  778. * @periodic_sched_queued: List of periodic QHs that have been queued for
  779. * execution. Items move from this list to either
  780. * periodic_sched_inactive or periodic_sched_ready when the
  781. * channel associated with the transfer is released. If the
  782. * interval for the QH is 1, the item moves to
  783. * periodic_sched_ready because it must be rescheduled for
  784. * the next frame. Otherwise, the item moves to
  785. * periodic_sched_inactive.
  786. * @split_order: List keeping track of channels doing splits, in order.
  787. * @periodic_usecs: Total bandwidth claimed so far for periodic transfers.
  788. * This value is in microseconds per (micro)frame. The
  789. * assumption is that all periodic transfers may occur in
  790. * the same (micro)frame.
  791. * @hs_periodic_bitmap: Bitmap used by the microframe scheduler any time the
  792. * host is in high speed mode; low speed schedules are
  793. * stored elsewhere since we need one per TT.
  794. * @frame_number: Frame number read from the core at SOF. The value ranges
  795. * from 0 to HFNUM_MAX_FRNUM.
  796. * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
  797. * SOF enable/disable.
  798. * @free_hc_list: Free host channels in the controller. This is a list of
  799. * struct dwc2_host_chan items.
  800. * @periodic_channels: Number of host channels assigned to periodic transfers.
  801. * Currently assuming that there is a dedicated host
  802. * channel for each periodic transaction and at least one
  803. * host channel is available for non-periodic transactions.
  804. * @non_periodic_channels: Number of host channels assigned to non-periodic
  805. * transfers
  806. * @available_host_channels Number of host channels available for the microframe
  807. * scheduler to use
  808. * @hc_ptr_array: Array of pointers to the host channel descriptors.
  809. * Allows accessing a host channel descriptor given the
  810. * host channel number. This is useful in interrupt
  811. * handlers.
  812. * @status_buf: Buffer used for data received during the status phase of
  813. * a control transfer.
  814. * @status_buf_dma: DMA address for status_buf
  815. * @start_work: Delayed work for handling host A-cable connection
  816. * @reset_work: Delayed work for handling a port reset
  817. * @otg_port: OTG port number
  818. * @frame_list: Frame list
  819. * @frame_list_dma: Frame list DMA address
  820. * @frame_list_sz: Frame list size
  821. * @desc_gen_cache: Kmem cache for generic descriptors
  822. * @desc_hsisoc_cache: Kmem cache for hs isochronous descriptors
  823. *
  824. * These are for peripheral mode:
  825. *
  826. * @driver: USB gadget driver
  827. * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
  828. * @num_of_eps: Number of available EPs (excluding EP0)
  829. * @debug_root: Root directrory for debugfs.
  830. * @debug_file: Main status file for debugfs.
  831. * @debug_testmode: Testmode status file for debugfs.
  832. * @debug_fifo: FIFO status file for debugfs.
  833. * @ep0_reply: Request used for ep0 reply.
  834. * @ep0_buff: Buffer for EP0 reply data, if needed.
  835. * @ctrl_buff: Buffer for EP0 control requests.
  836. * @ctrl_req: Request for EP0 control packets.
  837. * @ep0_state: EP0 control transfers state
  838. * @test_mode: USB test mode requested by the host
  839. * @eps: The endpoints being supplied to the gadget framework
  840. */
  841. struct dwc2_hsotg {
  842. struct device *dev;
  843. void __iomem *regs;
  844. /** Params detected from hardware */
  845. struct dwc2_hw_params hw_params;
  846. /** Params to actually use */
  847. struct dwc2_core_params params;
  848. enum usb_otg_state op_state;
  849. enum usb_dr_mode dr_mode;
  850. unsigned int hcd_enabled:1;
  851. unsigned int gadget_enabled:1;
  852. unsigned int ll_hw_enabled:1;
  853. struct phy *phy;
  854. struct usb_phy *uphy;
  855. struct dwc2_hsotg_plat *plat;
  856. struct regulator_bulk_data supplies[ARRAY_SIZE(dwc2_hsotg_supply_names)];
  857. u32 phyif;
  858. spinlock_t lock;
  859. void *priv;
  860. int irq;
  861. struct clk *clk;
  862. struct reset_control *reset;
  863. unsigned int queuing_high_bandwidth:1;
  864. unsigned int srp_success:1;
  865. struct workqueue_struct *wq_otg;
  866. struct work_struct wf_otg;
  867. struct timer_list wkp_timer;
  868. enum dwc2_lx_state lx_state;
  869. struct dwc2_gregs_backup gr_backup;
  870. struct dwc2_dregs_backup dr_backup;
  871. struct dwc2_hregs_backup hr_backup;
  872. struct dentry *debug_root;
  873. struct debugfs_regset32 *regset;
  874. /* DWC OTG HW Release versions */
  875. #define DWC2_CORE_REV_2_71a 0x4f54271a
  876. #define DWC2_CORE_REV_2_90a 0x4f54290a
  877. #define DWC2_CORE_REV_2_92a 0x4f54292a
  878. #define DWC2_CORE_REV_2_94a 0x4f54294a
  879. #define DWC2_CORE_REV_3_00a 0x4f54300a
  880. #define DWC2_CORE_REV_3_10a 0x4f54310a
  881. #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  882. union dwc2_hcd_internal_flags {
  883. u32 d32;
  884. struct {
  885. unsigned port_connect_status_change:1;
  886. unsigned port_connect_status:1;
  887. unsigned port_reset_change:1;
  888. unsigned port_enable_change:1;
  889. unsigned port_suspend_change:1;
  890. unsigned port_over_current_change:1;
  891. unsigned port_l1_change:1;
  892. unsigned reserved:25;
  893. } b;
  894. } flags;
  895. struct list_head non_periodic_sched_inactive;
  896. struct list_head non_periodic_sched_active;
  897. struct list_head *non_periodic_qh_ptr;
  898. struct list_head periodic_sched_inactive;
  899. struct list_head periodic_sched_ready;
  900. struct list_head periodic_sched_assigned;
  901. struct list_head periodic_sched_queued;
  902. struct list_head split_order;
  903. u16 periodic_usecs;
  904. unsigned long hs_periodic_bitmap[
  905. DIV_ROUND_UP(DWC2_HS_SCHEDULE_US, BITS_PER_LONG)];
  906. u16 frame_number;
  907. u16 periodic_qh_count;
  908. bool bus_suspended;
  909. bool new_connection;
  910. u16 last_frame_num;
  911. #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
  912. #define FRAME_NUM_ARRAY_SIZE 1000
  913. u16 *frame_num_array;
  914. u16 *last_frame_num_array;
  915. int frame_num_idx;
  916. int dumped_frame_num_array;
  917. #endif
  918. struct list_head free_hc_list;
  919. int periodic_channels;
  920. int non_periodic_channels;
  921. int available_host_channels;
  922. struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
  923. u8 *status_buf;
  924. dma_addr_t status_buf_dma;
  925. #define DWC2_HCD_STATUS_BUF_SIZE 64
  926. struct delayed_work start_work;
  927. struct delayed_work reset_work;
  928. u8 otg_port;
  929. u32 *frame_list;
  930. dma_addr_t frame_list_dma;
  931. u32 frame_list_sz;
  932. struct kmem_cache *desc_gen_cache;
  933. struct kmem_cache *desc_hsisoc_cache;
  934. #ifdef DEBUG
  935. u32 frrem_samples;
  936. u64 frrem_accum;
  937. u32 hfnum_7_samples_a;
  938. u64 hfnum_7_frrem_accum_a;
  939. u32 hfnum_0_samples_a;
  940. u64 hfnum_0_frrem_accum_a;
  941. u32 hfnum_other_samples_a;
  942. u64 hfnum_other_frrem_accum_a;
  943. u32 hfnum_7_samples_b;
  944. u64 hfnum_7_frrem_accum_b;
  945. u32 hfnum_0_samples_b;
  946. u64 hfnum_0_frrem_accum_b;
  947. u32 hfnum_other_samples_b;
  948. u64 hfnum_other_frrem_accum_b;
  949. #endif
  950. #endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
  951. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  952. /* Gadget structures */
  953. struct usb_gadget_driver *driver;
  954. int fifo_mem;
  955. unsigned int dedicated_fifos:1;
  956. unsigned char num_of_eps;
  957. u32 fifo_map;
  958. struct usb_request *ep0_reply;
  959. struct usb_request *ctrl_req;
  960. void *ep0_buff;
  961. void *ctrl_buff;
  962. enum dwc2_ep0_state ep0_state;
  963. u8 test_mode;
  964. struct usb_gadget gadget;
  965. unsigned int enabled:1;
  966. unsigned int connected:1;
  967. struct dwc2_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
  968. struct dwc2_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
  969. #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
  970. };
  971. /* Reasons for halting a host channel */
  972. enum dwc2_halt_status {
  973. DWC2_HC_XFER_NO_HALT_STATUS,
  974. DWC2_HC_XFER_COMPLETE,
  975. DWC2_HC_XFER_URB_COMPLETE,
  976. DWC2_HC_XFER_ACK,
  977. DWC2_HC_XFER_NAK,
  978. DWC2_HC_XFER_NYET,
  979. DWC2_HC_XFER_STALL,
  980. DWC2_HC_XFER_XACT_ERR,
  981. DWC2_HC_XFER_FRAME_OVERRUN,
  982. DWC2_HC_XFER_BABBLE_ERR,
  983. DWC2_HC_XFER_DATA_TOGGLE_ERR,
  984. DWC2_HC_XFER_AHB_ERR,
  985. DWC2_HC_XFER_PERIODIC_INCOMPLETE,
  986. DWC2_HC_XFER_URB_DEQUEUE,
  987. };
  988. /*
  989. * The following functions support initialization of the core driver component
  990. * and the DWC_otg controller
  991. */
  992. extern int dwc2_core_reset(struct dwc2_hsotg *hsotg);
  993. extern int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg);
  994. extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
  995. extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
  996. bool dwc2_force_mode_if_needed(struct dwc2_hsotg *hsotg, bool host);
  997. void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg);
  998. void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg);
  999. extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
  1000. /*
  1001. * Common core Functions.
  1002. * The following functions support managing the DWC_otg controller in either
  1003. * device or host mode.
  1004. */
  1005. extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
  1006. extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
  1007. extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
  1008. extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
  1009. extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
  1010. /* This function should be called on every hardware interrupt. */
  1011. extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
  1012. /* The device ID match table */
  1013. extern const struct of_device_id dwc2_of_match_table[];
  1014. extern int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg);
  1015. extern int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);
  1016. /* Parameters */
  1017. int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
  1018. int dwc2_init_params(struct dwc2_hsotg *hsotg);
  1019. /*
  1020. * The following functions check the controller's OTG operation mode
  1021. * capability (GHWCFG2.OTG_MODE).
  1022. *
  1023. * These functions can be used before the internal hsotg->hw_params
  1024. * are read in and cached so they always read directly from the
  1025. * GHWCFG2 register.
  1026. */
  1027. unsigned dwc2_op_mode(struct dwc2_hsotg *hsotg);
  1028. bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg);
  1029. bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg);
  1030. bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg);
  1031. /*
  1032. * Returns the mode of operation, host or device
  1033. */
  1034. static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg)
  1035. {
  1036. return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) != 0;
  1037. }
  1038. static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg)
  1039. {
  1040. return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) == 0;
  1041. }
  1042. /*
  1043. * Dump core registers and SPRAM
  1044. */
  1045. extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
  1046. extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
  1047. extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
  1048. /*
  1049. * Return OTG version - either 1.3 or 2.0
  1050. */
  1051. extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
  1052. /* Gadget defines */
  1053. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  1054. extern int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg);
  1055. extern int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2);
  1056. extern int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2);
  1057. extern int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq);
  1058. extern void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
  1059. bool reset);
  1060. extern void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg);
  1061. extern void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2);
  1062. extern int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
  1063. #define dwc2_is_device_connected(hsotg) (hsotg->connected)
  1064. int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg);
  1065. int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg);
  1066. #else
  1067. static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2)
  1068. { return 0; }
  1069. static inline int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2)
  1070. { return 0; }
  1071. static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2)
  1072. { return 0; }
  1073. static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
  1074. { return 0; }
  1075. static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
  1076. bool reset) {}
  1077. static inline void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
  1078. static inline void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
  1079. static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
  1080. int testmode)
  1081. { return 0; }
  1082. #define dwc2_is_device_connected(hsotg) (0)
  1083. static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
  1084. { return 0; }
  1085. static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg)
  1086. { return 0; }
  1087. #endif
  1088. #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  1089. extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
  1090. extern int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us);
  1091. extern void dwc2_hcd_connect(struct dwc2_hsotg *hsotg);
  1092. extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force);
  1093. extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
  1094. int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg);
  1095. int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg);
  1096. #else
  1097. static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
  1098. { return 0; }
  1099. static inline int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg,
  1100. int us)
  1101. { return 0; }
  1102. static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {}
  1103. static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {}
  1104. static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
  1105. static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
  1106. static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
  1107. { return 0; }
  1108. static inline int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
  1109. { return 0; }
  1110. static inline int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
  1111. { return 0; }
  1112. #endif
  1113. #endif /* __DWC2_CORE_H__ */