net2272.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * PLX NET2272 high/full speed USB device controller
  4. *
  5. * Copyright (C) 2005-2006 PLX Technology, Inc.
  6. * Copyright (C) 2006-2011 Analog Devices, Inc.
  7. */
  8. #ifndef __NET2272_H__
  9. #define __NET2272_H__
  10. /* Main Registers */
  11. #define REGADDRPTR 0x00
  12. #define REGDATA 0x01
  13. #define IRQSTAT0 0x02
  14. #define ENDPOINT_0_INTERRUPT 0
  15. #define ENDPOINT_A_INTERRUPT 1
  16. #define ENDPOINT_B_INTERRUPT 2
  17. #define ENDPOINT_C_INTERRUPT 3
  18. #define VIRTUALIZED_ENDPOINT_INTERRUPT 4
  19. #define SETUP_PACKET_INTERRUPT 5
  20. #define DMA_DONE_INTERRUPT 6
  21. #define SOF_INTERRUPT 7
  22. #define IRQSTAT1 0x03
  23. #define CONTROL_STATUS_INTERRUPT 1
  24. #define VBUS_INTERRUPT 2
  25. #define SUSPEND_REQUEST_INTERRUPT 3
  26. #define SUSPEND_REQUEST_CHANGE_INTERRUPT 4
  27. #define RESUME_INTERRUPT 5
  28. #define ROOT_PORT_RESET_INTERRUPT 6
  29. #define RESET_STATUS 7
  30. #define PAGESEL 0x04
  31. #define DMAREQ 0x1c
  32. #define DMA_ENDPOINT_SELECT 0
  33. #define DREQ_POLARITY 1
  34. #define DACK_POLARITY 2
  35. #define EOT_POLARITY 3
  36. #define DMA_CONTROL_DACK 4
  37. #define DMA_REQUEST_ENABLE 5
  38. #define DMA_REQUEST 6
  39. #define DMA_BUFFER_VALID 7
  40. #define SCRATCH 0x1d
  41. #define IRQENB0 0x20
  42. #define ENDPOINT_0_INTERRUPT_ENABLE 0
  43. #define ENDPOINT_A_INTERRUPT_ENABLE 1
  44. #define ENDPOINT_B_INTERRUPT_ENABLE 2
  45. #define ENDPOINT_C_INTERRUPT_ENABLE 3
  46. #define VIRTUALIZED_ENDPOINT_INTERRUPT_ENABLE 4
  47. #define SETUP_PACKET_INTERRUPT_ENABLE 5
  48. #define DMA_DONE_INTERRUPT_ENABLE 6
  49. #define SOF_INTERRUPT_ENABLE 7
  50. #define IRQENB1 0x21
  51. #define VBUS_INTERRUPT_ENABLE 2
  52. #define SUSPEND_REQUEST_INTERRUPT_ENABLE 3
  53. #define SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE 4
  54. #define RESUME_INTERRUPT_ENABLE 5
  55. #define ROOT_PORT_RESET_INTERRUPT_ENABLE 6
  56. #define LOCCTL 0x22
  57. #define DATA_WIDTH 0
  58. #define LOCAL_CLOCK_OUTPUT 1
  59. #define LOCAL_CLOCK_OUTPUT_OFF 0
  60. #define LOCAL_CLOCK_OUTPUT_3_75MHZ 1
  61. #define LOCAL_CLOCK_OUTPUT_7_5MHZ 2
  62. #define LOCAL_CLOCK_OUTPUT_15MHZ 3
  63. #define LOCAL_CLOCK_OUTPUT_30MHZ 4
  64. #define LOCAL_CLOCK_OUTPUT_60MHZ 5
  65. #define DMA_SPLIT_BUS_MODE 4
  66. #define BYTE_SWAP 5
  67. #define BUFFER_CONFIGURATION 6
  68. #define BUFFER_CONFIGURATION_EPA512_EPB512 0
  69. #define BUFFER_CONFIGURATION_EPA1024_EPB512 1
  70. #define BUFFER_CONFIGURATION_EPA1024_EPB1024 2
  71. #define BUFFER_CONFIGURATION_EPA1024DB 3
  72. #define CHIPREV_LEGACY 0x23
  73. #define NET2270_LEGACY_REV 0x40
  74. #define LOCCTL1 0x24
  75. #define DMA_MODE 0
  76. #define SLOW_DREQ 0
  77. #define FAST_DREQ 1
  78. #define BURST_MODE 2
  79. #define DMA_DACK_ENABLE 2
  80. #define CHIPREV_2272 0x25
  81. #define CHIPREV_NET2272_R1 0x10
  82. #define CHIPREV_NET2272_R1A 0x11
  83. /* USB Registers */
  84. #define USBCTL0 0x18
  85. #define IO_WAKEUP_ENABLE 1
  86. #define USB_DETECT_ENABLE 3
  87. #define USB_ROOT_PORT_WAKEUP_ENABLE 5
  88. #define USBCTL1 0x19
  89. #define VBUS_PIN 0
  90. #define USB_FULL_SPEED 1
  91. #define USB_HIGH_SPEED 2
  92. #define GENERATE_RESUME 3
  93. #define VIRTUAL_ENDPOINT_ENABLE 4
  94. #define FRAME0 0x1a
  95. #define FRAME1 0x1b
  96. #define OURADDR 0x30
  97. #define FORCE_IMMEDIATE 7
  98. #define USBDIAG 0x31
  99. #define FORCE_TRANSMIT_CRC_ERROR 0
  100. #define PREVENT_TRANSMIT_BIT_STUFF 1
  101. #define FORCE_RECEIVE_ERROR 2
  102. #define FAST_TIMES 4
  103. #define USBTEST 0x32
  104. #define TEST_MODE_SELECT 0
  105. #define NORMAL_OPERATION 0
  106. #define TEST_J 1
  107. #define TEST_K 2
  108. #define TEST_SE0_NAK 3
  109. #define TEST_PACKET 4
  110. #define TEST_FORCE_ENABLE 5
  111. #define XCVRDIAG 0x33
  112. #define FORCE_FULL_SPEED 2
  113. #define FORCE_HIGH_SPEED 3
  114. #define OPMODE 4
  115. #define NORMAL_OPERATION 0
  116. #define NON_DRIVING 1
  117. #define DISABLE_BITSTUFF_AND_NRZI_ENCODE 2
  118. #define LINESTATE 6
  119. #define SE0_STATE 0
  120. #define J_STATE 1
  121. #define K_STATE 2
  122. #define SE1_STATE 3
  123. #define VIRTOUT0 0x34
  124. #define VIRTOUT1 0x35
  125. #define VIRTIN0 0x36
  126. #define VIRTIN1 0x37
  127. #define SETUP0 0x40
  128. #define SETUP1 0x41
  129. #define SETUP2 0x42
  130. #define SETUP3 0x43
  131. #define SETUP4 0x44
  132. #define SETUP5 0x45
  133. #define SETUP6 0x46
  134. #define SETUP7 0x47
  135. /* Endpoint Registers (Paged via PAGESEL) */
  136. #define EP_DATA 0x05
  137. #define EP_STAT0 0x06
  138. #define DATA_IN_TOKEN_INTERRUPT 0
  139. #define DATA_OUT_TOKEN_INTERRUPT 1
  140. #define DATA_PACKET_TRANSMITTED_INTERRUPT 2
  141. #define DATA_PACKET_RECEIVED_INTERRUPT 3
  142. #define SHORT_PACKET_TRANSFERRED_INTERRUPT 4
  143. #define NAK_OUT_PACKETS 5
  144. #define BUFFER_EMPTY 6
  145. #define BUFFER_FULL 7
  146. #define EP_STAT1 0x07
  147. #define TIMEOUT 0
  148. #define USB_OUT_ACK_SENT 1
  149. #define USB_OUT_NAK_SENT 2
  150. #define USB_IN_ACK_RCVD 3
  151. #define USB_IN_NAK_SENT 4
  152. #define USB_STALL_SENT 5
  153. #define LOCAL_OUT_ZLP 6
  154. #define BUFFER_FLUSH 7
  155. #define EP_TRANSFER0 0x08
  156. #define EP_TRANSFER1 0x09
  157. #define EP_TRANSFER2 0x0a
  158. #define EP_IRQENB 0x0b
  159. #define DATA_IN_TOKEN_INTERRUPT_ENABLE 0
  160. #define DATA_OUT_TOKEN_INTERRUPT_ENABLE 1
  161. #define DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE 2
  162. #define DATA_PACKET_RECEIVED_INTERRUPT_ENABLE 3
  163. #define SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE 4
  164. #define EP_AVAIL0 0x0c
  165. #define EP_AVAIL1 0x0d
  166. #define EP_RSPCLR 0x0e
  167. #define EP_RSPSET 0x0f
  168. #define ENDPOINT_HALT 0
  169. #define ENDPOINT_TOGGLE 1
  170. #define NAK_OUT_PACKETS_MODE 2
  171. #define CONTROL_STATUS_PHASE_HANDSHAKE 3
  172. #define INTERRUPT_MODE 4
  173. #define AUTOVALIDATE 5
  174. #define HIDE_STATUS_PHASE 6
  175. #define ALT_NAK_OUT_PACKETS 7
  176. #define EP_MAXPKT0 0x28
  177. #define EP_MAXPKT1 0x29
  178. #define ADDITIONAL_TRANSACTION_OPPORTUNITIES 3
  179. #define NONE_ADDITIONAL_TRANSACTION 0
  180. #define ONE_ADDITIONAL_TRANSACTION 1
  181. #define TWO_ADDITIONAL_TRANSACTION 2
  182. #define EP_CFG 0x2a
  183. #define ENDPOINT_NUMBER 0
  184. #define ENDPOINT_DIRECTION 4
  185. #define ENDPOINT_TYPE 5
  186. #define ENDPOINT_ENABLE 7
  187. #define EP_HBW 0x2b
  188. #define HIGH_BANDWIDTH_OUT_TRANSACTION_PID 0
  189. #define DATA0_PID 0
  190. #define DATA1_PID 1
  191. #define DATA2_PID 2
  192. #define MDATA_PID 3
  193. #define EP_BUFF_STATES 0x2c
  194. #define BUFFER_A_STATE 0
  195. #define BUFFER_B_STATE 2
  196. #define BUFF_FREE 0
  197. #define BUFF_VALID 1
  198. #define BUFF_LCL 2
  199. #define BUFF_USB 3
  200. /*---------------------------------------------------------------------------*/
  201. #define PCI_DEVICE_ID_RDK1 0x9054
  202. /* PCI-RDK EPLD Registers */
  203. #define RDK_EPLD_IO_REGISTER1 0x00000000
  204. #define RDK_EPLD_USB_RESET 0
  205. #define RDK_EPLD_USB_POWERDOWN 1
  206. #define RDK_EPLD_USB_WAKEUP 2
  207. #define RDK_EPLD_USB_EOT 3
  208. #define RDK_EPLD_DPPULL 4
  209. #define RDK_EPLD_IO_REGISTER2 0x00000004
  210. #define RDK_EPLD_BUSWIDTH 0
  211. #define RDK_EPLD_USER 2
  212. #define RDK_EPLD_RESET_INTERRUPT_ENABLE 3
  213. #define RDK_EPLD_DMA_TIMEOUT_ENABLE 4
  214. #define RDK_EPLD_STATUS_REGISTER 0x00000008
  215. #define RDK_EPLD_USB_LRESET 0
  216. #define RDK_EPLD_REVISION_REGISTER 0x0000000c
  217. /* PCI-RDK PLX 9054 Registers */
  218. #define INTCSR 0x68
  219. #define PCI_INTERRUPT_ENABLE 8
  220. #define LOCAL_INTERRUPT_INPUT_ENABLE 11
  221. #define LOCAL_INPUT_INTERRUPT_ACTIVE 15
  222. #define LOCAL_DMA_CHANNEL_0_INTERRUPT_ENABLE 18
  223. #define LOCAL_DMA_CHANNEL_1_INTERRUPT_ENABLE 19
  224. #define DMA_CHANNEL_0_INTERRUPT_ACTIVE 21
  225. #define DMA_CHANNEL_1_INTERRUPT_ACTIVE 22
  226. #define CNTRL 0x6C
  227. #define RELOAD_CONFIGURATION_REGISTERS 29
  228. #define PCI_ADAPTER_SOFTWARE_RESET 30
  229. #define DMAMODE0 0x80
  230. #define LOCAL_BUS_WIDTH 0
  231. #define INTERNAL_WAIT_STATES 2
  232. #define TA_READY_INPUT_ENABLE 6
  233. #define LOCAL_BURST_ENABLE 8
  234. #define SCATTER_GATHER_MODE 9
  235. #define DONE_INTERRUPT_ENABLE 10
  236. #define LOCAL_ADDRESSING_MODE 11
  237. #define DEMAND_MODE 12
  238. #define DMA_EOT_ENABLE 14
  239. #define FAST_SLOW_TERMINATE_MODE_SELECT 15
  240. #define DMA_CHANNEL_INTERRUPT_SELECT 17
  241. #define DMAPADR0 0x84
  242. #define DMALADR0 0x88
  243. #define DMASIZ0 0x8c
  244. #define DMADPR0 0x90
  245. #define DESCRIPTOR_LOCATION 0
  246. #define END_OF_CHAIN 1
  247. #define INTERRUPT_AFTER_TERMINAL_COUNT 2
  248. #define DIRECTION_OF_TRANSFER 3
  249. #define DMACSR0 0xa8
  250. #define CHANNEL_ENABLE 0
  251. #define CHANNEL_START 1
  252. #define CHANNEL_ABORT 2
  253. #define CHANNEL_CLEAR_INTERRUPT 3
  254. #define CHANNEL_DONE 4
  255. #define DMATHR 0xb0
  256. #define LBRD1 0xf8
  257. #define MEMORY_SPACE_LOCAL_BUS_WIDTH 0
  258. #define W8_BIT 0
  259. #define W16_BIT 1
  260. /* Special OR'ing of INTCSR bits */
  261. #define LOCAL_INTERRUPT_TEST \
  262. ((1 << LOCAL_INPUT_INTERRUPT_ACTIVE) | \
  263. (1 << LOCAL_INTERRUPT_INPUT_ENABLE))
  264. #define DMA_CHANNEL_0_TEST \
  265. ((1 << DMA_CHANNEL_0_INTERRUPT_ACTIVE) | \
  266. (1 << LOCAL_DMA_CHANNEL_0_INTERRUPT_ENABLE))
  267. #define DMA_CHANNEL_1_TEST \
  268. ((1 << DMA_CHANNEL_1_INTERRUPT_ACTIVE) | \
  269. (1 << LOCAL_DMA_CHANNEL_1_INTERRUPT_ENABLE))
  270. /* EPLD Registers */
  271. #define RDK_EPLD_IO_REGISTER1 0x00000000
  272. #define RDK_EPLD_USB_RESET 0
  273. #define RDK_EPLD_USB_POWERDOWN 1
  274. #define RDK_EPLD_USB_WAKEUP 2
  275. #define RDK_EPLD_USB_EOT 3
  276. #define RDK_EPLD_DPPULL 4
  277. #define RDK_EPLD_IO_REGISTER2 0x00000004
  278. #define RDK_EPLD_BUSWIDTH 0
  279. #define RDK_EPLD_USER 2
  280. #define RDK_EPLD_RESET_INTERRUPT_ENABLE 3
  281. #define RDK_EPLD_DMA_TIMEOUT_ENABLE 4
  282. #define RDK_EPLD_STATUS_REGISTER 0x00000008
  283. #define RDK_EPLD_USB_LRESET 0
  284. #define RDK_EPLD_REVISION_REGISTER 0x0000000c
  285. #define EPLD_IO_CONTROL_REGISTER 0x400
  286. #define NET2272_RESET 0
  287. #define BUSWIDTH 1
  288. #define MPX_MODE 3
  289. #define USER 4
  290. #define DMA_TIMEOUT_ENABLE 5
  291. #define DMA_CTL_DACK 6
  292. #define EPLD_DMA_ENABLE 7
  293. #define EPLD_DMA_CONTROL_REGISTER 0x800
  294. #define SPLIT_DMA_MODE 0
  295. #define SPLIT_DMA_DIRECTION 1
  296. #define SPLIT_DMA_ENABLE 2
  297. #define SPLIT_DMA_INTERRUPT_ENABLE 3
  298. #define SPLIT_DMA_INTERRUPT 4
  299. #define EPLD_DMA_MODE 5
  300. #define EPLD_DMA_CONTROLLER_ENABLE 7
  301. #define SPLIT_DMA_ADDRESS_LOW 0xc00
  302. #define SPLIT_DMA_ADDRESS_HIGH 0x1000
  303. #define SPLIT_DMA_BYTE_COUNT_LOW 0x1400
  304. #define SPLIT_DMA_BYTE_COUNT_HIGH 0x1800
  305. #define EPLD_REVISION_REGISTER 0x1c00
  306. #define SPLIT_DMA_RAM 0x4000
  307. #define DMA_RAM_SIZE 0x1000
  308. /*---------------------------------------------------------------------------*/
  309. #define PCI_DEVICE_ID_RDK2 0x3272
  310. /* PCI-RDK version 2 registers */
  311. /* Main Control Registers */
  312. #define RDK2_IRQENB 0x00
  313. #define RDK2_IRQSTAT 0x04
  314. #define PB7 23
  315. #define PB6 22
  316. #define PB5 21
  317. #define PB4 20
  318. #define PB3 19
  319. #define PB2 18
  320. #define PB1 17
  321. #define PB0 16
  322. #define GP3 23
  323. #define GP2 23
  324. #define GP1 23
  325. #define GP0 23
  326. #define DMA_RETRY_ABORT 6
  327. #define DMA_PAUSE_DONE 5
  328. #define DMA_ABORT_DONE 4
  329. #define DMA_OUT_FIFO_TRANSFER_DONE 3
  330. #define DMA_LOCAL_DONE 2
  331. #define DMA_PCI_DONE 1
  332. #define NET2272_PCI_IRQ 0
  333. #define RDK2_LOCCTLRDK 0x08
  334. #define CHIP_RESET 3
  335. #define SPLIT_DMA 2
  336. #define MULTIPLEX_MODE 1
  337. #define BUS_WIDTH 0
  338. #define RDK2_GPIOCTL 0x10
  339. #define GP3_OUT_ENABLE 7
  340. #define GP2_OUT_ENABLE 6
  341. #define GP1_OUT_ENABLE 5
  342. #define GP0_OUT_ENABLE 4
  343. #define GP3_DATA 3
  344. #define GP2_DATA 2
  345. #define GP1_DATA 1
  346. #define GP0_DATA 0
  347. #define RDK2_LEDSW 0x14
  348. #define LED3 27
  349. #define LED2 26
  350. #define LED1 25
  351. #define LED0 24
  352. #define PBUTTON 16
  353. #define DIPSW 0
  354. #define RDK2_DIAG 0x18
  355. #define RDK2_FAST_TIMES 2
  356. #define FORCE_PCI_SERR 1
  357. #define FORCE_PCI_INT 0
  358. #define RDK2_FPGAREV 0x1C
  359. /* Dma Control registers */
  360. #define RDK2_DMACTL 0x80
  361. #define ADDR_HOLD 24
  362. #define RETRY_COUNT 16 /* 23:16 */
  363. #define FIFO_THRESHOLD 11 /* 15:11 */
  364. #define MEM_WRITE_INVALIDATE 10
  365. #define READ_MULTIPLE 9
  366. #define READ_LINE 8
  367. #define RDK2_DMA_MODE 6 /* 7:6 */
  368. #define CONTROL_DACK 5
  369. #define EOT_ENABLE 4
  370. #define EOT_POLARITY 3
  371. #define DACK_POLARITY 2
  372. #define DREQ_POLARITY 1
  373. #define DMA_ENABLE 0
  374. #define RDK2_DMASTAT 0x84
  375. #define GATHER_COUNT 12 /* 14:12 */
  376. #define FIFO_COUNT 6 /* 11:6 */
  377. #define FIFO_FLUSH 5
  378. #define FIFO_TRANSFER 4
  379. #define PAUSE_DONE 3
  380. #define ABORT_DONE 2
  381. #define DMA_ABORT 1
  382. #define DMA_START 0
  383. #define RDK2_DMAPCICOUNT 0x88
  384. #define DMA_DIRECTION 31
  385. #define DMA_PCI_BYTE_COUNT 0 /* 0:23 */
  386. #define RDK2_DMALOCCOUNT 0x8C /* 0:23 dma local byte count */
  387. #define RDK2_DMAADDR 0x90 /* 2:31 PCI bus starting address */
  388. /*---------------------------------------------------------------------------*/
  389. #define REG_INDEXED_THRESHOLD (1 << 5)
  390. /* DRIVER DATA STRUCTURES and UTILITIES */
  391. struct net2272_ep {
  392. struct usb_ep ep;
  393. struct net2272 *dev;
  394. unsigned long irqs;
  395. /* analogous to a host-side qh */
  396. struct list_head queue;
  397. const struct usb_endpoint_descriptor *desc;
  398. unsigned num:8,
  399. fifo_size:12,
  400. stopped:1,
  401. wedged:1,
  402. is_in:1,
  403. is_iso:1,
  404. dma:1,
  405. not_empty:1;
  406. };
  407. struct net2272 {
  408. /* each device provides one gadget, several endpoints */
  409. struct usb_gadget gadget;
  410. struct device *dev;
  411. unsigned short dev_id;
  412. spinlock_t lock;
  413. struct net2272_ep ep[4];
  414. struct usb_gadget_driver *driver;
  415. unsigned protocol_stall:1,
  416. softconnect:1,
  417. wakeup:1,
  418. dma_eot_polarity:1,
  419. dma_dack_polarity:1,
  420. dma_dreq_polarity:1,
  421. dma_busy:1;
  422. u16 chiprev;
  423. u8 pagesel;
  424. unsigned int irq;
  425. unsigned short fifo_mode;
  426. unsigned int base_shift;
  427. u16 __iomem *base_addr;
  428. union {
  429. #ifdef CONFIG_USB_PCI
  430. struct {
  431. void __iomem *plx9054_base_addr;
  432. void __iomem *epld_base_addr;
  433. } rdk1;
  434. struct {
  435. /* Bar0, Bar1 is base_addr both mem-mapped */
  436. void __iomem *fpga_base_addr;
  437. } rdk2;
  438. #endif
  439. };
  440. };
  441. static void __iomem *
  442. net2272_reg_addr(struct net2272 *dev, unsigned int reg)
  443. {
  444. return dev->base_addr + (reg << dev->base_shift);
  445. }
  446. static void
  447. net2272_write(struct net2272 *dev, unsigned int reg, u8 value)
  448. {
  449. if (reg >= REG_INDEXED_THRESHOLD) {
  450. /*
  451. * Indexed register; use REGADDRPTR/REGDATA
  452. * - Save and restore REGADDRPTR. This prevents REGADDRPTR from
  453. * changes between other code sections, but it is time consuming.
  454. * - Performance tips: either do not save and restore REGADDRPTR (if it
  455. * is safe) or do save/restore operations only in critical sections.
  456. u8 tmp = readb(dev->base_addr + REGADDRPTR);
  457. */
  458. writeb((u8)reg, net2272_reg_addr(dev, REGADDRPTR));
  459. writeb(value, net2272_reg_addr(dev, REGDATA));
  460. /* writeb(tmp, net2272_reg_addr(dev, REGADDRPTR)); */
  461. } else
  462. writeb(value, net2272_reg_addr(dev, reg));
  463. }
  464. static u8
  465. net2272_read(struct net2272 *dev, unsigned int reg)
  466. {
  467. u8 ret;
  468. if (reg >= REG_INDEXED_THRESHOLD) {
  469. /*
  470. * Indexed register; use REGADDRPTR/REGDATA
  471. * - Save and restore REGADDRPTR. This prevents REGADDRPTR from
  472. * changes between other code sections, but it is time consuming.
  473. * - Performance tips: either do not save and restore REGADDRPTR (if it
  474. * is safe) or do save/restore operations only in critical sections.
  475. u8 tmp = readb(dev->base_addr + REGADDRPTR);
  476. */
  477. writeb((u8)reg, net2272_reg_addr(dev, REGADDRPTR));
  478. ret = readb(net2272_reg_addr(dev, REGDATA));
  479. /* writeb(tmp, net2272_reg_addr(dev, REGADDRPTR)); */
  480. } else
  481. ret = readb(net2272_reg_addr(dev, reg));
  482. return ret;
  483. }
  484. static void
  485. net2272_ep_write(struct net2272_ep *ep, unsigned int reg, u8 value)
  486. {
  487. struct net2272 *dev = ep->dev;
  488. if (dev->pagesel != ep->num) {
  489. net2272_write(dev, PAGESEL, ep->num);
  490. dev->pagesel = ep->num;
  491. }
  492. net2272_write(dev, reg, value);
  493. }
  494. static u8
  495. net2272_ep_read(struct net2272_ep *ep, unsigned int reg)
  496. {
  497. struct net2272 *dev = ep->dev;
  498. if (dev->pagesel != ep->num) {
  499. net2272_write(dev, PAGESEL, ep->num);
  500. dev->pagesel = ep->num;
  501. }
  502. return net2272_read(dev, reg);
  503. }
  504. static void allow_status(struct net2272_ep *ep)
  505. {
  506. /* ep0 only */
  507. net2272_ep_write(ep, EP_RSPCLR,
  508. (1 << CONTROL_STATUS_PHASE_HANDSHAKE) |
  509. (1 << ALT_NAK_OUT_PACKETS) |
  510. (1 << NAK_OUT_PACKETS_MODE));
  511. ep->stopped = 1;
  512. }
  513. static void set_halt(struct net2272_ep *ep)
  514. {
  515. /* ep0 and bulk/intr endpoints */
  516. net2272_ep_write(ep, EP_RSPCLR, 1 << CONTROL_STATUS_PHASE_HANDSHAKE);
  517. net2272_ep_write(ep, EP_RSPSET, 1 << ENDPOINT_HALT);
  518. }
  519. static void clear_halt(struct net2272_ep *ep)
  520. {
  521. /* ep0 and bulk/intr endpoints */
  522. net2272_ep_write(ep, EP_RSPCLR,
  523. (1 << ENDPOINT_HALT) | (1 << ENDPOINT_TOGGLE));
  524. }
  525. /* count (<= 4) bytes in the next fifo write will be valid */
  526. static void set_fifo_bytecount(struct net2272_ep *ep, unsigned count)
  527. {
  528. /* net2272_ep_write will truncate to u8 for us */
  529. net2272_ep_write(ep, EP_TRANSFER2, count >> 16);
  530. net2272_ep_write(ep, EP_TRANSFER1, count >> 8);
  531. net2272_ep_write(ep, EP_TRANSFER0, count);
  532. }
  533. struct net2272_request {
  534. struct usb_request req;
  535. struct list_head queue;
  536. unsigned mapped:1,
  537. valid:1;
  538. };
  539. #endif