core.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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 s3c_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. * @sent_zlp: Set if we've sent 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 s3c_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 char dir_in;
  133. unsigned char index;
  134. unsigned char mc;
  135. unsigned char interval;
  136. unsigned int halted:1;
  137. unsigned int periodic:1;
  138. unsigned int isochronous:1;
  139. unsigned int sent_zlp:1;
  140. char name[10];
  141. };
  142. /**
  143. * struct s3c_hsotg - driver state.
  144. * @dev: The parent device supplied to the probe function
  145. * @driver: USB gadget driver
  146. * @phy: The otg phy transceiver structure for phy control.
  147. * @uphy: The otg phy transceiver structure for old USB phy control.
  148. * @plat: The platform specific configuration data. This can be removed once
  149. * all SoCs support usb transceiver.
  150. * @regs: The memory area mapped for accessing registers.
  151. * @irq: The IRQ number we are using
  152. * @supplies: Definition of USB power supplies
  153. * @phyif: PHY interface width
  154. * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
  155. * @num_of_eps: Number of available EPs (excluding EP0)
  156. * @debug_root: root directrory for debugfs.
  157. * @debug_file: main status file for debugfs.
  158. * @debug_fifo: FIFO status file for debugfs.
  159. * @ep0_reply: Request used for ep0 reply.
  160. * @ep0_buff: Buffer for EP0 reply data, if needed.
  161. * @ctrl_buff: Buffer for EP0 control requests.
  162. * @ctrl_req: Request for EP0 control packets.
  163. * @setup: NAK management for EP0 SETUP
  164. * @last_rst: Time of last reset
  165. * @eps: The endpoints being supplied to the gadget framework
  166. */
  167. struct s3c_hsotg {
  168. struct device *dev;
  169. struct usb_gadget_driver *driver;
  170. struct phy *phy;
  171. struct usb_phy *uphy;
  172. struct s3c_hsotg_plat *plat;
  173. spinlock_t lock;
  174. void __iomem *regs;
  175. int irq;
  176. struct clk *clk;
  177. struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)];
  178. u32 phyif;
  179. unsigned int dedicated_fifos:1;
  180. unsigned char num_of_eps;
  181. struct dentry *debug_root;
  182. struct dentry *debug_file;
  183. struct dentry *debug_fifo;
  184. struct usb_request *ep0_reply;
  185. struct usb_request *ctrl_req;
  186. u8 ep0_buff[8];
  187. u8 ctrl_buff[8];
  188. struct usb_gadget gadget;
  189. unsigned int setup;
  190. unsigned long last_rst;
  191. struct s3c_hsotg_ep *eps;
  192. };
  193. /**
  194. * struct s3c_hsotg_req - data transfer request
  195. * @req: The USB gadget request
  196. * @queue: The list of requests for the endpoint this is queued for.
  197. * @in_progress: Has already had size/packets written to core
  198. * @mapped: DMA buffer for this request has been mapped via dma_map_single().
  199. */
  200. struct s3c_hsotg_req {
  201. struct usb_request req;
  202. struct list_head queue;
  203. unsigned char in_progress;
  204. unsigned char mapped;
  205. };
  206. #define call_gadget(_hs, _entry) \
  207. do { \
  208. if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
  209. (_hs)->driver && (_hs)->driver->_entry) { \
  210. spin_unlock(&_hs->lock); \
  211. (_hs)->driver->_entry(&(_hs)->gadget); \
  212. spin_lock(&_hs->lock); \
  213. } \
  214. } while (0)
  215. struct dwc2_hsotg;
  216. struct dwc2_host_chan;
  217. /* Device States */
  218. enum dwc2_lx_state {
  219. DWC2_L0, /* On state */
  220. DWC2_L1, /* LPM sleep state */
  221. DWC2_L2, /* USB suspend state */
  222. DWC2_L3, /* Off state */
  223. };
  224. /**
  225. * struct dwc2_core_params - Parameters for configuring the core
  226. *
  227. * @otg_cap: Specifies the OTG capabilities.
  228. * 0 - HNP and SRP capable
  229. * 1 - SRP Only capable
  230. * 2 - No HNP/SRP capable (always available)
  231. * Defaults to best available option (0, 1, then 2)
  232. * @otg_ver: OTG version supported
  233. * 0 - 1.3 (default)
  234. * 1 - 2.0
  235. * @dma_enable: Specifies whether to use slave or DMA mode for accessing
  236. * the data FIFOs. The driver will automatically detect the
  237. * value for this parameter if none is specified.
  238. * 0 - Slave (always available)
  239. * 1 - DMA (default, if available)
  240. * @dma_desc_enable: When DMA mode is enabled, specifies whether to use
  241. * address DMA mode or descriptor DMA mode for accessing
  242. * the data FIFOs. The driver will automatically detect the
  243. * value for this if none is specified.
  244. * 0 - Address DMA
  245. * 1 - Descriptor DMA (default, if available)
  246. * @speed: Specifies the maximum speed of operation in host and
  247. * device mode. The actual speed depends on the speed of
  248. * the attached device and the value of phy_type.
  249. * 0 - High Speed
  250. * (default when phy_type is UTMI+ or ULPI)
  251. * 1 - Full Speed
  252. * (default when phy_type is Full Speed)
  253. * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
  254. * 1 - Allow dynamic FIFO sizing (default, if available)
  255. * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
  256. * are enabled
  257. * @host_rx_fifo_size: Number of 4-byte words in the Rx FIFO in host mode when
  258. * dynamic FIFO sizing is enabled
  259. * 16 to 32768
  260. * Actual maximum value is autodetected and also
  261. * the default.
  262. * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
  263. * in host mode when dynamic FIFO sizing is enabled
  264. * 16 to 32768
  265. * Actual maximum value is autodetected and also
  266. * the default.
  267. * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
  268. * host mode when dynamic FIFO sizing is enabled
  269. * 16 to 32768
  270. * Actual maximum value is autodetected and also
  271. * the default.
  272. * @max_transfer_size: The maximum transfer size supported, in bytes
  273. * 2047 to 65,535
  274. * Actual maximum value is autodetected and also
  275. * the default.
  276. * @max_packet_count: The maximum number of packets in a transfer
  277. * 15 to 511
  278. * Actual maximum value is autodetected and also
  279. * the default.
  280. * @host_channels: The number of host channel registers to use
  281. * 1 to 16
  282. * Actual maximum value is autodetected and also
  283. * the default.
  284. * @phy_type: Specifies the type of PHY interface to use. By default,
  285. * the driver will automatically detect the phy_type.
  286. * 0 - Full Speed Phy
  287. * 1 - UTMI+ Phy
  288. * 2 - ULPI Phy
  289. * Defaults to best available option (2, 1, then 0)
  290. * @phy_utmi_width: Specifies the UTMI+ Data Width (in bits). This parameter
  291. * is applicable for a phy_type of UTMI+ or ULPI. (For a
  292. * ULPI phy_type, this parameter indicates the data width
  293. * between the MAC and the ULPI Wrapper.) Also, this
  294. * parameter is applicable only if the OTG_HSPHY_WIDTH cC
  295. * parameter was set to "8 and 16 bits", meaning that the
  296. * core has been configured to work at either data path
  297. * width.
  298. * 8 or 16 (default 16 if available)
  299. * @phy_ulpi_ddr: Specifies whether the ULPI operates at double or single
  300. * data rate. This parameter is only applicable if phy_type
  301. * is ULPI.
  302. * 0 - single data rate ULPI interface with 8 bit wide
  303. * data bus (default)
  304. * 1 - double data rate ULPI interface with 4 bit wide
  305. * data bus
  306. * @phy_ulpi_ext_vbus: For a ULPI phy, specifies whether to use the internal or
  307. * external supply to drive the VBus
  308. * 0 - Internal supply (default)
  309. * 1 - External supply
  310. * @i2c_enable: Specifies whether to use the I2Cinterface for a full
  311. * speed PHY. This parameter is only applicable if phy_type
  312. * is FS.
  313. * 0 - No (default)
  314. * 1 - Yes
  315. * @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
  316. * 0 - No (default)
  317. * 1 - Yes
  318. * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
  319. * when attached to a Full Speed or Low Speed device in
  320. * host mode.
  321. * 0 - Don't support low power mode (default)
  322. * 1 - Support low power mode
  323. * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
  324. * when connected to a Low Speed device in host
  325. * mode. This parameter is applicable only if
  326. * host_support_fs_ls_low_power is enabled.
  327. * 0 - 48 MHz
  328. * (default when phy_type is UTMI+ or ULPI)
  329. * 1 - 6 MHz
  330. * (default when phy_type is Full Speed)
  331. * @ts_dline: Enable Term Select Dline pulsing
  332. * 0 - No (default)
  333. * 1 - Yes
  334. * @reload_ctl: Allow dynamic reloading of HFIR register during runtime
  335. * 0 - No (default for core < 2.92a)
  336. * 1 - Yes (default for core >= 2.92a)
  337. * @ahbcfg: This field allows the default value of the GAHBCFG
  338. * register to be overridden
  339. * -1 - GAHBCFG value will be set to 0x06
  340. * (INCR4, default)
  341. * all others - GAHBCFG value will be overridden with
  342. * this value
  343. * Not all bits can be controlled like this, the
  344. * bits defined by GAHBCFG_CTRL_MASK are controlled
  345. * by the driver and are ignored in this
  346. * configuration value.
  347. * @uframe_sched: True to enable the microframe scheduler
  348. *
  349. * The following parameters may be specified when starting the module. These
  350. * parameters define how the DWC_otg controller should be configured. A
  351. * value of -1 (or any other out of range value) for any parameter means
  352. * to read the value from hardware (if possible) or use the builtin
  353. * default described above.
  354. */
  355. struct dwc2_core_params {
  356. /*
  357. * Don't add any non-int members here, this will break
  358. * dwc2_set_all_params!
  359. */
  360. int otg_cap;
  361. int otg_ver;
  362. int dma_enable;
  363. int dma_desc_enable;
  364. int speed;
  365. int enable_dynamic_fifo;
  366. int en_multiple_tx_fifo;
  367. int host_rx_fifo_size;
  368. int host_nperio_tx_fifo_size;
  369. int host_perio_tx_fifo_size;
  370. int max_transfer_size;
  371. int max_packet_count;
  372. int host_channels;
  373. int phy_type;
  374. int phy_utmi_width;
  375. int phy_ulpi_ddr;
  376. int phy_ulpi_ext_vbus;
  377. int i2c_enable;
  378. int ulpi_fs_ls;
  379. int host_support_fs_ls_low_power;
  380. int host_ls_low_power_phy_clk;
  381. int ts_dline;
  382. int reload_ctl;
  383. int ahbcfg;
  384. int uframe_sched;
  385. };
  386. /**
  387. * struct dwc2_hw_params - Autodetected parameters.
  388. *
  389. * These parameters are the various parameters read from hardware
  390. * registers during initialization. They typically contain the best
  391. * supported or maximum value that can be configured in the
  392. * corresponding dwc2_core_params value.
  393. *
  394. * The values that are not in dwc2_core_params are documented below.
  395. *
  396. * @op_mode Mode of Operation
  397. * 0 - HNP- and SRP-Capable OTG (Host & Device)
  398. * 1 - SRP-Capable OTG (Host & Device)
  399. * 2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
  400. * 3 - SRP-Capable Device
  401. * 4 - Non-OTG Device
  402. * 5 - SRP-Capable Host
  403. * 6 - Non-OTG Host
  404. * @arch Architecture
  405. * 0 - Slave only
  406. * 1 - External DMA
  407. * 2 - Internal DMA
  408. * @power_optimized Are power optimizations enabled?
  409. * @num_dev_ep Number of device endpoints available
  410. * @num_dev_perio_in_ep Number of device periodic IN endpoints
  411. * avaialable
  412. * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
  413. * Depth
  414. * 0 to 30
  415. * @host_perio_tx_q_depth
  416. * Host Mode Periodic Request Queue Depth
  417. * 2, 4 or 8
  418. * @nperio_tx_q_depth
  419. * Non-Periodic Request Queue Depth
  420. * 2, 4 or 8
  421. * @hs_phy_type High-speed PHY interface type
  422. * 0 - High-speed interface not supported
  423. * 1 - UTMI+
  424. * 2 - ULPI
  425. * 3 - UTMI+ and ULPI
  426. * @fs_phy_type Full-speed PHY interface type
  427. * 0 - Full speed interface not supported
  428. * 1 - Dedicated full speed interface
  429. * 2 - FS pins shared with UTMI+ pins
  430. * 3 - FS pins shared with ULPI pins
  431. * @total_fifo_size: Total internal RAM for FIFOs (bytes)
  432. * @utmi_phy_data_width UTMI+ PHY data width
  433. * 0 - 8 bits
  434. * 1 - 16 bits
  435. * 2 - 8 or 16 bits
  436. * @snpsid: Value from SNPSID register
  437. */
  438. struct dwc2_hw_params {
  439. unsigned op_mode:3;
  440. unsigned arch:2;
  441. unsigned dma_desc_enable:1;
  442. unsigned enable_dynamic_fifo:1;
  443. unsigned en_multiple_tx_fifo:1;
  444. unsigned host_rx_fifo_size:16;
  445. unsigned host_nperio_tx_fifo_size:16;
  446. unsigned host_perio_tx_fifo_size:16;
  447. unsigned nperio_tx_q_depth:3;
  448. unsigned host_perio_tx_q_depth:3;
  449. unsigned dev_token_q_depth:5;
  450. unsigned max_transfer_size:26;
  451. unsigned max_packet_count:11;
  452. unsigned host_channels:5;
  453. unsigned hs_phy_type:2;
  454. unsigned fs_phy_type:2;
  455. unsigned i2c_enable:1;
  456. unsigned num_dev_ep:4;
  457. unsigned num_dev_perio_in_ep:4;
  458. unsigned total_fifo_size:16;
  459. unsigned power_optimized:1;
  460. unsigned utmi_phy_data_width:2;
  461. u32 snpsid;
  462. };
  463. /**
  464. * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
  465. * and periodic schedules
  466. *
  467. * @dev: The struct device pointer
  468. * @regs: Pointer to controller regs
  469. * @core_params: Parameters that define how the core should be configured
  470. * @hw_params: Parameters that were autodetected from the
  471. * hardware registers
  472. * @op_state: The operational State, during transitions (a_host=>
  473. * a_peripheral and b_device=>b_host) this may not match
  474. * the core, but allows the software to determine
  475. * transitions
  476. * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
  477. * transfer are in process of being queued
  478. * @srp_success: Stores status of SRP request in the case of a FS PHY
  479. * with an I2C interface
  480. * @wq_otg: Workqueue object used for handling of some interrupts
  481. * @wf_otg: Work object for handling Connector ID Status Change
  482. * interrupt
  483. * @wkp_timer: Timer object for handling Wakeup Detected interrupt
  484. * @lx_state: Lx state of connected device
  485. * @flags: Flags for handling root port state changes
  486. * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
  487. * Transfers associated with these QHs are not currently
  488. * assigned to a host channel.
  489. * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
  490. * Transfers associated with these QHs are currently
  491. * assigned to a host channel.
  492. * @non_periodic_qh_ptr: Pointer to next QH to process in the active
  493. * non-periodic schedule
  494. * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
  495. * list of QHs for periodic transfers that are _not_
  496. * scheduled for the next frame. Each QH in the list has an
  497. * interval counter that determines when it needs to be
  498. * scheduled for execution. This scheduling mechanism
  499. * allows only a simple calculation for periodic bandwidth
  500. * used (i.e. must assume that all periodic transfers may
  501. * need to execute in the same frame). However, it greatly
  502. * simplifies scheduling and should be sufficient for the
  503. * vast majority of OTG hosts, which need to connect to a
  504. * small number of peripherals at one time. Items move from
  505. * this list to periodic_sched_ready when the QH interval
  506. * counter is 0 at SOF.
  507. * @periodic_sched_ready: List of periodic QHs that are ready for execution in
  508. * the next frame, but have not yet been assigned to host
  509. * channels. Items move from this list to
  510. * periodic_sched_assigned as host channels become
  511. * available during the current frame.
  512. * @periodic_sched_assigned: List of periodic QHs to be executed in the next
  513. * frame that are assigned to host channels. Items move
  514. * from this list to periodic_sched_queued as the
  515. * transactions for the QH are queued to the DWC_otg
  516. * controller.
  517. * @periodic_sched_queued: List of periodic QHs that have been queued for
  518. * execution. Items move from this list to either
  519. * periodic_sched_inactive or periodic_sched_ready when the
  520. * channel associated with the transfer is released. If the
  521. * interval for the QH is 1, the item moves to
  522. * periodic_sched_ready because it must be rescheduled for
  523. * the next frame. Otherwise, the item moves to
  524. * periodic_sched_inactive.
  525. * @periodic_usecs: Total bandwidth claimed so far for periodic transfers.
  526. * This value is in microseconds per (micro)frame. The
  527. * assumption is that all periodic transfers may occur in
  528. * the same (micro)frame.
  529. * @frame_usecs: Internal variable used by the microframe scheduler
  530. * @frame_number: Frame number read from the core at SOF. The value ranges
  531. * from 0 to HFNUM_MAX_FRNUM.
  532. * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
  533. * SOF enable/disable.
  534. * @free_hc_list: Free host channels in the controller. This is a list of
  535. * struct dwc2_host_chan items.
  536. * @periodic_channels: Number of host channels assigned to periodic transfers.
  537. * Currently assuming that there is a dedicated host
  538. * channel for each periodic transaction and at least one
  539. * host channel is available for non-periodic transactions.
  540. * @non_periodic_channels: Number of host channels assigned to non-periodic
  541. * transfers
  542. * @available_host_channels Number of host channels available for the microframe
  543. * scheduler to use
  544. * @hc_ptr_array: Array of pointers to the host channel descriptors.
  545. * Allows accessing a host channel descriptor given the
  546. * host channel number. This is useful in interrupt
  547. * handlers.
  548. * @status_buf: Buffer used for data received during the status phase of
  549. * a control transfer.
  550. * @status_buf_dma: DMA address for status_buf
  551. * @start_work: Delayed work for handling host A-cable connection
  552. * @reset_work: Delayed work for handling a port reset
  553. * @lock: Spinlock that protects all the driver data structures
  554. * @priv: Stores a pointer to the struct usb_hcd
  555. * @otg_port: OTG port number
  556. * @frame_list: Frame list
  557. * @frame_list_dma: Frame list DMA address
  558. */
  559. struct dwc2_hsotg {
  560. struct device *dev;
  561. void __iomem *regs;
  562. /** Params detected from hardware */
  563. struct dwc2_hw_params hw_params;
  564. /** Params to actually use */
  565. struct dwc2_core_params *core_params;
  566. enum usb_otg_state op_state;
  567. unsigned int queuing_high_bandwidth:1;
  568. unsigned int srp_success:1;
  569. struct workqueue_struct *wq_otg;
  570. struct work_struct wf_otg;
  571. struct timer_list wkp_timer;
  572. enum dwc2_lx_state lx_state;
  573. union dwc2_hcd_internal_flags {
  574. u32 d32;
  575. struct {
  576. unsigned port_connect_status_change:1;
  577. unsigned port_connect_status:1;
  578. unsigned port_reset_change:1;
  579. unsigned port_enable_change:1;
  580. unsigned port_suspend_change:1;
  581. unsigned port_over_current_change:1;
  582. unsigned port_l1_change:1;
  583. unsigned reserved:26;
  584. } b;
  585. } flags;
  586. struct list_head non_periodic_sched_inactive;
  587. struct list_head non_periodic_sched_active;
  588. struct list_head *non_periodic_qh_ptr;
  589. struct list_head periodic_sched_inactive;
  590. struct list_head periodic_sched_ready;
  591. struct list_head periodic_sched_assigned;
  592. struct list_head periodic_sched_queued;
  593. u16 periodic_usecs;
  594. u16 frame_usecs[8];
  595. u16 frame_number;
  596. u16 periodic_qh_count;
  597. #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
  598. #define FRAME_NUM_ARRAY_SIZE 1000
  599. u16 last_frame_num;
  600. u16 *frame_num_array;
  601. u16 *last_frame_num_array;
  602. int frame_num_idx;
  603. int dumped_frame_num_array;
  604. #endif
  605. struct list_head free_hc_list;
  606. int periodic_channels;
  607. int non_periodic_channels;
  608. int available_host_channels;
  609. struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
  610. u8 *status_buf;
  611. dma_addr_t status_buf_dma;
  612. #define DWC2_HCD_STATUS_BUF_SIZE 64
  613. struct delayed_work start_work;
  614. struct delayed_work reset_work;
  615. spinlock_t lock;
  616. void *priv;
  617. u8 otg_port;
  618. u32 *frame_list;
  619. dma_addr_t frame_list_dma;
  620. /* DWC OTG HW Release versions */
  621. #define DWC2_CORE_REV_2_71a 0x4f54271a
  622. #define DWC2_CORE_REV_2_90a 0x4f54290a
  623. #define DWC2_CORE_REV_2_92a 0x4f54292a
  624. #define DWC2_CORE_REV_2_94a 0x4f54294a
  625. #define DWC2_CORE_REV_3_00a 0x4f54300a
  626. #ifdef DEBUG
  627. u32 frrem_samples;
  628. u64 frrem_accum;
  629. u32 hfnum_7_samples_a;
  630. u64 hfnum_7_frrem_accum_a;
  631. u32 hfnum_0_samples_a;
  632. u64 hfnum_0_frrem_accum_a;
  633. u32 hfnum_other_samples_a;
  634. u64 hfnum_other_frrem_accum_a;
  635. u32 hfnum_7_samples_b;
  636. u64 hfnum_7_frrem_accum_b;
  637. u32 hfnum_0_samples_b;
  638. u64 hfnum_0_frrem_accum_b;
  639. u32 hfnum_other_samples_b;
  640. u64 hfnum_other_frrem_accum_b;
  641. #endif
  642. };
  643. /* Reasons for halting a host channel */
  644. enum dwc2_halt_status {
  645. DWC2_HC_XFER_NO_HALT_STATUS,
  646. DWC2_HC_XFER_COMPLETE,
  647. DWC2_HC_XFER_URB_COMPLETE,
  648. DWC2_HC_XFER_ACK,
  649. DWC2_HC_XFER_NAK,
  650. DWC2_HC_XFER_NYET,
  651. DWC2_HC_XFER_STALL,
  652. DWC2_HC_XFER_XACT_ERR,
  653. DWC2_HC_XFER_FRAME_OVERRUN,
  654. DWC2_HC_XFER_BABBLE_ERR,
  655. DWC2_HC_XFER_DATA_TOGGLE_ERR,
  656. DWC2_HC_XFER_AHB_ERR,
  657. DWC2_HC_XFER_PERIODIC_INCOMPLETE,
  658. DWC2_HC_XFER_URB_DEQUEUE,
  659. };
  660. /*
  661. * The following functions support initialization of the core driver component
  662. * and the DWC_otg controller
  663. */
  664. extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
  665. /*
  666. * Host core Functions.
  667. * The following functions support managing the DWC_otg controller in host
  668. * mode.
  669. */
  670. extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
  671. extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
  672. enum dwc2_halt_status halt_status);
  673. extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
  674. struct dwc2_host_chan *chan);
  675. extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
  676. struct dwc2_host_chan *chan);
  677. extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
  678. struct dwc2_host_chan *chan);
  679. extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
  680. struct dwc2_host_chan *chan);
  681. extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
  682. struct dwc2_host_chan *chan);
  683. extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
  684. extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
  685. extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
  686. extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
  687. /*
  688. * Common core Functions.
  689. * The following functions support managing the DWC_otg controller in either
  690. * device or host mode.
  691. */
  692. extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
  693. extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
  694. extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
  695. extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq);
  696. extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
  697. extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
  698. /* This function should be called on every hardware interrupt. */
  699. extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
  700. /* OTG Core Parameters */
  701. /*
  702. * Specifies the OTG capabilities. The driver will automatically
  703. * detect the value for this parameter if none is specified.
  704. * 0 - HNP and SRP capable (default)
  705. * 1 - SRP Only capable
  706. * 2 - No HNP/SRP capable
  707. */
  708. extern void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
  709. #define DWC2_CAP_PARAM_HNP_SRP_CAPABLE 0
  710. #define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE 1
  711. #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  712. /*
  713. * Specifies whether to use slave or DMA mode for accessing the data
  714. * FIFOs. The driver will automatically detect the value for this
  715. * parameter if none is specified.
  716. * 0 - Slave
  717. * 1 - DMA (default, if available)
  718. */
  719. extern void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
  720. /*
  721. * When DMA mode is enabled specifies whether to use
  722. * address DMA or DMA Descritor mode for accessing the data
  723. * FIFOs in device mode. The driver will automatically detect
  724. * the value for this parameter if none is specified.
  725. * 0 - address DMA
  726. * 1 - DMA Descriptor(default, if available)
  727. */
  728. extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
  729. /*
  730. * Specifies the maximum speed of operation in host and device mode.
  731. * The actual speed depends on the speed of the attached device and
  732. * the value of phy_type. The actual speed depends on the speed of the
  733. * attached device.
  734. * 0 - High Speed (default)
  735. * 1 - Full Speed
  736. */
  737. extern void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
  738. #define DWC2_SPEED_PARAM_HIGH 0
  739. #define DWC2_SPEED_PARAM_FULL 1
  740. /*
  741. * Specifies whether low power mode is supported when attached
  742. * to a Full Speed or Low Speed device in host mode.
  743. *
  744. * 0 - Don't support low power mode (default)
  745. * 1 - Support low power mode
  746. */
  747. extern void dwc2_set_param_host_support_fs_ls_low_power(
  748. struct dwc2_hsotg *hsotg, int val);
  749. /*
  750. * Specifies the PHY clock rate in low power mode when connected to a
  751. * Low Speed device in host mode. This parameter is applicable only if
  752. * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  753. * then defaults to 6 MHZ otherwise 48 MHZ.
  754. *
  755. * 0 - 48 MHz
  756. * 1 - 6 MHz
  757. */
  758. extern void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
  759. int val);
  760. #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  761. #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  762. /*
  763. * 0 - Use cC FIFO size parameters
  764. * 1 - Allow dynamic FIFO sizing (default)
  765. */
  766. extern void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
  767. int val);
  768. /*
  769. * Number of 4-byte words in the Rx FIFO in host mode when dynamic
  770. * FIFO sizing is enabled.
  771. * 16 to 32768 (default 1024)
  772. */
  773. extern void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
  774. /*
  775. * Number of 4-byte words in the non-periodic Tx FIFO in host mode
  776. * when Dynamic FIFO sizing is enabled in the core.
  777. * 16 to 32768 (default 256)
  778. */
  779. extern void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
  780. int val);
  781. /*
  782. * Number of 4-byte words in the host periodic Tx FIFO when dynamic
  783. * FIFO sizing is enabled.
  784. * 16 to 32768 (default 256)
  785. */
  786. extern void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
  787. int val);
  788. /*
  789. * The maximum transfer size supported in bytes.
  790. * 2047 to 65,535 (default 65,535)
  791. */
  792. extern void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
  793. /*
  794. * The maximum number of packets in a transfer.
  795. * 15 to 511 (default 511)
  796. */
  797. extern void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
  798. /*
  799. * The number of host channel registers to use.
  800. * 1 to 16 (default 11)
  801. * Note: The FPGA configuration supports a maximum of 11 host channels.
  802. */
  803. extern void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
  804. /*
  805. * Specifies the type of PHY interface to use. By default, the driver
  806. * will automatically detect the phy_type.
  807. *
  808. * 0 - Full Speed PHY
  809. * 1 - UTMI+ (default)
  810. * 2 - ULPI
  811. */
  812. extern void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
  813. #define DWC2_PHY_TYPE_PARAM_FS 0
  814. #define DWC2_PHY_TYPE_PARAM_UTMI 1
  815. #define DWC2_PHY_TYPE_PARAM_ULPI 2
  816. /*
  817. * Specifies the UTMI+ Data Width. This parameter is
  818. * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  819. * PHY_TYPE, this parameter indicates the data width between
  820. * the MAC and the ULPI Wrapper.) Also, this parameter is
  821. * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  822. * to "8 and 16 bits", meaning that the core has been
  823. * configured to work at either data path width.
  824. *
  825. * 8 or 16 bits (default 16)
  826. */
  827. extern void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
  828. /*
  829. * Specifies whether the ULPI operates at double or single
  830. * data rate. This parameter is only applicable if PHY_TYPE is
  831. * ULPI.
  832. *
  833. * 0 - single data rate ULPI interface with 8 bit wide data
  834. * bus (default)
  835. * 1 - double data rate ULPI interface with 4 bit wide data
  836. * bus
  837. */
  838. extern void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
  839. /*
  840. * Specifies whether to use the internal or external supply to
  841. * drive the vbus with a ULPI phy.
  842. */
  843. extern void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
  844. #define DWC2_PHY_ULPI_INTERNAL_VBUS 0
  845. #define DWC2_PHY_ULPI_EXTERNAL_VBUS 1
  846. /*
  847. * Specifies whether to use the I2Cinterface for full speed PHY. This
  848. * parameter is only applicable if PHY_TYPE is FS.
  849. * 0 - No (default)
  850. * 1 - Yes
  851. */
  852. extern void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
  853. extern void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
  854. extern void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
  855. /*
  856. * Specifies whether dedicated transmit FIFOs are
  857. * enabled for non periodic IN endpoints in device mode
  858. * 0 - No
  859. * 1 - Yes
  860. */
  861. extern void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
  862. int val);
  863. extern void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
  864. extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
  865. extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
  866. /*
  867. * Dump core registers and SPRAM
  868. */
  869. extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
  870. extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
  871. extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
  872. /*
  873. * Return OTG version - either 1.3 or 2.0
  874. */
  875. extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
  876. #endif /* __DWC2_CORE_H__ */