core.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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. };
  473. /**
  474. * struct dwc2_dregs_backup - Holds device registers state before entering partial
  475. * power down
  476. * @dcfg: Backup of DCFG register
  477. * @dctl: Backup of DCTL register
  478. * @daintmsk: Backup of DAINTMSK register
  479. * @diepmsk: Backup of DIEPMSK register
  480. * @doepmsk: Backup of DOEPMSK register
  481. * @diepctl: Backup of DIEPCTL register
  482. * @dieptsiz: Backup of DIEPTSIZ register
  483. * @diepdma: Backup of DIEPDMA register
  484. * @doepctl: Backup of DOEPCTL register
  485. * @doeptsiz: Backup of DOEPTSIZ register
  486. * @doepdma: Backup of DOEPDMA register
  487. */
  488. struct dwc2_dregs_backup {
  489. u32 dcfg;
  490. u32 dctl;
  491. u32 daintmsk;
  492. u32 diepmsk;
  493. u32 doepmsk;
  494. u32 diepctl[MAX_EPS_CHANNELS];
  495. u32 dieptsiz[MAX_EPS_CHANNELS];
  496. u32 diepdma[MAX_EPS_CHANNELS];
  497. u32 doepctl[MAX_EPS_CHANNELS];
  498. u32 doeptsiz[MAX_EPS_CHANNELS];
  499. u32 doepdma[MAX_EPS_CHANNELS];
  500. };
  501. /**
  502. * struct dwc2_hregs_backup - Holds host registers state before entering partial
  503. * power down
  504. * @hcfg: Backup of HCFG register
  505. * @haintmsk: Backup of HAINTMSK register
  506. * @hcintmsk: Backup of HCINTMSK register
  507. * @hptr0: Backup of HPTR0 register
  508. * @hfir: Backup of HFIR register
  509. */
  510. struct dwc2_hregs_backup {
  511. u32 hcfg;
  512. u32 haintmsk;
  513. u32 hcintmsk[MAX_EPS_CHANNELS];
  514. u32 hprt0;
  515. u32 hfir;
  516. };
  517. /**
  518. * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
  519. * and periodic schedules
  520. *
  521. * These are common for both host and peripheral modes:
  522. *
  523. * @dev: The struct device pointer
  524. * @regs: Pointer to controller regs
  525. * @hw_params: Parameters that were autodetected from the
  526. * hardware registers
  527. * @core_params: Parameters that define how the core should be configured
  528. * @op_state: The operational State, during transitions (a_host=>
  529. * a_peripheral and b_device=>b_host) this may not match
  530. * the core, but allows the software to determine
  531. * transitions
  532. * @dr_mode: Requested mode of operation, one of following:
  533. * - USB_DR_MODE_PERIPHERAL
  534. * - USB_DR_MODE_HOST
  535. * - USB_DR_MODE_OTG
  536. * @lock: Spinlock that protects all the driver data structures
  537. * @priv: Stores a pointer to the struct usb_hcd
  538. * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
  539. * transfer are in process of being queued
  540. * @srp_success: Stores status of SRP request in the case of a FS PHY
  541. * with an I2C interface
  542. * @wq_otg: Workqueue object used for handling of some interrupts
  543. * @wf_otg: Work object for handling Connector ID Status Change
  544. * interrupt
  545. * @wkp_timer: Timer object for handling Wakeup Detected interrupt
  546. * @lx_state: Lx state of connected device
  547. * @gregs_backup: Backup of global registers during suspend
  548. * @dregs_backup: Backup of device registers during suspend
  549. * @hregs_backup: Backup of host registers during suspend
  550. *
  551. * These are for host mode:
  552. *
  553. * @flags: Flags for handling root port state changes
  554. * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
  555. * Transfers associated with these QHs are not currently
  556. * assigned to a host channel.
  557. * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
  558. * Transfers associated with these QHs are currently
  559. * assigned to a host channel.
  560. * @non_periodic_qh_ptr: Pointer to next QH to process in the active
  561. * non-periodic schedule
  562. * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
  563. * list of QHs for periodic transfers that are _not_
  564. * scheduled for the next frame. Each QH in the list has an
  565. * interval counter that determines when it needs to be
  566. * scheduled for execution. This scheduling mechanism
  567. * allows only a simple calculation for periodic bandwidth
  568. * used (i.e. must assume that all periodic transfers may
  569. * need to execute in the same frame). However, it greatly
  570. * simplifies scheduling and should be sufficient for the
  571. * vast majority of OTG hosts, which need to connect to a
  572. * small number of peripherals at one time. Items move from
  573. * this list to periodic_sched_ready when the QH interval
  574. * counter is 0 at SOF.
  575. * @periodic_sched_ready: List of periodic QHs that are ready for execution in
  576. * the next frame, but have not yet been assigned to host
  577. * channels. Items move from this list to
  578. * periodic_sched_assigned as host channels become
  579. * available during the current frame.
  580. * @periodic_sched_assigned: List of periodic QHs to be executed in the next
  581. * frame that are assigned to host channels. Items move
  582. * from this list to periodic_sched_queued as the
  583. * transactions for the QH are queued to the DWC_otg
  584. * controller.
  585. * @periodic_sched_queued: List of periodic QHs that have been queued for
  586. * execution. Items move from this list to either
  587. * periodic_sched_inactive or periodic_sched_ready when the
  588. * channel associated with the transfer is released. If the
  589. * interval for the QH is 1, the item moves to
  590. * periodic_sched_ready because it must be rescheduled for
  591. * the next frame. Otherwise, the item moves to
  592. * periodic_sched_inactive.
  593. * @periodic_usecs: Total bandwidth claimed so far for periodic transfers.
  594. * This value is in microseconds per (micro)frame. The
  595. * assumption is that all periodic transfers may occur in
  596. * the same (micro)frame.
  597. * @frame_usecs: Internal variable used by the microframe scheduler
  598. * @frame_number: Frame number read from the core at SOF. The value ranges
  599. * from 0 to HFNUM_MAX_FRNUM.
  600. * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
  601. * SOF enable/disable.
  602. * @free_hc_list: Free host channels in the controller. This is a list of
  603. * struct dwc2_host_chan items.
  604. * @periodic_channels: Number of host channels assigned to periodic transfers.
  605. * Currently assuming that there is a dedicated host
  606. * channel for each periodic transaction and at least one
  607. * host channel is available for non-periodic transactions.
  608. * @non_periodic_channels: Number of host channels assigned to non-periodic
  609. * transfers
  610. * @available_host_channels Number of host channels available for the microframe
  611. * scheduler to use
  612. * @hc_ptr_array: Array of pointers to the host channel descriptors.
  613. * Allows accessing a host channel descriptor given the
  614. * host channel number. This is useful in interrupt
  615. * handlers.
  616. * @status_buf: Buffer used for data received during the status phase of
  617. * a control transfer.
  618. * @status_buf_dma: DMA address for status_buf
  619. * @start_work: Delayed work for handling host A-cable connection
  620. * @reset_work: Delayed work for handling a port reset
  621. * @otg_port: OTG port number
  622. * @frame_list: Frame list
  623. * @frame_list_dma: Frame list DMA address
  624. *
  625. * These are for peripheral mode:
  626. *
  627. * @driver: USB gadget driver
  628. * @phy: The otg phy transceiver structure for phy control.
  629. * @uphy: The otg phy transceiver structure for old USB phy control.
  630. * @plat: The platform specific configuration data. This can be removed once
  631. * all SoCs support usb transceiver.
  632. * @supplies: Definition of USB power supplies
  633. * @phyif: PHY interface width
  634. * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
  635. * @num_of_eps: Number of available EPs (excluding EP0)
  636. * @debug_root: Root directrory for debugfs.
  637. * @debug_file: Main status file for debugfs.
  638. * @debug_testmode: Testmode status file for debugfs.
  639. * @debug_fifo: FIFO status file for debugfs.
  640. * @ep0_reply: Request used for ep0 reply.
  641. * @ep0_buff: Buffer for EP0 reply data, if needed.
  642. * @ctrl_buff: Buffer for EP0 control requests.
  643. * @ctrl_req: Request for EP0 control packets.
  644. * @ep0_state: EP0 control transfers state
  645. * @test_mode: USB test mode requested by the host
  646. * @last_rst: Time of last reset
  647. * @eps: The endpoints being supplied to the gadget framework
  648. * @g_using_dma: Indicate if dma usage is enabled
  649. * @g_rx_fifo_sz: Contains rx fifo size value
  650. * @g_np_g_tx_fifo_sz: Contains Non-Periodic tx fifo size value
  651. * @g_tx_fifo_sz: Contains tx fifo size value per endpoints
  652. */
  653. struct dwc2_hsotg {
  654. struct device *dev;
  655. void __iomem *regs;
  656. /** Params detected from hardware */
  657. struct dwc2_hw_params hw_params;
  658. /** Params to actually use */
  659. struct dwc2_core_params *core_params;
  660. enum usb_otg_state op_state;
  661. enum usb_dr_mode dr_mode;
  662. unsigned int hcd_enabled:1;
  663. unsigned int gadget_enabled:1;
  664. struct phy *phy;
  665. struct usb_phy *uphy;
  666. struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)];
  667. spinlock_t lock;
  668. struct mutex init_mutex;
  669. void *priv;
  670. int irq;
  671. struct clk *clk;
  672. unsigned int queuing_high_bandwidth:1;
  673. unsigned int srp_success:1;
  674. struct workqueue_struct *wq_otg;
  675. struct work_struct wf_otg;
  676. struct timer_list wkp_timer;
  677. enum dwc2_lx_state lx_state;
  678. struct dwc2_gregs_backup *gr_backup;
  679. struct dwc2_dregs_backup *dr_backup;
  680. struct dwc2_hregs_backup *hr_backup;
  681. struct dentry *debug_root;
  682. struct debugfs_regset32 *regset;
  683. /* DWC OTG HW Release versions */
  684. #define DWC2_CORE_REV_2_71a 0x4f54271a
  685. #define DWC2_CORE_REV_2_90a 0x4f54290a
  686. #define DWC2_CORE_REV_2_92a 0x4f54292a
  687. #define DWC2_CORE_REV_2_94a 0x4f54294a
  688. #define DWC2_CORE_REV_3_00a 0x4f54300a
  689. #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  690. union dwc2_hcd_internal_flags {
  691. u32 d32;
  692. struct {
  693. unsigned port_connect_status_change:1;
  694. unsigned port_connect_status:1;
  695. unsigned port_reset_change:1;
  696. unsigned port_enable_change:1;
  697. unsigned port_suspend_change:1;
  698. unsigned port_over_current_change:1;
  699. unsigned port_l1_change:1;
  700. unsigned reserved:25;
  701. } b;
  702. } flags;
  703. struct list_head non_periodic_sched_inactive;
  704. struct list_head non_periodic_sched_active;
  705. struct list_head *non_periodic_qh_ptr;
  706. struct list_head periodic_sched_inactive;
  707. struct list_head periodic_sched_ready;
  708. struct list_head periodic_sched_assigned;
  709. struct list_head periodic_sched_queued;
  710. u16 periodic_usecs;
  711. u16 frame_usecs[8];
  712. u16 frame_number;
  713. u16 periodic_qh_count;
  714. #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
  715. #define FRAME_NUM_ARRAY_SIZE 1000
  716. u16 last_frame_num;
  717. u16 *frame_num_array;
  718. u16 *last_frame_num_array;
  719. int frame_num_idx;
  720. int dumped_frame_num_array;
  721. #endif
  722. struct list_head free_hc_list;
  723. int periodic_channels;
  724. int non_periodic_channels;
  725. int available_host_channels;
  726. struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
  727. u8 *status_buf;
  728. dma_addr_t status_buf_dma;
  729. #define DWC2_HCD_STATUS_BUF_SIZE 64
  730. struct delayed_work start_work;
  731. struct delayed_work reset_work;
  732. u8 otg_port;
  733. u32 *frame_list;
  734. dma_addr_t frame_list_dma;
  735. #ifdef DEBUG
  736. u32 frrem_samples;
  737. u64 frrem_accum;
  738. u32 hfnum_7_samples_a;
  739. u64 hfnum_7_frrem_accum_a;
  740. u32 hfnum_0_samples_a;
  741. u64 hfnum_0_frrem_accum_a;
  742. u32 hfnum_other_samples_a;
  743. u64 hfnum_other_frrem_accum_a;
  744. u32 hfnum_7_samples_b;
  745. u64 hfnum_7_frrem_accum_b;
  746. u32 hfnum_0_samples_b;
  747. u64 hfnum_0_frrem_accum_b;
  748. u32 hfnum_other_samples_b;
  749. u64 hfnum_other_frrem_accum_b;
  750. #endif
  751. #endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
  752. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  753. /* Gadget structures */
  754. struct usb_gadget_driver *driver;
  755. struct s3c_hsotg_plat *plat;
  756. u32 phyif;
  757. int fifo_mem;
  758. unsigned int dedicated_fifos:1;
  759. unsigned char num_of_eps;
  760. u32 fifo_map;
  761. struct usb_request *ep0_reply;
  762. struct usb_request *ctrl_req;
  763. void *ep0_buff;
  764. void *ctrl_buff;
  765. enum dwc2_ep0_state ep0_state;
  766. u8 test_mode;
  767. struct usb_gadget gadget;
  768. unsigned int enabled:1;
  769. unsigned int connected:1;
  770. unsigned long last_rst;
  771. struct s3c_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
  772. struct s3c_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
  773. u32 g_using_dma;
  774. u32 g_rx_fifo_sz;
  775. u32 g_np_g_tx_fifo_sz;
  776. u32 g_tx_fifo_sz[MAX_EPS_CHANNELS];
  777. #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
  778. };
  779. /* Reasons for halting a host channel */
  780. enum dwc2_halt_status {
  781. DWC2_HC_XFER_NO_HALT_STATUS,
  782. DWC2_HC_XFER_COMPLETE,
  783. DWC2_HC_XFER_URB_COMPLETE,
  784. DWC2_HC_XFER_ACK,
  785. DWC2_HC_XFER_NAK,
  786. DWC2_HC_XFER_NYET,
  787. DWC2_HC_XFER_STALL,
  788. DWC2_HC_XFER_XACT_ERR,
  789. DWC2_HC_XFER_FRAME_OVERRUN,
  790. DWC2_HC_XFER_BABBLE_ERR,
  791. DWC2_HC_XFER_DATA_TOGGLE_ERR,
  792. DWC2_HC_XFER_AHB_ERR,
  793. DWC2_HC_XFER_PERIODIC_INCOMPLETE,
  794. DWC2_HC_XFER_URB_DEQUEUE,
  795. };
  796. /*
  797. * The following functions support initialization of the core driver component
  798. * and the DWC_otg controller
  799. */
  800. extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
  801. extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
  802. extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
  803. /*
  804. * Host core Functions.
  805. * The following functions support managing the DWC_otg controller in host
  806. * mode.
  807. */
  808. extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
  809. extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
  810. enum dwc2_halt_status halt_status);
  811. extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
  812. struct dwc2_host_chan *chan);
  813. extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
  814. struct dwc2_host_chan *chan);
  815. extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
  816. struct dwc2_host_chan *chan);
  817. extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
  818. struct dwc2_host_chan *chan);
  819. extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
  820. struct dwc2_host_chan *chan);
  821. extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
  822. extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
  823. extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
  824. extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
  825. /*
  826. * Common core Functions.
  827. * The following functions support managing the DWC_otg controller in either
  828. * device or host mode.
  829. */
  830. extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
  831. extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
  832. extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
  833. extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq);
  834. extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
  835. extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
  836. /* This function should be called on every hardware interrupt. */
  837. extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
  838. /* OTG Core Parameters */
  839. /*
  840. * Specifies the OTG capabilities. The driver will automatically
  841. * detect the value for this parameter if none is specified.
  842. * 0 - HNP and SRP capable (default)
  843. * 1 - SRP Only capable
  844. * 2 - No HNP/SRP capable
  845. */
  846. extern void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
  847. #define DWC2_CAP_PARAM_HNP_SRP_CAPABLE 0
  848. #define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE 1
  849. #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  850. /*
  851. * Specifies whether to use slave or DMA mode for accessing the data
  852. * FIFOs. The driver will automatically detect the value for this
  853. * parameter if none is specified.
  854. * 0 - Slave
  855. * 1 - DMA (default, if available)
  856. */
  857. extern void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
  858. /*
  859. * When DMA mode is enabled specifies whether to use
  860. * address DMA or DMA Descritor mode for accessing the data
  861. * FIFOs in device mode. The driver will automatically detect
  862. * the value for this parameter if none is specified.
  863. * 0 - address DMA
  864. * 1 - DMA Descriptor(default, if available)
  865. */
  866. extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
  867. /*
  868. * Specifies the maximum speed of operation in host and device mode.
  869. * The actual speed depends on the speed of the attached device and
  870. * the value of phy_type. The actual speed depends on the speed of the
  871. * attached device.
  872. * 0 - High Speed (default)
  873. * 1 - Full Speed
  874. */
  875. extern void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
  876. #define DWC2_SPEED_PARAM_HIGH 0
  877. #define DWC2_SPEED_PARAM_FULL 1
  878. /*
  879. * Specifies whether low power mode is supported when attached
  880. * to a Full Speed or Low Speed device in host mode.
  881. *
  882. * 0 - Don't support low power mode (default)
  883. * 1 - Support low power mode
  884. */
  885. extern void dwc2_set_param_host_support_fs_ls_low_power(
  886. struct dwc2_hsotg *hsotg, int val);
  887. /*
  888. * Specifies the PHY clock rate in low power mode when connected to a
  889. * Low Speed device in host mode. This parameter is applicable only if
  890. * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  891. * then defaults to 6 MHZ otherwise 48 MHZ.
  892. *
  893. * 0 - 48 MHz
  894. * 1 - 6 MHz
  895. */
  896. extern void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
  897. int val);
  898. #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  899. #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  900. /*
  901. * 0 - Use cC FIFO size parameters
  902. * 1 - Allow dynamic FIFO sizing (default)
  903. */
  904. extern void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
  905. int val);
  906. /*
  907. * Number of 4-byte words in the Rx FIFO in host mode when dynamic
  908. * FIFO sizing is enabled.
  909. * 16 to 32768 (default 1024)
  910. */
  911. extern void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
  912. /*
  913. * Number of 4-byte words in the non-periodic Tx FIFO in host mode
  914. * when Dynamic FIFO sizing is enabled in the core.
  915. * 16 to 32768 (default 256)
  916. */
  917. extern void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
  918. int val);
  919. /*
  920. * Number of 4-byte words in the host periodic Tx FIFO when dynamic
  921. * FIFO sizing is enabled.
  922. * 16 to 32768 (default 256)
  923. */
  924. extern void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
  925. int val);
  926. /*
  927. * The maximum transfer size supported in bytes.
  928. * 2047 to 65,535 (default 65,535)
  929. */
  930. extern void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
  931. /*
  932. * The maximum number of packets in a transfer.
  933. * 15 to 511 (default 511)
  934. */
  935. extern void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
  936. /*
  937. * The number of host channel registers to use.
  938. * 1 to 16 (default 11)
  939. * Note: The FPGA configuration supports a maximum of 11 host channels.
  940. */
  941. extern void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
  942. /*
  943. * Specifies the type of PHY interface to use. By default, the driver
  944. * will automatically detect the phy_type.
  945. *
  946. * 0 - Full Speed PHY
  947. * 1 - UTMI+ (default)
  948. * 2 - ULPI
  949. */
  950. extern void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
  951. #define DWC2_PHY_TYPE_PARAM_FS 0
  952. #define DWC2_PHY_TYPE_PARAM_UTMI 1
  953. #define DWC2_PHY_TYPE_PARAM_ULPI 2
  954. /*
  955. * Specifies the UTMI+ Data Width. This parameter is
  956. * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  957. * PHY_TYPE, this parameter indicates the data width between
  958. * the MAC and the ULPI Wrapper.) Also, this parameter is
  959. * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  960. * to "8 and 16 bits", meaning that the core has been
  961. * configured to work at either data path width.
  962. *
  963. * 8 or 16 bits (default 16)
  964. */
  965. extern void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
  966. /*
  967. * Specifies whether the ULPI operates at double or single
  968. * data rate. This parameter is only applicable if PHY_TYPE is
  969. * ULPI.
  970. *
  971. * 0 - single data rate ULPI interface with 8 bit wide data
  972. * bus (default)
  973. * 1 - double data rate ULPI interface with 4 bit wide data
  974. * bus
  975. */
  976. extern void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
  977. /*
  978. * Specifies whether to use the internal or external supply to
  979. * drive the vbus with a ULPI phy.
  980. */
  981. extern void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
  982. #define DWC2_PHY_ULPI_INTERNAL_VBUS 0
  983. #define DWC2_PHY_ULPI_EXTERNAL_VBUS 1
  984. /*
  985. * Specifies whether to use the I2Cinterface for full speed PHY. This
  986. * parameter is only applicable if PHY_TYPE is FS.
  987. * 0 - No (default)
  988. * 1 - Yes
  989. */
  990. extern void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
  991. extern void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
  992. extern void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
  993. /*
  994. * Specifies whether dedicated transmit FIFOs are
  995. * enabled for non periodic IN endpoints in device mode
  996. * 0 - No
  997. * 1 - Yes
  998. */
  999. extern void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
  1000. int val);
  1001. extern void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
  1002. extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
  1003. extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
  1004. extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
  1005. const struct dwc2_core_params *params);
  1006. extern void dwc2_set_all_params(struct dwc2_core_params *params, int value);
  1007. extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
  1008. /*
  1009. * Dump core registers and SPRAM
  1010. */
  1011. extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
  1012. extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
  1013. extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
  1014. /*
  1015. * Return OTG version - either 1.3 or 2.0
  1016. */
  1017. extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
  1018. /* Gadget defines */
  1019. #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  1020. extern int s3c_hsotg_remove(struct dwc2_hsotg *hsotg);
  1021. extern int s3c_hsotg_suspend(struct dwc2_hsotg *dwc2);
  1022. extern int s3c_hsotg_resume(struct dwc2_hsotg *dwc2);
  1023. extern int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq);
  1024. extern void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
  1025. bool reset);
  1026. extern void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg);
  1027. extern void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2);
  1028. extern int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
  1029. #define dwc2_is_device_connected(hsotg) (hsotg->connected)
  1030. #else
  1031. static inline int s3c_hsotg_remove(struct dwc2_hsotg *dwc2)
  1032. { return 0; }
  1033. static inline int s3c_hsotg_suspend(struct dwc2_hsotg *dwc2)
  1034. { return 0; }
  1035. static inline int s3c_hsotg_resume(struct dwc2_hsotg *dwc2)
  1036. { return 0; }
  1037. static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
  1038. { return 0; }
  1039. static inline void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
  1040. bool reset) {}
  1041. static inline void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
  1042. static inline void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
  1043. static inline int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
  1044. int testmode)
  1045. { return 0; }
  1046. #define dwc2_is_device_connected(hsotg) (0)
  1047. #endif
  1048. #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
  1049. extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
  1050. extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
  1051. extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
  1052. #else
  1053. static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
  1054. { return 0; }
  1055. static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {}
  1056. static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
  1057. static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
  1058. static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
  1059. { return 0; }
  1060. #endif
  1061. #endif /* __DWC2_CORE_H__ */