net2272.h 17 KB

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