net2280.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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 GPIO_INTERRUPT 13
  177. #define DMA_D_INTERRUPT 12
  178. #define DMA_C_INTERRUPT 11
  179. #define DMA_B_INTERRUPT 10
  180. #define DMA_A_INTERRUPT 9
  181. #define EEPROM_DONE_INTERRUPT 8
  182. #define VBUS_INTERRUPT 7
  183. #define CONTROL_STATUS_INTERRUPT 6
  184. #define ROOT_PORT_RESET_INTERRUPT 4
  185. #define SUSPEND_REQUEST_INTERRUPT 3
  186. #define SUSPEND_REQUEST_CHANGE_INTERRUPT 2
  187. #define RESUME_INTERRUPT 1
  188. #define SOF_INTERRUPT 0
  189. // offset 0x0030
  190. u32 idxaddr;
  191. u32 idxdata;
  192. u32 fifoctl;
  193. #define PCI_BASE2_RANGE 16
  194. #define IGNORE_FIFO_AVAILABILITY 3
  195. #define PCI_BASE2_SELECT 2
  196. #define FIFO_CONFIGURATION_SELECT 0
  197. u32 _unused2;
  198. // offset 0x0040
  199. u32 memaddr;
  200. #define START 28
  201. #define DIRECTION 27
  202. #define FIFO_DIAGNOSTIC_SELECT 24
  203. #define MEMORY_ADDRESS 0
  204. u32 memdata0;
  205. u32 memdata1;
  206. u32 _unused3;
  207. // offset 0x0050
  208. u32 gpioctl;
  209. #define GPIO3_LED_SELECT 12
  210. #define GPIO3_INTERRUPT_ENABLE 11
  211. #define GPIO2_INTERRUPT_ENABLE 10
  212. #define GPIO1_INTERRUPT_ENABLE 9
  213. #define GPIO0_INTERRUPT_ENABLE 8
  214. #define GPIO3_OUTPUT_ENABLE 7
  215. #define GPIO2_OUTPUT_ENABLE 6
  216. #define GPIO1_OUTPUT_ENABLE 5
  217. #define GPIO0_OUTPUT_ENABLE 4
  218. #define GPIO3_DATA 3
  219. #define GPIO2_DATA 2
  220. #define GPIO1_DATA 1
  221. #define GPIO0_DATA 0
  222. u32 gpiostat;
  223. #define GPIO3_INTERRUPT 3
  224. #define GPIO2_INTERRUPT 2
  225. #define GPIO1_INTERRUPT 1
  226. #define GPIO0_INTERRUPT 0
  227. } __attribute__ ((packed));
  228. /* usb control, BAR0 + 0x0080 */
  229. struct net2280_usb_regs {
  230. // offset 0x0080
  231. u32 stdrsp;
  232. #define STALL_UNSUPPORTED_REQUESTS 31
  233. #define SET_TEST_MODE 16
  234. #define GET_OTHER_SPEED_CONFIGURATION 15
  235. #define GET_DEVICE_QUALIFIER 14
  236. #define SET_ADDRESS 13
  237. #define ENDPOINT_SET_CLEAR_HALT 12
  238. #define DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP 11
  239. #define GET_STRING_DESCRIPTOR_2 10
  240. #define GET_STRING_DESCRIPTOR_1 9
  241. #define GET_STRING_DESCRIPTOR_0 8
  242. #define GET_SET_INTERFACE 6
  243. #define GET_SET_CONFIGURATION 5
  244. #define GET_CONFIGURATION_DESCRIPTOR 4
  245. #define GET_DEVICE_DESCRIPTOR 3
  246. #define GET_ENDPOINT_STATUS 2
  247. #define GET_INTERFACE_STATUS 1
  248. #define GET_DEVICE_STATUS 0
  249. u32 prodvendid;
  250. #define PRODUCT_ID 16
  251. #define VENDOR_ID 0
  252. u32 relnum;
  253. u32 usbctl;
  254. #define SERIAL_NUMBER_INDEX 16
  255. #define PRODUCT_ID_STRING_ENABLE 13
  256. #define VENDOR_ID_STRING_ENABLE 12
  257. #define USB_ROOT_PORT_WAKEUP_ENABLE 11
  258. #define VBUS_PIN 10
  259. #define TIMED_DISCONNECT 9
  260. #define SUSPEND_IMMEDIATELY 7
  261. #define SELF_POWERED_USB_DEVICE 6
  262. #define REMOTE_WAKEUP_SUPPORT 5
  263. #define PME_POLARITY 4
  264. #define USB_DETECT_ENABLE 3
  265. #define PME_WAKEUP_ENABLE 2
  266. #define DEVICE_REMOTE_WAKEUP_ENABLE 1
  267. #define SELF_POWERED_STATUS 0
  268. // offset 0x0090
  269. u32 usbstat;
  270. #define HIGH_SPEED 7
  271. #define FULL_SPEED 6
  272. #define GENERATE_RESUME 5
  273. #define GENERATE_DEVICE_REMOTE_WAKEUP 4
  274. u32 xcvrdiag;
  275. #define FORCE_HIGH_SPEED_MODE 31
  276. #define FORCE_FULL_SPEED_MODE 30
  277. #define USB_TEST_MODE 24
  278. #define LINE_STATE 16
  279. #define TRANSCEIVER_OPERATION_MODE 2
  280. #define TRANSCEIVER_SELECT 1
  281. #define TERMINATION_SELECT 0
  282. u32 setup0123;
  283. u32 setup4567;
  284. // offset 0x0090
  285. u32 _unused0;
  286. u32 ouraddr;
  287. #define FORCE_IMMEDIATE 7
  288. #define OUR_USB_ADDRESS 0
  289. u32 ourconfig;
  290. } __attribute__ ((packed));
  291. /* pci control, BAR0 + 0x0100 */
  292. struct net2280_pci_regs {
  293. // offset 0x0100
  294. u32 pcimstctl;
  295. #define PCI_ARBITER_PARK_SELECT 13
  296. #define PCI_MULTI LEVEL_ARBITER 12
  297. #define PCI_RETRY_ABORT_ENABLE 11
  298. #define DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE 10
  299. #define DMA_READ_MULTIPLE_ENABLE 9
  300. #define DMA_READ_LINE_ENABLE 8
  301. #define PCI_MASTER_COMMAND_SELECT 6
  302. #define MEM_READ_OR_WRITE 0
  303. #define IO_READ_OR_WRITE 1
  304. #define CFG_READ_OR_WRITE 2
  305. #define PCI_MASTER_START 5
  306. #define PCI_MASTER_READ_WRITE 4
  307. #define PCI_MASTER_WRITE 0
  308. #define PCI_MASTER_READ 1
  309. #define PCI_MASTER_BYTE_WRITE_ENABLES 0
  310. u32 pcimstaddr;
  311. u32 pcimstdata;
  312. u32 pcimststat;
  313. #define PCI_ARBITER_CLEAR 2
  314. #define PCI_EXTERNAL_ARBITER 1
  315. #define PCI_HOST_MODE 0
  316. } __attribute__ ((packed));
  317. /* dma control, BAR0 + 0x0180 ... array of four structs like this,
  318. * for channels 0..3. see also struct net2280_dma: descriptor
  319. * that can be loaded into some of these registers.
  320. */
  321. struct net2280_dma_regs { /* [11.7] */
  322. // offset 0x0180, 0x01a0, 0x01c0, 0x01e0,
  323. u32 dmactl;
  324. #define DMA_SCATTER_GATHER_DONE_INTERRUPT_ENABLE 25
  325. #define DMA_CLEAR_COUNT_ENABLE 21
  326. #define DESCRIPTOR_POLLING_RATE 19
  327. #define POLL_CONTINUOUS 0
  328. #define POLL_1_USEC 1
  329. #define POLL_100_USEC 2
  330. #define POLL_1_MSEC 3
  331. #define DMA_VALID_BIT_POLLING_ENABLE 18
  332. #define DMA_VALID_BIT_ENABLE 17
  333. #define DMA_SCATTER_GATHER_ENABLE 16
  334. #define DMA_OUT_AUTO_START_ENABLE 4
  335. #define DMA_PREEMPT_ENABLE 3
  336. #define DMA_FIFO_VALIDATE 2
  337. #define DMA_ENABLE 1
  338. #define DMA_ADDRESS_HOLD 0
  339. u32 dmastat;
  340. #define DMA_SCATTER_GATHER_DONE_INTERRUPT 25
  341. #define DMA_TRANSACTION_DONE_INTERRUPT 24
  342. #define DMA_ABORT 1
  343. #define DMA_START 0
  344. u32 _unused0 [2];
  345. // offset 0x0190, 0x01b0, 0x01d0, 0x01f0,
  346. u32 dmacount;
  347. #define VALID_BIT 31
  348. #define DMA_DIRECTION 30
  349. #define DMA_DONE_INTERRUPT_ENABLE 29
  350. #define END_OF_CHAIN 28
  351. #define DMA_BYTE_COUNT_MASK ((1<<24)-1)
  352. #define DMA_BYTE_COUNT 0
  353. u32 dmaaddr;
  354. u32 dmadesc;
  355. u32 _unused1;
  356. } __attribute__ ((packed));
  357. /* dedicated endpoint registers, BAR0 + 0x0200 */
  358. struct net2280_dep_regs { /* [11.8] */
  359. // offset 0x0200, 0x0210, 0x220, 0x230, 0x240
  360. u32 dep_cfg;
  361. // offset 0x0204, 0x0214, 0x224, 0x234, 0x244
  362. u32 dep_rsp;
  363. u32 _unused [2];
  364. } __attribute__ ((packed));
  365. /* configurable endpoint registers, BAR0 + 0x0300 ... array of seven structs
  366. * like this, for ep0 then the configurable endpoints A..F
  367. * ep0 reserved for control; E and F have only 64 bytes of fifo
  368. */
  369. struct net2280_ep_regs { /* [11.9] */
  370. // offset 0x0300, 0x0320, 0x0340, 0x0360, 0x0380, 0x03a0, 0x03c0
  371. u32 ep_cfg;
  372. #define ENDPOINT_BYTE_COUNT 16
  373. #define ENDPOINT_ENABLE 10
  374. #define ENDPOINT_TYPE 8
  375. #define ENDPOINT_DIRECTION 7
  376. #define ENDPOINT_NUMBER 0
  377. u32 ep_rsp;
  378. #define SET_NAK_OUT_PACKETS 15
  379. #define SET_EP_HIDE_STATUS_PHASE 14
  380. #define SET_EP_FORCE_CRC_ERROR 13
  381. #define SET_INTERRUPT_MODE 12
  382. #define SET_CONTROL_STATUS_PHASE_HANDSHAKE 11
  383. #define SET_NAK_OUT_PACKETS_MODE 10
  384. #define SET_ENDPOINT_TOGGLE 9
  385. #define SET_ENDPOINT_HALT 8
  386. #define CLEAR_NAK_OUT_PACKETS 7
  387. #define CLEAR_EP_HIDE_STATUS_PHASE 6
  388. #define CLEAR_EP_FORCE_CRC_ERROR 5
  389. #define CLEAR_INTERRUPT_MODE 4
  390. #define CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE 3
  391. #define CLEAR_NAK_OUT_PACKETS_MODE 2
  392. #define CLEAR_ENDPOINT_TOGGLE 1
  393. #define CLEAR_ENDPOINT_HALT 0
  394. u32 ep_irqenb;
  395. #define SHORT_PACKET_OUT_DONE_INTERRUPT_ENABLE 6
  396. #define SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE 5
  397. #define DATA_PACKET_RECEIVED_INTERRUPT_ENABLE 3
  398. #define DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE 2
  399. #define DATA_OUT_PING_TOKEN_INTERRUPT_ENABLE 1
  400. #define DATA_IN_TOKEN_INTERRUPT_ENABLE 0
  401. u32 ep_stat;
  402. #define FIFO_VALID_COUNT 24
  403. #define HIGH_BANDWIDTH_OUT_TRANSACTION_PID 22
  404. #define TIMEOUT 21
  405. #define USB_STALL_SENT 20
  406. #define USB_IN_NAK_SENT 19
  407. #define USB_IN_ACK_RCVD 18
  408. #define USB_OUT_PING_NAK_SENT 17
  409. #define USB_OUT_ACK_SENT 16
  410. #define FIFO_OVERFLOW 13
  411. #define FIFO_UNDERFLOW 12
  412. #define FIFO_FULL 11
  413. #define FIFO_EMPTY 10
  414. #define FIFO_FLUSH 9
  415. #define SHORT_PACKET_OUT_DONE_INTERRUPT 6
  416. #define SHORT_PACKET_TRANSFERRED_INTERRUPT 5
  417. #define NAK_OUT_PACKETS 4
  418. #define DATA_PACKET_RECEIVED_INTERRUPT 3
  419. #define DATA_PACKET_TRANSMITTED_INTERRUPT 2
  420. #define DATA_OUT_PING_TOKEN_INTERRUPT 1
  421. #define DATA_IN_TOKEN_INTERRUPT 0
  422. // offset 0x0310, 0x0330, 0x0350, 0x0370, 0x0390, 0x03b0, 0x03d0
  423. u32 ep_avail;
  424. u32 ep_data;
  425. u32 _unused0 [2];
  426. } __attribute__ ((packed));
  427. /*-------------------------------------------------------------------------*/
  428. #ifdef __KERNEL__
  429. /* indexed registers [11.10] are accessed indirectly
  430. * caller must own the device lock.
  431. */
  432. static inline u32
  433. get_idx_reg (struct net2280_regs __iomem *regs, u32 index)
  434. {
  435. writel (index, &regs->idxaddr);
  436. /* NOTE: synchs device/cpu memory views */
  437. return readl (&regs->idxdata);
  438. }
  439. static inline void
  440. set_idx_reg (struct net2280_regs __iomem *regs, u32 index, u32 value)
  441. {
  442. writel (index, &regs->idxaddr);
  443. writel (value, &regs->idxdata);
  444. /* posted, may not be visible yet */
  445. }
  446. #endif /* __KERNEL__ */
  447. #define REG_DIAG 0x0
  448. #define RETRY_COUNTER 16
  449. #define FORCE_PCI_SERR 11
  450. #define FORCE_PCI_INTERRUPT 10
  451. #define FORCE_USB_INTERRUPT 9
  452. #define FORCE_CPU_INTERRUPT 8
  453. #define ILLEGAL_BYTE_ENABLES 5
  454. #define FAST_TIMES 4
  455. #define FORCE_RECEIVE_ERROR 2
  456. #define FORCE_TRANSMIT_CRC_ERROR 0
  457. #define REG_FRAME 0x02 /* from last sof */
  458. #define REG_CHIPREV 0x03 /* in bcd */
  459. #define REG_HS_NAK_RATE 0x0a /* NAK per N uframes */
  460. #define CHIPREV_1 0x0100
  461. #define CHIPREV_1A 0x0110
  462. #ifdef __KERNEL__
  463. /* ep a-f highspeed and fullspeed maxpacket, addresses
  464. * computed from ep->num
  465. */
  466. #define REG_EP_MAXPKT(dev,num) (((num) + 1) * 0x10 + \
  467. (((dev)->gadget.speed == USB_SPEED_HIGH) ? 0 : 1))
  468. /*-------------------------------------------------------------------------*/
  469. /* [8.3] for scatter/gather i/o
  470. * use struct net2280_dma_regs bitfields
  471. */
  472. struct net2280_dma {
  473. __le32 dmacount;
  474. __le32 dmaaddr; /* the buffer */
  475. __le32 dmadesc; /* next dma descriptor */
  476. __le32 _reserved;
  477. } __attribute__ ((aligned (16)));
  478. /*-------------------------------------------------------------------------*/
  479. /* DRIVER DATA STRUCTURES and UTILITIES */
  480. struct net2280_ep {
  481. struct usb_ep ep;
  482. struct net2280_ep_regs __iomem *regs;
  483. struct net2280_dma_regs __iomem *dma;
  484. struct net2280_dma *dummy;
  485. dma_addr_t td_dma; /* of dummy */
  486. struct net2280 *dev;
  487. unsigned long irqs;
  488. /* analogous to a host-side qh */
  489. struct list_head queue;
  490. const struct usb_endpoint_descriptor *desc;
  491. unsigned num : 8,
  492. fifo_size : 12,
  493. in_fifo_validate : 1,
  494. out_overflow : 1,
  495. stopped : 1,
  496. is_in : 1,
  497. is_iso : 1;
  498. };
  499. static inline void allow_status (struct net2280_ep *ep)
  500. {
  501. /* ep0 only */
  502. writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
  503. | (1 << CLEAR_NAK_OUT_PACKETS)
  504. | (1 << CLEAR_NAK_OUT_PACKETS_MODE)
  505. , &ep->regs->ep_rsp);
  506. ep->stopped = 1;
  507. }
  508. /* count (<= 4) bytes in the next fifo write will be valid */
  509. static inline void set_fifo_bytecount (struct net2280_ep *ep, unsigned count)
  510. {
  511. writeb (count, 2 + (u8 __iomem *) &ep->regs->ep_cfg);
  512. }
  513. struct net2280_request {
  514. struct usb_request req;
  515. struct net2280_dma *td;
  516. dma_addr_t td_dma;
  517. struct list_head queue;
  518. unsigned mapped : 1,
  519. valid : 1;
  520. };
  521. struct net2280 {
  522. /* each pci device provides one gadget, several endpoints */
  523. struct usb_gadget gadget;
  524. spinlock_t lock;
  525. struct net2280_ep ep [7];
  526. struct usb_gadget_driver *driver;
  527. unsigned enabled : 1,
  528. protocol_stall : 1,
  529. softconnect : 1,
  530. got_irq : 1,
  531. region : 1;
  532. u16 chiprev;
  533. /* pci state used to access those endpoints */
  534. struct pci_dev *pdev;
  535. struct net2280_regs __iomem *regs;
  536. struct net2280_usb_regs __iomem *usb;
  537. struct net2280_pci_regs __iomem *pci;
  538. struct net2280_dma_regs __iomem *dma;
  539. struct net2280_dep_regs __iomem *dep;
  540. struct net2280_ep_regs __iomem *epregs;
  541. struct pci_pool *requests;
  542. // statistics...
  543. };
  544. static inline void set_halt (struct net2280_ep *ep)
  545. {
  546. /* ep0 and bulk/intr endpoints */
  547. writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
  548. /* set NAK_OUT for erratum 0114 */
  549. | ((ep->dev->chiprev == CHIPREV_1) << SET_NAK_OUT_PACKETS)
  550. | (1 << SET_ENDPOINT_HALT)
  551. , &ep->regs->ep_rsp);
  552. }
  553. static inline void clear_halt (struct net2280_ep *ep)
  554. {
  555. /* ep0 and bulk/intr endpoints */
  556. writel ( (1 << CLEAR_ENDPOINT_HALT)
  557. | (1 << CLEAR_ENDPOINT_TOGGLE)
  558. /* unless the gadget driver left a short packet in the
  559. * fifo, this reverses the erratum 0114 workaround.
  560. */
  561. | ((ep->dev->chiprev == CHIPREV_1) << CLEAR_NAK_OUT_PACKETS)
  562. , &ep->regs->ep_rsp);
  563. }
  564. #ifdef USE_RDK_LEDS
  565. static inline void net2280_led_init (struct net2280 *dev)
  566. {
  567. /* LED3 (green) is on during USB activity. note erratum 0113. */
  568. writel ((1 << GPIO3_LED_SELECT)
  569. | (1 << GPIO3_OUTPUT_ENABLE)
  570. | (1 << GPIO2_OUTPUT_ENABLE)
  571. | (1 << GPIO1_OUTPUT_ENABLE)
  572. | (1 << GPIO0_OUTPUT_ENABLE)
  573. , &dev->regs->gpioctl);
  574. }
  575. /* indicate speed with bi-color LED 0/1 */
  576. static inline
  577. void net2280_led_speed (struct net2280 *dev, enum usb_device_speed speed)
  578. {
  579. u32 val = readl (&dev->regs->gpioctl);
  580. switch (speed) {
  581. case USB_SPEED_HIGH: /* green */
  582. val &= ~(1 << GPIO0_DATA);
  583. val |= (1 << GPIO1_DATA);
  584. break;
  585. case USB_SPEED_FULL: /* red */
  586. val &= ~(1 << GPIO1_DATA);
  587. val |= (1 << GPIO0_DATA);
  588. break;
  589. default: /* (off/black) */
  590. val &= ~((1 << GPIO1_DATA) | (1 << GPIO0_DATA));
  591. break;
  592. }
  593. writel (val, &dev->regs->gpioctl);
  594. }
  595. /* indicate power with LED 2 */
  596. static inline void net2280_led_active (struct net2280 *dev, int is_active)
  597. {
  598. u32 val = readl (&dev->regs->gpioctl);
  599. // FIXME this LED never seems to turn on.
  600. if (is_active)
  601. val |= GPIO2_DATA;
  602. else
  603. val &= ~GPIO2_DATA;
  604. writel (val, &dev->regs->gpioctl);
  605. }
  606. static inline void net2280_led_shutdown (struct net2280 *dev)
  607. {
  608. /* turn off all four GPIO*_DATA bits */
  609. writel (readl (&dev->regs->gpioctl) & ~0x0f,
  610. &dev->regs->gpioctl);
  611. }
  612. #else
  613. #define net2280_led_init(dev) do { } while (0)
  614. #define net2280_led_speed(dev, speed) do { } while (0)
  615. #define net2280_led_shutdown(dev) do { } while (0)
  616. #endif
  617. /*-------------------------------------------------------------------------*/
  618. #define xprintk(dev,level,fmt,args...) \
  619. printk(level "%s %s: " fmt , driver_name , \
  620. pci_name(dev->pdev) , ## args)
  621. #ifdef DEBUG
  622. #undef DEBUG
  623. #define DEBUG(dev,fmt,args...) \
  624. xprintk(dev , KERN_DEBUG , fmt , ## args)
  625. #else
  626. #define DEBUG(dev,fmt,args...) \
  627. do { } while (0)
  628. #endif /* DEBUG */
  629. #ifdef VERBOSE
  630. #define VDEBUG DEBUG
  631. #else
  632. #define VDEBUG(dev,fmt,args...) \
  633. do { } while (0)
  634. #endif /* VERBOSE */
  635. #define ERROR(dev,fmt,args...) \
  636. xprintk(dev , KERN_ERR , fmt , ## args)
  637. #define WARN(dev,fmt,args...) \
  638. xprintk(dev , KERN_WARNING , fmt , ## args)
  639. #define INFO(dev,fmt,args...) \
  640. xprintk(dev , KERN_INFO , fmt , ## args)
  641. /*-------------------------------------------------------------------------*/
  642. static inline void start_out_naking (struct net2280_ep *ep)
  643. {
  644. /* NOTE: hardware races lurk here, and PING protocol issues */
  645. writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
  646. /* synch with device */
  647. readl (&ep->regs->ep_rsp);
  648. }
  649. #ifdef DEBUG
  650. static inline void assert_out_naking (struct net2280_ep *ep, const char *where)
  651. {
  652. u32 tmp = readl (&ep->regs->ep_stat);
  653. if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) {
  654. DEBUG (ep->dev, "%s %s %08x !NAK\n",
  655. ep->ep.name, where, tmp);
  656. writel ((1 << SET_NAK_OUT_PACKETS),
  657. &ep->regs->ep_rsp);
  658. }
  659. }
  660. #define ASSERT_OUT_NAKING(ep) assert_out_naking(ep,__FUNCTION__)
  661. #else
  662. #define ASSERT_OUT_NAKING(ep) do {} while (0)
  663. #endif
  664. static inline void stop_out_naking (struct net2280_ep *ep)
  665. {
  666. u32 tmp;
  667. tmp = readl (&ep->regs->ep_stat);
  668. if ((tmp & (1 << NAK_OUT_PACKETS)) != 0)
  669. writel ((1 << CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
  670. }
  671. #endif /* __KERNEL__ */