diff options
Diffstat (limited to 'drivers/usb')
342 files changed, 22934 insertions, 3911 deletions
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 2642b8a11e05..2e6b832e004b 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig | |||
@@ -94,8 +94,6 @@ source "drivers/usb/wusbcore/Kconfig" | |||
94 | 94 | ||
95 | source "drivers/usb/host/Kconfig" | 95 | source "drivers/usb/host/Kconfig" |
96 | 96 | ||
97 | source "drivers/usb/musb/Kconfig" | ||
98 | |||
99 | source "drivers/usb/renesas_usbhs/Kconfig" | 97 | source "drivers/usb/renesas_usbhs/Kconfig" |
100 | 98 | ||
101 | source "drivers/usb/class/Kconfig" | 99 | source "drivers/usb/class/Kconfig" |
@@ -106,8 +104,12 @@ source "drivers/usb/image/Kconfig" | |||
106 | 104 | ||
107 | endif | 105 | endif |
108 | 106 | ||
107 | source "drivers/usb/musb/Kconfig" | ||
108 | |||
109 | source "drivers/usb/dwc3/Kconfig" | 109 | source "drivers/usb/dwc3/Kconfig" |
110 | 110 | ||
111 | source "drivers/usb/dwc2/Kconfig" | ||
112 | |||
111 | source "drivers/usb/chipidea/Kconfig" | 113 | source "drivers/usb/chipidea/Kconfig" |
112 | 114 | ||
113 | comment "USB port drivers" | 115 | comment "USB port drivers" |
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index 70d7c5b92c3c..1ae2bf39d84b 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile | |||
@@ -7,6 +7,7 @@ | |||
7 | obj-$(CONFIG_USB) += core/ | 7 | obj-$(CONFIG_USB) += core/ |
8 | 8 | ||
9 | obj-$(CONFIG_USB_DWC3) += dwc3/ | 9 | obj-$(CONFIG_USB_DWC3) += dwc3/ |
10 | obj-$(CONFIG_USB_DWC2) += dwc2/ | ||
10 | 11 | ||
11 | obj-$(CONFIG_USB_MON) += mon/ | 12 | obj-$(CONFIG_USB_MON) += mon/ |
12 | 13 | ||
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c index 8a7eb77233b4..813d4d3a51c6 100644 --- a/drivers/usb/atm/cxacru.c +++ b/drivers/usb/atm/cxacru.c | |||
@@ -35,7 +35,6 @@ | |||
35 | #include <linux/timer.h> | 35 | #include <linux/timer.h> |
36 | #include <linux/errno.h> | 36 | #include <linux/errno.h> |
37 | #include <linux/slab.h> | 37 | #include <linux/slab.h> |
38 | #include <linux/init.h> | ||
39 | #include <linux/device.h> | 38 | #include <linux/device.h> |
40 | #include <linux/firmware.h> | 39 | #include <linux/firmware.h> |
41 | #include <linux/mutex.h> | 40 | #include <linux/mutex.h> |
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c index 69461d653972..0dc8c06a7b5f 100644 --- a/drivers/usb/atm/speedtch.c +++ b/drivers/usb/atm/speedtch.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include <linux/device.h> | 27 | #include <linux/device.h> |
28 | #include <linux/errno.h> | 28 | #include <linux/errno.h> |
29 | #include <linux/firmware.h> | 29 | #include <linux/firmware.h> |
30 | #include <linux/init.h> | ||
31 | #include <linux/kernel.h> | 30 | #include <linux/kernel.h> |
32 | #include <linux/module.h> | 31 | #include <linux/module.h> |
33 | #include <linux/moduleparam.h> | 32 | #include <linux/moduleparam.h> |
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c index defff43950bc..5a459377574b 100644 --- a/drivers/usb/atm/ueagle-atm.c +++ b/drivers/usb/atm/ueagle-atm.c | |||
@@ -57,7 +57,6 @@ | |||
57 | 57 | ||
58 | #include <linux/module.h> | 58 | #include <linux/module.h> |
59 | #include <linux/moduleparam.h> | 59 | #include <linux/moduleparam.h> |
60 | #include <linux/init.h> | ||
61 | #include <linux/crc32.h> | 60 | #include <linux/crc32.h> |
62 | #include <linux/usb.h> | 61 | #include <linux/usb.h> |
63 | #include <linux/firmware.h> | 62 | #include <linux/firmware.h> |
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c index 25a7bfcf666c..dada0146cd7f 100644 --- a/drivers/usb/atm/usbatm.c +++ b/drivers/usb/atm/usbatm.c | |||
@@ -170,9 +170,9 @@ struct usbatm_control { | |||
170 | static void usbatm_atm_dev_close(struct atm_dev *atm_dev); | 170 | static void usbatm_atm_dev_close(struct atm_dev *atm_dev); |
171 | static int usbatm_atm_open(struct atm_vcc *vcc); | 171 | static int usbatm_atm_open(struct atm_vcc *vcc); |
172 | static void usbatm_atm_close(struct atm_vcc *vcc); | 172 | static void usbatm_atm_close(struct atm_vcc *vcc); |
173 | static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd, void __user * arg); | 173 | static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd, void __user *arg); |
174 | static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb); | 174 | static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb); |
175 | static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page); | 175 | static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page); |
176 | 176 | ||
177 | static struct atmdev_ops usbatm_atm_devops = { | 177 | static struct atmdev_ops usbatm_atm_devops = { |
178 | .dev_close = usbatm_atm_dev_close, | 178 | .dev_close = usbatm_atm_dev_close, |
@@ -739,7 +739,7 @@ static void usbatm_atm_dev_close(struct atm_dev *atm_dev) | |||
739 | usbatm_put_instance(instance); /* taken in usbatm_atm_init */ | 739 | usbatm_put_instance(instance); /* taken in usbatm_atm_init */ |
740 | } | 740 | } |
741 | 741 | ||
742 | static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page) | 742 | static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page) |
743 | { | 743 | { |
744 | struct usbatm_data *instance = atm_dev->dev_data; | 744 | struct usbatm_data *instance = atm_dev->dev_data; |
745 | int left = *pos; | 745 | int left = *pos; |
@@ -895,7 +895,7 @@ static void usbatm_atm_close(struct atm_vcc *vcc) | |||
895 | } | 895 | } |
896 | 896 | ||
897 | static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd, | 897 | static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd, |
898 | void __user * arg) | 898 | void __user *arg) |
899 | { | 899 | { |
900 | struct usbatm_data *instance = atm_dev->dev_data; | 900 | struct usbatm_data *instance = atm_dev->dev_data; |
901 | 901 | ||
diff --git a/drivers/usb/c67x00/Makefile b/drivers/usb/c67x00/Makefile index b1218683c8ec..da5f314a5de0 100644 --- a/drivers/usb/c67x00/Makefile +++ b/drivers/usb/c67x00/Makefile | |||
@@ -2,8 +2,6 @@ | |||
2 | # Makefile for Cypress C67X00 USB Controller | 2 | # Makefile for Cypress C67X00 USB Controller |
3 | # | 3 | # |
4 | 4 | ||
5 | ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG | ||
6 | |||
7 | obj-$(CONFIG_USB_C67X00_HCD) += c67x00.o | 5 | obj-$(CONFIG_USB_C67X00_HCD) += c67x00.o |
8 | 6 | ||
9 | c67x00-y := c67x00-drv.o c67x00-ll-hpi.o c67x00-hcd.o c67x00-sched.o | 7 | c67x00-y := c67x00-drv.o c67x00-ll-hpi.o c67x00-hcd.o c67x00-sched.o |
diff --git a/drivers/usb/c67x00/c67x00-hcd.c b/drivers/usb/c67x00/c67x00-hcd.c index 75e47b860a53..20ec4eee1ac8 100644 --- a/drivers/usb/c67x00/c67x00-hcd.c +++ b/drivers/usb/c67x00/c67x00-hcd.c | |||
@@ -384,6 +384,8 @@ int c67x00_hcd_probe(struct c67x00_sie *sie) | |||
384 | goto err2; | 384 | goto err2; |
385 | } | 385 | } |
386 | 386 | ||
387 | device_wakeup_enable(hcd->self.controller); | ||
388 | |||
387 | spin_lock_irqsave(&sie->lock, flags); | 389 | spin_lock_irqsave(&sie->lock, flags); |
388 | sie->private_data = c67x00; | 390 | sie->private_data = c67x00; |
389 | sie->irq = c67x00_hcd_irq; | 391 | sie->irq = c67x00_hcd_irq; |
diff --git a/drivers/usb/c67x00/c67x00-hcd.h b/drivers/usb/c67x00/c67x00-hcd.h index e3d493d4d61a..cf8a455a6403 100644 --- a/drivers/usb/c67x00/c67x00-hcd.h +++ b/drivers/usb/c67x00/c67x00-hcd.h | |||
@@ -45,7 +45,7 @@ | |||
45 | /* | 45 | /* |
46 | * The current implementation switches between _STD (default) and _ISO (when | 46 | * The current implementation switches between _STD (default) and _ISO (when |
47 | * isochronous transfers are scheduled), in order to optimize the throughput | 47 | * isochronous transfers are scheduled), in order to optimize the throughput |
48 | * in normal cicrumstances, but also provide good isochronous behaviour. | 48 | * in normal circumstances, but also provide good isochronous behaviour. |
49 | * | 49 | * |
50 | * Bandwidth is described in bit time so with a 12MHz USB clock and 1ms | 50 | * Bandwidth is described in bit time so with a 12MHz USB clock and 1ms |
51 | * frames; there are 12000 bit times per frame. | 51 | * frames; there are 12000 bit times per frame. |
diff --git a/drivers/usb/c67x00/c67x00-ll-hpi.c b/drivers/usb/c67x00/c67x00-ll-hpi.c index 3a1ca4dfc83a..b58151841e10 100644 --- a/drivers/usb/c67x00/c67x00-ll-hpi.c +++ b/drivers/usb/c67x00/c67x00-ll-hpi.c | |||
@@ -22,6 +22,7 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <asm/byteorder.h> | 24 | #include <asm/byteorder.h> |
25 | #include <linux/delay.h> | ||
25 | #include <linux/io.h> | 26 | #include <linux/io.h> |
26 | #include <linux/jiffies.h> | 27 | #include <linux/jiffies.h> |
27 | #include <linux/usb/c67x00.h> | 28 | #include <linux/usb/c67x00.h> |
@@ -62,8 +63,8 @@ struct c67x00_lcp_int_data { | |||
62 | * HPI implementation | 63 | * HPI implementation |
63 | * | 64 | * |
64 | * The c67x00 chip also support control via SPI or HSS serial | 65 | * The c67x00 chip also support control via SPI or HSS serial |
65 | * interfaces. However, this driver assumes that register access can | 66 | * interfaces. However, this driver assumes that register access can |
66 | * be performed from IRQ context. While this is a safe assuption with | 67 | * be performed from IRQ context. While this is a safe assumption with |
67 | * the HPI interface, it is not true for the serial interfaces. | 68 | * the HPI interface, it is not true for the serial interfaces. |
68 | */ | 69 | */ |
69 | 70 | ||
@@ -73,13 +74,22 @@ struct c67x00_lcp_int_data { | |||
73 | #define HPI_ADDR 2 | 74 | #define HPI_ADDR 2 |
74 | #define HPI_STATUS 3 | 75 | #define HPI_STATUS 3 |
75 | 76 | ||
77 | /* | ||
78 | * According to CY7C67300 specification (tables 140 and 141) HPI read and | ||
79 | * write cycle duration Tcyc must be at least 6T long, where T is 1/48MHz, | ||
80 | * which is 125ns. | ||
81 | */ | ||
82 | #define HPI_T_CYC_NS 125 | ||
83 | |||
76 | static inline u16 hpi_read_reg(struct c67x00_device *dev, int reg) | 84 | static inline u16 hpi_read_reg(struct c67x00_device *dev, int reg) |
77 | { | 85 | { |
86 | ndelay(HPI_T_CYC_NS); | ||
78 | return __raw_readw(dev->hpi.base + reg * dev->hpi.regstep); | 87 | return __raw_readw(dev->hpi.base + reg * dev->hpi.regstep); |
79 | } | 88 | } |
80 | 89 | ||
81 | static inline void hpi_write_reg(struct c67x00_device *dev, int reg, u16 value) | 90 | static inline void hpi_write_reg(struct c67x00_device *dev, int reg, u16 value) |
82 | { | 91 | { |
92 | ndelay(HPI_T_CYC_NS); | ||
83 | __raw_writew(value, dev->hpi.base + reg * dev->hpi.regstep); | 93 | __raw_writew(value, dev->hpi.base + reg * dev->hpi.regstep); |
84 | } | 94 | } |
85 | 95 | ||
diff --git a/drivers/usb/c67x00/c67x00-sched.c b/drivers/usb/c67x00/c67x00-sched.c index 892cc96466eb..7311ed61e99a 100644 --- a/drivers/usb/c67x00/c67x00-sched.c +++ b/drivers/usb/c67x00/c67x00-sched.c | |||
@@ -144,8 +144,6 @@ struct c67x00_urb_priv { | |||
144 | 144 | ||
145 | /* -------------------------------------------------------------------------- */ | 145 | /* -------------------------------------------------------------------------- */ |
146 | 146 | ||
147 | #ifdef DEBUG | ||
148 | |||
149 | /** | 147 | /** |
150 | * dbg_td - Dump the contents of the TD | 148 | * dbg_td - Dump the contents of the TD |
151 | */ | 149 | */ |
@@ -166,16 +164,8 @@ static void dbg_td(struct c67x00_hcd *c67x00, struct c67x00_td *td, char *msg) | |||
166 | dev_dbg(dev, "retry_cnt: 0x%02x\n", td->retry_cnt); | 164 | dev_dbg(dev, "retry_cnt: 0x%02x\n", td->retry_cnt); |
167 | dev_dbg(dev, "residue: 0x%02x\n", td->residue); | 165 | dev_dbg(dev, "residue: 0x%02x\n", td->residue); |
168 | dev_dbg(dev, "next_td_addr: 0x%04x\n", td_next_td_addr(td)); | 166 | dev_dbg(dev, "next_td_addr: 0x%04x\n", td_next_td_addr(td)); |
169 | dev_dbg(dev, "data:"); | 167 | dev_dbg(dev, "data: %*ph\n", td_length(td), td->data); |
170 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 1, | ||
171 | td->data, td_length(td), 1); | ||
172 | } | 168 | } |
173 | #else /* DEBUG */ | ||
174 | |||
175 | static inline void | ||
176 | dbg_td(struct c67x00_hcd *c67x00, struct c67x00_td *td, char *msg) { } | ||
177 | |||
178 | #endif /* DEBUG */ | ||
179 | 169 | ||
180 | /* -------------------------------------------------------------------------- */ | 170 | /* -------------------------------------------------------------------------- */ |
181 | /* Helper functions */ | 171 | /* Helper functions */ |
@@ -372,6 +362,13 @@ int c67x00_urb_enqueue(struct usb_hcd *hcd, | |||
372 | struct c67x00_hcd *c67x00 = hcd_to_c67x00_hcd(hcd); | 362 | struct c67x00_hcd *c67x00 = hcd_to_c67x00_hcd(hcd); |
373 | int port = get_root_port(urb->dev)-1; | 363 | int port = get_root_port(urb->dev)-1; |
374 | 364 | ||
365 | /* Allocate and initialize urb private data */ | ||
366 | urbp = kzalloc(sizeof(*urbp), mem_flags); | ||
367 | if (!urbp) { | ||
368 | ret = -ENOMEM; | ||
369 | goto err_urbp; | ||
370 | } | ||
371 | |||
375 | spin_lock_irqsave(&c67x00->lock, flags); | 372 | spin_lock_irqsave(&c67x00->lock, flags); |
376 | 373 | ||
377 | /* Make sure host controller is running */ | 374 | /* Make sure host controller is running */ |
@@ -384,13 +381,6 @@ int c67x00_urb_enqueue(struct usb_hcd *hcd, | |||
384 | if (ret) | 381 | if (ret) |
385 | goto err_not_linked; | 382 | goto err_not_linked; |
386 | 383 | ||
387 | /* Allocate and initialize urb private data */ | ||
388 | urbp = kzalloc(sizeof(*urbp), mem_flags); | ||
389 | if (!urbp) { | ||
390 | ret = -ENOMEM; | ||
391 | goto err_urbp; | ||
392 | } | ||
393 | |||
394 | INIT_LIST_HEAD(&urbp->hep_node); | 384 | INIT_LIST_HEAD(&urbp->hep_node); |
395 | urbp->urb = urb; | 385 | urbp->urb = urb; |
396 | urbp->port = port; | 386 | urbp->port = port; |
@@ -453,11 +443,11 @@ int c67x00_urb_enqueue(struct usb_hcd *hcd, | |||
453 | return 0; | 443 | return 0; |
454 | 444 | ||
455 | err_epdata: | 445 | err_epdata: |
456 | kfree(urbp); | ||
457 | err_urbp: | ||
458 | usb_hcd_unlink_urb_from_ep(hcd, urb); | 446 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
459 | err_not_linked: | 447 | err_not_linked: |
460 | spin_unlock_irqrestore(&c67x00->lock, flags); | 448 | spin_unlock_irqrestore(&c67x00->lock, flags); |
449 | kfree(urbp); | ||
450 | err_urbp: | ||
461 | 451 | ||
462 | return ret; | 452 | return ret; |
463 | } | 453 | } |
@@ -780,7 +770,8 @@ static int c67x00_add_iso_urb(struct c67x00_hcd *c67x00, struct urb *urb) | |||
780 | ret = c67x00_create_td(c67x00, urb, td_buf, len, pid, 0, | 770 | ret = c67x00_create_td(c67x00, urb, td_buf, len, pid, 0, |
781 | urbp->cnt); | 771 | urbp->cnt); |
782 | if (ret) { | 772 | if (ret) { |
783 | printk(KERN_DEBUG "create failed: %d\n", ret); | 773 | dev_dbg(c67x00_hcd_dev(c67x00), "create failed: %d\n", |
774 | ret); | ||
784 | urb->iso_frame_desc[urbp->cnt].actual_length = 0; | 775 | urb->iso_frame_desc[urbp->cnt].actual_length = 0; |
785 | urb->iso_frame_desc[urbp->cnt].status = ret; | 776 | urb->iso_frame_desc[urbp->cnt].status = ret; |
786 | if (urbp->cnt + 1 == urb->number_of_packets) | 777 | if (urbp->cnt + 1 == urb->number_of_packets) |
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile index a99d980454a6..7345d2115af2 100644 --- a/drivers/usb/chipidea/Makefile +++ b/drivers/usb/chipidea/Makefile | |||
@@ -17,5 +17,5 @@ ifneq ($(CONFIG_PCI),) | |||
17 | endif | 17 | endif |
18 | 18 | ||
19 | ifneq ($(CONFIG_OF),) | 19 | ifneq ($(CONFIG_OF),) |
20 | obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_imx.o usbmisc_imx.o | 20 | obj-$(CONFIG_USB_CHIPIDEA) += usbmisc_imx.o ci_hdrc_imx.o |
21 | endif | 21 | endif |
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index 1c94fc5257f4..88b80f7728e4 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h | |||
@@ -26,6 +26,35 @@ | |||
26 | #define ENDPT_MAX 32 | 26 | #define ENDPT_MAX 32 |
27 | 27 | ||
28 | /****************************************************************************** | 28 | /****************************************************************************** |
29 | * REGISTERS | ||
30 | *****************************************************************************/ | ||
31 | /* register indices */ | ||
32 | enum ci_hw_regs { | ||
33 | CAP_CAPLENGTH, | ||
34 | CAP_HCCPARAMS, | ||
35 | CAP_DCCPARAMS, | ||
36 | CAP_TESTMODE, | ||
37 | CAP_LAST = CAP_TESTMODE, | ||
38 | OP_USBCMD, | ||
39 | OP_USBSTS, | ||
40 | OP_USBINTR, | ||
41 | OP_DEVICEADDR, | ||
42 | OP_ENDPTLISTADDR, | ||
43 | OP_PORTSC, | ||
44 | OP_DEVLC, | ||
45 | OP_OTGSC, | ||
46 | OP_USBMODE, | ||
47 | OP_ENDPTSETUPSTAT, | ||
48 | OP_ENDPTPRIME, | ||
49 | OP_ENDPTFLUSH, | ||
50 | OP_ENDPTSTAT, | ||
51 | OP_ENDPTCOMPLETE, | ||
52 | OP_ENDPTCTRL, | ||
53 | /* endptctrl1..15 follow */ | ||
54 | OP_LAST = OP_ENDPTCTRL + ENDPT_MAX / 2, | ||
55 | }; | ||
56 | |||
57 | /****************************************************************************** | ||
29 | * STRUCTURES | 58 | * STRUCTURES |
30 | *****************************************************************************/ | 59 | *****************************************************************************/ |
31 | /** | 60 | /** |
@@ -98,7 +127,7 @@ struct hw_bank { | |||
98 | void __iomem *cap; | 127 | void __iomem *cap; |
99 | void __iomem *op; | 128 | void __iomem *op; |
100 | size_t size; | 129 | size_t size; |
101 | void __iomem **regmap; | 130 | void __iomem *regmap[OP_LAST + 1]; |
102 | }; | 131 | }; |
103 | 132 | ||
104 | /** | 133 | /** |
@@ -135,6 +164,7 @@ struct hw_bank { | |||
135 | * @id_event: indicates there is an id event, and handled at ci_otg_work | 164 | * @id_event: indicates there is an id event, and handled at ci_otg_work |
136 | * @b_sess_valid_event: indicates there is a vbus event, and handled | 165 | * @b_sess_valid_event: indicates there is a vbus event, and handled |
137 | * at ci_otg_work | 166 | * at ci_otg_work |
167 | * @imx28_write_fix: Freescale imx28 needs swp instruction for writing | ||
138 | */ | 168 | */ |
139 | struct ci_hdrc { | 169 | struct ci_hdrc { |
140 | struct device *dev; | 170 | struct device *dev; |
@@ -173,6 +203,7 @@ struct ci_hdrc { | |||
173 | struct dentry *debugfs; | 203 | struct dentry *debugfs; |
174 | bool id_event; | 204 | bool id_event; |
175 | bool b_sess_valid_event; | 205 | bool b_sess_valid_event; |
206 | bool imx28_write_fix; | ||
176 | }; | 207 | }; |
177 | 208 | ||
178 | static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci) | 209 | static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci) |
@@ -209,38 +240,6 @@ static inline void ci_role_stop(struct ci_hdrc *ci) | |||
209 | ci->roles[role]->stop(ci); | 240 | ci->roles[role]->stop(ci); |
210 | } | 241 | } |
211 | 242 | ||
212 | /****************************************************************************** | ||
213 | * REGISTERS | ||
214 | *****************************************************************************/ | ||
215 | /* register size */ | ||
216 | #define REG_BITS (32) | ||
217 | |||
218 | /* register indices */ | ||
219 | enum ci_hw_regs { | ||
220 | CAP_CAPLENGTH, | ||
221 | CAP_HCCPARAMS, | ||
222 | CAP_DCCPARAMS, | ||
223 | CAP_TESTMODE, | ||
224 | CAP_LAST = CAP_TESTMODE, | ||
225 | OP_USBCMD, | ||
226 | OP_USBSTS, | ||
227 | OP_USBINTR, | ||
228 | OP_DEVICEADDR, | ||
229 | OP_ENDPTLISTADDR, | ||
230 | OP_PORTSC, | ||
231 | OP_DEVLC, | ||
232 | OP_OTGSC, | ||
233 | OP_USBMODE, | ||
234 | OP_ENDPTSETUPSTAT, | ||
235 | OP_ENDPTPRIME, | ||
236 | OP_ENDPTFLUSH, | ||
237 | OP_ENDPTSTAT, | ||
238 | OP_ENDPTCOMPLETE, | ||
239 | OP_ENDPTCTRL, | ||
240 | /* endptctrl1..15 follow */ | ||
241 | OP_LAST = OP_ENDPTCTRL + ENDPT_MAX / 2, | ||
242 | }; | ||
243 | |||
244 | /** | 243 | /** |
245 | * hw_read: reads from a hw register | 244 | * hw_read: reads from a hw register |
246 | * @reg: register index | 245 | * @reg: register index |
@@ -253,6 +252,26 @@ static inline u32 hw_read(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask) | |||
253 | return ioread32(ci->hw_bank.regmap[reg]) & mask; | 252 | return ioread32(ci->hw_bank.regmap[reg]) & mask; |
254 | } | 253 | } |
255 | 254 | ||
255 | #ifdef CONFIG_SOC_IMX28 | ||
256 | static inline void imx28_ci_writel(u32 val, volatile void __iomem *addr) | ||
257 | { | ||
258 | __asm__ ("swp %0, %0, [%1]" : : "r"(val), "r"(addr)); | ||
259 | } | ||
260 | #else | ||
261 | static inline void imx28_ci_writel(u32 val, volatile void __iomem *addr) | ||
262 | { | ||
263 | } | ||
264 | #endif | ||
265 | |||
266 | static inline void __hw_write(struct ci_hdrc *ci, u32 val, | ||
267 | void __iomem *addr) | ||
268 | { | ||
269 | if (ci->imx28_write_fix) | ||
270 | imx28_ci_writel(val, addr); | ||
271 | else | ||
272 | iowrite32(val, addr); | ||
273 | } | ||
274 | |||
256 | /** | 275 | /** |
257 | * hw_write: writes to a hw register | 276 | * hw_write: writes to a hw register |
258 | * @reg: register index | 277 | * @reg: register index |
@@ -266,7 +285,7 @@ static inline void hw_write(struct ci_hdrc *ci, enum ci_hw_regs reg, | |||
266 | data = (ioread32(ci->hw_bank.regmap[reg]) & ~mask) | 285 | data = (ioread32(ci->hw_bank.regmap[reg]) & ~mask) |
267 | | (data & mask); | 286 | | (data & mask); |
268 | 287 | ||
269 | iowrite32(data, ci->hw_bank.regmap[reg]); | 288 | __hw_write(ci, data, ci->hw_bank.regmap[reg]); |
270 | } | 289 | } |
271 | 290 | ||
272 | /** | 291 | /** |
@@ -281,7 +300,7 @@ static inline u32 hw_test_and_clear(struct ci_hdrc *ci, enum ci_hw_regs reg, | |||
281 | { | 300 | { |
282 | u32 val = ioread32(ci->hw_bank.regmap[reg]) & mask; | 301 | u32 val = ioread32(ci->hw_bank.regmap[reg]) & mask; |
283 | 302 | ||
284 | iowrite32(val, ci->hw_bank.regmap[reg]); | 303 | __hw_write(ci, val, ci->hw_bank.regmap[reg]); |
285 | return val; | 304 | return val; |
286 | } | 305 | } |
287 | 306 | ||
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index bb5d976e5b81..c00f77257d36 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c | |||
@@ -23,6 +23,26 @@ | |||
23 | #include "ci.h" | 23 | #include "ci.h" |
24 | #include "ci_hdrc_imx.h" | 24 | #include "ci_hdrc_imx.h" |
25 | 25 | ||
26 | #define CI_HDRC_IMX_IMX28_WRITE_FIX BIT(0) | ||
27 | |||
28 | struct ci_hdrc_imx_platform_flag { | ||
29 | unsigned int flags; | ||
30 | }; | ||
31 | |||
32 | static const struct ci_hdrc_imx_platform_flag imx27_usb_data = { | ||
33 | }; | ||
34 | |||
35 | static const struct ci_hdrc_imx_platform_flag imx28_usb_data = { | ||
36 | .flags = CI_HDRC_IMX_IMX28_WRITE_FIX, | ||
37 | }; | ||
38 | |||
39 | static const struct of_device_id ci_hdrc_imx_dt_ids[] = { | ||
40 | { .compatible = "fsl,imx28-usb", .data = &imx28_usb_data}, | ||
41 | { .compatible = "fsl,imx27-usb", .data = &imx27_usb_data}, | ||
42 | { /* sentinel */ } | ||
43 | }; | ||
44 | MODULE_DEVICE_TABLE(of, ci_hdrc_imx_dt_ids); | ||
45 | |||
26 | struct ci_hdrc_imx_data { | 46 | struct ci_hdrc_imx_data { |
27 | struct usb_phy *phy; | 47 | struct usb_phy *phy; |
28 | struct platform_device *ci_pdev; | 48 | struct platform_device *ci_pdev; |
@@ -82,6 +102,9 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) | |||
82 | CI_HDRC_DISABLE_STREAMING, | 102 | CI_HDRC_DISABLE_STREAMING, |
83 | }; | 103 | }; |
84 | int ret; | 104 | int ret; |
105 | const struct of_device_id *of_id = | ||
106 | of_match_device(ci_hdrc_imx_dt_ids, &pdev->dev); | ||
107 | const struct ci_hdrc_imx_platform_flag *imx_platform_flag = of_id->data; | ||
85 | 108 | ||
86 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); | 109 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
87 | if (!data) { | 110 | if (!data) { |
@@ -115,6 +138,9 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) | |||
115 | 138 | ||
116 | pdata.phy = data->phy; | 139 | pdata.phy = data->phy; |
117 | 140 | ||
141 | if (imx_platform_flag->flags & CI_HDRC_IMX_IMX28_WRITE_FIX) | ||
142 | pdata.flags |= CI_HDRC_IMX28_WRITE_FIX; | ||
143 | |||
118 | ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); | 144 | ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
119 | if (ret) | 145 | if (ret) |
120 | goto err_clk; | 146 | goto err_clk; |
@@ -173,12 +199,6 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev) | |||
173 | return 0; | 199 | return 0; |
174 | } | 200 | } |
175 | 201 | ||
176 | static const struct of_device_id ci_hdrc_imx_dt_ids[] = { | ||
177 | { .compatible = "fsl,imx27-usb", }, | ||
178 | { /* sentinel */ } | ||
179 | }; | ||
180 | MODULE_DEVICE_TABLE(of, ci_hdrc_imx_dt_ids); | ||
181 | |||
182 | static struct platform_driver ci_hdrc_imx_driver = { | 202 | static struct platform_driver ci_hdrc_imx_driver = { |
183 | .probe = ci_hdrc_imx_probe, | 203 | .probe = ci_hdrc_imx_probe, |
184 | .remove = ci_hdrc_imx_remove, | 204 | .remove = ci_hdrc_imx_remove, |
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.h b/drivers/usb/chipidea/ci_hdrc_imx.h index c7271590dd0a..996ec93467b2 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.h +++ b/drivers/usb/chipidea/ci_hdrc_imx.h | |||
@@ -9,6 +9,9 @@ | |||
9 | * http://www.gnu.org/copyleft/gpl.html | 9 | * http://www.gnu.org/copyleft/gpl.html |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #ifndef __DRIVER_USB_CHIPIDEA_CI_HDRC_IMX_H | ||
13 | #define __DRIVER_USB_CHIPIDEA_CI_HDRC_IMX_H | ||
14 | |||
12 | struct imx_usbmisc_data { | 15 | struct imx_usbmisc_data { |
13 | int index; | 16 | int index; |
14 | 17 | ||
@@ -18,3 +21,5 @@ struct imx_usbmisc_data { | |||
18 | 21 | ||
19 | int imx_usbmisc_init(struct imx_usbmisc_data *); | 22 | int imx_usbmisc_init(struct imx_usbmisc_data *); |
20 | int imx_usbmisc_init_post(struct imx_usbmisc_data *); | 23 | int imx_usbmisc_init_post(struct imx_usbmisc_data *); |
24 | |||
25 | #endif /* __DRIVER_USB_CHIPIDEA_CI_HDRC_IMX_H */ | ||
diff --git a/drivers/usb/chipidea/ci_hdrc_pci.c b/drivers/usb/chipidea/ci_hdrc_pci.c index d514332ac081..241ae3444fde 100644 --- a/drivers/usb/chipidea/ci_hdrc_pci.c +++ b/drivers/usb/chipidea/ci_hdrc_pci.c | |||
@@ -112,7 +112,7 @@ static void ci_hdrc_pci_remove(struct pci_dev *pdev) | |||
112 | * | 112 | * |
113 | * Check "pci.h" for details | 113 | * Check "pci.h" for details |
114 | */ | 114 | */ |
115 | static DEFINE_PCI_DEVICE_TABLE(ci_hdrc_pci_id_table) = { | 115 | static const struct pci_device_id ci_hdrc_pci_id_table[] = { |
116 | { | 116 | { |
117 | PCI_DEVICE(0x153F, 0x1004), | 117 | PCI_DEVICE(0x153F, 0x1004), |
118 | .driver_data = (kernel_ulong_t)&pci_platdata, | 118 | .driver_data = (kernel_ulong_t)&pci_platdata, |
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 6e73f8cd60e5..33f22bc6ad7f 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c | |||
@@ -75,61 +75,54 @@ | |||
75 | #include "otg.h" | 75 | #include "otg.h" |
76 | 76 | ||
77 | /* Controller register map */ | 77 | /* Controller register map */ |
78 | static uintptr_t ci_regs_nolpm[] = { | 78 | static const u8 ci_regs_nolpm[] = { |
79 | [CAP_CAPLENGTH] = 0x000UL, | 79 | [CAP_CAPLENGTH] = 0x00U, |
80 | [CAP_HCCPARAMS] = 0x008UL, | 80 | [CAP_HCCPARAMS] = 0x08U, |
81 | [CAP_DCCPARAMS] = 0x024UL, | 81 | [CAP_DCCPARAMS] = 0x24U, |
82 | [CAP_TESTMODE] = 0x038UL, | 82 | [CAP_TESTMODE] = 0x38U, |
83 | [OP_USBCMD] = 0x000UL, | 83 | [OP_USBCMD] = 0x00U, |
84 | [OP_USBSTS] = 0x004UL, | 84 | [OP_USBSTS] = 0x04U, |
85 | [OP_USBINTR] = 0x008UL, | 85 | [OP_USBINTR] = 0x08U, |
86 | [OP_DEVICEADDR] = 0x014UL, | 86 | [OP_DEVICEADDR] = 0x14U, |
87 | [OP_ENDPTLISTADDR] = 0x018UL, | 87 | [OP_ENDPTLISTADDR] = 0x18U, |
88 | [OP_PORTSC] = 0x044UL, | 88 | [OP_PORTSC] = 0x44U, |
89 | [OP_DEVLC] = 0x084UL, | 89 | [OP_DEVLC] = 0x84U, |
90 | [OP_OTGSC] = 0x064UL, | 90 | [OP_OTGSC] = 0x64U, |
91 | [OP_USBMODE] = 0x068UL, | 91 | [OP_USBMODE] = 0x68U, |
92 | [OP_ENDPTSETUPSTAT] = 0x06CUL, | 92 | [OP_ENDPTSETUPSTAT] = 0x6CU, |
93 | [OP_ENDPTPRIME] = 0x070UL, | 93 | [OP_ENDPTPRIME] = 0x70U, |
94 | [OP_ENDPTFLUSH] = 0x074UL, | 94 | [OP_ENDPTFLUSH] = 0x74U, |
95 | [OP_ENDPTSTAT] = 0x078UL, | 95 | [OP_ENDPTSTAT] = 0x78U, |
96 | [OP_ENDPTCOMPLETE] = 0x07CUL, | 96 | [OP_ENDPTCOMPLETE] = 0x7CU, |
97 | [OP_ENDPTCTRL] = 0x080UL, | 97 | [OP_ENDPTCTRL] = 0x80U, |
98 | }; | 98 | }; |
99 | 99 | ||
100 | static uintptr_t ci_regs_lpm[] = { | 100 | static const u8 ci_regs_lpm[] = { |
101 | [CAP_CAPLENGTH] = 0x000UL, | 101 | [CAP_CAPLENGTH] = 0x00U, |
102 | [CAP_HCCPARAMS] = 0x008UL, | 102 | [CAP_HCCPARAMS] = 0x08U, |
103 | [CAP_DCCPARAMS] = 0x024UL, | 103 | [CAP_DCCPARAMS] = 0x24U, |
104 | [CAP_TESTMODE] = 0x0FCUL, | 104 | [CAP_TESTMODE] = 0xFCU, |
105 | [OP_USBCMD] = 0x000UL, | 105 | [OP_USBCMD] = 0x00U, |
106 | [OP_USBSTS] = 0x004UL, | 106 | [OP_USBSTS] = 0x04U, |
107 | [OP_USBINTR] = 0x008UL, | 107 | [OP_USBINTR] = 0x08U, |
108 | [OP_DEVICEADDR] = 0x014UL, | 108 | [OP_DEVICEADDR] = 0x14U, |
109 | [OP_ENDPTLISTADDR] = 0x018UL, | 109 | [OP_ENDPTLISTADDR] = 0x18U, |
110 | [OP_PORTSC] = 0x044UL, | 110 | [OP_PORTSC] = 0x44U, |
111 | [OP_DEVLC] = 0x084UL, | 111 | [OP_DEVLC] = 0x84U, |
112 | [OP_OTGSC] = 0x0C4UL, | 112 | [OP_OTGSC] = 0xC4U, |
113 | [OP_USBMODE] = 0x0C8UL, | 113 | [OP_USBMODE] = 0xC8U, |
114 | [OP_ENDPTSETUPSTAT] = 0x0D8UL, | 114 | [OP_ENDPTSETUPSTAT] = 0xD8U, |
115 | [OP_ENDPTPRIME] = 0x0DCUL, | 115 | [OP_ENDPTPRIME] = 0xDCU, |
116 | [OP_ENDPTFLUSH] = 0x0E0UL, | 116 | [OP_ENDPTFLUSH] = 0xE0U, |
117 | [OP_ENDPTSTAT] = 0x0E4UL, | 117 | [OP_ENDPTSTAT] = 0xE4U, |
118 | [OP_ENDPTCOMPLETE] = 0x0E8UL, | 118 | [OP_ENDPTCOMPLETE] = 0xE8U, |
119 | [OP_ENDPTCTRL] = 0x0ECUL, | 119 | [OP_ENDPTCTRL] = 0xECU, |
120 | }; | 120 | }; |
121 | 121 | ||
122 | static int hw_alloc_regmap(struct ci_hdrc *ci, bool is_lpm) | 122 | static int hw_alloc_regmap(struct ci_hdrc *ci, bool is_lpm) |
123 | { | 123 | { |
124 | int i; | 124 | int i; |
125 | 125 | ||
126 | kfree(ci->hw_bank.regmap); | ||
127 | |||
128 | ci->hw_bank.regmap = kzalloc((OP_LAST + 1) * sizeof(void *), | ||
129 | GFP_KERNEL); | ||
130 | if (!ci->hw_bank.regmap) | ||
131 | return -ENOMEM; | ||
132 | |||
133 | for (i = 0; i < OP_ENDPTCTRL; i++) | 126 | for (i = 0; i < OP_ENDPTCTRL; i++) |
134 | ci->hw_bank.regmap[i] = | 127 | ci->hw_bank.regmap[i] = |
135 | (i <= CAP_LAST ? ci->hw_bank.cap : ci->hw_bank.op) + | 128 | (i <= CAP_LAST ? ci->hw_bank.cap : ci->hw_bank.op) + |
@@ -208,7 +201,8 @@ static int hw_device_init(struct ci_hdrc *ci, void __iomem *base) | |||
208 | reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >> | 201 | reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >> |
209 | __ffs(HCCPARAMS_LEN); | 202 | __ffs(HCCPARAMS_LEN); |
210 | ci->hw_bank.lpm = reg; | 203 | ci->hw_bank.lpm = reg; |
211 | hw_alloc_regmap(ci, !!reg); | 204 | if (reg) |
205 | hw_alloc_regmap(ci, !!reg); | ||
212 | ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs; | 206 | ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs; |
213 | ci->hw_bank.size += OP_LAST; | 207 | ci->hw_bank.size += OP_LAST; |
214 | ci->hw_bank.size /= sizeof(u32); | 208 | ci->hw_bank.size /= sizeof(u32); |
@@ -242,7 +236,7 @@ static int hw_device_init(struct ci_hdrc *ci, void __iomem *base) | |||
242 | 236 | ||
243 | static void hw_phymode_configure(struct ci_hdrc *ci) | 237 | static void hw_phymode_configure(struct ci_hdrc *ci) |
244 | { | 238 | { |
245 | u32 portsc, lpm, sts; | 239 | u32 portsc, lpm, sts = 0; |
246 | 240 | ||
247 | switch (ci->platdata->phy_mode) { | 241 | switch (ci->platdata->phy_mode) { |
248 | case USBPHY_INTERFACE_MODE_UTMI: | 242 | case USBPHY_INTERFACE_MODE_UTMI: |
@@ -272,10 +266,12 @@ static void hw_phymode_configure(struct ci_hdrc *ci) | |||
272 | 266 | ||
273 | if (ci->hw_bank.lpm) { | 267 | if (ci->hw_bank.lpm) { |
274 | hw_write(ci, OP_DEVLC, DEVLC_PTS(7) | DEVLC_PTW, lpm); | 268 | hw_write(ci, OP_DEVLC, DEVLC_PTS(7) | DEVLC_PTW, lpm); |
275 | hw_write(ci, OP_DEVLC, DEVLC_STS, sts); | 269 | if (sts) |
270 | hw_write(ci, OP_DEVLC, DEVLC_STS, DEVLC_STS); | ||
276 | } else { | 271 | } else { |
277 | hw_write(ci, OP_PORTSC, PORTSC_PTS(7) | PORTSC_PTW, portsc); | 272 | hw_write(ci, OP_PORTSC, PORTSC_PTS(7) | PORTSC_PTW, portsc); |
278 | hw_write(ci, OP_PORTSC, PORTSC_STS, sts); | 273 | if (sts) |
274 | hw_write(ci, OP_PORTSC, PORTSC_STS, PORTSC_STS); | ||
279 | } | 275 | } |
280 | } | 276 | } |
281 | 277 | ||
@@ -554,6 +550,8 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
554 | 550 | ||
555 | ci->dev = dev; | 551 | ci->dev = dev; |
556 | ci->platdata = dev->platform_data; | 552 | ci->platdata = dev->platform_data; |
553 | ci->imx28_write_fix = !!(ci->platdata->flags & | ||
554 | CI_HDRC_IMX28_WRITE_FIX); | ||
557 | 555 | ||
558 | ret = hw_device_init(ci, base); | 556 | ret = hw_device_init(ci, base); |
559 | if (ret < 0) { | 557 | if (ret < 0) { |
@@ -561,6 +559,8 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
561 | return -ENODEV; | 559 | return -ENODEV; |
562 | } | 560 | } |
563 | 561 | ||
562 | hw_phymode_configure(ci); | ||
563 | |||
564 | ret = ci_usb_phy_init(ci); | 564 | ret = ci_usb_phy_init(ci); |
565 | if (ret) { | 565 | if (ret) { |
566 | dev_err(dev, "unable to init phy: %d\n", ret); | 566 | dev_err(dev, "unable to init phy: %d\n", ret); |
@@ -578,8 +578,6 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
578 | 578 | ||
579 | ci_get_otg_capable(ci); | 579 | ci_get_otg_capable(ci); |
580 | 580 | ||
581 | hw_phymode_configure(ci); | ||
582 | |||
583 | dr_mode = ci->platdata->dr_mode; | 581 | dr_mode = ci->platdata->dr_mode; |
584 | /* initialize role(s) before the interrupt is requested */ | 582 | /* initialize role(s) before the interrupt is requested */ |
585 | if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { | 583 | if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { |
@@ -680,7 +678,6 @@ static int ci_hdrc_remove(struct platform_device *pdev) | |||
680 | ci_role_destroy(ci); | 678 | ci_role_destroy(ci); |
681 | ci_hdrc_enter_lpm(ci, true); | 679 | ci_hdrc_enter_lpm(ci, true); |
682 | ci_usb_phy_destroy(ci); | 680 | ci_usb_phy_destroy(ci); |
683 | kfree(ci->hw_bank.regmap); | ||
684 | 681 | ||
685 | return 0; | 682 | return 0; |
686 | } | 683 | } |
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index 526cd77563d8..a8ac6c16dac9 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c | |||
@@ -65,6 +65,7 @@ static int host_start(struct ci_hdrc *ci) | |||
65 | ehci->caps = ci->hw_bank.cap; | 65 | ehci->caps = ci->hw_bank.cap; |
66 | ehci->has_hostpc = ci->hw_bank.lpm; | 66 | ehci->has_hostpc = ci->hw_bank.lpm; |
67 | ehci->has_tdi_phy_lpm = ci->hw_bank.lpm; | 67 | ehci->has_tdi_phy_lpm = ci->hw_bank.lpm; |
68 | ehci->imx28_write_fix = ci->imx28_write_fix; | ||
68 | 69 | ||
69 | if (ci->platdata->reg_vbus) { | 70 | if (ci->platdata->reg_vbus) { |
70 | ret = regulator_enable(ci->platdata->reg_vbus); | 71 | ret = regulator_enable(ci->platdata->reg_vbus); |
diff --git a/drivers/usb/chipidea/otg.h b/drivers/usb/chipidea/otg.h index 2d9f090733bc..449bee07f4fe 100644 --- a/drivers/usb/chipidea/otg.h +++ b/drivers/usb/chipidea/otg.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2013 Freescale Semiconductor, Inc. | 2 | * Copyright (C) 2013-2014 Freescale Semiconductor, Inc. |
3 | * | 3 | * |
4 | * Author: Peter Chen | 4 | * Author: Peter Chen |
5 | * | 5 | * |
@@ -19,12 +19,12 @@ static inline void ci_clear_otg_interrupt(struct ci_hdrc *ci, u32 bits) | |||
19 | 19 | ||
20 | static inline void ci_enable_otg_interrupt(struct ci_hdrc *ci, u32 bits) | 20 | static inline void ci_enable_otg_interrupt(struct ci_hdrc *ci, u32 bits) |
21 | { | 21 | { |
22 | hw_write(ci, OP_OTGSC, bits, bits); | 22 | hw_write(ci, OP_OTGSC, bits | OTGSC_INT_STATUS_BITS, bits); |
23 | } | 23 | } |
24 | 24 | ||
25 | static inline void ci_disable_otg_interrupt(struct ci_hdrc *ci, u32 bits) | 25 | static inline void ci_disable_otg_interrupt(struct ci_hdrc *ci, u32 bits) |
26 | { | 26 | { |
27 | hw_write(ci, OP_OTGSC, bits, 0); | 27 | hw_write(ci, OP_OTGSC, bits | OTGSC_INT_STATUS_BITS, 0); |
28 | } | 28 | } |
29 | 29 | ||
30 | int ci_hdrc_otg_init(struct ci_hdrc *ci); | 30 | int ci_hdrc_otg_init(struct ci_hdrc *ci); |
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 69d20fbb38a2..80de2f88ed2c 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c | |||
@@ -393,6 +393,14 @@ static int add_td_to_list(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq, | |||
393 | node->ptr->token = cpu_to_le32(length << __ffs(TD_TOTAL_BYTES)); | 393 | node->ptr->token = cpu_to_le32(length << __ffs(TD_TOTAL_BYTES)); |
394 | node->ptr->token &= cpu_to_le32(TD_TOTAL_BYTES); | 394 | node->ptr->token &= cpu_to_le32(TD_TOTAL_BYTES); |
395 | node->ptr->token |= cpu_to_le32(TD_STATUS_ACTIVE); | 395 | node->ptr->token |= cpu_to_le32(TD_STATUS_ACTIVE); |
396 | if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == TX) { | ||
397 | u32 mul = hwreq->req.length / hwep->ep.maxpacket; | ||
398 | |||
399 | if (hwreq->req.length == 0 | ||
400 | || hwreq->req.length % hwep->ep.maxpacket) | ||
401 | mul++; | ||
402 | node->ptr->token |= mul << __ffs(TD_MULTO); | ||
403 | } | ||
396 | 404 | ||
397 | temp = (u32) (hwreq->req.dma + hwreq->req.actual); | 405 | temp = (u32) (hwreq->req.dma + hwreq->req.actual); |
398 | if (length) { | 406 | if (length) { |
@@ -515,10 +523,11 @@ static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) | |||
515 | hwep->qh.ptr->td.token &= | 523 | hwep->qh.ptr->td.token &= |
516 | cpu_to_le32(~(TD_STATUS_HALTED|TD_STATUS_ACTIVE)); | 524 | cpu_to_le32(~(TD_STATUS_HALTED|TD_STATUS_ACTIVE)); |
517 | 525 | ||
518 | if (hwep->type == USB_ENDPOINT_XFER_ISOC) { | 526 | if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == RX) { |
519 | u32 mul = hwreq->req.length / hwep->ep.maxpacket; | 527 | u32 mul = hwreq->req.length / hwep->ep.maxpacket; |
520 | 528 | ||
521 | if (hwreq->req.length % hwep->ep.maxpacket) | 529 | if (hwreq->req.length == 0 |
530 | || hwreq->req.length % hwep->ep.maxpacket) | ||
522 | mul++; | 531 | mul++; |
523 | hwep->qh.ptr->cap |= mul << __ffs(QH_MULT); | 532 | hwep->qh.ptr->cap |= mul << __ffs(QH_MULT); |
524 | } | 533 | } |
@@ -1173,6 +1182,12 @@ static int ep_enable(struct usb_ep *ep, | |||
1173 | if (hwep->num) | 1182 | if (hwep->num) |
1174 | cap |= QH_ZLT; | 1183 | cap |= QH_ZLT; |
1175 | cap |= (hwep->ep.maxpacket << __ffs(QH_MAX_PKT)) & QH_MAX_PKT; | 1184 | cap |= (hwep->ep.maxpacket << __ffs(QH_MAX_PKT)) & QH_MAX_PKT; |
1185 | /* | ||
1186 | * For ISO-TX, we set mult at QH as the largest value, and use | ||
1187 | * MultO at TD as real mult value. | ||
1188 | */ | ||
1189 | if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == TX) | ||
1190 | cap |= 3 << __ffs(QH_MULT); | ||
1176 | 1191 | ||
1177 | hwep->qh.ptr->cap = cpu_to_le32(cap); | 1192 | hwep->qh.ptr->cap = cpu_to_le32(cap); |
1178 | 1193 | ||
@@ -1566,7 +1581,7 @@ static int init_eps(struct ci_hdrc *ci) | |||
1566 | * eps, maxP is set by epautoconfig() called | 1581 | * eps, maxP is set by epautoconfig() called |
1567 | * by gadget layer | 1582 | * by gadget layer |
1568 | */ | 1583 | */ |
1569 | hwep->ep.maxpacket = (unsigned short)~0; | 1584 | usb_ep_set_maxpacket_limit(&hwep->ep, (unsigned short)~0); |
1570 | 1585 | ||
1571 | INIT_LIST_HEAD(&hwep->qh.queue); | 1586 | INIT_LIST_HEAD(&hwep->qh.queue); |
1572 | hwep->qh.ptr = dma_pool_alloc(ci->qh_pool, GFP_KERNEL, | 1587 | hwep->qh.ptr = dma_pool_alloc(ci->qh_pool, GFP_KERNEL, |
@@ -1586,7 +1601,7 @@ static int init_eps(struct ci_hdrc *ci) | |||
1586 | else | 1601 | else |
1587 | ci->ep0in = hwep; | 1602 | ci->ep0in = hwep; |
1588 | 1603 | ||
1589 | hwep->ep.maxpacket = CTRL_PAYLOAD_MAX; | 1604 | usb_ep_set_maxpacket_limit(&hwep->ep, CTRL_PAYLOAD_MAX); |
1590 | continue; | 1605 | continue; |
1591 | } | 1606 | } |
1592 | 1607 | ||
diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index 8a1094b1182f..cd061abe3507 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c | |||
@@ -21,6 +21,10 @@ | |||
21 | #define MX25_USB_PHY_CTRL_OFFSET 0x08 | 21 | #define MX25_USB_PHY_CTRL_OFFSET 0x08 |
22 | #define MX25_BM_EXTERNAL_VBUS_DIVIDER BIT(23) | 22 | #define MX25_BM_EXTERNAL_VBUS_DIVIDER BIT(23) |
23 | 23 | ||
24 | #define MX27_H1_PM_BIT BIT(8) | ||
25 | #define MX27_H2_PM_BIT BIT(16) | ||
26 | #define MX27_OTG_PM_BIT BIT(24) | ||
27 | |||
24 | #define MX53_USB_OTG_PHY_CTRL_0_OFFSET 0x08 | 28 | #define MX53_USB_OTG_PHY_CTRL_0_OFFSET 0x08 |
25 | #define MX53_USB_UH2_CTRL_OFFSET 0x14 | 29 | #define MX53_USB_UH2_CTRL_OFFSET 0x14 |
26 | #define MX53_USB_UH3_CTRL_OFFSET 0x18 | 30 | #define MX53_USB_UH3_CTRL_OFFSET 0x18 |
@@ -68,6 +72,36 @@ static int usbmisc_imx25_post(struct imx_usbmisc_data *data) | |||
68 | return 0; | 72 | return 0; |
69 | } | 73 | } |
70 | 74 | ||
75 | static int usbmisc_imx27_init(struct imx_usbmisc_data *data) | ||
76 | { | ||
77 | unsigned long flags; | ||
78 | u32 val; | ||
79 | |||
80 | switch (data->index) { | ||
81 | case 0: | ||
82 | val = MX27_OTG_PM_BIT; | ||
83 | break; | ||
84 | case 1: | ||
85 | val = MX27_H1_PM_BIT; | ||
86 | break; | ||
87 | case 2: | ||
88 | val = MX27_H2_PM_BIT; | ||
89 | break; | ||
90 | default: | ||
91 | return -EINVAL; | ||
92 | }; | ||
93 | |||
94 | spin_lock_irqsave(&usbmisc->lock, flags); | ||
95 | if (data->disable_oc) | ||
96 | val = readl(usbmisc->base) | val; | ||
97 | else | ||
98 | val = readl(usbmisc->base) & ~val; | ||
99 | writel(val, usbmisc->base); | ||
100 | spin_unlock_irqrestore(&usbmisc->lock, flags); | ||
101 | |||
102 | return 0; | ||
103 | } | ||
104 | |||
71 | static int usbmisc_imx53_init(struct imx_usbmisc_data *data) | 105 | static int usbmisc_imx53_init(struct imx_usbmisc_data *data) |
72 | { | 106 | { |
73 | void __iomem *reg = NULL; | 107 | void __iomem *reg = NULL; |
@@ -128,6 +162,10 @@ static const struct usbmisc_ops imx25_usbmisc_ops = { | |||
128 | .post = usbmisc_imx25_post, | 162 | .post = usbmisc_imx25_post, |
129 | }; | 163 | }; |
130 | 164 | ||
165 | static const struct usbmisc_ops imx27_usbmisc_ops = { | ||
166 | .init = usbmisc_imx27_init, | ||
167 | }; | ||
168 | |||
131 | static const struct usbmisc_ops imx53_usbmisc_ops = { | 169 | static const struct usbmisc_ops imx53_usbmisc_ops = { |
132 | .init = usbmisc_imx53_init, | 170 | .init = usbmisc_imx53_init, |
133 | }; | 171 | }; |
@@ -162,6 +200,14 @@ static const struct of_device_id usbmisc_imx_dt_ids[] = { | |||
162 | .data = &imx25_usbmisc_ops, | 200 | .data = &imx25_usbmisc_ops, |
163 | }, | 201 | }, |
164 | { | 202 | { |
203 | .compatible = "fsl,imx27-usbmisc", | ||
204 | .data = &imx27_usbmisc_ops, | ||
205 | }, | ||
206 | { | ||
207 | .compatible = "fsl,imx51-usbmisc", | ||
208 | .data = &imx53_usbmisc_ops, | ||
209 | }, | ||
210 | { | ||
165 | .compatible = "fsl,imx53-usbmisc", | 211 | .compatible = "fsl,imx53-usbmisc", |
166 | .data = &imx53_usbmisc_ops, | 212 | .data = &imx53_usbmisc_ops, |
167 | }, | 213 | }, |
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index e8404319ca68..900f7ff805ee 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c | |||
@@ -262,6 +262,7 @@ static void acm_ctrl_irq(struct urb *urb) | |||
262 | struct usb_cdc_notification *dr = urb->transfer_buffer; | 262 | struct usb_cdc_notification *dr = urb->transfer_buffer; |
263 | unsigned char *data; | 263 | unsigned char *data; |
264 | int newctrl; | 264 | int newctrl; |
265 | int difference; | ||
265 | int retval; | 266 | int retval; |
266 | int status = urb->status; | 267 | int status = urb->status; |
267 | 268 | ||
@@ -302,20 +303,31 @@ static void acm_ctrl_irq(struct urb *urb) | |||
302 | tty_port_tty_hangup(&acm->port, false); | 303 | tty_port_tty_hangup(&acm->port, false); |
303 | } | 304 | } |
304 | 305 | ||
306 | difference = acm->ctrlin ^ newctrl; | ||
307 | spin_lock(&acm->read_lock); | ||
305 | acm->ctrlin = newctrl; | 308 | acm->ctrlin = newctrl; |
309 | acm->oldcount = acm->iocount; | ||
310 | |||
311 | if (difference & ACM_CTRL_DSR) | ||
312 | acm->iocount.dsr++; | ||
313 | if (difference & ACM_CTRL_BRK) | ||
314 | acm->iocount.brk++; | ||
315 | if (difference & ACM_CTRL_RI) | ||
316 | acm->iocount.rng++; | ||
317 | if (difference & ACM_CTRL_DCD) | ||
318 | acm->iocount.dcd++; | ||
319 | if (difference & ACM_CTRL_FRAMING) | ||
320 | acm->iocount.frame++; | ||
321 | if (difference & ACM_CTRL_PARITY) | ||
322 | acm->iocount.parity++; | ||
323 | if (difference & ACM_CTRL_OVERRUN) | ||
324 | acm->iocount.overrun++; | ||
325 | spin_unlock(&acm->read_lock); | ||
326 | |||
327 | if (difference) | ||
328 | wake_up_all(&acm->wioctl); | ||
306 | 329 | ||
307 | dev_dbg(&acm->control->dev, | 330 | break; |
308 | "%s - input control lines: dcd%c dsr%c break%c " | ||
309 | "ring%c framing%c parity%c overrun%c\n", | ||
310 | __func__, | ||
311 | acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', | ||
312 | acm->ctrlin & ACM_CTRL_DSR ? '+' : '-', | ||
313 | acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', | ||
314 | acm->ctrlin & ACM_CTRL_RI ? '+' : '-', | ||
315 | acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-', | ||
316 | acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-', | ||
317 | acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-'); | ||
318 | break; | ||
319 | 331 | ||
320 | default: | 332 | default: |
321 | dev_dbg(&acm->control->dev, | 333 | dev_dbg(&acm->control->dev, |
@@ -796,6 +808,72 @@ static int set_serial_info(struct acm *acm, | |||
796 | return retval; | 808 | return retval; |
797 | } | 809 | } |
798 | 810 | ||
811 | static int wait_serial_change(struct acm *acm, unsigned long arg) | ||
812 | { | ||
813 | int rv = 0; | ||
814 | DECLARE_WAITQUEUE(wait, current); | ||
815 | struct async_icount old, new; | ||
816 | |||
817 | if (arg & (TIOCM_DSR | TIOCM_RI | TIOCM_CD )) | ||
818 | return -EINVAL; | ||
819 | do { | ||
820 | spin_lock_irq(&acm->read_lock); | ||
821 | old = acm->oldcount; | ||
822 | new = acm->iocount; | ||
823 | acm->oldcount = new; | ||
824 | spin_unlock_irq(&acm->read_lock); | ||
825 | |||
826 | if ((arg & TIOCM_DSR) && | ||
827 | old.dsr != new.dsr) | ||
828 | break; | ||
829 | if ((arg & TIOCM_CD) && | ||
830 | old.dcd != new.dcd) | ||
831 | break; | ||
832 | if ((arg & TIOCM_RI) && | ||
833 | old.rng != new.rng) | ||
834 | break; | ||
835 | |||
836 | add_wait_queue(&acm->wioctl, &wait); | ||
837 | set_current_state(TASK_INTERRUPTIBLE); | ||
838 | schedule(); | ||
839 | remove_wait_queue(&acm->wioctl, &wait); | ||
840 | if (acm->disconnected) { | ||
841 | if (arg & TIOCM_CD) | ||
842 | break; | ||
843 | else | ||
844 | rv = -ENODEV; | ||
845 | } else { | ||
846 | if (signal_pending(current)) | ||
847 | rv = -ERESTARTSYS; | ||
848 | } | ||
849 | } while (!rv); | ||
850 | |||
851 | |||
852 | |||
853 | return rv; | ||
854 | } | ||
855 | |||
856 | static int get_serial_usage(struct acm *acm, | ||
857 | struct serial_icounter_struct __user *count) | ||
858 | { | ||
859 | struct serial_icounter_struct icount; | ||
860 | int rv = 0; | ||
861 | |||
862 | memset(&icount, 0, sizeof(icount)); | ||
863 | icount.dsr = acm->iocount.dsr; | ||
864 | icount.rng = acm->iocount.rng; | ||
865 | icount.dcd = acm->iocount.dcd; | ||
866 | icount.frame = acm->iocount.frame; | ||
867 | icount.overrun = acm->iocount.overrun; | ||
868 | icount.parity = acm->iocount.parity; | ||
869 | icount.brk = acm->iocount.brk; | ||
870 | |||
871 | if (copy_to_user(count, &icount, sizeof(icount)) > 0) | ||
872 | rv = -EFAULT; | ||
873 | |||
874 | return rv; | ||
875 | } | ||
876 | |||
799 | static int acm_tty_ioctl(struct tty_struct *tty, | 877 | static int acm_tty_ioctl(struct tty_struct *tty, |
800 | unsigned int cmd, unsigned long arg) | 878 | unsigned int cmd, unsigned long arg) |
801 | { | 879 | { |
@@ -809,6 +887,18 @@ static int acm_tty_ioctl(struct tty_struct *tty, | |||
809 | case TIOCSSERIAL: | 887 | case TIOCSSERIAL: |
810 | rv = set_serial_info(acm, (struct serial_struct __user *) arg); | 888 | rv = set_serial_info(acm, (struct serial_struct __user *) arg); |
811 | break; | 889 | break; |
890 | case TIOCMIWAIT: | ||
891 | rv = usb_autopm_get_interface(acm->control); | ||
892 | if (rv < 0) { | ||
893 | rv = -EIO; | ||
894 | break; | ||
895 | } | ||
896 | rv = wait_serial_change(acm, arg); | ||
897 | usb_autopm_put_interface(acm->control); | ||
898 | break; | ||
899 | case TIOCGICOUNT: | ||
900 | rv = get_serial_usage(acm, (struct serial_icounter_struct __user *) arg); | ||
901 | break; | ||
812 | } | 902 | } |
813 | 903 | ||
814 | return rv; | 904 | return rv; |
@@ -1167,6 +1257,7 @@ made_compressed_probe: | |||
1167 | acm->readsize = readsize; | 1257 | acm->readsize = readsize; |
1168 | acm->rx_buflimit = num_rx_buf; | 1258 | acm->rx_buflimit = num_rx_buf; |
1169 | INIT_WORK(&acm->work, acm_softint); | 1259 | INIT_WORK(&acm->work, acm_softint); |
1260 | init_waitqueue_head(&acm->wioctl); | ||
1170 | spin_lock_init(&acm->write_lock); | 1261 | spin_lock_init(&acm->write_lock); |
1171 | spin_lock_init(&acm->read_lock); | 1262 | spin_lock_init(&acm->read_lock); |
1172 | mutex_init(&acm->mutex); | 1263 | mutex_init(&acm->mutex); |
@@ -1383,6 +1474,7 @@ static void acm_disconnect(struct usb_interface *intf) | |||
1383 | device_remove_file(&acm->control->dev, | 1474 | device_remove_file(&acm->control->dev, |
1384 | &dev_attr_iCountryCodeRelDate); | 1475 | &dev_attr_iCountryCodeRelDate); |
1385 | } | 1476 | } |
1477 | wake_up_all(&acm->wioctl); | ||
1386 | device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); | 1478 | device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); |
1387 | usb_set_intfdata(acm->control, NULL); | 1479 | usb_set_intfdata(acm->control, NULL); |
1388 | usb_set_intfdata(acm->data, NULL); | 1480 | usb_set_intfdata(acm->data, NULL); |
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h index 0f76e4af600e..e38dc785808f 100644 --- a/drivers/usb/class/cdc-acm.h +++ b/drivers/usb/class/cdc-acm.h | |||
@@ -106,6 +106,9 @@ struct acm { | |||
106 | struct work_struct work; /* work queue entry for line discipline waking up */ | 106 | struct work_struct work; /* work queue entry for line discipline waking up */ |
107 | unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */ | 107 | unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */ |
108 | unsigned int ctrlout; /* output control lines (DTR, RTS) */ | 108 | unsigned int ctrlout; /* output control lines (DTR, RTS) */ |
109 | struct async_icount iocount; /* counters for control line changes */ | ||
110 | struct async_icount oldcount; /* for comparison of counter */ | ||
111 | wait_queue_head_t wioctl; /* for ioctl */ | ||
109 | unsigned int writesize; /* max packet size for the output bulk endpoint */ | 112 | unsigned int writesize; /* max packet size for the output bulk endpoint */ |
110 | unsigned int readsize,ctrlsize; /* buffer sizes for freeing */ | 113 | unsigned int readsize,ctrlsize; /* buffer sizes for freeing */ |
111 | unsigned int minor; /* acm minor number */ | 114 | unsigned int minor; /* acm minor number */ |
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c index 0b23a8639311..a051a7a2b1bd 100644 --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c | |||
@@ -432,6 +432,38 @@ outnl: | |||
432 | return rv < 0 ? rv : count; | 432 | return rv < 0 ? rv : count; |
433 | } | 433 | } |
434 | 434 | ||
435 | /* | ||
436 | * clear WDM_READ flag and possibly submit the read urb if resp_count | ||
437 | * is non-zero. | ||
438 | * | ||
439 | * Called with desc->iuspin locked | ||
440 | */ | ||
441 | static int clear_wdm_read_flag(struct wdm_device *desc) | ||
442 | { | ||
443 | int rv = 0; | ||
444 | |||
445 | clear_bit(WDM_READ, &desc->flags); | ||
446 | |||
447 | /* submit read urb only if the device is waiting for it */ | ||
448 | if (!desc->resp_count || !--desc->resp_count) | ||
449 | goto out; | ||
450 | |||
451 | set_bit(WDM_RESPONDING, &desc->flags); | ||
452 | spin_unlock_irq(&desc->iuspin); | ||
453 | rv = usb_submit_urb(desc->response, GFP_KERNEL); | ||
454 | spin_lock_irq(&desc->iuspin); | ||
455 | if (rv) { | ||
456 | dev_err(&desc->intf->dev, | ||
457 | "usb_submit_urb failed with result %d\n", rv); | ||
458 | |||
459 | /* make sure the next notification trigger a submit */ | ||
460 | clear_bit(WDM_RESPONDING, &desc->flags); | ||
461 | desc->resp_count = 0; | ||
462 | } | ||
463 | out: | ||
464 | return rv; | ||
465 | } | ||
466 | |||
435 | static ssize_t wdm_read | 467 | static ssize_t wdm_read |
436 | (struct file *file, char __user *buffer, size_t count, loff_t *ppos) | 468 | (struct file *file, char __user *buffer, size_t count, loff_t *ppos) |
437 | { | 469 | { |
@@ -503,8 +535,10 @@ retry: | |||
503 | 535 | ||
504 | if (!desc->reslength) { /* zero length read */ | 536 | if (!desc->reslength) { /* zero length read */ |
505 | dev_dbg(&desc->intf->dev, "%s: zero length - clearing WDM_READ\n", __func__); | 537 | dev_dbg(&desc->intf->dev, "%s: zero length - clearing WDM_READ\n", __func__); |
506 | clear_bit(WDM_READ, &desc->flags); | 538 | rv = clear_wdm_read_flag(desc); |
507 | spin_unlock_irq(&desc->iuspin); | 539 | spin_unlock_irq(&desc->iuspin); |
540 | if (rv < 0) | ||
541 | goto err; | ||
508 | goto retry; | 542 | goto retry; |
509 | } | 543 | } |
510 | cntr = desc->length; | 544 | cntr = desc->length; |
@@ -526,37 +560,9 @@ retry: | |||
526 | 560 | ||
527 | desc->length -= cntr; | 561 | desc->length -= cntr; |
528 | /* in case we had outstanding data */ | 562 | /* in case we had outstanding data */ |
529 | if (!desc->length) { | 563 | if (!desc->length) |
530 | clear_bit(WDM_READ, &desc->flags); | 564 | clear_wdm_read_flag(desc); |
531 | 565 | spin_unlock_irq(&desc->iuspin); | |
532 | if (--desc->resp_count) { | ||
533 | set_bit(WDM_RESPONDING, &desc->flags); | ||
534 | spin_unlock_irq(&desc->iuspin); | ||
535 | |||
536 | rv = usb_submit_urb(desc->response, GFP_KERNEL); | ||
537 | if (rv) { | ||
538 | dev_err(&desc->intf->dev, | ||
539 | "%s: usb_submit_urb failed with result %d\n", | ||
540 | __func__, rv); | ||
541 | spin_lock_irq(&desc->iuspin); | ||
542 | clear_bit(WDM_RESPONDING, &desc->flags); | ||
543 | spin_unlock_irq(&desc->iuspin); | ||
544 | |||
545 | if (rv == -ENOMEM) { | ||
546 | rv = schedule_work(&desc->rxwork); | ||
547 | if (rv) | ||
548 | dev_err(&desc->intf->dev, "Cannot schedule work\n"); | ||
549 | } else { | ||
550 | spin_lock_irq(&desc->iuspin); | ||
551 | desc->resp_count = 0; | ||
552 | spin_unlock_irq(&desc->iuspin); | ||
553 | } | ||
554 | } | ||
555 | } else | ||
556 | spin_unlock_irq(&desc->iuspin); | ||
557 | } else | ||
558 | spin_unlock_irq(&desc->iuspin); | ||
559 | |||
560 | rv = cntr; | 566 | rv = cntr; |
561 | 567 | ||
562 | err: | 568 | err: |
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c index d4c47d5d7625..0924ee40a966 100644 --- a/drivers/usb/class/usblp.c +++ b/drivers/usb/class/usblp.c | |||
@@ -52,7 +52,6 @@ | |||
52 | #include <linux/sched.h> | 52 | #include <linux/sched.h> |
53 | #include <linux/signal.h> | 53 | #include <linux/signal.h> |
54 | #include <linux/poll.h> | 54 | #include <linux/poll.h> |
55 | #include <linux/init.h> | ||
56 | #include <linux/slab.h> | 55 | #include <linux/slab.h> |
57 | #include <linux/lp.h> | 56 | #include <linux/lp.h> |
58 | #include <linux/mutex.h> | 57 | #include <linux/mutex.h> |
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c index 09de131ee0cb..cfbec9c7e09e 100644 --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c | |||
@@ -21,7 +21,6 @@ | |||
21 | 21 | ||
22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
23 | 23 | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/module.h> | 24 | #include <linux/module.h> |
26 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
27 | #include <linux/fs.h> | 26 | #include <linux/fs.h> |
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index 5e847ad2f58a..2f6f93220046 100644 --- a/drivers/usb/core/Makefile +++ b/drivers/usb/core/Makefile | |||
@@ -2,8 +2,6 @@ | |||
2 | # Makefile for USB Core files and filesystem | 2 | # Makefile for USB Core files and filesystem |
3 | # | 3 | # |
4 | 4 | ||
5 | ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG | ||
6 | |||
7 | usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o | 5 | usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o |
8 | usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o | 6 | usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o |
9 | usbcore-y += devio.o notify.o generic.o quirks.o devices.o | 7 | usbcore-y += devio.o notify.o generic.o quirks.o devices.o |
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c index 23559746be92..684ef70dc09d 100644 --- a/drivers/usb/core/buffer.c +++ b/drivers/usb/core/buffer.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * DMA memory management for framework level HCD code (hc_driver) | 2 | * DMA memory management for framework level HCD code (hc_driver) |
3 | * | 3 | * |
4 | * This implementation plugs in through generic "usb_bus" level methods, | 4 | * This implementation plugs in through generic "usb_bus" level methods, |
5 | * and should work with all USB controllers, regardles of bus type. | 5 | * and should work with all USB controllers, regardless of bus type. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c index a6b2cabe7930..8d72f0c65937 100644 --- a/drivers/usb/core/config.c +++ b/drivers/usb/core/config.c | |||
@@ -3,7 +3,6 @@ | |||
3 | #include <linux/usb/hcd.h> | 3 | #include <linux/usb/hcd.h> |
4 | #include <linux/usb/quirks.h> | 4 | #include <linux/usb/quirks.h> |
5 | #include <linux/module.h> | 5 | #include <linux/module.h> |
6 | #include <linux/init.h> | ||
7 | #include <linux/slab.h> | 6 | #include <linux/slab.h> |
8 | #include <linux/device.h> | 7 | #include <linux/device.h> |
9 | #include <asm/byteorder.h> | 8 | #include <asm/byteorder.h> |
@@ -651,10 +650,6 @@ void usb_destroy_configuration(struct usb_device *dev) | |||
651 | * | 650 | * |
652 | * hub-only!! ... and only in reset path, or usb_new_device() | 651 | * hub-only!! ... and only in reset path, or usb_new_device() |
653 | * (used by real hubs and virtual root hubs) | 652 | * (used by real hubs and virtual root hubs) |
654 | * | ||
655 | * NOTE: if this is a WUSB device and is not authorized, we skip the | ||
656 | * whole thing. A non-authorized USB device has no | ||
657 | * configurations. | ||
658 | */ | 653 | */ |
659 | int usb_get_configuration(struct usb_device *dev) | 654 | int usb_get_configuration(struct usb_device *dev) |
660 | { | 655 | { |
@@ -666,8 +661,6 @@ int usb_get_configuration(struct usb_device *dev) | |||
666 | struct usb_config_descriptor *desc; | 661 | struct usb_config_descriptor *desc; |
667 | 662 | ||
668 | cfgno = 0; | 663 | cfgno = 0; |
669 | if (dev->authorized == 0) /* Not really an error */ | ||
670 | goto out_not_authorized; | ||
671 | result = -ENOMEM; | 664 | result = -ENOMEM; |
672 | if (ncfg > USB_MAXCONFIG) { | 665 | if (ncfg > USB_MAXCONFIG) { |
673 | dev_warn(ddev, "too many configurations: %d, " | 666 | dev_warn(ddev, "too many configurations: %d, " |
@@ -751,7 +744,6 @@ int usb_get_configuration(struct usb_device *dev) | |||
751 | 744 | ||
752 | err: | 745 | err: |
753 | kfree(desc); | 746 | kfree(desc); |
754 | out_not_authorized: | ||
755 | dev->descriptor.bNumConfigurations = cfgno; | 747 | dev->descriptor.bNumConfigurations = cfgno; |
756 | err2: | 748 | err2: |
757 | if (result == -ENOMEM) | 749 | if (result == -ENOMEM) |
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 967152a63bd3..90e18f6fa2bb 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c | |||
@@ -118,7 +118,7 @@ module_param(usbfs_memory_mb, uint, 0644); | |||
118 | MODULE_PARM_DESC(usbfs_memory_mb, | 118 | MODULE_PARM_DESC(usbfs_memory_mb, |
119 | "maximum MB allowed for usbfs buffers (0 = no limit)"); | 119 | "maximum MB allowed for usbfs buffers (0 = no limit)"); |
120 | 120 | ||
121 | /* Hard limit, necessary to avoid aithmetic overflow */ | 121 | /* Hard limit, necessary to avoid arithmetic overflow */ |
122 | #define USBFS_XFER_MAX (UINT_MAX / 2 - 1000000) | 122 | #define USBFS_XFER_MAX (UINT_MAX / 2 - 1000000) |
123 | 123 | ||
124 | static atomic_t usbfs_memory_usage; /* Total memory currently allocated */ | 124 | static atomic_t usbfs_memory_usage; /* Total memory currently allocated */ |
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 47aade2a5e74..5d01558cef66 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -37,6 +37,7 @@ | |||
37 | * and cause the driver to probe for all devices again. | 37 | * and cause the driver to probe for all devices again. |
38 | */ | 38 | */ |
39 | ssize_t usb_store_new_id(struct usb_dynids *dynids, | 39 | ssize_t usb_store_new_id(struct usb_dynids *dynids, |
40 | const struct usb_device_id *id_table, | ||
40 | struct device_driver *driver, | 41 | struct device_driver *driver, |
41 | const char *buf, size_t count) | 42 | const char *buf, size_t count) |
42 | { | 43 | { |
@@ -44,11 +45,12 @@ ssize_t usb_store_new_id(struct usb_dynids *dynids, | |||
44 | u32 idVendor = 0; | 45 | u32 idVendor = 0; |
45 | u32 idProduct = 0; | 46 | u32 idProduct = 0; |
46 | unsigned int bInterfaceClass = 0; | 47 | unsigned int bInterfaceClass = 0; |
48 | u32 refVendor, refProduct; | ||
47 | int fields = 0; | 49 | int fields = 0; |
48 | int retval = 0; | 50 | int retval = 0; |
49 | 51 | ||
50 | fields = sscanf(buf, "%x %x %x", &idVendor, &idProduct, | 52 | fields = sscanf(buf, "%x %x %x %x %x", &idVendor, &idProduct, |
51 | &bInterfaceClass); | 53 | &bInterfaceClass, &refVendor, &refProduct); |
52 | if (fields < 2) | 54 | if (fields < 2) |
53 | return -EINVAL; | 55 | return -EINVAL; |
54 | 56 | ||
@@ -60,11 +62,30 @@ ssize_t usb_store_new_id(struct usb_dynids *dynids, | |||
60 | dynid->id.idVendor = idVendor; | 62 | dynid->id.idVendor = idVendor; |
61 | dynid->id.idProduct = idProduct; | 63 | dynid->id.idProduct = idProduct; |
62 | dynid->id.match_flags = USB_DEVICE_ID_MATCH_DEVICE; | 64 | dynid->id.match_flags = USB_DEVICE_ID_MATCH_DEVICE; |
63 | if (fields == 3) { | 65 | if (fields > 2 && bInterfaceClass) { |
66 | if (bInterfaceClass > 255) | ||
67 | return -EINVAL; | ||
68 | |||
64 | dynid->id.bInterfaceClass = (u8)bInterfaceClass; | 69 | dynid->id.bInterfaceClass = (u8)bInterfaceClass; |
65 | dynid->id.match_flags |= USB_DEVICE_ID_MATCH_INT_CLASS; | 70 | dynid->id.match_flags |= USB_DEVICE_ID_MATCH_INT_CLASS; |
66 | } | 71 | } |
67 | 72 | ||
73 | if (fields > 4) { | ||
74 | const struct usb_device_id *id = id_table; | ||
75 | |||
76 | if (!id) | ||
77 | return -ENODEV; | ||
78 | |||
79 | for (; id->match_flags; id++) | ||
80 | if (id->idVendor == refVendor && id->idProduct == refProduct) | ||
81 | break; | ||
82 | |||
83 | if (id->match_flags) | ||
84 | dynid->id.driver_info = id->driver_info; | ||
85 | else | ||
86 | return -ENODEV; | ||
87 | } | ||
88 | |||
68 | spin_lock(&dynids->lock); | 89 | spin_lock(&dynids->lock); |
69 | list_add_tail(&dynid->node, &dynids->list); | 90 | list_add_tail(&dynid->node, &dynids->list); |
70 | spin_unlock(&dynids->lock); | 91 | spin_unlock(&dynids->lock); |
@@ -106,7 +127,7 @@ static ssize_t new_id_store(struct device_driver *driver, | |||
106 | { | 127 | { |
107 | struct usb_driver *usb_drv = to_usb_driver(driver); | 128 | struct usb_driver *usb_drv = to_usb_driver(driver); |
108 | 129 | ||
109 | return usb_store_new_id(&usb_drv->dynids, driver, buf, count); | 130 | return usb_store_new_id(&usb_drv->dynids, usb_drv->id_table, driver, buf, count); |
110 | } | 131 | } |
111 | static DRIVER_ATTR_RW(new_id); | 132 | static DRIVER_ATTR_RW(new_id); |
112 | 133 | ||
@@ -839,7 +860,7 @@ int usb_register_device_driver(struct usb_device_driver *new_udriver, | |||
839 | return -ENODEV; | 860 | return -ENODEV; |
840 | 861 | ||
841 | new_udriver->drvwrap.for_devices = 1; | 862 | new_udriver->drvwrap.for_devices = 1; |
842 | new_udriver->drvwrap.driver.name = (char *) new_udriver->name; | 863 | new_udriver->drvwrap.driver.name = new_udriver->name; |
843 | new_udriver->drvwrap.driver.bus = &usb_bus_type; | 864 | new_udriver->drvwrap.driver.bus = &usb_bus_type; |
844 | new_udriver->drvwrap.driver.probe = usb_probe_device; | 865 | new_udriver->drvwrap.driver.probe = usb_probe_device; |
845 | new_udriver->drvwrap.driver.remove = usb_unbind_device; | 866 | new_udriver->drvwrap.driver.remove = usb_unbind_device; |
@@ -900,7 +921,7 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner, | |||
900 | return -ENODEV; | 921 | return -ENODEV; |
901 | 922 | ||
902 | new_driver->drvwrap.for_devices = 0; | 923 | new_driver->drvwrap.for_devices = 0; |
903 | new_driver->drvwrap.driver.name = (char *) new_driver->name; | 924 | new_driver->drvwrap.driver.name = new_driver->name; |
904 | new_driver->drvwrap.driver.bus = &usb_bus_type; | 925 | new_driver->drvwrap.driver.bus = &usb_bus_type; |
905 | new_driver->drvwrap.driver.probe = usb_probe_interface; | 926 | new_driver->drvwrap.driver.probe = usb_probe_interface; |
906 | new_driver->drvwrap.driver.remove = usb_unbind_interface; | 927 | new_driver->drvwrap.driver.remove = usb_unbind_interface; |
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index dfe9d0f22978..d59d99347d54 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c | |||
@@ -282,6 +282,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
282 | 282 | ||
283 | if (retval != 0) | 283 | if (retval != 0) |
284 | goto unmap_registers; | 284 | goto unmap_registers; |
285 | device_wakeup_enable(hcd->self.controller); | ||
285 | 286 | ||
286 | if (pci_dev_run_wake(dev)) | 287 | if (pci_dev_run_wake(dev)) |
287 | pm_runtime_put_noidle(&dev->dev); | 288 | pm_runtime_put_noidle(&dev->dev); |
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 6bffb8c87bc9..199aaea6bfe0 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -44,6 +44,7 @@ | |||
44 | 44 | ||
45 | #include <linux/usb.h> | 45 | #include <linux/usb.h> |
46 | #include <linux/usb/hcd.h> | 46 | #include <linux/usb/hcd.h> |
47 | #include <linux/usb/phy.h> | ||
47 | 48 | ||
48 | #include "usb.h" | 49 | #include "usb.h" |
49 | 50 | ||
@@ -1297,7 +1298,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_unlink_urb_from_ep); | |||
1297 | * DMA framework is dma_declare_coherent_memory() | 1298 | * DMA framework is dma_declare_coherent_memory() |
1298 | * | 1299 | * |
1299 | * - So we use that, even though the primary requirement | 1300 | * - So we use that, even though the primary requirement |
1300 | * is that the memory be "local" (hence addressible | 1301 | * is that the memory be "local" (hence addressable |
1301 | * by that device), not "coherent". | 1302 | * by that device), not "coherent". |
1302 | * | 1303 | * |
1303 | */ | 1304 | */ |
@@ -2588,6 +2589,24 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2588 | int retval; | 2589 | int retval; |
2589 | struct usb_device *rhdev; | 2590 | struct usb_device *rhdev; |
2590 | 2591 | ||
2592 | if (IS_ENABLED(CONFIG_USB_PHY) && !hcd->phy) { | ||
2593 | struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller, 0); | ||
2594 | |||
2595 | if (IS_ERR(phy)) { | ||
2596 | retval = PTR_ERR(phy); | ||
2597 | if (retval == -EPROBE_DEFER) | ||
2598 | return retval; | ||
2599 | } else { | ||
2600 | retval = usb_phy_init(phy); | ||
2601 | if (retval) { | ||
2602 | usb_put_phy(phy); | ||
2603 | return retval; | ||
2604 | } | ||
2605 | hcd->phy = phy; | ||
2606 | hcd->remove_phy = 1; | ||
2607 | } | ||
2608 | } | ||
2609 | |||
2591 | dev_info(hcd->self.controller, "%s\n", hcd->product_desc); | 2610 | dev_info(hcd->self.controller, "%s\n", hcd->product_desc); |
2592 | 2611 | ||
2593 | /* Keep old behaviour if authorized_default is not in [0, 1]. */ | 2612 | /* Keep old behaviour if authorized_default is not in [0, 1]. */ |
@@ -2603,7 +2622,7 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2603 | */ | 2622 | */ |
2604 | if ((retval = hcd_buffer_create(hcd)) != 0) { | 2623 | if ((retval = hcd_buffer_create(hcd)) != 0) { |
2605 | dev_dbg(hcd->self.controller, "pool alloc failed\n"); | 2624 | dev_dbg(hcd->self.controller, "pool alloc failed\n"); |
2606 | return retval; | 2625 | goto err_remove_phy; |
2607 | } | 2626 | } |
2608 | 2627 | ||
2609 | if ((retval = usb_register_bus(&hcd->self)) < 0) | 2628 | if ((retval = usb_register_bus(&hcd->self)) < 0) |
@@ -2693,12 +2712,6 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2693 | if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) | 2712 | if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) |
2694 | usb_hcd_poll_rh_status(hcd); | 2713 | usb_hcd_poll_rh_status(hcd); |
2695 | 2714 | ||
2696 | /* | ||
2697 | * Host controllers don't generate their own wakeup requests; | ||
2698 | * they only forward requests from the root hub. Therefore | ||
2699 | * controllers should always be enabled for remote wakeup. | ||
2700 | */ | ||
2701 | device_wakeup_enable(hcd->self.controller); | ||
2702 | return retval; | 2715 | return retval; |
2703 | 2716 | ||
2704 | error_create_attr_group: | 2717 | error_create_attr_group: |
@@ -2734,6 +2747,12 @@ err_allocate_root_hub: | |||
2734 | usb_deregister_bus(&hcd->self); | 2747 | usb_deregister_bus(&hcd->self); |
2735 | err_register_bus: | 2748 | err_register_bus: |
2736 | hcd_buffer_destroy(hcd); | 2749 | hcd_buffer_destroy(hcd); |
2750 | err_remove_phy: | ||
2751 | if (hcd->remove_phy && hcd->phy) { | ||
2752 | usb_phy_shutdown(hcd->phy); | ||
2753 | usb_put_phy(hcd->phy); | ||
2754 | hcd->phy = NULL; | ||
2755 | } | ||
2737 | return retval; | 2756 | return retval; |
2738 | } | 2757 | } |
2739 | EXPORT_SYMBOL_GPL(usb_add_hcd); | 2758 | EXPORT_SYMBOL_GPL(usb_add_hcd); |
@@ -2806,6 +2825,11 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2806 | usb_put_dev(hcd->self.root_hub); | 2825 | usb_put_dev(hcd->self.root_hub); |
2807 | usb_deregister_bus(&hcd->self); | 2826 | usb_deregister_bus(&hcd->self); |
2808 | hcd_buffer_destroy(hcd); | 2827 | hcd_buffer_destroy(hcd); |
2828 | if (hcd->remove_phy && hcd->phy) { | ||
2829 | usb_phy_shutdown(hcd->phy); | ||
2830 | usb_put_phy(hcd->phy); | ||
2831 | hcd->phy = NULL; | ||
2832 | } | ||
2809 | } | 2833 | } |
2810 | EXPORT_SYMBOL_GPL(usb_remove_hcd); | 2834 | EXPORT_SYMBOL_GPL(usb_remove_hcd); |
2811 | 2835 | ||
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index bd9dc3504b51..babba885978d 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -33,13 +33,6 @@ | |||
33 | 33 | ||
34 | #include "hub.h" | 34 | #include "hub.h" |
35 | 35 | ||
36 | /* if we are in debug mode, always announce new devices */ | ||
37 | #ifdef DEBUG | ||
38 | #ifndef CONFIG_USB_ANNOUNCE_NEW_DEVICES | ||
39 | #define CONFIG_USB_ANNOUNCE_NEW_DEVICES | ||
40 | #endif | ||
41 | #endif | ||
42 | |||
43 | #define USB_VENDOR_GENESYS_LOGIC 0x05e3 | 36 | #define USB_VENDOR_GENESYS_LOGIC 0x05e3 |
44 | #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 | 37 | #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 |
45 | 38 | ||
@@ -1154,7 +1147,8 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1154 | /* Tell khubd to disconnect the device or | 1147 | /* Tell khubd to disconnect the device or |
1155 | * check for a new connection | 1148 | * check for a new connection |
1156 | */ | 1149 | */ |
1157 | if (udev || (portstatus & USB_PORT_STAT_CONNECTION)) | 1150 | if (udev || (portstatus & USB_PORT_STAT_CONNECTION) || |
1151 | (portstatus & USB_PORT_STAT_OVERCURRENT)) | ||
1158 | set_bit(port1, hub->change_bits); | 1152 | set_bit(port1, hub->change_bits); |
1159 | 1153 | ||
1160 | } else if (portstatus & USB_PORT_STAT_ENABLE) { | 1154 | } else if (portstatus & USB_PORT_STAT_ENABLE) { |
@@ -1607,7 +1601,7 @@ static void hub_disconnect(struct usb_interface *intf) | |||
1607 | { | 1601 | { |
1608 | struct usb_hub *hub = usb_get_intfdata(intf); | 1602 | struct usb_hub *hub = usb_get_intfdata(intf); |
1609 | struct usb_device *hdev = interface_to_usbdev(intf); | 1603 | struct usb_device *hdev = interface_to_usbdev(intf); |
1610 | int i; | 1604 | int port1; |
1611 | 1605 | ||
1612 | /* Take the hub off the event list and don't let it be added again */ | 1606 | /* Take the hub off the event list and don't let it be added again */ |
1613 | spin_lock_irq(&hub_event_lock); | 1607 | spin_lock_irq(&hub_event_lock); |
@@ -1622,11 +1616,15 @@ static void hub_disconnect(struct usb_interface *intf) | |||
1622 | hub->error = 0; | 1616 | hub->error = 0; |
1623 | hub_quiesce(hub, HUB_DISCONNECT); | 1617 | hub_quiesce(hub, HUB_DISCONNECT); |
1624 | 1618 | ||
1625 | usb_set_intfdata (intf, NULL); | 1619 | /* Avoid races with recursively_mark_NOTATTACHED() */ |
1620 | spin_lock_irq(&device_state_lock); | ||
1621 | port1 = hdev->maxchild; | ||
1622 | hdev->maxchild = 0; | ||
1623 | usb_set_intfdata(intf, NULL); | ||
1624 | spin_unlock_irq(&device_state_lock); | ||
1626 | 1625 | ||
1627 | for (i = 0; i < hdev->maxchild; i++) | 1626 | for (; port1 > 0; --port1) |
1628 | usb_hub_remove_port_device(hub, i + 1); | 1627 | usb_hub_remove_port_device(hub, port1); |
1629 | hub->hdev->maxchild = 0; | ||
1630 | 1628 | ||
1631 | if (hub->hdev->speed == USB_SPEED_HIGH) | 1629 | if (hub->hdev->speed == USB_SPEED_HIGH) |
1632 | highspeed_hubs--; | 1630 | highspeed_hubs--; |
@@ -2235,17 +2233,13 @@ static int usb_enumerate_device(struct usb_device *udev) | |||
2235 | return err; | 2233 | return err; |
2236 | } | 2234 | } |
2237 | } | 2235 | } |
2238 | if (udev->wusb == 1 && udev->authorized == 0) { | 2236 | |
2239 | udev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL); | 2237 | /* read the standard strings and cache them if present */ |
2240 | udev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL); | 2238 | udev->product = usb_cache_string(udev, udev->descriptor.iProduct); |
2241 | udev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL); | 2239 | udev->manufacturer = usb_cache_string(udev, |
2242 | } else { | 2240 | udev->descriptor.iManufacturer); |
2243 | /* read the standard strings and cache them if present */ | 2241 | udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); |
2244 | udev->product = usb_cache_string(udev, udev->descriptor.iProduct); | 2242 | |
2245 | udev->manufacturer = usb_cache_string(udev, | ||
2246 | udev->descriptor.iManufacturer); | ||
2247 | udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); | ||
2248 | } | ||
2249 | err = usb_enumerate_device_otg(udev); | 2243 | err = usb_enumerate_device_otg(udev); |
2250 | if (err < 0) | 2244 | if (err < 0) |
2251 | return err; | 2245 | return err; |
@@ -2427,16 +2421,6 @@ int usb_deauthorize_device(struct usb_device *usb_dev) | |||
2427 | usb_dev->authorized = 0; | 2421 | usb_dev->authorized = 0; |
2428 | usb_set_configuration(usb_dev, -1); | 2422 | usb_set_configuration(usb_dev, -1); |
2429 | 2423 | ||
2430 | kfree(usb_dev->product); | ||
2431 | usb_dev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL); | ||
2432 | kfree(usb_dev->manufacturer); | ||
2433 | usb_dev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL); | ||
2434 | kfree(usb_dev->serial); | ||
2435 | usb_dev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL); | ||
2436 | |||
2437 | usb_destroy_configuration(usb_dev); | ||
2438 | usb_dev->descriptor.bNumConfigurations = 0; | ||
2439 | |||
2440 | out_unauthorized: | 2424 | out_unauthorized: |
2441 | usb_unlock_device(usb_dev); | 2425 | usb_unlock_device(usb_dev); |
2442 | return 0; | 2426 | return 0; |
@@ -2464,17 +2448,7 @@ int usb_authorize_device(struct usb_device *usb_dev) | |||
2464 | goto error_device_descriptor; | 2448 | goto error_device_descriptor; |
2465 | } | 2449 | } |
2466 | 2450 | ||
2467 | kfree(usb_dev->product); | ||
2468 | usb_dev->product = NULL; | ||
2469 | kfree(usb_dev->manufacturer); | ||
2470 | usb_dev->manufacturer = NULL; | ||
2471 | kfree(usb_dev->serial); | ||
2472 | usb_dev->serial = NULL; | ||
2473 | |||
2474 | usb_dev->authorized = 1; | 2451 | usb_dev->authorized = 1; |
2475 | result = usb_enumerate_device(usb_dev); | ||
2476 | if (result < 0) | ||
2477 | goto error_enumerate; | ||
2478 | /* Choose and set the configuration. This registers the interfaces | 2452 | /* Choose and set the configuration. This registers the interfaces |
2479 | * with the driver core and lets interface drivers bind to them. | 2453 | * with the driver core and lets interface drivers bind to them. |
2480 | */ | 2454 | */ |
@@ -2490,7 +2464,6 @@ int usb_authorize_device(struct usb_device *usb_dev) | |||
2490 | } | 2464 | } |
2491 | dev_info(&usb_dev->dev, "authorized to connect\n"); | 2465 | dev_info(&usb_dev->dev, "authorized to connect\n"); |
2492 | 2466 | ||
2493 | error_enumerate: | ||
2494 | error_device_descriptor: | 2467 | error_device_descriptor: |
2495 | usb_autosuspend_device(usb_dev); | 2468 | usb_autosuspend_device(usb_dev); |
2496 | error_autoresume: | 2469 | error_autoresume: |
@@ -2523,10 +2496,25 @@ static unsigned hub_is_wusb(struct usb_hub *hub) | |||
2523 | #define HUB_LONG_RESET_TIME 200 | 2496 | #define HUB_LONG_RESET_TIME 200 |
2524 | #define HUB_RESET_TIMEOUT 800 | 2497 | #define HUB_RESET_TIMEOUT 800 |
2525 | 2498 | ||
2499 | /* | ||
2500 | * "New scheme" enumeration causes an extra state transition to be | ||
2501 | * exposed to an xhci host and causes USB3 devices to receive control | ||
2502 | * commands in the default state. This has been seen to cause | ||
2503 | * enumeration failures, so disable this enumeration scheme for USB3 | ||
2504 | * devices. | ||
2505 | */ | ||
2506 | static bool use_new_scheme(struct usb_device *udev, int retry) | ||
2507 | { | ||
2508 | if (udev->speed == USB_SPEED_SUPER) | ||
2509 | return false; | ||
2510 | |||
2511 | return USE_NEW_SCHEME(retry); | ||
2512 | } | ||
2513 | |||
2526 | static int hub_port_reset(struct usb_hub *hub, int port1, | 2514 | static int hub_port_reset(struct usb_hub *hub, int port1, |
2527 | struct usb_device *udev, unsigned int delay, bool warm); | 2515 | struct usb_device *udev, unsigned int delay, bool warm); |
2528 | 2516 | ||
2529 | /* Is a USB 3.0 port in the Inactive or Complinance Mode state? | 2517 | /* Is a USB 3.0 port in the Inactive or Compliance Mode state? |
2530 | * Port worm reset is required to recover | 2518 | * Port worm reset is required to recover |
2531 | */ | 2519 | */ |
2532 | static bool hub_port_warm_reset_required(struct usb_hub *hub, u16 portstatus) | 2520 | static bool hub_port_warm_reset_required(struct usb_hub *hub, u16 portstatus) |
@@ -3334,7 +3322,8 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | |||
3334 | 3322 | ||
3335 | udev = hub->ports[port1 - 1]->child; | 3323 | udev = hub->ports[port1 - 1]->child; |
3336 | if (udev && udev->can_submit) { | 3324 | if (udev && udev->can_submit) { |
3337 | dev_warn(&intf->dev, "port %d nyet suspended\n", port1); | 3325 | dev_warn(&intf->dev, "port %d not suspended yet\n", |
3326 | port1); | ||
3338 | if (PMSG_IS_AUTO(msg)) | 3327 | if (PMSG_IS_AUTO(msg)) |
3339 | return -EBUSY; | 3328 | return -EBUSY; |
3340 | } | 3329 | } |
@@ -3981,6 +3970,20 @@ static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev) | |||
3981 | } | 3970 | } |
3982 | } | 3971 | } |
3983 | 3972 | ||
3973 | static int hub_enable_device(struct usb_device *udev) | ||
3974 | { | ||
3975 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | ||
3976 | |||
3977 | if (!hcd->driver->enable_device) | ||
3978 | return 0; | ||
3979 | if (udev->state == USB_STATE_ADDRESS) | ||
3980 | return 0; | ||
3981 | if (udev->state != USB_STATE_DEFAULT) | ||
3982 | return -EINVAL; | ||
3983 | |||
3984 | return hcd->driver->enable_device(hcd, udev); | ||
3985 | } | ||
3986 | |||
3984 | /* Reset device, (re)assign address, get device descriptor. | 3987 | /* Reset device, (re)assign address, get device descriptor. |
3985 | * Device connection must be stable, no more debouncing needed. | 3988 | * Device connection must be stable, no more debouncing needed. |
3986 | * Returns device in USB_STATE_ADDRESS, except on error. | 3989 | * Returns device in USB_STATE_ADDRESS, except on error. |
@@ -4093,7 +4096,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
4093 | * this area, and this is how Linux has done it for ages. | 4096 | * this area, and this is how Linux has done it for ages. |
4094 | * Change it cautiously. | 4097 | * Change it cautiously. |
4095 | * | 4098 | * |
4096 | * NOTE: If USE_NEW_SCHEME() is true we will start by issuing | 4099 | * NOTE: If use_new_scheme() is true we will start by issuing |
4097 | * a 64-byte GET_DESCRIPTOR request. This is what Windows does, | 4100 | * a 64-byte GET_DESCRIPTOR request. This is what Windows does, |
4098 | * so it may help with some non-standards-compliant devices. | 4101 | * so it may help with some non-standards-compliant devices. |
4099 | * Otherwise we start with SET_ADDRESS and then try to read the | 4102 | * Otherwise we start with SET_ADDRESS and then try to read the |
@@ -4101,10 +4104,17 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
4101 | * value. | 4104 | * value. |
4102 | */ | 4105 | */ |
4103 | for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { | 4106 | for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { |
4104 | if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) { | 4107 | bool did_new_scheme = false; |
4108 | |||
4109 | if (use_new_scheme(udev, retry_counter)) { | ||
4105 | struct usb_device_descriptor *buf; | 4110 | struct usb_device_descriptor *buf; |
4106 | int r = 0; | 4111 | int r = 0; |
4107 | 4112 | ||
4113 | did_new_scheme = true; | ||
4114 | retval = hub_enable_device(udev); | ||
4115 | if (retval < 0) | ||
4116 | goto fail; | ||
4117 | |||
4108 | #define GET_DESCRIPTOR_BUFSIZE 64 | 4118 | #define GET_DESCRIPTOR_BUFSIZE 64 |
4109 | buf = kmalloc(GET_DESCRIPTOR_BUFSIZE, GFP_NOIO); | 4119 | buf = kmalloc(GET_DESCRIPTOR_BUFSIZE, GFP_NOIO); |
4110 | if (!buf) { | 4120 | if (!buf) { |
@@ -4193,7 +4203,11 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
4193 | * - read ep0 maxpacket even for high and low speed, | 4203 | * - read ep0 maxpacket even for high and low speed, |
4194 | */ | 4204 | */ |
4195 | msleep(10); | 4205 | msleep(10); |
4196 | if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) | 4206 | /* use_new_scheme() checks the speed which may have |
4207 | * changed since the initial look so we cache the result | ||
4208 | * in did_new_scheme | ||
4209 | */ | ||
4210 | if (did_new_scheme) | ||
4197 | break; | 4211 | break; |
4198 | } | 4212 | } |
4199 | 4213 | ||
@@ -4900,7 +4914,7 @@ static void hub_events(void) | |||
4900 | 4914 | ||
4901 | static int hub_thread(void *__unused) | 4915 | static int hub_thread(void *__unused) |
4902 | { | 4916 | { |
4903 | /* khubd needs to be freezable to avoid intefering with USB-PERSIST | 4917 | /* khubd needs to be freezable to avoid interfering with USB-PERSIST |
4904 | * port handover. Otherwise it might see that a full-speed device | 4918 | * port handover. Otherwise it might see that a full-speed device |
4905 | * was gone before the EHCI controller had handed its port over to | 4919 | * was gone before the EHCI controller had handed its port over to |
4906 | * the companion full-speed controller. | 4920 | * the companion full-speed controller. |
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 4e4790dea343..df629a310e44 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h | |||
@@ -78,7 +78,7 @@ struct usb_hub { | |||
78 | 78 | ||
79 | /** | 79 | /** |
80 | * struct usb port - kernel's representation of a usb port | 80 | * struct usb port - kernel's representation of a usb port |
81 | * @child: usb device attatched to the port | 81 | * @child: usb device attached to the port |
82 | * @dev: generic device interface | 82 | * @dev: generic device interface |
83 | * @port_owner: port's owner | 83 | * @port_owner: port's owner |
84 | * @connect_type: port's connect type | 84 | * @connect_type: port's connect type |
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index bb315970e475..f829a1aad1c3 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -6,7 +6,6 @@ | |||
6 | #include <linux/usb.h> | 6 | #include <linux/usb.h> |
7 | #include <linux/module.h> | 7 | #include <linux/module.h> |
8 | #include <linux/slab.h> | 8 | #include <linux/slab.h> |
9 | #include <linux/init.h> | ||
10 | #include <linux/mm.h> | 9 | #include <linux/mm.h> |
11 | #include <linux/timer.h> | 10 | #include <linux/timer.h> |
12 | #include <linux/ctype.h> | 11 | #include <linux/ctype.h> |
@@ -218,7 +217,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg); | |||
218 | * | 217 | * |
219 | * Return: | 218 | * Return: |
220 | * If successful, 0. Otherwise a negative error number. The number of actual | 219 | * If successful, 0. Otherwise a negative error number. The number of actual |
221 | * bytes transferred will be stored in the @actual_length paramater. | 220 | * bytes transferred will be stored in the @actual_length parameter. |
222 | * | 221 | * |
223 | */ | 222 | */ |
224 | int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, | 223 | int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, |
@@ -518,7 +517,7 @@ void usb_sg_wait(struct usb_sg_request *io) | |||
518 | io->urbs[i]->dev = io->dev; | 517 | io->urbs[i]->dev = io->dev; |
519 | retval = usb_submit_urb(io->urbs[i], GFP_ATOMIC); | 518 | retval = usb_submit_urb(io->urbs[i], GFP_ATOMIC); |
520 | 519 | ||
521 | /* after we submit, let completions or cancelations fire; | 520 | /* after we submit, let completions or cancellations fire; |
522 | * we handshake using io->status. | 521 | * we handshake using io->status. |
523 | */ | 522 | */ |
524 | spin_unlock_irq(&io->lock); | 523 | spin_unlock_irq(&io->lock); |
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c index 12924dbfdc2c..8f37063c0a49 100644 --- a/drivers/usb/core/quirks.c +++ b/drivers/usb/core/quirks.c | |||
@@ -98,9 +98,6 @@ static const struct usb_device_id usb_quirk_list[] = { | |||
98 | /* Alcor Micro Corp. Hub */ | 98 | /* Alcor Micro Corp. Hub */ |
99 | { USB_DEVICE(0x058f, 0x9254), .driver_info = USB_QUIRK_RESET_RESUME }, | 99 | { USB_DEVICE(0x058f, 0x9254), .driver_info = USB_QUIRK_RESET_RESUME }, |
100 | 100 | ||
101 | /* MicroTouch Systems touchscreen */ | ||
102 | { USB_DEVICE(0x0596, 0x051e), .driver_info = USB_QUIRK_RESET_RESUME }, | ||
103 | |||
104 | /* appletouch */ | 101 | /* appletouch */ |
105 | { USB_DEVICE(0x05ac, 0x021a), .driver_info = USB_QUIRK_RESET_RESUME }, | 102 | { USB_DEVICE(0x05ac, 0x021a), .driver_info = USB_QUIRK_RESET_RESUME }, |
106 | 103 | ||
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 52a97adf02a0..1236c6011c70 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -837,7 +837,7 @@ void usb_remove_sysfs_dev_files(struct usb_device *udev) | |||
837 | device_remove_bin_file(dev, &dev_bin_attr_descriptors); | 837 | device_remove_bin_file(dev, &dev_bin_attr_descriptors); |
838 | } | 838 | } |
839 | 839 | ||
840 | /* Interface Accociation Descriptor fields */ | 840 | /* Interface Association Descriptor fields */ |
841 | #define usb_intf_assoc_attr(field, format_string) \ | 841 | #define usb_intf_assoc_attr(field, format_string) \ |
842 | static ssize_t \ | 842 | static ssize_t \ |
843 | iad_##field##_show(struct device *dev, struct device_attribute *attr, \ | 843 | iad_##field##_show(struct device *dev, struct device_attribute *attr, \ |
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index e62208356c89..9ff665f1322f 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c | |||
@@ -2,7 +2,6 @@ | |||
2 | #include <linux/string.h> | 2 | #include <linux/string.h> |
3 | #include <linux/bitops.h> | 3 | #include <linux/bitops.h> |
4 | #include <linux/slab.h> | 4 | #include <linux/slab.h> |
5 | #include <linux/init.h> | ||
6 | #include <linux/log2.h> | 5 | #include <linux/log2.h> |
7 | #include <linux/usb.h> | 6 | #include <linux/usb.h> |
8 | #include <linux/wait.h> | 7 | #include <linux/wait.h> |
@@ -53,7 +52,7 @@ EXPORT_SYMBOL_GPL(usb_init_urb); | |||
53 | * valid options for this. | 52 | * valid options for this. |
54 | * | 53 | * |
55 | * Creates an urb for the USB driver to use, initializes a few internal | 54 | * Creates an urb for the USB driver to use, initializes a few internal |
56 | * structures, incrementes the usage counter, and returns a pointer to it. | 55 | * structures, increments the usage counter, and returns a pointer to it. |
57 | * | 56 | * |
58 | * If the driver want to use this urb for interrupt, control, or bulk | 57 | * If the driver want to use this urb for interrupt, control, or bulk |
59 | * endpoints, pass '0' as the number of iso packets. | 58 | * endpoints, pass '0' as the number of iso packets. |
@@ -281,7 +280,7 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb); | |||
281 | * | 280 | * |
282 | * Device drivers must explicitly request that repetition, by ensuring that | 281 | * Device drivers must explicitly request that repetition, by ensuring that |
283 | * some URB is always on the endpoint's queue (except possibly for short | 282 | * some URB is always on the endpoint's queue (except possibly for short |
284 | * periods during completion callacks). When there is no longer an urb | 283 | * periods during completion callbacks). When there is no longer an urb |
285 | * queued, the endpoint's bandwidth reservation is canceled. This means | 284 | * queued, the endpoint's bandwidth reservation is canceled. This means |
286 | * drivers can use their completion handlers to ensure they keep bandwidth | 285 | * drivers can use their completion handlers to ensure they keep bandwidth |
287 | * they need, by reinitializing and resubmitting the just-completed urb | 286 | * they need, by reinitializing and resubmitting the just-completed urb |
@@ -325,10 +324,14 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb); | |||
325 | */ | 324 | */ |
326 | int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | 325 | int usb_submit_urb(struct urb *urb, gfp_t mem_flags) |
327 | { | 326 | { |
327 | static int pipetypes[4] = { | ||
328 | PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT | ||
329 | }; | ||
328 | int xfertype, max; | 330 | int xfertype, max; |
329 | struct usb_device *dev; | 331 | struct usb_device *dev; |
330 | struct usb_host_endpoint *ep; | 332 | struct usb_host_endpoint *ep; |
331 | int is_out; | 333 | int is_out; |
334 | unsigned int allowed; | ||
332 | 335 | ||
333 | if (!urb || !urb->complete) | 336 | if (!urb || !urb->complete) |
334 | return -EINVAL; | 337 | return -EINVAL; |
@@ -436,15 +439,10 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
436 | if (urb->transfer_buffer_length > INT_MAX) | 439 | if (urb->transfer_buffer_length > INT_MAX) |
437 | return -EMSGSIZE; | 440 | return -EMSGSIZE; |
438 | 441 | ||
439 | #ifdef DEBUG | 442 | /* |
440 | /* stuff that drivers shouldn't do, but which shouldn't | 443 | * stuff that drivers shouldn't do, but which shouldn't |
441 | * cause problems in HCDs if they get it wrong. | 444 | * cause problems in HCDs if they get it wrong. |
442 | */ | 445 | */ |
443 | { | ||
444 | unsigned int allowed; | ||
445 | static int pipetypes[4] = { | ||
446 | PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT | ||
447 | }; | ||
448 | 446 | ||
449 | /* Check that the pipe's type matches the endpoint's type */ | 447 | /* Check that the pipe's type matches the endpoint's type */ |
450 | if (usb_pipetype(urb->pipe) != pipetypes[xfertype]) | 448 | if (usb_pipetype(urb->pipe) != pipetypes[xfertype]) |
@@ -476,8 +474,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
476 | if (allowed != urb->transfer_flags) | 474 | if (allowed != urb->transfer_flags) |
477 | dev_WARN(&dev->dev, "BOGUS urb flags, %x --> %x\n", | 475 | dev_WARN(&dev->dev, "BOGUS urb flags, %x --> %x\n", |
478 | urb->transfer_flags, allowed); | 476 | urb->transfer_flags, allowed); |
479 | } | 477 | |
480 | #endif | ||
481 | /* | 478 | /* |
482 | * Force periodic transfer intervals to be legal values that are | 479 | * Force periodic transfer intervals to be legal values that are |
483 | * a power of two (so HCDs don't need to). | 480 | * a power of two (so HCDs don't need to). |
@@ -492,9 +489,9 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
492 | /* too small? */ | 489 | /* too small? */ |
493 | switch (dev->speed) { | 490 | switch (dev->speed) { |
494 | case USB_SPEED_WIRELESS: | 491 | case USB_SPEED_WIRELESS: |
495 | if (urb->interval < 6) | 492 | if ((urb->interval < 6) |
493 | && (xfertype == USB_ENDPOINT_XFER_INT)) | ||
496 | return -EINVAL; | 494 | return -EINVAL; |
497 | break; | ||
498 | default: | 495 | default: |
499 | if (urb->interval <= 0) | 496 | if (urb->interval <= 0) |
500 | return -EINVAL; | 497 | return -EINVAL; |
diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c index f0155a39aaa3..5ca4070b1f38 100644 --- a/drivers/usb/core/usb-acpi.c +++ b/drivers/usb/core/usb-acpi.c | |||
@@ -91,7 +91,7 @@ static int usb_acpi_check_port_connect_type(struct usb_device *hdev, | |||
91 | int ret = 0; | 91 | int ret = 0; |
92 | 92 | ||
93 | /* | 93 | /* |
94 | * Accoding to ACPI Spec 9.13. PLD indicates whether usb port is | 94 | * According to ACPI Spec 9.13. PLD indicates whether usb port is |
95 | * user visible and _UPC indicates whether it is connectable. If | 95 | * user visible and _UPC indicates whether it is connectable. If |
96 | * the port was visible and connectable, it could be freely connected | 96 | * the port was visible and connectable, it could be freely connected |
97 | * and disconnected with USB devices. If no visible and connectable, | 97 | * and disconnected with USB devices. If no visible and connectable, |
diff --git a/drivers/usb/dwc2/Kconfig b/drivers/usb/dwc2/Kconfig new file mode 100644 index 000000000000..be947d673844 --- /dev/null +++ b/drivers/usb/dwc2/Kconfig | |||
@@ -0,0 +1,53 @@ | |||
1 | config USB_DWC2 | ||
2 | tristate "DesignWare USB2 DRD Core Support" | ||
3 | depends on USB | ||
4 | help | ||
5 | Say Y or M here if your system has a Dual Role HighSpeed | ||
6 | USB controller based on the DesignWare HSOTG IP Core. | ||
7 | |||
8 | If you choose to build this driver as dynamically linked | ||
9 | modules, the core module will be called dwc2.ko, the | ||
10 | PCI bus interface module (if you have a PCI bus system) | ||
11 | will be called dwc2_pci.ko and the platform interface module | ||
12 | (for controllers directly connected to the CPU) will be called | ||
13 | dwc2_platform.ko. | ||
14 | |||
15 | NOTE: This driver at present only implements the Host mode | ||
16 | of the controller. The existing s3c-hsotg driver supports | ||
17 | Peripheral mode, but only for the Samsung S3C platforms. | ||
18 | There are plans to merge the s3c-hsotg driver with this | ||
19 | driver in the near future to create a dual-role driver. | ||
20 | |||
21 | if USB_DWC2 | ||
22 | |||
23 | config USB_DWC2_DEBUG | ||
24 | bool "Enable Debugging Messages" | ||
25 | help | ||
26 | Say Y here to enable debugging messages in the DWC2 Driver. | ||
27 | |||
28 | config USB_DWC2_VERBOSE | ||
29 | bool "Enable Verbose Debugging Messages" | ||
30 | depends on USB_DWC2_DEBUG | ||
31 | help | ||
32 | Say Y here to enable verbose debugging messages in the DWC2 Driver. | ||
33 | WARNING: Enabling this will quickly fill your message log. | ||
34 | If in doubt, say N. | ||
35 | |||
36 | config USB_DWC2_TRACK_MISSED_SOFS | ||
37 | bool "Enable Missed SOF Tracking" | ||
38 | help | ||
39 | Say Y here to enable logging of missed SOF events to the dmesg log. | ||
40 | WARNING: This feature is still experimental. | ||
41 | If in doubt, say N. | ||
42 | |||
43 | config USB_DWC2_DEBUG_PERIODIC | ||
44 | bool "Enable Debugging Messages For Periodic Transfers" | ||
45 | depends on USB_DWC2_DEBUG || USB_DWC2_VERBOSE | ||
46 | default y | ||
47 | help | ||
48 | Say N here to disable (verbose) debugging messages to be | ||
49 | logged for periodic transfers. This allows better debugging of | ||
50 | non-periodic transfers, but of course the debug logs will be | ||
51 | incomplete. Note that this also disables some debug messages | ||
52 | for which the transfer type cannot be deduced. | ||
53 | endif | ||
diff --git a/drivers/usb/dwc2/Makefile b/drivers/usb/dwc2/Makefile new file mode 100644 index 000000000000..11529d3439b0 --- /dev/null +++ b/drivers/usb/dwc2/Makefile | |||
@@ -0,0 +1,25 @@ | |||
1 | ccflags-$(CONFIG_USB_DWC2_DEBUG) += -DDEBUG | ||
2 | ccflags-$(CONFIG_USB_DWC2_VERBOSE) += -DVERBOSE_DEBUG | ||
3 | |||
4 | obj-$(CONFIG_USB_DWC2) += dwc2.o | ||
5 | |||
6 | dwc2-y += core.o core_intr.o | ||
7 | |||
8 | # NOTE: This driver at present only implements the Host mode | ||
9 | # of the controller. The existing s3c-hsotg driver supports | ||
10 | # Peripheral mode, but only for the Samsung S3C platforms. | ||
11 | # There are plans to merge the s3c-hsotg driver with this | ||
12 | # driver in the near future to create a dual-role driver. Once | ||
13 | # that is done, Host mode will become an optional feature that | ||
14 | # is selected with a config option. | ||
15 | |||
16 | dwc2-y += hcd.o hcd_intr.o | ||
17 | dwc2-y += hcd_queue.o hcd_ddma.o | ||
18 | |||
19 | ifneq ($(CONFIG_PCI),) | ||
20 | obj-$(CONFIG_USB_DWC2) += dwc2_pci.o | ||
21 | endif | ||
22 | obj-$(CONFIG_USB_DWC2) += dwc2_platform.o | ||
23 | |||
24 | dwc2_pci-y += pci.o | ||
25 | dwc2_platform-y += platform.o | ||
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c new file mode 100644 index 000000000000..8565d87f94b4 --- /dev/null +++ b/drivers/usb/dwc2/core.c | |||
@@ -0,0 +1,2777 @@ | |||
1 | /* | ||
2 | * core.c - DesignWare HS OTG Controller common routines | ||
3 | * | ||
4 | * Copyright (C) 2004-2013 Synopsys, Inc. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions, and the following disclaimer, | ||
11 | * without modification. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The names of the above-listed copyright holders may not be used | ||
16 | * to endorse or promote products derived from this software without | ||
17 | * specific prior written permission. | ||
18 | * | ||
19 | * ALTERNATIVELY, this software may be distributed under the terms of the | ||
20 | * GNU General Public License ("GPL") as published by the Free Software | ||
21 | * Foundation; either version 2 of the License, or (at your option) any | ||
22 | * later version. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
26 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
35 | */ | ||
36 | |||
37 | /* | ||
38 | * The Core code provides basic services for accessing and managing the | ||
39 | * DWC_otg hardware. These services are used by both the Host Controller | ||
40 | * Driver and the Peripheral Controller Driver. | ||
41 | */ | ||
42 | #include <linux/kernel.h> | ||
43 | #include <linux/module.h> | ||
44 | #include <linux/moduleparam.h> | ||
45 | #include <linux/spinlock.h> | ||
46 | #include <linux/interrupt.h> | ||
47 | #include <linux/dma-mapping.h> | ||
48 | #include <linux/delay.h> | ||
49 | #include <linux/io.h> | ||
50 | #include <linux/slab.h> | ||
51 | #include <linux/usb.h> | ||
52 | |||
53 | #include <linux/usb/hcd.h> | ||
54 | #include <linux/usb/ch11.h> | ||
55 | |||
56 | #include "core.h" | ||
57 | #include "hcd.h" | ||
58 | |||
59 | /** | ||
60 | * dwc2_enable_common_interrupts() - Initializes the commmon interrupts, | ||
61 | * used in both device and host modes | ||
62 | * | ||
63 | * @hsotg: Programming view of the DWC_otg controller | ||
64 | */ | ||
65 | static void dwc2_enable_common_interrupts(struct dwc2_hsotg *hsotg) | ||
66 | { | ||
67 | u32 intmsk; | ||
68 | |||
69 | /* Clear any pending OTG Interrupts */ | ||
70 | writel(0xffffffff, hsotg->regs + GOTGINT); | ||
71 | |||
72 | /* Clear any pending interrupts */ | ||
73 | writel(0xffffffff, hsotg->regs + GINTSTS); | ||
74 | |||
75 | /* Enable the interrupts in the GINTMSK */ | ||
76 | intmsk = GINTSTS_MODEMIS | GINTSTS_OTGINT; | ||
77 | |||
78 | if (hsotg->core_params->dma_enable <= 0) | ||
79 | intmsk |= GINTSTS_RXFLVL; | ||
80 | |||
81 | intmsk |= GINTSTS_CONIDSTSCHNG | GINTSTS_WKUPINT | GINTSTS_USBSUSP | | ||
82 | GINTSTS_SESSREQINT; | ||
83 | |||
84 | writel(intmsk, hsotg->regs + GINTMSK); | ||
85 | } | ||
86 | |||
87 | /* | ||
88 | * Initializes the FSLSPClkSel field of the HCFG register depending on the | ||
89 | * PHY type | ||
90 | */ | ||
91 | static void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg) | ||
92 | { | ||
93 | u32 hcfg, val; | ||
94 | |||
95 | if ((hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI && | ||
96 | hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED && | ||
97 | hsotg->core_params->ulpi_fs_ls > 0) || | ||
98 | hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) { | ||
99 | /* Full speed PHY */ | ||
100 | val = HCFG_FSLSPCLKSEL_48_MHZ; | ||
101 | } else { | ||
102 | /* High speed PHY running at full speed or high speed */ | ||
103 | val = HCFG_FSLSPCLKSEL_30_60_MHZ; | ||
104 | } | ||
105 | |||
106 | dev_dbg(hsotg->dev, "Initializing HCFG.FSLSPClkSel to %08x\n", val); | ||
107 | hcfg = readl(hsotg->regs + HCFG); | ||
108 | hcfg &= ~HCFG_FSLSPCLKSEL_MASK; | ||
109 | hcfg |= val << HCFG_FSLSPCLKSEL_SHIFT; | ||
110 | writel(hcfg, hsotg->regs + HCFG); | ||
111 | } | ||
112 | |||
113 | /* | ||
114 | * Do core a soft reset of the core. Be careful with this because it | ||
115 | * resets all the internal state machines of the core. | ||
116 | */ | ||
117 | static int dwc2_core_reset(struct dwc2_hsotg *hsotg) | ||
118 | { | ||
119 | u32 greset; | ||
120 | int count = 0; | ||
121 | |||
122 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
123 | |||
124 | /* Wait for AHB master IDLE state */ | ||
125 | do { | ||
126 | usleep_range(20000, 40000); | ||
127 | greset = readl(hsotg->regs + GRSTCTL); | ||
128 | if (++count > 50) { | ||
129 | dev_warn(hsotg->dev, | ||
130 | "%s() HANG! AHB Idle GRSTCTL=%0x\n", | ||
131 | __func__, greset); | ||
132 | return -EBUSY; | ||
133 | } | ||
134 | } while (!(greset & GRSTCTL_AHBIDLE)); | ||
135 | |||
136 | /* Core Soft Reset */ | ||
137 | count = 0; | ||
138 | greset |= GRSTCTL_CSFTRST; | ||
139 | writel(greset, hsotg->regs + GRSTCTL); | ||
140 | do { | ||
141 | usleep_range(20000, 40000); | ||
142 | greset = readl(hsotg->regs + GRSTCTL); | ||
143 | if (++count > 50) { | ||
144 | dev_warn(hsotg->dev, | ||
145 | "%s() HANG! Soft Reset GRSTCTL=%0x\n", | ||
146 | __func__, greset); | ||
147 | return -EBUSY; | ||
148 | } | ||
149 | } while (greset & GRSTCTL_CSFTRST); | ||
150 | |||
151 | /* | ||
152 | * NOTE: This long sleep is _very_ important, otherwise the core will | ||
153 | * not stay in host mode after a connector ID change! | ||
154 | */ | ||
155 | usleep_range(150000, 200000); | ||
156 | |||
157 | return 0; | ||
158 | } | ||
159 | |||
160 | static int dwc2_fs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) | ||
161 | { | ||
162 | u32 usbcfg, i2cctl; | ||
163 | int retval = 0; | ||
164 | |||
165 | /* | ||
166 | * core_init() is now called on every switch so only call the | ||
167 | * following for the first time through | ||
168 | */ | ||
169 | if (select_phy) { | ||
170 | dev_dbg(hsotg->dev, "FS PHY selected\n"); | ||
171 | usbcfg = readl(hsotg->regs + GUSBCFG); | ||
172 | usbcfg |= GUSBCFG_PHYSEL; | ||
173 | writel(usbcfg, hsotg->regs + GUSBCFG); | ||
174 | |||
175 | /* Reset after a PHY select */ | ||
176 | retval = dwc2_core_reset(hsotg); | ||
177 | if (retval) { | ||
178 | dev_err(hsotg->dev, "%s() Reset failed, aborting", | ||
179 | __func__); | ||
180 | return retval; | ||
181 | } | ||
182 | } | ||
183 | |||
184 | /* | ||
185 | * Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also | ||
186 | * do this on HNP Dev/Host mode switches (done in dev_init and | ||
187 | * host_init). | ||
188 | */ | ||
189 | if (dwc2_is_host_mode(hsotg)) | ||
190 | dwc2_init_fs_ls_pclk_sel(hsotg); | ||
191 | |||
192 | if (hsotg->core_params->i2c_enable > 0) { | ||
193 | dev_dbg(hsotg->dev, "FS PHY enabling I2C\n"); | ||
194 | |||
195 | /* Program GUSBCFG.OtgUtmiFsSel to I2C */ | ||
196 | usbcfg = readl(hsotg->regs + GUSBCFG); | ||
197 | usbcfg |= GUSBCFG_OTG_UTMI_FS_SEL; | ||
198 | writel(usbcfg, hsotg->regs + GUSBCFG); | ||
199 | |||
200 | /* Program GI2CCTL.I2CEn */ | ||
201 | i2cctl = readl(hsotg->regs + GI2CCTL); | ||
202 | i2cctl &= ~GI2CCTL_I2CDEVADDR_MASK; | ||
203 | i2cctl |= 1 << GI2CCTL_I2CDEVADDR_SHIFT; | ||
204 | i2cctl &= ~GI2CCTL_I2CEN; | ||
205 | writel(i2cctl, hsotg->regs + GI2CCTL); | ||
206 | i2cctl |= GI2CCTL_I2CEN; | ||
207 | writel(i2cctl, hsotg->regs + GI2CCTL); | ||
208 | } | ||
209 | |||
210 | return retval; | ||
211 | } | ||
212 | |||
213 | static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) | ||
214 | { | ||
215 | u32 usbcfg; | ||
216 | int retval = 0; | ||
217 | |||
218 | if (!select_phy) | ||
219 | return -ENODEV; | ||
220 | |||
221 | usbcfg = readl(hsotg->regs + GUSBCFG); | ||
222 | |||
223 | /* | ||
224 | * HS PHY parameters. These parameters are preserved during soft reset | ||
225 | * so only program the first time. Do a soft reset immediately after | ||
226 | * setting phyif. | ||
227 | */ | ||
228 | switch (hsotg->core_params->phy_type) { | ||
229 | case DWC2_PHY_TYPE_PARAM_ULPI: | ||
230 | /* ULPI interface */ | ||
231 | dev_dbg(hsotg->dev, "HS ULPI PHY selected\n"); | ||
232 | usbcfg |= GUSBCFG_ULPI_UTMI_SEL; | ||
233 | usbcfg &= ~(GUSBCFG_PHYIF16 | GUSBCFG_DDRSEL); | ||
234 | if (hsotg->core_params->phy_ulpi_ddr > 0) | ||
235 | usbcfg |= GUSBCFG_DDRSEL; | ||
236 | break; | ||
237 | case DWC2_PHY_TYPE_PARAM_UTMI: | ||
238 | /* UTMI+ interface */ | ||
239 | dev_dbg(hsotg->dev, "HS UTMI+ PHY selected\n"); | ||
240 | usbcfg &= ~(GUSBCFG_ULPI_UTMI_SEL | GUSBCFG_PHYIF16); | ||
241 | if (hsotg->core_params->phy_utmi_width == 16) | ||
242 | usbcfg |= GUSBCFG_PHYIF16; | ||
243 | break; | ||
244 | default: | ||
245 | dev_err(hsotg->dev, "FS PHY selected at HS!\n"); | ||
246 | break; | ||
247 | } | ||
248 | |||
249 | writel(usbcfg, hsotg->regs + GUSBCFG); | ||
250 | |||
251 | /* Reset after setting the PHY parameters */ | ||
252 | retval = dwc2_core_reset(hsotg); | ||
253 | if (retval) { | ||
254 | dev_err(hsotg->dev, "%s() Reset failed, aborting", | ||
255 | __func__); | ||
256 | return retval; | ||
257 | } | ||
258 | |||
259 | return retval; | ||
260 | } | ||
261 | |||
262 | static int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) | ||
263 | { | ||
264 | u32 usbcfg; | ||
265 | int retval = 0; | ||
266 | |||
267 | if (hsotg->core_params->speed == DWC2_SPEED_PARAM_FULL && | ||
268 | hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) { | ||
269 | /* If FS mode with FS PHY */ | ||
270 | retval = dwc2_fs_phy_init(hsotg, select_phy); | ||
271 | if (retval) | ||
272 | return retval; | ||
273 | } else { | ||
274 | /* High speed PHY */ | ||
275 | retval = dwc2_hs_phy_init(hsotg, select_phy); | ||
276 | if (retval) | ||
277 | return retval; | ||
278 | } | ||
279 | |||
280 | if (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI && | ||
281 | hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED && | ||
282 | hsotg->core_params->ulpi_fs_ls > 0) { | ||
283 | dev_dbg(hsotg->dev, "Setting ULPI FSLS\n"); | ||
284 | usbcfg = readl(hsotg->regs + GUSBCFG); | ||
285 | usbcfg |= GUSBCFG_ULPI_FS_LS; | ||
286 | usbcfg |= GUSBCFG_ULPI_CLK_SUSP_M; | ||
287 | writel(usbcfg, hsotg->regs + GUSBCFG); | ||
288 | } else { | ||
289 | usbcfg = readl(hsotg->regs + GUSBCFG); | ||
290 | usbcfg &= ~GUSBCFG_ULPI_FS_LS; | ||
291 | usbcfg &= ~GUSBCFG_ULPI_CLK_SUSP_M; | ||
292 | writel(usbcfg, hsotg->regs + GUSBCFG); | ||
293 | } | ||
294 | |||
295 | return retval; | ||
296 | } | ||
297 | |||
298 | static int dwc2_gahbcfg_init(struct dwc2_hsotg *hsotg) | ||
299 | { | ||
300 | u32 ahbcfg = readl(hsotg->regs + GAHBCFG); | ||
301 | |||
302 | switch (hsotg->hw_params.arch) { | ||
303 | case GHWCFG2_EXT_DMA_ARCH: | ||
304 | dev_err(hsotg->dev, "External DMA Mode not supported\n"); | ||
305 | return -EINVAL; | ||
306 | |||
307 | case GHWCFG2_INT_DMA_ARCH: | ||
308 | dev_dbg(hsotg->dev, "Internal DMA Mode\n"); | ||
309 | if (hsotg->core_params->ahbcfg != -1) { | ||
310 | ahbcfg &= GAHBCFG_CTRL_MASK; | ||
311 | ahbcfg |= hsotg->core_params->ahbcfg & | ||
312 | ~GAHBCFG_CTRL_MASK; | ||
313 | } | ||
314 | break; | ||
315 | |||
316 | case GHWCFG2_SLAVE_ONLY_ARCH: | ||
317 | default: | ||
318 | dev_dbg(hsotg->dev, "Slave Only Mode\n"); | ||
319 | break; | ||
320 | } | ||
321 | |||
322 | dev_dbg(hsotg->dev, "dma_enable:%d dma_desc_enable:%d\n", | ||
323 | hsotg->core_params->dma_enable, | ||
324 | hsotg->core_params->dma_desc_enable); | ||
325 | |||
326 | if (hsotg->core_params->dma_enable > 0) { | ||
327 | if (hsotg->core_params->dma_desc_enable > 0) | ||
328 | dev_dbg(hsotg->dev, "Using Descriptor DMA mode\n"); | ||
329 | else | ||
330 | dev_dbg(hsotg->dev, "Using Buffer DMA mode\n"); | ||
331 | } else { | ||
332 | dev_dbg(hsotg->dev, "Using Slave mode\n"); | ||
333 | hsotg->core_params->dma_desc_enable = 0; | ||
334 | } | ||
335 | |||
336 | if (hsotg->core_params->dma_enable > 0) | ||
337 | ahbcfg |= GAHBCFG_DMA_EN; | ||
338 | |||
339 | writel(ahbcfg, hsotg->regs + GAHBCFG); | ||
340 | |||
341 | return 0; | ||
342 | } | ||
343 | |||
344 | static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg) | ||
345 | { | ||
346 | u32 usbcfg; | ||
347 | |||
348 | usbcfg = readl(hsotg->regs + GUSBCFG); | ||
349 | usbcfg &= ~(GUSBCFG_HNPCAP | GUSBCFG_SRPCAP); | ||
350 | |||
351 | switch (hsotg->hw_params.op_mode) { | ||
352 | case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: | ||
353 | if (hsotg->core_params->otg_cap == | ||
354 | DWC2_CAP_PARAM_HNP_SRP_CAPABLE) | ||
355 | usbcfg |= GUSBCFG_HNPCAP; | ||
356 | if (hsotg->core_params->otg_cap != | ||
357 | DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE) | ||
358 | usbcfg |= GUSBCFG_SRPCAP; | ||
359 | break; | ||
360 | |||
361 | case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: | ||
362 | case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: | ||
363 | case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: | ||
364 | if (hsotg->core_params->otg_cap != | ||
365 | DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE) | ||
366 | usbcfg |= GUSBCFG_SRPCAP; | ||
367 | break; | ||
368 | |||
369 | case GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE: | ||
370 | case GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE: | ||
371 | case GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST: | ||
372 | default: | ||
373 | break; | ||
374 | } | ||
375 | |||
376 | writel(usbcfg, hsotg->regs + GUSBCFG); | ||
377 | } | ||
378 | |||
379 | /** | ||
380 | * dwc2_core_init() - Initializes the DWC_otg controller registers and | ||
381 | * prepares the core for device mode or host mode operation | ||
382 | * | ||
383 | * @hsotg: Programming view of the DWC_otg controller | ||
384 | * @select_phy: If true then also set the Phy type | ||
385 | * @irq: If >= 0, the irq to register | ||
386 | */ | ||
387 | int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq) | ||
388 | { | ||
389 | u32 usbcfg, otgctl; | ||
390 | int retval; | ||
391 | |||
392 | dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); | ||
393 | |||
394 | usbcfg = readl(hsotg->regs + GUSBCFG); | ||
395 | |||
396 | /* Set ULPI External VBUS bit if needed */ | ||
397 | usbcfg &= ~GUSBCFG_ULPI_EXT_VBUS_DRV; | ||
398 | if (hsotg->core_params->phy_ulpi_ext_vbus == | ||
399 | DWC2_PHY_ULPI_EXTERNAL_VBUS) | ||
400 | usbcfg |= GUSBCFG_ULPI_EXT_VBUS_DRV; | ||
401 | |||
402 | /* Set external TS Dline pulsing bit if needed */ | ||
403 | usbcfg &= ~GUSBCFG_TERMSELDLPULSE; | ||
404 | if (hsotg->core_params->ts_dline > 0) | ||
405 | usbcfg |= GUSBCFG_TERMSELDLPULSE; | ||
406 | |||
407 | writel(usbcfg, hsotg->regs + GUSBCFG); | ||
408 | |||
409 | /* Reset the Controller */ | ||
410 | retval = dwc2_core_reset(hsotg); | ||
411 | if (retval) { | ||
412 | dev_err(hsotg->dev, "%s(): Reset failed, aborting\n", | ||
413 | __func__); | ||
414 | return retval; | ||
415 | } | ||
416 | |||
417 | /* | ||
418 | * This needs to happen in FS mode before any other programming occurs | ||
419 | */ | ||
420 | retval = dwc2_phy_init(hsotg, select_phy); | ||
421 | if (retval) | ||
422 | return retval; | ||
423 | |||
424 | /* Program the GAHBCFG Register */ | ||
425 | retval = dwc2_gahbcfg_init(hsotg); | ||
426 | if (retval) | ||
427 | return retval; | ||
428 | |||
429 | /* Program the GUSBCFG register */ | ||
430 | dwc2_gusbcfg_init(hsotg); | ||
431 | |||
432 | /* Program the GOTGCTL register */ | ||
433 | otgctl = readl(hsotg->regs + GOTGCTL); | ||
434 | otgctl &= ~GOTGCTL_OTGVER; | ||
435 | if (hsotg->core_params->otg_ver > 0) | ||
436 | otgctl |= GOTGCTL_OTGVER; | ||
437 | writel(otgctl, hsotg->regs + GOTGCTL); | ||
438 | dev_dbg(hsotg->dev, "OTG VER PARAM: %d\n", hsotg->core_params->otg_ver); | ||
439 | |||
440 | /* Clear the SRP success bit for FS-I2c */ | ||
441 | hsotg->srp_success = 0; | ||
442 | |||
443 | if (irq >= 0) { | ||
444 | dev_dbg(hsotg->dev, "registering common handler for irq%d\n", | ||
445 | irq); | ||
446 | retval = devm_request_irq(hsotg->dev, irq, | ||
447 | dwc2_handle_common_intr, IRQF_SHARED, | ||
448 | dev_name(hsotg->dev), hsotg); | ||
449 | if (retval) | ||
450 | return retval; | ||
451 | } | ||
452 | |||
453 | /* Enable common interrupts */ | ||
454 | dwc2_enable_common_interrupts(hsotg); | ||
455 | |||
456 | /* | ||
457 | * Do device or host intialization based on mode during PCD and | ||
458 | * HCD initialization | ||
459 | */ | ||
460 | if (dwc2_is_host_mode(hsotg)) { | ||
461 | dev_dbg(hsotg->dev, "Host Mode\n"); | ||
462 | hsotg->op_state = OTG_STATE_A_HOST; | ||
463 | } else { | ||
464 | dev_dbg(hsotg->dev, "Device Mode\n"); | ||
465 | hsotg->op_state = OTG_STATE_B_PERIPHERAL; | ||
466 | } | ||
467 | |||
468 | return 0; | ||
469 | } | ||
470 | |||
471 | /** | ||
472 | * dwc2_enable_host_interrupts() - Enables the Host mode interrupts | ||
473 | * | ||
474 | * @hsotg: Programming view of DWC_otg controller | ||
475 | */ | ||
476 | void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg) | ||
477 | { | ||
478 | u32 intmsk; | ||
479 | |||
480 | dev_dbg(hsotg->dev, "%s()\n", __func__); | ||
481 | |||
482 | /* Disable all interrupts */ | ||
483 | writel(0, hsotg->regs + GINTMSK); | ||
484 | writel(0, hsotg->regs + HAINTMSK); | ||
485 | |||
486 | /* Enable the common interrupts */ | ||
487 | dwc2_enable_common_interrupts(hsotg); | ||
488 | |||
489 | /* Enable host mode interrupts without disturbing common interrupts */ | ||
490 | intmsk = readl(hsotg->regs + GINTMSK); | ||
491 | intmsk |= GINTSTS_DISCONNINT | GINTSTS_PRTINT | GINTSTS_HCHINT; | ||
492 | writel(intmsk, hsotg->regs + GINTMSK); | ||
493 | } | ||
494 | |||
495 | /** | ||
496 | * dwc2_disable_host_interrupts() - Disables the Host Mode interrupts | ||
497 | * | ||
498 | * @hsotg: Programming view of DWC_otg controller | ||
499 | */ | ||
500 | void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg) | ||
501 | { | ||
502 | u32 intmsk = readl(hsotg->regs + GINTMSK); | ||
503 | |||
504 | /* Disable host mode interrupts without disturbing common interrupts */ | ||
505 | intmsk &= ~(GINTSTS_SOF | GINTSTS_PRTINT | GINTSTS_HCHINT | | ||
506 | GINTSTS_PTXFEMP | GINTSTS_NPTXFEMP); | ||
507 | writel(intmsk, hsotg->regs + GINTMSK); | ||
508 | } | ||
509 | |||
510 | static void dwc2_config_fifos(struct dwc2_hsotg *hsotg) | ||
511 | { | ||
512 | struct dwc2_core_params *params = hsotg->core_params; | ||
513 | u32 nptxfsiz, hptxfsiz, dfifocfg, grxfsiz; | ||
514 | |||
515 | if (!params->enable_dynamic_fifo) | ||
516 | return; | ||
517 | |||
518 | /* Rx FIFO */ | ||
519 | grxfsiz = readl(hsotg->regs + GRXFSIZ); | ||
520 | dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz); | ||
521 | grxfsiz &= ~GRXFSIZ_DEPTH_MASK; | ||
522 | grxfsiz |= params->host_rx_fifo_size << | ||
523 | GRXFSIZ_DEPTH_SHIFT & GRXFSIZ_DEPTH_MASK; | ||
524 | writel(grxfsiz, hsotg->regs + GRXFSIZ); | ||
525 | dev_dbg(hsotg->dev, "new grxfsiz=%08x\n", readl(hsotg->regs + GRXFSIZ)); | ||
526 | |||
527 | /* Non-periodic Tx FIFO */ | ||
528 | dev_dbg(hsotg->dev, "initial gnptxfsiz=%08x\n", | ||
529 | readl(hsotg->regs + GNPTXFSIZ)); | ||
530 | nptxfsiz = params->host_nperio_tx_fifo_size << | ||
531 | FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK; | ||
532 | nptxfsiz |= params->host_rx_fifo_size << | ||
533 | FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK; | ||
534 | writel(nptxfsiz, hsotg->regs + GNPTXFSIZ); | ||
535 | dev_dbg(hsotg->dev, "new gnptxfsiz=%08x\n", | ||
536 | readl(hsotg->regs + GNPTXFSIZ)); | ||
537 | |||
538 | /* Periodic Tx FIFO */ | ||
539 | dev_dbg(hsotg->dev, "initial hptxfsiz=%08x\n", | ||
540 | readl(hsotg->regs + HPTXFSIZ)); | ||
541 | hptxfsiz = params->host_perio_tx_fifo_size << | ||
542 | FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK; | ||
543 | hptxfsiz |= (params->host_rx_fifo_size + | ||
544 | params->host_nperio_tx_fifo_size) << | ||
545 | FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK; | ||
546 | writel(hptxfsiz, hsotg->regs + HPTXFSIZ); | ||
547 | dev_dbg(hsotg->dev, "new hptxfsiz=%08x\n", | ||
548 | readl(hsotg->regs + HPTXFSIZ)); | ||
549 | |||
550 | if (hsotg->core_params->en_multiple_tx_fifo > 0 && | ||
551 | hsotg->hw_params.snpsid <= DWC2_CORE_REV_2_94a) { | ||
552 | /* | ||
553 | * Global DFIFOCFG calculation for Host mode - | ||
554 | * include RxFIFO, NPTXFIFO and HPTXFIFO | ||
555 | */ | ||
556 | dfifocfg = readl(hsotg->regs + GDFIFOCFG); | ||
557 | dfifocfg &= ~GDFIFOCFG_EPINFOBASE_MASK; | ||
558 | dfifocfg |= (params->host_rx_fifo_size + | ||
559 | params->host_nperio_tx_fifo_size + | ||
560 | params->host_perio_tx_fifo_size) << | ||
561 | GDFIFOCFG_EPINFOBASE_SHIFT & | ||
562 | GDFIFOCFG_EPINFOBASE_MASK; | ||
563 | writel(dfifocfg, hsotg->regs + GDFIFOCFG); | ||
564 | } | ||
565 | } | ||
566 | |||
567 | /** | ||
568 | * dwc2_core_host_init() - Initializes the DWC_otg controller registers for | ||
569 | * Host mode | ||
570 | * | ||
571 | * @hsotg: Programming view of DWC_otg controller | ||
572 | * | ||
573 | * This function flushes the Tx and Rx FIFOs and flushes any entries in the | ||
574 | * request queues. Host channels are reset to ensure that they are ready for | ||
575 | * performing transfers. | ||
576 | */ | ||
577 | void dwc2_core_host_init(struct dwc2_hsotg *hsotg) | ||
578 | { | ||
579 | u32 hcfg, hfir, otgctl; | ||
580 | |||
581 | dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); | ||
582 | |||
583 | /* Restart the Phy Clock */ | ||
584 | writel(0, hsotg->regs + PCGCTL); | ||
585 | |||
586 | /* Initialize Host Configuration Register */ | ||
587 | dwc2_init_fs_ls_pclk_sel(hsotg); | ||
588 | if (hsotg->core_params->speed == DWC2_SPEED_PARAM_FULL) { | ||
589 | hcfg = readl(hsotg->regs + HCFG); | ||
590 | hcfg |= HCFG_FSLSSUPP; | ||
591 | writel(hcfg, hsotg->regs + HCFG); | ||
592 | } | ||
593 | |||
594 | /* | ||
595 | * This bit allows dynamic reloading of the HFIR register during | ||
596 | * runtime. This bit needs to be programmed during initial configuration | ||
597 | * and its value must not be changed during runtime. | ||
598 | */ | ||
599 | if (hsotg->core_params->reload_ctl > 0) { | ||
600 | hfir = readl(hsotg->regs + HFIR); | ||
601 | hfir |= HFIR_RLDCTRL; | ||
602 | writel(hfir, hsotg->regs + HFIR); | ||
603 | } | ||
604 | |||
605 | if (hsotg->core_params->dma_desc_enable > 0) { | ||
606 | u32 op_mode = hsotg->hw_params.op_mode; | ||
607 | if (hsotg->hw_params.snpsid < DWC2_CORE_REV_2_90a || | ||
608 | !hsotg->hw_params.dma_desc_enable || | ||
609 | op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE || | ||
610 | op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE || | ||
611 | op_mode == GHWCFG2_OP_MODE_UNDEFINED) { | ||
612 | dev_err(hsotg->dev, | ||
613 | "Hardware does not support descriptor DMA mode -\n"); | ||
614 | dev_err(hsotg->dev, | ||
615 | "falling back to buffer DMA mode.\n"); | ||
616 | hsotg->core_params->dma_desc_enable = 0; | ||
617 | } else { | ||
618 | hcfg = readl(hsotg->regs + HCFG); | ||
619 | hcfg |= HCFG_DESCDMA; | ||
620 | writel(hcfg, hsotg->regs + HCFG); | ||
621 | } | ||
622 | } | ||
623 | |||
624 | /* Configure data FIFO sizes */ | ||
625 | dwc2_config_fifos(hsotg); | ||
626 | |||
627 | /* TODO - check this */ | ||
628 | /* Clear Host Set HNP Enable in the OTG Control Register */ | ||
629 | otgctl = readl(hsotg->regs + GOTGCTL); | ||
630 | otgctl &= ~GOTGCTL_HSTSETHNPEN; | ||
631 | writel(otgctl, hsotg->regs + GOTGCTL); | ||
632 | |||
633 | /* Make sure the FIFOs are flushed */ | ||
634 | dwc2_flush_tx_fifo(hsotg, 0x10 /* all TX FIFOs */); | ||
635 | dwc2_flush_rx_fifo(hsotg); | ||
636 | |||
637 | /* Clear Host Set HNP Enable in the OTG Control Register */ | ||
638 | otgctl = readl(hsotg->regs + GOTGCTL); | ||
639 | otgctl &= ~GOTGCTL_HSTSETHNPEN; | ||
640 | writel(otgctl, hsotg->regs + GOTGCTL); | ||
641 | |||
642 | if (hsotg->core_params->dma_desc_enable <= 0) { | ||
643 | int num_channels, i; | ||
644 | u32 hcchar; | ||
645 | |||
646 | /* Flush out any leftover queued requests */ | ||
647 | num_channels = hsotg->core_params->host_channels; | ||
648 | for (i = 0; i < num_channels; i++) { | ||
649 | hcchar = readl(hsotg->regs + HCCHAR(i)); | ||
650 | hcchar &= ~HCCHAR_CHENA; | ||
651 | hcchar |= HCCHAR_CHDIS; | ||
652 | hcchar &= ~HCCHAR_EPDIR; | ||
653 | writel(hcchar, hsotg->regs + HCCHAR(i)); | ||
654 | } | ||
655 | |||
656 | /* Halt all channels to put them into a known state */ | ||
657 | for (i = 0; i < num_channels; i++) { | ||
658 | int count = 0; | ||
659 | |||
660 | hcchar = readl(hsotg->regs + HCCHAR(i)); | ||
661 | hcchar |= HCCHAR_CHENA | HCCHAR_CHDIS; | ||
662 | hcchar &= ~HCCHAR_EPDIR; | ||
663 | writel(hcchar, hsotg->regs + HCCHAR(i)); | ||
664 | dev_dbg(hsotg->dev, "%s: Halt channel %d\n", | ||
665 | __func__, i); | ||
666 | do { | ||
667 | hcchar = readl(hsotg->regs + HCCHAR(i)); | ||
668 | if (++count > 1000) { | ||
669 | dev_err(hsotg->dev, | ||
670 | "Unable to clear enable on channel %d\n", | ||
671 | i); | ||
672 | break; | ||
673 | } | ||
674 | udelay(1); | ||
675 | } while (hcchar & HCCHAR_CHENA); | ||
676 | } | ||
677 | } | ||
678 | |||
679 | /* Turn on the vbus power */ | ||
680 | dev_dbg(hsotg->dev, "Init: Port Power? op_state=%d\n", hsotg->op_state); | ||
681 | if (hsotg->op_state == OTG_STATE_A_HOST) { | ||
682 | u32 hprt0 = dwc2_read_hprt0(hsotg); | ||
683 | |||
684 | dev_dbg(hsotg->dev, "Init: Power Port (%d)\n", | ||
685 | !!(hprt0 & HPRT0_PWR)); | ||
686 | if (!(hprt0 & HPRT0_PWR)) { | ||
687 | hprt0 |= HPRT0_PWR; | ||
688 | writel(hprt0, hsotg->regs + HPRT0); | ||
689 | } | ||
690 | } | ||
691 | |||
692 | dwc2_enable_host_interrupts(hsotg); | ||
693 | } | ||
694 | |||
695 | static void dwc2_hc_enable_slave_ints(struct dwc2_hsotg *hsotg, | ||
696 | struct dwc2_host_chan *chan) | ||
697 | { | ||
698 | u32 hcintmsk = HCINTMSK_CHHLTD; | ||
699 | |||
700 | switch (chan->ep_type) { | ||
701 | case USB_ENDPOINT_XFER_CONTROL: | ||
702 | case USB_ENDPOINT_XFER_BULK: | ||
703 | dev_vdbg(hsotg->dev, "control/bulk\n"); | ||
704 | hcintmsk |= HCINTMSK_XFERCOMPL; | ||
705 | hcintmsk |= HCINTMSK_STALL; | ||
706 | hcintmsk |= HCINTMSK_XACTERR; | ||
707 | hcintmsk |= HCINTMSK_DATATGLERR; | ||
708 | if (chan->ep_is_in) { | ||
709 | hcintmsk |= HCINTMSK_BBLERR; | ||
710 | } else { | ||
711 | hcintmsk |= HCINTMSK_NAK; | ||
712 | hcintmsk |= HCINTMSK_NYET; | ||
713 | if (chan->do_ping) | ||
714 | hcintmsk |= HCINTMSK_ACK; | ||
715 | } | ||
716 | |||
717 | if (chan->do_split) { | ||
718 | hcintmsk |= HCINTMSK_NAK; | ||
719 | if (chan->complete_split) | ||
720 | hcintmsk |= HCINTMSK_NYET; | ||
721 | else | ||
722 | hcintmsk |= HCINTMSK_ACK; | ||
723 | } | ||
724 | |||
725 | if (chan->error_state) | ||
726 | hcintmsk |= HCINTMSK_ACK; | ||
727 | break; | ||
728 | |||
729 | case USB_ENDPOINT_XFER_INT: | ||
730 | if (dbg_perio()) | ||
731 | dev_vdbg(hsotg->dev, "intr\n"); | ||
732 | hcintmsk |= HCINTMSK_XFERCOMPL; | ||
733 | hcintmsk |= HCINTMSK_NAK; | ||
734 | hcintmsk |= HCINTMSK_STALL; | ||
735 | hcintmsk |= HCINTMSK_XACTERR; | ||
736 | hcintmsk |= HCINTMSK_DATATGLERR; | ||
737 | hcintmsk |= HCINTMSK_FRMOVRUN; | ||
738 | |||
739 | if (chan->ep_is_in) | ||
740 | hcintmsk |= HCINTMSK_BBLERR; | ||
741 | if (chan->error_state) | ||
742 | hcintmsk |= HCINTMSK_ACK; | ||
743 | if (chan->do_split) { | ||
744 | if (chan->complete_split) | ||
745 | hcintmsk |= HCINTMSK_NYET; | ||
746 | else | ||
747 | hcintmsk |= HCINTMSK_ACK; | ||
748 | } | ||
749 | break; | ||
750 | |||
751 | case USB_ENDPOINT_XFER_ISOC: | ||
752 | if (dbg_perio()) | ||
753 | dev_vdbg(hsotg->dev, "isoc\n"); | ||
754 | hcintmsk |= HCINTMSK_XFERCOMPL; | ||
755 | hcintmsk |= HCINTMSK_FRMOVRUN; | ||
756 | hcintmsk |= HCINTMSK_ACK; | ||
757 | |||
758 | if (chan->ep_is_in) { | ||
759 | hcintmsk |= HCINTMSK_XACTERR; | ||
760 | hcintmsk |= HCINTMSK_BBLERR; | ||
761 | } | ||
762 | break; | ||
763 | default: | ||
764 | dev_err(hsotg->dev, "## Unknown EP type ##\n"); | ||
765 | break; | ||
766 | } | ||
767 | |||
768 | writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num)); | ||
769 | if (dbg_hc(chan)) | ||
770 | dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk); | ||
771 | } | ||
772 | |||
773 | static void dwc2_hc_enable_dma_ints(struct dwc2_hsotg *hsotg, | ||
774 | struct dwc2_host_chan *chan) | ||
775 | { | ||
776 | u32 hcintmsk = HCINTMSK_CHHLTD; | ||
777 | |||
778 | /* | ||
779 | * For Descriptor DMA mode core halts the channel on AHB error. | ||
780 | * Interrupt is not required. | ||
781 | */ | ||
782 | if (hsotg->core_params->dma_desc_enable <= 0) { | ||
783 | if (dbg_hc(chan)) | ||
784 | dev_vdbg(hsotg->dev, "desc DMA disabled\n"); | ||
785 | hcintmsk |= HCINTMSK_AHBERR; | ||
786 | } else { | ||
787 | if (dbg_hc(chan)) | ||
788 | dev_vdbg(hsotg->dev, "desc DMA enabled\n"); | ||
789 | if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) | ||
790 | hcintmsk |= HCINTMSK_XFERCOMPL; | ||
791 | } | ||
792 | |||
793 | if (chan->error_state && !chan->do_split && | ||
794 | chan->ep_type != USB_ENDPOINT_XFER_ISOC) { | ||
795 | if (dbg_hc(chan)) | ||
796 | dev_vdbg(hsotg->dev, "setting ACK\n"); | ||
797 | hcintmsk |= HCINTMSK_ACK; | ||
798 | if (chan->ep_is_in) { | ||
799 | hcintmsk |= HCINTMSK_DATATGLERR; | ||
800 | if (chan->ep_type != USB_ENDPOINT_XFER_INT) | ||
801 | hcintmsk |= HCINTMSK_NAK; | ||
802 | } | ||
803 | } | ||
804 | |||
805 | writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num)); | ||
806 | if (dbg_hc(chan)) | ||
807 | dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk); | ||
808 | } | ||
809 | |||
810 | static void dwc2_hc_enable_ints(struct dwc2_hsotg *hsotg, | ||
811 | struct dwc2_host_chan *chan) | ||
812 | { | ||
813 | u32 intmsk; | ||
814 | |||
815 | if (hsotg->core_params->dma_enable > 0) { | ||
816 | if (dbg_hc(chan)) | ||
817 | dev_vdbg(hsotg->dev, "DMA enabled\n"); | ||
818 | dwc2_hc_enable_dma_ints(hsotg, chan); | ||
819 | } else { | ||
820 | if (dbg_hc(chan)) | ||
821 | dev_vdbg(hsotg->dev, "DMA disabled\n"); | ||
822 | dwc2_hc_enable_slave_ints(hsotg, chan); | ||
823 | } | ||
824 | |||
825 | /* Enable the top level host channel interrupt */ | ||
826 | intmsk = readl(hsotg->regs + HAINTMSK); | ||
827 | intmsk |= 1 << chan->hc_num; | ||
828 | writel(intmsk, hsotg->regs + HAINTMSK); | ||
829 | if (dbg_hc(chan)) | ||
830 | dev_vdbg(hsotg->dev, "set HAINTMSK to %08x\n", intmsk); | ||
831 | |||
832 | /* Make sure host channel interrupts are enabled */ | ||
833 | intmsk = readl(hsotg->regs + GINTMSK); | ||
834 | intmsk |= GINTSTS_HCHINT; | ||
835 | writel(intmsk, hsotg->regs + GINTMSK); | ||
836 | if (dbg_hc(chan)) | ||
837 | dev_vdbg(hsotg->dev, "set GINTMSK to %08x\n", intmsk); | ||
838 | } | ||
839 | |||
840 | /** | ||
841 | * dwc2_hc_init() - Prepares a host channel for transferring packets to/from | ||
842 | * a specific endpoint | ||
843 | * | ||
844 | * @hsotg: Programming view of DWC_otg controller | ||
845 | * @chan: Information needed to initialize the host channel | ||
846 | * | ||
847 | * The HCCHARn register is set up with the characteristics specified in chan. | ||
848 | * Host channel interrupts that may need to be serviced while this transfer is | ||
849 | * in progress are enabled. | ||
850 | */ | ||
851 | void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) | ||
852 | { | ||
853 | u8 hc_num = chan->hc_num; | ||
854 | u32 hcintmsk; | ||
855 | u32 hcchar; | ||
856 | u32 hcsplt = 0; | ||
857 | |||
858 | if (dbg_hc(chan)) | ||
859 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
860 | |||
861 | /* Clear old interrupt conditions for this host channel */ | ||
862 | hcintmsk = 0xffffffff; | ||
863 | hcintmsk &= ~HCINTMSK_RESERVED14_31; | ||
864 | writel(hcintmsk, hsotg->regs + HCINT(hc_num)); | ||
865 | |||
866 | /* Enable channel interrupts required for this transfer */ | ||
867 | dwc2_hc_enable_ints(hsotg, chan); | ||
868 | |||
869 | /* | ||
870 | * Program the HCCHARn register with the endpoint characteristics for | ||
871 | * the current transfer | ||
872 | */ | ||
873 | hcchar = chan->dev_addr << HCCHAR_DEVADDR_SHIFT & HCCHAR_DEVADDR_MASK; | ||
874 | hcchar |= chan->ep_num << HCCHAR_EPNUM_SHIFT & HCCHAR_EPNUM_MASK; | ||
875 | if (chan->ep_is_in) | ||
876 | hcchar |= HCCHAR_EPDIR; | ||
877 | if (chan->speed == USB_SPEED_LOW) | ||
878 | hcchar |= HCCHAR_LSPDDEV; | ||
879 | hcchar |= chan->ep_type << HCCHAR_EPTYPE_SHIFT & HCCHAR_EPTYPE_MASK; | ||
880 | hcchar |= chan->max_packet << HCCHAR_MPS_SHIFT & HCCHAR_MPS_MASK; | ||
881 | writel(hcchar, hsotg->regs + HCCHAR(hc_num)); | ||
882 | if (dbg_hc(chan)) { | ||
883 | dev_vdbg(hsotg->dev, "set HCCHAR(%d) to %08x\n", | ||
884 | hc_num, hcchar); | ||
885 | |||
886 | dev_vdbg(hsotg->dev, "%s: Channel %d\n", | ||
887 | __func__, hc_num); | ||
888 | dev_vdbg(hsotg->dev, " Dev Addr: %d\n", | ||
889 | chan->dev_addr); | ||
890 | dev_vdbg(hsotg->dev, " Ep Num: %d\n", | ||
891 | chan->ep_num); | ||
892 | dev_vdbg(hsotg->dev, " Is In: %d\n", | ||
893 | chan->ep_is_in); | ||
894 | dev_vdbg(hsotg->dev, " Is Low Speed: %d\n", | ||
895 | chan->speed == USB_SPEED_LOW); | ||
896 | dev_vdbg(hsotg->dev, " Ep Type: %d\n", | ||
897 | chan->ep_type); | ||
898 | dev_vdbg(hsotg->dev, " Max Pkt: %d\n", | ||
899 | chan->max_packet); | ||
900 | } | ||
901 | |||
902 | /* Program the HCSPLT register for SPLITs */ | ||
903 | if (chan->do_split) { | ||
904 | if (dbg_hc(chan)) | ||
905 | dev_vdbg(hsotg->dev, | ||
906 | "Programming HC %d with split --> %s\n", | ||
907 | hc_num, | ||
908 | chan->complete_split ? "CSPLIT" : "SSPLIT"); | ||
909 | if (chan->complete_split) | ||
910 | hcsplt |= HCSPLT_COMPSPLT; | ||
911 | hcsplt |= chan->xact_pos << HCSPLT_XACTPOS_SHIFT & | ||
912 | HCSPLT_XACTPOS_MASK; | ||
913 | hcsplt |= chan->hub_addr << HCSPLT_HUBADDR_SHIFT & | ||
914 | HCSPLT_HUBADDR_MASK; | ||
915 | hcsplt |= chan->hub_port << HCSPLT_PRTADDR_SHIFT & | ||
916 | HCSPLT_PRTADDR_MASK; | ||
917 | if (dbg_hc(chan)) { | ||
918 | dev_vdbg(hsotg->dev, " comp split %d\n", | ||
919 | chan->complete_split); | ||
920 | dev_vdbg(hsotg->dev, " xact pos %d\n", | ||
921 | chan->xact_pos); | ||
922 | dev_vdbg(hsotg->dev, " hub addr %d\n", | ||
923 | chan->hub_addr); | ||
924 | dev_vdbg(hsotg->dev, " hub port %d\n", | ||
925 | chan->hub_port); | ||
926 | dev_vdbg(hsotg->dev, " is_in %d\n", | ||
927 | chan->ep_is_in); | ||
928 | dev_vdbg(hsotg->dev, " Max Pkt %d\n", | ||
929 | chan->max_packet); | ||
930 | dev_vdbg(hsotg->dev, " xferlen %d\n", | ||
931 | chan->xfer_len); | ||
932 | } | ||
933 | } | ||
934 | |||
935 | writel(hcsplt, hsotg->regs + HCSPLT(hc_num)); | ||
936 | } | ||
937 | |||
938 | /** | ||
939 | * dwc2_hc_halt() - Attempts to halt a host channel | ||
940 | * | ||
941 | * @hsotg: Controller register interface | ||
942 | * @chan: Host channel to halt | ||
943 | * @halt_status: Reason for halting the channel | ||
944 | * | ||
945 | * This function should only be called in Slave mode or to abort a transfer in | ||
946 | * either Slave mode or DMA mode. Under normal circumstances in DMA mode, the | ||
947 | * controller halts the channel when the transfer is complete or a condition | ||
948 | * occurs that requires application intervention. | ||
949 | * | ||
950 | * In slave mode, checks for a free request queue entry, then sets the Channel | ||
951 | * Enable and Channel Disable bits of the Host Channel Characteristics | ||
952 | * register of the specified channel to intiate the halt. If there is no free | ||
953 | * request queue entry, sets only the Channel Disable bit of the HCCHARn | ||
954 | * register to flush requests for this channel. In the latter case, sets a | ||
955 | * flag to indicate that the host channel needs to be halted when a request | ||
956 | * queue slot is open. | ||
957 | * | ||
958 | * In DMA mode, always sets the Channel Enable and Channel Disable bits of the | ||
959 | * HCCHARn register. The controller ensures there is space in the request | ||
960 | * queue before submitting the halt request. | ||
961 | * | ||
962 | * Some time may elapse before the core flushes any posted requests for this | ||
963 | * host channel and halts. The Channel Halted interrupt handler completes the | ||
964 | * deactivation of the host channel. | ||
965 | */ | ||
966 | void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan, | ||
967 | enum dwc2_halt_status halt_status) | ||
968 | { | ||
969 | u32 nptxsts, hptxsts, hcchar; | ||
970 | |||
971 | if (dbg_hc(chan)) | ||
972 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
973 | if (halt_status == DWC2_HC_XFER_NO_HALT_STATUS) | ||
974 | dev_err(hsotg->dev, "!!! halt_status = %d !!!\n", halt_status); | ||
975 | |||
976 | if (halt_status == DWC2_HC_XFER_URB_DEQUEUE || | ||
977 | halt_status == DWC2_HC_XFER_AHB_ERR) { | ||
978 | /* | ||
979 | * Disable all channel interrupts except Ch Halted. The QTD | ||
980 | * and QH state associated with this transfer has been cleared | ||
981 | * (in the case of URB_DEQUEUE), so the channel needs to be | ||
982 | * shut down carefully to prevent crashes. | ||
983 | */ | ||
984 | u32 hcintmsk = HCINTMSK_CHHLTD; | ||
985 | |||
986 | dev_vdbg(hsotg->dev, "dequeue/error\n"); | ||
987 | writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num)); | ||
988 | |||
989 | /* | ||
990 | * Make sure no other interrupts besides halt are currently | ||
991 | * pending. Handling another interrupt could cause a crash due | ||
992 | * to the QTD and QH state. | ||
993 | */ | ||
994 | writel(~hcintmsk, hsotg->regs + HCINT(chan->hc_num)); | ||
995 | |||
996 | /* | ||
997 | * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR | ||
998 | * even if the channel was already halted for some other | ||
999 | * reason | ||
1000 | */ | ||
1001 | chan->halt_status = halt_status; | ||
1002 | |||
1003 | hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); | ||
1004 | if (!(hcchar & HCCHAR_CHENA)) { | ||
1005 | /* | ||
1006 | * The channel is either already halted or it hasn't | ||
1007 | * started yet. In DMA mode, the transfer may halt if | ||
1008 | * it finishes normally or a condition occurs that | ||
1009 | * requires driver intervention. Don't want to halt | ||
1010 | * the channel again. In either Slave or DMA mode, | ||
1011 | * it's possible that the transfer has been assigned | ||
1012 | * to a channel, but not started yet when an URB is | ||
1013 | * dequeued. Don't want to halt a channel that hasn't | ||
1014 | * started yet. | ||
1015 | */ | ||
1016 | return; | ||
1017 | } | ||
1018 | } | ||
1019 | if (chan->halt_pending) { | ||
1020 | /* | ||
1021 | * A halt has already been issued for this channel. This might | ||
1022 | * happen when a transfer is aborted by a higher level in | ||
1023 | * the stack. | ||
1024 | */ | ||
1025 | dev_vdbg(hsotg->dev, | ||
1026 | "*** %s: Channel %d, chan->halt_pending already set ***\n", | ||
1027 | __func__, chan->hc_num); | ||
1028 | return; | ||
1029 | } | ||
1030 | |||
1031 | hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); | ||
1032 | |||
1033 | /* No need to set the bit in DDMA for disabling the channel */ | ||
1034 | /* TODO check it everywhere channel is disabled */ | ||
1035 | if (hsotg->core_params->dma_desc_enable <= 0) { | ||
1036 | if (dbg_hc(chan)) | ||
1037 | dev_vdbg(hsotg->dev, "desc DMA disabled\n"); | ||
1038 | hcchar |= HCCHAR_CHENA; | ||
1039 | } else { | ||
1040 | if (dbg_hc(chan)) | ||
1041 | dev_dbg(hsotg->dev, "desc DMA enabled\n"); | ||
1042 | } | ||
1043 | hcchar |= HCCHAR_CHDIS; | ||
1044 | |||
1045 | if (hsotg->core_params->dma_enable <= 0) { | ||
1046 | if (dbg_hc(chan)) | ||
1047 | dev_vdbg(hsotg->dev, "DMA not enabled\n"); | ||
1048 | hcchar |= HCCHAR_CHENA; | ||
1049 | |||
1050 | /* Check for space in the request queue to issue the halt */ | ||
1051 | if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL || | ||
1052 | chan->ep_type == USB_ENDPOINT_XFER_BULK) { | ||
1053 | dev_vdbg(hsotg->dev, "control/bulk\n"); | ||
1054 | nptxsts = readl(hsotg->regs + GNPTXSTS); | ||
1055 | if ((nptxsts & TXSTS_QSPCAVAIL_MASK) == 0) { | ||
1056 | dev_vdbg(hsotg->dev, "Disabling channel\n"); | ||
1057 | hcchar &= ~HCCHAR_CHENA; | ||
1058 | } | ||
1059 | } else { | ||
1060 | if (dbg_perio()) | ||
1061 | dev_vdbg(hsotg->dev, "isoc/intr\n"); | ||
1062 | hptxsts = readl(hsotg->regs + HPTXSTS); | ||
1063 | if ((hptxsts & TXSTS_QSPCAVAIL_MASK) == 0 || | ||
1064 | hsotg->queuing_high_bandwidth) { | ||
1065 | if (dbg_perio()) | ||
1066 | dev_vdbg(hsotg->dev, "Disabling channel\n"); | ||
1067 | hcchar &= ~HCCHAR_CHENA; | ||
1068 | } | ||
1069 | } | ||
1070 | } else { | ||
1071 | if (dbg_hc(chan)) | ||
1072 | dev_vdbg(hsotg->dev, "DMA enabled\n"); | ||
1073 | } | ||
1074 | |||
1075 | writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); | ||
1076 | chan->halt_status = halt_status; | ||
1077 | |||
1078 | if (hcchar & HCCHAR_CHENA) { | ||
1079 | if (dbg_hc(chan)) | ||
1080 | dev_vdbg(hsotg->dev, "Channel enabled\n"); | ||
1081 | chan->halt_pending = 1; | ||
1082 | chan->halt_on_queue = 0; | ||
1083 | } else { | ||
1084 | if (dbg_hc(chan)) | ||
1085 | dev_vdbg(hsotg->dev, "Channel disabled\n"); | ||
1086 | chan->halt_on_queue = 1; | ||
1087 | } | ||
1088 | |||
1089 | if (dbg_hc(chan)) { | ||
1090 | dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, | ||
1091 | chan->hc_num); | ||
1092 | dev_vdbg(hsotg->dev, " hcchar: 0x%08x\n", | ||
1093 | hcchar); | ||
1094 | dev_vdbg(hsotg->dev, " halt_pending: %d\n", | ||
1095 | chan->halt_pending); | ||
1096 | dev_vdbg(hsotg->dev, " halt_on_queue: %d\n", | ||
1097 | chan->halt_on_queue); | ||
1098 | dev_vdbg(hsotg->dev, " halt_status: %d\n", | ||
1099 | chan->halt_status); | ||
1100 | } | ||
1101 | } | ||
1102 | |||
1103 | /** | ||
1104 | * dwc2_hc_cleanup() - Clears the transfer state for a host channel | ||
1105 | * | ||
1106 | * @hsotg: Programming view of DWC_otg controller | ||
1107 | * @chan: Identifies the host channel to clean up | ||
1108 | * | ||
1109 | * This function is normally called after a transfer is done and the host | ||
1110 | * channel is being released | ||
1111 | */ | ||
1112 | void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) | ||
1113 | { | ||
1114 | u32 hcintmsk; | ||
1115 | |||
1116 | chan->xfer_started = 0; | ||
1117 | |||
1118 | /* | ||
1119 | * Clear channel interrupt enables and any unhandled channel interrupt | ||
1120 | * conditions | ||
1121 | */ | ||
1122 | writel(0, hsotg->regs + HCINTMSK(chan->hc_num)); | ||
1123 | hcintmsk = 0xffffffff; | ||
1124 | hcintmsk &= ~HCINTMSK_RESERVED14_31; | ||
1125 | writel(hcintmsk, hsotg->regs + HCINT(chan->hc_num)); | ||
1126 | } | ||
1127 | |||
1128 | /** | ||
1129 | * dwc2_hc_set_even_odd_frame() - Sets the channel property that indicates in | ||
1130 | * which frame a periodic transfer should occur | ||
1131 | * | ||
1132 | * @hsotg: Programming view of DWC_otg controller | ||
1133 | * @chan: Identifies the host channel to set up and its properties | ||
1134 | * @hcchar: Current value of the HCCHAR register for the specified host channel | ||
1135 | * | ||
1136 | * This function has no effect on non-periodic transfers | ||
1137 | */ | ||
1138 | static void dwc2_hc_set_even_odd_frame(struct dwc2_hsotg *hsotg, | ||
1139 | struct dwc2_host_chan *chan, u32 *hcchar) | ||
1140 | { | ||
1141 | if (chan->ep_type == USB_ENDPOINT_XFER_INT || | ||
1142 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) { | ||
1143 | /* 1 if _next_ frame is odd, 0 if it's even */ | ||
1144 | if (!(dwc2_hcd_get_frame_number(hsotg) & 0x1)) | ||
1145 | *hcchar |= HCCHAR_ODDFRM; | ||
1146 | } | ||
1147 | } | ||
1148 | |||
1149 | static void dwc2_set_pid_isoc(struct dwc2_host_chan *chan) | ||
1150 | { | ||
1151 | /* Set up the initial PID for the transfer */ | ||
1152 | if (chan->speed == USB_SPEED_HIGH) { | ||
1153 | if (chan->ep_is_in) { | ||
1154 | if (chan->multi_count == 1) | ||
1155 | chan->data_pid_start = DWC2_HC_PID_DATA0; | ||
1156 | else if (chan->multi_count == 2) | ||
1157 | chan->data_pid_start = DWC2_HC_PID_DATA1; | ||
1158 | else | ||
1159 | chan->data_pid_start = DWC2_HC_PID_DATA2; | ||
1160 | } else { | ||
1161 | if (chan->multi_count == 1) | ||
1162 | chan->data_pid_start = DWC2_HC_PID_DATA0; | ||
1163 | else | ||
1164 | chan->data_pid_start = DWC2_HC_PID_MDATA; | ||
1165 | } | ||
1166 | } else { | ||
1167 | chan->data_pid_start = DWC2_HC_PID_DATA0; | ||
1168 | } | ||
1169 | } | ||
1170 | |||
1171 | /** | ||
1172 | * dwc2_hc_write_packet() - Writes a packet into the Tx FIFO associated with | ||
1173 | * the Host Channel | ||
1174 | * | ||
1175 | * @hsotg: Programming view of DWC_otg controller | ||
1176 | * @chan: Information needed to initialize the host channel | ||
1177 | * | ||
1178 | * This function should only be called in Slave mode. For a channel associated | ||
1179 | * with a non-periodic EP, the non-periodic Tx FIFO is written. For a channel | ||
1180 | * associated with a periodic EP, the periodic Tx FIFO is written. | ||
1181 | * | ||
1182 | * Upon return the xfer_buf and xfer_count fields in chan are incremented by | ||
1183 | * the number of bytes written to the Tx FIFO. | ||
1184 | */ | ||
1185 | static void dwc2_hc_write_packet(struct dwc2_hsotg *hsotg, | ||
1186 | struct dwc2_host_chan *chan) | ||
1187 | { | ||
1188 | u32 i; | ||
1189 | u32 remaining_count; | ||
1190 | u32 byte_count; | ||
1191 | u32 dword_count; | ||
1192 | u32 __iomem *data_fifo; | ||
1193 | u32 *data_buf = (u32 *)chan->xfer_buf; | ||
1194 | |||
1195 | if (dbg_hc(chan)) | ||
1196 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
1197 | |||
1198 | data_fifo = (u32 __iomem *)(hsotg->regs + HCFIFO(chan->hc_num)); | ||
1199 | |||
1200 | remaining_count = chan->xfer_len - chan->xfer_count; | ||
1201 | if (remaining_count > chan->max_packet) | ||
1202 | byte_count = chan->max_packet; | ||
1203 | else | ||
1204 | byte_count = remaining_count; | ||
1205 | |||
1206 | dword_count = (byte_count + 3) / 4; | ||
1207 | |||
1208 | if (((unsigned long)data_buf & 0x3) == 0) { | ||
1209 | /* xfer_buf is DWORD aligned */ | ||
1210 | for (i = 0; i < dword_count; i++, data_buf++) | ||
1211 | writel(*data_buf, data_fifo); | ||
1212 | } else { | ||
1213 | /* xfer_buf is not DWORD aligned */ | ||
1214 | for (i = 0; i < dword_count; i++, data_buf++) { | ||
1215 | u32 data = data_buf[0] | data_buf[1] << 8 | | ||
1216 | data_buf[2] << 16 | data_buf[3] << 24; | ||
1217 | writel(data, data_fifo); | ||
1218 | } | ||
1219 | } | ||
1220 | |||
1221 | chan->xfer_count += byte_count; | ||
1222 | chan->xfer_buf += byte_count; | ||
1223 | } | ||
1224 | |||
1225 | /** | ||
1226 | * dwc2_hc_start_transfer() - Does the setup for a data transfer for a host | ||
1227 | * channel and starts the transfer | ||
1228 | * | ||
1229 | * @hsotg: Programming view of DWC_otg controller | ||
1230 | * @chan: Information needed to initialize the host channel. The xfer_len value | ||
1231 | * may be reduced to accommodate the max widths of the XferSize and | ||
1232 | * PktCnt fields in the HCTSIZn register. The multi_count value may be | ||
1233 | * changed to reflect the final xfer_len value. | ||
1234 | * | ||
1235 | * This function may be called in either Slave mode or DMA mode. In Slave mode, | ||
1236 | * the caller must ensure that there is sufficient space in the request queue | ||
1237 | * and Tx Data FIFO. | ||
1238 | * | ||
1239 | * For an OUT transfer in Slave mode, it loads a data packet into the | ||
1240 | * appropriate FIFO. If necessary, additional data packets are loaded in the | ||
1241 | * Host ISR. | ||
1242 | * | ||
1243 | * For an IN transfer in Slave mode, a data packet is requested. The data | ||
1244 | * packets are unloaded from the Rx FIFO in the Host ISR. If necessary, | ||
1245 | * additional data packets are requested in the Host ISR. | ||
1246 | * | ||
1247 | * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ | ||
1248 | * register along with a packet count of 1 and the channel is enabled. This | ||
1249 | * causes a single PING transaction to occur. Other fields in HCTSIZ are | ||
1250 | * simply set to 0 since no data transfer occurs in this case. | ||
1251 | * | ||
1252 | * For a PING transfer in DMA mode, the HCTSIZ register is initialized with | ||
1253 | * all the information required to perform the subsequent data transfer. In | ||
1254 | * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the | ||
1255 | * controller performs the entire PING protocol, then starts the data | ||
1256 | * transfer. | ||
1257 | */ | ||
1258 | void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg, | ||
1259 | struct dwc2_host_chan *chan) | ||
1260 | { | ||
1261 | u32 max_hc_xfer_size = hsotg->core_params->max_transfer_size; | ||
1262 | u16 max_hc_pkt_count = hsotg->core_params->max_packet_count; | ||
1263 | u32 hcchar; | ||
1264 | u32 hctsiz = 0; | ||
1265 | u16 num_packets; | ||
1266 | |||
1267 | if (dbg_hc(chan)) | ||
1268 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
1269 | |||
1270 | if (chan->do_ping) { | ||
1271 | if (hsotg->core_params->dma_enable <= 0) { | ||
1272 | if (dbg_hc(chan)) | ||
1273 | dev_vdbg(hsotg->dev, "ping, no DMA\n"); | ||
1274 | dwc2_hc_do_ping(hsotg, chan); | ||
1275 | chan->xfer_started = 1; | ||
1276 | return; | ||
1277 | } else { | ||
1278 | if (dbg_hc(chan)) | ||
1279 | dev_vdbg(hsotg->dev, "ping, DMA\n"); | ||
1280 | hctsiz |= TSIZ_DOPNG; | ||
1281 | } | ||
1282 | } | ||
1283 | |||
1284 | if (chan->do_split) { | ||
1285 | if (dbg_hc(chan)) | ||
1286 | dev_vdbg(hsotg->dev, "split\n"); | ||
1287 | num_packets = 1; | ||
1288 | |||
1289 | if (chan->complete_split && !chan->ep_is_in) | ||
1290 | /* | ||
1291 | * For CSPLIT OUT Transfer, set the size to 0 so the | ||
1292 | * core doesn't expect any data written to the FIFO | ||
1293 | */ | ||
1294 | chan->xfer_len = 0; | ||
1295 | else if (chan->ep_is_in || chan->xfer_len > chan->max_packet) | ||
1296 | chan->xfer_len = chan->max_packet; | ||
1297 | else if (!chan->ep_is_in && chan->xfer_len > 188) | ||
1298 | chan->xfer_len = 188; | ||
1299 | |||
1300 | hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT & | ||
1301 | TSIZ_XFERSIZE_MASK; | ||
1302 | } else { | ||
1303 | if (dbg_hc(chan)) | ||
1304 | dev_vdbg(hsotg->dev, "no split\n"); | ||
1305 | /* | ||
1306 | * Ensure that the transfer length and packet count will fit | ||
1307 | * in the widths allocated for them in the HCTSIZn register | ||
1308 | */ | ||
1309 | if (chan->ep_type == USB_ENDPOINT_XFER_INT || | ||
1310 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) { | ||
1311 | /* | ||
1312 | * Make sure the transfer size is no larger than one | ||
1313 | * (micro)frame's worth of data. (A check was done | ||
1314 | * when the periodic transfer was accepted to ensure | ||
1315 | * that a (micro)frame's worth of data can be | ||
1316 | * programmed into a channel.) | ||
1317 | */ | ||
1318 | u32 max_periodic_len = | ||
1319 | chan->multi_count * chan->max_packet; | ||
1320 | |||
1321 | if (chan->xfer_len > max_periodic_len) | ||
1322 | chan->xfer_len = max_periodic_len; | ||
1323 | } else if (chan->xfer_len > max_hc_xfer_size) { | ||
1324 | /* | ||
1325 | * Make sure that xfer_len is a multiple of max packet | ||
1326 | * size | ||
1327 | */ | ||
1328 | chan->xfer_len = | ||
1329 | max_hc_xfer_size - chan->max_packet + 1; | ||
1330 | } | ||
1331 | |||
1332 | if (chan->xfer_len > 0) { | ||
1333 | num_packets = (chan->xfer_len + chan->max_packet - 1) / | ||
1334 | chan->max_packet; | ||
1335 | if (num_packets > max_hc_pkt_count) { | ||
1336 | num_packets = max_hc_pkt_count; | ||
1337 | chan->xfer_len = num_packets * chan->max_packet; | ||
1338 | } | ||
1339 | } else { | ||
1340 | /* Need 1 packet for transfer length of 0 */ | ||
1341 | num_packets = 1; | ||
1342 | } | ||
1343 | |||
1344 | if (chan->ep_is_in) | ||
1345 | /* | ||
1346 | * Always program an integral # of max packets for IN | ||
1347 | * transfers | ||
1348 | */ | ||
1349 | chan->xfer_len = num_packets * chan->max_packet; | ||
1350 | |||
1351 | if (chan->ep_type == USB_ENDPOINT_XFER_INT || | ||
1352 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) | ||
1353 | /* | ||
1354 | * Make sure that the multi_count field matches the | ||
1355 | * actual transfer length | ||
1356 | */ | ||
1357 | chan->multi_count = num_packets; | ||
1358 | |||
1359 | if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) | ||
1360 | dwc2_set_pid_isoc(chan); | ||
1361 | |||
1362 | hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT & | ||
1363 | TSIZ_XFERSIZE_MASK; | ||
1364 | } | ||
1365 | |||
1366 | chan->start_pkt_count = num_packets; | ||
1367 | hctsiz |= num_packets << TSIZ_PKTCNT_SHIFT & TSIZ_PKTCNT_MASK; | ||
1368 | hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT & | ||
1369 | TSIZ_SC_MC_PID_MASK; | ||
1370 | writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); | ||
1371 | if (dbg_hc(chan)) { | ||
1372 | dev_vdbg(hsotg->dev, "Wrote %08x to HCTSIZ(%d)\n", | ||
1373 | hctsiz, chan->hc_num); | ||
1374 | |||
1375 | dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, | ||
1376 | chan->hc_num); | ||
1377 | dev_vdbg(hsotg->dev, " Xfer Size: %d\n", | ||
1378 | (hctsiz & TSIZ_XFERSIZE_MASK) >> | ||
1379 | TSIZ_XFERSIZE_SHIFT); | ||
1380 | dev_vdbg(hsotg->dev, " Num Pkts: %d\n", | ||
1381 | (hctsiz & TSIZ_PKTCNT_MASK) >> | ||
1382 | TSIZ_PKTCNT_SHIFT); | ||
1383 | dev_vdbg(hsotg->dev, " Start PID: %d\n", | ||
1384 | (hctsiz & TSIZ_SC_MC_PID_MASK) >> | ||
1385 | TSIZ_SC_MC_PID_SHIFT); | ||
1386 | } | ||
1387 | |||
1388 | if (hsotg->core_params->dma_enable > 0) { | ||
1389 | dma_addr_t dma_addr; | ||
1390 | |||
1391 | if (chan->align_buf) { | ||
1392 | if (dbg_hc(chan)) | ||
1393 | dev_vdbg(hsotg->dev, "align_buf\n"); | ||
1394 | dma_addr = chan->align_buf; | ||
1395 | } else { | ||
1396 | dma_addr = chan->xfer_dma; | ||
1397 | } | ||
1398 | writel((u32)dma_addr, hsotg->regs + HCDMA(chan->hc_num)); | ||
1399 | if (dbg_hc(chan)) | ||
1400 | dev_vdbg(hsotg->dev, "Wrote %08lx to HCDMA(%d)\n", | ||
1401 | (unsigned long)dma_addr, chan->hc_num); | ||
1402 | } | ||
1403 | |||
1404 | /* Start the split */ | ||
1405 | if (chan->do_split) { | ||
1406 | u32 hcsplt = readl(hsotg->regs + HCSPLT(chan->hc_num)); | ||
1407 | |||
1408 | hcsplt |= HCSPLT_SPLTENA; | ||
1409 | writel(hcsplt, hsotg->regs + HCSPLT(chan->hc_num)); | ||
1410 | } | ||
1411 | |||
1412 | hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); | ||
1413 | hcchar &= ~HCCHAR_MULTICNT_MASK; | ||
1414 | hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT & | ||
1415 | HCCHAR_MULTICNT_MASK; | ||
1416 | dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); | ||
1417 | |||
1418 | if (hcchar & HCCHAR_CHDIS) | ||
1419 | dev_warn(hsotg->dev, | ||
1420 | "%s: chdis set, channel %d, hcchar 0x%08x\n", | ||
1421 | __func__, chan->hc_num, hcchar); | ||
1422 | |||
1423 | /* Set host channel enable after all other setup is complete */ | ||
1424 | hcchar |= HCCHAR_CHENA; | ||
1425 | hcchar &= ~HCCHAR_CHDIS; | ||
1426 | |||
1427 | if (dbg_hc(chan)) | ||
1428 | dev_vdbg(hsotg->dev, " Multi Cnt: %d\n", | ||
1429 | (hcchar & HCCHAR_MULTICNT_MASK) >> | ||
1430 | HCCHAR_MULTICNT_SHIFT); | ||
1431 | |||
1432 | writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); | ||
1433 | if (dbg_hc(chan)) | ||
1434 | dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, | ||
1435 | chan->hc_num); | ||
1436 | |||
1437 | chan->xfer_started = 1; | ||
1438 | chan->requests++; | ||
1439 | |||
1440 | if (hsotg->core_params->dma_enable <= 0 && | ||
1441 | !chan->ep_is_in && chan->xfer_len > 0) | ||
1442 | /* Load OUT packet into the appropriate Tx FIFO */ | ||
1443 | dwc2_hc_write_packet(hsotg, chan); | ||
1444 | } | ||
1445 | |||
1446 | /** | ||
1447 | * dwc2_hc_start_transfer_ddma() - Does the setup for a data transfer for a | ||
1448 | * host channel and starts the transfer in Descriptor DMA mode | ||
1449 | * | ||
1450 | * @hsotg: Programming view of DWC_otg controller | ||
1451 | * @chan: Information needed to initialize the host channel | ||
1452 | * | ||
1453 | * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set. | ||
1454 | * Sets PID and NTD values. For periodic transfers initializes SCHED_INFO field | ||
1455 | * with micro-frame bitmap. | ||
1456 | * | ||
1457 | * Initializes HCDMA register with descriptor list address and CTD value then | ||
1458 | * starts the transfer via enabling the channel. | ||
1459 | */ | ||
1460 | void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg, | ||
1461 | struct dwc2_host_chan *chan) | ||
1462 | { | ||
1463 | u32 hcchar; | ||
1464 | u32 hc_dma; | ||
1465 | u32 hctsiz = 0; | ||
1466 | |||
1467 | if (chan->do_ping) | ||
1468 | hctsiz |= TSIZ_DOPNG; | ||
1469 | |||
1470 | if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) | ||
1471 | dwc2_set_pid_isoc(chan); | ||
1472 | |||
1473 | /* Packet Count and Xfer Size are not used in Descriptor DMA mode */ | ||
1474 | hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT & | ||
1475 | TSIZ_SC_MC_PID_MASK; | ||
1476 | |||
1477 | /* 0 - 1 descriptor, 1 - 2 descriptors, etc */ | ||
1478 | hctsiz |= (chan->ntd - 1) << TSIZ_NTD_SHIFT & TSIZ_NTD_MASK; | ||
1479 | |||
1480 | /* Non-zero only for high-speed interrupt endpoints */ | ||
1481 | hctsiz |= chan->schinfo << TSIZ_SCHINFO_SHIFT & TSIZ_SCHINFO_MASK; | ||
1482 | |||
1483 | if (dbg_hc(chan)) { | ||
1484 | dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, | ||
1485 | chan->hc_num); | ||
1486 | dev_vdbg(hsotg->dev, " Start PID: %d\n", | ||
1487 | chan->data_pid_start); | ||
1488 | dev_vdbg(hsotg->dev, " NTD: %d\n", chan->ntd - 1); | ||
1489 | } | ||
1490 | |||
1491 | writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); | ||
1492 | |||
1493 | hc_dma = (u32)chan->desc_list_addr & HCDMA_DMA_ADDR_MASK; | ||
1494 | |||
1495 | /* Always start from first descriptor */ | ||
1496 | hc_dma &= ~HCDMA_CTD_MASK; | ||
1497 | writel(hc_dma, hsotg->regs + HCDMA(chan->hc_num)); | ||
1498 | if (dbg_hc(chan)) | ||
1499 | dev_vdbg(hsotg->dev, "Wrote %08x to HCDMA(%d)\n", | ||
1500 | hc_dma, chan->hc_num); | ||
1501 | |||
1502 | hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); | ||
1503 | hcchar &= ~HCCHAR_MULTICNT_MASK; | ||
1504 | hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT & | ||
1505 | HCCHAR_MULTICNT_MASK; | ||
1506 | |||
1507 | if (hcchar & HCCHAR_CHDIS) | ||
1508 | dev_warn(hsotg->dev, | ||
1509 | "%s: chdis set, channel %d, hcchar 0x%08x\n", | ||
1510 | __func__, chan->hc_num, hcchar); | ||
1511 | |||
1512 | /* Set host channel enable after all other setup is complete */ | ||
1513 | hcchar |= HCCHAR_CHENA; | ||
1514 | hcchar &= ~HCCHAR_CHDIS; | ||
1515 | |||
1516 | if (dbg_hc(chan)) | ||
1517 | dev_vdbg(hsotg->dev, " Multi Cnt: %d\n", | ||
1518 | (hcchar & HCCHAR_MULTICNT_MASK) >> | ||
1519 | HCCHAR_MULTICNT_SHIFT); | ||
1520 | |||
1521 | writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); | ||
1522 | if (dbg_hc(chan)) | ||
1523 | dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, | ||
1524 | chan->hc_num); | ||
1525 | |||
1526 | chan->xfer_started = 1; | ||
1527 | chan->requests++; | ||
1528 | } | ||
1529 | |||
1530 | /** | ||
1531 | * dwc2_hc_continue_transfer() - Continues a data transfer that was started by | ||
1532 | * a previous call to dwc2_hc_start_transfer() | ||
1533 | * | ||
1534 | * @hsotg: Programming view of DWC_otg controller | ||
1535 | * @chan: Information needed to initialize the host channel | ||
1536 | * | ||
1537 | * The caller must ensure there is sufficient space in the request queue and Tx | ||
1538 | * Data FIFO. This function should only be called in Slave mode. In DMA mode, | ||
1539 | * the controller acts autonomously to complete transfers programmed to a host | ||
1540 | * channel. | ||
1541 | * | ||
1542 | * For an OUT transfer, a new data packet is loaded into the appropriate FIFO | ||
1543 | * if there is any data remaining to be queued. For an IN transfer, another | ||
1544 | * data packet is always requested. For the SETUP phase of a control transfer, | ||
1545 | * this function does nothing. | ||
1546 | * | ||
1547 | * Return: 1 if a new request is queued, 0 if no more requests are required | ||
1548 | * for this transfer | ||
1549 | */ | ||
1550 | int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg, | ||
1551 | struct dwc2_host_chan *chan) | ||
1552 | { | ||
1553 | if (dbg_hc(chan)) | ||
1554 | dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, | ||
1555 | chan->hc_num); | ||
1556 | |||
1557 | if (chan->do_split) | ||
1558 | /* SPLITs always queue just once per channel */ | ||
1559 | return 0; | ||
1560 | |||
1561 | if (chan->data_pid_start == DWC2_HC_PID_SETUP) | ||
1562 | /* SETUPs are queued only once since they can't be NAK'd */ | ||
1563 | return 0; | ||
1564 | |||
1565 | if (chan->ep_is_in) { | ||
1566 | /* | ||
1567 | * Always queue another request for other IN transfers. If | ||
1568 | * back-to-back INs are issued and NAKs are received for both, | ||
1569 | * the driver may still be processing the first NAK when the | ||
1570 | * second NAK is received. When the interrupt handler clears | ||
1571 | * the NAK interrupt for the first NAK, the second NAK will | ||
1572 | * not be seen. So we can't depend on the NAK interrupt | ||
1573 | * handler to requeue a NAK'd request. Instead, IN requests | ||
1574 | * are issued each time this function is called. When the | ||
1575 | * transfer completes, the extra requests for the channel will | ||
1576 | * be flushed. | ||
1577 | */ | ||
1578 | u32 hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); | ||
1579 | |||
1580 | dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); | ||
1581 | hcchar |= HCCHAR_CHENA; | ||
1582 | hcchar &= ~HCCHAR_CHDIS; | ||
1583 | if (dbg_hc(chan)) | ||
1584 | dev_vdbg(hsotg->dev, " IN xfer: hcchar = 0x%08x\n", | ||
1585 | hcchar); | ||
1586 | writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); | ||
1587 | chan->requests++; | ||
1588 | return 1; | ||
1589 | } | ||
1590 | |||
1591 | /* OUT transfers */ | ||
1592 | |||
1593 | if (chan->xfer_count < chan->xfer_len) { | ||
1594 | if (chan->ep_type == USB_ENDPOINT_XFER_INT || | ||
1595 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) { | ||
1596 | u32 hcchar = readl(hsotg->regs + | ||
1597 | HCCHAR(chan->hc_num)); | ||
1598 | |||
1599 | dwc2_hc_set_even_odd_frame(hsotg, chan, | ||
1600 | &hcchar); | ||
1601 | } | ||
1602 | |||
1603 | /* Load OUT packet into the appropriate Tx FIFO */ | ||
1604 | dwc2_hc_write_packet(hsotg, chan); | ||
1605 | chan->requests++; | ||
1606 | return 1; | ||
1607 | } | ||
1608 | |||
1609 | return 0; | ||
1610 | } | ||
1611 | |||
1612 | /** | ||
1613 | * dwc2_hc_do_ping() - Starts a PING transfer | ||
1614 | * | ||
1615 | * @hsotg: Programming view of DWC_otg controller | ||
1616 | * @chan: Information needed to initialize the host channel | ||
1617 | * | ||
1618 | * This function should only be called in Slave mode. The Do Ping bit is set in | ||
1619 | * the HCTSIZ register, then the channel is enabled. | ||
1620 | */ | ||
1621 | void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) | ||
1622 | { | ||
1623 | u32 hcchar; | ||
1624 | u32 hctsiz; | ||
1625 | |||
1626 | if (dbg_hc(chan)) | ||
1627 | dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, | ||
1628 | chan->hc_num); | ||
1629 | |||
1630 | |||
1631 | hctsiz = TSIZ_DOPNG; | ||
1632 | hctsiz |= 1 << TSIZ_PKTCNT_SHIFT; | ||
1633 | writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); | ||
1634 | |||
1635 | hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); | ||
1636 | hcchar |= HCCHAR_CHENA; | ||
1637 | hcchar &= ~HCCHAR_CHDIS; | ||
1638 | writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); | ||
1639 | } | ||
1640 | |||
1641 | /** | ||
1642 | * dwc2_calc_frame_interval() - Calculates the correct frame Interval value for | ||
1643 | * the HFIR register according to PHY type and speed | ||
1644 | * | ||
1645 | * @hsotg: Programming view of DWC_otg controller | ||
1646 | * | ||
1647 | * NOTE: The caller can modify the value of the HFIR register only after the | ||
1648 | * Port Enable bit of the Host Port Control and Status register (HPRT.EnaPort) | ||
1649 | * has been set | ||
1650 | */ | ||
1651 | u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg) | ||
1652 | { | ||
1653 | u32 usbcfg; | ||
1654 | u32 hprt0; | ||
1655 | int clock = 60; /* default value */ | ||
1656 | |||
1657 | usbcfg = readl(hsotg->regs + GUSBCFG); | ||
1658 | hprt0 = readl(hsotg->regs + HPRT0); | ||
1659 | |||
1660 | if (!(usbcfg & GUSBCFG_PHYSEL) && (usbcfg & GUSBCFG_ULPI_UTMI_SEL) && | ||
1661 | !(usbcfg & GUSBCFG_PHYIF16)) | ||
1662 | clock = 60; | ||
1663 | if ((usbcfg & GUSBCFG_PHYSEL) && hsotg->hw_params.fs_phy_type == | ||
1664 | GHWCFG2_FS_PHY_TYPE_SHARED_ULPI) | ||
1665 | clock = 48; | ||
1666 | if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) && | ||
1667 | !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16)) | ||
1668 | clock = 30; | ||
1669 | if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) && | ||
1670 | !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && !(usbcfg & GUSBCFG_PHYIF16)) | ||
1671 | clock = 60; | ||
1672 | if ((usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) && | ||
1673 | !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16)) | ||
1674 | clock = 48; | ||
1675 | if ((usbcfg & GUSBCFG_PHYSEL) && !(usbcfg & GUSBCFG_PHYIF16) && | ||
1676 | hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_SHARED_UTMI) | ||
1677 | clock = 48; | ||
1678 | if ((usbcfg & GUSBCFG_PHYSEL) && | ||
1679 | hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) | ||
1680 | clock = 48; | ||
1681 | |||
1682 | if ((hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT == HPRT0_SPD_HIGH_SPEED) | ||
1683 | /* High speed case */ | ||
1684 | return 125 * clock; | ||
1685 | else | ||
1686 | /* FS/LS case */ | ||
1687 | return 1000 * clock; | ||
1688 | } | ||
1689 | |||
1690 | /** | ||
1691 | * dwc2_read_packet() - Reads a packet from the Rx FIFO into the destination | ||
1692 | * buffer | ||
1693 | * | ||
1694 | * @core_if: Programming view of DWC_otg controller | ||
1695 | * @dest: Destination buffer for the packet | ||
1696 | * @bytes: Number of bytes to copy to the destination | ||
1697 | */ | ||
1698 | void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes) | ||
1699 | { | ||
1700 | u32 __iomem *fifo = hsotg->regs + HCFIFO(0); | ||
1701 | u32 *data_buf = (u32 *)dest; | ||
1702 | int word_count = (bytes + 3) / 4; | ||
1703 | int i; | ||
1704 | |||
1705 | /* | ||
1706 | * Todo: Account for the case where dest is not dword aligned. This | ||
1707 | * requires reading data from the FIFO into a u32 temp buffer, then | ||
1708 | * moving it into the data buffer. | ||
1709 | */ | ||
1710 | |||
1711 | dev_vdbg(hsotg->dev, "%s(%p,%p,%d)\n", __func__, hsotg, dest, bytes); | ||
1712 | |||
1713 | for (i = 0; i < word_count; i++, data_buf++) | ||
1714 | *data_buf = readl(fifo); | ||
1715 | } | ||
1716 | |||
1717 | /** | ||
1718 | * dwc2_dump_host_registers() - Prints the host registers | ||
1719 | * | ||
1720 | * @hsotg: Programming view of DWC_otg controller | ||
1721 | * | ||
1722 | * NOTE: This function will be removed once the peripheral controller code | ||
1723 | * is integrated and the driver is stable | ||
1724 | */ | ||
1725 | void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg) | ||
1726 | { | ||
1727 | #ifdef DEBUG | ||
1728 | u32 __iomem *addr; | ||
1729 | int i; | ||
1730 | |||
1731 | dev_dbg(hsotg->dev, "Host Global Registers\n"); | ||
1732 | addr = hsotg->regs + HCFG; | ||
1733 | dev_dbg(hsotg->dev, "HCFG @0x%08lX : 0x%08X\n", | ||
1734 | (unsigned long)addr, readl(addr)); | ||
1735 | addr = hsotg->regs + HFIR; | ||
1736 | dev_dbg(hsotg->dev, "HFIR @0x%08lX : 0x%08X\n", | ||
1737 | (unsigned long)addr, readl(addr)); | ||
1738 | addr = hsotg->regs + HFNUM; | ||
1739 | dev_dbg(hsotg->dev, "HFNUM @0x%08lX : 0x%08X\n", | ||
1740 | (unsigned long)addr, readl(addr)); | ||
1741 | addr = hsotg->regs + HPTXSTS; | ||
1742 | dev_dbg(hsotg->dev, "HPTXSTS @0x%08lX : 0x%08X\n", | ||
1743 | (unsigned long)addr, readl(addr)); | ||
1744 | addr = hsotg->regs + HAINT; | ||
1745 | dev_dbg(hsotg->dev, "HAINT @0x%08lX : 0x%08X\n", | ||
1746 | (unsigned long)addr, readl(addr)); | ||
1747 | addr = hsotg->regs + HAINTMSK; | ||
1748 | dev_dbg(hsotg->dev, "HAINTMSK @0x%08lX : 0x%08X\n", | ||
1749 | (unsigned long)addr, readl(addr)); | ||
1750 | if (hsotg->core_params->dma_desc_enable > 0) { | ||
1751 | addr = hsotg->regs + HFLBADDR; | ||
1752 | dev_dbg(hsotg->dev, "HFLBADDR @0x%08lX : 0x%08X\n", | ||
1753 | (unsigned long)addr, readl(addr)); | ||
1754 | } | ||
1755 | |||
1756 | addr = hsotg->regs + HPRT0; | ||
1757 | dev_dbg(hsotg->dev, "HPRT0 @0x%08lX : 0x%08X\n", | ||
1758 | (unsigned long)addr, readl(addr)); | ||
1759 | |||
1760 | for (i = 0; i < hsotg->core_params->host_channels; i++) { | ||
1761 | dev_dbg(hsotg->dev, "Host Channel %d Specific Registers\n", i); | ||
1762 | addr = hsotg->regs + HCCHAR(i); | ||
1763 | dev_dbg(hsotg->dev, "HCCHAR @0x%08lX : 0x%08X\n", | ||
1764 | (unsigned long)addr, readl(addr)); | ||
1765 | addr = hsotg->regs + HCSPLT(i); | ||
1766 | dev_dbg(hsotg->dev, "HCSPLT @0x%08lX : 0x%08X\n", | ||
1767 | (unsigned long)addr, readl(addr)); | ||
1768 | addr = hsotg->regs + HCINT(i); | ||
1769 | dev_dbg(hsotg->dev, "HCINT @0x%08lX : 0x%08X\n", | ||
1770 | (unsigned long)addr, readl(addr)); | ||
1771 | addr = hsotg->regs + HCINTMSK(i); | ||
1772 | dev_dbg(hsotg->dev, "HCINTMSK @0x%08lX : 0x%08X\n", | ||
1773 | (unsigned long)addr, readl(addr)); | ||
1774 | addr = hsotg->regs + HCTSIZ(i); | ||
1775 | dev_dbg(hsotg->dev, "HCTSIZ @0x%08lX : 0x%08X\n", | ||
1776 | (unsigned long)addr, readl(addr)); | ||
1777 | addr = hsotg->regs + HCDMA(i); | ||
1778 | dev_dbg(hsotg->dev, "HCDMA @0x%08lX : 0x%08X\n", | ||
1779 | (unsigned long)addr, readl(addr)); | ||
1780 | if (hsotg->core_params->dma_desc_enable > 0) { | ||
1781 | addr = hsotg->regs + HCDMAB(i); | ||
1782 | dev_dbg(hsotg->dev, "HCDMAB @0x%08lX : 0x%08X\n", | ||
1783 | (unsigned long)addr, readl(addr)); | ||
1784 | } | ||
1785 | } | ||
1786 | #endif | ||
1787 | } | ||
1788 | |||
1789 | /** | ||
1790 | * dwc2_dump_global_registers() - Prints the core global registers | ||
1791 | * | ||
1792 | * @hsotg: Programming view of DWC_otg controller | ||
1793 | * | ||
1794 | * NOTE: This function will be removed once the peripheral controller code | ||
1795 | * is integrated and the driver is stable | ||
1796 | */ | ||
1797 | void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg) | ||
1798 | { | ||
1799 | #ifdef DEBUG | ||
1800 | u32 __iomem *addr; | ||
1801 | |||
1802 | dev_dbg(hsotg->dev, "Core Global Registers\n"); | ||
1803 | addr = hsotg->regs + GOTGCTL; | ||
1804 | dev_dbg(hsotg->dev, "GOTGCTL @0x%08lX : 0x%08X\n", | ||
1805 | (unsigned long)addr, readl(addr)); | ||
1806 | addr = hsotg->regs + GOTGINT; | ||
1807 | dev_dbg(hsotg->dev, "GOTGINT @0x%08lX : 0x%08X\n", | ||
1808 | (unsigned long)addr, readl(addr)); | ||
1809 | addr = hsotg->regs + GAHBCFG; | ||
1810 | dev_dbg(hsotg->dev, "GAHBCFG @0x%08lX : 0x%08X\n", | ||
1811 | (unsigned long)addr, readl(addr)); | ||
1812 | addr = hsotg->regs + GUSBCFG; | ||
1813 | dev_dbg(hsotg->dev, "GUSBCFG @0x%08lX : 0x%08X\n", | ||
1814 | (unsigned long)addr, readl(addr)); | ||
1815 | addr = hsotg->regs + GRSTCTL; | ||
1816 | dev_dbg(hsotg->dev, "GRSTCTL @0x%08lX : 0x%08X\n", | ||
1817 | (unsigned long)addr, readl(addr)); | ||
1818 | addr = hsotg->regs + GINTSTS; | ||
1819 | dev_dbg(hsotg->dev, "GINTSTS @0x%08lX : 0x%08X\n", | ||
1820 | (unsigned long)addr, readl(addr)); | ||
1821 | addr = hsotg->regs + GINTMSK; | ||
1822 | dev_dbg(hsotg->dev, "GINTMSK @0x%08lX : 0x%08X\n", | ||
1823 | (unsigned long)addr, readl(addr)); | ||
1824 | addr = hsotg->regs + GRXSTSR; | ||
1825 | dev_dbg(hsotg->dev, "GRXSTSR @0x%08lX : 0x%08X\n", | ||
1826 | (unsigned long)addr, readl(addr)); | ||
1827 | addr = hsotg->regs + GRXFSIZ; | ||
1828 | dev_dbg(hsotg->dev, "GRXFSIZ @0x%08lX : 0x%08X\n", | ||
1829 | (unsigned long)addr, readl(addr)); | ||
1830 | addr = hsotg->regs + GNPTXFSIZ; | ||
1831 | dev_dbg(hsotg->dev, "GNPTXFSIZ @0x%08lX : 0x%08X\n", | ||
1832 | (unsigned long)addr, readl(addr)); | ||
1833 | addr = hsotg->regs + GNPTXSTS; | ||
1834 | dev_dbg(hsotg->dev, "GNPTXSTS @0x%08lX : 0x%08X\n", | ||
1835 | (unsigned long)addr, readl(addr)); | ||
1836 | addr = hsotg->regs + GI2CCTL; | ||
1837 | dev_dbg(hsotg->dev, "GI2CCTL @0x%08lX : 0x%08X\n", | ||
1838 | (unsigned long)addr, readl(addr)); | ||
1839 | addr = hsotg->regs + GPVNDCTL; | ||
1840 | dev_dbg(hsotg->dev, "GPVNDCTL @0x%08lX : 0x%08X\n", | ||
1841 | (unsigned long)addr, readl(addr)); | ||
1842 | addr = hsotg->regs + GGPIO; | ||
1843 | dev_dbg(hsotg->dev, "GGPIO @0x%08lX : 0x%08X\n", | ||
1844 | (unsigned long)addr, readl(addr)); | ||
1845 | addr = hsotg->regs + GUID; | ||
1846 | dev_dbg(hsotg->dev, "GUID @0x%08lX : 0x%08X\n", | ||
1847 | (unsigned long)addr, readl(addr)); | ||
1848 | addr = hsotg->regs + GSNPSID; | ||
1849 | dev_dbg(hsotg->dev, "GSNPSID @0x%08lX : 0x%08X\n", | ||
1850 | (unsigned long)addr, readl(addr)); | ||
1851 | addr = hsotg->regs + GHWCFG1; | ||
1852 | dev_dbg(hsotg->dev, "GHWCFG1 @0x%08lX : 0x%08X\n", | ||
1853 | (unsigned long)addr, readl(addr)); | ||
1854 | addr = hsotg->regs + GHWCFG2; | ||
1855 | dev_dbg(hsotg->dev, "GHWCFG2 @0x%08lX : 0x%08X\n", | ||
1856 | (unsigned long)addr, readl(addr)); | ||
1857 | addr = hsotg->regs + GHWCFG3; | ||
1858 | dev_dbg(hsotg->dev, "GHWCFG3 @0x%08lX : 0x%08X\n", | ||
1859 | (unsigned long)addr, readl(addr)); | ||
1860 | addr = hsotg->regs + GHWCFG4; | ||
1861 | dev_dbg(hsotg->dev, "GHWCFG4 @0x%08lX : 0x%08X\n", | ||
1862 | (unsigned long)addr, readl(addr)); | ||
1863 | addr = hsotg->regs + GLPMCFG; | ||
1864 | dev_dbg(hsotg->dev, "GLPMCFG @0x%08lX : 0x%08X\n", | ||
1865 | (unsigned long)addr, readl(addr)); | ||
1866 | addr = hsotg->regs + GPWRDN; | ||
1867 | dev_dbg(hsotg->dev, "GPWRDN @0x%08lX : 0x%08X\n", | ||
1868 | (unsigned long)addr, readl(addr)); | ||
1869 | addr = hsotg->regs + GDFIFOCFG; | ||
1870 | dev_dbg(hsotg->dev, "GDFIFOCFG @0x%08lX : 0x%08X\n", | ||
1871 | (unsigned long)addr, readl(addr)); | ||
1872 | addr = hsotg->regs + HPTXFSIZ; | ||
1873 | dev_dbg(hsotg->dev, "HPTXFSIZ @0x%08lX : 0x%08X\n", | ||
1874 | (unsigned long)addr, readl(addr)); | ||
1875 | |||
1876 | addr = hsotg->regs + PCGCTL; | ||
1877 | dev_dbg(hsotg->dev, "PCGCTL @0x%08lX : 0x%08X\n", | ||
1878 | (unsigned long)addr, readl(addr)); | ||
1879 | #endif | ||
1880 | } | ||
1881 | |||
1882 | /** | ||
1883 | * dwc2_flush_tx_fifo() - Flushes a Tx FIFO | ||
1884 | * | ||
1885 | * @hsotg: Programming view of DWC_otg controller | ||
1886 | * @num: Tx FIFO to flush | ||
1887 | */ | ||
1888 | void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num) | ||
1889 | { | ||
1890 | u32 greset; | ||
1891 | int count = 0; | ||
1892 | |||
1893 | dev_vdbg(hsotg->dev, "Flush Tx FIFO %d\n", num); | ||
1894 | |||
1895 | greset = GRSTCTL_TXFFLSH; | ||
1896 | greset |= num << GRSTCTL_TXFNUM_SHIFT & GRSTCTL_TXFNUM_MASK; | ||
1897 | writel(greset, hsotg->regs + GRSTCTL); | ||
1898 | |||
1899 | do { | ||
1900 | greset = readl(hsotg->regs + GRSTCTL); | ||
1901 | if (++count > 10000) { | ||
1902 | dev_warn(hsotg->dev, | ||
1903 | "%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n", | ||
1904 | __func__, greset, | ||
1905 | readl(hsotg->regs + GNPTXSTS)); | ||
1906 | break; | ||
1907 | } | ||
1908 | udelay(1); | ||
1909 | } while (greset & GRSTCTL_TXFFLSH); | ||
1910 | |||
1911 | /* Wait for at least 3 PHY Clocks */ | ||
1912 | udelay(1); | ||
1913 | } | ||
1914 | |||
1915 | /** | ||
1916 | * dwc2_flush_rx_fifo() - Flushes the Rx FIFO | ||
1917 | * | ||
1918 | * @hsotg: Programming view of DWC_otg controller | ||
1919 | */ | ||
1920 | void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg) | ||
1921 | { | ||
1922 | u32 greset; | ||
1923 | int count = 0; | ||
1924 | |||
1925 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
1926 | |||
1927 | greset = GRSTCTL_RXFFLSH; | ||
1928 | writel(greset, hsotg->regs + GRSTCTL); | ||
1929 | |||
1930 | do { | ||
1931 | greset = readl(hsotg->regs + GRSTCTL); | ||
1932 | if (++count > 10000) { | ||
1933 | dev_warn(hsotg->dev, "%s() HANG! GRSTCTL=%0x\n", | ||
1934 | __func__, greset); | ||
1935 | break; | ||
1936 | } | ||
1937 | udelay(1); | ||
1938 | } while (greset & GRSTCTL_RXFFLSH); | ||
1939 | |||
1940 | /* Wait for at least 3 PHY Clocks */ | ||
1941 | udelay(1); | ||
1942 | } | ||
1943 | |||
1944 | #define DWC2_OUT_OF_BOUNDS(a, b, c) ((a) < (b) || (a) > (c)) | ||
1945 | |||
1946 | /* Parameter access functions */ | ||
1947 | void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val) | ||
1948 | { | ||
1949 | int valid = 1; | ||
1950 | |||
1951 | switch (val) { | ||
1952 | case DWC2_CAP_PARAM_HNP_SRP_CAPABLE: | ||
1953 | if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE) | ||
1954 | valid = 0; | ||
1955 | break; | ||
1956 | case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE: | ||
1957 | switch (hsotg->hw_params.op_mode) { | ||
1958 | case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: | ||
1959 | case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: | ||
1960 | case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: | ||
1961 | case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: | ||
1962 | break; | ||
1963 | default: | ||
1964 | valid = 0; | ||
1965 | break; | ||
1966 | } | ||
1967 | break; | ||
1968 | case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE: | ||
1969 | /* always valid */ | ||
1970 | break; | ||
1971 | default: | ||
1972 | valid = 0; | ||
1973 | break; | ||
1974 | } | ||
1975 | |||
1976 | if (!valid) { | ||
1977 | if (val >= 0) | ||
1978 | dev_err(hsotg->dev, | ||
1979 | "%d invalid for otg_cap parameter. Check HW configuration.\n", | ||
1980 | val); | ||
1981 | switch (hsotg->hw_params.op_mode) { | ||
1982 | case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: | ||
1983 | val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE; | ||
1984 | break; | ||
1985 | case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: | ||
1986 | case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: | ||
1987 | case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: | ||
1988 | val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE; | ||
1989 | break; | ||
1990 | default: | ||
1991 | val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE; | ||
1992 | break; | ||
1993 | } | ||
1994 | dev_dbg(hsotg->dev, "Setting otg_cap to %d\n", val); | ||
1995 | } | ||
1996 | |||
1997 | hsotg->core_params->otg_cap = val; | ||
1998 | } | ||
1999 | |||
2000 | void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val) | ||
2001 | { | ||
2002 | int valid = 1; | ||
2003 | |||
2004 | if (val > 0 && hsotg->hw_params.arch == GHWCFG2_SLAVE_ONLY_ARCH) | ||
2005 | valid = 0; | ||
2006 | if (val < 0) | ||
2007 | valid = 0; | ||
2008 | |||
2009 | if (!valid) { | ||
2010 | if (val >= 0) | ||
2011 | dev_err(hsotg->dev, | ||
2012 | "%d invalid for dma_enable parameter. Check HW configuration.\n", | ||
2013 | val); | ||
2014 | val = hsotg->hw_params.arch != GHWCFG2_SLAVE_ONLY_ARCH; | ||
2015 | dev_dbg(hsotg->dev, "Setting dma_enable to %d\n", val); | ||
2016 | } | ||
2017 | |||
2018 | hsotg->core_params->dma_enable = val; | ||
2019 | } | ||
2020 | |||
2021 | void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val) | ||
2022 | { | ||
2023 | int valid = 1; | ||
2024 | |||
2025 | if (val > 0 && (hsotg->core_params->dma_enable <= 0 || | ||
2026 | !hsotg->hw_params.dma_desc_enable)) | ||
2027 | valid = 0; | ||
2028 | if (val < 0) | ||
2029 | valid = 0; | ||
2030 | |||
2031 | if (!valid) { | ||
2032 | if (val >= 0) | ||
2033 | dev_err(hsotg->dev, | ||
2034 | "%d invalid for dma_desc_enable parameter. Check HW configuration.\n", | ||
2035 | val); | ||
2036 | val = (hsotg->core_params->dma_enable > 0 && | ||
2037 | hsotg->hw_params.dma_desc_enable); | ||
2038 | dev_dbg(hsotg->dev, "Setting dma_desc_enable to %d\n", val); | ||
2039 | } | ||
2040 | |||
2041 | hsotg->core_params->dma_desc_enable = val; | ||
2042 | } | ||
2043 | |||
2044 | void dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg, | ||
2045 | int val) | ||
2046 | { | ||
2047 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { | ||
2048 | if (val >= 0) { | ||
2049 | dev_err(hsotg->dev, | ||
2050 | "Wrong value for host_support_fs_low_power\n"); | ||
2051 | dev_err(hsotg->dev, | ||
2052 | "host_support_fs_low_power must be 0 or 1\n"); | ||
2053 | } | ||
2054 | val = 0; | ||
2055 | dev_dbg(hsotg->dev, | ||
2056 | "Setting host_support_fs_low_power to %d\n", val); | ||
2057 | } | ||
2058 | |||
2059 | hsotg->core_params->host_support_fs_ls_low_power = val; | ||
2060 | } | ||
2061 | |||
2062 | void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg, int val) | ||
2063 | { | ||
2064 | int valid = 1; | ||
2065 | |||
2066 | if (val > 0 && !hsotg->hw_params.enable_dynamic_fifo) | ||
2067 | valid = 0; | ||
2068 | if (val < 0) | ||
2069 | valid = 0; | ||
2070 | |||
2071 | if (!valid) { | ||
2072 | if (val >= 0) | ||
2073 | dev_err(hsotg->dev, | ||
2074 | "%d invalid for enable_dynamic_fifo parameter. Check HW configuration.\n", | ||
2075 | val); | ||
2076 | val = hsotg->hw_params.enable_dynamic_fifo; | ||
2077 | dev_dbg(hsotg->dev, "Setting enable_dynamic_fifo to %d\n", val); | ||
2078 | } | ||
2079 | |||
2080 | hsotg->core_params->enable_dynamic_fifo = val; | ||
2081 | } | ||
2082 | |||
2083 | void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val) | ||
2084 | { | ||
2085 | int valid = 1; | ||
2086 | |||
2087 | if (val < 16 || val > hsotg->hw_params.host_rx_fifo_size) | ||
2088 | valid = 0; | ||
2089 | |||
2090 | if (!valid) { | ||
2091 | if (val >= 0) | ||
2092 | dev_err(hsotg->dev, | ||
2093 | "%d invalid for host_rx_fifo_size. Check HW configuration.\n", | ||
2094 | val); | ||
2095 | val = hsotg->hw_params.host_rx_fifo_size; | ||
2096 | dev_dbg(hsotg->dev, "Setting host_rx_fifo_size to %d\n", val); | ||
2097 | } | ||
2098 | |||
2099 | hsotg->core_params->host_rx_fifo_size = val; | ||
2100 | } | ||
2101 | |||
2102 | void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val) | ||
2103 | { | ||
2104 | int valid = 1; | ||
2105 | |||
2106 | if (val < 16 || val > hsotg->hw_params.host_nperio_tx_fifo_size) | ||
2107 | valid = 0; | ||
2108 | |||
2109 | if (!valid) { | ||
2110 | if (val >= 0) | ||
2111 | dev_err(hsotg->dev, | ||
2112 | "%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n", | ||
2113 | val); | ||
2114 | val = hsotg->hw_params.host_nperio_tx_fifo_size; | ||
2115 | dev_dbg(hsotg->dev, "Setting host_nperio_tx_fifo_size to %d\n", | ||
2116 | val); | ||
2117 | } | ||
2118 | |||
2119 | hsotg->core_params->host_nperio_tx_fifo_size = val; | ||
2120 | } | ||
2121 | |||
2122 | void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val) | ||
2123 | { | ||
2124 | int valid = 1; | ||
2125 | |||
2126 | if (val < 16 || val > hsotg->hw_params.host_perio_tx_fifo_size) | ||
2127 | valid = 0; | ||
2128 | |||
2129 | if (!valid) { | ||
2130 | if (val >= 0) | ||
2131 | dev_err(hsotg->dev, | ||
2132 | "%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n", | ||
2133 | val); | ||
2134 | val = hsotg->hw_params.host_perio_tx_fifo_size; | ||
2135 | dev_dbg(hsotg->dev, "Setting host_perio_tx_fifo_size to %d\n", | ||
2136 | val); | ||
2137 | } | ||
2138 | |||
2139 | hsotg->core_params->host_perio_tx_fifo_size = val; | ||
2140 | } | ||
2141 | |||
2142 | void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val) | ||
2143 | { | ||
2144 | int valid = 1; | ||
2145 | |||
2146 | if (val < 2047 || val > hsotg->hw_params.max_transfer_size) | ||
2147 | valid = 0; | ||
2148 | |||
2149 | if (!valid) { | ||
2150 | if (val >= 0) | ||
2151 | dev_err(hsotg->dev, | ||
2152 | "%d invalid for max_transfer_size. Check HW configuration.\n", | ||
2153 | val); | ||
2154 | val = hsotg->hw_params.max_transfer_size; | ||
2155 | dev_dbg(hsotg->dev, "Setting max_transfer_size to %d\n", val); | ||
2156 | } | ||
2157 | |||
2158 | hsotg->core_params->max_transfer_size = val; | ||
2159 | } | ||
2160 | |||
2161 | void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val) | ||
2162 | { | ||
2163 | int valid = 1; | ||
2164 | |||
2165 | if (val < 15 || val > hsotg->hw_params.max_packet_count) | ||
2166 | valid = 0; | ||
2167 | |||
2168 | if (!valid) { | ||
2169 | if (val >= 0) | ||
2170 | dev_err(hsotg->dev, | ||
2171 | "%d invalid for max_packet_count. Check HW configuration.\n", | ||
2172 | val); | ||
2173 | val = hsotg->hw_params.max_packet_count; | ||
2174 | dev_dbg(hsotg->dev, "Setting max_packet_count to %d\n", val); | ||
2175 | } | ||
2176 | |||
2177 | hsotg->core_params->max_packet_count = val; | ||
2178 | } | ||
2179 | |||
2180 | void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val) | ||
2181 | { | ||
2182 | int valid = 1; | ||
2183 | |||
2184 | if (val < 1 || val > hsotg->hw_params.host_channels) | ||
2185 | valid = 0; | ||
2186 | |||
2187 | if (!valid) { | ||
2188 | if (val >= 0) | ||
2189 | dev_err(hsotg->dev, | ||
2190 | "%d invalid for host_channels. Check HW configuration.\n", | ||
2191 | val); | ||
2192 | val = hsotg->hw_params.host_channels; | ||
2193 | dev_dbg(hsotg->dev, "Setting host_channels to %d\n", val); | ||
2194 | } | ||
2195 | |||
2196 | hsotg->core_params->host_channels = val; | ||
2197 | } | ||
2198 | |||
2199 | void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val) | ||
2200 | { | ||
2201 | int valid = 0; | ||
2202 | u32 hs_phy_type, fs_phy_type; | ||
2203 | |||
2204 | if (DWC2_OUT_OF_BOUNDS(val, DWC2_PHY_TYPE_PARAM_FS, | ||
2205 | DWC2_PHY_TYPE_PARAM_ULPI)) { | ||
2206 | if (val >= 0) { | ||
2207 | dev_err(hsotg->dev, "Wrong value for phy_type\n"); | ||
2208 | dev_err(hsotg->dev, "phy_type must be 0, 1 or 2\n"); | ||
2209 | } | ||
2210 | |||
2211 | valid = 0; | ||
2212 | } | ||
2213 | |||
2214 | hs_phy_type = hsotg->hw_params.hs_phy_type; | ||
2215 | fs_phy_type = hsotg->hw_params.fs_phy_type; | ||
2216 | if (val == DWC2_PHY_TYPE_PARAM_UTMI && | ||
2217 | (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || | ||
2218 | hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) | ||
2219 | valid = 1; | ||
2220 | else if (val == DWC2_PHY_TYPE_PARAM_ULPI && | ||
2221 | (hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI || | ||
2222 | hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) | ||
2223 | valid = 1; | ||
2224 | else if (val == DWC2_PHY_TYPE_PARAM_FS && | ||
2225 | fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) | ||
2226 | valid = 1; | ||
2227 | |||
2228 | if (!valid) { | ||
2229 | if (val >= 0) | ||
2230 | dev_err(hsotg->dev, | ||
2231 | "%d invalid for phy_type. Check HW configuration.\n", | ||
2232 | val); | ||
2233 | val = DWC2_PHY_TYPE_PARAM_FS; | ||
2234 | if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) { | ||
2235 | if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || | ||
2236 | hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI) | ||
2237 | val = DWC2_PHY_TYPE_PARAM_UTMI; | ||
2238 | else | ||
2239 | val = DWC2_PHY_TYPE_PARAM_ULPI; | ||
2240 | } | ||
2241 | dev_dbg(hsotg->dev, "Setting phy_type to %d\n", val); | ||
2242 | } | ||
2243 | |||
2244 | hsotg->core_params->phy_type = val; | ||
2245 | } | ||
2246 | |||
2247 | static int dwc2_get_param_phy_type(struct dwc2_hsotg *hsotg) | ||
2248 | { | ||
2249 | return hsotg->core_params->phy_type; | ||
2250 | } | ||
2251 | |||
2252 | void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val) | ||
2253 | { | ||
2254 | int valid = 1; | ||
2255 | |||
2256 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { | ||
2257 | if (val >= 0) { | ||
2258 | dev_err(hsotg->dev, "Wrong value for speed parameter\n"); | ||
2259 | dev_err(hsotg->dev, "max_speed parameter must be 0 or 1\n"); | ||
2260 | } | ||
2261 | valid = 0; | ||
2262 | } | ||
2263 | |||
2264 | if (val == DWC2_SPEED_PARAM_HIGH && | ||
2265 | dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS) | ||
2266 | valid = 0; | ||
2267 | |||
2268 | if (!valid) { | ||
2269 | if (val >= 0) | ||
2270 | dev_err(hsotg->dev, | ||
2271 | "%d invalid for speed parameter. Check HW configuration.\n", | ||
2272 | val); | ||
2273 | val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS ? | ||
2274 | DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH; | ||
2275 | dev_dbg(hsotg->dev, "Setting speed to %d\n", val); | ||
2276 | } | ||
2277 | |||
2278 | hsotg->core_params->speed = val; | ||
2279 | } | ||
2280 | |||
2281 | void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg, int val) | ||
2282 | { | ||
2283 | int valid = 1; | ||
2284 | |||
2285 | if (DWC2_OUT_OF_BOUNDS(val, DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ, | ||
2286 | DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)) { | ||
2287 | if (val >= 0) { | ||
2288 | dev_err(hsotg->dev, | ||
2289 | "Wrong value for host_ls_low_power_phy_clk parameter\n"); | ||
2290 | dev_err(hsotg->dev, | ||
2291 | "host_ls_low_power_phy_clk must be 0 or 1\n"); | ||
2292 | } | ||
2293 | valid = 0; | ||
2294 | } | ||
2295 | |||
2296 | if (val == DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ && | ||
2297 | dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS) | ||
2298 | valid = 0; | ||
2299 | |||
2300 | if (!valid) { | ||
2301 | if (val >= 0) | ||
2302 | dev_err(hsotg->dev, | ||
2303 | "%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n", | ||
2304 | val); | ||
2305 | val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS | ||
2306 | ? DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ | ||
2307 | : DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ; | ||
2308 | dev_dbg(hsotg->dev, "Setting host_ls_low_power_phy_clk to %d\n", | ||
2309 | val); | ||
2310 | } | ||
2311 | |||
2312 | hsotg->core_params->host_ls_low_power_phy_clk = val; | ||
2313 | } | ||
2314 | |||
2315 | void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val) | ||
2316 | { | ||
2317 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { | ||
2318 | if (val >= 0) { | ||
2319 | dev_err(hsotg->dev, "Wrong value for phy_ulpi_ddr\n"); | ||
2320 | dev_err(hsotg->dev, "phy_upli_ddr must be 0 or 1\n"); | ||
2321 | } | ||
2322 | val = 0; | ||
2323 | dev_dbg(hsotg->dev, "Setting phy_upli_ddr to %d\n", val); | ||
2324 | } | ||
2325 | |||
2326 | hsotg->core_params->phy_ulpi_ddr = val; | ||
2327 | } | ||
2328 | |||
2329 | void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val) | ||
2330 | { | ||
2331 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { | ||
2332 | if (val >= 0) { | ||
2333 | dev_err(hsotg->dev, | ||
2334 | "Wrong value for phy_ulpi_ext_vbus\n"); | ||
2335 | dev_err(hsotg->dev, | ||
2336 | "phy_ulpi_ext_vbus must be 0 or 1\n"); | ||
2337 | } | ||
2338 | val = 0; | ||
2339 | dev_dbg(hsotg->dev, "Setting phy_ulpi_ext_vbus to %d\n", val); | ||
2340 | } | ||
2341 | |||
2342 | hsotg->core_params->phy_ulpi_ext_vbus = val; | ||
2343 | } | ||
2344 | |||
2345 | void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val) | ||
2346 | { | ||
2347 | int valid = 0; | ||
2348 | |||
2349 | switch (hsotg->hw_params.utmi_phy_data_width) { | ||
2350 | case GHWCFG4_UTMI_PHY_DATA_WIDTH_8: | ||
2351 | valid = (val == 8); | ||
2352 | break; | ||
2353 | case GHWCFG4_UTMI_PHY_DATA_WIDTH_16: | ||
2354 | valid = (val == 16); | ||
2355 | break; | ||
2356 | case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16: | ||
2357 | valid = (val == 8 || val == 16); | ||
2358 | break; | ||
2359 | } | ||
2360 | |||
2361 | if (!valid) { | ||
2362 | if (val >= 0) { | ||
2363 | dev_err(hsotg->dev, | ||
2364 | "%d invalid for phy_utmi_width. Check HW configuration.\n", | ||
2365 | val); | ||
2366 | } | ||
2367 | val = (hsotg->hw_params.utmi_phy_data_width == | ||
2368 | GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16; | ||
2369 | dev_dbg(hsotg->dev, "Setting phy_utmi_width to %d\n", val); | ||
2370 | } | ||
2371 | |||
2372 | hsotg->core_params->phy_utmi_width = val; | ||
2373 | } | ||
2374 | |||
2375 | void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val) | ||
2376 | { | ||
2377 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { | ||
2378 | if (val >= 0) { | ||
2379 | dev_err(hsotg->dev, "Wrong value for ulpi_fs_ls\n"); | ||
2380 | dev_err(hsotg->dev, "ulpi_fs_ls must be 0 or 1\n"); | ||
2381 | } | ||
2382 | val = 0; | ||
2383 | dev_dbg(hsotg->dev, "Setting ulpi_fs_ls to %d\n", val); | ||
2384 | } | ||
2385 | |||
2386 | hsotg->core_params->ulpi_fs_ls = val; | ||
2387 | } | ||
2388 | |||
2389 | void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val) | ||
2390 | { | ||
2391 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { | ||
2392 | if (val >= 0) { | ||
2393 | dev_err(hsotg->dev, "Wrong value for ts_dline\n"); | ||
2394 | dev_err(hsotg->dev, "ts_dline must be 0 or 1\n"); | ||
2395 | } | ||
2396 | val = 0; | ||
2397 | dev_dbg(hsotg->dev, "Setting ts_dline to %d\n", val); | ||
2398 | } | ||
2399 | |||
2400 | hsotg->core_params->ts_dline = val; | ||
2401 | } | ||
2402 | |||
2403 | void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val) | ||
2404 | { | ||
2405 | int valid = 1; | ||
2406 | |||
2407 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { | ||
2408 | if (val >= 0) { | ||
2409 | dev_err(hsotg->dev, "Wrong value for i2c_enable\n"); | ||
2410 | dev_err(hsotg->dev, "i2c_enable must be 0 or 1\n"); | ||
2411 | } | ||
2412 | |||
2413 | valid = 0; | ||
2414 | } | ||
2415 | |||
2416 | if (val == 1 && !(hsotg->hw_params.i2c_enable)) | ||
2417 | valid = 0; | ||
2418 | |||
2419 | if (!valid) { | ||
2420 | if (val >= 0) | ||
2421 | dev_err(hsotg->dev, | ||
2422 | "%d invalid for i2c_enable. Check HW configuration.\n", | ||
2423 | val); | ||
2424 | val = hsotg->hw_params.i2c_enable; | ||
2425 | dev_dbg(hsotg->dev, "Setting i2c_enable to %d\n", val); | ||
2426 | } | ||
2427 | |||
2428 | hsotg->core_params->i2c_enable = val; | ||
2429 | } | ||
2430 | |||
2431 | void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg, int val) | ||
2432 | { | ||
2433 | int valid = 1; | ||
2434 | |||
2435 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { | ||
2436 | if (val >= 0) { | ||
2437 | dev_err(hsotg->dev, | ||
2438 | "Wrong value for en_multiple_tx_fifo,\n"); | ||
2439 | dev_err(hsotg->dev, | ||
2440 | "en_multiple_tx_fifo must be 0 or 1\n"); | ||
2441 | } | ||
2442 | valid = 0; | ||
2443 | } | ||
2444 | |||
2445 | if (val == 1 && !hsotg->hw_params.en_multiple_tx_fifo) | ||
2446 | valid = 0; | ||
2447 | |||
2448 | if (!valid) { | ||
2449 | if (val >= 0) | ||
2450 | dev_err(hsotg->dev, | ||
2451 | "%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n", | ||
2452 | val); | ||
2453 | val = hsotg->hw_params.en_multiple_tx_fifo; | ||
2454 | dev_dbg(hsotg->dev, "Setting en_multiple_tx_fifo to %d\n", val); | ||
2455 | } | ||
2456 | |||
2457 | hsotg->core_params->en_multiple_tx_fifo = val; | ||
2458 | } | ||
2459 | |||
2460 | void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val) | ||
2461 | { | ||
2462 | int valid = 1; | ||
2463 | |||
2464 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { | ||
2465 | if (val >= 0) { | ||
2466 | dev_err(hsotg->dev, | ||
2467 | "'%d' invalid for parameter reload_ctl\n", val); | ||
2468 | dev_err(hsotg->dev, "reload_ctl must be 0 or 1\n"); | ||
2469 | } | ||
2470 | valid = 0; | ||
2471 | } | ||
2472 | |||
2473 | if (val == 1 && hsotg->hw_params.snpsid < DWC2_CORE_REV_2_92a) | ||
2474 | valid = 0; | ||
2475 | |||
2476 | if (!valid) { | ||
2477 | if (val >= 0) | ||
2478 | dev_err(hsotg->dev, | ||
2479 | "%d invalid for parameter reload_ctl. Check HW configuration.\n", | ||
2480 | val); | ||
2481 | val = hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_92a; | ||
2482 | dev_dbg(hsotg->dev, "Setting reload_ctl to %d\n", val); | ||
2483 | } | ||
2484 | |||
2485 | hsotg->core_params->reload_ctl = val; | ||
2486 | } | ||
2487 | |||
2488 | void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val) | ||
2489 | { | ||
2490 | if (val != -1) | ||
2491 | hsotg->core_params->ahbcfg = val; | ||
2492 | else | ||
2493 | hsotg->core_params->ahbcfg = GAHBCFG_HBSTLEN_INCR4 << | ||
2494 | GAHBCFG_HBSTLEN_SHIFT; | ||
2495 | } | ||
2496 | |||
2497 | void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val) | ||
2498 | { | ||
2499 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { | ||
2500 | if (val >= 0) { | ||
2501 | dev_err(hsotg->dev, | ||
2502 | "'%d' invalid for parameter otg_ver\n", val); | ||
2503 | dev_err(hsotg->dev, | ||
2504 | "otg_ver must be 0 (for OTG 1.3 support) or 1 (for OTG 2.0 support)\n"); | ||
2505 | } | ||
2506 | val = 0; | ||
2507 | dev_dbg(hsotg->dev, "Setting otg_ver to %d\n", val); | ||
2508 | } | ||
2509 | |||
2510 | hsotg->core_params->otg_ver = val; | ||
2511 | } | ||
2512 | |||
2513 | static void dwc2_set_param_uframe_sched(struct dwc2_hsotg *hsotg, int val) | ||
2514 | { | ||
2515 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { | ||
2516 | if (val >= 0) { | ||
2517 | dev_err(hsotg->dev, | ||
2518 | "'%d' invalid for parameter uframe_sched\n", | ||
2519 | val); | ||
2520 | dev_err(hsotg->dev, "uframe_sched must be 0 or 1\n"); | ||
2521 | } | ||
2522 | val = 1; | ||
2523 | dev_dbg(hsotg->dev, "Setting uframe_sched to %d\n", val); | ||
2524 | } | ||
2525 | |||
2526 | hsotg->core_params->uframe_sched = val; | ||
2527 | } | ||
2528 | |||
2529 | /* | ||
2530 | * This function is called during module intialization to pass module parameters | ||
2531 | * for the DWC_otg core. | ||
2532 | */ | ||
2533 | void dwc2_set_parameters(struct dwc2_hsotg *hsotg, | ||
2534 | const struct dwc2_core_params *params) | ||
2535 | { | ||
2536 | dev_dbg(hsotg->dev, "%s()\n", __func__); | ||
2537 | |||
2538 | dwc2_set_param_otg_cap(hsotg, params->otg_cap); | ||
2539 | dwc2_set_param_dma_enable(hsotg, params->dma_enable); | ||
2540 | dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable); | ||
2541 | dwc2_set_param_host_support_fs_ls_low_power(hsotg, | ||
2542 | params->host_support_fs_ls_low_power); | ||
2543 | dwc2_set_param_enable_dynamic_fifo(hsotg, | ||
2544 | params->enable_dynamic_fifo); | ||
2545 | dwc2_set_param_host_rx_fifo_size(hsotg, | ||
2546 | params->host_rx_fifo_size); | ||
2547 | dwc2_set_param_host_nperio_tx_fifo_size(hsotg, | ||
2548 | params->host_nperio_tx_fifo_size); | ||
2549 | dwc2_set_param_host_perio_tx_fifo_size(hsotg, | ||
2550 | params->host_perio_tx_fifo_size); | ||
2551 | dwc2_set_param_max_transfer_size(hsotg, | ||
2552 | params->max_transfer_size); | ||
2553 | dwc2_set_param_max_packet_count(hsotg, | ||
2554 | params->max_packet_count); | ||
2555 | dwc2_set_param_host_channels(hsotg, params->host_channels); | ||
2556 | dwc2_set_param_phy_type(hsotg, params->phy_type); | ||
2557 | dwc2_set_param_speed(hsotg, params->speed); | ||
2558 | dwc2_set_param_host_ls_low_power_phy_clk(hsotg, | ||
2559 | params->host_ls_low_power_phy_clk); | ||
2560 | dwc2_set_param_phy_ulpi_ddr(hsotg, params->phy_ulpi_ddr); | ||
2561 | dwc2_set_param_phy_ulpi_ext_vbus(hsotg, | ||
2562 | params->phy_ulpi_ext_vbus); | ||
2563 | dwc2_set_param_phy_utmi_width(hsotg, params->phy_utmi_width); | ||
2564 | dwc2_set_param_ulpi_fs_ls(hsotg, params->ulpi_fs_ls); | ||
2565 | dwc2_set_param_ts_dline(hsotg, params->ts_dline); | ||
2566 | dwc2_set_param_i2c_enable(hsotg, params->i2c_enable); | ||
2567 | dwc2_set_param_en_multiple_tx_fifo(hsotg, | ||
2568 | params->en_multiple_tx_fifo); | ||
2569 | dwc2_set_param_reload_ctl(hsotg, params->reload_ctl); | ||
2570 | dwc2_set_param_ahbcfg(hsotg, params->ahbcfg); | ||
2571 | dwc2_set_param_otg_ver(hsotg, params->otg_ver); | ||
2572 | dwc2_set_param_uframe_sched(hsotg, params->uframe_sched); | ||
2573 | } | ||
2574 | |||
2575 | /** | ||
2576 | * During device initialization, read various hardware configuration | ||
2577 | * registers and interpret the contents. | ||
2578 | */ | ||
2579 | int dwc2_get_hwparams(struct dwc2_hsotg *hsotg) | ||
2580 | { | ||
2581 | struct dwc2_hw_params *hw = &hsotg->hw_params; | ||
2582 | unsigned width; | ||
2583 | u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4; | ||
2584 | u32 hptxfsiz, grxfsiz, gnptxfsiz; | ||
2585 | u32 gusbcfg; | ||
2586 | |||
2587 | /* | ||
2588 | * Attempt to ensure this device is really a DWC_otg Controller. | ||
2589 | * Read and verify the GSNPSID register contents. The value should be | ||
2590 | * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3", | ||
2591 | * as in "OTG version 2.xx" or "OTG version 3.xx". | ||
2592 | */ | ||
2593 | hw->snpsid = readl(hsotg->regs + GSNPSID); | ||
2594 | if ((hw->snpsid & 0xfffff000) != 0x4f542000 && | ||
2595 | (hw->snpsid & 0xfffff000) != 0x4f543000) { | ||
2596 | dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n", | ||
2597 | hw->snpsid); | ||
2598 | return -ENODEV; | ||
2599 | } | ||
2600 | |||
2601 | dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n", | ||
2602 | hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf, | ||
2603 | hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid); | ||
2604 | |||
2605 | hwcfg1 = readl(hsotg->regs + GHWCFG1); | ||
2606 | hwcfg2 = readl(hsotg->regs + GHWCFG2); | ||
2607 | hwcfg3 = readl(hsotg->regs + GHWCFG3); | ||
2608 | hwcfg4 = readl(hsotg->regs + GHWCFG4); | ||
2609 | gnptxfsiz = readl(hsotg->regs + GNPTXFSIZ); | ||
2610 | grxfsiz = readl(hsotg->regs + GRXFSIZ); | ||
2611 | |||
2612 | dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hwcfg1); | ||
2613 | dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hwcfg2); | ||
2614 | dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hwcfg3); | ||
2615 | dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4); | ||
2616 | dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); | ||
2617 | dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz); | ||
2618 | |||
2619 | /* Force host mode to get HPTXFSIZ exact power on value */ | ||
2620 | gusbcfg = readl(hsotg->regs + GUSBCFG); | ||
2621 | gusbcfg |= GUSBCFG_FORCEHOSTMODE; | ||
2622 | writel(gusbcfg, hsotg->regs + GUSBCFG); | ||
2623 | usleep_range(100000, 150000); | ||
2624 | |||
2625 | hptxfsiz = readl(hsotg->regs + HPTXFSIZ); | ||
2626 | dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz); | ||
2627 | gusbcfg = readl(hsotg->regs + GUSBCFG); | ||
2628 | gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; | ||
2629 | writel(gusbcfg, hsotg->regs + GUSBCFG); | ||
2630 | usleep_range(100000, 150000); | ||
2631 | |||
2632 | /* hwcfg2 */ | ||
2633 | hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >> | ||
2634 | GHWCFG2_OP_MODE_SHIFT; | ||
2635 | hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >> | ||
2636 | GHWCFG2_ARCHITECTURE_SHIFT; | ||
2637 | hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO); | ||
2638 | hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >> | ||
2639 | GHWCFG2_NUM_HOST_CHAN_SHIFT); | ||
2640 | hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >> | ||
2641 | GHWCFG2_HS_PHY_TYPE_SHIFT; | ||
2642 | hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >> | ||
2643 | GHWCFG2_FS_PHY_TYPE_SHIFT; | ||
2644 | hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >> | ||
2645 | GHWCFG2_NUM_DEV_EP_SHIFT; | ||
2646 | hw->nperio_tx_q_depth = | ||
2647 | (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >> | ||
2648 | GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1; | ||
2649 | hw->host_perio_tx_q_depth = | ||
2650 | (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >> | ||
2651 | GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1; | ||
2652 | hw->dev_token_q_depth = | ||
2653 | (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >> | ||
2654 | GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT; | ||
2655 | |||
2656 | /* hwcfg3 */ | ||
2657 | width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >> | ||
2658 | GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT; | ||
2659 | hw->max_transfer_size = (1 << (width + 11)) - 1; | ||
2660 | width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >> | ||
2661 | GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT; | ||
2662 | hw->max_packet_count = (1 << (width + 4)) - 1; | ||
2663 | hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C); | ||
2664 | hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >> | ||
2665 | GHWCFG3_DFIFO_DEPTH_SHIFT; | ||
2666 | |||
2667 | /* hwcfg4 */ | ||
2668 | hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN); | ||
2669 | hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >> | ||
2670 | GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT; | ||
2671 | hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA); | ||
2672 | hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ); | ||
2673 | hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >> | ||
2674 | GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT; | ||
2675 | |||
2676 | /* fifo sizes */ | ||
2677 | hw->host_rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >> | ||
2678 | GRXFSIZ_DEPTH_SHIFT; | ||
2679 | hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> | ||
2680 | FIFOSIZE_DEPTH_SHIFT; | ||
2681 | hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >> | ||
2682 | FIFOSIZE_DEPTH_SHIFT; | ||
2683 | |||
2684 | dev_dbg(hsotg->dev, "Detected values from hardware:\n"); | ||
2685 | dev_dbg(hsotg->dev, " op_mode=%d\n", | ||
2686 | hw->op_mode); | ||
2687 | dev_dbg(hsotg->dev, " arch=%d\n", | ||
2688 | hw->arch); | ||
2689 | dev_dbg(hsotg->dev, " dma_desc_enable=%d\n", | ||
2690 | hw->dma_desc_enable); | ||
2691 | dev_dbg(hsotg->dev, " power_optimized=%d\n", | ||
2692 | hw->power_optimized); | ||
2693 | dev_dbg(hsotg->dev, " i2c_enable=%d\n", | ||
2694 | hw->i2c_enable); | ||
2695 | dev_dbg(hsotg->dev, " hs_phy_type=%d\n", | ||
2696 | hw->hs_phy_type); | ||
2697 | dev_dbg(hsotg->dev, " fs_phy_type=%d\n", | ||
2698 | hw->fs_phy_type); | ||
2699 | dev_dbg(hsotg->dev, " utmi_phy_data_wdith=%d\n", | ||
2700 | hw->utmi_phy_data_width); | ||
2701 | dev_dbg(hsotg->dev, " num_dev_ep=%d\n", | ||
2702 | hw->num_dev_ep); | ||
2703 | dev_dbg(hsotg->dev, " num_dev_perio_in_ep=%d\n", | ||
2704 | hw->num_dev_perio_in_ep); | ||
2705 | dev_dbg(hsotg->dev, " host_channels=%d\n", | ||
2706 | hw->host_channels); | ||
2707 | dev_dbg(hsotg->dev, " max_transfer_size=%d\n", | ||
2708 | hw->max_transfer_size); | ||
2709 | dev_dbg(hsotg->dev, " max_packet_count=%d\n", | ||
2710 | hw->max_packet_count); | ||
2711 | dev_dbg(hsotg->dev, " nperio_tx_q_depth=0x%0x\n", | ||
2712 | hw->nperio_tx_q_depth); | ||
2713 | dev_dbg(hsotg->dev, " host_perio_tx_q_depth=0x%0x\n", | ||
2714 | hw->host_perio_tx_q_depth); | ||
2715 | dev_dbg(hsotg->dev, " dev_token_q_depth=0x%0x\n", | ||
2716 | hw->dev_token_q_depth); | ||
2717 | dev_dbg(hsotg->dev, " enable_dynamic_fifo=%d\n", | ||
2718 | hw->enable_dynamic_fifo); | ||
2719 | dev_dbg(hsotg->dev, " en_multiple_tx_fifo=%d\n", | ||
2720 | hw->en_multiple_tx_fifo); | ||
2721 | dev_dbg(hsotg->dev, " total_fifo_size=%d\n", | ||
2722 | hw->total_fifo_size); | ||
2723 | dev_dbg(hsotg->dev, " host_rx_fifo_size=%d\n", | ||
2724 | hw->host_rx_fifo_size); | ||
2725 | dev_dbg(hsotg->dev, " host_nperio_tx_fifo_size=%d\n", | ||
2726 | hw->host_nperio_tx_fifo_size); | ||
2727 | dev_dbg(hsotg->dev, " host_perio_tx_fifo_size=%d\n", | ||
2728 | hw->host_perio_tx_fifo_size); | ||
2729 | dev_dbg(hsotg->dev, "\n"); | ||
2730 | |||
2731 | return 0; | ||
2732 | } | ||
2733 | |||
2734 | u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg) | ||
2735 | { | ||
2736 | return hsotg->core_params->otg_ver == 1 ? 0x0200 : 0x0103; | ||
2737 | } | ||
2738 | |||
2739 | bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg) | ||
2740 | { | ||
2741 | if (readl(hsotg->regs + GSNPSID) == 0xffffffff) | ||
2742 | return false; | ||
2743 | else | ||
2744 | return true; | ||
2745 | } | ||
2746 | |||
2747 | /** | ||
2748 | * dwc2_enable_global_interrupts() - Enables the controller's Global | ||
2749 | * Interrupt in the AHB Config register | ||
2750 | * | ||
2751 | * @hsotg: Programming view of DWC_otg controller | ||
2752 | */ | ||
2753 | void dwc2_enable_global_interrupts(struct dwc2_hsotg *hsotg) | ||
2754 | { | ||
2755 | u32 ahbcfg = readl(hsotg->regs + GAHBCFG); | ||
2756 | |||
2757 | ahbcfg |= GAHBCFG_GLBL_INTR_EN; | ||
2758 | writel(ahbcfg, hsotg->regs + GAHBCFG); | ||
2759 | } | ||
2760 | |||
2761 | /** | ||
2762 | * dwc2_disable_global_interrupts() - Disables the controller's Global | ||
2763 | * Interrupt in the AHB Config register | ||
2764 | * | ||
2765 | * @hsotg: Programming view of DWC_otg controller | ||
2766 | */ | ||
2767 | void dwc2_disable_global_interrupts(struct dwc2_hsotg *hsotg) | ||
2768 | { | ||
2769 | u32 ahbcfg = readl(hsotg->regs + GAHBCFG); | ||
2770 | |||
2771 | ahbcfg &= ~GAHBCFG_GLBL_INTR_EN; | ||
2772 | writel(ahbcfg, hsotg->regs + GAHBCFG); | ||
2773 | } | ||
2774 | |||
2775 | MODULE_DESCRIPTION("DESIGNWARE HS OTG Core"); | ||
2776 | MODULE_AUTHOR("Synopsys, Inc."); | ||
2777 | MODULE_LICENSE("Dual BSD/GPL"); | ||
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h new file mode 100644 index 000000000000..648519c024b5 --- /dev/null +++ b/drivers/usb/dwc2/core.h | |||
@@ -0,0 +1,768 @@ | |||
1 | /* | ||
2 | * core.h - DesignWare HS OTG Controller common declarations | ||
3 | * | ||
4 | * Copyright (C) 2004-2013 Synopsys, Inc. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions, and the following disclaimer, | ||
11 | * without modification. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The names of the above-listed copyright holders may not be used | ||
16 | * to endorse or promote products derived from this software without | ||
17 | * specific prior written permission. | ||
18 | * | ||
19 | * ALTERNATIVELY, this software may be distributed under the terms of the | ||
20 | * GNU General Public License ("GPL") as published by the Free Software | ||
21 | * Foundation; either version 2 of the License, or (at your option) any | ||
22 | * later version. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
26 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
35 | */ | ||
36 | |||
37 | #ifndef __DWC2_CORE_H__ | ||
38 | #define __DWC2_CORE_H__ | ||
39 | |||
40 | #include <linux/usb/phy.h> | ||
41 | #include "hw.h" | ||
42 | |||
43 | #ifdef DWC2_LOG_WRITES | ||
44 | static inline void do_write(u32 value, void *addr) | ||
45 | { | ||
46 | writel(value, addr); | ||
47 | pr_info("INFO:: wrote %08x to %p\n", value, addr); | ||
48 | } | ||
49 | |||
50 | #undef writel | ||
51 | #define writel(v, a) do_write(v, a) | ||
52 | #endif | ||
53 | |||
54 | /* Maximum number of Endpoints/HostChannels */ | ||
55 | #define MAX_EPS_CHANNELS 16 | ||
56 | |||
57 | struct dwc2_hsotg; | ||
58 | struct dwc2_host_chan; | ||
59 | |||
60 | /* Device States */ | ||
61 | enum dwc2_lx_state { | ||
62 | DWC2_L0, /* On state */ | ||
63 | DWC2_L1, /* LPM sleep state */ | ||
64 | DWC2_L2, /* USB suspend state */ | ||
65 | DWC2_L3, /* Off state */ | ||
66 | }; | ||
67 | |||
68 | /** | ||
69 | * struct dwc2_core_params - Parameters for configuring the core | ||
70 | * | ||
71 | * @otg_cap: Specifies the OTG capabilities. | ||
72 | * 0 - HNP and SRP capable | ||
73 | * 1 - SRP Only capable | ||
74 | * 2 - No HNP/SRP capable (always available) | ||
75 | * Defaults to best available option (0, 1, then 2) | ||
76 | * @otg_ver: OTG version supported | ||
77 | * 0 - 1.3 (default) | ||
78 | * 1 - 2.0 | ||
79 | * @dma_enable: Specifies whether to use slave or DMA mode for accessing | ||
80 | * the data FIFOs. The driver will automatically detect the | ||
81 | * value for this parameter if none is specified. | ||
82 | * 0 - Slave (always available) | ||
83 | * 1 - DMA (default, if available) | ||
84 | * @dma_desc_enable: When DMA mode is enabled, specifies whether to use | ||
85 | * address DMA mode or descriptor DMA mode for accessing | ||
86 | * the data FIFOs. The driver will automatically detect the | ||
87 | * value for this if none is specified. | ||
88 | * 0 - Address DMA | ||
89 | * 1 - Descriptor DMA (default, if available) | ||
90 | * @speed: Specifies the maximum speed of operation in host and | ||
91 | * device mode. The actual speed depends on the speed of | ||
92 | * the attached device and the value of phy_type. | ||
93 | * 0 - High Speed | ||
94 | * (default when phy_type is UTMI+ or ULPI) | ||
95 | * 1 - Full Speed | ||
96 | * (default when phy_type is Full Speed) | ||
97 | * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters | ||
98 | * 1 - Allow dynamic FIFO sizing (default, if available) | ||
99 | * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs | ||
100 | * are enabled | ||
101 | * @host_rx_fifo_size: Number of 4-byte words in the Rx FIFO in host mode when | ||
102 | * dynamic FIFO sizing is enabled | ||
103 | * 16 to 32768 | ||
104 | * Actual maximum value is autodetected and also | ||
105 | * the default. | ||
106 | * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO | ||
107 | * in host mode when dynamic FIFO sizing is enabled | ||
108 | * 16 to 32768 | ||
109 | * Actual maximum value is autodetected and also | ||
110 | * the default. | ||
111 | * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in | ||
112 | * host mode when dynamic FIFO sizing is enabled | ||
113 | * 16 to 32768 | ||
114 | * Actual maximum value is autodetected and also | ||
115 | * the default. | ||
116 | * @max_transfer_size: The maximum transfer size supported, in bytes | ||
117 | * 2047 to 65,535 | ||
118 | * Actual maximum value is autodetected and also | ||
119 | * the default. | ||
120 | * @max_packet_count: The maximum number of packets in a transfer | ||
121 | * 15 to 511 | ||
122 | * Actual maximum value is autodetected and also | ||
123 | * the default. | ||
124 | * @host_channels: The number of host channel registers to use | ||
125 | * 1 to 16 | ||
126 | * Actual maximum value is autodetected and also | ||
127 | * the default. | ||
128 | * @phy_type: Specifies the type of PHY interface to use. By default, | ||
129 | * the driver will automatically detect the phy_type. | ||
130 | * 0 - Full Speed Phy | ||
131 | * 1 - UTMI+ Phy | ||
132 | * 2 - ULPI Phy | ||
133 | * Defaults to best available option (2, 1, then 0) | ||
134 | * @phy_utmi_width: Specifies the UTMI+ Data Width (in bits). This parameter | ||
135 | * is applicable for a phy_type of UTMI+ or ULPI. (For a | ||
136 | * ULPI phy_type, this parameter indicates the data width | ||
137 | * between the MAC and the ULPI Wrapper.) Also, this | ||
138 | * parameter is applicable only if the OTG_HSPHY_WIDTH cC | ||
139 | * parameter was set to "8 and 16 bits", meaning that the | ||
140 | * core has been configured to work at either data path | ||
141 | * width. | ||
142 | * 8 or 16 (default 16 if available) | ||
143 | * @phy_ulpi_ddr: Specifies whether the ULPI operates at double or single | ||
144 | * data rate. This parameter is only applicable if phy_type | ||
145 | * is ULPI. | ||
146 | * 0 - single data rate ULPI interface with 8 bit wide | ||
147 | * data bus (default) | ||
148 | * 1 - double data rate ULPI interface with 4 bit wide | ||
149 | * data bus | ||
150 | * @phy_ulpi_ext_vbus: For a ULPI phy, specifies whether to use the internal or | ||
151 | * external supply to drive the VBus | ||
152 | * 0 - Internal supply (default) | ||
153 | * 1 - External supply | ||
154 | * @i2c_enable: Specifies whether to use the I2Cinterface for a full | ||
155 | * speed PHY. This parameter is only applicable if phy_type | ||
156 | * is FS. | ||
157 | * 0 - No (default) | ||
158 | * 1 - Yes | ||
159 | * @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only | ||
160 | * 0 - No (default) | ||
161 | * 1 - Yes | ||
162 | * @host_support_fs_ls_low_power: Specifies whether low power mode is supported | ||
163 | * when attached to a Full Speed or Low Speed device in | ||
164 | * host mode. | ||
165 | * 0 - Don't support low power mode (default) | ||
166 | * 1 - Support low power mode | ||
167 | * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode | ||
168 | * when connected to a Low Speed device in host | ||
169 | * mode. This parameter is applicable only if | ||
170 | * host_support_fs_ls_low_power is enabled. | ||
171 | * 0 - 48 MHz | ||
172 | * (default when phy_type is UTMI+ or ULPI) | ||
173 | * 1 - 6 MHz | ||
174 | * (default when phy_type is Full Speed) | ||
175 | * @ts_dline: Enable Term Select Dline pulsing | ||
176 | * 0 - No (default) | ||
177 | * 1 - Yes | ||
178 | * @reload_ctl: Allow dynamic reloading of HFIR register during runtime | ||
179 | * 0 - No (default for core < 2.92a) | ||
180 | * 1 - Yes (default for core >= 2.92a) | ||
181 | * @ahbcfg: This field allows the default value of the GAHBCFG | ||
182 | * register to be overridden | ||
183 | * -1 - GAHBCFG value will be set to 0x06 | ||
184 | * (INCR4, default) | ||
185 | * all others - GAHBCFG value will be overridden with | ||
186 | * this value | ||
187 | * Not all bits can be controlled like this, the | ||
188 | * bits defined by GAHBCFG_CTRL_MASK are controlled | ||
189 | * by the driver and are ignored in this | ||
190 | * configuration value. | ||
191 | * @uframe_sched: True to enable the microframe scheduler | ||
192 | * | ||
193 | * The following parameters may be specified when starting the module. These | ||
194 | * parameters define how the DWC_otg controller should be configured. A | ||
195 | * value of -1 (or any other out of range value) for any parameter means | ||
196 | * to read the value from hardware (if possible) or use the builtin | ||
197 | * default described above. | ||
198 | */ | ||
199 | struct dwc2_core_params { | ||
200 | /* | ||
201 | * Don't add any non-int members here, this will break | ||
202 | * dwc2_set_all_params! | ||
203 | */ | ||
204 | int otg_cap; | ||
205 | int otg_ver; | ||
206 | int dma_enable; | ||
207 | int dma_desc_enable; | ||
208 | int speed; | ||
209 | int enable_dynamic_fifo; | ||
210 | int en_multiple_tx_fifo; | ||
211 | int host_rx_fifo_size; | ||
212 | int host_nperio_tx_fifo_size; | ||
213 | int host_perio_tx_fifo_size; | ||
214 | int max_transfer_size; | ||
215 | int max_packet_count; | ||
216 | int host_channels; | ||
217 | int phy_type; | ||
218 | int phy_utmi_width; | ||
219 | int phy_ulpi_ddr; | ||
220 | int phy_ulpi_ext_vbus; | ||
221 | int i2c_enable; | ||
222 | int ulpi_fs_ls; | ||
223 | int host_support_fs_ls_low_power; | ||
224 | int host_ls_low_power_phy_clk; | ||
225 | int ts_dline; | ||
226 | int reload_ctl; | ||
227 | int ahbcfg; | ||
228 | int uframe_sched; | ||
229 | }; | ||
230 | |||
231 | /** | ||
232 | * struct dwc2_hw_params - Autodetected parameters. | ||
233 | * | ||
234 | * These parameters are the various parameters read from hardware | ||
235 | * registers during initialization. They typically contain the best | ||
236 | * supported or maximum value that can be configured in the | ||
237 | * corresponding dwc2_core_params value. | ||
238 | * | ||
239 | * The values that are not in dwc2_core_params are documented below. | ||
240 | * | ||
241 | * @op_mode Mode of Operation | ||
242 | * 0 - HNP- and SRP-Capable OTG (Host & Device) | ||
243 | * 1 - SRP-Capable OTG (Host & Device) | ||
244 | * 2 - Non-HNP and Non-SRP Capable OTG (Host & Device) | ||
245 | * 3 - SRP-Capable Device | ||
246 | * 4 - Non-OTG Device | ||
247 | * 5 - SRP-Capable Host | ||
248 | * 6 - Non-OTG Host | ||
249 | * @arch Architecture | ||
250 | * 0 - Slave only | ||
251 | * 1 - External DMA | ||
252 | * 2 - Internal DMA | ||
253 | * @power_optimized Are power optimizations enabled? | ||
254 | * @num_dev_ep Number of device endpoints available | ||
255 | * @num_dev_perio_in_ep Number of device periodic IN endpoints | ||
256 | * avaialable | ||
257 | * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue | ||
258 | * Depth | ||
259 | * 0 to 30 | ||
260 | * @host_perio_tx_q_depth | ||
261 | * Host Mode Periodic Request Queue Depth | ||
262 | * 2, 4 or 8 | ||
263 | * @nperio_tx_q_depth | ||
264 | * Non-Periodic Request Queue Depth | ||
265 | * 2, 4 or 8 | ||
266 | * @hs_phy_type High-speed PHY interface type | ||
267 | * 0 - High-speed interface not supported | ||
268 | * 1 - UTMI+ | ||
269 | * 2 - ULPI | ||
270 | * 3 - UTMI+ and ULPI | ||
271 | * @fs_phy_type Full-speed PHY interface type | ||
272 | * 0 - Full speed interface not supported | ||
273 | * 1 - Dedicated full speed interface | ||
274 | * 2 - FS pins shared with UTMI+ pins | ||
275 | * 3 - FS pins shared with ULPI pins | ||
276 | * @total_fifo_size: Total internal RAM for FIFOs (bytes) | ||
277 | * @utmi_phy_data_width UTMI+ PHY data width | ||
278 | * 0 - 8 bits | ||
279 | * 1 - 16 bits | ||
280 | * 2 - 8 or 16 bits | ||
281 | * @snpsid: Value from SNPSID register | ||
282 | */ | ||
283 | struct dwc2_hw_params { | ||
284 | unsigned op_mode:3; | ||
285 | unsigned arch:2; | ||
286 | unsigned dma_desc_enable:1; | ||
287 | unsigned enable_dynamic_fifo:1; | ||
288 | unsigned en_multiple_tx_fifo:1; | ||
289 | unsigned host_rx_fifo_size:16; | ||
290 | unsigned host_nperio_tx_fifo_size:16; | ||
291 | unsigned host_perio_tx_fifo_size:16; | ||
292 | unsigned nperio_tx_q_depth:3; | ||
293 | unsigned host_perio_tx_q_depth:3; | ||
294 | unsigned dev_token_q_depth:5; | ||
295 | unsigned max_transfer_size:26; | ||
296 | unsigned max_packet_count:11; | ||
297 | unsigned host_channels:5; | ||
298 | unsigned hs_phy_type:2; | ||
299 | unsigned fs_phy_type:2; | ||
300 | unsigned i2c_enable:1; | ||
301 | unsigned num_dev_ep:4; | ||
302 | unsigned num_dev_perio_in_ep:4; | ||
303 | unsigned total_fifo_size:16; | ||
304 | unsigned power_optimized:1; | ||
305 | unsigned utmi_phy_data_width:2; | ||
306 | u32 snpsid; | ||
307 | }; | ||
308 | |||
309 | /** | ||
310 | * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic | ||
311 | * and periodic schedules | ||
312 | * | ||
313 | * @dev: The struct device pointer | ||
314 | * @regs: Pointer to controller regs | ||
315 | * @core_params: Parameters that define how the core should be configured | ||
316 | * @hw_params: Parameters that were autodetected from the | ||
317 | * hardware registers | ||
318 | * @op_state: The operational State, during transitions (a_host=> | ||
319 | * a_peripheral and b_device=>b_host) this may not match | ||
320 | * the core, but allows the software to determine | ||
321 | * transitions | ||
322 | * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth | ||
323 | * transfer are in process of being queued | ||
324 | * @srp_success: Stores status of SRP request in the case of a FS PHY | ||
325 | * with an I2C interface | ||
326 | * @wq_otg: Workqueue object used for handling of some interrupts | ||
327 | * @wf_otg: Work object for handling Connector ID Status Change | ||
328 | * interrupt | ||
329 | * @wkp_timer: Timer object for handling Wakeup Detected interrupt | ||
330 | * @lx_state: Lx state of connected device | ||
331 | * @flags: Flags for handling root port state changes | ||
332 | * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule. | ||
333 | * Transfers associated with these QHs are not currently | ||
334 | * assigned to a host channel. | ||
335 | * @non_periodic_sched_active: Active QHs in the non-periodic schedule. | ||
336 | * Transfers associated with these QHs are currently | ||
337 | * assigned to a host channel. | ||
338 | * @non_periodic_qh_ptr: Pointer to next QH to process in the active | ||
339 | * non-periodic schedule | ||
340 | * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a | ||
341 | * list of QHs for periodic transfers that are _not_ | ||
342 | * scheduled for the next frame. Each QH in the list has an | ||
343 | * interval counter that determines when it needs to be | ||
344 | * scheduled for execution. This scheduling mechanism | ||
345 | * allows only a simple calculation for periodic bandwidth | ||
346 | * used (i.e. must assume that all periodic transfers may | ||
347 | * need to execute in the same frame). However, it greatly | ||
348 | * simplifies scheduling and should be sufficient for the | ||
349 | * vast majority of OTG hosts, which need to connect to a | ||
350 | * small number of peripherals at one time. Items move from | ||
351 | * this list to periodic_sched_ready when the QH interval | ||
352 | * counter is 0 at SOF. | ||
353 | * @periodic_sched_ready: List of periodic QHs that are ready for execution in | ||
354 | * the next frame, but have not yet been assigned to host | ||
355 | * channels. Items move from this list to | ||
356 | * periodic_sched_assigned as host channels become | ||
357 | * available during the current frame. | ||
358 | * @periodic_sched_assigned: List of periodic QHs to be executed in the next | ||
359 | * frame that are assigned to host channels. Items move | ||
360 | * from this list to periodic_sched_queued as the | ||
361 | * transactions for the QH are queued to the DWC_otg | ||
362 | * controller. | ||
363 | * @periodic_sched_queued: List of periodic QHs that have been queued for | ||
364 | * execution. Items move from this list to either | ||
365 | * periodic_sched_inactive or periodic_sched_ready when the | ||
366 | * channel associated with the transfer is released. If the | ||
367 | * interval for the QH is 1, the item moves to | ||
368 | * periodic_sched_ready because it must be rescheduled for | ||
369 | * the next frame. Otherwise, the item moves to | ||
370 | * periodic_sched_inactive. | ||
371 | * @periodic_usecs: Total bandwidth claimed so far for periodic transfers. | ||
372 | * This value is in microseconds per (micro)frame. The | ||
373 | * assumption is that all periodic transfers may occur in | ||
374 | * the same (micro)frame. | ||
375 | * @frame_usecs: Internal variable used by the microframe scheduler | ||
376 | * @frame_number: Frame number read from the core at SOF. The value ranges | ||
377 | * from 0 to HFNUM_MAX_FRNUM. | ||
378 | * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for | ||
379 | * SOF enable/disable. | ||
380 | * @free_hc_list: Free host channels in the controller. This is a list of | ||
381 | * struct dwc2_host_chan items. | ||
382 | * @periodic_channels: Number of host channels assigned to periodic transfers. | ||
383 | * Currently assuming that there is a dedicated host | ||
384 | * channel for each periodic transaction and at least one | ||
385 | * host channel is available for non-periodic transactions. | ||
386 | * @non_periodic_channels: Number of host channels assigned to non-periodic | ||
387 | * transfers | ||
388 | * @available_host_channels Number of host channels available for the microframe | ||
389 | * scheduler to use | ||
390 | * @hc_ptr_array: Array of pointers to the host channel descriptors. | ||
391 | * Allows accessing a host channel descriptor given the | ||
392 | * host channel number. This is useful in interrupt | ||
393 | * handlers. | ||
394 | * @status_buf: Buffer used for data received during the status phase of | ||
395 | * a control transfer. | ||
396 | * @status_buf_dma: DMA address for status_buf | ||
397 | * @start_work: Delayed work for handling host A-cable connection | ||
398 | * @reset_work: Delayed work for handling a port reset | ||
399 | * @lock: Spinlock that protects all the driver data structures | ||
400 | * @priv: Stores a pointer to the struct usb_hcd | ||
401 | * @otg_port: OTG port number | ||
402 | * @frame_list: Frame list | ||
403 | * @frame_list_dma: Frame list DMA address | ||
404 | */ | ||
405 | struct dwc2_hsotg { | ||
406 | struct device *dev; | ||
407 | void __iomem *regs; | ||
408 | /** Params detected from hardware */ | ||
409 | struct dwc2_hw_params hw_params; | ||
410 | /** Params to actually use */ | ||
411 | struct dwc2_core_params *core_params; | ||
412 | enum usb_otg_state op_state; | ||
413 | |||
414 | unsigned int queuing_high_bandwidth:1; | ||
415 | unsigned int srp_success:1; | ||
416 | |||
417 | struct workqueue_struct *wq_otg; | ||
418 | struct work_struct wf_otg; | ||
419 | struct timer_list wkp_timer; | ||
420 | enum dwc2_lx_state lx_state; | ||
421 | |||
422 | union dwc2_hcd_internal_flags { | ||
423 | u32 d32; | ||
424 | struct { | ||
425 | unsigned port_connect_status_change:1; | ||
426 | unsigned port_connect_status:1; | ||
427 | unsigned port_reset_change:1; | ||
428 | unsigned port_enable_change:1; | ||
429 | unsigned port_suspend_change:1; | ||
430 | unsigned port_over_current_change:1; | ||
431 | unsigned port_l1_change:1; | ||
432 | unsigned reserved:26; | ||
433 | } b; | ||
434 | } flags; | ||
435 | |||
436 | struct list_head non_periodic_sched_inactive; | ||
437 | struct list_head non_periodic_sched_active; | ||
438 | struct list_head *non_periodic_qh_ptr; | ||
439 | struct list_head periodic_sched_inactive; | ||
440 | struct list_head periodic_sched_ready; | ||
441 | struct list_head periodic_sched_assigned; | ||
442 | struct list_head periodic_sched_queued; | ||
443 | u16 periodic_usecs; | ||
444 | u16 frame_usecs[8]; | ||
445 | u16 frame_number; | ||
446 | u16 periodic_qh_count; | ||
447 | |||
448 | #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS | ||
449 | #define FRAME_NUM_ARRAY_SIZE 1000 | ||
450 | u16 last_frame_num; | ||
451 | u16 *frame_num_array; | ||
452 | u16 *last_frame_num_array; | ||
453 | int frame_num_idx; | ||
454 | int dumped_frame_num_array; | ||
455 | #endif | ||
456 | |||
457 | struct list_head free_hc_list; | ||
458 | int periodic_channels; | ||
459 | int non_periodic_channels; | ||
460 | int available_host_channels; | ||
461 | struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS]; | ||
462 | u8 *status_buf; | ||
463 | dma_addr_t status_buf_dma; | ||
464 | #define DWC2_HCD_STATUS_BUF_SIZE 64 | ||
465 | |||
466 | struct delayed_work start_work; | ||
467 | struct delayed_work reset_work; | ||
468 | spinlock_t lock; | ||
469 | void *priv; | ||
470 | u8 otg_port; | ||
471 | u32 *frame_list; | ||
472 | dma_addr_t frame_list_dma; | ||
473 | |||
474 | /* DWC OTG HW Release versions */ | ||
475 | #define DWC2_CORE_REV_2_71a 0x4f54271a | ||
476 | #define DWC2_CORE_REV_2_90a 0x4f54290a | ||
477 | #define DWC2_CORE_REV_2_92a 0x4f54292a | ||
478 | #define DWC2_CORE_REV_2_94a 0x4f54294a | ||
479 | #define DWC2_CORE_REV_3_00a 0x4f54300a | ||
480 | |||
481 | #ifdef DEBUG | ||
482 | u32 frrem_samples; | ||
483 | u64 frrem_accum; | ||
484 | |||
485 | u32 hfnum_7_samples_a; | ||
486 | u64 hfnum_7_frrem_accum_a; | ||
487 | u32 hfnum_0_samples_a; | ||
488 | u64 hfnum_0_frrem_accum_a; | ||
489 | u32 hfnum_other_samples_a; | ||
490 | u64 hfnum_other_frrem_accum_a; | ||
491 | |||
492 | u32 hfnum_7_samples_b; | ||
493 | u64 hfnum_7_frrem_accum_b; | ||
494 | u32 hfnum_0_samples_b; | ||
495 | u64 hfnum_0_frrem_accum_b; | ||
496 | u32 hfnum_other_samples_b; | ||
497 | u64 hfnum_other_frrem_accum_b; | ||
498 | #endif | ||
499 | }; | ||
500 | |||
501 | /* Reasons for halting a host channel */ | ||
502 | enum dwc2_halt_status { | ||
503 | DWC2_HC_XFER_NO_HALT_STATUS, | ||
504 | DWC2_HC_XFER_COMPLETE, | ||
505 | DWC2_HC_XFER_URB_COMPLETE, | ||
506 | DWC2_HC_XFER_ACK, | ||
507 | DWC2_HC_XFER_NAK, | ||
508 | DWC2_HC_XFER_NYET, | ||
509 | DWC2_HC_XFER_STALL, | ||
510 | DWC2_HC_XFER_XACT_ERR, | ||
511 | DWC2_HC_XFER_FRAME_OVERRUN, | ||
512 | DWC2_HC_XFER_BABBLE_ERR, | ||
513 | DWC2_HC_XFER_DATA_TOGGLE_ERR, | ||
514 | DWC2_HC_XFER_AHB_ERR, | ||
515 | DWC2_HC_XFER_PERIODIC_INCOMPLETE, | ||
516 | DWC2_HC_XFER_URB_DEQUEUE, | ||
517 | }; | ||
518 | |||
519 | /* | ||
520 | * The following functions support initialization of the core driver component | ||
521 | * and the DWC_otg controller | ||
522 | */ | ||
523 | extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg); | ||
524 | |||
525 | /* | ||
526 | * Host core Functions. | ||
527 | * The following functions support managing the DWC_otg controller in host | ||
528 | * mode. | ||
529 | */ | ||
530 | extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan); | ||
531 | extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan, | ||
532 | enum dwc2_halt_status halt_status); | ||
533 | extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, | ||
534 | struct dwc2_host_chan *chan); | ||
535 | extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg, | ||
536 | struct dwc2_host_chan *chan); | ||
537 | extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg, | ||
538 | struct dwc2_host_chan *chan); | ||
539 | extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg, | ||
540 | struct dwc2_host_chan *chan); | ||
541 | extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg, | ||
542 | struct dwc2_host_chan *chan); | ||
543 | extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg); | ||
544 | extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg); | ||
545 | |||
546 | extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg); | ||
547 | extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg); | ||
548 | |||
549 | /* | ||
550 | * Common core Functions. | ||
551 | * The following functions support managing the DWC_otg controller in either | ||
552 | * device or host mode. | ||
553 | */ | ||
554 | extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes); | ||
555 | extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num); | ||
556 | extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg); | ||
557 | |||
558 | extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq); | ||
559 | extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd); | ||
560 | extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd); | ||
561 | |||
562 | /* This function should be called on every hardware interrupt. */ | ||
563 | extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev); | ||
564 | |||
565 | /* OTG Core Parameters */ | ||
566 | |||
567 | /* | ||
568 | * Specifies the OTG capabilities. The driver will automatically | ||
569 | * detect the value for this parameter if none is specified. | ||
570 | * 0 - HNP and SRP capable (default) | ||
571 | * 1 - SRP Only capable | ||
572 | * 2 - No HNP/SRP capable | ||
573 | */ | ||
574 | extern void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val); | ||
575 | #define DWC2_CAP_PARAM_HNP_SRP_CAPABLE 0 | ||
576 | #define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE 1 | ||
577 | #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE 2 | ||
578 | |||
579 | /* | ||
580 | * Specifies whether to use slave or DMA mode for accessing the data | ||
581 | * FIFOs. The driver will automatically detect the value for this | ||
582 | * parameter if none is specified. | ||
583 | * 0 - Slave | ||
584 | * 1 - DMA (default, if available) | ||
585 | */ | ||
586 | extern void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val); | ||
587 | |||
588 | /* | ||
589 | * When DMA mode is enabled specifies whether to use | ||
590 | * address DMA or DMA Descritor mode for accessing the data | ||
591 | * FIFOs in device mode. The driver will automatically detect | ||
592 | * the value for this parameter if none is specified. | ||
593 | * 0 - address DMA | ||
594 | * 1 - DMA Descriptor(default, if available) | ||
595 | */ | ||
596 | extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val); | ||
597 | |||
598 | /* | ||
599 | * Specifies the maximum speed of operation in host and device mode. | ||
600 | * The actual speed depends on the speed of the attached device and | ||
601 | * the value of phy_type. The actual speed depends on the speed of the | ||
602 | * attached device. | ||
603 | * 0 - High Speed (default) | ||
604 | * 1 - Full Speed | ||
605 | */ | ||
606 | extern void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val); | ||
607 | #define DWC2_SPEED_PARAM_HIGH 0 | ||
608 | #define DWC2_SPEED_PARAM_FULL 1 | ||
609 | |||
610 | /* | ||
611 | * Specifies whether low power mode is supported when attached | ||
612 | * to a Full Speed or Low Speed device in host mode. | ||
613 | * | ||
614 | * 0 - Don't support low power mode (default) | ||
615 | * 1 - Support low power mode | ||
616 | */ | ||
617 | extern void dwc2_set_param_host_support_fs_ls_low_power( | ||
618 | struct dwc2_hsotg *hsotg, int val); | ||
619 | |||
620 | /* | ||
621 | * Specifies the PHY clock rate in low power mode when connected to a | ||
622 | * Low Speed device in host mode. This parameter is applicable only if | ||
623 | * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS | ||
624 | * then defaults to 6 MHZ otherwise 48 MHZ. | ||
625 | * | ||
626 | * 0 - 48 MHz | ||
627 | * 1 - 6 MHz | ||
628 | */ | ||
629 | extern void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg, | ||
630 | int val); | ||
631 | #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0 | ||
632 | #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1 | ||
633 | |||
634 | /* | ||
635 | * 0 - Use cC FIFO size parameters | ||
636 | * 1 - Allow dynamic FIFO sizing (default) | ||
637 | */ | ||
638 | extern void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg, | ||
639 | int val); | ||
640 | |||
641 | /* | ||
642 | * Number of 4-byte words in the Rx FIFO in host mode when dynamic | ||
643 | * FIFO sizing is enabled. | ||
644 | * 16 to 32768 (default 1024) | ||
645 | */ | ||
646 | extern void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val); | ||
647 | |||
648 | /* | ||
649 | * Number of 4-byte words in the non-periodic Tx FIFO in host mode | ||
650 | * when Dynamic FIFO sizing is enabled in the core. | ||
651 | * 16 to 32768 (default 256) | ||
652 | */ | ||
653 | extern void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg, | ||
654 | int val); | ||
655 | |||
656 | /* | ||
657 | * Number of 4-byte words in the host periodic Tx FIFO when dynamic | ||
658 | * FIFO sizing is enabled. | ||
659 | * 16 to 32768 (default 256) | ||
660 | */ | ||
661 | extern void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg, | ||
662 | int val); | ||
663 | |||
664 | /* | ||
665 | * The maximum transfer size supported in bytes. | ||
666 | * 2047 to 65,535 (default 65,535) | ||
667 | */ | ||
668 | extern void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val); | ||
669 | |||
670 | /* | ||
671 | * The maximum number of packets in a transfer. | ||
672 | * 15 to 511 (default 511) | ||
673 | */ | ||
674 | extern void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val); | ||
675 | |||
676 | /* | ||
677 | * The number of host channel registers to use. | ||
678 | * 1 to 16 (default 11) | ||
679 | * Note: The FPGA configuration supports a maximum of 11 host channels. | ||
680 | */ | ||
681 | extern void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val); | ||
682 | |||
683 | /* | ||
684 | * Specifies the type of PHY interface to use. By default, the driver | ||
685 | * will automatically detect the phy_type. | ||
686 | * | ||
687 | * 0 - Full Speed PHY | ||
688 | * 1 - UTMI+ (default) | ||
689 | * 2 - ULPI | ||
690 | */ | ||
691 | extern void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val); | ||
692 | #define DWC2_PHY_TYPE_PARAM_FS 0 | ||
693 | #define DWC2_PHY_TYPE_PARAM_UTMI 1 | ||
694 | #define DWC2_PHY_TYPE_PARAM_ULPI 2 | ||
695 | |||
696 | /* | ||
697 | * Specifies the UTMI+ Data Width. This parameter is | ||
698 | * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI | ||
699 | * PHY_TYPE, this parameter indicates the data width between | ||
700 | * the MAC and the ULPI Wrapper.) Also, this parameter is | ||
701 | * applicable only if the OTG_HSPHY_WIDTH cC parameter was set | ||
702 | * to "8 and 16 bits", meaning that the core has been | ||
703 | * configured to work at either data path width. | ||
704 | * | ||
705 | * 8 or 16 bits (default 16) | ||
706 | */ | ||
707 | extern void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val); | ||
708 | |||
709 | /* | ||
710 | * Specifies whether the ULPI operates at double or single | ||
711 | * data rate. This parameter is only applicable if PHY_TYPE is | ||
712 | * ULPI. | ||
713 | * | ||
714 | * 0 - single data rate ULPI interface with 8 bit wide data | ||
715 | * bus (default) | ||
716 | * 1 - double data rate ULPI interface with 4 bit wide data | ||
717 | * bus | ||
718 | */ | ||
719 | extern void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val); | ||
720 | |||
721 | /* | ||
722 | * Specifies whether to use the internal or external supply to | ||
723 | * drive the vbus with a ULPI phy. | ||
724 | */ | ||
725 | extern void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val); | ||
726 | #define DWC2_PHY_ULPI_INTERNAL_VBUS 0 | ||
727 | #define DWC2_PHY_ULPI_EXTERNAL_VBUS 1 | ||
728 | |||
729 | /* | ||
730 | * Specifies whether to use the I2Cinterface for full speed PHY. This | ||
731 | * parameter is only applicable if PHY_TYPE is FS. | ||
732 | * 0 - No (default) | ||
733 | * 1 - Yes | ||
734 | */ | ||
735 | extern void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val); | ||
736 | |||
737 | extern void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val); | ||
738 | |||
739 | extern void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val); | ||
740 | |||
741 | /* | ||
742 | * Specifies whether dedicated transmit FIFOs are | ||
743 | * enabled for non periodic IN endpoints in device mode | ||
744 | * 0 - No | ||
745 | * 1 - Yes | ||
746 | */ | ||
747 | extern void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg, | ||
748 | int val); | ||
749 | |||
750 | extern void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val); | ||
751 | |||
752 | extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val); | ||
753 | |||
754 | extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val); | ||
755 | |||
756 | /* | ||
757 | * Dump core registers and SPRAM | ||
758 | */ | ||
759 | extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg); | ||
760 | extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg); | ||
761 | extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg); | ||
762 | |||
763 | /* | ||
764 | * Return OTG version - either 1.3 or 2.0 | ||
765 | */ | ||
766 | extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg); | ||
767 | |||
768 | #endif /* __DWC2_CORE_H__ */ | ||
diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c new file mode 100644 index 000000000000..8205799e6db3 --- /dev/null +++ b/drivers/usb/dwc2/core_intr.c | |||
@@ -0,0 +1,492 @@ | |||
1 | /* | ||
2 | * core_intr.c - DesignWare HS OTG Controller common interrupt handling | ||
3 | * | ||
4 | * Copyright (C) 2004-2013 Synopsys, Inc. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions, and the following disclaimer, | ||
11 | * without modification. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The names of the above-listed copyright holders may not be used | ||
16 | * to endorse or promote products derived from this software without | ||
17 | * specific prior written permission. | ||
18 | * | ||
19 | * ALTERNATIVELY, this software may be distributed under the terms of the | ||
20 | * GNU General Public License ("GPL") as published by the Free Software | ||
21 | * Foundation; either version 2 of the License, or (at your option) any | ||
22 | * later version. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
26 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
35 | */ | ||
36 | |||
37 | /* | ||
38 | * This file contains the common interrupt handlers | ||
39 | */ | ||
40 | #include <linux/kernel.h> | ||
41 | #include <linux/module.h> | ||
42 | #include <linux/moduleparam.h> | ||
43 | #include <linux/spinlock.h> | ||
44 | #include <linux/interrupt.h> | ||
45 | #include <linux/dma-mapping.h> | ||
46 | #include <linux/io.h> | ||
47 | #include <linux/slab.h> | ||
48 | #include <linux/usb.h> | ||
49 | |||
50 | #include <linux/usb/hcd.h> | ||
51 | #include <linux/usb/ch11.h> | ||
52 | |||
53 | #include "core.h" | ||
54 | #include "hcd.h" | ||
55 | |||
56 | static const char *dwc2_op_state_str(struct dwc2_hsotg *hsotg) | ||
57 | { | ||
58 | switch (hsotg->op_state) { | ||
59 | case OTG_STATE_A_HOST: | ||
60 | return "a_host"; | ||
61 | case OTG_STATE_A_SUSPEND: | ||
62 | return "a_suspend"; | ||
63 | case OTG_STATE_A_PERIPHERAL: | ||
64 | return "a_peripheral"; | ||
65 | case OTG_STATE_B_PERIPHERAL: | ||
66 | return "b_peripheral"; | ||
67 | case OTG_STATE_B_HOST: | ||
68 | return "b_host"; | ||
69 | default: | ||
70 | return "unknown"; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * dwc2_handle_mode_mismatch_intr() - Logs a mode mismatch warning message | ||
76 | * | ||
77 | * @hsotg: Programming view of DWC_otg controller | ||
78 | */ | ||
79 | static void dwc2_handle_mode_mismatch_intr(struct dwc2_hsotg *hsotg) | ||
80 | { | ||
81 | dev_warn(hsotg->dev, "Mode Mismatch Interrupt: currently in %s mode\n", | ||
82 | dwc2_is_host_mode(hsotg) ? "Host" : "Device"); | ||
83 | |||
84 | /* Clear interrupt */ | ||
85 | writel(GINTSTS_MODEMIS, hsotg->regs + GINTSTS); | ||
86 | } | ||
87 | |||
88 | /** | ||
89 | * dwc2_handle_otg_intr() - Handles the OTG Interrupts. It reads the OTG | ||
90 | * Interrupt Register (GOTGINT) to determine what interrupt has occurred. | ||
91 | * | ||
92 | * @hsotg: Programming view of DWC_otg controller | ||
93 | */ | ||
94 | static void dwc2_handle_otg_intr(struct dwc2_hsotg *hsotg) | ||
95 | { | ||
96 | u32 gotgint; | ||
97 | u32 gotgctl; | ||
98 | u32 gintmsk; | ||
99 | |||
100 | gotgint = readl(hsotg->regs + GOTGINT); | ||
101 | gotgctl = readl(hsotg->regs + GOTGCTL); | ||
102 | dev_dbg(hsotg->dev, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint, | ||
103 | dwc2_op_state_str(hsotg)); | ||
104 | |||
105 | if (gotgint & GOTGINT_SES_END_DET) { | ||
106 | dev_dbg(hsotg->dev, | ||
107 | " ++OTG Interrupt: Session End Detected++ (%s)\n", | ||
108 | dwc2_op_state_str(hsotg)); | ||
109 | gotgctl = readl(hsotg->regs + GOTGCTL); | ||
110 | |||
111 | if (hsotg->op_state == OTG_STATE_B_HOST) { | ||
112 | hsotg->op_state = OTG_STATE_B_PERIPHERAL; | ||
113 | } else { | ||
114 | /* | ||
115 | * If not B_HOST and Device HNP still set, HNP did | ||
116 | * not succeed! | ||
117 | */ | ||
118 | if (gotgctl & GOTGCTL_DEVHNPEN) { | ||
119 | dev_dbg(hsotg->dev, "Session End Detected\n"); | ||
120 | dev_err(hsotg->dev, | ||
121 | "Device Not Connected/Responding!\n"); | ||
122 | } | ||
123 | |||
124 | /* | ||
125 | * If Session End Detected the B-Cable has been | ||
126 | * disconnected | ||
127 | */ | ||
128 | /* Reset to a clean state */ | ||
129 | hsotg->lx_state = DWC2_L0; | ||
130 | } | ||
131 | |||
132 | gotgctl = readl(hsotg->regs + GOTGCTL); | ||
133 | gotgctl &= ~GOTGCTL_DEVHNPEN; | ||
134 | writel(gotgctl, hsotg->regs + GOTGCTL); | ||
135 | } | ||
136 | |||
137 | if (gotgint & GOTGINT_SES_REQ_SUC_STS_CHNG) { | ||
138 | dev_dbg(hsotg->dev, | ||
139 | " ++OTG Interrupt: Session Request Success Status Change++\n"); | ||
140 | gotgctl = readl(hsotg->regs + GOTGCTL); | ||
141 | if (gotgctl & GOTGCTL_SESREQSCS) { | ||
142 | if (hsotg->core_params->phy_type == | ||
143 | DWC2_PHY_TYPE_PARAM_FS | ||
144 | && hsotg->core_params->i2c_enable > 0) { | ||
145 | hsotg->srp_success = 1; | ||
146 | } else { | ||
147 | /* Clear Session Request */ | ||
148 | gotgctl = readl(hsotg->regs + GOTGCTL); | ||
149 | gotgctl &= ~GOTGCTL_SESREQ; | ||
150 | writel(gotgctl, hsotg->regs + GOTGCTL); | ||
151 | } | ||
152 | } | ||
153 | } | ||
154 | |||
155 | if (gotgint & GOTGINT_HST_NEG_SUC_STS_CHNG) { | ||
156 | /* | ||
157 | * Print statements during the HNP interrupt handling | ||
158 | * can cause it to fail | ||
159 | */ | ||
160 | gotgctl = readl(hsotg->regs + GOTGCTL); | ||
161 | /* | ||
162 | * WA for 3.00a- HW is not setting cur_mode, even sometimes | ||
163 | * this does not help | ||
164 | */ | ||
165 | if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a) | ||
166 | udelay(100); | ||
167 | if (gotgctl & GOTGCTL_HSTNEGSCS) { | ||
168 | if (dwc2_is_host_mode(hsotg)) { | ||
169 | hsotg->op_state = OTG_STATE_B_HOST; | ||
170 | /* | ||
171 | * Need to disable SOF interrupt immediately. | ||
172 | * When switching from device to host, the PCD | ||
173 | * interrupt handler won't handle the interrupt | ||
174 | * if host mode is already set. The HCD | ||
175 | * interrupt handler won't get called if the | ||
176 | * HCD state is HALT. This means that the | ||
177 | * interrupt does not get handled and Linux | ||
178 | * complains loudly. | ||
179 | */ | ||
180 | gintmsk = readl(hsotg->regs + GINTMSK); | ||
181 | gintmsk &= ~GINTSTS_SOF; | ||
182 | writel(gintmsk, hsotg->regs + GINTMSK); | ||
183 | |||
184 | /* | ||
185 | * Call callback function with spin lock | ||
186 | * released | ||
187 | */ | ||
188 | spin_unlock(&hsotg->lock); | ||
189 | |||
190 | /* Initialize the Core for Host mode */ | ||
191 | dwc2_hcd_start(hsotg); | ||
192 | spin_lock(&hsotg->lock); | ||
193 | hsotg->op_state = OTG_STATE_B_HOST; | ||
194 | } | ||
195 | } else { | ||
196 | gotgctl = readl(hsotg->regs + GOTGCTL); | ||
197 | gotgctl &= ~(GOTGCTL_HNPREQ | GOTGCTL_DEVHNPEN); | ||
198 | writel(gotgctl, hsotg->regs + GOTGCTL); | ||
199 | dev_dbg(hsotg->dev, "HNP Failed\n"); | ||
200 | dev_err(hsotg->dev, | ||
201 | "Device Not Connected/Responding\n"); | ||
202 | } | ||
203 | } | ||
204 | |||
205 | if (gotgint & GOTGINT_HST_NEG_DET) { | ||
206 | /* | ||
207 | * The disconnect interrupt is set at the same time as | ||
208 | * Host Negotiation Detected. During the mode switch all | ||
209 | * interrupts are cleared so the disconnect interrupt | ||
210 | * handler will not get executed. | ||
211 | */ | ||
212 | dev_dbg(hsotg->dev, | ||
213 | " ++OTG Interrupt: Host Negotiation Detected++ (%s)\n", | ||
214 | (dwc2_is_host_mode(hsotg) ? "Host" : "Device")); | ||
215 | if (dwc2_is_device_mode(hsotg)) { | ||
216 | dev_dbg(hsotg->dev, "a_suspend->a_peripheral (%d)\n", | ||
217 | hsotg->op_state); | ||
218 | spin_unlock(&hsotg->lock); | ||
219 | dwc2_hcd_disconnect(hsotg); | ||
220 | spin_lock(&hsotg->lock); | ||
221 | hsotg->op_state = OTG_STATE_A_PERIPHERAL; | ||
222 | } else { | ||
223 | /* Need to disable SOF interrupt immediately */ | ||
224 | gintmsk = readl(hsotg->regs + GINTMSK); | ||
225 | gintmsk &= ~GINTSTS_SOF; | ||
226 | writel(gintmsk, hsotg->regs + GINTMSK); | ||
227 | spin_unlock(&hsotg->lock); | ||
228 | dwc2_hcd_start(hsotg); | ||
229 | spin_lock(&hsotg->lock); | ||
230 | hsotg->op_state = OTG_STATE_A_HOST; | ||
231 | } | ||
232 | } | ||
233 | |||
234 | if (gotgint & GOTGINT_A_DEV_TOUT_CHG) | ||
235 | dev_dbg(hsotg->dev, | ||
236 | " ++OTG Interrupt: A-Device Timeout Change++\n"); | ||
237 | if (gotgint & GOTGINT_DBNCE_DONE) | ||
238 | dev_dbg(hsotg->dev, " ++OTG Interrupt: Debounce Done++\n"); | ||
239 | |||
240 | /* Clear GOTGINT */ | ||
241 | writel(gotgint, hsotg->regs + GOTGINT); | ||
242 | } | ||
243 | |||
244 | /** | ||
245 | * dwc2_handle_conn_id_status_change_intr() - Handles the Connector ID Status | ||
246 | * Change Interrupt | ||
247 | * | ||
248 | * @hsotg: Programming view of DWC_otg controller | ||
249 | * | ||
250 | * Reads the OTG Interrupt Register (GOTCTL) to determine whether this is a | ||
251 | * Device to Host Mode transition or a Host to Device Mode transition. This only | ||
252 | * occurs when the cable is connected/removed from the PHY connector. | ||
253 | */ | ||
254 | static void dwc2_handle_conn_id_status_change_intr(struct dwc2_hsotg *hsotg) | ||
255 | { | ||
256 | u32 gintmsk = readl(hsotg->regs + GINTMSK); | ||
257 | |||
258 | /* Need to disable SOF interrupt immediately */ | ||
259 | gintmsk &= ~GINTSTS_SOF; | ||
260 | writel(gintmsk, hsotg->regs + GINTMSK); | ||
261 | |||
262 | dev_dbg(hsotg->dev, " ++Connector ID Status Change Interrupt++ (%s)\n", | ||
263 | dwc2_is_host_mode(hsotg) ? "Host" : "Device"); | ||
264 | |||
265 | /* | ||
266 | * Need to schedule a work, as there are possible DELAY function calls. | ||
267 | * Release lock before scheduling workq as it holds spinlock during | ||
268 | * scheduling. | ||
269 | */ | ||
270 | spin_unlock(&hsotg->lock); | ||
271 | queue_work(hsotg->wq_otg, &hsotg->wf_otg); | ||
272 | spin_lock(&hsotg->lock); | ||
273 | |||
274 | /* Clear interrupt */ | ||
275 | writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS); | ||
276 | } | ||
277 | |||
278 | /** | ||
279 | * dwc2_handle_session_req_intr() - This interrupt indicates that a device is | ||
280 | * initiating the Session Request Protocol to request the host to turn on bus | ||
281 | * power so a new session can begin | ||
282 | * | ||
283 | * @hsotg: Programming view of DWC_otg controller | ||
284 | * | ||
285 | * This handler responds by turning on bus power. If the DWC_otg controller is | ||
286 | * in low power mode, this handler brings the controller out of low power mode | ||
287 | * before turning on bus power. | ||
288 | */ | ||
289 | static void dwc2_handle_session_req_intr(struct dwc2_hsotg *hsotg) | ||
290 | { | ||
291 | dev_dbg(hsotg->dev, "++Session Request Interrupt++\n"); | ||
292 | |||
293 | /* Clear interrupt */ | ||
294 | writel(GINTSTS_SESSREQINT, hsotg->regs + GINTSTS); | ||
295 | } | ||
296 | |||
297 | /* | ||
298 | * This interrupt indicates that the DWC_otg controller has detected a | ||
299 | * resume or remote wakeup sequence. If the DWC_otg controller is in | ||
300 | * low power mode, the handler must brings the controller out of low | ||
301 | * power mode. The controller automatically begins resume signaling. | ||
302 | * The handler schedules a time to stop resume signaling. | ||
303 | */ | ||
304 | static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg) | ||
305 | { | ||
306 | dev_dbg(hsotg->dev, "++Resume or Remote Wakeup Detected Interrupt++\n"); | ||
307 | dev_dbg(hsotg->dev, "%s lxstate = %d\n", __func__, hsotg->lx_state); | ||
308 | |||
309 | if (dwc2_is_device_mode(hsotg)) { | ||
310 | dev_dbg(hsotg->dev, "DSTS=0x%0x\n", readl(hsotg->regs + DSTS)); | ||
311 | if (hsotg->lx_state == DWC2_L2) { | ||
312 | u32 dctl = readl(hsotg->regs + DCTL); | ||
313 | |||
314 | /* Clear Remote Wakeup Signaling */ | ||
315 | dctl &= ~DCTL_RMTWKUPSIG; | ||
316 | writel(dctl, hsotg->regs + DCTL); | ||
317 | } | ||
318 | /* Change to L0 state */ | ||
319 | hsotg->lx_state = DWC2_L0; | ||
320 | } else { | ||
321 | if (hsotg->lx_state != DWC2_L1) { | ||
322 | u32 pcgcctl = readl(hsotg->regs + PCGCTL); | ||
323 | |||
324 | /* Restart the Phy Clock */ | ||
325 | pcgcctl &= ~PCGCTL_STOPPCLK; | ||
326 | writel(pcgcctl, hsotg->regs + PCGCTL); | ||
327 | mod_timer(&hsotg->wkp_timer, | ||
328 | jiffies + msecs_to_jiffies(71)); | ||
329 | } else { | ||
330 | /* Change to L0 state */ | ||
331 | hsotg->lx_state = DWC2_L0; | ||
332 | } | ||
333 | } | ||
334 | |||
335 | /* Clear interrupt */ | ||
336 | writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS); | ||
337 | } | ||
338 | |||
339 | /* | ||
340 | * This interrupt indicates that a device has been disconnected from the | ||
341 | * root port | ||
342 | */ | ||
343 | static void dwc2_handle_disconnect_intr(struct dwc2_hsotg *hsotg) | ||
344 | { | ||
345 | dev_dbg(hsotg->dev, "++Disconnect Detected Interrupt++ (%s) %s\n", | ||
346 | dwc2_is_host_mode(hsotg) ? "Host" : "Device", | ||
347 | dwc2_op_state_str(hsotg)); | ||
348 | |||
349 | /* Change to L3 (OFF) state */ | ||
350 | hsotg->lx_state = DWC2_L3; | ||
351 | |||
352 | writel(GINTSTS_DISCONNINT, hsotg->regs + GINTSTS); | ||
353 | } | ||
354 | |||
355 | /* | ||
356 | * This interrupt indicates that SUSPEND state has been detected on the USB. | ||
357 | * | ||
358 | * For HNP the USB Suspend interrupt signals the change from "a_peripheral" | ||
359 | * to "a_host". | ||
360 | * | ||
361 | * When power management is enabled the core will be put in low power mode. | ||
362 | */ | ||
363 | static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg) | ||
364 | { | ||
365 | u32 dsts; | ||
366 | |||
367 | dev_dbg(hsotg->dev, "USB SUSPEND\n"); | ||
368 | |||
369 | if (dwc2_is_device_mode(hsotg)) { | ||
370 | /* | ||
371 | * Check the Device status register to determine if the Suspend | ||
372 | * state is active | ||
373 | */ | ||
374 | dsts = readl(hsotg->regs + DSTS); | ||
375 | dev_dbg(hsotg->dev, "DSTS=0x%0x\n", dsts); | ||
376 | dev_dbg(hsotg->dev, | ||
377 | "DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d\n", | ||
378 | !!(dsts & DSTS_SUSPSTS), | ||
379 | hsotg->hw_params.power_optimized); | ||
380 | } else { | ||
381 | if (hsotg->op_state == OTG_STATE_A_PERIPHERAL) { | ||
382 | dev_dbg(hsotg->dev, "a_peripheral->a_host\n"); | ||
383 | |||
384 | /* Clear the a_peripheral flag, back to a_host */ | ||
385 | spin_unlock(&hsotg->lock); | ||
386 | dwc2_hcd_start(hsotg); | ||
387 | spin_lock(&hsotg->lock); | ||
388 | hsotg->op_state = OTG_STATE_A_HOST; | ||
389 | } | ||
390 | } | ||
391 | |||
392 | /* Change to L2 (suspend) state */ | ||
393 | hsotg->lx_state = DWC2_L2; | ||
394 | |||
395 | /* Clear interrupt */ | ||
396 | writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS); | ||
397 | } | ||
398 | |||
399 | #define GINTMSK_COMMON (GINTSTS_WKUPINT | GINTSTS_SESSREQINT | \ | ||
400 | GINTSTS_CONIDSTSCHNG | GINTSTS_OTGINT | \ | ||
401 | GINTSTS_MODEMIS | GINTSTS_DISCONNINT | \ | ||
402 | GINTSTS_USBSUSP | GINTSTS_PRTINT) | ||
403 | |||
404 | /* | ||
405 | * This function returns the Core Interrupt register | ||
406 | */ | ||
407 | static u32 dwc2_read_common_intr(struct dwc2_hsotg *hsotg) | ||
408 | { | ||
409 | u32 gintsts; | ||
410 | u32 gintmsk; | ||
411 | u32 gahbcfg; | ||
412 | u32 gintmsk_common = GINTMSK_COMMON; | ||
413 | |||
414 | gintsts = readl(hsotg->regs + GINTSTS); | ||
415 | gintmsk = readl(hsotg->regs + GINTMSK); | ||
416 | gahbcfg = readl(hsotg->regs + GAHBCFG); | ||
417 | |||
418 | /* If any common interrupts set */ | ||
419 | if (gintsts & gintmsk_common) | ||
420 | dev_dbg(hsotg->dev, "gintsts=%08x gintmsk=%08x\n", | ||
421 | gintsts, gintmsk); | ||
422 | |||
423 | if (gahbcfg & GAHBCFG_GLBL_INTR_EN) | ||
424 | return gintsts & gintmsk & gintmsk_common; | ||
425 | else | ||
426 | return 0; | ||
427 | } | ||
428 | |||
429 | /* | ||
430 | * Common interrupt handler | ||
431 | * | ||
432 | * The common interrupts are those that occur in both Host and Device mode. | ||
433 | * This handler handles the following interrupts: | ||
434 | * - Mode Mismatch Interrupt | ||
435 | * - OTG Interrupt | ||
436 | * - Connector ID Status Change Interrupt | ||
437 | * - Disconnect Interrupt | ||
438 | * - Session Request Interrupt | ||
439 | * - Resume / Remote Wakeup Detected Interrupt | ||
440 | * - Suspend Interrupt | ||
441 | */ | ||
442 | irqreturn_t dwc2_handle_common_intr(int irq, void *dev) | ||
443 | { | ||
444 | struct dwc2_hsotg *hsotg = dev; | ||
445 | u32 gintsts; | ||
446 | irqreturn_t retval = IRQ_NONE; | ||
447 | |||
448 | if (!dwc2_is_controller_alive(hsotg)) { | ||
449 | dev_warn(hsotg->dev, "Controller is dead\n"); | ||
450 | goto out; | ||
451 | } | ||
452 | |||
453 | spin_lock(&hsotg->lock); | ||
454 | |||
455 | gintsts = dwc2_read_common_intr(hsotg); | ||
456 | if (gintsts & ~GINTSTS_PRTINT) | ||
457 | retval = IRQ_HANDLED; | ||
458 | |||
459 | if (gintsts & GINTSTS_MODEMIS) | ||
460 | dwc2_handle_mode_mismatch_intr(hsotg); | ||
461 | if (gintsts & GINTSTS_OTGINT) | ||
462 | dwc2_handle_otg_intr(hsotg); | ||
463 | if (gintsts & GINTSTS_CONIDSTSCHNG) | ||
464 | dwc2_handle_conn_id_status_change_intr(hsotg); | ||
465 | if (gintsts & GINTSTS_DISCONNINT) | ||
466 | dwc2_handle_disconnect_intr(hsotg); | ||
467 | if (gintsts & GINTSTS_SESSREQINT) | ||
468 | dwc2_handle_session_req_intr(hsotg); | ||
469 | if (gintsts & GINTSTS_WKUPINT) | ||
470 | dwc2_handle_wakeup_detected_intr(hsotg); | ||
471 | if (gintsts & GINTSTS_USBSUSP) | ||
472 | dwc2_handle_usb_suspend_intr(hsotg); | ||
473 | |||
474 | if (gintsts & GINTSTS_PRTINT) { | ||
475 | /* | ||
476 | * The port interrupt occurs while in device mode with HPRT0 | ||
477 | * Port Enable/Disable | ||
478 | */ | ||
479 | if (dwc2_is_device_mode(hsotg)) { | ||
480 | dev_dbg(hsotg->dev, | ||
481 | " --Port interrupt received in Device mode--\n"); | ||
482 | gintsts = GINTSTS_PRTINT; | ||
483 | writel(gintsts, hsotg->regs + GINTSTS); | ||
484 | retval = 1; | ||
485 | } | ||
486 | } | ||
487 | |||
488 | spin_unlock(&hsotg->lock); | ||
489 | out: | ||
490 | return retval; | ||
491 | } | ||
492 | EXPORT_SYMBOL_GPL(dwc2_handle_common_intr); | ||
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c new file mode 100644 index 000000000000..f59484d43b35 --- /dev/null +++ b/drivers/usb/dwc2/hcd.c | |||
@@ -0,0 +1,2992 @@ | |||
1 | /* | ||
2 | * hcd.c - DesignWare HS OTG Controller host-mode routines | ||
3 | * | ||
4 | * Copyright (C) 2004-2013 Synopsys, Inc. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions, and the following disclaimer, | ||
11 | * without modification. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The names of the above-listed copyright holders may not be used | ||
16 | * to endorse or promote products derived from this software without | ||
17 | * specific prior written permission. | ||
18 | * | ||
19 | * ALTERNATIVELY, this software may be distributed under the terms of the | ||
20 | * GNU General Public License ("GPL") as published by the Free Software | ||
21 | * Foundation; either version 2 of the License, or (at your option) any | ||
22 | * later version. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
26 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
35 | */ | ||
36 | |||
37 | /* | ||
38 | * This file contains the core HCD code, and implements the Linux hc_driver | ||
39 | * API | ||
40 | */ | ||
41 | #include <linux/kernel.h> | ||
42 | #include <linux/module.h> | ||
43 | #include <linux/spinlock.h> | ||
44 | #include <linux/interrupt.h> | ||
45 | #include <linux/dma-mapping.h> | ||
46 | #include <linux/delay.h> | ||
47 | #include <linux/io.h> | ||
48 | #include <linux/slab.h> | ||
49 | #include <linux/usb.h> | ||
50 | |||
51 | #include <linux/usb/hcd.h> | ||
52 | #include <linux/usb/ch11.h> | ||
53 | |||
54 | #include "core.h" | ||
55 | #include "hcd.h" | ||
56 | |||
57 | /** | ||
58 | * dwc2_dump_channel_info() - Prints the state of a host channel | ||
59 | * | ||
60 | * @hsotg: Programming view of DWC_otg controller | ||
61 | * @chan: Pointer to the channel to dump | ||
62 | * | ||
63 | * Must be called with interrupt disabled and spinlock held | ||
64 | * | ||
65 | * NOTE: This function will be removed once the peripheral controller code | ||
66 | * is integrated and the driver is stable | ||
67 | */ | ||
68 | static void dwc2_dump_channel_info(struct dwc2_hsotg *hsotg, | ||
69 | struct dwc2_host_chan *chan) | ||
70 | { | ||
71 | #ifdef VERBOSE_DEBUG | ||
72 | int num_channels = hsotg->core_params->host_channels; | ||
73 | struct dwc2_qh *qh; | ||
74 | u32 hcchar; | ||
75 | u32 hcsplt; | ||
76 | u32 hctsiz; | ||
77 | u32 hc_dma; | ||
78 | int i; | ||
79 | |||
80 | if (chan == NULL) | ||
81 | return; | ||
82 | |||
83 | hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); | ||
84 | hcsplt = readl(hsotg->regs + HCSPLT(chan->hc_num)); | ||
85 | hctsiz = readl(hsotg->regs + HCTSIZ(chan->hc_num)); | ||
86 | hc_dma = readl(hsotg->regs + HCDMA(chan->hc_num)); | ||
87 | |||
88 | dev_dbg(hsotg->dev, " Assigned to channel %p:\n", chan); | ||
89 | dev_dbg(hsotg->dev, " hcchar 0x%08x, hcsplt 0x%08x\n", | ||
90 | hcchar, hcsplt); | ||
91 | dev_dbg(hsotg->dev, " hctsiz 0x%08x, hc_dma 0x%08x\n", | ||
92 | hctsiz, hc_dma); | ||
93 | dev_dbg(hsotg->dev, " dev_addr: %d, ep_num: %d, ep_is_in: %d\n", | ||
94 | chan->dev_addr, chan->ep_num, chan->ep_is_in); | ||
95 | dev_dbg(hsotg->dev, " ep_type: %d\n", chan->ep_type); | ||
96 | dev_dbg(hsotg->dev, " max_packet: %d\n", chan->max_packet); | ||
97 | dev_dbg(hsotg->dev, " data_pid_start: %d\n", chan->data_pid_start); | ||
98 | dev_dbg(hsotg->dev, " xfer_started: %d\n", chan->xfer_started); | ||
99 | dev_dbg(hsotg->dev, " halt_status: %d\n", chan->halt_status); | ||
100 | dev_dbg(hsotg->dev, " xfer_buf: %p\n", chan->xfer_buf); | ||
101 | dev_dbg(hsotg->dev, " xfer_dma: %08lx\n", | ||
102 | (unsigned long)chan->xfer_dma); | ||
103 | dev_dbg(hsotg->dev, " xfer_len: %d\n", chan->xfer_len); | ||
104 | dev_dbg(hsotg->dev, " qh: %p\n", chan->qh); | ||
105 | dev_dbg(hsotg->dev, " NP inactive sched:\n"); | ||
106 | list_for_each_entry(qh, &hsotg->non_periodic_sched_inactive, | ||
107 | qh_list_entry) | ||
108 | dev_dbg(hsotg->dev, " %p\n", qh); | ||
109 | dev_dbg(hsotg->dev, " NP active sched:\n"); | ||
110 | list_for_each_entry(qh, &hsotg->non_periodic_sched_active, | ||
111 | qh_list_entry) | ||
112 | dev_dbg(hsotg->dev, " %p\n", qh); | ||
113 | dev_dbg(hsotg->dev, " Channels:\n"); | ||
114 | for (i = 0; i < num_channels; i++) { | ||
115 | struct dwc2_host_chan *chan = hsotg->hc_ptr_array[i]; | ||
116 | |||
117 | dev_dbg(hsotg->dev, " %2d: %p\n", i, chan); | ||
118 | } | ||
119 | #endif /* VERBOSE_DEBUG */ | ||
120 | } | ||
121 | |||
122 | /* | ||
123 | * Processes all the URBs in a single list of QHs. Completes them with | ||
124 | * -ETIMEDOUT and frees the QTD. | ||
125 | * | ||
126 | * Must be called with interrupt disabled and spinlock held | ||
127 | */ | ||
128 | static void dwc2_kill_urbs_in_qh_list(struct dwc2_hsotg *hsotg, | ||
129 | struct list_head *qh_list) | ||
130 | { | ||
131 | struct dwc2_qh *qh, *qh_tmp; | ||
132 | struct dwc2_qtd *qtd, *qtd_tmp; | ||
133 | |||
134 | list_for_each_entry_safe(qh, qh_tmp, qh_list, qh_list_entry) { | ||
135 | list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, | ||
136 | qtd_list_entry) { | ||
137 | dwc2_host_complete(hsotg, qtd, -ETIMEDOUT); | ||
138 | dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); | ||
139 | } | ||
140 | } | ||
141 | } | ||
142 | |||
143 | static void dwc2_qh_list_free(struct dwc2_hsotg *hsotg, | ||
144 | struct list_head *qh_list) | ||
145 | { | ||
146 | struct dwc2_qtd *qtd, *qtd_tmp; | ||
147 | struct dwc2_qh *qh, *qh_tmp; | ||
148 | unsigned long flags; | ||
149 | |||
150 | if (!qh_list->next) | ||
151 | /* The list hasn't been initialized yet */ | ||
152 | return; | ||
153 | |||
154 | spin_lock_irqsave(&hsotg->lock, flags); | ||
155 | |||
156 | /* Ensure there are no QTDs or URBs left */ | ||
157 | dwc2_kill_urbs_in_qh_list(hsotg, qh_list); | ||
158 | |||
159 | list_for_each_entry_safe(qh, qh_tmp, qh_list, qh_list_entry) { | ||
160 | dwc2_hcd_qh_unlink(hsotg, qh); | ||
161 | |||
162 | /* Free each QTD in the QH's QTD list */ | ||
163 | list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, | ||
164 | qtd_list_entry) | ||
165 | dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); | ||
166 | |||
167 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
168 | dwc2_hcd_qh_free(hsotg, qh); | ||
169 | spin_lock_irqsave(&hsotg->lock, flags); | ||
170 | } | ||
171 | |||
172 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
173 | } | ||
174 | |||
175 | /* | ||
176 | * Responds with an error status of -ETIMEDOUT to all URBs in the non-periodic | ||
177 | * and periodic schedules. The QTD associated with each URB is removed from | ||
178 | * the schedule and freed. This function may be called when a disconnect is | ||
179 | * detected or when the HCD is being stopped. | ||
180 | * | ||
181 | * Must be called with interrupt disabled and spinlock held | ||
182 | */ | ||
183 | static void dwc2_kill_all_urbs(struct dwc2_hsotg *hsotg) | ||
184 | { | ||
185 | dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_inactive); | ||
186 | dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_active); | ||
187 | dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_inactive); | ||
188 | dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_ready); | ||
189 | dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_assigned); | ||
190 | dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_queued); | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * dwc2_hcd_start() - Starts the HCD when switching to Host mode | ||
195 | * | ||
196 | * @hsotg: Pointer to struct dwc2_hsotg | ||
197 | */ | ||
198 | void dwc2_hcd_start(struct dwc2_hsotg *hsotg) | ||
199 | { | ||
200 | u32 hprt0; | ||
201 | |||
202 | if (hsotg->op_state == OTG_STATE_B_HOST) { | ||
203 | /* | ||
204 | * Reset the port. During a HNP mode switch the reset | ||
205 | * needs to occur within 1ms and have a duration of at | ||
206 | * least 50ms. | ||
207 | */ | ||
208 | hprt0 = dwc2_read_hprt0(hsotg); | ||
209 | hprt0 |= HPRT0_RST; | ||
210 | writel(hprt0, hsotg->regs + HPRT0); | ||
211 | } | ||
212 | |||
213 | queue_delayed_work(hsotg->wq_otg, &hsotg->start_work, | ||
214 | msecs_to_jiffies(50)); | ||
215 | } | ||
216 | |||
217 | /* Must be called with interrupt disabled and spinlock held */ | ||
218 | static void dwc2_hcd_cleanup_channels(struct dwc2_hsotg *hsotg) | ||
219 | { | ||
220 | int num_channels = hsotg->core_params->host_channels; | ||
221 | struct dwc2_host_chan *channel; | ||
222 | u32 hcchar; | ||
223 | int i; | ||
224 | |||
225 | if (hsotg->core_params->dma_enable <= 0) { | ||
226 | /* Flush out any channel requests in slave mode */ | ||
227 | for (i = 0; i < num_channels; i++) { | ||
228 | channel = hsotg->hc_ptr_array[i]; | ||
229 | if (!list_empty(&channel->hc_list_entry)) | ||
230 | continue; | ||
231 | hcchar = readl(hsotg->regs + HCCHAR(i)); | ||
232 | if (hcchar & HCCHAR_CHENA) { | ||
233 | hcchar &= ~(HCCHAR_CHENA | HCCHAR_EPDIR); | ||
234 | hcchar |= HCCHAR_CHDIS; | ||
235 | writel(hcchar, hsotg->regs + HCCHAR(i)); | ||
236 | } | ||
237 | } | ||
238 | } | ||
239 | |||
240 | for (i = 0; i < num_channels; i++) { | ||
241 | channel = hsotg->hc_ptr_array[i]; | ||
242 | if (!list_empty(&channel->hc_list_entry)) | ||
243 | continue; | ||
244 | hcchar = readl(hsotg->regs + HCCHAR(i)); | ||
245 | if (hcchar & HCCHAR_CHENA) { | ||
246 | /* Halt the channel */ | ||
247 | hcchar |= HCCHAR_CHDIS; | ||
248 | writel(hcchar, hsotg->regs + HCCHAR(i)); | ||
249 | } | ||
250 | |||
251 | dwc2_hc_cleanup(hsotg, channel); | ||
252 | list_add_tail(&channel->hc_list_entry, &hsotg->free_hc_list); | ||
253 | /* | ||
254 | * Added for Descriptor DMA to prevent channel double cleanup in | ||
255 | * release_channel_ddma(), which is called from ep_disable when | ||
256 | * device disconnects | ||
257 | */ | ||
258 | channel->qh = NULL; | ||
259 | } | ||
260 | } | ||
261 | |||
262 | /** | ||
263 | * dwc2_hcd_disconnect() - Handles disconnect of the HCD | ||
264 | * | ||
265 | * @hsotg: Pointer to struct dwc2_hsotg | ||
266 | * | ||
267 | * Must be called with interrupt disabled and spinlock held | ||
268 | */ | ||
269 | void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) | ||
270 | { | ||
271 | u32 intr; | ||
272 | |||
273 | /* Set status flags for the hub driver */ | ||
274 | hsotg->flags.b.port_connect_status_change = 1; | ||
275 | hsotg->flags.b.port_connect_status = 0; | ||
276 | |||
277 | /* | ||
278 | * Shutdown any transfers in process by clearing the Tx FIFO Empty | ||
279 | * interrupt mask and status bits and disabling subsequent host | ||
280 | * channel interrupts. | ||
281 | */ | ||
282 | intr = readl(hsotg->regs + GINTMSK); | ||
283 | intr &= ~(GINTSTS_NPTXFEMP | GINTSTS_PTXFEMP | GINTSTS_HCHINT); | ||
284 | writel(intr, hsotg->regs + GINTMSK); | ||
285 | intr = GINTSTS_NPTXFEMP | GINTSTS_PTXFEMP | GINTSTS_HCHINT; | ||
286 | writel(intr, hsotg->regs + GINTSTS); | ||
287 | |||
288 | /* | ||
289 | * Turn off the vbus power only if the core has transitioned to device | ||
290 | * mode. If still in host mode, need to keep power on to detect a | ||
291 | * reconnection. | ||
292 | */ | ||
293 | if (dwc2_is_device_mode(hsotg)) { | ||
294 | if (hsotg->op_state != OTG_STATE_A_SUSPEND) { | ||
295 | dev_dbg(hsotg->dev, "Disconnect: PortPower off\n"); | ||
296 | writel(0, hsotg->regs + HPRT0); | ||
297 | } | ||
298 | |||
299 | dwc2_disable_host_interrupts(hsotg); | ||
300 | } | ||
301 | |||
302 | /* Respond with an error status to all URBs in the schedule */ | ||
303 | dwc2_kill_all_urbs(hsotg); | ||
304 | |||
305 | if (dwc2_is_host_mode(hsotg)) | ||
306 | /* Clean up any host channels that were in use */ | ||
307 | dwc2_hcd_cleanup_channels(hsotg); | ||
308 | |||
309 | dwc2_host_disconnect(hsotg); | ||
310 | } | ||
311 | |||
312 | /** | ||
313 | * dwc2_hcd_rem_wakeup() - Handles Remote Wakeup | ||
314 | * | ||
315 | * @hsotg: Pointer to struct dwc2_hsotg | ||
316 | */ | ||
317 | static void dwc2_hcd_rem_wakeup(struct dwc2_hsotg *hsotg) | ||
318 | { | ||
319 | if (hsotg->lx_state == DWC2_L2) | ||
320 | hsotg->flags.b.port_suspend_change = 1; | ||
321 | else | ||
322 | hsotg->flags.b.port_l1_change = 1; | ||
323 | } | ||
324 | |||
325 | /** | ||
326 | * dwc2_hcd_stop() - Halts the DWC_otg host mode operations in a clean manner | ||
327 | * | ||
328 | * @hsotg: Pointer to struct dwc2_hsotg | ||
329 | * | ||
330 | * Must be called with interrupt disabled and spinlock held | ||
331 | */ | ||
332 | void dwc2_hcd_stop(struct dwc2_hsotg *hsotg) | ||
333 | { | ||
334 | dev_dbg(hsotg->dev, "DWC OTG HCD STOP\n"); | ||
335 | |||
336 | /* | ||
337 | * The root hub should be disconnected before this function is called. | ||
338 | * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue) | ||
339 | * and the QH lists (via ..._hcd_endpoint_disable). | ||
340 | */ | ||
341 | |||
342 | /* Turn off all host-specific interrupts */ | ||
343 | dwc2_disable_host_interrupts(hsotg); | ||
344 | |||
345 | /* Turn off the vbus power */ | ||
346 | dev_dbg(hsotg->dev, "PortPower off\n"); | ||
347 | writel(0, hsotg->regs + HPRT0); | ||
348 | } | ||
349 | |||
350 | static int dwc2_hcd_urb_enqueue(struct dwc2_hsotg *hsotg, | ||
351 | struct dwc2_hcd_urb *urb, void **ep_handle, | ||
352 | gfp_t mem_flags) | ||
353 | { | ||
354 | struct dwc2_qtd *qtd; | ||
355 | unsigned long flags; | ||
356 | u32 intr_mask; | ||
357 | int retval; | ||
358 | int dev_speed; | ||
359 | |||
360 | if (!hsotg->flags.b.port_connect_status) { | ||
361 | /* No longer connected */ | ||
362 | dev_err(hsotg->dev, "Not connected\n"); | ||
363 | return -ENODEV; | ||
364 | } | ||
365 | |||
366 | dev_speed = dwc2_host_get_speed(hsotg, urb->priv); | ||
367 | |||
368 | /* Some configurations cannot support LS traffic on a FS root port */ | ||
369 | if ((dev_speed == USB_SPEED_LOW) && | ||
370 | (hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) && | ||
371 | (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI)) { | ||
372 | u32 hprt0 = readl(hsotg->regs + HPRT0); | ||
373 | u32 prtspd = (hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT; | ||
374 | |||
375 | if (prtspd == HPRT0_SPD_FULL_SPEED) | ||
376 | return -ENODEV; | ||
377 | } | ||
378 | |||
379 | qtd = kzalloc(sizeof(*qtd), mem_flags); | ||
380 | if (!qtd) | ||
381 | return -ENOMEM; | ||
382 | |||
383 | dwc2_hcd_qtd_init(qtd, urb); | ||
384 | retval = dwc2_hcd_qtd_add(hsotg, qtd, (struct dwc2_qh **)ep_handle, | ||
385 | mem_flags); | ||
386 | if (retval) { | ||
387 | dev_err(hsotg->dev, | ||
388 | "DWC OTG HCD URB Enqueue failed adding QTD. Error status %d\n", | ||
389 | retval); | ||
390 | kfree(qtd); | ||
391 | return retval; | ||
392 | } | ||
393 | |||
394 | intr_mask = readl(hsotg->regs + GINTMSK); | ||
395 | if (!(intr_mask & GINTSTS_SOF)) { | ||
396 | enum dwc2_transaction_type tr_type; | ||
397 | |||
398 | if (qtd->qh->ep_type == USB_ENDPOINT_XFER_BULK && | ||
399 | !(qtd->urb->flags & URB_GIVEBACK_ASAP)) | ||
400 | /* | ||
401 | * Do not schedule SG transactions until qtd has | ||
402 | * URB_GIVEBACK_ASAP set | ||
403 | */ | ||
404 | return 0; | ||
405 | |||
406 | spin_lock_irqsave(&hsotg->lock, flags); | ||
407 | tr_type = dwc2_hcd_select_transactions(hsotg); | ||
408 | if (tr_type != DWC2_TRANSACTION_NONE) | ||
409 | dwc2_hcd_queue_transactions(hsotg, tr_type); | ||
410 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
411 | } | ||
412 | |||
413 | return 0; | ||
414 | } | ||
415 | |||
416 | /* Must be called with interrupt disabled and spinlock held */ | ||
417 | static int dwc2_hcd_urb_dequeue(struct dwc2_hsotg *hsotg, | ||
418 | struct dwc2_hcd_urb *urb) | ||
419 | { | ||
420 | struct dwc2_qh *qh; | ||
421 | struct dwc2_qtd *urb_qtd; | ||
422 | |||
423 | urb_qtd = urb->qtd; | ||
424 | if (!urb_qtd) { | ||
425 | dev_dbg(hsotg->dev, "## Urb QTD is NULL ##\n"); | ||
426 | return -EINVAL; | ||
427 | } | ||
428 | |||
429 | qh = urb_qtd->qh; | ||
430 | if (!qh) { | ||
431 | dev_dbg(hsotg->dev, "## Urb QTD QH is NULL ##\n"); | ||
432 | return -EINVAL; | ||
433 | } | ||
434 | |||
435 | urb->priv = NULL; | ||
436 | |||
437 | if (urb_qtd->in_process && qh->channel) { | ||
438 | dwc2_dump_channel_info(hsotg, qh->channel); | ||
439 | |||
440 | /* The QTD is in process (it has been assigned to a channel) */ | ||
441 | if (hsotg->flags.b.port_connect_status) | ||
442 | /* | ||
443 | * If still connected (i.e. in host mode), halt the | ||
444 | * channel so it can be used for other transfers. If | ||
445 | * no longer connected, the host registers can't be | ||
446 | * written to halt the channel since the core is in | ||
447 | * device mode. | ||
448 | */ | ||
449 | dwc2_hc_halt(hsotg, qh->channel, | ||
450 | DWC2_HC_XFER_URB_DEQUEUE); | ||
451 | } | ||
452 | |||
453 | /* | ||
454 | * Free the QTD and clean up the associated QH. Leave the QH in the | ||
455 | * schedule if it has any remaining QTDs. | ||
456 | */ | ||
457 | if (hsotg->core_params->dma_desc_enable <= 0) { | ||
458 | u8 in_process = urb_qtd->in_process; | ||
459 | |||
460 | dwc2_hcd_qtd_unlink_and_free(hsotg, urb_qtd, qh); | ||
461 | if (in_process) { | ||
462 | dwc2_hcd_qh_deactivate(hsotg, qh, 0); | ||
463 | qh->channel = NULL; | ||
464 | } else if (list_empty(&qh->qtd_list)) { | ||
465 | dwc2_hcd_qh_unlink(hsotg, qh); | ||
466 | } | ||
467 | } else { | ||
468 | dwc2_hcd_qtd_unlink_and_free(hsotg, urb_qtd, qh); | ||
469 | } | ||
470 | |||
471 | return 0; | ||
472 | } | ||
473 | |||
474 | /* Must NOT be called with interrupt disabled or spinlock held */ | ||
475 | static int dwc2_hcd_endpoint_disable(struct dwc2_hsotg *hsotg, | ||
476 | struct usb_host_endpoint *ep, int retry) | ||
477 | { | ||
478 | struct dwc2_qtd *qtd, *qtd_tmp; | ||
479 | struct dwc2_qh *qh; | ||
480 | unsigned long flags; | ||
481 | int rc; | ||
482 | |||
483 | spin_lock_irqsave(&hsotg->lock, flags); | ||
484 | |||
485 | qh = ep->hcpriv; | ||
486 | if (!qh) { | ||
487 | rc = -EINVAL; | ||
488 | goto err; | ||
489 | } | ||
490 | |||
491 | while (!list_empty(&qh->qtd_list) && retry--) { | ||
492 | if (retry == 0) { | ||
493 | dev_err(hsotg->dev, | ||
494 | "## timeout in dwc2_hcd_endpoint_disable() ##\n"); | ||
495 | rc = -EBUSY; | ||
496 | goto err; | ||
497 | } | ||
498 | |||
499 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
500 | usleep_range(20000, 40000); | ||
501 | spin_lock_irqsave(&hsotg->lock, flags); | ||
502 | qh = ep->hcpriv; | ||
503 | if (!qh) { | ||
504 | rc = -EINVAL; | ||
505 | goto err; | ||
506 | } | ||
507 | } | ||
508 | |||
509 | dwc2_hcd_qh_unlink(hsotg, qh); | ||
510 | |||
511 | /* Free each QTD in the QH's QTD list */ | ||
512 | list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) | ||
513 | dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); | ||
514 | |||
515 | ep->hcpriv = NULL; | ||
516 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
517 | dwc2_hcd_qh_free(hsotg, qh); | ||
518 | |||
519 | return 0; | ||
520 | |||
521 | err: | ||
522 | ep->hcpriv = NULL; | ||
523 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
524 | |||
525 | return rc; | ||
526 | } | ||
527 | |||
528 | /* Must be called with interrupt disabled and spinlock held */ | ||
529 | static int dwc2_hcd_endpoint_reset(struct dwc2_hsotg *hsotg, | ||
530 | struct usb_host_endpoint *ep) | ||
531 | { | ||
532 | struct dwc2_qh *qh = ep->hcpriv; | ||
533 | |||
534 | if (!qh) | ||
535 | return -EINVAL; | ||
536 | |||
537 | qh->data_toggle = DWC2_HC_PID_DATA0; | ||
538 | |||
539 | return 0; | ||
540 | } | ||
541 | |||
542 | /* | ||
543 | * Initializes dynamic portions of the DWC_otg HCD state | ||
544 | * | ||
545 | * Must be called with interrupt disabled and spinlock held | ||
546 | */ | ||
547 | static void dwc2_hcd_reinit(struct dwc2_hsotg *hsotg) | ||
548 | { | ||
549 | struct dwc2_host_chan *chan, *chan_tmp; | ||
550 | int num_channels; | ||
551 | int i; | ||
552 | |||
553 | hsotg->flags.d32 = 0; | ||
554 | hsotg->non_periodic_qh_ptr = &hsotg->non_periodic_sched_active; | ||
555 | |||
556 | if (hsotg->core_params->uframe_sched > 0) { | ||
557 | hsotg->available_host_channels = | ||
558 | hsotg->core_params->host_channels; | ||
559 | } else { | ||
560 | hsotg->non_periodic_channels = 0; | ||
561 | hsotg->periodic_channels = 0; | ||
562 | } | ||
563 | |||
564 | /* | ||
565 | * Put all channels in the free channel list and clean up channel | ||
566 | * states | ||
567 | */ | ||
568 | list_for_each_entry_safe(chan, chan_tmp, &hsotg->free_hc_list, | ||
569 | hc_list_entry) | ||
570 | list_del_init(&chan->hc_list_entry); | ||
571 | |||
572 | num_channels = hsotg->core_params->host_channels; | ||
573 | for (i = 0; i < num_channels; i++) { | ||
574 | chan = hsotg->hc_ptr_array[i]; | ||
575 | list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list); | ||
576 | dwc2_hc_cleanup(hsotg, chan); | ||
577 | } | ||
578 | |||
579 | /* Initialize the DWC core for host mode operation */ | ||
580 | dwc2_core_host_init(hsotg); | ||
581 | } | ||
582 | |||
583 | static void dwc2_hc_init_split(struct dwc2_hsotg *hsotg, | ||
584 | struct dwc2_host_chan *chan, | ||
585 | struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb) | ||
586 | { | ||
587 | int hub_addr, hub_port; | ||
588 | |||
589 | chan->do_split = 1; | ||
590 | chan->xact_pos = qtd->isoc_split_pos; | ||
591 | chan->complete_split = qtd->complete_split; | ||
592 | dwc2_host_hub_info(hsotg, urb->priv, &hub_addr, &hub_port); | ||
593 | chan->hub_addr = (u8)hub_addr; | ||
594 | chan->hub_port = (u8)hub_port; | ||
595 | } | ||
596 | |||
597 | static void *dwc2_hc_init_xfer(struct dwc2_hsotg *hsotg, | ||
598 | struct dwc2_host_chan *chan, | ||
599 | struct dwc2_qtd *qtd, void *bufptr) | ||
600 | { | ||
601 | struct dwc2_hcd_urb *urb = qtd->urb; | ||
602 | struct dwc2_hcd_iso_packet_desc *frame_desc; | ||
603 | |||
604 | switch (dwc2_hcd_get_pipe_type(&urb->pipe_info)) { | ||
605 | case USB_ENDPOINT_XFER_CONTROL: | ||
606 | chan->ep_type = USB_ENDPOINT_XFER_CONTROL; | ||
607 | |||
608 | switch (qtd->control_phase) { | ||
609 | case DWC2_CONTROL_SETUP: | ||
610 | dev_vdbg(hsotg->dev, " Control setup transaction\n"); | ||
611 | chan->do_ping = 0; | ||
612 | chan->ep_is_in = 0; | ||
613 | chan->data_pid_start = DWC2_HC_PID_SETUP; | ||
614 | if (hsotg->core_params->dma_enable > 0) | ||
615 | chan->xfer_dma = urb->setup_dma; | ||
616 | else | ||
617 | chan->xfer_buf = urb->setup_packet; | ||
618 | chan->xfer_len = 8; | ||
619 | bufptr = NULL; | ||
620 | break; | ||
621 | |||
622 | case DWC2_CONTROL_DATA: | ||
623 | dev_vdbg(hsotg->dev, " Control data transaction\n"); | ||
624 | chan->data_pid_start = qtd->data_toggle; | ||
625 | break; | ||
626 | |||
627 | case DWC2_CONTROL_STATUS: | ||
628 | /* | ||
629 | * Direction is opposite of data direction or IN if no | ||
630 | * data | ||
631 | */ | ||
632 | dev_vdbg(hsotg->dev, " Control status transaction\n"); | ||
633 | if (urb->length == 0) | ||
634 | chan->ep_is_in = 1; | ||
635 | else | ||
636 | chan->ep_is_in = | ||
637 | dwc2_hcd_is_pipe_out(&urb->pipe_info); | ||
638 | if (chan->ep_is_in) | ||
639 | chan->do_ping = 0; | ||
640 | chan->data_pid_start = DWC2_HC_PID_DATA1; | ||
641 | chan->xfer_len = 0; | ||
642 | if (hsotg->core_params->dma_enable > 0) | ||
643 | chan->xfer_dma = hsotg->status_buf_dma; | ||
644 | else | ||
645 | chan->xfer_buf = hsotg->status_buf; | ||
646 | bufptr = NULL; | ||
647 | break; | ||
648 | } | ||
649 | break; | ||
650 | |||
651 | case USB_ENDPOINT_XFER_BULK: | ||
652 | chan->ep_type = USB_ENDPOINT_XFER_BULK; | ||
653 | break; | ||
654 | |||
655 | case USB_ENDPOINT_XFER_INT: | ||
656 | chan->ep_type = USB_ENDPOINT_XFER_INT; | ||
657 | break; | ||
658 | |||
659 | case USB_ENDPOINT_XFER_ISOC: | ||
660 | chan->ep_type = USB_ENDPOINT_XFER_ISOC; | ||
661 | if (hsotg->core_params->dma_desc_enable > 0) | ||
662 | break; | ||
663 | |||
664 | frame_desc = &urb->iso_descs[qtd->isoc_frame_index]; | ||
665 | frame_desc->status = 0; | ||
666 | |||
667 | if (hsotg->core_params->dma_enable > 0) { | ||
668 | chan->xfer_dma = urb->dma; | ||
669 | chan->xfer_dma += frame_desc->offset + | ||
670 | qtd->isoc_split_offset; | ||
671 | } else { | ||
672 | chan->xfer_buf = urb->buf; | ||
673 | chan->xfer_buf += frame_desc->offset + | ||
674 | qtd->isoc_split_offset; | ||
675 | } | ||
676 | |||
677 | chan->xfer_len = frame_desc->length - qtd->isoc_split_offset; | ||
678 | |||
679 | /* For non-dword aligned buffers */ | ||
680 | if (hsotg->core_params->dma_enable > 0 && | ||
681 | (chan->xfer_dma & 0x3)) | ||
682 | bufptr = (u8 *)urb->buf + frame_desc->offset + | ||
683 | qtd->isoc_split_offset; | ||
684 | else | ||
685 | bufptr = NULL; | ||
686 | |||
687 | if (chan->xact_pos == DWC2_HCSPLT_XACTPOS_ALL) { | ||
688 | if (chan->xfer_len <= 188) | ||
689 | chan->xact_pos = DWC2_HCSPLT_XACTPOS_ALL; | ||
690 | else | ||
691 | chan->xact_pos = DWC2_HCSPLT_XACTPOS_BEGIN; | ||
692 | } | ||
693 | break; | ||
694 | } | ||
695 | |||
696 | return bufptr; | ||
697 | } | ||
698 | |||
699 | static int dwc2_hc_setup_align_buf(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, | ||
700 | struct dwc2_host_chan *chan, void *bufptr) | ||
701 | { | ||
702 | u32 buf_size; | ||
703 | |||
704 | if (chan->ep_type != USB_ENDPOINT_XFER_ISOC) | ||
705 | buf_size = hsotg->core_params->max_transfer_size; | ||
706 | else | ||
707 | buf_size = 4096; | ||
708 | |||
709 | if (!qh->dw_align_buf) { | ||
710 | qh->dw_align_buf = dma_alloc_coherent(hsotg->dev, buf_size, | ||
711 | &qh->dw_align_buf_dma, | ||
712 | GFP_ATOMIC); | ||
713 | if (!qh->dw_align_buf) | ||
714 | return -ENOMEM; | ||
715 | } | ||
716 | |||
717 | if (!chan->ep_is_in && chan->xfer_len) { | ||
718 | dma_sync_single_for_cpu(hsotg->dev, chan->xfer_dma, buf_size, | ||
719 | DMA_TO_DEVICE); | ||
720 | memcpy(qh->dw_align_buf, bufptr, chan->xfer_len); | ||
721 | dma_sync_single_for_device(hsotg->dev, chan->xfer_dma, buf_size, | ||
722 | DMA_TO_DEVICE); | ||
723 | } | ||
724 | |||
725 | chan->align_buf = qh->dw_align_buf_dma; | ||
726 | return 0; | ||
727 | } | ||
728 | |||
729 | /** | ||
730 | * dwc2_assign_and_init_hc() - Assigns transactions from a QTD to a free host | ||
731 | * channel and initializes the host channel to perform the transactions. The | ||
732 | * host channel is removed from the free list. | ||
733 | * | ||
734 | * @hsotg: The HCD state structure | ||
735 | * @qh: Transactions from the first QTD for this QH are selected and assigned | ||
736 | * to a free host channel | ||
737 | */ | ||
738 | static int dwc2_assign_and_init_hc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | ||
739 | { | ||
740 | struct dwc2_host_chan *chan; | ||
741 | struct dwc2_hcd_urb *urb; | ||
742 | struct dwc2_qtd *qtd; | ||
743 | void *bufptr = NULL; | ||
744 | |||
745 | if (dbg_qh(qh)) | ||
746 | dev_vdbg(hsotg->dev, "%s(%p,%p)\n", __func__, hsotg, qh); | ||
747 | |||
748 | if (list_empty(&qh->qtd_list)) { | ||
749 | dev_dbg(hsotg->dev, "No QTDs in QH list\n"); | ||
750 | return -ENOMEM; | ||
751 | } | ||
752 | |||
753 | if (list_empty(&hsotg->free_hc_list)) { | ||
754 | dev_dbg(hsotg->dev, "No free channel to assign\n"); | ||
755 | return -ENOMEM; | ||
756 | } | ||
757 | |||
758 | chan = list_first_entry(&hsotg->free_hc_list, struct dwc2_host_chan, | ||
759 | hc_list_entry); | ||
760 | |||
761 | /* Remove host channel from free list */ | ||
762 | list_del_init(&chan->hc_list_entry); | ||
763 | |||
764 | qtd = list_first_entry(&qh->qtd_list, struct dwc2_qtd, qtd_list_entry); | ||
765 | urb = qtd->urb; | ||
766 | qh->channel = chan; | ||
767 | qtd->in_process = 1; | ||
768 | |||
769 | /* | ||
770 | * Use usb_pipedevice to determine device address. This address is | ||
771 | * 0 before the SET_ADDRESS command and the correct address afterward. | ||
772 | */ | ||
773 | chan->dev_addr = dwc2_hcd_get_dev_addr(&urb->pipe_info); | ||
774 | chan->ep_num = dwc2_hcd_get_ep_num(&urb->pipe_info); | ||
775 | chan->speed = qh->dev_speed; | ||
776 | chan->max_packet = dwc2_max_packet(qh->maxp); | ||
777 | |||
778 | chan->xfer_started = 0; | ||
779 | chan->halt_status = DWC2_HC_XFER_NO_HALT_STATUS; | ||
780 | chan->error_state = (qtd->error_count > 0); | ||
781 | chan->halt_on_queue = 0; | ||
782 | chan->halt_pending = 0; | ||
783 | chan->requests = 0; | ||
784 | |||
785 | /* | ||
786 | * The following values may be modified in the transfer type section | ||
787 | * below. The xfer_len value may be reduced when the transfer is | ||
788 | * started to accommodate the max widths of the XferSize and PktCnt | ||
789 | * fields in the HCTSIZn register. | ||
790 | */ | ||
791 | |||
792 | chan->ep_is_in = (dwc2_hcd_is_pipe_in(&urb->pipe_info) != 0); | ||
793 | if (chan->ep_is_in) | ||
794 | chan->do_ping = 0; | ||
795 | else | ||
796 | chan->do_ping = qh->ping_state; | ||
797 | |||
798 | chan->data_pid_start = qh->data_toggle; | ||
799 | chan->multi_count = 1; | ||
800 | |||
801 | if (urb->actual_length > urb->length && | ||
802 | !dwc2_hcd_is_pipe_in(&urb->pipe_info)) | ||
803 | urb->actual_length = urb->length; | ||
804 | |||
805 | if (hsotg->core_params->dma_enable > 0) { | ||
806 | chan->xfer_dma = urb->dma + urb->actual_length; | ||
807 | |||
808 | /* For non-dword aligned case */ | ||
809 | if (hsotg->core_params->dma_desc_enable <= 0 && | ||
810 | (chan->xfer_dma & 0x3)) | ||
811 | bufptr = (u8 *)urb->buf + urb->actual_length; | ||
812 | } else { | ||
813 | chan->xfer_buf = (u8 *)urb->buf + urb->actual_length; | ||
814 | } | ||
815 | |||
816 | chan->xfer_len = urb->length - urb->actual_length; | ||
817 | chan->xfer_count = 0; | ||
818 | |||
819 | /* Set the split attributes if required */ | ||
820 | if (qh->do_split) | ||
821 | dwc2_hc_init_split(hsotg, chan, qtd, urb); | ||
822 | else | ||
823 | chan->do_split = 0; | ||
824 | |||
825 | /* Set the transfer attributes */ | ||
826 | bufptr = dwc2_hc_init_xfer(hsotg, chan, qtd, bufptr); | ||
827 | |||
828 | /* Non DWORD-aligned buffer case */ | ||
829 | if (bufptr) { | ||
830 | dev_vdbg(hsotg->dev, "Non-aligned buffer\n"); | ||
831 | if (dwc2_hc_setup_align_buf(hsotg, qh, chan, bufptr)) { | ||
832 | dev_err(hsotg->dev, | ||
833 | "%s: Failed to allocate memory to handle non-dword aligned buffer\n", | ||
834 | __func__); | ||
835 | /* Add channel back to free list */ | ||
836 | chan->align_buf = 0; | ||
837 | chan->multi_count = 0; | ||
838 | list_add_tail(&chan->hc_list_entry, | ||
839 | &hsotg->free_hc_list); | ||
840 | qtd->in_process = 0; | ||
841 | qh->channel = NULL; | ||
842 | return -ENOMEM; | ||
843 | } | ||
844 | } else { | ||
845 | chan->align_buf = 0; | ||
846 | } | ||
847 | |||
848 | if (chan->ep_type == USB_ENDPOINT_XFER_INT || | ||
849 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) | ||
850 | /* | ||
851 | * This value may be modified when the transfer is started | ||
852 | * to reflect the actual transfer length | ||
853 | */ | ||
854 | chan->multi_count = dwc2_hb_mult(qh->maxp); | ||
855 | |||
856 | if (hsotg->core_params->dma_desc_enable > 0) | ||
857 | chan->desc_list_addr = qh->desc_list_dma; | ||
858 | |||
859 | dwc2_hc_init(hsotg, chan); | ||
860 | chan->qh = qh; | ||
861 | |||
862 | return 0; | ||
863 | } | ||
864 | |||
865 | /** | ||
866 | * dwc2_hcd_select_transactions() - Selects transactions from the HCD transfer | ||
867 | * schedule and assigns them to available host channels. Called from the HCD | ||
868 | * interrupt handler functions. | ||
869 | * | ||
870 | * @hsotg: The HCD state structure | ||
871 | * | ||
872 | * Return: The types of new transactions that were assigned to host channels | ||
873 | */ | ||
874 | enum dwc2_transaction_type dwc2_hcd_select_transactions( | ||
875 | struct dwc2_hsotg *hsotg) | ||
876 | { | ||
877 | enum dwc2_transaction_type ret_val = DWC2_TRANSACTION_NONE; | ||
878 | struct list_head *qh_ptr; | ||
879 | struct dwc2_qh *qh; | ||
880 | int num_channels; | ||
881 | |||
882 | #ifdef DWC2_DEBUG_SOF | ||
883 | dev_vdbg(hsotg->dev, " Select Transactions\n"); | ||
884 | #endif | ||
885 | |||
886 | /* Process entries in the periodic ready list */ | ||
887 | qh_ptr = hsotg->periodic_sched_ready.next; | ||
888 | while (qh_ptr != &hsotg->periodic_sched_ready) { | ||
889 | if (list_empty(&hsotg->free_hc_list)) | ||
890 | break; | ||
891 | if (hsotg->core_params->uframe_sched > 0) { | ||
892 | if (hsotg->available_host_channels <= 1) | ||
893 | break; | ||
894 | hsotg->available_host_channels--; | ||
895 | } | ||
896 | qh = list_entry(qh_ptr, struct dwc2_qh, qh_list_entry); | ||
897 | if (dwc2_assign_and_init_hc(hsotg, qh)) | ||
898 | break; | ||
899 | |||
900 | /* | ||
901 | * Move the QH from the periodic ready schedule to the | ||
902 | * periodic assigned schedule | ||
903 | */ | ||
904 | qh_ptr = qh_ptr->next; | ||
905 | list_move(&qh->qh_list_entry, &hsotg->periodic_sched_assigned); | ||
906 | ret_val = DWC2_TRANSACTION_PERIODIC; | ||
907 | } | ||
908 | |||
909 | /* | ||
910 | * Process entries in the inactive portion of the non-periodic | ||
911 | * schedule. Some free host channels may not be used if they are | ||
912 | * reserved for periodic transfers. | ||
913 | */ | ||
914 | num_channels = hsotg->core_params->host_channels; | ||
915 | qh_ptr = hsotg->non_periodic_sched_inactive.next; | ||
916 | while (qh_ptr != &hsotg->non_periodic_sched_inactive) { | ||
917 | if (hsotg->core_params->uframe_sched <= 0 && | ||
918 | hsotg->non_periodic_channels >= num_channels - | ||
919 | hsotg->periodic_channels) | ||
920 | break; | ||
921 | if (list_empty(&hsotg->free_hc_list)) | ||
922 | break; | ||
923 | qh = list_entry(qh_ptr, struct dwc2_qh, qh_list_entry); | ||
924 | if (hsotg->core_params->uframe_sched > 0) { | ||
925 | if (hsotg->available_host_channels < 1) | ||
926 | break; | ||
927 | hsotg->available_host_channels--; | ||
928 | } | ||
929 | |||
930 | if (dwc2_assign_and_init_hc(hsotg, qh)) | ||
931 | break; | ||
932 | |||
933 | /* | ||
934 | * Move the QH from the non-periodic inactive schedule to the | ||
935 | * non-periodic active schedule | ||
936 | */ | ||
937 | qh_ptr = qh_ptr->next; | ||
938 | list_move(&qh->qh_list_entry, | ||
939 | &hsotg->non_periodic_sched_active); | ||
940 | |||
941 | if (ret_val == DWC2_TRANSACTION_NONE) | ||
942 | ret_val = DWC2_TRANSACTION_NON_PERIODIC; | ||
943 | else | ||
944 | ret_val = DWC2_TRANSACTION_ALL; | ||
945 | |||
946 | if (hsotg->core_params->uframe_sched <= 0) | ||
947 | hsotg->non_periodic_channels++; | ||
948 | } | ||
949 | |||
950 | return ret_val; | ||
951 | } | ||
952 | |||
953 | /** | ||
954 | * dwc2_queue_transaction() - Attempts to queue a single transaction request for | ||
955 | * a host channel associated with either a periodic or non-periodic transfer | ||
956 | * | ||
957 | * @hsotg: The HCD state structure | ||
958 | * @chan: Host channel descriptor associated with either a periodic or | ||
959 | * non-periodic transfer | ||
960 | * @fifo_dwords_avail: Number of DWORDs available in the periodic Tx FIFO | ||
961 | * for periodic transfers or the non-periodic Tx FIFO | ||
962 | * for non-periodic transfers | ||
963 | * | ||
964 | * Return: 1 if a request is queued and more requests may be needed to | ||
965 | * complete the transfer, 0 if no more requests are required for this | ||
966 | * transfer, -1 if there is insufficient space in the Tx FIFO | ||
967 | * | ||
968 | * This function assumes that there is space available in the appropriate | ||
969 | * request queue. For an OUT transfer or SETUP transaction in Slave mode, | ||
970 | * it checks whether space is available in the appropriate Tx FIFO. | ||
971 | * | ||
972 | * Must be called with interrupt disabled and spinlock held | ||
973 | */ | ||
974 | static int dwc2_queue_transaction(struct dwc2_hsotg *hsotg, | ||
975 | struct dwc2_host_chan *chan, | ||
976 | u16 fifo_dwords_avail) | ||
977 | { | ||
978 | int retval = 0; | ||
979 | |||
980 | if (hsotg->core_params->dma_enable > 0) { | ||
981 | if (hsotg->core_params->dma_desc_enable > 0) { | ||
982 | if (!chan->xfer_started || | ||
983 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) { | ||
984 | dwc2_hcd_start_xfer_ddma(hsotg, chan->qh); | ||
985 | chan->qh->ping_state = 0; | ||
986 | } | ||
987 | } else if (!chan->xfer_started) { | ||
988 | dwc2_hc_start_transfer(hsotg, chan); | ||
989 | chan->qh->ping_state = 0; | ||
990 | } | ||
991 | } else if (chan->halt_pending) { | ||
992 | /* Don't queue a request if the channel has been halted */ | ||
993 | } else if (chan->halt_on_queue) { | ||
994 | dwc2_hc_halt(hsotg, chan, chan->halt_status); | ||
995 | } else if (chan->do_ping) { | ||
996 | if (!chan->xfer_started) | ||
997 | dwc2_hc_start_transfer(hsotg, chan); | ||
998 | } else if (!chan->ep_is_in || | ||
999 | chan->data_pid_start == DWC2_HC_PID_SETUP) { | ||
1000 | if ((fifo_dwords_avail * 4) >= chan->max_packet) { | ||
1001 | if (!chan->xfer_started) { | ||
1002 | dwc2_hc_start_transfer(hsotg, chan); | ||
1003 | retval = 1; | ||
1004 | } else { | ||
1005 | retval = dwc2_hc_continue_transfer(hsotg, chan); | ||
1006 | } | ||
1007 | } else { | ||
1008 | retval = -1; | ||
1009 | } | ||
1010 | } else { | ||
1011 | if (!chan->xfer_started) { | ||
1012 | dwc2_hc_start_transfer(hsotg, chan); | ||
1013 | retval = 1; | ||
1014 | } else { | ||
1015 | retval = dwc2_hc_continue_transfer(hsotg, chan); | ||
1016 | } | ||
1017 | } | ||
1018 | |||
1019 | return retval; | ||
1020 | } | ||
1021 | |||
1022 | /* | ||
1023 | * Processes periodic channels for the next frame and queues transactions for | ||
1024 | * these channels to the DWC_otg controller. After queueing transactions, the | ||
1025 | * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions | ||
1026 | * to queue as Periodic Tx FIFO or request queue space becomes available. | ||
1027 | * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled. | ||
1028 | * | ||
1029 | * Must be called with interrupt disabled and spinlock held | ||
1030 | */ | ||
1031 | static void dwc2_process_periodic_channels(struct dwc2_hsotg *hsotg) | ||
1032 | { | ||
1033 | struct list_head *qh_ptr; | ||
1034 | struct dwc2_qh *qh; | ||
1035 | u32 tx_status; | ||
1036 | u32 fspcavail; | ||
1037 | u32 gintmsk; | ||
1038 | int status; | ||
1039 | int no_queue_space = 0; | ||
1040 | int no_fifo_space = 0; | ||
1041 | u32 qspcavail; | ||
1042 | |||
1043 | if (dbg_perio()) | ||
1044 | dev_vdbg(hsotg->dev, "Queue periodic transactions\n"); | ||
1045 | |||
1046 | tx_status = readl(hsotg->regs + HPTXSTS); | ||
1047 | qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >> | ||
1048 | TXSTS_QSPCAVAIL_SHIFT; | ||
1049 | fspcavail = (tx_status & TXSTS_FSPCAVAIL_MASK) >> | ||
1050 | TXSTS_FSPCAVAIL_SHIFT; | ||
1051 | |||
1052 | if (dbg_perio()) { | ||
1053 | dev_vdbg(hsotg->dev, " P Tx Req Queue Space Avail (before queue): %d\n", | ||
1054 | qspcavail); | ||
1055 | dev_vdbg(hsotg->dev, " P Tx FIFO Space Avail (before queue): %d\n", | ||
1056 | fspcavail); | ||
1057 | } | ||
1058 | |||
1059 | qh_ptr = hsotg->periodic_sched_assigned.next; | ||
1060 | while (qh_ptr != &hsotg->periodic_sched_assigned) { | ||
1061 | tx_status = readl(hsotg->regs + HPTXSTS); | ||
1062 | qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >> | ||
1063 | TXSTS_QSPCAVAIL_SHIFT; | ||
1064 | if (qspcavail == 0) { | ||
1065 | no_queue_space = 1; | ||
1066 | break; | ||
1067 | } | ||
1068 | |||
1069 | qh = list_entry(qh_ptr, struct dwc2_qh, qh_list_entry); | ||
1070 | if (!qh->channel) { | ||
1071 | qh_ptr = qh_ptr->next; | ||
1072 | continue; | ||
1073 | } | ||
1074 | |||
1075 | /* Make sure EP's TT buffer is clean before queueing qtds */ | ||
1076 | if (qh->tt_buffer_dirty) { | ||
1077 | qh_ptr = qh_ptr->next; | ||
1078 | continue; | ||
1079 | } | ||
1080 | |||
1081 | /* | ||
1082 | * Set a flag if we're queuing high-bandwidth in slave mode. | ||
1083 | * The flag prevents any halts to get into the request queue in | ||
1084 | * the middle of multiple high-bandwidth packets getting queued. | ||
1085 | */ | ||
1086 | if (hsotg->core_params->dma_enable <= 0 && | ||
1087 | qh->channel->multi_count > 1) | ||
1088 | hsotg->queuing_high_bandwidth = 1; | ||
1089 | |||
1090 | fspcavail = (tx_status & TXSTS_FSPCAVAIL_MASK) >> | ||
1091 | TXSTS_FSPCAVAIL_SHIFT; | ||
1092 | status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail); | ||
1093 | if (status < 0) { | ||
1094 | no_fifo_space = 1; | ||
1095 | break; | ||
1096 | } | ||
1097 | |||
1098 | /* | ||
1099 | * In Slave mode, stay on the current transfer until there is | ||
1100 | * nothing more to do or the high-bandwidth request count is | ||
1101 | * reached. In DMA mode, only need to queue one request. The | ||
1102 | * controller automatically handles multiple packets for | ||
1103 | * high-bandwidth transfers. | ||
1104 | */ | ||
1105 | if (hsotg->core_params->dma_enable > 0 || status == 0 || | ||
1106 | qh->channel->requests == qh->channel->multi_count) { | ||
1107 | qh_ptr = qh_ptr->next; | ||
1108 | /* | ||
1109 | * Move the QH from the periodic assigned schedule to | ||
1110 | * the periodic queued schedule | ||
1111 | */ | ||
1112 | list_move(&qh->qh_list_entry, | ||
1113 | &hsotg->periodic_sched_queued); | ||
1114 | |||
1115 | /* done queuing high bandwidth */ | ||
1116 | hsotg->queuing_high_bandwidth = 0; | ||
1117 | } | ||
1118 | } | ||
1119 | |||
1120 | if (hsotg->core_params->dma_enable <= 0) { | ||
1121 | tx_status = readl(hsotg->regs + HPTXSTS); | ||
1122 | qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >> | ||
1123 | TXSTS_QSPCAVAIL_SHIFT; | ||
1124 | fspcavail = (tx_status & TXSTS_FSPCAVAIL_MASK) >> | ||
1125 | TXSTS_FSPCAVAIL_SHIFT; | ||
1126 | if (dbg_perio()) { | ||
1127 | dev_vdbg(hsotg->dev, | ||
1128 | " P Tx Req Queue Space Avail (after queue): %d\n", | ||
1129 | qspcavail); | ||
1130 | dev_vdbg(hsotg->dev, | ||
1131 | " P Tx FIFO Space Avail (after queue): %d\n", | ||
1132 | fspcavail); | ||
1133 | } | ||
1134 | |||
1135 | if (!list_empty(&hsotg->periodic_sched_assigned) || | ||
1136 | no_queue_space || no_fifo_space) { | ||
1137 | /* | ||
1138 | * May need to queue more transactions as the request | ||
1139 | * queue or Tx FIFO empties. Enable the periodic Tx | ||
1140 | * FIFO empty interrupt. (Always use the half-empty | ||
1141 | * level to ensure that new requests are loaded as | ||
1142 | * soon as possible.) | ||
1143 | */ | ||
1144 | gintmsk = readl(hsotg->regs + GINTMSK); | ||
1145 | gintmsk |= GINTSTS_PTXFEMP; | ||
1146 | writel(gintmsk, hsotg->regs + GINTMSK); | ||
1147 | } else { | ||
1148 | /* | ||
1149 | * Disable the Tx FIFO empty interrupt since there are | ||
1150 | * no more transactions that need to be queued right | ||
1151 | * now. This function is called from interrupt | ||
1152 | * handlers to queue more transactions as transfer | ||
1153 | * states change. | ||
1154 | */ | ||
1155 | gintmsk = readl(hsotg->regs + GINTMSK); | ||
1156 | gintmsk &= ~GINTSTS_PTXFEMP; | ||
1157 | writel(gintmsk, hsotg->regs + GINTMSK); | ||
1158 | } | ||
1159 | } | ||
1160 | } | ||
1161 | |||
1162 | /* | ||
1163 | * Processes active non-periodic channels and queues transactions for these | ||
1164 | * channels to the DWC_otg controller. After queueing transactions, the NP Tx | ||
1165 | * FIFO Empty interrupt is enabled if there are more transactions to queue as | ||
1166 | * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx | ||
1167 | * FIFO Empty interrupt is disabled. | ||
1168 | * | ||
1169 | * Must be called with interrupt disabled and spinlock held | ||
1170 | */ | ||
1171 | static void dwc2_process_non_periodic_channels(struct dwc2_hsotg *hsotg) | ||
1172 | { | ||
1173 | struct list_head *orig_qh_ptr; | ||
1174 | struct dwc2_qh *qh; | ||
1175 | u32 tx_status; | ||
1176 | u32 qspcavail; | ||
1177 | u32 fspcavail; | ||
1178 | u32 gintmsk; | ||
1179 | int status; | ||
1180 | int no_queue_space = 0; | ||
1181 | int no_fifo_space = 0; | ||
1182 | int more_to_do = 0; | ||
1183 | |||
1184 | dev_vdbg(hsotg->dev, "Queue non-periodic transactions\n"); | ||
1185 | |||
1186 | tx_status = readl(hsotg->regs + GNPTXSTS); | ||
1187 | qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >> | ||
1188 | TXSTS_QSPCAVAIL_SHIFT; | ||
1189 | fspcavail = (tx_status & TXSTS_FSPCAVAIL_MASK) >> | ||
1190 | TXSTS_FSPCAVAIL_SHIFT; | ||
1191 | dev_vdbg(hsotg->dev, " NP Tx Req Queue Space Avail (before queue): %d\n", | ||
1192 | qspcavail); | ||
1193 | dev_vdbg(hsotg->dev, " NP Tx FIFO Space Avail (before queue): %d\n", | ||
1194 | fspcavail); | ||
1195 | |||
1196 | /* | ||
1197 | * Keep track of the starting point. Skip over the start-of-list | ||
1198 | * entry. | ||
1199 | */ | ||
1200 | if (hsotg->non_periodic_qh_ptr == &hsotg->non_periodic_sched_active) | ||
1201 | hsotg->non_periodic_qh_ptr = hsotg->non_periodic_qh_ptr->next; | ||
1202 | orig_qh_ptr = hsotg->non_periodic_qh_ptr; | ||
1203 | |||
1204 | /* | ||
1205 | * Process once through the active list or until no more space is | ||
1206 | * available in the request queue or the Tx FIFO | ||
1207 | */ | ||
1208 | do { | ||
1209 | tx_status = readl(hsotg->regs + GNPTXSTS); | ||
1210 | qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >> | ||
1211 | TXSTS_QSPCAVAIL_SHIFT; | ||
1212 | if (hsotg->core_params->dma_enable <= 0 && qspcavail == 0) { | ||
1213 | no_queue_space = 1; | ||
1214 | break; | ||
1215 | } | ||
1216 | |||
1217 | qh = list_entry(hsotg->non_periodic_qh_ptr, struct dwc2_qh, | ||
1218 | qh_list_entry); | ||
1219 | if (!qh->channel) | ||
1220 | goto next; | ||
1221 | |||
1222 | /* Make sure EP's TT buffer is clean before queueing qtds */ | ||
1223 | if (qh->tt_buffer_dirty) | ||
1224 | goto next; | ||
1225 | |||
1226 | fspcavail = (tx_status & TXSTS_FSPCAVAIL_MASK) >> | ||
1227 | TXSTS_FSPCAVAIL_SHIFT; | ||
1228 | status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail); | ||
1229 | |||
1230 | if (status > 0) { | ||
1231 | more_to_do = 1; | ||
1232 | } else if (status < 0) { | ||
1233 | no_fifo_space = 1; | ||
1234 | break; | ||
1235 | } | ||
1236 | next: | ||
1237 | /* Advance to next QH, skipping start-of-list entry */ | ||
1238 | hsotg->non_periodic_qh_ptr = hsotg->non_periodic_qh_ptr->next; | ||
1239 | if (hsotg->non_periodic_qh_ptr == | ||
1240 | &hsotg->non_periodic_sched_active) | ||
1241 | hsotg->non_periodic_qh_ptr = | ||
1242 | hsotg->non_periodic_qh_ptr->next; | ||
1243 | } while (hsotg->non_periodic_qh_ptr != orig_qh_ptr); | ||
1244 | |||
1245 | if (hsotg->core_params->dma_enable <= 0) { | ||
1246 | tx_status = readl(hsotg->regs + GNPTXSTS); | ||
1247 | qspcavail = (tx_status & TXSTS_QSPCAVAIL_MASK) >> | ||
1248 | TXSTS_QSPCAVAIL_SHIFT; | ||
1249 | fspcavail = (tx_status & TXSTS_FSPCAVAIL_MASK) >> | ||
1250 | TXSTS_FSPCAVAIL_SHIFT; | ||
1251 | dev_vdbg(hsotg->dev, | ||
1252 | " NP Tx Req Queue Space Avail (after queue): %d\n", | ||
1253 | qspcavail); | ||
1254 | dev_vdbg(hsotg->dev, | ||
1255 | " NP Tx FIFO Space Avail (after queue): %d\n", | ||
1256 | fspcavail); | ||
1257 | |||
1258 | if (more_to_do || no_queue_space || no_fifo_space) { | ||
1259 | /* | ||
1260 | * May need to queue more transactions as the request | ||
1261 | * queue or Tx FIFO empties. Enable the non-periodic | ||
1262 | * Tx FIFO empty interrupt. (Always use the half-empty | ||
1263 | * level to ensure that new requests are loaded as | ||
1264 | * soon as possible.) | ||
1265 | */ | ||
1266 | gintmsk = readl(hsotg->regs + GINTMSK); | ||
1267 | gintmsk |= GINTSTS_NPTXFEMP; | ||
1268 | writel(gintmsk, hsotg->regs + GINTMSK); | ||
1269 | } else { | ||
1270 | /* | ||
1271 | * Disable the Tx FIFO empty interrupt since there are | ||
1272 | * no more transactions that need to be queued right | ||
1273 | * now. This function is called from interrupt | ||
1274 | * handlers to queue more transactions as transfer | ||
1275 | * states change. | ||
1276 | */ | ||
1277 | gintmsk = readl(hsotg->regs + GINTMSK); | ||
1278 | gintmsk &= ~GINTSTS_NPTXFEMP; | ||
1279 | writel(gintmsk, hsotg->regs + GINTMSK); | ||
1280 | } | ||
1281 | } | ||
1282 | } | ||
1283 | |||
1284 | /** | ||
1285 | * dwc2_hcd_queue_transactions() - Processes the currently active host channels | ||
1286 | * and queues transactions for these channels to the DWC_otg controller. Called | ||
1287 | * from the HCD interrupt handler functions. | ||
1288 | * | ||
1289 | * @hsotg: The HCD state structure | ||
1290 | * @tr_type: The type(s) of transactions to queue (non-periodic, periodic, | ||
1291 | * or both) | ||
1292 | * | ||
1293 | * Must be called with interrupt disabled and spinlock held | ||
1294 | */ | ||
1295 | void dwc2_hcd_queue_transactions(struct dwc2_hsotg *hsotg, | ||
1296 | enum dwc2_transaction_type tr_type) | ||
1297 | { | ||
1298 | #ifdef DWC2_DEBUG_SOF | ||
1299 | dev_vdbg(hsotg->dev, "Queue Transactions\n"); | ||
1300 | #endif | ||
1301 | /* Process host channels associated with periodic transfers */ | ||
1302 | if ((tr_type == DWC2_TRANSACTION_PERIODIC || | ||
1303 | tr_type == DWC2_TRANSACTION_ALL) && | ||
1304 | !list_empty(&hsotg->periodic_sched_assigned)) | ||
1305 | dwc2_process_periodic_channels(hsotg); | ||
1306 | |||
1307 | /* Process host channels associated with non-periodic transfers */ | ||
1308 | if (tr_type == DWC2_TRANSACTION_NON_PERIODIC || | ||
1309 | tr_type == DWC2_TRANSACTION_ALL) { | ||
1310 | if (!list_empty(&hsotg->non_periodic_sched_active)) { | ||
1311 | dwc2_process_non_periodic_channels(hsotg); | ||
1312 | } else { | ||
1313 | /* | ||
1314 | * Ensure NP Tx FIFO empty interrupt is disabled when | ||
1315 | * there are no non-periodic transfers to process | ||
1316 | */ | ||
1317 | u32 gintmsk = readl(hsotg->regs + GINTMSK); | ||
1318 | |||
1319 | gintmsk &= ~GINTSTS_NPTXFEMP; | ||
1320 | writel(gintmsk, hsotg->regs + GINTMSK); | ||
1321 | } | ||
1322 | } | ||
1323 | } | ||
1324 | |||
1325 | static void dwc2_conn_id_status_change(struct work_struct *work) | ||
1326 | { | ||
1327 | struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, | ||
1328 | wf_otg); | ||
1329 | u32 count = 0; | ||
1330 | u32 gotgctl; | ||
1331 | |||
1332 | dev_dbg(hsotg->dev, "%s()\n", __func__); | ||
1333 | |||
1334 | gotgctl = readl(hsotg->regs + GOTGCTL); | ||
1335 | dev_dbg(hsotg->dev, "gotgctl=%0x\n", gotgctl); | ||
1336 | dev_dbg(hsotg->dev, "gotgctl.b.conidsts=%d\n", | ||
1337 | !!(gotgctl & GOTGCTL_CONID_B)); | ||
1338 | |||
1339 | /* B-Device connector (Device Mode) */ | ||
1340 | if (gotgctl & GOTGCTL_CONID_B) { | ||
1341 | /* Wait for switch to device mode */ | ||
1342 | dev_dbg(hsotg->dev, "connId B\n"); | ||
1343 | while (!dwc2_is_device_mode(hsotg)) { | ||
1344 | dev_info(hsotg->dev, | ||
1345 | "Waiting for Peripheral Mode, Mode=%s\n", | ||
1346 | dwc2_is_host_mode(hsotg) ? "Host" : | ||
1347 | "Peripheral"); | ||
1348 | usleep_range(20000, 40000); | ||
1349 | if (++count > 250) | ||
1350 | break; | ||
1351 | } | ||
1352 | if (count > 250) | ||
1353 | dev_err(hsotg->dev, | ||
1354 | "Connection id status change timed out\n"); | ||
1355 | hsotg->op_state = OTG_STATE_B_PERIPHERAL; | ||
1356 | dwc2_core_init(hsotg, false, -1); | ||
1357 | dwc2_enable_global_interrupts(hsotg); | ||
1358 | } else { | ||
1359 | /* A-Device connector (Host Mode) */ | ||
1360 | dev_dbg(hsotg->dev, "connId A\n"); | ||
1361 | while (!dwc2_is_host_mode(hsotg)) { | ||
1362 | dev_info(hsotg->dev, "Waiting for Host Mode, Mode=%s\n", | ||
1363 | dwc2_is_host_mode(hsotg) ? | ||
1364 | "Host" : "Peripheral"); | ||
1365 | usleep_range(20000, 40000); | ||
1366 | if (++count > 250) | ||
1367 | break; | ||
1368 | } | ||
1369 | if (count > 250) | ||
1370 | dev_err(hsotg->dev, | ||
1371 | "Connection id status change timed out\n"); | ||
1372 | hsotg->op_state = OTG_STATE_A_HOST; | ||
1373 | |||
1374 | /* Initialize the Core for Host mode */ | ||
1375 | dwc2_core_init(hsotg, false, -1); | ||
1376 | dwc2_enable_global_interrupts(hsotg); | ||
1377 | dwc2_hcd_start(hsotg); | ||
1378 | } | ||
1379 | } | ||
1380 | |||
1381 | static void dwc2_wakeup_detected(unsigned long data) | ||
1382 | { | ||
1383 | struct dwc2_hsotg *hsotg = (struct dwc2_hsotg *)data; | ||
1384 | u32 hprt0; | ||
1385 | |||
1386 | dev_dbg(hsotg->dev, "%s()\n", __func__); | ||
1387 | |||
1388 | /* | ||
1389 | * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms | ||
1390 | * so that OPT tests pass with all PHYs.) | ||
1391 | */ | ||
1392 | hprt0 = dwc2_read_hprt0(hsotg); | ||
1393 | dev_dbg(hsotg->dev, "Resume: HPRT0=%0x\n", hprt0); | ||
1394 | hprt0 &= ~HPRT0_RES; | ||
1395 | writel(hprt0, hsotg->regs + HPRT0); | ||
1396 | dev_dbg(hsotg->dev, "Clear Resume: HPRT0=%0x\n", | ||
1397 | readl(hsotg->regs + HPRT0)); | ||
1398 | |||
1399 | dwc2_hcd_rem_wakeup(hsotg); | ||
1400 | |||
1401 | /* Change to L0 state */ | ||
1402 | hsotg->lx_state = DWC2_L0; | ||
1403 | } | ||
1404 | |||
1405 | static int dwc2_host_is_b_hnp_enabled(struct dwc2_hsotg *hsotg) | ||
1406 | { | ||
1407 | struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg); | ||
1408 | |||
1409 | return hcd->self.b_hnp_enable; | ||
1410 | } | ||
1411 | |||
1412 | /* Must NOT be called with interrupt disabled or spinlock held */ | ||
1413 | static void dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex) | ||
1414 | { | ||
1415 | unsigned long flags; | ||
1416 | u32 hprt0; | ||
1417 | u32 pcgctl; | ||
1418 | u32 gotgctl; | ||
1419 | |||
1420 | dev_dbg(hsotg->dev, "%s()\n", __func__); | ||
1421 | |||
1422 | spin_lock_irqsave(&hsotg->lock, flags); | ||
1423 | |||
1424 | if (windex == hsotg->otg_port && dwc2_host_is_b_hnp_enabled(hsotg)) { | ||
1425 | gotgctl = readl(hsotg->regs + GOTGCTL); | ||
1426 | gotgctl |= GOTGCTL_HSTSETHNPEN; | ||
1427 | writel(gotgctl, hsotg->regs + GOTGCTL); | ||
1428 | hsotg->op_state = OTG_STATE_A_SUSPEND; | ||
1429 | } | ||
1430 | |||
1431 | hprt0 = dwc2_read_hprt0(hsotg); | ||
1432 | hprt0 |= HPRT0_SUSP; | ||
1433 | writel(hprt0, hsotg->regs + HPRT0); | ||
1434 | |||
1435 | /* Update lx_state */ | ||
1436 | hsotg->lx_state = DWC2_L2; | ||
1437 | |||
1438 | /* Suspend the Phy Clock */ | ||
1439 | pcgctl = readl(hsotg->regs + PCGCTL); | ||
1440 | pcgctl |= PCGCTL_STOPPCLK; | ||
1441 | writel(pcgctl, hsotg->regs + PCGCTL); | ||
1442 | udelay(10); | ||
1443 | |||
1444 | /* For HNP the bus must be suspended for at least 200ms */ | ||
1445 | if (dwc2_host_is_b_hnp_enabled(hsotg)) { | ||
1446 | pcgctl = readl(hsotg->regs + PCGCTL); | ||
1447 | pcgctl &= ~PCGCTL_STOPPCLK; | ||
1448 | writel(pcgctl, hsotg->regs + PCGCTL); | ||
1449 | |||
1450 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
1451 | |||
1452 | usleep_range(200000, 250000); | ||
1453 | } else { | ||
1454 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
1455 | } | ||
1456 | } | ||
1457 | |||
1458 | /* Handles hub class-specific requests */ | ||
1459 | static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, | ||
1460 | u16 wvalue, u16 windex, char *buf, u16 wlength) | ||
1461 | { | ||
1462 | struct usb_hub_descriptor *hub_desc; | ||
1463 | int retval = 0; | ||
1464 | u32 hprt0; | ||
1465 | u32 port_status; | ||
1466 | u32 speed; | ||
1467 | u32 pcgctl; | ||
1468 | |||
1469 | switch (typereq) { | ||
1470 | case ClearHubFeature: | ||
1471 | dev_dbg(hsotg->dev, "ClearHubFeature %1xh\n", wvalue); | ||
1472 | |||
1473 | switch (wvalue) { | ||
1474 | case C_HUB_LOCAL_POWER: | ||
1475 | case C_HUB_OVER_CURRENT: | ||
1476 | /* Nothing required here */ | ||
1477 | break; | ||
1478 | |||
1479 | default: | ||
1480 | retval = -EINVAL; | ||
1481 | dev_err(hsotg->dev, | ||
1482 | "ClearHubFeature request %1xh unknown\n", | ||
1483 | wvalue); | ||
1484 | } | ||
1485 | break; | ||
1486 | |||
1487 | case ClearPortFeature: | ||
1488 | if (wvalue != USB_PORT_FEAT_L1) | ||
1489 | if (!windex || windex > 1) | ||
1490 | goto error; | ||
1491 | switch (wvalue) { | ||
1492 | case USB_PORT_FEAT_ENABLE: | ||
1493 | dev_dbg(hsotg->dev, | ||
1494 | "ClearPortFeature USB_PORT_FEAT_ENABLE\n"); | ||
1495 | hprt0 = dwc2_read_hprt0(hsotg); | ||
1496 | hprt0 |= HPRT0_ENA; | ||
1497 | writel(hprt0, hsotg->regs + HPRT0); | ||
1498 | break; | ||
1499 | |||
1500 | case USB_PORT_FEAT_SUSPEND: | ||
1501 | dev_dbg(hsotg->dev, | ||
1502 | "ClearPortFeature USB_PORT_FEAT_SUSPEND\n"); | ||
1503 | writel(0, hsotg->regs + PCGCTL); | ||
1504 | usleep_range(20000, 40000); | ||
1505 | |||
1506 | hprt0 = dwc2_read_hprt0(hsotg); | ||
1507 | hprt0 |= HPRT0_RES; | ||
1508 | writel(hprt0, hsotg->regs + HPRT0); | ||
1509 | hprt0 &= ~HPRT0_SUSP; | ||
1510 | usleep_range(100000, 150000); | ||
1511 | |||
1512 | hprt0 &= ~HPRT0_RES; | ||
1513 | writel(hprt0, hsotg->regs + HPRT0); | ||
1514 | break; | ||
1515 | |||
1516 | case USB_PORT_FEAT_POWER: | ||
1517 | dev_dbg(hsotg->dev, | ||
1518 | "ClearPortFeature USB_PORT_FEAT_POWER\n"); | ||
1519 | hprt0 = dwc2_read_hprt0(hsotg); | ||
1520 | hprt0 &= ~HPRT0_PWR; | ||
1521 | writel(hprt0, hsotg->regs + HPRT0); | ||
1522 | break; | ||
1523 | |||
1524 | case USB_PORT_FEAT_INDICATOR: | ||
1525 | dev_dbg(hsotg->dev, | ||
1526 | "ClearPortFeature USB_PORT_FEAT_INDICATOR\n"); | ||
1527 | /* Port indicator not supported */ | ||
1528 | break; | ||
1529 | |||
1530 | case USB_PORT_FEAT_C_CONNECTION: | ||
1531 | /* | ||
1532 | * Clears driver's internal Connect Status Change flag | ||
1533 | */ | ||
1534 | dev_dbg(hsotg->dev, | ||
1535 | "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n"); | ||
1536 | hsotg->flags.b.port_connect_status_change = 0; | ||
1537 | break; | ||
1538 | |||
1539 | case USB_PORT_FEAT_C_RESET: | ||
1540 | /* Clears driver's internal Port Reset Change flag */ | ||
1541 | dev_dbg(hsotg->dev, | ||
1542 | "ClearPortFeature USB_PORT_FEAT_C_RESET\n"); | ||
1543 | hsotg->flags.b.port_reset_change = 0; | ||
1544 | break; | ||
1545 | |||
1546 | case USB_PORT_FEAT_C_ENABLE: | ||
1547 | /* | ||
1548 | * Clears the driver's internal Port Enable/Disable | ||
1549 | * Change flag | ||
1550 | */ | ||
1551 | dev_dbg(hsotg->dev, | ||
1552 | "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n"); | ||
1553 | hsotg->flags.b.port_enable_change = 0; | ||
1554 | break; | ||
1555 | |||
1556 | case USB_PORT_FEAT_C_SUSPEND: | ||
1557 | /* | ||
1558 | * Clears the driver's internal Port Suspend Change | ||
1559 | * flag, which is set when resume signaling on the host | ||
1560 | * port is complete | ||
1561 | */ | ||
1562 | dev_dbg(hsotg->dev, | ||
1563 | "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n"); | ||
1564 | hsotg->flags.b.port_suspend_change = 0; | ||
1565 | break; | ||
1566 | |||
1567 | case USB_PORT_FEAT_C_PORT_L1: | ||
1568 | dev_dbg(hsotg->dev, | ||
1569 | "ClearPortFeature USB_PORT_FEAT_C_PORT_L1\n"); | ||
1570 | hsotg->flags.b.port_l1_change = 0; | ||
1571 | break; | ||
1572 | |||
1573 | case USB_PORT_FEAT_C_OVER_CURRENT: | ||
1574 | dev_dbg(hsotg->dev, | ||
1575 | "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n"); | ||
1576 | hsotg->flags.b.port_over_current_change = 0; | ||
1577 | break; | ||
1578 | |||
1579 | default: | ||
1580 | retval = -EINVAL; | ||
1581 | dev_err(hsotg->dev, | ||
1582 | "ClearPortFeature request %1xh unknown or unsupported\n", | ||
1583 | wvalue); | ||
1584 | } | ||
1585 | break; | ||
1586 | |||
1587 | case GetHubDescriptor: | ||
1588 | dev_dbg(hsotg->dev, "GetHubDescriptor\n"); | ||
1589 | hub_desc = (struct usb_hub_descriptor *)buf; | ||
1590 | hub_desc->bDescLength = 9; | ||
1591 | hub_desc->bDescriptorType = 0x29; | ||
1592 | hub_desc->bNbrPorts = 1; | ||
1593 | hub_desc->wHubCharacteristics = cpu_to_le16(0x08); | ||
1594 | hub_desc->bPwrOn2PwrGood = 1; | ||
1595 | hub_desc->bHubContrCurrent = 0; | ||
1596 | hub_desc->u.hs.DeviceRemovable[0] = 0; | ||
1597 | hub_desc->u.hs.DeviceRemovable[1] = 0xff; | ||
1598 | break; | ||
1599 | |||
1600 | case GetHubStatus: | ||
1601 | dev_dbg(hsotg->dev, "GetHubStatus\n"); | ||
1602 | memset(buf, 0, 4); | ||
1603 | break; | ||
1604 | |||
1605 | case GetPortStatus: | ||
1606 | dev_vdbg(hsotg->dev, | ||
1607 | "GetPortStatus wIndex=0x%04x flags=0x%08x\n", windex, | ||
1608 | hsotg->flags.d32); | ||
1609 | if (!windex || windex > 1) | ||
1610 | goto error; | ||
1611 | |||
1612 | port_status = 0; | ||
1613 | if (hsotg->flags.b.port_connect_status_change) | ||
1614 | port_status |= USB_PORT_STAT_C_CONNECTION << 16; | ||
1615 | if (hsotg->flags.b.port_enable_change) | ||
1616 | port_status |= USB_PORT_STAT_C_ENABLE << 16; | ||
1617 | if (hsotg->flags.b.port_suspend_change) | ||
1618 | port_status |= USB_PORT_STAT_C_SUSPEND << 16; | ||
1619 | if (hsotg->flags.b.port_l1_change) | ||
1620 | port_status |= USB_PORT_STAT_C_L1 << 16; | ||
1621 | if (hsotg->flags.b.port_reset_change) | ||
1622 | port_status |= USB_PORT_STAT_C_RESET << 16; | ||
1623 | if (hsotg->flags.b.port_over_current_change) { | ||
1624 | dev_warn(hsotg->dev, "Overcurrent change detected\n"); | ||
1625 | port_status |= USB_PORT_STAT_C_OVERCURRENT << 16; | ||
1626 | } | ||
1627 | |||
1628 | if (!hsotg->flags.b.port_connect_status) { | ||
1629 | /* | ||
1630 | * The port is disconnected, which means the core is | ||
1631 | * either in device mode or it soon will be. Just | ||
1632 | * return 0's for the remainder of the port status | ||
1633 | * since the port register can't be read if the core | ||
1634 | * is in device mode. | ||
1635 | */ | ||
1636 | *(__le32 *)buf = cpu_to_le32(port_status); | ||
1637 | break; | ||
1638 | } | ||
1639 | |||
1640 | hprt0 = readl(hsotg->regs + HPRT0); | ||
1641 | dev_vdbg(hsotg->dev, " HPRT0: 0x%08x\n", hprt0); | ||
1642 | |||
1643 | if (hprt0 & HPRT0_CONNSTS) | ||
1644 | port_status |= USB_PORT_STAT_CONNECTION; | ||
1645 | if (hprt0 & HPRT0_ENA) | ||
1646 | port_status |= USB_PORT_STAT_ENABLE; | ||
1647 | if (hprt0 & HPRT0_SUSP) | ||
1648 | port_status |= USB_PORT_STAT_SUSPEND; | ||
1649 | if (hprt0 & HPRT0_OVRCURRACT) | ||
1650 | port_status |= USB_PORT_STAT_OVERCURRENT; | ||
1651 | if (hprt0 & HPRT0_RST) | ||
1652 | port_status |= USB_PORT_STAT_RESET; | ||
1653 | if (hprt0 & HPRT0_PWR) | ||
1654 | port_status |= USB_PORT_STAT_POWER; | ||
1655 | |||
1656 | speed = (hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT; | ||
1657 | if (speed == HPRT0_SPD_HIGH_SPEED) | ||
1658 | port_status |= USB_PORT_STAT_HIGH_SPEED; | ||
1659 | else if (speed == HPRT0_SPD_LOW_SPEED) | ||
1660 | port_status |= USB_PORT_STAT_LOW_SPEED; | ||
1661 | |||
1662 | if (hprt0 & HPRT0_TSTCTL_MASK) | ||
1663 | port_status |= USB_PORT_STAT_TEST; | ||
1664 | /* USB_PORT_FEAT_INDICATOR unsupported always 0 */ | ||
1665 | |||
1666 | dev_vdbg(hsotg->dev, "port_status=%08x\n", port_status); | ||
1667 | *(__le32 *)buf = cpu_to_le32(port_status); | ||
1668 | break; | ||
1669 | |||
1670 | case SetHubFeature: | ||
1671 | dev_dbg(hsotg->dev, "SetHubFeature\n"); | ||
1672 | /* No HUB features supported */ | ||
1673 | break; | ||
1674 | |||
1675 | case SetPortFeature: | ||
1676 | dev_dbg(hsotg->dev, "SetPortFeature\n"); | ||
1677 | if (wvalue != USB_PORT_FEAT_TEST && (!windex || windex > 1)) | ||
1678 | goto error; | ||
1679 | |||
1680 | if (!hsotg->flags.b.port_connect_status) { | ||
1681 | /* | ||
1682 | * The port is disconnected, which means the core is | ||
1683 | * either in device mode or it soon will be. Just | ||
1684 | * return without doing anything since the port | ||
1685 | * register can't be written if the core is in device | ||
1686 | * mode. | ||
1687 | */ | ||
1688 | break; | ||
1689 | } | ||
1690 | |||
1691 | switch (wvalue) { | ||
1692 | case USB_PORT_FEAT_SUSPEND: | ||
1693 | dev_dbg(hsotg->dev, | ||
1694 | "SetPortFeature - USB_PORT_FEAT_SUSPEND\n"); | ||
1695 | if (windex != hsotg->otg_port) | ||
1696 | goto error; | ||
1697 | dwc2_port_suspend(hsotg, windex); | ||
1698 | break; | ||
1699 | |||
1700 | case USB_PORT_FEAT_POWER: | ||
1701 | dev_dbg(hsotg->dev, | ||
1702 | "SetPortFeature - USB_PORT_FEAT_POWER\n"); | ||
1703 | hprt0 = dwc2_read_hprt0(hsotg); | ||
1704 | hprt0 |= HPRT0_PWR; | ||
1705 | writel(hprt0, hsotg->regs + HPRT0); | ||
1706 | break; | ||
1707 | |||
1708 | case USB_PORT_FEAT_RESET: | ||
1709 | hprt0 = dwc2_read_hprt0(hsotg); | ||
1710 | dev_dbg(hsotg->dev, | ||
1711 | "SetPortFeature - USB_PORT_FEAT_RESET\n"); | ||
1712 | pcgctl = readl(hsotg->regs + PCGCTL); | ||
1713 | pcgctl &= ~(PCGCTL_ENBL_SLEEP_GATING | PCGCTL_STOPPCLK); | ||
1714 | writel(pcgctl, hsotg->regs + PCGCTL); | ||
1715 | /* ??? Original driver does this */ | ||
1716 | writel(0, hsotg->regs + PCGCTL); | ||
1717 | |||
1718 | hprt0 = dwc2_read_hprt0(hsotg); | ||
1719 | /* Clear suspend bit if resetting from suspend state */ | ||
1720 | hprt0 &= ~HPRT0_SUSP; | ||
1721 | |||
1722 | /* | ||
1723 | * When B-Host the Port reset bit is set in the Start | ||
1724 | * HCD Callback function, so that the reset is started | ||
1725 | * within 1ms of the HNP success interrupt | ||
1726 | */ | ||
1727 | if (!dwc2_hcd_is_b_host(hsotg)) { | ||
1728 | hprt0 |= HPRT0_PWR | HPRT0_RST; | ||
1729 | dev_dbg(hsotg->dev, | ||
1730 | "In host mode, hprt0=%08x\n", hprt0); | ||
1731 | writel(hprt0, hsotg->regs + HPRT0); | ||
1732 | } | ||
1733 | |||
1734 | /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */ | ||
1735 | usleep_range(50000, 70000); | ||
1736 | hprt0 &= ~HPRT0_RST; | ||
1737 | writel(hprt0, hsotg->regs + HPRT0); | ||
1738 | hsotg->lx_state = DWC2_L0; /* Now back to On state */ | ||
1739 | break; | ||
1740 | |||
1741 | case USB_PORT_FEAT_INDICATOR: | ||
1742 | dev_dbg(hsotg->dev, | ||
1743 | "SetPortFeature - USB_PORT_FEAT_INDICATOR\n"); | ||
1744 | /* Not supported */ | ||
1745 | break; | ||
1746 | |||
1747 | default: | ||
1748 | retval = -EINVAL; | ||
1749 | dev_err(hsotg->dev, | ||
1750 | "SetPortFeature %1xh unknown or unsupported\n", | ||
1751 | wvalue); | ||
1752 | break; | ||
1753 | } | ||
1754 | break; | ||
1755 | |||
1756 | default: | ||
1757 | error: | ||
1758 | retval = -EINVAL; | ||
1759 | dev_dbg(hsotg->dev, | ||
1760 | "Unknown hub control request: %1xh wIndex: %1xh wValue: %1xh\n", | ||
1761 | typereq, windex, wvalue); | ||
1762 | break; | ||
1763 | } | ||
1764 | |||
1765 | return retval; | ||
1766 | } | ||
1767 | |||
1768 | static int dwc2_hcd_is_status_changed(struct dwc2_hsotg *hsotg, int port) | ||
1769 | { | ||
1770 | int retval; | ||
1771 | |||
1772 | if (port != 1) | ||
1773 | return -EINVAL; | ||
1774 | |||
1775 | retval = (hsotg->flags.b.port_connect_status_change || | ||
1776 | hsotg->flags.b.port_reset_change || | ||
1777 | hsotg->flags.b.port_enable_change || | ||
1778 | hsotg->flags.b.port_suspend_change || | ||
1779 | hsotg->flags.b.port_over_current_change); | ||
1780 | |||
1781 | if (retval) { | ||
1782 | dev_dbg(hsotg->dev, | ||
1783 | "DWC OTG HCD HUB STATUS DATA: Root port status changed\n"); | ||
1784 | dev_dbg(hsotg->dev, " port_connect_status_change: %d\n", | ||
1785 | hsotg->flags.b.port_connect_status_change); | ||
1786 | dev_dbg(hsotg->dev, " port_reset_change: %d\n", | ||
1787 | hsotg->flags.b.port_reset_change); | ||
1788 | dev_dbg(hsotg->dev, " port_enable_change: %d\n", | ||
1789 | hsotg->flags.b.port_enable_change); | ||
1790 | dev_dbg(hsotg->dev, " port_suspend_change: %d\n", | ||
1791 | hsotg->flags.b.port_suspend_change); | ||
1792 | dev_dbg(hsotg->dev, " port_over_current_change: %d\n", | ||
1793 | hsotg->flags.b.port_over_current_change); | ||
1794 | } | ||
1795 | |||
1796 | return retval; | ||
1797 | } | ||
1798 | |||
1799 | int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) | ||
1800 | { | ||
1801 | u32 hfnum = readl(hsotg->regs + HFNUM); | ||
1802 | |||
1803 | #ifdef DWC2_DEBUG_SOF | ||
1804 | dev_vdbg(hsotg->dev, "DWC OTG HCD GET FRAME NUMBER %d\n", | ||
1805 | (hfnum & HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT); | ||
1806 | #endif | ||
1807 | return (hfnum & HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT; | ||
1808 | } | ||
1809 | |||
1810 | int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg) | ||
1811 | { | ||
1812 | return hsotg->op_state == OTG_STATE_B_HOST; | ||
1813 | } | ||
1814 | |||
1815 | static struct dwc2_hcd_urb *dwc2_hcd_urb_alloc(struct dwc2_hsotg *hsotg, | ||
1816 | int iso_desc_count, | ||
1817 | gfp_t mem_flags) | ||
1818 | { | ||
1819 | struct dwc2_hcd_urb *urb; | ||
1820 | u32 size = sizeof(*urb) + iso_desc_count * | ||
1821 | sizeof(struct dwc2_hcd_iso_packet_desc); | ||
1822 | |||
1823 | urb = kzalloc(size, mem_flags); | ||
1824 | if (urb) | ||
1825 | urb->packet_count = iso_desc_count; | ||
1826 | return urb; | ||
1827 | } | ||
1828 | |||
1829 | static void dwc2_hcd_urb_set_pipeinfo(struct dwc2_hsotg *hsotg, | ||
1830 | struct dwc2_hcd_urb *urb, u8 dev_addr, | ||
1831 | u8 ep_num, u8 ep_type, u8 ep_dir, u16 mps) | ||
1832 | { | ||
1833 | if (dbg_perio() || | ||
1834 | ep_type == USB_ENDPOINT_XFER_BULK || | ||
1835 | ep_type == USB_ENDPOINT_XFER_CONTROL) | ||
1836 | dev_vdbg(hsotg->dev, | ||
1837 | "addr=%d, ep_num=%d, ep_dir=%1x, ep_type=%1x, mps=%d\n", | ||
1838 | dev_addr, ep_num, ep_dir, ep_type, mps); | ||
1839 | urb->pipe_info.dev_addr = dev_addr; | ||
1840 | urb->pipe_info.ep_num = ep_num; | ||
1841 | urb->pipe_info.pipe_type = ep_type; | ||
1842 | urb->pipe_info.pipe_dir = ep_dir; | ||
1843 | urb->pipe_info.mps = mps; | ||
1844 | } | ||
1845 | |||
1846 | /* | ||
1847 | * NOTE: This function will be removed once the peripheral controller code | ||
1848 | * is integrated and the driver is stable | ||
1849 | */ | ||
1850 | void dwc2_hcd_dump_state(struct dwc2_hsotg *hsotg) | ||
1851 | { | ||
1852 | #ifdef DEBUG | ||
1853 | struct dwc2_host_chan *chan; | ||
1854 | struct dwc2_hcd_urb *urb; | ||
1855 | struct dwc2_qtd *qtd; | ||
1856 | int num_channels; | ||
1857 | u32 np_tx_status; | ||
1858 | u32 p_tx_status; | ||
1859 | int i; | ||
1860 | |||
1861 | num_channels = hsotg->core_params->host_channels; | ||
1862 | dev_dbg(hsotg->dev, "\n"); | ||
1863 | dev_dbg(hsotg->dev, | ||
1864 | "************************************************************\n"); | ||
1865 | dev_dbg(hsotg->dev, "HCD State:\n"); | ||
1866 | dev_dbg(hsotg->dev, " Num channels: %d\n", num_channels); | ||
1867 | |||
1868 | for (i = 0; i < num_channels; i++) { | ||
1869 | chan = hsotg->hc_ptr_array[i]; | ||
1870 | dev_dbg(hsotg->dev, " Channel %d:\n", i); | ||
1871 | dev_dbg(hsotg->dev, | ||
1872 | " dev_addr: %d, ep_num: %d, ep_is_in: %d\n", | ||
1873 | chan->dev_addr, chan->ep_num, chan->ep_is_in); | ||
1874 | dev_dbg(hsotg->dev, " speed: %d\n", chan->speed); | ||
1875 | dev_dbg(hsotg->dev, " ep_type: %d\n", chan->ep_type); | ||
1876 | dev_dbg(hsotg->dev, " max_packet: %d\n", chan->max_packet); | ||
1877 | dev_dbg(hsotg->dev, " data_pid_start: %d\n", | ||
1878 | chan->data_pid_start); | ||
1879 | dev_dbg(hsotg->dev, " multi_count: %d\n", chan->multi_count); | ||
1880 | dev_dbg(hsotg->dev, " xfer_started: %d\n", | ||
1881 | chan->xfer_started); | ||
1882 | dev_dbg(hsotg->dev, " xfer_buf: %p\n", chan->xfer_buf); | ||
1883 | dev_dbg(hsotg->dev, " xfer_dma: %08lx\n", | ||
1884 | (unsigned long)chan->xfer_dma); | ||
1885 | dev_dbg(hsotg->dev, " xfer_len: %d\n", chan->xfer_len); | ||
1886 | dev_dbg(hsotg->dev, " xfer_count: %d\n", chan->xfer_count); | ||
1887 | dev_dbg(hsotg->dev, " halt_on_queue: %d\n", | ||
1888 | chan->halt_on_queue); | ||
1889 | dev_dbg(hsotg->dev, " halt_pending: %d\n", | ||
1890 | chan->halt_pending); | ||
1891 | dev_dbg(hsotg->dev, " halt_status: %d\n", chan->halt_status); | ||
1892 | dev_dbg(hsotg->dev, " do_split: %d\n", chan->do_split); | ||
1893 | dev_dbg(hsotg->dev, " complete_split: %d\n", | ||
1894 | chan->complete_split); | ||
1895 | dev_dbg(hsotg->dev, " hub_addr: %d\n", chan->hub_addr); | ||
1896 | dev_dbg(hsotg->dev, " hub_port: %d\n", chan->hub_port); | ||
1897 | dev_dbg(hsotg->dev, " xact_pos: %d\n", chan->xact_pos); | ||
1898 | dev_dbg(hsotg->dev, " requests: %d\n", chan->requests); | ||
1899 | dev_dbg(hsotg->dev, " qh: %p\n", chan->qh); | ||
1900 | |||
1901 | if (chan->xfer_started) { | ||
1902 | u32 hfnum, hcchar, hctsiz, hcint, hcintmsk; | ||
1903 | |||
1904 | hfnum = readl(hsotg->regs + HFNUM); | ||
1905 | hcchar = readl(hsotg->regs + HCCHAR(i)); | ||
1906 | hctsiz = readl(hsotg->regs + HCTSIZ(i)); | ||
1907 | hcint = readl(hsotg->regs + HCINT(i)); | ||
1908 | hcintmsk = readl(hsotg->regs + HCINTMSK(i)); | ||
1909 | dev_dbg(hsotg->dev, " hfnum: 0x%08x\n", hfnum); | ||
1910 | dev_dbg(hsotg->dev, " hcchar: 0x%08x\n", hcchar); | ||
1911 | dev_dbg(hsotg->dev, " hctsiz: 0x%08x\n", hctsiz); | ||
1912 | dev_dbg(hsotg->dev, " hcint: 0x%08x\n", hcint); | ||
1913 | dev_dbg(hsotg->dev, " hcintmsk: 0x%08x\n", hcintmsk); | ||
1914 | } | ||
1915 | |||
1916 | if (!(chan->xfer_started && chan->qh)) | ||
1917 | continue; | ||
1918 | |||
1919 | list_for_each_entry(qtd, &chan->qh->qtd_list, qtd_list_entry) { | ||
1920 | if (!qtd->in_process) | ||
1921 | break; | ||
1922 | urb = qtd->urb; | ||
1923 | dev_dbg(hsotg->dev, " URB Info:\n"); | ||
1924 | dev_dbg(hsotg->dev, " qtd: %p, urb: %p\n", | ||
1925 | qtd, urb); | ||
1926 | if (urb) { | ||
1927 | dev_dbg(hsotg->dev, | ||
1928 | " Dev: %d, EP: %d %s\n", | ||
1929 | dwc2_hcd_get_dev_addr(&urb->pipe_info), | ||
1930 | dwc2_hcd_get_ep_num(&urb->pipe_info), | ||
1931 | dwc2_hcd_is_pipe_in(&urb->pipe_info) ? | ||
1932 | "IN" : "OUT"); | ||
1933 | dev_dbg(hsotg->dev, | ||
1934 | " Max packet size: %d\n", | ||
1935 | dwc2_hcd_get_mps(&urb->pipe_info)); | ||
1936 | dev_dbg(hsotg->dev, | ||
1937 | " transfer_buffer: %p\n", | ||
1938 | urb->buf); | ||
1939 | dev_dbg(hsotg->dev, | ||
1940 | " transfer_dma: %08lx\n", | ||
1941 | (unsigned long)urb->dma); | ||
1942 | dev_dbg(hsotg->dev, | ||
1943 | " transfer_buffer_length: %d\n", | ||
1944 | urb->length); | ||
1945 | dev_dbg(hsotg->dev, " actual_length: %d\n", | ||
1946 | urb->actual_length); | ||
1947 | } | ||
1948 | } | ||
1949 | } | ||
1950 | |||
1951 | dev_dbg(hsotg->dev, " non_periodic_channels: %d\n", | ||
1952 | hsotg->non_periodic_channels); | ||
1953 | dev_dbg(hsotg->dev, " periodic_channels: %d\n", | ||
1954 | hsotg->periodic_channels); | ||
1955 | dev_dbg(hsotg->dev, " periodic_usecs: %d\n", hsotg->periodic_usecs); | ||
1956 | np_tx_status = readl(hsotg->regs + GNPTXSTS); | ||
1957 | dev_dbg(hsotg->dev, " NP Tx Req Queue Space Avail: %d\n", | ||
1958 | (np_tx_status & TXSTS_QSPCAVAIL_MASK) >> TXSTS_QSPCAVAIL_SHIFT); | ||
1959 | dev_dbg(hsotg->dev, " NP Tx FIFO Space Avail: %d\n", | ||
1960 | (np_tx_status & TXSTS_FSPCAVAIL_MASK) >> TXSTS_FSPCAVAIL_SHIFT); | ||
1961 | p_tx_status = readl(hsotg->regs + HPTXSTS); | ||
1962 | dev_dbg(hsotg->dev, " P Tx Req Queue Space Avail: %d\n", | ||
1963 | (p_tx_status & TXSTS_QSPCAVAIL_MASK) >> TXSTS_QSPCAVAIL_SHIFT); | ||
1964 | dev_dbg(hsotg->dev, " P Tx FIFO Space Avail: %d\n", | ||
1965 | (p_tx_status & TXSTS_FSPCAVAIL_MASK) >> TXSTS_FSPCAVAIL_SHIFT); | ||
1966 | dwc2_hcd_dump_frrem(hsotg); | ||
1967 | dwc2_dump_global_registers(hsotg); | ||
1968 | dwc2_dump_host_registers(hsotg); | ||
1969 | dev_dbg(hsotg->dev, | ||
1970 | "************************************************************\n"); | ||
1971 | dev_dbg(hsotg->dev, "\n"); | ||
1972 | #endif | ||
1973 | } | ||
1974 | |||
1975 | /* | ||
1976 | * NOTE: This function will be removed once the peripheral controller code | ||
1977 | * is integrated and the driver is stable | ||
1978 | */ | ||
1979 | void dwc2_hcd_dump_frrem(struct dwc2_hsotg *hsotg) | ||
1980 | { | ||
1981 | #ifdef DWC2_DUMP_FRREM | ||
1982 | dev_dbg(hsotg->dev, "Frame remaining at SOF:\n"); | ||
1983 | dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n", | ||
1984 | hsotg->frrem_samples, hsotg->frrem_accum, | ||
1985 | hsotg->frrem_samples > 0 ? | ||
1986 | hsotg->frrem_accum / hsotg->frrem_samples : 0); | ||
1987 | dev_dbg(hsotg->dev, "\n"); | ||
1988 | dev_dbg(hsotg->dev, "Frame remaining at start_transfer (uframe 7):\n"); | ||
1989 | dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n", | ||
1990 | hsotg->hfnum_7_samples, | ||
1991 | hsotg->hfnum_7_frrem_accum, | ||
1992 | hsotg->hfnum_7_samples > 0 ? | ||
1993 | hsotg->hfnum_7_frrem_accum / hsotg->hfnum_7_samples : 0); | ||
1994 | dev_dbg(hsotg->dev, "Frame remaining at start_transfer (uframe 0):\n"); | ||
1995 | dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n", | ||
1996 | hsotg->hfnum_0_samples, | ||
1997 | hsotg->hfnum_0_frrem_accum, | ||
1998 | hsotg->hfnum_0_samples > 0 ? | ||
1999 | hsotg->hfnum_0_frrem_accum / hsotg->hfnum_0_samples : 0); | ||
2000 | dev_dbg(hsotg->dev, "Frame remaining at start_transfer (uframe 1-6):\n"); | ||
2001 | dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n", | ||
2002 | hsotg->hfnum_other_samples, | ||
2003 | hsotg->hfnum_other_frrem_accum, | ||
2004 | hsotg->hfnum_other_samples > 0 ? | ||
2005 | hsotg->hfnum_other_frrem_accum / hsotg->hfnum_other_samples : | ||
2006 | 0); | ||
2007 | dev_dbg(hsotg->dev, "\n"); | ||
2008 | dev_dbg(hsotg->dev, "Frame remaining at sample point A (uframe 7):\n"); | ||
2009 | dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n", | ||
2010 | hsotg->hfnum_7_samples_a, hsotg->hfnum_7_frrem_accum_a, | ||
2011 | hsotg->hfnum_7_samples_a > 0 ? | ||
2012 | hsotg->hfnum_7_frrem_accum_a / hsotg->hfnum_7_samples_a : 0); | ||
2013 | dev_dbg(hsotg->dev, "Frame remaining at sample point A (uframe 0):\n"); | ||
2014 | dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n", | ||
2015 | hsotg->hfnum_0_samples_a, hsotg->hfnum_0_frrem_accum_a, | ||
2016 | hsotg->hfnum_0_samples_a > 0 ? | ||
2017 | hsotg->hfnum_0_frrem_accum_a / hsotg->hfnum_0_samples_a : 0); | ||
2018 | dev_dbg(hsotg->dev, "Frame remaining at sample point A (uframe 1-6):\n"); | ||
2019 | dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n", | ||
2020 | hsotg->hfnum_other_samples_a, hsotg->hfnum_other_frrem_accum_a, | ||
2021 | hsotg->hfnum_other_samples_a > 0 ? | ||
2022 | hsotg->hfnum_other_frrem_accum_a / hsotg->hfnum_other_samples_a | ||
2023 | : 0); | ||
2024 | dev_dbg(hsotg->dev, "\n"); | ||
2025 | dev_dbg(hsotg->dev, "Frame remaining at sample point B (uframe 7):\n"); | ||
2026 | dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n", | ||
2027 | hsotg->hfnum_7_samples_b, hsotg->hfnum_7_frrem_accum_b, | ||
2028 | hsotg->hfnum_7_samples_b > 0 ? | ||
2029 | hsotg->hfnum_7_frrem_accum_b / hsotg->hfnum_7_samples_b : 0); | ||
2030 | dev_dbg(hsotg->dev, "Frame remaining at sample point B (uframe 0):\n"); | ||
2031 | dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n", | ||
2032 | hsotg->hfnum_0_samples_b, hsotg->hfnum_0_frrem_accum_b, | ||
2033 | (hsotg->hfnum_0_samples_b > 0) ? | ||
2034 | hsotg->hfnum_0_frrem_accum_b / hsotg->hfnum_0_samples_b : 0); | ||
2035 | dev_dbg(hsotg->dev, "Frame remaining at sample point B (uframe 1-6):\n"); | ||
2036 | dev_dbg(hsotg->dev, " samples %u, accum %llu, avg %llu\n", | ||
2037 | hsotg->hfnum_other_samples_b, hsotg->hfnum_other_frrem_accum_b, | ||
2038 | (hsotg->hfnum_other_samples_b > 0) ? | ||
2039 | hsotg->hfnum_other_frrem_accum_b / hsotg->hfnum_other_samples_b | ||
2040 | : 0); | ||
2041 | #endif | ||
2042 | } | ||
2043 | |||
2044 | struct wrapper_priv_data { | ||
2045 | struct dwc2_hsotg *hsotg; | ||
2046 | }; | ||
2047 | |||
2048 | /* Gets the dwc2_hsotg from a usb_hcd */ | ||
2049 | static struct dwc2_hsotg *dwc2_hcd_to_hsotg(struct usb_hcd *hcd) | ||
2050 | { | ||
2051 | struct wrapper_priv_data *p; | ||
2052 | |||
2053 | p = (struct wrapper_priv_data *) &hcd->hcd_priv; | ||
2054 | return p->hsotg; | ||
2055 | } | ||
2056 | |||
2057 | static int _dwc2_hcd_start(struct usb_hcd *hcd); | ||
2058 | |||
2059 | void dwc2_host_start(struct dwc2_hsotg *hsotg) | ||
2060 | { | ||
2061 | struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg); | ||
2062 | |||
2063 | hcd->self.is_b_host = dwc2_hcd_is_b_host(hsotg); | ||
2064 | _dwc2_hcd_start(hcd); | ||
2065 | } | ||
2066 | |||
2067 | void dwc2_host_disconnect(struct dwc2_hsotg *hsotg) | ||
2068 | { | ||
2069 | struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg); | ||
2070 | |||
2071 | hcd->self.is_b_host = 0; | ||
2072 | } | ||
2073 | |||
2074 | void dwc2_host_hub_info(struct dwc2_hsotg *hsotg, void *context, int *hub_addr, | ||
2075 | int *hub_port) | ||
2076 | { | ||
2077 | struct urb *urb = context; | ||
2078 | |||
2079 | if (urb->dev->tt) | ||
2080 | *hub_addr = urb->dev->tt->hub->devnum; | ||
2081 | else | ||
2082 | *hub_addr = 0; | ||
2083 | *hub_port = urb->dev->ttport; | ||
2084 | } | ||
2085 | |||
2086 | int dwc2_host_get_speed(struct dwc2_hsotg *hsotg, void *context) | ||
2087 | { | ||
2088 | struct urb *urb = context; | ||
2089 | |||
2090 | return urb->dev->speed; | ||
2091 | } | ||
2092 | |||
2093 | static void dwc2_allocate_bus_bandwidth(struct usb_hcd *hcd, u16 bw, | ||
2094 | struct urb *urb) | ||
2095 | { | ||
2096 | struct usb_bus *bus = hcd_to_bus(hcd); | ||
2097 | |||
2098 | if (urb->interval) | ||
2099 | bus->bandwidth_allocated += bw / urb->interval; | ||
2100 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) | ||
2101 | bus->bandwidth_isoc_reqs++; | ||
2102 | else | ||
2103 | bus->bandwidth_int_reqs++; | ||
2104 | } | ||
2105 | |||
2106 | static void dwc2_free_bus_bandwidth(struct usb_hcd *hcd, u16 bw, | ||
2107 | struct urb *urb) | ||
2108 | { | ||
2109 | struct usb_bus *bus = hcd_to_bus(hcd); | ||
2110 | |||
2111 | if (urb->interval) | ||
2112 | bus->bandwidth_allocated -= bw / urb->interval; | ||
2113 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) | ||
2114 | bus->bandwidth_isoc_reqs--; | ||
2115 | else | ||
2116 | bus->bandwidth_int_reqs--; | ||
2117 | } | ||
2118 | |||
2119 | /* | ||
2120 | * Sets the final status of an URB and returns it to the upper layer. Any | ||
2121 | * required cleanup of the URB is performed. | ||
2122 | * | ||
2123 | * Must be called with interrupt disabled and spinlock held | ||
2124 | */ | ||
2125 | void dwc2_host_complete(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, | ||
2126 | int status) | ||
2127 | { | ||
2128 | struct urb *urb; | ||
2129 | int i; | ||
2130 | |||
2131 | if (!qtd) { | ||
2132 | dev_dbg(hsotg->dev, "## %s: qtd is NULL ##\n", __func__); | ||
2133 | return; | ||
2134 | } | ||
2135 | |||
2136 | if (!qtd->urb) { | ||
2137 | dev_dbg(hsotg->dev, "## %s: qtd->urb is NULL ##\n", __func__); | ||
2138 | return; | ||
2139 | } | ||
2140 | |||
2141 | urb = qtd->urb->priv; | ||
2142 | if (!urb) { | ||
2143 | dev_dbg(hsotg->dev, "## %s: urb->priv is NULL ##\n", __func__); | ||
2144 | return; | ||
2145 | } | ||
2146 | |||
2147 | urb->actual_length = dwc2_hcd_urb_get_actual_length(qtd->urb); | ||
2148 | |||
2149 | if (dbg_urb(urb)) | ||
2150 | dev_vdbg(hsotg->dev, | ||
2151 | "%s: urb %p device %d ep %d-%s status %d actual %d\n", | ||
2152 | __func__, urb, usb_pipedevice(urb->pipe), | ||
2153 | usb_pipeendpoint(urb->pipe), | ||
2154 | usb_pipein(urb->pipe) ? "IN" : "OUT", status, | ||
2155 | urb->actual_length); | ||
2156 | |||
2157 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS && dbg_perio()) { | ||
2158 | for (i = 0; i < urb->number_of_packets; i++) | ||
2159 | dev_vdbg(hsotg->dev, " ISO Desc %d status %d\n", | ||
2160 | i, urb->iso_frame_desc[i].status); | ||
2161 | } | ||
2162 | |||
2163 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { | ||
2164 | urb->error_count = dwc2_hcd_urb_get_error_count(qtd->urb); | ||
2165 | for (i = 0; i < urb->number_of_packets; ++i) { | ||
2166 | urb->iso_frame_desc[i].actual_length = | ||
2167 | dwc2_hcd_urb_get_iso_desc_actual_length( | ||
2168 | qtd->urb, i); | ||
2169 | urb->iso_frame_desc[i].status = | ||
2170 | dwc2_hcd_urb_get_iso_desc_status(qtd->urb, i); | ||
2171 | } | ||
2172 | } | ||
2173 | |||
2174 | urb->status = status; | ||
2175 | if (!status) { | ||
2176 | if ((urb->transfer_flags & URB_SHORT_NOT_OK) && | ||
2177 | urb->actual_length < urb->transfer_buffer_length) | ||
2178 | urb->status = -EREMOTEIO; | ||
2179 | } | ||
2180 | |||
2181 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS || | ||
2182 | usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { | ||
2183 | struct usb_host_endpoint *ep = urb->ep; | ||
2184 | |||
2185 | if (ep) | ||
2186 | dwc2_free_bus_bandwidth(dwc2_hsotg_to_hcd(hsotg), | ||
2187 | dwc2_hcd_get_ep_bandwidth(hsotg, ep), | ||
2188 | urb); | ||
2189 | } | ||
2190 | |||
2191 | usb_hcd_unlink_urb_from_ep(dwc2_hsotg_to_hcd(hsotg), urb); | ||
2192 | urb->hcpriv = NULL; | ||
2193 | kfree(qtd->urb); | ||
2194 | qtd->urb = NULL; | ||
2195 | |||
2196 | spin_unlock(&hsotg->lock); | ||
2197 | usb_hcd_giveback_urb(dwc2_hsotg_to_hcd(hsotg), urb, status); | ||
2198 | spin_lock(&hsotg->lock); | ||
2199 | } | ||
2200 | |||
2201 | /* | ||
2202 | * Work queue function for starting the HCD when A-Cable is connected | ||
2203 | */ | ||
2204 | static void dwc2_hcd_start_func(struct work_struct *work) | ||
2205 | { | ||
2206 | struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, | ||
2207 | start_work.work); | ||
2208 | |||
2209 | dev_dbg(hsotg->dev, "%s() %p\n", __func__, hsotg); | ||
2210 | dwc2_host_start(hsotg); | ||
2211 | } | ||
2212 | |||
2213 | /* | ||
2214 | * Reset work queue function | ||
2215 | */ | ||
2216 | static void dwc2_hcd_reset_func(struct work_struct *work) | ||
2217 | { | ||
2218 | struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, | ||
2219 | reset_work.work); | ||
2220 | u32 hprt0; | ||
2221 | |||
2222 | dev_dbg(hsotg->dev, "USB RESET function called\n"); | ||
2223 | hprt0 = dwc2_read_hprt0(hsotg); | ||
2224 | hprt0 &= ~HPRT0_RST; | ||
2225 | writel(hprt0, hsotg->regs + HPRT0); | ||
2226 | hsotg->flags.b.port_reset_change = 1; | ||
2227 | } | ||
2228 | |||
2229 | /* | ||
2230 | * ========================================================================= | ||
2231 | * Linux HC Driver Functions | ||
2232 | * ========================================================================= | ||
2233 | */ | ||
2234 | |||
2235 | /* | ||
2236 | * Initializes the DWC_otg controller and its root hub and prepares it for host | ||
2237 | * mode operation. Activates the root port. Returns 0 on success and a negative | ||
2238 | * error code on failure. | ||
2239 | */ | ||
2240 | static int _dwc2_hcd_start(struct usb_hcd *hcd) | ||
2241 | { | ||
2242 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2243 | struct usb_bus *bus = hcd_to_bus(hcd); | ||
2244 | unsigned long flags; | ||
2245 | |||
2246 | dev_dbg(hsotg->dev, "DWC OTG HCD START\n"); | ||
2247 | |||
2248 | spin_lock_irqsave(&hsotg->lock, flags); | ||
2249 | |||
2250 | hcd->state = HC_STATE_RUNNING; | ||
2251 | |||
2252 | if (dwc2_is_device_mode(hsotg)) { | ||
2253 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
2254 | return 0; /* why 0 ?? */ | ||
2255 | } | ||
2256 | |||
2257 | dwc2_hcd_reinit(hsotg); | ||
2258 | |||
2259 | /* Initialize and connect root hub if one is not already attached */ | ||
2260 | if (bus->root_hub) { | ||
2261 | dev_dbg(hsotg->dev, "DWC OTG HCD Has Root Hub\n"); | ||
2262 | /* Inform the HUB driver to resume */ | ||
2263 | usb_hcd_resume_root_hub(hcd); | ||
2264 | } | ||
2265 | |||
2266 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
2267 | return 0; | ||
2268 | } | ||
2269 | |||
2270 | /* | ||
2271 | * Halts the DWC_otg host mode operations in a clean manner. USB transfers are | ||
2272 | * stopped. | ||
2273 | */ | ||
2274 | static void _dwc2_hcd_stop(struct usb_hcd *hcd) | ||
2275 | { | ||
2276 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2277 | unsigned long flags; | ||
2278 | |||
2279 | spin_lock_irqsave(&hsotg->lock, flags); | ||
2280 | dwc2_hcd_stop(hsotg); | ||
2281 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
2282 | |||
2283 | usleep_range(1000, 3000); | ||
2284 | } | ||
2285 | |||
2286 | /* Returns the current frame number */ | ||
2287 | static int _dwc2_hcd_get_frame_number(struct usb_hcd *hcd) | ||
2288 | { | ||
2289 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2290 | |||
2291 | return dwc2_hcd_get_frame_number(hsotg); | ||
2292 | } | ||
2293 | |||
2294 | static void dwc2_dump_urb_info(struct usb_hcd *hcd, struct urb *urb, | ||
2295 | char *fn_name) | ||
2296 | { | ||
2297 | #ifdef VERBOSE_DEBUG | ||
2298 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2299 | char *pipetype; | ||
2300 | char *speed; | ||
2301 | |||
2302 | dev_vdbg(hsotg->dev, "%s, urb %p\n", fn_name, urb); | ||
2303 | dev_vdbg(hsotg->dev, " Device address: %d\n", | ||
2304 | usb_pipedevice(urb->pipe)); | ||
2305 | dev_vdbg(hsotg->dev, " Endpoint: %d, %s\n", | ||
2306 | usb_pipeendpoint(urb->pipe), | ||
2307 | usb_pipein(urb->pipe) ? "IN" : "OUT"); | ||
2308 | |||
2309 | switch (usb_pipetype(urb->pipe)) { | ||
2310 | case PIPE_CONTROL: | ||
2311 | pipetype = "CONTROL"; | ||
2312 | break; | ||
2313 | case PIPE_BULK: | ||
2314 | pipetype = "BULK"; | ||
2315 | break; | ||
2316 | case PIPE_INTERRUPT: | ||
2317 | pipetype = "INTERRUPT"; | ||
2318 | break; | ||
2319 | case PIPE_ISOCHRONOUS: | ||
2320 | pipetype = "ISOCHRONOUS"; | ||
2321 | break; | ||
2322 | default: | ||
2323 | pipetype = "UNKNOWN"; | ||
2324 | break; | ||
2325 | } | ||
2326 | |||
2327 | dev_vdbg(hsotg->dev, " Endpoint type: %s %s (%s)\n", pipetype, | ||
2328 | usb_urb_dir_in(urb) ? "IN" : "OUT", usb_pipein(urb->pipe) ? | ||
2329 | "IN" : "OUT"); | ||
2330 | |||
2331 | switch (urb->dev->speed) { | ||
2332 | case USB_SPEED_HIGH: | ||
2333 | speed = "HIGH"; | ||
2334 | break; | ||
2335 | case USB_SPEED_FULL: | ||
2336 | speed = "FULL"; | ||
2337 | break; | ||
2338 | case USB_SPEED_LOW: | ||
2339 | speed = "LOW"; | ||
2340 | break; | ||
2341 | default: | ||
2342 | speed = "UNKNOWN"; | ||
2343 | break; | ||
2344 | } | ||
2345 | |||
2346 | dev_vdbg(hsotg->dev, " Speed: %s\n", speed); | ||
2347 | dev_vdbg(hsotg->dev, " Max packet size: %d\n", | ||
2348 | usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe))); | ||
2349 | dev_vdbg(hsotg->dev, " Data buffer length: %d\n", | ||
2350 | urb->transfer_buffer_length); | ||
2351 | dev_vdbg(hsotg->dev, " Transfer buffer: %p, Transfer DMA: %08lx\n", | ||
2352 | urb->transfer_buffer, (unsigned long)urb->transfer_dma); | ||
2353 | dev_vdbg(hsotg->dev, " Setup buffer: %p, Setup DMA: %08lx\n", | ||
2354 | urb->setup_packet, (unsigned long)urb->setup_dma); | ||
2355 | dev_vdbg(hsotg->dev, " Interval: %d\n", urb->interval); | ||
2356 | |||
2357 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { | ||
2358 | int i; | ||
2359 | |||
2360 | for (i = 0; i < urb->number_of_packets; i++) { | ||
2361 | dev_vdbg(hsotg->dev, " ISO Desc %d:\n", i); | ||
2362 | dev_vdbg(hsotg->dev, " offset: %d, length %d\n", | ||
2363 | urb->iso_frame_desc[i].offset, | ||
2364 | urb->iso_frame_desc[i].length); | ||
2365 | } | ||
2366 | } | ||
2367 | #endif | ||
2368 | } | ||
2369 | |||
2370 | /* | ||
2371 | * Starts processing a USB transfer request specified by a USB Request Block | ||
2372 | * (URB). mem_flags indicates the type of memory allocation to use while | ||
2373 | * processing this URB. | ||
2374 | */ | ||
2375 | static int _dwc2_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, | ||
2376 | gfp_t mem_flags) | ||
2377 | { | ||
2378 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2379 | struct usb_host_endpoint *ep = urb->ep; | ||
2380 | struct dwc2_hcd_urb *dwc2_urb; | ||
2381 | int i; | ||
2382 | int retval; | ||
2383 | int alloc_bandwidth = 0; | ||
2384 | u8 ep_type = 0; | ||
2385 | u32 tflags = 0; | ||
2386 | void *buf; | ||
2387 | unsigned long flags; | ||
2388 | |||
2389 | if (dbg_urb(urb)) { | ||
2390 | dev_vdbg(hsotg->dev, "DWC OTG HCD URB Enqueue\n"); | ||
2391 | dwc2_dump_urb_info(hcd, urb, "urb_enqueue"); | ||
2392 | } | ||
2393 | |||
2394 | if (ep == NULL) | ||
2395 | return -EINVAL; | ||
2396 | |||
2397 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS || | ||
2398 | usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { | ||
2399 | spin_lock_irqsave(&hsotg->lock, flags); | ||
2400 | if (!dwc2_hcd_is_bandwidth_allocated(hsotg, ep)) | ||
2401 | alloc_bandwidth = 1; | ||
2402 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
2403 | } | ||
2404 | |||
2405 | switch (usb_pipetype(urb->pipe)) { | ||
2406 | case PIPE_CONTROL: | ||
2407 | ep_type = USB_ENDPOINT_XFER_CONTROL; | ||
2408 | break; | ||
2409 | case PIPE_ISOCHRONOUS: | ||
2410 | ep_type = USB_ENDPOINT_XFER_ISOC; | ||
2411 | break; | ||
2412 | case PIPE_BULK: | ||
2413 | ep_type = USB_ENDPOINT_XFER_BULK; | ||
2414 | break; | ||
2415 | case PIPE_INTERRUPT: | ||
2416 | ep_type = USB_ENDPOINT_XFER_INT; | ||
2417 | break; | ||
2418 | default: | ||
2419 | dev_warn(hsotg->dev, "Wrong ep type\n"); | ||
2420 | } | ||
2421 | |||
2422 | dwc2_urb = dwc2_hcd_urb_alloc(hsotg, urb->number_of_packets, | ||
2423 | mem_flags); | ||
2424 | if (!dwc2_urb) | ||
2425 | return -ENOMEM; | ||
2426 | |||
2427 | dwc2_hcd_urb_set_pipeinfo(hsotg, dwc2_urb, usb_pipedevice(urb->pipe), | ||
2428 | usb_pipeendpoint(urb->pipe), ep_type, | ||
2429 | usb_pipein(urb->pipe), | ||
2430 | usb_maxpacket(urb->dev, urb->pipe, | ||
2431 | !(usb_pipein(urb->pipe)))); | ||
2432 | |||
2433 | buf = urb->transfer_buffer; | ||
2434 | |||
2435 | if (hcd->self.uses_dma) { | ||
2436 | if (!buf && (urb->transfer_dma & 3)) { | ||
2437 | dev_err(hsotg->dev, | ||
2438 | "%s: unaligned transfer with no transfer_buffer", | ||
2439 | __func__); | ||
2440 | retval = -EINVAL; | ||
2441 | goto fail1; | ||
2442 | } | ||
2443 | } | ||
2444 | |||
2445 | if (!(urb->transfer_flags & URB_NO_INTERRUPT)) | ||
2446 | tflags |= URB_GIVEBACK_ASAP; | ||
2447 | if (urb->transfer_flags & URB_ZERO_PACKET) | ||
2448 | tflags |= URB_SEND_ZERO_PACKET; | ||
2449 | |||
2450 | dwc2_urb->priv = urb; | ||
2451 | dwc2_urb->buf = buf; | ||
2452 | dwc2_urb->dma = urb->transfer_dma; | ||
2453 | dwc2_urb->length = urb->transfer_buffer_length; | ||
2454 | dwc2_urb->setup_packet = urb->setup_packet; | ||
2455 | dwc2_urb->setup_dma = urb->setup_dma; | ||
2456 | dwc2_urb->flags = tflags; | ||
2457 | dwc2_urb->interval = urb->interval; | ||
2458 | dwc2_urb->status = -EINPROGRESS; | ||
2459 | |||
2460 | for (i = 0; i < urb->number_of_packets; ++i) | ||
2461 | dwc2_hcd_urb_set_iso_desc_params(dwc2_urb, i, | ||
2462 | urb->iso_frame_desc[i].offset, | ||
2463 | urb->iso_frame_desc[i].length); | ||
2464 | |||
2465 | urb->hcpriv = dwc2_urb; | ||
2466 | |||
2467 | spin_lock_irqsave(&hsotg->lock, flags); | ||
2468 | retval = usb_hcd_link_urb_to_ep(hcd, urb); | ||
2469 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
2470 | if (retval) | ||
2471 | goto fail1; | ||
2472 | |||
2473 | retval = dwc2_hcd_urb_enqueue(hsotg, dwc2_urb, &ep->hcpriv, mem_flags); | ||
2474 | if (retval) | ||
2475 | goto fail2; | ||
2476 | |||
2477 | if (alloc_bandwidth) { | ||
2478 | spin_lock_irqsave(&hsotg->lock, flags); | ||
2479 | dwc2_allocate_bus_bandwidth(hcd, | ||
2480 | dwc2_hcd_get_ep_bandwidth(hsotg, ep), | ||
2481 | urb); | ||
2482 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
2483 | } | ||
2484 | |||
2485 | return 0; | ||
2486 | |||
2487 | fail2: | ||
2488 | spin_lock_irqsave(&hsotg->lock, flags); | ||
2489 | dwc2_urb->priv = NULL; | ||
2490 | usb_hcd_unlink_urb_from_ep(hcd, urb); | ||
2491 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
2492 | fail1: | ||
2493 | urb->hcpriv = NULL; | ||
2494 | kfree(dwc2_urb); | ||
2495 | |||
2496 | return retval; | ||
2497 | } | ||
2498 | |||
2499 | /* | ||
2500 | * Aborts/cancels a USB transfer request. Always returns 0 to indicate success. | ||
2501 | */ | ||
2502 | static int _dwc2_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | ||
2503 | int status) | ||
2504 | { | ||
2505 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2506 | int rc; | ||
2507 | unsigned long flags; | ||
2508 | |||
2509 | dev_dbg(hsotg->dev, "DWC OTG HCD URB Dequeue\n"); | ||
2510 | dwc2_dump_urb_info(hcd, urb, "urb_dequeue"); | ||
2511 | |||
2512 | spin_lock_irqsave(&hsotg->lock, flags); | ||
2513 | |||
2514 | rc = usb_hcd_check_unlink_urb(hcd, urb, status); | ||
2515 | if (rc) | ||
2516 | goto out; | ||
2517 | |||
2518 | if (!urb->hcpriv) { | ||
2519 | dev_dbg(hsotg->dev, "## urb->hcpriv is NULL ##\n"); | ||
2520 | goto out; | ||
2521 | } | ||
2522 | |||
2523 | rc = dwc2_hcd_urb_dequeue(hsotg, urb->hcpriv); | ||
2524 | |||
2525 | usb_hcd_unlink_urb_from_ep(hcd, urb); | ||
2526 | |||
2527 | kfree(urb->hcpriv); | ||
2528 | urb->hcpriv = NULL; | ||
2529 | |||
2530 | /* Higher layer software sets URB status */ | ||
2531 | spin_unlock(&hsotg->lock); | ||
2532 | usb_hcd_giveback_urb(hcd, urb, status); | ||
2533 | spin_lock(&hsotg->lock); | ||
2534 | |||
2535 | dev_dbg(hsotg->dev, "Called usb_hcd_giveback_urb()\n"); | ||
2536 | dev_dbg(hsotg->dev, " urb->status = %d\n", urb->status); | ||
2537 | out: | ||
2538 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
2539 | |||
2540 | return rc; | ||
2541 | } | ||
2542 | |||
2543 | /* | ||
2544 | * Frees resources in the DWC_otg controller related to a given endpoint. Also | ||
2545 | * clears state in the HCD related to the endpoint. Any URBs for the endpoint | ||
2546 | * must already be dequeued. | ||
2547 | */ | ||
2548 | static void _dwc2_hcd_endpoint_disable(struct usb_hcd *hcd, | ||
2549 | struct usb_host_endpoint *ep) | ||
2550 | { | ||
2551 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2552 | |||
2553 | dev_dbg(hsotg->dev, | ||
2554 | "DWC OTG HCD EP DISABLE: bEndpointAddress=0x%02x, ep->hcpriv=%p\n", | ||
2555 | ep->desc.bEndpointAddress, ep->hcpriv); | ||
2556 | dwc2_hcd_endpoint_disable(hsotg, ep, 250); | ||
2557 | } | ||
2558 | |||
2559 | /* | ||
2560 | * Resets endpoint specific parameter values, in current version used to reset | ||
2561 | * the data toggle (as a WA). This function can be called from usb_clear_halt | ||
2562 | * routine. | ||
2563 | */ | ||
2564 | static void _dwc2_hcd_endpoint_reset(struct usb_hcd *hcd, | ||
2565 | struct usb_host_endpoint *ep) | ||
2566 | { | ||
2567 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2568 | int is_control = usb_endpoint_xfer_control(&ep->desc); | ||
2569 | int is_out = usb_endpoint_dir_out(&ep->desc); | ||
2570 | int epnum = usb_endpoint_num(&ep->desc); | ||
2571 | struct usb_device *udev; | ||
2572 | unsigned long flags; | ||
2573 | |||
2574 | dev_dbg(hsotg->dev, | ||
2575 | "DWC OTG HCD EP RESET: bEndpointAddress=0x%02x\n", | ||
2576 | ep->desc.bEndpointAddress); | ||
2577 | |||
2578 | udev = to_usb_device(hsotg->dev); | ||
2579 | |||
2580 | spin_lock_irqsave(&hsotg->lock, flags); | ||
2581 | |||
2582 | usb_settoggle(udev, epnum, is_out, 0); | ||
2583 | if (is_control) | ||
2584 | usb_settoggle(udev, epnum, !is_out, 0); | ||
2585 | dwc2_hcd_endpoint_reset(hsotg, ep); | ||
2586 | |||
2587 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
2588 | } | ||
2589 | |||
2590 | /* | ||
2591 | * Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if | ||
2592 | * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid | ||
2593 | * interrupt. | ||
2594 | * | ||
2595 | * This function is called by the USB core when an interrupt occurs | ||
2596 | */ | ||
2597 | static irqreturn_t _dwc2_hcd_irq(struct usb_hcd *hcd) | ||
2598 | { | ||
2599 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2600 | |||
2601 | return dwc2_handle_hcd_intr(hsotg); | ||
2602 | } | ||
2603 | |||
2604 | /* | ||
2605 | * Creates Status Change bitmap for the root hub and root port. The bitmap is | ||
2606 | * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1 | ||
2607 | * is the status change indicator for the single root port. Returns 1 if either | ||
2608 | * change indicator is 1, otherwise returns 0. | ||
2609 | */ | ||
2610 | static int _dwc2_hcd_hub_status_data(struct usb_hcd *hcd, char *buf) | ||
2611 | { | ||
2612 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2613 | |||
2614 | buf[0] = dwc2_hcd_is_status_changed(hsotg, 1) << 1; | ||
2615 | return buf[0] != 0; | ||
2616 | } | ||
2617 | |||
2618 | /* Handles hub class-specific requests */ | ||
2619 | static int _dwc2_hcd_hub_control(struct usb_hcd *hcd, u16 typereq, u16 wvalue, | ||
2620 | u16 windex, char *buf, u16 wlength) | ||
2621 | { | ||
2622 | int retval = dwc2_hcd_hub_control(dwc2_hcd_to_hsotg(hcd), typereq, | ||
2623 | wvalue, windex, buf, wlength); | ||
2624 | return retval; | ||
2625 | } | ||
2626 | |||
2627 | /* Handles hub TT buffer clear completions */ | ||
2628 | static void _dwc2_hcd_clear_tt_buffer_complete(struct usb_hcd *hcd, | ||
2629 | struct usb_host_endpoint *ep) | ||
2630 | { | ||
2631 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2632 | struct dwc2_qh *qh; | ||
2633 | unsigned long flags; | ||
2634 | |||
2635 | qh = ep->hcpriv; | ||
2636 | if (!qh) | ||
2637 | return; | ||
2638 | |||
2639 | spin_lock_irqsave(&hsotg->lock, flags); | ||
2640 | qh->tt_buffer_dirty = 0; | ||
2641 | |||
2642 | if (hsotg->flags.b.port_connect_status) | ||
2643 | dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_ALL); | ||
2644 | |||
2645 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
2646 | } | ||
2647 | |||
2648 | static struct hc_driver dwc2_hc_driver = { | ||
2649 | .description = "dwc2_hsotg", | ||
2650 | .product_desc = "DWC OTG Controller", | ||
2651 | .hcd_priv_size = sizeof(struct wrapper_priv_data), | ||
2652 | |||
2653 | .irq = _dwc2_hcd_irq, | ||
2654 | .flags = HCD_MEMORY | HCD_USB2, | ||
2655 | |||
2656 | .start = _dwc2_hcd_start, | ||
2657 | .stop = _dwc2_hcd_stop, | ||
2658 | .urb_enqueue = _dwc2_hcd_urb_enqueue, | ||
2659 | .urb_dequeue = _dwc2_hcd_urb_dequeue, | ||
2660 | .endpoint_disable = _dwc2_hcd_endpoint_disable, | ||
2661 | .endpoint_reset = _dwc2_hcd_endpoint_reset, | ||
2662 | .get_frame_number = _dwc2_hcd_get_frame_number, | ||
2663 | |||
2664 | .hub_status_data = _dwc2_hcd_hub_status_data, | ||
2665 | .hub_control = _dwc2_hcd_hub_control, | ||
2666 | .clear_tt_buffer_complete = _dwc2_hcd_clear_tt_buffer_complete, | ||
2667 | }; | ||
2668 | |||
2669 | /* | ||
2670 | * Frees secondary storage associated with the dwc2_hsotg structure contained | ||
2671 | * in the struct usb_hcd field | ||
2672 | */ | ||
2673 | static void dwc2_hcd_free(struct dwc2_hsotg *hsotg) | ||
2674 | { | ||
2675 | u32 ahbcfg; | ||
2676 | u32 dctl; | ||
2677 | int i; | ||
2678 | |||
2679 | dev_dbg(hsotg->dev, "DWC OTG HCD FREE\n"); | ||
2680 | |||
2681 | /* Free memory for QH/QTD lists */ | ||
2682 | dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_inactive); | ||
2683 | dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_active); | ||
2684 | dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_inactive); | ||
2685 | dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_ready); | ||
2686 | dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_assigned); | ||
2687 | dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_queued); | ||
2688 | |||
2689 | /* Free memory for the host channels */ | ||
2690 | for (i = 0; i < MAX_EPS_CHANNELS; i++) { | ||
2691 | struct dwc2_host_chan *chan = hsotg->hc_ptr_array[i]; | ||
2692 | |||
2693 | if (chan != NULL) { | ||
2694 | dev_dbg(hsotg->dev, "HCD Free channel #%i, chan=%p\n", | ||
2695 | i, chan); | ||
2696 | hsotg->hc_ptr_array[i] = NULL; | ||
2697 | kfree(chan); | ||
2698 | } | ||
2699 | } | ||
2700 | |||
2701 | if (hsotg->core_params->dma_enable > 0) { | ||
2702 | if (hsotg->status_buf) { | ||
2703 | dma_free_coherent(hsotg->dev, DWC2_HCD_STATUS_BUF_SIZE, | ||
2704 | hsotg->status_buf, | ||
2705 | hsotg->status_buf_dma); | ||
2706 | hsotg->status_buf = NULL; | ||
2707 | } | ||
2708 | } else { | ||
2709 | kfree(hsotg->status_buf); | ||
2710 | hsotg->status_buf = NULL; | ||
2711 | } | ||
2712 | |||
2713 | ahbcfg = readl(hsotg->regs + GAHBCFG); | ||
2714 | |||
2715 | /* Disable all interrupts */ | ||
2716 | ahbcfg &= ~GAHBCFG_GLBL_INTR_EN; | ||
2717 | writel(ahbcfg, hsotg->regs + GAHBCFG); | ||
2718 | writel(0, hsotg->regs + GINTMSK); | ||
2719 | |||
2720 | if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a) { | ||
2721 | dctl = readl(hsotg->regs + DCTL); | ||
2722 | dctl |= DCTL_SFTDISCON; | ||
2723 | writel(dctl, hsotg->regs + DCTL); | ||
2724 | } | ||
2725 | |||
2726 | if (hsotg->wq_otg) { | ||
2727 | if (!cancel_work_sync(&hsotg->wf_otg)) | ||
2728 | flush_workqueue(hsotg->wq_otg); | ||
2729 | destroy_workqueue(hsotg->wq_otg); | ||
2730 | } | ||
2731 | |||
2732 | kfree(hsotg->core_params); | ||
2733 | hsotg->core_params = NULL; | ||
2734 | del_timer(&hsotg->wkp_timer); | ||
2735 | } | ||
2736 | |||
2737 | static void dwc2_hcd_release(struct dwc2_hsotg *hsotg) | ||
2738 | { | ||
2739 | /* Turn off all host-specific interrupts */ | ||
2740 | dwc2_disable_host_interrupts(hsotg); | ||
2741 | |||
2742 | dwc2_hcd_free(hsotg); | ||
2743 | } | ||
2744 | |||
2745 | /* | ||
2746 | * Sets all parameters to the given value. | ||
2747 | * | ||
2748 | * Assumes that the dwc2_core_params struct contains only integers. | ||
2749 | */ | ||
2750 | void dwc2_set_all_params(struct dwc2_core_params *params, int value) | ||
2751 | { | ||
2752 | int *p = (int *)params; | ||
2753 | size_t size = sizeof(*params) / sizeof(*p); | ||
2754 | int i; | ||
2755 | |||
2756 | for (i = 0; i < size; i++) | ||
2757 | p[i] = value; | ||
2758 | } | ||
2759 | EXPORT_SYMBOL_GPL(dwc2_set_all_params); | ||
2760 | |||
2761 | /* | ||
2762 | * Initializes the HCD. This function allocates memory for and initializes the | ||
2763 | * static parts of the usb_hcd and dwc2_hsotg structures. It also registers the | ||
2764 | * USB bus with the core and calls the hc_driver->start() function. It returns | ||
2765 | * a negative error on failure. | ||
2766 | */ | ||
2767 | int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq, | ||
2768 | const struct dwc2_core_params *params) | ||
2769 | { | ||
2770 | struct usb_hcd *hcd; | ||
2771 | struct dwc2_host_chan *channel; | ||
2772 | u32 hcfg; | ||
2773 | int i, num_channels; | ||
2774 | int retval; | ||
2775 | |||
2776 | dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n"); | ||
2777 | |||
2778 | /* Detect config values from hardware */ | ||
2779 | retval = dwc2_get_hwparams(hsotg); | ||
2780 | |||
2781 | if (retval) | ||
2782 | return retval; | ||
2783 | |||
2784 | retval = -ENOMEM; | ||
2785 | |||
2786 | hcfg = readl(hsotg->regs + HCFG); | ||
2787 | dev_dbg(hsotg->dev, "hcfg=%08x\n", hcfg); | ||
2788 | |||
2789 | #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS | ||
2790 | hsotg->frame_num_array = kzalloc(sizeof(*hsotg->frame_num_array) * | ||
2791 | FRAME_NUM_ARRAY_SIZE, GFP_KERNEL); | ||
2792 | if (!hsotg->frame_num_array) | ||
2793 | goto error1; | ||
2794 | hsotg->last_frame_num_array = kzalloc( | ||
2795 | sizeof(*hsotg->last_frame_num_array) * | ||
2796 | FRAME_NUM_ARRAY_SIZE, GFP_KERNEL); | ||
2797 | if (!hsotg->last_frame_num_array) | ||
2798 | goto error1; | ||
2799 | hsotg->last_frame_num = HFNUM_MAX_FRNUM; | ||
2800 | #endif | ||
2801 | |||
2802 | hsotg->core_params = kzalloc(sizeof(*hsotg->core_params), GFP_KERNEL); | ||
2803 | if (!hsotg->core_params) | ||
2804 | goto error1; | ||
2805 | |||
2806 | dwc2_set_all_params(hsotg->core_params, -1); | ||
2807 | |||
2808 | /* Validate parameter values */ | ||
2809 | dwc2_set_parameters(hsotg, params); | ||
2810 | |||
2811 | /* Check if the bus driver or platform code has setup a dma_mask */ | ||
2812 | if (hsotg->core_params->dma_enable > 0 && | ||
2813 | hsotg->dev->dma_mask == NULL) { | ||
2814 | dev_warn(hsotg->dev, | ||
2815 | "dma_mask not set, disabling DMA\n"); | ||
2816 | hsotg->core_params->dma_enable = 0; | ||
2817 | hsotg->core_params->dma_desc_enable = 0; | ||
2818 | } | ||
2819 | |||
2820 | /* Set device flags indicating whether the HCD supports DMA */ | ||
2821 | if (hsotg->core_params->dma_enable > 0) { | ||
2822 | if (dma_set_mask(hsotg->dev, DMA_BIT_MASK(32)) < 0) | ||
2823 | dev_warn(hsotg->dev, "can't set DMA mask\n"); | ||
2824 | if (dma_set_coherent_mask(hsotg->dev, DMA_BIT_MASK(32)) < 0) | ||
2825 | dev_warn(hsotg->dev, "can't set coherent DMA mask\n"); | ||
2826 | } | ||
2827 | |||
2828 | hcd = usb_create_hcd(&dwc2_hc_driver, hsotg->dev, dev_name(hsotg->dev)); | ||
2829 | if (!hcd) | ||
2830 | goto error1; | ||
2831 | |||
2832 | if (hsotg->core_params->dma_enable <= 0) | ||
2833 | hcd->self.uses_dma = 0; | ||
2834 | |||
2835 | hcd->has_tt = 1; | ||
2836 | |||
2837 | spin_lock_init(&hsotg->lock); | ||
2838 | ((struct wrapper_priv_data *) &hcd->hcd_priv)->hsotg = hsotg; | ||
2839 | hsotg->priv = hcd; | ||
2840 | |||
2841 | /* | ||
2842 | * Disable the global interrupt until all the interrupt handlers are | ||
2843 | * installed | ||
2844 | */ | ||
2845 | dwc2_disable_global_interrupts(hsotg); | ||
2846 | |||
2847 | /* Initialize the DWC_otg core, and select the Phy type */ | ||
2848 | retval = dwc2_core_init(hsotg, true, irq); | ||
2849 | if (retval) | ||
2850 | goto error2; | ||
2851 | |||
2852 | /* Create new workqueue and init work */ | ||
2853 | retval = -ENOMEM; | ||
2854 | hsotg->wq_otg = create_singlethread_workqueue("dwc2"); | ||
2855 | if (!hsotg->wq_otg) { | ||
2856 | dev_err(hsotg->dev, "Failed to create workqueue\n"); | ||
2857 | goto error2; | ||
2858 | } | ||
2859 | INIT_WORK(&hsotg->wf_otg, dwc2_conn_id_status_change); | ||
2860 | |||
2861 | setup_timer(&hsotg->wkp_timer, dwc2_wakeup_detected, | ||
2862 | (unsigned long)hsotg); | ||
2863 | |||
2864 | /* Initialize the non-periodic schedule */ | ||
2865 | INIT_LIST_HEAD(&hsotg->non_periodic_sched_inactive); | ||
2866 | INIT_LIST_HEAD(&hsotg->non_periodic_sched_active); | ||
2867 | |||
2868 | /* Initialize the periodic schedule */ | ||
2869 | INIT_LIST_HEAD(&hsotg->periodic_sched_inactive); | ||
2870 | INIT_LIST_HEAD(&hsotg->periodic_sched_ready); | ||
2871 | INIT_LIST_HEAD(&hsotg->periodic_sched_assigned); | ||
2872 | INIT_LIST_HEAD(&hsotg->periodic_sched_queued); | ||
2873 | |||
2874 | /* | ||
2875 | * Create a host channel descriptor for each host channel implemented | ||
2876 | * in the controller. Initialize the channel descriptor array. | ||
2877 | */ | ||
2878 | INIT_LIST_HEAD(&hsotg->free_hc_list); | ||
2879 | num_channels = hsotg->core_params->host_channels; | ||
2880 | memset(&hsotg->hc_ptr_array[0], 0, sizeof(hsotg->hc_ptr_array)); | ||
2881 | |||
2882 | for (i = 0; i < num_channels; i++) { | ||
2883 | channel = kzalloc(sizeof(*channel), GFP_KERNEL); | ||
2884 | if (channel == NULL) | ||
2885 | goto error3; | ||
2886 | channel->hc_num = i; | ||
2887 | hsotg->hc_ptr_array[i] = channel; | ||
2888 | } | ||
2889 | |||
2890 | if (hsotg->core_params->uframe_sched > 0) | ||
2891 | dwc2_hcd_init_usecs(hsotg); | ||
2892 | |||
2893 | /* Initialize hsotg start work */ | ||
2894 | INIT_DELAYED_WORK(&hsotg->start_work, dwc2_hcd_start_func); | ||
2895 | |||
2896 | /* Initialize port reset work */ | ||
2897 | INIT_DELAYED_WORK(&hsotg->reset_work, dwc2_hcd_reset_func); | ||
2898 | |||
2899 | /* | ||
2900 | * Allocate space for storing data on status transactions. Normally no | ||
2901 | * data is sent, but this space acts as a bit bucket. This must be | ||
2902 | * done after usb_add_hcd since that function allocates the DMA buffer | ||
2903 | * pool. | ||
2904 | */ | ||
2905 | if (hsotg->core_params->dma_enable > 0) | ||
2906 | hsotg->status_buf = dma_alloc_coherent(hsotg->dev, | ||
2907 | DWC2_HCD_STATUS_BUF_SIZE, | ||
2908 | &hsotg->status_buf_dma, GFP_KERNEL); | ||
2909 | else | ||
2910 | hsotg->status_buf = kzalloc(DWC2_HCD_STATUS_BUF_SIZE, | ||
2911 | GFP_KERNEL); | ||
2912 | |||
2913 | if (!hsotg->status_buf) | ||
2914 | goto error3; | ||
2915 | |||
2916 | hsotg->otg_port = 1; | ||
2917 | hsotg->frame_list = NULL; | ||
2918 | hsotg->frame_list_dma = 0; | ||
2919 | hsotg->periodic_qh_count = 0; | ||
2920 | |||
2921 | /* Initiate lx_state to L3 disconnected state */ | ||
2922 | hsotg->lx_state = DWC2_L3; | ||
2923 | |||
2924 | hcd->self.otg_port = hsotg->otg_port; | ||
2925 | |||
2926 | /* Don't support SG list at this point */ | ||
2927 | hcd->self.sg_tablesize = 0; | ||
2928 | |||
2929 | /* | ||
2930 | * Finish generic HCD initialization and start the HCD. This function | ||
2931 | * allocates the DMA buffer pool, registers the USB bus, requests the | ||
2932 | * IRQ line, and calls hcd_start method. | ||
2933 | */ | ||
2934 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | ||
2935 | if (retval < 0) | ||
2936 | goto error3; | ||
2937 | |||
2938 | device_wakeup_enable(hcd->self.controller); | ||
2939 | |||
2940 | dwc2_hcd_dump_state(hsotg); | ||
2941 | |||
2942 | dwc2_enable_global_interrupts(hsotg); | ||
2943 | |||
2944 | return 0; | ||
2945 | |||
2946 | error3: | ||
2947 | dwc2_hcd_release(hsotg); | ||
2948 | error2: | ||
2949 | usb_put_hcd(hcd); | ||
2950 | error1: | ||
2951 | kfree(hsotg->core_params); | ||
2952 | |||
2953 | #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS | ||
2954 | kfree(hsotg->last_frame_num_array); | ||
2955 | kfree(hsotg->frame_num_array); | ||
2956 | #endif | ||
2957 | |||
2958 | dev_err(hsotg->dev, "%s() FAILED, returning %d\n", __func__, retval); | ||
2959 | return retval; | ||
2960 | } | ||
2961 | EXPORT_SYMBOL_GPL(dwc2_hcd_init); | ||
2962 | |||
2963 | /* | ||
2964 | * Removes the HCD. | ||
2965 | * Frees memory and resources associated with the HCD and deregisters the bus. | ||
2966 | */ | ||
2967 | void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) | ||
2968 | { | ||
2969 | struct usb_hcd *hcd; | ||
2970 | |||
2971 | dev_dbg(hsotg->dev, "DWC OTG HCD REMOVE\n"); | ||
2972 | |||
2973 | hcd = dwc2_hsotg_to_hcd(hsotg); | ||
2974 | dev_dbg(hsotg->dev, "hsotg->hcd = %p\n", hcd); | ||
2975 | |||
2976 | if (!hcd) { | ||
2977 | dev_dbg(hsotg->dev, "%s: dwc2_hsotg_to_hcd(hsotg) NULL!\n", | ||
2978 | __func__); | ||
2979 | return; | ||
2980 | } | ||
2981 | |||
2982 | usb_remove_hcd(hcd); | ||
2983 | hsotg->priv = NULL; | ||
2984 | dwc2_hcd_release(hsotg); | ||
2985 | usb_put_hcd(hcd); | ||
2986 | |||
2987 | #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS | ||
2988 | kfree(hsotg->last_frame_num_array); | ||
2989 | kfree(hsotg->frame_num_array); | ||
2990 | #endif | ||
2991 | } | ||
2992 | EXPORT_SYMBOL_GPL(dwc2_hcd_remove); | ||
diff --git a/drivers/usb/dwc2/hcd.h b/drivers/usb/dwc2/hcd.h new file mode 100644 index 000000000000..fdc6d489084a --- /dev/null +++ b/drivers/usb/dwc2/hcd.h | |||
@@ -0,0 +1,769 @@ | |||
1 | /* | ||
2 | * hcd.h - DesignWare HS OTG Controller host-mode declarations | ||
3 | * | ||
4 | * Copyright (C) 2004-2013 Synopsys, Inc. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions, and the following disclaimer, | ||
11 | * without modification. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The names of the above-listed copyright holders may not be used | ||
16 | * to endorse or promote products derived from this software without | ||
17 | * specific prior written permission. | ||
18 | * | ||
19 | * ALTERNATIVELY, this software may be distributed under the terms of the | ||
20 | * GNU General Public License ("GPL") as published by the Free Software | ||
21 | * Foundation; either version 2 of the License, or (at your option) any | ||
22 | * later version. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
26 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
35 | */ | ||
36 | #ifndef __DWC2_HCD_H__ | ||
37 | #define __DWC2_HCD_H__ | ||
38 | |||
39 | /* | ||
40 | * This file contains the structures, constants, and interfaces for the | ||
41 | * Host Contoller Driver (HCD) | ||
42 | * | ||
43 | * The Host Controller Driver (HCD) is responsible for translating requests | ||
44 | * from the USB Driver into the appropriate actions on the DWC_otg controller. | ||
45 | * It isolates the USBD from the specifics of the controller by providing an | ||
46 | * API to the USBD. | ||
47 | */ | ||
48 | |||
49 | struct dwc2_qh; | ||
50 | |||
51 | /** | ||
52 | * struct dwc2_host_chan - Software host channel descriptor | ||
53 | * | ||
54 | * @hc_num: Host channel number, used for register address lookup | ||
55 | * @dev_addr: Address of the device | ||
56 | * @ep_num: Endpoint of the device | ||
57 | * @ep_is_in: Endpoint direction | ||
58 | * @speed: Device speed. One of the following values: | ||
59 | * - USB_SPEED_LOW | ||
60 | * - USB_SPEED_FULL | ||
61 | * - USB_SPEED_HIGH | ||
62 | * @ep_type: Endpoint type. One of the following values: | ||
63 | * - USB_ENDPOINT_XFER_CONTROL: 0 | ||
64 | * - USB_ENDPOINT_XFER_ISOC: 1 | ||
65 | * - USB_ENDPOINT_XFER_BULK: 2 | ||
66 | * - USB_ENDPOINT_XFER_INTR: 3 | ||
67 | * @max_packet: Max packet size in bytes | ||
68 | * @data_pid_start: PID for initial transaction. | ||
69 | * 0: DATA0 | ||
70 | * 1: DATA2 | ||
71 | * 2: DATA1 | ||
72 | * 3: MDATA (non-Control EP), | ||
73 | * SETUP (Control EP) | ||
74 | * @multi_count: Number of additional periodic transactions per | ||
75 | * (micro)frame | ||
76 | * @xfer_buf: Pointer to current transfer buffer position | ||
77 | * @xfer_dma: DMA address of xfer_buf | ||
78 | * @align_buf: In Buffer DMA mode this will be used if xfer_buf is not | ||
79 | * DWORD aligned | ||
80 | * @xfer_len: Total number of bytes to transfer | ||
81 | * @xfer_count: Number of bytes transferred so far | ||
82 | * @start_pkt_count: Packet count at start of transfer | ||
83 | * @xfer_started: True if the transfer has been started | ||
84 | * @ping: True if a PING request should be issued on this channel | ||
85 | * @error_state: True if the error count for this transaction is non-zero | ||
86 | * @halt_on_queue: True if this channel should be halted the next time a | ||
87 | * request is queued for the channel. This is necessary in | ||
88 | * slave mode if no request queue space is available when | ||
89 | * an attempt is made to halt the channel. | ||
90 | * @halt_pending: True if the host channel has been halted, but the core | ||
91 | * is not finished flushing queued requests | ||
92 | * @do_split: Enable split for the channel | ||
93 | * @complete_split: Enable complete split | ||
94 | * @hub_addr: Address of high speed hub for the split | ||
95 | * @hub_port: Port of the low/full speed device for the split | ||
96 | * @xact_pos: Split transaction position. One of the following values: | ||
97 | * - DWC2_HCSPLT_XACTPOS_MID | ||
98 | * - DWC2_HCSPLT_XACTPOS_BEGIN | ||
99 | * - DWC2_HCSPLT_XACTPOS_END | ||
100 | * - DWC2_HCSPLT_XACTPOS_ALL | ||
101 | * @requests: Number of requests issued for this channel since it was | ||
102 | * assigned to the current transfer (not counting PINGs) | ||
103 | * @schinfo: Scheduling micro-frame bitmap | ||
104 | * @ntd: Number of transfer descriptors for the transfer | ||
105 | * @halt_status: Reason for halting the host channel | ||
106 | * @hcint Contents of the HCINT register when the interrupt came | ||
107 | * @qh: QH for the transfer being processed by this channel | ||
108 | * @hc_list_entry: For linking to list of host channels | ||
109 | * @desc_list_addr: Current QH's descriptor list DMA address | ||
110 | * | ||
111 | * This structure represents the state of a single host channel when acting in | ||
112 | * host mode. It contains the data items needed to transfer packets to an | ||
113 | * endpoint via a host channel. | ||
114 | */ | ||
115 | struct dwc2_host_chan { | ||
116 | u8 hc_num; | ||
117 | |||
118 | unsigned dev_addr:7; | ||
119 | unsigned ep_num:4; | ||
120 | unsigned ep_is_in:1; | ||
121 | unsigned speed:4; | ||
122 | unsigned ep_type:2; | ||
123 | unsigned max_packet:11; | ||
124 | unsigned data_pid_start:2; | ||
125 | #define DWC2_HC_PID_DATA0 TSIZ_SC_MC_PID_DATA0 | ||
126 | #define DWC2_HC_PID_DATA2 TSIZ_SC_MC_PID_DATA2 | ||
127 | #define DWC2_HC_PID_DATA1 TSIZ_SC_MC_PID_DATA1 | ||
128 | #define DWC2_HC_PID_MDATA TSIZ_SC_MC_PID_MDATA | ||
129 | #define DWC2_HC_PID_SETUP TSIZ_SC_MC_PID_SETUP | ||
130 | |||
131 | unsigned multi_count:2; | ||
132 | |||
133 | u8 *xfer_buf; | ||
134 | dma_addr_t xfer_dma; | ||
135 | dma_addr_t align_buf; | ||
136 | u32 xfer_len; | ||
137 | u32 xfer_count; | ||
138 | u16 start_pkt_count; | ||
139 | u8 xfer_started; | ||
140 | u8 do_ping; | ||
141 | u8 error_state; | ||
142 | u8 halt_on_queue; | ||
143 | u8 halt_pending; | ||
144 | u8 do_split; | ||
145 | u8 complete_split; | ||
146 | u8 hub_addr; | ||
147 | u8 hub_port; | ||
148 | u8 xact_pos; | ||
149 | #define DWC2_HCSPLT_XACTPOS_MID HCSPLT_XACTPOS_MID | ||
150 | #define DWC2_HCSPLT_XACTPOS_END HCSPLT_XACTPOS_END | ||
151 | #define DWC2_HCSPLT_XACTPOS_BEGIN HCSPLT_XACTPOS_BEGIN | ||
152 | #define DWC2_HCSPLT_XACTPOS_ALL HCSPLT_XACTPOS_ALL | ||
153 | |||
154 | u8 requests; | ||
155 | u8 schinfo; | ||
156 | u16 ntd; | ||
157 | enum dwc2_halt_status halt_status; | ||
158 | u32 hcint; | ||
159 | struct dwc2_qh *qh; | ||
160 | struct list_head hc_list_entry; | ||
161 | dma_addr_t desc_list_addr; | ||
162 | }; | ||
163 | |||
164 | struct dwc2_hcd_pipe_info { | ||
165 | u8 dev_addr; | ||
166 | u8 ep_num; | ||
167 | u8 pipe_type; | ||
168 | u8 pipe_dir; | ||
169 | u16 mps; | ||
170 | }; | ||
171 | |||
172 | struct dwc2_hcd_iso_packet_desc { | ||
173 | u32 offset; | ||
174 | u32 length; | ||
175 | u32 actual_length; | ||
176 | u32 status; | ||
177 | }; | ||
178 | |||
179 | struct dwc2_qtd; | ||
180 | |||
181 | struct dwc2_hcd_urb { | ||
182 | void *priv; | ||
183 | struct dwc2_qtd *qtd; | ||
184 | void *buf; | ||
185 | dma_addr_t dma; | ||
186 | void *setup_packet; | ||
187 | dma_addr_t setup_dma; | ||
188 | u32 length; | ||
189 | u32 actual_length; | ||
190 | u32 status; | ||
191 | u32 error_count; | ||
192 | u32 packet_count; | ||
193 | u32 flags; | ||
194 | u16 interval; | ||
195 | struct dwc2_hcd_pipe_info pipe_info; | ||
196 | struct dwc2_hcd_iso_packet_desc iso_descs[0]; | ||
197 | }; | ||
198 | |||
199 | /* Phases for control transfers */ | ||
200 | enum dwc2_control_phase { | ||
201 | DWC2_CONTROL_SETUP, | ||
202 | DWC2_CONTROL_DATA, | ||
203 | DWC2_CONTROL_STATUS, | ||
204 | }; | ||
205 | |||
206 | /* Transaction types */ | ||
207 | enum dwc2_transaction_type { | ||
208 | DWC2_TRANSACTION_NONE, | ||
209 | DWC2_TRANSACTION_PERIODIC, | ||
210 | DWC2_TRANSACTION_NON_PERIODIC, | ||
211 | DWC2_TRANSACTION_ALL, | ||
212 | }; | ||
213 | |||
214 | /** | ||
215 | * struct dwc2_qh - Software queue head structure | ||
216 | * | ||
217 | * @ep_type: Endpoint type. One of the following values: | ||
218 | * - USB_ENDPOINT_XFER_CONTROL | ||
219 | * - USB_ENDPOINT_XFER_BULK | ||
220 | * - USB_ENDPOINT_XFER_INT | ||
221 | * - USB_ENDPOINT_XFER_ISOC | ||
222 | * @ep_is_in: Endpoint direction | ||
223 | * @maxp: Value from wMaxPacketSize field of Endpoint Descriptor | ||
224 | * @dev_speed: Device speed. One of the following values: | ||
225 | * - USB_SPEED_LOW | ||
226 | * - USB_SPEED_FULL | ||
227 | * - USB_SPEED_HIGH | ||
228 | * @data_toggle: Determines the PID of the next data packet for | ||
229 | * non-controltransfers. Ignored for control transfers. | ||
230 | * One of the following values: | ||
231 | * - DWC2_HC_PID_DATA0 | ||
232 | * - DWC2_HC_PID_DATA1 | ||
233 | * @ping_state: Ping state | ||
234 | * @do_split: Full/low speed endpoint on high-speed hub requires split | ||
235 | * @td_first: Index of first activated isochronous transfer descriptor | ||
236 | * @td_last: Index of last activated isochronous transfer descriptor | ||
237 | * @usecs: Bandwidth in microseconds per (micro)frame | ||
238 | * @interval: Interval between transfers in (micro)frames | ||
239 | * @sched_frame: (Micro)frame to initialize a periodic transfer. | ||
240 | * The transfer executes in the following (micro)frame. | ||
241 | * @frame_usecs: Internal variable used by the microframe scheduler | ||
242 | * @start_split_frame: (Micro)frame at which last start split was initialized | ||
243 | * @ntd: Actual number of transfer descriptors in a list | ||
244 | * @dw_align_buf: Used instead of original buffer if its physical address | ||
245 | * is not dword-aligned | ||
246 | * @dw_align_buf_dma: DMA address for align_buf | ||
247 | * @qtd_list: List of QTDs for this QH | ||
248 | * @channel: Host channel currently processing transfers for this QH | ||
249 | * @qh_list_entry: Entry for QH in either the periodic or non-periodic | ||
250 | * schedule | ||
251 | * @desc_list: List of transfer descriptors | ||
252 | * @desc_list_dma: Physical address of desc_list | ||
253 | * @n_bytes: Xfer Bytes array. Each element corresponds to a transfer | ||
254 | * descriptor and indicates original XferSize value for the | ||
255 | * descriptor | ||
256 | * @tt_buffer_dirty True if clear_tt_buffer_complete is pending | ||
257 | * | ||
258 | * A Queue Head (QH) holds the static characteristics of an endpoint and | ||
259 | * maintains a list of transfers (QTDs) for that endpoint. A QH structure may | ||
260 | * be entered in either the non-periodic or periodic schedule. | ||
261 | */ | ||
262 | struct dwc2_qh { | ||
263 | u8 ep_type; | ||
264 | u8 ep_is_in; | ||
265 | u16 maxp; | ||
266 | u8 dev_speed; | ||
267 | u8 data_toggle; | ||
268 | u8 ping_state; | ||
269 | u8 do_split; | ||
270 | u8 td_first; | ||
271 | u8 td_last; | ||
272 | u16 usecs; | ||
273 | u16 interval; | ||
274 | u16 sched_frame; | ||
275 | u16 frame_usecs[8]; | ||
276 | u16 start_split_frame; | ||
277 | u16 ntd; | ||
278 | u8 *dw_align_buf; | ||
279 | dma_addr_t dw_align_buf_dma; | ||
280 | struct list_head qtd_list; | ||
281 | struct dwc2_host_chan *channel; | ||
282 | struct list_head qh_list_entry; | ||
283 | struct dwc2_hcd_dma_desc *desc_list; | ||
284 | dma_addr_t desc_list_dma; | ||
285 | u32 *n_bytes; | ||
286 | unsigned tt_buffer_dirty:1; | ||
287 | }; | ||
288 | |||
289 | /** | ||
290 | * struct dwc2_qtd - Software queue transfer descriptor (QTD) | ||
291 | * | ||
292 | * @control_phase: Current phase for control transfers (Setup, Data, or | ||
293 | * Status) | ||
294 | * @in_process: Indicates if this QTD is currently processed by HW | ||
295 | * @data_toggle: Determines the PID of the next data packet for the | ||
296 | * data phase of control transfers. Ignored for other | ||
297 | * transfer types. One of the following values: | ||
298 | * - DWC2_HC_PID_DATA0 | ||
299 | * - DWC2_HC_PID_DATA1 | ||
300 | * @complete_split: Keeps track of the current split type for FS/LS | ||
301 | * endpoints on a HS Hub | ||
302 | * @isoc_split_pos: Position of the ISOC split in full/low speed | ||
303 | * @isoc_frame_index: Index of the next frame descriptor for an isochronous | ||
304 | * transfer. A frame descriptor describes the buffer | ||
305 | * position and length of the data to be transferred in the | ||
306 | * next scheduled (micro)frame of an isochronous transfer. | ||
307 | * It also holds status for that transaction. The frame | ||
308 | * index starts at 0. | ||
309 | * @isoc_split_offset: Position of the ISOC split in the buffer for the | ||
310 | * current frame | ||
311 | * @ssplit_out_xfer_count: How many bytes transferred during SSPLIT OUT | ||
312 | * @error_count: Holds the number of bus errors that have occurred for | ||
313 | * a transaction within this transfer | ||
314 | * @n_desc: Number of DMA descriptors for this QTD | ||
315 | * @isoc_frame_index_last: Last activated frame (packet) index, used in | ||
316 | * descriptor DMA mode only | ||
317 | * @urb: URB for this transfer | ||
318 | * @qh: Queue head for this QTD | ||
319 | * @qtd_list_entry: For linking to the QH's list of QTDs | ||
320 | * | ||
321 | * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control, | ||
322 | * interrupt, or isochronous transfer. A single QTD is created for each URB | ||
323 | * (of one of these types) submitted to the HCD. The transfer associated with | ||
324 | * a QTD may require one or multiple transactions. | ||
325 | * | ||
326 | * A QTD is linked to a Queue Head, which is entered in either the | ||
327 | * non-periodic or periodic schedule for execution. When a QTD is chosen for | ||
328 | * execution, some or all of its transactions may be executed. After | ||
329 | * execution, the state of the QTD is updated. The QTD may be retired if all | ||
330 | * its transactions are complete or if an error occurred. Otherwise, it | ||
331 | * remains in the schedule so more transactions can be executed later. | ||
332 | */ | ||
333 | struct dwc2_qtd { | ||
334 | enum dwc2_control_phase control_phase; | ||
335 | u8 in_process; | ||
336 | u8 data_toggle; | ||
337 | u8 complete_split; | ||
338 | u8 isoc_split_pos; | ||
339 | u16 isoc_frame_index; | ||
340 | u16 isoc_split_offset; | ||
341 | u32 ssplit_out_xfer_count; | ||
342 | u8 error_count; | ||
343 | u8 n_desc; | ||
344 | u16 isoc_frame_index_last; | ||
345 | struct dwc2_hcd_urb *urb; | ||
346 | struct dwc2_qh *qh; | ||
347 | struct list_head qtd_list_entry; | ||
348 | }; | ||
349 | |||
350 | #ifdef DEBUG | ||
351 | struct hc_xfer_info { | ||
352 | struct dwc2_hsotg *hsotg; | ||
353 | struct dwc2_host_chan *chan; | ||
354 | }; | ||
355 | #endif | ||
356 | |||
357 | /* Gets the struct usb_hcd that contains a struct dwc2_hsotg */ | ||
358 | static inline struct usb_hcd *dwc2_hsotg_to_hcd(struct dwc2_hsotg *hsotg) | ||
359 | { | ||
360 | return (struct usb_hcd *)hsotg->priv; | ||
361 | } | ||
362 | |||
363 | /* | ||
364 | * Inline used to disable one channel interrupt. Channel interrupts are | ||
365 | * disabled when the channel is halted or released by the interrupt handler. | ||
366 | * There is no need to handle further interrupts of that type until the | ||
367 | * channel is re-assigned. In fact, subsequent handling may cause crashes | ||
368 | * because the channel structures are cleaned up when the channel is released. | ||
369 | */ | ||
370 | static inline void disable_hc_int(struct dwc2_hsotg *hsotg, int chnum, u32 intr) | ||
371 | { | ||
372 | u32 mask = readl(hsotg->regs + HCINTMSK(chnum)); | ||
373 | |||
374 | mask &= ~intr; | ||
375 | writel(mask, hsotg->regs + HCINTMSK(chnum)); | ||
376 | } | ||
377 | |||
378 | /* | ||
379 | * Returns the mode of operation, host or device | ||
380 | */ | ||
381 | static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg) | ||
382 | { | ||
383 | return (readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) != 0; | ||
384 | } | ||
385 | static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg) | ||
386 | { | ||
387 | return (readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) == 0; | ||
388 | } | ||
389 | |||
390 | /* | ||
391 | * Reads HPRT0 in preparation to modify. It keeps the WC bits 0 so that if they | ||
392 | * are read as 1, they won't clear when written back. | ||
393 | */ | ||
394 | static inline u32 dwc2_read_hprt0(struct dwc2_hsotg *hsotg) | ||
395 | { | ||
396 | u32 hprt0 = readl(hsotg->regs + HPRT0); | ||
397 | |||
398 | hprt0 &= ~(HPRT0_ENA | HPRT0_CONNDET | HPRT0_ENACHG | HPRT0_OVRCURRCHG); | ||
399 | return hprt0; | ||
400 | } | ||
401 | |||
402 | static inline u8 dwc2_hcd_get_ep_num(struct dwc2_hcd_pipe_info *pipe) | ||
403 | { | ||
404 | return pipe->ep_num; | ||
405 | } | ||
406 | |||
407 | static inline u8 dwc2_hcd_get_pipe_type(struct dwc2_hcd_pipe_info *pipe) | ||
408 | { | ||
409 | return pipe->pipe_type; | ||
410 | } | ||
411 | |||
412 | static inline u16 dwc2_hcd_get_mps(struct dwc2_hcd_pipe_info *pipe) | ||
413 | { | ||
414 | return pipe->mps; | ||
415 | } | ||
416 | |||
417 | static inline u8 dwc2_hcd_get_dev_addr(struct dwc2_hcd_pipe_info *pipe) | ||
418 | { | ||
419 | return pipe->dev_addr; | ||
420 | } | ||
421 | |||
422 | static inline u8 dwc2_hcd_is_pipe_isoc(struct dwc2_hcd_pipe_info *pipe) | ||
423 | { | ||
424 | return pipe->pipe_type == USB_ENDPOINT_XFER_ISOC; | ||
425 | } | ||
426 | |||
427 | static inline u8 dwc2_hcd_is_pipe_int(struct dwc2_hcd_pipe_info *pipe) | ||
428 | { | ||
429 | return pipe->pipe_type == USB_ENDPOINT_XFER_INT; | ||
430 | } | ||
431 | |||
432 | static inline u8 dwc2_hcd_is_pipe_bulk(struct dwc2_hcd_pipe_info *pipe) | ||
433 | { | ||
434 | return pipe->pipe_type == USB_ENDPOINT_XFER_BULK; | ||
435 | } | ||
436 | |||
437 | static inline u8 dwc2_hcd_is_pipe_control(struct dwc2_hcd_pipe_info *pipe) | ||
438 | { | ||
439 | return pipe->pipe_type == USB_ENDPOINT_XFER_CONTROL; | ||
440 | } | ||
441 | |||
442 | static inline u8 dwc2_hcd_is_pipe_in(struct dwc2_hcd_pipe_info *pipe) | ||
443 | { | ||
444 | return pipe->pipe_dir == USB_DIR_IN; | ||
445 | } | ||
446 | |||
447 | static inline u8 dwc2_hcd_is_pipe_out(struct dwc2_hcd_pipe_info *pipe) | ||
448 | { | ||
449 | return !dwc2_hcd_is_pipe_in(pipe); | ||
450 | } | ||
451 | |||
452 | extern int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq, | ||
453 | const struct dwc2_core_params *params); | ||
454 | extern void dwc2_hcd_remove(struct dwc2_hsotg *hsotg); | ||
455 | extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg, | ||
456 | const struct dwc2_core_params *params); | ||
457 | extern void dwc2_set_all_params(struct dwc2_core_params *params, int value); | ||
458 | extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg); | ||
459 | |||
460 | /* Transaction Execution Functions */ | ||
461 | extern enum dwc2_transaction_type dwc2_hcd_select_transactions( | ||
462 | struct dwc2_hsotg *hsotg); | ||
463 | extern void dwc2_hcd_queue_transactions(struct dwc2_hsotg *hsotg, | ||
464 | enum dwc2_transaction_type tr_type); | ||
465 | |||
466 | /* Schedule Queue Functions */ | ||
467 | /* Implemented in hcd_queue.c */ | ||
468 | extern void dwc2_hcd_init_usecs(struct dwc2_hsotg *hsotg); | ||
469 | extern void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh); | ||
470 | extern int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh); | ||
471 | extern void dwc2_hcd_qh_unlink(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh); | ||
472 | extern void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, | ||
473 | int sched_csplit); | ||
474 | |||
475 | extern void dwc2_hcd_qtd_init(struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb); | ||
476 | extern int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, | ||
477 | struct dwc2_qh **qh, gfp_t mem_flags); | ||
478 | |||
479 | /* Unlinks and frees a QTD */ | ||
480 | static inline void dwc2_hcd_qtd_unlink_and_free(struct dwc2_hsotg *hsotg, | ||
481 | struct dwc2_qtd *qtd, | ||
482 | struct dwc2_qh *qh) | ||
483 | { | ||
484 | list_del(&qtd->qtd_list_entry); | ||
485 | kfree(qtd); | ||
486 | } | ||
487 | |||
488 | /* Descriptor DMA support functions */ | ||
489 | extern void dwc2_hcd_start_xfer_ddma(struct dwc2_hsotg *hsotg, | ||
490 | struct dwc2_qh *qh); | ||
491 | extern void dwc2_hcd_complete_xfer_ddma(struct dwc2_hsotg *hsotg, | ||
492 | struct dwc2_host_chan *chan, int chnum, | ||
493 | enum dwc2_halt_status halt_status); | ||
494 | |||
495 | extern int dwc2_hcd_qh_init_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, | ||
496 | gfp_t mem_flags); | ||
497 | extern void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh); | ||
498 | |||
499 | /* Check if QH is non-periodic */ | ||
500 | #define dwc2_qh_is_non_per(_qh_ptr_) \ | ||
501 | ((_qh_ptr_)->ep_type == USB_ENDPOINT_XFER_BULK || \ | ||
502 | (_qh_ptr_)->ep_type == USB_ENDPOINT_XFER_CONTROL) | ||
503 | |||
504 | #ifdef CONFIG_USB_DWC2_DEBUG_PERIODIC | ||
505 | static inline bool dbg_hc(struct dwc2_host_chan *hc) { return true; } | ||
506 | static inline bool dbg_qh(struct dwc2_qh *qh) { return true; } | ||
507 | static inline bool dbg_urb(struct urb *urb) { return true; } | ||
508 | static inline bool dbg_perio(void) { return true; } | ||
509 | #else /* !CONFIG_USB_DWC2_DEBUG_PERIODIC */ | ||
510 | static inline bool dbg_hc(struct dwc2_host_chan *hc) | ||
511 | { | ||
512 | return hc->ep_type == USB_ENDPOINT_XFER_BULK || | ||
513 | hc->ep_type == USB_ENDPOINT_XFER_CONTROL; | ||
514 | } | ||
515 | |||
516 | static inline bool dbg_qh(struct dwc2_qh *qh) | ||
517 | { | ||
518 | return qh->ep_type == USB_ENDPOINT_XFER_BULK || | ||
519 | qh->ep_type == USB_ENDPOINT_XFER_CONTROL; | ||
520 | } | ||
521 | |||
522 | static inline bool dbg_urb(struct urb *urb) | ||
523 | { | ||
524 | return usb_pipetype(urb->pipe) == PIPE_BULK || | ||
525 | usb_pipetype(urb->pipe) == PIPE_CONTROL; | ||
526 | } | ||
527 | |||
528 | static inline bool dbg_perio(void) { return false; } | ||
529 | #endif | ||
530 | |||
531 | /* High bandwidth multiplier as encoded in highspeed endpoint descriptors */ | ||
532 | #define dwc2_hb_mult(wmaxpacketsize) (1 + (((wmaxpacketsize) >> 11) & 0x03)) | ||
533 | |||
534 | /* Packet size for any kind of endpoint descriptor */ | ||
535 | #define dwc2_max_packet(wmaxpacketsize) ((wmaxpacketsize) & 0x07ff) | ||
536 | |||
537 | /* | ||
538 | * Returns true if frame1 is less than or equal to frame2. The comparison is | ||
539 | * done modulo HFNUM_MAX_FRNUM. This accounts for the rollover of the | ||
540 | * frame number when the max frame number is reached. | ||
541 | */ | ||
542 | static inline int dwc2_frame_num_le(u16 frame1, u16 frame2) | ||
543 | { | ||
544 | return ((frame2 - frame1) & HFNUM_MAX_FRNUM) <= (HFNUM_MAX_FRNUM >> 1); | ||
545 | } | ||
546 | |||
547 | /* | ||
548 | * Returns true if frame1 is greater than frame2. The comparison is done | ||
549 | * modulo HFNUM_MAX_FRNUM. This accounts for the rollover of the frame | ||
550 | * number when the max frame number is reached. | ||
551 | */ | ||
552 | static inline int dwc2_frame_num_gt(u16 frame1, u16 frame2) | ||
553 | { | ||
554 | return (frame1 != frame2) && | ||
555 | ((frame1 - frame2) & HFNUM_MAX_FRNUM) < (HFNUM_MAX_FRNUM >> 1); | ||
556 | } | ||
557 | |||
558 | /* | ||
559 | * Increments frame by the amount specified by inc. The addition is done | ||
560 | * modulo HFNUM_MAX_FRNUM. Returns the incremented value. | ||
561 | */ | ||
562 | static inline u16 dwc2_frame_num_inc(u16 frame, u16 inc) | ||
563 | { | ||
564 | return (frame + inc) & HFNUM_MAX_FRNUM; | ||
565 | } | ||
566 | |||
567 | static inline u16 dwc2_full_frame_num(u16 frame) | ||
568 | { | ||
569 | return (frame & HFNUM_MAX_FRNUM) >> 3; | ||
570 | } | ||
571 | |||
572 | static inline u16 dwc2_micro_frame_num(u16 frame) | ||
573 | { | ||
574 | return frame & 0x7; | ||
575 | } | ||
576 | |||
577 | /* | ||
578 | * Returns the Core Interrupt Status register contents, ANDed with the Core | ||
579 | * Interrupt Mask register contents | ||
580 | */ | ||
581 | static inline u32 dwc2_read_core_intr(struct dwc2_hsotg *hsotg) | ||
582 | { | ||
583 | return readl(hsotg->regs + GINTSTS) & readl(hsotg->regs + GINTMSK); | ||
584 | } | ||
585 | |||
586 | static inline u32 dwc2_hcd_urb_get_status(struct dwc2_hcd_urb *dwc2_urb) | ||
587 | { | ||
588 | return dwc2_urb->status; | ||
589 | } | ||
590 | |||
591 | static inline u32 dwc2_hcd_urb_get_actual_length( | ||
592 | struct dwc2_hcd_urb *dwc2_urb) | ||
593 | { | ||
594 | return dwc2_urb->actual_length; | ||
595 | } | ||
596 | |||
597 | static inline u32 dwc2_hcd_urb_get_error_count(struct dwc2_hcd_urb *dwc2_urb) | ||
598 | { | ||
599 | return dwc2_urb->error_count; | ||
600 | } | ||
601 | |||
602 | static inline void dwc2_hcd_urb_set_iso_desc_params( | ||
603 | struct dwc2_hcd_urb *dwc2_urb, int desc_num, u32 offset, | ||
604 | u32 length) | ||
605 | { | ||
606 | dwc2_urb->iso_descs[desc_num].offset = offset; | ||
607 | dwc2_urb->iso_descs[desc_num].length = length; | ||
608 | } | ||
609 | |||
610 | static inline u32 dwc2_hcd_urb_get_iso_desc_status( | ||
611 | struct dwc2_hcd_urb *dwc2_urb, int desc_num) | ||
612 | { | ||
613 | return dwc2_urb->iso_descs[desc_num].status; | ||
614 | } | ||
615 | |||
616 | static inline u32 dwc2_hcd_urb_get_iso_desc_actual_length( | ||
617 | struct dwc2_hcd_urb *dwc2_urb, int desc_num) | ||
618 | { | ||
619 | return dwc2_urb->iso_descs[desc_num].actual_length; | ||
620 | } | ||
621 | |||
622 | static inline int dwc2_hcd_is_bandwidth_allocated(struct dwc2_hsotg *hsotg, | ||
623 | struct usb_host_endpoint *ep) | ||
624 | { | ||
625 | struct dwc2_qh *qh = ep->hcpriv; | ||
626 | |||
627 | if (qh && !list_empty(&qh->qh_list_entry)) | ||
628 | return 1; | ||
629 | |||
630 | return 0; | ||
631 | } | ||
632 | |||
633 | static inline u16 dwc2_hcd_get_ep_bandwidth(struct dwc2_hsotg *hsotg, | ||
634 | struct usb_host_endpoint *ep) | ||
635 | { | ||
636 | struct dwc2_qh *qh = ep->hcpriv; | ||
637 | |||
638 | if (!qh) { | ||
639 | WARN_ON(1); | ||
640 | return 0; | ||
641 | } | ||
642 | |||
643 | return qh->usecs; | ||
644 | } | ||
645 | |||
646 | extern void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg, | ||
647 | struct dwc2_host_chan *chan, int chnum, | ||
648 | struct dwc2_qtd *qtd); | ||
649 | |||
650 | /* HCD Core API */ | ||
651 | |||
652 | /** | ||
653 | * dwc2_handle_hcd_intr() - Called on every hardware interrupt | ||
654 | * | ||
655 | * @hsotg: The DWC2 HCD | ||
656 | * | ||
657 | * Returns IRQ_HANDLED if interrupt is handled | ||
658 | * Return IRQ_NONE if interrupt is not handled | ||
659 | */ | ||
660 | extern irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg); | ||
661 | |||
662 | /** | ||
663 | * dwc2_hcd_stop() - Halts the DWC_otg host mode operation | ||
664 | * | ||
665 | * @hsotg: The DWC2 HCD | ||
666 | */ | ||
667 | extern void dwc2_hcd_stop(struct dwc2_hsotg *hsotg); | ||
668 | |||
669 | extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg); | ||
670 | extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg); | ||
671 | |||
672 | /** | ||
673 | * dwc2_hcd_is_b_host() - Returns 1 if core currently is acting as B host, | ||
674 | * and 0 otherwise | ||
675 | * | ||
676 | * @hsotg: The DWC2 HCD | ||
677 | */ | ||
678 | extern int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg); | ||
679 | |||
680 | /** | ||
681 | * dwc2_hcd_get_frame_number() - Returns current frame number | ||
682 | * | ||
683 | * @hsotg: The DWC2 HCD | ||
684 | */ | ||
685 | extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg); | ||
686 | |||
687 | /** | ||
688 | * dwc2_hcd_dump_state() - Dumps hsotg state | ||
689 | * | ||
690 | * @hsotg: The DWC2 HCD | ||
691 | * | ||
692 | * NOTE: This function will be removed once the peripheral controller code | ||
693 | * is integrated and the driver is stable | ||
694 | */ | ||
695 | extern void dwc2_hcd_dump_state(struct dwc2_hsotg *hsotg); | ||
696 | |||
697 | /** | ||
698 | * dwc2_hcd_dump_frrem() - Dumps the average frame remaining at SOF | ||
699 | * | ||
700 | * @hsotg: The DWC2 HCD | ||
701 | * | ||
702 | * This can be used to determine average interrupt latency. Frame remaining is | ||
703 | * also shown for start transfer and two additional sample points. | ||
704 | * | ||
705 | * NOTE: This function will be removed once the peripheral controller code | ||
706 | * is integrated and the driver is stable | ||
707 | */ | ||
708 | extern void dwc2_hcd_dump_frrem(struct dwc2_hsotg *hsotg); | ||
709 | |||
710 | /* URB interface */ | ||
711 | |||
712 | /* Transfer flags */ | ||
713 | #define URB_GIVEBACK_ASAP 0x1 | ||
714 | #define URB_SEND_ZERO_PACKET 0x2 | ||
715 | |||
716 | /* Host driver callbacks */ | ||
717 | |||
718 | extern void dwc2_host_start(struct dwc2_hsotg *hsotg); | ||
719 | extern void dwc2_host_disconnect(struct dwc2_hsotg *hsotg); | ||
720 | extern void dwc2_host_hub_info(struct dwc2_hsotg *hsotg, void *context, | ||
721 | int *hub_addr, int *hub_port); | ||
722 | extern int dwc2_host_get_speed(struct dwc2_hsotg *hsotg, void *context); | ||
723 | extern void dwc2_host_complete(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, | ||
724 | int status); | ||
725 | |||
726 | #ifdef DEBUG | ||
727 | /* | ||
728 | * Macro to sample the remaining PHY clocks left in the current frame. This | ||
729 | * may be used during debugging to determine the average time it takes to | ||
730 | * execute sections of code. There are two possible sample points, "a" and | ||
731 | * "b", so the _letter_ argument must be one of these values. | ||
732 | * | ||
733 | * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For | ||
734 | * example, "cat /sys/devices/lm0/hcd_frrem". | ||
735 | */ | ||
736 | #define dwc2_sample_frrem(_hcd_, _qh_, _letter_) \ | ||
737 | do { \ | ||
738 | struct hfnum_data _hfnum_; \ | ||
739 | struct dwc2_qtd *_qtd_; \ | ||
740 | \ | ||
741 | _qtd_ = list_entry((_qh_)->qtd_list.next, struct dwc2_qtd, \ | ||
742 | qtd_list_entry); \ | ||
743 | if (usb_pipeint(_qtd_->urb->pipe) && \ | ||
744 | (_qh_)->start_split_frame != 0 && !_qtd_->complete_split) { \ | ||
745 | _hfnum_.d32 = readl((_hcd_)->regs + HFNUM); \ | ||
746 | switch (_hfnum_.b.frnum & 0x7) { \ | ||
747 | case 7: \ | ||
748 | (_hcd_)->hfnum_7_samples_##_letter_++; \ | ||
749 | (_hcd_)->hfnum_7_frrem_accum_##_letter_ += \ | ||
750 | _hfnum_.b.frrem; \ | ||
751 | break; \ | ||
752 | case 0: \ | ||
753 | (_hcd_)->hfnum_0_samples_##_letter_++; \ | ||
754 | (_hcd_)->hfnum_0_frrem_accum_##_letter_ += \ | ||
755 | _hfnum_.b.frrem; \ | ||
756 | break; \ | ||
757 | default: \ | ||
758 | (_hcd_)->hfnum_other_samples_##_letter_++; \ | ||
759 | (_hcd_)->hfnum_other_frrem_accum_##_letter_ += \ | ||
760 | _hfnum_.b.frrem; \ | ||
761 | break; \ | ||
762 | } \ | ||
763 | } \ | ||
764 | } while (0) | ||
765 | #else | ||
766 | #define dwc2_sample_frrem(_hcd_, _qh_, _letter_) do {} while (0) | ||
767 | #endif | ||
768 | |||
769 | #endif /* __DWC2_HCD_H__ */ | ||
diff --git a/drivers/usb/dwc2/hcd_ddma.c b/drivers/usb/dwc2/hcd_ddma.c new file mode 100644 index 000000000000..3376177e4d3c --- /dev/null +++ b/drivers/usb/dwc2/hcd_ddma.c | |||
@@ -0,0 +1,1212 @@ | |||
1 | /* | ||
2 | * hcd_ddma.c - DesignWare HS OTG Controller descriptor DMA routines | ||
3 | * | ||
4 | * Copyright (C) 2004-2013 Synopsys, Inc. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions, and the following disclaimer, | ||
11 | * without modification. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The names of the above-listed copyright holders may not be used | ||
16 | * to endorse or promote products derived from this software without | ||
17 | * specific prior written permission. | ||
18 | * | ||
19 | * ALTERNATIVELY, this software may be distributed under the terms of the | ||
20 | * GNU General Public License ("GPL") as published by the Free Software | ||
21 | * Foundation; either version 2 of the License, or (at your option) any | ||
22 | * later version. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
26 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
35 | */ | ||
36 | |||
37 | /* | ||
38 | * This file contains the Descriptor DMA implementation for Host mode | ||
39 | */ | ||
40 | #include <linux/kernel.h> | ||
41 | #include <linux/module.h> | ||
42 | #include <linux/spinlock.h> | ||
43 | #include <linux/interrupt.h> | ||
44 | #include <linux/dma-mapping.h> | ||
45 | #include <linux/io.h> | ||
46 | #include <linux/slab.h> | ||
47 | #include <linux/usb.h> | ||
48 | |||
49 | #include <linux/usb/hcd.h> | ||
50 | #include <linux/usb/ch11.h> | ||
51 | |||
52 | #include "core.h" | ||
53 | #include "hcd.h" | ||
54 | |||
55 | static u16 dwc2_frame_list_idx(u16 frame) | ||
56 | { | ||
57 | return frame & (FRLISTEN_64_SIZE - 1); | ||
58 | } | ||
59 | |||
60 | static u16 dwc2_desclist_idx_inc(u16 idx, u16 inc, u8 speed) | ||
61 | { | ||
62 | return (idx + inc) & | ||
63 | ((speed == USB_SPEED_HIGH ? MAX_DMA_DESC_NUM_HS_ISOC : | ||
64 | MAX_DMA_DESC_NUM_GENERIC) - 1); | ||
65 | } | ||
66 | |||
67 | static u16 dwc2_desclist_idx_dec(u16 idx, u16 inc, u8 speed) | ||
68 | { | ||
69 | return (idx - inc) & | ||
70 | ((speed == USB_SPEED_HIGH ? MAX_DMA_DESC_NUM_HS_ISOC : | ||
71 | MAX_DMA_DESC_NUM_GENERIC) - 1); | ||
72 | } | ||
73 | |||
74 | static u16 dwc2_max_desc_num(struct dwc2_qh *qh) | ||
75 | { | ||
76 | return (qh->ep_type == USB_ENDPOINT_XFER_ISOC && | ||
77 | qh->dev_speed == USB_SPEED_HIGH) ? | ||
78 | MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC; | ||
79 | } | ||
80 | |||
81 | static u16 dwc2_frame_incr_val(struct dwc2_qh *qh) | ||
82 | { | ||
83 | return qh->dev_speed == USB_SPEED_HIGH ? | ||
84 | (qh->interval + 8 - 1) / 8 : qh->interval; | ||
85 | } | ||
86 | |||
87 | static int dwc2_desc_list_alloc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, | ||
88 | gfp_t flags) | ||
89 | { | ||
90 | qh->desc_list = dma_alloc_coherent(hsotg->dev, | ||
91 | sizeof(struct dwc2_hcd_dma_desc) * | ||
92 | dwc2_max_desc_num(qh), &qh->desc_list_dma, | ||
93 | flags); | ||
94 | |||
95 | if (!qh->desc_list) | ||
96 | return -ENOMEM; | ||
97 | |||
98 | memset(qh->desc_list, 0, | ||
99 | sizeof(struct dwc2_hcd_dma_desc) * dwc2_max_desc_num(qh)); | ||
100 | |||
101 | qh->n_bytes = kzalloc(sizeof(u32) * dwc2_max_desc_num(qh), flags); | ||
102 | if (!qh->n_bytes) { | ||
103 | dma_free_coherent(hsotg->dev, sizeof(struct dwc2_hcd_dma_desc) | ||
104 | * dwc2_max_desc_num(qh), qh->desc_list, | ||
105 | qh->desc_list_dma); | ||
106 | qh->desc_list = NULL; | ||
107 | return -ENOMEM; | ||
108 | } | ||
109 | |||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | static void dwc2_desc_list_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | ||
114 | { | ||
115 | if (qh->desc_list) { | ||
116 | dma_free_coherent(hsotg->dev, sizeof(struct dwc2_hcd_dma_desc) | ||
117 | * dwc2_max_desc_num(qh), qh->desc_list, | ||
118 | qh->desc_list_dma); | ||
119 | qh->desc_list = NULL; | ||
120 | } | ||
121 | |||
122 | kfree(qh->n_bytes); | ||
123 | qh->n_bytes = NULL; | ||
124 | } | ||
125 | |||
126 | static int dwc2_frame_list_alloc(struct dwc2_hsotg *hsotg, gfp_t mem_flags) | ||
127 | { | ||
128 | if (hsotg->frame_list) | ||
129 | return 0; | ||
130 | |||
131 | hsotg->frame_list = dma_alloc_coherent(hsotg->dev, | ||
132 | 4 * FRLISTEN_64_SIZE, | ||
133 | &hsotg->frame_list_dma, | ||
134 | mem_flags); | ||
135 | if (!hsotg->frame_list) | ||
136 | return -ENOMEM; | ||
137 | |||
138 | memset(hsotg->frame_list, 0, 4 * FRLISTEN_64_SIZE); | ||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | static void dwc2_frame_list_free(struct dwc2_hsotg *hsotg) | ||
143 | { | ||
144 | u32 *frame_list; | ||
145 | dma_addr_t frame_list_dma; | ||
146 | unsigned long flags; | ||
147 | |||
148 | spin_lock_irqsave(&hsotg->lock, flags); | ||
149 | |||
150 | if (!hsotg->frame_list) { | ||
151 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
152 | return; | ||
153 | } | ||
154 | |||
155 | frame_list = hsotg->frame_list; | ||
156 | frame_list_dma = hsotg->frame_list_dma; | ||
157 | hsotg->frame_list = NULL; | ||
158 | |||
159 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
160 | |||
161 | dma_free_coherent(hsotg->dev, 4 * FRLISTEN_64_SIZE, frame_list, | ||
162 | frame_list_dma); | ||
163 | } | ||
164 | |||
165 | static void dwc2_per_sched_enable(struct dwc2_hsotg *hsotg, u32 fr_list_en) | ||
166 | { | ||
167 | u32 hcfg; | ||
168 | unsigned long flags; | ||
169 | |||
170 | spin_lock_irqsave(&hsotg->lock, flags); | ||
171 | |||
172 | hcfg = readl(hsotg->regs + HCFG); | ||
173 | if (hcfg & HCFG_PERSCHEDENA) { | ||
174 | /* already enabled */ | ||
175 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
176 | return; | ||
177 | } | ||
178 | |||
179 | writel(hsotg->frame_list_dma, hsotg->regs + HFLBADDR); | ||
180 | |||
181 | hcfg &= ~HCFG_FRLISTEN_MASK; | ||
182 | hcfg |= fr_list_en | HCFG_PERSCHEDENA; | ||
183 | dev_vdbg(hsotg->dev, "Enabling Periodic schedule\n"); | ||
184 | writel(hcfg, hsotg->regs + HCFG); | ||
185 | |||
186 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
187 | } | ||
188 | |||
189 | static void dwc2_per_sched_disable(struct dwc2_hsotg *hsotg) | ||
190 | { | ||
191 | u32 hcfg; | ||
192 | unsigned long flags; | ||
193 | |||
194 | spin_lock_irqsave(&hsotg->lock, flags); | ||
195 | |||
196 | hcfg = readl(hsotg->regs + HCFG); | ||
197 | if (!(hcfg & HCFG_PERSCHEDENA)) { | ||
198 | /* already disabled */ | ||
199 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
200 | return; | ||
201 | } | ||
202 | |||
203 | hcfg &= ~HCFG_PERSCHEDENA; | ||
204 | dev_vdbg(hsotg->dev, "Disabling Periodic schedule\n"); | ||
205 | writel(hcfg, hsotg->regs + HCFG); | ||
206 | |||
207 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
208 | } | ||
209 | |||
210 | /* | ||
211 | * Activates/Deactivates FrameList entries for the channel based on endpoint | ||
212 | * servicing period | ||
213 | */ | ||
214 | static void dwc2_update_frame_list(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, | ||
215 | int enable) | ||
216 | { | ||
217 | struct dwc2_host_chan *chan; | ||
218 | u16 i, j, inc; | ||
219 | |||
220 | if (!hsotg) { | ||
221 | pr_err("hsotg = %p\n", hsotg); | ||
222 | return; | ||
223 | } | ||
224 | |||
225 | if (!qh->channel) { | ||
226 | dev_err(hsotg->dev, "qh->channel = %p\n", qh->channel); | ||
227 | return; | ||
228 | } | ||
229 | |||
230 | if (!hsotg->frame_list) { | ||
231 | dev_err(hsotg->dev, "hsotg->frame_list = %p\n", | ||
232 | hsotg->frame_list); | ||
233 | return; | ||
234 | } | ||
235 | |||
236 | chan = qh->channel; | ||
237 | inc = dwc2_frame_incr_val(qh); | ||
238 | if (qh->ep_type == USB_ENDPOINT_XFER_ISOC) | ||
239 | i = dwc2_frame_list_idx(qh->sched_frame); | ||
240 | else | ||
241 | i = 0; | ||
242 | |||
243 | j = i; | ||
244 | do { | ||
245 | if (enable) | ||
246 | hsotg->frame_list[j] |= 1 << chan->hc_num; | ||
247 | else | ||
248 | hsotg->frame_list[j] &= ~(1 << chan->hc_num); | ||
249 | j = (j + inc) & (FRLISTEN_64_SIZE - 1); | ||
250 | } while (j != i); | ||
251 | |||
252 | if (!enable) | ||
253 | return; | ||
254 | |||
255 | chan->schinfo = 0; | ||
256 | if (chan->speed == USB_SPEED_HIGH && qh->interval) { | ||
257 | j = 1; | ||
258 | /* TODO - check this */ | ||
259 | inc = (8 + qh->interval - 1) / qh->interval; | ||
260 | for (i = 0; i < inc; i++) { | ||
261 | chan->schinfo |= j; | ||
262 | j = j << qh->interval; | ||
263 | } | ||
264 | } else { | ||
265 | chan->schinfo = 0xff; | ||
266 | } | ||
267 | } | ||
268 | |||
269 | static void dwc2_release_channel_ddma(struct dwc2_hsotg *hsotg, | ||
270 | struct dwc2_qh *qh) | ||
271 | { | ||
272 | struct dwc2_host_chan *chan = qh->channel; | ||
273 | |||
274 | if (dwc2_qh_is_non_per(qh)) { | ||
275 | if (hsotg->core_params->uframe_sched > 0) | ||
276 | hsotg->available_host_channels++; | ||
277 | else | ||
278 | hsotg->non_periodic_channels--; | ||
279 | } else { | ||
280 | dwc2_update_frame_list(hsotg, qh, 0); | ||
281 | } | ||
282 | |||
283 | /* | ||
284 | * The condition is added to prevent double cleanup try in case of | ||
285 | * device disconnect. See channel cleanup in dwc2_hcd_disconnect(). | ||
286 | */ | ||
287 | if (chan->qh) { | ||
288 | if (!list_empty(&chan->hc_list_entry)) | ||
289 | list_del(&chan->hc_list_entry); | ||
290 | dwc2_hc_cleanup(hsotg, chan); | ||
291 | list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list); | ||
292 | chan->qh = NULL; | ||
293 | } | ||
294 | |||
295 | qh->channel = NULL; | ||
296 | qh->ntd = 0; | ||
297 | |||
298 | if (qh->desc_list) | ||
299 | memset(qh->desc_list, 0, sizeof(struct dwc2_hcd_dma_desc) * | ||
300 | dwc2_max_desc_num(qh)); | ||
301 | } | ||
302 | |||
303 | /** | ||
304 | * dwc2_hcd_qh_init_ddma() - Initializes a QH structure's Descriptor DMA | ||
305 | * related members | ||
306 | * | ||
307 | * @hsotg: The HCD state structure for the DWC OTG controller | ||
308 | * @qh: The QH to init | ||
309 | * | ||
310 | * Return: 0 if successful, negative error code otherwise | ||
311 | * | ||
312 | * Allocates memory for the descriptor list. For the first periodic QH, | ||
313 | * allocates memory for the FrameList and enables periodic scheduling. | ||
314 | */ | ||
315 | int dwc2_hcd_qh_init_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, | ||
316 | gfp_t mem_flags) | ||
317 | { | ||
318 | int retval; | ||
319 | |||
320 | if (qh->do_split) { | ||
321 | dev_err(hsotg->dev, | ||
322 | "SPLIT Transfers are not supported in Descriptor DMA mode.\n"); | ||
323 | retval = -EINVAL; | ||
324 | goto err0; | ||
325 | } | ||
326 | |||
327 | retval = dwc2_desc_list_alloc(hsotg, qh, mem_flags); | ||
328 | if (retval) | ||
329 | goto err0; | ||
330 | |||
331 | if (qh->ep_type == USB_ENDPOINT_XFER_ISOC || | ||
332 | qh->ep_type == USB_ENDPOINT_XFER_INT) { | ||
333 | if (!hsotg->frame_list) { | ||
334 | retval = dwc2_frame_list_alloc(hsotg, mem_flags); | ||
335 | if (retval) | ||
336 | goto err1; | ||
337 | /* Enable periodic schedule on first periodic QH */ | ||
338 | dwc2_per_sched_enable(hsotg, HCFG_FRLISTEN_64); | ||
339 | } | ||
340 | } | ||
341 | |||
342 | qh->ntd = 0; | ||
343 | return 0; | ||
344 | |||
345 | err1: | ||
346 | dwc2_desc_list_free(hsotg, qh); | ||
347 | err0: | ||
348 | return retval; | ||
349 | } | ||
350 | |||
351 | /** | ||
352 | * dwc2_hcd_qh_free_ddma() - Frees a QH structure's Descriptor DMA related | ||
353 | * members | ||
354 | * | ||
355 | * @hsotg: The HCD state structure for the DWC OTG controller | ||
356 | * @qh: The QH to free | ||
357 | * | ||
358 | * Frees descriptor list memory associated with the QH. If QH is periodic and | ||
359 | * the last, frees FrameList memory and disables periodic scheduling. | ||
360 | */ | ||
361 | void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | ||
362 | { | ||
363 | dwc2_desc_list_free(hsotg, qh); | ||
364 | |||
365 | /* | ||
366 | * Channel still assigned due to some reasons. | ||
367 | * Seen on Isoc URB dequeue. Channel halted but no subsequent | ||
368 | * ChHalted interrupt to release the channel. Afterwards | ||
369 | * when it comes here from endpoint disable routine | ||
370 | * channel remains assigned. | ||
371 | */ | ||
372 | if (qh->channel) | ||
373 | dwc2_release_channel_ddma(hsotg, qh); | ||
374 | |||
375 | if ((qh->ep_type == USB_ENDPOINT_XFER_ISOC || | ||
376 | qh->ep_type == USB_ENDPOINT_XFER_INT) && | ||
377 | (hsotg->core_params->uframe_sched > 0 || | ||
378 | !hsotg->periodic_channels) && hsotg->frame_list) { | ||
379 | dwc2_per_sched_disable(hsotg); | ||
380 | dwc2_frame_list_free(hsotg); | ||
381 | } | ||
382 | } | ||
383 | |||
384 | static u8 dwc2_frame_to_desc_idx(struct dwc2_qh *qh, u16 frame_idx) | ||
385 | { | ||
386 | if (qh->dev_speed == USB_SPEED_HIGH) | ||
387 | /* Descriptor set (8 descriptors) index which is 8-aligned */ | ||
388 | return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8; | ||
389 | else | ||
390 | return frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1); | ||
391 | } | ||
392 | |||
393 | /* | ||
394 | * Determine starting frame for Isochronous transfer. | ||
395 | * Few frames skipped to prevent race condition with HC. | ||
396 | */ | ||
397 | static u16 dwc2_calc_starting_frame(struct dwc2_hsotg *hsotg, | ||
398 | struct dwc2_qh *qh, u16 *skip_frames) | ||
399 | { | ||
400 | u16 frame; | ||
401 | |||
402 | hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg); | ||
403 | |||
404 | /* sched_frame is always frame number (not uFrame) both in FS and HS! */ | ||
405 | |||
406 | /* | ||
407 | * skip_frames is used to limit activated descriptors number | ||
408 | * to avoid the situation when HC services the last activated | ||
409 | * descriptor firstly. | ||
410 | * Example for FS: | ||
411 | * Current frame is 1, scheduled frame is 3. Since HC always fetches | ||
412 | * the descriptor corresponding to curr_frame+1, the descriptor | ||
413 | * corresponding to frame 2 will be fetched. If the number of | ||
414 | * descriptors is max=64 (or greather) the list will be fully programmed | ||
415 | * with Active descriptors and it is possible case (rare) that the | ||
416 | * latest descriptor(considering rollback) corresponding to frame 2 will | ||
417 | * be serviced first. HS case is more probable because, in fact, up to | ||
418 | * 11 uframes (16 in the code) may be skipped. | ||
419 | */ | ||
420 | if (qh->dev_speed == USB_SPEED_HIGH) { | ||
421 | /* | ||
422 | * Consider uframe counter also, to start xfer asap. If half of | ||
423 | * the frame elapsed skip 2 frames otherwise just 1 frame. | ||
424 | * Starting descriptor index must be 8-aligned, so if the | ||
425 | * current frame is near to complete the next one is skipped as | ||
426 | * well. | ||
427 | */ | ||
428 | if (dwc2_micro_frame_num(hsotg->frame_number) >= 5) { | ||
429 | *skip_frames = 2 * 8; | ||
430 | frame = dwc2_frame_num_inc(hsotg->frame_number, | ||
431 | *skip_frames); | ||
432 | } else { | ||
433 | *skip_frames = 1 * 8; | ||
434 | frame = dwc2_frame_num_inc(hsotg->frame_number, | ||
435 | *skip_frames); | ||
436 | } | ||
437 | |||
438 | frame = dwc2_full_frame_num(frame); | ||
439 | } else { | ||
440 | /* | ||
441 | * Two frames are skipped for FS - the current and the next. | ||
442 | * But for descriptor programming, 1 frame (descriptor) is | ||
443 | * enough, see example above. | ||
444 | */ | ||
445 | *skip_frames = 1; | ||
446 | frame = dwc2_frame_num_inc(hsotg->frame_number, 2); | ||
447 | } | ||
448 | |||
449 | return frame; | ||
450 | } | ||
451 | |||
452 | /* | ||
453 | * Calculate initial descriptor index for isochronous transfer based on | ||
454 | * scheduled frame | ||
455 | */ | ||
456 | static u16 dwc2_recalc_initial_desc_idx(struct dwc2_hsotg *hsotg, | ||
457 | struct dwc2_qh *qh) | ||
458 | { | ||
459 | u16 frame, fr_idx, fr_idx_tmp, skip_frames; | ||
460 | |||
461 | /* | ||
462 | * With current ISOC processing algorithm the channel is being released | ||
463 | * when no more QTDs in the list (qh->ntd == 0). Thus this function is | ||
464 | * called only when qh->ntd == 0 and qh->channel == 0. | ||
465 | * | ||
466 | * So qh->channel != NULL branch is not used and just not removed from | ||
467 | * the source file. It is required for another possible approach which | ||
468 | * is, do not disable and release the channel when ISOC session | ||
469 | * completed, just move QH to inactive schedule until new QTD arrives. | ||
470 | * On new QTD, the QH moved back to 'ready' schedule, starting frame and | ||
471 | * therefore starting desc_index are recalculated. In this case channel | ||
472 | * is released only on ep_disable. | ||
473 | */ | ||
474 | |||
475 | /* | ||
476 | * Calculate starting descriptor index. For INTERRUPT endpoint it is | ||
477 | * always 0. | ||
478 | */ | ||
479 | if (qh->channel) { | ||
480 | frame = dwc2_calc_starting_frame(hsotg, qh, &skip_frames); | ||
481 | /* | ||
482 | * Calculate initial descriptor index based on FrameList current | ||
483 | * bitmap and servicing period | ||
484 | */ | ||
485 | fr_idx_tmp = dwc2_frame_list_idx(frame); | ||
486 | fr_idx = (FRLISTEN_64_SIZE + | ||
487 | dwc2_frame_list_idx(qh->sched_frame) - fr_idx_tmp) | ||
488 | % dwc2_frame_incr_val(qh); | ||
489 | fr_idx = (fr_idx + fr_idx_tmp) % FRLISTEN_64_SIZE; | ||
490 | } else { | ||
491 | qh->sched_frame = dwc2_calc_starting_frame(hsotg, qh, | ||
492 | &skip_frames); | ||
493 | fr_idx = dwc2_frame_list_idx(qh->sched_frame); | ||
494 | } | ||
495 | |||
496 | qh->td_first = qh->td_last = dwc2_frame_to_desc_idx(qh, fr_idx); | ||
497 | |||
498 | return skip_frames; | ||
499 | } | ||
500 | |||
501 | #define ISOC_URB_GIVEBACK_ASAP | ||
502 | |||
503 | #define MAX_ISOC_XFER_SIZE_FS 1023 | ||
504 | #define MAX_ISOC_XFER_SIZE_HS 3072 | ||
505 | #define DESCNUM_THRESHOLD 4 | ||
506 | |||
507 | static void dwc2_fill_host_isoc_dma_desc(struct dwc2_hsotg *hsotg, | ||
508 | struct dwc2_qtd *qtd, | ||
509 | struct dwc2_qh *qh, u32 max_xfer_size, | ||
510 | u16 idx) | ||
511 | { | ||
512 | struct dwc2_hcd_dma_desc *dma_desc = &qh->desc_list[idx]; | ||
513 | struct dwc2_hcd_iso_packet_desc *frame_desc; | ||
514 | |||
515 | memset(dma_desc, 0, sizeof(*dma_desc)); | ||
516 | frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last]; | ||
517 | |||
518 | if (frame_desc->length > max_xfer_size) | ||
519 | qh->n_bytes[idx] = max_xfer_size; | ||
520 | else | ||
521 | qh->n_bytes[idx] = frame_desc->length; | ||
522 | |||
523 | dma_desc->buf = (u32)(qtd->urb->dma + frame_desc->offset); | ||
524 | dma_desc->status = qh->n_bytes[idx] << HOST_DMA_ISOC_NBYTES_SHIFT & | ||
525 | HOST_DMA_ISOC_NBYTES_MASK; | ||
526 | |||
527 | #ifdef ISOC_URB_GIVEBACK_ASAP | ||
528 | /* Set IOC for each descriptor corresponding to last frame of URB */ | ||
529 | if (qtd->isoc_frame_index_last == qtd->urb->packet_count) | ||
530 | dma_desc->status |= HOST_DMA_IOC; | ||
531 | #endif | ||
532 | |||
533 | qh->ntd++; | ||
534 | qtd->isoc_frame_index_last++; | ||
535 | } | ||
536 | |||
537 | static void dwc2_init_isoc_dma_desc(struct dwc2_hsotg *hsotg, | ||
538 | struct dwc2_qh *qh, u16 skip_frames) | ||
539 | { | ||
540 | struct dwc2_qtd *qtd; | ||
541 | u32 max_xfer_size; | ||
542 | u16 idx, inc, n_desc, ntd_max = 0; | ||
543 | |||
544 | idx = qh->td_last; | ||
545 | inc = qh->interval; | ||
546 | n_desc = 0; | ||
547 | |||
548 | if (qh->interval) { | ||
549 | ntd_max = (dwc2_max_desc_num(qh) + qh->interval - 1) / | ||
550 | qh->interval; | ||
551 | if (skip_frames && !qh->channel) | ||
552 | ntd_max -= skip_frames / qh->interval; | ||
553 | } | ||
554 | |||
555 | max_xfer_size = qh->dev_speed == USB_SPEED_HIGH ? | ||
556 | MAX_ISOC_XFER_SIZE_HS : MAX_ISOC_XFER_SIZE_FS; | ||
557 | |||
558 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) { | ||
559 | while (qh->ntd < ntd_max && qtd->isoc_frame_index_last < | ||
560 | qtd->urb->packet_count) { | ||
561 | if (n_desc > 1) | ||
562 | qh->desc_list[n_desc - 1].status |= HOST_DMA_A; | ||
563 | dwc2_fill_host_isoc_dma_desc(hsotg, qtd, qh, | ||
564 | max_xfer_size, idx); | ||
565 | idx = dwc2_desclist_idx_inc(idx, inc, qh->dev_speed); | ||
566 | n_desc++; | ||
567 | } | ||
568 | qtd->in_process = 1; | ||
569 | } | ||
570 | |||
571 | qh->td_last = idx; | ||
572 | |||
573 | #ifdef ISOC_URB_GIVEBACK_ASAP | ||
574 | /* Set IOC for last descriptor if descriptor list is full */ | ||
575 | if (qh->ntd == ntd_max) { | ||
576 | idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed); | ||
577 | qh->desc_list[idx].status |= HOST_DMA_IOC; | ||
578 | } | ||
579 | #else | ||
580 | /* | ||
581 | * Set IOC bit only for one descriptor. Always try to be ahead of HW | ||
582 | * processing, i.e. on IOC generation driver activates next descriptor | ||
583 | * but core continues to process descriptors following the one with IOC | ||
584 | * set. | ||
585 | */ | ||
586 | |||
587 | if (n_desc > DESCNUM_THRESHOLD) | ||
588 | /* | ||
589 | * Move IOC "up". Required even if there is only one QTD | ||
590 | * in the list, because QTDs might continue to be queued, | ||
591 | * but during the activation it was only one queued. | ||
592 | * Actually more than one QTD might be in the list if this | ||
593 | * function called from XferCompletion - QTDs was queued during | ||
594 | * HW processing of the previous descriptor chunk. | ||
595 | */ | ||
596 | idx = dwc2_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), | ||
597 | qh->dev_speed); | ||
598 | else | ||
599 | /* | ||
600 | * Set the IOC for the latest descriptor if either number of | ||
601 | * descriptors is not greater than threshold or no more new | ||
602 | * descriptors activated | ||
603 | */ | ||
604 | idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed); | ||
605 | |||
606 | qh->desc_list[idx].status |= HOST_DMA_IOC; | ||
607 | #endif | ||
608 | |||
609 | if (n_desc) { | ||
610 | qh->desc_list[n_desc - 1].status |= HOST_DMA_A; | ||
611 | if (n_desc > 1) | ||
612 | qh->desc_list[0].status |= HOST_DMA_A; | ||
613 | } | ||
614 | } | ||
615 | |||
616 | static void dwc2_fill_host_dma_desc(struct dwc2_hsotg *hsotg, | ||
617 | struct dwc2_host_chan *chan, | ||
618 | struct dwc2_qtd *qtd, struct dwc2_qh *qh, | ||
619 | int n_desc) | ||
620 | { | ||
621 | struct dwc2_hcd_dma_desc *dma_desc = &qh->desc_list[n_desc]; | ||
622 | int len = chan->xfer_len; | ||
623 | |||
624 | if (len > MAX_DMA_DESC_SIZE - (chan->max_packet - 1)) | ||
625 | len = MAX_DMA_DESC_SIZE - (chan->max_packet - 1); | ||
626 | |||
627 | if (chan->ep_is_in) { | ||
628 | int num_packets; | ||
629 | |||
630 | if (len > 0 && chan->max_packet) | ||
631 | num_packets = (len + chan->max_packet - 1) | ||
632 | / chan->max_packet; | ||
633 | else | ||
634 | /* Need 1 packet for transfer length of 0 */ | ||
635 | num_packets = 1; | ||
636 | |||
637 | /* Always program an integral # of packets for IN transfers */ | ||
638 | len = num_packets * chan->max_packet; | ||
639 | } | ||
640 | |||
641 | dma_desc->status = len << HOST_DMA_NBYTES_SHIFT & HOST_DMA_NBYTES_MASK; | ||
642 | qh->n_bytes[n_desc] = len; | ||
643 | |||
644 | if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL && | ||
645 | qtd->control_phase == DWC2_CONTROL_SETUP) | ||
646 | dma_desc->status |= HOST_DMA_SUP; | ||
647 | |||
648 | dma_desc->buf = (u32)chan->xfer_dma; | ||
649 | |||
650 | /* | ||
651 | * Last (or only) descriptor of IN transfer with actual size less | ||
652 | * than MaxPacket | ||
653 | */ | ||
654 | if (len > chan->xfer_len) { | ||
655 | chan->xfer_len = 0; | ||
656 | } else { | ||
657 | chan->xfer_dma += len; | ||
658 | chan->xfer_len -= len; | ||
659 | } | ||
660 | } | ||
661 | |||
662 | static void dwc2_init_non_isoc_dma_desc(struct dwc2_hsotg *hsotg, | ||
663 | struct dwc2_qh *qh) | ||
664 | { | ||
665 | struct dwc2_qtd *qtd; | ||
666 | struct dwc2_host_chan *chan = qh->channel; | ||
667 | int n_desc = 0; | ||
668 | |||
669 | dev_vdbg(hsotg->dev, "%s(): qh=%p dma=%08lx len=%d\n", __func__, qh, | ||
670 | (unsigned long)chan->xfer_dma, chan->xfer_len); | ||
671 | |||
672 | /* | ||
673 | * Start with chan->xfer_dma initialized in assign_and_init_hc(), then | ||
674 | * if SG transfer consists of multiple URBs, this pointer is re-assigned | ||
675 | * to the buffer of the currently processed QTD. For non-SG request | ||
676 | * there is always one QTD active. | ||
677 | */ | ||
678 | |||
679 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) { | ||
680 | dev_vdbg(hsotg->dev, "qtd=%p\n", qtd); | ||
681 | |||
682 | if (n_desc) { | ||
683 | /* SG request - more than 1 QTD */ | ||
684 | chan->xfer_dma = qtd->urb->dma + | ||
685 | qtd->urb->actual_length; | ||
686 | chan->xfer_len = qtd->urb->length - | ||
687 | qtd->urb->actual_length; | ||
688 | dev_vdbg(hsotg->dev, "buf=%08lx len=%d\n", | ||
689 | (unsigned long)chan->xfer_dma, chan->xfer_len); | ||
690 | } | ||
691 | |||
692 | qtd->n_desc = 0; | ||
693 | do { | ||
694 | if (n_desc > 1) { | ||
695 | qh->desc_list[n_desc - 1].status |= HOST_DMA_A; | ||
696 | dev_vdbg(hsotg->dev, | ||
697 | "set A bit in desc %d (%p)\n", | ||
698 | n_desc - 1, | ||
699 | &qh->desc_list[n_desc - 1]); | ||
700 | } | ||
701 | dwc2_fill_host_dma_desc(hsotg, chan, qtd, qh, n_desc); | ||
702 | dev_vdbg(hsotg->dev, | ||
703 | "desc %d (%p) buf=%08x status=%08x\n", | ||
704 | n_desc, &qh->desc_list[n_desc], | ||
705 | qh->desc_list[n_desc].buf, | ||
706 | qh->desc_list[n_desc].status); | ||
707 | qtd->n_desc++; | ||
708 | n_desc++; | ||
709 | } while (chan->xfer_len > 0 && | ||
710 | n_desc != MAX_DMA_DESC_NUM_GENERIC); | ||
711 | |||
712 | dev_vdbg(hsotg->dev, "n_desc=%d\n", n_desc); | ||
713 | qtd->in_process = 1; | ||
714 | if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL) | ||
715 | break; | ||
716 | if (n_desc == MAX_DMA_DESC_NUM_GENERIC) | ||
717 | break; | ||
718 | } | ||
719 | |||
720 | if (n_desc) { | ||
721 | qh->desc_list[n_desc - 1].status |= | ||
722 | HOST_DMA_IOC | HOST_DMA_EOL | HOST_DMA_A; | ||
723 | dev_vdbg(hsotg->dev, "set IOC/EOL/A bits in desc %d (%p)\n", | ||
724 | n_desc - 1, &qh->desc_list[n_desc - 1]); | ||
725 | if (n_desc > 1) { | ||
726 | qh->desc_list[0].status |= HOST_DMA_A; | ||
727 | dev_vdbg(hsotg->dev, "set A bit in desc 0 (%p)\n", | ||
728 | &qh->desc_list[0]); | ||
729 | } | ||
730 | chan->ntd = n_desc; | ||
731 | } | ||
732 | } | ||
733 | |||
734 | /** | ||
735 | * dwc2_hcd_start_xfer_ddma() - Starts a transfer in Descriptor DMA mode | ||
736 | * | ||
737 | * @hsotg: The HCD state structure for the DWC OTG controller | ||
738 | * @qh: The QH to init | ||
739 | * | ||
740 | * Return: 0 if successful, negative error code otherwise | ||
741 | * | ||
742 | * For Control and Bulk endpoints, initializes descriptor list and starts the | ||
743 | * transfer. For Interrupt and Isochronous endpoints, initializes descriptor | ||
744 | * list then updates FrameList, marking appropriate entries as active. | ||
745 | * | ||
746 | * For Isochronous endpoints the starting descriptor index is calculated based | ||
747 | * on the scheduled frame, but only on the first transfer descriptor within a | ||
748 | * session. Then the transfer is started via enabling the channel. | ||
749 | * | ||
750 | * For Isochronous endpoints the channel is not halted on XferComplete | ||
751 | * interrupt so remains assigned to the endpoint(QH) until session is done. | ||
752 | */ | ||
753 | void dwc2_hcd_start_xfer_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | ||
754 | { | ||
755 | /* Channel is already assigned */ | ||
756 | struct dwc2_host_chan *chan = qh->channel; | ||
757 | u16 skip_frames = 0; | ||
758 | |||
759 | switch (chan->ep_type) { | ||
760 | case USB_ENDPOINT_XFER_CONTROL: | ||
761 | case USB_ENDPOINT_XFER_BULK: | ||
762 | dwc2_init_non_isoc_dma_desc(hsotg, qh); | ||
763 | dwc2_hc_start_transfer_ddma(hsotg, chan); | ||
764 | break; | ||
765 | case USB_ENDPOINT_XFER_INT: | ||
766 | dwc2_init_non_isoc_dma_desc(hsotg, qh); | ||
767 | dwc2_update_frame_list(hsotg, qh, 1); | ||
768 | dwc2_hc_start_transfer_ddma(hsotg, chan); | ||
769 | break; | ||
770 | case USB_ENDPOINT_XFER_ISOC: | ||
771 | if (!qh->ntd) | ||
772 | skip_frames = dwc2_recalc_initial_desc_idx(hsotg, qh); | ||
773 | dwc2_init_isoc_dma_desc(hsotg, qh, skip_frames); | ||
774 | |||
775 | if (!chan->xfer_started) { | ||
776 | dwc2_update_frame_list(hsotg, qh, 1); | ||
777 | |||
778 | /* | ||
779 | * Always set to max, instead of actual size. Otherwise | ||
780 | * ntd will be changed with channel being enabled. Not | ||
781 | * recommended. | ||
782 | */ | ||
783 | chan->ntd = dwc2_max_desc_num(qh); | ||
784 | |||
785 | /* Enable channel only once for ISOC */ | ||
786 | dwc2_hc_start_transfer_ddma(hsotg, chan); | ||
787 | } | ||
788 | |||
789 | break; | ||
790 | default: | ||
791 | break; | ||
792 | } | ||
793 | } | ||
794 | |||
795 | #define DWC2_CMPL_DONE 1 | ||
796 | #define DWC2_CMPL_STOP 2 | ||
797 | |||
798 | static int dwc2_cmpl_host_isoc_dma_desc(struct dwc2_hsotg *hsotg, | ||
799 | struct dwc2_host_chan *chan, | ||
800 | struct dwc2_qtd *qtd, | ||
801 | struct dwc2_qh *qh, u16 idx) | ||
802 | { | ||
803 | struct dwc2_hcd_dma_desc *dma_desc = &qh->desc_list[idx]; | ||
804 | struct dwc2_hcd_iso_packet_desc *frame_desc; | ||
805 | u16 remain = 0; | ||
806 | int rc = 0; | ||
807 | |||
808 | if (!qtd->urb) | ||
809 | return -EINVAL; | ||
810 | |||
811 | frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last]; | ||
812 | dma_desc->buf = (u32)(qtd->urb->dma + frame_desc->offset); | ||
813 | if (chan->ep_is_in) | ||
814 | remain = (dma_desc->status & HOST_DMA_ISOC_NBYTES_MASK) >> | ||
815 | HOST_DMA_ISOC_NBYTES_SHIFT; | ||
816 | |||
817 | if ((dma_desc->status & HOST_DMA_STS_MASK) == HOST_DMA_STS_PKTERR) { | ||
818 | /* | ||
819 | * XactError, or unable to complete all the transactions | ||
820 | * in the scheduled micro-frame/frame, both indicated by | ||
821 | * HOST_DMA_STS_PKTERR | ||
822 | */ | ||
823 | qtd->urb->error_count++; | ||
824 | frame_desc->actual_length = qh->n_bytes[idx] - remain; | ||
825 | frame_desc->status = -EPROTO; | ||
826 | } else { | ||
827 | /* Success */ | ||
828 | frame_desc->actual_length = qh->n_bytes[idx] - remain; | ||
829 | frame_desc->status = 0; | ||
830 | } | ||
831 | |||
832 | if (++qtd->isoc_frame_index == qtd->urb->packet_count) { | ||
833 | /* | ||
834 | * urb->status is not used for isoc transfers here. The | ||
835 | * individual frame_desc status are used instead. | ||
836 | */ | ||
837 | dwc2_host_complete(hsotg, qtd, 0); | ||
838 | dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); | ||
839 | |||
840 | /* | ||
841 | * This check is necessary because urb_dequeue can be called | ||
842 | * from urb complete callback (sound driver for example). All | ||
843 | * pending URBs are dequeued there, so no need for further | ||
844 | * processing. | ||
845 | */ | ||
846 | if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) | ||
847 | return -1; | ||
848 | rc = DWC2_CMPL_DONE; | ||
849 | } | ||
850 | |||
851 | qh->ntd--; | ||
852 | |||
853 | /* Stop if IOC requested descriptor reached */ | ||
854 | if (dma_desc->status & HOST_DMA_IOC) | ||
855 | rc = DWC2_CMPL_STOP; | ||
856 | |||
857 | return rc; | ||
858 | } | ||
859 | |||
860 | static void dwc2_complete_isoc_xfer_ddma(struct dwc2_hsotg *hsotg, | ||
861 | struct dwc2_host_chan *chan, | ||
862 | enum dwc2_halt_status halt_status) | ||
863 | { | ||
864 | struct dwc2_hcd_iso_packet_desc *frame_desc; | ||
865 | struct dwc2_qtd *qtd, *qtd_tmp; | ||
866 | struct dwc2_qh *qh; | ||
867 | u16 idx; | ||
868 | int rc; | ||
869 | |||
870 | qh = chan->qh; | ||
871 | idx = qh->td_first; | ||
872 | |||
873 | if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) { | ||
874 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) | ||
875 | qtd->in_process = 0; | ||
876 | return; | ||
877 | } | ||
878 | |||
879 | if (halt_status == DWC2_HC_XFER_AHB_ERR || | ||
880 | halt_status == DWC2_HC_XFER_BABBLE_ERR) { | ||
881 | /* | ||
882 | * Channel is halted in these error cases, considered as serious | ||
883 | * issues. | ||
884 | * Complete all URBs marking all frames as failed, irrespective | ||
885 | * whether some of the descriptors (frames) succeeded or not. | ||
886 | * Pass error code to completion routine as well, to update | ||
887 | * urb->status, some of class drivers might use it to stop | ||
888 | * queing transfer requests. | ||
889 | */ | ||
890 | int err = halt_status == DWC2_HC_XFER_AHB_ERR ? | ||
891 | -EIO : -EOVERFLOW; | ||
892 | |||
893 | list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, | ||
894 | qtd_list_entry) { | ||
895 | if (qtd->urb) { | ||
896 | for (idx = 0; idx < qtd->urb->packet_count; | ||
897 | idx++) { | ||
898 | frame_desc = &qtd->urb->iso_descs[idx]; | ||
899 | frame_desc->status = err; | ||
900 | } | ||
901 | |||
902 | dwc2_host_complete(hsotg, qtd, err); | ||
903 | } | ||
904 | |||
905 | dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); | ||
906 | } | ||
907 | |||
908 | return; | ||
909 | } | ||
910 | |||
911 | list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) { | ||
912 | if (!qtd->in_process) | ||
913 | break; | ||
914 | do { | ||
915 | rc = dwc2_cmpl_host_isoc_dma_desc(hsotg, chan, qtd, qh, | ||
916 | idx); | ||
917 | if (rc < 0) | ||
918 | return; | ||
919 | idx = dwc2_desclist_idx_inc(idx, qh->interval, | ||
920 | chan->speed); | ||
921 | if (rc == DWC2_CMPL_STOP) | ||
922 | goto stop_scan; | ||
923 | if (rc == DWC2_CMPL_DONE) | ||
924 | break; | ||
925 | } while (idx != qh->td_first); | ||
926 | } | ||
927 | |||
928 | stop_scan: | ||
929 | qh->td_first = idx; | ||
930 | } | ||
931 | |||
932 | static int dwc2_update_non_isoc_urb_state_ddma(struct dwc2_hsotg *hsotg, | ||
933 | struct dwc2_host_chan *chan, | ||
934 | struct dwc2_qtd *qtd, | ||
935 | struct dwc2_hcd_dma_desc *dma_desc, | ||
936 | enum dwc2_halt_status halt_status, | ||
937 | u32 n_bytes, int *xfer_done) | ||
938 | { | ||
939 | struct dwc2_hcd_urb *urb = qtd->urb; | ||
940 | u16 remain = 0; | ||
941 | |||
942 | if (chan->ep_is_in) | ||
943 | remain = (dma_desc->status & HOST_DMA_NBYTES_MASK) >> | ||
944 | HOST_DMA_NBYTES_SHIFT; | ||
945 | |||
946 | dev_vdbg(hsotg->dev, "remain=%d dwc2_urb=%p\n", remain, urb); | ||
947 | |||
948 | if (halt_status == DWC2_HC_XFER_AHB_ERR) { | ||
949 | dev_err(hsotg->dev, "EIO\n"); | ||
950 | urb->status = -EIO; | ||
951 | return 1; | ||
952 | } | ||
953 | |||
954 | if ((dma_desc->status & HOST_DMA_STS_MASK) == HOST_DMA_STS_PKTERR) { | ||
955 | switch (halt_status) { | ||
956 | case DWC2_HC_XFER_STALL: | ||
957 | dev_vdbg(hsotg->dev, "Stall\n"); | ||
958 | urb->status = -EPIPE; | ||
959 | break; | ||
960 | case DWC2_HC_XFER_BABBLE_ERR: | ||
961 | dev_err(hsotg->dev, "Babble\n"); | ||
962 | urb->status = -EOVERFLOW; | ||
963 | break; | ||
964 | case DWC2_HC_XFER_XACT_ERR: | ||
965 | dev_err(hsotg->dev, "XactErr\n"); | ||
966 | urb->status = -EPROTO; | ||
967 | break; | ||
968 | default: | ||
969 | dev_err(hsotg->dev, | ||
970 | "%s: Unhandled descriptor error status (%d)\n", | ||
971 | __func__, halt_status); | ||
972 | break; | ||
973 | } | ||
974 | return 1; | ||
975 | } | ||
976 | |||
977 | if (dma_desc->status & HOST_DMA_A) { | ||
978 | dev_vdbg(hsotg->dev, | ||
979 | "Active descriptor encountered on channel %d\n", | ||
980 | chan->hc_num); | ||
981 | return 0; | ||
982 | } | ||
983 | |||
984 | if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL) { | ||
985 | if (qtd->control_phase == DWC2_CONTROL_DATA) { | ||
986 | urb->actual_length += n_bytes - remain; | ||
987 | if (remain || urb->actual_length >= urb->length) { | ||
988 | /* | ||
989 | * For Control Data stage do not set urb->status | ||
990 | * to 0, to prevent URB callback. Set it when | ||
991 | * Status phase is done. See below. | ||
992 | */ | ||
993 | *xfer_done = 1; | ||
994 | } | ||
995 | } else if (qtd->control_phase == DWC2_CONTROL_STATUS) { | ||
996 | urb->status = 0; | ||
997 | *xfer_done = 1; | ||
998 | } | ||
999 | /* No handling for SETUP stage */ | ||
1000 | } else { | ||
1001 | /* BULK and INTR */ | ||
1002 | urb->actual_length += n_bytes - remain; | ||
1003 | dev_vdbg(hsotg->dev, "length=%d actual=%d\n", urb->length, | ||
1004 | urb->actual_length); | ||
1005 | if (remain || urb->actual_length >= urb->length) { | ||
1006 | urb->status = 0; | ||
1007 | *xfer_done = 1; | ||
1008 | } | ||
1009 | } | ||
1010 | |||
1011 | return 0; | ||
1012 | } | ||
1013 | |||
1014 | static int dwc2_process_non_isoc_desc(struct dwc2_hsotg *hsotg, | ||
1015 | struct dwc2_host_chan *chan, | ||
1016 | int chnum, struct dwc2_qtd *qtd, | ||
1017 | int desc_num, | ||
1018 | enum dwc2_halt_status halt_status, | ||
1019 | int *xfer_done) | ||
1020 | { | ||
1021 | struct dwc2_qh *qh = chan->qh; | ||
1022 | struct dwc2_hcd_urb *urb = qtd->urb; | ||
1023 | struct dwc2_hcd_dma_desc *dma_desc; | ||
1024 | u32 n_bytes; | ||
1025 | int failed; | ||
1026 | |||
1027 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
1028 | |||
1029 | if (!urb) | ||
1030 | return -EINVAL; | ||
1031 | |||
1032 | dma_desc = &qh->desc_list[desc_num]; | ||
1033 | n_bytes = qh->n_bytes[desc_num]; | ||
1034 | dev_vdbg(hsotg->dev, | ||
1035 | "qtd=%p dwc2_urb=%p desc_num=%d desc=%p n_bytes=%d\n", | ||
1036 | qtd, urb, desc_num, dma_desc, n_bytes); | ||
1037 | failed = dwc2_update_non_isoc_urb_state_ddma(hsotg, chan, qtd, dma_desc, | ||
1038 | halt_status, n_bytes, | ||
1039 | xfer_done); | ||
1040 | if (failed || (*xfer_done && urb->status != -EINPROGRESS)) { | ||
1041 | dwc2_host_complete(hsotg, qtd, urb->status); | ||
1042 | dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); | ||
1043 | dev_vdbg(hsotg->dev, "failed=%1x xfer_done=%1x status=%08x\n", | ||
1044 | failed, *xfer_done, urb->status); | ||
1045 | return failed; | ||
1046 | } | ||
1047 | |||
1048 | if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL) { | ||
1049 | switch (qtd->control_phase) { | ||
1050 | case DWC2_CONTROL_SETUP: | ||
1051 | if (urb->length > 0) | ||
1052 | qtd->control_phase = DWC2_CONTROL_DATA; | ||
1053 | else | ||
1054 | qtd->control_phase = DWC2_CONTROL_STATUS; | ||
1055 | dev_vdbg(hsotg->dev, | ||
1056 | " Control setup transaction done\n"); | ||
1057 | break; | ||
1058 | case DWC2_CONTROL_DATA: | ||
1059 | if (*xfer_done) { | ||
1060 | qtd->control_phase = DWC2_CONTROL_STATUS; | ||
1061 | dev_vdbg(hsotg->dev, | ||
1062 | " Control data transfer done\n"); | ||
1063 | } else if (desc_num + 1 == qtd->n_desc) { | ||
1064 | /* | ||
1065 | * Last descriptor for Control data stage which | ||
1066 | * is not completed yet | ||
1067 | */ | ||
1068 | dwc2_hcd_save_data_toggle(hsotg, chan, chnum, | ||
1069 | qtd); | ||
1070 | } | ||
1071 | break; | ||
1072 | default: | ||
1073 | break; | ||
1074 | } | ||
1075 | } | ||
1076 | |||
1077 | return 0; | ||
1078 | } | ||
1079 | |||
1080 | static void dwc2_complete_non_isoc_xfer_ddma(struct dwc2_hsotg *hsotg, | ||
1081 | struct dwc2_host_chan *chan, | ||
1082 | int chnum, | ||
1083 | enum dwc2_halt_status halt_status) | ||
1084 | { | ||
1085 | struct list_head *qtd_item, *qtd_tmp; | ||
1086 | struct dwc2_qh *qh = chan->qh; | ||
1087 | struct dwc2_qtd *qtd = NULL; | ||
1088 | int xfer_done; | ||
1089 | int desc_num = 0; | ||
1090 | |||
1091 | if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) { | ||
1092 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) | ||
1093 | qtd->in_process = 0; | ||
1094 | return; | ||
1095 | } | ||
1096 | |||
1097 | list_for_each_safe(qtd_item, qtd_tmp, &qh->qtd_list) { | ||
1098 | int i; | ||
1099 | |||
1100 | qtd = list_entry(qtd_item, struct dwc2_qtd, qtd_list_entry); | ||
1101 | xfer_done = 0; | ||
1102 | |||
1103 | for (i = 0; i < qtd->n_desc; i++) { | ||
1104 | if (dwc2_process_non_isoc_desc(hsotg, chan, chnum, qtd, | ||
1105 | desc_num, halt_status, | ||
1106 | &xfer_done)) { | ||
1107 | qtd = NULL; | ||
1108 | break; | ||
1109 | } | ||
1110 | desc_num++; | ||
1111 | } | ||
1112 | } | ||
1113 | |||
1114 | if (qh->ep_type != USB_ENDPOINT_XFER_CONTROL) { | ||
1115 | /* | ||
1116 | * Resetting the data toggle for bulk and interrupt endpoints | ||
1117 | * in case of stall. See handle_hc_stall_intr(). | ||
1118 | */ | ||
1119 | if (halt_status == DWC2_HC_XFER_STALL) | ||
1120 | qh->data_toggle = DWC2_HC_PID_DATA0; | ||
1121 | else if (qtd) | ||
1122 | dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd); | ||
1123 | } | ||
1124 | |||
1125 | if (halt_status == DWC2_HC_XFER_COMPLETE) { | ||
1126 | if (chan->hcint & HCINTMSK_NYET) { | ||
1127 | /* | ||
1128 | * Got a NYET on the last transaction of the transfer. | ||
1129 | * It means that the endpoint should be in the PING | ||
1130 | * state at the beginning of the next transfer. | ||
1131 | */ | ||
1132 | qh->ping_state = 1; | ||
1133 | } | ||
1134 | } | ||
1135 | } | ||
1136 | |||
1137 | /** | ||
1138 | * dwc2_hcd_complete_xfer_ddma() - Scans the descriptor list, updates URB's | ||
1139 | * status and calls completion routine for the URB if it's done. Called from | ||
1140 | * interrupt handlers. | ||
1141 | * | ||
1142 | * @hsotg: The HCD state structure for the DWC OTG controller | ||
1143 | * @chan: Host channel the transfer is completed on | ||
1144 | * @chnum: Index of Host channel registers | ||
1145 | * @halt_status: Reason the channel is being halted or just XferComplete | ||
1146 | * for isochronous transfers | ||
1147 | * | ||
1148 | * Releases the channel to be used by other transfers. | ||
1149 | * In case of Isochronous endpoint the channel is not halted until the end of | ||
1150 | * the session, i.e. QTD list is empty. | ||
1151 | * If periodic channel released the FrameList is updated accordingly. | ||
1152 | * Calls transaction selection routines to activate pending transfers. | ||
1153 | */ | ||
1154 | void dwc2_hcd_complete_xfer_ddma(struct dwc2_hsotg *hsotg, | ||
1155 | struct dwc2_host_chan *chan, int chnum, | ||
1156 | enum dwc2_halt_status halt_status) | ||
1157 | { | ||
1158 | struct dwc2_qh *qh = chan->qh; | ||
1159 | int continue_isoc_xfer = 0; | ||
1160 | enum dwc2_transaction_type tr_type; | ||
1161 | |||
1162 | if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) { | ||
1163 | dwc2_complete_isoc_xfer_ddma(hsotg, chan, halt_status); | ||
1164 | |||
1165 | /* Release the channel if halted or session completed */ | ||
1166 | if (halt_status != DWC2_HC_XFER_COMPLETE || | ||
1167 | list_empty(&qh->qtd_list)) { | ||
1168 | /* Halt the channel if session completed */ | ||
1169 | if (halt_status == DWC2_HC_XFER_COMPLETE) | ||
1170 | dwc2_hc_halt(hsotg, chan, halt_status); | ||
1171 | dwc2_release_channel_ddma(hsotg, qh); | ||
1172 | dwc2_hcd_qh_unlink(hsotg, qh); | ||
1173 | } else { | ||
1174 | /* Keep in assigned schedule to continue transfer */ | ||
1175 | list_move(&qh->qh_list_entry, | ||
1176 | &hsotg->periodic_sched_assigned); | ||
1177 | continue_isoc_xfer = 1; | ||
1178 | } | ||
1179 | /* | ||
1180 | * Todo: Consider the case when period exceeds FrameList size. | ||
1181 | * Frame Rollover interrupt should be used. | ||
1182 | */ | ||
1183 | } else { | ||
1184 | /* | ||
1185 | * Scan descriptor list to complete the URB(s), then release | ||
1186 | * the channel | ||
1187 | */ | ||
1188 | dwc2_complete_non_isoc_xfer_ddma(hsotg, chan, chnum, | ||
1189 | halt_status); | ||
1190 | dwc2_release_channel_ddma(hsotg, qh); | ||
1191 | dwc2_hcd_qh_unlink(hsotg, qh); | ||
1192 | |||
1193 | if (!list_empty(&qh->qtd_list)) { | ||
1194 | /* | ||
1195 | * Add back to inactive non-periodic schedule on normal | ||
1196 | * completion | ||
1197 | */ | ||
1198 | dwc2_hcd_qh_add(hsotg, qh); | ||
1199 | } | ||
1200 | } | ||
1201 | |||
1202 | tr_type = dwc2_hcd_select_transactions(hsotg); | ||
1203 | if (tr_type != DWC2_TRANSACTION_NONE || continue_isoc_xfer) { | ||
1204 | if (continue_isoc_xfer) { | ||
1205 | if (tr_type == DWC2_TRANSACTION_NONE) | ||
1206 | tr_type = DWC2_TRANSACTION_PERIODIC; | ||
1207 | else if (tr_type == DWC2_TRANSACTION_NON_PERIODIC) | ||
1208 | tr_type = DWC2_TRANSACTION_ALL; | ||
1209 | } | ||
1210 | dwc2_hcd_queue_transactions(hsotg, tr_type); | ||
1211 | } | ||
1212 | } | ||
diff --git a/drivers/usb/dwc2/hcd_intr.c b/drivers/usb/dwc2/hcd_intr.c new file mode 100644 index 000000000000..012f17ec1a37 --- /dev/null +++ b/drivers/usb/dwc2/hcd_intr.c | |||
@@ -0,0 +1,2119 @@ | |||
1 | /* | ||
2 | * hcd_intr.c - DesignWare HS OTG Controller host-mode interrupt handling | ||
3 | * | ||
4 | * Copyright (C) 2004-2013 Synopsys, Inc. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions, and the following disclaimer, | ||
11 | * without modification. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The names of the above-listed copyright holders may not be used | ||
16 | * to endorse or promote products derived from this software without | ||
17 | * specific prior written permission. | ||
18 | * | ||
19 | * ALTERNATIVELY, this software may be distributed under the terms of the | ||
20 | * GNU General Public License ("GPL") as published by the Free Software | ||
21 | * Foundation; either version 2 of the License, or (at your option) any | ||
22 | * later version. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
26 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
35 | */ | ||
36 | |||
37 | /* | ||
38 | * This file contains the interrupt handlers for Host mode | ||
39 | */ | ||
40 | #include <linux/kernel.h> | ||
41 | #include <linux/module.h> | ||
42 | #include <linux/spinlock.h> | ||
43 | #include <linux/interrupt.h> | ||
44 | #include <linux/dma-mapping.h> | ||
45 | #include <linux/io.h> | ||
46 | #include <linux/slab.h> | ||
47 | #include <linux/usb.h> | ||
48 | |||
49 | #include <linux/usb/hcd.h> | ||
50 | #include <linux/usb/ch11.h> | ||
51 | |||
52 | #include "core.h" | ||
53 | #include "hcd.h" | ||
54 | |||
55 | /* This function is for debug only */ | ||
56 | static void dwc2_track_missed_sofs(struct dwc2_hsotg *hsotg) | ||
57 | { | ||
58 | #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS | ||
59 | u16 curr_frame_number = hsotg->frame_number; | ||
60 | |||
61 | if (hsotg->frame_num_idx < FRAME_NUM_ARRAY_SIZE) { | ||
62 | if (((hsotg->last_frame_num + 1) & HFNUM_MAX_FRNUM) != | ||
63 | curr_frame_number) { | ||
64 | hsotg->frame_num_array[hsotg->frame_num_idx] = | ||
65 | curr_frame_number; | ||
66 | hsotg->last_frame_num_array[hsotg->frame_num_idx] = | ||
67 | hsotg->last_frame_num; | ||
68 | hsotg->frame_num_idx++; | ||
69 | } | ||
70 | } else if (!hsotg->dumped_frame_num_array) { | ||
71 | int i; | ||
72 | |||
73 | dev_info(hsotg->dev, "Frame Last Frame\n"); | ||
74 | dev_info(hsotg->dev, "----- ----------\n"); | ||
75 | for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) { | ||
76 | dev_info(hsotg->dev, "0x%04x 0x%04x\n", | ||
77 | hsotg->frame_num_array[i], | ||
78 | hsotg->last_frame_num_array[i]); | ||
79 | } | ||
80 | hsotg->dumped_frame_num_array = 1; | ||
81 | } | ||
82 | hsotg->last_frame_num = curr_frame_number; | ||
83 | #endif | ||
84 | } | ||
85 | |||
86 | static void dwc2_hc_handle_tt_clear(struct dwc2_hsotg *hsotg, | ||
87 | struct dwc2_host_chan *chan, | ||
88 | struct dwc2_qtd *qtd) | ||
89 | { | ||
90 | struct urb *usb_urb; | ||
91 | |||
92 | if (!chan->qh) | ||
93 | return; | ||
94 | |||
95 | if (chan->qh->dev_speed == USB_SPEED_HIGH) | ||
96 | return; | ||
97 | |||
98 | if (!qtd->urb) | ||
99 | return; | ||
100 | |||
101 | usb_urb = qtd->urb->priv; | ||
102 | if (!usb_urb || !usb_urb->dev || !usb_urb->dev->tt) | ||
103 | return; | ||
104 | |||
105 | if (qtd->urb->status != -EPIPE && qtd->urb->status != -EREMOTEIO) { | ||
106 | chan->qh->tt_buffer_dirty = 1; | ||
107 | if (usb_hub_clear_tt_buffer(usb_urb)) | ||
108 | /* Clear failed; let's hope things work anyway */ | ||
109 | chan->qh->tt_buffer_dirty = 0; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | /* | ||
114 | * Handles the start-of-frame interrupt in host mode. Non-periodic | ||
115 | * transactions may be queued to the DWC_otg controller for the current | ||
116 | * (micro)frame. Periodic transactions may be queued to the controller | ||
117 | * for the next (micro)frame. | ||
118 | */ | ||
119 | static void dwc2_sof_intr(struct dwc2_hsotg *hsotg) | ||
120 | { | ||
121 | struct list_head *qh_entry; | ||
122 | struct dwc2_qh *qh; | ||
123 | enum dwc2_transaction_type tr_type; | ||
124 | |||
125 | #ifdef DEBUG_SOF | ||
126 | dev_vdbg(hsotg->dev, "--Start of Frame Interrupt--\n"); | ||
127 | #endif | ||
128 | |||
129 | hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg); | ||
130 | |||
131 | dwc2_track_missed_sofs(hsotg); | ||
132 | |||
133 | /* Determine whether any periodic QHs should be executed */ | ||
134 | qh_entry = hsotg->periodic_sched_inactive.next; | ||
135 | while (qh_entry != &hsotg->periodic_sched_inactive) { | ||
136 | qh = list_entry(qh_entry, struct dwc2_qh, qh_list_entry); | ||
137 | qh_entry = qh_entry->next; | ||
138 | if (dwc2_frame_num_le(qh->sched_frame, hsotg->frame_number)) | ||
139 | /* | ||
140 | * Move QH to the ready list to be executed next | ||
141 | * (micro)frame | ||
142 | */ | ||
143 | list_move(&qh->qh_list_entry, | ||
144 | &hsotg->periodic_sched_ready); | ||
145 | } | ||
146 | tr_type = dwc2_hcd_select_transactions(hsotg); | ||
147 | if (tr_type != DWC2_TRANSACTION_NONE) | ||
148 | dwc2_hcd_queue_transactions(hsotg, tr_type); | ||
149 | |||
150 | /* Clear interrupt */ | ||
151 | writel(GINTSTS_SOF, hsotg->regs + GINTSTS); | ||
152 | } | ||
153 | |||
154 | /* | ||
155 | * Handles the Rx FIFO Level Interrupt, which indicates that there is | ||
156 | * at least one packet in the Rx FIFO. The packets are moved from the FIFO to | ||
157 | * memory if the DWC_otg controller is operating in Slave mode. | ||
158 | */ | ||
159 | static void dwc2_rx_fifo_level_intr(struct dwc2_hsotg *hsotg) | ||
160 | { | ||
161 | u32 grxsts, chnum, bcnt, dpid, pktsts; | ||
162 | struct dwc2_host_chan *chan; | ||
163 | |||
164 | if (dbg_perio()) | ||
165 | dev_vdbg(hsotg->dev, "--RxFIFO Level Interrupt--\n"); | ||
166 | |||
167 | grxsts = readl(hsotg->regs + GRXSTSP); | ||
168 | chnum = (grxsts & GRXSTS_HCHNUM_MASK) >> GRXSTS_HCHNUM_SHIFT; | ||
169 | chan = hsotg->hc_ptr_array[chnum]; | ||
170 | if (!chan) { | ||
171 | dev_err(hsotg->dev, "Unable to get corresponding channel\n"); | ||
172 | return; | ||
173 | } | ||
174 | |||
175 | bcnt = (grxsts & GRXSTS_BYTECNT_MASK) >> GRXSTS_BYTECNT_SHIFT; | ||
176 | dpid = (grxsts & GRXSTS_DPID_MASK) >> GRXSTS_DPID_SHIFT; | ||
177 | pktsts = (grxsts & GRXSTS_PKTSTS_MASK) >> GRXSTS_PKTSTS_SHIFT; | ||
178 | |||
179 | /* Packet Status */ | ||
180 | if (dbg_perio()) { | ||
181 | dev_vdbg(hsotg->dev, " Ch num = %d\n", chnum); | ||
182 | dev_vdbg(hsotg->dev, " Count = %d\n", bcnt); | ||
183 | dev_vdbg(hsotg->dev, " DPID = %d, chan.dpid = %d\n", dpid, | ||
184 | chan->data_pid_start); | ||
185 | dev_vdbg(hsotg->dev, " PStatus = %d\n", pktsts); | ||
186 | } | ||
187 | |||
188 | switch (pktsts) { | ||
189 | case GRXSTS_PKTSTS_HCHIN: | ||
190 | /* Read the data into the host buffer */ | ||
191 | if (bcnt > 0) { | ||
192 | dwc2_read_packet(hsotg, chan->xfer_buf, bcnt); | ||
193 | |||
194 | /* Update the HC fields for the next packet received */ | ||
195 | chan->xfer_count += bcnt; | ||
196 | chan->xfer_buf += bcnt; | ||
197 | } | ||
198 | break; | ||
199 | case GRXSTS_PKTSTS_HCHIN_XFER_COMP: | ||
200 | case GRXSTS_PKTSTS_DATATOGGLEERR: | ||
201 | case GRXSTS_PKTSTS_HCHHALTED: | ||
202 | /* Handled in interrupt, just ignore data */ | ||
203 | break; | ||
204 | default: | ||
205 | dev_err(hsotg->dev, | ||
206 | "RxFIFO Level Interrupt: Unknown status %d\n", pktsts); | ||
207 | break; | ||
208 | } | ||
209 | } | ||
210 | |||
211 | /* | ||
212 | * This interrupt occurs when the non-periodic Tx FIFO is half-empty. More | ||
213 | * data packets may be written to the FIFO for OUT transfers. More requests | ||
214 | * may be written to the non-periodic request queue for IN transfers. This | ||
215 | * interrupt is enabled only in Slave mode. | ||
216 | */ | ||
217 | static void dwc2_np_tx_fifo_empty_intr(struct dwc2_hsotg *hsotg) | ||
218 | { | ||
219 | dev_vdbg(hsotg->dev, "--Non-Periodic TxFIFO Empty Interrupt--\n"); | ||
220 | dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_NON_PERIODIC); | ||
221 | } | ||
222 | |||
223 | /* | ||
224 | * This interrupt occurs when the periodic Tx FIFO is half-empty. More data | ||
225 | * packets may be written to the FIFO for OUT transfers. More requests may be | ||
226 | * written to the periodic request queue for IN transfers. This interrupt is | ||
227 | * enabled only in Slave mode. | ||
228 | */ | ||
229 | static void dwc2_perio_tx_fifo_empty_intr(struct dwc2_hsotg *hsotg) | ||
230 | { | ||
231 | if (dbg_perio()) | ||
232 | dev_vdbg(hsotg->dev, "--Periodic TxFIFO Empty Interrupt--\n"); | ||
233 | dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_PERIODIC); | ||
234 | } | ||
235 | |||
236 | static void dwc2_hprt0_enable(struct dwc2_hsotg *hsotg, u32 hprt0, | ||
237 | u32 *hprt0_modify) | ||
238 | { | ||
239 | struct dwc2_core_params *params = hsotg->core_params; | ||
240 | int do_reset = 0; | ||
241 | u32 usbcfg; | ||
242 | u32 prtspd; | ||
243 | u32 hcfg; | ||
244 | u32 fslspclksel; | ||
245 | u32 hfir; | ||
246 | |||
247 | dev_vdbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); | ||
248 | |||
249 | /* Every time when port enables calculate HFIR.FrInterval */ | ||
250 | hfir = readl(hsotg->regs + HFIR); | ||
251 | hfir &= ~HFIR_FRINT_MASK; | ||
252 | hfir |= dwc2_calc_frame_interval(hsotg) << HFIR_FRINT_SHIFT & | ||
253 | HFIR_FRINT_MASK; | ||
254 | writel(hfir, hsotg->regs + HFIR); | ||
255 | |||
256 | /* Check if we need to adjust the PHY clock speed for low power */ | ||
257 | if (!params->host_support_fs_ls_low_power) { | ||
258 | /* Port has been enabled, set the reset change flag */ | ||
259 | hsotg->flags.b.port_reset_change = 1; | ||
260 | return; | ||
261 | } | ||
262 | |||
263 | usbcfg = readl(hsotg->regs + GUSBCFG); | ||
264 | prtspd = (hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT; | ||
265 | |||
266 | if (prtspd == HPRT0_SPD_LOW_SPEED || prtspd == HPRT0_SPD_FULL_SPEED) { | ||
267 | /* Low power */ | ||
268 | if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL)) { | ||
269 | /* Set PHY low power clock select for FS/LS devices */ | ||
270 | usbcfg |= GUSBCFG_PHY_LP_CLK_SEL; | ||
271 | writel(usbcfg, hsotg->regs + GUSBCFG); | ||
272 | do_reset = 1; | ||
273 | } | ||
274 | |||
275 | hcfg = readl(hsotg->regs + HCFG); | ||
276 | fslspclksel = (hcfg & HCFG_FSLSPCLKSEL_MASK) >> | ||
277 | HCFG_FSLSPCLKSEL_SHIFT; | ||
278 | |||
279 | if (prtspd == HPRT0_SPD_LOW_SPEED && | ||
280 | params->host_ls_low_power_phy_clk == | ||
281 | DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ) { | ||
282 | /* 6 MHZ */ | ||
283 | dev_vdbg(hsotg->dev, | ||
284 | "FS_PHY programming HCFG to 6 MHz\n"); | ||
285 | if (fslspclksel != HCFG_FSLSPCLKSEL_6_MHZ) { | ||
286 | fslspclksel = HCFG_FSLSPCLKSEL_6_MHZ; | ||
287 | hcfg &= ~HCFG_FSLSPCLKSEL_MASK; | ||
288 | hcfg |= fslspclksel << HCFG_FSLSPCLKSEL_SHIFT; | ||
289 | writel(hcfg, hsotg->regs + HCFG); | ||
290 | do_reset = 1; | ||
291 | } | ||
292 | } else { | ||
293 | /* 48 MHZ */ | ||
294 | dev_vdbg(hsotg->dev, | ||
295 | "FS_PHY programming HCFG to 48 MHz\n"); | ||
296 | if (fslspclksel != HCFG_FSLSPCLKSEL_48_MHZ) { | ||
297 | fslspclksel = HCFG_FSLSPCLKSEL_48_MHZ; | ||
298 | hcfg &= ~HCFG_FSLSPCLKSEL_MASK; | ||
299 | hcfg |= fslspclksel << HCFG_FSLSPCLKSEL_SHIFT; | ||
300 | writel(hcfg, hsotg->regs + HCFG); | ||
301 | do_reset = 1; | ||
302 | } | ||
303 | } | ||
304 | } else { | ||
305 | /* Not low power */ | ||
306 | if (usbcfg & GUSBCFG_PHY_LP_CLK_SEL) { | ||
307 | usbcfg &= ~GUSBCFG_PHY_LP_CLK_SEL; | ||
308 | writel(usbcfg, hsotg->regs + GUSBCFG); | ||
309 | do_reset = 1; | ||
310 | } | ||
311 | } | ||
312 | |||
313 | if (do_reset) { | ||
314 | *hprt0_modify |= HPRT0_RST; | ||
315 | queue_delayed_work(hsotg->wq_otg, &hsotg->reset_work, | ||
316 | msecs_to_jiffies(60)); | ||
317 | } else { | ||
318 | /* Port has been enabled, set the reset change flag */ | ||
319 | hsotg->flags.b.port_reset_change = 1; | ||
320 | } | ||
321 | } | ||
322 | |||
323 | /* | ||
324 | * There are multiple conditions that can cause a port interrupt. This function | ||
325 | * determines which interrupt conditions have occurred and handles them | ||
326 | * appropriately. | ||
327 | */ | ||
328 | static void dwc2_port_intr(struct dwc2_hsotg *hsotg) | ||
329 | { | ||
330 | u32 hprt0; | ||
331 | u32 hprt0_modify; | ||
332 | |||
333 | dev_vdbg(hsotg->dev, "--Port Interrupt--\n"); | ||
334 | |||
335 | hprt0 = readl(hsotg->regs + HPRT0); | ||
336 | hprt0_modify = hprt0; | ||
337 | |||
338 | /* | ||
339 | * Clear appropriate bits in HPRT0 to clear the interrupt bit in | ||
340 | * GINTSTS | ||
341 | */ | ||
342 | hprt0_modify &= ~(HPRT0_ENA | HPRT0_CONNDET | HPRT0_ENACHG | | ||
343 | HPRT0_OVRCURRCHG); | ||
344 | |||
345 | /* | ||
346 | * Port Connect Detected | ||
347 | * Set flag and clear if detected | ||
348 | */ | ||
349 | if (hprt0 & HPRT0_CONNDET) { | ||
350 | dev_vdbg(hsotg->dev, | ||
351 | "--Port Interrupt HPRT0=0x%08x Port Connect Detected--\n", | ||
352 | hprt0); | ||
353 | hsotg->flags.b.port_connect_status_change = 1; | ||
354 | hsotg->flags.b.port_connect_status = 1; | ||
355 | hprt0_modify |= HPRT0_CONNDET; | ||
356 | |||
357 | /* | ||
358 | * The Hub driver asserts a reset when it sees port connect | ||
359 | * status change flag | ||
360 | */ | ||
361 | } | ||
362 | |||
363 | /* | ||
364 | * Port Enable Changed | ||
365 | * Clear if detected - Set internal flag if disabled | ||
366 | */ | ||
367 | if (hprt0 & HPRT0_ENACHG) { | ||
368 | dev_vdbg(hsotg->dev, | ||
369 | " --Port Interrupt HPRT0=0x%08x Port Enable Changed (now %d)--\n", | ||
370 | hprt0, !!(hprt0 & HPRT0_ENA)); | ||
371 | hprt0_modify |= HPRT0_ENACHG; | ||
372 | if (hprt0 & HPRT0_ENA) | ||
373 | dwc2_hprt0_enable(hsotg, hprt0, &hprt0_modify); | ||
374 | else | ||
375 | hsotg->flags.b.port_enable_change = 1; | ||
376 | } | ||
377 | |||
378 | /* Overcurrent Change Interrupt */ | ||
379 | if (hprt0 & HPRT0_OVRCURRCHG) { | ||
380 | dev_vdbg(hsotg->dev, | ||
381 | " --Port Interrupt HPRT0=0x%08x Port Overcurrent Changed--\n", | ||
382 | hprt0); | ||
383 | hsotg->flags.b.port_over_current_change = 1; | ||
384 | hprt0_modify |= HPRT0_OVRCURRCHG; | ||
385 | } | ||
386 | |||
387 | /* Clear Port Interrupts */ | ||
388 | writel(hprt0_modify, hsotg->regs + HPRT0); | ||
389 | } | ||
390 | |||
391 | /* | ||
392 | * Gets the actual length of a transfer after the transfer halts. halt_status | ||
393 | * holds the reason for the halt. | ||
394 | * | ||
395 | * For IN transfers where halt_status is DWC2_HC_XFER_COMPLETE, *short_read | ||
396 | * is set to 1 upon return if less than the requested number of bytes were | ||
397 | * transferred. short_read may also be NULL on entry, in which case it remains | ||
398 | * unchanged. | ||
399 | */ | ||
400 | static u32 dwc2_get_actual_xfer_length(struct dwc2_hsotg *hsotg, | ||
401 | struct dwc2_host_chan *chan, int chnum, | ||
402 | struct dwc2_qtd *qtd, | ||
403 | enum dwc2_halt_status halt_status, | ||
404 | int *short_read) | ||
405 | { | ||
406 | u32 hctsiz, count, length; | ||
407 | |||
408 | hctsiz = readl(hsotg->regs + HCTSIZ(chnum)); | ||
409 | |||
410 | if (halt_status == DWC2_HC_XFER_COMPLETE) { | ||
411 | if (chan->ep_is_in) { | ||
412 | count = (hctsiz & TSIZ_XFERSIZE_MASK) >> | ||
413 | TSIZ_XFERSIZE_SHIFT; | ||
414 | length = chan->xfer_len - count; | ||
415 | if (short_read != NULL) | ||
416 | *short_read = (count != 0); | ||
417 | } else if (chan->qh->do_split) { | ||
418 | length = qtd->ssplit_out_xfer_count; | ||
419 | } else { | ||
420 | length = chan->xfer_len; | ||
421 | } | ||
422 | } else { | ||
423 | /* | ||
424 | * Must use the hctsiz.pktcnt field to determine how much data | ||
425 | * has been transferred. This field reflects the number of | ||
426 | * packets that have been transferred via the USB. This is | ||
427 | * always an integral number of packets if the transfer was | ||
428 | * halted before its normal completion. (Can't use the | ||
429 | * hctsiz.xfersize field because that reflects the number of | ||
430 | * bytes transferred via the AHB, not the USB). | ||
431 | */ | ||
432 | count = (hctsiz & TSIZ_PKTCNT_MASK) >> TSIZ_PKTCNT_SHIFT; | ||
433 | length = (chan->start_pkt_count - count) * chan->max_packet; | ||
434 | } | ||
435 | |||
436 | return length; | ||
437 | } | ||
438 | |||
439 | /** | ||
440 | * dwc2_update_urb_state() - Updates the state of the URB after a Transfer | ||
441 | * Complete interrupt on the host channel. Updates the actual_length field | ||
442 | * of the URB based on the number of bytes transferred via the host channel. | ||
443 | * Sets the URB status if the data transfer is finished. | ||
444 | * | ||
445 | * Return: 1 if the data transfer specified by the URB is completely finished, | ||
446 | * 0 otherwise | ||
447 | */ | ||
448 | static int dwc2_update_urb_state(struct dwc2_hsotg *hsotg, | ||
449 | struct dwc2_host_chan *chan, int chnum, | ||
450 | struct dwc2_hcd_urb *urb, | ||
451 | struct dwc2_qtd *qtd) | ||
452 | { | ||
453 | u32 hctsiz; | ||
454 | int xfer_done = 0; | ||
455 | int short_read = 0; | ||
456 | int xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd, | ||
457 | DWC2_HC_XFER_COMPLETE, | ||
458 | &short_read); | ||
459 | |||
460 | if (urb->actual_length + xfer_length > urb->length) { | ||
461 | dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__); | ||
462 | xfer_length = urb->length - urb->actual_length; | ||
463 | } | ||
464 | |||
465 | /* Non DWORD-aligned buffer case handling */ | ||
466 | if (chan->align_buf && xfer_length && chan->ep_is_in) { | ||
467 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); | ||
468 | dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length, | ||
469 | DMA_FROM_DEVICE); | ||
470 | memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf, | ||
471 | xfer_length); | ||
472 | dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length, | ||
473 | DMA_FROM_DEVICE); | ||
474 | } | ||
475 | |||
476 | dev_vdbg(hsotg->dev, "urb->actual_length=%d xfer_length=%d\n", | ||
477 | urb->actual_length, xfer_length); | ||
478 | urb->actual_length += xfer_length; | ||
479 | |||
480 | if (xfer_length && chan->ep_type == USB_ENDPOINT_XFER_BULK && | ||
481 | (urb->flags & URB_SEND_ZERO_PACKET) && | ||
482 | urb->actual_length >= urb->length && | ||
483 | !(urb->length % chan->max_packet)) { | ||
484 | xfer_done = 0; | ||
485 | } else if (short_read || urb->actual_length >= urb->length) { | ||
486 | xfer_done = 1; | ||
487 | urb->status = 0; | ||
488 | } | ||
489 | |||
490 | hctsiz = readl(hsotg->regs + HCTSIZ(chnum)); | ||
491 | dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n", | ||
492 | __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum); | ||
493 | dev_vdbg(hsotg->dev, " chan->xfer_len %d\n", chan->xfer_len); | ||
494 | dev_vdbg(hsotg->dev, " hctsiz.xfersize %d\n", | ||
495 | (hctsiz & TSIZ_XFERSIZE_MASK) >> TSIZ_XFERSIZE_SHIFT); | ||
496 | dev_vdbg(hsotg->dev, " urb->transfer_buffer_length %d\n", urb->length); | ||
497 | dev_vdbg(hsotg->dev, " urb->actual_length %d\n", urb->actual_length); | ||
498 | dev_vdbg(hsotg->dev, " short_read %d, xfer_done %d\n", short_read, | ||
499 | xfer_done); | ||
500 | |||
501 | return xfer_done; | ||
502 | } | ||
503 | |||
504 | /* | ||
505 | * Save the starting data toggle for the next transfer. The data toggle is | ||
506 | * saved in the QH for non-control transfers and it's saved in the QTD for | ||
507 | * control transfers. | ||
508 | */ | ||
509 | void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg, | ||
510 | struct dwc2_host_chan *chan, int chnum, | ||
511 | struct dwc2_qtd *qtd) | ||
512 | { | ||
513 | u32 hctsiz = readl(hsotg->regs + HCTSIZ(chnum)); | ||
514 | u32 pid = (hctsiz & TSIZ_SC_MC_PID_MASK) >> TSIZ_SC_MC_PID_SHIFT; | ||
515 | |||
516 | if (chan->ep_type != USB_ENDPOINT_XFER_CONTROL) { | ||
517 | if (pid == TSIZ_SC_MC_PID_DATA0) | ||
518 | chan->qh->data_toggle = DWC2_HC_PID_DATA0; | ||
519 | else | ||
520 | chan->qh->data_toggle = DWC2_HC_PID_DATA1; | ||
521 | } else { | ||
522 | if (pid == TSIZ_SC_MC_PID_DATA0) | ||
523 | qtd->data_toggle = DWC2_HC_PID_DATA0; | ||
524 | else | ||
525 | qtd->data_toggle = DWC2_HC_PID_DATA1; | ||
526 | } | ||
527 | } | ||
528 | |||
529 | /** | ||
530 | * dwc2_update_isoc_urb_state() - Updates the state of an Isochronous URB when | ||
531 | * the transfer is stopped for any reason. The fields of the current entry in | ||
532 | * the frame descriptor array are set based on the transfer state and the input | ||
533 | * halt_status. Completes the Isochronous URB if all the URB frames have been | ||
534 | * completed. | ||
535 | * | ||
536 | * Return: DWC2_HC_XFER_COMPLETE if there are more frames remaining to be | ||
537 | * transferred in the URB. Otherwise return DWC2_HC_XFER_URB_COMPLETE. | ||
538 | */ | ||
539 | static enum dwc2_halt_status dwc2_update_isoc_urb_state( | ||
540 | struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan, | ||
541 | int chnum, struct dwc2_qtd *qtd, | ||
542 | enum dwc2_halt_status halt_status) | ||
543 | { | ||
544 | struct dwc2_hcd_iso_packet_desc *frame_desc; | ||
545 | struct dwc2_hcd_urb *urb = qtd->urb; | ||
546 | |||
547 | if (!urb) | ||
548 | return DWC2_HC_XFER_NO_HALT_STATUS; | ||
549 | |||
550 | frame_desc = &urb->iso_descs[qtd->isoc_frame_index]; | ||
551 | |||
552 | switch (halt_status) { | ||
553 | case DWC2_HC_XFER_COMPLETE: | ||
554 | frame_desc->status = 0; | ||
555 | frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg, | ||
556 | chan, chnum, qtd, halt_status, NULL); | ||
557 | |||
558 | /* Non DWORD-aligned buffer case handling */ | ||
559 | if (chan->align_buf && frame_desc->actual_length && | ||
560 | chan->ep_is_in) { | ||
561 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", | ||
562 | __func__); | ||
563 | dma_sync_single_for_cpu(hsotg->dev, urb->dma, | ||
564 | urb->length, DMA_FROM_DEVICE); | ||
565 | memcpy(urb->buf + frame_desc->offset + | ||
566 | qtd->isoc_split_offset, chan->qh->dw_align_buf, | ||
567 | frame_desc->actual_length); | ||
568 | dma_sync_single_for_device(hsotg->dev, urb->dma, | ||
569 | urb->length, | ||
570 | DMA_FROM_DEVICE); | ||
571 | } | ||
572 | break; | ||
573 | case DWC2_HC_XFER_FRAME_OVERRUN: | ||
574 | urb->error_count++; | ||
575 | if (chan->ep_is_in) | ||
576 | frame_desc->status = -ENOSR; | ||
577 | else | ||
578 | frame_desc->status = -ECOMM; | ||
579 | frame_desc->actual_length = 0; | ||
580 | break; | ||
581 | case DWC2_HC_XFER_BABBLE_ERR: | ||
582 | urb->error_count++; | ||
583 | frame_desc->status = -EOVERFLOW; | ||
584 | /* Don't need to update actual_length in this case */ | ||
585 | break; | ||
586 | case DWC2_HC_XFER_XACT_ERR: | ||
587 | urb->error_count++; | ||
588 | frame_desc->status = -EPROTO; | ||
589 | frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg, | ||
590 | chan, chnum, qtd, halt_status, NULL); | ||
591 | |||
592 | /* Non DWORD-aligned buffer case handling */ | ||
593 | if (chan->align_buf && frame_desc->actual_length && | ||
594 | chan->ep_is_in) { | ||
595 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", | ||
596 | __func__); | ||
597 | dma_sync_single_for_cpu(hsotg->dev, urb->dma, | ||
598 | urb->length, DMA_FROM_DEVICE); | ||
599 | memcpy(urb->buf + frame_desc->offset + | ||
600 | qtd->isoc_split_offset, chan->qh->dw_align_buf, | ||
601 | frame_desc->actual_length); | ||
602 | dma_sync_single_for_device(hsotg->dev, urb->dma, | ||
603 | urb->length, | ||
604 | DMA_FROM_DEVICE); | ||
605 | } | ||
606 | |||
607 | /* Skip whole frame */ | ||
608 | if (chan->qh->do_split && | ||
609 | chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in && | ||
610 | hsotg->core_params->dma_enable > 0) { | ||
611 | qtd->complete_split = 0; | ||
612 | qtd->isoc_split_offset = 0; | ||
613 | } | ||
614 | |||
615 | break; | ||
616 | default: | ||
617 | dev_err(hsotg->dev, "Unhandled halt_status (%d)\n", | ||
618 | halt_status); | ||
619 | break; | ||
620 | } | ||
621 | |||
622 | if (++qtd->isoc_frame_index == urb->packet_count) { | ||
623 | /* | ||
624 | * urb->status is not used for isoc transfers. The individual | ||
625 | * frame_desc statuses are used instead. | ||
626 | */ | ||
627 | dwc2_host_complete(hsotg, qtd, 0); | ||
628 | halt_status = DWC2_HC_XFER_URB_COMPLETE; | ||
629 | } else { | ||
630 | halt_status = DWC2_HC_XFER_COMPLETE; | ||
631 | } | ||
632 | |||
633 | return halt_status; | ||
634 | } | ||
635 | |||
636 | /* | ||
637 | * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic | ||
638 | * QHs, removes the QH from the active non-periodic schedule. If any QTDs are | ||
639 | * still linked to the QH, the QH is added to the end of the inactive | ||
640 | * non-periodic schedule. For periodic QHs, removes the QH from the periodic | ||
641 | * schedule if no more QTDs are linked to the QH. | ||
642 | */ | ||
643 | static void dwc2_deactivate_qh(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, | ||
644 | int free_qtd) | ||
645 | { | ||
646 | int continue_split = 0; | ||
647 | struct dwc2_qtd *qtd; | ||
648 | |||
649 | if (dbg_qh(qh)) | ||
650 | dev_vdbg(hsotg->dev, " %s(%p,%p,%d)\n", __func__, | ||
651 | hsotg, qh, free_qtd); | ||
652 | |||
653 | if (list_empty(&qh->qtd_list)) { | ||
654 | dev_dbg(hsotg->dev, "## QTD list empty ##\n"); | ||
655 | goto no_qtd; | ||
656 | } | ||
657 | |||
658 | qtd = list_first_entry(&qh->qtd_list, struct dwc2_qtd, qtd_list_entry); | ||
659 | |||
660 | if (qtd->complete_split) | ||
661 | continue_split = 1; | ||
662 | else if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_MID || | ||
663 | qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_END) | ||
664 | continue_split = 1; | ||
665 | |||
666 | if (free_qtd) { | ||
667 | dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); | ||
668 | continue_split = 0; | ||
669 | } | ||
670 | |||
671 | no_qtd: | ||
672 | if (qh->channel) | ||
673 | qh->channel->align_buf = 0; | ||
674 | qh->channel = NULL; | ||
675 | dwc2_hcd_qh_deactivate(hsotg, qh, continue_split); | ||
676 | } | ||
677 | |||
678 | /** | ||
679 | * dwc2_release_channel() - Releases a host channel for use by other transfers | ||
680 | * | ||
681 | * @hsotg: The HCD state structure | ||
682 | * @chan: The host channel to release | ||
683 | * @qtd: The QTD associated with the host channel. This QTD may be | ||
684 | * freed if the transfer is complete or an error has occurred. | ||
685 | * @halt_status: Reason the channel is being released. This status | ||
686 | * determines the actions taken by this function. | ||
687 | * | ||
688 | * Also attempts to select and queue more transactions since at least one host | ||
689 | * channel is available. | ||
690 | */ | ||
691 | static void dwc2_release_channel(struct dwc2_hsotg *hsotg, | ||
692 | struct dwc2_host_chan *chan, | ||
693 | struct dwc2_qtd *qtd, | ||
694 | enum dwc2_halt_status halt_status) | ||
695 | { | ||
696 | enum dwc2_transaction_type tr_type; | ||
697 | u32 haintmsk; | ||
698 | int free_qtd = 0; | ||
699 | |||
700 | if (dbg_hc(chan)) | ||
701 | dev_vdbg(hsotg->dev, " %s: channel %d, halt_status %d\n", | ||
702 | __func__, chan->hc_num, halt_status); | ||
703 | |||
704 | switch (halt_status) { | ||
705 | case DWC2_HC_XFER_URB_COMPLETE: | ||
706 | free_qtd = 1; | ||
707 | break; | ||
708 | case DWC2_HC_XFER_AHB_ERR: | ||
709 | case DWC2_HC_XFER_STALL: | ||
710 | case DWC2_HC_XFER_BABBLE_ERR: | ||
711 | free_qtd = 1; | ||
712 | break; | ||
713 | case DWC2_HC_XFER_XACT_ERR: | ||
714 | if (qtd && qtd->error_count >= 3) { | ||
715 | dev_vdbg(hsotg->dev, | ||
716 | " Complete URB with transaction error\n"); | ||
717 | free_qtd = 1; | ||
718 | dwc2_host_complete(hsotg, qtd, -EPROTO); | ||
719 | } | ||
720 | break; | ||
721 | case DWC2_HC_XFER_URB_DEQUEUE: | ||
722 | /* | ||
723 | * The QTD has already been removed and the QH has been | ||
724 | * deactivated. Don't want to do anything except release the | ||
725 | * host channel and try to queue more transfers. | ||
726 | */ | ||
727 | goto cleanup; | ||
728 | case DWC2_HC_XFER_PERIODIC_INCOMPLETE: | ||
729 | dev_vdbg(hsotg->dev, " Complete URB with I/O error\n"); | ||
730 | free_qtd = 1; | ||
731 | dwc2_host_complete(hsotg, qtd, -EIO); | ||
732 | break; | ||
733 | case DWC2_HC_XFER_NO_HALT_STATUS: | ||
734 | default: | ||
735 | break; | ||
736 | } | ||
737 | |||
738 | dwc2_deactivate_qh(hsotg, chan->qh, free_qtd); | ||
739 | |||
740 | cleanup: | ||
741 | /* | ||
742 | * Release the host channel for use by other transfers. The cleanup | ||
743 | * function clears the channel interrupt enables and conditions, so | ||
744 | * there's no need to clear the Channel Halted interrupt separately. | ||
745 | */ | ||
746 | if (!list_empty(&chan->hc_list_entry)) | ||
747 | list_del(&chan->hc_list_entry); | ||
748 | dwc2_hc_cleanup(hsotg, chan); | ||
749 | list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list); | ||
750 | |||
751 | if (hsotg->core_params->uframe_sched > 0) { | ||
752 | hsotg->available_host_channels++; | ||
753 | } else { | ||
754 | switch (chan->ep_type) { | ||
755 | case USB_ENDPOINT_XFER_CONTROL: | ||
756 | case USB_ENDPOINT_XFER_BULK: | ||
757 | hsotg->non_periodic_channels--; | ||
758 | break; | ||
759 | default: | ||
760 | /* | ||
761 | * Don't release reservations for periodic channels | ||
762 | * here. That's done when a periodic transfer is | ||
763 | * descheduled (i.e. when the QH is removed from the | ||
764 | * periodic schedule). | ||
765 | */ | ||
766 | break; | ||
767 | } | ||
768 | } | ||
769 | |||
770 | haintmsk = readl(hsotg->regs + HAINTMSK); | ||
771 | haintmsk &= ~(1 << chan->hc_num); | ||
772 | writel(haintmsk, hsotg->regs + HAINTMSK); | ||
773 | |||
774 | /* Try to queue more transfers now that there's a free channel */ | ||
775 | tr_type = dwc2_hcd_select_transactions(hsotg); | ||
776 | if (tr_type != DWC2_TRANSACTION_NONE) | ||
777 | dwc2_hcd_queue_transactions(hsotg, tr_type); | ||
778 | } | ||
779 | |||
780 | /* | ||
781 | * Halts a host channel. If the channel cannot be halted immediately because | ||
782 | * the request queue is full, this function ensures that the FIFO empty | ||
783 | * interrupt for the appropriate queue is enabled so that the halt request can | ||
784 | * be queued when there is space in the request queue. | ||
785 | * | ||
786 | * This function may also be called in DMA mode. In that case, the channel is | ||
787 | * simply released since the core always halts the channel automatically in | ||
788 | * DMA mode. | ||
789 | */ | ||
790 | static void dwc2_halt_channel(struct dwc2_hsotg *hsotg, | ||
791 | struct dwc2_host_chan *chan, struct dwc2_qtd *qtd, | ||
792 | enum dwc2_halt_status halt_status) | ||
793 | { | ||
794 | if (dbg_hc(chan)) | ||
795 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
796 | |||
797 | if (hsotg->core_params->dma_enable > 0) { | ||
798 | if (dbg_hc(chan)) | ||
799 | dev_vdbg(hsotg->dev, "DMA enabled\n"); | ||
800 | dwc2_release_channel(hsotg, chan, qtd, halt_status); | ||
801 | return; | ||
802 | } | ||
803 | |||
804 | /* Slave mode processing */ | ||
805 | dwc2_hc_halt(hsotg, chan, halt_status); | ||
806 | |||
807 | if (chan->halt_on_queue) { | ||
808 | u32 gintmsk; | ||
809 | |||
810 | dev_vdbg(hsotg->dev, "Halt on queue\n"); | ||
811 | if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL || | ||
812 | chan->ep_type == USB_ENDPOINT_XFER_BULK) { | ||
813 | dev_vdbg(hsotg->dev, "control/bulk\n"); | ||
814 | /* | ||
815 | * Make sure the Non-periodic Tx FIFO empty interrupt | ||
816 | * is enabled so that the non-periodic schedule will | ||
817 | * be processed | ||
818 | */ | ||
819 | gintmsk = readl(hsotg->regs + GINTMSK); | ||
820 | gintmsk |= GINTSTS_NPTXFEMP; | ||
821 | writel(gintmsk, hsotg->regs + GINTMSK); | ||
822 | } else { | ||
823 | dev_vdbg(hsotg->dev, "isoc/intr\n"); | ||
824 | /* | ||
825 | * Move the QH from the periodic queued schedule to | ||
826 | * the periodic assigned schedule. This allows the | ||
827 | * halt to be queued when the periodic schedule is | ||
828 | * processed. | ||
829 | */ | ||
830 | list_move(&chan->qh->qh_list_entry, | ||
831 | &hsotg->periodic_sched_assigned); | ||
832 | |||
833 | /* | ||
834 | * Make sure the Periodic Tx FIFO Empty interrupt is | ||
835 | * enabled so that the periodic schedule will be | ||
836 | * processed | ||
837 | */ | ||
838 | gintmsk = readl(hsotg->regs + GINTMSK); | ||
839 | gintmsk |= GINTSTS_PTXFEMP; | ||
840 | writel(gintmsk, hsotg->regs + GINTMSK); | ||
841 | } | ||
842 | } | ||
843 | } | ||
844 | |||
845 | /* | ||
846 | * Performs common cleanup for non-periodic transfers after a Transfer | ||
847 | * Complete interrupt. This function should be called after any endpoint type | ||
848 | * specific handling is finished to release the host channel. | ||
849 | */ | ||
850 | static void dwc2_complete_non_periodic_xfer(struct dwc2_hsotg *hsotg, | ||
851 | struct dwc2_host_chan *chan, | ||
852 | int chnum, struct dwc2_qtd *qtd, | ||
853 | enum dwc2_halt_status halt_status) | ||
854 | { | ||
855 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
856 | |||
857 | qtd->error_count = 0; | ||
858 | |||
859 | if (chan->hcint & HCINTMSK_NYET) { | ||
860 | /* | ||
861 | * Got a NYET on the last transaction of the transfer. This | ||
862 | * means that the endpoint should be in the PING state at the | ||
863 | * beginning of the next transfer. | ||
864 | */ | ||
865 | dev_vdbg(hsotg->dev, "got NYET\n"); | ||
866 | chan->qh->ping_state = 1; | ||
867 | } | ||
868 | |||
869 | /* | ||
870 | * Always halt and release the host channel to make it available for | ||
871 | * more transfers. There may still be more phases for a control | ||
872 | * transfer or more data packets for a bulk transfer at this point, | ||
873 | * but the host channel is still halted. A channel will be reassigned | ||
874 | * to the transfer when the non-periodic schedule is processed after | ||
875 | * the channel is released. This allows transactions to be queued | ||
876 | * properly via dwc2_hcd_queue_transactions, which also enables the | ||
877 | * Tx FIFO Empty interrupt if necessary. | ||
878 | */ | ||
879 | if (chan->ep_is_in) { | ||
880 | /* | ||
881 | * IN transfers in Slave mode require an explicit disable to | ||
882 | * halt the channel. (In DMA mode, this call simply releases | ||
883 | * the channel.) | ||
884 | */ | ||
885 | dwc2_halt_channel(hsotg, chan, qtd, halt_status); | ||
886 | } else { | ||
887 | /* | ||
888 | * The channel is automatically disabled by the core for OUT | ||
889 | * transfers in Slave mode | ||
890 | */ | ||
891 | dwc2_release_channel(hsotg, chan, qtd, halt_status); | ||
892 | } | ||
893 | } | ||
894 | |||
895 | /* | ||
896 | * Performs common cleanup for periodic transfers after a Transfer Complete | ||
897 | * interrupt. This function should be called after any endpoint type specific | ||
898 | * handling is finished to release the host channel. | ||
899 | */ | ||
900 | static void dwc2_complete_periodic_xfer(struct dwc2_hsotg *hsotg, | ||
901 | struct dwc2_host_chan *chan, int chnum, | ||
902 | struct dwc2_qtd *qtd, | ||
903 | enum dwc2_halt_status halt_status) | ||
904 | { | ||
905 | u32 hctsiz = readl(hsotg->regs + HCTSIZ(chnum)); | ||
906 | |||
907 | qtd->error_count = 0; | ||
908 | |||
909 | if (!chan->ep_is_in || (hctsiz & TSIZ_PKTCNT_MASK) == 0) | ||
910 | /* Core halts channel in these cases */ | ||
911 | dwc2_release_channel(hsotg, chan, qtd, halt_status); | ||
912 | else | ||
913 | /* Flush any outstanding requests from the Tx queue */ | ||
914 | dwc2_halt_channel(hsotg, chan, qtd, halt_status); | ||
915 | } | ||
916 | |||
917 | static int dwc2_xfercomp_isoc_split_in(struct dwc2_hsotg *hsotg, | ||
918 | struct dwc2_host_chan *chan, int chnum, | ||
919 | struct dwc2_qtd *qtd) | ||
920 | { | ||
921 | struct dwc2_hcd_iso_packet_desc *frame_desc; | ||
922 | u32 len; | ||
923 | |||
924 | if (!qtd->urb) | ||
925 | return 0; | ||
926 | |||
927 | frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index]; | ||
928 | len = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd, | ||
929 | DWC2_HC_XFER_COMPLETE, NULL); | ||
930 | if (!len) { | ||
931 | qtd->complete_split = 0; | ||
932 | qtd->isoc_split_offset = 0; | ||
933 | return 0; | ||
934 | } | ||
935 | |||
936 | frame_desc->actual_length += len; | ||
937 | |||
938 | if (chan->align_buf) { | ||
939 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); | ||
940 | dma_sync_single_for_cpu(hsotg->dev, qtd->urb->dma, | ||
941 | qtd->urb->length, DMA_FROM_DEVICE); | ||
942 | memcpy(qtd->urb->buf + frame_desc->offset + | ||
943 | qtd->isoc_split_offset, chan->qh->dw_align_buf, len); | ||
944 | dma_sync_single_for_device(hsotg->dev, qtd->urb->dma, | ||
945 | qtd->urb->length, DMA_FROM_DEVICE); | ||
946 | } | ||
947 | |||
948 | qtd->isoc_split_offset += len; | ||
949 | |||
950 | if (frame_desc->actual_length >= frame_desc->length) { | ||
951 | frame_desc->status = 0; | ||
952 | qtd->isoc_frame_index++; | ||
953 | qtd->complete_split = 0; | ||
954 | qtd->isoc_split_offset = 0; | ||
955 | } | ||
956 | |||
957 | if (qtd->isoc_frame_index == qtd->urb->packet_count) { | ||
958 | dwc2_host_complete(hsotg, qtd, 0); | ||
959 | dwc2_release_channel(hsotg, chan, qtd, | ||
960 | DWC2_HC_XFER_URB_COMPLETE); | ||
961 | } else { | ||
962 | dwc2_release_channel(hsotg, chan, qtd, | ||
963 | DWC2_HC_XFER_NO_HALT_STATUS); | ||
964 | } | ||
965 | |||
966 | return 1; /* Indicates that channel released */ | ||
967 | } | ||
968 | |||
969 | /* | ||
970 | * Handles a host channel Transfer Complete interrupt. This handler may be | ||
971 | * called in either DMA mode or Slave mode. | ||
972 | */ | ||
973 | static void dwc2_hc_xfercomp_intr(struct dwc2_hsotg *hsotg, | ||
974 | struct dwc2_host_chan *chan, int chnum, | ||
975 | struct dwc2_qtd *qtd) | ||
976 | { | ||
977 | struct dwc2_hcd_urb *urb = qtd->urb; | ||
978 | int pipe_type = dwc2_hcd_get_pipe_type(&urb->pipe_info); | ||
979 | enum dwc2_halt_status halt_status = DWC2_HC_XFER_COMPLETE; | ||
980 | int urb_xfer_done; | ||
981 | |||
982 | if (dbg_hc(chan)) | ||
983 | dev_vdbg(hsotg->dev, | ||
984 | "--Host Channel %d Interrupt: Transfer Complete--\n", | ||
985 | chnum); | ||
986 | |||
987 | if (hsotg->core_params->dma_desc_enable > 0) { | ||
988 | dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum, halt_status); | ||
989 | if (pipe_type == USB_ENDPOINT_XFER_ISOC) | ||
990 | /* Do not disable the interrupt, just clear it */ | ||
991 | return; | ||
992 | goto handle_xfercomp_done; | ||
993 | } | ||
994 | |||
995 | /* Handle xfer complete on CSPLIT */ | ||
996 | if (chan->qh->do_split) { | ||
997 | if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in && | ||
998 | hsotg->core_params->dma_enable > 0) { | ||
999 | if (qtd->complete_split && | ||
1000 | dwc2_xfercomp_isoc_split_in(hsotg, chan, chnum, | ||
1001 | qtd)) | ||
1002 | goto handle_xfercomp_done; | ||
1003 | } else { | ||
1004 | qtd->complete_split = 0; | ||
1005 | } | ||
1006 | } | ||
1007 | |||
1008 | if (!urb) | ||
1009 | goto handle_xfercomp_done; | ||
1010 | |||
1011 | /* Update the QTD and URB states */ | ||
1012 | switch (pipe_type) { | ||
1013 | case USB_ENDPOINT_XFER_CONTROL: | ||
1014 | switch (qtd->control_phase) { | ||
1015 | case DWC2_CONTROL_SETUP: | ||
1016 | if (urb->length > 0) | ||
1017 | qtd->control_phase = DWC2_CONTROL_DATA; | ||
1018 | else | ||
1019 | qtd->control_phase = DWC2_CONTROL_STATUS; | ||
1020 | dev_vdbg(hsotg->dev, | ||
1021 | " Control setup transaction done\n"); | ||
1022 | halt_status = DWC2_HC_XFER_COMPLETE; | ||
1023 | break; | ||
1024 | case DWC2_CONTROL_DATA: | ||
1025 | urb_xfer_done = dwc2_update_urb_state(hsotg, chan, | ||
1026 | chnum, urb, qtd); | ||
1027 | if (urb_xfer_done) { | ||
1028 | qtd->control_phase = DWC2_CONTROL_STATUS; | ||
1029 | dev_vdbg(hsotg->dev, | ||
1030 | " Control data transfer done\n"); | ||
1031 | } else { | ||
1032 | dwc2_hcd_save_data_toggle(hsotg, chan, chnum, | ||
1033 | qtd); | ||
1034 | } | ||
1035 | halt_status = DWC2_HC_XFER_COMPLETE; | ||
1036 | break; | ||
1037 | case DWC2_CONTROL_STATUS: | ||
1038 | dev_vdbg(hsotg->dev, " Control transfer complete\n"); | ||
1039 | if (urb->status == -EINPROGRESS) | ||
1040 | urb->status = 0; | ||
1041 | dwc2_host_complete(hsotg, qtd, urb->status); | ||
1042 | halt_status = DWC2_HC_XFER_URB_COMPLETE; | ||
1043 | break; | ||
1044 | } | ||
1045 | |||
1046 | dwc2_complete_non_periodic_xfer(hsotg, chan, chnum, qtd, | ||
1047 | halt_status); | ||
1048 | break; | ||
1049 | case USB_ENDPOINT_XFER_BULK: | ||
1050 | dev_vdbg(hsotg->dev, " Bulk transfer complete\n"); | ||
1051 | urb_xfer_done = dwc2_update_urb_state(hsotg, chan, chnum, urb, | ||
1052 | qtd); | ||
1053 | if (urb_xfer_done) { | ||
1054 | dwc2_host_complete(hsotg, qtd, urb->status); | ||
1055 | halt_status = DWC2_HC_XFER_URB_COMPLETE; | ||
1056 | } else { | ||
1057 | halt_status = DWC2_HC_XFER_COMPLETE; | ||
1058 | } | ||
1059 | |||
1060 | dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd); | ||
1061 | dwc2_complete_non_periodic_xfer(hsotg, chan, chnum, qtd, | ||
1062 | halt_status); | ||
1063 | break; | ||
1064 | case USB_ENDPOINT_XFER_INT: | ||
1065 | dev_vdbg(hsotg->dev, " Interrupt transfer complete\n"); | ||
1066 | urb_xfer_done = dwc2_update_urb_state(hsotg, chan, chnum, urb, | ||
1067 | qtd); | ||
1068 | |||
1069 | /* | ||
1070 | * Interrupt URB is done on the first transfer complete | ||
1071 | * interrupt | ||
1072 | */ | ||
1073 | if (urb_xfer_done) { | ||
1074 | dwc2_host_complete(hsotg, qtd, urb->status); | ||
1075 | halt_status = DWC2_HC_XFER_URB_COMPLETE; | ||
1076 | } else { | ||
1077 | halt_status = DWC2_HC_XFER_COMPLETE; | ||
1078 | } | ||
1079 | |||
1080 | dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd); | ||
1081 | dwc2_complete_periodic_xfer(hsotg, chan, chnum, qtd, | ||
1082 | halt_status); | ||
1083 | break; | ||
1084 | case USB_ENDPOINT_XFER_ISOC: | ||
1085 | if (dbg_perio()) | ||
1086 | dev_vdbg(hsotg->dev, " Isochronous transfer complete\n"); | ||
1087 | if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_ALL) | ||
1088 | halt_status = dwc2_update_isoc_urb_state(hsotg, chan, | ||
1089 | chnum, qtd, DWC2_HC_XFER_COMPLETE); | ||
1090 | dwc2_complete_periodic_xfer(hsotg, chan, chnum, qtd, | ||
1091 | halt_status); | ||
1092 | break; | ||
1093 | } | ||
1094 | |||
1095 | handle_xfercomp_done: | ||
1096 | disable_hc_int(hsotg, chnum, HCINTMSK_XFERCOMPL); | ||
1097 | } | ||
1098 | |||
1099 | /* | ||
1100 | * Handles a host channel STALL interrupt. This handler may be called in | ||
1101 | * either DMA mode or Slave mode. | ||
1102 | */ | ||
1103 | static void dwc2_hc_stall_intr(struct dwc2_hsotg *hsotg, | ||
1104 | struct dwc2_host_chan *chan, int chnum, | ||
1105 | struct dwc2_qtd *qtd) | ||
1106 | { | ||
1107 | struct dwc2_hcd_urb *urb = qtd->urb; | ||
1108 | int pipe_type = dwc2_hcd_get_pipe_type(&urb->pipe_info); | ||
1109 | |||
1110 | dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: STALL Received--\n", | ||
1111 | chnum); | ||
1112 | |||
1113 | if (hsotg->core_params->dma_desc_enable > 0) { | ||
1114 | dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum, | ||
1115 | DWC2_HC_XFER_STALL); | ||
1116 | goto handle_stall_done; | ||
1117 | } | ||
1118 | |||
1119 | if (!urb) | ||
1120 | goto handle_stall_halt; | ||
1121 | |||
1122 | if (pipe_type == USB_ENDPOINT_XFER_CONTROL) | ||
1123 | dwc2_host_complete(hsotg, qtd, -EPIPE); | ||
1124 | |||
1125 | if (pipe_type == USB_ENDPOINT_XFER_BULK || | ||
1126 | pipe_type == USB_ENDPOINT_XFER_INT) { | ||
1127 | dwc2_host_complete(hsotg, qtd, -EPIPE); | ||
1128 | /* | ||
1129 | * USB protocol requires resetting the data toggle for bulk | ||
1130 | * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT) | ||
1131 | * setup command is issued to the endpoint. Anticipate the | ||
1132 | * CLEAR_FEATURE command since a STALL has occurred and reset | ||
1133 | * the data toggle now. | ||
1134 | */ | ||
1135 | chan->qh->data_toggle = 0; | ||
1136 | } | ||
1137 | |||
1138 | handle_stall_halt: | ||
1139 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_STALL); | ||
1140 | |||
1141 | handle_stall_done: | ||
1142 | disable_hc_int(hsotg, chnum, HCINTMSK_STALL); | ||
1143 | } | ||
1144 | |||
1145 | /* | ||
1146 | * Updates the state of the URB when a transfer has been stopped due to an | ||
1147 | * abnormal condition before the transfer completes. Modifies the | ||
1148 | * actual_length field of the URB to reflect the number of bytes that have | ||
1149 | * actually been transferred via the host channel. | ||
1150 | */ | ||
1151 | static void dwc2_update_urb_state_abn(struct dwc2_hsotg *hsotg, | ||
1152 | struct dwc2_host_chan *chan, int chnum, | ||
1153 | struct dwc2_hcd_urb *urb, | ||
1154 | struct dwc2_qtd *qtd, | ||
1155 | enum dwc2_halt_status halt_status) | ||
1156 | { | ||
1157 | u32 xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum, | ||
1158 | qtd, halt_status, NULL); | ||
1159 | u32 hctsiz; | ||
1160 | |||
1161 | if (urb->actual_length + xfer_length > urb->length) { | ||
1162 | dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__); | ||
1163 | xfer_length = urb->length - urb->actual_length; | ||
1164 | } | ||
1165 | |||
1166 | /* Non DWORD-aligned buffer case handling */ | ||
1167 | if (chan->align_buf && xfer_length && chan->ep_is_in) { | ||
1168 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); | ||
1169 | dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length, | ||
1170 | DMA_FROM_DEVICE); | ||
1171 | memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf, | ||
1172 | xfer_length); | ||
1173 | dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length, | ||
1174 | DMA_FROM_DEVICE); | ||
1175 | } | ||
1176 | |||
1177 | urb->actual_length += xfer_length; | ||
1178 | |||
1179 | hctsiz = readl(hsotg->regs + HCTSIZ(chnum)); | ||
1180 | dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n", | ||
1181 | __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum); | ||
1182 | dev_vdbg(hsotg->dev, " chan->start_pkt_count %d\n", | ||
1183 | chan->start_pkt_count); | ||
1184 | dev_vdbg(hsotg->dev, " hctsiz.pktcnt %d\n", | ||
1185 | (hctsiz & TSIZ_PKTCNT_MASK) >> TSIZ_PKTCNT_SHIFT); | ||
1186 | dev_vdbg(hsotg->dev, " chan->max_packet %d\n", chan->max_packet); | ||
1187 | dev_vdbg(hsotg->dev, " bytes_transferred %d\n", | ||
1188 | xfer_length); | ||
1189 | dev_vdbg(hsotg->dev, " urb->actual_length %d\n", | ||
1190 | urb->actual_length); | ||
1191 | dev_vdbg(hsotg->dev, " urb->transfer_buffer_length %d\n", | ||
1192 | urb->length); | ||
1193 | } | ||
1194 | |||
1195 | /* | ||
1196 | * Handles a host channel NAK interrupt. This handler may be called in either | ||
1197 | * DMA mode or Slave mode. | ||
1198 | */ | ||
1199 | static void dwc2_hc_nak_intr(struct dwc2_hsotg *hsotg, | ||
1200 | struct dwc2_host_chan *chan, int chnum, | ||
1201 | struct dwc2_qtd *qtd) | ||
1202 | { | ||
1203 | if (dbg_hc(chan)) | ||
1204 | dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NAK Received--\n", | ||
1205 | chnum); | ||
1206 | |||
1207 | /* | ||
1208 | * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and | ||
1209 | * interrupt. Re-start the SSPLIT transfer. | ||
1210 | */ | ||
1211 | if (chan->do_split) { | ||
1212 | if (chan->complete_split) | ||
1213 | qtd->error_count = 0; | ||
1214 | qtd->complete_split = 0; | ||
1215 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK); | ||
1216 | goto handle_nak_done; | ||
1217 | } | ||
1218 | |||
1219 | switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) { | ||
1220 | case USB_ENDPOINT_XFER_CONTROL: | ||
1221 | case USB_ENDPOINT_XFER_BULK: | ||
1222 | if (hsotg->core_params->dma_enable > 0 && chan->ep_is_in) { | ||
1223 | /* | ||
1224 | * NAK interrupts are enabled on bulk/control IN | ||
1225 | * transfers in DMA mode for the sole purpose of | ||
1226 | * resetting the error count after a transaction error | ||
1227 | * occurs. The core will continue transferring data. | ||
1228 | */ | ||
1229 | qtd->error_count = 0; | ||
1230 | break; | ||
1231 | } | ||
1232 | |||
1233 | /* | ||
1234 | * NAK interrupts normally occur during OUT transfers in DMA | ||
1235 | * or Slave mode. For IN transfers, more requests will be | ||
1236 | * queued as request queue space is available. | ||
1237 | */ | ||
1238 | qtd->error_count = 0; | ||
1239 | |||
1240 | if (!chan->qh->ping_state) { | ||
1241 | dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb, | ||
1242 | qtd, DWC2_HC_XFER_NAK); | ||
1243 | dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd); | ||
1244 | |||
1245 | if (chan->speed == USB_SPEED_HIGH) | ||
1246 | chan->qh->ping_state = 1; | ||
1247 | } | ||
1248 | |||
1249 | /* | ||
1250 | * Halt the channel so the transfer can be re-started from | ||
1251 | * the appropriate point or the PING protocol will | ||
1252 | * start/continue | ||
1253 | */ | ||
1254 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK); | ||
1255 | break; | ||
1256 | case USB_ENDPOINT_XFER_INT: | ||
1257 | qtd->error_count = 0; | ||
1258 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK); | ||
1259 | break; | ||
1260 | case USB_ENDPOINT_XFER_ISOC: | ||
1261 | /* Should never get called for isochronous transfers */ | ||
1262 | dev_err(hsotg->dev, "NACK interrupt for ISOC transfer\n"); | ||
1263 | break; | ||
1264 | } | ||
1265 | |||
1266 | handle_nak_done: | ||
1267 | disable_hc_int(hsotg, chnum, HCINTMSK_NAK); | ||
1268 | } | ||
1269 | |||
1270 | /* | ||
1271 | * Handles a host channel ACK interrupt. This interrupt is enabled when | ||
1272 | * performing the PING protocol in Slave mode, when errors occur during | ||
1273 | * either Slave mode or DMA mode, and during Start Split transactions. | ||
1274 | */ | ||
1275 | static void dwc2_hc_ack_intr(struct dwc2_hsotg *hsotg, | ||
1276 | struct dwc2_host_chan *chan, int chnum, | ||
1277 | struct dwc2_qtd *qtd) | ||
1278 | { | ||
1279 | struct dwc2_hcd_iso_packet_desc *frame_desc; | ||
1280 | |||
1281 | if (dbg_hc(chan)) | ||
1282 | dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: ACK Received--\n", | ||
1283 | chnum); | ||
1284 | |||
1285 | if (chan->do_split) { | ||
1286 | /* Handle ACK on SSPLIT. ACK should not occur in CSPLIT. */ | ||
1287 | if (!chan->ep_is_in && | ||
1288 | chan->data_pid_start != DWC2_HC_PID_SETUP) | ||
1289 | qtd->ssplit_out_xfer_count = chan->xfer_len; | ||
1290 | |||
1291 | if (chan->ep_type != USB_ENDPOINT_XFER_ISOC || chan->ep_is_in) { | ||
1292 | qtd->complete_split = 1; | ||
1293 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK); | ||
1294 | } else { | ||
1295 | /* ISOC OUT */ | ||
1296 | switch (chan->xact_pos) { | ||
1297 | case DWC2_HCSPLT_XACTPOS_ALL: | ||
1298 | break; | ||
1299 | case DWC2_HCSPLT_XACTPOS_END: | ||
1300 | qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL; | ||
1301 | qtd->isoc_split_offset = 0; | ||
1302 | break; | ||
1303 | case DWC2_HCSPLT_XACTPOS_BEGIN: | ||
1304 | case DWC2_HCSPLT_XACTPOS_MID: | ||
1305 | /* | ||
1306 | * For BEGIN or MID, calculate the length for | ||
1307 | * the next microframe to determine the correct | ||
1308 | * SSPLIT token, either MID or END | ||
1309 | */ | ||
1310 | frame_desc = &qtd->urb->iso_descs[ | ||
1311 | qtd->isoc_frame_index]; | ||
1312 | qtd->isoc_split_offset += 188; | ||
1313 | |||
1314 | if (frame_desc->length - qtd->isoc_split_offset | ||
1315 | <= 188) | ||
1316 | qtd->isoc_split_pos = | ||
1317 | DWC2_HCSPLT_XACTPOS_END; | ||
1318 | else | ||
1319 | qtd->isoc_split_pos = | ||
1320 | DWC2_HCSPLT_XACTPOS_MID; | ||
1321 | break; | ||
1322 | } | ||
1323 | } | ||
1324 | } else { | ||
1325 | qtd->error_count = 0; | ||
1326 | |||
1327 | if (chan->qh->ping_state) { | ||
1328 | chan->qh->ping_state = 0; | ||
1329 | /* | ||
1330 | * Halt the channel so the transfer can be re-started | ||
1331 | * from the appropriate point. This only happens in | ||
1332 | * Slave mode. In DMA mode, the ping_state is cleared | ||
1333 | * when the transfer is started because the core | ||
1334 | * automatically executes the PING, then the transfer. | ||
1335 | */ | ||
1336 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK); | ||
1337 | } | ||
1338 | } | ||
1339 | |||
1340 | /* | ||
1341 | * If the ACK occurred when _not_ in the PING state, let the channel | ||
1342 | * continue transferring data after clearing the error count | ||
1343 | */ | ||
1344 | disable_hc_int(hsotg, chnum, HCINTMSK_ACK); | ||
1345 | } | ||
1346 | |||
1347 | /* | ||
1348 | * Handles a host channel NYET interrupt. This interrupt should only occur on | ||
1349 | * Bulk and Control OUT endpoints and for complete split transactions. If a | ||
1350 | * NYET occurs at the same time as a Transfer Complete interrupt, it is | ||
1351 | * handled in the xfercomp interrupt handler, not here. This handler may be | ||
1352 | * called in either DMA mode or Slave mode. | ||
1353 | */ | ||
1354 | static void dwc2_hc_nyet_intr(struct dwc2_hsotg *hsotg, | ||
1355 | struct dwc2_host_chan *chan, int chnum, | ||
1356 | struct dwc2_qtd *qtd) | ||
1357 | { | ||
1358 | if (dbg_hc(chan)) | ||
1359 | dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NYET Received--\n", | ||
1360 | chnum); | ||
1361 | |||
1362 | /* | ||
1363 | * NYET on CSPLIT | ||
1364 | * re-do the CSPLIT immediately on non-periodic | ||
1365 | */ | ||
1366 | if (chan->do_split && chan->complete_split) { | ||
1367 | if (chan->ep_is_in && chan->ep_type == USB_ENDPOINT_XFER_ISOC && | ||
1368 | hsotg->core_params->dma_enable > 0) { | ||
1369 | qtd->complete_split = 0; | ||
1370 | qtd->isoc_split_offset = 0; | ||
1371 | qtd->isoc_frame_index++; | ||
1372 | if (qtd->urb && | ||
1373 | qtd->isoc_frame_index == qtd->urb->packet_count) { | ||
1374 | dwc2_host_complete(hsotg, qtd, 0); | ||
1375 | dwc2_release_channel(hsotg, chan, qtd, | ||
1376 | DWC2_HC_XFER_URB_COMPLETE); | ||
1377 | } else { | ||
1378 | dwc2_release_channel(hsotg, chan, qtd, | ||
1379 | DWC2_HC_XFER_NO_HALT_STATUS); | ||
1380 | } | ||
1381 | goto handle_nyet_done; | ||
1382 | } | ||
1383 | |||
1384 | if (chan->ep_type == USB_ENDPOINT_XFER_INT || | ||
1385 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) { | ||
1386 | int frnum = dwc2_hcd_get_frame_number(hsotg); | ||
1387 | |||
1388 | if (dwc2_full_frame_num(frnum) != | ||
1389 | dwc2_full_frame_num(chan->qh->sched_frame)) { | ||
1390 | /* | ||
1391 | * No longer in the same full speed frame. | ||
1392 | * Treat this as a transaction error. | ||
1393 | */ | ||
1394 | #if 0 | ||
1395 | /* | ||
1396 | * Todo: Fix system performance so this can | ||
1397 | * be treated as an error. Right now complete | ||
1398 | * splits cannot be scheduled precisely enough | ||
1399 | * due to other system activity, so this error | ||
1400 | * occurs regularly in Slave mode. | ||
1401 | */ | ||
1402 | qtd->error_count++; | ||
1403 | #endif | ||
1404 | qtd->complete_split = 0; | ||
1405 | dwc2_halt_channel(hsotg, chan, qtd, | ||
1406 | DWC2_HC_XFER_XACT_ERR); | ||
1407 | /* Todo: add support for isoc release */ | ||
1408 | goto handle_nyet_done; | ||
1409 | } | ||
1410 | } | ||
1411 | |||
1412 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET); | ||
1413 | goto handle_nyet_done; | ||
1414 | } | ||
1415 | |||
1416 | chan->qh->ping_state = 1; | ||
1417 | qtd->error_count = 0; | ||
1418 | |||
1419 | dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb, qtd, | ||
1420 | DWC2_HC_XFER_NYET); | ||
1421 | dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd); | ||
1422 | |||
1423 | /* | ||
1424 | * Halt the channel and re-start the transfer so the PING protocol | ||
1425 | * will start | ||
1426 | */ | ||
1427 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET); | ||
1428 | |||
1429 | handle_nyet_done: | ||
1430 | disable_hc_int(hsotg, chnum, HCINTMSK_NYET); | ||
1431 | } | ||
1432 | |||
1433 | /* | ||
1434 | * Handles a host channel babble interrupt. This handler may be called in | ||
1435 | * either DMA mode or Slave mode. | ||
1436 | */ | ||
1437 | static void dwc2_hc_babble_intr(struct dwc2_hsotg *hsotg, | ||
1438 | struct dwc2_host_chan *chan, int chnum, | ||
1439 | struct dwc2_qtd *qtd) | ||
1440 | { | ||
1441 | dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Babble Error--\n", | ||
1442 | chnum); | ||
1443 | |||
1444 | dwc2_hc_handle_tt_clear(hsotg, chan, qtd); | ||
1445 | |||
1446 | if (hsotg->core_params->dma_desc_enable > 0) { | ||
1447 | dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum, | ||
1448 | DWC2_HC_XFER_BABBLE_ERR); | ||
1449 | goto disable_int; | ||
1450 | } | ||
1451 | |||
1452 | if (chan->ep_type != USB_ENDPOINT_XFER_ISOC) { | ||
1453 | dwc2_host_complete(hsotg, qtd, -EOVERFLOW); | ||
1454 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_BABBLE_ERR); | ||
1455 | } else { | ||
1456 | enum dwc2_halt_status halt_status; | ||
1457 | |||
1458 | halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum, | ||
1459 | qtd, DWC2_HC_XFER_BABBLE_ERR); | ||
1460 | dwc2_halt_channel(hsotg, chan, qtd, halt_status); | ||
1461 | } | ||
1462 | |||
1463 | disable_int: | ||
1464 | disable_hc_int(hsotg, chnum, HCINTMSK_BBLERR); | ||
1465 | } | ||
1466 | |||
1467 | /* | ||
1468 | * Handles a host channel AHB error interrupt. This handler is only called in | ||
1469 | * DMA mode. | ||
1470 | */ | ||
1471 | static void dwc2_hc_ahberr_intr(struct dwc2_hsotg *hsotg, | ||
1472 | struct dwc2_host_chan *chan, int chnum, | ||
1473 | struct dwc2_qtd *qtd) | ||
1474 | { | ||
1475 | struct dwc2_hcd_urb *urb = qtd->urb; | ||
1476 | char *pipetype, *speed; | ||
1477 | u32 hcchar; | ||
1478 | u32 hcsplt; | ||
1479 | u32 hctsiz; | ||
1480 | u32 hc_dma; | ||
1481 | |||
1482 | dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: AHB Error--\n", | ||
1483 | chnum); | ||
1484 | |||
1485 | if (!urb) | ||
1486 | goto handle_ahberr_halt; | ||
1487 | |||
1488 | dwc2_hc_handle_tt_clear(hsotg, chan, qtd); | ||
1489 | |||
1490 | hcchar = readl(hsotg->regs + HCCHAR(chnum)); | ||
1491 | hcsplt = readl(hsotg->regs + HCSPLT(chnum)); | ||
1492 | hctsiz = readl(hsotg->regs + HCTSIZ(chnum)); | ||
1493 | hc_dma = readl(hsotg->regs + HCDMA(chnum)); | ||
1494 | |||
1495 | dev_err(hsotg->dev, "AHB ERROR, Channel %d\n", chnum); | ||
1496 | dev_err(hsotg->dev, " hcchar 0x%08x, hcsplt 0x%08x\n", hcchar, hcsplt); | ||
1497 | dev_err(hsotg->dev, " hctsiz 0x%08x, hc_dma 0x%08x\n", hctsiz, hc_dma); | ||
1498 | dev_err(hsotg->dev, " Device address: %d\n", | ||
1499 | dwc2_hcd_get_dev_addr(&urb->pipe_info)); | ||
1500 | dev_err(hsotg->dev, " Endpoint: %d, %s\n", | ||
1501 | dwc2_hcd_get_ep_num(&urb->pipe_info), | ||
1502 | dwc2_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"); | ||
1503 | |||
1504 | switch (dwc2_hcd_get_pipe_type(&urb->pipe_info)) { | ||
1505 | case USB_ENDPOINT_XFER_CONTROL: | ||
1506 | pipetype = "CONTROL"; | ||
1507 | break; | ||
1508 | case USB_ENDPOINT_XFER_BULK: | ||
1509 | pipetype = "BULK"; | ||
1510 | break; | ||
1511 | case USB_ENDPOINT_XFER_INT: | ||
1512 | pipetype = "INTERRUPT"; | ||
1513 | break; | ||
1514 | case USB_ENDPOINT_XFER_ISOC: | ||
1515 | pipetype = "ISOCHRONOUS"; | ||
1516 | break; | ||
1517 | default: | ||
1518 | pipetype = "UNKNOWN"; | ||
1519 | break; | ||
1520 | } | ||
1521 | |||
1522 | dev_err(hsotg->dev, " Endpoint type: %s\n", pipetype); | ||
1523 | |||
1524 | switch (chan->speed) { | ||
1525 | case USB_SPEED_HIGH: | ||
1526 | speed = "HIGH"; | ||
1527 | break; | ||
1528 | case USB_SPEED_FULL: | ||
1529 | speed = "FULL"; | ||
1530 | break; | ||
1531 | case USB_SPEED_LOW: | ||
1532 | speed = "LOW"; | ||
1533 | break; | ||
1534 | default: | ||
1535 | speed = "UNKNOWN"; | ||
1536 | break; | ||
1537 | } | ||
1538 | |||
1539 | dev_err(hsotg->dev, " Speed: %s\n", speed); | ||
1540 | |||
1541 | dev_err(hsotg->dev, " Max packet size: %d\n", | ||
1542 | dwc2_hcd_get_mps(&urb->pipe_info)); | ||
1543 | dev_err(hsotg->dev, " Data buffer length: %d\n", urb->length); | ||
1544 | dev_err(hsotg->dev, " Transfer buffer: %p, Transfer DMA: %08lx\n", | ||
1545 | urb->buf, (unsigned long)urb->dma); | ||
1546 | dev_err(hsotg->dev, " Setup buffer: %p, Setup DMA: %08lx\n", | ||
1547 | urb->setup_packet, (unsigned long)urb->setup_dma); | ||
1548 | dev_err(hsotg->dev, " Interval: %d\n", urb->interval); | ||
1549 | |||
1550 | /* Core halts the channel for Descriptor DMA mode */ | ||
1551 | if (hsotg->core_params->dma_desc_enable > 0) { | ||
1552 | dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum, | ||
1553 | DWC2_HC_XFER_AHB_ERR); | ||
1554 | goto handle_ahberr_done; | ||
1555 | } | ||
1556 | |||
1557 | dwc2_host_complete(hsotg, qtd, -EIO); | ||
1558 | |||
1559 | handle_ahberr_halt: | ||
1560 | /* | ||
1561 | * Force a channel halt. Don't call dwc2_halt_channel because that won't | ||
1562 | * write to the HCCHARn register in DMA mode to force the halt. | ||
1563 | */ | ||
1564 | dwc2_hc_halt(hsotg, chan, DWC2_HC_XFER_AHB_ERR); | ||
1565 | |||
1566 | handle_ahberr_done: | ||
1567 | disable_hc_int(hsotg, chnum, HCINTMSK_AHBERR); | ||
1568 | } | ||
1569 | |||
1570 | /* | ||
1571 | * Handles a host channel transaction error interrupt. This handler may be | ||
1572 | * called in either DMA mode or Slave mode. | ||
1573 | */ | ||
1574 | static void dwc2_hc_xacterr_intr(struct dwc2_hsotg *hsotg, | ||
1575 | struct dwc2_host_chan *chan, int chnum, | ||
1576 | struct dwc2_qtd *qtd) | ||
1577 | { | ||
1578 | dev_dbg(hsotg->dev, | ||
1579 | "--Host Channel %d Interrupt: Transaction Error--\n", chnum); | ||
1580 | |||
1581 | dwc2_hc_handle_tt_clear(hsotg, chan, qtd); | ||
1582 | |||
1583 | if (hsotg->core_params->dma_desc_enable > 0) { | ||
1584 | dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum, | ||
1585 | DWC2_HC_XFER_XACT_ERR); | ||
1586 | goto handle_xacterr_done; | ||
1587 | } | ||
1588 | |||
1589 | switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) { | ||
1590 | case USB_ENDPOINT_XFER_CONTROL: | ||
1591 | case USB_ENDPOINT_XFER_BULK: | ||
1592 | qtd->error_count++; | ||
1593 | if (!chan->qh->ping_state) { | ||
1594 | |||
1595 | dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb, | ||
1596 | qtd, DWC2_HC_XFER_XACT_ERR); | ||
1597 | dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd); | ||
1598 | if (!chan->ep_is_in && chan->speed == USB_SPEED_HIGH) | ||
1599 | chan->qh->ping_state = 1; | ||
1600 | } | ||
1601 | |||
1602 | /* | ||
1603 | * Halt the channel so the transfer can be re-started from | ||
1604 | * the appropriate point or the PING protocol will start | ||
1605 | */ | ||
1606 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR); | ||
1607 | break; | ||
1608 | case USB_ENDPOINT_XFER_INT: | ||
1609 | qtd->error_count++; | ||
1610 | if (chan->do_split && chan->complete_split) | ||
1611 | qtd->complete_split = 0; | ||
1612 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR); | ||
1613 | break; | ||
1614 | case USB_ENDPOINT_XFER_ISOC: | ||
1615 | { | ||
1616 | enum dwc2_halt_status halt_status; | ||
1617 | |||
1618 | halt_status = dwc2_update_isoc_urb_state(hsotg, chan, | ||
1619 | chnum, qtd, DWC2_HC_XFER_XACT_ERR); | ||
1620 | dwc2_halt_channel(hsotg, chan, qtd, halt_status); | ||
1621 | } | ||
1622 | break; | ||
1623 | } | ||
1624 | |||
1625 | handle_xacterr_done: | ||
1626 | disable_hc_int(hsotg, chnum, HCINTMSK_XACTERR); | ||
1627 | } | ||
1628 | |||
1629 | /* | ||
1630 | * Handles a host channel frame overrun interrupt. This handler may be called | ||
1631 | * in either DMA mode or Slave mode. | ||
1632 | */ | ||
1633 | static void dwc2_hc_frmovrun_intr(struct dwc2_hsotg *hsotg, | ||
1634 | struct dwc2_host_chan *chan, int chnum, | ||
1635 | struct dwc2_qtd *qtd) | ||
1636 | { | ||
1637 | enum dwc2_halt_status halt_status; | ||
1638 | |||
1639 | if (dbg_hc(chan)) | ||
1640 | dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Frame Overrun--\n", | ||
1641 | chnum); | ||
1642 | |||
1643 | dwc2_hc_handle_tt_clear(hsotg, chan, qtd); | ||
1644 | |||
1645 | switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) { | ||
1646 | case USB_ENDPOINT_XFER_CONTROL: | ||
1647 | case USB_ENDPOINT_XFER_BULK: | ||
1648 | break; | ||
1649 | case USB_ENDPOINT_XFER_INT: | ||
1650 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_FRAME_OVERRUN); | ||
1651 | break; | ||
1652 | case USB_ENDPOINT_XFER_ISOC: | ||
1653 | halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum, | ||
1654 | qtd, DWC2_HC_XFER_FRAME_OVERRUN); | ||
1655 | dwc2_halt_channel(hsotg, chan, qtd, halt_status); | ||
1656 | break; | ||
1657 | } | ||
1658 | |||
1659 | disable_hc_int(hsotg, chnum, HCINTMSK_FRMOVRUN); | ||
1660 | } | ||
1661 | |||
1662 | /* | ||
1663 | * Handles a host channel data toggle error interrupt. This handler may be | ||
1664 | * called in either DMA mode or Slave mode. | ||
1665 | */ | ||
1666 | static void dwc2_hc_datatglerr_intr(struct dwc2_hsotg *hsotg, | ||
1667 | struct dwc2_host_chan *chan, int chnum, | ||
1668 | struct dwc2_qtd *qtd) | ||
1669 | { | ||
1670 | dev_dbg(hsotg->dev, | ||
1671 | "--Host Channel %d Interrupt: Data Toggle Error--\n", chnum); | ||
1672 | |||
1673 | if (chan->ep_is_in) | ||
1674 | qtd->error_count = 0; | ||
1675 | else | ||
1676 | dev_err(hsotg->dev, | ||
1677 | "Data Toggle Error on OUT transfer, channel %d\n", | ||
1678 | chnum); | ||
1679 | |||
1680 | dwc2_hc_handle_tt_clear(hsotg, chan, qtd); | ||
1681 | disable_hc_int(hsotg, chnum, HCINTMSK_DATATGLERR); | ||
1682 | } | ||
1683 | |||
1684 | /* | ||
1685 | * For debug only. It checks that a valid halt status is set and that | ||
1686 | * HCCHARn.chdis is clear. If there's a problem, corrective action is | ||
1687 | * taken and a warning is issued. | ||
1688 | * | ||
1689 | * Return: true if halt status is ok, false otherwise | ||
1690 | */ | ||
1691 | static bool dwc2_halt_status_ok(struct dwc2_hsotg *hsotg, | ||
1692 | struct dwc2_host_chan *chan, int chnum, | ||
1693 | struct dwc2_qtd *qtd) | ||
1694 | { | ||
1695 | #ifdef DEBUG | ||
1696 | u32 hcchar; | ||
1697 | u32 hctsiz; | ||
1698 | u32 hcintmsk; | ||
1699 | u32 hcsplt; | ||
1700 | |||
1701 | if (chan->halt_status == DWC2_HC_XFER_NO_HALT_STATUS) { | ||
1702 | /* | ||
1703 | * This code is here only as a check. This condition should | ||
1704 | * never happen. Ignore the halt if it does occur. | ||
1705 | */ | ||
1706 | hcchar = readl(hsotg->regs + HCCHAR(chnum)); | ||
1707 | hctsiz = readl(hsotg->regs + HCTSIZ(chnum)); | ||
1708 | hcintmsk = readl(hsotg->regs + HCINTMSK(chnum)); | ||
1709 | hcsplt = readl(hsotg->regs + HCSPLT(chnum)); | ||
1710 | dev_dbg(hsotg->dev, | ||
1711 | "%s: chan->halt_status DWC2_HC_XFER_NO_HALT_STATUS,\n", | ||
1712 | __func__); | ||
1713 | dev_dbg(hsotg->dev, | ||
1714 | "channel %d, hcchar 0x%08x, hctsiz 0x%08x,\n", | ||
1715 | chnum, hcchar, hctsiz); | ||
1716 | dev_dbg(hsotg->dev, | ||
1717 | "hcint 0x%08x, hcintmsk 0x%08x, hcsplt 0x%08x,\n", | ||
1718 | chan->hcint, hcintmsk, hcsplt); | ||
1719 | if (qtd) | ||
1720 | dev_dbg(hsotg->dev, "qtd->complete_split %d\n", | ||
1721 | qtd->complete_split); | ||
1722 | dev_warn(hsotg->dev, | ||
1723 | "%s: no halt status, channel %d, ignoring interrupt\n", | ||
1724 | __func__, chnum); | ||
1725 | return false; | ||
1726 | } | ||
1727 | |||
1728 | /* | ||
1729 | * This code is here only as a check. hcchar.chdis should never be set | ||
1730 | * when the halt interrupt occurs. Halt the channel again if it does | ||
1731 | * occur. | ||
1732 | */ | ||
1733 | hcchar = readl(hsotg->regs + HCCHAR(chnum)); | ||
1734 | if (hcchar & HCCHAR_CHDIS) { | ||
1735 | dev_warn(hsotg->dev, | ||
1736 | "%s: hcchar.chdis set unexpectedly, hcchar 0x%08x, trying to halt again\n", | ||
1737 | __func__, hcchar); | ||
1738 | chan->halt_pending = 0; | ||
1739 | dwc2_halt_channel(hsotg, chan, qtd, chan->halt_status); | ||
1740 | return false; | ||
1741 | } | ||
1742 | #endif | ||
1743 | |||
1744 | return true; | ||
1745 | } | ||
1746 | |||
1747 | /* | ||
1748 | * Handles a host Channel Halted interrupt in DMA mode. This handler | ||
1749 | * determines the reason the channel halted and proceeds accordingly. | ||
1750 | */ | ||
1751 | static void dwc2_hc_chhltd_intr_dma(struct dwc2_hsotg *hsotg, | ||
1752 | struct dwc2_host_chan *chan, int chnum, | ||
1753 | struct dwc2_qtd *qtd) | ||
1754 | { | ||
1755 | u32 hcintmsk; | ||
1756 | int out_nak_enh = 0; | ||
1757 | |||
1758 | if (dbg_hc(chan)) | ||
1759 | dev_vdbg(hsotg->dev, | ||
1760 | "--Host Channel %d Interrupt: DMA Channel Halted--\n", | ||
1761 | chnum); | ||
1762 | |||
1763 | /* | ||
1764 | * For core with OUT NAK enhancement, the flow for high-speed | ||
1765 | * CONTROL/BULK OUT is handled a little differently | ||
1766 | */ | ||
1767 | if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_71a) { | ||
1768 | if (chan->speed == USB_SPEED_HIGH && !chan->ep_is_in && | ||
1769 | (chan->ep_type == USB_ENDPOINT_XFER_CONTROL || | ||
1770 | chan->ep_type == USB_ENDPOINT_XFER_BULK)) { | ||
1771 | out_nak_enh = 1; | ||
1772 | } | ||
1773 | } | ||
1774 | |||
1775 | if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE || | ||
1776 | (chan->halt_status == DWC2_HC_XFER_AHB_ERR && | ||
1777 | hsotg->core_params->dma_desc_enable <= 0)) { | ||
1778 | if (hsotg->core_params->dma_desc_enable > 0) | ||
1779 | dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum, | ||
1780 | chan->halt_status); | ||
1781 | else | ||
1782 | /* | ||
1783 | * Just release the channel. A dequeue can happen on a | ||
1784 | * transfer timeout. In the case of an AHB Error, the | ||
1785 | * channel was forced to halt because there's no way to | ||
1786 | * gracefully recover. | ||
1787 | */ | ||
1788 | dwc2_release_channel(hsotg, chan, qtd, | ||
1789 | chan->halt_status); | ||
1790 | return; | ||
1791 | } | ||
1792 | |||
1793 | hcintmsk = readl(hsotg->regs + HCINTMSK(chnum)); | ||
1794 | |||
1795 | if (chan->hcint & HCINTMSK_XFERCOMPL) { | ||
1796 | /* | ||
1797 | * Todo: This is here because of a possible hardware bug. Spec | ||
1798 | * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT | ||
1799 | * interrupt w/ACK bit set should occur, but I only see the | ||
1800 | * XFERCOMP bit, even with it masked out. This is a workaround | ||
1801 | * for that behavior. Should fix this when hardware is fixed. | ||
1802 | */ | ||
1803 | if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && !chan->ep_is_in) | ||
1804 | dwc2_hc_ack_intr(hsotg, chan, chnum, qtd); | ||
1805 | dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd); | ||
1806 | } else if (chan->hcint & HCINTMSK_STALL) { | ||
1807 | dwc2_hc_stall_intr(hsotg, chan, chnum, qtd); | ||
1808 | } else if ((chan->hcint & HCINTMSK_XACTERR) && | ||
1809 | hsotg->core_params->dma_desc_enable <= 0) { | ||
1810 | if (out_nak_enh) { | ||
1811 | if (chan->hcint & | ||
1812 | (HCINTMSK_NYET | HCINTMSK_NAK | HCINTMSK_ACK)) { | ||
1813 | dev_vdbg(hsotg->dev, | ||
1814 | "XactErr with NYET/NAK/ACK\n"); | ||
1815 | qtd->error_count = 0; | ||
1816 | } else { | ||
1817 | dev_vdbg(hsotg->dev, | ||
1818 | "XactErr without NYET/NAK/ACK\n"); | ||
1819 | } | ||
1820 | } | ||
1821 | |||
1822 | /* | ||
1823 | * Must handle xacterr before nak or ack. Could get a xacterr | ||
1824 | * at the same time as either of these on a BULK/CONTROL OUT | ||
1825 | * that started with a PING. The xacterr takes precedence. | ||
1826 | */ | ||
1827 | dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd); | ||
1828 | } else if ((chan->hcint & HCINTMSK_XCS_XACT) && | ||
1829 | hsotg->core_params->dma_desc_enable > 0) { | ||
1830 | dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd); | ||
1831 | } else if ((chan->hcint & HCINTMSK_AHBERR) && | ||
1832 | hsotg->core_params->dma_desc_enable > 0) { | ||
1833 | dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd); | ||
1834 | } else if (chan->hcint & HCINTMSK_BBLERR) { | ||
1835 | dwc2_hc_babble_intr(hsotg, chan, chnum, qtd); | ||
1836 | } else if (chan->hcint & HCINTMSK_FRMOVRUN) { | ||
1837 | dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd); | ||
1838 | } else if (!out_nak_enh) { | ||
1839 | if (chan->hcint & HCINTMSK_NYET) { | ||
1840 | /* | ||
1841 | * Must handle nyet before nak or ack. Could get a nyet | ||
1842 | * at the same time as either of those on a BULK/CONTROL | ||
1843 | * OUT that started with a PING. The nyet takes | ||
1844 | * precedence. | ||
1845 | */ | ||
1846 | dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd); | ||
1847 | } else if ((chan->hcint & HCINTMSK_NAK) && | ||
1848 | !(hcintmsk & HCINTMSK_NAK)) { | ||
1849 | /* | ||
1850 | * If nak is not masked, it's because a non-split IN | ||
1851 | * transfer is in an error state. In that case, the nak | ||
1852 | * is handled by the nak interrupt handler, not here. | ||
1853 | * Handle nak here for BULK/CONTROL OUT transfers, which | ||
1854 | * halt on a NAK to allow rewinding the buffer pointer. | ||
1855 | */ | ||
1856 | dwc2_hc_nak_intr(hsotg, chan, chnum, qtd); | ||
1857 | } else if ((chan->hcint & HCINTMSK_ACK) && | ||
1858 | !(hcintmsk & HCINTMSK_ACK)) { | ||
1859 | /* | ||
1860 | * If ack is not masked, it's because a non-split IN | ||
1861 | * transfer is in an error state. In that case, the ack | ||
1862 | * is handled by the ack interrupt handler, not here. | ||
1863 | * Handle ack here for split transfers. Start splits | ||
1864 | * halt on ACK. | ||
1865 | */ | ||
1866 | dwc2_hc_ack_intr(hsotg, chan, chnum, qtd); | ||
1867 | } else { | ||
1868 | if (chan->ep_type == USB_ENDPOINT_XFER_INT || | ||
1869 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) { | ||
1870 | /* | ||
1871 | * A periodic transfer halted with no other | ||
1872 | * channel interrupts set. Assume it was halted | ||
1873 | * by the core because it could not be completed | ||
1874 | * in its scheduled (micro)frame. | ||
1875 | */ | ||
1876 | dev_dbg(hsotg->dev, | ||
1877 | "%s: Halt channel %d (assume incomplete periodic transfer)\n", | ||
1878 | __func__, chnum); | ||
1879 | dwc2_halt_channel(hsotg, chan, qtd, | ||
1880 | DWC2_HC_XFER_PERIODIC_INCOMPLETE); | ||
1881 | } else { | ||
1882 | dev_err(hsotg->dev, | ||
1883 | "%s: Channel %d - ChHltd set, but reason is unknown\n", | ||
1884 | __func__, chnum); | ||
1885 | dev_err(hsotg->dev, | ||
1886 | "hcint 0x%08x, intsts 0x%08x\n", | ||
1887 | chan->hcint, | ||
1888 | readl(hsotg->regs + GINTSTS)); | ||
1889 | } | ||
1890 | } | ||
1891 | } else { | ||
1892 | dev_info(hsotg->dev, | ||
1893 | "NYET/NAK/ACK/other in non-error case, 0x%08x\n", | ||
1894 | chan->hcint); | ||
1895 | } | ||
1896 | } | ||
1897 | |||
1898 | /* | ||
1899 | * Handles a host channel Channel Halted interrupt | ||
1900 | * | ||
1901 | * In slave mode, this handler is called only when the driver specifically | ||
1902 | * requests a halt. This occurs during handling other host channel interrupts | ||
1903 | * (e.g. nak, xacterr, stall, nyet, etc.). | ||
1904 | * | ||
1905 | * In DMA mode, this is the interrupt that occurs when the core has finished | ||
1906 | * processing a transfer on a channel. Other host channel interrupts (except | ||
1907 | * ahberr) are disabled in DMA mode. | ||
1908 | */ | ||
1909 | static void dwc2_hc_chhltd_intr(struct dwc2_hsotg *hsotg, | ||
1910 | struct dwc2_host_chan *chan, int chnum, | ||
1911 | struct dwc2_qtd *qtd) | ||
1912 | { | ||
1913 | if (dbg_hc(chan)) | ||
1914 | dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: Channel Halted--\n", | ||
1915 | chnum); | ||
1916 | |||
1917 | if (hsotg->core_params->dma_enable > 0) { | ||
1918 | dwc2_hc_chhltd_intr_dma(hsotg, chan, chnum, qtd); | ||
1919 | } else { | ||
1920 | if (!dwc2_halt_status_ok(hsotg, chan, chnum, qtd)) | ||
1921 | return; | ||
1922 | dwc2_release_channel(hsotg, chan, qtd, chan->halt_status); | ||
1923 | } | ||
1924 | } | ||
1925 | |||
1926 | /* Handles interrupt for a specific Host Channel */ | ||
1927 | static void dwc2_hc_n_intr(struct dwc2_hsotg *hsotg, int chnum) | ||
1928 | { | ||
1929 | struct dwc2_qtd *qtd; | ||
1930 | struct dwc2_host_chan *chan; | ||
1931 | u32 hcint, hcintmsk; | ||
1932 | |||
1933 | chan = hsotg->hc_ptr_array[chnum]; | ||
1934 | |||
1935 | hcint = readl(hsotg->regs + HCINT(chnum)); | ||
1936 | hcintmsk = readl(hsotg->regs + HCINTMSK(chnum)); | ||
1937 | if (!chan) { | ||
1938 | dev_err(hsotg->dev, "## hc_ptr_array for channel is NULL ##\n"); | ||
1939 | writel(hcint, hsotg->regs + HCINT(chnum)); | ||
1940 | return; | ||
1941 | } | ||
1942 | |||
1943 | if (dbg_hc(chan)) { | ||
1944 | dev_vdbg(hsotg->dev, "--Host Channel Interrupt--, Channel %d\n", | ||
1945 | chnum); | ||
1946 | dev_vdbg(hsotg->dev, | ||
1947 | " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n", | ||
1948 | hcint, hcintmsk, hcint & hcintmsk); | ||
1949 | } | ||
1950 | |||
1951 | writel(hcint, hsotg->regs + HCINT(chnum)); | ||
1952 | chan->hcint = hcint; | ||
1953 | hcint &= hcintmsk; | ||
1954 | |||
1955 | /* | ||
1956 | * If the channel was halted due to a dequeue, the qtd list might | ||
1957 | * be empty or at least the first entry will not be the active qtd. | ||
1958 | * In this case, take a shortcut and just release the channel. | ||
1959 | */ | ||
1960 | if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) { | ||
1961 | /* | ||
1962 | * If the channel was halted, this should be the only | ||
1963 | * interrupt unmasked | ||
1964 | */ | ||
1965 | WARN_ON(hcint != HCINTMSK_CHHLTD); | ||
1966 | if (hsotg->core_params->dma_desc_enable > 0) | ||
1967 | dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum, | ||
1968 | chan->halt_status); | ||
1969 | else | ||
1970 | dwc2_release_channel(hsotg, chan, NULL, | ||
1971 | chan->halt_status); | ||
1972 | return; | ||
1973 | } | ||
1974 | |||
1975 | if (list_empty(&chan->qh->qtd_list)) { | ||
1976 | /* | ||
1977 | * TODO: Will this ever happen with the | ||
1978 | * DWC2_HC_XFER_URB_DEQUEUE handling above? | ||
1979 | */ | ||
1980 | dev_dbg(hsotg->dev, "## no QTD queued for channel %d ##\n", | ||
1981 | chnum); | ||
1982 | dev_dbg(hsotg->dev, | ||
1983 | " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n", | ||
1984 | chan->hcint, hcintmsk, hcint); | ||
1985 | chan->halt_status = DWC2_HC_XFER_NO_HALT_STATUS; | ||
1986 | disable_hc_int(hsotg, chnum, HCINTMSK_CHHLTD); | ||
1987 | chan->hcint = 0; | ||
1988 | return; | ||
1989 | } | ||
1990 | |||
1991 | qtd = list_first_entry(&chan->qh->qtd_list, struct dwc2_qtd, | ||
1992 | qtd_list_entry); | ||
1993 | |||
1994 | if (hsotg->core_params->dma_enable <= 0) { | ||
1995 | if ((hcint & HCINTMSK_CHHLTD) && hcint != HCINTMSK_CHHLTD) | ||
1996 | hcint &= ~HCINTMSK_CHHLTD; | ||
1997 | } | ||
1998 | |||
1999 | if (hcint & HCINTMSK_XFERCOMPL) { | ||
2000 | dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd); | ||
2001 | /* | ||
2002 | * If NYET occurred at same time as Xfer Complete, the NYET is | ||
2003 | * handled by the Xfer Complete interrupt handler. Don't want | ||
2004 | * to call the NYET interrupt handler in this case. | ||
2005 | */ | ||
2006 | hcint &= ~HCINTMSK_NYET; | ||
2007 | } | ||
2008 | if (hcint & HCINTMSK_CHHLTD) | ||
2009 | dwc2_hc_chhltd_intr(hsotg, chan, chnum, qtd); | ||
2010 | if (hcint & HCINTMSK_AHBERR) | ||
2011 | dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd); | ||
2012 | if (hcint & HCINTMSK_STALL) | ||
2013 | dwc2_hc_stall_intr(hsotg, chan, chnum, qtd); | ||
2014 | if (hcint & HCINTMSK_NAK) | ||
2015 | dwc2_hc_nak_intr(hsotg, chan, chnum, qtd); | ||
2016 | if (hcint & HCINTMSK_ACK) | ||
2017 | dwc2_hc_ack_intr(hsotg, chan, chnum, qtd); | ||
2018 | if (hcint & HCINTMSK_NYET) | ||
2019 | dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd); | ||
2020 | if (hcint & HCINTMSK_XACTERR) | ||
2021 | dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd); | ||
2022 | if (hcint & HCINTMSK_BBLERR) | ||
2023 | dwc2_hc_babble_intr(hsotg, chan, chnum, qtd); | ||
2024 | if (hcint & HCINTMSK_FRMOVRUN) | ||
2025 | dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd); | ||
2026 | if (hcint & HCINTMSK_DATATGLERR) | ||
2027 | dwc2_hc_datatglerr_intr(hsotg, chan, chnum, qtd); | ||
2028 | |||
2029 | chan->hcint = 0; | ||
2030 | } | ||
2031 | |||
2032 | /* | ||
2033 | * This interrupt indicates that one or more host channels has a pending | ||
2034 | * interrupt. There are multiple conditions that can cause each host channel | ||
2035 | * interrupt. This function determines which conditions have occurred for each | ||
2036 | * host channel interrupt and handles them appropriately. | ||
2037 | */ | ||
2038 | static void dwc2_hc_intr(struct dwc2_hsotg *hsotg) | ||
2039 | { | ||
2040 | u32 haint; | ||
2041 | int i; | ||
2042 | |||
2043 | haint = readl(hsotg->regs + HAINT); | ||
2044 | if (dbg_perio()) { | ||
2045 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
2046 | |||
2047 | dev_vdbg(hsotg->dev, "HAINT=%08x\n", haint); | ||
2048 | } | ||
2049 | |||
2050 | for (i = 0; i < hsotg->core_params->host_channels; i++) { | ||
2051 | if (haint & (1 << i)) | ||
2052 | dwc2_hc_n_intr(hsotg, i); | ||
2053 | } | ||
2054 | } | ||
2055 | |||
2056 | /* This function handles interrupts for the HCD */ | ||
2057 | irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg) | ||
2058 | { | ||
2059 | u32 gintsts, dbg_gintsts; | ||
2060 | irqreturn_t retval = IRQ_NONE; | ||
2061 | |||
2062 | if (!dwc2_is_controller_alive(hsotg)) { | ||
2063 | dev_warn(hsotg->dev, "Controller is dead\n"); | ||
2064 | return retval; | ||
2065 | } | ||
2066 | |||
2067 | spin_lock(&hsotg->lock); | ||
2068 | |||
2069 | /* Check if HOST Mode */ | ||
2070 | if (dwc2_is_host_mode(hsotg)) { | ||
2071 | gintsts = dwc2_read_core_intr(hsotg); | ||
2072 | if (!gintsts) { | ||
2073 | spin_unlock(&hsotg->lock); | ||
2074 | return retval; | ||
2075 | } | ||
2076 | |||
2077 | retval = IRQ_HANDLED; | ||
2078 | |||
2079 | dbg_gintsts = gintsts; | ||
2080 | #ifndef DEBUG_SOF | ||
2081 | dbg_gintsts &= ~GINTSTS_SOF; | ||
2082 | #endif | ||
2083 | if (!dbg_perio()) | ||
2084 | dbg_gintsts &= ~(GINTSTS_HCHINT | GINTSTS_RXFLVL | | ||
2085 | GINTSTS_PTXFEMP); | ||
2086 | |||
2087 | /* Only print if there are any non-suppressed interrupts left */ | ||
2088 | if (dbg_gintsts) | ||
2089 | dev_vdbg(hsotg->dev, | ||
2090 | "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n", | ||
2091 | gintsts); | ||
2092 | |||
2093 | if (gintsts & GINTSTS_SOF) | ||
2094 | dwc2_sof_intr(hsotg); | ||
2095 | if (gintsts & GINTSTS_RXFLVL) | ||
2096 | dwc2_rx_fifo_level_intr(hsotg); | ||
2097 | if (gintsts & GINTSTS_NPTXFEMP) | ||
2098 | dwc2_np_tx_fifo_empty_intr(hsotg); | ||
2099 | if (gintsts & GINTSTS_PRTINT) | ||
2100 | dwc2_port_intr(hsotg); | ||
2101 | if (gintsts & GINTSTS_HCHINT) | ||
2102 | dwc2_hc_intr(hsotg); | ||
2103 | if (gintsts & GINTSTS_PTXFEMP) | ||
2104 | dwc2_perio_tx_fifo_empty_intr(hsotg); | ||
2105 | |||
2106 | if (dbg_gintsts) { | ||
2107 | dev_vdbg(hsotg->dev, | ||
2108 | "DWC OTG HCD Finished Servicing Interrupts\n"); | ||
2109 | dev_vdbg(hsotg->dev, | ||
2110 | "DWC OTG HCD gintsts=0x%08x gintmsk=0x%08x\n", | ||
2111 | readl(hsotg->regs + GINTSTS), | ||
2112 | readl(hsotg->regs + GINTMSK)); | ||
2113 | } | ||
2114 | } | ||
2115 | |||
2116 | spin_unlock(&hsotg->lock); | ||
2117 | |||
2118 | return retval; | ||
2119 | } | ||
diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c new file mode 100644 index 000000000000..9540f7e1e20e --- /dev/null +++ b/drivers/usb/dwc2/hcd_queue.c | |||
@@ -0,0 +1,835 @@ | |||
1 | /* | ||
2 | * hcd_queue.c - DesignWare HS OTG Controller host queuing routines | ||
3 | * | ||
4 | * Copyright (C) 2004-2013 Synopsys, Inc. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions, and the following disclaimer, | ||
11 | * without modification. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The names of the above-listed copyright holders may not be used | ||
16 | * to endorse or promote products derived from this software without | ||
17 | * specific prior written permission. | ||
18 | * | ||
19 | * ALTERNATIVELY, this software may be distributed under the terms of the | ||
20 | * GNU General Public License ("GPL") as published by the Free Software | ||
21 | * Foundation; either version 2 of the License, or (at your option) any | ||
22 | * later version. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
26 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
35 | */ | ||
36 | |||
37 | /* | ||
38 | * This file contains the functions to manage Queue Heads and Queue | ||
39 | * Transfer Descriptors for Host mode | ||
40 | */ | ||
41 | #include <linux/kernel.h> | ||
42 | #include <linux/module.h> | ||
43 | #include <linux/spinlock.h> | ||
44 | #include <linux/interrupt.h> | ||
45 | #include <linux/dma-mapping.h> | ||
46 | #include <linux/io.h> | ||
47 | #include <linux/slab.h> | ||
48 | #include <linux/usb.h> | ||
49 | |||
50 | #include <linux/usb/hcd.h> | ||
51 | #include <linux/usb/ch11.h> | ||
52 | |||
53 | #include "core.h" | ||
54 | #include "hcd.h" | ||
55 | |||
56 | /** | ||
57 | * dwc2_qh_init() - Initializes a QH structure | ||
58 | * | ||
59 | * @hsotg: The HCD state structure for the DWC OTG controller | ||
60 | * @qh: The QH to init | ||
61 | * @urb: Holds the information about the device/endpoint needed to initialize | ||
62 | * the QH | ||
63 | */ | ||
64 | #define SCHEDULE_SLOP 10 | ||
65 | static void dwc2_qh_init(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, | ||
66 | struct dwc2_hcd_urb *urb) | ||
67 | { | ||
68 | int dev_speed, hub_addr, hub_port; | ||
69 | char *speed, *type; | ||
70 | |||
71 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
72 | |||
73 | /* Initialize QH */ | ||
74 | qh->ep_type = dwc2_hcd_get_pipe_type(&urb->pipe_info); | ||
75 | qh->ep_is_in = dwc2_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0; | ||
76 | |||
77 | qh->data_toggle = DWC2_HC_PID_DATA0; | ||
78 | qh->maxp = dwc2_hcd_get_mps(&urb->pipe_info); | ||
79 | INIT_LIST_HEAD(&qh->qtd_list); | ||
80 | INIT_LIST_HEAD(&qh->qh_list_entry); | ||
81 | |||
82 | /* FS/LS Endpoint on HS Hub, NOT virtual root hub */ | ||
83 | dev_speed = dwc2_host_get_speed(hsotg, urb->priv); | ||
84 | |||
85 | dwc2_host_hub_info(hsotg, urb->priv, &hub_addr, &hub_port); | ||
86 | |||
87 | if ((dev_speed == USB_SPEED_LOW || dev_speed == USB_SPEED_FULL) && | ||
88 | hub_addr != 0 && hub_addr != 1) { | ||
89 | dev_vdbg(hsotg->dev, | ||
90 | "QH init: EP %d: TT found at hub addr %d, for port %d\n", | ||
91 | dwc2_hcd_get_ep_num(&urb->pipe_info), hub_addr, | ||
92 | hub_port); | ||
93 | qh->do_split = 1; | ||
94 | } | ||
95 | |||
96 | if (qh->ep_type == USB_ENDPOINT_XFER_INT || | ||
97 | qh->ep_type == USB_ENDPOINT_XFER_ISOC) { | ||
98 | /* Compute scheduling parameters once and save them */ | ||
99 | u32 hprt, prtspd; | ||
100 | |||
101 | /* Todo: Account for split transfers in the bus time */ | ||
102 | int bytecount = | ||
103 | dwc2_hb_mult(qh->maxp) * dwc2_max_packet(qh->maxp); | ||
104 | |||
105 | qh->usecs = NS_TO_US(usb_calc_bus_time(qh->do_split ? | ||
106 | USB_SPEED_HIGH : dev_speed, qh->ep_is_in, | ||
107 | qh->ep_type == USB_ENDPOINT_XFER_ISOC, | ||
108 | bytecount)); | ||
109 | /* Start in a slightly future (micro)frame */ | ||
110 | qh->sched_frame = dwc2_frame_num_inc(hsotg->frame_number, | ||
111 | SCHEDULE_SLOP); | ||
112 | qh->interval = urb->interval; | ||
113 | #if 0 | ||
114 | /* Increase interrupt polling rate for debugging */ | ||
115 | if (qh->ep_type == USB_ENDPOINT_XFER_INT) | ||
116 | qh->interval = 8; | ||
117 | #endif | ||
118 | hprt = readl(hsotg->regs + HPRT0); | ||
119 | prtspd = (hprt & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT; | ||
120 | if (prtspd == HPRT0_SPD_HIGH_SPEED && | ||
121 | (dev_speed == USB_SPEED_LOW || | ||
122 | dev_speed == USB_SPEED_FULL)) { | ||
123 | qh->interval *= 8; | ||
124 | qh->sched_frame |= 0x7; | ||
125 | qh->start_split_frame = qh->sched_frame; | ||
126 | } | ||
127 | dev_dbg(hsotg->dev, "interval=%d\n", qh->interval); | ||
128 | } | ||
129 | |||
130 | dev_vdbg(hsotg->dev, "DWC OTG HCD QH Initialized\n"); | ||
131 | dev_vdbg(hsotg->dev, "DWC OTG HCD QH - qh = %p\n", qh); | ||
132 | dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Device Address = %d\n", | ||
133 | dwc2_hcd_get_dev_addr(&urb->pipe_info)); | ||
134 | dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Endpoint %d, %s\n", | ||
135 | dwc2_hcd_get_ep_num(&urb->pipe_info), | ||
136 | dwc2_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"); | ||
137 | |||
138 | qh->dev_speed = dev_speed; | ||
139 | |||
140 | switch (dev_speed) { | ||
141 | case USB_SPEED_LOW: | ||
142 | speed = "low"; | ||
143 | break; | ||
144 | case USB_SPEED_FULL: | ||
145 | speed = "full"; | ||
146 | break; | ||
147 | case USB_SPEED_HIGH: | ||
148 | speed = "high"; | ||
149 | break; | ||
150 | default: | ||
151 | speed = "?"; | ||
152 | break; | ||
153 | } | ||
154 | dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Speed = %s\n", speed); | ||
155 | |||
156 | switch (qh->ep_type) { | ||
157 | case USB_ENDPOINT_XFER_ISOC: | ||
158 | type = "isochronous"; | ||
159 | break; | ||
160 | case USB_ENDPOINT_XFER_INT: | ||
161 | type = "interrupt"; | ||
162 | break; | ||
163 | case USB_ENDPOINT_XFER_CONTROL: | ||
164 | type = "control"; | ||
165 | break; | ||
166 | case USB_ENDPOINT_XFER_BULK: | ||
167 | type = "bulk"; | ||
168 | break; | ||
169 | default: | ||
170 | type = "?"; | ||
171 | break; | ||
172 | } | ||
173 | |||
174 | dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Type = %s\n", type); | ||
175 | |||
176 | if (qh->ep_type == USB_ENDPOINT_XFER_INT) { | ||
177 | dev_vdbg(hsotg->dev, "DWC OTG HCD QH - usecs = %d\n", | ||
178 | qh->usecs); | ||
179 | dev_vdbg(hsotg->dev, "DWC OTG HCD QH - interval = %d\n", | ||
180 | qh->interval); | ||
181 | } | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * dwc2_hcd_qh_create() - Allocates and initializes a QH | ||
186 | * | ||
187 | * @hsotg: The HCD state structure for the DWC OTG controller | ||
188 | * @urb: Holds the information about the device/endpoint needed | ||
189 | * to initialize the QH | ||
190 | * @atomic_alloc: Flag to do atomic allocation if needed | ||
191 | * | ||
192 | * Return: Pointer to the newly allocated QH, or NULL on error | ||
193 | */ | ||
194 | static struct dwc2_qh *dwc2_hcd_qh_create(struct dwc2_hsotg *hsotg, | ||
195 | struct dwc2_hcd_urb *urb, | ||
196 | gfp_t mem_flags) | ||
197 | { | ||
198 | struct dwc2_qh *qh; | ||
199 | |||
200 | if (!urb->priv) | ||
201 | return NULL; | ||
202 | |||
203 | /* Allocate memory */ | ||
204 | qh = kzalloc(sizeof(*qh), mem_flags); | ||
205 | if (!qh) | ||
206 | return NULL; | ||
207 | |||
208 | dwc2_qh_init(hsotg, qh, urb); | ||
209 | |||
210 | if (hsotg->core_params->dma_desc_enable > 0 && | ||
211 | dwc2_hcd_qh_init_ddma(hsotg, qh, mem_flags) < 0) { | ||
212 | dwc2_hcd_qh_free(hsotg, qh); | ||
213 | return NULL; | ||
214 | } | ||
215 | |||
216 | return qh; | ||
217 | } | ||
218 | |||
219 | /** | ||
220 | * dwc2_hcd_qh_free() - Frees the QH | ||
221 | * | ||
222 | * @hsotg: HCD instance | ||
223 | * @qh: The QH to free | ||
224 | * | ||
225 | * QH should already be removed from the list. QTD list should already be empty | ||
226 | * if called from URB Dequeue. | ||
227 | * | ||
228 | * Must NOT be called with interrupt disabled or spinlock held | ||
229 | */ | ||
230 | void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | ||
231 | { | ||
232 | u32 buf_size; | ||
233 | |||
234 | if (hsotg->core_params->dma_desc_enable > 0) { | ||
235 | dwc2_hcd_qh_free_ddma(hsotg, qh); | ||
236 | } else if (qh->dw_align_buf) { | ||
237 | if (qh->ep_type == USB_ENDPOINT_XFER_ISOC) | ||
238 | buf_size = 4096; | ||
239 | else | ||
240 | buf_size = hsotg->core_params->max_transfer_size; | ||
241 | dma_free_coherent(hsotg->dev, buf_size, qh->dw_align_buf, | ||
242 | qh->dw_align_buf_dma); | ||
243 | } | ||
244 | |||
245 | kfree(qh); | ||
246 | } | ||
247 | |||
248 | /** | ||
249 | * dwc2_periodic_channel_available() - Checks that a channel is available for a | ||
250 | * periodic transfer | ||
251 | * | ||
252 | * @hsotg: The HCD state structure for the DWC OTG controller | ||
253 | * | ||
254 | * Return: 0 if successful, negative error code otherwise | ||
255 | */ | ||
256 | static int dwc2_periodic_channel_available(struct dwc2_hsotg *hsotg) | ||
257 | { | ||
258 | /* | ||
259 | * Currently assuming that there is a dedicated host channel for | ||
260 | * each periodic transaction plus at least one host channel for | ||
261 | * non-periodic transactions | ||
262 | */ | ||
263 | int status; | ||
264 | int num_channels; | ||
265 | |||
266 | num_channels = hsotg->core_params->host_channels; | ||
267 | if (hsotg->periodic_channels + hsotg->non_periodic_channels < | ||
268 | num_channels | ||
269 | && hsotg->periodic_channels < num_channels - 1) { | ||
270 | status = 0; | ||
271 | } else { | ||
272 | dev_dbg(hsotg->dev, | ||
273 | "%s: Total channels: %d, Periodic: %d, " | ||
274 | "Non-periodic: %d\n", __func__, num_channels, | ||
275 | hsotg->periodic_channels, hsotg->non_periodic_channels); | ||
276 | status = -ENOSPC; | ||
277 | } | ||
278 | |||
279 | return status; | ||
280 | } | ||
281 | |||
282 | /** | ||
283 | * dwc2_check_periodic_bandwidth() - Checks that there is sufficient bandwidth | ||
284 | * for the specified QH in the periodic schedule | ||
285 | * | ||
286 | * @hsotg: The HCD state structure for the DWC OTG controller | ||
287 | * @qh: QH containing periodic bandwidth required | ||
288 | * | ||
289 | * Return: 0 if successful, negative error code otherwise | ||
290 | * | ||
291 | * For simplicity, this calculation assumes that all the transfers in the | ||
292 | * periodic schedule may occur in the same (micro)frame | ||
293 | */ | ||
294 | static int dwc2_check_periodic_bandwidth(struct dwc2_hsotg *hsotg, | ||
295 | struct dwc2_qh *qh) | ||
296 | { | ||
297 | int status; | ||
298 | s16 max_claimed_usecs; | ||
299 | |||
300 | status = 0; | ||
301 | |||
302 | if (qh->dev_speed == USB_SPEED_HIGH || qh->do_split) { | ||
303 | /* | ||
304 | * High speed mode | ||
305 | * Max periodic usecs is 80% x 125 usec = 100 usec | ||
306 | */ | ||
307 | max_claimed_usecs = 100 - qh->usecs; | ||
308 | } else { | ||
309 | /* | ||
310 | * Full speed mode | ||
311 | * Max periodic usecs is 90% x 1000 usec = 900 usec | ||
312 | */ | ||
313 | max_claimed_usecs = 900 - qh->usecs; | ||
314 | } | ||
315 | |||
316 | if (hsotg->periodic_usecs > max_claimed_usecs) { | ||
317 | dev_err(hsotg->dev, | ||
318 | "%s: already claimed usecs %d, required usecs %d\n", | ||
319 | __func__, hsotg->periodic_usecs, qh->usecs); | ||
320 | status = -ENOSPC; | ||
321 | } | ||
322 | |||
323 | return status; | ||
324 | } | ||
325 | |||
326 | /** | ||
327 | * Microframe scheduler | ||
328 | * track the total use in hsotg->frame_usecs | ||
329 | * keep each qh use in qh->frame_usecs | ||
330 | * when surrendering the qh then donate the time back | ||
331 | */ | ||
332 | static const unsigned short max_uframe_usecs[] = { | ||
333 | 100, 100, 100, 100, 100, 100, 30, 0 | ||
334 | }; | ||
335 | |||
336 | void dwc2_hcd_init_usecs(struct dwc2_hsotg *hsotg) | ||
337 | { | ||
338 | int i; | ||
339 | |||
340 | for (i = 0; i < 8; i++) | ||
341 | hsotg->frame_usecs[i] = max_uframe_usecs[i]; | ||
342 | } | ||
343 | |||
344 | static int dwc2_find_single_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | ||
345 | { | ||
346 | unsigned short utime = qh->usecs; | ||
347 | int i; | ||
348 | |||
349 | for (i = 0; i < 8; i++) { | ||
350 | /* At the start hsotg->frame_usecs[i] = max_uframe_usecs[i] */ | ||
351 | if (utime <= hsotg->frame_usecs[i]) { | ||
352 | hsotg->frame_usecs[i] -= utime; | ||
353 | qh->frame_usecs[i] += utime; | ||
354 | return i; | ||
355 | } | ||
356 | } | ||
357 | return -ENOSPC; | ||
358 | } | ||
359 | |||
360 | /* | ||
361 | * use this for FS apps that can span multiple uframes | ||
362 | */ | ||
363 | static int dwc2_find_multi_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | ||
364 | { | ||
365 | unsigned short utime = qh->usecs; | ||
366 | unsigned short xtime; | ||
367 | int t_left; | ||
368 | int i; | ||
369 | int j; | ||
370 | int k; | ||
371 | |||
372 | for (i = 0; i < 8; i++) { | ||
373 | if (hsotg->frame_usecs[i] <= 0) | ||
374 | continue; | ||
375 | |||
376 | /* | ||
377 | * we need n consecutive slots so use j as a start slot | ||
378 | * j plus j+1 must be enough time (for now) | ||
379 | */ | ||
380 | xtime = hsotg->frame_usecs[i]; | ||
381 | for (j = i + 1; j < 8; j++) { | ||
382 | /* | ||
383 | * if we add this frame remaining time to xtime we may | ||
384 | * be OK, if not we need to test j for a complete frame | ||
385 | */ | ||
386 | if (xtime + hsotg->frame_usecs[j] < utime) { | ||
387 | if (hsotg->frame_usecs[j] < | ||
388 | max_uframe_usecs[j]) | ||
389 | continue; | ||
390 | } | ||
391 | if (xtime >= utime) { | ||
392 | t_left = utime; | ||
393 | for (k = i; k < 8; k++) { | ||
394 | t_left -= hsotg->frame_usecs[k]; | ||
395 | if (t_left <= 0) { | ||
396 | qh->frame_usecs[k] += | ||
397 | hsotg->frame_usecs[k] | ||
398 | + t_left; | ||
399 | hsotg->frame_usecs[k] = -t_left; | ||
400 | return i; | ||
401 | } else { | ||
402 | qh->frame_usecs[k] += | ||
403 | hsotg->frame_usecs[k]; | ||
404 | hsotg->frame_usecs[k] = 0; | ||
405 | } | ||
406 | } | ||
407 | } | ||
408 | /* add the frame time to x time */ | ||
409 | xtime += hsotg->frame_usecs[j]; | ||
410 | /* we must have a fully available next frame or break */ | ||
411 | if (xtime < utime && | ||
412 | hsotg->frame_usecs[j] == max_uframe_usecs[j]) | ||
413 | continue; | ||
414 | } | ||
415 | } | ||
416 | return -ENOSPC; | ||
417 | } | ||
418 | |||
419 | static int dwc2_find_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | ||
420 | { | ||
421 | int ret; | ||
422 | |||
423 | if (qh->dev_speed == USB_SPEED_HIGH) { | ||
424 | /* if this is a hs transaction we need a full frame */ | ||
425 | ret = dwc2_find_single_uframe(hsotg, qh); | ||
426 | } else { | ||
427 | /* | ||
428 | * if this is a fs transaction we may need a sequence | ||
429 | * of frames | ||
430 | */ | ||
431 | ret = dwc2_find_multi_uframe(hsotg, qh); | ||
432 | } | ||
433 | return ret; | ||
434 | } | ||
435 | |||
436 | /** | ||
437 | * dwc2_check_max_xfer_size() - Checks that the max transfer size allowed in a | ||
438 | * host channel is large enough to handle the maximum data transfer in a single | ||
439 | * (micro)frame for a periodic transfer | ||
440 | * | ||
441 | * @hsotg: The HCD state structure for the DWC OTG controller | ||
442 | * @qh: QH for a periodic endpoint | ||
443 | * | ||
444 | * Return: 0 if successful, negative error code otherwise | ||
445 | */ | ||
446 | static int dwc2_check_max_xfer_size(struct dwc2_hsotg *hsotg, | ||
447 | struct dwc2_qh *qh) | ||
448 | { | ||
449 | u32 max_xfer_size; | ||
450 | u32 max_channel_xfer_size; | ||
451 | int status = 0; | ||
452 | |||
453 | max_xfer_size = dwc2_max_packet(qh->maxp) * dwc2_hb_mult(qh->maxp); | ||
454 | max_channel_xfer_size = hsotg->core_params->max_transfer_size; | ||
455 | |||
456 | if (max_xfer_size > max_channel_xfer_size) { | ||
457 | dev_err(hsotg->dev, | ||
458 | "%s: Periodic xfer length %d > max xfer length for channel %d\n", | ||
459 | __func__, max_xfer_size, max_channel_xfer_size); | ||
460 | status = -ENOSPC; | ||
461 | } | ||
462 | |||
463 | return status; | ||
464 | } | ||
465 | |||
466 | /** | ||
467 | * dwc2_schedule_periodic() - Schedules an interrupt or isochronous transfer in | ||
468 | * the periodic schedule | ||
469 | * | ||
470 | * @hsotg: The HCD state structure for the DWC OTG controller | ||
471 | * @qh: QH for the periodic transfer. The QH should already contain the | ||
472 | * scheduling information. | ||
473 | * | ||
474 | * Return: 0 if successful, negative error code otherwise | ||
475 | */ | ||
476 | static int dwc2_schedule_periodic(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | ||
477 | { | ||
478 | int status; | ||
479 | |||
480 | if (hsotg->core_params->uframe_sched > 0) { | ||
481 | int frame = -1; | ||
482 | |||
483 | status = dwc2_find_uframe(hsotg, qh); | ||
484 | if (status == 0) | ||
485 | frame = 7; | ||
486 | else if (status > 0) | ||
487 | frame = status - 1; | ||
488 | |||
489 | /* Set the new frame up */ | ||
490 | if (frame >= 0) { | ||
491 | qh->sched_frame &= ~0x7; | ||
492 | qh->sched_frame |= (frame & 7); | ||
493 | } | ||
494 | |||
495 | if (status > 0) | ||
496 | status = 0; | ||
497 | } else { | ||
498 | status = dwc2_periodic_channel_available(hsotg); | ||
499 | if (status) { | ||
500 | dev_info(hsotg->dev, | ||
501 | "%s: No host channel available for periodic transfer\n", | ||
502 | __func__); | ||
503 | return status; | ||
504 | } | ||
505 | |||
506 | status = dwc2_check_periodic_bandwidth(hsotg, qh); | ||
507 | } | ||
508 | |||
509 | if (status) { | ||
510 | dev_dbg(hsotg->dev, | ||
511 | "%s: Insufficient periodic bandwidth for periodic transfer\n", | ||
512 | __func__); | ||
513 | return status; | ||
514 | } | ||
515 | |||
516 | status = dwc2_check_max_xfer_size(hsotg, qh); | ||
517 | if (status) { | ||
518 | dev_dbg(hsotg->dev, | ||
519 | "%s: Channel max transfer size too small for periodic transfer\n", | ||
520 | __func__); | ||
521 | return status; | ||
522 | } | ||
523 | |||
524 | if (hsotg->core_params->dma_desc_enable > 0) | ||
525 | /* Don't rely on SOF and start in ready schedule */ | ||
526 | list_add_tail(&qh->qh_list_entry, &hsotg->periodic_sched_ready); | ||
527 | else | ||
528 | /* Always start in inactive schedule */ | ||
529 | list_add_tail(&qh->qh_list_entry, | ||
530 | &hsotg->periodic_sched_inactive); | ||
531 | |||
532 | if (hsotg->core_params->uframe_sched <= 0) | ||
533 | /* Reserve periodic channel */ | ||
534 | hsotg->periodic_channels++; | ||
535 | |||
536 | /* Update claimed usecs per (micro)frame */ | ||
537 | hsotg->periodic_usecs += qh->usecs; | ||
538 | |||
539 | return status; | ||
540 | } | ||
541 | |||
542 | /** | ||
543 | * dwc2_deschedule_periodic() - Removes an interrupt or isochronous transfer | ||
544 | * from the periodic schedule | ||
545 | * | ||
546 | * @hsotg: The HCD state structure for the DWC OTG controller | ||
547 | * @qh: QH for the periodic transfer | ||
548 | */ | ||
549 | static void dwc2_deschedule_periodic(struct dwc2_hsotg *hsotg, | ||
550 | struct dwc2_qh *qh) | ||
551 | { | ||
552 | int i; | ||
553 | |||
554 | list_del_init(&qh->qh_list_entry); | ||
555 | |||
556 | /* Update claimed usecs per (micro)frame */ | ||
557 | hsotg->periodic_usecs -= qh->usecs; | ||
558 | |||
559 | if (hsotg->core_params->uframe_sched > 0) { | ||
560 | for (i = 0; i < 8; i++) { | ||
561 | hsotg->frame_usecs[i] += qh->frame_usecs[i]; | ||
562 | qh->frame_usecs[i] = 0; | ||
563 | } | ||
564 | } else { | ||
565 | /* Release periodic channel reservation */ | ||
566 | hsotg->periodic_channels--; | ||
567 | } | ||
568 | } | ||
569 | |||
570 | /** | ||
571 | * dwc2_hcd_qh_add() - Adds a QH to either the non periodic or periodic | ||
572 | * schedule if it is not already in the schedule. If the QH is already in | ||
573 | * the schedule, no action is taken. | ||
574 | * | ||
575 | * @hsotg: The HCD state structure for the DWC OTG controller | ||
576 | * @qh: The QH to add | ||
577 | * | ||
578 | * Return: 0 if successful, negative error code otherwise | ||
579 | */ | ||
580 | int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | ||
581 | { | ||
582 | int status; | ||
583 | u32 intr_mask; | ||
584 | |||
585 | if (dbg_qh(qh)) | ||
586 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
587 | |||
588 | if (!list_empty(&qh->qh_list_entry)) | ||
589 | /* QH already in a schedule */ | ||
590 | return 0; | ||
591 | |||
592 | /* Add the new QH to the appropriate schedule */ | ||
593 | if (dwc2_qh_is_non_per(qh)) { | ||
594 | /* Always start in inactive schedule */ | ||
595 | list_add_tail(&qh->qh_list_entry, | ||
596 | &hsotg->non_periodic_sched_inactive); | ||
597 | return 0; | ||
598 | } | ||
599 | |||
600 | status = dwc2_schedule_periodic(hsotg, qh); | ||
601 | if (status) | ||
602 | return status; | ||
603 | if (!hsotg->periodic_qh_count) { | ||
604 | intr_mask = readl(hsotg->regs + GINTMSK); | ||
605 | intr_mask |= GINTSTS_SOF; | ||
606 | writel(intr_mask, hsotg->regs + GINTMSK); | ||
607 | } | ||
608 | hsotg->periodic_qh_count++; | ||
609 | |||
610 | return 0; | ||
611 | } | ||
612 | |||
613 | /** | ||
614 | * dwc2_hcd_qh_unlink() - Removes a QH from either the non-periodic or periodic | ||
615 | * schedule. Memory is not freed. | ||
616 | * | ||
617 | * @hsotg: The HCD state structure | ||
618 | * @qh: QH to remove from schedule | ||
619 | */ | ||
620 | void dwc2_hcd_qh_unlink(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | ||
621 | { | ||
622 | u32 intr_mask; | ||
623 | |||
624 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
625 | |||
626 | if (list_empty(&qh->qh_list_entry)) | ||
627 | /* QH is not in a schedule */ | ||
628 | return; | ||
629 | |||
630 | if (dwc2_qh_is_non_per(qh)) { | ||
631 | if (hsotg->non_periodic_qh_ptr == &qh->qh_list_entry) | ||
632 | hsotg->non_periodic_qh_ptr = | ||
633 | hsotg->non_periodic_qh_ptr->next; | ||
634 | list_del_init(&qh->qh_list_entry); | ||
635 | return; | ||
636 | } | ||
637 | |||
638 | dwc2_deschedule_periodic(hsotg, qh); | ||
639 | hsotg->periodic_qh_count--; | ||
640 | if (!hsotg->periodic_qh_count) { | ||
641 | intr_mask = readl(hsotg->regs + GINTMSK); | ||
642 | intr_mask &= ~GINTSTS_SOF; | ||
643 | writel(intr_mask, hsotg->regs + GINTMSK); | ||
644 | } | ||
645 | } | ||
646 | |||
647 | /* | ||
648 | * Schedule the next continuing periodic split transfer | ||
649 | */ | ||
650 | static void dwc2_sched_periodic_split(struct dwc2_hsotg *hsotg, | ||
651 | struct dwc2_qh *qh, u16 frame_number, | ||
652 | int sched_next_periodic_split) | ||
653 | { | ||
654 | u16 incr; | ||
655 | |||
656 | if (sched_next_periodic_split) { | ||
657 | qh->sched_frame = frame_number; | ||
658 | incr = dwc2_frame_num_inc(qh->start_split_frame, 1); | ||
659 | if (dwc2_frame_num_le(frame_number, incr)) { | ||
660 | /* | ||
661 | * Allow one frame to elapse after start split | ||
662 | * microframe before scheduling complete split, but | ||
663 | * DON'T if we are doing the next start split in the | ||
664 | * same frame for an ISOC out | ||
665 | */ | ||
666 | if (qh->ep_type != USB_ENDPOINT_XFER_ISOC || | ||
667 | qh->ep_is_in != 0) { | ||
668 | qh->sched_frame = | ||
669 | dwc2_frame_num_inc(qh->sched_frame, 1); | ||
670 | } | ||
671 | } | ||
672 | } else { | ||
673 | qh->sched_frame = dwc2_frame_num_inc(qh->start_split_frame, | ||
674 | qh->interval); | ||
675 | if (dwc2_frame_num_le(qh->sched_frame, frame_number)) | ||
676 | qh->sched_frame = frame_number; | ||
677 | qh->sched_frame |= 0x7; | ||
678 | qh->start_split_frame = qh->sched_frame; | ||
679 | } | ||
680 | } | ||
681 | |||
682 | /* | ||
683 | * Deactivates a QH. For non-periodic QHs, removes the QH from the active | ||
684 | * non-periodic schedule. The QH is added to the inactive non-periodic | ||
685 | * schedule if any QTDs are still attached to the QH. | ||
686 | * | ||
687 | * For periodic QHs, the QH is removed from the periodic queued schedule. If | ||
688 | * there are any QTDs still attached to the QH, the QH is added to either the | ||
689 | * periodic inactive schedule or the periodic ready schedule and its next | ||
690 | * scheduled frame is calculated. The QH is placed in the ready schedule if | ||
691 | * the scheduled frame has been reached already. Otherwise it's placed in the | ||
692 | * inactive schedule. If there are no QTDs attached to the QH, the QH is | ||
693 | * completely removed from the periodic schedule. | ||
694 | */ | ||
695 | void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, | ||
696 | int sched_next_periodic_split) | ||
697 | { | ||
698 | u16 frame_number; | ||
699 | |||
700 | if (dbg_qh(qh)) | ||
701 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | ||
702 | |||
703 | if (dwc2_qh_is_non_per(qh)) { | ||
704 | dwc2_hcd_qh_unlink(hsotg, qh); | ||
705 | if (!list_empty(&qh->qtd_list)) | ||
706 | /* Add back to inactive non-periodic schedule */ | ||
707 | dwc2_hcd_qh_add(hsotg, qh); | ||
708 | return; | ||
709 | } | ||
710 | |||
711 | frame_number = dwc2_hcd_get_frame_number(hsotg); | ||
712 | |||
713 | if (qh->do_split) { | ||
714 | dwc2_sched_periodic_split(hsotg, qh, frame_number, | ||
715 | sched_next_periodic_split); | ||
716 | } else { | ||
717 | qh->sched_frame = dwc2_frame_num_inc(qh->sched_frame, | ||
718 | qh->interval); | ||
719 | if (dwc2_frame_num_le(qh->sched_frame, frame_number)) | ||
720 | qh->sched_frame = frame_number; | ||
721 | } | ||
722 | |||
723 | if (list_empty(&qh->qtd_list)) { | ||
724 | dwc2_hcd_qh_unlink(hsotg, qh); | ||
725 | return; | ||
726 | } | ||
727 | /* | ||
728 | * Remove from periodic_sched_queued and move to | ||
729 | * appropriate queue | ||
730 | */ | ||
731 | if ((hsotg->core_params->uframe_sched > 0 && | ||
732 | dwc2_frame_num_le(qh->sched_frame, frame_number)) || | ||
733 | (hsotg->core_params->uframe_sched <= 0 && | ||
734 | qh->sched_frame == frame_number)) | ||
735 | list_move(&qh->qh_list_entry, &hsotg->periodic_sched_ready); | ||
736 | else | ||
737 | list_move(&qh->qh_list_entry, &hsotg->periodic_sched_inactive); | ||
738 | } | ||
739 | |||
740 | /** | ||
741 | * dwc2_hcd_qtd_init() - Initializes a QTD structure | ||
742 | * | ||
743 | * @qtd: The QTD to initialize | ||
744 | * @urb: The associated URB | ||
745 | */ | ||
746 | void dwc2_hcd_qtd_init(struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb) | ||
747 | { | ||
748 | qtd->urb = urb; | ||
749 | if (dwc2_hcd_get_pipe_type(&urb->pipe_info) == | ||
750 | USB_ENDPOINT_XFER_CONTROL) { | ||
751 | /* | ||
752 | * The only time the QTD data toggle is used is on the data | ||
753 | * phase of control transfers. This phase always starts with | ||
754 | * DATA1. | ||
755 | */ | ||
756 | qtd->data_toggle = DWC2_HC_PID_DATA1; | ||
757 | qtd->control_phase = DWC2_CONTROL_SETUP; | ||
758 | } | ||
759 | |||
760 | /* Start split */ | ||
761 | qtd->complete_split = 0; | ||
762 | qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL; | ||
763 | qtd->isoc_split_offset = 0; | ||
764 | qtd->in_process = 0; | ||
765 | |||
766 | /* Store the qtd ptr in the urb to reference the QTD */ | ||
767 | urb->qtd = qtd; | ||
768 | } | ||
769 | |||
770 | /** | ||
771 | * dwc2_hcd_qtd_add() - Adds a QTD to the QTD-list of a QH | ||
772 | * | ||
773 | * @hsotg: The DWC HCD structure | ||
774 | * @qtd: The QTD to add | ||
775 | * @qh: Out parameter to return queue head | ||
776 | * @atomic_alloc: Flag to do atomic alloc if needed | ||
777 | * | ||
778 | * Return: 0 if successful, negative error code otherwise | ||
779 | * | ||
780 | * Finds the correct QH to place the QTD into. If it does not find a QH, it | ||
781 | * will create a new QH. If the QH to which the QTD is added is not currently | ||
782 | * scheduled, it is placed into the proper schedule based on its EP type. | ||
783 | */ | ||
784 | int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, | ||
785 | struct dwc2_qh **qh, gfp_t mem_flags) | ||
786 | { | ||
787 | struct dwc2_hcd_urb *urb = qtd->urb; | ||
788 | unsigned long flags; | ||
789 | int allocated = 0; | ||
790 | int retval; | ||
791 | |||
792 | /* | ||
793 | * Get the QH which holds the QTD-list to insert to. Create QH if it | ||
794 | * doesn't exist. | ||
795 | */ | ||
796 | if (*qh == NULL) { | ||
797 | *qh = dwc2_hcd_qh_create(hsotg, urb, mem_flags); | ||
798 | if (*qh == NULL) | ||
799 | return -ENOMEM; | ||
800 | allocated = 1; | ||
801 | } | ||
802 | |||
803 | spin_lock_irqsave(&hsotg->lock, flags); | ||
804 | |||
805 | retval = dwc2_hcd_qh_add(hsotg, *qh); | ||
806 | if (retval) | ||
807 | goto fail; | ||
808 | |||
809 | qtd->qh = *qh; | ||
810 | list_add_tail(&qtd->qtd_list_entry, &(*qh)->qtd_list); | ||
811 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
812 | |||
813 | return 0; | ||
814 | |||
815 | fail: | ||
816 | if (allocated) { | ||
817 | struct dwc2_qtd *qtd2, *qtd2_tmp; | ||
818 | struct dwc2_qh *qh_tmp = *qh; | ||
819 | |||
820 | *qh = NULL; | ||
821 | dwc2_hcd_qh_unlink(hsotg, qh_tmp); | ||
822 | |||
823 | /* Free each QTD in the QH's QTD list */ | ||
824 | list_for_each_entry_safe(qtd2, qtd2_tmp, &qh_tmp->qtd_list, | ||
825 | qtd_list_entry) | ||
826 | dwc2_hcd_qtd_unlink_and_free(hsotg, qtd2, qh_tmp); | ||
827 | |||
828 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
829 | dwc2_hcd_qh_free(hsotg, qh_tmp); | ||
830 | } else { | ||
831 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
832 | } | ||
833 | |||
834 | return retval; | ||
835 | } | ||
diff --git a/drivers/usb/dwc2/hw.h b/drivers/usb/dwc2/hw.h new file mode 100644 index 000000000000..9c92a3c7588a --- /dev/null +++ b/drivers/usb/dwc2/hw.h | |||
@@ -0,0 +1,809 @@ | |||
1 | /* | ||
2 | * hw.h - DesignWare HS OTG Controller hardware definitions | ||
3 | * | ||
4 | * Copyright 2004-2013 Synopsys, Inc. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions, and the following disclaimer, | ||
11 | * without modification. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The names of the above-listed copyright holders may not be used | ||
16 | * to endorse or promote products derived from this software without | ||
17 | * specific prior written permission. | ||
18 | * | ||
19 | * ALTERNATIVELY, this software may be distributed under the terms of the | ||
20 | * GNU General Public License ("GPL") as published by the Free Software | ||
21 | * Foundation; either version 2 of the License, or (at your option) any | ||
22 | * later version. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
26 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
35 | */ | ||
36 | |||
37 | #ifndef __DWC2_HW_H__ | ||
38 | #define __DWC2_HW_H__ | ||
39 | |||
40 | #define HSOTG_REG(x) (x) | ||
41 | |||
42 | #define GOTGCTL HSOTG_REG(0x000) | ||
43 | #define GOTGCTL_CHIRPEN (1 << 27) | ||
44 | #define GOTGCTL_MULT_VALID_BC_MASK (0x1f << 22) | ||
45 | #define GOTGCTL_MULT_VALID_BC_SHIFT 22 | ||
46 | #define GOTGCTL_OTGVER (1 << 20) | ||
47 | #define GOTGCTL_BSESVLD (1 << 19) | ||
48 | #define GOTGCTL_ASESVLD (1 << 18) | ||
49 | #define GOTGCTL_DBNC_SHORT (1 << 17) | ||
50 | #define GOTGCTL_CONID_B (1 << 16) | ||
51 | #define GOTGCTL_DEVHNPEN (1 << 11) | ||
52 | #define GOTGCTL_HSTSETHNPEN (1 << 10) | ||
53 | #define GOTGCTL_HNPREQ (1 << 9) | ||
54 | #define GOTGCTL_HSTNEGSCS (1 << 8) | ||
55 | #define GOTGCTL_SESREQ (1 << 1) | ||
56 | #define GOTGCTL_SESREQSCS (1 << 0) | ||
57 | |||
58 | #define GOTGINT HSOTG_REG(0x004) | ||
59 | #define GOTGINT_DBNCE_DONE (1 << 19) | ||
60 | #define GOTGINT_A_DEV_TOUT_CHG (1 << 18) | ||
61 | #define GOTGINT_HST_NEG_DET (1 << 17) | ||
62 | #define GOTGINT_HST_NEG_SUC_STS_CHNG (1 << 9) | ||
63 | #define GOTGINT_SES_REQ_SUC_STS_CHNG (1 << 8) | ||
64 | #define GOTGINT_SES_END_DET (1 << 2) | ||
65 | |||
66 | #define GAHBCFG HSOTG_REG(0x008) | ||
67 | #define GAHBCFG_AHB_SINGLE (1 << 23) | ||
68 | #define GAHBCFG_NOTI_ALL_DMA_WRIT (1 << 22) | ||
69 | #define GAHBCFG_REM_MEM_SUPP (1 << 21) | ||
70 | #define GAHBCFG_P_TXF_EMP_LVL (1 << 8) | ||
71 | #define GAHBCFG_NP_TXF_EMP_LVL (1 << 7) | ||
72 | #define GAHBCFG_DMA_EN (1 << 5) | ||
73 | #define GAHBCFG_HBSTLEN_MASK (0xf << 1) | ||
74 | #define GAHBCFG_HBSTLEN_SHIFT 1 | ||
75 | #define GAHBCFG_HBSTLEN_SINGLE 0 | ||
76 | #define GAHBCFG_HBSTLEN_INCR 1 | ||
77 | #define GAHBCFG_HBSTLEN_INCR4 3 | ||
78 | #define GAHBCFG_HBSTLEN_INCR8 5 | ||
79 | #define GAHBCFG_HBSTLEN_INCR16 7 | ||
80 | #define GAHBCFG_GLBL_INTR_EN (1 << 0) | ||
81 | #define GAHBCFG_CTRL_MASK (GAHBCFG_P_TXF_EMP_LVL | \ | ||
82 | GAHBCFG_NP_TXF_EMP_LVL | \ | ||
83 | GAHBCFG_DMA_EN | \ | ||
84 | GAHBCFG_GLBL_INTR_EN) | ||
85 | |||
86 | #define GUSBCFG HSOTG_REG(0x00C) | ||
87 | #define GUSBCFG_FORCEDEVMODE (1 << 30) | ||
88 | #define GUSBCFG_FORCEHOSTMODE (1 << 29) | ||
89 | #define GUSBCFG_TXENDDELAY (1 << 28) | ||
90 | #define GUSBCFG_ICTRAFFICPULLREMOVE (1 << 27) | ||
91 | #define GUSBCFG_ICUSBCAP (1 << 26) | ||
92 | #define GUSBCFG_ULPI_INT_PROT_DIS (1 << 25) | ||
93 | #define GUSBCFG_INDICATORPASSTHROUGH (1 << 24) | ||
94 | #define GUSBCFG_INDICATORCOMPLEMENT (1 << 23) | ||
95 | #define GUSBCFG_TERMSELDLPULSE (1 << 22) | ||
96 | #define GUSBCFG_ULPI_INT_VBUS_IND (1 << 21) | ||
97 | #define GUSBCFG_ULPI_EXT_VBUS_DRV (1 << 20) | ||
98 | #define GUSBCFG_ULPI_CLK_SUSP_M (1 << 19) | ||
99 | #define GUSBCFG_ULPI_AUTO_RES (1 << 18) | ||
100 | #define GUSBCFG_ULPI_FS_LS (1 << 17) | ||
101 | #define GUSBCFG_OTG_UTMI_FS_SEL (1 << 16) | ||
102 | #define GUSBCFG_PHY_LP_CLK_SEL (1 << 15) | ||
103 | #define GUSBCFG_USBTRDTIM_MASK (0xf << 10) | ||
104 | #define GUSBCFG_USBTRDTIM_SHIFT 10 | ||
105 | #define GUSBCFG_HNPCAP (1 << 9) | ||
106 | #define GUSBCFG_SRPCAP (1 << 8) | ||
107 | #define GUSBCFG_DDRSEL (1 << 7) | ||
108 | #define GUSBCFG_PHYSEL (1 << 6) | ||
109 | #define GUSBCFG_FSINTF (1 << 5) | ||
110 | #define GUSBCFG_ULPI_UTMI_SEL (1 << 4) | ||
111 | #define GUSBCFG_PHYIF16 (1 << 3) | ||
112 | #define GUSBCFG_TOUTCAL_MASK (0x7 << 0) | ||
113 | #define GUSBCFG_TOUTCAL_SHIFT 0 | ||
114 | #define GUSBCFG_TOUTCAL_LIMIT 0x7 | ||
115 | #define GUSBCFG_TOUTCAL(_x) ((_x) << 0) | ||
116 | |||
117 | #define GRSTCTL HSOTG_REG(0x010) | ||
118 | #define GRSTCTL_AHBIDLE (1 << 31) | ||
119 | #define GRSTCTL_DMAREQ (1 << 30) | ||
120 | #define GRSTCTL_TXFNUM_MASK (0x1f << 6) | ||
121 | #define GRSTCTL_TXFNUM_SHIFT 6 | ||
122 | #define GRSTCTL_TXFNUM_LIMIT 0x1f | ||
123 | #define GRSTCTL_TXFNUM(_x) ((_x) << 6) | ||
124 | #define GRSTCTL_TXFFLSH (1 << 5) | ||
125 | #define GRSTCTL_RXFFLSH (1 << 4) | ||
126 | #define GRSTCTL_IN_TKNQ_FLSH (1 << 3) | ||
127 | #define GRSTCTL_FRMCNTRRST (1 << 2) | ||
128 | #define GRSTCTL_HSFTRST (1 << 1) | ||
129 | #define GRSTCTL_CSFTRST (1 << 0) | ||
130 | |||
131 | #define GINTSTS HSOTG_REG(0x014) | ||
132 | #define GINTMSK HSOTG_REG(0x018) | ||
133 | #define GINTSTS_WKUPINT (1 << 31) | ||
134 | #define GINTSTS_SESSREQINT (1 << 30) | ||
135 | #define GINTSTS_DISCONNINT (1 << 29) | ||
136 | #define GINTSTS_CONIDSTSCHNG (1 << 28) | ||
137 | #define GINTSTS_LPMTRANRCVD (1 << 27) | ||
138 | #define GINTSTS_PTXFEMP (1 << 26) | ||
139 | #define GINTSTS_HCHINT (1 << 25) | ||
140 | #define GINTSTS_PRTINT (1 << 24) | ||
141 | #define GINTSTS_RESETDET (1 << 23) | ||
142 | #define GINTSTS_FET_SUSP (1 << 22) | ||
143 | #define GINTSTS_INCOMPL_IP (1 << 21) | ||
144 | #define GINTSTS_INCOMPL_SOIN (1 << 20) | ||
145 | #define GINTSTS_OEPINT (1 << 19) | ||
146 | #define GINTSTS_IEPINT (1 << 18) | ||
147 | #define GINTSTS_EPMIS (1 << 17) | ||
148 | #define GINTSTS_RESTOREDONE (1 << 16) | ||
149 | #define GINTSTS_EOPF (1 << 15) | ||
150 | #define GINTSTS_ISOUTDROP (1 << 14) | ||
151 | #define GINTSTS_ENUMDONE (1 << 13) | ||
152 | #define GINTSTS_USBRST (1 << 12) | ||
153 | #define GINTSTS_USBSUSP (1 << 11) | ||
154 | #define GINTSTS_ERLYSUSP (1 << 10) | ||
155 | #define GINTSTS_I2CINT (1 << 9) | ||
156 | #define GINTSTS_ULPI_CK_INT (1 << 8) | ||
157 | #define GINTSTS_GOUTNAKEFF (1 << 7) | ||
158 | #define GINTSTS_GINNAKEFF (1 << 6) | ||
159 | #define GINTSTS_NPTXFEMP (1 << 5) | ||
160 | #define GINTSTS_RXFLVL (1 << 4) | ||
161 | #define GINTSTS_SOF (1 << 3) | ||
162 | #define GINTSTS_OTGINT (1 << 2) | ||
163 | #define GINTSTS_MODEMIS (1 << 1) | ||
164 | #define GINTSTS_CURMODE_HOST (1 << 0) | ||
165 | |||
166 | #define GRXSTSR HSOTG_REG(0x01C) | ||
167 | #define GRXSTSP HSOTG_REG(0x020) | ||
168 | #define GRXSTS_FN_MASK (0x7f << 25) | ||
169 | #define GRXSTS_FN_SHIFT 25 | ||
170 | #define GRXSTS_PKTSTS_MASK (0xf << 17) | ||
171 | #define GRXSTS_PKTSTS_SHIFT 17 | ||
172 | #define GRXSTS_PKTSTS_GLOBALOUTNAK 1 | ||
173 | #define GRXSTS_PKTSTS_OUTRX 2 | ||
174 | #define GRXSTS_PKTSTS_HCHIN 2 | ||
175 | #define GRXSTS_PKTSTS_OUTDONE 3 | ||
176 | #define GRXSTS_PKTSTS_HCHIN_XFER_COMP 3 | ||
177 | #define GRXSTS_PKTSTS_SETUPDONE 4 | ||
178 | #define GRXSTS_PKTSTS_DATATOGGLEERR 5 | ||
179 | #define GRXSTS_PKTSTS_SETUPRX 6 | ||
180 | #define GRXSTS_PKTSTS_HCHHALTED 7 | ||
181 | #define GRXSTS_HCHNUM_MASK (0xf << 0) | ||
182 | #define GRXSTS_HCHNUM_SHIFT 0 | ||
183 | #define GRXSTS_DPID_MASK (0x3 << 15) | ||
184 | #define GRXSTS_DPID_SHIFT 15 | ||
185 | #define GRXSTS_BYTECNT_MASK (0x7ff << 4) | ||
186 | #define GRXSTS_BYTECNT_SHIFT 4 | ||
187 | #define GRXSTS_EPNUM_MASK (0xf << 0) | ||
188 | #define GRXSTS_EPNUM_SHIFT 0 | ||
189 | |||
190 | #define GRXFSIZ HSOTG_REG(0x024) | ||
191 | #define GRXFSIZ_DEPTH_MASK (0xffff << 0) | ||
192 | #define GRXFSIZ_DEPTH_SHIFT 0 | ||
193 | |||
194 | #define GNPTXFSIZ HSOTG_REG(0x028) | ||
195 | /* Use FIFOSIZE_* constants to access this register */ | ||
196 | |||
197 | #define GNPTXSTS HSOTG_REG(0x02C) | ||
198 | #define GNPTXSTS_NP_TXQ_TOP_MASK (0x7f << 24) | ||
199 | #define GNPTXSTS_NP_TXQ_TOP_SHIFT 24 | ||
200 | #define GNPTXSTS_NP_TXQ_SPC_AVAIL_MASK (0xff << 16) | ||
201 | #define GNPTXSTS_NP_TXQ_SPC_AVAIL_SHIFT 16 | ||
202 | #define GNPTXSTS_NP_TXQ_SPC_AVAIL_GET(_v) (((_v) >> 16) & 0xff) | ||
203 | #define GNPTXSTS_NP_TXF_SPC_AVAIL_MASK (0xffff << 0) | ||
204 | #define GNPTXSTS_NP_TXF_SPC_AVAIL_SHIFT 0 | ||
205 | #define GNPTXSTS_NP_TXF_SPC_AVAIL_GET(_v) (((_v) >> 0) & 0xffff) | ||
206 | |||
207 | #define GI2CCTL HSOTG_REG(0x0030) | ||
208 | #define GI2CCTL_BSYDNE (1 << 31) | ||
209 | #define GI2CCTL_RW (1 << 30) | ||
210 | #define GI2CCTL_I2CDATSE0 (1 << 28) | ||
211 | #define GI2CCTL_I2CDEVADDR_MASK (0x3 << 26) | ||
212 | #define GI2CCTL_I2CDEVADDR_SHIFT 26 | ||
213 | #define GI2CCTL_I2CSUSPCTL (1 << 25) | ||
214 | #define GI2CCTL_ACK (1 << 24) | ||
215 | #define GI2CCTL_I2CEN (1 << 23) | ||
216 | #define GI2CCTL_ADDR_MASK (0x7f << 16) | ||
217 | #define GI2CCTL_ADDR_SHIFT 16 | ||
218 | #define GI2CCTL_REGADDR_MASK (0xff << 8) | ||
219 | #define GI2CCTL_REGADDR_SHIFT 8 | ||
220 | #define GI2CCTL_RWDATA_MASK (0xff << 0) | ||
221 | #define GI2CCTL_RWDATA_SHIFT 0 | ||
222 | |||
223 | #define GPVNDCTL HSOTG_REG(0x0034) | ||
224 | #define GGPIO HSOTG_REG(0x0038) | ||
225 | #define GUID HSOTG_REG(0x003c) | ||
226 | #define GSNPSID HSOTG_REG(0x0040) | ||
227 | #define GHWCFG1 HSOTG_REG(0x0044) | ||
228 | |||
229 | #define GHWCFG2 HSOTG_REG(0x0048) | ||
230 | #define GHWCFG2_OTG_ENABLE_IC_USB (1 << 31) | ||
231 | #define GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK (0x1f << 26) | ||
232 | #define GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT 26 | ||
233 | #define GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK (0x3 << 24) | ||
234 | #define GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT 24 | ||
235 | #define GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK (0x3 << 22) | ||
236 | #define GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT 22 | ||
237 | #define GHWCFG2_MULTI_PROC_INT (1 << 20) | ||
238 | #define GHWCFG2_DYNAMIC_FIFO (1 << 19) | ||
239 | #define GHWCFG2_PERIO_EP_SUPPORTED (1 << 18) | ||
240 | #define GHWCFG2_NUM_HOST_CHAN_MASK (0xf << 14) | ||
241 | #define GHWCFG2_NUM_HOST_CHAN_SHIFT 14 | ||
242 | #define GHWCFG2_NUM_DEV_EP_MASK (0xf << 10) | ||
243 | #define GHWCFG2_NUM_DEV_EP_SHIFT 10 | ||
244 | #define GHWCFG2_FS_PHY_TYPE_MASK (0x3 << 8) | ||
245 | #define GHWCFG2_FS_PHY_TYPE_SHIFT 8 | ||
246 | #define GHWCFG2_FS_PHY_TYPE_NOT_SUPPORTED 0 | ||
247 | #define GHWCFG2_FS_PHY_TYPE_DEDICATED 1 | ||
248 | #define GHWCFG2_FS_PHY_TYPE_SHARED_UTMI 2 | ||
249 | #define GHWCFG2_FS_PHY_TYPE_SHARED_ULPI 3 | ||
250 | #define GHWCFG2_HS_PHY_TYPE_MASK (0x3 << 6) | ||
251 | #define GHWCFG2_HS_PHY_TYPE_SHIFT 6 | ||
252 | #define GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0 | ||
253 | #define GHWCFG2_HS_PHY_TYPE_UTMI 1 | ||
254 | #define GHWCFG2_HS_PHY_TYPE_ULPI 2 | ||
255 | #define GHWCFG2_HS_PHY_TYPE_UTMI_ULPI 3 | ||
256 | #define GHWCFG2_POINT2POINT (1 << 5) | ||
257 | #define GHWCFG2_ARCHITECTURE_MASK (0x3 << 3) | ||
258 | #define GHWCFG2_ARCHITECTURE_SHIFT 3 | ||
259 | #define GHWCFG2_SLAVE_ONLY_ARCH 0 | ||
260 | #define GHWCFG2_EXT_DMA_ARCH 1 | ||
261 | #define GHWCFG2_INT_DMA_ARCH 2 | ||
262 | #define GHWCFG2_OP_MODE_MASK (0x7 << 0) | ||
263 | #define GHWCFG2_OP_MODE_SHIFT 0 | ||
264 | #define GHWCFG2_OP_MODE_HNP_SRP_CAPABLE 0 | ||
265 | #define GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE 1 | ||
266 | #define GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE 2 | ||
267 | #define GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3 | ||
268 | #define GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4 | ||
269 | #define GHWCFG2_OP_MODE_SRP_CAPABLE_HOST 5 | ||
270 | #define GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6 | ||
271 | #define GHWCFG2_OP_MODE_UNDEFINED 7 | ||
272 | |||
273 | #define GHWCFG3 HSOTG_REG(0x004c) | ||
274 | #define GHWCFG3_DFIFO_DEPTH_MASK (0xffff << 16) | ||
275 | #define GHWCFG3_DFIFO_DEPTH_SHIFT 16 | ||
276 | #define GHWCFG3_OTG_LPM_EN (1 << 15) | ||
277 | #define GHWCFG3_BC_SUPPORT (1 << 14) | ||
278 | #define GHWCFG3_OTG_ENABLE_HSIC (1 << 13) | ||
279 | #define GHWCFG3_ADP_SUPP (1 << 12) | ||
280 | #define GHWCFG3_SYNCH_RESET_TYPE (1 << 11) | ||
281 | #define GHWCFG3_OPTIONAL_FEATURES (1 << 10) | ||
282 | #define GHWCFG3_VENDOR_CTRL_IF (1 << 9) | ||
283 | #define GHWCFG3_I2C (1 << 8) | ||
284 | #define GHWCFG3_OTG_FUNC (1 << 7) | ||
285 | #define GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK (0x7 << 4) | ||
286 | #define GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT 4 | ||
287 | #define GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK (0xf << 0) | ||
288 | #define GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT 0 | ||
289 | |||
290 | #define GHWCFG4 HSOTG_REG(0x0050) | ||
291 | #define GHWCFG4_DESC_DMA_DYN (1 << 31) | ||
292 | #define GHWCFG4_DESC_DMA (1 << 30) | ||
293 | #define GHWCFG4_NUM_IN_EPS_MASK (0xf << 26) | ||
294 | #define GHWCFG4_NUM_IN_EPS_SHIFT 26 | ||
295 | #define GHWCFG4_DED_FIFO_EN (1 << 25) | ||
296 | #define GHWCFG4_SESSION_END_FILT_EN (1 << 24) | ||
297 | #define GHWCFG4_B_VALID_FILT_EN (1 << 23) | ||
298 | #define GHWCFG4_A_VALID_FILT_EN (1 << 22) | ||
299 | #define GHWCFG4_VBUS_VALID_FILT_EN (1 << 21) | ||
300 | #define GHWCFG4_IDDIG_FILT_EN (1 << 20) | ||
301 | #define GHWCFG4_NUM_DEV_MODE_CTRL_EP_MASK (0xf << 16) | ||
302 | #define GHWCFG4_NUM_DEV_MODE_CTRL_EP_SHIFT 16 | ||
303 | #define GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK (0x3 << 14) | ||
304 | #define GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT 14 | ||
305 | #define GHWCFG4_UTMI_PHY_DATA_WIDTH_8 0 | ||
306 | #define GHWCFG4_UTMI_PHY_DATA_WIDTH_16 1 | ||
307 | #define GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16 2 | ||
308 | #define GHWCFG4_XHIBER (1 << 7) | ||
309 | #define GHWCFG4_HIBER (1 << 6) | ||
310 | #define GHWCFG4_MIN_AHB_FREQ (1 << 5) | ||
311 | #define GHWCFG4_POWER_OPTIMIZ (1 << 4) | ||
312 | #define GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK (0xf << 0) | ||
313 | #define GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT 0 | ||
314 | |||
315 | #define GLPMCFG HSOTG_REG(0x0054) | ||
316 | #define GLPMCFG_INV_SEL_HSIC (1 << 31) | ||
317 | #define GLPMCFG_HSIC_CONNECT (1 << 30) | ||
318 | #define GLPMCFG_RETRY_COUNT_STS_MASK (0x7 << 25) | ||
319 | #define GLPMCFG_RETRY_COUNT_STS_SHIFT 25 | ||
320 | #define GLPMCFG_SEND_LPM (1 << 24) | ||
321 | #define GLPMCFG_RETRY_COUNT_MASK (0x7 << 21) | ||
322 | #define GLPMCFG_RETRY_COUNT_SHIFT 21 | ||
323 | #define GLPMCFG_LPM_CHAN_INDEX_MASK (0xf << 17) | ||
324 | #define GLPMCFG_LPM_CHAN_INDEX_SHIFT 17 | ||
325 | #define GLPMCFG_SLEEP_STATE_RESUMEOK (1 << 16) | ||
326 | #define GLPMCFG_PRT_SLEEP_STS (1 << 15) | ||
327 | #define GLPMCFG_LPM_RESP_MASK (0x3 << 13) | ||
328 | #define GLPMCFG_LPM_RESP_SHIFT 13 | ||
329 | #define GLPMCFG_HIRD_THRES_MASK (0x1f << 8) | ||
330 | #define GLPMCFG_HIRD_THRES_SHIFT 8 | ||
331 | #define GLPMCFG_HIRD_THRES_EN (0x10 << 8) | ||
332 | #define GLPMCFG_EN_UTMI_SLEEP (1 << 7) | ||
333 | #define GLPMCFG_REM_WKUP_EN (1 << 6) | ||
334 | #define GLPMCFG_HIRD_MASK (0xf << 2) | ||
335 | #define GLPMCFG_HIRD_SHIFT 2 | ||
336 | #define GLPMCFG_APPL_RESP (1 << 1) | ||
337 | #define GLPMCFG_LPM_CAP_EN (1 << 0) | ||
338 | |||
339 | #define GPWRDN HSOTG_REG(0x0058) | ||
340 | #define GPWRDN_MULT_VAL_ID_BC_MASK (0x1f << 24) | ||
341 | #define GPWRDN_MULT_VAL_ID_BC_SHIFT 24 | ||
342 | #define GPWRDN_ADP_INT (1 << 23) | ||
343 | #define GPWRDN_BSESSVLD (1 << 22) | ||
344 | #define GPWRDN_IDSTS (1 << 21) | ||
345 | #define GPWRDN_LINESTATE_MASK (0x3 << 19) | ||
346 | #define GPWRDN_LINESTATE_SHIFT 19 | ||
347 | #define GPWRDN_STS_CHGINT_MSK (1 << 18) | ||
348 | #define GPWRDN_STS_CHGINT (1 << 17) | ||
349 | #define GPWRDN_SRP_DET_MSK (1 << 16) | ||
350 | #define GPWRDN_SRP_DET (1 << 15) | ||
351 | #define GPWRDN_CONNECT_DET_MSK (1 << 14) | ||
352 | #define GPWRDN_CONNECT_DET (1 << 13) | ||
353 | #define GPWRDN_DISCONN_DET_MSK (1 << 12) | ||
354 | #define GPWRDN_DISCONN_DET (1 << 11) | ||
355 | #define GPWRDN_RST_DET_MSK (1 << 10) | ||
356 | #define GPWRDN_RST_DET (1 << 9) | ||
357 | #define GPWRDN_LNSTSCHG_MSK (1 << 8) | ||
358 | #define GPWRDN_LNSTSCHG (1 << 7) | ||
359 | #define GPWRDN_DIS_VBUS (1 << 6) | ||
360 | #define GPWRDN_PWRDNSWTCH (1 << 5) | ||
361 | #define GPWRDN_PWRDNRSTN (1 << 4) | ||
362 | #define GPWRDN_PWRDNCLMP (1 << 3) | ||
363 | #define GPWRDN_RESTORE (1 << 2) | ||
364 | #define GPWRDN_PMUACTV (1 << 1) | ||
365 | #define GPWRDN_PMUINTSEL (1 << 0) | ||
366 | |||
367 | #define GDFIFOCFG HSOTG_REG(0x005c) | ||
368 | #define GDFIFOCFG_EPINFOBASE_MASK (0xffff << 16) | ||
369 | #define GDFIFOCFG_EPINFOBASE_SHIFT 16 | ||
370 | #define GDFIFOCFG_GDFIFOCFG_MASK (0xffff << 0) | ||
371 | #define GDFIFOCFG_GDFIFOCFG_SHIFT 0 | ||
372 | |||
373 | #define ADPCTL HSOTG_REG(0x0060) | ||
374 | #define ADPCTL_AR_MASK (0x3 << 27) | ||
375 | #define ADPCTL_AR_SHIFT 27 | ||
376 | #define ADPCTL_ADP_TMOUT_INT_MSK (1 << 26) | ||
377 | #define ADPCTL_ADP_SNS_INT_MSK (1 << 25) | ||
378 | #define ADPCTL_ADP_PRB_INT_MSK (1 << 24) | ||
379 | #define ADPCTL_ADP_TMOUT_INT (1 << 23) | ||
380 | #define ADPCTL_ADP_SNS_INT (1 << 22) | ||
381 | #define ADPCTL_ADP_PRB_INT (1 << 21) | ||
382 | #define ADPCTL_ADPENA (1 << 20) | ||
383 | #define ADPCTL_ADPRES (1 << 19) | ||
384 | #define ADPCTL_ENASNS (1 << 18) | ||
385 | #define ADPCTL_ENAPRB (1 << 17) | ||
386 | #define ADPCTL_RTIM_MASK (0x7ff << 6) | ||
387 | #define ADPCTL_RTIM_SHIFT 6 | ||
388 | #define ADPCTL_PRB_PER_MASK (0x3 << 4) | ||
389 | #define ADPCTL_PRB_PER_SHIFT 4 | ||
390 | #define ADPCTL_PRB_DELTA_MASK (0x3 << 2) | ||
391 | #define ADPCTL_PRB_DELTA_SHIFT 2 | ||
392 | #define ADPCTL_PRB_DSCHRG_MASK (0x3 << 0) | ||
393 | #define ADPCTL_PRB_DSCHRG_SHIFT 0 | ||
394 | |||
395 | #define HPTXFSIZ HSOTG_REG(0x100) | ||
396 | /* Use FIFOSIZE_* constants to access this register */ | ||
397 | |||
398 | #define DPTXFSIZN(_a) HSOTG_REG(0x104 + (((_a) - 1) * 4)) | ||
399 | /* Use FIFOSIZE_* constants to access this register */ | ||
400 | |||
401 | /* These apply to the GNPTXFSIZ, HPTXFSIZ and DPTXFSIZN registers */ | ||
402 | #define FIFOSIZE_DEPTH_MASK (0xffff << 16) | ||
403 | #define FIFOSIZE_DEPTH_SHIFT 16 | ||
404 | #define FIFOSIZE_STARTADDR_MASK (0xffff << 0) | ||
405 | #define FIFOSIZE_STARTADDR_SHIFT 0 | ||
406 | |||
407 | /* Device mode registers */ | ||
408 | |||
409 | #define DCFG HSOTG_REG(0x800) | ||
410 | #define DCFG_EPMISCNT_MASK (0x1f << 18) | ||
411 | #define DCFG_EPMISCNT_SHIFT 18 | ||
412 | #define DCFG_EPMISCNT_LIMIT 0x1f | ||
413 | #define DCFG_EPMISCNT(_x) ((_x) << 18) | ||
414 | #define DCFG_PERFRINT_MASK (0x3 << 11) | ||
415 | #define DCFG_PERFRINT_SHIFT 11 | ||
416 | #define DCFG_PERFRINT_LIMIT 0x3 | ||
417 | #define DCFG_PERFRINT(_x) ((_x) << 11) | ||
418 | #define DCFG_DEVADDR_MASK (0x7f << 4) | ||
419 | #define DCFG_DEVADDR_SHIFT 4 | ||
420 | #define DCFG_DEVADDR_LIMIT 0x7f | ||
421 | #define DCFG_DEVADDR(_x) ((_x) << 4) | ||
422 | #define DCFG_NZ_STS_OUT_HSHK (1 << 2) | ||
423 | #define DCFG_DEVSPD_MASK (0x3 << 0) | ||
424 | #define DCFG_DEVSPD_SHIFT 0 | ||
425 | #define DCFG_DEVSPD_HS 0 | ||
426 | #define DCFG_DEVSPD_FS 1 | ||
427 | #define DCFG_DEVSPD_LS 2 | ||
428 | #define DCFG_DEVSPD_FS48 3 | ||
429 | |||
430 | #define DCTL HSOTG_REG(0x804) | ||
431 | #define DCTL_PWRONPRGDONE (1 << 11) | ||
432 | #define DCTL_CGOUTNAK (1 << 10) | ||
433 | #define DCTL_SGOUTNAK (1 << 9) | ||
434 | #define DCTL_CGNPINNAK (1 << 8) | ||
435 | #define DCTL_SGNPINNAK (1 << 7) | ||
436 | #define DCTL_TSTCTL_MASK (0x7 << 4) | ||
437 | #define DCTL_TSTCTL_SHIFT 4 | ||
438 | #define DCTL_GOUTNAKSTS (1 << 3) | ||
439 | #define DCTL_GNPINNAKSTS (1 << 2) | ||
440 | #define DCTL_SFTDISCON (1 << 1) | ||
441 | #define DCTL_RMTWKUPSIG (1 << 0) | ||
442 | |||
443 | #define DSTS HSOTG_REG(0x808) | ||
444 | #define DSTS_SOFFN_MASK (0x3fff << 8) | ||
445 | #define DSTS_SOFFN_SHIFT 8 | ||
446 | #define DSTS_SOFFN_LIMIT 0x3fff | ||
447 | #define DSTS_SOFFN(_x) ((_x) << 8) | ||
448 | #define DSTS_ERRATICERR (1 << 3) | ||
449 | #define DSTS_ENUMSPD_MASK (0x3 << 1) | ||
450 | #define DSTS_ENUMSPD_SHIFT 1 | ||
451 | #define DSTS_ENUMSPD_HS 0 | ||
452 | #define DSTS_ENUMSPD_FS 1 | ||
453 | #define DSTS_ENUMSPD_LS 2 | ||
454 | #define DSTS_ENUMSPD_FS48 3 | ||
455 | #define DSTS_SUSPSTS (1 << 0) | ||
456 | |||
457 | #define DIEPMSK HSOTG_REG(0x810) | ||
458 | #define DIEPMSK_TXFIFOEMPTY (1 << 7) | ||
459 | #define DIEPMSK_INEPNAKEFFMSK (1 << 6) | ||
460 | #define DIEPMSK_INTKNEPMISMSK (1 << 5) | ||
461 | #define DIEPMSK_INTKNTXFEMPMSK (1 << 4) | ||
462 | #define DIEPMSK_TIMEOUTMSK (1 << 3) | ||
463 | #define DIEPMSK_AHBERRMSK (1 << 2) | ||
464 | #define DIEPMSK_EPDISBLDMSK (1 << 1) | ||
465 | #define DIEPMSK_XFERCOMPLMSK (1 << 0) | ||
466 | |||
467 | #define DOEPMSK HSOTG_REG(0x814) | ||
468 | #define DOEPMSK_BACK2BACKSETUP (1 << 6) | ||
469 | #define DOEPMSK_OUTTKNEPDISMSK (1 << 4) | ||
470 | #define DOEPMSK_SETUPMSK (1 << 3) | ||
471 | #define DOEPMSK_AHBERRMSK (1 << 2) | ||
472 | #define DOEPMSK_EPDISBLDMSK (1 << 1) | ||
473 | #define DOEPMSK_XFERCOMPLMSK (1 << 0) | ||
474 | |||
475 | #define DAINT HSOTG_REG(0x818) | ||
476 | #define DAINTMSK HSOTG_REG(0x81C) | ||
477 | #define DAINT_OUTEP_SHIFT 16 | ||
478 | #define DAINT_OUTEP(_x) (1 << ((_x) + 16)) | ||
479 | #define DAINT_INEP(_x) (1 << (_x)) | ||
480 | |||
481 | #define DTKNQR1 HSOTG_REG(0x820) | ||
482 | #define DTKNQR2 HSOTG_REG(0x824) | ||
483 | #define DTKNQR3 HSOTG_REG(0x830) | ||
484 | #define DTKNQR4 HSOTG_REG(0x834) | ||
485 | |||
486 | #define DVBUSDIS HSOTG_REG(0x828) | ||
487 | #define DVBUSPULSE HSOTG_REG(0x82C) | ||
488 | |||
489 | #define DIEPCTL0 HSOTG_REG(0x900) | ||
490 | #define DIEPCTL(_a) HSOTG_REG(0x900 + ((_a) * 0x20)) | ||
491 | |||
492 | #define DOEPCTL0 HSOTG_REG(0xB00) | ||
493 | #define DOEPCTL(_a) HSOTG_REG(0xB00 + ((_a) * 0x20)) | ||
494 | |||
495 | /* EP0 specialness: | ||
496 | * bits[29..28] - reserved (no SetD0PID, SetD1PID) | ||
497 | * bits[25..22] - should always be zero, this isn't a periodic endpoint | ||
498 | * bits[10..0] - MPS setting different for EP0 | ||
499 | */ | ||
500 | #define D0EPCTL_MPS_MASK (0x3 << 0) | ||
501 | #define D0EPCTL_MPS_SHIFT 0 | ||
502 | #define D0EPCTL_MPS_64 0 | ||
503 | #define D0EPCTL_MPS_32 1 | ||
504 | #define D0EPCTL_MPS_16 2 | ||
505 | #define D0EPCTL_MPS_8 3 | ||
506 | |||
507 | #define DXEPCTL_EPENA (1 << 31) | ||
508 | #define DXEPCTL_EPDIS (1 << 30) | ||
509 | #define DXEPCTL_SETD1PID (1 << 29) | ||
510 | #define DXEPCTL_SETODDFR (1 << 29) | ||
511 | #define DXEPCTL_SETD0PID (1 << 28) | ||
512 | #define DXEPCTL_SETEVENFR (1 << 28) | ||
513 | #define DXEPCTL_SNAK (1 << 27) | ||
514 | #define DXEPCTL_CNAK (1 << 26) | ||
515 | #define DXEPCTL_TXFNUM_MASK (0xf << 22) | ||
516 | #define DXEPCTL_TXFNUM_SHIFT 22 | ||
517 | #define DXEPCTL_TXFNUM_LIMIT 0xf | ||
518 | #define DXEPCTL_TXFNUM(_x) ((_x) << 22) | ||
519 | #define DXEPCTL_STALL (1 << 21) | ||
520 | #define DXEPCTL_SNP (1 << 20) | ||
521 | #define DXEPCTL_EPTYPE_MASK (0x3 << 18) | ||
522 | #define DXEPCTL_EPTYPE_SHIFT 18 | ||
523 | #define DXEPCTL_EPTYPE_CONTROL 0 | ||
524 | #define DXEPCTL_EPTYPE_ISO 1 | ||
525 | #define DXEPCTL_EPTYPE_BULK 2 | ||
526 | #define DXEPCTL_EPTYPE_INTTERUPT 3 | ||
527 | #define DXEPCTL_NAKSTS (1 << 17) | ||
528 | #define DXEPCTL_DPID (1 << 16) | ||
529 | #define DXEPCTL_EOFRNUM (1 << 16) | ||
530 | #define DXEPCTL_USBACTEP (1 << 15) | ||
531 | #define DXEPCTL_NEXTEP_MASK (0xf << 11) | ||
532 | #define DXEPCTL_NEXTEP_SHIFT 11 | ||
533 | #define DXEPCTL_NEXTEP_LIMIT 0xf | ||
534 | #define DXEPCTL_NEXTEP(_x) ((_x) << 11) | ||
535 | #define DXEPCTL_MPS_MASK (0x7ff << 0) | ||
536 | #define DXEPCTL_MPS_SHIFT 0 | ||
537 | #define DXEPCTL_MPS_LIMIT 0x7ff | ||
538 | #define DXEPCTL_MPS(_x) ((_x) << 0) | ||
539 | |||
540 | #define DIEPINT(_a) HSOTG_REG(0x908 + ((_a) * 0x20)) | ||
541 | #define DOEPINT(_a) HSOTG_REG(0xB08 + ((_a) * 0x20)) | ||
542 | #define DXEPINT_INEPNAKEFF (1 << 6) | ||
543 | #define DXEPINT_BACK2BACKSETUP (1 << 6) | ||
544 | #define DXEPINT_INTKNEPMIS (1 << 5) | ||
545 | #define DXEPINT_INTKNTXFEMP (1 << 4) | ||
546 | #define DXEPINT_OUTTKNEPDIS (1 << 4) | ||
547 | #define DXEPINT_TIMEOUT (1 << 3) | ||
548 | #define DXEPINT_SETUP (1 << 3) | ||
549 | #define DXEPINT_AHBERR (1 << 2) | ||
550 | #define DXEPINT_EPDISBLD (1 << 1) | ||
551 | #define DXEPINT_XFERCOMPL (1 << 0) | ||
552 | |||
553 | #define DIEPTSIZ0 HSOTG_REG(0x910) | ||
554 | #define DIEPTSIZ0_PKTCNT_MASK (0x3 << 19) | ||
555 | #define DIEPTSIZ0_PKTCNT_SHIFT 19 | ||
556 | #define DIEPTSIZ0_PKTCNT_LIMIT 0x3 | ||
557 | #define DIEPTSIZ0_PKTCNT(_x) ((_x) << 19) | ||
558 | #define DIEPTSIZ0_XFERSIZE_MASK (0x7f << 0) | ||
559 | #define DIEPTSIZ0_XFERSIZE_SHIFT 0 | ||
560 | #define DIEPTSIZ0_XFERSIZE_LIMIT 0x7f | ||
561 | #define DIEPTSIZ0_XFERSIZE(_x) ((_x) << 0) | ||
562 | |||
563 | #define DOEPTSIZ0 HSOTG_REG(0xB10) | ||
564 | #define DOEPTSIZ0_SUPCNT_MASK (0x3 << 29) | ||
565 | #define DOEPTSIZ0_SUPCNT_SHIFT 29 | ||
566 | #define DOEPTSIZ0_SUPCNT_LIMIT 0x3 | ||
567 | #define DOEPTSIZ0_SUPCNT(_x) ((_x) << 29) | ||
568 | #define DOEPTSIZ0_PKTCNT (1 << 19) | ||
569 | #define DOEPTSIZ0_XFERSIZE_MASK (0x7f << 0) | ||
570 | #define DOEPTSIZ0_XFERSIZE_SHIFT 0 | ||
571 | |||
572 | #define DIEPTSIZ(_a) HSOTG_REG(0x910 + ((_a) * 0x20)) | ||
573 | #define DOEPTSIZ(_a) HSOTG_REG(0xB10 + ((_a) * 0x20)) | ||
574 | #define DXEPTSIZ_MC_MASK (0x3 << 29) | ||
575 | #define DXEPTSIZ_MC_SHIFT 29 | ||
576 | #define DXEPTSIZ_MC_LIMIT 0x3 | ||
577 | #define DXEPTSIZ_MC(_x) ((_x) << 29) | ||
578 | #define DXEPTSIZ_PKTCNT_MASK (0x3ff << 19) | ||
579 | #define DXEPTSIZ_PKTCNT_SHIFT 19 | ||
580 | #define DXEPTSIZ_PKTCNT_LIMIT 0x3ff | ||
581 | #define DXEPTSIZ_PKTCNT_GET(_v) (((_v) >> 19) & 0x3ff) | ||
582 | #define DXEPTSIZ_PKTCNT(_x) ((_x) << 19) | ||
583 | #define DXEPTSIZ_XFERSIZE_MASK (0x7ffff << 0) | ||
584 | #define DXEPTSIZ_XFERSIZE_SHIFT 0 | ||
585 | #define DXEPTSIZ_XFERSIZE_LIMIT 0x7ffff | ||
586 | #define DXEPTSIZ_XFERSIZE_GET(_v) (((_v) >> 0) & 0x7ffff) | ||
587 | #define DXEPTSIZ_XFERSIZE(_x) ((_x) << 0) | ||
588 | |||
589 | #define DIEPDMA(_a) HSOTG_REG(0x914 + ((_a) * 0x20)) | ||
590 | #define DOEPDMA(_a) HSOTG_REG(0xB14 + ((_a) * 0x20)) | ||
591 | |||
592 | #define DTXFSTS(_a) HSOTG_REG(0x918 + ((_a) * 0x20)) | ||
593 | |||
594 | #define PCGCTL HSOTG_REG(0x0e00) | ||
595 | #define PCGCTL_IF_DEV_MODE (1 << 31) | ||
596 | #define PCGCTL_P2HD_PRT_SPD_MASK (0x3 << 29) | ||
597 | #define PCGCTL_P2HD_PRT_SPD_SHIFT 29 | ||
598 | #define PCGCTL_P2HD_DEV_ENUM_SPD_MASK (0x3 << 27) | ||
599 | #define PCGCTL_P2HD_DEV_ENUM_SPD_SHIFT 27 | ||
600 | #define PCGCTL_MAC_DEV_ADDR_MASK (0x7f << 20) | ||
601 | #define PCGCTL_MAC_DEV_ADDR_SHIFT 20 | ||
602 | #define PCGCTL_MAX_TERMSEL (1 << 19) | ||
603 | #define PCGCTL_MAX_XCVRSELECT_MASK (0x3 << 17) | ||
604 | #define PCGCTL_MAX_XCVRSELECT_SHIFT 17 | ||
605 | #define PCGCTL_PORT_POWER (1 << 16) | ||
606 | #define PCGCTL_PRT_CLK_SEL_MASK (0x3 << 14) | ||
607 | #define PCGCTL_PRT_CLK_SEL_SHIFT 14 | ||
608 | #define PCGCTL_ESS_REG_RESTORED (1 << 13) | ||
609 | #define PCGCTL_EXTND_HIBER_SWITCH (1 << 12) | ||
610 | #define PCGCTL_EXTND_HIBER_PWRCLMP (1 << 11) | ||
611 | #define PCGCTL_ENBL_EXTND_HIBER (1 << 10) | ||
612 | #define PCGCTL_RESTOREMODE (1 << 9) | ||
613 | #define PCGCTL_RESETAFTSUSP (1 << 8) | ||
614 | #define PCGCTL_DEEP_SLEEP (1 << 7) | ||
615 | #define PCGCTL_PHY_IN_SLEEP (1 << 6) | ||
616 | #define PCGCTL_ENBL_SLEEP_GATING (1 << 5) | ||
617 | #define PCGCTL_RSTPDWNMODULE (1 << 3) | ||
618 | #define PCGCTL_PWRCLMP (1 << 2) | ||
619 | #define PCGCTL_GATEHCLK (1 << 1) | ||
620 | #define PCGCTL_STOPPCLK (1 << 0) | ||
621 | |||
622 | #define EPFIFO(_a) HSOTG_REG(0x1000 + ((_a) * 0x1000)) | ||
623 | |||
624 | /* Host Mode Registers */ | ||
625 | |||
626 | #define HCFG HSOTG_REG(0x0400) | ||
627 | #define HCFG_MODECHTIMEN (1 << 31) | ||
628 | #define HCFG_PERSCHEDENA (1 << 26) | ||
629 | #define HCFG_FRLISTEN_MASK (0x3 << 24) | ||
630 | #define HCFG_FRLISTEN_SHIFT 24 | ||
631 | #define HCFG_FRLISTEN_8 (0 << 24) | ||
632 | #define FRLISTEN_8_SIZE 8 | ||
633 | #define HCFG_FRLISTEN_16 (1 << 24) | ||
634 | #define FRLISTEN_16_SIZE 16 | ||
635 | #define HCFG_FRLISTEN_32 (2 << 24) | ||
636 | #define FRLISTEN_32_SIZE 32 | ||
637 | #define HCFG_FRLISTEN_64 (3 << 24) | ||
638 | #define FRLISTEN_64_SIZE 64 | ||
639 | #define HCFG_DESCDMA (1 << 23) | ||
640 | #define HCFG_RESVALID_MASK (0xff << 8) | ||
641 | #define HCFG_RESVALID_SHIFT 8 | ||
642 | #define HCFG_ENA32KHZ (1 << 7) | ||
643 | #define HCFG_FSLSSUPP (1 << 2) | ||
644 | #define HCFG_FSLSPCLKSEL_MASK (0x3 << 0) | ||
645 | #define HCFG_FSLSPCLKSEL_SHIFT 0 | ||
646 | #define HCFG_FSLSPCLKSEL_30_60_MHZ 0 | ||
647 | #define HCFG_FSLSPCLKSEL_48_MHZ 1 | ||
648 | #define HCFG_FSLSPCLKSEL_6_MHZ 2 | ||
649 | |||
650 | #define HFIR HSOTG_REG(0x0404) | ||
651 | #define HFIR_FRINT_MASK (0xffff << 0) | ||
652 | #define HFIR_FRINT_SHIFT 0 | ||
653 | #define HFIR_RLDCTRL (1 << 16) | ||
654 | |||
655 | #define HFNUM HSOTG_REG(0x0408) | ||
656 | #define HFNUM_FRREM_MASK (0xffff << 16) | ||
657 | #define HFNUM_FRREM_SHIFT 16 | ||
658 | #define HFNUM_FRNUM_MASK (0xffff << 0) | ||
659 | #define HFNUM_FRNUM_SHIFT 0 | ||
660 | #define HFNUM_MAX_FRNUM 0x3fff | ||
661 | |||
662 | #define HPTXSTS HSOTG_REG(0x0410) | ||
663 | #define TXSTS_QTOP_ODD (1 << 31) | ||
664 | #define TXSTS_QTOP_CHNEP_MASK (0xf << 27) | ||
665 | #define TXSTS_QTOP_CHNEP_SHIFT 27 | ||
666 | #define TXSTS_QTOP_TOKEN_MASK (0x3 << 25) | ||
667 | #define TXSTS_QTOP_TOKEN_SHIFT 25 | ||
668 | #define TXSTS_QTOP_TERMINATE (1 << 24) | ||
669 | #define TXSTS_QSPCAVAIL_MASK (0xff << 16) | ||
670 | #define TXSTS_QSPCAVAIL_SHIFT 16 | ||
671 | #define TXSTS_FSPCAVAIL_MASK (0xffff << 0) | ||
672 | #define TXSTS_FSPCAVAIL_SHIFT 0 | ||
673 | |||
674 | #define HAINT HSOTG_REG(0x0414) | ||
675 | #define HAINTMSK HSOTG_REG(0x0418) | ||
676 | #define HFLBADDR HSOTG_REG(0x041c) | ||
677 | |||
678 | #define HPRT0 HSOTG_REG(0x0440) | ||
679 | #define HPRT0_SPD_MASK (0x3 << 17) | ||
680 | #define HPRT0_SPD_SHIFT 17 | ||
681 | #define HPRT0_SPD_HIGH_SPEED 0 | ||
682 | #define HPRT0_SPD_FULL_SPEED 1 | ||
683 | #define HPRT0_SPD_LOW_SPEED 2 | ||
684 | #define HPRT0_TSTCTL_MASK (0xf << 13) | ||
685 | #define HPRT0_TSTCTL_SHIFT 13 | ||
686 | #define HPRT0_PWR (1 << 12) | ||
687 | #define HPRT0_LNSTS_MASK (0x3 << 10) | ||
688 | #define HPRT0_LNSTS_SHIFT 10 | ||
689 | #define HPRT0_RST (1 << 8) | ||
690 | #define HPRT0_SUSP (1 << 7) | ||
691 | #define HPRT0_RES (1 << 6) | ||
692 | #define HPRT0_OVRCURRCHG (1 << 5) | ||
693 | #define HPRT0_OVRCURRACT (1 << 4) | ||
694 | #define HPRT0_ENACHG (1 << 3) | ||
695 | #define HPRT0_ENA (1 << 2) | ||
696 | #define HPRT0_CONNDET (1 << 1) | ||
697 | #define HPRT0_CONNSTS (1 << 0) | ||
698 | |||
699 | #define HCCHAR(_ch) HSOTG_REG(0x0500 + 0x20 * (_ch)) | ||
700 | #define HCCHAR_CHENA (1 << 31) | ||
701 | #define HCCHAR_CHDIS (1 << 30) | ||
702 | #define HCCHAR_ODDFRM (1 << 29) | ||
703 | #define HCCHAR_DEVADDR_MASK (0x7f << 22) | ||
704 | #define HCCHAR_DEVADDR_SHIFT 22 | ||
705 | #define HCCHAR_MULTICNT_MASK (0x3 << 20) | ||
706 | #define HCCHAR_MULTICNT_SHIFT 20 | ||
707 | #define HCCHAR_EPTYPE_MASK (0x3 << 18) | ||
708 | #define HCCHAR_EPTYPE_SHIFT 18 | ||
709 | #define HCCHAR_LSPDDEV (1 << 17) | ||
710 | #define HCCHAR_EPDIR (1 << 15) | ||
711 | #define HCCHAR_EPNUM_MASK (0xf << 11) | ||
712 | #define HCCHAR_EPNUM_SHIFT 11 | ||
713 | #define HCCHAR_MPS_MASK (0x7ff << 0) | ||
714 | #define HCCHAR_MPS_SHIFT 0 | ||
715 | |||
716 | #define HCSPLT(_ch) HSOTG_REG(0x0504 + 0x20 * (_ch)) | ||
717 | #define HCSPLT_SPLTENA (1 << 31) | ||
718 | #define HCSPLT_COMPSPLT (1 << 16) | ||
719 | #define HCSPLT_XACTPOS_MASK (0x3 << 14) | ||
720 | #define HCSPLT_XACTPOS_SHIFT 14 | ||
721 | #define HCSPLT_XACTPOS_MID 0 | ||
722 | #define HCSPLT_XACTPOS_END 1 | ||
723 | #define HCSPLT_XACTPOS_BEGIN 2 | ||
724 | #define HCSPLT_XACTPOS_ALL 3 | ||
725 | #define HCSPLT_HUBADDR_MASK (0x7f << 7) | ||
726 | #define HCSPLT_HUBADDR_SHIFT 7 | ||
727 | #define HCSPLT_PRTADDR_MASK (0x7f << 0) | ||
728 | #define HCSPLT_PRTADDR_SHIFT 0 | ||
729 | |||
730 | #define HCINT(_ch) HSOTG_REG(0x0508 + 0x20 * (_ch)) | ||
731 | #define HCINTMSK(_ch) HSOTG_REG(0x050c + 0x20 * (_ch)) | ||
732 | #define HCINTMSK_RESERVED14_31 (0x3ffff << 14) | ||
733 | #define HCINTMSK_FRM_LIST_ROLL (1 << 13) | ||
734 | #define HCINTMSK_XCS_XACT (1 << 12) | ||
735 | #define HCINTMSK_BNA (1 << 11) | ||
736 | #define HCINTMSK_DATATGLERR (1 << 10) | ||
737 | #define HCINTMSK_FRMOVRUN (1 << 9) | ||
738 | #define HCINTMSK_BBLERR (1 << 8) | ||
739 | #define HCINTMSK_XACTERR (1 << 7) | ||
740 | #define HCINTMSK_NYET (1 << 6) | ||
741 | #define HCINTMSK_ACK (1 << 5) | ||
742 | #define HCINTMSK_NAK (1 << 4) | ||
743 | #define HCINTMSK_STALL (1 << 3) | ||
744 | #define HCINTMSK_AHBERR (1 << 2) | ||
745 | #define HCINTMSK_CHHLTD (1 << 1) | ||
746 | #define HCINTMSK_XFERCOMPL (1 << 0) | ||
747 | |||
748 | #define HCTSIZ(_ch) HSOTG_REG(0x0510 + 0x20 * (_ch)) | ||
749 | #define TSIZ_DOPNG (1 << 31) | ||
750 | #define TSIZ_SC_MC_PID_MASK (0x3 << 29) | ||
751 | #define TSIZ_SC_MC_PID_SHIFT 29 | ||
752 | #define TSIZ_SC_MC_PID_DATA0 0 | ||
753 | #define TSIZ_SC_MC_PID_DATA2 1 | ||
754 | #define TSIZ_SC_MC_PID_DATA1 2 | ||
755 | #define TSIZ_SC_MC_PID_MDATA 3 | ||
756 | #define TSIZ_SC_MC_PID_SETUP 3 | ||
757 | #define TSIZ_PKTCNT_MASK (0x3ff << 19) | ||
758 | #define TSIZ_PKTCNT_SHIFT 19 | ||
759 | #define TSIZ_NTD_MASK (0xff << 8) | ||
760 | #define TSIZ_NTD_SHIFT 8 | ||
761 | #define TSIZ_SCHINFO_MASK (0xff << 0) | ||
762 | #define TSIZ_SCHINFO_SHIFT 0 | ||
763 | #define TSIZ_XFERSIZE_MASK (0x7ffff << 0) | ||
764 | #define TSIZ_XFERSIZE_SHIFT 0 | ||
765 | |||
766 | #define HCDMA(_ch) HSOTG_REG(0x0514 + 0x20 * (_ch)) | ||
767 | #define HCDMA_DMA_ADDR_MASK (0x1fffff << 11) | ||
768 | #define HCDMA_DMA_ADDR_SHIFT 11 | ||
769 | #define HCDMA_CTD_MASK (0xff << 3) | ||
770 | #define HCDMA_CTD_SHIFT 3 | ||
771 | |||
772 | #define HCDMAB(_ch) HSOTG_REG(0x051c + 0x20 * (_ch)) | ||
773 | |||
774 | #define HCFIFO(_ch) HSOTG_REG(0x1000 + 0x1000 * (_ch)) | ||
775 | |||
776 | /** | ||
777 | * struct dwc2_hcd_dma_desc - Host-mode DMA descriptor structure | ||
778 | * | ||
779 | * @status: DMA descriptor status quadlet | ||
780 | * @buf: DMA descriptor data buffer pointer | ||
781 | * | ||
782 | * DMA Descriptor structure contains two quadlets: | ||
783 | * Status quadlet and Data buffer pointer. | ||
784 | */ | ||
785 | struct dwc2_hcd_dma_desc { | ||
786 | u32 status; | ||
787 | u32 buf; | ||
788 | }; | ||
789 | |||
790 | #define HOST_DMA_A (1 << 31) | ||
791 | #define HOST_DMA_STS_MASK (0x3 << 28) | ||
792 | #define HOST_DMA_STS_SHIFT 28 | ||
793 | #define HOST_DMA_STS_PKTERR (1 << 28) | ||
794 | #define HOST_DMA_EOL (1 << 26) | ||
795 | #define HOST_DMA_IOC (1 << 25) | ||
796 | #define HOST_DMA_SUP (1 << 24) | ||
797 | #define HOST_DMA_ALT_QTD (1 << 23) | ||
798 | #define HOST_DMA_QTD_OFFSET_MASK (0x3f << 17) | ||
799 | #define HOST_DMA_QTD_OFFSET_SHIFT 17 | ||
800 | #define HOST_DMA_ISOC_NBYTES_MASK (0xfff << 0) | ||
801 | #define HOST_DMA_ISOC_NBYTES_SHIFT 0 | ||
802 | #define HOST_DMA_NBYTES_MASK (0x1ffff << 0) | ||
803 | #define HOST_DMA_NBYTES_SHIFT 0 | ||
804 | |||
805 | #define MAX_DMA_DESC_SIZE 131071 | ||
806 | #define MAX_DMA_DESC_NUM_GENERIC 64 | ||
807 | #define MAX_DMA_DESC_NUM_HS_ISOC 256 | ||
808 | |||
809 | #endif /* __DWC2_HW_H__ */ | ||
diff --git a/drivers/usb/dwc2/pci.c b/drivers/usb/dwc2/pci.c new file mode 100644 index 000000000000..c291fca5d21f --- /dev/null +++ b/drivers/usb/dwc2/pci.c | |||
@@ -0,0 +1,178 @@ | |||
1 | /* | ||
2 | * pci.c - DesignWare HS OTG Controller PCI driver | ||
3 | * | ||
4 | * Copyright (C) 2004-2013 Synopsys, Inc. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions, and the following disclaimer, | ||
11 | * without modification. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The names of the above-listed copyright holders may not be used | ||
16 | * to endorse or promote products derived from this software without | ||
17 | * specific prior written permission. | ||
18 | * | ||
19 | * ALTERNATIVELY, this software may be distributed under the terms of the | ||
20 | * GNU General Public License ("GPL") as published by the Free Software | ||
21 | * Foundation; either version 2 of the License, or (at your option) any | ||
22 | * later version. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
26 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
35 | */ | ||
36 | |||
37 | /* | ||
38 | * Provides the initialization and cleanup entry points for the DWC_otg PCI | ||
39 | * driver | ||
40 | */ | ||
41 | #include <linux/kernel.h> | ||
42 | #include <linux/module.h> | ||
43 | #include <linux/moduleparam.h> | ||
44 | #include <linux/spinlock.h> | ||
45 | #include <linux/interrupt.h> | ||
46 | #include <linux/io.h> | ||
47 | #include <linux/slab.h> | ||
48 | #include <linux/pci.h> | ||
49 | #include <linux/usb.h> | ||
50 | |||
51 | #include <linux/usb/hcd.h> | ||
52 | #include <linux/usb/ch11.h> | ||
53 | |||
54 | #include "core.h" | ||
55 | #include "hcd.h" | ||
56 | |||
57 | #define PCI_VENDOR_ID_SYNOPSYS 0x16c3 | ||
58 | #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 | ||
59 | |||
60 | static const char dwc2_driver_name[] = "dwc2"; | ||
61 | |||
62 | static const struct dwc2_core_params dwc2_module_params = { | ||
63 | .otg_cap = -1, | ||
64 | .otg_ver = -1, | ||
65 | .dma_enable = -1, | ||
66 | .dma_desc_enable = 0, | ||
67 | .speed = -1, | ||
68 | .enable_dynamic_fifo = -1, | ||
69 | .en_multiple_tx_fifo = -1, | ||
70 | .host_rx_fifo_size = 1024, | ||
71 | .host_nperio_tx_fifo_size = 256, | ||
72 | .host_perio_tx_fifo_size = 1024, | ||
73 | .max_transfer_size = 65535, | ||
74 | .max_packet_count = 511, | ||
75 | .host_channels = -1, | ||
76 | .phy_type = -1, | ||
77 | .phy_utmi_width = -1, | ||
78 | .phy_ulpi_ddr = -1, | ||
79 | .phy_ulpi_ext_vbus = -1, | ||
80 | .i2c_enable = -1, | ||
81 | .ulpi_fs_ls = -1, | ||
82 | .host_support_fs_ls_low_power = -1, | ||
83 | .host_ls_low_power_phy_clk = -1, | ||
84 | .ts_dline = -1, | ||
85 | .reload_ctl = -1, | ||
86 | .ahbcfg = -1, | ||
87 | .uframe_sched = -1, | ||
88 | }; | ||
89 | |||
90 | /** | ||
91 | * dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the | ||
92 | * DWC_otg driver | ||
93 | * | ||
94 | * @dev: Bus device | ||
95 | * | ||
96 | * This routine is called, for example, when the rmmod command is executed. The | ||
97 | * device may or may not be electrically present. If it is present, the driver | ||
98 | * stops device processing. Any resources used on behalf of this device are | ||
99 | * freed. | ||
100 | */ | ||
101 | static void dwc2_driver_remove(struct pci_dev *dev) | ||
102 | { | ||
103 | struct dwc2_hsotg *hsotg = pci_get_drvdata(dev); | ||
104 | |||
105 | dwc2_hcd_remove(hsotg); | ||
106 | pci_disable_device(dev); | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg | ||
111 | * driver | ||
112 | * | ||
113 | * @dev: Bus device | ||
114 | * | ||
115 | * This routine creates the driver components required to control the device | ||
116 | * (core, HCD, and PCD) and initializes the device. The driver components are | ||
117 | * stored in a dwc2_hsotg structure. A reference to the dwc2_hsotg is saved | ||
118 | * in the device private data. This allows the driver to access the dwc2_hsotg | ||
119 | * structure on subsequent calls to driver methods for this device. | ||
120 | */ | ||
121 | static int dwc2_driver_probe(struct pci_dev *dev, | ||
122 | const struct pci_device_id *id) | ||
123 | { | ||
124 | struct dwc2_hsotg *hsotg; | ||
125 | int retval; | ||
126 | |||
127 | hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); | ||
128 | if (!hsotg) | ||
129 | return -ENOMEM; | ||
130 | |||
131 | hsotg->dev = &dev->dev; | ||
132 | hsotg->regs = devm_ioremap_resource(&dev->dev, &dev->resource[0]); | ||
133 | if (IS_ERR(hsotg->regs)) | ||
134 | return PTR_ERR(hsotg->regs); | ||
135 | |||
136 | dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", | ||
137 | (unsigned long)pci_resource_start(dev, 0), hsotg->regs); | ||
138 | |||
139 | if (pci_enable_device(dev) < 0) | ||
140 | return -ENODEV; | ||
141 | |||
142 | pci_set_master(dev); | ||
143 | |||
144 | retval = dwc2_hcd_init(hsotg, dev->irq, &dwc2_module_params); | ||
145 | if (retval) { | ||
146 | pci_disable_device(dev); | ||
147 | return retval; | ||
148 | } | ||
149 | |||
150 | pci_set_drvdata(dev, hsotg); | ||
151 | |||
152 | return retval; | ||
153 | } | ||
154 | |||
155 | static const struct pci_device_id dwc2_pci_ids[] = { | ||
156 | { | ||
157 | PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG), | ||
158 | }, | ||
159 | { | ||
160 | PCI_DEVICE(PCI_VENDOR_ID_STMICRO, | ||
161 | PCI_DEVICE_ID_STMICRO_USB_OTG), | ||
162 | }, | ||
163 | { /* end: all zeroes */ } | ||
164 | }; | ||
165 | MODULE_DEVICE_TABLE(pci, dwc2_pci_ids); | ||
166 | |||
167 | static struct pci_driver dwc2_pci_driver = { | ||
168 | .name = dwc2_driver_name, | ||
169 | .id_table = dwc2_pci_ids, | ||
170 | .probe = dwc2_driver_probe, | ||
171 | .remove = dwc2_driver_remove, | ||
172 | }; | ||
173 | |||
174 | module_pci_driver(dwc2_pci_driver); | ||
175 | |||
176 | MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue"); | ||
177 | MODULE_AUTHOR("Synopsys, Inc."); | ||
178 | MODULE_LICENSE("Dual BSD/GPL"); | ||
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c new file mode 100644 index 000000000000..d01d0d3f2cf0 --- /dev/null +++ b/drivers/usb/dwc2/platform.c | |||
@@ -0,0 +1,187 @@ | |||
1 | /* | ||
2 | * platform.c - DesignWare HS OTG Controller platform driver | ||
3 | * | ||
4 | * Copyright (C) Matthijs Kooijman <matthijs@stdin.nl> | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions, and the following disclaimer, | ||
11 | * without modification. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The names of the above-listed copyright holders may not be used | ||
16 | * to endorse or promote products derived from this software without | ||
17 | * specific prior written permission. | ||
18 | * | ||
19 | * ALTERNATIVELY, this software may be distributed under the terms of the | ||
20 | * GNU General Public License ("GPL") as published by the Free Software | ||
21 | * Foundation; either version 2 of the License, or (at your option) any | ||
22 | * later version. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
26 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
35 | */ | ||
36 | |||
37 | #include <linux/kernel.h> | ||
38 | #include <linux/module.h> | ||
39 | #include <linux/slab.h> | ||
40 | #include <linux/device.h> | ||
41 | #include <linux/dma-mapping.h> | ||
42 | #include <linux/of_device.h> | ||
43 | #include <linux/platform_device.h> | ||
44 | |||
45 | #include "core.h" | ||
46 | #include "hcd.h" | ||
47 | |||
48 | static const char dwc2_driver_name[] = "dwc2"; | ||
49 | |||
50 | static const struct dwc2_core_params params_bcm2835 = { | ||
51 | .otg_cap = 0, /* HNP/SRP capable */ | ||
52 | .otg_ver = 0, /* 1.3 */ | ||
53 | .dma_enable = 1, | ||
54 | .dma_desc_enable = 0, | ||
55 | .speed = 0, /* High Speed */ | ||
56 | .enable_dynamic_fifo = 1, | ||
57 | .en_multiple_tx_fifo = 1, | ||
58 | .host_rx_fifo_size = 774, /* 774 DWORDs */ | ||
59 | .host_nperio_tx_fifo_size = 256, /* 256 DWORDs */ | ||
60 | .host_perio_tx_fifo_size = 512, /* 512 DWORDs */ | ||
61 | .max_transfer_size = 65535, | ||
62 | .max_packet_count = 511, | ||
63 | .host_channels = 8, | ||
64 | .phy_type = 1, /* UTMI */ | ||
65 | .phy_utmi_width = 8, /* 8 bits */ | ||
66 | .phy_ulpi_ddr = 0, /* Single */ | ||
67 | .phy_ulpi_ext_vbus = 0, | ||
68 | .i2c_enable = 0, | ||
69 | .ulpi_fs_ls = 0, | ||
70 | .host_support_fs_ls_low_power = 0, | ||
71 | .host_ls_low_power_phy_clk = 0, /* 48 MHz */ | ||
72 | .ts_dline = 0, | ||
73 | .reload_ctl = 0, | ||
74 | .ahbcfg = 0x10, | ||
75 | .uframe_sched = 0, | ||
76 | }; | ||
77 | |||
78 | /** | ||
79 | * dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the | ||
80 | * DWC_otg driver | ||
81 | * | ||
82 | * @dev: Platform device | ||
83 | * | ||
84 | * This routine is called, for example, when the rmmod command is executed. The | ||
85 | * device may or may not be electrically present. If it is present, the driver | ||
86 | * stops device processing. Any resources used on behalf of this device are | ||
87 | * freed. | ||
88 | */ | ||
89 | static int dwc2_driver_remove(struct platform_device *dev) | ||
90 | { | ||
91 | struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); | ||
92 | |||
93 | dwc2_hcd_remove(hsotg); | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | static const struct of_device_id dwc2_of_match_table[] = { | ||
99 | { .compatible = "brcm,bcm2835-usb", .data = ¶ms_bcm2835 }, | ||
100 | { .compatible = "snps,dwc2", .data = NULL }, | ||
101 | {}, | ||
102 | }; | ||
103 | MODULE_DEVICE_TABLE(of, dwc2_of_match_table); | ||
104 | |||
105 | /** | ||
106 | * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg | ||
107 | * driver | ||
108 | * | ||
109 | * @dev: Platform device | ||
110 | * | ||
111 | * This routine creates the driver components required to control the device | ||
112 | * (core, HCD, and PCD) and initializes the device. The driver components are | ||
113 | * stored in a dwc2_hsotg structure. A reference to the dwc2_hsotg is saved | ||
114 | * in the device private data. This allows the driver to access the dwc2_hsotg | ||
115 | * structure on subsequent calls to driver methods for this device. | ||
116 | */ | ||
117 | static int dwc2_driver_probe(struct platform_device *dev) | ||
118 | { | ||
119 | const struct of_device_id *match; | ||
120 | const struct dwc2_core_params *params; | ||
121 | struct dwc2_core_params defparams; | ||
122 | struct dwc2_hsotg *hsotg; | ||
123 | struct resource *res; | ||
124 | int retval; | ||
125 | int irq; | ||
126 | |||
127 | match = of_match_device(dwc2_of_match_table, &dev->dev); | ||
128 | if (match && match->data) { | ||
129 | params = match->data; | ||
130 | } else { | ||
131 | /* Default all params to autodetect */ | ||
132 | dwc2_set_all_params(&defparams, -1); | ||
133 | params = &defparams; | ||
134 | } | ||
135 | |||
136 | hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); | ||
137 | if (!hsotg) | ||
138 | return -ENOMEM; | ||
139 | |||
140 | hsotg->dev = &dev->dev; | ||
141 | |||
142 | /* | ||
143 | * Use reasonable defaults so platforms don't have to provide these. | ||
144 | */ | ||
145 | if (!dev->dev.dma_mask) | ||
146 | dev->dev.dma_mask = &dev->dev.coherent_dma_mask; | ||
147 | retval = dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(32)); | ||
148 | if (retval) | ||
149 | return retval; | ||
150 | |||
151 | irq = platform_get_irq(dev, 0); | ||
152 | if (irq < 0) { | ||
153 | dev_err(&dev->dev, "missing IRQ resource\n"); | ||
154 | return irq; | ||
155 | } | ||
156 | |||
157 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
158 | hsotg->regs = devm_ioremap_resource(&dev->dev, res); | ||
159 | if (IS_ERR(hsotg->regs)) | ||
160 | return PTR_ERR(hsotg->regs); | ||
161 | |||
162 | dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", | ||
163 | (unsigned long)res->start, hsotg->regs); | ||
164 | |||
165 | retval = dwc2_hcd_init(hsotg, irq, params); | ||
166 | if (retval) | ||
167 | return retval; | ||
168 | |||
169 | platform_set_drvdata(dev, hsotg); | ||
170 | |||
171 | return retval; | ||
172 | } | ||
173 | |||
174 | static struct platform_driver dwc2_platform_driver = { | ||
175 | .driver = { | ||
176 | .name = dwc2_driver_name, | ||
177 | .of_match_table = dwc2_of_match_table, | ||
178 | }, | ||
179 | .probe = dwc2_driver_probe, | ||
180 | .remove = dwc2_driver_remove, | ||
181 | }; | ||
182 | |||
183 | module_platform_driver(dwc2_platform_driver); | ||
184 | |||
185 | MODULE_DESCRIPTION("DESIGNWARE HS OTG Platform Glue"); | ||
186 | MODULE_AUTHOR("Matthijs Kooijman <matthijs@stdin.nl>"); | ||
187 | MODULE_LICENSE("Dual BSD/GPL"); | ||
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 70fc43027a5c..e2c730fc9a90 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig | |||
@@ -70,6 +70,13 @@ config USB_DWC3_PCI | |||
70 | One such PCIe-based platform is Synopsys' PCIe HAPS model of | 70 | One such PCIe-based platform is Synopsys' PCIe HAPS model of |
71 | this IP. | 71 | this IP. |
72 | 72 | ||
73 | config USB_DWC3_KEYSTONE | ||
74 | tristate "Texas Instruments Keystone2 Platforms" | ||
75 | default USB_DWC3 | ||
76 | help | ||
77 | Support of USB2/3 functionality in TI Keystone2 platforms. | ||
78 | Say 'Y' or 'M' here if you have one such device | ||
79 | |||
73 | comment "Debugging features" | 80 | comment "Debugging features" |
74 | 81 | ||
75 | config USB_DWC3_DEBUG | 82 | config USB_DWC3_DEBUG |
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile index dd1760145c46..10ac3e72482e 100644 --- a/drivers/usb/dwc3/Makefile +++ b/drivers/usb/dwc3/Makefile | |||
@@ -32,3 +32,4 @@ endif | |||
32 | obj-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o | 32 | obj-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o |
33 | obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o | 33 | obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o |
34 | obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o | 34 | obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o |
35 | obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o | ||
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index 8b20c70d91e7..28c8ad79f5e6 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c | |||
@@ -50,6 +50,7 @@ static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos) | |||
50 | 50 | ||
51 | exynos->usb2_phy = pdev; | 51 | exynos->usb2_phy = pdev; |
52 | pdata.type = USB_PHY_TYPE_USB2; | 52 | pdata.type = USB_PHY_TYPE_USB2; |
53 | pdata.gpio_reset = -1; | ||
53 | 54 | ||
54 | ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata)); | 55 | ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata)); |
55 | if (ret) | 56 | if (ret) |
diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c new file mode 100644 index 000000000000..1fad1618df6e --- /dev/null +++ b/drivers/usb/dwc3/dwc3-keystone.c | |||
@@ -0,0 +1,202 @@ | |||
1 | /** | ||
2 | * dwc3-keystone.c - Keystone Specific Glue layer | ||
3 | * | ||
4 | * Copyright (C) 2010-2013 Texas Instruments Incorporated - http://www.ti.com | ||
5 | * | ||
6 | * Author: WingMan Kwok <w-kwok2@ti.com> | ||
7 | * | ||
8 | * This program is free software: you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 of | ||
10 | * the License as published by the Free Software Foundation. | ||
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 | |||
18 | #include <linux/clk.h> | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/interrupt.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/dma-mapping.h> | ||
24 | #include <linux/io.h> | ||
25 | #include <linux/of_platform.h> | ||
26 | |||
27 | /* USBSS register offsets */ | ||
28 | #define USBSS_REVISION 0x0000 | ||
29 | #define USBSS_SYSCONFIG 0x0010 | ||
30 | #define USBSS_IRQ_EOI 0x0018 | ||
31 | #define USBSS_IRQSTATUS_RAW_0 0x0020 | ||
32 | #define USBSS_IRQSTATUS_0 0x0024 | ||
33 | #define USBSS_IRQENABLE_SET_0 0x0028 | ||
34 | #define USBSS_IRQENABLE_CLR_0 0x002c | ||
35 | |||
36 | /* IRQ register bits */ | ||
37 | #define USBSS_IRQ_EOI_LINE(n) BIT(n) | ||
38 | #define USBSS_IRQ_EVENT_ST BIT(0) | ||
39 | #define USBSS_IRQ_COREIRQ_EN BIT(0) | ||
40 | #define USBSS_IRQ_COREIRQ_CLR BIT(0) | ||
41 | |||
42 | static u64 kdwc3_dma_mask; | ||
43 | |||
44 | struct dwc3_keystone { | ||
45 | struct device *dev; | ||
46 | struct clk *clk; | ||
47 | void __iomem *usbss; | ||
48 | }; | ||
49 | |||
50 | static inline u32 kdwc3_readl(void __iomem *base, u32 offset) | ||
51 | { | ||
52 | return readl(base + offset); | ||
53 | } | ||
54 | |||
55 | static inline void kdwc3_writel(void __iomem *base, u32 offset, u32 value) | ||
56 | { | ||
57 | writel(value, base + offset); | ||
58 | } | ||
59 | |||
60 | static void kdwc3_enable_irqs(struct dwc3_keystone *kdwc) | ||
61 | { | ||
62 | u32 val; | ||
63 | |||
64 | val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0); | ||
65 | val |= USBSS_IRQ_COREIRQ_EN; | ||
66 | kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val); | ||
67 | } | ||
68 | |||
69 | static void kdwc3_disable_irqs(struct dwc3_keystone *kdwc) | ||
70 | { | ||
71 | u32 val; | ||
72 | |||
73 | val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0); | ||
74 | val &= ~USBSS_IRQ_COREIRQ_EN; | ||
75 | kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val); | ||
76 | } | ||
77 | |||
78 | static irqreturn_t dwc3_keystone_interrupt(int irq, void *_kdwc) | ||
79 | { | ||
80 | struct dwc3_keystone *kdwc = _kdwc; | ||
81 | |||
82 | kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_CLR_0, USBSS_IRQ_COREIRQ_CLR); | ||
83 | kdwc3_writel(kdwc->usbss, USBSS_IRQSTATUS_0, USBSS_IRQ_EVENT_ST); | ||
84 | kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, USBSS_IRQ_COREIRQ_EN); | ||
85 | kdwc3_writel(kdwc->usbss, USBSS_IRQ_EOI, USBSS_IRQ_EOI_LINE(0)); | ||
86 | |||
87 | return IRQ_HANDLED; | ||
88 | } | ||
89 | |||
90 | static int kdwc3_probe(struct platform_device *pdev) | ||
91 | { | ||
92 | struct device *dev = &pdev->dev; | ||
93 | struct device_node *node = pdev->dev.of_node; | ||
94 | struct dwc3_keystone *kdwc; | ||
95 | struct resource *res; | ||
96 | int error, irq; | ||
97 | |||
98 | kdwc = devm_kzalloc(dev, sizeof(*kdwc), GFP_KERNEL); | ||
99 | if (!kdwc) | ||
100 | return -ENOMEM; | ||
101 | |||
102 | platform_set_drvdata(pdev, kdwc); | ||
103 | |||
104 | kdwc->dev = dev; | ||
105 | |||
106 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
107 | if (!res) { | ||
108 | dev_err(dev, "missing usbss resource\n"); | ||
109 | return -EINVAL; | ||
110 | } | ||
111 | |||
112 | kdwc->usbss = devm_ioremap_resource(dev, res); | ||
113 | if (IS_ERR(kdwc->usbss)) | ||
114 | return PTR_ERR(kdwc->usbss); | ||
115 | |||
116 | kdwc3_dma_mask = dma_get_mask(dev); | ||
117 | dev->dma_mask = &kdwc3_dma_mask; | ||
118 | |||
119 | kdwc->clk = devm_clk_get(kdwc->dev, "usb"); | ||
120 | |||
121 | error = clk_prepare_enable(kdwc->clk); | ||
122 | if (error < 0) { | ||
123 | dev_dbg(kdwc->dev, "unable to enable usb clock, err %d\n", | ||
124 | error); | ||
125 | return error; | ||
126 | } | ||
127 | |||
128 | irq = platform_get_irq(pdev, 0); | ||
129 | if (irq < 0) { | ||
130 | dev_err(&pdev->dev, "missing irq\n"); | ||
131 | goto err_irq; | ||
132 | } | ||
133 | |||
134 | error = devm_request_irq(dev, irq, dwc3_keystone_interrupt, IRQF_SHARED, | ||
135 | dev_name(dev), kdwc); | ||
136 | if (error) { | ||
137 | dev_err(dev, "failed to request IRQ #%d --> %d\n", | ||
138 | irq, error); | ||
139 | goto err_irq; | ||
140 | } | ||
141 | |||
142 | kdwc3_enable_irqs(kdwc); | ||
143 | |||
144 | error = of_platform_populate(node, NULL, NULL, dev); | ||
145 | if (error) { | ||
146 | dev_err(&pdev->dev, "failed to create dwc3 core\n"); | ||
147 | goto err_core; | ||
148 | } | ||
149 | |||
150 | return 0; | ||
151 | |||
152 | err_core: | ||
153 | kdwc3_disable_irqs(kdwc); | ||
154 | err_irq: | ||
155 | clk_disable_unprepare(kdwc->clk); | ||
156 | |||
157 | return error; | ||
158 | } | ||
159 | |||
160 | static int kdwc3_remove_core(struct device *dev, void *c) | ||
161 | { | ||
162 | struct platform_device *pdev = to_platform_device(dev); | ||
163 | |||
164 | platform_device_unregister(pdev); | ||
165 | |||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | static int kdwc3_remove(struct platform_device *pdev) | ||
170 | { | ||
171 | struct dwc3_keystone *kdwc = platform_get_drvdata(pdev); | ||
172 | |||
173 | kdwc3_disable_irqs(kdwc); | ||
174 | device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core); | ||
175 | clk_disable_unprepare(kdwc->clk); | ||
176 | platform_set_drvdata(pdev, NULL); | ||
177 | |||
178 | return 0; | ||
179 | } | ||
180 | |||
181 | static const struct of_device_id kdwc3_of_match[] = { | ||
182 | { .compatible = "ti,keystone-dwc3", }, | ||
183 | {}, | ||
184 | }; | ||
185 | MODULE_DEVICE_TABLE(of, kdwc3_of_match); | ||
186 | |||
187 | static struct platform_driver kdwc3_driver = { | ||
188 | .probe = kdwc3_probe, | ||
189 | .remove = kdwc3_remove, | ||
190 | .driver = { | ||
191 | .name = "keystone-dwc3", | ||
192 | .owner = THIS_MODULE, | ||
193 | .of_match_table = kdwc3_of_match, | ||
194 | }, | ||
195 | }; | ||
196 | |||
197 | module_platform_driver(kdwc3_driver); | ||
198 | |||
199 | MODULE_ALIAS("platform:keystone-dwc3"); | ||
200 | MODULE_AUTHOR("WingMan Kwok <w-kwok2@ti.com>"); | ||
201 | MODULE_LICENSE("GPL v2"); | ||
202 | MODULE_DESCRIPTION("DesignWare USB3 KEYSTONE Glue Layer"); | ||
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c index 7f7ea62e961b..b269dbd47fc4 100644 --- a/drivers/usb/dwc3/dwc3-omap.c +++ b/drivers/usb/dwc3/dwc3-omap.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
22 | #include <linux/interrupt.h> | 22 | #include <linux/interrupt.h> |
23 | #include <linux/spinlock.h> | ||
24 | #include <linux/platform_device.h> | 23 | #include <linux/platform_device.h> |
25 | #include <linux/platform_data/dwc3-omap.h> | 24 | #include <linux/platform_data/dwc3-omap.h> |
26 | #include <linux/pm_runtime.h> | 25 | #include <linux/pm_runtime.h> |
@@ -120,9 +119,6 @@ | |||
120 | #define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID (1 << 1) | 119 | #define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID (1 << 1) |
121 | 120 | ||
122 | struct dwc3_omap { | 121 | struct dwc3_omap { |
123 | /* device lock */ | ||
124 | spinlock_t lock; | ||
125 | |||
126 | struct device *dev; | 122 | struct device *dev; |
127 | 123 | ||
128 | int irq; | 124 | int irq; |
@@ -280,8 +276,6 @@ static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) | |||
280 | struct dwc3_omap *omap = _omap; | 276 | struct dwc3_omap *omap = _omap; |
281 | u32 reg; | 277 | u32 reg; |
282 | 278 | ||
283 | spin_lock(&omap->lock); | ||
284 | |||
285 | reg = dwc3_omap_read_irqmisc_status(omap); | 279 | reg = dwc3_omap_read_irqmisc_status(omap); |
286 | 280 | ||
287 | if (reg & USBOTGSS_IRQMISC_DMADISABLECLR) { | 281 | if (reg & USBOTGSS_IRQMISC_DMADISABLECLR) { |
@@ -322,8 +316,6 @@ static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) | |||
322 | 316 | ||
323 | dwc3_omap_write_irq0_status(omap, reg); | 317 | dwc3_omap_write_irq0_status(omap, reg); |
324 | 318 | ||
325 | spin_unlock(&omap->lock); | ||
326 | |||
327 | return IRQ_HANDLED; | 319 | return IRQ_HANDLED; |
328 | } | 320 | } |
329 | 321 | ||
@@ -449,8 +441,6 @@ static int dwc3_omap_probe(struct platform_device *pdev) | |||
449 | } | 441 | } |
450 | } | 442 | } |
451 | 443 | ||
452 | spin_lock_init(&omap->lock); | ||
453 | |||
454 | omap->dev = dev; | 444 | omap->dev = dev; |
455 | omap->irq = irq; | 445 | omap->irq = irq; |
456 | omap->base = base; | 446 | omap->base = base; |
@@ -535,7 +525,7 @@ static int dwc3_omap_probe(struct platform_device *pdev) | |||
535 | edev = of_extcon_get_extcon_dev(dev, 0); | 525 | edev = of_extcon_get_extcon_dev(dev, 0); |
536 | if (IS_ERR(edev)) { | 526 | if (IS_ERR(edev)) { |
537 | dev_vdbg(dev, "couldn't get extcon device\n"); | 527 | dev_vdbg(dev, "couldn't get extcon device\n"); |
538 | ret = PTR_ERR(edev); | 528 | ret = -EPROBE_DEFER; |
539 | goto err2; | 529 | goto err2; |
540 | } | 530 | } |
541 | 531 | ||
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index 31443aeedcdb..f393c183cc69 100644 --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c | |||
@@ -52,6 +52,7 @@ static int dwc3_pci_register_phys(struct dwc3_pci *glue) | |||
52 | 52 | ||
53 | glue->usb2_phy = pdev; | 53 | glue->usb2_phy = pdev; |
54 | pdata.type = USB_PHY_TYPE_USB2; | 54 | pdata.type = USB_PHY_TYPE_USB2; |
55 | pdata.gpio_reset = -1; | ||
55 | 56 | ||
56 | ret = platform_device_add_data(glue->usb2_phy, &pdata, sizeof(pdata)); | 57 | ret = platform_device_add_data(glue->usb2_phy, &pdata, sizeof(pdata)); |
57 | if (ret) | 58 | if (ret) |
@@ -182,7 +183,7 @@ static void dwc3_pci_remove(struct pci_dev *pci) | |||
182 | pci_disable_device(pci); | 183 | pci_disable_device(pci); |
183 | } | 184 | } |
184 | 185 | ||
185 | static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = { | 186 | static const struct pci_device_id dwc3_pci_id_table[] = { |
186 | { | 187 | { |
187 | PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, | 188 | PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, |
188 | PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3), | 189 | PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3), |
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 02e44fcaf205..2da0a5a2803a 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c | |||
@@ -1650,7 +1650,7 @@ static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc, | |||
1650 | dev_vdbg(dwc->dev, "initializing %s\n", dep->name); | 1650 | dev_vdbg(dwc->dev, "initializing %s\n", dep->name); |
1651 | 1651 | ||
1652 | if (epnum == 0 || epnum == 1) { | 1652 | if (epnum == 0 || epnum == 1) { |
1653 | dep->endpoint.maxpacket = 512; | 1653 | usb_ep_set_maxpacket_limit(&dep->endpoint, 512); |
1654 | dep->endpoint.maxburst = 1; | 1654 | dep->endpoint.maxburst = 1; |
1655 | dep->endpoint.ops = &dwc3_gadget_ep0_ops; | 1655 | dep->endpoint.ops = &dwc3_gadget_ep0_ops; |
1656 | if (!epnum) | 1656 | if (!epnum) |
@@ -1658,7 +1658,7 @@ static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc, | |||
1658 | } else { | 1658 | } else { |
1659 | int ret; | 1659 | int ret; |
1660 | 1660 | ||
1661 | dep->endpoint.maxpacket = 1024; | 1661 | usb_ep_set_maxpacket_limit(&dep->endpoint, 1024); |
1662 | dep->endpoint.max_streams = 15; | 1662 | dep->endpoint.max_streams = 15; |
1663 | dep->endpoint.ops = &dwc3_gadget_ep_ops; | 1663 | dep->endpoint.ops = &dwc3_gadget_ep_ops; |
1664 | list_add_tail(&dep->endpoint.ep_list, | 1664 | list_add_tail(&dep->endpoint.ep_list, |
@@ -2597,6 +2597,12 @@ int dwc3_gadget_init(struct dwc3 *dwc) | |||
2597 | dwc->gadget.name = "dwc3-gadget"; | 2597 | dwc->gadget.name = "dwc3-gadget"; |
2598 | 2598 | ||
2599 | /* | 2599 | /* |
2600 | * Per databook, DWC3 needs buffer size to be aligned to MaxPacketSize | ||
2601 | * on ep out. | ||
2602 | */ | ||
2603 | dwc->gadget.quirk_ep_out_aligned_size = true; | ||
2604 | |||
2605 | /* | ||
2600 | * REVISIT: Here we should clear all pending IRQs to be | 2606 | * REVISIT: Here we should clear all pending IRQs to be |
2601 | * sure we're starting from a well known location. | 2607 | * sure we're starting from a well known location. |
2602 | */ | 2608 | */ |
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index f66d96ad1f51..8154165aa601 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -216,6 +216,13 @@ config USB_FOTG210_UDC | |||
216 | Say "y" to link the driver statically, or "m" to build a | 216 | Say "y" to link the driver statically, or "m" to build a |
217 | dynamically linked module called "fotg210_udc". | 217 | dynamically linked module called "fotg210_udc". |
218 | 218 | ||
219 | config USB_GR_UDC | ||
220 | tristate "Aeroflex Gaisler GRUSBDC USB Peripheral Controller Driver" | ||
221 | depends on HAS_DMA | ||
222 | help | ||
223 | Select this to support Aeroflex Gaisler GRUSBDC cores from the GRLIB | ||
224 | VHDL IP core library. | ||
225 | |||
219 | config USB_OMAP | 226 | config USB_OMAP |
220 | tristate "OMAP USB Device Controller" | 227 | tristate "OMAP USB Device Controller" |
221 | depends on ARCH_OMAP1 | 228 | depends on ARCH_OMAP1 |
@@ -294,11 +301,11 @@ config USB_PXA27X | |||
294 | gadget drivers to also be dynamically linked. | 301 | gadget drivers to also be dynamically linked. |
295 | 302 | ||
296 | config USB_S3C_HSOTG | 303 | config USB_S3C_HSOTG |
297 | tristate "S3C HS/OtG USB Device controller" | 304 | depends on ARM |
298 | depends on S3C_DEV_USB_HSOTG | 305 | tristate "Designware/S3C HS/OtG USB Device controller" |
299 | help | 306 | help |
300 | The Samsung S3C64XX USB2.0 high-speed gadget controller | 307 | The Designware USB2.0 high-speed gadget controller |
301 | integrated into the S3C64XX series SoC. | 308 | integrated into many SoCs. |
302 | 309 | ||
303 | config USB_S3C2410 | 310 | config USB_S3C2410 |
304 | tristate "S3C2410 USB Device Controller" | 311 | tristate "S3C2410 USB Device Controller" |
@@ -512,9 +519,6 @@ config USB_U_SERIAL | |||
512 | config USB_U_ETHER | 519 | config USB_U_ETHER |
513 | tristate | 520 | tristate |
514 | 521 | ||
515 | config USB_U_RNDIS | ||
516 | tristate | ||
517 | |||
518 | config USB_F_SERIAL | 522 | config USB_F_SERIAL |
519 | tristate | 523 | tristate |
520 | 524 | ||
@@ -542,6 +546,9 @@ config USB_F_RNDIS | |||
542 | config USB_F_MASS_STORAGE | 546 | config USB_F_MASS_STORAGE |
543 | tristate | 547 | tristate |
544 | 548 | ||
549 | config USB_F_FS | ||
550 | tristate | ||
551 | |||
545 | choice | 552 | choice |
546 | tristate "USB Gadget Drivers" | 553 | tristate "USB Gadget Drivers" |
547 | default USB_ETH | 554 | default USB_ETH |
@@ -642,7 +649,6 @@ config USB_CONFIGFS_RNDIS | |||
642 | depends on USB_CONFIGFS | 649 | depends on USB_CONFIGFS |
643 | depends on NET | 650 | depends on NET |
644 | select USB_U_ETHER | 651 | select USB_U_ETHER |
645 | select USB_U_RNDIS | ||
646 | select USB_F_RNDIS | 652 | select USB_F_RNDIS |
647 | help | 653 | help |
648 | Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol, | 654 | Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol, |
@@ -690,6 +696,31 @@ config USB_CONFIGFS_MASS_STORAGE | |||
690 | device (in much the same way as the "loop" device driver), | 696 | device (in much the same way as the "loop" device driver), |
691 | specified as a module parameter or sysfs option. | 697 | specified as a module parameter or sysfs option. |
692 | 698 | ||
699 | config USB_CONFIGFS_F_LB_SS | ||
700 | boolean "Loopback and sourcesink function (for testing)" | ||
701 | depends on USB_CONFIGFS | ||
702 | select USB_F_SS_LB | ||
703 | help | ||
704 | Loopback function loops back a configurable number of transfers. | ||
705 | Sourcesink function either sinks and sources bulk data. | ||
706 | It also implements control requests, for "chapter 9" conformance. | ||
707 | Make this be the first driver you try using on top of any new | ||
708 | USB peripheral controller driver. Then you can use host-side | ||
709 | test software, like the "usbtest" driver, to put your hardware | ||
710 | and its driver through a basic set of functional tests. | ||
711 | |||
712 | config USB_CONFIGFS_F_FS | ||
713 | boolean "Function filesystem (FunctionFS)" | ||
714 | depends on USB_CONFIGFS | ||
715 | select USB_F_FS | ||
716 | help | ||
717 | The Function Filesystem (FunctionFS) lets one create USB | ||
718 | composite functions in user space in the same way GadgetFS | ||
719 | lets one create USB gadgets in user space. This allows creation | ||
720 | of composite gadgets such that some of the functions are | ||
721 | implemented in kernel space (for instance Ethernet, serial or | ||
722 | mass storage) and other are implemented in user space. | ||
723 | |||
693 | config USB_ZERO | 724 | config USB_ZERO |
694 | tristate "Gadget Zero (DEVELOPMENT)" | 725 | tristate "Gadget Zero (DEVELOPMENT)" |
695 | select USB_LIBCOMPOSITE | 726 | select USB_LIBCOMPOSITE |
@@ -760,7 +791,6 @@ config USB_ETH | |||
760 | depends on NET | 791 | depends on NET |
761 | select USB_LIBCOMPOSITE | 792 | select USB_LIBCOMPOSITE |
762 | select USB_U_ETHER | 793 | select USB_U_ETHER |
763 | select USB_U_RNDIS | ||
764 | select USB_F_ECM | 794 | select USB_F_ECM |
765 | select USB_F_SUBSET | 795 | select USB_F_SUBSET |
766 | select CRC32 | 796 | select CRC32 |
@@ -864,6 +894,7 @@ config USB_GADGETFS | |||
864 | config USB_FUNCTIONFS | 894 | config USB_FUNCTIONFS |
865 | tristate "Function Filesystem" | 895 | tristate "Function Filesystem" |
866 | select USB_LIBCOMPOSITE | 896 | select USB_LIBCOMPOSITE |
897 | select USB_F_FS | ||
867 | select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) | 898 | select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) |
868 | help | 899 | help |
869 | The Function Filesystem (FunctionFS) lets one create USB | 900 | The Function Filesystem (FunctionFS) lets one create USB |
@@ -883,6 +914,8 @@ config USB_FUNCTIONFS_ETH | |||
883 | bool "Include configuration with CDC ECM (Ethernet)" | 914 | bool "Include configuration with CDC ECM (Ethernet)" |
884 | depends on USB_FUNCTIONFS && NET | 915 | depends on USB_FUNCTIONFS && NET |
885 | select USB_U_ETHER | 916 | select USB_U_ETHER |
917 | select USB_F_ECM | ||
918 | select USB_F_SUBSET | ||
886 | help | 919 | help |
887 | Include a configuration with CDC ECM function (Ethernet) and the | 920 | Include a configuration with CDC ECM function (Ethernet) and the |
888 | Function Filesystem. | 921 | Function Filesystem. |
@@ -891,7 +924,7 @@ config USB_FUNCTIONFS_RNDIS | |||
891 | bool "Include configuration with RNDIS (Ethernet)" | 924 | bool "Include configuration with RNDIS (Ethernet)" |
892 | depends on USB_FUNCTIONFS && NET | 925 | depends on USB_FUNCTIONFS && NET |
893 | select USB_U_ETHER | 926 | select USB_U_ETHER |
894 | select USB_U_RNDIS | 927 | select USB_F_RNDIS |
895 | help | 928 | help |
896 | Include a configuration with RNDIS function (Ethernet) and the Filesystem. | 929 | Include a configuration with RNDIS function (Ethernet) and the Filesystem. |
897 | 930 | ||
@@ -1065,7 +1098,6 @@ config USB_G_MULTI | |||
1065 | config USB_G_MULTI_RNDIS | 1098 | config USB_G_MULTI_RNDIS |
1066 | bool "RNDIS + CDC Serial + Storage configuration" | 1099 | bool "RNDIS + CDC Serial + Storage configuration" |
1067 | depends on USB_G_MULTI | 1100 | depends on USB_G_MULTI |
1068 | select USB_U_RNDIS | ||
1069 | select USB_F_RNDIS | 1101 | select USB_F_RNDIS |
1070 | default y | 1102 | default y |
1071 | help | 1103 | help |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index f1af39603d4d..5f150bc1b4bc 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -7,7 +7,7 @@ ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG | |||
7 | obj-$(CONFIG_USB_GADGET) += udc-core.o | 7 | obj-$(CONFIG_USB_GADGET) += udc-core.o |
8 | obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o | 8 | obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o |
9 | libcomposite-y := usbstring.o config.o epautoconf.o | 9 | libcomposite-y := usbstring.o config.o epautoconf.o |
10 | libcomposite-y += composite.o functions.o configfs.o | 10 | libcomposite-y += composite.o functions.o configfs.o u_f.o |
11 | obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o | 11 | obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o |
12 | obj-$(CONFIG_USB_NET2272) += net2272.o | 12 | obj-$(CONFIG_USB_NET2272) += net2272.o |
13 | obj-$(CONFIG_USB_NET2280) += net2280.o | 13 | obj-$(CONFIG_USB_NET2280) += net2280.o |
@@ -35,6 +35,7 @@ mv_udc-y := mv_udc_core.o | |||
35 | obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o | 35 | obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o |
36 | obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o | 36 | obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o |
37 | obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o | 37 | obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o |
38 | obj-$(CONFIG_USB_GR_UDC) += gr_udc.o | ||
38 | 39 | ||
39 | # USB Functions | 40 | # USB Functions |
40 | usb_f_acm-y := f_acm.o | 41 | usb_f_acm-y := f_acm.o |
@@ -47,8 +48,6 @@ obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o | |||
47 | usb_f_obex-y := f_obex.o | 48 | usb_f_obex-y := f_obex.o |
48 | obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o | 49 | obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o |
49 | obj-$(CONFIG_USB_U_ETHER) += u_ether.o | 50 | obj-$(CONFIG_USB_U_ETHER) += u_ether.o |
50 | u_rndis-y := rndis.o | ||
51 | obj-$(CONFIG_USB_U_RNDIS) += u_rndis.o | ||
52 | usb_f_ncm-y := f_ncm.o | 51 | usb_f_ncm-y := f_ncm.o |
53 | obj-$(CONFIG_USB_F_NCM) += usb_f_ncm.o | 52 | obj-$(CONFIG_USB_F_NCM) += usb_f_ncm.o |
54 | usb_f_ecm-y := f_ecm.o | 53 | usb_f_ecm-y := f_ecm.o |
@@ -59,10 +58,12 @@ usb_f_eem-y := f_eem.o | |||
59 | obj-$(CONFIG_USB_F_EEM) += usb_f_eem.o | 58 | obj-$(CONFIG_USB_F_EEM) += usb_f_eem.o |
60 | usb_f_ecm_subset-y := f_subset.o | 59 | usb_f_ecm_subset-y := f_subset.o |
61 | obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o | 60 | obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o |
62 | usb_f_rndis-y := f_rndis.o | 61 | usb_f_rndis-y := f_rndis.o rndis.o |
63 | obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o | 62 | obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o |
64 | usb_f_mass_storage-y := f_mass_storage.o storage_common.o | 63 | usb_f_mass_storage-y := f_mass_storage.o storage_common.o |
65 | obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o | 64 | obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o |
65 | usb_f_fs-y := f_fs.o | ||
66 | obj-$(CONFIG_USB_F_FS) += usb_f_fs.o | ||
66 | 67 | ||
67 | # | 68 | # |
68 | # USB gadget drivers | 69 | # USB gadget drivers |
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c index 7bfa134fe0e3..a252444cc0a7 100644 --- a/drivers/usb/gadget/acm_ms.c +++ b/drivers/usb/gadget/acm_ms.c | |||
@@ -107,7 +107,7 @@ static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; | |||
107 | */ | 107 | */ |
108 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS | 108 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS |
109 | 109 | ||
110 | #endif /* CONFIG_USB_DEBUG */ | 110 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ |
111 | 111 | ||
112 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); | 112 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); |
113 | 113 | ||
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c index 54a1e2954cea..41b062eb4de0 100644 --- a/drivers/usb/gadget/amd5536udc.c +++ b/drivers/usb/gadget/amd5536udc.c | |||
@@ -40,7 +40,6 @@ | |||
40 | #include <linux/sched.h> | 40 | #include <linux/sched.h> |
41 | #include <linux/slab.h> | 41 | #include <linux/slab.h> |
42 | #include <linux/errno.h> | 42 | #include <linux/errno.h> |
43 | #include <linux/init.h> | ||
44 | #include <linux/timer.h> | 43 | #include <linux/timer.h> |
45 | #include <linux/list.h> | 44 | #include <linux/list.h> |
46 | #include <linux/interrupt.h> | 45 | #include <linux/interrupt.h> |
@@ -446,7 +445,7 @@ static void ep_init(struct udc_regs __iomem *regs, struct udc_ep *ep) | |||
446 | ep->ep.ops = &udc_ep_ops; | 445 | ep->ep.ops = &udc_ep_ops; |
447 | INIT_LIST_HEAD(&ep->queue); | 446 | INIT_LIST_HEAD(&ep->queue); |
448 | 447 | ||
449 | ep->ep.maxpacket = (u16) ~0; | 448 | usb_ep_set_maxpacket_limit(&ep->ep,(u16) ~0); |
450 | /* set NAK */ | 449 | /* set NAK */ |
451 | tmp = readl(&ep->regs->ctl); | 450 | tmp = readl(&ep->regs->ctl); |
452 | tmp |= AMD_BIT(UDC_EPCTL_SNAK); | 451 | tmp |= AMD_BIT(UDC_EPCTL_SNAK); |
@@ -1564,12 +1563,15 @@ static void udc_setup_endpoints(struct udc *dev) | |||
1564 | } | 1563 | } |
1565 | /* EP0 max packet */ | 1564 | /* EP0 max packet */ |
1566 | if (dev->gadget.speed == USB_SPEED_FULL) { | 1565 | if (dev->gadget.speed == USB_SPEED_FULL) { |
1567 | dev->ep[UDC_EP0IN_IX].ep.maxpacket = UDC_FS_EP0IN_MAX_PKT_SIZE; | 1566 | usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0IN_IX].ep, |
1568 | dev->ep[UDC_EP0OUT_IX].ep.maxpacket = | 1567 | UDC_FS_EP0IN_MAX_PKT_SIZE); |
1569 | UDC_FS_EP0OUT_MAX_PKT_SIZE; | 1568 | usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0OUT_IX].ep, |
1569 | UDC_FS_EP0OUT_MAX_PKT_SIZE); | ||
1570 | } else if (dev->gadget.speed == USB_SPEED_HIGH) { | 1570 | } else if (dev->gadget.speed == USB_SPEED_HIGH) { |
1571 | dev->ep[UDC_EP0IN_IX].ep.maxpacket = UDC_EP0IN_MAX_PKT_SIZE; | 1571 | usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0IN_IX].ep, |
1572 | dev->ep[UDC_EP0OUT_IX].ep.maxpacket = UDC_EP0OUT_MAX_PKT_SIZE; | 1572 | UDC_EP0IN_MAX_PKT_SIZE); |
1573 | usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0OUT_IX].ep, | ||
1574 | UDC_EP0OUT_MAX_PKT_SIZE); | ||
1573 | } | 1575 | } |
1574 | 1576 | ||
1575 | /* | 1577 | /* |
@@ -3338,7 +3340,7 @@ static int udc_remote_wakeup(struct udc *dev) | |||
3338 | } | 3340 | } |
3339 | 3341 | ||
3340 | /* PCI device parameters */ | 3342 | /* PCI device parameters */ |
3341 | static DEFINE_PCI_DEVICE_TABLE(pci_id) = { | 3343 | static const struct pci_device_id pci_id[] = { |
3342 | { | 3344 | { |
3343 | PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x2096), | 3345 | PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x2096), |
3344 | .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, | 3346 | .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, |
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 4cc4fd6d1473..cea8c20a1425 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c | |||
@@ -21,7 +21,6 @@ | |||
21 | #include <linux/ioport.h> | 21 | #include <linux/ioport.h> |
22 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
23 | #include <linux/errno.h> | 23 | #include <linux/errno.h> |
24 | #include <linux/init.h> | ||
25 | #include <linux/list.h> | 24 | #include <linux/list.h> |
26 | #include <linux/interrupt.h> | 25 | #include <linux/interrupt.h> |
27 | #include <linux/proc_fs.h> | 26 | #include <linux/proc_fs.h> |
@@ -834,7 +833,7 @@ static void udc_reinit(struct at91_udc *udc) | |||
834 | ep->ep.desc = NULL; | 833 | ep->ep.desc = NULL; |
835 | ep->stopped = 0; | 834 | ep->stopped = 0; |
836 | ep->fifo_bank = 0; | 835 | ep->fifo_bank = 0; |
837 | ep->ep.maxpacket = ep->maxpacket; | 836 | usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); |
838 | ep->creg = (void __iomem *) udc->udp_baseaddr + AT91_UDP_CSR(i); | 837 | ep->creg = (void __iomem *) udc->udp_baseaddr + AT91_UDP_CSR(i); |
839 | /* initialize one queue per endpoint */ | 838 | /* initialize one queue per endpoint */ |
840 | INIT_LIST_HEAD(&ep->queue); | 839 | INIT_LIST_HEAD(&ep->queue); |
@@ -1759,15 +1758,15 @@ static int at91udc_probe(struct platform_device *pdev) | |||
1759 | 1758 | ||
1760 | /* newer chips have more FIFO memory than rm9200 */ | 1759 | /* newer chips have more FIFO memory than rm9200 */ |
1761 | if (cpu_is_at91sam9260() || cpu_is_at91sam9g20()) { | 1760 | if (cpu_is_at91sam9260() || cpu_is_at91sam9g20()) { |
1762 | udc->ep[0].maxpacket = 64; | 1761 | usb_ep_set_maxpacket_limit(&udc->ep[0].ep, 64); |
1763 | udc->ep[3].maxpacket = 64; | 1762 | usb_ep_set_maxpacket_limit(&udc->ep[3].ep, 64); |
1764 | udc->ep[4].maxpacket = 512; | 1763 | usb_ep_set_maxpacket_limit(&udc->ep[4].ep, 512); |
1765 | udc->ep[5].maxpacket = 512; | 1764 | usb_ep_set_maxpacket_limit(&udc->ep[5].ep, 512); |
1766 | } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) { | 1765 | } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) { |
1767 | udc->ep[3].maxpacket = 64; | 1766 | usb_ep_set_maxpacket_limit(&udc->ep[3].ep, 64); |
1768 | } else if (cpu_is_at91sam9263()) { | 1767 | } else if (cpu_is_at91sam9263()) { |
1769 | udc->ep[0].maxpacket = 64; | 1768 | usb_ep_set_maxpacket_limit(&udc->ep[0].ep, 64); |
1770 | udc->ep[3].maxpacket = 64; | 1769 | usb_ep_set_maxpacket_limit(&udc->ep[3].ep, 64); |
1771 | } | 1770 | } |
1772 | 1771 | ||
1773 | udc->udp_baseaddr = ioremap(res->start, resource_size(res)); | 1772 | udc->udp_baseaddr = ioremap(res->start, resource_size(res)); |
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index 2cb52e0438df..52771d4c44bc 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c | |||
@@ -326,7 +326,7 @@ static int vbus_is_present(struct usba_udc *udc) | |||
326 | 326 | ||
327 | #if defined(CONFIG_ARCH_AT91SAM9RL) | 327 | #if defined(CONFIG_ARCH_AT91SAM9RL) |
328 | 328 | ||
329 | #include <mach/at91_pmc.h> | 329 | #include <linux/clk/at91_pmc.h> |
330 | 330 | ||
331 | static void toggle_bias(int is_on) | 331 | static void toggle_bias(int is_on) |
332 | { | 332 | { |
@@ -1012,7 +1012,7 @@ static void nop_release(struct device *dev) | |||
1012 | 1012 | ||
1013 | } | 1013 | } |
1014 | 1014 | ||
1015 | struct usb_gadget usba_gadget_template = { | 1015 | static struct usb_gadget usba_gadget_template = { |
1016 | .ops = &usba_udc_ops, | 1016 | .ops = &usba_udc_ops, |
1017 | .max_speed = USB_SPEED_HIGH, | 1017 | .max_speed = USB_SPEED_HIGH, |
1018 | .name = "atmel_usba_udc", | 1018 | .name = "atmel_usba_udc", |
@@ -1904,7 +1904,7 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev, | |||
1904 | ep->dma_regs = udc->regs + USBA_DMA_BASE(i); | 1904 | ep->dma_regs = udc->regs + USBA_DMA_BASE(i); |
1905 | ep->fifo = udc->fifo + USBA_FIFO_BASE(i); | 1905 | ep->fifo = udc->fifo + USBA_FIFO_BASE(i); |
1906 | ep->ep.ops = &usba_ep_ops; | 1906 | ep->ep.ops = &usba_ep_ops; |
1907 | ep->ep.maxpacket = ep->fifo_size; | 1907 | usb_ep_set_maxpacket_limit(&ep->ep, ep->fifo_size); |
1908 | ep->udc = udc; | 1908 | ep->udc = udc; |
1909 | INIT_LIST_HEAD(&ep->queue); | 1909 | INIT_LIST_HEAD(&ep->queue); |
1910 | 1910 | ||
@@ -1957,7 +1957,8 @@ static struct usba_ep * usba_udc_pdata(struct platform_device *pdev, | |||
1957 | ep->fifo = udc->fifo + USBA_FIFO_BASE(i); | 1957 | ep->fifo = udc->fifo + USBA_FIFO_BASE(i); |
1958 | ep->ep.ops = &usba_ep_ops; | 1958 | ep->ep.ops = &usba_ep_ops; |
1959 | ep->ep.name = pdata->ep[i].name; | 1959 | ep->ep.name = pdata->ep[i].name; |
1960 | ep->fifo_size = ep->ep.maxpacket = pdata->ep[i].fifo_size; | 1960 | ep->fifo_size = pdata->ep[i].fifo_size; |
1961 | usb_ep_set_maxpacket_limit(&ep->ep, ep->fifo_size); | ||
1961 | ep->udc = udc; | 1962 | ep->udc = udc; |
1962 | INIT_LIST_HEAD(&ep->queue); | 1963 | INIT_LIST_HEAD(&ep->queue); |
1963 | ep->nr_banks = pdata->ep[i].nr_banks; | 1964 | ep->nr_banks = pdata->ep[i].nr_banks; |
@@ -1995,14 +1996,12 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
1995 | if (irq < 0) | 1996 | if (irq < 0) |
1996 | return irq; | 1997 | return irq; |
1997 | 1998 | ||
1998 | pclk = clk_get(&pdev->dev, "pclk"); | 1999 | pclk = devm_clk_get(&pdev->dev, "pclk"); |
1999 | if (IS_ERR(pclk)) | 2000 | if (IS_ERR(pclk)) |
2000 | return PTR_ERR(pclk); | 2001 | return PTR_ERR(pclk); |
2001 | hclk = clk_get(&pdev->dev, "hclk"); | 2002 | hclk = devm_clk_get(&pdev->dev, "hclk"); |
2002 | if (IS_ERR(hclk)) { | 2003 | if (IS_ERR(hclk)) |
2003 | ret = PTR_ERR(hclk); | 2004 | return PTR_ERR(hclk); |
2004 | goto err_get_hclk; | ||
2005 | } | ||
2006 | 2005 | ||
2007 | spin_lock_init(&udc->lock); | 2006 | spin_lock_init(&udc->lock); |
2008 | udc->pdev = pdev; | 2007 | udc->pdev = pdev; |
@@ -2011,17 +2010,17 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
2011 | udc->vbus_pin = -ENODEV; | 2010 | udc->vbus_pin = -ENODEV; |
2012 | 2011 | ||
2013 | ret = -ENOMEM; | 2012 | ret = -ENOMEM; |
2014 | udc->regs = ioremap(regs->start, resource_size(regs)); | 2013 | udc->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs)); |
2015 | if (!udc->regs) { | 2014 | if (!udc->regs) { |
2016 | dev_err(&pdev->dev, "Unable to map I/O memory, aborting.\n"); | 2015 | dev_err(&pdev->dev, "Unable to map I/O memory, aborting.\n"); |
2017 | goto err_map_regs; | 2016 | return ret; |
2018 | } | 2017 | } |
2019 | dev_info(&pdev->dev, "MMIO registers at 0x%08lx mapped at %p\n", | 2018 | dev_info(&pdev->dev, "MMIO registers at 0x%08lx mapped at %p\n", |
2020 | (unsigned long)regs->start, udc->regs); | 2019 | (unsigned long)regs->start, udc->regs); |
2021 | udc->fifo = ioremap(fifo->start, resource_size(fifo)); | 2020 | udc->fifo = devm_ioremap(&pdev->dev, fifo->start, resource_size(fifo)); |
2022 | if (!udc->fifo) { | 2021 | if (!udc->fifo) { |
2023 | dev_err(&pdev->dev, "Unable to map FIFO, aborting.\n"); | 2022 | dev_err(&pdev->dev, "Unable to map FIFO, aborting.\n"); |
2024 | goto err_map_fifo; | 2023 | return ret; |
2025 | } | 2024 | } |
2026 | dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n", | 2025 | dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n", |
2027 | (unsigned long)fifo->start, udc->fifo); | 2026 | (unsigned long)fifo->start, udc->fifo); |
@@ -2032,7 +2031,7 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
2032 | ret = clk_prepare_enable(pclk); | 2031 | ret = clk_prepare_enable(pclk); |
2033 | if (ret) { | 2032 | if (ret) { |
2034 | dev_err(&pdev->dev, "Unable to enable pclk, aborting.\n"); | 2033 | dev_err(&pdev->dev, "Unable to enable pclk, aborting.\n"); |
2035 | goto err_clk_enable; | 2034 | return ret; |
2036 | } | 2035 | } |
2037 | toggle_bias(0); | 2036 | toggle_bias(0); |
2038 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); | 2037 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); |
@@ -2043,22 +2042,22 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
2043 | else | 2042 | else |
2044 | udc->usba_ep = usba_udc_pdata(pdev, udc); | 2043 | udc->usba_ep = usba_udc_pdata(pdev, udc); |
2045 | 2044 | ||
2046 | if (IS_ERR(udc->usba_ep)) { | 2045 | if (IS_ERR(udc->usba_ep)) |
2047 | ret = PTR_ERR(udc->usba_ep); | 2046 | return PTR_ERR(udc->usba_ep); |
2048 | goto err_alloc_ep; | ||
2049 | } | ||
2050 | 2047 | ||
2051 | ret = request_irq(irq, usba_udc_irq, 0, "atmel_usba_udc", udc); | 2048 | ret = devm_request_irq(&pdev->dev, irq, usba_udc_irq, 0, |
2049 | "atmel_usba_udc", udc); | ||
2052 | if (ret) { | 2050 | if (ret) { |
2053 | dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n", | 2051 | dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n", |
2054 | irq, ret); | 2052 | irq, ret); |
2055 | goto err_request_irq; | 2053 | return ret; |
2056 | } | 2054 | } |
2057 | udc->irq = irq; | 2055 | udc->irq = irq; |
2058 | 2056 | ||
2059 | if (gpio_is_valid(udc->vbus_pin)) { | 2057 | if (gpio_is_valid(udc->vbus_pin)) { |
2060 | if (!devm_gpio_request(&pdev->dev, udc->vbus_pin, "atmel_usba_udc")) { | 2058 | if (!devm_gpio_request(&pdev->dev, udc->vbus_pin, "atmel_usba_udc")) { |
2061 | ret = request_irq(gpio_to_irq(udc->vbus_pin), | 2059 | ret = devm_request_irq(&pdev->dev, |
2060 | gpio_to_irq(udc->vbus_pin), | ||
2062 | usba_vbus_irq, 0, | 2061 | usba_vbus_irq, 0, |
2063 | "atmel_usba_udc", udc); | 2062 | "atmel_usba_udc", udc); |
2064 | if (ret) { | 2063 | if (ret) { |
@@ -2077,31 +2076,13 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
2077 | 2076 | ||
2078 | ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); | 2077 | ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); |
2079 | if (ret) | 2078 | if (ret) |
2080 | goto err_add_udc; | 2079 | return ret; |
2081 | 2080 | ||
2082 | usba_init_debugfs(udc); | 2081 | usba_init_debugfs(udc); |
2083 | for (i = 1; i < udc->num_ep; i++) | 2082 | for (i = 1; i < udc->num_ep; i++) |
2084 | usba_ep_init_debugfs(udc, &udc->usba_ep[i]); | 2083 | usba_ep_init_debugfs(udc, &udc->usba_ep[i]); |
2085 | 2084 | ||
2086 | return 0; | 2085 | return 0; |
2087 | |||
2088 | err_add_udc: | ||
2089 | if (gpio_is_valid(udc->vbus_pin)) | ||
2090 | free_irq(gpio_to_irq(udc->vbus_pin), udc); | ||
2091 | |||
2092 | free_irq(irq, udc); | ||
2093 | err_request_irq: | ||
2094 | err_alloc_ep: | ||
2095 | err_clk_enable: | ||
2096 | iounmap(udc->fifo); | ||
2097 | err_map_fifo: | ||
2098 | iounmap(udc->regs); | ||
2099 | err_map_regs: | ||
2100 | clk_put(hclk); | ||
2101 | err_get_hclk: | ||
2102 | clk_put(pclk); | ||
2103 | |||
2104 | return ret; | ||
2105 | } | 2086 | } |
2106 | 2087 | ||
2107 | static int __exit usba_udc_remove(struct platform_device *pdev) | 2088 | static int __exit usba_udc_remove(struct platform_device *pdev) |
@@ -2117,16 +2098,6 @@ static int __exit usba_udc_remove(struct platform_device *pdev) | |||
2117 | usba_ep_cleanup_debugfs(&udc->usba_ep[i]); | 2098 | usba_ep_cleanup_debugfs(&udc->usba_ep[i]); |
2118 | usba_cleanup_debugfs(udc); | 2099 | usba_cleanup_debugfs(udc); |
2119 | 2100 | ||
2120 | if (gpio_is_valid(udc->vbus_pin)) { | ||
2121 | free_irq(gpio_to_irq(udc->vbus_pin), udc); | ||
2122 | } | ||
2123 | |||
2124 | free_irq(udc->irq, udc); | ||
2125 | iounmap(udc->fifo); | ||
2126 | iounmap(udc->regs); | ||
2127 | clk_put(udc->hclk); | ||
2128 | clk_put(udc->pclk); | ||
2129 | |||
2130 | return 0; | 2101 | return 0; |
2131 | } | 2102 | } |
2132 | 2103 | ||
diff --git a/drivers/usb/gadget/bcm63xx_udc.c b/drivers/usb/gadget/bcm63xx_udc.c index c58fcf1ebe41..888fbb43b338 100644 --- a/drivers/usb/gadget/bcm63xx_udc.c +++ b/drivers/usb/gadget/bcm63xx_udc.c | |||
@@ -19,7 +19,6 @@ | |||
19 | #include <linux/device.h> | 19 | #include <linux/device.h> |
20 | #include <linux/dma-mapping.h> | 20 | #include <linux/dma-mapping.h> |
21 | #include <linux/errno.h> | 21 | #include <linux/errno.h> |
22 | #include <linux/init.h> | ||
23 | #include <linux/interrupt.h> | 22 | #include <linux/interrupt.h> |
24 | #include <linux/ioport.h> | 23 | #include <linux/ioport.h> |
25 | #include <linux/kconfig.h> | 24 | #include <linux/kconfig.h> |
@@ -549,7 +548,7 @@ static void bcm63xx_ep_setup(struct bcm63xx_udc *udc) | |||
549 | 548 | ||
550 | if (idx < 0) | 549 | if (idx < 0) |
551 | continue; | 550 | continue; |
552 | udc->bep[idx].ep.maxpacket = max_pkt; | 551 | usb_ep_set_maxpacket_limit(&udc->bep[idx].ep, max_pkt); |
553 | 552 | ||
554 | val = (idx << USBD_CSR_EP_LOG_SHIFT) | | 553 | val = (idx << USBD_CSR_EP_LOG_SHIFT) | |
555 | (cfg->dir << USBD_CSR_EP_DIR_SHIFT) | | 554 | (cfg->dir << USBD_CSR_EP_DIR_SHIFT) | |
@@ -943,7 +942,7 @@ static int bcm63xx_init_udc_hw(struct bcm63xx_udc *udc) | |||
943 | bep->ep.ops = &bcm63xx_udc_ep_ops; | 942 | bep->ep.ops = &bcm63xx_udc_ep_ops; |
944 | list_add_tail(&bep->ep.ep_list, &udc->gadget.ep_list); | 943 | list_add_tail(&bep->ep.ep_list, &udc->gadget.ep_list); |
945 | bep->halted = 0; | 944 | bep->halted = 0; |
946 | bep->ep.maxpacket = BCM63XX_MAX_CTRL_PKT; | 945 | usb_ep_set_maxpacket_limit(&bep->ep, BCM63XX_MAX_CTRL_PKT); |
947 | bep->udc = udc; | 946 | bep->udc = udc; |
948 | bep->ep.desc = NULL; | 947 | bep->ep.desc = NULL; |
949 | INIT_LIST_HEAD(&bep->queue); | 948 | INIT_LIST_HEAD(&bep->queue); |
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 2018ba1a2172..d742bed7a5fa 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -1452,8 +1452,22 @@ unknown: | |||
1452 | struct usb_configuration *c; | 1452 | struct usb_configuration *c; |
1453 | 1453 | ||
1454 | c = cdev->config; | 1454 | c = cdev->config; |
1455 | if (c && c->setup) | 1455 | if (!c) |
1456 | goto done; | ||
1457 | |||
1458 | /* try current config's setup */ | ||
1459 | if (c->setup) { | ||
1456 | value = c->setup(c, ctrl); | 1460 | value = c->setup(c, ctrl); |
1461 | goto done; | ||
1462 | } | ||
1463 | |||
1464 | /* try the only function in the current config */ | ||
1465 | if (!list_is_singular(&c->functions)) | ||
1466 | goto done; | ||
1467 | f = list_first_entry(&c->functions, struct usb_function, | ||
1468 | list); | ||
1469 | if (f->setup) | ||
1470 | value = f->setup(f, ctrl); | ||
1457 | } | 1471 | } |
1458 | 1472 | ||
1459 | goto done; | 1473 | goto done; |
@@ -1714,7 +1728,7 @@ composite_resume(struct usb_gadget *gadget) | |||
1714 | { | 1728 | { |
1715 | struct usb_composite_dev *cdev = get_gadget_data(gadget); | 1729 | struct usb_composite_dev *cdev = get_gadget_data(gadget); |
1716 | struct usb_function *f; | 1730 | struct usb_function *f; |
1717 | u8 maxpower; | 1731 | u16 maxpower; |
1718 | 1732 | ||
1719 | /* REVISIT: should we have config level | 1733 | /* REVISIT: should we have config level |
1720 | * suspend/resume callbacks? | 1734 | * suspend/resume callbacks? |
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 25885112fa35..7d1cc01796b6 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c | |||
@@ -4,6 +4,7 @@ | |||
4 | #include <linux/device.h> | 4 | #include <linux/device.h> |
5 | #include <linux/usb/composite.h> | 5 | #include <linux/usb/composite.h> |
6 | #include <linux/usb/gadget_configfs.h> | 6 | #include <linux/usb/gadget_configfs.h> |
7 | #include "configfs.h" | ||
7 | 8 | ||
8 | int check_user_usb_string(const char *name, | 9 | int check_user_usb_string(const char *name, |
9 | struct usb_gadget_strings *stringtab_dev) | 10 | struct usb_gadget_strings *stringtab_dev) |
@@ -564,6 +565,13 @@ static struct config_group *function_make( | |||
564 | usb_put_function_instance(fi); | 565 | usb_put_function_instance(fi); |
565 | return ERR_PTR(ret); | 566 | return ERR_PTR(ret); |
566 | } | 567 | } |
568 | if (fi->set_inst_name) { | ||
569 | ret = fi->set_inst_name(fi, instance_name); | ||
570 | if (ret) { | ||
571 | usb_put_function_instance(fi); | ||
572 | return ERR_PTR(ret); | ||
573 | } | ||
574 | } | ||
567 | 575 | ||
568 | gi = container_of(group, struct gadget_info, functions_group); | 576 | gi = container_of(group, struct gadget_info, functions_group); |
569 | 577 | ||
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 8f4dae310923..8c06430dcc47 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -951,7 +951,7 @@ static void init_dummy_udc_hw(struct dummy *dum) | |||
951 | list_add_tail(&ep->ep.ep_list, &dum->gadget.ep_list); | 951 | list_add_tail(&ep->ep.ep_list, &dum->gadget.ep_list); |
952 | ep->halted = ep->wedged = ep->already_seen = | 952 | ep->halted = ep->wedged = ep->already_seen = |
953 | ep->setup_stage = 0; | 953 | ep->setup_stage = 0; |
954 | ep->ep.maxpacket = ~0; | 954 | usb_ep_set_maxpacket_limit(&ep->ep, ~0); |
955 | ep->ep.max_streams = 16; | 955 | ep->ep.max_streams = 16; |
956 | ep->last_io = jiffies; | 956 | ep->last_io = jiffies; |
957 | ep->gadget = &dum->gadget; | 957 | ep->gadget = &dum->gadget; |
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index a777f7bd11b4..0567cca1465e 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c | |||
@@ -11,7 +11,6 @@ | |||
11 | 11 | ||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/init.h> | ||
15 | #include <linux/types.h> | 14 | #include <linux/types.h> |
16 | #include <linux/device.h> | 15 | #include <linux/device.h> |
17 | 16 | ||
@@ -58,7 +57,7 @@ ep_matches ( | |||
58 | return 0; | 57 | return 0; |
59 | 58 | ||
60 | /* only support ep0 for portable CONTROL traffic */ | 59 | /* only support ep0 for portable CONTROL traffic */ |
61 | type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; | 60 | type = usb_endpoint_type(desc); |
62 | if (USB_ENDPOINT_XFER_CONTROL == type) | 61 | if (USB_ENDPOINT_XFER_CONTROL == type) |
63 | return 0; | 62 | return 0; |
64 | 63 | ||
@@ -129,7 +128,7 @@ ep_matches ( | |||
129 | * and wants to know the maximum possible, provide the info. | 128 | * and wants to know the maximum possible, provide the info. |
130 | */ | 129 | */ |
131 | if (desc->wMaxPacketSize == 0) | 130 | if (desc->wMaxPacketSize == 0) |
132 | desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket); | 131 | desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket_limit); |
133 | 132 | ||
134 | /* endpoint maxpacket size is an input parameter, except for bulk | 133 | /* endpoint maxpacket size is an input parameter, except for bulk |
135 | * where it's an output parameter representing the full speed limit. | 134 | * where it's an output parameter representing the full speed limit. |
@@ -145,7 +144,7 @@ ep_matches ( | |||
145 | 144 | ||
146 | case USB_ENDPOINT_XFER_ISOC: | 145 | case USB_ENDPOINT_XFER_ISOC: |
147 | /* ISO: limit 1023 bytes full speed, 1024 high/super speed */ | 146 | /* ISO: limit 1023 bytes full speed, 1024 high/super speed */ |
148 | if (ep->maxpacket < max) | 147 | if (ep->maxpacket_limit < max) |
149 | return 0; | 148 | return 0; |
150 | if (!gadget_is_dualspeed(gadget) && max > 1023) | 149 | if (!gadget_is_dualspeed(gadget) && max > 1023) |
151 | return 0; | 150 | return 0; |
@@ -178,7 +177,7 @@ ep_matches ( | |||
178 | 177 | ||
179 | /* report (variable) full speed bulk maxpacket */ | 178 | /* report (variable) full speed bulk maxpacket */ |
180 | if ((USB_ENDPOINT_XFER_BULK == type) && !ep_comp) { | 179 | if ((USB_ENDPOINT_XFER_BULK == type) && !ep_comp) { |
181 | int size = ep->maxpacket; | 180 | int size = ep->maxpacket_limit; |
182 | 181 | ||
183 | /* min() doesn't work on bitfields with gcc-3.5 */ | 182 | /* min() doesn't work on bitfields with gcc-3.5 */ |
184 | if (size > 64) | 183 | if (size > 64) |
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c index 8d9e6f7e8f1a..798760fa7e70 100644 --- a/drivers/usb/gadget/f_ecm.c +++ b/drivers/usb/gadget/f_ecm.c | |||
@@ -691,7 +691,6 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) | |||
691 | int status; | 691 | int status; |
692 | struct usb_ep *ep; | 692 | struct usb_ep *ep; |
693 | 693 | ||
694 | #ifndef USBF_ECM_INCLUDED | ||
695 | struct f_ecm_opts *ecm_opts; | 694 | struct f_ecm_opts *ecm_opts; |
696 | 695 | ||
697 | if (!can_support_ecm(cdev->gadget)) | 696 | if (!can_support_ecm(cdev->gadget)) |
@@ -715,7 +714,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) | |||
715 | return status; | 714 | return status; |
716 | ecm_opts->bound = true; | 715 | ecm_opts->bound = true; |
717 | } | 716 | } |
718 | #endif | 717 | |
719 | us = usb_gstrings_attach(cdev, ecm_strings, | 718 | us = usb_gstrings_attach(cdev, ecm_strings, |
720 | ARRAY_SIZE(ecm_string_defs)); | 719 | ARRAY_SIZE(ecm_string_defs)); |
721 | if (IS_ERR(us)) | 720 | if (IS_ERR(us)) |
@@ -834,74 +833,6 @@ fail: | |||
834 | return status; | 833 | return status; |
835 | } | 834 | } |
836 | 835 | ||
837 | #ifdef USBF_ECM_INCLUDED | ||
838 | |||
839 | static void | ||
840 | ecm_old_unbind(struct usb_configuration *c, struct usb_function *f) | ||
841 | { | ||
842 | struct f_ecm *ecm = func_to_ecm(f); | ||
843 | |||
844 | DBG(c->cdev, "ecm unbind\n"); | ||
845 | |||
846 | usb_free_all_descriptors(f); | ||
847 | |||
848 | kfree(ecm->notify_req->buf); | ||
849 | usb_ep_free_request(ecm->notify, ecm->notify_req); | ||
850 | kfree(ecm); | ||
851 | } | ||
852 | |||
853 | /** | ||
854 | * ecm_bind_config - add CDC Ethernet network link to a configuration | ||
855 | * @c: the configuration to support the network link | ||
856 | * @ethaddr: a buffer in which the ethernet address of the host side | ||
857 | * side of the link was recorded | ||
858 | * @dev: eth_dev structure | ||
859 | * Context: single threaded during gadget setup | ||
860 | * | ||
861 | * Returns zero on success, else negative errno. | ||
862 | * | ||
863 | * Caller must have called @gether_setup(). Caller is also responsible | ||
864 | * for calling @gether_cleanup() before module unload. | ||
865 | */ | ||
866 | int | ||
867 | ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
868 | struct eth_dev *dev) | ||
869 | { | ||
870 | struct f_ecm *ecm; | ||
871 | int status; | ||
872 | |||
873 | if (!can_support_ecm(c->cdev->gadget) || !ethaddr) | ||
874 | return -EINVAL; | ||
875 | |||
876 | /* allocate and initialize one new instance */ | ||
877 | ecm = kzalloc(sizeof *ecm, GFP_KERNEL); | ||
878 | if (!ecm) | ||
879 | return -ENOMEM; | ||
880 | |||
881 | /* export host's Ethernet address in CDC format */ | ||
882 | snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr); | ||
883 | ecm_string_defs[1].s = ecm->ethaddr; | ||
884 | |||
885 | ecm->port.ioport = dev; | ||
886 | ecm->port.cdc_filter = DEFAULT_FILTER; | ||
887 | |||
888 | ecm->port.func.name = "cdc_ethernet"; | ||
889 | /* descriptors are per-instance copies */ | ||
890 | ecm->port.func.bind = ecm_bind; | ||
891 | ecm->port.func.unbind = ecm_old_unbind; | ||
892 | ecm->port.func.set_alt = ecm_set_alt; | ||
893 | ecm->port.func.get_alt = ecm_get_alt; | ||
894 | ecm->port.func.setup = ecm_setup; | ||
895 | ecm->port.func.disable = ecm_disable; | ||
896 | |||
897 | status = usb_add_function(c, &ecm->port.func); | ||
898 | if (status) | ||
899 | kfree(ecm); | ||
900 | return status; | ||
901 | } | ||
902 | |||
903 | #else | ||
904 | |||
905 | static inline struct f_ecm_opts *to_f_ecm_opts(struct config_item *item) | 836 | static inline struct f_ecm_opts *to_f_ecm_opts(struct config_item *item) |
906 | { | 837 | { |
907 | return container_of(to_config_group(item), struct f_ecm_opts, | 838 | return container_of(to_config_group(item), struct f_ecm_opts, |
@@ -1040,5 +971,3 @@ static struct usb_function *ecm_alloc(struct usb_function_instance *fi) | |||
1040 | DECLARE_USB_FUNCTION_INIT(ecm, ecm_alloc_inst, ecm_alloc); | 971 | DECLARE_USB_FUNCTION_INIT(ecm, ecm_alloc_inst, ecm_alloc); |
1041 | MODULE_LICENSE("GPL"); | 972 | MODULE_LICENSE("GPL"); |
1042 | MODULE_AUTHOR("David Brownell"); | 973 | MODULE_AUTHOR("David Brownell"); |
1043 | |||
1044 | #endif | ||
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index 241fc873ffa4..306a2b52125c 100644 --- a/drivers/usb/gadget/f_fs.c +++ b/drivers/usb/gadget/f_fs.c | |||
@@ -22,218 +22,42 @@ | |||
22 | #include <linux/pagemap.h> | 22 | #include <linux/pagemap.h> |
23 | #include <linux/export.h> | 23 | #include <linux/export.h> |
24 | #include <linux/hid.h> | 24 | #include <linux/hid.h> |
25 | #include <linux/module.h> | ||
25 | #include <asm/unaligned.h> | 26 | #include <asm/unaligned.h> |
26 | 27 | ||
27 | #include <linux/usb/composite.h> | 28 | #include <linux/usb/composite.h> |
28 | #include <linux/usb/functionfs.h> | 29 | #include <linux/usb/functionfs.h> |
29 | 30 | ||
31 | #include "u_fs.h" | ||
32 | #include "configfs.h" | ||
30 | 33 | ||
31 | #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ | 34 | #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ |
32 | 35 | ||
33 | 36 | /* Variable Length Array Macros **********************************************/ | |
34 | /* Debugging ****************************************************************/ | 37 | #define vla_group(groupname) size_t groupname##__next = 0 |
35 | 38 | #define vla_group_size(groupname) groupname##__next | |
36 | #ifdef VERBOSE_DEBUG | 39 | |
37 | #ifndef pr_vdebug | 40 | #define vla_item(groupname, type, name, n) \ |
38 | # define pr_vdebug pr_debug | 41 | size_t groupname##_##name##__offset = ({ \ |
39 | #endif /* pr_vdebug */ | 42 | size_t align_mask = __alignof__(type) - 1; \ |
40 | # define ffs_dump_mem(prefix, ptr, len) \ | 43 | size_t offset = (groupname##__next + align_mask) & ~align_mask;\ |
41 | print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len) | 44 | size_t size = (n) * sizeof(type); \ |
42 | #else | 45 | groupname##__next = offset + size; \ |
43 | #ifndef pr_vdebug | 46 | offset; \ |
44 | # define pr_vdebug(...) do { } while (0) | 47 | }) |
45 | #endif /* pr_vdebug */ | 48 | |
46 | # define ffs_dump_mem(prefix, ptr, len) do { } while (0) | 49 | #define vla_item_with_sz(groupname, type, name, n) \ |
47 | #endif /* VERBOSE_DEBUG */ | 50 | size_t groupname##_##name##__sz = (n) * sizeof(type); \ |
48 | 51 | size_t groupname##_##name##__offset = ({ \ | |
49 | #define ENTER() pr_vdebug("%s()\n", __func__) | 52 | size_t align_mask = __alignof__(type) - 1; \ |
50 | 53 | size_t offset = (groupname##__next + align_mask) & ~align_mask;\ | |
51 | 54 | size_t size = groupname##_##name##__sz; \ | |
52 | /* The data structure and setup file ****************************************/ | 55 | groupname##__next = offset + size; \ |
53 | 56 | offset; \ | |
54 | enum ffs_state { | 57 | }) |
55 | /* | 58 | |
56 | * Waiting for descriptors and strings. | 59 | #define vla_ptr(ptr, groupname, name) \ |
57 | * | 60 | ((void *) ((char *)ptr + groupname##_##name##__offset)) |
58 | * In this state no open(2), read(2) or write(2) on epfiles | ||
59 | * may succeed (which should not be the problem as there | ||
60 | * should be no such files opened in the first place). | ||
61 | */ | ||
62 | FFS_READ_DESCRIPTORS, | ||
63 | FFS_READ_STRINGS, | ||
64 | |||
65 | /* | ||
66 | * We've got descriptors and strings. We are or have called | ||
67 | * functionfs_ready_callback(). functionfs_bind() may have | ||
68 | * been called but we don't know. | ||
69 | * | ||
70 | * This is the only state in which operations on epfiles may | ||
71 | * succeed. | ||
72 | */ | ||
73 | FFS_ACTIVE, | ||
74 | |||
75 | /* | ||
76 | * All endpoints have been closed. This state is also set if | ||
77 | * we encounter an unrecoverable error. The only | ||
78 | * unrecoverable error is situation when after reading strings | ||
79 | * from user space we fail to initialise epfiles or | ||
80 | * functionfs_ready_callback() returns with error (<0). | ||
81 | * | ||
82 | * In this state no open(2), read(2) or write(2) (both on ep0 | ||
83 | * as well as epfile) may succeed (at this point epfiles are | ||
84 | * unlinked and all closed so this is not a problem; ep0 is | ||
85 | * also closed but ep0 file exists and so open(2) on ep0 must | ||
86 | * fail). | ||
87 | */ | ||
88 | FFS_CLOSING | ||
89 | }; | ||
90 | |||
91 | |||
92 | enum ffs_setup_state { | ||
93 | /* There is no setup request pending. */ | ||
94 | FFS_NO_SETUP, | ||
95 | /* | ||
96 | * User has read events and there was a setup request event | ||
97 | * there. The next read/write on ep0 will handle the | ||
98 | * request. | ||
99 | */ | ||
100 | FFS_SETUP_PENDING, | ||
101 | /* | ||
102 | * There was event pending but before user space handled it | ||
103 | * some other event was introduced which canceled existing | ||
104 | * setup. If this state is set read/write on ep0 return | ||
105 | * -EIDRM. This state is only set when adding event. | ||
106 | */ | ||
107 | FFS_SETUP_CANCELED | ||
108 | }; | ||
109 | |||
110 | |||
111 | |||
112 | struct ffs_epfile; | ||
113 | struct ffs_function; | ||
114 | |||
115 | struct ffs_data { | ||
116 | struct usb_gadget *gadget; | ||
117 | |||
118 | /* | ||
119 | * Protect access read/write operations, only one read/write | ||
120 | * at a time. As a consequence protects ep0req and company. | ||
121 | * While setup request is being processed (queued) this is | ||
122 | * held. | ||
123 | */ | ||
124 | struct mutex mutex; | ||
125 | |||
126 | /* | ||
127 | * Protect access to endpoint related structures (basically | ||
128 | * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for | ||
129 | * endpoint zero. | ||
130 | */ | ||
131 | spinlock_t eps_lock; | ||
132 | |||
133 | /* | ||
134 | * XXX REVISIT do we need our own request? Since we are not | ||
135 | * handling setup requests immediately user space may be so | ||
136 | * slow that another setup will be sent to the gadget but this | ||
137 | * time not to us but another function and then there could be | ||
138 | * a race. Is that the case? Or maybe we can use cdev->req | ||
139 | * after all, maybe we just need some spinlock for that? | ||
140 | */ | ||
141 | struct usb_request *ep0req; /* P: mutex */ | ||
142 | struct completion ep0req_completion; /* P: mutex */ | ||
143 | int ep0req_status; /* P: mutex */ | ||
144 | |||
145 | /* reference counter */ | ||
146 | atomic_t ref; | ||
147 | /* how many files are opened (EP0 and others) */ | ||
148 | atomic_t opened; | ||
149 | |||
150 | /* EP0 state */ | ||
151 | enum ffs_state state; | ||
152 | |||
153 | /* | ||
154 | * Possible transitions: | ||
155 | * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock | ||
156 | * happens only in ep0 read which is P: mutex | ||
157 | * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock | ||
158 | * happens only in ep0 i/o which is P: mutex | ||
159 | * + FFS_SETUP_PENDING -> FFS_SETUP_CANCELED -- P: ev.waitq.lock | ||
160 | * + FFS_SETUP_CANCELED -> FFS_NO_SETUP -- cmpxchg | ||
161 | */ | ||
162 | enum ffs_setup_state setup_state; | ||
163 | |||
164 | #define FFS_SETUP_STATE(ffs) \ | ||
165 | ((enum ffs_setup_state)cmpxchg(&(ffs)->setup_state, \ | ||
166 | FFS_SETUP_CANCELED, FFS_NO_SETUP)) | ||
167 | |||
168 | /* Events & such. */ | ||
169 | struct { | ||
170 | u8 types[4]; | ||
171 | unsigned short count; | ||
172 | /* XXX REVISIT need to update it in some places, or do we? */ | ||
173 | unsigned short can_stall; | ||
174 | struct usb_ctrlrequest setup; | ||
175 | |||
176 | wait_queue_head_t waitq; | ||
177 | } ev; /* the whole structure, P: ev.waitq.lock */ | ||
178 | |||
179 | /* Flags */ | ||
180 | unsigned long flags; | ||
181 | #define FFS_FL_CALL_CLOSED_CALLBACK 0 | ||
182 | #define FFS_FL_BOUND 1 | ||
183 | |||
184 | /* Active function */ | ||
185 | struct ffs_function *func; | ||
186 | |||
187 | /* | ||
188 | * Device name, write once when file system is mounted. | ||
189 | * Intended for user to read if she wants. | ||
190 | */ | ||
191 | const char *dev_name; | ||
192 | /* Private data for our user (ie. gadget). Managed by user. */ | ||
193 | void *private_data; | ||
194 | |||
195 | /* filled by __ffs_data_got_descs() */ | ||
196 | /* | ||
197 | * Real descriptors are 16 bytes after raw_descs (so you need | ||
198 | * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the | ||
199 | * first full speed descriptor). raw_descs_length and | ||
200 | * raw_fs_descs_length do not have those 16 bytes added. | ||
201 | */ | ||
202 | const void *raw_descs; | ||
203 | unsigned raw_descs_length; | ||
204 | unsigned raw_fs_descs_length; | ||
205 | unsigned fs_descs_count; | ||
206 | unsigned hs_descs_count; | ||
207 | |||
208 | unsigned short strings_count; | ||
209 | unsigned short interfaces_count; | ||
210 | unsigned short eps_count; | ||
211 | unsigned short _pad1; | ||
212 | |||
213 | /* filled by __ffs_data_got_strings() */ | ||
214 | /* ids in stringtabs are set in functionfs_bind() */ | ||
215 | const void *raw_strings; | ||
216 | struct usb_gadget_strings **stringtabs; | ||
217 | |||
218 | /* | ||
219 | * File system's super block, write once when file system is | ||
220 | * mounted. | ||
221 | */ | ||
222 | struct super_block *sb; | ||
223 | |||
224 | /* File permissions, written once when fs is mounted */ | ||
225 | struct ffs_file_perms { | ||
226 | umode_t mode; | ||
227 | kuid_t uid; | ||
228 | kgid_t gid; | ||
229 | } file_perms; | ||
230 | |||
231 | /* | ||
232 | * The endpoint files, filled by ffs_epfiles_create(), | ||
233 | * destroyed by ffs_epfiles_destroy(). | ||
234 | */ | ||
235 | struct ffs_epfile *epfiles; | ||
236 | }; | ||
237 | 61 | ||
238 | /* Reference counter handling */ | 62 | /* Reference counter handling */ |
239 | static void ffs_data_get(struct ffs_data *ffs); | 63 | static void ffs_data_get(struct ffs_data *ffs); |
@@ -274,15 +98,12 @@ static struct ffs_function *ffs_func_from_usb(struct usb_function *f) | |||
274 | return container_of(f, struct ffs_function, function); | 98 | return container_of(f, struct ffs_function, function); |
275 | } | 99 | } |
276 | 100 | ||
277 | static void ffs_func_free(struct ffs_function *func); | ||
278 | 101 | ||
279 | static void ffs_func_eps_disable(struct ffs_function *func); | 102 | static void ffs_func_eps_disable(struct ffs_function *func); |
280 | static int __must_check ffs_func_eps_enable(struct ffs_function *func); | 103 | static int __must_check ffs_func_eps_enable(struct ffs_function *func); |
281 | 104 | ||
282 | static int ffs_func_bind(struct usb_configuration *, | 105 | static int ffs_func_bind(struct usb_configuration *, |
283 | struct usb_function *); | 106 | struct usb_function *); |
284 | static void ffs_func_unbind(struct usb_configuration *, | ||
285 | struct usb_function *); | ||
286 | static int ffs_func_set_alt(struct usb_function *, unsigned, unsigned); | 107 | static int ffs_func_set_alt(struct usb_function *, unsigned, unsigned); |
287 | static void ffs_func_disable(struct usb_function *); | 108 | static void ffs_func_disable(struct usb_function *); |
288 | static int ffs_func_setup(struct usb_function *, | 109 | static int ffs_func_setup(struct usb_function *, |
@@ -335,6 +156,17 @@ ffs_sb_create_file(struct super_block *sb, const char *name, void *data, | |||
335 | const struct file_operations *fops, | 156 | const struct file_operations *fops, |
336 | struct dentry **dentry_p); | 157 | struct dentry **dentry_p); |
337 | 158 | ||
159 | /* Devices management *******************************************************/ | ||
160 | |||
161 | DEFINE_MUTEX(ffs_lock); | ||
162 | EXPORT_SYMBOL(ffs_lock); | ||
163 | |||
164 | static struct ffs_dev *ffs_find_dev(const char *name); | ||
165 | static int _ffs_name_dev(struct ffs_dev *dev, const char *name); | ||
166 | static void *ffs_acquire_dev(const char *dev_name); | ||
167 | static void ffs_release_dev(struct ffs_data *ffs_data); | ||
168 | static int ffs_ready(struct ffs_data *ffs); | ||
169 | static void ffs_closed(struct ffs_data *ffs); | ||
338 | 170 | ||
339 | /* Misc helper functions ****************************************************/ | 171 | /* Misc helper functions ****************************************************/ |
340 | 172 | ||
@@ -460,7 +292,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, | |||
460 | ffs->state = FFS_ACTIVE; | 292 | ffs->state = FFS_ACTIVE; |
461 | mutex_unlock(&ffs->mutex); | 293 | mutex_unlock(&ffs->mutex); |
462 | 294 | ||
463 | ret = functionfs_ready_callback(ffs); | 295 | ret = ffs_ready(ffs); |
464 | if (unlikely(ret < 0)) { | 296 | if (unlikely(ret < 0)) { |
465 | ffs->state = FFS_CLOSING; | 297 | ffs->state = FFS_CLOSING; |
466 | return ret; | 298 | return ret; |
@@ -753,78 +585,71 @@ static ssize_t ffs_epfile_io(struct file *file, | |||
753 | char __user *buf, size_t len, int read) | 585 | char __user *buf, size_t len, int read) |
754 | { | 586 | { |
755 | struct ffs_epfile *epfile = file->private_data; | 587 | struct ffs_epfile *epfile = file->private_data; |
588 | struct usb_gadget *gadget = epfile->ffs->gadget; | ||
756 | struct ffs_ep *ep; | 589 | struct ffs_ep *ep; |
757 | char *data = NULL; | 590 | char *data = NULL; |
758 | ssize_t ret; | 591 | ssize_t ret, data_len; |
759 | int halt; | 592 | int halt; |
760 | 593 | ||
761 | goto first_try; | 594 | /* Are we still active? */ |
762 | do { | 595 | if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) { |
763 | spin_unlock_irq(&epfile->ffs->eps_lock); | 596 | ret = -ENODEV; |
764 | mutex_unlock(&epfile->mutex); | 597 | goto error; |
598 | } | ||
765 | 599 | ||
766 | first_try: | 600 | /* Wait for endpoint to be enabled */ |
767 | /* Are we still active? */ | 601 | ep = epfile->ep; |
768 | if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) { | 602 | if (!ep) { |
769 | ret = -ENODEV; | 603 | if (file->f_flags & O_NONBLOCK) { |
604 | ret = -EAGAIN; | ||
770 | goto error; | 605 | goto error; |
771 | } | 606 | } |
772 | 607 | ||
773 | /* Wait for endpoint to be enabled */ | 608 | ret = wait_event_interruptible(epfile->wait, (ep = epfile->ep)); |
774 | ep = epfile->ep; | 609 | if (ret) { |
775 | if (!ep) { | 610 | ret = -EINTR; |
776 | if (file->f_flags & O_NONBLOCK) { | ||
777 | ret = -EAGAIN; | ||
778 | goto error; | ||
779 | } | ||
780 | |||
781 | if (wait_event_interruptible(epfile->wait, | ||
782 | (ep = epfile->ep))) { | ||
783 | ret = -EINTR; | ||
784 | goto error; | ||
785 | } | ||
786 | } | ||
787 | |||
788 | /* Do we halt? */ | ||
789 | halt = !read == !epfile->in; | ||
790 | if (halt && epfile->isoc) { | ||
791 | ret = -EINVAL; | ||
792 | goto error; | 611 | goto error; |
793 | } | 612 | } |
613 | } | ||
794 | 614 | ||
795 | /* Allocate & copy */ | 615 | /* Do we halt? */ |
796 | if (!halt && !data) { | 616 | halt = !read == !epfile->in; |
797 | data = kzalloc(len, GFP_KERNEL); | 617 | if (halt && epfile->isoc) { |
798 | if (unlikely(!data)) | 618 | ret = -EINVAL; |
799 | return -ENOMEM; | 619 | goto error; |
620 | } | ||
800 | 621 | ||
801 | if (!read && | 622 | /* Allocate & copy */ |
802 | unlikely(__copy_from_user(data, buf, len))) { | 623 | if (!halt) { |
803 | ret = -EFAULT; | 624 | /* |
804 | goto error; | 625 | * Controller may require buffer size to be aligned to |
805 | } | 626 | * maxpacketsize of an out endpoint. |
806 | } | 627 | */ |
628 | data_len = read ? usb_ep_align_maybe(gadget, ep->ep, len) : len; | ||
629 | |||
630 | data = kmalloc(data_len, GFP_KERNEL); | ||
631 | if (unlikely(!data)) | ||
632 | return -ENOMEM; | ||
807 | 633 | ||
808 | /* We will be using request */ | 634 | if (!read && unlikely(copy_from_user(data, buf, len))) { |
809 | ret = ffs_mutex_lock(&epfile->mutex, | 635 | ret = -EFAULT; |
810 | file->f_flags & O_NONBLOCK); | ||
811 | if (unlikely(ret)) | ||
812 | goto error; | 636 | goto error; |
637 | } | ||
638 | } | ||
813 | 639 | ||
814 | /* | 640 | /* We will be using request */ |
815 | * We're called from user space, we can use _irq rather then | 641 | ret = ffs_mutex_lock(&epfile->mutex, file->f_flags & O_NONBLOCK); |
816 | * _irqsave | 642 | if (unlikely(ret)) |
817 | */ | 643 | goto error; |
818 | spin_lock_irq(&epfile->ffs->eps_lock); | ||
819 | 644 | ||
820 | /* | 645 | spin_lock_irq(&epfile->ffs->eps_lock); |
821 | * While we were acquiring mutex endpoint got disabled | ||
822 | * or changed? | ||
823 | */ | ||
824 | } while (unlikely(epfile->ep != ep)); | ||
825 | 646 | ||
826 | /* Halt */ | 647 | if (epfile->ep != ep) { |
827 | if (unlikely(halt)) { | 648 | /* In the meantime, endpoint got disabled or changed. */ |
649 | ret = -ESHUTDOWN; | ||
650 | spin_unlock_irq(&epfile->ffs->eps_lock); | ||
651 | } else if (halt) { | ||
652 | /* Halt */ | ||
828 | if (likely(epfile->ep == ep) && !WARN_ON(!ep->ep)) | 653 | if (likely(epfile->ep == ep) && !WARN_ON(!ep->ep)) |
829 | usb_ep_set_halt(ep->ep); | 654 | usb_ep_set_halt(ep->ep); |
830 | spin_unlock_irq(&epfile->ffs->eps_lock); | 655 | spin_unlock_irq(&epfile->ffs->eps_lock); |
@@ -837,7 +662,7 @@ first_try: | |||
837 | req->context = &done; | 662 | req->context = &done; |
838 | req->complete = ffs_epfile_io_complete; | 663 | req->complete = ffs_epfile_io_complete; |
839 | req->buf = data; | 664 | req->buf = data; |
840 | req->length = len; | 665 | req->length = data_len; |
841 | 666 | ||
842 | ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); | 667 | ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); |
843 | 668 | ||
@@ -849,9 +674,17 @@ first_try: | |||
849 | ret = -EINTR; | 674 | ret = -EINTR; |
850 | usb_ep_dequeue(ep->ep, req); | 675 | usb_ep_dequeue(ep->ep, req); |
851 | } else { | 676 | } else { |
677 | /* | ||
678 | * XXX We may end up silently droping data here. | ||
679 | * Since data_len (i.e. req->length) may be bigger | ||
680 | * than len (after being rounded up to maxpacketsize), | ||
681 | * we may end up with more data then user space has | ||
682 | * space for. | ||
683 | */ | ||
852 | ret = ep->status; | 684 | ret = ep->status; |
853 | if (read && ret > 0 && | 685 | if (read && ret > 0 && |
854 | unlikely(copy_to_user(buf, data, ret))) | 686 | unlikely(copy_to_user(buf, data, |
687 | min_t(size_t, ret, len)))) | ||
855 | ret = -EFAULT; | 688 | ret = -EFAULT; |
856 | } | 689 | } |
857 | } | 690 | } |
@@ -1191,7 +1024,7 @@ ffs_fs_mount(struct file_system_type *t, int flags, | |||
1191 | return ERR_PTR(-ENOMEM); | 1024 | return ERR_PTR(-ENOMEM); |
1192 | } | 1025 | } |
1193 | 1026 | ||
1194 | ffs_dev = functionfs_acquire_dev_callback(dev_name); | 1027 | ffs_dev = ffs_acquire_dev(dev_name); |
1195 | if (IS_ERR(ffs_dev)) { | 1028 | if (IS_ERR(ffs_dev)) { |
1196 | ffs_data_put(ffs); | 1029 | ffs_data_put(ffs); |
1197 | return ERR_CAST(ffs_dev); | 1030 | return ERR_CAST(ffs_dev); |
@@ -1201,7 +1034,7 @@ ffs_fs_mount(struct file_system_type *t, int flags, | |||
1201 | 1034 | ||
1202 | rv = mount_nodev(t, flags, &data, ffs_sb_fill); | 1035 | rv = mount_nodev(t, flags, &data, ffs_sb_fill); |
1203 | if (IS_ERR(rv) && data.ffs_data) { | 1036 | if (IS_ERR(rv) && data.ffs_data) { |
1204 | functionfs_release_dev_callback(data.ffs_data); | 1037 | ffs_release_dev(data.ffs_data); |
1205 | ffs_data_put(data.ffs_data); | 1038 | ffs_data_put(data.ffs_data); |
1206 | } | 1039 | } |
1207 | return rv; | 1040 | return rv; |
@@ -1214,7 +1047,7 @@ ffs_fs_kill_sb(struct super_block *sb) | |||
1214 | 1047 | ||
1215 | kill_litter_super(sb); | 1048 | kill_litter_super(sb); |
1216 | if (sb->s_fs_info) { | 1049 | if (sb->s_fs_info) { |
1217 | functionfs_release_dev_callback(sb->s_fs_info); | 1050 | ffs_release_dev(sb->s_fs_info); |
1218 | ffs_data_put(sb->s_fs_info); | 1051 | ffs_data_put(sb->s_fs_info); |
1219 | } | 1052 | } |
1220 | } | 1053 | } |
@@ -1327,7 +1160,7 @@ static void ffs_data_clear(struct ffs_data *ffs) | |||
1327 | ENTER(); | 1160 | ENTER(); |
1328 | 1161 | ||
1329 | if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags)) | 1162 | if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags)) |
1330 | functionfs_closed_callback(ffs); | 1163 | ffs_closed(ffs); |
1331 | 1164 | ||
1332 | BUG_ON(ffs->gadget); | 1165 | BUG_ON(ffs->gadget); |
1333 | 1166 | ||
@@ -1463,71 +1296,6 @@ static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count) | |||
1463 | kfree(epfiles); | 1296 | kfree(epfiles); |
1464 | } | 1297 | } |
1465 | 1298 | ||
1466 | static int functionfs_bind_config(struct usb_composite_dev *cdev, | ||
1467 | struct usb_configuration *c, | ||
1468 | struct ffs_data *ffs) | ||
1469 | { | ||
1470 | struct ffs_function *func; | ||
1471 | int ret; | ||
1472 | |||
1473 | ENTER(); | ||
1474 | |||
1475 | func = kzalloc(sizeof *func, GFP_KERNEL); | ||
1476 | if (unlikely(!func)) | ||
1477 | return -ENOMEM; | ||
1478 | |||
1479 | func->function.name = "Function FS Gadget"; | ||
1480 | func->function.strings = ffs->stringtabs; | ||
1481 | |||
1482 | func->function.bind = ffs_func_bind; | ||
1483 | func->function.unbind = ffs_func_unbind; | ||
1484 | func->function.set_alt = ffs_func_set_alt; | ||
1485 | func->function.disable = ffs_func_disable; | ||
1486 | func->function.setup = ffs_func_setup; | ||
1487 | func->function.suspend = ffs_func_suspend; | ||
1488 | func->function.resume = ffs_func_resume; | ||
1489 | |||
1490 | func->conf = c; | ||
1491 | func->gadget = cdev->gadget; | ||
1492 | func->ffs = ffs; | ||
1493 | ffs_data_get(ffs); | ||
1494 | |||
1495 | ret = usb_add_function(c, &func->function); | ||
1496 | if (unlikely(ret)) | ||
1497 | ffs_func_free(func); | ||
1498 | |||
1499 | return ret; | ||
1500 | } | ||
1501 | |||
1502 | static void ffs_func_free(struct ffs_function *func) | ||
1503 | { | ||
1504 | struct ffs_ep *ep = func->eps; | ||
1505 | unsigned count = func->ffs->eps_count; | ||
1506 | unsigned long flags; | ||
1507 | |||
1508 | ENTER(); | ||
1509 | |||
1510 | /* cleanup after autoconfig */ | ||
1511 | spin_lock_irqsave(&func->ffs->eps_lock, flags); | ||
1512 | do { | ||
1513 | if (ep->ep && ep->req) | ||
1514 | usb_ep_free_request(ep->ep, ep->req); | ||
1515 | ep->req = NULL; | ||
1516 | ++ep; | ||
1517 | } while (--count); | ||
1518 | spin_unlock_irqrestore(&func->ffs->eps_lock, flags); | ||
1519 | |||
1520 | ffs_data_put(func->ffs); | ||
1521 | |||
1522 | kfree(func->eps); | ||
1523 | /* | ||
1524 | * eps and interfaces_nums are allocated in the same chunk so | ||
1525 | * only one free is required. Descriptors are also allocated | ||
1526 | * in the same chunk. | ||
1527 | */ | ||
1528 | |||
1529 | kfree(func); | ||
1530 | } | ||
1531 | 1299 | ||
1532 | static void ffs_func_eps_disable(struct ffs_function *func) | 1300 | static void ffs_func_eps_disable(struct ffs_function *func) |
1533 | { | 1301 | { |
@@ -1901,30 +1669,34 @@ static int __ffs_data_got_strings(struct ffs_data *ffs, | |||
1901 | 1669 | ||
1902 | /* Allocate everything in one chunk so there's less maintenance. */ | 1670 | /* Allocate everything in one chunk so there's less maintenance. */ |
1903 | { | 1671 | { |
1904 | struct { | ||
1905 | struct usb_gadget_strings *stringtabs[lang_count + 1]; | ||
1906 | struct usb_gadget_strings stringtab[lang_count]; | ||
1907 | struct usb_string strings[lang_count*(needed_count+1)]; | ||
1908 | } *d; | ||
1909 | unsigned i = 0; | 1672 | unsigned i = 0; |
1673 | vla_group(d); | ||
1674 | vla_item(d, struct usb_gadget_strings *, stringtabs, | ||
1675 | lang_count + 1); | ||
1676 | vla_item(d, struct usb_gadget_strings, stringtab, lang_count); | ||
1677 | vla_item(d, struct usb_string, strings, | ||
1678 | lang_count*(needed_count+1)); | ||
1679 | |||
1680 | char *vlabuf = kmalloc(vla_group_size(d), GFP_KERNEL); | ||
1910 | 1681 | ||
1911 | d = kmalloc(sizeof *d, GFP_KERNEL); | 1682 | if (unlikely(!vlabuf)) { |
1912 | if (unlikely(!d)) { | ||
1913 | kfree(_data); | 1683 | kfree(_data); |
1914 | return -ENOMEM; | 1684 | return -ENOMEM; |
1915 | } | 1685 | } |
1916 | 1686 | ||
1917 | stringtabs = d->stringtabs; | 1687 | /* Initialize the VLA pointers */ |
1918 | t = d->stringtab; | 1688 | stringtabs = vla_ptr(vlabuf, d, stringtabs); |
1689 | t = vla_ptr(vlabuf, d, stringtab); | ||
1919 | i = lang_count; | 1690 | i = lang_count; |
1920 | do { | 1691 | do { |
1921 | *stringtabs++ = t++; | 1692 | *stringtabs++ = t++; |
1922 | } while (--i); | 1693 | } while (--i); |
1923 | *stringtabs = NULL; | 1694 | *stringtabs = NULL; |
1924 | 1695 | ||
1925 | stringtabs = d->stringtabs; | 1696 | /* stringtabs = vlabuf = d_stringtabs for later kfree */ |
1926 | t = d->stringtab; | 1697 | stringtabs = vla_ptr(vlabuf, d, stringtabs); |
1927 | s = d->strings; | 1698 | t = vla_ptr(vlabuf, d, stringtab); |
1699 | s = vla_ptr(vlabuf, d, strings); | ||
1928 | strings = s; | 1700 | strings = s; |
1929 | } | 1701 | } |
1930 | 1702 | ||
@@ -2187,8 +1959,57 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, | |||
2187 | return 0; | 1959 | return 0; |
2188 | } | 1960 | } |
2189 | 1961 | ||
2190 | static int ffs_func_bind(struct usb_configuration *c, | 1962 | static inline struct f_fs_opts *ffs_do_functionfs_bind(struct usb_function *f, |
2191 | struct usb_function *f) | 1963 | struct usb_configuration *c) |
1964 | { | ||
1965 | struct ffs_function *func = ffs_func_from_usb(f); | ||
1966 | struct f_fs_opts *ffs_opts = | ||
1967 | container_of(f->fi, struct f_fs_opts, func_inst); | ||
1968 | int ret; | ||
1969 | |||
1970 | ENTER(); | ||
1971 | |||
1972 | /* | ||
1973 | * Legacy gadget triggers binding in functionfs_ready_callback, | ||
1974 | * which already uses locking; taking the same lock here would | ||
1975 | * cause a deadlock. | ||
1976 | * | ||
1977 | * Configfs-enabled gadgets however do need ffs_dev_lock. | ||
1978 | */ | ||
1979 | if (!ffs_opts->no_configfs) | ||
1980 | ffs_dev_lock(); | ||
1981 | ret = ffs_opts->dev->desc_ready ? 0 : -ENODEV; | ||
1982 | func->ffs = ffs_opts->dev->ffs_data; | ||
1983 | if (!ffs_opts->no_configfs) | ||
1984 | ffs_dev_unlock(); | ||
1985 | if (ret) | ||
1986 | return ERR_PTR(ret); | ||
1987 | |||
1988 | func->conf = c; | ||
1989 | func->gadget = c->cdev->gadget; | ||
1990 | |||
1991 | ffs_data_get(func->ffs); | ||
1992 | |||
1993 | /* | ||
1994 | * in drivers/usb/gadget/configfs.c:configfs_composite_bind() | ||
1995 | * configurations are bound in sequence with list_for_each_entry, | ||
1996 | * in each configuration its functions are bound in sequence | ||
1997 | * with list_for_each_entry, so we assume no race condition | ||
1998 | * with regard to ffs_opts->bound access | ||
1999 | */ | ||
2000 | if (!ffs_opts->refcnt) { | ||
2001 | ret = functionfs_bind(func->ffs, c->cdev); | ||
2002 | if (ret) | ||
2003 | return ERR_PTR(ret); | ||
2004 | } | ||
2005 | ffs_opts->refcnt++; | ||
2006 | func->function.strings = func->ffs->stringtabs; | ||
2007 | |||
2008 | return ffs_opts; | ||
2009 | } | ||
2010 | |||
2011 | static int _ffs_func_bind(struct usb_configuration *c, | ||
2012 | struct usb_function *f) | ||
2192 | { | 2013 | { |
2193 | struct ffs_function *func = ffs_func_from_usb(f); | 2014 | struct ffs_function *func = ffs_func_from_usb(f); |
2194 | struct ffs_data *ffs = func->ffs; | 2015 | struct ffs_data *ffs = func->ffs; |
@@ -2200,16 +2021,16 @@ static int ffs_func_bind(struct usb_configuration *c, | |||
2200 | int ret; | 2021 | int ret; |
2201 | 2022 | ||
2202 | /* Make it a single chunk, less management later on */ | 2023 | /* Make it a single chunk, less management later on */ |
2203 | struct { | 2024 | vla_group(d); |
2204 | struct ffs_ep eps[ffs->eps_count]; | 2025 | vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); |
2205 | struct usb_descriptor_header | 2026 | vla_item_with_sz(d, struct usb_descriptor_header *, fs_descs, |
2206 | *fs_descs[full ? ffs->fs_descs_count + 1 : 0]; | 2027 | full ? ffs->fs_descs_count + 1 : 0); |
2207 | struct usb_descriptor_header | 2028 | vla_item_with_sz(d, struct usb_descriptor_header *, hs_descs, |
2208 | *hs_descs[high ? ffs->hs_descs_count + 1 : 0]; | 2029 | high ? ffs->hs_descs_count + 1 : 0); |
2209 | short inums[ffs->interfaces_count]; | 2030 | vla_item_with_sz(d, short, inums, ffs->interfaces_count); |
2210 | char raw_descs[high ? ffs->raw_descs_length | 2031 | vla_item_with_sz(d, char, raw_descs, |
2211 | : ffs->raw_fs_descs_length]; | 2032 | high ? ffs->raw_descs_length : ffs->raw_fs_descs_length); |
2212 | } *data; | 2033 | char *vlabuf; |
2213 | 2034 | ||
2214 | ENTER(); | 2035 | ENTER(); |
2215 | 2036 | ||
@@ -2217,21 +2038,28 @@ static int ffs_func_bind(struct usb_configuration *c, | |||
2217 | if (unlikely(!(full | high))) | 2038 | if (unlikely(!(full | high))) |
2218 | return -ENOTSUPP; | 2039 | return -ENOTSUPP; |
2219 | 2040 | ||
2220 | /* Allocate */ | 2041 | /* Allocate a single chunk, less management later on */ |
2221 | data = kmalloc(sizeof *data, GFP_KERNEL); | 2042 | vlabuf = kmalloc(vla_group_size(d), GFP_KERNEL); |
2222 | if (unlikely(!data)) | 2043 | if (unlikely(!vlabuf)) |
2223 | return -ENOMEM; | 2044 | return -ENOMEM; |
2224 | 2045 | ||
2225 | /* Zero */ | 2046 | /* Zero */ |
2226 | memset(data->eps, 0, sizeof data->eps); | 2047 | memset(vla_ptr(vlabuf, d, eps), 0, d_eps__sz); |
2227 | memcpy(data->raw_descs, ffs->raw_descs + 16, sizeof data->raw_descs); | 2048 | memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs + 16, |
2228 | memset(data->inums, 0xff, sizeof data->inums); | 2049 | d_raw_descs__sz); |
2229 | for (ret = ffs->eps_count; ret; --ret) | 2050 | memset(vla_ptr(vlabuf, d, inums), 0xff, d_inums__sz); |
2230 | data->eps[ret].num = -1; | 2051 | for (ret = ffs->eps_count; ret; --ret) { |
2052 | struct ffs_ep *ptr; | ||
2053 | |||
2054 | ptr = vla_ptr(vlabuf, d, eps); | ||
2055 | ptr[ret].num = -1; | ||
2056 | } | ||
2231 | 2057 | ||
2232 | /* Save pointers */ | 2058 | /* Save pointers |
2233 | func->eps = data->eps; | 2059 | * d_eps == vlabuf, func->eps used to kfree vlabuf later |
2234 | func->interfaces_nums = data->inums; | 2060 | */ |
2061 | func->eps = vla_ptr(vlabuf, d, eps); | ||
2062 | func->interfaces_nums = vla_ptr(vlabuf, d, inums); | ||
2235 | 2063 | ||
2236 | /* | 2064 | /* |
2237 | * Go through all the endpoint descriptors and allocate | 2065 | * Go through all the endpoint descriptors and allocate |
@@ -2239,10 +2067,10 @@ static int ffs_func_bind(struct usb_configuration *c, | |||
2239 | * numbers without worrying that it may be described later on. | 2067 | * numbers without worrying that it may be described later on. |
2240 | */ | 2068 | */ |
2241 | if (likely(full)) { | 2069 | if (likely(full)) { |
2242 | func->function.fs_descriptors = data->fs_descs; | 2070 | func->function.fs_descriptors = vla_ptr(vlabuf, d, fs_descs); |
2243 | ret = ffs_do_descs(ffs->fs_descs_count, | 2071 | ret = ffs_do_descs(ffs->fs_descs_count, |
2244 | data->raw_descs, | 2072 | vla_ptr(vlabuf, d, raw_descs), |
2245 | sizeof data->raw_descs, | 2073 | d_raw_descs__sz, |
2246 | __ffs_func_bind_do_descs, func); | 2074 | __ffs_func_bind_do_descs, func); |
2247 | if (unlikely(ret < 0)) | 2075 | if (unlikely(ret < 0)) |
2248 | goto error; | 2076 | goto error; |
@@ -2251,10 +2079,10 @@ static int ffs_func_bind(struct usb_configuration *c, | |||
2251 | } | 2079 | } |
2252 | 2080 | ||
2253 | if (likely(high)) { | 2081 | if (likely(high)) { |
2254 | func->function.hs_descriptors = data->hs_descs; | 2082 | func->function.hs_descriptors = vla_ptr(vlabuf, d, hs_descs); |
2255 | ret = ffs_do_descs(ffs->hs_descs_count, | 2083 | ret = ffs_do_descs(ffs->hs_descs_count, |
2256 | data->raw_descs + ret, | 2084 | vla_ptr(vlabuf, d, raw_descs) + ret, |
2257 | (sizeof data->raw_descs) - ret, | 2085 | d_raw_descs__sz - ret, |
2258 | __ffs_func_bind_do_descs, func); | 2086 | __ffs_func_bind_do_descs, func); |
2259 | if (unlikely(ret < 0)) | 2087 | if (unlikely(ret < 0)) |
2260 | goto error; | 2088 | goto error; |
@@ -2267,7 +2095,7 @@ static int ffs_func_bind(struct usb_configuration *c, | |||
2267 | */ | 2095 | */ |
2268 | ret = ffs_do_descs(ffs->fs_descs_count + | 2096 | ret = ffs_do_descs(ffs->fs_descs_count + |
2269 | (high ? ffs->hs_descs_count : 0), | 2097 | (high ? ffs->hs_descs_count : 0), |
2270 | data->raw_descs, sizeof data->raw_descs, | 2098 | vla_ptr(vlabuf, d, raw_descs), d_raw_descs__sz, |
2271 | __ffs_func_bind_do_nums, func); | 2099 | __ffs_func_bind_do_nums, func); |
2272 | if (unlikely(ret < 0)) | 2100 | if (unlikely(ret < 0)) |
2273 | goto error; | 2101 | goto error; |
@@ -2281,26 +2109,19 @@ error: | |||
2281 | return ret; | 2109 | return ret; |
2282 | } | 2110 | } |
2283 | 2111 | ||
2284 | 2112 | static int ffs_func_bind(struct usb_configuration *c, | |
2285 | /* Other USB function hooks *************************************************/ | 2113 | struct usb_function *f) |
2286 | |||
2287 | static void ffs_func_unbind(struct usb_configuration *c, | ||
2288 | struct usb_function *f) | ||
2289 | { | 2114 | { |
2290 | struct ffs_function *func = ffs_func_from_usb(f); | 2115 | struct f_fs_opts *ffs_opts = ffs_do_functionfs_bind(f, c); |
2291 | struct ffs_data *ffs = func->ffs; | ||
2292 | 2116 | ||
2293 | ENTER(); | 2117 | if (IS_ERR(ffs_opts)) |
2118 | return PTR_ERR(ffs_opts); | ||
2294 | 2119 | ||
2295 | if (ffs->func == func) { | 2120 | return _ffs_func_bind(c, f); |
2296 | ffs_func_eps_disable(func); | 2121 | } |
2297 | ffs->func = NULL; | ||
2298 | } | ||
2299 | 2122 | ||
2300 | ffs_event_add(ffs, FUNCTIONFS_UNBIND); | ||
2301 | 2123 | ||
2302 | ffs_func_free(func); | 2124 | /* Other USB function hooks *************************************************/ |
2303 | } | ||
2304 | 2125 | ||
2305 | static int ffs_func_set_alt(struct usb_function *f, | 2126 | static int ffs_func_set_alt(struct usb_function *f, |
2306 | unsigned interface, unsigned alt) | 2127 | unsigned interface, unsigned alt) |
@@ -2428,6 +2249,411 @@ static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf) | |||
2428 | } | 2249 | } |
2429 | 2250 | ||
2430 | 2251 | ||
2252 | /* Devices management *******************************************************/ | ||
2253 | |||
2254 | static LIST_HEAD(ffs_devices); | ||
2255 | |||
2256 | static struct ffs_dev *_ffs_find_dev(const char *name) | ||
2257 | { | ||
2258 | struct ffs_dev *dev; | ||
2259 | |||
2260 | list_for_each_entry(dev, &ffs_devices, entry) { | ||
2261 | if (!dev->name || !name) | ||
2262 | continue; | ||
2263 | if (strcmp(dev->name, name) == 0) | ||
2264 | return dev; | ||
2265 | } | ||
2266 | |||
2267 | return NULL; | ||
2268 | } | ||
2269 | |||
2270 | /* | ||
2271 | * ffs_lock must be taken by the caller of this function | ||
2272 | */ | ||
2273 | static struct ffs_dev *ffs_get_single_dev(void) | ||
2274 | { | ||
2275 | struct ffs_dev *dev; | ||
2276 | |||
2277 | if (list_is_singular(&ffs_devices)) { | ||
2278 | dev = list_first_entry(&ffs_devices, struct ffs_dev, entry); | ||
2279 | if (dev->single) | ||
2280 | return dev; | ||
2281 | } | ||
2282 | |||
2283 | return NULL; | ||
2284 | } | ||
2285 | |||
2286 | /* | ||
2287 | * ffs_lock must be taken by the caller of this function | ||
2288 | */ | ||
2289 | static struct ffs_dev *ffs_find_dev(const char *name) | ||
2290 | { | ||
2291 | struct ffs_dev *dev; | ||
2292 | |||
2293 | dev = ffs_get_single_dev(); | ||
2294 | if (dev) | ||
2295 | return dev; | ||
2296 | |||
2297 | return _ffs_find_dev(name); | ||
2298 | } | ||
2299 | |||
2300 | /* Configfs support *********************************************************/ | ||
2301 | |||
2302 | static inline struct f_fs_opts *to_ffs_opts(struct config_item *item) | ||
2303 | { | ||
2304 | return container_of(to_config_group(item), struct f_fs_opts, | ||
2305 | func_inst.group); | ||
2306 | } | ||
2307 | |||
2308 | static void ffs_attr_release(struct config_item *item) | ||
2309 | { | ||
2310 | struct f_fs_opts *opts = to_ffs_opts(item); | ||
2311 | |||
2312 | usb_put_function_instance(&opts->func_inst); | ||
2313 | } | ||
2314 | |||
2315 | static struct configfs_item_operations ffs_item_ops = { | ||
2316 | .release = ffs_attr_release, | ||
2317 | }; | ||
2318 | |||
2319 | static struct config_item_type ffs_func_type = { | ||
2320 | .ct_item_ops = &ffs_item_ops, | ||
2321 | .ct_owner = THIS_MODULE, | ||
2322 | }; | ||
2323 | |||
2324 | |||
2325 | /* Function registration interface ******************************************/ | ||
2326 | |||
2327 | static void ffs_free_inst(struct usb_function_instance *f) | ||
2328 | { | ||
2329 | struct f_fs_opts *opts; | ||
2330 | |||
2331 | opts = to_f_fs_opts(f); | ||
2332 | ffs_dev_lock(); | ||
2333 | ffs_free_dev(opts->dev); | ||
2334 | ffs_dev_unlock(); | ||
2335 | kfree(opts); | ||
2336 | } | ||
2337 | |||
2338 | #define MAX_INST_NAME_LEN 40 | ||
2339 | |||
2340 | static int ffs_set_inst_name(struct usb_function_instance *fi, const char *name) | ||
2341 | { | ||
2342 | struct f_fs_opts *opts; | ||
2343 | char *ptr; | ||
2344 | const char *tmp; | ||
2345 | int name_len, ret; | ||
2346 | |||
2347 | name_len = strlen(name) + 1; | ||
2348 | if (name_len > MAX_INST_NAME_LEN) | ||
2349 | return -ENAMETOOLONG; | ||
2350 | |||
2351 | ptr = kstrndup(name, name_len, GFP_KERNEL); | ||
2352 | if (!ptr) | ||
2353 | return -ENOMEM; | ||
2354 | |||
2355 | opts = to_f_fs_opts(fi); | ||
2356 | tmp = NULL; | ||
2357 | |||
2358 | ffs_dev_lock(); | ||
2359 | |||
2360 | tmp = opts->dev->name_allocated ? opts->dev->name : NULL; | ||
2361 | ret = _ffs_name_dev(opts->dev, ptr); | ||
2362 | if (ret) { | ||
2363 | kfree(ptr); | ||
2364 | ffs_dev_unlock(); | ||
2365 | return ret; | ||
2366 | } | ||
2367 | opts->dev->name_allocated = true; | ||
2368 | |||
2369 | ffs_dev_unlock(); | ||
2370 | |||
2371 | kfree(tmp); | ||
2372 | |||
2373 | return 0; | ||
2374 | } | ||
2375 | |||
2376 | static struct usb_function_instance *ffs_alloc_inst(void) | ||
2377 | { | ||
2378 | struct f_fs_opts *opts; | ||
2379 | struct ffs_dev *dev; | ||
2380 | |||
2381 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | ||
2382 | if (!opts) | ||
2383 | return ERR_PTR(-ENOMEM); | ||
2384 | |||
2385 | opts->func_inst.set_inst_name = ffs_set_inst_name; | ||
2386 | opts->func_inst.free_func_inst = ffs_free_inst; | ||
2387 | ffs_dev_lock(); | ||
2388 | dev = ffs_alloc_dev(); | ||
2389 | ffs_dev_unlock(); | ||
2390 | if (IS_ERR(dev)) { | ||
2391 | kfree(opts); | ||
2392 | return ERR_CAST(dev); | ||
2393 | } | ||
2394 | opts->dev = dev; | ||
2395 | dev->opts = opts; | ||
2396 | |||
2397 | config_group_init_type_name(&opts->func_inst.group, "", | ||
2398 | &ffs_func_type); | ||
2399 | return &opts->func_inst; | ||
2400 | } | ||
2401 | |||
2402 | static void ffs_free(struct usb_function *f) | ||
2403 | { | ||
2404 | kfree(ffs_func_from_usb(f)); | ||
2405 | } | ||
2406 | |||
2407 | static void ffs_func_unbind(struct usb_configuration *c, | ||
2408 | struct usb_function *f) | ||
2409 | { | ||
2410 | struct ffs_function *func = ffs_func_from_usb(f); | ||
2411 | struct ffs_data *ffs = func->ffs; | ||
2412 | struct f_fs_opts *opts = | ||
2413 | container_of(f->fi, struct f_fs_opts, func_inst); | ||
2414 | struct ffs_ep *ep = func->eps; | ||
2415 | unsigned count = ffs->eps_count; | ||
2416 | unsigned long flags; | ||
2417 | |||
2418 | ENTER(); | ||
2419 | if (ffs->func == func) { | ||
2420 | ffs_func_eps_disable(func); | ||
2421 | ffs->func = NULL; | ||
2422 | } | ||
2423 | |||
2424 | if (!--opts->refcnt) | ||
2425 | functionfs_unbind(ffs); | ||
2426 | |||
2427 | /* cleanup after autoconfig */ | ||
2428 | spin_lock_irqsave(&func->ffs->eps_lock, flags); | ||
2429 | do { | ||
2430 | if (ep->ep && ep->req) | ||
2431 | usb_ep_free_request(ep->ep, ep->req); | ||
2432 | ep->req = NULL; | ||
2433 | ++ep; | ||
2434 | } while (--count); | ||
2435 | spin_unlock_irqrestore(&func->ffs->eps_lock, flags); | ||
2436 | kfree(func->eps); | ||
2437 | func->eps = NULL; | ||
2438 | /* | ||
2439 | * eps, descriptors and interfaces_nums are allocated in the | ||
2440 | * same chunk so only one free is required. | ||
2441 | */ | ||
2442 | func->function.fs_descriptors = NULL; | ||
2443 | func->function.hs_descriptors = NULL; | ||
2444 | func->interfaces_nums = NULL; | ||
2445 | |||
2446 | ffs_event_add(ffs, FUNCTIONFS_UNBIND); | ||
2447 | } | ||
2448 | |||
2449 | static struct usb_function *ffs_alloc(struct usb_function_instance *fi) | ||
2450 | { | ||
2451 | struct ffs_function *func; | ||
2452 | |||
2453 | ENTER(); | ||
2454 | |||
2455 | func = kzalloc(sizeof(*func), GFP_KERNEL); | ||
2456 | if (unlikely(!func)) | ||
2457 | return ERR_PTR(-ENOMEM); | ||
2458 | |||
2459 | func->function.name = "Function FS Gadget"; | ||
2460 | |||
2461 | func->function.bind = ffs_func_bind; | ||
2462 | func->function.unbind = ffs_func_unbind; | ||
2463 | func->function.set_alt = ffs_func_set_alt; | ||
2464 | func->function.disable = ffs_func_disable; | ||
2465 | func->function.setup = ffs_func_setup; | ||
2466 | func->function.suspend = ffs_func_suspend; | ||
2467 | func->function.resume = ffs_func_resume; | ||
2468 | func->function.free_func = ffs_free; | ||
2469 | |||
2470 | return &func->function; | ||
2471 | } | ||
2472 | |||
2473 | /* | ||
2474 | * ffs_lock must be taken by the caller of this function | ||
2475 | */ | ||
2476 | struct ffs_dev *ffs_alloc_dev(void) | ||
2477 | { | ||
2478 | struct ffs_dev *dev; | ||
2479 | int ret; | ||
2480 | |||
2481 | if (ffs_get_single_dev()) | ||
2482 | return ERR_PTR(-EBUSY); | ||
2483 | |||
2484 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
2485 | if (!dev) | ||
2486 | return ERR_PTR(-ENOMEM); | ||
2487 | |||
2488 | if (list_empty(&ffs_devices)) { | ||
2489 | ret = functionfs_init(); | ||
2490 | if (ret) { | ||
2491 | kfree(dev); | ||
2492 | return ERR_PTR(ret); | ||
2493 | } | ||
2494 | } | ||
2495 | |||
2496 | list_add(&dev->entry, &ffs_devices); | ||
2497 | |||
2498 | return dev; | ||
2499 | } | ||
2500 | |||
2501 | /* | ||
2502 | * ffs_lock must be taken by the caller of this function | ||
2503 | * The caller is responsible for "name" being available whenever f_fs needs it | ||
2504 | */ | ||
2505 | static int _ffs_name_dev(struct ffs_dev *dev, const char *name) | ||
2506 | { | ||
2507 | struct ffs_dev *existing; | ||
2508 | |||
2509 | existing = _ffs_find_dev(name); | ||
2510 | if (existing) | ||
2511 | return -EBUSY; | ||
2512 | |||
2513 | dev->name = name; | ||
2514 | |||
2515 | return 0; | ||
2516 | } | ||
2517 | |||
2518 | /* | ||
2519 | * The caller is responsible for "name" being available whenever f_fs needs it | ||
2520 | */ | ||
2521 | int ffs_name_dev(struct ffs_dev *dev, const char *name) | ||
2522 | { | ||
2523 | int ret; | ||
2524 | |||
2525 | ffs_dev_lock(); | ||
2526 | ret = _ffs_name_dev(dev, name); | ||
2527 | ffs_dev_unlock(); | ||
2528 | |||
2529 | return ret; | ||
2530 | } | ||
2531 | EXPORT_SYMBOL(ffs_name_dev); | ||
2532 | |||
2533 | int ffs_single_dev(struct ffs_dev *dev) | ||
2534 | { | ||
2535 | int ret; | ||
2536 | |||
2537 | ret = 0; | ||
2538 | ffs_dev_lock(); | ||
2539 | |||
2540 | if (!list_is_singular(&ffs_devices)) | ||
2541 | ret = -EBUSY; | ||
2542 | else | ||
2543 | dev->single = true; | ||
2544 | |||
2545 | ffs_dev_unlock(); | ||
2546 | return ret; | ||
2547 | } | ||
2548 | EXPORT_SYMBOL(ffs_single_dev); | ||
2549 | |||
2550 | /* | ||
2551 | * ffs_lock must be taken by the caller of this function | ||
2552 | */ | ||
2553 | void ffs_free_dev(struct ffs_dev *dev) | ||
2554 | { | ||
2555 | list_del(&dev->entry); | ||
2556 | if (dev->name_allocated) | ||
2557 | kfree(dev->name); | ||
2558 | kfree(dev); | ||
2559 | if (list_empty(&ffs_devices)) | ||
2560 | functionfs_cleanup(); | ||
2561 | } | ||
2562 | |||
2563 | static void *ffs_acquire_dev(const char *dev_name) | ||
2564 | { | ||
2565 | struct ffs_dev *ffs_dev; | ||
2566 | |||
2567 | ENTER(); | ||
2568 | ffs_dev_lock(); | ||
2569 | |||
2570 | ffs_dev = ffs_find_dev(dev_name); | ||
2571 | if (!ffs_dev) | ||
2572 | ffs_dev = ERR_PTR(-ENODEV); | ||
2573 | else if (ffs_dev->mounted) | ||
2574 | ffs_dev = ERR_PTR(-EBUSY); | ||
2575 | else if (ffs_dev->ffs_acquire_dev_callback && | ||
2576 | ffs_dev->ffs_acquire_dev_callback(ffs_dev)) | ||
2577 | ffs_dev = ERR_PTR(-ENODEV); | ||
2578 | else | ||
2579 | ffs_dev->mounted = true; | ||
2580 | |||
2581 | ffs_dev_unlock(); | ||
2582 | return ffs_dev; | ||
2583 | } | ||
2584 | |||
2585 | static void ffs_release_dev(struct ffs_data *ffs_data) | ||
2586 | { | ||
2587 | struct ffs_dev *ffs_dev; | ||
2588 | |||
2589 | ENTER(); | ||
2590 | ffs_dev_lock(); | ||
2591 | |||
2592 | ffs_dev = ffs_data->private_data; | ||
2593 | if (ffs_dev) | ||
2594 | ffs_dev->mounted = false; | ||
2595 | |||
2596 | if (ffs_dev->ffs_release_dev_callback) | ||
2597 | ffs_dev->ffs_release_dev_callback(ffs_dev); | ||
2598 | |||
2599 | ffs_dev_unlock(); | ||
2600 | } | ||
2601 | |||
2602 | static int ffs_ready(struct ffs_data *ffs) | ||
2603 | { | ||
2604 | struct ffs_dev *ffs_obj; | ||
2605 | int ret = 0; | ||
2606 | |||
2607 | ENTER(); | ||
2608 | ffs_dev_lock(); | ||
2609 | |||
2610 | ffs_obj = ffs->private_data; | ||
2611 | if (!ffs_obj) { | ||
2612 | ret = -EINVAL; | ||
2613 | goto done; | ||
2614 | } | ||
2615 | if (WARN_ON(ffs_obj->desc_ready)) { | ||
2616 | ret = -EBUSY; | ||
2617 | goto done; | ||
2618 | } | ||
2619 | |||
2620 | ffs_obj->desc_ready = true; | ||
2621 | ffs_obj->ffs_data = ffs; | ||
2622 | |||
2623 | if (ffs_obj->ffs_ready_callback) | ||
2624 | ret = ffs_obj->ffs_ready_callback(ffs); | ||
2625 | |||
2626 | done: | ||
2627 | ffs_dev_unlock(); | ||
2628 | return ret; | ||
2629 | } | ||
2630 | |||
2631 | static void ffs_closed(struct ffs_data *ffs) | ||
2632 | { | ||
2633 | struct ffs_dev *ffs_obj; | ||
2634 | |||
2635 | ENTER(); | ||
2636 | ffs_dev_lock(); | ||
2637 | |||
2638 | ffs_obj = ffs->private_data; | ||
2639 | if (!ffs_obj) | ||
2640 | goto done; | ||
2641 | |||
2642 | ffs_obj->desc_ready = false; | ||
2643 | |||
2644 | if (ffs_obj->ffs_closed_callback) | ||
2645 | ffs_obj->ffs_closed_callback(ffs); | ||
2646 | |||
2647 | if (!ffs_obj->opts || ffs_obj->opts->no_configfs | ||
2648 | || !ffs_obj->opts->func_inst.group.cg_item.ci_parent) | ||
2649 | goto done; | ||
2650 | |||
2651 | unregister_gadget_item(ffs_obj->opts-> | ||
2652 | func_inst.group.cg_item.ci_parent->ci_parent); | ||
2653 | done: | ||
2654 | ffs_dev_unlock(); | ||
2655 | } | ||
2656 | |||
2431 | /* Misc helper functions ****************************************************/ | 2657 | /* Misc helper functions ****************************************************/ |
2432 | 2658 | ||
2433 | static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock) | 2659 | static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock) |
@@ -2458,3 +2684,7 @@ static char *ffs_prepare_buffer(const char __user *buf, size_t len) | |||
2458 | 2684 | ||
2459 | return data; | 2685 | return data; |
2460 | } | 2686 | } |
2687 | |||
2688 | DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc); | ||
2689 | MODULE_LICENSE("GPL"); | ||
2690 | MODULE_AUTHOR("Michal Nazarewicz"); | ||
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c index 6e69a8e8d22a..a95290a1289f 100644 --- a/drivers/usb/gadget/f_hid.c +++ b/drivers/usb/gadget/f_hid.c | |||
@@ -20,6 +20,8 @@ | |||
20 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
21 | #include <linux/usb/g_hid.h> | 21 | #include <linux/usb/g_hid.h> |
22 | 22 | ||
23 | #include "u_f.h" | ||
24 | |||
23 | static int major, minors; | 25 | static int major, minors; |
24 | static struct class *hidg_class; | 26 | static struct class *hidg_class; |
25 | 27 | ||
@@ -334,20 +336,10 @@ static int f_hidg_open(struct inode *inode, struct file *fd) | |||
334 | /*-------------------------------------------------------------------------*/ | 336 | /*-------------------------------------------------------------------------*/ |
335 | /* usb_function */ | 337 | /* usb_function */ |
336 | 338 | ||
337 | static struct usb_request *hidg_alloc_ep_req(struct usb_ep *ep, unsigned length) | 339 | static inline struct usb_request *hidg_alloc_ep_req(struct usb_ep *ep, |
340 | unsigned length) | ||
338 | { | 341 | { |
339 | struct usb_request *req; | 342 | return alloc_ep_req(ep, length, length); |
340 | |||
341 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); | ||
342 | if (req) { | ||
343 | req->length = length; | ||
344 | req->buf = kmalloc(length, GFP_ATOMIC); | ||
345 | if (!req->buf) { | ||
346 | usb_ep_free_request(ep, req); | ||
347 | req = NULL; | ||
348 | } | ||
349 | } | ||
350 | return req; | ||
351 | } | 343 | } |
352 | 344 | ||
353 | static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req) | 345 | static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req) |
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c index 4a3873a0f2d0..4557cd03f0b1 100644 --- a/drivers/usb/gadget/f_loopback.c +++ b/drivers/usb/gadget/f_loopback.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/usb/composite.h> | 20 | #include <linux/usb/composite.h> |
21 | 21 | ||
22 | #include "g_zero.h" | 22 | #include "g_zero.h" |
23 | #include "u_f.h" | ||
23 | 24 | ||
24 | /* | 25 | /* |
25 | * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals, | 26 | * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals, |
@@ -119,7 +120,7 @@ static struct usb_endpoint_descriptor ss_loop_source_desc = { | |||
119 | .wMaxPacketSize = cpu_to_le16(1024), | 120 | .wMaxPacketSize = cpu_to_le16(1024), |
120 | }; | 121 | }; |
121 | 122 | ||
122 | struct usb_ss_ep_comp_descriptor ss_loop_source_comp_desc = { | 123 | static struct usb_ss_ep_comp_descriptor ss_loop_source_comp_desc = { |
123 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 124 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
124 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 125 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
125 | .bMaxBurst = 0, | 126 | .bMaxBurst = 0, |
@@ -135,7 +136,7 @@ static struct usb_endpoint_descriptor ss_loop_sink_desc = { | |||
135 | .wMaxPacketSize = cpu_to_le16(1024), | 136 | .wMaxPacketSize = cpu_to_le16(1024), |
136 | }; | 137 | }; |
137 | 138 | ||
138 | struct usb_ss_ep_comp_descriptor ss_loop_sink_comp_desc = { | 139 | static struct usb_ss_ep_comp_descriptor ss_loop_sink_comp_desc = { |
139 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 140 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
140 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 141 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
141 | .bMaxBurst = 0, | 142 | .bMaxBurst = 0, |
@@ -230,6 +231,14 @@ autoconf_fail: | |||
230 | 231 | ||
231 | static void lb_free_func(struct usb_function *f) | 232 | static void lb_free_func(struct usb_function *f) |
232 | { | 233 | { |
234 | struct f_lb_opts *opts; | ||
235 | |||
236 | opts = container_of(f->fi, struct f_lb_opts, func_inst); | ||
237 | |||
238 | mutex_lock(&opts->lock); | ||
239 | opts->refcnt--; | ||
240 | mutex_unlock(&opts->lock); | ||
241 | |||
233 | usb_free_all_descriptors(f); | 242 | usb_free_all_descriptors(f); |
234 | kfree(func_to_loop(f)); | 243 | kfree(func_to_loop(f)); |
235 | } | 244 | } |
@@ -293,6 +302,11 @@ static void disable_loopback(struct f_loopback *loop) | |||
293 | VDBG(cdev, "%s disabled\n", loop->function.name); | 302 | VDBG(cdev, "%s disabled\n", loop->function.name); |
294 | } | 303 | } |
295 | 304 | ||
305 | static inline struct usb_request *lb_alloc_ep_req(struct usb_ep *ep, int len) | ||
306 | { | ||
307 | return alloc_ep_req(ep, len, buflen); | ||
308 | } | ||
309 | |||
296 | static int | 310 | static int |
297 | enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop) | 311 | enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop) |
298 | { | 312 | { |
@@ -332,7 +346,7 @@ fail0: | |||
332 | * than 'buflen' bytes each. | 346 | * than 'buflen' bytes each. |
333 | */ | 347 | */ |
334 | for (i = 0; i < qlen && result == 0; i++) { | 348 | for (i = 0; i < qlen && result == 0; i++) { |
335 | req = alloc_ep_req(ep, 0); | 349 | req = lb_alloc_ep_req(ep, 0); |
336 | if (req) { | 350 | if (req) { |
337 | req->complete = loopback_complete; | 351 | req->complete = loopback_complete; |
338 | result = usb_ep_queue(ep, req, GFP_ATOMIC); | 352 | result = usb_ep_queue(ep, req, GFP_ATOMIC); |
@@ -380,6 +394,11 @@ static struct usb_function *loopback_alloc(struct usb_function_instance *fi) | |||
380 | return ERR_PTR(-ENOMEM); | 394 | return ERR_PTR(-ENOMEM); |
381 | 395 | ||
382 | lb_opts = container_of(fi, struct f_lb_opts, func_inst); | 396 | lb_opts = container_of(fi, struct f_lb_opts, func_inst); |
397 | |||
398 | mutex_lock(&lb_opts->lock); | ||
399 | lb_opts->refcnt++; | ||
400 | mutex_unlock(&lb_opts->lock); | ||
401 | |||
383 | buflen = lb_opts->bulk_buflen; | 402 | buflen = lb_opts->bulk_buflen; |
384 | qlen = lb_opts->qlen; | 403 | qlen = lb_opts->qlen; |
385 | if (!qlen) | 404 | if (!qlen) |
@@ -396,6 +415,118 @@ static struct usb_function *loopback_alloc(struct usb_function_instance *fi) | |||
396 | return &loop->function; | 415 | return &loop->function; |
397 | } | 416 | } |
398 | 417 | ||
418 | static inline struct f_lb_opts *to_f_lb_opts(struct config_item *item) | ||
419 | { | ||
420 | return container_of(to_config_group(item), struct f_lb_opts, | ||
421 | func_inst.group); | ||
422 | } | ||
423 | |||
424 | CONFIGFS_ATTR_STRUCT(f_lb_opts); | ||
425 | CONFIGFS_ATTR_OPS(f_lb_opts); | ||
426 | |||
427 | static void lb_attr_release(struct config_item *item) | ||
428 | { | ||
429 | struct f_lb_opts *lb_opts = to_f_lb_opts(item); | ||
430 | |||
431 | usb_put_function_instance(&lb_opts->func_inst); | ||
432 | } | ||
433 | |||
434 | static struct configfs_item_operations lb_item_ops = { | ||
435 | .release = lb_attr_release, | ||
436 | .show_attribute = f_lb_opts_attr_show, | ||
437 | .store_attribute = f_lb_opts_attr_store, | ||
438 | }; | ||
439 | |||
440 | static ssize_t f_lb_opts_qlen_show(struct f_lb_opts *opts, char *page) | ||
441 | { | ||
442 | int result; | ||
443 | |||
444 | mutex_lock(&opts->lock); | ||
445 | result = sprintf(page, "%d", opts->qlen); | ||
446 | mutex_unlock(&opts->lock); | ||
447 | |||
448 | return result; | ||
449 | } | ||
450 | |||
451 | static ssize_t f_lb_opts_qlen_store(struct f_lb_opts *opts, | ||
452 | const char *page, size_t len) | ||
453 | { | ||
454 | int ret; | ||
455 | u32 num; | ||
456 | |||
457 | mutex_lock(&opts->lock); | ||
458 | if (opts->refcnt) { | ||
459 | ret = -EBUSY; | ||
460 | goto end; | ||
461 | } | ||
462 | |||
463 | ret = kstrtou32(page, 0, &num); | ||
464 | if (ret) | ||
465 | goto end; | ||
466 | |||
467 | opts->qlen = num; | ||
468 | ret = len; | ||
469 | end: | ||
470 | mutex_unlock(&opts->lock); | ||
471 | return ret; | ||
472 | } | ||
473 | |||
474 | static struct f_lb_opts_attribute f_lb_opts_qlen = | ||
475 | __CONFIGFS_ATTR(qlen, S_IRUGO | S_IWUSR, | ||
476 | f_lb_opts_qlen_show, | ||
477 | f_lb_opts_qlen_store); | ||
478 | |||
479 | static ssize_t f_lb_opts_bulk_buflen_show(struct f_lb_opts *opts, char *page) | ||
480 | { | ||
481 | int result; | ||
482 | |||
483 | mutex_lock(&opts->lock); | ||
484 | result = sprintf(page, "%d", opts->bulk_buflen); | ||
485 | mutex_unlock(&opts->lock); | ||
486 | |||
487 | return result; | ||
488 | } | ||
489 | |||
490 | static ssize_t f_lb_opts_bulk_buflen_store(struct f_lb_opts *opts, | ||
491 | const char *page, size_t len) | ||
492 | { | ||
493 | int ret; | ||
494 | u32 num; | ||
495 | |||
496 | mutex_lock(&opts->lock); | ||
497 | if (opts->refcnt) { | ||
498 | ret = -EBUSY; | ||
499 | goto end; | ||
500 | } | ||
501 | |||
502 | ret = kstrtou32(page, 0, &num); | ||
503 | if (ret) | ||
504 | goto end; | ||
505 | |||
506 | opts->bulk_buflen = num; | ||
507 | ret = len; | ||
508 | end: | ||
509 | mutex_unlock(&opts->lock); | ||
510 | return ret; | ||
511 | } | ||
512 | |||
513 | static struct f_lb_opts_attribute f_lb_opts_bulk_buflen = | ||
514 | __CONFIGFS_ATTR(buflen, S_IRUGO | S_IWUSR, | ||
515 | f_lb_opts_bulk_buflen_show, | ||
516 | f_lb_opts_bulk_buflen_store); | ||
517 | |||
518 | static struct configfs_attribute *lb_attrs[] = { | ||
519 | &f_lb_opts_qlen.attr, | ||
520 | &f_lb_opts_bulk_buflen.attr, | ||
521 | NULL, | ||
522 | }; | ||
523 | |||
524 | static struct config_item_type lb_func_type = { | ||
525 | .ct_item_ops = &lb_item_ops, | ||
526 | .ct_attrs = lb_attrs, | ||
527 | .ct_owner = THIS_MODULE, | ||
528 | }; | ||
529 | |||
399 | static void lb_free_instance(struct usb_function_instance *fi) | 530 | static void lb_free_instance(struct usb_function_instance *fi) |
400 | { | 531 | { |
401 | struct f_lb_opts *lb_opts; | 532 | struct f_lb_opts *lb_opts; |
@@ -411,7 +542,14 @@ static struct usb_function_instance *loopback_alloc_instance(void) | |||
411 | lb_opts = kzalloc(sizeof(*lb_opts), GFP_KERNEL); | 542 | lb_opts = kzalloc(sizeof(*lb_opts), GFP_KERNEL); |
412 | if (!lb_opts) | 543 | if (!lb_opts) |
413 | return ERR_PTR(-ENOMEM); | 544 | return ERR_PTR(-ENOMEM); |
545 | mutex_init(&lb_opts->lock); | ||
414 | lb_opts->func_inst.free_func_inst = lb_free_instance; | 546 | lb_opts->func_inst.free_func_inst = lb_free_instance; |
547 | lb_opts->bulk_buflen = GZERO_BULK_BUFLEN; | ||
548 | lb_opts->qlen = GZERO_QLEN; | ||
549 | |||
550 | config_group_init_type_name(&lb_opts->func_inst.group, "", | ||
551 | &lb_func_type); | ||
552 | |||
415 | return &lb_opts->func_inst; | 553 | return &lb_opts->func_inst; |
416 | } | 554 | } |
417 | DECLARE_USB_FUNCTION(Loopback, loopback_alloc_instance, loopback_alloc); | 555 | DECLARE_USB_FUNCTION(Loopback, loopback_alloc_instance, loopback_alloc); |
diff --git a/drivers/usb/gadget/f_midi.c b/drivers/usb/gadget/f_midi.c index 263e721c2694..36d4bb23087f 100644 --- a/drivers/usb/gadget/f_midi.c +++ b/drivers/usb/gadget/f_midi.c | |||
@@ -32,6 +32,8 @@ | |||
32 | #include <linux/usb/audio.h> | 32 | #include <linux/usb/audio.h> |
33 | #include <linux/usb/midi.h> | 33 | #include <linux/usb/midi.h> |
34 | 34 | ||
35 | #include "u_f.h" | ||
36 | |||
35 | MODULE_AUTHOR("Ben Williamson"); | 37 | MODULE_AUTHOR("Ben Williamson"); |
36 | MODULE_LICENSE("GPL v2"); | 38 | MODULE_LICENSE("GPL v2"); |
37 | 39 | ||
@@ -191,20 +193,10 @@ static struct usb_gadget_strings *midi_strings[] = { | |||
191 | NULL, | 193 | NULL, |
192 | }; | 194 | }; |
193 | 195 | ||
194 | static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length) | 196 | static inline struct usb_request *midi_alloc_ep_req(struct usb_ep *ep, |
197 | unsigned length) | ||
195 | { | 198 | { |
196 | struct usb_request *req; | 199 | return alloc_ep_req(ep, length, length); |
197 | |||
198 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); | ||
199 | if (req) { | ||
200 | req->length = length; | ||
201 | req->buf = kmalloc(length, GFP_ATOMIC); | ||
202 | if (!req->buf) { | ||
203 | usb_ep_free_request(ep, req); | ||
204 | req = NULL; | ||
205 | } | ||
206 | } | ||
207 | return req; | ||
208 | } | 200 | } |
209 | 201 | ||
210 | static void free_ep_req(struct usb_ep *ep, struct usb_request *req) | 202 | static void free_ep_req(struct usb_ep *ep, struct usb_request *req) |
@@ -365,7 +357,7 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
365 | /* allocate a bunch of read buffers and queue them all at once. */ | 357 | /* allocate a bunch of read buffers and queue them all at once. */ |
366 | for (i = 0; i < midi->qlen && err == 0; i++) { | 358 | for (i = 0; i < midi->qlen && err == 0; i++) { |
367 | struct usb_request *req = | 359 | struct usb_request *req = |
368 | alloc_ep_req(midi->out_ep, midi->buflen); | 360 | midi_alloc_ep_req(midi->out_ep, midi->buflen); |
369 | if (req == NULL) | 361 | if (req == NULL) |
370 | return -ENOMEM; | 362 | return -ENOMEM; |
371 | 363 | ||
@@ -546,7 +538,7 @@ static void f_midi_transmit(struct f_midi *midi, struct usb_request *req) | |||
546 | return; | 538 | return; |
547 | 539 | ||
548 | if (!req) | 540 | if (!req) |
549 | req = alloc_ep_req(ep, midi->buflen); | 541 | req = midi_alloc_ep_req(ep, midi->buflen); |
550 | 542 | ||
551 | if (!req) { | 543 | if (!req) { |
552 | ERROR(midi, "gmidi_transmit: alloc_ep_request failed\n"); | 544 | ERROR(midi, "gmidi_transmit: alloc_ep_request failed\n"); |
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c index 1c28fe13328a..a9499fd30792 100644 --- a/drivers/usb/gadget/f_ncm.c +++ b/drivers/usb/gadget/f_ncm.c | |||
@@ -1386,7 +1386,7 @@ static void ncm_unbind(struct usb_configuration *c, struct usb_function *f) | |||
1386 | usb_ep_free_request(ncm->notify, ncm->notify_req); | 1386 | usb_ep_free_request(ncm->notify, ncm->notify_req); |
1387 | } | 1387 | } |
1388 | 1388 | ||
1389 | struct usb_function *ncm_alloc(struct usb_function_instance *fi) | 1389 | static struct usb_function *ncm_alloc(struct usb_function_instance *fi) |
1390 | { | 1390 | { |
1391 | struct f_ncm *ncm; | 1391 | struct f_ncm *ncm; |
1392 | struct f_ncm_opts *opts; | 1392 | struct f_ncm_opts *opts; |
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c index ad39f1dacba3..aebae1853bce 100644 --- a/drivers/usb/gadget/f_obex.c +++ b/drivers/usb/gadget/f_obex.c | |||
@@ -499,7 +499,7 @@ static void obex_unbind(struct usb_configuration *c, struct usb_function *f) | |||
499 | usb_free_all_descriptors(f); | 499 | usb_free_all_descriptors(f); |
500 | } | 500 | } |
501 | 501 | ||
502 | struct usb_function *obex_alloc(struct usb_function_instance *fi) | 502 | static struct usb_function *obex_alloc(struct usb_function_instance *fi) |
503 | { | 503 | { |
504 | struct f_obex *obex; | 504 | struct f_obex *obex; |
505 | struct f_serial_opts *opts; | 505 | struct f_serial_opts *opts; |
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c index eb3aa817a662..f2b781773eed 100644 --- a/drivers/usb/gadget/f_phonet.c +++ b/drivers/usb/gadget/f_phonet.c | |||
@@ -689,7 +689,7 @@ static void pn_unbind(struct usb_configuration *c, struct usb_function *f) | |||
689 | usb_free_all_descriptors(f); | 689 | usb_free_all_descriptors(f); |
690 | } | 690 | } |
691 | 691 | ||
692 | struct usb_function *phonet_alloc(struct usb_function_instance *fi) | 692 | static struct usb_function *phonet_alloc(struct usb_function_instance *fi) |
693 | { | 693 | { |
694 | struct f_phonet *fp; | 694 | struct f_phonet *fp; |
695 | struct f_phonet_opts *opts; | 695 | struct f_phonet_opts *opts; |
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c index 717ed7f95639..c11761ce5113 100644 --- a/drivers/usb/gadget/f_rndis.c +++ b/drivers/usb/gadget/f_rndis.c | |||
@@ -675,7 +675,6 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
675 | int status; | 675 | int status; |
676 | struct usb_ep *ep; | 676 | struct usb_ep *ep; |
677 | 677 | ||
678 | #ifndef USB_FRNDIS_INCLUDED | ||
679 | struct f_rndis_opts *rndis_opts; | 678 | struct f_rndis_opts *rndis_opts; |
680 | 679 | ||
681 | if (!can_support_rndis(c)) | 680 | if (!can_support_rndis(c)) |
@@ -697,7 +696,7 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
697 | return status; | 696 | return status; |
698 | rndis_opts->bound = true; | 697 | rndis_opts->bound = true; |
699 | } | 698 | } |
700 | #endif | 699 | |
701 | us = usb_gstrings_attach(cdev, rndis_strings, | 700 | us = usb_gstrings_attach(cdev, rndis_strings, |
702 | ARRAY_SIZE(rndis_string_defs)); | 701 | ARRAY_SIZE(rndis_string_defs)); |
703 | if (IS_ERR(us)) | 702 | if (IS_ERR(us)) |
@@ -782,13 +781,6 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
782 | rndis->port.open = rndis_open; | 781 | rndis->port.open = rndis_open; |
783 | rndis->port.close = rndis_close; | 782 | rndis->port.close = rndis_close; |
784 | 783 | ||
785 | #ifdef USB_FRNDIS_INCLUDED | ||
786 | status = rndis_register(rndis_response_available, rndis); | ||
787 | if (status < 0) | ||
788 | goto fail; | ||
789 | rndis->config = status; | ||
790 | #endif | ||
791 | |||
792 | rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0); | 784 | rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0); |
793 | rndis_set_host_mac(rndis->config, rndis->ethaddr); | 785 | rndis_set_host_mac(rndis->config, rndis->ethaddr); |
794 | 786 | ||
@@ -830,66 +822,6 @@ fail: | |||
830 | return status; | 822 | return status; |
831 | } | 823 | } |
832 | 824 | ||
833 | #ifdef USB_FRNDIS_INCLUDED | ||
834 | |||
835 | static void | ||
836 | rndis_old_unbind(struct usb_configuration *c, struct usb_function *f) | ||
837 | { | ||
838 | struct f_rndis *rndis = func_to_rndis(f); | ||
839 | |||
840 | rndis_deregister(rndis->config); | ||
841 | |||
842 | usb_free_all_descriptors(f); | ||
843 | |||
844 | kfree(rndis->notify_req->buf); | ||
845 | usb_ep_free_request(rndis->notify, rndis->notify_req); | ||
846 | |||
847 | kfree(rndis); | ||
848 | } | ||
849 | |||
850 | int | ||
851 | rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
852 | u32 vendorID, const char *manufacturer, struct eth_dev *dev) | ||
853 | { | ||
854 | struct f_rndis *rndis; | ||
855 | int status; | ||
856 | |||
857 | /* allocate and initialize one new instance */ | ||
858 | status = -ENOMEM; | ||
859 | rndis = kzalloc(sizeof *rndis, GFP_KERNEL); | ||
860 | if (!rndis) | ||
861 | goto fail; | ||
862 | |||
863 | memcpy(rndis->ethaddr, ethaddr, ETH_ALEN); | ||
864 | rndis->vendorID = vendorID; | ||
865 | rndis->manufacturer = manufacturer; | ||
866 | |||
867 | rndis->port.ioport = dev; | ||
868 | /* RNDIS activates when the host changes this filter */ | ||
869 | rndis->port.cdc_filter = 0; | ||
870 | |||
871 | /* RNDIS has special (and complex) framing */ | ||
872 | rndis->port.header_len = sizeof(struct rndis_packet_msg_type); | ||
873 | rndis->port.wrap = rndis_add_header; | ||
874 | rndis->port.unwrap = rndis_rm_hdr; | ||
875 | |||
876 | rndis->port.func.name = "rndis"; | ||
877 | /* descriptors are per-instance copies */ | ||
878 | rndis->port.func.bind = rndis_bind; | ||
879 | rndis->port.func.unbind = rndis_old_unbind; | ||
880 | rndis->port.func.set_alt = rndis_set_alt; | ||
881 | rndis->port.func.setup = rndis_setup; | ||
882 | rndis->port.func.disable = rndis_disable; | ||
883 | |||
884 | status = usb_add_function(c, &rndis->port.func); | ||
885 | if (status) | ||
886 | kfree(rndis); | ||
887 | fail: | ||
888 | return status; | ||
889 | } | ||
890 | |||
891 | #else | ||
892 | |||
893 | void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net) | 825 | void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net) |
894 | { | 826 | { |
895 | struct f_rndis_opts *opts; | 827 | struct f_rndis_opts *opts; |
@@ -1047,8 +979,26 @@ static struct usb_function *rndis_alloc(struct usb_function_instance *fi) | |||
1047 | return &rndis->port.func; | 979 | return &rndis->port.func; |
1048 | } | 980 | } |
1049 | 981 | ||
1050 | DECLARE_USB_FUNCTION_INIT(rndis, rndis_alloc_inst, rndis_alloc); | 982 | DECLARE_USB_FUNCTION(rndis, rndis_alloc_inst, rndis_alloc); |
983 | |||
984 | static int __init rndis_mod_init(void) | ||
985 | { | ||
986 | int ret; | ||
987 | |||
988 | ret = rndis_init(); | ||
989 | if (ret) | ||
990 | return ret; | ||
991 | |||
992 | return usb_function_register(&rndisusb_func); | ||
993 | } | ||
994 | module_init(rndis_mod_init); | ||
995 | |||
996 | static void __exit rndis_mod_exit(void) | ||
997 | { | ||
998 | usb_function_unregister(&rndisusb_func); | ||
999 | rndis_exit(); | ||
1000 | } | ||
1001 | module_exit(rndis_mod_exit); | ||
1002 | |||
1051 | MODULE_LICENSE("GPL"); | 1003 | MODULE_LICENSE("GPL"); |
1052 | MODULE_AUTHOR("David Brownell"); | 1004 | MODULE_AUTHOR("David Brownell"); |
1053 | |||
1054 | #endif | ||
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c index 981113c9924d..9ecbcbf36a45 100644 --- a/drivers/usb/gadget/f_serial.c +++ b/drivers/usb/gadget/f_serial.c | |||
@@ -354,7 +354,7 @@ static void gser_unbind(struct usb_configuration *c, struct usb_function *f) | |||
354 | usb_free_all_descriptors(f); | 354 | usb_free_all_descriptors(f); |
355 | } | 355 | } |
356 | 356 | ||
357 | struct usb_function *gser_alloc(struct usb_function_instance *fi) | 357 | static struct usb_function *gser_alloc(struct usb_function_instance *fi) |
358 | { | 358 | { |
359 | struct f_gser *gser; | 359 | struct f_gser *gser; |
360 | struct f_serial_opts *opts; | 360 | struct f_serial_opts *opts; |
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c index a8895859a221..d3cd52db78fe 100644 --- a/drivers/usb/gadget/f_sourcesink.c +++ b/drivers/usb/gadget/f_sourcesink.c | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include "g_zero.h" | 22 | #include "g_zero.h" |
23 | #include "gadget_chips.h" | 23 | #include "gadget_chips.h" |
24 | #include "u_f.h" | ||
24 | 25 | ||
25 | /* | 26 | /* |
26 | * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral | 27 | * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral |
@@ -201,7 +202,7 @@ static struct usb_endpoint_descriptor ss_source_desc = { | |||
201 | .wMaxPacketSize = cpu_to_le16(1024), | 202 | .wMaxPacketSize = cpu_to_le16(1024), |
202 | }; | 203 | }; |
203 | 204 | ||
204 | struct usb_ss_ep_comp_descriptor ss_source_comp_desc = { | 205 | static struct usb_ss_ep_comp_descriptor ss_source_comp_desc = { |
205 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 206 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
206 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 207 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
207 | 208 | ||
@@ -218,7 +219,7 @@ static struct usb_endpoint_descriptor ss_sink_desc = { | |||
218 | .wMaxPacketSize = cpu_to_le16(1024), | 219 | .wMaxPacketSize = cpu_to_le16(1024), |
219 | }; | 220 | }; |
220 | 221 | ||
221 | struct usb_ss_ep_comp_descriptor ss_sink_comp_desc = { | 222 | static struct usb_ss_ep_comp_descriptor ss_sink_comp_desc = { |
222 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 223 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
223 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 224 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
224 | 225 | ||
@@ -236,7 +237,7 @@ static struct usb_endpoint_descriptor ss_iso_source_desc = { | |||
236 | .bInterval = 4, | 237 | .bInterval = 4, |
237 | }; | 238 | }; |
238 | 239 | ||
239 | struct usb_ss_ep_comp_descriptor ss_iso_source_comp_desc = { | 240 | static struct usb_ss_ep_comp_descriptor ss_iso_source_comp_desc = { |
240 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 241 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
241 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 242 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
242 | 243 | ||
@@ -254,7 +255,7 @@ static struct usb_endpoint_descriptor ss_iso_sink_desc = { | |||
254 | .bInterval = 4, | 255 | .bInterval = 4, |
255 | }; | 256 | }; |
256 | 257 | ||
257 | struct usb_ss_ep_comp_descriptor ss_iso_sink_comp_desc = { | 258 | static struct usb_ss_ep_comp_descriptor ss_iso_sink_comp_desc = { |
258 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 259 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
259 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 260 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
260 | 261 | ||
@@ -301,23 +302,9 @@ static struct usb_gadget_strings *sourcesink_strings[] = { | |||
301 | 302 | ||
302 | /*-------------------------------------------------------------------------*/ | 303 | /*-------------------------------------------------------------------------*/ |
303 | 304 | ||
304 | struct usb_request *alloc_ep_req(struct usb_ep *ep, int len) | 305 | static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len) |
305 | { | 306 | { |
306 | struct usb_request *req; | 307 | return alloc_ep_req(ep, len, buflen); |
307 | |||
308 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); | ||
309 | if (req) { | ||
310 | if (len) | ||
311 | req->length = len; | ||
312 | else | ||
313 | req->length = buflen; | ||
314 | req->buf = kmalloc(req->length, GFP_ATOMIC); | ||
315 | if (!req->buf) { | ||
316 | usb_ep_free_request(ep, req); | ||
317 | req = NULL; | ||
318 | } | ||
319 | } | ||
320 | return req; | ||
321 | } | 308 | } |
322 | 309 | ||
323 | void free_ep_req(struct usb_ep *ep, struct usb_request *req) | 310 | void free_ep_req(struct usb_ep *ep, struct usb_request *req) |
@@ -490,6 +477,14 @@ no_iso: | |||
490 | static void | 477 | static void |
491 | sourcesink_free_func(struct usb_function *f) | 478 | sourcesink_free_func(struct usb_function *f) |
492 | { | 479 | { |
480 | struct f_ss_opts *opts; | ||
481 | |||
482 | opts = container_of(f->fi, struct f_ss_opts, func_inst); | ||
483 | |||
484 | mutex_lock(&opts->lock); | ||
485 | opts->refcnt--; | ||
486 | mutex_unlock(&opts->lock); | ||
487 | |||
493 | usb_free_all_descriptors(f); | 488 | usb_free_all_descriptors(f); |
494 | kfree(func_to_ss(f)); | 489 | kfree(func_to_ss(f)); |
495 | } | 490 | } |
@@ -628,10 +623,10 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in, | |||
628 | break; | 623 | break; |
629 | } | 624 | } |
630 | ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; | 625 | ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; |
631 | req = alloc_ep_req(ep, size); | 626 | req = ss_alloc_ep_req(ep, size); |
632 | } else { | 627 | } else { |
633 | ep = is_in ? ss->in_ep : ss->out_ep; | 628 | ep = is_in ? ss->in_ep : ss->out_ep; |
634 | req = alloc_ep_req(ep, 0); | 629 | req = ss_alloc_ep_req(ep, 0); |
635 | } | 630 | } |
636 | 631 | ||
637 | if (!req) | 632 | if (!req) |
@@ -878,6 +873,11 @@ static struct usb_function *source_sink_alloc_func( | |||
878 | return NULL; | 873 | return NULL; |
879 | 874 | ||
880 | ss_opts = container_of(fi, struct f_ss_opts, func_inst); | 875 | ss_opts = container_of(fi, struct f_ss_opts, func_inst); |
876 | |||
877 | mutex_lock(&ss_opts->lock); | ||
878 | ss_opts->refcnt++; | ||
879 | mutex_unlock(&ss_opts->lock); | ||
880 | |||
881 | pattern = ss_opts->pattern; | 881 | pattern = ss_opts->pattern; |
882 | isoc_interval = ss_opts->isoc_interval; | 882 | isoc_interval = ss_opts->isoc_interval; |
883 | isoc_maxpacket = ss_opts->isoc_maxpacket; | 883 | isoc_maxpacket = ss_opts->isoc_maxpacket; |
@@ -898,6 +898,303 @@ static struct usb_function *source_sink_alloc_func( | |||
898 | return &ss->function; | 898 | return &ss->function; |
899 | } | 899 | } |
900 | 900 | ||
901 | static inline struct f_ss_opts *to_f_ss_opts(struct config_item *item) | ||
902 | { | ||
903 | return container_of(to_config_group(item), struct f_ss_opts, | ||
904 | func_inst.group); | ||
905 | } | ||
906 | |||
907 | CONFIGFS_ATTR_STRUCT(f_ss_opts); | ||
908 | CONFIGFS_ATTR_OPS(f_ss_opts); | ||
909 | |||
910 | static void ss_attr_release(struct config_item *item) | ||
911 | { | ||
912 | struct f_ss_opts *ss_opts = to_f_ss_opts(item); | ||
913 | |||
914 | usb_put_function_instance(&ss_opts->func_inst); | ||
915 | } | ||
916 | |||
917 | static struct configfs_item_operations ss_item_ops = { | ||
918 | .release = ss_attr_release, | ||
919 | .show_attribute = f_ss_opts_attr_show, | ||
920 | .store_attribute = f_ss_opts_attr_store, | ||
921 | }; | ||
922 | |||
923 | static ssize_t f_ss_opts_pattern_show(struct f_ss_opts *opts, char *page) | ||
924 | { | ||
925 | int result; | ||
926 | |||
927 | mutex_lock(&opts->lock); | ||
928 | result = sprintf(page, "%d", opts->pattern); | ||
929 | mutex_unlock(&opts->lock); | ||
930 | |||
931 | return result; | ||
932 | } | ||
933 | |||
934 | static ssize_t f_ss_opts_pattern_store(struct f_ss_opts *opts, | ||
935 | const char *page, size_t len) | ||
936 | { | ||
937 | int ret; | ||
938 | u8 num; | ||
939 | |||
940 | mutex_lock(&opts->lock); | ||
941 | if (opts->refcnt) { | ||
942 | ret = -EBUSY; | ||
943 | goto end; | ||
944 | } | ||
945 | |||
946 | ret = kstrtou8(page, 0, &num); | ||
947 | if (ret) | ||
948 | goto end; | ||
949 | |||
950 | if (num != 0 && num != 1 && num != 2) { | ||
951 | ret = -EINVAL; | ||
952 | goto end; | ||
953 | } | ||
954 | |||
955 | opts->pattern = num; | ||
956 | ret = len; | ||
957 | end: | ||
958 | mutex_unlock(&opts->lock); | ||
959 | return ret; | ||
960 | } | ||
961 | |||
962 | static struct f_ss_opts_attribute f_ss_opts_pattern = | ||
963 | __CONFIGFS_ATTR(pattern, S_IRUGO | S_IWUSR, | ||
964 | f_ss_opts_pattern_show, | ||
965 | f_ss_opts_pattern_store); | ||
966 | |||
967 | static ssize_t f_ss_opts_isoc_interval_show(struct f_ss_opts *opts, char *page) | ||
968 | { | ||
969 | int result; | ||
970 | |||
971 | mutex_lock(&opts->lock); | ||
972 | result = sprintf(page, "%d", opts->isoc_interval); | ||
973 | mutex_unlock(&opts->lock); | ||
974 | |||
975 | return result; | ||
976 | } | ||
977 | |||
978 | static ssize_t f_ss_opts_isoc_interval_store(struct f_ss_opts *opts, | ||
979 | const char *page, size_t len) | ||
980 | { | ||
981 | int ret; | ||
982 | u8 num; | ||
983 | |||
984 | mutex_lock(&opts->lock); | ||
985 | if (opts->refcnt) { | ||
986 | ret = -EBUSY; | ||
987 | goto end; | ||
988 | } | ||
989 | |||
990 | ret = kstrtou8(page, 0, &num); | ||
991 | if (ret) | ||
992 | goto end; | ||
993 | |||
994 | if (num > 16) { | ||
995 | ret = -EINVAL; | ||
996 | goto end; | ||
997 | } | ||
998 | |||
999 | opts->isoc_interval = num; | ||
1000 | ret = len; | ||
1001 | end: | ||
1002 | mutex_unlock(&opts->lock); | ||
1003 | return ret; | ||
1004 | } | ||
1005 | |||
1006 | static struct f_ss_opts_attribute f_ss_opts_isoc_interval = | ||
1007 | __CONFIGFS_ATTR(isoc_interval, S_IRUGO | S_IWUSR, | ||
1008 | f_ss_opts_isoc_interval_show, | ||
1009 | f_ss_opts_isoc_interval_store); | ||
1010 | |||
1011 | static ssize_t f_ss_opts_isoc_maxpacket_show(struct f_ss_opts *opts, char *page) | ||
1012 | { | ||
1013 | int result; | ||
1014 | |||
1015 | mutex_lock(&opts->lock); | ||
1016 | result = sprintf(page, "%d", opts->isoc_maxpacket); | ||
1017 | mutex_unlock(&opts->lock); | ||
1018 | |||
1019 | return result; | ||
1020 | } | ||
1021 | |||
1022 | static ssize_t f_ss_opts_isoc_maxpacket_store(struct f_ss_opts *opts, | ||
1023 | const char *page, size_t len) | ||
1024 | { | ||
1025 | int ret; | ||
1026 | u16 num; | ||
1027 | |||
1028 | mutex_lock(&opts->lock); | ||
1029 | if (opts->refcnt) { | ||
1030 | ret = -EBUSY; | ||
1031 | goto end; | ||
1032 | } | ||
1033 | |||
1034 | ret = kstrtou16(page, 0, &num); | ||
1035 | if (ret) | ||
1036 | goto end; | ||
1037 | |||
1038 | if (num > 1024) { | ||
1039 | ret = -EINVAL; | ||
1040 | goto end; | ||
1041 | } | ||
1042 | |||
1043 | opts->isoc_maxpacket = num; | ||
1044 | ret = len; | ||
1045 | end: | ||
1046 | mutex_unlock(&opts->lock); | ||
1047 | return ret; | ||
1048 | } | ||
1049 | |||
1050 | static struct f_ss_opts_attribute f_ss_opts_isoc_maxpacket = | ||
1051 | __CONFIGFS_ATTR(isoc_maxpacket, S_IRUGO | S_IWUSR, | ||
1052 | f_ss_opts_isoc_maxpacket_show, | ||
1053 | f_ss_opts_isoc_maxpacket_store); | ||
1054 | |||
1055 | static ssize_t f_ss_opts_isoc_mult_show(struct f_ss_opts *opts, char *page) | ||
1056 | { | ||
1057 | int result; | ||
1058 | |||
1059 | mutex_lock(&opts->lock); | ||
1060 | result = sprintf(page, "%d", opts->isoc_mult); | ||
1061 | mutex_unlock(&opts->lock); | ||
1062 | |||
1063 | return result; | ||
1064 | } | ||
1065 | |||
1066 | static ssize_t f_ss_opts_isoc_mult_store(struct f_ss_opts *opts, | ||
1067 | const char *page, size_t len) | ||
1068 | { | ||
1069 | int ret; | ||
1070 | u8 num; | ||
1071 | |||
1072 | mutex_lock(&opts->lock); | ||
1073 | if (opts->refcnt) { | ||
1074 | ret = -EBUSY; | ||
1075 | goto end; | ||
1076 | } | ||
1077 | |||
1078 | ret = kstrtou8(page, 0, &num); | ||
1079 | if (ret) | ||
1080 | goto end; | ||
1081 | |||
1082 | if (num > 2) { | ||
1083 | ret = -EINVAL; | ||
1084 | goto end; | ||
1085 | } | ||
1086 | |||
1087 | opts->isoc_mult = num; | ||
1088 | ret = len; | ||
1089 | end: | ||
1090 | mutex_unlock(&opts->lock); | ||
1091 | return ret; | ||
1092 | } | ||
1093 | |||
1094 | static struct f_ss_opts_attribute f_ss_opts_isoc_mult = | ||
1095 | __CONFIGFS_ATTR(isoc_mult, S_IRUGO | S_IWUSR, | ||
1096 | f_ss_opts_isoc_mult_show, | ||
1097 | f_ss_opts_isoc_mult_store); | ||
1098 | |||
1099 | static ssize_t f_ss_opts_isoc_maxburst_show(struct f_ss_opts *opts, char *page) | ||
1100 | { | ||
1101 | int result; | ||
1102 | |||
1103 | mutex_lock(&opts->lock); | ||
1104 | result = sprintf(page, "%d", opts->isoc_maxburst); | ||
1105 | mutex_unlock(&opts->lock); | ||
1106 | |||
1107 | return result; | ||
1108 | } | ||
1109 | |||
1110 | static ssize_t f_ss_opts_isoc_maxburst_store(struct f_ss_opts *opts, | ||
1111 | const char *page, size_t len) | ||
1112 | { | ||
1113 | int ret; | ||
1114 | u8 num; | ||
1115 | |||
1116 | mutex_lock(&opts->lock); | ||
1117 | if (opts->refcnt) { | ||
1118 | ret = -EBUSY; | ||
1119 | goto end; | ||
1120 | } | ||
1121 | |||
1122 | ret = kstrtou8(page, 0, &num); | ||
1123 | if (ret) | ||
1124 | goto end; | ||
1125 | |||
1126 | if (num > 15) { | ||
1127 | ret = -EINVAL; | ||
1128 | goto end; | ||
1129 | } | ||
1130 | |||
1131 | opts->isoc_maxburst = num; | ||
1132 | ret = len; | ||
1133 | end: | ||
1134 | mutex_unlock(&opts->lock); | ||
1135 | return ret; | ||
1136 | } | ||
1137 | |||
1138 | static struct f_ss_opts_attribute f_ss_opts_isoc_maxburst = | ||
1139 | __CONFIGFS_ATTR(isoc_maxburst, S_IRUGO | S_IWUSR, | ||
1140 | f_ss_opts_isoc_maxburst_show, | ||
1141 | f_ss_opts_isoc_maxburst_store); | ||
1142 | |||
1143 | static ssize_t f_ss_opts_bulk_buflen_show(struct f_ss_opts *opts, char *page) | ||
1144 | { | ||
1145 | int result; | ||
1146 | |||
1147 | mutex_lock(&opts->lock); | ||
1148 | result = sprintf(page, "%d", opts->bulk_buflen); | ||
1149 | mutex_unlock(&opts->lock); | ||
1150 | |||
1151 | return result; | ||
1152 | } | ||
1153 | |||
1154 | static ssize_t f_ss_opts_bulk_buflen_store(struct f_ss_opts *opts, | ||
1155 | const char *page, size_t len) | ||
1156 | { | ||
1157 | int ret; | ||
1158 | u32 num; | ||
1159 | |||
1160 | mutex_lock(&opts->lock); | ||
1161 | if (opts->refcnt) { | ||
1162 | ret = -EBUSY; | ||
1163 | goto end; | ||
1164 | } | ||
1165 | |||
1166 | ret = kstrtou32(page, 0, &num); | ||
1167 | if (ret) | ||
1168 | goto end; | ||
1169 | |||
1170 | opts->bulk_buflen = num; | ||
1171 | ret = len; | ||
1172 | end: | ||
1173 | mutex_unlock(&opts->lock); | ||
1174 | return ret; | ||
1175 | } | ||
1176 | |||
1177 | static struct f_ss_opts_attribute f_ss_opts_bulk_buflen = | ||
1178 | __CONFIGFS_ATTR(buflen, S_IRUGO | S_IWUSR, | ||
1179 | f_ss_opts_bulk_buflen_show, | ||
1180 | f_ss_opts_bulk_buflen_store); | ||
1181 | |||
1182 | static struct configfs_attribute *ss_attrs[] = { | ||
1183 | &f_ss_opts_pattern.attr, | ||
1184 | &f_ss_opts_isoc_interval.attr, | ||
1185 | &f_ss_opts_isoc_maxpacket.attr, | ||
1186 | &f_ss_opts_isoc_mult.attr, | ||
1187 | &f_ss_opts_isoc_maxburst.attr, | ||
1188 | &f_ss_opts_bulk_buflen.attr, | ||
1189 | NULL, | ||
1190 | }; | ||
1191 | |||
1192 | static struct config_item_type ss_func_type = { | ||
1193 | .ct_item_ops = &ss_item_ops, | ||
1194 | .ct_attrs = ss_attrs, | ||
1195 | .ct_owner = THIS_MODULE, | ||
1196 | }; | ||
1197 | |||
901 | static void source_sink_free_instance(struct usb_function_instance *fi) | 1198 | static void source_sink_free_instance(struct usb_function_instance *fi) |
902 | { | 1199 | { |
903 | struct f_ss_opts *ss_opts; | 1200 | struct f_ss_opts *ss_opts; |
@@ -913,7 +1210,15 @@ static struct usb_function_instance *source_sink_alloc_inst(void) | |||
913 | ss_opts = kzalloc(sizeof(*ss_opts), GFP_KERNEL); | 1210 | ss_opts = kzalloc(sizeof(*ss_opts), GFP_KERNEL); |
914 | if (!ss_opts) | 1211 | if (!ss_opts) |
915 | return ERR_PTR(-ENOMEM); | 1212 | return ERR_PTR(-ENOMEM); |
1213 | mutex_init(&ss_opts->lock); | ||
916 | ss_opts->func_inst.free_func_inst = source_sink_free_instance; | 1214 | ss_opts->func_inst.free_func_inst = source_sink_free_instance; |
1215 | ss_opts->isoc_interval = GZERO_ISOC_INTERVAL; | ||
1216 | ss_opts->isoc_maxpacket = GZERO_ISOC_MAXPACKET; | ||
1217 | ss_opts->bulk_buflen = GZERO_BULK_BUFLEN; | ||
1218 | |||
1219 | config_group_init_type_name(&ss_opts->func_inst.group, "", | ||
1220 | &ss_func_type); | ||
1221 | |||
917 | return &ss_opts->func_inst; | 1222 | return &ss_opts->func_inst; |
918 | } | 1223 | } |
919 | DECLARE_USB_FUNCTION(SourceSink, source_sink_alloc_inst, | 1224 | DECLARE_USB_FUNCTION(SourceSink, source_sink_alloc_inst, |
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c index 7c8674fa7e80..f1a59190ac9a 100644 --- a/drivers/usb/gadget/f_subset.c +++ b/drivers/usb/gadget/f_subset.c | |||
@@ -301,7 +301,6 @@ geth_bind(struct usb_configuration *c, struct usb_function *f) | |||
301 | int status; | 301 | int status; |
302 | struct usb_ep *ep; | 302 | struct usb_ep *ep; |
303 | 303 | ||
304 | #ifndef USB_FSUBSET_INCLUDED | ||
305 | struct f_gether_opts *gether_opts; | 304 | struct f_gether_opts *gether_opts; |
306 | 305 | ||
307 | gether_opts = container_of(f->fi, struct f_gether_opts, func_inst); | 306 | gether_opts = container_of(f->fi, struct f_gether_opts, func_inst); |
@@ -322,7 +321,7 @@ geth_bind(struct usb_configuration *c, struct usb_function *f) | |||
322 | return status; | 321 | return status; |
323 | gether_opts->bound = true; | 322 | gether_opts->bound = true; |
324 | } | 323 | } |
325 | #endif | 324 | |
326 | us = usb_gstrings_attach(cdev, geth_strings, | 325 | us = usb_gstrings_attach(cdev, geth_strings, |
327 | ARRAY_SIZE(geth_string_defs)); | 326 | ARRAY_SIZE(geth_string_defs)); |
328 | if (IS_ERR(us)) | 327 | if (IS_ERR(us)) |
@@ -393,61 +392,6 @@ fail: | |||
393 | return status; | 392 | return status; |
394 | } | 393 | } |
395 | 394 | ||
396 | #ifdef USB_FSUBSET_INCLUDED | ||
397 | |||
398 | static void | ||
399 | geth_old_unbind(struct usb_configuration *c, struct usb_function *f) | ||
400 | { | ||
401 | geth_string_defs[0].id = 0; | ||
402 | usb_free_all_descriptors(f); | ||
403 | kfree(func_to_geth(f)); | ||
404 | } | ||
405 | |||
406 | /** | ||
407 | * geth_bind_config - add CDC Subset network link to a configuration | ||
408 | * @c: the configuration to support the network link | ||
409 | * @ethaddr: a buffer in which the ethernet address of the host side | ||
410 | * side of the link was recorded | ||
411 | * @dev: eth_dev structure | ||
412 | * Context: single threaded during gadget setup | ||
413 | * | ||
414 | * Returns zero on success, else negative errno. | ||
415 | * | ||
416 | * Caller must have called @gether_setup(). Caller is also responsible | ||
417 | * for calling @gether_cleanup() before module unload. | ||
418 | */ | ||
419 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
420 | struct eth_dev *dev) | ||
421 | { | ||
422 | struct f_gether *geth; | ||
423 | int status; | ||
424 | |||
425 | /* allocate and initialize one new instance */ | ||
426 | geth = kzalloc(sizeof *geth, GFP_KERNEL); | ||
427 | if (!geth) | ||
428 | return -ENOMEM; | ||
429 | |||
430 | /* export host's Ethernet address in CDC format */ | ||
431 | snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr); | ||
432 | geth_string_defs[1].s = geth->ethaddr; | ||
433 | |||
434 | geth->port.ioport = dev; | ||
435 | geth->port.cdc_filter = DEFAULT_FILTER; | ||
436 | |||
437 | geth->port.func.name = "cdc_subset"; | ||
438 | geth->port.func.bind = geth_bind; | ||
439 | geth->port.func.unbind = geth_old_unbind; | ||
440 | geth->port.func.set_alt = geth_set_alt; | ||
441 | geth->port.func.disable = geth_disable; | ||
442 | |||
443 | status = usb_add_function(c, &geth->port.func); | ||
444 | if (status) | ||
445 | kfree(geth); | ||
446 | return status; | ||
447 | } | ||
448 | |||
449 | #else | ||
450 | |||
451 | static inline struct f_gether_opts *to_f_gether_opts(struct config_item *item) | 395 | static inline struct f_gether_opts *to_f_gether_opts(struct config_item *item) |
452 | { | 396 | { |
453 | return container_of(to_config_group(item), struct f_gether_opts, | 397 | return container_of(to_config_group(item), struct f_gether_opts, |
@@ -573,5 +517,3 @@ static struct usb_function *geth_alloc(struct usb_function_instance *fi) | |||
573 | DECLARE_USB_FUNCTION_INIT(geth, geth_alloc_inst, geth_alloc); | 517 | DECLARE_USB_FUNCTION_INIT(geth, geth_alloc_inst, geth_alloc); |
574 | MODULE_LICENSE("GPL"); | 518 | MODULE_LICENSE("GPL"); |
575 | MODULE_AUTHOR("David Brownell"); | 519 | MODULE_AUTHOR("David Brownell"); |
576 | |||
577 | #endif | ||
diff --git a/drivers/usb/gadget/fotg210-udc.c b/drivers/usb/gadget/fotg210-udc.c index bbbfd1948778..2d0305280e8c 100644 --- a/drivers/usb/gadget/fotg210-udc.c +++ b/drivers/usb/gadget/fotg210-udc.c | |||
@@ -1157,8 +1157,9 @@ static int fotg210_udc_probe(struct platform_device *pdev) | |||
1157 | INIT_LIST_HEAD(&ep->queue); | 1157 | INIT_LIST_HEAD(&ep->queue); |
1158 | ep->ep.name = fotg210_ep_name[i]; | 1158 | ep->ep.name = fotg210_ep_name[i]; |
1159 | ep->ep.ops = &fotg210_ep_ops; | 1159 | ep->ep.ops = &fotg210_ep_ops; |
1160 | usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); | ||
1160 | } | 1161 | } |
1161 | fotg210->ep[0]->ep.maxpacket = 0x40; | 1162 | usb_ep_set_maxpacket_limit(&fotg210->ep[0]->ep, 0x40); |
1162 | fotg210->gadget.ep0 = &fotg210->ep[0]->ep; | 1163 | fotg210->gadget.ep0 = &fotg210->ep[0]->ep; |
1163 | INIT_LIST_HEAD(&fotg210->gadget.ep0->ep_list); | 1164 | INIT_LIST_HEAD(&fotg210->gadget.ep0->ep_list); |
1164 | 1165 | ||
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c index 807127d56fa3..ad5483335167 100644 --- a/drivers/usb/gadget/fsl_qe_udc.c +++ b/drivers/usb/gadget/fsl_qe_udc.c | |||
@@ -22,7 +22,6 @@ | |||
22 | 22 | ||
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/init.h> | ||
26 | #include <linux/ioport.h> | 25 | #include <linux/ioport.h> |
27 | #include <linux/types.h> | 26 | #include <linux/types.h> |
28 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
@@ -2429,7 +2428,7 @@ static int qe_ep_config(struct qe_udc *udc, unsigned char pipe_num) | |||
2429 | 2428 | ||
2430 | ep->ep.ops = &qe_ep_ops; | 2429 | ep->ep.ops = &qe_ep_ops; |
2431 | ep->stopped = 1; | 2430 | ep->stopped = 1; |
2432 | ep->ep.maxpacket = (unsigned short) ~0; | 2431 | usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); |
2433 | ep->ep.desc = NULL; | 2432 | ep->ep.desc = NULL; |
2434 | ep->dir = 0xff; | 2433 | ep->dir = 0xff; |
2435 | ep->epnum = (u8)pipe_num; | 2434 | ep->epnum = (u8)pipe_num; |
@@ -2717,7 +2716,7 @@ MODULE_DEVICE_TABLE(of, qe_udc_match); | |||
2717 | 2716 | ||
2718 | static struct platform_driver udc_driver = { | 2717 | static struct platform_driver udc_driver = { |
2719 | .driver = { | 2718 | .driver = { |
2720 | .name = (char *)driver_name, | 2719 | .name = driver_name, |
2721 | .owner = THIS_MODULE, | 2720 | .owner = THIS_MODULE, |
2722 | .of_match_table = qe_udc_match, | 2721 | .of_match_table = qe_udc_match, |
2723 | }, | 2722 | }, |
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c index 36ac7cfba91d..15960af0f67e 100644 --- a/drivers/usb/gadget/fsl_udc_core.c +++ b/drivers/usb/gadget/fsl_udc_core.c | |||
@@ -2311,7 +2311,7 @@ static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index, | |||
2311 | /* for ep0: maxP defined in desc | 2311 | /* for ep0: maxP defined in desc |
2312 | * for other eps, maxP is set by epautoconfig() called by gadget layer | 2312 | * for other eps, maxP is set by epautoconfig() called by gadget layer |
2313 | */ | 2313 | */ |
2314 | ep->ep.maxpacket = (unsigned short) ~0; | 2314 | usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); |
2315 | 2315 | ||
2316 | /* the queue lists any req for this ep */ | 2316 | /* the queue lists any req for this ep */ |
2317 | INIT_LIST_HEAD(&ep->queue); | 2317 | INIT_LIST_HEAD(&ep->queue); |
@@ -2469,7 +2469,8 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2469 | * for other eps, gadget layer called ep_enable with defined desc | 2469 | * for other eps, gadget layer called ep_enable with defined desc |
2470 | */ | 2470 | */ |
2471 | udc_controller->eps[0].ep.desc = &fsl_ep0_desc; | 2471 | udc_controller->eps[0].ep.desc = &fsl_ep0_desc; |
2472 | udc_controller->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD; | 2472 | usb_ep_set_maxpacket_limit(&udc_controller->eps[0].ep, |
2473 | USB_MAX_CTRL_PAYLOAD); | ||
2473 | 2474 | ||
2474 | /* setup the udc->eps[] for non-control endpoints and link | 2475 | /* setup the udc->eps[] for non-control endpoints and link |
2475 | * to gadget.ep_list */ | 2476 | * to gadget.ep_list */ |
@@ -2666,7 +2667,7 @@ static struct platform_driver udc_driver = { | |||
2666 | .suspend = fsl_udc_suspend, | 2667 | .suspend = fsl_udc_suspend, |
2667 | .resume = fsl_udc_resume, | 2668 | .resume = fsl_udc_resume, |
2668 | .driver = { | 2669 | .driver = { |
2669 | .name = (char *)driver_name, | 2670 | .name = driver_name, |
2670 | .owner = THIS_MODULE, | 2671 | .owner = THIS_MODULE, |
2671 | /* udc suspend/resume called from OTG driver */ | 2672 | /* udc suspend/resume called from OTG driver */ |
2672 | .suspend = fsl_udc_otg_suspend, | 2673 | .suspend = fsl_udc_otg_suspend, |
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c index b278abe52453..6423f1840ed9 100644 --- a/drivers/usb/gadget/fusb300_udc.c +++ b/drivers/usb/gadget/fusb300_udc.c | |||
@@ -1452,9 +1452,9 @@ static int __init fusb300_probe(struct platform_device *pdev) | |||
1452 | INIT_LIST_HEAD(&ep->queue); | 1452 | INIT_LIST_HEAD(&ep->queue); |
1453 | ep->ep.name = fusb300_ep_name[i]; | 1453 | ep->ep.name = fusb300_ep_name[i]; |
1454 | ep->ep.ops = &fusb300_ep_ops; | 1454 | ep->ep.ops = &fusb300_ep_ops; |
1455 | ep->ep.maxpacket = HS_BULK_MAX_PACKET_SIZE; | 1455 | usb_ep_set_maxpacket_limit(&ep->ep, HS_BULK_MAX_PACKET_SIZE); |
1456 | } | 1456 | } |
1457 | fusb300->ep[0]->ep.maxpacket = HS_CTL_MAX_PACKET_SIZE; | 1457 | usb_ep_set_maxpacket_limit(&fusb300->ep[0]->ep, HS_CTL_MAX_PACKET_SIZE); |
1458 | fusb300->ep[0]->epnum = 0; | 1458 | fusb300->ep[0]->epnum = 0; |
1459 | fusb300->gadget.ep0 = &fusb300->ep[0]->ep; | 1459 | fusb300->gadget.ep0 = &fusb300->ep[0]->ep; |
1460 | INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list); | 1460 | INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list); |
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index 2344efe4f4ce..fe12e6a27448 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c | |||
@@ -13,14 +13,10 @@ | |||
13 | #define pr_fmt(fmt) "g_ffs: " fmt | 13 | #define pr_fmt(fmt) "g_ffs: " fmt |
14 | 14 | ||
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | /* | 16 | |
17 | * kbuild is not very cooperative with respect to linking separately | ||
18 | * compiled library objects into one module. So for now we won't use | ||
19 | * separate compilation ... ensuring init/exit sections work to shrink | ||
20 | * the runtime footprint, and giving us at least some parts of what | ||
21 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
22 | */ | ||
23 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS | 17 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS |
18 | #include <linux/netdevice.h> | ||
19 | |||
24 | # if defined USB_ETH_RNDIS | 20 | # if defined USB_ETH_RNDIS |
25 | # undef USB_ETH_RNDIS | 21 | # undef USB_ETH_RNDIS |
26 | # endif | 22 | # endif |
@@ -28,31 +24,31 @@ | |||
28 | # define USB_ETH_RNDIS y | 24 | # define USB_ETH_RNDIS y |
29 | # endif | 25 | # endif |
30 | 26 | ||
31 | #define USBF_ECM_INCLUDED | 27 | # include "u_ecm.h" |
32 | # include "f_ecm.c" | 28 | # include "u_gether.h" |
33 | #define USB_FSUBSET_INCLUDED | ||
34 | # include "f_subset.c" | ||
35 | # ifdef USB_ETH_RNDIS | 29 | # ifdef USB_ETH_RNDIS |
36 | # define USB_FRNDIS_INCLUDED | 30 | # include "u_rndis.h" |
37 | # include "f_rndis.c" | ||
38 | # include "rndis.h" | 31 | # include "rndis.h" |
39 | # endif | 32 | # endif |
40 | # include "u_ether.h" | 33 | # include "u_ether.h" |
41 | 34 | ||
42 | static u8 gfs_host_mac[ETH_ALEN]; | 35 | USB_ETHERNET_MODULE_PARAMETERS(); |
43 | static struct eth_dev *the_dev; | 36 | |
44 | # ifdef CONFIG_USB_FUNCTIONFS_ETH | 37 | # ifdef CONFIG_USB_FUNCTIONFS_ETH |
45 | static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | 38 | static int eth_bind_config(struct usb_configuration *c); |
46 | struct eth_dev *dev); | 39 | static struct usb_function_instance *fi_ecm; |
40 | static struct usb_function *f_ecm; | ||
41 | static struct usb_function_instance *fi_geth; | ||
42 | static struct usb_function *f_geth; | ||
43 | # endif | ||
44 | # ifdef CONFIG_USB_FUNCTIONFS_RNDIS | ||
45 | static int bind_rndis_config(struct usb_configuration *c); | ||
46 | static struct usb_function_instance *fi_rndis; | ||
47 | static struct usb_function *f_rndis; | ||
47 | # endif | 48 | # endif |
48 | #else | ||
49 | # define the_dev NULL | ||
50 | # define gether_cleanup(dev) do { } while (0) | ||
51 | # define gfs_host_mac NULL | ||
52 | struct eth_dev; | ||
53 | #endif | 49 | #endif |
54 | 50 | ||
55 | #include "f_fs.c" | 51 | #include "u_fs.h" |
56 | 52 | ||
57 | #define DRIVER_NAME "g_ffs" | 53 | #define DRIVER_NAME "g_ffs" |
58 | #define DRIVER_DESC "USB Function Filesystem" | 54 | #define DRIVER_DESC "USB Function Filesystem" |
@@ -67,19 +63,8 @@ MODULE_LICENSE("GPL"); | |||
67 | 63 | ||
68 | #define GFS_MAX_DEVS 10 | 64 | #define GFS_MAX_DEVS 10 |
69 | 65 | ||
70 | struct gfs_ffs_obj { | ||
71 | const char *name; | ||
72 | bool mounted; | ||
73 | bool desc_ready; | ||
74 | struct ffs_data *ffs_data; | ||
75 | }; | ||
76 | |||
77 | USB_GADGET_COMPOSITE_OPTIONS(); | 66 | USB_GADGET_COMPOSITE_OPTIONS(); |
78 | 67 | ||
79 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS | ||
80 | USB_ETHERNET_MODULE_PARAMETERS(); | ||
81 | #endif | ||
82 | |||
83 | static struct usb_device_descriptor gfs_dev_desc = { | 68 | static struct usb_device_descriptor gfs_dev_desc = { |
84 | .bLength = sizeof gfs_dev_desc, | 69 | .bLength = sizeof gfs_dev_desc, |
85 | .bDescriptorType = USB_DT_DEVICE, | 70 | .bDescriptorType = USB_DT_DEVICE, |
@@ -146,12 +131,12 @@ static struct usb_gadget_strings *gfs_dev_strings[] = { | |||
146 | 131 | ||
147 | struct gfs_configuration { | 132 | struct gfs_configuration { |
148 | struct usb_configuration c; | 133 | struct usb_configuration c; |
149 | int (*eth)(struct usb_configuration *c, u8 *ethaddr, | 134 | int (*eth)(struct usb_configuration *c); |
150 | struct eth_dev *dev); | 135 | int num; |
151 | } gfs_configurations[] = { | 136 | } gfs_configurations[] = { |
152 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | 137 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
153 | { | 138 | { |
154 | .eth = rndis_bind_config, | 139 | .eth = bind_rndis_config, |
155 | }, | 140 | }, |
156 | #endif | 141 | #endif |
157 | 142 | ||
@@ -167,10 +152,15 @@ struct gfs_configuration { | |||
167 | #endif | 152 | #endif |
168 | }; | 153 | }; |
169 | 154 | ||
155 | static void *functionfs_acquire_dev(struct ffs_dev *dev); | ||
156 | static void functionfs_release_dev(struct ffs_dev *dev); | ||
157 | static int functionfs_ready_callback(struct ffs_data *ffs); | ||
158 | static void functionfs_closed_callback(struct ffs_data *ffs); | ||
170 | static int gfs_bind(struct usb_composite_dev *cdev); | 159 | static int gfs_bind(struct usb_composite_dev *cdev); |
171 | static int gfs_unbind(struct usb_composite_dev *cdev); | 160 | static int gfs_unbind(struct usb_composite_dev *cdev); |
172 | static int gfs_do_config(struct usb_configuration *c); | 161 | static int gfs_do_config(struct usb_configuration *c); |
173 | 162 | ||
163 | |||
174 | static __refdata struct usb_composite_driver gfs_driver = { | 164 | static __refdata struct usb_composite_driver gfs_driver = { |
175 | .name = DRIVER_NAME, | 165 | .name = DRIVER_NAME, |
176 | .dev = &gfs_dev_desc, | 166 | .dev = &gfs_dev_desc, |
@@ -180,206 +170,244 @@ static __refdata struct usb_composite_driver gfs_driver = { | |||
180 | .unbind = gfs_unbind, | 170 | .unbind = gfs_unbind, |
181 | }; | 171 | }; |
182 | 172 | ||
183 | static DEFINE_MUTEX(gfs_lock); | ||
184 | static unsigned int missing_funcs; | 173 | static unsigned int missing_funcs; |
185 | static bool gfs_ether_setup; | ||
186 | static bool gfs_registered; | 174 | static bool gfs_registered; |
187 | static bool gfs_single_func; | 175 | static bool gfs_single_func; |
188 | static struct gfs_ffs_obj *ffs_tab; | 176 | static struct usb_function_instance **fi_ffs; |
177 | static struct usb_function **f_ffs[] = { | ||
178 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | ||
179 | NULL, | ||
180 | #endif | ||
181 | |||
182 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | ||
183 | NULL, | ||
184 | #endif | ||
185 | |||
186 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC | ||
187 | NULL, | ||
188 | #endif | ||
189 | }; | ||
190 | |||
191 | #define N_CONF ARRAY_SIZE(f_ffs) | ||
189 | 192 | ||
190 | static int __init gfs_init(void) | 193 | static int __init gfs_init(void) |
191 | { | 194 | { |
195 | struct f_fs_opts *opts; | ||
192 | int i; | 196 | int i; |
197 | int ret = 0; | ||
193 | 198 | ||
194 | ENTER(); | 199 | ENTER(); |
195 | 200 | ||
196 | if (!func_num) { | 201 | if (func_num < 2) { |
197 | gfs_single_func = true; | 202 | gfs_single_func = true; |
198 | func_num = 1; | 203 | func_num = 1; |
199 | } | 204 | } |
200 | 205 | ||
201 | ffs_tab = kcalloc(func_num, sizeof *ffs_tab, GFP_KERNEL); | 206 | /* |
202 | if (!ffs_tab) | 207 | * Allocate in one chunk for easier maintenance |
203 | return -ENOMEM; | 208 | */ |
209 | f_ffs[0] = kcalloc(func_num * N_CONF, sizeof(*f_ffs), GFP_KERNEL); | ||
210 | if (!f_ffs[0]) { | ||
211 | ret = -ENOMEM; | ||
212 | goto no_func; | ||
213 | } | ||
214 | for (i = 1; i < N_CONF; ++i) | ||
215 | f_ffs[i] = f_ffs[0] + i * func_num; | ||
204 | 216 | ||
205 | if (!gfs_single_func) | 217 | fi_ffs = kcalloc(func_num, sizeof(*fi_ffs), GFP_KERNEL); |
206 | for (i = 0; i < func_num; i++) | 218 | if (!fi_ffs) { |
207 | ffs_tab[i].name = func_names[i]; | 219 | ret = -ENOMEM; |
220 | goto no_func; | ||
221 | } | ||
222 | |||
223 | for (i = 0; i < func_num; i++) { | ||
224 | fi_ffs[i] = usb_get_function_instance("ffs"); | ||
225 | if (IS_ERR(fi_ffs[i])) { | ||
226 | ret = PTR_ERR(fi_ffs[i]); | ||
227 | --i; | ||
228 | goto no_dev; | ||
229 | } | ||
230 | opts = to_f_fs_opts(fi_ffs[i]); | ||
231 | if (gfs_single_func) | ||
232 | ret = ffs_single_dev(opts->dev); | ||
233 | else | ||
234 | ret = ffs_name_dev(opts->dev, func_names[i]); | ||
235 | if (ret) | ||
236 | goto no_dev; | ||
237 | opts->dev->ffs_ready_callback = functionfs_ready_callback; | ||
238 | opts->dev->ffs_closed_callback = functionfs_closed_callback; | ||
239 | opts->dev->ffs_acquire_dev_callback = functionfs_acquire_dev; | ||
240 | opts->dev->ffs_release_dev_callback = functionfs_release_dev; | ||
241 | opts->no_configfs = true; | ||
242 | } | ||
208 | 243 | ||
209 | missing_funcs = func_num; | 244 | missing_funcs = func_num; |
210 | 245 | ||
211 | return functionfs_init(); | 246 | return 0; |
247 | no_dev: | ||
248 | while (i >= 0) | ||
249 | usb_put_function_instance(fi_ffs[i--]); | ||
250 | kfree(fi_ffs); | ||
251 | no_func: | ||
252 | kfree(f_ffs[0]); | ||
253 | return ret; | ||
212 | } | 254 | } |
213 | module_init(gfs_init); | 255 | module_init(gfs_init); |
214 | 256 | ||
215 | static void __exit gfs_exit(void) | 257 | static void __exit gfs_exit(void) |
216 | { | 258 | { |
259 | int i; | ||
260 | |||
217 | ENTER(); | 261 | ENTER(); |
218 | mutex_lock(&gfs_lock); | ||
219 | 262 | ||
220 | if (gfs_registered) | 263 | if (gfs_registered) |
221 | usb_composite_unregister(&gfs_driver); | 264 | usb_composite_unregister(&gfs_driver); |
222 | gfs_registered = false; | 265 | gfs_registered = false; |
223 | 266 | ||
224 | functionfs_cleanup(); | 267 | kfree(f_ffs[0]); |
268 | |||
269 | for (i = 0; i < func_num; i++) | ||
270 | usb_put_function_instance(fi_ffs[i]); | ||
225 | 271 | ||
226 | mutex_unlock(&gfs_lock); | 272 | kfree(fi_ffs); |
227 | kfree(ffs_tab); | ||
228 | } | 273 | } |
229 | module_exit(gfs_exit); | 274 | module_exit(gfs_exit); |
230 | 275 | ||
231 | static struct gfs_ffs_obj *gfs_find_dev(const char *dev_name) | 276 | static void *functionfs_acquire_dev(struct ffs_dev *dev) |
232 | { | 277 | { |
233 | int i; | 278 | if (!try_module_get(THIS_MODULE)) |
234 | 279 | return ERR_PTR(-ENODEV); | |
235 | ENTER(); | 280 | |
236 | 281 | return 0; | |
237 | if (gfs_single_func) | 282 | } |
238 | return &ffs_tab[0]; | ||
239 | |||
240 | for (i = 0; i < func_num; i++) | ||
241 | if (strcmp(ffs_tab[i].name, dev_name) == 0) | ||
242 | return &ffs_tab[i]; | ||
243 | 283 | ||
244 | return NULL; | 284 | static void functionfs_release_dev(struct ffs_dev *dev) |
285 | { | ||
286 | module_put(THIS_MODULE); | ||
245 | } | 287 | } |
246 | 288 | ||
289 | /* | ||
290 | * The caller of this function takes ffs_lock | ||
291 | */ | ||
247 | static int functionfs_ready_callback(struct ffs_data *ffs) | 292 | static int functionfs_ready_callback(struct ffs_data *ffs) |
248 | { | 293 | { |
249 | struct gfs_ffs_obj *ffs_obj; | 294 | int ret = 0; |
250 | int ret; | ||
251 | |||
252 | ENTER(); | ||
253 | mutex_lock(&gfs_lock); | ||
254 | 295 | ||
255 | ffs_obj = ffs->private_data; | 296 | if (--missing_funcs) |
256 | if (!ffs_obj) { | 297 | return 0; |
257 | ret = -EINVAL; | ||
258 | goto done; | ||
259 | } | ||
260 | 298 | ||
261 | if (WARN_ON(ffs_obj->desc_ready)) { | 299 | if (gfs_registered) |
262 | ret = -EBUSY; | 300 | return -EBUSY; |
263 | goto done; | ||
264 | } | ||
265 | ffs_obj->desc_ready = true; | ||
266 | ffs_obj->ffs_data = ffs; | ||
267 | |||
268 | if (--missing_funcs) { | ||
269 | ret = 0; | ||
270 | goto done; | ||
271 | } | ||
272 | 301 | ||
273 | if (gfs_registered) { | ||
274 | ret = -EBUSY; | ||
275 | goto done; | ||
276 | } | ||
277 | gfs_registered = true; | 302 | gfs_registered = true; |
278 | 303 | ||
279 | ret = usb_composite_probe(&gfs_driver); | 304 | ret = usb_composite_probe(&gfs_driver); |
280 | if (unlikely(ret < 0)) | 305 | if (unlikely(ret < 0)) |
281 | gfs_registered = false; | 306 | gfs_registered = false; |
282 | 307 | ||
283 | done: | ||
284 | mutex_unlock(&gfs_lock); | ||
285 | return ret; | 308 | return ret; |
286 | } | 309 | } |
287 | 310 | ||
311 | /* | ||
312 | * The caller of this function takes ffs_lock | ||
313 | */ | ||
288 | static void functionfs_closed_callback(struct ffs_data *ffs) | 314 | static void functionfs_closed_callback(struct ffs_data *ffs) |
289 | { | 315 | { |
290 | struct gfs_ffs_obj *ffs_obj; | ||
291 | |||
292 | ENTER(); | ||
293 | mutex_lock(&gfs_lock); | ||
294 | |||
295 | ffs_obj = ffs->private_data; | ||
296 | if (!ffs_obj) | ||
297 | goto done; | ||
298 | |||
299 | ffs_obj->desc_ready = false; | ||
300 | missing_funcs++; | 316 | missing_funcs++; |
301 | 317 | ||
302 | if (gfs_registered) | 318 | if (gfs_registered) |
303 | usb_composite_unregister(&gfs_driver); | 319 | usb_composite_unregister(&gfs_driver); |
304 | gfs_registered = false; | 320 | gfs_registered = false; |
305 | |||
306 | done: | ||
307 | mutex_unlock(&gfs_lock); | ||
308 | } | 321 | } |
309 | 322 | ||
310 | static void *functionfs_acquire_dev_callback(const char *dev_name) | 323 | /* |
324 | * It is assumed that gfs_bind is called from a context where ffs_lock is held | ||
325 | */ | ||
326 | static int gfs_bind(struct usb_composite_dev *cdev) | ||
311 | { | 327 | { |
312 | struct gfs_ffs_obj *ffs_dev; | 328 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS |
329 | struct net_device *net; | ||
330 | #endif | ||
331 | int ret, i; | ||
313 | 332 | ||
314 | ENTER(); | 333 | ENTER(); |
315 | mutex_lock(&gfs_lock); | ||
316 | |||
317 | ffs_dev = gfs_find_dev(dev_name); | ||
318 | if (!ffs_dev) { | ||
319 | ffs_dev = ERR_PTR(-ENODEV); | ||
320 | goto done; | ||
321 | } | ||
322 | 334 | ||
323 | if (ffs_dev->mounted) { | 335 | if (missing_funcs) |
324 | ffs_dev = ERR_PTR(-EBUSY); | 336 | return -ENODEV; |
325 | goto done; | 337 | #if defined CONFIG_USB_FUNCTIONFS_ETH |
338 | if (can_support_ecm(cdev->gadget)) { | ||
339 | struct f_ecm_opts *ecm_opts; | ||
340 | |||
341 | fi_ecm = usb_get_function_instance("ecm"); | ||
342 | if (IS_ERR(fi_ecm)) | ||
343 | return PTR_ERR(fi_ecm); | ||
344 | ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); | ||
345 | net = ecm_opts->net; | ||
346 | } else { | ||
347 | struct f_gether_opts *geth_opts; | ||
348 | |||
349 | fi_geth = usb_get_function_instance("geth"); | ||
350 | if (IS_ERR(fi_geth)) | ||
351 | return PTR_ERR(fi_geth); | ||
352 | geth_opts = container_of(fi_geth, struct f_gether_opts, | ||
353 | func_inst); | ||
354 | net = geth_opts->net; | ||
326 | } | 355 | } |
327 | ffs_dev->mounted = true; | 356 | #endif |
328 | 357 | ||
329 | done: | 358 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
330 | mutex_unlock(&gfs_lock); | 359 | { |
331 | return ffs_dev; | 360 | struct f_rndis_opts *rndis_opts; |
332 | } | ||
333 | 361 | ||
334 | static void functionfs_release_dev_callback(struct ffs_data *ffs_data) | 362 | fi_rndis = usb_get_function_instance("rndis"); |
335 | { | 363 | if (IS_ERR(fi_rndis)) { |
336 | struct gfs_ffs_obj *ffs_dev; | 364 | ret = PTR_ERR(fi_rndis); |
365 | goto error; | ||
366 | } | ||
367 | rndis_opts = container_of(fi_rndis, struct f_rndis_opts, | ||
368 | func_inst); | ||
369 | #ifndef CONFIG_USB_FUNCTIONFS_ETH | ||
370 | net = rndis_opts->net; | ||
371 | #endif | ||
372 | } | ||
373 | #endif | ||
337 | 374 | ||
338 | ENTER(); | 375 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS |
339 | mutex_lock(&gfs_lock); | 376 | gether_set_qmult(net, qmult); |
377 | if (!gether_set_host_addr(net, host_addr)) | ||
378 | pr_info("using host ethernet address: %s", host_addr); | ||
379 | if (!gether_set_dev_addr(net, dev_addr)) | ||
380 | pr_info("using self ethernet address: %s", dev_addr); | ||
381 | #endif | ||
340 | 382 | ||
341 | ffs_dev = ffs_data->private_data; | 383 | #if defined CONFIG_USB_FUNCTIONFS_RNDIS && defined CONFIG_USB_FUNCTIONFS_ETH |
342 | if (ffs_dev) | 384 | gether_set_gadget(net, cdev->gadget); |
343 | ffs_dev->mounted = false; | 385 | ret = gether_register_netdev(net); |
386 | if (ret) | ||
387 | goto error_rndis; | ||
344 | 388 | ||
345 | mutex_unlock(&gfs_lock); | 389 | if (can_support_ecm(cdev->gadget)) { |
346 | } | 390 | struct f_ecm_opts *ecm_opts; |
347 | 391 | ||
348 | /* | 392 | ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); |
349 | * It is assumed that gfs_bind is called from a context where gfs_lock is held | 393 | ecm_opts->bound = true; |
350 | */ | 394 | } else { |
351 | static int gfs_bind(struct usb_composite_dev *cdev) | 395 | struct f_gether_opts *geth_opts; |
352 | { | ||
353 | int ret, i; | ||
354 | 396 | ||
355 | ENTER(); | 397 | geth_opts = container_of(fi_geth, struct f_gether_opts, |
398 | func_inst); | ||
399 | geth_opts->bound = true; | ||
400 | } | ||
356 | 401 | ||
357 | if (missing_funcs) | 402 | rndis_borrow_net(fi_rndis, net); |
358 | return -ENODEV; | ||
359 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS | ||
360 | the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, gfs_host_mac, | ||
361 | qmult); | ||
362 | #endif | 403 | #endif |
363 | if (IS_ERR(the_dev)) { | ||
364 | ret = PTR_ERR(the_dev); | ||
365 | goto error_quick; | ||
366 | } | ||
367 | gfs_ether_setup = true; | ||
368 | 404 | ||
405 | /* TODO: gstrings_attach? */ | ||
369 | ret = usb_string_ids_tab(cdev, gfs_strings); | 406 | ret = usb_string_ids_tab(cdev, gfs_strings); |
370 | if (unlikely(ret < 0)) | 407 | if (unlikely(ret < 0)) |
371 | goto error; | 408 | goto error_rndis; |
372 | gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id; | 409 | gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id; |
373 | 410 | ||
374 | for (i = func_num; i--; ) { | ||
375 | ret = functionfs_bind(ffs_tab[i].ffs_data, cdev); | ||
376 | if (unlikely(ret < 0)) { | ||
377 | while (++i < func_num) | ||
378 | functionfs_unbind(ffs_tab[i].ffs_data); | ||
379 | goto error; | ||
380 | } | ||
381 | } | ||
382 | |||
383 | for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { | 411 | for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { |
384 | struct gfs_configuration *c = gfs_configurations + i; | 412 | struct gfs_configuration *c = gfs_configurations + i; |
385 | int sid = USB_GADGET_FIRST_AVAIL_IDX + i; | 413 | int sid = USB_GADGET_FIRST_AVAIL_IDX + i; |
@@ -389,6 +417,8 @@ static int gfs_bind(struct usb_composite_dev *cdev) | |||
389 | c->c.bConfigurationValue = 1 + i; | 417 | c->c.bConfigurationValue = 1 + i; |
390 | c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; | 418 | c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; |
391 | 419 | ||
420 | c->num = i; | ||
421 | |||
392 | ret = usb_add_config(cdev, &c->c, gfs_do_config); | 422 | ret = usb_add_config(cdev, &c->c, gfs_do_config); |
393 | if (unlikely(ret < 0)) | 423 | if (unlikely(ret < 0)) |
394 | goto error_unbind; | 424 | goto error_unbind; |
@@ -396,18 +426,24 @@ static int gfs_bind(struct usb_composite_dev *cdev) | |||
396 | usb_composite_overwrite_options(cdev, &coverwrite); | 426 | usb_composite_overwrite_options(cdev, &coverwrite); |
397 | return 0; | 427 | return 0; |
398 | 428 | ||
429 | /* TODO */ | ||
399 | error_unbind: | 430 | error_unbind: |
400 | for (i = 0; i < func_num; i++) | 431 | error_rndis: |
401 | functionfs_unbind(ffs_tab[i].ffs_data); | 432 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
433 | usb_put_function_instance(fi_rndis); | ||
402 | error: | 434 | error: |
403 | gether_cleanup(the_dev); | 435 | #endif |
404 | error_quick: | 436 | #if defined CONFIG_USB_FUNCTIONFS_ETH |
405 | gfs_ether_setup = false; | 437 | if (can_support_ecm(cdev->gadget)) |
438 | usb_put_function_instance(fi_ecm); | ||
439 | else | ||
440 | usb_put_function_instance(fi_geth); | ||
441 | #endif | ||
406 | return ret; | 442 | return ret; |
407 | } | 443 | } |
408 | 444 | ||
409 | /* | 445 | /* |
410 | * It is assumed that gfs_unbind is called from a context where gfs_lock is held | 446 | * It is assumed that gfs_unbind is called from a context where ffs_lock is held |
411 | */ | 447 | */ |
412 | static int gfs_unbind(struct usb_composite_dev *cdev) | 448 | static int gfs_unbind(struct usb_composite_dev *cdev) |
413 | { | 449 | { |
@@ -415,28 +451,30 @@ static int gfs_unbind(struct usb_composite_dev *cdev) | |||
415 | 451 | ||
416 | ENTER(); | 452 | ENTER(); |
417 | 453 | ||
418 | /* | ||
419 | * We may have been called in an error recovery from | ||
420 | * composite_bind() after gfs_unbind() failure so we need to | ||
421 | * check if gfs_ffs_data is not NULL since gfs_bind() handles | ||
422 | * all error recovery itself. I'd rather we werent called | ||
423 | * from composite on orror recovery, but what you're gonna | ||
424 | * do...? | ||
425 | */ | ||
426 | if (gfs_ether_setup) | ||
427 | gether_cleanup(the_dev); | ||
428 | gfs_ether_setup = false; | ||
429 | 454 | ||
430 | for (i = func_num; i--; ) | 455 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
431 | if (ffs_tab[i].ffs_data) | 456 | usb_put_function(f_rndis); |
432 | functionfs_unbind(ffs_tab[i].ffs_data); | 457 | usb_put_function_instance(fi_rndis); |
458 | #endif | ||
459 | |||
460 | #if defined CONFIG_USB_FUNCTIONFS_ETH | ||
461 | if (can_support_ecm(cdev->gadget)) { | ||
462 | usb_put_function(f_ecm); | ||
463 | usb_put_function_instance(fi_ecm); | ||
464 | } else { | ||
465 | usb_put_function(f_geth); | ||
466 | usb_put_function_instance(fi_geth); | ||
467 | } | ||
468 | #endif | ||
469 | for (i = 0; i < N_CONF * func_num; ++i) | ||
470 | usb_put_function(*(f_ffs[0] + i)); | ||
433 | 471 | ||
434 | return 0; | 472 | return 0; |
435 | } | 473 | } |
436 | 474 | ||
437 | /* | 475 | /* |
438 | * It is assumed that gfs_do_config is called from a context where | 476 | * It is assumed that gfs_do_config is called from a context where |
439 | * gfs_lock is held | 477 | * ffs_lock is held |
440 | */ | 478 | */ |
441 | static int gfs_do_config(struct usb_configuration *c) | 479 | static int gfs_do_config(struct usb_configuration *c) |
442 | { | 480 | { |
@@ -454,15 +492,22 @@ static int gfs_do_config(struct usb_configuration *c) | |||
454 | } | 492 | } |
455 | 493 | ||
456 | if (gc->eth) { | 494 | if (gc->eth) { |
457 | ret = gc->eth(c, gfs_host_mac, the_dev); | 495 | ret = gc->eth(c); |
458 | if (unlikely(ret < 0)) | 496 | if (unlikely(ret < 0)) |
459 | return ret; | 497 | return ret; |
460 | } | 498 | } |
461 | 499 | ||
462 | for (i = 0; i < func_num; i++) { | 500 | for (i = 0; i < func_num; i++) { |
463 | ret = functionfs_bind_config(c->cdev, c, ffs_tab[i].ffs_data); | 501 | f_ffs[gc->num][i] = usb_get_function(fi_ffs[i]); |
464 | if (unlikely(ret < 0)) | 502 | if (IS_ERR(f_ffs[gc->num][i])) { |
465 | return ret; | 503 | ret = PTR_ERR(f_ffs[gc->num][i]); |
504 | goto error; | ||
505 | } | ||
506 | ret = usb_add_function(c, f_ffs[gc->num][i]); | ||
507 | if (ret < 0) { | ||
508 | usb_put_function(f_ffs[gc->num][i]); | ||
509 | goto error; | ||
510 | } | ||
466 | } | 511 | } |
467 | 512 | ||
468 | /* | 513 | /* |
@@ -479,16 +524,59 @@ static int gfs_do_config(struct usb_configuration *c) | |||
479 | c->interface[c->next_interface_id] = NULL; | 524 | c->interface[c->next_interface_id] = NULL; |
480 | 525 | ||
481 | return 0; | 526 | return 0; |
527 | error: | ||
528 | while (--i >= 0) { | ||
529 | if (!IS_ERR(f_ffs[gc->num][i])) | ||
530 | usb_remove_function(c, f_ffs[gc->num][i]); | ||
531 | usb_put_function(f_ffs[gc->num][i]); | ||
532 | } | ||
533 | return ret; | ||
482 | } | 534 | } |
483 | 535 | ||
484 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | 536 | #ifdef CONFIG_USB_FUNCTIONFS_ETH |
485 | 537 | ||
486 | static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | 538 | static int eth_bind_config(struct usb_configuration *c) |
487 | struct eth_dev *dev) | 539 | { |
540 | int status = 0; | ||
541 | |||
542 | if (can_support_ecm(c->cdev->gadget)) { | ||
543 | f_ecm = usb_get_function(fi_ecm); | ||
544 | if (IS_ERR(f_ecm)) | ||
545 | return PTR_ERR(f_ecm); | ||
546 | |||
547 | status = usb_add_function(c, f_ecm); | ||
548 | if (status < 0) | ||
549 | usb_put_function(f_ecm); | ||
550 | |||
551 | } else { | ||
552 | f_geth = usb_get_function(fi_geth); | ||
553 | if (IS_ERR(f_geth)) | ||
554 | return PTR_ERR(f_geth); | ||
555 | |||
556 | status = usb_add_function(c, f_geth); | ||
557 | if (status < 0) | ||
558 | usb_put_function(f_geth); | ||
559 | } | ||
560 | return status; | ||
561 | } | ||
562 | |||
563 | #endif | ||
564 | |||
565 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | ||
566 | |||
567 | static int bind_rndis_config(struct usb_configuration *c) | ||
488 | { | 568 | { |
489 | return can_support_ecm(c->cdev->gadget) | 569 | int status = 0; |
490 | ? ecm_bind_config(c, ethaddr, dev) | 570 | |
491 | : geth_bind_config(c, ethaddr, dev); | 571 | f_rndis = usb_get_function(fi_rndis); |
572 | if (IS_ERR(f_rndis)) | ||
573 | return PTR_ERR(f_rndis); | ||
574 | |||
575 | status = usb_add_function(c, f_rndis); | ||
576 | if (status < 0) | ||
577 | usb_put_function(f_rndis); | ||
578 | |||
579 | return status; | ||
492 | } | 580 | } |
493 | 581 | ||
494 | #endif | 582 | #endif |
diff --git a/drivers/usb/gadget/g_zero.h b/drivers/usb/gadget/g_zero.h index ef3e8515272b..15f180904f8a 100644 --- a/drivers/usb/gadget/g_zero.h +++ b/drivers/usb/gadget/g_zero.h | |||
@@ -6,6 +6,11 @@ | |||
6 | #ifndef __G_ZERO_H | 6 | #ifndef __G_ZERO_H |
7 | #define __G_ZERO_H | 7 | #define __G_ZERO_H |
8 | 8 | ||
9 | #define GZERO_BULK_BUFLEN 4096 | ||
10 | #define GZERO_QLEN 32 | ||
11 | #define GZERO_ISOC_INTERVAL 4 | ||
12 | #define GZERO_ISOC_MAXPACKET 1024 | ||
13 | |||
9 | struct usb_zero_options { | 14 | struct usb_zero_options { |
10 | unsigned pattern; | 15 | unsigned pattern; |
11 | unsigned isoc_interval; | 16 | unsigned isoc_interval; |
@@ -24,19 +29,36 @@ struct f_ss_opts { | |||
24 | unsigned isoc_mult; | 29 | unsigned isoc_mult; |
25 | unsigned isoc_maxburst; | 30 | unsigned isoc_maxburst; |
26 | unsigned bulk_buflen; | 31 | unsigned bulk_buflen; |
32 | |||
33 | /* | ||
34 | * Read/write access to configfs attributes is handled by configfs. | ||
35 | * | ||
36 | * This is to protect the data from concurrent access by read/write | ||
37 | * and create symlink/remove symlink. | ||
38 | */ | ||
39 | struct mutex lock; | ||
40 | int refcnt; | ||
27 | }; | 41 | }; |
28 | 42 | ||
29 | struct f_lb_opts { | 43 | struct f_lb_opts { |
30 | struct usb_function_instance func_inst; | 44 | struct usb_function_instance func_inst; |
31 | unsigned bulk_buflen; | 45 | unsigned bulk_buflen; |
32 | unsigned qlen; | 46 | unsigned qlen; |
47 | |||
48 | /* | ||
49 | * Read/write access to configfs attributes is handled by configfs. | ||
50 | * | ||
51 | * This is to protect the data from concurrent access by read/write | ||
52 | * and create symlink/remove symlink. | ||
53 | */ | ||
54 | struct mutex lock; | ||
55 | int refcnt; | ||
33 | }; | 56 | }; |
34 | 57 | ||
35 | void lb_modexit(void); | 58 | void lb_modexit(void); |
36 | int lb_modinit(void); | 59 | int lb_modinit(void); |
37 | 60 | ||
38 | /* common utilities */ | 61 | /* common utilities */ |
39 | struct usb_request *alloc_ep_req(struct usb_ep *ep, int len); | ||
40 | void free_ep_req(struct usb_ep *ep, struct usb_request *req); | 62 | void free_ep_req(struct usb_ep *ep, struct usb_request *req); |
41 | void disable_endpoints(struct usb_composite_dev *cdev, | 63 | void disable_endpoints(struct usb_composite_dev *cdev, |
42 | struct usb_ep *in, struct usb_ep *out, | 64 | struct usb_ep *in, struct usb_ep *out, |
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c index f82768015715..6c85839e15ad 100644 --- a/drivers/usb/gadget/goku_udc.c +++ b/drivers/usb/gadget/goku_udc.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include <linux/ioport.h> | 30 | #include <linux/ioport.h> |
31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
32 | #include <linux/errno.h> | 32 | #include <linux/errno.h> |
33 | #include <linux/init.h> | ||
34 | #include <linux/timer.h> | 33 | #include <linux/timer.h> |
35 | #include <linux/list.h> | 34 | #include <linux/list.h> |
36 | #include <linux/interrupt.h> | 35 | #include <linux/interrupt.h> |
@@ -231,7 +230,7 @@ static void ep_reset(struct goku_udc_regs __iomem *regs, struct goku_ep *ep) | |||
231 | } | 230 | } |
232 | } | 231 | } |
233 | 232 | ||
234 | ep->ep.maxpacket = MAX_FIFO_SIZE; | 233 | usb_ep_set_maxpacket_limit(&ep->ep, MAX_FIFO_SIZE); |
235 | ep->ep.desc = NULL; | 234 | ep->ep.desc = NULL; |
236 | ep->stopped = 1; | 235 | ep->stopped = 1; |
237 | ep->irqs = 0; | 236 | ep->irqs = 0; |
@@ -1251,7 +1250,7 @@ static void udc_reinit (struct goku_udc *dev) | |||
1251 | } | 1250 | } |
1252 | 1251 | ||
1253 | dev->ep[0].reg_mode = NULL; | 1252 | dev->ep[0].reg_mode = NULL; |
1254 | dev->ep[0].ep.maxpacket = MAX_EP0_SIZE; | 1253 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, MAX_EP0_SIZE); |
1255 | list_del_init (&dev->ep[0].ep.ep_list); | 1254 | list_del_init (&dev->ep[0].ep.ep_list); |
1256 | } | 1255 | } |
1257 | 1256 | ||
@@ -1350,16 +1349,12 @@ static int goku_udc_start(struct usb_gadget *g, | |||
1350 | return 0; | 1349 | return 0; |
1351 | } | 1350 | } |
1352 | 1351 | ||
1353 | static void | 1352 | static void stop_activity(struct goku_udc *dev) |
1354 | stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver) | ||
1355 | { | 1353 | { |
1356 | unsigned i; | 1354 | unsigned i; |
1357 | 1355 | ||
1358 | DBG (dev, "%s\n", __func__); | 1356 | DBG (dev, "%s\n", __func__); |
1359 | 1357 | ||
1360 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
1361 | driver = NULL; | ||
1362 | |||
1363 | /* disconnect gadget driver after quiesceing hw and the driver */ | 1358 | /* disconnect gadget driver after quiesceing hw and the driver */ |
1364 | udc_reset (dev); | 1359 | udc_reset (dev); |
1365 | for (i = 0; i < 4; i++) | 1360 | for (i = 0; i < 4; i++) |
@@ -1377,7 +1372,7 @@ static int goku_udc_stop(struct usb_gadget *g, | |||
1377 | 1372 | ||
1378 | spin_lock_irqsave(&dev->lock, flags); | 1373 | spin_lock_irqsave(&dev->lock, flags); |
1379 | dev->driver = NULL; | 1374 | dev->driver = NULL; |
1380 | stop_activity(dev, driver); | 1375 | stop_activity(dev); |
1381 | spin_unlock_irqrestore(&dev->lock, flags); | 1376 | spin_unlock_irqrestore(&dev->lock, flags); |
1382 | 1377 | ||
1383 | return 0; | 1378 | return 0; |
@@ -1521,7 +1516,7 @@ rescan: | |||
1521 | if (unlikely(stat & INT_DEVWIDE)) { | 1516 | if (unlikely(stat & INT_DEVWIDE)) { |
1522 | if (stat & INT_SYSERROR) { | 1517 | if (stat & INT_SYSERROR) { |
1523 | ERROR(dev, "system error\n"); | 1518 | ERROR(dev, "system error\n"); |
1524 | stop_activity(dev, dev->driver); | 1519 | stop_activity(dev); |
1525 | stat = 0; | 1520 | stat = 0; |
1526 | handled = 1; | 1521 | handled = 1; |
1527 | // FIXME have a neater way to prevent re-enumeration | 1522 | // FIXME have a neater way to prevent re-enumeration |
@@ -1536,7 +1531,7 @@ rescan: | |||
1536 | } else { | 1531 | } else { |
1537 | DBG(dev, "disconnect\n"); | 1532 | DBG(dev, "disconnect\n"); |
1538 | if (dev->gadget.speed == USB_SPEED_FULL) | 1533 | if (dev->gadget.speed == USB_SPEED_FULL) |
1539 | stop_activity(dev, dev->driver); | 1534 | stop_activity(dev); |
1540 | dev->ep0state = EP0_DISCONNECT; | 1535 | dev->ep0state = EP0_DISCONNECT; |
1541 | dev->int_enable = INT_DEVWIDE; | 1536 | dev->int_enable = INT_DEVWIDE; |
1542 | writel(dev->int_enable, &dev->regs->int_enable); | 1537 | writel(dev->int_enable, &dev->regs->int_enable); |
diff --git a/drivers/usb/gadget/gr_udc.c b/drivers/usb/gadget/gr_udc.c new file mode 100644 index 000000000000..914cbd84ee40 --- /dev/null +++ b/drivers/usb/gadget/gr_udc.c | |||
@@ -0,0 +1,2238 @@ | |||
1 | /* | ||
2 | * USB Peripheral Controller driver for Aeroflex Gaisler GRUSBDC. | ||
3 | * | ||
4 | * 2013 (c) Aeroflex Gaisler AB | ||
5 | * | ||
6 | * This driver supports GRUSBDC USB Device Controller cores available in the | ||
7 | * GRLIB VHDL IP core library. | ||
8 | * | ||
9 | * Full documentation of the GRUSBDC core can be found here: | ||
10 | * http://www.gaisler.com/products/grlib/grip.pdf | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify it | ||
13 | * under the terms of the GNU General Public License as published by the | ||
14 | * Free Software Foundation; either version 2 of the License, or (at your | ||
15 | * option) any later version. | ||
16 | * | ||
17 | * Contributors: | ||
18 | * - Andreas Larsson <andreas@gaisler.com> | ||
19 | * - Marko Isomaki | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * A GRUSBDC core can have up to 16 IN endpoints and 16 OUT endpoints each | ||
24 | * individually configurable to any of the four USB transfer types. This driver | ||
25 | * only supports cores in DMA mode. | ||
26 | */ | ||
27 | |||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <linux/spinlock.h> | ||
32 | #include <linux/errno.h> | ||
33 | #include <linux/list.h> | ||
34 | #include <linux/interrupt.h> | ||
35 | #include <linux/device.h> | ||
36 | #include <linux/usb/ch9.h> | ||
37 | #include <linux/usb/gadget.h> | ||
38 | #include <linux/dma-mapping.h> | ||
39 | #include <linux/dmapool.h> | ||
40 | #include <linux/debugfs.h> | ||
41 | #include <linux/seq_file.h> | ||
42 | #include <linux/of_platform.h> | ||
43 | #include <linux/of_irq.h> | ||
44 | #include <linux/of_address.h> | ||
45 | |||
46 | #include <asm/byteorder.h> | ||
47 | |||
48 | #include "gr_udc.h" | ||
49 | |||
50 | #define DRIVER_NAME "gr_udc" | ||
51 | #define DRIVER_DESC "Aeroflex Gaisler GRUSBDC USB Peripheral Controller" | ||
52 | |||
53 | static const char driver_name[] = DRIVER_NAME; | ||
54 | static const char driver_desc[] = DRIVER_DESC; | ||
55 | |||
56 | #define gr_read32(x) (ioread32be((x))) | ||
57 | #define gr_write32(x, v) (iowrite32be((v), (x))) | ||
58 | |||
59 | /* USB speed and corresponding string calculated from status register value */ | ||
60 | #define GR_SPEED(status) \ | ||
61 | ((status & GR_STATUS_SP) ? USB_SPEED_FULL : USB_SPEED_HIGH) | ||
62 | #define GR_SPEED_STR(status) usb_speed_string(GR_SPEED(status)) | ||
63 | |||
64 | /* Size of hardware buffer calculated from epctrl register value */ | ||
65 | #define GR_BUFFER_SIZE(epctrl) \ | ||
66 | ((((epctrl) & GR_EPCTRL_BUFSZ_MASK) >> GR_EPCTRL_BUFSZ_POS) * \ | ||
67 | GR_EPCTRL_BUFSZ_SCALER) | ||
68 | |||
69 | /* ---------------------------------------------------------------------- */ | ||
70 | /* Debug printout functionality */ | ||
71 | |||
72 | static const char * const gr_modestring[] = {"control", "iso", "bulk", "int"}; | ||
73 | |||
74 | static const char *gr_ep0state_string(enum gr_ep0state state) | ||
75 | { | ||
76 | static const char *const names[] = { | ||
77 | [GR_EP0_DISCONNECT] = "disconnect", | ||
78 | [GR_EP0_SETUP] = "setup", | ||
79 | [GR_EP0_IDATA] = "idata", | ||
80 | [GR_EP0_ODATA] = "odata", | ||
81 | [GR_EP0_ISTATUS] = "istatus", | ||
82 | [GR_EP0_OSTATUS] = "ostatus", | ||
83 | [GR_EP0_STALL] = "stall", | ||
84 | [GR_EP0_SUSPEND] = "suspend", | ||
85 | }; | ||
86 | |||
87 | if (state < 0 || state >= ARRAY_SIZE(names)) | ||
88 | return "UNKNOWN"; | ||
89 | |||
90 | return names[state]; | ||
91 | } | ||
92 | |||
93 | #ifdef VERBOSE_DEBUG | ||
94 | |||
95 | static void gr_dbgprint_request(const char *str, struct gr_ep *ep, | ||
96 | struct gr_request *req) | ||
97 | { | ||
98 | int buflen = ep->is_in ? req->req.length : req->req.actual; | ||
99 | int rowlen = 32; | ||
100 | int plen = min(rowlen, buflen); | ||
101 | |||
102 | dev_dbg(ep->dev->dev, "%s: 0x%p, %d bytes data%s:\n", str, req, buflen, | ||
103 | (buflen > plen ? " (truncated)" : "")); | ||
104 | print_hex_dump_debug(" ", DUMP_PREFIX_NONE, | ||
105 | rowlen, 4, req->req.buf, plen, false); | ||
106 | } | ||
107 | |||
108 | static void gr_dbgprint_devreq(struct gr_udc *dev, u8 type, u8 request, | ||
109 | u16 value, u16 index, u16 length) | ||
110 | { | ||
111 | dev_vdbg(dev->dev, "REQ: %02x.%02x v%04x i%04x l%04x\n", | ||
112 | type, request, value, index, length); | ||
113 | } | ||
114 | #else /* !VERBOSE_DEBUG */ | ||
115 | |||
116 | static void gr_dbgprint_request(const char *str, struct gr_ep *ep, | ||
117 | struct gr_request *req) {} | ||
118 | |||
119 | static void gr_dbgprint_devreq(struct gr_udc *dev, u8 type, u8 request, | ||
120 | u16 value, u16 index, u16 length) {} | ||
121 | |||
122 | #endif /* VERBOSE_DEBUG */ | ||
123 | |||
124 | /* ---------------------------------------------------------------------- */ | ||
125 | /* Debugfs functionality */ | ||
126 | |||
127 | #ifdef CONFIG_USB_GADGET_DEBUG_FS | ||
128 | |||
129 | static void gr_seq_ep_show(struct seq_file *seq, struct gr_ep *ep) | ||
130 | { | ||
131 | u32 epctrl = gr_read32(&ep->regs->epctrl); | ||
132 | u32 epstat = gr_read32(&ep->regs->epstat); | ||
133 | int mode = (epctrl & GR_EPCTRL_TT_MASK) >> GR_EPCTRL_TT_POS; | ||
134 | struct gr_request *req; | ||
135 | |||
136 | seq_printf(seq, "%s:\n", ep->ep.name); | ||
137 | seq_printf(seq, " mode = %s\n", gr_modestring[mode]); | ||
138 | seq_printf(seq, " halted: %d\n", !!(epctrl & GR_EPCTRL_EH)); | ||
139 | seq_printf(seq, " disabled: %d\n", !!(epctrl & GR_EPCTRL_ED)); | ||
140 | seq_printf(seq, " valid: %d\n", !!(epctrl & GR_EPCTRL_EV)); | ||
141 | seq_printf(seq, " dma_start = %d\n", ep->dma_start); | ||
142 | seq_printf(seq, " stopped = %d\n", ep->stopped); | ||
143 | seq_printf(seq, " wedged = %d\n", ep->wedged); | ||
144 | seq_printf(seq, " callback = %d\n", ep->callback); | ||
145 | seq_printf(seq, " maxpacket = %d\n", ep->ep.maxpacket); | ||
146 | seq_printf(seq, " bytes_per_buffer = %d\n", ep->bytes_per_buffer); | ||
147 | if (mode == 1 || mode == 3) | ||
148 | seq_printf(seq, " nt = %d\n", | ||
149 | (epctrl & GR_EPCTRL_NT_MASK) >> GR_EPCTRL_NT_POS); | ||
150 | |||
151 | seq_printf(seq, " Buffer 0: %s %s%d\n", | ||
152 | epstat & GR_EPSTAT_B0 ? "valid" : "invalid", | ||
153 | epstat & GR_EPSTAT_BS ? " " : "selected ", | ||
154 | (epstat & GR_EPSTAT_B0CNT_MASK) >> GR_EPSTAT_B0CNT_POS); | ||
155 | seq_printf(seq, " Buffer 1: %s %s%d\n", | ||
156 | epstat & GR_EPSTAT_B1 ? "valid" : "invalid", | ||
157 | epstat & GR_EPSTAT_BS ? "selected " : " ", | ||
158 | (epstat & GR_EPSTAT_B1CNT_MASK) >> GR_EPSTAT_B1CNT_POS); | ||
159 | |||
160 | if (list_empty(&ep->queue)) { | ||
161 | seq_puts(seq, " Queue: empty\n\n"); | ||
162 | return; | ||
163 | } | ||
164 | |||
165 | seq_puts(seq, " Queue:\n"); | ||
166 | list_for_each_entry(req, &ep->queue, queue) { | ||
167 | struct gr_dma_desc *desc; | ||
168 | struct gr_dma_desc *next; | ||
169 | |||
170 | seq_printf(seq, " 0x%p: 0x%p %d %d\n", req, | ||
171 | &req->req.buf, req->req.actual, req->req.length); | ||
172 | |||
173 | next = req->first_desc; | ||
174 | do { | ||
175 | desc = next; | ||
176 | next = desc->next_desc; | ||
177 | seq_printf(seq, " %c 0x%p (0x%08x): 0x%05x 0x%08x\n", | ||
178 | desc == req->curr_desc ? 'c' : ' ', | ||
179 | desc, desc->paddr, desc->ctrl, desc->data); | ||
180 | } while (desc != req->last_desc); | ||
181 | } | ||
182 | seq_puts(seq, "\n"); | ||
183 | } | ||
184 | |||
185 | |||
186 | static int gr_seq_show(struct seq_file *seq, void *v) | ||
187 | { | ||
188 | struct gr_udc *dev = seq->private; | ||
189 | u32 control = gr_read32(&dev->regs->control); | ||
190 | u32 status = gr_read32(&dev->regs->status); | ||
191 | struct gr_ep *ep; | ||
192 | |||
193 | seq_printf(seq, "usb state = %s\n", | ||
194 | usb_state_string(dev->gadget.state)); | ||
195 | seq_printf(seq, "address = %d\n", | ||
196 | (control & GR_CONTROL_UA_MASK) >> GR_CONTROL_UA_POS); | ||
197 | seq_printf(seq, "speed = %s\n", GR_SPEED_STR(status)); | ||
198 | seq_printf(seq, "ep0state = %s\n", gr_ep0state_string(dev->ep0state)); | ||
199 | seq_printf(seq, "irq_enabled = %d\n", dev->irq_enabled); | ||
200 | seq_printf(seq, "remote_wakeup = %d\n", dev->remote_wakeup); | ||
201 | seq_printf(seq, "test_mode = %d\n", dev->test_mode); | ||
202 | seq_puts(seq, "\n"); | ||
203 | |||
204 | list_for_each_entry(ep, &dev->ep_list, ep_list) | ||
205 | gr_seq_ep_show(seq, ep); | ||
206 | |||
207 | return 0; | ||
208 | } | ||
209 | |||
210 | static int gr_dfs_open(struct inode *inode, struct file *file) | ||
211 | { | ||
212 | return single_open(file, gr_seq_show, inode->i_private); | ||
213 | } | ||
214 | |||
215 | static const struct file_operations gr_dfs_fops = { | ||
216 | .owner = THIS_MODULE, | ||
217 | .open = gr_dfs_open, | ||
218 | .read = seq_read, | ||
219 | .llseek = seq_lseek, | ||
220 | .release = single_release, | ||
221 | }; | ||
222 | |||
223 | static void gr_dfs_create(struct gr_udc *dev) | ||
224 | { | ||
225 | const char *name = "gr_udc_state"; | ||
226 | |||
227 | dev->dfs_root = debugfs_create_dir(dev_name(dev->dev), NULL); | ||
228 | if (IS_ERR(dev->dfs_root)) { | ||
229 | dev_err(dev->dev, "Failed to create debugfs directory\n"); | ||
230 | return; | ||
231 | } | ||
232 | dev->dfs_state = debugfs_create_file(name, 0444, dev->dfs_root, | ||
233 | dev, &gr_dfs_fops); | ||
234 | if (IS_ERR(dev->dfs_state)) | ||
235 | dev_err(dev->dev, "Failed to create debugfs file %s\n", name); | ||
236 | } | ||
237 | |||
238 | static void gr_dfs_delete(struct gr_udc *dev) | ||
239 | { | ||
240 | /* Handles NULL and ERR pointers internally */ | ||
241 | debugfs_remove(dev->dfs_state); | ||
242 | debugfs_remove(dev->dfs_root); | ||
243 | } | ||
244 | |||
245 | #else /* !CONFIG_USB_GADGET_DEBUG_FS */ | ||
246 | |||
247 | static void gr_dfs_create(struct gr_udc *dev) {} | ||
248 | static void gr_dfs_delete(struct gr_udc *dev) {} | ||
249 | |||
250 | #endif /* CONFIG_USB_GADGET_DEBUG_FS */ | ||
251 | |||
252 | /* ---------------------------------------------------------------------- */ | ||
253 | /* DMA and request handling */ | ||
254 | |||
255 | /* Allocates a new struct gr_dma_desc, sets paddr and zeroes the rest */ | ||
256 | static struct gr_dma_desc *gr_alloc_dma_desc(struct gr_ep *ep, gfp_t gfp_flags) | ||
257 | { | ||
258 | dma_addr_t paddr; | ||
259 | struct gr_dma_desc *dma_desc; | ||
260 | |||
261 | dma_desc = dma_pool_alloc(ep->dev->desc_pool, gfp_flags, &paddr); | ||
262 | if (!dma_desc) { | ||
263 | dev_err(ep->dev->dev, "Could not allocate from DMA pool\n"); | ||
264 | return NULL; | ||
265 | } | ||
266 | |||
267 | memset(dma_desc, 0, sizeof(*dma_desc)); | ||
268 | dma_desc->paddr = paddr; | ||
269 | |||
270 | return dma_desc; | ||
271 | } | ||
272 | |||
273 | static inline void gr_free_dma_desc(struct gr_udc *dev, | ||
274 | struct gr_dma_desc *desc) | ||
275 | { | ||
276 | dma_pool_free(dev->desc_pool, desc, (dma_addr_t)desc->paddr); | ||
277 | } | ||
278 | |||
279 | /* Frees the chain of struct gr_dma_desc for the given request */ | ||
280 | static void gr_free_dma_desc_chain(struct gr_udc *dev, struct gr_request *req) | ||
281 | { | ||
282 | struct gr_dma_desc *desc; | ||
283 | struct gr_dma_desc *next; | ||
284 | |||
285 | next = req->first_desc; | ||
286 | if (!next) | ||
287 | return; | ||
288 | |||
289 | do { | ||
290 | desc = next; | ||
291 | next = desc->next_desc; | ||
292 | gr_free_dma_desc(dev, desc); | ||
293 | } while (desc != req->last_desc); | ||
294 | |||
295 | req->first_desc = NULL; | ||
296 | req->curr_desc = NULL; | ||
297 | req->last_desc = NULL; | ||
298 | } | ||
299 | |||
300 | static void gr_ep0_setup(struct gr_udc *dev, struct gr_request *req); | ||
301 | |||
302 | /* | ||
303 | * Frees allocated resources and calls the appropriate completion function/setup | ||
304 | * package handler for a finished request. | ||
305 | * | ||
306 | * Must be called with dev->lock held and irqs disabled. | ||
307 | */ | ||
308 | static void gr_finish_request(struct gr_ep *ep, struct gr_request *req, | ||
309 | int status) | ||
310 | __releases(&dev->lock) | ||
311 | __acquires(&dev->lock) | ||
312 | { | ||
313 | struct gr_udc *dev; | ||
314 | |||
315 | list_del_init(&req->queue); | ||
316 | |||
317 | if (likely(req->req.status == -EINPROGRESS)) | ||
318 | req->req.status = status; | ||
319 | else | ||
320 | status = req->req.status; | ||
321 | |||
322 | dev = ep->dev; | ||
323 | usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in); | ||
324 | gr_free_dma_desc_chain(dev, req); | ||
325 | |||
326 | if (ep->is_in) /* For OUT, actual gets updated bit by bit */ | ||
327 | req->req.actual = req->req.length; | ||
328 | |||
329 | if (!status) { | ||
330 | if (ep->is_in) | ||
331 | gr_dbgprint_request("SENT", ep, req); | ||
332 | else | ||
333 | gr_dbgprint_request("RECV", ep, req); | ||
334 | } | ||
335 | |||
336 | /* Prevent changes to ep->queue during callback */ | ||
337 | ep->callback = 1; | ||
338 | if (req == dev->ep0reqo && !status) { | ||
339 | if (req->setup) | ||
340 | gr_ep0_setup(dev, req); | ||
341 | else | ||
342 | dev_err(dev->dev, | ||
343 | "Unexpected non setup packet on ep0in\n"); | ||
344 | } else if (req->req.complete) { | ||
345 | spin_unlock(&dev->lock); | ||
346 | |||
347 | req->req.complete(&ep->ep, &req->req); | ||
348 | |||
349 | spin_lock(&dev->lock); | ||
350 | } | ||
351 | ep->callback = 0; | ||
352 | } | ||
353 | |||
354 | static struct usb_request *gr_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) | ||
355 | { | ||
356 | struct gr_request *req; | ||
357 | |||
358 | req = kzalloc(sizeof(*req), gfp_flags); | ||
359 | if (!req) | ||
360 | return NULL; | ||
361 | |||
362 | INIT_LIST_HEAD(&req->queue); | ||
363 | |||
364 | return &req->req; | ||
365 | } | ||
366 | |||
367 | /* | ||
368 | * Starts DMA for endpoint ep if there are requests in the queue. | ||
369 | * | ||
370 | * Must be called with dev->lock held and with !ep->stopped. | ||
371 | */ | ||
372 | static void gr_start_dma(struct gr_ep *ep) | ||
373 | { | ||
374 | struct gr_request *req; | ||
375 | u32 dmactrl; | ||
376 | |||
377 | if (list_empty(&ep->queue)) { | ||
378 | ep->dma_start = 0; | ||
379 | return; | ||
380 | } | ||
381 | |||
382 | req = list_first_entry(&ep->queue, struct gr_request, queue); | ||
383 | |||
384 | /* A descriptor should already have been allocated */ | ||
385 | BUG_ON(!req->curr_desc); | ||
386 | |||
387 | wmb(); /* Make sure all is settled before handing it over to DMA */ | ||
388 | |||
389 | /* Set the descriptor pointer in the hardware */ | ||
390 | gr_write32(&ep->regs->dmaaddr, req->curr_desc->paddr); | ||
391 | |||
392 | /* Announce available descriptors */ | ||
393 | dmactrl = gr_read32(&ep->regs->dmactrl); | ||
394 | gr_write32(&ep->regs->dmactrl, dmactrl | GR_DMACTRL_DA); | ||
395 | |||
396 | ep->dma_start = 1; | ||
397 | } | ||
398 | |||
399 | /* | ||
400 | * Finishes the first request in the ep's queue and, if available, starts the | ||
401 | * next request in queue. | ||
402 | * | ||
403 | * Must be called with dev->lock held, irqs disabled and with !ep->stopped. | ||
404 | */ | ||
405 | static void gr_dma_advance(struct gr_ep *ep, int status) | ||
406 | { | ||
407 | struct gr_request *req; | ||
408 | |||
409 | req = list_first_entry(&ep->queue, struct gr_request, queue); | ||
410 | gr_finish_request(ep, req, status); | ||
411 | gr_start_dma(ep); /* Regardless of ep->dma_start */ | ||
412 | } | ||
413 | |||
414 | /* | ||
415 | * Abort DMA for an endpoint. Sets the abort DMA bit which causes an ongoing DMA | ||
416 | * transfer to be canceled and clears GR_DMACTRL_DA. | ||
417 | * | ||
418 | * Must be called with dev->lock held. | ||
419 | */ | ||
420 | static void gr_abort_dma(struct gr_ep *ep) | ||
421 | { | ||
422 | u32 dmactrl; | ||
423 | |||
424 | dmactrl = gr_read32(&ep->regs->dmactrl); | ||
425 | gr_write32(&ep->regs->dmactrl, dmactrl | GR_DMACTRL_AD); | ||
426 | } | ||
427 | |||
428 | /* | ||
429 | * Allocates and sets up a struct gr_dma_desc and putting it on the descriptor | ||
430 | * chain. | ||
431 | * | ||
432 | * Size is not used for OUT endpoints. Hardware can not be instructed to handle | ||
433 | * smaller buffer than MAXPL in the OUT direction. | ||
434 | */ | ||
435 | static int gr_add_dma_desc(struct gr_ep *ep, struct gr_request *req, | ||
436 | dma_addr_t data, unsigned size, gfp_t gfp_flags) | ||
437 | { | ||
438 | struct gr_dma_desc *desc; | ||
439 | |||
440 | desc = gr_alloc_dma_desc(ep, gfp_flags); | ||
441 | if (!desc) | ||
442 | return -ENOMEM; | ||
443 | |||
444 | desc->data = data; | ||
445 | if (ep->is_in) | ||
446 | desc->ctrl = | ||
447 | (GR_DESC_IN_CTRL_LEN_MASK & size) | GR_DESC_IN_CTRL_EN; | ||
448 | else | ||
449 | desc->ctrl = GR_DESC_OUT_CTRL_IE; | ||
450 | |||
451 | if (!req->first_desc) { | ||
452 | req->first_desc = desc; | ||
453 | req->curr_desc = desc; | ||
454 | } else { | ||
455 | req->last_desc->next_desc = desc; | ||
456 | req->last_desc->next = desc->paddr; | ||
457 | req->last_desc->ctrl |= GR_DESC_OUT_CTRL_NX; | ||
458 | } | ||
459 | req->last_desc = desc; | ||
460 | |||
461 | return 0; | ||
462 | } | ||
463 | |||
464 | /* | ||
465 | * Sets up a chain of struct gr_dma_descriptors pointing to buffers that | ||
466 | * together covers req->req.length bytes of the buffer at DMA address | ||
467 | * req->req.dma for the OUT direction. | ||
468 | * | ||
469 | * The first descriptor in the chain is enabled, the rest disabled. The | ||
470 | * interrupt handler will later enable them one by one when needed so we can | ||
471 | * find out when the transfer is finished. For OUT endpoints, all descriptors | ||
472 | * therefore generate interrutps. | ||
473 | */ | ||
474 | static int gr_setup_out_desc_list(struct gr_ep *ep, struct gr_request *req, | ||
475 | gfp_t gfp_flags) | ||
476 | { | ||
477 | u16 bytes_left; /* Bytes left to provide descriptors for */ | ||
478 | u16 bytes_used; /* Bytes accommodated for */ | ||
479 | int ret = 0; | ||
480 | |||
481 | req->first_desc = NULL; /* Signals that no allocation is done yet */ | ||
482 | bytes_left = req->req.length; | ||
483 | bytes_used = 0; | ||
484 | while (bytes_left > 0) { | ||
485 | dma_addr_t start = req->req.dma + bytes_used; | ||
486 | u16 size = min(bytes_left, ep->bytes_per_buffer); | ||
487 | |||
488 | /* Should not happen however - gr_queue stops such lengths */ | ||
489 | if (size < ep->bytes_per_buffer) | ||
490 | dev_warn(ep->dev->dev, | ||
491 | "Buffer overrun risk: %u < %u bytes/buffer\n", | ||
492 | size, ep->bytes_per_buffer); | ||
493 | |||
494 | ret = gr_add_dma_desc(ep, req, start, size, gfp_flags); | ||
495 | if (ret) | ||
496 | goto alloc_err; | ||
497 | |||
498 | bytes_left -= size; | ||
499 | bytes_used += size; | ||
500 | } | ||
501 | |||
502 | req->first_desc->ctrl |= GR_DESC_OUT_CTRL_EN; | ||
503 | |||
504 | return 0; | ||
505 | |||
506 | alloc_err: | ||
507 | gr_free_dma_desc_chain(ep->dev, req); | ||
508 | |||
509 | return ret; | ||
510 | } | ||
511 | |||
512 | /* | ||
513 | * Sets up a chain of struct gr_dma_descriptors pointing to buffers that | ||
514 | * together covers req->req.length bytes of the buffer at DMA address | ||
515 | * req->req.dma for the IN direction. | ||
516 | * | ||
517 | * When more data is provided than the maximum payload size, the hardware splits | ||
518 | * this up into several payloads automatically. Moreover, ep->bytes_per_buffer | ||
519 | * is always set to a multiple of the maximum payload (restricted to the valid | ||
520 | * number of maximum payloads during high bandwidth isochronous or interrupt | ||
521 | * transfers) | ||
522 | * | ||
523 | * All descriptors are enabled from the beginning and we only generate an | ||
524 | * interrupt for the last one indicating that the entire request has been pushed | ||
525 | * to hardware. | ||
526 | */ | ||
527 | static int gr_setup_in_desc_list(struct gr_ep *ep, struct gr_request *req, | ||
528 | gfp_t gfp_flags) | ||
529 | { | ||
530 | u16 bytes_left; /* Bytes left in req to provide descriptors for */ | ||
531 | u16 bytes_used; /* Bytes in req accommodated for */ | ||
532 | int ret = 0; | ||
533 | |||
534 | req->first_desc = NULL; /* Signals that no allocation is done yet */ | ||
535 | bytes_left = req->req.length; | ||
536 | bytes_used = 0; | ||
537 | do { /* Allow for zero length packets */ | ||
538 | dma_addr_t start = req->req.dma + bytes_used; | ||
539 | u16 size = min(bytes_left, ep->bytes_per_buffer); | ||
540 | |||
541 | ret = gr_add_dma_desc(ep, req, start, size, gfp_flags); | ||
542 | if (ret) | ||
543 | goto alloc_err; | ||
544 | |||
545 | bytes_left -= size; | ||
546 | bytes_used += size; | ||
547 | } while (bytes_left > 0); | ||
548 | |||
549 | /* | ||
550 | * Send an extra zero length packet to indicate that no more data is | ||
551 | * available when req->req.zero is set and the data length is even | ||
552 | * multiples of ep->ep.maxpacket. | ||
553 | */ | ||
554 | if (req->req.zero && (req->req.length % ep->ep.maxpacket == 0)) { | ||
555 | ret = gr_add_dma_desc(ep, req, 0, 0, gfp_flags); | ||
556 | if (ret) | ||
557 | goto alloc_err; | ||
558 | } | ||
559 | |||
560 | /* | ||
561 | * For IN packets we only want to know when the last packet has been | ||
562 | * transmitted (not just put into internal buffers). | ||
563 | */ | ||
564 | req->last_desc->ctrl |= GR_DESC_IN_CTRL_PI; | ||
565 | |||
566 | return 0; | ||
567 | |||
568 | alloc_err: | ||
569 | gr_free_dma_desc_chain(ep->dev, req); | ||
570 | |||
571 | return ret; | ||
572 | } | ||
573 | |||
574 | /* Must be called with dev->lock held */ | ||
575 | static int gr_queue(struct gr_ep *ep, struct gr_request *req, gfp_t gfp_flags) | ||
576 | { | ||
577 | struct gr_udc *dev = ep->dev; | ||
578 | int ret; | ||
579 | |||
580 | if (unlikely(!ep->ep.desc && ep->num != 0)) { | ||
581 | dev_err(dev->dev, "No ep descriptor for %s\n", ep->ep.name); | ||
582 | return -EINVAL; | ||
583 | } | ||
584 | |||
585 | if (unlikely(!req->req.buf || !list_empty(&req->queue))) { | ||
586 | dev_err(dev->dev, | ||
587 | "Invalid request for %s: buf=%p list_empty=%d\n", | ||
588 | ep->ep.name, req->req.buf, list_empty(&req->queue)); | ||
589 | return -EINVAL; | ||
590 | } | ||
591 | |||
592 | /* | ||
593 | * The DMA controller can not handle smaller OUT buffers than | ||
594 | * maxpacket. It could lead to buffer overruns if unexpectedly long | ||
595 | * packet are received. | ||
596 | */ | ||
597 | if (!ep->is_in && (req->req.length % ep->ep.maxpacket) != 0) { | ||
598 | dev_err(dev->dev, | ||
599 | "OUT request length %d is not multiple of maxpacket\n", | ||
600 | req->req.length); | ||
601 | return -EMSGSIZE; | ||
602 | } | ||
603 | |||
604 | if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) { | ||
605 | dev_err(dev->dev, "-ESHUTDOWN"); | ||
606 | return -ESHUTDOWN; | ||
607 | } | ||
608 | |||
609 | /* Can't touch registers when suspended */ | ||
610 | if (dev->ep0state == GR_EP0_SUSPEND) { | ||
611 | dev_err(dev->dev, "-EBUSY"); | ||
612 | return -EBUSY; | ||
613 | } | ||
614 | |||
615 | /* Set up DMA mapping in case the caller didn't */ | ||
616 | ret = usb_gadget_map_request(&dev->gadget, &req->req, ep->is_in); | ||
617 | if (ret) { | ||
618 | dev_err(dev->dev, "usb_gadget_map_request"); | ||
619 | return ret; | ||
620 | } | ||
621 | |||
622 | if (ep->is_in) | ||
623 | ret = gr_setup_in_desc_list(ep, req, gfp_flags); | ||
624 | else | ||
625 | ret = gr_setup_out_desc_list(ep, req, gfp_flags); | ||
626 | if (ret) | ||
627 | return ret; | ||
628 | |||
629 | req->req.status = -EINPROGRESS; | ||
630 | req->req.actual = 0; | ||
631 | list_add_tail(&req->queue, &ep->queue); | ||
632 | |||
633 | /* Start DMA if not started, otherwise interrupt handler handles it */ | ||
634 | if (!ep->dma_start && likely(!ep->stopped)) | ||
635 | gr_start_dma(ep); | ||
636 | |||
637 | return 0; | ||
638 | } | ||
639 | |||
640 | /* | ||
641 | * Queue a request from within the driver. | ||
642 | * | ||
643 | * Must be called with dev->lock held. | ||
644 | */ | ||
645 | static inline int gr_queue_int(struct gr_ep *ep, struct gr_request *req, | ||
646 | gfp_t gfp_flags) | ||
647 | { | ||
648 | if (ep->is_in) | ||
649 | gr_dbgprint_request("RESP", ep, req); | ||
650 | |||
651 | return gr_queue(ep, req, gfp_flags); | ||
652 | } | ||
653 | |||
654 | /* ---------------------------------------------------------------------- */ | ||
655 | /* General helper functions */ | ||
656 | |||
657 | /* | ||
658 | * Dequeue ALL requests. | ||
659 | * | ||
660 | * Must be called with dev->lock held and irqs disabled. | ||
661 | */ | ||
662 | static void gr_ep_nuke(struct gr_ep *ep) | ||
663 | { | ||
664 | struct gr_request *req; | ||
665 | |||
666 | ep->stopped = 1; | ||
667 | ep->dma_start = 0; | ||
668 | gr_abort_dma(ep); | ||
669 | |||
670 | while (!list_empty(&ep->queue)) { | ||
671 | req = list_first_entry(&ep->queue, struct gr_request, queue); | ||
672 | gr_finish_request(ep, req, -ESHUTDOWN); | ||
673 | } | ||
674 | } | ||
675 | |||
676 | /* | ||
677 | * Reset the hardware state of this endpoint. | ||
678 | * | ||
679 | * Must be called with dev->lock held. | ||
680 | */ | ||
681 | static void gr_ep_reset(struct gr_ep *ep) | ||
682 | { | ||
683 | gr_write32(&ep->regs->epctrl, 0); | ||
684 | gr_write32(&ep->regs->dmactrl, 0); | ||
685 | |||
686 | ep->ep.maxpacket = MAX_CTRL_PL_SIZE; | ||
687 | ep->ep.desc = NULL; | ||
688 | ep->stopped = 1; | ||
689 | ep->dma_start = 0; | ||
690 | } | ||
691 | |||
692 | /* | ||
693 | * Generate STALL on ep0in/out. | ||
694 | * | ||
695 | * Must be called with dev->lock held. | ||
696 | */ | ||
697 | static void gr_control_stall(struct gr_udc *dev) | ||
698 | { | ||
699 | u32 epctrl; | ||
700 | |||
701 | epctrl = gr_read32(&dev->epo[0].regs->epctrl); | ||
702 | gr_write32(&dev->epo[0].regs->epctrl, epctrl | GR_EPCTRL_CS); | ||
703 | epctrl = gr_read32(&dev->epi[0].regs->epctrl); | ||
704 | gr_write32(&dev->epi[0].regs->epctrl, epctrl | GR_EPCTRL_CS); | ||
705 | |||
706 | dev->ep0state = GR_EP0_STALL; | ||
707 | } | ||
708 | |||
709 | /* | ||
710 | * Halts, halts and wedges, or clears halt for an endpoint. | ||
711 | * | ||
712 | * Must be called with dev->lock held. | ||
713 | */ | ||
714 | static int gr_ep_halt_wedge(struct gr_ep *ep, int halt, int wedge, int fromhost) | ||
715 | { | ||
716 | u32 epctrl; | ||
717 | int retval = 0; | ||
718 | |||
719 | if (ep->num && !ep->ep.desc) | ||
720 | return -EINVAL; | ||
721 | |||
722 | if (ep->num && ep->ep.desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) | ||
723 | return -EOPNOTSUPP; | ||
724 | |||
725 | /* Never actually halt ep0, and therefore never clear halt for ep0 */ | ||
726 | if (!ep->num) { | ||
727 | if (halt && !fromhost) { | ||
728 | /* ep0 halt from gadget - generate protocol stall */ | ||
729 | gr_control_stall(ep->dev); | ||
730 | dev_dbg(ep->dev->dev, "EP: stall ep0\n"); | ||
731 | return 0; | ||
732 | } | ||
733 | return -EINVAL; | ||
734 | } | ||
735 | |||
736 | dev_dbg(ep->dev->dev, "EP: %s halt %s\n", | ||
737 | (halt ? (wedge ? "wedge" : "set") : "clear"), ep->ep.name); | ||
738 | |||
739 | epctrl = gr_read32(&ep->regs->epctrl); | ||
740 | if (halt) { | ||
741 | /* Set HALT */ | ||
742 | gr_write32(&ep->regs->epctrl, epctrl | GR_EPCTRL_EH); | ||
743 | ep->stopped = 1; | ||
744 | if (wedge) | ||
745 | ep->wedged = 1; | ||
746 | } else { | ||
747 | gr_write32(&ep->regs->epctrl, epctrl & ~GR_EPCTRL_EH); | ||
748 | ep->stopped = 0; | ||
749 | ep->wedged = 0; | ||
750 | |||
751 | /* Things might have been queued up in the meantime */ | ||
752 | if (!ep->dma_start) | ||
753 | gr_start_dma(ep); | ||
754 | } | ||
755 | |||
756 | return retval; | ||
757 | } | ||
758 | |||
759 | /* Must be called with dev->lock held */ | ||
760 | static inline void gr_set_ep0state(struct gr_udc *dev, enum gr_ep0state value) | ||
761 | { | ||
762 | if (dev->ep0state != value) | ||
763 | dev_vdbg(dev->dev, "STATE: ep0state=%s\n", | ||
764 | gr_ep0state_string(value)); | ||
765 | dev->ep0state = value; | ||
766 | } | ||
767 | |||
768 | /* | ||
769 | * Should only be called when endpoints can not generate interrupts. | ||
770 | * | ||
771 | * Must be called with dev->lock held. | ||
772 | */ | ||
773 | static void gr_disable_interrupts_and_pullup(struct gr_udc *dev) | ||
774 | { | ||
775 | gr_write32(&dev->regs->control, 0); | ||
776 | wmb(); /* Make sure that we do not deny one of our interrupts */ | ||
777 | dev->irq_enabled = 0; | ||
778 | } | ||
779 | |||
780 | /* | ||
781 | * Stop all device activity and disable data line pullup. | ||
782 | * | ||
783 | * Must be called with dev->lock held and irqs disabled. | ||
784 | */ | ||
785 | static void gr_stop_activity(struct gr_udc *dev) | ||
786 | { | ||
787 | struct gr_ep *ep; | ||
788 | |||
789 | list_for_each_entry(ep, &dev->ep_list, ep_list) | ||
790 | gr_ep_nuke(ep); | ||
791 | |||
792 | gr_disable_interrupts_and_pullup(dev); | ||
793 | |||
794 | gr_set_ep0state(dev, GR_EP0_DISCONNECT); | ||
795 | usb_gadget_set_state(&dev->gadget, USB_STATE_NOTATTACHED); | ||
796 | } | ||
797 | |||
798 | /* ---------------------------------------------------------------------- */ | ||
799 | /* ep0 setup packet handling */ | ||
800 | |||
801 | static void gr_ep0_testmode_complete(struct usb_ep *_ep, | ||
802 | struct usb_request *_req) | ||
803 | { | ||
804 | struct gr_ep *ep; | ||
805 | struct gr_udc *dev; | ||
806 | u32 control; | ||
807 | |||
808 | ep = container_of(_ep, struct gr_ep, ep); | ||
809 | dev = ep->dev; | ||
810 | |||
811 | spin_lock(&dev->lock); | ||
812 | |||
813 | control = gr_read32(&dev->regs->control); | ||
814 | control |= GR_CONTROL_TM | (dev->test_mode << GR_CONTROL_TS_POS); | ||
815 | gr_write32(&dev->regs->control, control); | ||
816 | |||
817 | spin_unlock(&dev->lock); | ||
818 | } | ||
819 | |||
820 | static void gr_ep0_dummy_complete(struct usb_ep *_ep, struct usb_request *_req) | ||
821 | { | ||
822 | /* Nothing needs to be done here */ | ||
823 | } | ||
824 | |||
825 | /* | ||
826 | * Queue a response on ep0in. | ||
827 | * | ||
828 | * Must be called with dev->lock held. | ||
829 | */ | ||
830 | static int gr_ep0_respond(struct gr_udc *dev, u8 *buf, int length, | ||
831 | void (*complete)(struct usb_ep *ep, | ||
832 | struct usb_request *req)) | ||
833 | { | ||
834 | u8 *reqbuf = dev->ep0reqi->req.buf; | ||
835 | int status; | ||
836 | int i; | ||
837 | |||
838 | for (i = 0; i < length; i++) | ||
839 | reqbuf[i] = buf[i]; | ||
840 | dev->ep0reqi->req.length = length; | ||
841 | dev->ep0reqi->req.complete = complete; | ||
842 | |||
843 | status = gr_queue_int(&dev->epi[0], dev->ep0reqi, GFP_ATOMIC); | ||
844 | if (status < 0) | ||
845 | dev_err(dev->dev, | ||
846 | "Could not queue ep0in setup response: %d\n", status); | ||
847 | |||
848 | return status; | ||
849 | } | ||
850 | |||
851 | /* | ||
852 | * Queue a 2 byte response on ep0in. | ||
853 | * | ||
854 | * Must be called with dev->lock held. | ||
855 | */ | ||
856 | static inline int gr_ep0_respond_u16(struct gr_udc *dev, u16 response) | ||
857 | { | ||
858 | __le16 le_response = cpu_to_le16(response); | ||
859 | |||
860 | return gr_ep0_respond(dev, (u8 *)&le_response, 2, | ||
861 | gr_ep0_dummy_complete); | ||
862 | } | ||
863 | |||
864 | /* | ||
865 | * Queue a ZLP response on ep0in. | ||
866 | * | ||
867 | * Must be called with dev->lock held. | ||
868 | */ | ||
869 | static inline int gr_ep0_respond_empty(struct gr_udc *dev) | ||
870 | { | ||
871 | return gr_ep0_respond(dev, NULL, 0, gr_ep0_dummy_complete); | ||
872 | } | ||
873 | |||
874 | /* | ||
875 | * This is run when a SET_ADDRESS request is received. First writes | ||
876 | * the new address to the control register which is updated internally | ||
877 | * when the next IN packet is ACKED. | ||
878 | * | ||
879 | * Must be called with dev->lock held. | ||
880 | */ | ||
881 | static void gr_set_address(struct gr_udc *dev, u8 address) | ||
882 | { | ||
883 | u32 control; | ||
884 | |||
885 | control = gr_read32(&dev->regs->control) & ~GR_CONTROL_UA_MASK; | ||
886 | control |= (address << GR_CONTROL_UA_POS) & GR_CONTROL_UA_MASK; | ||
887 | control |= GR_CONTROL_SU; | ||
888 | gr_write32(&dev->regs->control, control); | ||
889 | } | ||
890 | |||
891 | /* | ||
892 | * Returns negative for STALL, 0 for successful handling and positive for | ||
893 | * delegation. | ||
894 | * | ||
895 | * Must be called with dev->lock held. | ||
896 | */ | ||
897 | static int gr_device_request(struct gr_udc *dev, u8 type, u8 request, | ||
898 | u16 value, u16 index) | ||
899 | { | ||
900 | u16 response; | ||
901 | u8 test; | ||
902 | |||
903 | switch (request) { | ||
904 | case USB_REQ_SET_ADDRESS: | ||
905 | dev_dbg(dev->dev, "STATUS: address %d\n", value & 0xff); | ||
906 | gr_set_address(dev, value & 0xff); | ||
907 | if (value) | ||
908 | usb_gadget_set_state(&dev->gadget, USB_STATE_ADDRESS); | ||
909 | else | ||
910 | usb_gadget_set_state(&dev->gadget, USB_STATE_DEFAULT); | ||
911 | return gr_ep0_respond_empty(dev); | ||
912 | |||
913 | case USB_REQ_GET_STATUS: | ||
914 | /* Self powered | remote wakeup */ | ||
915 | response = 0x0001 | (dev->remote_wakeup ? 0x0002 : 0); | ||
916 | return gr_ep0_respond_u16(dev, response); | ||
917 | |||
918 | case USB_REQ_SET_FEATURE: | ||
919 | switch (value) { | ||
920 | case USB_DEVICE_REMOTE_WAKEUP: | ||
921 | /* Allow remote wakeup */ | ||
922 | dev->remote_wakeup = 1; | ||
923 | return gr_ep0_respond_empty(dev); | ||
924 | |||
925 | case USB_DEVICE_TEST_MODE: | ||
926 | /* The hardware does not support TEST_FORCE_EN */ | ||
927 | test = index >> 8; | ||
928 | if (test >= TEST_J && test <= TEST_PACKET) { | ||
929 | dev->test_mode = test; | ||
930 | return gr_ep0_respond(dev, NULL, 0, | ||
931 | gr_ep0_testmode_complete); | ||
932 | } | ||
933 | } | ||
934 | break; | ||
935 | |||
936 | case USB_REQ_CLEAR_FEATURE: | ||
937 | switch (value) { | ||
938 | case USB_DEVICE_REMOTE_WAKEUP: | ||
939 | /* Disallow remote wakeup */ | ||
940 | dev->remote_wakeup = 0; | ||
941 | return gr_ep0_respond_empty(dev); | ||
942 | } | ||
943 | break; | ||
944 | } | ||
945 | |||
946 | return 1; /* Delegate the rest */ | ||
947 | } | ||
948 | |||
949 | /* | ||
950 | * Returns negative for STALL, 0 for successful handling and positive for | ||
951 | * delegation. | ||
952 | * | ||
953 | * Must be called with dev->lock held. | ||
954 | */ | ||
955 | static int gr_interface_request(struct gr_udc *dev, u8 type, u8 request, | ||
956 | u16 value, u16 index) | ||
957 | { | ||
958 | if (dev->gadget.state != USB_STATE_CONFIGURED) | ||
959 | return -1; | ||
960 | |||
961 | /* | ||
962 | * Should return STALL for invalid interfaces, but udc driver does not | ||
963 | * know anything about that. However, many gadget drivers do not handle | ||
964 | * GET_STATUS so we need to take care of that. | ||
965 | */ | ||
966 | |||
967 | switch (request) { | ||
968 | case USB_REQ_GET_STATUS: | ||
969 | return gr_ep0_respond_u16(dev, 0x0000); | ||
970 | |||
971 | case USB_REQ_SET_FEATURE: | ||
972 | case USB_REQ_CLEAR_FEATURE: | ||
973 | /* | ||
974 | * No possible valid standard requests. Still let gadget drivers | ||
975 | * have a go at it. | ||
976 | */ | ||
977 | break; | ||
978 | } | ||
979 | |||
980 | return 1; /* Delegate the rest */ | ||
981 | } | ||
982 | |||
983 | /* | ||
984 | * Returns negative for STALL, 0 for successful handling and positive for | ||
985 | * delegation. | ||
986 | * | ||
987 | * Must be called with dev->lock held. | ||
988 | */ | ||
989 | static int gr_endpoint_request(struct gr_udc *dev, u8 type, u8 request, | ||
990 | u16 value, u16 index) | ||
991 | { | ||
992 | struct gr_ep *ep; | ||
993 | int status; | ||
994 | int halted; | ||
995 | u8 epnum = index & USB_ENDPOINT_NUMBER_MASK; | ||
996 | u8 is_in = index & USB_ENDPOINT_DIR_MASK; | ||
997 | |||
998 | if ((is_in && epnum >= dev->nepi) || (!is_in && epnum >= dev->nepo)) | ||
999 | return -1; | ||
1000 | |||
1001 | if (dev->gadget.state != USB_STATE_CONFIGURED && epnum != 0) | ||
1002 | return -1; | ||
1003 | |||
1004 | ep = (is_in ? &dev->epi[epnum] : &dev->epo[epnum]); | ||
1005 | |||
1006 | switch (request) { | ||
1007 | case USB_REQ_GET_STATUS: | ||
1008 | halted = gr_read32(&ep->regs->epctrl) & GR_EPCTRL_EH; | ||
1009 | return gr_ep0_respond_u16(dev, halted ? 0x0001 : 0); | ||
1010 | |||
1011 | case USB_REQ_SET_FEATURE: | ||
1012 | switch (value) { | ||
1013 | case USB_ENDPOINT_HALT: | ||
1014 | status = gr_ep_halt_wedge(ep, 1, 0, 1); | ||
1015 | if (status >= 0) | ||
1016 | status = gr_ep0_respond_empty(dev); | ||
1017 | return status; | ||
1018 | } | ||
1019 | break; | ||
1020 | |||
1021 | case USB_REQ_CLEAR_FEATURE: | ||
1022 | switch (value) { | ||
1023 | case USB_ENDPOINT_HALT: | ||
1024 | if (ep->wedged) | ||
1025 | return -1; | ||
1026 | status = gr_ep_halt_wedge(ep, 0, 0, 1); | ||
1027 | if (status >= 0) | ||
1028 | status = gr_ep0_respond_empty(dev); | ||
1029 | return status; | ||
1030 | } | ||
1031 | break; | ||
1032 | } | ||
1033 | |||
1034 | return 1; /* Delegate the rest */ | ||
1035 | } | ||
1036 | |||
1037 | /* Must be called with dev->lock held */ | ||
1038 | static void gr_ep0out_requeue(struct gr_udc *dev) | ||
1039 | { | ||
1040 | int ret = gr_queue_int(&dev->epo[0], dev->ep0reqo, GFP_ATOMIC); | ||
1041 | |||
1042 | if (ret) | ||
1043 | dev_err(dev->dev, "Could not queue ep0out setup request: %d\n", | ||
1044 | ret); | ||
1045 | } | ||
1046 | |||
1047 | /* | ||
1048 | * The main function dealing with setup requests on ep0. | ||
1049 | * | ||
1050 | * Must be called with dev->lock held and irqs disabled | ||
1051 | */ | ||
1052 | static void gr_ep0_setup(struct gr_udc *dev, struct gr_request *req) | ||
1053 | __releases(&dev->lock) | ||
1054 | __acquires(&dev->lock) | ||
1055 | { | ||
1056 | union { | ||
1057 | struct usb_ctrlrequest ctrl; | ||
1058 | u8 raw[8]; | ||
1059 | u32 word[2]; | ||
1060 | } u; | ||
1061 | u8 type; | ||
1062 | u8 request; | ||
1063 | u16 value; | ||
1064 | u16 index; | ||
1065 | u16 length; | ||
1066 | int i; | ||
1067 | int status; | ||
1068 | |||
1069 | /* Restore from ep0 halt */ | ||
1070 | if (dev->ep0state == GR_EP0_STALL) { | ||
1071 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1072 | if (!req->req.actual) | ||
1073 | goto out; | ||
1074 | } | ||
1075 | |||
1076 | if (dev->ep0state == GR_EP0_ISTATUS) { | ||
1077 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1078 | if (req->req.actual > 0) | ||
1079 | dev_dbg(dev->dev, | ||
1080 | "Unexpected setup packet at state %s\n", | ||
1081 | gr_ep0state_string(GR_EP0_ISTATUS)); | ||
1082 | else | ||
1083 | goto out; /* Got expected ZLP */ | ||
1084 | } else if (dev->ep0state != GR_EP0_SETUP) { | ||
1085 | dev_info(dev->dev, | ||
1086 | "Unexpected ep0out request at state %s - stalling\n", | ||
1087 | gr_ep0state_string(dev->ep0state)); | ||
1088 | gr_control_stall(dev); | ||
1089 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1090 | goto out; | ||
1091 | } else if (!req->req.actual) { | ||
1092 | dev_dbg(dev->dev, "Unexpected ZLP at state %s\n", | ||
1093 | gr_ep0state_string(dev->ep0state)); | ||
1094 | goto out; | ||
1095 | } | ||
1096 | |||
1097 | /* Handle SETUP packet */ | ||
1098 | for (i = 0; i < req->req.actual; i++) | ||
1099 | u.raw[i] = ((u8 *)req->req.buf)[i]; | ||
1100 | |||
1101 | type = u.ctrl.bRequestType; | ||
1102 | request = u.ctrl.bRequest; | ||
1103 | value = le16_to_cpu(u.ctrl.wValue); | ||
1104 | index = le16_to_cpu(u.ctrl.wIndex); | ||
1105 | length = le16_to_cpu(u.ctrl.wLength); | ||
1106 | |||
1107 | gr_dbgprint_devreq(dev, type, request, value, index, length); | ||
1108 | |||
1109 | /* Check for data stage */ | ||
1110 | if (length) { | ||
1111 | if (type & USB_DIR_IN) | ||
1112 | gr_set_ep0state(dev, GR_EP0_IDATA); | ||
1113 | else | ||
1114 | gr_set_ep0state(dev, GR_EP0_ODATA); | ||
1115 | } | ||
1116 | |||
1117 | status = 1; /* Positive status flags delegation */ | ||
1118 | if ((type & USB_TYPE_MASK) == USB_TYPE_STANDARD) { | ||
1119 | switch (type & USB_RECIP_MASK) { | ||
1120 | case USB_RECIP_DEVICE: | ||
1121 | status = gr_device_request(dev, type, request, | ||
1122 | value, index); | ||
1123 | break; | ||
1124 | case USB_RECIP_ENDPOINT: | ||
1125 | status = gr_endpoint_request(dev, type, request, | ||
1126 | value, index); | ||
1127 | break; | ||
1128 | case USB_RECIP_INTERFACE: | ||
1129 | status = gr_interface_request(dev, type, request, | ||
1130 | value, index); | ||
1131 | break; | ||
1132 | } | ||
1133 | } | ||
1134 | |||
1135 | if (status > 0) { | ||
1136 | spin_unlock(&dev->lock); | ||
1137 | |||
1138 | dev_vdbg(dev->dev, "DELEGATE\n"); | ||
1139 | status = dev->driver->setup(&dev->gadget, &u.ctrl); | ||
1140 | |||
1141 | spin_lock(&dev->lock); | ||
1142 | } | ||
1143 | |||
1144 | /* Generate STALL on both ep0out and ep0in if requested */ | ||
1145 | if (unlikely(status < 0)) { | ||
1146 | dev_vdbg(dev->dev, "STALL\n"); | ||
1147 | gr_control_stall(dev); | ||
1148 | } | ||
1149 | |||
1150 | if ((type & USB_TYPE_MASK) == USB_TYPE_STANDARD && | ||
1151 | request == USB_REQ_SET_CONFIGURATION) { | ||
1152 | if (!value) { | ||
1153 | dev_dbg(dev->dev, "STATUS: deconfigured\n"); | ||
1154 | usb_gadget_set_state(&dev->gadget, USB_STATE_ADDRESS); | ||
1155 | } else if (status >= 0) { | ||
1156 | /* Not configured unless gadget OK:s it */ | ||
1157 | dev_dbg(dev->dev, "STATUS: configured: %d\n", value); | ||
1158 | usb_gadget_set_state(&dev->gadget, | ||
1159 | USB_STATE_CONFIGURED); | ||
1160 | } | ||
1161 | } | ||
1162 | |||
1163 | /* Get ready for next stage */ | ||
1164 | if (dev->ep0state == GR_EP0_ODATA) | ||
1165 | gr_set_ep0state(dev, GR_EP0_OSTATUS); | ||
1166 | else if (dev->ep0state == GR_EP0_IDATA) | ||
1167 | gr_set_ep0state(dev, GR_EP0_ISTATUS); | ||
1168 | else | ||
1169 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1170 | |||
1171 | out: | ||
1172 | gr_ep0out_requeue(dev); | ||
1173 | } | ||
1174 | |||
1175 | /* ---------------------------------------------------------------------- */ | ||
1176 | /* VBUS and USB reset handling */ | ||
1177 | |||
1178 | /* Must be called with dev->lock held and irqs disabled */ | ||
1179 | static void gr_vbus_connected(struct gr_udc *dev, u32 status) | ||
1180 | { | ||
1181 | u32 control; | ||
1182 | |||
1183 | dev->gadget.speed = GR_SPEED(status); | ||
1184 | usb_gadget_set_state(&dev->gadget, USB_STATE_POWERED); | ||
1185 | |||
1186 | /* Turn on full interrupts and pullup */ | ||
1187 | control = (GR_CONTROL_SI | GR_CONTROL_UI | GR_CONTROL_VI | | ||
1188 | GR_CONTROL_SP | GR_CONTROL_EP); | ||
1189 | gr_write32(&dev->regs->control, control); | ||
1190 | } | ||
1191 | |||
1192 | /* Must be called with dev->lock held */ | ||
1193 | static void gr_enable_vbus_detect(struct gr_udc *dev) | ||
1194 | { | ||
1195 | u32 status; | ||
1196 | |||
1197 | dev->irq_enabled = 1; | ||
1198 | wmb(); /* Make sure we do not ignore an interrupt */ | ||
1199 | gr_write32(&dev->regs->control, GR_CONTROL_VI); | ||
1200 | |||
1201 | /* Take care of the case we are already plugged in at this point */ | ||
1202 | status = gr_read32(&dev->regs->status); | ||
1203 | if (status & GR_STATUS_VB) | ||
1204 | gr_vbus_connected(dev, status); | ||
1205 | } | ||
1206 | |||
1207 | /* Must be called with dev->lock held and irqs disabled */ | ||
1208 | static void gr_vbus_disconnected(struct gr_udc *dev) | ||
1209 | { | ||
1210 | gr_stop_activity(dev); | ||
1211 | |||
1212 | /* Report disconnect */ | ||
1213 | if (dev->driver && dev->driver->disconnect) { | ||
1214 | spin_unlock(&dev->lock); | ||
1215 | |||
1216 | dev->driver->disconnect(&dev->gadget); | ||
1217 | |||
1218 | spin_lock(&dev->lock); | ||
1219 | } | ||
1220 | |||
1221 | gr_enable_vbus_detect(dev); | ||
1222 | } | ||
1223 | |||
1224 | /* Must be called with dev->lock held and irqs disabled */ | ||
1225 | static void gr_udc_usbreset(struct gr_udc *dev, u32 status) | ||
1226 | { | ||
1227 | gr_set_address(dev, 0); | ||
1228 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1229 | usb_gadget_set_state(&dev->gadget, USB_STATE_DEFAULT); | ||
1230 | dev->gadget.speed = GR_SPEED(status); | ||
1231 | |||
1232 | gr_ep_nuke(&dev->epo[0]); | ||
1233 | gr_ep_nuke(&dev->epi[0]); | ||
1234 | dev->epo[0].stopped = 0; | ||
1235 | dev->epi[0].stopped = 0; | ||
1236 | gr_ep0out_requeue(dev); | ||
1237 | } | ||
1238 | |||
1239 | /* ---------------------------------------------------------------------- */ | ||
1240 | /* Irq handling */ | ||
1241 | |||
1242 | /* | ||
1243 | * Handles interrupts from in endpoints. Returns whether something was handled. | ||
1244 | * | ||
1245 | * Must be called with dev->lock held, irqs disabled and with !ep->stopped. | ||
1246 | */ | ||
1247 | static int gr_handle_in_ep(struct gr_ep *ep) | ||
1248 | { | ||
1249 | struct gr_request *req; | ||
1250 | |||
1251 | req = list_first_entry(&ep->queue, struct gr_request, queue); | ||
1252 | if (!req->last_desc) | ||
1253 | return 0; | ||
1254 | |||
1255 | if (ACCESS_ONCE(req->last_desc->ctrl) & GR_DESC_IN_CTRL_EN) | ||
1256 | return 0; /* Not put in hardware buffers yet */ | ||
1257 | |||
1258 | if (gr_read32(&ep->regs->epstat) & (GR_EPSTAT_B1 | GR_EPSTAT_B0)) | ||
1259 | return 0; /* Not transmitted yet, still in hardware buffers */ | ||
1260 | |||
1261 | /* Write complete */ | ||
1262 | gr_dma_advance(ep, 0); | ||
1263 | |||
1264 | return 1; | ||
1265 | } | ||
1266 | |||
1267 | /* | ||
1268 | * Handles interrupts from out endpoints. Returns whether something was handled. | ||
1269 | * | ||
1270 | * Must be called with dev->lock held, irqs disabled and with !ep->stopped. | ||
1271 | */ | ||
1272 | static int gr_handle_out_ep(struct gr_ep *ep) | ||
1273 | { | ||
1274 | u32 ep_dmactrl; | ||
1275 | u32 ctrl; | ||
1276 | u16 len; | ||
1277 | struct gr_request *req; | ||
1278 | struct gr_udc *dev = ep->dev; | ||
1279 | |||
1280 | req = list_first_entry(&ep->queue, struct gr_request, queue); | ||
1281 | if (!req->curr_desc) | ||
1282 | return 0; | ||
1283 | |||
1284 | ctrl = ACCESS_ONCE(req->curr_desc->ctrl); | ||
1285 | if (ctrl & GR_DESC_OUT_CTRL_EN) | ||
1286 | return 0; /* Not received yet */ | ||
1287 | |||
1288 | /* Read complete */ | ||
1289 | len = ctrl & GR_DESC_OUT_CTRL_LEN_MASK; | ||
1290 | req->req.actual += len; | ||
1291 | if (ctrl & GR_DESC_OUT_CTRL_SE) | ||
1292 | req->setup = 1; | ||
1293 | |||
1294 | if (len < ep->ep.maxpacket || req->req.actual == req->req.length) { | ||
1295 | /* Short packet or the expected size - we are done */ | ||
1296 | |||
1297 | if ((ep == &dev->epo[0]) && (dev->ep0state == GR_EP0_OSTATUS)) { | ||
1298 | /* | ||
1299 | * Send a status stage ZLP to ack the DATA stage in the | ||
1300 | * OUT direction. This needs to be done before | ||
1301 | * gr_dma_advance as that can lead to a call to | ||
1302 | * ep0_setup that can change dev->ep0state. | ||
1303 | */ | ||
1304 | gr_ep0_respond_empty(dev); | ||
1305 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1306 | } | ||
1307 | |||
1308 | gr_dma_advance(ep, 0); | ||
1309 | } else { | ||
1310 | /* Not done yet. Enable the next descriptor to receive more. */ | ||
1311 | req->curr_desc = req->curr_desc->next_desc; | ||
1312 | req->curr_desc->ctrl |= GR_DESC_OUT_CTRL_EN; | ||
1313 | |||
1314 | ep_dmactrl = gr_read32(&ep->regs->dmactrl); | ||
1315 | gr_write32(&ep->regs->dmactrl, ep_dmactrl | GR_DMACTRL_DA); | ||
1316 | } | ||
1317 | |||
1318 | return 1; | ||
1319 | } | ||
1320 | |||
1321 | /* | ||
1322 | * Handle state changes. Returns whether something was handled. | ||
1323 | * | ||
1324 | * Must be called with dev->lock held and irqs disabled. | ||
1325 | */ | ||
1326 | static int gr_handle_state_changes(struct gr_udc *dev) | ||
1327 | { | ||
1328 | u32 status = gr_read32(&dev->regs->status); | ||
1329 | int handled = 0; | ||
1330 | int powstate = !(dev->gadget.state == USB_STATE_NOTATTACHED || | ||
1331 | dev->gadget.state == USB_STATE_ATTACHED); | ||
1332 | |||
1333 | /* VBUS valid detected */ | ||
1334 | if (!powstate && (status & GR_STATUS_VB)) { | ||
1335 | dev_dbg(dev->dev, "STATUS: vbus valid detected\n"); | ||
1336 | gr_vbus_connected(dev, status); | ||
1337 | handled = 1; | ||
1338 | } | ||
1339 | |||
1340 | /* Disconnect */ | ||
1341 | if (powstate && !(status & GR_STATUS_VB)) { | ||
1342 | dev_dbg(dev->dev, "STATUS: vbus invalid detected\n"); | ||
1343 | gr_vbus_disconnected(dev); | ||
1344 | handled = 1; | ||
1345 | } | ||
1346 | |||
1347 | /* USB reset detected */ | ||
1348 | if (status & GR_STATUS_UR) { | ||
1349 | dev_dbg(dev->dev, "STATUS: USB reset - speed is %s\n", | ||
1350 | GR_SPEED_STR(status)); | ||
1351 | gr_write32(&dev->regs->status, GR_STATUS_UR); | ||
1352 | gr_udc_usbreset(dev, status); | ||
1353 | handled = 1; | ||
1354 | } | ||
1355 | |||
1356 | /* Speed change */ | ||
1357 | if (dev->gadget.speed != GR_SPEED(status)) { | ||
1358 | dev_dbg(dev->dev, "STATUS: USB Speed change to %s\n", | ||
1359 | GR_SPEED_STR(status)); | ||
1360 | dev->gadget.speed = GR_SPEED(status); | ||
1361 | handled = 1; | ||
1362 | } | ||
1363 | |||
1364 | /* Going into suspend */ | ||
1365 | if ((dev->ep0state != GR_EP0_SUSPEND) && !(status & GR_STATUS_SU)) { | ||
1366 | dev_dbg(dev->dev, "STATUS: USB suspend\n"); | ||
1367 | gr_set_ep0state(dev, GR_EP0_SUSPEND); | ||
1368 | dev->suspended_from = dev->gadget.state; | ||
1369 | usb_gadget_set_state(&dev->gadget, USB_STATE_SUSPENDED); | ||
1370 | |||
1371 | if ((dev->gadget.speed != USB_SPEED_UNKNOWN) && | ||
1372 | dev->driver && dev->driver->suspend) { | ||
1373 | spin_unlock(&dev->lock); | ||
1374 | |||
1375 | dev->driver->suspend(&dev->gadget); | ||
1376 | |||
1377 | spin_lock(&dev->lock); | ||
1378 | } | ||
1379 | handled = 1; | ||
1380 | } | ||
1381 | |||
1382 | /* Coming out of suspend */ | ||
1383 | if ((dev->ep0state == GR_EP0_SUSPEND) && (status & GR_STATUS_SU)) { | ||
1384 | dev_dbg(dev->dev, "STATUS: USB resume\n"); | ||
1385 | if (dev->suspended_from == USB_STATE_POWERED) | ||
1386 | gr_set_ep0state(dev, GR_EP0_DISCONNECT); | ||
1387 | else | ||
1388 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1389 | usb_gadget_set_state(&dev->gadget, dev->suspended_from); | ||
1390 | |||
1391 | if ((dev->gadget.speed != USB_SPEED_UNKNOWN) && | ||
1392 | dev->driver && dev->driver->resume) { | ||
1393 | spin_unlock(&dev->lock); | ||
1394 | |||
1395 | dev->driver->resume(&dev->gadget); | ||
1396 | |||
1397 | spin_lock(&dev->lock); | ||
1398 | } | ||
1399 | handled = 1; | ||
1400 | } | ||
1401 | |||
1402 | return handled; | ||
1403 | } | ||
1404 | |||
1405 | /* Non-interrupt context irq handler */ | ||
1406 | static irqreturn_t gr_irq_handler(int irq, void *_dev) | ||
1407 | { | ||
1408 | struct gr_udc *dev = _dev; | ||
1409 | struct gr_ep *ep; | ||
1410 | int handled = 0; | ||
1411 | int i; | ||
1412 | unsigned long flags; | ||
1413 | |||
1414 | spin_lock_irqsave(&dev->lock, flags); | ||
1415 | |||
1416 | if (!dev->irq_enabled) | ||
1417 | goto out; | ||
1418 | |||
1419 | /* | ||
1420 | * Check IN ep interrupts. We check these before the OUT eps because | ||
1421 | * some gadgets reuse the request that might already be currently | ||
1422 | * outstanding and needs to be completed (mainly setup requests). | ||
1423 | */ | ||
1424 | for (i = 0; i < dev->nepi; i++) { | ||
1425 | ep = &dev->epi[i]; | ||
1426 | if (!ep->stopped && !ep->callback && !list_empty(&ep->queue)) | ||
1427 | handled = gr_handle_in_ep(ep) || handled; | ||
1428 | } | ||
1429 | |||
1430 | /* Check OUT ep interrupts */ | ||
1431 | for (i = 0; i < dev->nepo; i++) { | ||
1432 | ep = &dev->epo[i]; | ||
1433 | if (!ep->stopped && !ep->callback && !list_empty(&ep->queue)) | ||
1434 | handled = gr_handle_out_ep(ep) || handled; | ||
1435 | } | ||
1436 | |||
1437 | /* Check status interrupts */ | ||
1438 | handled = gr_handle_state_changes(dev) || handled; | ||
1439 | |||
1440 | /* | ||
1441 | * Check AMBA DMA errors. Only check if we didn't find anything else to | ||
1442 | * handle because this shouldn't happen if we did everything right. | ||
1443 | */ | ||
1444 | if (!handled) { | ||
1445 | list_for_each_entry(ep, &dev->ep_list, ep_list) { | ||
1446 | if (gr_read32(&ep->regs->dmactrl) & GR_DMACTRL_AE) { | ||
1447 | dev_err(dev->dev, | ||
1448 | "AMBA Error occurred for %s\n", | ||
1449 | ep->ep.name); | ||
1450 | handled = 1; | ||
1451 | } | ||
1452 | } | ||
1453 | } | ||
1454 | |||
1455 | out: | ||
1456 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1457 | |||
1458 | return handled ? IRQ_HANDLED : IRQ_NONE; | ||
1459 | } | ||
1460 | |||
1461 | /* Interrupt context irq handler */ | ||
1462 | static irqreturn_t gr_irq(int irq, void *_dev) | ||
1463 | { | ||
1464 | struct gr_udc *dev = _dev; | ||
1465 | |||
1466 | if (!dev->irq_enabled) | ||
1467 | return IRQ_NONE; | ||
1468 | |||
1469 | return IRQ_WAKE_THREAD; | ||
1470 | } | ||
1471 | |||
1472 | /* ---------------------------------------------------------------------- */ | ||
1473 | /* USB ep ops */ | ||
1474 | |||
1475 | /* Enable endpoint. Not for ep0in and ep0out that are handled separately. */ | ||
1476 | static int gr_ep_enable(struct usb_ep *_ep, | ||
1477 | const struct usb_endpoint_descriptor *desc) | ||
1478 | { | ||
1479 | struct gr_udc *dev; | ||
1480 | struct gr_ep *ep; | ||
1481 | u8 mode; | ||
1482 | u8 nt; | ||
1483 | u16 max; | ||
1484 | u16 buffer_size = 0; | ||
1485 | u32 epctrl; | ||
1486 | |||
1487 | ep = container_of(_ep, struct gr_ep, ep); | ||
1488 | if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) | ||
1489 | return -EINVAL; | ||
1490 | |||
1491 | dev = ep->dev; | ||
1492 | |||
1493 | /* 'ep0' IN and OUT are reserved */ | ||
1494 | if (ep == &dev->epo[0] || ep == &dev->epi[0]) | ||
1495 | return -EINVAL; | ||
1496 | |||
1497 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
1498 | return -ESHUTDOWN; | ||
1499 | |||
1500 | /* Make sure we are clear for enabling */ | ||
1501 | epctrl = gr_read32(&ep->regs->epctrl); | ||
1502 | if (epctrl & GR_EPCTRL_EV) | ||
1503 | return -EBUSY; | ||
1504 | |||
1505 | /* Check that directions match */ | ||
1506 | if (!ep->is_in != !usb_endpoint_dir_in(desc)) | ||
1507 | return -EINVAL; | ||
1508 | |||
1509 | /* Check ep num */ | ||
1510 | if ((!ep->is_in && ep->num >= dev->nepo) || | ||
1511 | (ep->is_in && ep->num >= dev->nepi)) | ||
1512 | return -EINVAL; | ||
1513 | |||
1514 | if (usb_endpoint_xfer_control(desc)) { | ||
1515 | mode = 0; | ||
1516 | } else if (usb_endpoint_xfer_isoc(desc)) { | ||
1517 | mode = 1; | ||
1518 | } else if (usb_endpoint_xfer_bulk(desc)) { | ||
1519 | mode = 2; | ||
1520 | } else if (usb_endpoint_xfer_int(desc)) { | ||
1521 | mode = 3; | ||
1522 | } else { | ||
1523 | dev_err(dev->dev, "Unknown transfer type for %s\n", | ||
1524 | ep->ep.name); | ||
1525 | return -EINVAL; | ||
1526 | } | ||
1527 | |||
1528 | /* | ||
1529 | * Bits 10-0 set the max payload. 12-11 set the number of | ||
1530 | * additional transactions. | ||
1531 | */ | ||
1532 | max = 0x7ff & usb_endpoint_maxp(desc); | ||
1533 | nt = 0x3 & (usb_endpoint_maxp(desc) >> 11); | ||
1534 | buffer_size = GR_BUFFER_SIZE(epctrl); | ||
1535 | if (nt && (mode == 0 || mode == 2)) { | ||
1536 | dev_err(dev->dev, | ||
1537 | "%s mode: multiple trans./microframe not valid\n", | ||
1538 | (mode == 2 ? "Bulk" : "Control")); | ||
1539 | return -EINVAL; | ||
1540 | } else if (nt == 0x11) { | ||
1541 | dev_err(dev->dev, "Invalid value for trans./microframe\n"); | ||
1542 | return -EINVAL; | ||
1543 | } else if ((nt + 1) * max > buffer_size) { | ||
1544 | dev_err(dev->dev, "Hw buffer size %d < max payload %d * %d\n", | ||
1545 | buffer_size, (nt + 1), max); | ||
1546 | return -EINVAL; | ||
1547 | } else if (max == 0) { | ||
1548 | dev_err(dev->dev, "Max payload cannot be set to 0\n"); | ||
1549 | return -EINVAL; | ||
1550 | } | ||
1551 | |||
1552 | spin_lock(&ep->dev->lock); | ||
1553 | |||
1554 | if (!ep->stopped) { | ||
1555 | spin_unlock(&ep->dev->lock); | ||
1556 | return -EBUSY; | ||
1557 | } | ||
1558 | |||
1559 | ep->stopped = 0; | ||
1560 | ep->wedged = 0; | ||
1561 | ep->ep.desc = desc; | ||
1562 | ep->ep.maxpacket = max; | ||
1563 | ep->dma_start = 0; | ||
1564 | |||
1565 | |||
1566 | if (nt) { | ||
1567 | /* | ||
1568 | * Maximum possible size of all payloads in one microframe | ||
1569 | * regardless of direction when using high-bandwidth mode. | ||
1570 | */ | ||
1571 | ep->bytes_per_buffer = (nt + 1) * max; | ||
1572 | } else if (ep->is_in) { | ||
1573 | /* | ||
1574 | * The biggest multiple of maximum packet size that fits into | ||
1575 | * the buffer. The hardware will split up into many packets in | ||
1576 | * the IN direction. | ||
1577 | */ | ||
1578 | ep->bytes_per_buffer = (buffer_size / max) * max; | ||
1579 | } else { | ||
1580 | /* | ||
1581 | * Only single packets will be placed the buffers in the OUT | ||
1582 | * direction. | ||
1583 | */ | ||
1584 | ep->bytes_per_buffer = max; | ||
1585 | } | ||
1586 | |||
1587 | epctrl = (max << GR_EPCTRL_MAXPL_POS) | ||
1588 | | (nt << GR_EPCTRL_NT_POS) | ||
1589 | | (mode << GR_EPCTRL_TT_POS) | ||
1590 | | GR_EPCTRL_EV; | ||
1591 | if (ep->is_in) | ||
1592 | epctrl |= GR_EPCTRL_PI; | ||
1593 | gr_write32(&ep->regs->epctrl, epctrl); | ||
1594 | |||
1595 | gr_write32(&ep->regs->dmactrl, GR_DMACTRL_IE | GR_DMACTRL_AI); | ||
1596 | |||
1597 | spin_unlock(&ep->dev->lock); | ||
1598 | |||
1599 | dev_dbg(ep->dev->dev, "EP: %s enabled - %s with %d bytes/buffer\n", | ||
1600 | ep->ep.name, gr_modestring[mode], ep->bytes_per_buffer); | ||
1601 | return 0; | ||
1602 | } | ||
1603 | |||
1604 | /* Disable endpoint. Not for ep0in and ep0out that are handled separately. */ | ||
1605 | static int gr_ep_disable(struct usb_ep *_ep) | ||
1606 | { | ||
1607 | struct gr_ep *ep; | ||
1608 | struct gr_udc *dev; | ||
1609 | unsigned long flags; | ||
1610 | |||
1611 | ep = container_of(_ep, struct gr_ep, ep); | ||
1612 | if (!_ep || !ep->ep.desc) | ||
1613 | return -ENODEV; | ||
1614 | |||
1615 | dev = ep->dev; | ||
1616 | |||
1617 | /* 'ep0' IN and OUT are reserved */ | ||
1618 | if (ep == &dev->epo[0] || ep == &dev->epi[0]) | ||
1619 | return -EINVAL; | ||
1620 | |||
1621 | if (dev->ep0state == GR_EP0_SUSPEND) | ||
1622 | return -EBUSY; | ||
1623 | |||
1624 | dev_dbg(ep->dev->dev, "EP: disable %s\n", ep->ep.name); | ||
1625 | |||
1626 | spin_lock_irqsave(&dev->lock, flags); | ||
1627 | |||
1628 | gr_ep_nuke(ep); | ||
1629 | gr_ep_reset(ep); | ||
1630 | ep->ep.desc = NULL; | ||
1631 | |||
1632 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1633 | |||
1634 | return 0; | ||
1635 | } | ||
1636 | |||
1637 | /* | ||
1638 | * Frees a request, but not any DMA buffers associated with it | ||
1639 | * (gr_finish_request should already have taken care of that). | ||
1640 | */ | ||
1641 | static void gr_free_request(struct usb_ep *_ep, struct usb_request *_req) | ||
1642 | { | ||
1643 | struct gr_request *req; | ||
1644 | |||
1645 | if (!_ep || !_req) | ||
1646 | return; | ||
1647 | req = container_of(_req, struct gr_request, req); | ||
1648 | |||
1649 | /* Leads to memory leak */ | ||
1650 | WARN(!list_empty(&req->queue), | ||
1651 | "request not dequeued properly before freeing\n"); | ||
1652 | |||
1653 | kfree(req); | ||
1654 | } | ||
1655 | |||
1656 | /* Queue a request from the gadget */ | ||
1657 | static int gr_queue_ext(struct usb_ep *_ep, struct usb_request *_req, | ||
1658 | gfp_t gfp_flags) | ||
1659 | { | ||
1660 | struct gr_ep *ep; | ||
1661 | struct gr_request *req; | ||
1662 | struct gr_udc *dev; | ||
1663 | int ret; | ||
1664 | |||
1665 | if (unlikely(!_ep || !_req)) | ||
1666 | return -EINVAL; | ||
1667 | |||
1668 | ep = container_of(_ep, struct gr_ep, ep); | ||
1669 | req = container_of(_req, struct gr_request, req); | ||
1670 | dev = ep->dev; | ||
1671 | |||
1672 | spin_lock(&ep->dev->lock); | ||
1673 | |||
1674 | /* | ||
1675 | * The ep0 pointer in the gadget struct is used both for ep0in and | ||
1676 | * ep0out. In a data stage in the out direction ep0out needs to be used | ||
1677 | * instead of the default ep0in. Completion functions might use | ||
1678 | * driver_data, so that needs to be copied as well. | ||
1679 | */ | ||
1680 | if ((ep == &dev->epi[0]) && (dev->ep0state == GR_EP0_ODATA)) { | ||
1681 | ep = &dev->epo[0]; | ||
1682 | ep->ep.driver_data = dev->epi[0].ep.driver_data; | ||
1683 | } | ||
1684 | |||
1685 | if (ep->is_in) | ||
1686 | gr_dbgprint_request("EXTERN", ep, req); | ||
1687 | |||
1688 | ret = gr_queue(ep, req, gfp_flags); | ||
1689 | |||
1690 | spin_unlock(&ep->dev->lock); | ||
1691 | |||
1692 | return ret; | ||
1693 | } | ||
1694 | |||
1695 | /* Dequeue JUST ONE request */ | ||
1696 | static int gr_dequeue(struct usb_ep *_ep, struct usb_request *_req) | ||
1697 | { | ||
1698 | struct gr_request *req; | ||
1699 | struct gr_ep *ep; | ||
1700 | struct gr_udc *dev; | ||
1701 | int ret = 0; | ||
1702 | unsigned long flags; | ||
1703 | |||
1704 | ep = container_of(_ep, struct gr_ep, ep); | ||
1705 | if (!_ep || !_req || (!ep->ep.desc && ep->num != 0)) | ||
1706 | return -EINVAL; | ||
1707 | dev = ep->dev; | ||
1708 | if (!dev->driver) | ||
1709 | return -ESHUTDOWN; | ||
1710 | |||
1711 | /* We can't touch (DMA) registers when suspended */ | ||
1712 | if (dev->ep0state == GR_EP0_SUSPEND) | ||
1713 | return -EBUSY; | ||
1714 | |||
1715 | spin_lock_irqsave(&dev->lock, flags); | ||
1716 | |||
1717 | /* Make sure it's actually queued on this endpoint */ | ||
1718 | list_for_each_entry(req, &ep->queue, queue) { | ||
1719 | if (&req->req == _req) | ||
1720 | break; | ||
1721 | } | ||
1722 | if (&req->req != _req) { | ||
1723 | ret = -EINVAL; | ||
1724 | goto out; | ||
1725 | } | ||
1726 | |||
1727 | if (list_first_entry(&ep->queue, struct gr_request, queue) == req) { | ||
1728 | /* This request is currently being processed */ | ||
1729 | gr_abort_dma(ep); | ||
1730 | if (ep->stopped) | ||
1731 | gr_finish_request(ep, req, -ECONNRESET); | ||
1732 | else | ||
1733 | gr_dma_advance(ep, -ECONNRESET); | ||
1734 | } else if (!list_empty(&req->queue)) { | ||
1735 | /* Not being processed - gr_finish_request dequeues it */ | ||
1736 | gr_finish_request(ep, req, -ECONNRESET); | ||
1737 | } else { | ||
1738 | ret = -EOPNOTSUPP; | ||
1739 | } | ||
1740 | |||
1741 | out: | ||
1742 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1743 | |||
1744 | return ret; | ||
1745 | } | ||
1746 | |||
1747 | /* Helper for gr_set_halt and gr_set_wedge */ | ||
1748 | static int gr_set_halt_wedge(struct usb_ep *_ep, int halt, int wedge) | ||
1749 | { | ||
1750 | int ret; | ||
1751 | struct gr_ep *ep; | ||
1752 | |||
1753 | if (!_ep) | ||
1754 | return -ENODEV; | ||
1755 | ep = container_of(_ep, struct gr_ep, ep); | ||
1756 | |||
1757 | spin_lock(&ep->dev->lock); | ||
1758 | |||
1759 | /* Halting an IN endpoint should fail if queue is not empty */ | ||
1760 | if (halt && ep->is_in && !list_empty(&ep->queue)) { | ||
1761 | ret = -EAGAIN; | ||
1762 | goto out; | ||
1763 | } | ||
1764 | |||
1765 | ret = gr_ep_halt_wedge(ep, halt, wedge, 0); | ||
1766 | |||
1767 | out: | ||
1768 | spin_unlock(&ep->dev->lock); | ||
1769 | |||
1770 | return ret; | ||
1771 | } | ||
1772 | |||
1773 | /* Halt endpoint */ | ||
1774 | static int gr_set_halt(struct usb_ep *_ep, int halt) | ||
1775 | { | ||
1776 | return gr_set_halt_wedge(_ep, halt, 0); | ||
1777 | } | ||
1778 | |||
1779 | /* Halt and wedge endpoint */ | ||
1780 | static int gr_set_wedge(struct usb_ep *_ep) | ||
1781 | { | ||
1782 | return gr_set_halt_wedge(_ep, 1, 1); | ||
1783 | } | ||
1784 | |||
1785 | /* | ||
1786 | * Return the total number of bytes currently stored in the internal buffers of | ||
1787 | * the endpoint. | ||
1788 | */ | ||
1789 | static int gr_fifo_status(struct usb_ep *_ep) | ||
1790 | { | ||
1791 | struct gr_ep *ep; | ||
1792 | u32 epstat; | ||
1793 | u32 bytes = 0; | ||
1794 | |||
1795 | if (!_ep) | ||
1796 | return -ENODEV; | ||
1797 | ep = container_of(_ep, struct gr_ep, ep); | ||
1798 | |||
1799 | epstat = gr_read32(&ep->regs->epstat); | ||
1800 | |||
1801 | if (epstat & GR_EPSTAT_B0) | ||
1802 | bytes += (epstat & GR_EPSTAT_B0CNT_MASK) >> GR_EPSTAT_B0CNT_POS; | ||
1803 | if (epstat & GR_EPSTAT_B1) | ||
1804 | bytes += (epstat & GR_EPSTAT_B1CNT_MASK) >> GR_EPSTAT_B1CNT_POS; | ||
1805 | |||
1806 | return bytes; | ||
1807 | } | ||
1808 | |||
1809 | |||
1810 | /* Empty data from internal buffers of an endpoint. */ | ||
1811 | static void gr_fifo_flush(struct usb_ep *_ep) | ||
1812 | { | ||
1813 | struct gr_ep *ep; | ||
1814 | u32 epctrl; | ||
1815 | |||
1816 | if (!_ep) | ||
1817 | return; | ||
1818 | ep = container_of(_ep, struct gr_ep, ep); | ||
1819 | dev_vdbg(ep->dev->dev, "EP: flush fifo %s\n", ep->ep.name); | ||
1820 | |||
1821 | spin_lock(&ep->dev->lock); | ||
1822 | |||
1823 | epctrl = gr_read32(&ep->regs->epctrl); | ||
1824 | epctrl |= GR_EPCTRL_CB; | ||
1825 | gr_write32(&ep->regs->epctrl, epctrl); | ||
1826 | |||
1827 | spin_unlock(&ep->dev->lock); | ||
1828 | } | ||
1829 | |||
1830 | static struct usb_ep_ops gr_ep_ops = { | ||
1831 | .enable = gr_ep_enable, | ||
1832 | .disable = gr_ep_disable, | ||
1833 | |||
1834 | .alloc_request = gr_alloc_request, | ||
1835 | .free_request = gr_free_request, | ||
1836 | |||
1837 | .queue = gr_queue_ext, | ||
1838 | .dequeue = gr_dequeue, | ||
1839 | |||
1840 | .set_halt = gr_set_halt, | ||
1841 | .set_wedge = gr_set_wedge, | ||
1842 | .fifo_status = gr_fifo_status, | ||
1843 | .fifo_flush = gr_fifo_flush, | ||
1844 | }; | ||
1845 | |||
1846 | /* ---------------------------------------------------------------------- */ | ||
1847 | /* USB Gadget ops */ | ||
1848 | |||
1849 | static int gr_get_frame(struct usb_gadget *_gadget) | ||
1850 | { | ||
1851 | struct gr_udc *dev; | ||
1852 | |||
1853 | if (!_gadget) | ||
1854 | return -ENODEV; | ||
1855 | dev = container_of(_gadget, struct gr_udc, gadget); | ||
1856 | return gr_read32(&dev->regs->status) & GR_STATUS_FN_MASK; | ||
1857 | } | ||
1858 | |||
1859 | static int gr_wakeup(struct usb_gadget *_gadget) | ||
1860 | { | ||
1861 | struct gr_udc *dev; | ||
1862 | |||
1863 | if (!_gadget) | ||
1864 | return -ENODEV; | ||
1865 | dev = container_of(_gadget, struct gr_udc, gadget); | ||
1866 | |||
1867 | /* Remote wakeup feature not enabled by host*/ | ||
1868 | if (!dev->remote_wakeup) | ||
1869 | return -EINVAL; | ||
1870 | |||
1871 | spin_lock(&dev->lock); | ||
1872 | |||
1873 | gr_write32(&dev->regs->control, | ||
1874 | gr_read32(&dev->regs->control) | GR_CONTROL_RW); | ||
1875 | |||
1876 | spin_unlock(&dev->lock); | ||
1877 | |||
1878 | return 0; | ||
1879 | } | ||
1880 | |||
1881 | static int gr_pullup(struct usb_gadget *_gadget, int is_on) | ||
1882 | { | ||
1883 | struct gr_udc *dev; | ||
1884 | u32 control; | ||
1885 | |||
1886 | if (!_gadget) | ||
1887 | return -ENODEV; | ||
1888 | dev = container_of(_gadget, struct gr_udc, gadget); | ||
1889 | |||
1890 | spin_lock(&dev->lock); | ||
1891 | |||
1892 | control = gr_read32(&dev->regs->control); | ||
1893 | if (is_on) | ||
1894 | control |= GR_CONTROL_EP; | ||
1895 | else | ||
1896 | control &= ~GR_CONTROL_EP; | ||
1897 | gr_write32(&dev->regs->control, control); | ||
1898 | |||
1899 | spin_unlock(&dev->lock); | ||
1900 | |||
1901 | return 0; | ||
1902 | } | ||
1903 | |||
1904 | static int gr_udc_start(struct usb_gadget *gadget, | ||
1905 | struct usb_gadget_driver *driver) | ||
1906 | { | ||
1907 | struct gr_udc *dev = to_gr_udc(gadget); | ||
1908 | |||
1909 | spin_lock(&dev->lock); | ||
1910 | |||
1911 | /* Hook up the driver */ | ||
1912 | driver->driver.bus = NULL; | ||
1913 | dev->driver = driver; | ||
1914 | |||
1915 | /* Get ready for host detection */ | ||
1916 | gr_enable_vbus_detect(dev); | ||
1917 | |||
1918 | spin_unlock(&dev->lock); | ||
1919 | |||
1920 | dev_info(dev->dev, "Started with gadget driver '%s'\n", | ||
1921 | driver->driver.name); | ||
1922 | |||
1923 | return 0; | ||
1924 | } | ||
1925 | |||
1926 | static int gr_udc_stop(struct usb_gadget *gadget, | ||
1927 | struct usb_gadget_driver *driver) | ||
1928 | { | ||
1929 | struct gr_udc *dev = to_gr_udc(gadget); | ||
1930 | unsigned long flags; | ||
1931 | |||
1932 | spin_lock_irqsave(&dev->lock, flags); | ||
1933 | |||
1934 | dev->driver = NULL; | ||
1935 | gr_stop_activity(dev); | ||
1936 | |||
1937 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1938 | |||
1939 | dev_info(dev->dev, "Stopped\n"); | ||
1940 | |||
1941 | return 0; | ||
1942 | } | ||
1943 | |||
1944 | static const struct usb_gadget_ops gr_ops = { | ||
1945 | .get_frame = gr_get_frame, | ||
1946 | .wakeup = gr_wakeup, | ||
1947 | .pullup = gr_pullup, | ||
1948 | .udc_start = gr_udc_start, | ||
1949 | .udc_stop = gr_udc_stop, | ||
1950 | /* Other operations not supported */ | ||
1951 | }; | ||
1952 | |||
1953 | /* ---------------------------------------------------------------------- */ | ||
1954 | /* Module probe, removal and of-matching */ | ||
1955 | |||
1956 | static const char * const onames[] = { | ||
1957 | "ep0out", "ep1out", "ep2out", "ep3out", "ep4out", "ep5out", | ||
1958 | "ep6out", "ep7out", "ep8out", "ep9out", "ep10out", "ep11out", | ||
1959 | "ep12out", "ep13out", "ep14out", "ep15out" | ||
1960 | }; | ||
1961 | |||
1962 | static const char * const inames[] = { | ||
1963 | "ep0in", "ep1in", "ep2in", "ep3in", "ep4in", "ep5in", | ||
1964 | "ep6in", "ep7in", "ep8in", "ep9in", "ep10in", "ep11in", | ||
1965 | "ep12in", "ep13in", "ep14in", "ep15in" | ||
1966 | }; | ||
1967 | |||
1968 | /* Must be called with dev->lock held */ | ||
1969 | static int gr_ep_init(struct gr_udc *dev, int num, int is_in, u32 maxplimit) | ||
1970 | { | ||
1971 | struct gr_ep *ep; | ||
1972 | struct gr_request *req; | ||
1973 | struct usb_request *_req; | ||
1974 | void *buf; | ||
1975 | |||
1976 | if (is_in) { | ||
1977 | ep = &dev->epi[num]; | ||
1978 | ep->ep.name = inames[num]; | ||
1979 | ep->regs = &dev->regs->epi[num]; | ||
1980 | } else { | ||
1981 | ep = &dev->epo[num]; | ||
1982 | ep->ep.name = onames[num]; | ||
1983 | ep->regs = &dev->regs->epo[num]; | ||
1984 | } | ||
1985 | |||
1986 | gr_ep_reset(ep); | ||
1987 | ep->num = num; | ||
1988 | ep->is_in = is_in; | ||
1989 | ep->dev = dev; | ||
1990 | ep->ep.ops = &gr_ep_ops; | ||
1991 | INIT_LIST_HEAD(&ep->queue); | ||
1992 | |||
1993 | if (num == 0) { | ||
1994 | _req = gr_alloc_request(&ep->ep, GFP_KERNEL); | ||
1995 | buf = devm_kzalloc(dev->dev, PAGE_SIZE, GFP_DMA | GFP_KERNEL); | ||
1996 | if (!_req || !buf) { | ||
1997 | /* possible _req freed by gr_probe via gr_remove */ | ||
1998 | return -ENOMEM; | ||
1999 | } | ||
2000 | |||
2001 | req = container_of(_req, struct gr_request, req); | ||
2002 | req->req.buf = buf; | ||
2003 | req->req.length = MAX_CTRL_PL_SIZE; | ||
2004 | |||
2005 | if (is_in) | ||
2006 | dev->ep0reqi = req; /* Complete gets set as used */ | ||
2007 | else | ||
2008 | dev->ep0reqo = req; /* Completion treated separately */ | ||
2009 | |||
2010 | usb_ep_set_maxpacket_limit(&ep->ep, MAX_CTRL_PL_SIZE); | ||
2011 | ep->bytes_per_buffer = MAX_CTRL_PL_SIZE; | ||
2012 | } else { | ||
2013 | usb_ep_set_maxpacket_limit(&ep->ep, (u16)maxplimit); | ||
2014 | list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); | ||
2015 | } | ||
2016 | list_add_tail(&ep->ep_list, &dev->ep_list); | ||
2017 | |||
2018 | return 0; | ||
2019 | } | ||
2020 | |||
2021 | /* Must be called with dev->lock held */ | ||
2022 | static int gr_udc_init(struct gr_udc *dev) | ||
2023 | { | ||
2024 | struct device_node *np = dev->dev->of_node; | ||
2025 | u32 epctrl_val; | ||
2026 | u32 dmactrl_val; | ||
2027 | int i; | ||
2028 | int ret = 0; | ||
2029 | u32 *bufsizes; | ||
2030 | u32 bufsize; | ||
2031 | int len; | ||
2032 | |||
2033 | gr_set_address(dev, 0); | ||
2034 | |||
2035 | INIT_LIST_HEAD(&dev->gadget.ep_list); | ||
2036 | dev->gadget.speed = USB_SPEED_UNKNOWN; | ||
2037 | dev->gadget.ep0 = &dev->epi[0].ep; | ||
2038 | |||
2039 | INIT_LIST_HEAD(&dev->ep_list); | ||
2040 | gr_set_ep0state(dev, GR_EP0_DISCONNECT); | ||
2041 | |||
2042 | bufsizes = (u32 *)of_get_property(np, "epobufsizes", &len); | ||
2043 | len /= sizeof(u32); | ||
2044 | for (i = 0; i < dev->nepo; i++) { | ||
2045 | bufsize = (bufsizes && i < len) ? bufsizes[i] : 1024; | ||
2046 | ret = gr_ep_init(dev, i, 0, bufsize); | ||
2047 | if (ret) | ||
2048 | return ret; | ||
2049 | } | ||
2050 | |||
2051 | bufsizes = (u32 *)of_get_property(np, "epibufsizes", &len); | ||
2052 | len /= sizeof(u32); | ||
2053 | for (i = 0; i < dev->nepi; i++) { | ||
2054 | bufsize = (bufsizes && i < len) ? bufsizes[i] : 1024; | ||
2055 | ret = gr_ep_init(dev, i, 1, bufsize); | ||
2056 | if (ret) | ||
2057 | return ret; | ||
2058 | } | ||
2059 | |||
2060 | /* Must be disabled by default */ | ||
2061 | dev->remote_wakeup = 0; | ||
2062 | |||
2063 | /* Enable ep0out and ep0in */ | ||
2064 | epctrl_val = (MAX_CTRL_PL_SIZE << GR_EPCTRL_MAXPL_POS) | GR_EPCTRL_EV; | ||
2065 | dmactrl_val = GR_DMACTRL_IE | GR_DMACTRL_AI; | ||
2066 | gr_write32(&dev->epo[0].regs->epctrl, epctrl_val); | ||
2067 | gr_write32(&dev->epi[0].regs->epctrl, epctrl_val | GR_EPCTRL_PI); | ||
2068 | gr_write32(&dev->epo[0].regs->dmactrl, dmactrl_val); | ||
2069 | gr_write32(&dev->epi[0].regs->dmactrl, dmactrl_val); | ||
2070 | |||
2071 | return 0; | ||
2072 | } | ||
2073 | |||
2074 | static int gr_remove(struct platform_device *ofdev) | ||
2075 | { | ||
2076 | struct gr_udc *dev = dev_get_drvdata(&ofdev->dev); | ||
2077 | |||
2078 | if (dev->added) | ||
2079 | usb_del_gadget_udc(&dev->gadget); /* Shuts everything down */ | ||
2080 | if (dev->driver) | ||
2081 | return -EBUSY; | ||
2082 | |||
2083 | gr_dfs_delete(dev); | ||
2084 | if (dev->desc_pool) | ||
2085 | dma_pool_destroy(dev->desc_pool); | ||
2086 | dev_set_drvdata(&ofdev->dev, NULL); | ||
2087 | |||
2088 | gr_free_request(&dev->epi[0].ep, &dev->ep0reqi->req); | ||
2089 | gr_free_request(&dev->epo[0].ep, &dev->ep0reqo->req); | ||
2090 | |||
2091 | return 0; | ||
2092 | } | ||
2093 | static int gr_request_irq(struct gr_udc *dev, int irq) | ||
2094 | { | ||
2095 | return devm_request_threaded_irq(dev->dev, irq, gr_irq, gr_irq_handler, | ||
2096 | IRQF_SHARED, driver_name, dev); | ||
2097 | } | ||
2098 | |||
2099 | static int gr_probe(struct platform_device *ofdev) | ||
2100 | { | ||
2101 | struct gr_udc *dev; | ||
2102 | struct resource *res; | ||
2103 | struct gr_regs __iomem *regs; | ||
2104 | int retval; | ||
2105 | u32 status; | ||
2106 | |||
2107 | dev = devm_kzalloc(&ofdev->dev, sizeof(*dev), GFP_KERNEL); | ||
2108 | if (!dev) | ||
2109 | return -ENOMEM; | ||
2110 | dev->dev = &ofdev->dev; | ||
2111 | |||
2112 | res = platform_get_resource(ofdev, IORESOURCE_MEM, 0); | ||
2113 | regs = devm_ioremap_resource(dev->dev, res); | ||
2114 | if (IS_ERR(regs)) | ||
2115 | return PTR_ERR(regs); | ||
2116 | |||
2117 | dev->irq = irq_of_parse_and_map(dev->dev->of_node, 0); | ||
2118 | if (!dev->irq) { | ||
2119 | dev_err(dev->dev, "No irq found\n"); | ||
2120 | return -ENODEV; | ||
2121 | } | ||
2122 | |||
2123 | /* Some core configurations has separate irqs for IN and OUT events */ | ||
2124 | dev->irqi = irq_of_parse_and_map(dev->dev->of_node, 1); | ||
2125 | if (dev->irqi) { | ||
2126 | dev->irqo = irq_of_parse_and_map(dev->dev->of_node, 2); | ||
2127 | if (!dev->irqo) { | ||
2128 | dev_err(dev->dev, "Found irqi but not irqo\n"); | ||
2129 | return -ENODEV; | ||
2130 | } | ||
2131 | } | ||
2132 | |||
2133 | dev->gadget.name = driver_name; | ||
2134 | dev->gadget.max_speed = USB_SPEED_HIGH; | ||
2135 | dev->gadget.ops = &gr_ops; | ||
2136 | dev->gadget.quirk_ep_out_aligned_size = true; | ||
2137 | |||
2138 | spin_lock_init(&dev->lock); | ||
2139 | dev->regs = regs; | ||
2140 | |||
2141 | dev_set_drvdata(&ofdev->dev, dev); | ||
2142 | |||
2143 | /* Determine number of endpoints and data interface mode */ | ||
2144 | status = gr_read32(&dev->regs->status); | ||
2145 | dev->nepi = ((status & GR_STATUS_NEPI_MASK) >> GR_STATUS_NEPI_POS) + 1; | ||
2146 | dev->nepo = ((status & GR_STATUS_NEPO_MASK) >> GR_STATUS_NEPO_POS) + 1; | ||
2147 | |||
2148 | if (!(status & GR_STATUS_DM)) { | ||
2149 | dev_err(dev->dev, "Slave mode cores are not supported\n"); | ||
2150 | return -ENODEV; | ||
2151 | } | ||
2152 | |||
2153 | /* --- Effects of the following calls might need explicit cleanup --- */ | ||
2154 | |||
2155 | /* Create DMA pool for descriptors */ | ||
2156 | dev->desc_pool = dma_pool_create("desc_pool", dev->dev, | ||
2157 | sizeof(struct gr_dma_desc), 4, 0); | ||
2158 | if (!dev->desc_pool) { | ||
2159 | dev_err(dev->dev, "Could not allocate DMA pool"); | ||
2160 | return -ENOMEM; | ||
2161 | } | ||
2162 | |||
2163 | spin_lock(&dev->lock); | ||
2164 | |||
2165 | /* Inside lock so that no gadget can use this udc until probe is done */ | ||
2166 | retval = usb_add_gadget_udc(dev->dev, &dev->gadget); | ||
2167 | if (retval) { | ||
2168 | dev_err(dev->dev, "Could not add gadget udc"); | ||
2169 | goto out; | ||
2170 | } | ||
2171 | dev->added = 1; | ||
2172 | |||
2173 | retval = gr_udc_init(dev); | ||
2174 | if (retval) | ||
2175 | goto out; | ||
2176 | |||
2177 | gr_dfs_create(dev); | ||
2178 | |||
2179 | /* Clear all interrupt enables that might be left on since last boot */ | ||
2180 | gr_disable_interrupts_and_pullup(dev); | ||
2181 | |||
2182 | retval = gr_request_irq(dev, dev->irq); | ||
2183 | if (retval) { | ||
2184 | dev_err(dev->dev, "Failed to request irq %d\n", dev->irq); | ||
2185 | goto out; | ||
2186 | } | ||
2187 | |||
2188 | if (dev->irqi) { | ||
2189 | retval = gr_request_irq(dev, dev->irqi); | ||
2190 | if (retval) { | ||
2191 | dev_err(dev->dev, "Failed to request irqi %d\n", | ||
2192 | dev->irqi); | ||
2193 | goto out; | ||
2194 | } | ||
2195 | retval = gr_request_irq(dev, dev->irqo); | ||
2196 | if (retval) { | ||
2197 | dev_err(dev->dev, "Failed to request irqo %d\n", | ||
2198 | dev->irqo); | ||
2199 | goto out; | ||
2200 | } | ||
2201 | } | ||
2202 | |||
2203 | if (dev->irqi) | ||
2204 | dev_info(dev->dev, "regs: %p, irqs %d, %d, %d\n", dev->regs, | ||
2205 | dev->irq, dev->irqi, dev->irqo); | ||
2206 | else | ||
2207 | dev_info(dev->dev, "regs: %p, irq %d\n", dev->regs, dev->irq); | ||
2208 | |||
2209 | out: | ||
2210 | spin_unlock(&dev->lock); | ||
2211 | |||
2212 | if (retval) | ||
2213 | gr_remove(ofdev); | ||
2214 | |||
2215 | return retval; | ||
2216 | } | ||
2217 | |||
2218 | static struct of_device_id gr_match[] = { | ||
2219 | {.name = "GAISLER_USBDC"}, | ||
2220 | {.name = "01_021"}, | ||
2221 | {}, | ||
2222 | }; | ||
2223 | MODULE_DEVICE_TABLE(of, gr_match); | ||
2224 | |||
2225 | static struct platform_driver gr_driver = { | ||
2226 | .driver = { | ||
2227 | .name = DRIVER_NAME, | ||
2228 | .owner = THIS_MODULE, | ||
2229 | .of_match_table = gr_match, | ||
2230 | }, | ||
2231 | .probe = gr_probe, | ||
2232 | .remove = gr_remove, | ||
2233 | }; | ||
2234 | module_platform_driver(gr_driver); | ||
2235 | |||
2236 | MODULE_AUTHOR("Aeroflex Gaisler AB."); | ||
2237 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
2238 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/gadget/gr_udc.h b/drivers/usb/gadget/gr_udc.h new file mode 100644 index 000000000000..8388897d9ec3 --- /dev/null +++ b/drivers/usb/gadget/gr_udc.h | |||
@@ -0,0 +1,220 @@ | |||
1 | /* | ||
2 | * USB Peripheral Controller driver for Aeroflex Gaisler GRUSBDC. | ||
3 | * | ||
4 | * 2013 (c) Aeroflex Gaisler AB | ||
5 | * | ||
6 | * This driver supports GRUSBDC USB Device Controller cores available in the | ||
7 | * GRLIB VHDL IP core library. | ||
8 | * | ||
9 | * Full documentation of the GRUSBDC core can be found here: | ||
10 | * http://www.gaisler.com/products/grlib/grip.pdf | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify it | ||
13 | * under the terms of the GNU General Public License as published by the | ||
14 | * Free Software Foundation; either version 2 of the License, or (at your | ||
15 | * option) any later version. | ||
16 | * | ||
17 | * Contributors: | ||
18 | * - Andreas Larsson <andreas@gaisler.com> | ||
19 | * - Marko Isomaki | ||
20 | */ | ||
21 | |||
22 | /* Control registers on the AMBA bus */ | ||
23 | |||
24 | #define GR_MAXEP 16 /* Max # endpoints for *each* direction */ | ||
25 | |||
26 | struct gr_epregs { | ||
27 | u32 epctrl; | ||
28 | union { | ||
29 | struct { /* Slave mode*/ | ||
30 | u32 slvctrl; | ||
31 | u32 slvdata; | ||
32 | }; | ||
33 | struct { /* DMA mode*/ | ||
34 | u32 dmactrl; | ||
35 | u32 dmaaddr; | ||
36 | }; | ||
37 | }; | ||
38 | u32 epstat; | ||
39 | }; | ||
40 | |||
41 | struct gr_regs { | ||
42 | struct gr_epregs epo[GR_MAXEP]; /* 0x000 - 0x0fc */ | ||
43 | struct gr_epregs epi[GR_MAXEP]; /* 0x100 - 0x1fc */ | ||
44 | u32 control; /* 0x200 */ | ||
45 | u32 status; /* 0x204 */ | ||
46 | }; | ||
47 | |||
48 | #define GR_EPCTRL_BUFSZ_SCALER 8 | ||
49 | #define GR_EPCTRL_BUFSZ_MASK 0xffe00000 | ||
50 | #define GR_EPCTRL_BUFSZ_POS 21 | ||
51 | #define GR_EPCTRL_PI BIT(20) | ||
52 | #define GR_EPCTRL_CB BIT(19) | ||
53 | #define GR_EPCTRL_CS BIT(18) | ||
54 | #define GR_EPCTRL_MAXPL_MASK 0x0003ff80 | ||
55 | #define GR_EPCTRL_MAXPL_POS 7 | ||
56 | #define GR_EPCTRL_NT_MASK 0x00000060 | ||
57 | #define GR_EPCTRL_NT_POS 5 | ||
58 | #define GR_EPCTRL_TT_MASK 0x00000018 | ||
59 | #define GR_EPCTRL_TT_POS 3 | ||
60 | #define GR_EPCTRL_EH BIT(2) | ||
61 | #define GR_EPCTRL_ED BIT(1) | ||
62 | #define GR_EPCTRL_EV BIT(0) | ||
63 | |||
64 | #define GR_DMACTRL_AE BIT(10) | ||
65 | #define GR_DMACTRL_AD BIT(3) | ||
66 | #define GR_DMACTRL_AI BIT(2) | ||
67 | #define GR_DMACTRL_IE BIT(1) | ||
68 | #define GR_DMACTRL_DA BIT(0) | ||
69 | |||
70 | #define GR_EPSTAT_PT BIT(29) | ||
71 | #define GR_EPSTAT_PR BIT(29) | ||
72 | #define GR_EPSTAT_B1CNT_MASK 0x1fff0000 | ||
73 | #define GR_EPSTAT_B1CNT_POS 16 | ||
74 | #define GR_EPSTAT_B0CNT_MASK 0x0000fff8 | ||
75 | #define GR_EPSTAT_B0CNT_POS 3 | ||
76 | #define GR_EPSTAT_B1 BIT(2) | ||
77 | #define GR_EPSTAT_B0 BIT(1) | ||
78 | #define GR_EPSTAT_BS BIT(0) | ||
79 | |||
80 | #define GR_CONTROL_SI BIT(31) | ||
81 | #define GR_CONTROL_UI BIT(30) | ||
82 | #define GR_CONTROL_VI BIT(29) | ||
83 | #define GR_CONTROL_SP BIT(28) | ||
84 | #define GR_CONTROL_FI BIT(27) | ||
85 | #define GR_CONTROL_EP BIT(14) | ||
86 | #define GR_CONTROL_DH BIT(13) | ||
87 | #define GR_CONTROL_RW BIT(12) | ||
88 | #define GR_CONTROL_TS_MASK 0x00000e00 | ||
89 | #define GR_CONTROL_TS_POS 9 | ||
90 | #define GR_CONTROL_TM BIT(8) | ||
91 | #define GR_CONTROL_UA_MASK 0x000000fe | ||
92 | #define GR_CONTROL_UA_POS 1 | ||
93 | #define GR_CONTROL_SU BIT(0) | ||
94 | |||
95 | #define GR_STATUS_NEPI_MASK 0xf0000000 | ||
96 | #define GR_STATUS_NEPI_POS 28 | ||
97 | #define GR_STATUS_NEPO_MASK 0x0f000000 | ||
98 | #define GR_STATUS_NEPO_POS 24 | ||
99 | #define GR_STATUS_DM BIT(23) | ||
100 | #define GR_STATUS_SU BIT(17) | ||
101 | #define GR_STATUS_UR BIT(16) | ||
102 | #define GR_STATUS_VB BIT(15) | ||
103 | #define GR_STATUS_SP BIT(14) | ||
104 | #define GR_STATUS_AF_MASK 0x00003800 | ||
105 | #define GR_STATUS_AF_POS 11 | ||
106 | #define GR_STATUS_FN_MASK 0x000007ff | ||
107 | #define GR_STATUS_FN_POS 0 | ||
108 | |||
109 | |||
110 | #define MAX_CTRL_PL_SIZE 64 /* As per USB standard for full and high speed */ | ||
111 | |||
112 | /*-------------------------------------------------------------------------*/ | ||
113 | |||
114 | /* Driver data structures and utilities */ | ||
115 | |||
116 | struct gr_dma_desc { | ||
117 | u32 ctrl; | ||
118 | u32 data; | ||
119 | u32 next; | ||
120 | |||
121 | /* These must be last because hw uses the previous three */ | ||
122 | u32 paddr; | ||
123 | struct gr_dma_desc *next_desc; | ||
124 | }; | ||
125 | |||
126 | #define GR_DESC_OUT_CTRL_SE BIT(17) | ||
127 | #define GR_DESC_OUT_CTRL_IE BIT(15) | ||
128 | #define GR_DESC_OUT_CTRL_NX BIT(14) | ||
129 | #define GR_DESC_OUT_CTRL_EN BIT(13) | ||
130 | #define GR_DESC_OUT_CTRL_LEN_MASK 0x00001fff | ||
131 | |||
132 | #define GR_DESC_IN_CTRL_MO BIT(18) | ||
133 | #define GR_DESC_IN_CTRL_PI BIT(17) | ||
134 | #define GR_DESC_IN_CTRL_ML BIT(16) | ||
135 | #define GR_DESC_IN_CTRL_IE BIT(15) | ||
136 | #define GR_DESC_IN_CTRL_NX BIT(14) | ||
137 | #define GR_DESC_IN_CTRL_EN BIT(13) | ||
138 | #define GR_DESC_IN_CTRL_LEN_MASK 0x00001fff | ||
139 | |||
140 | #define GR_DESC_DMAADDR_MASK 0xfffffffc | ||
141 | |||
142 | struct gr_ep { | ||
143 | struct usb_ep ep; | ||
144 | struct gr_udc *dev; | ||
145 | u16 bytes_per_buffer; | ||
146 | unsigned int dma_start; | ||
147 | struct gr_epregs __iomem *regs; | ||
148 | |||
149 | unsigned num:8; | ||
150 | unsigned is_in:1; | ||
151 | unsigned stopped:1; | ||
152 | unsigned wedged:1; | ||
153 | unsigned callback:1; | ||
154 | |||
155 | /* analogous to a host-side qh */ | ||
156 | struct list_head queue; | ||
157 | |||
158 | struct list_head ep_list; | ||
159 | }; | ||
160 | |||
161 | struct gr_request { | ||
162 | struct usb_request req; | ||
163 | struct list_head queue; | ||
164 | |||
165 | /* Chain of dma descriptors */ | ||
166 | struct gr_dma_desc *first_desc; /* First in the chain */ | ||
167 | struct gr_dma_desc *curr_desc; /* Current descriptor */ | ||
168 | struct gr_dma_desc *last_desc; /* Last in the chain */ | ||
169 | |||
170 | u8 setup; /* Setup packet */ | ||
171 | }; | ||
172 | |||
173 | enum gr_ep0state { | ||
174 | GR_EP0_DISCONNECT = 0, /* No host */ | ||
175 | GR_EP0_SETUP, /* Between STATUS ack and SETUP report */ | ||
176 | GR_EP0_IDATA, /* IN data stage */ | ||
177 | GR_EP0_ODATA, /* OUT data stage */ | ||
178 | GR_EP0_ISTATUS, /* Status stage after IN data stage */ | ||
179 | GR_EP0_OSTATUS, /* Status stage after OUT data stage */ | ||
180 | GR_EP0_STALL, /* Data or status stages */ | ||
181 | GR_EP0_SUSPEND, /* USB suspend */ | ||
182 | }; | ||
183 | |||
184 | struct gr_udc { | ||
185 | struct usb_gadget gadget; | ||
186 | struct gr_ep epi[GR_MAXEP]; | ||
187 | struct gr_ep epo[GR_MAXEP]; | ||
188 | struct usb_gadget_driver *driver; | ||
189 | struct dma_pool *desc_pool; | ||
190 | struct device *dev; | ||
191 | |||
192 | enum gr_ep0state ep0state; | ||
193 | struct gr_request *ep0reqo; | ||
194 | struct gr_request *ep0reqi; | ||
195 | |||
196 | struct gr_regs __iomem *regs; | ||
197 | int irq; | ||
198 | int irqi; | ||
199 | int irqo; | ||
200 | |||
201 | unsigned added:1; | ||
202 | unsigned irq_enabled:1; | ||
203 | unsigned remote_wakeup:1; | ||
204 | |||
205 | u8 test_mode; | ||
206 | |||
207 | enum usb_device_state suspended_from; | ||
208 | |||
209 | unsigned int nepi; | ||
210 | unsigned int nepo; | ||
211 | |||
212 | struct list_head ep_list; | ||
213 | |||
214 | spinlock_t lock; /* General lock, a.k.a. "dev->lock" in comments */ | ||
215 | |||
216 | struct dentry *dfs_root; | ||
217 | struct dentry *dfs_state; | ||
218 | }; | ||
219 | |||
220 | #define to_gr_udc(gadget) (container_of((gadget), struct gr_udc, gadget)) | ||
diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c index 6a2a65aa0057..049ebab0d360 100644 --- a/drivers/usb/gadget/lpc32xx_udc.c +++ b/drivers/usb/gadget/lpc32xx_udc.c | |||
@@ -1449,7 +1449,7 @@ static void udc_reinit(struct lpc32xx_udc *udc) | |||
1449 | 1449 | ||
1450 | if (i != 0) | 1450 | if (i != 0) |
1451 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); | 1451 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); |
1452 | ep->ep.maxpacket = ep->maxpacket; | 1452 | usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); |
1453 | INIT_LIST_HEAD(&ep->queue); | 1453 | INIT_LIST_HEAD(&ep->queue); |
1454 | ep->req_pending = 0; | 1454 | ep->req_pending = 0; |
1455 | } | 1455 | } |
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index d5f050d30edf..8cae01d88597 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c | |||
@@ -1647,9 +1647,9 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1647 | INIT_LIST_HEAD(&ep->queue); | 1647 | INIT_LIST_HEAD(&ep->queue); |
1648 | ep->ep.name = m66592_ep_name[i]; | 1648 | ep->ep.name = m66592_ep_name[i]; |
1649 | ep->ep.ops = &m66592_ep_ops; | 1649 | ep->ep.ops = &m66592_ep_ops; |
1650 | ep->ep.maxpacket = 512; | 1650 | usb_ep_set_maxpacket_limit(&ep->ep, 512); |
1651 | } | 1651 | } |
1652 | m66592->ep[0].ep.maxpacket = 64; | 1652 | usb_ep_set_maxpacket_limit(&m66592->ep[0].ep, 64); |
1653 | m66592->ep[0].pipenum = 0; | 1653 | m66592->ep[0].pipenum = 0; |
1654 | m66592->ep[0].fifoaddr = M66592_CFIFO; | 1654 | m66592->ep[0].fifoaddr = M66592_CFIFO; |
1655 | m66592->ep[0].fifosel = M66592_CFIFOSEL; | 1655 | m66592->ep[0].fifosel = M66592_CFIFOSEL; |
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index 4fdaa54a2a2a..940f6cde8e89 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c | |||
@@ -134,7 +134,7 @@ static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; | |||
134 | */ | 134 | */ |
135 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS | 135 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS |
136 | 136 | ||
137 | #endif /* CONFIG_USB_DEBUG */ | 137 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ |
138 | 138 | ||
139 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); | 139 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); |
140 | 140 | ||
diff --git a/drivers/usb/gadget/mv_u3d_core.c b/drivers/usb/gadget/mv_u3d_core.c index 234711eabea1..d2ca59e7b477 100644 --- a/drivers/usb/gadget/mv_u3d_core.c +++ b/drivers/usb/gadget/mv_u3d_core.c | |||
@@ -15,7 +15,6 @@ | |||
15 | #include <linux/sched.h> | 15 | #include <linux/sched.h> |
16 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
17 | #include <linux/errno.h> | 17 | #include <linux/errno.h> |
18 | #include <linux/init.h> | ||
19 | #include <linux/timer.h> | 18 | #include <linux/timer.h> |
20 | #include <linux/list.h> | 19 | #include <linux/list.h> |
21 | #include <linux/notifier.h> | 20 | #include <linux/notifier.h> |
@@ -1336,7 +1335,7 @@ static int mv_u3d_eps_init(struct mv_u3d *u3d) | |||
1336 | ep->ep.name = ep->name; | 1335 | ep->ep.name = ep->name; |
1337 | ep->ep.ops = &mv_u3d_ep_ops; | 1336 | ep->ep.ops = &mv_u3d_ep_ops; |
1338 | ep->wedge = 0; | 1337 | ep->wedge = 0; |
1339 | ep->ep.maxpacket = MV_U3D_EP0_MAX_PKT_SIZE; | 1338 | usb_ep_set_maxpacket_limit(&ep->ep, MV_U3D_EP0_MAX_PKT_SIZE); |
1340 | ep->ep_num = 0; | 1339 | ep->ep_num = 0; |
1341 | ep->ep.desc = &mv_u3d_ep0_desc; | 1340 | ep->ep.desc = &mv_u3d_ep0_desc; |
1342 | INIT_LIST_HEAD(&ep->queue); | 1341 | INIT_LIST_HEAD(&ep->queue); |
@@ -1361,7 +1360,7 @@ static int mv_u3d_eps_init(struct mv_u3d *u3d) | |||
1361 | ep->ep.name = ep->name; | 1360 | ep->ep.name = ep->name; |
1362 | 1361 | ||
1363 | ep->ep.ops = &mv_u3d_ep_ops; | 1362 | ep->ep.ops = &mv_u3d_ep_ops; |
1364 | ep->ep.maxpacket = (unsigned short) ~0; | 1363 | usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); |
1365 | ep->ep_num = i / 2; | 1364 | ep->ep_num = i / 2; |
1366 | 1365 | ||
1367 | INIT_LIST_HEAD(&ep->queue); | 1366 | INIT_LIST_HEAD(&ep->queue); |
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c index 104cdbea635a..fcff3a571b45 100644 --- a/drivers/usb/gadget/mv_udc_core.c +++ b/drivers/usb/gadget/mv_udc_core.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | #include <linux/errno.h> | 21 | #include <linux/errno.h> |
22 | #include <linux/err.h> | 22 | #include <linux/err.h> |
23 | #include <linux/init.h> | ||
24 | #include <linux/timer.h> | 23 | #include <linux/timer.h> |
25 | #include <linux/list.h> | 24 | #include <linux/list.h> |
26 | #include <linux/interrupt.h> | 25 | #include <linux/interrupt.h> |
@@ -1261,7 +1260,7 @@ static int eps_init(struct mv_udc *udc) | |||
1261 | ep->ep.ops = &mv_ep_ops; | 1260 | ep->ep.ops = &mv_ep_ops; |
1262 | ep->wedge = 0; | 1261 | ep->wedge = 0; |
1263 | ep->stopped = 0; | 1262 | ep->stopped = 0; |
1264 | ep->ep.maxpacket = EP0_MAX_PKT_SIZE; | 1263 | usb_ep_set_maxpacket_limit(&ep->ep, EP0_MAX_PKT_SIZE); |
1265 | ep->ep_num = 0; | 1264 | ep->ep_num = 0; |
1266 | ep->ep.desc = &mv_ep0_desc; | 1265 | ep->ep.desc = &mv_ep0_desc; |
1267 | INIT_LIST_HEAD(&ep->queue); | 1266 | INIT_LIST_HEAD(&ep->queue); |
@@ -1284,7 +1283,7 @@ static int eps_init(struct mv_udc *udc) | |||
1284 | 1283 | ||
1285 | ep->ep.ops = &mv_ep_ops; | 1284 | ep->ep.ops = &mv_ep_ops; |
1286 | ep->stopped = 0; | 1285 | ep->stopped = 0; |
1287 | ep->ep.maxpacket = (unsigned short) ~0; | 1286 | usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); |
1288 | ep->ep_num = i / 2; | 1287 | ep->ep_num = i / 2; |
1289 | 1288 | ||
1290 | INIT_LIST_HEAD(&ep->queue); | 1289 | INIT_LIST_HEAD(&ep->queue); |
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c index bf2bb39f35a2..ca15405583e2 100644 --- a/drivers/usb/gadget/net2272.c +++ b/drivers/usb/gadget/net2272.c | |||
@@ -266,7 +266,7 @@ static void net2272_ep_reset(struct net2272_ep *ep) | |||
266 | ep->desc = NULL; | 266 | ep->desc = NULL; |
267 | INIT_LIST_HEAD(&ep->queue); | 267 | INIT_LIST_HEAD(&ep->queue); |
268 | 268 | ||
269 | ep->ep.maxpacket = ~0; | 269 | usb_ep_set_maxpacket_limit(&ep->ep, ~0); |
270 | ep->ep.ops = &net2272_ep_ops; | 270 | ep->ep.ops = &net2272_ep_ops; |
271 | 271 | ||
272 | /* disable irqs, endpoint */ | 272 | /* disable irqs, endpoint */ |
@@ -1409,7 +1409,7 @@ net2272_usb_reinit(struct net2272 *dev) | |||
1409 | ep->fifo_size = 64; | 1409 | ep->fifo_size = 64; |
1410 | net2272_ep_reset(ep); | 1410 | net2272_ep_reset(ep); |
1411 | } | 1411 | } |
1412 | dev->ep[0].ep.maxpacket = 64; | 1412 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 64); |
1413 | 1413 | ||
1414 | dev->gadget.ep0 = &dev->ep[0].ep; | 1414 | dev->gadget.ep0 = &dev->ep[0].ep; |
1415 | dev->ep[0].stopped = 0; | 1415 | dev->ep[0].stopped = 0; |
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c index fc852177c087..43e5e2f9888f 100644 --- a/drivers/usb/gadget/net2280.c +++ b/drivers/usb/gadget/net2280.c | |||
@@ -293,7 +293,7 @@ static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep) | |||
293 | ep->desc = NULL; | 293 | ep->desc = NULL; |
294 | INIT_LIST_HEAD (&ep->queue); | 294 | INIT_LIST_HEAD (&ep->queue); |
295 | 295 | ||
296 | ep->ep.maxpacket = ~0; | 296 | usb_ep_set_maxpacket_limit(&ep->ep, ~0); |
297 | ep->ep.ops = &net2280_ep_ops; | 297 | ep->ep.ops = &net2280_ep_ops; |
298 | 298 | ||
299 | /* disable the dma, irqs, endpoint... */ | 299 | /* disable the dma, irqs, endpoint... */ |
@@ -1805,9 +1805,9 @@ static void usb_reinit (struct net2280 *dev) | |||
1805 | ep->regs = &dev->epregs [tmp]; | 1805 | ep->regs = &dev->epregs [tmp]; |
1806 | ep_reset (dev->regs, ep); | 1806 | ep_reset (dev->regs, ep); |
1807 | } | 1807 | } |
1808 | dev->ep [0].ep.maxpacket = 64; | 1808 | usb_ep_set_maxpacket_limit(&dev->ep [0].ep, 64); |
1809 | dev->ep [5].ep.maxpacket = 64; | 1809 | usb_ep_set_maxpacket_limit(&dev->ep [5].ep, 64); |
1810 | dev->ep [6].ep.maxpacket = 64; | 1810 | usb_ep_set_maxpacket_limit(&dev->ep [6].ep, 64); |
1811 | 1811 | ||
1812 | dev->gadget.ep0 = &dev->ep [0].ep; | 1812 | dev->gadget.ep0 = &dev->ep [0].ep; |
1813 | dev->ep [0].stopped = 0; | 1813 | dev->ep [0].stopped = 0; |
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c index 0a8099a488c4..3ab386167519 100644 --- a/drivers/usb/gadget/nokia.c +++ b/drivers/usb/gadget/nokia.c | |||
@@ -126,9 +126,9 @@ static int __init nokia_bind_config(struct usb_configuration *c) | |||
126 | struct usb_function *f_ecm; | 126 | struct usb_function *f_ecm; |
127 | struct usb_function *f_obex2 = NULL; | 127 | struct usb_function *f_obex2 = NULL; |
128 | int status = 0; | 128 | int status = 0; |
129 | int obex1_stat = 0; | 129 | int obex1_stat = -1; |
130 | int obex2_stat = 0; | 130 | int obex2_stat = -1; |
131 | int phonet_stat = 0; | 131 | int phonet_stat = -1; |
132 | 132 | ||
133 | if (!IS_ERR(fi_phonet)) { | 133 | if (!IS_ERR(fi_phonet)) { |
134 | f_phonet = usb_get_function(fi_phonet); | 134 | f_phonet = usb_get_function(fi_phonet); |
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c index 83957cc225d9..2ae4f6d69f74 100644 --- a/drivers/usb/gadget/omap_udc.c +++ b/drivers/usb/gadget/omap_udc.c | |||
@@ -22,7 +22,6 @@ | |||
22 | #include <linux/errno.h> | 22 | #include <linux/errno.h> |
23 | #include <linux/delay.h> | 23 | #include <linux/delay.h> |
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <linux/init.h> | ||
26 | #include <linux/timer.h> | 25 | #include <linux/timer.h> |
27 | #include <linux/list.h> | 26 | #include <linux/list.h> |
28 | #include <linux/interrupt.h> | 27 | #include <linux/interrupt.h> |
@@ -2586,7 +2585,8 @@ omap_ep_setup(char *name, u8 addr, u8 type, | |||
2586 | 2585 | ||
2587 | ep->ep.name = ep->name; | 2586 | ep->ep.name = ep->name; |
2588 | ep->ep.ops = &omap_ep_ops; | 2587 | ep->ep.ops = &omap_ep_ops; |
2589 | ep->ep.maxpacket = ep->maxpacket = maxp; | 2588 | ep->maxpacket = maxp; |
2589 | usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); | ||
2590 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); | 2590 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); |
2591 | 2591 | ||
2592 | return buf; | 2592 | return buf; |
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c index 32d5e923750b..eb8c3bedb57a 100644 --- a/drivers/usb/gadget/pch_udc.c +++ b/drivers/usb/gadget/pch_udc.c | |||
@@ -2896,12 +2896,12 @@ static void pch_udc_pcd_reinit(struct pch_udc_dev *dev) | |||
2896 | ep->offset_addr = (UDC_EPINT_OUT_SHIFT + ep->num) * | 2896 | ep->offset_addr = (UDC_EPINT_OUT_SHIFT + ep->num) * |
2897 | UDC_EP_REG_SHIFT; | 2897 | UDC_EP_REG_SHIFT; |
2898 | /* need to set ep->ep.maxpacket and set Default Configuration?*/ | 2898 | /* need to set ep->ep.maxpacket and set Default Configuration?*/ |
2899 | ep->ep.maxpacket = UDC_BULK_MAX_PKT_SIZE; | 2899 | usb_ep_set_maxpacket_limit(&ep->ep, UDC_BULK_MAX_PKT_SIZE); |
2900 | list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); | 2900 | list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); |
2901 | INIT_LIST_HEAD(&ep->queue); | 2901 | INIT_LIST_HEAD(&ep->queue); |
2902 | } | 2902 | } |
2903 | dev->ep[UDC_EP0IN_IDX].ep.maxpacket = UDC_EP0IN_MAX_PKT_SIZE; | 2903 | usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0IN_IDX].ep, UDC_EP0IN_MAX_PKT_SIZE); |
2904 | dev->ep[UDC_EP0OUT_IDX].ep.maxpacket = UDC_EP0OUT_MAX_PKT_SIZE; | 2904 | usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0OUT_IDX].ep, UDC_EP0OUT_MAX_PKT_SIZE); |
2905 | 2905 | ||
2906 | /* remove ep0 in and out from the list. They have own pointer */ | 2906 | /* remove ep0 in and out from the list. They have own pointer */ |
2907 | list_del_init(&dev->ep[UDC_EP0IN_IDX].ep.ep_list); | 2907 | list_del_init(&dev->ep[UDC_EP0IN_IDX].ep.ep_list); |
@@ -3210,7 +3210,7 @@ finished: | |||
3210 | return retval; | 3210 | return retval; |
3211 | } | 3211 | } |
3212 | 3212 | ||
3213 | static DEFINE_PCI_DEVICE_TABLE(pch_udc_pcidev_id) = { | 3213 | static const struct pci_device_id pch_udc_pcidev_id[] = { |
3214 | { | 3214 | { |
3215 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EG20T_UDC), | 3215 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EG20T_UDC), |
3216 | .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, | 3216 | .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, |
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c index 409a3c45a36a..9984437d2952 100644 --- a/drivers/usb/gadget/pxa25x_udc.c +++ b/drivers/usb/gadget/pxa25x_udc.c | |||
@@ -24,7 +24,6 @@ | |||
24 | #include <linux/err.h> | 24 | #include <linux/err.h> |
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | #include <linux/init.h> | ||
28 | #include <linux/timer.h> | 27 | #include <linux/timer.h> |
29 | #include <linux/list.h> | 28 | #include <linux/list.h> |
30 | #include <linux/interrupt.h> | 29 | #include <linux/interrupt.h> |
@@ -1194,6 +1193,7 @@ static void udc_reinit(struct pxa25x_udc *dev) | |||
1194 | ep->stopped = 0; | 1193 | ep->stopped = 0; |
1195 | INIT_LIST_HEAD (&ep->queue); | 1194 | INIT_LIST_HEAD (&ep->queue); |
1196 | ep->pio_irqs = 0; | 1195 | ep->pio_irqs = 0; |
1196 | usb_ep_set_maxpacket_limit(&ep->ep, ep->ep.maxpacket); | ||
1197 | } | 1197 | } |
1198 | 1198 | ||
1199 | /* the rest was statically initialized, and is read-only */ | 1199 | /* the rest was statically initialized, and is read-only */ |
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c index 3c97da7760da..cdf4d678be96 100644 --- a/drivers/usb/gadget/pxa27x_udc.c +++ b/drivers/usb/gadget/pxa27x_udc.c | |||
@@ -1737,9 +1737,12 @@ static void udc_init_data(struct pxa_udc *dev) | |||
1737 | } | 1737 | } |
1738 | 1738 | ||
1739 | /* USB endpoints init */ | 1739 | /* USB endpoints init */ |
1740 | for (i = 1; i < NR_USB_ENDPOINTS; i++) | 1740 | for (i = 1; i < NR_USB_ENDPOINTS; i++) { |
1741 | list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list, | 1741 | list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list, |
1742 | &dev->gadget.ep_list); | 1742 | &dev->gadget.ep_list); |
1743 | usb_ep_set_maxpacket_limit(&dev->udc_usb_ep[i].usb_ep, | ||
1744 | dev->udc_usb_ep[i].usb_ep.maxpacket); | ||
1745 | } | ||
1743 | } | 1746 | } |
1744 | 1747 | ||
1745 | /** | 1748 | /** |
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c index 68be48d33404..aff0a6718bc6 100644 --- a/drivers/usb/gadget/r8a66597-udc.c +++ b/drivers/usb/gadget/r8a66597-udc.c | |||
@@ -1833,7 +1833,7 @@ static int __exit r8a66597_remove(struct platform_device *pdev) | |||
1833 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); | 1833 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); |
1834 | 1834 | ||
1835 | if (r8a66597->pdata->on_chip) { | 1835 | if (r8a66597->pdata->on_chip) { |
1836 | clk_disable(r8a66597->clk); | 1836 | clk_disable_unprepare(r8a66597->clk); |
1837 | clk_put(r8a66597->clk); | 1837 | clk_put(r8a66597->clk); |
1838 | } | 1838 | } |
1839 | 1839 | ||
@@ -1931,7 +1931,7 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1931 | ret = PTR_ERR(r8a66597->clk); | 1931 | ret = PTR_ERR(r8a66597->clk); |
1932 | goto clean_up; | 1932 | goto clean_up; |
1933 | } | 1933 | } |
1934 | clk_enable(r8a66597->clk); | 1934 | clk_prepare_enable(r8a66597->clk); |
1935 | } | 1935 | } |
1936 | 1936 | ||
1937 | if (r8a66597->pdata->sudmac) { | 1937 | if (r8a66597->pdata->sudmac) { |
@@ -1964,9 +1964,9 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1964 | INIT_LIST_HEAD(&ep->queue); | 1964 | INIT_LIST_HEAD(&ep->queue); |
1965 | ep->ep.name = r8a66597_ep_name[i]; | 1965 | ep->ep.name = r8a66597_ep_name[i]; |
1966 | ep->ep.ops = &r8a66597_ep_ops; | 1966 | ep->ep.ops = &r8a66597_ep_ops; |
1967 | ep->ep.maxpacket = 512; | 1967 | usb_ep_set_maxpacket_limit(&ep->ep, 512); |
1968 | } | 1968 | } |
1969 | r8a66597->ep[0].ep.maxpacket = 64; | 1969 | usb_ep_set_maxpacket_limit(&r8a66597->ep[0].ep, 64); |
1970 | r8a66597->ep[0].pipenum = 0; | 1970 | r8a66597->ep[0].pipenum = 0; |
1971 | r8a66597->ep[0].fifoaddr = CFIFO; | 1971 | r8a66597->ep[0].fifoaddr = CFIFO; |
1972 | r8a66597->ep[0].fifosel = CFIFOSEL; | 1972 | r8a66597->ep[0].fifosel = CFIFOSEL; |
@@ -1996,7 +1996,7 @@ clean_up3: | |||
1996 | free_irq(irq, r8a66597); | 1996 | free_irq(irq, r8a66597); |
1997 | clean_up2: | 1997 | clean_up2: |
1998 | if (r8a66597->pdata->on_chip) { | 1998 | if (r8a66597->pdata->on_chip) { |
1999 | clk_disable(r8a66597->clk); | 1999 | clk_disable_unprepare(r8a66597->clk); |
2000 | clk_put(r8a66597->clk); | 2000 | clk_put(r8a66597->clk); |
2001 | } | 2001 | } |
2002 | clean_up: | 2002 | clean_up: |
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index a3ad732bc812..d822d822efb3 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c | |||
@@ -25,7 +25,6 @@ | |||
25 | #include <linux/moduleparam.h> | 25 | #include <linux/moduleparam.h> |
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
28 | #include <linux/init.h> | ||
29 | #include <linux/list.h> | 28 | #include <linux/list.h> |
30 | #include <linux/proc_fs.h> | 29 | #include <linux/proc_fs.h> |
31 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
@@ -1142,7 +1141,7 @@ static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS]; | |||
1142 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ | 1141 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ |
1143 | 1142 | ||
1144 | 1143 | ||
1145 | static int rndis_init(void) | 1144 | int rndis_init(void) |
1146 | { | 1145 | { |
1147 | u8 i; | 1146 | u8 i; |
1148 | 1147 | ||
@@ -1174,9 +1173,8 @@ static int rndis_init(void) | |||
1174 | 1173 | ||
1175 | return 0; | 1174 | return 0; |
1176 | } | 1175 | } |
1177 | module_init(rndis_init); | ||
1178 | 1176 | ||
1179 | static void rndis_exit(void) | 1177 | void rndis_exit(void) |
1180 | { | 1178 | { |
1181 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | 1179 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
1182 | u8 i; | 1180 | u8 i; |
@@ -1188,6 +1186,4 @@ static void rndis_exit(void) | |||
1188 | } | 1186 | } |
1189 | #endif | 1187 | #endif |
1190 | } | 1188 | } |
1191 | module_exit(rndis_exit); | ||
1192 | 1189 | ||
1193 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c index e20bc109fdd7..1172eaeddd85 100644 --- a/drivers/usb/gadget/s3c-hsotg.c +++ b/drivers/usb/gadget/s3c-hsotg.c | |||
@@ -30,14 +30,13 @@ | |||
30 | #include <linux/clk.h> | 30 | #include <linux/clk.h> |
31 | #include <linux/regulator/consumer.h> | 31 | #include <linux/regulator/consumer.h> |
32 | #include <linux/of_platform.h> | 32 | #include <linux/of_platform.h> |
33 | #include <linux/phy/phy.h> | ||
33 | 34 | ||
34 | #include <linux/usb/ch9.h> | 35 | #include <linux/usb/ch9.h> |
35 | #include <linux/usb/gadget.h> | 36 | #include <linux/usb/gadget.h> |
36 | #include <linux/usb/phy.h> | 37 | #include <linux/usb/phy.h> |
37 | #include <linux/platform_data/s3c-hsotg.h> | 38 | #include <linux/platform_data/s3c-hsotg.h> |
38 | 39 | ||
39 | #include <mach/map.h> | ||
40 | |||
41 | #include "s3c-hsotg.h" | 40 | #include "s3c-hsotg.h" |
42 | 41 | ||
43 | static const char * const s3c_hsotg_supply_names[] = { | 42 | static const char * const s3c_hsotg_supply_names[] = { |
@@ -140,11 +139,13 @@ struct s3c_hsotg_ep { | |||
140 | * @dev: The parent device supplied to the probe function | 139 | * @dev: The parent device supplied to the probe function |
141 | * @driver: USB gadget driver | 140 | * @driver: USB gadget driver |
142 | * @phy: The otg phy transceiver structure for phy control. | 141 | * @phy: The otg phy transceiver structure for phy control. |
142 | * @uphy: The otg phy transceiver structure for old USB phy control. | ||
143 | * @plat: The platform specific configuration data. This can be removed once | 143 | * @plat: The platform specific configuration data. This can be removed once |
144 | * all SoCs support usb transceiver. | 144 | * all SoCs support usb transceiver. |
145 | * @regs: The memory area mapped for accessing registers. | 145 | * @regs: The memory area mapped for accessing registers. |
146 | * @irq: The IRQ number we are using | 146 | * @irq: The IRQ number we are using |
147 | * @supplies: Definition of USB power supplies | 147 | * @supplies: Definition of USB power supplies |
148 | * @phyif: PHY interface width | ||
148 | * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. | 149 | * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. |
149 | * @num_of_eps: Number of available EPs (excluding EP0) | 150 | * @num_of_eps: Number of available EPs (excluding EP0) |
150 | * @debug_root: root directrory for debugfs. | 151 | * @debug_root: root directrory for debugfs. |
@@ -161,7 +162,8 @@ struct s3c_hsotg_ep { | |||
161 | struct s3c_hsotg { | 162 | struct s3c_hsotg { |
162 | struct device *dev; | 163 | struct device *dev; |
163 | struct usb_gadget_driver *driver; | 164 | struct usb_gadget_driver *driver; |
164 | struct usb_phy *phy; | 165 | struct phy *phy; |
166 | struct usb_phy *uphy; | ||
165 | struct s3c_hsotg_plat *plat; | 167 | struct s3c_hsotg_plat *plat; |
166 | 168 | ||
167 | spinlock_t lock; | 169 | spinlock_t lock; |
@@ -172,6 +174,7 @@ struct s3c_hsotg { | |||
172 | 174 | ||
173 | struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; | 175 | struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; |
174 | 176 | ||
177 | u32 phyif; | ||
175 | unsigned int dedicated_fifos:1; | 178 | unsigned int dedicated_fifos:1; |
176 | unsigned char num_of_eps; | 179 | unsigned char num_of_eps; |
177 | 180 | ||
@@ -2086,13 +2089,13 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) | |||
2086 | case DSTS_EnumSpd_FS48: | 2089 | case DSTS_EnumSpd_FS48: |
2087 | hsotg->gadget.speed = USB_SPEED_FULL; | 2090 | hsotg->gadget.speed = USB_SPEED_FULL; |
2088 | ep0_mps = EP0_MPS_LIMIT; | 2091 | ep0_mps = EP0_MPS_LIMIT; |
2089 | ep_mps = 64; | 2092 | ep_mps = 1023; |
2090 | break; | 2093 | break; |
2091 | 2094 | ||
2092 | case DSTS_EnumSpd_HS: | 2095 | case DSTS_EnumSpd_HS: |
2093 | hsotg->gadget.speed = USB_SPEED_HIGH; | 2096 | hsotg->gadget.speed = USB_SPEED_HIGH; |
2094 | ep0_mps = EP0_MPS_LIMIT; | 2097 | ep0_mps = EP0_MPS_LIMIT; |
2095 | ep_mps = 512; | 2098 | ep_mps = 1024; |
2096 | break; | 2099 | break; |
2097 | 2100 | ||
2098 | case DSTS_EnumSpd_LS: | 2101 | case DSTS_EnumSpd_LS: |
@@ -2156,6 +2159,9 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, | |||
2156 | s3c_hsotg_complete_request(hsotg, ep, req, | 2159 | s3c_hsotg_complete_request(hsotg, ep, req, |
2157 | result); | 2160 | result); |
2158 | } | 2161 | } |
2162 | if(hsotg->dedicated_fifos) | ||
2163 | if ((readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4 < 3072) | ||
2164 | s3c_hsotg_txfifo_flush(hsotg, ep->index); | ||
2159 | } | 2165 | } |
2160 | 2166 | ||
2161 | #define call_gadget(_hs, _entry) \ | 2167 | #define call_gadget(_hs, _entry) \ |
@@ -2283,7 +2289,7 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | |||
2283 | */ | 2289 | */ |
2284 | 2290 | ||
2285 | /* set the PLL on, remove the HNP/SRP and set the PHY */ | 2291 | /* set the PLL on, remove the HNP/SRP and set the PHY */ |
2286 | writel(GUSBCFG_PHYIf16 | GUSBCFG_TOutCal(7) | | 2292 | writel(hsotg->phyif | GUSBCFG_TOutCal(7) | |
2287 | (0x5 << 10), hsotg->regs + GUSBCFG); | 2293 | (0x5 << 10), hsotg->regs + GUSBCFG); |
2288 | 2294 | ||
2289 | s3c_hsotg_init_fifo(hsotg); | 2295 | s3c_hsotg_init_fifo(hsotg); |
@@ -2908,8 +2914,11 @@ static void s3c_hsotg_phy_enable(struct s3c_hsotg *hsotg) | |||
2908 | 2914 | ||
2909 | dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev); | 2915 | dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev); |
2910 | 2916 | ||
2911 | if (hsotg->phy) | 2917 | if (hsotg->phy) { |
2912 | usb_phy_init(hsotg->phy); | 2918 | phy_init(hsotg->phy); |
2919 | phy_power_on(hsotg->phy); | ||
2920 | } else if (hsotg->uphy) | ||
2921 | usb_phy_init(hsotg->uphy); | ||
2913 | else if (hsotg->plat->phy_init) | 2922 | else if (hsotg->plat->phy_init) |
2914 | hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); | 2923 | hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); |
2915 | } | 2924 | } |
@@ -2925,8 +2934,11 @@ static void s3c_hsotg_phy_disable(struct s3c_hsotg *hsotg) | |||
2925 | { | 2934 | { |
2926 | struct platform_device *pdev = to_platform_device(hsotg->dev); | 2935 | struct platform_device *pdev = to_platform_device(hsotg->dev); |
2927 | 2936 | ||
2928 | if (hsotg->phy) | 2937 | if (hsotg->phy) { |
2929 | usb_phy_shutdown(hsotg->phy); | 2938 | phy_power_off(hsotg->phy); |
2939 | phy_exit(hsotg->phy); | ||
2940 | } else if (hsotg->uphy) | ||
2941 | usb_phy_shutdown(hsotg->uphy); | ||
2930 | else if (hsotg->plat->phy_exit) | 2942 | else if (hsotg->plat->phy_exit) |
2931 | hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); | 2943 | hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); |
2932 | } | 2944 | } |
@@ -3152,7 +3164,7 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
3152 | 3164 | ||
3153 | hs_ep->parent = hsotg; | 3165 | hs_ep->parent = hsotg; |
3154 | hs_ep->ep.name = hs_ep->name; | 3166 | hs_ep->ep.name = hs_ep->name; |
3155 | hs_ep->ep.maxpacket = epnum ? 1024 : EP0_MPS_LIMIT; | 3167 | usb_ep_set_maxpacket_limit(&hs_ep->ep, epnum ? 1024 : EP0_MPS_LIMIT); |
3156 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; | 3168 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; |
3157 | 3169 | ||
3158 | /* | 3170 | /* |
@@ -3533,7 +3545,8 @@ static void s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) | |||
3533 | static int s3c_hsotg_probe(struct platform_device *pdev) | 3545 | static int s3c_hsotg_probe(struct platform_device *pdev) |
3534 | { | 3546 | { |
3535 | struct s3c_hsotg_plat *plat = dev_get_platdata(&pdev->dev); | 3547 | struct s3c_hsotg_plat *plat = dev_get_platdata(&pdev->dev); |
3536 | struct usb_phy *phy; | 3548 | struct phy *phy; |
3549 | struct usb_phy *uphy; | ||
3537 | struct device *dev = &pdev->dev; | 3550 | struct device *dev = &pdev->dev; |
3538 | struct s3c_hsotg_ep *eps; | 3551 | struct s3c_hsotg_ep *eps; |
3539 | struct s3c_hsotg *hsotg; | 3552 | struct s3c_hsotg *hsotg; |
@@ -3548,19 +3561,26 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3548 | return -ENOMEM; | 3561 | return -ENOMEM; |
3549 | } | 3562 | } |
3550 | 3563 | ||
3551 | phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); | 3564 | /* |
3565 | * Attempt to find a generic PHY, then look for an old style | ||
3566 | * USB PHY, finally fall back to pdata | ||
3567 | */ | ||
3568 | phy = devm_phy_get(&pdev->dev, "usb2-phy"); | ||
3552 | if (IS_ERR(phy)) { | 3569 | if (IS_ERR(phy)) { |
3553 | /* Fallback for pdata */ | 3570 | uphy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); |
3554 | plat = dev_get_platdata(&pdev->dev); | 3571 | if (IS_ERR(uphy)) { |
3555 | if (!plat) { | 3572 | /* Fallback for pdata */ |
3556 | dev_err(&pdev->dev, "no platform data or transceiver defined\n"); | 3573 | plat = dev_get_platdata(&pdev->dev); |
3557 | return -EPROBE_DEFER; | 3574 | if (!plat) { |
3558 | } else { | 3575 | dev_err(&pdev->dev, |
3576 | "no platform data or transceiver defined\n"); | ||
3577 | return -EPROBE_DEFER; | ||
3578 | } | ||
3559 | hsotg->plat = plat; | 3579 | hsotg->plat = plat; |
3560 | } | 3580 | } else |
3561 | } else { | 3581 | hsotg->uphy = uphy; |
3582 | } else | ||
3562 | hsotg->phy = phy; | 3583 | hsotg->phy = phy; |
3563 | } | ||
3564 | 3584 | ||
3565 | hsotg->dev = dev; | 3585 | hsotg->dev = dev; |
3566 | 3586 | ||
@@ -3627,6 +3647,19 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3627 | goto err_supplies; | 3647 | goto err_supplies; |
3628 | } | 3648 | } |
3629 | 3649 | ||
3650 | /* Set default UTMI width */ | ||
3651 | hsotg->phyif = GUSBCFG_PHYIf16; | ||
3652 | |||
3653 | /* | ||
3654 | * If using the generic PHY framework, check if the PHY bus | ||
3655 | * width is 8-bit and set the phyif appropriately. | ||
3656 | */ | ||
3657 | if (hsotg->phy && (phy_get_bus_width(phy) == 8)) | ||
3658 | hsotg->phyif = GUSBCFG_PHYIf8; | ||
3659 | |||
3660 | if (hsotg->phy) | ||
3661 | phy_init(hsotg->phy); | ||
3662 | |||
3630 | /* usb phy enable */ | 3663 | /* usb phy enable */ |
3631 | s3c_hsotg_phy_enable(hsotg); | 3664 | s3c_hsotg_phy_enable(hsotg); |
3632 | 3665 | ||
@@ -3720,6 +3753,8 @@ static int s3c_hsotg_remove(struct platform_device *pdev) | |||
3720 | } | 3753 | } |
3721 | 3754 | ||
3722 | s3c_hsotg_phy_disable(hsotg); | 3755 | s3c_hsotg_phy_disable(hsotg); |
3756 | if (hsotg->phy) | ||
3757 | phy_exit(hsotg->phy); | ||
3723 | clk_disable_unprepare(hsotg->clk); | 3758 | clk_disable_unprepare(hsotg->clk); |
3724 | 3759 | ||
3725 | return 0; | 3760 | return 0; |
@@ -3733,6 +3768,7 @@ static int s3c_hsotg_remove(struct platform_device *pdev) | |||
3733 | #ifdef CONFIG_OF | 3768 | #ifdef CONFIG_OF |
3734 | static const struct of_device_id s3c_hsotg_of_ids[] = { | 3769 | static const struct of_device_id s3c_hsotg_of_ids[] = { |
3735 | { .compatible = "samsung,s3c6400-hsotg", }, | 3770 | { .compatible = "samsung,s3c6400-hsotg", }, |
3771 | { .compatible = "snps,dwc2", }, | ||
3736 | { /* sentinel */ } | 3772 | { /* sentinel */ } |
3737 | }; | 3773 | }; |
3738 | MODULE_DEVICE_TABLE(of, s3c_hsotg_of_ids); | 3774 | MODULE_DEVICE_TABLE(of, s3c_hsotg_of_ids); |
diff --git a/drivers/usb/gadget/s3c-hsotg.h b/drivers/usb/gadget/s3c-hsotg.h index d650b1295831..85f549ff8c1f 100644 --- a/drivers/usb/gadget/s3c-hsotg.h +++ b/drivers/usb/gadget/s3c-hsotg.h | |||
@@ -55,6 +55,7 @@ | |||
55 | #define GUSBCFG_HNPCap (1 << 9) | 55 | #define GUSBCFG_HNPCap (1 << 9) |
56 | #define GUSBCFG_SRPCap (1 << 8) | 56 | #define GUSBCFG_SRPCap (1 << 8) |
57 | #define GUSBCFG_PHYIf16 (1 << 3) | 57 | #define GUSBCFG_PHYIf16 (1 << 3) |
58 | #define GUSBCFG_PHYIf8 (0 << 3) | ||
58 | #define GUSBCFG_TOutCal_MASK (0x7 << 0) | 59 | #define GUSBCFG_TOutCal_MASK (0x7 << 0) |
59 | #define GUSBCFG_TOutCal_SHIFT (0) | 60 | #define GUSBCFG_TOutCal_SHIFT (0) |
60 | #define GUSBCFG_TOutCal_LIMIT (0x7) | 61 | #define GUSBCFG_TOutCal_LIMIT (0x7) |
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c index 1a1a41498db2..ea4bbfe72ec0 100644 --- a/drivers/usb/gadget/s3c-hsudc.c +++ b/drivers/usb/gadget/s3c-hsudc.c | |||
@@ -999,7 +999,7 @@ static void s3c_hsudc_initep(struct s3c_hsudc *hsudc, | |||
999 | 999 | ||
1000 | hsep->dev = hsudc; | 1000 | hsep->dev = hsudc; |
1001 | hsep->ep.name = hsep->name; | 1001 | hsep->ep.name = hsep->name; |
1002 | hsep->ep.maxpacket = epnum ? 512 : 64; | 1002 | usb_ep_set_maxpacket_limit(&hsep->ep, epnum ? 512 : 64); |
1003 | hsep->ep.ops = &s3c_hsudc_ep_ops; | 1003 | hsep->ep.ops = &s3c_hsudc_ep_ops; |
1004 | hsep->fifo = hsudc->regs + S3C_BR(epnum); | 1004 | hsep->fifo = hsudc->regs + S3C_BR(epnum); |
1005 | hsep->ep.desc = NULL; | 1005 | hsep->ep.desc = NULL; |
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index c72d810e6b36..f04b2c3154de 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -1629,6 +1629,7 @@ static void s3c2410_udc_reinit(struct s3c2410_udc *dev) | |||
1629 | ep->ep.desc = NULL; | 1629 | ep->ep.desc = NULL; |
1630 | ep->halted = 0; | 1630 | ep->halted = 0; |
1631 | INIT_LIST_HEAD(&ep->queue); | 1631 | INIT_LIST_HEAD(&ep->queue); |
1632 | usb_ep_set_maxpacket_limit(&ep->ep, &ep->ep.maxpacket); | ||
1632 | } | 1633 | } |
1633 | } | 1634 | } |
1634 | 1635 | ||
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index 2aae0d61bb19..b7d4f82872b7 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -753,7 +753,7 @@ static struct device_type gadget_type = { | |||
753 | * gadget driver using this framework. The link layer addresses are | 753 | * gadget driver using this framework. The link layer addresses are |
754 | * set up using module parameters. | 754 | * set up using module parameters. |
755 | * | 755 | * |
756 | * Returns negative errno, or zero on success | 756 | * Returns an eth_dev pointer on success, or an ERR_PTR on failure. |
757 | */ | 757 | */ |
758 | struct eth_dev *gether_setup_name(struct usb_gadget *g, | 758 | struct eth_dev *gether_setup_name(struct usb_gadget *g, |
759 | const char *dev_addr, const char *host_addr, | 759 | const char *dev_addr, const char *host_addr, |
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h index fb23d1fde8eb..0f0290acea7e 100644 --- a/drivers/usb/gadget/u_ether.h +++ b/drivers/usb/gadget/u_ether.h | |||
@@ -106,7 +106,7 @@ struct eth_dev *gether_setup_name(struct usb_gadget *g, | |||
106 | * gadget driver using this framework. The link layer addresses are | 106 | * gadget driver using this framework. The link layer addresses are |
107 | * set up using module parameters. | 107 | * set up using module parameters. |
108 | * | 108 | * |
109 | * Returns negative errno, or zero on success | 109 | * Returns a eth_dev pointer on success, or an ERR_PTR on failure |
110 | */ | 110 | */ |
111 | static inline struct eth_dev *gether_setup(struct usb_gadget *g, | 111 | static inline struct eth_dev *gether_setup(struct usb_gadget *g, |
112 | const char *dev_addr, const char *host_addr, | 112 | const char *dev_addr, const char *host_addr, |
@@ -267,45 +267,4 @@ static inline bool can_support_ecm(struct usb_gadget *gadget) | |||
267 | return true; | 267 | return true; |
268 | } | 268 | } |
269 | 269 | ||
270 | /* each configuration may bind one instance of an ethernet link */ | ||
271 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
272 | struct eth_dev *dev); | ||
273 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
274 | struct eth_dev *dev); | ||
275 | |||
276 | #ifdef USB_ETH_RNDIS | ||
277 | |||
278 | int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
279 | u32 vendorID, const char *manufacturer, struct eth_dev *dev); | ||
280 | |||
281 | #else | ||
282 | |||
283 | static inline int | ||
284 | rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
285 | u32 vendorID, const char *manufacturer, struct eth_dev *dev) | ||
286 | { | ||
287 | return 0; | ||
288 | } | ||
289 | |||
290 | #endif | ||
291 | |||
292 | /** | ||
293 | * rndis_bind_config - add RNDIS network link to a configuration | ||
294 | * @c: the configuration to support the network link | ||
295 | * @ethaddr: a buffer in which the ethernet address of the host side | ||
296 | * side of the link was recorded | ||
297 | * Context: single threaded during gadget setup | ||
298 | * | ||
299 | * Returns zero on success, else negative errno. | ||
300 | * | ||
301 | * Caller must have called @gether_setup(). Caller is also responsible | ||
302 | * for calling @gether_cleanup() before module unload. | ||
303 | */ | ||
304 | static inline int rndis_bind_config(struct usb_configuration *c, | ||
305 | u8 ethaddr[ETH_ALEN], struct eth_dev *dev) | ||
306 | { | ||
307 | return rndis_bind_config_vendor(c, ethaddr, 0, NULL, dev); | ||
308 | } | ||
309 | |||
310 | |||
311 | #endif /* __U_ETHER_H */ | 270 | #endif /* __U_ETHER_H */ |
diff --git a/drivers/usb/gadget/u_f.c b/drivers/usb/gadget/u_f.c new file mode 100644 index 000000000000..63b6642c162b --- /dev/null +++ b/drivers/usb/gadget/u_f.c | |||
@@ -0,0 +1,32 @@ | |||
1 | /* | ||
2 | * u_f.c -- USB function utilities for Gadget stack | ||
3 | * | ||
4 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. | ||
5 | * http://www.samsung.com | ||
6 | * | ||
7 | * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> | ||
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 version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | */ | ||
13 | |||
14 | #include <linux/usb/gadget.h> | ||
15 | #include "u_f.h" | ||
16 | |||
17 | struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len) | ||
18 | { | ||
19 | struct usb_request *req; | ||
20 | |||
21 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); | ||
22 | if (req) { | ||
23 | req->length = len ?: default_len; | ||
24 | req->buf = kmalloc(req->length, GFP_ATOMIC); | ||
25 | if (!req->buf) { | ||
26 | usb_ep_free_request(ep, req); | ||
27 | req = NULL; | ||
28 | } | ||
29 | } | ||
30 | return req; | ||
31 | } | ||
32 | EXPORT_SYMBOL(alloc_ep_req); | ||
diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h new file mode 100644 index 000000000000..71034c061fca --- /dev/null +++ b/drivers/usb/gadget/u_f.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /* | ||
2 | * u_f.h | ||
3 | * | ||
4 | * Utility definitions for USB functions | ||
5 | * | ||
6 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. | ||
7 | * http://www.samsung.com | ||
8 | * | ||
9 | * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #ifndef __U_F_H__ | ||
17 | #define __U_F_H__ | ||
18 | |||
19 | struct usb_ep; | ||
20 | struct usb_request; | ||
21 | |||
22 | struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len); | ||
23 | |||
24 | #endif /* __U_F_H__ */ | ||
25 | |||
26 | |||
diff --git a/drivers/usb/gadget/u_fs.h b/drivers/usb/gadget/u_fs.h new file mode 100644 index 000000000000..bc2d3718219b --- /dev/null +++ b/drivers/usb/gadget/u_fs.h | |||
@@ -0,0 +1,267 @@ | |||
1 | /* | ||
2 | * u_fs.h | ||
3 | * | ||
4 | * Utility definitions for the FunctionFS | ||
5 | * | ||
6 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. | ||
7 | * http://www.samsung.com | ||
8 | * | ||
9 | * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #ifndef U_FFS_H | ||
17 | #define U_FFS_H | ||
18 | |||
19 | #include <linux/usb/composite.h> | ||
20 | #include <linux/list.h> | ||
21 | #include <linux/mutex.h> | ||
22 | |||
23 | #ifdef VERBOSE_DEBUG | ||
24 | #ifndef pr_vdebug | ||
25 | # define pr_vdebug pr_debug | ||
26 | #endif /* pr_vdebug */ | ||
27 | # define ffs_dump_mem(prefix, ptr, len) \ | ||
28 | print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len) | ||
29 | #else | ||
30 | #ifndef pr_vdebug | ||
31 | # define pr_vdebug(...) do { } while (0) | ||
32 | #endif /* pr_vdebug */ | ||
33 | # define ffs_dump_mem(prefix, ptr, len) do { } while (0) | ||
34 | #endif /* VERBOSE_DEBUG */ | ||
35 | |||
36 | #define ENTER() pr_vdebug("%s()\n", __func__) | ||
37 | |||
38 | struct f_fs_opts; | ||
39 | |||
40 | struct ffs_dev { | ||
41 | const char *name; | ||
42 | bool name_allocated; | ||
43 | bool mounted; | ||
44 | bool desc_ready; | ||
45 | bool single; | ||
46 | struct ffs_data *ffs_data; | ||
47 | struct f_fs_opts *opts; | ||
48 | struct list_head entry; | ||
49 | |||
50 | int (*ffs_ready_callback)(struct ffs_data *ffs); | ||
51 | void (*ffs_closed_callback)(struct ffs_data *ffs); | ||
52 | void *(*ffs_acquire_dev_callback)(struct ffs_dev *dev); | ||
53 | void (*ffs_release_dev_callback)(struct ffs_dev *dev); | ||
54 | }; | ||
55 | |||
56 | extern struct mutex ffs_lock; | ||
57 | |||
58 | static inline void ffs_dev_lock(void) | ||
59 | { | ||
60 | mutex_lock(&ffs_lock); | ||
61 | } | ||
62 | |||
63 | static inline void ffs_dev_unlock(void) | ||
64 | { | ||
65 | mutex_unlock(&ffs_lock); | ||
66 | } | ||
67 | |||
68 | struct ffs_dev *ffs_alloc_dev(void); | ||
69 | int ffs_name_dev(struct ffs_dev *dev, const char *name); | ||
70 | int ffs_single_dev(struct ffs_dev *dev); | ||
71 | void ffs_free_dev(struct ffs_dev *dev); | ||
72 | |||
73 | struct ffs_epfile; | ||
74 | struct ffs_function; | ||
75 | |||
76 | enum ffs_state { | ||
77 | /* | ||
78 | * Waiting for descriptors and strings. | ||
79 | * | ||
80 | * In this state no open(2), read(2) or write(2) on epfiles | ||
81 | * may succeed (which should not be the problem as there | ||
82 | * should be no such files opened in the first place). | ||
83 | */ | ||
84 | FFS_READ_DESCRIPTORS, | ||
85 | FFS_READ_STRINGS, | ||
86 | |||
87 | /* | ||
88 | * We've got descriptors and strings. We are or have called | ||
89 | * functionfs_ready_callback(). functionfs_bind() may have | ||
90 | * been called but we don't know. | ||
91 | * | ||
92 | * This is the only state in which operations on epfiles may | ||
93 | * succeed. | ||
94 | */ | ||
95 | FFS_ACTIVE, | ||
96 | |||
97 | /* | ||
98 | * All endpoints have been closed. This state is also set if | ||
99 | * we encounter an unrecoverable error. The only | ||
100 | * unrecoverable error is situation when after reading strings | ||
101 | * from user space we fail to initialise epfiles or | ||
102 | * functionfs_ready_callback() returns with error (<0). | ||
103 | * | ||
104 | * In this state no open(2), read(2) or write(2) (both on ep0 | ||
105 | * as well as epfile) may succeed (at this point epfiles are | ||
106 | * unlinked and all closed so this is not a problem; ep0 is | ||
107 | * also closed but ep0 file exists and so open(2) on ep0 must | ||
108 | * fail). | ||
109 | */ | ||
110 | FFS_CLOSING | ||
111 | }; | ||
112 | |||
113 | enum ffs_setup_state { | ||
114 | /* There is no setup request pending. */ | ||
115 | FFS_NO_SETUP, | ||
116 | /* | ||
117 | * User has read events and there was a setup request event | ||
118 | * there. The next read/write on ep0 will handle the | ||
119 | * request. | ||
120 | */ | ||
121 | FFS_SETUP_PENDING, | ||
122 | /* | ||
123 | * There was event pending but before user space handled it | ||
124 | * some other event was introduced which canceled existing | ||
125 | * setup. If this state is set read/write on ep0 return | ||
126 | * -EIDRM. This state is only set when adding event. | ||
127 | */ | ||
128 | FFS_SETUP_CANCELED | ||
129 | }; | ||
130 | |||
131 | struct ffs_data { | ||
132 | struct usb_gadget *gadget; | ||
133 | |||
134 | /* | ||
135 | * Protect access read/write operations, only one read/write | ||
136 | * at a time. As a consequence protects ep0req and company. | ||
137 | * While setup request is being processed (queued) this is | ||
138 | * held. | ||
139 | */ | ||
140 | struct mutex mutex; | ||
141 | |||
142 | /* | ||
143 | * Protect access to endpoint related structures (basically | ||
144 | * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for | ||
145 | * endpoint zero. | ||
146 | */ | ||
147 | spinlock_t eps_lock; | ||
148 | |||
149 | /* | ||
150 | * XXX REVISIT do we need our own request? Since we are not | ||
151 | * handling setup requests immediately user space may be so | ||
152 | * slow that another setup will be sent to the gadget but this | ||
153 | * time not to us but another function and then there could be | ||
154 | * a race. Is that the case? Or maybe we can use cdev->req | ||
155 | * after all, maybe we just need some spinlock for that? | ||
156 | */ | ||
157 | struct usb_request *ep0req; /* P: mutex */ | ||
158 | struct completion ep0req_completion; /* P: mutex */ | ||
159 | int ep0req_status; /* P: mutex */ | ||
160 | |||
161 | /* reference counter */ | ||
162 | atomic_t ref; | ||
163 | /* how many files are opened (EP0 and others) */ | ||
164 | atomic_t opened; | ||
165 | |||
166 | /* EP0 state */ | ||
167 | enum ffs_state state; | ||
168 | |||
169 | /* | ||
170 | * Possible transitions: | ||
171 | * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock | ||
172 | * happens only in ep0 read which is P: mutex | ||
173 | * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock | ||
174 | * happens only in ep0 i/o which is P: mutex | ||
175 | * + FFS_SETUP_PENDING -> FFS_SETUP_CANCELED -- P: ev.waitq.lock | ||
176 | * + FFS_SETUP_CANCELED -> FFS_NO_SETUP -- cmpxchg | ||
177 | */ | ||
178 | enum ffs_setup_state setup_state; | ||
179 | |||
180 | #define FFS_SETUP_STATE(ffs) \ | ||
181 | ((enum ffs_setup_state)cmpxchg(&(ffs)->setup_state, \ | ||
182 | FFS_SETUP_CANCELED, FFS_NO_SETUP)) | ||
183 | |||
184 | /* Events & such. */ | ||
185 | struct { | ||
186 | u8 types[4]; | ||
187 | unsigned short count; | ||
188 | /* XXX REVISIT need to update it in some places, or do we? */ | ||
189 | unsigned short can_stall; | ||
190 | struct usb_ctrlrequest setup; | ||
191 | |||
192 | wait_queue_head_t waitq; | ||
193 | } ev; /* the whole structure, P: ev.waitq.lock */ | ||
194 | |||
195 | /* Flags */ | ||
196 | unsigned long flags; | ||
197 | #define FFS_FL_CALL_CLOSED_CALLBACK 0 | ||
198 | #define FFS_FL_BOUND 1 | ||
199 | |||
200 | /* Active function */ | ||
201 | struct ffs_function *func; | ||
202 | |||
203 | /* | ||
204 | * Device name, write once when file system is mounted. | ||
205 | * Intended for user to read if she wants. | ||
206 | */ | ||
207 | const char *dev_name; | ||
208 | /* Private data for our user (ie. gadget). Managed by user. */ | ||
209 | void *private_data; | ||
210 | |||
211 | /* filled by __ffs_data_got_descs() */ | ||
212 | /* | ||
213 | * Real descriptors are 16 bytes after raw_descs (so you need | ||
214 | * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the | ||
215 | * first full speed descriptor). raw_descs_length and | ||
216 | * raw_fs_descs_length do not have those 16 bytes added. | ||
217 | */ | ||
218 | const void *raw_descs; | ||
219 | unsigned raw_descs_length; | ||
220 | unsigned raw_fs_descs_length; | ||
221 | unsigned fs_descs_count; | ||
222 | unsigned hs_descs_count; | ||
223 | |||
224 | unsigned short strings_count; | ||
225 | unsigned short interfaces_count; | ||
226 | unsigned short eps_count; | ||
227 | unsigned short _pad1; | ||
228 | |||
229 | /* filled by __ffs_data_got_strings() */ | ||
230 | /* ids in stringtabs are set in functionfs_bind() */ | ||
231 | const void *raw_strings; | ||
232 | struct usb_gadget_strings **stringtabs; | ||
233 | |||
234 | /* | ||
235 | * File system's super block, write once when file system is | ||
236 | * mounted. | ||
237 | */ | ||
238 | struct super_block *sb; | ||
239 | |||
240 | /* File permissions, written once when fs is mounted */ | ||
241 | struct ffs_file_perms { | ||
242 | umode_t mode; | ||
243 | kuid_t uid; | ||
244 | kgid_t gid; | ||
245 | } file_perms; | ||
246 | |||
247 | /* | ||
248 | * The endpoint files, filled by ffs_epfiles_create(), | ||
249 | * destroyed by ffs_epfiles_destroy(). | ||
250 | */ | ||
251 | struct ffs_epfile *epfiles; | ||
252 | }; | ||
253 | |||
254 | |||
255 | struct f_fs_opts { | ||
256 | struct usb_function_instance func_inst; | ||
257 | struct ffs_dev *dev; | ||
258 | unsigned refcnt; | ||
259 | bool no_configfs; | ||
260 | }; | ||
261 | |||
262 | static inline struct f_fs_opts *to_f_fs_opts(struct usb_function_instance *fi) | ||
263 | { | ||
264 | return container_of(fi, struct f_fs_opts, func_inst); | ||
265 | } | ||
266 | |||
267 | #endif /* U_FFS_H */ | ||
diff --git a/drivers/usb/gadget/u_rndis.h b/drivers/usb/gadget/u_rndis.h index c62ba82e9600..7291b15c9dce 100644 --- a/drivers/usb/gadget/u_rndis.h +++ b/drivers/usb/gadget/u_rndis.h | |||
@@ -36,6 +36,8 @@ struct f_rndis_opts { | |||
36 | int refcnt; | 36 | int refcnt; |
37 | }; | 37 | }; |
38 | 38 | ||
39 | int rndis_init(void); | ||
40 | void rndis_exit(void); | ||
39 | void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net); | 41 | void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net); |
40 | 42 | ||
41 | #endif /* U_RNDIS_H */ | 43 | #endif /* U_RNDIS_H */ |
diff --git a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c index 1f49fce0f0b7..73a4dfba0edb 100644 --- a/drivers/usb/gadget/usbstring.c +++ b/drivers/usb/gadget/usbstring.c | |||
@@ -13,7 +13,6 @@ | |||
13 | #include <linux/list.h> | 13 | #include <linux/list.h> |
14 | #include <linux/string.h> | 14 | #include <linux/string.h> |
15 | #include <linux/device.h> | 15 | #include <linux/device.h> |
16 | #include <linux/init.h> | ||
17 | #include <linux/nls.h> | 16 | #include <linux/nls.h> |
18 | 17 | ||
19 | #include <linux/usb/ch9.h> | 18 | #include <linux/usb/ch9.h> |
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index f49b0b61ecc8..9f170c53e3d9 100644 --- a/drivers/usb/gadget/zero.c +++ b/drivers/usb/gadget/zero.c | |||
@@ -64,10 +64,10 @@ static bool loopdefault = 0; | |||
64 | module_param(loopdefault, bool, S_IRUGO|S_IWUSR); | 64 | module_param(loopdefault, bool, S_IRUGO|S_IWUSR); |
65 | 65 | ||
66 | static struct usb_zero_options gzero_options = { | 66 | static struct usb_zero_options gzero_options = { |
67 | .isoc_interval = 4, | 67 | .isoc_interval = GZERO_ISOC_INTERVAL, |
68 | .isoc_maxpacket = 1024, | 68 | .isoc_maxpacket = GZERO_ISOC_MAXPACKET, |
69 | .bulk_buflen = 4096, | 69 | .bulk_buflen = GZERO_BULK_BUFLEN, |
70 | .qlen = 32, | 70 | .qlen = GZERO_QLEN, |
71 | }; | 71 | }; |
72 | 72 | ||
73 | /*-------------------------------------------------------------------------*/ | 73 | /*-------------------------------------------------------------------------*/ |
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 01e879ef3654..7530468c9a4f 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile | |||
@@ -2,8 +2,6 @@ | |||
2 | # Makefile for USB Host Controller Drivers | 2 | # Makefile for USB Host Controller Drivers |
3 | # | 3 | # |
4 | 4 | ||
5 | ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG | ||
6 | |||
7 | # tell define_trace.h where to find the xhci trace header | 5 | # tell define_trace.h where to find the xhci trace header |
8 | CFLAGS_xhci-trace.o := -I$(src) | 6 | CFLAGS_xhci-trace.o := -I$(src) |
9 | 7 | ||
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c index 284f8417eae5..ec9f7b75d497 100644 --- a/drivers/usb/host/ehci-atmel.c +++ b/drivers/usb/host/ehci-atmel.c | |||
@@ -153,6 +153,7 @@ static int ehci_atmel_drv_probe(struct platform_device *pdev) | |||
153 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | 153 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); |
154 | if (retval) | 154 | if (retval) |
155 | goto fail_add_hcd; | 155 | goto fail_add_hcd; |
156 | device_wakeup_enable(hcd->self.controller); | ||
156 | 157 | ||
157 | return retval; | 158 | return retval; |
158 | 159 | ||
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index 4a9c2edbcb2b..524cbf26d992 100644 --- a/drivers/usb/host/ehci-dbg.c +++ b/drivers/usb/host/ehci-dbg.c | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | /* this file is part of ehci-hcd.c */ | 19 | /* this file is part of ehci-hcd.c */ |
20 | 20 | ||
21 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) | 21 | #ifdef CONFIG_DYNAMIC_DEBUG |
22 | 22 | ||
23 | /* check the values in the HCSPARAMS register | 23 | /* check the values in the HCSPARAMS register |
24 | * (host controller _Structural_ parameters) | 24 | * (host controller _Structural_ parameters) |
@@ -62,7 +62,7 @@ static inline void dbg_hcs_params (struct ehci_hcd *ehci, char *label) {} | |||
62 | 62 | ||
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) | 65 | #ifdef CONFIG_DYNAMIC_DEBUG |
66 | 66 | ||
67 | /* check the values in the HCCPARAMS register | 67 | /* check the values in the HCCPARAMS register |
68 | * (host controller _Capability_ parameters) | 68 | * (host controller _Capability_ parameters) |
@@ -101,7 +101,7 @@ static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {} | |||
101 | 101 | ||
102 | #endif | 102 | #endif |
103 | 103 | ||
104 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) | 104 | #ifdef CONFIG_DYNAMIC_DEBUG |
105 | 105 | ||
106 | static void __maybe_unused | 106 | static void __maybe_unused |
107 | dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd) | 107 | dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd) |
@@ -301,7 +301,7 @@ static inline int __maybe_unused | |||
301 | dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status) | 301 | dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status) |
302 | { return 0; } | 302 | { return 0; } |
303 | 303 | ||
304 | #endif /* DEBUG || CONFIG_DYNAMIC_DEBUG */ | 304 | #endif /* CONFIG_DYNAMIC_DEBUG */ |
305 | 305 | ||
306 | /* functions have the "wrong" filename when they're output... */ | 306 | /* functions have the "wrong" filename when they're output... */ |
307 | #define dbg_status(ehci, label, status) { \ | 307 | #define dbg_status(ehci, label, status) { \ |
@@ -818,7 +818,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf) | |||
818 | 818 | ||
819 | #ifdef CONFIG_PCI | 819 | #ifdef CONFIG_PCI |
820 | /* EHCI 0.96 and later may have "extended capabilities" */ | 820 | /* EHCI 0.96 and later may have "extended capabilities" */ |
821 | if (hcd->self.controller->bus == &pci_bus_type) { | 821 | if (dev_is_pci(hcd->self.controller)) { |
822 | struct pci_dev *pdev; | 822 | struct pci_dev *pdev; |
823 | u32 offset, cap, cap2; | 823 | u32 offset, cap, cap2; |
824 | unsigned count = 256/4; | 824 | unsigned count = 256/4; |
diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c index e97c198e052f..d1d8c47777c5 100644 --- a/drivers/usb/host/ehci-exynos.c +++ b/drivers/usb/host/ehci-exynos.c | |||
@@ -166,6 +166,7 @@ skip_phy: | |||
166 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); | 166 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); |
167 | goto fail_add_hcd; | 167 | goto fail_add_hcd; |
168 | } | 168 | } |
169 | device_wakeup_enable(hcd->self.controller); | ||
169 | 170 | ||
170 | platform_set_drvdata(pdev, hcd); | 171 | platform_set_drvdata(pdev, hcd); |
171 | 172 | ||
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c index a06d5012201f..6f2c8d3899d2 100644 --- a/drivers/usb/host/ehci-fsl.c +++ b/drivers/usb/host/ehci-fsl.c | |||
@@ -102,19 +102,11 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver, | |||
102 | } | 102 | } |
103 | hcd->rsrc_start = res->start; | 103 | hcd->rsrc_start = res->start; |
104 | hcd->rsrc_len = resource_size(res); | 104 | hcd->rsrc_len = resource_size(res); |
105 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, | 105 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
106 | driver->description)) { | 106 | if (IS_ERR(hcd->regs)) { |
107 | dev_dbg(&pdev->dev, "controller already in use\n"); | 107 | retval = PTR_ERR(hcd->regs); |
108 | retval = -EBUSY; | ||
109 | goto err2; | 108 | goto err2; |
110 | } | 109 | } |
111 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
112 | |||
113 | if (hcd->regs == NULL) { | ||
114 | dev_dbg(&pdev->dev, "error mapping memory\n"); | ||
115 | retval = -EFAULT; | ||
116 | goto err3; | ||
117 | } | ||
118 | 110 | ||
119 | pdata->regs = hcd->regs; | 111 | pdata->regs = hcd->regs; |
120 | 112 | ||
@@ -126,7 +118,7 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver, | |||
126 | */ | 118 | */ |
127 | if (pdata->init && pdata->init(pdev)) { | 119 | if (pdata->init && pdata->init(pdev)) { |
128 | retval = -ENODEV; | 120 | retval = -ENODEV; |
129 | goto err4; | 121 | goto err2; |
130 | } | 122 | } |
131 | 123 | ||
132 | /* Enable USB controller, 83xx or 8536 */ | 124 | /* Enable USB controller, 83xx or 8536 */ |
@@ -137,7 +129,8 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver, | |||
137 | 129 | ||
138 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | 130 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); |
139 | if (retval != 0) | 131 | if (retval != 0) |
140 | goto err4; | 132 | goto err2; |
133 | device_wakeup_enable(hcd->self.controller); | ||
141 | 134 | ||
142 | #ifdef CONFIG_USB_OTG | 135 | #ifdef CONFIG_USB_OTG |
143 | if (pdata->operating_mode == FSL_USB2_DR_OTG) { | 136 | if (pdata->operating_mode == FSL_USB2_DR_OTG) { |
@@ -152,21 +145,17 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver, | |||
152 | &ehci_to_hcd(ehci)->self); | 145 | &ehci_to_hcd(ehci)->self); |
153 | if (retval) { | 146 | if (retval) { |
154 | usb_put_phy(hcd->phy); | 147 | usb_put_phy(hcd->phy); |
155 | goto err4; | 148 | goto err2; |
156 | } | 149 | } |
157 | } else { | 150 | } else { |
158 | dev_err(&pdev->dev, "can't find phy\n"); | 151 | dev_err(&pdev->dev, "can't find phy\n"); |
159 | retval = -ENODEV; | 152 | retval = -ENODEV; |
160 | goto err4; | 153 | goto err2; |
161 | } | 154 | } |
162 | } | 155 | } |
163 | #endif | 156 | #endif |
164 | return retval; | 157 | return retval; |
165 | 158 | ||
166 | err4: | ||
167 | iounmap(hcd->regs); | ||
168 | err3: | ||
169 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
170 | err2: | 159 | err2: |
171 | usb_put_hcd(hcd); | 160 | usb_put_hcd(hcd); |
172 | err1: | 161 | err1: |
@@ -205,8 +194,6 @@ static void usb_hcd_fsl_remove(struct usb_hcd *hcd, | |||
205 | */ | 194 | */ |
206 | if (pdata->exit) | 195 | if (pdata->exit) |
207 | pdata->exit(pdev); | 196 | pdata->exit(pdev); |
208 | iounmap(hcd->regs); | ||
209 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
210 | usb_put_hcd(hcd); | 197 | usb_put_hcd(hcd); |
211 | } | 198 | } |
212 | 199 | ||
@@ -267,7 +254,7 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd, | |||
267 | if (!(spin_event_timeout(in_be32(non_ehci + FSL_SOC_USB_CTRL) & | 254 | if (!(spin_event_timeout(in_be32(non_ehci + FSL_SOC_USB_CTRL) & |
268 | PHY_CLK_VALID, FSL_USB_PHY_CLK_TIMEOUT, 0) || | 255 | PHY_CLK_VALID, FSL_USB_PHY_CLK_TIMEOUT, 0) || |
269 | in_be32(non_ehci + FSL_SOC_USB_PRICTRL))) { | 256 | in_be32(non_ehci + FSL_SOC_USB_PRICTRL))) { |
270 | printk(KERN_WARNING "fsl-ehci: USB PHY clock invalid\n"); | 257 | dev_warn(hcd->self.controller, "USB PHY clock invalid\n"); |
271 | return -EINVAL; | 258 | return -EINVAL; |
272 | } | 259 | } |
273 | } | 260 | } |
@@ -413,7 +400,7 @@ static int ehci_fsl_mpc512x_drv_suspend(struct device *dev) | |||
413 | struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev); | 400 | struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev); |
414 | u32 tmp; | 401 | u32 tmp; |
415 | 402 | ||
416 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) | 403 | #ifdef CONFIG_DYNAMIC_DEBUG |
417 | u32 mode = ehci_readl(ehci, hcd->regs + FSL_SOC_USB_USBMODE); | 404 | u32 mode = ehci_readl(ehci, hcd->regs + FSL_SOC_USB_USBMODE); |
418 | mode &= USBMODE_CM_MASK; | 405 | mode &= USBMODE_CM_MASK; |
419 | tmp = ehci_readl(ehci, hcd->regs + 0x140); /* usbcmd */ | 406 | tmp = ehci_readl(ehci, hcd->regs + 0x140); /* usbcmd */ |
diff --git a/drivers/usb/host/ehci-grlib.c b/drivers/usb/host/ehci-grlib.c index b52a66ce92e8..495b6fbcbcd9 100644 --- a/drivers/usb/host/ehci-grlib.c +++ b/drivers/usb/host/ehci-grlib.c | |||
@@ -113,7 +113,8 @@ static int ehci_hcd_grlib_probe(struct platform_device *op) | |||
113 | 113 | ||
114 | irq = irq_of_parse_and_map(dn, 0); | 114 | irq = irq_of_parse_and_map(dn, 0); |
115 | if (irq == NO_IRQ) { | 115 | if (irq == NO_IRQ) { |
116 | printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__); | 116 | dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n", |
117 | __FILE__); | ||
117 | rv = -EBUSY; | 118 | rv = -EBUSY; |
118 | goto err_irq; | 119 | goto err_irq; |
119 | } | 120 | } |
@@ -140,6 +141,7 @@ static int ehci_hcd_grlib_probe(struct platform_device *op) | |||
140 | if (rv) | 141 | if (rv) |
141 | goto err_ioremap; | 142 | goto err_ioremap; |
142 | 143 | ||
144 | device_wakeup_enable(hcd->self.controller); | ||
143 | return 0; | 145 | return 0; |
144 | 146 | ||
145 | err_ioremap: | 147 | err_ioremap: |
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index e8ba4c44223a..471142725ffe 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c | |||
@@ -71,7 +71,6 @@ | |||
71 | static const char hcd_name [] = "ehci_hcd"; | 71 | static const char hcd_name [] = "ehci_hcd"; |
72 | 72 | ||
73 | 73 | ||
74 | #undef VERBOSE_DEBUG | ||
75 | #undef EHCI_URB_TRACE | 74 | #undef EHCI_URB_TRACE |
76 | 75 | ||
77 | /* magic numbers that can affect system performance */ | 76 | /* magic numbers that can affect system performance */ |
@@ -714,13 +713,6 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd) | |||
714 | cmd = ehci_readl(ehci, &ehci->regs->command); | 713 | cmd = ehci_readl(ehci, &ehci->regs->command); |
715 | bh = 0; | 714 | bh = 0; |
716 | 715 | ||
717 | #ifdef VERBOSE_DEBUG | ||
718 | /* unrequested/ignored: Frame List Rollover */ | ||
719 | dbg_status (ehci, "irq", status); | ||
720 | #endif | ||
721 | |||
722 | /* INT, ERR, and IAA interrupt rates can be throttled */ | ||
723 | |||
724 | /* normal [4.15.1.2] or error [4.15.1.1] completion */ | 716 | /* normal [4.15.1.2] or error [4.15.1.1] completion */ |
725 | if (likely ((status & (STS_INT|STS_ERR)) != 0)) { | 717 | if (likely ((status & (STS_INT|STS_ERR)) != 0)) { |
726 | if (likely ((status & STS_ERR) == 0)) | 718 | if (likely ((status & STS_ERR) == 0)) |
@@ -1320,7 +1312,7 @@ static int __init ehci_hcd_init(void) | |||
1320 | sizeof(struct ehci_qh), sizeof(struct ehci_qtd), | 1312 | sizeof(struct ehci_qh), sizeof(struct ehci_qtd), |
1321 | sizeof(struct ehci_itd), sizeof(struct ehci_sitd)); | 1313 | sizeof(struct ehci_itd), sizeof(struct ehci_sitd)); |
1322 | 1314 | ||
1323 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) | 1315 | #ifdef CONFIG_DYNAMIC_DEBUG |
1324 | ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root); | 1316 | ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root); |
1325 | if (!ehci_debug_root) { | 1317 | if (!ehci_debug_root) { |
1326 | retval = -ENOENT; | 1318 | retval = -ENOENT; |
@@ -1369,7 +1361,7 @@ clean2: | |||
1369 | platform_driver_unregister(&PLATFORM_DRIVER); | 1361 | platform_driver_unregister(&PLATFORM_DRIVER); |
1370 | clean0: | 1362 | clean0: |
1371 | #endif | 1363 | #endif |
1372 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) | 1364 | #ifdef CONFIG_DYNAMIC_DEBUG |
1373 | debugfs_remove(ehci_debug_root); | 1365 | debugfs_remove(ehci_debug_root); |
1374 | ehci_debug_root = NULL; | 1366 | ehci_debug_root = NULL; |
1375 | err_debug: | 1367 | err_debug: |
@@ -1393,7 +1385,7 @@ static void __exit ehci_hcd_cleanup(void) | |||
1393 | #ifdef PS3_SYSTEM_BUS_DRIVER | 1385 | #ifdef PS3_SYSTEM_BUS_DRIVER |
1394 | ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); | 1386 | ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); |
1395 | #endif | 1387 | #endif |
1396 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) | 1388 | #ifdef CONFIG_DYNAMIC_DEBUG |
1397 | debugfs_remove(ehci_debug_root); | 1389 | debugfs_remove(ehci_debug_root); |
1398 | #endif | 1390 | #endif |
1399 | clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); | 1391 | clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); |
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 835fc0844a66..47b858fc50b2 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c | |||
@@ -1114,10 +1114,8 @@ static int ehci_hub_control ( | |||
1114 | if (test_bit(wIndex, &ehci->port_c_suspend)) | 1114 | if (test_bit(wIndex, &ehci->port_c_suspend)) |
1115 | status |= USB_PORT_STAT_C_SUSPEND << 16; | 1115 | status |= USB_PORT_STAT_C_SUSPEND << 16; |
1116 | 1116 | ||
1117 | #ifndef VERBOSE_DEBUG | 1117 | if (status & ~0xffff) /* only if wPortChange is interesting */ |
1118 | if (status & ~0xffff) /* only if wPortChange is interesting */ | 1118 | dbg_port(ehci, "GetStatus", wIndex + 1, temp); |
1119 | #endif | ||
1120 | dbg_port (ehci, "GetStatus", wIndex + 1, temp); | ||
1121 | put_unaligned_le32(status, buf); | 1119 | put_unaligned_le32(status, buf); |
1122 | break; | 1120 | break; |
1123 | case SetHubFeature: | 1121 | case SetHubFeature: |
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c index 417c10da9450..bd61612a7251 100644 --- a/drivers/usb/host/ehci-mv.c +++ b/drivers/usb/host/ehci-mv.c | |||
@@ -178,7 +178,7 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
178 | 178 | ||
179 | ehci_mv->phy_regs = devm_ioremap(&pdev->dev, r->start, | 179 | ehci_mv->phy_regs = devm_ioremap(&pdev->dev, r->start, |
180 | resource_size(r)); | 180 | resource_size(r)); |
181 | if (ehci_mv->phy_regs == 0) { | 181 | if (!ehci_mv->phy_regs) { |
182 | dev_err(&pdev->dev, "failed to map phy I/O memory\n"); | 182 | dev_err(&pdev->dev, "failed to map phy I/O memory\n"); |
183 | retval = -EFAULT; | 183 | retval = -EFAULT; |
184 | goto err_put_hcd; | 184 | goto err_put_hcd; |
@@ -257,6 +257,7 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
257 | "failed to add hcd with err %d\n", retval); | 257 | "failed to add hcd with err %d\n", retval); |
258 | goto err_set_vbus; | 258 | goto err_set_vbus; |
259 | } | 259 | } |
260 | device_wakeup_enable(hcd->self.controller); | ||
260 | } | 261 | } |
261 | 262 | ||
262 | if (pdata->private_init) | 263 | if (pdata->private_init) |
diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c index 0528dc4526c8..dbe5e4eea08d 100644 --- a/drivers/usb/host/ehci-mxc.c +++ b/drivers/usb/host/ehci-mxc.c | |||
@@ -155,6 +155,7 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev) | |||
155 | if (ret) | 155 | if (ret) |
156 | goto err_add; | 156 | goto err_add; |
157 | 157 | ||
158 | device_wakeup_enable(hcd->self.controller); | ||
158 | return 0; | 159 | return 0; |
159 | 160 | ||
160 | err_add: | 161 | err_add: |
diff --git a/drivers/usb/host/ehci-octeon.c b/drivers/usb/host/ehci-octeon.c index 4c528b2c033a..9051439039a7 100644 --- a/drivers/usb/host/ehci-octeon.c +++ b/drivers/usb/host/ehci-octeon.c | |||
@@ -128,20 +128,12 @@ static int ehci_octeon_drv_probe(struct platform_device *pdev) | |||
128 | hcd->rsrc_start = res_mem->start; | 128 | hcd->rsrc_start = res_mem->start; |
129 | hcd->rsrc_len = resource_size(res_mem); | 129 | hcd->rsrc_len = resource_size(res_mem); |
130 | 130 | ||
131 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, | 131 | hcd->regs = devm_ioremap_resource(&pdev->dev, res_mem); |
132 | OCTEON_EHCI_HCD_NAME)) { | 132 | if (IS_ERR(hcd->regs)) { |
133 | dev_err(&pdev->dev, "request_mem_region failed\n"); | 133 | ret = PTR_ERR(hcd->regs); |
134 | ret = -EBUSY; | ||
135 | goto err1; | 134 | goto err1; |
136 | } | 135 | } |
137 | 136 | ||
138 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
139 | if (!hcd->regs) { | ||
140 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
141 | ret = -ENOMEM; | ||
142 | goto err2; | ||
143 | } | ||
144 | |||
145 | ehci_octeon_start(); | 137 | ehci_octeon_start(); |
146 | 138 | ||
147 | ehci = hcd_to_ehci(hcd); | 139 | ehci = hcd_to_ehci(hcd); |
@@ -156,18 +148,16 @@ static int ehci_octeon_drv_probe(struct platform_device *pdev) | |||
156 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); | 148 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
157 | if (ret) { | 149 | if (ret) { |
158 | dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); | 150 | dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); |
159 | goto err3; | 151 | goto err2; |
160 | } | 152 | } |
153 | device_wakeup_enable(hcd->self.controller); | ||
161 | 154 | ||
162 | platform_set_drvdata(pdev, hcd); | 155 | platform_set_drvdata(pdev, hcd); |
163 | 156 | ||
164 | return 0; | 157 | return 0; |
165 | err3: | 158 | err2: |
166 | ehci_octeon_stop(); | 159 | ehci_octeon_stop(); |
167 | 160 | ||
168 | iounmap(hcd->regs); | ||
169 | err2: | ||
170 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
171 | err1: | 161 | err1: |
172 | usb_put_hcd(hcd); | 162 | usb_put_hcd(hcd); |
173 | return ret; | 163 | return ret; |
@@ -180,8 +170,6 @@ static int ehci_octeon_drv_remove(struct platform_device *pdev) | |||
180 | usb_remove_hcd(hcd); | 170 | usb_remove_hcd(hcd); |
181 | 171 | ||
182 | ehci_octeon_stop(); | 172 | ehci_octeon_stop(); |
183 | iounmap(hcd->regs); | ||
184 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
185 | usb_put_hcd(hcd); | 173 | usb_put_hcd(hcd); |
186 | 174 | ||
187 | return 0; | 175 | return 0; |
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c index 6fa82d6b7661..a24720beb39d 100644 --- a/drivers/usb/host/ehci-omap.c +++ b/drivers/usb/host/ehci-omap.c | |||
@@ -215,6 +215,7 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev) | |||
215 | dev_err(dev, "failed to add hcd with err %d\n", ret); | 215 | dev_err(dev, "failed to add hcd with err %d\n", ret); |
216 | goto err_pm_runtime; | 216 | goto err_pm_runtime; |
217 | } | 217 | } |
218 | device_wakeup_enable(hcd->self.controller); | ||
218 | 219 | ||
219 | /* | 220 | /* |
220 | * Bring PHYs out of reset for non PHY modes. | 221 | * Bring PHYs out of reset for non PHY modes. |
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c index 2ba76730e650..30d35e5e503a 100644 --- a/drivers/usb/host/ehci-orion.c +++ b/drivers/usb/host/ehci-orion.c | |||
@@ -184,33 +184,23 @@ static int ehci_orion_drv_probe(struct platform_device *pdev) | |||
184 | if (err) | 184 | if (err) |
185 | goto err1; | 185 | goto err1; |
186 | 186 | ||
187 | if (!request_mem_region(res->start, resource_size(res), | 187 | regs = devm_ioremap_resource(&pdev->dev, res); |
188 | ehci_orion_hc_driver.description)) { | 188 | if (IS_ERR(regs)) { |
189 | dev_dbg(&pdev->dev, "controller already in use\n"); | 189 | err = PTR_ERR(regs); |
190 | err = -EBUSY; | ||
191 | goto err1; | 190 | goto err1; |
192 | } | 191 | } |
193 | 192 | ||
194 | regs = ioremap(res->start, resource_size(res)); | ||
195 | if (regs == NULL) { | ||
196 | dev_dbg(&pdev->dev, "error mapping memory\n"); | ||
197 | err = -EFAULT; | ||
198 | goto err2; | ||
199 | } | ||
200 | |||
201 | /* Not all platforms can gate the clock, so it is not | 193 | /* Not all platforms can gate the clock, so it is not |
202 | an error if the clock does not exists. */ | 194 | an error if the clock does not exists. */ |
203 | clk = clk_get(&pdev->dev, NULL); | 195 | clk = devm_clk_get(&pdev->dev, NULL); |
204 | if (!IS_ERR(clk)) { | 196 | if (!IS_ERR(clk)) |
205 | clk_prepare_enable(clk); | 197 | clk_prepare_enable(clk); |
206 | clk_put(clk); | ||
207 | } | ||
208 | 198 | ||
209 | hcd = usb_create_hcd(&ehci_orion_hc_driver, | 199 | hcd = usb_create_hcd(&ehci_orion_hc_driver, |
210 | &pdev->dev, dev_name(&pdev->dev)); | 200 | &pdev->dev, dev_name(&pdev->dev)); |
211 | if (!hcd) { | 201 | if (!hcd) { |
212 | err = -ENOMEM; | 202 | err = -ENOMEM; |
213 | goto err3; | 203 | goto err2; |
214 | } | 204 | } |
215 | 205 | ||
216 | hcd->rsrc_start = res->start; | 206 | hcd->rsrc_start = res->start; |
@@ -245,25 +235,21 @@ static int ehci_orion_drv_probe(struct platform_device *pdev) | |||
245 | case EHCI_PHY_DD: | 235 | case EHCI_PHY_DD: |
246 | case EHCI_PHY_KW: | 236 | case EHCI_PHY_KW: |
247 | default: | 237 | default: |
248 | printk(KERN_WARNING "Orion ehci -USB phy version isn't supported.\n"); | 238 | dev_warn(&pdev->dev, "USB phy version isn't supported.\n"); |
249 | } | 239 | } |
250 | 240 | ||
251 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); | 241 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
252 | if (err) | 242 | if (err) |
253 | goto err4; | 243 | goto err3; |
254 | 244 | ||
245 | device_wakeup_enable(hcd->self.controller); | ||
255 | return 0; | 246 | return 0; |
256 | 247 | ||
257 | err4: | ||
258 | usb_put_hcd(hcd); | ||
259 | err3: | 248 | err3: |
260 | if (!IS_ERR(clk)) { | 249 | usb_put_hcd(hcd); |
261 | clk_disable_unprepare(clk); | ||
262 | clk_put(clk); | ||
263 | } | ||
264 | iounmap(regs); | ||
265 | err2: | 250 | err2: |
266 | release_mem_region(res->start, resource_size(res)); | 251 | if (!IS_ERR(clk)) |
252 | clk_disable_unprepare(clk); | ||
267 | err1: | 253 | err1: |
268 | dev_err(&pdev->dev, "init %s fail, %d\n", | 254 | dev_err(&pdev->dev, "init %s fail, %d\n", |
269 | dev_name(&pdev->dev), err); | 255 | dev_name(&pdev->dev), err); |
@@ -277,15 +263,11 @@ static int ehci_orion_drv_remove(struct platform_device *pdev) | |||
277 | struct clk *clk; | 263 | struct clk *clk; |
278 | 264 | ||
279 | usb_remove_hcd(hcd); | 265 | usb_remove_hcd(hcd); |
280 | iounmap(hcd->regs); | ||
281 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
282 | usb_put_hcd(hcd); | 266 | usb_put_hcd(hcd); |
283 | 267 | ||
284 | clk = clk_get(&pdev->dev, NULL); | 268 | clk = devm_clk_get(&pdev->dev, NULL); |
285 | if (!IS_ERR(clk)) { | 269 | if (!IS_ERR(clk)) |
286 | clk_disable_unprepare(clk); | 270 | clk_disable_unprepare(clk); |
287 | clk_put(clk); | ||
288 | } | ||
289 | return 0; | 271 | return 0; |
290 | } | 272 | } |
291 | 273 | ||
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c index 7f30b7168d5a..01536cfd361d 100644 --- a/drivers/usb/host/ehci-platform.c +++ b/drivers/usb/host/ehci-platform.c | |||
@@ -132,6 +132,7 @@ static int ehci_platform_probe(struct platform_device *dev) | |||
132 | if (err) | 132 | if (err) |
133 | goto err_put_hcd; | 133 | goto err_put_hcd; |
134 | 134 | ||
135 | device_wakeup_enable(hcd->self.controller); | ||
135 | platform_set_drvdata(dev, hcd); | 136 | platform_set_drvdata(dev, hcd); |
136 | 137 | ||
137 | return err; | 138 | return err; |
diff --git a/drivers/usb/host/ehci-pmcmsp.c b/drivers/usb/host/ehci-pmcmsp.c index 893b707f0000..af3974a5e7c2 100644 --- a/drivers/usb/host/ehci-pmcmsp.c +++ b/drivers/usb/host/ehci-pmcmsp.c | |||
@@ -210,8 +210,10 @@ int usb_hcd_msp_probe(const struct hc_driver *driver, | |||
210 | 210 | ||
211 | 211 | ||
212 | retval = usb_add_hcd(hcd, res->start, IRQF_SHARED); | 212 | retval = usb_add_hcd(hcd, res->start, IRQF_SHARED); |
213 | if (retval == 0) | 213 | if (retval == 0) { |
214 | device_wakeup_enable(hcd->self.controller); | ||
214 | return 0; | 215 | return 0; |
216 | } | ||
215 | 217 | ||
216 | usb_remove_hcd(hcd); | 218 | usb_remove_hcd(hcd); |
217 | err3: | 219 | err3: |
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c index 875d2fcc9e0e..547924796d29 100644 --- a/drivers/usb/host/ehci-ppc-of.c +++ b/drivers/usb/host/ehci-ppc-of.c | |||
@@ -119,7 +119,8 @@ static int ehci_hcd_ppc_of_probe(struct platform_device *op) | |||
119 | 119 | ||
120 | irq = irq_of_parse_and_map(dn, 0); | 120 | irq = irq_of_parse_and_map(dn, 0); |
121 | if (irq == NO_IRQ) { | 121 | if (irq == NO_IRQ) { |
122 | printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__); | 122 | dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n", |
123 | __FILE__); | ||
123 | rv = -EBUSY; | 124 | rv = -EBUSY; |
124 | goto err_irq; | 125 | goto err_irq; |
125 | } | 126 | } |
@@ -169,6 +170,7 @@ static int ehci_hcd_ppc_of_probe(struct platform_device *op) | |||
169 | if (rv) | 170 | if (rv) |
170 | goto err_ioremap; | 171 | goto err_ioremap; |
171 | 172 | ||
173 | device_wakeup_enable(hcd->self.controller); | ||
172 | return 0; | 174 | return 0; |
173 | 175 | ||
174 | err_ioremap: | 176 | err_ioremap: |
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c index 8188542ba17e..7934ff9b35e1 100644 --- a/drivers/usb/host/ehci-ps3.c +++ b/drivers/usb/host/ehci-ps3.c | |||
@@ -189,6 +189,7 @@ static int ps3_ehci_probe(struct ps3_system_bus_device *dev) | |||
189 | goto fail_add_hcd; | 189 | goto fail_add_hcd; |
190 | } | 190 | } |
191 | 191 | ||
192 | device_wakeup_enable(hcd->self.controller); | ||
192 | return result; | 193 | return result; |
193 | 194 | ||
194 | fail_add_hcd: | 195 | fail_add_hcd: |
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c index db05bd8ee9d5..54f5332f814d 100644 --- a/drivers/usb/host/ehci-q.c +++ b/drivers/usb/host/ehci-q.c | |||
@@ -168,13 +168,13 @@ static void ehci_clear_tt_buffer(struct ehci_hcd *ehci, struct ehci_qh *qh, | |||
168 | * Note: this routine is never called for Isochronous transfers. | 168 | * Note: this routine is never called for Isochronous transfers. |
169 | */ | 169 | */ |
170 | if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->clearing_tt) { | 170 | if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->clearing_tt) { |
171 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) | 171 | #ifdef CONFIG_DYNAMIC_DEBUG |
172 | struct usb_device *tt = urb->dev->tt->hub; | 172 | struct usb_device *tt = urb->dev->tt->hub; |
173 | dev_dbg(&tt->dev, | 173 | dev_dbg(&tt->dev, |
174 | "clear tt buffer port %d, a%d ep%d t%08x\n", | 174 | "clear tt buffer port %d, a%d ep%d t%08x\n", |
175 | urb->dev->ttport, urb->dev->devnum, | 175 | urb->dev->ttport, urb->dev->devnum, |
176 | usb_pipeendpoint(urb->pipe), token); | 176 | usb_pipeendpoint(urb->pipe), token); |
177 | #endif /* DEBUG || CONFIG_DYNAMIC_DEBUG */ | 177 | #endif /* CONFIG_DYNAMIC_DEBUG */ |
178 | if (!ehci_is_TDI(ehci) | 178 | if (!ehci_is_TDI(ehci) |
179 | || urb->dev->tt->hub != | 179 | || urb->dev->tt->hub != |
180 | ehci_to_hcd(ehci)->self.root_hub) { | 180 | ehci_to_hcd(ehci)->self.root_hub) { |
diff --git a/drivers/usb/host/ehci-sead3.c b/drivers/usb/host/ehci-sead3.c index 8a734498079b..cf1267673868 100644 --- a/drivers/usb/host/ehci-sead3.c +++ b/drivers/usb/host/ehci-sead3.c | |||
@@ -126,6 +126,7 @@ static int ehci_hcd_sead3_drv_probe(struct platform_device *pdev) | |||
126 | IRQF_SHARED); | 126 | IRQF_SHARED); |
127 | if (ret == 0) { | 127 | if (ret == 0) { |
128 | platform_set_drvdata(pdev, hcd); | 128 | platform_set_drvdata(pdev, hcd); |
129 | device_wakeup_enable(hcd->self.controller); | ||
129 | return ret; | 130 | return ret; |
130 | } | 131 | } |
131 | 132 | ||
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c index dc899eb2b861..9b9b9f5b016e 100644 --- a/drivers/usb/host/ehci-sh.c +++ b/drivers/usb/host/ehci-sh.c | |||
@@ -151,6 +151,7 @@ static int ehci_hcd_sh_probe(struct platform_device *pdev) | |||
151 | dev_err(&pdev->dev, "Failed to add hcd"); | 151 | dev_err(&pdev->dev, "Failed to add hcd"); |
152 | goto fail_add_hcd; | 152 | goto fail_add_hcd; |
153 | } | 153 | } |
154 | device_wakeup_enable(hcd->self.controller); | ||
154 | 155 | ||
155 | priv->hcd = hcd; | 156 | priv->hcd = hcd; |
156 | platform_set_drvdata(pdev, priv); | 157 | platform_set_drvdata(pdev, priv); |
diff --git a/drivers/usb/host/ehci-spear.c b/drivers/usb/host/ehci-spear.c index ee6f9ffaa0e7..8bd915b2ae8c 100644 --- a/drivers/usb/host/ehci-spear.c +++ b/drivers/usb/host/ehci-spear.c | |||
@@ -130,6 +130,7 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev) | |||
130 | if (retval) | 130 | if (retval) |
131 | goto err_stop_ehci; | 131 | goto err_stop_ehci; |
132 | 132 | ||
133 | device_wakeup_enable(hcd->self.controller); | ||
133 | return retval; | 134 | return retval; |
134 | 135 | ||
135 | err_stop_ehci: | 136 | err_stop_ehci: |
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c index b9fd0396011e..af28b748e87a 100644 --- a/drivers/usb/host/ehci-tegra.c +++ b/drivers/usb/host/ehci-tegra.c | |||
@@ -17,7 +17,6 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <linux/clk.h> | 19 | #include <linux/clk.h> |
20 | #include <linux/clk/tegra.h> | ||
21 | #include <linux/dma-mapping.h> | 20 | #include <linux/dma-mapping.h> |
22 | #include <linux/err.h> | 21 | #include <linux/err.h> |
23 | #include <linux/gpio.h> | 22 | #include <linux/gpio.h> |
@@ -29,6 +28,7 @@ | |||
29 | #include <linux/of_gpio.h> | 28 | #include <linux/of_gpio.h> |
30 | #include <linux/platform_device.h> | 29 | #include <linux/platform_device.h> |
31 | #include <linux/pm_runtime.h> | 30 | #include <linux/pm_runtime.h> |
31 | #include <linux/reset.h> | ||
32 | #include <linux/slab.h> | 32 | #include <linux/slab.h> |
33 | #include <linux/usb/ehci_def.h> | 33 | #include <linux/usb/ehci_def.h> |
34 | #include <linux/usb/tegra_usb_phy.h> | 34 | #include <linux/usb/tegra_usb_phy.h> |
@@ -62,6 +62,7 @@ static int (*orig_hub_control)(struct usb_hcd *hcd, | |||
62 | struct tegra_ehci_hcd { | 62 | struct tegra_ehci_hcd { |
63 | struct tegra_usb_phy *phy; | 63 | struct tegra_usb_phy *phy; |
64 | struct clk *clk; | 64 | struct clk *clk; |
65 | struct reset_control *rst; | ||
65 | int port_resuming; | 66 | int port_resuming; |
66 | bool needs_double_reset; | 67 | bool needs_double_reset; |
67 | enum tegra_usb_phy_port_speed port_speed; | 68 | enum tegra_usb_phy_port_speed port_speed; |
@@ -385,13 +386,20 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
385 | goto cleanup_hcd_create; | 386 | goto cleanup_hcd_create; |
386 | } | 387 | } |
387 | 388 | ||
389 | tegra->rst = devm_reset_control_get(&pdev->dev, "usb"); | ||
390 | if (IS_ERR(tegra->rst)) { | ||
391 | dev_err(&pdev->dev, "Can't get ehci reset\n"); | ||
392 | err = PTR_ERR(tegra->rst); | ||
393 | goto cleanup_hcd_create; | ||
394 | } | ||
395 | |||
388 | err = clk_prepare_enable(tegra->clk); | 396 | err = clk_prepare_enable(tegra->clk); |
389 | if (err) | 397 | if (err) |
390 | goto cleanup_hcd_create; | 398 | goto cleanup_hcd_create; |
391 | 399 | ||
392 | tegra_periph_reset_assert(tegra->clk); | 400 | reset_control_assert(tegra->rst); |
393 | udelay(1); | 401 | udelay(1); |
394 | tegra_periph_reset_deassert(tegra->clk); | 402 | reset_control_deassert(tegra->rst); |
395 | 403 | ||
396 | u_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0); | 404 | u_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0); |
397 | if (IS_ERR(u_phy)) { | 405 | if (IS_ERR(u_phy)) { |
@@ -455,6 +463,7 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
455 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); | 463 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); |
456 | goto cleanup_otg_set_host; | 464 | goto cleanup_otg_set_host; |
457 | } | 465 | } |
466 | device_wakeup_enable(hcd->self.controller); | ||
458 | 467 | ||
459 | return err; | 468 | return err; |
460 | 469 | ||
diff --git a/drivers/usb/host/ehci-tilegx.c b/drivers/usb/host/ehci-tilegx.c index 67026ffbf9a8..f3713d32c9a1 100644 --- a/drivers/usb/host/ehci-tilegx.c +++ b/drivers/usb/host/ehci-tilegx.c | |||
@@ -170,6 +170,7 @@ static int ehci_hcd_tilegx_drv_probe(struct platform_device *pdev) | |||
170 | ret = usb_add_hcd(hcd, pdata->irq, IRQF_SHARED); | 170 | ret = usb_add_hcd(hcd, pdata->irq, IRQF_SHARED); |
171 | if (ret == 0) { | 171 | if (ret == 0) { |
172 | platform_set_drvdata(pdev, hcd); | 172 | platform_set_drvdata(pdev, hcd); |
173 | device_wakeup_enable(hcd->self.controller); | ||
173 | return ret; | 174 | return ret; |
174 | } | 175 | } |
175 | 176 | ||
diff --git a/drivers/usb/host/ehci-w90x900.c b/drivers/usb/host/ehci-w90x900.c index cdad8438c02b..a9303aff125e 100644 --- a/drivers/usb/host/ehci-w90x900.c +++ b/drivers/usb/host/ehci-w90x900.c | |||
@@ -58,17 +58,12 @@ static int usb_w90x900_probe(const struct hc_driver *driver, | |||
58 | hcd->rsrc_start = res->start; | 58 | hcd->rsrc_start = res->start; |
59 | hcd->rsrc_len = resource_size(res); | 59 | hcd->rsrc_len = resource_size(res); |
60 | 60 | ||
61 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | 61 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
62 | retval = -EBUSY; | 62 | if (IS_ERR(hcd->regs)) { |
63 | retval = PTR_ERR(hcd->regs); | ||
63 | goto err2; | 64 | goto err2; |
64 | } | 65 | } |
65 | 66 | ||
66 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
67 | if (hcd->regs == NULL) { | ||
68 | retval = -EFAULT; | ||
69 | goto err3; | ||
70 | } | ||
71 | |||
72 | ehci = hcd_to_ehci(hcd); | 67 | ehci = hcd_to_ehci(hcd); |
73 | ehci->caps = hcd->regs; | 68 | ehci->caps = hcd->regs; |
74 | ehci->regs = hcd->regs + | 69 | ehci->regs = hcd->regs + |
@@ -88,17 +83,14 @@ static int usb_w90x900_probe(const struct hc_driver *driver, | |||
88 | 83 | ||
89 | irq = platform_get_irq(pdev, 0); | 84 | irq = platform_get_irq(pdev, 0); |
90 | if (irq < 0) | 85 | if (irq < 0) |
91 | goto err4; | 86 | goto err2; |
92 | 87 | ||
93 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | 88 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); |
94 | if (retval != 0) | 89 | if (retval != 0) |
95 | goto err4; | 90 | goto err2; |
96 | 91 | ||
92 | device_wakeup_enable(hcd->self.controller); | ||
97 | return retval; | 93 | return retval; |
98 | err4: | ||
99 | iounmap(hcd->regs); | ||
100 | err3: | ||
101 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
102 | err2: | 94 | err2: |
103 | usb_put_hcd(hcd); | 95 | usb_put_hcd(hcd); |
104 | err1: | 96 | err1: |
@@ -109,8 +101,6 @@ static void usb_w90x900_remove(struct usb_hcd *hcd, | |||
109 | struct platform_device *pdev) | 101 | struct platform_device *pdev) |
110 | { | 102 | { |
111 | usb_remove_hcd(hcd); | 103 | usb_remove_hcd(hcd); |
112 | iounmap(hcd->regs); | ||
113 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
114 | usb_put_hcd(hcd); | 104 | usb_put_hcd(hcd); |
115 | } | 105 | } |
116 | 106 | ||
diff --git a/drivers/usb/host/ehci-xilinx-of.c b/drivers/usb/host/ehci-xilinx-of.c index 95979f9f4381..fe57710753e8 100644 --- a/drivers/usb/host/ehci-xilinx-of.c +++ b/drivers/usb/host/ehci-xilinx-of.c | |||
@@ -155,7 +155,8 @@ static int ehci_hcd_xilinx_of_probe(struct platform_device *op) | |||
155 | 155 | ||
156 | irq = irq_of_parse_and_map(dn, 0); | 156 | irq = irq_of_parse_and_map(dn, 0); |
157 | if (!irq) { | 157 | if (!irq) { |
158 | printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__); | 158 | dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n", |
159 | __FILE__); | ||
159 | rv = -EBUSY; | 160 | rv = -EBUSY; |
160 | goto err_irq; | 161 | goto err_irq; |
161 | } | 162 | } |
@@ -191,8 +192,10 @@ static int ehci_hcd_xilinx_of_probe(struct platform_device *op) | |||
191 | ehci->caps = hcd->regs + 0x100; | 192 | ehci->caps = hcd->regs + 0x100; |
192 | 193 | ||
193 | rv = usb_add_hcd(hcd, irq, 0); | 194 | rv = usb_add_hcd(hcd, irq, 0); |
194 | if (rv == 0) | 195 | if (rv == 0) { |
196 | device_wakeup_enable(hcd->self.controller); | ||
195 | return 0; | 197 | return 0; |
198 | } | ||
196 | 199 | ||
197 | err_irq: | 200 | err_irq: |
198 | usb_put_hcd(hcd); | 201 | usb_put_hcd(hcd); |
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index e8f41c5e771b..9dfc6c1394d6 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h | |||
@@ -38,7 +38,7 @@ typedef __u16 __bitwise __hc16; | |||
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | /* statistics can be kept for tuning/monitoring */ | 40 | /* statistics can be kept for tuning/monitoring */ |
41 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) | 41 | #ifdef CONFIG_DYNAMIC_DEBUG |
42 | #define EHCI_STATS | 42 | #define EHCI_STATS |
43 | #endif | 43 | #endif |
44 | 44 | ||
@@ -225,6 +225,7 @@ struct ehci_hcd { /* one per controller */ | |||
225 | unsigned has_synopsys_hc_bug:1; /* Synopsys HC */ | 225 | unsigned has_synopsys_hc_bug:1; /* Synopsys HC */ |
226 | unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */ | 226 | unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */ |
227 | unsigned need_oc_pp_cycle:1; /* MPC834X port power */ | 227 | unsigned need_oc_pp_cycle:1; /* MPC834X port power */ |
228 | unsigned imx28_write_fix:1; /* For Freescale i.MX28 */ | ||
228 | 229 | ||
229 | /* required for usb32 quirk */ | 230 | /* required for usb32 quirk */ |
230 | #define OHCI_CTRL_HCFS (3 << 6) | 231 | #define OHCI_CTRL_HCFS (3 << 6) |
@@ -248,7 +249,7 @@ struct ehci_hcd { /* one per controller */ | |||
248 | #endif | 249 | #endif |
249 | 250 | ||
250 | /* debug files */ | 251 | /* debug files */ |
251 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) | 252 | #ifdef CONFIG_DYNAMIC_DEBUG |
252 | struct dentry *debug_dir; | 253 | struct dentry *debug_dir; |
253 | #endif | 254 | #endif |
254 | 255 | ||
@@ -728,6 +729,18 @@ static inline unsigned int ehci_readl(const struct ehci_hcd *ehci, | |||
728 | #endif | 729 | #endif |
729 | } | 730 | } |
730 | 731 | ||
732 | #ifdef CONFIG_SOC_IMX28 | ||
733 | static inline void imx28_ehci_writel(const unsigned int val, | ||
734 | volatile __u32 __iomem *addr) | ||
735 | { | ||
736 | __asm__ ("swp %0, %0, [%1]" : : "r"(val), "r"(addr)); | ||
737 | } | ||
738 | #else | ||
739 | static inline void imx28_ehci_writel(const unsigned int val, | ||
740 | volatile __u32 __iomem *addr) | ||
741 | { | ||
742 | } | ||
743 | #endif | ||
731 | static inline void ehci_writel(const struct ehci_hcd *ehci, | 744 | static inline void ehci_writel(const struct ehci_hcd *ehci, |
732 | const unsigned int val, __u32 __iomem *regs) | 745 | const unsigned int val, __u32 __iomem *regs) |
733 | { | 746 | { |
@@ -736,7 +749,10 @@ static inline void ehci_writel(const struct ehci_hcd *ehci, | |||
736 | writel_be(val, regs) : | 749 | writel_be(val, regs) : |
737 | writel(val, regs); | 750 | writel(val, regs); |
738 | #else | 751 | #else |
739 | writel(val, regs); | 752 | if (ehci->imx28_write_fix) |
753 | imx28_ehci_writel(val, regs); | ||
754 | else | ||
755 | writel(val, regs); | ||
740 | #endif | 756 | #endif |
741 | } | 757 | } |
742 | 758 | ||
@@ -832,9 +848,9 @@ static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x) | |||
832 | dev_warn(ehci_to_hcd(ehci)->self.controller , fmt , ## args) | 848 | dev_warn(ehci_to_hcd(ehci)->self.controller , fmt , ## args) |
833 | 849 | ||
834 | 850 | ||
835 | #if !defined(DEBUG) && !defined(CONFIG_DYNAMIC_DEBUG) | 851 | #ifndef CONFIG_DYNAMIC_DEBUG |
836 | #define STUB_DEBUG_FILES | 852 | #define STUB_DEBUG_FILES |
837 | #endif /* !DEBUG && !CONFIG_DYNAMIC_DEBUG */ | 853 | #endif |
838 | 854 | ||
839 | /*-------------------------------------------------------------------------*/ | 855 | /*-------------------------------------------------------------------------*/ |
840 | 856 | ||
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c index 0551c0af0fd1..1cf68eaf2ed8 100644 --- a/drivers/usb/host/fhci-hcd.c +++ b/drivers/usb/host/fhci-hcd.c | |||
@@ -754,6 +754,8 @@ static int of_fhci_probe(struct platform_device *ofdev) | |||
754 | if (ret < 0) | 754 | if (ret < 0) |
755 | goto err_add_hcd; | 755 | goto err_add_hcd; |
756 | 756 | ||
757 | device_wakeup_enable(hcd->self.controller); | ||
758 | |||
757 | fhci_dfs_create(fhci); | 759 | fhci_dfs_create(fhci); |
758 | 760 | ||
759 | return 0; | 761 | return 0; |
diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c index 55486bd23cf1..98a89d16cc3e 100644 --- a/drivers/usb/host/fotg210-hcd.c +++ b/drivers/usb/host/fotg210-hcd.c | |||
@@ -56,12 +56,9 @@ | |||
56 | 56 | ||
57 | static const char hcd_name[] = "fotg210_hcd"; | 57 | static const char hcd_name[] = "fotg210_hcd"; |
58 | 58 | ||
59 | #undef VERBOSE_DEBUG | ||
60 | #undef FOTG210_URB_TRACE | 59 | #undef FOTG210_URB_TRACE |
61 | 60 | ||
62 | #ifdef DEBUG | ||
63 | #define FOTG210_STATS | 61 | #define FOTG210_STATS |
64 | #endif | ||
65 | 62 | ||
66 | /* magic numbers that can affect system performance */ | 63 | /* magic numbers that can affect system performance */ |
67 | #define FOTG210_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */ | 64 | #define FOTG210_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */ |
@@ -107,14 +104,6 @@ MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us"); | |||
107 | #define fotg210_warn(fotg210, fmt, args...) \ | 104 | #define fotg210_warn(fotg210, fmt, args...) \ |
108 | dev_warn(fotg210_to_hcd(fotg210)->self.controller , fmt , ## args) | 105 | dev_warn(fotg210_to_hcd(fotg210)->self.controller , fmt , ## args) |
109 | 106 | ||
110 | #ifdef VERBOSE_DEBUG | ||
111 | # define fotg210_vdbg fotg210_dbg | ||
112 | #else | ||
113 | static inline void fotg210_vdbg(struct fotg210_hcd *fotg210, ...) {} | ||
114 | #endif | ||
115 | |||
116 | #ifdef DEBUG | ||
117 | |||
118 | /* check the values in the HCSPARAMS register | 107 | /* check the values in the HCSPARAMS register |
119 | * (host controller _Structural_ parameters) | 108 | * (host controller _Structural_ parameters) |
120 | * see EHCI spec, Table 2-4 for each value | 109 | * see EHCI spec, Table 2-4 for each value |
@@ -129,13 +118,6 @@ static void dbg_hcs_params(struct fotg210_hcd *fotg210, char *label) | |||
129 | HCS_N_PORTS(params) | 118 | HCS_N_PORTS(params) |
130 | ); | 119 | ); |
131 | } | 120 | } |
132 | #else | ||
133 | |||
134 | static inline void dbg_hcs_params(struct fotg210_hcd *fotg210, char *label) {} | ||
135 | |||
136 | #endif | ||
137 | |||
138 | #ifdef DEBUG | ||
139 | 121 | ||
140 | /* check the values in the HCCPARAMS register | 122 | /* check the values in the HCCPARAMS register |
141 | * (host controller _Capability_ parameters) | 123 | * (host controller _Capability_ parameters) |
@@ -152,13 +134,6 @@ static void dbg_hcc_params(struct fotg210_hcd *fotg210, char *label) | |||
152 | HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", | 134 | HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", |
153 | HCC_CANPARK(params) ? " park" : ""); | 135 | HCC_CANPARK(params) ? " park" : ""); |
154 | } | 136 | } |
155 | #else | ||
156 | |||
157 | static inline void dbg_hcc_params(struct fotg210_hcd *fotg210, char *label) {} | ||
158 | |||
159 | #endif | ||
160 | |||
161 | #ifdef DEBUG | ||
162 | 137 | ||
163 | static void __maybe_unused | 138 | static void __maybe_unused |
164 | dbg_qtd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd) | 139 | dbg_qtd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd) |
@@ -272,8 +247,8 @@ dbg_command_buf(char *buf, unsigned len, const char *label, u32 command) | |||
272 | ); | 247 | ); |
273 | } | 248 | } |
274 | 249 | ||
275 | static int | 250 | static char |
276 | dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status) | 251 | *dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status) |
277 | { | 252 | { |
278 | char *sig; | 253 | char *sig; |
279 | 254 | ||
@@ -293,7 +268,7 @@ dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status) | |||
293 | break; | 268 | break; |
294 | } | 269 | } |
295 | 270 | ||
296 | return scnprintf(buf, len, | 271 | scnprintf(buf, len, |
297 | "%s%sport:%d status %06x %d " | 272 | "%s%sport:%d status %06x %d " |
298 | "sig=%s%s%s%s%s%s%s%s", | 273 | "sig=%s%s%s%s%s%s%s%s", |
299 | label, label[0] ? " " : "", port, status, | 274 | label, label[0] ? " " : "", port, status, |
@@ -306,31 +281,9 @@ dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status) | |||
306 | (status & PORT_PE) ? " PE" : "", | 281 | (status & PORT_PE) ? " PE" : "", |
307 | (status & PORT_CSC) ? " CSC" : "", | 282 | (status & PORT_CSC) ? " CSC" : "", |
308 | (status & PORT_CONNECT) ? " CONNECT" : ""); | 283 | (status & PORT_CONNECT) ? " CONNECT" : ""); |
284 | return buf; | ||
309 | } | 285 | } |
310 | 286 | ||
311 | #else | ||
312 | static inline void __maybe_unused | ||
313 | dbg_qh(char *label, struct fotg210_hcd *fotg210, struct fotg210_qh *qh) | ||
314 | {} | ||
315 | |||
316 | static inline int __maybe_unused | ||
317 | dbg_status_buf(char *buf, unsigned len, const char *label, u32 status) | ||
318 | { return 0; } | ||
319 | |||
320 | static inline int __maybe_unused | ||
321 | dbg_command_buf(char *buf, unsigned len, const char *label, u32 command) | ||
322 | { return 0; } | ||
323 | |||
324 | static inline int __maybe_unused | ||
325 | dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable) | ||
326 | { return 0; } | ||
327 | |||
328 | static inline int __maybe_unused | ||
329 | dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status) | ||
330 | { return 0; } | ||
331 | |||
332 | #endif /* DEBUG */ | ||
333 | |||
334 | /* functions have the "wrong" filename when they're output... */ | 287 | /* functions have the "wrong" filename when they're output... */ |
335 | #define dbg_status(fotg210, label, status) { \ | 288 | #define dbg_status(fotg210, label, status) { \ |
336 | char _buf[80]; \ | 289 | char _buf[80]; \ |
@@ -346,19 +299,11 @@ dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status) | |||
346 | 299 | ||
347 | #define dbg_port(fotg210, label, port, status) { \ | 300 | #define dbg_port(fotg210, label, port, status) { \ |
348 | char _buf[80]; \ | 301 | char _buf[80]; \ |
349 | dbg_port_buf(_buf, sizeof(_buf), label, port, status); \ | 302 | fotg210_dbg(fotg210, "%s\n", dbg_port_buf(_buf, sizeof(_buf), label, port, status) ); \ |
350 | fotg210_dbg(fotg210, "%s\n", _buf); \ | ||
351 | } | 303 | } |
352 | 304 | ||
353 | /*-------------------------------------------------------------------------*/ | 305 | /*-------------------------------------------------------------------------*/ |
354 | 306 | ||
355 | #ifdef STUB_DEBUG_FILES | ||
356 | |||
357 | static inline void create_debug_files(struct fotg210_hcd *bus) { } | ||
358 | static inline void remove_debug_files(struct fotg210_hcd *bus) { } | ||
359 | |||
360 | #else | ||
361 | |||
362 | /* troubleshooting help: expose state in debugfs */ | 307 | /* troubleshooting help: expose state in debugfs */ |
363 | 308 | ||
364 | static int debug_async_open(struct inode *, struct file *); | 309 | static int debug_async_open(struct inode *, struct file *); |
@@ -954,7 +899,6 @@ static inline void remove_debug_files(struct fotg210_hcd *fotg210) | |||
954 | debugfs_remove_recursive(fotg210->debug_dir); | 899 | debugfs_remove_recursive(fotg210->debug_dir); |
955 | } | 900 | } |
956 | 901 | ||
957 | #endif /* STUB_DEBUG_FILES */ | ||
958 | /*-------------------------------------------------------------------------*/ | 902 | /*-------------------------------------------------------------------------*/ |
959 | 903 | ||
960 | /* | 904 | /* |
@@ -1398,7 +1342,7 @@ static void fotg210_iaa_watchdog(struct fotg210_hcd *fotg210) | |||
1398 | &fotg210->regs->status); | 1342 | &fotg210->regs->status); |
1399 | } | 1343 | } |
1400 | 1344 | ||
1401 | fotg210_vdbg(fotg210, "IAA watchdog: status %x cmd %x\n", | 1345 | fotg210_dbg(fotg210, "IAA watchdog: status %x cmd %x\n", |
1402 | status, cmd); | 1346 | status, cmd); |
1403 | end_unlink_async(fotg210); | 1347 | end_unlink_async(fotg210); |
1404 | } | 1348 | } |
@@ -1810,10 +1754,8 @@ static int fotg210_hub_control( | |||
1810 | if (test_bit(wIndex, &fotg210->port_c_suspend)) | 1754 | if (test_bit(wIndex, &fotg210->port_c_suspend)) |
1811 | status |= USB_PORT_STAT_C_SUSPEND << 16; | 1755 | status |= USB_PORT_STAT_C_SUSPEND << 16; |
1812 | 1756 | ||
1813 | #ifndef VERBOSE_DEBUG | 1757 | if (status & ~0xffff) /* only if wPortChange is interesting */ |
1814 | if (status & ~0xffff) /* only if wPortChange is interesting */ | 1758 | dbg_port(fotg210, "GetStatus", wIndex + 1, temp); |
1815 | #endif | ||
1816 | dbg_port(fotg210, "GetStatus", wIndex + 1, temp); | ||
1817 | put_unaligned_le32(status, buf); | 1759 | put_unaligned_le32(status, buf); |
1818 | break; | 1760 | break; |
1819 | case SetHubFeature: | 1761 | case SetHubFeature: |
@@ -1856,7 +1798,7 @@ static int fotg210_hub_control( | |||
1856 | * which can be fine if this root hub has a | 1798 | * which can be fine if this root hub has a |
1857 | * transaction translator built in. | 1799 | * transaction translator built in. |
1858 | */ | 1800 | */ |
1859 | fotg210_vdbg(fotg210, "port %d reset\n", wIndex + 1); | 1801 | fotg210_dbg(fotg210, "port %d reset\n", wIndex + 1); |
1860 | temp |= PORT_RESET; | 1802 | temp |= PORT_RESET; |
1861 | temp &= ~PORT_PE; | 1803 | temp &= ~PORT_PE; |
1862 | 1804 | ||
@@ -2274,13 +2216,12 @@ static void fotg210_clear_tt_buffer(struct fotg210_hcd *fotg210, | |||
2274 | * Note: this routine is never called for Isochronous transfers. | 2216 | * Note: this routine is never called for Isochronous transfers. |
2275 | */ | 2217 | */ |
2276 | if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->clearing_tt) { | 2218 | if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->clearing_tt) { |
2277 | #ifdef DEBUG | ||
2278 | struct usb_device *tt = urb->dev->tt->hub; | 2219 | struct usb_device *tt = urb->dev->tt->hub; |
2279 | dev_dbg(&tt->dev, | 2220 | dev_dbg(&tt->dev, |
2280 | "clear tt buffer port %d, a%d ep%d t%08x\n", | 2221 | "clear tt buffer port %d, a%d ep%d t%08x\n", |
2281 | urb->dev->ttport, urb->dev->devnum, | 2222 | urb->dev->ttport, urb->dev->devnum, |
2282 | usb_pipeendpoint(urb->pipe), token); | 2223 | usb_pipeendpoint(urb->pipe), token); |
2283 | #endif /* DEBUG */ | 2224 | |
2284 | if (urb->dev->tt->hub != | 2225 | if (urb->dev->tt->hub != |
2285 | fotg210_to_hcd(fotg210)->self.root_hub) { | 2226 | fotg210_to_hcd(fotg210)->self.root_hub) { |
2286 | if (usb_hub_clear_tt_buffer(urb) == 0) | 2227 | if (usb_hub_clear_tt_buffer(urb) == 0) |
@@ -2341,7 +2282,7 @@ static int qtd_copy_status( | |||
2341 | status = -EPROTO; | 2282 | status = -EPROTO; |
2342 | } | 2283 | } |
2343 | 2284 | ||
2344 | fotg210_vdbg(fotg210, | 2285 | fotg210_dbg(fotg210, |
2345 | "dev%d ep%d%s qtd token %08x --> status %d\n", | 2286 | "dev%d ep%d%s qtd token %08x --> status %d\n", |
2346 | usb_pipedevice(urb->pipe), | 2287 | usb_pipedevice(urb->pipe), |
2347 | usb_pipeendpoint(urb->pipe), | 2288 | usb_pipeendpoint(urb->pipe), |
@@ -3583,11 +3524,9 @@ periodic_usecs(struct fotg210_hcd *fotg210, unsigned frame, unsigned uframe) | |||
3583 | break; | 3524 | break; |
3584 | } | 3525 | } |
3585 | } | 3526 | } |
3586 | #ifdef DEBUG | ||
3587 | if (usecs > fotg210->uframe_periodic_max) | 3527 | if (usecs > fotg210->uframe_periodic_max) |
3588 | fotg210_err(fotg210, "uframe %d sched overrun: %d usecs\n", | 3528 | fotg210_err(fotg210, "uframe %d sched overrun: %d usecs\n", |
3589 | frame * 8 + uframe, usecs); | 3529 | frame * 8 + uframe, usecs); |
3590 | #endif | ||
3591 | return usecs; | 3530 | return usecs; |
3592 | } | 3531 | } |
3593 | 3532 | ||
@@ -4646,7 +4585,7 @@ static void itd_link_urb( | |||
4646 | if (unlikely(list_empty(&stream->td_list))) { | 4585 | if (unlikely(list_empty(&stream->td_list))) { |
4647 | fotg210_to_hcd(fotg210)->self.bandwidth_allocated | 4586 | fotg210_to_hcd(fotg210)->self.bandwidth_allocated |
4648 | += stream->bandwidth; | 4587 | += stream->bandwidth; |
4649 | fotg210_vdbg(fotg210, | 4588 | fotg210_dbg(fotg210, |
4650 | "schedule devp %s ep%d%s-iso period %d start %d.%d\n", | 4589 | "schedule devp %s ep%d%s-iso period %d start %d.%d\n", |
4651 | urb->dev->devpath, stream->bEndpointAddress & 0x0f, | 4590 | urb->dev->devpath, stream->bEndpointAddress & 0x0f, |
4652 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", | 4591 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", |
@@ -4779,7 +4718,7 @@ static bool itd_complete(struct fotg210_hcd *fotg210, struct fotg210_itd *itd) | |||
4779 | if (unlikely(list_is_singular(&stream->td_list))) { | 4718 | if (unlikely(list_is_singular(&stream->td_list))) { |
4780 | fotg210_to_hcd(fotg210)->self.bandwidth_allocated | 4719 | fotg210_to_hcd(fotg210)->self.bandwidth_allocated |
4781 | -= stream->bandwidth; | 4720 | -= stream->bandwidth; |
4782 | fotg210_vdbg(fotg210, | 4721 | fotg210_dbg(fotg210, |
4783 | "deschedule devp %s ep%d%s-iso\n", | 4722 | "deschedule devp %s ep%d%s-iso\n", |
4784 | dev->devpath, stream->bEndpointAddress & 0x0f, | 4723 | dev->devpath, stream->bEndpointAddress & 0x0f, |
4785 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); | 4724 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); |
@@ -5444,10 +5383,8 @@ static irqreturn_t fotg210_irq(struct usb_hcd *hcd) | |||
5444 | cmd = fotg210_readl(fotg210, &fotg210->regs->command); | 5383 | cmd = fotg210_readl(fotg210, &fotg210->regs->command); |
5445 | bh = 0; | 5384 | bh = 0; |
5446 | 5385 | ||
5447 | #ifdef VERBOSE_DEBUG | ||
5448 | /* unrequested/ignored: Frame List Rollover */ | 5386 | /* unrequested/ignored: Frame List Rollover */ |
5449 | dbg_status(fotg210, "irq", status); | 5387 | dbg_status(fotg210, "irq", status); |
5450 | #endif | ||
5451 | 5388 | ||
5452 | /* INT, ERR, and IAA interrupt rates can be throttled */ | 5389 | /* INT, ERR, and IAA interrupt rates can be throttled */ |
5453 | 5390 | ||
@@ -5952,6 +5889,7 @@ static int fotg210_hcd_probe(struct platform_device *pdev) | |||
5952 | dev_err(dev, "failed to add hcd with err %d\n", retval); | 5889 | dev_err(dev, "failed to add hcd with err %d\n", retval); |
5953 | goto fail_add_hcd; | 5890 | goto fail_add_hcd; |
5954 | } | 5891 | } |
5892 | device_wakeup_enable(hcd->self.controller); | ||
5955 | 5893 | ||
5956 | return retval; | 5894 | return retval; |
5957 | 5895 | ||
@@ -6013,13 +5951,11 @@ static int __init fotg210_hcd_init(void) | |||
6013 | sizeof(struct fotg210_qh), sizeof(struct fotg210_qtd), | 5951 | sizeof(struct fotg210_qh), sizeof(struct fotg210_qtd), |
6014 | sizeof(struct fotg210_itd)); | 5952 | sizeof(struct fotg210_itd)); |
6015 | 5953 | ||
6016 | #ifdef DEBUG | ||
6017 | fotg210_debug_root = debugfs_create_dir("fotg210", usb_debug_root); | 5954 | fotg210_debug_root = debugfs_create_dir("fotg210", usb_debug_root); |
6018 | if (!fotg210_debug_root) { | 5955 | if (!fotg210_debug_root) { |
6019 | retval = -ENOENT; | 5956 | retval = -ENOENT; |
6020 | goto err_debug; | 5957 | goto err_debug; |
6021 | } | 5958 | } |
6022 | #endif | ||
6023 | 5959 | ||
6024 | retval = platform_driver_register(&fotg210_hcd_driver); | 5960 | retval = platform_driver_register(&fotg210_hcd_driver); |
6025 | if (retval < 0) | 5961 | if (retval < 0) |
@@ -6028,11 +5964,9 @@ static int __init fotg210_hcd_init(void) | |||
6028 | 5964 | ||
6029 | platform_driver_unregister(&fotg210_hcd_driver); | 5965 | platform_driver_unregister(&fotg210_hcd_driver); |
6030 | clean: | 5966 | clean: |
6031 | #ifdef DEBUG | ||
6032 | debugfs_remove(fotg210_debug_root); | 5967 | debugfs_remove(fotg210_debug_root); |
6033 | fotg210_debug_root = NULL; | 5968 | fotg210_debug_root = NULL; |
6034 | err_debug: | 5969 | err_debug: |
6035 | #endif | ||
6036 | clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); | 5970 | clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); |
6037 | return retval; | 5971 | return retval; |
6038 | } | 5972 | } |
@@ -6041,9 +5975,7 @@ module_init(fotg210_hcd_init); | |||
6041 | static void __exit fotg210_hcd_cleanup(void) | 5975 | static void __exit fotg210_hcd_cleanup(void) |
6042 | { | 5976 | { |
6043 | platform_driver_unregister(&fotg210_hcd_driver); | 5977 | platform_driver_unregister(&fotg210_hcd_driver); |
6044 | #ifdef DEBUG | ||
6045 | debugfs_remove(fotg210_debug_root); | 5978 | debugfs_remove(fotg210_debug_root); |
6046 | #endif | ||
6047 | clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); | 5979 | clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); |
6048 | } | 5980 | } |
6049 | module_exit(fotg210_hcd_cleanup); | 5981 | module_exit(fotg210_hcd_cleanup); |
diff --git a/drivers/usb/host/fotg210.h b/drivers/usb/host/fotg210.h index 8920f9d32564..ac6cd1bfd208 100644 --- a/drivers/usb/host/fotg210.h +++ b/drivers/usb/host/fotg210.h | |||
@@ -174,9 +174,7 @@ struct fotg210_hcd { /* one per controller */ | |||
174 | #endif | 174 | #endif |
175 | 175 | ||
176 | /* debug files */ | 176 | /* debug files */ |
177 | #ifdef DEBUG | ||
178 | struct dentry *debug_dir; | 177 | struct dentry *debug_dir; |
179 | #endif | ||
180 | }; | 178 | }; |
181 | 179 | ||
182 | /* convert between an HCD pointer and the corresponding FOTG210_HCD */ | 180 | /* convert between an HCD pointer and the corresponding FOTG210_HCD */ |
@@ -741,10 +739,4 @@ static inline unsigned fotg210_read_frame_index(struct fotg210_hcd *fotg210) | |||
741 | }) | 739 | }) |
742 | /*-------------------------------------------------------------------------*/ | 740 | /*-------------------------------------------------------------------------*/ |
743 | 741 | ||
744 | #ifndef DEBUG | ||
745 | #define STUB_DEBUG_FILES | ||
746 | #endif /* DEBUG */ | ||
747 | |||
748 | /*-------------------------------------------------------------------------*/ | ||
749 | |||
750 | #endif /* __LINUX_FOTG210_H */ | 742 | #endif /* __LINUX_FOTG210_H */ |
diff --git a/drivers/usb/host/fusbh200-hcd.c b/drivers/usb/host/fusbh200-hcd.c index e1c6d850a7e1..ba9499060f63 100644 --- a/drivers/usb/host/fusbh200-hcd.c +++ b/drivers/usb/host/fusbh200-hcd.c | |||
@@ -57,13 +57,8 @@ | |||
57 | 57 | ||
58 | static const char hcd_name [] = "fusbh200_hcd"; | 58 | static const char hcd_name [] = "fusbh200_hcd"; |
59 | 59 | ||
60 | #undef VERBOSE_DEBUG | ||
61 | #undef FUSBH200_URB_TRACE | 60 | #undef FUSBH200_URB_TRACE |
62 | 61 | ||
63 | #ifdef DEBUG | ||
64 | #define FUSBH200_STATS | ||
65 | #endif | ||
66 | |||
67 | /* magic numbers that can affect system performance */ | 62 | /* magic numbers that can affect system performance */ |
68 | #define FUSBH200_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */ | 63 | #define FUSBH200_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */ |
69 | #define FUSBH200_TUNE_RL_HS 4 /* nak throttle; see 4.9 */ | 64 | #define FUSBH200_TUNE_RL_HS 4 /* nak throttle; see 4.9 */ |
@@ -108,14 +103,6 @@ MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us"); | |||
108 | #define fusbh200_warn(fusbh200, fmt, args...) \ | 103 | #define fusbh200_warn(fusbh200, fmt, args...) \ |
109 | dev_warn (fusbh200_to_hcd(fusbh200)->self.controller , fmt , ## args ) | 104 | dev_warn (fusbh200_to_hcd(fusbh200)->self.controller , fmt , ## args ) |
110 | 105 | ||
111 | #ifdef VERBOSE_DEBUG | ||
112 | # define fusbh200_vdbg fusbh200_dbg | ||
113 | #else | ||
114 | static inline void fusbh200_vdbg(struct fusbh200_hcd *fusbh200, ...) {} | ||
115 | #endif | ||
116 | |||
117 | #ifdef DEBUG | ||
118 | |||
119 | /* check the values in the HCSPARAMS register | 106 | /* check the values in the HCSPARAMS register |
120 | * (host controller _Structural_ parameters) | 107 | * (host controller _Structural_ parameters) |
121 | * see EHCI spec, Table 2-4 for each value | 108 | * see EHCI spec, Table 2-4 for each value |
@@ -130,13 +117,6 @@ static void dbg_hcs_params (struct fusbh200_hcd *fusbh200, char *label) | |||
130 | HCS_N_PORTS (params) | 117 | HCS_N_PORTS (params) |
131 | ); | 118 | ); |
132 | } | 119 | } |
133 | #else | ||
134 | |||
135 | static inline void dbg_hcs_params (struct fusbh200_hcd *fusbh200, char *label) {} | ||
136 | |||
137 | #endif | ||
138 | |||
139 | #ifdef DEBUG | ||
140 | 120 | ||
141 | /* check the values in the HCCPARAMS register | 121 | /* check the values in the HCCPARAMS register |
142 | * (host controller _Capability_ parameters) | 122 | * (host controller _Capability_ parameters) |
@@ -153,13 +133,6 @@ static void dbg_hcc_params (struct fusbh200_hcd *fusbh200, char *label) | |||
153 | HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", | 133 | HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", |
154 | HCC_CANPARK(params) ? " park" : ""); | 134 | HCC_CANPARK(params) ? " park" : ""); |
155 | } | 135 | } |
156 | #else | ||
157 | |||
158 | static inline void dbg_hcc_params (struct fusbh200_hcd *fusbh200, char *label) {} | ||
159 | |||
160 | #endif | ||
161 | |||
162 | #ifdef DEBUG | ||
163 | 136 | ||
164 | static void __maybe_unused | 137 | static void __maybe_unused |
165 | dbg_qtd (const char *label, struct fusbh200_hcd *fusbh200, struct fusbh200_qtd *qtd) | 138 | dbg_qtd (const char *label, struct fusbh200_hcd *fusbh200, struct fusbh200_qtd *qtd) |
@@ -302,29 +275,6 @@ dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status) | |||
302 | (status & PORT_CONNECT) ? " CONNECT" : ""); | 275 | (status & PORT_CONNECT) ? " CONNECT" : ""); |
303 | } | 276 | } |
304 | 277 | ||
305 | #else | ||
306 | static inline void __maybe_unused | ||
307 | dbg_qh (char *label, struct fusbh200_hcd *fusbh200, struct fusbh200_qh *qh) | ||
308 | {} | ||
309 | |||
310 | static inline int __maybe_unused | ||
311 | dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) | ||
312 | { return 0; } | ||
313 | |||
314 | static inline int __maybe_unused | ||
315 | dbg_command_buf (char *buf, unsigned len, const char *label, u32 command) | ||
316 | { return 0; } | ||
317 | |||
318 | static inline int __maybe_unused | ||
319 | dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable) | ||
320 | { return 0; } | ||
321 | |||
322 | static inline int __maybe_unused | ||
323 | dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status) | ||
324 | { return 0; } | ||
325 | |||
326 | #endif /* DEBUG */ | ||
327 | |||
328 | /* functions have the "wrong" filename when they're output... */ | 278 | /* functions have the "wrong" filename when they're output... */ |
329 | #define dbg_status(fusbh200, label, status) { \ | 279 | #define dbg_status(fusbh200, label, status) { \ |
330 | char _buf [80]; \ | 280 | char _buf [80]; \ |
@@ -346,13 +296,6 @@ dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status) | |||
346 | 296 | ||
347 | /*-------------------------------------------------------------------------*/ | 297 | /*-------------------------------------------------------------------------*/ |
348 | 298 | ||
349 | #ifdef STUB_DEBUG_FILES | ||
350 | |||
351 | static inline void create_debug_files (struct fusbh200_hcd *bus) { } | ||
352 | static inline void remove_debug_files (struct fusbh200_hcd *bus) { } | ||
353 | |||
354 | #else | ||
355 | |||
356 | /* troubleshooting help: expose state in debugfs */ | 299 | /* troubleshooting help: expose state in debugfs */ |
357 | 300 | ||
358 | static int debug_async_open(struct inode *, struct file *); | 301 | static int debug_async_open(struct inode *, struct file *); |
@@ -775,7 +718,6 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf) | |||
775 | next += temp; | 718 | next += temp; |
776 | } | 719 | } |
777 | 720 | ||
778 | #ifdef FUSBH200_STATS | ||
779 | temp = scnprintf (next, size, | 721 | temp = scnprintf (next, size, |
780 | "irq normal %ld err %ld iaa %ld (lost %ld)\n", | 722 | "irq normal %ld err %ld iaa %ld (lost %ld)\n", |
781 | fusbh200->stats.normal, fusbh200->stats.error, fusbh200->stats.iaa, | 723 | fusbh200->stats.normal, fusbh200->stats.error, fusbh200->stats.iaa, |
@@ -787,7 +729,6 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf) | |||
787 | fusbh200->stats.complete, fusbh200->stats.unlink); | 729 | fusbh200->stats.complete, fusbh200->stats.unlink); |
788 | size -= temp; | 730 | size -= temp; |
789 | next += temp; | 731 | next += temp; |
790 | #endif | ||
791 | 732 | ||
792 | done: | 733 | done: |
793 | spin_unlock_irqrestore (&fusbh200->lock, flags); | 734 | spin_unlock_irqrestore (&fusbh200->lock, flags); |
@@ -928,7 +869,6 @@ static inline void remove_debug_files (struct fusbh200_hcd *fusbh200) | |||
928 | debugfs_remove_recursive(fusbh200->debug_dir); | 869 | debugfs_remove_recursive(fusbh200->debug_dir); |
929 | } | 870 | } |
930 | 871 | ||
931 | #endif /* STUB_DEBUG_FILES */ | ||
932 | /*-------------------------------------------------------------------------*/ | 872 | /*-------------------------------------------------------------------------*/ |
933 | 873 | ||
934 | /* | 874 | /* |
@@ -1362,7 +1302,7 @@ static void fusbh200_iaa_watchdog(struct fusbh200_hcd *fusbh200) | |||
1362 | fusbh200_writel(fusbh200, STS_IAA, &fusbh200->regs->status); | 1302 | fusbh200_writel(fusbh200, STS_IAA, &fusbh200->regs->status); |
1363 | } | 1303 | } |
1364 | 1304 | ||
1365 | fusbh200_vdbg(fusbh200, "IAA watchdog: status %x cmd %x\n", | 1305 | fusbh200_dbg(fusbh200, "IAA watchdog: status %x cmd %x\n", |
1366 | status, cmd); | 1306 | status, cmd); |
1367 | end_unlink_async(fusbh200); | 1307 | end_unlink_async(fusbh200); |
1368 | } | 1308 | } |
@@ -1769,10 +1709,8 @@ static int fusbh200_hub_control ( | |||
1769 | if (test_bit(wIndex, &fusbh200->port_c_suspend)) | 1709 | if (test_bit(wIndex, &fusbh200->port_c_suspend)) |
1770 | status |= USB_PORT_STAT_C_SUSPEND << 16; | 1710 | status |= USB_PORT_STAT_C_SUSPEND << 16; |
1771 | 1711 | ||
1772 | #ifndef VERBOSE_DEBUG | 1712 | if (status & ~0xffff) /* only if wPortChange is interesting */ |
1773 | if (status & ~0xffff) /* only if wPortChange is interesting */ | 1713 | dbg_port(fusbh200, "GetStatus", wIndex + 1, temp); |
1774 | #endif | ||
1775 | dbg_port (fusbh200, "GetStatus", wIndex + 1, temp); | ||
1776 | put_unaligned_le32(status, buf); | 1714 | put_unaligned_le32(status, buf); |
1777 | break; | 1715 | break; |
1778 | case SetHubFeature: | 1716 | case SetHubFeature: |
@@ -1814,7 +1752,7 @@ static int fusbh200_hub_control ( | |||
1814 | * which can be fine if this root hub has a | 1752 | * which can be fine if this root hub has a |
1815 | * transaction translator built in. | 1753 | * transaction translator built in. |
1816 | */ | 1754 | */ |
1817 | fusbh200_vdbg (fusbh200, "port %d reset\n", wIndex + 1); | 1755 | fusbh200_dbg(fusbh200, "port %d reset\n", wIndex + 1); |
1818 | temp |= PORT_RESET; | 1756 | temp |= PORT_RESET; |
1819 | temp &= ~PORT_PE; | 1757 | temp &= ~PORT_PE; |
1820 | 1758 | ||
@@ -2230,13 +2168,13 @@ static void fusbh200_clear_tt_buffer(struct fusbh200_hcd *fusbh200, struct fusbh | |||
2230 | * Note: this routine is never called for Isochronous transfers. | 2168 | * Note: this routine is never called for Isochronous transfers. |
2231 | */ | 2169 | */ |
2232 | if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->clearing_tt) { | 2170 | if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->clearing_tt) { |
2233 | #ifdef DEBUG | ||
2234 | struct usb_device *tt = urb->dev->tt->hub; | 2171 | struct usb_device *tt = urb->dev->tt->hub; |
2172 | |||
2235 | dev_dbg(&tt->dev, | 2173 | dev_dbg(&tt->dev, |
2236 | "clear tt buffer port %d, a%d ep%d t%08x\n", | 2174 | "clear tt buffer port %d, a%d ep%d t%08x\n", |
2237 | urb->dev->ttport, urb->dev->devnum, | 2175 | urb->dev->ttport, urb->dev->devnum, |
2238 | usb_pipeendpoint(urb->pipe), token); | 2176 | usb_pipeendpoint(urb->pipe), token); |
2239 | #endif /* DEBUG */ | 2177 | |
2240 | if (urb->dev->tt->hub != | 2178 | if (urb->dev->tt->hub != |
2241 | fusbh200_to_hcd(fusbh200)->self.root_hub) { | 2179 | fusbh200_to_hcd(fusbh200)->self.root_hub) { |
2242 | if (usb_hub_clear_tt_buffer(urb) == 0) | 2180 | if (usb_hub_clear_tt_buffer(urb) == 0) |
@@ -2297,7 +2235,7 @@ static int qtd_copy_status ( | |||
2297 | status = -EPROTO; | 2235 | status = -EPROTO; |
2298 | } | 2236 | } |
2299 | 2237 | ||
2300 | fusbh200_vdbg (fusbh200, | 2238 | fusbh200_dbg(fusbh200, |
2301 | "dev%d ep%d%s qtd token %08x --> status %d\n", | 2239 | "dev%d ep%d%s qtd token %08x --> status %d\n", |
2302 | usb_pipedevice (urb->pipe), | 2240 | usb_pipedevice (urb->pipe), |
2303 | usb_pipeendpoint (urb->pipe), | 2241 | usb_pipeendpoint (urb->pipe), |
@@ -3529,11 +3467,9 @@ periodic_usecs (struct fusbh200_hcd *fusbh200, unsigned frame, unsigned uframe) | |||
3529 | break; | 3467 | break; |
3530 | } | 3468 | } |
3531 | } | 3469 | } |
3532 | #ifdef DEBUG | ||
3533 | if (usecs > fusbh200->uframe_periodic_max) | 3470 | if (usecs > fusbh200->uframe_periodic_max) |
3534 | fusbh200_err (fusbh200, "uframe %d sched overrun: %d usecs\n", | 3471 | fusbh200_err (fusbh200, "uframe %d sched overrun: %d usecs\n", |
3535 | frame * 8 + uframe, usecs); | 3472 | frame * 8 + uframe, usecs); |
3536 | #endif | ||
3537 | return usecs; | 3473 | return usecs; |
3538 | } | 3474 | } |
3539 | 3475 | ||
@@ -4586,7 +4522,7 @@ static void itd_link_urb( | |||
4586 | if (unlikely (list_empty(&stream->td_list))) { | 4522 | if (unlikely (list_empty(&stream->td_list))) { |
4587 | fusbh200_to_hcd(fusbh200)->self.bandwidth_allocated | 4523 | fusbh200_to_hcd(fusbh200)->self.bandwidth_allocated |
4588 | += stream->bandwidth; | 4524 | += stream->bandwidth; |
4589 | fusbh200_vdbg (fusbh200, | 4525 | fusbh200_dbg(fusbh200, |
4590 | "schedule devp %s ep%d%s-iso period %d start %d.%d\n", | 4526 | "schedule devp %s ep%d%s-iso period %d start %d.%d\n", |
4591 | urb->dev->devpath, stream->bEndpointAddress & 0x0f, | 4527 | urb->dev->devpath, stream->bEndpointAddress & 0x0f, |
4592 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", | 4528 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", |
@@ -4717,7 +4653,7 @@ static bool itd_complete(struct fusbh200_hcd *fusbh200, struct fusbh200_itd *itd | |||
4717 | if (unlikely(list_is_singular(&stream->td_list))) { | 4653 | if (unlikely(list_is_singular(&stream->td_list))) { |
4718 | fusbh200_to_hcd(fusbh200)->self.bandwidth_allocated | 4654 | fusbh200_to_hcd(fusbh200)->self.bandwidth_allocated |
4719 | -= stream->bandwidth; | 4655 | -= stream->bandwidth; |
4720 | fusbh200_vdbg (fusbh200, | 4656 | fusbh200_dbg(fusbh200, |
4721 | "deschedule devp %s ep%d%s-iso\n", | 4657 | "deschedule devp %s ep%d%s-iso\n", |
4722 | dev->devpath, stream->bEndpointAddress & 0x0f, | 4658 | dev->devpath, stream->bEndpointAddress & 0x0f, |
4723 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); | 4659 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); |
@@ -5115,13 +5051,11 @@ static void fusbh200_stop (struct usb_hcd *hcd) | |||
5115 | spin_unlock_irq (&fusbh200->lock); | 5051 | spin_unlock_irq (&fusbh200->lock); |
5116 | fusbh200_mem_cleanup (fusbh200); | 5052 | fusbh200_mem_cleanup (fusbh200); |
5117 | 5053 | ||
5118 | #ifdef FUSBH200_STATS | ||
5119 | fusbh200_dbg(fusbh200, "irq normal %ld err %ld iaa %ld (lost %ld)\n", | 5054 | fusbh200_dbg(fusbh200, "irq normal %ld err %ld iaa %ld (lost %ld)\n", |
5120 | fusbh200->stats.normal, fusbh200->stats.error, fusbh200->stats.iaa, | 5055 | fusbh200->stats.normal, fusbh200->stats.error, fusbh200->stats.iaa, |
5121 | fusbh200->stats.lost_iaa); | 5056 | fusbh200->stats.lost_iaa); |
5122 | fusbh200_dbg (fusbh200, "complete %ld unlink %ld\n", | 5057 | fusbh200_dbg (fusbh200, "complete %ld unlink %ld\n", |
5123 | fusbh200->stats.complete, fusbh200->stats.unlink); | 5058 | fusbh200->stats.complete, fusbh200->stats.unlink); |
5124 | #endif | ||
5125 | 5059 | ||
5126 | dbg_status (fusbh200, "fusbh200_stop completed", | 5060 | dbg_status (fusbh200, "fusbh200_stop completed", |
5127 | fusbh200_readl(fusbh200, &fusbh200->regs->status)); | 5061 | fusbh200_readl(fusbh200, &fusbh200->regs->status)); |
@@ -5365,13 +5299,6 @@ static irqreturn_t fusbh200_irq (struct usb_hcd *hcd) | |||
5365 | cmd = fusbh200_readl(fusbh200, &fusbh200->regs->command); | 5299 | cmd = fusbh200_readl(fusbh200, &fusbh200->regs->command); |
5366 | bh = 0; | 5300 | bh = 0; |
5367 | 5301 | ||
5368 | #ifdef VERBOSE_DEBUG | ||
5369 | /* unrequested/ignored: Frame List Rollover */ | ||
5370 | dbg_status (fusbh200, "irq", status); | ||
5371 | #endif | ||
5372 | |||
5373 | /* INT, ERR, and IAA interrupt rates can be throttled */ | ||
5374 | |||
5375 | /* normal [4.15.1.2] or error [4.15.1.1] completion */ | 5302 | /* normal [4.15.1.2] or error [4.15.1.1] completion */ |
5376 | if (likely ((status & (STS_INT|STS_ERR)) != 0)) { | 5303 | if (likely ((status & (STS_INT|STS_ERR)) != 0)) { |
5377 | if (likely ((status & STS_ERR) == 0)) | 5304 | if (likely ((status & STS_ERR) == 0)) |
@@ -5871,6 +5798,7 @@ static int fusbh200_hcd_probe(struct platform_device *pdev) | |||
5871 | dev_err(dev, "failed to add hcd with err %d\n", retval); | 5798 | dev_err(dev, "failed to add hcd with err %d\n", retval); |
5872 | goto fail_add_hcd; | 5799 | goto fail_add_hcd; |
5873 | } | 5800 | } |
5801 | device_wakeup_enable(hcd->self.controller); | ||
5874 | 5802 | ||
5875 | return retval; | 5803 | return retval; |
5876 | 5804 | ||
@@ -5936,13 +5864,11 @@ static int __init fusbh200_hcd_init(void) | |||
5936 | sizeof(struct fusbh200_qh), sizeof(struct fusbh200_qtd), | 5864 | sizeof(struct fusbh200_qh), sizeof(struct fusbh200_qtd), |
5937 | sizeof(struct fusbh200_itd)); | 5865 | sizeof(struct fusbh200_itd)); |
5938 | 5866 | ||
5939 | #ifdef DEBUG | ||
5940 | fusbh200_debug_root = debugfs_create_dir("fusbh200", usb_debug_root); | 5867 | fusbh200_debug_root = debugfs_create_dir("fusbh200", usb_debug_root); |
5941 | if (!fusbh200_debug_root) { | 5868 | if (!fusbh200_debug_root) { |
5942 | retval = -ENOENT; | 5869 | retval = -ENOENT; |
5943 | goto err_debug; | 5870 | goto err_debug; |
5944 | } | 5871 | } |
5945 | #endif | ||
5946 | 5872 | ||
5947 | retval = platform_driver_register(&fusbh200_hcd_fusbh200_driver); | 5873 | retval = platform_driver_register(&fusbh200_hcd_fusbh200_driver); |
5948 | if (retval < 0) | 5874 | if (retval < 0) |
@@ -5951,11 +5877,9 @@ static int __init fusbh200_hcd_init(void) | |||
5951 | 5877 | ||
5952 | platform_driver_unregister(&fusbh200_hcd_fusbh200_driver); | 5878 | platform_driver_unregister(&fusbh200_hcd_fusbh200_driver); |
5953 | clean: | 5879 | clean: |
5954 | #ifdef DEBUG | ||
5955 | debugfs_remove(fusbh200_debug_root); | 5880 | debugfs_remove(fusbh200_debug_root); |
5956 | fusbh200_debug_root = NULL; | 5881 | fusbh200_debug_root = NULL; |
5957 | err_debug: | 5882 | err_debug: |
5958 | #endif | ||
5959 | clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); | 5883 | clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); |
5960 | return retval; | 5884 | return retval; |
5961 | } | 5885 | } |
@@ -5964,9 +5888,7 @@ module_init(fusbh200_hcd_init); | |||
5964 | static void __exit fusbh200_hcd_cleanup(void) | 5888 | static void __exit fusbh200_hcd_cleanup(void) |
5965 | { | 5889 | { |
5966 | platform_driver_unregister(&fusbh200_hcd_fusbh200_driver); | 5890 | platform_driver_unregister(&fusbh200_hcd_fusbh200_driver); |
5967 | #ifdef DEBUG | ||
5968 | debugfs_remove(fusbh200_debug_root); | 5891 | debugfs_remove(fusbh200_debug_root); |
5969 | #endif | ||
5970 | clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); | 5892 | clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); |
5971 | } | 5893 | } |
5972 | module_exit(fusbh200_hcd_cleanup); | 5894 | module_exit(fusbh200_hcd_cleanup); |
diff --git a/drivers/usb/host/fusbh200.h b/drivers/usb/host/fusbh200.h index 797c9e855270..6b719e066c3f 100644 --- a/drivers/usb/host/fusbh200.h +++ b/drivers/usb/host/fusbh200.h | |||
@@ -165,17 +165,11 @@ struct fusbh200_hcd { /* one per controller */ | |||
165 | u8 sbrn; /* packed release number */ | 165 | u8 sbrn; /* packed release number */ |
166 | 166 | ||
167 | /* irq statistics */ | 167 | /* irq statistics */ |
168 | #ifdef FUSBH200_STATS | ||
169 | struct fusbh200_stats stats; | 168 | struct fusbh200_stats stats; |
170 | # define COUNT(x) do { (x)++; } while (0) | 169 | # define COUNT(x) do { (x)++; } while (0) |
171 | #else | ||
172 | # define COUNT(x) do {} while (0) | ||
173 | #endif | ||
174 | 170 | ||
175 | /* debug files */ | 171 | /* debug files */ |
176 | #ifdef DEBUG | ||
177 | struct dentry *debug_dir; | 172 | struct dentry *debug_dir; |
178 | #endif | ||
179 | }; | 173 | }; |
180 | 174 | ||
181 | /* convert between an HCD pointer and the corresponding FUSBH200_HCD */ | 175 | /* convert between an HCD pointer and the corresponding FUSBH200_HCD */ |
@@ -734,10 +728,4 @@ static inline unsigned fusbh200_read_frame_index(struct fusbh200_hcd *fusbh200) | |||
734 | }) | 728 | }) |
735 | /*-------------------------------------------------------------------------*/ | 729 | /*-------------------------------------------------------------------------*/ |
736 | 730 | ||
737 | #ifndef DEBUG | ||
738 | #define STUB_DEBUG_FILES | ||
739 | #endif /* DEBUG */ | ||
740 | |||
741 | /*-------------------------------------------------------------------------*/ | ||
742 | |||
743 | #endif /* __LINUX_FUSBH200_H */ | 731 | #endif /* __LINUX_FUSBH200_H */ |
diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c index ada0a52797b1..e07669993f58 100644 --- a/drivers/usb/host/hwa-hc.c +++ b/drivers/usb/host/hwa-hc.c | |||
@@ -54,7 +54,6 @@ | |||
54 | * DWA). | 54 | * DWA). |
55 | */ | 55 | */ |
56 | #include <linux/kernel.h> | 56 | #include <linux/kernel.h> |
57 | #include <linux/init.h> | ||
58 | #include <linux/slab.h> | 57 | #include <linux/slab.h> |
59 | #include <linux/module.h> | 58 | #include <linux/module.h> |
60 | #include <linux/workqueue.h> | 59 | #include <linux/workqueue.h> |
@@ -86,7 +85,7 @@ static int __hwahc_set_cluster_id(struct hwahc *hwahc, u8 cluster_id) | |||
86 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 85 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
87 | cluster_id, | 86 | cluster_id, |
88 | wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, | 87 | wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, |
89 | NULL, 0, 1000 /* FIXME: arbitrary */); | 88 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
90 | if (result < 0) | 89 | if (result < 0) |
91 | dev_err(dev, "Cannot set WUSB Cluster ID to 0x%02x: %d\n", | 90 | dev_err(dev, "Cannot set WUSB Cluster ID to 0x%02x: %d\n", |
92 | cluster_id, result); | 91 | cluster_id, result); |
@@ -106,7 +105,7 @@ static int __hwahc_op_set_num_dnts(struct wusbhc *wusbhc, u8 interval, u8 slots) | |||
106 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 105 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
107 | interval << 8 | slots, | 106 | interval << 8 | slots, |
108 | wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, | 107 | wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, |
109 | NULL, 0, 1000 /* FIXME: arbitrary */); | 108 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
110 | } | 109 | } |
111 | 110 | ||
112 | /* | 111 | /* |
@@ -224,7 +223,7 @@ static int hwahc_op_urb_dequeue(struct usb_hcd *usb_hcd, struct urb *urb, | |||
224 | struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); | 223 | struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); |
225 | struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); | 224 | struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); |
226 | 225 | ||
227 | return wa_urb_dequeue(&hwahc->wa, urb); | 226 | return wa_urb_dequeue(&hwahc->wa, urb, status); |
228 | } | 227 | } |
229 | 228 | ||
230 | /* | 229 | /* |
@@ -281,7 +280,7 @@ static void __hwahc_op_wusbhc_stop(struct wusbhc *wusbhc, int delay) | |||
281 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 280 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
282 | delay * 1000, | 281 | delay * 1000, |
283 | iface_no, | 282 | iface_no, |
284 | NULL, 0, 1000 /* FIXME: arbitrary */); | 283 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
285 | if (ret == 0) | 284 | if (ret == 0) |
286 | msleep(delay); | 285 | msleep(delay); |
287 | 286 | ||
@@ -310,7 +309,7 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index, | |||
310 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 309 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
311 | stream_index, | 310 | stream_index, |
312 | wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, | 311 | wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, |
313 | NULL, 0, 1000 /* FIXME: arbitrary */); | 312 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
314 | if (result < 0) { | 313 | if (result < 0) { |
315 | dev_err(dev, "Cannot set WUSB stream index: %d\n", result); | 314 | dev_err(dev, "Cannot set WUSB stream index: %d\n", result); |
316 | goto out; | 315 | goto out; |
@@ -321,7 +320,7 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index, | |||
321 | WUSB_REQ_SET_WUSB_MAS, | 320 | WUSB_REQ_SET_WUSB_MAS, |
322 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 321 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
323 | 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, | 322 | 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, |
324 | mas_le, 32, 1000 /* FIXME: arbitrary */); | 323 | mas_le, 32, USB_CTRL_SET_TIMEOUT); |
325 | if (result < 0) | 324 | if (result < 0) |
326 | dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result); | 325 | dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result); |
327 | out: | 326 | out: |
@@ -355,7 +354,7 @@ static int __hwahc_op_mmcie_add(struct wusbhc *wusbhc, u8 interval, | |||
355 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 354 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
356 | interval << 8 | repeat_cnt, | 355 | interval << 8 | repeat_cnt, |
357 | handle << 8 | iface_no, | 356 | handle << 8 | iface_no, |
358 | wuie, wuie->bLength, 1000 /* FIXME: arbitrary */); | 357 | wuie, wuie->bLength, USB_CTRL_SET_TIMEOUT); |
359 | } | 358 | } |
360 | 359 | ||
361 | /* | 360 | /* |
@@ -372,7 +371,7 @@ static int __hwahc_op_mmcie_rm(struct wusbhc *wusbhc, u8 handle) | |||
372 | WUSB_REQ_REMOVE_MMC_IE, | 371 | WUSB_REQ_REMOVE_MMC_IE, |
373 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 372 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
374 | 0, handle << 8 | iface_no, | 373 | 0, handle << 8 | iface_no, |
375 | NULL, 0, 1000 /* FIXME: arbitrary */); | 374 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
376 | } | 375 | } |
377 | 376 | ||
378 | /* | 377 | /* |
@@ -415,7 +414,7 @@ static int __hwahc_op_dev_info_set(struct wusbhc *wusbhc, | |||
415 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 414 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
416 | 0, wusb_dev->port_idx << 8 | iface_no, | 415 | 0, wusb_dev->port_idx << 8 | iface_no, |
417 | dev_info, sizeof(struct hwa_dev_info), | 416 | dev_info, sizeof(struct hwa_dev_info), |
418 | 1000 /* FIXME: arbitrary */); | 417 | USB_CTRL_SET_TIMEOUT); |
419 | kfree(dev_info); | 418 | kfree(dev_info); |
420 | return ret; | 419 | return ret; |
421 | } | 420 | } |
@@ -455,7 +454,7 @@ static int __hwahc_dev_set_key(struct wusbhc *wusbhc, u8 port_idx, u32 tkid, | |||
455 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 454 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
456 | USB_DT_KEY << 8 | key_idx, | 455 | USB_DT_KEY << 8 | key_idx, |
457 | port_idx << 8 | iface_no, | 456 | port_idx << 8 | iface_no, |
458 | keyd, keyd_len, 1000 /* FIXME: arbitrary */); | 457 | keyd, keyd_len, USB_CTRL_SET_TIMEOUT); |
459 | 458 | ||
460 | kzfree(keyd); /* clear keys etc. */ | 459 | kzfree(keyd); /* clear keys etc. */ |
461 | return result; | 460 | return result; |
@@ -497,7 +496,7 @@ static int __hwahc_op_set_ptk(struct wusbhc *wusbhc, u8 port_idx, u32 tkid, | |||
497 | USB_REQ_SET_ENCRYPTION, | 496 | USB_REQ_SET_ENCRYPTION, |
498 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 497 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
499 | encryption_value, port_idx << 8 | iface_no, | 498 | encryption_value, port_idx << 8 | iface_no, |
500 | NULL, 0, 1000 /* FIXME: arbitrary */); | 499 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
501 | if (result < 0) | 500 | if (result < 0) |
502 | dev_err(wusbhc->dev, "Can't set host's WUSB encryption for " | 501 | dev_err(wusbhc->dev, "Can't set host's WUSB encryption for " |
503 | "port index %u to %s (value %d): %d\n", port_idx, | 502 | "port index %u to %s (value %d): %d\n", port_idx, |
@@ -791,6 +790,7 @@ static int hwahc_probe(struct usb_interface *usb_iface, | |||
791 | dev_err(dev, "Cannot add HCD: %d\n", result); | 790 | dev_err(dev, "Cannot add HCD: %d\n", result); |
792 | goto error_add_hcd; | 791 | goto error_add_hcd; |
793 | } | 792 | } |
793 | device_wakeup_enable(usb_hcd->self.controller); | ||
794 | result = wusbhc_b_create(&hwahc->wusbhc); | 794 | result = wusbhc_b_create(&hwahc->wusbhc); |
795 | if (result < 0) { | 795 | if (result < 0) { |
796 | dev_err(dev, "Cannot setup phase B of WUSBHC: %d\n", result); | 796 | dev_err(dev, "Cannot setup phase B of WUSBHC: %d\n", result); |
diff --git a/drivers/usb/host/imx21-dbg.c b/drivers/usb/host/imx21-dbg.c index ec98ecee3517..4f320d050da7 100644 --- a/drivers/usb/host/imx21-dbg.c +++ b/drivers/usb/host/imx21-dbg.c | |||
@@ -18,6 +18,10 @@ | |||
18 | 18 | ||
19 | /* this file is part of imx21-hcd.c */ | 19 | /* this file is part of imx21-hcd.c */ |
20 | 20 | ||
21 | #ifdef CONFIG_DYNAMIC_DEBUG | ||
22 | #define DEBUG | ||
23 | #endif | ||
24 | |||
21 | #ifndef DEBUG | 25 | #ifndef DEBUG |
22 | 26 | ||
23 | static inline void create_debug_files(struct imx21 *imx21) { } | 27 | static inline void create_debug_files(struct imx21 *imx21) { } |
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c index adb01d950a16..207bad99301f 100644 --- a/drivers/usb/host/imx21-hcd.c +++ b/drivers/usb/host/imx21-hcd.c | |||
@@ -62,6 +62,10 @@ | |||
62 | 62 | ||
63 | #include "imx21-hcd.h" | 63 | #include "imx21-hcd.h" |
64 | 64 | ||
65 | #ifdef CONFIG_DYNAMIC_DEBUG | ||
66 | #define DEBUG | ||
67 | #endif | ||
68 | |||
65 | #ifdef DEBUG | 69 | #ifdef DEBUG |
66 | #define DEBUG_LOG_FRAME(imx21, etd, event) \ | 70 | #define DEBUG_LOG_FRAME(imx21, etd, event) \ |
67 | (etd)->event##_frame = readl((imx21)->regs + USBH_FRMNUB) | 71 | (etd)->event##_frame = readl((imx21)->regs + USBH_FRMNUB) |
@@ -1906,6 +1910,7 @@ static int imx21_probe(struct platform_device *pdev) | |||
1906 | dev_err(imx21->dev, "usb_add_hcd() returned %d\n", ret); | 1910 | dev_err(imx21->dev, "usb_add_hcd() returned %d\n", ret); |
1907 | goto failed_add_hcd; | 1911 | goto failed_add_hcd; |
1908 | } | 1912 | } |
1913 | device_wakeup_enable(hcd->self.controller); | ||
1909 | 1914 | ||
1910 | return 0; | 1915 | return 0; |
1911 | 1916 | ||
@@ -1926,7 +1931,7 @@ failed_request_mem: | |||
1926 | 1931 | ||
1927 | static struct platform_driver imx21_hcd_driver = { | 1932 | static struct platform_driver imx21_hcd_driver = { |
1928 | .driver = { | 1933 | .driver = { |
1929 | .name = (char *)hcd_name, | 1934 | .name = hcd_name, |
1930 | }, | 1935 | }, |
1931 | .probe = imx21_probe, | 1936 | .probe = imx21_probe, |
1932 | .remove = imx21_remove, | 1937 | .remove = imx21_remove, |
diff --git a/drivers/usb/host/imx21-hcd.h b/drivers/usb/host/imx21-hcd.h index c005770a73e9..05122f8a6983 100644 --- a/drivers/usb/host/imx21-hcd.h +++ b/drivers/usb/host/imx21-hcd.h | |||
@@ -24,6 +24,10 @@ | |||
24 | #ifndef __LINUX_IMX21_HCD_H__ | 24 | #ifndef __LINUX_IMX21_HCD_H__ |
25 | #define __LINUX_IMX21_HCD_H__ | 25 | #define __LINUX_IMX21_HCD_H__ |
26 | 26 | ||
27 | #ifdef CONFIG_DYNAMIC_DEBUG | ||
28 | #define DEBUG | ||
29 | #endif | ||
30 | |||
27 | #include <linux/platform_data/usb-mx2.h> | 31 | #include <linux/platform_data/usb-mx2.h> |
28 | 32 | ||
29 | #define NUM_ISO_ETDS 2 | 33 | #define NUM_ISO_ETDS 2 |
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c index c7d0f8f231be..240e792c81a7 100644 --- a/drivers/usb/host/isp116x-hcd.c +++ b/drivers/usb/host/isp116x-hcd.c | |||
@@ -60,7 +60,6 @@ | |||
60 | #include <linux/debugfs.h> | 60 | #include <linux/debugfs.h> |
61 | #include <linux/seq_file.h> | 61 | #include <linux/seq_file.h> |
62 | #include <linux/errno.h> | 62 | #include <linux/errno.h> |
63 | #include <linux/init.h> | ||
64 | #include <linux/list.h> | 63 | #include <linux/list.h> |
65 | #include <linux/slab.h> | 64 | #include <linux/slab.h> |
66 | #include <linux/usb.h> | 65 | #include <linux/usb.h> |
@@ -1645,6 +1644,8 @@ static int isp116x_probe(struct platform_device *pdev) | |||
1645 | if (ret) | 1644 | if (ret) |
1646 | goto err6; | 1645 | goto err6; |
1647 | 1646 | ||
1647 | device_wakeup_enable(hcd->self.controller); | ||
1648 | |||
1648 | ret = create_debug_file(isp116x); | 1649 | ret = create_debug_file(isp116x); |
1649 | if (ret) { | 1650 | if (ret) { |
1650 | ERR("Couldn't create debugfs entry\n"); | 1651 | ERR("Couldn't create debugfs entry\n"); |
@@ -1705,7 +1706,7 @@ static struct platform_driver isp116x_driver = { | |||
1705 | .suspend = isp116x_suspend, | 1706 | .suspend = isp116x_suspend, |
1706 | .resume = isp116x_resume, | 1707 | .resume = isp116x_resume, |
1707 | .driver = { | 1708 | .driver = { |
1708 | .name = (char *)hcd_name, | 1709 | .name = hcd_name, |
1709 | .owner = THIS_MODULE, | 1710 | .owner = THIS_MODULE, |
1710 | }, | 1711 | }, |
1711 | }; | 1712 | }; |
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c index 935a2dd367a8..875bcfd3ec1a 100644 --- a/drivers/usb/host/isp1362-hcd.c +++ b/drivers/usb/host/isp1362-hcd.c | |||
@@ -67,7 +67,6 @@ | |||
67 | #include <linux/sched.h> | 67 | #include <linux/sched.h> |
68 | #include <linux/slab.h> | 68 | #include <linux/slab.h> |
69 | #include <linux/errno.h> | 69 | #include <linux/errno.h> |
70 | #include <linux/init.h> | ||
71 | #include <linux/list.h> | 70 | #include <linux/list.h> |
72 | #include <linux/interrupt.h> | 71 | #include <linux/interrupt.h> |
73 | #include <linux/usb.h> | 72 | #include <linux/usb.h> |
@@ -2746,6 +2745,8 @@ static int isp1362_probe(struct platform_device *pdev) | |||
2746 | retval = usb_add_hcd(hcd, irq, irq_flags | IRQF_SHARED); | 2745 | retval = usb_add_hcd(hcd, irq, irq_flags | IRQF_SHARED); |
2747 | if (retval != 0) | 2746 | if (retval != 0) |
2748 | goto err6; | 2747 | goto err6; |
2748 | device_wakeup_enable(hcd->self.controller); | ||
2749 | |||
2749 | pr_info("%s, irq %d\n", hcd->product_desc, irq); | 2750 | pr_info("%s, irq %d\n", hcd->product_desc, irq); |
2750 | 2751 | ||
2751 | create_debug_file(isp1362_hcd); | 2752 | create_debug_file(isp1362_hcd); |
@@ -2829,7 +2830,7 @@ static struct platform_driver isp1362_driver = { | |||
2829 | .suspend = isp1362_suspend, | 2830 | .suspend = isp1362_suspend, |
2830 | .resume = isp1362_resume, | 2831 | .resume = isp1362_resume, |
2831 | .driver = { | 2832 | .driver = { |
2832 | .name = (char *)hcd_name, | 2833 | .name = hcd_name, |
2833 | .owner = THIS_MODULE, | 2834 | .owner = THIS_MODULE, |
2834 | }, | 2835 | }, |
2835 | }; | 2836 | }; |
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c index 2facee53eab1..51a0ae9cdd1d 100644 --- a/drivers/usb/host/isp1760-hcd.c +++ b/drivers/usb/host/isp1760-hcd.c | |||
@@ -2250,6 +2250,7 @@ struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len, | |||
2250 | ret = usb_add_hcd(hcd, irq, irqflags); | 2250 | ret = usb_add_hcd(hcd, irq, irqflags); |
2251 | if (ret) | 2251 | if (ret) |
2252 | goto err_unmap; | 2252 | goto err_unmap; |
2253 | device_wakeup_enable(hcd->self.controller); | ||
2253 | 2254 | ||
2254 | return hcd; | 2255 | return hcd; |
2255 | 2256 | ||
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c index 8c356af79409..091ae4905cfc 100644 --- a/drivers/usb/host/ohci-at91.c +++ b/drivers/usb/host/ohci-at91.c | |||
@@ -152,49 +152,42 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver, | |||
152 | return irq; | 152 | return irq; |
153 | } | 153 | } |
154 | 154 | ||
155 | hcd = usb_create_hcd(driver, &pdev->dev, "at91"); | 155 | hcd = usb_create_hcd(driver, dev, "at91"); |
156 | if (!hcd) | 156 | if (!hcd) |
157 | return -ENOMEM; | 157 | return -ENOMEM; |
158 | hcd->rsrc_start = res->start; | 158 | hcd->rsrc_start = res->start; |
159 | hcd->rsrc_len = resource_size(res); | 159 | hcd->rsrc_len = resource_size(res); |
160 | 160 | ||
161 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | 161 | hcd->regs = devm_ioremap_resource(dev, res); |
162 | pr_debug("request_mem_region failed\n"); | 162 | if (IS_ERR(hcd->regs)) { |
163 | retval = -EBUSY; | 163 | retval = PTR_ERR(hcd->regs); |
164 | goto err1; | 164 | goto err; |
165 | } | 165 | } |
166 | 166 | ||
167 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | 167 | iclk = devm_clk_get(dev, "ohci_clk"); |
168 | if (!hcd->regs) { | ||
169 | pr_debug("ioremap failed\n"); | ||
170 | retval = -EIO; | ||
171 | goto err2; | ||
172 | } | ||
173 | |||
174 | iclk = clk_get(&pdev->dev, "ohci_clk"); | ||
175 | if (IS_ERR(iclk)) { | 168 | if (IS_ERR(iclk)) { |
176 | dev_err(&pdev->dev, "failed to get ohci_clk\n"); | 169 | dev_err(dev, "failed to get ohci_clk\n"); |
177 | retval = PTR_ERR(iclk); | 170 | retval = PTR_ERR(iclk); |
178 | goto err3; | 171 | goto err; |
179 | } | 172 | } |
180 | fclk = clk_get(&pdev->dev, "uhpck"); | 173 | fclk = devm_clk_get(dev, "uhpck"); |
181 | if (IS_ERR(fclk)) { | 174 | if (IS_ERR(fclk)) { |
182 | dev_err(&pdev->dev, "failed to get uhpck\n"); | 175 | dev_err(dev, "failed to get uhpck\n"); |
183 | retval = PTR_ERR(fclk); | 176 | retval = PTR_ERR(fclk); |
184 | goto err4; | 177 | goto err; |
185 | } | 178 | } |
186 | hclk = clk_get(&pdev->dev, "hclk"); | 179 | hclk = devm_clk_get(dev, "hclk"); |
187 | if (IS_ERR(hclk)) { | 180 | if (IS_ERR(hclk)) { |
188 | dev_err(&pdev->dev, "failed to get hclk\n"); | 181 | dev_err(dev, "failed to get hclk\n"); |
189 | retval = PTR_ERR(hclk); | 182 | retval = PTR_ERR(hclk); |
190 | goto err5; | 183 | goto err; |
191 | } | 184 | } |
192 | if (IS_ENABLED(CONFIG_COMMON_CLK)) { | 185 | if (IS_ENABLED(CONFIG_COMMON_CLK)) { |
193 | uclk = clk_get(&pdev->dev, "usb_clk"); | 186 | uclk = devm_clk_get(dev, "usb_clk"); |
194 | if (IS_ERR(uclk)) { | 187 | if (IS_ERR(uclk)) { |
195 | dev_err(&pdev->dev, "failed to get uclk\n"); | 188 | dev_err(dev, "failed to get uclk\n"); |
196 | retval = PTR_ERR(uclk); | 189 | retval = PTR_ERR(uclk); |
197 | goto err6; | 190 | goto err; |
198 | } | 191 | } |
199 | } | 192 | } |
200 | 193 | ||
@@ -204,28 +197,15 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver, | |||
204 | at91_start_hc(pdev); | 197 | at91_start_hc(pdev); |
205 | 198 | ||
206 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | 199 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); |
207 | if (retval == 0) | 200 | if (retval == 0) { |
201 | device_wakeup_enable(hcd->self.controller); | ||
208 | return retval; | 202 | return retval; |
203 | } | ||
209 | 204 | ||
210 | /* Error handling */ | 205 | /* Error handling */ |
211 | at91_stop_hc(pdev); | 206 | at91_stop_hc(pdev); |
212 | 207 | ||
213 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | 208 | err: |
214 | clk_put(uclk); | ||
215 | err6: | ||
216 | clk_put(hclk); | ||
217 | err5: | ||
218 | clk_put(fclk); | ||
219 | err4: | ||
220 | clk_put(iclk); | ||
221 | |||
222 | err3: | ||
223 | iounmap(hcd->regs); | ||
224 | |||
225 | err2: | ||
226 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
227 | |||
228 | err1: | ||
229 | usb_put_hcd(hcd); | 209 | usb_put_hcd(hcd); |
230 | return retval; | 210 | return retval; |
231 | } | 211 | } |
@@ -248,16 +228,7 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd, | |||
248 | { | 228 | { |
249 | usb_remove_hcd(hcd); | 229 | usb_remove_hcd(hcd); |
250 | at91_stop_hc(pdev); | 230 | at91_stop_hc(pdev); |
251 | iounmap(hcd->regs); | ||
252 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
253 | usb_put_hcd(hcd); | 231 | usb_put_hcd(hcd); |
254 | |||
255 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | ||
256 | clk_put(uclk); | ||
257 | clk_put(hclk); | ||
258 | clk_put(fclk); | ||
259 | clk_put(iclk); | ||
260 | fclk = iclk = hclk = NULL; | ||
261 | } | 232 | } |
262 | 233 | ||
263 | /*-------------------------------------------------------------------------*/ | 234 | /*-------------------------------------------------------------------------*/ |
@@ -639,10 +610,17 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg) | |||
639 | { | 610 | { |
640 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 611 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
641 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 612 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
613 | bool do_wakeup = device_may_wakeup(&pdev->dev); | ||
614 | int ret; | ||
642 | 615 | ||
643 | if (device_may_wakeup(&pdev->dev)) | 616 | if (do_wakeup) |
644 | enable_irq_wake(hcd->irq); | 617 | enable_irq_wake(hcd->irq); |
645 | 618 | ||
619 | ret = ohci_suspend(hcd, do_wakeup); | ||
620 | if (ret) { | ||
621 | disable_irq_wake(hcd->irq); | ||
622 | return ret; | ||
623 | } | ||
646 | /* | 624 | /* |
647 | * The integrated transceivers seem unable to notice disconnect, | 625 | * The integrated transceivers seem unable to notice disconnect, |
648 | * reconnect, or wakeup without the 48 MHz clock active. so for | 626 | * reconnect, or wakeup without the 48 MHz clock active. so for |
@@ -661,7 +639,7 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg) | |||
661 | at91_stop_clock(); | 639 | at91_stop_clock(); |
662 | } | 640 | } |
663 | 641 | ||
664 | return 0; | 642 | return ret; |
665 | } | 643 | } |
666 | 644 | ||
667 | static int ohci_hcd_at91_drv_resume(struct platform_device *pdev) | 645 | static int ohci_hcd_at91_drv_resume(struct platform_device *pdev) |
diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c index 9be59f11e051..df06be6b47f5 100644 --- a/drivers/usb/host/ohci-da8xx.c +++ b/drivers/usb/host/ohci-da8xx.c | |||
@@ -300,41 +300,28 @@ static int usb_hcd_da8xx_probe(const struct hc_driver *driver, | |||
300 | if (hub == NULL) | 300 | if (hub == NULL) |
301 | return -ENODEV; | 301 | return -ENODEV; |
302 | 302 | ||
303 | usb11_clk = clk_get(&pdev->dev, "usb11"); | 303 | usb11_clk = devm_clk_get(&pdev->dev, "usb11"); |
304 | if (IS_ERR(usb11_clk)) | 304 | if (IS_ERR(usb11_clk)) |
305 | return PTR_ERR(usb11_clk); | 305 | return PTR_ERR(usb11_clk); |
306 | 306 | ||
307 | usb20_clk = clk_get(&pdev->dev, "usb20"); | 307 | usb20_clk = devm_clk_get(&pdev->dev, "usb20"); |
308 | if (IS_ERR(usb20_clk)) { | 308 | if (IS_ERR(usb20_clk)) |
309 | error = PTR_ERR(usb20_clk); | 309 | return PTR_ERR(usb20_clk); |
310 | goto err0; | ||
311 | } | ||
312 | 310 | ||
313 | hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); | 311 | hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); |
314 | if (!hcd) { | 312 | if (!hcd) |
315 | error = -ENOMEM; | 313 | return -ENOMEM; |
316 | goto err1; | ||
317 | } | ||
318 | 314 | ||
319 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 315 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
320 | if (!mem) { | 316 | if (!mem) |
321 | error = -ENODEV; | 317 | return -ENODEV; |
322 | goto err2; | ||
323 | } | ||
324 | hcd->rsrc_start = mem->start; | 318 | hcd->rsrc_start = mem->start; |
325 | hcd->rsrc_len = resource_size(mem); | 319 | hcd->rsrc_len = resource_size(mem); |
326 | 320 | ||
327 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | 321 | hcd->regs = devm_ioremap_resource(&pdev->dev, mem); |
328 | dev_dbg(&pdev->dev, "request_mem_region failed\n"); | 322 | if (IS_ERR(hcd->regs)) { |
329 | error = -EBUSY; | 323 | error = PTR_ERR(hcd->regs); |
330 | goto err2; | 324 | goto err; |
331 | } | ||
332 | |||
333 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
334 | if (!hcd->regs) { | ||
335 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
336 | error = -ENOMEM; | ||
337 | goto err3; | ||
338 | } | 325 | } |
339 | 326 | ||
340 | ohci_hcd_init(hcd_to_ohci(hcd)); | 327 | ohci_hcd_init(hcd_to_ohci(hcd)); |
@@ -342,11 +329,13 @@ static int usb_hcd_da8xx_probe(const struct hc_driver *driver, | |||
342 | irq = platform_get_irq(pdev, 0); | 329 | irq = platform_get_irq(pdev, 0); |
343 | if (irq < 0) { | 330 | if (irq < 0) { |
344 | error = -ENODEV; | 331 | error = -ENODEV; |
345 | goto err4; | 332 | goto err; |
346 | } | 333 | } |
347 | error = usb_add_hcd(hcd, irq, 0); | 334 | error = usb_add_hcd(hcd, irq, 0); |
348 | if (error) | 335 | if (error) |
349 | goto err4; | 336 | goto err; |
337 | |||
338 | device_wakeup_enable(hcd->self.controller); | ||
350 | 339 | ||
351 | if (hub->ocic_notify) { | 340 | if (hub->ocic_notify) { |
352 | error = hub->ocic_notify(ohci_da8xx_ocic_handler); | 341 | error = hub->ocic_notify(ohci_da8xx_ocic_handler); |
@@ -355,16 +344,8 @@ static int usb_hcd_da8xx_probe(const struct hc_driver *driver, | |||
355 | } | 344 | } |
356 | 345 | ||
357 | usb_remove_hcd(hcd); | 346 | usb_remove_hcd(hcd); |
358 | err4: | 347 | err: |
359 | iounmap(hcd->regs); | ||
360 | err3: | ||
361 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
362 | err2: | ||
363 | usb_put_hcd(hcd); | 348 | usb_put_hcd(hcd); |
364 | err1: | ||
365 | clk_put(usb20_clk); | ||
366 | err0: | ||
367 | clk_put(usb11_clk); | ||
368 | return error; | 349 | return error; |
369 | } | 350 | } |
370 | 351 | ||
@@ -384,11 +365,7 @@ usb_hcd_da8xx_remove(struct usb_hcd *hcd, struct platform_device *pdev) | |||
384 | 365 | ||
385 | hub->ocic_notify(NULL); | 366 | hub->ocic_notify(NULL); |
386 | usb_remove_hcd(hcd); | 367 | usb_remove_hcd(hcd); |
387 | iounmap(hcd->regs); | ||
388 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
389 | usb_put_hcd(hcd); | 368 | usb_put_hcd(hcd); |
390 | clk_put(usb20_clk); | ||
391 | clk_put(usb11_clk); | ||
392 | } | 369 | } |
393 | 370 | ||
394 | static int ohci_hcd_da8xx_drv_probe(struct platform_device *dev) | 371 | static int ohci_hcd_da8xx_drv_probe(struct platform_device *dev) |
@@ -406,19 +383,27 @@ static int ohci_hcd_da8xx_drv_remove(struct platform_device *dev) | |||
406 | } | 383 | } |
407 | 384 | ||
408 | #ifdef CONFIG_PM | 385 | #ifdef CONFIG_PM |
409 | static int ohci_da8xx_suspend(struct platform_device *dev, pm_message_t message) | 386 | static int ohci_da8xx_suspend(struct platform_device *pdev, |
387 | pm_message_t message) | ||
410 | { | 388 | { |
411 | struct usb_hcd *hcd = platform_get_drvdata(dev); | 389 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
412 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 390 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
391 | bool do_wakeup = device_may_wakeup(&pdev->dev); | ||
392 | int ret; | ||
393 | |||
413 | 394 | ||
414 | if (time_before(jiffies, ohci->next_statechange)) | 395 | if (time_before(jiffies, ohci->next_statechange)) |
415 | msleep(5); | 396 | msleep(5); |
416 | ohci->next_statechange = jiffies; | 397 | ohci->next_statechange = jiffies; |
417 | 398 | ||
399 | ret = ohci_suspend(hcd, do_wakeup); | ||
400 | if (ret) | ||
401 | return ret; | ||
402 | |||
418 | ohci_da8xx_clock(0); | 403 | ohci_da8xx_clock(0); |
419 | hcd->state = HC_STATE_SUSPENDED; | 404 | hcd->state = HC_STATE_SUSPENDED; |
420 | dev->dev.power.power_state = PMSG_SUSPEND; | 405 | |
421 | return 0; | 406 | return ret; |
422 | } | 407 | } |
423 | 408 | ||
424 | static int ohci_da8xx_resume(struct platform_device *dev) | 409 | static int ohci_da8xx_resume(struct platform_device *dev) |
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c index 3fca52ec02ac..45032e933e18 100644 --- a/drivers/usb/host/ohci-dbg.c +++ b/drivers/usb/host/ohci-dbg.c | |||
@@ -9,8 +9,6 @@ | |||
9 | 9 | ||
10 | /*-------------------------------------------------------------------------*/ | 10 | /*-------------------------------------------------------------------------*/ |
11 | 11 | ||
12 | #ifdef DEBUG | ||
13 | |||
14 | #define edstring(ed_type) ({ char *temp; \ | 12 | #define edstring(ed_type) ({ char *temp; \ |
15 | switch (ed_type) { \ | 13 | switch (ed_type) { \ |
16 | case PIPE_CONTROL: temp = "ctrl"; break; \ | 14 | case PIPE_CONTROL: temp = "ctrl"; break; \ |
@@ -20,57 +18,6 @@ | |||
20 | } temp;}) | 18 | } temp;}) |
21 | #define pipestring(pipe) edstring(usb_pipetype(pipe)) | 19 | #define pipestring(pipe) edstring(usb_pipetype(pipe)) |
22 | 20 | ||
23 | /* debug| print the main components of an URB | ||
24 | * small: 0) header + data packets 1) just header | ||
25 | */ | ||
26 | static void __maybe_unused | ||
27 | urb_print(struct urb * urb, char * str, int small, int status) | ||
28 | { | ||
29 | unsigned int pipe= urb->pipe; | ||
30 | |||
31 | if (!urb->dev || !urb->dev->bus) { | ||
32 | printk(KERN_DEBUG "%s URB: no dev\n", str); | ||
33 | return; | ||
34 | } | ||
35 | |||
36 | #ifndef OHCI_VERBOSE_DEBUG | ||
37 | if (status != 0) | ||
38 | #endif | ||
39 | printk(KERN_DEBUG "%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d stat=%d\n", | ||
40 | str, | ||
41 | urb, | ||
42 | usb_pipedevice (pipe), | ||
43 | usb_pipeendpoint (pipe), | ||
44 | usb_pipeout (pipe)? "out" : "in", | ||
45 | pipestring (pipe), | ||
46 | urb->transfer_flags, | ||
47 | urb->actual_length, | ||
48 | urb->transfer_buffer_length, | ||
49 | status); | ||
50 | |||
51 | #ifdef OHCI_VERBOSE_DEBUG | ||
52 | if (!small) { | ||
53 | int i, len; | ||
54 | |||
55 | if (usb_pipecontrol (pipe)) { | ||
56 | printk (KERN_DEBUG "%s: setup(8):", __FILE__); | ||
57 | for (i = 0; i < 8 ; i++) | ||
58 | printk (" %02x", ((__u8 *) urb->setup_packet) [i]); | ||
59 | printk ("\n"); | ||
60 | } | ||
61 | if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) { | ||
62 | printk (KERN_DEBUG "%s: data(%d/%d):", __FILE__, | ||
63 | urb->actual_length, | ||
64 | urb->transfer_buffer_length); | ||
65 | len = usb_pipeout (pipe)? | ||
66 | urb->transfer_buffer_length: urb->actual_length; | ||
67 | for (i = 0; i < 16 && i < len; i++) | ||
68 | printk (" %02x", ((__u8 *) urb->transfer_buffer) [i]); | ||
69 | printk ("%s stat:%d\n", i < len? "...": "", status); | ||
70 | } | ||
71 | } | ||
72 | #endif | ||
73 | } | ||
74 | 21 | ||
75 | #define ohci_dbg_sw(ohci, next, size, format, arg...) \ | 22 | #define ohci_dbg_sw(ohci, next, size, format, arg...) \ |
76 | do { \ | 23 | do { \ |
@@ -407,22 +354,8 @@ ohci_dump_ed (const struct ohci_hcd *ohci, const char *label, | |||
407 | } | 354 | } |
408 | } | 355 | } |
409 | 356 | ||
410 | #else | ||
411 | static inline void ohci_dump (struct ohci_hcd *controller, int verbose) {} | ||
412 | |||
413 | #undef OHCI_VERBOSE_DEBUG | ||
414 | |||
415 | #endif /* DEBUG */ | ||
416 | |||
417 | /*-------------------------------------------------------------------------*/ | 357 | /*-------------------------------------------------------------------------*/ |
418 | 358 | ||
419 | #ifdef STUB_DEBUG_FILES | ||
420 | |||
421 | static inline void create_debug_files (struct ohci_hcd *bus) { } | ||
422 | static inline void remove_debug_files (struct ohci_hcd *bus) { } | ||
423 | |||
424 | #else | ||
425 | |||
426 | static int debug_async_open(struct inode *, struct file *); | 359 | static int debug_async_open(struct inode *, struct file *); |
427 | static int debug_periodic_open(struct inode *, struct file *); | 360 | static int debug_periodic_open(struct inode *, struct file *); |
428 | static int debug_registers_open(struct inode *, struct file *); | 361 | static int debug_registers_open(struct inode *, struct file *); |
@@ -871,7 +804,5 @@ static inline void remove_debug_files (struct ohci_hcd *ohci) | |||
871 | debugfs_remove(ohci->debug_dir); | 804 | debugfs_remove(ohci->debug_dir); |
872 | } | 805 | } |
873 | 806 | ||
874 | #endif | ||
875 | |||
876 | /*-------------------------------------------------------------------------*/ | 807 | /*-------------------------------------------------------------------------*/ |
877 | 808 | ||
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c index 91ec9b2cd378..68588d8a09bb 100644 --- a/drivers/usb/host/ohci-exynos.c +++ b/drivers/usb/host/ohci-exynos.c | |||
@@ -146,6 +146,7 @@ skip_phy: | |||
146 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); | 146 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); |
147 | goto fail_add_hcd; | 147 | goto fail_add_hcd; |
148 | } | 148 | } |
149 | device_wakeup_enable(hcd->self.controller); | ||
149 | return 0; | 150 | return 0; |
150 | 151 | ||
151 | fail_add_hcd: | 152 | fail_add_hcd: |
@@ -191,23 +192,14 @@ static int exynos_ohci_suspend(struct device *dev) | |||
191 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); | 192 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
192 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 193 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
193 | struct platform_device *pdev = to_platform_device(dev); | 194 | struct platform_device *pdev = to_platform_device(dev); |
195 | bool do_wakeup = device_may_wakeup(dev); | ||
194 | unsigned long flags; | 196 | unsigned long flags; |
195 | int rc = 0; | 197 | int rc = ohci_suspend(hcd, do_wakeup); |
196 | 198 | ||
197 | /* | 199 | if (rc) |
198 | * Root hub was already suspended. Disable irq emission and | 200 | return rc; |
199 | * mark HW unaccessible, bail out if RH has been resumed. Use | ||
200 | * the spinlock to properly synchronize with possible pending | ||
201 | * RH suspend or resume activity. | ||
202 | */ | ||
203 | spin_lock_irqsave(&ohci->lock, flags); | ||
204 | if (ohci->rh_state != OHCI_RH_SUSPENDED && | ||
205 | ohci->rh_state != OHCI_RH_HALTED) { | ||
206 | rc = -EINVAL; | ||
207 | goto fail; | ||
208 | } | ||
209 | 201 | ||
210 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 202 | spin_lock_irqsave(&ohci->lock, flags); |
211 | 203 | ||
212 | if (exynos_ohci->otg) | 204 | if (exynos_ohci->otg) |
213 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); | 205 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); |
@@ -216,10 +208,9 @@ static int exynos_ohci_suspend(struct device *dev) | |||
216 | 208 | ||
217 | clk_disable_unprepare(exynos_ohci->clk); | 209 | clk_disable_unprepare(exynos_ohci->clk); |
218 | 210 | ||
219 | fail: | ||
220 | spin_unlock_irqrestore(&ohci->lock, flags); | 211 | spin_unlock_irqrestore(&ohci->lock, flags); |
221 | 212 | ||
222 | return rc; | 213 | return 0; |
223 | } | 214 | } |
224 | 215 | ||
225 | static int exynos_ohci_resume(struct device *dev) | 216 | static int exynos_ohci_resume(struct device *dev) |
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index 8ada13f8dde2..3586460fb2a1 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c | |||
@@ -51,8 +51,6 @@ | |||
51 | 51 | ||
52 | /*-------------------------------------------------------------------------*/ | 52 | /*-------------------------------------------------------------------------*/ |
53 | 53 | ||
54 | #undef OHCI_VERBOSE_DEBUG /* not always helpful */ | ||
55 | |||
56 | /* For initializing controller (mask in an HCFS mode too) */ | 54 | /* For initializing controller (mask in an HCFS mode too) */ |
57 | #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR | 55 | #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR |
58 | #define OHCI_INTR_INIT \ | 56 | #define OHCI_INTR_INIT \ |
@@ -127,10 +125,6 @@ static int ohci_urb_enqueue ( | |||
127 | unsigned long flags; | 125 | unsigned long flags; |
128 | int retval = 0; | 126 | int retval = 0; |
129 | 127 | ||
130 | #ifdef OHCI_VERBOSE_DEBUG | ||
131 | urb_print(urb, "SUB", usb_pipein(pipe), -EINPROGRESS); | ||
132 | #endif | ||
133 | |||
134 | /* every endpoint has a ed, locate and maybe (re)initialize it */ | 128 | /* every endpoint has a ed, locate and maybe (re)initialize it */ |
135 | if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval))) | 129 | if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval))) |
136 | return -ENOMEM; | 130 | return -ENOMEM; |
@@ -284,10 +278,6 @@ static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | |||
284 | unsigned long flags; | 278 | unsigned long flags; |
285 | int rc; | 279 | int rc; |
286 | 280 | ||
287 | #ifdef OHCI_VERBOSE_DEBUG | ||
288 | urb_print(urb, "UNLINK", 1, status); | ||
289 | #endif | ||
290 | |||
291 | spin_lock_irqsave (&ohci->lock, flags); | 281 | spin_lock_irqsave (&ohci->lock, flags); |
292 | rc = usb_hcd_check_unlink_urb(hcd, urb, status); | 282 | rc = usb_hcd_check_unlink_urb(hcd, urb, status); |
293 | if (rc) { | 283 | if (rc) { |
@@ -840,7 +830,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd) | |||
840 | } | 830 | } |
841 | 831 | ||
842 | if (ints & OHCI_INTR_RHSC) { | 832 | if (ints & OHCI_INTR_RHSC) { |
843 | ohci_vdbg(ohci, "rhsc\n"); | 833 | ohci_dbg(ohci, "rhsc\n"); |
844 | ohci->next_statechange = jiffies + STATECHANGE_DELAY; | 834 | ohci->next_statechange = jiffies + STATECHANGE_DELAY; |
845 | ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC, | 835 | ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC, |
846 | ®s->intrstatus); | 836 | ®s->intrstatus); |
@@ -862,7 +852,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd) | |||
862 | * this might not happen. | 852 | * this might not happen. |
863 | */ | 853 | */ |
864 | else if (ints & OHCI_INTR_RD) { | 854 | else if (ints & OHCI_INTR_RD) { |
865 | ohci_vdbg(ohci, "resume detect\n"); | 855 | ohci_dbg(ohci, "resume detect\n"); |
866 | ohci_writel(ohci, OHCI_INTR_RD, ®s->intrstatus); | 856 | ohci_writel(ohci, OHCI_INTR_RD, ®s->intrstatus); |
867 | set_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 857 | set_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
868 | if (ohci->autostop) { | 858 | if (ohci->autostop) { |
@@ -1036,6 +1026,7 @@ int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup) | |||
1036 | { | 1026 | { |
1037 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | 1027 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
1038 | unsigned long flags; | 1028 | unsigned long flags; |
1029 | int rc = 0; | ||
1039 | 1030 | ||
1040 | /* Disable irq emission and mark HW unaccessible. Use | 1031 | /* Disable irq emission and mark HW unaccessible. Use |
1041 | * the spinlock to properly synchronize with possible pending | 1032 | * the spinlock to properly synchronize with possible pending |
@@ -1048,7 +1039,13 @@ int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup) | |||
1048 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 1039 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
1049 | spin_unlock_irqrestore (&ohci->lock, flags); | 1040 | spin_unlock_irqrestore (&ohci->lock, flags); |
1050 | 1041 | ||
1051 | return 0; | 1042 | synchronize_irq(hcd->irq); |
1043 | |||
1044 | if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) { | ||
1045 | ohci_resume(hcd, false); | ||
1046 | rc = -EBUSY; | ||
1047 | } | ||
1048 | return rc; | ||
1052 | } | 1049 | } |
1053 | EXPORT_SYMBOL_GPL(ohci_suspend); | 1050 | EXPORT_SYMBOL_GPL(ohci_suspend); |
1054 | 1051 | ||
@@ -1233,13 +1230,11 @@ static int __init ohci_hcd_mod_init(void) | |||
1233 | sizeof (struct ed), sizeof (struct td)); | 1230 | sizeof (struct ed), sizeof (struct td)); |
1234 | set_bit(USB_OHCI_LOADED, &usb_hcds_loaded); | 1231 | set_bit(USB_OHCI_LOADED, &usb_hcds_loaded); |
1235 | 1232 | ||
1236 | #ifdef DEBUG | ||
1237 | ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root); | 1233 | ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root); |
1238 | if (!ohci_debug_root) { | 1234 | if (!ohci_debug_root) { |
1239 | retval = -ENOENT; | 1235 | retval = -ENOENT; |
1240 | goto error_debug; | 1236 | goto error_debug; |
1241 | } | 1237 | } |
1242 | #endif | ||
1243 | 1238 | ||
1244 | #ifdef PS3_SYSTEM_BUS_DRIVER | 1239 | #ifdef PS3_SYSTEM_BUS_DRIVER |
1245 | retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER); | 1240 | retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER); |
@@ -1314,11 +1309,9 @@ static int __init ohci_hcd_mod_init(void) | |||
1314 | ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); | 1309 | ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); |
1315 | error_ps3: | 1310 | error_ps3: |
1316 | #endif | 1311 | #endif |
1317 | #ifdef DEBUG | ||
1318 | debugfs_remove(ohci_debug_root); | 1312 | debugfs_remove(ohci_debug_root); |
1319 | ohci_debug_root = NULL; | 1313 | ohci_debug_root = NULL; |
1320 | error_debug: | 1314 | error_debug: |
1321 | #endif | ||
1322 | 1315 | ||
1323 | clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded); | 1316 | clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded); |
1324 | return retval; | 1317 | return retval; |
@@ -1348,9 +1341,7 @@ static void __exit ohci_hcd_mod_exit(void) | |||
1348 | #ifdef PS3_SYSTEM_BUS_DRIVER | 1341 | #ifdef PS3_SYSTEM_BUS_DRIVER |
1349 | ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); | 1342 | ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); |
1350 | #endif | 1343 | #endif |
1351 | #ifdef DEBUG | ||
1352 | debugfs_remove(ohci_debug_root); | 1344 | debugfs_remove(ohci_debug_root); |
1353 | #endif | ||
1354 | clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded); | 1345 | clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded); |
1355 | } | 1346 | } |
1356 | module_exit(ohci_hcd_mod_exit); | 1347 | module_exit(ohci_hcd_mod_exit); |
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c index 61705a760e7d..c81c8721cc5a 100644 --- a/drivers/usb/host/ohci-hub.c +++ b/drivers/usb/host/ohci-hub.c | |||
@@ -725,10 +725,8 @@ static int ohci_hub_control ( | |||
725 | temp = roothub_portstatus (ohci, wIndex); | 725 | temp = roothub_portstatus (ohci, wIndex); |
726 | put_unaligned_le32(temp, buf); | 726 | put_unaligned_le32(temp, buf); |
727 | 727 | ||
728 | #ifndef OHCI_VERBOSE_DEBUG | 728 | if (*(u16*)(buf+2)) /* only if wPortChange is interesting */ |
729 | if (*(u16*)(buf+2)) /* only if wPortChange is interesting */ | 729 | dbg_port(ohci, "GetStatus", wIndex, temp); |
730 | #endif | ||
731 | dbg_port (ohci, "GetStatus", wIndex, temp); | ||
732 | break; | 730 | break; |
733 | case SetHubFeature: | 731 | case SetHubFeature: |
734 | switch (wValue) { | 732 | switch (wValue) { |
diff --git a/drivers/usb/host/ohci-jz4740.c b/drivers/usb/host/ohci-jz4740.c index d4ef53990d73..af8dc1b92d75 100644 --- a/drivers/usb/host/ohci-jz4740.c +++ b/drivers/usb/host/ohci-jz4740.c | |||
@@ -174,31 +174,23 @@ static int jz4740_ohci_probe(struct platform_device *pdev) | |||
174 | 174 | ||
175 | jz4740_ohci = hcd_to_jz4740_hcd(hcd); | 175 | jz4740_ohci = hcd_to_jz4740_hcd(hcd); |
176 | 176 | ||
177 | res = request_mem_region(res->start, resource_size(res), hcd_name); | ||
178 | if (!res) { | ||
179 | dev_err(&pdev->dev, "Failed to request mem region.\n"); | ||
180 | ret = -EBUSY; | ||
181 | goto err_free; | ||
182 | } | ||
183 | |||
184 | hcd->rsrc_start = res->start; | 177 | hcd->rsrc_start = res->start; |
185 | hcd->rsrc_len = resource_size(res); | 178 | hcd->rsrc_len = resource_size(res); |
186 | hcd->regs = ioremap(res->start, resource_size(res)); | ||
187 | 179 | ||
188 | if (!hcd->regs) { | 180 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
189 | dev_err(&pdev->dev, "Failed to ioremap registers.\n"); | 181 | if (IS_ERR(hcd->regs)) { |
190 | ret = -EBUSY; | 182 | ret = PTR_ERR(hcd->regs); |
191 | goto err_release_mem; | 183 | goto err_free; |
192 | } | 184 | } |
193 | 185 | ||
194 | jz4740_ohci->clk = clk_get(&pdev->dev, "uhc"); | 186 | jz4740_ohci->clk = devm_clk_get(&pdev->dev, "uhc"); |
195 | if (IS_ERR(jz4740_ohci->clk)) { | 187 | if (IS_ERR(jz4740_ohci->clk)) { |
196 | ret = PTR_ERR(jz4740_ohci->clk); | 188 | ret = PTR_ERR(jz4740_ohci->clk); |
197 | dev_err(&pdev->dev, "Failed to get clock: %d\n", ret); | 189 | dev_err(&pdev->dev, "Failed to get clock: %d\n", ret); |
198 | goto err_iounmap; | 190 | goto err_free; |
199 | } | 191 | } |
200 | 192 | ||
201 | jz4740_ohci->vbus = regulator_get(&pdev->dev, "vbus"); | 193 | jz4740_ohci->vbus = devm_regulator_get(&pdev->dev, "vbus"); |
202 | if (IS_ERR(jz4740_ohci->vbus)) | 194 | if (IS_ERR(jz4740_ohci->vbus)) |
203 | jz4740_ohci->vbus = NULL; | 195 | jz4740_ohci->vbus = NULL; |
204 | 196 | ||
@@ -217,21 +209,15 @@ static int jz4740_ohci_probe(struct platform_device *pdev) | |||
217 | dev_err(&pdev->dev, "Failed to add hcd: %d\n", ret); | 209 | dev_err(&pdev->dev, "Failed to add hcd: %d\n", ret); |
218 | goto err_disable; | 210 | goto err_disable; |
219 | } | 211 | } |
212 | device_wakeup_enable(hcd->self.controller); | ||
220 | 213 | ||
221 | return 0; | 214 | return 0; |
222 | 215 | ||
223 | err_disable: | 216 | err_disable: |
224 | if (jz4740_ohci->vbus) { | 217 | if (jz4740_ohci->vbus) |
225 | regulator_disable(jz4740_ohci->vbus); | 218 | regulator_disable(jz4740_ohci->vbus); |
226 | regulator_put(jz4740_ohci->vbus); | ||
227 | } | ||
228 | clk_disable(jz4740_ohci->clk); | 219 | clk_disable(jz4740_ohci->clk); |
229 | 220 | ||
230 | clk_put(jz4740_ohci->clk); | ||
231 | err_iounmap: | ||
232 | iounmap(hcd->regs); | ||
233 | err_release_mem: | ||
234 | release_mem_region(res->start, resource_size(res)); | ||
235 | err_free: | 221 | err_free: |
236 | usb_put_hcd(hcd); | 222 | usb_put_hcd(hcd); |
237 | 223 | ||
@@ -245,16 +231,10 @@ static int jz4740_ohci_remove(struct platform_device *pdev) | |||
245 | 231 | ||
246 | usb_remove_hcd(hcd); | 232 | usb_remove_hcd(hcd); |
247 | 233 | ||
248 | if (jz4740_ohci->vbus) { | 234 | if (jz4740_ohci->vbus) |
249 | regulator_disable(jz4740_ohci->vbus); | 235 | regulator_disable(jz4740_ohci->vbus); |
250 | regulator_put(jz4740_ohci->vbus); | ||
251 | } | ||
252 | 236 | ||
253 | clk_disable(jz4740_ohci->clk); | 237 | clk_disable(jz4740_ohci->clk); |
254 | clk_put(jz4740_ohci->clk); | ||
255 | |||
256 | iounmap(hcd->regs); | ||
257 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
258 | 238 | ||
259 | usb_put_hcd(hcd); | 239 | usb_put_hcd(hcd); |
260 | 240 | ||
diff --git a/drivers/usb/host/ohci-nxp.c b/drivers/usb/host/ohci-nxp.c index e99db8a6d55f..ba180ed0f81c 100644 --- a/drivers/usb/host/ohci-nxp.c +++ b/drivers/usb/host/ohci-nxp.c | |||
@@ -196,17 +196,17 @@ static int ohci_hcd_nxp_probe(struct platform_device *pdev) | |||
196 | __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL); | 196 | __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL); |
197 | 197 | ||
198 | /* Enable USB PLL */ | 198 | /* Enable USB PLL */ |
199 | usb_pll_clk = clk_get(&pdev->dev, "ck_pll5"); | 199 | usb_pll_clk = devm_clk_get(&pdev->dev, "ck_pll5"); |
200 | if (IS_ERR(usb_pll_clk)) { | 200 | if (IS_ERR(usb_pll_clk)) { |
201 | dev_err(&pdev->dev, "failed to acquire USB PLL\n"); | 201 | dev_err(&pdev->dev, "failed to acquire USB PLL\n"); |
202 | ret = PTR_ERR(usb_pll_clk); | 202 | ret = PTR_ERR(usb_pll_clk); |
203 | goto fail_pll; | 203 | goto fail_disable; |
204 | } | 204 | } |
205 | 205 | ||
206 | ret = clk_enable(usb_pll_clk); | 206 | ret = clk_enable(usb_pll_clk); |
207 | if (ret < 0) { | 207 | if (ret < 0) { |
208 | dev_err(&pdev->dev, "failed to start USB PLL\n"); | 208 | dev_err(&pdev->dev, "failed to start USB PLL\n"); |
209 | goto fail_pllen; | 209 | goto fail_disable; |
210 | } | 210 | } |
211 | 211 | ||
212 | ret = clk_set_rate(usb_pll_clk, 48000); | 212 | ret = clk_set_rate(usb_pll_clk, 48000); |
@@ -216,21 +216,21 @@ static int ohci_hcd_nxp_probe(struct platform_device *pdev) | |||
216 | } | 216 | } |
217 | 217 | ||
218 | /* Enable USB device clock */ | 218 | /* Enable USB device clock */ |
219 | usb_dev_clk = clk_get(&pdev->dev, "ck_usbd"); | 219 | usb_dev_clk = devm_clk_get(&pdev->dev, "ck_usbd"); |
220 | if (IS_ERR(usb_dev_clk)) { | 220 | if (IS_ERR(usb_dev_clk)) { |
221 | dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n"); | 221 | dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n"); |
222 | ret = PTR_ERR(usb_dev_clk); | 222 | ret = PTR_ERR(usb_dev_clk); |
223 | goto fail_dev; | 223 | goto fail_rate; |
224 | } | 224 | } |
225 | 225 | ||
226 | ret = clk_enable(usb_dev_clk); | 226 | ret = clk_enable(usb_dev_clk); |
227 | if (ret < 0) { | 227 | if (ret < 0) { |
228 | dev_err(&pdev->dev, "failed to start USB DEV Clock\n"); | 228 | dev_err(&pdev->dev, "failed to start USB DEV Clock\n"); |
229 | goto fail_deven; | 229 | goto fail_rate; |
230 | } | 230 | } |
231 | 231 | ||
232 | /* Enable USB otg clocks */ | 232 | /* Enable USB otg clocks */ |
233 | usb_otg_clk = clk_get(&pdev->dev, "ck_usb_otg"); | 233 | usb_otg_clk = devm_clk_get(&pdev->dev, "ck_usb_otg"); |
234 | if (IS_ERR(usb_otg_clk)) { | 234 | if (IS_ERR(usb_otg_clk)) { |
235 | dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n"); | 235 | dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n"); |
236 | ret = PTR_ERR(usb_otg_clk); | 236 | ret = PTR_ERR(usb_otg_clk); |
@@ -242,7 +242,7 @@ static int ohci_hcd_nxp_probe(struct platform_device *pdev) | |||
242 | ret = clk_enable(usb_otg_clk); | 242 | ret = clk_enable(usb_otg_clk); |
243 | if (ret < 0) { | 243 | if (ret < 0) { |
244 | dev_err(&pdev->dev, "failed to start USB DEV Clock\n"); | 244 | dev_err(&pdev->dev, "failed to start USB DEV Clock\n"); |
245 | goto fail_otgen; | 245 | goto fail_otg; |
246 | } | 246 | } |
247 | 247 | ||
248 | isp1301_configure(); | 248 | isp1301_configure(); |
@@ -274,26 +274,20 @@ static int ohci_hcd_nxp_probe(struct platform_device *pdev) | |||
274 | 274 | ||
275 | dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq); | 275 | dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq); |
276 | ret = usb_add_hcd(hcd, irq, 0); | 276 | ret = usb_add_hcd(hcd, irq, 0); |
277 | if (ret == 0) | 277 | if (ret == 0) { |
278 | device_wakeup_enable(hcd->self.controller); | ||
278 | return ret; | 279 | return ret; |
280 | } | ||
279 | 281 | ||
280 | ohci_nxp_stop_hc(); | 282 | ohci_nxp_stop_hc(); |
281 | fail_resource: | 283 | fail_resource: |
282 | usb_put_hcd(hcd); | 284 | usb_put_hcd(hcd); |
283 | fail_hcd: | 285 | fail_hcd: |
284 | clk_disable(usb_otg_clk); | 286 | clk_disable(usb_otg_clk); |
285 | fail_otgen: | ||
286 | clk_put(usb_otg_clk); | ||
287 | fail_otg: | 287 | fail_otg: |
288 | clk_disable(usb_dev_clk); | 288 | clk_disable(usb_dev_clk); |
289 | fail_deven: | ||
290 | clk_put(usb_dev_clk); | ||
291 | fail_dev: | ||
292 | fail_rate: | 289 | fail_rate: |
293 | clk_disable(usb_pll_clk); | 290 | clk_disable(usb_pll_clk); |
294 | fail_pllen: | ||
295 | clk_put(usb_pll_clk); | ||
296 | fail_pll: | ||
297 | fail_disable: | 291 | fail_disable: |
298 | isp1301_i2c_client = NULL; | 292 | isp1301_i2c_client = NULL; |
299 | return ret; | 293 | return ret; |
@@ -307,9 +301,7 @@ static int ohci_hcd_nxp_remove(struct platform_device *pdev) | |||
307 | ohci_nxp_stop_hc(); | 301 | ohci_nxp_stop_hc(); |
308 | usb_put_hcd(hcd); | 302 | usb_put_hcd(hcd); |
309 | clk_disable(usb_pll_clk); | 303 | clk_disable(usb_pll_clk); |
310 | clk_put(usb_pll_clk); | ||
311 | clk_disable(usb_dev_clk); | 304 | clk_disable(usb_dev_clk); |
312 | clk_put(usb_dev_clk); | ||
313 | i2c_unregister_device(isp1301_i2c_client); | 305 | i2c_unregister_device(isp1301_i2c_client); |
314 | isp1301_i2c_client = NULL; | 306 | isp1301_i2c_client = NULL; |
315 | 307 | ||
diff --git a/drivers/usb/host/ohci-octeon.c b/drivers/usb/host/ohci-octeon.c index 6c16dcef15c6..15af8954085e 100644 --- a/drivers/usb/host/ohci-octeon.c +++ b/drivers/usb/host/ohci-octeon.c | |||
@@ -138,20 +138,12 @@ static int ohci_octeon_drv_probe(struct platform_device *pdev) | |||
138 | hcd->rsrc_start = res_mem->start; | 138 | hcd->rsrc_start = res_mem->start; |
139 | hcd->rsrc_len = resource_size(res_mem); | 139 | hcd->rsrc_len = resource_size(res_mem); |
140 | 140 | ||
141 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, | 141 | reg_base = devm_ioremap_resource(&pdev->dev, res_mem); |
142 | OCTEON_OHCI_HCD_NAME)) { | 142 | if (IS_ERR(reg_base)) { |
143 | dev_err(&pdev->dev, "request_mem_region failed\n"); | 143 | ret = PTR_ERR(reg_base); |
144 | ret = -EBUSY; | ||
145 | goto err1; | 144 | goto err1; |
146 | } | 145 | } |
147 | 146 | ||
148 | reg_base = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
149 | if (!reg_base) { | ||
150 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
151 | ret = -ENOMEM; | ||
152 | goto err2; | ||
153 | } | ||
154 | |||
155 | ohci_octeon_hw_start(); | 147 | ohci_octeon_hw_start(); |
156 | 148 | ||
157 | hcd->regs = reg_base; | 149 | hcd->regs = reg_base; |
@@ -168,19 +160,18 @@ static int ohci_octeon_drv_probe(struct platform_device *pdev) | |||
168 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); | 160 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
169 | if (ret) { | 161 | if (ret) { |
170 | dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); | 162 | dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); |
171 | goto err3; | 163 | goto err2; |
172 | } | 164 | } |
173 | 165 | ||
166 | device_wakeup_enable(hcd->self.controller); | ||
167 | |||
174 | platform_set_drvdata(pdev, hcd); | 168 | platform_set_drvdata(pdev, hcd); |
175 | 169 | ||
176 | return 0; | 170 | return 0; |
177 | 171 | ||
178 | err3: | 172 | err2: |
179 | ohci_octeon_hw_stop(); | 173 | ohci_octeon_hw_stop(); |
180 | 174 | ||
181 | iounmap(hcd->regs); | ||
182 | err2: | ||
183 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
184 | err1: | 175 | err1: |
185 | usb_put_hcd(hcd); | 176 | usb_put_hcd(hcd); |
186 | return ret; | 177 | return ret; |
@@ -193,8 +184,6 @@ static int ohci_octeon_drv_remove(struct platform_device *pdev) | |||
193 | usb_remove_hcd(hcd); | 184 | usb_remove_hcd(hcd); |
194 | 185 | ||
195 | ohci_octeon_hw_stop(); | 186 | ohci_octeon_hw_stop(); |
196 | iounmap(hcd->regs); | ||
197 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
198 | usb_put_hcd(hcd); | 187 | usb_put_hcd(hcd); |
199 | 188 | ||
200 | return 0; | 189 | return 0; |
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c index f253214741ba..c923cafcaca7 100644 --- a/drivers/usb/host/ohci-omap.c +++ b/drivers/usb/host/ohci-omap.c | |||
@@ -311,14 +311,14 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver, | |||
311 | struct usb_hcd *hcd = 0; | 311 | struct usb_hcd *hcd = 0; |
312 | 312 | ||
313 | if (pdev->num_resources != 2) { | 313 | if (pdev->num_resources != 2) { |
314 | printk(KERN_ERR "hcd probe: invalid num_resources: %i\n", | 314 | dev_err(&pdev->dev, "invalid num_resources: %i\n", |
315 | pdev->num_resources); | 315 | pdev->num_resources); |
316 | return -ENODEV; | 316 | return -ENODEV; |
317 | } | 317 | } |
318 | 318 | ||
319 | if (pdev->resource[0].flags != IORESOURCE_MEM | 319 | if (pdev->resource[0].flags != IORESOURCE_MEM |
320 | || pdev->resource[1].flags != IORESOURCE_IRQ) { | 320 | || pdev->resource[1].flags != IORESOURCE_IRQ) { |
321 | printk(KERN_ERR "hcd probe: invalid resource type\n"); | 321 | dev_err(&pdev->dev, "invalid resource type\n"); |
322 | return -ENODEV; | 322 | return -ENODEV; |
323 | } | 323 | } |
324 | 324 | ||
@@ -367,6 +367,7 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver, | |||
367 | if (retval) | 367 | if (retval) |
368 | goto err3; | 368 | goto err3; |
369 | 369 | ||
370 | device_wakeup_enable(hcd->self.controller); | ||
370 | return 0; | 371 | return 0; |
371 | err3: | 372 | err3: |
372 | iounmap(hcd->regs); | 373 | iounmap(hcd->regs); |
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c index 21457417a856..ec15aebe8786 100644 --- a/drivers/usb/host/ohci-omap3.c +++ b/drivers/usb/host/ohci-omap3.c | |||
@@ -130,6 +130,7 @@ static int ohci_hcd_omap3_probe(struct platform_device *pdev) | |||
130 | dev_dbg(dev, "failed to add hcd with err %d\n", ret); | 130 | dev_dbg(dev, "failed to add hcd with err %d\n", ret); |
131 | goto err_add_hcd; | 131 | goto err_add_hcd; |
132 | } | 132 | } |
133 | device_wakeup_enable(hcd->self.controller); | ||
133 | 134 | ||
134 | return 0; | 135 | return 0; |
135 | 136 | ||
diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c index f351ff5b171f..68f674cd095f 100644 --- a/drivers/usb/host/ohci-platform.c +++ b/drivers/usb/host/ohci-platform.c | |||
@@ -108,6 +108,8 @@ static int ohci_platform_probe(struct platform_device *dev) | |||
108 | if (err) | 108 | if (err) |
109 | goto err_put_hcd; | 109 | goto err_put_hcd; |
110 | 110 | ||
111 | device_wakeup_enable(hcd->self.controller); | ||
112 | |||
111 | platform_set_drvdata(dev, hcd); | 113 | platform_set_drvdata(dev, hcd); |
112 | 114 | ||
113 | return err; | 115 | return err; |
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c index 81f3eba215c1..965e3e9e688a 100644 --- a/drivers/usb/host/ohci-ppc-of.c +++ b/drivers/usb/host/ohci-ppc-of.c | |||
@@ -115,24 +115,18 @@ static int ohci_hcd_ppc_of_probe(struct platform_device *op) | |||
115 | hcd->rsrc_start = res.start; | 115 | hcd->rsrc_start = res.start; |
116 | hcd->rsrc_len = resource_size(&res); | 116 | hcd->rsrc_len = resource_size(&res); |
117 | 117 | ||
118 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | 118 | hcd->regs = devm_ioremap_resource(&op->dev, &res); |
119 | printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__); | 119 | if (IS_ERR(hcd->regs)) { |
120 | rv = -EBUSY; | 120 | rv = PTR_ERR(hcd->regs); |
121 | goto err_rmr; | 121 | goto err_rmr; |
122 | } | 122 | } |
123 | 123 | ||
124 | irq = irq_of_parse_and_map(dn, 0); | 124 | irq = irq_of_parse_and_map(dn, 0); |
125 | if (irq == NO_IRQ) { | 125 | if (irq == NO_IRQ) { |
126 | printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__); | 126 | dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n", |
127 | __FILE__); | ||
127 | rv = -EBUSY; | 128 | rv = -EBUSY; |
128 | goto err_irq; | 129 | goto err_rmr; |
129 | } | ||
130 | |||
131 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
132 | if (!hcd->regs) { | ||
133 | printk(KERN_ERR "%s: ioremap failed\n", __FILE__); | ||
134 | rv = -ENOMEM; | ||
135 | goto err_ioremap; | ||
136 | } | 130 | } |
137 | 131 | ||
138 | ohci = hcd_to_ohci(hcd); | 132 | ohci = hcd_to_ohci(hcd); |
@@ -147,8 +141,10 @@ static int ohci_hcd_ppc_of_probe(struct platform_device *op) | |||
147 | ohci_hcd_init(ohci); | 141 | ohci_hcd_init(ohci); |
148 | 142 | ||
149 | rv = usb_add_hcd(hcd, irq, 0); | 143 | rv = usb_add_hcd(hcd, irq, 0); |
150 | if (rv == 0) | 144 | if (rv == 0) { |
145 | device_wakeup_enable(hcd->self.controller); | ||
151 | return 0; | 146 | return 0; |
147 | } | ||
152 | 148 | ||
153 | /* by now, 440epx is known to show usb_23 erratum */ | 149 | /* by now, 440epx is known to show usb_23 erratum */ |
154 | np = of_find_compatible_node(NULL, NULL, "ibm,usb-ehci-440epx"); | 150 | np = of_find_compatible_node(NULL, NULL, "ibm,usb-ehci-440epx"); |
@@ -174,11 +170,7 @@ static int ohci_hcd_ppc_of_probe(struct platform_device *op) | |||
174 | pr_debug("%s: cannot get ehci offset from fdt\n", __FILE__); | 170 | pr_debug("%s: cannot get ehci offset from fdt\n", __FILE__); |
175 | } | 171 | } |
176 | 172 | ||
177 | iounmap(hcd->regs); | ||
178 | err_ioremap: | ||
179 | irq_dispose_mapping(irq); | 173 | irq_dispose_mapping(irq); |
180 | err_irq: | ||
181 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
182 | err_rmr: | 174 | err_rmr: |
183 | usb_put_hcd(hcd); | 175 | usb_put_hcd(hcd); |
184 | 176 | ||
@@ -193,9 +185,7 @@ static int ohci_hcd_ppc_of_remove(struct platform_device *op) | |||
193 | 185 | ||
194 | usb_remove_hcd(hcd); | 186 | usb_remove_hcd(hcd); |
195 | 187 | ||
196 | iounmap(hcd->regs); | ||
197 | irq_dispose_mapping(hcd->irq); | 188 | irq_dispose_mapping(hcd->irq); |
198 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
199 | 189 | ||
200 | usb_put_hcd(hcd); | 190 | usb_put_hcd(hcd); |
201 | 191 | ||
diff --git a/drivers/usb/host/ohci-ps3.c b/drivers/usb/host/ohci-ps3.c index 7d35cd9e2862..71d8bc4c27f6 100644 --- a/drivers/usb/host/ohci-ps3.c +++ b/drivers/usb/host/ohci-ps3.c | |||
@@ -173,6 +173,7 @@ static int ps3_ohci_probe(struct ps3_system_bus_device *dev) | |||
173 | goto fail_add_hcd; | 173 | goto fail_add_hcd; |
174 | } | 174 | } |
175 | 175 | ||
176 | device_wakeup_enable(hcd->self.controller); | ||
176 | return result; | 177 | return result; |
177 | 178 | ||
178 | fail_add_hcd: | 179 | fail_add_hcd: |
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c index 9b7435f0dcd6..d21d5fefa76c 100644 --- a/drivers/usb/host/ohci-pxa27x.c +++ b/drivers/usb/host/ohci-pxa27x.c | |||
@@ -388,37 +388,28 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device | |||
388 | return -ENXIO; | 388 | return -ENXIO; |
389 | } | 389 | } |
390 | 390 | ||
391 | usb_clk = clk_get(&pdev->dev, NULL); | 391 | usb_clk = devm_clk_get(&pdev->dev, NULL); |
392 | if (IS_ERR(usb_clk)) | 392 | if (IS_ERR(usb_clk)) |
393 | return PTR_ERR(usb_clk); | 393 | return PTR_ERR(usb_clk); |
394 | 394 | ||
395 | hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x"); | 395 | hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x"); |
396 | if (!hcd) { | 396 | if (!hcd) |
397 | retval = -ENOMEM; | 397 | return -ENOMEM; |
398 | goto err0; | ||
399 | } | ||
400 | 398 | ||
401 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 399 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
402 | if (!r) { | 400 | if (!r) { |
403 | pr_err("no resource of IORESOURCE_MEM"); | 401 | pr_err("no resource of IORESOURCE_MEM"); |
404 | retval = -ENXIO; | 402 | retval = -ENXIO; |
405 | goto err1; | 403 | goto err; |
406 | } | 404 | } |
407 | 405 | ||
408 | hcd->rsrc_start = r->start; | 406 | hcd->rsrc_start = r->start; |
409 | hcd->rsrc_len = resource_size(r); | 407 | hcd->rsrc_len = resource_size(r); |
410 | 408 | ||
411 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | 409 | hcd->regs = devm_ioremap_resource(&pdev->dev, r); |
412 | pr_debug("request_mem_region failed"); | 410 | if (IS_ERR(hcd->regs)) { |
413 | retval = -EBUSY; | 411 | retval = PTR_ERR(hcd->regs); |
414 | goto err1; | 412 | goto err; |
415 | } | ||
416 | |||
417 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
418 | if (!hcd->regs) { | ||
419 | pr_debug("ioremap failed"); | ||
420 | retval = -ENOMEM; | ||
421 | goto err2; | ||
422 | } | 413 | } |
423 | 414 | ||
424 | /* initialize "struct pxa27x_ohci" */ | 415 | /* initialize "struct pxa27x_ohci" */ |
@@ -429,7 +420,7 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device | |||
429 | retval = pxa27x_start_hc(pxa_ohci, &pdev->dev); | 420 | retval = pxa27x_start_hc(pxa_ohci, &pdev->dev); |
430 | if (retval < 0) { | 421 | if (retval < 0) { |
431 | pr_debug("pxa27x_start_hc failed"); | 422 | pr_debug("pxa27x_start_hc failed"); |
432 | goto err3; | 423 | goto err; |
433 | } | 424 | } |
434 | 425 | ||
435 | /* Select Power Management Mode */ | 426 | /* Select Power Management Mode */ |
@@ -443,18 +434,14 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device | |||
443 | ohci->num_ports = 3; | 434 | ohci->num_ports = 3; |
444 | 435 | ||
445 | retval = usb_add_hcd(hcd, irq, 0); | 436 | retval = usb_add_hcd(hcd, irq, 0); |
446 | if (retval == 0) | 437 | if (retval == 0) { |
438 | device_wakeup_enable(hcd->self.controller); | ||
447 | return retval; | 439 | return retval; |
440 | } | ||
448 | 441 | ||
449 | pxa27x_stop_hc(pxa_ohci, &pdev->dev); | 442 | pxa27x_stop_hc(pxa_ohci, &pdev->dev); |
450 | err3: | 443 | err: |
451 | iounmap(hcd->regs); | ||
452 | err2: | ||
453 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
454 | err1: | ||
455 | usb_put_hcd(hcd); | 444 | usb_put_hcd(hcd); |
456 | err0: | ||
457 | clk_put(usb_clk); | ||
458 | return retval; | 445 | return retval; |
459 | } | 446 | } |
460 | 447 | ||
@@ -478,9 +465,6 @@ void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev) | |||
478 | 465 | ||
479 | usb_remove_hcd(hcd); | 466 | usb_remove_hcd(hcd); |
480 | pxa27x_stop_hc(pxa_ohci, &pdev->dev); | 467 | pxa27x_stop_hc(pxa_ohci, &pdev->dev); |
481 | iounmap(hcd->regs); | ||
482 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
483 | clk_put(pxa_ohci->clk); | ||
484 | usb_put_hcd(hcd); | 468 | usb_put_hcd(hcd); |
485 | } | 469 | } |
486 | 470 | ||
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c index e7f577e63624..d4253e319428 100644 --- a/drivers/usb/host/ohci-q.c +++ b/drivers/usb/host/ohci-q.c | |||
@@ -68,10 +68,6 @@ __acquires(ohci->lock) | |||
68 | break; | 68 | break; |
69 | } | 69 | } |
70 | 70 | ||
71 | #ifdef OHCI_VERBOSE_DEBUG | ||
72 | urb_print(urb, "RET", usb_pipeout (urb->pipe), status); | ||
73 | #endif | ||
74 | |||
75 | /* urb->complete() can reenter this HCD */ | 71 | /* urb->complete() can reenter this HCD */ |
76 | usb_hcd_unlink_urb_from_ep(ohci_to_hcd(ohci), urb); | 72 | usb_hcd_unlink_urb_from_ep(ohci_to_hcd(ohci), urb); |
77 | spin_unlock (&ohci->lock); | 73 | spin_unlock (&ohci->lock); |
@@ -147,7 +143,7 @@ static void periodic_link (struct ohci_hcd *ohci, struct ed *ed) | |||
147 | { | 143 | { |
148 | unsigned i; | 144 | unsigned i; |
149 | 145 | ||
150 | ohci_vdbg (ohci, "link %sed %p branch %d [%dus.], interval %d\n", | 146 | ohci_dbg(ohci, "link %sed %p branch %d [%dus.], interval %d\n", |
151 | (ed->hwINFO & cpu_to_hc32 (ohci, ED_ISO)) ? "iso " : "", | 147 | (ed->hwINFO & cpu_to_hc32 (ohci, ED_ISO)) ? "iso " : "", |
152 | ed, ed->branch, ed->load, ed->interval); | 148 | ed, ed->branch, ed->load, ed->interval); |
153 | 149 | ||
@@ -294,7 +290,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed) | |||
294 | } | 290 | } |
295 | ohci_to_hcd(ohci)->self.bandwidth_allocated -= ed->load / ed->interval; | 291 | ohci_to_hcd(ohci)->self.bandwidth_allocated -= ed->load / ed->interval; |
296 | 292 | ||
297 | ohci_vdbg (ohci, "unlink %sed %p branch %d [%dus.], interval %d\n", | 293 | ohci_dbg(ohci, "unlink %sed %p branch %d [%dus.], interval %d\n", |
298 | (ed->hwINFO & cpu_to_hc32 (ohci, ED_ISO)) ? "iso " : "", | 294 | (ed->hwINFO & cpu_to_hc32 (ohci, ED_ISO)) ? "iso " : "", |
299 | ed, ed->branch, ed->load, ed->interval); | 295 | ed, ed->branch, ed->load, ed->interval); |
300 | } | 296 | } |
@@ -765,7 +761,7 @@ static int td_done(struct ohci_hcd *ohci, struct urb *urb, struct td *td) | |||
765 | urb->iso_frame_desc [td->index].status = cc_to_error [cc]; | 761 | urb->iso_frame_desc [td->index].status = cc_to_error [cc]; |
766 | 762 | ||
767 | if (cc != TD_CC_NOERROR) | 763 | if (cc != TD_CC_NOERROR) |
768 | ohci_vdbg (ohci, | 764 | ohci_dbg(ohci, |
769 | "urb %p iso td %p (%d) len %d cc %d\n", | 765 | "urb %p iso td %p (%d) len %d cc %d\n", |
770 | urb, td, 1 + td->index, dlen, cc); | 766 | urb, td, 1 + td->index, dlen, cc); |
771 | 767 | ||
@@ -797,7 +793,7 @@ static int td_done(struct ohci_hcd *ohci, struct urb *urb, struct td *td) | |||
797 | } | 793 | } |
798 | 794 | ||
799 | if (cc != TD_CC_NOERROR && cc < 0x0E) | 795 | if (cc != TD_CC_NOERROR && cc < 0x0E) |
800 | ohci_vdbg (ohci, | 796 | ohci_dbg(ohci, |
801 | "urb %p td %p (%d) cc %d, len=%d/%d\n", | 797 | "urb %p td %p (%d) cc %d, len=%d/%d\n", |
802 | urb, td, 1 + td->index, cc, | 798 | urb, td, 1 + td->index, cc, |
803 | urb->actual_length, | 799 | urb->actual_length, |
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c index f90101b9cdb9..ff7c8f1c48fb 100644 --- a/drivers/usb/host/ohci-s3c2410.c +++ b/drivers/usb/host/ohci-s3c2410.c | |||
@@ -395,6 +395,7 @@ static int usb_hcd_s3c2410_probe(const struct hc_driver *driver, | |||
395 | if (retval != 0) | 395 | if (retval != 0) |
396 | goto err_ioremap; | 396 | goto err_ioremap; |
397 | 397 | ||
398 | device_wakeup_enable(hcd->self.controller); | ||
398 | return 0; | 399 | return 0; |
399 | 400 | ||
400 | err_ioremap: | 401 | err_ioremap: |
@@ -426,28 +427,15 @@ static int ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev) | |||
426 | static int ohci_hcd_s3c2410_drv_suspend(struct device *dev) | 427 | static int ohci_hcd_s3c2410_drv_suspend(struct device *dev) |
427 | { | 428 | { |
428 | struct usb_hcd *hcd = dev_get_drvdata(dev); | 429 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
429 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
430 | struct platform_device *pdev = to_platform_device(dev); | 430 | struct platform_device *pdev = to_platform_device(dev); |
431 | unsigned long flags; | 431 | bool do_wakeup = device_may_wakeup(dev); |
432 | int rc = 0; | 432 | int rc = 0; |
433 | 433 | ||
434 | /* | 434 | rc = ohci_suspend(hcd, do_wakeup); |
435 | * Root hub was already suspended. Disable irq emission and | 435 | if (rc) |
436 | * mark HW unaccessible, bail out if RH has been resumed. Use | 436 | return rc; |
437 | * the spinlock to properly synchronize with possible pending | ||
438 | * RH suspend or resume activity. | ||
439 | */ | ||
440 | spin_lock_irqsave(&ohci->lock, flags); | ||
441 | if (ohci->rh_state != OHCI_RH_SUSPENDED) { | ||
442 | rc = -EINVAL; | ||
443 | goto bail; | ||
444 | } | ||
445 | |||
446 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | ||
447 | 437 | ||
448 | s3c2410_stop_hc(pdev); | 438 | s3c2410_stop_hc(pdev); |
449 | bail: | ||
450 | spin_unlock_irqrestore(&ohci->lock, flags); | ||
451 | 439 | ||
452 | return rc; | 440 | return rc; |
453 | } | 441 | } |
diff --git a/drivers/usb/host/ohci-sa1111.c b/drivers/usb/host/ohci-sa1111.c index aa9e127bbe71..2ac266d692a2 100644 --- a/drivers/usb/host/ohci-sa1111.c +++ b/drivers/usb/host/ohci-sa1111.c | |||
@@ -211,8 +211,10 @@ static int ohci_hcd_sa1111_probe(struct sa1111_dev *dev) | |||
211 | goto err2; | 211 | goto err2; |
212 | 212 | ||
213 | ret = usb_add_hcd(hcd, dev->irq[1], 0); | 213 | ret = usb_add_hcd(hcd, dev->irq[1], 0); |
214 | if (ret == 0) | 214 | if (ret == 0) { |
215 | device_wakeup_enable(hcd->self.controller); | ||
215 | return ret; | 216 | return ret; |
217 | } | ||
216 | 218 | ||
217 | sa1111_stop_hc(dev); | 219 | sa1111_stop_hc(dev); |
218 | err2: | 220 | err2: |
diff --git a/drivers/usb/host/ohci-sm501.c b/drivers/usb/host/ohci-sm501.c index 2a5de5fecd8f..4e81c804c73e 100644 --- a/drivers/usb/host/ohci-sm501.c +++ b/drivers/usb/host/ohci-sm501.c | |||
@@ -168,6 +168,7 @@ static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev) | |||
168 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | 168 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); |
169 | if (retval) | 169 | if (retval) |
170 | goto err5; | 170 | goto err5; |
171 | device_wakeup_enable(hcd->self.controller); | ||
171 | 172 | ||
172 | /* enable power and unmask interrupts */ | 173 | /* enable power and unmask interrupts */ |
173 | 174 | ||
diff --git a/drivers/usb/host/ohci-spear.c b/drivers/usb/host/ohci-spear.c index 6b02107d281d..8b29a0c04c23 100644 --- a/drivers/usb/host/ohci-spear.c +++ b/drivers/usb/host/ohci-spear.c | |||
@@ -81,17 +81,10 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) | |||
81 | 81 | ||
82 | hcd->rsrc_start = pdev->resource[0].start; | 82 | hcd->rsrc_start = pdev->resource[0].start; |
83 | hcd->rsrc_len = resource_size(res); | 83 | hcd->rsrc_len = resource_size(res); |
84 | if (!devm_request_mem_region(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len, | ||
85 | hcd_name)) { | ||
86 | dev_dbg(&pdev->dev, "request_mem_region failed\n"); | ||
87 | retval = -EBUSY; | ||
88 | goto err_put_hcd; | ||
89 | } | ||
90 | 84 | ||
91 | hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len); | 85 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
92 | if (!hcd->regs) { | 86 | if (IS_ERR(hcd->regs)) { |
93 | dev_dbg(&pdev->dev, "ioremap failed\n"); | 87 | retval = PTR_ERR(hcd->regs); |
94 | retval = -ENOMEM; | ||
95 | goto err_put_hcd; | 88 | goto err_put_hcd; |
96 | } | 89 | } |
97 | 90 | ||
@@ -103,8 +96,10 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) | |||
103 | ohci = hcd_to_ohci(hcd); | 96 | ohci = hcd_to_ohci(hcd); |
104 | 97 | ||
105 | retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0); | 98 | retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0); |
106 | if (retval == 0) | 99 | if (retval == 0) { |
100 | device_wakeup_enable(hcd->self.controller); | ||
107 | return retval; | 101 | return retval; |
102 | } | ||
108 | 103 | ||
109 | clk_disable_unprepare(sohci_p->clk); | 104 | clk_disable_unprepare(sohci_p->clk); |
110 | err_put_hcd: | 105 | err_put_hcd: |
@@ -129,20 +124,26 @@ static int spear_ohci_hcd_drv_remove(struct platform_device *pdev) | |||
129 | } | 124 | } |
130 | 125 | ||
131 | #if defined(CONFIG_PM) | 126 | #if defined(CONFIG_PM) |
132 | static int spear_ohci_hcd_drv_suspend(struct platform_device *dev, | 127 | static int spear_ohci_hcd_drv_suspend(struct platform_device *pdev, |
133 | pm_message_t message) | 128 | pm_message_t message) |
134 | { | 129 | { |
135 | struct usb_hcd *hcd = platform_get_drvdata(dev); | 130 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
136 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 131 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
137 | struct spear_ohci *sohci_p = to_spear_ohci(hcd); | 132 | struct spear_ohci *sohci_p = to_spear_ohci(hcd); |
133 | bool do_wakeup = device_may_wakeup(&pdev->dev); | ||
134 | int ret; | ||
138 | 135 | ||
139 | if (time_before(jiffies, ohci->next_statechange)) | 136 | if (time_before(jiffies, ohci->next_statechange)) |
140 | msleep(5); | 137 | msleep(5); |
141 | ohci->next_statechange = jiffies; | 138 | ohci->next_statechange = jiffies; |
142 | 139 | ||
140 | ret = ohci_suspend(hcd, do_wakeup); | ||
141 | if (ret) | ||
142 | return ret; | ||
143 | |||
143 | clk_disable_unprepare(sohci_p->clk); | 144 | clk_disable_unprepare(sohci_p->clk); |
144 | 145 | ||
145 | return 0; | 146 | return ret; |
146 | } | 147 | } |
147 | 148 | ||
148 | static int spear_ohci_hcd_drv_resume(struct platform_device *dev) | 149 | static int spear_ohci_hcd_drv_resume(struct platform_device *dev) |
diff --git a/drivers/usb/host/ohci-tilegx.c b/drivers/usb/host/ohci-tilegx.c index 22540ab71f55..0b183e0b0a8a 100644 --- a/drivers/usb/host/ohci-tilegx.c +++ b/drivers/usb/host/ohci-tilegx.c | |||
@@ -159,6 +159,7 @@ static int ohci_hcd_tilegx_drv_probe(struct platform_device *pdev) | |||
159 | ret = usb_add_hcd(hcd, pdata->irq, IRQF_SHARED); | 159 | ret = usb_add_hcd(hcd, pdata->irq, IRQF_SHARED); |
160 | if (ret == 0) { | 160 | if (ret == 0) { |
161 | platform_set_drvdata(pdev, hcd); | 161 | platform_set_drvdata(pdev, hcd); |
162 | device_wakeup_enable(hcd->self.controller); | ||
162 | return ret; | 163 | return ret; |
163 | } | 164 | } |
164 | 165 | ||
diff --git a/drivers/usb/host/ohci-tmio.c b/drivers/usb/host/ohci-tmio.c index ecb09a5ada9c..bb409588d39c 100644 --- a/drivers/usb/host/ohci-tmio.c +++ b/drivers/usb/host/ohci-tmio.c | |||
@@ -27,7 +27,6 @@ | |||
27 | /*#include <linux/fs.h> | 27 | /*#include <linux/fs.h> |
28 | #include <linux/mount.h> | 28 | #include <linux/mount.h> |
29 | #include <linux/pagemap.h> | 29 | #include <linux/pagemap.h> |
30 | #include <linux/init.h> | ||
31 | #include <linux/namei.h> | 30 | #include <linux/namei.h> |
32 | #include <linux/sched.h>*/ | 31 | #include <linux/sched.h>*/ |
33 | #include <linux/platform_device.h> | 32 | #include <linux/platform_device.h> |
@@ -250,6 +249,7 @@ static int ohci_hcd_tmio_drv_probe(struct platform_device *dev) | |||
250 | if (ret) | 249 | if (ret) |
251 | goto err_add_hcd; | 250 | goto err_add_hcd; |
252 | 251 | ||
252 | device_wakeup_enable(hcd->self.controller); | ||
253 | if (ret == 0) | 253 | if (ret == 0) |
254 | return ret; | 254 | return ret; |
255 | 255 | ||
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h index e2e5faa5a402..9250cada13f0 100644 --- a/drivers/usb/host/ohci.h +++ b/drivers/usb/host/ohci.h | |||
@@ -415,12 +415,11 @@ struct ohci_hcd { | |||
415 | struct ed *ed_to_check; | 415 | struct ed *ed_to_check; |
416 | unsigned zf_delay; | 416 | unsigned zf_delay; |
417 | 417 | ||
418 | #ifdef DEBUG | ||
419 | struct dentry *debug_dir; | 418 | struct dentry *debug_dir; |
420 | struct dentry *debug_async; | 419 | struct dentry *debug_async; |
421 | struct dentry *debug_periodic; | 420 | struct dentry *debug_periodic; |
422 | struct dentry *debug_registers; | 421 | struct dentry *debug_registers; |
423 | #endif | 422 | |
424 | /* platform-specific data -- must come last */ | 423 | /* platform-specific data -- must come last */ |
425 | unsigned long priv[0] __aligned(sizeof(s64)); | 424 | unsigned long priv[0] __aligned(sizeof(s64)); |
426 | 425 | ||
@@ -474,10 +473,6 @@ static inline struct usb_hcd *ohci_to_hcd (const struct ohci_hcd *ohci) | |||
474 | 473 | ||
475 | /*-------------------------------------------------------------------------*/ | 474 | /*-------------------------------------------------------------------------*/ |
476 | 475 | ||
477 | #ifndef DEBUG | ||
478 | #define STUB_DEBUG_FILES | ||
479 | #endif /* DEBUG */ | ||
480 | |||
481 | #define ohci_dbg(ohci, fmt, args...) \ | 476 | #define ohci_dbg(ohci, fmt, args...) \ |
482 | dev_dbg (ohci_to_hcd(ohci)->self.controller , fmt , ## args ) | 477 | dev_dbg (ohci_to_hcd(ohci)->self.controller , fmt , ## args ) |
483 | #define ohci_err(ohci, fmt, args...) \ | 478 | #define ohci_err(ohci, fmt, args...) \ |
@@ -487,12 +482,6 @@ static inline struct usb_hcd *ohci_to_hcd (const struct ohci_hcd *ohci) | |||
487 | #define ohci_warn(ohci, fmt, args...) \ | 482 | #define ohci_warn(ohci, fmt, args...) \ |
488 | dev_warn (ohci_to_hcd(ohci)->self.controller , fmt , ## args ) | 483 | dev_warn (ohci_to_hcd(ohci)->self.controller , fmt , ## args ) |
489 | 484 | ||
490 | #ifdef OHCI_VERBOSE_DEBUG | ||
491 | # define ohci_vdbg ohci_dbg | ||
492 | #else | ||
493 | # define ohci_vdbg(ohci, fmt, args...) do { } while (0) | ||
494 | #endif | ||
495 | |||
496 | /*-------------------------------------------------------------------------*/ | 485 | /*-------------------------------------------------------------------------*/ |
497 | 486 | ||
498 | /* | 487 | /* |
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c index 4a6df2d8f902..e07248b6ab67 100644 --- a/drivers/usb/host/oxu210hp-hcd.c +++ b/drivers/usb/host/oxu210hp-hcd.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include <linux/sched.h> | 29 | #include <linux/sched.h> |
30 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
31 | #include <linux/errno.h> | 31 | #include <linux/errno.h> |
32 | #include <linux/init.h> | ||
33 | #include <linux/timer.h> | 32 | #include <linux/timer.h> |
34 | #include <linux/list.h> | 33 | #include <linux/list.h> |
35 | #include <linux/interrupt.h> | 34 | #include <linux/interrupt.h> |
@@ -60,6 +59,10 @@ | |||
60 | #define oxu_info(oxu, fmt, args...) \ | 59 | #define oxu_info(oxu, fmt, args...) \ |
61 | dev_info(oxu_to_hcd(oxu)->self.controller , fmt , ## args) | 60 | dev_info(oxu_to_hcd(oxu)->self.controller , fmt , ## args) |
62 | 61 | ||
62 | #ifdef CONFIG_DYNAMIC_DEBUG | ||
63 | #define DEBUG | ||
64 | #endif | ||
65 | |||
63 | static inline struct usb_hcd *oxu_to_hcd(struct oxu_hcd *oxu) | 66 | static inline struct usb_hcd *oxu_to_hcd(struct oxu_hcd *oxu) |
64 | { | 67 | { |
65 | return container_of((void *) oxu, struct usb_hcd, hcd_priv); | 68 | return container_of((void *) oxu, struct usb_hcd, hcd_priv); |
@@ -3747,6 +3750,7 @@ static struct usb_hcd *oxu_create(struct platform_device *pdev, | |||
3747 | if (ret < 0) | 3750 | if (ret < 0) |
3748 | return ERR_PTR(ret); | 3751 | return ERR_PTR(ret); |
3749 | 3752 | ||
3753 | device_wakeup_enable(hcd->self.controller); | ||
3750 | return hcd; | 3754 | return hcd; |
3751 | } | 3755 | } |
3752 | 3756 | ||
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c index dfbdd3aefe98..00661d305143 100644 --- a/drivers/usb/host/pci-quirks.c +++ b/drivers/usb/host/pci-quirks.c | |||
@@ -12,7 +12,6 @@ | |||
12 | #include <linux/kconfig.h> | 12 | #include <linux/kconfig.h> |
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/pci.h> | 14 | #include <linux/pci.h> |
15 | #include <linux/init.h> | ||
16 | #include <linux/delay.h> | 15 | #include <linux/delay.h> |
17 | #include <linux/export.h> | 16 | #include <linux/export.h> |
18 | #include <linux/acpi.h> | 17 | #include <linux/acpi.h> |
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c index 2ad004ae747c..110b4b9ebeaa 100644 --- a/drivers/usb/host/r8a66597-hcd.c +++ b/drivers/usb/host/r8a66597-hcd.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
28 | #include <linux/sched.h> | 28 | #include <linux/sched.h> |
29 | #include <linux/errno.h> | 29 | #include <linux/errno.h> |
30 | #include <linux/init.h> | ||
31 | #include <linux/timer.h> | 30 | #include <linux/timer.h> |
32 | #include <linux/delay.h> | 31 | #include <linux/delay.h> |
33 | #include <linux/list.h> | 32 | #include <linux/list.h> |
@@ -95,7 +94,7 @@ static int r8a66597_clock_enable(struct r8a66597 *r8a66597) | |||
95 | int i = 0; | 94 | int i = 0; |
96 | 95 | ||
97 | if (r8a66597->pdata->on_chip) { | 96 | if (r8a66597->pdata->on_chip) { |
98 | clk_enable(r8a66597->clk); | 97 | clk_prepare_enable(r8a66597->clk); |
99 | do { | 98 | do { |
100 | r8a66597_write(r8a66597, SCKE, SYSCFG0); | 99 | r8a66597_write(r8a66597, SCKE, SYSCFG0); |
101 | tmp = r8a66597_read(r8a66597, SYSCFG0); | 100 | tmp = r8a66597_read(r8a66597, SYSCFG0); |
@@ -139,7 +138,7 @@ static void r8a66597_clock_disable(struct r8a66597 *r8a66597) | |||
139 | udelay(1); | 138 | udelay(1); |
140 | 139 | ||
141 | if (r8a66597->pdata->on_chip) { | 140 | if (r8a66597->pdata->on_chip) { |
142 | clk_disable(r8a66597->clk); | 141 | clk_disable_unprepare(r8a66597->clk); |
143 | } else { | 142 | } else { |
144 | r8a66597_bclr(r8a66597, PLLC, SYSCFG0); | 143 | r8a66597_bclr(r8a66597, PLLC, SYSCFG0); |
145 | r8a66597_bclr(r8a66597, XCKE, SYSCFG0); | 144 | r8a66597_bclr(r8a66597, XCKE, SYSCFG0); |
@@ -2514,6 +2513,7 @@ static int r8a66597_probe(struct platform_device *pdev) | |||
2514 | dev_err(&pdev->dev, "Failed to add hcd\n"); | 2513 | dev_err(&pdev->dev, "Failed to add hcd\n"); |
2515 | goto clean_up3; | 2514 | goto clean_up3; |
2516 | } | 2515 | } |
2516 | device_wakeup_enable(hcd->self.controller); | ||
2517 | 2517 | ||
2518 | return 0; | 2518 | return 0; |
2519 | 2519 | ||
@@ -2534,7 +2534,7 @@ static struct platform_driver r8a66597_driver = { | |||
2534 | .probe = r8a66597_probe, | 2534 | .probe = r8a66597_probe, |
2535 | .remove = r8a66597_remove, | 2535 | .remove = r8a66597_remove, |
2536 | .driver = { | 2536 | .driver = { |
2537 | .name = (char *) hcd_name, | 2537 | .name = hcd_name, |
2538 | .owner = THIS_MODULE, | 2538 | .owner = THIS_MODULE, |
2539 | .pm = R8A66597_DEV_PM_OPS, | 2539 | .pm = R8A66597_DEV_PM_OPS, |
2540 | }, | 2540 | }, |
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index 79620c39217e..a517151867af 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c | |||
@@ -39,7 +39,6 @@ | |||
39 | #include <linux/sched.h> | 39 | #include <linux/sched.h> |
40 | #include <linux/slab.h> | 40 | #include <linux/slab.h> |
41 | #include <linux/errno.h> | 41 | #include <linux/errno.h> |
42 | #include <linux/init.h> | ||
43 | #include <linux/timer.h> | 42 | #include <linux/timer.h> |
44 | #include <linux/list.h> | 43 | #include <linux/list.h> |
45 | #include <linux/interrupt.h> | 44 | #include <linux/interrupt.h> |
@@ -1732,6 +1731,8 @@ sl811h_probe(struct platform_device *dev) | |||
1732 | if (retval != 0) | 1731 | if (retval != 0) |
1733 | goto err6; | 1732 | goto err6; |
1734 | 1733 | ||
1734 | device_wakeup_enable(hcd->self.controller); | ||
1735 | |||
1735 | create_debug_file(sl811); | 1736 | create_debug_file(sl811); |
1736 | return retval; | 1737 | return retval; |
1737 | 1738 | ||
diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c index 469564e57a52..88a9bffe93df 100644 --- a/drivers/usb/host/sl811_cs.c +++ b/drivers/usb/host/sl811_cs.c | |||
@@ -12,7 +12,6 @@ | |||
12 | 12 | ||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/init.h> | ||
16 | #include <linux/ptrace.h> | 15 | #include <linux/ptrace.h> |
17 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
18 | #include <linux/string.h> | 17 | #include <linux/string.h> |
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c index e402beb5a069..c0671750671f 100644 --- a/drivers/usb/host/u132-hcd.c +++ b/drivers/usb/host/u132-hcd.c | |||
@@ -3133,6 +3133,7 @@ static int u132_probe(struct platform_device *pdev) | |||
3133 | u132_u132_put_kref(u132); | 3133 | u132_u132_put_kref(u132); |
3134 | return retval; | 3134 | return retval; |
3135 | } else { | 3135 | } else { |
3136 | device_wakeup_enable(hcd->self.controller); | ||
3136 | u132_monitor_queue_work(u132, 100); | 3137 | u132_monitor_queue_work(u132, 100); |
3137 | return 0; | 3138 | return 0; |
3138 | } | 3139 | } |
@@ -3217,7 +3218,7 @@ static struct platform_driver u132_platform_driver = { | |||
3217 | .suspend = u132_suspend, | 3218 | .suspend = u132_suspend, |
3218 | .resume = u132_resume, | 3219 | .resume = u132_resume, |
3219 | .driver = { | 3220 | .driver = { |
3220 | .name = (char *)hcd_name, | 3221 | .name = hcd_name, |
3221 | .owner = THIS_MODULE, | 3222 | .owner = THIS_MODULE, |
3222 | }, | 3223 | }, |
3223 | }; | 3224 | }; |
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c index 8e239cdd95d5..1b28a000d5c6 100644 --- a/drivers/usb/host/uhci-debug.c +++ b/drivers/usb/host/uhci-debug.c | |||
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | static struct dentry *uhci_debugfs_root; | 21 | static struct dentry *uhci_debugfs_root; |
22 | 22 | ||
23 | #ifdef DEBUG | 23 | #ifdef CONFIG_DYNAMIC_DEBUG |
24 | 24 | ||
25 | /* Handle REALLY large printks so we don't overflow buffers */ | 25 | /* Handle REALLY large printks so we don't overflow buffers */ |
26 | static void lprintk(char *buf) | 26 | static void lprintk(char *buf) |
@@ -635,7 +635,7 @@ static const struct file_operations uhci_debug_operations = { | |||
635 | 635 | ||
636 | #endif /* CONFIG_DEBUG_FS */ | 636 | #endif /* CONFIG_DEBUG_FS */ |
637 | 637 | ||
638 | #else /* DEBUG */ | 638 | #else /* CONFIG_DYNAMIC_DEBUG*/ |
639 | 639 | ||
640 | static inline void lprintk(char *buf) | 640 | static inline void lprintk(char *buf) |
641 | {} | 641 | {} |
diff --git a/drivers/usb/host/uhci-grlib.c b/drivers/usb/host/uhci-grlib.c index 53c23ff7d685..ab25dc397e8b 100644 --- a/drivers/usb/host/uhci-grlib.c +++ b/drivers/usb/host/uhci-grlib.c | |||
@@ -141,6 +141,7 @@ static int uhci_hcd_grlib_probe(struct platform_device *op) | |||
141 | if (rv) | 141 | if (rv) |
142 | goto err_uhci; | 142 | goto err_uhci; |
143 | 143 | ||
144 | device_wakeup_enable(hcd->self.controller); | ||
144 | return 0; | 145 | return 0; |
145 | 146 | ||
146 | err_uhci: | 147 | err_uhci: |
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c index 4a86b63745b8..27f35e8f161b 100644 --- a/drivers/usb/host/uhci-hcd.c +++ b/drivers/usb/host/uhci-hcd.c | |||
@@ -69,18 +69,21 @@ MODULE_PARM_DESC(ignore_oc, "ignore hardware overcurrent indications"); | |||
69 | * show all queues in /sys/kernel/debug/uhci/[pci_addr] | 69 | * show all queues in /sys/kernel/debug/uhci/[pci_addr] |
70 | * debug = 3, show all TDs in URBs when dumping | 70 | * debug = 3, show all TDs in URBs when dumping |
71 | */ | 71 | */ |
72 | #ifdef DEBUG | 72 | #ifdef CONFIG_DYNAMIC_DEBUG |
73 | #define DEBUG_CONFIGURED 1 | 73 | |
74 | static int debug = 1; | 74 | static int debug = 1; |
75 | module_param(debug, int, S_IRUGO | S_IWUSR); | 75 | module_param(debug, int, S_IRUGO | S_IWUSR); |
76 | MODULE_PARM_DESC(debug, "Debug level"); | 76 | MODULE_PARM_DESC(debug, "Debug level"); |
77 | static char *errbuf; | ||
77 | 78 | ||
78 | #else | 79 | #else |
79 | #define DEBUG_CONFIGURED 0 | 80 | |
80 | #define debug 0 | 81 | #define debug 0 |
82 | #define errbuf NULL | ||
83 | |||
81 | #endif | 84 | #endif |
82 | 85 | ||
83 | static char *errbuf; | 86 | |
84 | #define ERRBUF_LEN (32 * 1024) | 87 | #define ERRBUF_LEN (32 * 1024) |
85 | 88 | ||
86 | static struct kmem_cache *uhci_up_cachep; /* urb_priv */ | 89 | static struct kmem_cache *uhci_up_cachep; /* urb_priv */ |
@@ -516,13 +519,12 @@ static void release_uhci(struct uhci_hcd *uhci) | |||
516 | { | 519 | { |
517 | int i; | 520 | int i; |
518 | 521 | ||
519 | if (DEBUG_CONFIGURED) { | ||
520 | spin_lock_irq(&uhci->lock); | ||
521 | uhci->is_initialized = 0; | ||
522 | spin_unlock_irq(&uhci->lock); | ||
523 | 522 | ||
524 | debugfs_remove(uhci->dentry); | 523 | spin_lock_irq(&uhci->lock); |
525 | } | 524 | uhci->is_initialized = 0; |
525 | spin_unlock_irq(&uhci->lock); | ||
526 | |||
527 | debugfs_remove(uhci->dentry); | ||
526 | 528 | ||
527 | for (i = 0; i < UHCI_NUM_SKELQH; i++) | 529 | for (i = 0; i < UHCI_NUM_SKELQH; i++) |
528 | uhci_free_qh(uhci, uhci->skelqh[i]); | 530 | uhci_free_qh(uhci, uhci->skelqh[i]); |
@@ -868,14 +870,14 @@ static int __init uhci_hcd_init(void) | |||
868 | ignore_oc ? ", overcurrent ignored" : ""); | 870 | ignore_oc ? ", overcurrent ignored" : ""); |
869 | set_bit(USB_UHCI_LOADED, &usb_hcds_loaded); | 871 | set_bit(USB_UHCI_LOADED, &usb_hcds_loaded); |
870 | 872 | ||
871 | if (DEBUG_CONFIGURED) { | 873 | #ifdef CONFIG_DYNAMIC_DEBUG |
872 | errbuf = kmalloc(ERRBUF_LEN, GFP_KERNEL); | 874 | errbuf = kmalloc(ERRBUF_LEN, GFP_KERNEL); |
873 | if (!errbuf) | 875 | if (!errbuf) |
874 | goto errbuf_failed; | 876 | goto errbuf_failed; |
875 | uhci_debugfs_root = debugfs_create_dir("uhci", usb_debug_root); | 877 | uhci_debugfs_root = debugfs_create_dir("uhci", usb_debug_root); |
876 | if (!uhci_debugfs_root) | 878 | if (!uhci_debugfs_root) |
877 | goto debug_failed; | 879 | goto debug_failed; |
878 | } | 880 | #endif |
879 | 881 | ||
880 | uhci_up_cachep = kmem_cache_create("uhci_urb_priv", | 882 | uhci_up_cachep = kmem_cache_create("uhci_urb_priv", |
881 | sizeof(struct urb_priv), 0, 0, NULL); | 883 | sizeof(struct urb_priv), 0, 0, NULL); |
@@ -906,12 +908,14 @@ clean0: | |||
906 | kmem_cache_destroy(uhci_up_cachep); | 908 | kmem_cache_destroy(uhci_up_cachep); |
907 | 909 | ||
908 | up_failed: | 910 | up_failed: |
911 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) | ||
909 | debugfs_remove(uhci_debugfs_root); | 912 | debugfs_remove(uhci_debugfs_root); |
910 | 913 | ||
911 | debug_failed: | 914 | debug_failed: |
912 | kfree(errbuf); | 915 | kfree(errbuf); |
913 | 916 | ||
914 | errbuf_failed: | 917 | errbuf_failed: |
918 | #endif | ||
915 | 919 | ||
916 | clear_bit(USB_UHCI_LOADED, &usb_hcds_loaded); | 920 | clear_bit(USB_UHCI_LOADED, &usb_hcds_loaded); |
917 | return retval; | 921 | return retval; |
@@ -927,7 +931,9 @@ static void __exit uhci_hcd_cleanup(void) | |||
927 | #endif | 931 | #endif |
928 | kmem_cache_destroy(uhci_up_cachep); | 932 | kmem_cache_destroy(uhci_up_cachep); |
929 | debugfs_remove(uhci_debugfs_root); | 933 | debugfs_remove(uhci_debugfs_root); |
934 | #ifdef CONFIG_DYNAMIC_DEBUG | ||
930 | kfree(errbuf); | 935 | kfree(errbuf); |
936 | #endif | ||
931 | clear_bit(USB_UHCI_LOADED, &usb_hcds_loaded); | 937 | clear_bit(USB_UHCI_LOADED, &usb_hcds_loaded); |
932 | } | 938 | } |
933 | 939 | ||
diff --git a/drivers/usb/host/uhci-pci.c b/drivers/usb/host/uhci-pci.c index 4cd79888804b..940304c33224 100644 --- a/drivers/usb/host/uhci-pci.c +++ b/drivers/usb/host/uhci-pci.c | |||
@@ -279,7 +279,7 @@ static const struct hc_driver uhci_driver = { | |||
279 | .hub_control = uhci_hub_control, | 279 | .hub_control = uhci_hub_control, |
280 | }; | 280 | }; |
281 | 281 | ||
282 | static DEFINE_PCI_DEVICE_TABLE(uhci_pci_ids) = { { | 282 | static const struct pci_device_id uhci_pci_ids[] = { { |
283 | /* handle any USB UHCI controller */ | 283 | /* handle any USB UHCI controller */ |
284 | PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0), | 284 | PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0), |
285 | .driver_data = (unsigned long) &uhci_driver, | 285 | .driver_data = (unsigned long) &uhci_driver, |
diff --git a/drivers/usb/host/uhci-platform.c b/drivers/usb/host/uhci-platform.c index 3003fefaa964..44e6c9da8892 100644 --- a/drivers/usb/host/uhci-platform.c +++ b/drivers/usb/host/uhci-platform.c | |||
@@ -108,6 +108,7 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev) | |||
108 | if (ret) | 108 | if (ret) |
109 | goto err_uhci; | 109 | goto err_uhci; |
110 | 110 | ||
111 | device_wakeup_enable(hcd->self.controller); | ||
111 | return 0; | 112 | return 0; |
112 | 113 | ||
113 | err_uhci: | 114 | err_uhci: |
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c index 1b0888f8da9a..d7b363a418de 100644 --- a/drivers/usb/host/whci/hcd.c +++ b/drivers/usb/host/whci/hcd.c | |||
@@ -293,6 +293,7 @@ static int whc_probe(struct umc_dev *umc) | |||
293 | dev_err(dev, "cannot add HCD: %d\n", ret); | 293 | dev_err(dev, "cannot add HCD: %d\n", ret); |
294 | goto error_usb_add_hcd; | 294 | goto error_usb_add_hcd; |
295 | } | 295 | } |
296 | device_wakeup_enable(usb_hcd->self.controller); | ||
296 | 297 | ||
297 | ret = wusbhc_b_create(wusbhc); | 298 | ret = wusbhc_b_create(wusbhc); |
298 | if (ret) { | 299 | if (ret) { |
diff --git a/drivers/usb/host/whci/int.c b/drivers/usb/host/whci/int.c index 6aae70028101..0c086b2790d1 100644 --- a/drivers/usb/host/whci/int.c +++ b/drivers/usb/host/whci/int.c | |||
@@ -16,7 +16,6 @@ | |||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | */ | 17 | */ |
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/init.h> | ||
20 | #include <linux/uwb/umc.h> | 19 | #include <linux/uwb/umc.h> |
21 | 20 | ||
22 | #include "../../wusbcore/wusbhc.h" | 21 | #include "../../wusbcore/wusbhc.h" |
diff --git a/drivers/usb/host/whci/wusb.c b/drivers/usb/host/whci/wusb.c index f24efdebad17..8d2762682869 100644 --- a/drivers/usb/host/whci/wusb.c +++ b/drivers/usb/host/whci/wusb.c | |||
@@ -16,7 +16,6 @@ | |||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | */ | 17 | */ |
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/init.h> | ||
20 | #include <linux/uwb/umc.h> | 19 | #include <linux/uwb/umc.h> |
21 | 20 | ||
22 | #include "../../wusbcore/wusbhc.h" | 21 | #include "../../wusbcore/wusbhc.h" |
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c index 73503a81ee81..b016d38199f2 100644 --- a/drivers/usb/host/xhci-dbg.c +++ b/drivers/usb/host/xhci-dbg.c | |||
@@ -32,7 +32,7 @@ void xhci_dbg_regs(struct xhci_hcd *xhci) | |||
32 | 32 | ||
33 | xhci_dbg(xhci, "// xHCI capability registers at %p:\n", | 33 | xhci_dbg(xhci, "// xHCI capability registers at %p:\n", |
34 | xhci->cap_regs); | 34 | xhci->cap_regs); |
35 | temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase); | 35 | temp = readl(&xhci->cap_regs->hc_capbase); |
36 | xhci_dbg(xhci, "// @%p = 0x%x (CAPLENGTH AND HCIVERSION)\n", | 36 | xhci_dbg(xhci, "// @%p = 0x%x (CAPLENGTH AND HCIVERSION)\n", |
37 | &xhci->cap_regs->hc_capbase, temp); | 37 | &xhci->cap_regs->hc_capbase, temp); |
38 | xhci_dbg(xhci, "// CAPLENGTH: 0x%x\n", | 38 | xhci_dbg(xhci, "// CAPLENGTH: 0x%x\n", |
@@ -44,13 +44,13 @@ void xhci_dbg_regs(struct xhci_hcd *xhci) | |||
44 | 44 | ||
45 | xhci_dbg(xhci, "// xHCI operational registers at %p:\n", xhci->op_regs); | 45 | xhci_dbg(xhci, "// xHCI operational registers at %p:\n", xhci->op_regs); |
46 | 46 | ||
47 | temp = xhci_readl(xhci, &xhci->cap_regs->run_regs_off); | 47 | temp = readl(&xhci->cap_regs->run_regs_off); |
48 | xhci_dbg(xhci, "// @%p = 0x%x RTSOFF\n", | 48 | xhci_dbg(xhci, "// @%p = 0x%x RTSOFF\n", |
49 | &xhci->cap_regs->run_regs_off, | 49 | &xhci->cap_regs->run_regs_off, |
50 | (unsigned int) temp & RTSOFF_MASK); | 50 | (unsigned int) temp & RTSOFF_MASK); |
51 | xhci_dbg(xhci, "// xHCI runtime registers at %p:\n", xhci->run_regs); | 51 | xhci_dbg(xhci, "// xHCI runtime registers at %p:\n", xhci->run_regs); |
52 | 52 | ||
53 | temp = xhci_readl(xhci, &xhci->cap_regs->db_off); | 53 | temp = readl(&xhci->cap_regs->db_off); |
54 | xhci_dbg(xhci, "// @%p = 0x%x DBOFF\n", &xhci->cap_regs->db_off, temp); | 54 | xhci_dbg(xhci, "// @%p = 0x%x DBOFF\n", &xhci->cap_regs->db_off, temp); |
55 | xhci_dbg(xhci, "// Doorbell array at %p:\n", xhci->dba); | 55 | xhci_dbg(xhci, "// Doorbell array at %p:\n", xhci->dba); |
56 | } | 56 | } |
@@ -61,7 +61,7 @@ static void xhci_print_cap_regs(struct xhci_hcd *xhci) | |||
61 | 61 | ||
62 | xhci_dbg(xhci, "xHCI capability registers at %p:\n", xhci->cap_regs); | 62 | xhci_dbg(xhci, "xHCI capability registers at %p:\n", xhci->cap_regs); |
63 | 63 | ||
64 | temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase); | 64 | temp = readl(&xhci->cap_regs->hc_capbase); |
65 | xhci_dbg(xhci, "CAPLENGTH AND HCIVERSION 0x%x:\n", | 65 | xhci_dbg(xhci, "CAPLENGTH AND HCIVERSION 0x%x:\n", |
66 | (unsigned int) temp); | 66 | (unsigned int) temp); |
67 | xhci_dbg(xhci, "CAPLENGTH: 0x%x\n", | 67 | xhci_dbg(xhci, "CAPLENGTH: 0x%x\n", |
@@ -69,7 +69,7 @@ static void xhci_print_cap_regs(struct xhci_hcd *xhci) | |||
69 | xhci_dbg(xhci, "HCIVERSION: 0x%x\n", | 69 | xhci_dbg(xhci, "HCIVERSION: 0x%x\n", |
70 | (unsigned int) HC_VERSION(temp)); | 70 | (unsigned int) HC_VERSION(temp)); |
71 | 71 | ||
72 | temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params1); | 72 | temp = readl(&xhci->cap_regs->hcs_params1); |
73 | xhci_dbg(xhci, "HCSPARAMS 1: 0x%x\n", | 73 | xhci_dbg(xhci, "HCSPARAMS 1: 0x%x\n", |
74 | (unsigned int) temp); | 74 | (unsigned int) temp); |
75 | xhci_dbg(xhci, " Max device slots: %u\n", | 75 | xhci_dbg(xhci, " Max device slots: %u\n", |
@@ -79,7 +79,7 @@ static void xhci_print_cap_regs(struct xhci_hcd *xhci) | |||
79 | xhci_dbg(xhci, " Max ports: %u\n", | 79 | xhci_dbg(xhci, " Max ports: %u\n", |
80 | (unsigned int) HCS_MAX_PORTS(temp)); | 80 | (unsigned int) HCS_MAX_PORTS(temp)); |
81 | 81 | ||
82 | temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params2); | 82 | temp = readl(&xhci->cap_regs->hcs_params2); |
83 | xhci_dbg(xhci, "HCSPARAMS 2: 0x%x\n", | 83 | xhci_dbg(xhci, "HCSPARAMS 2: 0x%x\n", |
84 | (unsigned int) temp); | 84 | (unsigned int) temp); |
85 | xhci_dbg(xhci, " Isoc scheduling threshold: %u\n", | 85 | xhci_dbg(xhci, " Isoc scheduling threshold: %u\n", |
@@ -87,7 +87,7 @@ static void xhci_print_cap_regs(struct xhci_hcd *xhci) | |||
87 | xhci_dbg(xhci, " Maximum allowed segments in event ring: %u\n", | 87 | xhci_dbg(xhci, " Maximum allowed segments in event ring: %u\n", |
88 | (unsigned int) HCS_ERST_MAX(temp)); | 88 | (unsigned int) HCS_ERST_MAX(temp)); |
89 | 89 | ||
90 | temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params3); | 90 | temp = readl(&xhci->cap_regs->hcs_params3); |
91 | xhci_dbg(xhci, "HCSPARAMS 3 0x%x:\n", | 91 | xhci_dbg(xhci, "HCSPARAMS 3 0x%x:\n", |
92 | (unsigned int) temp); | 92 | (unsigned int) temp); |
93 | xhci_dbg(xhci, " Worst case U1 device exit latency: %u\n", | 93 | xhci_dbg(xhci, " Worst case U1 device exit latency: %u\n", |
@@ -95,14 +95,14 @@ static void xhci_print_cap_regs(struct xhci_hcd *xhci) | |||
95 | xhci_dbg(xhci, " Worst case U2 device exit latency: %u\n", | 95 | xhci_dbg(xhci, " Worst case U2 device exit latency: %u\n", |
96 | (unsigned int) HCS_U2_LATENCY(temp)); | 96 | (unsigned int) HCS_U2_LATENCY(temp)); |
97 | 97 | ||
98 | temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); | 98 | temp = readl(&xhci->cap_regs->hcc_params); |
99 | xhci_dbg(xhci, "HCC PARAMS 0x%x:\n", (unsigned int) temp); | 99 | xhci_dbg(xhci, "HCC PARAMS 0x%x:\n", (unsigned int) temp); |
100 | xhci_dbg(xhci, " HC generates %s bit addresses\n", | 100 | xhci_dbg(xhci, " HC generates %s bit addresses\n", |
101 | HCC_64BIT_ADDR(temp) ? "64" : "32"); | 101 | HCC_64BIT_ADDR(temp) ? "64" : "32"); |
102 | /* FIXME */ | 102 | /* FIXME */ |
103 | xhci_dbg(xhci, " FIXME: more HCCPARAMS debugging\n"); | 103 | xhci_dbg(xhci, " FIXME: more HCCPARAMS debugging\n"); |
104 | 104 | ||
105 | temp = xhci_readl(xhci, &xhci->cap_regs->run_regs_off); | 105 | temp = readl(&xhci->cap_regs->run_regs_off); |
106 | xhci_dbg(xhci, "RTSOFF 0x%x:\n", temp & RTSOFF_MASK); | 106 | xhci_dbg(xhci, "RTSOFF 0x%x:\n", temp & RTSOFF_MASK); |
107 | } | 107 | } |
108 | 108 | ||
@@ -110,7 +110,7 @@ static void xhci_print_command_reg(struct xhci_hcd *xhci) | |||
110 | { | 110 | { |
111 | u32 temp; | 111 | u32 temp; |
112 | 112 | ||
113 | temp = xhci_readl(xhci, &xhci->op_regs->command); | 113 | temp = readl(&xhci->op_regs->command); |
114 | xhci_dbg(xhci, "USBCMD 0x%x:\n", temp); | 114 | xhci_dbg(xhci, "USBCMD 0x%x:\n", temp); |
115 | xhci_dbg(xhci, " HC is %s\n", | 115 | xhci_dbg(xhci, " HC is %s\n", |
116 | (temp & CMD_RUN) ? "running" : "being stopped"); | 116 | (temp & CMD_RUN) ? "running" : "being stopped"); |
@@ -128,7 +128,7 @@ static void xhci_print_status(struct xhci_hcd *xhci) | |||
128 | { | 128 | { |
129 | u32 temp; | 129 | u32 temp; |
130 | 130 | ||
131 | temp = xhci_readl(xhci, &xhci->op_regs->status); | 131 | temp = readl(&xhci->op_regs->status); |
132 | xhci_dbg(xhci, "USBSTS 0x%x:\n", temp); | 132 | xhci_dbg(xhci, "USBSTS 0x%x:\n", temp); |
133 | xhci_dbg(xhci, " Event ring is %sempty\n", | 133 | xhci_dbg(xhci, " Event ring is %sempty\n", |
134 | (temp & STS_EINT) ? "not " : ""); | 134 | (temp & STS_EINT) ? "not " : ""); |
@@ -163,7 +163,7 @@ static void xhci_print_ports(struct xhci_hcd *xhci) | |||
163 | for (j = 0; j < NUM_PORT_REGS; ++j) { | 163 | for (j = 0; j < NUM_PORT_REGS; ++j) { |
164 | xhci_dbg(xhci, "%p port %s reg = 0x%x\n", | 164 | xhci_dbg(xhci, "%p port %s reg = 0x%x\n", |
165 | addr, names[j], | 165 | addr, names[j], |
166 | (unsigned int) xhci_readl(xhci, addr)); | 166 | (unsigned int) readl(addr)); |
167 | addr++; | 167 | addr++; |
168 | } | 168 | } |
169 | } | 169 | } |
@@ -177,7 +177,7 @@ void xhci_print_ir_set(struct xhci_hcd *xhci, int set_num) | |||
177 | u64 temp_64; | 177 | u64 temp_64; |
178 | 178 | ||
179 | addr = &ir_set->irq_pending; | 179 | addr = &ir_set->irq_pending; |
180 | temp = xhci_readl(xhci, addr); | 180 | temp = readl(addr); |
181 | if (temp == XHCI_INIT_VALUE) | 181 | if (temp == XHCI_INIT_VALUE) |
182 | return; | 182 | return; |
183 | 183 | ||
@@ -187,28 +187,28 @@ void xhci_print_ir_set(struct xhci_hcd *xhci, int set_num) | |||
187 | (unsigned int)temp); | 187 | (unsigned int)temp); |
188 | 188 | ||
189 | addr = &ir_set->irq_control; | 189 | addr = &ir_set->irq_control; |
190 | temp = xhci_readl(xhci, addr); | 190 | temp = readl(addr); |
191 | xhci_dbg(xhci, " %p: ir_set.control = 0x%x\n", addr, | 191 | xhci_dbg(xhci, " %p: ir_set.control = 0x%x\n", addr, |
192 | (unsigned int)temp); | 192 | (unsigned int)temp); |
193 | 193 | ||
194 | addr = &ir_set->erst_size; | 194 | addr = &ir_set->erst_size; |
195 | temp = xhci_readl(xhci, addr); | 195 | temp = readl(addr); |
196 | xhci_dbg(xhci, " %p: ir_set.erst_size = 0x%x\n", addr, | 196 | xhci_dbg(xhci, " %p: ir_set.erst_size = 0x%x\n", addr, |
197 | (unsigned int)temp); | 197 | (unsigned int)temp); |
198 | 198 | ||
199 | addr = &ir_set->rsvd; | 199 | addr = &ir_set->rsvd; |
200 | temp = xhci_readl(xhci, addr); | 200 | temp = readl(addr); |
201 | if (temp != XHCI_INIT_VALUE) | 201 | if (temp != XHCI_INIT_VALUE) |
202 | xhci_dbg(xhci, " WARN: %p: ir_set.rsvd = 0x%x\n", | 202 | xhci_dbg(xhci, " WARN: %p: ir_set.rsvd = 0x%x\n", |
203 | addr, (unsigned int)temp); | 203 | addr, (unsigned int)temp); |
204 | 204 | ||
205 | addr = &ir_set->erst_base; | 205 | addr = &ir_set->erst_base; |
206 | temp_64 = xhci_read_64(xhci, addr); | 206 | temp_64 = readq(addr); |
207 | xhci_dbg(xhci, " %p: ir_set.erst_base = @%08llx\n", | 207 | xhci_dbg(xhci, " %p: ir_set.erst_base = @%08llx\n", |
208 | addr, temp_64); | 208 | addr, temp_64); |
209 | 209 | ||
210 | addr = &ir_set->erst_dequeue; | 210 | addr = &ir_set->erst_dequeue; |
211 | temp_64 = xhci_read_64(xhci, addr); | 211 | temp_64 = readq(addr); |
212 | xhci_dbg(xhci, " %p: ir_set.erst_dequeue = @%08llx\n", | 212 | xhci_dbg(xhci, " %p: ir_set.erst_dequeue = @%08llx\n", |
213 | addr, temp_64); | 213 | addr, temp_64); |
214 | } | 214 | } |
@@ -219,12 +219,12 @@ void xhci_print_run_regs(struct xhci_hcd *xhci) | |||
219 | int i; | 219 | int i; |
220 | 220 | ||
221 | xhci_dbg(xhci, "xHCI runtime registers at %p:\n", xhci->run_regs); | 221 | xhci_dbg(xhci, "xHCI runtime registers at %p:\n", xhci->run_regs); |
222 | temp = xhci_readl(xhci, &xhci->run_regs->microframe_index); | 222 | temp = readl(&xhci->run_regs->microframe_index); |
223 | xhci_dbg(xhci, " %p: Microframe index = 0x%x\n", | 223 | xhci_dbg(xhci, " %p: Microframe index = 0x%x\n", |
224 | &xhci->run_regs->microframe_index, | 224 | &xhci->run_regs->microframe_index, |
225 | (unsigned int) temp); | 225 | (unsigned int) temp); |
226 | for (i = 0; i < 7; ++i) { | 226 | for (i = 0; i < 7; ++i) { |
227 | temp = xhci_readl(xhci, &xhci->run_regs->rsvd[i]); | 227 | temp = readl(&xhci->run_regs->rsvd[i]); |
228 | if (temp != XHCI_INIT_VALUE) | 228 | if (temp != XHCI_INIT_VALUE) |
229 | xhci_dbg(xhci, " WARN: %p: Rsvd[%i] = 0x%x\n", | 229 | xhci_dbg(xhci, " WARN: %p: Rsvd[%i] = 0x%x\n", |
230 | &xhci->run_regs->rsvd[i], | 230 | &xhci->run_regs->rsvd[i], |
@@ -412,7 +412,7 @@ void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci) | |||
412 | { | 412 | { |
413 | u64 val; | 413 | u64 val; |
414 | 414 | ||
415 | val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); | 415 | val = readq(&xhci->op_regs->cmd_ring); |
416 | xhci_dbg(xhci, "// xHC command ring deq ptr low bits + flags = @%08x\n", | 416 | xhci_dbg(xhci, "// xHC command ring deq ptr low bits + flags = @%08x\n", |
417 | lower_32_bits(val)); | 417 | lower_32_bits(val)); |
418 | xhci_dbg(xhci, "// xHC command ring deq ptr high bits = @%08x\n", | 418 | xhci_dbg(xhci, "// xHC command ring deq ptr high bits = @%08x\n", |
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 805f2348eeba..9992fbfec85f 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c | |||
@@ -94,7 +94,7 @@ static void xhci_usb2_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, | |||
94 | */ | 94 | */ |
95 | memset(port_removable, 0, sizeof(port_removable)); | 95 | memset(port_removable, 0, sizeof(port_removable)); |
96 | for (i = 0; i < ports; i++) { | 96 | for (i = 0; i < ports; i++) { |
97 | portsc = xhci_readl(xhci, xhci->usb2_ports[i]); | 97 | portsc = readl(xhci->usb2_ports[i]); |
98 | /* If a device is removable, PORTSC reports a 0, same as in the | 98 | /* If a device is removable, PORTSC reports a 0, same as in the |
99 | * hub descriptor DeviceRemovable bits. | 99 | * hub descriptor DeviceRemovable bits. |
100 | */ | 100 | */ |
@@ -148,7 +148,7 @@ static void xhci_usb3_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, | |||
148 | port_removable = 0; | 148 | port_removable = 0; |
149 | /* bit 0 is reserved, bit 1 is for port 1, etc. */ | 149 | /* bit 0 is reserved, bit 1 is for port 1, etc. */ |
150 | for (i = 0; i < ports; i++) { | 150 | for (i = 0; i < ports; i++) { |
151 | portsc = xhci_readl(xhci, xhci->usb3_ports[i]); | 151 | portsc = readl(xhci->usb3_ports[i]); |
152 | if (portsc & PORT_DEV_REMOVE) | 152 | if (portsc & PORT_DEV_REMOVE) |
153 | port_removable |= 1 << (i + 1); | 153 | port_removable |= 1 << (i + 1); |
154 | } | 154 | } |
@@ -342,8 +342,8 @@ static void xhci_disable_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, | |||
342 | } | 342 | } |
343 | 343 | ||
344 | /* Write 1 to disable the port */ | 344 | /* Write 1 to disable the port */ |
345 | xhci_writel(xhci, port_status | PORT_PE, addr); | 345 | writel(port_status | PORT_PE, addr); |
346 | port_status = xhci_readl(xhci, addr); | 346 | port_status = readl(addr); |
347 | xhci_dbg(xhci, "disable port, actual port %d status = 0x%x\n", | 347 | xhci_dbg(xhci, "disable port, actual port %d status = 0x%x\n", |
348 | wIndex, port_status); | 348 | wIndex, port_status); |
349 | } | 349 | } |
@@ -388,8 +388,8 @@ static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue, | |||
388 | return; | 388 | return; |
389 | } | 389 | } |
390 | /* Change bits are all write 1 to clear */ | 390 | /* Change bits are all write 1 to clear */ |
391 | xhci_writel(xhci, port_status | status, addr); | 391 | writel(port_status | status, addr); |
392 | port_status = xhci_readl(xhci, addr); | 392 | port_status = readl(addr); |
393 | xhci_dbg(xhci, "clear port %s change, actual port %d status = 0x%x\n", | 393 | xhci_dbg(xhci, "clear port %s change, actual port %d status = 0x%x\n", |
394 | port_change_bit, wIndex, port_status); | 394 | port_change_bit, wIndex, port_status); |
395 | } | 395 | } |
@@ -415,11 +415,11 @@ void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array, | |||
415 | { | 415 | { |
416 | u32 temp; | 416 | u32 temp; |
417 | 417 | ||
418 | temp = xhci_readl(xhci, port_array[port_id]); | 418 | temp = readl(port_array[port_id]); |
419 | temp = xhci_port_state_to_neutral(temp); | 419 | temp = xhci_port_state_to_neutral(temp); |
420 | temp &= ~PORT_PLS_MASK; | 420 | temp &= ~PORT_PLS_MASK; |
421 | temp |= PORT_LINK_STROBE | link_state; | 421 | temp |= PORT_LINK_STROBE | link_state; |
422 | xhci_writel(xhci, temp, port_array[port_id]); | 422 | writel(temp, port_array[port_id]); |
423 | } | 423 | } |
424 | 424 | ||
425 | static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci, | 425 | static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci, |
@@ -427,7 +427,7 @@ static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci, | |||
427 | { | 427 | { |
428 | u32 temp; | 428 | u32 temp; |
429 | 429 | ||
430 | temp = xhci_readl(xhci, port_array[port_id]); | 430 | temp = readl(port_array[port_id]); |
431 | temp = xhci_port_state_to_neutral(temp); | 431 | temp = xhci_port_state_to_neutral(temp); |
432 | 432 | ||
433 | if (wake_mask & USB_PORT_FEAT_REMOTE_WAKE_CONNECT) | 433 | if (wake_mask & USB_PORT_FEAT_REMOTE_WAKE_CONNECT) |
@@ -445,7 +445,7 @@ static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci, | |||
445 | else | 445 | else |
446 | temp &= ~PORT_WKOC_E; | 446 | temp &= ~PORT_WKOC_E; |
447 | 447 | ||
448 | xhci_writel(xhci, temp, port_array[port_id]); | 448 | writel(temp, port_array[port_id]); |
449 | } | 449 | } |
450 | 450 | ||
451 | /* Test and clear port RWC bit */ | 451 | /* Test and clear port RWC bit */ |
@@ -454,11 +454,11 @@ void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array, | |||
454 | { | 454 | { |
455 | u32 temp; | 455 | u32 temp; |
456 | 456 | ||
457 | temp = xhci_readl(xhci, port_array[port_id]); | 457 | temp = readl(port_array[port_id]); |
458 | if (temp & port_bit) { | 458 | if (temp & port_bit) { |
459 | temp = xhci_port_state_to_neutral(temp); | 459 | temp = xhci_port_state_to_neutral(temp); |
460 | temp |= port_bit; | 460 | temp |= port_bit; |
461 | xhci_writel(xhci, temp, port_array[port_id]); | 461 | writel(temp, port_array[port_id]); |
462 | } | 462 | } |
463 | } | 463 | } |
464 | 464 | ||
@@ -623,8 +623,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd, | |||
623 | } | 623 | } |
624 | xhci_ring_device(xhci, slot_id); | 624 | xhci_ring_device(xhci, slot_id); |
625 | } else { | 625 | } else { |
626 | int port_status = xhci_readl(xhci, | 626 | int port_status = readl(port_array[wIndex]); |
627 | port_array[wIndex]); | ||
628 | xhci_warn(xhci, "Port resume took longer than %i msec, port status = 0x%x\n", | 627 | xhci_warn(xhci, "Port resume took longer than %i msec, port status = 0x%x\n", |
629 | XHCI_MAX_REXIT_TIMEOUT, | 628 | XHCI_MAX_REXIT_TIMEOUT, |
630 | port_status); | 629 | port_status); |
@@ -733,12 +732,12 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
733 | /* Set the U1 and U2 exit latencies. */ | 732 | /* Set the U1 and U2 exit latencies. */ |
734 | memcpy(buf, &usb_bos_descriptor, | 733 | memcpy(buf, &usb_bos_descriptor, |
735 | USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE); | 734 | USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE); |
736 | temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params3); | 735 | temp = readl(&xhci->cap_regs->hcs_params3); |
737 | buf[12] = HCS_U1_LATENCY(temp); | 736 | buf[12] = HCS_U1_LATENCY(temp); |
738 | put_unaligned_le16(HCS_U2_LATENCY(temp), &buf[13]); | 737 | put_unaligned_le16(HCS_U2_LATENCY(temp), &buf[13]); |
739 | 738 | ||
740 | /* Indicate whether the host has LTM support. */ | 739 | /* Indicate whether the host has LTM support. */ |
741 | temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); | 740 | temp = readl(&xhci->cap_regs->hcc_params); |
742 | if (HCC_LTC(temp)) | 741 | if (HCC_LTC(temp)) |
743 | buf[8] |= USB_LTM_SUPPORT; | 742 | buf[8] |= USB_LTM_SUPPORT; |
744 | 743 | ||
@@ -748,7 +747,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
748 | if (!wIndex || wIndex > max_ports) | 747 | if (!wIndex || wIndex > max_ports) |
749 | goto error; | 748 | goto error; |
750 | wIndex--; | 749 | wIndex--; |
751 | temp = xhci_readl(xhci, port_array[wIndex]); | 750 | temp = readl(port_array[wIndex]); |
752 | if (temp == 0xffffffff) { | 751 | if (temp == 0xffffffff) { |
753 | retval = -ENODEV; | 752 | retval = -ENODEV; |
754 | break; | 753 | break; |
@@ -775,7 +774,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
775 | if (!wIndex || wIndex > max_ports) | 774 | if (!wIndex || wIndex > max_ports) |
776 | goto error; | 775 | goto error; |
777 | wIndex--; | 776 | wIndex--; |
778 | temp = xhci_readl(xhci, port_array[wIndex]); | 777 | temp = readl(port_array[wIndex]); |
779 | if (temp == 0xffffffff) { | 778 | if (temp == 0xffffffff) { |
780 | retval = -ENODEV; | 779 | retval = -ENODEV; |
781 | break; | 780 | break; |
@@ -784,7 +783,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
784 | /* FIXME: What new port features do we need to support? */ | 783 | /* FIXME: What new port features do we need to support? */ |
785 | switch (wValue) { | 784 | switch (wValue) { |
786 | case USB_PORT_FEAT_SUSPEND: | 785 | case USB_PORT_FEAT_SUSPEND: |
787 | temp = xhci_readl(xhci, port_array[wIndex]); | 786 | temp = readl(port_array[wIndex]); |
788 | if ((temp & PORT_PLS_MASK) != XDEV_U0) { | 787 | if ((temp & PORT_PLS_MASK) != XDEV_U0) { |
789 | /* Resume the port to U0 first */ | 788 | /* Resume the port to U0 first */ |
790 | xhci_set_link_state(xhci, port_array, wIndex, | 789 | xhci_set_link_state(xhci, port_array, wIndex, |
@@ -797,7 +796,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
797 | * a port unless the port reports that it is in the | 796 | * a port unless the port reports that it is in the |
798 | * enabled (PED = ‘1’,PLS < ‘3’) state. | 797 | * enabled (PED = ‘1’,PLS < ‘3’) state. |
799 | */ | 798 | */ |
800 | temp = xhci_readl(xhci, port_array[wIndex]); | 799 | temp = readl(port_array[wIndex]); |
801 | if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) | 800 | if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) |
802 | || (temp & PORT_PLS_MASK) >= XDEV_U3) { | 801 | || (temp & PORT_PLS_MASK) >= XDEV_U3) { |
803 | xhci_warn(xhci, "USB core suspending device " | 802 | xhci_warn(xhci, "USB core suspending device " |
@@ -822,11 +821,11 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
822 | msleep(10); /* wait device to enter */ | 821 | msleep(10); /* wait device to enter */ |
823 | spin_lock_irqsave(&xhci->lock, flags); | 822 | spin_lock_irqsave(&xhci->lock, flags); |
824 | 823 | ||
825 | temp = xhci_readl(xhci, port_array[wIndex]); | 824 | temp = readl(port_array[wIndex]); |
826 | bus_state->suspended_ports |= 1 << wIndex; | 825 | bus_state->suspended_ports |= 1 << wIndex; |
827 | break; | 826 | break; |
828 | case USB_PORT_FEAT_LINK_STATE: | 827 | case USB_PORT_FEAT_LINK_STATE: |
829 | temp = xhci_readl(xhci, port_array[wIndex]); | 828 | temp = readl(port_array[wIndex]); |
830 | 829 | ||
831 | /* Disable port */ | 830 | /* Disable port */ |
832 | if (link_state == USB_SS_PORT_LS_SS_DISABLED) { | 831 | if (link_state == USB_SS_PORT_LS_SS_DISABLED) { |
@@ -839,9 +838,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
839 | temp |= PORT_CSC | PORT_PEC | PORT_WRC | | 838 | temp |= PORT_CSC | PORT_PEC | PORT_WRC | |
840 | PORT_OCC | PORT_RC | PORT_PLC | | 839 | PORT_OCC | PORT_RC | PORT_PLC | |
841 | PORT_CEC; | 840 | PORT_CEC; |
842 | xhci_writel(xhci, temp | PORT_PE, | 841 | writel(temp | PORT_PE, port_array[wIndex]); |
843 | port_array[wIndex]); | 842 | temp = readl(port_array[wIndex]); |
844 | temp = xhci_readl(xhci, port_array[wIndex]); | ||
845 | break; | 843 | break; |
846 | } | 844 | } |
847 | 845 | ||
@@ -850,7 +848,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
850 | xhci_dbg(xhci, "Enable port %d\n", wIndex); | 848 | xhci_dbg(xhci, "Enable port %d\n", wIndex); |
851 | xhci_set_link_state(xhci, port_array, wIndex, | 849 | xhci_set_link_state(xhci, port_array, wIndex, |
852 | link_state); | 850 | link_state); |
853 | temp = xhci_readl(xhci, port_array[wIndex]); | 851 | temp = readl(port_array[wIndex]); |
854 | break; | 852 | break; |
855 | } | 853 | } |
856 | 854 | ||
@@ -884,7 +882,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
884 | msleep(20); /* wait device to enter */ | 882 | msleep(20); /* wait device to enter */ |
885 | spin_lock_irqsave(&xhci->lock, flags); | 883 | spin_lock_irqsave(&xhci->lock, flags); |
886 | 884 | ||
887 | temp = xhci_readl(xhci, port_array[wIndex]); | 885 | temp = readl(port_array[wIndex]); |
888 | if (link_state == USB_SS_PORT_LS_U3) | 886 | if (link_state == USB_SS_PORT_LS_U3) |
889 | bus_state->suspended_ports |= 1 << wIndex; | 887 | bus_state->suspended_ports |= 1 << wIndex; |
890 | break; | 888 | break; |
@@ -895,10 +893,9 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
895 | * However, khubd will ignore the roothub events until | 893 | * However, khubd will ignore the roothub events until |
896 | * the roothub is registered. | 894 | * the roothub is registered. |
897 | */ | 895 | */ |
898 | xhci_writel(xhci, temp | PORT_POWER, | 896 | writel(temp | PORT_POWER, port_array[wIndex]); |
899 | port_array[wIndex]); | ||
900 | 897 | ||
901 | temp = xhci_readl(xhci, port_array[wIndex]); | 898 | temp = readl(port_array[wIndex]); |
902 | xhci_dbg(xhci, "set port power, actual port %d status = 0x%x\n", wIndex, temp); | 899 | xhci_dbg(xhci, "set port power, actual port %d status = 0x%x\n", wIndex, temp); |
903 | 900 | ||
904 | spin_unlock_irqrestore(&xhci->lock, flags); | 901 | spin_unlock_irqrestore(&xhci->lock, flags); |
@@ -911,52 +908,52 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
911 | break; | 908 | break; |
912 | case USB_PORT_FEAT_RESET: | 909 | case USB_PORT_FEAT_RESET: |
913 | temp = (temp | PORT_RESET); | 910 | temp = (temp | PORT_RESET); |
914 | xhci_writel(xhci, temp, port_array[wIndex]); | 911 | writel(temp, port_array[wIndex]); |
915 | 912 | ||
916 | temp = xhci_readl(xhci, port_array[wIndex]); | 913 | temp = readl(port_array[wIndex]); |
917 | xhci_dbg(xhci, "set port reset, actual port %d status = 0x%x\n", wIndex, temp); | 914 | xhci_dbg(xhci, "set port reset, actual port %d status = 0x%x\n", wIndex, temp); |
918 | break; | 915 | break; |
919 | case USB_PORT_FEAT_REMOTE_WAKE_MASK: | 916 | case USB_PORT_FEAT_REMOTE_WAKE_MASK: |
920 | xhci_set_remote_wake_mask(xhci, port_array, | 917 | xhci_set_remote_wake_mask(xhci, port_array, |
921 | wIndex, wake_mask); | 918 | wIndex, wake_mask); |
922 | temp = xhci_readl(xhci, port_array[wIndex]); | 919 | temp = readl(port_array[wIndex]); |
923 | xhci_dbg(xhci, "set port remote wake mask, " | 920 | xhci_dbg(xhci, "set port remote wake mask, " |
924 | "actual port %d status = 0x%x\n", | 921 | "actual port %d status = 0x%x\n", |
925 | wIndex, temp); | 922 | wIndex, temp); |
926 | break; | 923 | break; |
927 | case USB_PORT_FEAT_BH_PORT_RESET: | 924 | case USB_PORT_FEAT_BH_PORT_RESET: |
928 | temp |= PORT_WR; | 925 | temp |= PORT_WR; |
929 | xhci_writel(xhci, temp, port_array[wIndex]); | 926 | writel(temp, port_array[wIndex]); |
930 | 927 | ||
931 | temp = xhci_readl(xhci, port_array[wIndex]); | 928 | temp = readl(port_array[wIndex]); |
932 | break; | 929 | break; |
933 | case USB_PORT_FEAT_U1_TIMEOUT: | 930 | case USB_PORT_FEAT_U1_TIMEOUT: |
934 | if (hcd->speed != HCD_USB3) | 931 | if (hcd->speed != HCD_USB3) |
935 | goto error; | 932 | goto error; |
936 | temp = xhci_readl(xhci, port_array[wIndex] + PORTPMSC); | 933 | temp = readl(port_array[wIndex] + PORTPMSC); |
937 | temp &= ~PORT_U1_TIMEOUT_MASK; | 934 | temp &= ~PORT_U1_TIMEOUT_MASK; |
938 | temp |= PORT_U1_TIMEOUT(timeout); | 935 | temp |= PORT_U1_TIMEOUT(timeout); |
939 | xhci_writel(xhci, temp, port_array[wIndex] + PORTPMSC); | 936 | writel(temp, port_array[wIndex] + PORTPMSC); |
940 | break; | 937 | break; |
941 | case USB_PORT_FEAT_U2_TIMEOUT: | 938 | case USB_PORT_FEAT_U2_TIMEOUT: |
942 | if (hcd->speed != HCD_USB3) | 939 | if (hcd->speed != HCD_USB3) |
943 | goto error; | 940 | goto error; |
944 | temp = xhci_readl(xhci, port_array[wIndex] + PORTPMSC); | 941 | temp = readl(port_array[wIndex] + PORTPMSC); |
945 | temp &= ~PORT_U2_TIMEOUT_MASK; | 942 | temp &= ~PORT_U2_TIMEOUT_MASK; |
946 | temp |= PORT_U2_TIMEOUT(timeout); | 943 | temp |= PORT_U2_TIMEOUT(timeout); |
947 | xhci_writel(xhci, temp, port_array[wIndex] + PORTPMSC); | 944 | writel(temp, port_array[wIndex] + PORTPMSC); |
948 | break; | 945 | break; |
949 | default: | 946 | default: |
950 | goto error; | 947 | goto error; |
951 | } | 948 | } |
952 | /* unblock any posted writes */ | 949 | /* unblock any posted writes */ |
953 | temp = xhci_readl(xhci, port_array[wIndex]); | 950 | temp = readl(port_array[wIndex]); |
954 | break; | 951 | break; |
955 | case ClearPortFeature: | 952 | case ClearPortFeature: |
956 | if (!wIndex || wIndex > max_ports) | 953 | if (!wIndex || wIndex > max_ports) |
957 | goto error; | 954 | goto error; |
958 | wIndex--; | 955 | wIndex--; |
959 | temp = xhci_readl(xhci, port_array[wIndex]); | 956 | temp = readl(port_array[wIndex]); |
960 | if (temp == 0xffffffff) { | 957 | if (temp == 0xffffffff) { |
961 | retval = -ENODEV; | 958 | retval = -ENODEV; |
962 | break; | 959 | break; |
@@ -965,7 +962,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
965 | temp = xhci_port_state_to_neutral(temp); | 962 | temp = xhci_port_state_to_neutral(temp); |
966 | switch (wValue) { | 963 | switch (wValue) { |
967 | case USB_PORT_FEAT_SUSPEND: | 964 | case USB_PORT_FEAT_SUSPEND: |
968 | temp = xhci_readl(xhci, port_array[wIndex]); | 965 | temp = readl(port_array[wIndex]); |
969 | xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n"); | 966 | xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n"); |
970 | xhci_dbg(xhci, "PORTSC %04x\n", temp); | 967 | xhci_dbg(xhci, "PORTSC %04x\n", temp); |
971 | if (temp & PORT_RESET) | 968 | if (temp & PORT_RESET) |
@@ -1008,8 +1005,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
1008 | port_array[wIndex], temp); | 1005 | port_array[wIndex], temp); |
1009 | break; | 1006 | break; |
1010 | case USB_PORT_FEAT_POWER: | 1007 | case USB_PORT_FEAT_POWER: |
1011 | xhci_writel(xhci, temp & ~PORT_POWER, | 1008 | writel(temp & ~PORT_POWER, port_array[wIndex]); |
1012 | port_array[wIndex]); | ||
1013 | 1009 | ||
1014 | spin_unlock_irqrestore(&xhci->lock, flags); | 1010 | spin_unlock_irqrestore(&xhci->lock, flags); |
1015 | temp = usb_acpi_power_manageable(hcd->self.root_hub, | 1011 | temp = usb_acpi_power_manageable(hcd->self.root_hub, |
@@ -1070,7 +1066,7 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
1070 | spin_lock_irqsave(&xhci->lock, flags); | 1066 | spin_lock_irqsave(&xhci->lock, flags); |
1071 | /* For each port, did anything change? If so, set that bit in buf. */ | 1067 | /* For each port, did anything change? If so, set that bit in buf. */ |
1072 | for (i = 0; i < max_ports; i++) { | 1068 | for (i = 0; i < max_ports; i++) { |
1073 | temp = xhci_readl(xhci, port_array[i]); | 1069 | temp = readl(port_array[i]); |
1074 | if (temp == 0xffffffff) { | 1070 | if (temp == 0xffffffff) { |
1075 | retval = -ENODEV; | 1071 | retval = -ENODEV; |
1076 | break; | 1072 | break; |
@@ -1124,7 +1120,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd) | |||
1124 | u32 t1, t2; | 1120 | u32 t1, t2; |
1125 | int slot_id; | 1121 | int slot_id; |
1126 | 1122 | ||
1127 | t1 = xhci_readl(xhci, port_array[port_index]); | 1123 | t1 = readl(port_array[port_index]); |
1128 | t2 = xhci_port_state_to_neutral(t1); | 1124 | t2 = xhci_port_state_to_neutral(t1); |
1129 | 1125 | ||
1130 | if ((t1 & PORT_PE) && !(t1 & PORT_PLS_MASK)) { | 1126 | if ((t1 & PORT_PE) && !(t1 & PORT_PLS_MASK)) { |
@@ -1157,7 +1153,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd) | |||
1157 | 1153 | ||
1158 | t1 = xhci_port_state_to_neutral(t1); | 1154 | t1 = xhci_port_state_to_neutral(t1); |
1159 | if (t1 != t2) | 1155 | if (t1 != t2) |
1160 | xhci_writel(xhci, t2, port_array[port_index]); | 1156 | writel(t2, port_array[port_index]); |
1161 | } | 1157 | } |
1162 | hcd->state = HC_STATE_SUSPENDED; | 1158 | hcd->state = HC_STATE_SUSPENDED; |
1163 | bus_state->next_statechange = jiffies + msecs_to_jiffies(10); | 1159 | bus_state->next_statechange = jiffies + msecs_to_jiffies(10); |
@@ -1187,9 +1183,9 @@ int xhci_bus_resume(struct usb_hcd *hcd) | |||
1187 | } | 1183 | } |
1188 | 1184 | ||
1189 | /* delay the irqs */ | 1185 | /* delay the irqs */ |
1190 | temp = xhci_readl(xhci, &xhci->op_regs->command); | 1186 | temp = readl(&xhci->op_regs->command); |
1191 | temp &= ~CMD_EIE; | 1187 | temp &= ~CMD_EIE; |
1192 | xhci_writel(xhci, temp, &xhci->op_regs->command); | 1188 | writel(temp, &xhci->op_regs->command); |
1193 | 1189 | ||
1194 | port_index = max_ports; | 1190 | port_index = max_ports; |
1195 | while (port_index--) { | 1191 | while (port_index--) { |
@@ -1198,7 +1194,7 @@ int xhci_bus_resume(struct usb_hcd *hcd) | |||
1198 | u32 temp; | 1194 | u32 temp; |
1199 | int slot_id; | 1195 | int slot_id; |
1200 | 1196 | ||
1201 | temp = xhci_readl(xhci, port_array[port_index]); | 1197 | temp = readl(port_array[port_index]); |
1202 | if (DEV_SUPERSPEED(temp)) | 1198 | if (DEV_SUPERSPEED(temp)) |
1203 | temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); | 1199 | temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); |
1204 | else | 1200 | else |
@@ -1235,17 +1231,17 @@ int xhci_bus_resume(struct usb_hcd *hcd) | |||
1235 | if (slot_id) | 1231 | if (slot_id) |
1236 | xhci_ring_device(xhci, slot_id); | 1232 | xhci_ring_device(xhci, slot_id); |
1237 | } else | 1233 | } else |
1238 | xhci_writel(xhci, temp, port_array[port_index]); | 1234 | writel(temp, port_array[port_index]); |
1239 | } | 1235 | } |
1240 | 1236 | ||
1241 | (void) xhci_readl(xhci, &xhci->op_regs->command); | 1237 | (void) readl(&xhci->op_regs->command); |
1242 | 1238 | ||
1243 | bus_state->next_statechange = jiffies + msecs_to_jiffies(5); | 1239 | bus_state->next_statechange = jiffies + msecs_to_jiffies(5); |
1244 | /* re-enable irqs */ | 1240 | /* re-enable irqs */ |
1245 | temp = xhci_readl(xhci, &xhci->op_regs->command); | 1241 | temp = readl(&xhci->op_regs->command); |
1246 | temp |= CMD_EIE; | 1242 | temp |= CMD_EIE; |
1247 | xhci_writel(xhci, temp, &xhci->op_regs->command); | 1243 | writel(temp, &xhci->op_regs->command); |
1248 | temp = xhci_readl(xhci, &xhci->op_regs->command); | 1244 | temp = readl(&xhci->op_regs->command); |
1249 | 1245 | ||
1250 | spin_unlock_irqrestore(&xhci->lock, flags); | 1246 | spin_unlock_irqrestore(&xhci->lock, flags); |
1251 | return 0; | 1247 | return 0; |
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 49b8bd063fab..873c272b3ef5 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c | |||
@@ -57,7 +57,7 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci, | |||
57 | /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */ | 57 | /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */ |
58 | if (cycle_state == 0) { | 58 | if (cycle_state == 0) { |
59 | for (i = 0; i < TRBS_PER_SEGMENT; i++) | 59 | for (i = 0; i < TRBS_PER_SEGMENT; i++) |
60 | seg->trbs[i].link.control |= TRB_CYCLE; | 60 | seg->trbs[i].link.control |= cpu_to_le32(TRB_CYCLE); |
61 | } | 61 | } |
62 | seg->dma = dma; | 62 | seg->dma = dma; |
63 | seg->next = NULL; | 63 | seg->next = NULL; |
@@ -308,7 +308,8 @@ static void xhci_reinit_cached_ring(struct xhci_hcd *xhci, | |||
308 | sizeof(union xhci_trb)*TRBS_PER_SEGMENT); | 308 | sizeof(union xhci_trb)*TRBS_PER_SEGMENT); |
309 | if (cycle_state == 0) { | 309 | if (cycle_state == 0) { |
310 | for (i = 0; i < TRBS_PER_SEGMENT; i++) | 310 | for (i = 0; i < TRBS_PER_SEGMENT; i++) |
311 | seg->trbs[i].link.control |= TRB_CYCLE; | 311 | seg->trbs[i].link.control |= |
312 | cpu_to_le32(TRB_CYCLE); | ||
312 | } | 313 | } |
313 | /* All endpoint rings have link TRBs */ | 314 | /* All endpoint rings have link TRBs */ |
314 | xhci_link_segments(xhci, seg, seg->next, type); | 315 | xhci_link_segments(xhci, seg, seg->next, type); |
@@ -432,10 +433,10 @@ static void xhci_free_stream_ctx(struct xhci_hcd *xhci, | |||
432 | unsigned int num_stream_ctxs, | 433 | unsigned int num_stream_ctxs, |
433 | struct xhci_stream_ctx *stream_ctx, dma_addr_t dma) | 434 | struct xhci_stream_ctx *stream_ctx, dma_addr_t dma) |
434 | { | 435 | { |
435 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | 436 | struct device *dev = xhci_to_hcd(xhci)->self.controller; |
436 | 437 | ||
437 | if (num_stream_ctxs > MEDIUM_STREAM_ARRAY_SIZE) | 438 | if (num_stream_ctxs > MEDIUM_STREAM_ARRAY_SIZE) |
438 | dma_free_coherent(&pdev->dev, | 439 | dma_free_coherent(dev, |
439 | sizeof(struct xhci_stream_ctx)*num_stream_ctxs, | 440 | sizeof(struct xhci_stream_ctx)*num_stream_ctxs, |
440 | stream_ctx, dma); | 441 | stream_ctx, dma); |
441 | else if (num_stream_ctxs <= SMALL_STREAM_ARRAY_SIZE) | 442 | else if (num_stream_ctxs <= SMALL_STREAM_ARRAY_SIZE) |
@@ -460,10 +461,10 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci, | |||
460 | unsigned int num_stream_ctxs, dma_addr_t *dma, | 461 | unsigned int num_stream_ctxs, dma_addr_t *dma, |
461 | gfp_t mem_flags) | 462 | gfp_t mem_flags) |
462 | { | 463 | { |
463 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | 464 | struct device *dev = xhci_to_hcd(xhci)->self.controller; |
464 | 465 | ||
465 | if (num_stream_ctxs > MEDIUM_STREAM_ARRAY_SIZE) | 466 | if (num_stream_ctxs > MEDIUM_STREAM_ARRAY_SIZE) |
466 | return dma_alloc_coherent(&pdev->dev, | 467 | return dma_alloc_coherent(dev, |
467 | sizeof(struct xhci_stream_ctx)*num_stream_ctxs, | 468 | sizeof(struct xhci_stream_ctx)*num_stream_ctxs, |
468 | dma, mem_flags); | 469 | dma, mem_flags); |
469 | else if (num_stream_ctxs <= SMALL_STREAM_ARRAY_SIZE) | 470 | else if (num_stream_ctxs <= SMALL_STREAM_ARRAY_SIZE) |
@@ -721,8 +722,7 @@ void xhci_free_stream_info(struct xhci_hcd *xhci, | |||
721 | stream_info->stream_ctx_array, | 722 | stream_info->stream_ctx_array, |
722 | stream_info->ctx_array_dma); | 723 | stream_info->ctx_array_dma); |
723 | 724 | ||
724 | if (stream_info) | 725 | kfree(stream_info->stream_rings); |
725 | kfree(stream_info->stream_rings); | ||
726 | kfree(stream_info); | 726 | kfree(stream_info); |
727 | } | 727 | } |
728 | 728 | ||
@@ -1616,7 +1616,7 @@ static void scratchpad_free(struct xhci_hcd *xhci) | |||
1616 | { | 1616 | { |
1617 | int num_sp; | 1617 | int num_sp; |
1618 | int i; | 1618 | int i; |
1619 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | 1619 | struct device *dev = xhci_to_hcd(xhci)->self.controller; |
1620 | 1620 | ||
1621 | if (!xhci->scratchpad) | 1621 | if (!xhci->scratchpad) |
1622 | return; | 1622 | return; |
@@ -1624,13 +1624,13 @@ static void scratchpad_free(struct xhci_hcd *xhci) | |||
1624 | num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); | 1624 | num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); |
1625 | 1625 | ||
1626 | for (i = 0; i < num_sp; i++) { | 1626 | for (i = 0; i < num_sp; i++) { |
1627 | dma_free_coherent(&pdev->dev, xhci->page_size, | 1627 | dma_free_coherent(dev, xhci->page_size, |
1628 | xhci->scratchpad->sp_buffers[i], | 1628 | xhci->scratchpad->sp_buffers[i], |
1629 | xhci->scratchpad->sp_dma_buffers[i]); | 1629 | xhci->scratchpad->sp_dma_buffers[i]); |
1630 | } | 1630 | } |
1631 | kfree(xhci->scratchpad->sp_dma_buffers); | 1631 | kfree(xhci->scratchpad->sp_dma_buffers); |
1632 | kfree(xhci->scratchpad->sp_buffers); | 1632 | kfree(xhci->scratchpad->sp_buffers); |
1633 | dma_free_coherent(&pdev->dev, num_sp * sizeof(u64), | 1633 | dma_free_coherent(dev, num_sp * sizeof(u64), |
1634 | xhci->scratchpad->sp_array, | 1634 | xhci->scratchpad->sp_array, |
1635 | xhci->scratchpad->sp_dma); | 1635 | xhci->scratchpad->sp_dma); |
1636 | kfree(xhci->scratchpad); | 1636 | kfree(xhci->scratchpad); |
@@ -1692,7 +1692,7 @@ void xhci_free_command(struct xhci_hcd *xhci, | |||
1692 | 1692 | ||
1693 | void xhci_mem_cleanup(struct xhci_hcd *xhci) | 1693 | void xhci_mem_cleanup(struct xhci_hcd *xhci) |
1694 | { | 1694 | { |
1695 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | 1695 | struct device *dev = xhci_to_hcd(xhci)->self.controller; |
1696 | struct xhci_cd *cur_cd, *next_cd; | 1696 | struct xhci_cd *cur_cd, *next_cd; |
1697 | int size; | 1697 | int size; |
1698 | int i, j, num_ports; | 1698 | int i, j, num_ports; |
@@ -1700,7 +1700,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) | |||
1700 | /* Free the Event Ring Segment Table and the actual Event Ring */ | 1700 | /* Free the Event Ring Segment Table and the actual Event Ring */ |
1701 | size = sizeof(struct xhci_erst_entry)*(xhci->erst.num_entries); | 1701 | size = sizeof(struct xhci_erst_entry)*(xhci->erst.num_entries); |
1702 | if (xhci->erst.entries) | 1702 | if (xhci->erst.entries) |
1703 | dma_free_coherent(&pdev->dev, size, | 1703 | dma_free_coherent(dev, size, |
1704 | xhci->erst.entries, xhci->erst.erst_dma_addr); | 1704 | xhci->erst.entries, xhci->erst.erst_dma_addr); |
1705 | xhci->erst.entries = NULL; | 1705 | xhci->erst.entries = NULL; |
1706 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed ERST"); | 1706 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed ERST"); |
@@ -1748,7 +1748,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) | |||
1748 | "Freed medium stream array pool"); | 1748 | "Freed medium stream array pool"); |
1749 | 1749 | ||
1750 | if (xhci->dcbaa) | 1750 | if (xhci->dcbaa) |
1751 | dma_free_coherent(&pdev->dev, sizeof(*xhci->dcbaa), | 1751 | dma_free_coherent(dev, sizeof(*xhci->dcbaa), |
1752 | xhci->dcbaa, xhci->dcbaa->dma); | 1752 | xhci->dcbaa, xhci->dcbaa->dma); |
1753 | xhci->dcbaa = NULL; | 1753 | xhci->dcbaa = NULL; |
1754 | 1754 | ||
@@ -1958,7 +1958,7 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci) | |||
1958 | xhci_warn(xhci, "WARN something wrong with SW event ring " | 1958 | xhci_warn(xhci, "WARN something wrong with SW event ring " |
1959 | "dequeue ptr.\n"); | 1959 | "dequeue ptr.\n"); |
1960 | /* Update HC event ring dequeue pointer */ | 1960 | /* Update HC event ring dequeue pointer */ |
1961 | temp = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); | 1961 | temp = readq(&xhci->ir_set->erst_dequeue); |
1962 | temp &= ERST_PTR_MASK; | 1962 | temp &= ERST_PTR_MASK; |
1963 | /* Don't clear the EHB bit (which is RW1C) because | 1963 | /* Don't clear the EHB bit (which is RW1C) because |
1964 | * there might be more events to service. | 1964 | * there might be more events to service. |
@@ -1967,7 +1967,7 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci) | |||
1967 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 1967 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
1968 | "// Write event ring dequeue pointer, " | 1968 | "// Write event ring dequeue pointer, " |
1969 | "preserving EHB bit"); | 1969 | "preserving EHB bit"); |
1970 | xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp, | 1970 | writeq(((u64) deq & (u64) ~ERST_PTR_MASK) | temp, |
1971 | &xhci->ir_set->erst_dequeue); | 1971 | &xhci->ir_set->erst_dequeue); |
1972 | } | 1972 | } |
1973 | 1973 | ||
@@ -1986,7 +1986,7 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports, | |||
1986 | } | 1986 | } |
1987 | 1987 | ||
1988 | /* Port offset and count in the third dword, see section 7.2 */ | 1988 | /* Port offset and count in the third dword, see section 7.2 */ |
1989 | temp = xhci_readl(xhci, addr + 2); | 1989 | temp = readl(addr + 2); |
1990 | port_offset = XHCI_EXT_PORT_OFF(temp); | 1990 | port_offset = XHCI_EXT_PORT_OFF(temp); |
1991 | port_count = XHCI_EXT_PORT_COUNT(temp); | 1991 | port_count = XHCI_EXT_PORT_COUNT(temp); |
1992 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 1992 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
@@ -2069,7 +2069,7 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) | |||
2069 | int cap_count = 0; | 2069 | int cap_count = 0; |
2070 | 2070 | ||
2071 | addr = &xhci->cap_regs->hcc_params; | 2071 | addr = &xhci->cap_regs->hcc_params; |
2072 | offset = XHCI_HCC_EXT_CAPS(xhci_readl(xhci, addr)); | 2072 | offset = XHCI_HCC_EXT_CAPS(readl(addr)); |
2073 | if (offset == 0) { | 2073 | if (offset == 0) { |
2074 | xhci_err(xhci, "No Extended Capability registers, " | 2074 | xhci_err(xhci, "No Extended Capability registers, " |
2075 | "unable to set up roothub.\n"); | 2075 | "unable to set up roothub.\n"); |
@@ -2106,7 +2106,7 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) | |||
2106 | /* count extended protocol capability entries for later caching */ | 2106 | /* count extended protocol capability entries for later caching */ |
2107 | do { | 2107 | do { |
2108 | u32 cap_id; | 2108 | u32 cap_id; |
2109 | cap_id = xhci_readl(xhci, tmp_addr); | 2109 | cap_id = readl(tmp_addr); |
2110 | if (XHCI_EXT_CAPS_ID(cap_id) == XHCI_EXT_CAPS_PROTOCOL) | 2110 | if (XHCI_EXT_CAPS_ID(cap_id) == XHCI_EXT_CAPS_PROTOCOL) |
2111 | cap_count++; | 2111 | cap_count++; |
2112 | tmp_offset = XHCI_EXT_CAPS_NEXT(cap_id); | 2112 | tmp_offset = XHCI_EXT_CAPS_NEXT(cap_id); |
@@ -2120,7 +2120,7 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) | |||
2120 | while (1) { | 2120 | while (1) { |
2121 | u32 cap_id; | 2121 | u32 cap_id; |
2122 | 2122 | ||
2123 | cap_id = xhci_readl(xhci, addr); | 2123 | cap_id = readl(addr); |
2124 | if (XHCI_EXT_CAPS_ID(cap_id) == XHCI_EXT_CAPS_PROTOCOL) | 2124 | if (XHCI_EXT_CAPS_ID(cap_id) == XHCI_EXT_CAPS_PROTOCOL) |
2125 | xhci_add_in_port(xhci, num_ports, addr, | 2125 | xhci_add_in_port(xhci, num_ports, addr, |
2126 | (u8) XHCI_EXT_PORT_MAJOR(cap_id), | 2126 | (u8) XHCI_EXT_PORT_MAJOR(cap_id), |
@@ -2224,7 +2224,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
2224 | 2224 | ||
2225 | INIT_LIST_HEAD(&xhci->cancel_cmd_list); | 2225 | INIT_LIST_HEAD(&xhci->cancel_cmd_list); |
2226 | 2226 | ||
2227 | page_size = xhci_readl(xhci, &xhci->op_regs->page_size); | 2227 | page_size = readl(&xhci->op_regs->page_size); |
2228 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 2228 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
2229 | "Supported page size register = 0x%x", page_size); | 2229 | "Supported page size register = 0x%x", page_size); |
2230 | for (i = 0; i < 16; i++) { | 2230 | for (i = 0; i < 16; i++) { |
@@ -2247,14 +2247,14 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
2247 | * Program the Number of Device Slots Enabled field in the CONFIG | 2247 | * Program the Number of Device Slots Enabled field in the CONFIG |
2248 | * register with the max value of slots the HC can handle. | 2248 | * register with the max value of slots the HC can handle. |
2249 | */ | 2249 | */ |
2250 | val = HCS_MAX_SLOTS(xhci_readl(xhci, &xhci->cap_regs->hcs_params1)); | 2250 | val = HCS_MAX_SLOTS(readl(&xhci->cap_regs->hcs_params1)); |
2251 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 2251 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
2252 | "// xHC can handle at most %d device slots.", val); | 2252 | "// xHC can handle at most %d device slots.", val); |
2253 | val2 = xhci_readl(xhci, &xhci->op_regs->config_reg); | 2253 | val2 = readl(&xhci->op_regs->config_reg); |
2254 | val |= (val2 & ~HCS_SLOTS_MASK); | 2254 | val |= (val2 & ~HCS_SLOTS_MASK); |
2255 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 2255 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
2256 | "// Setting Max device slots reg = 0x%x.", val); | 2256 | "// Setting Max device slots reg = 0x%x.", val); |
2257 | xhci_writel(xhci, val, &xhci->op_regs->config_reg); | 2257 | writel(val, &xhci->op_regs->config_reg); |
2258 | 2258 | ||
2259 | /* | 2259 | /* |
2260 | * Section 5.4.8 - doorbell array must be | 2260 | * Section 5.4.8 - doorbell array must be |
@@ -2269,7 +2269,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
2269 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 2269 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
2270 | "// Device context base array address = 0x%llx (DMA), %p (virt)", | 2270 | "// Device context base array address = 0x%llx (DMA), %p (virt)", |
2271 | (unsigned long long)xhci->dcbaa->dma, xhci->dcbaa); | 2271 | (unsigned long long)xhci->dcbaa->dma, xhci->dcbaa); |
2272 | xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr); | 2272 | writeq(dma, &xhci->op_regs->dcbaa_ptr); |
2273 | 2273 | ||
2274 | /* | 2274 | /* |
2275 | * Initialize the ring segment pool. The ring must be a contiguous | 2275 | * Initialize the ring segment pool. The ring must be a contiguous |
@@ -2312,13 +2312,13 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
2312 | (unsigned long long)xhci->cmd_ring->first_seg->dma); | 2312 | (unsigned long long)xhci->cmd_ring->first_seg->dma); |
2313 | 2313 | ||
2314 | /* Set the address in the Command Ring Control register */ | 2314 | /* Set the address in the Command Ring Control register */ |
2315 | val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); | 2315 | val_64 = readq(&xhci->op_regs->cmd_ring); |
2316 | val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | | 2316 | val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | |
2317 | (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) | | 2317 | (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) | |
2318 | xhci->cmd_ring->cycle_state; | 2318 | xhci->cmd_ring->cycle_state; |
2319 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 2319 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
2320 | "// Setting command ring address to 0x%x", val); | 2320 | "// Setting command ring address to 0x%x", val); |
2321 | xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); | 2321 | writeq(val_64, &xhci->op_regs->cmd_ring); |
2322 | xhci_dbg_cmd_ptrs(xhci); | 2322 | xhci_dbg_cmd_ptrs(xhci); |
2323 | 2323 | ||
2324 | xhci->lpm_command = xhci_alloc_command(xhci, true, true, flags); | 2324 | xhci->lpm_command = xhci_alloc_command(xhci, true, true, flags); |
@@ -2331,7 +2331,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
2331 | */ | 2331 | */ |
2332 | xhci->cmd_ring_reserved_trbs++; | 2332 | xhci->cmd_ring_reserved_trbs++; |
2333 | 2333 | ||
2334 | val = xhci_readl(xhci, &xhci->cap_regs->db_off); | 2334 | val = readl(&xhci->cap_regs->db_off); |
2335 | val &= DBOFF_MASK; | 2335 | val &= DBOFF_MASK; |
2336 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 2336 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
2337 | "// Doorbell array is located at offset 0x%x" | 2337 | "// Doorbell array is located at offset 0x%x" |
@@ -2382,13 +2382,13 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
2382 | } | 2382 | } |
2383 | 2383 | ||
2384 | /* set ERST count with the number of entries in the segment table */ | 2384 | /* set ERST count with the number of entries in the segment table */ |
2385 | val = xhci_readl(xhci, &xhci->ir_set->erst_size); | 2385 | val = readl(&xhci->ir_set->erst_size); |
2386 | val &= ERST_SIZE_MASK; | 2386 | val &= ERST_SIZE_MASK; |
2387 | val |= ERST_NUM_SEGS; | 2387 | val |= ERST_NUM_SEGS; |
2388 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 2388 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
2389 | "// Write ERST size = %i to ir_set 0 (some bits preserved)", | 2389 | "// Write ERST size = %i to ir_set 0 (some bits preserved)", |
2390 | val); | 2390 | val); |
2391 | xhci_writel(xhci, val, &xhci->ir_set->erst_size); | 2391 | writel(val, &xhci->ir_set->erst_size); |
2392 | 2392 | ||
2393 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 2393 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
2394 | "// Set ERST entries to point to event ring."); | 2394 | "// Set ERST entries to point to event ring."); |
@@ -2396,10 +2396,10 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
2396 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 2396 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
2397 | "// Set ERST base address for ir_set 0 = 0x%llx", | 2397 | "// Set ERST base address for ir_set 0 = 0x%llx", |
2398 | (unsigned long long)xhci->erst.erst_dma_addr); | 2398 | (unsigned long long)xhci->erst.erst_dma_addr); |
2399 | val_64 = xhci_read_64(xhci, &xhci->ir_set->erst_base); | 2399 | val_64 = readq(&xhci->ir_set->erst_base); |
2400 | val_64 &= ERST_PTR_MASK; | 2400 | val_64 &= ERST_PTR_MASK; |
2401 | val_64 |= (xhci->erst.erst_dma_addr & (u64) ~ERST_PTR_MASK); | 2401 | val_64 |= (xhci->erst.erst_dma_addr & (u64) ~ERST_PTR_MASK); |
2402 | xhci_write_64(xhci, val_64, &xhci->ir_set->erst_base); | 2402 | writeq(val_64, &xhci->ir_set->erst_base); |
2403 | 2403 | ||
2404 | /* Set the event ring dequeue address */ | 2404 | /* Set the event ring dequeue address */ |
2405 | xhci_set_hc_event_deq(xhci); | 2405 | xhci_set_hc_event_deq(xhci); |
@@ -2431,10 +2431,10 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
2431 | * is necessary for allowing USB 3.0 devices to do remote wakeup from | 2431 | * is necessary for allowing USB 3.0 devices to do remote wakeup from |
2432 | * U3 (device suspend). | 2432 | * U3 (device suspend). |
2433 | */ | 2433 | */ |
2434 | temp = xhci_readl(xhci, &xhci->op_regs->dev_notification); | 2434 | temp = readl(&xhci->op_regs->dev_notification); |
2435 | temp &= ~DEV_NOTE_MASK; | 2435 | temp &= ~DEV_NOTE_MASK; |
2436 | temp |= DEV_NOTE_FWAKE; | 2436 | temp |= DEV_NOTE_FWAKE; |
2437 | xhci_writel(xhci, temp, &xhci->op_regs->dev_notification); | 2437 | writel(temp, &xhci->op_regs->dev_notification); |
2438 | 2438 | ||
2439 | return 0; | 2439 | return 0; |
2440 | 2440 | ||
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 73f5208714a4..3c898c12a06b 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c | |||
@@ -336,6 +336,7 @@ static const struct hc_driver xhci_pci_hc_driver = { | |||
336 | .check_bandwidth = xhci_check_bandwidth, | 336 | .check_bandwidth = xhci_check_bandwidth, |
337 | .reset_bandwidth = xhci_reset_bandwidth, | 337 | .reset_bandwidth = xhci_reset_bandwidth, |
338 | .address_device = xhci_address_device, | 338 | .address_device = xhci_address_device, |
339 | .enable_device = xhci_enable_device, | ||
339 | .update_hub_device = xhci_update_hub_device, | 340 | .update_hub_device = xhci_update_hub_device, |
340 | .reset_device = xhci_discover_or_reset_device, | 341 | .reset_device = xhci_discover_or_reset_device, |
341 | 342 | ||
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index d9c169f470d3..8abda5c73ca1 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c | |||
@@ -69,6 +69,7 @@ static const struct hc_driver xhci_plat_xhci_driver = { | |||
69 | .check_bandwidth = xhci_check_bandwidth, | 69 | .check_bandwidth = xhci_check_bandwidth, |
70 | .reset_bandwidth = xhci_reset_bandwidth, | 70 | .reset_bandwidth = xhci_reset_bandwidth, |
71 | .address_device = xhci_address_device, | 71 | .address_device = xhci_address_device, |
72 | .enable_device = xhci_enable_device, | ||
72 | .update_hub_device = xhci_update_hub_device, | 73 | .update_hub_device = xhci_update_hub_device, |
73 | .reset_device = xhci_discover_or_reset_device, | 74 | .reset_device = xhci_discover_or_reset_device, |
74 | 75 | ||
@@ -139,6 +140,7 @@ static int xhci_plat_probe(struct platform_device *pdev) | |||
139 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); | 140 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
140 | if (ret) | 141 | if (ret) |
141 | goto unmap_registers; | 142 | goto unmap_registers; |
143 | device_wakeup_enable(hcd->self.controller); | ||
142 | 144 | ||
143 | /* USB 2.0 roothub is stored in the platform_device now. */ | 145 | /* USB 2.0 roothub is stored in the platform_device now. */ |
144 | hcd = platform_get_drvdata(pdev); | 146 | hcd = platform_get_drvdata(pdev); |
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 53c2e296467f..a0b248c34526 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
@@ -156,8 +156,6 @@ static void next_trb(struct xhci_hcd *xhci, | |||
156 | */ | 156 | */ |
157 | static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring) | 157 | static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring) |
158 | { | 158 | { |
159 | unsigned long long addr; | ||
160 | |||
161 | ring->deq_updates++; | 159 | ring->deq_updates++; |
162 | 160 | ||
163 | /* | 161 | /* |
@@ -186,8 +184,6 @@ static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring) | |||
186 | ring->dequeue++; | 184 | ring->dequeue++; |
187 | } | 185 | } |
188 | } while (last_trb(xhci, ring, ring->deq_seg, ring->dequeue)); | 186 | } while (last_trb(xhci, ring, ring->deq_seg, ring->dequeue)); |
189 | |||
190 | addr = (unsigned long long) xhci_trb_virt_to_dma(ring->deq_seg, ring->dequeue); | ||
191 | } | 187 | } |
192 | 188 | ||
193 | /* | 189 | /* |
@@ -212,7 +208,6 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, | |||
212 | { | 208 | { |
213 | u32 chain; | 209 | u32 chain; |
214 | union xhci_trb *next; | 210 | union xhci_trb *next; |
215 | unsigned long long addr; | ||
216 | 211 | ||
217 | chain = le32_to_cpu(ring->enqueue->generic.field[3]) & TRB_CHAIN; | 212 | chain = le32_to_cpu(ring->enqueue->generic.field[3]) & TRB_CHAIN; |
218 | /* If this is not event ring, there is one less usable TRB */ | 213 | /* If this is not event ring, there is one less usable TRB */ |
@@ -264,7 +259,6 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, | |||
264 | ring->enqueue = ring->enq_seg->trbs; | 259 | ring->enqueue = ring->enq_seg->trbs; |
265 | next = ring->enqueue; | 260 | next = ring->enqueue; |
266 | } | 261 | } |
267 | addr = (unsigned long long) xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue); | ||
268 | } | 262 | } |
269 | 263 | ||
270 | /* | 264 | /* |
@@ -295,9 +289,9 @@ void xhci_ring_cmd_db(struct xhci_hcd *xhci) | |||
295 | return; | 289 | return; |
296 | 290 | ||
297 | xhci_dbg(xhci, "// Ding dong!\n"); | 291 | xhci_dbg(xhci, "// Ding dong!\n"); |
298 | xhci_writel(xhci, DB_VALUE_HOST, &xhci->dba->doorbell[0]); | 292 | writel(DB_VALUE_HOST, &xhci->dba->doorbell[0]); |
299 | /* Flush PCI posted writes */ | 293 | /* Flush PCI posted writes */ |
300 | xhci_readl(xhci, &xhci->dba->doorbell[0]); | 294 | readl(&xhci->dba->doorbell[0]); |
301 | } | 295 | } |
302 | 296 | ||
303 | static int xhci_abort_cmd_ring(struct xhci_hcd *xhci) | 297 | static int xhci_abort_cmd_ring(struct xhci_hcd *xhci) |
@@ -313,14 +307,13 @@ static int xhci_abort_cmd_ring(struct xhci_hcd *xhci) | |||
313 | return 0; | 307 | return 0; |
314 | } | 308 | } |
315 | 309 | ||
316 | temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); | 310 | temp_64 = readq(&xhci->op_regs->cmd_ring); |
317 | if (!(temp_64 & CMD_RING_RUNNING)) { | 311 | if (!(temp_64 & CMD_RING_RUNNING)) { |
318 | xhci_dbg(xhci, "Command ring had been stopped\n"); | 312 | xhci_dbg(xhci, "Command ring had been stopped\n"); |
319 | return 0; | 313 | return 0; |
320 | } | 314 | } |
321 | xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; | 315 | xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; |
322 | xhci_write_64(xhci, temp_64 | CMD_RING_ABORT, | 316 | writeq(temp_64 | CMD_RING_ABORT, &xhci->op_regs->cmd_ring); |
323 | &xhci->op_regs->cmd_ring); | ||
324 | 317 | ||
325 | /* Section 4.6.1.2 of xHCI 1.0 spec says software should | 318 | /* Section 4.6.1.2 of xHCI 1.0 spec says software should |
326 | * time the completion od all xHCI commands, including | 319 | * time the completion od all xHCI commands, including |
@@ -427,7 +420,7 @@ void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, | |||
427 | if ((ep_state & EP_HALT_PENDING) || (ep_state & SET_DEQ_PENDING) || | 420 | if ((ep_state & EP_HALT_PENDING) || (ep_state & SET_DEQ_PENDING) || |
428 | (ep_state & EP_HALTED)) | 421 | (ep_state & EP_HALTED)) |
429 | return; | 422 | return; |
430 | xhci_writel(xhci, DB_VALUE(ep_index, stream_id), db_addr); | 423 | writel(DB_VALUE(ep_index, stream_id), db_addr); |
431 | /* The CPU has better things to do at this point than wait for a | 424 | /* The CPU has better things to do at this point than wait for a |
432 | * write-posting flush. It'll get there soon enough. | 425 | * write-posting flush. It'll get there soon enough. |
433 | */ | 426 | */ |
@@ -1655,7 +1648,7 @@ static void handle_device_notification(struct xhci_hcd *xhci, | |||
1655 | u32 slot_id; | 1648 | u32 slot_id; |
1656 | struct usb_device *udev; | 1649 | struct usb_device *udev; |
1657 | 1650 | ||
1658 | slot_id = TRB_TO_SLOT_ID(event->generic.field[3]); | 1651 | slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->generic.field[3])); |
1659 | if (!xhci->devs[slot_id]) { | 1652 | if (!xhci->devs[slot_id]) { |
1660 | xhci_warn(xhci, "Device Notification event for " | 1653 | xhci_warn(xhci, "Device Notification event for " |
1661 | "unused slot %u\n", slot_id); | 1654 | "unused slot %u\n", slot_id); |
@@ -1739,7 +1732,7 @@ static void handle_port_status(struct xhci_hcd *xhci, | |||
1739 | faked_port_index = find_faked_portnum_from_hw_portnum(hcd, xhci, | 1732 | faked_port_index = find_faked_portnum_from_hw_portnum(hcd, xhci, |
1740 | port_id); | 1733 | port_id); |
1741 | 1734 | ||
1742 | temp = xhci_readl(xhci, port_array[faked_port_index]); | 1735 | temp = readl(port_array[faked_port_index]); |
1743 | if (hcd->state == HC_STATE_SUSPENDED) { | 1736 | if (hcd->state == HC_STATE_SUSPENDED) { |
1744 | xhci_dbg(xhci, "resume root hub\n"); | 1737 | xhci_dbg(xhci, "resume root hub\n"); |
1745 | usb_hcd_resume_root_hub(hcd); | 1738 | usb_hcd_resume_root_hub(hcd); |
@@ -1748,7 +1741,7 @@ static void handle_port_status(struct xhci_hcd *xhci, | |||
1748 | if ((temp & PORT_PLC) && (temp & PORT_PLS_MASK) == XDEV_RESUME) { | 1741 | if ((temp & PORT_PLC) && (temp & PORT_PLS_MASK) == XDEV_RESUME) { |
1749 | xhci_dbg(xhci, "port resume event for port %d\n", port_id); | 1742 | xhci_dbg(xhci, "port resume event for port %d\n", port_id); |
1750 | 1743 | ||
1751 | temp1 = xhci_readl(xhci, &xhci->op_regs->command); | 1744 | temp1 = readl(&xhci->op_regs->command); |
1752 | if (!(temp1 & CMD_RUN)) { | 1745 | if (!(temp1 & CMD_RUN)) { |
1753 | xhci_warn(xhci, "xHC is not running.\n"); | 1746 | xhci_warn(xhci, "xHC is not running.\n"); |
1754 | goto cleanup; | 1747 | goto cleanup; |
@@ -2831,7 +2824,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) | |||
2831 | 2824 | ||
2832 | spin_lock(&xhci->lock); | 2825 | spin_lock(&xhci->lock); |
2833 | /* Check if the xHC generated the interrupt, or the irq is shared */ | 2826 | /* Check if the xHC generated the interrupt, or the irq is shared */ |
2834 | status = xhci_readl(xhci, &xhci->op_regs->status); | 2827 | status = readl(&xhci->op_regs->status); |
2835 | if (status == 0xffffffff) | 2828 | if (status == 0xffffffff) |
2836 | goto hw_died; | 2829 | goto hw_died; |
2837 | 2830 | ||
@@ -2853,16 +2846,16 @@ hw_died: | |||
2853 | * Write 1 to clear the interrupt status. | 2846 | * Write 1 to clear the interrupt status. |
2854 | */ | 2847 | */ |
2855 | status |= STS_EINT; | 2848 | status |= STS_EINT; |
2856 | xhci_writel(xhci, status, &xhci->op_regs->status); | 2849 | writel(status, &xhci->op_regs->status); |
2857 | /* FIXME when MSI-X is supported and there are multiple vectors */ | 2850 | /* FIXME when MSI-X is supported and there are multiple vectors */ |
2858 | /* Clear the MSI-X event interrupt status */ | 2851 | /* Clear the MSI-X event interrupt status */ |
2859 | 2852 | ||
2860 | if (hcd->irq) { | 2853 | if (hcd->irq) { |
2861 | u32 irq_pending; | 2854 | u32 irq_pending; |
2862 | /* Acknowledge the PCI interrupt */ | 2855 | /* Acknowledge the PCI interrupt */ |
2863 | irq_pending = xhci_readl(xhci, &xhci->ir_set->irq_pending); | 2856 | irq_pending = readl(&xhci->ir_set->irq_pending); |
2864 | irq_pending |= IMAN_IP; | 2857 | irq_pending |= IMAN_IP; |
2865 | xhci_writel(xhci, irq_pending, &xhci->ir_set->irq_pending); | 2858 | writel(irq_pending, &xhci->ir_set->irq_pending); |
2866 | } | 2859 | } |
2867 | 2860 | ||
2868 | if (xhci->xhc_state & XHCI_STATE_DYING) { | 2861 | if (xhci->xhc_state & XHCI_STATE_DYING) { |
@@ -2871,9 +2864,8 @@ hw_died: | |||
2871 | /* Clear the event handler busy flag (RW1C); | 2864 | /* Clear the event handler busy flag (RW1C); |
2872 | * the event ring should be empty. | 2865 | * the event ring should be empty. |
2873 | */ | 2866 | */ |
2874 | temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); | 2867 | temp_64 = readq(&xhci->ir_set->erst_dequeue); |
2875 | xhci_write_64(xhci, temp_64 | ERST_EHB, | 2868 | writeq(temp_64 | ERST_EHB, &xhci->ir_set->erst_dequeue); |
2876 | &xhci->ir_set->erst_dequeue); | ||
2877 | spin_unlock(&xhci->lock); | 2869 | spin_unlock(&xhci->lock); |
2878 | 2870 | ||
2879 | return IRQ_HANDLED; | 2871 | return IRQ_HANDLED; |
@@ -2885,7 +2877,7 @@ hw_died: | |||
2885 | */ | 2877 | */ |
2886 | while (xhci_handle_event(xhci) > 0) {} | 2878 | while (xhci_handle_event(xhci) > 0) {} |
2887 | 2879 | ||
2888 | temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); | 2880 | temp_64 = readq(&xhci->ir_set->erst_dequeue); |
2889 | /* If necessary, update the HW's version of the event ring deq ptr. */ | 2881 | /* If necessary, update the HW's version of the event ring deq ptr. */ |
2890 | if (event_ring_deq != xhci->event_ring->dequeue) { | 2882 | if (event_ring_deq != xhci->event_ring->dequeue) { |
2891 | deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, | 2883 | deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, |
@@ -2900,7 +2892,7 @@ hw_died: | |||
2900 | 2892 | ||
2901 | /* Clear the event handler busy flag (RW1C); event ring is empty. */ | 2893 | /* Clear the event handler busy flag (RW1C); event ring is empty. */ |
2902 | temp_64 |= ERST_EHB; | 2894 | temp_64 |= ERST_EHB; |
2903 | xhci_write_64(xhci, temp_64, &xhci->ir_set->erst_dequeue); | 2895 | writeq(temp_64, &xhci->ir_set->erst_dequeue); |
2904 | 2896 | ||
2905 | spin_unlock(&xhci->lock); | 2897 | spin_unlock(&xhci->lock); |
2906 | 2898 | ||
@@ -3008,7 +3000,7 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, | |||
3008 | if (num_trbs >= TRBS_PER_SEGMENT) { | 3000 | if (num_trbs >= TRBS_PER_SEGMENT) { |
3009 | xhci_err(xhci, "Too many fragments %d, max %d\n", | 3001 | xhci_err(xhci, "Too many fragments %d, max %d\n", |
3010 | num_trbs, TRBS_PER_SEGMENT - 1); | 3002 | num_trbs, TRBS_PER_SEGMENT - 1); |
3011 | return -ENOMEM; | 3003 | return -EINVAL; |
3012 | } | 3004 | } |
3013 | 3005 | ||
3014 | nop_cmd = cpu_to_le32(TRB_TYPE(TRB_TR_NOOP) | | 3006 | nop_cmd = cpu_to_le32(TRB_TYPE(TRB_TR_NOOP) | |
@@ -3981,7 +3973,7 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
3981 | if (ret) | 3973 | if (ret) |
3982 | return ret; | 3974 | return ret; |
3983 | 3975 | ||
3984 | start_frame = xhci_readl(xhci, &xhci->run_regs->microframe_index); | 3976 | start_frame = readl(&xhci->run_regs->microframe_index); |
3985 | start_frame &= 0x3fff; | 3977 | start_frame &= 0x3fff; |
3986 | 3978 | ||
3987 | urb->start_frame = start_frame; | 3979 | urb->start_frame = start_frame; |
@@ -4056,12 +4048,12 @@ int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id) | |||
4056 | 4048 | ||
4057 | /* Queue an address device command TRB */ | 4049 | /* Queue an address device command TRB */ |
4058 | int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 4050 | int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, |
4059 | u32 slot_id) | 4051 | u32 slot_id, enum xhci_setup_dev setup) |
4060 | { | 4052 | { |
4061 | return queue_command(xhci, lower_32_bits(in_ctx_ptr), | 4053 | return queue_command(xhci, lower_32_bits(in_ctx_ptr), |
4062 | upper_32_bits(in_ctx_ptr), 0, | 4054 | upper_32_bits(in_ctx_ptr), 0, |
4063 | TRB_TYPE(TRB_ADDR_DEV) | SLOT_ID_FOR_TRB(slot_id), | 4055 | TRB_TYPE(TRB_ADDR_DEV) | SLOT_ID_FOR_TRB(slot_id) |
4064 | false); | 4056 | | (setup == SETUP_CONTEXT_ONLY ? TRB_BSR : 0), false); |
4065 | } | 4057 | } |
4066 | 4058 | ||
4067 | int xhci_queue_vendor_command(struct xhci_hcd *xhci, | 4059 | int xhci_queue_vendor_command(struct xhci_hcd *xhci, |
diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h index 20364cc8d2fb..dde3959b7a33 100644 --- a/drivers/usb/host/xhci-trace.h +++ b/drivers/usb/host/xhci-trace.h | |||
@@ -116,12 +116,12 @@ DECLARE_EVENT_CLASS(xhci_log_event, | |||
116 | __field(u64, dma) | 116 | __field(u64, dma) |
117 | __field(u32, status) | 117 | __field(u32, status) |
118 | __field(u32, flags) | 118 | __field(u32, flags) |
119 | __dynamic_array(__le32, trb, 4) | 119 | __dynamic_array(u8, trb, sizeof(struct xhci_generic_trb)) |
120 | ), | 120 | ), |
121 | TP_fast_assign( | 121 | TP_fast_assign( |
122 | __entry->va = trb_va; | 122 | __entry->va = trb_va; |
123 | __entry->dma = le64_to_cpu(((u64)ev->field[1]) << 32 | | 123 | __entry->dma = ((u64)le32_to_cpu(ev->field[1])) << 32 | |
124 | ev->field[0]); | 124 | le32_to_cpu(ev->field[0]); |
125 | __entry->status = le32_to_cpu(ev->field[2]); | 125 | __entry->status = le32_to_cpu(ev->field[2]); |
126 | __entry->flags = le32_to_cpu(ev->field[3]); | 126 | __entry->flags = le32_to_cpu(ev->field[3]); |
127 | memcpy(__get_dynamic_array(trb), trb_va, | 127 | memcpy(__get_dynamic_array(trb), trb_va, |
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 4265b48856f6..ad364394885a 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c | |||
@@ -40,6 +40,10 @@ static int link_quirk; | |||
40 | module_param(link_quirk, int, S_IRUGO | S_IWUSR); | 40 | module_param(link_quirk, int, S_IRUGO | S_IWUSR); |
41 | MODULE_PARM_DESC(link_quirk, "Don't clear the chain bit on a link TRB"); | 41 | MODULE_PARM_DESC(link_quirk, "Don't clear the chain bit on a link TRB"); |
42 | 42 | ||
43 | static unsigned int quirks; | ||
44 | module_param(quirks, uint, S_IRUGO); | ||
45 | MODULE_PARM_DESC(quirks, "Bit flags for quirks to be enabled as default"); | ||
46 | |||
43 | /* TODO: copied from ehci-hcd.c - can this be refactored? */ | 47 | /* TODO: copied from ehci-hcd.c - can this be refactored? */ |
44 | /* | 48 | /* |
45 | * xhci_handshake - spin reading hc until handshake completes or fails | 49 | * xhci_handshake - spin reading hc until handshake completes or fails |
@@ -60,7 +64,7 @@ int xhci_handshake(struct xhci_hcd *xhci, void __iomem *ptr, | |||
60 | u32 result; | 64 | u32 result; |
61 | 65 | ||
62 | do { | 66 | do { |
63 | result = xhci_readl(xhci, ptr); | 67 | result = readl(ptr); |
64 | if (result == ~(u32)0) /* card removed */ | 68 | if (result == ~(u32)0) /* card removed */ |
65 | return -ENODEV; | 69 | return -ENODEV; |
66 | result &= mask; | 70 | result &= mask; |
@@ -82,13 +86,13 @@ void xhci_quiesce(struct xhci_hcd *xhci) | |||
82 | u32 mask; | 86 | u32 mask; |
83 | 87 | ||
84 | mask = ~(XHCI_IRQS); | 88 | mask = ~(XHCI_IRQS); |
85 | halted = xhci_readl(xhci, &xhci->op_regs->status) & STS_HALT; | 89 | halted = readl(&xhci->op_regs->status) & STS_HALT; |
86 | if (!halted) | 90 | if (!halted) |
87 | mask &= ~CMD_RUN; | 91 | mask &= ~CMD_RUN; |
88 | 92 | ||
89 | cmd = xhci_readl(xhci, &xhci->op_regs->command); | 93 | cmd = readl(&xhci->op_regs->command); |
90 | cmd &= mask; | 94 | cmd &= mask; |
91 | xhci_writel(xhci, cmd, &xhci->op_regs->command); | 95 | writel(cmd, &xhci->op_regs->command); |
92 | } | 96 | } |
93 | 97 | ||
94 | /* | 98 | /* |
@@ -124,11 +128,11 @@ static int xhci_start(struct xhci_hcd *xhci) | |||
124 | u32 temp; | 128 | u32 temp; |
125 | int ret; | 129 | int ret; |
126 | 130 | ||
127 | temp = xhci_readl(xhci, &xhci->op_regs->command); | 131 | temp = readl(&xhci->op_regs->command); |
128 | temp |= (CMD_RUN); | 132 | temp |= (CMD_RUN); |
129 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Turn on HC, cmd = 0x%x.", | 133 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Turn on HC, cmd = 0x%x.", |
130 | temp); | 134 | temp); |
131 | xhci_writel(xhci, temp, &xhci->op_regs->command); | 135 | writel(temp, &xhci->op_regs->command); |
132 | 136 | ||
133 | /* | 137 | /* |
134 | * Wait for the HCHalted Status bit to be 0 to indicate the host is | 138 | * Wait for the HCHalted Status bit to be 0 to indicate the host is |
@@ -158,16 +162,16 @@ int xhci_reset(struct xhci_hcd *xhci) | |||
158 | u32 state; | 162 | u32 state; |
159 | int ret, i; | 163 | int ret, i; |
160 | 164 | ||
161 | state = xhci_readl(xhci, &xhci->op_regs->status); | 165 | state = readl(&xhci->op_regs->status); |
162 | if ((state & STS_HALT) == 0) { | 166 | if ((state & STS_HALT) == 0) { |
163 | xhci_warn(xhci, "Host controller not halted, aborting reset.\n"); | 167 | xhci_warn(xhci, "Host controller not halted, aborting reset.\n"); |
164 | return 0; | 168 | return 0; |
165 | } | 169 | } |
166 | 170 | ||
167 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Reset the HC"); | 171 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Reset the HC"); |
168 | command = xhci_readl(xhci, &xhci->op_regs->command); | 172 | command = readl(&xhci->op_regs->command); |
169 | command |= CMD_RESET; | 173 | command |= CMD_RESET; |
170 | xhci_writel(xhci, command, &xhci->op_regs->command); | 174 | writel(command, &xhci->op_regs->command); |
171 | 175 | ||
172 | ret = xhci_handshake(xhci, &xhci->op_regs->command, | 176 | ret = xhci_handshake(xhci, &xhci->op_regs->command, |
173 | CMD_RESET, 0, 10 * 1000 * 1000); | 177 | CMD_RESET, 0, 10 * 1000 * 1000); |
@@ -321,6 +325,9 @@ static void xhci_cleanup_msix(struct xhci_hcd *xhci) | |||
321 | struct usb_hcd *hcd = xhci_to_hcd(xhci); | 325 | struct usb_hcd *hcd = xhci_to_hcd(xhci); |
322 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); | 326 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); |
323 | 327 | ||
328 | if (xhci->quirks & XHCI_PLAT) | ||
329 | return; | ||
330 | |||
324 | xhci_free_irq(xhci); | 331 | xhci_free_irq(xhci); |
325 | 332 | ||
326 | if (xhci->msix_entries) { | 333 | if (xhci->msix_entries) { |
@@ -422,7 +429,7 @@ static void compliance_mode_recovery(unsigned long arg) | |||
422 | xhci = (struct xhci_hcd *)arg; | 429 | xhci = (struct xhci_hcd *)arg; |
423 | 430 | ||
424 | for (i = 0; i < xhci->num_usb3_ports; i++) { | 431 | for (i = 0; i < xhci->num_usb3_ports; i++) { |
425 | temp = xhci_readl(xhci, xhci->usb3_ports[i]); | 432 | temp = readl(xhci->usb3_ports[i]); |
426 | if ((temp & PORT_PLS_MASK) == USB_SS_PORT_LS_COMP_MOD) { | 433 | if ((temp & PORT_PLS_MASK) == USB_SS_PORT_LS_COMP_MOD) { |
427 | /* | 434 | /* |
428 | * Compliance Mode Detected. Letting USB Core | 435 | * Compliance Mode Detected. Letting USB Core |
@@ -604,31 +611,30 @@ int xhci_run(struct usb_hcd *hcd) | |||
604 | xhci_dbg(xhci, "Event ring:\n"); | 611 | xhci_dbg(xhci, "Event ring:\n"); |
605 | xhci_debug_ring(xhci, xhci->event_ring); | 612 | xhci_debug_ring(xhci, xhci->event_ring); |
606 | xhci_dbg_ring_ptrs(xhci, xhci->event_ring); | 613 | xhci_dbg_ring_ptrs(xhci, xhci->event_ring); |
607 | temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); | 614 | temp_64 = readq(&xhci->ir_set->erst_dequeue); |
608 | temp_64 &= ~ERST_PTR_MASK; | 615 | temp_64 &= ~ERST_PTR_MASK; |
609 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 616 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
610 | "ERST deq = 64'h%0lx", (long unsigned int) temp_64); | 617 | "ERST deq = 64'h%0lx", (long unsigned int) temp_64); |
611 | 618 | ||
612 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 619 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
613 | "// Set the interrupt modulation register"); | 620 | "// Set the interrupt modulation register"); |
614 | temp = xhci_readl(xhci, &xhci->ir_set->irq_control); | 621 | temp = readl(&xhci->ir_set->irq_control); |
615 | temp &= ~ER_IRQ_INTERVAL_MASK; | 622 | temp &= ~ER_IRQ_INTERVAL_MASK; |
616 | temp |= (u32) 160; | 623 | temp |= (u32) 160; |
617 | xhci_writel(xhci, temp, &xhci->ir_set->irq_control); | 624 | writel(temp, &xhci->ir_set->irq_control); |
618 | 625 | ||
619 | /* Set the HCD state before we enable the irqs */ | 626 | /* Set the HCD state before we enable the irqs */ |
620 | temp = xhci_readl(xhci, &xhci->op_regs->command); | 627 | temp = readl(&xhci->op_regs->command); |
621 | temp |= (CMD_EIE); | 628 | temp |= (CMD_EIE); |
622 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 629 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
623 | "// Enable interrupts, cmd = 0x%x.", temp); | 630 | "// Enable interrupts, cmd = 0x%x.", temp); |
624 | xhci_writel(xhci, temp, &xhci->op_regs->command); | 631 | writel(temp, &xhci->op_regs->command); |
625 | 632 | ||
626 | temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); | 633 | temp = readl(&xhci->ir_set->irq_pending); |
627 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 634 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
628 | "// Enabling event ring interrupter %p by writing 0x%x to irq_pending", | 635 | "// Enabling event ring interrupter %p by writing 0x%x to irq_pending", |
629 | xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp)); | 636 | xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp)); |
630 | xhci_writel(xhci, ER_IRQ_ENABLE(temp), | 637 | writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending); |
631 | &xhci->ir_set->irq_pending); | ||
632 | xhci_print_ir_set(xhci, 0); | 638 | xhci_print_ir_set(xhci, 0); |
633 | 639 | ||
634 | if (xhci->quirks & XHCI_NEC_HOST) | 640 | if (xhci->quirks & XHCI_NEC_HOST) |
@@ -698,18 +704,17 @@ void xhci_stop(struct usb_hcd *hcd) | |||
698 | 704 | ||
699 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 705 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
700 | "// Disabling event ring interrupts"); | 706 | "// Disabling event ring interrupts"); |
701 | temp = xhci_readl(xhci, &xhci->op_regs->status); | 707 | temp = readl(&xhci->op_regs->status); |
702 | xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status); | 708 | writel(temp & ~STS_EINT, &xhci->op_regs->status); |
703 | temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); | 709 | temp = readl(&xhci->ir_set->irq_pending); |
704 | xhci_writel(xhci, ER_IRQ_DISABLE(temp), | 710 | writel(ER_IRQ_DISABLE(temp), &xhci->ir_set->irq_pending); |
705 | &xhci->ir_set->irq_pending); | ||
706 | xhci_print_ir_set(xhci, 0); | 711 | xhci_print_ir_set(xhci, 0); |
707 | 712 | ||
708 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, "cleaning up memory"); | 713 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, "cleaning up memory"); |
709 | xhci_mem_cleanup(xhci); | 714 | xhci_mem_cleanup(xhci); |
710 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 715 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
711 | "xhci_stop completed - status = %x", | 716 | "xhci_stop completed - status = %x", |
712 | xhci_readl(xhci, &xhci->op_regs->status)); | 717 | readl(&xhci->op_regs->status)); |
713 | } | 718 | } |
714 | 719 | ||
715 | /* | 720 | /* |
@@ -739,7 +744,7 @@ void xhci_shutdown(struct usb_hcd *hcd) | |||
739 | 744 | ||
740 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 745 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
741 | "xhci_shutdown completed - status = %x", | 746 | "xhci_shutdown completed - status = %x", |
742 | xhci_readl(xhci, &xhci->op_regs->status)); | 747 | readl(&xhci->op_regs->status)); |
743 | 748 | ||
744 | /* Yet another workaround for spurious wakeups at shutdown with HSW */ | 749 | /* Yet another workaround for spurious wakeups at shutdown with HSW */ |
745 | if (xhci->quirks & XHCI_SPURIOUS_WAKEUP) | 750 | if (xhci->quirks & XHCI_SPURIOUS_WAKEUP) |
@@ -749,28 +754,28 @@ void xhci_shutdown(struct usb_hcd *hcd) | |||
749 | #ifdef CONFIG_PM | 754 | #ifdef CONFIG_PM |
750 | static void xhci_save_registers(struct xhci_hcd *xhci) | 755 | static void xhci_save_registers(struct xhci_hcd *xhci) |
751 | { | 756 | { |
752 | xhci->s3.command = xhci_readl(xhci, &xhci->op_regs->command); | 757 | xhci->s3.command = readl(&xhci->op_regs->command); |
753 | xhci->s3.dev_nt = xhci_readl(xhci, &xhci->op_regs->dev_notification); | 758 | xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); |
754 | xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); | 759 | xhci->s3.dcbaa_ptr = readq(&xhci->op_regs->dcbaa_ptr); |
755 | xhci->s3.config_reg = xhci_readl(xhci, &xhci->op_regs->config_reg); | 760 | xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); |
756 | xhci->s3.erst_size = xhci_readl(xhci, &xhci->ir_set->erst_size); | 761 | xhci->s3.erst_size = readl(&xhci->ir_set->erst_size); |
757 | xhci->s3.erst_base = xhci_read_64(xhci, &xhci->ir_set->erst_base); | 762 | xhci->s3.erst_base = readq(&xhci->ir_set->erst_base); |
758 | xhci->s3.erst_dequeue = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); | 763 | xhci->s3.erst_dequeue = readq(&xhci->ir_set->erst_dequeue); |
759 | xhci->s3.irq_pending = xhci_readl(xhci, &xhci->ir_set->irq_pending); | 764 | xhci->s3.irq_pending = readl(&xhci->ir_set->irq_pending); |
760 | xhci->s3.irq_control = xhci_readl(xhci, &xhci->ir_set->irq_control); | 765 | xhci->s3.irq_control = readl(&xhci->ir_set->irq_control); |
761 | } | 766 | } |
762 | 767 | ||
763 | static void xhci_restore_registers(struct xhci_hcd *xhci) | 768 | static void xhci_restore_registers(struct xhci_hcd *xhci) |
764 | { | 769 | { |
765 | xhci_writel(xhci, xhci->s3.command, &xhci->op_regs->command); | 770 | writel(xhci->s3.command, &xhci->op_regs->command); |
766 | xhci_writel(xhci, xhci->s3.dev_nt, &xhci->op_regs->dev_notification); | 771 | writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); |
767 | xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); | 772 | writeq(xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); |
768 | xhci_writel(xhci, xhci->s3.config_reg, &xhci->op_regs->config_reg); | 773 | writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); |
769 | xhci_writel(xhci, xhci->s3.erst_size, &xhci->ir_set->erst_size); | 774 | writel(xhci->s3.erst_size, &xhci->ir_set->erst_size); |
770 | xhci_write_64(xhci, xhci->s3.erst_base, &xhci->ir_set->erst_base); | 775 | writeq(xhci->s3.erst_base, &xhci->ir_set->erst_base); |
771 | xhci_write_64(xhci, xhci->s3.erst_dequeue, &xhci->ir_set->erst_dequeue); | 776 | writeq(xhci->s3.erst_dequeue, &xhci->ir_set->erst_dequeue); |
772 | xhci_writel(xhci, xhci->s3.irq_pending, &xhci->ir_set->irq_pending); | 777 | writel(xhci->s3.irq_pending, &xhci->ir_set->irq_pending); |
773 | xhci_writel(xhci, xhci->s3.irq_control, &xhci->ir_set->irq_control); | 778 | writel(xhci->s3.irq_control, &xhci->ir_set->irq_control); |
774 | } | 779 | } |
775 | 780 | ||
776 | static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) | 781 | static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) |
@@ -778,7 +783,7 @@ static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) | |||
778 | u64 val_64; | 783 | u64 val_64; |
779 | 784 | ||
780 | /* step 2: initialize command ring buffer */ | 785 | /* step 2: initialize command ring buffer */ |
781 | val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); | 786 | val_64 = readq(&xhci->op_regs->cmd_ring); |
782 | val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | | 787 | val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | |
783 | (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, | 788 | (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, |
784 | xhci->cmd_ring->dequeue) & | 789 | xhci->cmd_ring->dequeue) & |
@@ -787,7 +792,7 @@ static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) | |||
787 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 792 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
788 | "// Setting command ring address to 0x%llx", | 793 | "// Setting command ring address to 0x%llx", |
789 | (long unsigned long) val_64); | 794 | (long unsigned long) val_64); |
790 | xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); | 795 | writeq(val_64, &xhci->op_regs->cmd_ring); |
791 | } | 796 | } |
792 | 797 | ||
793 | /* | 798 | /* |
@@ -866,9 +871,9 @@ int xhci_suspend(struct xhci_hcd *xhci) | |||
866 | /* skipped assuming that port suspend has done */ | 871 | /* skipped assuming that port suspend has done */ |
867 | 872 | ||
868 | /* step 2: clear Run/Stop bit */ | 873 | /* step 2: clear Run/Stop bit */ |
869 | command = xhci_readl(xhci, &xhci->op_regs->command); | 874 | command = readl(&xhci->op_regs->command); |
870 | command &= ~CMD_RUN; | 875 | command &= ~CMD_RUN; |
871 | xhci_writel(xhci, command, &xhci->op_regs->command); | 876 | writel(command, &xhci->op_regs->command); |
872 | 877 | ||
873 | /* Some chips from Fresco Logic need an extraordinary delay */ | 878 | /* Some chips from Fresco Logic need an extraordinary delay */ |
874 | delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1; | 879 | delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1; |
@@ -885,9 +890,9 @@ int xhci_suspend(struct xhci_hcd *xhci) | |||
885 | xhci_save_registers(xhci); | 890 | xhci_save_registers(xhci); |
886 | 891 | ||
887 | /* step 4: set CSS flag */ | 892 | /* step 4: set CSS flag */ |
888 | command = xhci_readl(xhci, &xhci->op_regs->command); | 893 | command = readl(&xhci->op_regs->command); |
889 | command |= CMD_CSS; | 894 | command |= CMD_CSS; |
890 | xhci_writel(xhci, command, &xhci->op_regs->command); | 895 | writel(command, &xhci->op_regs->command); |
891 | if (xhci_handshake(xhci, &xhci->op_regs->status, | 896 | if (xhci_handshake(xhci, &xhci->op_regs->status, |
892 | STS_SAVE, 0, 10 * 1000)) { | 897 | STS_SAVE, 0, 10 * 1000)) { |
893 | xhci_warn(xhci, "WARN: xHC save state timeout\n"); | 898 | xhci_warn(xhci, "WARN: xHC save state timeout\n"); |
@@ -951,16 +956,16 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) | |||
951 | xhci_set_cmd_ring_deq(xhci); | 956 | xhci_set_cmd_ring_deq(xhci); |
952 | /* step 3: restore state and start state*/ | 957 | /* step 3: restore state and start state*/ |
953 | /* step 3: set CRS flag */ | 958 | /* step 3: set CRS flag */ |
954 | command = xhci_readl(xhci, &xhci->op_regs->command); | 959 | command = readl(&xhci->op_regs->command); |
955 | command |= CMD_CRS; | 960 | command |= CMD_CRS; |
956 | xhci_writel(xhci, command, &xhci->op_regs->command); | 961 | writel(command, &xhci->op_regs->command); |
957 | if (xhci_handshake(xhci, &xhci->op_regs->status, | 962 | if (xhci_handshake(xhci, &xhci->op_regs->status, |
958 | STS_RESTORE, 0, 10 * 1000)) { | 963 | STS_RESTORE, 0, 10 * 1000)) { |
959 | xhci_warn(xhci, "WARN: xHC restore state timeout\n"); | 964 | xhci_warn(xhci, "WARN: xHC restore state timeout\n"); |
960 | spin_unlock_irq(&xhci->lock); | 965 | spin_unlock_irq(&xhci->lock); |
961 | return -ETIMEDOUT; | 966 | return -ETIMEDOUT; |
962 | } | 967 | } |
963 | temp = xhci_readl(xhci, &xhci->op_regs->status); | 968 | temp = readl(&xhci->op_regs->status); |
964 | } | 969 | } |
965 | 970 | ||
966 | /* If restore operation fails, re-initialize the HC during resume */ | 971 | /* If restore operation fails, re-initialize the HC during resume */ |
@@ -984,17 +989,16 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) | |||
984 | xhci_cleanup_msix(xhci); | 989 | xhci_cleanup_msix(xhci); |
985 | 990 | ||
986 | xhci_dbg(xhci, "// Disabling event ring interrupts\n"); | 991 | xhci_dbg(xhci, "// Disabling event ring interrupts\n"); |
987 | temp = xhci_readl(xhci, &xhci->op_regs->status); | 992 | temp = readl(&xhci->op_regs->status); |
988 | xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status); | 993 | writel(temp & ~STS_EINT, &xhci->op_regs->status); |
989 | temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); | 994 | temp = readl(&xhci->ir_set->irq_pending); |
990 | xhci_writel(xhci, ER_IRQ_DISABLE(temp), | 995 | writel(ER_IRQ_DISABLE(temp), &xhci->ir_set->irq_pending); |
991 | &xhci->ir_set->irq_pending); | ||
992 | xhci_print_ir_set(xhci, 0); | 996 | xhci_print_ir_set(xhci, 0); |
993 | 997 | ||
994 | xhci_dbg(xhci, "cleaning up memory\n"); | 998 | xhci_dbg(xhci, "cleaning up memory\n"); |
995 | xhci_mem_cleanup(xhci); | 999 | xhci_mem_cleanup(xhci); |
996 | xhci_dbg(xhci, "xhci_stop completed - status = %x\n", | 1000 | xhci_dbg(xhci, "xhci_stop completed - status = %x\n", |
997 | xhci_readl(xhci, &xhci->op_regs->status)); | 1001 | readl(&xhci->op_regs->status)); |
998 | 1002 | ||
999 | /* USB core calls the PCI reinit and start functions twice: | 1003 | /* USB core calls the PCI reinit and start functions twice: |
1000 | * first with the primary HCD, and then with the secondary HCD. | 1004 | * first with the primary HCD, and then with the secondary HCD. |
@@ -1023,9 +1027,9 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) | |||
1023 | } | 1027 | } |
1024 | 1028 | ||
1025 | /* step 4: set Run/Stop bit */ | 1029 | /* step 4: set Run/Stop bit */ |
1026 | command = xhci_readl(xhci, &xhci->op_regs->command); | 1030 | command = readl(&xhci->op_regs->command); |
1027 | command |= CMD_RUN; | 1031 | command |= CMD_RUN; |
1028 | xhci_writel(xhci, command, &xhci->op_regs->command); | 1032 | writel(command, &xhci->op_regs->command); |
1029 | xhci_handshake(xhci, &xhci->op_regs->status, STS_HALT, | 1033 | xhci_handshake(xhci, &xhci->op_regs->status, STS_HALT, |
1030 | 0, 250 * 1000); | 1034 | 0, 250 * 1000); |
1031 | 1035 | ||
@@ -1464,7 +1468,7 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | |||
1464 | ret = usb_hcd_check_unlink_urb(hcd, urb, status); | 1468 | ret = usb_hcd_check_unlink_urb(hcd, urb, status); |
1465 | if (ret || !urb->hcpriv) | 1469 | if (ret || !urb->hcpriv) |
1466 | goto done; | 1470 | goto done; |
1467 | temp = xhci_readl(xhci, &xhci->op_regs->status); | 1471 | temp = readl(&xhci->op_regs->status); |
1468 | if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) { | 1472 | if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) { |
1469 | xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, | 1473 | xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, |
1470 | "HW died, freeing TD."); | 1474 | "HW died, freeing TD."); |
@@ -1892,8 +1896,8 @@ static u32 xhci_count_num_new_endpoints(struct xhci_hcd *xhci, | |||
1892 | * (bit 1). The default control endpoint is added during the Address | 1896 | * (bit 1). The default control endpoint is added during the Address |
1893 | * Device command and is never removed until the slot is disabled. | 1897 | * Device command and is never removed until the slot is disabled. |
1894 | */ | 1898 | */ |
1895 | valid_add_flags = ctrl_ctx->add_flags >> 2; | 1899 | valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; |
1896 | valid_drop_flags = ctrl_ctx->drop_flags >> 2; | 1900 | valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; |
1897 | 1901 | ||
1898 | /* Use hweight32 to count the number of ones in the add flags, or | 1902 | /* Use hweight32 to count the number of ones in the add flags, or |
1899 | * number of endpoints added. Don't count endpoints that are changed | 1903 | * number of endpoints added. Don't count endpoints that are changed |
@@ -1909,8 +1913,8 @@ static unsigned int xhci_count_num_dropped_endpoints(struct xhci_hcd *xhci, | |||
1909 | u32 valid_add_flags; | 1913 | u32 valid_add_flags; |
1910 | u32 valid_drop_flags; | 1914 | u32 valid_drop_flags; |
1911 | 1915 | ||
1912 | valid_add_flags = ctrl_ctx->add_flags >> 2; | 1916 | valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; |
1913 | valid_drop_flags = ctrl_ctx->drop_flags >> 2; | 1917 | valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; |
1914 | 1918 | ||
1915 | return hweight32(valid_drop_flags) - | 1919 | return hweight32(valid_drop_flags) - |
1916 | hweight32(valid_add_flags & valid_drop_flags); | 1920 | hweight32(valid_add_flags & valid_drop_flags); |
@@ -3585,7 +3589,7 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) | |||
3585 | 3589 | ||
3586 | spin_lock_irqsave(&xhci->lock, flags); | 3590 | spin_lock_irqsave(&xhci->lock, flags); |
3587 | /* Don't disable the slot if the host controller is dead. */ | 3591 | /* Don't disable the slot if the host controller is dead. */ |
3588 | state = xhci_readl(xhci, &xhci->op_regs->status); | 3592 | state = readl(&xhci->op_regs->status); |
3589 | if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || | 3593 | if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || |
3590 | (xhci->xhc_state & XHCI_STATE_HALTED)) { | 3594 | (xhci->xhc_state & XHCI_STATE_HALTED)) { |
3591 | xhci_free_virt_device(xhci, udev->slot_id); | 3595 | xhci_free_virt_device(xhci, udev->slot_id); |
@@ -3712,13 +3716,15 @@ disable_slot: | |||
3712 | } | 3716 | } |
3713 | 3717 | ||
3714 | /* | 3718 | /* |
3715 | * Issue an Address Device command (which will issue a SetAddress request to | 3719 | * Issue an Address Device command and optionally send a corresponding |
3716 | * the device). | 3720 | * SetAddress request to the device. |
3717 | * We should be protected by the usb_address0_mutex in khubd's hub_port_init, so | 3721 | * We should be protected by the usb_address0_mutex in khubd's hub_port_init, so |
3718 | * we should only issue and wait on one address command at the same time. | 3722 | * we should only issue and wait on one address command at the same time. |
3719 | */ | 3723 | */ |
3720 | int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | 3724 | static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, |
3725 | enum xhci_setup_dev setup) | ||
3721 | { | 3726 | { |
3727 | const char *act = setup == SETUP_CONTEXT_ONLY ? "context" : "address"; | ||
3722 | unsigned long flags; | 3728 | unsigned long flags; |
3723 | int timeleft; | 3729 | int timeleft; |
3724 | struct xhci_virt_device *virt_dev; | 3730 | struct xhci_virt_device *virt_dev; |
@@ -3771,12 +3777,12 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3771 | xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); | 3777 | xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); |
3772 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); | 3778 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); |
3773 | trace_xhci_address_ctx(xhci, virt_dev->in_ctx, | 3779 | trace_xhci_address_ctx(xhci, virt_dev->in_ctx, |
3774 | slot_ctx->dev_info >> 27); | 3780 | le32_to_cpu(slot_ctx->dev_info) >> 27); |
3775 | 3781 | ||
3776 | spin_lock_irqsave(&xhci->lock, flags); | 3782 | spin_lock_irqsave(&xhci->lock, flags); |
3777 | cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring); | 3783 | cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring); |
3778 | ret = xhci_queue_address_device(xhci, virt_dev->in_ctx->dma, | 3784 | ret = xhci_queue_address_device(xhci, virt_dev->in_ctx->dma, |
3779 | udev->slot_id); | 3785 | udev->slot_id, setup); |
3780 | if (ret) { | 3786 | if (ret) { |
3781 | spin_unlock_irqrestore(&xhci->lock, flags); | 3787 | spin_unlock_irqrestore(&xhci->lock, flags); |
3782 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, | 3788 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, |
@@ -3794,8 +3800,8 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3794 | * command on a timeout. | 3800 | * command on a timeout. |
3795 | */ | 3801 | */ |
3796 | if (timeleft <= 0) { | 3802 | if (timeleft <= 0) { |
3797 | xhci_warn(xhci, "%s while waiting for address device command\n", | 3803 | xhci_warn(xhci, "%s while waiting for setup %s command\n", |
3798 | timeleft == 0 ? "Timeout" : "Signal"); | 3804 | timeleft == 0 ? "Timeout" : "Signal", act); |
3799 | /* cancel the address device command */ | 3805 | /* cancel the address device command */ |
3800 | ret = xhci_cancel_cmd(xhci, NULL, cmd_trb); | 3806 | ret = xhci_cancel_cmd(xhci, NULL, cmd_trb); |
3801 | if (ret < 0) | 3807 | if (ret < 0) |
@@ -3806,26 +3812,27 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3806 | switch (virt_dev->cmd_status) { | 3812 | switch (virt_dev->cmd_status) { |
3807 | case COMP_CTX_STATE: | 3813 | case COMP_CTX_STATE: |
3808 | case COMP_EBADSLT: | 3814 | case COMP_EBADSLT: |
3809 | xhci_err(xhci, "Setup ERROR: address device command for slot %d.\n", | 3815 | xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n", |
3810 | udev->slot_id); | 3816 | act, udev->slot_id); |
3811 | ret = -EINVAL; | 3817 | ret = -EINVAL; |
3812 | break; | 3818 | break; |
3813 | case COMP_TX_ERR: | 3819 | case COMP_TX_ERR: |
3814 | dev_warn(&udev->dev, "Device not responding to set address.\n"); | 3820 | dev_warn(&udev->dev, "Device not responding to setup %s.\n", act); |
3815 | ret = -EPROTO; | 3821 | ret = -EPROTO; |
3816 | break; | 3822 | break; |
3817 | case COMP_DEV_ERR: | 3823 | case COMP_DEV_ERR: |
3818 | dev_warn(&udev->dev, "ERROR: Incompatible device for address " | 3824 | dev_warn(&udev->dev, |
3819 | "device command.\n"); | 3825 | "ERROR: Incompatible device for setup %s command\n", act); |
3820 | ret = -ENODEV; | 3826 | ret = -ENODEV; |
3821 | break; | 3827 | break; |
3822 | case COMP_SUCCESS: | 3828 | case COMP_SUCCESS: |
3823 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, | 3829 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, |
3824 | "Successful Address Device command"); | 3830 | "Successful setup %s command", act); |
3825 | break; | 3831 | break; |
3826 | default: | 3832 | default: |
3827 | xhci_err(xhci, "ERROR: unexpected command completion " | 3833 | xhci_err(xhci, |
3828 | "code 0x%x.\n", virt_dev->cmd_status); | 3834 | "ERROR: unexpected setup %s command completion code 0x%x.\n", |
3835 | act, virt_dev->cmd_status); | ||
3829 | xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); | 3836 | xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); |
3830 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2); | 3837 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2); |
3831 | trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); | 3838 | trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); |
@@ -3835,7 +3842,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3835 | if (ret) { | 3842 | if (ret) { |
3836 | return ret; | 3843 | return ret; |
3837 | } | 3844 | } |
3838 | temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); | 3845 | temp_64 = readq(&xhci->op_regs->dcbaa_ptr); |
3839 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, | 3846 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, |
3840 | "Op regs DCBAA ptr = %#016llx", temp_64); | 3847 | "Op regs DCBAA ptr = %#016llx", temp_64); |
3841 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, | 3848 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, |
@@ -3850,7 +3857,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3850 | xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); | 3857 | xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); |
3851 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); | 3858 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); |
3852 | trace_xhci_address_ctx(xhci, virt_dev->in_ctx, | 3859 | trace_xhci_address_ctx(xhci, virt_dev->in_ctx, |
3853 | slot_ctx->dev_info >> 27); | 3860 | le32_to_cpu(slot_ctx->dev_info) >> 27); |
3854 | xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); | 3861 | xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); |
3855 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2); | 3862 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2); |
3856 | /* | 3863 | /* |
@@ -3859,7 +3866,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3859 | */ | 3866 | */ |
3860 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); | 3867 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); |
3861 | trace_xhci_address_ctx(xhci, virt_dev->out_ctx, | 3868 | trace_xhci_address_ctx(xhci, virt_dev->out_ctx, |
3862 | slot_ctx->dev_info >> 27); | 3869 | le32_to_cpu(slot_ctx->dev_info) >> 27); |
3863 | /* Zero the input context control for later use */ | 3870 | /* Zero the input context control for later use */ |
3864 | ctrl_ctx->add_flags = 0; | 3871 | ctrl_ctx->add_flags = 0; |
3865 | ctrl_ctx->drop_flags = 0; | 3872 | ctrl_ctx->drop_flags = 0; |
@@ -3871,6 +3878,16 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3871 | return 0; | 3878 | return 0; |
3872 | } | 3879 | } |
3873 | 3880 | ||
3881 | int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | ||
3882 | { | ||
3883 | return xhci_setup_device(hcd, udev, SETUP_CONTEXT_ADDRESS); | ||
3884 | } | ||
3885 | |||
3886 | int xhci_enable_device(struct usb_hcd *hcd, struct usb_device *udev) | ||
3887 | { | ||
3888 | return xhci_setup_device(hcd, udev, SETUP_CONTEXT_ONLY); | ||
3889 | } | ||
3890 | |||
3874 | /* | 3891 | /* |
3875 | * Transfer the port index into real index in the HW port status | 3892 | * Transfer the port index into real index in the HW port status |
3876 | * registers. Caculate offset between the port's PORTSC register | 3893 | * registers. Caculate offset between the port's PORTSC register |
@@ -4042,7 +4059,7 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, | |||
4042 | port_array = xhci->usb2_ports; | 4059 | port_array = xhci->usb2_ports; |
4043 | port_num = udev->portnum - 1; | 4060 | port_num = udev->portnum - 1; |
4044 | pm_addr = port_array[port_num] + PORTPMSC; | 4061 | pm_addr = port_array[port_num] + PORTPMSC; |
4045 | pm_val = xhci_readl(xhci, pm_addr); | 4062 | pm_val = readl(pm_addr); |
4046 | hlpm_addr = port_array[port_num] + PORTHLPMC; | 4063 | hlpm_addr = port_array[port_num] + PORTHLPMC; |
4047 | field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); | 4064 | field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); |
4048 | 4065 | ||
@@ -4082,26 +4099,26 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, | |||
4082 | spin_lock_irqsave(&xhci->lock, flags); | 4099 | spin_lock_irqsave(&xhci->lock, flags); |
4083 | 4100 | ||
4084 | hlpm_val = xhci_calculate_usb2_hw_lpm_params(udev); | 4101 | hlpm_val = xhci_calculate_usb2_hw_lpm_params(udev); |
4085 | xhci_writel(xhci, hlpm_val, hlpm_addr); | 4102 | writel(hlpm_val, hlpm_addr); |
4086 | /* flush write */ | 4103 | /* flush write */ |
4087 | xhci_readl(xhci, hlpm_addr); | 4104 | readl(hlpm_addr); |
4088 | } else { | 4105 | } else { |
4089 | hird = xhci_calculate_hird_besl(xhci, udev); | 4106 | hird = xhci_calculate_hird_besl(xhci, udev); |
4090 | } | 4107 | } |
4091 | 4108 | ||
4092 | pm_val &= ~PORT_HIRD_MASK; | 4109 | pm_val &= ~PORT_HIRD_MASK; |
4093 | pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id); | 4110 | pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id); |
4094 | xhci_writel(xhci, pm_val, pm_addr); | 4111 | writel(pm_val, pm_addr); |
4095 | pm_val = xhci_readl(xhci, pm_addr); | 4112 | pm_val = readl(pm_addr); |
4096 | pm_val |= PORT_HLE; | 4113 | pm_val |= PORT_HLE; |
4097 | xhci_writel(xhci, pm_val, pm_addr); | 4114 | writel(pm_val, pm_addr); |
4098 | /* flush write */ | 4115 | /* flush write */ |
4099 | xhci_readl(xhci, pm_addr); | 4116 | readl(pm_addr); |
4100 | } else { | 4117 | } else { |
4101 | pm_val &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK | PORT_L1DS_MASK); | 4118 | pm_val &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK | PORT_L1DS_MASK); |
4102 | xhci_writel(xhci, pm_val, pm_addr); | 4119 | writel(pm_val, pm_addr); |
4103 | /* flush write */ | 4120 | /* flush write */ |
4104 | xhci_readl(xhci, pm_addr); | 4121 | readl(pm_addr); |
4105 | if (udev->usb2_hw_lpm_besl_capable) { | 4122 | if (udev->usb2_hw_lpm_besl_capable) { |
4106 | spin_unlock_irqrestore(&xhci->lock, flags); | 4123 | spin_unlock_irqrestore(&xhci->lock, flags); |
4107 | mutex_lock(hcd->bandwidth_mutex); | 4124 | mutex_lock(hcd->bandwidth_mutex); |
@@ -4455,7 +4472,7 @@ static u16 xhci_calculate_lpm_timeout(struct usb_hcd *hcd, | |||
4455 | if (!config) | 4472 | if (!config) |
4456 | return timeout; | 4473 | return timeout; |
4457 | 4474 | ||
4458 | for (i = 0; i < USB_MAXINTERFACES; i++) { | 4475 | for (i = 0; i < config->desc.bNumInterfaces; i++) { |
4459 | struct usb_driver *driver; | 4476 | struct usb_driver *driver; |
4460 | struct usb_interface *intf = config->interface[i]; | 4477 | struct usb_interface *intf = config->interface[i]; |
4461 | 4478 | ||
@@ -4704,7 +4721,7 @@ int xhci_get_frame(struct usb_hcd *hcd) | |||
4704 | { | 4721 | { |
4705 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 4722 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
4706 | /* EHCI mods by the periodic size. Why? */ | 4723 | /* EHCI mods by the periodic size. Why? */ |
4707 | return xhci_readl(xhci, &xhci->run_regs->microframe_index) >> 3; | 4724 | return readl(&xhci->run_regs->microframe_index) >> 3; |
4708 | } | 4725 | } |
4709 | 4726 | ||
4710 | int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks) | 4727 | int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks) |
@@ -4713,8 +4730,8 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks) | |||
4713 | struct device *dev = hcd->self.controller; | 4730 | struct device *dev = hcd->self.controller; |
4714 | int retval; | 4731 | int retval; |
4715 | 4732 | ||
4716 | /* Accept arbitrarily long scatter-gather lists */ | 4733 | /* Limit the block layer scatter-gather lists to half a segment. */ |
4717 | hcd->self.sg_tablesize = ~0; | 4734 | hcd->self.sg_tablesize = TRBS_PER_SEGMENT / 2; |
4718 | 4735 | ||
4719 | /* support to build packet from discontinuous buffers */ | 4736 | /* support to build packet from discontinuous buffers */ |
4720 | hcd->self.no_sg_constraint = 1; | 4737 | hcd->self.no_sg_constraint = 1; |
@@ -4748,18 +4765,20 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks) | |||
4748 | 4765 | ||
4749 | xhci->cap_regs = hcd->regs; | 4766 | xhci->cap_regs = hcd->regs; |
4750 | xhci->op_regs = hcd->regs + | 4767 | xhci->op_regs = hcd->regs + |
4751 | HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase)); | 4768 | HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); |
4752 | xhci->run_regs = hcd->regs + | 4769 | xhci->run_regs = hcd->regs + |
4753 | (xhci_readl(xhci, &xhci->cap_regs->run_regs_off) & RTSOFF_MASK); | 4770 | (readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK); |
4754 | /* Cache read-only capability registers */ | 4771 | /* Cache read-only capability registers */ |
4755 | xhci->hcs_params1 = xhci_readl(xhci, &xhci->cap_regs->hcs_params1); | 4772 | xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1); |
4756 | xhci->hcs_params2 = xhci_readl(xhci, &xhci->cap_regs->hcs_params2); | 4773 | xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); |
4757 | xhci->hcs_params3 = xhci_readl(xhci, &xhci->cap_regs->hcs_params3); | 4774 | xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); |
4758 | xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hc_capbase); | 4775 | xhci->hcc_params = readl(&xhci->cap_regs->hc_capbase); |
4759 | xhci->hci_version = HC_VERSION(xhci->hcc_params); | 4776 | xhci->hci_version = HC_VERSION(xhci->hcc_params); |
4760 | xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hcc_params); | 4777 | xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); |
4761 | xhci_print_registers(xhci); | 4778 | xhci_print_registers(xhci); |
4762 | 4779 | ||
4780 | xhci->quirks = quirks; | ||
4781 | |||
4763 | get_quirks(dev, xhci); | 4782 | get_quirks(dev, xhci); |
4764 | 4783 | ||
4765 | /* In xhci controllers which follow xhci 1.0 spec gives a spurious | 4784 | /* In xhci controllers which follow xhci 1.0 spec gives a spurious |
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 03c74b7965f8..f8416639bf31 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h | |||
@@ -28,6 +28,17 @@ | |||
28 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
29 | #include <linux/usb/hcd.h> | 29 | #include <linux/usb/hcd.h> |
30 | 30 | ||
31 | /* | ||
32 | * Registers should always be accessed with double word or quad word accesses. | ||
33 | * | ||
34 | * Some xHCI implementations may support 64-bit address pointers. Registers | ||
35 | * with 64-bit address pointers should be written to with dword accesses by | ||
36 | * writing the low dword first (ptr[0]), then the high dword (ptr[1]) second. | ||
37 | * xHCI implementations that do not support 64-bit address pointers will ignore | ||
38 | * the high dword, and write order is irrelevant. | ||
39 | */ | ||
40 | #include <asm-generic/io-64-nonatomic-lo-hi.h> | ||
41 | |||
31 | /* Code sharing between pci-quirks and xhci hcd */ | 42 | /* Code sharing between pci-quirks and xhci hcd */ |
32 | #include "xhci-ext-caps.h" | 43 | #include "xhci-ext-caps.h" |
33 | #include "pci-quirks.h" | 44 | #include "pci-quirks.h" |
@@ -752,7 +763,7 @@ struct xhci_stream_ctx { | |||
752 | }; | 763 | }; |
753 | 764 | ||
754 | /* Stream Context Types (section 6.4.1) - bits 3:1 of stream ctx deq ptr */ | 765 | /* Stream Context Types (section 6.4.1) - bits 3:1 of stream ctx deq ptr */ |
755 | #define SCT_FOR_CTX(p) (((p) << 1) & 0x7) | 766 | #define SCT_FOR_CTX(p) (((p) & 0x7) << 1) |
756 | /* Secondary stream array type, dequeue pointer is to a transfer ring */ | 767 | /* Secondary stream array type, dequeue pointer is to a transfer ring */ |
757 | #define SCT_SEC_TR 0 | 768 | #define SCT_SEC_TR 0 |
758 | /* Primary stream array type, dequeue pointer is to a transfer ring */ | 769 | /* Primary stream array type, dequeue pointer is to a transfer ring */ |
@@ -1097,6 +1108,14 @@ struct xhci_event_cmd { | |||
1097 | }; | 1108 | }; |
1098 | 1109 | ||
1099 | /* flags bitmasks */ | 1110 | /* flags bitmasks */ |
1111 | |||
1112 | /* Address device - disable SetAddress */ | ||
1113 | #define TRB_BSR (1<<9) | ||
1114 | enum xhci_setup_dev { | ||
1115 | SETUP_CONTEXT_ONLY, | ||
1116 | SETUP_CONTEXT_ADDRESS, | ||
1117 | }; | ||
1118 | |||
1100 | /* bits 16:23 are the virtual function ID */ | 1119 | /* bits 16:23 are the virtual function ID */ |
1101 | /* bits 24:31 are the slot ID */ | 1120 | /* bits 24:31 are the slot ID */ |
1102 | #define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24) | 1121 | #define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24) |
@@ -1260,7 +1279,7 @@ union xhci_trb { | |||
1260 | * since the command ring is 64-byte aligned. | 1279 | * since the command ring is 64-byte aligned. |
1261 | * It must also be greater than 16. | 1280 | * It must also be greater than 16. |
1262 | */ | 1281 | */ |
1263 | #define TRBS_PER_SEGMENT 64 | 1282 | #define TRBS_PER_SEGMENT 256 |
1264 | /* Allow two commands + a link TRB, along with any reserved command TRBs */ | 1283 | /* Allow two commands + a link TRB, along with any reserved command TRBs */ |
1265 | #define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3) | 1284 | #define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3) |
1266 | #define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16) | 1285 | #define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16) |
@@ -1595,47 +1614,6 @@ static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci) | |||
1595 | #define xhci_warn_ratelimited(xhci, fmt, args...) \ | 1614 | #define xhci_warn_ratelimited(xhci, fmt, args...) \ |
1596 | dev_warn_ratelimited(xhci_to_hcd(xhci)->self.controller , fmt , ## args) | 1615 | dev_warn_ratelimited(xhci_to_hcd(xhci)->self.controller , fmt , ## args) |
1597 | 1616 | ||
1598 | /* TODO: copied from ehci.h - can be refactored? */ | ||
1599 | /* xHCI spec says all registers are little endian */ | ||
1600 | static inline unsigned int xhci_readl(const struct xhci_hcd *xhci, | ||
1601 | __le32 __iomem *regs) | ||
1602 | { | ||
1603 | return readl(regs); | ||
1604 | } | ||
1605 | static inline void xhci_writel(struct xhci_hcd *xhci, | ||
1606 | const unsigned int val, __le32 __iomem *regs) | ||
1607 | { | ||
1608 | writel(val, regs); | ||
1609 | } | ||
1610 | |||
1611 | /* | ||
1612 | * Registers should always be accessed with double word or quad word accesses. | ||
1613 | * | ||
1614 | * Some xHCI implementations may support 64-bit address pointers. Registers | ||
1615 | * with 64-bit address pointers should be written to with dword accesses by | ||
1616 | * writing the low dword first (ptr[0]), then the high dword (ptr[1]) second. | ||
1617 | * xHCI implementations that do not support 64-bit address pointers will ignore | ||
1618 | * the high dword, and write order is irrelevant. | ||
1619 | */ | ||
1620 | static inline u64 xhci_read_64(const struct xhci_hcd *xhci, | ||
1621 | __le64 __iomem *regs) | ||
1622 | { | ||
1623 | __u32 __iomem *ptr = (__u32 __iomem *) regs; | ||
1624 | u64 val_lo = readl(ptr); | ||
1625 | u64 val_hi = readl(ptr + 1); | ||
1626 | return val_lo + (val_hi << 32); | ||
1627 | } | ||
1628 | static inline void xhci_write_64(struct xhci_hcd *xhci, | ||
1629 | const u64 val, __le64 __iomem *regs) | ||
1630 | { | ||
1631 | __u32 __iomem *ptr = (__u32 __iomem *) regs; | ||
1632 | u32 val_lo = lower_32_bits(val); | ||
1633 | u32 val_hi = upper_32_bits(val); | ||
1634 | |||
1635 | writel(val_lo, ptr); | ||
1636 | writel(val_hi, ptr + 1); | ||
1637 | } | ||
1638 | |||
1639 | static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci) | 1617 | static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci) |
1640 | { | 1618 | { |
1641 | return xhci->quirks & XHCI_LINK_TRB_QUIRK; | 1619 | return xhci->quirks & XHCI_LINK_TRB_QUIRK; |
@@ -1790,6 +1768,7 @@ int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev, | |||
1790 | struct usb_host_endpoint **eps, unsigned int num_eps, | 1768 | struct usb_host_endpoint **eps, unsigned int num_eps, |
1791 | gfp_t mem_flags); | 1769 | gfp_t mem_flags); |
1792 | int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev); | 1770 | int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev); |
1771 | int xhci_enable_device(struct usb_hcd *hcd, struct usb_device *udev); | ||
1793 | int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev); | 1772 | int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev); |
1794 | int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, | 1773 | int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, |
1795 | struct usb_device *udev, int enable); | 1774 | struct usb_device *udev, int enable); |
@@ -1813,7 +1792,7 @@ int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); | |||
1813 | void xhci_ring_cmd_db(struct xhci_hcd *xhci); | 1792 | void xhci_ring_cmd_db(struct xhci_hcd *xhci); |
1814 | int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id); | 1793 | int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id); |
1815 | int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 1794 | int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, |
1816 | u32 slot_id); | 1795 | u32 slot_id, enum xhci_setup_dev); |
1817 | int xhci_queue_vendor_command(struct xhci_hcd *xhci, | 1796 | int xhci_queue_vendor_command(struct xhci_hcd *xhci, |
1818 | u32 field1, u32 field2, u32 field3, u32 field4); | 1797 | u32 field1, u32 field2, u32 field3, u32 field4); |
1819 | int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id, | 1798 | int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id, |
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c index 7121b50098d3..a62865af53cc 100644 --- a/drivers/usb/image/mdc800.c +++ b/drivers/usb/image/mdc800.c | |||
@@ -51,7 +51,7 @@ | |||
51 | * | 51 | * |
52 | * version 0.7.3 | 52 | * version 0.7.3 |
53 | * bugfix : The mdc800->state field gets set to READY after the | 53 | * bugfix : The mdc800->state field gets set to READY after the |
54 | * the diconnect function sets it to NOT_CONNECTED. This makes the | 54 | * the disconnect function sets it to NOT_CONNECTED. This makes the |
55 | * driver running like the camera is connected and causes some | 55 | * driver running like the camera is connected and causes some |
56 | * hang ups. | 56 | * hang ups. |
57 | * | 57 | * |
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c index 9c0f8caba3be..37b44b04a701 100644 --- a/drivers/usb/image/microtek.c +++ b/drivers/usb/image/microtek.c | |||
@@ -125,7 +125,6 @@ | |||
125 | #include <linux/errno.h> | 125 | #include <linux/errno.h> |
126 | #include <linux/random.h> | 126 | #include <linux/random.h> |
127 | #include <linux/poll.h> | 127 | #include <linux/poll.h> |
128 | #include <linux/init.h> | ||
129 | #include <linux/slab.h> | 128 | #include <linux/slab.h> |
130 | #include <linux/spinlock.h> | 129 | #include <linux/spinlock.h> |
131 | #include <linux/usb.h> | 130 | #include <linux/usb.h> |
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c index 3eaa83f05086..493c7f268b6f 100644 --- a/drivers/usb/misc/adutux.c +++ b/drivers/usb/misc/adutux.c | |||
@@ -22,7 +22,6 @@ | |||
22 | 22 | ||
23 | #include <linux/kernel.h> | 23 | #include <linux/kernel.h> |
24 | #include <linux/errno.h> | 24 | #include <linux/errno.h> |
25 | #include <linux/init.h> | ||
26 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
27 | #include <linux/module.h> | 26 | #include <linux/module.h> |
28 | #include <linux/usb.h> | 27 | #include <linux/usb.h> |
diff --git a/drivers/usb/misc/cypress_cy7c63.c b/drivers/usb/misc/cypress_cy7c63.c index 3f7c1a92579f..402b94dd2531 100644 --- a/drivers/usb/misc/cypress_cy7c63.c +++ b/drivers/usb/misc/cypress_cy7c63.c | |||
@@ -29,7 +29,6 @@ | |||
29 | * published by the Free Software Foundation, version 2. | 29 | * published by the Free Software Foundation, version 2. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <linux/init.h> | ||
33 | #include <linux/module.h> | 32 | #include <linux/module.h> |
34 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
35 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
diff --git a/drivers/usb/misc/cytherm.c b/drivers/usb/misc/cytherm.c index 5b9831b95d97..9bab1a33bc16 100644 --- a/drivers/usb/misc/cytherm.c +++ b/drivers/usb/misc/cytherm.c | |||
@@ -16,7 +16,6 @@ | |||
16 | 16 | ||
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
19 | #include <linux/init.h> | ||
20 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
21 | #include <linux/module.h> | 20 | #include <linux/module.h> |
22 | #include <linux/usb.h> | 21 | #include <linux/usb.h> |
diff --git a/drivers/usb/misc/emi26.c b/drivers/usb/misc/emi26.c index d65984dee751..8950fa5e973d 100644 --- a/drivers/usb/misc/emi26.c +++ b/drivers/usb/misc/emi26.c | |||
@@ -13,7 +13,6 @@ | |||
13 | #include <linux/errno.h> | 13 | #include <linux/errno.h> |
14 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/init.h> | ||
17 | #include <linux/usb.h> | 16 | #include <linux/usb.h> |
18 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
19 | #include <linux/firmware.h> | 18 | #include <linux/firmware.h> |
diff --git a/drivers/usb/misc/emi62.c b/drivers/usb/misc/emi62.c index ae794b90766b..1d9be4431b72 100644 --- a/drivers/usb/misc/emi62.c +++ b/drivers/usb/misc/emi62.c | |||
@@ -10,7 +10,6 @@ | |||
10 | #include <linux/kernel.h> | 10 | #include <linux/kernel.h> |
11 | #include <linux/errno.h> | 11 | #include <linux/errno.h> |
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/init.h> | ||
14 | #include <linux/module.h> | 13 | #include <linux/module.h> |
15 | #include <linux/usb.h> | 14 | #include <linux/usb.h> |
16 | #include <linux/delay.h> | 15 | #include <linux/delay.h> |
diff --git a/drivers/usb/misc/ezusb.c b/drivers/usb/misc/ezusb.c index e712afed947c..947811bc8126 100644 --- a/drivers/usb/misc/ezusb.c +++ b/drivers/usb/misc/ezusb.c | |||
@@ -9,7 +9,6 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
12 | #include <linux/init.h> | ||
13 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
14 | #include <linux/module.h> | 13 | #include <linux/module.h> |
15 | #include <linux/usb.h> | 14 | #include <linux/usb.h> |
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c index ce978384fda1..4e38683c653c 100644 --- a/drivers/usb/misc/idmouse.c +++ b/drivers/usb/misc/idmouse.c | |||
@@ -19,7 +19,6 @@ | |||
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/errno.h> | 20 | #include <linux/errno.h> |
21 | #include <linux/delay.h> | 21 | #include <linux/delay.h> |
22 | #include <linux/init.h> | ||
23 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
24 | #include <linux/module.h> | 23 | #include <linux/module.h> |
25 | #include <linux/completion.h> | 24 | #include <linux/completion.h> |
@@ -386,7 +385,7 @@ static int idmouse_probe(struct usb_interface *interface, | |||
386 | result = usb_register_dev(interface, &idmouse_class); | 385 | result = usb_register_dev(interface, &idmouse_class); |
387 | if (result) { | 386 | if (result) { |
388 | /* something prevented us from registering this device */ | 387 | /* something prevented us from registering this device */ |
389 | dev_err(&interface->dev, "Unble to allocate minor number.\n"); | 388 | dev_err(&interface->dev, "Unable to allocate minor number.\n"); |
390 | usb_set_intfdata(interface, NULL); | 389 | usb_set_intfdata(interface, NULL); |
391 | idmouse_delete(dev); | 390 | idmouse_delete(dev); |
392 | return result; | 391 | return result; |
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c index d36f34e25bed..20bcfdd7eace 100644 --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c | |||
@@ -15,7 +15,6 @@ | |||
15 | 15 | ||
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | #include <linux/usb.h> | 17 | #include <linux/usb.h> |
18 | #include <linux/init.h> | ||
19 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
20 | #include <linux/sched.h> | 19 | #include <linux/sched.h> |
21 | #include <linux/mutex.h> | 20 | #include <linux/mutex.h> |
@@ -300,7 +299,7 @@ static ssize_t iowarrior_read(struct file *file, char __user *buffer, | |||
300 | do { | 299 | do { |
301 | atomic_set(&dev->overflow_flag, 0); | 300 | atomic_set(&dev->overflow_flag, 0); |
302 | if ((read_idx = read_index(dev)) == -1) { | 301 | if ((read_idx = read_index(dev)) == -1) { |
303 | /* queue emty */ | 302 | /* queue empty */ |
304 | if (file->f_flags & O_NONBLOCK) | 303 | if (file->f_flags & O_NONBLOCK) |
305 | return -EAGAIN; | 304 | return -EAGAIN; |
306 | else { | 305 | else { |
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c index b1d59532ac22..82503a7ff6c8 100644 --- a/drivers/usb/misc/ldusb.c +++ b/drivers/usb/misc/ldusb.c | |||
@@ -24,7 +24,6 @@ | |||
24 | 24 | ||
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/errno.h> | 26 | #include <linux/errno.h> |
27 | #include <linux/init.h> | ||
28 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
29 | #include <linux/module.h> | 28 | #include <linux/module.h> |
30 | #include <linux/mutex.h> | 29 | #include <linux/mutex.h> |
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c index eb37c9542052..97cd9e24bd25 100644 --- a/drivers/usb/misc/legousbtower.c +++ b/drivers/usb/misc/legousbtower.c | |||
@@ -79,7 +79,6 @@ | |||
79 | 79 | ||
80 | #include <linux/kernel.h> | 80 | #include <linux/kernel.h> |
81 | #include <linux/errno.h> | 81 | #include <linux/errno.h> |
82 | #include <linux/init.h> | ||
83 | #include <linux/slab.h> | 82 | #include <linux/slab.h> |
84 | #include <linux/module.h> | 83 | #include <linux/module.h> |
85 | #include <linux/completion.h> | 84 | #include <linux/completion.h> |
diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c index b9b356a9dd11..13731d512624 100644 --- a/drivers/usb/misc/rio500.c +++ b/drivers/usb/misc/rio500.c | |||
@@ -36,7 +36,6 @@ | |||
36 | #include <linux/errno.h> | 36 | #include <linux/errno.h> |
37 | #include <linux/random.h> | 37 | #include <linux/random.h> |
38 | #include <linux/poll.h> | 38 | #include <linux/poll.h> |
39 | #include <linux/init.h> | ||
40 | #include <linux/slab.h> | 39 | #include <linux/slab.h> |
41 | #include <linux/spinlock.h> | 40 | #include <linux/spinlock.h> |
42 | #include <linux/usb.h> | 41 | #include <linux/usb.h> |
diff --git a/drivers/usb/misc/sisusbvga/sisusb_init.c b/drivers/usb/misc/sisusbvga/sisusb_init.c index cb8a3d91f970..bf0032ca35ed 100644 --- a/drivers/usb/misc/sisusbvga/sisusb_init.c +++ b/drivers/usb/misc/sisusbvga/sisusb_init.c | |||
@@ -40,7 +40,6 @@ | |||
40 | #include <linux/kernel.h> | 40 | #include <linux/kernel.h> |
41 | #include <linux/errno.h> | 41 | #include <linux/errno.h> |
42 | #include <linux/poll.h> | 42 | #include <linux/poll.h> |
43 | #include <linux/init.h> | ||
44 | #include <linux/spinlock.h> | 43 | #include <linux/spinlock.h> |
45 | 44 | ||
46 | #include "sisusb.h" | 45 | #include "sisusb.h" |
diff --git a/drivers/usb/misc/trancevibrator.c b/drivers/usb/misc/trancevibrator.c index 741efed4a236..4145314a515b 100644 --- a/drivers/usb/misc/trancevibrator.c +++ b/drivers/usb/misc/trancevibrator.c | |||
@@ -21,7 +21,6 @@ | |||
21 | /* Standard include files */ | 21 | /* Standard include files */ |
22 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
23 | #include <linux/errno.h> | 23 | #include <linux/errno.h> |
24 | #include <linux/init.h> | ||
25 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
26 | #include <linux/module.h> | 25 | #include <linux/module.h> |
27 | #include <linux/usb.h> | 26 | #include <linux/usb.h> |
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c index 89927bcff974..1184390508e9 100644 --- a/drivers/usb/misc/usblcd.c +++ b/drivers/usb/misc/usblcd.c | |||
@@ -14,7 +14,6 @@ | |||
14 | *****************************************************************************/ | 14 | *****************************************************************************/ |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/init.h> | ||
18 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
19 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
20 | #include <linux/mutex.h> | 19 | #include <linux/mutex.h> |
diff --git a/drivers/usb/misc/usbled.c b/drivers/usb/misc/usbled.c index 12d03e7ad636..78eb4ff33269 100644 --- a/drivers/usb/misc/usbled.c +++ b/drivers/usb/misc/usbled.c | |||
@@ -11,7 +11,6 @@ | |||
11 | 11 | ||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/errno.h> | 13 | #include <linux/errno.h> |
14 | #include <linux/init.h> | ||
15 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
16 | #include <linux/module.h> | 15 | #include <linux/module.h> |
17 | #include <linux/usb.h> | 16 | #include <linux/usb.h> |
diff --git a/drivers/usb/misc/usbsevseg.c b/drivers/usb/misc/usbsevseg.c index b2d82b937392..1fe6b73c22f3 100644 --- a/drivers/usb/misc/usbsevseg.c +++ b/drivers/usb/misc/usbsevseg.c | |||
@@ -12,7 +12,6 @@ | |||
12 | 12 | ||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/errno.h> | 14 | #include <linux/errno.h> |
15 | #include <linux/init.h> | ||
16 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
17 | #include <linux/module.h> | 16 | #include <linux/module.h> |
18 | #include <linux/string.h> | 17 | #include <linux/string.h> |
@@ -57,7 +56,7 @@ struct usb_sevsegdev { | |||
57 | * if str commands are used, we would assume the end of string | 56 | * if str commands are used, we would assume the end of string |
58 | * so mem commands are used. | 57 | * so mem commands are used. |
59 | */ | 58 | */ |
60 | inline size_t my_memlen(const char *buf, size_t count) | 59 | static inline size_t my_memlen(const char *buf, size_t count) |
61 | { | 60 | { |
62 | if (count > 0 && buf[count-1] == '\n') | 61 | if (count > 0 && buf[count-1] == '\n') |
63 | return count - 1; | 62 | return count - 1; |
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index b4152820d655..f6568b5e9b06 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c | |||
@@ -10,6 +10,7 @@ | |||
10 | 10 | ||
11 | #include <linux/usb.h> | 11 | #include <linux/usb.h> |
12 | 12 | ||
13 | #define SIMPLE_IO_TIMEOUT 10000 /* in milliseconds */ | ||
13 | 14 | ||
14 | /*-------------------------------------------------------------------------*/ | 15 | /*-------------------------------------------------------------------------*/ |
15 | 16 | ||
@@ -366,6 +367,7 @@ static int simple_io( | |||
366 | int max = urb->transfer_buffer_length; | 367 | int max = urb->transfer_buffer_length; |
367 | struct completion completion; | 368 | struct completion completion; |
368 | int retval = 0; | 369 | int retval = 0; |
370 | unsigned long expire; | ||
369 | 371 | ||
370 | urb->context = &completion; | 372 | urb->context = &completion; |
371 | while (retval == 0 && iterations-- > 0) { | 373 | while (retval == 0 && iterations-- > 0) { |
@@ -378,9 +380,15 @@ static int simple_io( | |||
378 | if (retval != 0) | 380 | if (retval != 0) |
379 | break; | 381 | break; |
380 | 382 | ||
381 | /* NOTE: no timeouts; can't be broken out of by interrupt */ | 383 | expire = msecs_to_jiffies(SIMPLE_IO_TIMEOUT); |
382 | wait_for_completion(&completion); | 384 | if (!wait_for_completion_timeout(&completion, expire)) { |
383 | retval = urb->status; | 385 | usb_kill_urb(urb); |
386 | retval = (urb->status == -ENOENT ? | ||
387 | -ETIMEDOUT : urb->status); | ||
388 | } else { | ||
389 | retval = urb->status; | ||
390 | } | ||
391 | |||
384 | urb->dev = udev; | 392 | urb->dev = udev; |
385 | if (retval == 0 && usb_pipein(urb->pipe)) | 393 | if (retval == 0 && usb_pipein(urb->pipe)) |
386 | retval = simple_check_buf(tdev, urb); | 394 | retval = simple_check_buf(tdev, urb); |
@@ -619,8 +627,8 @@ static int is_good_ext(struct usbtest_dev *tdev, u8 *buf) | |||
619 | } | 627 | } |
620 | 628 | ||
621 | attr = le32_to_cpu(ext->bmAttributes); | 629 | attr = le32_to_cpu(ext->bmAttributes); |
622 | /* bits[1:4] is used and others are reserved */ | 630 | /* bits[1:15] is used and others are reserved */ |
623 | if (attr & ~0x1e) { /* reserved == 0 */ | 631 | if (attr & ~0xfffe) { /* reserved == 0 */ |
624 | ERROR(tdev, "reserved bits set\n"); | 632 | ERROR(tdev, "reserved bits set\n"); |
625 | return 0; | 633 | return 0; |
626 | } | 634 | } |
@@ -763,7 +771,7 @@ static int ch9_postconfig(struct usbtest_dev *dev) | |||
763 | * there's always [9.4.3] a bos device descriptor [9.6.2] in USB | 771 | * there's always [9.4.3] a bos device descriptor [9.6.2] in USB |
764 | * 3.0 spec | 772 | * 3.0 spec |
765 | */ | 773 | */ |
766 | if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0300) { | 774 | if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0210) { |
767 | struct usb_bos_descriptor *bos = NULL; | 775 | struct usb_bos_descriptor *bos = NULL; |
768 | struct usb_dev_cap_header *header = NULL; | 776 | struct usb_dev_cap_header *header = NULL; |
769 | unsigned total, num, length; | 777 | unsigned total, num, length; |
@@ -944,7 +952,7 @@ struct ctrl_ctx { | |||
944 | int last; | 952 | int last; |
945 | }; | 953 | }; |
946 | 954 | ||
947 | #define NUM_SUBCASES 15 /* how many test subcases here? */ | 955 | #define NUM_SUBCASES 16 /* how many test subcases here? */ |
948 | 956 | ||
949 | struct subcase { | 957 | struct subcase { |
950 | struct usb_ctrlrequest setup; | 958 | struct usb_ctrlrequest setup; |
@@ -1218,6 +1226,15 @@ test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param) | |||
1218 | } | 1226 | } |
1219 | expected = -EREMOTEIO; | 1227 | expected = -EREMOTEIO; |
1220 | break; | 1228 | break; |
1229 | case 15: | ||
1230 | req.wValue = cpu_to_le16(USB_DT_BOS << 8); | ||
1231 | if (udev->bos) | ||
1232 | len = le16_to_cpu(udev->bos->desc->wTotalLength); | ||
1233 | else | ||
1234 | len = sizeof(struct usb_bos_descriptor); | ||
1235 | if (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0201) | ||
1236 | expected = -EPIPE; | ||
1237 | break; | ||
1221 | default: | 1238 | default: |
1222 | ERROR(dev, "bogus number of ctrl queue testcases!\n"); | 1239 | ERROR(dev, "bogus number of ctrl queue testcases!\n"); |
1223 | context.status = -EINVAL; | 1240 | context.status = -EINVAL; |
@@ -1537,8 +1554,17 @@ static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb) | |||
1537 | return retval; | 1554 | return retval; |
1538 | } | 1555 | } |
1539 | retval = verify_halted(tdev, ep, urb); | 1556 | retval = verify_halted(tdev, ep, urb); |
1540 | if (retval < 0) | 1557 | if (retval < 0) { |
1558 | int ret; | ||
1559 | |||
1560 | /* clear halt anyways, else further tests will fail */ | ||
1561 | ret = usb_clear_halt(urb->dev, urb->pipe); | ||
1562 | if (ret) | ||
1563 | ERROR(tdev, "ep %02x couldn't clear halt, %d\n", | ||
1564 | ep, ret); | ||
1565 | |||
1541 | return retval; | 1566 | return retval; |
1567 | } | ||
1542 | 1568 | ||
1543 | /* clear halt (tests API + protocol), verify it worked */ | 1569 | /* clear halt (tests API + protocol), verify it worked */ |
1544 | retval = usb_clear_halt(urb->dev, urb->pipe); | 1570 | retval = usb_clear_halt(urb->dev, urb->pipe); |
diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c index b6ab515bfc6c..24278208bf74 100644 --- a/drivers/usb/misc/yurex.c +++ b/drivers/usb/misc/yurex.c | |||
@@ -11,7 +11,6 @@ | |||
11 | 11 | ||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/errno.h> | 13 | #include <linux/errno.h> |
14 | #include <linux/init.h> | ||
15 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
16 | #include <linux/module.h> | 15 | #include <linux/module.h> |
17 | #include <linux/kref.h> | 16 | #include <linux/kref.h> |
@@ -464,7 +463,7 @@ static ssize_t yurex_write(struct file *file, const char *user_buffer, size_t co | |||
464 | goto error; | 463 | goto error; |
465 | 464 | ||
466 | mutex_lock(&dev->io_mutex); | 465 | mutex_lock(&dev->io_mutex); |
467 | if (!dev->interface) { /* alreaday disconnected */ | 466 | if (!dev->interface) { /* already disconnected */ |
468 | mutex_unlock(&dev->io_mutex); | 467 | mutex_unlock(&dev->io_mutex); |
469 | retval = -ENODEV; | 468 | retval = -ENODEV; |
470 | goto error; | 469 | goto error; |
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig index 57dfc0cedb00..688dc8bb192d 100644 --- a/drivers/usb/musb/Kconfig +++ b/drivers/usb/musb/Kconfig | |||
@@ -6,7 +6,7 @@ | |||
6 | # (M)HDRC = (Multipoint) Highspeed Dual-Role Controller | 6 | # (M)HDRC = (Multipoint) Highspeed Dual-Role Controller |
7 | config USB_MUSB_HDRC | 7 | config USB_MUSB_HDRC |
8 | tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' | 8 | tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' |
9 | depends on USB_GADGET | 9 | depends on (USB || USB_GADGET) |
10 | help | 10 | help |
11 | Say Y here if your system has a dual role high speed USB | 11 | Say Y here if your system has a dual role high speed USB |
12 | controller based on the Mentor Graphics silicon IP. Then | 12 | controller based on the Mentor Graphics silicon IP. Then |
@@ -35,21 +35,21 @@ choice | |||
35 | 35 | ||
36 | config USB_MUSB_HOST | 36 | config USB_MUSB_HOST |
37 | bool "Host only mode" | 37 | bool "Host only mode" |
38 | depends on USB | 38 | depends on USB=y || USB=USB_MUSB_HDRC |
39 | help | 39 | help |
40 | Select this when you want to use MUSB in host mode only, | 40 | Select this when you want to use MUSB in host mode only, |
41 | thereby the gadget feature will be regressed. | 41 | thereby the gadget feature will be regressed. |
42 | 42 | ||
43 | config USB_MUSB_GADGET | 43 | config USB_MUSB_GADGET |
44 | bool "Gadget only mode" | 44 | bool "Gadget only mode" |
45 | depends on USB_GADGET | 45 | depends on USB_GADGET=y || USB_GADGET=USB_MUSB_HDRC |
46 | help | 46 | help |
47 | Select this when you want to use MUSB in gadget mode only, | 47 | Select this when you want to use MUSB in gadget mode only, |
48 | thereby the host feature will be regressed. | 48 | thereby the host feature will be regressed. |
49 | 49 | ||
50 | config USB_MUSB_DUAL_ROLE | 50 | config USB_MUSB_DUAL_ROLE |
51 | bool "Dual Role mode" | 51 | bool "Dual Role mode" |
52 | depends on (USB && USB_GADGET) | 52 | depends on ((USB=y || USB=USB_MUSB_HDRC) && (USB_GADGET=y || USB_GADGET=USB_MUSB_HDRC)) |
53 | help | 53 | help |
54 | This is the default mode of working of MUSB controller where | 54 | This is the default mode of working of MUSB controller where |
55 | both host and gadget features are enabled. | 55 | both host and gadget features are enabled. |
@@ -93,6 +93,12 @@ config USB_MUSB_BLACKFIN | |||
93 | config USB_MUSB_UX500 | 93 | config USB_MUSB_UX500 |
94 | tristate "Ux500 platforms" | 94 | tristate "Ux500 platforms" |
95 | 95 | ||
96 | config USB_MUSB_JZ4740 | ||
97 | tristate "JZ4740" | ||
98 | depends on MACH_JZ4740 || COMPILE_TEST | ||
99 | depends on USB_MUSB_GADGET | ||
100 | depends on USB_OTG_BLACKLIST_HUB | ||
101 | |||
96 | endchoice | 102 | endchoice |
97 | 103 | ||
98 | config USB_MUSB_AM335X_CHILD | 104 | config USB_MUSB_AM335X_CHILD |
@@ -100,7 +106,7 @@ config USB_MUSB_AM335X_CHILD | |||
100 | 106 | ||
101 | choice | 107 | choice |
102 | prompt 'MUSB DMA mode' | 108 | prompt 'MUSB DMA mode' |
103 | default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM | 109 | default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM || USB_MUSB_JZ4740 |
104 | default USB_UX500_DMA if USB_MUSB_UX500 | 110 | default USB_UX500_DMA if USB_MUSB_UX500 |
105 | default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN | 111 | default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN |
106 | default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI | 112 | default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI |
diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile index c5ea5c6dc169..ba495018b416 100644 --- a/drivers/usb/musb/Makefile +++ b/drivers/usb/musb/Makefile | |||
@@ -19,6 +19,7 @@ obj-$(CONFIG_USB_MUSB_DAVINCI) += davinci.o | |||
19 | obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o | 19 | obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o |
20 | obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o | 20 | obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o |
21 | obj-$(CONFIG_USB_MUSB_UX500) += ux500.o | 21 | obj-$(CONFIG_USB_MUSB_UX500) += ux500.o |
22 | obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o | ||
22 | 23 | ||
23 | 24 | ||
24 | obj-$(CONFIG_USB_MUSB_AM335X_CHILD) += musb_am335x.o | 25 | obj-$(CONFIG_USB_MUSB_AM335X_CHILD) += musb_am335x.o |
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c index ca45b39db5b9..b3aa0184af9a 100644 --- a/drivers/usb/musb/am35x.c +++ b/drivers/usb/musb/am35x.c | |||
@@ -26,7 +26,6 @@ | |||
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/module.h> | 29 | #include <linux/module.h> |
31 | #include <linux/clk.h> | 30 | #include <linux/clk.h> |
32 | #include <linux/err.h> | 31 | #include <linux/err.h> |
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c index d9692f78e227..796677fa9a15 100644 --- a/drivers/usb/musb/blackfin.c +++ b/drivers/usb/musb/blackfin.c | |||
@@ -11,7 +11,6 @@ | |||
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/sched.h> | 13 | #include <linux/sched.h> |
14 | #include <linux/init.h> | ||
15 | #include <linux/list.h> | 14 | #include <linux/list.h> |
16 | #include <linux/gpio.h> | 15 | #include <linux/gpio.h> |
17 | #include <linux/io.h> | 16 | #include <linux/io.h> |
@@ -77,7 +76,7 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src) | |||
77 | bfin_write16(USB_DMA_REG(epnum, USB_DMAx_CTRL), dma_reg); | 76 | bfin_write16(USB_DMA_REG(epnum, USB_DMAx_CTRL), dma_reg); |
78 | SSYNC(); | 77 | SSYNC(); |
79 | 78 | ||
80 | /* Wait for compelete */ | 79 | /* Wait for complete */ |
81 | while (!(bfin_read_USB_DMA_INTERRUPT() & (1 << epnum))) | 80 | while (!(bfin_read_USB_DMA_INTERRUPT() & (1 << epnum))) |
82 | cpu_relax(); | 81 | cpu_relax(); |
83 | 82 | ||
@@ -131,7 +130,7 @@ void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) | |||
131 | bfin_write16(USB_DMA_REG(epnum, USB_DMAx_CTRL), dma_reg); | 130 | bfin_write16(USB_DMA_REG(epnum, USB_DMAx_CTRL), dma_reg); |
132 | SSYNC(); | 131 | SSYNC(); |
133 | 132 | ||
134 | /* Wait for compelete */ | 133 | /* Wait for complete */ |
135 | while (!(bfin_read_USB_DMA_INTERRUPT() & (1 << epnum))) | 134 | while (!(bfin_read_USB_DMA_INTERRUPT() & (1 << epnum))) |
136 | cpu_relax(); | 135 | cpu_relax(); |
137 | 136 | ||
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c index 2f2c1cb36421..e3486de71995 100644 --- a/drivers/usb/musb/da8xx.c +++ b/drivers/usb/musb/da8xx.c | |||
@@ -26,7 +26,6 @@ | |||
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/module.h> | 29 | #include <linux/module.h> |
31 | #include <linux/clk.h> | 30 | #include <linux/clk.h> |
32 | #include <linux/err.h> | 31 | #include <linux/err.h> |
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c index 1121fd741bf8..c259dac9d056 100644 --- a/drivers/usb/musb/davinci.c +++ b/drivers/usb/musb/davinci.c | |||
@@ -24,7 +24,6 @@ | |||
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/sched.h> | 26 | #include <linux/sched.h> |
27 | #include <linux/init.h> | ||
28 | #include <linux/list.h> | 27 | #include <linux/list.h> |
29 | #include <linux/delay.h> | 28 | #include <linux/delay.h> |
30 | #include <linux/clk.h> | 29 | #include <linux/clk.h> |
diff --git a/drivers/usb/musb/jz4740.c b/drivers/usb/musb/jz4740.c new file mode 100644 index 000000000000..5f30537f1927 --- /dev/null +++ b/drivers/usb/musb/jz4740.c | |||
@@ -0,0 +1,201 @@ | |||
1 | /* | ||
2 | * Ingenic JZ4740 "glue layer" | ||
3 | * | ||
4 | * Copyright (C) 2013, Apelete Seketeli <apelete@seketeli.net> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * You should have received a copy of the GNU General Public License along | ||
12 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
13 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
14 | */ | ||
15 | |||
16 | #include <linux/clk.h> | ||
17 | #include <linux/dma-mapping.h> | ||
18 | #include <linux/errno.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | |||
23 | #include "musb_core.h" | ||
24 | |||
25 | struct jz4740_glue { | ||
26 | struct device *dev; | ||
27 | struct platform_device *musb; | ||
28 | struct clk *clk; | ||
29 | }; | ||
30 | |||
31 | static irqreturn_t jz4740_musb_interrupt(int irq, void *__hci) | ||
32 | { | ||
33 | unsigned long flags; | ||
34 | irqreturn_t retval = IRQ_NONE; | ||
35 | struct musb *musb = __hci; | ||
36 | |||
37 | spin_lock_irqsave(&musb->lock, flags); | ||
38 | |||
39 | musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); | ||
40 | musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); | ||
41 | musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); | ||
42 | |||
43 | /* | ||
44 | * The controller is gadget only, the state of the host mode IRQ bits is | ||
45 | * undefined. Mask them to make sure that the musb driver core will | ||
46 | * never see them set | ||
47 | */ | ||
48 | musb->int_usb &= MUSB_INTR_SUSPEND | MUSB_INTR_RESUME | | ||
49 | MUSB_INTR_RESET | MUSB_INTR_SOF; | ||
50 | |||
51 | if (musb->int_usb || musb->int_tx || musb->int_rx) | ||
52 | retval = musb_interrupt(musb); | ||
53 | |||
54 | spin_unlock_irqrestore(&musb->lock, flags); | ||
55 | |||
56 | return retval; | ||
57 | } | ||
58 | |||
59 | static struct musb_fifo_cfg jz4740_musb_fifo_cfg[] = { | ||
60 | { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, | ||
61 | { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, | ||
62 | { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 64, }, | ||
63 | }; | ||
64 | |||
65 | static struct musb_hdrc_config jz4740_musb_config = { | ||
66 | /* Silicon does not implement USB OTG. */ | ||
67 | .multipoint = 0, | ||
68 | /* Max EPs scanned, driver will decide which EP can be used. */ | ||
69 | .num_eps = 4, | ||
70 | /* RAMbits needed to configure EPs from table */ | ||
71 | .ram_bits = 9, | ||
72 | .fifo_cfg = jz4740_musb_fifo_cfg, | ||
73 | .fifo_cfg_size = ARRAY_SIZE(jz4740_musb_fifo_cfg), | ||
74 | }; | ||
75 | |||
76 | static struct musb_hdrc_platform_data jz4740_musb_platform_data = { | ||
77 | .mode = MUSB_PERIPHERAL, | ||
78 | .config = &jz4740_musb_config, | ||
79 | }; | ||
80 | |||
81 | static int jz4740_musb_init(struct musb *musb) | ||
82 | { | ||
83 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); | ||
84 | if (!musb->xceiv) { | ||
85 | pr_err("HS UDC: no transceiver configured\n"); | ||
86 | return -ENODEV; | ||
87 | } | ||
88 | |||
89 | /* Silicon does not implement ConfigData register. | ||
90 | * Set dyn_fifo to avoid reading EP config from hardware. | ||
91 | */ | ||
92 | musb->dyn_fifo = true; | ||
93 | |||
94 | musb->isr = jz4740_musb_interrupt; | ||
95 | |||
96 | return 0; | ||
97 | } | ||
98 | |||
99 | static int jz4740_musb_exit(struct musb *musb) | ||
100 | { | ||
101 | usb_put_phy(musb->xceiv); | ||
102 | |||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | static const struct musb_platform_ops jz4740_musb_ops = { | ||
107 | .init = jz4740_musb_init, | ||
108 | .exit = jz4740_musb_exit, | ||
109 | }; | ||
110 | |||
111 | static int jz4740_probe(struct platform_device *pdev) | ||
112 | { | ||
113 | struct musb_hdrc_platform_data *pdata = &jz4740_musb_platform_data; | ||
114 | struct platform_device *musb; | ||
115 | struct jz4740_glue *glue; | ||
116 | struct clk *clk; | ||
117 | int ret; | ||
118 | |||
119 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); | ||
120 | if (!glue) | ||
121 | return -ENOMEM; | ||
122 | |||
123 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); | ||
124 | if (!musb) { | ||
125 | dev_err(&pdev->dev, "failed to allocate musb device\n"); | ||
126 | return -ENOMEM; | ||
127 | } | ||
128 | |||
129 | clk = devm_clk_get(&pdev->dev, "udc"); | ||
130 | if (IS_ERR(clk)) { | ||
131 | dev_err(&pdev->dev, "failed to get clock\n"); | ||
132 | ret = PTR_ERR(clk); | ||
133 | goto err_platform_device_put; | ||
134 | } | ||
135 | |||
136 | ret = clk_prepare_enable(clk); | ||
137 | if (ret) { | ||
138 | dev_err(&pdev->dev, "failed to enable clock\n"); | ||
139 | goto err_platform_device_put; | ||
140 | } | ||
141 | |||
142 | musb->dev.parent = &pdev->dev; | ||
143 | |||
144 | glue->dev = &pdev->dev; | ||
145 | glue->musb = musb; | ||
146 | glue->clk = clk; | ||
147 | |||
148 | pdata->platform_ops = &jz4740_musb_ops; | ||
149 | |||
150 | platform_set_drvdata(pdev, glue); | ||
151 | |||
152 | ret = platform_device_add_resources(musb, pdev->resource, | ||
153 | pdev->num_resources); | ||
154 | if (ret) { | ||
155 | dev_err(&pdev->dev, "failed to add resources\n"); | ||
156 | goto err_clk_disable; | ||
157 | } | ||
158 | |||
159 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | ||
160 | if (ret) { | ||
161 | dev_err(&pdev->dev, "failed to add platform_data\n"); | ||
162 | goto err_clk_disable; | ||
163 | } | ||
164 | |||
165 | ret = platform_device_add(musb); | ||
166 | if (ret) { | ||
167 | dev_err(&pdev->dev, "failed to register musb device\n"); | ||
168 | goto err_clk_disable; | ||
169 | } | ||
170 | |||
171 | return 0; | ||
172 | |||
173 | err_clk_disable: | ||
174 | clk_disable_unprepare(clk); | ||
175 | err_platform_device_put: | ||
176 | platform_device_put(musb); | ||
177 | return ret; | ||
178 | } | ||
179 | |||
180 | static int jz4740_remove(struct platform_device *pdev) | ||
181 | { | ||
182 | struct jz4740_glue *glue = platform_get_drvdata(pdev); | ||
183 | |||
184 | platform_device_unregister(glue->musb); | ||
185 | clk_disable_unprepare(glue->clk); | ||
186 | |||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | static struct platform_driver jz4740_driver = { | ||
191 | .probe = jz4740_probe, | ||
192 | .remove = jz4740_remove, | ||
193 | .driver = { | ||
194 | .name = "musb-jz4740", | ||
195 | }, | ||
196 | }; | ||
197 | |||
198 | MODULE_DESCRIPTION("JZ4740 MUSB Glue Layer"); | ||
199 | MODULE_AUTHOR("Apelete Seketeli <apelete@seketeli.net>"); | ||
200 | MODULE_LICENSE("GPL v2"); | ||
201 | module_platform_driver(jz4740_driver); | ||
diff --git a/drivers/usb/musb/musb_am335x.c b/drivers/usb/musb/musb_am335x.c index 8be9b02c3cc2..d2353781bd2d 100644 --- a/drivers/usb/musb/musb_am335x.c +++ b/drivers/usb/musb/musb_am335x.c | |||
@@ -1,4 +1,3 @@ | |||
1 | #include <linux/init.h> | ||
2 | #include <linux/platform_device.h> | 1 | #include <linux/platform_device.h> |
3 | #include <linux/pm_runtime.h> | 2 | #include <linux/pm_runtime.h> |
4 | #include <linux/module.h> | 3 | #include <linux/module.h> |
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 4d4499b80449..fc192ad9cc6a 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c | |||
@@ -83,7 +83,7 @@ | |||
83 | * This gets many kinds of configuration information: | 83 | * This gets many kinds of configuration information: |
84 | * - Kconfig for everything user-configurable | 84 | * - Kconfig for everything user-configurable |
85 | * - platform_device for addressing, irq, and platform_data | 85 | * - platform_device for addressing, irq, and platform_data |
86 | * - platform_data is mostly for board-specific informarion | 86 | * - platform_data is mostly for board-specific information |
87 | * (plus recentrly, SOC or family details) | 87 | * (plus recentrly, SOC or family details) |
88 | * | 88 | * |
89 | * Most of the conditional compilation will (someday) vanish. | 89 | * Most of the conditional compilation will (someday) vanish. |
@@ -93,7 +93,6 @@ | |||
93 | #include <linux/kernel.h> | 93 | #include <linux/kernel.h> |
94 | #include <linux/sched.h> | 94 | #include <linux/sched.h> |
95 | #include <linux/slab.h> | 95 | #include <linux/slab.h> |
96 | #include <linux/init.h> | ||
97 | #include <linux/list.h> | 96 | #include <linux/list.h> |
98 | #include <linux/kobject.h> | 97 | #include <linux/kobject.h> |
99 | #include <linux/prefetch.h> | 98 | #include <linux/prefetch.h> |
@@ -478,8 +477,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
478 | musb->port1_status |= | 477 | musb->port1_status |= |
479 | (USB_PORT_STAT_C_SUSPEND << 16) | 478 | (USB_PORT_STAT_C_SUSPEND << 16) |
480 | | MUSB_PORT_STAT_RESUME; | 479 | | MUSB_PORT_STAT_RESUME; |
481 | musb->rh_timer = jiffies | 480 | schedule_delayed_work( |
482 | + msecs_to_jiffies(20); | 481 | &musb->finish_resume_work, 20); |
483 | 482 | ||
484 | musb->xceiv->state = OTG_STATE_A_HOST; | 483 | musb->xceiv->state = OTG_STATE_A_HOST; |
485 | musb->is_active = 1; | 484 | musb->is_active = 1; |
@@ -1187,7 +1186,7 @@ fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep, | |||
1187 | musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum); | 1186 | musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum); |
1188 | 1187 | ||
1189 | /* EP0 reserved endpoint for control, bidirectional; | 1188 | /* EP0 reserved endpoint for control, bidirectional; |
1190 | * EP1 reserved for bulk, two unidirection halves. | 1189 | * EP1 reserved for bulk, two unidirectional halves. |
1191 | */ | 1190 | */ |
1192 | if (hw_ep->epnum == 1) | 1191 | if (hw_ep->epnum == 1) |
1193 | musb->bulk_ep = hw_ep; | 1192 | musb->bulk_ep = hw_ep; |
@@ -1813,6 +1812,21 @@ static void musb_free(struct musb *musb) | |||
1813 | musb_host_free(musb); | 1812 | musb_host_free(musb); |
1814 | } | 1813 | } |
1815 | 1814 | ||
1815 | static void musb_deassert_reset(struct work_struct *work) | ||
1816 | { | ||
1817 | struct musb *musb; | ||
1818 | unsigned long flags; | ||
1819 | |||
1820 | musb = container_of(work, struct musb, deassert_reset_work.work); | ||
1821 | |||
1822 | spin_lock_irqsave(&musb->lock, flags); | ||
1823 | |||
1824 | if (musb->port1_status & USB_PORT_STAT_RESET) | ||
1825 | musb_port_reset(musb, false); | ||
1826 | |||
1827 | spin_unlock_irqrestore(&musb->lock, flags); | ||
1828 | } | ||
1829 | |||
1816 | /* | 1830 | /* |
1817 | * Perform generic per-controller initialization. | 1831 | * Perform generic per-controller initialization. |
1818 | * | 1832 | * |
@@ -1857,7 +1871,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1857 | /* The musb_platform_init() call: | 1871 | /* The musb_platform_init() call: |
1858 | * - adjusts musb->mregs | 1872 | * - adjusts musb->mregs |
1859 | * - sets the musb->isr | 1873 | * - sets the musb->isr |
1860 | * - may initialize an integrated tranceiver | 1874 | * - may initialize an integrated transceiver |
1861 | * - initializes musb->xceiv, usually by otg_get_phy() | 1875 | * - initializes musb->xceiv, usually by otg_get_phy() |
1862 | * - stops powering VBUS | 1876 | * - stops powering VBUS |
1863 | * | 1877 | * |
@@ -1897,6 +1911,8 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1897 | 1911 | ||
1898 | /* Init IRQ workqueue before request_irq */ | 1912 | /* Init IRQ workqueue before request_irq */ |
1899 | INIT_WORK(&musb->irq_work, musb_irq_work); | 1913 | INIT_WORK(&musb->irq_work, musb_irq_work); |
1914 | INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset); | ||
1915 | INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume); | ||
1900 | 1916 | ||
1901 | /* setup musb parts of the core (especially endpoints) */ | 1917 | /* setup musb parts of the core (especially endpoints) */ |
1902 | status = musb_core_init(plat->config->multipoint | 1918 | status = musb_core_init(plat->config->multipoint |
@@ -1940,17 +1956,26 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1940 | switch (musb->port_mode) { | 1956 | switch (musb->port_mode) { |
1941 | case MUSB_PORT_MODE_HOST: | 1957 | case MUSB_PORT_MODE_HOST: |
1942 | status = musb_host_setup(musb, plat->power); | 1958 | status = musb_host_setup(musb, plat->power); |
1959 | if (status < 0) | ||
1960 | goto fail3; | ||
1961 | status = musb_platform_set_mode(musb, MUSB_HOST); | ||
1943 | break; | 1962 | break; |
1944 | case MUSB_PORT_MODE_GADGET: | 1963 | case MUSB_PORT_MODE_GADGET: |
1945 | status = musb_gadget_setup(musb); | 1964 | status = musb_gadget_setup(musb); |
1965 | if (status < 0) | ||
1966 | goto fail3; | ||
1967 | status = musb_platform_set_mode(musb, MUSB_PERIPHERAL); | ||
1946 | break; | 1968 | break; |
1947 | case MUSB_PORT_MODE_DUAL_ROLE: | 1969 | case MUSB_PORT_MODE_DUAL_ROLE: |
1948 | status = musb_host_setup(musb, plat->power); | 1970 | status = musb_host_setup(musb, plat->power); |
1949 | if (status < 0) | 1971 | if (status < 0) |
1950 | goto fail3; | 1972 | goto fail3; |
1951 | status = musb_gadget_setup(musb); | 1973 | status = musb_gadget_setup(musb); |
1952 | if (status) | 1974 | if (status) { |
1953 | musb_host_cleanup(musb); | 1975 | musb_host_cleanup(musb); |
1976 | goto fail3; | ||
1977 | } | ||
1978 | status = musb_platform_set_mode(musb, MUSB_OTG); | ||
1954 | break; | 1979 | break; |
1955 | default: | 1980 | default: |
1956 | dev_err(dev, "unsupported port mode %d\n", musb->port_mode); | 1981 | dev_err(dev, "unsupported port mode %d\n", musb->port_mode); |
@@ -1981,6 +2006,8 @@ fail4: | |||
1981 | 2006 | ||
1982 | fail3: | 2007 | fail3: |
1983 | cancel_work_sync(&musb->irq_work); | 2008 | cancel_work_sync(&musb->irq_work); |
2009 | cancel_delayed_work_sync(&musb->finish_resume_work); | ||
2010 | cancel_delayed_work_sync(&musb->deassert_reset_work); | ||
1984 | if (musb->dma_controller) | 2011 | if (musb->dma_controller) |
1985 | dma_controller_destroy(musb->dma_controller); | 2012 | dma_controller_destroy(musb->dma_controller); |
1986 | fail2_5: | 2013 | fail2_5: |
@@ -2044,6 +2071,8 @@ static int musb_remove(struct platform_device *pdev) | |||
2044 | dma_controller_destroy(musb->dma_controller); | 2071 | dma_controller_destroy(musb->dma_controller); |
2045 | 2072 | ||
2046 | cancel_work_sync(&musb->irq_work); | 2073 | cancel_work_sync(&musb->irq_work); |
2074 | cancel_delayed_work_sync(&musb->finish_resume_work); | ||
2075 | cancel_delayed_work_sync(&musb->deassert_reset_work); | ||
2047 | musb_free(musb); | 2076 | musb_free(musb); |
2048 | device_init_wakeup(dev, 0); | 2077 | device_init_wakeup(dev, 0); |
2049 | return 0; | 2078 | return 0; |
@@ -2216,16 +2245,28 @@ static int musb_suspend(struct device *dev) | |||
2216 | */ | 2245 | */ |
2217 | } | 2246 | } |
2218 | 2247 | ||
2248 | musb_save_context(musb); | ||
2249 | |||
2219 | spin_unlock_irqrestore(&musb->lock, flags); | 2250 | spin_unlock_irqrestore(&musb->lock, flags); |
2220 | return 0; | 2251 | return 0; |
2221 | } | 2252 | } |
2222 | 2253 | ||
2223 | static int musb_resume_noirq(struct device *dev) | 2254 | static int musb_resume_noirq(struct device *dev) |
2224 | { | 2255 | { |
2225 | /* for static cmos like DaVinci, register values were preserved | 2256 | struct musb *musb = dev_to_musb(dev); |
2257 | |||
2258 | /* | ||
2259 | * For static cmos like DaVinci, register values were preserved | ||
2226 | * unless for some reason the whole soc powered down or the USB | 2260 | * unless for some reason the whole soc powered down or the USB |
2227 | * module got reset through the PSC (vs just being disabled). | 2261 | * module got reset through the PSC (vs just being disabled). |
2262 | * | ||
2263 | * For the DSPS glue layer though, a full register restore has to | ||
2264 | * be done. As it shouldn't harm other platforms, we do it | ||
2265 | * unconditionally. | ||
2228 | */ | 2266 | */ |
2267 | |||
2268 | musb_restore_context(musb); | ||
2269 | |||
2229 | return 0; | 2270 | return 0; |
2230 | } | 2271 | } |
2231 | 2272 | ||
@@ -2283,19 +2324,4 @@ static struct platform_driver musb_driver = { | |||
2283 | .shutdown = musb_shutdown, | 2324 | .shutdown = musb_shutdown, |
2284 | }; | 2325 | }; |
2285 | 2326 | ||
2286 | /*-------------------------------------------------------------------------*/ | 2327 | module_platform_driver(musb_driver); |
2287 | |||
2288 | static int __init musb_init(void) | ||
2289 | { | ||
2290 | if (usb_disabled()) | ||
2291 | return 0; | ||
2292 | |||
2293 | return platform_driver_register(&musb_driver); | ||
2294 | } | ||
2295 | module_init(musb_init); | ||
2296 | |||
2297 | static void __exit musb_cleanup(void) | ||
2298 | { | ||
2299 | platform_driver_unregister(&musb_driver); | ||
2300 | } | ||
2301 | module_exit(musb_cleanup); | ||
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index 29f7cd7c7964..7083e82776ff 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h | |||
@@ -47,6 +47,7 @@ | |||
47 | #include <linux/usb/otg.h> | 47 | #include <linux/usb/otg.h> |
48 | #include <linux/usb/musb.h> | 48 | #include <linux/usb/musb.h> |
49 | #include <linux/phy/phy.h> | 49 | #include <linux/phy/phy.h> |
50 | #include <linux/workqueue.h> | ||
50 | 51 | ||
51 | struct musb; | 52 | struct musb; |
52 | struct musb_hw_ep; | 53 | struct musb_hw_ep; |
@@ -295,6 +296,8 @@ struct musb { | |||
295 | 296 | ||
296 | irqreturn_t (*isr)(int, void *); | 297 | irqreturn_t (*isr)(int, void *); |
297 | struct work_struct irq_work; | 298 | struct work_struct irq_work; |
299 | struct delayed_work deassert_reset_work; | ||
300 | struct delayed_work finish_resume_work; | ||
298 | u16 hwvers; | 301 | u16 hwvers; |
299 | 302 | ||
300 | u16 intrrxe; | 303 | u16 intrrxe; |
diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c index a12bd30401e0..f88929609bac 100644 --- a/drivers/usb/musb/musb_cppi41.c +++ b/drivers/usb/musb/musb_cppi41.c | |||
@@ -615,7 +615,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller) | |||
615 | 615 | ||
616 | dc = dma_request_slave_channel(dev, str); | 616 | dc = dma_request_slave_channel(dev, str); |
617 | if (!dc) { | 617 | if (!dc) { |
618 | dev_err(dev, "Falied to request %s.\n", str); | 618 | dev_err(dev, "Failed to request %s.\n", str); |
619 | ret = -EPROBE_DEFER; | 619 | ret = -EPROBE_DEFER; |
620 | goto err; | 620 | goto err; |
621 | } | 621 | } |
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index 1901f6fe5807..7a109eae9b9a 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c | |||
@@ -29,7 +29,6 @@ | |||
29 | * da8xx.c would be merged to this file after testing. | 29 | * da8xx.c would be merged to this file after testing. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <linux/init.h> | ||
33 | #include <linux/io.h> | 32 | #include <linux/io.h> |
34 | #include <linux/err.h> | 33 | #include <linux/err.h> |
35 | #include <linux/platform_device.h> | 34 | #include <linux/platform_device.h> |
@@ -83,6 +82,8 @@ struct dsps_musb_wrapper { | |||
83 | u16 coreintr_status; | 82 | u16 coreintr_status; |
84 | u16 phy_utmi; | 83 | u16 phy_utmi; |
85 | u16 mode; | 84 | u16 mode; |
85 | u16 tx_mode; | ||
86 | u16 rx_mode; | ||
86 | 87 | ||
87 | /* bit positions for control */ | 88 | /* bit positions for control */ |
88 | unsigned reset:5; | 89 | unsigned reset:5; |
@@ -106,10 +107,24 @@ struct dsps_musb_wrapper { | |||
106 | 107 | ||
107 | /* bit positions for mode */ | 108 | /* bit positions for mode */ |
108 | unsigned iddig:5; | 109 | unsigned iddig:5; |
110 | unsigned iddig_mux:5; | ||
109 | /* miscellaneous stuff */ | 111 | /* miscellaneous stuff */ |
110 | u8 poll_seconds; | 112 | u8 poll_seconds; |
111 | }; | 113 | }; |
112 | 114 | ||
115 | /* | ||
116 | * register shadow for suspend | ||
117 | */ | ||
118 | struct dsps_context { | ||
119 | u32 control; | ||
120 | u32 epintr; | ||
121 | u32 coreintr; | ||
122 | u32 phy_utmi; | ||
123 | u32 mode; | ||
124 | u32 tx_mode; | ||
125 | u32 rx_mode; | ||
126 | }; | ||
127 | |||
113 | /** | 128 | /** |
114 | * DSPS glue structure. | 129 | * DSPS glue structure. |
115 | */ | 130 | */ |
@@ -119,6 +134,8 @@ struct dsps_glue { | |||
119 | const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */ | 134 | const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */ |
120 | struct timer_list timer; /* otg_workaround timer */ | 135 | struct timer_list timer; /* otg_workaround timer */ |
121 | unsigned long last_timer; /* last timer data for each instance */ | 136 | unsigned long last_timer; /* last timer data for each instance */ |
137 | |||
138 | struct dsps_context context; | ||
122 | }; | 139 | }; |
123 | 140 | ||
124 | static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) | 141 | static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) |
@@ -341,8 +358,9 @@ static irqreturn_t dsps_interrupt(int irq, void *hci) | |||
341 | if (musb->int_tx || musb->int_rx || musb->int_usb) | 358 | if (musb->int_tx || musb->int_rx || musb->int_usb) |
342 | ret |= musb_interrupt(musb); | 359 | ret |= musb_interrupt(musb); |
343 | 360 | ||
344 | /* Poll for ID change */ | 361 | /* Poll for ID change in OTG port mode */ |
345 | if (musb->xceiv->state == OTG_STATE_B_IDLE) | 362 | if (musb->xceiv->state == OTG_STATE_B_IDLE && |
363 | musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) | ||
346 | mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); | 364 | mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); |
347 | out: | 365 | out: |
348 | spin_unlock_irqrestore(&musb->lock, flags); | 366 | spin_unlock_irqrestore(&musb->lock, flags); |
@@ -406,6 +424,54 @@ static int dsps_musb_exit(struct musb *musb) | |||
406 | return 0; | 424 | return 0; |
407 | } | 425 | } |
408 | 426 | ||
427 | static int dsps_musb_set_mode(struct musb *musb, u8 mode) | ||
428 | { | ||
429 | struct device *dev = musb->controller; | ||
430 | struct dsps_glue *glue = dev_get_drvdata(dev->parent); | ||
431 | const struct dsps_musb_wrapper *wrp = glue->wrp; | ||
432 | void __iomem *ctrl_base = musb->ctrl_base; | ||
433 | void __iomem *base = musb->mregs; | ||
434 | u32 reg; | ||
435 | |||
436 | reg = dsps_readl(base, wrp->mode); | ||
437 | |||
438 | switch (mode) { | ||
439 | case MUSB_HOST: | ||
440 | reg &= ~(1 << wrp->iddig); | ||
441 | |||
442 | /* | ||
443 | * if we're setting mode to host-only or device-only, we're | ||
444 | * going to ignore whatever the PHY sends us and just force | ||
445 | * ID pin status by SW | ||
446 | */ | ||
447 | reg |= (1 << wrp->iddig_mux); | ||
448 | |||
449 | dsps_writel(base, wrp->mode, reg); | ||
450 | dsps_writel(ctrl_base, wrp->phy_utmi, 0x02); | ||
451 | break; | ||
452 | case MUSB_PERIPHERAL: | ||
453 | reg |= (1 << wrp->iddig); | ||
454 | |||
455 | /* | ||
456 | * if we're setting mode to host-only or device-only, we're | ||
457 | * going to ignore whatever the PHY sends us and just force | ||
458 | * ID pin status by SW | ||
459 | */ | ||
460 | reg |= (1 << wrp->iddig_mux); | ||
461 | |||
462 | dsps_writel(base, wrp->mode, reg); | ||
463 | break; | ||
464 | case MUSB_OTG: | ||
465 | dsps_writel(base, wrp->phy_utmi, 0x02); | ||
466 | break; | ||
467 | default: | ||
468 | dev_err(glue->dev, "unsupported mode %d\n", mode); | ||
469 | return -EINVAL; | ||
470 | } | ||
471 | |||
472 | return 0; | ||
473 | } | ||
474 | |||
409 | static struct musb_platform_ops dsps_ops = { | 475 | static struct musb_platform_ops dsps_ops = { |
410 | .init = dsps_musb_init, | 476 | .init = dsps_musb_init, |
411 | .exit = dsps_musb_exit, | 477 | .exit = dsps_musb_exit, |
@@ -414,6 +480,7 @@ static struct musb_platform_ops dsps_ops = { | |||
414 | .disable = dsps_musb_disable, | 480 | .disable = dsps_musb_disable, |
415 | 481 | ||
416 | .try_idle = dsps_musb_try_idle, | 482 | .try_idle = dsps_musb_try_idle, |
483 | .set_mode = dsps_musb_set_mode, | ||
417 | }; | 484 | }; |
418 | 485 | ||
419 | static u64 musb_dmamask = DMA_BIT_MASK(32); | 486 | static u64 musb_dmamask = DMA_BIT_MASK(32); |
@@ -507,6 +574,7 @@ static int dsps_create_musb_pdev(struct dsps_glue *glue, | |||
507 | 574 | ||
508 | config->num_eps = get_int_prop(dn, "mentor,num-eps"); | 575 | config->num_eps = get_int_prop(dn, "mentor,num-eps"); |
509 | config->ram_bits = get_int_prop(dn, "mentor,ram-bits"); | 576 | config->ram_bits = get_int_prop(dn, "mentor,ram-bits"); |
577 | config->host_port_deassert_reset_at_resume = 1; | ||
510 | pdata.mode = get_musb_port_mode(dev); | 578 | pdata.mode = get_musb_port_mode(dev); |
511 | /* DT keeps this entry in mA, musb expects it as per USB spec */ | 579 | /* DT keeps this entry in mA, musb expects it as per USB spec */ |
512 | pdata.power = get_int_prop(dn, "mentor,power") / 2; | 580 | pdata.power = get_int_prop(dn, "mentor,power") / 2; |
@@ -605,9 +673,12 @@ static const struct dsps_musb_wrapper am33xx_driver_data = { | |||
605 | .coreintr_status = 0x34, | 673 | .coreintr_status = 0x34, |
606 | .phy_utmi = 0xe0, | 674 | .phy_utmi = 0xe0, |
607 | .mode = 0xe8, | 675 | .mode = 0xe8, |
676 | .tx_mode = 0x70, | ||
677 | .rx_mode = 0x74, | ||
608 | .reset = 0, | 678 | .reset = 0, |
609 | .otg_disable = 21, | 679 | .otg_disable = 21, |
610 | .iddig = 8, | 680 | .iddig = 8, |
681 | .iddig_mux = 7, | ||
611 | .usb_shift = 0, | 682 | .usb_shift = 0, |
612 | .usb_mask = 0x1ff, | 683 | .usb_mask = 0x1ff, |
613 | .usb_bitmap = (0x1ff << 0), | 684 | .usb_bitmap = (0x1ff << 0), |
@@ -628,11 +699,52 @@ static const struct of_device_id musb_dsps_of_match[] = { | |||
628 | }; | 699 | }; |
629 | MODULE_DEVICE_TABLE(of, musb_dsps_of_match); | 700 | MODULE_DEVICE_TABLE(of, musb_dsps_of_match); |
630 | 701 | ||
702 | #ifdef CONFIG_PM | ||
703 | static int dsps_suspend(struct device *dev) | ||
704 | { | ||
705 | struct dsps_glue *glue = dev_get_drvdata(dev); | ||
706 | const struct dsps_musb_wrapper *wrp = glue->wrp; | ||
707 | struct musb *musb = platform_get_drvdata(glue->musb); | ||
708 | void __iomem *mbase = musb->ctrl_base; | ||
709 | |||
710 | glue->context.control = dsps_readl(mbase, wrp->control); | ||
711 | glue->context.epintr = dsps_readl(mbase, wrp->epintr_set); | ||
712 | glue->context.coreintr = dsps_readl(mbase, wrp->coreintr_set); | ||
713 | glue->context.phy_utmi = dsps_readl(mbase, wrp->phy_utmi); | ||
714 | glue->context.mode = dsps_readl(mbase, wrp->mode); | ||
715 | glue->context.tx_mode = dsps_readl(mbase, wrp->tx_mode); | ||
716 | glue->context.rx_mode = dsps_readl(mbase, wrp->rx_mode); | ||
717 | |||
718 | return 0; | ||
719 | } | ||
720 | |||
721 | static int dsps_resume(struct device *dev) | ||
722 | { | ||
723 | struct dsps_glue *glue = dev_get_drvdata(dev); | ||
724 | const struct dsps_musb_wrapper *wrp = glue->wrp; | ||
725 | struct musb *musb = platform_get_drvdata(glue->musb); | ||
726 | void __iomem *mbase = musb->ctrl_base; | ||
727 | |||
728 | dsps_writel(mbase, wrp->control, glue->context.control); | ||
729 | dsps_writel(mbase, wrp->epintr_set, glue->context.epintr); | ||
730 | dsps_writel(mbase, wrp->coreintr_set, glue->context.coreintr); | ||
731 | dsps_writel(mbase, wrp->phy_utmi, glue->context.phy_utmi); | ||
732 | dsps_writel(mbase, wrp->mode, glue->context.mode); | ||
733 | dsps_writel(mbase, wrp->tx_mode, glue->context.tx_mode); | ||
734 | dsps_writel(mbase, wrp->rx_mode, glue->context.rx_mode); | ||
735 | |||
736 | return 0; | ||
737 | } | ||
738 | #endif | ||
739 | |||
740 | static SIMPLE_DEV_PM_OPS(dsps_pm_ops, dsps_suspend, dsps_resume); | ||
741 | |||
631 | static struct platform_driver dsps_usbss_driver = { | 742 | static struct platform_driver dsps_usbss_driver = { |
632 | .probe = dsps_probe, | 743 | .probe = dsps_probe, |
633 | .remove = dsps_remove, | 744 | .remove = dsps_remove, |
634 | .driver = { | 745 | .driver = { |
635 | .name = "musb-dsps", | 746 | .name = "musb-dsps", |
747 | .pm = &dsps_pm_ops, | ||
636 | .of_match_table = musb_dsps_of_match, | 748 | .of_match_table = musb_dsps_of_match, |
637 | }, | 749 | }, |
638 | }; | 750 | }; |
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index 32fb057c03f5..d4aa779339f1 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c | |||
@@ -1727,14 +1727,14 @@ init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 epnum, int is_in) | |||
1727 | ep->end_point.name = ep->name; | 1727 | ep->end_point.name = ep->name; |
1728 | INIT_LIST_HEAD(&ep->end_point.ep_list); | 1728 | INIT_LIST_HEAD(&ep->end_point.ep_list); |
1729 | if (!epnum) { | 1729 | if (!epnum) { |
1730 | ep->end_point.maxpacket = 64; | 1730 | usb_ep_set_maxpacket_limit(&ep->end_point, 64); |
1731 | ep->end_point.ops = &musb_g_ep0_ops; | 1731 | ep->end_point.ops = &musb_g_ep0_ops; |
1732 | musb->g.ep0 = &ep->end_point; | 1732 | musb->g.ep0 = &ep->end_point; |
1733 | } else { | 1733 | } else { |
1734 | if (is_in) | 1734 | if (is_in) |
1735 | ep->end_point.maxpacket = hw_ep->max_packet_sz_tx; | 1735 | usb_ep_set_maxpacket_limit(&ep->end_point, hw_ep->max_packet_sz_tx); |
1736 | else | 1736 | else |
1737 | ep->end_point.maxpacket = hw_ep->max_packet_sz_rx; | 1737 | usb_ep_set_maxpacket_limit(&ep->end_point, hw_ep->max_packet_sz_rx); |
1738 | ep->end_point.ops = &musb_ep_ops; | 1738 | ep->end_point.ops = &musb_ep_ops; |
1739 | list_add_tail(&ep->end_point.ep_list, &musb->g.ep_list); | 1739 | list_add_tail(&ep->end_point.ep_list, &musb->g.ep_list); |
1740 | } | 1740 | } |
@@ -2119,7 +2119,15 @@ __acquires(musb->lock) | |||
2119 | /* Normal reset, as B-Device; | 2119 | /* Normal reset, as B-Device; |
2120 | * or else after HNP, as A-Device | 2120 | * or else after HNP, as A-Device |
2121 | */ | 2121 | */ |
2122 | if (devctl & MUSB_DEVCTL_BDEVICE) { | 2122 | if (!musb->g.is_otg) { |
2123 | /* USB device controllers that are not OTG compatible | ||
2124 | * may not have DEVCTL register in silicon. | ||
2125 | * In that case, do not rely on devctl for setting | ||
2126 | * peripheral mode. | ||
2127 | */ | ||
2128 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | ||
2129 | musb->g.is_a_peripheral = 0; | ||
2130 | } else if (devctl & MUSB_DEVCTL_BDEVICE) { | ||
2123 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 2131 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; |
2124 | musb->g.is_a_peripheral = 0; | 2132 | musb->g.is_a_peripheral = 0; |
2125 | } else { | 2133 | } else { |
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c index 6582a20bec05..ed455724017b 100644 --- a/drivers/usb/musb/musb_host.c +++ b/drivers/usb/musb/musb_host.c | |||
@@ -39,7 +39,6 @@ | |||
39 | #include <linux/sched.h> | 39 | #include <linux/sched.h> |
40 | #include <linux/slab.h> | 40 | #include <linux/slab.h> |
41 | #include <linux/errno.h> | 41 | #include <linux/errno.h> |
42 | #include <linux/init.h> | ||
43 | #include <linux/list.h> | 42 | #include <linux/list.h> |
44 | #include <linux/dma-mapping.h> | 43 | #include <linux/dma-mapping.h> |
45 | 44 | ||
@@ -2013,7 +2012,7 @@ static int musb_schedule( | |||
2013 | head = &musb->out_bulk; | 2012 | head = &musb->out_bulk; |
2014 | 2013 | ||
2015 | /* Enable bulk RX/TX NAK timeout scheme when bulk requests are | 2014 | /* Enable bulk RX/TX NAK timeout scheme when bulk requests are |
2016 | * multiplexed. This scheme doen't work in high speed to full | 2015 | * multiplexed. This scheme does not work in high speed to full |
2017 | * speed scenario as NAK interrupts are not coming from a | 2016 | * speed scenario as NAK interrupts are not coming from a |
2018 | * full speed device connected to a high speed device. | 2017 | * full speed device connected to a high speed device. |
2019 | * NAK timeout interval is 8 (128 uframe or 16ms) for HS and | 2018 | * NAK timeout interval is 8 (128 uframe or 16ms) for HS and |
@@ -2433,6 +2432,8 @@ static int musb_bus_suspend(struct usb_hcd *hcd) | |||
2433 | struct musb *musb = hcd_to_musb(hcd); | 2432 | struct musb *musb = hcd_to_musb(hcd); |
2434 | u8 devctl; | 2433 | u8 devctl; |
2435 | 2434 | ||
2435 | musb_port_suspend(musb, true); | ||
2436 | |||
2436 | if (!is_host_active(musb)) | 2437 | if (!is_host_active(musb)) |
2437 | return 0; | 2438 | return 0; |
2438 | 2439 | ||
@@ -2462,7 +2463,12 @@ static int musb_bus_suspend(struct usb_hcd *hcd) | |||
2462 | 2463 | ||
2463 | static int musb_bus_resume(struct usb_hcd *hcd) | 2464 | static int musb_bus_resume(struct usb_hcd *hcd) |
2464 | { | 2465 | { |
2465 | /* resuming child port does the work */ | 2466 | struct musb *musb = hcd_to_musb(hcd); |
2467 | |||
2468 | if (musb->config && | ||
2469 | musb->config->host_port_deassert_reset_at_resume) | ||
2470 | musb_port_reset(musb, false); | ||
2471 | |||
2466 | return 0; | 2472 | return 0; |
2467 | } | 2473 | } |
2468 | 2474 | ||
@@ -2657,6 +2663,7 @@ int musb_host_setup(struct musb *musb, int power_budget) | |||
2657 | if (ret < 0) | 2663 | if (ret < 0) |
2658 | return ret; | 2664 | return ret; |
2659 | 2665 | ||
2666 | device_wakeup_enable(hcd->self.controller); | ||
2660 | return 0; | 2667 | return 0; |
2661 | } | 2668 | } |
2662 | 2669 | ||
diff --git a/drivers/usb/musb/musb_host.h b/drivers/usb/musb/musb_host.h index 960d73570b2f..7bbf01bf4bb0 100644 --- a/drivers/usb/musb/musb_host.h +++ b/drivers/usb/musb/musb_host.h | |||
@@ -92,6 +92,9 @@ extern void musb_host_rx(struct musb *, u8); | |||
92 | extern void musb_root_disconnect(struct musb *musb); | 92 | extern void musb_root_disconnect(struct musb *musb); |
93 | extern void musb_host_resume_root_hub(struct musb *musb); | 93 | extern void musb_host_resume_root_hub(struct musb *musb); |
94 | extern void musb_host_poke_root_hub(struct musb *musb); | 94 | extern void musb_host_poke_root_hub(struct musb *musb); |
95 | extern void musb_port_suspend(struct musb *musb, bool do_suspend); | ||
96 | extern void musb_port_reset(struct musb *musb, bool do_reset); | ||
97 | extern void musb_host_finish_resume(struct work_struct *work); | ||
95 | #else | 98 | #else |
96 | static inline struct musb *hcd_to_musb(struct usb_hcd *hcd) | 99 | static inline struct musb *hcd_to_musb(struct usb_hcd *hcd) |
97 | { | 100 | { |
@@ -121,6 +124,9 @@ static inline void musb_root_disconnect(struct musb *musb) {} | |||
121 | static inline void musb_host_resume_root_hub(struct musb *musb) {} | 124 | static inline void musb_host_resume_root_hub(struct musb *musb) {} |
122 | static inline void musb_host_poll_rh_status(struct musb *musb) {} | 125 | static inline void musb_host_poll_rh_status(struct musb *musb) {} |
123 | static inline void musb_host_poke_root_hub(struct musb *musb) {} | 126 | static inline void musb_host_poke_root_hub(struct musb *musb) {} |
127 | static inline void musb_port_suspend(struct musb *musb, bool do_suspend) {} | ||
128 | static inline void musb_port_reset(struct musb *musb, bool do_reset) {} | ||
129 | static inline void musb_host_finish_resume(struct work_struct *work) {} | ||
124 | #endif | 130 | #endif |
125 | 131 | ||
126 | struct usb_hcd; | 132 | struct usb_hcd; |
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c index 9af6bba5eac9..eb634433ef09 100644 --- a/drivers/usb/musb/musb_virthub.c +++ b/drivers/usb/musb/musb_virthub.c | |||
@@ -36,7 +36,6 @@ | |||
36 | #include <linux/kernel.h> | 36 | #include <linux/kernel.h> |
37 | #include <linux/sched.h> | 37 | #include <linux/sched.h> |
38 | #include <linux/errno.h> | 38 | #include <linux/errno.h> |
39 | #include <linux/init.h> | ||
40 | #include <linux/time.h> | 39 | #include <linux/time.h> |
41 | #include <linux/timer.h> | 40 | #include <linux/timer.h> |
42 | 41 | ||
@@ -44,7 +43,38 @@ | |||
44 | 43 | ||
45 | #include "musb_core.h" | 44 | #include "musb_core.h" |
46 | 45 | ||
47 | static void musb_port_suspend(struct musb *musb, bool do_suspend) | 46 | void musb_host_finish_resume(struct work_struct *work) |
47 | { | ||
48 | struct musb *musb; | ||
49 | unsigned long flags; | ||
50 | u8 power; | ||
51 | |||
52 | musb = container_of(work, struct musb, finish_resume_work.work); | ||
53 | |||
54 | spin_lock_irqsave(&musb->lock, flags); | ||
55 | |||
56 | power = musb_readb(musb->mregs, MUSB_POWER); | ||
57 | power &= ~MUSB_POWER_RESUME; | ||
58 | dev_dbg(musb->controller, "root port resume stopped, power %02x\n", | ||
59 | power); | ||
60 | musb_writeb(musb->mregs, MUSB_POWER, power); | ||
61 | |||
62 | /* | ||
63 | * ISSUE: DaVinci (RTL 1.300) disconnects after | ||
64 | * resume of high speed peripherals (but not full | ||
65 | * speed ones). | ||
66 | */ | ||
67 | musb->is_active = 1; | ||
68 | musb->port1_status &= ~(USB_PORT_STAT_SUSPEND | MUSB_PORT_STAT_RESUME); | ||
69 | musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; | ||
70 | usb_hcd_poll_rh_status(musb->hcd); | ||
71 | /* NOTE: it might really be A_WAIT_BCON ... */ | ||
72 | musb->xceiv->state = OTG_STATE_A_HOST; | ||
73 | |||
74 | spin_unlock_irqrestore(&musb->lock, flags); | ||
75 | } | ||
76 | |||
77 | void musb_port_suspend(struct musb *musb, bool do_suspend) | ||
48 | { | 78 | { |
49 | struct usb_otg *otg = musb->xceiv->otg; | 79 | struct usb_otg *otg = musb->xceiv->otg; |
50 | u8 power; | 80 | u8 power; |
@@ -105,11 +135,11 @@ static void musb_port_suspend(struct musb *musb, bool do_suspend) | |||
105 | 135 | ||
106 | /* later, GetPortStatus will stop RESUME signaling */ | 136 | /* later, GetPortStatus will stop RESUME signaling */ |
107 | musb->port1_status |= MUSB_PORT_STAT_RESUME; | 137 | musb->port1_status |= MUSB_PORT_STAT_RESUME; |
108 | musb->rh_timer = jiffies + msecs_to_jiffies(20); | 138 | schedule_delayed_work(&musb->finish_resume_work, 20); |
109 | } | 139 | } |
110 | } | 140 | } |
111 | 141 | ||
112 | static void musb_port_reset(struct musb *musb, bool do_reset) | 142 | void musb_port_reset(struct musb *musb, bool do_reset) |
113 | { | 143 | { |
114 | u8 power; | 144 | u8 power; |
115 | void __iomem *mbase = musb->mregs; | 145 | void __iomem *mbase = musb->mregs; |
@@ -150,7 +180,7 @@ static void musb_port_reset(struct musb *musb, bool do_reset) | |||
150 | 180 | ||
151 | musb->port1_status |= USB_PORT_STAT_RESET; | 181 | musb->port1_status |= USB_PORT_STAT_RESET; |
152 | musb->port1_status &= ~USB_PORT_STAT_ENABLE; | 182 | musb->port1_status &= ~USB_PORT_STAT_ENABLE; |
153 | musb->rh_timer = jiffies + msecs_to_jiffies(50); | 183 | schedule_delayed_work(&musb->deassert_reset_work, 50); |
154 | } else { | 184 | } else { |
155 | dev_dbg(musb->controller, "root port reset stopped\n"); | 185 | dev_dbg(musb->controller, "root port reset stopped\n"); |
156 | musb_writeb(mbase, MUSB_POWER, | 186 | musb_writeb(mbase, MUSB_POWER, |
@@ -325,36 +355,6 @@ int musb_hub_control( | |||
325 | if (wIndex != 1) | 355 | if (wIndex != 1) |
326 | goto error; | 356 | goto error; |
327 | 357 | ||
328 | /* finish RESET signaling? */ | ||
329 | if ((musb->port1_status & USB_PORT_STAT_RESET) | ||
330 | && time_after_eq(jiffies, musb->rh_timer)) | ||
331 | musb_port_reset(musb, false); | ||
332 | |||
333 | /* finish RESUME signaling? */ | ||
334 | if ((musb->port1_status & MUSB_PORT_STAT_RESUME) | ||
335 | && time_after_eq(jiffies, musb->rh_timer)) { | ||
336 | u8 power; | ||
337 | |||
338 | power = musb_readb(musb->mregs, MUSB_POWER); | ||
339 | power &= ~MUSB_POWER_RESUME; | ||
340 | dev_dbg(musb->controller, "root port resume stopped, power %02x\n", | ||
341 | power); | ||
342 | musb_writeb(musb->mregs, MUSB_POWER, power); | ||
343 | |||
344 | /* ISSUE: DaVinci (RTL 1.300) disconnects after | ||
345 | * resume of high speed peripherals (but not full | ||
346 | * speed ones). | ||
347 | */ | ||
348 | |||
349 | musb->is_active = 1; | ||
350 | musb->port1_status &= ~(USB_PORT_STAT_SUSPEND | ||
351 | | MUSB_PORT_STAT_RESUME); | ||
352 | musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; | ||
353 | usb_hcd_poll_rh_status(musb->hcd); | ||
354 | /* NOTE: it might really be A_WAIT_BCON ... */ | ||
355 | musb->xceiv->state = OTG_STATE_A_HOST; | ||
356 | } | ||
357 | |||
358 | put_unaligned(cpu_to_le32(musb->port1_status | 358 | put_unaligned(cpu_to_le32(musb->port1_status |
359 | & ~MUSB_PORT_STAT_RESUME), | 359 | & ~MUSB_PORT_STAT_RESUME), |
360 | (__le32 *) buf); | 360 | (__le32 *) buf); |
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c index 4432314d70ee..4e9fb1d08698 100644 --- a/drivers/usb/musb/tusb6010.c +++ b/drivers/usb/musb/tusb6010.c | |||
@@ -18,7 +18,6 @@ | |||
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/err.h> | 20 | #include <linux/err.h> |
21 | #include <linux/init.h> | ||
22 | #include <linux/prefetch.h> | 21 | #include <linux/prefetch.h> |
23 | #include <linux/usb.h> | 22 | #include <linux/usb.h> |
24 | #include <linux/irq.h> | 23 | #include <linux/irq.h> |
diff --git a/drivers/usb/musb/tusb6010_omap.c b/drivers/usb/musb/tusb6010_omap.c index b8794eb81e9c..e33b6b2c44c2 100644 --- a/drivers/usb/musb/tusb6010_omap.c +++ b/drivers/usb/musb/tusb6010_omap.c | |||
@@ -11,7 +11,6 @@ | |||
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/errno.h> | 13 | #include <linux/errno.h> |
14 | #include <linux/init.h> | ||
15 | #include <linux/usb.h> | 14 | #include <linux/usb.h> |
16 | #include <linux/platform_device.h> | 15 | #include <linux/platform_device.h> |
17 | #include <linux/dma-mapping.h> | 16 | #include <linux/dma-mapping.h> |
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c index 122446bf1664..c2e45e632723 100644 --- a/drivers/usb/musb/ux500.c +++ b/drivers/usb/musb/ux500.c | |||
@@ -21,7 +21,6 @@ | |||
21 | 21 | ||
22 | #include <linux/module.h> | 22 | #include <linux/module.h> |
23 | #include <linux/kernel.h> | 23 | #include <linux/kernel.h> |
24 | #include <linux/init.h> | ||
25 | #include <linux/clk.h> | 24 | #include <linux/clk.h> |
26 | #include <linux/err.h> | 25 | #include <linux/err.h> |
27 | #include <linux/io.h> | 26 | #include <linux/io.h> |
diff --git a/drivers/usb/musb/ux500_dma.c b/drivers/usb/musb/ux500_dma.c index 3700e9713258..9aad00f11bd5 100644 --- a/drivers/usb/musb/ux500_dma.c +++ b/drivers/usb/musb/ux500_dma.c | |||
@@ -336,7 +336,9 @@ static int ux500_dma_controller_start(struct ux500_dma_controller *controller) | |||
336 | data ? | 336 | data ? |
337 | data->dma_filter : | 337 | data->dma_filter : |
338 | NULL, | 338 | NULL, |
339 | param_array[ch_num]); | 339 | param_array ? |
340 | param_array[ch_num] : | ||
341 | NULL); | ||
340 | 342 | ||
341 | if (!ux500_channel->dma_chan) { | 343 | if (!ux500_channel->dma_chan) { |
342 | ERR("Dma pipe allocation error dir=%d ch=%d\n", | 344 | ERR("Dma pipe allocation error dir=%d ch=%d\n", |
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 2b41c636a52a..7d1451d5bbea 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig | |||
@@ -6,6 +6,15 @@ menu "USB Physical Layer drivers" | |||
6 | config USB_PHY | 6 | config USB_PHY |
7 | def_bool n | 7 | def_bool n |
8 | 8 | ||
9 | config USB_OTG_FSM | ||
10 | tristate "USB 2.0 OTG FSM implementation" | ||
11 | depends on USB | ||
12 | select USB_OTG | ||
13 | select USB_PHY | ||
14 | help | ||
15 | Implements OTG Final State Machine as specified in On-The-Go | ||
16 | and Embedded Host Supplement to the USB Revision 2.0 Specification. | ||
17 | |||
9 | # | 18 | # |
10 | # USB Transceiver Drivers | 19 | # USB Transceiver Drivers |
11 | # | 20 | # |
@@ -19,9 +28,8 @@ config AB8500_USB | |||
19 | in host mode, low speed. | 28 | in host mode, low speed. |
20 | 29 | ||
21 | config FSL_USB2_OTG | 30 | config FSL_USB2_OTG |
22 | tristate "Freescale USB OTG Transceiver Driver" | 31 | bool "Freescale USB OTG Transceiver Driver" |
23 | depends on USB_EHCI_FSL && USB_FSL_USB2 && PM_RUNTIME | 32 | depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_OTG_FSM && PM_RUNTIME |
24 | depends on USB | ||
25 | select USB_OTG | 33 | select USB_OTG |
26 | select USB_PHY | 34 | select USB_PHY |
27 | help | 35 | help |
@@ -40,7 +48,16 @@ config ISP1301_OMAP | |||
40 | Instruments OMAP processors. | 48 | Instruments OMAP processors. |
41 | 49 | ||
42 | This driver can also be built as a module. If so, the module | 50 | This driver can also be built as a module. If so, the module |
43 | will be called isp1301_omap. | 51 | will be called phy-isp1301-omap. |
52 | |||
53 | config KEYSTONE_USB_PHY | ||
54 | tristate "Keystone USB PHY Driver" | ||
55 | depends on ARCH_KEYSTONE || COMPILE_TEST | ||
56 | select NOP_USB_XCEIV | ||
57 | help | ||
58 | Enable this to support Keystone USB phy. This driver provides | ||
59 | interface to interact with USB 2.0 and USB 3.0 PHY that is part | ||
60 | of the Keystone SOC. | ||
44 | 61 | ||
45 | config MV_U3D_PHY | 62 | config MV_U3D_PHY |
46 | bool "Marvell USB 3.0 PHY controller Driver" | 63 | bool "Marvell USB 3.0 PHY controller Driver" |
@@ -136,6 +153,31 @@ config USB_GPIO_VBUS | |||
136 | optionally control of a D+ pullup GPIO as well as a VBUS | 153 | optionally control of a D+ pullup GPIO as well as a VBUS |
137 | current limit regulator. | 154 | current limit regulator. |
138 | 155 | ||
156 | config OMAP_OTG | ||
157 | tristate "OMAP USB OTG controller driver" | ||
158 | depends on ARCH_OMAP_OTG && EXTCON | ||
159 | help | ||
160 | Enable this to support some transceivers on OMAP1 platforms. OTG | ||
161 | controller is needed to switch between host and peripheral modes. | ||
162 | |||
163 | This driver can also be built as a module. If so, the module | ||
164 | will be called phy-omap-otg. | ||
165 | |||
166 | config TAHVO_USB | ||
167 | tristate "Tahvo USB transceiver driver" | ||
168 | depends on MFD_RETU && EXTCON | ||
169 | select USB_PHY | ||
170 | help | ||
171 | Enable this to support USB transceiver on Tahvo. This is used | ||
172 | at least on Nokia 770. | ||
173 | |||
174 | config TAHVO_USB_HOST_BY_DEFAULT | ||
175 | depends on TAHVO_USB | ||
176 | boolean "Device in USB host mode by default" | ||
177 | help | ||
178 | Say Y here, if you want the device to enter USB host mode | ||
179 | by default on bootup. | ||
180 | |||
139 | config USB_ISP1301 | 181 | config USB_ISP1301 |
140 | tristate "NXP ISP1301 USB transceiver support" | 182 | tristate "NXP ISP1301 USB transceiver support" |
141 | depends on USB || USB_GADGET | 183 | depends on USB || USB_GADGET |
@@ -147,7 +189,7 @@ config USB_ISP1301 | |||
147 | and OTG drivers (to be selected separately). | 189 | and OTG drivers (to be selected separately). |
148 | 190 | ||
149 | To compile this driver as a module, choose M here: the | 191 | To compile this driver as a module, choose M here: the |
150 | module will be called isp1301. | 192 | module will be called phy-isp1301. |
151 | 193 | ||
152 | config USB_MSM_OTG | 194 | config USB_MSM_OTG |
153 | tristate "OTG support for Qualcomm on-chip USB controller" | 195 | tristate "OTG support for Qualcomm on-chip USB controller" |
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 022c1da7fb78..be58adae3496 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile | |||
@@ -3,18 +3,20 @@ | |||
3 | # | 3 | # |
4 | obj-$(CONFIG_USB_PHY) += phy.o | 4 | obj-$(CONFIG_USB_PHY) += phy.o |
5 | obj-$(CONFIG_OF) += of.o | 5 | obj-$(CONFIG_OF) += of.o |
6 | obj-$(CONFIG_USB_OTG_FSM) += phy-fsm-usb.o | ||
6 | 7 | ||
7 | # transceiver drivers, keep the list sorted | 8 | # transceiver drivers, keep the list sorted |
8 | 9 | ||
9 | obj-$(CONFIG_AB8500_USB) += phy-ab8500-usb.o | 10 | obj-$(CONFIG_AB8500_USB) += phy-ab8500-usb.o |
10 | phy-fsl-usb2-objs := phy-fsl-usb.o phy-fsm-usb.o | 11 | obj-$(CONFIG_FSL_USB2_OTG) += phy-fsl-usb.o |
11 | obj-$(CONFIG_FSL_USB2_OTG) += phy-fsl-usb2.o | ||
12 | obj-$(CONFIG_ISP1301_OMAP) += phy-isp1301-omap.o | 12 | obj-$(CONFIG_ISP1301_OMAP) += phy-isp1301-omap.o |
13 | obj-$(CONFIG_MV_U3D_PHY) += phy-mv-u3d-usb.o | 13 | obj-$(CONFIG_MV_U3D_PHY) += phy-mv-u3d-usb.o |
14 | obj-$(CONFIG_NOP_USB_XCEIV) += phy-generic.o | 14 | obj-$(CONFIG_NOP_USB_XCEIV) += phy-generic.o |
15 | obj-$(CONFIG_TAHVO_USB) += phy-tahvo.o | ||
15 | obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o | 16 | obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o |
16 | obj-$(CONFIG_AM335X_CONTROL_USB) += phy-am335x-control.o | 17 | obj-$(CONFIG_AM335X_CONTROL_USB) += phy-am335x-control.o |
17 | obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o | 18 | obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o |
19 | obj-$(CONFIG_OMAP_OTG) += phy-omap-otg.o | ||
18 | obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o | 20 | obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o |
19 | obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o | 21 | obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o |
20 | obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o | 22 | obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o |
@@ -30,3 +32,4 @@ obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o | |||
30 | obj-$(CONFIG_USB_RCAR_GEN2_PHY) += phy-rcar-gen2-usb.o | 32 | obj-$(CONFIG_USB_RCAR_GEN2_PHY) += phy-rcar-gen2-usb.o |
31 | obj-$(CONFIG_USB_ULPI) += phy-ulpi.o | 33 | obj-$(CONFIG_USB_ULPI) += phy-ulpi.o |
32 | obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o | 34 | obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o |
35 | obj-$(CONFIG_KEYSTONE_USB_PHY) += phy-keystone.o | ||
diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c index 087402350b6d..11ab2c45e462 100644 --- a/drivers/usb/phy/phy-ab8500-usb.c +++ b/drivers/usb/phy/phy-ab8500-usb.c | |||
@@ -1415,8 +1415,6 @@ static int ab8500_usb_probe(struct platform_device *pdev) | |||
1415 | 1415 | ||
1416 | platform_set_drvdata(pdev, ab); | 1416 | platform_set_drvdata(pdev, ab); |
1417 | 1417 | ||
1418 | ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier); | ||
1419 | |||
1420 | /* all: Disable phy when called from set_host and set_peripheral */ | 1418 | /* all: Disable phy when called from set_host and set_peripheral */ |
1421 | INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work); | 1419 | INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work); |
1422 | 1420 | ||
diff --git a/drivers/usb/phy/phy-am335x-control.c b/drivers/usb/phy/phy-am335x-control.c index 634f49acd20e..d75196ad5f2f 100644 --- a/drivers/usb/phy/phy-am335x-control.c +++ b/drivers/usb/phy/phy-am335x-control.c | |||
@@ -3,11 +3,7 @@ | |||
3 | #include <linux/err.h> | 3 | #include <linux/err.h> |
4 | #include <linux/of.h> | 4 | #include <linux/of.h> |
5 | #include <linux/io.h> | 5 | #include <linux/io.h> |
6 | 6 | #include "am35x-phy-control.h" | |
7 | struct phy_control { | ||
8 | void (*phy_power)(struct phy_control *phy_ctrl, u32 id, bool on); | ||
9 | void (*phy_wkup)(struct phy_control *phy_ctrl, u32 id, bool on); | ||
10 | }; | ||
11 | 7 | ||
12 | struct am335x_control_usb { | 8 | struct am335x_control_usb { |
13 | struct device *dev; | 9 | struct device *dev; |
diff --git a/drivers/usb/phy/phy-am335x.c b/drivers/usb/phy/phy-am335x.c index 0e3c60cb669a..12fc3468a01e 100644 --- a/drivers/usb/phy/phy-am335x.c +++ b/drivers/usb/phy/phy-am335x.c | |||
@@ -63,6 +63,19 @@ static int am335x_phy_probe(struct platform_device *pdev) | |||
63 | am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown; | 63 | am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown; |
64 | 64 | ||
65 | platform_set_drvdata(pdev, am_phy); | 65 | platform_set_drvdata(pdev, am_phy); |
66 | device_init_wakeup(dev, true); | ||
67 | |||
68 | /* | ||
69 | * If we leave PHY wakeup enabled then AM33XX wakes up | ||
70 | * immediately from DS0. To avoid this we mark dev->power.can_wakeup | ||
71 | * to false. The same is checked in suspend routine to decide | ||
72 | * on whether to enable PHY wakeup or not. | ||
73 | * PHY wakeup works fine in standby mode, there by allowing us to | ||
74 | * handle remote wakeup, wakeup on disconnect and connect. | ||
75 | */ | ||
76 | |||
77 | device_set_wakeup_enable(dev, false); | ||
78 | phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); | ||
66 | 79 | ||
67 | return 0; | 80 | return 0; |
68 | } | 81 | } |
@@ -75,38 +88,48 @@ static int am335x_phy_remove(struct platform_device *pdev) | |||
75 | return 0; | 88 | return 0; |
76 | } | 89 | } |
77 | 90 | ||
78 | #ifdef CONFIG_PM_RUNTIME | 91 | #ifdef CONFIG_PM_SLEEP |
79 | 92 | static int am335x_phy_suspend(struct device *dev) | |
80 | static int am335x_phy_runtime_suspend(struct device *dev) | ||
81 | { | 93 | { |
82 | struct platform_device *pdev = to_platform_device(dev); | 94 | struct platform_device *pdev = to_platform_device(dev); |
83 | struct am335x_phy *am_phy = platform_get_drvdata(pdev); | 95 | struct am335x_phy *am_phy = platform_get_drvdata(pdev); |
84 | 96 | ||
97 | /* | ||
98 | * Enable phy wakeup only if dev->power.can_wakeup is true. | ||
99 | * Make sure to enable wakeup to support remote wakeup in | ||
100 | * standby mode ( same is not supported in OFF(DS0) mode). | ||
101 | * Enable it by doing | ||
102 | * echo enabled > /sys/bus/platform/devices/<usb-phy-id>/power/wakeup | ||
103 | */ | ||
104 | |||
85 | if (device_may_wakeup(dev)) | 105 | if (device_may_wakeup(dev)) |
86 | phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true); | 106 | phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true); |
107 | |||
87 | phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); | 108 | phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); |
109 | |||
88 | return 0; | 110 | return 0; |
89 | } | 111 | } |
90 | 112 | ||
91 | static int am335x_phy_runtime_resume(struct device *dev) | 113 | static int am335x_phy_resume(struct device *dev) |
92 | { | 114 | { |
93 | struct platform_device *pdev = to_platform_device(dev); | 115 | struct platform_device *pdev = to_platform_device(dev); |
94 | struct am335x_phy *am_phy = platform_get_drvdata(pdev); | 116 | struct am335x_phy *am_phy = platform_get_drvdata(pdev); |
95 | 117 | ||
96 | phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); | 118 | phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); |
119 | |||
97 | if (device_may_wakeup(dev)) | 120 | if (device_may_wakeup(dev)) |
98 | phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false); | 121 | phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false); |
122 | |||
99 | return 0; | 123 | return 0; |
100 | } | 124 | } |
101 | 125 | ||
102 | static const struct dev_pm_ops am335x_pm_ops = { | 126 | static const struct dev_pm_ops am335x_pm_ops = { |
103 | SET_RUNTIME_PM_OPS(am335x_phy_runtime_suspend, | 127 | SET_SYSTEM_SLEEP_PM_OPS(am335x_phy_suspend, am335x_phy_resume) |
104 | am335x_phy_runtime_resume, NULL) | ||
105 | }; | 128 | }; |
106 | 129 | ||
107 | #define DEV_PM_OPS (&am335x_pm_ops) | 130 | #define DEV_PM_OPS (&am335x_pm_ops) |
108 | #else | 131 | #else |
109 | #define DEV_PM_OPS NULL | 132 | #define DEV_PM_OPS NULL |
110 | #endif | 133 | #endif |
111 | 134 | ||
112 | static const struct of_device_id am335x_phy_ids[] = { | 135 | static const struct of_device_id am335x_phy_ids[] = { |
diff --git a/drivers/usb/phy/phy-fsl-usb.c b/drivers/usb/phy/phy-fsl-usb.c index 7f3c73b967ce..2b0f968d9325 100644 --- a/drivers/usb/phy/phy-fsl-usb.c +++ b/drivers/usb/phy/phy-fsl-usb.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | #include <linux/proc_fs.h> | 28 | #include <linux/proc_fs.h> |
29 | #include <linux/errno.h> | 29 | #include <linux/errno.h> |
30 | #include <linux/init.h> | ||
31 | #include <linux/interrupt.h> | 30 | #include <linux/interrupt.h> |
32 | #include <linux/io.h> | 31 | #include <linux/io.h> |
33 | #include <linux/timer.h> | 32 | #include <linux/timer.h> |
@@ -848,7 +847,7 @@ static int fsl_otg_conf(struct platform_device *pdev) | |||
848 | pr_info("Couldn't init OTG timers\n"); | 847 | pr_info("Couldn't init OTG timers\n"); |
849 | goto err; | 848 | goto err; |
850 | } | 849 | } |
851 | spin_lock_init(&fsl_otg_tc->fsm.lock); | 850 | mutex_init(&fsl_otg_tc->fsm.lock); |
852 | 851 | ||
853 | /* Set OTG state machine operations */ | 852 | /* Set OTG state machine operations */ |
854 | fsl_otg_tc->fsm.ops = &fsl_otg_ops; | 853 | fsl_otg_tc->fsm.ops = &fsl_otg_ops; |
@@ -1017,10 +1016,9 @@ static int show_fsl_usb2_otg_state(struct device *dev, | |||
1017 | struct otg_fsm *fsm = &fsl_otg_dev->fsm; | 1016 | struct otg_fsm *fsm = &fsl_otg_dev->fsm; |
1018 | char *next = buf; | 1017 | char *next = buf; |
1019 | unsigned size = PAGE_SIZE; | 1018 | unsigned size = PAGE_SIZE; |
1020 | unsigned long flags; | ||
1021 | int t; | 1019 | int t; |
1022 | 1020 | ||
1023 | spin_lock_irqsave(&fsm->lock, flags); | 1021 | mutex_lock(&fsm->lock); |
1024 | 1022 | ||
1025 | /* basic driver infomation */ | 1023 | /* basic driver infomation */ |
1026 | t = scnprintf(next, size, | 1024 | t = scnprintf(next, size, |
@@ -1088,7 +1086,7 @@ static int show_fsl_usb2_otg_state(struct device *dev, | |||
1088 | size -= t; | 1086 | size -= t; |
1089 | next += t; | 1087 | next += t; |
1090 | 1088 | ||
1091 | spin_unlock_irqrestore(&fsm->lock, flags); | 1089 | mutex_unlock(&fsm->lock); |
1092 | 1090 | ||
1093 | return PAGE_SIZE - size; | 1091 | return PAGE_SIZE - size; |
1094 | } | 1092 | } |
diff --git a/drivers/usb/phy/phy-fsl-usb.h b/drivers/usb/phy/phy-fsl-usb.h index 7365170a2f23..5986c96354df 100644 --- a/drivers/usb/phy/phy-fsl-usb.h +++ b/drivers/usb/phy/phy-fsl-usb.h | |||
@@ -15,7 +15,7 @@ | |||
15 | * 675 Mass Ave, Cambridge, MA 02139, USA. | 15 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "phy-fsm-usb.h" | 18 | #include <linux/usb/otg-fsm.h> |
19 | #include <linux/usb/otg.h> | 19 | #include <linux/usb/otg.h> |
20 | #include <linux/ioctl.h> | 20 | #include <linux/ioctl.h> |
21 | 21 | ||
diff --git a/drivers/usb/phy/phy-fsm-usb.c b/drivers/usb/phy/phy-fsm-usb.c index 329c2d2f8595..7aa314ef4a8a 100644 --- a/drivers/usb/phy/phy-fsm-usb.c +++ b/drivers/usb/phy/phy-fsm-usb.c | |||
@@ -23,13 +23,12 @@ | |||
23 | 23 | ||
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/types.h> | 25 | #include <linux/types.h> |
26 | #include <linux/spinlock.h> | 26 | #include <linux/mutex.h> |
27 | #include <linux/delay.h> | 27 | #include <linux/delay.h> |
28 | #include <linux/usb.h> | 28 | #include <linux/usb.h> |
29 | #include <linux/usb/gadget.h> | 29 | #include <linux/usb/gadget.h> |
30 | #include <linux/usb/otg.h> | 30 | #include <linux/usb/otg.h> |
31 | 31 | #include <linux/usb/otg-fsm.h> | |
32 | #include "phy-fsm-usb.h" | ||
33 | 32 | ||
34 | /* Change USB protocol when there is a protocol change */ | 33 | /* Change USB protocol when there is a protocol change */ |
35 | static int otg_set_protocol(struct otg_fsm *fsm, int protocol) | 34 | static int otg_set_protocol(struct otg_fsm *fsm, int protocol) |
@@ -65,7 +64,7 @@ static int otg_set_protocol(struct otg_fsm *fsm, int protocol) | |||
65 | static int state_changed; | 64 | static int state_changed; |
66 | 65 | ||
67 | /* Called when leaving a state. Do state clean up jobs here */ | 66 | /* Called when leaving a state. Do state clean up jobs here */ |
68 | void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state) | 67 | static void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state) |
69 | { | 68 | { |
70 | switch (old_state) { | 69 | switch (old_state) { |
71 | case OTG_STATE_B_IDLE: | 70 | case OTG_STATE_B_IDLE: |
@@ -122,7 +121,7 @@ void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state) | |||
122 | } | 121 | } |
123 | 122 | ||
124 | /* Called when entering a state */ | 123 | /* Called when entering a state */ |
125 | int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) | 124 | static int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) |
126 | { | 125 | { |
127 | state_changed = 1; | 126 | state_changed = 1; |
128 | if (fsm->otg->phy->state == new_state) | 127 | if (fsm->otg->phy->state == new_state) |
@@ -245,9 +244,8 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) | |||
245 | int otg_statemachine(struct otg_fsm *fsm) | 244 | int otg_statemachine(struct otg_fsm *fsm) |
246 | { | 245 | { |
247 | enum usb_otg_state state; | 246 | enum usb_otg_state state; |
248 | unsigned long flags; | ||
249 | 247 | ||
250 | spin_lock_irqsave(&fsm->lock, flags); | 248 | mutex_lock(&fsm->lock); |
251 | 249 | ||
252 | state = fsm->otg->phy->state; | 250 | state = fsm->otg->phy->state; |
253 | state_changed = 0; | 251 | state_changed = 0; |
@@ -359,7 +357,7 @@ int otg_statemachine(struct otg_fsm *fsm) | |||
359 | default: | 357 | default: |
360 | break; | 358 | break; |
361 | } | 359 | } |
362 | spin_unlock_irqrestore(&fsm->lock, flags); | 360 | mutex_unlock(&fsm->lock); |
363 | 361 | ||
364 | VDBG("quit statemachine, changed = %d\n", state_changed); | 362 | VDBG("quit statemachine, changed = %d\n", state_changed); |
365 | return state_changed; | 363 | return state_changed; |
diff --git a/drivers/usb/phy/phy-fsm-usb.h b/drivers/usb/phy/phy-fsm-usb.h deleted file mode 100644 index 7441b46a27f1..000000000000 --- a/drivers/usb/phy/phy-fsm-usb.h +++ /dev/null | |||
@@ -1,236 +0,0 @@ | |||
1 | /* Copyright (C) 2007,2008 Freescale Semiconductor, Inc. | ||
2 | * | ||
3 | * This program is free software; you can redistribute it and/or modify it | ||
4 | * under the terms of the GNU General Public License as published by the | ||
5 | * Free Software Foundation; either version 2 of the License, or (at your | ||
6 | * option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, but | ||
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | * General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License along | ||
14 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
16 | */ | ||
17 | |||
18 | #undef VERBOSE | ||
19 | |||
20 | #ifdef VERBOSE | ||
21 | #define VDBG(fmt, args...) pr_debug("[%s] " fmt , \ | ||
22 | __func__, ## args) | ||
23 | #else | ||
24 | #define VDBG(stuff...) do {} while (0) | ||
25 | #endif | ||
26 | |||
27 | #ifdef VERBOSE | ||
28 | #define MPC_LOC printk("Current Location [%s]:[%d]\n", __FILE__, __LINE__) | ||
29 | #else | ||
30 | #define MPC_LOC do {} while (0) | ||
31 | #endif | ||
32 | |||
33 | #define PROTO_UNDEF (0) | ||
34 | #define PROTO_HOST (1) | ||
35 | #define PROTO_GADGET (2) | ||
36 | |||
37 | enum otg_fsm_timer { | ||
38 | /* Standard OTG timers */ | ||
39 | A_WAIT_VRISE, | ||
40 | A_WAIT_VFALL, | ||
41 | A_WAIT_BCON, | ||
42 | A_AIDL_BDIS, | ||
43 | B_ASE0_BRST, | ||
44 | A_BIDL_ADIS, | ||
45 | |||
46 | /* Auxiliary timers */ | ||
47 | B_SE0_SRP, | ||
48 | B_SRP_FAIL, | ||
49 | A_WAIT_ENUM, | ||
50 | |||
51 | NUM_OTG_FSM_TIMERS, | ||
52 | }; | ||
53 | |||
54 | /* OTG state machine according to the OTG spec */ | ||
55 | struct otg_fsm { | ||
56 | /* Input */ | ||
57 | int id; | ||
58 | int adp_change; | ||
59 | int power_up; | ||
60 | int test_device; | ||
61 | int a_bus_drop; | ||
62 | int a_bus_req; | ||
63 | int a_srp_det; | ||
64 | int a_vbus_vld; | ||
65 | int b_conn; | ||
66 | int a_bus_resume; | ||
67 | int a_bus_suspend; | ||
68 | int a_conn; | ||
69 | int b_bus_req; | ||
70 | int b_se0_srp; | ||
71 | int b_ssend_srp; | ||
72 | int b_sess_vld; | ||
73 | /* Auxilary inputs */ | ||
74 | int a_sess_vld; | ||
75 | int b_bus_resume; | ||
76 | int b_bus_suspend; | ||
77 | |||
78 | /* Output */ | ||
79 | int data_pulse; | ||
80 | int drv_vbus; | ||
81 | int loc_conn; | ||
82 | int loc_sof; | ||
83 | int adp_prb; | ||
84 | int adp_sns; | ||
85 | |||
86 | /* Internal variables */ | ||
87 | int a_set_b_hnp_en; | ||
88 | int b_srp_done; | ||
89 | int b_hnp_enable; | ||
90 | int a_clr_err; | ||
91 | |||
92 | /* Informative variables */ | ||
93 | int a_bus_drop_inf; | ||
94 | int a_bus_req_inf; | ||
95 | int a_clr_err_inf; | ||
96 | int b_bus_req_inf; | ||
97 | /* Auxilary informative variables */ | ||
98 | int a_suspend_req_inf; | ||
99 | |||
100 | /* Timeout indicator for timers */ | ||
101 | int a_wait_vrise_tmout; | ||
102 | int a_wait_vfall_tmout; | ||
103 | int a_wait_bcon_tmout; | ||
104 | int a_aidl_bdis_tmout; | ||
105 | int b_ase0_brst_tmout; | ||
106 | int a_bidl_adis_tmout; | ||
107 | |||
108 | struct otg_fsm_ops *ops; | ||
109 | struct usb_otg *otg; | ||
110 | |||
111 | /* Current usb protocol used: 0:undefine; 1:host; 2:client */ | ||
112 | int protocol; | ||
113 | spinlock_t lock; | ||
114 | }; | ||
115 | |||
116 | struct otg_fsm_ops { | ||
117 | void (*chrg_vbus)(struct otg_fsm *fsm, int on); | ||
118 | void (*drv_vbus)(struct otg_fsm *fsm, int on); | ||
119 | void (*loc_conn)(struct otg_fsm *fsm, int on); | ||
120 | void (*loc_sof)(struct otg_fsm *fsm, int on); | ||
121 | void (*start_pulse)(struct otg_fsm *fsm); | ||
122 | void (*start_adp_prb)(struct otg_fsm *fsm); | ||
123 | void (*start_adp_sns)(struct otg_fsm *fsm); | ||
124 | void (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer); | ||
125 | void (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer); | ||
126 | int (*start_host)(struct otg_fsm *fsm, int on); | ||
127 | int (*start_gadget)(struct otg_fsm *fsm, int on); | ||
128 | }; | ||
129 | |||
130 | |||
131 | static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on) | ||
132 | { | ||
133 | if (!fsm->ops->chrg_vbus) | ||
134 | return -EOPNOTSUPP; | ||
135 | fsm->ops->chrg_vbus(fsm, on); | ||
136 | return 0; | ||
137 | } | ||
138 | |||
139 | static inline int otg_drv_vbus(struct otg_fsm *fsm, int on) | ||
140 | { | ||
141 | if (!fsm->ops->drv_vbus) | ||
142 | return -EOPNOTSUPP; | ||
143 | if (fsm->drv_vbus != on) { | ||
144 | fsm->drv_vbus = on; | ||
145 | fsm->ops->drv_vbus(fsm, on); | ||
146 | } | ||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | static inline int otg_loc_conn(struct otg_fsm *fsm, int on) | ||
151 | { | ||
152 | if (!fsm->ops->loc_conn) | ||
153 | return -EOPNOTSUPP; | ||
154 | if (fsm->loc_conn != on) { | ||
155 | fsm->loc_conn = on; | ||
156 | fsm->ops->loc_conn(fsm, on); | ||
157 | } | ||
158 | return 0; | ||
159 | } | ||
160 | |||
161 | static inline int otg_loc_sof(struct otg_fsm *fsm, int on) | ||
162 | { | ||
163 | if (!fsm->ops->loc_sof) | ||
164 | return -EOPNOTSUPP; | ||
165 | if (fsm->loc_sof != on) { | ||
166 | fsm->loc_sof = on; | ||
167 | fsm->ops->loc_sof(fsm, on); | ||
168 | } | ||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | static inline int otg_start_pulse(struct otg_fsm *fsm) | ||
173 | { | ||
174 | if (!fsm->ops->start_pulse) | ||
175 | return -EOPNOTSUPP; | ||
176 | if (!fsm->data_pulse) { | ||
177 | fsm->data_pulse = 1; | ||
178 | fsm->ops->start_pulse(fsm); | ||
179 | } | ||
180 | return 0; | ||
181 | } | ||
182 | |||
183 | static inline int otg_start_adp_prb(struct otg_fsm *fsm) | ||
184 | { | ||
185 | if (!fsm->ops->start_adp_prb) | ||
186 | return -EOPNOTSUPP; | ||
187 | if (!fsm->adp_prb) { | ||
188 | fsm->adp_sns = 0; | ||
189 | fsm->adp_prb = 1; | ||
190 | fsm->ops->start_adp_prb(fsm); | ||
191 | } | ||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | static inline int otg_start_adp_sns(struct otg_fsm *fsm) | ||
196 | { | ||
197 | if (!fsm->ops->start_adp_sns) | ||
198 | return -EOPNOTSUPP; | ||
199 | if (!fsm->adp_sns) { | ||
200 | fsm->adp_sns = 1; | ||
201 | fsm->ops->start_adp_sns(fsm); | ||
202 | } | ||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer) | ||
207 | { | ||
208 | if (!fsm->ops->add_timer) | ||
209 | return -EOPNOTSUPP; | ||
210 | fsm->ops->add_timer(fsm, timer); | ||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer) | ||
215 | { | ||
216 | if (!fsm->ops->del_timer) | ||
217 | return -EOPNOTSUPP; | ||
218 | fsm->ops->del_timer(fsm, timer); | ||
219 | return 0; | ||
220 | } | ||
221 | |||
222 | static inline int otg_start_host(struct otg_fsm *fsm, int on) | ||
223 | { | ||
224 | if (!fsm->ops->start_host) | ||
225 | return -EOPNOTSUPP; | ||
226 | return fsm->ops->start_host(fsm, on); | ||
227 | } | ||
228 | |||
229 | static inline int otg_start_gadget(struct otg_fsm *fsm, int on) | ||
230 | { | ||
231 | if (!fsm->ops->start_gadget) | ||
232 | return -EOPNOTSUPP; | ||
233 | return fsm->ops->start_gadget(fsm, on); | ||
234 | } | ||
235 | |||
236 | int otg_statemachine(struct otg_fsm *fsm); | ||
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c index aa6d37b3378a..bb394980532b 100644 --- a/drivers/usb/phy/phy-generic.c +++ b/drivers/usb/phy/phy-generic.c | |||
@@ -241,7 +241,6 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, | |||
241 | nop->phy.otg->set_host = nop_set_host; | 241 | nop->phy.otg->set_host = nop_set_host; |
242 | nop->phy.otg->set_peripheral = nop_set_peripheral; | 242 | nop->phy.otg->set_peripheral = nop_set_peripheral; |
243 | 243 | ||
244 | ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier); | ||
245 | return 0; | 244 | return 0; |
246 | } | 245 | } |
247 | EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy); | 246 | EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy); |
diff --git a/drivers/usb/phy/phy-gpio-vbus-usb.c b/drivers/usb/phy/phy-gpio-vbus-usb.c index 02799a5efcd4..69462e09d014 100644 --- a/drivers/usb/phy/phy-gpio-vbus-usb.c +++ b/drivers/usb/phy/phy-gpio-vbus-usb.c | |||
@@ -314,8 +314,6 @@ static int gpio_vbus_probe(struct platform_device *pdev) | |||
314 | goto err_irq; | 314 | goto err_irq; |
315 | } | 315 | } |
316 | 316 | ||
317 | ATOMIC_INIT_NOTIFIER_HEAD(&gpio_vbus->phy.notifier); | ||
318 | |||
319 | INIT_DELAYED_WORK(&gpio_vbus->work, gpio_vbus_work); | 317 | INIT_DELAYED_WORK(&gpio_vbus->work, gpio_vbus_work); |
320 | 318 | ||
321 | gpio_vbus->vbus_draw = regulator_get(&pdev->dev, "vbus_draw"); | 319 | gpio_vbus->vbus_draw = regulator_get(&pdev->dev, "vbus_draw"); |
diff --git a/drivers/usb/phy/phy-isp1301-omap.c b/drivers/usb/phy/phy-isp1301-omap.c index d3a5160e4cc7..6e146d723b37 100644 --- a/drivers/usb/phy/phy-isp1301-omap.c +++ b/drivers/usb/phy/phy-isp1301-omap.c | |||
@@ -1277,7 +1277,7 @@ isp1301_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
1277 | { | 1277 | { |
1278 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); | 1278 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); |
1279 | 1279 | ||
1280 | if (!otg || isp != the_transceiver) | 1280 | if (isp != the_transceiver) |
1281 | return -ENODEV; | 1281 | return -ENODEV; |
1282 | 1282 | ||
1283 | if (!host) { | 1283 | if (!host) { |
@@ -1333,7 +1333,7 @@ isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) | |||
1333 | { | 1333 | { |
1334 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); | 1334 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); |
1335 | 1335 | ||
1336 | if (!otg || isp != the_transceiver) | 1336 | if (isp != the_transceiver) |
1337 | return -ENODEV; | 1337 | return -ENODEV; |
1338 | 1338 | ||
1339 | if (!gadget) { | 1339 | if (!gadget) { |
@@ -1414,8 +1414,7 @@ isp1301_start_srp(struct usb_otg *otg) | |||
1414 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); | 1414 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); |
1415 | u32 otg_ctrl; | 1415 | u32 otg_ctrl; |
1416 | 1416 | ||
1417 | if (!otg || isp != the_transceiver | 1417 | if (isp != the_transceiver || isp->phy.state != OTG_STATE_B_IDLE) |
1418 | || isp->phy.state != OTG_STATE_B_IDLE) | ||
1419 | return -ENODEV; | 1418 | return -ENODEV; |
1420 | 1419 | ||
1421 | otg_ctrl = omap_readl(OTG_CTRL); | 1420 | otg_ctrl = omap_readl(OTG_CTRL); |
@@ -1442,7 +1441,7 @@ isp1301_start_hnp(struct usb_otg *otg) | |||
1442 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); | 1441 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); |
1443 | u32 l; | 1442 | u32 l; |
1444 | 1443 | ||
1445 | if (!otg || isp != the_transceiver) | 1444 | if (isp != the_transceiver) |
1446 | return -ENODEV; | 1445 | return -ENODEV; |
1447 | if (otg->default_a && (otg->host == NULL || !otg->host->b_hnp_enable)) | 1446 | if (otg->default_a && (otg->host == NULL || !otg->host->b_hnp_enable)) |
1448 | return -ENOTCONN; | 1447 | return -ENOTCONN; |
diff --git a/drivers/usb/phy/phy-keystone.c b/drivers/usb/phy/phy-keystone.c new file mode 100644 index 000000000000..d762003896c0 --- /dev/null +++ b/drivers/usb/phy/phy-keystone.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | * phy-keystone - USB PHY, talking to dwc3 controller in Keystone. | ||
3 | * | ||
4 | * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * Author: WingMan Kwok <w-kwok2@ti.com> | ||
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 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/usb/usb_phy_gen_xceiv.h> | ||
22 | #include <linux/io.h> | ||
23 | #include <linux/of.h> | ||
24 | |||
25 | #include "phy-generic.h" | ||
26 | |||
27 | /* USB PHY control register offsets */ | ||
28 | #define USB_PHY_CTL_UTMI 0x0000 | ||
29 | #define USB_PHY_CTL_PIPE 0x0004 | ||
30 | #define USB_PHY_CTL_PARAM_1 0x0008 | ||
31 | #define USB_PHY_CTL_PARAM_2 0x000c | ||
32 | #define USB_PHY_CTL_CLOCK 0x0010 | ||
33 | #define USB_PHY_CTL_PLL 0x0014 | ||
34 | |||
35 | #define PHY_REF_SSP_EN BIT(29) | ||
36 | |||
37 | struct keystone_usbphy { | ||
38 | struct usb_phy_gen_xceiv usb_phy_gen; | ||
39 | void __iomem *phy_ctrl; | ||
40 | }; | ||
41 | |||
42 | static inline u32 keystone_usbphy_readl(void __iomem *base, u32 offset) | ||
43 | { | ||
44 | return readl(base + offset); | ||
45 | } | ||
46 | |||
47 | static inline void keystone_usbphy_writel(void __iomem *base, | ||
48 | u32 offset, u32 value) | ||
49 | { | ||
50 | writel(value, base + offset); | ||
51 | } | ||
52 | |||
53 | static int keystone_usbphy_init(struct usb_phy *phy) | ||
54 | { | ||
55 | struct keystone_usbphy *k_phy = dev_get_drvdata(phy->dev); | ||
56 | u32 val; | ||
57 | |||
58 | val = keystone_usbphy_readl(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK); | ||
59 | keystone_usbphy_writel(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK, | ||
60 | val | PHY_REF_SSP_EN); | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | static void keystone_usbphy_shutdown(struct usb_phy *phy) | ||
65 | { | ||
66 | struct keystone_usbphy *k_phy = dev_get_drvdata(phy->dev); | ||
67 | u32 val; | ||
68 | |||
69 | val = keystone_usbphy_readl(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK); | ||
70 | keystone_usbphy_writel(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK, | ||
71 | val &= ~PHY_REF_SSP_EN); | ||
72 | } | ||
73 | |||
74 | static int keystone_usbphy_probe(struct platform_device *pdev) | ||
75 | { | ||
76 | struct device *dev = &pdev->dev; | ||
77 | struct keystone_usbphy *k_phy; | ||
78 | struct resource *res; | ||
79 | int ret; | ||
80 | |||
81 | k_phy = devm_kzalloc(dev, sizeof(*k_phy), GFP_KERNEL); | ||
82 | if (!k_phy) | ||
83 | return -ENOMEM; | ||
84 | |||
85 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
86 | k_phy->phy_ctrl = devm_ioremap_resource(dev, res); | ||
87 | if (IS_ERR(k_phy->phy_ctrl)) | ||
88 | return PTR_ERR(k_phy->phy_ctrl); | ||
89 | |||
90 | ret = usb_phy_gen_create_phy(dev, &k_phy->usb_phy_gen, NULL); | ||
91 | if (ret) | ||
92 | return ret; | ||
93 | |||
94 | k_phy->usb_phy_gen.phy.init = keystone_usbphy_init; | ||
95 | k_phy->usb_phy_gen.phy.shutdown = keystone_usbphy_shutdown; | ||
96 | |||
97 | platform_set_drvdata(pdev, k_phy); | ||
98 | |||
99 | ret = usb_add_phy_dev(&k_phy->usb_phy_gen.phy); | ||
100 | if (ret) | ||
101 | return ret; | ||
102 | |||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | static int keystone_usbphy_remove(struct platform_device *pdev) | ||
107 | { | ||
108 | struct keystone_usbphy *k_phy = platform_get_drvdata(pdev); | ||
109 | |||
110 | usb_remove_phy(&k_phy->usb_phy_gen.phy); | ||
111 | |||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | static const struct of_device_id keystone_usbphy_ids[] = { | ||
116 | { .compatible = "ti,keystone-usbphy" }, | ||
117 | { } | ||
118 | }; | ||
119 | MODULE_DEVICE_TABLE(of, keystone_usbphy_ids); | ||
120 | |||
121 | static struct platform_driver keystone_usbphy_driver = { | ||
122 | .probe = keystone_usbphy_probe, | ||
123 | .remove = keystone_usbphy_remove, | ||
124 | .driver = { | ||
125 | .name = "keystone-usbphy", | ||
126 | .owner = THIS_MODULE, | ||
127 | .of_match_table = keystone_usbphy_ids, | ||
128 | }, | ||
129 | }; | ||
130 | |||
131 | module_platform_driver(keystone_usbphy_driver); | ||
132 | |||
133 | MODULE_ALIAS("platform:keystone-usbphy"); | ||
134 | MODULE_AUTHOR("Texas Instruments Inc."); | ||
135 | MODULE_DESCRIPTION("Keystone USB phy driver"); | ||
136 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c index e9d4cd960ecd..8546c8dccd51 100644 --- a/drivers/usb/phy/phy-msm-usb.c +++ b/drivers/usb/phy/phy-msm-usb.c | |||
@@ -40,8 +40,6 @@ | |||
40 | #include <linux/usb/msm_hsusb_hw.h> | 40 | #include <linux/usb/msm_hsusb_hw.h> |
41 | #include <linux/regulator/consumer.h> | 41 | #include <linux/regulator/consumer.h> |
42 | 42 | ||
43 | #include <mach/clk.h> | ||
44 | |||
45 | #define MSM_USB_BASE (motg->regs) | 43 | #define MSM_USB_BASE (motg->regs) |
46 | #define DRIVER_NAME "msm_otg" | 44 | #define DRIVER_NAME "msm_otg" |
47 | 45 | ||
@@ -308,33 +306,30 @@ static void ulpi_init(struct msm_otg *motg) | |||
308 | 306 | ||
309 | static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) | 307 | static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) |
310 | { | 308 | { |
311 | int ret; | 309 | int ret = 0; |
310 | |||
311 | if (!motg->pdata->link_clk_reset) | ||
312 | return ret; | ||
313 | |||
314 | ret = motg->pdata->link_clk_reset(motg->clk, assert); | ||
315 | if (ret) | ||
316 | dev_err(motg->phy.dev, "usb link clk reset %s failed\n", | ||
317 | assert ? "assert" : "deassert"); | ||
312 | 318 | ||
313 | if (assert) { | ||
314 | ret = clk_reset(motg->clk, CLK_RESET_ASSERT); | ||
315 | if (ret) | ||
316 | dev_err(motg->phy.dev, "usb hs_clk assert failed\n"); | ||
317 | } else { | ||
318 | ret = clk_reset(motg->clk, CLK_RESET_DEASSERT); | ||
319 | if (ret) | ||
320 | dev_err(motg->phy.dev, "usb hs_clk deassert failed\n"); | ||
321 | } | ||
322 | return ret; | 319 | return ret; |
323 | } | 320 | } |
324 | 321 | ||
325 | static int msm_otg_phy_clk_reset(struct msm_otg *motg) | 322 | static int msm_otg_phy_clk_reset(struct msm_otg *motg) |
326 | { | 323 | { |
327 | int ret; | 324 | int ret = 0; |
328 | 325 | ||
329 | ret = clk_reset(motg->phy_reset_clk, CLK_RESET_ASSERT); | 326 | if (!motg->pdata->phy_clk_reset) |
330 | if (ret) { | ||
331 | dev_err(motg->phy.dev, "usb phy clk assert failed\n"); | ||
332 | return ret; | 327 | return ret; |
333 | } | 328 | |
334 | usleep_range(10000, 12000); | 329 | ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); |
335 | ret = clk_reset(motg->phy_reset_clk, CLK_RESET_DEASSERT); | ||
336 | if (ret) | 330 | if (ret) |
337 | dev_err(motg->phy.dev, "usb phy clk deassert failed\n"); | 331 | dev_err(motg->phy.dev, "usb phy clk reset failed\n"); |
332 | |||
338 | return ret; | 333 | return ret; |
339 | } | 334 | } |
340 | 335 | ||
@@ -669,6 +664,7 @@ static void msm_otg_start_host(struct usb_phy *phy, int on) | |||
669 | pdata->setup_gpio(OTG_STATE_A_HOST); | 664 | pdata->setup_gpio(OTG_STATE_A_HOST); |
670 | #ifdef CONFIG_USB | 665 | #ifdef CONFIG_USB |
671 | usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); | 666 | usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
667 | device_wakeup_enable(hcd->self.controller); | ||
672 | #endif | 668 | #endif |
673 | } else { | 669 | } else { |
674 | dev_dbg(phy->dev, "host off\n"); | 670 | dev_dbg(phy->dev, "host off\n"); |
diff --git a/drivers/usb/phy/phy-mv-usb.c b/drivers/usb/phy/phy-mv-usb.c index 98f6ac6a78ea..7d80c54f0ac6 100644 --- a/drivers/usb/phy/phy-mv-usb.c +++ b/drivers/usb/phy/phy-mv-usb.c | |||
@@ -11,7 +11,6 @@ | |||
11 | 11 | ||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/init.h> | ||
15 | #include <linux/io.h> | 14 | #include <linux/io.h> |
16 | #include <linux/uaccess.h> | 15 | #include <linux/uaccess.h> |
17 | #include <linux/device.h> | 16 | #include <linux/device.h> |
@@ -213,10 +212,12 @@ static void mv_otg_start_host(struct mv_otg *mvotg, int on) | |||
213 | 212 | ||
214 | hcd = bus_to_hcd(otg->host); | 213 | hcd = bus_to_hcd(otg->host); |
215 | 214 | ||
216 | if (on) | 215 | if (on) { |
217 | usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); | 216 | usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
218 | else | 217 | device_wakeup_enable(hcd->self.controller); |
218 | } else { | ||
219 | usb_remove_hcd(hcd); | 219 | usb_remove_hcd(hcd); |
220 | } | ||
220 | #endif /* CONFIG_USB */ | 221 | #endif /* CONFIG_USB */ |
221 | } | 222 | } |
222 | 223 | ||
diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c index 545844b7e796..b42897b6474c 100644 --- a/drivers/usb/phy/phy-mxs-usb.c +++ b/drivers/usb/phy/phy-mxs-usb.c | |||
@@ -63,9 +63,13 @@ static int mxs_phy_hw_init(struct mxs_phy *mxs_phy) | |||
63 | 63 | ||
64 | static int mxs_phy_init(struct usb_phy *phy) | 64 | static int mxs_phy_init(struct usb_phy *phy) |
65 | { | 65 | { |
66 | int ret; | ||
66 | struct mxs_phy *mxs_phy = to_mxs_phy(phy); | 67 | struct mxs_phy *mxs_phy = to_mxs_phy(phy); |
67 | 68 | ||
68 | clk_prepare_enable(mxs_phy->clk); | 69 | ret = clk_prepare_enable(mxs_phy->clk); |
70 | if (ret) | ||
71 | return ret; | ||
72 | |||
69 | return mxs_phy_hw_init(mxs_phy); | 73 | return mxs_phy_hw_init(mxs_phy); |
70 | } | 74 | } |
71 | 75 | ||
@@ -81,6 +85,7 @@ static void mxs_phy_shutdown(struct usb_phy *phy) | |||
81 | 85 | ||
82 | static int mxs_phy_suspend(struct usb_phy *x, int suspend) | 86 | static int mxs_phy_suspend(struct usb_phy *x, int suspend) |
83 | { | 87 | { |
88 | int ret; | ||
84 | struct mxs_phy *mxs_phy = to_mxs_phy(x); | 89 | struct mxs_phy *mxs_phy = to_mxs_phy(x); |
85 | 90 | ||
86 | if (suspend) { | 91 | if (suspend) { |
@@ -89,7 +94,9 @@ static int mxs_phy_suspend(struct usb_phy *x, int suspend) | |||
89 | x->io_priv + HW_USBPHY_CTRL_SET); | 94 | x->io_priv + HW_USBPHY_CTRL_SET); |
90 | clk_disable_unprepare(mxs_phy->clk); | 95 | clk_disable_unprepare(mxs_phy->clk); |
91 | } else { | 96 | } else { |
92 | clk_prepare_enable(mxs_phy->clk); | 97 | ret = clk_prepare_enable(mxs_phy->clk); |
98 | if (ret) | ||
99 | return ret; | ||
93 | writel(BM_USBPHY_CTRL_CLKGATE, | 100 | writel(BM_USBPHY_CTRL_CLKGATE, |
94 | x->io_priv + HW_USBPHY_CTRL_CLR); | 101 | x->io_priv + HW_USBPHY_CTRL_CLR); |
95 | writel(0, x->io_priv + HW_USBPHY_PWD); | 102 | writel(0, x->io_priv + HW_USBPHY_PWD); |
@@ -160,8 +167,6 @@ static int mxs_phy_probe(struct platform_device *pdev) | |||
160 | mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect; | 167 | mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect; |
161 | mxs_phy->phy.type = USB_PHY_TYPE_USB2; | 168 | mxs_phy->phy.type = USB_PHY_TYPE_USB2; |
162 | 169 | ||
163 | ATOMIC_INIT_NOTIFIER_HEAD(&mxs_phy->phy.notifier); | ||
164 | |||
165 | mxs_phy->clk = clk; | 170 | mxs_phy->clk = clk; |
166 | 171 | ||
167 | platform_set_drvdata(pdev, mxs_phy); | 172 | platform_set_drvdata(pdev, mxs_phy); |
diff --git a/drivers/usb/phy/phy-omap-control.c b/drivers/usb/phy/phy-omap-control.c index 09c5ace1edd8..e7253182e47d 100644 --- a/drivers/usb/phy/phy-omap-control.c +++ b/drivers/usb/phy/phy-omap-control.c | |||
@@ -84,6 +84,20 @@ void omap_control_usb_phy_power(struct device *dev, int on) | |||
84 | else | 84 | else |
85 | val |= OMAP_CTRL_USB2_PHY_PD; | 85 | val |= OMAP_CTRL_USB2_PHY_PD; |
86 | break; | 86 | break; |
87 | |||
88 | case OMAP_CTRL_TYPE_AM437USB2: | ||
89 | if (on) { | ||
90 | val &= ~(AM437X_CTRL_USB2_PHY_PD | | ||
91 | AM437X_CTRL_USB2_OTG_PD); | ||
92 | val |= (AM437X_CTRL_USB2_OTGVDET_EN | | ||
93 | AM437X_CTRL_USB2_OTGSESSEND_EN); | ||
94 | } else { | ||
95 | val &= ~(AM437X_CTRL_USB2_OTGVDET_EN | | ||
96 | AM437X_CTRL_USB2_OTGSESSEND_EN); | ||
97 | val |= (AM437X_CTRL_USB2_PHY_PD | | ||
98 | AM437X_CTRL_USB2_OTG_PD); | ||
99 | } | ||
100 | break; | ||
87 | default: | 101 | default: |
88 | dev_err(dev, "%s: type %d not recognized\n", | 102 | dev_err(dev, "%s: type %d not recognized\n", |
89 | __func__, control_usb->type); | 103 | __func__, control_usb->type); |
@@ -197,6 +211,7 @@ static const enum omap_control_usb_type otghs_data = OMAP_CTRL_TYPE_OTGHS; | |||
197 | static const enum omap_control_usb_type usb2_data = OMAP_CTRL_TYPE_USB2; | 211 | static const enum omap_control_usb_type usb2_data = OMAP_CTRL_TYPE_USB2; |
198 | static const enum omap_control_usb_type pipe3_data = OMAP_CTRL_TYPE_PIPE3; | 212 | static const enum omap_control_usb_type pipe3_data = OMAP_CTRL_TYPE_PIPE3; |
199 | static const enum omap_control_usb_type dra7usb2_data = OMAP_CTRL_TYPE_DRA7USB2; | 213 | static const enum omap_control_usb_type dra7usb2_data = OMAP_CTRL_TYPE_DRA7USB2; |
214 | static const enum omap_control_usb_type am437usb2_data = OMAP_CTRL_TYPE_AM437USB2; | ||
200 | 215 | ||
201 | static const struct of_device_id omap_control_usb_id_table[] = { | 216 | static const struct of_device_id omap_control_usb_id_table[] = { |
202 | { | 217 | { |
@@ -215,6 +230,10 @@ static const struct of_device_id omap_control_usb_id_table[] = { | |||
215 | .compatible = "ti,control-phy-dra7usb2", | 230 | .compatible = "ti,control-phy-dra7usb2", |
216 | .data = &dra7usb2_data, | 231 | .data = &dra7usb2_data, |
217 | }, | 232 | }, |
233 | { | ||
234 | .compatible = "ti,control-phy-am437usb2", | ||
235 | .data = &am437usb2_data, | ||
236 | }, | ||
218 | {}, | 237 | {}, |
219 | }; | 238 | }; |
220 | MODULE_DEVICE_TABLE(of, omap_control_usb_id_table); | 239 | MODULE_DEVICE_TABLE(of, omap_control_usb_id_table); |
diff --git a/drivers/usb/phy/phy-omap-otg.c b/drivers/usb/phy/phy-omap-otg.c new file mode 100644 index 000000000000..11598cdb3189 --- /dev/null +++ b/drivers/usb/phy/phy-omap-otg.c | |||
@@ -0,0 +1,169 @@ | |||
1 | /* | ||
2 | * OMAP OTG controller driver | ||
3 | * | ||
4 | * Based on code from tahvo-usb.c and isp1301_omap.c drivers. | ||
5 | * | ||
6 | * Copyright (C) 2005-2006 Nokia Corporation | ||
7 | * Copyright (C) 2004 Texas Instruments | ||
8 | * Copyright (C) 2004 David Brownell | ||
9 | * | ||
10 | * This file is subject to the terms and conditions of the GNU General | ||
11 | * Public License. See the file "COPYING" in the main directory of this | ||
12 | * archive for more details. | ||
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 | |||
20 | #include <linux/io.h> | ||
21 | #include <linux/err.h> | ||
22 | #include <linux/extcon.h> | ||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/interrupt.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | #include <linux/platform_data/usb-omap1.h> | ||
28 | |||
29 | struct otg_device { | ||
30 | void __iomem *base; | ||
31 | bool id; | ||
32 | bool vbus; | ||
33 | struct extcon_specific_cable_nb vbus_dev; | ||
34 | struct extcon_specific_cable_nb id_dev; | ||
35 | struct notifier_block vbus_nb; | ||
36 | struct notifier_block id_nb; | ||
37 | }; | ||
38 | |||
39 | #define OMAP_OTG_CTRL 0x0c | ||
40 | #define OMAP_OTG_ASESSVLD (1 << 20) | ||
41 | #define OMAP_OTG_BSESSEND (1 << 19) | ||
42 | #define OMAP_OTG_BSESSVLD (1 << 18) | ||
43 | #define OMAP_OTG_VBUSVLD (1 << 17) | ||
44 | #define OMAP_OTG_ID (1 << 16) | ||
45 | #define OMAP_OTG_XCEIV_OUTPUTS \ | ||
46 | (OMAP_OTG_ASESSVLD | OMAP_OTG_BSESSEND | OMAP_OTG_BSESSVLD | \ | ||
47 | OMAP_OTG_VBUSVLD | OMAP_OTG_ID) | ||
48 | |||
49 | static void omap_otg_ctrl(struct otg_device *otg_dev, u32 outputs) | ||
50 | { | ||
51 | u32 l; | ||
52 | |||
53 | l = readl(otg_dev->base + OMAP_OTG_CTRL); | ||
54 | l &= ~OMAP_OTG_XCEIV_OUTPUTS; | ||
55 | l |= outputs; | ||
56 | writel(l, otg_dev->base + OMAP_OTG_CTRL); | ||
57 | } | ||
58 | |||
59 | static void omap_otg_set_mode(struct otg_device *otg_dev) | ||
60 | { | ||
61 | if (!otg_dev->id && otg_dev->vbus) | ||
62 | /* Set B-session valid. */ | ||
63 | omap_otg_ctrl(otg_dev, OMAP_OTG_ID | OMAP_OTG_BSESSVLD); | ||
64 | else if (otg_dev->vbus) | ||
65 | /* Set A-session valid. */ | ||
66 | omap_otg_ctrl(otg_dev, OMAP_OTG_ASESSVLD); | ||
67 | else if (!otg_dev->id) | ||
68 | /* Set B-session end to indicate no VBUS. */ | ||
69 | omap_otg_ctrl(otg_dev, OMAP_OTG_ID | OMAP_OTG_BSESSEND); | ||
70 | } | ||
71 | |||
72 | static int omap_otg_id_notifier(struct notifier_block *nb, | ||
73 | unsigned long event, void *ptr) | ||
74 | { | ||
75 | struct otg_device *otg_dev = container_of(nb, struct otg_device, id_nb); | ||
76 | |||
77 | otg_dev->id = event; | ||
78 | omap_otg_set_mode(otg_dev); | ||
79 | |||
80 | return NOTIFY_DONE; | ||
81 | } | ||
82 | |||
83 | static int omap_otg_vbus_notifier(struct notifier_block *nb, | ||
84 | unsigned long event, void *ptr) | ||
85 | { | ||
86 | struct otg_device *otg_dev = container_of(nb, struct otg_device, | ||
87 | vbus_nb); | ||
88 | |||
89 | otg_dev->vbus = event; | ||
90 | omap_otg_set_mode(otg_dev); | ||
91 | |||
92 | return NOTIFY_DONE; | ||
93 | } | ||
94 | |||
95 | static int omap_otg_probe(struct platform_device *pdev) | ||
96 | { | ||
97 | const struct omap_usb_config *config = pdev->dev.platform_data; | ||
98 | struct otg_device *otg_dev; | ||
99 | struct extcon_dev *extcon; | ||
100 | int ret; | ||
101 | u32 rev; | ||
102 | |||
103 | if (!config || !config->extcon) | ||
104 | return -ENODEV; | ||
105 | |||
106 | extcon = extcon_get_extcon_dev(config->extcon); | ||
107 | if (!extcon) | ||
108 | return -EPROBE_DEFER; | ||
109 | |||
110 | otg_dev = devm_kzalloc(&pdev->dev, sizeof(*otg_dev), GFP_KERNEL); | ||
111 | if (!otg_dev) | ||
112 | return -ENOMEM; | ||
113 | |||
114 | otg_dev->base = devm_ioremap_resource(&pdev->dev, &pdev->resource[0]); | ||
115 | if (IS_ERR(otg_dev->base)) | ||
116 | return PTR_ERR(otg_dev->base); | ||
117 | |||
118 | otg_dev->id_nb.notifier_call = omap_otg_id_notifier; | ||
119 | otg_dev->vbus_nb.notifier_call = omap_otg_vbus_notifier; | ||
120 | |||
121 | ret = extcon_register_interest(&otg_dev->id_dev, config->extcon, | ||
122 | "USB-HOST", &otg_dev->id_nb); | ||
123 | if (ret) | ||
124 | return ret; | ||
125 | |||
126 | ret = extcon_register_interest(&otg_dev->vbus_dev, config->extcon, | ||
127 | "USB", &otg_dev->vbus_nb); | ||
128 | if (ret) { | ||
129 | extcon_unregister_interest(&otg_dev->id_dev); | ||
130 | return ret; | ||
131 | } | ||
132 | |||
133 | otg_dev->id = extcon_get_cable_state(extcon, "USB-HOST"); | ||
134 | otg_dev->vbus = extcon_get_cable_state(extcon, "USB"); | ||
135 | omap_otg_set_mode(otg_dev); | ||
136 | |||
137 | rev = readl(otg_dev->base); | ||
138 | |||
139 | dev_info(&pdev->dev, | ||
140 | "OMAP USB OTG controller rev %d.%d (%s, id=%d, vbus=%d)\n", | ||
141 | (rev >> 4) & 0xf, rev & 0xf, config->extcon, otg_dev->id, | ||
142 | otg_dev->vbus); | ||
143 | |||
144 | return 0; | ||
145 | } | ||
146 | |||
147 | static int omap_otg_remove(struct platform_device *pdev) | ||
148 | { | ||
149 | struct otg_device *otg_dev = platform_get_drvdata(pdev); | ||
150 | |||
151 | extcon_unregister_interest(&otg_dev->id_dev); | ||
152 | extcon_unregister_interest(&otg_dev->vbus_dev); | ||
153 | |||
154 | return 0; | ||
155 | } | ||
156 | |||
157 | static struct platform_driver omap_otg_driver = { | ||
158 | .probe = omap_otg_probe, | ||
159 | .remove = omap_otg_remove, | ||
160 | .driver = { | ||
161 | .owner = THIS_MODULE, | ||
162 | .name = "omap_otg", | ||
163 | }, | ||
164 | }; | ||
165 | module_platform_driver(omap_otg_driver); | ||
166 | |||
167 | MODULE_DESCRIPTION("OMAP USB OTG controller driver"); | ||
168 | MODULE_LICENSE("GPL"); | ||
169 | MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>"); | ||
diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c b/drivers/usb/phy/phy-rcar-gen2-usb.c index db3ab34cddb4..551e0a6c0e22 100644 --- a/drivers/usb/phy/phy-rcar-gen2-usb.c +++ b/drivers/usb/phy/phy-rcar-gen2-usb.c | |||
@@ -213,7 +213,7 @@ static int rcar_gen2_usb_phy_probe(struct platform_device *pdev) | |||
213 | priv->phy.shutdown = rcar_gen2_usb_phy_shutdown; | 213 | priv->phy.shutdown = rcar_gen2_usb_phy_shutdown; |
214 | priv->phy.set_suspend = rcar_gen2_usb_phy_set_suspend; | 214 | priv->phy.set_suspend = rcar_gen2_usb_phy_set_suspend; |
215 | 215 | ||
216 | retval = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2); | 216 | retval = usb_add_phy_dev(&priv->phy); |
217 | if (retval < 0) { | 217 | if (retval < 0) { |
218 | dev_err(dev, "Failed to add USB phy\n"); | 218 | dev_err(dev, "Failed to add USB phy\n"); |
219 | return retval; | 219 | return retval; |
diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c new file mode 100644 index 000000000000..cc61ee44b911 --- /dev/null +++ b/drivers/usb/phy/phy-tahvo.c | |||
@@ -0,0 +1,457 @@ | |||
1 | /* | ||
2 | * Tahvo USB transceiver driver | ||
3 | * | ||
4 | * Copyright (C) 2005-2006 Nokia Corporation | ||
5 | * | ||
6 | * Parts copied from isp1301_omap.c. | ||
7 | * Copyright (C) 2004 Texas Instruments | ||
8 | * Copyright (C) 2004 David Brownell | ||
9 | * | ||
10 | * Original driver written by Juha Yrjölä, Tony Lindgren and Timo Teräs. | ||
11 | * Modified for Retu/Tahvo MFD by Aaro Koskinen. | ||
12 | * | ||
13 | * This file is subject to the terms and conditions of the GNU General | ||
14 | * Public License. See the file "COPYING" in the main directory of this | ||
15 | * archive for more details. | ||
16 | * | ||
17 | * This program is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU General Public License for more details. | ||
21 | */ | ||
22 | |||
23 | #include <linux/io.h> | ||
24 | #include <linux/clk.h> | ||
25 | #include <linux/usb.h> | ||
26 | #include <linux/extcon.h> | ||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/usb/otg.h> | ||
30 | #include <linux/mfd/retu.h> | ||
31 | #include <linux/usb/gadget.h> | ||
32 | #include <linux/platform_device.h> | ||
33 | |||
34 | #define DRIVER_NAME "tahvo-usb" | ||
35 | |||
36 | #define TAHVO_REG_IDSR 0x02 | ||
37 | #define TAHVO_REG_USBR 0x06 | ||
38 | |||
39 | #define USBR_SLAVE_CONTROL (1 << 8) | ||
40 | #define USBR_VPPVIO_SW (1 << 7) | ||
41 | #define USBR_SPEED (1 << 6) | ||
42 | #define USBR_REGOUT (1 << 5) | ||
43 | #define USBR_MASTER_SW2 (1 << 4) | ||
44 | #define USBR_MASTER_SW1 (1 << 3) | ||
45 | #define USBR_SLAVE_SW (1 << 2) | ||
46 | #define USBR_NSUSPEND (1 << 1) | ||
47 | #define USBR_SEMODE (1 << 0) | ||
48 | |||
49 | #define TAHVO_MODE_HOST 0 | ||
50 | #define TAHVO_MODE_PERIPHERAL 1 | ||
51 | |||
52 | struct tahvo_usb { | ||
53 | struct platform_device *pt_dev; | ||
54 | struct usb_phy phy; | ||
55 | int vbus_state; | ||
56 | struct mutex serialize; | ||
57 | struct clk *ick; | ||
58 | int irq; | ||
59 | int tahvo_mode; | ||
60 | struct extcon_dev extcon; | ||
61 | }; | ||
62 | |||
63 | static const char *tahvo_cable[] = { | ||
64 | "USB-HOST", | ||
65 | "USB", | ||
66 | NULL, | ||
67 | }; | ||
68 | |||
69 | static ssize_t vbus_state_show(struct device *device, | ||
70 | struct device_attribute *attr, char *buf) | ||
71 | { | ||
72 | struct tahvo_usb *tu = dev_get_drvdata(device); | ||
73 | return sprintf(buf, "%s\n", tu->vbus_state ? "on" : "off"); | ||
74 | } | ||
75 | static DEVICE_ATTR(vbus, 0444, vbus_state_show, NULL); | ||
76 | |||
77 | static void check_vbus_state(struct tahvo_usb *tu) | ||
78 | { | ||
79 | struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); | ||
80 | int reg, prev_state; | ||
81 | |||
82 | reg = retu_read(rdev, TAHVO_REG_IDSR); | ||
83 | if (reg & TAHVO_STAT_VBUS) { | ||
84 | switch (tu->phy.state) { | ||
85 | case OTG_STATE_B_IDLE: | ||
86 | /* Enable the gadget driver */ | ||
87 | if (tu->phy.otg->gadget) | ||
88 | usb_gadget_vbus_connect(tu->phy.otg->gadget); | ||
89 | tu->phy.state = OTG_STATE_B_PERIPHERAL; | ||
90 | break; | ||
91 | case OTG_STATE_A_IDLE: | ||
92 | /* | ||
93 | * Session is now valid assuming the USB hub is driving | ||
94 | * Vbus. | ||
95 | */ | ||
96 | tu->phy.state = OTG_STATE_A_HOST; | ||
97 | break; | ||
98 | default: | ||
99 | break; | ||
100 | } | ||
101 | dev_info(&tu->pt_dev->dev, "USB cable connected\n"); | ||
102 | } else { | ||
103 | switch (tu->phy.state) { | ||
104 | case OTG_STATE_B_PERIPHERAL: | ||
105 | if (tu->phy.otg->gadget) | ||
106 | usb_gadget_vbus_disconnect(tu->phy.otg->gadget); | ||
107 | tu->phy.state = OTG_STATE_B_IDLE; | ||
108 | break; | ||
109 | case OTG_STATE_A_HOST: | ||
110 | tu->phy.state = OTG_STATE_A_IDLE; | ||
111 | break; | ||
112 | default: | ||
113 | break; | ||
114 | } | ||
115 | dev_info(&tu->pt_dev->dev, "USB cable disconnected\n"); | ||
116 | } | ||
117 | |||
118 | prev_state = tu->vbus_state; | ||
119 | tu->vbus_state = reg & TAHVO_STAT_VBUS; | ||
120 | if (prev_state != tu->vbus_state) { | ||
121 | extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state); | ||
122 | sysfs_notify(&tu->pt_dev->dev.kobj, NULL, "vbus_state"); | ||
123 | } | ||
124 | } | ||
125 | |||
126 | static void tahvo_usb_become_host(struct tahvo_usb *tu) | ||
127 | { | ||
128 | struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); | ||
129 | |||
130 | extcon_set_cable_state(&tu->extcon, "USB-HOST", true); | ||
131 | |||
132 | /* Power up the transceiver in USB host mode */ | ||
133 | retu_write(rdev, TAHVO_REG_USBR, USBR_REGOUT | USBR_NSUSPEND | | ||
134 | USBR_MASTER_SW2 | USBR_MASTER_SW1); | ||
135 | tu->phy.state = OTG_STATE_A_IDLE; | ||
136 | |||
137 | check_vbus_state(tu); | ||
138 | } | ||
139 | |||
140 | static void tahvo_usb_stop_host(struct tahvo_usb *tu) | ||
141 | { | ||
142 | tu->phy.state = OTG_STATE_A_IDLE; | ||
143 | } | ||
144 | |||
145 | static void tahvo_usb_become_peripheral(struct tahvo_usb *tu) | ||
146 | { | ||
147 | struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); | ||
148 | |||
149 | extcon_set_cable_state(&tu->extcon, "USB-HOST", false); | ||
150 | |||
151 | /* Power up transceiver and set it in USB peripheral mode */ | ||
152 | retu_write(rdev, TAHVO_REG_USBR, USBR_SLAVE_CONTROL | USBR_REGOUT | | ||
153 | USBR_NSUSPEND | USBR_SLAVE_SW); | ||
154 | tu->phy.state = OTG_STATE_B_IDLE; | ||
155 | |||
156 | check_vbus_state(tu); | ||
157 | } | ||
158 | |||
159 | static void tahvo_usb_stop_peripheral(struct tahvo_usb *tu) | ||
160 | { | ||
161 | if (tu->phy.otg->gadget) | ||
162 | usb_gadget_vbus_disconnect(tu->phy.otg->gadget); | ||
163 | tu->phy.state = OTG_STATE_B_IDLE; | ||
164 | } | ||
165 | |||
166 | static void tahvo_usb_power_off(struct tahvo_usb *tu) | ||
167 | { | ||
168 | struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); | ||
169 | |||
170 | /* Disable gadget controller if any */ | ||
171 | if (tu->phy.otg->gadget) | ||
172 | usb_gadget_vbus_disconnect(tu->phy.otg->gadget); | ||
173 | |||
174 | /* Power off transceiver */ | ||
175 | retu_write(rdev, TAHVO_REG_USBR, 0); | ||
176 | tu->phy.state = OTG_STATE_UNDEFINED; | ||
177 | } | ||
178 | |||
179 | static int tahvo_usb_set_suspend(struct usb_phy *dev, int suspend) | ||
180 | { | ||
181 | struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, phy); | ||
182 | struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); | ||
183 | u16 w; | ||
184 | |||
185 | dev_dbg(&tu->pt_dev->dev, "%s\n", __func__); | ||
186 | |||
187 | w = retu_read(rdev, TAHVO_REG_USBR); | ||
188 | if (suspend) | ||
189 | w &= ~USBR_NSUSPEND; | ||
190 | else | ||
191 | w |= USBR_NSUSPEND; | ||
192 | retu_write(rdev, TAHVO_REG_USBR, w); | ||
193 | |||
194 | return 0; | ||
195 | } | ||
196 | |||
197 | static int tahvo_usb_set_host(struct usb_otg *otg, struct usb_bus *host) | ||
198 | { | ||
199 | struct tahvo_usb *tu = container_of(otg->phy, struct tahvo_usb, phy); | ||
200 | |||
201 | dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, host); | ||
202 | |||
203 | mutex_lock(&tu->serialize); | ||
204 | |||
205 | if (host == NULL) { | ||
206 | if (tu->tahvo_mode == TAHVO_MODE_HOST) | ||
207 | tahvo_usb_power_off(tu); | ||
208 | otg->host = NULL; | ||
209 | mutex_unlock(&tu->serialize); | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | if (tu->tahvo_mode == TAHVO_MODE_HOST) { | ||
214 | otg->host = NULL; | ||
215 | tahvo_usb_become_host(tu); | ||
216 | } | ||
217 | |||
218 | otg->host = host; | ||
219 | |||
220 | mutex_unlock(&tu->serialize); | ||
221 | |||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | static int tahvo_usb_set_peripheral(struct usb_otg *otg, | ||
226 | struct usb_gadget *gadget) | ||
227 | { | ||
228 | struct tahvo_usb *tu = container_of(otg->phy, struct tahvo_usb, phy); | ||
229 | |||
230 | dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, gadget); | ||
231 | |||
232 | mutex_lock(&tu->serialize); | ||
233 | |||
234 | if (!gadget) { | ||
235 | if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) | ||
236 | tahvo_usb_power_off(tu); | ||
237 | tu->phy.otg->gadget = NULL; | ||
238 | mutex_unlock(&tu->serialize); | ||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | tu->phy.otg->gadget = gadget; | ||
243 | if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) | ||
244 | tahvo_usb_become_peripheral(tu); | ||
245 | |||
246 | mutex_unlock(&tu->serialize); | ||
247 | |||
248 | return 0; | ||
249 | } | ||
250 | |||
251 | static irqreturn_t tahvo_usb_vbus_interrupt(int irq, void *_tu) | ||
252 | { | ||
253 | struct tahvo_usb *tu = _tu; | ||
254 | |||
255 | mutex_lock(&tu->serialize); | ||
256 | check_vbus_state(tu); | ||
257 | mutex_unlock(&tu->serialize); | ||
258 | |||
259 | return IRQ_HANDLED; | ||
260 | } | ||
261 | |||
262 | static ssize_t otg_mode_show(struct device *device, | ||
263 | struct device_attribute *attr, char *buf) | ||
264 | { | ||
265 | struct tahvo_usb *tu = dev_get_drvdata(device); | ||
266 | |||
267 | switch (tu->tahvo_mode) { | ||
268 | case TAHVO_MODE_HOST: | ||
269 | return sprintf(buf, "host\n"); | ||
270 | case TAHVO_MODE_PERIPHERAL: | ||
271 | return sprintf(buf, "peripheral\n"); | ||
272 | } | ||
273 | |||
274 | return -EINVAL; | ||
275 | } | ||
276 | |||
277 | static ssize_t otg_mode_store(struct device *device, | ||
278 | struct device_attribute *attr, | ||
279 | const char *buf, size_t count) | ||
280 | { | ||
281 | struct tahvo_usb *tu = dev_get_drvdata(device); | ||
282 | int r; | ||
283 | |||
284 | mutex_lock(&tu->serialize); | ||
285 | if (count >= 4 && strncmp(buf, "host", 4) == 0) { | ||
286 | if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) | ||
287 | tahvo_usb_stop_peripheral(tu); | ||
288 | tu->tahvo_mode = TAHVO_MODE_HOST; | ||
289 | if (tu->phy.otg->host) { | ||
290 | dev_info(device, "HOST mode: host controller present\n"); | ||
291 | tahvo_usb_become_host(tu); | ||
292 | } else { | ||
293 | dev_info(device, "HOST mode: no host controller, powering off\n"); | ||
294 | tahvo_usb_power_off(tu); | ||
295 | } | ||
296 | r = strlen(buf); | ||
297 | } else if (count >= 10 && strncmp(buf, "peripheral", 10) == 0) { | ||
298 | if (tu->tahvo_mode == TAHVO_MODE_HOST) | ||
299 | tahvo_usb_stop_host(tu); | ||
300 | tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; | ||
301 | if (tu->phy.otg->gadget) { | ||
302 | dev_info(device, "PERIPHERAL mode: gadget driver present\n"); | ||
303 | tahvo_usb_become_peripheral(tu); | ||
304 | } else { | ||
305 | dev_info(device, "PERIPHERAL mode: no gadget driver, powering off\n"); | ||
306 | tahvo_usb_power_off(tu); | ||
307 | } | ||
308 | r = strlen(buf); | ||
309 | } else { | ||
310 | r = -EINVAL; | ||
311 | } | ||
312 | mutex_unlock(&tu->serialize); | ||
313 | |||
314 | return r; | ||
315 | } | ||
316 | static DEVICE_ATTR(otg_mode, 0644, otg_mode_show, otg_mode_store); | ||
317 | |||
318 | static struct attribute *tahvo_attributes[] = { | ||
319 | &dev_attr_vbus.attr, | ||
320 | &dev_attr_otg_mode.attr, | ||
321 | NULL | ||
322 | }; | ||
323 | |||
324 | static struct attribute_group tahvo_attr_group = { | ||
325 | .attrs = tahvo_attributes, | ||
326 | }; | ||
327 | |||
328 | static int tahvo_usb_probe(struct platform_device *pdev) | ||
329 | { | ||
330 | struct retu_dev *rdev = dev_get_drvdata(pdev->dev.parent); | ||
331 | struct tahvo_usb *tu; | ||
332 | int ret; | ||
333 | |||
334 | tu = devm_kzalloc(&pdev->dev, sizeof(*tu), GFP_KERNEL); | ||
335 | if (!tu) | ||
336 | return -ENOMEM; | ||
337 | |||
338 | tu->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*tu->phy.otg), | ||
339 | GFP_KERNEL); | ||
340 | if (!tu->phy.otg) | ||
341 | return -ENOMEM; | ||
342 | |||
343 | tu->pt_dev = pdev; | ||
344 | |||
345 | /* Default mode */ | ||
346 | #ifdef CONFIG_TAHVO_USB_HOST_BY_DEFAULT | ||
347 | tu->tahvo_mode = TAHVO_MODE_HOST; | ||
348 | #else | ||
349 | tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; | ||
350 | #endif | ||
351 | |||
352 | mutex_init(&tu->serialize); | ||
353 | |||
354 | tu->ick = devm_clk_get(&pdev->dev, "usb_l4_ick"); | ||
355 | if (!IS_ERR(tu->ick)) | ||
356 | clk_enable(tu->ick); | ||
357 | |||
358 | /* | ||
359 | * Set initial state, so that we generate kevents only on state changes. | ||
360 | */ | ||
361 | tu->vbus_state = retu_read(rdev, TAHVO_REG_IDSR) & TAHVO_STAT_VBUS; | ||
362 | |||
363 | tu->extcon.name = DRIVER_NAME; | ||
364 | tu->extcon.supported_cable = tahvo_cable; | ||
365 | tu->extcon.dev.parent = &pdev->dev; | ||
366 | |||
367 | ret = extcon_dev_register(&tu->extcon); | ||
368 | if (ret) { | ||
369 | dev_err(&pdev->dev, "could not register extcon device: %d\n", | ||
370 | ret); | ||
371 | goto err_disable_clk; | ||
372 | } | ||
373 | |||
374 | /* Set the initial cable state. */ | ||
375 | extcon_set_cable_state(&tu->extcon, "USB-HOST", | ||
376 | tu->tahvo_mode == TAHVO_MODE_HOST); | ||
377 | extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state); | ||
378 | |||
379 | /* Create OTG interface */ | ||
380 | tahvo_usb_power_off(tu); | ||
381 | tu->phy.dev = &pdev->dev; | ||
382 | tu->phy.state = OTG_STATE_UNDEFINED; | ||
383 | tu->phy.label = DRIVER_NAME; | ||
384 | tu->phy.set_suspend = tahvo_usb_set_suspend; | ||
385 | |||
386 | tu->phy.otg->phy = &tu->phy; | ||
387 | tu->phy.otg->set_host = tahvo_usb_set_host; | ||
388 | tu->phy.otg->set_peripheral = tahvo_usb_set_peripheral; | ||
389 | |||
390 | ret = usb_add_phy(&tu->phy, USB_PHY_TYPE_USB2); | ||
391 | if (ret < 0) { | ||
392 | dev_err(&pdev->dev, "cannot register USB transceiver: %d\n", | ||
393 | ret); | ||
394 | goto err_extcon_unreg; | ||
395 | } | ||
396 | |||
397 | dev_set_drvdata(&pdev->dev, tu); | ||
398 | |||
399 | tu->irq = platform_get_irq(pdev, 0); | ||
400 | ret = request_threaded_irq(tu->irq, NULL, tahvo_usb_vbus_interrupt, 0, | ||
401 | "tahvo-vbus", tu); | ||
402 | if (ret) { | ||
403 | dev_err(&pdev->dev, "could not register tahvo-vbus irq: %d\n", | ||
404 | ret); | ||
405 | goto err_remove_phy; | ||
406 | } | ||
407 | |||
408 | /* Attributes */ | ||
409 | ret = sysfs_create_group(&pdev->dev.kobj, &tahvo_attr_group); | ||
410 | if (ret) { | ||
411 | dev_err(&pdev->dev, "cannot create sysfs group: %d\n", ret); | ||
412 | goto err_free_irq; | ||
413 | } | ||
414 | |||
415 | return 0; | ||
416 | |||
417 | err_free_irq: | ||
418 | free_irq(tu->irq, tu); | ||
419 | err_remove_phy: | ||
420 | usb_remove_phy(&tu->phy); | ||
421 | err_extcon_unreg: | ||
422 | extcon_dev_unregister(&tu->extcon); | ||
423 | err_disable_clk: | ||
424 | if (!IS_ERR(tu->ick)) | ||
425 | clk_disable(tu->ick); | ||
426 | |||
427 | return ret; | ||
428 | } | ||
429 | |||
430 | static int tahvo_usb_remove(struct platform_device *pdev) | ||
431 | { | ||
432 | struct tahvo_usb *tu = platform_get_drvdata(pdev); | ||
433 | |||
434 | sysfs_remove_group(&pdev->dev.kobj, &tahvo_attr_group); | ||
435 | free_irq(tu->irq, tu); | ||
436 | usb_remove_phy(&tu->phy); | ||
437 | extcon_dev_unregister(&tu->extcon); | ||
438 | if (!IS_ERR(tu->ick)) | ||
439 | clk_disable(tu->ick); | ||
440 | |||
441 | return 0; | ||
442 | } | ||
443 | |||
444 | static struct platform_driver tahvo_usb_driver = { | ||
445 | .probe = tahvo_usb_probe, | ||
446 | .remove = tahvo_usb_remove, | ||
447 | .driver = { | ||
448 | .name = "tahvo-usb", | ||
449 | .owner = THIS_MODULE, | ||
450 | }, | ||
451 | }; | ||
452 | module_platform_driver(tahvo_usb_driver); | ||
453 | |||
454 | MODULE_DESCRIPTION("Tahvo USB transceiver driver"); | ||
455 | MODULE_LICENSE("GPL"); | ||
456 | MODULE_AUTHOR("Juha Yrjölä, Tony Lindgren, and Timo Teräs"); | ||
457 | MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>"); | ||
diff --git a/drivers/usb/phy/phy-twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c index bad57ce77ba5..214172b68d5d 100644 --- a/drivers/usb/phy/phy-twl6030-usb.c +++ b/drivers/usb/phy/phy-twl6030-usb.c | |||
@@ -328,7 +328,7 @@ static int twl6030_usb_probe(struct platform_device *pdev) | |||
328 | struct device *dev = &pdev->dev; | 328 | struct device *dev = &pdev->dev; |
329 | struct twl4030_usb_data *pdata = dev_get_platdata(dev); | 329 | struct twl4030_usb_data *pdata = dev_get_platdata(dev); |
330 | 330 | ||
331 | twl = devm_kzalloc(dev, sizeof *twl, GFP_KERNEL); | 331 | twl = devm_kzalloc(dev, sizeof(*twl), GFP_KERNEL); |
332 | if (!twl) | 332 | if (!twl) |
333 | return -ENOMEM; | 333 | return -ENOMEM; |
334 | 334 | ||
diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 1b74523e1fee..e6f61e4361df 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c | |||
@@ -329,6 +329,8 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type) | |||
329 | return -EINVAL; | 329 | return -EINVAL; |
330 | } | 330 | } |
331 | 331 | ||
332 | ATOMIC_INIT_NOTIFIER_HEAD(&x->notifier); | ||
333 | |||
332 | spin_lock_irqsave(&phy_lock, flags); | 334 | spin_lock_irqsave(&phy_lock, flags); |
333 | 335 | ||
334 | list_for_each_entry(phy, &phy_list, head) { | 336 | list_for_each_entry(phy, &phy_list, head) { |
@@ -367,6 +369,8 @@ int usb_add_phy_dev(struct usb_phy *x) | |||
367 | return -EINVAL; | 369 | return -EINVAL; |
368 | } | 370 | } |
369 | 371 | ||
372 | ATOMIC_INIT_NOTIFIER_HEAD(&x->notifier); | ||
373 | |||
370 | spin_lock_irqsave(&phy_lock, flags); | 374 | spin_lock_irqsave(&phy_lock, flags); |
371 | list_for_each_entry(phy_bind, &phy_bind_list, list) | 375 | list_for_each_entry(phy_bind, &phy_bind_list, list) |
372 | if (!(strcmp(phy_bind->phy_dev_name, dev_name(x->dev)))) | 376 | if (!(strcmp(phy_bind->phy_dev_name, dev_name(x->dev)))) |
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c index 45b94019aec8..d49f9c326035 100644 --- a/drivers/usb/renesas_usbhs/fifo.c +++ b/drivers/usb/renesas_usbhs/fifo.c | |||
@@ -1124,19 +1124,8 @@ void usbhs_fifo_init(struct usbhs_priv *priv) | |||
1124 | mod->irq_brdysts = 0; | 1124 | mod->irq_brdysts = 0; |
1125 | 1125 | ||
1126 | cfifo->pipe = NULL; | 1126 | cfifo->pipe = NULL; |
1127 | cfifo->tx_chan = NULL; | ||
1128 | cfifo->rx_chan = NULL; | ||
1129 | |||
1130 | d0fifo->pipe = NULL; | 1127 | d0fifo->pipe = NULL; |
1131 | d0fifo->tx_chan = NULL; | ||
1132 | d0fifo->rx_chan = NULL; | ||
1133 | |||
1134 | d1fifo->pipe = NULL; | 1128 | d1fifo->pipe = NULL; |
1135 | d1fifo->tx_chan = NULL; | ||
1136 | d1fifo->rx_chan = NULL; | ||
1137 | |||
1138 | usbhsf_dma_init(priv, usbhsf_get_d0fifo(priv)); | ||
1139 | usbhsf_dma_init(priv, usbhsf_get_d1fifo(priv)); | ||
1140 | } | 1129 | } |
1141 | 1130 | ||
1142 | void usbhs_fifo_quit(struct usbhs_priv *priv) | 1131 | void usbhs_fifo_quit(struct usbhs_priv *priv) |
@@ -1147,9 +1136,6 @@ void usbhs_fifo_quit(struct usbhs_priv *priv) | |||
1147 | mod->irq_ready = NULL; | 1136 | mod->irq_ready = NULL; |
1148 | mod->irq_bempsts = 0; | 1137 | mod->irq_bempsts = 0; |
1149 | mod->irq_brdysts = 0; | 1138 | mod->irq_brdysts = 0; |
1150 | |||
1151 | usbhsf_dma_quit(priv, usbhsf_get_d0fifo(priv)); | ||
1152 | usbhsf_dma_quit(priv, usbhsf_get_d1fifo(priv)); | ||
1153 | } | 1139 | } |
1154 | 1140 | ||
1155 | int usbhs_fifo_probe(struct usbhs_priv *priv) | 1141 | int usbhs_fifo_probe(struct usbhs_priv *priv) |
@@ -1171,6 +1157,7 @@ int usbhs_fifo_probe(struct usbhs_priv *priv) | |||
1171 | fifo->ctr = D0FIFOCTR; | 1157 | fifo->ctr = D0FIFOCTR; |
1172 | fifo->tx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d0_tx_id); | 1158 | fifo->tx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d0_tx_id); |
1173 | fifo->rx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d0_rx_id); | 1159 | fifo->rx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d0_rx_id); |
1160 | usbhsf_dma_init(priv, fifo); | ||
1174 | 1161 | ||
1175 | /* D1FIFO */ | 1162 | /* D1FIFO */ |
1176 | fifo = usbhsf_get_d1fifo(priv); | 1163 | fifo = usbhsf_get_d1fifo(priv); |
@@ -1180,10 +1167,13 @@ int usbhs_fifo_probe(struct usbhs_priv *priv) | |||
1180 | fifo->ctr = D1FIFOCTR; | 1167 | fifo->ctr = D1FIFOCTR; |
1181 | fifo->tx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d1_tx_id); | 1168 | fifo->tx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d1_tx_id); |
1182 | fifo->rx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d1_rx_id); | 1169 | fifo->rx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d1_rx_id); |
1170 | usbhsf_dma_init(priv, fifo); | ||
1183 | 1171 | ||
1184 | return 0; | 1172 | return 0; |
1185 | } | 1173 | } |
1186 | 1174 | ||
1187 | void usbhs_fifo_remove(struct usbhs_priv *priv) | 1175 | void usbhs_fifo_remove(struct usbhs_priv *priv) |
1188 | { | 1176 | { |
1177 | usbhsf_dma_quit(priv, usbhsf_get_d0fifo(priv)); | ||
1178 | usbhsf_dma_quit(priv, usbhsf_get_d1fifo(priv)); | ||
1189 | } | 1179 | } |
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c index 3385aeb5a364..458f3766bef1 100644 --- a/drivers/usb/renesas_usbhs/mod_gadget.c +++ b/drivers/usb/renesas_usbhs/mod_gadget.c | |||
@@ -987,11 +987,11 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv) | |||
987 | /* init DCP */ | 987 | /* init DCP */ |
988 | if (usbhsg_is_dcp(uep)) { | 988 | if (usbhsg_is_dcp(uep)) { |
989 | gpriv->gadget.ep0 = &uep->ep; | 989 | gpriv->gadget.ep0 = &uep->ep; |
990 | uep->ep.maxpacket = 64; | 990 | usb_ep_set_maxpacket_limit(&uep->ep, 64); |
991 | } | 991 | } |
992 | /* init normal pipe */ | 992 | /* init normal pipe */ |
993 | else { | 993 | else { |
994 | uep->ep.maxpacket = 512; | 994 | usb_ep_set_maxpacket_limit(&uep->ep, 512); |
995 | list_add_tail(&uep->ep.ep_list, &gpriv->gadget.ep_list); | 995 | list_add_tail(&uep->ep.ep_list, &gpriv->gadget.ep_list); |
996 | } | 996 | } |
997 | } | 997 | } |
diff --git a/drivers/usb/renesas_usbhs/mod_host.c b/drivers/usb/renesas_usbhs/mod_host.c index e40f565004d0..10e1ded9c9cc 100644 --- a/drivers/usb/renesas_usbhs/mod_host.c +++ b/drivers/usb/renesas_usbhs/mod_host.c | |||
@@ -1469,6 +1469,7 @@ static int usbhsh_start(struct usbhs_priv *priv) | |||
1469 | ret = usb_add_hcd(hcd, 0, 0); | 1469 | ret = usb_add_hcd(hcd, 0, 0); |
1470 | if (ret < 0) | 1470 | if (ret < 0) |
1471 | return 0; | 1471 | return 0; |
1472 | device_wakeup_enable(hcd->self.controller); | ||
1472 | 1473 | ||
1473 | /* | 1474 | /* |
1474 | * pipe initialize and enable DCP | 1475 | * pipe initialize and enable DCP |
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig index ddb9c51f2c99..3ce5c74b29e4 100644 --- a/drivers/usb/serial/Kconfig +++ b/drivers/usb/serial/Kconfig | |||
@@ -472,6 +472,35 @@ config USB_SERIAL_MOS7840 | |||
472 | To compile this driver as a module, choose M here: the | 472 | To compile this driver as a module, choose M here: the |
473 | module will be called mos7840. If unsure, choose N. | 473 | module will be called mos7840. If unsure, choose N. |
474 | 474 | ||
475 | config USB_SERIAL_MXUPORT | ||
476 | tristate "USB Moxa UPORT Serial Driver" | ||
477 | ---help--- | ||
478 | Say Y here if you want to use a MOXA UPort Serial hub. | ||
479 | |||
480 | This driver supports: | ||
481 | |||
482 | [2 Port] | ||
483 | - UPort 1250 : 2 Port RS-232/422/485 USB to Serial Hub | ||
484 | - UPort 1250I : 2 Port RS-232/422/485 USB to Serial Hub with | ||
485 | Isolation | ||
486 | |||
487 | [4 Port] | ||
488 | - UPort 1410 : 4 Port RS-232 USB to Serial Hub | ||
489 | - UPort 1450 : 4 Port RS-232/422/485 USB to Serial Hub | ||
490 | - UPort 1450I : 4 Port RS-232/422/485 USB to Serial Hub with | ||
491 | Isolation | ||
492 | |||
493 | [8 Port] | ||
494 | - UPort 1610-8 : 8 Port RS-232 USB to Serial Hub | ||
495 | - UPort 1650-8 : 8 Port RS-232/422/485 USB to Serial Hub | ||
496 | |||
497 | [16 Port] | ||
498 | - UPort 1610-16 : 16 Port RS-232 USB to Serial Hub | ||
499 | - UPort 1650-16 : 16 Port RS-232/422/485 USB to Serial Hub | ||
500 | |||
501 | To compile this driver as a module, choose M here: the | ||
502 | module will be called mxuport. | ||
503 | |||
475 | config USB_SERIAL_NAVMAN | 504 | config USB_SERIAL_NAVMAN |
476 | tristate "USB Navman GPS device" | 505 | tristate "USB Navman GPS device" |
477 | help | 506 | help |
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile index 42670f0b5bc0..bfdafd349441 100644 --- a/drivers/usb/serial/Makefile +++ b/drivers/usb/serial/Makefile | |||
@@ -37,6 +37,7 @@ obj-$(CONFIG_USB_SERIAL_MCT_U232) += mct_u232.o | |||
37 | obj-$(CONFIG_USB_SERIAL_METRO) += metro-usb.o | 37 | obj-$(CONFIG_USB_SERIAL_METRO) += metro-usb.o |
38 | obj-$(CONFIG_USB_SERIAL_MOS7720) += mos7720.o | 38 | obj-$(CONFIG_USB_SERIAL_MOS7720) += mos7720.o |
39 | obj-$(CONFIG_USB_SERIAL_MOS7840) += mos7840.o | 39 | obj-$(CONFIG_USB_SERIAL_MOS7840) += mos7840.o |
40 | obj-$(CONFIG_USB_SERIAL_MXUPORT) += mxuport.o | ||
40 | obj-$(CONFIG_USB_SERIAL_NAVMAN) += navman.o | 41 | obj-$(CONFIG_USB_SERIAL_NAVMAN) += navman.o |
41 | obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o | 42 | obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o |
42 | obj-$(CONFIG_USB_SERIAL_OPTICON) += opticon.o | 43 | obj-$(CONFIG_USB_SERIAL_OPTICON) += opticon.o |
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c index 6e320cec397d..80a9845cd93f 100644 --- a/drivers/usb/serial/aircable.c +++ b/drivers/usb/serial/aircable.c | |||
@@ -10,9 +10,9 @@ | |||
10 | * | 10 | * |
11 | * The device works as an standard CDC device, it has 2 interfaces, the first | 11 | * The device works as an standard CDC device, it has 2 interfaces, the first |
12 | * one is for firmware access and the second is the serial one. | 12 | * one is for firmware access and the second is the serial one. |
13 | * The protocol is very simply, there are two posibilities reading or writing. | 13 | * The protocol is very simply, there are two possibilities reading or writing. |
14 | * When writing the first urb must have a Header that starts with 0x20 0x29 the | 14 | * When writing the first urb must have a Header that starts with 0x20 0x29 the |
15 | * next two bytes must say how much data will be sended. | 15 | * next two bytes must say how much data will be sent. |
16 | * When reading the process is almost equal except that the header starts with | 16 | * When reading the process is almost equal except that the header starts with |
17 | * 0x00 0x20. | 17 | * 0x00 0x20. |
18 | * | 18 | * |
@@ -31,15 +31,15 @@ | |||
31 | * | 31 | * |
32 | * The driver registers himself with the USB-serial core and the USB Core. I had | 32 | * The driver registers himself with the USB-serial core and the USB Core. I had |
33 | * to implement a probe function against USB-serial, because other way, the | 33 | * to implement a probe function against USB-serial, because other way, the |
34 | * driver was attaching himself to both interfaces. I have tryed with different | 34 | * driver was attaching himself to both interfaces. I have tried with different |
35 | * configurations of usb_serial_driver with out exit, only the probe function | 35 | * configurations of usb_serial_driver with out exit, only the probe function |
36 | * could handle this correctly. | 36 | * could handle this correctly. |
37 | * | 37 | * |
38 | * I have taken some info from a Greg Kroah-Hartman article: | 38 | * I have taken some info from a Greg Kroah-Hartman article: |
39 | * http://www.linuxjournal.com/article/6573 | 39 | * http://www.linuxjournal.com/article/6573 |
40 | * And from Linux Device Driver Kit CD, which is a great work, the authors taken | 40 | * And from Linux Device Driver Kit CD, which is a great work, the authors taken |
41 | * the work to recompile lots of information an knowladge in drivers development | 41 | * the work to recompile lots of information an knowledge in drivers development |
42 | * and made it all avaible inside a cd. | 42 | * and made it all available inside a cd. |
43 | * URL: http://kernel.org/pub/linux/kernel/people/gregkh/ddk/ | 43 | * URL: http://kernel.org/pub/linux/kernel/people/gregkh/ddk/ |
44 | * | 44 | * |
45 | */ | 45 | */ |
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c index bc77e955cbef..1532cde8a437 100644 --- a/drivers/usb/serial/ark3116.c +++ b/drivers/usb/serial/ark3116.c | |||
@@ -23,7 +23,6 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/init.h> | ||
27 | #include <linux/ioctl.h> | 26 | #include <linux/ioctl.h> |
28 | #include <linux/tty.h> | 27 | #include <linux/tty.h> |
29 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
@@ -71,7 +70,7 @@ struct ark3116_private { | |||
71 | __u32 lcr; /* line control register value */ | 70 | __u32 lcr; /* line control register value */ |
72 | __u32 hcr; /* handshake control register (0x8) | 71 | __u32 hcr; /* handshake control register (0x8) |
73 | * value */ | 72 | * value */ |
74 | __u32 mcr; /* modem contol register value */ | 73 | __u32 mcr; /* modem control register value */ |
75 | 74 | ||
76 | /* protects the status values below */ | 75 | /* protects the status values below */ |
77 | spinlock_t status_lock; | 76 | spinlock_t status_lock; |
@@ -609,7 +608,7 @@ static void ark3116_read_int_callback(struct urb *urb) | |||
609 | } | 608 | } |
610 | 609 | ||
611 | 610 | ||
612 | /* Data comes in via the bulk (data) URB, erors/interrupts via the int URB. | 611 | /* Data comes in via the bulk (data) URB, errors/interrupts via the int URB. |
613 | * This means that we cannot be sure which data byte has an associated error | 612 | * This means that we cannot be sure which data byte has an associated error |
614 | * condition, so we report an error for all data in the next bulk read. | 613 | * condition, so we report an error for all data in the next bulk read. |
615 | * | 614 | * |
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c index 84217e78ded4..15bc71853db5 100644 --- a/drivers/usb/serial/belkin_sa.c +++ b/drivers/usb/serial/belkin_sa.c | |||
@@ -18,14 +18,13 @@ | |||
18 | * driver | 18 | * driver |
19 | * | 19 | * |
20 | * TODO: | 20 | * TODO: |
21 | * -- Add true modem contol line query capability. Currently we track the | 21 | * -- Add true modem control line query capability. Currently we track the |
22 | * states reported by the interrupt and the states we request. | 22 | * states reported by the interrupt and the states we request. |
23 | * -- Add support for flush commands | 23 | * -- Add support for flush commands |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
28 | #include <linux/init.h> | ||
29 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
30 | #include <linux/tty.h> | 29 | #include <linux/tty.h> |
31 | #include <linux/tty_driver.h> | 30 | #include <linux/tty_driver.h> |
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c index 6335490d5760..35a2373cde67 100644 --- a/drivers/usb/serial/bus.c +++ b/drivers/usb/serial/bus.c | |||
@@ -125,10 +125,12 @@ static ssize_t new_id_store(struct device_driver *driver, | |||
125 | const char *buf, size_t count) | 125 | const char *buf, size_t count) |
126 | { | 126 | { |
127 | struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver); | 127 | struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver); |
128 | ssize_t retval = usb_store_new_id(&usb_drv->dynids, driver, buf, count); | 128 | ssize_t retval = usb_store_new_id(&usb_drv->dynids, usb_drv->id_table, |
129 | driver, buf, count); | ||
129 | 130 | ||
130 | if (retval >= 0 && usb_drv->usb_driver != NULL) | 131 | if (retval >= 0 && usb_drv->usb_driver != NULL) |
131 | retval = usb_store_new_id(&usb_drv->usb_driver->dynids, | 132 | retval = usb_store_new_id(&usb_drv->usb_driver->dynids, |
133 | usb_drv->usb_driver->id_table, | ||
132 | &usb_drv->usb_driver->drvwrap.driver, | 134 | &usb_drv->usb_driver->drvwrap.driver, |
133 | buf, count); | 135 | buf, count); |
134 | return retval; | 136 | return retval; |
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c index c2a4171ab9cb..82371f61f23d 100644 --- a/drivers/usb/serial/ch341.c +++ b/drivers/usb/serial/ch341.c | |||
@@ -16,7 +16,6 @@ | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/init.h> | ||
20 | #include <linux/tty.h> | 19 | #include <linux/tty.h> |
21 | #include <linux/module.h> | 20 | #include <linux/module.h> |
22 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
@@ -83,7 +82,6 @@ struct ch341_private { | |||
83 | unsigned baud_rate; /* set baud rate */ | 82 | unsigned baud_rate; /* set baud rate */ |
84 | u8 line_control; /* set line control value RTS/DTR */ | 83 | u8 line_control; /* set line control value RTS/DTR */ |
85 | u8 line_status; /* active status of modem control inputs */ | 84 | u8 line_status; /* active status of modem control inputs */ |
86 | u8 multi_status_change; /* status changed multiple since last call */ | ||
87 | }; | 85 | }; |
88 | 86 | ||
89 | static int ch341_control_out(struct usb_device *dev, u8 request, | 87 | static int ch341_control_out(struct usb_device *dev, u8 request, |
@@ -174,7 +172,6 @@ static int ch341_get_status(struct usb_device *dev, struct ch341_private *priv) | |||
174 | r = 0; | 172 | r = 0; |
175 | spin_lock_irqsave(&priv->lock, flags); | 173 | spin_lock_irqsave(&priv->lock, flags); |
176 | priv->line_status = (~(*buffer)) & CH341_BITS_MODEM_STAT; | 174 | priv->line_status = (~(*buffer)) & CH341_BITS_MODEM_STAT; |
177 | priv->multi_status_change = 0; | ||
178 | spin_unlock_irqrestore(&priv->lock, flags); | 175 | spin_unlock_irqrestore(&priv->lock, flags); |
179 | } else | 176 | } else |
180 | r = -EPROTO; | 177 | r = -EPROTO; |
@@ -384,10 +381,8 @@ static void ch341_break_ctl(struct tty_struct *tty, int break_state) | |||
384 | uint8_t *break_reg; | 381 | uint8_t *break_reg; |
385 | 382 | ||
386 | break_reg = kmalloc(2, GFP_KERNEL); | 383 | break_reg = kmalloc(2, GFP_KERNEL); |
387 | if (!break_reg) { | 384 | if (!break_reg) |
388 | dev_err(&port->dev, "%s - kmalloc failed\n", __func__); | ||
389 | return; | 385 | return; |
390 | } | ||
391 | 386 | ||
392 | r = ch341_control_in(port->serial->dev, CH341_REQ_READ_REG, | 387 | r = ch341_control_in(port->serial->dev, CH341_REQ_READ_REG, |
393 | ch341_break_reg, 0, break_reg, 2); | 388 | ch341_break_reg, 0, break_reg, 2); |
@@ -442,11 +437,55 @@ static int ch341_tiocmset(struct tty_struct *tty, | |||
442 | return ch341_set_handshake(port->serial->dev, control); | 437 | return ch341_set_handshake(port->serial->dev, control); |
443 | } | 438 | } |
444 | 439 | ||
440 | static void ch341_update_line_status(struct usb_serial_port *port, | ||
441 | unsigned char *data, size_t len) | ||
442 | { | ||
443 | struct ch341_private *priv = usb_get_serial_port_data(port); | ||
444 | struct tty_struct *tty; | ||
445 | unsigned long flags; | ||
446 | u8 status; | ||
447 | u8 delta; | ||
448 | |||
449 | if (len < 4) | ||
450 | return; | ||
451 | |||
452 | status = ~data[2] & CH341_BITS_MODEM_STAT; | ||
453 | |||
454 | spin_lock_irqsave(&priv->lock, flags); | ||
455 | delta = status ^ priv->line_status; | ||
456 | priv->line_status = status; | ||
457 | spin_unlock_irqrestore(&priv->lock, flags); | ||
458 | |||
459 | if (data[1] & CH341_MULT_STAT) | ||
460 | dev_dbg(&port->dev, "%s - multiple status change\n", __func__); | ||
461 | |||
462 | if (!delta) | ||
463 | return; | ||
464 | |||
465 | if (delta & CH341_BIT_CTS) | ||
466 | port->icount.cts++; | ||
467 | if (delta & CH341_BIT_DSR) | ||
468 | port->icount.dsr++; | ||
469 | if (delta & CH341_BIT_RI) | ||
470 | port->icount.rng++; | ||
471 | if (delta & CH341_BIT_DCD) { | ||
472 | port->icount.dcd++; | ||
473 | tty = tty_port_tty_get(&port->port); | ||
474 | if (tty) { | ||
475 | usb_serial_handle_dcd_change(port, tty, | ||
476 | status & CH341_BIT_DCD); | ||
477 | tty_kref_put(tty); | ||
478 | } | ||
479 | } | ||
480 | |||
481 | wake_up_interruptible(&port->port.delta_msr_wait); | ||
482 | } | ||
483 | |||
445 | static void ch341_read_int_callback(struct urb *urb) | 484 | static void ch341_read_int_callback(struct urb *urb) |
446 | { | 485 | { |
447 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; | 486 | struct usb_serial_port *port = urb->context; |
448 | unsigned char *data = urb->transfer_buffer; | 487 | unsigned char *data = urb->transfer_buffer; |
449 | unsigned int actual_length = urb->actual_length; | 488 | unsigned int len = urb->actual_length; |
450 | int status; | 489 | int status; |
451 | 490 | ||
452 | switch (urb->status) { | 491 | switch (urb->status) { |
@@ -457,89 +496,23 @@ static void ch341_read_int_callback(struct urb *urb) | |||
457 | case -ENOENT: | 496 | case -ENOENT: |
458 | case -ESHUTDOWN: | 497 | case -ESHUTDOWN: |
459 | /* this urb is terminated, clean up */ | 498 | /* this urb is terminated, clean up */ |
460 | dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", | 499 | dev_dbg(&urb->dev->dev, "%s - urb shutting down: %d\n", |
461 | __func__, urb->status); | 500 | __func__, urb->status); |
462 | return; | 501 | return; |
463 | default: | 502 | default: |
464 | dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", | 503 | dev_dbg(&urb->dev->dev, "%s - nonzero urb status: %d\n", |
465 | __func__, urb->status); | 504 | __func__, urb->status); |
466 | goto exit; | 505 | goto exit; |
467 | } | 506 | } |
468 | 507 | ||
469 | usb_serial_debug_data(&port->dev, __func__, | 508 | usb_serial_debug_data(&port->dev, __func__, len, data); |
470 | urb->actual_length, urb->transfer_buffer); | 509 | ch341_update_line_status(port, data, len); |
471 | |||
472 | if (actual_length >= 4) { | ||
473 | struct ch341_private *priv = usb_get_serial_port_data(port); | ||
474 | unsigned long flags; | ||
475 | u8 prev_line_status = priv->line_status; | ||
476 | |||
477 | spin_lock_irqsave(&priv->lock, flags); | ||
478 | priv->line_status = (~(data[2])) & CH341_BITS_MODEM_STAT; | ||
479 | if ((data[1] & CH341_MULT_STAT)) | ||
480 | priv->multi_status_change = 1; | ||
481 | spin_unlock_irqrestore(&priv->lock, flags); | ||
482 | |||
483 | if ((priv->line_status ^ prev_line_status) & CH341_BIT_DCD) { | ||
484 | struct tty_struct *tty = tty_port_tty_get(&port->port); | ||
485 | if (tty) | ||
486 | usb_serial_handle_dcd_change(port, tty, | ||
487 | priv->line_status & CH341_BIT_DCD); | ||
488 | tty_kref_put(tty); | ||
489 | } | ||
490 | |||
491 | wake_up_interruptible(&port->port.delta_msr_wait); | ||
492 | } | ||
493 | |||
494 | exit: | 510 | exit: |
495 | status = usb_submit_urb(urb, GFP_ATOMIC); | 511 | status = usb_submit_urb(urb, GFP_ATOMIC); |
496 | if (status) | 512 | if (status) { |
497 | dev_err(&urb->dev->dev, | 513 | dev_err(&urb->dev->dev, "%s - usb_submit_urb failed: %d\n", |
498 | "%s - usb_submit_urb failed with result %d\n", | ||
499 | __func__, status); | 514 | __func__, status); |
500 | } | ||
501 | |||
502 | static int ch341_tiocmiwait(struct tty_struct *tty, unsigned long arg) | ||
503 | { | ||
504 | struct usb_serial_port *port = tty->driver_data; | ||
505 | struct ch341_private *priv = usb_get_serial_port_data(port); | ||
506 | unsigned long flags; | ||
507 | u8 prevstatus; | ||
508 | u8 status; | ||
509 | u8 changed; | ||
510 | u8 multi_change = 0; | ||
511 | |||
512 | spin_lock_irqsave(&priv->lock, flags); | ||
513 | prevstatus = priv->line_status; | ||
514 | priv->multi_status_change = 0; | ||
515 | spin_unlock_irqrestore(&priv->lock, flags); | ||
516 | |||
517 | while (!multi_change) { | ||
518 | interruptible_sleep_on(&port->port.delta_msr_wait); | ||
519 | /* see if a signal did it */ | ||
520 | if (signal_pending(current)) | ||
521 | return -ERESTARTSYS; | ||
522 | |||
523 | if (port->serial->disconnected) | ||
524 | return -EIO; | ||
525 | |||
526 | spin_lock_irqsave(&priv->lock, flags); | ||
527 | status = priv->line_status; | ||
528 | multi_change = priv->multi_status_change; | ||
529 | spin_unlock_irqrestore(&priv->lock, flags); | ||
530 | |||
531 | changed = prevstatus ^ status; | ||
532 | |||
533 | if (((arg & TIOCM_RNG) && (changed & CH341_BIT_RI)) || | ||
534 | ((arg & TIOCM_DSR) && (changed & CH341_BIT_DSR)) || | ||
535 | ((arg & TIOCM_CD) && (changed & CH341_BIT_DCD)) || | ||
536 | ((arg & TIOCM_CTS) && (changed & CH341_BIT_CTS))) { | ||
537 | return 0; | ||
538 | } | ||
539 | prevstatus = status; | ||
540 | } | 515 | } |
541 | |||
542 | return 0; | ||
543 | } | 516 | } |
544 | 517 | ||
545 | static int ch341_tiocmget(struct tty_struct *tty) | 518 | static int ch341_tiocmget(struct tty_struct *tty) |
@@ -595,7 +568,7 @@ static struct usb_serial_driver ch341_device = { | |||
595 | .break_ctl = ch341_break_ctl, | 568 | .break_ctl = ch341_break_ctl, |
596 | .tiocmget = ch341_tiocmget, | 569 | .tiocmget = ch341_tiocmget, |
597 | .tiocmset = ch341_tiocmset, | 570 | .tiocmset = ch341_tiocmset, |
598 | .tiocmiwait = ch341_tiocmiwait, | 571 | .tiocmiwait = usb_serial_generic_tiocmiwait, |
599 | .read_int_callback = ch341_read_int_callback, | 572 | .read_int_callback = ch341_read_int_callback, |
600 | .port_probe = ch341_port_probe, | 573 | .port_probe = ch341_port_probe, |
601 | .port_remove = ch341_port_remove, | 574 | .port_remove = ch341_port_remove, |
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c index c69bb50d4663..8d7fc48b1f30 100644 --- a/drivers/usb/serial/console.c +++ b/drivers/usb/serial/console.c | |||
@@ -14,7 +14,6 @@ | |||
14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
15 | 15 | ||
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/init.h> | ||
18 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
19 | #include <linux/tty.h> | 18 | #include <linux/tty.h> |
20 | #include <linux/console.h> | 19 | #include <linux/console.h> |
@@ -135,7 +134,6 @@ static int usb_console_setup(struct console *co, char *options) | |||
135 | tty = kzalloc(sizeof(*tty), GFP_KERNEL); | 134 | tty = kzalloc(sizeof(*tty), GFP_KERNEL); |
136 | if (!tty) { | 135 | if (!tty) { |
137 | retval = -ENOMEM; | 136 | retval = -ENOMEM; |
138 | dev_err(&port->dev, "no more memory\n"); | ||
139 | goto reset_open_count; | 137 | goto reset_open_count; |
140 | } | 138 | } |
141 | kref_init(&tty->kref); | 139 | kref_init(&tty->kref); |
@@ -144,7 +142,6 @@ static int usb_console_setup(struct console *co, char *options) | |||
144 | tty->index = co->index; | 142 | tty->index = co->index; |
145 | if (tty_init_termios(tty)) { | 143 | if (tty_init_termios(tty)) { |
146 | retval = -ENOMEM; | 144 | retval = -ENOMEM; |
147 | dev_err(&port->dev, "no more memory\n"); | ||
148 | goto free_tty; | 145 | goto free_tty; |
149 | } | 146 | } |
150 | } | 147 | } |
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 6987b535aa98..95fa1217afdd 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c | |||
@@ -305,10 +305,8 @@ static int cp210x_get_config(struct usb_serial_port *port, u8 request, | |||
305 | length = (((size - 1) | 3) + 1) / 4; | 305 | length = (((size - 1) | 3) + 1) / 4; |
306 | 306 | ||
307 | buf = kcalloc(length, sizeof(__le32), GFP_KERNEL); | 307 | buf = kcalloc(length, sizeof(__le32), GFP_KERNEL); |
308 | if (!buf) { | 308 | if (!buf) |
309 | dev_err(&port->dev, "%s - out of memory.\n", __func__); | ||
310 | return -ENOMEM; | 309 | return -ENOMEM; |
311 | } | ||
312 | 310 | ||
313 | /* Issue the request, attempting to read 'size' bytes */ | 311 | /* Issue the request, attempting to read 'size' bytes */ |
314 | result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | 312 | result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), |
@@ -352,10 +350,8 @@ static int cp210x_set_config(struct usb_serial_port *port, u8 request, | |||
352 | length = (((size - 1) | 3) + 1) / 4; | 350 | length = (((size - 1) | 3) + 1) / 4; |
353 | 351 | ||
354 | buf = kmalloc(length * sizeof(__le32), GFP_KERNEL); | 352 | buf = kmalloc(length * sizeof(__le32), GFP_KERNEL); |
355 | if (!buf) { | 353 | if (!buf) |
356 | dev_err(&port->dev, "%s - out of memory.\n", __func__); | ||
357 | return -ENOMEM; | 354 | return -ENOMEM; |
358 | } | ||
359 | 355 | ||
360 | /* Array of integers into bytes */ | 356 | /* Array of integers into bytes */ |
361 | for (i = 0; i < length; i++) | 357 | for (i = 0; i < length; i++) |
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c index 6e1b69d0f5f5..0ac3b3b3236c 100644 --- a/drivers/usb/serial/cyberjack.c +++ b/drivers/usb/serial/cyberjack.c | |||
@@ -30,7 +30,6 @@ | |||
30 | 30 | ||
31 | #include <linux/kernel.h> | 31 | #include <linux/kernel.h> |
32 | #include <linux/errno.h> | 32 | #include <linux/errno.h> |
33 | #include <linux/init.h> | ||
34 | #include <linux/slab.h> | 33 | #include <linux/slab.h> |
35 | #include <linux/tty.h> | 34 | #include <linux/tty.h> |
36 | #include <linux/tty_driver.h> | 35 | #include <linux/tty_driver.h> |
@@ -285,7 +284,7 @@ static void cyberjack_read_int_callback(struct urb *urb) | |||
285 | goto resubmit; | 284 | goto resubmit; |
286 | } | 285 | } |
287 | 286 | ||
288 | /* "+=" is probably more fault tollerant than "=" */ | 287 | /* "+=" is probably more fault tolerant than "=" */ |
289 | priv->rdtodo += size; | 288 | priv->rdtodo += size; |
290 | 289 | ||
291 | dev_dbg(dev, "%s - rdtodo: %d\n", __func__, priv->rdtodo); | 290 | dev_dbg(dev, "%s - rdtodo: %d\n", __func__, priv->rdtodo); |
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c index 558605d646f3..bccb1223143a 100644 --- a/drivers/usb/serial/cypress_m8.c +++ b/drivers/usb/serial/cypress_m8.c | |||
@@ -27,7 +27,6 @@ | |||
27 | 27 | ||
28 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
29 | #include <linux/errno.h> | 29 | #include <linux/errno.h> |
30 | #include <linux/init.h> | ||
31 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
32 | #include <linux/tty.h> | 31 | #include <linux/tty.h> |
33 | #include <linux/tty_driver.h> | 32 | #include <linux/tty_driver.h> |
@@ -113,7 +112,7 @@ struct cypress_private { | |||
113 | int baud_rate; /* stores current baud rate in | 112 | int baud_rate; /* stores current baud rate in |
114 | integer form */ | 113 | integer form */ |
115 | int isthrottled; /* if throttled, discard reads */ | 114 | int isthrottled; /* if throttled, discard reads */ |
116 | char prev_status, diff_status; /* used for TIOCMIWAIT */ | 115 | char prev_status; /* used for TIOCMIWAIT */ |
117 | /* we pass a pointer to this as the argument sent to | 116 | /* we pass a pointer to this as the argument sent to |
118 | cypress_set_termios old_termios */ | 117 | cypress_set_termios old_termios */ |
119 | struct ktermios tmp_termios; /* stores the old termios settings */ | 118 | struct ktermios tmp_termios; /* stores the old termios settings */ |
@@ -136,7 +135,6 @@ static void cypress_set_termios(struct tty_struct *tty, | |||
136 | static int cypress_tiocmget(struct tty_struct *tty); | 135 | static int cypress_tiocmget(struct tty_struct *tty); |
137 | static int cypress_tiocmset(struct tty_struct *tty, | 136 | static int cypress_tiocmset(struct tty_struct *tty, |
138 | unsigned int set, unsigned int clear); | 137 | unsigned int set, unsigned int clear); |
139 | static int cypress_tiocmiwait(struct tty_struct *tty, unsigned long arg); | ||
140 | static int cypress_chars_in_buffer(struct tty_struct *tty); | 138 | static int cypress_chars_in_buffer(struct tty_struct *tty); |
141 | static void cypress_throttle(struct tty_struct *tty); | 139 | static void cypress_throttle(struct tty_struct *tty); |
142 | static void cypress_unthrottle(struct tty_struct *tty); | 140 | static void cypress_unthrottle(struct tty_struct *tty); |
@@ -162,7 +160,7 @@ static struct usb_serial_driver cypress_earthmate_device = { | |||
162 | .set_termios = cypress_set_termios, | 160 | .set_termios = cypress_set_termios, |
163 | .tiocmget = cypress_tiocmget, | 161 | .tiocmget = cypress_tiocmget, |
164 | .tiocmset = cypress_tiocmset, | 162 | .tiocmset = cypress_tiocmset, |
165 | .tiocmiwait = cypress_tiocmiwait, | 163 | .tiocmiwait = usb_serial_generic_tiocmiwait, |
166 | .chars_in_buffer = cypress_chars_in_buffer, | 164 | .chars_in_buffer = cypress_chars_in_buffer, |
167 | .throttle = cypress_throttle, | 165 | .throttle = cypress_throttle, |
168 | .unthrottle = cypress_unthrottle, | 166 | .unthrottle = cypress_unthrottle, |
@@ -188,7 +186,7 @@ static struct usb_serial_driver cypress_hidcom_device = { | |||
188 | .set_termios = cypress_set_termios, | 186 | .set_termios = cypress_set_termios, |
189 | .tiocmget = cypress_tiocmget, | 187 | .tiocmget = cypress_tiocmget, |
190 | .tiocmset = cypress_tiocmset, | 188 | .tiocmset = cypress_tiocmset, |
191 | .tiocmiwait = cypress_tiocmiwait, | 189 | .tiocmiwait = usb_serial_generic_tiocmiwait, |
192 | .chars_in_buffer = cypress_chars_in_buffer, | 190 | .chars_in_buffer = cypress_chars_in_buffer, |
193 | .throttle = cypress_throttle, | 191 | .throttle = cypress_throttle, |
194 | .unthrottle = cypress_unthrottle, | 192 | .unthrottle = cypress_unthrottle, |
@@ -214,7 +212,7 @@ static struct usb_serial_driver cypress_ca42v2_device = { | |||
214 | .set_termios = cypress_set_termios, | 212 | .set_termios = cypress_set_termios, |
215 | .tiocmget = cypress_tiocmget, | 213 | .tiocmget = cypress_tiocmget, |
216 | .tiocmset = cypress_tiocmset, | 214 | .tiocmset = cypress_tiocmset, |
217 | .tiocmiwait = cypress_tiocmiwait, | 215 | .tiocmiwait = usb_serial_generic_tiocmiwait, |
218 | .chars_in_buffer = cypress_chars_in_buffer, | 216 | .chars_in_buffer = cypress_chars_in_buffer, |
219 | .throttle = cypress_throttle, | 217 | .throttle = cypress_throttle, |
220 | .unthrottle = cypress_unthrottle, | 218 | .unthrottle = cypress_unthrottle, |
@@ -864,45 +862,6 @@ static int cypress_tiocmset(struct tty_struct *tty, | |||
864 | return cypress_write(tty, port, NULL, 0); | 862 | return cypress_write(tty, port, NULL, 0); |
865 | } | 863 | } |
866 | 864 | ||
867 | |||
868 | static int cypress_tiocmiwait(struct tty_struct *tty, unsigned long arg) | ||
869 | { | ||
870 | struct usb_serial_port *port = tty->driver_data; | ||
871 | struct cypress_private *priv = usb_get_serial_port_data(port); | ||
872 | char diff; | ||
873 | |||
874 | for (;;) { | ||
875 | interruptible_sleep_on(&port->port.delta_msr_wait); | ||
876 | /* see if a signal did it */ | ||
877 | if (signal_pending(current)) | ||
878 | return -ERESTARTSYS; | ||
879 | |||
880 | if (port->serial->disconnected) | ||
881 | return -EIO; | ||
882 | |||
883 | diff = priv->diff_status; | ||
884 | if (diff == 0) | ||
885 | return -EIO; /* no change => error */ | ||
886 | |||
887 | /* consume all events */ | ||
888 | priv->diff_status = 0; | ||
889 | |||
890 | /* return 0 if caller wanted to know about | ||
891 | these bits */ | ||
892 | if (((arg & TIOCM_RNG) && (diff & UART_RI)) || | ||
893 | ((arg & TIOCM_DSR) && (diff & UART_DSR)) || | ||
894 | ((arg & TIOCM_CD) && (diff & UART_CD)) || | ||
895 | ((arg & TIOCM_CTS) && (diff & UART_CTS))) | ||
896 | return 0; | ||
897 | /* otherwise caller can't care less about what | ||
898 | * happened, and so we continue to wait for | ||
899 | * more events. | ||
900 | */ | ||
901 | } | ||
902 | |||
903 | return 0; | ||
904 | } | ||
905 | |||
906 | static void cypress_set_termios(struct tty_struct *tty, | 865 | static void cypress_set_termios(struct tty_struct *tty, |
907 | struct usb_serial_port *port, struct ktermios *old_termios) | 866 | struct usb_serial_port *port, struct ktermios *old_termios) |
908 | { | 867 | { |
@@ -1185,9 +1144,21 @@ static void cypress_read_int_callback(struct urb *urb) | |||
1185 | spin_lock_irqsave(&priv->lock, flags); | 1144 | spin_lock_irqsave(&priv->lock, flags); |
1186 | /* check to see if status has changed */ | 1145 | /* check to see if status has changed */ |
1187 | if (priv->current_status != priv->prev_status) { | 1146 | if (priv->current_status != priv->prev_status) { |
1188 | priv->diff_status |= priv->current_status ^ | 1147 | u8 delta = priv->current_status ^ priv->prev_status; |
1189 | priv->prev_status; | 1148 | |
1190 | wake_up_interruptible(&port->port.delta_msr_wait); | 1149 | if (delta & UART_MSR_MASK) { |
1150 | if (delta & UART_CTS) | ||
1151 | port->icount.cts++; | ||
1152 | if (delta & UART_DSR) | ||
1153 | port->icount.dsr++; | ||
1154 | if (delta & UART_RI) | ||
1155 | port->icount.rng++; | ||
1156 | if (delta & UART_CD) | ||
1157 | port->icount.dcd++; | ||
1158 | |||
1159 | wake_up_interruptible(&port->port.delta_msr_wait); | ||
1160 | } | ||
1161 | |||
1191 | priv->prev_status = priv->current_status; | 1162 | priv->prev_status = priv->current_status; |
1192 | } | 1163 | } |
1193 | spin_unlock_irqrestore(&priv->lock, flags); | 1164 | spin_unlock_irqrestore(&priv->lock, flags); |
diff --git a/drivers/usb/serial/cypress_m8.h b/drivers/usb/serial/cypress_m8.h index b461311a2ae7..119d2e17077b 100644 --- a/drivers/usb/serial/cypress_m8.h +++ b/drivers/usb/serial/cypress_m8.h | |||
@@ -55,19 +55,23 @@ | |||
55 | #define CT_GENERIC 0x0F | 55 | #define CT_GENERIC 0x0F |
56 | /* End of chiptype definitions */ | 56 | /* End of chiptype definitions */ |
57 | 57 | ||
58 | /* RS-232 serial data communication protocol definitions */ | 58 | /* |
59 | /* these are sent / read at byte 0 of the input/output hid reports */ | 59 | * RS-232 serial data communication protocol definitions. |
60 | /* You can find these values defined in the CY4601 USB to Serial design notes */ | 60 | * |
61 | 61 | * These are sent / read at byte 0 of the input/output hid reports. | |
62 | #define CONTROL_DTR 0x20 /* data terminal ready - flow control - host to device */ | 62 | * You can find these values defined in the CY4601 USB to Serial design notes. |
63 | #define UART_DSR 0x20 /* data set ready - flow control - device to host */ | 63 | */ |
64 | #define CONTROL_RTS 0x10 /* request to send - flow control - host to device */ | 64 | |
65 | #define UART_CTS 0x10 /* clear to send - flow control - device to host */ | 65 | #define CONTROL_DTR 0x20 /* data terminal ready */ |
66 | #define UART_RI 0x10 /* ring indicator - modem - device to host */ | 66 | #define CONTROL_RTS 0x10 /* request to send */ |
67 | #define UART_CD 0x40 /* carrier detect - modem - device to host */ | 67 | #define CONTROL_RESET 0x08 /* sent with output report */ |
68 | #define CYP_ERROR 0x08 /* received from input report - device to host */ | 68 | |
69 | /* Note - the below has nothing to do with the "feature report" reset */ | 69 | #define UART_MSR_MASK 0xf0 |
70 | #define CONTROL_RESET 0x08 /* sent with output report - host to device */ | 70 | #define UART_RI 0x80 /* ring indicator */ |
71 | #define UART_CD 0x40 /* carrier detect */ | ||
72 | #define UART_DSR 0x20 /* data set ready */ | ||
73 | #define UART_CTS 0x10 /* clear to send */ | ||
74 | #define CYP_ERROR 0x08 /* received from input report */ | ||
71 | 75 | ||
72 | /* End of RS-232 protocol definitions */ | 76 | /* End of RS-232 protocol definitions */ |
73 | 77 | ||
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index 19b467fe0388..8a23c53b946e 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c | |||
@@ -17,7 +17,6 @@ | |||
17 | 17 | ||
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/init.h> | ||
21 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
22 | #include <linux/tty.h> | 21 | #include <linux/tty.h> |
23 | #include <linux/tty_driver.h> | 22 | #include <linux/tty_driver.h> |
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c index 0f658618db13..90e603d5f660 100644 --- a/drivers/usb/serial/empeg.c +++ b/drivers/usb/serial/empeg.c | |||
@@ -17,7 +17,6 @@ | |||
17 | 17 | ||
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/init.h> | ||
21 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
22 | #include <linux/tty.h> | 21 | #include <linux/tty.h> |
23 | #include <linux/tty_driver.h> | 22 | #include <linux/tty_driver.h> |
diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 639a18fb67e6..c5dc233db2d9 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c | |||
@@ -12,7 +12,6 @@ | |||
12 | 12 | ||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/errno.h> | 14 | #include <linux/errno.h> |
15 | #include <linux/init.h> | ||
16 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
17 | #include <linux/tty.h> | 16 | #include <linux/tty.h> |
18 | #include <linux/tty_driver.h> | 17 | #include <linux/tty_driver.h> |
@@ -55,6 +54,13 @@ static void f81232_update_line_status(struct usb_serial_port *port, | |||
55 | unsigned char *data, | 54 | unsigned char *data, |
56 | unsigned int actual_length) | 55 | unsigned int actual_length) |
57 | { | 56 | { |
57 | /* | ||
58 | * FIXME: Update port->icount, and call | ||
59 | * | ||
60 | * wake_up_interruptible(&port->port.delta_msr_wait); | ||
61 | * | ||
62 | * on MSR changes. | ||
63 | */ | ||
58 | } | 64 | } |
59 | 65 | ||
60 | static void f81232_read_int_callback(struct urb *urb) | 66 | static void f81232_read_int_callback(struct urb *urb) |
@@ -110,7 +116,6 @@ static void f81232_process_read_urb(struct urb *urb) | |||
110 | line_status = priv->line_status; | 116 | line_status = priv->line_status; |
111 | priv->line_status &= ~UART_STATE_TRANSIENT_MASK; | 117 | priv->line_status &= ~UART_STATE_TRANSIENT_MASK; |
112 | spin_unlock_irqrestore(&priv->lock, flags); | 118 | spin_unlock_irqrestore(&priv->lock, flags); |
113 | wake_up_interruptible(&port->port.delta_msr_wait); | ||
114 | 119 | ||
115 | if (!urb->actual_length) | 120 | if (!urb->actual_length) |
116 | return; | 121 | return; |
@@ -241,54 +246,12 @@ static int f81232_carrier_raised(struct usb_serial_port *port) | |||
241 | return 0; | 246 | return 0; |
242 | } | 247 | } |
243 | 248 | ||
244 | static int f81232_tiocmiwait(struct tty_struct *tty, unsigned long arg) | ||
245 | { | ||
246 | struct usb_serial_port *port = tty->driver_data; | ||
247 | struct f81232_private *priv = usb_get_serial_port_data(port); | ||
248 | unsigned long flags; | ||
249 | unsigned int prevstatus; | ||
250 | unsigned int status; | ||
251 | unsigned int changed; | ||
252 | |||
253 | spin_lock_irqsave(&priv->lock, flags); | ||
254 | prevstatus = priv->line_status; | ||
255 | spin_unlock_irqrestore(&priv->lock, flags); | ||
256 | |||
257 | while (1) { | ||
258 | interruptible_sleep_on(&port->port.delta_msr_wait); | ||
259 | /* see if a signal did it */ | ||
260 | if (signal_pending(current)) | ||
261 | return -ERESTARTSYS; | ||
262 | |||
263 | if (port->serial->disconnected) | ||
264 | return -EIO; | ||
265 | |||
266 | spin_lock_irqsave(&priv->lock, flags); | ||
267 | status = priv->line_status; | ||
268 | spin_unlock_irqrestore(&priv->lock, flags); | ||
269 | |||
270 | changed = prevstatus ^ status; | ||
271 | |||
272 | if (((arg & TIOCM_RNG) && (changed & UART_RING)) || | ||
273 | ((arg & TIOCM_DSR) && (changed & UART_DSR)) || | ||
274 | ((arg & TIOCM_CD) && (changed & UART_DCD)) || | ||
275 | ((arg & TIOCM_CTS) && (changed & UART_CTS))) { | ||
276 | return 0; | ||
277 | } | ||
278 | prevstatus = status; | ||
279 | } | ||
280 | /* NOTREACHED */ | ||
281 | return 0; | ||
282 | } | ||
283 | |||
284 | static int f81232_ioctl(struct tty_struct *tty, | 249 | static int f81232_ioctl(struct tty_struct *tty, |
285 | unsigned int cmd, unsigned long arg) | 250 | unsigned int cmd, unsigned long arg) |
286 | { | 251 | { |
287 | struct serial_struct ser; | 252 | struct serial_struct ser; |
288 | struct usb_serial_port *port = tty->driver_data; | 253 | struct usb_serial_port *port = tty->driver_data; |
289 | 254 | ||
290 | dev_dbg(&port->dev, "%s cmd = 0x%04x\n", __func__, cmd); | ||
291 | |||
292 | switch (cmd) { | 255 | switch (cmd) { |
293 | case TIOCGSERIAL: | 256 | case TIOCGSERIAL: |
294 | memset(&ser, 0, sizeof ser); | 257 | memset(&ser, 0, sizeof ser); |
@@ -302,8 +265,6 @@ static int f81232_ioctl(struct tty_struct *tty, | |||
302 | 265 | ||
303 | return 0; | 266 | return 0; |
304 | default: | 267 | default: |
305 | dev_dbg(&port->dev, "%s not supported = 0x%04x\n", | ||
306 | __func__, cmd); | ||
307 | break; | 268 | break; |
308 | } | 269 | } |
309 | return -ENOIOCTLCMD; | 270 | return -ENOIOCTLCMD; |
@@ -354,7 +315,7 @@ static struct usb_serial_driver f81232_device = { | |||
354 | .set_termios = f81232_set_termios, | 315 | .set_termios = f81232_set_termios, |
355 | .tiocmget = f81232_tiocmget, | 316 | .tiocmget = f81232_tiocmget, |
356 | .tiocmset = f81232_tiocmset, | 317 | .tiocmset = f81232_tiocmset, |
357 | .tiocmiwait = f81232_tiocmiwait, | 318 | .tiocmiwait = usb_serial_generic_tiocmiwait, |
358 | .process_read_urb = f81232_process_read_urb, | 319 | .process_read_urb = f81232_process_read_urb, |
359 | .read_int_callback = f81232_read_int_callback, | 320 | .read_int_callback = f81232_read_int_callback, |
360 | .port_probe = f81232_port_probe, | 321 | .port_probe = f81232_port_probe, |
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index fb0d537435eb..ce0d7b0db012 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c | |||
@@ -33,7 +33,6 @@ | |||
33 | 33 | ||
34 | #include <linux/kernel.h> | 34 | #include <linux/kernel.h> |
35 | #include <linux/errno.h> | 35 | #include <linux/errno.h> |
36 | #include <linux/init.h> | ||
37 | #include <linux/slab.h> | 36 | #include <linux/slab.h> |
38 | #include <linux/tty.h> | 37 | #include <linux/tty.h> |
39 | #include <linux/tty_driver.h> | 38 | #include <linux/tty_driver.h> |
@@ -145,7 +144,7 @@ static struct ftdi_sio_quirk ftdi_8u2232c_quirk = { | |||
145 | * Device ID not listed? Test it using | 144 | * Device ID not listed? Test it using |
146 | * /sys/bus/usb-serial/drivers/ftdi_sio/new_id and send a patch or report. | 145 | * /sys/bus/usb-serial/drivers/ftdi_sio/new_id and send a patch or report. |
147 | */ | 146 | */ |
148 | static struct usb_device_id id_table_combined [] = { | 147 | static const struct usb_device_id id_table_combined[] = { |
149 | { USB_DEVICE(FTDI_VID, FTDI_ZEITCONTROL_TAGTRACE_MIFARE_PID) }, | 148 | { USB_DEVICE(FTDI_VID, FTDI_ZEITCONTROL_TAGTRACE_MIFARE_PID) }, |
150 | { USB_DEVICE(FTDI_VID, FTDI_CTI_MINI_PID) }, | 149 | { USB_DEVICE(FTDI_VID, FTDI_CTI_MINI_PID) }, |
151 | { USB_DEVICE(FTDI_VID, FTDI_CTI_NANO_PID) }, | 150 | { USB_DEVICE(FTDI_VID, FTDI_CTI_NANO_PID) }, |
@@ -1695,11 +1694,8 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port) | |||
1695 | 1694 | ||
1696 | 1695 | ||
1697 | priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL); | 1696 | priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL); |
1698 | if (!priv) { | 1697 | if (!priv) |
1699 | dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n", __func__, | ||
1700 | sizeof(struct ftdi_private)); | ||
1701 | return -ENOMEM; | 1698 | return -ENOMEM; |
1702 | } | ||
1703 | 1699 | ||
1704 | mutex_init(&priv->cfg_lock); | 1700 | mutex_init(&priv->cfg_lock); |
1705 | 1701 | ||
@@ -2124,10 +2120,20 @@ static void ftdi_set_termios(struct tty_struct *tty, | |||
2124 | } | 2120 | } |
2125 | 2121 | ||
2126 | /* | 2122 | /* |
2127 | * All FTDI UART chips are limited to CS7/8. We won't pretend to | 2123 | * All FTDI UART chips are limited to CS7/8. We shouldn't pretend to |
2128 | * support CS5/6 and revert the CSIZE setting instead. | 2124 | * support CS5/6 and revert the CSIZE setting instead. |
2125 | * | ||
2126 | * CS5 however is used to control some smartcard readers which abuse | ||
2127 | * this limitation to switch modes. Original FTDI chips fall back to | ||
2128 | * eight data bits. | ||
2129 | * | ||
2130 | * TODO: Implement a quirk to only allow this with mentioned | ||
2131 | * readers. One I know of (Argolis Smartreader V1) | ||
2132 | * returns "USB smartcard server" as iInterface string. | ||
2133 | * The vendor didn't bother with a custom VID/PID of | ||
2134 | * course. | ||
2129 | */ | 2135 | */ |
2130 | if ((C_CSIZE(tty) != CS8) && (C_CSIZE(tty) != CS7)) { | 2136 | if (C_CSIZE(tty) == CS6) { |
2131 | dev_warn(ddev, "requested CSIZE setting not supported\n"); | 2137 | dev_warn(ddev, "requested CSIZE setting not supported\n"); |
2132 | 2138 | ||
2133 | termios->c_cflag &= ~CSIZE; | 2139 | termios->c_cflag &= ~CSIZE; |
@@ -2174,6 +2180,9 @@ no_skip: | |||
2174 | urb_value |= FTDI_SIO_SET_DATA_PARITY_NONE; | 2180 | urb_value |= FTDI_SIO_SET_DATA_PARITY_NONE; |
2175 | } | 2181 | } |
2176 | switch (cflag & CSIZE) { | 2182 | switch (cflag & CSIZE) { |
2183 | case CS5: | ||
2184 | dev_dbg(ddev, "Setting CS5 quirk\n"); | ||
2185 | break; | ||
2177 | case CS7: | 2186 | case CS7: |
2178 | urb_value |= 7; | 2187 | urb_value |= 7; |
2179 | dev_dbg(ddev, "Setting CS7\n"); | 2188 | dev_dbg(ddev, "Setting CS7\n"); |
@@ -2383,8 +2392,6 @@ static int ftdi_ioctl(struct tty_struct *tty, | |||
2383 | { | 2392 | { |
2384 | struct usb_serial_port *port = tty->driver_data; | 2393 | struct usb_serial_port *port = tty->driver_data; |
2385 | 2394 | ||
2386 | dev_dbg(&port->dev, "%s cmd 0x%04x\n", __func__, cmd); | ||
2387 | |||
2388 | /* Based on code from acm.c and others */ | 2395 | /* Based on code from acm.c and others */ |
2389 | switch (cmd) { | 2396 | switch (cmd) { |
2390 | 2397 | ||
@@ -2401,11 +2408,7 @@ static int ftdi_ioctl(struct tty_struct *tty, | |||
2401 | default: | 2408 | default: |
2402 | break; | 2409 | break; |
2403 | } | 2410 | } |
2404 | /* This is not necessarily an error - turns out the higher layers | 2411 | |
2405 | * will do some ioctls themselves (see comment above) | ||
2406 | */ | ||
2407 | dev_dbg(&port->dev, "%s arg not supported - it was 0x%04x - check /usr/include/asm/ioctls.h\n", | ||
2408 | __func__, cmd); | ||
2409 | return -ENOIOCTLCMD; | 2412 | return -ENOIOCTLCMD; |
2410 | } | 2413 | } |
2411 | 2414 | ||
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 04b5ed90ffb2..db591d19d416 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c | |||
@@ -25,7 +25,6 @@ | |||
25 | 25 | ||
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
28 | #include <linux/init.h> | ||
29 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
30 | #include <linux/timer.h> | 29 | #include <linux/timer.h> |
31 | #include <linux/tty.h> | 30 | #include <linux/tty.h> |
@@ -275,14 +274,13 @@ static int pkt_add(struct garmin_data *garmin_data_p, | |||
275 | unsigned long flags; | 274 | unsigned long flags; |
276 | struct garmin_packet *pkt; | 275 | struct garmin_packet *pkt; |
277 | 276 | ||
278 | /* process only packets containg data ... */ | 277 | /* process only packets containing data ... */ |
279 | if (data_length) { | 278 | if (data_length) { |
280 | pkt = kmalloc(sizeof(struct garmin_packet)+data_length, | 279 | pkt = kmalloc(sizeof(struct garmin_packet)+data_length, |
281 | GFP_ATOMIC); | 280 | GFP_ATOMIC); |
282 | if (pkt == NULL) { | 281 | if (!pkt) |
283 | dev_err(&garmin_data_p->port->dev, "out of memory\n"); | ||
284 | return 0; | 282 | return 0; |
285 | } | 283 | |
286 | pkt->size = data_length; | 284 | pkt->size = data_length; |
287 | memcpy(pkt->data, data, data_length); | 285 | memcpy(pkt->data, data, data_length); |
288 | 286 | ||
@@ -1006,14 +1004,11 @@ static int garmin_write_bulk(struct usb_serial_port *port, | |||
1006 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | 1004 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
1007 | 1005 | ||
1008 | buffer = kmalloc(count, GFP_ATOMIC); | 1006 | buffer = kmalloc(count, GFP_ATOMIC); |
1009 | if (!buffer) { | 1007 | if (!buffer) |
1010 | dev_err(&port->dev, "out of memory\n"); | ||
1011 | return -ENOMEM; | 1008 | return -ENOMEM; |
1012 | } | ||
1013 | 1009 | ||
1014 | urb = usb_alloc_urb(0, GFP_ATOMIC); | 1010 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
1015 | if (!urb) { | 1011 | if (!urb) { |
1016 | dev_err(&port->dev, "no more free urbs\n"); | ||
1017 | kfree(buffer); | 1012 | kfree(buffer); |
1018 | return -ENOMEM; | 1013 | return -ENOMEM; |
1019 | } | 1014 | } |
@@ -1148,7 +1143,7 @@ static void garmin_read_process(struct garmin_data *garmin_data_p, | |||
1148 | unsigned long flags; | 1143 | unsigned long flags; |
1149 | 1144 | ||
1150 | if (garmin_data_p->flags & FLAGS_DROP_DATA) { | 1145 | if (garmin_data_p->flags & FLAGS_DROP_DATA) { |
1151 | /* abort-transfer cmd is actice */ | 1146 | /* abort-transfer cmd is active */ |
1152 | dev_dbg(&garmin_data_p->port->dev, "%s - pkt dropped\n", __func__); | 1147 | dev_dbg(&garmin_data_p->port->dev, "%s - pkt dropped\n", __func__); |
1153 | } else if (garmin_data_p->state != STATE_DISCONNECTED && | 1148 | } else if (garmin_data_p->state != STATE_DISCONNECTED && |
1154 | garmin_data_p->state != STATE_RESET) { | 1149 | garmin_data_p->state != STATE_RESET) { |
@@ -1393,10 +1388,9 @@ static int garmin_port_probe(struct usb_serial_port *port) | |||
1393 | struct garmin_data *garmin_data_p; | 1388 | struct garmin_data *garmin_data_p; |
1394 | 1389 | ||
1395 | garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL); | 1390 | garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL); |
1396 | if (garmin_data_p == NULL) { | 1391 | if (!garmin_data_p) |
1397 | dev_err(&port->dev, "%s - Out of memory\n", __func__); | ||
1398 | return -ENOMEM; | 1392 | return -ENOMEM; |
1399 | } | 1393 | |
1400 | init_timer(&garmin_data_p->timer); | 1394 | init_timer(&garmin_data_p->timer); |
1401 | spin_lock_init(&garmin_data_p->lock); | 1395 | spin_lock_init(&garmin_data_p->lock); |
1402 | INIT_LIST_HEAD(&garmin_data_p->pktlist); | 1396 | INIT_LIST_HEAD(&garmin_data_p->pktlist); |
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index c91481d74a14..c0866971db2b 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c | |||
@@ -32,7 +32,6 @@ | |||
32 | #include <linux/kernel.h> | 32 | #include <linux/kernel.h> |
33 | #include <linux/jiffies.h> | 33 | #include <linux/jiffies.h> |
34 | #include <linux/errno.h> | 34 | #include <linux/errno.h> |
35 | #include <linux/init.h> | ||
36 | #include <linux/slab.h> | 35 | #include <linux/slab.h> |
37 | #include <linux/tty.h> | 36 | #include <linux/tty.h> |
38 | #include <linux/tty_driver.h> | 37 | #include <linux/tty_driver.h> |
@@ -898,7 +897,6 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
898 | edge_port->txfifo.fifo = kmalloc(edge_port->maxTxCredits, GFP_KERNEL); | 897 | edge_port->txfifo.fifo = kmalloc(edge_port->maxTxCredits, GFP_KERNEL); |
899 | 898 | ||
900 | if (!edge_port->txfifo.fifo) { | 899 | if (!edge_port->txfifo.fifo) { |
901 | dev_dbg(dev, "%s - no memory\n", __func__); | ||
902 | edge_close(port); | 900 | edge_close(port); |
903 | return -ENOMEM; | 901 | return -ENOMEM; |
904 | } | 902 | } |
@@ -908,7 +906,6 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
908 | edge_port->write_in_progress = false; | 906 | edge_port->write_in_progress = false; |
909 | 907 | ||
910 | if (!edge_port->write_urb) { | 908 | if (!edge_port->write_urb) { |
911 | dev_dbg(dev, "%s - no memory\n", __func__); | ||
912 | edge_close(port); | 909 | edge_close(port); |
913 | return -ENOMEM; | 910 | return -ENOMEM; |
914 | } | 911 | } |
@@ -1245,9 +1242,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, | |||
1245 | to send out */ | 1242 | to send out */ |
1246 | count = fifo->count; | 1243 | count = fifo->count; |
1247 | buffer = kmalloc(count+2, GFP_ATOMIC); | 1244 | buffer = kmalloc(count+2, GFP_ATOMIC); |
1248 | if (buffer == NULL) { | 1245 | if (!buffer) { |
1249 | dev_err_console(edge_port->port, | ||
1250 | "%s - no more kernel memory...\n", __func__); | ||
1251 | edge_port->write_in_progress = false; | 1246 | edge_port->write_in_progress = false; |
1252 | goto exit_send; | 1247 | goto exit_send; |
1253 | } | 1248 | } |
@@ -1593,8 +1588,6 @@ static int edge_ioctl(struct tty_struct *tty, | |||
1593 | DEFINE_WAIT(wait); | 1588 | DEFINE_WAIT(wait); |
1594 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 1589 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
1595 | 1590 | ||
1596 | dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd); | ||
1597 | |||
1598 | switch (cmd) { | 1591 | switch (cmd) { |
1599 | case TIOCSERGETLSR: | 1592 | case TIOCSERGETLSR: |
1600 | dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__); | 1593 | dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__); |
@@ -2027,11 +2020,8 @@ static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, | |||
2027 | dev_dbg(&serial->dev->dev, "%s - %x, %x, %d\n", __func__, extAddr, addr, length); | 2020 | dev_dbg(&serial->dev->dev, "%s - %x, %x, %d\n", __func__, extAddr, addr, length); |
2028 | 2021 | ||
2029 | transfer_buffer = kmalloc(64, GFP_KERNEL); | 2022 | transfer_buffer = kmalloc(64, GFP_KERNEL); |
2030 | if (!transfer_buffer) { | 2023 | if (!transfer_buffer) |
2031 | dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", | ||
2032 | __func__, 64); | ||
2033 | return -ENOMEM; | 2024 | return -ENOMEM; |
2034 | } | ||
2035 | 2025 | ||
2036 | /* need to split these writes up into 64 byte chunks */ | 2026 | /* need to split these writes up into 64 byte chunks */ |
2037 | result = 0; | 2027 | result = 0; |
@@ -2075,11 +2065,8 @@ static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, | |||
2075 | unsigned char *transfer_buffer; | 2065 | unsigned char *transfer_buffer; |
2076 | 2066 | ||
2077 | transfer_buffer = kmalloc(64, GFP_KERNEL); | 2067 | transfer_buffer = kmalloc(64, GFP_KERNEL); |
2078 | if (!transfer_buffer) { | 2068 | if (!transfer_buffer) |
2079 | dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", | ||
2080 | __func__, 64); | ||
2081 | return -ENOMEM; | 2069 | return -ENOMEM; |
2082 | } | ||
2083 | 2070 | ||
2084 | /* need to split these writes up into 64 byte chunks */ | 2071 | /* need to split these writes up into 64 byte chunks */ |
2085 | result = 0; | 2072 | result = 0; |
@@ -2121,11 +2108,8 @@ static int rom_read(struct usb_serial *serial, __u16 extAddr, | |||
2121 | unsigned char *transfer_buffer; | 2108 | unsigned char *transfer_buffer; |
2122 | 2109 | ||
2123 | transfer_buffer = kmalloc(64, GFP_KERNEL); | 2110 | transfer_buffer = kmalloc(64, GFP_KERNEL); |
2124 | if (!transfer_buffer) { | 2111 | if (!transfer_buffer) |
2125 | dev_err(&serial->dev->dev, | ||
2126 | "%s - kmalloc(%d) failed.\n", __func__, 64); | ||
2127 | return -ENOMEM; | 2112 | return -ENOMEM; |
2128 | } | ||
2129 | 2113 | ||
2130 | /* need to split these reads up into 64 byte chunks */ | 2114 | /* need to split these reads up into 64 byte chunks */ |
2131 | result = 0; | 2115 | result = 0; |
@@ -2165,11 +2149,8 @@ static int send_iosp_ext_cmd(struct edgeport_port *edge_port, | |||
2165 | int status = 0; | 2149 | int status = 0; |
2166 | 2150 | ||
2167 | buffer = kmalloc(10, GFP_ATOMIC); | 2151 | buffer = kmalloc(10, GFP_ATOMIC); |
2168 | if (!buffer) { | 2152 | if (!buffer) |
2169 | dev_err(&edge_port->port->dev, | ||
2170 | "%s - kmalloc(%d) failed.\n", __func__, 10); | ||
2171 | return -ENOMEM; | 2153 | return -ENOMEM; |
2172 | } | ||
2173 | 2154 | ||
2174 | currentCommand = buffer; | 2155 | currentCommand = buffer; |
2175 | 2156 | ||
@@ -2276,10 +2257,9 @@ static int send_cmd_write_baud_rate(struct edgeport_port *edge_port, | |||
2276 | 2257 | ||
2277 | /* Alloc memory for the string of commands. */ | 2258 | /* Alloc memory for the string of commands. */ |
2278 | cmdBuffer = kmalloc(0x100, GFP_ATOMIC); | 2259 | cmdBuffer = kmalloc(0x100, GFP_ATOMIC); |
2279 | if (!cmdBuffer) { | 2260 | if (!cmdBuffer) |
2280 | dev_err(dev, "%s - kmalloc(%d) failed.\n", __func__, 0x100); | ||
2281 | return -ENOMEM; | 2261 | return -ENOMEM; |
2282 | } | 2262 | |
2283 | currCmd = cmdBuffer; | 2263 | currCmd = cmdBuffer; |
2284 | 2264 | ||
2285 | /* Enable access to divisor latch */ | 2265 | /* Enable access to divisor latch */ |
@@ -2785,10 +2765,9 @@ static int edge_startup(struct usb_serial *serial) | |||
2785 | 2765 | ||
2786 | /* create our private serial structure */ | 2766 | /* create our private serial structure */ |
2787 | edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); | 2767 | edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); |
2788 | if (edge_serial == NULL) { | 2768 | if (!edge_serial) |
2789 | dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); | ||
2790 | return -ENOMEM; | 2769 | return -ENOMEM; |
2791 | } | 2770 | |
2792 | spin_lock_init(&edge_serial->es_lock); | 2771 | spin_lock_init(&edge_serial->es_lock); |
2793 | edge_serial->serial = serial; | 2772 | edge_serial->serial = serial; |
2794 | usb_set_serial_data(serial, edge_serial); | 2773 | usb_set_serial_data(serial, edge_serial); |
@@ -2877,14 +2856,12 @@ static int edge_startup(struct usb_serial *serial) | |||
2877 | /* not set up yet, so do it now */ | 2856 | /* not set up yet, so do it now */ |
2878 | edge_serial->interrupt_read_urb = | 2857 | edge_serial->interrupt_read_urb = |
2879 | usb_alloc_urb(0, GFP_KERNEL); | 2858 | usb_alloc_urb(0, GFP_KERNEL); |
2880 | if (!edge_serial->interrupt_read_urb) { | 2859 | if (!edge_serial->interrupt_read_urb) |
2881 | dev_err(ddev, "out of memory\n"); | ||
2882 | return -ENOMEM; | 2860 | return -ENOMEM; |
2883 | } | 2861 | |
2884 | edge_serial->interrupt_in_buffer = | 2862 | edge_serial->interrupt_in_buffer = |
2885 | kmalloc(buffer_size, GFP_KERNEL); | 2863 | kmalloc(buffer_size, GFP_KERNEL); |
2886 | if (!edge_serial->interrupt_in_buffer) { | 2864 | if (!edge_serial->interrupt_in_buffer) { |
2887 | dev_err(ddev, "out of memory\n"); | ||
2888 | usb_free_urb(edge_serial->interrupt_read_urb); | 2865 | usb_free_urb(edge_serial->interrupt_read_urb); |
2889 | return -ENOMEM; | 2866 | return -ENOMEM; |
2890 | } | 2867 | } |
@@ -2914,14 +2891,12 @@ static int edge_startup(struct usb_serial *serial) | |||
2914 | /* not set up yet, so do it now */ | 2891 | /* not set up yet, so do it now */ |
2915 | edge_serial->read_urb = | 2892 | edge_serial->read_urb = |
2916 | usb_alloc_urb(0, GFP_KERNEL); | 2893 | usb_alloc_urb(0, GFP_KERNEL); |
2917 | if (!edge_serial->read_urb) { | 2894 | if (!edge_serial->read_urb) |
2918 | dev_err(ddev, "out of memory\n"); | ||
2919 | return -ENOMEM; | 2895 | return -ENOMEM; |
2920 | } | 2896 | |
2921 | edge_serial->bulk_in_buffer = | 2897 | edge_serial->bulk_in_buffer = |
2922 | kmalloc(buffer_size, GFP_KERNEL); | 2898 | kmalloc(buffer_size, GFP_KERNEL); |
2923 | if (!edge_serial->bulk_in_buffer) { | 2899 | if (!edge_serial->bulk_in_buffer) { |
2924 | dev_err(&dev->dev, "out of memory\n"); | ||
2925 | usb_free_urb(edge_serial->read_urb); | 2900 | usb_free_urb(edge_serial->read_urb); |
2926 | return -ENOMEM; | 2901 | return -ENOMEM; |
2927 | } | 2902 | } |
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index b7187bf32469..a2db5be9c305 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
21 | #include <linux/jiffies.h> | 21 | #include <linux/jiffies.h> |
22 | #include <linux/errno.h> | 22 | #include <linux/errno.h> |
23 | #include <linux/init.h> | ||
24 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
25 | #include <linux/tty.h> | 24 | #include <linux/tty.h> |
26 | #include <linux/tty_driver.h> | 25 | #include <linux/tty_driver.h> |
@@ -364,11 +363,9 @@ static int write_boot_mem(struct edgeport_serial *serial, | |||
364 | /* Must do a read before write */ | 363 | /* Must do a read before write */ |
365 | if (!serial->TiReadI2C) { | 364 | if (!serial->TiReadI2C) { |
366 | temp = kmalloc(1, GFP_KERNEL); | 365 | temp = kmalloc(1, GFP_KERNEL); |
367 | if (!temp) { | 366 | if (!temp) |
368 | dev_err(&serial->serial->dev->dev, | ||
369 | "%s - out of memory\n", __func__); | ||
370 | return -ENOMEM; | 367 | return -ENOMEM; |
371 | } | 368 | |
372 | status = read_boot_mem(serial, 0, 1, temp); | 369 | status = read_boot_mem(serial, 0, 1, temp); |
373 | kfree(temp); | 370 | kfree(temp); |
374 | if (status) | 371 | if (status) |
@@ -471,10 +468,8 @@ static int tx_active(struct edgeport_port *port) | |||
471 | int bytes_left = 0; | 468 | int bytes_left = 0; |
472 | 469 | ||
473 | oedb = kmalloc(sizeof(*oedb), GFP_KERNEL); | 470 | oedb = kmalloc(sizeof(*oedb), GFP_KERNEL); |
474 | if (!oedb) { | 471 | if (!oedb) |
475 | dev_err(&port->port->dev, "%s - out of memory\n", __func__); | ||
476 | return -ENOMEM; | 472 | return -ENOMEM; |
477 | } | ||
478 | 473 | ||
479 | lsr = kmalloc(1, GFP_KERNEL); /* Sigh, that's right, just one byte, | 474 | lsr = kmalloc(1, GFP_KERNEL); /* Sigh, that's right, just one byte, |
480 | as not all platforms can do DMA | 475 | as not all platforms can do DMA |
@@ -625,14 +620,11 @@ static int check_i2c_image(struct edgeport_serial *serial) | |||
625 | __u16 ttype; | 620 | __u16 ttype; |
626 | 621 | ||
627 | rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL); | 622 | rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL); |
628 | if (!rom_desc) { | 623 | if (!rom_desc) |
629 | dev_err(dev, "%s - out of memory\n", __func__); | ||
630 | return -ENOMEM; | 624 | return -ENOMEM; |
631 | } | 625 | |
632 | buffer = kmalloc(TI_MAX_I2C_SIZE, GFP_KERNEL); | 626 | buffer = kmalloc(TI_MAX_I2C_SIZE, GFP_KERNEL); |
633 | if (!buffer) { | 627 | if (!buffer) { |
634 | dev_err(dev, "%s - out of memory when allocating buffer\n", | ||
635 | __func__); | ||
636 | kfree(rom_desc); | 628 | kfree(rom_desc); |
637 | return -ENOMEM; | 629 | return -ENOMEM; |
638 | } | 630 | } |
@@ -706,10 +698,9 @@ static int get_manuf_info(struct edgeport_serial *serial, __u8 *buffer) | |||
706 | struct device *dev = &serial->serial->dev->dev; | 698 | struct device *dev = &serial->serial->dev->dev; |
707 | 699 | ||
708 | rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL); | 700 | rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL); |
709 | if (!rom_desc) { | 701 | if (!rom_desc) |
710 | dev_err(dev, "%s - out of memory\n", __func__); | ||
711 | return -ENOMEM; | 702 | return -ENOMEM; |
712 | } | 703 | |
713 | start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_ION, | 704 | start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_ION, |
714 | rom_desc); | 705 | rom_desc); |
715 | 706 | ||
@@ -769,10 +760,8 @@ static int build_i2c_fw_hdr(__u8 *header, struct device *dev) | |||
769 | sizeof(struct ti_i2c_firmware_rec)); | 760 | sizeof(struct ti_i2c_firmware_rec)); |
770 | 761 | ||
771 | buffer = kmalloc(buffer_size, GFP_KERNEL); | 762 | buffer = kmalloc(buffer_size, GFP_KERNEL); |
772 | if (!buffer) { | 763 | if (!buffer) |
773 | dev_err(dev, "%s - out of memory\n", __func__); | ||
774 | return -ENOMEM; | 764 | return -ENOMEM; |
775 | } | ||
776 | 765 | ||
777 | // Set entire image of 0xffs | 766 | // Set entire image of 0xffs |
778 | memset(buffer, 0xff, buffer_size); | 767 | memset(buffer, 0xff, buffer_size); |
@@ -832,10 +821,8 @@ static int i2c_type_bootmode(struct edgeport_serial *serial) | |||
832 | u8 *data; | 821 | u8 *data; |
833 | 822 | ||
834 | data = kmalloc(1, GFP_KERNEL); | 823 | data = kmalloc(1, GFP_KERNEL); |
835 | if (!data) { | 824 | if (!data) |
836 | dev_err(dev, "%s - out of memory\n", __func__); | ||
837 | return -ENOMEM; | 825 | return -ENOMEM; |
838 | } | ||
839 | 826 | ||
840 | /* Try to read type 2 */ | 827 | /* Try to read type 2 */ |
841 | status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ, | 828 | status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ, |
@@ -986,10 +973,9 @@ static int download_fw(struct edgeport_serial *serial) | |||
986 | * Read Manufacturing Descriptor from TI Based Edgeport | 973 | * Read Manufacturing Descriptor from TI Based Edgeport |
987 | */ | 974 | */ |
988 | ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL); | 975 | ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL); |
989 | if (!ti_manuf_desc) { | 976 | if (!ti_manuf_desc) |
990 | dev_err(dev, "%s - out of memory.\n", __func__); | ||
991 | return -ENOMEM; | 977 | return -ENOMEM; |
992 | } | 978 | |
993 | status = get_manuf_info(serial, (__u8 *)ti_manuf_desc); | 979 | status = get_manuf_info(serial, (__u8 *)ti_manuf_desc); |
994 | if (status) { | 980 | if (status) { |
995 | kfree(ti_manuf_desc); | 981 | kfree(ti_manuf_desc); |
@@ -1006,7 +992,6 @@ static int download_fw(struct edgeport_serial *serial) | |||
1006 | 992 | ||
1007 | rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL); | 993 | rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL); |
1008 | if (!rom_desc) { | 994 | if (!rom_desc) { |
1009 | dev_err(dev, "%s - out of memory.\n", __func__); | ||
1010 | kfree(ti_manuf_desc); | 995 | kfree(ti_manuf_desc); |
1011 | return -ENOMEM; | 996 | return -ENOMEM; |
1012 | } | 997 | } |
@@ -1023,7 +1008,6 @@ static int download_fw(struct edgeport_serial *serial) | |||
1023 | firmware_version = kmalloc(sizeof(*firmware_version), | 1008 | firmware_version = kmalloc(sizeof(*firmware_version), |
1024 | GFP_KERNEL); | 1009 | GFP_KERNEL); |
1025 | if (!firmware_version) { | 1010 | if (!firmware_version) { |
1026 | dev_err(dev, "%s - out of memory.\n", __func__); | ||
1027 | kfree(rom_desc); | 1011 | kfree(rom_desc); |
1028 | kfree(ti_manuf_desc); | 1012 | kfree(ti_manuf_desc); |
1029 | return -ENOMEM; | 1013 | return -ENOMEM; |
@@ -1068,8 +1052,6 @@ static int download_fw(struct edgeport_serial *serial) | |||
1068 | 1052 | ||
1069 | record = kmalloc(1, GFP_KERNEL); | 1053 | record = kmalloc(1, GFP_KERNEL); |
1070 | if (!record) { | 1054 | if (!record) { |
1071 | dev_err(dev, "%s - out of memory.\n", | ||
1072 | __func__); | ||
1073 | kfree(firmware_version); | 1055 | kfree(firmware_version); |
1074 | kfree(rom_desc); | 1056 | kfree(rom_desc); |
1075 | kfree(ti_manuf_desc); | 1057 | kfree(ti_manuf_desc); |
@@ -1153,7 +1135,6 @@ static int download_fw(struct edgeport_serial *serial) | |||
1153 | 1135 | ||
1154 | header = kmalloc(HEADER_SIZE, GFP_KERNEL); | 1136 | header = kmalloc(HEADER_SIZE, GFP_KERNEL); |
1155 | if (!header) { | 1137 | if (!header) { |
1156 | dev_err(dev, "%s - out of memory.\n", __func__); | ||
1157 | kfree(rom_desc); | 1138 | kfree(rom_desc); |
1158 | kfree(ti_manuf_desc); | 1139 | kfree(ti_manuf_desc); |
1159 | return -ENOMEM; | 1140 | return -ENOMEM; |
@@ -1161,7 +1142,6 @@ static int download_fw(struct edgeport_serial *serial) | |||
1161 | 1142 | ||
1162 | vheader = kmalloc(HEADER_SIZE, GFP_KERNEL); | 1143 | vheader = kmalloc(HEADER_SIZE, GFP_KERNEL); |
1163 | if (!vheader) { | 1144 | if (!vheader) { |
1164 | dev_err(dev, "%s - out of memory.\n", __func__); | ||
1165 | kfree(header); | 1145 | kfree(header); |
1166 | kfree(rom_desc); | 1146 | kfree(rom_desc); |
1167 | kfree(ti_manuf_desc); | 1147 | kfree(ti_manuf_desc); |
@@ -1290,10 +1270,9 @@ static int download_fw(struct edgeport_serial *serial) | |||
1290 | * Read Manufacturing Descriptor from TI Based Edgeport | 1270 | * Read Manufacturing Descriptor from TI Based Edgeport |
1291 | */ | 1271 | */ |
1292 | ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL); | 1272 | ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL); |
1293 | if (!ti_manuf_desc) { | 1273 | if (!ti_manuf_desc) |
1294 | dev_err(dev, "%s - out of memory.\n", __func__); | ||
1295 | return -ENOMEM; | 1274 | return -ENOMEM; |
1296 | } | 1275 | |
1297 | status = get_manuf_info(serial, (__u8 *)ti_manuf_desc); | 1276 | status = get_manuf_info(serial, (__u8 *)ti_manuf_desc); |
1298 | if (status) { | 1277 | if (status) { |
1299 | kfree(ti_manuf_desc); | 1278 | kfree(ti_manuf_desc); |
@@ -1328,10 +1307,8 @@ static int download_fw(struct edgeport_serial *serial) | |||
1328 | buffer_size = (((1024 * 16) - 512) + | 1307 | buffer_size = (((1024 * 16) - 512) + |
1329 | sizeof(struct ti_i2c_image_header)); | 1308 | sizeof(struct ti_i2c_image_header)); |
1330 | buffer = kmalloc(buffer_size, GFP_KERNEL); | 1309 | buffer = kmalloc(buffer_size, GFP_KERNEL); |
1331 | if (!buffer) { | 1310 | if (!buffer) |
1332 | dev_err(dev, "%s - out of memory\n", __func__); | ||
1333 | return -ENOMEM; | 1311 | return -ENOMEM; |
1334 | } | ||
1335 | 1312 | ||
1336 | /* Initialize the buffer to 0xff (pad the buffer) */ | 1313 | /* Initialize the buffer to 0xff (pad the buffer) */ |
1337 | memset(buffer, 0xff, buffer_size); | 1314 | memset(buffer, 0xff, buffer_size); |
@@ -2122,7 +2099,6 @@ static void change_port_settings(struct tty_struct *tty, | |||
2122 | config = kmalloc (sizeof (*config), GFP_KERNEL); | 2099 | config = kmalloc (sizeof (*config), GFP_KERNEL); |
2123 | if (!config) { | 2100 | if (!config) { |
2124 | tty->termios = *old_termios; | 2101 | tty->termios = *old_termios; |
2125 | dev_err(dev, "%s - out of memory\n", __func__); | ||
2126 | return; | 2102 | return; |
2127 | } | 2103 | } |
2128 | 2104 | ||
@@ -2362,8 +2338,6 @@ static int edge_ioctl(struct tty_struct *tty, | |||
2362 | struct usb_serial_port *port = tty->driver_data; | 2338 | struct usb_serial_port *port = tty->driver_data; |
2363 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 2339 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
2364 | 2340 | ||
2365 | dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd); | ||
2366 | |||
2367 | switch (cmd) { | 2341 | switch (cmd) { |
2368 | case TIOCGSERIAL: | 2342 | case TIOCGSERIAL: |
2369 | dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__); | 2343 | dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__); |
@@ -2395,10 +2369,9 @@ static int edge_startup(struct usb_serial *serial) | |||
2395 | 2369 | ||
2396 | /* create our private serial structure */ | 2370 | /* create our private serial structure */ |
2397 | edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); | 2371 | edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); |
2398 | if (edge_serial == NULL) { | 2372 | if (!edge_serial) |
2399 | dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); | ||
2400 | return -ENOMEM; | 2373 | return -ENOMEM; |
2401 | } | 2374 | |
2402 | mutex_init(&edge_serial->es_lock); | 2375 | mutex_init(&edge_serial->es_lock); |
2403 | edge_serial->serial = serial; | 2376 | edge_serial->serial = serial; |
2404 | usb_set_serial_data(serial, edge_serial); | 2377 | usb_set_serial_data(serial, edge_serial); |
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c index 76c9a847da5d..f51a5d52c0ed 100644 --- a/drivers/usb/serial/ipaq.c +++ b/drivers/usb/serial/ipaq.c | |||
@@ -12,7 +12,6 @@ | |||
12 | 12 | ||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/errno.h> | 14 | #include <linux/errno.h> |
15 | #include <linux/init.h> | ||
16 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
17 | #include <linux/tty.h> | 16 | #include <linux/tty.h> |
18 | #include <linux/tty_driver.h> | 17 | #include <linux/tty_driver.h> |
@@ -37,7 +36,7 @@ static int ipaq_open(struct tty_struct *tty, | |||
37 | static int ipaq_calc_num_ports(struct usb_serial *serial); | 36 | static int ipaq_calc_num_ports(struct usb_serial *serial); |
38 | static int ipaq_startup(struct usb_serial *serial); | 37 | static int ipaq_startup(struct usb_serial *serial); |
39 | 38 | ||
40 | static struct usb_device_id ipaq_id_table [] = { | 39 | static const struct usb_device_id ipaq_id_table[] = { |
41 | { USB_DEVICE(0x0104, 0x00BE) }, /* Socket USB Sync */ | 40 | { USB_DEVICE(0x0104, 0x00BE) }, /* Socket USB Sync */ |
42 | { USB_DEVICE(0x03F0, 0x1016) }, /* HP USB Sync */ | 41 | { USB_DEVICE(0x03F0, 0x1016) }, /* HP USB Sync */ |
43 | { USB_DEVICE(0x03F0, 0x1116) }, /* HP USB Sync 1611 */ | 42 | { USB_DEVICE(0x03F0, 0x1116) }, /* HP USB Sync 1611 */ |
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c index 155eab14b30e..8b1cf18a668b 100644 --- a/drivers/usb/serial/ipw.c +++ b/drivers/usb/serial/ipw.c | |||
@@ -38,7 +38,6 @@ | |||
38 | 38 | ||
39 | #include <linux/kernel.h> | 39 | #include <linux/kernel.h> |
40 | #include <linux/errno.h> | 40 | #include <linux/errno.h> |
41 | #include <linux/init.h> | ||
42 | #include <linux/slab.h> | 41 | #include <linux/slab.h> |
43 | #include <linux/tty.h> | 42 | #include <linux/tty.h> |
44 | #include <linux/tty_flip.h> | 43 | #include <linux/tty_flip.h> |
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index 716930ab1bb1..73956d48a0c5 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c | |||
@@ -377,15 +377,12 @@ static void ir_set_termios(struct tty_struct *tty, | |||
377 | * send the baud change out on an "empty" data packet | 377 | * send the baud change out on an "empty" data packet |
378 | */ | 378 | */ |
379 | urb = usb_alloc_urb(0, GFP_KERNEL); | 379 | urb = usb_alloc_urb(0, GFP_KERNEL); |
380 | if (!urb) { | 380 | if (!urb) |
381 | dev_err(&port->dev, "%s - no more urbs\n", __func__); | ||
382 | return; | 381 | return; |
383 | } | 382 | |
384 | transfer_buffer = kmalloc(1, GFP_KERNEL); | 383 | transfer_buffer = kmalloc(1, GFP_KERNEL); |
385 | if (!transfer_buffer) { | 384 | if (!transfer_buffer) |
386 | dev_err(&port->dev, "%s - out of memory\n", __func__); | ||
387 | goto err_buf; | 385 | goto err_buf; |
388 | } | ||
389 | 386 | ||
390 | *transfer_buffer = ir_xbof | ir_baud; | 387 | *transfer_buffer = ir_xbof | ir_baud; |
391 | 388 | ||
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c index 57c439a24b5a..d00dae17d520 100644 --- a/drivers/usb/serial/iuu_phoenix.c +++ b/drivers/usb/serial/iuu_phoenix.c | |||
@@ -17,7 +17,6 @@ | |||
17 | */ | 17 | */ |
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/init.h> | ||
21 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
22 | #include <linux/tty.h> | 21 | #include <linux/tty.h> |
23 | #include <linux/tty_driver.h> | 22 | #include <linux/tty_driver.h> |
@@ -770,7 +769,7 @@ uart_enable_failed: | |||
770 | return status; | 769 | return status; |
771 | } | 770 | } |
772 | 771 | ||
773 | /* Diables the IUU UART (a.k.a. the Phoenix voiderface) */ | 772 | /* Disables the IUU UART (a.k.a. the Phoenix voiderface) */ |
774 | static int iuu_uart_off(struct usb_serial_port *port) | 773 | static int iuu_uart_off(struct usb_serial_port *port) |
775 | { | 774 | { |
776 | int status; | 775 | int status; |
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c index d6960aebe246..265c6776b081 100644 --- a/drivers/usb/serial/keyspan.c +++ b/drivers/usb/serial/keyspan.c | |||
@@ -31,7 +31,6 @@ | |||
31 | #include <linux/kernel.h> | 31 | #include <linux/kernel.h> |
32 | #include <linux/jiffies.h> | 32 | #include <linux/jiffies.h> |
33 | #include <linux/errno.h> | 33 | #include <linux/errno.h> |
34 | #include <linux/init.h> | ||
35 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
36 | #include <linux/tty.h> | 35 | #include <linux/tty.h> |
37 | #include <linux/tty_driver.h> | 36 | #include <linux/tty_driver.h> |
@@ -165,7 +164,7 @@ static void keyspan_set_termios(struct tty_struct *tty, | |||
165 | if (d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk, | 164 | if (d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk, |
166 | NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) { | 165 | NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) { |
167 | /* FIXME - more to do here to ensure rate changes cleanly */ | 166 | /* FIXME - more to do here to ensure rate changes cleanly */ |
168 | /* FIXME - calcuate exact rate from divisor ? */ | 167 | /* FIXME - calculate exact rate from divisor ? */ |
169 | p_priv->baud = baud_rate; | 168 | p_priv->baud = baud_rate; |
170 | } else | 169 | } else |
171 | baud_rate = tty_termios_baud_rate(old_termios); | 170 | baud_rate = tty_termios_baud_rate(old_termios); |
@@ -1226,10 +1225,8 @@ static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint, | |||
1226 | 1225 | ||
1227 | dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d.\n", __func__, endpoint); | 1226 | dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d.\n", __func__, endpoint); |
1228 | urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */ | 1227 | urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */ |
1229 | if (urb == NULL) { | 1228 | if (!urb) |
1230 | dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d failed.\n", __func__, endpoint); | ||
1231 | return NULL; | 1229 | return NULL; |
1232 | } | ||
1233 | 1230 | ||
1234 | if (endpoint == 0) { | 1231 | if (endpoint == 0) { |
1235 | /* control EP filled in when used */ | 1232 | /* control EP filled in when used */ |
@@ -2312,10 +2309,8 @@ static int keyspan_startup(struct usb_serial *serial) | |||
2312 | 2309 | ||
2313 | /* Setup private data for serial driver */ | 2310 | /* Setup private data for serial driver */ |
2314 | s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL); | 2311 | s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL); |
2315 | if (!s_priv) { | 2312 | if (!s_priv) |
2316 | dev_dbg(&serial->dev->dev, "%s - kmalloc for keyspan_serial_private failed.\n", __func__); | ||
2317 | return -ENOMEM; | 2313 | return -ENOMEM; |
2318 | } | ||
2319 | 2314 | ||
2320 | s_priv->instat_buf = kzalloc(INSTAT_BUFLEN, GFP_KERNEL); | 2315 | s_priv->instat_buf = kzalloc(INSTAT_BUFLEN, GFP_KERNEL); |
2321 | if (!s_priv->instat_buf) | 2316 | if (!s_priv->instat_buf) |
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index 5f1d382e55cf..e972412b614b 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c | |||
@@ -17,7 +17,6 @@ | |||
17 | 17 | ||
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/init.h> | ||
21 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
22 | #include <linux/tty.h> | 21 | #include <linux/tty.h> |
23 | #include <linux/tty_driver.h> | 22 | #include <linux/tty_driver.h> |
diff --git a/drivers/usb/serial/keyspan_usa26msg.h b/drivers/usb/serial/keyspan_usa26msg.h index 3808727db65a..09e21e84fc4e 100644 --- a/drivers/usb/serial/keyspan_usa26msg.h +++ b/drivers/usb/serial/keyspan_usa26msg.h | |||
@@ -62,7 +62,7 @@ | |||
62 | or: | 62 | or: |
63 | 63 | ||
64 | (b) 0x80 bit set | 64 | (b) 0x80 bit set |
65 | indiates that the bytes following alternate data and | 65 | indicates that the bytes following alternate data and |
66 | status bytes: | 66 | status bytes: |
67 | 67 | ||
68 | STAT DATA STAT DATA STAT DATA STAT DATA ... | 68 | STAT DATA STAT DATA STAT DATA STAT DATA ... |
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c index 1b4054fe52a5..c88cc4966b23 100644 --- a/drivers/usb/serial/kl5kusb105.c +++ b/drivers/usb/serial/kl5kusb105.c | |||
@@ -37,7 +37,6 @@ | |||
37 | 37 | ||
38 | #include <linux/kernel.h> | 38 | #include <linux/kernel.h> |
39 | #include <linux/errno.h> | 39 | #include <linux/errno.h> |
40 | #include <linux/init.h> | ||
41 | #include <linux/slab.h> | 40 | #include <linux/slab.h> |
42 | #include <linux/tty.h> | 41 | #include <linux/tty.h> |
43 | #include <linux/tty_driver.h> | 42 | #include <linux/tty_driver.h> |
@@ -182,11 +181,9 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, | |||
182 | dev_info(&port->serial->dev->dev, "sending SIO Poll request\n"); | 181 | dev_info(&port->serial->dev->dev, "sending SIO Poll request\n"); |
183 | 182 | ||
184 | status_buf = kmalloc(KLSI_STATUSBUF_LEN, GFP_KERNEL); | 183 | status_buf = kmalloc(KLSI_STATUSBUF_LEN, GFP_KERNEL); |
185 | if (!status_buf) { | 184 | if (!status_buf) |
186 | dev_err(&port->dev, "%s - out of memory for status buffer.\n", | ||
187 | __func__); | ||
188 | return -ENOMEM; | 185 | return -ENOMEM; |
189 | } | 186 | |
190 | status_buf[0] = 0xff; | 187 | status_buf[0] = 0xff; |
191 | status_buf[1] = 0xff; | 188 | status_buf[1] = 0xff; |
192 | rc = usb_control_msg(port->serial->dev, | 189 | rc = usb_control_msg(port->serial->dev, |
@@ -273,11 +270,9 @@ static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
273 | * priv->line_state. | 270 | * priv->line_state. |
274 | */ | 271 | */ |
275 | cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); | 272 | cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); |
276 | if (!cfg) { | 273 | if (!cfg) |
277 | dev_err(&port->dev, "%s - out of memory for config buffer.\n", | ||
278 | __func__); | ||
279 | return -ENOMEM; | 274 | return -ENOMEM; |
280 | } | 275 | |
281 | cfg->pktlen = 5; | 276 | cfg->pktlen = 5; |
282 | cfg->baudrate = kl5kusb105a_sio_b9600; | 277 | cfg->baudrate = kl5kusb105a_sio_b9600; |
283 | cfg->databits = kl5kusb105a_dtb_8; | 278 | cfg->databits = kl5kusb105a_dtb_8; |
@@ -417,10 +412,8 @@ static void klsi_105_set_termios(struct tty_struct *tty, | |||
417 | speed_t baud; | 412 | speed_t baud; |
418 | 413 | ||
419 | cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); | 414 | cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); |
420 | if (!cfg) { | 415 | if (!cfg) |
421 | dev_err(dev, "%s - out of memory for config buffer.\n", __func__); | ||
422 | return; | 416 | return; |
423 | } | ||
424 | 417 | ||
425 | /* lock while we are modifying the settings */ | 418 | /* lock while we are modifying the settings */ |
426 | spin_lock_irqsave(&priv->lock, flags); | 419 | spin_lock_irqsave(&priv->lock, flags); |
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c index 78b48c31abf5..618c1c1f227e 100644 --- a/drivers/usb/serial/kobil_sct.c +++ b/drivers/usb/serial/kobil_sct.c | |||
@@ -25,7 +25,6 @@ | |||
25 | 25 | ||
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
28 | #include <linux/init.h> | ||
29 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
30 | #include <linux/tty.h> | 29 | #include <linux/tty.h> |
31 | #include <linux/tty_driver.h> | 30 | #include <linux/tty_driver.h> |
@@ -194,7 +193,7 @@ static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
194 | KOBIL_TIMEOUT | 193 | KOBIL_TIMEOUT |
195 | ); | 194 | ); |
196 | dev_dbg(dev, "%s - Send get_HW_version URB returns: %i\n", __func__, result); | 195 | dev_dbg(dev, "%s - Send get_HW_version URB returns: %i\n", __func__, result); |
197 | dev_dbg(dev, "Harware version: %i.%i.%i\n", transfer_buffer[0], | 196 | dev_dbg(dev, "Hardware version: %i.%i.%i\n", transfer_buffer[0], |
198 | transfer_buffer[1], transfer_buffer[2]); | 197 | transfer_buffer[1], transfer_buffer[2]); |
199 | 198 | ||
200 | /* get firmware version */ | 199 | /* get firmware version */ |
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c index 6a15adf53360..fd707d6a10e2 100644 --- a/drivers/usb/serial/mct_u232.c +++ b/drivers/usb/serial/mct_u232.c | |||
@@ -23,7 +23,6 @@ | |||
23 | 23 | ||
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/errno.h> | 25 | #include <linux/errno.h> |
26 | #include <linux/init.h> | ||
27 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
28 | #include <linux/tty.h> | 27 | #include <linux/tty.h> |
29 | #include <linux/tty_driver.h> | 28 | #include <linux/tty_driver.h> |
diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c index 40ccf6e5e318..39e683096e94 100644 --- a/drivers/usb/serial/metro-usb.c +++ b/drivers/usb/serial/metro-usb.c | |||
@@ -7,7 +7,6 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/kernel.h> | 9 | #include <linux/kernel.h> |
10 | #include <linux/init.h> | ||
11 | #include <linux/tty.h> | 10 | #include <linux/tty.h> |
12 | #include <linux/module.h> | 11 | #include <linux/module.h> |
13 | #include <linux/usb.h> | 12 | #include <linux/usb.h> |
@@ -43,7 +42,7 @@ struct metrousb_private { | |||
43 | }; | 42 | }; |
44 | 43 | ||
45 | /* Device table list. */ | 44 | /* Device table list. */ |
46 | static struct usb_device_id id_table[] = { | 45 | static const struct usb_device_id id_table[] = { |
47 | { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_BI) }, | 46 | { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_BI) }, |
48 | { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_UNI) }, | 47 | { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_UNI) }, |
49 | { }, /* Terminating entry. */ | 48 | { }, /* Terminating entry. */ |
@@ -54,7 +53,7 @@ MODULE_DEVICE_TABLE(usb, id_table); | |||
54 | #define UNI_CMD_OPEN 0x80 | 53 | #define UNI_CMD_OPEN 0x80 |
55 | #define UNI_CMD_CLOSE 0xFF | 54 | #define UNI_CMD_CLOSE 0xFF |
56 | 55 | ||
57 | inline int metrousb_is_unidirectional_mode(struct usb_serial_port *port) | 56 | static inline int metrousb_is_unidirectional_mode(struct usb_serial_port *port) |
58 | { | 57 | { |
59 | __u16 product_id = le16_to_cpu( | 58 | __u16 product_id = le16_to_cpu( |
60 | port->serial->dev->descriptor.idProduct); | 59 | port->serial->dev->descriptor.idProduct); |
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index 439c951f261b..4eb277225a77 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * mos7720.c | 2 | * mos7720.c |
3 | * Controls the Moschip 7720 usb to dual port serial convertor | 3 | * Controls the Moschip 7720 usb to dual port serial converter |
4 | * | 4 | * |
5 | * Copyright 2006 Moschip Semiconductor Tech. Ltd. | 5 | * Copyright 2006 Moschip Semiconductor Tech. Ltd. |
6 | * | 6 | * |
@@ -22,7 +22,6 @@ | |||
22 | */ | 22 | */ |
23 | #include <linux/kernel.h> | 23 | #include <linux/kernel.h> |
24 | #include <linux/errno.h> | 24 | #include <linux/errno.h> |
25 | #include <linux/init.h> | ||
26 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
27 | #include <linux/tty.h> | 26 | #include <linux/tty.h> |
28 | #include <linux/tty_driver.h> | 27 | #include <linux/tty_driver.h> |
@@ -46,7 +45,7 @@ | |||
46 | #define MOS_WRITE 0x0E | 45 | #define MOS_WRITE 0x0E |
47 | #define MOS_READ 0x0D | 46 | #define MOS_READ 0x0D |
48 | 47 | ||
49 | /* Interrupt Rotinue Defines */ | 48 | /* Interrupt Routines Defines */ |
50 | #define SERIAL_IIR_RLS 0x06 | 49 | #define SERIAL_IIR_RLS 0x06 |
51 | #define SERIAL_IIR_RDA 0x04 | 50 | #define SERIAL_IIR_RDA 0x04 |
52 | #define SERIAL_IIR_CTI 0x0c | 51 | #define SERIAL_IIR_CTI 0x0c |
@@ -362,15 +361,13 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport, | |||
362 | 361 | ||
363 | /* create and initialize the control urb and containing urbtracker */ | 362 | /* create and initialize the control urb and containing urbtracker */ |
364 | urbtrack = kmalloc(sizeof(struct urbtracker), GFP_ATOMIC); | 363 | urbtrack = kmalloc(sizeof(struct urbtracker), GFP_ATOMIC); |
365 | if (urbtrack == NULL) { | 364 | if (!urbtrack) |
366 | dev_err(&usbdev->dev, "out of memory"); | ||
367 | return -ENOMEM; | 365 | return -ENOMEM; |
368 | } | 366 | |
369 | kref_get(&mos_parport->ref_count); | 367 | kref_get(&mos_parport->ref_count); |
370 | urbtrack->mos_parport = mos_parport; | 368 | urbtrack->mos_parport = mos_parport; |
371 | urbtrack->urb = usb_alloc_urb(0, GFP_ATOMIC); | 369 | urbtrack->urb = usb_alloc_urb(0, GFP_ATOMIC); |
372 | if (urbtrack->urb == NULL) { | 370 | if (!urbtrack->urb) { |
373 | dev_err(&usbdev->dev, "out of urbs"); | ||
374 | kfree(urbtrack); | 371 | kfree(urbtrack); |
375 | return -ENOMEM; | 372 | return -ENOMEM; |
376 | } | 373 | } |
@@ -440,7 +437,7 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport, | |||
440 | * not called the release function yet because someone has a serial port open. | 437 | * not called the release function yet because someone has a serial port open. |
441 | * The shared release_lock prevents the first, and the mutex and disconnected | 438 | * The shared release_lock prevents the first, and the mutex and disconnected |
442 | * flag maintained by usbserial covers the second. We also use the msg_pending | 439 | * flag maintained by usbserial covers the second. We also use the msg_pending |
443 | * flag to ensure that all synchronous usb messgage calls have completed before | 440 | * flag to ensure that all synchronous usb message calls have completed before |
444 | * our release function can return. | 441 | * our release function can return. |
445 | */ | 442 | */ |
446 | static int parport_prologue(struct parport *pp) | 443 | static int parport_prologue(struct parport *pp) |
@@ -471,7 +468,7 @@ static int parport_prologue(struct parport *pp) | |||
471 | } | 468 | } |
472 | 469 | ||
473 | /* | 470 | /* |
474 | * This is the the common bottom part of all parallel port functions that send | 471 | * This is the common bottom part of all parallel port functions that send |
475 | * synchronous messages to the device. | 472 | * synchronous messages to the device. |
476 | */ | 473 | */ |
477 | static inline void parport_epilogue(struct parport *pp) | 474 | static inline void parport_epilogue(struct parport *pp) |
@@ -702,10 +699,9 @@ static int mos7715_parport_init(struct usb_serial *serial) | |||
702 | 699 | ||
703 | /* allocate and initialize parallel port control struct */ | 700 | /* allocate and initialize parallel port control struct */ |
704 | mos_parport = kzalloc(sizeof(struct mos7715_parport), GFP_KERNEL); | 701 | mos_parport = kzalloc(sizeof(struct mos7715_parport), GFP_KERNEL); |
705 | if (mos_parport == NULL) { | 702 | if (!mos_parport) |
706 | dev_dbg(&serial->dev->dev, "%s: kzalloc failed\n", __func__); | ||
707 | return -ENOMEM; | 703 | return -ENOMEM; |
708 | } | 704 | |
709 | mos_parport->msg_pending = false; | 705 | mos_parport->msg_pending = false; |
710 | kref_init(&mos_parport->ref_count); | 706 | kref_init(&mos_parport->ref_count); |
711 | spin_lock_init(&mos_parport->listlock); | 707 | spin_lock_init(&mos_parport->listlock); |
@@ -1018,18 +1014,12 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
1018 | for (j = 0; j < NUM_URBS; ++j) { | 1014 | for (j = 0; j < NUM_URBS; ++j) { |
1019 | urb = usb_alloc_urb(0, GFP_KERNEL); | 1015 | urb = usb_alloc_urb(0, GFP_KERNEL); |
1020 | mos7720_port->write_urb_pool[j] = urb; | 1016 | mos7720_port->write_urb_pool[j] = urb; |
1021 | 1017 | if (!urb) | |
1022 | if (urb == NULL) { | ||
1023 | dev_err(&port->dev, "No more urbs???\n"); | ||
1024 | continue; | 1018 | continue; |
1025 | } | ||
1026 | 1019 | ||
1027 | urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, | 1020 | urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, |
1028 | GFP_KERNEL); | 1021 | GFP_KERNEL); |
1029 | if (!urb->transfer_buffer) { | 1022 | if (!urb->transfer_buffer) { |
1030 | dev_err(&port->dev, | ||
1031 | "%s-out of memory for urb buffers.\n", | ||
1032 | __func__); | ||
1033 | usb_free_urb(mos7720_port->write_urb_pool[j]); | 1023 | usb_free_urb(mos7720_port->write_urb_pool[j]); |
1034 | mos7720_port->write_urb_pool[j] = NULL; | 1024 | mos7720_port->write_urb_pool[j] = NULL; |
1035 | continue; | 1025 | continue; |
@@ -1250,11 +1240,8 @@ static int mos7720_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
1250 | if (urb->transfer_buffer == NULL) { | 1240 | if (urb->transfer_buffer == NULL) { |
1251 | urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, | 1241 | urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, |
1252 | GFP_KERNEL); | 1242 | GFP_KERNEL); |
1253 | if (urb->transfer_buffer == NULL) { | 1243 | if (!urb->transfer_buffer) |
1254 | dev_err_console(port, "%s no more kernel memory...\n", | ||
1255 | __func__); | ||
1256 | goto exit; | 1244 | goto exit; |
1257 | } | ||
1258 | } | 1245 | } |
1259 | transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); | 1246 | transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); |
1260 | 1247 | ||
@@ -1885,8 +1872,6 @@ static int mos7720_ioctl(struct tty_struct *tty, | |||
1885 | if (mos7720_port == NULL) | 1872 | if (mos7720_port == NULL) |
1886 | return -ENODEV; | 1873 | return -ENODEV; |
1887 | 1874 | ||
1888 | dev_dbg(&port->dev, "%s - cmd = 0x%x", __func__, cmd); | ||
1889 | |||
1890 | switch (cmd) { | 1875 | switch (cmd) { |
1891 | case TIOCSERGETLSR: | 1876 | case TIOCSERGETLSR: |
1892 | dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__); | 1877 | dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__); |
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index a69da83604c0..e9d967ff521b 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c | |||
@@ -24,7 +24,6 @@ | |||
24 | 24 | ||
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/errno.h> | 26 | #include <linux/errno.h> |
27 | #include <linux/init.h> | ||
28 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
29 | #include <linux/tty.h> | 28 | #include <linux/tty.h> |
30 | #include <linux/tty_driver.h> | 29 | #include <linux/tty_driver.h> |
@@ -876,20 +875,14 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
876 | for (j = 0; j < NUM_URBS; ++j) { | 875 | for (j = 0; j < NUM_URBS; ++j) { |
877 | urb = usb_alloc_urb(0, GFP_KERNEL); | 876 | urb = usb_alloc_urb(0, GFP_KERNEL); |
878 | mos7840_port->write_urb_pool[j] = urb; | 877 | mos7840_port->write_urb_pool[j] = urb; |
879 | 878 | if (!urb) | |
880 | if (urb == NULL) { | ||
881 | dev_err(&port->dev, "No more urbs???\n"); | ||
882 | continue; | 879 | continue; |
883 | } | ||
884 | 880 | ||
885 | urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, | 881 | urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, |
886 | GFP_KERNEL); | 882 | GFP_KERNEL); |
887 | if (!urb->transfer_buffer) { | 883 | if (!urb->transfer_buffer) { |
888 | usb_free_urb(urb); | 884 | usb_free_urb(urb); |
889 | mos7840_port->write_urb_pool[j] = NULL; | 885 | mos7840_port->write_urb_pool[j] = NULL; |
890 | dev_err(&port->dev, | ||
891 | "%s-out of memory for urb buffers.\n", | ||
892 | __func__); | ||
893 | continue; | 886 | continue; |
894 | } | 887 | } |
895 | } | 888 | } |
@@ -1381,12 +1374,8 @@ static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
1381 | if (urb->transfer_buffer == NULL) { | 1374 | if (urb->transfer_buffer == NULL) { |
1382 | urb->transfer_buffer = | 1375 | urb->transfer_buffer = |
1383 | kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); | 1376 | kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); |
1384 | 1377 | if (!urb->transfer_buffer) | |
1385 | if (urb->transfer_buffer == NULL) { | ||
1386 | dev_err_console(port, "%s no more kernel memory...\n", | ||
1387 | __func__); | ||
1388 | goto exit; | 1378 | goto exit; |
1389 | } | ||
1390 | } | 1379 | } |
1391 | transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); | 1380 | transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); |
1392 | 1381 | ||
@@ -2070,8 +2059,6 @@ static int mos7840_ioctl(struct tty_struct *tty, | |||
2070 | if (mos7840_port == NULL) | 2059 | if (mos7840_port == NULL) |
2071 | return -1; | 2060 | return -1; |
2072 | 2061 | ||
2073 | dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd); | ||
2074 | |||
2075 | switch (cmd) { | 2062 | switch (cmd) { |
2076 | /* return number of bytes available */ | 2063 | /* return number of bytes available */ |
2077 | 2064 | ||
@@ -2208,10 +2195,8 @@ static int mos7840_port_probe(struct usb_serial_port *port) | |||
2208 | 2195 | ||
2209 | dev_dbg(&port->dev, "mos7840_startup: configuring port %d\n", pnum); | 2196 | dev_dbg(&port->dev, "mos7840_startup: configuring port %d\n", pnum); |
2210 | mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); | 2197 | mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); |
2211 | if (mos7840_port == NULL) { | 2198 | if (!mos7840_port) |
2212 | dev_err(&port->dev, "%s - Out of memory\n", __func__); | ||
2213 | return -ENOMEM; | 2199 | return -ENOMEM; |
2214 | } | ||
2215 | 2200 | ||
2216 | /* Initialize all port interrupt end point to port 0 int | 2201 | /* Initialize all port interrupt end point to port 0 int |
2217 | * endpoint. Our device has only one interrupt end point | 2202 | * endpoint. Our device has only one interrupt end point |
diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c new file mode 100644 index 000000000000..ab1d690274ae --- /dev/null +++ b/drivers/usb/serial/mxuport.c | |||
@@ -0,0 +1,1393 @@ | |||
1 | /* | ||
2 | * mxuport.c - MOXA UPort series driver | ||
3 | * | ||
4 | * Copyright (c) 2006 Moxa Technologies Co., Ltd. | ||
5 | * Copyright (c) 2013 Andrew Lunn <andrew@lunn.ch> | ||
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 | * Supports the following Moxa USB to serial converters: | ||
13 | * 2 ports : UPort 1250, UPort 1250I | ||
14 | * 4 ports : UPort 1410, UPort 1450, UPort 1450I | ||
15 | * 8 ports : UPort 1610-8, UPort 1650-8 | ||
16 | * 16 ports : UPort 1610-16, UPort 1650-16 | ||
17 | */ | ||
18 | |||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/firmware.h> | ||
22 | #include <linux/jiffies.h> | ||
23 | #include <linux/serial.h> | ||
24 | #include <linux/serial_reg.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/tty.h> | ||
27 | #include <linux/tty_driver.h> | ||
28 | #include <linux/tty_flip.h> | ||
29 | #include <linux/uaccess.h> | ||
30 | #include <linux/usb.h> | ||
31 | #include <linux/usb/serial.h> | ||
32 | #include <asm/unaligned.h> | ||
33 | |||
34 | /* Definitions for the vendor ID and device ID */ | ||
35 | #define MX_USBSERIAL_VID 0x110A | ||
36 | #define MX_UPORT1250_PID 0x1250 | ||
37 | #define MX_UPORT1251_PID 0x1251 | ||
38 | #define MX_UPORT1410_PID 0x1410 | ||
39 | #define MX_UPORT1450_PID 0x1450 | ||
40 | #define MX_UPORT1451_PID 0x1451 | ||
41 | #define MX_UPORT1618_PID 0x1618 | ||
42 | #define MX_UPORT1658_PID 0x1658 | ||
43 | #define MX_UPORT1613_PID 0x1613 | ||
44 | #define MX_UPORT1653_PID 0x1653 | ||
45 | |||
46 | /* Definitions for USB info */ | ||
47 | #define HEADER_SIZE 4 | ||
48 | #define EVENT_LENGTH 8 | ||
49 | #define DOWN_BLOCK_SIZE 64 | ||
50 | |||
51 | /* Definitions for firmware info */ | ||
52 | #define VER_ADDR_1 0x20 | ||
53 | #define VER_ADDR_2 0x24 | ||
54 | #define VER_ADDR_3 0x28 | ||
55 | |||
56 | /* Definitions for USB vendor request */ | ||
57 | #define RQ_VENDOR_NONE 0x00 | ||
58 | #define RQ_VENDOR_SET_BAUD 0x01 /* Set baud rate */ | ||
59 | #define RQ_VENDOR_SET_LINE 0x02 /* Set line status */ | ||
60 | #define RQ_VENDOR_SET_CHARS 0x03 /* Set Xon/Xoff chars */ | ||
61 | #define RQ_VENDOR_SET_RTS 0x04 /* Set RTS */ | ||
62 | #define RQ_VENDOR_SET_DTR 0x05 /* Set DTR */ | ||
63 | #define RQ_VENDOR_SET_XONXOFF 0x06 /* Set auto Xon/Xoff */ | ||
64 | #define RQ_VENDOR_SET_RX_HOST_EN 0x07 /* Set RX host enable */ | ||
65 | #define RQ_VENDOR_SET_OPEN 0x08 /* Set open/close port */ | ||
66 | #define RQ_VENDOR_PURGE 0x09 /* Purge Rx/Tx buffer */ | ||
67 | #define RQ_VENDOR_SET_MCR 0x0A /* Set MCR register */ | ||
68 | #define RQ_VENDOR_SET_BREAK 0x0B /* Set Break signal */ | ||
69 | |||
70 | #define RQ_VENDOR_START_FW_DOWN 0x0C /* Start firmware download */ | ||
71 | #define RQ_VENDOR_STOP_FW_DOWN 0x0D /* Stop firmware download */ | ||
72 | #define RQ_VENDOR_QUERY_FW_READY 0x0E /* Query if new firmware ready */ | ||
73 | |||
74 | #define RQ_VENDOR_SET_FIFO_DISABLE 0x0F /* Set fifo disable */ | ||
75 | #define RQ_VENDOR_SET_INTERFACE 0x10 /* Set interface */ | ||
76 | #define RQ_VENDOR_SET_HIGH_PERFOR 0x11 /* Set hi-performance */ | ||
77 | |||
78 | #define RQ_VENDOR_ERASE_BLOCK 0x12 /* Erase flash block */ | ||
79 | #define RQ_VENDOR_WRITE_PAGE 0x13 /* Write flash page */ | ||
80 | #define RQ_VENDOR_PREPARE_WRITE 0x14 /* Prepare write flash */ | ||
81 | #define RQ_VENDOR_CONFIRM_WRITE 0x15 /* Confirm write flash */ | ||
82 | #define RQ_VENDOR_LOCATE 0x16 /* Locate the device */ | ||
83 | |||
84 | #define RQ_VENDOR_START_ROM_DOWN 0x17 /* Start firmware download */ | ||
85 | #define RQ_VENDOR_ROM_DATA 0x18 /* Rom file data */ | ||
86 | #define RQ_VENDOR_STOP_ROM_DOWN 0x19 /* Stop firmware download */ | ||
87 | #define RQ_VENDOR_FW_DATA 0x20 /* Firmware data */ | ||
88 | |||
89 | #define RQ_VENDOR_RESET_DEVICE 0x23 /* Try to reset the device */ | ||
90 | #define RQ_VENDOR_QUERY_FW_CONFIG 0x24 | ||
91 | |||
92 | #define RQ_VENDOR_GET_VERSION 0x81 /* Get firmware version */ | ||
93 | #define RQ_VENDOR_GET_PAGE 0x82 /* Read flash page */ | ||
94 | #define RQ_VENDOR_GET_ROM_PROC 0x83 /* Get ROM process state */ | ||
95 | |||
96 | #define RQ_VENDOR_GET_INQUEUE 0x84 /* Data in input buffer */ | ||
97 | #define RQ_VENDOR_GET_OUTQUEUE 0x85 /* Data in output buffer */ | ||
98 | |||
99 | #define RQ_VENDOR_GET_MSR 0x86 /* Get modem status register */ | ||
100 | |||
101 | /* Definitions for UPort event type */ | ||
102 | #define UPORT_EVENT_NONE 0 /* None */ | ||
103 | #define UPORT_EVENT_TXBUF_THRESHOLD 1 /* Tx buffer threshold */ | ||
104 | #define UPORT_EVENT_SEND_NEXT 2 /* Send next */ | ||
105 | #define UPORT_EVENT_MSR 3 /* Modem status */ | ||
106 | #define UPORT_EVENT_LSR 4 /* Line status */ | ||
107 | #define UPORT_EVENT_MCR 5 /* Modem control */ | ||
108 | |||
109 | /* Definitions for serial event type */ | ||
110 | #define SERIAL_EV_CTS 0x0008 /* CTS changed state */ | ||
111 | #define SERIAL_EV_DSR 0x0010 /* DSR changed state */ | ||
112 | #define SERIAL_EV_RLSD 0x0020 /* RLSD changed state */ | ||
113 | |||
114 | /* Definitions for modem control event type */ | ||
115 | #define SERIAL_EV_XOFF 0x40 /* XOFF received */ | ||
116 | |||
117 | /* Definitions for line control of communication */ | ||
118 | #define MX_WORDLENGTH_5 5 | ||
119 | #define MX_WORDLENGTH_6 6 | ||
120 | #define MX_WORDLENGTH_7 7 | ||
121 | #define MX_WORDLENGTH_8 8 | ||
122 | |||
123 | #define MX_PARITY_NONE 0 | ||
124 | #define MX_PARITY_ODD 1 | ||
125 | #define MX_PARITY_EVEN 2 | ||
126 | #define MX_PARITY_MARK 3 | ||
127 | #define MX_PARITY_SPACE 4 | ||
128 | |||
129 | #define MX_STOP_BITS_1 0 | ||
130 | #define MX_STOP_BITS_1_5 1 | ||
131 | #define MX_STOP_BITS_2 2 | ||
132 | |||
133 | #define MX_RTS_DISABLE 0x0 | ||
134 | #define MX_RTS_ENABLE 0x1 | ||
135 | #define MX_RTS_HW 0x2 | ||
136 | #define MX_RTS_NO_CHANGE 0x3 /* Flag, not valid register value*/ | ||
137 | |||
138 | #define MX_INT_RS232 0 | ||
139 | #define MX_INT_2W_RS485 1 | ||
140 | #define MX_INT_RS422 2 | ||
141 | #define MX_INT_4W_RS485 3 | ||
142 | |||
143 | /* Definitions for holding reason */ | ||
144 | #define MX_WAIT_FOR_CTS 0x0001 | ||
145 | #define MX_WAIT_FOR_DSR 0x0002 | ||
146 | #define MX_WAIT_FOR_DCD 0x0004 | ||
147 | #define MX_WAIT_FOR_XON 0x0008 | ||
148 | #define MX_WAIT_FOR_START_TX 0x0010 | ||
149 | #define MX_WAIT_FOR_UNTHROTTLE 0x0020 | ||
150 | #define MX_WAIT_FOR_LOW_WATER 0x0040 | ||
151 | #define MX_WAIT_FOR_SEND_NEXT 0x0080 | ||
152 | |||
153 | #define MX_UPORT_2_PORT BIT(0) | ||
154 | #define MX_UPORT_4_PORT BIT(1) | ||
155 | #define MX_UPORT_8_PORT BIT(2) | ||
156 | #define MX_UPORT_16_PORT BIT(3) | ||
157 | |||
158 | /* This structure holds all of the local port information */ | ||
159 | struct mxuport_port { | ||
160 | u8 mcr_state; /* Last MCR state */ | ||
161 | u8 msr_state; /* Last MSR state */ | ||
162 | struct mutex mutex; /* Protects mcr_state */ | ||
163 | spinlock_t spinlock; /* Protects msr_state */ | ||
164 | }; | ||
165 | |||
166 | /* Table of devices that work with this driver */ | ||
167 | static const struct usb_device_id mxuport_idtable[] = { | ||
168 | { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1250_PID), | ||
169 | .driver_info = MX_UPORT_2_PORT }, | ||
170 | { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1251_PID), | ||
171 | .driver_info = MX_UPORT_2_PORT }, | ||
172 | { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1410_PID), | ||
173 | .driver_info = MX_UPORT_4_PORT }, | ||
174 | { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1450_PID), | ||
175 | .driver_info = MX_UPORT_4_PORT }, | ||
176 | { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1451_PID), | ||
177 | .driver_info = MX_UPORT_4_PORT }, | ||
178 | { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1618_PID), | ||
179 | .driver_info = MX_UPORT_8_PORT }, | ||
180 | { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1658_PID), | ||
181 | .driver_info = MX_UPORT_8_PORT }, | ||
182 | { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1613_PID), | ||
183 | .driver_info = MX_UPORT_16_PORT }, | ||
184 | { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1653_PID), | ||
185 | .driver_info = MX_UPORT_16_PORT }, | ||
186 | {} /* Terminating entry */ | ||
187 | }; | ||
188 | |||
189 | MODULE_DEVICE_TABLE(usb, mxuport_idtable); | ||
190 | |||
191 | /* | ||
192 | * Add a four byte header containing the port number and the number of | ||
193 | * bytes of data in the message. Return the number of bytes in the | ||
194 | * buffer. | ||
195 | */ | ||
196 | static int mxuport_prepare_write_buffer(struct usb_serial_port *port, | ||
197 | void *dest, size_t size) | ||
198 | { | ||
199 | u8 *buf = dest; | ||
200 | int count; | ||
201 | |||
202 | count = kfifo_out_locked(&port->write_fifo, buf + HEADER_SIZE, | ||
203 | size - HEADER_SIZE, | ||
204 | &port->lock); | ||
205 | |||
206 | put_unaligned_be16(port->port_number, buf); | ||
207 | put_unaligned_be16(count, buf + 2); | ||
208 | |||
209 | dev_dbg(&port->dev, "%s - size %zd count %d\n", __func__, | ||
210 | size, count); | ||
211 | |||
212 | return count + HEADER_SIZE; | ||
213 | } | ||
214 | |||
215 | /* Read the given buffer in from the control pipe. */ | ||
216 | static int mxuport_recv_ctrl_urb(struct usb_serial *serial, | ||
217 | u8 request, u16 value, u16 index, | ||
218 | u8 *data, size_t size) | ||
219 | { | ||
220 | int status; | ||
221 | |||
222 | status = usb_control_msg(serial->dev, | ||
223 | usb_rcvctrlpipe(serial->dev, 0), | ||
224 | request, | ||
225 | (USB_DIR_IN | USB_TYPE_VENDOR | | ||
226 | USB_RECIP_DEVICE), value, index, | ||
227 | data, size, | ||
228 | USB_CTRL_GET_TIMEOUT); | ||
229 | if (status < 0) { | ||
230 | dev_err(&serial->interface->dev, | ||
231 | "%s - usb_control_msg failed (%d)\n", | ||
232 | __func__, status); | ||
233 | return status; | ||
234 | } | ||
235 | |||
236 | if (status != size) { | ||
237 | dev_err(&serial->interface->dev, | ||
238 | "%s - short read (%d / %zd)\n", | ||
239 | __func__, status, size); | ||
240 | return -EIO; | ||
241 | } | ||
242 | |||
243 | return status; | ||
244 | } | ||
245 | |||
246 | /* Write the given buffer out to the control pipe. */ | ||
247 | static int mxuport_send_ctrl_data_urb(struct usb_serial *serial, | ||
248 | u8 request, | ||
249 | u16 value, u16 index, | ||
250 | u8 *data, size_t size) | ||
251 | { | ||
252 | int status; | ||
253 | |||
254 | status = usb_control_msg(serial->dev, | ||
255 | usb_sndctrlpipe(serial->dev, 0), | ||
256 | request, | ||
257 | (USB_DIR_OUT | USB_TYPE_VENDOR | | ||
258 | USB_RECIP_DEVICE), value, index, | ||
259 | data, size, | ||
260 | USB_CTRL_SET_TIMEOUT); | ||
261 | if (status < 0) { | ||
262 | dev_err(&serial->interface->dev, | ||
263 | "%s - usb_control_msg failed (%d)\n", | ||
264 | __func__, status); | ||
265 | return status; | ||
266 | } | ||
267 | |||
268 | if (status != size) { | ||
269 | dev_err(&serial->interface->dev, | ||
270 | "%s - short write (%d / %zd)\n", | ||
271 | __func__, status, size); | ||
272 | return -EIO; | ||
273 | } | ||
274 | |||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | /* Send a vendor request without any data */ | ||
279 | static int mxuport_send_ctrl_urb(struct usb_serial *serial, | ||
280 | u8 request, u16 value, u16 index) | ||
281 | { | ||
282 | return mxuport_send_ctrl_data_urb(serial, request, value, index, | ||
283 | NULL, 0); | ||
284 | } | ||
285 | |||
286 | /* | ||
287 | * mxuport_throttle - throttle function of driver | ||
288 | * | ||
289 | * This function is called by the tty driver when it wants to stop the | ||
290 | * data being read from the port. Since all the data comes over one | ||
291 | * bulk in endpoint, we cannot stop submitting urbs by setting | ||
292 | * port->throttle. Instead tell the device to stop sending us data for | ||
293 | * the port. | ||
294 | */ | ||
295 | static void mxuport_throttle(struct tty_struct *tty) | ||
296 | { | ||
297 | struct usb_serial_port *port = tty->driver_data; | ||
298 | struct usb_serial *serial = port->serial; | ||
299 | |||
300 | dev_dbg(&port->dev, "%s\n", __func__); | ||
301 | |||
302 | mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_RX_HOST_EN, | ||
303 | 0, port->port_number); | ||
304 | } | ||
305 | |||
306 | /* | ||
307 | * mxuport_unthrottle - unthrottle function of driver | ||
308 | * | ||
309 | * This function is called by the tty driver when it wants to resume | ||
310 | * the data being read from the port. Tell the device it can resume | ||
311 | * sending us received data from the port. | ||
312 | */ | ||
313 | static void mxuport_unthrottle(struct tty_struct *tty) | ||
314 | { | ||
315 | |||
316 | struct usb_serial_port *port = tty->driver_data; | ||
317 | struct usb_serial *serial = port->serial; | ||
318 | |||
319 | dev_dbg(&port->dev, "%s\n", __func__); | ||
320 | |||
321 | mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_RX_HOST_EN, | ||
322 | 1, port->port_number); | ||
323 | } | ||
324 | |||
325 | /* | ||
326 | * Processes one chunk of data received for a port. Mostly a copy of | ||
327 | * usb_serial_generic_process_read_urb(). | ||
328 | */ | ||
329 | static void mxuport_process_read_urb_data(struct usb_serial_port *port, | ||
330 | char *data, int size) | ||
331 | { | ||
332 | int i; | ||
333 | |||
334 | if (!port->port.console || !port->sysrq) { | ||
335 | tty_insert_flip_string(&port->port, data, size); | ||
336 | } else { | ||
337 | for (i = 0; i < size; i++, data++) { | ||
338 | if (!usb_serial_handle_sysrq_char(port, *data)) | ||
339 | tty_insert_flip_char(&port->port, *data, | ||
340 | TTY_NORMAL); | ||
341 | } | ||
342 | } | ||
343 | tty_flip_buffer_push(&port->port); | ||
344 | } | ||
345 | |||
346 | static void mxuport_msr_event(struct usb_serial_port *port, u8 buf[4]) | ||
347 | { | ||
348 | struct mxuport_port *mxport = usb_get_serial_port_data(port); | ||
349 | u8 rcv_msr_hold = buf[2] & 0xF0; | ||
350 | u16 rcv_msr_event = get_unaligned_be16(buf); | ||
351 | unsigned long flags; | ||
352 | |||
353 | if (rcv_msr_event == 0) | ||
354 | return; | ||
355 | |||
356 | /* Update MSR status */ | ||
357 | spin_lock_irqsave(&mxport->spinlock, flags); | ||
358 | |||
359 | dev_dbg(&port->dev, "%s - current MSR status = 0x%x\n", | ||
360 | __func__, mxport->msr_state); | ||
361 | |||
362 | if (rcv_msr_hold & UART_MSR_CTS) { | ||
363 | mxport->msr_state |= UART_MSR_CTS; | ||
364 | dev_dbg(&port->dev, "%s - CTS high\n", __func__); | ||
365 | } else { | ||
366 | mxport->msr_state &= ~UART_MSR_CTS; | ||
367 | dev_dbg(&port->dev, "%s - CTS low\n", __func__); | ||
368 | } | ||
369 | |||
370 | if (rcv_msr_hold & UART_MSR_DSR) { | ||
371 | mxport->msr_state |= UART_MSR_DSR; | ||
372 | dev_dbg(&port->dev, "%s - DSR high\n", __func__); | ||
373 | } else { | ||
374 | mxport->msr_state &= ~UART_MSR_DSR; | ||
375 | dev_dbg(&port->dev, "%s - DSR low\n", __func__); | ||
376 | } | ||
377 | |||
378 | if (rcv_msr_hold & UART_MSR_DCD) { | ||
379 | mxport->msr_state |= UART_MSR_DCD; | ||
380 | dev_dbg(&port->dev, "%s - DCD high\n", __func__); | ||
381 | } else { | ||
382 | mxport->msr_state &= ~UART_MSR_DCD; | ||
383 | dev_dbg(&port->dev, "%s - DCD low\n", __func__); | ||
384 | } | ||
385 | spin_unlock_irqrestore(&mxport->spinlock, flags); | ||
386 | |||
387 | if (rcv_msr_event & | ||
388 | (SERIAL_EV_CTS | SERIAL_EV_DSR | SERIAL_EV_RLSD)) { | ||
389 | |||
390 | if (rcv_msr_event & SERIAL_EV_CTS) { | ||
391 | port->icount.cts++; | ||
392 | dev_dbg(&port->dev, "%s - CTS change\n", __func__); | ||
393 | } | ||
394 | |||
395 | if (rcv_msr_event & SERIAL_EV_DSR) { | ||
396 | port->icount.dsr++; | ||
397 | dev_dbg(&port->dev, "%s - DSR change\n", __func__); | ||
398 | } | ||
399 | |||
400 | if (rcv_msr_event & SERIAL_EV_RLSD) { | ||
401 | port->icount.dcd++; | ||
402 | dev_dbg(&port->dev, "%s - DCD change\n", __func__); | ||
403 | } | ||
404 | wake_up_interruptible(&port->port.delta_msr_wait); | ||
405 | } | ||
406 | } | ||
407 | |||
408 | static void mxuport_lsr_event(struct usb_serial_port *port, u8 buf[4]) | ||
409 | { | ||
410 | u8 lsr_event = buf[2]; | ||
411 | |||
412 | if (lsr_event & UART_LSR_BI) { | ||
413 | port->icount.brk++; | ||
414 | dev_dbg(&port->dev, "%s - break error\n", __func__); | ||
415 | } | ||
416 | |||
417 | if (lsr_event & UART_LSR_FE) { | ||
418 | port->icount.frame++; | ||
419 | dev_dbg(&port->dev, "%s - frame error\n", __func__); | ||
420 | } | ||
421 | |||
422 | if (lsr_event & UART_LSR_PE) { | ||
423 | port->icount.parity++; | ||
424 | dev_dbg(&port->dev, "%s - parity error\n", __func__); | ||
425 | } | ||
426 | |||
427 | if (lsr_event & UART_LSR_OE) { | ||
428 | port->icount.overrun++; | ||
429 | dev_dbg(&port->dev, "%s - overrun error\n", __func__); | ||
430 | } | ||
431 | } | ||
432 | |||
433 | /* | ||
434 | * When something interesting happens, modem control lines XON/XOFF | ||
435 | * etc, the device sends an event. Process these events. | ||
436 | */ | ||
437 | static void mxuport_process_read_urb_event(struct usb_serial_port *port, | ||
438 | u8 buf[4], u32 event) | ||
439 | { | ||
440 | dev_dbg(&port->dev, "%s - receive event : %04x\n", __func__, event); | ||
441 | |||
442 | switch (event) { | ||
443 | case UPORT_EVENT_SEND_NEXT: | ||
444 | /* | ||
445 | * Sent as part of the flow control on device buffers. | ||
446 | * Not currently used. | ||
447 | */ | ||
448 | break; | ||
449 | case UPORT_EVENT_MSR: | ||
450 | mxuport_msr_event(port, buf); | ||
451 | break; | ||
452 | case UPORT_EVENT_LSR: | ||
453 | mxuport_lsr_event(port, buf); | ||
454 | break; | ||
455 | case UPORT_EVENT_MCR: | ||
456 | /* | ||
457 | * Event to indicate a change in XON/XOFF from the | ||
458 | * peer. Currently not used. We just continue | ||
459 | * sending the device data and it will buffer it if | ||
460 | * needed. This event could be used for flow control | ||
461 | * between the host and the device. | ||
462 | */ | ||
463 | break; | ||
464 | default: | ||
465 | dev_dbg(&port->dev, "Unexpected event\n"); | ||
466 | break; | ||
467 | } | ||
468 | } | ||
469 | |||
470 | /* | ||
471 | * One URB can contain data for multiple ports. Demultiplex the data, | ||
472 | * checking the port exists, is opened and the message is valid. | ||
473 | */ | ||
474 | static void mxuport_process_read_urb_demux_data(struct urb *urb) | ||
475 | { | ||
476 | struct usb_serial_port *port = urb->context; | ||
477 | struct usb_serial *serial = port->serial; | ||
478 | u8 *data = urb->transfer_buffer; | ||
479 | u8 *end = data + urb->actual_length; | ||
480 | struct usb_serial_port *demux_port; | ||
481 | u8 *ch; | ||
482 | u16 rcv_port; | ||
483 | u16 rcv_len; | ||
484 | |||
485 | while (data < end) { | ||
486 | if (data + HEADER_SIZE > end) { | ||
487 | dev_warn(&port->dev, "%s - message with short header\n", | ||
488 | __func__); | ||
489 | return; | ||
490 | } | ||
491 | |||
492 | rcv_port = get_unaligned_be16(data); | ||
493 | if (rcv_port >= serial->num_ports) { | ||
494 | dev_warn(&port->dev, "%s - message for invalid port\n", | ||
495 | __func__); | ||
496 | return; | ||
497 | } | ||
498 | |||
499 | demux_port = serial->port[rcv_port]; | ||
500 | rcv_len = get_unaligned_be16(data + 2); | ||
501 | if (!rcv_len || data + HEADER_SIZE + rcv_len > end) { | ||
502 | dev_warn(&port->dev, "%s - short data\n", __func__); | ||
503 | return; | ||
504 | } | ||
505 | |||
506 | if (test_bit(ASYNCB_INITIALIZED, &demux_port->port.flags)) { | ||
507 | ch = data + HEADER_SIZE; | ||
508 | mxuport_process_read_urb_data(demux_port, ch, rcv_len); | ||
509 | } else { | ||
510 | dev_dbg(&demux_port->dev, "%s - data for closed port\n", | ||
511 | __func__); | ||
512 | } | ||
513 | data += HEADER_SIZE + rcv_len; | ||
514 | } | ||
515 | } | ||
516 | |||
517 | /* | ||
518 | * One URB can contain events for multiple ports. Demultiplex the event, | ||
519 | * checking the port exists, and is opened. | ||
520 | */ | ||
521 | static void mxuport_process_read_urb_demux_event(struct urb *urb) | ||
522 | { | ||
523 | struct usb_serial_port *port = urb->context; | ||
524 | struct usb_serial *serial = port->serial; | ||
525 | u8 *data = urb->transfer_buffer; | ||
526 | u8 *end = data + urb->actual_length; | ||
527 | struct usb_serial_port *demux_port; | ||
528 | u8 *ch; | ||
529 | u16 rcv_port; | ||
530 | u16 rcv_event; | ||
531 | |||
532 | while (data < end) { | ||
533 | if (data + EVENT_LENGTH > end) { | ||
534 | dev_warn(&port->dev, "%s - message with short event\n", | ||
535 | __func__); | ||
536 | return; | ||
537 | } | ||
538 | |||
539 | rcv_port = get_unaligned_be16(data); | ||
540 | if (rcv_port >= serial->num_ports) { | ||
541 | dev_warn(&port->dev, "%s - message for invalid port\n", | ||
542 | __func__); | ||
543 | return; | ||
544 | } | ||
545 | |||
546 | demux_port = serial->port[rcv_port]; | ||
547 | if (test_bit(ASYNCB_INITIALIZED, &demux_port->port.flags)) { | ||
548 | ch = data + HEADER_SIZE; | ||
549 | rcv_event = get_unaligned_be16(data + 2); | ||
550 | mxuport_process_read_urb_event(demux_port, ch, | ||
551 | rcv_event); | ||
552 | } else { | ||
553 | dev_dbg(&demux_port->dev, | ||
554 | "%s - event for closed port\n", __func__); | ||
555 | } | ||
556 | data += EVENT_LENGTH; | ||
557 | } | ||
558 | } | ||
559 | |||
560 | /* | ||
561 | * This is called when we have received data on the bulk in | ||
562 | * endpoint. Depending on which port it was received on, it can | ||
563 | * contain serial data or events. | ||
564 | */ | ||
565 | static void mxuport_process_read_urb(struct urb *urb) | ||
566 | { | ||
567 | struct usb_serial_port *port = urb->context; | ||
568 | struct usb_serial *serial = port->serial; | ||
569 | |||
570 | if (port == serial->port[0]) | ||
571 | mxuport_process_read_urb_demux_data(urb); | ||
572 | |||
573 | if (port == serial->port[1]) | ||
574 | mxuport_process_read_urb_demux_event(urb); | ||
575 | } | ||
576 | |||
577 | /* | ||
578 | * Ask the device how many bytes it has queued to be sent out. If | ||
579 | * there are none, return true. | ||
580 | */ | ||
581 | static bool mxuport_tx_empty(struct usb_serial_port *port) | ||
582 | { | ||
583 | struct usb_serial *serial = port->serial; | ||
584 | bool is_empty = true; | ||
585 | u32 txlen; | ||
586 | u8 *len_buf; | ||
587 | int err; | ||
588 | |||
589 | len_buf = kzalloc(4, GFP_KERNEL); | ||
590 | if (!len_buf) | ||
591 | goto out; | ||
592 | |||
593 | err = mxuport_recv_ctrl_urb(serial, RQ_VENDOR_GET_OUTQUEUE, 0, | ||
594 | port->port_number, len_buf, 4); | ||
595 | if (err < 0) | ||
596 | goto out; | ||
597 | |||
598 | txlen = get_unaligned_be32(len_buf); | ||
599 | dev_dbg(&port->dev, "%s - tx len = %u\n", __func__, txlen); | ||
600 | |||
601 | if (txlen != 0) | ||
602 | is_empty = false; | ||
603 | |||
604 | out: | ||
605 | kfree(len_buf); | ||
606 | return is_empty; | ||
607 | } | ||
608 | |||
609 | static int mxuport_set_mcr(struct usb_serial_port *port, u8 mcr_state) | ||
610 | { | ||
611 | struct usb_serial *serial = port->serial; | ||
612 | int err; | ||
613 | |||
614 | dev_dbg(&port->dev, "%s - %02x\n", __func__, mcr_state); | ||
615 | |||
616 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_MCR, | ||
617 | mcr_state, port->port_number); | ||
618 | if (err) | ||
619 | dev_err(&port->dev, "%s - failed to change MCR\n", __func__); | ||
620 | |||
621 | return err; | ||
622 | } | ||
623 | |||
624 | static int mxuport_set_dtr(struct usb_serial_port *port, int on) | ||
625 | { | ||
626 | struct mxuport_port *mxport = usb_get_serial_port_data(port); | ||
627 | struct usb_serial *serial = port->serial; | ||
628 | int err; | ||
629 | |||
630 | mutex_lock(&mxport->mutex); | ||
631 | |||
632 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_DTR, | ||
633 | !!on, port->port_number); | ||
634 | if (!err) { | ||
635 | if (on) | ||
636 | mxport->mcr_state |= UART_MCR_DTR; | ||
637 | else | ||
638 | mxport->mcr_state &= ~UART_MCR_DTR; | ||
639 | } | ||
640 | |||
641 | mutex_unlock(&mxport->mutex); | ||
642 | |||
643 | return err; | ||
644 | } | ||
645 | |||
646 | static int mxuport_set_rts(struct usb_serial_port *port, u8 state) | ||
647 | { | ||
648 | struct mxuport_port *mxport = usb_get_serial_port_data(port); | ||
649 | struct usb_serial *serial = port->serial; | ||
650 | int err; | ||
651 | u8 mcr_state; | ||
652 | |||
653 | mutex_lock(&mxport->mutex); | ||
654 | mcr_state = mxport->mcr_state; | ||
655 | |||
656 | switch (state) { | ||
657 | case MX_RTS_DISABLE: | ||
658 | mcr_state &= ~UART_MCR_RTS; | ||
659 | break; | ||
660 | case MX_RTS_ENABLE: | ||
661 | mcr_state |= UART_MCR_RTS; | ||
662 | break; | ||
663 | case MX_RTS_HW: | ||
664 | /* | ||
665 | * Do not update mxport->mcr_state when doing hardware | ||
666 | * flow control. | ||
667 | */ | ||
668 | break; | ||
669 | default: | ||
670 | /* | ||
671 | * Should not happen, but somebody might try passing | ||
672 | * MX_RTS_NO_CHANGE, which is not valid. | ||
673 | */ | ||
674 | err = -EINVAL; | ||
675 | goto out; | ||
676 | } | ||
677 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_RTS, | ||
678 | state, port->port_number); | ||
679 | if (!err) | ||
680 | mxport->mcr_state = mcr_state; | ||
681 | |||
682 | out: | ||
683 | mutex_unlock(&mxport->mutex); | ||
684 | |||
685 | return err; | ||
686 | } | ||
687 | |||
688 | static void mxuport_dtr_rts(struct usb_serial_port *port, int on) | ||
689 | { | ||
690 | struct mxuport_port *mxport = usb_get_serial_port_data(port); | ||
691 | u8 mcr_state; | ||
692 | int err; | ||
693 | |||
694 | mutex_lock(&mxport->mutex); | ||
695 | mcr_state = mxport->mcr_state; | ||
696 | |||
697 | if (on) | ||
698 | mcr_state |= (UART_MCR_RTS | UART_MCR_DTR); | ||
699 | else | ||
700 | mcr_state &= ~(UART_MCR_RTS | UART_MCR_DTR); | ||
701 | |||
702 | err = mxuport_set_mcr(port, mcr_state); | ||
703 | if (!err) | ||
704 | mxport->mcr_state = mcr_state; | ||
705 | |||
706 | mutex_unlock(&mxport->mutex); | ||
707 | } | ||
708 | |||
709 | static int mxuport_tiocmset(struct tty_struct *tty, unsigned int set, | ||
710 | unsigned int clear) | ||
711 | { | ||
712 | struct usb_serial_port *port = tty->driver_data; | ||
713 | struct mxuport_port *mxport = usb_get_serial_port_data(port); | ||
714 | int err; | ||
715 | u8 mcr_state; | ||
716 | |||
717 | mutex_lock(&mxport->mutex); | ||
718 | mcr_state = mxport->mcr_state; | ||
719 | |||
720 | if (set & TIOCM_RTS) | ||
721 | mcr_state |= UART_MCR_RTS; | ||
722 | |||
723 | if (set & TIOCM_DTR) | ||
724 | mcr_state |= UART_MCR_DTR; | ||
725 | |||
726 | if (clear & TIOCM_RTS) | ||
727 | mcr_state &= ~UART_MCR_RTS; | ||
728 | |||
729 | if (clear & TIOCM_DTR) | ||
730 | mcr_state &= ~UART_MCR_DTR; | ||
731 | |||
732 | err = mxuport_set_mcr(port, mcr_state); | ||
733 | if (!err) | ||
734 | mxport->mcr_state = mcr_state; | ||
735 | |||
736 | mutex_unlock(&mxport->mutex); | ||
737 | |||
738 | return err; | ||
739 | } | ||
740 | |||
741 | static int mxuport_tiocmget(struct tty_struct *tty) | ||
742 | { | ||
743 | struct mxuport_port *mxport; | ||
744 | struct usb_serial_port *port = tty->driver_data; | ||
745 | unsigned int result; | ||
746 | unsigned long flags; | ||
747 | unsigned int msr; | ||
748 | unsigned int mcr; | ||
749 | |||
750 | mxport = usb_get_serial_port_data(port); | ||
751 | |||
752 | mutex_lock(&mxport->mutex); | ||
753 | spin_lock_irqsave(&mxport->spinlock, flags); | ||
754 | |||
755 | msr = mxport->msr_state; | ||
756 | mcr = mxport->mcr_state; | ||
757 | |||
758 | spin_unlock_irqrestore(&mxport->spinlock, flags); | ||
759 | mutex_unlock(&mxport->mutex); | ||
760 | |||
761 | result = (((mcr & UART_MCR_DTR) ? TIOCM_DTR : 0) | /* 0x002 */ | ||
762 | ((mcr & UART_MCR_RTS) ? TIOCM_RTS : 0) | /* 0x004 */ | ||
763 | ((msr & UART_MSR_CTS) ? TIOCM_CTS : 0) | /* 0x020 */ | ||
764 | ((msr & UART_MSR_DCD) ? TIOCM_CAR : 0) | /* 0x040 */ | ||
765 | ((msr & UART_MSR_RI) ? TIOCM_RI : 0) | /* 0x080 */ | ||
766 | ((msr & UART_MSR_DSR) ? TIOCM_DSR : 0)); /* 0x100 */ | ||
767 | |||
768 | dev_dbg(&port->dev, "%s - 0x%04x\n", __func__, result); | ||
769 | |||
770 | return result; | ||
771 | } | ||
772 | |||
773 | static int mxuport_set_termios_flow(struct tty_struct *tty, | ||
774 | struct ktermios *old_termios, | ||
775 | struct usb_serial_port *port, | ||
776 | struct usb_serial *serial) | ||
777 | { | ||
778 | u8 xon = START_CHAR(tty); | ||
779 | u8 xoff = STOP_CHAR(tty); | ||
780 | int enable; | ||
781 | int err; | ||
782 | u8 *buf; | ||
783 | u8 rts; | ||
784 | |||
785 | buf = kmalloc(2, GFP_KERNEL); | ||
786 | if (!buf) | ||
787 | return -ENOMEM; | ||
788 | |||
789 | /* S/W flow control settings */ | ||
790 | if (I_IXOFF(tty) || I_IXON(tty)) { | ||
791 | enable = 1; | ||
792 | buf[0] = xon; | ||
793 | buf[1] = xoff; | ||
794 | |||
795 | err = mxuport_send_ctrl_data_urb(serial, RQ_VENDOR_SET_CHARS, | ||
796 | 0, port->port_number, | ||
797 | buf, 2); | ||
798 | if (err) | ||
799 | goto out; | ||
800 | |||
801 | dev_dbg(&port->dev, "%s - XON = 0x%02x, XOFF = 0x%02x\n", | ||
802 | __func__, xon, xoff); | ||
803 | } else { | ||
804 | enable = 0; | ||
805 | } | ||
806 | |||
807 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_XONXOFF, | ||
808 | enable, port->port_number); | ||
809 | if (err) | ||
810 | goto out; | ||
811 | |||
812 | rts = MX_RTS_NO_CHANGE; | ||
813 | |||
814 | /* H/W flow control settings */ | ||
815 | if (!old_termios || | ||
816 | C_CRTSCTS(tty) != (old_termios->c_cflag & CRTSCTS)) { | ||
817 | if (C_CRTSCTS(tty)) | ||
818 | rts = MX_RTS_HW; | ||
819 | else | ||
820 | rts = MX_RTS_ENABLE; | ||
821 | } | ||
822 | |||
823 | if (C_BAUD(tty)) { | ||
824 | if (old_termios && (old_termios->c_cflag & CBAUD) == B0) { | ||
825 | /* Raise DTR and RTS */ | ||
826 | if (C_CRTSCTS(tty)) | ||
827 | rts = MX_RTS_HW; | ||
828 | else | ||
829 | rts = MX_RTS_ENABLE; | ||
830 | mxuport_set_dtr(port, 1); | ||
831 | } | ||
832 | } else { | ||
833 | /* Drop DTR and RTS */ | ||
834 | rts = MX_RTS_DISABLE; | ||
835 | mxuport_set_dtr(port, 0); | ||
836 | } | ||
837 | |||
838 | if (rts != MX_RTS_NO_CHANGE) | ||
839 | err = mxuport_set_rts(port, rts); | ||
840 | |||
841 | out: | ||
842 | kfree(buf); | ||
843 | return err; | ||
844 | } | ||
845 | |||
846 | static void mxuport_set_termios(struct tty_struct *tty, | ||
847 | struct usb_serial_port *port, | ||
848 | struct ktermios *old_termios) | ||
849 | { | ||
850 | struct usb_serial *serial = port->serial; | ||
851 | u8 *buf; | ||
852 | u8 data_bits; | ||
853 | u8 stop_bits; | ||
854 | u8 parity; | ||
855 | int baud; | ||
856 | int err; | ||
857 | |||
858 | if (old_termios && | ||
859 | !tty_termios_hw_change(&tty->termios, old_termios) && | ||
860 | tty->termios.c_iflag == old_termios->c_iflag) { | ||
861 | dev_dbg(&port->dev, "%s - nothing to change\n", __func__); | ||
862 | return; | ||
863 | } | ||
864 | |||
865 | buf = kmalloc(4, GFP_KERNEL); | ||
866 | if (!buf) | ||
867 | return; | ||
868 | |||
869 | /* Set data bit of termios */ | ||
870 | switch (C_CSIZE(tty)) { | ||
871 | case CS5: | ||
872 | data_bits = MX_WORDLENGTH_5; | ||
873 | break; | ||
874 | case CS6: | ||
875 | data_bits = MX_WORDLENGTH_6; | ||
876 | break; | ||
877 | case CS7: | ||
878 | data_bits = MX_WORDLENGTH_7; | ||
879 | break; | ||
880 | case CS8: | ||
881 | default: | ||
882 | data_bits = MX_WORDLENGTH_8; | ||
883 | break; | ||
884 | } | ||
885 | |||
886 | /* Set parity of termios */ | ||
887 | if (C_PARENB(tty)) { | ||
888 | if (C_CMSPAR(tty)) { | ||
889 | if (C_PARODD(tty)) | ||
890 | parity = MX_PARITY_MARK; | ||
891 | else | ||
892 | parity = MX_PARITY_SPACE; | ||
893 | } else { | ||
894 | if (C_PARODD(tty)) | ||
895 | parity = MX_PARITY_ODD; | ||
896 | else | ||
897 | parity = MX_PARITY_EVEN; | ||
898 | } | ||
899 | } else { | ||
900 | parity = MX_PARITY_NONE; | ||
901 | } | ||
902 | |||
903 | /* Set stop bit of termios */ | ||
904 | if (C_CSTOPB(tty)) | ||
905 | stop_bits = MX_STOP_BITS_2; | ||
906 | else | ||
907 | stop_bits = MX_STOP_BITS_1; | ||
908 | |||
909 | buf[0] = data_bits; | ||
910 | buf[1] = parity; | ||
911 | buf[2] = stop_bits; | ||
912 | buf[3] = 0; | ||
913 | |||
914 | err = mxuport_send_ctrl_data_urb(serial, RQ_VENDOR_SET_LINE, | ||
915 | 0, port->port_number, buf, 4); | ||
916 | if (err) | ||
917 | goto out; | ||
918 | |||
919 | err = mxuport_set_termios_flow(tty, old_termios, port, serial); | ||
920 | if (err) | ||
921 | goto out; | ||
922 | |||
923 | baud = tty_get_baud_rate(tty); | ||
924 | if (!baud) | ||
925 | baud = 9600; | ||
926 | |||
927 | /* Note: Little Endian */ | ||
928 | put_unaligned_le32(baud, buf); | ||
929 | |||
930 | err = mxuport_send_ctrl_data_urb(serial, RQ_VENDOR_SET_BAUD, | ||
931 | 0, port->port_number, | ||
932 | buf, 4); | ||
933 | if (err) | ||
934 | goto out; | ||
935 | |||
936 | dev_dbg(&port->dev, "baud_rate : %d\n", baud); | ||
937 | dev_dbg(&port->dev, "data_bits : %d\n", data_bits); | ||
938 | dev_dbg(&port->dev, "parity : %d\n", parity); | ||
939 | dev_dbg(&port->dev, "stop_bits : %d\n", stop_bits); | ||
940 | |||
941 | out: | ||
942 | kfree(buf); | ||
943 | } | ||
944 | |||
945 | /* | ||
946 | * Determine how many ports this device has dynamically. It will be | ||
947 | * called after the probe() callback is called, but before attach(). | ||
948 | */ | ||
949 | static int mxuport_calc_num_ports(struct usb_serial *serial) | ||
950 | { | ||
951 | unsigned long features = (unsigned long)usb_get_serial_data(serial); | ||
952 | |||
953 | if (features & MX_UPORT_2_PORT) | ||
954 | return 2; | ||
955 | if (features & MX_UPORT_4_PORT) | ||
956 | return 4; | ||
957 | if (features & MX_UPORT_8_PORT) | ||
958 | return 8; | ||
959 | if (features & MX_UPORT_16_PORT) | ||
960 | return 16; | ||
961 | |||
962 | return 0; | ||
963 | } | ||
964 | |||
965 | /* Get the version of the firmware currently running. */ | ||
966 | static int mxuport_get_fw_version(struct usb_serial *serial, u32 *version) | ||
967 | { | ||
968 | u8 *ver_buf; | ||
969 | int err; | ||
970 | |||
971 | ver_buf = kzalloc(4, GFP_KERNEL); | ||
972 | if (!ver_buf) | ||
973 | return -ENOMEM; | ||
974 | |||
975 | /* Get firmware version from SDRAM */ | ||
976 | err = mxuport_recv_ctrl_urb(serial, RQ_VENDOR_GET_VERSION, 0, 0, | ||
977 | ver_buf, 4); | ||
978 | if (err != 4) { | ||
979 | err = -EIO; | ||
980 | goto out; | ||
981 | } | ||
982 | |||
983 | *version = (ver_buf[0] << 16) | (ver_buf[1] << 8) | ver_buf[2]; | ||
984 | err = 0; | ||
985 | out: | ||
986 | kfree(ver_buf); | ||
987 | return err; | ||
988 | } | ||
989 | |||
990 | /* Given a firmware blob, download it to the device. */ | ||
991 | static int mxuport_download_fw(struct usb_serial *serial, | ||
992 | const struct firmware *fw_p) | ||
993 | { | ||
994 | u8 *fw_buf; | ||
995 | size_t txlen; | ||
996 | size_t fwidx; | ||
997 | int err; | ||
998 | |||
999 | fw_buf = kmalloc(DOWN_BLOCK_SIZE, GFP_KERNEL); | ||
1000 | if (!fw_buf) | ||
1001 | return -ENOMEM; | ||
1002 | |||
1003 | dev_dbg(&serial->interface->dev, "Starting firmware download...\n"); | ||
1004 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_START_FW_DOWN, 0, 0); | ||
1005 | if (err) | ||
1006 | goto out; | ||
1007 | |||
1008 | fwidx = 0; | ||
1009 | do { | ||
1010 | txlen = min_t(size_t, (fw_p->size - fwidx), DOWN_BLOCK_SIZE); | ||
1011 | |||
1012 | memcpy(fw_buf, &fw_p->data[fwidx], txlen); | ||
1013 | err = mxuport_send_ctrl_data_urb(serial, RQ_VENDOR_FW_DATA, | ||
1014 | 0, 0, fw_buf, txlen); | ||
1015 | if (err) { | ||
1016 | mxuport_send_ctrl_urb(serial, RQ_VENDOR_STOP_FW_DOWN, | ||
1017 | 0, 0); | ||
1018 | goto out; | ||
1019 | } | ||
1020 | |||
1021 | fwidx += txlen; | ||
1022 | usleep_range(1000, 2000); | ||
1023 | |||
1024 | } while (fwidx < fw_p->size); | ||
1025 | |||
1026 | msleep(1000); | ||
1027 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_STOP_FW_DOWN, 0, 0); | ||
1028 | if (err) | ||
1029 | goto out; | ||
1030 | |||
1031 | msleep(1000); | ||
1032 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_QUERY_FW_READY, 0, 0); | ||
1033 | |||
1034 | out: | ||
1035 | kfree(fw_buf); | ||
1036 | return err; | ||
1037 | } | ||
1038 | |||
1039 | static int mxuport_probe(struct usb_serial *serial, | ||
1040 | const struct usb_device_id *id) | ||
1041 | { | ||
1042 | u16 productid = le16_to_cpu(serial->dev->descriptor.idProduct); | ||
1043 | const struct firmware *fw_p = NULL; | ||
1044 | u32 version; | ||
1045 | int local_ver; | ||
1046 | char buf[32]; | ||
1047 | int err; | ||
1048 | |||
1049 | /* Load our firmware */ | ||
1050 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_QUERY_FW_CONFIG, 0, 0); | ||
1051 | if (err) { | ||
1052 | mxuport_send_ctrl_urb(serial, RQ_VENDOR_RESET_DEVICE, 0, 0); | ||
1053 | return err; | ||
1054 | } | ||
1055 | |||
1056 | err = mxuport_get_fw_version(serial, &version); | ||
1057 | if (err < 0) | ||
1058 | return err; | ||
1059 | |||
1060 | dev_dbg(&serial->interface->dev, "Device firmware version v%x.%x.%x\n", | ||
1061 | (version & 0xff0000) >> 16, | ||
1062 | (version & 0xff00) >> 8, | ||
1063 | (version & 0xff)); | ||
1064 | |||
1065 | snprintf(buf, sizeof(buf) - 1, "moxa/moxa-%04x.fw", productid); | ||
1066 | |||
1067 | err = request_firmware(&fw_p, buf, &serial->interface->dev); | ||
1068 | if (err) { | ||
1069 | dev_warn(&serial->interface->dev, "Firmware %s not found\n", | ||
1070 | buf); | ||
1071 | |||
1072 | /* Use the firmware already in the device */ | ||
1073 | err = 0; | ||
1074 | } else { | ||
1075 | local_ver = ((fw_p->data[VER_ADDR_1] << 16) | | ||
1076 | (fw_p->data[VER_ADDR_2] << 8) | | ||
1077 | fw_p->data[VER_ADDR_3]); | ||
1078 | dev_dbg(&serial->interface->dev, | ||
1079 | "Available firmware version v%x.%x.%x\n", | ||
1080 | fw_p->data[VER_ADDR_1], fw_p->data[VER_ADDR_2], | ||
1081 | fw_p->data[VER_ADDR_3]); | ||
1082 | if (local_ver > version) { | ||
1083 | err = mxuport_download_fw(serial, fw_p); | ||
1084 | if (err) | ||
1085 | goto out; | ||
1086 | err = mxuport_get_fw_version(serial, &version); | ||
1087 | if (err < 0) | ||
1088 | goto out; | ||
1089 | } | ||
1090 | } | ||
1091 | |||
1092 | dev_info(&serial->interface->dev, | ||
1093 | "Using device firmware version v%x.%x.%x\n", | ||
1094 | (version & 0xff0000) >> 16, | ||
1095 | (version & 0xff00) >> 8, | ||
1096 | (version & 0xff)); | ||
1097 | |||
1098 | /* | ||
1099 | * Contains the features of this hardware. Store away for | ||
1100 | * later use, eg, number of ports. | ||
1101 | */ | ||
1102 | usb_set_serial_data(serial, (void *)id->driver_info); | ||
1103 | out: | ||
1104 | if (fw_p) | ||
1105 | release_firmware(fw_p); | ||
1106 | return err; | ||
1107 | } | ||
1108 | |||
1109 | |||
1110 | static int mxuport_port_probe(struct usb_serial_port *port) | ||
1111 | { | ||
1112 | struct usb_serial *serial = port->serial; | ||
1113 | struct mxuport_port *mxport; | ||
1114 | int err; | ||
1115 | |||
1116 | mxport = devm_kzalloc(&port->dev, sizeof(struct mxuport_port), | ||
1117 | GFP_KERNEL); | ||
1118 | if (!mxport) | ||
1119 | return -ENOMEM; | ||
1120 | |||
1121 | mutex_init(&mxport->mutex); | ||
1122 | spin_lock_init(&mxport->spinlock); | ||
1123 | |||
1124 | /* Set the port private data */ | ||
1125 | usb_set_serial_port_data(port, mxport); | ||
1126 | |||
1127 | /* Set FIFO (Enable) */ | ||
1128 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_FIFO_DISABLE, | ||
1129 | 0, port->port_number); | ||
1130 | if (err) | ||
1131 | return err; | ||
1132 | |||
1133 | /* Set transmission mode (Hi-Performance) */ | ||
1134 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_HIGH_PERFOR, | ||
1135 | 0, port->port_number); | ||
1136 | if (err) | ||
1137 | return err; | ||
1138 | |||
1139 | /* Set interface (RS-232) */ | ||
1140 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_INTERFACE, | ||
1141 | MX_INT_RS232, | ||
1142 | port->port_number); | ||
1143 | if (err) | ||
1144 | return err; | ||
1145 | |||
1146 | return 0; | ||
1147 | } | ||
1148 | |||
1149 | static int mxuport_alloc_write_urb(struct usb_serial *serial, | ||
1150 | struct usb_serial_port *port, | ||
1151 | struct usb_serial_port *port0, | ||
1152 | int j) | ||
1153 | { | ||
1154 | struct usb_device *dev = interface_to_usbdev(serial->interface); | ||
1155 | |||
1156 | set_bit(j, &port->write_urbs_free); | ||
1157 | port->write_urbs[j] = usb_alloc_urb(0, GFP_KERNEL); | ||
1158 | if (!port->write_urbs[j]) | ||
1159 | return -ENOMEM; | ||
1160 | |||
1161 | port->bulk_out_buffers[j] = kmalloc(port0->bulk_out_size, GFP_KERNEL); | ||
1162 | if (!port->bulk_out_buffers[j]) | ||
1163 | return -ENOMEM; | ||
1164 | |||
1165 | usb_fill_bulk_urb(port->write_urbs[j], dev, | ||
1166 | usb_sndbulkpipe(dev, port->bulk_out_endpointAddress), | ||
1167 | port->bulk_out_buffers[j], | ||
1168 | port->bulk_out_size, | ||
1169 | serial->type->write_bulk_callback, | ||
1170 | port); | ||
1171 | return 0; | ||
1172 | } | ||
1173 | |||
1174 | |||
1175 | static int mxuport_alloc_write_urbs(struct usb_serial *serial, | ||
1176 | struct usb_serial_port *port, | ||
1177 | struct usb_serial_port *port0) | ||
1178 | { | ||
1179 | int j; | ||
1180 | int ret; | ||
1181 | |||
1182 | for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) { | ||
1183 | ret = mxuport_alloc_write_urb(serial, port, port0, j); | ||
1184 | if (ret) | ||
1185 | return ret; | ||
1186 | } | ||
1187 | return 0; | ||
1188 | } | ||
1189 | |||
1190 | |||
1191 | static int mxuport_attach(struct usb_serial *serial) | ||
1192 | { | ||
1193 | struct usb_serial_port *port0 = serial->port[0]; | ||
1194 | struct usb_serial_port *port1 = serial->port[1]; | ||
1195 | struct usb_serial_port *port; | ||
1196 | int err; | ||
1197 | int i; | ||
1198 | int j; | ||
1199 | |||
1200 | /* | ||
1201 | * Throw away all but the first allocated write URBs so we can | ||
1202 | * set them up again to fit the multiplexing scheme. | ||
1203 | */ | ||
1204 | for (i = 1; i < serial->num_bulk_out; ++i) { | ||
1205 | port = serial->port[i]; | ||
1206 | for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) { | ||
1207 | usb_free_urb(port->write_urbs[j]); | ||
1208 | kfree(port->bulk_out_buffers[j]); | ||
1209 | port->write_urbs[j] = NULL; | ||
1210 | port->bulk_out_buffers[j] = NULL; | ||
1211 | } | ||
1212 | port->write_urbs_free = 0; | ||
1213 | } | ||
1214 | |||
1215 | /* | ||
1216 | * All write data is sent over the first bulk out endpoint, | ||
1217 | * with an added header to indicate the port. Allocate URBs | ||
1218 | * for each port to the first bulk out endpoint. | ||
1219 | */ | ||
1220 | for (i = 1; i < serial->num_ports; ++i) { | ||
1221 | port = serial->port[i]; | ||
1222 | port->bulk_out_size = port0->bulk_out_size; | ||
1223 | port->bulk_out_endpointAddress = | ||
1224 | port0->bulk_out_endpointAddress; | ||
1225 | |||
1226 | err = mxuport_alloc_write_urbs(serial, port, port0); | ||
1227 | if (err) | ||
1228 | return err; | ||
1229 | |||
1230 | port->write_urb = port->write_urbs[0]; | ||
1231 | port->bulk_out_buffer = port->bulk_out_buffers[0]; | ||
1232 | |||
1233 | /* | ||
1234 | * Ensure each port has a fifo. The framework only | ||
1235 | * allocates a fifo to ports with a bulk out endpoint, | ||
1236 | * where as we need one for every port. | ||
1237 | */ | ||
1238 | if (!kfifo_initialized(&port->write_fifo)) { | ||
1239 | err = kfifo_alloc(&port->write_fifo, PAGE_SIZE, | ||
1240 | GFP_KERNEL); | ||
1241 | if (err) | ||
1242 | return err; | ||
1243 | } | ||
1244 | } | ||
1245 | |||
1246 | /* | ||
1247 | * All data from the ports is received on the first bulk in | ||
1248 | * endpoint, with a multiplex header. The second bulk in is | ||
1249 | * used for events. | ||
1250 | * | ||
1251 | * Start to read from the device. | ||
1252 | */ | ||
1253 | err = usb_serial_generic_submit_read_urbs(port0, GFP_KERNEL); | ||
1254 | if (err) | ||
1255 | return err; | ||
1256 | |||
1257 | err = usb_serial_generic_submit_read_urbs(port1, GFP_KERNEL); | ||
1258 | if (err) { | ||
1259 | usb_serial_generic_close(port0); | ||
1260 | return err; | ||
1261 | } | ||
1262 | |||
1263 | return 0; | ||
1264 | } | ||
1265 | |||
1266 | static int mxuport_open(struct tty_struct *tty, struct usb_serial_port *port) | ||
1267 | { | ||
1268 | struct mxuport_port *mxport = usb_get_serial_port_data(port); | ||
1269 | struct usb_serial *serial = port->serial; | ||
1270 | int err; | ||
1271 | |||
1272 | /* Set receive host (enable) */ | ||
1273 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_RX_HOST_EN, | ||
1274 | 1, port->port_number); | ||
1275 | if (err) | ||
1276 | return err; | ||
1277 | |||
1278 | err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_OPEN, | ||
1279 | 1, port->port_number); | ||
1280 | if (err) { | ||
1281 | mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_RX_HOST_EN, | ||
1282 | 0, port->port_number); | ||
1283 | return err; | ||
1284 | } | ||
1285 | |||
1286 | /* Initial port termios */ | ||
1287 | mxuport_set_termios(tty, port, NULL); | ||
1288 | |||
1289 | /* | ||
1290 | * TODO: use RQ_VENDOR_GET_MSR, once we know what it | ||
1291 | * returns. | ||
1292 | */ | ||
1293 | mxport->msr_state = 0; | ||
1294 | |||
1295 | return err; | ||
1296 | } | ||
1297 | |||
1298 | static void mxuport_close(struct usb_serial_port *port) | ||
1299 | { | ||
1300 | struct usb_serial *serial = port->serial; | ||
1301 | |||
1302 | mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_OPEN, 0, | ||
1303 | port->port_number); | ||
1304 | |||
1305 | mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_RX_HOST_EN, 0, | ||
1306 | port->port_number); | ||
1307 | } | ||
1308 | |||
1309 | /* Send a break to the port. */ | ||
1310 | static void mxuport_break_ctl(struct tty_struct *tty, int break_state) | ||
1311 | { | ||
1312 | struct usb_serial_port *port = tty->driver_data; | ||
1313 | struct usb_serial *serial = port->serial; | ||
1314 | int enable; | ||
1315 | |||
1316 | if (break_state == -1) { | ||
1317 | enable = 1; | ||
1318 | dev_dbg(&port->dev, "%s - sending break\n", __func__); | ||
1319 | } else { | ||
1320 | enable = 0; | ||
1321 | dev_dbg(&port->dev, "%s - clearing break\n", __func__); | ||
1322 | } | ||
1323 | |||
1324 | mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_BREAK, | ||
1325 | enable, port->port_number); | ||
1326 | } | ||
1327 | |||
1328 | static int mxuport_resume(struct usb_serial *serial) | ||
1329 | { | ||
1330 | struct usb_serial_port *port; | ||
1331 | int c = 0; | ||
1332 | int i; | ||
1333 | int r; | ||
1334 | |||
1335 | for (i = 0; i < 2; i++) { | ||
1336 | port = serial->port[i]; | ||
1337 | |||
1338 | r = usb_serial_generic_submit_read_urbs(port, GFP_NOIO); | ||
1339 | if (r < 0) | ||
1340 | c++; | ||
1341 | } | ||
1342 | |||
1343 | for (i = 0; i < serial->num_ports; i++) { | ||
1344 | port = serial->port[i]; | ||
1345 | if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) | ||
1346 | continue; | ||
1347 | |||
1348 | r = usb_serial_generic_write_start(port, GFP_NOIO); | ||
1349 | if (r < 0) | ||
1350 | c++; | ||
1351 | } | ||
1352 | |||
1353 | return c ? -EIO : 0; | ||
1354 | } | ||
1355 | |||
1356 | static struct usb_serial_driver mxuport_device = { | ||
1357 | .driver = { | ||
1358 | .owner = THIS_MODULE, | ||
1359 | .name = "mxuport", | ||
1360 | }, | ||
1361 | .description = "MOXA UPort", | ||
1362 | .id_table = mxuport_idtable, | ||
1363 | .num_ports = 0, | ||
1364 | .probe = mxuport_probe, | ||
1365 | .port_probe = mxuport_port_probe, | ||
1366 | .attach = mxuport_attach, | ||
1367 | .calc_num_ports = mxuport_calc_num_ports, | ||
1368 | .open = mxuport_open, | ||
1369 | .close = mxuport_close, | ||
1370 | .set_termios = mxuport_set_termios, | ||
1371 | .break_ctl = mxuport_break_ctl, | ||
1372 | .tx_empty = mxuport_tx_empty, | ||
1373 | .tiocmiwait = usb_serial_generic_tiocmiwait, | ||
1374 | .get_icount = usb_serial_generic_get_icount, | ||
1375 | .throttle = mxuport_throttle, | ||
1376 | .unthrottle = mxuport_unthrottle, | ||
1377 | .tiocmget = mxuport_tiocmget, | ||
1378 | .tiocmset = mxuport_tiocmset, | ||
1379 | .dtr_rts = mxuport_dtr_rts, | ||
1380 | .process_read_urb = mxuport_process_read_urb, | ||
1381 | .prepare_write_buffer = mxuport_prepare_write_buffer, | ||
1382 | .resume = mxuport_resume, | ||
1383 | }; | ||
1384 | |||
1385 | static struct usb_serial_driver *const serial_drivers[] = { | ||
1386 | &mxuport_device, NULL | ||
1387 | }; | ||
1388 | |||
1389 | module_usb_serial_driver(serial_drivers, mxuport_idtable); | ||
1390 | |||
1391 | MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>"); | ||
1392 | MODULE_AUTHOR("<support@moxa.com>"); | ||
1393 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/serial/navman.c b/drivers/usb/serial/navman.c index 38725fc8c2c8..2a97cdc078d5 100644 --- a/drivers/usb/serial/navman.c +++ b/drivers/usb/serial/navman.c | |||
@@ -14,7 +14,6 @@ | |||
14 | 14 | ||
15 | #include <linux/gfp.h> | 15 | #include <linux/gfp.h> |
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/init.h> | ||
18 | #include <linux/tty.h> | 17 | #include <linux/tty.h> |
19 | #include <linux/tty_flip.h> | 18 | #include <linux/tty_flip.h> |
20 | #include <linux/module.h> | 19 | #include <linux/module.h> |
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c index 5739bf6f7200..f6c6900bccf0 100644 --- a/drivers/usb/serial/omninet.c +++ b/drivers/usb/serial/omninet.c | |||
@@ -13,7 +13,6 @@ | |||
13 | 13 | ||
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/errno.h> | 15 | #include <linux/errno.h> |
16 | #include <linux/init.h> | ||
17 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
18 | #include <linux/tty.h> | 17 | #include <linux/tty.h> |
19 | #include <linux/tty_driver.h> | 18 | #include <linux/tty_driver.h> |
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c index cbe779f578f9..4856fb7e637e 100644 --- a/drivers/usb/serial/opticon.c +++ b/drivers/usb/serial/opticon.c | |||
@@ -12,7 +12,6 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/init.h> | ||
16 | #include <linux/tty.h> | 15 | #include <linux/tty.h> |
17 | #include <linux/tty_driver.h> | 16 | #include <linux/tty_driver.h> |
18 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
@@ -139,7 +138,7 @@ static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
139 | /* Clear RTS line */ | 138 | /* Clear RTS line */ |
140 | send_control_msg(port, CONTROL_RTS, 0); | 139 | send_control_msg(port, CONTROL_RTS, 0); |
141 | 140 | ||
142 | /* clear the halt status of the enpoint */ | 141 | /* clear the halt status of the endpoint */ |
143 | usb_clear_halt(port->serial->dev, port->read_urb->pipe); | 142 | usb_clear_halt(port->serial->dev, port->read_urb->pipe); |
144 | 143 | ||
145 | res = usb_serial_generic_open(tty, port); | 144 | res = usb_serial_generic_open(tty, port); |
@@ -200,15 +199,12 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
200 | 199 | ||
201 | buffer = kmalloc(count, GFP_ATOMIC); | 200 | buffer = kmalloc(count, GFP_ATOMIC); |
202 | if (!buffer) { | 201 | if (!buffer) { |
203 | dev_err(&port->dev, "out of memory\n"); | ||
204 | count = -ENOMEM; | 202 | count = -ENOMEM; |
205 | |||
206 | goto error_no_buffer; | 203 | goto error_no_buffer; |
207 | } | 204 | } |
208 | 205 | ||
209 | urb = usb_alloc_urb(0, GFP_ATOMIC); | 206 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
210 | if (!urb) { | 207 | if (!urb) { |
211 | dev_err(&port->dev, "no more free urbs\n"); | ||
212 | count = -ENOMEM; | 208 | count = -ENOMEM; |
213 | goto error_no_urb; | 209 | goto error_no_urb; |
214 | } | 210 | } |
@@ -217,11 +213,10 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
217 | 213 | ||
218 | usb_serial_debug_data(&port->dev, __func__, count, buffer); | 214 | usb_serial_debug_data(&port->dev, __func__, count, buffer); |
219 | 215 | ||
220 | /* The conncected devices do not have a bulk write endpoint, | 216 | /* The connected devices do not have a bulk write endpoint, |
221 | * to transmit data to de barcode device the control endpoint is used */ | 217 | * to transmit data to de barcode device the control endpoint is used */ |
222 | dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO); | 218 | dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO); |
223 | if (!dr) { | 219 | if (!dr) { |
224 | dev_err(&port->dev, "out of memory\n"); | ||
225 | count = -ENOMEM; | 220 | count = -ENOMEM; |
226 | goto error_no_dr; | 221 | goto error_no_dr; |
227 | } | 222 | } |
@@ -367,8 +362,6 @@ static int opticon_ioctl(struct tty_struct *tty, | |||
367 | { | 362 | { |
368 | struct usb_serial_port *port = tty->driver_data; | 363 | struct usb_serial_port *port = tty->driver_data; |
369 | 364 | ||
370 | dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd); | ||
371 | |||
372 | switch (cmd) { | 365 | switch (cmd) { |
373 | case TIOCGSERIAL: | 366 | case TIOCGSERIAL: |
374 | return get_serial_info(port, | 367 | return get_serial_info(port, |
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index cc7a24154490..5c86f57e4afa 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c | |||
@@ -320,6 +320,9 @@ static void option_instat_callback(struct urb *urb); | |||
320 | * It seems to contain a Qualcomm QSC6240/6290 chipset */ | 320 | * It seems to contain a Qualcomm QSC6240/6290 chipset */ |
321 | #define FOUR_G_SYSTEMS_PRODUCT_W14 0x9603 | 321 | #define FOUR_G_SYSTEMS_PRODUCT_W14 0x9603 |
322 | 322 | ||
323 | /* iBall 3.5G connect wireless modem */ | ||
324 | #define IBALL_3_5G_CONNECT 0x9605 | ||
325 | |||
323 | /* Zoom */ | 326 | /* Zoom */ |
324 | #define ZOOM_PRODUCT_4597 0x9607 | 327 | #define ZOOM_PRODUCT_4597 0x9607 |
325 | 328 | ||
@@ -1447,6 +1450,17 @@ static const struct usb_device_id option_ids[] = { | |||
1447 | .driver_info = (kernel_ulong_t)&net_intf3_blacklist }, | 1450 | .driver_info = (kernel_ulong_t)&net_intf3_blacklist }, |
1448 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0178, 0xff, 0xff, 0xff), | 1451 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0178, 0xff, 0xff, 0xff), |
1449 | .driver_info = (kernel_ulong_t)&net_intf3_blacklist }, | 1452 | .driver_info = (kernel_ulong_t)&net_intf3_blacklist }, |
1453 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xffe9, 0xff, 0xff, 0xff) }, | ||
1454 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff8b, 0xff, 0xff, 0xff) }, | ||
1455 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff8c, 0xff, 0xff, 0xff) }, | ||
1456 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff8d, 0xff, 0xff, 0xff) }, | ||
1457 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff8e, 0xff, 0xff, 0xff) }, | ||
1458 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff8f, 0xff, 0xff, 0xff) }, | ||
1459 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff90, 0xff, 0xff, 0xff) }, | ||
1460 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff91, 0xff, 0xff, 0xff) }, | ||
1461 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff92, 0xff, 0xff, 0xff) }, | ||
1462 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff93, 0xff, 0xff, 0xff) }, | ||
1463 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff94, 0xff, 0xff, 0xff) }, | ||
1450 | 1464 | ||
1451 | /* NOTE: most ZTE CDMA devices should be driven by zte_ev, not option */ | 1465 | /* NOTE: most ZTE CDMA devices should be driven by zte_ev, not option */ |
1452 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MC2718, 0xff, 0xff, 0xff), | 1466 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MC2718, 0xff, 0xff, 0xff), |
@@ -1489,6 +1503,7 @@ static const struct usb_device_id option_ids[] = { | |||
1489 | .driver_info = (kernel_ulong_t)&four_g_w14_blacklist | 1503 | .driver_info = (kernel_ulong_t)&four_g_w14_blacklist |
1490 | }, | 1504 | }, |
1491 | { USB_DEVICE(LONGCHEER_VENDOR_ID, ZOOM_PRODUCT_4597) }, | 1505 | { USB_DEVICE(LONGCHEER_VENDOR_ID, ZOOM_PRODUCT_4597) }, |
1506 | { USB_DEVICE(LONGCHEER_VENDOR_ID, IBALL_3_5G_CONNECT) }, | ||
1492 | { USB_DEVICE(HAIER_VENDOR_ID, HAIER_PRODUCT_CE100) }, | 1507 | { USB_DEVICE(HAIER_VENDOR_ID, HAIER_PRODUCT_CE100) }, |
1493 | /* Pirelli */ | 1508 | /* Pirelli */ |
1494 | { USB_DEVICE_INTERFACE_CLASS(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_C100_1, 0xff) }, | 1509 | { USB_DEVICE_INTERFACE_CLASS(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_C100_1, 0xff) }, |
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c index a2080ac7b7e5..a4b88bc038b6 100644 --- a/drivers/usb/serial/oti6858.c +++ b/drivers/usb/serial/oti6858.c | |||
@@ -39,7 +39,6 @@ | |||
39 | 39 | ||
40 | #include <linux/kernel.h> | 40 | #include <linux/kernel.h> |
41 | #include <linux/errno.h> | 41 | #include <linux/errno.h> |
42 | #include <linux/init.h> | ||
43 | #include <linux/slab.h> | 42 | #include <linux/slab.h> |
44 | #include <linux/tty.h> | 43 | #include <linux/tty.h> |
45 | #include <linux/tty_driver.h> | 44 | #include <linux/tty_driver.h> |
@@ -103,6 +102,7 @@ struct oti6858_control_pkt { | |||
103 | #define TX_BUFFER_EMPTIED 0x09 | 102 | #define TX_BUFFER_EMPTIED 0x09 |
104 | u8 pin_state; | 103 | u8 pin_state; |
105 | #define PIN_MASK 0x3f | 104 | #define PIN_MASK 0x3f |
105 | #define PIN_MSR_MASK 0x1b | ||
106 | #define PIN_RTS 0x20 /* output pin */ | 106 | #define PIN_RTS 0x20 /* output pin */ |
107 | #define PIN_CTS 0x10 /* input pin, active low */ | 107 | #define PIN_CTS 0x10 /* input pin, active low */ |
108 | #define PIN_DSR 0x08 /* input pin, active low */ | 108 | #define PIN_DSR 0x08 /* input pin, active low */ |
@@ -134,7 +134,6 @@ static int oti6858_chars_in_buffer(struct tty_struct *tty); | |||
134 | static int oti6858_tiocmget(struct tty_struct *tty); | 134 | static int oti6858_tiocmget(struct tty_struct *tty); |
135 | static int oti6858_tiocmset(struct tty_struct *tty, | 135 | static int oti6858_tiocmset(struct tty_struct *tty, |
136 | unsigned int set, unsigned int clear); | 136 | unsigned int set, unsigned int clear); |
137 | static int oti6858_tiocmiwait(struct tty_struct *tty, unsigned long arg); | ||
138 | static int oti6858_port_probe(struct usb_serial_port *port); | 137 | static int oti6858_port_probe(struct usb_serial_port *port); |
139 | static int oti6858_port_remove(struct usb_serial_port *port); | 138 | static int oti6858_port_remove(struct usb_serial_port *port); |
140 | 139 | ||
@@ -153,7 +152,7 @@ static struct usb_serial_driver oti6858_device = { | |||
153 | .init_termios = oti6858_init_termios, | 152 | .init_termios = oti6858_init_termios, |
154 | .tiocmget = oti6858_tiocmget, | 153 | .tiocmget = oti6858_tiocmget, |
155 | .tiocmset = oti6858_tiocmset, | 154 | .tiocmset = oti6858_tiocmset, |
156 | .tiocmiwait = oti6858_tiocmiwait, | 155 | .tiocmiwait = usb_serial_generic_tiocmiwait, |
157 | .read_bulk_callback = oti6858_read_bulk_callback, | 156 | .read_bulk_callback = oti6858_read_bulk_callback, |
158 | .read_int_callback = oti6858_read_int_callback, | 157 | .read_int_callback = oti6858_read_int_callback, |
159 | .write_bulk_callback = oti6858_write_bulk_callback, | 158 | .write_bulk_callback = oti6858_write_bulk_callback, |
@@ -200,8 +199,7 @@ static void setup_line(struct work_struct *work) | |||
200 | int result; | 199 | int result; |
201 | 200 | ||
202 | new_setup = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL); | 201 | new_setup = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL); |
203 | if (new_setup == NULL) { | 202 | if (!new_setup) { |
204 | dev_err(&port->dev, "%s(): out of memory!\n", __func__); | ||
205 | /* we will try again */ | 203 | /* we will try again */ |
206 | schedule_delayed_work(&priv->delayed_setup_work, | 204 | schedule_delayed_work(&priv->delayed_setup_work, |
207 | msecs_to_jiffies(2)); | 205 | msecs_to_jiffies(2)); |
@@ -287,11 +285,9 @@ static void send_data(struct work_struct *work) | |||
287 | 285 | ||
288 | if (count != 0) { | 286 | if (count != 0) { |
289 | allow = kmalloc(1, GFP_KERNEL); | 287 | allow = kmalloc(1, GFP_KERNEL); |
290 | if (!allow) { | 288 | if (!allow) |
291 | dev_err_console(port, "%s(): kmalloc failed\n", | ||
292 | __func__); | ||
293 | return; | 289 | return; |
294 | } | 290 | |
295 | result = usb_control_msg(port->serial->dev, | 291 | result = usb_control_msg(port->serial->dev, |
296 | usb_rcvctrlpipe(port->serial->dev, 0), | 292 | usb_rcvctrlpipe(port->serial->dev, 0), |
297 | OTI6858_REQ_T_CHECK_TXBUFF, | 293 | OTI6858_REQ_T_CHECK_TXBUFF, |
@@ -517,10 +513,8 @@ static int oti6858_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
517 | usb_clear_halt(serial->dev, port->read_urb->pipe); | 513 | usb_clear_halt(serial->dev, port->read_urb->pipe); |
518 | 514 | ||
519 | buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL); | 515 | buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL); |
520 | if (buf == NULL) { | 516 | if (!buf) |
521 | dev_err(&port->dev, "%s(): out of memory!\n", __func__); | ||
522 | return -ENOMEM; | 517 | return -ENOMEM; |
523 | } | ||
524 | 518 | ||
525 | result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | 519 | result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), |
526 | OTI6858_REQ_T_GET_STATUS, | 520 | OTI6858_REQ_T_GET_STATUS, |
@@ -647,46 +641,6 @@ static int oti6858_tiocmget(struct tty_struct *tty) | |||
647 | return result; | 641 | return result; |
648 | } | 642 | } |
649 | 643 | ||
650 | static int oti6858_tiocmiwait(struct tty_struct *tty, unsigned long arg) | ||
651 | { | ||
652 | struct usb_serial_port *port = tty->driver_data; | ||
653 | struct oti6858_private *priv = usb_get_serial_port_data(port); | ||
654 | unsigned long flags; | ||
655 | unsigned int prev, status; | ||
656 | unsigned int changed; | ||
657 | |||
658 | spin_lock_irqsave(&priv->lock, flags); | ||
659 | prev = priv->status.pin_state; | ||
660 | spin_unlock_irqrestore(&priv->lock, flags); | ||
661 | |||
662 | while (1) { | ||
663 | wait_event_interruptible(port->port.delta_msr_wait, | ||
664 | port->serial->disconnected || | ||
665 | priv->status.pin_state != prev); | ||
666 | if (signal_pending(current)) | ||
667 | return -ERESTARTSYS; | ||
668 | |||
669 | if (port->serial->disconnected) | ||
670 | return -EIO; | ||
671 | |||
672 | spin_lock_irqsave(&priv->lock, flags); | ||
673 | status = priv->status.pin_state & PIN_MASK; | ||
674 | spin_unlock_irqrestore(&priv->lock, flags); | ||
675 | |||
676 | changed = prev ^ status; | ||
677 | /* FIXME: check if this is correct (active high/low) */ | ||
678 | if (((arg & TIOCM_RNG) && (changed & PIN_RI)) || | ||
679 | ((arg & TIOCM_DSR) && (changed & PIN_DSR)) || | ||
680 | ((arg & TIOCM_CD) && (changed & PIN_DCD)) || | ||
681 | ((arg & TIOCM_CTS) && (changed & PIN_CTS))) | ||
682 | return 0; | ||
683 | prev = status; | ||
684 | } | ||
685 | |||
686 | /* NOTREACHED */ | ||
687 | return 0; | ||
688 | } | ||
689 | |||
690 | static void oti6858_read_int_callback(struct urb *urb) | 644 | static void oti6858_read_int_callback(struct urb *urb) |
691 | { | 645 | { |
692 | struct usb_serial_port *port = urb->context; | 646 | struct usb_serial_port *port = urb->context; |
@@ -744,8 +698,21 @@ static void oti6858_read_int_callback(struct urb *urb) | |||
744 | } | 698 | } |
745 | 699 | ||
746 | if (!priv->transient) { | 700 | if (!priv->transient) { |
747 | if (xs->pin_state != priv->status.pin_state) | 701 | u8 delta = xs->pin_state ^ priv->status.pin_state; |
702 | |||
703 | if (delta & PIN_MSR_MASK) { | ||
704 | if (delta & PIN_CTS) | ||
705 | port->icount.cts++; | ||
706 | if (delta & PIN_DSR) | ||
707 | port->icount.dsr++; | ||
708 | if (delta & PIN_RI) | ||
709 | port->icount.rng++; | ||
710 | if (delta & PIN_DCD) | ||
711 | port->icount.dcd++; | ||
712 | |||
748 | wake_up_interruptible(&port->port.delta_msr_wait); | 713 | wake_up_interruptible(&port->port.delta_msr_wait); |
714 | } | ||
715 | |||
749 | memcpy(&priv->status, xs, OTI6858_CTRL_PKT_SIZE); | 716 | memcpy(&priv->status, xs, OTI6858_CTRL_PKT_SIZE); |
750 | } | 717 | } |
751 | 718 | ||
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 1e3318dfa1cb..2e22fc22c382 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c | |||
@@ -12,12 +12,10 @@ | |||
12 | * | 12 | * |
13 | * See Documentation/usb/usb-serial.txt for more information on using this | 13 | * See Documentation/usb/usb-serial.txt for more information on using this |
14 | * driver | 14 | * driver |
15 | * | ||
16 | */ | 15 | */ |
17 | 16 | ||
18 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
19 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
20 | #include <linux/init.h> | ||
21 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
22 | #include <linux/tty.h> | 20 | #include <linux/tty.h> |
23 | #include <linux/tty_driver.h> | 21 | #include <linux/tty_driver.h> |
@@ -32,10 +30,9 @@ | |||
32 | #include <asm/unaligned.h> | 30 | #include <asm/unaligned.h> |
33 | #include "pl2303.h" | 31 | #include "pl2303.h" |
34 | 32 | ||
35 | /* | 33 | |
36 | * Version Information | 34 | #define PL2303_QUIRK_UART_STATE_IDX0 BIT(0) |
37 | */ | 35 | #define PL2303_QUIRK_LEGACY BIT(1) |
38 | #define DRIVER_DESC "Prolific PL2303 USB to serial adaptor driver" | ||
39 | 36 | ||
40 | static const struct usb_device_id id_table[] = { | 37 | static const struct usb_device_id id_table[] = { |
41 | { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) }, | 38 | { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) }, |
@@ -64,9 +61,12 @@ static const struct usb_device_id id_table[] = { | |||
64 | { USB_DEVICE(SITECOM_VENDOR_ID, SITECOM_PRODUCT_ID) }, | 61 | { USB_DEVICE(SITECOM_VENDOR_ID, SITECOM_PRODUCT_ID) }, |
65 | { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_ID) }, | 62 | { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_ID) }, |
66 | { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_ID) }, | 63 | { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_ID) }, |
67 | { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_SX1) }, | 64 | { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_SX1), |
68 | { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X65) }, | 65 | .driver_info = PL2303_QUIRK_UART_STATE_IDX0 }, |
69 | { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X75) }, | 66 | { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X65), |
67 | .driver_info = PL2303_QUIRK_UART_STATE_IDX0 }, | ||
68 | { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X75), | ||
69 | .driver_info = PL2303_QUIRK_UART_STATE_IDX0 }, | ||
70 | { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_EF81) }, | 70 | { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_EF81) }, |
71 | { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_ID_S81) }, /* Benq/Siemens S81 */ | 71 | { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_ID_S81) }, /* Benq/Siemens S81 */ |
72 | { USB_DEVICE(SYNTECH_VENDOR_ID, SYNTECH_PRODUCT_ID) }, | 72 | { USB_DEVICE(SYNTECH_VENDOR_ID, SYNTECH_PRODUCT_ID) }, |
@@ -116,7 +116,8 @@ MODULE_DEVICE_TABLE(usb, id_table); | |||
116 | #define VENDOR_READ_REQUEST_TYPE 0xc0 | 116 | #define VENDOR_READ_REQUEST_TYPE 0xc0 |
117 | #define VENDOR_READ_REQUEST 0x01 | 117 | #define VENDOR_READ_REQUEST 0x01 |
118 | 118 | ||
119 | #define UART_STATE 0x08 | 119 | #define UART_STATE_INDEX 8 |
120 | #define UART_STATE_MSR_MASK 0x8b | ||
120 | #define UART_STATE_TRANSIENT_MASK 0x74 | 121 | #define UART_STATE_TRANSIENT_MASK 0x74 |
121 | #define UART_DCD 0x01 | 122 | #define UART_DCD 0x01 |
122 | #define UART_DSR 0x02 | 123 | #define UART_DSR 0x02 |
@@ -129,98 +130,142 @@ MODULE_DEVICE_TABLE(usb, id_table); | |||
129 | 130 | ||
130 | 131 | ||
131 | enum pl2303_type { | 132 | enum pl2303_type { |
132 | type_0, /* don't know the difference between type 0 and */ | 133 | TYPE_01, /* Type 0 and 1 (difference unknown) */ |
133 | type_1, /* type 1, until someone from prolific tells us... */ | 134 | TYPE_HX, /* HX version of the pl2303 chip */ |
134 | HX, /* HX version of the pl2303 chip */ | 135 | TYPE_COUNT |
136 | }; | ||
137 | |||
138 | struct pl2303_type_data { | ||
139 | speed_t max_baud_rate; | ||
140 | unsigned long quirks; | ||
135 | }; | 141 | }; |
136 | 142 | ||
137 | struct pl2303_serial_private { | 143 | struct pl2303_serial_private { |
138 | enum pl2303_type type; | 144 | const struct pl2303_type_data *type; |
145 | unsigned long quirks; | ||
139 | }; | 146 | }; |
140 | 147 | ||
141 | struct pl2303_private { | 148 | struct pl2303_private { |
142 | spinlock_t lock; | 149 | spinlock_t lock; |
143 | u8 line_control; | 150 | u8 line_control; |
144 | u8 line_status; | 151 | u8 line_status; |
152 | |||
153 | u8 line_settings[7]; | ||
154 | }; | ||
155 | |||
156 | static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = { | ||
157 | [TYPE_01] = { | ||
158 | .max_baud_rate = 1228800, | ||
159 | .quirks = PL2303_QUIRK_LEGACY, | ||
160 | }, | ||
145 | }; | 161 | }; |
146 | 162 | ||
147 | static int pl2303_vendor_read(__u16 value, __u16 index, | 163 | static int pl2303_vendor_read(struct usb_serial *serial, u16 value, |
148 | struct usb_serial *serial, unsigned char *buf) | 164 | unsigned char buf[1]) |
149 | { | 165 | { |
150 | int res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | 166 | struct device *dev = &serial->interface->dev; |
167 | int res; | ||
168 | |||
169 | res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | ||
151 | VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE, | 170 | VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE, |
152 | value, index, buf, 1, 100); | 171 | value, 0, buf, 1, 100); |
153 | dev_dbg(&serial->interface->dev, "0x%x:0x%x:0x%x:0x%x %d - %x\n", | 172 | if (res != 1) { |
154 | VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, value, index, | 173 | dev_err(dev, "%s - failed to read [%04x]: %d\n", __func__, |
155 | res, buf[0]); | 174 | value, res); |
156 | return res; | 175 | if (res >= 0) |
176 | res = -EIO; | ||
177 | |||
178 | return res; | ||
179 | } | ||
180 | |||
181 | dev_dbg(dev, "%s - [%04x] = %02x\n", __func__, value, buf[0]); | ||
182 | |||
183 | return 0; | ||
157 | } | 184 | } |
158 | 185 | ||
159 | static int pl2303_vendor_write(__u16 value, __u16 index, | 186 | static int pl2303_vendor_write(struct usb_serial *serial, u16 value, u16 index) |
160 | struct usb_serial *serial) | ||
161 | { | 187 | { |
162 | int res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | 188 | struct device *dev = &serial->interface->dev; |
189 | int res; | ||
190 | |||
191 | dev_dbg(dev, "%s - [%04x] = %02x\n", __func__, value, index); | ||
192 | |||
193 | res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
163 | VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE, | 194 | VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE, |
164 | value, index, NULL, 0, 100); | 195 | value, index, NULL, 0, 100); |
165 | dev_dbg(&serial->interface->dev, "0x%x:0x%x:0x%x:0x%x %d\n", | 196 | if (res) { |
166 | VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, value, index, | 197 | dev_err(dev, "%s - failed to write [%04x]: %d\n", __func__, |
167 | res); | 198 | value, res); |
168 | return res; | 199 | return res; |
200 | } | ||
201 | |||
202 | return 0; | ||
203 | } | ||
204 | |||
205 | static int pl2303_probe(struct usb_serial *serial, | ||
206 | const struct usb_device_id *id) | ||
207 | { | ||
208 | usb_set_serial_data(serial, (void *)id->driver_info); | ||
209 | |||
210 | return 0; | ||
169 | } | 211 | } |
170 | 212 | ||
171 | static int pl2303_startup(struct usb_serial *serial) | 213 | static int pl2303_startup(struct usb_serial *serial) |
172 | { | 214 | { |
173 | struct pl2303_serial_private *spriv; | 215 | struct pl2303_serial_private *spriv; |
174 | enum pl2303_type type = type_0; | 216 | enum pl2303_type type = TYPE_01; |
175 | unsigned char *buf; | 217 | unsigned char *buf; |
176 | 218 | ||
177 | spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); | 219 | spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); |
178 | if (!spriv) | 220 | if (!spriv) |
179 | return -ENOMEM; | 221 | return -ENOMEM; |
180 | 222 | ||
181 | buf = kmalloc(10, GFP_KERNEL); | 223 | buf = kmalloc(1, GFP_KERNEL); |
182 | if (!buf) { | 224 | if (!buf) { |
183 | kfree(spriv); | 225 | kfree(spriv); |
184 | return -ENOMEM; | 226 | return -ENOMEM; |
185 | } | 227 | } |
186 | 228 | ||
187 | if (serial->dev->descriptor.bDeviceClass == 0x02) | 229 | if (serial->dev->descriptor.bDeviceClass == 0x02) |
188 | type = type_0; | 230 | type = TYPE_01; /* type 0 */ |
189 | else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40) | 231 | else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40) |
190 | type = HX; | 232 | type = TYPE_HX; |
191 | else if (serial->dev->descriptor.bDeviceClass == 0x00) | 233 | else if (serial->dev->descriptor.bDeviceClass == 0x00) |
192 | type = type_1; | 234 | type = TYPE_01; /* type 1 */ |
193 | else if (serial->dev->descriptor.bDeviceClass == 0xFF) | 235 | else if (serial->dev->descriptor.bDeviceClass == 0xFF) |
194 | type = type_1; | 236 | type = TYPE_01; /* type 1 */ |
195 | dev_dbg(&serial->interface->dev, "device type: %d\n", type); | 237 | dev_dbg(&serial->interface->dev, "device type: %d\n", type); |
196 | 238 | ||
197 | spriv->type = type; | 239 | spriv->type = &pl2303_type_data[type]; |
240 | spriv->quirks = (unsigned long)usb_get_serial_data(serial); | ||
241 | spriv->quirks |= spriv->type->quirks; | ||
242 | |||
198 | usb_set_serial_data(serial, spriv); | 243 | usb_set_serial_data(serial, spriv); |
199 | 244 | ||
200 | pl2303_vendor_read(0x8484, 0, serial, buf); | 245 | pl2303_vendor_read(serial, 0x8484, buf); |
201 | pl2303_vendor_write(0x0404, 0, serial); | 246 | pl2303_vendor_write(serial, 0x0404, 0); |
202 | pl2303_vendor_read(0x8484, 0, serial, buf); | 247 | pl2303_vendor_read(serial, 0x8484, buf); |
203 | pl2303_vendor_read(0x8383, 0, serial, buf); | 248 | pl2303_vendor_read(serial, 0x8383, buf); |
204 | pl2303_vendor_read(0x8484, 0, serial, buf); | 249 | pl2303_vendor_read(serial, 0x8484, buf); |
205 | pl2303_vendor_write(0x0404, 1, serial); | 250 | pl2303_vendor_write(serial, 0x0404, 1); |
206 | pl2303_vendor_read(0x8484, 0, serial, buf); | 251 | pl2303_vendor_read(serial, 0x8484, buf); |
207 | pl2303_vendor_read(0x8383, 0, serial, buf); | 252 | pl2303_vendor_read(serial, 0x8383, buf); |
208 | pl2303_vendor_write(0, 1, serial); | 253 | pl2303_vendor_write(serial, 0, 1); |
209 | pl2303_vendor_write(1, 0, serial); | 254 | pl2303_vendor_write(serial, 1, 0); |
210 | if (type == HX) | 255 | if (spriv->quirks & PL2303_QUIRK_LEGACY) |
211 | pl2303_vendor_write(2, 0x44, serial); | 256 | pl2303_vendor_write(serial, 2, 0x24); |
212 | else | 257 | else |
213 | pl2303_vendor_write(2, 0x24, serial); | 258 | pl2303_vendor_write(serial, 2, 0x44); |
214 | 259 | ||
215 | kfree(buf); | 260 | kfree(buf); |
261 | |||
216 | return 0; | 262 | return 0; |
217 | } | 263 | } |
218 | 264 | ||
219 | static void pl2303_release(struct usb_serial *serial) | 265 | static void pl2303_release(struct usb_serial *serial) |
220 | { | 266 | { |
221 | struct pl2303_serial_private *spriv; | 267 | struct pl2303_serial_private *spriv = usb_get_serial_data(serial); |
222 | 268 | ||
223 | spriv = usb_get_serial_data(serial); | ||
224 | kfree(spriv); | 269 | kfree(spriv); |
225 | } | 270 | } |
226 | 271 | ||
@@ -243,9 +288,8 @@ static int pl2303_port_probe(struct usb_serial_port *port) | |||
243 | 288 | ||
244 | static int pl2303_port_remove(struct usb_serial_port *port) | 289 | static int pl2303_port_remove(struct usb_serial_port *port) |
245 | { | 290 | { |
246 | struct pl2303_private *priv; | 291 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
247 | 292 | ||
248 | priv = usb_get_serial_port_data(port); | ||
249 | kfree(priv); | 293 | kfree(priv); |
250 | 294 | ||
251 | return 0; | 295 | return 0; |
@@ -256,39 +300,31 @@ static int pl2303_set_control_lines(struct usb_serial_port *port, u8 value) | |||
256 | struct usb_device *dev = port->serial->dev; | 300 | struct usb_device *dev = port->serial->dev; |
257 | int retval; | 301 | int retval; |
258 | 302 | ||
303 | dev_dbg(&port->dev, "%s - %02x\n", __func__, value); | ||
304 | |||
259 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 305 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
260 | SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, | 306 | SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, |
261 | value, 0, NULL, 0, 100); | 307 | value, 0, NULL, 0, 100); |
262 | dev_dbg(&port->dev, "%s - value = %d, retval = %d\n", __func__, | 308 | if (retval) |
263 | value, retval); | 309 | dev_err(&port->dev, "%s - failed: %d\n", __func__, retval); |
310 | |||
264 | return retval; | 311 | return retval; |
265 | } | 312 | } |
266 | 313 | ||
267 | static void pl2303_encode_baudrate(struct tty_struct *tty, | 314 | /* |
268 | struct usb_serial_port *port, | 315 | * Returns the nearest supported baud rate that can be set directly without |
269 | u8 buf[4]) | 316 | * using divisors. |
317 | */ | ||
318 | static speed_t pl2303_get_supported_baud_rate(speed_t baud) | ||
270 | { | 319 | { |
271 | const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600, | 320 | static const speed_t baud_sup[] = { |
272 | 4800, 7200, 9600, 14400, 19200, 28800, 38400, | 321 | 75, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600, |
273 | 57600, 115200, 230400, 460800, 500000, 614400, | 322 | 14400, 19200, 28800, 38400, 57600, 115200, 230400, 460800, |
274 | 921600, 1228800, 2457600, 3000000, 6000000 }; | 323 | 614400, 921600, 1228800, 2457600, 3000000, 6000000 |
275 | 324 | }; | |
276 | struct usb_serial *serial = port->serial; | ||
277 | struct pl2303_serial_private *spriv = usb_get_serial_data(serial); | ||
278 | int baud; | ||
279 | int i; | ||
280 | 325 | ||
281 | /* | 326 | unsigned i; |
282 | * NOTE: Only the values defined in baud_sup are supported! | ||
283 | * => if unsupported values are set, the PL2303 seems to use | ||
284 | * 9600 baud (at least my PL2303X always does) | ||
285 | */ | ||
286 | baud = tty_get_baud_rate(tty); | ||
287 | dev_dbg(&port->dev, "baud requested = %d\n", baud); | ||
288 | if (!baud) | ||
289 | return; | ||
290 | 327 | ||
291 | /* Set baudrate to nearest supported value */ | ||
292 | for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) { | 328 | for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) { |
293 | if (baud_sup[i] > baud) | 329 | if (baud_sup[i] > baud) |
294 | break; | 330 | break; |
@@ -301,31 +337,120 @@ static void pl2303_encode_baudrate(struct tty_struct *tty, | |||
301 | else | 337 | else |
302 | baud = baud_sup[i]; | 338 | baud = baud_sup[i]; |
303 | 339 | ||
304 | /* type_0, type_1 only support up to 1228800 baud */ | 340 | return baud; |
305 | if (spriv->type != HX) | 341 | } |
306 | baud = min_t(int, baud, 1228800); | ||
307 | 342 | ||
308 | if (baud <= 115200) { | 343 | /* |
309 | put_unaligned_le32(baud, buf); | 344 | * NOTE: If unsupported baud rates are set directly, the PL2303 seems to |
310 | } else { | 345 | * use 9600 baud. |
311 | /* | 346 | */ |
312 | * Apparently the formula for higher speeds is: | 347 | static speed_t pl2303_encode_baud_rate_direct(unsigned char buf[4], |
313 | * baudrate = 12M * 32 / (2^buf[1]) / buf[0] | 348 | speed_t baud) |
314 | */ | 349 | { |
315 | unsigned tmp = 12000000 * 32 / baud; | 350 | put_unaligned_le32(baud, buf); |
316 | buf[3] = 0x80; | 351 | |
317 | buf[2] = 0; | 352 | return baud; |
318 | buf[1] = (tmp >= 256); | 353 | } |
319 | while (tmp >= 256) { | 354 | |
320 | tmp >>= 2; | 355 | static speed_t pl2303_encode_baud_rate_divisor(unsigned char buf[4], |
321 | buf[1] <<= 1; | 356 | speed_t baud) |
322 | } | 357 | { |
323 | buf[0] = tmp; | 358 | unsigned int tmp; |
359 | |||
360 | /* | ||
361 | * Apparently the formula is: | ||
362 | * baudrate = 12M * 32 / (2^buf[1]) / buf[0] | ||
363 | */ | ||
364 | tmp = 12000000 * 32 / baud; | ||
365 | buf[3] = 0x80; | ||
366 | buf[2] = 0; | ||
367 | buf[1] = (tmp >= 256); | ||
368 | while (tmp >= 256) { | ||
369 | tmp >>= 2; | ||
370 | buf[1] <<= 1; | ||
324 | } | 371 | } |
372 | buf[0] = tmp; | ||
373 | |||
374 | return baud; | ||
375 | } | ||
376 | |||
377 | static void pl2303_encode_baud_rate(struct tty_struct *tty, | ||
378 | struct usb_serial_port *port, | ||
379 | u8 buf[4]) | ||
380 | { | ||
381 | struct usb_serial *serial = port->serial; | ||
382 | struct pl2303_serial_private *spriv = usb_get_serial_data(serial); | ||
383 | speed_t baud_sup; | ||
384 | speed_t baud; | ||
385 | |||
386 | baud = tty_get_baud_rate(tty); | ||
387 | dev_dbg(&port->dev, "baud requested = %u\n", baud); | ||
388 | if (!baud) | ||
389 | return; | ||
390 | |||
391 | if (spriv->type->max_baud_rate) | ||
392 | baud = min_t(speed_t, baud, spriv->type->max_baud_rate); | ||
393 | /* | ||
394 | * Set baud rate to nearest supported value. | ||
395 | * | ||
396 | * NOTE: Baud rate 500k can only be set using divisors. | ||
397 | */ | ||
398 | baud_sup = pl2303_get_supported_baud_rate(baud); | ||
399 | |||
400 | if (baud == 500000) | ||
401 | baud = pl2303_encode_baud_rate_divisor(buf, baud); | ||
402 | else | ||
403 | baud = pl2303_encode_baud_rate_direct(buf, baud_sup); | ||
325 | 404 | ||
326 | /* Save resulting baud rate */ | 405 | /* Save resulting baud rate */ |
327 | tty_encode_baud_rate(tty, baud, baud); | 406 | tty_encode_baud_rate(tty, baud, baud); |
328 | dev_dbg(&port->dev, "baud set = %d\n", baud); | 407 | dev_dbg(&port->dev, "baud set = %u\n", baud); |
408 | } | ||
409 | |||
410 | static int pl2303_get_line_request(struct usb_serial_port *port, | ||
411 | unsigned char buf[7]) | ||
412 | { | ||
413 | struct usb_device *udev = port->serial->dev; | ||
414 | int ret; | ||
415 | |||
416 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | ||
417 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, | ||
418 | 0, 0, buf, 7, 100); | ||
419 | if (ret != 7) { | ||
420 | dev_err(&port->dev, "%s - failed: %d\n", __func__, ret); | ||
421 | |||
422 | if (ret > 0) | ||
423 | ret = -EIO; | ||
424 | |||
425 | return ret; | ||
426 | } | ||
427 | |||
428 | dev_dbg(&port->dev, "%s - %7ph\n", __func__, buf); | ||
429 | |||
430 | return 0; | ||
431 | } | ||
432 | |||
433 | static int pl2303_set_line_request(struct usb_serial_port *port, | ||
434 | unsigned char buf[7]) | ||
435 | { | ||
436 | struct usb_device *udev = port->serial->dev; | ||
437 | int ret; | ||
438 | |||
439 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
440 | SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE, | ||
441 | 0, 0, buf, 7, 100); | ||
442 | if (ret != 7) { | ||
443 | dev_err(&port->dev, "%s - failed: %d\n", __func__, ret); | ||
444 | |||
445 | if (ret > 0) | ||
446 | ret = -EIO; | ||
447 | |||
448 | return ret; | ||
449 | } | ||
450 | |||
451 | dev_dbg(&port->dev, "%s - %7ph\n", __func__, buf); | ||
452 | |||
453 | return 0; | ||
329 | } | 454 | } |
330 | 455 | ||
331 | static void pl2303_set_termios(struct tty_struct *tty, | 456 | static void pl2303_set_termios(struct tty_struct *tty, |
@@ -336,30 +461,21 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
336 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 461 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
337 | unsigned long flags; | 462 | unsigned long flags; |
338 | unsigned char *buf; | 463 | unsigned char *buf; |
339 | int i; | 464 | int ret; |
340 | u8 control; | 465 | u8 control; |
341 | 466 | ||
342 | /* | ||
343 | * The PL2303 is reported to lose bytes if you change serial settings | ||
344 | * even to the same values as before. Thus we actually need to filter | ||
345 | * in this specific case. | ||
346 | */ | ||
347 | if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios)) | 467 | if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios)) |
348 | return; | 468 | return; |
349 | 469 | ||
350 | buf = kzalloc(7, GFP_KERNEL); | 470 | buf = kzalloc(7, GFP_KERNEL); |
351 | if (!buf) { | 471 | if (!buf) { |
352 | dev_err(&port->dev, "%s - out of memory.\n", __func__); | ||
353 | /* Report back no change occurred */ | 472 | /* Report back no change occurred */ |
354 | if (old_termios) | 473 | if (old_termios) |
355 | tty->termios = *old_termios; | 474 | tty->termios = *old_termios; |
356 | return; | 475 | return; |
357 | } | 476 | } |
358 | 477 | ||
359 | i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | 478 | pl2303_get_line_request(port, buf); |
360 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, | ||
361 | 0, 0, buf, 7, 100); | ||
362 | dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); | ||
363 | 479 | ||
364 | switch (C_CSIZE(tty)) { | 480 | switch (C_CSIZE(tty)) { |
365 | case CS5: | 481 | case CS5: |
@@ -378,7 +494,7 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
378 | dev_dbg(&port->dev, "data bits = %d\n", buf[6]); | 494 | dev_dbg(&port->dev, "data bits = %d\n", buf[6]); |
379 | 495 | ||
380 | /* For reference buf[0]:buf[3] baud rate value */ | 496 | /* For reference buf[0]:buf[3] baud rate value */ |
381 | pl2303_encode_baudrate(tty, port, &buf[0]); | 497 | pl2303_encode_baud_rate(tty, port, &buf[0]); |
382 | 498 | ||
383 | /* For reference buf[4]=0 is 1 stop bits */ | 499 | /* For reference buf[4]=0 is 1 stop bits */ |
384 | /* For reference buf[4]=1 is 1.5 stop bits */ | 500 | /* For reference buf[4]=1 is 1.5 stop bits */ |
@@ -407,7 +523,7 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
407 | /* For reference buf[5]=3 is mark parity */ | 523 | /* For reference buf[5]=3 is mark parity */ |
408 | /* For reference buf[5]=4 is space parity */ | 524 | /* For reference buf[5]=4 is space parity */ |
409 | if (C_PARODD(tty)) { | 525 | if (C_PARODD(tty)) { |
410 | if (tty->termios.c_cflag & CMSPAR) { | 526 | if (C_CMSPAR(tty)) { |
411 | buf[5] = 3; | 527 | buf[5] = 3; |
412 | dev_dbg(&port->dev, "parity = mark\n"); | 528 | dev_dbg(&port->dev, "parity = mark\n"); |
413 | } else { | 529 | } else { |
@@ -415,7 +531,7 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
415 | dev_dbg(&port->dev, "parity = odd\n"); | 531 | dev_dbg(&port->dev, "parity = odd\n"); |
416 | } | 532 | } |
417 | } else { | 533 | } else { |
418 | if (tty->termios.c_cflag & CMSPAR) { | 534 | if (C_CMSPAR(tty)) { |
419 | buf[5] = 4; | 535 | buf[5] = 4; |
420 | dev_dbg(&port->dev, "parity = space\n"); | 536 | dev_dbg(&port->dev, "parity = space\n"); |
421 | } else { | 537 | } else { |
@@ -428,10 +544,23 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
428 | dev_dbg(&port->dev, "parity = none\n"); | 544 | dev_dbg(&port->dev, "parity = none\n"); |
429 | } | 545 | } |
430 | 546 | ||
431 | i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | 547 | /* |
432 | SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE, | 548 | * Some PL2303 are known to lose bytes if you change serial settings |
433 | 0, 0, buf, 7, 100); | 549 | * even to the same values as before. Thus we actually need to filter |
434 | dev_dbg(&port->dev, "0x21:0x20:0:0 %d\n", i); | 550 | * in this specific case. |
551 | * | ||
552 | * Note that the tty_termios_hw_change check above is not sufficient | ||
553 | * as a previously requested baud rate may differ from the one | ||
554 | * actually used (and stored in old_termios). | ||
555 | * | ||
556 | * NOTE: No additional locking needed for line_settings as it is | ||
557 | * only used in set_termios, which is serialised against itself. | ||
558 | */ | ||
559 | if (!old_termios || memcmp(buf, priv->line_settings, 7)) { | ||
560 | ret = pl2303_set_line_request(port, buf); | ||
561 | if (!ret) | ||
562 | memcpy(priv->line_settings, buf, 7); | ||
563 | } | ||
435 | 564 | ||
436 | /* change control lines if we are switching to or from B0 */ | 565 | /* change control lines if we are switching to or from B0 */ |
437 | spin_lock_irqsave(&priv->lock, flags); | 566 | spin_lock_irqsave(&priv->lock, flags); |
@@ -448,19 +577,13 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
448 | spin_unlock_irqrestore(&priv->lock, flags); | 577 | spin_unlock_irqrestore(&priv->lock, flags); |
449 | } | 578 | } |
450 | 579 | ||
451 | memset(buf, 0, 7); | ||
452 | i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | ||
453 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, | ||
454 | 0, 0, buf, 7, 100); | ||
455 | dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); | ||
456 | |||
457 | if (C_CRTSCTS(tty)) { | 580 | if (C_CRTSCTS(tty)) { |
458 | if (spriv->type == HX) | 581 | if (spriv->quirks & PL2303_QUIRK_LEGACY) |
459 | pl2303_vendor_write(0x0, 0x61, serial); | 582 | pl2303_vendor_write(serial, 0x0, 0x41); |
460 | else | 583 | else |
461 | pl2303_vendor_write(0x0, 0x41, serial); | 584 | pl2303_vendor_write(serial, 0x0, 0x61); |
462 | } else { | 585 | } else { |
463 | pl2303_vendor_write(0x0, 0x0, serial); | 586 | pl2303_vendor_write(serial, 0x0, 0x0); |
464 | } | 587 | } |
465 | 588 | ||
466 | kfree(buf); | 589 | kfree(buf); |
@@ -473,13 +596,13 @@ static void pl2303_dtr_rts(struct usb_serial_port *port, int on) | |||
473 | u8 control; | 596 | u8 control; |
474 | 597 | ||
475 | spin_lock_irqsave(&priv->lock, flags); | 598 | spin_lock_irqsave(&priv->lock, flags); |
476 | /* Change DTR and RTS */ | ||
477 | if (on) | 599 | if (on) |
478 | priv->line_control |= (CONTROL_DTR | CONTROL_RTS); | 600 | priv->line_control |= (CONTROL_DTR | CONTROL_RTS); |
479 | else | 601 | else |
480 | priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); | 602 | priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); |
481 | control = priv->line_control; | 603 | control = priv->line_control; |
482 | spin_unlock_irqrestore(&priv->lock, flags); | 604 | spin_unlock_irqrestore(&priv->lock, flags); |
605 | |||
483 | pl2303_set_control_lines(port, control); | 606 | pl2303_set_control_lines(port, control); |
484 | } | 607 | } |
485 | 608 | ||
@@ -495,13 +618,13 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
495 | struct pl2303_serial_private *spriv = usb_get_serial_data(serial); | 618 | struct pl2303_serial_private *spriv = usb_get_serial_data(serial); |
496 | int result; | 619 | int result; |
497 | 620 | ||
498 | if (spriv->type != HX) { | 621 | if (spriv->quirks & PL2303_QUIRK_LEGACY) { |
499 | usb_clear_halt(serial->dev, port->write_urb->pipe); | 622 | usb_clear_halt(serial->dev, port->write_urb->pipe); |
500 | usb_clear_halt(serial->dev, port->read_urb->pipe); | 623 | usb_clear_halt(serial->dev, port->read_urb->pipe); |
501 | } else { | 624 | } else { |
502 | /* reset upstream data pipes */ | 625 | /* reset upstream data pipes */ |
503 | pl2303_vendor_write(8, 0, serial); | 626 | pl2303_vendor_write(serial, 8, 0); |
504 | pl2303_vendor_write(9, 0, serial); | 627 | pl2303_vendor_write(serial, 9, 0); |
505 | } | 628 | } |
506 | 629 | ||
507 | /* Setup termios */ | 630 | /* Setup termios */ |
@@ -510,8 +633,8 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
510 | 633 | ||
511 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); | 634 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
512 | if (result) { | 635 | if (result) { |
513 | dev_err(&port->dev, "%s - failed submitting interrupt urb," | 636 | dev_err(&port->dev, "failed to submit interrupt urb: %d\n", |
514 | " error %d\n", __func__, result); | 637 | result); |
515 | return result; | 638 | return result; |
516 | } | 639 | } |
517 | 640 | ||
@@ -581,48 +704,10 @@ static int pl2303_tiocmget(struct tty_struct *tty) | |||
581 | static int pl2303_carrier_raised(struct usb_serial_port *port) | 704 | static int pl2303_carrier_raised(struct usb_serial_port *port) |
582 | { | 705 | { |
583 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 706 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
707 | |||
584 | if (priv->line_status & UART_DCD) | 708 | if (priv->line_status & UART_DCD) |
585 | return 1; | 709 | return 1; |
586 | return 0; | ||
587 | } | ||
588 | 710 | ||
589 | static int pl2303_tiocmiwait(struct tty_struct *tty, unsigned long arg) | ||
590 | { | ||
591 | struct usb_serial_port *port = tty->driver_data; | ||
592 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
593 | unsigned long flags; | ||
594 | unsigned int prevstatus; | ||
595 | unsigned int status; | ||
596 | unsigned int changed; | ||
597 | |||
598 | spin_lock_irqsave(&priv->lock, flags); | ||
599 | prevstatus = priv->line_status; | ||
600 | spin_unlock_irqrestore(&priv->lock, flags); | ||
601 | |||
602 | while (1) { | ||
603 | interruptible_sleep_on(&port->port.delta_msr_wait); | ||
604 | /* see if a signal did it */ | ||
605 | if (signal_pending(current)) | ||
606 | return -ERESTARTSYS; | ||
607 | |||
608 | if (port->serial->disconnected) | ||
609 | return -EIO; | ||
610 | |||
611 | spin_lock_irqsave(&priv->lock, flags); | ||
612 | status = priv->line_status; | ||
613 | spin_unlock_irqrestore(&priv->lock, flags); | ||
614 | |||
615 | changed = prevstatus ^ status; | ||
616 | |||
617 | if (((arg & TIOCM_RNG) && (changed & UART_RING)) || | ||
618 | ((arg & TIOCM_DSR) && (changed & UART_DSR)) || | ||
619 | ((arg & TIOCM_CD) && (changed & UART_DCD)) || | ||
620 | ((arg & TIOCM_CTS) && (changed & UART_CTS))) { | ||
621 | return 0; | ||
622 | } | ||
623 | prevstatus = status; | ||
624 | } | ||
625 | /* NOTREACHED */ | ||
626 | return 0; | 711 | return 0; |
627 | } | 712 | } |
628 | 713 | ||
@@ -632,8 +717,6 @@ static int pl2303_ioctl(struct tty_struct *tty, | |||
632 | struct serial_struct ser; | 717 | struct serial_struct ser; |
633 | struct usb_serial_port *port = tty->driver_data; | 718 | struct usb_serial_port *port = tty->driver_data; |
634 | 719 | ||
635 | dev_dbg(&port->dev, "%s cmd = 0x%04x\n", __func__, cmd); | ||
636 | |||
637 | switch (cmd) { | 720 | switch (cmd) { |
638 | case TIOCGSERIAL: | 721 | case TIOCGSERIAL: |
639 | memset(&ser, 0, sizeof ser); | 722 | memset(&ser, 0, sizeof ser); |
@@ -647,9 +730,9 @@ static int pl2303_ioctl(struct tty_struct *tty, | |||
647 | 730 | ||
648 | return 0; | 731 | return 0; |
649 | default: | 732 | default: |
650 | dev_dbg(&port->dev, "%s not supported = 0x%04x\n", __func__, cmd); | ||
651 | break; | 733 | break; |
652 | } | 734 | } |
735 | |||
653 | return -ENOIOCTLCMD; | 736 | return -ENOIOCTLCMD; |
654 | } | 737 | } |
655 | 738 | ||
@@ -664,6 +747,7 @@ static void pl2303_break_ctl(struct tty_struct *tty, int break_state) | |||
664 | state = BREAK_OFF; | 747 | state = BREAK_OFF; |
665 | else | 748 | else |
666 | state = BREAK_ON; | 749 | state = BREAK_ON; |
750 | |||
667 | dev_dbg(&port->dev, "%s - turning break %s\n", __func__, | 751 | dev_dbg(&port->dev, "%s - turning break %s\n", __func__, |
668 | state == BREAK_OFF ? "off" : "on"); | 752 | state == BREAK_OFF ? "off" : "on"); |
669 | 753 | ||
@@ -678,48 +762,51 @@ static void pl2303_update_line_status(struct usb_serial_port *port, | |||
678 | unsigned char *data, | 762 | unsigned char *data, |
679 | unsigned int actual_length) | 763 | unsigned int actual_length) |
680 | { | 764 | { |
681 | 765 | struct usb_serial *serial = port->serial; | |
766 | struct pl2303_serial_private *spriv = usb_get_serial_data(serial); | ||
682 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 767 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
683 | struct tty_struct *tty; | 768 | struct tty_struct *tty; |
684 | unsigned long flags; | 769 | unsigned long flags; |
685 | u8 status_idx = UART_STATE; | 770 | unsigned int status_idx = UART_STATE_INDEX; |
686 | u8 length = UART_STATE + 1; | 771 | u8 status; |
687 | u8 prev_line_status; | 772 | u8 delta; |
688 | u16 idv, idp; | ||
689 | |||
690 | idv = le16_to_cpu(port->serial->dev->descriptor.idVendor); | ||
691 | idp = le16_to_cpu(port->serial->dev->descriptor.idProduct); | ||
692 | |||
693 | 773 | ||
694 | if (idv == SIEMENS_VENDOR_ID) { | 774 | if (spriv->quirks & PL2303_QUIRK_UART_STATE_IDX0) |
695 | if (idp == SIEMENS_PRODUCT_ID_X65 || | 775 | status_idx = 0; |
696 | idp == SIEMENS_PRODUCT_ID_SX1 || | ||
697 | idp == SIEMENS_PRODUCT_ID_X75) { | ||
698 | 776 | ||
699 | length = 1; | 777 | if (actual_length < status_idx + 1) |
700 | status_idx = 0; | ||
701 | } | ||
702 | } | ||
703 | |||
704 | if (actual_length < length) | ||
705 | return; | 778 | return; |
706 | 779 | ||
780 | status = data[status_idx]; | ||
781 | |||
707 | /* Save off the uart status for others to look at */ | 782 | /* Save off the uart status for others to look at */ |
708 | spin_lock_irqsave(&priv->lock, flags); | 783 | spin_lock_irqsave(&priv->lock, flags); |
709 | prev_line_status = priv->line_status; | 784 | delta = priv->line_status ^ status; |
710 | priv->line_status = data[status_idx]; | 785 | priv->line_status = status; |
711 | spin_unlock_irqrestore(&priv->lock, flags); | 786 | spin_unlock_irqrestore(&priv->lock, flags); |
712 | if (priv->line_status & UART_BREAK_ERROR) | 787 | |
788 | if (status & UART_BREAK_ERROR) | ||
713 | usb_serial_handle_break(port); | 789 | usb_serial_handle_break(port); |
714 | wake_up_interruptible(&port->port.delta_msr_wait); | ||
715 | 790 | ||
716 | tty = tty_port_tty_get(&port->port); | 791 | if (delta & UART_STATE_MSR_MASK) { |
717 | if (!tty) | 792 | if (delta & UART_CTS) |
718 | return; | 793 | port->icount.cts++; |
719 | if ((priv->line_status ^ prev_line_status) & UART_DCD) | 794 | if (delta & UART_DSR) |
720 | usb_serial_handle_dcd_change(port, tty, | 795 | port->icount.dsr++; |
721 | priv->line_status & UART_DCD); | 796 | if (delta & UART_RING) |
722 | tty_kref_put(tty); | 797 | port->icount.rng++; |
798 | if (delta & UART_DCD) { | ||
799 | port->icount.dcd++; | ||
800 | tty = tty_port_tty_get(&port->port); | ||
801 | if (tty) { | ||
802 | usb_serial_handle_dcd_change(port, tty, | ||
803 | status & UART_DCD); | ||
804 | tty_kref_put(tty); | ||
805 | } | ||
806 | } | ||
807 | |||
808 | wake_up_interruptible(&port->port.delta_msr_wait); | ||
809 | } | ||
723 | } | 810 | } |
724 | 811 | ||
725 | static void pl2303_read_int_callback(struct urb *urb) | 812 | static void pl2303_read_int_callback(struct urb *urb) |
@@ -754,10 +841,11 @@ static void pl2303_read_int_callback(struct urb *urb) | |||
754 | 841 | ||
755 | exit: | 842 | exit: |
756 | retval = usb_submit_urb(urb, GFP_ATOMIC); | 843 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
757 | if (retval) | 844 | if (retval) { |
758 | dev_err(&port->dev, | 845 | dev_err(&port->dev, |
759 | "%s - usb_submit_urb failed with result %d\n", | 846 | "%s - usb_submit_urb failed with result %d\n", |
760 | __func__, retval); | 847 | __func__, retval); |
848 | } | ||
761 | } | 849 | } |
762 | 850 | ||
763 | static void pl2303_process_read_urb(struct urb *urb) | 851 | static void pl2303_process_read_urb(struct urb *urb) |
@@ -775,13 +863,14 @@ static void pl2303_process_read_urb(struct urb *urb) | |||
775 | line_status = priv->line_status; | 863 | line_status = priv->line_status; |
776 | priv->line_status &= ~UART_STATE_TRANSIENT_MASK; | 864 | priv->line_status &= ~UART_STATE_TRANSIENT_MASK; |
777 | spin_unlock_irqrestore(&priv->lock, flags); | 865 | spin_unlock_irqrestore(&priv->lock, flags); |
778 | wake_up_interruptible(&port->port.delta_msr_wait); | ||
779 | 866 | ||
780 | if (!urb->actual_length) | 867 | if (!urb->actual_length) |
781 | return; | 868 | return; |
782 | 869 | ||
783 | /* break takes precedence over parity, */ | 870 | /* |
784 | /* which takes precedence over framing errors */ | 871 | * Break takes precedence over parity, which takes precedence over |
872 | * framing errors. | ||
873 | */ | ||
785 | if (line_status & UART_BREAK_ERROR) | 874 | if (line_status & UART_BREAK_ERROR) |
786 | tty_flag = TTY_BREAK; | 875 | tty_flag = TTY_BREAK; |
787 | else if (line_status & UART_PARITY_ERROR) | 876 | else if (line_status & UART_PARITY_ERROR) |
@@ -809,7 +898,6 @@ static void pl2303_process_read_urb(struct urb *urb) | |||
809 | tty_flip_buffer_push(&port->port); | 898 | tty_flip_buffer_push(&port->port); |
810 | } | 899 | } |
811 | 900 | ||
812 | /* All of the device info needed for the PL2303 SIO serial converter */ | ||
813 | static struct usb_serial_driver pl2303_device = { | 901 | static struct usb_serial_driver pl2303_device = { |
814 | .driver = { | 902 | .driver = { |
815 | .owner = THIS_MODULE, | 903 | .owner = THIS_MODULE, |
@@ -821,16 +909,17 @@ static struct usb_serial_driver pl2303_device = { | |||
821 | .bulk_out_size = 256, | 909 | .bulk_out_size = 256, |
822 | .open = pl2303_open, | 910 | .open = pl2303_open, |
823 | .close = pl2303_close, | 911 | .close = pl2303_close, |
824 | .dtr_rts = pl2303_dtr_rts, | 912 | .dtr_rts = pl2303_dtr_rts, |
825 | .carrier_raised = pl2303_carrier_raised, | 913 | .carrier_raised = pl2303_carrier_raised, |
826 | .ioctl = pl2303_ioctl, | 914 | .ioctl = pl2303_ioctl, |
827 | .break_ctl = pl2303_break_ctl, | 915 | .break_ctl = pl2303_break_ctl, |
828 | .set_termios = pl2303_set_termios, | 916 | .set_termios = pl2303_set_termios, |
829 | .tiocmget = pl2303_tiocmget, | 917 | .tiocmget = pl2303_tiocmget, |
830 | .tiocmset = pl2303_tiocmset, | 918 | .tiocmset = pl2303_tiocmset, |
831 | .tiocmiwait = pl2303_tiocmiwait, | 919 | .tiocmiwait = usb_serial_generic_tiocmiwait, |
832 | .process_read_urb = pl2303_process_read_urb, | 920 | .process_read_urb = pl2303_process_read_urb, |
833 | .read_int_callback = pl2303_read_int_callback, | 921 | .read_int_callback = pl2303_read_int_callback, |
922 | .probe = pl2303_probe, | ||
834 | .attach = pl2303_startup, | 923 | .attach = pl2303_startup, |
835 | .release = pl2303_release, | 924 | .release = pl2303_release, |
836 | .port_probe = pl2303_port_probe, | 925 | .port_probe = pl2303_port_probe, |
@@ -843,5 +932,5 @@ static struct usb_serial_driver * const serial_drivers[] = { | |||
843 | 932 | ||
844 | module_usb_serial_driver(serial_drivers, id_table); | 933 | module_usb_serial_driver(serial_drivers, id_table); |
845 | 934 | ||
846 | MODULE_DESCRIPTION(DRIVER_DESC); | 935 | MODULE_DESCRIPTION("Prolific PL2303 USB to serial adaptor driver"); |
847 | MODULE_LICENSE("GPL"); | 936 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/usb/serial/qcaux.c b/drivers/usb/serial/qcaux.c index 31f81c3c15eb..6e9f8af96959 100644 --- a/drivers/usb/serial/qcaux.c +++ b/drivers/usb/serial/qcaux.c | |||
@@ -16,7 +16,6 @@ | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/init.h> | ||
20 | #include <linux/tty.h> | 19 | #include <linux/tty.h> |
21 | #include <linux/module.h> | 20 | #include <linux/module.h> |
22 | #include <linux/usb.h> | 21 | #include <linux/usb.h> |
@@ -54,7 +53,7 @@ | |||
54 | #define SAMSUNG_VENDOR_ID 0x04e8 | 53 | #define SAMSUNG_VENDOR_ID 0x04e8 |
55 | #define SAMSUNG_PRODUCT_U520 0x6640 /* SCH-U520 */ | 54 | #define SAMSUNG_PRODUCT_U520 0x6640 /* SCH-U520 */ |
56 | 55 | ||
57 | static struct usb_device_id id_table[] = { | 56 | static const struct usb_device_id id_table[] = { |
58 | { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_PC5740, 0xff, 0x00, 0x00) }, | 57 | { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_PC5740, 0xff, 0x00, 0x00) }, |
59 | { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_PC5750, 0xff, 0x00, 0x00) }, | 58 | { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_PC5750, 0xff, 0x00, 0x00) }, |
60 | { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_UM150, 0xff, 0x00, 0x00) }, | 59 | { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_UM150, 0xff, 0x00, 0x00) }, |
diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c index a24d59ae4032..7725ed261ed6 100644 --- a/drivers/usb/serial/quatech2.c +++ b/drivers/usb/serial/quatech2.c | |||
@@ -15,7 +15,6 @@ | |||
15 | 15 | ||
16 | #include <asm/unaligned.h> | 16 | #include <asm/unaligned.h> |
17 | #include <linux/errno.h> | 17 | #include <linux/errno.h> |
18 | #include <linux/init.h> | ||
19 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
20 | #include <linux/tty.h> | 19 | #include <linux/tty.h> |
21 | #include <linux/tty_driver.h> | 20 | #include <linux/tty_driver.h> |
@@ -676,10 +675,8 @@ static int qt2_setup_urbs(struct usb_serial *serial) | |||
676 | 675 | ||
677 | serial_priv = usb_get_serial_data(serial); | 676 | serial_priv = usb_get_serial_data(serial); |
678 | serial_priv->read_urb = usb_alloc_urb(0, GFP_KERNEL); | 677 | serial_priv->read_urb = usb_alloc_urb(0, GFP_KERNEL); |
679 | if (!serial_priv->read_urb) { | 678 | if (!serial_priv->read_urb) |
680 | dev_err(&serial->dev->dev, "No free urbs available\n"); | ||
681 | return -ENOMEM; | 679 | return -ENOMEM; |
682 | } | ||
683 | 680 | ||
684 | usb_fill_bulk_urb(serial_priv->read_urb, serial->dev, | 681 | usb_fill_bulk_urb(serial_priv->read_urb, serial->dev, |
685 | usb_rcvbulkpipe(serial->dev, | 682 | usb_rcvbulkpipe(serial->dev, |
@@ -715,10 +712,8 @@ static int qt2_attach(struct usb_serial *serial) | |||
715 | } | 712 | } |
716 | 713 | ||
717 | serial_priv = kzalloc(sizeof(*serial_priv), GFP_KERNEL); | 714 | serial_priv = kzalloc(sizeof(*serial_priv), GFP_KERNEL); |
718 | if (!serial_priv) { | 715 | if (!serial_priv) |
719 | dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); | ||
720 | return -ENOMEM; | 716 | return -ENOMEM; |
721 | } | ||
722 | 717 | ||
723 | serial_priv->read_buffer = kmalloc(QT2_READ_BUFFER_SIZE, GFP_KERNEL); | 718 | serial_priv->read_buffer = kmalloc(QT2_READ_BUFFER_SIZE, GFP_KERNEL); |
724 | if (!serial_priv->read_buffer) { | 719 | if (!serial_priv->read_buffer) { |
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c index ba895989d8c4..b2dff0f14743 100644 --- a/drivers/usb/serial/safe_serial.c +++ b/drivers/usb/serial/safe_serial.c | |||
@@ -67,7 +67,6 @@ | |||
67 | #include <linux/kernel.h> | 67 | #include <linux/kernel.h> |
68 | #include <linux/errno.h> | 68 | #include <linux/errno.h> |
69 | #include <linux/gfp.h> | 69 | #include <linux/gfp.h> |
70 | #include <linux/init.h> | ||
71 | #include <linux/tty.h> | 70 | #include <linux/tty.h> |
72 | #include <linux/tty_driver.h> | 71 | #include <linux/tty_driver.h> |
73 | #include <linux/tty_flip.h> | 72 | #include <linux/tty_flip.h> |
@@ -125,7 +124,7 @@ MODULE_PARM_DESC(padded, "Pad to full wMaxPacketSize On/Off"); | |||
125 | .bInterfaceClass = (ic), \ | 124 | .bInterfaceClass = (ic), \ |
126 | .bInterfaceSubClass = (isc), | 125 | .bInterfaceSubClass = (isc), |
127 | 126 | ||
128 | static struct usb_device_id id_table[] = { | 127 | static const struct usb_device_id id_table[] = { |
129 | {MY_USB_DEVICE(0x49f, 0xffff, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Itsy */ | 128 | {MY_USB_DEVICE(0x49f, 0xffff, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Itsy */ |
130 | {MY_USB_DEVICE(0x3f0, 0x2101, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Calypso */ | 129 | {MY_USB_DEVICE(0x3f0, 0x2101, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Calypso */ |
131 | {MY_USB_DEVICE(0x4dd, 0x8001, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Iris */ | 130 | {MY_USB_DEVICE(0x4dd, 0x8001, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Iris */ |
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index de958c5b52e3..a9eb6221a815 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c | |||
@@ -497,14 +497,12 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
497 | 497 | ||
498 | buffer = kmalloc(writesize, GFP_ATOMIC); | 498 | buffer = kmalloc(writesize, GFP_ATOMIC); |
499 | if (!buffer) { | 499 | if (!buffer) { |
500 | dev_err(&port->dev, "out of memory\n"); | ||
501 | retval = -ENOMEM; | 500 | retval = -ENOMEM; |
502 | goto error_no_buffer; | 501 | goto error_no_buffer; |
503 | } | 502 | } |
504 | 503 | ||
505 | urb = usb_alloc_urb(0, GFP_ATOMIC); | 504 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
506 | if (!urb) { | 505 | if (!urb) { |
507 | dev_err(&port->dev, "no more free urbs\n"); | ||
508 | retval = -ENOMEM; | 506 | retval = -ENOMEM; |
509 | goto error_no_urb; | 507 | goto error_no_urb; |
510 | } | 508 | } |
@@ -736,11 +734,8 @@ static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint, | |||
736 | return NULL; | 734 | return NULL; |
737 | 735 | ||
738 | urb = usb_alloc_urb(0, mem_flags); | 736 | urb = usb_alloc_urb(0, mem_flags); |
739 | if (urb == NULL) { | 737 | if (!urb) |
740 | dev_dbg(&serial->dev->dev, "%s: alloc for endpoint %d failed\n", | ||
741 | __func__, endpoint); | ||
742 | return NULL; | 738 | return NULL; |
743 | } | ||
744 | 739 | ||
745 | buf = kmalloc(len, mem_flags); | 740 | buf = kmalloc(len, mem_flags); |
746 | if (buf) { | 741 | if (buf) { |
@@ -752,9 +747,6 @@ static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint, | |||
752 | dev_dbg(&serial->dev->dev, "%s %c u : %p d:%p\n", __func__, | 747 | dev_dbg(&serial->dev->dev, "%s %c u : %p d:%p\n", __func__, |
753 | dir == USB_DIR_IN ? 'i' : 'o', urb, buf); | 748 | dir == USB_DIR_IN ? 'i' : 'o', urb, buf); |
754 | } else { | 749 | } else { |
755 | dev_dbg(&serial->dev->dev, "%s %c u:%p d:%p\n", __func__, | ||
756 | dir == USB_DIR_IN ? 'i' : 'o', urb, buf); | ||
757 | |||
758 | sierra_release_urb(urb); | 750 | sierra_release_urb(urb); |
759 | urb = NULL; | 751 | urb = NULL; |
760 | } | 752 | } |
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c index 5b793c352267..4ec04f73c800 100644 --- a/drivers/usb/serial/spcp8x5.c +++ b/drivers/usb/serial/spcp8x5.c | |||
@@ -16,7 +16,6 @@ | |||
16 | */ | 16 | */ |
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
19 | #include <linux/init.h> | ||
20 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
21 | #include <linux/tty.h> | 20 | #include <linux/tty.h> |
22 | #include <linux/tty_driver.h> | 21 | #include <linux/tty_driver.h> |
diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c index e5750be49054..a7fe664b6b7d 100644 --- a/drivers/usb/serial/ssu100.c +++ b/drivers/usb/serial/ssu100.c | |||
@@ -6,7 +6,6 @@ | |||
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <linux/errno.h> | 8 | #include <linux/errno.h> |
9 | #include <linux/init.h> | ||
10 | #include <linux/slab.h> | 9 | #include <linux/slab.h> |
11 | #include <linux/tty.h> | 10 | #include <linux/tty.h> |
12 | #include <linux/tty_driver.h> | 11 | #include <linux/tty_driver.h> |
@@ -342,8 +341,6 @@ static int ssu100_ioctl(struct tty_struct *tty, | |||
342 | { | 341 | { |
343 | struct usb_serial_port *port = tty->driver_data; | 342 | struct usb_serial_port *port = tty->driver_data; |
344 | 343 | ||
345 | dev_dbg(&port->dev, "%s cmd 0x%04x\n", __func__, cmd); | ||
346 | |||
347 | switch (cmd) { | 344 | switch (cmd) { |
348 | case TIOCGSERIAL: | 345 | case TIOCGSERIAL: |
349 | return get_serial_info(port, | 346 | return get_serial_info(port, |
@@ -352,8 +349,6 @@ static int ssu100_ioctl(struct tty_struct *tty, | |||
352 | break; | 349 | break; |
353 | } | 350 | } |
354 | 351 | ||
355 | dev_dbg(&port->dev, "%s arg not supported\n", __func__); | ||
356 | |||
357 | return -ENOIOCTLCMD; | 352 | return -ENOIOCTLCMD; |
358 | } | 353 | } |
359 | 354 | ||
diff --git a/drivers/usb/serial/symbolserial.c b/drivers/usb/serial/symbolserial.c index 9b1648945e7a..9fa7dd413e83 100644 --- a/drivers/usb/serial/symbolserial.c +++ b/drivers/usb/serial/symbolserial.c | |||
@@ -11,7 +11,6 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/init.h> | ||
15 | #include <linux/tty.h> | 14 | #include <linux/tty.h> |
16 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
17 | #include <linux/tty_driver.h> | 16 | #include <linux/tty_driver.h> |
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index c9a35697ebe9..ec7cea585663 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c | |||
@@ -21,7 +21,6 @@ | |||
21 | #include <linux/kernel.h> | 21 | #include <linux/kernel.h> |
22 | #include <linux/errno.h> | 22 | #include <linux/errno.h> |
23 | #include <linux/firmware.h> | 23 | #include <linux/firmware.h> |
24 | #include <linux/init.h> | ||
25 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
26 | #include <linux/tty.h> | 25 | #include <linux/tty.h> |
27 | #include <linux/tty_driver.h> | 26 | #include <linux/tty_driver.h> |
@@ -143,7 +142,7 @@ static int ti_download_firmware(struct ti_device *tdev); | |||
143 | static int closing_wait = TI_DEFAULT_CLOSING_WAIT; | 142 | static int closing_wait = TI_DEFAULT_CLOSING_WAIT; |
144 | 143 | ||
145 | /* supported devices */ | 144 | /* supported devices */ |
146 | static struct usb_device_id ti_id_table_3410[] = { | 145 | static const struct usb_device_id ti_id_table_3410[] = { |
147 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, | 146 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, |
148 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, | 147 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, |
149 | { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) }, | 148 | { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) }, |
@@ -163,7 +162,7 @@ static struct usb_device_id ti_id_table_3410[] = { | |||
163 | { } /* terminator */ | 162 | { } /* terminator */ |
164 | }; | 163 | }; |
165 | 164 | ||
166 | static struct usb_device_id ti_id_table_5052[] = { | 165 | static const struct usb_device_id ti_id_table_5052[] = { |
167 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_BOOT_PRODUCT_ID) }, | 166 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_BOOT_PRODUCT_ID) }, |
168 | { USB_DEVICE(TI_VENDOR_ID, TI_5152_BOOT_PRODUCT_ID) }, | 167 | { USB_DEVICE(TI_VENDOR_ID, TI_5152_BOOT_PRODUCT_ID) }, |
169 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_EEPROM_PRODUCT_ID) }, | 168 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_EEPROM_PRODUCT_ID) }, |
@@ -171,7 +170,7 @@ static struct usb_device_id ti_id_table_5052[] = { | |||
171 | { } /* terminator */ | 170 | { } /* terminator */ |
172 | }; | 171 | }; |
173 | 172 | ||
174 | static struct usb_device_id ti_id_table_combined[] = { | 173 | static const struct usb_device_id ti_id_table_combined[] = { |
175 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, | 174 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, |
176 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, | 175 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, |
177 | { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) }, | 176 | { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) }, |
@@ -301,10 +300,9 @@ static int ti_startup(struct usb_serial *serial) | |||
301 | 300 | ||
302 | /* create device structure */ | 301 | /* create device structure */ |
303 | tdev = kzalloc(sizeof(struct ti_device), GFP_KERNEL); | 302 | tdev = kzalloc(sizeof(struct ti_device), GFP_KERNEL); |
304 | if (tdev == NULL) { | 303 | if (!tdev) |
305 | dev_err(&dev->dev, "%s - out of memory\n", __func__); | ||
306 | return -ENOMEM; | 304 | return -ENOMEM; |
307 | } | 305 | |
308 | mutex_init(&tdev->td_open_close_lock); | 306 | mutex_init(&tdev->td_open_close_lock); |
309 | tdev->td_serial = serial; | 307 | tdev->td_serial = serial; |
310 | usb_set_serial_data(serial, tdev); | 308 | usb_set_serial_data(serial, tdev); |
@@ -683,8 +681,6 @@ static int ti_ioctl(struct tty_struct *tty, | |||
683 | struct usb_serial_port *port = tty->driver_data; | 681 | struct usb_serial_port *port = tty->driver_data; |
684 | struct ti_port *tport = usb_get_serial_port_data(port); | 682 | struct ti_port *tport = usb_get_serial_port_data(port); |
685 | 683 | ||
686 | dev_dbg(&port->dev, "%s - cmd = 0x%04X\n", __func__, cmd); | ||
687 | |||
688 | if (tport == NULL) | 684 | if (tport == NULL) |
689 | return -ENODEV; | 685 | return -ENODEV; |
690 | 686 | ||
@@ -724,10 +720,8 @@ static void ti_set_termios(struct tty_struct *tty, | |||
724 | return; | 720 | return; |
725 | 721 | ||
726 | config = kmalloc(sizeof(*config), GFP_KERNEL); | 722 | config = kmalloc(sizeof(*config), GFP_KERNEL); |
727 | if (!config) { | 723 | if (!config) |
728 | dev_err(&port->dev, "%s - out of memory\n", __func__); | ||
729 | return; | 724 | return; |
730 | } | ||
731 | 725 | ||
732 | config->wFlags = 0; | 726 | config->wFlags = 0; |
733 | 727 | ||
@@ -1196,10 +1190,8 @@ static int ti_get_lsr(struct ti_port *tport, u8 *lsr) | |||
1196 | 1190 | ||
1197 | size = sizeof(struct ti_port_status); | 1191 | size = sizeof(struct ti_port_status); |
1198 | data = kmalloc(size, GFP_KERNEL); | 1192 | data = kmalloc(size, GFP_KERNEL); |
1199 | if (!data) { | 1193 | if (!data) |
1200 | dev_err(&port->dev, "%s - out of memory\n", __func__); | ||
1201 | return -ENOMEM; | 1194 | return -ENOMEM; |
1202 | } | ||
1203 | 1195 | ||
1204 | status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS, | 1196 | status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS, |
1205 | (__u8)(TI_UART1_PORT+port_number), 0, (__u8 *)data, size); | 1197 | (__u8)(TI_UART1_PORT+port_number), 0, (__u8 *)data, size); |
@@ -1399,10 +1391,8 @@ static int ti_write_byte(struct usb_serial_port *port, | |||
1399 | 1391 | ||
1400 | size = sizeof(struct ti_write_data_bytes) + 2; | 1392 | size = sizeof(struct ti_write_data_bytes) + 2; |
1401 | data = kmalloc(size, GFP_KERNEL); | 1393 | data = kmalloc(size, GFP_KERNEL); |
1402 | if (!data) { | 1394 | if (!data) |
1403 | dev_err(&port->dev, "%s - out of memory\n", __func__); | ||
1404 | return -ENOMEM; | 1395 | return -ENOMEM; |
1405 | } | ||
1406 | 1396 | ||
1407 | data->bAddrType = TI_RW_DATA_ADDR_XDATA; | 1397 | data->bAddrType = TI_RW_DATA_ADDR_XDATA; |
1408 | data->bDataType = TI_RW_DATA_BYTE; | 1398 | data->bDataType = TI_RW_DATA_BYTE; |
@@ -1518,7 +1508,6 @@ static int ti_download_firmware(struct ti_device *tdev) | |||
1518 | status = ti_do_download(dev, pipe, buffer, fw_p->size); | 1508 | status = ti_do_download(dev, pipe, buffer, fw_p->size); |
1519 | kfree(buffer); | 1509 | kfree(buffer); |
1520 | } else { | 1510 | } else { |
1521 | dev_dbg(&dev->dev, "%s ENOMEM\n", __func__); | ||
1522 | status = -ENOMEM; | 1511 | status = -ENOMEM; |
1523 | } | 1512 | } |
1524 | release_firmware(fw_p); | 1513 | release_firmware(fw_p); |
diff --git a/drivers/usb/serial/usb-serial-simple.c b/drivers/usb/serial/usb-serial-simple.c index 52eb91f2eb2a..f112b079ddfc 100644 --- a/drivers/usb/serial/usb-serial-simple.c +++ b/drivers/usb/serial/usb-serial-simple.c | |||
@@ -15,7 +15,6 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/init.h> | ||
19 | #include <linux/tty.h> | 18 | #include <linux/tty.h> |
20 | #include <linux/module.h> | 19 | #include <linux/module.h> |
21 | #include <linux/usb.h> | 20 | #include <linux/usb.h> |
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 6091bd5a1f4f..7c9dc28640bb 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -405,7 +405,7 @@ static int serial_ioctl(struct tty_struct *tty, | |||
405 | struct usb_serial_port *port = tty->driver_data; | 405 | struct usb_serial_port *port = tty->driver_data; |
406 | int retval = -ENOIOCTLCMD; | 406 | int retval = -ENOIOCTLCMD; |
407 | 407 | ||
408 | dev_dbg(tty->dev, "%s - cmd 0x%.4x\n", __func__, cmd); | 408 | dev_dbg(tty->dev, "%s - cmd 0x%04x\n", __func__, cmd); |
409 | 409 | ||
410 | switch (cmd) { | 410 | switch (cmd) { |
411 | case TIOCMIWAIT: | 411 | case TIOCMIWAIT: |
diff --git a/drivers/usb/serial/usb_debug.c b/drivers/usb/serial/usb_debug.c index 5760f97ee508..ca2fa5bbe17e 100644 --- a/drivers/usb/serial/usb_debug.c +++ b/drivers/usb/serial/usb_debug.c | |||
@@ -10,7 +10,6 @@ | |||
10 | 10 | ||
11 | #include <linux/gfp.h> | 11 | #include <linux/gfp.h> |
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/init.h> | ||
14 | #include <linux/tty.h> | 13 | #include <linux/tty.h> |
15 | #include <linux/module.h> | 14 | #include <linux/module.h> |
16 | #include <linux/usb.h> | 15 | #include <linux/usb.h> |
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c index 85365784040b..640fe0173236 100644 --- a/drivers/usb/serial/usb_wwan.c +++ b/drivers/usb/serial/usb_wwan.c | |||
@@ -447,12 +447,8 @@ static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port, | |||
447 | struct urb *urb; | 447 | struct urb *urb; |
448 | 448 | ||
449 | urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */ | 449 | urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */ |
450 | if (urb == NULL) { | 450 | if (!urb) |
451 | dev_dbg(&serial->interface->dev, | ||
452 | "%s: alloc for endpoint %d failed.\n", __func__, | ||
453 | endpoint); | ||
454 | return NULL; | 451 | return NULL; |
455 | } | ||
456 | 452 | ||
457 | /* Fill URB using supplied data. */ | 453 | /* Fill URB using supplied data. */ |
458 | usb_fill_bulk_urb(urb, serial->dev, | 454 | usb_fill_bulk_urb(urb, serial->dev, |
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c index 9910aa2edf4b..bf2bd40e5f2a 100644 --- a/drivers/usb/serial/visor.c +++ b/drivers/usb/serial/visor.c | |||
@@ -16,7 +16,6 @@ | |||
16 | 16 | ||
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
19 | #include <linux/init.h> | ||
20 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
21 | #include <linux/tty.h> | 20 | #include <linux/tty.h> |
22 | #include <linux/tty_driver.h> | 21 | #include <linux/tty_driver.h> |
@@ -51,7 +50,7 @@ static int palm_os_3_probe(struct usb_serial *serial, | |||
51 | static int palm_os_4_probe(struct usb_serial *serial, | 50 | static int palm_os_4_probe(struct usb_serial *serial, |
52 | const struct usb_device_id *id); | 51 | const struct usb_device_id *id); |
53 | 52 | ||
54 | static struct usb_device_id id_table [] = { | 53 | static const struct usb_device_id id_table[] = { |
55 | { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID), | 54 | { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID), |
56 | .driver_info = (kernel_ulong_t)&palm_os_3_probe }, | 55 | .driver_info = (kernel_ulong_t)&palm_os_3_probe }, |
57 | { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID), | 56 | { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID), |
@@ -113,18 +112,18 @@ static struct usb_device_id id_table [] = { | |||
113 | { } /* Terminating entry */ | 112 | { } /* Terminating entry */ |
114 | }; | 113 | }; |
115 | 114 | ||
116 | static struct usb_device_id clie_id_5_table [] = { | 115 | static const struct usb_device_id clie_id_5_table[] = { |
117 | { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID), | 116 | { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID), |
118 | .driver_info = (kernel_ulong_t)&palm_os_4_probe }, | 117 | .driver_info = (kernel_ulong_t)&palm_os_4_probe }, |
119 | { } /* Terminating entry */ | 118 | { } /* Terminating entry */ |
120 | }; | 119 | }; |
121 | 120 | ||
122 | static struct usb_device_id clie_id_3_5_table [] = { | 121 | static const struct usb_device_id clie_id_3_5_table[] = { |
123 | { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) }, | 122 | { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) }, |
124 | { } /* Terminating entry */ | 123 | { } /* Terminating entry */ |
125 | }; | 124 | }; |
126 | 125 | ||
127 | static struct usb_device_id id_table_combined [] = { | 126 | static const struct usb_device_id id_table_combined[] = { |
128 | { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID) }, | 127 | { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID) }, |
129 | { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID) }, | 128 | { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID) }, |
130 | { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID) }, | 129 | { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID) }, |
@@ -324,11 +323,8 @@ static int palm_os_3_probe(struct usb_serial *serial, | |||
324 | int num_ports = 0; | 323 | int num_ports = 0; |
325 | 324 | ||
326 | transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL); | 325 | transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL); |
327 | if (!transfer_buffer) { | 326 | if (!transfer_buffer) |
328 | dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__, | ||
329 | sizeof(*connection_info)); | ||
330 | return -ENOMEM; | 327 | return -ENOMEM; |
331 | } | ||
332 | 328 | ||
333 | /* send a get connection info request */ | 329 | /* send a get connection info request */ |
334 | retval = usb_control_msg(serial->dev, | 330 | retval = usb_control_msg(serial->dev, |
@@ -419,11 +415,8 @@ static int palm_os_4_probe(struct usb_serial *serial, | |||
419 | int retval; | 415 | int retval; |
420 | 416 | ||
421 | transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL); | 417 | transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL); |
422 | if (!transfer_buffer) { | 418 | if (!transfer_buffer) |
423 | dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__, | ||
424 | sizeof(*connection_info)); | ||
425 | return -ENOMEM; | 419 | return -ENOMEM; |
426 | } | ||
427 | 420 | ||
428 | retval = usb_control_msg(serial->dev, | 421 | retval = usb_control_msg(serial->dev, |
429 | usb_rcvctrlpipe(serial->dev, 0), | 422 | usb_rcvctrlpipe(serial->dev, 0), |
diff --git a/drivers/usb/serial/visor.h b/drivers/usb/serial/visor.h index 88db4d06aefb..4c456dd69ce5 100644 --- a/drivers/usb/serial/visor.h +++ b/drivers/usb/serial/visor.h | |||
@@ -136,7 +136,7 @@ struct visor_connection_info { | |||
136 | * connections.end_point_info is non-zero. If value is 0, then | 136 | * connections.end_point_info is non-zero. If value is 0, then |
137 | * connections.port contains the endpoint number, which is the same for in | 137 | * connections.port contains the endpoint number, which is the same for in |
138 | * and out. | 138 | * and out. |
139 | * @port_function_id: contains the creator id of the applicaton that opened | 139 | * @port_function_id: contains the creator id of the application that opened |
140 | * this connection. | 140 | * this connection. |
141 | * @port: contains the in/out endpoint number. Is 0 if in and out endpoint | 141 | * @port: contains the in/out endpoint number. Is 0 if in and out endpoint |
142 | * numbers are different. | 142 | * numbers are different. |
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c index 36a7740e827c..e62f2dff8b7d 100644 --- a/drivers/usb/serial/whiteheat.c +++ b/drivers/usb/serial/whiteheat.c | |||
@@ -18,7 +18,6 @@ | |||
18 | 18 | ||
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/errno.h> | 20 | #include <linux/errno.h> |
21 | #include <linux/init.h> | ||
22 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
23 | #include <linux/tty.h> | 22 | #include <linux/tty.h> |
24 | #include <linux/tty_driver.h> | 23 | #include <linux/tty_driver.h> |
@@ -288,12 +287,8 @@ static int whiteheat_attach(struct usb_serial *serial) | |||
288 | 287 | ||
289 | command_info = kmalloc(sizeof(struct whiteheat_command_private), | 288 | command_info = kmalloc(sizeof(struct whiteheat_command_private), |
290 | GFP_KERNEL); | 289 | GFP_KERNEL); |
291 | if (command_info == NULL) { | 290 | if (!command_info) |
292 | dev_err(&serial->dev->dev, | ||
293 | "%s: Out of memory for port structures\n", | ||
294 | serial->type->description); | ||
295 | goto no_command_private; | 291 | goto no_command_private; |
296 | } | ||
297 | 292 | ||
298 | mutex_init(&command_info->mutex); | 293 | mutex_init(&command_info->mutex); |
299 | command_info->port_running = 0; | 294 | command_info->port_running = 0; |
@@ -455,8 +450,6 @@ static int whiteheat_ioctl(struct tty_struct *tty, | |||
455 | struct serial_struct serstruct; | 450 | struct serial_struct serstruct; |
456 | void __user *user_arg = (void __user *)arg; | 451 | void __user *user_arg = (void __user *)arg; |
457 | 452 | ||
458 | dev_dbg(&port->dev, "%s - cmd 0x%.4x\n", __func__, cmd); | ||
459 | |||
460 | switch (cmd) { | 453 | switch (cmd) { |
461 | case TIOCGSERIAL: | 454 | case TIOCGSERIAL: |
462 | memset(&serstruct, 0, sizeof(serstruct)); | 455 | memset(&serstruct, 0, sizeof(serstruct)); |
diff --git a/drivers/usb/serial/wishbone-serial.c b/drivers/usb/serial/wishbone-serial.c index 100573c6f19e..4fed4a0bd702 100644 --- a/drivers/usb/serial/wishbone-serial.c +++ b/drivers/usb/serial/wishbone-serial.c | |||
@@ -11,7 +11,6 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/init.h> | ||
15 | #include <linux/tty.h> | 14 | #include <linux/tty.h> |
16 | #include <linux/module.h> | 15 | #include <linux/module.h> |
17 | #include <linux/usb.h> | 16 | #include <linux/usb.h> |
diff --git a/drivers/usb/serial/xsens_mt.c b/drivers/usb/serial/xsens_mt.c index 1d5798d891bc..4841fb57400c 100644 --- a/drivers/usb/serial/xsens_mt.c +++ b/drivers/usb/serial/xsens_mt.c | |||
@@ -9,7 +9,6 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
12 | #include <linux/init.h> | ||
13 | #include <linux/tty.h> | 12 | #include <linux/tty.h> |
14 | #include <linux/module.h> | 13 | #include <linux/module.h> |
15 | #include <linux/usb.h> | 14 | #include <linux/usb.h> |
diff --git a/drivers/usb/serial/zte_ev.c b/drivers/usb/serial/zte_ev.c index eae2c873b39f..e40ab739c4a6 100644 --- a/drivers/usb/serial/zte_ev.c +++ b/drivers/usb/serial/zte_ev.c | |||
@@ -13,7 +13,6 @@ | |||
13 | * show the commands used to talk to the device, but I am not sure. | 13 | * show the commands used to talk to the device, but I am not sure. |
14 | */ | 14 | */ |
15 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
16 | #include <linux/init.h> | ||
17 | #include <linux/tty.h> | 16 | #include <linux/tty.h> |
18 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
19 | #include <linux/module.h> | 18 | #include <linux/module.h> |
@@ -53,7 +52,7 @@ static int zte_ev_usb_serial_open(struct tty_struct *tty, | |||
53 | USB_CTRL_GET_TIMEOUT); | 52 | USB_CTRL_GET_TIMEOUT); |
54 | dev_dbg(dev, "result = %d\n", result); | 53 | dev_dbg(dev, "result = %d\n", result); |
55 | 54 | ||
56 | /* send 2st cmd and recieve data */ | 55 | /* send 2st cmd and receive data */ |
57 | /* | 56 | /* |
58 | * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 25.1.0(5) | 57 | * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 25.1.0(5) |
59 | * 16.0 DI 00 96 00 00 00 00 08 | 58 | * 16.0 DI 00 96 00 00 00 00 08 |
@@ -65,7 +64,7 @@ static int zte_ev_usb_serial_open(struct tty_struct *tty, | |||
65 | USB_CTRL_GET_TIMEOUT); | 64 | USB_CTRL_GET_TIMEOUT); |
66 | debug_data(dev, __func__, len, buf, result); | 65 | debug_data(dev, __func__, len, buf, result); |
67 | 66 | ||
68 | /* send 3 cmd */ | 67 | /* send 3rd cmd */ |
69 | /* | 68 | /* |
70 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 30.1.0 | 69 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 30.1.0 |
71 | * 16.0 DO 80 25 00 00 00 00 08 .%..... 30.2.0 | 70 | * 16.0 DO 80 25 00 00 00 00 08 .%..... 30.2.0 |
@@ -84,7 +83,7 @@ static int zte_ev_usb_serial_open(struct tty_struct *tty, | |||
84 | USB_CTRL_GET_TIMEOUT); | 83 | USB_CTRL_GET_TIMEOUT); |
85 | debug_data(dev, __func__, len, buf, result); | 84 | debug_data(dev, __func__, len, buf, result); |
86 | 85 | ||
87 | /* send 4 cmd */ | 86 | /* send 4th cmd */ |
88 | /* | 87 | /* |
89 | * 16.0 CTL 21 22 03 00 00 00 00 00 | 88 | * 16.0 CTL 21 22 03 00 00 00 00 00 |
90 | */ | 89 | */ |
@@ -95,7 +94,7 @@ static int zte_ev_usb_serial_open(struct tty_struct *tty, | |||
95 | USB_CTRL_GET_TIMEOUT); | 94 | USB_CTRL_GET_TIMEOUT); |
96 | dev_dbg(dev, "result = %d\n", result); | 95 | dev_dbg(dev, "result = %d\n", result); |
97 | 96 | ||
98 | /* send 5 cmd */ | 97 | /* send 5th cmd */ |
99 | /* | 98 | /* |
100 | * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 33.1.0 | 99 | * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 33.1.0 |
101 | * 16.0 DI 80 25 00 00 00 00 08 | 100 | * 16.0 DI 80 25 00 00 00 00 08 |
@@ -107,7 +106,7 @@ static int zte_ev_usb_serial_open(struct tty_struct *tty, | |||
107 | USB_CTRL_GET_TIMEOUT); | 106 | USB_CTRL_GET_TIMEOUT); |
108 | debug_data(dev, __func__, len, buf, result); | 107 | debug_data(dev, __func__, len, buf, result); |
109 | 108 | ||
110 | /* send 6 cmd */ | 109 | /* send 6th cmd */ |
111 | /* | 110 | /* |
112 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 34.1.0 | 111 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 34.1.0 |
113 | * 16.0 DO 80 25 00 00 00 00 08 | 112 | * 16.0 DO 80 25 00 00 00 00 08 |
@@ -195,7 +194,7 @@ static void zte_ev_usb_serial_close(struct usb_serial_port *port) | |||
195 | USB_CTRL_GET_TIMEOUT); | 194 | USB_CTRL_GET_TIMEOUT); |
196 | debug_data(dev, __func__, len, buf, result); | 195 | debug_data(dev, __func__, len, buf, result); |
197 | 196 | ||
198 | /* send 4 cmd */ | 197 | /* send 4th cmd */ |
199 | /* | 198 | /* |
200 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 30.1.0 | 199 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 30.1.0 |
201 | * 16.0 DO 00 c2 01 00 00 00 08 .%..... 30.2.0 | 200 | * 16.0 DO 00 c2 01 00 00 00 08 .%..... 30.2.0 |
@@ -214,7 +213,7 @@ static void zte_ev_usb_serial_close(struct usb_serial_port *port) | |||
214 | USB_CTRL_GET_TIMEOUT); | 213 | USB_CTRL_GET_TIMEOUT); |
215 | debug_data(dev, __func__, len, buf, result); | 214 | debug_data(dev, __func__, len, buf, result); |
216 | 215 | ||
217 | /* send 5 cmd */ | 216 | /* send 5th cmd */ |
218 | /* | 217 | /* |
219 | * 16.0 CTL 21 22 03 00 00 00 00 00 | 218 | * 16.0 CTL 21 22 03 00 00 00 00 00 |
220 | */ | 219 | */ |
@@ -225,7 +224,7 @@ static void zte_ev_usb_serial_close(struct usb_serial_port *port) | |||
225 | USB_CTRL_GET_TIMEOUT); | 224 | USB_CTRL_GET_TIMEOUT); |
226 | dev_dbg(dev, "result = %d\n", result); | 225 | dev_dbg(dev, "result = %d\n", result); |
227 | 226 | ||
228 | /* send 6 cmd */ | 227 | /* send 6th cmd */ |
229 | /* | 228 | /* |
230 | * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 33.1.0 | 229 | * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 33.1.0 |
231 | * 16.0 DI 00 c2 01 00 00 00 08 | 230 | * 16.0 DI 00 c2 01 00 00 00 08 |
@@ -237,7 +236,7 @@ static void zte_ev_usb_serial_close(struct usb_serial_port *port) | |||
237 | USB_CTRL_GET_TIMEOUT); | 236 | USB_CTRL_GET_TIMEOUT); |
238 | debug_data(dev, __func__, len, buf, result); | 237 | debug_data(dev, __func__, len, buf, result); |
239 | 238 | ||
240 | /* send 7 cmd */ | 239 | /* send 7th cmd */ |
241 | /* | 240 | /* |
242 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 354.1.0 | 241 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 354.1.0 |
243 | * 16.0 DO 00 c2 01 00 00 00 08 ....... 354.2.0 | 242 | * 16.0 DO 00 c2 01 00 00 00 08 ....... 354.2.0 |
@@ -256,7 +255,7 @@ static void zte_ev_usb_serial_close(struct usb_serial_port *port) | |||
256 | USB_CTRL_GET_TIMEOUT); | 255 | USB_CTRL_GET_TIMEOUT); |
257 | debug_data(dev, __func__, len, buf, result); | 256 | debug_data(dev, __func__, len, buf, result); |
258 | 257 | ||
259 | /* send 8 cmd */ | 258 | /* send 8th cmd */ |
260 | /* | 259 | /* |
261 | * 16.0 CTL 21 22 03 00 00 00 00 00 | 260 | * 16.0 CTL 21 22 03 00 00 00 00 00 |
262 | */ | 261 | */ |
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c index 26964895c88b..74e2aa23b045 100644 --- a/drivers/usb/storage/onetouch.c +++ b/drivers/usb/storage/onetouch.c | |||
@@ -30,7 +30,6 @@ | |||
30 | 30 | ||
31 | #include <linux/kernel.h> | 31 | #include <linux/kernel.h> |
32 | #include <linux/input.h> | 32 | #include <linux/input.h> |
33 | #include <linux/init.h> | ||
34 | #include <linux/slab.h> | 33 | #include <linux/slab.h> |
35 | #include <linux/module.h> | 34 | #include <linux/module.h> |
36 | #include <linux/usb/input.h> | 35 | #include <linux/usb/input.h> |
diff --git a/drivers/usb/storage/protocol.c b/drivers/usb/storage/protocol.c index 5dfb4c36a1b0..12e3c2fac642 100644 --- a/drivers/usb/storage/protocol.c +++ b/drivers/usb/storage/protocol.c | |||
@@ -135,69 +135,42 @@ unsigned int usb_stor_access_xfer_buf(unsigned char *buffer, | |||
135 | unsigned int buflen, struct scsi_cmnd *srb, struct scatterlist **sgptr, | 135 | unsigned int buflen, struct scsi_cmnd *srb, struct scatterlist **sgptr, |
136 | unsigned int *offset, enum xfer_buf_dir dir) | 136 | unsigned int *offset, enum xfer_buf_dir dir) |
137 | { | 137 | { |
138 | unsigned int cnt; | 138 | unsigned int cnt = 0; |
139 | struct scatterlist *sg = *sgptr; | 139 | struct scatterlist *sg = *sgptr; |
140 | struct sg_mapping_iter miter; | ||
141 | unsigned int nents = scsi_sg_count(srb); | ||
140 | 142 | ||
141 | /* We have to go through the list one entry | 143 | if (sg) |
142 | * at a time. Each s-g entry contains some number of pages, and | 144 | nents = sg_nents(sg); |
143 | * each page has to be kmap()'ed separately. If the page is already | 145 | else |
144 | * in kernel-addressable memory then kmap() will return its address. | ||
145 | * If the page is not directly accessible -- such as a user buffer | ||
146 | * located in high memory -- then kmap() will map it to a temporary | ||
147 | * position in the kernel's virtual address space. | ||
148 | */ | ||
149 | |||
150 | if (!sg) | ||
151 | sg = scsi_sglist(srb); | 146 | sg = scsi_sglist(srb); |
152 | 147 | ||
153 | /* This loop handles a single s-g list entry, which may | 148 | sg_miter_start(&miter, sg, nents, dir == FROM_XFER_BUF ? |
154 | * include multiple pages. Find the initial page structure | 149 | SG_MITER_FROM_SG: SG_MITER_TO_SG); |
155 | * and the starting offset within the page, and update | ||
156 | * the *offset and **sgptr values for the next loop. | ||
157 | */ | ||
158 | cnt = 0; | ||
159 | while (cnt < buflen && sg) { | ||
160 | struct page *page = sg_page(sg) + | ||
161 | ((sg->offset + *offset) >> PAGE_SHIFT); | ||
162 | unsigned int poff = (sg->offset + *offset) & (PAGE_SIZE-1); | ||
163 | unsigned int sglen = sg->length - *offset; | ||
164 | |||
165 | if (sglen > buflen - cnt) { | ||
166 | |||
167 | /* Transfer ends within this s-g entry */ | ||
168 | sglen = buflen - cnt; | ||
169 | *offset += sglen; | ||
170 | } else { | ||
171 | 150 | ||
172 | /* Transfer continues to next s-g entry */ | 151 | if (!sg_miter_skip(&miter, *offset)) |
173 | *offset = 0; | 152 | return cnt; |
174 | sg = sg_next(sg); | 153 | |
175 | } | 154 | while (sg_miter_next(&miter) && cnt < buflen) { |
155 | unsigned int len = min_t(unsigned int, miter.length, | ||
156 | buflen - cnt); | ||
157 | |||
158 | if (dir == FROM_XFER_BUF) | ||
159 | memcpy(buffer + cnt, miter.addr, len); | ||
160 | else | ||
161 | memcpy(miter.addr, buffer + cnt, len); | ||
176 | 162 | ||
177 | /* Transfer the data for all the pages in this | 163 | if (*offset + len < miter.piter.sg->length) { |
178 | * s-g entry. For each page: call kmap(), do the | 164 | *offset += len; |
179 | * transfer, and call kunmap() immediately after. */ | 165 | *sgptr = miter.piter.sg; |
180 | while (sglen > 0) { | 166 | } else { |
181 | unsigned int plen = min(sglen, (unsigned int) | 167 | *offset = 0; |
182 | PAGE_SIZE - poff); | 168 | *sgptr = sg_next(miter.piter.sg); |
183 | unsigned char *ptr = kmap(page); | ||
184 | |||
185 | if (dir == TO_XFER_BUF) | ||
186 | memcpy(ptr + poff, buffer + cnt, plen); | ||
187 | else | ||
188 | memcpy(buffer + cnt, ptr + poff, plen); | ||
189 | kunmap(page); | ||
190 | |||
191 | /* Start at the beginning of the next page */ | ||
192 | poff = 0; | ||
193 | ++page; | ||
194 | cnt += plen; | ||
195 | sglen -= plen; | ||
196 | } | 169 | } |
170 | cnt += len; | ||
197 | } | 171 | } |
198 | *sgptr = sg; | 172 | sg_miter_stop(&miter); |
199 | 173 | ||
200 | /* Return the amount actually transferred */ | ||
201 | return cnt; | 174 | return cnt; |
202 | } | 175 | } |
203 | EXPORT_SYMBOL_GPL(usb_stor_access_xfer_buf); | 176 | EXPORT_SYMBOL_GPL(usb_stor_access_xfer_buf); |
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h index de32cfa5bfa6..ad06255c2ade 100644 --- a/drivers/usb/storage/unusual_devs.h +++ b/drivers/usb/storage/unusual_devs.h | |||
@@ -234,6 +234,13 @@ UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370, | |||
234 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, | 234 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, |
235 | US_FL_MAX_SECTORS_64 ), | 235 | US_FL_MAX_SECTORS_64 ), |
236 | 236 | ||
237 | /* Patch submitted by Mikhail Zolotaryov <lebon@lebon.org.ua> */ | ||
238 | UNUSUAL_DEV( 0x0421, 0x06aa, 0x1110, 0x1110, | ||
239 | "Nokia", | ||
240 | "502", | ||
241 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, | ||
242 | US_FL_MAX_SECTORS_64 ), | ||
243 | |||
237 | #ifdef NO_SDDR09 | 244 | #ifdef NO_SDDR09 |
238 | UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100, | 245 | UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100, |
239 | "Microtech", | 246 | "Microtech", |
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 5c4fe0749af1..1c0b89f2a138 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c | |||
@@ -53,7 +53,6 @@ | |||
53 | #include <linux/errno.h> | 53 | #include <linux/errno.h> |
54 | #include <linux/freezer.h> | 54 | #include <linux/freezer.h> |
55 | #include <linux/module.h> | 55 | #include <linux/module.h> |
56 | #include <linux/init.h> | ||
57 | #include <linux/slab.h> | 56 | #include <linux/slab.h> |
58 | #include <linux/kthread.h> | 57 | #include <linux/kthread.h> |
59 | #include <linux/mutex.h> | 58 | #include <linux/mutex.h> |
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c index ff97652343a3..545d09b8081d 100644 --- a/drivers/usb/usb-skeleton.c +++ b/drivers/usb/usb-skeleton.c | |||
@@ -14,7 +14,6 @@ | |||
14 | 14 | ||
15 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
16 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
17 | #include <linux/init.h> | ||
18 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
19 | #include <linux/module.h> | 18 | #include <linux/module.h> |
20 | #include <linux/kref.h> | 19 | #include <linux/kref.h> |
diff --git a/drivers/usb/wusbcore/cbaf.c b/drivers/usb/wusbcore/cbaf.c index f06ed82e63d1..da1b872918b5 100644 --- a/drivers/usb/wusbcore/cbaf.c +++ b/drivers/usb/wusbcore/cbaf.c | |||
@@ -144,7 +144,7 @@ static int cbaf_check(struct cbaf *cbaf) | |||
144 | CBAF_REQ_GET_ASSOCIATION_INFORMATION, | 144 | CBAF_REQ_GET_ASSOCIATION_INFORMATION, |
145 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 145 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
146 | 0, cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber, | 146 | 0, cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber, |
147 | cbaf->buffer, cbaf->buffer_size, 1000 /* FIXME: arbitrary */); | 147 | cbaf->buffer, cbaf->buffer_size, USB_CTRL_GET_TIMEOUT); |
148 | if (result < 0) { | 148 | if (result < 0) { |
149 | dev_err(dev, "Cannot get available association types: %d\n", | 149 | dev_err(dev, "Cannot get available association types: %d\n", |
150 | result); | 150 | result); |
@@ -184,7 +184,7 @@ static int cbaf_check(struct cbaf *cbaf) | |||
184 | assoc_request = itr; | 184 | assoc_request = itr; |
185 | 185 | ||
186 | if (top - itr < sizeof(*assoc_request)) { | 186 | if (top - itr < sizeof(*assoc_request)) { |
187 | dev_err(dev, "Not enough data to decode associaton " | 187 | dev_err(dev, "Not enough data to decode association " |
188 | "request (%zu vs %zu bytes needed)\n", | 188 | "request (%zu vs %zu bytes needed)\n", |
189 | top - itr, sizeof(*assoc_request)); | 189 | top - itr, sizeof(*assoc_request)); |
190 | break; | 190 | break; |
@@ -235,7 +235,7 @@ static int cbaf_check(struct cbaf *cbaf) | |||
235 | 235 | ||
236 | static const struct wusb_cbaf_host_info cbaf_host_info_defaults = { | 236 | static const struct wusb_cbaf_host_info cbaf_host_info_defaults = { |
237 | .AssociationTypeId_hdr = WUSB_AR_AssociationTypeId, | 237 | .AssociationTypeId_hdr = WUSB_AR_AssociationTypeId, |
238 | .AssociationTypeId = cpu_to_le16(AR_TYPE_WUSB), | 238 | .AssociationTypeId = cpu_to_le16(AR_TYPE_WUSB), |
239 | .AssociationSubTypeId_hdr = WUSB_AR_AssociationSubTypeId, | 239 | .AssociationSubTypeId_hdr = WUSB_AR_AssociationSubTypeId, |
240 | .AssociationSubTypeId = cpu_to_le16(AR_TYPE_WUSB_RETRIEVE_HOST_INFO), | 240 | .AssociationSubTypeId = cpu_to_le16(AR_TYPE_WUSB_RETRIEVE_HOST_INFO), |
241 | .CHID_hdr = WUSB_AR_CHID, | 241 | .CHID_hdr = WUSB_AR_CHID, |
@@ -260,12 +260,13 @@ static int cbaf_send_host_info(struct cbaf *cbaf) | |||
260 | hi->HostFriendlyName_hdr.len = cpu_to_le16(name_len); | 260 | hi->HostFriendlyName_hdr.len = cpu_to_le16(name_len); |
261 | hi_size = sizeof(*hi) + name_len; | 261 | hi_size = sizeof(*hi) + name_len; |
262 | 262 | ||
263 | return usb_control_msg(cbaf->usb_dev, usb_sndctrlpipe(cbaf->usb_dev, 0), | 263 | return usb_control_msg(cbaf->usb_dev, |
264 | usb_sndctrlpipe(cbaf->usb_dev, 0), | ||
264 | CBAF_REQ_SET_ASSOCIATION_RESPONSE, | 265 | CBAF_REQ_SET_ASSOCIATION_RESPONSE, |
265 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 266 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
266 | 0x0101, | 267 | 0x0101, |
267 | cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber, | 268 | cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber, |
268 | hi, hi_size, 1000 /* FIXME: arbitrary */); | 269 | hi, hi_size, USB_CTRL_SET_TIMEOUT); |
269 | } | 270 | } |
270 | 271 | ||
271 | /* | 272 | /* |
@@ -288,9 +289,10 @@ static int cbaf_cdid_get(struct cbaf *cbaf) | |||
288 | CBAF_REQ_GET_ASSOCIATION_REQUEST, | 289 | CBAF_REQ_GET_ASSOCIATION_REQUEST, |
289 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 290 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
290 | 0x0200, cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber, | 291 | 0x0200, cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber, |
291 | di, cbaf->buffer_size, 1000 /* FIXME: arbitrary */); | 292 | di, cbaf->buffer_size, USB_CTRL_GET_TIMEOUT); |
292 | if (result < 0) { | 293 | if (result < 0) { |
293 | dev_err(dev, "Cannot request device information: %d\n", result); | 294 | dev_err(dev, "Cannot request device information: %d\n", |
295 | result); | ||
294 | return result; | 296 | return result; |
295 | } | 297 | } |
296 | 298 | ||
@@ -491,11 +493,11 @@ static DEVICE_ATTR(wusb_device_name, 0600, cbaf_wusb_device_name_show, NULL); | |||
491 | 493 | ||
492 | static const struct wusb_cbaf_cc_data cbaf_cc_data_defaults = { | 494 | static const struct wusb_cbaf_cc_data cbaf_cc_data_defaults = { |
493 | .AssociationTypeId_hdr = WUSB_AR_AssociationTypeId, | 495 | .AssociationTypeId_hdr = WUSB_AR_AssociationTypeId, |
494 | .AssociationTypeId = cpu_to_le16(AR_TYPE_WUSB), | 496 | .AssociationTypeId = cpu_to_le16(AR_TYPE_WUSB), |
495 | .AssociationSubTypeId_hdr = WUSB_AR_AssociationSubTypeId, | 497 | .AssociationSubTypeId_hdr = WUSB_AR_AssociationSubTypeId, |
496 | .AssociationSubTypeId = cpu_to_le16(AR_TYPE_WUSB_ASSOCIATE), | 498 | .AssociationSubTypeId = cpu_to_le16(AR_TYPE_WUSB_ASSOCIATE), |
497 | .Length_hdr = WUSB_AR_Length, | 499 | .Length_hdr = WUSB_AR_Length, |
498 | .Length = cpu_to_le32(sizeof(struct wusb_cbaf_cc_data)), | 500 | .Length = cpu_to_le32(sizeof(struct wusb_cbaf_cc_data)), |
499 | .ConnectionContext_hdr = WUSB_AR_ConnectionContext, | 501 | .ConnectionContext_hdr = WUSB_AR_ConnectionContext, |
500 | .BandGroups_hdr = WUSB_AR_BandGroups, | 502 | .BandGroups_hdr = WUSB_AR_BandGroups, |
501 | }; | 503 | }; |
@@ -536,7 +538,7 @@ static int cbaf_cc_upload(struct cbaf *cbaf) | |||
536 | CBAF_REQ_SET_ASSOCIATION_RESPONSE, | 538 | CBAF_REQ_SET_ASSOCIATION_RESPONSE, |
537 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 539 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
538 | 0x0201, cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber, | 540 | 0x0201, cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber, |
539 | ccd, sizeof(*ccd), 1000 /* FIXME: arbitrary */); | 541 | ccd, sizeof(*ccd), USB_CTRL_SET_TIMEOUT); |
540 | 542 | ||
541 | return result; | 543 | return result; |
542 | } | 544 | } |
diff --git a/drivers/usb/wusbcore/crypto.c b/drivers/usb/wusbcore/crypto.c index 7e4bf95f8f7b..9a95b2dc6d1b 100644 --- a/drivers/usb/wusbcore/crypto.c +++ b/drivers/usb/wusbcore/crypto.c | |||
@@ -87,7 +87,7 @@ struct aes_ccm_block { | |||
87 | * B1 contains l(a), the MAC header, the encryption offset and padding. | 87 | * B1 contains l(a), the MAC header, the encryption offset and padding. |
88 | * | 88 | * |
89 | * If EO is nonzero, additional blocks are built from payload bytes | 89 | * If EO is nonzero, additional blocks are built from payload bytes |
90 | * until EO is exahusted (FIXME: padding to 16 bytes, I guess). The | 90 | * until EO is exhausted (FIXME: padding to 16 bytes, I guess). The |
91 | * padding is not xmitted. | 91 | * padding is not xmitted. |
92 | */ | 92 | */ |
93 | 93 | ||
diff --git a/drivers/usb/wusbcore/devconnect.c b/drivers/usb/wusbcore/devconnect.c index f14e7929ba22..3b959e83b28e 100644 --- a/drivers/usb/wusbcore/devconnect.c +++ b/drivers/usb/wusbcore/devconnect.c | |||
@@ -265,9 +265,9 @@ static void wusbhc_devconnect_acked_work(struct work_struct *work) | |||
265 | * Addresses: because WUSB hosts have no downstream hubs, we can do a | 265 | * Addresses: because WUSB hosts have no downstream hubs, we can do a |
266 | * 1:1 mapping between 'port number' and device | 266 | * 1:1 mapping between 'port number' and device |
267 | * address. This simplifies many things, as during this | 267 | * address. This simplifies many things, as during this |
268 | * initial connect phase the USB stack has no knoledge of | 268 | * initial connect phase the USB stack has no knowledge of |
269 | * the device and hasn't assigned an address yet--we know | 269 | * the device and hasn't assigned an address yet--we know |
270 | * USB's choose_address() will use the same euristics we | 270 | * USB's choose_address() will use the same heuristics we |
271 | * use here, so we can assume which address will be assigned. | 271 | * use here, so we can assume which address will be assigned. |
272 | * | 272 | * |
273 | * USB stack always assigns address 1 to the root hub, so | 273 | * USB stack always assigns address 1 to the root hub, so |
diff --git a/drivers/usb/wusbcore/mmc.c b/drivers/usb/wusbcore/mmc.c index b71760c8d3ad..44741267c917 100644 --- a/drivers/usb/wusbcore/mmc.c +++ b/drivers/usb/wusbcore/mmc.c | |||
@@ -206,13 +206,15 @@ int wusbhc_start(struct wusbhc *wusbhc) | |||
206 | 206 | ||
207 | result = wusbhc_devconnect_start(wusbhc); | 207 | result = wusbhc_devconnect_start(wusbhc); |
208 | if (result < 0) { | 208 | if (result < 0) { |
209 | dev_err(dev, "error enabling device connections: %d\n", result); | 209 | dev_err(dev, "error enabling device connections: %d\n", |
210 | result); | ||
210 | goto error_devconnect_start; | 211 | goto error_devconnect_start; |
211 | } | 212 | } |
212 | 213 | ||
213 | result = wusbhc_sec_start(wusbhc); | 214 | result = wusbhc_sec_start(wusbhc); |
214 | if (result < 0) { | 215 | if (result < 0) { |
215 | dev_err(dev, "error starting security in the HC: %d\n", result); | 216 | dev_err(dev, "error starting security in the HC: %d\n", |
217 | result); | ||
216 | goto error_sec_start; | 218 | goto error_sec_start; |
217 | } | 219 | } |
218 | 220 | ||
@@ -284,7 +286,8 @@ int wusbhc_chid_set(struct wusbhc *wusbhc, const struct wusb_ckhdid *chid) | |||
284 | wusbhc->uwb_rc = uwb_rc_get_by_grandpa(wusbhc->dev->parent); | 286 | wusbhc->uwb_rc = uwb_rc_get_by_grandpa(wusbhc->dev->parent); |
285 | if (wusbhc->uwb_rc == NULL) { | 287 | if (wusbhc->uwb_rc == NULL) { |
286 | result = -ENODEV; | 288 | result = -ENODEV; |
287 | dev_err(wusbhc->dev, "Cannot get associated UWB Host Controller\n"); | 289 | dev_err(wusbhc->dev, |
290 | "Cannot get associated UWB Host Controller\n"); | ||
288 | goto error_rc_get; | 291 | goto error_rc_get; |
289 | } | 292 | } |
290 | 293 | ||
diff --git a/drivers/usb/wusbcore/pal.c b/drivers/usb/wusbcore/pal.c index 59e100c2eb50..090f27371a8f 100644 --- a/drivers/usb/wusbcore/pal.c +++ b/drivers/usb/wusbcore/pal.c | |||
@@ -22,6 +22,7 @@ static void wusbhc_channel_changed(struct uwb_pal *pal, int channel) | |||
22 | { | 22 | { |
23 | struct wusbhc *wusbhc = container_of(pal, struct wusbhc, pal); | 23 | struct wusbhc *wusbhc = container_of(pal, struct wusbhc, pal); |
24 | 24 | ||
25 | dev_dbg(wusbhc->dev, "%s: channel = %d\n", __func__, channel); | ||
25 | if (channel < 0) | 26 | if (channel < 0) |
26 | wusbhc_stop(wusbhc); | 27 | wusbhc_stop(wusbhc); |
27 | else | 28 | else |
diff --git a/drivers/usb/wusbcore/reservation.c b/drivers/usb/wusbcore/reservation.c index ead79f793927..d5efd0f07d2b 100644 --- a/drivers/usb/wusbcore/reservation.c +++ b/drivers/usb/wusbcore/reservation.c | |||
@@ -51,6 +51,7 @@ static void wusbhc_rsv_complete_cb(struct uwb_rsv *rsv) | |||
51 | struct uwb_mas_bm mas; | 51 | struct uwb_mas_bm mas; |
52 | char buf[72]; | 52 | char buf[72]; |
53 | 53 | ||
54 | dev_dbg(dev, "%s: state = %d\n", __func__, rsv->state); | ||
54 | switch (rsv->state) { | 55 | switch (rsv->state) { |
55 | case UWB_RSV_STATE_O_ESTABLISHED: | 56 | case UWB_RSV_STATE_O_ESTABLISHED: |
56 | uwb_rsv_get_usable_mas(rsv, &mas); | 57 | uwb_rsv_get_usable_mas(rsv, &mas); |
diff --git a/drivers/usb/wusbcore/security.c b/drivers/usb/wusbcore/security.c index 4c40d0dbf53d..95be9953cd47 100644 --- a/drivers/usb/wusbcore/security.c +++ b/drivers/usb/wusbcore/security.c | |||
@@ -33,7 +33,8 @@ static void wusbhc_gtk_rekey_work(struct work_struct *work); | |||
33 | 33 | ||
34 | int wusbhc_sec_create(struct wusbhc *wusbhc) | 34 | int wusbhc_sec_create(struct wusbhc *wusbhc) |
35 | { | 35 | { |
36 | wusbhc->gtk.descr.bLength = sizeof(wusbhc->gtk.descr) + sizeof(wusbhc->gtk.data); | 36 | wusbhc->gtk.descr.bLength = sizeof(wusbhc->gtk.descr) + |
37 | sizeof(wusbhc->gtk.data); | ||
37 | wusbhc->gtk.descr.bDescriptorType = USB_DT_KEY; | 38 | wusbhc->gtk.descr.bDescriptorType = USB_DT_KEY; |
38 | wusbhc->gtk.descr.bReserved = 0; | 39 | wusbhc->gtk.descr.bReserved = 0; |
39 | wusbhc->gtk_index = 0; | 40 | wusbhc->gtk_index = 0; |
@@ -56,7 +57,7 @@ void wusbhc_sec_destroy(struct wusbhc *wusbhc) | |||
56 | * @wusb_dev: the device whose PTK the TKID is for | 57 | * @wusb_dev: the device whose PTK the TKID is for |
57 | * (or NULL for a TKID for a GTK) | 58 | * (or NULL for a TKID for a GTK) |
58 | * | 59 | * |
59 | * The generated TKID consist of two parts: the device's authenicated | 60 | * The generated TKID consists of two parts: the device's authenticated |
60 | * address (or 0 or a GTK); and an incrementing number. This ensures | 61 | * address (or 0 or a GTK); and an incrementing number. This ensures |
61 | * that TKIDs cannot be shared between devices and by the time the | 62 | * that TKIDs cannot be shared between devices and by the time the |
62 | * incrementing number wraps around the older TKIDs will no longer be | 63 | * incrementing number wraps around the older TKIDs will no longer be |
@@ -138,7 +139,7 @@ const char *wusb_et_name(u8 x) | |||
138 | case USB_ENC_TYPE_WIRED: return "wired"; | 139 | case USB_ENC_TYPE_WIRED: return "wired"; |
139 | case USB_ENC_TYPE_CCM_1: return "CCM-1"; | 140 | case USB_ENC_TYPE_CCM_1: return "CCM-1"; |
140 | case USB_ENC_TYPE_RSA_1: return "RSA-1"; | 141 | case USB_ENC_TYPE_RSA_1: return "RSA-1"; |
141 | default: return "unknown"; | 142 | default: return "unknown"; |
142 | } | 143 | } |
143 | } | 144 | } |
144 | EXPORT_SYMBOL_GPL(wusb_et_name); | 145 | EXPORT_SYMBOL_GPL(wusb_et_name); |
@@ -165,7 +166,7 @@ static int wusb_dev_set_encryption(struct usb_device *usb_dev, int value) | |||
165 | result = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), | 166 | result = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
166 | USB_REQ_SET_ENCRYPTION, | 167 | USB_REQ_SET_ENCRYPTION, |
167 | USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, | 168 | USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, |
168 | value, 0, NULL, 0, 1000 /* FIXME: arbitrary */); | 169 | value, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); |
169 | if (result < 0) | 170 | if (result < 0) |
170 | dev_err(dev, "Can't set device's WUSB encryption to " | 171 | dev_err(dev, "Can't set device's WUSB encryption to " |
171 | "%s (value %d): %d\n", | 172 | "%s (value %d): %d\n", |
@@ -191,7 +192,7 @@ static int wusb_dev_set_gtk(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev) | |||
191 | USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, | 192 | USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, |
192 | USB_DT_KEY << 8 | key_index, 0, | 193 | USB_DT_KEY << 8 | key_index, 0, |
193 | &wusbhc->gtk.descr, wusbhc->gtk.descr.bLength, | 194 | &wusbhc->gtk.descr, wusbhc->gtk.descr.bLength, |
194 | 1000); | 195 | USB_CTRL_SET_TIMEOUT); |
195 | } | 196 | } |
196 | 197 | ||
197 | 198 | ||
@@ -222,7 +223,8 @@ int wusb_dev_sec_add(struct wusbhc *wusbhc, | |||
222 | secd_size = le16_to_cpu(secd->wTotalLength); | 223 | secd_size = le16_to_cpu(secd->wTotalLength); |
223 | new_secd = krealloc(secd, secd_size, GFP_KERNEL); | 224 | new_secd = krealloc(secd, secd_size, GFP_KERNEL); |
224 | if (new_secd == NULL) { | 225 | if (new_secd == NULL) { |
225 | dev_err(dev, "Can't allocate space for security descriptors\n"); | 226 | dev_err(dev, |
227 | "Can't allocate space for security descriptors\n"); | ||
226 | goto out; | 228 | goto out; |
227 | } | 229 | } |
228 | secd = new_secd; | 230 | secd = new_secd; |
@@ -301,8 +303,9 @@ int wusb_dev_update_address(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev) | |||
301 | 303 | ||
302 | /* Set address 0 */ | 304 | /* Set address 0 */ |
303 | result = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), | 305 | result = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
304 | USB_REQ_SET_ADDRESS, 0, | 306 | USB_REQ_SET_ADDRESS, |
305 | 0, 0, NULL, 0, 1000 /* FIXME: arbitrary */); | 307 | USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, |
308 | 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); | ||
306 | if (result < 0) { | 309 | if (result < 0) { |
307 | dev_err(dev, "auth failed: can't set address 0: %d\n", | 310 | dev_err(dev, "auth failed: can't set address 0: %d\n", |
308 | result); | 311 | result); |
@@ -316,9 +319,10 @@ int wusb_dev_update_address(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev) | |||
316 | 319 | ||
317 | /* Set new (authenticated) address. */ | 320 | /* Set new (authenticated) address. */ |
318 | result = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), | 321 | result = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
319 | USB_REQ_SET_ADDRESS, 0, | 322 | USB_REQ_SET_ADDRESS, |
320 | new_address, 0, NULL, 0, | 323 | USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, |
321 | 1000 /* FIXME: arbitrary */); | 324 | new_address, 0, NULL, 0, |
325 | USB_CTRL_SET_TIMEOUT); | ||
322 | if (result < 0) { | 326 | if (result < 0) { |
323 | dev_err(dev, "auth failed: can't set address %u: %d\n", | 327 | dev_err(dev, "auth failed: can't set address %u: %d\n", |
324 | new_address, result); | 328 | new_address, result); |
@@ -375,13 +379,13 @@ int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev, | |||
375 | hs[0].bReserved = 0; | 379 | hs[0].bReserved = 0; |
376 | memcpy(hs[0].CDID, &wusb_dev->cdid, sizeof(hs[0].CDID)); | 380 | memcpy(hs[0].CDID, &wusb_dev->cdid, sizeof(hs[0].CDID)); |
377 | get_random_bytes(&hs[0].nonce, sizeof(hs[0].nonce)); | 381 | get_random_bytes(&hs[0].nonce, sizeof(hs[0].nonce)); |
378 | memset(hs[0].MIC, 0, sizeof(hs[0].MIC)); /* Per WUSB1.0[T7-22] */ | 382 | memset(hs[0].MIC, 0, sizeof(hs[0].MIC)); /* Per WUSB1.0[T7-22] */ |
379 | 383 | ||
380 | result = usb_control_msg( | 384 | result = usb_control_msg( |
381 | usb_dev, usb_sndctrlpipe(usb_dev, 0), | 385 | usb_dev, usb_sndctrlpipe(usb_dev, 0), |
382 | USB_REQ_SET_HANDSHAKE, | 386 | USB_REQ_SET_HANDSHAKE, |
383 | USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, | 387 | USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, |
384 | 1, 0, &hs[0], sizeof(hs[0]), 1000 /* FIXME: arbitrary */); | 388 | 1, 0, &hs[0], sizeof(hs[0]), USB_CTRL_SET_TIMEOUT); |
385 | if (result < 0) { | 389 | if (result < 0) { |
386 | dev_err(dev, "Handshake1: request failed: %d\n", result); | 390 | dev_err(dev, "Handshake1: request failed: %d\n", result); |
387 | goto error_hs1; | 391 | goto error_hs1; |
@@ -392,7 +396,7 @@ int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev, | |||
392 | usb_dev, usb_rcvctrlpipe(usb_dev, 0), | 396 | usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
393 | USB_REQ_GET_HANDSHAKE, | 397 | USB_REQ_GET_HANDSHAKE, |
394 | USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE, | 398 | USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE, |
395 | 2, 0, &hs[1], sizeof(hs[1]), 1000 /* FIXME: arbitrary */); | 399 | 2, 0, &hs[1], sizeof(hs[1]), USB_CTRL_GET_TIMEOUT); |
396 | if (result < 0) { | 400 | if (result < 0) { |
397 | dev_err(dev, "Handshake2: request failed: %d\n", result); | 401 | dev_err(dev, "Handshake2: request failed: %d\n", result); |
398 | goto error_hs2; | 402 | goto error_hs2; |
@@ -422,7 +426,7 @@ int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev, | |||
422 | } | 426 | } |
423 | 427 | ||
424 | /* Setup the CCM nonce */ | 428 | /* Setup the CCM nonce */ |
425 | memset(&ccm_n.sfn, 0, sizeof(ccm_n.sfn)); /* Per WUSB1.0[6.5.2] */ | 429 | memset(&ccm_n.sfn, 0, sizeof(ccm_n.sfn)); /* Per WUSB1.0[6.5.2] */ |
426 | memcpy(ccm_n.tkid, &tkid_le, sizeof(ccm_n.tkid)); | 430 | memcpy(ccm_n.tkid, &tkid_le, sizeof(ccm_n.tkid)); |
427 | ccm_n.src_addr = wusbhc->uwb_rc->uwb_dev.dev_addr; | 431 | ccm_n.src_addr = wusbhc->uwb_rc->uwb_dev.dev_addr; |
428 | ccm_n.dest_addr.data[0] = wusb_dev->addr; | 432 | ccm_n.dest_addr.data[0] = wusb_dev->addr; |
@@ -469,7 +473,7 @@ int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev, | |||
469 | usb_dev, usb_sndctrlpipe(usb_dev, 0), | 473 | usb_dev, usb_sndctrlpipe(usb_dev, 0), |
470 | USB_REQ_SET_HANDSHAKE, | 474 | USB_REQ_SET_HANDSHAKE, |
471 | USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, | 475 | USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, |
472 | 3, 0, &hs[2], sizeof(hs[2]), 1000 /* FIXME: arbitrary */); | 476 | 3, 0, &hs[2], sizeof(hs[2]), USB_CTRL_SET_TIMEOUT); |
473 | if (result < 0) { | 477 | if (result < 0) { |
474 | dev_err(dev, "Handshake3: request failed: %d\n", result); | 478 | dev_err(dev, "Handshake3: request failed: %d\n", result); |
475 | goto error_hs3; | 479 | goto error_hs3; |
@@ -553,11 +557,13 @@ static void wusbhc_gtk_rekey_work(struct work_struct *work) | |||
553 | list_for_each_entry_safe(wusb_dev, wusb_dev_next, &rekey_list, | 557 | list_for_each_entry_safe(wusb_dev, wusb_dev_next, &rekey_list, |
554 | rekey_node) { | 558 | rekey_node) { |
555 | list_del_init(&wusb_dev->rekey_node); | 559 | list_del_init(&wusb_dev->rekey_node); |
556 | dev_dbg(&wusb_dev->usb_dev->dev, "%s: rekey device at port %d\n", | 560 | dev_dbg(&wusb_dev->usb_dev->dev, |
561 | "%s: rekey device at port %d\n", | ||
557 | __func__, wusb_dev->port_idx); | 562 | __func__, wusb_dev->port_idx); |
558 | 563 | ||
559 | if (wusb_dev_set_gtk(wusbhc, wusb_dev) < 0) { | 564 | if (wusb_dev_set_gtk(wusbhc, wusb_dev) < 0) { |
560 | dev_err(&wusb_dev->usb_dev->dev, "%s: rekey device at port %d failed\n", | 565 | dev_err(&wusb_dev->usb_dev->dev, |
566 | "%s: rekey device at port %d failed\n", | ||
561 | __func__, wusb_dev->port_idx); | 567 | __func__, wusb_dev->port_idx); |
562 | } | 568 | } |
563 | wusb_dev_put(wusb_dev); | 569 | wusb_dev_put(wusb_dev); |
diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h index e614f02f0cf2..a2ef84b8397e 100644 --- a/drivers/usb/wusbcore/wa-hc.h +++ b/drivers/usb/wusbcore/wa-hc.h | |||
@@ -36,7 +36,7 @@ | |||
36 | * | 36 | * |
37 | * hcd glue with the USB API Host Controller Interface API. | 37 | * hcd glue with the USB API Host Controller Interface API. |
38 | * | 38 | * |
39 | * nep Notification EndPoint managent: collect notifications | 39 | * nep Notification EndPoint management: collect notifications |
40 | * and queue them with the workqueue daemon. | 40 | * and queue them with the workqueue daemon. |
41 | * | 41 | * |
42 | * Handle notifications as coming from the NEP. Sends them | 42 | * Handle notifications as coming from the NEP. Sends them |
@@ -144,7 +144,7 @@ enum wa_quirks { | |||
144 | * | 144 | * |
145 | * @wa_descr Can be accessed without locking because it is in | 145 | * @wa_descr Can be accessed without locking because it is in |
146 | * the same area where the device descriptors were | 146 | * the same area where the device descriptors were |
147 | * read, so it is guaranteed to exist umodified while | 147 | * read, so it is guaranteed to exist unmodified while |
148 | * the device exists. | 148 | * the device exists. |
149 | * | 149 | * |
150 | * Endianess has been converted to CPU's. | 150 | * Endianess has been converted to CPU's. |
@@ -167,8 +167,8 @@ enum wa_quirks { | |||
167 | * submitted from an atomic context). | 167 | * submitted from an atomic context). |
168 | * | 168 | * |
169 | * FIXME: this needs to be layered up: a wusbhc layer (for sharing | 169 | * FIXME: this needs to be layered up: a wusbhc layer (for sharing |
170 | * comonalities with WHCI), a wa layer (for sharing | 170 | * commonalities with WHCI), a wa layer (for sharing |
171 | * comonalities with DWA-RC). | 171 | * commonalities with DWA-RC). |
172 | */ | 172 | */ |
173 | struct wahc { | 173 | struct wahc { |
174 | struct usb_device *usb_dev; | 174 | struct usb_device *usb_dev; |
@@ -197,10 +197,10 @@ struct wahc { | |||
197 | struct mutex rpipe_mutex; /* assigning resources to endpoints */ | 197 | struct mutex rpipe_mutex; /* assigning resources to endpoints */ |
198 | 198 | ||
199 | /* | 199 | /* |
200 | * dti_state is used to track the state of the dti_urb. When dti_state | 200 | * dti_state is used to track the state of the dti_urb. When dti_state |
201 | * is WA_DTI_ISOC_PACKET_STATUS_PENDING, dti_isoc_xfer_in_progress and | 201 | * is WA_DTI_ISOC_PACKET_STATUS_PENDING, dti_isoc_xfer_in_progress and |
202 | * dti_isoc_xfer_seg identify which xfer the incoming isoc packet status | 202 | * dti_isoc_xfer_seg identify which xfer the incoming isoc packet |
203 | * refers to. | 203 | * status refers to. |
204 | */ | 204 | */ |
205 | enum wa_dti_state dti_state; | 205 | enum wa_dti_state dti_state; |
206 | u32 dti_isoc_xfer_in_progress; | 206 | u32 dti_isoc_xfer_in_progress; |
@@ -211,7 +211,7 @@ struct wahc { | |||
211 | void *dti_buf; | 211 | void *dti_buf; |
212 | size_t dti_buf_size; | 212 | size_t dti_buf_size; |
213 | 213 | ||
214 | unsigned long dto_in_use; /* protect dto endoint serialization. */ | 214 | unsigned long dto_in_use; /* protect dto endoint serialization */ |
215 | 215 | ||
216 | s32 status; /* For reading status */ | 216 | s32 status; /* For reading status */ |
217 | 217 | ||
@@ -332,7 +332,7 @@ static inline int rpipe_avail_inc(struct wa_rpipe *rpipe) | |||
332 | /* Transferring data */ | 332 | /* Transferring data */ |
333 | extern int wa_urb_enqueue(struct wahc *, struct usb_host_endpoint *, | 333 | extern int wa_urb_enqueue(struct wahc *, struct usb_host_endpoint *, |
334 | struct urb *, gfp_t); | 334 | struct urb *, gfp_t); |
335 | extern int wa_urb_dequeue(struct wahc *, struct urb *); | 335 | extern int wa_urb_dequeue(struct wahc *, struct urb *, int); |
336 | extern void wa_handle_notif_xfer(struct wahc *, struct wa_notif_hdr *); | 336 | extern void wa_handle_notif_xfer(struct wahc *, struct wa_notif_hdr *); |
337 | 337 | ||
338 | 338 | ||
@@ -345,7 +345,7 @@ extern void wa_handle_notif_xfer(struct wahc *, struct wa_notif_hdr *); | |||
345 | * it...no RC specific function is called...unless I miss | 345 | * it...no RC specific function is called...unless I miss |
346 | * something. | 346 | * something. |
347 | * | 347 | * |
348 | * FIXME: has to go away in favour of an 'struct' hcd based sollution | 348 | * FIXME: has to go away in favour of a 'struct' hcd based solution |
349 | */ | 349 | */ |
350 | static inline struct wahc *wa_get(struct wahc *wa) | 350 | static inline struct wahc *wa_get(struct wahc *wa) |
351 | { | 351 | { |
@@ -366,7 +366,7 @@ static inline int __wa_feature(struct wahc *wa, unsigned op, u16 feature) | |||
366 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 366 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
367 | feature, | 367 | feature, |
368 | wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, | 368 | wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, |
369 | NULL, 0, 1000 /* FIXME: arbitrary */); | 369 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
370 | } | 370 | } |
371 | 371 | ||
372 | 372 | ||
@@ -400,8 +400,7 @@ s32 __wa_get_status(struct wahc *wa) | |||
400 | USB_REQ_GET_STATUS, | 400 | USB_REQ_GET_STATUS, |
401 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 401 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
402 | 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, | 402 | 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, |
403 | &wa->status, sizeof(wa->status), | 403 | &wa->status, sizeof(wa->status), USB_CTRL_GET_TIMEOUT); |
404 | 1000 /* FIXME: arbitrary */); | ||
405 | if (result >= 0) | 404 | if (result >= 0) |
406 | result = wa->status; | 405 | result = wa->status; |
407 | return result; | 406 | return result; |
diff --git a/drivers/usb/wusbcore/wa-nep.c b/drivers/usb/wusbcore/wa-nep.c index ada4e0870623..60a10d21947d 100644 --- a/drivers/usb/wusbcore/wa-nep.c +++ b/drivers/usb/wusbcore/wa-nep.c | |||
@@ -69,8 +69,8 @@ struct wa_notif_work { | |||
69 | * [the wuswad daemon, basically] | 69 | * [the wuswad daemon, basically] |
70 | * | 70 | * |
71 | * @_nw: Pointer to a descriptor which has the pointer to the | 71 | * @_nw: Pointer to a descriptor which has the pointer to the |
72 | * @wa, the size of the buffer and the work queue | 72 | * @wa, the size of the buffer and the work queue |
73 | * structure (so we can free all when done). | 73 | * structure (so we can free all when done). |
74 | * @returns 0 if ok, < 0 errno code on error. | 74 | * @returns 0 if ok, < 0 errno code on error. |
75 | * | 75 | * |
76 | * All notifications follow the same format; they need to start with a | 76 | * All notifications follow the same format; they need to start with a |
@@ -93,7 +93,8 @@ static void wa_notif_dispatch(struct work_struct *ws) | |||
93 | { | 93 | { |
94 | void *itr; | 94 | void *itr; |
95 | u8 missing = 0; | 95 | u8 missing = 0; |
96 | struct wa_notif_work *nw = container_of(ws, struct wa_notif_work, work); | 96 | struct wa_notif_work *nw = container_of(ws, struct wa_notif_work, |
97 | work); | ||
97 | struct wahc *wa = nw->wa; | 98 | struct wahc *wa = nw->wa; |
98 | struct wa_notif_hdr *notif_hdr; | 99 | struct wa_notif_hdr *notif_hdr; |
99 | size_t size; | 100 | size_t size; |
@@ -271,7 +272,8 @@ int wa_nep_create(struct wahc *wa, struct usb_interface *iface) | |||
271 | wa->nep_buffer_size = 1024; | 272 | wa->nep_buffer_size = 1024; |
272 | wa->nep_buffer = kmalloc(wa->nep_buffer_size, GFP_KERNEL); | 273 | wa->nep_buffer = kmalloc(wa->nep_buffer_size, GFP_KERNEL); |
273 | if (wa->nep_buffer == NULL) { | 274 | if (wa->nep_buffer == NULL) { |
274 | dev_err(dev, "Unable to allocate notification's read buffer\n"); | 275 | dev_err(dev, |
276 | "Unable to allocate notification's read buffer\n"); | ||
275 | goto error_nep_buffer; | 277 | goto error_nep_buffer; |
276 | } | 278 | } |
277 | wa->nep_urb = usb_alloc_urb(0, GFP_KERNEL); | 279 | wa->nep_urb = usb_alloc_urb(0, GFP_KERNEL); |
diff --git a/drivers/usb/wusbcore/wa-rpipe.c b/drivers/usb/wusbcore/wa-rpipe.c index b48e74cc54d7..6ca80a4efc1b 100644 --- a/drivers/usb/wusbcore/wa-rpipe.c +++ b/drivers/usb/wusbcore/wa-rpipe.c | |||
@@ -57,7 +57,6 @@ | |||
57 | * urb->dev->devnum, to make sure that we always have the right | 57 | * urb->dev->devnum, to make sure that we always have the right |
58 | * destination address. | 58 | * destination address. |
59 | */ | 59 | */ |
60 | #include <linux/init.h> | ||
61 | #include <linux/atomic.h> | 60 | #include <linux/atomic.h> |
62 | #include <linux/bitmap.h> | 61 | #include <linux/bitmap.h> |
63 | #include <linux/slab.h> | 62 | #include <linux/slab.h> |
@@ -80,7 +79,7 @@ static int __rpipe_get_descr(struct wahc *wa, | |||
80 | USB_REQ_GET_DESCRIPTOR, | 79 | USB_REQ_GET_DESCRIPTOR, |
81 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_RPIPE, | 80 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_RPIPE, |
82 | USB_DT_RPIPE<<8, index, descr, sizeof(*descr), | 81 | USB_DT_RPIPE<<8, index, descr, sizeof(*descr), |
83 | 1000 /* FIXME: arbitrary */); | 82 | USB_CTRL_GET_TIMEOUT); |
84 | if (result < 0) { | 83 | if (result < 0) { |
85 | dev_err(dev, "rpipe %u: get descriptor failed: %d\n", | 84 | dev_err(dev, "rpipe %u: get descriptor failed: %d\n", |
86 | index, (int)result); | 85 | index, (int)result); |
@@ -118,7 +117,7 @@ static int __rpipe_set_descr(struct wahc *wa, | |||
118 | USB_REQ_SET_DESCRIPTOR, | 117 | USB_REQ_SET_DESCRIPTOR, |
119 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, | 118 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, |
120 | USB_DT_RPIPE<<8, index, descr, sizeof(*descr), | 119 | USB_DT_RPIPE<<8, index, descr, sizeof(*descr), |
121 | HZ / 10); | 120 | USB_CTRL_SET_TIMEOUT); |
122 | if (result < 0) { | 121 | if (result < 0) { |
123 | dev_err(dev, "rpipe %u: set descriptor failed: %d\n", | 122 | dev_err(dev, "rpipe %u: set descriptor failed: %d\n", |
124 | index, (int)result); | 123 | index, (int)result); |
@@ -184,7 +183,7 @@ EXPORT_SYMBOL_GPL(rpipe_destroy); | |||
184 | /* | 183 | /* |
185 | * Locate an idle rpipe, create an structure for it and return it | 184 | * Locate an idle rpipe, create an structure for it and return it |
186 | * | 185 | * |
187 | * @wa is referenced and unlocked | 186 | * @wa is referenced and unlocked |
188 | * @crs enum rpipe_attr, required endpoint characteristics | 187 | * @crs enum rpipe_attr, required endpoint characteristics |
189 | * | 188 | * |
190 | * The rpipe can be used only sequentially (not in parallel). | 189 | * The rpipe can be used only sequentially (not in parallel). |
@@ -237,7 +236,7 @@ static int __rpipe_reset(struct wahc *wa, unsigned index) | |||
237 | wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), | 236 | wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), |
238 | USB_REQ_RPIPE_RESET, | 237 | USB_REQ_RPIPE_RESET, |
239 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, | 238 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, |
240 | 0, index, NULL, 0, 1000 /* FIXME: arbitrary */); | 239 | 0, index, NULL, 0, USB_CTRL_SET_TIMEOUT); |
241 | if (result < 0) | 240 | if (result < 0) |
242 | dev_err(dev, "rpipe %u: reset failed: %d\n", | 241 | dev_err(dev, "rpipe %u: reset failed: %d\n", |
243 | index, result); | 242 | index, result); |
@@ -308,7 +307,7 @@ out: | |||
308 | /* | 307 | /* |
309 | * Aim an rpipe to its device & endpoint destination | 308 | * Aim an rpipe to its device & endpoint destination |
310 | * | 309 | * |
311 | * Make sure we change the address to unauthenticathed if the device | 310 | * Make sure we change the address to unauthenticated if the device |
312 | * is WUSB and it is not authenticated. | 311 | * is WUSB and it is not authenticated. |
313 | */ | 312 | */ |
314 | static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa, | 313 | static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa, |
@@ -329,7 +328,8 @@ static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa, | |||
329 | } | 328 | } |
330 | unauth = usb_dev->wusb && !usb_dev->authenticated ? 0x80 : 0; | 329 | unauth = usb_dev->wusb && !usb_dev->authenticated ? 0x80 : 0; |
331 | __rpipe_reset(wa, le16_to_cpu(rpipe->descr.wRPipeIndex)); | 330 | __rpipe_reset(wa, le16_to_cpu(rpipe->descr.wRPipeIndex)); |
332 | atomic_set(&rpipe->segs_available, le16_to_cpu(rpipe->descr.wRequests)); | 331 | atomic_set(&rpipe->segs_available, |
332 | le16_to_cpu(rpipe->descr.wRequests)); | ||
333 | /* FIXME: block allocation system; request with queuing and timeout */ | 333 | /* FIXME: block allocation system; request with queuing and timeout */ |
334 | /* FIXME: compute so seg_size > ep->maxpktsize */ | 334 | /* FIXME: compute so seg_size > ep->maxpktsize */ |
335 | rpipe->descr.wBlocks = cpu_to_le16(16); /* given */ | 335 | rpipe->descr.wBlocks = cpu_to_le16(16); /* given */ |
@@ -527,7 +527,7 @@ void rpipe_ep_disable(struct wahc *wa, struct usb_host_endpoint *ep) | |||
527 | wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0), | 527 | wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0), |
528 | USB_REQ_RPIPE_ABORT, | 528 | USB_REQ_RPIPE_ABORT, |
529 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, | 529 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, |
530 | 0, index, NULL, 0, 1000 /* FIXME: arbitrary */); | 530 | 0, index, NULL, 0, USB_CTRL_SET_TIMEOUT); |
531 | rpipe_put(rpipe); | 531 | rpipe_put(rpipe); |
532 | } | 532 | } |
533 | mutex_unlock(&wa->rpipe_mutex); | 533 | mutex_unlock(&wa->rpipe_mutex); |
@@ -548,9 +548,8 @@ void rpipe_clear_feature_stalled(struct wahc *wa, struct usb_host_endpoint *ep) | |||
548 | wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0), | 548 | wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0), |
549 | USB_REQ_CLEAR_FEATURE, | 549 | USB_REQ_CLEAR_FEATURE, |
550 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, | 550 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, |
551 | RPIPE_STALL, index, NULL, 0, 1000); | 551 | RPIPE_STALL, index, NULL, 0, USB_CTRL_SET_TIMEOUT); |
552 | } | 552 | } |
553 | mutex_unlock(&wa->rpipe_mutex); | 553 | mutex_unlock(&wa->rpipe_mutex); |
554 | } | 554 | } |
555 | EXPORT_SYMBOL_GPL(rpipe_clear_feature_stalled); | 555 | EXPORT_SYMBOL_GPL(rpipe_clear_feature_stalled); |
556 | |||
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c index ed5abe87b049..3cd96e936d77 100644 --- a/drivers/usb/wusbcore/wa-xfer.c +++ b/drivers/usb/wusbcore/wa-xfer.c | |||
@@ -79,7 +79,6 @@ | |||
79 | * availability of the different required components (blocks, | 79 | * availability of the different required components (blocks, |
80 | * rpipes, segment slots, etc), we go scheduling them. Painful. | 80 | * rpipes, segment slots, etc), we go scheduling them. Painful. |
81 | */ | 81 | */ |
82 | #include <linux/init.h> | ||
83 | #include <linux/spinlock.h> | 82 | #include <linux/spinlock.h> |
84 | #include <linux/slab.h> | 83 | #include <linux/slab.h> |
85 | #include <linux/hash.h> | 84 | #include <linux/hash.h> |
@@ -124,6 +123,8 @@ struct wa_seg { | |||
124 | u8 index; /* which segment we are */ | 123 | u8 index; /* which segment we are */ |
125 | int isoc_frame_count; /* number of isoc frames in this segment. */ | 124 | int isoc_frame_count; /* number of isoc frames in this segment. */ |
126 | int isoc_frame_offset; /* starting frame offset in the xfer URB. */ | 125 | int isoc_frame_offset; /* starting frame offset in the xfer URB. */ |
126 | /* Isoc frame that the current transfer buffer corresponds to. */ | ||
127 | int isoc_frame_index; | ||
127 | int isoc_size; /* size of all isoc frames sent by this seg. */ | 128 | int isoc_size; /* size of all isoc frames sent by this seg. */ |
128 | enum wa_seg_status status; | 129 | enum wa_seg_status status; |
129 | ssize_t result; /* bytes xfered or error */ | 130 | ssize_t result; /* bytes xfered or error */ |
@@ -158,8 +159,6 @@ struct wa_xfer { | |||
158 | unsigned is_dma:1; | 159 | unsigned is_dma:1; |
159 | size_t seg_size; | 160 | size_t seg_size; |
160 | int result; | 161 | int result; |
161 | /* Isoc frame that the current transfer buffer corresponds to. */ | ||
162 | int dto_isoc_frame_index; | ||
163 | 162 | ||
164 | gfp_t gfp; /* allocation mask */ | 163 | gfp_t gfp; /* allocation mask */ |
165 | 164 | ||
@@ -282,6 +281,7 @@ static void wa_xfer_giveback(struct wa_xfer *xfer) | |||
282 | 281 | ||
283 | spin_lock_irqsave(&xfer->wa->xfer_list_lock, flags); | 282 | spin_lock_irqsave(&xfer->wa->xfer_list_lock, flags); |
284 | list_del_init(&xfer->list_node); | 283 | list_del_init(&xfer->list_node); |
284 | usb_hcd_unlink_urb_from_ep(&(xfer->wa->wusb->usb_hcd), xfer->urb); | ||
285 | spin_unlock_irqrestore(&xfer->wa->xfer_list_lock, flags); | 285 | spin_unlock_irqrestore(&xfer->wa->xfer_list_lock, flags); |
286 | /* FIXME: segmentation broken -- kills DWA */ | 286 | /* FIXME: segmentation broken -- kills DWA */ |
287 | wusbhc_giveback_urb(xfer->wa->wusb, xfer->urb, xfer->result); | 287 | wusbhc_giveback_urb(xfer->wa->wusb, xfer->urb, xfer->result); |
@@ -372,10 +372,10 @@ static unsigned __wa_xfer_is_done(struct wa_xfer *xfer) | |||
372 | seg->result); | 372 | seg->result); |
373 | goto out; | 373 | goto out; |
374 | case WA_SEG_ABORTED: | 374 | case WA_SEG_ABORTED: |
375 | dev_dbg(dev, "xfer %p ID %08X#%u ABORTED: result %d\n", | 375 | xfer->result = seg->result; |
376 | xfer, wa_xfer_id(xfer), seg->index, | 376 | dev_dbg(dev, "xfer %p ID %08X#%u: ABORTED result %zu(0x%08zX)\n", |
377 | urb->status); | 377 | xfer, wa_xfer_id(xfer), seg->index, seg->result, |
378 | xfer->result = urb->status; | 378 | seg->result); |
379 | goto out; | 379 | goto out; |
380 | default: | 380 | default: |
381 | dev_warn(dev, "xfer %p ID %08X#%u: is_done bad state %d\n", | 381 | dev_warn(dev, "xfer %p ID %08X#%u: is_done bad state %d\n", |
@@ -487,13 +487,14 @@ static int __wa_seg_calculate_isoc_frame_count(struct wa_xfer *xfer, | |||
487 | && ((segment_size + iso_frame_desc[index].length) | 487 | && ((segment_size + iso_frame_desc[index].length) |
488 | <= xfer->seg_size)) { | 488 | <= xfer->seg_size)) { |
489 | /* | 489 | /* |
490 | * For Alereon HWA devices, only include an isoc frame in a | 490 | * For Alereon HWA devices, only include an isoc frame in an |
491 | * segment if it is physically contiguous with the previous | 491 | * out segment if it is physically contiguous with the previous |
492 | * frame. This is required because those devices expect | 492 | * frame. This is required because those devices expect |
493 | * the isoc frames to be sent as a single USB transaction as | 493 | * the isoc frames to be sent as a single USB transaction as |
494 | * opposed to one transaction per frame with standard HWA. | 494 | * opposed to one transaction per frame with standard HWA. |
495 | */ | 495 | */ |
496 | if ((xfer->wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) | 496 | if ((xfer->wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) |
497 | && (xfer->is_inbound == 0) | ||
497 | && (index > isoc_frame_offset) | 498 | && (index > isoc_frame_offset) |
498 | && ((iso_frame_desc[index - 1].offset + | 499 | && ((iso_frame_desc[index - 1].offset + |
499 | iso_frame_desc[index - 1].length) != | 500 | iso_frame_desc[index - 1].length) != |
@@ -536,14 +537,8 @@ static ssize_t __wa_xfer_setup_sizes(struct wa_xfer *xfer, | |||
536 | result = sizeof(struct wa_xfer_bi); | 537 | result = sizeof(struct wa_xfer_bi); |
537 | break; | 538 | break; |
538 | case USB_ENDPOINT_XFER_ISOC: | 539 | case USB_ENDPOINT_XFER_ISOC: |
539 | if (usb_pipeout(urb->pipe)) { | 540 | *pxfer_type = WA_XFER_TYPE_ISO; |
540 | *pxfer_type = WA_XFER_TYPE_ISO; | 541 | result = sizeof(struct wa_xfer_hwaiso); |
541 | result = sizeof(struct wa_xfer_hwaiso); | ||
542 | } else { | ||
543 | dev_err(dev, "FIXME: ISOC IN not implemented\n"); | ||
544 | result = -ENOSYS; | ||
545 | goto error; | ||
546 | } | ||
547 | break; | 542 | break; |
548 | default: | 543 | default: |
549 | /* never happens */ | 544 | /* never happens */ |
@@ -554,10 +549,22 @@ static ssize_t __wa_xfer_setup_sizes(struct wa_xfer *xfer, | |||
554 | xfer->is_dma = urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP ? 1 : 0; | 549 | xfer->is_dma = urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP ? 1 : 0; |
555 | 550 | ||
556 | maxpktsize = le16_to_cpu(rpipe->descr.wMaxPacketSize); | 551 | maxpktsize = le16_to_cpu(rpipe->descr.wMaxPacketSize); |
552 | xfer->seg_size = le16_to_cpu(rpipe->descr.wBlocks) | ||
553 | * 1 << (xfer->wa->wa_descr->bRPipeBlockSize - 1); | ||
554 | /* Compute the segment size and make sure it is a multiple of | ||
555 | * the maxpktsize (WUSB1.0[8.3.3.1])...not really too much of | ||
556 | * a check (FIXME) */ | ||
557 | if (xfer->seg_size < maxpktsize) { | ||
558 | dev_err(dev, | ||
559 | "HW BUG? seg_size %zu smaller than maxpktsize %zu\n", | ||
560 | xfer->seg_size, maxpktsize); | ||
561 | result = -EINVAL; | ||
562 | goto error; | ||
563 | } | ||
564 | xfer->seg_size = (xfer->seg_size / maxpktsize) * maxpktsize; | ||
557 | if ((rpipe->descr.bmAttribute & 0x3) == USB_ENDPOINT_XFER_ISOC) { | 565 | if ((rpipe->descr.bmAttribute & 0x3) == USB_ENDPOINT_XFER_ISOC) { |
558 | int index = 0; | 566 | int index = 0; |
559 | 567 | ||
560 | xfer->seg_size = maxpktsize; | ||
561 | xfer->segs = 0; | 568 | xfer->segs = 0; |
562 | /* | 569 | /* |
563 | * loop over urb->number_of_packets to determine how many | 570 | * loop over urb->number_of_packets to determine how many |
@@ -570,19 +577,6 @@ static ssize_t __wa_xfer_setup_sizes(struct wa_xfer *xfer, | |||
570 | ++xfer->segs; | 577 | ++xfer->segs; |
571 | } | 578 | } |
572 | } else { | 579 | } else { |
573 | xfer->seg_size = le16_to_cpu(rpipe->descr.wBlocks) | ||
574 | * 1 << (xfer->wa->wa_descr->bRPipeBlockSize - 1); | ||
575 | /* Compute the segment size and make sure it is a multiple of | ||
576 | * the maxpktsize (WUSB1.0[8.3.3.1])...not really too much of | ||
577 | * a check (FIXME) */ | ||
578 | if (xfer->seg_size < maxpktsize) { | ||
579 | dev_err(dev, | ||
580 | "HW BUG? seg_size %zu smaller than maxpktsize %zu\n", | ||
581 | xfer->seg_size, maxpktsize); | ||
582 | result = -EINVAL; | ||
583 | goto error; | ||
584 | } | ||
585 | xfer->seg_size = (xfer->seg_size / maxpktsize) * maxpktsize; | ||
586 | xfer->segs = DIV_ROUND_UP(urb->transfer_buffer_length, | 580 | xfer->segs = DIV_ROUND_UP(urb->transfer_buffer_length, |
587 | xfer->seg_size); | 581 | xfer->seg_size); |
588 | if (xfer->segs == 0 && *pxfer_type == WA_XFER_TYPE_CTL) | 582 | if (xfer->segs == 0 && *pxfer_type == WA_XFER_TYPE_CTL) |
@@ -700,23 +694,23 @@ static void wa_seg_dto_cb(struct urb *urb) | |||
700 | if (usb_pipeisoc(xfer->urb->pipe)) { | 694 | if (usb_pipeisoc(xfer->urb->pipe)) { |
701 | /* Alereon HWA sends all isoc frames in a single transfer. */ | 695 | /* Alereon HWA sends all isoc frames in a single transfer. */ |
702 | if (wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) | 696 | if (wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) |
703 | xfer->dto_isoc_frame_index += seg->isoc_frame_count; | 697 | seg->isoc_frame_index += seg->isoc_frame_count; |
704 | else | 698 | else |
705 | xfer->dto_isoc_frame_index += 1; | 699 | seg->isoc_frame_index += 1; |
706 | if (xfer->dto_isoc_frame_index < seg->isoc_frame_count) { | 700 | if (seg->isoc_frame_index < seg->isoc_frame_count) { |
707 | data_send_done = 0; | 701 | data_send_done = 0; |
708 | holding_dto = 1; /* checked in error cases. */ | 702 | holding_dto = 1; /* checked in error cases. */ |
709 | /* | 703 | /* |
710 | * if this is the last isoc frame of the segment, we | 704 | * if this is the last isoc frame of the segment, we |
711 | * can release DTO after sending this frame. | 705 | * can release DTO after sending this frame. |
712 | */ | 706 | */ |
713 | if ((xfer->dto_isoc_frame_index + 1) >= | 707 | if ((seg->isoc_frame_index + 1) >= |
714 | seg->isoc_frame_count) | 708 | seg->isoc_frame_count) |
715 | release_dto = 1; | 709 | release_dto = 1; |
716 | } | 710 | } |
717 | dev_dbg(dev, "xfer 0x%08X#%u: isoc frame = %d, holding_dto = %d, release_dto = %d.\n", | 711 | dev_dbg(dev, "xfer 0x%08X#%u: isoc frame = %d, holding_dto = %d, release_dto = %d.\n", |
718 | wa_xfer_id(xfer), seg->index, | 712 | wa_xfer_id(xfer), seg->index, seg->isoc_frame_index, |
719 | xfer->dto_isoc_frame_index, holding_dto, release_dto); | 713 | holding_dto, release_dto); |
720 | } | 714 | } |
721 | spin_unlock_irqrestore(&xfer->lock, flags); | 715 | spin_unlock_irqrestore(&xfer->lock, flags); |
722 | 716 | ||
@@ -736,8 +730,7 @@ static void wa_seg_dto_cb(struct urb *urb) | |||
736 | * send the URB and release DTO if we no longer need it. | 730 | * send the URB and release DTO if we no longer need it. |
737 | */ | 731 | */ |
738 | __wa_populate_dto_urb_isoc(xfer, seg, | 732 | __wa_populate_dto_urb_isoc(xfer, seg, |
739 | seg->isoc_frame_offset + | 733 | seg->isoc_frame_offset + seg->isoc_frame_index); |
740 | xfer->dto_isoc_frame_index); | ||
741 | 734 | ||
742 | /* resubmit the URB with the next isoc frame. */ | 735 | /* resubmit the URB with the next isoc frame. */ |
743 | result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC); | 736 | result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC); |
@@ -844,7 +837,7 @@ static void wa_seg_iso_pack_desc_cb(struct urb *urb) | |||
844 | wa_xfer_id(xfer), seg->index, urb->status); | 837 | wa_xfer_id(xfer), seg->index, urb->status); |
845 | if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, | 838 | if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, |
846 | EDC_ERROR_TIMEFRAME)){ | 839 | EDC_ERROR_TIMEFRAME)){ |
847 | dev_err(dev, "DTO: URB max acceptable errors exceeded, resetting device\n"); | 840 | dev_err(dev, "iso xfer: URB max acceptable errors exceeded, resetting device\n"); |
848 | wa_reset_all(wa); | 841 | wa_reset_all(wa); |
849 | } | 842 | } |
850 | if (seg->status != WA_SEG_ERROR) { | 843 | if (seg->status != WA_SEG_ERROR) { |
@@ -1108,7 +1101,7 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) | |||
1108 | const struct usb_endpoint_descriptor *dto_epd = xfer->wa->dto_epd; | 1101 | const struct usb_endpoint_descriptor *dto_epd = xfer->wa->dto_epd; |
1109 | struct wa_seg *seg; | 1102 | struct wa_seg *seg; |
1110 | size_t buf_itr, buf_size, buf_itr_size; | 1103 | size_t buf_itr, buf_size, buf_itr_size; |
1111 | int xfer_isoc_frame_offset = 0; | 1104 | int isoc_frame_offset = 0; |
1112 | 1105 | ||
1113 | result = -ENOMEM; | 1106 | result = -ENOMEM; |
1114 | xfer->seg = kcalloc(xfer->segs, sizeof(xfer->seg[0]), GFP_ATOMIC); | 1107 | xfer->seg = kcalloc(xfer->segs, sizeof(xfer->seg[0]), GFP_ATOMIC); |
@@ -1121,10 +1114,14 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) | |||
1121 | size_t iso_pkt_descr_size = 0; | 1114 | size_t iso_pkt_descr_size = 0; |
1122 | int seg_isoc_frame_count = 0, seg_isoc_size = 0; | 1115 | int seg_isoc_frame_count = 0, seg_isoc_size = 0; |
1123 | 1116 | ||
1117 | /* | ||
1118 | * Adjust the size of the segment object to contain space for | ||
1119 | * the isoc packet descriptor buffer. | ||
1120 | */ | ||
1124 | if (usb_pipeisoc(xfer->urb->pipe)) { | 1121 | if (usb_pipeisoc(xfer->urb->pipe)) { |
1125 | seg_isoc_frame_count = | 1122 | seg_isoc_frame_count = |
1126 | __wa_seg_calculate_isoc_frame_count(xfer, | 1123 | __wa_seg_calculate_isoc_frame_count(xfer, |
1127 | xfer_isoc_frame_offset, &seg_isoc_size); | 1124 | isoc_frame_offset, &seg_isoc_size); |
1128 | 1125 | ||
1129 | iso_pkt_descr_size = | 1126 | iso_pkt_descr_size = |
1130 | sizeof(struct wa_xfer_packet_info_hwaiso) + | 1127 | sizeof(struct wa_xfer_packet_info_hwaiso) + |
@@ -1137,15 +1134,40 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) | |||
1137 | wa_seg_init(seg); | 1134 | wa_seg_init(seg); |
1138 | seg->xfer = xfer; | 1135 | seg->xfer = xfer; |
1139 | seg->index = cnt; | 1136 | seg->index = cnt; |
1140 | seg->isoc_frame_count = seg_isoc_frame_count; | ||
1141 | seg->isoc_frame_offset = xfer_isoc_frame_offset; | ||
1142 | seg->isoc_size = seg_isoc_size; | ||
1143 | usb_fill_bulk_urb(&seg->tr_urb, usb_dev, | 1137 | usb_fill_bulk_urb(&seg->tr_urb, usb_dev, |
1144 | usb_sndbulkpipe(usb_dev, | 1138 | usb_sndbulkpipe(usb_dev, |
1145 | dto_epd->bEndpointAddress), | 1139 | dto_epd->bEndpointAddress), |
1146 | &seg->xfer_hdr, xfer_hdr_size, | 1140 | &seg->xfer_hdr, xfer_hdr_size, |
1147 | wa_seg_tr_cb, seg); | 1141 | wa_seg_tr_cb, seg); |
1148 | buf_itr_size = min(buf_size, xfer->seg_size); | 1142 | buf_itr_size = min(buf_size, xfer->seg_size); |
1143 | |||
1144 | if (usb_pipeisoc(xfer->urb->pipe)) { | ||
1145 | seg->isoc_frame_count = seg_isoc_frame_count; | ||
1146 | seg->isoc_frame_offset = isoc_frame_offset; | ||
1147 | seg->isoc_size = seg_isoc_size; | ||
1148 | /* iso packet descriptor. */ | ||
1149 | seg->isoc_pack_desc_urb = | ||
1150 | usb_alloc_urb(0, GFP_ATOMIC); | ||
1151 | if (seg->isoc_pack_desc_urb == NULL) | ||
1152 | goto error_iso_pack_desc_alloc; | ||
1153 | /* | ||
1154 | * The buffer for the isoc packet descriptor starts | ||
1155 | * after the transfer request header in the | ||
1156 | * segment object memory buffer. | ||
1157 | */ | ||
1158 | usb_fill_bulk_urb( | ||
1159 | seg->isoc_pack_desc_urb, usb_dev, | ||
1160 | usb_sndbulkpipe(usb_dev, | ||
1161 | dto_epd->bEndpointAddress), | ||
1162 | (void *)(&seg->xfer_hdr) + | ||
1163 | xfer_hdr_size, | ||
1164 | iso_pkt_descr_size, | ||
1165 | wa_seg_iso_pack_desc_cb, seg); | ||
1166 | |||
1167 | /* adjust starting frame offset for next seg. */ | ||
1168 | isoc_frame_offset += seg_isoc_frame_count; | ||
1169 | } | ||
1170 | |||
1149 | if (xfer->is_inbound == 0 && buf_size > 0) { | 1171 | if (xfer->is_inbound == 0 && buf_size > 0) { |
1150 | /* outbound data. */ | 1172 | /* outbound data. */ |
1151 | seg->dto_urb = usb_alloc_urb(0, GFP_ATOMIC); | 1173 | seg->dto_urb = usb_alloc_urb(0, GFP_ATOMIC); |
@@ -1158,25 +1180,6 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) | |||
1158 | NULL, 0, wa_seg_dto_cb, seg); | 1180 | NULL, 0, wa_seg_dto_cb, seg); |
1159 | 1181 | ||
1160 | if (usb_pipeisoc(xfer->urb->pipe)) { | 1182 | if (usb_pipeisoc(xfer->urb->pipe)) { |
1161 | /* iso packet descriptor. */ | ||
1162 | seg->isoc_pack_desc_urb = | ||
1163 | usb_alloc_urb(0, GFP_ATOMIC); | ||
1164 | if (seg->isoc_pack_desc_urb == NULL) | ||
1165 | goto error_iso_pack_desc_alloc; | ||
1166 | /* | ||
1167 | * The buffer for the isoc packet descriptor | ||
1168 | * after the transfer request header in the | ||
1169 | * segment object memory buffer. | ||
1170 | */ | ||
1171 | usb_fill_bulk_urb( | ||
1172 | seg->isoc_pack_desc_urb, usb_dev, | ||
1173 | usb_sndbulkpipe(usb_dev, | ||
1174 | dto_epd->bEndpointAddress), | ||
1175 | (void *)(&seg->xfer_hdr) + | ||
1176 | xfer_hdr_size, | ||
1177 | iso_pkt_descr_size, | ||
1178 | wa_seg_iso_pack_desc_cb, seg); | ||
1179 | |||
1180 | /* | 1183 | /* |
1181 | * Fill in the xfer buffer information for the | 1184 | * Fill in the xfer buffer information for the |
1182 | * first isoc frame. Subsequent frames in this | 1185 | * first isoc frame. Subsequent frames in this |
@@ -1184,9 +1187,7 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) | |||
1184 | * DTO completion routine, if needed. | 1187 | * DTO completion routine, if needed. |
1185 | */ | 1188 | */ |
1186 | __wa_populate_dto_urb_isoc(xfer, seg, | 1189 | __wa_populate_dto_urb_isoc(xfer, seg, |
1187 | xfer_isoc_frame_offset); | 1190 | seg->isoc_frame_offset); |
1188 | /* adjust starting frame offset for next seg. */ | ||
1189 | xfer_isoc_frame_offset += seg_isoc_frame_count; | ||
1190 | } else { | 1191 | } else { |
1191 | /* fill in the xfer buffer information. */ | 1192 | /* fill in the xfer buffer information. */ |
1192 | result = __wa_populate_dto_urb(xfer, seg, | 1193 | result = __wa_populate_dto_urb(xfer, seg, |
@@ -1207,10 +1208,11 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) | |||
1207 | * Use the fact that cnt is left at were it failed. The remaining | 1208 | * Use the fact that cnt is left at were it failed. The remaining |
1208 | * segments will be cleaned up by wa_xfer_destroy. | 1209 | * segments will be cleaned up by wa_xfer_destroy. |
1209 | */ | 1210 | */ |
1210 | error_iso_pack_desc_alloc: | ||
1211 | error_seg_outbound_populate: | 1211 | error_seg_outbound_populate: |
1212 | usb_free_urb(xfer->seg[cnt]->dto_urb); | 1212 | usb_free_urb(xfer->seg[cnt]->dto_urb); |
1213 | error_dto_alloc: | 1213 | error_dto_alloc: |
1214 | usb_free_urb(xfer->seg[cnt]->isoc_pack_desc_urb); | ||
1215 | error_iso_pack_desc_alloc: | ||
1214 | kfree(xfer->seg[cnt]); | 1216 | kfree(xfer->seg[cnt]); |
1215 | xfer->seg[cnt] = NULL; | 1217 | xfer->seg[cnt] = NULL; |
1216 | error_seg_kmalloc: | 1218 | error_seg_kmalloc: |
@@ -1259,8 +1261,11 @@ static int __wa_xfer_setup(struct wa_xfer *xfer, struct urb *urb) | |||
1259 | for (cnt = 1; cnt < xfer->segs; cnt++) { | 1261 | for (cnt = 1; cnt < xfer->segs; cnt++) { |
1260 | struct wa_xfer_packet_info_hwaiso *packet_desc; | 1262 | struct wa_xfer_packet_info_hwaiso *packet_desc; |
1261 | struct wa_seg *seg = xfer->seg[cnt]; | 1263 | struct wa_seg *seg = xfer->seg[cnt]; |
1264 | struct wa_xfer_hwaiso *xfer_iso; | ||
1262 | 1265 | ||
1263 | xfer_hdr = &seg->xfer_hdr; | 1266 | xfer_hdr = &seg->xfer_hdr; |
1267 | xfer_iso = container_of(xfer_hdr, | ||
1268 | struct wa_xfer_hwaiso, hdr); | ||
1264 | packet_desc = ((void *)xfer_hdr) + xfer_hdr_size; | 1269 | packet_desc = ((void *)xfer_hdr) + xfer_hdr_size; |
1265 | /* | 1270 | /* |
1266 | * Copy values from the 0th header. Segment specific | 1271 | * Copy values from the 0th header. Segment specific |
@@ -1270,6 +1275,8 @@ static int __wa_xfer_setup(struct wa_xfer *xfer, struct urb *urb) | |||
1270 | xfer_hdr->bTransferSegment = cnt; | 1275 | xfer_hdr->bTransferSegment = cnt; |
1271 | xfer_hdr->dwTransferLength = | 1276 | xfer_hdr->dwTransferLength = |
1272 | cpu_to_le32(seg->isoc_size); | 1277 | cpu_to_le32(seg->isoc_size); |
1278 | xfer_iso->dwNumOfPackets = | ||
1279 | cpu_to_le32(seg->isoc_frame_count); | ||
1273 | __wa_setup_isoc_packet_descr(packet_desc, xfer, seg); | 1280 | __wa_setup_isoc_packet_descr(packet_desc, xfer, seg); |
1274 | seg->status = WA_SEG_READY; | 1281 | seg->status = WA_SEG_READY; |
1275 | } | 1282 | } |
@@ -1320,32 +1327,31 @@ static int __wa_seg_submit(struct wa_rpipe *rpipe, struct wa_xfer *xfer, | |||
1320 | } | 1327 | } |
1321 | /* submit the isoc packet descriptor if present. */ | 1328 | /* submit the isoc packet descriptor if present. */ |
1322 | if (seg->isoc_pack_desc_urb) { | 1329 | if (seg->isoc_pack_desc_urb) { |
1323 | struct wahc *wa = xfer->wa; | ||
1324 | |||
1325 | result = usb_submit_urb(seg->isoc_pack_desc_urb, GFP_ATOMIC); | 1330 | result = usb_submit_urb(seg->isoc_pack_desc_urb, GFP_ATOMIC); |
1331 | seg->isoc_frame_index = 0; | ||
1326 | if (result < 0) { | 1332 | if (result < 0) { |
1327 | pr_err("%s: xfer %p#%u: ISO packet descriptor submit failed: %d\n", | 1333 | pr_err("%s: xfer %p#%u: ISO packet descriptor submit failed: %d\n", |
1328 | __func__, xfer, seg->index, result); | 1334 | __func__, xfer, seg->index, result); |
1329 | goto error_iso_pack_desc_submit; | 1335 | goto error_iso_pack_desc_submit; |
1330 | } | 1336 | } |
1331 | xfer->dto_isoc_frame_index = 0; | ||
1332 | /* | ||
1333 | * If this segment contains more than one isoc frame, hold | ||
1334 | * onto the dto resource until we send all frames. | ||
1335 | * Only applies to non-Alereon devices. | ||
1336 | */ | ||
1337 | if (((wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) == 0) | ||
1338 | && (seg->isoc_frame_count > 1)) | ||
1339 | *dto_done = 0; | ||
1340 | } | 1337 | } |
1341 | /* submit the out data if this is an out request. */ | 1338 | /* submit the out data if this is an out request. */ |
1342 | if (seg->dto_urb) { | 1339 | if (seg->dto_urb) { |
1340 | struct wahc *wa = xfer->wa; | ||
1343 | result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC); | 1341 | result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC); |
1344 | if (result < 0) { | 1342 | if (result < 0) { |
1345 | pr_err("%s: xfer %p#%u: DTO submit failed: %d\n", | 1343 | pr_err("%s: xfer %p#%u: DTO submit failed: %d\n", |
1346 | __func__, xfer, seg->index, result); | 1344 | __func__, xfer, seg->index, result); |
1347 | goto error_dto_submit; | 1345 | goto error_dto_submit; |
1348 | } | 1346 | } |
1347 | /* | ||
1348 | * If this segment contains more than one isoc frame, hold | ||
1349 | * onto the dto resource until we send all frames. | ||
1350 | * Only applies to non-Alereon devices. | ||
1351 | */ | ||
1352 | if (((wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) == 0) | ||
1353 | && (seg->isoc_frame_count > 1)) | ||
1354 | *dto_done = 0; | ||
1349 | } | 1355 | } |
1350 | seg->status = WA_SEG_SUBMITTED; | 1356 | seg->status = WA_SEG_SUBMITTED; |
1351 | rpipe_avail_dec(rpipe); | 1357 | rpipe_avail_dec(rpipe); |
@@ -1567,7 +1573,8 @@ static int wa_urb_enqueue_b(struct wa_xfer *xfer) | |||
1567 | wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, urb->dev); | 1573 | wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, urb->dev); |
1568 | if (wusb_dev == NULL) { | 1574 | if (wusb_dev == NULL) { |
1569 | mutex_unlock(&wusbhc->mutex); | 1575 | mutex_unlock(&wusbhc->mutex); |
1570 | pr_err("%s: error wusb dev gone\n", __func__); | 1576 | dev_err(&(urb->dev->dev), "%s: error wusb dev gone\n", |
1577 | __func__); | ||
1571 | goto error_dev_gone; | 1578 | goto error_dev_gone; |
1572 | } | 1579 | } |
1573 | mutex_unlock(&wusbhc->mutex); | 1580 | mutex_unlock(&wusbhc->mutex); |
@@ -1576,18 +1583,18 @@ static int wa_urb_enqueue_b(struct wa_xfer *xfer) | |||
1576 | xfer->wusb_dev = wusb_dev; | 1583 | xfer->wusb_dev = wusb_dev; |
1577 | result = urb->status; | 1584 | result = urb->status; |
1578 | if (urb->status != -EINPROGRESS) { | 1585 | if (urb->status != -EINPROGRESS) { |
1579 | pr_err("%s: error_dequeued\n", __func__); | 1586 | dev_err(&(urb->dev->dev), "%s: error_dequeued\n", __func__); |
1580 | goto error_dequeued; | 1587 | goto error_dequeued; |
1581 | } | 1588 | } |
1582 | 1589 | ||
1583 | result = __wa_xfer_setup(xfer, urb); | 1590 | result = __wa_xfer_setup(xfer, urb); |
1584 | if (result < 0) { | 1591 | if (result < 0) { |
1585 | pr_err("%s: error_xfer_setup\n", __func__); | 1592 | dev_err(&(urb->dev->dev), "%s: error_xfer_setup\n", __func__); |
1586 | goto error_xfer_setup; | 1593 | goto error_xfer_setup; |
1587 | } | 1594 | } |
1588 | result = __wa_xfer_submit(xfer); | 1595 | result = __wa_xfer_submit(xfer); |
1589 | if (result < 0) { | 1596 | if (result < 0) { |
1590 | pr_err("%s: error_xfer_submit\n", __func__); | 1597 | dev_err(&(urb->dev->dev), "%s: error_xfer_submit\n", __func__); |
1591 | goto error_xfer_submit; | 1598 | goto error_xfer_submit; |
1592 | } | 1599 | } |
1593 | spin_unlock_irqrestore(&xfer->lock, flags); | 1600 | spin_unlock_irqrestore(&xfer->lock, flags); |
@@ -1730,6 +1737,12 @@ int wa_urb_enqueue(struct wahc *wa, struct usb_host_endpoint *ep, | |||
1730 | dump_stack(); | 1737 | dump_stack(); |
1731 | } | 1738 | } |
1732 | 1739 | ||
1740 | spin_lock_irqsave(&wa->xfer_list_lock, my_flags); | ||
1741 | result = usb_hcd_link_urb_to_ep(&(wa->wusb->usb_hcd), urb); | ||
1742 | spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags); | ||
1743 | if (result < 0) | ||
1744 | goto error_link_urb; | ||
1745 | |||
1733 | result = -ENOMEM; | 1746 | result = -ENOMEM; |
1734 | xfer = kzalloc(sizeof(*xfer), gfp); | 1747 | xfer = kzalloc(sizeof(*xfer), gfp); |
1735 | if (xfer == NULL) | 1748 | if (xfer == NULL) |
@@ -1769,6 +1782,9 @@ int wa_urb_enqueue(struct wahc *wa, struct usb_host_endpoint *ep, | |||
1769 | __func__, result); | 1782 | __func__, result); |
1770 | wa_put(xfer->wa); | 1783 | wa_put(xfer->wa); |
1771 | wa_xfer_put(xfer); | 1784 | wa_xfer_put(xfer); |
1785 | spin_lock_irqsave(&wa->xfer_list_lock, my_flags); | ||
1786 | usb_hcd_unlink_urb_from_ep(&(wa->wusb->usb_hcd), urb); | ||
1787 | spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags); | ||
1772 | return result; | 1788 | return result; |
1773 | } | 1789 | } |
1774 | } | 1790 | } |
@@ -1777,6 +1793,10 @@ int wa_urb_enqueue(struct wahc *wa, struct usb_host_endpoint *ep, | |||
1777 | error_dequeued: | 1793 | error_dequeued: |
1778 | kfree(xfer); | 1794 | kfree(xfer); |
1779 | error_kmalloc: | 1795 | error_kmalloc: |
1796 | spin_lock_irqsave(&wa->xfer_list_lock, my_flags); | ||
1797 | usb_hcd_unlink_urb_from_ep(&(wa->wusb->usb_hcd), urb); | ||
1798 | spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags); | ||
1799 | error_link_urb: | ||
1780 | return result; | 1800 | return result; |
1781 | } | 1801 | } |
1782 | EXPORT_SYMBOL_GPL(wa_urb_enqueue); | 1802 | EXPORT_SYMBOL_GPL(wa_urb_enqueue); |
@@ -1799,7 +1819,7 @@ EXPORT_SYMBOL_GPL(wa_urb_enqueue); | |||
1799 | * asynch request] and then make sure we cancel each segment. | 1819 | * asynch request] and then make sure we cancel each segment. |
1800 | * | 1820 | * |
1801 | */ | 1821 | */ |
1802 | int wa_urb_dequeue(struct wahc *wa, struct urb *urb) | 1822 | int wa_urb_dequeue(struct wahc *wa, struct urb *urb, int status) |
1803 | { | 1823 | { |
1804 | unsigned long flags, flags2; | 1824 | unsigned long flags, flags2; |
1805 | struct wa_xfer *xfer; | 1825 | struct wa_xfer *xfer; |
@@ -1807,6 +1827,14 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb) | |||
1807 | struct wa_rpipe *rpipe; | 1827 | struct wa_rpipe *rpipe; |
1808 | unsigned cnt, done = 0, xfer_abort_pending; | 1828 | unsigned cnt, done = 0, xfer_abort_pending; |
1809 | unsigned rpipe_ready = 0; | 1829 | unsigned rpipe_ready = 0; |
1830 | int result; | ||
1831 | |||
1832 | /* check if it is safe to unlink. */ | ||
1833 | spin_lock_irqsave(&wa->xfer_list_lock, flags); | ||
1834 | result = usb_hcd_check_unlink_urb(&(wa->wusb->usb_hcd), urb, status); | ||
1835 | spin_unlock_irqrestore(&wa->xfer_list_lock, flags); | ||
1836 | if (result) | ||
1837 | return result; | ||
1810 | 1838 | ||
1811 | xfer = urb->hcpriv; | 1839 | xfer = urb->hcpriv; |
1812 | if (xfer == NULL) { | 1840 | if (xfer == NULL) { |
@@ -1822,9 +1850,10 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb) | |||
1822 | pr_debug("%s: DEQUEUE xfer id 0x%08X\n", __func__, wa_xfer_id(xfer)); | 1850 | pr_debug("%s: DEQUEUE xfer id 0x%08X\n", __func__, wa_xfer_id(xfer)); |
1823 | rpipe = xfer->ep->hcpriv; | 1851 | rpipe = xfer->ep->hcpriv; |
1824 | if (rpipe == NULL) { | 1852 | if (rpipe == NULL) { |
1825 | pr_debug("%s: xfer id 0x%08X has no RPIPE. %s", | 1853 | pr_debug("%s: xfer %p id 0x%08X has no RPIPE. %s", |
1826 | __func__, wa_xfer_id(xfer), | 1854 | __func__, xfer, wa_xfer_id(xfer), |
1827 | "Probably already aborted.\n" ); | 1855 | "Probably already aborted.\n" ); |
1856 | result = -ENOENT; | ||
1828 | goto out_unlock; | 1857 | goto out_unlock; |
1829 | } | 1858 | } |
1830 | /* Check the delayed list -> if there, release and complete */ | 1859 | /* Check the delayed list -> if there, release and complete */ |
@@ -1855,6 +1884,7 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb) | |||
1855 | * segments will be completed in the DTI interrupt. | 1884 | * segments will be completed in the DTI interrupt. |
1856 | */ | 1885 | */ |
1857 | seg->status = WA_SEG_ABORTED; | 1886 | seg->status = WA_SEG_ABORTED; |
1887 | seg->result = -ENOENT; | ||
1858 | spin_lock_irqsave(&rpipe->seg_lock, flags2); | 1888 | spin_lock_irqsave(&rpipe->seg_lock, flags2); |
1859 | list_del(&seg->list_node); | 1889 | list_del(&seg->list_node); |
1860 | xfer->segs_done++; | 1890 | xfer->segs_done++; |
@@ -1894,12 +1924,12 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb) | |||
1894 | wa_xfer_completion(xfer); | 1924 | wa_xfer_completion(xfer); |
1895 | if (rpipe_ready) | 1925 | if (rpipe_ready) |
1896 | wa_xfer_delayed_run(rpipe); | 1926 | wa_xfer_delayed_run(rpipe); |
1897 | return 0; | 1927 | return result; |
1898 | 1928 | ||
1899 | out_unlock: | 1929 | out_unlock: |
1900 | spin_unlock_irqrestore(&xfer->lock, flags); | 1930 | spin_unlock_irqrestore(&xfer->lock, flags); |
1901 | out: | 1931 | out: |
1902 | return 0; | 1932 | return result; |
1903 | 1933 | ||
1904 | dequeue_delayed: | 1934 | dequeue_delayed: |
1905 | list_del_init(&xfer->list_node); | 1935 | list_del_init(&xfer->list_node); |
@@ -1935,7 +1965,7 @@ static int wa_xfer_status_to_errno(u8 status) | |||
1935 | [WA_XFER_STATUS_NOT_FOUND] = 0, | 1965 | [WA_XFER_STATUS_NOT_FOUND] = 0, |
1936 | [WA_XFER_STATUS_INSUFFICIENT_RESOURCE] = -ENOMEM, | 1966 | [WA_XFER_STATUS_INSUFFICIENT_RESOURCE] = -ENOMEM, |
1937 | [WA_XFER_STATUS_TRANSACTION_ERROR] = -EILSEQ, | 1967 | [WA_XFER_STATUS_TRANSACTION_ERROR] = -EILSEQ, |
1938 | [WA_XFER_STATUS_ABORTED] = -EINTR, | 1968 | [WA_XFER_STATUS_ABORTED] = -ENOENT, |
1939 | [WA_XFER_STATUS_RPIPE_NOT_READY] = EINVAL, | 1969 | [WA_XFER_STATUS_RPIPE_NOT_READY] = EINVAL, |
1940 | [WA_XFER_INVALID_FORMAT] = EINVAL, | 1970 | [WA_XFER_INVALID_FORMAT] = EINVAL, |
1941 | [WA_XFER_UNEXPECTED_SEGMENT_NUMBER] = EINVAL, | 1971 | [WA_XFER_UNEXPECTED_SEGMENT_NUMBER] = EINVAL, |
@@ -1968,7 +1998,7 @@ static int wa_xfer_status_to_errno(u8 status) | |||
1968 | * the xfer will complete cleanly. | 1998 | * the xfer will complete cleanly. |
1969 | */ | 1999 | */ |
1970 | static void wa_complete_remaining_xfer_segs(struct wa_xfer *xfer, | 2000 | static void wa_complete_remaining_xfer_segs(struct wa_xfer *xfer, |
1971 | struct wa_seg *incoming_seg) | 2001 | struct wa_seg *incoming_seg, enum wa_seg_status status) |
1972 | { | 2002 | { |
1973 | int index; | 2003 | int index; |
1974 | struct wa_rpipe *rpipe = xfer->ep->hcpriv; | 2004 | struct wa_rpipe *rpipe = xfer->ep->hcpriv; |
@@ -1990,7 +2020,7 @@ static void wa_complete_remaining_xfer_segs(struct wa_xfer *xfer, | |||
1990 | */ | 2020 | */ |
1991 | case WA_SEG_DELAYED: | 2021 | case WA_SEG_DELAYED: |
1992 | xfer->segs_done++; | 2022 | xfer->segs_done++; |
1993 | current_seg->status = incoming_seg->status; | 2023 | current_seg->status = status; |
1994 | break; | 2024 | break; |
1995 | case WA_SEG_ABORTED: | 2025 | case WA_SEG_ABORTED: |
1996 | break; | 2026 | break; |
@@ -2003,6 +2033,77 @@ static void wa_complete_remaining_xfer_segs(struct wa_xfer *xfer, | |||
2003 | } | 2033 | } |
2004 | } | 2034 | } |
2005 | 2035 | ||
2036 | /* Populate the wa->buf_in_urb based on the current isoc transfer state. */ | ||
2037 | static void __wa_populate_buf_in_urb_isoc(struct wahc *wa, struct wa_xfer *xfer, | ||
2038 | struct wa_seg *seg, int curr_iso_frame) | ||
2039 | { | ||
2040 | BUG_ON(wa->buf_in_urb->status == -EINPROGRESS); | ||
2041 | |||
2042 | /* this should always be 0 before a resubmit. */ | ||
2043 | wa->buf_in_urb->num_mapped_sgs = 0; | ||
2044 | wa->buf_in_urb->transfer_dma = xfer->urb->transfer_dma + | ||
2045 | xfer->urb->iso_frame_desc[curr_iso_frame].offset; | ||
2046 | wa->buf_in_urb->transfer_buffer_length = | ||
2047 | xfer->urb->iso_frame_desc[curr_iso_frame].length; | ||
2048 | wa->buf_in_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
2049 | wa->buf_in_urb->transfer_buffer = NULL; | ||
2050 | wa->buf_in_urb->sg = NULL; | ||
2051 | wa->buf_in_urb->num_sgs = 0; | ||
2052 | wa->buf_in_urb->context = seg; | ||
2053 | } | ||
2054 | |||
2055 | /* Populate the wa->buf_in_urb based on the current transfer state. */ | ||
2056 | static int wa_populate_buf_in_urb(struct wahc *wa, struct wa_xfer *xfer, | ||
2057 | unsigned int seg_idx, unsigned int bytes_transferred) | ||
2058 | { | ||
2059 | int result = 0; | ||
2060 | struct wa_seg *seg = xfer->seg[seg_idx]; | ||
2061 | |||
2062 | BUG_ON(wa->buf_in_urb->status == -EINPROGRESS); | ||
2063 | /* this should always be 0 before a resubmit. */ | ||
2064 | wa->buf_in_urb->num_mapped_sgs = 0; | ||
2065 | |||
2066 | if (xfer->is_dma) { | ||
2067 | wa->buf_in_urb->transfer_dma = xfer->urb->transfer_dma | ||
2068 | + (seg_idx * xfer->seg_size); | ||
2069 | wa->buf_in_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
2070 | wa->buf_in_urb->transfer_buffer = NULL; | ||
2071 | wa->buf_in_urb->sg = NULL; | ||
2072 | wa->buf_in_urb->num_sgs = 0; | ||
2073 | } else { | ||
2074 | /* do buffer or SG processing. */ | ||
2075 | wa->buf_in_urb->transfer_flags &= ~URB_NO_TRANSFER_DMA_MAP; | ||
2076 | |||
2077 | if (xfer->urb->transfer_buffer) { | ||
2078 | wa->buf_in_urb->transfer_buffer = | ||
2079 | xfer->urb->transfer_buffer | ||
2080 | + (seg_idx * xfer->seg_size); | ||
2081 | wa->buf_in_urb->sg = NULL; | ||
2082 | wa->buf_in_urb->num_sgs = 0; | ||
2083 | } else { | ||
2084 | /* allocate an SG list to store seg_size bytes | ||
2085 | and copy the subset of the xfer->urb->sg | ||
2086 | that matches the buffer subset we are | ||
2087 | about to read. */ | ||
2088 | wa->buf_in_urb->sg = wa_xfer_create_subset_sg( | ||
2089 | xfer->urb->sg, | ||
2090 | seg_idx * xfer->seg_size, | ||
2091 | bytes_transferred, | ||
2092 | &(wa->buf_in_urb->num_sgs)); | ||
2093 | |||
2094 | if (!(wa->buf_in_urb->sg)) { | ||
2095 | wa->buf_in_urb->num_sgs = 0; | ||
2096 | result = -ENOMEM; | ||
2097 | } | ||
2098 | wa->buf_in_urb->transfer_buffer = NULL; | ||
2099 | } | ||
2100 | } | ||
2101 | wa->buf_in_urb->transfer_buffer_length = bytes_transferred; | ||
2102 | wa->buf_in_urb->context = seg; | ||
2103 | |||
2104 | return result; | ||
2105 | } | ||
2106 | |||
2006 | /* | 2107 | /* |
2007 | * Process a xfer result completion message | 2108 | * Process a xfer result completion message |
2008 | * | 2109 | * |
@@ -2016,12 +2117,13 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer, | |||
2016 | int result; | 2117 | int result; |
2017 | struct device *dev = &wa->usb_iface->dev; | 2118 | struct device *dev = &wa->usb_iface->dev; |
2018 | unsigned long flags; | 2119 | unsigned long flags; |
2019 | u8 seg_idx; | 2120 | unsigned int seg_idx; |
2020 | struct wa_seg *seg; | 2121 | struct wa_seg *seg; |
2021 | struct wa_rpipe *rpipe; | 2122 | struct wa_rpipe *rpipe; |
2022 | unsigned done = 0; | 2123 | unsigned done = 0; |
2023 | u8 usb_status; | 2124 | u8 usb_status; |
2024 | unsigned rpipe_ready = 0; | 2125 | unsigned rpipe_ready = 0; |
2126 | unsigned bytes_transferred = le32_to_cpu(xfer_result->dwTransferLength); | ||
2025 | 2127 | ||
2026 | spin_lock_irqsave(&xfer->lock, flags); | 2128 | spin_lock_irqsave(&xfer->lock, flags); |
2027 | seg_idx = xfer_result->bTransferSegment & 0x7f; | 2129 | seg_idx = xfer_result->bTransferSegment & 0x7f; |
@@ -2054,66 +2156,34 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer, | |||
2054 | /* FIXME: we ignore warnings, tally them for stats */ | 2156 | /* FIXME: we ignore warnings, tally them for stats */ |
2055 | if (usb_status & 0x40) /* Warning?... */ | 2157 | if (usb_status & 0x40) /* Warning?... */ |
2056 | usb_status = 0; /* ... pass */ | 2158 | usb_status = 0; /* ... pass */ |
2057 | if (usb_pipeisoc(xfer->urb->pipe)) { | 2159 | /* |
2160 | * If the last segment bit is set, complete the remaining segments. | ||
2161 | * When the current segment is completed, either in wa_buf_in_cb for | ||
2162 | * transfers with data or below for no data, the xfer will complete. | ||
2163 | */ | ||
2164 | if (xfer_result->bTransferSegment & 0x80) | ||
2165 | wa_complete_remaining_xfer_segs(xfer, seg, WA_SEG_DONE); | ||
2166 | if (usb_pipeisoc(xfer->urb->pipe) | ||
2167 | && (le32_to_cpu(xfer_result->dwNumOfPackets) > 0)) { | ||
2058 | /* set up WA state to read the isoc packet status next. */ | 2168 | /* set up WA state to read the isoc packet status next. */ |
2059 | wa->dti_isoc_xfer_in_progress = wa_xfer_id(xfer); | 2169 | wa->dti_isoc_xfer_in_progress = wa_xfer_id(xfer); |
2060 | wa->dti_isoc_xfer_seg = seg_idx; | 2170 | wa->dti_isoc_xfer_seg = seg_idx; |
2061 | wa->dti_state = WA_DTI_ISOC_PACKET_STATUS_PENDING; | 2171 | wa->dti_state = WA_DTI_ISOC_PACKET_STATUS_PENDING; |
2062 | } else if (xfer->is_inbound) { /* IN data phase: read to buffer */ | 2172 | } else if (xfer->is_inbound && !usb_pipeisoc(xfer->urb->pipe) |
2173 | && (bytes_transferred > 0)) { | ||
2174 | /* IN data phase: read to buffer */ | ||
2063 | seg->status = WA_SEG_DTI_PENDING; | 2175 | seg->status = WA_SEG_DTI_PENDING; |
2064 | BUG_ON(wa->buf_in_urb->status == -EINPROGRESS); | 2176 | result = wa_populate_buf_in_urb(wa, xfer, seg_idx, |
2065 | /* this should always be 0 before a resubmit. */ | 2177 | bytes_transferred); |
2066 | wa->buf_in_urb->num_mapped_sgs = 0; | 2178 | if (result < 0) |
2067 | 2179 | goto error_buf_in_populate; | |
2068 | if (xfer->is_dma) { | ||
2069 | wa->buf_in_urb->transfer_dma = | ||
2070 | xfer->urb->transfer_dma | ||
2071 | + (seg_idx * xfer->seg_size); | ||
2072 | wa->buf_in_urb->transfer_flags | ||
2073 | |= URB_NO_TRANSFER_DMA_MAP; | ||
2074 | wa->buf_in_urb->transfer_buffer = NULL; | ||
2075 | wa->buf_in_urb->sg = NULL; | ||
2076 | wa->buf_in_urb->num_sgs = 0; | ||
2077 | } else { | ||
2078 | /* do buffer or SG processing. */ | ||
2079 | wa->buf_in_urb->transfer_flags | ||
2080 | &= ~URB_NO_TRANSFER_DMA_MAP; | ||
2081 | |||
2082 | if (xfer->urb->transfer_buffer) { | ||
2083 | wa->buf_in_urb->transfer_buffer = | ||
2084 | xfer->urb->transfer_buffer | ||
2085 | + (seg_idx * xfer->seg_size); | ||
2086 | wa->buf_in_urb->sg = NULL; | ||
2087 | wa->buf_in_urb->num_sgs = 0; | ||
2088 | } else { | ||
2089 | /* allocate an SG list to store seg_size bytes | ||
2090 | and copy the subset of the xfer->urb->sg | ||
2091 | that matches the buffer subset we are | ||
2092 | about to read. */ | ||
2093 | wa->buf_in_urb->sg = wa_xfer_create_subset_sg( | ||
2094 | xfer->urb->sg, | ||
2095 | seg_idx * xfer->seg_size, | ||
2096 | le32_to_cpu( | ||
2097 | xfer_result->dwTransferLength), | ||
2098 | &(wa->buf_in_urb->num_sgs)); | ||
2099 | |||
2100 | if (!(wa->buf_in_urb->sg)) { | ||
2101 | wa->buf_in_urb->num_sgs = 0; | ||
2102 | goto error_sg_alloc; | ||
2103 | } | ||
2104 | wa->buf_in_urb->transfer_buffer = NULL; | ||
2105 | } | ||
2106 | } | ||
2107 | wa->buf_in_urb->transfer_buffer_length = | ||
2108 | le32_to_cpu(xfer_result->dwTransferLength); | ||
2109 | wa->buf_in_urb->context = seg; | ||
2110 | result = usb_submit_urb(wa->buf_in_urb, GFP_ATOMIC); | 2180 | result = usb_submit_urb(wa->buf_in_urb, GFP_ATOMIC); |
2111 | if (result < 0) | 2181 | if (result < 0) |
2112 | goto error_submit_buf_in; | 2182 | goto error_submit_buf_in; |
2113 | } else { | 2183 | } else { |
2114 | /* OUT data phase, complete it -- */ | 2184 | /* OUT data phase or no data, complete it -- */ |
2115 | seg->status = WA_SEG_DONE; | 2185 | seg->status = WA_SEG_DONE; |
2116 | seg->result = le32_to_cpu(xfer_result->dwTransferLength); | 2186 | seg->result = bytes_transferred; |
2117 | xfer->segs_done++; | 2187 | xfer->segs_done++; |
2118 | rpipe_ready = rpipe_avail_inc(rpipe); | 2188 | rpipe_ready = rpipe_avail_inc(rpipe); |
2119 | done = __wa_xfer_is_done(xfer); | 2189 | done = __wa_xfer_is_done(xfer); |
@@ -2137,13 +2207,13 @@ error_submit_buf_in: | |||
2137 | seg->result = result; | 2207 | seg->result = result; |
2138 | kfree(wa->buf_in_urb->sg); | 2208 | kfree(wa->buf_in_urb->sg); |
2139 | wa->buf_in_urb->sg = NULL; | 2209 | wa->buf_in_urb->sg = NULL; |
2140 | error_sg_alloc: | 2210 | error_buf_in_populate: |
2141 | __wa_xfer_abort(xfer); | 2211 | __wa_xfer_abort(xfer); |
2142 | seg->status = WA_SEG_ERROR; | 2212 | seg->status = WA_SEG_ERROR; |
2143 | error_complete: | 2213 | error_complete: |
2144 | xfer->segs_done++; | 2214 | xfer->segs_done++; |
2145 | rpipe_ready = rpipe_avail_inc(rpipe); | 2215 | rpipe_ready = rpipe_avail_inc(rpipe); |
2146 | wa_complete_remaining_xfer_segs(xfer, seg); | 2216 | wa_complete_remaining_xfer_segs(xfer, seg, seg->status); |
2147 | done = __wa_xfer_is_done(xfer); | 2217 | done = __wa_xfer_is_done(xfer); |
2148 | /* | 2218 | /* |
2149 | * queue work item to clear STALL for control endpoints. | 2219 | * queue work item to clear STALL for control endpoints. |
@@ -2172,7 +2242,7 @@ error_complete: | |||
2172 | 2242 | ||
2173 | error_bad_seg: | 2243 | error_bad_seg: |
2174 | spin_unlock_irqrestore(&xfer->lock, flags); | 2244 | spin_unlock_irqrestore(&xfer->lock, flags); |
2175 | wa_urb_dequeue(wa, xfer->urb); | 2245 | wa_urb_dequeue(wa, xfer->urb, -ENOENT); |
2176 | if (printk_ratelimit()) | 2246 | if (printk_ratelimit()) |
2177 | dev_err(dev, "xfer %p#%u: bad segment\n", xfer, seg_idx); | 2247 | dev_err(dev, "xfer %p#%u: bad segment\n", xfer, seg_idx); |
2178 | if (edc_inc(&wa->dti_edc, EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME)) { | 2248 | if (edc_inc(&wa->dti_edc, EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME)) { |
@@ -2192,7 +2262,7 @@ segment_aborted: | |||
2192 | * | 2262 | * |
2193 | * inbound transfers: need to schedule a buf_in_urb read | 2263 | * inbound transfers: need to schedule a buf_in_urb read |
2194 | */ | 2264 | */ |
2195 | static void wa_process_iso_packet_status(struct wahc *wa, struct urb *urb) | 2265 | static int wa_process_iso_packet_status(struct wahc *wa, struct urb *urb) |
2196 | { | 2266 | { |
2197 | struct device *dev = &wa->usb_iface->dev; | 2267 | struct device *dev = &wa->usb_iface->dev; |
2198 | struct wa_xfer_packet_status_hwaiso *packet_status; | 2268 | struct wa_xfer_packet_status_hwaiso *packet_status; |
@@ -2201,8 +2271,8 @@ static void wa_process_iso_packet_status(struct wahc *wa, struct urb *urb) | |||
2201 | unsigned long flags; | 2271 | unsigned long flags; |
2202 | struct wa_seg *seg; | 2272 | struct wa_seg *seg; |
2203 | struct wa_rpipe *rpipe; | 2273 | struct wa_rpipe *rpipe; |
2204 | unsigned done = 0; | 2274 | unsigned done = 0, dti_busy = 0, data_frame_count = 0, seg_index; |
2205 | unsigned rpipe_ready = 0, seg_index; | 2275 | unsigned first_frame_index = 0, rpipe_ready = 0; |
2206 | int expected_size; | 2276 | int expected_size; |
2207 | 2277 | ||
2208 | /* We have a xfer result buffer; check it */ | 2278 | /* We have a xfer result buffer; check it */ |
@@ -2238,18 +2308,48 @@ static void wa_process_iso_packet_status(struct wahc *wa, struct urb *urb) | |||
2238 | le16_to_cpu(packet_status->wLength)); | 2308 | le16_to_cpu(packet_status->wLength)); |
2239 | goto error_bad_seg; | 2309 | goto error_bad_seg; |
2240 | } | 2310 | } |
2241 | /* isoc packet status and lengths back xfer urb. */ | 2311 | /* write isoc packet status and lengths back to the xfer urb. */ |
2242 | status_array = packet_status->PacketStatus; | 2312 | status_array = packet_status->PacketStatus; |
2313 | xfer->urb->start_frame = | ||
2314 | wa->wusb->usb_hcd.driver->get_frame_number(&wa->wusb->usb_hcd); | ||
2243 | for (seg_index = 0; seg_index < seg->isoc_frame_count; ++seg_index) { | 2315 | for (seg_index = 0; seg_index < seg->isoc_frame_count; ++seg_index) { |
2244 | xfer->urb->iso_frame_desc[seg->index].status = | 2316 | struct usb_iso_packet_descriptor *iso_frame_desc = |
2317 | xfer->urb->iso_frame_desc; | ||
2318 | const int urb_frame_index = | ||
2319 | seg->isoc_frame_offset + seg_index; | ||
2320 | |||
2321 | iso_frame_desc[urb_frame_index].status = | ||
2245 | wa_xfer_status_to_errno( | 2322 | wa_xfer_status_to_errno( |
2246 | le16_to_cpu(status_array[seg_index].PacketStatus)); | 2323 | le16_to_cpu(status_array[seg_index].PacketStatus)); |
2247 | xfer->urb->iso_frame_desc[seg->index].actual_length = | 2324 | iso_frame_desc[urb_frame_index].actual_length = |
2248 | le16_to_cpu(status_array[seg_index].PacketLength); | 2325 | le16_to_cpu(status_array[seg_index].PacketLength); |
2326 | /* track the number of frames successfully transferred. */ | ||
2327 | if (iso_frame_desc[urb_frame_index].actual_length > 0) { | ||
2328 | /* save the starting frame index for buf_in_urb. */ | ||
2329 | if (!data_frame_count) | ||
2330 | first_frame_index = seg_index; | ||
2331 | ++data_frame_count; | ||
2332 | } | ||
2249 | } | 2333 | } |
2250 | 2334 | ||
2251 | if (!xfer->is_inbound) { | 2335 | if (xfer->is_inbound && data_frame_count) { |
2252 | /* OUT transfer, complete it -- */ | 2336 | int result; |
2337 | |||
2338 | seg->isoc_frame_index = first_frame_index; | ||
2339 | /* submit a read URB for the first frame with data. */ | ||
2340 | __wa_populate_buf_in_urb_isoc(wa, xfer, seg, | ||
2341 | seg->isoc_frame_index + seg->isoc_frame_offset); | ||
2342 | |||
2343 | result = usb_submit_urb(wa->buf_in_urb, GFP_ATOMIC); | ||
2344 | if (result < 0) { | ||
2345 | dev_err(dev, "DTI Error: Could not submit buf in URB (%d)", | ||
2346 | result); | ||
2347 | wa_reset_all(wa); | ||
2348 | } else if (data_frame_count > 1) | ||
2349 | /* If we need to read multiple frames, set DTI busy. */ | ||
2350 | dti_busy = 1; | ||
2351 | } else { | ||
2352 | /* OUT transfer or no more IN data, complete it -- */ | ||
2253 | seg->status = WA_SEG_DONE; | 2353 | seg->status = WA_SEG_DONE; |
2254 | xfer->segs_done++; | 2354 | xfer->segs_done++; |
2255 | rpipe_ready = rpipe_avail_inc(rpipe); | 2355 | rpipe_ready = rpipe_avail_inc(rpipe); |
@@ -2262,13 +2362,13 @@ static void wa_process_iso_packet_status(struct wahc *wa, struct urb *urb) | |||
2262 | if (rpipe_ready) | 2362 | if (rpipe_ready) |
2263 | wa_xfer_delayed_run(rpipe); | 2363 | wa_xfer_delayed_run(rpipe); |
2264 | wa_xfer_put(xfer); | 2364 | wa_xfer_put(xfer); |
2265 | return; | 2365 | return dti_busy; |
2266 | 2366 | ||
2267 | error_bad_seg: | 2367 | error_bad_seg: |
2268 | spin_unlock_irqrestore(&xfer->lock, flags); | 2368 | spin_unlock_irqrestore(&xfer->lock, flags); |
2269 | wa_xfer_put(xfer); | 2369 | wa_xfer_put(xfer); |
2270 | error_parse_buffer: | 2370 | error_parse_buffer: |
2271 | return; | 2371 | return dti_busy; |
2272 | } | 2372 | } |
2273 | 2373 | ||
2274 | /* | 2374 | /* |
@@ -2288,7 +2388,7 @@ static void wa_buf_in_cb(struct urb *urb) | |||
2288 | struct wahc *wa; | 2388 | struct wahc *wa; |
2289 | struct device *dev; | 2389 | struct device *dev; |
2290 | struct wa_rpipe *rpipe; | 2390 | struct wa_rpipe *rpipe; |
2291 | unsigned rpipe_ready; | 2391 | unsigned rpipe_ready = 0, seg_index, isoc_data_frame_count = 0; |
2292 | unsigned long flags; | 2392 | unsigned long flags; |
2293 | u8 done = 0; | 2393 | u8 done = 0; |
2294 | 2394 | ||
@@ -2296,19 +2396,61 @@ static void wa_buf_in_cb(struct urb *urb) | |||
2296 | kfree(urb->sg); | 2396 | kfree(urb->sg); |
2297 | urb->sg = NULL; | 2397 | urb->sg = NULL; |
2298 | 2398 | ||
2399 | spin_lock_irqsave(&xfer->lock, flags); | ||
2400 | wa = xfer->wa; | ||
2401 | dev = &wa->usb_iface->dev; | ||
2402 | |||
2403 | if (usb_pipeisoc(xfer->urb->pipe)) { | ||
2404 | /* | ||
2405 | * Find the next isoc frame with data. Bail out after | ||
2406 | * isoc_data_frame_count > 1 since there is no need to walk | ||
2407 | * the entire frame array. We just need to know if | ||
2408 | * isoc_data_frame_count is 0, 1, or >1. | ||
2409 | */ | ||
2410 | seg_index = seg->isoc_frame_index + 1; | ||
2411 | while ((seg_index < seg->isoc_frame_count) | ||
2412 | && (isoc_data_frame_count <= 1)) { | ||
2413 | struct usb_iso_packet_descriptor *iso_frame_desc = | ||
2414 | xfer->urb->iso_frame_desc; | ||
2415 | const int urb_frame_index = | ||
2416 | seg->isoc_frame_offset + seg_index; | ||
2417 | |||
2418 | if (iso_frame_desc[urb_frame_index].actual_length > 0) { | ||
2419 | /* save the index of the next frame with data */ | ||
2420 | if (!isoc_data_frame_count) | ||
2421 | seg->isoc_frame_index = seg_index; | ||
2422 | ++isoc_data_frame_count; | ||
2423 | } | ||
2424 | ++seg_index; | ||
2425 | } | ||
2426 | } | ||
2427 | spin_unlock_irqrestore(&xfer->lock, flags); | ||
2428 | |||
2299 | switch (urb->status) { | 2429 | switch (urb->status) { |
2300 | case 0: | 2430 | case 0: |
2301 | spin_lock_irqsave(&xfer->lock, flags); | 2431 | spin_lock_irqsave(&xfer->lock, flags); |
2302 | wa = xfer->wa; | 2432 | |
2303 | dev = &wa->usb_iface->dev; | 2433 | seg->result += urb->actual_length; |
2304 | rpipe = xfer->ep->hcpriv; | 2434 | if (isoc_data_frame_count > 0) { |
2305 | dev_dbg(dev, "xfer %p#%u: data in done (%zu bytes)\n", | 2435 | int result; |
2306 | xfer, seg->index, (size_t)urb->actual_length); | 2436 | /* submit a read URB for the first frame with data. */ |
2307 | seg->status = WA_SEG_DONE; | 2437 | __wa_populate_buf_in_urb_isoc(wa, xfer, seg, |
2308 | seg->result = urb->actual_length; | 2438 | seg->isoc_frame_index + seg->isoc_frame_offset); |
2309 | xfer->segs_done++; | 2439 | result = usb_submit_urb(wa->buf_in_urb, GFP_ATOMIC); |
2310 | rpipe_ready = rpipe_avail_inc(rpipe); | 2440 | if (result < 0) { |
2311 | done = __wa_xfer_is_done(xfer); | 2441 | dev_err(dev, "DTI Error: Could not submit buf in URB (%d)", |
2442 | result); | ||
2443 | wa_reset_all(wa); | ||
2444 | } | ||
2445 | } else { | ||
2446 | rpipe = xfer->ep->hcpriv; | ||
2447 | seg->status = WA_SEG_DONE; | ||
2448 | dev_dbg(dev, "xfer %p#%u: data in done (%zu bytes)\n", | ||
2449 | xfer, seg->index, seg->result); | ||
2450 | xfer->segs_done++; | ||
2451 | rpipe_ready = rpipe_avail_inc(rpipe); | ||
2452 | done = __wa_xfer_is_done(xfer); | ||
2453 | } | ||
2312 | spin_unlock_irqrestore(&xfer->lock, flags); | 2454 | spin_unlock_irqrestore(&xfer->lock, flags); |
2313 | if (done) | 2455 | if (done) |
2314 | wa_xfer_completion(xfer); | 2456 | wa_xfer_completion(xfer); |
@@ -2320,8 +2462,6 @@ static void wa_buf_in_cb(struct urb *urb) | |||
2320 | break; | 2462 | break; |
2321 | default: /* Other errors ... */ | 2463 | default: /* Other errors ... */ |
2322 | spin_lock_irqsave(&xfer->lock, flags); | 2464 | spin_lock_irqsave(&xfer->lock, flags); |
2323 | wa = xfer->wa; | ||
2324 | dev = &wa->usb_iface->dev; | ||
2325 | rpipe = xfer->ep->hcpriv; | 2465 | rpipe = xfer->ep->hcpriv; |
2326 | if (printk_ratelimit()) | 2466 | if (printk_ratelimit()) |
2327 | dev_err(dev, "xfer %p#%u: data in error %d\n", | 2467 | dev_err(dev, "xfer %p#%u: data in error %d\n", |
@@ -2344,6 +2484,20 @@ static void wa_buf_in_cb(struct urb *urb) | |||
2344 | if (rpipe_ready) | 2484 | if (rpipe_ready) |
2345 | wa_xfer_delayed_run(rpipe); | 2485 | wa_xfer_delayed_run(rpipe); |
2346 | } | 2486 | } |
2487 | /* | ||
2488 | * If we are in this callback and isoc_data_frame_count > 0, it means | ||
2489 | * that the dti_urb submission was delayed in wa_dti_cb. Once | ||
2490 | * isoc_data_frame_count gets to 1, we can submit the deferred URB | ||
2491 | * since the last buf_in_urb was just submitted. | ||
2492 | */ | ||
2493 | if (isoc_data_frame_count == 1) { | ||
2494 | int result = usb_submit_urb(wa->dti_urb, GFP_ATOMIC); | ||
2495 | if (result < 0) { | ||
2496 | dev_err(dev, "DTI Error: Could not submit DTI URB (%d)\n", | ||
2497 | result); | ||
2498 | wa_reset_all(wa); | ||
2499 | } | ||
2500 | } | ||
2347 | } | 2501 | } |
2348 | 2502 | ||
2349 | /* | 2503 | /* |
@@ -2374,7 +2528,7 @@ static void wa_buf_in_cb(struct urb *urb) | |||
2374 | */ | 2528 | */ |
2375 | static void wa_dti_cb(struct urb *urb) | 2529 | static void wa_dti_cb(struct urb *urb) |
2376 | { | 2530 | { |
2377 | int result; | 2531 | int result, dti_busy = 0; |
2378 | struct wahc *wa = urb->context; | 2532 | struct wahc *wa = urb->context; |
2379 | struct device *dev = &wa->usb_iface->dev; | 2533 | struct device *dev = &wa->usb_iface->dev; |
2380 | u32 xfer_id; | 2534 | u32 xfer_id; |
@@ -2422,7 +2576,7 @@ static void wa_dti_cb(struct urb *urb) | |||
2422 | wa_xfer_result_chew(wa, xfer, xfer_result); | 2576 | wa_xfer_result_chew(wa, xfer, xfer_result); |
2423 | wa_xfer_put(xfer); | 2577 | wa_xfer_put(xfer); |
2424 | } else if (wa->dti_state == WA_DTI_ISOC_PACKET_STATUS_PENDING) { | 2578 | } else if (wa->dti_state == WA_DTI_ISOC_PACKET_STATUS_PENDING) { |
2425 | wa_process_iso_packet_status(wa, urb); | 2579 | dti_busy = wa_process_iso_packet_status(wa, urb); |
2426 | } else { | 2580 | } else { |
2427 | dev_err(dev, "DTI Error: unexpected EP state = %d\n", | 2581 | dev_err(dev, "DTI Error: unexpected EP state = %d\n", |
2428 | wa->dti_state); | 2582 | wa->dti_state); |
@@ -2445,12 +2599,15 @@ static void wa_dti_cb(struct urb *urb) | |||
2445 | dev_err(dev, "DTI: URB error %d\n", urb->status); | 2599 | dev_err(dev, "DTI: URB error %d\n", urb->status); |
2446 | break; | 2600 | break; |
2447 | } | 2601 | } |
2448 | /* Resubmit the DTI URB */ | 2602 | |
2449 | result = usb_submit_urb(wa->dti_urb, GFP_ATOMIC); | 2603 | /* Resubmit the DTI URB if we are not busy processing isoc in frames. */ |
2450 | if (result < 0) { | 2604 | if (!dti_busy) { |
2451 | dev_err(dev, "DTI Error: Could not submit DTI URB (%d), " | 2605 | result = usb_submit_urb(wa->dti_urb, GFP_ATOMIC); |
2452 | "resetting\n", result); | 2606 | if (result < 0) { |
2453 | wa_reset_all(wa); | 2607 | dev_err(dev, "DTI Error: Could not submit DTI URB (%d)\n", |
2608 | result); | ||
2609 | wa_reset_all(wa); | ||
2610 | } | ||
2454 | } | 2611 | } |
2455 | out: | 2612 | out: |
2456 | return; | 2613 | return; |
@@ -2517,8 +2674,8 @@ void wa_handle_notif_xfer(struct wahc *wa, struct wa_notif_hdr *notif_hdr) | |||
2517 | NULL, 0, wa_buf_in_cb, wa); | 2674 | NULL, 0, wa_buf_in_cb, wa); |
2518 | result = usb_submit_urb(wa->dti_urb, GFP_KERNEL); | 2675 | result = usb_submit_urb(wa->dti_urb, GFP_KERNEL); |
2519 | if (result < 0) { | 2676 | if (result < 0) { |
2520 | dev_err(dev, "DTI Error: Could not submit DTI URB (%d), " | 2677 | dev_err(dev, "DTI Error: Could not submit DTI URB (%d) resetting\n", |
2521 | "resetting\n", result); | 2678 | result); |
2522 | goto error_dti_urb_submit; | 2679 | goto error_dti_urb_submit; |
2523 | } | 2680 | } |
2524 | out: | 2681 | out: |
diff --git a/drivers/usb/wusbcore/wusbhc.c b/drivers/usb/wusbcore/wusbhc.c index 742c607d1fa3..3e1ba51d1a43 100644 --- a/drivers/usb/wusbcore/wusbhc.c +++ b/drivers/usb/wusbcore/wusbhc.c | |||
@@ -55,7 +55,8 @@ static struct wusbhc *usbhc_dev_to_wusbhc(struct device *dev) | |||
55 | * value of trust_timeout is jiffies. | 55 | * value of trust_timeout is jiffies. |
56 | */ | 56 | */ |
57 | static ssize_t wusb_trust_timeout_show(struct device *dev, | 57 | static ssize_t wusb_trust_timeout_show(struct device *dev, |
58 | struct device_attribute *attr, char *buf) | 58 | struct device_attribute *attr, |
59 | char *buf) | ||
59 | { | 60 | { |
60 | struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev); | 61 | struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev); |
61 | 62 | ||
@@ -173,7 +174,8 @@ static ssize_t wusb_phy_rate_store(struct device *dev, | |||
173 | wusbhc->phy_rate = phy_rate; | 174 | wusbhc->phy_rate = phy_rate; |
174 | return size; | 175 | return size; |
175 | } | 176 | } |
176 | static DEVICE_ATTR(wusb_phy_rate, 0644, wusb_phy_rate_show, wusb_phy_rate_store); | 177 | static DEVICE_ATTR(wusb_phy_rate, 0644, wusb_phy_rate_show, |
178 | wusb_phy_rate_store); | ||
177 | 179 | ||
178 | static ssize_t wusb_dnts_show(struct device *dev, | 180 | static ssize_t wusb_dnts_show(struct device *dev, |
179 | struct device_attribute *attr, | 181 | struct device_attribute *attr, |
@@ -227,7 +229,8 @@ static ssize_t wusb_retry_count_store(struct device *dev, | |||
227 | if (result != 1) | 229 | if (result != 1) |
228 | return -EINVAL; | 230 | return -EINVAL; |
229 | 231 | ||
230 | wusbhc->retry_count = max_t(uint8_t, retry_count, WUSB_RETRY_COUNT_MAX); | 232 | wusbhc->retry_count = max_t(uint8_t, retry_count, |
233 | WUSB_RETRY_COUNT_MAX); | ||
231 | 234 | ||
232 | return size; | 235 | return size; |
233 | } | 236 | } |
@@ -321,7 +324,8 @@ int wusbhc_b_create(struct wusbhc *wusbhc) | |||
321 | 324 | ||
322 | result = sysfs_create_group(wusbhc_kobj(wusbhc), &wusbhc_attr_group); | 325 | result = sysfs_create_group(wusbhc_kobj(wusbhc), &wusbhc_attr_group); |
323 | if (result < 0) { | 326 | if (result < 0) { |
324 | dev_err(dev, "Cannot register WUSBHC attributes: %d\n", result); | 327 | dev_err(dev, "Cannot register WUSBHC attributes: %d\n", |
328 | result); | ||
325 | goto error_create_attr_group; | 329 | goto error_create_attr_group; |
326 | } | 330 | } |
327 | 331 | ||
@@ -419,13 +423,14 @@ EXPORT_SYMBOL_GPL(wusb_cluster_id_put); | |||
419 | * - After a successful transfer, update the trust timeout timestamp | 423 | * - After a successful transfer, update the trust timeout timestamp |
420 | * for the WUSB device. | 424 | * for the WUSB device. |
421 | * | 425 | * |
422 | * - [WUSB] sections 4.13 and 7.5.1 specifies the stop retrasmittion | 426 | * - [WUSB] sections 4.13 and 7.5.1 specify the stop retransmission |
423 | * condition for the WCONNECTACK_IE is that the host has observed | 427 | * condition for the WCONNECTACK_IE is that the host has observed |
424 | * the associated device responding to a control transfer. | 428 | * the associated device responding to a control transfer. |
425 | */ | 429 | */ |
426 | void wusbhc_giveback_urb(struct wusbhc *wusbhc, struct urb *urb, int status) | 430 | void wusbhc_giveback_urb(struct wusbhc *wusbhc, struct urb *urb, int status) |
427 | { | 431 | { |
428 | struct wusb_dev *wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, urb->dev); | 432 | struct wusb_dev *wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, |
433 | urb->dev); | ||
429 | 434 | ||
430 | if (status == 0 && wusb_dev) { | 435 | if (status == 0 && wusb_dev) { |
431 | wusb_dev->entry_ts = jiffies; | 436 | wusb_dev->entry_ts = jiffies; |
diff --git a/drivers/usb/wusbcore/wusbhc.h b/drivers/usb/wusbcore/wusbhc.h index 6bd3b819a6b5..2384add45371 100644 --- a/drivers/usb/wusbcore/wusbhc.h +++ b/drivers/usb/wusbcore/wusbhc.h | |||
@@ -164,7 +164,7 @@ struct wusb_port { | |||
164 | * functions/operations that only deal with general Wireless USB HC | 164 | * functions/operations that only deal with general Wireless USB HC |
165 | * issues use this data type to refer to the host. | 165 | * issues use this data type to refer to the host. |
166 | * | 166 | * |
167 | * @usb_hcd Instantiation of a USB host controller | 167 | * @usb_hcd Instantiation of a USB host controller |
168 | * (initialized by upper layer [HWA=HC or WHCI]. | 168 | * (initialized by upper layer [HWA=HC or WHCI]. |
169 | * | 169 | * |
170 | * @dev Device that implements this; initialized by the | 170 | * @dev Device that implements this; initialized by the |
@@ -196,7 +196,7 @@ struct wusb_port { | |||
196 | * @ports_max Number of simultaneous device connections (fake | 196 | * @ports_max Number of simultaneous device connections (fake |
197 | * ports) this HC will take. Read-only. | 197 | * ports) this HC will take. Read-only. |
198 | * | 198 | * |
199 | * @port Array of port status for each fake root port. Guaranteed to | 199 | * @port Array of port status for each fake root port. Guaranteed to |
200 | * always be the same length during device existence | 200 | * always be the same length during device existence |
201 | * [this allows for some unlocked but referenced reading]. | 201 | * [this allows for some unlocked but referenced reading]. |
202 | * | 202 | * |
@@ -329,7 +329,8 @@ void wusbhc_pal_unregister(struct wusbhc *wusbhc); | |||
329 | * This is a safe assumption as @usb_dev->bus is referenced all the | 329 | * This is a safe assumption as @usb_dev->bus is referenced all the |
330 | * time during the @usb_dev life cycle. | 330 | * time during the @usb_dev life cycle. |
331 | */ | 331 | */ |
332 | static inline struct usb_hcd *usb_hcd_get_by_usb_dev(struct usb_device *usb_dev) | 332 | static inline |
333 | struct usb_hcd *usb_hcd_get_by_usb_dev(struct usb_device *usb_dev) | ||
333 | { | 334 | { |
334 | struct usb_hcd *usb_hcd; | 335 | struct usb_hcd *usb_hcd; |
335 | usb_hcd = container_of(usb_dev->bus, struct usb_hcd, self); | 336 | usb_hcd = container_of(usb_dev->bus, struct usb_hcd, self); |