core.h 37 KB

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