hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/staging/octeon-usb/octeon-hcd.c
....@@ -50,6 +50,7 @@
5050 #include <linux/module.h>
5151 #include <linux/usb/hcd.h>
5252 #include <linux/prefetch.h>
53
+#include <linux/dma-mapping.h>
5354 #include <linux/platform_device.h>
5455
5556 #include <asm/octeon/octeon.h>
....@@ -377,29 +378,6 @@
377378 struct cvmx_usb_tx_fifo nonperiodic;
378379 };
379380
380
-/* This macro spins on a register waiting for it to reach a condition. */
381
-#define CVMX_WAIT_FOR_FIELD32(address, _union, cond, timeout_usec) \
382
- ({int result; \
383
- do { \
384
- u64 done = cvmx_get_cycle() + (u64)timeout_usec * \
385
- octeon_get_clock_rate() / 1000000; \
386
- union _union c; \
387
- \
388
- while (1) { \
389
- c.u32 = cvmx_usb_read_csr32(usb, address); \
390
- \
391
- if (cond) { \
392
- result = 0; \
393
- break; \
394
- } else if (cvmx_get_cycle() > done) { \
395
- result = -1; \
396
- break; \
397
- } else \
398
- __delay(100); \
399
- } \
400
- } while (0); \
401
- result; })
402
-
403381 /*
404382 * This macro logically sets a single field in a CSR. It does the sequence
405383 * read, modify, and write
....@@ -428,7 +406,7 @@
428406 */
429407 struct octeon_temp_buffer {
430408 void *orig_buffer;
431
- u8 data[0];
409
+ u8 data[];
432410 };
433411
434412 static inline struct usb_hcd *octeon_to_hcd(struct octeon_hcd *p)
....@@ -543,8 +521,7 @@
543521 */
544522 static inline u32 cvmx_usb_read_csr32(struct octeon_hcd *usb, u64 address)
545523 {
546
- u32 result = cvmx_read64_uint32(address ^ 4);
547
- return result;
524
+ return cvmx_read64_uint32(address ^ 4);
548525 }
549526
550527 /**
....@@ -593,6 +570,33 @@
593570 return 0; /* Data0 */
594571 }
595572
573
+/* Loops through register until txfflsh or rxfflsh become zero.*/
574
+static int cvmx_wait_tx_rx(struct octeon_hcd *usb, int fflsh_type)
575
+{
576
+ int result;
577
+ u64 address = CVMX_USBCX_GRSTCTL(usb->index);
578
+ u64 done = cvmx_get_cycle() + 100 *
579
+ (u64)octeon_get_clock_rate / 1000000;
580
+ union cvmx_usbcx_grstctl c;
581
+
582
+ while (1) {
583
+ c.u32 = cvmx_usb_read_csr32(usb, address);
584
+ if (fflsh_type == 0 && c.s.txfflsh == 0) {
585
+ result = 0;
586
+ break;
587
+ } else if (fflsh_type == 1 && c.s.rxfflsh == 0) {
588
+ result = 0;
589
+ break;
590
+ } else if (cvmx_get_cycle() > done) {
591
+ result = -1;
592
+ break;
593
+ }
594
+
595
+ __delay(100);
596
+ }
597
+ return result;
598
+}
599
+
596600 static void cvmx_fifo_setup(struct octeon_hcd *usb)
597601 {
598602 union cvmx_usbcx_ghwcfg3 usbcx_ghwcfg3;
....@@ -634,12 +638,10 @@
634638 cvmx_usbcx_grstctl, txfnum, 0x10);
635639 USB_SET_FIELD32(CVMX_USBCX_GRSTCTL(usb->index),
636640 cvmx_usbcx_grstctl, txfflsh, 1);
637
- CVMX_WAIT_FOR_FIELD32(CVMX_USBCX_GRSTCTL(usb->index),
638
- cvmx_usbcx_grstctl, c.s.txfflsh == 0, 100);
641
+ cvmx_wait_tx_rx(usb, 0);
639642 USB_SET_FIELD32(CVMX_USBCX_GRSTCTL(usb->index),
640643 cvmx_usbcx_grstctl, rxfflsh, 1);
641
- CVMX_WAIT_FOR_FIELD32(CVMX_USBCX_GRSTCTL(usb->index),
642
- cvmx_usbcx_grstctl, c.s.rxfflsh == 0, 100);
644
+ cvmx_wait_tx_rx(usb, 1);
643645 }
644646
645647 /**
....@@ -1231,8 +1233,7 @@
12311233 cvmx_write64_uint32(csr_address, *ptr++);
12321234 cvmx_write64_uint32(csr_address, *ptr++);
12331235 cvmx_write64_uint32(csr_address, *ptr++);
1234
- cvmx_read64_uint64(
1235
- CVMX_USBNX_DMA0_INB_CHN0(usb->index));
1236
+ cvmx_read64_uint64(CVMX_USBNX_DMA0_INB_CHN0(usb->index));
12361237 words -= 3;
12371238 }
12381239 cvmx_write64_uint32(csr_address, *ptr++);
....@@ -1834,8 +1835,7 @@
18341835 *
18351836 * Returns: Pipe or NULL if none are ready
18361837 */
1837
-static struct cvmx_usb_pipe *cvmx_usb_find_ready_pipe(
1838
- struct octeon_hcd *usb,
1838
+static struct cvmx_usb_pipe *cvmx_usb_find_ready_pipe(struct octeon_hcd *usb,
18391839 enum cvmx_usb_transfer xfer_type)
18401840 {
18411841 struct list_head *list = usb->active_pipes + xfer_type;
....@@ -2382,13 +2382,11 @@
23822382 */
23832383 static int cvmx_usb_get_frame_number(struct octeon_hcd *usb)
23842384 {
2385
- int frame_number;
23862385 union cvmx_usbcx_hfnum usbc_hfnum;
23872386
23882387 usbc_hfnum.u32 = cvmx_usb_read_csr32(usb, CVMX_USBCX_HFNUM(usb->index));
2389
- frame_number = usbc_hfnum.s.frnum;
23902388
2391
- return frame_number;
2389
+ return usbc_hfnum.s.frnum;
23922390 }
23932391
23942392 static void cvmx_usb_transfer_control(struct octeon_hcd *usb,
....@@ -2768,7 +2766,7 @@
27682766 (pipe->transfer_dir == CVMX_USB_DIRECTION_OUT))
27692767 pipe->flags |= CVMX_USB_PIPE_FLAGS_NEED_PING;
27702768
2771
- if (unlikely(WARN_ON_ONCE(bytes_this_transfer < 0))) {
2769
+ if (WARN_ON_ONCE(bytes_this_transfer < 0)) {
27722770 /*
27732771 * In some rare cases the DMA engine seems to get stuck and
27742772 * keeps substracting same byte count over and over again. In
....@@ -3512,7 +3510,7 @@
35123510 .product_desc = "Octeon Host Controller",
35133511 .hcd_priv_size = sizeof(struct octeon_hcd),
35143512 .irq = octeon_usb_irq,
3515
- .flags = HCD_MEMORY | HCD_USB2,
3513
+ .flags = HCD_MEMORY | HCD_DMA | HCD_USB2,
35163514 .start = octeon_usb_start,
35173515 .stop = octeon_usb_stop,
35183516 .urb_enqueue = octeon_usb_urb_enqueue,
....@@ -3604,8 +3602,9 @@
36043602 * Set the DMA mask to 64bits so we get buffers already translated for
36053603 * DMA.
36063604 */
3607
- dev->coherent_dma_mask = ~0;
3608
- dev->dma_mask = &dev->coherent_dma_mask;
3605
+ i = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64));
3606
+ if (i)
3607
+ return i;
36093608
36103609 /*
36113610 * Only cn52XX and cn56XX have DWC_OTG USB hardware and the