net2280.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /*
  2. * NetChip 2280 high/full speed USB device controller.
  3. * Unlike many such controllers, this one talks PCI.
  4. */
  5. /*
  6. * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com)
  7. * Copyright (C) 2003 David Brownell
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. /*-------------------------------------------------------------------------*/
  24. /* NET2280 MEMORY MAPPED REGISTERS
  25. *
  26. * The register layout came from the chip documentation, and the bit
  27. * number definitions were extracted from chip specification.
  28. *
  29. * Use the shift operator ('<<') to build bit masks, with readl/writel
  30. * to access the registers through PCI.
  31. */
  32. /* main registers, BAR0 + 0x0000 */
  33. struct net2280_regs {
  34. // offset 0x0000
  35. u32 devinit;
  36. #define LOCAL_CLOCK_FREQUENCY 8
  37. #define FORCE_PCI_RESET 7
  38. #define PCI_ID 6
  39. #define PCI_ENABLE 5
  40. #define FIFO_SOFT_RESET 4
  41. #define CFG_SOFT_RESET 3
  42. #define PCI_SOFT_RESET 2
  43. #define USB_SOFT_RESET 1
  44. #define M8051_RESET 0
  45. u32 eectl;
  46. #define EEPROM_ADDRESS_WIDTH 23
  47. #define EEPROM_CHIP_SELECT_ACTIVE 22
  48. #define EEPROM_PRESENT 21
  49. #define EEPROM_VALID 20
  50. #define EEPROM_BUSY 19
  51. #define EEPROM_CHIP_SELECT_ENABLE 18
  52. #define EEPROM_BYTE_READ_START 17
  53. #define EEPROM_BYTE_WRITE_START 16
  54. #define EEPROM_READ_DATA 8
  55. #define EEPROM_WRITE_DATA 0
  56. u32 eeclkfreq;
  57. u32 _unused0;
  58. // offset 0x0010
  59. u32 pciirqenb0; /* interrupt PCI master ... */
  60. #define SETUP_PACKET_INTERRUPT_ENABLE 7
  61. #define ENDPOINT_F_INTERRUPT_ENABLE 6
  62. #define ENDPOINT_E_INTERRUPT_ENABLE 5
  63. #define ENDPOINT_D_INTERRUPT_ENABLE 4
  64. #define ENDPOINT_C_INTERRUPT_ENABLE 3
  65. #define ENDPOINT_B_INTERRUPT_ENABLE 2
  66. #define ENDPOINT_A_INTERRUPT_ENABLE 1
  67. #define ENDPOINT_0_INTERRUPT_ENABLE 0
  68. u32 pciirqenb1;
  69. #define PCI_INTERRUPT_ENABLE 31
  70. #define POWER_STATE_CHANGE_INTERRUPT_ENABLE 27
  71. #define PCI_ARBITER_TIMEOUT_INTERRUPT_ENABLE 26
  72. #define PCI_PARITY_ERROR_INTERRUPT_ENABLE 25
  73. #define PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE 20
  74. #define PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE 19
  75. #define PCI_TARGET_ABORT_ASSERTED_INTERRUPT_ENABLE 18
  76. #define PCI_RETRY_ABORT_INTERRUPT_ENABLE 17
  77. #define PCI_MASTER_CYCLE_DONE_INTERRUPT_ENABLE 16
  78. #define GPIO_INTERRUPT_ENABLE 13
  79. #define DMA_D_INTERRUPT_ENABLE 12
  80. #define DMA_C_INTERRUPT_ENABLE 11
  81. #define DMA_B_INTERRUPT_ENABLE 10
  82. #define DMA_A_INTERRUPT_ENABLE 9
  83. #define EEPROM_DONE_INTERRUPT_ENABLE 8
  84. #define VBUS_INTERRUPT_ENABLE 7
  85. #define CONTROL_STATUS_INTERRUPT_ENABLE 6
  86. #define ROOT_PORT_RESET_INTERRUPT_ENABLE 4
  87. #define SUSPEND_REQUEST_INTERRUPT_ENABLE 3
  88. #define SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE 2
  89. #define RESUME_INTERRUPT_ENABLE 1
  90. #define SOF_INTERRUPT_ENABLE 0
  91. u32 cpu_irqenb0; /* ... or onboard 8051 */
  92. #define SETUP_PACKET_INTERRUPT_ENABLE 7
  93. #define ENDPOINT_F_INTERRUPT_ENABLE 6
  94. #define ENDPOINT_E_INTERRUPT_ENABLE 5
  95. #define ENDPOINT_D_INTERRUPT_ENABLE 4
  96. #define ENDPOINT_C_INTERRUPT_ENABLE 3
  97. #define ENDPOINT_B_INTERRUPT_ENABLE 2
  98. #define ENDPOINT_A_INTERRUPT_ENABLE 1
  99. #define ENDPOINT_0_INTERRUPT_ENABLE 0
  100. u32 cpu_irqenb1;
  101. #define CPU_INTERRUPT_ENABLE 31
  102. #define POWER_STATE_CHANGE_INTERRUPT_ENABLE 27
  103. #define PCI_ARBITER_TIMEOUT_INTERRUPT_ENABLE 26
  104. #define PCI_PARITY_ERROR_INTERRUPT_ENABLE 25
  105. #define PCI_INTA_INTERRUPT_ENABLE 24
  106. #define PCI_PME_INTERRUPT_ENABLE 23
  107. #define PCI_SERR_INTERRUPT_ENABLE 22
  108. #define PCI_PERR_INTERRUPT_ENABLE 21
  109. #define PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE 20
  110. #define PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE 19
  111. #define PCI_RETRY_ABORT_INTERRUPT_ENABLE 17
  112. #define PCI_MASTER_CYCLE_DONE_INTERRUPT_ENABLE 16
  113. #define GPIO_INTERRUPT_ENABLE 13
  114. #define DMA_D_INTERRUPT_ENABLE 12
  115. #define DMA_C_INTERRUPT_ENABLE 11
  116. #define DMA_B_INTERRUPT_ENABLE 10
  117. #define DMA_A_INTERRUPT_ENABLE 9
  118. #define EEPROM_DONE_INTERRUPT_ENABLE 8
  119. #define VBUS_INTERRUPT_ENABLE 7
  120. #define CONTROL_STATUS_INTERRUPT_ENABLE 6
  121. #define ROOT_PORT_RESET_INTERRUPT_ENABLE 4
  122. #define SUSPEND_REQUEST_INTERRUPT_ENABLE 3
  123. #define SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE 2
  124. #define RESUME_INTERRUPT_ENABLE 1
  125. #define SOF_INTERRUPT_ENABLE 0
  126. // offset 0x0020
  127. u32 _unused1;
  128. u32 usbirqenb1;
  129. #define USB_INTERRUPT_ENABLE 31
  130. #define POWER_STATE_CHANGE_INTERRUPT_ENABLE 27
  131. #define PCI_ARBITER_TIMEOUT_INTERRUPT_ENABLE 26
  132. #define PCI_PARITY_ERROR_INTERRUPT_ENABLE 25
  133. #define PCI_INTA_INTERRUPT_ENABLE 24
  134. #define PCI_PME_INTERRUPT_ENABLE 23
  135. #define PCI_SERR_INTERRUPT_ENABLE 22
  136. #define PCI_PERR_INTERRUPT_ENABLE 21
  137. #define PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE 20
  138. #define PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE 19
  139. #define PCI_RETRY_ABORT_INTERRUPT_ENABLE 17
  140. #define PCI_MASTER_CYCLE_DONE_INTERRUPT_ENABLE 16
  141. #define GPIO_INTERRUPT_ENABLE 13
  142. #define DMA_D_INTERRUPT_ENABLE 12
  143. #define DMA_C_INTERRUPT_ENABLE 11
  144. #define DMA_B_INTERRUPT_ENABLE 10
  145. #define DMA_A_INTERRUPT_ENABLE 9
  146. #define EEPROM_DONE_INTERRUPT_ENABLE 8
  147. #define VBUS_INTERRUPT_ENABLE 7
  148. #define CONTROL_STATUS_INTERRUPT_ENABLE 6
  149. #define ROOT_PORT_RESET_INTERRUPT_ENABLE 4
  150. #define SUSPEND_REQUEST_INTERRUPT_ENABLE 3
  151. #define SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE 2
  152. #define RESUME_INTERRUPT_ENABLE 1
  153. #define SOF_INTERRUPT_ENABLE 0
  154. u32 irqstat0;
  155. #define INTA_ASSERTED 12
  156. #define SETUP_PACKET_INTERRUPT 7
  157. #define ENDPOINT_F_INTERRUPT 6
  158. #define ENDPOINT_E_INTERRUPT 5
  159. #define ENDPOINT_D_INTERRUPT 4
  160. #define ENDPOINT_C_INTERRUPT 3
  161. #define ENDPOINT_B_INTERRUPT 2
  162. #define ENDPOINT_A_INTERRUPT 1
  163. #define ENDPOINT_0_INTERRUPT 0
  164. u32 irqstat1;
  165. #define POWER_STATE_CHANGE_INTERRUPT 27
  166. #define PCI_ARBITER_TIMEOUT_INTERRUPT 26
  167. #define PCI_PARITY_ERROR_INTERRUPT 25
  168. #define PCI_INTA_INTERRUPT 24
  169. #define PCI_PME_INTERRUPT 23
  170. #define PCI_SERR_INTERRUPT 22
  171. #define PCI_PERR_INTERRUPT 21
  172. #define PCI_MASTER_ABORT_RECEIVED_INTERRUPT 20
  173. #define PCI_TARGET_ABORT_RECEIVED_INTERRUPT 19
  174. #define PCI_RETRY_ABORT_INTERRUPT 17
  175. #define PCI_MASTER_CYCLE_DONE_INTERRUPT 16
  176. #define SOF_DOWN_INTERRUPT 14
  177. #define GPIO_INTERRUPT 13
  178. #define DMA_D_INTERRUPT 12
  179. #define DMA_C_INTERRUPT 11
  180. #define DMA_B_INTERRUPT 10
  181. #define DMA_A_INTERRUPT 9
  182. #define EEPROM_DONE_INTERRUPT 8
  183. #define VBUS_INTERRUPT 7
  184. #define CONTROL_STATUS_INTERRUPT 6
  185. #define ROOT_PORT_RESET_INTERRUPT 4
  186. #define SUSPEND_REQUEST_INTERRUPT 3
  187. #define SUSPEND_REQUEST_CHANGE_INTERRUPT 2
  188. #define RESUME_INTERRUPT 1
  189. #define SOF_INTERRUPT 0
  190. // offset 0x0030
  191. u32 idxaddr;
  192. u32 idxdata;
  193. u32 fifoctl;
  194. #define PCI_BASE2_RANGE 16
  195. #define IGNORE_FIFO_AVAILABILITY 3
  196. #define PCI_BASE2_SELECT 2
  197. #define FIFO_CONFIGURATION_SELECT 0
  198. u32 _unused2;
  199. // offset 0x0040
  200. u32 memaddr;
  201. #define START 28
  202. #define DIRECTION 27
  203. #define FIFO_DIAGNOSTIC_SELECT 24
  204. #define MEMORY_ADDRESS 0
  205. u32 memdata0;
  206. u32 memdata1;
  207. u32 _unused3;
  208. // offset 0x0050
  209. u32 gpioctl;
  210. #define GPIO3_LED_SELECT 12
  211. #define GPIO3_INTERRUPT_ENABLE 11
  212. #define GPIO2_INTERRUPT_ENABLE 10
  213. #define GPIO1_INTERRUPT_ENABLE 9
  214. #define GPIO0_INTERRUPT_ENABLE 8
  215. #define GPIO3_OUTPUT_ENABLE 7
  216. #define GPIO2_OUTPUT_ENABLE 6
  217. #define GPIO1_OUTPUT_ENABLE 5
  218. #define GPIO0_OUTPUT_ENABLE 4
  219. #define GPIO3_DATA 3
  220. #define GPIO2_DATA 2
  221. #define GPIO1_DATA 1
  222. #define GPIO0_DATA 0
  223. u32 gpiostat;
  224. #define GPIO3_INTERRUPT 3
  225. #define GPIO2_INTERRUPT 2
  226. #define GPIO1_INTERRUPT 1
  227. #define GPIO0_INTERRUPT 0
  228. } __attribute__ ((packed));
  229. /* usb control, BAR0 + 0x0080 */
  230. struct net2280_usb_regs {
  231. // offset 0x0080
  232. u32 stdrsp;
  233. #define STALL_UNSUPPORTED_REQUESTS 31
  234. #define SET_TEST_MODE 16
  235. #define GET_OTHER_SPEED_CONFIGURATION 15
  236. #define GET_DEVICE_QUALIFIER 14
  237. #define SET_ADDRESS 13
  238. #define ENDPOINT_SET_CLEAR_HALT 12
  239. #define DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP 11
  240. #define GET_STRING_DESCRIPTOR_2 10
  241. #define GET_STRING_DESCRIPTOR_1 9
  242. #define GET_STRING_DESCRIPTOR_0 8
  243. #define GET_SET_INTERFACE 6
  244. #define GET_SET_CONFIGURATION 5
  245. #define GET_CONFIGURATION_DESCRIPTOR 4
  246. #define GET_DEVICE_DESCRIPTOR 3
  247. #define GET_ENDPOINT_STATUS 2
  248. #define GET_INTERFACE_STATUS 1
  249. #define GET_DEVICE_STATUS 0
  250. u32 prodvendid;
  251. #define PRODUCT_ID 16
  252. #define VENDOR_ID 0
  253. u32 relnum;
  254. u32 usbctl;
  255. #define SERIAL_NUMBER_INDEX 16
  256. #define PRODUCT_ID_STRING_ENABLE 13
  257. #define VENDOR_ID_STRING_ENABLE 12
  258. #define USB_ROOT_PORT_WAKEUP_ENABLE 11
  259. #define VBUS_PIN 10
  260. #define TIMED_DISCONNECT 9
  261. #define SUSPEND_IMMEDIATELY 7
  262. #define SELF_POWERED_USB_DEVICE 6
  263. #define REMOTE_WAKEUP_SUPPORT 5
  264. #define PME_POLARITY 4
  265. #define USB_DETECT_ENABLE 3
  266. #define PME_WAKEUP_ENABLE 2
  267. #define DEVICE_REMOTE_WAKEUP_ENABLE 1
  268. #define SELF_POWERED_STATUS 0
  269. // offset 0x0090
  270. u32 usbstat;
  271. #define HIGH_SPEED 7
  272. #define FULL_SPEED 6
  273. #define GENERATE_RESUME 5
  274. #define GENERATE_DEVICE_REMOTE_WAKEUP 4
  275. u32 xcvrdiag;
  276. #define FORCE_HIGH_SPEED_MODE 31
  277. #define FORCE_FULL_SPEED_MODE 30
  278. #define USB_TEST_MODE 24
  279. #define LINE_STATE 16
  280. #define TRANSCEIVER_OPERATION_MODE 2
  281. #define TRANSCEIVER_SELECT 1
  282. #define TERMINATION_SELECT 0
  283. u32 setup0123;
  284. u32 setup4567;
  285. // offset 0x0090
  286. u32 _unused0;
  287. u32 ouraddr;
  288. #define FORCE_IMMEDIATE 7
  289. #define OUR_USB_ADDRESS 0
  290. u32 ourconfig;
  291. } __attribute__ ((packed));
  292. /* pci control, BAR0 + 0x0100 */
  293. struct net2280_pci_regs {
  294. // offset 0x0100
  295. u32 pcimstctl;
  296. #define PCI_ARBITER_PARK_SELECT 13
  297. #define PCI_MULTI LEVEL_ARBITER 12
  298. #define PCI_RETRY_ABORT_ENABLE 11
  299. #define DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE 10
  300. #define DMA_READ_MULTIPLE_ENABLE 9
  301. #define DMA_READ_LINE_ENABLE 8
  302. #define PCI_MASTER_COMMAND_SELECT 6
  303. #define MEM_READ_OR_WRITE 0
  304. #define IO_READ_OR_WRITE 1
  305. #define CFG_READ_OR_WRITE 2
  306. #define PCI_MASTER_START 5
  307. #define PCI_MASTER_READ_WRITE 4
  308. #define PCI_MASTER_WRITE 0
  309. #define PCI_MASTER_READ 1
  310. #define PCI_MASTER_BYTE_WRITE_ENABLES 0
  311. u32 pcimstaddr;
  312. u32 pcimstdata;
  313. u32 pcimststat;
  314. #define PCI_ARBITER_CLEAR 2
  315. #define PCI_EXTERNAL_ARBITER 1
  316. #define PCI_HOST_MODE 0
  317. } __attribute__ ((packed));
  318. /* dma control, BAR0 + 0x0180 ... array of four structs like this,
  319. * for channels 0..3. see also struct net2280_dma: descriptor
  320. * that can be loaded into some of these registers.
  321. */
  322. struct net2280_dma_regs { /* [11.7] */
  323. // offset 0x0180, 0x01a0, 0x01c0, 0x01e0,
  324. u32 dmactl;
  325. #define DMA_SCATTER_GATHER_DONE_INTERRUPT_ENABLE 25
  326. #define DMA_CLEAR_COUNT_ENABLE 21
  327. #define DESCRIPTOR_POLLING_RATE 19
  328. #define POLL_CONTINUOUS 0
  329. #define POLL_1_USEC 1
  330. #define POLL_100_USEC 2
  331. #define POLL_1_MSEC 3
  332. #define DMA_VALID_BIT_POLLING_ENABLE 18
  333. #define DMA_VALID_BIT_ENABLE 17
  334. #define DMA_SCATTER_GATHER_ENABLE 16
  335. #define DMA_OUT_AUTO_START_ENABLE 4
  336. #define DMA_PREEMPT_ENABLE 3
  337. #define DMA_FIFO_VALIDATE 2
  338. #define DMA_ENABLE 1
  339. #define DMA_ADDRESS_HOLD 0
  340. u32 dmastat;
  341. #define DMA_ABORT_DONE_INTERRUPT 27
  342. #define DMA_SCATTER_GATHER_DONE_INTERRUPT 25
  343. #define DMA_TRANSACTION_DONE_INTERRUPT 24
  344. #define DMA_ABORT 1
  345. #define DMA_START 0
  346. u32 _unused0 [2];
  347. // offset 0x0190, 0x01b0, 0x01d0, 0x01f0,
  348. u32 dmacount;
  349. #define VALID_BIT 31
  350. #define DMA_DIRECTION 30
  351. #define DMA_DONE_INTERRUPT_ENABLE 29
  352. #define END_OF_CHAIN 28
  353. #define DMA_BYTE_COUNT_MASK ((1<<24)-1)
  354. #define DMA_BYTE_COUNT 0
  355. u32 dmaaddr;
  356. u32 dmadesc;
  357. u32 _unused1;
  358. } __attribute__ ((packed));
  359. /* dedicated endpoint registers, BAR0 + 0x0200 */
  360. struct net2280_dep_regs { /* [11.8] */
  361. // offset 0x0200, 0x0210, 0x220, 0x230, 0x240
  362. u32 dep_cfg;
  363. // offset 0x0204, 0x0214, 0x224, 0x234, 0x244
  364. u32 dep_rsp;
  365. u32 _unused [2];
  366. } __attribute__ ((packed));
  367. /* configurable endpoint registers, BAR0 + 0x0300 ... array of seven structs
  368. * like this, for ep0 then the configurable endpoints A..F
  369. * ep0 reserved for control; E and F have only 64 bytes of fifo
  370. */
  371. struct net2280_ep_regs { /* [11.9] */
  372. // offset 0x0300, 0x0320, 0x0340, 0x0360, 0x0380, 0x03a0, 0x03c0
  373. u32 ep_cfg;
  374. #define ENDPOINT_BYTE_COUNT 16
  375. #define ENDPOINT_ENABLE 10
  376. #define ENDPOINT_TYPE 8
  377. #define ENDPOINT_DIRECTION 7
  378. #define ENDPOINT_NUMBER 0
  379. u32 ep_rsp;
  380. #define SET_NAK_OUT_PACKETS 15
  381. #define SET_EP_HIDE_STATUS_PHASE 14
  382. #define SET_EP_FORCE_CRC_ERROR 13
  383. #define SET_INTERRUPT_MODE 12
  384. #define SET_CONTROL_STATUS_PHASE_HANDSHAKE 11
  385. #define SET_NAK_OUT_PACKETS_MODE 10
  386. #define SET_ENDPOINT_TOGGLE 9
  387. #define SET_ENDPOINT_HALT 8
  388. #define CLEAR_NAK_OUT_PACKETS 7
  389. #define CLEAR_EP_HIDE_STATUS_PHASE 6
  390. #define CLEAR_EP_FORCE_CRC_ERROR 5
  391. #define CLEAR_INTERRUPT_MODE 4
  392. #define CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE 3
  393. #define CLEAR_NAK_OUT_PACKETS_MODE 2
  394. #define CLEAR_ENDPOINT_TOGGLE 1
  395. #define CLEAR_ENDPOINT_HALT 0
  396. u32 ep_irqenb;
  397. #define SHORT_PACKET_OUT_DONE_INTERRUPT_ENABLE 6
  398. #define SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE 5
  399. #define DATA_PACKET_RECEIVED_INTERRUPT_ENABLE 3
  400. #define DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE 2
  401. #define DATA_OUT_PING_TOKEN_INTERRUPT_ENABLE 1
  402. #define DATA_IN_TOKEN_INTERRUPT_ENABLE 0
  403. u32 ep_stat;
  404. #define FIFO_VALID_COUNT 24
  405. #define HIGH_BANDWIDTH_OUT_TRANSACTION_PID 22
  406. #define TIMEOUT 21
  407. #define USB_STALL_SENT 20
  408. #define USB_IN_NAK_SENT 19
  409. #define USB_IN_ACK_RCVD 18
  410. #define USB_OUT_PING_NAK_SENT 17
  411. #define USB_OUT_ACK_SENT 16
  412. #define FIFO_OVERFLOW 13
  413. #define FIFO_UNDERFLOW 12
  414. #define FIFO_FULL 11
  415. #define FIFO_EMPTY 10
  416. #define FIFO_FLUSH 9
  417. #define SHORT_PACKET_OUT_DONE_INTERRUPT 6
  418. #define SHORT_PACKET_TRANSFERRED_INTERRUPT 5
  419. #define NAK_OUT_PACKETS 4
  420. #define DATA_PACKET_RECEIVED_INTERRUPT 3
  421. #define DATA_PACKET_TRANSMITTED_INTERRUPT 2
  422. #define DATA_OUT_PING_TOKEN_INTERRUPT 1
  423. #define DATA_IN_TOKEN_INTERRUPT 0
  424. // offset 0x0310, 0x0330, 0x0350, 0x0370, 0x0390, 0x03b0, 0x03d0
  425. u32 ep_avail;
  426. u32 ep_data;
  427. u32 _unused0 [2];
  428. } __attribute__ ((packed));
  429. /*-------------------------------------------------------------------------*/
  430. #ifdef __KERNEL__
  431. /* indexed registers [11.10] are accessed indirectly
  432. * caller must own the device lock.
  433. */
  434. static inline u32
  435. get_idx_reg (struct net2280_regs __iomem *regs, u32 index)
  436. {
  437. writel (index, &regs->idxaddr);
  438. /* NOTE: synchs device/cpu memory views */
  439. return readl (&regs->idxdata);
  440. }
  441. static inline void
  442. set_idx_reg (struct net2280_regs __iomem *regs, u32 index, u32 value)
  443. {
  444. writel (index, &regs->idxaddr);
  445. writel (value, &regs->idxdata);
  446. /* posted, may not be visible yet */
  447. }
  448. #endif /* __KERNEL__ */
  449. #define REG_DIAG 0x0
  450. #define RETRY_COUNTER 16
  451. #define FORCE_PCI_SERR 11
  452. #define FORCE_PCI_INTERRUPT 10
  453. #define FORCE_USB_INTERRUPT 9
  454. #define FORCE_CPU_INTERRUPT 8
  455. #define ILLEGAL_BYTE_ENABLES 5
  456. #define FAST_TIMES 4
  457. #define FORCE_RECEIVE_ERROR 2
  458. #define FORCE_TRANSMIT_CRC_ERROR 0
  459. #define REG_FRAME 0x02 /* from last sof */
  460. #define REG_CHIPREV 0x03 /* in bcd */
  461. #define REG_HS_NAK_RATE 0x0a /* NAK per N uframes */
  462. #define CHIPREV_1 0x0100
  463. #define CHIPREV_1A 0x0110
  464. #ifdef __KERNEL__
  465. /* ep a-f highspeed and fullspeed maxpacket, addresses
  466. * computed from ep->num
  467. */
  468. #define REG_EP_MAXPKT(dev,num) (((num) + 1) * 0x10 + \
  469. (((dev)->gadget.speed == USB_SPEED_HIGH) ? 0 : 1))
  470. /*-------------------------------------------------------------------------*/
  471. /* [8.3] for scatter/gather i/o
  472. * use struct net2280_dma_regs bitfields
  473. */
  474. struct net2280_dma {
  475. __le32 dmacount;
  476. __le32 dmaaddr; /* the buffer */
  477. __le32 dmadesc; /* next dma descriptor */
  478. __le32 _reserved;
  479. } __attribute__ ((aligned (16)));
  480. /*-------------------------------------------------------------------------*/
  481. /* DRIVER DATA STRUCTURES and UTILITIES */
  482. struct net2280_ep {
  483. struct usb_ep ep;
  484. struct net2280_ep_regs __iomem *regs;
  485. struct net2280_dma_regs __iomem *dma;
  486. struct net2280_dma *dummy;
  487. dma_addr_t td_dma; /* of dummy */
  488. struct net2280 *dev;
  489. unsigned long irqs;
  490. /* analogous to a host-side qh */
  491. struct list_head queue;
  492. const struct usb_endpoint_descriptor *desc;
  493. unsigned num : 8,
  494. fifo_size : 12,
  495. in_fifo_validate : 1,
  496. out_overflow : 1,
  497. stopped : 1,
  498. is_in : 1,
  499. is_iso : 1;
  500. };
  501. static inline void allow_status (struct net2280_ep *ep)
  502. {
  503. /* ep0 only */
  504. writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
  505. | (1 << CLEAR_NAK_OUT_PACKETS)
  506. | (1 << CLEAR_NAK_OUT_PACKETS_MODE)
  507. , &ep->regs->ep_rsp);
  508. ep->stopped = 1;
  509. }
  510. /* count (<= 4) bytes in the next fifo write will be valid */
  511. static inline void set_fifo_bytecount (struct net2280_ep *ep, unsigned count)
  512. {
  513. writeb (count, 2 + (u8 __iomem *) &ep->regs->ep_cfg);
  514. }
  515. struct net2280_request {
  516. struct usb_request req;
  517. struct net2280_dma *td;
  518. dma_addr_t td_dma;
  519. struct list_head queue;
  520. unsigned mapped : 1,
  521. valid : 1;
  522. };
  523. struct net2280 {
  524. /* each pci device provides one gadget, several endpoints */
  525. struct usb_gadget gadget;
  526. spinlock_t lock;
  527. struct net2280_ep ep [7];
  528. struct usb_gadget_driver *driver;
  529. unsigned enabled : 1,
  530. protocol_stall : 1,
  531. softconnect : 1,
  532. got_irq : 1,
  533. region : 1;
  534. u16 chiprev;
  535. /* pci state used to access those endpoints */
  536. struct pci_dev *pdev;
  537. struct net2280_regs __iomem *regs;
  538. struct net2280_usb_regs __iomem *usb;
  539. struct net2280_pci_regs __iomem *pci;
  540. struct net2280_dma_regs __iomem *dma;
  541. struct net2280_dep_regs __iomem *dep;
  542. struct net2280_ep_regs __iomem *epregs;
  543. struct pci_pool *requests;
  544. // statistics...
  545. };
  546. static inline void set_halt (struct net2280_ep *ep)
  547. {
  548. /* ep0 and bulk/intr endpoints */
  549. writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
  550. /* set NAK_OUT for erratum 0114 */
  551. | ((ep->dev->chiprev == CHIPREV_1) << SET_NAK_OUT_PACKETS)
  552. | (1 << SET_ENDPOINT_HALT)
  553. , &ep->regs->ep_rsp);
  554. }
  555. static inline void clear_halt (struct net2280_ep *ep)
  556. {
  557. /* ep0 and bulk/intr endpoints */
  558. writel ( (1 << CLEAR_ENDPOINT_HALT)
  559. | (1 << CLEAR_ENDPOINT_TOGGLE)
  560. /* unless the gadget driver left a short packet in the
  561. * fifo, this reverses the erratum 0114 workaround.
  562. */
  563. | ((ep->dev->chiprev == CHIPREV_1) << CLEAR_NAK_OUT_PACKETS)
  564. , &ep->regs->ep_rsp);
  565. }
  566. #ifdef USE_RDK_LEDS
  567. static inline void net2280_led_init (struct net2280 *dev)
  568. {
  569. /* LED3 (green) is on during USB activity. note erratum 0113. */
  570. writel ((1 << GPIO3_LED_SELECT)
  571. | (1 << GPIO3_OUTPUT_ENABLE)
  572. | (1 << GPIO2_OUTPUT_ENABLE)
  573. | (1 << GPIO1_OUTPUT_ENABLE)
  574. | (1 << GPIO0_OUTPUT_ENABLE)
  575. , &dev->regs->gpioctl);
  576. }
  577. /* indicate speed with bi-color LED 0/1 */
  578. static inline
  579. void net2280_led_speed (struct net2280 *dev, enum usb_device_speed speed)
  580. {
  581. u32 val = readl (&dev->regs->gpioctl);
  582. switch (speed) {
  583. case USB_SPEED_HIGH: /* green */
  584. val &= ~(1 << GPIO0_DATA);
  585. val |= (1 << GPIO1_DATA);
  586. break;
  587. case USB_SPEED_FULL: /* red */
  588. val &= ~(1 << GPIO1_DATA);
  589. val |= (1 << GPIO0_DATA);
  590. break;
  591. default: /* (off/black) */
  592. val &= ~((1 << GPIO1_DATA) | (1 << GPIO0_DATA));
  593. break;
  594. }
  595. writel (val, &dev->regs->gpioctl);
  596. }
  597. /* indicate power with LED 2 */
  598. static inline void net2280_led_active (struct net2280 *dev, int is_active)
  599. {
  600. u32 val = readl (&dev->regs->gpioctl);
  601. // FIXME this LED never seems to turn on.
  602. if (is_active)
  603. val |= GPIO2_DATA;
  604. else
  605. val &= ~GPIO2_DATA;
  606. writel (val, &dev->regs->gpioctl);
  607. }
  608. static inline void net2280_led_shutdown (struct net2280 *dev)
  609. {
  610. /* turn off all four GPIO*_DATA bits */
  611. writel (readl (&dev->regs->gpioctl) & ~0x0f,
  612. &dev->regs->gpioctl);
  613. }
  614. #else
  615. #define net2280_led_init(dev) do { } while (0)
  616. #define net2280_led_speed(dev, speed) do { } while (0)
  617. #define net2280_led_shutdown(dev) do { } while (0)
  618. #endif
  619. /*-------------------------------------------------------------------------*/
  620. #define xprintk(dev,level,fmt,args...) \
  621. printk(level "%s %s: " fmt , driver_name , \
  622. pci_name(dev->pdev) , ## args)
  623. #ifdef DEBUG
  624. #undef DEBUG
  625. #define DEBUG(dev,fmt,args...) \
  626. xprintk(dev , KERN_DEBUG , fmt , ## args)
  627. #else
  628. #define DEBUG(dev,fmt,args...) \
  629. do { } while (0)
  630. #endif /* DEBUG */
  631. #ifdef VERBOSE
  632. #define VDEBUG DEBUG
  633. #else
  634. #define VDEBUG(dev,fmt,args...) \
  635. do { } while (0)
  636. #endif /* VERBOSE */
  637. #define ERROR(dev,fmt,args...) \
  638. xprintk(dev , KERN_ERR , fmt , ## args)
  639. #define WARN(dev,fmt,args...) \
  640. xprintk(dev , KERN_WARNING , fmt , ## args)
  641. #define INFO(dev,fmt,args...) \
  642. xprintk(dev , KERN_INFO , fmt , ## args)
  643. /*-------------------------------------------------------------------------*/
  644. static inline void start_out_naking (struct net2280_ep *ep)
  645. {
  646. /* NOTE: hardware races lurk here, and PING protocol issues */
  647. writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
  648. /* synch with device */
  649. readl (&ep->regs->ep_rsp);
  650. }
  651. #ifdef DEBUG
  652. static inline void assert_out_naking (struct net2280_ep *ep, const char *where)
  653. {
  654. u32 tmp = readl (&ep->regs->ep_stat);
  655. if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) {
  656. DEBUG (ep->dev, "%s %s %08x !NAK\n",
  657. ep->ep.name, where, tmp);
  658. writel ((1 << SET_NAK_OUT_PACKETS),
  659. &ep->regs->ep_rsp);
  660. }
  661. }
  662. #define ASSERT_OUT_NAKING(ep) assert_out_naking(ep,__FUNCTION__)
  663. #else
  664. #define ASSERT_OUT_NAKING(ep) do {} while (0)
  665. #endif
  666. static inline void stop_out_naking (struct net2280_ep *ep)
  667. {
  668. u32 tmp;
  669. tmp = readl (&ep->regs->ep_stat);
  670. if ((tmp & (1 << NAK_OUT_PACKETS)) != 0)
  671. writel ((1 << CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
  672. }
  673. #endif /* __KERNEL__ */