core.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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/usb/phy.h>
  39. #include "hw.h"
  40. #ifdef DWC2_LOG_WRITES
  41. static inline void do_write(u32 value, void *addr)
  42. {
  43. writel(value, addr);
  44. pr_info("INFO:: wrote %08x to %p\n", value, addr);
  45. }
  46. #undef writel
  47. #define writel(v, a) do_write(v, a)
  48. #endif
  49. /* Maximum number of Endpoints/HostChannels */
  50. #define MAX_EPS_CHANNELS 16
  51. struct dwc2_hsotg;
  52. struct dwc2_host_chan;
  53. /* Device States */
  54. enum dwc2_lx_state {
  55. DWC2_L0, /* On state */
  56. DWC2_L1, /* LPM sleep state */
  57. DWC2_L2, /* USB suspend state */
  58. DWC2_L3, /* Off state */
  59. };
  60. /**
  61. * struct dwc2_core_params - Parameters for configuring the core
  62. *
  63. * @otg_cap: Specifies the OTG capabilities.
  64. * 0 - HNP and SRP capable
  65. * 1 - SRP Only capable
  66. * 2 - No HNP/SRP capable (always available)
  67. * Defaults to best available option (0, 1, then 2)
  68. * @otg_ver: OTG version supported
  69. * 0 - 1.3 (default)
  70. * 1 - 2.0
  71. * @dma_enable: Specifies whether to use slave or DMA mode for accessing
  72. * the data FIFOs. The driver will automatically detect the
  73. * value for this parameter if none is specified.
  74. * 0 - Slave (always available)
  75. * 1 - DMA (default, if available)
  76. * @dma_desc_enable: When DMA mode is enabled, specifies whether to use
  77. * address DMA mode or descriptor DMA mode for accessing
  78. * the data FIFOs. The driver will automatically detect the
  79. * value for this if none is specified.
  80. * 0 - Address DMA
  81. * 1 - Descriptor DMA (default, if available)
  82. * @speed: Specifies the maximum speed of operation in host and
  83. * device mode. The actual speed depends on the speed of
  84. * the attached device and the value of phy_type.
  85. * 0 - High Speed
  86. * (default when phy_type is UTMI+ or ULPI)
  87. * 1 - Full Speed
  88. * (default when phy_type is Full Speed)
  89. * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
  90. * 1 - Allow dynamic FIFO sizing (default, if available)
  91. * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
  92. * are enabled
  93. * @host_rx_fifo_size: Number of 4-byte words in the Rx FIFO in host mode when
  94. * dynamic FIFO sizing is enabled
  95. * 16 to 32768
  96. * Actual maximum value is autodetected and also
  97. * the default.
  98. * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
  99. * in host mode when dynamic FIFO sizing is enabled
  100. * 16 to 32768
  101. * Actual maximum value is autodetected and also
  102. * the default.
  103. * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
  104. * host mode when dynamic FIFO sizing is enabled
  105. * 16 to 32768
  106. * Actual maximum value is autodetected and also
  107. * the default.
  108. * @max_transfer_size: The maximum transfer size supported, in bytes
  109. * 2047 to 65,535
  110. * Actual maximum value is autodetected and also
  111. * the default.
  112. * @max_packet_count: The maximum number of packets in a transfer
  113. * 15 to 511
  114. * Actual maximum value is autodetected and also
  115. * the default.
  116. * @host_channels: The number of host channel registers to use
  117. * 1 to 16
  118. * Actual maximum value is autodetected and also
  119. * the default.
  120. * @phy_type: Specifies the type of PHY interface to use. By default,
  121. * the driver will automatically detect the phy_type.
  122. * 0 - Full Speed Phy
  123. * 1 - UTMI+ Phy
  124. * 2 - ULPI Phy
  125. * Defaults to best available option (2, 1, then 0)
  126. * @phy_utmi_width: Specifies the UTMI+ Data Width (in bits). This parameter
  127. * is applicable for a phy_type of UTMI+ or ULPI. (For a
  128. * ULPI phy_type, this parameter indicates the data width
  129. * between the MAC and the ULPI Wrapper.) Also, this
  130. * parameter is applicable only if the OTG_HSPHY_WIDTH cC
  131. * parameter was set to "8 and 16 bits", meaning that the
  132. * core has been configured to work at either data path
  133. * width.
  134. * 8 or 16 (default 16 if available)
  135. * @phy_ulpi_ddr: Specifies whether the ULPI operates at double or single
  136. * data rate. This parameter is only applicable if phy_type
  137. * is ULPI.
  138. * 0 - single data rate ULPI interface with 8 bit wide
  139. * data bus (default)
  140. * 1 - double data rate ULPI interface with 4 bit wide
  141. * data bus
  142. * @phy_ulpi_ext_vbus: For a ULPI phy, specifies whether to use the internal or
  143. * external supply to drive the VBus
  144. * 0 - Internal supply (default)
  145. * 1 - External supply
  146. * @i2c_enable: Specifies whether to use the I2Cinterface for a full
  147. * speed PHY. This parameter is only applicable if phy_type
  148. * is FS.
  149. * 0 - No (default)
  150. * 1 - Yes
  151. * @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
  152. * 0 - No (default)
  153. * 1 - Yes
  154. * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
  155. * when attached to a Full Speed or Low Speed device in
  156. * host mode.
  157. * 0 - Don't support low power mode (default)
  158. * 1 - Support low power mode
  159. * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
  160. * when connected to a Low Speed device in host
  161. * mode. This parameter is applicable only if
  162. * host_support_fs_ls_low_power is enabled.
  163. * 0 - 48 MHz
  164. * (default when phy_type is UTMI+ or ULPI)
  165. * 1 - 6 MHz
  166. * (default when phy_type is Full Speed)
  167. * @ts_dline: Enable Term Select Dline pulsing
  168. * 0 - No (default)
  169. * 1 - Yes
  170. * @reload_ctl: Allow dynamic reloading of HFIR register during runtime
  171. * 0 - No (default for core < 2.92a)
  172. * 1 - Yes (default for core >= 2.92a)
  173. * @ahbcfg: This field allows the default value of the GAHBCFG
  174. * register to be overridden
  175. * -1 - GAHBCFG value will be set to 0x06
  176. * (INCR4, default)
  177. * all others - GAHBCFG value will be overridden with
  178. * this value
  179. * Not all bits can be controlled like this, the
  180. * bits defined by GAHBCFG_CTRL_MASK are controlled
  181. * by the driver and are ignored in this
  182. * configuration value.
  183. * @uframe_sched: True to enable the microframe scheduler
  184. *
  185. * The following parameters may be specified when starting the module. These
  186. * parameters define how the DWC_otg controller should be configured. A
  187. * value of -1 (or any other out of range value) for any parameter means
  188. * to read the value from hardware (if possible) or use the builtin
  189. * default described above.
  190. */
  191. struct dwc2_core_params {
  192. /*
  193. * Don't add any non-int members here, this will break
  194. * dwc2_set_all_params!
  195. */
  196. int otg_cap;
  197. int otg_ver;
  198. int dma_enable;
  199. int dma_desc_enable;
  200. int speed;
  201. int enable_dynamic_fifo;
  202. int en_multiple_tx_fifo;
  203. int host_rx_fifo_size;
  204. int host_nperio_tx_fifo_size;
  205. int host_perio_tx_fifo_size;
  206. int max_transfer_size;
  207. int max_packet_count;
  208. int host_channels;
  209. int phy_type;
  210. int phy_utmi_width;
  211. int phy_ulpi_ddr;
  212. int phy_ulpi_ext_vbus;
  213. int i2c_enable;
  214. int ulpi_fs_ls;
  215. int host_support_fs_ls_low_power;
  216. int host_ls_low_power_phy_clk;
  217. int ts_dline;
  218. int reload_ctl;
  219. int ahbcfg;
  220. int uframe_sched;
  221. };
  222. /**
  223. * struct dwc2_hw_params - Autodetected parameters.
  224. *
  225. * These parameters are the various parameters read from hardware
  226. * registers during initialization. They typically contain the best
  227. * supported or maximum value that can be configured in the
  228. * corresponding dwc2_core_params value.
  229. *
  230. * The values that are not in dwc2_core_params are documented below.
  231. *
  232. * @op_mode Mode of Operation
  233. * 0 - HNP- and SRP-Capable OTG (Host & Device)
  234. * 1 - SRP-Capable OTG (Host & Device)
  235. * 2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
  236. * 3 - SRP-Capable Device
  237. * 4 - Non-OTG Device
  238. * 5 - SRP-Capable Host
  239. * 6 - Non-OTG Host
  240. * @arch Architecture
  241. * 0 - Slave only
  242. * 1 - External DMA
  243. * 2 - Internal DMA
  244. * @power_optimized Are power optimizations enabled?
  245. * @num_dev_ep Number of device endpoints available
  246. * @num_dev_perio_in_ep Number of device periodic IN endpoints
  247. * avaialable
  248. * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
  249. * Depth
  250. * 0 to 30
  251. * @host_perio_tx_q_depth
  252. * Host Mode Periodic Request Queue Depth
  253. * 2, 4 or 8
  254. * @nperio_tx_q_depth
  255. * Non-Periodic Request Queue Depth
  256. * 2, 4 or 8
  257. * @hs_phy_type High-speed PHY interface type
  258. * 0 - High-speed interface not supported
  259. * 1 - UTMI+
  260. * 2 - ULPI
  261. * 3 - UTMI+ and ULPI
  262. * @fs_phy_type Full-speed PHY interface type
  263. * 0 - Full speed interface not supported
  264. * 1 - Dedicated full speed interface
  265. * 2 - FS pins shared with UTMI+ pins
  266. * 3 - FS pins shared with ULPI pins
  267. * @total_fifo_size: Total internal RAM for FIFOs (bytes)
  268. * @utmi_phy_data_width UTMI+ PHY data width
  269. * 0 - 8 bits
  270. * 1 - 16 bits
  271. * 2 - 8 or 16 bits
  272. * @snpsid: Value from SNPSID register
  273. */
  274. struct dwc2_hw_params {
  275. unsigned op_mode:3;
  276. unsigned arch:2;
  277. unsigned dma_desc_enable:1;
  278. unsigned enable_dynamic_fifo:1;
  279. unsigned en_multiple_tx_fifo:1;
  280. unsigned host_rx_fifo_size:16;
  281. unsigned host_nperio_tx_fifo_size:16;
  282. unsigned host_perio_tx_fifo_size:16;
  283. unsigned nperio_tx_q_depth:3;
  284. unsigned host_perio_tx_q_depth:3;
  285. unsigned dev_token_q_depth:5;
  286. unsigned max_transfer_size:26;
  287. unsigned max_packet_count:11;
  288. unsigned host_channels:5;
  289. unsigned hs_phy_type:2;
  290. unsigned fs_phy_type:2;
  291. unsigned i2c_enable:1;
  292. unsigned num_dev_ep:4;
  293. unsigned num_dev_perio_in_ep:4;
  294. unsigned total_fifo_size:16;
  295. unsigned power_optimized:1;
  296. unsigned utmi_phy_data_width:2;
  297. u32 snpsid;
  298. };
  299. /**
  300. * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
  301. * and periodic schedules
  302. *
  303. * @dev: The struct device pointer
  304. * @regs: Pointer to controller regs
  305. * @core_params: Parameters that define how the core should be configured
  306. * @hw_params: Parameters that were autodetected from the
  307. * hardware registers
  308. * @op_state: The operational State, during transitions (a_host=>
  309. * a_peripheral and b_device=>b_host) this may not match
  310. * the core, but allows the software to determine
  311. * transitions
  312. * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
  313. * transfer are in process of being queued
  314. * @srp_success: Stores status of SRP request in the case of a FS PHY
  315. * with an I2C interface
  316. * @wq_otg: Workqueue object used for handling of some interrupts
  317. * @wf_otg: Work object for handling Connector ID Status Change
  318. * interrupt
  319. * @wkp_timer: Timer object for handling Wakeup Detected interrupt
  320. * @lx_state: Lx state of connected device
  321. * @flags: Flags for handling root port state changes
  322. * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
  323. * Transfers associated with these QHs are not currently
  324. * assigned to a host channel.
  325. * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
  326. * Transfers associated with these QHs are currently
  327. * assigned to a host channel.
  328. * @non_periodic_qh_ptr: Pointer to next QH to process in the active
  329. * non-periodic schedule
  330. * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
  331. * list of QHs for periodic transfers that are _not_
  332. * scheduled for the next frame. Each QH in the list has an
  333. * interval counter that determines when it needs to be
  334. * scheduled for execution. This scheduling mechanism
  335. * allows only a simple calculation for periodic bandwidth
  336. * used (i.e. must assume that all periodic transfers may
  337. * need to execute in the same frame). However, it greatly
  338. * simplifies scheduling and should be sufficient for the
  339. * vast majority of OTG hosts, which need to connect to a
  340. * small number of peripherals at one time. Items move from
  341. * this list to periodic_sched_ready when the QH interval
  342. * counter is 0 at SOF.
  343. * @periodic_sched_ready: List of periodic QHs that are ready for execution in
  344. * the next frame, but have not yet been assigned to host
  345. * channels. Items move from this list to
  346. * periodic_sched_assigned as host channels become
  347. * available during the current frame.
  348. * @periodic_sched_assigned: List of periodic QHs to be executed in the next
  349. * frame that are assigned to host channels. Items move
  350. * from this list to periodic_sched_queued as the
  351. * transactions for the QH are queued to the DWC_otg
  352. * controller.
  353. * @periodic_sched_queued: List of periodic QHs that have been queued for
  354. * execution. Items move from this list to either
  355. * periodic_sched_inactive or periodic_sched_ready when the
  356. * channel associated with the transfer is released. If the
  357. * interval for the QH is 1, the item moves to
  358. * periodic_sched_ready because it must be rescheduled for
  359. * the next frame. Otherwise, the item moves to
  360. * periodic_sched_inactive.
  361. * @periodic_usecs: Total bandwidth claimed so far for periodic transfers.
  362. * This value is in microseconds per (micro)frame. The
  363. * assumption is that all periodic transfers may occur in
  364. * the same (micro)frame.
  365. * @frame_usecs: Internal variable used by the microframe scheduler
  366. * @frame_number: Frame number read from the core at SOF. The value ranges
  367. * from 0 to HFNUM_MAX_FRNUM.
  368. * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
  369. * SOF enable/disable.
  370. * @free_hc_list: Free host channels in the controller. This is a list of
  371. * struct dwc2_host_chan items.
  372. * @periodic_channels: Number of host channels assigned to periodic transfers.
  373. * Currently assuming that there is a dedicated host
  374. * channel for each periodic transaction and at least one
  375. * host channel is available for non-periodic transactions.
  376. * @non_periodic_channels: Number of host channels assigned to non-periodic
  377. * transfers
  378. * @available_host_channels Number of host channels available for the microframe
  379. * scheduler to use
  380. * @hc_ptr_array: Array of pointers to the host channel descriptors.
  381. * Allows accessing a host channel descriptor given the
  382. * host channel number. This is useful in interrupt
  383. * handlers.
  384. * @status_buf: Buffer used for data received during the status phase of
  385. * a control transfer.
  386. * @status_buf_dma: DMA address for status_buf
  387. * @start_work: Delayed work for handling host A-cable connection
  388. * @reset_work: Delayed work for handling a port reset
  389. * @lock: Spinlock that protects all the driver data structures
  390. * @priv: Stores a pointer to the struct usb_hcd
  391. * @otg_port: OTG port number
  392. * @frame_list: Frame list
  393. * @frame_list_dma: Frame list DMA address
  394. */
  395. struct dwc2_hsotg {
  396. struct device *dev;
  397. void __iomem *regs;
  398. /** Params detected from hardware */
  399. struct dwc2_hw_params hw_params;
  400. /** Params to actually use */
  401. struct dwc2_core_params *core_params;
  402. enum usb_otg_state op_state;
  403. unsigned int queuing_high_bandwidth:1;
  404. unsigned int srp_success:1;
  405. struct workqueue_struct *wq_otg;
  406. struct work_struct wf_otg;
  407. struct timer_list wkp_timer;
  408. enum dwc2_lx_state lx_state;
  409. union dwc2_hcd_internal_flags {
  410. u32 d32;
  411. struct {
  412. unsigned port_connect_status_change:1;
  413. unsigned port_connect_status:1;
  414. unsigned port_reset_change:1;
  415. unsigned port_enable_change:1;
  416. unsigned port_suspend_change:1;
  417. unsigned port_over_current_change:1;
  418. unsigned port_l1_change:1;
  419. unsigned reserved:26;
  420. } b;
  421. } flags;
  422. struct list_head non_periodic_sched_inactive;
  423. struct list_head non_periodic_sched_active;
  424. struct list_head *non_periodic_qh_ptr;
  425. struct list_head periodic_sched_inactive;
  426. struct list_head periodic_sched_ready;
  427. struct list_head periodic_sched_assigned;
  428. struct list_head periodic_sched_queued;
  429. u16 periodic_usecs;
  430. u16 frame_usecs[8];
  431. u16 frame_number;
  432. u16 periodic_qh_count;
  433. #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
  434. #define FRAME_NUM_ARRAY_SIZE 1000
  435. u16 last_frame_num;
  436. u16 *frame_num_array;
  437. u16 *last_frame_num_array;
  438. int frame_num_idx;
  439. int dumped_frame_num_array;
  440. #endif
  441. struct list_head free_hc_list;
  442. int periodic_channels;
  443. int non_periodic_channels;
  444. int available_host_channels;
  445. struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
  446. u8 *status_buf;
  447. dma_addr_t status_buf_dma;
  448. #define DWC2_HCD_STATUS_BUF_SIZE 64
  449. struct delayed_work start_work;
  450. struct delayed_work reset_work;
  451. spinlock_t lock;
  452. void *priv;
  453. u8 otg_port;
  454. u32 *frame_list;
  455. dma_addr_t frame_list_dma;
  456. /* DWC OTG HW Release versions */
  457. #define DWC2_CORE_REV_2_71a 0x4f54271a
  458. #define DWC2_CORE_REV_2_90a 0x4f54290a
  459. #define DWC2_CORE_REV_2_92a 0x4f54292a
  460. #define DWC2_CORE_REV_2_94a 0x4f54294a
  461. #define DWC2_CORE_REV_3_00a 0x4f54300a
  462. #ifdef DEBUG
  463. u32 frrem_samples;
  464. u64 frrem_accum;
  465. u32 hfnum_7_samples_a;
  466. u64 hfnum_7_frrem_accum_a;
  467. u32 hfnum_0_samples_a;
  468. u64 hfnum_0_frrem_accum_a;
  469. u32 hfnum_other_samples_a;
  470. u64 hfnum_other_frrem_accum_a;
  471. u32 hfnum_7_samples_b;
  472. u64 hfnum_7_frrem_accum_b;
  473. u32 hfnum_0_samples_b;
  474. u64 hfnum_0_frrem_accum_b;
  475. u32 hfnum_other_samples_b;
  476. u64 hfnum_other_frrem_accum_b;
  477. #endif
  478. };
  479. /* Reasons for halting a host channel */
  480. enum dwc2_halt_status {
  481. DWC2_HC_XFER_NO_HALT_STATUS,
  482. DWC2_HC_XFER_COMPLETE,
  483. DWC2_HC_XFER_URB_COMPLETE,
  484. DWC2_HC_XFER_ACK,
  485. DWC2_HC_XFER_NAK,
  486. DWC2_HC_XFER_NYET,
  487. DWC2_HC_XFER_STALL,
  488. DWC2_HC_XFER_XACT_ERR,
  489. DWC2_HC_XFER_FRAME_OVERRUN,
  490. DWC2_HC_XFER_BABBLE_ERR,
  491. DWC2_HC_XFER_DATA_TOGGLE_ERR,
  492. DWC2_HC_XFER_AHB_ERR,
  493. DWC2_HC_XFER_PERIODIC_INCOMPLETE,
  494. DWC2_HC_XFER_URB_DEQUEUE,
  495. };
  496. /*
  497. * The following functions support initialization of the core driver component
  498. * and the DWC_otg controller
  499. */
  500. extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
  501. /*
  502. * Host core Functions.
  503. * The following functions support managing the DWC_otg controller in host
  504. * mode.
  505. */
  506. extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
  507. extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
  508. enum dwc2_halt_status halt_status);
  509. extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
  510. struct dwc2_host_chan *chan);
  511. extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
  512. struct dwc2_host_chan *chan);
  513. extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
  514. struct dwc2_host_chan *chan);
  515. extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
  516. struct dwc2_host_chan *chan);
  517. extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
  518. struct dwc2_host_chan *chan);
  519. extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
  520. extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
  521. extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
  522. extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
  523. /*
  524. * Common core Functions.
  525. * The following functions support managing the DWC_otg controller in either
  526. * device or host mode.
  527. */
  528. extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
  529. extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
  530. extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
  531. extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq);
  532. extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
  533. extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
  534. /* This function should be called on every hardware interrupt. */
  535. extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
  536. /* OTG Core Parameters */
  537. /*
  538. * Specifies the OTG capabilities. The driver will automatically
  539. * detect the value for this parameter if none is specified.
  540. * 0 - HNP and SRP capable (default)
  541. * 1 - SRP Only capable
  542. * 2 - No HNP/SRP capable
  543. */
  544. extern void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
  545. #define DWC2_CAP_PARAM_HNP_SRP_CAPABLE 0
  546. #define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE 1
  547. #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  548. /*
  549. * Specifies whether to use slave or DMA mode for accessing the data
  550. * FIFOs. The driver will automatically detect the value for this
  551. * parameter if none is specified.
  552. * 0 - Slave
  553. * 1 - DMA (default, if available)
  554. */
  555. extern void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
  556. /*
  557. * When DMA mode is enabled specifies whether to use
  558. * address DMA or DMA Descritor mode for accessing the data
  559. * FIFOs in device mode. The driver will automatically detect
  560. * the value for this parameter if none is specified.
  561. * 0 - address DMA
  562. * 1 - DMA Descriptor(default, if available)
  563. */
  564. extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
  565. /*
  566. * Specifies the maximum speed of operation in host and device mode.
  567. * The actual speed depends on the speed of the attached device and
  568. * the value of phy_type. The actual speed depends on the speed of the
  569. * attached device.
  570. * 0 - High Speed (default)
  571. * 1 - Full Speed
  572. */
  573. extern void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
  574. #define DWC2_SPEED_PARAM_HIGH 0
  575. #define DWC2_SPEED_PARAM_FULL 1
  576. /*
  577. * Specifies whether low power mode is supported when attached
  578. * to a Full Speed or Low Speed device in host mode.
  579. *
  580. * 0 - Don't support low power mode (default)
  581. * 1 - Support low power mode
  582. */
  583. extern void dwc2_set_param_host_support_fs_ls_low_power(
  584. struct dwc2_hsotg *hsotg, int val);
  585. /*
  586. * Specifies the PHY clock rate in low power mode when connected to a
  587. * Low Speed device in host mode. This parameter is applicable only if
  588. * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  589. * then defaults to 6 MHZ otherwise 48 MHZ.
  590. *
  591. * 0 - 48 MHz
  592. * 1 - 6 MHz
  593. */
  594. extern void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
  595. int val);
  596. #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  597. #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  598. /*
  599. * 0 - Use cC FIFO size parameters
  600. * 1 - Allow dynamic FIFO sizing (default)
  601. */
  602. extern void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
  603. int val);
  604. /*
  605. * Number of 4-byte words in the Rx FIFO in host mode when dynamic
  606. * FIFO sizing is enabled.
  607. * 16 to 32768 (default 1024)
  608. */
  609. extern void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
  610. /*
  611. * Number of 4-byte words in the non-periodic Tx FIFO in host mode
  612. * when Dynamic FIFO sizing is enabled in the core.
  613. * 16 to 32768 (default 256)
  614. */
  615. extern void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
  616. int val);
  617. /*
  618. * Number of 4-byte words in the host periodic Tx FIFO when dynamic
  619. * FIFO sizing is enabled.
  620. * 16 to 32768 (default 256)
  621. */
  622. extern void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
  623. int val);
  624. /*
  625. * The maximum transfer size supported in bytes.
  626. * 2047 to 65,535 (default 65,535)
  627. */
  628. extern void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
  629. /*
  630. * The maximum number of packets in a transfer.
  631. * 15 to 511 (default 511)
  632. */
  633. extern void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
  634. /*
  635. * The number of host channel registers to use.
  636. * 1 to 16 (default 11)
  637. * Note: The FPGA configuration supports a maximum of 11 host channels.
  638. */
  639. extern void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
  640. /*
  641. * Specifies the type of PHY interface to use. By default, the driver
  642. * will automatically detect the phy_type.
  643. *
  644. * 0 - Full Speed PHY
  645. * 1 - UTMI+ (default)
  646. * 2 - ULPI
  647. */
  648. extern void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
  649. #define DWC2_PHY_TYPE_PARAM_FS 0
  650. #define DWC2_PHY_TYPE_PARAM_UTMI 1
  651. #define DWC2_PHY_TYPE_PARAM_ULPI 2
  652. /*
  653. * Specifies the UTMI+ Data Width. This parameter is
  654. * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  655. * PHY_TYPE, this parameter indicates the data width between
  656. * the MAC and the ULPI Wrapper.) Also, this parameter is
  657. * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  658. * to "8 and 16 bits", meaning that the core has been
  659. * configured to work at either data path width.
  660. *
  661. * 8 or 16 bits (default 16)
  662. */
  663. extern void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
  664. /*
  665. * Specifies whether the ULPI operates at double or single
  666. * data rate. This parameter is only applicable if PHY_TYPE is
  667. * ULPI.
  668. *
  669. * 0 - single data rate ULPI interface with 8 bit wide data
  670. * bus (default)
  671. * 1 - double data rate ULPI interface with 4 bit wide data
  672. * bus
  673. */
  674. extern void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
  675. /*
  676. * Specifies whether to use the internal or external supply to
  677. * drive the vbus with a ULPI phy.
  678. */
  679. extern void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
  680. #define DWC2_PHY_ULPI_INTERNAL_VBUS 0
  681. #define DWC2_PHY_ULPI_EXTERNAL_VBUS 1
  682. /*
  683. * Specifies whether to use the I2Cinterface for full speed PHY. This
  684. * parameter is only applicable if PHY_TYPE is FS.
  685. * 0 - No (default)
  686. * 1 - Yes
  687. */
  688. extern void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
  689. extern void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
  690. extern void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
  691. /*
  692. * Specifies whether dedicated transmit FIFOs are
  693. * enabled for non periodic IN endpoints in device mode
  694. * 0 - No
  695. * 1 - Yes
  696. */
  697. extern void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
  698. int val);
  699. extern void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
  700. extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
  701. extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
  702. /*
  703. * Dump core registers and SPRAM
  704. */
  705. extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
  706. extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
  707. extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
  708. /*
  709. * Return OTG version - either 1.3 or 2.0
  710. */
  711. extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
  712. #endif /* __DWC2_CORE_H__ */