core.h 44 KB

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