core.h 45 KB

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