net2272.h 16 KB

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