diff options
author | David Vrabel <david.vrabel@csr.com> | 2009-01-22 14:12:32 -0500 |
---|---|---|
committer | David Vrabel <david.vrabel@csr.com> | 2009-01-22 14:12:32 -0500 |
commit | dff243f7cb3a2ebbb09093066c1bc4a90ff5b3a4 (patch) | |
tree | 1c63e7c2f879cd322ca785671b74b4ff796dd24c /drivers/usb | |
parent | a5e6ced58d423cb09c4fc0087dcfdb0b5deb5e1c (diff) | |
parent | f3b8436ad9a8ad36b3c9fa1fe030c7f38e5d3d0b (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6 into for-upstream
Diffstat (limited to 'drivers/usb')
117 files changed, 15678 insertions, 1328 deletions
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 289d81adfb9c..83babb0a1df7 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig | |||
@@ -150,4 +150,6 @@ source "drivers/usb/atm/Kconfig" | |||
150 | 150 | ||
151 | source "drivers/usb/gadget/Kconfig" | 151 | source "drivers/usb/gadget/Kconfig" |
152 | 152 | ||
153 | source "drivers/usb/otg/Kconfig" | ||
154 | |||
153 | endif # USB_SUPPORT | 155 | endif # USB_SUPPORT |
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index d50a99f70aee..00b47ea24f86 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c | |||
@@ -1275,7 +1275,7 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message) | |||
1275 | struct acm *acm = usb_get_intfdata(intf); | 1275 | struct acm *acm = usb_get_intfdata(intf); |
1276 | int cnt; | 1276 | int cnt; |
1277 | 1277 | ||
1278 | if (acm->dev->auto_pm) { | 1278 | if (message.event & PM_EVENT_AUTO) { |
1279 | int b; | 1279 | int b; |
1280 | 1280 | ||
1281 | spin_lock_irq(&acm->read_lock); | 1281 | spin_lock_irq(&acm->read_lock); |
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c index 5a8ecc045e3f..3771d6e6d0cc 100644 --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c | |||
@@ -764,7 +764,8 @@ static int wdm_suspend(struct usb_interface *intf, pm_message_t message) | |||
764 | 764 | ||
765 | mutex_lock(&desc->plock); | 765 | mutex_lock(&desc->plock); |
766 | #ifdef CONFIG_PM | 766 | #ifdef CONFIG_PM |
767 | if (interface_to_usbdev(desc->intf)->auto_pm && test_bit(WDM_IN_USE, &desc->flags)) { | 767 | if ((message.event & PM_EVENT_AUTO) && |
768 | test_bit(WDM_IN_USE, &desc->flags)) { | ||
768 | rv = -EBUSY; | 769 | rv = -EBUSY; |
769 | } else { | 770 | } else { |
770 | #endif | 771 | #endif |
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c index 43a863c5cc43..0f5c05f6f9df 100644 --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include <linux/init.h> | 22 | #include <linux/init.h> |
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/kernel.h> | ||
24 | #include <linux/fs.h> | 25 | #include <linux/fs.h> |
25 | #include <linux/uaccess.h> | 26 | #include <linux/uaccess.h> |
26 | #include <linux/kref.h> | 27 | #include <linux/kref.h> |
@@ -482,7 +483,6 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf, | |||
482 | int retval; | 483 | int retval; |
483 | int actual; | 484 | int actual; |
484 | unsigned long int n_bytes; | 485 | unsigned long int n_bytes; |
485 | int n; | ||
486 | int remaining; | 486 | int remaining; |
487 | int done; | 487 | int done; |
488 | int this_part; | 488 | int this_part; |
@@ -526,11 +526,8 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf, | |||
526 | goto exit; | 526 | goto exit; |
527 | } | 527 | } |
528 | 528 | ||
529 | n_bytes = 12 + this_part; | 529 | n_bytes = roundup(12 + this_part, 4); |
530 | if (this_part % 4) | 530 | memset(buffer + 12 + this_part, 0, n_bytes - (12 + this_part)); |
531 | n_bytes += 4 - this_part % 4; | ||
532 | for (n = 12 + this_part; n < n_bytes; n++) | ||
533 | buffer[n] = 0; | ||
534 | 531 | ||
535 | retval = usb_bulk_msg(data->usb_dev, | 532 | retval = usb_bulk_msg(data->usb_dev, |
536 | usb_sndbulkpipe(data->usb_dev, | 533 | usb_sndbulkpipe(data->usb_dev, |
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index aa79280df15d..26fece124e0e 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c | |||
@@ -981,9 +981,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
981 | return -EINVAL; | 981 | return -EINVAL; |
982 | if (!uurb->buffer) | 982 | if (!uurb->buffer) |
983 | return -EINVAL; | 983 | return -EINVAL; |
984 | if (uurb->signr != 0 && (uurb->signr < SIGRTMIN || | ||
985 | uurb->signr > SIGRTMAX)) | ||
986 | return -EINVAL; | ||
987 | if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL && | 984 | if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL && |
988 | (uurb->endpoint & ~USB_ENDPOINT_DIR_MASK) == 0)) { | 985 | (uurb->endpoint & ~USB_ENDPOINT_DIR_MASK) == 0)) { |
989 | ifnum = findintfep(ps->dev, uurb->endpoint); | 986 | ifnum = findintfep(ps->dev, uurb->endpoint); |
@@ -1320,7 +1317,7 @@ static int get_urb32(struct usbdevfs_urb *kurb, | |||
1320 | if (__get_user(uptr, &uurb->buffer)) | 1317 | if (__get_user(uptr, &uurb->buffer)) |
1321 | return -EFAULT; | 1318 | return -EFAULT; |
1322 | kurb->buffer = compat_ptr(uptr); | 1319 | kurb->buffer = compat_ptr(uptr); |
1323 | if (__get_user(uptr, &uurb->buffer)) | 1320 | if (__get_user(uptr, &uurb->usercontext)) |
1324 | return -EFAULT; | 1321 | return -EFAULT; |
1325 | kurb->usercontext = compat_ptr(uptr); | 1322 | kurb->usercontext = compat_ptr(uptr); |
1326 | 1323 | ||
@@ -1401,8 +1398,6 @@ static int proc_disconnectsignal(struct dev_state *ps, void __user *arg) | |||
1401 | 1398 | ||
1402 | if (copy_from_user(&ds, arg, sizeof(ds))) | 1399 | if (copy_from_user(&ds, arg, sizeof(ds))) |
1403 | return -EFAULT; | 1400 | return -EFAULT; |
1404 | if (ds.signr != 0 && (ds.signr < SIGRTMIN || ds.signr > SIGRTMAX)) | ||
1405 | return -EINVAL; | ||
1406 | ps->discsignr = ds.signr; | 1401 | ps->discsignr = ds.signr; |
1407 | ps->disccontext = ds.context; | 1402 | ps->disccontext = ds.context; |
1408 | return 0; | 1403 | return 0; |
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 8c081308b0e2..98760553bc95 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -184,6 +184,20 @@ static int usb_unbind_device(struct device *dev) | |||
184 | return 0; | 184 | return 0; |
185 | } | 185 | } |
186 | 186 | ||
187 | /* | ||
188 | * Cancel any pending scheduled resets | ||
189 | * | ||
190 | * [see usb_queue_reset_device()] | ||
191 | * | ||
192 | * Called after unconfiguring / when releasing interfaces. See | ||
193 | * comments in __usb_queue_reset_device() regarding | ||
194 | * udev->reset_running. | ||
195 | */ | ||
196 | static void usb_cancel_queued_reset(struct usb_interface *iface) | ||
197 | { | ||
198 | if (iface->reset_running == 0) | ||
199 | cancel_work_sync(&iface->reset_ws); | ||
200 | } | ||
187 | 201 | ||
188 | /* called from driver core with dev locked */ | 202 | /* called from driver core with dev locked */ |
189 | static int usb_probe_interface(struct device *dev) | 203 | static int usb_probe_interface(struct device *dev) |
@@ -242,6 +256,7 @@ static int usb_probe_interface(struct device *dev) | |||
242 | mark_quiesced(intf); | 256 | mark_quiesced(intf); |
243 | intf->needs_remote_wakeup = 0; | 257 | intf->needs_remote_wakeup = 0; |
244 | intf->condition = USB_INTERFACE_UNBOUND; | 258 | intf->condition = USB_INTERFACE_UNBOUND; |
259 | usb_cancel_queued_reset(intf); | ||
245 | } else | 260 | } else |
246 | intf->condition = USB_INTERFACE_BOUND; | 261 | intf->condition = USB_INTERFACE_BOUND; |
247 | 262 | ||
@@ -272,6 +287,7 @@ static int usb_unbind_interface(struct device *dev) | |||
272 | usb_disable_interface(udev, intf); | 287 | usb_disable_interface(udev, intf); |
273 | 288 | ||
274 | driver->disconnect(intf); | 289 | driver->disconnect(intf); |
290 | usb_cancel_queued_reset(intf); | ||
275 | 291 | ||
276 | /* Reset other interface state. | 292 | /* Reset other interface state. |
277 | * We cannot do a Set-Interface if the device is suspended or | 293 | * We cannot do a Set-Interface if the device is suspended or |
@@ -279,9 +295,12 @@ static int usb_unbind_interface(struct device *dev) | |||
279 | * altsetting means creating new endpoint device entries). | 295 | * altsetting means creating new endpoint device entries). |
280 | * When either of these happens, defer the Set-Interface. | 296 | * When either of these happens, defer the Set-Interface. |
281 | */ | 297 | */ |
282 | if (intf->cur_altsetting->desc.bAlternateSetting == 0) | 298 | if (intf->cur_altsetting->desc.bAlternateSetting == 0) { |
283 | ; /* Already in altsetting 0 so skip Set-Interface */ | 299 | /* Already in altsetting 0 so skip Set-Interface. |
284 | else if (!error && intf->dev.power.status == DPM_ON) | 300 | * Just re-enable it without affecting the endpoint toggles. |
301 | */ | ||
302 | usb_enable_interface(udev, intf, false); | ||
303 | } else if (!error && intf->dev.power.status == DPM_ON) | ||
285 | usb_set_interface(udev, intf->altsetting[0]. | 304 | usb_set_interface(udev, intf->altsetting[0]. |
286 | desc.bInterfaceNumber, 0); | 305 | desc.bInterfaceNumber, 0); |
287 | else | 306 | else |
@@ -380,8 +399,10 @@ void usb_driver_release_interface(struct usb_driver *driver, | |||
380 | if (device_is_registered(dev)) { | 399 | if (device_is_registered(dev)) { |
381 | iface->condition = USB_INTERFACE_UNBINDING; | 400 | iface->condition = USB_INTERFACE_UNBINDING; |
382 | device_release_driver(dev); | 401 | device_release_driver(dev); |
402 | } else { | ||
403 | iface->condition = USB_INTERFACE_UNBOUND; | ||
404 | usb_cancel_queued_reset(iface); | ||
383 | } | 405 | } |
384 | |||
385 | dev->driver = NULL; | 406 | dev->driver = NULL; |
386 | usb_set_intfdata(iface, NULL); | 407 | usb_set_intfdata(iface, NULL); |
387 | 408 | ||
@@ -904,7 +925,7 @@ static int usb_suspend_device(struct usb_device *udev, pm_message_t msg) | |||
904 | } | 925 | } |
905 | 926 | ||
906 | /* Caller has locked udev's pm_mutex */ | 927 | /* Caller has locked udev's pm_mutex */ |
907 | static int usb_resume_device(struct usb_device *udev) | 928 | static int usb_resume_device(struct usb_device *udev, pm_message_t msg) |
908 | { | 929 | { |
909 | struct usb_device_driver *udriver; | 930 | struct usb_device_driver *udriver; |
910 | int status = 0; | 931 | int status = 0; |
@@ -922,7 +943,7 @@ static int usb_resume_device(struct usb_device *udev) | |||
922 | udev->reset_resume = 1; | 943 | udev->reset_resume = 1; |
923 | 944 | ||
924 | udriver = to_usb_device_driver(udev->dev.driver); | 945 | udriver = to_usb_device_driver(udev->dev.driver); |
925 | status = udriver->resume(udev); | 946 | status = udriver->resume(udev, msg); |
926 | 947 | ||
927 | done: | 948 | done: |
928 | dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); | 949 | dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); |
@@ -942,7 +963,8 @@ static int usb_suspend_interface(struct usb_device *udev, | |||
942 | if (udev->state == USB_STATE_NOTATTACHED || !is_active(intf)) | 963 | if (udev->state == USB_STATE_NOTATTACHED || !is_active(intf)) |
943 | goto done; | 964 | goto done; |
944 | 965 | ||
945 | if (intf->condition == USB_INTERFACE_UNBOUND) /* This can't happen */ | 966 | /* This can happen; see usb_driver_release_interface() */ |
967 | if (intf->condition == USB_INTERFACE_UNBOUND) | ||
946 | goto done; | 968 | goto done; |
947 | driver = to_usb_driver(intf->dev.driver); | 969 | driver = to_usb_driver(intf->dev.driver); |
948 | 970 | ||
@@ -950,7 +972,7 @@ static int usb_suspend_interface(struct usb_device *udev, | |||
950 | status = driver->suspend(intf, msg); | 972 | status = driver->suspend(intf, msg); |
951 | if (status == 0) | 973 | if (status == 0) |
952 | mark_quiesced(intf); | 974 | mark_quiesced(intf); |
953 | else if (!udev->auto_pm) | 975 | else if (!(msg.event & PM_EVENT_AUTO)) |
954 | dev_err(&intf->dev, "%s error %d\n", | 976 | dev_err(&intf->dev, "%s error %d\n", |
955 | "suspend", status); | 977 | "suspend", status); |
956 | } else { | 978 | } else { |
@@ -968,7 +990,7 @@ static int usb_suspend_interface(struct usb_device *udev, | |||
968 | 990 | ||
969 | /* Caller has locked intf's usb_device's pm_mutex */ | 991 | /* Caller has locked intf's usb_device's pm_mutex */ |
970 | static int usb_resume_interface(struct usb_device *udev, | 992 | static int usb_resume_interface(struct usb_device *udev, |
971 | struct usb_interface *intf, int reset_resume) | 993 | struct usb_interface *intf, pm_message_t msg, int reset_resume) |
972 | { | 994 | { |
973 | struct usb_driver *driver; | 995 | struct usb_driver *driver; |
974 | int status = 0; | 996 | int status = 0; |
@@ -1092,7 +1114,7 @@ static int autosuspend_check(struct usb_device *udev, int reschedule) | |||
1092 | if (reschedule) { | 1114 | if (reschedule) { |
1093 | if (!timer_pending(&udev->autosuspend.timer)) { | 1115 | if (!timer_pending(&udev->autosuspend.timer)) { |
1094 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, | 1116 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, |
1095 | round_jiffies_relative(suspend_time - j)); | 1117 | round_jiffies_up_relative(suspend_time - j)); |
1096 | } | 1118 | } |
1097 | return -EAGAIN; | 1119 | return -EAGAIN; |
1098 | } | 1120 | } |
@@ -1119,10 +1141,9 @@ static inline int autosuspend_check(struct usb_device *udev, int reschedule) | |||
1119 | * all the interfaces which were suspended are resumed so that they remain | 1141 | * all the interfaces which were suspended are resumed so that they remain |
1120 | * in the same state as the device. | 1142 | * in the same state as the device. |
1121 | * | 1143 | * |
1122 | * If an autosuspend is in progress (@udev->auto_pm is set), the routine | 1144 | * If an autosuspend is in progress the routine checks first to make sure |
1123 | * checks first to make sure that neither the device itself or any of its | 1145 | * that neither the device itself or any of its active interfaces is in use |
1124 | * active interfaces is in use (pm_usage_cnt is greater than 0). If they | 1146 | * (pm_usage_cnt is greater than 0). If they are, the autosuspend fails. |
1125 | * are, the autosuspend fails. | ||
1126 | * | 1147 | * |
1127 | * If the suspend succeeds, the routine recursively queues an autosuspend | 1148 | * If the suspend succeeds, the routine recursively queues an autosuspend |
1128 | * request for @udev's parent device, thereby propagating the change up | 1149 | * request for @udev's parent device, thereby propagating the change up |
@@ -1157,7 +1178,7 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | |||
1157 | 1178 | ||
1158 | udev->do_remote_wakeup = device_may_wakeup(&udev->dev); | 1179 | udev->do_remote_wakeup = device_may_wakeup(&udev->dev); |
1159 | 1180 | ||
1160 | if (udev->auto_pm) { | 1181 | if (msg.event & PM_EVENT_AUTO) { |
1161 | status = autosuspend_check(udev, 0); | 1182 | status = autosuspend_check(udev, 0); |
1162 | if (status < 0) | 1183 | if (status < 0) |
1163 | goto done; | 1184 | goto done; |
@@ -1177,13 +1198,16 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | |||
1177 | 1198 | ||
1178 | /* If the suspend failed, resume interfaces that did get suspended */ | 1199 | /* If the suspend failed, resume interfaces that did get suspended */ |
1179 | if (status != 0) { | 1200 | if (status != 0) { |
1201 | pm_message_t msg2; | ||
1202 | |||
1203 | msg2.event = msg.event ^ (PM_EVENT_SUSPEND | PM_EVENT_RESUME); | ||
1180 | while (--i >= 0) { | 1204 | while (--i >= 0) { |
1181 | intf = udev->actconfig->interface[i]; | 1205 | intf = udev->actconfig->interface[i]; |
1182 | usb_resume_interface(udev, intf, 0); | 1206 | usb_resume_interface(udev, intf, msg2, 0); |
1183 | } | 1207 | } |
1184 | 1208 | ||
1185 | /* Try another autosuspend when the interfaces aren't busy */ | 1209 | /* Try another autosuspend when the interfaces aren't busy */ |
1186 | if (udev->auto_pm) | 1210 | if (msg.event & PM_EVENT_AUTO) |
1187 | autosuspend_check(udev, status == -EBUSY); | 1211 | autosuspend_check(udev, status == -EBUSY); |
1188 | 1212 | ||
1189 | /* If the suspend succeeded then prevent any more URB submissions, | 1213 | /* If the suspend succeeded then prevent any more URB submissions, |
@@ -1213,6 +1237,7 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | |||
1213 | /** | 1237 | /** |
1214 | * usb_resume_both - resume a USB device and its interfaces | 1238 | * usb_resume_both - resume a USB device and its interfaces |
1215 | * @udev: the usb_device to resume | 1239 | * @udev: the usb_device to resume |
1240 | * @msg: Power Management message describing this state transition | ||
1216 | * | 1241 | * |
1217 | * This is the central routine for resuming USB devices. It calls the | 1242 | * This is the central routine for resuming USB devices. It calls the |
1218 | * the resume method for @udev and then calls the resume methods for all | 1243 | * the resume method for @udev and then calls the resume methods for all |
@@ -1238,7 +1263,7 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | |||
1238 | * | 1263 | * |
1239 | * This routine can run only in process context. | 1264 | * This routine can run only in process context. |
1240 | */ | 1265 | */ |
1241 | static int usb_resume_both(struct usb_device *udev) | 1266 | static int usb_resume_both(struct usb_device *udev, pm_message_t msg) |
1242 | { | 1267 | { |
1243 | int status = 0; | 1268 | int status = 0; |
1244 | int i; | 1269 | int i; |
@@ -1254,14 +1279,15 @@ static int usb_resume_both(struct usb_device *udev) | |||
1254 | 1279 | ||
1255 | /* Propagate the resume up the tree, if necessary */ | 1280 | /* Propagate the resume up the tree, if necessary */ |
1256 | if (udev->state == USB_STATE_SUSPENDED) { | 1281 | if (udev->state == USB_STATE_SUSPENDED) { |
1257 | if (udev->auto_pm && udev->autoresume_disabled) { | 1282 | if ((msg.event & PM_EVENT_AUTO) && |
1283 | udev->autoresume_disabled) { | ||
1258 | status = -EPERM; | 1284 | status = -EPERM; |
1259 | goto done; | 1285 | goto done; |
1260 | } | 1286 | } |
1261 | if (parent) { | 1287 | if (parent) { |
1262 | status = usb_autoresume_device(parent); | 1288 | status = usb_autoresume_device(parent); |
1263 | if (status == 0) { | 1289 | if (status == 0) { |
1264 | status = usb_resume_device(udev); | 1290 | status = usb_resume_device(udev, msg); |
1265 | if (status || udev->state == | 1291 | if (status || udev->state == |
1266 | USB_STATE_NOTATTACHED) { | 1292 | USB_STATE_NOTATTACHED) { |
1267 | usb_autosuspend_device(parent); | 1293 | usb_autosuspend_device(parent); |
@@ -1284,15 +1310,16 @@ static int usb_resume_both(struct usb_device *udev) | |||
1284 | /* We can't progagate beyond the USB subsystem, | 1310 | /* We can't progagate beyond the USB subsystem, |
1285 | * so if a root hub's controller is suspended | 1311 | * so if a root hub's controller is suspended |
1286 | * then we're stuck. */ | 1312 | * then we're stuck. */ |
1287 | status = usb_resume_device(udev); | 1313 | status = usb_resume_device(udev, msg); |
1288 | } | 1314 | } |
1289 | } else if (udev->reset_resume) | 1315 | } else if (udev->reset_resume) |
1290 | status = usb_resume_device(udev); | 1316 | status = usb_resume_device(udev, msg); |
1291 | 1317 | ||
1292 | if (status == 0 && udev->actconfig) { | 1318 | if (status == 0 && udev->actconfig) { |
1293 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { | 1319 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { |
1294 | intf = udev->actconfig->interface[i]; | 1320 | intf = udev->actconfig->interface[i]; |
1295 | usb_resume_interface(udev, intf, udev->reset_resume); | 1321 | usb_resume_interface(udev, intf, msg, |
1322 | udev->reset_resume); | ||
1296 | } | 1323 | } |
1297 | } | 1324 | } |
1298 | 1325 | ||
@@ -1320,13 +1347,13 @@ static int usb_autopm_do_device(struct usb_device *udev, int inc_usage_cnt) | |||
1320 | udev->last_busy = jiffies; | 1347 | udev->last_busy = jiffies; |
1321 | if (inc_usage_cnt >= 0 && udev->pm_usage_cnt > 0) { | 1348 | if (inc_usage_cnt >= 0 && udev->pm_usage_cnt > 0) { |
1322 | if (udev->state == USB_STATE_SUSPENDED) | 1349 | if (udev->state == USB_STATE_SUSPENDED) |
1323 | status = usb_resume_both(udev); | 1350 | status = usb_resume_both(udev, PMSG_AUTO_RESUME); |
1324 | if (status != 0) | 1351 | if (status != 0) |
1325 | udev->pm_usage_cnt -= inc_usage_cnt; | 1352 | udev->pm_usage_cnt -= inc_usage_cnt; |
1326 | else if (inc_usage_cnt) | 1353 | else if (inc_usage_cnt) |
1327 | udev->last_busy = jiffies; | 1354 | udev->last_busy = jiffies; |
1328 | } else if (inc_usage_cnt <= 0 && udev->pm_usage_cnt <= 0) { | 1355 | } else if (inc_usage_cnt <= 0 && udev->pm_usage_cnt <= 0) { |
1329 | status = usb_suspend_both(udev, PMSG_SUSPEND); | 1356 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); |
1330 | } | 1357 | } |
1331 | usb_pm_unlock(udev); | 1358 | usb_pm_unlock(udev); |
1332 | return status; | 1359 | return status; |
@@ -1341,6 +1368,19 @@ void usb_autosuspend_work(struct work_struct *work) | |||
1341 | usb_autopm_do_device(udev, 0); | 1368 | usb_autopm_do_device(udev, 0); |
1342 | } | 1369 | } |
1343 | 1370 | ||
1371 | /* usb_autoresume_work - callback routine to autoresume a USB device */ | ||
1372 | void usb_autoresume_work(struct work_struct *work) | ||
1373 | { | ||
1374 | struct usb_device *udev = | ||
1375 | container_of(work, struct usb_device, autoresume); | ||
1376 | |||
1377 | /* Wake it up, let the drivers do their thing, and then put it | ||
1378 | * back to sleep. | ||
1379 | */ | ||
1380 | if (usb_autopm_do_device(udev, 1) == 0) | ||
1381 | usb_autopm_do_device(udev, -1); | ||
1382 | } | ||
1383 | |||
1344 | /** | 1384 | /** |
1345 | * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces | 1385 | * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces |
1346 | * @udev: the usb_device to autosuspend | 1386 | * @udev: the usb_device to autosuspend |
@@ -1437,13 +1477,14 @@ static int usb_autopm_do_interface(struct usb_interface *intf, | |||
1437 | udev->last_busy = jiffies; | 1477 | udev->last_busy = jiffies; |
1438 | if (inc_usage_cnt >= 0 && intf->pm_usage_cnt > 0) { | 1478 | if (inc_usage_cnt >= 0 && intf->pm_usage_cnt > 0) { |
1439 | if (udev->state == USB_STATE_SUSPENDED) | 1479 | if (udev->state == USB_STATE_SUSPENDED) |
1440 | status = usb_resume_both(udev); | 1480 | status = usb_resume_both(udev, |
1481 | PMSG_AUTO_RESUME); | ||
1441 | if (status != 0) | 1482 | if (status != 0) |
1442 | intf->pm_usage_cnt -= inc_usage_cnt; | 1483 | intf->pm_usage_cnt -= inc_usage_cnt; |
1443 | else | 1484 | else |
1444 | udev->last_busy = jiffies; | 1485 | udev->last_busy = jiffies; |
1445 | } else if (inc_usage_cnt <= 0 && intf->pm_usage_cnt <= 0) { | 1486 | } else if (inc_usage_cnt <= 0 && intf->pm_usage_cnt <= 0) { |
1446 | status = usb_suspend_both(udev, PMSG_SUSPEND); | 1487 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); |
1447 | } | 1488 | } |
1448 | } | 1489 | } |
1449 | usb_pm_unlock(udev); | 1490 | usb_pm_unlock(udev); |
@@ -1492,6 +1533,45 @@ void usb_autopm_put_interface(struct usb_interface *intf) | |||
1492 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface); | 1533 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface); |
1493 | 1534 | ||
1494 | /** | 1535 | /** |
1536 | * usb_autopm_put_interface_async - decrement a USB interface's PM-usage counter | ||
1537 | * @intf: the usb_interface whose counter should be decremented | ||
1538 | * | ||
1539 | * This routine does essentially the same thing as | ||
1540 | * usb_autopm_put_interface(): it decrements @intf's usage counter and | ||
1541 | * queues a delayed autosuspend request if the counter is <= 0. The | ||
1542 | * difference is that it does not acquire the device's pm_mutex; | ||
1543 | * callers must handle all synchronization issues themselves. | ||
1544 | * | ||
1545 | * Typically a driver would call this routine during an URB's completion | ||
1546 | * handler, if no more URBs were pending. | ||
1547 | * | ||
1548 | * This routine can run in atomic context. | ||
1549 | */ | ||
1550 | void usb_autopm_put_interface_async(struct usb_interface *intf) | ||
1551 | { | ||
1552 | struct usb_device *udev = interface_to_usbdev(intf); | ||
1553 | int status = 0; | ||
1554 | |||
1555 | if (intf->condition == USB_INTERFACE_UNBOUND) { | ||
1556 | status = -ENODEV; | ||
1557 | } else { | ||
1558 | udev->last_busy = jiffies; | ||
1559 | --intf->pm_usage_cnt; | ||
1560 | if (udev->autosuspend_disabled || udev->autosuspend_delay < 0) | ||
1561 | status = -EPERM; | ||
1562 | else if (intf->pm_usage_cnt <= 0 && | ||
1563 | !timer_pending(&udev->autosuspend.timer)) { | ||
1564 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, | ||
1565 | round_jiffies_up_relative( | ||
1566 | udev->autosuspend_delay)); | ||
1567 | } | ||
1568 | } | ||
1569 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", | ||
1570 | __func__, status, intf->pm_usage_cnt); | ||
1571 | } | ||
1572 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async); | ||
1573 | |||
1574 | /** | ||
1495 | * usb_autopm_get_interface - increment a USB interface's PM-usage counter | 1575 | * usb_autopm_get_interface - increment a USB interface's PM-usage counter |
1496 | * @intf: the usb_interface whose counter should be incremented | 1576 | * @intf: the usb_interface whose counter should be incremented |
1497 | * | 1577 | * |
@@ -1537,6 +1617,37 @@ int usb_autopm_get_interface(struct usb_interface *intf) | |||
1537 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface); | 1617 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface); |
1538 | 1618 | ||
1539 | /** | 1619 | /** |
1620 | * usb_autopm_get_interface_async - increment a USB interface's PM-usage counter | ||
1621 | * @intf: the usb_interface whose counter should be incremented | ||
1622 | * | ||
1623 | * This routine does much the same thing as | ||
1624 | * usb_autopm_get_interface(): it increments @intf's usage counter and | ||
1625 | * queues an autoresume request if the result is > 0. The differences | ||
1626 | * are that it does not acquire the device's pm_mutex (callers must | ||
1627 | * handle all synchronization issues themselves), and it does not | ||
1628 | * autoresume the device directly (it only queues a request). After a | ||
1629 | * successful call, the device will generally not yet be resumed. | ||
1630 | * | ||
1631 | * This routine can run in atomic context. | ||
1632 | */ | ||
1633 | int usb_autopm_get_interface_async(struct usb_interface *intf) | ||
1634 | { | ||
1635 | struct usb_device *udev = interface_to_usbdev(intf); | ||
1636 | int status = 0; | ||
1637 | |||
1638 | if (intf->condition == USB_INTERFACE_UNBOUND) | ||
1639 | status = -ENODEV; | ||
1640 | else if (udev->autoresume_disabled) | ||
1641 | status = -EPERM; | ||
1642 | else if (++intf->pm_usage_cnt > 0 && udev->state == USB_STATE_SUSPENDED) | ||
1643 | queue_work(ksuspend_usb_wq, &udev->autoresume); | ||
1644 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", | ||
1645 | __func__, status, intf->pm_usage_cnt); | ||
1646 | return status; | ||
1647 | } | ||
1648 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface_async); | ||
1649 | |||
1650 | /** | ||
1540 | * usb_autopm_set_interface - set a USB interface's autosuspend state | 1651 | * usb_autopm_set_interface - set a USB interface's autosuspend state |
1541 | * @intf: the usb_interface whose state should be set | 1652 | * @intf: the usb_interface whose state should be set |
1542 | * | 1653 | * |
@@ -1563,6 +1674,9 @@ EXPORT_SYMBOL_GPL(usb_autopm_set_interface); | |||
1563 | void usb_autosuspend_work(struct work_struct *work) | 1674 | void usb_autosuspend_work(struct work_struct *work) |
1564 | {} | 1675 | {} |
1565 | 1676 | ||
1677 | void usb_autoresume_work(struct work_struct *work) | ||
1678 | {} | ||
1679 | |||
1566 | #endif /* CONFIG_USB_SUSPEND */ | 1680 | #endif /* CONFIG_USB_SUSPEND */ |
1567 | 1681 | ||
1568 | /** | 1682 | /** |
@@ -1595,6 +1709,7 @@ int usb_external_suspend_device(struct usb_device *udev, pm_message_t msg) | |||
1595 | /** | 1709 | /** |
1596 | * usb_external_resume_device - external resume of a USB device and its interfaces | 1710 | * usb_external_resume_device - external resume of a USB device and its interfaces |
1597 | * @udev: the usb_device to resume | 1711 | * @udev: the usb_device to resume |
1712 | * @msg: Power Management message describing this state transition | ||
1598 | * | 1713 | * |
1599 | * This routine handles external resume requests: ones not generated | 1714 | * This routine handles external resume requests: ones not generated |
1600 | * internally by a USB driver (autoresume) but rather coming from the user | 1715 | * internally by a USB driver (autoresume) but rather coming from the user |
@@ -1603,13 +1718,13 @@ int usb_external_suspend_device(struct usb_device *udev, pm_message_t msg) | |||
1603 | * | 1718 | * |
1604 | * The caller must hold @udev's device lock. | 1719 | * The caller must hold @udev's device lock. |
1605 | */ | 1720 | */ |
1606 | int usb_external_resume_device(struct usb_device *udev) | 1721 | int usb_external_resume_device(struct usb_device *udev, pm_message_t msg) |
1607 | { | 1722 | { |
1608 | int status; | 1723 | int status; |
1609 | 1724 | ||
1610 | usb_pm_lock(udev); | 1725 | usb_pm_lock(udev); |
1611 | udev->auto_pm = 0; | 1726 | udev->auto_pm = 0; |
1612 | status = usb_resume_both(udev); | 1727 | status = usb_resume_both(udev, msg); |
1613 | udev->last_busy = jiffies; | 1728 | udev->last_busy = jiffies; |
1614 | usb_pm_unlock(udev); | 1729 | usb_pm_unlock(udev); |
1615 | if (status == 0) | 1730 | if (status == 0) |
@@ -1622,7 +1737,7 @@ int usb_external_resume_device(struct usb_device *udev) | |||
1622 | return status; | 1737 | return status; |
1623 | } | 1738 | } |
1624 | 1739 | ||
1625 | int usb_suspend(struct device *dev, pm_message_t message) | 1740 | int usb_suspend(struct device *dev, pm_message_t msg) |
1626 | { | 1741 | { |
1627 | struct usb_device *udev; | 1742 | struct usb_device *udev; |
1628 | 1743 | ||
@@ -1641,10 +1756,10 @@ int usb_suspend(struct device *dev, pm_message_t message) | |||
1641 | } | 1756 | } |
1642 | 1757 | ||
1643 | udev->skip_sys_resume = 0; | 1758 | udev->skip_sys_resume = 0; |
1644 | return usb_external_suspend_device(udev, message); | 1759 | return usb_external_suspend_device(udev, msg); |
1645 | } | 1760 | } |
1646 | 1761 | ||
1647 | int usb_resume(struct device *dev) | 1762 | int usb_resume(struct device *dev, pm_message_t msg) |
1648 | { | 1763 | { |
1649 | struct usb_device *udev; | 1764 | struct usb_device *udev; |
1650 | 1765 | ||
@@ -1656,7 +1771,7 @@ int usb_resume(struct device *dev) | |||
1656 | */ | 1771 | */ |
1657 | if (udev->skip_sys_resume) | 1772 | if (udev->skip_sys_resume) |
1658 | return 0; | 1773 | return 0; |
1659 | return usb_external_resume_device(udev); | 1774 | return usb_external_resume_device(udev, msg); |
1660 | } | 1775 | } |
1661 | 1776 | ||
1662 | #endif /* CONFIG_PM */ | 1777 | #endif /* CONFIG_PM */ |
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c index 946fae43d622..e1710f260b4f 100644 --- a/drivers/usb/core/endpoint.c +++ b/drivers/usb/core/endpoint.c | |||
@@ -276,7 +276,7 @@ static void ep_device_release(struct device *dev) | |||
276 | kfree(ep_dev); | 276 | kfree(ep_dev); |
277 | } | 277 | } |
278 | 278 | ||
279 | int usb_create_ep_files(struct device *parent, | 279 | int usb_create_ep_devs(struct device *parent, |
280 | struct usb_host_endpoint *endpoint, | 280 | struct usb_host_endpoint *endpoint, |
281 | struct usb_device *udev) | 281 | struct usb_device *udev) |
282 | { | 282 | { |
@@ -340,7 +340,7 @@ exit: | |||
340 | return retval; | 340 | return retval; |
341 | } | 341 | } |
342 | 342 | ||
343 | void usb_remove_ep_files(struct usb_host_endpoint *endpoint) | 343 | void usb_remove_ep_devs(struct usb_host_endpoint *endpoint) |
344 | { | 344 | { |
345 | struct ep_device *ep_dev = endpoint->ep_dev; | 345 | struct ep_device *ep_dev = endpoint->ep_dev; |
346 | 346 | ||
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c index 7e912f21fd36..30ecac3af15a 100644 --- a/drivers/usb/core/generic.c +++ b/drivers/usb/core/generic.c | |||
@@ -200,18 +200,18 @@ static int generic_suspend(struct usb_device *udev, pm_message_t msg) | |||
200 | * interfaces manually by doing a bus (or "global") suspend. | 200 | * interfaces manually by doing a bus (or "global") suspend. |
201 | */ | 201 | */ |
202 | if (!udev->parent) | 202 | if (!udev->parent) |
203 | rc = hcd_bus_suspend(udev); | 203 | rc = hcd_bus_suspend(udev, msg); |
204 | 204 | ||
205 | /* Non-root devices don't need to do anything for FREEZE or PRETHAW */ | 205 | /* Non-root devices don't need to do anything for FREEZE or PRETHAW */ |
206 | else if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_PRETHAW) | 206 | else if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_PRETHAW) |
207 | rc = 0; | 207 | rc = 0; |
208 | else | 208 | else |
209 | rc = usb_port_suspend(udev); | 209 | rc = usb_port_suspend(udev, msg); |
210 | 210 | ||
211 | return rc; | 211 | return rc; |
212 | } | 212 | } |
213 | 213 | ||
214 | static int generic_resume(struct usb_device *udev) | 214 | static int generic_resume(struct usb_device *udev, pm_message_t msg) |
215 | { | 215 | { |
216 | int rc; | 216 | int rc; |
217 | 217 | ||
@@ -221,9 +221,9 @@ static int generic_resume(struct usb_device *udev) | |||
221 | * interfaces manually by doing a bus (or "global") resume. | 221 | * interfaces manually by doing a bus (or "global") resume. |
222 | */ | 222 | */ |
223 | if (!udev->parent) | 223 | if (!udev->parent) |
224 | rc = hcd_bus_resume(udev); | 224 | rc = hcd_bus_resume(udev, msg); |
225 | else | 225 | else |
226 | rc = usb_port_resume(udev); | 226 | rc = usb_port_resume(udev, msg); |
227 | return rc; | 227 | return rc; |
228 | } | 228 | } |
229 | 229 | ||
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index 5b87ae7f0a6a..507741ed4482 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c | |||
@@ -128,6 +128,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
128 | } | 128 | } |
129 | 129 | ||
130 | pci_set_master(dev); | 130 | pci_set_master(dev); |
131 | device_set_wakeup_enable(&dev->dev, 1); | ||
131 | 132 | ||
132 | retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); | 133 | retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); |
133 | if (retval != 0) | 134 | if (retval != 0) |
@@ -191,17 +192,15 @@ EXPORT_SYMBOL_GPL(usb_hcd_pci_remove); | |||
191 | /** | 192 | /** |
192 | * usb_hcd_pci_suspend - power management suspend of a PCI-based HCD | 193 | * usb_hcd_pci_suspend - power management suspend of a PCI-based HCD |
193 | * @dev: USB Host Controller being suspended | 194 | * @dev: USB Host Controller being suspended |
194 | * @message: semantics in flux | 195 | * @message: Power Management message describing this state transition |
195 | * | 196 | * |
196 | * Store this function in the HCD's struct pci_driver as suspend(). | 197 | * Store this function in the HCD's struct pci_driver as .suspend. |
197 | */ | 198 | */ |
198 | int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message) | 199 | int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message) |
199 | { | 200 | { |
200 | struct usb_hcd *hcd; | 201 | struct usb_hcd *hcd = pci_get_drvdata(dev); |
201 | int retval = 0; | 202 | int retval = 0; |
202 | int has_pci_pm; | 203 | int wake, w; |
203 | |||
204 | hcd = pci_get_drvdata(dev); | ||
205 | 204 | ||
206 | /* Root hub suspend should have stopped all downstream traffic, | 205 | /* Root hub suspend should have stopped all downstream traffic, |
207 | * and all bus master traffic. And done so for both the interface | 206 | * and all bus master traffic. And done so for both the interface |
@@ -212,8 +211,15 @@ int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message) | |||
212 | * otherwise the swsusp will save (and restore) garbage state. | 211 | * otherwise the swsusp will save (and restore) garbage state. |
213 | */ | 212 | */ |
214 | if (!(hcd->state == HC_STATE_SUSPENDED || | 213 | if (!(hcd->state == HC_STATE_SUSPENDED || |
215 | hcd->state == HC_STATE_HALT)) | 214 | hcd->state == HC_STATE_HALT)) { |
216 | return -EBUSY; | 215 | dev_warn(&dev->dev, "Root hub is not suspended\n"); |
216 | retval = -EBUSY; | ||
217 | goto done; | ||
218 | } | ||
219 | |||
220 | /* We might already be suspended (runtime PM -- not yet written) */ | ||
221 | if (dev->current_state != PCI_D0) | ||
222 | goto done; | ||
217 | 223 | ||
218 | if (hcd->driver->pci_suspend) { | 224 | if (hcd->driver->pci_suspend) { |
219 | retval = hcd->driver->pci_suspend(hcd, message); | 225 | retval = hcd->driver->pci_suspend(hcd, message); |
@@ -221,49 +227,60 @@ int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message) | |||
221 | if (retval) | 227 | if (retval) |
222 | goto done; | 228 | goto done; |
223 | } | 229 | } |
224 | synchronize_irq(dev->irq); | ||
225 | 230 | ||
226 | /* FIXME until the generic PM interfaces change a lot more, this | 231 | synchronize_irq(dev->irq); |
227 | * can't use PCI D1 and D2 states. For example, the confusion | ||
228 | * between messages and states will need to vanish, and messages | ||
229 | * will need to provide a target system state again. | ||
230 | * | ||
231 | * It'll be important to learn characteristics of the target state, | ||
232 | * especially on embedded hardware where the HCD will often be in | ||
233 | * charge of an external VBUS power supply and one or more clocks. | ||
234 | * Some target system states will leave them active; others won't. | ||
235 | * (With PCI, that's often handled by platform BIOS code.) | ||
236 | */ | ||
237 | 232 | ||
238 | /* even when the PCI layer rejects some of the PCI calls | 233 | /* Don't fail on error to enable wakeup. We rely on pci code |
239 | * below, HCs can try global suspend and reduce DMA traffic. | 234 | * to reject requests the hardware can't implement, rather |
240 | * PM-sensitive HCDs may already have done this. | 235 | * than coding the same thing. |
241 | */ | 236 | */ |
242 | has_pci_pm = pci_find_capability(dev, PCI_CAP_ID_PM); | 237 | wake = (hcd->state == HC_STATE_SUSPENDED && |
238 | device_may_wakeup(&dev->dev)); | ||
239 | w = pci_wake_from_d3(dev, wake); | ||
240 | if (w < 0) | ||
241 | wake = w; | ||
242 | dev_dbg(&dev->dev, "wakeup: %d\n", wake); | ||
243 | 243 | ||
244 | /* Downstream ports from this root hub should already be quiesced, so | 244 | /* Downstream ports from this root hub should already be quiesced, so |
245 | * there will be no DMA activity. Now we can shut down the upstream | 245 | * there will be no DMA activity. Now we can shut down the upstream |
246 | * link (except maybe for PME# resume signaling) and enter some PCI | 246 | * link (except maybe for PME# resume signaling) and enter some PCI |
247 | * low power state, if the hardware allows. | 247 | * low power state, if the hardware allows. |
248 | */ | 248 | */ |
249 | if (hcd->state == HC_STATE_SUSPENDED) { | 249 | pci_disable_device(dev); |
250 | done: | ||
251 | return retval; | ||
252 | } | ||
253 | EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend); | ||
250 | 254 | ||
251 | /* no DMA or IRQs except when HC is active */ | 255 | /** |
252 | if (dev->current_state == PCI_D0) { | 256 | * usb_hcd_pci_suspend_late - suspend a PCI-based HCD after IRQs are disabled |
253 | pci_save_state(dev); | 257 | * @dev: USB Host Controller being suspended |
254 | pci_disable_device(dev); | 258 | * @message: Power Management message describing this state transition |
255 | } | 259 | * |
260 | * Store this function in the HCD's struct pci_driver as .suspend_late. | ||
261 | */ | ||
262 | int usb_hcd_pci_suspend_late(struct pci_dev *dev, pm_message_t message) | ||
263 | { | ||
264 | int retval = 0; | ||
265 | int has_pci_pm; | ||
256 | 266 | ||
257 | if (message.event == PM_EVENT_FREEZE || | 267 | /* We might already be suspended (runtime PM -- not yet written) */ |
258 | message.event == PM_EVENT_PRETHAW) { | 268 | if (dev->current_state != PCI_D0) |
259 | dev_dbg(hcd->self.controller, "--> no state change\n"); | 269 | goto done; |
260 | goto done; | ||
261 | } | ||
262 | 270 | ||
263 | if (!has_pci_pm) { | 271 | pci_save_state(dev); |
264 | dev_dbg(hcd->self.controller, "--> PCI D0/legacy\n"); | 272 | |
265 | goto done; | 273 | /* Don't change state if we don't need to */ |
266 | } | 274 | if (message.event == PM_EVENT_FREEZE || |
275 | message.event == PM_EVENT_PRETHAW) { | ||
276 | dev_dbg(&dev->dev, "--> no state change\n"); | ||
277 | goto done; | ||
278 | } | ||
279 | |||
280 | has_pci_pm = pci_find_capability(dev, PCI_CAP_ID_PM); | ||
281 | if (!has_pci_pm) { | ||
282 | dev_dbg(&dev->dev, "--> PCI D0 legacy\n"); | ||
283 | } else { | ||
267 | 284 | ||
268 | /* NOTE: dev->current_state becomes nonzero only here, and | 285 | /* NOTE: dev->current_state becomes nonzero only here, and |
269 | * only for devices that support PCI PM. Also, exiting | 286 | * only for devices that support PCI PM. Also, exiting |
@@ -273,35 +290,16 @@ int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message) | |||
273 | retval = pci_set_power_state(dev, PCI_D3hot); | 290 | retval = pci_set_power_state(dev, PCI_D3hot); |
274 | suspend_report_result(pci_set_power_state, retval); | 291 | suspend_report_result(pci_set_power_state, retval); |
275 | if (retval == 0) { | 292 | if (retval == 0) { |
276 | int wake = device_can_wakeup(&hcd->self.root_hub->dev); | 293 | dev_dbg(&dev->dev, "--> PCI D3\n"); |
277 | |||
278 | wake = wake && device_may_wakeup(hcd->self.controller); | ||
279 | |||
280 | dev_dbg(hcd->self.controller, "--> PCI D3%s\n", | ||
281 | wake ? "/wakeup" : ""); | ||
282 | |||
283 | /* Ignore these return values. We rely on pci code to | ||
284 | * reject requests the hardware can't implement, rather | ||
285 | * than coding the same thing. | ||
286 | */ | ||
287 | (void) pci_enable_wake(dev, PCI_D3hot, wake); | ||
288 | (void) pci_enable_wake(dev, PCI_D3cold, wake); | ||
289 | } else { | 294 | } else { |
290 | dev_dbg(&dev->dev, "PCI D3 suspend fail, %d\n", | 295 | dev_dbg(&dev->dev, "PCI D3 suspend fail, %d\n", |
291 | retval); | 296 | retval); |
292 | (void) usb_hcd_pci_resume(dev); | 297 | pci_restore_state(dev); |
293 | } | 298 | } |
294 | |||
295 | } else if (hcd->state != HC_STATE_HALT) { | ||
296 | dev_dbg(hcd->self.controller, "hcd state %d; not suspended\n", | ||
297 | hcd->state); | ||
298 | WARN_ON(1); | ||
299 | retval = -EINVAL; | ||
300 | } | 299 | } |
301 | 300 | ||
302 | done: | ||
303 | if (retval == 0) { | ||
304 | #ifdef CONFIG_PPC_PMAC | 301 | #ifdef CONFIG_PPC_PMAC |
302 | if (retval == 0) { | ||
305 | /* Disable ASIC clocks for USB */ | 303 | /* Disable ASIC clocks for USB */ |
306 | if (machine_is(powermac)) { | 304 | if (machine_is(powermac)) { |
307 | struct device_node *of_node; | 305 | struct device_node *of_node; |
@@ -311,30 +309,24 @@ done: | |||
311 | pmac_call_feature(PMAC_FTR_USB_ENABLE, | 309 | pmac_call_feature(PMAC_FTR_USB_ENABLE, |
312 | of_node, 0, 0); | 310 | of_node, 0, 0); |
313 | } | 311 | } |
314 | #endif | ||
315 | } | 312 | } |
313 | #endif | ||
316 | 314 | ||
315 | done: | ||
317 | return retval; | 316 | return retval; |
318 | } | 317 | } |
319 | EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend); | 318 | EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend_late); |
320 | 319 | ||
321 | /** | 320 | /** |
322 | * usb_hcd_pci_resume - power management resume of a PCI-based HCD | 321 | * usb_hcd_pci_resume_early - resume a PCI-based HCD before IRQs are enabled |
323 | * @dev: USB Host Controller being resumed | 322 | * @dev: USB Host Controller being resumed |
324 | * | 323 | * |
325 | * Store this function in the HCD's struct pci_driver as resume(). | 324 | * Store this function in the HCD's struct pci_driver as .resume_early. |
326 | */ | 325 | */ |
327 | int usb_hcd_pci_resume(struct pci_dev *dev) | 326 | int usb_hcd_pci_resume_early(struct pci_dev *dev) |
328 | { | 327 | { |
329 | struct usb_hcd *hcd; | 328 | int retval = 0; |
330 | int retval; | 329 | pci_power_t state = dev->current_state; |
331 | |||
332 | hcd = pci_get_drvdata(dev); | ||
333 | if (hcd->state != HC_STATE_SUSPENDED) { | ||
334 | dev_dbg(hcd->self.controller, | ||
335 | "can't resume, not suspended!\n"); | ||
336 | return 0; | ||
337 | } | ||
338 | 330 | ||
339 | #ifdef CONFIG_PPC_PMAC | 331 | #ifdef CONFIG_PPC_PMAC |
340 | /* Reenable ASIC clocks for USB */ | 332 | /* Reenable ASIC clocks for USB */ |
@@ -352,7 +344,7 @@ int usb_hcd_pci_resume(struct pci_dev *dev) | |||
352 | * calls "standby", "suspend to RAM", and so on). There are also | 344 | * calls "standby", "suspend to RAM", and so on). There are also |
353 | * dirty cases when swsusp fakes a suspend in "shutdown" mode. | 345 | * dirty cases when swsusp fakes a suspend in "shutdown" mode. |
354 | */ | 346 | */ |
355 | if (dev->current_state != PCI_D0) { | 347 | if (state != PCI_D0) { |
356 | #ifdef DEBUG | 348 | #ifdef DEBUG |
357 | int pci_pm; | 349 | int pci_pm; |
358 | u16 pmcr; | 350 | u16 pmcr; |
@@ -364,8 +356,7 @@ int usb_hcd_pci_resume(struct pci_dev *dev) | |||
364 | /* Clean case: power to USB and to HC registers was | 356 | /* Clean case: power to USB and to HC registers was |
365 | * maintained; remote wakeup is easy. | 357 | * maintained; remote wakeup is easy. |
366 | */ | 358 | */ |
367 | dev_dbg(hcd->self.controller, "resume from PCI D%d\n", | 359 | dev_dbg(&dev->dev, "resume from PCI D%d\n", pmcr); |
368 | pmcr); | ||
369 | } else { | 360 | } else { |
370 | /* Clean: HC lost Vcc power, D0 uninitialized | 361 | /* Clean: HC lost Vcc power, D0 uninitialized |
371 | * + Vaux may have preserved port and transceiver | 362 | * + Vaux may have preserved port and transceiver |
@@ -376,32 +367,55 @@ int usb_hcd_pci_resume(struct pci_dev *dev) | |||
376 | * + after BIOS init | 367 | * + after BIOS init |
377 | * + after Linux init (HCD statically linked) | 368 | * + after Linux init (HCD statically linked) |
378 | */ | 369 | */ |
379 | dev_dbg(hcd->self.controller, | 370 | dev_dbg(&dev->dev, "resume from previous PCI D%d\n", |
380 | "PCI D0, from previous PCI D%d\n", | 371 | state); |
381 | dev->current_state); | ||
382 | } | 372 | } |
383 | #endif | 373 | #endif |
384 | /* yes, ignore these results too... */ | 374 | |
385 | (void) pci_enable_wake(dev, dev->current_state, 0); | 375 | retval = pci_set_power_state(dev, PCI_D0); |
386 | (void) pci_enable_wake(dev, PCI_D3cold, 0); | ||
387 | } else { | 376 | } else { |
388 | /* Same basic cases: clean (powered/not), dirty */ | 377 | /* Same basic cases: clean (powered/not), dirty */ |
389 | dev_dbg(hcd->self.controller, "PCI legacy resume\n"); | 378 | dev_dbg(&dev->dev, "PCI legacy resume\n"); |
379 | } | ||
380 | |||
381 | if (retval < 0) | ||
382 | dev_err(&dev->dev, "can't resume: %d\n", retval); | ||
383 | else | ||
384 | pci_restore_state(dev); | ||
385 | |||
386 | return retval; | ||
387 | } | ||
388 | EXPORT_SYMBOL_GPL(usb_hcd_pci_resume_early); | ||
389 | |||
390 | /** | ||
391 | * usb_hcd_pci_resume - power management resume of a PCI-based HCD | ||
392 | * @dev: USB Host Controller being resumed | ||
393 | * | ||
394 | * Store this function in the HCD's struct pci_driver as .resume. | ||
395 | */ | ||
396 | int usb_hcd_pci_resume(struct pci_dev *dev) | ||
397 | { | ||
398 | struct usb_hcd *hcd; | ||
399 | int retval; | ||
400 | |||
401 | hcd = pci_get_drvdata(dev); | ||
402 | if (hcd->state != HC_STATE_SUSPENDED) { | ||
403 | dev_dbg(hcd->self.controller, | ||
404 | "can't resume, not suspended!\n"); | ||
405 | return 0; | ||
390 | } | 406 | } |
391 | 407 | ||
392 | /* NOTE: the PCI API itself is asymmetric here. We don't need to | ||
393 | * pci_set_power_state(PCI_D0) since that's part of re-enabling; | ||
394 | * but that won't re-enable bus mastering. Yet pci_disable_device() | ||
395 | * explicitly disables bus mastering... | ||
396 | */ | ||
397 | retval = pci_enable_device(dev); | 408 | retval = pci_enable_device(dev); |
398 | if (retval < 0) { | 409 | if (retval < 0) { |
399 | dev_err(hcd->self.controller, | 410 | dev_err(&dev->dev, "can't re-enable after resume, %d!\n", |
400 | "can't re-enable after resume, %d!\n", retval); | 411 | retval); |
401 | return retval; | 412 | return retval; |
402 | } | 413 | } |
414 | |||
403 | pci_set_master(dev); | 415 | pci_set_master(dev); |
404 | pci_restore_state(dev); | 416 | |
417 | /* yes, ignore this result too... */ | ||
418 | (void) pci_wake_from_d3(dev, 0); | ||
405 | 419 | ||
406 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 420 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
407 | 421 | ||
@@ -413,7 +427,6 @@ int usb_hcd_pci_resume(struct pci_dev *dev) | |||
413 | usb_hc_died(hcd); | 427 | usb_hc_died(hcd); |
414 | } | 428 | } |
415 | } | 429 | } |
416 | |||
417 | return retval; | 430 | return retval; |
418 | } | 431 | } |
419 | EXPORT_SYMBOL_GPL(usb_hcd_pci_resume); | 432 | EXPORT_SYMBOL_GPL(usb_hcd_pci_resume); |
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index e1b42626d04d..3c711db55d86 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -1010,7 +1010,7 @@ int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb) | |||
1010 | spin_lock(&hcd_urb_list_lock); | 1010 | spin_lock(&hcd_urb_list_lock); |
1011 | 1011 | ||
1012 | /* Check that the URB isn't being killed */ | 1012 | /* Check that the URB isn't being killed */ |
1013 | if (unlikely(urb->reject)) { | 1013 | if (unlikely(atomic_read(&urb->reject))) { |
1014 | rc = -EPERM; | 1014 | rc = -EPERM; |
1015 | goto done; | 1015 | goto done; |
1016 | } | 1016 | } |
@@ -1340,7 +1340,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) | |||
1340 | INIT_LIST_HEAD(&urb->urb_list); | 1340 | INIT_LIST_HEAD(&urb->urb_list); |
1341 | atomic_dec(&urb->use_count); | 1341 | atomic_dec(&urb->use_count); |
1342 | atomic_dec(&urb->dev->urbnum); | 1342 | atomic_dec(&urb->dev->urbnum); |
1343 | if (urb->reject) | 1343 | if (atomic_read(&urb->reject)) |
1344 | wake_up(&usb_kill_urb_queue); | 1344 | wake_up(&usb_kill_urb_queue); |
1345 | usb_put_urb(urb); | 1345 | usb_put_urb(urb); |
1346 | } | 1346 | } |
@@ -1444,7 +1444,7 @@ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status) | |||
1444 | urb->status = status; | 1444 | urb->status = status; |
1445 | urb->complete (urb); | 1445 | urb->complete (urb); |
1446 | atomic_dec (&urb->use_count); | 1446 | atomic_dec (&urb->use_count); |
1447 | if (unlikely (urb->reject)) | 1447 | if (unlikely(atomic_read(&urb->reject))) |
1448 | wake_up (&usb_kill_urb_queue); | 1448 | wake_up (&usb_kill_urb_queue); |
1449 | usb_put_urb (urb); | 1449 | usb_put_urb (urb); |
1450 | } | 1450 | } |
@@ -1573,14 +1573,14 @@ int usb_hcd_get_frame_number (struct usb_device *udev) | |||
1573 | 1573 | ||
1574 | #ifdef CONFIG_PM | 1574 | #ifdef CONFIG_PM |
1575 | 1575 | ||
1576 | int hcd_bus_suspend(struct usb_device *rhdev) | 1576 | int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg) |
1577 | { | 1577 | { |
1578 | struct usb_hcd *hcd = container_of(rhdev->bus, struct usb_hcd, self); | 1578 | struct usb_hcd *hcd = container_of(rhdev->bus, struct usb_hcd, self); |
1579 | int status; | 1579 | int status; |
1580 | int old_state = hcd->state; | 1580 | int old_state = hcd->state; |
1581 | 1581 | ||
1582 | dev_dbg(&rhdev->dev, "bus %s%s\n", | 1582 | dev_dbg(&rhdev->dev, "bus %s%s\n", |
1583 | rhdev->auto_pm ? "auto-" : "", "suspend"); | 1583 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend"); |
1584 | if (!hcd->driver->bus_suspend) { | 1584 | if (!hcd->driver->bus_suspend) { |
1585 | status = -ENOENT; | 1585 | status = -ENOENT; |
1586 | } else { | 1586 | } else { |
@@ -1598,14 +1598,14 @@ int hcd_bus_suspend(struct usb_device *rhdev) | |||
1598 | return status; | 1598 | return status; |
1599 | } | 1599 | } |
1600 | 1600 | ||
1601 | int hcd_bus_resume(struct usb_device *rhdev) | 1601 | int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) |
1602 | { | 1602 | { |
1603 | struct usb_hcd *hcd = container_of(rhdev->bus, struct usb_hcd, self); | 1603 | struct usb_hcd *hcd = container_of(rhdev->bus, struct usb_hcd, self); |
1604 | int status; | 1604 | int status; |
1605 | int old_state = hcd->state; | 1605 | int old_state = hcd->state; |
1606 | 1606 | ||
1607 | dev_dbg(&rhdev->dev, "usb %s%s\n", | 1607 | dev_dbg(&rhdev->dev, "usb %s%s\n", |
1608 | rhdev->auto_pm ? "auto-" : "", "resume"); | 1608 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume"); |
1609 | if (!hcd->driver->bus_resume) | 1609 | if (!hcd->driver->bus_resume) |
1610 | return -ENOENT; | 1610 | return -ENOENT; |
1611 | if (hcd->state == HC_STATE_RUNNING) | 1611 | if (hcd->state == HC_STATE_RUNNING) |
@@ -1638,7 +1638,7 @@ static void hcd_resume_work(struct work_struct *work) | |||
1638 | 1638 | ||
1639 | usb_lock_device(udev); | 1639 | usb_lock_device(udev); |
1640 | usb_mark_last_busy(udev); | 1640 | usb_mark_last_busy(udev); |
1641 | usb_external_resume_device(udev); | 1641 | usb_external_resume_device(udev, PMSG_REMOTE_RESUME); |
1642 | usb_unlock_device(udev); | 1642 | usb_unlock_device(udev); |
1643 | } | 1643 | } |
1644 | 1644 | ||
@@ -2028,7 +2028,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown); | |||
2028 | 2028 | ||
2029 | /*-------------------------------------------------------------------------*/ | 2029 | /*-------------------------------------------------------------------------*/ |
2030 | 2030 | ||
2031 | #if defined(CONFIG_USB_MON) | 2031 | #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE) |
2032 | 2032 | ||
2033 | struct usb_mon_operations *mon_ops; | 2033 | struct usb_mon_operations *mon_ops; |
2034 | 2034 | ||
@@ -2064,4 +2064,4 @@ void usb_mon_deregister (void) | |||
2064 | } | 2064 | } |
2065 | EXPORT_SYMBOL_GPL (usb_mon_deregister); | 2065 | EXPORT_SYMBOL_GPL (usb_mon_deregister); |
2066 | 2066 | ||
2067 | #endif /* CONFIG_USB_MON */ | 2067 | #endif /* CONFIG_USB_MON || CONFIG_USB_MON_MODULE */ |
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h index 9465e70f4dd0..572d2cf46e8d 100644 --- a/drivers/usb/core/hcd.h +++ b/drivers/usb/core/hcd.h | |||
@@ -16,6 +16,8 @@ | |||
16 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #ifndef __USB_CORE_HCD_H | ||
20 | #define __USB_CORE_HCD_H | ||
19 | 21 | ||
20 | #ifdef __KERNEL__ | 22 | #ifdef __KERNEL__ |
21 | 23 | ||
@@ -254,7 +256,9 @@ extern int usb_hcd_pci_probe(struct pci_dev *dev, | |||
254 | extern void usb_hcd_pci_remove(struct pci_dev *dev); | 256 | extern void usb_hcd_pci_remove(struct pci_dev *dev); |
255 | 257 | ||
256 | #ifdef CONFIG_PM | 258 | #ifdef CONFIG_PM |
257 | extern int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t state); | 259 | extern int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t msg); |
260 | extern int usb_hcd_pci_suspend_late(struct pci_dev *dev, pm_message_t msg); | ||
261 | extern int usb_hcd_pci_resume_early(struct pci_dev *dev); | ||
258 | extern int usb_hcd_pci_resume(struct pci_dev *dev); | 262 | extern int usb_hcd_pci_resume(struct pci_dev *dev); |
259 | #endif /* CONFIG_PM */ | 263 | #endif /* CONFIG_PM */ |
260 | 264 | ||
@@ -386,8 +390,8 @@ extern int usb_find_interface_driver(struct usb_device *dev, | |||
386 | #ifdef CONFIG_PM | 390 | #ifdef CONFIG_PM |
387 | extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd); | 391 | extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd); |
388 | extern void usb_root_hub_lost_power(struct usb_device *rhdev); | 392 | extern void usb_root_hub_lost_power(struct usb_device *rhdev); |
389 | extern int hcd_bus_suspend(struct usb_device *rhdev); | 393 | extern int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg); |
390 | extern int hcd_bus_resume(struct usb_device *rhdev); | 394 | extern int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg); |
391 | #else | 395 | #else |
392 | static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) | 396 | static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) |
393 | { | 397 | { |
@@ -419,7 +423,7 @@ static inline void usbfs_cleanup(void) { } | |||
419 | 423 | ||
420 | /*-------------------------------------------------------------------------*/ | 424 | /*-------------------------------------------------------------------------*/ |
421 | 425 | ||
422 | #if defined(CONFIG_USB_MON) | 426 | #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE) |
423 | 427 | ||
424 | struct usb_mon_operations { | 428 | struct usb_mon_operations { |
425 | void (*urb_submit)(struct usb_bus *bus, struct urb *urb); | 429 | void (*urb_submit)(struct usb_bus *bus, struct urb *urb); |
@@ -461,7 +465,7 @@ static inline void usbmon_urb_submit_error(struct usb_bus *bus, struct urb *urb, | |||
461 | static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb, | 465 | static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb, |
462 | int status) {} | 466 | int status) {} |
463 | 467 | ||
464 | #endif /* CONFIG_USB_MON */ | 468 | #endif /* CONFIG_USB_MON || CONFIG_USB_MON_MODULE */ |
465 | 469 | ||
466 | /*-------------------------------------------------------------------------*/ | 470 | /*-------------------------------------------------------------------------*/ |
467 | 471 | ||
@@ -490,3 +494,5 @@ extern struct rw_semaphore ehci_cf_port_reset_rwsem; | |||
490 | extern unsigned long usb_hcds_loaded; | 494 | extern unsigned long usb_hcds_loaded; |
491 | 495 | ||
492 | #endif /* __KERNEL__ */ | 496 | #endif /* __KERNEL__ */ |
497 | |||
498 | #endif /* __USB_CORE_HCD_H */ | ||
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index b19cbfcd51da..94d5ee263c20 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -107,7 +107,9 @@ MODULE_PARM_DESC (blinkenlights, "true to cycle leds on hubs"); | |||
107 | /* define initial 64-byte descriptor request timeout in milliseconds */ | 107 | /* define initial 64-byte descriptor request timeout in milliseconds */ |
108 | static int initial_descriptor_timeout = USB_CTRL_GET_TIMEOUT; | 108 | static int initial_descriptor_timeout = USB_CTRL_GET_TIMEOUT; |
109 | module_param(initial_descriptor_timeout, int, S_IRUGO|S_IWUSR); | 109 | module_param(initial_descriptor_timeout, int, S_IRUGO|S_IWUSR); |
110 | MODULE_PARM_DESC(initial_descriptor_timeout, "initial 64-byte descriptor request timeout in milliseconds (default 5000 - 5.0 seconds)"); | 110 | MODULE_PARM_DESC(initial_descriptor_timeout, |
111 | "initial 64-byte descriptor request timeout in milliseconds " | ||
112 | "(default 5000 - 5.0 seconds)"); | ||
111 | 113 | ||
112 | /* | 114 | /* |
113 | * As of 2.6.10 we introduce a new USB device initialization scheme which | 115 | * As of 2.6.10 we introduce a new USB device initialization scheme which |
@@ -1136,8 +1138,8 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id) | |||
1136 | hdev = interface_to_usbdev(intf); | 1138 | hdev = interface_to_usbdev(intf); |
1137 | 1139 | ||
1138 | if (hdev->level == MAX_TOPO_LEVEL) { | 1140 | if (hdev->level == MAX_TOPO_LEVEL) { |
1139 | dev_err(&intf->dev, "Unsupported bus topology: " | 1141 | dev_err(&intf->dev, |
1140 | "hub nested too deep\n"); | 1142 | "Unsupported bus topology: hub nested too deep\n"); |
1141 | return -E2BIG; | 1143 | return -E2BIG; |
1142 | } | 1144 | } |
1143 | 1145 | ||
@@ -1374,8 +1376,9 @@ static void usb_stop_pm(struct usb_device *udev) | |||
1374 | usb_autosuspend_device(udev->parent); | 1376 | usb_autosuspend_device(udev->parent); |
1375 | usb_pm_unlock(udev); | 1377 | usb_pm_unlock(udev); |
1376 | 1378 | ||
1377 | /* Stop any autosuspend requests already submitted */ | 1379 | /* Stop any autosuspend or autoresume requests already submitted */ |
1378 | cancel_rearming_delayed_work(&udev->autosuspend); | 1380 | cancel_delayed_work_sync(&udev->autosuspend); |
1381 | cancel_work_sync(&udev->autoresume); | ||
1379 | } | 1382 | } |
1380 | 1383 | ||
1381 | #else | 1384 | #else |
@@ -1434,17 +1437,12 @@ void usb_disconnect(struct usb_device **pdev) | |||
1434 | usb_disable_device(udev, 0); | 1437 | usb_disable_device(udev, 0); |
1435 | usb_hcd_synchronize_unlinks(udev); | 1438 | usb_hcd_synchronize_unlinks(udev); |
1436 | 1439 | ||
1440 | usb_remove_ep_devs(&udev->ep0); | ||
1437 | usb_unlock_device(udev); | 1441 | usb_unlock_device(udev); |
1438 | 1442 | ||
1439 | /* Remove the device-specific files from sysfs. This must be | ||
1440 | * done with udev unlocked, because some of the attribute | ||
1441 | * routines try to acquire the device lock. | ||
1442 | */ | ||
1443 | usb_remove_sysfs_dev_files(udev); | ||
1444 | |||
1445 | /* Unregister the device. The device driver is responsible | 1443 | /* Unregister the device. The device driver is responsible |
1446 | * for removing the device files from usbfs and sysfs and for | 1444 | * for de-configuring the device and invoking the remove-device |
1447 | * de-configuring the device. | 1445 | * notifier chain (used by usbfs and possibly others). |
1448 | */ | 1446 | */ |
1449 | device_del(&udev->dev); | 1447 | device_del(&udev->dev); |
1450 | 1448 | ||
@@ -1476,8 +1474,8 @@ static void announce_device(struct usb_device *udev) | |||
1476 | dev_info(&udev->dev, "New USB device found, idVendor=%04x, idProduct=%04x\n", | 1474 | dev_info(&udev->dev, "New USB device found, idVendor=%04x, idProduct=%04x\n", |
1477 | le16_to_cpu(udev->descriptor.idVendor), | 1475 | le16_to_cpu(udev->descriptor.idVendor), |
1478 | le16_to_cpu(udev->descriptor.idProduct)); | 1476 | le16_to_cpu(udev->descriptor.idProduct)); |
1479 | dev_info(&udev->dev, "New USB device strings: Mfr=%d, Product=%d, " | 1477 | dev_info(&udev->dev, |
1480 | "SerialNumber=%d\n", | 1478 | "New USB device strings: Mfr=%d, Product=%d, SerialNumber=%d\n", |
1481 | udev->descriptor.iManufacturer, | 1479 | udev->descriptor.iManufacturer, |
1482 | udev->descriptor.iProduct, | 1480 | udev->descriptor.iProduct, |
1483 | udev->descriptor.iSerialNumber); | 1481 | udev->descriptor.iSerialNumber); |
@@ -1542,7 +1540,7 @@ static int usb_configure_device_otg(struct usb_device *udev) | |||
1542 | * customize to match your product. | 1540 | * customize to match your product. |
1543 | */ | 1541 | */ |
1544 | dev_info(&udev->dev, | 1542 | dev_info(&udev->dev, |
1545 | "can't set HNP mode; %d\n", | 1543 | "can't set HNP mode: %d\n", |
1546 | err); | 1544 | err); |
1547 | bus->b_hnp_enable = 0; | 1545 | bus->b_hnp_enable = 0; |
1548 | } | 1546 | } |
@@ -1556,7 +1554,7 @@ static int usb_configure_device_otg(struct usb_device *udev) | |||
1556 | * (Includes HNP test device.) | 1554 | * (Includes HNP test device.) |
1557 | */ | 1555 | */ |
1558 | if (udev->bus->b_hnp_enable || udev->bus->is_b_host) { | 1556 | if (udev->bus->b_hnp_enable || udev->bus->is_b_host) { |
1559 | err = usb_port_suspend(udev); | 1557 | err = usb_port_suspend(udev, PMSG_SUSPEND); |
1560 | if (err < 0) | 1558 | if (err < 0) |
1561 | dev_dbg(&udev->dev, "HNP fail, %d\n", err); | 1559 | dev_dbg(&udev->dev, "HNP fail, %d\n", err); |
1562 | } | 1560 | } |
@@ -1635,6 +1633,10 @@ int usb_new_device(struct usb_device *udev) | |||
1635 | { | 1633 | { |
1636 | int err; | 1634 | int err; |
1637 | 1635 | ||
1636 | /* Increment the parent's count of unsuspended children */ | ||
1637 | if (udev->parent) | ||
1638 | usb_autoresume_device(udev->parent); | ||
1639 | |||
1638 | usb_detect_quirks(udev); /* Determine quirks */ | 1640 | usb_detect_quirks(udev); /* Determine quirks */ |
1639 | err = usb_configure_device(udev); /* detect & probe dev/intfs */ | 1641 | err = usb_configure_device(udev); /* detect & probe dev/intfs */ |
1640 | if (err < 0) | 1642 | if (err < 0) |
@@ -1643,13 +1645,12 @@ int usb_new_device(struct usb_device *udev) | |||
1643 | udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, | 1645 | udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, |
1644 | (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); | 1646 | (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); |
1645 | 1647 | ||
1646 | /* Increment the parent's count of unsuspended children */ | 1648 | /* Tell the world! */ |
1647 | if (udev->parent) | 1649 | announce_device(udev); |
1648 | usb_autoresume_device(udev->parent); | ||
1649 | 1650 | ||
1650 | /* Register the device. The device driver is responsible | 1651 | /* Register the device. The device driver is responsible |
1651 | * for adding the device files to sysfs and for configuring | 1652 | * for configuring the device and invoking the add-device |
1652 | * the device. | 1653 | * notifier chain (used by usbfs and possibly others). |
1653 | */ | 1654 | */ |
1654 | err = device_add(&udev->dev); | 1655 | err = device_add(&udev->dev); |
1655 | if (err) { | 1656 | if (err) { |
@@ -1657,15 +1658,12 @@ int usb_new_device(struct usb_device *udev) | |||
1657 | goto fail; | 1658 | goto fail; |
1658 | } | 1659 | } |
1659 | 1660 | ||
1660 | /* put device-specific files into sysfs */ | 1661 | (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); |
1661 | usb_create_sysfs_dev_files(udev); | ||
1662 | |||
1663 | /* Tell the world! */ | ||
1664 | announce_device(udev); | ||
1665 | return err; | 1662 | return err; |
1666 | 1663 | ||
1667 | fail: | 1664 | fail: |
1668 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); | 1665 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); |
1666 | usb_stop_pm(udev); | ||
1669 | return err; | 1667 | return err; |
1670 | } | 1668 | } |
1671 | 1669 | ||
@@ -1982,7 +1980,7 @@ static int check_port_resume_type(struct usb_device *udev, | |||
1982 | * | 1980 | * |
1983 | * Returns 0 on success, else negative errno. | 1981 | * Returns 0 on success, else negative errno. |
1984 | */ | 1982 | */ |
1985 | int usb_port_suspend(struct usb_device *udev) | 1983 | int usb_port_suspend(struct usb_device *udev, pm_message_t msg) |
1986 | { | 1984 | { |
1987 | struct usb_hub *hub = hdev_to_hub(udev->parent); | 1985 | struct usb_hub *hub = hdev_to_hub(udev->parent); |
1988 | int port1 = udev->portnum; | 1986 | int port1 = udev->portnum; |
@@ -2021,7 +2019,7 @@ int usb_port_suspend(struct usb_device *udev) | |||
2021 | } else { | 2019 | } else { |
2022 | /* device has up to 10 msec to fully suspend */ | 2020 | /* device has up to 10 msec to fully suspend */ |
2023 | dev_dbg(&udev->dev, "usb %ssuspend\n", | 2021 | dev_dbg(&udev->dev, "usb %ssuspend\n", |
2024 | udev->auto_pm ? "auto-" : ""); | 2022 | (msg.event & PM_EVENT_AUTO ? "auto-" : "")); |
2025 | usb_set_device_state(udev, USB_STATE_SUSPENDED); | 2023 | usb_set_device_state(udev, USB_STATE_SUSPENDED); |
2026 | msleep(10); | 2024 | msleep(10); |
2027 | } | 2025 | } |
@@ -2045,8 +2043,8 @@ static int finish_port_resume(struct usb_device *udev) | |||
2045 | u16 devstatus; | 2043 | u16 devstatus; |
2046 | 2044 | ||
2047 | /* caller owns the udev device lock */ | 2045 | /* caller owns the udev device lock */ |
2048 | dev_dbg(&udev->dev, "finish %sresume\n", | 2046 | dev_dbg(&udev->dev, "%s\n", |
2049 | udev->reset_resume ? "reset-" : ""); | 2047 | udev->reset_resume ? "finish reset-resume" : "finish resume"); |
2050 | 2048 | ||
2051 | /* usb ch9 identifies four variants of SUSPENDED, based on what | 2049 | /* usb ch9 identifies four variants of SUSPENDED, based on what |
2052 | * state the device resumes to. Linux currently won't see the | 2050 | * state the device resumes to. Linux currently won't see the |
@@ -2098,8 +2096,9 @@ static int finish_port_resume(struct usb_device *udev) | |||
2098 | NULL, 0, | 2096 | NULL, 0, |
2099 | USB_CTRL_SET_TIMEOUT); | 2097 | USB_CTRL_SET_TIMEOUT); |
2100 | if (status) | 2098 | if (status) |
2101 | dev_dbg(&udev->dev, "disable remote " | 2099 | dev_dbg(&udev->dev, |
2102 | "wakeup, status %d\n", status); | 2100 | "disable remote wakeup, status %d\n", |
2101 | status); | ||
2103 | } | 2102 | } |
2104 | status = 0; | 2103 | status = 0; |
2105 | } | 2104 | } |
@@ -2140,7 +2139,7 @@ static int finish_port_resume(struct usb_device *udev) | |||
2140 | * | 2139 | * |
2141 | * Returns 0 on success, else negative errno. | 2140 | * Returns 0 on success, else negative errno. |
2142 | */ | 2141 | */ |
2143 | int usb_port_resume(struct usb_device *udev) | 2142 | int usb_port_resume(struct usb_device *udev, pm_message_t msg) |
2144 | { | 2143 | { |
2145 | struct usb_hub *hub = hdev_to_hub(udev->parent); | 2144 | struct usb_hub *hub = hdev_to_hub(udev->parent); |
2146 | int port1 = udev->portnum; | 2145 | int port1 = udev->portnum; |
@@ -2165,7 +2164,7 @@ int usb_port_resume(struct usb_device *udev) | |||
2165 | } else { | 2164 | } else { |
2166 | /* drive resume for at least 20 msec */ | 2165 | /* drive resume for at least 20 msec */ |
2167 | dev_dbg(&udev->dev, "usb %sresume\n", | 2166 | dev_dbg(&udev->dev, "usb %sresume\n", |
2168 | udev->auto_pm ? "auto-" : ""); | 2167 | (msg.event & PM_EVENT_AUTO ? "auto-" : "")); |
2169 | msleep(25); | 2168 | msleep(25); |
2170 | 2169 | ||
2171 | /* Virtual root hubs can trigger on GET_PORT_STATUS to | 2170 | /* Virtual root hubs can trigger on GET_PORT_STATUS to |
@@ -2206,7 +2205,7 @@ static int remote_wakeup(struct usb_device *udev) | |||
2206 | if (udev->state == USB_STATE_SUSPENDED) { | 2205 | if (udev->state == USB_STATE_SUSPENDED) { |
2207 | dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); | 2206 | dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); |
2208 | usb_mark_last_busy(udev); | 2207 | usb_mark_last_busy(udev); |
2209 | status = usb_external_resume_device(udev); | 2208 | status = usb_external_resume_device(udev, PMSG_REMOTE_RESUME); |
2210 | } | 2209 | } |
2211 | return status; | 2210 | return status; |
2212 | } | 2211 | } |
@@ -2215,14 +2214,14 @@ static int remote_wakeup(struct usb_device *udev) | |||
2215 | 2214 | ||
2216 | /* When CONFIG_USB_SUSPEND isn't set, we never suspend or resume any ports. */ | 2215 | /* When CONFIG_USB_SUSPEND isn't set, we never suspend or resume any ports. */ |
2217 | 2216 | ||
2218 | int usb_port_suspend(struct usb_device *udev) | 2217 | int usb_port_suspend(struct usb_device *udev, pm_message_t msg) |
2219 | { | 2218 | { |
2220 | return 0; | 2219 | return 0; |
2221 | } | 2220 | } |
2222 | 2221 | ||
2223 | /* However we may need to do a reset-resume */ | 2222 | /* However we may need to do a reset-resume */ |
2224 | 2223 | ||
2225 | int usb_port_resume(struct usb_device *udev) | 2224 | int usb_port_resume(struct usb_device *udev, pm_message_t msg) |
2226 | { | 2225 | { |
2227 | struct usb_hub *hub = hdev_to_hub(udev->parent); | 2226 | struct usb_hub *hub = hdev_to_hub(udev->parent); |
2228 | int port1 = udev->portnum; | 2227 | int port1 = udev->portnum; |
@@ -2262,7 +2261,7 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | |||
2262 | 2261 | ||
2263 | udev = hdev->children [port1-1]; | 2262 | udev = hdev->children [port1-1]; |
2264 | if (udev && udev->can_submit) { | 2263 | if (udev && udev->can_submit) { |
2265 | if (!hdev->auto_pm) | 2264 | if (!(msg.event & PM_EVENT_AUTO)) |
2266 | dev_dbg(&intf->dev, "port %d nyet suspended\n", | 2265 | dev_dbg(&intf->dev, "port %d nyet suspended\n", |
2267 | port1); | 2266 | port1); |
2268 | return -EBUSY; | 2267 | return -EBUSY; |
@@ -2385,7 +2384,7 @@ void usb_ep0_reinit(struct usb_device *udev) | |||
2385 | { | 2384 | { |
2386 | usb_disable_endpoint(udev, 0 + USB_DIR_IN); | 2385 | usb_disable_endpoint(udev, 0 + USB_DIR_IN); |
2387 | usb_disable_endpoint(udev, 0 + USB_DIR_OUT); | 2386 | usb_disable_endpoint(udev, 0 + USB_DIR_OUT); |
2388 | usb_enable_endpoint(udev, &udev->ep0); | 2387 | usb_enable_endpoint(udev, &udev->ep0, true); |
2389 | } | 2388 | } |
2390 | EXPORT_SYMBOL_GPL(usb_ep0_reinit); | 2389 | EXPORT_SYMBOL_GPL(usb_ep0_reinit); |
2391 | 2390 | ||
@@ -2582,9 +2581,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2582 | goto fail; | 2581 | goto fail; |
2583 | } | 2582 | } |
2584 | if (r) { | 2583 | if (r) { |
2585 | dev_err(&udev->dev, "device descriptor " | 2584 | dev_err(&udev->dev, |
2586 | "read/%s, error %d\n", | 2585 | "device descriptor read/64, error %d\n", |
2587 | "64", r); | 2586 | r); |
2588 | retval = -EMSGSIZE; | 2587 | retval = -EMSGSIZE; |
2589 | continue; | 2588 | continue; |
2590 | } | 2589 | } |
@@ -2621,9 +2620,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2621 | 2620 | ||
2622 | retval = usb_get_device_descriptor(udev, 8); | 2621 | retval = usb_get_device_descriptor(udev, 8); |
2623 | if (retval < 8) { | 2622 | if (retval < 8) { |
2624 | dev_err(&udev->dev, "device descriptor " | 2623 | dev_err(&udev->dev, |
2625 | "read/%s, error %d\n", | 2624 | "device descriptor read/8, error %d\n", |
2626 | "8", retval); | 2625 | retval); |
2627 | if (retval >= 0) | 2626 | if (retval >= 0) |
2628 | retval = -EMSGSIZE; | 2627 | retval = -EMSGSIZE; |
2629 | } else { | 2628 | } else { |
@@ -2650,8 +2649,8 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2650 | 2649 | ||
2651 | retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE); | 2650 | retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE); |
2652 | if (retval < (signed)sizeof(udev->descriptor)) { | 2651 | if (retval < (signed)sizeof(udev->descriptor)) { |
2653 | dev_err(&udev->dev, "device descriptor read/%s, error %d\n", | 2652 | dev_err(&udev->dev, "device descriptor read/all, error %d\n", |
2654 | "all", retval); | 2653 | retval); |
2655 | if (retval >= 0) | 2654 | if (retval >= 0) |
2656 | retval = -ENOMSG; | 2655 | retval = -ENOMSG; |
2657 | goto fail; | 2656 | goto fail; |
@@ -2719,9 +2718,9 @@ hub_power_remaining (struct usb_hub *hub) | |||
2719 | else | 2718 | else |
2720 | delta = 8; | 2719 | delta = 8; |
2721 | if (delta > hub->mA_per_port) | 2720 | if (delta > hub->mA_per_port) |
2722 | dev_warn(&udev->dev, "%dmA is over %umA budget " | 2721 | dev_warn(&udev->dev, |
2723 | "for port %d!\n", | 2722 | "%dmA is over %umA budget for port %d!\n", |
2724 | delta, hub->mA_per_port, port1); | 2723 | delta, hub->mA_per_port, port1); |
2725 | remaining -= delta; | 2724 | remaining -= delta; |
2726 | } | 2725 | } |
2727 | if (remaining < 0) { | 2726 | if (remaining < 0) { |
@@ -3517,3 +3516,46 @@ int usb_reset_device(struct usb_device *udev) | |||
3517 | return ret; | 3516 | return ret; |
3518 | } | 3517 | } |
3519 | EXPORT_SYMBOL_GPL(usb_reset_device); | 3518 | EXPORT_SYMBOL_GPL(usb_reset_device); |
3519 | |||
3520 | |||
3521 | /** | ||
3522 | * usb_queue_reset_device - Reset a USB device from an atomic context | ||
3523 | * @iface: USB interface belonging to the device to reset | ||
3524 | * | ||
3525 | * This function can be used to reset a USB device from an atomic | ||
3526 | * context, where usb_reset_device() won't work (as it blocks). | ||
3527 | * | ||
3528 | * Doing a reset via this method is functionally equivalent to calling | ||
3529 | * usb_reset_device(), except for the fact that it is delayed to a | ||
3530 | * workqueue. This means that any drivers bound to other interfaces | ||
3531 | * might be unbound, as well as users from usbfs in user space. | ||
3532 | * | ||
3533 | * Corner cases: | ||
3534 | * | ||
3535 | * - Scheduling two resets at the same time from two different drivers | ||
3536 | * attached to two different interfaces of the same device is | ||
3537 | * possible; depending on how the driver attached to each interface | ||
3538 | * handles ->pre_reset(), the second reset might happen or not. | ||
3539 | * | ||
3540 | * - If a driver is unbound and it had a pending reset, the reset will | ||
3541 | * be cancelled. | ||
3542 | * | ||
3543 | * - This function can be called during .probe() or .disconnect() | ||
3544 | * times. On return from .disconnect(), any pending resets will be | ||
3545 | * cancelled. | ||
3546 | * | ||
3547 | * There is no no need to lock/unlock the @reset_ws as schedule_work() | ||
3548 | * does its own. | ||
3549 | * | ||
3550 | * NOTE: We don't do any reference count tracking because it is not | ||
3551 | * needed. The lifecycle of the work_struct is tied to the | ||
3552 | * usb_interface. Before destroying the interface we cancel the | ||
3553 | * work_struct, so the fact that work_struct is queued and or | ||
3554 | * running means the interface (and thus, the device) exist and | ||
3555 | * are referenced. | ||
3556 | */ | ||
3557 | void usb_queue_reset_device(struct usb_interface *iface) | ||
3558 | { | ||
3559 | schedule_work(&iface->reset_ws); | ||
3560 | } | ||
3561 | EXPORT_SYMBOL_GPL(usb_queue_reset_device); | ||
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 6d1048faf08e..de51667dd64d 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -18,6 +18,8 @@ | |||
18 | #include "hcd.h" /* for usbcore internals */ | 18 | #include "hcd.h" /* for usbcore internals */ |
19 | #include "usb.h" | 19 | #include "usb.h" |
20 | 20 | ||
21 | static void cancel_async_set_config(struct usb_device *udev); | ||
22 | |||
21 | struct api_context { | 23 | struct api_context { |
22 | struct completion done; | 24 | struct completion done; |
23 | int status; | 25 | int status; |
@@ -139,9 +141,9 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, | |||
139 | 141 | ||
140 | dr->bRequestType = requesttype; | 142 | dr->bRequestType = requesttype; |
141 | dr->bRequest = request; | 143 | dr->bRequest = request; |
142 | dr->wValue = cpu_to_le16p(&value); | 144 | dr->wValue = cpu_to_le16(value); |
143 | dr->wIndex = cpu_to_le16p(&index); | 145 | dr->wIndex = cpu_to_le16(index); |
144 | dr->wLength = cpu_to_le16p(&size); | 146 | dr->wLength = cpu_to_le16(size); |
145 | 147 | ||
146 | /* dbg("usb_control_msg"); */ | 148 | /* dbg("usb_control_msg"); */ |
147 | 149 | ||
@@ -1004,6 +1006,34 @@ int usb_clear_halt(struct usb_device *dev, int pipe) | |||
1004 | } | 1006 | } |
1005 | EXPORT_SYMBOL_GPL(usb_clear_halt); | 1007 | EXPORT_SYMBOL_GPL(usb_clear_halt); |
1006 | 1008 | ||
1009 | static int create_intf_ep_devs(struct usb_interface *intf) | ||
1010 | { | ||
1011 | struct usb_device *udev = interface_to_usbdev(intf); | ||
1012 | struct usb_host_interface *alt = intf->cur_altsetting; | ||
1013 | int i; | ||
1014 | |||
1015 | if (intf->ep_devs_created || intf->unregistering) | ||
1016 | return 0; | ||
1017 | |||
1018 | for (i = 0; i < alt->desc.bNumEndpoints; ++i) | ||
1019 | (void) usb_create_ep_devs(&intf->dev, &alt->endpoint[i], udev); | ||
1020 | intf->ep_devs_created = 1; | ||
1021 | return 0; | ||
1022 | } | ||
1023 | |||
1024 | static void remove_intf_ep_devs(struct usb_interface *intf) | ||
1025 | { | ||
1026 | struct usb_host_interface *alt = intf->cur_altsetting; | ||
1027 | int i; | ||
1028 | |||
1029 | if (!intf->ep_devs_created) | ||
1030 | return; | ||
1031 | |||
1032 | for (i = 0; i < alt->desc.bNumEndpoints; ++i) | ||
1033 | usb_remove_ep_devs(&alt->endpoint[i]); | ||
1034 | intf->ep_devs_created = 0; | ||
1035 | } | ||
1036 | |||
1007 | /** | 1037 | /** |
1008 | * usb_disable_endpoint -- Disable an endpoint by address | 1038 | * usb_disable_endpoint -- Disable an endpoint by address |
1009 | * @dev: the device whose endpoint is being disabled | 1039 | * @dev: the device whose endpoint is being disabled |
@@ -1092,7 +1122,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0) | |||
1092 | dev_dbg(&dev->dev, "unregistering interface %s\n", | 1122 | dev_dbg(&dev->dev, "unregistering interface %s\n", |
1093 | dev_name(&interface->dev)); | 1123 | dev_name(&interface->dev)); |
1094 | interface->unregistering = 1; | 1124 | interface->unregistering = 1; |
1095 | usb_remove_sysfs_intf_files(interface); | 1125 | remove_intf_ep_devs(interface); |
1096 | device_del(&interface->dev); | 1126 | device_del(&interface->dev); |
1097 | } | 1127 | } |
1098 | 1128 | ||
@@ -1113,22 +1143,26 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0) | |||
1113 | * usb_enable_endpoint - Enable an endpoint for USB communications | 1143 | * usb_enable_endpoint - Enable an endpoint for USB communications |
1114 | * @dev: the device whose interface is being enabled | 1144 | * @dev: the device whose interface is being enabled |
1115 | * @ep: the endpoint | 1145 | * @ep: the endpoint |
1146 | * @reset_toggle: flag to set the endpoint's toggle back to 0 | ||
1116 | * | 1147 | * |
1117 | * Resets the endpoint toggle, and sets dev->ep_{in,out} pointers. | 1148 | * Resets the endpoint toggle if asked, and sets dev->ep_{in,out} pointers. |
1118 | * For control endpoints, both the input and output sides are handled. | 1149 | * For control endpoints, both the input and output sides are handled. |
1119 | */ | 1150 | */ |
1120 | void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep) | 1151 | void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep, |
1152 | bool reset_toggle) | ||
1121 | { | 1153 | { |
1122 | int epnum = usb_endpoint_num(&ep->desc); | 1154 | int epnum = usb_endpoint_num(&ep->desc); |
1123 | int is_out = usb_endpoint_dir_out(&ep->desc); | 1155 | int is_out = usb_endpoint_dir_out(&ep->desc); |
1124 | int is_control = usb_endpoint_xfer_control(&ep->desc); | 1156 | int is_control = usb_endpoint_xfer_control(&ep->desc); |
1125 | 1157 | ||
1126 | if (is_out || is_control) { | 1158 | if (is_out || is_control) { |
1127 | usb_settoggle(dev, epnum, 1, 0); | 1159 | if (reset_toggle) |
1160 | usb_settoggle(dev, epnum, 1, 0); | ||
1128 | dev->ep_out[epnum] = ep; | 1161 | dev->ep_out[epnum] = ep; |
1129 | } | 1162 | } |
1130 | if (!is_out || is_control) { | 1163 | if (!is_out || is_control) { |
1131 | usb_settoggle(dev, epnum, 0, 0); | 1164 | if (reset_toggle) |
1165 | usb_settoggle(dev, epnum, 0, 0); | ||
1132 | dev->ep_in[epnum] = ep; | 1166 | dev->ep_in[epnum] = ep; |
1133 | } | 1167 | } |
1134 | ep->enabled = 1; | 1168 | ep->enabled = 1; |
@@ -1138,17 +1172,18 @@ void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep) | |||
1138 | * usb_enable_interface - Enable all the endpoints for an interface | 1172 | * usb_enable_interface - Enable all the endpoints for an interface |
1139 | * @dev: the device whose interface is being enabled | 1173 | * @dev: the device whose interface is being enabled |
1140 | * @intf: pointer to the interface descriptor | 1174 | * @intf: pointer to the interface descriptor |
1175 | * @reset_toggles: flag to set the endpoints' toggles back to 0 | ||
1141 | * | 1176 | * |
1142 | * Enables all the endpoints for the interface's current altsetting. | 1177 | * Enables all the endpoints for the interface's current altsetting. |
1143 | */ | 1178 | */ |
1144 | static void usb_enable_interface(struct usb_device *dev, | 1179 | void usb_enable_interface(struct usb_device *dev, |
1145 | struct usb_interface *intf) | 1180 | struct usb_interface *intf, bool reset_toggles) |
1146 | { | 1181 | { |
1147 | struct usb_host_interface *alt = intf->cur_altsetting; | 1182 | struct usb_host_interface *alt = intf->cur_altsetting; |
1148 | int i; | 1183 | int i; |
1149 | 1184 | ||
1150 | for (i = 0; i < alt->desc.bNumEndpoints; ++i) | 1185 | for (i = 0; i < alt->desc.bNumEndpoints; ++i) |
1151 | usb_enable_endpoint(dev, &alt->endpoint[i]); | 1186 | usb_enable_endpoint(dev, &alt->endpoint[i], reset_toggles); |
1152 | } | 1187 | } |
1153 | 1188 | ||
1154 | /** | 1189 | /** |
@@ -1235,8 +1270,10 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1235 | */ | 1270 | */ |
1236 | 1271 | ||
1237 | /* prevent submissions using previous endpoint settings */ | 1272 | /* prevent submissions using previous endpoint settings */ |
1238 | if (iface->cur_altsetting != alt) | 1273 | if (iface->cur_altsetting != alt) { |
1274 | remove_intf_ep_devs(iface); | ||
1239 | usb_remove_sysfs_intf_files(iface); | 1275 | usb_remove_sysfs_intf_files(iface); |
1276 | } | ||
1240 | usb_disable_interface(dev, iface); | 1277 | usb_disable_interface(dev, iface); |
1241 | 1278 | ||
1242 | iface->cur_altsetting = alt; | 1279 | iface->cur_altsetting = alt; |
@@ -1271,10 +1308,11 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1271 | * during the SETUP stage - hence EP0 toggles are "don't care" here. | 1308 | * during the SETUP stage - hence EP0 toggles are "don't care" here. |
1272 | * (Likewise, EP0 never "halts" on well designed devices.) | 1309 | * (Likewise, EP0 never "halts" on well designed devices.) |
1273 | */ | 1310 | */ |
1274 | usb_enable_interface(dev, iface); | 1311 | usb_enable_interface(dev, iface, true); |
1275 | if (device_is_registered(&iface->dev)) | 1312 | if (device_is_registered(&iface->dev)) { |
1276 | usb_create_sysfs_intf_files(iface); | 1313 | usb_create_sysfs_intf_files(iface); |
1277 | 1314 | create_intf_ep_devs(iface); | |
1315 | } | ||
1278 | return 0; | 1316 | return 0; |
1279 | } | 1317 | } |
1280 | EXPORT_SYMBOL_GPL(usb_set_interface); | 1318 | EXPORT_SYMBOL_GPL(usb_set_interface); |
@@ -1334,7 +1372,6 @@ int usb_reset_configuration(struct usb_device *dev) | |||
1334 | struct usb_interface *intf = config->interface[i]; | 1372 | struct usb_interface *intf = config->interface[i]; |
1335 | struct usb_host_interface *alt; | 1373 | struct usb_host_interface *alt; |
1336 | 1374 | ||
1337 | usb_remove_sysfs_intf_files(intf); | ||
1338 | alt = usb_altnum_to_altsetting(intf, 0); | 1375 | alt = usb_altnum_to_altsetting(intf, 0); |
1339 | 1376 | ||
1340 | /* No altsetting 0? We'll assume the first altsetting. | 1377 | /* No altsetting 0? We'll assume the first altsetting. |
@@ -1345,10 +1382,16 @@ int usb_reset_configuration(struct usb_device *dev) | |||
1345 | if (!alt) | 1382 | if (!alt) |
1346 | alt = &intf->altsetting[0]; | 1383 | alt = &intf->altsetting[0]; |
1347 | 1384 | ||
1385 | if (alt != intf->cur_altsetting) { | ||
1386 | remove_intf_ep_devs(intf); | ||
1387 | usb_remove_sysfs_intf_files(intf); | ||
1388 | } | ||
1348 | intf->cur_altsetting = alt; | 1389 | intf->cur_altsetting = alt; |
1349 | usb_enable_interface(dev, intf); | 1390 | usb_enable_interface(dev, intf, true); |
1350 | if (device_is_registered(&intf->dev)) | 1391 | if (device_is_registered(&intf->dev)) { |
1351 | usb_create_sysfs_intf_files(intf); | 1392 | usb_create_sysfs_intf_files(intf); |
1393 | create_intf_ep_devs(intf); | ||
1394 | } | ||
1352 | } | 1395 | } |
1353 | return 0; | 1396 | return 0; |
1354 | } | 1397 | } |
@@ -1441,6 +1484,46 @@ static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev, | |||
1441 | return retval; | 1484 | return retval; |
1442 | } | 1485 | } |
1443 | 1486 | ||
1487 | |||
1488 | /* | ||
1489 | * Internal function to queue a device reset | ||
1490 | * | ||
1491 | * This is initialized into the workstruct in 'struct | ||
1492 | * usb_device->reset_ws' that is launched by | ||
1493 | * message.c:usb_set_configuration() when initializing each 'struct | ||
1494 | * usb_interface'. | ||
1495 | * | ||
1496 | * It is safe to get the USB device without reference counts because | ||
1497 | * the life cycle of @iface is bound to the life cycle of @udev. Then, | ||
1498 | * this function will be ran only if @iface is alive (and before | ||
1499 | * freeing it any scheduled instances of it will have been cancelled). | ||
1500 | * | ||
1501 | * We need to set a flag (usb_dev->reset_running) because when we call | ||
1502 | * the reset, the interfaces might be unbound. The current interface | ||
1503 | * cannot try to remove the queued work as it would cause a deadlock | ||
1504 | * (you cannot remove your work from within your executing | ||
1505 | * workqueue). This flag lets it know, so that | ||
1506 | * usb_cancel_queued_reset() doesn't try to do it. | ||
1507 | * | ||
1508 | * See usb_queue_reset_device() for more details | ||
1509 | */ | ||
1510 | void __usb_queue_reset_device(struct work_struct *ws) | ||
1511 | { | ||
1512 | int rc; | ||
1513 | struct usb_interface *iface = | ||
1514 | container_of(ws, struct usb_interface, reset_ws); | ||
1515 | struct usb_device *udev = interface_to_usbdev(iface); | ||
1516 | |||
1517 | rc = usb_lock_device_for_reset(udev, iface); | ||
1518 | if (rc >= 0) { | ||
1519 | iface->reset_running = 1; | ||
1520 | usb_reset_device(udev); | ||
1521 | iface->reset_running = 0; | ||
1522 | usb_unlock_device(udev); | ||
1523 | } | ||
1524 | } | ||
1525 | |||
1526 | |||
1444 | /* | 1527 | /* |
1445 | * usb_set_configuration - Makes a particular device setting be current | 1528 | * usb_set_configuration - Makes a particular device setting be current |
1446 | * @dev: the device whose configuration is being updated | 1529 | * @dev: the device whose configuration is being updated |
@@ -1560,6 +1643,9 @@ free_interfaces: | |||
1560 | if (dev->state != USB_STATE_ADDRESS) | 1643 | if (dev->state != USB_STATE_ADDRESS) |
1561 | usb_disable_device(dev, 1); /* Skip ep0 */ | 1644 | usb_disable_device(dev, 1); /* Skip ep0 */ |
1562 | 1645 | ||
1646 | /* Get rid of pending async Set-Config requests for this device */ | ||
1647 | cancel_async_set_config(dev); | ||
1648 | |||
1563 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 1649 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
1564 | USB_REQ_SET_CONFIGURATION, 0, configuration, 0, | 1650 | USB_REQ_SET_CONFIGURATION, 0, configuration, 0, |
1565 | NULL, 0, USB_CTRL_SET_TIMEOUT); | 1651 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
@@ -1604,13 +1690,14 @@ free_interfaces: | |||
1604 | alt = &intf->altsetting[0]; | 1690 | alt = &intf->altsetting[0]; |
1605 | 1691 | ||
1606 | intf->cur_altsetting = alt; | 1692 | intf->cur_altsetting = alt; |
1607 | usb_enable_interface(dev, intf); | 1693 | usb_enable_interface(dev, intf, true); |
1608 | intf->dev.parent = &dev->dev; | 1694 | intf->dev.parent = &dev->dev; |
1609 | intf->dev.driver = NULL; | 1695 | intf->dev.driver = NULL; |
1610 | intf->dev.bus = &usb_bus_type; | 1696 | intf->dev.bus = &usb_bus_type; |
1611 | intf->dev.type = &usb_if_device_type; | 1697 | intf->dev.type = &usb_if_device_type; |
1612 | intf->dev.groups = usb_interface_groups; | 1698 | intf->dev.groups = usb_interface_groups; |
1613 | intf->dev.dma_mask = dev->dev.dma_mask; | 1699 | intf->dev.dma_mask = dev->dev.dma_mask; |
1700 | INIT_WORK(&intf->reset_ws, __usb_queue_reset_device); | ||
1614 | device_initialize(&intf->dev); | 1701 | device_initialize(&intf->dev); |
1615 | mark_quiesced(intf); | 1702 | mark_quiesced(intf); |
1616 | dev_set_name(&intf->dev, "%d-%s:%d.%d", | 1703 | dev_set_name(&intf->dev, "%d-%s:%d.%d", |
@@ -1641,17 +1728,21 @@ free_interfaces: | |||
1641 | dev_name(&intf->dev), ret); | 1728 | dev_name(&intf->dev), ret); |
1642 | continue; | 1729 | continue; |
1643 | } | 1730 | } |
1644 | usb_create_sysfs_intf_files(intf); | 1731 | create_intf_ep_devs(intf); |
1645 | } | 1732 | } |
1646 | 1733 | ||
1647 | usb_autosuspend_device(dev); | 1734 | usb_autosuspend_device(dev); |
1648 | return 0; | 1735 | return 0; |
1649 | } | 1736 | } |
1650 | 1737 | ||
1738 | static LIST_HEAD(set_config_list); | ||
1739 | static DEFINE_SPINLOCK(set_config_lock); | ||
1740 | |||
1651 | struct set_config_request { | 1741 | struct set_config_request { |
1652 | struct usb_device *udev; | 1742 | struct usb_device *udev; |
1653 | int config; | 1743 | int config; |
1654 | struct work_struct work; | 1744 | struct work_struct work; |
1745 | struct list_head node; | ||
1655 | }; | 1746 | }; |
1656 | 1747 | ||
1657 | /* Worker routine for usb_driver_set_configuration() */ | 1748 | /* Worker routine for usb_driver_set_configuration() */ |
@@ -1659,14 +1750,35 @@ static void driver_set_config_work(struct work_struct *work) | |||
1659 | { | 1750 | { |
1660 | struct set_config_request *req = | 1751 | struct set_config_request *req = |
1661 | container_of(work, struct set_config_request, work); | 1752 | container_of(work, struct set_config_request, work); |
1753 | struct usb_device *udev = req->udev; | ||
1754 | |||
1755 | usb_lock_device(udev); | ||
1756 | spin_lock(&set_config_lock); | ||
1757 | list_del(&req->node); | ||
1758 | spin_unlock(&set_config_lock); | ||
1662 | 1759 | ||
1663 | usb_lock_device(req->udev); | 1760 | if (req->config >= -1) /* Is req still valid? */ |
1664 | usb_set_configuration(req->udev, req->config); | 1761 | usb_set_configuration(udev, req->config); |
1665 | usb_unlock_device(req->udev); | 1762 | usb_unlock_device(udev); |
1666 | usb_put_dev(req->udev); | 1763 | usb_put_dev(udev); |
1667 | kfree(req); | 1764 | kfree(req); |
1668 | } | 1765 | } |
1669 | 1766 | ||
1767 | /* Cancel pending Set-Config requests for a device whose configuration | ||
1768 | * was just changed | ||
1769 | */ | ||
1770 | static void cancel_async_set_config(struct usb_device *udev) | ||
1771 | { | ||
1772 | struct set_config_request *req; | ||
1773 | |||
1774 | spin_lock(&set_config_lock); | ||
1775 | list_for_each_entry(req, &set_config_list, node) { | ||
1776 | if (req->udev == udev) | ||
1777 | req->config = -999; /* Mark as cancelled */ | ||
1778 | } | ||
1779 | spin_unlock(&set_config_lock); | ||
1780 | } | ||
1781 | |||
1670 | /** | 1782 | /** |
1671 | * usb_driver_set_configuration - Provide a way for drivers to change device configurations | 1783 | * usb_driver_set_configuration - Provide a way for drivers to change device configurations |
1672 | * @udev: the device whose configuration is being updated | 1784 | * @udev: the device whose configuration is being updated |
@@ -1698,6 +1810,10 @@ int usb_driver_set_configuration(struct usb_device *udev, int config) | |||
1698 | req->config = config; | 1810 | req->config = config; |
1699 | INIT_WORK(&req->work, driver_set_config_work); | 1811 | INIT_WORK(&req->work, driver_set_config_work); |
1700 | 1812 | ||
1813 | spin_lock(&set_config_lock); | ||
1814 | list_add(&req->node, &set_config_list); | ||
1815 | spin_unlock(&set_config_lock); | ||
1816 | |||
1701 | usb_get_dev(udev); | 1817 | usb_get_dev(udev); |
1702 | schedule_work(&req->work); | 1818 | schedule_work(&req->work); |
1703 | return 0; | 1819 | return 0; |
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 4fb65fdc9dc3..4cc2456ef3be 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -359,19 +359,19 @@ set_level(struct device *dev, struct device_attribute *attr, | |||
359 | strncmp(buf, on_string, len) == 0) { | 359 | strncmp(buf, on_string, len) == 0) { |
360 | udev->autosuspend_disabled = 1; | 360 | udev->autosuspend_disabled = 1; |
361 | udev->autoresume_disabled = 0; | 361 | udev->autoresume_disabled = 0; |
362 | rc = usb_external_resume_device(udev); | 362 | rc = usb_external_resume_device(udev, PMSG_USER_RESUME); |
363 | 363 | ||
364 | } else if (len == sizeof auto_string - 1 && | 364 | } else if (len == sizeof auto_string - 1 && |
365 | strncmp(buf, auto_string, len) == 0) { | 365 | strncmp(buf, auto_string, len) == 0) { |
366 | udev->autosuspend_disabled = 0; | 366 | udev->autosuspend_disabled = 0; |
367 | udev->autoresume_disabled = 0; | 367 | udev->autoresume_disabled = 0; |
368 | rc = usb_external_resume_device(udev); | 368 | rc = usb_external_resume_device(udev, PMSG_USER_RESUME); |
369 | 369 | ||
370 | } else if (len == sizeof suspend_string - 1 && | 370 | } else if (len == sizeof suspend_string - 1 && |
371 | strncmp(buf, suspend_string, len) == 0) { | 371 | strncmp(buf, suspend_string, len) == 0) { |
372 | udev->autosuspend_disabled = 0; | 372 | udev->autosuspend_disabled = 0; |
373 | udev->autoresume_disabled = 1; | 373 | udev->autoresume_disabled = 1; |
374 | rc = usb_external_suspend_device(udev, PMSG_SUSPEND); | 374 | rc = usb_external_suspend_device(udev, PMSG_USER_SUSPEND); |
375 | 375 | ||
376 | } else | 376 | } else |
377 | rc = -EINVAL; | 377 | rc = -EINVAL; |
@@ -629,9 +629,6 @@ int usb_create_sysfs_dev_files(struct usb_device *udev) | |||
629 | struct device *dev = &udev->dev; | 629 | struct device *dev = &udev->dev; |
630 | int retval; | 630 | int retval; |
631 | 631 | ||
632 | /* Unforunately these attributes cannot be created before | ||
633 | * the uevent is broadcast. | ||
634 | */ | ||
635 | retval = device_create_bin_file(dev, &dev_bin_attr_descriptors); | 632 | retval = device_create_bin_file(dev, &dev_bin_attr_descriptors); |
636 | if (retval) | 633 | if (retval) |
637 | goto error; | 634 | goto error; |
@@ -643,11 +640,7 @@ int usb_create_sysfs_dev_files(struct usb_device *udev) | |||
643 | retval = add_power_attributes(dev); | 640 | retval = add_power_attributes(dev); |
644 | if (retval) | 641 | if (retval) |
645 | goto error; | 642 | goto error; |
646 | 643 | return retval; | |
647 | retval = usb_create_ep_files(dev, &udev->ep0, udev); | ||
648 | if (retval) | ||
649 | goto error; | ||
650 | return 0; | ||
651 | error: | 644 | error: |
652 | usb_remove_sysfs_dev_files(udev); | 645 | usb_remove_sysfs_dev_files(udev); |
653 | return retval; | 646 | return retval; |
@@ -657,7 +650,6 @@ void usb_remove_sysfs_dev_files(struct usb_device *udev) | |||
657 | { | 650 | { |
658 | struct device *dev = &udev->dev; | 651 | struct device *dev = &udev->dev; |
659 | 652 | ||
660 | usb_remove_ep_files(&udev->ep0); | ||
661 | remove_power_attributes(dev); | 653 | remove_power_attributes(dev); |
662 | remove_persist_attributes(dev); | 654 | remove_persist_attributes(dev); |
663 | device_remove_bin_file(dev, &dev_bin_attr_descriptors); | 655 | device_remove_bin_file(dev, &dev_bin_attr_descriptors); |
@@ -812,28 +804,6 @@ struct attribute_group *usb_interface_groups[] = { | |||
812 | NULL | 804 | NULL |
813 | }; | 805 | }; |
814 | 806 | ||
815 | static inline void usb_create_intf_ep_files(struct usb_interface *intf, | ||
816 | struct usb_device *udev) | ||
817 | { | ||
818 | struct usb_host_interface *iface_desc; | ||
819 | int i; | ||
820 | |||
821 | iface_desc = intf->cur_altsetting; | ||
822 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) | ||
823 | usb_create_ep_files(&intf->dev, &iface_desc->endpoint[i], | ||
824 | udev); | ||
825 | } | ||
826 | |||
827 | static inline void usb_remove_intf_ep_files(struct usb_interface *intf) | ||
828 | { | ||
829 | struct usb_host_interface *iface_desc; | ||
830 | int i; | ||
831 | |||
832 | iface_desc = intf->cur_altsetting; | ||
833 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) | ||
834 | usb_remove_ep_files(&iface_desc->endpoint[i]); | ||
835 | } | ||
836 | |||
837 | int usb_create_sysfs_intf_files(struct usb_interface *intf) | 807 | int usb_create_sysfs_intf_files(struct usb_interface *intf) |
838 | { | 808 | { |
839 | struct usb_device *udev = interface_to_usbdev(intf); | 809 | struct usb_device *udev = interface_to_usbdev(intf); |
@@ -843,26 +813,19 @@ int usb_create_sysfs_intf_files(struct usb_interface *intf) | |||
843 | if (intf->sysfs_files_created || intf->unregistering) | 813 | if (intf->sysfs_files_created || intf->unregistering) |
844 | return 0; | 814 | return 0; |
845 | 815 | ||
846 | /* The interface string may be present in some altsettings | ||
847 | * and missing in others. Hence its attribute cannot be created | ||
848 | * before the uevent is broadcast. | ||
849 | */ | ||
850 | if (alt->string == NULL) | 816 | if (alt->string == NULL) |
851 | alt->string = usb_cache_string(udev, alt->desc.iInterface); | 817 | alt->string = usb_cache_string(udev, alt->desc.iInterface); |
852 | if (alt->string) | 818 | if (alt->string) |
853 | retval = device_create_file(&intf->dev, &dev_attr_interface); | 819 | retval = device_create_file(&intf->dev, &dev_attr_interface); |
854 | usb_create_intf_ep_files(intf, udev); | ||
855 | intf->sysfs_files_created = 1; | 820 | intf->sysfs_files_created = 1; |
856 | return 0; | 821 | return 0; |
857 | } | 822 | } |
858 | 823 | ||
859 | void usb_remove_sysfs_intf_files(struct usb_interface *intf) | 824 | void usb_remove_sysfs_intf_files(struct usb_interface *intf) |
860 | { | 825 | { |
861 | struct device *dev = &intf->dev; | ||
862 | |||
863 | if (!intf->sysfs_files_created) | 826 | if (!intf->sysfs_files_created) |
864 | return; | 827 | return; |
865 | usb_remove_intf_ep_files(intf); | 828 | |
866 | device_remove_file(dev, &dev_attr_interface); | 829 | device_remove_file(&intf->dev, &dev_attr_interface); |
867 | intf->sysfs_files_created = 0; | 830 | intf->sysfs_files_created = 0; |
868 | } | 831 | } |
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index 1f68af9db3f7..58bc5e3c2560 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c | |||
@@ -10,7 +10,6 @@ | |||
10 | 10 | ||
11 | #define to_urb(d) container_of(d, struct urb, kref) | 11 | #define to_urb(d) container_of(d, struct urb, kref) |
12 | 12 | ||
13 | static DEFINE_SPINLOCK(usb_reject_lock); | ||
14 | 13 | ||
15 | static void urb_destroy(struct kref *kref) | 14 | static void urb_destroy(struct kref *kref) |
16 | { | 15 | { |
@@ -131,9 +130,7 @@ void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor) | |||
131 | urb->anchor = anchor; | 130 | urb->anchor = anchor; |
132 | 131 | ||
133 | if (unlikely(anchor->poisoned)) { | 132 | if (unlikely(anchor->poisoned)) { |
134 | spin_lock(&usb_reject_lock); | 133 | atomic_inc(&urb->reject); |
135 | urb->reject++; | ||
136 | spin_unlock(&usb_reject_lock); | ||
137 | } | 134 | } |
138 | 135 | ||
139 | spin_unlock_irqrestore(&anchor->lock, flags); | 136 | spin_unlock_irqrestore(&anchor->lock, flags); |
@@ -565,16 +562,12 @@ void usb_kill_urb(struct urb *urb) | |||
565 | might_sleep(); | 562 | might_sleep(); |
566 | if (!(urb && urb->dev && urb->ep)) | 563 | if (!(urb && urb->dev && urb->ep)) |
567 | return; | 564 | return; |
568 | spin_lock_irq(&usb_reject_lock); | 565 | atomic_inc(&urb->reject); |
569 | ++urb->reject; | ||
570 | spin_unlock_irq(&usb_reject_lock); | ||
571 | 566 | ||
572 | usb_hcd_unlink_urb(urb, -ENOENT); | 567 | usb_hcd_unlink_urb(urb, -ENOENT); |
573 | wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); | 568 | wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); |
574 | 569 | ||
575 | spin_lock_irq(&usb_reject_lock); | 570 | atomic_dec(&urb->reject); |
576 | --urb->reject; | ||
577 | spin_unlock_irq(&usb_reject_lock); | ||
578 | } | 571 | } |
579 | EXPORT_SYMBOL_GPL(usb_kill_urb); | 572 | EXPORT_SYMBOL_GPL(usb_kill_urb); |
580 | 573 | ||
@@ -606,9 +599,7 @@ void usb_poison_urb(struct urb *urb) | |||
606 | might_sleep(); | 599 | might_sleep(); |
607 | if (!(urb && urb->dev && urb->ep)) | 600 | if (!(urb && urb->dev && urb->ep)) |
608 | return; | 601 | return; |
609 | spin_lock_irq(&usb_reject_lock); | 602 | atomic_inc(&urb->reject); |
610 | ++urb->reject; | ||
611 | spin_unlock_irq(&usb_reject_lock); | ||
612 | 603 | ||
613 | usb_hcd_unlink_urb(urb, -ENOENT); | 604 | usb_hcd_unlink_urb(urb, -ENOENT); |
614 | wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); | 605 | wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); |
@@ -617,14 +608,10 @@ EXPORT_SYMBOL_GPL(usb_poison_urb); | |||
617 | 608 | ||
618 | void usb_unpoison_urb(struct urb *urb) | 609 | void usb_unpoison_urb(struct urb *urb) |
619 | { | 610 | { |
620 | unsigned long flags; | ||
621 | |||
622 | if (!urb) | 611 | if (!urb) |
623 | return; | 612 | return; |
624 | 613 | ||
625 | spin_lock_irqsave(&usb_reject_lock, flags); | 614 | atomic_dec(&urb->reject); |
626 | --urb->reject; | ||
627 | spin_unlock_irqrestore(&usb_reject_lock, flags); | ||
628 | } | 615 | } |
629 | EXPORT_SYMBOL_GPL(usb_unpoison_urb); | 616 | EXPORT_SYMBOL_GPL(usb_unpoison_urb); |
630 | 617 | ||
@@ -692,6 +679,26 @@ void usb_poison_anchored_urbs(struct usb_anchor *anchor) | |||
692 | EXPORT_SYMBOL_GPL(usb_poison_anchored_urbs); | 679 | EXPORT_SYMBOL_GPL(usb_poison_anchored_urbs); |
693 | 680 | ||
694 | /** | 681 | /** |
682 | * usb_unpoison_anchored_urbs - let an anchor be used successfully again | ||
683 | * @anchor: anchor the requests are bound to | ||
684 | * | ||
685 | * Reverses the effect of usb_poison_anchored_urbs | ||
686 | * the anchor can be used normally after it returns | ||
687 | */ | ||
688 | void usb_unpoison_anchored_urbs(struct usb_anchor *anchor) | ||
689 | { | ||
690 | unsigned long flags; | ||
691 | struct urb *lazarus; | ||
692 | |||
693 | spin_lock_irqsave(&anchor->lock, flags); | ||
694 | list_for_each_entry(lazarus, &anchor->urb_list, anchor_list) { | ||
695 | usb_unpoison_urb(lazarus); | ||
696 | } | ||
697 | anchor->poisoned = 0; | ||
698 | spin_unlock_irqrestore(&anchor->lock, flags); | ||
699 | } | ||
700 | EXPORT_SYMBOL_GPL(usb_unpoison_anchored_urbs); | ||
701 | /** | ||
695 | * usb_unlink_anchored_urbs - asynchronously cancel transfer requests en masse | 702 | * usb_unlink_anchored_urbs - asynchronously cancel transfer requests en masse |
696 | * @anchor: anchor the requests are bound to | 703 | * @anchor: anchor the requests are bound to |
697 | * | 704 | * |
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 399e15fc5052..dcfc072630c1 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -253,7 +253,7 @@ static int usb_dev_prepare(struct device *dev) | |||
253 | static void usb_dev_complete(struct device *dev) | 253 | static void usb_dev_complete(struct device *dev) |
254 | { | 254 | { |
255 | /* Currently used only for rebinding interfaces */ | 255 | /* Currently used only for rebinding interfaces */ |
256 | usb_resume(dev); /* Implement eventually? */ | 256 | usb_resume(dev, PMSG_RESUME); /* Message event is meaningless */ |
257 | } | 257 | } |
258 | 258 | ||
259 | static int usb_dev_suspend(struct device *dev) | 259 | static int usb_dev_suspend(struct device *dev) |
@@ -263,7 +263,7 @@ static int usb_dev_suspend(struct device *dev) | |||
263 | 263 | ||
264 | static int usb_dev_resume(struct device *dev) | 264 | static int usb_dev_resume(struct device *dev) |
265 | { | 265 | { |
266 | return usb_resume(dev); | 266 | return usb_resume(dev, PMSG_RESUME); |
267 | } | 267 | } |
268 | 268 | ||
269 | static int usb_dev_freeze(struct device *dev) | 269 | static int usb_dev_freeze(struct device *dev) |
@@ -273,7 +273,7 @@ static int usb_dev_freeze(struct device *dev) | |||
273 | 273 | ||
274 | static int usb_dev_thaw(struct device *dev) | 274 | static int usb_dev_thaw(struct device *dev) |
275 | { | 275 | { |
276 | return usb_resume(dev); | 276 | return usb_resume(dev, PMSG_THAW); |
277 | } | 277 | } |
278 | 278 | ||
279 | static int usb_dev_poweroff(struct device *dev) | 279 | static int usb_dev_poweroff(struct device *dev) |
@@ -283,7 +283,7 @@ static int usb_dev_poweroff(struct device *dev) | |||
283 | 283 | ||
284 | static int usb_dev_restore(struct device *dev) | 284 | static int usb_dev_restore(struct device *dev) |
285 | { | 285 | { |
286 | return usb_resume(dev); | 286 | return usb_resume(dev, PMSG_RESTORE); |
287 | } | 287 | } |
288 | 288 | ||
289 | static struct dev_pm_ops usb_device_pm_ops = { | 289 | static struct dev_pm_ops usb_device_pm_ops = { |
@@ -362,7 +362,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, | |||
362 | dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; | 362 | dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; |
363 | dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT; | 363 | dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT; |
364 | /* ep0 maxpacket comes later, from device descriptor */ | 364 | /* ep0 maxpacket comes later, from device descriptor */ |
365 | usb_enable_endpoint(dev, &dev->ep0); | 365 | usb_enable_endpoint(dev, &dev->ep0, true); |
366 | dev->can_submit = 1; | 366 | dev->can_submit = 1; |
367 | 367 | ||
368 | /* Save readable and stable topology id, distinguishing devices | 368 | /* Save readable and stable topology id, distinguishing devices |
@@ -402,6 +402,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, | |||
402 | #ifdef CONFIG_PM | 402 | #ifdef CONFIG_PM |
403 | mutex_init(&dev->pm_mutex); | 403 | mutex_init(&dev->pm_mutex); |
404 | INIT_DELAYED_WORK(&dev->autosuspend, usb_autosuspend_work); | 404 | INIT_DELAYED_WORK(&dev->autosuspend, usb_autosuspend_work); |
405 | INIT_WORK(&dev->autoresume, usb_autoresume_work); | ||
405 | dev->autosuspend_delay = usb_autosuspend_delay * HZ; | 406 | dev->autosuspend_delay = usb_autosuspend_delay * HZ; |
406 | dev->connect_time = jiffies; | 407 | dev->connect_time = jiffies; |
407 | dev->active_duration = -jiffies; | 408 | dev->active_duration = -jiffies; |
@@ -513,10 +514,7 @@ EXPORT_SYMBOL_GPL(usb_put_intf); | |||
513 | * disconnect; in some drivers (such as usb-storage) the disconnect() | 514 | * disconnect; in some drivers (such as usb-storage) the disconnect() |
514 | * or suspend() method will block waiting for a device reset to complete. | 515 | * or suspend() method will block waiting for a device reset to complete. |
515 | * | 516 | * |
516 | * Returns a negative error code for failure, otherwise 1 or 0 to indicate | 517 | * Returns a negative error code for failure, otherwise 0. |
517 | * that the device will or will not have to be unlocked. (0 can be | ||
518 | * returned when an interface is given and is BINDING, because in that | ||
519 | * case the driver already owns the device lock.) | ||
520 | */ | 518 | */ |
521 | int usb_lock_device_for_reset(struct usb_device *udev, | 519 | int usb_lock_device_for_reset(struct usb_device *udev, |
522 | const struct usb_interface *iface) | 520 | const struct usb_interface *iface) |
@@ -527,16 +525,9 @@ int usb_lock_device_for_reset(struct usb_device *udev, | |||
527 | return -ENODEV; | 525 | return -ENODEV; |
528 | if (udev->state == USB_STATE_SUSPENDED) | 526 | if (udev->state == USB_STATE_SUSPENDED) |
529 | return -EHOSTUNREACH; | 527 | return -EHOSTUNREACH; |
530 | if (iface) { | 528 | if (iface && (iface->condition == USB_INTERFACE_UNBINDING || |
531 | switch (iface->condition) { | 529 | iface->condition == USB_INTERFACE_UNBOUND)) |
532 | case USB_INTERFACE_BINDING: | 530 | return -EINTR; |
533 | return 0; | ||
534 | case USB_INTERFACE_BOUND: | ||
535 | break; | ||
536 | default: | ||
537 | return -EINTR; | ||
538 | } | ||
539 | } | ||
540 | 531 | ||
541 | while (usb_trylock_device(udev) != 0) { | 532 | while (usb_trylock_device(udev) != 0) { |
542 | 533 | ||
@@ -550,10 +541,11 @@ int usb_lock_device_for_reset(struct usb_device *udev, | |||
550 | return -ENODEV; | 541 | return -ENODEV; |
551 | if (udev->state == USB_STATE_SUSPENDED) | 542 | if (udev->state == USB_STATE_SUSPENDED) |
552 | return -EHOSTUNREACH; | 543 | return -EHOSTUNREACH; |
553 | if (iface && iface->condition != USB_INTERFACE_BOUND) | 544 | if (iface && (iface->condition == USB_INTERFACE_UNBINDING || |
545 | iface->condition == USB_INTERFACE_UNBOUND)) | ||
554 | return -EINTR; | 546 | return -EINTR; |
555 | } | 547 | } |
556 | return 1; | 548 | return 0; |
557 | } | 549 | } |
558 | EXPORT_SYMBOL_GPL(usb_lock_device_for_reset); | 550 | EXPORT_SYMBOL_GPL(usb_lock_device_for_reset); |
559 | 551 | ||
@@ -962,8 +954,12 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in, | |||
962 | } | 954 | } |
963 | EXPORT_SYMBOL_GPL(usb_buffer_unmap_sg); | 955 | EXPORT_SYMBOL_GPL(usb_buffer_unmap_sg); |
964 | 956 | ||
965 | /* format to disable USB on kernel command line is: nousb */ | 957 | /* To disable USB, kernel command line is 'nousb' not 'usbcore.nousb' */ |
966 | __module_param_call("", nousb, param_set_bool, param_get_bool, &nousb, 0444); | 958 | #ifdef MODULE |
959 | module_param(nousb, bool, 0444); | ||
960 | #else | ||
961 | core_param(nousb, nousb, bool, 0444); | ||
962 | #endif | ||
967 | 963 | ||
968 | /* | 964 | /* |
969 | * for external read access to <nousb> | 965 | * for external read access to <nousb> |
@@ -975,6 +971,37 @@ int usb_disabled(void) | |||
975 | EXPORT_SYMBOL_GPL(usb_disabled); | 971 | EXPORT_SYMBOL_GPL(usb_disabled); |
976 | 972 | ||
977 | /* | 973 | /* |
974 | * Notifications of device and interface registration | ||
975 | */ | ||
976 | static int usb_bus_notify(struct notifier_block *nb, unsigned long action, | ||
977 | void *data) | ||
978 | { | ||
979 | struct device *dev = data; | ||
980 | |||
981 | switch (action) { | ||
982 | case BUS_NOTIFY_ADD_DEVICE: | ||
983 | if (dev->type == &usb_device_type) | ||
984 | (void) usb_create_sysfs_dev_files(to_usb_device(dev)); | ||
985 | else if (dev->type == &usb_if_device_type) | ||
986 | (void) usb_create_sysfs_intf_files( | ||
987 | to_usb_interface(dev)); | ||
988 | break; | ||
989 | |||
990 | case BUS_NOTIFY_DEL_DEVICE: | ||
991 | if (dev->type == &usb_device_type) | ||
992 | usb_remove_sysfs_dev_files(to_usb_device(dev)); | ||
993 | else if (dev->type == &usb_if_device_type) | ||
994 | usb_remove_sysfs_intf_files(to_usb_interface(dev)); | ||
995 | break; | ||
996 | } | ||
997 | return 0; | ||
998 | } | ||
999 | |||
1000 | static struct notifier_block usb_bus_nb = { | ||
1001 | .notifier_call = usb_bus_notify, | ||
1002 | }; | ||
1003 | |||
1004 | /* | ||
978 | * Init | 1005 | * Init |
979 | */ | 1006 | */ |
980 | static int __init usb_init(void) | 1007 | static int __init usb_init(void) |
@@ -991,6 +1018,9 @@ static int __init usb_init(void) | |||
991 | retval = bus_register(&usb_bus_type); | 1018 | retval = bus_register(&usb_bus_type); |
992 | if (retval) | 1019 | if (retval) |
993 | goto bus_register_failed; | 1020 | goto bus_register_failed; |
1021 | retval = bus_register_notifier(&usb_bus_type, &usb_bus_nb); | ||
1022 | if (retval) | ||
1023 | goto bus_notifier_failed; | ||
994 | retval = usb_host_init(); | 1024 | retval = usb_host_init(); |
995 | if (retval) | 1025 | if (retval) |
996 | goto host_init_failed; | 1026 | goto host_init_failed; |
@@ -1025,6 +1055,8 @@ driver_register_failed: | |||
1025 | major_init_failed: | 1055 | major_init_failed: |
1026 | usb_host_cleanup(); | 1056 | usb_host_cleanup(); |
1027 | host_init_failed: | 1057 | host_init_failed: |
1058 | bus_unregister_notifier(&usb_bus_type, &usb_bus_nb); | ||
1059 | bus_notifier_failed: | ||
1028 | bus_unregister(&usb_bus_type); | 1060 | bus_unregister(&usb_bus_type); |
1029 | bus_register_failed: | 1061 | bus_register_failed: |
1030 | ksuspend_usb_cleanup(); | 1062 | ksuspend_usb_cleanup(); |
@@ -1048,6 +1080,7 @@ static void __exit usb_exit(void) | |||
1048 | usb_devio_cleanup(); | 1080 | usb_devio_cleanup(); |
1049 | usb_hub_cleanup(); | 1081 | usb_hub_cleanup(); |
1050 | usb_host_cleanup(); | 1082 | usb_host_cleanup(); |
1083 | bus_unregister_notifier(&usb_bus_type, &usb_bus_nb); | ||
1051 | bus_unregister(&usb_bus_type); | 1084 | bus_unregister(&usb_bus_type); |
1052 | ksuspend_usb_cleanup(); | 1085 | ksuspend_usb_cleanup(); |
1053 | } | 1086 | } |
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index 9a1a45ac3add..386177867a8a 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -1,16 +1,20 @@ | |||
1 | #include <linux/pm.h> | ||
2 | |||
1 | /* Functions local to drivers/usb/core/ */ | 3 | /* Functions local to drivers/usb/core/ */ |
2 | 4 | ||
3 | extern int usb_create_sysfs_dev_files(struct usb_device *dev); | 5 | extern int usb_create_sysfs_dev_files(struct usb_device *dev); |
4 | extern void usb_remove_sysfs_dev_files(struct usb_device *dev); | 6 | extern void usb_remove_sysfs_dev_files(struct usb_device *dev); |
5 | extern int usb_create_sysfs_intf_files(struct usb_interface *intf); | 7 | extern int usb_create_sysfs_intf_files(struct usb_interface *intf); |
6 | extern void usb_remove_sysfs_intf_files(struct usb_interface *intf); | 8 | extern void usb_remove_sysfs_intf_files(struct usb_interface *intf); |
7 | extern int usb_create_ep_files(struct device *parent, | 9 | extern int usb_create_ep_devs(struct device *parent, |
8 | struct usb_host_endpoint *endpoint, | 10 | struct usb_host_endpoint *endpoint, |
9 | struct usb_device *udev); | 11 | struct usb_device *udev); |
10 | extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint); | 12 | extern void usb_remove_ep_devs(struct usb_host_endpoint *endpoint); |
11 | 13 | ||
12 | extern void usb_enable_endpoint(struct usb_device *dev, | 14 | extern void usb_enable_endpoint(struct usb_device *dev, |
13 | struct usb_host_endpoint *ep); | 15 | struct usb_host_endpoint *ep, bool reset_toggle); |
16 | extern void usb_enable_interface(struct usb_device *dev, | ||
17 | struct usb_interface *intf, bool reset_toggles); | ||
14 | extern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr); | 18 | extern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr); |
15 | extern void usb_disable_interface(struct usb_device *dev, | 19 | extern void usb_disable_interface(struct usb_device *dev, |
16 | struct usb_interface *intf); | 20 | struct usb_interface *intf); |
@@ -42,14 +46,16 @@ extern void usb_host_cleanup(void); | |||
42 | #ifdef CONFIG_PM | 46 | #ifdef CONFIG_PM |
43 | 47 | ||
44 | extern int usb_suspend(struct device *dev, pm_message_t msg); | 48 | extern int usb_suspend(struct device *dev, pm_message_t msg); |
45 | extern int usb_resume(struct device *dev); | 49 | extern int usb_resume(struct device *dev, pm_message_t msg); |
46 | 50 | ||
47 | extern void usb_autosuspend_work(struct work_struct *work); | 51 | extern void usb_autosuspend_work(struct work_struct *work); |
48 | extern int usb_port_suspend(struct usb_device *dev); | 52 | extern void usb_autoresume_work(struct work_struct *work); |
49 | extern int usb_port_resume(struct usb_device *dev); | 53 | extern int usb_port_suspend(struct usb_device *dev, pm_message_t msg); |
54 | extern int usb_port_resume(struct usb_device *dev, pm_message_t msg); | ||
50 | extern int usb_external_suspend_device(struct usb_device *udev, | 55 | extern int usb_external_suspend_device(struct usb_device *udev, |
51 | pm_message_t msg); | 56 | pm_message_t msg); |
52 | extern int usb_external_resume_device(struct usb_device *udev); | 57 | extern int usb_external_resume_device(struct usb_device *udev, |
58 | pm_message_t msg); | ||
53 | 59 | ||
54 | static inline void usb_pm_lock(struct usb_device *udev) | 60 | static inline void usb_pm_lock(struct usb_device *udev) |
55 | { | 61 | { |
@@ -63,12 +69,12 @@ static inline void usb_pm_unlock(struct usb_device *udev) | |||
63 | 69 | ||
64 | #else | 70 | #else |
65 | 71 | ||
66 | static inline int usb_port_suspend(struct usb_device *udev) | 72 | static inline int usb_port_suspend(struct usb_device *udev, pm_message_t msg) |
67 | { | 73 | { |
68 | return 0; | 74 | return 0; |
69 | } | 75 | } |
70 | 76 | ||
71 | static inline int usb_port_resume(struct usb_device *udev) | 77 | static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg) |
72 | { | 78 | { |
73 | return 0; | 79 | return 0; |
74 | } | 80 | } |
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index dd4cd5a51370..3219d137340a 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -297,13 +297,34 @@ config USB_S3C2410_DEBUG | |||
297 | 297 | ||
298 | # musb builds in ../musb along with host support | 298 | # musb builds in ../musb along with host support |
299 | config USB_GADGET_MUSB_HDRC | 299 | config USB_GADGET_MUSB_HDRC |
300 | boolean "Inventra HDRC USB Peripheral (TI, ...)" | 300 | boolean "Inventra HDRC USB Peripheral (TI, ADI, ...)" |
301 | depends on USB_MUSB_HDRC && (USB_MUSB_PERIPHERAL || USB_MUSB_OTG) | 301 | depends on USB_MUSB_HDRC && (USB_MUSB_PERIPHERAL || USB_MUSB_OTG) |
302 | select USB_GADGET_DUALSPEED | 302 | select USB_GADGET_DUALSPEED |
303 | select USB_GADGET_SELECTED | 303 | select USB_GADGET_SELECTED |
304 | help | 304 | help |
305 | This OTG-capable silicon IP is used in dual designs including | 305 | This OTG-capable silicon IP is used in dual designs including |
306 | the TI DaVinci, OMAP 243x, OMAP 343x, and TUSB 6010. | 306 | the TI DaVinci, OMAP 243x, OMAP 343x, TUSB 6010, and ADI Blackfin |
307 | |||
308 | config USB_GADGET_IMX | ||
309 | boolean "Freescale IMX USB Peripheral Controller" | ||
310 | depends on ARCH_MX1 | ||
311 | help | ||
312 | Freescale's IMX series include an integrated full speed | ||
313 | USB 1.1 device controller. The controller in the IMX series | ||
314 | is register-compatible. | ||
315 | |||
316 | It has Six fixed-function endpoints, as well as endpoint | ||
317 | zero (for control transfers). | ||
318 | |||
319 | Say "y" to link the driver statically, or "m" to build a | ||
320 | dynamically linked module called "imx_udc" and force all | ||
321 | gadget drivers to also be dynamically linked. | ||
322 | |||
323 | config USB_IMX | ||
324 | tristate | ||
325 | depends on USB_GADGET_IMX | ||
326 | default USB_GADGET | ||
327 | select USB_GADGET_SELECTED | ||
307 | 328 | ||
308 | config USB_GADGET_M66592 | 329 | config USB_GADGET_M66592 |
309 | boolean "Renesas M66592 USB Peripheral Controller" | 330 | boolean "Renesas M66592 USB Peripheral Controller" |
@@ -377,6 +398,24 @@ config USB_FSL_QE | |||
377 | default USB_GADGET | 398 | default USB_GADGET |
378 | select USB_GADGET_SELECTED | 399 | select USB_GADGET_SELECTED |
379 | 400 | ||
401 | config USB_GADGET_CI13XXX | ||
402 | boolean "MIPS USB CI13xxx" | ||
403 | depends on PCI | ||
404 | select USB_GADGET_DUALSPEED | ||
405 | help | ||
406 | MIPS USB IP core family device controller | ||
407 | Currently it only supports IP part number CI13412 | ||
408 | |||
409 | Say "y" to link the driver statically, or "m" to build a | ||
410 | dynamically linked module called "ci13xxx_udc" and force all | ||
411 | gadget drivers to also be dynamically linked. | ||
412 | |||
413 | config USB_CI13XXX | ||
414 | tristate | ||
415 | depends on USB_GADGET_CI13XXX | ||
416 | default USB_GADGET | ||
417 | select USB_GADGET_SELECTED | ||
418 | |||
380 | config USB_GADGET_NET2280 | 419 | config USB_GADGET_NET2280 |
381 | boolean "NetChip 228x" | 420 | boolean "NetChip 228x" |
382 | depends on PCI | 421 | depends on PCI |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index bd4041b47dce..39a51d746cb7 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -10,6 +10,7 @@ obj-$(CONFIG_USB_NET2280) += net2280.o | |||
10 | obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o | 10 | obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o |
11 | obj-$(CONFIG_USB_PXA25X) += pxa25x_udc.o | 11 | obj-$(CONFIG_USB_PXA25X) += pxa25x_udc.o |
12 | obj-$(CONFIG_USB_PXA27X) += pxa27x_udc.o | 12 | obj-$(CONFIG_USB_PXA27X) += pxa27x_udc.o |
13 | obj-$(CONFIG_USB_IMX) += imx_udc.o | ||
13 | obj-$(CONFIG_USB_GOKU) += goku_udc.o | 14 | obj-$(CONFIG_USB_GOKU) += goku_udc.o |
14 | obj-$(CONFIG_USB_OMAP) += omap_udc.o | 15 | obj-$(CONFIG_USB_OMAP) += omap_udc.o |
15 | obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o | 16 | obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o |
@@ -19,6 +20,7 @@ obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o | |||
19 | obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o | 20 | obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o |
20 | obj-$(CONFIG_USB_M66592) += m66592-udc.o | 21 | obj-$(CONFIG_USB_M66592) += m66592-udc.o |
21 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o | 22 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o |
23 | obj-$(CONFIG_USB_CI13XXX) += ci13xxx_udc.o | ||
22 | 24 | ||
23 | # | 25 | # |
24 | # USB gadget drivers | 26 | # USB gadget drivers |
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c new file mode 100644 index 000000000000..bebf911c7e5f --- /dev/null +++ b/drivers/usb/gadget/ci13xxx_udc.c | |||
@@ -0,0 +1,2830 @@ | |||
1 | /* | ||
2 | * ci13xxx_udc.c - MIPS USB IP core family device controller | ||
3 | * | ||
4 | * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. | ||
5 | * | ||
6 | * Author: David Lopo | ||
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 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * Description: MIPS USB IP core family device controller | ||
15 | * Currently it only supports IP part number CI13412 | ||
16 | * | ||
17 | * This driver is composed of several blocks: | ||
18 | * - HW: hardware interface | ||
19 | * - DBG: debug facilities (optional) | ||
20 | * - UTIL: utilities | ||
21 | * - ISR: interrupts handling | ||
22 | * - ENDPT: endpoint operations (Gadget API) | ||
23 | * - GADGET: gadget operations (Gadget API) | ||
24 | * - BUS: bus glue code, bus abstraction layer | ||
25 | * - PCI: PCI core interface and PCI resources (interrupts, memory...) | ||
26 | * | ||
27 | * Compile Options | ||
28 | * - CONFIG_USB_GADGET_DEBUG_FILES: enable debug facilities | ||
29 | * - STALL_IN: non-empty bulk-in pipes cannot be halted | ||
30 | * if defined mass storage compliance succeeds but with warnings | ||
31 | * => case 4: Hi > Dn | ||
32 | * => case 5: Hi > Di | ||
33 | * => case 8: Hi <> Do | ||
34 | * if undefined usbtest 13 fails | ||
35 | * - TRACE: enable function tracing (depends on DEBUG) | ||
36 | * | ||
37 | * Main Features | ||
38 | * - Chapter 9 & Mass Storage Compliance with Gadget File Storage | ||
39 | * - Chapter 9 Compliance with Gadget Zero (STALL_IN undefined) | ||
40 | * - Normal & LPM support | ||
41 | * | ||
42 | * USBTEST Report | ||
43 | * - OK: 0-12, 13 (STALL_IN defined) & 14 | ||
44 | * - Not Supported: 15 & 16 (ISO) | ||
45 | * | ||
46 | * TODO List | ||
47 | * - OTG | ||
48 | * - Isochronous & Interrupt Traffic | ||
49 | * - Handle requests which spawns into several TDs | ||
50 | * - GET_STATUS(device) - always reports 0 | ||
51 | * - Gadget API (majority of optional features) | ||
52 | * - Suspend & Remote Wakeup | ||
53 | */ | ||
54 | #include <linux/device.h> | ||
55 | #include <linux/dmapool.h> | ||
56 | #include <linux/dma-mapping.h> | ||
57 | #include <linux/init.h> | ||
58 | #include <linux/interrupt.h> | ||
59 | #include <linux/interrupt.h> | ||
60 | #include <linux/io.h> | ||
61 | #include <linux/irq.h> | ||
62 | #include <linux/kernel.h> | ||
63 | #include <linux/module.h> | ||
64 | #include <linux/pci.h> | ||
65 | #include <linux/usb/ch9.h> | ||
66 | #include <linux/usb/gadget.h> | ||
67 | |||
68 | #include "ci13xxx_udc.h" | ||
69 | |||
70 | |||
71 | /****************************************************************************** | ||
72 | * DEFINE | ||
73 | *****************************************************************************/ | ||
74 | /* ctrl register bank access */ | ||
75 | static DEFINE_SPINLOCK(udc_lock); | ||
76 | |||
77 | /* driver name */ | ||
78 | #define UDC_DRIVER_NAME "ci13xxx_udc" | ||
79 | |||
80 | /* control endpoint description */ | ||
81 | static const struct usb_endpoint_descriptor | ||
82 | ctrl_endpt_desc = { | ||
83 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
84 | .bDescriptorType = USB_DT_ENDPOINT, | ||
85 | |||
86 | .bmAttributes = USB_ENDPOINT_XFER_CONTROL, | ||
87 | .wMaxPacketSize = cpu_to_le16(CTRL_PAYLOAD_MAX), | ||
88 | }; | ||
89 | |||
90 | /* UDC descriptor */ | ||
91 | static struct ci13xxx *_udc; | ||
92 | |||
93 | /* Interrupt statistics */ | ||
94 | #define ISR_MASK 0x1F | ||
95 | static struct { | ||
96 | u32 test; | ||
97 | u32 ui; | ||
98 | u32 uei; | ||
99 | u32 pci; | ||
100 | u32 uri; | ||
101 | u32 sli; | ||
102 | u32 none; | ||
103 | struct { | ||
104 | u32 cnt; | ||
105 | u32 buf[ISR_MASK+1]; | ||
106 | u32 idx; | ||
107 | } hndl; | ||
108 | } isr_statistics; | ||
109 | |||
110 | /** | ||
111 | * ffs_nr: find first (least significant) bit set | ||
112 | * @x: the word to search | ||
113 | * | ||
114 | * This function returns bit number (instead of position) | ||
115 | */ | ||
116 | static int ffs_nr(u32 x) | ||
117 | { | ||
118 | int n = ffs(x); | ||
119 | |||
120 | return n ? n-1 : 32; | ||
121 | } | ||
122 | |||
123 | /****************************************************************************** | ||
124 | * HW block | ||
125 | *****************************************************************************/ | ||
126 | /* register bank descriptor */ | ||
127 | static struct { | ||
128 | unsigned lpm; /* is LPM? */ | ||
129 | void __iomem *abs; /* bus map offset */ | ||
130 | void __iomem *cap; /* bus map offset + CAP offset + CAP data */ | ||
131 | size_t size; /* bank size */ | ||
132 | } hw_bank; | ||
133 | |||
134 | /* UDC register map */ | ||
135 | #define ABS_CAPLENGTH (0x100UL) | ||
136 | #define ABS_HCCPARAMS (0x108UL) | ||
137 | #define ABS_DCCPARAMS (0x124UL) | ||
138 | #define ABS_TESTMODE (hw_bank.lpm ? 0x0FCUL : 0x138UL) | ||
139 | /* offset to CAPLENTGH (addr + data) */ | ||
140 | #define CAP_USBCMD (0x000UL) | ||
141 | #define CAP_USBSTS (0x004UL) | ||
142 | #define CAP_USBINTR (0x008UL) | ||
143 | #define CAP_DEVICEADDR (0x014UL) | ||
144 | #define CAP_ENDPTLISTADDR (0x018UL) | ||
145 | #define CAP_PORTSC (0x044UL) | ||
146 | #define CAP_DEVLC (0x0B4UL) | ||
147 | #define CAP_USBMODE (hw_bank.lpm ? 0x0C8UL : 0x068UL) | ||
148 | #define CAP_ENDPTSETUPSTAT (hw_bank.lpm ? 0x0D8UL : 0x06CUL) | ||
149 | #define CAP_ENDPTPRIME (hw_bank.lpm ? 0x0DCUL : 0x070UL) | ||
150 | #define CAP_ENDPTFLUSH (hw_bank.lpm ? 0x0E0UL : 0x074UL) | ||
151 | #define CAP_ENDPTSTAT (hw_bank.lpm ? 0x0E4UL : 0x078UL) | ||
152 | #define CAP_ENDPTCOMPLETE (hw_bank.lpm ? 0x0E8UL : 0x07CUL) | ||
153 | #define CAP_ENDPTCTRL (hw_bank.lpm ? 0x0ECUL : 0x080UL) | ||
154 | #define CAP_LAST (hw_bank.lpm ? 0x12CUL : 0x0C0UL) | ||
155 | |||
156 | /* maximum number of enpoints: valid only after hw_device_reset() */ | ||
157 | static unsigned hw_ep_max; | ||
158 | |||
159 | /** | ||
160 | * hw_ep_bit: calculates the bit number | ||
161 | * @num: endpoint number | ||
162 | * @dir: endpoint direction | ||
163 | * | ||
164 | * This function returns bit number | ||
165 | */ | ||
166 | static inline int hw_ep_bit(int num, int dir) | ||
167 | { | ||
168 | return num + (dir ? 16 : 0); | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * hw_aread: reads from register bitfield | ||
173 | * @addr: address relative to bus map | ||
174 | * @mask: bitfield mask | ||
175 | * | ||
176 | * This function returns register bitfield data | ||
177 | */ | ||
178 | static u32 hw_aread(u32 addr, u32 mask) | ||
179 | { | ||
180 | return ioread32(addr + hw_bank.abs) & mask; | ||
181 | } | ||
182 | |||
183 | /** | ||
184 | * hw_awrite: writes to register bitfield | ||
185 | * @addr: address relative to bus map | ||
186 | * @mask: bitfield mask | ||
187 | * @data: new data | ||
188 | */ | ||
189 | static void hw_awrite(u32 addr, u32 mask, u32 data) | ||
190 | { | ||
191 | iowrite32(hw_aread(addr, ~mask) | (data & mask), | ||
192 | addr + hw_bank.abs); | ||
193 | } | ||
194 | |||
195 | /** | ||
196 | * hw_cread: reads from register bitfield | ||
197 | * @addr: address relative to CAP offset plus content | ||
198 | * @mask: bitfield mask | ||
199 | * | ||
200 | * This function returns register bitfield data | ||
201 | */ | ||
202 | static u32 hw_cread(u32 addr, u32 mask) | ||
203 | { | ||
204 | return ioread32(addr + hw_bank.cap) & mask; | ||
205 | } | ||
206 | |||
207 | /** | ||
208 | * hw_cwrite: writes to register bitfield | ||
209 | * @addr: address relative to CAP offset plus content | ||
210 | * @mask: bitfield mask | ||
211 | * @data: new data | ||
212 | */ | ||
213 | static void hw_cwrite(u32 addr, u32 mask, u32 data) | ||
214 | { | ||
215 | iowrite32(hw_cread(addr, ~mask) | (data & mask), | ||
216 | addr + hw_bank.cap); | ||
217 | } | ||
218 | |||
219 | /** | ||
220 | * hw_ctest_and_clear: tests & clears register bitfield | ||
221 | * @addr: address relative to CAP offset plus content | ||
222 | * @mask: bitfield mask | ||
223 | * | ||
224 | * This function returns register bitfield data | ||
225 | */ | ||
226 | static u32 hw_ctest_and_clear(u32 addr, u32 mask) | ||
227 | { | ||
228 | u32 reg = hw_cread(addr, mask); | ||
229 | |||
230 | iowrite32(reg, addr + hw_bank.cap); | ||
231 | return reg; | ||
232 | } | ||
233 | |||
234 | /** | ||
235 | * hw_ctest_and_write: tests & writes register bitfield | ||
236 | * @addr: address relative to CAP offset plus content | ||
237 | * @mask: bitfield mask | ||
238 | * @data: new data | ||
239 | * | ||
240 | * This function returns register bitfield data | ||
241 | */ | ||
242 | static u32 hw_ctest_and_write(u32 addr, u32 mask, u32 data) | ||
243 | { | ||
244 | u32 reg = hw_cread(addr, ~0); | ||
245 | |||
246 | iowrite32((reg & ~mask) | (data & mask), addr + hw_bank.cap); | ||
247 | return (reg & mask) >> ffs_nr(mask); | ||
248 | } | ||
249 | |||
250 | /** | ||
251 | * hw_device_reset: resets chip (execute without interruption) | ||
252 | * @base: register base address | ||
253 | * | ||
254 | * This function returns an error code | ||
255 | */ | ||
256 | static int hw_device_reset(void __iomem *base) | ||
257 | { | ||
258 | u32 reg; | ||
259 | |||
260 | /* bank is a module variable */ | ||
261 | hw_bank.abs = base; | ||
262 | |||
263 | hw_bank.cap = hw_bank.abs; | ||
264 | hw_bank.cap += ABS_CAPLENGTH; | ||
265 | hw_bank.cap += ioread8(hw_bank.cap); | ||
266 | |||
267 | reg = hw_aread(ABS_HCCPARAMS, HCCPARAMS_LEN) >> ffs_nr(HCCPARAMS_LEN); | ||
268 | hw_bank.lpm = reg; | ||
269 | hw_bank.size = hw_bank.cap - hw_bank.abs; | ||
270 | hw_bank.size += CAP_LAST; | ||
271 | hw_bank.size /= sizeof(u32); | ||
272 | |||
273 | /* should flush & stop before reset */ | ||
274 | hw_cwrite(CAP_ENDPTFLUSH, ~0, ~0); | ||
275 | hw_cwrite(CAP_USBCMD, USBCMD_RS, 0); | ||
276 | |||
277 | hw_cwrite(CAP_USBCMD, USBCMD_RST, USBCMD_RST); | ||
278 | while (hw_cread(CAP_USBCMD, USBCMD_RST)) | ||
279 | udelay(10); /* not RTOS friendly */ | ||
280 | |||
281 | /* USBMODE should be configured step by step */ | ||
282 | hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); | ||
283 | hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_DEVICE); | ||
284 | hw_cwrite(CAP_USBMODE, USBMODE_SLOM, USBMODE_SLOM); /* HW >= 2.3 */ | ||
285 | |||
286 | if (hw_cread(CAP_USBMODE, USBMODE_CM) != USBMODE_CM_DEVICE) { | ||
287 | pr_err("cannot enter in device mode"); | ||
288 | pr_err("lpm = %i", hw_bank.lpm); | ||
289 | return -ENODEV; | ||
290 | } | ||
291 | |||
292 | reg = hw_aread(ABS_DCCPARAMS, DCCPARAMS_DEN) >> ffs_nr(DCCPARAMS_DEN); | ||
293 | if (reg == 0 || reg > ENDPT_MAX) | ||
294 | return -ENODEV; | ||
295 | |||
296 | hw_ep_max = reg; /* cache hw ENDPT_MAX */ | ||
297 | |||
298 | /* setup lock mode ? */ | ||
299 | |||
300 | /* ENDPTSETUPSTAT is '0' by default */ | ||
301 | |||
302 | /* HCSPARAMS.bf.ppc SHOULD BE zero for device */ | ||
303 | |||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * hw_device_state: enables/disables interrupts & starts/stops device (execute | ||
309 | * without interruption) | ||
310 | * @dma: 0 => disable, !0 => enable and set dma engine | ||
311 | * | ||
312 | * This function returns an error code | ||
313 | */ | ||
314 | static int hw_device_state(u32 dma) | ||
315 | { | ||
316 | if (dma) { | ||
317 | hw_cwrite(CAP_ENDPTLISTADDR, ~0, dma); | ||
318 | /* interrupt, error, port change, reset, sleep/suspend */ | ||
319 | hw_cwrite(CAP_USBINTR, ~0, | ||
320 | USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); | ||
321 | hw_cwrite(CAP_USBCMD, USBCMD_RS, USBCMD_RS); | ||
322 | } else { | ||
323 | hw_cwrite(CAP_USBCMD, USBCMD_RS, 0); | ||
324 | hw_cwrite(CAP_USBINTR, ~0, 0); | ||
325 | } | ||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | /** | ||
330 | * hw_ep_flush: flush endpoint fifo (execute without interruption) | ||
331 | * @num: endpoint number | ||
332 | * @dir: endpoint direction | ||
333 | * | ||
334 | * This function returns an error code | ||
335 | */ | ||
336 | static int hw_ep_flush(int num, int dir) | ||
337 | { | ||
338 | int n = hw_ep_bit(num, dir); | ||
339 | |||
340 | do { | ||
341 | /* flush any pending transfer */ | ||
342 | hw_cwrite(CAP_ENDPTFLUSH, BIT(n), BIT(n)); | ||
343 | while (hw_cread(CAP_ENDPTFLUSH, BIT(n))) | ||
344 | cpu_relax(); | ||
345 | } while (hw_cread(CAP_ENDPTSTAT, BIT(n))); | ||
346 | |||
347 | return 0; | ||
348 | } | ||
349 | |||
350 | /** | ||
351 | * hw_ep_disable: disables endpoint (execute without interruption) | ||
352 | * @num: endpoint number | ||
353 | * @dir: endpoint direction | ||
354 | * | ||
355 | * This function returns an error code | ||
356 | */ | ||
357 | static int hw_ep_disable(int num, int dir) | ||
358 | { | ||
359 | hw_ep_flush(num, dir); | ||
360 | hw_cwrite(CAP_ENDPTCTRL + num * sizeof(u32), | ||
361 | dir ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0); | ||
362 | return 0; | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * hw_ep_enable: enables endpoint (execute without interruption) | ||
367 | * @num: endpoint number | ||
368 | * @dir: endpoint direction | ||
369 | * @type: endpoint type | ||
370 | * | ||
371 | * This function returns an error code | ||
372 | */ | ||
373 | static int hw_ep_enable(int num, int dir, int type) | ||
374 | { | ||
375 | u32 mask, data; | ||
376 | |||
377 | if (dir) { | ||
378 | mask = ENDPTCTRL_TXT; /* type */ | ||
379 | data = type << ffs_nr(mask); | ||
380 | |||
381 | mask |= ENDPTCTRL_TXS; /* unstall */ | ||
382 | mask |= ENDPTCTRL_TXR; /* reset data toggle */ | ||
383 | data |= ENDPTCTRL_TXR; | ||
384 | mask |= ENDPTCTRL_TXE; /* enable */ | ||
385 | data |= ENDPTCTRL_TXE; | ||
386 | } else { | ||
387 | mask = ENDPTCTRL_RXT; /* type */ | ||
388 | data = type << ffs_nr(mask); | ||
389 | |||
390 | mask |= ENDPTCTRL_RXS; /* unstall */ | ||
391 | mask |= ENDPTCTRL_RXR; /* reset data toggle */ | ||
392 | data |= ENDPTCTRL_RXR; | ||
393 | mask |= ENDPTCTRL_RXE; /* enable */ | ||
394 | data |= ENDPTCTRL_RXE; | ||
395 | } | ||
396 | hw_cwrite(CAP_ENDPTCTRL + num * sizeof(u32), mask, data); | ||
397 | return 0; | ||
398 | } | ||
399 | |||
400 | /** | ||
401 | * hw_ep_get_halt: return endpoint halt status | ||
402 | * @num: endpoint number | ||
403 | * @dir: endpoint direction | ||
404 | * | ||
405 | * This function returns 1 if endpoint halted | ||
406 | */ | ||
407 | static int hw_ep_get_halt(int num, int dir) | ||
408 | { | ||
409 | u32 mask = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; | ||
410 | |||
411 | return hw_cread(CAP_ENDPTCTRL + num * sizeof(u32), mask) ? 1 : 0; | ||
412 | } | ||
413 | |||
414 | /** | ||
415 | * hw_ep_is_primed: test if endpoint is primed (execute without interruption) | ||
416 | * @num: endpoint number | ||
417 | * @dir: endpoint direction | ||
418 | * | ||
419 | * This function returns true if endpoint primed | ||
420 | */ | ||
421 | static int hw_ep_is_primed(int num, int dir) | ||
422 | { | ||
423 | u32 reg = hw_cread(CAP_ENDPTPRIME, ~0) | hw_cread(CAP_ENDPTSTAT, ~0); | ||
424 | |||
425 | return test_bit(hw_ep_bit(num, dir), (void *)®); | ||
426 | } | ||
427 | |||
428 | /** | ||
429 | * hw_test_and_clear_setup_status: test & clear setup status (execute without | ||
430 | * interruption) | ||
431 | * @n: bit number (endpoint) | ||
432 | * | ||
433 | * This function returns setup status | ||
434 | */ | ||
435 | static int hw_test_and_clear_setup_status(int n) | ||
436 | { | ||
437 | return hw_ctest_and_clear(CAP_ENDPTSETUPSTAT, BIT(n)); | ||
438 | } | ||
439 | |||
440 | /** | ||
441 | * hw_ep_prime: primes endpoint (execute without interruption) | ||
442 | * @num: endpoint number | ||
443 | * @dir: endpoint direction | ||
444 | * @is_ctrl: true if control endpoint | ||
445 | * | ||
446 | * This function returns an error code | ||
447 | */ | ||
448 | static int hw_ep_prime(int num, int dir, int is_ctrl) | ||
449 | { | ||
450 | int n = hw_ep_bit(num, dir); | ||
451 | |||
452 | /* the caller should flush first */ | ||
453 | if (hw_ep_is_primed(num, dir)) | ||
454 | return -EBUSY; | ||
455 | |||
456 | if (is_ctrl && dir == RX && hw_cread(CAP_ENDPTSETUPSTAT, BIT(num))) | ||
457 | return -EAGAIN; | ||
458 | |||
459 | hw_cwrite(CAP_ENDPTPRIME, BIT(n), BIT(n)); | ||
460 | |||
461 | while (hw_cread(CAP_ENDPTPRIME, BIT(n))) | ||
462 | cpu_relax(); | ||
463 | if (is_ctrl && dir == RX && hw_cread(CAP_ENDPTSETUPSTAT, BIT(num))) | ||
464 | return -EAGAIN; | ||
465 | |||
466 | /* status shoult be tested according with manual but it doesn't work */ | ||
467 | return 0; | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * hw_ep_set_halt: configures ep halt & resets data toggle after clear (execute | ||
472 | * without interruption) | ||
473 | * @num: endpoint number | ||
474 | * @dir: endpoint direction | ||
475 | * @value: true => stall, false => unstall | ||
476 | * | ||
477 | * This function returns an error code | ||
478 | */ | ||
479 | static int hw_ep_set_halt(int num, int dir, int value) | ||
480 | { | ||
481 | if (value != 0 && value != 1) | ||
482 | return -EINVAL; | ||
483 | |||
484 | do { | ||
485 | u32 addr = CAP_ENDPTCTRL + num * sizeof(u32); | ||
486 | u32 mask_xs = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; | ||
487 | u32 mask_xr = dir ? ENDPTCTRL_TXR : ENDPTCTRL_RXR; | ||
488 | |||
489 | /* data toggle - reserved for EP0 but it's in ESS */ | ||
490 | hw_cwrite(addr, mask_xs|mask_xr, value ? mask_xs : mask_xr); | ||
491 | |||
492 | } while (value != hw_ep_get_halt(num, dir)); | ||
493 | |||
494 | return 0; | ||
495 | } | ||
496 | |||
497 | /** | ||
498 | * hw_intr_clear: disables interrupt & clears interrupt status (execute without | ||
499 | * interruption) | ||
500 | * @n: interrupt bit | ||
501 | * | ||
502 | * This function returns an error code | ||
503 | */ | ||
504 | static int hw_intr_clear(int n) | ||
505 | { | ||
506 | if (n >= REG_BITS) | ||
507 | return -EINVAL; | ||
508 | |||
509 | hw_cwrite(CAP_USBINTR, BIT(n), 0); | ||
510 | hw_cwrite(CAP_USBSTS, BIT(n), BIT(n)); | ||
511 | return 0; | ||
512 | } | ||
513 | |||
514 | /** | ||
515 | * hw_intr_force: enables interrupt & forces interrupt status (execute without | ||
516 | * interruption) | ||
517 | * @n: interrupt bit | ||
518 | * | ||
519 | * This function returns an error code | ||
520 | */ | ||
521 | static int hw_intr_force(int n) | ||
522 | { | ||
523 | if (n >= REG_BITS) | ||
524 | return -EINVAL; | ||
525 | |||
526 | hw_awrite(ABS_TESTMODE, TESTMODE_FORCE, TESTMODE_FORCE); | ||
527 | hw_cwrite(CAP_USBINTR, BIT(n), BIT(n)); | ||
528 | hw_cwrite(CAP_USBSTS, BIT(n), BIT(n)); | ||
529 | hw_awrite(ABS_TESTMODE, TESTMODE_FORCE, 0); | ||
530 | return 0; | ||
531 | } | ||
532 | |||
533 | /** | ||
534 | * hw_is_port_high_speed: test if port is high speed | ||
535 | * | ||
536 | * This function returns true if high speed port | ||
537 | */ | ||
538 | static int hw_port_is_high_speed(void) | ||
539 | { | ||
540 | return hw_bank.lpm ? hw_cread(CAP_DEVLC, DEVLC_PSPD) : | ||
541 | hw_cread(CAP_PORTSC, PORTSC_HSP); | ||
542 | } | ||
543 | |||
544 | /** | ||
545 | * hw_port_test_get: reads port test mode value | ||
546 | * | ||
547 | * This function returns port test mode value | ||
548 | */ | ||
549 | static u8 hw_port_test_get(void) | ||
550 | { | ||
551 | return hw_cread(CAP_PORTSC, PORTSC_PTC) >> ffs_nr(PORTSC_PTC); | ||
552 | } | ||
553 | |||
554 | /** | ||
555 | * hw_port_test_set: writes port test mode (execute without interruption) | ||
556 | * @mode: new value | ||
557 | * | ||
558 | * This function returns an error code | ||
559 | */ | ||
560 | static int hw_port_test_set(u8 mode) | ||
561 | { | ||
562 | const u8 TEST_MODE_MAX = 7; | ||
563 | |||
564 | if (mode > TEST_MODE_MAX) | ||
565 | return -EINVAL; | ||
566 | |||
567 | hw_cwrite(CAP_PORTSC, PORTSC_PTC, mode << ffs_nr(PORTSC_PTC)); | ||
568 | return 0; | ||
569 | } | ||
570 | |||
571 | /** | ||
572 | * hw_read_intr_enable: returns interrupt enable register | ||
573 | * | ||
574 | * This function returns register data | ||
575 | */ | ||
576 | static u32 hw_read_intr_enable(void) | ||
577 | { | ||
578 | return hw_cread(CAP_USBINTR, ~0); | ||
579 | } | ||
580 | |||
581 | /** | ||
582 | * hw_read_intr_status: returns interrupt status register | ||
583 | * | ||
584 | * This function returns register data | ||
585 | */ | ||
586 | static u32 hw_read_intr_status(void) | ||
587 | { | ||
588 | return hw_cread(CAP_USBSTS, ~0); | ||
589 | } | ||
590 | |||
591 | /** | ||
592 | * hw_register_read: reads all device registers (execute without interruption) | ||
593 | * @buf: destination buffer | ||
594 | * @size: buffer size | ||
595 | * | ||
596 | * This function returns number of registers read | ||
597 | */ | ||
598 | static size_t hw_register_read(u32 *buf, size_t size) | ||
599 | { | ||
600 | unsigned i; | ||
601 | |||
602 | if (size > hw_bank.size) | ||
603 | size = hw_bank.size; | ||
604 | |||
605 | for (i = 0; i < size; i++) | ||
606 | buf[i] = hw_aread(i * sizeof(u32), ~0); | ||
607 | |||
608 | return size; | ||
609 | } | ||
610 | |||
611 | /** | ||
612 | * hw_register_write: writes to register | ||
613 | * @addr: register address | ||
614 | * @data: register value | ||
615 | * | ||
616 | * This function returns an error code | ||
617 | */ | ||
618 | static int hw_register_write(u16 addr, u32 data) | ||
619 | { | ||
620 | /* align */ | ||
621 | addr /= sizeof(u32); | ||
622 | |||
623 | if (addr >= hw_bank.size) | ||
624 | return -EINVAL; | ||
625 | |||
626 | /* align */ | ||
627 | addr *= sizeof(u32); | ||
628 | |||
629 | hw_awrite(addr, ~0, data); | ||
630 | return 0; | ||
631 | } | ||
632 | |||
633 | /** | ||
634 | * hw_test_and_clear_complete: test & clear complete status (execute without | ||
635 | * interruption) | ||
636 | * @n: bit number (endpoint) | ||
637 | * | ||
638 | * This function returns complete status | ||
639 | */ | ||
640 | static int hw_test_and_clear_complete(int n) | ||
641 | { | ||
642 | return hw_ctest_and_clear(CAP_ENDPTCOMPLETE, BIT(n)); | ||
643 | } | ||
644 | |||
645 | /** | ||
646 | * hw_test_and_clear_intr_active: test & clear active interrupts (execute | ||
647 | * without interruption) | ||
648 | * | ||
649 | * This function returns active interrutps | ||
650 | */ | ||
651 | static u32 hw_test_and_clear_intr_active(void) | ||
652 | { | ||
653 | u32 reg = hw_read_intr_status() & hw_read_intr_enable(); | ||
654 | |||
655 | hw_cwrite(CAP_USBSTS, ~0, reg); | ||
656 | return reg; | ||
657 | } | ||
658 | |||
659 | /** | ||
660 | * hw_test_and_clear_setup_guard: test & clear setup guard (execute without | ||
661 | * interruption) | ||
662 | * | ||
663 | * This function returns guard value | ||
664 | */ | ||
665 | static int hw_test_and_clear_setup_guard(void) | ||
666 | { | ||
667 | return hw_ctest_and_write(CAP_USBCMD, USBCMD_SUTW, 0); | ||
668 | } | ||
669 | |||
670 | /** | ||
671 | * hw_test_and_set_setup_guard: test & set setup guard (execute without | ||
672 | * interruption) | ||
673 | * | ||
674 | * This function returns guard value | ||
675 | */ | ||
676 | static int hw_test_and_set_setup_guard(void) | ||
677 | { | ||
678 | return hw_ctest_and_write(CAP_USBCMD, USBCMD_SUTW, USBCMD_SUTW); | ||
679 | } | ||
680 | |||
681 | /** | ||
682 | * hw_usb_set_address: configures USB address (execute without interruption) | ||
683 | * @value: new USB address | ||
684 | * | ||
685 | * This function returns an error code | ||
686 | */ | ||
687 | static int hw_usb_set_address(u8 value) | ||
688 | { | ||
689 | /* advance */ | ||
690 | hw_cwrite(CAP_DEVICEADDR, DEVICEADDR_USBADR | DEVICEADDR_USBADRA, | ||
691 | value << ffs_nr(DEVICEADDR_USBADR) | DEVICEADDR_USBADRA); | ||
692 | return 0; | ||
693 | } | ||
694 | |||
695 | /** | ||
696 | * hw_usb_reset: restart device after a bus reset (execute without | ||
697 | * interruption) | ||
698 | * | ||
699 | * This function returns an error code | ||
700 | */ | ||
701 | static int hw_usb_reset(void) | ||
702 | { | ||
703 | hw_usb_set_address(0); | ||
704 | |||
705 | /* ESS flushes only at end?!? */ | ||
706 | hw_cwrite(CAP_ENDPTFLUSH, ~0, ~0); /* flush all EPs */ | ||
707 | |||
708 | /* clear setup token semaphores */ | ||
709 | hw_cwrite(CAP_ENDPTSETUPSTAT, 0, 0); /* writes its content */ | ||
710 | |||
711 | /* clear complete status */ | ||
712 | hw_cwrite(CAP_ENDPTCOMPLETE, 0, 0); /* writes its content */ | ||
713 | |||
714 | /* wait until all bits cleared */ | ||
715 | while (hw_cread(CAP_ENDPTPRIME, ~0)) | ||
716 | udelay(10); /* not RTOS friendly */ | ||
717 | |||
718 | /* reset all endpoints ? */ | ||
719 | |||
720 | /* reset internal status and wait for further instructions | ||
721 | no need to verify the port reset status (ESS does it) */ | ||
722 | |||
723 | return 0; | ||
724 | } | ||
725 | |||
726 | /****************************************************************************** | ||
727 | * DBG block | ||
728 | *****************************************************************************/ | ||
729 | /** | ||
730 | * show_device: prints information about device capabilities and status | ||
731 | * | ||
732 | * Check "device.h" for details | ||
733 | */ | ||
734 | static ssize_t show_device(struct device *dev, struct device_attribute *attr, | ||
735 | char *buf) | ||
736 | { | ||
737 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
738 | struct usb_gadget *gadget = &udc->gadget; | ||
739 | int n = 0; | ||
740 | |||
741 | dbg_trace("[%s] %p\n", __func__, buf); | ||
742 | if (attr == NULL || buf == NULL) { | ||
743 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
744 | return 0; | ||
745 | } | ||
746 | |||
747 | n += scnprintf(buf + n, PAGE_SIZE - n, "speed = %d\n", | ||
748 | gadget->speed); | ||
749 | n += scnprintf(buf + n, PAGE_SIZE - n, "is_dualspeed = %d\n", | ||
750 | gadget->is_dualspeed); | ||
751 | n += scnprintf(buf + n, PAGE_SIZE - n, "is_otg = %d\n", | ||
752 | gadget->is_otg); | ||
753 | n += scnprintf(buf + n, PAGE_SIZE - n, "is_a_peripheral = %d\n", | ||
754 | gadget->is_a_peripheral); | ||
755 | n += scnprintf(buf + n, PAGE_SIZE - n, "b_hnp_enable = %d\n", | ||
756 | gadget->b_hnp_enable); | ||
757 | n += scnprintf(buf + n, PAGE_SIZE - n, "a_hnp_support = %d\n", | ||
758 | gadget->a_hnp_support); | ||
759 | n += scnprintf(buf + n, PAGE_SIZE - n, "a_alt_hnp_support = %d\n", | ||
760 | gadget->a_alt_hnp_support); | ||
761 | n += scnprintf(buf + n, PAGE_SIZE - n, "name = %s\n", | ||
762 | (gadget->name ? gadget->name : "")); | ||
763 | |||
764 | return n; | ||
765 | } | ||
766 | static DEVICE_ATTR(device, S_IRUSR, show_device, NULL); | ||
767 | |||
768 | /** | ||
769 | * show_driver: prints information about attached gadget (if any) | ||
770 | * | ||
771 | * Check "device.h" for details | ||
772 | */ | ||
773 | static ssize_t show_driver(struct device *dev, struct device_attribute *attr, | ||
774 | char *buf) | ||
775 | { | ||
776 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
777 | struct usb_gadget_driver *driver = udc->driver; | ||
778 | int n = 0; | ||
779 | |||
780 | dbg_trace("[%s] %p\n", __func__, buf); | ||
781 | if (attr == NULL || buf == NULL) { | ||
782 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
783 | return 0; | ||
784 | } | ||
785 | |||
786 | if (driver == NULL) | ||
787 | return scnprintf(buf, PAGE_SIZE, | ||
788 | "There is no gadget attached!\n"); | ||
789 | |||
790 | n += scnprintf(buf + n, PAGE_SIZE - n, "function = %s\n", | ||
791 | (driver->function ? driver->function : "")); | ||
792 | n += scnprintf(buf + n, PAGE_SIZE - n, "max speed = %d\n", | ||
793 | driver->speed); | ||
794 | |||
795 | return n; | ||
796 | } | ||
797 | static DEVICE_ATTR(driver, S_IRUSR, show_driver, NULL); | ||
798 | |||
799 | /* Maximum event message length */ | ||
800 | #define DBG_DATA_MSG 64UL | ||
801 | |||
802 | /* Maximum event messages */ | ||
803 | #define DBG_DATA_MAX 128UL | ||
804 | |||
805 | /* Event buffer descriptor */ | ||
806 | static struct { | ||
807 | char (buf[DBG_DATA_MAX])[DBG_DATA_MSG]; /* buffer */ | ||
808 | unsigned idx; /* index */ | ||
809 | unsigned tty; /* print to console? */ | ||
810 | rwlock_t lck; /* lock */ | ||
811 | } dbg_data = { | ||
812 | .idx = 0, | ||
813 | .tty = 0, | ||
814 | .lck = __RW_LOCK_UNLOCKED(lck) | ||
815 | }; | ||
816 | |||
817 | /** | ||
818 | * dbg_dec: decrements debug event index | ||
819 | * @idx: buffer index | ||
820 | */ | ||
821 | static void dbg_dec(unsigned *idx) | ||
822 | { | ||
823 | *idx = (*idx - 1) & (DBG_DATA_MAX-1); | ||
824 | } | ||
825 | |||
826 | /** | ||
827 | * dbg_inc: increments debug event index | ||
828 | * @idx: buffer index | ||
829 | */ | ||
830 | static void dbg_inc(unsigned *idx) | ||
831 | { | ||
832 | *idx = (*idx + 1) & (DBG_DATA_MAX-1); | ||
833 | } | ||
834 | |||
835 | /** | ||
836 | * dbg_print: prints the common part of the event | ||
837 | * @addr: endpoint address | ||
838 | * @name: event name | ||
839 | * @status: status | ||
840 | * @extra: extra information | ||
841 | */ | ||
842 | static void dbg_print(u8 addr, const char *name, int status, const char *extra) | ||
843 | { | ||
844 | struct timeval tval; | ||
845 | unsigned int stamp; | ||
846 | unsigned long flags; | ||
847 | |||
848 | write_lock_irqsave(&dbg_data.lck, flags); | ||
849 | |||
850 | do_gettimeofday(&tval); | ||
851 | stamp = tval.tv_sec & 0xFFFF; /* 2^32 = 4294967296. Limit to 4096s */ | ||
852 | stamp = stamp * 1000000 + tval.tv_usec; | ||
853 | |||
854 | scnprintf(dbg_data.buf[dbg_data.idx], DBG_DATA_MSG, | ||
855 | "%04X\t» %02X %-7.7s %4i «\t%s\n", | ||
856 | stamp, addr, name, status, extra); | ||
857 | |||
858 | dbg_inc(&dbg_data.idx); | ||
859 | |||
860 | write_unlock_irqrestore(&dbg_data.lck, flags); | ||
861 | |||
862 | if (dbg_data.tty != 0) | ||
863 | pr_notice("%04X\t» %02X %-7.7s %4i «\t%s\n", | ||
864 | stamp, addr, name, status, extra); | ||
865 | } | ||
866 | |||
867 | /** | ||
868 | * dbg_done: prints a DONE event | ||
869 | * @addr: endpoint address | ||
870 | * @td: transfer descriptor | ||
871 | * @status: status | ||
872 | */ | ||
873 | static void dbg_done(u8 addr, const u32 token, int status) | ||
874 | { | ||
875 | char msg[DBG_DATA_MSG]; | ||
876 | |||
877 | scnprintf(msg, sizeof(msg), "%d %02X", | ||
878 | (int)(token & TD_TOTAL_BYTES) >> ffs_nr(TD_TOTAL_BYTES), | ||
879 | (int)(token & TD_STATUS) >> ffs_nr(TD_STATUS)); | ||
880 | dbg_print(addr, "DONE", status, msg); | ||
881 | } | ||
882 | |||
883 | /** | ||
884 | * dbg_event: prints a generic event | ||
885 | * @addr: endpoint address | ||
886 | * @name: event name | ||
887 | * @status: status | ||
888 | */ | ||
889 | static void dbg_event(u8 addr, const char *name, int status) | ||
890 | { | ||
891 | if (name != NULL) | ||
892 | dbg_print(addr, name, status, ""); | ||
893 | } | ||
894 | |||
895 | /* | ||
896 | * dbg_queue: prints a QUEUE event | ||
897 | * @addr: endpoint address | ||
898 | * @req: USB request | ||
899 | * @status: status | ||
900 | */ | ||
901 | static void dbg_queue(u8 addr, const struct usb_request *req, int status) | ||
902 | { | ||
903 | char msg[DBG_DATA_MSG]; | ||
904 | |||
905 | if (req != NULL) { | ||
906 | scnprintf(msg, sizeof(msg), | ||
907 | "%d %d", !req->no_interrupt, req->length); | ||
908 | dbg_print(addr, "QUEUE", status, msg); | ||
909 | } | ||
910 | } | ||
911 | |||
912 | /** | ||
913 | * dbg_setup: prints a SETUP event | ||
914 | * @addr: endpoint address | ||
915 | * @req: setup request | ||
916 | */ | ||
917 | static void dbg_setup(u8 addr, const struct usb_ctrlrequest *req) | ||
918 | { | ||
919 | char msg[DBG_DATA_MSG]; | ||
920 | |||
921 | if (req != NULL) { | ||
922 | scnprintf(msg, sizeof(msg), | ||
923 | "%02X %02X %04X %04X %d", req->bRequestType, | ||
924 | req->bRequest, le16_to_cpu(req->wValue), | ||
925 | le16_to_cpu(req->wIndex), le16_to_cpu(req->wLength)); | ||
926 | dbg_print(addr, "SETUP", 0, msg); | ||
927 | } | ||
928 | } | ||
929 | |||
930 | /** | ||
931 | * show_events: displays the event buffer | ||
932 | * | ||
933 | * Check "device.h" for details | ||
934 | */ | ||
935 | static ssize_t show_events(struct device *dev, struct device_attribute *attr, | ||
936 | char *buf) | ||
937 | { | ||
938 | unsigned long flags; | ||
939 | unsigned i, j, n = 0; | ||
940 | |||
941 | dbg_trace("[%s] %p\n", __func__, buf); | ||
942 | if (attr == NULL || buf == NULL) { | ||
943 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
944 | return 0; | ||
945 | } | ||
946 | |||
947 | read_lock_irqsave(&dbg_data.lck, flags); | ||
948 | |||
949 | i = dbg_data.idx; | ||
950 | for (dbg_dec(&i); i != dbg_data.idx; dbg_dec(&i)) { | ||
951 | n += strlen(dbg_data.buf[i]); | ||
952 | if (n >= PAGE_SIZE) { | ||
953 | n -= strlen(dbg_data.buf[i]); | ||
954 | break; | ||
955 | } | ||
956 | } | ||
957 | for (j = 0, dbg_inc(&i); j < n; dbg_inc(&i)) | ||
958 | j += scnprintf(buf + j, PAGE_SIZE - j, | ||
959 | "%s", dbg_data.buf[i]); | ||
960 | |||
961 | read_unlock_irqrestore(&dbg_data.lck, flags); | ||
962 | |||
963 | return n; | ||
964 | } | ||
965 | |||
966 | /** | ||
967 | * store_events: configure if events are going to be also printed to console | ||
968 | * | ||
969 | * Check "device.h" for details | ||
970 | */ | ||
971 | static ssize_t store_events(struct device *dev, struct device_attribute *attr, | ||
972 | const char *buf, size_t count) | ||
973 | { | ||
974 | unsigned tty; | ||
975 | |||
976 | dbg_trace("[%s] %p, %d\n", __func__, buf, count); | ||
977 | if (attr == NULL || buf == NULL) { | ||
978 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
979 | goto done; | ||
980 | } | ||
981 | |||
982 | if (sscanf(buf, "%u", &tty) != 1 || tty > 1) { | ||
983 | dev_err(dev, "<1|0>: enable|disable console log\n"); | ||
984 | goto done; | ||
985 | } | ||
986 | |||
987 | dbg_data.tty = tty; | ||
988 | dev_info(dev, "tty = %u", dbg_data.tty); | ||
989 | |||
990 | done: | ||
991 | return count; | ||
992 | } | ||
993 | static DEVICE_ATTR(events, S_IRUSR | S_IWUSR, show_events, store_events); | ||
994 | |||
995 | /** | ||
996 | * show_inters: interrupt status, enable status and historic | ||
997 | * | ||
998 | * Check "device.h" for details | ||
999 | */ | ||
1000 | static ssize_t show_inters(struct device *dev, struct device_attribute *attr, | ||
1001 | char *buf) | ||
1002 | { | ||
1003 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1004 | unsigned long flags; | ||
1005 | u32 intr; | ||
1006 | unsigned i, j, n = 0; | ||
1007 | |||
1008 | dbg_trace("[%s] %p\n", __func__, buf); | ||
1009 | if (attr == NULL || buf == NULL) { | ||
1010 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1011 | return 0; | ||
1012 | } | ||
1013 | |||
1014 | spin_lock_irqsave(udc->lock, flags); | ||
1015 | |||
1016 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1017 | "status = %08x\n", hw_read_intr_status()); | ||
1018 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1019 | "enable = %08x\n", hw_read_intr_enable()); | ||
1020 | |||
1021 | n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n", | ||
1022 | isr_statistics.test); | ||
1023 | n += scnprintf(buf + n, PAGE_SIZE - n, "» ui = %d\n", | ||
1024 | isr_statistics.ui); | ||
1025 | n += scnprintf(buf + n, PAGE_SIZE - n, "» uei = %d\n", | ||
1026 | isr_statistics.uei); | ||
1027 | n += scnprintf(buf + n, PAGE_SIZE - n, "» pci = %d\n", | ||
1028 | isr_statistics.pci); | ||
1029 | n += scnprintf(buf + n, PAGE_SIZE - n, "» uri = %d\n", | ||
1030 | isr_statistics.uri); | ||
1031 | n += scnprintf(buf + n, PAGE_SIZE - n, "» sli = %d\n", | ||
1032 | isr_statistics.sli); | ||
1033 | n += scnprintf(buf + n, PAGE_SIZE - n, "*none = %d\n", | ||
1034 | isr_statistics.none); | ||
1035 | n += scnprintf(buf + n, PAGE_SIZE - n, "*hndl = %d\n", | ||
1036 | isr_statistics.hndl.cnt); | ||
1037 | |||
1038 | for (i = isr_statistics.hndl.idx, j = 0; j <= ISR_MASK; j++, i++) { | ||
1039 | i &= ISR_MASK; | ||
1040 | intr = isr_statistics.hndl.buf[i]; | ||
1041 | |||
1042 | if (USBi_UI & intr) | ||
1043 | n += scnprintf(buf + n, PAGE_SIZE - n, "ui "); | ||
1044 | intr &= ~USBi_UI; | ||
1045 | if (USBi_UEI & intr) | ||
1046 | n += scnprintf(buf + n, PAGE_SIZE - n, "uei "); | ||
1047 | intr &= ~USBi_UEI; | ||
1048 | if (USBi_PCI & intr) | ||
1049 | n += scnprintf(buf + n, PAGE_SIZE - n, "pci "); | ||
1050 | intr &= ~USBi_PCI; | ||
1051 | if (USBi_URI & intr) | ||
1052 | n += scnprintf(buf + n, PAGE_SIZE - n, "uri "); | ||
1053 | intr &= ~USBi_URI; | ||
1054 | if (USBi_SLI & intr) | ||
1055 | n += scnprintf(buf + n, PAGE_SIZE - n, "sli "); | ||
1056 | intr &= ~USBi_SLI; | ||
1057 | if (intr) | ||
1058 | n += scnprintf(buf + n, PAGE_SIZE - n, "??? "); | ||
1059 | if (isr_statistics.hndl.buf[i]) | ||
1060 | n += scnprintf(buf + n, PAGE_SIZE - n, "\n"); | ||
1061 | } | ||
1062 | |||
1063 | spin_unlock_irqrestore(udc->lock, flags); | ||
1064 | |||
1065 | return n; | ||
1066 | } | ||
1067 | |||
1068 | /** | ||
1069 | * store_inters: enable & force or disable an individual interrutps | ||
1070 | * (to be used for test purposes only) | ||
1071 | * | ||
1072 | * Check "device.h" for details | ||
1073 | */ | ||
1074 | static ssize_t store_inters(struct device *dev, struct device_attribute *attr, | ||
1075 | const char *buf, size_t count) | ||
1076 | { | ||
1077 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1078 | unsigned long flags; | ||
1079 | unsigned en, bit; | ||
1080 | |||
1081 | dbg_trace("[%s] %p, %d\n", __func__, buf, count); | ||
1082 | if (attr == NULL || buf == NULL) { | ||
1083 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1084 | goto done; | ||
1085 | } | ||
1086 | |||
1087 | if (sscanf(buf, "%u %u", &en, &bit) != 2 || en > 1) { | ||
1088 | dev_err(dev, "<1|0> <bit>: enable|disable interrupt"); | ||
1089 | goto done; | ||
1090 | } | ||
1091 | |||
1092 | spin_lock_irqsave(udc->lock, flags); | ||
1093 | if (en) { | ||
1094 | if (hw_intr_force(bit)) | ||
1095 | dev_err(dev, "invalid bit number\n"); | ||
1096 | else | ||
1097 | isr_statistics.test++; | ||
1098 | } else { | ||
1099 | if (hw_intr_clear(bit)) | ||
1100 | dev_err(dev, "invalid bit number\n"); | ||
1101 | } | ||
1102 | spin_unlock_irqrestore(udc->lock, flags); | ||
1103 | |||
1104 | done: | ||
1105 | return count; | ||
1106 | } | ||
1107 | static DEVICE_ATTR(inters, S_IRUSR | S_IWUSR, show_inters, store_inters); | ||
1108 | |||
1109 | /** | ||
1110 | * show_port_test: reads port test mode | ||
1111 | * | ||
1112 | * Check "device.h" for details | ||
1113 | */ | ||
1114 | static ssize_t show_port_test(struct device *dev, | ||
1115 | struct device_attribute *attr, char *buf) | ||
1116 | { | ||
1117 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1118 | unsigned long flags; | ||
1119 | unsigned mode; | ||
1120 | |||
1121 | dbg_trace("[%s] %p\n", __func__, buf); | ||
1122 | if (attr == NULL || buf == NULL) { | ||
1123 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1124 | return 0; | ||
1125 | } | ||
1126 | |||
1127 | spin_lock_irqsave(udc->lock, flags); | ||
1128 | mode = hw_port_test_get(); | ||
1129 | spin_unlock_irqrestore(udc->lock, flags); | ||
1130 | |||
1131 | return scnprintf(buf, PAGE_SIZE, "mode = %u\n", mode); | ||
1132 | } | ||
1133 | |||
1134 | /** | ||
1135 | * store_port_test: writes port test mode | ||
1136 | * | ||
1137 | * Check "device.h" for details | ||
1138 | */ | ||
1139 | static ssize_t store_port_test(struct device *dev, | ||
1140 | struct device_attribute *attr, | ||
1141 | const char *buf, size_t count) | ||
1142 | { | ||
1143 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1144 | unsigned long flags; | ||
1145 | unsigned mode; | ||
1146 | |||
1147 | dbg_trace("[%s] %p, %d\n", __func__, buf, count); | ||
1148 | if (attr == NULL || buf == NULL) { | ||
1149 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1150 | goto done; | ||
1151 | } | ||
1152 | |||
1153 | if (sscanf(buf, "%u", &mode) != 1) { | ||
1154 | dev_err(dev, "<mode>: set port test mode"); | ||
1155 | goto done; | ||
1156 | } | ||
1157 | |||
1158 | spin_lock_irqsave(udc->lock, flags); | ||
1159 | if (hw_port_test_set(mode)) | ||
1160 | dev_err(dev, "invalid mode\n"); | ||
1161 | spin_unlock_irqrestore(udc->lock, flags); | ||
1162 | |||
1163 | done: | ||
1164 | return count; | ||
1165 | } | ||
1166 | static DEVICE_ATTR(port_test, S_IRUSR | S_IWUSR, | ||
1167 | show_port_test, store_port_test); | ||
1168 | |||
1169 | /** | ||
1170 | * show_qheads: DMA contents of all queue heads | ||
1171 | * | ||
1172 | * Check "device.h" for details | ||
1173 | */ | ||
1174 | static ssize_t show_qheads(struct device *dev, struct device_attribute *attr, | ||
1175 | char *buf) | ||
1176 | { | ||
1177 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1178 | unsigned long flags; | ||
1179 | unsigned i, j, n = 0; | ||
1180 | |||
1181 | dbg_trace("[%s] %p\n", __func__, buf); | ||
1182 | if (attr == NULL || buf == NULL) { | ||
1183 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1184 | return 0; | ||
1185 | } | ||
1186 | |||
1187 | spin_lock_irqsave(udc->lock, flags); | ||
1188 | for (i = 0; i < hw_ep_max; i++) { | ||
1189 | struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; | ||
1190 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1191 | "EP=%02i: RX=%08X TX=%08X\n", | ||
1192 | i, (u32)mEp->qh[RX].dma, (u32)mEp->qh[TX].dma); | ||
1193 | for (j = 0; j < (sizeof(struct ci13xxx_qh)/sizeof(u32)); j++) { | ||
1194 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1195 | " %04X: %08X %08X\n", j, | ||
1196 | *((u32 *)mEp->qh[RX].ptr + j), | ||
1197 | *((u32 *)mEp->qh[TX].ptr + j)); | ||
1198 | } | ||
1199 | } | ||
1200 | spin_unlock_irqrestore(udc->lock, flags); | ||
1201 | |||
1202 | return n; | ||
1203 | } | ||
1204 | static DEVICE_ATTR(qheads, S_IRUSR, show_qheads, NULL); | ||
1205 | |||
1206 | /** | ||
1207 | * show_registers: dumps all registers | ||
1208 | * | ||
1209 | * Check "device.h" for details | ||
1210 | */ | ||
1211 | static ssize_t show_registers(struct device *dev, | ||
1212 | struct device_attribute *attr, char *buf) | ||
1213 | { | ||
1214 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1215 | unsigned long flags; | ||
1216 | u32 dump[512]; | ||
1217 | unsigned i, k, n = 0; | ||
1218 | |||
1219 | dbg_trace("[%s] %p\n", __func__, buf); | ||
1220 | if (attr == NULL || buf == NULL) { | ||
1221 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1222 | return 0; | ||
1223 | } | ||
1224 | |||
1225 | spin_lock_irqsave(udc->lock, flags); | ||
1226 | k = hw_register_read(dump, sizeof(dump)/sizeof(u32)); | ||
1227 | spin_unlock_irqrestore(udc->lock, flags); | ||
1228 | |||
1229 | for (i = 0; i < k; i++) { | ||
1230 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1231 | "reg[0x%04X] = 0x%08X\n", | ||
1232 | i * (unsigned)sizeof(u32), dump[i]); | ||
1233 | } | ||
1234 | |||
1235 | return n; | ||
1236 | } | ||
1237 | |||
1238 | /** | ||
1239 | * store_registers: writes value to register address | ||
1240 | * | ||
1241 | * Check "device.h" for details | ||
1242 | */ | ||
1243 | static ssize_t store_registers(struct device *dev, | ||
1244 | struct device_attribute *attr, | ||
1245 | const char *buf, size_t count) | ||
1246 | { | ||
1247 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1248 | unsigned long addr, data, flags; | ||
1249 | |||
1250 | dbg_trace("[%s] %p, %d\n", __func__, buf, count); | ||
1251 | if (attr == NULL || buf == NULL) { | ||
1252 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1253 | goto done; | ||
1254 | } | ||
1255 | |||
1256 | if (sscanf(buf, "%li %li", &addr, &data) != 2) { | ||
1257 | dev_err(dev, "<addr> <data>: write data to register address"); | ||
1258 | goto done; | ||
1259 | } | ||
1260 | |||
1261 | spin_lock_irqsave(udc->lock, flags); | ||
1262 | if (hw_register_write(addr, data)) | ||
1263 | dev_err(dev, "invalid address range\n"); | ||
1264 | spin_unlock_irqrestore(udc->lock, flags); | ||
1265 | |||
1266 | done: | ||
1267 | return count; | ||
1268 | } | ||
1269 | static DEVICE_ATTR(registers, S_IRUSR | S_IWUSR, | ||
1270 | show_registers, store_registers); | ||
1271 | |||
1272 | /** | ||
1273 | * show_requests: DMA contents of all requests currently queued (all endpts) | ||
1274 | * | ||
1275 | * Check "device.h" for details | ||
1276 | */ | ||
1277 | static ssize_t show_requests(struct device *dev, struct device_attribute *attr, | ||
1278 | char *buf) | ||
1279 | { | ||
1280 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1281 | unsigned long flags; | ||
1282 | struct list_head *ptr = NULL; | ||
1283 | struct ci13xxx_req *req = NULL; | ||
1284 | unsigned i, j, k, n = 0, qSize = sizeof(struct ci13xxx_td)/sizeof(u32); | ||
1285 | |||
1286 | dbg_trace("[%s] %p\n", __func__, buf); | ||
1287 | if (attr == NULL || buf == NULL) { | ||
1288 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1289 | return 0; | ||
1290 | } | ||
1291 | |||
1292 | spin_lock_irqsave(udc->lock, flags); | ||
1293 | for (i = 0; i < hw_ep_max; i++) | ||
1294 | for (k = RX; k <= TX; k++) | ||
1295 | list_for_each(ptr, &udc->ci13xxx_ep[i].qh[k].queue) | ||
1296 | { | ||
1297 | req = list_entry(ptr, | ||
1298 | struct ci13xxx_req, queue); | ||
1299 | |||
1300 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1301 | "EP=%02i: TD=%08X %s\n", | ||
1302 | i, (u32)req->dma, | ||
1303 | ((k == RX) ? "RX" : "TX")); | ||
1304 | |||
1305 | for (j = 0; j < qSize; j++) | ||
1306 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1307 | " %04X: %08X\n", j, | ||
1308 | *((u32 *)req->ptr + j)); | ||
1309 | } | ||
1310 | spin_unlock_irqrestore(udc->lock, flags); | ||
1311 | |||
1312 | return n; | ||
1313 | } | ||
1314 | static DEVICE_ATTR(requests, S_IRUSR, show_requests, NULL); | ||
1315 | |||
1316 | /** | ||
1317 | * dbg_create_files: initializes the attribute interface | ||
1318 | * @dev: device | ||
1319 | * | ||
1320 | * This function returns an error code | ||
1321 | */ | ||
1322 | __maybe_unused static int dbg_create_files(struct device *dev) | ||
1323 | { | ||
1324 | int retval = 0; | ||
1325 | |||
1326 | if (dev == NULL) | ||
1327 | return -EINVAL; | ||
1328 | retval = device_create_file(dev, &dev_attr_device); | ||
1329 | if (retval) | ||
1330 | goto done; | ||
1331 | retval = device_create_file(dev, &dev_attr_driver); | ||
1332 | if (retval) | ||
1333 | goto rm_device; | ||
1334 | retval = device_create_file(dev, &dev_attr_events); | ||
1335 | if (retval) | ||
1336 | goto rm_driver; | ||
1337 | retval = device_create_file(dev, &dev_attr_inters); | ||
1338 | if (retval) | ||
1339 | goto rm_events; | ||
1340 | retval = device_create_file(dev, &dev_attr_port_test); | ||
1341 | if (retval) | ||
1342 | goto rm_inters; | ||
1343 | retval = device_create_file(dev, &dev_attr_qheads); | ||
1344 | if (retval) | ||
1345 | goto rm_port_test; | ||
1346 | retval = device_create_file(dev, &dev_attr_registers); | ||
1347 | if (retval) | ||
1348 | goto rm_qheads; | ||
1349 | retval = device_create_file(dev, &dev_attr_requests); | ||
1350 | if (retval) | ||
1351 | goto rm_registers; | ||
1352 | return 0; | ||
1353 | |||
1354 | rm_registers: | ||
1355 | device_remove_file(dev, &dev_attr_registers); | ||
1356 | rm_qheads: | ||
1357 | device_remove_file(dev, &dev_attr_qheads); | ||
1358 | rm_port_test: | ||
1359 | device_remove_file(dev, &dev_attr_port_test); | ||
1360 | rm_inters: | ||
1361 | device_remove_file(dev, &dev_attr_inters); | ||
1362 | rm_events: | ||
1363 | device_remove_file(dev, &dev_attr_events); | ||
1364 | rm_driver: | ||
1365 | device_remove_file(dev, &dev_attr_driver); | ||
1366 | rm_device: | ||
1367 | device_remove_file(dev, &dev_attr_device); | ||
1368 | done: | ||
1369 | return retval; | ||
1370 | } | ||
1371 | |||
1372 | /** | ||
1373 | * dbg_remove_files: destroys the attribute interface | ||
1374 | * @dev: device | ||
1375 | * | ||
1376 | * This function returns an error code | ||
1377 | */ | ||
1378 | __maybe_unused static int dbg_remove_files(struct device *dev) | ||
1379 | { | ||
1380 | if (dev == NULL) | ||
1381 | return -EINVAL; | ||
1382 | device_remove_file(dev, &dev_attr_requests); | ||
1383 | device_remove_file(dev, &dev_attr_registers); | ||
1384 | device_remove_file(dev, &dev_attr_qheads); | ||
1385 | device_remove_file(dev, &dev_attr_port_test); | ||
1386 | device_remove_file(dev, &dev_attr_inters); | ||
1387 | device_remove_file(dev, &dev_attr_events); | ||
1388 | device_remove_file(dev, &dev_attr_driver); | ||
1389 | device_remove_file(dev, &dev_attr_device); | ||
1390 | return 0; | ||
1391 | } | ||
1392 | |||
1393 | /****************************************************************************** | ||
1394 | * UTIL block | ||
1395 | *****************************************************************************/ | ||
1396 | /** | ||
1397 | * _usb_addr: calculates endpoint address from direction & number | ||
1398 | * @ep: endpoint | ||
1399 | */ | ||
1400 | static inline u8 _usb_addr(struct ci13xxx_ep *ep) | ||
1401 | { | ||
1402 | return ((ep->dir == TX) ? USB_ENDPOINT_DIR_MASK : 0) | ep->num; | ||
1403 | } | ||
1404 | |||
1405 | /** | ||
1406 | * _hardware_queue: configures a request at hardware level | ||
1407 | * @gadget: gadget | ||
1408 | * @mEp: endpoint | ||
1409 | * | ||
1410 | * This function returns an error code | ||
1411 | */ | ||
1412 | static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) | ||
1413 | { | ||
1414 | unsigned i; | ||
1415 | |||
1416 | trace("%p, %p", mEp, mReq); | ||
1417 | |||
1418 | /* don't queue twice */ | ||
1419 | if (mReq->req.status == -EALREADY) | ||
1420 | return -EALREADY; | ||
1421 | |||
1422 | if (hw_ep_is_primed(mEp->num, mEp->dir)) | ||
1423 | return -EBUSY; | ||
1424 | |||
1425 | mReq->req.status = -EALREADY; | ||
1426 | |||
1427 | if (mReq->req.length && !mReq->req.dma) { | ||
1428 | mReq->req.dma = \ | ||
1429 | dma_map_single(mEp->device, mReq->req.buf, | ||
1430 | mReq->req.length, mEp->dir ? | ||
1431 | DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
1432 | if (mReq->req.dma == 0) | ||
1433 | return -ENOMEM; | ||
1434 | |||
1435 | mReq->map = 1; | ||
1436 | } | ||
1437 | |||
1438 | /* | ||
1439 | * TD configuration | ||
1440 | * TODO - handle requests which spawns into several TDs | ||
1441 | */ | ||
1442 | memset(mReq->ptr, 0, sizeof(*mReq->ptr)); | ||
1443 | mReq->ptr->next |= TD_TERMINATE; | ||
1444 | mReq->ptr->token = mReq->req.length << ffs_nr(TD_TOTAL_BYTES); | ||
1445 | mReq->ptr->token &= TD_TOTAL_BYTES; | ||
1446 | mReq->ptr->token |= TD_IOC; | ||
1447 | mReq->ptr->token |= TD_STATUS_ACTIVE; | ||
1448 | mReq->ptr->page[0] = mReq->req.dma; | ||
1449 | for (i = 1; i < 5; i++) | ||
1450 | mReq->ptr->page[i] = | ||
1451 | (mReq->req.dma + i * PAGE_SIZE) & ~TD_RESERVED_MASK; | ||
1452 | |||
1453 | /* | ||
1454 | * QH configuration | ||
1455 | * At this point it's guaranteed exclusive access to qhead | ||
1456 | * (endpt is not primed) so it's no need to use tripwire | ||
1457 | */ | ||
1458 | mEp->qh[mEp->dir].ptr->td.next = mReq->dma; /* TERMINATE = 0 */ | ||
1459 | mEp->qh[mEp->dir].ptr->td.token &= ~TD_STATUS; /* clear status */ | ||
1460 | if (mReq->req.zero == 0) | ||
1461 | mEp->qh[mEp->dir].ptr->cap |= QH_ZLT; | ||
1462 | else | ||
1463 | mEp->qh[mEp->dir].ptr->cap &= ~QH_ZLT; | ||
1464 | |||
1465 | wmb(); /* synchronize before ep prime */ | ||
1466 | |||
1467 | return hw_ep_prime(mEp->num, mEp->dir, | ||
1468 | mEp->type == USB_ENDPOINT_XFER_CONTROL); | ||
1469 | } | ||
1470 | |||
1471 | /** | ||
1472 | * _hardware_dequeue: handles a request at hardware level | ||
1473 | * @gadget: gadget | ||
1474 | * @mEp: endpoint | ||
1475 | * | ||
1476 | * This function returns an error code | ||
1477 | */ | ||
1478 | static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) | ||
1479 | { | ||
1480 | trace("%p, %p", mEp, mReq); | ||
1481 | |||
1482 | if (mReq->req.status != -EALREADY) | ||
1483 | return -EINVAL; | ||
1484 | |||
1485 | if (hw_ep_is_primed(mEp->num, mEp->dir)) | ||
1486 | hw_ep_flush(mEp->num, mEp->dir); | ||
1487 | |||
1488 | mReq->req.status = 0; | ||
1489 | |||
1490 | if (mReq->map) { | ||
1491 | dma_unmap_single(mEp->device, mReq->req.dma, mReq->req.length, | ||
1492 | mEp->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
1493 | mReq->req.dma = 0; | ||
1494 | mReq->map = 0; | ||
1495 | } | ||
1496 | |||
1497 | mReq->req.status = mReq->ptr->token & TD_STATUS; | ||
1498 | if ((TD_STATUS_ACTIVE & mReq->req.status) != 0) | ||
1499 | mReq->req.status = -ECONNRESET; | ||
1500 | else if ((TD_STATUS_HALTED & mReq->req.status) != 0) | ||
1501 | mReq->req.status = -1; | ||
1502 | else if ((TD_STATUS_DT_ERR & mReq->req.status) != 0) | ||
1503 | mReq->req.status = -1; | ||
1504 | else if ((TD_STATUS_TR_ERR & mReq->req.status) != 0) | ||
1505 | mReq->req.status = -1; | ||
1506 | |||
1507 | mReq->req.actual = mReq->ptr->token & TD_TOTAL_BYTES; | ||
1508 | mReq->req.actual >>= ffs_nr(TD_TOTAL_BYTES); | ||
1509 | mReq->req.actual = mReq->req.length - mReq->req.actual; | ||
1510 | mReq->req.actual = mReq->req.status ? 0 : mReq->req.actual; | ||
1511 | |||
1512 | return mReq->req.actual; | ||
1513 | } | ||
1514 | |||
1515 | /** | ||
1516 | * _ep_nuke: dequeues all endpoint requests | ||
1517 | * @mEp: endpoint | ||
1518 | * | ||
1519 | * This function returns an error code | ||
1520 | * Caller must hold lock | ||
1521 | */ | ||
1522 | static int _ep_nuke(struct ci13xxx_ep *mEp) | ||
1523 | __releases(mEp->lock) | ||
1524 | __acquires(mEp->lock) | ||
1525 | { | ||
1526 | trace("%p", mEp); | ||
1527 | |||
1528 | if (mEp == NULL) | ||
1529 | return -EINVAL; | ||
1530 | |||
1531 | hw_ep_flush(mEp->num, mEp->dir); | ||
1532 | |||
1533 | while (!list_empty(&mEp->qh[mEp->dir].queue)) { | ||
1534 | |||
1535 | /* pop oldest request */ | ||
1536 | struct ci13xxx_req *mReq = \ | ||
1537 | list_entry(mEp->qh[mEp->dir].queue.next, | ||
1538 | struct ci13xxx_req, queue); | ||
1539 | list_del_init(&mReq->queue); | ||
1540 | mReq->req.status = -ESHUTDOWN; | ||
1541 | |||
1542 | if (!mReq->req.no_interrupt && mReq->req.complete != NULL) { | ||
1543 | spin_unlock(mEp->lock); | ||
1544 | mReq->req.complete(&mEp->ep, &mReq->req); | ||
1545 | spin_lock(mEp->lock); | ||
1546 | } | ||
1547 | } | ||
1548 | return 0; | ||
1549 | } | ||
1550 | |||
1551 | /** | ||
1552 | * _gadget_stop_activity: stops all USB activity, flushes & disables all endpts | ||
1553 | * @gadget: gadget | ||
1554 | * | ||
1555 | * This function returns an error code | ||
1556 | * Caller must hold lock | ||
1557 | */ | ||
1558 | static int _gadget_stop_activity(struct usb_gadget *gadget) | ||
1559 | __releases(udc->lock) | ||
1560 | __acquires(udc->lock) | ||
1561 | { | ||
1562 | struct usb_ep *ep; | ||
1563 | struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget); | ||
1564 | struct ci13xxx_ep *mEp = container_of(gadget->ep0, | ||
1565 | struct ci13xxx_ep, ep); | ||
1566 | |||
1567 | trace("%p", gadget); | ||
1568 | |||
1569 | if (gadget == NULL) | ||
1570 | return -EINVAL; | ||
1571 | |||
1572 | spin_unlock(udc->lock); | ||
1573 | |||
1574 | /* flush all endpoints */ | ||
1575 | gadget_for_each_ep(ep, gadget) { | ||
1576 | usb_ep_fifo_flush(ep); | ||
1577 | } | ||
1578 | usb_ep_fifo_flush(gadget->ep0); | ||
1579 | |||
1580 | udc->driver->disconnect(gadget); | ||
1581 | |||
1582 | /* make sure to disable all endpoints */ | ||
1583 | gadget_for_each_ep(ep, gadget) { | ||
1584 | usb_ep_disable(ep); | ||
1585 | } | ||
1586 | usb_ep_disable(gadget->ep0); | ||
1587 | |||
1588 | if (mEp->status != NULL) { | ||
1589 | usb_ep_free_request(gadget->ep0, mEp->status); | ||
1590 | mEp->status = NULL; | ||
1591 | } | ||
1592 | |||
1593 | spin_lock(udc->lock); | ||
1594 | |||
1595 | return 0; | ||
1596 | } | ||
1597 | |||
1598 | /****************************************************************************** | ||
1599 | * ISR block | ||
1600 | *****************************************************************************/ | ||
1601 | /** | ||
1602 | * isr_reset_handler: USB reset interrupt handler | ||
1603 | * @udc: UDC device | ||
1604 | * | ||
1605 | * This function resets USB engine after a bus reset occurred | ||
1606 | */ | ||
1607 | static void isr_reset_handler(struct ci13xxx *udc) | ||
1608 | __releases(udc->lock) | ||
1609 | __acquires(udc->lock) | ||
1610 | { | ||
1611 | struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[0]; | ||
1612 | int retval; | ||
1613 | |||
1614 | trace("%p", udc); | ||
1615 | |||
1616 | if (udc == NULL) { | ||
1617 | err("EINVAL"); | ||
1618 | return; | ||
1619 | } | ||
1620 | |||
1621 | dbg_event(0xFF, "BUS RST", 0); | ||
1622 | |||
1623 | retval = _gadget_stop_activity(&udc->gadget); | ||
1624 | if (retval) | ||
1625 | goto done; | ||
1626 | |||
1627 | retval = hw_usb_reset(); | ||
1628 | if (retval) | ||
1629 | goto done; | ||
1630 | |||
1631 | spin_unlock(udc->lock); | ||
1632 | retval = usb_ep_enable(&mEp->ep, &ctrl_endpt_desc); | ||
1633 | if (!retval) { | ||
1634 | mEp->status = usb_ep_alloc_request(&mEp->ep, GFP_KERNEL); | ||
1635 | if (mEp->status == NULL) { | ||
1636 | usb_ep_disable(&mEp->ep); | ||
1637 | retval = -ENOMEM; | ||
1638 | } | ||
1639 | } | ||
1640 | spin_lock(udc->lock); | ||
1641 | |||
1642 | done: | ||
1643 | if (retval) | ||
1644 | err("error: %i", retval); | ||
1645 | } | ||
1646 | |||
1647 | /** | ||
1648 | * isr_get_status_complete: get_status request complete function | ||
1649 | * @ep: endpoint | ||
1650 | * @req: request handled | ||
1651 | * | ||
1652 | * Caller must release lock | ||
1653 | */ | ||
1654 | static void isr_get_status_complete(struct usb_ep *ep, struct usb_request *req) | ||
1655 | { | ||
1656 | trace("%p, %p", ep, req); | ||
1657 | |||
1658 | if (ep == NULL || req == NULL) { | ||
1659 | err("EINVAL"); | ||
1660 | return; | ||
1661 | } | ||
1662 | |||
1663 | kfree(req->buf); | ||
1664 | usb_ep_free_request(ep, req); | ||
1665 | } | ||
1666 | |||
1667 | /** | ||
1668 | * isr_get_status_response: get_status request response | ||
1669 | * @ep: endpoint | ||
1670 | * @setup: setup request packet | ||
1671 | * | ||
1672 | * This function returns an error code | ||
1673 | */ | ||
1674 | static int isr_get_status_response(struct ci13xxx_ep *mEp, | ||
1675 | struct usb_ctrlrequest *setup) | ||
1676 | __releases(mEp->lock) | ||
1677 | __acquires(mEp->lock) | ||
1678 | { | ||
1679 | struct usb_request *req = NULL; | ||
1680 | gfp_t gfp_flags = GFP_ATOMIC; | ||
1681 | int dir, num, retval; | ||
1682 | |||
1683 | trace("%p, %p", mEp, setup); | ||
1684 | |||
1685 | if (mEp == NULL || setup == NULL) | ||
1686 | return -EINVAL; | ||
1687 | |||
1688 | spin_unlock(mEp->lock); | ||
1689 | req = usb_ep_alloc_request(&mEp->ep, gfp_flags); | ||
1690 | spin_lock(mEp->lock); | ||
1691 | if (req == NULL) | ||
1692 | return -ENOMEM; | ||
1693 | |||
1694 | req->complete = isr_get_status_complete; | ||
1695 | req->length = 2; | ||
1696 | req->buf = kzalloc(req->length, gfp_flags); | ||
1697 | if (req->buf == NULL) { | ||
1698 | retval = -ENOMEM; | ||
1699 | goto err_free_req; | ||
1700 | } | ||
1701 | |||
1702 | if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) { | ||
1703 | /* TODO: D1 - Remote Wakeup; D0 - Self Powered */ | ||
1704 | retval = 0; | ||
1705 | } else if ((setup->bRequestType & USB_RECIP_MASK) \ | ||
1706 | == USB_RECIP_ENDPOINT) { | ||
1707 | dir = (le16_to_cpu(setup->wIndex) & USB_ENDPOINT_DIR_MASK) ? | ||
1708 | TX : RX; | ||
1709 | num = le16_to_cpu(setup->wIndex) & USB_ENDPOINT_NUMBER_MASK; | ||
1710 | *((u16 *)req->buf) = hw_ep_get_halt(num, dir); | ||
1711 | } | ||
1712 | /* else do nothing; reserved for future use */ | ||
1713 | |||
1714 | spin_unlock(mEp->lock); | ||
1715 | retval = usb_ep_queue(&mEp->ep, req, gfp_flags); | ||
1716 | spin_lock(mEp->lock); | ||
1717 | if (retval) | ||
1718 | goto err_free_buf; | ||
1719 | |||
1720 | return 0; | ||
1721 | |||
1722 | err_free_buf: | ||
1723 | kfree(req->buf); | ||
1724 | err_free_req: | ||
1725 | spin_unlock(mEp->lock); | ||
1726 | usb_ep_free_request(&mEp->ep, req); | ||
1727 | spin_lock(mEp->lock); | ||
1728 | return retval; | ||
1729 | } | ||
1730 | |||
1731 | /** | ||
1732 | * isr_setup_status_phase: queues the status phase of a setup transation | ||
1733 | * @mEp: endpoint | ||
1734 | * | ||
1735 | * This function returns an error code | ||
1736 | */ | ||
1737 | static int isr_setup_status_phase(struct ci13xxx_ep *mEp) | ||
1738 | __releases(mEp->lock) | ||
1739 | __acquires(mEp->lock) | ||
1740 | { | ||
1741 | int retval; | ||
1742 | |||
1743 | trace("%p", mEp); | ||
1744 | |||
1745 | /* mEp is always valid & configured */ | ||
1746 | |||
1747 | if (mEp->type == USB_ENDPOINT_XFER_CONTROL) | ||
1748 | mEp->dir = (mEp->dir == TX) ? RX : TX; | ||
1749 | |||
1750 | mEp->status->no_interrupt = 1; | ||
1751 | |||
1752 | spin_unlock(mEp->lock); | ||
1753 | retval = usb_ep_queue(&mEp->ep, mEp->status, GFP_ATOMIC); | ||
1754 | spin_lock(mEp->lock); | ||
1755 | |||
1756 | return retval; | ||
1757 | } | ||
1758 | |||
1759 | /** | ||
1760 | * isr_tr_complete_low: transaction complete low level handler | ||
1761 | * @mEp: endpoint | ||
1762 | * | ||
1763 | * This function returns an error code | ||
1764 | * Caller must hold lock | ||
1765 | */ | ||
1766 | static int isr_tr_complete_low(struct ci13xxx_ep *mEp) | ||
1767 | __releases(mEp->lock) | ||
1768 | __acquires(mEp->lock) | ||
1769 | { | ||
1770 | struct ci13xxx_req *mReq; | ||
1771 | int retval; | ||
1772 | |||
1773 | trace("%p", mEp); | ||
1774 | |||
1775 | if (list_empty(&mEp->qh[mEp->dir].queue)) | ||
1776 | return -EINVAL; | ||
1777 | |||
1778 | /* pop oldest request */ | ||
1779 | mReq = list_entry(mEp->qh[mEp->dir].queue.next, | ||
1780 | struct ci13xxx_req, queue); | ||
1781 | list_del_init(&mReq->queue); | ||
1782 | |||
1783 | retval = _hardware_dequeue(mEp, mReq); | ||
1784 | if (retval < 0) { | ||
1785 | dbg_event(_usb_addr(mEp), "DONE", retval); | ||
1786 | goto done; | ||
1787 | } | ||
1788 | |||
1789 | dbg_done(_usb_addr(mEp), mReq->ptr->token, retval); | ||
1790 | |||
1791 | if (!mReq->req.no_interrupt && mReq->req.complete != NULL) { | ||
1792 | spin_unlock(mEp->lock); | ||
1793 | mReq->req.complete(&mEp->ep, &mReq->req); | ||
1794 | spin_lock(mEp->lock); | ||
1795 | } | ||
1796 | |||
1797 | if (!list_empty(&mEp->qh[mEp->dir].queue)) { | ||
1798 | mReq = list_entry(mEp->qh[mEp->dir].queue.next, | ||
1799 | struct ci13xxx_req, queue); | ||
1800 | _hardware_enqueue(mEp, mReq); | ||
1801 | } | ||
1802 | |||
1803 | done: | ||
1804 | return retval; | ||
1805 | } | ||
1806 | |||
1807 | /** | ||
1808 | * isr_tr_complete_handler: transaction complete interrupt handler | ||
1809 | * @udc: UDC descriptor | ||
1810 | * | ||
1811 | * This function handles traffic events | ||
1812 | */ | ||
1813 | static void isr_tr_complete_handler(struct ci13xxx *udc) | ||
1814 | __releases(udc->lock) | ||
1815 | __acquires(udc->lock) | ||
1816 | { | ||
1817 | unsigned i; | ||
1818 | |||
1819 | trace("%p", udc); | ||
1820 | |||
1821 | if (udc == NULL) { | ||
1822 | err("EINVAL"); | ||
1823 | return; | ||
1824 | } | ||
1825 | |||
1826 | for (i = 0; i < hw_ep_max; i++) { | ||
1827 | struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; | ||
1828 | int type, num, err = -EINVAL; | ||
1829 | struct usb_ctrlrequest req; | ||
1830 | |||
1831 | |||
1832 | if (mEp->desc == NULL) | ||
1833 | continue; /* not configured */ | ||
1834 | |||
1835 | if ((mEp->dir == RX && hw_test_and_clear_complete(i)) || | ||
1836 | (mEp->dir == TX && hw_test_and_clear_complete(i + 16))) { | ||
1837 | err = isr_tr_complete_low(mEp); | ||
1838 | if (mEp->type == USB_ENDPOINT_XFER_CONTROL) { | ||
1839 | if (err > 0) /* needs status phase */ | ||
1840 | err = isr_setup_status_phase(mEp); | ||
1841 | if (err < 0) { | ||
1842 | dbg_event(_usb_addr(mEp), | ||
1843 | "ERROR", err); | ||
1844 | spin_unlock(udc->lock); | ||
1845 | if (usb_ep_set_halt(&mEp->ep)) | ||
1846 | err("error: ep_set_halt"); | ||
1847 | spin_lock(udc->lock); | ||
1848 | } | ||
1849 | } | ||
1850 | } | ||
1851 | |||
1852 | if (mEp->type != USB_ENDPOINT_XFER_CONTROL || | ||
1853 | !hw_test_and_clear_setup_status(i)) | ||
1854 | continue; | ||
1855 | |||
1856 | if (i != 0) { | ||
1857 | warn("ctrl traffic received at endpoint"); | ||
1858 | continue; | ||
1859 | } | ||
1860 | |||
1861 | /* read_setup_packet */ | ||
1862 | do { | ||
1863 | hw_test_and_set_setup_guard(); | ||
1864 | memcpy(&req, &mEp->qh[RX].ptr->setup, sizeof(req)); | ||
1865 | } while (!hw_test_and_clear_setup_guard()); | ||
1866 | |||
1867 | type = req.bRequestType; | ||
1868 | |||
1869 | mEp->dir = (type & USB_DIR_IN) ? TX : RX; | ||
1870 | |||
1871 | dbg_setup(_usb_addr(mEp), &req); | ||
1872 | |||
1873 | switch (req.bRequest) { | ||
1874 | case USB_REQ_CLEAR_FEATURE: | ||
1875 | if (type != (USB_DIR_OUT|USB_RECIP_ENDPOINT) && | ||
1876 | le16_to_cpu(req.wValue) != USB_ENDPOINT_HALT) | ||
1877 | goto delegate; | ||
1878 | if (req.wLength != 0) | ||
1879 | break; | ||
1880 | num = le16_to_cpu(req.wIndex); | ||
1881 | num &= USB_ENDPOINT_NUMBER_MASK; | ||
1882 | if (!udc->ci13xxx_ep[num].wedge) { | ||
1883 | spin_unlock(udc->lock); | ||
1884 | err = usb_ep_clear_halt( | ||
1885 | &udc->ci13xxx_ep[num].ep); | ||
1886 | spin_lock(udc->lock); | ||
1887 | if (err) | ||
1888 | break; | ||
1889 | } | ||
1890 | err = isr_setup_status_phase(mEp); | ||
1891 | break; | ||
1892 | case USB_REQ_GET_STATUS: | ||
1893 | if (type != (USB_DIR_IN|USB_RECIP_DEVICE) && | ||
1894 | type != (USB_DIR_IN|USB_RECIP_ENDPOINT) && | ||
1895 | type != (USB_DIR_IN|USB_RECIP_INTERFACE)) | ||
1896 | goto delegate; | ||
1897 | if (le16_to_cpu(req.wLength) != 2 || | ||
1898 | le16_to_cpu(req.wValue) != 0) | ||
1899 | break; | ||
1900 | err = isr_get_status_response(mEp, &req); | ||
1901 | break; | ||
1902 | case USB_REQ_SET_ADDRESS: | ||
1903 | if (type != (USB_DIR_OUT|USB_RECIP_DEVICE)) | ||
1904 | goto delegate; | ||
1905 | if (le16_to_cpu(req.wLength) != 0 || | ||
1906 | le16_to_cpu(req.wIndex) != 0) | ||
1907 | break; | ||
1908 | err = hw_usb_set_address((u8)le16_to_cpu(req.wValue)); | ||
1909 | if (err) | ||
1910 | break; | ||
1911 | err = isr_setup_status_phase(mEp); | ||
1912 | break; | ||
1913 | case USB_REQ_SET_FEATURE: | ||
1914 | if (type != (USB_DIR_OUT|USB_RECIP_ENDPOINT) && | ||
1915 | le16_to_cpu(req.wValue) != USB_ENDPOINT_HALT) | ||
1916 | goto delegate; | ||
1917 | if (req.wLength != 0) | ||
1918 | break; | ||
1919 | num = le16_to_cpu(req.wIndex); | ||
1920 | num &= USB_ENDPOINT_NUMBER_MASK; | ||
1921 | |||
1922 | spin_unlock(udc->lock); | ||
1923 | err = usb_ep_set_halt(&udc->ci13xxx_ep[num].ep); | ||
1924 | spin_lock(udc->lock); | ||
1925 | if (err) | ||
1926 | break; | ||
1927 | err = isr_setup_status_phase(mEp); | ||
1928 | break; | ||
1929 | default: | ||
1930 | delegate: | ||
1931 | if (req.wLength == 0) /* no data phase */ | ||
1932 | mEp->dir = TX; | ||
1933 | |||
1934 | spin_unlock(udc->lock); | ||
1935 | err = udc->driver->setup(&udc->gadget, &req); | ||
1936 | spin_lock(udc->lock); | ||
1937 | break; | ||
1938 | } | ||
1939 | |||
1940 | if (err < 0) { | ||
1941 | dbg_event(_usb_addr(mEp), "ERROR", err); | ||
1942 | |||
1943 | spin_unlock(udc->lock); | ||
1944 | if (usb_ep_set_halt(&mEp->ep)) | ||
1945 | err("error: ep_set_halt"); | ||
1946 | spin_lock(udc->lock); | ||
1947 | } | ||
1948 | } | ||
1949 | } | ||
1950 | |||
1951 | /****************************************************************************** | ||
1952 | * ENDPT block | ||
1953 | *****************************************************************************/ | ||
1954 | /** | ||
1955 | * ep_enable: configure endpoint, making it usable | ||
1956 | * | ||
1957 | * Check usb_ep_enable() at "usb_gadget.h" for details | ||
1958 | */ | ||
1959 | static int ep_enable(struct usb_ep *ep, | ||
1960 | const struct usb_endpoint_descriptor *desc) | ||
1961 | { | ||
1962 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
1963 | int direction, retval = 0; | ||
1964 | unsigned long flags; | ||
1965 | |||
1966 | trace("%p, %p", ep, desc); | ||
1967 | |||
1968 | if (ep == NULL || desc == NULL) | ||
1969 | return -EINVAL; | ||
1970 | |||
1971 | spin_lock_irqsave(mEp->lock, flags); | ||
1972 | |||
1973 | /* only internal SW should enable ctrl endpts */ | ||
1974 | |||
1975 | mEp->desc = desc; | ||
1976 | |||
1977 | if (!list_empty(&mEp->qh[mEp->dir].queue)) | ||
1978 | warn("enabling a non-empty endpoint!"); | ||
1979 | |||
1980 | mEp->dir = (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? TX : RX; | ||
1981 | mEp->num = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; | ||
1982 | mEp->type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; | ||
1983 | |||
1984 | mEp->ep.maxpacket = __constant_le16_to_cpu(desc->wMaxPacketSize); | ||
1985 | |||
1986 | direction = mEp->dir; | ||
1987 | do { | ||
1988 | dbg_event(_usb_addr(mEp), "ENABLE", 0); | ||
1989 | |||
1990 | if (mEp->type == USB_ENDPOINT_XFER_CONTROL) | ||
1991 | mEp->qh[mEp->dir].ptr->cap |= QH_IOS; | ||
1992 | else if (mEp->type == USB_ENDPOINT_XFER_ISOC) | ||
1993 | mEp->qh[mEp->dir].ptr->cap &= ~QH_MULT; | ||
1994 | else | ||
1995 | mEp->qh[mEp->dir].ptr->cap &= ~QH_ZLT; | ||
1996 | |||
1997 | mEp->qh[mEp->dir].ptr->cap |= | ||
1998 | (mEp->ep.maxpacket << ffs_nr(QH_MAX_PKT)) & QH_MAX_PKT; | ||
1999 | mEp->qh[mEp->dir].ptr->td.next |= TD_TERMINATE; /* needed? */ | ||
2000 | |||
2001 | retval |= hw_ep_enable(mEp->num, mEp->dir, mEp->type); | ||
2002 | |||
2003 | if (mEp->type == USB_ENDPOINT_XFER_CONTROL) | ||
2004 | mEp->dir = (mEp->dir == TX) ? RX : TX; | ||
2005 | |||
2006 | } while (mEp->dir != direction); | ||
2007 | |||
2008 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2009 | return retval; | ||
2010 | } | ||
2011 | |||
2012 | /** | ||
2013 | * ep_disable: endpoint is no longer usable | ||
2014 | * | ||
2015 | * Check usb_ep_disable() at "usb_gadget.h" for details | ||
2016 | */ | ||
2017 | static int ep_disable(struct usb_ep *ep) | ||
2018 | { | ||
2019 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2020 | int direction, retval = 0; | ||
2021 | unsigned long flags; | ||
2022 | |||
2023 | trace("%p", ep); | ||
2024 | |||
2025 | if (ep == NULL) | ||
2026 | return -EINVAL; | ||
2027 | else if (mEp->desc == NULL) | ||
2028 | return -EBUSY; | ||
2029 | |||
2030 | spin_lock_irqsave(mEp->lock, flags); | ||
2031 | |||
2032 | /* only internal SW should disable ctrl endpts */ | ||
2033 | |||
2034 | direction = mEp->dir; | ||
2035 | do { | ||
2036 | dbg_event(_usb_addr(mEp), "DISABLE", 0); | ||
2037 | |||
2038 | retval |= _ep_nuke(mEp); | ||
2039 | retval |= hw_ep_disable(mEp->num, mEp->dir); | ||
2040 | |||
2041 | if (mEp->type == USB_ENDPOINT_XFER_CONTROL) | ||
2042 | mEp->dir = (mEp->dir == TX) ? RX : TX; | ||
2043 | |||
2044 | } while (mEp->dir != direction); | ||
2045 | |||
2046 | mEp->desc = NULL; | ||
2047 | |||
2048 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2049 | return retval; | ||
2050 | } | ||
2051 | |||
2052 | /** | ||
2053 | * ep_alloc_request: allocate a request object to use with this endpoint | ||
2054 | * | ||
2055 | * Check usb_ep_alloc_request() at "usb_gadget.h" for details | ||
2056 | */ | ||
2057 | static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags) | ||
2058 | { | ||
2059 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2060 | struct ci13xxx_req *mReq = NULL; | ||
2061 | unsigned long flags; | ||
2062 | |||
2063 | trace("%p, %i", ep, gfp_flags); | ||
2064 | |||
2065 | if (ep == NULL) { | ||
2066 | err("EINVAL"); | ||
2067 | return NULL; | ||
2068 | } | ||
2069 | |||
2070 | spin_lock_irqsave(mEp->lock, flags); | ||
2071 | |||
2072 | mReq = kzalloc(sizeof(struct ci13xxx_req), gfp_flags); | ||
2073 | if (mReq != NULL) { | ||
2074 | INIT_LIST_HEAD(&mReq->queue); | ||
2075 | |||
2076 | mReq->ptr = dma_pool_alloc(mEp->td_pool, gfp_flags, | ||
2077 | &mReq->dma); | ||
2078 | if (mReq->ptr == NULL) { | ||
2079 | kfree(mReq); | ||
2080 | mReq = NULL; | ||
2081 | } | ||
2082 | } | ||
2083 | |||
2084 | dbg_event(_usb_addr(mEp), "ALLOC", mReq == NULL); | ||
2085 | |||
2086 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2087 | |||
2088 | return (mReq == NULL) ? NULL : &mReq->req; | ||
2089 | } | ||
2090 | |||
2091 | /** | ||
2092 | * ep_free_request: frees a request object | ||
2093 | * | ||
2094 | * Check usb_ep_free_request() at "usb_gadget.h" for details | ||
2095 | */ | ||
2096 | static void ep_free_request(struct usb_ep *ep, struct usb_request *req) | ||
2097 | { | ||
2098 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2099 | struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req); | ||
2100 | unsigned long flags; | ||
2101 | |||
2102 | trace("%p, %p", ep, req); | ||
2103 | |||
2104 | if (ep == NULL || req == NULL) { | ||
2105 | err("EINVAL"); | ||
2106 | return; | ||
2107 | } else if (!list_empty(&mReq->queue)) { | ||
2108 | err("EBUSY"); | ||
2109 | return; | ||
2110 | } | ||
2111 | |||
2112 | spin_lock_irqsave(mEp->lock, flags); | ||
2113 | |||
2114 | if (mReq->ptr) | ||
2115 | dma_pool_free(mEp->td_pool, mReq->ptr, mReq->dma); | ||
2116 | kfree(mReq); | ||
2117 | |||
2118 | dbg_event(_usb_addr(mEp), "FREE", 0); | ||
2119 | |||
2120 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2121 | } | ||
2122 | |||
2123 | /** | ||
2124 | * ep_queue: queues (submits) an I/O request to an endpoint | ||
2125 | * | ||
2126 | * Check usb_ep_queue()* at usb_gadget.h" for details | ||
2127 | */ | ||
2128 | static int ep_queue(struct usb_ep *ep, struct usb_request *req, | ||
2129 | gfp_t __maybe_unused gfp_flags) | ||
2130 | { | ||
2131 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2132 | struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req); | ||
2133 | int retval = 0; | ||
2134 | unsigned long flags; | ||
2135 | |||
2136 | trace("%p, %p, %X", ep, req, gfp_flags); | ||
2137 | |||
2138 | if (ep == NULL || req == NULL || mEp->desc == NULL) | ||
2139 | return -EINVAL; | ||
2140 | |||
2141 | spin_lock_irqsave(mEp->lock, flags); | ||
2142 | |||
2143 | if (mEp->type == USB_ENDPOINT_XFER_CONTROL && | ||
2144 | !list_empty(&mEp->qh[mEp->dir].queue)) { | ||
2145 | _ep_nuke(mEp); | ||
2146 | retval = -EOVERFLOW; | ||
2147 | warn("endpoint ctrl %X nuked", _usb_addr(mEp)); | ||
2148 | } | ||
2149 | |||
2150 | /* first nuke then test link, e.g. previous status has not sent */ | ||
2151 | if (!list_empty(&mReq->queue)) { | ||
2152 | retval = -EBUSY; | ||
2153 | err("request already in queue"); | ||
2154 | goto done; | ||
2155 | } | ||
2156 | |||
2157 | if (req->length > (4 * PAGE_SIZE)) { | ||
2158 | req->length = (4 * PAGE_SIZE); | ||
2159 | retval = -EMSGSIZE; | ||
2160 | warn("request length truncated"); | ||
2161 | } | ||
2162 | |||
2163 | dbg_queue(_usb_addr(mEp), req, retval); | ||
2164 | |||
2165 | /* push request */ | ||
2166 | mReq->req.status = -EINPROGRESS; | ||
2167 | mReq->req.actual = 0; | ||
2168 | list_add_tail(&mReq->queue, &mEp->qh[mEp->dir].queue); | ||
2169 | |||
2170 | retval = _hardware_enqueue(mEp, mReq); | ||
2171 | if (retval == -EALREADY || retval == -EBUSY) { | ||
2172 | dbg_event(_usb_addr(mEp), "QUEUE", retval); | ||
2173 | retval = 0; | ||
2174 | } | ||
2175 | |||
2176 | done: | ||
2177 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2178 | return retval; | ||
2179 | } | ||
2180 | |||
2181 | /** | ||
2182 | * ep_dequeue: dequeues (cancels, unlinks) an I/O request from an endpoint | ||
2183 | * | ||
2184 | * Check usb_ep_dequeue() at "usb_gadget.h" for details | ||
2185 | */ | ||
2186 | static int ep_dequeue(struct usb_ep *ep, struct usb_request *req) | ||
2187 | { | ||
2188 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2189 | struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req); | ||
2190 | unsigned long flags; | ||
2191 | |||
2192 | trace("%p, %p", ep, req); | ||
2193 | |||
2194 | if (ep == NULL || req == NULL || mEp->desc == NULL || | ||
2195 | list_empty(&mReq->queue) || list_empty(&mEp->qh[mEp->dir].queue)) | ||
2196 | return -EINVAL; | ||
2197 | |||
2198 | spin_lock_irqsave(mEp->lock, flags); | ||
2199 | |||
2200 | dbg_event(_usb_addr(mEp), "DEQUEUE", 0); | ||
2201 | |||
2202 | if (mReq->req.status == -EALREADY) | ||
2203 | _hardware_dequeue(mEp, mReq); | ||
2204 | |||
2205 | /* pop request */ | ||
2206 | list_del_init(&mReq->queue); | ||
2207 | req->status = -ECONNRESET; | ||
2208 | |||
2209 | if (!mReq->req.no_interrupt && mReq->req.complete != NULL) { | ||
2210 | spin_unlock(mEp->lock); | ||
2211 | mReq->req.complete(&mEp->ep, &mReq->req); | ||
2212 | spin_lock(mEp->lock); | ||
2213 | } | ||
2214 | |||
2215 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2216 | return 0; | ||
2217 | } | ||
2218 | |||
2219 | /** | ||
2220 | * ep_set_halt: sets the endpoint halt feature | ||
2221 | * | ||
2222 | * Check usb_ep_set_halt() at "usb_gadget.h" for details | ||
2223 | */ | ||
2224 | static int ep_set_halt(struct usb_ep *ep, int value) | ||
2225 | { | ||
2226 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2227 | int direction, retval = 0; | ||
2228 | unsigned long flags; | ||
2229 | |||
2230 | trace("%p, %i", ep, value); | ||
2231 | |||
2232 | if (ep == NULL || mEp->desc == NULL) | ||
2233 | return -EINVAL; | ||
2234 | |||
2235 | spin_lock_irqsave(mEp->lock, flags); | ||
2236 | |||
2237 | #ifndef STALL_IN | ||
2238 | /* g_file_storage MS compliant but g_zero fails chapter 9 compliance */ | ||
2239 | if (value && mEp->type == USB_ENDPOINT_XFER_BULK && mEp->dir == TX && | ||
2240 | !list_empty(&mEp->qh[mEp->dir].queue)) { | ||
2241 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2242 | return -EAGAIN; | ||
2243 | } | ||
2244 | #endif | ||
2245 | |||
2246 | direction = mEp->dir; | ||
2247 | do { | ||
2248 | dbg_event(_usb_addr(mEp), "HALT", value); | ||
2249 | retval |= hw_ep_set_halt(mEp->num, mEp->dir, value); | ||
2250 | |||
2251 | if (!value) | ||
2252 | mEp->wedge = 0; | ||
2253 | |||
2254 | if (mEp->type == USB_ENDPOINT_XFER_CONTROL) | ||
2255 | mEp->dir = (mEp->dir == TX) ? RX : TX; | ||
2256 | |||
2257 | } while (mEp->dir != direction); | ||
2258 | |||
2259 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2260 | return retval; | ||
2261 | } | ||
2262 | |||
2263 | /** | ||
2264 | * ep_set_wedge: sets the halt feature and ignores clear requests | ||
2265 | * | ||
2266 | * Check usb_ep_set_wedge() at "usb_gadget.h" for details | ||
2267 | */ | ||
2268 | static int ep_set_wedge(struct usb_ep *ep) | ||
2269 | { | ||
2270 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2271 | unsigned long flags; | ||
2272 | |||
2273 | trace("%p", ep); | ||
2274 | |||
2275 | if (ep == NULL || mEp->desc == NULL) | ||
2276 | return -EINVAL; | ||
2277 | |||
2278 | spin_lock_irqsave(mEp->lock, flags); | ||
2279 | |||
2280 | dbg_event(_usb_addr(mEp), "WEDGE", 0); | ||
2281 | mEp->wedge = 1; | ||
2282 | |||
2283 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2284 | |||
2285 | return usb_ep_set_halt(ep); | ||
2286 | } | ||
2287 | |||
2288 | /** | ||
2289 | * ep_fifo_flush: flushes contents of a fifo | ||
2290 | * | ||
2291 | * Check usb_ep_fifo_flush() at "usb_gadget.h" for details | ||
2292 | */ | ||
2293 | static void ep_fifo_flush(struct usb_ep *ep) | ||
2294 | { | ||
2295 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2296 | unsigned long flags; | ||
2297 | |||
2298 | trace("%p", ep); | ||
2299 | |||
2300 | if (ep == NULL) { | ||
2301 | err("%02X: -EINVAL", _usb_addr(mEp)); | ||
2302 | return; | ||
2303 | } | ||
2304 | |||
2305 | spin_lock_irqsave(mEp->lock, flags); | ||
2306 | |||
2307 | dbg_event(_usb_addr(mEp), "FFLUSH", 0); | ||
2308 | hw_ep_flush(mEp->num, mEp->dir); | ||
2309 | |||
2310 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2311 | } | ||
2312 | |||
2313 | /** | ||
2314 | * Endpoint-specific part of the API to the USB controller hardware | ||
2315 | * Check "usb_gadget.h" for details | ||
2316 | */ | ||
2317 | static const struct usb_ep_ops usb_ep_ops = { | ||
2318 | .enable = ep_enable, | ||
2319 | .disable = ep_disable, | ||
2320 | .alloc_request = ep_alloc_request, | ||
2321 | .free_request = ep_free_request, | ||
2322 | .queue = ep_queue, | ||
2323 | .dequeue = ep_dequeue, | ||
2324 | .set_halt = ep_set_halt, | ||
2325 | .set_wedge = ep_set_wedge, | ||
2326 | .fifo_flush = ep_fifo_flush, | ||
2327 | }; | ||
2328 | |||
2329 | /****************************************************************************** | ||
2330 | * GADGET block | ||
2331 | *****************************************************************************/ | ||
2332 | /** | ||
2333 | * Device operations part of the API to the USB controller hardware, | ||
2334 | * which don't involve endpoints (or i/o) | ||
2335 | * Check "usb_gadget.h" for details | ||
2336 | */ | ||
2337 | static const struct usb_gadget_ops usb_gadget_ops; | ||
2338 | |||
2339 | /** | ||
2340 | * usb_gadget_register_driver: register a gadget driver | ||
2341 | * | ||
2342 | * Check usb_gadget_register_driver() at "usb_gadget.h" for details | ||
2343 | * Interrupts are enabled here | ||
2344 | */ | ||
2345 | int usb_gadget_register_driver(struct usb_gadget_driver *driver) | ||
2346 | { | ||
2347 | struct ci13xxx *udc = _udc; | ||
2348 | unsigned long i, k, flags; | ||
2349 | int retval = -ENOMEM; | ||
2350 | |||
2351 | trace("%p", driver); | ||
2352 | |||
2353 | if (driver == NULL || | ||
2354 | driver->bind == NULL || | ||
2355 | driver->unbind == NULL || | ||
2356 | driver->setup == NULL || | ||
2357 | driver->disconnect == NULL || | ||
2358 | driver->suspend == NULL || | ||
2359 | driver->resume == NULL) | ||
2360 | return -EINVAL; | ||
2361 | else if (udc == NULL) | ||
2362 | return -ENODEV; | ||
2363 | else if (udc->driver != NULL) | ||
2364 | return -EBUSY; | ||
2365 | |||
2366 | /* alloc resources */ | ||
2367 | udc->qh_pool = dma_pool_create("ci13xxx_qh", &udc->gadget.dev, | ||
2368 | sizeof(struct ci13xxx_qh), | ||
2369 | 64, PAGE_SIZE); | ||
2370 | if (udc->qh_pool == NULL) | ||
2371 | return -ENOMEM; | ||
2372 | |||
2373 | udc->td_pool = dma_pool_create("ci13xxx_td", &udc->gadget.dev, | ||
2374 | sizeof(struct ci13xxx_td), | ||
2375 | 64, PAGE_SIZE); | ||
2376 | if (udc->td_pool == NULL) { | ||
2377 | dma_pool_destroy(udc->qh_pool); | ||
2378 | udc->qh_pool = NULL; | ||
2379 | return -ENOMEM; | ||
2380 | } | ||
2381 | |||
2382 | spin_lock_irqsave(udc->lock, flags); | ||
2383 | |||
2384 | info("hw_ep_max = %d", hw_ep_max); | ||
2385 | |||
2386 | udc->driver = driver; | ||
2387 | udc->gadget.ops = NULL; | ||
2388 | udc->gadget.dev.driver = NULL; | ||
2389 | |||
2390 | retval = 0; | ||
2391 | for (i = 0; i < hw_ep_max; i++) { | ||
2392 | struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; | ||
2393 | |||
2394 | scnprintf(mEp->name, sizeof(mEp->name), "ep%i", (int)i); | ||
2395 | |||
2396 | mEp->lock = udc->lock; | ||
2397 | mEp->device = &udc->gadget.dev; | ||
2398 | mEp->td_pool = udc->td_pool; | ||
2399 | |||
2400 | mEp->ep.name = mEp->name; | ||
2401 | mEp->ep.ops = &usb_ep_ops; | ||
2402 | mEp->ep.maxpacket = CTRL_PAYLOAD_MAX; | ||
2403 | |||
2404 | /* this allocation cannot be random */ | ||
2405 | for (k = RX; k <= TX; k++) { | ||
2406 | INIT_LIST_HEAD(&mEp->qh[k].queue); | ||
2407 | mEp->qh[k].ptr = dma_pool_alloc(udc->qh_pool, | ||
2408 | GFP_KERNEL, | ||
2409 | &mEp->qh[k].dma); | ||
2410 | if (mEp->qh[k].ptr == NULL) | ||
2411 | retval = -ENOMEM; | ||
2412 | else | ||
2413 | memset(mEp->qh[k].ptr, 0, | ||
2414 | sizeof(*mEp->qh[k].ptr)); | ||
2415 | } | ||
2416 | if (i == 0) | ||
2417 | udc->gadget.ep0 = &mEp->ep; | ||
2418 | else | ||
2419 | list_add_tail(&mEp->ep.ep_list, &udc->gadget.ep_list); | ||
2420 | } | ||
2421 | if (retval) | ||
2422 | goto done; | ||
2423 | |||
2424 | /* bind gadget */ | ||
2425 | driver->driver.bus = NULL; | ||
2426 | udc->gadget.ops = &usb_gadget_ops; | ||
2427 | udc->gadget.dev.driver = &driver->driver; | ||
2428 | |||
2429 | spin_unlock_irqrestore(udc->lock, flags); | ||
2430 | retval = driver->bind(&udc->gadget); /* MAY SLEEP */ | ||
2431 | spin_lock_irqsave(udc->lock, flags); | ||
2432 | |||
2433 | if (retval) { | ||
2434 | udc->gadget.ops = NULL; | ||
2435 | udc->gadget.dev.driver = NULL; | ||
2436 | goto done; | ||
2437 | } | ||
2438 | |||
2439 | retval = hw_device_state(udc->ci13xxx_ep[0].qh[RX].dma); | ||
2440 | |||
2441 | done: | ||
2442 | spin_unlock_irqrestore(udc->lock, flags); | ||
2443 | if (retval) | ||
2444 | usb_gadget_unregister_driver(driver); | ||
2445 | return retval; | ||
2446 | } | ||
2447 | EXPORT_SYMBOL(usb_gadget_register_driver); | ||
2448 | |||
2449 | /** | ||
2450 | * usb_gadget_unregister_driver: unregister a gadget driver | ||
2451 | * | ||
2452 | * Check usb_gadget_unregister_driver() at "usb_gadget.h" for details | ||
2453 | */ | ||
2454 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | ||
2455 | { | ||
2456 | struct ci13xxx *udc = _udc; | ||
2457 | unsigned long i, k, flags; | ||
2458 | |||
2459 | trace("%p", driver); | ||
2460 | |||
2461 | if (driver == NULL || | ||
2462 | driver->bind == NULL || | ||
2463 | driver->unbind == NULL || | ||
2464 | driver->setup == NULL || | ||
2465 | driver->disconnect == NULL || | ||
2466 | driver->suspend == NULL || | ||
2467 | driver->resume == NULL || | ||
2468 | driver != udc->driver) | ||
2469 | return -EINVAL; | ||
2470 | |||
2471 | spin_lock_irqsave(udc->lock, flags); | ||
2472 | |||
2473 | hw_device_state(0); | ||
2474 | |||
2475 | /* unbind gadget */ | ||
2476 | if (udc->gadget.ops != NULL) { | ||
2477 | _gadget_stop_activity(&udc->gadget); | ||
2478 | |||
2479 | spin_unlock_irqrestore(udc->lock, flags); | ||
2480 | driver->unbind(&udc->gadget); /* MAY SLEEP */ | ||
2481 | spin_lock_irqsave(udc->lock, flags); | ||
2482 | |||
2483 | udc->gadget.ops = NULL; | ||
2484 | udc->gadget.dev.driver = NULL; | ||
2485 | } | ||
2486 | |||
2487 | /* free resources */ | ||
2488 | for (i = 0; i < hw_ep_max; i++) { | ||
2489 | struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; | ||
2490 | |||
2491 | if (i == 0) | ||
2492 | udc->gadget.ep0 = NULL; | ||
2493 | else if (!list_empty(&mEp->ep.ep_list)) | ||
2494 | list_del_init(&mEp->ep.ep_list); | ||
2495 | |||
2496 | for (k = RX; k <= TX; k++) | ||
2497 | if (mEp->qh[k].ptr != NULL) | ||
2498 | dma_pool_free(udc->qh_pool, | ||
2499 | mEp->qh[k].ptr, mEp->qh[k].dma); | ||
2500 | } | ||
2501 | |||
2502 | udc->driver = NULL; | ||
2503 | |||
2504 | spin_unlock_irqrestore(udc->lock, flags); | ||
2505 | |||
2506 | if (udc->td_pool != NULL) { | ||
2507 | dma_pool_destroy(udc->td_pool); | ||
2508 | udc->td_pool = NULL; | ||
2509 | } | ||
2510 | if (udc->qh_pool != NULL) { | ||
2511 | dma_pool_destroy(udc->qh_pool); | ||
2512 | udc->qh_pool = NULL; | ||
2513 | } | ||
2514 | |||
2515 | return 0; | ||
2516 | } | ||
2517 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
2518 | |||
2519 | /****************************************************************************** | ||
2520 | * BUS block | ||
2521 | *****************************************************************************/ | ||
2522 | /** | ||
2523 | * udc_irq: global interrupt handler | ||
2524 | * | ||
2525 | * This function returns IRQ_HANDLED if the IRQ has been handled | ||
2526 | * It locks access to registers | ||
2527 | */ | ||
2528 | static irqreturn_t udc_irq(void) | ||
2529 | { | ||
2530 | struct ci13xxx *udc = _udc; | ||
2531 | irqreturn_t retval; | ||
2532 | u32 intr; | ||
2533 | |||
2534 | trace(); | ||
2535 | |||
2536 | if (udc == NULL) { | ||
2537 | err("ENODEV"); | ||
2538 | return IRQ_HANDLED; | ||
2539 | } | ||
2540 | |||
2541 | spin_lock(udc->lock); | ||
2542 | intr = hw_test_and_clear_intr_active(); | ||
2543 | if (intr) { | ||
2544 | isr_statistics.hndl.buf[isr_statistics.hndl.idx++] = intr; | ||
2545 | isr_statistics.hndl.idx &= ISR_MASK; | ||
2546 | isr_statistics.hndl.cnt++; | ||
2547 | |||
2548 | /* order defines priority - do NOT change it */ | ||
2549 | if (USBi_URI & intr) { | ||
2550 | isr_statistics.uri++; | ||
2551 | isr_reset_handler(udc); | ||
2552 | } | ||
2553 | if (USBi_PCI & intr) { | ||
2554 | isr_statistics.pci++; | ||
2555 | udc->gadget.speed = hw_port_is_high_speed() ? | ||
2556 | USB_SPEED_HIGH : USB_SPEED_FULL; | ||
2557 | } | ||
2558 | if (USBi_UEI & intr) | ||
2559 | isr_statistics.uei++; | ||
2560 | if (USBi_UI & intr) { | ||
2561 | isr_statistics.ui++; | ||
2562 | isr_tr_complete_handler(udc); | ||
2563 | } | ||
2564 | if (USBi_SLI & intr) | ||
2565 | isr_statistics.sli++; | ||
2566 | retval = IRQ_HANDLED; | ||
2567 | } else { | ||
2568 | isr_statistics.none++; | ||
2569 | retval = IRQ_NONE; | ||
2570 | } | ||
2571 | spin_unlock(udc->lock); | ||
2572 | |||
2573 | return retval; | ||
2574 | } | ||
2575 | |||
2576 | /** | ||
2577 | * udc_release: driver release function | ||
2578 | * @dev: device | ||
2579 | * | ||
2580 | * Currently does nothing | ||
2581 | */ | ||
2582 | static void udc_release(struct device *dev) | ||
2583 | { | ||
2584 | trace("%p", dev); | ||
2585 | |||
2586 | if (dev == NULL) | ||
2587 | err("EINVAL"); | ||
2588 | } | ||
2589 | |||
2590 | /** | ||
2591 | * udc_probe: parent probe must call this to initialize UDC | ||
2592 | * @dev: parent device | ||
2593 | * @regs: registers base address | ||
2594 | * @name: driver name | ||
2595 | * | ||
2596 | * This function returns an error code | ||
2597 | * No interrupts active, the IRQ has not been requested yet | ||
2598 | * Kernel assumes 32-bit DMA operations by default, no need to dma_set_mask | ||
2599 | */ | ||
2600 | static int udc_probe(struct device *dev, void __iomem *regs, const char *name) | ||
2601 | { | ||
2602 | struct ci13xxx *udc; | ||
2603 | int retval = 0; | ||
2604 | |||
2605 | trace("%p, %p, %p", dev, regs, name); | ||
2606 | |||
2607 | if (dev == NULL || regs == NULL || name == NULL) | ||
2608 | return -EINVAL; | ||
2609 | |||
2610 | udc = kzalloc(sizeof(struct ci13xxx), GFP_KERNEL); | ||
2611 | if (udc == NULL) | ||
2612 | return -ENOMEM; | ||
2613 | |||
2614 | udc->lock = &udc_lock; | ||
2615 | |||
2616 | retval = hw_device_reset(regs); | ||
2617 | if (retval) | ||
2618 | goto done; | ||
2619 | |||
2620 | udc->gadget.ops = NULL; | ||
2621 | udc->gadget.speed = USB_SPEED_UNKNOWN; | ||
2622 | udc->gadget.is_dualspeed = 1; | ||
2623 | udc->gadget.is_otg = 0; | ||
2624 | udc->gadget.name = name; | ||
2625 | |||
2626 | INIT_LIST_HEAD(&udc->gadget.ep_list); | ||
2627 | udc->gadget.ep0 = NULL; | ||
2628 | |||
2629 | strcpy(udc->gadget.dev.bus_id, "gadget"); | ||
2630 | udc->gadget.dev.dma_mask = dev->dma_mask; | ||
2631 | udc->gadget.dev.parent = dev; | ||
2632 | udc->gadget.dev.release = udc_release; | ||
2633 | |||
2634 | retval = device_register(&udc->gadget.dev); | ||
2635 | if (retval) | ||
2636 | goto done; | ||
2637 | |||
2638 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
2639 | retval = dbg_create_files(&udc->gadget.dev); | ||
2640 | #endif | ||
2641 | if (retval) { | ||
2642 | device_unregister(&udc->gadget.dev); | ||
2643 | goto done; | ||
2644 | } | ||
2645 | |||
2646 | _udc = udc; | ||
2647 | return retval; | ||
2648 | |||
2649 | done: | ||
2650 | err("error = %i", retval); | ||
2651 | kfree(udc); | ||
2652 | _udc = NULL; | ||
2653 | return retval; | ||
2654 | } | ||
2655 | |||
2656 | /** | ||
2657 | * udc_remove: parent remove must call this to remove UDC | ||
2658 | * | ||
2659 | * No interrupts active, the IRQ has been released | ||
2660 | */ | ||
2661 | static void udc_remove(void) | ||
2662 | { | ||
2663 | struct ci13xxx *udc = _udc; | ||
2664 | |||
2665 | if (udc == NULL) { | ||
2666 | err("EINVAL"); | ||
2667 | return; | ||
2668 | } | ||
2669 | |||
2670 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
2671 | dbg_remove_files(&udc->gadget.dev); | ||
2672 | #endif | ||
2673 | device_unregister(&udc->gadget.dev); | ||
2674 | |||
2675 | kfree(udc); | ||
2676 | _udc = NULL; | ||
2677 | } | ||
2678 | |||
2679 | /****************************************************************************** | ||
2680 | * PCI block | ||
2681 | *****************************************************************************/ | ||
2682 | /** | ||
2683 | * ci13xxx_pci_irq: interrut handler | ||
2684 | * @irq: irq number | ||
2685 | * @pdev: USB Device Controller interrupt source | ||
2686 | * | ||
2687 | * This function returns IRQ_HANDLED if the IRQ has been handled | ||
2688 | * This is an ISR don't trace, use attribute interface instead | ||
2689 | */ | ||
2690 | static irqreturn_t ci13xxx_pci_irq(int irq, void *pdev) | ||
2691 | { | ||
2692 | if (irq == 0) { | ||
2693 | dev_err(&((struct pci_dev *)pdev)->dev, "Invalid IRQ0 usage!"); | ||
2694 | return IRQ_HANDLED; | ||
2695 | } | ||
2696 | return udc_irq(); | ||
2697 | } | ||
2698 | |||
2699 | /** | ||
2700 | * ci13xxx_pci_probe: PCI probe | ||
2701 | * @pdev: USB device controller being probed | ||
2702 | * @id: PCI hotplug ID connecting controller to UDC framework | ||
2703 | * | ||
2704 | * This function returns an error code | ||
2705 | * Allocates basic PCI resources for this USB device controller, and then | ||
2706 | * invokes the udc_probe() method to start the UDC associated with it | ||
2707 | */ | ||
2708 | static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev, | ||
2709 | const struct pci_device_id *id) | ||
2710 | { | ||
2711 | void __iomem *regs = NULL; | ||
2712 | int retval = 0; | ||
2713 | |||
2714 | if (id == NULL) | ||
2715 | return -EINVAL; | ||
2716 | |||
2717 | retval = pci_enable_device(pdev); | ||
2718 | if (retval) | ||
2719 | goto done; | ||
2720 | |||
2721 | if (!pdev->irq) { | ||
2722 | dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!"); | ||
2723 | retval = -ENODEV; | ||
2724 | goto disable_device; | ||
2725 | } | ||
2726 | |||
2727 | retval = pci_request_regions(pdev, UDC_DRIVER_NAME); | ||
2728 | if (retval) | ||
2729 | goto disable_device; | ||
2730 | |||
2731 | /* BAR 0 holds all the registers */ | ||
2732 | regs = pci_iomap(pdev, 0, 0); | ||
2733 | if (!regs) { | ||
2734 | dev_err(&pdev->dev, "Error mapping memory!"); | ||
2735 | retval = -EFAULT; | ||
2736 | goto release_regions; | ||
2737 | } | ||
2738 | pci_set_drvdata(pdev, (__force void *)regs); | ||
2739 | |||
2740 | pci_set_master(pdev); | ||
2741 | pci_try_set_mwi(pdev); | ||
2742 | |||
2743 | retval = udc_probe(&pdev->dev, regs, UDC_DRIVER_NAME); | ||
2744 | if (retval) | ||
2745 | goto iounmap; | ||
2746 | |||
2747 | /* our device does not have MSI capability */ | ||
2748 | |||
2749 | retval = request_irq(pdev->irq, ci13xxx_pci_irq, IRQF_SHARED, | ||
2750 | UDC_DRIVER_NAME, pdev); | ||
2751 | if (retval) | ||
2752 | goto gadget_remove; | ||
2753 | |||
2754 | return 0; | ||
2755 | |||
2756 | gadget_remove: | ||
2757 | udc_remove(); | ||
2758 | iounmap: | ||
2759 | pci_iounmap(pdev, regs); | ||
2760 | release_regions: | ||
2761 | pci_release_regions(pdev); | ||
2762 | disable_device: | ||
2763 | pci_disable_device(pdev); | ||
2764 | done: | ||
2765 | return retval; | ||
2766 | } | ||
2767 | |||
2768 | /** | ||
2769 | * ci13xxx_pci_remove: PCI remove | ||
2770 | * @pdev: USB Device Controller being removed | ||
2771 | * | ||
2772 | * Reverses the effect of ci13xxx_pci_probe(), | ||
2773 | * first invoking the udc_remove() and then releases | ||
2774 | * all PCI resources allocated for this USB device controller | ||
2775 | */ | ||
2776 | static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev) | ||
2777 | { | ||
2778 | free_irq(pdev->irq, pdev); | ||
2779 | udc_remove(); | ||
2780 | pci_iounmap(pdev, (__force void __iomem *)pci_get_drvdata(pdev)); | ||
2781 | pci_release_regions(pdev); | ||
2782 | pci_disable_device(pdev); | ||
2783 | } | ||
2784 | |||
2785 | /** | ||
2786 | * PCI device table | ||
2787 | * PCI device structure | ||
2788 | * | ||
2789 | * Check "pci.h" for details | ||
2790 | */ | ||
2791 | static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = { | ||
2792 | { PCI_DEVICE(0x153F, 0x1004) }, | ||
2793 | { PCI_DEVICE(0x153F, 0x1006) }, | ||
2794 | { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ } | ||
2795 | }; | ||
2796 | MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table); | ||
2797 | |||
2798 | static struct pci_driver ci13xxx_pci_driver = { | ||
2799 | .name = UDC_DRIVER_NAME, | ||
2800 | .id_table = ci13xxx_pci_id_table, | ||
2801 | .probe = ci13xxx_pci_probe, | ||
2802 | .remove = __devexit_p(ci13xxx_pci_remove), | ||
2803 | }; | ||
2804 | |||
2805 | /** | ||
2806 | * ci13xxx_pci_init: module init | ||
2807 | * | ||
2808 | * Driver load | ||
2809 | */ | ||
2810 | static int __init ci13xxx_pci_init(void) | ||
2811 | { | ||
2812 | return pci_register_driver(&ci13xxx_pci_driver); | ||
2813 | } | ||
2814 | module_init(ci13xxx_pci_init); | ||
2815 | |||
2816 | /** | ||
2817 | * ci13xxx_pci_exit: module exit | ||
2818 | * | ||
2819 | * Driver unload | ||
2820 | */ | ||
2821 | static void __exit ci13xxx_pci_exit(void) | ||
2822 | { | ||
2823 | pci_unregister_driver(&ci13xxx_pci_driver); | ||
2824 | } | ||
2825 | module_exit(ci13xxx_pci_exit); | ||
2826 | |||
2827 | MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>"); | ||
2828 | MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller"); | ||
2829 | MODULE_LICENSE("GPL"); | ||
2830 | MODULE_VERSION("June 2008"); | ||
diff --git a/drivers/usb/gadget/ci13xxx_udc.h b/drivers/usb/gadget/ci13xxx_udc.h new file mode 100644 index 000000000000..4026e9cede34 --- /dev/null +++ b/drivers/usb/gadget/ci13xxx_udc.h | |||
@@ -0,0 +1,195 @@ | |||
1 | /* | ||
2 | * ci13xxx_udc.h - structures, registers, and macros MIPS USB IP core | ||
3 | * | ||
4 | * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. | ||
5 | * | ||
6 | * Author: David Lopo | ||
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 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | * Description: MIPS USB IP core family device controller | ||
13 | * Structures, registers and logging macros | ||
14 | */ | ||
15 | |||
16 | #ifndef _CI13XXX_h_ | ||
17 | #define _CI13XXX_h_ | ||
18 | |||
19 | /****************************************************************************** | ||
20 | * DEFINE | ||
21 | *****************************************************************************/ | ||
22 | #define ENDPT_MAX (16) | ||
23 | #define CTRL_PAYLOAD_MAX (64) | ||
24 | #define RX (0) /* similar to USB_DIR_OUT but can be used as an index */ | ||
25 | #define TX (1) /* similar to USB_DIR_IN but can be used as an index */ | ||
26 | |||
27 | /****************************************************************************** | ||
28 | * STRUCTURES | ||
29 | *****************************************************************************/ | ||
30 | /* DMA layout of transfer descriptors */ | ||
31 | struct ci13xxx_td { | ||
32 | /* 0 */ | ||
33 | u32 next; | ||
34 | #define TD_TERMINATE BIT(0) | ||
35 | /* 1 */ | ||
36 | u32 token; | ||
37 | #define TD_STATUS (0x00FFUL << 0) | ||
38 | #define TD_STATUS_TR_ERR BIT(3) | ||
39 | #define TD_STATUS_DT_ERR BIT(5) | ||
40 | #define TD_STATUS_HALTED BIT(6) | ||
41 | #define TD_STATUS_ACTIVE BIT(7) | ||
42 | #define TD_MULTO (0x0003UL << 10) | ||
43 | #define TD_IOC BIT(15) | ||
44 | #define TD_TOTAL_BYTES (0x7FFFUL << 16) | ||
45 | /* 2 */ | ||
46 | u32 page[5]; | ||
47 | #define TD_CURR_OFFSET (0x0FFFUL << 0) | ||
48 | #define TD_FRAME_NUM (0x07FFUL << 0) | ||
49 | #define TD_RESERVED_MASK (0x0FFFUL << 0) | ||
50 | } __attribute__ ((packed)); | ||
51 | |||
52 | /* DMA layout of queue heads */ | ||
53 | struct ci13xxx_qh { | ||
54 | /* 0 */ | ||
55 | u32 cap; | ||
56 | #define QH_IOS BIT(15) | ||
57 | #define QH_MAX_PKT (0x07FFUL << 16) | ||
58 | #define QH_ZLT BIT(29) | ||
59 | #define QH_MULT (0x0003UL << 30) | ||
60 | /* 1 */ | ||
61 | u32 curr; | ||
62 | /* 2 - 8 */ | ||
63 | struct ci13xxx_td td; | ||
64 | /* 9 */ | ||
65 | u32 RESERVED; | ||
66 | struct usb_ctrlrequest setup; | ||
67 | } __attribute__ ((packed)); | ||
68 | |||
69 | /* Extension of usb_request */ | ||
70 | struct ci13xxx_req { | ||
71 | struct usb_request req; | ||
72 | unsigned map; | ||
73 | struct list_head queue; | ||
74 | struct ci13xxx_td *ptr; | ||
75 | dma_addr_t dma; | ||
76 | }; | ||
77 | |||
78 | /* Extension of usb_ep */ | ||
79 | struct ci13xxx_ep { | ||
80 | struct usb_ep ep; | ||
81 | const struct usb_endpoint_descriptor *desc; | ||
82 | u8 dir; | ||
83 | u8 num; | ||
84 | u8 type; | ||
85 | char name[16]; | ||
86 | struct { | ||
87 | struct list_head queue; | ||
88 | struct ci13xxx_qh *ptr; | ||
89 | dma_addr_t dma; | ||
90 | } qh[2]; | ||
91 | struct usb_request *status; | ||
92 | int wedge; | ||
93 | |||
94 | /* global resources */ | ||
95 | spinlock_t *lock; | ||
96 | struct device *device; | ||
97 | struct dma_pool *td_pool; | ||
98 | }; | ||
99 | |||
100 | /* CI13XXX UDC descriptor & global resources */ | ||
101 | struct ci13xxx { | ||
102 | spinlock_t *lock; /* ctrl register bank access */ | ||
103 | |||
104 | struct dma_pool *qh_pool; /* DMA pool for queue heads */ | ||
105 | struct dma_pool *td_pool; /* DMA pool for transfer descs */ | ||
106 | |||
107 | struct usb_gadget gadget; /* USB slave device */ | ||
108 | struct ci13xxx_ep ci13xxx_ep[ENDPT_MAX]; /* extended endpts */ | ||
109 | |||
110 | struct usb_gadget_driver *driver; /* 3rd party gadget driver */ | ||
111 | }; | ||
112 | |||
113 | /****************************************************************************** | ||
114 | * REGISTERS | ||
115 | *****************************************************************************/ | ||
116 | /* register size */ | ||
117 | #define REG_BITS (32) | ||
118 | |||
119 | /* HCCPARAMS */ | ||
120 | #define HCCPARAMS_LEN BIT(17) | ||
121 | |||
122 | /* DCCPARAMS */ | ||
123 | #define DCCPARAMS_DEN (0x1F << 0) | ||
124 | #define DCCPARAMS_DC BIT(7) | ||
125 | |||
126 | /* TESTMODE */ | ||
127 | #define TESTMODE_FORCE BIT(0) | ||
128 | |||
129 | /* USBCMD */ | ||
130 | #define USBCMD_RS BIT(0) | ||
131 | #define USBCMD_RST BIT(1) | ||
132 | #define USBCMD_SUTW BIT(13) | ||
133 | |||
134 | /* USBSTS & USBINTR */ | ||
135 | #define USBi_UI BIT(0) | ||
136 | #define USBi_UEI BIT(1) | ||
137 | #define USBi_PCI BIT(2) | ||
138 | #define USBi_URI BIT(6) | ||
139 | #define USBi_SLI BIT(8) | ||
140 | |||
141 | /* DEVICEADDR */ | ||
142 | #define DEVICEADDR_USBADRA BIT(24) | ||
143 | #define DEVICEADDR_USBADR (0x7FUL << 25) | ||
144 | |||
145 | /* PORTSC */ | ||
146 | #define PORTSC_SUSP BIT(7) | ||
147 | #define PORTSC_HSP BIT(9) | ||
148 | #define PORTSC_PTC (0x0FUL << 16) | ||
149 | |||
150 | /* DEVLC */ | ||
151 | #define DEVLC_PSPD (0x03UL << 25) | ||
152 | #define DEVLC_PSPD_HS (0x02UL << 25) | ||
153 | |||
154 | /* USBMODE */ | ||
155 | #define USBMODE_CM (0x03UL << 0) | ||
156 | #define USBMODE_CM_IDLE (0x00UL << 0) | ||
157 | #define USBMODE_CM_DEVICE (0x02UL << 0) | ||
158 | #define USBMODE_CM_HOST (0x03UL << 0) | ||
159 | #define USBMODE_SLOM BIT(3) | ||
160 | |||
161 | /* ENDPTCTRL */ | ||
162 | #define ENDPTCTRL_RXS BIT(0) | ||
163 | #define ENDPTCTRL_RXT (0x03UL << 2) | ||
164 | #define ENDPTCTRL_RXR BIT(6) /* reserved for port 0 */ | ||
165 | #define ENDPTCTRL_RXE BIT(7) | ||
166 | #define ENDPTCTRL_TXS BIT(16) | ||
167 | #define ENDPTCTRL_TXT (0x03UL << 18) | ||
168 | #define ENDPTCTRL_TXR BIT(22) /* reserved for port 0 */ | ||
169 | #define ENDPTCTRL_TXE BIT(23) | ||
170 | |||
171 | /****************************************************************************** | ||
172 | * LOGGING | ||
173 | *****************************************************************************/ | ||
174 | #define ci13xxx_printk(level, format, args...) \ | ||
175 | do { \ | ||
176 | if (_udc == NULL) \ | ||
177 | printk(level "[%s] " format "\n", __func__, ## args); \ | ||
178 | else \ | ||
179 | dev_printk(level, _udc->gadget.dev.parent, \ | ||
180 | "[%s] " format "\n", __func__, ## args); \ | ||
181 | } while (0) | ||
182 | |||
183 | #define err(format, args...) ci13xxx_printk(KERN_ERR, format, ## args) | ||
184 | #define warn(format, args...) ci13xxx_printk(KERN_WARNING, format, ## args) | ||
185 | #define info(format, args...) ci13xxx_printk(KERN_INFO, format, ## args) | ||
186 | |||
187 | #ifdef TRACE | ||
188 | #define trace(format, args...) ci13xxx_printk(KERN_DEBUG, format, ## args) | ||
189 | #define dbg_trace(format, args...) dev_dbg(dev, format, ##args) | ||
190 | #else | ||
191 | #define trace(format, args...) do {} while (0) | ||
192 | #define dbg_trace(format, args...) do {} while (0) | ||
193 | #endif | ||
194 | |||
195 | #endif /* _CI13XXX_h_ */ | ||
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index 9462e30192d8..a36b1175b18d 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c | |||
@@ -161,7 +161,7 @@ ep_matches ( | |||
161 | /* report address */ | 161 | /* report address */ |
162 | desc->bEndpointAddress &= USB_DIR_IN; | 162 | desc->bEndpointAddress &= USB_DIR_IN; |
163 | if (isdigit (ep->name [2])) { | 163 | if (isdigit (ep->name [2])) { |
164 | u8 num = simple_strtol (&ep->name [2], NULL, 10); | 164 | u8 num = simple_strtoul (&ep->name [2], NULL, 10); |
165 | desc->bEndpointAddress |= num; | 165 | desc->bEndpointAddress |= num; |
166 | #ifdef MANY_ENDPOINTS | 166 | #ifdef MANY_ENDPOINTS |
167 | } else if (desc->bEndpointAddress & USB_DIR_IN) { | 167 | } else if (desc->bEndpointAddress & USB_DIR_IN) { |
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c index d8fc9b32fe36..c0916c7b217e 100644 --- a/drivers/usb/gadget/f_phonet.c +++ b/drivers/usb/gadget/f_phonet.c | |||
@@ -279,6 +279,13 @@ static int pn_net_mtu(struct net_device *dev, int new_mtu) | |||
279 | return err; | 279 | return err; |
280 | } | 280 | } |
281 | 281 | ||
282 | static const struct net_device_ops pn_netdev_ops = { | ||
283 | .ndo_open = pn_net_open, | ||
284 | .ndo_stop = pn_net_close, | ||
285 | .ndo_start_xmit = pn_net_xmit, | ||
286 | .ndo_change_mtu = pn_net_mtu, | ||
287 | }; | ||
288 | |||
282 | static void pn_net_setup(struct net_device *dev) | 289 | static void pn_net_setup(struct net_device *dev) |
283 | { | 290 | { |
284 | dev->features = 0; | 291 | dev->features = 0; |
@@ -290,12 +297,9 @@ static void pn_net_setup(struct net_device *dev) | |||
290 | dev->addr_len = 1; | 297 | dev->addr_len = 1; |
291 | dev->tx_queue_len = 1; | 298 | dev->tx_queue_len = 1; |
292 | 299 | ||
300 | dev->netdev_ops = &pn_netdev_ops; | ||
293 | dev->destructor = free_netdev; | 301 | dev->destructor = free_netdev; |
294 | dev->header_ops = &phonet_header_ops; | 302 | dev->header_ops = &phonet_header_ops; |
295 | dev->open = pn_net_open; | ||
296 | dev->stop = pn_net_close; | ||
297 | dev->hard_start_xmit = pn_net_xmit; /* mandatory */ | ||
298 | dev->change_mtu = pn_net_mtu; | ||
299 | } | 303 | } |
300 | 304 | ||
301 | /*-------------------------------------------------------------------------*/ | 305 | /*-------------------------------------------------------------------------*/ |
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index 2e71368f45b4..b10fa31cc915 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * file_storage.c -- File-backed USB Storage Gadget, for USB development | 2 | * file_storage.c -- File-backed USB Storage Gadget, for USB development |
3 | * | 3 | * |
4 | * Copyright (C) 2003-2007 Alan Stern | 4 | * Copyright (C) 2003-2008 Alan Stern |
5 | * All rights reserved. | 5 | * All rights reserved. |
6 | * | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
@@ -38,16 +38,17 @@ | |||
38 | 38 | ||
39 | /* | 39 | /* |
40 | * The File-backed Storage Gadget acts as a USB Mass Storage device, | 40 | * The File-backed Storage Gadget acts as a USB Mass Storage device, |
41 | * appearing to the host as a disk drive. In addition to providing an | 41 | * appearing to the host as a disk drive or as a CD-ROM drive. In addition |
42 | * example of a genuinely useful gadget driver for a USB device, it also | 42 | * to providing an example of a genuinely useful gadget driver for a USB |
43 | * illustrates a technique of double-buffering for increased throughput. | 43 | * device, it also illustrates a technique of double-buffering for increased |
44 | * Last but not least, it gives an easy way to probe the behavior of the | 44 | * throughput. Last but not least, it gives an easy way to probe the |
45 | * Mass Storage drivers in a USB host. | 45 | * behavior of the Mass Storage drivers in a USB host. |
46 | * | 46 | * |
47 | * Backing storage is provided by a regular file or a block device, specified | 47 | * Backing storage is provided by a regular file or a block device, specified |
48 | * by the "file" module parameter. Access can be limited to read-only by | 48 | * by the "file" module parameter. Access can be limited to read-only by |
49 | * setting the optional "ro" module parameter. The gadget will indicate that | 49 | * setting the optional "ro" module parameter. (For CD-ROM emulation, |
50 | * it has removable media if the optional "removable" module parameter is set. | 50 | * access is always read-only.) The gadget will indicate that it has |
51 | * removable media if the optional "removable" module parameter is set. | ||
51 | * | 52 | * |
52 | * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI), | 53 | * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI), |
53 | * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected | 54 | * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected |
@@ -64,7 +65,12 @@ | |||
64 | * The default number of LUNs is taken from the number of "file" elements; | 65 | * The default number of LUNs is taken from the number of "file" elements; |
65 | * it is 1 if "file" is not given. If "removable" is not set then a backing | 66 | * it is 1 if "file" is not given. If "removable" is not set then a backing |
66 | * file must be specified for each LUN. If it is set, then an unspecified | 67 | * file must be specified for each LUN. If it is set, then an unspecified |
67 | * or empty backing filename means the LUN's medium is not loaded. | 68 | * or empty backing filename means the LUN's medium is not loaded. Ideally |
69 | * each LUN would be settable independently as a disk drive or a CD-ROM | ||
70 | * drive, but currently all LUNs have to be the same type. The CD-ROM | ||
71 | * emulation includes a single data track and no audio tracks; hence there | ||
72 | * need be only one backing file per LUN. Note also that the CD-ROM block | ||
73 | * length is set to 512 rather than the more common value 2048. | ||
68 | * | 74 | * |
69 | * Requirements are modest; only a bulk-in and a bulk-out endpoint are | 75 | * Requirements are modest; only a bulk-in and a bulk-out endpoint are |
70 | * needed (an interrupt-out endpoint is also needed for CBI). The memory | 76 | * needed (an interrupt-out endpoint is also needed for CBI). The memory |
@@ -91,6 +97,8 @@ | |||
91 | * USB device controller (usually true), | 97 | * USB device controller (usually true), |
92 | * boolean to permit the driver to halt | 98 | * boolean to permit the driver to halt |
93 | * bulk endpoints | 99 | * bulk endpoints |
100 | * cdrom Default false, boolean for whether to emulate | ||
101 | * a CD-ROM drive | ||
94 | * transport=XXX Default BBB, transport name (CB, CBI, or BBB) | 102 | * transport=XXX Default BBB, transport name (CB, CBI, or BBB) |
95 | * protocol=YYY Default SCSI, protocol name (RBC, 8020 or | 103 | * protocol=YYY Default SCSI, protocol name (RBC, 8020 or |
96 | * ATAPI, QIC, UFI, 8070, or SCSI; | 104 | * ATAPI, QIC, UFI, 8070, or SCSI; |
@@ -103,15 +111,16 @@ | |||
103 | * PAGE_CACHE_SIZE) | 111 | * PAGE_CACHE_SIZE) |
104 | * | 112 | * |
105 | * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", | 113 | * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", |
106 | * "removable", "luns", and "stall" options are available; default values | 114 | * "removable", "luns", "stall", and "cdrom" options are available; default |
107 | * are used for everything else. | 115 | * values are used for everything else. |
108 | * | 116 | * |
109 | * The pathnames of the backing files and the ro settings are available in | 117 | * The pathnames of the backing files and the ro settings are available in |
110 | * the attribute files "file" and "ro" in the lun<n> subdirectory of the | 118 | * the attribute files "file" and "ro" in the lun<n> subdirectory of the |
111 | * gadget's sysfs directory. If the "removable" option is set, writing to | 119 | * gadget's sysfs directory. If the "removable" option is set, writing to |
112 | * these files will simulate ejecting/loading the medium (writing an empty | 120 | * these files will simulate ejecting/loading the medium (writing an empty |
113 | * line means eject) and adjusting a write-enable tab. Changes to the ro | 121 | * line means eject) and adjusting a write-enable tab. Changes to the ro |
114 | * setting are not allowed when the medium is loaded. | 122 | * setting are not allowed when the medium is loaded or if CD-ROM emulation |
123 | * is being used. | ||
115 | * | 124 | * |
116 | * This gadget driver is heavily based on "Gadget Zero" by David Brownell. | 125 | * This gadget driver is heavily based on "Gadget Zero" by David Brownell. |
117 | * The driver's SCSI command interface was based on the "Information | 126 | * The driver's SCSI command interface was based on the "Information |
@@ -261,7 +270,7 @@ | |||
261 | 270 | ||
262 | #define DRIVER_DESC "File-backed Storage Gadget" | 271 | #define DRIVER_DESC "File-backed Storage Gadget" |
263 | #define DRIVER_NAME "g_file_storage" | 272 | #define DRIVER_NAME "g_file_storage" |
264 | #define DRIVER_VERSION "7 August 2007" | 273 | #define DRIVER_VERSION "20 November 2008" |
265 | 274 | ||
266 | static const char longname[] = DRIVER_DESC; | 275 | static const char longname[] = DRIVER_DESC; |
267 | static const char shortname[] = DRIVER_NAME; | 276 | static const char shortname[] = DRIVER_NAME; |
@@ -341,6 +350,7 @@ static struct { | |||
341 | 350 | ||
342 | int removable; | 351 | int removable; |
343 | int can_stall; | 352 | int can_stall; |
353 | int cdrom; | ||
344 | 354 | ||
345 | char *transport_parm; | 355 | char *transport_parm; |
346 | char *protocol_parm; | 356 | char *protocol_parm; |
@@ -359,6 +369,7 @@ static struct { | |||
359 | .protocol_parm = "SCSI", | 369 | .protocol_parm = "SCSI", |
360 | .removable = 0, | 370 | .removable = 0, |
361 | .can_stall = 1, | 371 | .can_stall = 1, |
372 | .cdrom = 0, | ||
362 | .vendor = DRIVER_VENDOR_ID, | 373 | .vendor = DRIVER_VENDOR_ID, |
363 | .product = DRIVER_PRODUCT_ID, | 374 | .product = DRIVER_PRODUCT_ID, |
364 | .release = 0xffff, // Use controller chip type | 375 | .release = 0xffff, // Use controller chip type |
@@ -382,6 +393,9 @@ MODULE_PARM_DESC(removable, "true to simulate removable media"); | |||
382 | module_param_named(stall, mod_data.can_stall, bool, S_IRUGO); | 393 | module_param_named(stall, mod_data.can_stall, bool, S_IRUGO); |
383 | MODULE_PARM_DESC(stall, "false to prevent bulk stalls"); | 394 | MODULE_PARM_DESC(stall, "false to prevent bulk stalls"); |
384 | 395 | ||
396 | module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO); | ||
397 | MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk"); | ||
398 | |||
385 | 399 | ||
386 | /* In the non-TEST version, only the module parameters listed above | 400 | /* In the non-TEST version, only the module parameters listed above |
387 | * are available. */ | 401 | * are available. */ |
@@ -411,6 +425,10 @@ MODULE_PARM_DESC(buflen, "I/O buffer size"); | |||
411 | 425 | ||
412 | /*-------------------------------------------------------------------------*/ | 426 | /*-------------------------------------------------------------------------*/ |
413 | 427 | ||
428 | /* SCSI device types */ | ||
429 | #define TYPE_DISK 0x00 | ||
430 | #define TYPE_CDROM 0x05 | ||
431 | |||
414 | /* USB protocol value = the transport method */ | 432 | /* USB protocol value = the transport method */ |
415 | #define USB_PR_CBI 0x00 // Control/Bulk/Interrupt | 433 | #define USB_PR_CBI 0x00 // Control/Bulk/Interrupt |
416 | #define USB_PR_CB 0x01 // Control/Bulk w/o interrupt | 434 | #define USB_PR_CB 0x01 // Control/Bulk w/o interrupt |
@@ -487,6 +505,8 @@ struct interrupt_data { | |||
487 | #define SC_READ_12 0xa8 | 505 | #define SC_READ_12 0xa8 |
488 | #define SC_READ_CAPACITY 0x25 | 506 | #define SC_READ_CAPACITY 0x25 |
489 | #define SC_READ_FORMAT_CAPACITIES 0x23 | 507 | #define SC_READ_FORMAT_CAPACITIES 0x23 |
508 | #define SC_READ_HEADER 0x44 | ||
509 | #define SC_READ_TOC 0x43 | ||
490 | #define SC_RELEASE 0x17 | 510 | #define SC_RELEASE 0x17 |
491 | #define SC_REQUEST_SENSE 0x03 | 511 | #define SC_REQUEST_SENSE 0x03 |
492 | #define SC_RESERVE 0x16 | 512 | #define SC_RESERVE 0x16 |
@@ -2006,23 +2026,28 @@ static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh) | |||
2006 | u8 *buf = (u8 *) bh->buf; | 2026 | u8 *buf = (u8 *) bh->buf; |
2007 | 2027 | ||
2008 | static char vendor_id[] = "Linux "; | 2028 | static char vendor_id[] = "Linux "; |
2009 | static char product_id[] = "File-Stor Gadget"; | 2029 | static char product_disk_id[] = "File-Stor Gadget"; |
2030 | static char product_cdrom_id[] = "File-CD Gadget "; | ||
2010 | 2031 | ||
2011 | if (!fsg->curlun) { // Unsupported LUNs are okay | 2032 | if (!fsg->curlun) { // Unsupported LUNs are okay |
2012 | fsg->bad_lun_okay = 1; | 2033 | fsg->bad_lun_okay = 1; |
2013 | memset(buf, 0, 36); | 2034 | memset(buf, 0, 36); |
2014 | buf[0] = 0x7f; // Unsupported, no device-type | 2035 | buf[0] = 0x7f; // Unsupported, no device-type |
2036 | buf[4] = 31; // Additional length | ||
2015 | return 36; | 2037 | return 36; |
2016 | } | 2038 | } |
2017 | 2039 | ||
2018 | memset(buf, 0, 8); // Non-removable, direct-access device | 2040 | memset(buf, 0, 8); |
2041 | buf[0] = (mod_data.cdrom ? TYPE_CDROM : TYPE_DISK); | ||
2019 | if (mod_data.removable) | 2042 | if (mod_data.removable) |
2020 | buf[1] = 0x80; | 2043 | buf[1] = 0x80; |
2021 | buf[2] = 2; // ANSI SCSI level 2 | 2044 | buf[2] = 2; // ANSI SCSI level 2 |
2022 | buf[3] = 2; // SCSI-2 INQUIRY data format | 2045 | buf[3] = 2; // SCSI-2 INQUIRY data format |
2023 | buf[4] = 31; // Additional length | 2046 | buf[4] = 31; // Additional length |
2024 | // No special options | 2047 | // No special options |
2025 | sprintf(buf + 8, "%-8s%-16s%04x", vendor_id, product_id, | 2048 | sprintf(buf + 8, "%-8s%-16s%04x", vendor_id, |
2049 | (mod_data.cdrom ? product_cdrom_id : | ||
2050 | product_disk_id), | ||
2026 | mod_data.release); | 2051 | mod_data.release); |
2027 | return 36; | 2052 | return 36; |
2028 | } | 2053 | } |
@@ -2101,6 +2126,75 @@ static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh) | |||
2101 | } | 2126 | } |
2102 | 2127 | ||
2103 | 2128 | ||
2129 | static void store_cdrom_address(u8 *dest, int msf, u32 addr) | ||
2130 | { | ||
2131 | if (msf) { | ||
2132 | /* Convert to Minutes-Seconds-Frames */ | ||
2133 | addr >>= 2; /* Convert to 2048-byte frames */ | ||
2134 | addr += 2*75; /* Lead-in occupies 2 seconds */ | ||
2135 | dest[3] = addr % 75; /* Frames */ | ||
2136 | addr /= 75; | ||
2137 | dest[2] = addr % 60; /* Seconds */ | ||
2138 | addr /= 60; | ||
2139 | dest[1] = addr; /* Minutes */ | ||
2140 | dest[0] = 0; /* Reserved */ | ||
2141 | } else { | ||
2142 | /* Absolute sector */ | ||
2143 | put_be32(dest, addr); | ||
2144 | } | ||
2145 | } | ||
2146 | |||
2147 | static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh) | ||
2148 | { | ||
2149 | struct lun *curlun = fsg->curlun; | ||
2150 | int msf = fsg->cmnd[1] & 0x02; | ||
2151 | u32 lba = get_be32(&fsg->cmnd[2]); | ||
2152 | u8 *buf = (u8 *) bh->buf; | ||
2153 | |||
2154 | if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */ | ||
2155 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; | ||
2156 | return -EINVAL; | ||
2157 | } | ||
2158 | if (lba >= curlun->num_sectors) { | ||
2159 | curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | ||
2160 | return -EINVAL; | ||
2161 | } | ||
2162 | |||
2163 | memset(buf, 0, 8); | ||
2164 | buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */ | ||
2165 | store_cdrom_address(&buf[4], msf, lba); | ||
2166 | return 8; | ||
2167 | } | ||
2168 | |||
2169 | |||
2170 | static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh) | ||
2171 | { | ||
2172 | struct lun *curlun = fsg->curlun; | ||
2173 | int msf = fsg->cmnd[1] & 0x02; | ||
2174 | int start_track = fsg->cmnd[6]; | ||
2175 | u8 *buf = (u8 *) bh->buf; | ||
2176 | |||
2177 | if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */ | ||
2178 | start_track > 1) { | ||
2179 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; | ||
2180 | return -EINVAL; | ||
2181 | } | ||
2182 | |||
2183 | memset(buf, 0, 20); | ||
2184 | buf[1] = (20-2); /* TOC data length */ | ||
2185 | buf[2] = 1; /* First track number */ | ||
2186 | buf[3] = 1; /* Last track number */ | ||
2187 | buf[5] = 0x16; /* Data track, copying allowed */ | ||
2188 | buf[6] = 0x01; /* Only track is number 1 */ | ||
2189 | store_cdrom_address(&buf[8], msf, 0); | ||
2190 | |||
2191 | buf[13] = 0x16; /* Lead-out track is data */ | ||
2192 | buf[14] = 0xAA; /* Lead-out track number */ | ||
2193 | store_cdrom_address(&buf[16], msf, curlun->num_sectors); | ||
2194 | return 20; | ||
2195 | } | ||
2196 | |||
2197 | |||
2104 | static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh) | 2198 | static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh) |
2105 | { | 2199 | { |
2106 | struct lun *curlun = fsg->curlun; | 2200 | struct lun *curlun = fsg->curlun; |
@@ -2848,6 +2942,26 @@ static int do_scsi_command(struct fsg_dev *fsg) | |||
2848 | reply = do_read_capacity(fsg, bh); | 2942 | reply = do_read_capacity(fsg, bh); |
2849 | break; | 2943 | break; |
2850 | 2944 | ||
2945 | case SC_READ_HEADER: | ||
2946 | if (!mod_data.cdrom) | ||
2947 | goto unknown_cmnd; | ||
2948 | fsg->data_size_from_cmnd = get_be16(&fsg->cmnd[7]); | ||
2949 | if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, | ||
2950 | (3<<7) | (0x1f<<1), 1, | ||
2951 | "READ HEADER")) == 0) | ||
2952 | reply = do_read_header(fsg, bh); | ||
2953 | break; | ||
2954 | |||
2955 | case SC_READ_TOC: | ||
2956 | if (!mod_data.cdrom) | ||
2957 | goto unknown_cmnd; | ||
2958 | fsg->data_size_from_cmnd = get_be16(&fsg->cmnd[7]); | ||
2959 | if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, | ||
2960 | (7<<6) | (1<<1), 1, | ||
2961 | "READ TOC")) == 0) | ||
2962 | reply = do_read_toc(fsg, bh); | ||
2963 | break; | ||
2964 | |||
2851 | case SC_READ_FORMAT_CAPACITIES: | 2965 | case SC_READ_FORMAT_CAPACITIES: |
2852 | fsg->data_size_from_cmnd = get_be16(&fsg->cmnd[7]); | 2966 | fsg->data_size_from_cmnd = get_be16(&fsg->cmnd[7]); |
2853 | if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, | 2967 | if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, |
@@ -2933,6 +3047,7 @@ static int do_scsi_command(struct fsg_dev *fsg) | |||
2933 | // Fall through | 3047 | // Fall through |
2934 | 3048 | ||
2935 | default: | 3049 | default: |
3050 | unknown_cmnd: | ||
2936 | fsg->data_size_from_cmnd = 0; | 3051 | fsg->data_size_from_cmnd = 0; |
2937 | sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]); | 3052 | sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]); |
2938 | if ((reply = check_command(fsg, fsg->cmnd_size, | 3053 | if ((reply = check_command(fsg, fsg->cmnd_size, |
@@ -3498,6 +3613,7 @@ static int open_backing_file(struct lun *curlun, const char *filename) | |||
3498 | struct inode *inode = NULL; | 3613 | struct inode *inode = NULL; |
3499 | loff_t size; | 3614 | loff_t size; |
3500 | loff_t num_sectors; | 3615 | loff_t num_sectors; |
3616 | loff_t min_sectors; | ||
3501 | 3617 | ||
3502 | /* R/W if we can, R/O if we must */ | 3618 | /* R/W if we can, R/O if we must */ |
3503 | ro = curlun->ro; | 3619 | ro = curlun->ro; |
@@ -3541,8 +3657,19 @@ static int open_backing_file(struct lun *curlun, const char *filename) | |||
3541 | rc = (int) size; | 3657 | rc = (int) size; |
3542 | goto out; | 3658 | goto out; |
3543 | } | 3659 | } |
3544 | num_sectors = size >> 9; // File size in 512-byte sectors | 3660 | num_sectors = size >> 9; // File size in 512-byte blocks |
3545 | if (num_sectors == 0) { | 3661 | min_sectors = 1; |
3662 | if (mod_data.cdrom) { | ||
3663 | num_sectors &= ~3; // Reduce to a multiple of 2048 | ||
3664 | min_sectors = 300*4; // Smallest track is 300 frames | ||
3665 | if (num_sectors >= 256*60*75*4) { | ||
3666 | num_sectors = (256*60*75 - 1) * 4; | ||
3667 | LINFO(curlun, "file too big: %s\n", filename); | ||
3668 | LINFO(curlun, "using only first %d blocks\n", | ||
3669 | (int) num_sectors); | ||
3670 | } | ||
3671 | } | ||
3672 | if (num_sectors < min_sectors) { | ||
3546 | LINFO(curlun, "file too small: %s\n", filename); | 3673 | LINFO(curlun, "file too small: %s\n", filename); |
3547 | rc = -ETOOSMALL; | 3674 | rc = -ETOOSMALL; |
3548 | goto out; | 3675 | goto out; |
@@ -3845,9 +3972,12 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3845 | goto out; | 3972 | goto out; |
3846 | 3973 | ||
3847 | if (mod_data.removable) { // Enable the store_xxx attributes | 3974 | if (mod_data.removable) { // Enable the store_xxx attributes |
3848 | dev_attr_ro.attr.mode = dev_attr_file.attr.mode = 0644; | 3975 | dev_attr_file.attr.mode = 0644; |
3849 | dev_attr_ro.store = store_ro; | ||
3850 | dev_attr_file.store = store_file; | 3976 | dev_attr_file.store = store_file; |
3977 | if (!mod_data.cdrom) { | ||
3978 | dev_attr_ro.attr.mode = 0644; | ||
3979 | dev_attr_ro.store = store_ro; | ||
3980 | } | ||
3851 | } | 3981 | } |
3852 | 3982 | ||
3853 | /* Find out how many LUNs there should be */ | 3983 | /* Find out how many LUNs there should be */ |
@@ -3872,6 +4002,8 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3872 | for (i = 0; i < fsg->nluns; ++i) { | 4002 | for (i = 0; i < fsg->nluns; ++i) { |
3873 | curlun = &fsg->luns[i]; | 4003 | curlun = &fsg->luns[i]; |
3874 | curlun->ro = mod_data.ro[i]; | 4004 | curlun->ro = mod_data.ro[i]; |
4005 | if (mod_data.cdrom) | ||
4006 | curlun->ro = 1; | ||
3875 | curlun->dev.release = lun_release; | 4007 | curlun->dev.release = lun_release; |
3876 | curlun->dev.parent = &gadget->dev; | 4008 | curlun->dev.parent = &gadget->dev; |
3877 | curlun->dev.driver = &fsg_driver.driver; | 4009 | curlun->dev.driver = &fsg_driver.driver; |
@@ -4031,9 +4163,9 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
4031 | mod_data.protocol_name, mod_data.protocol_type); | 4163 | mod_data.protocol_name, mod_data.protocol_type); |
4032 | DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n", | 4164 | DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n", |
4033 | mod_data.vendor, mod_data.product, mod_data.release); | 4165 | mod_data.vendor, mod_data.product, mod_data.release); |
4034 | DBG(fsg, "removable=%d, stall=%d, buflen=%u\n", | 4166 | DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n", |
4035 | mod_data.removable, mod_data.can_stall, | 4167 | mod_data.removable, mod_data.can_stall, |
4036 | mod_data.buflen); | 4168 | mod_data.cdrom, mod_data.buflen); |
4037 | DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task)); | 4169 | DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task)); |
4038 | 4170 | ||
4039 | set_bit(REGISTERED, &fsg->atomic_bitflags); | 4171 | set_bit(REGISTERED, &fsg->atomic_bitflags); |
@@ -4050,6 +4182,7 @@ out: | |||
4050 | fsg->state = FSG_STATE_TERMINATED; // The thread is dead | 4182 | fsg->state = FSG_STATE_TERMINATED; // The thread is dead |
4051 | fsg_unbind(gadget); | 4183 | fsg_unbind(gadget); |
4052 | close_all_backing_files(fsg); | 4184 | close_all_backing_files(fsg); |
4185 | complete(&fsg->thread_notifier); | ||
4053 | return rc; | 4186 | return rc; |
4054 | } | 4187 | } |
4055 | 4188 | ||
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c index f40272565098..d6c5bcd40064 100644 --- a/drivers/usb/gadget/fsl_qe_udc.c +++ b/drivers/usb/gadget/fsl_qe_udc.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/ioport.h> | 26 | #include <linux/ioport.h> |
27 | #include <linux/types.h> | 27 | #include <linux/types.h> |
28 | #include <linux/errno.h> | 28 | #include <linux/errno.h> |
29 | #include <linux/err.h> | ||
29 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
30 | #include <linux/list.h> | 31 | #include <linux/list.h> |
31 | #include <linux/interrupt.h> | 32 | #include <linux/interrupt.h> |
@@ -370,6 +371,9 @@ static int qe_ep_bd_init(struct qe_udc *udc, unsigned char pipe_num) | |||
370 | /* alloc multi-ram for BD rings and set the ep parameters */ | 371 | /* alloc multi-ram for BD rings and set the ep parameters */ |
371 | tmp_addr = cpm_muram_alloc(sizeof(struct qe_bd) * (bdring_len + | 372 | tmp_addr = cpm_muram_alloc(sizeof(struct qe_bd) * (bdring_len + |
372 | USB_BDRING_LEN_TX), QE_ALIGNMENT_OF_BD); | 373 | USB_BDRING_LEN_TX), QE_ALIGNMENT_OF_BD); |
374 | if (IS_ERR_VALUE(tmp_addr)) | ||
375 | return -ENOMEM; | ||
376 | |||
373 | out_be16(&epparam->rbase, (u16)tmp_addr); | 377 | out_be16(&epparam->rbase, (u16)tmp_addr); |
374 | out_be16(&epparam->tbase, (u16)(tmp_addr + | 378 | out_be16(&epparam->tbase, (u16)(tmp_addr + |
375 | (sizeof(struct qe_bd) * bdring_len))); | 379 | (sizeof(struct qe_bd) * bdring_len))); |
@@ -689,7 +693,7 @@ en_done2: | |||
689 | en_done1: | 693 | en_done1: |
690 | spin_unlock_irqrestore(&udc->lock, flags); | 694 | spin_unlock_irqrestore(&udc->lock, flags); |
691 | en_done: | 695 | en_done: |
692 | dev_dbg(udc->dev, "failed to initialize %s\n", ep->ep.name); | 696 | dev_err(udc->dev, "failed to initialize %s\n", ep->ep.name); |
693 | return -ENODEV; | 697 | return -ENODEV; |
694 | } | 698 | } |
695 | 699 | ||
@@ -2408,6 +2412,8 @@ static struct qe_udc __devinit *qe_udc_config(struct of_device *ofdev) | |||
2408 | tmp_addr = cpm_muram_alloc((USB_MAX_ENDPOINTS * | 2412 | tmp_addr = cpm_muram_alloc((USB_MAX_ENDPOINTS * |
2409 | sizeof(struct usb_ep_para)), | 2413 | sizeof(struct usb_ep_para)), |
2410 | USB_EP_PARA_ALIGNMENT); | 2414 | USB_EP_PARA_ALIGNMENT); |
2415 | if (IS_ERR_VALUE(tmp_addr)) | ||
2416 | goto cleanup; | ||
2411 | 2417 | ||
2412 | for (i = 0; i < USB_MAX_ENDPOINTS; i++) { | 2418 | for (i = 0; i < USB_MAX_ENDPOINTS; i++) { |
2413 | out_be16(&usbpram->epptr[i], (u16)tmp_addr); | 2419 | out_be16(&usbpram->epptr[i], (u16)tmp_addr); |
@@ -2513,7 +2519,7 @@ static int __devinit qe_udc_probe(struct of_device *ofdev, | |||
2513 | /* Initialize the udc structure including QH member and other member */ | 2519 | /* Initialize the udc structure including QH member and other member */ |
2514 | udc_controller = qe_udc_config(ofdev); | 2520 | udc_controller = qe_udc_config(ofdev); |
2515 | if (!udc_controller) { | 2521 | if (!udc_controller) { |
2516 | dev_dbg(&ofdev->dev, "udc_controll is NULL\n"); | 2522 | dev_err(&ofdev->dev, "failed to initialize\n"); |
2517 | return -ENOMEM; | 2523 | return -ENOMEM; |
2518 | } | 2524 | } |
2519 | 2525 | ||
@@ -2568,7 +2574,7 @@ static int __devinit qe_udc_probe(struct of_device *ofdev, | |||
2568 | /* create a buf for ZLP send, need to remain zeroed */ | 2574 | /* create a buf for ZLP send, need to remain zeroed */ |
2569 | udc_controller->nullbuf = kzalloc(256, GFP_KERNEL); | 2575 | udc_controller->nullbuf = kzalloc(256, GFP_KERNEL); |
2570 | if (udc_controller->nullbuf == NULL) { | 2576 | if (udc_controller->nullbuf == NULL) { |
2571 | dev_dbg(udc_controller->dev, "cannot alloc nullbuf\n"); | 2577 | dev_err(udc_controller->dev, "cannot alloc nullbuf\n"); |
2572 | ret = -ENOMEM; | 2578 | ret = -ENOMEM; |
2573 | goto err3; | 2579 | goto err3; |
2574 | } | 2580 | } |
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index 4e3107dd2f34..ec6d439a2aa5 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h | |||
@@ -110,7 +110,6 @@ | |||
110 | #define gadget_is_at91(g) 0 | 110 | #define gadget_is_at91(g) 0 |
111 | #endif | 111 | #endif |
112 | 112 | ||
113 | /* status unclear */ | ||
114 | #ifdef CONFIG_USB_GADGET_IMX | 113 | #ifdef CONFIG_USB_GADGET_IMX |
115 | #define gadget_is_imx(g) !strcmp("imx_udc", (g)->name) | 114 | #define gadget_is_imx(g) !strcmp("imx_udc", (g)->name) |
116 | #else | 115 | #else |
@@ -158,6 +157,11 @@ | |||
158 | #define gadget_is_fsl_qe(g) 0 | 157 | #define gadget_is_fsl_qe(g) 0 |
159 | #endif | 158 | #endif |
160 | 159 | ||
160 | #ifdef CONFIG_USB_GADGET_CI13XXX | ||
161 | #define gadget_is_ci13xxx(g) (!strcmp("ci13xxx_udc", (g)->name)) | ||
162 | #else | ||
163 | #define gadget_is_ci13xxx(g) 0 | ||
164 | #endif | ||
161 | 165 | ||
162 | // CONFIG_USB_GADGET_SX2 | 166 | // CONFIG_USB_GADGET_SX2 |
163 | // CONFIG_USB_GADGET_AU1X00 | 167 | // CONFIG_USB_GADGET_AU1X00 |
@@ -225,6 +229,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) | |||
225 | return 0x21; | 229 | return 0x21; |
226 | else if (gadget_is_fsl_qe(gadget)) | 230 | else if (gadget_is_fsl_qe(gadget)) |
227 | return 0x22; | 231 | return 0x22; |
232 | else if (gadget_is_ci13xxx(gadget)) | ||
233 | return 0x23; | ||
228 | return -ENOENT; | 234 | return -ENOENT; |
229 | } | 235 | } |
230 | 236 | ||
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c index 60aa04847b18..63419c4d503c 100644 --- a/drivers/usb/gadget/goku_udc.c +++ b/drivers/usb/gadget/goku_udc.c | |||
@@ -1349,7 +1349,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
1349 | int retval; | 1349 | int retval; |
1350 | 1350 | ||
1351 | if (!driver | 1351 | if (!driver |
1352 | || driver->speed != USB_SPEED_FULL | 1352 | || driver->speed < USB_SPEED_FULL |
1353 | || !driver->bind | 1353 | || !driver->bind |
1354 | || !driver->disconnect | 1354 | || !driver->disconnect |
1355 | || !driver->setup) | 1355 | || !driver->setup) |
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c new file mode 100644 index 000000000000..cde8fdf15d5b --- /dev/null +++ b/drivers/usb/gadget/imx_udc.c | |||
@@ -0,0 +1,1516 @@ | |||
1 | /* | ||
2 | * driver/usb/gadget/imx_udc.c | ||
3 | * | ||
4 | * Copyright (C) 2005 Mike Lee(eemike@gmail.com) | ||
5 | * Copyright (C) 2008 Darius Augulis <augulis.darius@gmail.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | */ | ||
17 | |||
18 | #include <linux/init.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/errno.h> | ||
23 | #include <linux/list.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/io.h> | ||
26 | #include <linux/irq.h> | ||
27 | #include <linux/device.h> | ||
28 | #include <linux/dma-mapping.h> | ||
29 | #include <linux/clk.h> | ||
30 | #include <linux/delay.h> | ||
31 | |||
32 | #include <linux/usb/ch9.h> | ||
33 | #include <linux/usb/gadget.h> | ||
34 | |||
35 | #include <mach/usb.h> | ||
36 | #include <mach/hardware.h> | ||
37 | |||
38 | #include "imx_udc.h" | ||
39 | |||
40 | static const char driver_name[] = "imx_udc"; | ||
41 | static const char ep0name[] = "ep0"; | ||
42 | |||
43 | void ep0_chg_stat(const char *label, struct imx_udc_struct *imx_usb, | ||
44 | enum ep0_state stat); | ||
45 | |||
46 | /******************************************************************************* | ||
47 | * IMX UDC hardware related functions | ||
48 | ******************************************************************************* | ||
49 | */ | ||
50 | |||
51 | void imx_udc_enable(struct imx_udc_struct *imx_usb) | ||
52 | { | ||
53 | int temp = __raw_readl(imx_usb->base + USB_CTRL); | ||
54 | __raw_writel(temp | CTRL_FE_ENA | CTRL_AFE_ENA, imx_usb->base + USB_CTRL); | ||
55 | imx_usb->gadget.speed = USB_SPEED_FULL; | ||
56 | } | ||
57 | |||
58 | void imx_udc_disable(struct imx_udc_struct *imx_usb) | ||
59 | { | ||
60 | int temp = __raw_readl(imx_usb->base + USB_CTRL); | ||
61 | |||
62 | __raw_writel(temp & ~(CTRL_FE_ENA | CTRL_AFE_ENA), | ||
63 | imx_usb->base + USB_CTRL); | ||
64 | |||
65 | ep0_chg_stat(__func__, imx_usb, EP0_IDLE); | ||
66 | imx_usb->gadget.speed = USB_SPEED_UNKNOWN; | ||
67 | } | ||
68 | |||
69 | void imx_udc_reset(struct imx_udc_struct *imx_usb) | ||
70 | { | ||
71 | int temp = __raw_readl(imx_usb->base + USB_ENAB); | ||
72 | |||
73 | /* set RST bit */ | ||
74 | __raw_writel(temp | ENAB_RST, imx_usb->base + USB_ENAB); | ||
75 | |||
76 | /* wait RST bit to clear */ | ||
77 | do {} while (__raw_readl(imx_usb->base + USB_ENAB) & ENAB_RST); | ||
78 | |||
79 | /* wait CFG bit to assert */ | ||
80 | do {} while (!(__raw_readl(imx_usb->base + USB_DADR) & DADR_CFG)); | ||
81 | |||
82 | /* udc module is now ready */ | ||
83 | } | ||
84 | |||
85 | void imx_udc_config(struct imx_udc_struct *imx_usb) | ||
86 | { | ||
87 | u8 ep_conf[5]; | ||
88 | u8 i, j, cfg; | ||
89 | struct imx_ep_struct *imx_ep; | ||
90 | |||
91 | /* wait CFG bit to assert */ | ||
92 | do {} while (!(__raw_readl(imx_usb->base + USB_DADR) & DADR_CFG)); | ||
93 | |||
94 | /* Download the endpoint buffer for endpoint 0. */ | ||
95 | for (j = 0; j < 5; j++) { | ||
96 | i = (j == 2 ? imx_usb->imx_ep[0].fifosize : 0x00); | ||
97 | __raw_writeb(i, imx_usb->base + USB_DDAT); | ||
98 | do {} while (__raw_readl(imx_usb->base + USB_DADR) & DADR_BSY); | ||
99 | } | ||
100 | |||
101 | /* Download the endpoint buffers for endpoints 1-5. | ||
102 | * We specify two configurations, one interface | ||
103 | */ | ||
104 | for (cfg = 1; cfg < 3; cfg++) { | ||
105 | for (i = 1; i < IMX_USB_NB_EP; i++) { | ||
106 | imx_ep = &imx_usb->imx_ep[i]; | ||
107 | /* EP no | Config no */ | ||
108 | ep_conf[0] = (i << 4) | (cfg << 2); | ||
109 | /* Type | Direction */ | ||
110 | ep_conf[1] = (imx_ep->bmAttributes << 3) | | ||
111 | (EP_DIR(imx_ep) << 2); | ||
112 | /* Max packet size */ | ||
113 | ep_conf[2] = imx_ep->fifosize; | ||
114 | /* TRXTYP */ | ||
115 | ep_conf[3] = 0xC0; | ||
116 | /* FIFO no */ | ||
117 | ep_conf[4] = i; | ||
118 | |||
119 | D_INI(imx_usb->dev, | ||
120 | "<%s> ep%d_conf[%d]:" | ||
121 | "[%02x-%02x-%02x-%02x-%02x]\n", | ||
122 | __func__, i, cfg, | ||
123 | ep_conf[0], ep_conf[1], ep_conf[2], | ||
124 | ep_conf[3], ep_conf[4]); | ||
125 | |||
126 | for (j = 0; j < 5; j++) { | ||
127 | __raw_writeb(ep_conf[j], | ||
128 | imx_usb->base + USB_DDAT); | ||
129 | do {} while (__raw_readl(imx_usb->base + USB_DADR) | ||
130 | & DADR_BSY); | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | |||
135 | /* wait CFG bit to clear */ | ||
136 | do {} while (__raw_readl(imx_usb->base + USB_DADR) & DADR_CFG); | ||
137 | } | ||
138 | |||
139 | void imx_udc_init_irq(struct imx_udc_struct *imx_usb) | ||
140 | { | ||
141 | int i; | ||
142 | |||
143 | /* Mask and clear all irqs */ | ||
144 | __raw_writel(0xFFFFFFFF, imx_usb->base + USB_MASK); | ||
145 | __raw_writel(0xFFFFFFFF, imx_usb->base + USB_INTR); | ||
146 | for (i = 0; i < IMX_USB_NB_EP; i++) { | ||
147 | __raw_writel(0x1FF, imx_usb->base + USB_EP_MASK(i)); | ||
148 | __raw_writel(0x1FF, imx_usb->base + USB_EP_INTR(i)); | ||
149 | } | ||
150 | |||
151 | /* Enable USB irqs */ | ||
152 | __raw_writel(INTR_MSOF | INTR_FRAME_MATCH, imx_usb->base + USB_MASK); | ||
153 | |||
154 | /* Enable EP0 irqs */ | ||
155 | __raw_writel(0x1FF & ~(EPINTR_DEVREQ | EPINTR_MDEVREQ | EPINTR_EOT | ||
156 | | EPINTR_EOF | EPINTR_FIFO_EMPTY | EPINTR_FIFO_FULL), | ||
157 | imx_usb->base + USB_EP_MASK(0)); | ||
158 | } | ||
159 | |||
160 | void imx_udc_init_ep(struct imx_udc_struct *imx_usb) | ||
161 | { | ||
162 | int i, max, temp; | ||
163 | struct imx_ep_struct *imx_ep; | ||
164 | for (i = 0; i < IMX_USB_NB_EP; i++) { | ||
165 | imx_ep = &imx_usb->imx_ep[i]; | ||
166 | switch (imx_ep->fifosize) { | ||
167 | case 8: | ||
168 | max = 0; | ||
169 | break; | ||
170 | case 16: | ||
171 | max = 1; | ||
172 | break; | ||
173 | case 32: | ||
174 | max = 2; | ||
175 | break; | ||
176 | case 64: | ||
177 | max = 3; | ||
178 | break; | ||
179 | default: | ||
180 | max = 1; | ||
181 | break; | ||
182 | } | ||
183 | temp = (EP_DIR(imx_ep) << 7) | (max << 5) | ||
184 | | (imx_ep->bmAttributes << 3); | ||
185 | __raw_writel(temp, imx_usb->base + USB_EP_STAT(i)); | ||
186 | __raw_writel(temp | EPSTAT_FLUSH, imx_usb->base + USB_EP_STAT(i)); | ||
187 | D_INI(imx_usb->dev, "<%s> ep%d_stat %08x\n", __func__, i, | ||
188 | __raw_readl(imx_usb->base + USB_EP_STAT(i))); | ||
189 | } | ||
190 | } | ||
191 | |||
192 | void imx_udc_init_fifo(struct imx_udc_struct *imx_usb) | ||
193 | { | ||
194 | int i, temp; | ||
195 | struct imx_ep_struct *imx_ep; | ||
196 | for (i = 0; i < IMX_USB_NB_EP; i++) { | ||
197 | imx_ep = &imx_usb->imx_ep[i]; | ||
198 | |||
199 | /* Fifo control */ | ||
200 | temp = EP_DIR(imx_ep) ? 0x0B000000 : 0x0F000000; | ||
201 | __raw_writel(temp, imx_usb->base + USB_EP_FCTRL(i)); | ||
202 | D_INI(imx_usb->dev, "<%s> ep%d_fctrl %08x\n", __func__, i, | ||
203 | __raw_readl(imx_usb->base + USB_EP_FCTRL(i))); | ||
204 | |||
205 | /* Fifo alarm */ | ||
206 | temp = (i ? imx_ep->fifosize / 2 : 0); | ||
207 | __raw_writel(temp, imx_usb->base + USB_EP_FALRM(i)); | ||
208 | D_INI(imx_usb->dev, "<%s> ep%d_falrm %08x\n", __func__, i, | ||
209 | __raw_readl(imx_usb->base + USB_EP_FALRM(i))); | ||
210 | } | ||
211 | } | ||
212 | |||
213 | static void imx_udc_init(struct imx_udc_struct *imx_usb) | ||
214 | { | ||
215 | /* Reset UDC */ | ||
216 | imx_udc_reset(imx_usb); | ||
217 | |||
218 | /* Download config to enpoint buffer */ | ||
219 | imx_udc_config(imx_usb); | ||
220 | |||
221 | /* Setup interrups */ | ||
222 | imx_udc_init_irq(imx_usb); | ||
223 | |||
224 | /* Setup endpoints */ | ||
225 | imx_udc_init_ep(imx_usb); | ||
226 | |||
227 | /* Setup fifos */ | ||
228 | imx_udc_init_fifo(imx_usb); | ||
229 | } | ||
230 | |||
231 | void imx_ep_irq_enable(struct imx_ep_struct *imx_ep) | ||
232 | { | ||
233 | |||
234 | int i = EP_NO(imx_ep); | ||
235 | |||
236 | __raw_writel(0x1FF, imx_ep->imx_usb->base + USB_EP_MASK(i)); | ||
237 | __raw_writel(0x1FF, imx_ep->imx_usb->base + USB_EP_INTR(i)); | ||
238 | __raw_writel(0x1FF & ~(EPINTR_EOT | EPINTR_EOF), | ||
239 | imx_ep->imx_usb->base + USB_EP_MASK(i)); | ||
240 | } | ||
241 | |||
242 | void imx_ep_irq_disable(struct imx_ep_struct *imx_ep) | ||
243 | { | ||
244 | |||
245 | int i = EP_NO(imx_ep); | ||
246 | |||
247 | __raw_writel(0x1FF, imx_ep->imx_usb->base + USB_EP_MASK(i)); | ||
248 | __raw_writel(0x1FF, imx_ep->imx_usb->base + USB_EP_INTR(i)); | ||
249 | } | ||
250 | |||
251 | int imx_ep_empty(struct imx_ep_struct *imx_ep) | ||
252 | { | ||
253 | struct imx_udc_struct *imx_usb = imx_ep->imx_usb; | ||
254 | |||
255 | return __raw_readl(imx_usb->base + USB_EP_FSTAT(EP_NO(imx_ep))) | ||
256 | & FSTAT_EMPTY; | ||
257 | } | ||
258 | |||
259 | unsigned imx_fifo_bcount(struct imx_ep_struct *imx_ep) | ||
260 | { | ||
261 | struct imx_udc_struct *imx_usb = imx_ep->imx_usb; | ||
262 | |||
263 | return (__raw_readl(imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))) | ||
264 | & EPSTAT_BCOUNT) >> 16; | ||
265 | } | ||
266 | |||
267 | void imx_flush(struct imx_ep_struct *imx_ep) | ||
268 | { | ||
269 | struct imx_udc_struct *imx_usb = imx_ep->imx_usb; | ||
270 | |||
271 | int temp = __raw_readl(imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); | ||
272 | __raw_writel(temp | EPSTAT_FLUSH, | ||
273 | imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); | ||
274 | } | ||
275 | |||
276 | void imx_ep_stall(struct imx_ep_struct *imx_ep) | ||
277 | { | ||
278 | struct imx_udc_struct *imx_usb = imx_ep->imx_usb; | ||
279 | int temp, i; | ||
280 | |||
281 | D_ERR(imx_usb->dev, "<%s> Forced stall on %s\n", __func__, imx_ep->ep.name); | ||
282 | |||
283 | imx_flush(imx_ep); | ||
284 | |||
285 | /* Special care for ep0 */ | ||
286 | if (EP_NO(imx_ep)) { | ||
287 | temp = __raw_readl(imx_usb->base + USB_CTRL); | ||
288 | __raw_writel(temp | CTRL_CMDOVER | CTRL_CMDERROR, imx_usb->base + USB_CTRL); | ||
289 | do { } while (__raw_readl(imx_usb->base + USB_CTRL) & CTRL_CMDOVER); | ||
290 | temp = __raw_readl(imx_usb->base + USB_CTRL); | ||
291 | __raw_writel(temp & ~CTRL_CMDERROR, imx_usb->base + USB_CTRL); | ||
292 | } | ||
293 | else { | ||
294 | temp = __raw_readl(imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); | ||
295 | __raw_writel(temp | EPSTAT_STALL, | ||
296 | imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); | ||
297 | |||
298 | for (i = 0; i < 100; i ++) { | ||
299 | temp = __raw_readl(imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); | ||
300 | if (!temp & EPSTAT_STALL) | ||
301 | break; | ||
302 | udelay(20); | ||
303 | } | ||
304 | if (i == 50) | ||
305 | D_ERR(imx_usb->dev, "<%s> Non finished stall on %s\n", | ||
306 | __func__, imx_ep->ep.name); | ||
307 | } | ||
308 | } | ||
309 | |||
310 | static int imx_udc_get_frame(struct usb_gadget *_gadget) | ||
311 | { | ||
312 | struct imx_udc_struct *imx_usb = container_of(_gadget, | ||
313 | struct imx_udc_struct, gadget); | ||
314 | |||
315 | return __raw_readl(imx_usb->base + USB_FRAME) & 0x7FF; | ||
316 | } | ||
317 | |||
318 | static int imx_udc_wakeup(struct usb_gadget *_gadget) | ||
319 | { | ||
320 | return 0; | ||
321 | } | ||
322 | |||
323 | /******************************************************************************* | ||
324 | * USB request control functions | ||
325 | ******************************************************************************* | ||
326 | */ | ||
327 | |||
328 | static void ep_add_request(struct imx_ep_struct *imx_ep, struct imx_request *req) | ||
329 | { | ||
330 | if (unlikely(!req)) | ||
331 | return; | ||
332 | |||
333 | req->in_use = 1; | ||
334 | list_add_tail(&req->queue, &imx_ep->queue); | ||
335 | } | ||
336 | |||
337 | static void ep_del_request(struct imx_ep_struct *imx_ep, struct imx_request *req) | ||
338 | { | ||
339 | if (unlikely(!req)) | ||
340 | return; | ||
341 | |||
342 | list_del_init(&req->queue); | ||
343 | req->in_use = 0; | ||
344 | } | ||
345 | |||
346 | static void done(struct imx_ep_struct *imx_ep, struct imx_request *req, int status) | ||
347 | { | ||
348 | ep_del_request(imx_ep, req); | ||
349 | |||
350 | if (likely(req->req.status == -EINPROGRESS)) | ||
351 | req->req.status = status; | ||
352 | else | ||
353 | status = req->req.status; | ||
354 | |||
355 | if (status && status != -ESHUTDOWN) | ||
356 | D_ERR(imx_ep->imx_usb->dev, | ||
357 | "<%s> complete %s req %p stat %d len %u/%u\n", __func__, | ||
358 | imx_ep->ep.name, &req->req, status, | ||
359 | req->req.actual, req->req.length); | ||
360 | |||
361 | req->req.complete(&imx_ep->ep, &req->req); | ||
362 | } | ||
363 | |||
364 | static void nuke(struct imx_ep_struct *imx_ep, int status) | ||
365 | { | ||
366 | struct imx_request *req; | ||
367 | |||
368 | while (!list_empty(&imx_ep->queue)) { | ||
369 | req = list_entry(imx_ep->queue.next, struct imx_request, queue); | ||
370 | done(imx_ep, req, status); | ||
371 | } | ||
372 | } | ||
373 | |||
374 | /******************************************************************************* | ||
375 | * Data tansfer over USB functions | ||
376 | ******************************************************************************* | ||
377 | */ | ||
378 | static int read_packet(struct imx_ep_struct *imx_ep, struct imx_request *req) | ||
379 | { | ||
380 | u8 *buf; | ||
381 | int bytes_ep, bufferspace, count, i; | ||
382 | |||
383 | bytes_ep = imx_fifo_bcount(imx_ep); | ||
384 | bufferspace = req->req.length - req->req.actual; | ||
385 | |||
386 | buf = req->req.buf + req->req.actual; | ||
387 | prefetchw(buf); | ||
388 | |||
389 | if (unlikely(imx_ep_empty(imx_ep))) | ||
390 | count = 0; /* zlp */ | ||
391 | else | ||
392 | count = min(bytes_ep, bufferspace); | ||
393 | |||
394 | for (i = count; i > 0; i--) | ||
395 | *buf++ = __raw_readb(imx_ep->imx_usb->base | ||
396 | + USB_EP_FDAT0(EP_NO(imx_ep))); | ||
397 | req->req.actual += count; | ||
398 | |||
399 | return count; | ||
400 | } | ||
401 | |||
402 | static int write_packet(struct imx_ep_struct *imx_ep, struct imx_request *req) | ||
403 | { | ||
404 | u8 *buf; | ||
405 | int length, count, temp; | ||
406 | |||
407 | buf = req->req.buf + req->req.actual; | ||
408 | prefetch(buf); | ||
409 | |||
410 | length = min(req->req.length - req->req.actual, (u32)imx_ep->fifosize); | ||
411 | |||
412 | if (imx_fifo_bcount(imx_ep) + length > imx_ep->fifosize) { | ||
413 | D_TRX(imx_ep->imx_usb->dev, "<%s> packet overfill %s fifo\n", | ||
414 | __func__, imx_ep->ep.name); | ||
415 | return -1; | ||
416 | } | ||
417 | |||
418 | req->req.actual += length; | ||
419 | count = length; | ||
420 | |||
421 | if (!count && req->req.zero) { /* zlp */ | ||
422 | temp = __raw_readl(imx_ep->imx_usb->base | ||
423 | + USB_EP_STAT(EP_NO(imx_ep))); | ||
424 | __raw_writel(temp | EPSTAT_ZLPS, imx_ep->imx_usb->base | ||
425 | + USB_EP_STAT(EP_NO(imx_ep))); | ||
426 | D_TRX(imx_ep->imx_usb->dev, "<%s> zero packet\n", __func__); | ||
427 | return 0; | ||
428 | } | ||
429 | |||
430 | while (count--) { | ||
431 | if (count == 0) { /* last byte */ | ||
432 | temp = __raw_readl(imx_ep->imx_usb->base | ||
433 | + USB_EP_FCTRL(EP_NO(imx_ep))); | ||
434 | __raw_writel(temp | FCTRL_WFR, imx_ep->imx_usb->base | ||
435 | + USB_EP_FCTRL(EP_NO(imx_ep))); | ||
436 | } | ||
437 | __raw_writeb(*buf++, | ||
438 | imx_ep->imx_usb->base + USB_EP_FDAT0(EP_NO(imx_ep))); | ||
439 | } | ||
440 | |||
441 | return length; | ||
442 | } | ||
443 | |||
444 | static int read_fifo(struct imx_ep_struct *imx_ep, struct imx_request *req) | ||
445 | { | ||
446 | int bytes = 0, | ||
447 | count, | ||
448 | completed = 0; | ||
449 | |||
450 | while (__raw_readl(imx_ep->imx_usb->base + USB_EP_FSTAT(EP_NO(imx_ep))) | ||
451 | & FSTAT_FR) { | ||
452 | count = read_packet(imx_ep, req); | ||
453 | bytes += count; | ||
454 | |||
455 | completed = (count != imx_ep->fifosize); | ||
456 | if (completed || req->req.actual == req->req.length) { | ||
457 | completed = 1; | ||
458 | break; | ||
459 | } | ||
460 | } | ||
461 | |||
462 | if (completed || !req->req.length) { | ||
463 | done(imx_ep, req, 0); | ||
464 | D_REQ(imx_ep->imx_usb->dev, "<%s> %s req<%p> %s\n", | ||
465 | __func__, imx_ep->ep.name, req, | ||
466 | completed ? "completed" : "not completed"); | ||
467 | if (!EP_NO(imx_ep)) | ||
468 | ep0_chg_stat(__func__, imx_ep->imx_usb, EP0_IDLE); | ||
469 | } | ||
470 | |||
471 | D_TRX(imx_ep->imx_usb->dev, "<%s> bytes read: %d\n", __func__, bytes); | ||
472 | |||
473 | return completed; | ||
474 | } | ||
475 | |||
476 | static int write_fifo(struct imx_ep_struct *imx_ep, struct imx_request *req) | ||
477 | { | ||
478 | int bytes = 0, | ||
479 | count, | ||
480 | completed = 0; | ||
481 | |||
482 | while (!completed) { | ||
483 | count = write_packet(imx_ep, req); | ||
484 | if (count < 0) | ||
485 | break; /* busy */ | ||
486 | bytes += count; | ||
487 | |||
488 | /* last packet "must be" short (or a zlp) */ | ||
489 | completed = (count != imx_ep->fifosize); | ||
490 | |||
491 | if (unlikely(completed)) { | ||
492 | done(imx_ep, req, 0); | ||
493 | D_REQ(imx_ep->imx_usb->dev, "<%s> %s req<%p> %s\n", | ||
494 | __func__, imx_ep->ep.name, req, | ||
495 | completed ? "completed" : "not completed"); | ||
496 | if (!EP_NO(imx_ep)) | ||
497 | ep0_chg_stat(__func__, imx_ep->imx_usb, EP0_IDLE); | ||
498 | } | ||
499 | } | ||
500 | |||
501 | D_TRX(imx_ep->imx_usb->dev, "<%s> bytes sent: %d\n", __func__, bytes); | ||
502 | |||
503 | return completed; | ||
504 | } | ||
505 | |||
506 | /******************************************************************************* | ||
507 | * Endpoint handlers | ||
508 | ******************************************************************************* | ||
509 | */ | ||
510 | static int handle_ep(struct imx_ep_struct *imx_ep) | ||
511 | { | ||
512 | struct imx_request *req; | ||
513 | int completed = 0; | ||
514 | |||
515 | do { | ||
516 | if (!list_empty(&imx_ep->queue)) | ||
517 | req = list_entry(imx_ep->queue.next, | ||
518 | struct imx_request, queue); | ||
519 | else { | ||
520 | D_REQ(imx_ep->imx_usb->dev, "<%s> no request on %s\n", | ||
521 | __func__, imx_ep->ep.name); | ||
522 | return 0; | ||
523 | } | ||
524 | |||
525 | if (EP_DIR(imx_ep)) /* to host */ | ||
526 | completed = write_fifo(imx_ep, req); | ||
527 | else /* to device */ | ||
528 | completed = read_fifo(imx_ep, req); | ||
529 | |||
530 | dump_ep_stat(__func__, imx_ep); | ||
531 | |||
532 | } while (completed); | ||
533 | |||
534 | return 0; | ||
535 | } | ||
536 | |||
537 | static int handle_ep0(struct imx_ep_struct *imx_ep) | ||
538 | { | ||
539 | struct imx_request *req = NULL; | ||
540 | int ret = 0; | ||
541 | |||
542 | if (!list_empty(&imx_ep->queue)) | ||
543 | req = list_entry(imx_ep->queue.next, struct imx_request, queue); | ||
544 | |||
545 | if (req) { | ||
546 | switch (imx_ep->imx_usb->ep0state) { | ||
547 | |||
548 | case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR */ | ||
549 | write_fifo(imx_ep, req); | ||
550 | break; | ||
551 | case EP0_OUT_DATA_PHASE: /* SET_DESCRIPTOR */ | ||
552 | read_fifo(imx_ep, req); | ||
553 | break; | ||
554 | default: | ||
555 | D_EP0(imx_ep->imx_usb->dev, | ||
556 | "<%s> ep0 i/o, odd state %d\n", | ||
557 | __func__, imx_ep->imx_usb->ep0state); | ||
558 | ep_del_request(imx_ep, req); | ||
559 | ret = -EL2HLT; | ||
560 | break; | ||
561 | } | ||
562 | } | ||
563 | |||
564 | return ret; | ||
565 | } | ||
566 | |||
567 | static void handle_ep0_devreq(struct imx_udc_struct *imx_usb) | ||
568 | { | ||
569 | struct imx_ep_struct *imx_ep = &imx_usb->imx_ep[0]; | ||
570 | union { | ||
571 | struct usb_ctrlrequest r; | ||
572 | u8 raw[8]; | ||
573 | u32 word[2]; | ||
574 | } u; | ||
575 | int temp, i; | ||
576 | |||
577 | nuke(imx_ep, -EPROTO); | ||
578 | |||
579 | /* read SETUP packet */ | ||
580 | for (i = 0; i < 2; i++) { | ||
581 | if (imx_ep_empty(imx_ep)) { | ||
582 | D_ERR(imx_usb->dev, | ||
583 | "<%s> no setup packet received\n", __func__); | ||
584 | goto stall; | ||
585 | } | ||
586 | u.word[i] = __raw_readl(imx_usb->base + USB_EP_FDAT(EP_NO(imx_ep))); | ||
587 | } | ||
588 | |||
589 | temp = imx_ep_empty(imx_ep); | ||
590 | while (!imx_ep_empty(imx_ep)) { | ||
591 | i = __raw_readl(imx_usb->base + USB_EP_FDAT(EP_NO(imx_ep))); | ||
592 | D_ERR(imx_usb->dev, | ||
593 | "<%s> wrong to have extra bytes for setup : 0x%08x\n", | ||
594 | __func__, i); | ||
595 | } | ||
596 | if (!temp) | ||
597 | goto stall; | ||
598 | |||
599 | le16_to_cpus(&u.r.wValue); | ||
600 | le16_to_cpus(&u.r.wIndex); | ||
601 | le16_to_cpus(&u.r.wLength); | ||
602 | |||
603 | D_REQ(imx_usb->dev, "<%s> SETUP %02x.%02x v%04x i%04x l%04x\n", | ||
604 | __func__, u.r.bRequestType, u.r.bRequest, | ||
605 | u.r.wValue, u.r.wIndex, u.r.wLength); | ||
606 | |||
607 | if (imx_usb->set_config) { | ||
608 | /* NACK the host by using CMDOVER */ | ||
609 | temp = __raw_readl(imx_usb->base + USB_CTRL); | ||
610 | __raw_writel(temp | CTRL_CMDOVER, imx_usb->base + USB_CTRL); | ||
611 | |||
612 | D_ERR(imx_usb->dev, | ||
613 | "<%s> set config req is pending, NACK the host\n", | ||
614 | __func__); | ||
615 | return; | ||
616 | } | ||
617 | |||
618 | if (u.r.bRequestType & USB_DIR_IN) | ||
619 | ep0_chg_stat(__func__, imx_usb, EP0_IN_DATA_PHASE); | ||
620 | else | ||
621 | ep0_chg_stat(__func__, imx_usb, EP0_OUT_DATA_PHASE); | ||
622 | |||
623 | i = imx_usb->driver->setup(&imx_usb->gadget, &u.r); | ||
624 | if (i < 0) { | ||
625 | D_ERR(imx_usb->dev, "<%s> device setup error %d\n", | ||
626 | __func__, i); | ||
627 | goto stall; | ||
628 | } | ||
629 | |||
630 | return; | ||
631 | stall: | ||
632 | D_ERR(imx_usb->dev, "<%s> protocol STALL\n", __func__); | ||
633 | imx_ep_stall(imx_ep); | ||
634 | ep0_chg_stat(__func__, imx_usb, EP0_STALL); | ||
635 | return; | ||
636 | } | ||
637 | |||
638 | /******************************************************************************* | ||
639 | * USB gadget callback functions | ||
640 | ******************************************************************************* | ||
641 | */ | ||
642 | |||
643 | static int imx_ep_enable(struct usb_ep *usb_ep, | ||
644 | const struct usb_endpoint_descriptor *desc) | ||
645 | { | ||
646 | struct imx_ep_struct *imx_ep = container_of(usb_ep, | ||
647 | struct imx_ep_struct, ep); | ||
648 | struct imx_udc_struct *imx_usb = imx_ep->imx_usb; | ||
649 | unsigned long flags; | ||
650 | |||
651 | if (!usb_ep | ||
652 | || !desc | ||
653 | || !EP_NO(imx_ep) | ||
654 | || desc->bDescriptorType != USB_DT_ENDPOINT | ||
655 | || imx_ep->bEndpointAddress != desc->bEndpointAddress) { | ||
656 | D_ERR(imx_usb->dev, | ||
657 | "<%s> bad ep or descriptor\n", __func__); | ||
658 | return -EINVAL; | ||
659 | } | ||
660 | |||
661 | if (imx_ep->bmAttributes != desc->bmAttributes) { | ||
662 | D_ERR(imx_usb->dev, | ||
663 | "<%s> %s type mismatch\n", __func__, usb_ep->name); | ||
664 | return -EINVAL; | ||
665 | } | ||
666 | |||
667 | if (imx_ep->fifosize < le16_to_cpu(desc->wMaxPacketSize)) { | ||
668 | D_ERR(imx_usb->dev, | ||
669 | "<%s> bad %s maxpacket\n", __func__, usb_ep->name); | ||
670 | return -ERANGE; | ||
671 | } | ||
672 | |||
673 | if (!imx_usb->driver || imx_usb->gadget.speed == USB_SPEED_UNKNOWN) { | ||
674 | D_ERR(imx_usb->dev, "<%s> bogus device state\n", __func__); | ||
675 | return -ESHUTDOWN; | ||
676 | } | ||
677 | |||
678 | local_irq_save(flags); | ||
679 | |||
680 | imx_ep->stopped = 0; | ||
681 | imx_flush(imx_ep); | ||
682 | imx_ep_irq_enable(imx_ep); | ||
683 | |||
684 | local_irq_restore(flags); | ||
685 | |||
686 | D_EPX(imx_usb->dev, "<%s> ENABLED %s\n", __func__, usb_ep->name); | ||
687 | return 0; | ||
688 | } | ||
689 | |||
690 | static int imx_ep_disable(struct usb_ep *usb_ep) | ||
691 | { | ||
692 | struct imx_ep_struct *imx_ep = container_of(usb_ep, | ||
693 | struct imx_ep_struct, ep); | ||
694 | unsigned long flags; | ||
695 | |||
696 | if (!usb_ep || !EP_NO(imx_ep) || !list_empty(&imx_ep->queue)) { | ||
697 | D_ERR(imx_ep->imx_usb->dev, "<%s> %s can not be disabled\n", | ||
698 | __func__, usb_ep ? imx_ep->ep.name : NULL); | ||
699 | return -EINVAL; | ||
700 | } | ||
701 | |||
702 | local_irq_save(flags); | ||
703 | |||
704 | imx_ep->stopped = 1; | ||
705 | nuke(imx_ep, -ESHUTDOWN); | ||
706 | imx_flush(imx_ep); | ||
707 | imx_ep_irq_disable(imx_ep); | ||
708 | |||
709 | local_irq_restore(flags); | ||
710 | |||
711 | D_EPX(imx_ep->imx_usb->dev, | ||
712 | "<%s> DISABLED %s\n", __func__, usb_ep->name); | ||
713 | return 0; | ||
714 | } | ||
715 | |||
716 | static struct usb_request *imx_ep_alloc_request | ||
717 | (struct usb_ep *usb_ep, gfp_t gfp_flags) | ||
718 | { | ||
719 | struct imx_request *req; | ||
720 | |||
721 | req = kzalloc(sizeof *req, gfp_flags); | ||
722 | if (!req || !usb_ep) | ||
723 | return 0; | ||
724 | |||
725 | INIT_LIST_HEAD(&req->queue); | ||
726 | req->in_use = 0; | ||
727 | |||
728 | return &req->req; | ||
729 | } | ||
730 | |||
731 | static void imx_ep_free_request | ||
732 | (struct usb_ep *usb_ep, struct usb_request *usb_req) | ||
733 | { | ||
734 | struct imx_request *req; | ||
735 | |||
736 | req = container_of(usb_req, struct imx_request, req); | ||
737 | WARN_ON(!list_empty(&req->queue)); | ||
738 | kfree(req); | ||
739 | } | ||
740 | |||
741 | static int imx_ep_queue | ||
742 | (struct usb_ep *usb_ep, struct usb_request *usb_req, gfp_t gfp_flags) | ||
743 | { | ||
744 | struct imx_ep_struct *imx_ep; | ||
745 | struct imx_udc_struct *imx_usb; | ||
746 | struct imx_request *req; | ||
747 | unsigned long flags; | ||
748 | int ret = 0; | ||
749 | |||
750 | imx_ep = container_of(usb_ep, struct imx_ep_struct, ep); | ||
751 | imx_usb = imx_ep->imx_usb; | ||
752 | req = container_of(usb_req, struct imx_request, req); | ||
753 | |||
754 | /* | ||
755 | Special care on IMX udc. | ||
756 | Ignore enqueue when after set configuration from the | ||
757 | host. This assume all gadget drivers reply set | ||
758 | configuration with the next ep0 req enqueue. | ||
759 | */ | ||
760 | if (imx_usb->set_config && !EP_NO(imx_ep)) { | ||
761 | imx_usb->set_config = 0; | ||
762 | D_EPX(imx_usb->dev, | ||
763 | "<%s> gadget reply set config\n", __func__); | ||
764 | return 0; | ||
765 | } | ||
766 | |||
767 | if (unlikely(!usb_req || !req || !usb_req->complete || !usb_req->buf)) { | ||
768 | D_ERR(imx_usb->dev, "<%s> bad params\n", __func__); | ||
769 | return -EINVAL; | ||
770 | } | ||
771 | |||
772 | if (unlikely(!usb_ep || !imx_ep)) { | ||
773 | D_ERR(imx_usb->dev, "<%s> bad ep\n", __func__); | ||
774 | return -EINVAL; | ||
775 | } | ||
776 | |||
777 | if (!imx_usb->driver || imx_usb->gadget.speed == USB_SPEED_UNKNOWN) { | ||
778 | D_ERR(imx_usb->dev, "<%s> bogus device state\n", __func__); | ||
779 | return -ESHUTDOWN; | ||
780 | } | ||
781 | |||
782 | local_irq_save(flags); | ||
783 | |||
784 | /* Debug */ | ||
785 | D_REQ(imx_usb->dev, "<%s> ep%d %s request for [%d] bytes\n", | ||
786 | __func__, EP_NO(imx_ep), | ||
787 | ((!EP_NO(imx_ep) && imx_ep->imx_usb->ep0state == EP0_IN_DATA_PHASE) | ||
788 | || (EP_NO(imx_ep) && EP_DIR(imx_ep))) ? "IN" : "OUT", usb_req->length); | ||
789 | dump_req(__func__, imx_ep, usb_req); | ||
790 | |||
791 | if (imx_ep->stopped) { | ||
792 | usb_req->status = -ESHUTDOWN; | ||
793 | ret = -ESHUTDOWN; | ||
794 | goto out; | ||
795 | } | ||
796 | |||
797 | if (req->in_use) { | ||
798 | D_ERR(imx_usb->dev, | ||
799 | "<%s> refusing to queue req %p (already queued)\n", | ||
800 | __func__, req); | ||
801 | goto out; | ||
802 | } | ||
803 | |||
804 | usb_req->status = -EINPROGRESS; | ||
805 | usb_req->actual = 0; | ||
806 | |||
807 | ep_add_request(imx_ep, req); | ||
808 | |||
809 | if (!EP_NO(imx_ep)) | ||
810 | ret = handle_ep0(imx_ep); | ||
811 | else | ||
812 | ret = handle_ep(imx_ep); | ||
813 | out: | ||
814 | local_irq_restore(flags); | ||
815 | return ret; | ||
816 | } | ||
817 | |||
818 | static int imx_ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req) | ||
819 | { | ||
820 | |||
821 | struct imx_ep_struct *imx_ep = container_of | ||
822 | (usb_ep, struct imx_ep_struct, ep); | ||
823 | struct imx_request *req; | ||
824 | unsigned long flags; | ||
825 | |||
826 | if (unlikely(!usb_ep || !EP_NO(imx_ep))) { | ||
827 | D_ERR(imx_ep->imx_usb->dev, "<%s> bad ep\n", __func__); | ||
828 | return -EINVAL; | ||
829 | } | ||
830 | |||
831 | local_irq_save(flags); | ||
832 | |||
833 | /* make sure it's actually queued on this endpoint */ | ||
834 | list_for_each_entry(req, &imx_ep->queue, queue) { | ||
835 | if (&req->req == usb_req) | ||
836 | break; | ||
837 | } | ||
838 | if (&req->req != usb_req) { | ||
839 | local_irq_restore(flags); | ||
840 | return -EINVAL; | ||
841 | } | ||
842 | |||
843 | done(imx_ep, req, -ECONNRESET); | ||
844 | |||
845 | local_irq_restore(flags); | ||
846 | return 0; | ||
847 | } | ||
848 | |||
849 | static int imx_ep_set_halt(struct usb_ep *usb_ep, int value) | ||
850 | { | ||
851 | struct imx_ep_struct *imx_ep = container_of | ||
852 | (usb_ep, struct imx_ep_struct, ep); | ||
853 | unsigned long flags; | ||
854 | |||
855 | if (unlikely(!usb_ep || !EP_NO(imx_ep))) { | ||
856 | D_ERR(imx_ep->imx_usb->dev, "<%s> bad ep\n", __func__); | ||
857 | return -EINVAL; | ||
858 | } | ||
859 | |||
860 | local_irq_save(flags); | ||
861 | |||
862 | if ((imx_ep->bEndpointAddress & USB_DIR_IN) | ||
863 | && !list_empty(&imx_ep->queue)) { | ||
864 | local_irq_restore(flags); | ||
865 | return -EAGAIN; | ||
866 | } | ||
867 | |||
868 | imx_ep_stall(imx_ep); | ||
869 | |||
870 | local_irq_restore(flags); | ||
871 | |||
872 | D_EPX(imx_ep->imx_usb->dev, "<%s> %s halt\n", __func__, usb_ep->name); | ||
873 | return 0; | ||
874 | } | ||
875 | |||
876 | static int imx_ep_fifo_status(struct usb_ep *usb_ep) | ||
877 | { | ||
878 | struct imx_ep_struct *imx_ep = container_of | ||
879 | (usb_ep, struct imx_ep_struct, ep); | ||
880 | |||
881 | if (!usb_ep) { | ||
882 | D_ERR(imx_ep->imx_usb->dev, "<%s> bad ep\n", __func__); | ||
883 | return -ENODEV; | ||
884 | } | ||
885 | |||
886 | if (imx_ep->imx_usb->gadget.speed == USB_SPEED_UNKNOWN) | ||
887 | return 0; | ||
888 | else | ||
889 | return imx_fifo_bcount(imx_ep); | ||
890 | } | ||
891 | |||
892 | static void imx_ep_fifo_flush(struct usb_ep *usb_ep) | ||
893 | { | ||
894 | struct imx_ep_struct *imx_ep = container_of | ||
895 | (usb_ep, struct imx_ep_struct, ep); | ||
896 | unsigned long flags; | ||
897 | |||
898 | local_irq_save(flags); | ||
899 | |||
900 | if (!usb_ep || !EP_NO(imx_ep) || !list_empty(&imx_ep->queue)) { | ||
901 | D_ERR(imx_ep->imx_usb->dev, "<%s> bad ep\n", __func__); | ||
902 | local_irq_restore(flags); | ||
903 | return; | ||
904 | } | ||
905 | |||
906 | /* toggle and halt bits stay unchanged */ | ||
907 | imx_flush(imx_ep); | ||
908 | |||
909 | local_irq_restore(flags); | ||
910 | } | ||
911 | |||
912 | static struct usb_ep_ops imx_ep_ops = { | ||
913 | .enable = imx_ep_enable, | ||
914 | .disable = imx_ep_disable, | ||
915 | |||
916 | .alloc_request = imx_ep_alloc_request, | ||
917 | .free_request = imx_ep_free_request, | ||
918 | |||
919 | .queue = imx_ep_queue, | ||
920 | .dequeue = imx_ep_dequeue, | ||
921 | |||
922 | .set_halt = imx_ep_set_halt, | ||
923 | .fifo_status = imx_ep_fifo_status, | ||
924 | .fifo_flush = imx_ep_fifo_flush, | ||
925 | }; | ||
926 | |||
927 | /******************************************************************************* | ||
928 | * USB endpoint control functions | ||
929 | ******************************************************************************* | ||
930 | */ | ||
931 | |||
932 | void ep0_chg_stat(const char *label, | ||
933 | struct imx_udc_struct *imx_usb, enum ep0_state stat) | ||
934 | { | ||
935 | D_EP0(imx_usb->dev, "<%s> from %15s to %15s\n", | ||
936 | label, state_name[imx_usb->ep0state], state_name[stat]); | ||
937 | |||
938 | if (imx_usb->ep0state == stat) | ||
939 | return; | ||
940 | |||
941 | imx_usb->ep0state = stat; | ||
942 | } | ||
943 | |||
944 | static void usb_init_data(struct imx_udc_struct *imx_usb) | ||
945 | { | ||
946 | struct imx_ep_struct *imx_ep; | ||
947 | u8 i; | ||
948 | |||
949 | /* device/ep0 records init */ | ||
950 | INIT_LIST_HEAD(&imx_usb->gadget.ep_list); | ||
951 | INIT_LIST_HEAD(&imx_usb->gadget.ep0->ep_list); | ||
952 | ep0_chg_stat(__func__, imx_usb, EP0_IDLE); | ||
953 | |||
954 | /* basic endpoint records init */ | ||
955 | for (i = 0; i < IMX_USB_NB_EP; i++) { | ||
956 | imx_ep = &imx_usb->imx_ep[i]; | ||
957 | |||
958 | if (i) { | ||
959 | list_add_tail(&imx_ep->ep.ep_list, | ||
960 | &imx_usb->gadget.ep_list); | ||
961 | imx_ep->stopped = 1; | ||
962 | } else | ||
963 | imx_ep->stopped = 0; | ||
964 | |||
965 | INIT_LIST_HEAD(&imx_ep->queue); | ||
966 | } | ||
967 | } | ||
968 | |||
969 | static void udc_stop_activity(struct imx_udc_struct *imx_usb, | ||
970 | struct usb_gadget_driver *driver) | ||
971 | { | ||
972 | struct imx_ep_struct *imx_ep; | ||
973 | int i; | ||
974 | |||
975 | if (imx_usb->gadget.speed == USB_SPEED_UNKNOWN) | ||
976 | driver = NULL; | ||
977 | |||
978 | /* prevent new request submissions, kill any outstanding requests */ | ||
979 | for (i = 1; i < IMX_USB_NB_EP; i++) { | ||
980 | imx_ep = &imx_usb->imx_ep[i]; | ||
981 | imx_flush(imx_ep); | ||
982 | imx_ep->stopped = 1; | ||
983 | imx_ep_irq_disable(imx_ep); | ||
984 | nuke(imx_ep, -ESHUTDOWN); | ||
985 | } | ||
986 | |||
987 | imx_usb->cfg = 0; | ||
988 | imx_usb->intf = 0; | ||
989 | imx_usb->alt = 0; | ||
990 | |||
991 | if (driver) | ||
992 | driver->disconnect(&imx_usb->gadget); | ||
993 | } | ||
994 | |||
995 | /******************************************************************************* | ||
996 | * Interrupt handlers | ||
997 | ******************************************************************************* | ||
998 | */ | ||
999 | |||
1000 | static irqreturn_t imx_udc_irq(int irq, void *dev) | ||
1001 | { | ||
1002 | struct imx_udc_struct *imx_usb = dev; | ||
1003 | struct usb_ctrlrequest u; | ||
1004 | int temp, cfg, intf, alt; | ||
1005 | int intr = __raw_readl(imx_usb->base + USB_INTR); | ||
1006 | |||
1007 | if (intr & (INTR_WAKEUP | INTR_SUSPEND | INTR_RESUME | INTR_RESET_START | ||
1008 | | INTR_RESET_STOP | INTR_CFG_CHG)) { | ||
1009 | dump_intr(__func__, intr, imx_usb->dev); | ||
1010 | dump_usb_stat(__func__, imx_usb); | ||
1011 | } | ||
1012 | |||
1013 | if (!imx_usb->driver) { | ||
1014 | /*imx_udc_disable(imx_usb);*/ | ||
1015 | goto end_irq; | ||
1016 | } | ||
1017 | |||
1018 | if (intr & INTR_WAKEUP) { | ||
1019 | if (imx_usb->gadget.speed == USB_SPEED_UNKNOWN | ||
1020 | && imx_usb->driver && imx_usb->driver->resume) | ||
1021 | imx_usb->driver->resume(&imx_usb->gadget); | ||
1022 | imx_usb->set_config = 0; | ||
1023 | imx_usb->gadget.speed = USB_SPEED_FULL; | ||
1024 | } | ||
1025 | |||
1026 | if (intr & INTR_SUSPEND) { | ||
1027 | if (imx_usb->gadget.speed != USB_SPEED_UNKNOWN | ||
1028 | && imx_usb->driver && imx_usb->driver->suspend) | ||
1029 | imx_usb->driver->suspend(&imx_usb->gadget); | ||
1030 | imx_usb->set_config = 0; | ||
1031 | imx_usb->gadget.speed = USB_SPEED_UNKNOWN; | ||
1032 | } | ||
1033 | |||
1034 | if (intr & INTR_RESET_START) { | ||
1035 | __raw_writel(intr, imx_usb->base + USB_INTR); | ||
1036 | udc_stop_activity(imx_usb, imx_usb->driver); | ||
1037 | imx_usb->set_config = 0; | ||
1038 | imx_usb->gadget.speed = USB_SPEED_UNKNOWN; | ||
1039 | } | ||
1040 | |||
1041 | if (intr & INTR_RESET_STOP) | ||
1042 | imx_usb->gadget.speed = USB_SPEED_FULL; | ||
1043 | |||
1044 | if (intr & INTR_CFG_CHG) { | ||
1045 | __raw_writel(INTR_CFG_CHG, imx_usb->base + USB_INTR); | ||
1046 | temp = __raw_readl(imx_usb->base + USB_STAT); | ||
1047 | cfg = (temp & STAT_CFG) >> 5; | ||
1048 | intf = (temp & STAT_INTF) >> 3; | ||
1049 | alt = temp & STAT_ALTSET; | ||
1050 | |||
1051 | D_REQ(imx_usb->dev, | ||
1052 | "<%s> orig config C=%d, I=%d, A=%d / " | ||
1053 | "req config C=%d, I=%d, A=%d\n", | ||
1054 | __func__, imx_usb->cfg, imx_usb->intf, imx_usb->alt, | ||
1055 | cfg, intf, alt); | ||
1056 | |||
1057 | if (cfg != 1 && cfg != 2) | ||
1058 | goto end_irq; | ||
1059 | |||
1060 | imx_usb->set_config = 0; | ||
1061 | |||
1062 | /* Config setup */ | ||
1063 | if (imx_usb->cfg != cfg) { | ||
1064 | D_REQ(imx_usb->dev, "<%s> Change config start\n",__func__); | ||
1065 | u.bRequest = USB_REQ_SET_CONFIGURATION; | ||
1066 | u.bRequestType = USB_DIR_OUT | | ||
1067 | USB_TYPE_STANDARD | | ||
1068 | USB_RECIP_DEVICE; | ||
1069 | u.wValue = cfg; | ||
1070 | u.wIndex = 0; | ||
1071 | u.wLength = 0; | ||
1072 | imx_usb->cfg = cfg; | ||
1073 | imx_usb->set_config = 1; | ||
1074 | imx_usb->driver->setup(&imx_usb->gadget, &u); | ||
1075 | imx_usb->set_config = 0; | ||
1076 | D_REQ(imx_usb->dev, "<%s> Change config done\n",__func__); | ||
1077 | |||
1078 | } | ||
1079 | if (imx_usb->intf != intf || imx_usb->alt != alt) { | ||
1080 | D_REQ(imx_usb->dev, "<%s> Change interface start\n",__func__); | ||
1081 | u.bRequest = USB_REQ_SET_INTERFACE; | ||
1082 | u.bRequestType = USB_DIR_OUT | | ||
1083 | USB_TYPE_STANDARD | | ||
1084 | USB_RECIP_INTERFACE; | ||
1085 | u.wValue = alt; | ||
1086 | u.wIndex = intf; | ||
1087 | u.wLength = 0; | ||
1088 | imx_usb->intf = intf; | ||
1089 | imx_usb->alt = alt; | ||
1090 | imx_usb->set_config = 1; | ||
1091 | imx_usb->driver->setup(&imx_usb->gadget, &u); | ||
1092 | imx_usb->set_config = 0; | ||
1093 | D_REQ(imx_usb->dev, "<%s> Change interface done\n",__func__); | ||
1094 | } | ||
1095 | } | ||
1096 | |||
1097 | if (intr & INTR_SOF) { | ||
1098 | if (imx_usb->ep0state == EP0_IDLE) { | ||
1099 | temp = __raw_readl(imx_usb->base + USB_CTRL); | ||
1100 | __raw_writel(temp | CTRL_CMDOVER, imx_usb->base + USB_CTRL); | ||
1101 | } | ||
1102 | } | ||
1103 | |||
1104 | end_irq: | ||
1105 | __raw_writel(intr, imx_usb->base + USB_INTR); | ||
1106 | return IRQ_HANDLED; | ||
1107 | } | ||
1108 | |||
1109 | static irqreturn_t imx_udc_ctrl_irq(int irq, void *dev) | ||
1110 | { | ||
1111 | struct imx_udc_struct *imx_usb = dev; | ||
1112 | int intr = __raw_readl(imx_usb->base + USB_EP_INTR(0)); | ||
1113 | |||
1114 | dump_ep_intr(__func__, 0, intr, imx_usb->dev); | ||
1115 | |||
1116 | if (!imx_usb->driver) { | ||
1117 | __raw_writel(intr, imx_usb->base + USB_EP_INTR(0)); | ||
1118 | return IRQ_HANDLED; | ||
1119 | } | ||
1120 | |||
1121 | /* DEVREQ IRQ has highest priority */ | ||
1122 | if (intr & (EPINTR_DEVREQ | EPINTR_MDEVREQ)) | ||
1123 | handle_ep0_devreq(imx_usb); | ||
1124 | /* Seem i.MX is missing EOF interrupt sometimes. | ||
1125 | * Therefore we monitor both EOF and FIFO_EMPTY interrups | ||
1126 | * when transmiting, and both EOF and FIFO_FULL when | ||
1127 | * receiving data. | ||
1128 | */ | ||
1129 | else if (intr & (EPINTR_EOF | EPINTR_FIFO_EMPTY | EPINTR_FIFO_FULL)) | ||
1130 | handle_ep0(&imx_usb->imx_ep[0]); | ||
1131 | |||
1132 | __raw_writel(intr, imx_usb->base + USB_EP_INTR(0)); | ||
1133 | |||
1134 | return IRQ_HANDLED; | ||
1135 | } | ||
1136 | |||
1137 | static irqreturn_t imx_udc_bulk_irq(int irq, void *dev) | ||
1138 | { | ||
1139 | struct imx_udc_struct *imx_usb = dev; | ||
1140 | struct imx_ep_struct *imx_ep = &imx_usb->imx_ep[irq - USBD_INT0]; | ||
1141 | int intr = __raw_readl(imx_usb->base + USB_EP_INTR(EP_NO(imx_ep))); | ||
1142 | |||
1143 | dump_ep_intr(__func__, irq - USBD_INT0, intr, imx_usb->dev); | ||
1144 | |||
1145 | if (!imx_usb->driver) { | ||
1146 | __raw_writel(intr, imx_usb->base + USB_EP_INTR(EP_NO(imx_ep))); | ||
1147 | return IRQ_HANDLED; | ||
1148 | } | ||
1149 | |||
1150 | handle_ep(imx_ep); | ||
1151 | |||
1152 | __raw_writel(intr, imx_usb->base + USB_EP_INTR(EP_NO(imx_ep))); | ||
1153 | |||
1154 | return IRQ_HANDLED; | ||
1155 | } | ||
1156 | |||
1157 | irq_handler_t intr_handler(int i) | ||
1158 | { | ||
1159 | switch (i) { | ||
1160 | case 0: | ||
1161 | return imx_udc_ctrl_irq; | ||
1162 | case 1: | ||
1163 | case 2: | ||
1164 | case 3: | ||
1165 | case 4: | ||
1166 | case 5: | ||
1167 | return imx_udc_bulk_irq; | ||
1168 | default: | ||
1169 | return imx_udc_irq; | ||
1170 | } | ||
1171 | } | ||
1172 | |||
1173 | /******************************************************************************* | ||
1174 | * Static defined IMX UDC structure | ||
1175 | ******************************************************************************* | ||
1176 | */ | ||
1177 | |||
1178 | static const struct usb_gadget_ops imx_udc_ops = { | ||
1179 | .get_frame = imx_udc_get_frame, | ||
1180 | .wakeup = imx_udc_wakeup, | ||
1181 | }; | ||
1182 | |||
1183 | static struct imx_udc_struct controller = { | ||
1184 | .gadget = { | ||
1185 | .ops = &imx_udc_ops, | ||
1186 | .ep0 = &controller.imx_ep[0].ep, | ||
1187 | .name = driver_name, | ||
1188 | .dev = { | ||
1189 | .bus_id = "gadget", | ||
1190 | }, | ||
1191 | }, | ||
1192 | |||
1193 | .imx_ep[0] = { | ||
1194 | .ep = { | ||
1195 | .name = ep0name, | ||
1196 | .ops = &imx_ep_ops, | ||
1197 | .maxpacket = 32, | ||
1198 | }, | ||
1199 | .imx_usb = &controller, | ||
1200 | .fifosize = 32, | ||
1201 | .bEndpointAddress = 0, | ||
1202 | .bmAttributes = USB_ENDPOINT_XFER_CONTROL, | ||
1203 | }, | ||
1204 | .imx_ep[1] = { | ||
1205 | .ep = { | ||
1206 | .name = "ep1in-bulk", | ||
1207 | .ops = &imx_ep_ops, | ||
1208 | .maxpacket = 64, | ||
1209 | }, | ||
1210 | .imx_usb = &controller, | ||
1211 | .fifosize = 64, | ||
1212 | .bEndpointAddress = USB_DIR_IN | 1, | ||
1213 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
1214 | }, | ||
1215 | .imx_ep[2] = { | ||
1216 | .ep = { | ||
1217 | .name = "ep2out-bulk", | ||
1218 | .ops = &imx_ep_ops, | ||
1219 | .maxpacket = 64, | ||
1220 | }, | ||
1221 | .imx_usb = &controller, | ||
1222 | .fifosize = 64, | ||
1223 | .bEndpointAddress = USB_DIR_OUT | 2, | ||
1224 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
1225 | }, | ||
1226 | .imx_ep[3] = { | ||
1227 | .ep = { | ||
1228 | .name = "ep3out-bulk", | ||
1229 | .ops = &imx_ep_ops, | ||
1230 | .maxpacket = 32, | ||
1231 | }, | ||
1232 | .imx_usb = &controller, | ||
1233 | .fifosize = 32, | ||
1234 | .bEndpointAddress = USB_DIR_OUT | 3, | ||
1235 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
1236 | }, | ||
1237 | .imx_ep[4] = { | ||
1238 | .ep = { | ||
1239 | .name = "ep4in-int", | ||
1240 | .ops = &imx_ep_ops, | ||
1241 | .maxpacket = 32, | ||
1242 | }, | ||
1243 | .imx_usb = &controller, | ||
1244 | .fifosize = 32, | ||
1245 | .bEndpointAddress = USB_DIR_IN | 4, | ||
1246 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
1247 | }, | ||
1248 | .imx_ep[5] = { | ||
1249 | .ep = { | ||
1250 | .name = "ep5out-int", | ||
1251 | .ops = &imx_ep_ops, | ||
1252 | .maxpacket = 32, | ||
1253 | }, | ||
1254 | .imx_usb = &controller, | ||
1255 | .fifosize = 32, | ||
1256 | .bEndpointAddress = USB_DIR_OUT | 5, | ||
1257 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
1258 | }, | ||
1259 | }; | ||
1260 | |||
1261 | /******************************************************************************* | ||
1262 | * USB gadged driver functions | ||
1263 | ******************************************************************************* | ||
1264 | */ | ||
1265 | int usb_gadget_register_driver(struct usb_gadget_driver *driver) | ||
1266 | { | ||
1267 | struct imx_udc_struct *imx_usb = &controller; | ||
1268 | int retval; | ||
1269 | |||
1270 | if (!driver | ||
1271 | || driver->speed < USB_SPEED_FULL | ||
1272 | || !driver->bind | ||
1273 | || !driver->disconnect | ||
1274 | || !driver->setup) | ||
1275 | return -EINVAL; | ||
1276 | if (!imx_usb) | ||
1277 | return -ENODEV; | ||
1278 | if (imx_usb->driver) | ||
1279 | return -EBUSY; | ||
1280 | |||
1281 | /* first hook up the driver ... */ | ||
1282 | imx_usb->driver = driver; | ||
1283 | imx_usb->gadget.dev.driver = &driver->driver; | ||
1284 | |||
1285 | retval = device_add(&imx_usb->gadget.dev); | ||
1286 | if (retval) | ||
1287 | goto fail; | ||
1288 | retval = driver->bind(&imx_usb->gadget); | ||
1289 | if (retval) { | ||
1290 | D_ERR(imx_usb->dev, "<%s> bind to driver %s --> error %d\n", | ||
1291 | __func__, driver->driver.name, retval); | ||
1292 | device_del(&imx_usb->gadget.dev); | ||
1293 | |||
1294 | goto fail; | ||
1295 | } | ||
1296 | |||
1297 | D_INI(imx_usb->dev, "<%s> registered gadget driver '%s'\n", | ||
1298 | __func__, driver->driver.name); | ||
1299 | |||
1300 | imx_udc_enable(imx_usb); | ||
1301 | |||
1302 | return 0; | ||
1303 | fail: | ||
1304 | imx_usb->driver = NULL; | ||
1305 | imx_usb->gadget.dev.driver = NULL; | ||
1306 | return retval; | ||
1307 | } | ||
1308 | EXPORT_SYMBOL(usb_gadget_register_driver); | ||
1309 | |||
1310 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | ||
1311 | { | ||
1312 | struct imx_udc_struct *imx_usb = &controller; | ||
1313 | |||
1314 | if (!imx_usb) | ||
1315 | return -ENODEV; | ||
1316 | if (!driver || driver != imx_usb->driver || !driver->unbind) | ||
1317 | return -EINVAL; | ||
1318 | |||
1319 | udc_stop_activity(imx_usb, driver); | ||
1320 | imx_udc_disable(imx_usb); | ||
1321 | |||
1322 | driver->unbind(&imx_usb->gadget); | ||
1323 | imx_usb->gadget.dev.driver = NULL; | ||
1324 | imx_usb->driver = NULL; | ||
1325 | |||
1326 | device_del(&imx_usb->gadget.dev); | ||
1327 | |||
1328 | D_INI(imx_usb->dev, "<%s> unregistered gadget driver '%s'\n", | ||
1329 | __func__, driver->driver.name); | ||
1330 | |||
1331 | return 0; | ||
1332 | } | ||
1333 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1334 | |||
1335 | /******************************************************************************* | ||
1336 | * Module functions | ||
1337 | ******************************************************************************* | ||
1338 | */ | ||
1339 | |||
1340 | static int __init imx_udc_probe(struct platform_device *pdev) | ||
1341 | { | ||
1342 | struct imx_udc_struct *imx_usb = &controller; | ||
1343 | struct resource *res; | ||
1344 | struct imxusb_platform_data *pdata; | ||
1345 | struct clk *clk; | ||
1346 | void __iomem *base; | ||
1347 | int ret = 0; | ||
1348 | int i, res_size; | ||
1349 | |||
1350 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
1351 | if (!res) { | ||
1352 | dev_err(&pdev->dev, "can't get device resources\n"); | ||
1353 | return -ENODEV; | ||
1354 | } | ||
1355 | |||
1356 | pdata = pdev->dev.platform_data; | ||
1357 | if (!pdata) { | ||
1358 | dev_err(&pdev->dev, "driver needs platform data\n"); | ||
1359 | return -ENODEV; | ||
1360 | } | ||
1361 | |||
1362 | res_size = res->end - res->start + 1; | ||
1363 | if (!request_mem_region(res->start, res_size, res->name)) { | ||
1364 | dev_err(&pdev->dev, "can't allocate %d bytes at %d address\n", | ||
1365 | res_size, res->start); | ||
1366 | return -ENOMEM; | ||
1367 | } | ||
1368 | |||
1369 | if (pdata->init) { | ||
1370 | ret = pdata->init(&pdev->dev); | ||
1371 | if (ret) | ||
1372 | goto fail0; | ||
1373 | } | ||
1374 | |||
1375 | base = ioremap(res->start, res_size); | ||
1376 | if (!base) { | ||
1377 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
1378 | ret = -EIO; | ||
1379 | goto fail1; | ||
1380 | } | ||
1381 | |||
1382 | clk = clk_get(NULL, "usbd_clk"); | ||
1383 | if (IS_ERR(clk)) { | ||
1384 | ret = PTR_ERR(clk); | ||
1385 | dev_err(&pdev->dev, "can't get USB clock\n"); | ||
1386 | goto fail2; | ||
1387 | } | ||
1388 | clk_enable(clk); | ||
1389 | |||
1390 | if (clk_get_rate(clk) != 48000000) { | ||
1391 | D_INI(&pdev->dev, | ||
1392 | "Bad USB clock (%d Hz), changing to 48000000 Hz\n", | ||
1393 | (int)clk_get_rate(clk)); | ||
1394 | if (clk_set_rate(clk, 48000000)) { | ||
1395 | dev_err(&pdev->dev, | ||
1396 | "Unable to set correct USB clock (48MHz)\n"); | ||
1397 | ret = -EIO; | ||
1398 | goto fail3; | ||
1399 | } | ||
1400 | } | ||
1401 | |||
1402 | for (i = 0; i < IMX_USB_NB_EP + 1; i++) { | ||
1403 | imx_usb->usbd_int[i] = platform_get_irq(pdev, i); | ||
1404 | if (imx_usb->usbd_int[i] < 0) { | ||
1405 | dev_err(&pdev->dev, "can't get irq number\n"); | ||
1406 | ret = -ENODEV; | ||
1407 | goto fail3; | ||
1408 | } | ||
1409 | } | ||
1410 | |||
1411 | for (i = 0; i < IMX_USB_NB_EP + 1; i++) { | ||
1412 | ret = request_irq(imx_usb->usbd_int[i], intr_handler(i), | ||
1413 | IRQF_DISABLED, driver_name, imx_usb); | ||
1414 | if (ret) { | ||
1415 | dev_err(&pdev->dev, "can't get irq %i, err %d\n", | ||
1416 | imx_usb->usbd_int[i], ret); | ||
1417 | for (--i; i >= 0; i--) | ||
1418 | free_irq(imx_usb->usbd_int[i], imx_usb); | ||
1419 | goto fail3; | ||
1420 | } | ||
1421 | } | ||
1422 | |||
1423 | imx_usb->res = res; | ||
1424 | imx_usb->base = base; | ||
1425 | imx_usb->clk = clk; | ||
1426 | imx_usb->dev = &pdev->dev; | ||
1427 | |||
1428 | device_initialize(&imx_usb->gadget.dev); | ||
1429 | |||
1430 | imx_usb->gadget.dev.parent = &pdev->dev; | ||
1431 | imx_usb->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
1432 | |||
1433 | platform_set_drvdata(pdev, imx_usb); | ||
1434 | |||
1435 | usb_init_data(imx_usb); | ||
1436 | imx_udc_init(imx_usb); | ||
1437 | |||
1438 | return 0; | ||
1439 | |||
1440 | fail3: | ||
1441 | clk_put(clk); | ||
1442 | clk_disable(clk); | ||
1443 | fail2: | ||
1444 | iounmap(base); | ||
1445 | fail1: | ||
1446 | if (pdata->exit) | ||
1447 | pdata->exit(&pdev->dev); | ||
1448 | fail0: | ||
1449 | release_mem_region(res->start, res_size); | ||
1450 | return ret; | ||
1451 | } | ||
1452 | |||
1453 | static int __exit imx_udc_remove(struct platform_device *pdev) | ||
1454 | { | ||
1455 | struct imx_udc_struct *imx_usb = platform_get_drvdata(pdev); | ||
1456 | struct imxusb_platform_data *pdata = pdev->dev.platform_data; | ||
1457 | int i; | ||
1458 | |||
1459 | imx_udc_disable(imx_usb); | ||
1460 | |||
1461 | for (i = 0; i < IMX_USB_NB_EP + 1; i++) | ||
1462 | free_irq(imx_usb->usbd_int[i], imx_usb); | ||
1463 | |||
1464 | clk_put(imx_usb->clk); | ||
1465 | clk_disable(imx_usb->clk); | ||
1466 | iounmap(imx_usb->base); | ||
1467 | |||
1468 | release_mem_region(imx_usb->res->start, | ||
1469 | imx_usb->res->end - imx_usb->res->start + 1); | ||
1470 | |||
1471 | if (pdata->exit) | ||
1472 | pdata->exit(&pdev->dev); | ||
1473 | |||
1474 | platform_set_drvdata(pdev, NULL); | ||
1475 | |||
1476 | return 0; | ||
1477 | } | ||
1478 | |||
1479 | /*----------------------------------------------------------------------------*/ | ||
1480 | |||
1481 | #ifdef CONFIG_PM | ||
1482 | #define imx_udc_suspend NULL | ||
1483 | #define imx_udc_resume NULL | ||
1484 | #else | ||
1485 | #define imx_udc_suspend NULL | ||
1486 | #define imx_udc_resume NULL | ||
1487 | #endif | ||
1488 | |||
1489 | /*----------------------------------------------------------------------------*/ | ||
1490 | |||
1491 | static struct platform_driver udc_driver = { | ||
1492 | .driver = { | ||
1493 | .name = driver_name, | ||
1494 | .owner = THIS_MODULE, | ||
1495 | }, | ||
1496 | .remove = __exit_p(imx_udc_remove), | ||
1497 | .suspend = imx_udc_suspend, | ||
1498 | .resume = imx_udc_resume, | ||
1499 | }; | ||
1500 | |||
1501 | static int __init udc_init(void) | ||
1502 | { | ||
1503 | return platform_driver_probe(&udc_driver, imx_udc_probe); | ||
1504 | } | ||
1505 | module_init(udc_init); | ||
1506 | |||
1507 | static void __exit udc_exit(void) | ||
1508 | { | ||
1509 | platform_driver_unregister(&udc_driver); | ||
1510 | } | ||
1511 | module_exit(udc_exit); | ||
1512 | |||
1513 | MODULE_DESCRIPTION("IMX USB Device Controller driver"); | ||
1514 | MODULE_AUTHOR("Darius Augulis <augulis.darius@gmail.com>"); | ||
1515 | MODULE_LICENSE("GPL"); | ||
1516 | MODULE_ALIAS("platform:imx_udc"); | ||
diff --git a/drivers/usb/gadget/imx_udc.h b/drivers/usb/gadget/imx_udc.h new file mode 100644 index 000000000000..850076937d8d --- /dev/null +++ b/drivers/usb/gadget/imx_udc.h | |||
@@ -0,0 +1,344 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2005 Mike Lee(eemike@gmail.com) | ||
3 | * | ||
4 | * This udc driver is now under testing and code is based on pxa2xx_udc.h | ||
5 | * Please use it with your own risk! | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | */ | ||
17 | |||
18 | #ifndef __LINUX_USB_GADGET_IMX_H | ||
19 | #define __LINUX_USB_GADGET_IMX_H | ||
20 | |||
21 | #include <linux/types.h> | ||
22 | |||
23 | /* Helper macros */ | ||
24 | #define EP_NO(ep) ((ep->bEndpointAddress) & ~USB_DIR_IN) /* IN:1, OUT:0 */ | ||
25 | #define EP_DIR(ep) ((ep->bEndpointAddress) & USB_DIR_IN ? 1 : 0) | ||
26 | #define irq_to_ep(irq) (((irq) >= USBD_INT0) || ((irq) <= USBD_INT6) ? ((irq) - USBD_INT0) : (USBD_INT6)) /*should not happen*/ | ||
27 | #define ep_to_irq(ep) (EP_NO((ep)) + USBD_INT0) | ||
28 | #define IMX_USB_NB_EP 6 | ||
29 | |||
30 | /* Driver structures */ | ||
31 | struct imx_request { | ||
32 | struct usb_request req; | ||
33 | struct list_head queue; | ||
34 | unsigned int in_use; | ||
35 | }; | ||
36 | |||
37 | enum ep0_state { | ||
38 | EP0_IDLE, | ||
39 | EP0_IN_DATA_PHASE, | ||
40 | EP0_OUT_DATA_PHASE, | ||
41 | EP0_CONFIG, | ||
42 | EP0_STALL, | ||
43 | }; | ||
44 | |||
45 | struct imx_ep_struct { | ||
46 | struct usb_ep ep; | ||
47 | struct imx_udc_struct *imx_usb; | ||
48 | struct list_head queue; | ||
49 | unsigned char stopped; | ||
50 | unsigned char fifosize; | ||
51 | unsigned char bEndpointAddress; | ||
52 | unsigned char bmAttributes; | ||
53 | }; | ||
54 | |||
55 | struct imx_udc_struct { | ||
56 | struct usb_gadget gadget; | ||
57 | struct usb_gadget_driver *driver; | ||
58 | struct device *dev; | ||
59 | struct imx_ep_struct imx_ep[IMX_USB_NB_EP]; | ||
60 | struct clk *clk; | ||
61 | enum ep0_state ep0state; | ||
62 | struct resource *res; | ||
63 | void __iomem *base; | ||
64 | unsigned char set_config; | ||
65 | int cfg, | ||
66 | intf, | ||
67 | alt, | ||
68 | usbd_int[7]; | ||
69 | }; | ||
70 | |||
71 | /* USB registers */ | ||
72 | #define USB_FRAME (0x00) /* USB frame */ | ||
73 | #define USB_SPEC (0x04) /* USB Spec */ | ||
74 | #define USB_STAT (0x08) /* USB Status */ | ||
75 | #define USB_CTRL (0x0C) /* USB Control */ | ||
76 | #define USB_DADR (0x10) /* USB Desc RAM addr */ | ||
77 | #define USB_DDAT (0x14) /* USB Desc RAM/EP buffer data */ | ||
78 | #define USB_INTR (0x18) /* USB interrupt */ | ||
79 | #define USB_MASK (0x1C) /* USB Mask */ | ||
80 | #define USB_ENAB (0x24) /* USB Enable */ | ||
81 | #define USB_EP_STAT(x) (0x30 + (x*0x30)) /* USB status/control */ | ||
82 | #define USB_EP_INTR(x) (0x34 + (x*0x30)) /* USB interrupt */ | ||
83 | #define USB_EP_MASK(x) (0x38 + (x*0x30)) /* USB mask */ | ||
84 | #define USB_EP_FDAT(x) (0x3C + (x*0x30)) /* USB FIFO data */ | ||
85 | #define USB_EP_FDAT0(x) (0x3C + (x*0x30)) /* USB FIFO data */ | ||
86 | #define USB_EP_FDAT1(x) (0x3D + (x*0x30)) /* USB FIFO data */ | ||
87 | #define USB_EP_FDAT2(x) (0x3E + (x*0x30)) /* USB FIFO data */ | ||
88 | #define USB_EP_FDAT3(x) (0x3F + (x*0x30)) /* USB FIFO data */ | ||
89 | #define USB_EP_FSTAT(x) (0x40 + (x*0x30)) /* USB FIFO status */ | ||
90 | #define USB_EP_FCTRL(x) (0x44 + (x*0x30)) /* USB FIFO control */ | ||
91 | #define USB_EP_LRFP(x) (0x48 + (x*0x30)) /* USB last read frame pointer */ | ||
92 | #define USB_EP_LWFP(x) (0x4C + (x*0x30)) /* USB last write frame pointer */ | ||
93 | #define USB_EP_FALRM(x) (0x50 + (x*0x30)) /* USB FIFO alarm */ | ||
94 | #define USB_EP_FRDP(x) (0x54 + (x*0x30)) /* USB FIFO read pointer */ | ||
95 | #define USB_EP_FWRP(x) (0x58 + (x*0x30)) /* USB FIFO write pointer */ | ||
96 | /* USB Control Register Bit Fields.*/ | ||
97 | #define CTRL_CMDOVER (1<<6) /* UDC status */ | ||
98 | #define CTRL_CMDERROR (1<<5) /* UDC status */ | ||
99 | #define CTRL_FE_ENA (1<<3) /* Enable Font End logic */ | ||
100 | #define CTRL_UDC_RST (1<<2) /* UDC reset */ | ||
101 | #define CTRL_AFE_ENA (1<<1) /* Analog Font end enable */ | ||
102 | #define CTRL_RESUME (1<<0) /* UDC resume */ | ||
103 | /* USB Status Register Bit Fields.*/ | ||
104 | #define STAT_RST (1<<8) | ||
105 | #define STAT_SUSP (1<<7) | ||
106 | #define STAT_CFG (3<<5) | ||
107 | #define STAT_INTF (3<<3) | ||
108 | #define STAT_ALTSET (7<<0) | ||
109 | /* USB Interrupt Status/Mask Registers Bit fields */ | ||
110 | #define INTR_WAKEUP (1<<31) /* Wake up Interrupt */ | ||
111 | #define INTR_MSOF (1<<7) /* Missed Start of Frame */ | ||
112 | #define INTR_SOF (1<<6) /* Start of Frame */ | ||
113 | #define INTR_RESET_STOP (1<<5) /* Reset Signaling stop */ | ||
114 | #define INTR_RESET_START (1<<4) /* Reset Signaling start */ | ||
115 | #define INTR_RESUME (1<<3) /* Suspend to resume */ | ||
116 | #define INTR_SUSPEND (1<<2) /* Active to suspend */ | ||
117 | #define INTR_FRAME_MATCH (1<<1) /* Frame matched */ | ||
118 | #define INTR_CFG_CHG (1<<0) /* Configuration change occurred */ | ||
119 | /* USB Enable Register Bit Fields.*/ | ||
120 | #define ENAB_RST (1<<31) /* Reset USB modules */ | ||
121 | #define ENAB_ENAB (1<<30) /* Enable USB modules*/ | ||
122 | #define ENAB_SUSPEND (1<<29) /* Suspend USB modules */ | ||
123 | #define ENAB_ENDIAN (1<<28) /* Endian of USB modules */ | ||
124 | #define ENAB_PWRMD (1<<0) /* Power mode of USB modules */ | ||
125 | /* USB Descriptor Ram Address Register bit fields */ | ||
126 | #define DADR_CFG (1<<31) /* Configuration */ | ||
127 | #define DADR_BSY (1<<30) /* Busy status */ | ||
128 | #define DADR_DADR (0x1FF) /* Descriptor Ram Address */ | ||
129 | /* USB Descriptor RAM/Endpoint Buffer Data Register bit fields */ | ||
130 | #define DDAT_DDAT (0xFF) /* Descriptor Endpoint Buffer */ | ||
131 | /* USB Endpoint Status Register bit fields */ | ||
132 | #define EPSTAT_BCOUNT (0x7F<<16) /* Endpoint FIFO byte count */ | ||
133 | #define EPSTAT_SIP (1<<8) /* Endpoint setup in progress */ | ||
134 | #define EPSTAT_DIR (1<<7) /* Endpoint transfer direction */ | ||
135 | #define EPSTAT_MAX (3<<5) /* Endpoint Max packet size */ | ||
136 | #define EPSTAT_TYP (3<<3) /* Endpoint type */ | ||
137 | #define EPSTAT_ZLPS (1<<2) /* Send zero length packet */ | ||
138 | #define EPSTAT_FLUSH (1<<1) /* Endpoint FIFO Flush */ | ||
139 | #define EPSTAT_STALL (1<<0) /* Force stall */ | ||
140 | /* USB Endpoint FIFO Status Register bit fields */ | ||
141 | #define FSTAT_FRAME_STAT (0xF<<24) /* Frame status bit [0-3] */ | ||
142 | #define FSTAT_ERR (1<<22) /* FIFO error */ | ||
143 | #define FSTAT_UF (1<<21) /* FIFO underflow */ | ||
144 | #define FSTAT_OF (1<<20) /* FIFO overflow */ | ||
145 | #define FSTAT_FR (1<<19) /* FIFO frame ready */ | ||
146 | #define FSTAT_FULL (1<<18) /* FIFO full */ | ||
147 | #define FSTAT_ALRM (1<<17) /* FIFO alarm */ | ||
148 | #define FSTAT_EMPTY (1<<16) /* FIFO empty */ | ||
149 | /* USB Endpoint FIFO Control Register bit fields */ | ||
150 | #define FCTRL_WFR (1<<29) /* Write frame end */ | ||
151 | /* USB Endpoint Interrupt Status Regsiter bit fields */ | ||
152 | #define EPINTR_FIFO_FULL (1<<8) /* fifo full */ | ||
153 | #define EPINTR_FIFO_EMPTY (1<<7) /* fifo empty */ | ||
154 | #define EPINTR_FIFO_ERROR (1<<6) /* fifo error */ | ||
155 | #define EPINTR_FIFO_HIGH (1<<5) /* fifo high */ | ||
156 | #define EPINTR_FIFO_LOW (1<<4) /* fifo low */ | ||
157 | #define EPINTR_MDEVREQ (1<<3) /* multi Device request */ | ||
158 | #define EPINTR_EOT (1<<2) /* fifo end of transfer */ | ||
159 | #define EPINTR_DEVREQ (1<<1) /* Device request */ | ||
160 | #define EPINTR_EOF (1<<0) /* fifo end of frame */ | ||
161 | |||
162 | /* Debug macros */ | ||
163 | #ifdef DEBUG | ||
164 | |||
165 | /* #define DEBUG_REQ */ | ||
166 | /* #define DEBUG_TRX */ | ||
167 | /* #define DEBUG_INIT */ | ||
168 | /* #define DEBUG_EP0 */ | ||
169 | /* #define DEBUG_EPX */ | ||
170 | /* #define DEBUG_IRQ */ | ||
171 | /* #define DEBUG_EPIRQ */ | ||
172 | /* #define DEBUG_DUMP */ | ||
173 | #define DEBUG_ERR | ||
174 | |||
175 | #ifdef DEBUG_REQ | ||
176 | #define D_REQ(dev, args...) dev_dbg(dev, ## args) | ||
177 | #else | ||
178 | #define D_REQ(dev, args...) do {} while (0) | ||
179 | #endif /* DEBUG_REQ */ | ||
180 | |||
181 | #ifdef DEBUG_TRX | ||
182 | #define D_TRX(dev, args...) dev_dbg(dev, ## args) | ||
183 | #else | ||
184 | #define D_TRX(dev, args...) do {} while (0) | ||
185 | #endif /* DEBUG_TRX */ | ||
186 | |||
187 | #ifdef DEBUG_INIT | ||
188 | #define D_INI(dev, args...) dev_dbg(dev, ## args) | ||
189 | #else | ||
190 | #define D_INI(dev, args...) do {} while (0) | ||
191 | #endif /* DEBUG_INIT */ | ||
192 | |||
193 | #ifdef DEBUG_EP0 | ||
194 | static const char *state_name[] = { | ||
195 | "EP0_IDLE", | ||
196 | "EP0_IN_DATA_PHASE", | ||
197 | "EP0_OUT_DATA_PHASE", | ||
198 | "EP0_CONFIG", | ||
199 | "EP0_STALL" | ||
200 | }; | ||
201 | #define D_EP0(dev, args...) dev_dbg(dev, ## args) | ||
202 | #else | ||
203 | #define D_EP0(dev, args...) do {} while (0) | ||
204 | #endif /* DEBUG_EP0 */ | ||
205 | |||
206 | #ifdef DEBUG_EPX | ||
207 | #define D_EPX(dev, args...) dev_dbg(dev, ## args) | ||
208 | #else | ||
209 | #define D_EPX(dev, args...) do {} while (0) | ||
210 | #endif /* DEBUG_EP0 */ | ||
211 | |||
212 | #ifdef DEBUG_IRQ | ||
213 | static void dump_intr(const char *label, int irqreg, struct device *dev) | ||
214 | { | ||
215 | dev_dbg(dev, "<%s> USB_INTR=[%s%s%s%s%s%s%s%s%s]\n", label, | ||
216 | (irqreg & INTR_WAKEUP) ? " wake" : "", | ||
217 | (irqreg & INTR_MSOF) ? " msof" : "", | ||
218 | (irqreg & INTR_SOF) ? " sof" : "", | ||
219 | (irqreg & INTR_RESUME) ? " resume" : "", | ||
220 | (irqreg & INTR_SUSPEND) ? " suspend" : "", | ||
221 | (irqreg & INTR_RESET_STOP) ? " noreset" : "", | ||
222 | (irqreg & INTR_RESET_START) ? " reset" : "", | ||
223 | (irqreg & INTR_FRAME_MATCH) ? " fmatch" : "", | ||
224 | (irqreg & INTR_CFG_CHG) ? " config" : ""); | ||
225 | } | ||
226 | #else | ||
227 | #define dump_intr(x, y, z) do {} while (0) | ||
228 | #endif /* DEBUG_IRQ */ | ||
229 | |||
230 | #ifdef DEBUG_EPIRQ | ||
231 | static void dump_ep_intr(const char *label, int nr, int irqreg, struct device *dev) | ||
232 | { | ||
233 | dev_dbg(dev, "<%s> EP%d_INTR=[%s%s%s%s%s%s%s%s%s]\n", label, nr, | ||
234 | (irqreg & EPINTR_FIFO_FULL) ? " full" : "", | ||
235 | (irqreg & EPINTR_FIFO_EMPTY) ? " fempty" : "", | ||
236 | (irqreg & EPINTR_FIFO_ERROR) ? " ferr" : "", | ||
237 | (irqreg & EPINTR_FIFO_HIGH) ? " fhigh" : "", | ||
238 | (irqreg & EPINTR_FIFO_LOW) ? " flow" : "", | ||
239 | (irqreg & EPINTR_MDEVREQ) ? " mreq" : "", | ||
240 | (irqreg & EPINTR_EOF) ? " eof" : "", | ||
241 | (irqreg & EPINTR_DEVREQ) ? " devreq" : "", | ||
242 | (irqreg & EPINTR_EOT) ? " eot" : ""); | ||
243 | } | ||
244 | #else | ||
245 | #define dump_ep_intr(x, y, z, i) do {} while (0) | ||
246 | #endif /* DEBUG_IRQ */ | ||
247 | |||
248 | #ifdef DEBUG_DUMP | ||
249 | static void dump_usb_stat(const char *label, struct imx_udc_struct *imx_usb) | ||
250 | { | ||
251 | int temp = __raw_readl(imx_usb->base + USB_STAT); | ||
252 | |||
253 | dev_dbg(imx_usb->dev, | ||
254 | "<%s> USB_STAT=[%s%s CFG=%d, INTF=%d, ALTR=%d]\n", label, | ||
255 | (temp & STAT_RST) ? " reset" : "", | ||
256 | (temp & STAT_SUSP) ? " suspend" : "", | ||
257 | (temp & STAT_CFG) >> 5, | ||
258 | (temp & STAT_INTF) >> 3, | ||
259 | (temp & STAT_ALTSET)); | ||
260 | } | ||
261 | |||
262 | static void dump_ep_stat(const char *label, struct imx_ep_struct *imx_ep) | ||
263 | { | ||
264 | int temp = __raw_readl(imx_ep->imx_usb->base + USB_EP_INTR(EP_NO(imx_ep))); | ||
265 | |||
266 | dev_dbg(imx_ep->imx_usb->dev, | ||
267 | "<%s> EP%d_INTR=[%s%s%s%s%s%s%s%s%s]\n", label, EP_NO(imx_ep), | ||
268 | (temp & EPINTR_FIFO_FULL) ? " full" : "", | ||
269 | (temp & EPINTR_FIFO_EMPTY) ? " fempty" : "", | ||
270 | (temp & EPINTR_FIFO_ERROR) ? " ferr" : "", | ||
271 | (temp & EPINTR_FIFO_HIGH) ? " fhigh" : "", | ||
272 | (temp & EPINTR_FIFO_LOW) ? " flow" : "", | ||
273 | (temp & EPINTR_MDEVREQ) ? " mreq" : "", | ||
274 | (temp & EPINTR_EOF) ? " eof" : "", | ||
275 | (temp & EPINTR_DEVREQ) ? " devreq" : "", | ||
276 | (temp & EPINTR_EOT) ? " eot" : ""); | ||
277 | |||
278 | temp = __raw_readl(imx_ep->imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); | ||
279 | |||
280 | dev_dbg(imx_ep->imx_usb->dev, | ||
281 | "<%s> EP%d_STAT=[%s%s bcount=%d]\n", label, EP_NO(imx_ep), | ||
282 | (temp & EPSTAT_SIP) ? " sip" : "", | ||
283 | (temp & EPSTAT_STALL) ? " stall" : "", | ||
284 | (temp & EPSTAT_BCOUNT) >> 16); | ||
285 | |||
286 | temp = __raw_readl(imx_ep->imx_usb->base + USB_EP_FSTAT(EP_NO(imx_ep))); | ||
287 | |||
288 | dev_dbg(imx_ep->imx_usb->dev, | ||
289 | "<%s> EP%d_FSTAT=[%s%s%s%s%s%s%s]\n", label, EP_NO(imx_ep), | ||
290 | (temp & FSTAT_ERR) ? " ferr" : "", | ||
291 | (temp & FSTAT_UF) ? " funder" : "", | ||
292 | (temp & FSTAT_OF) ? " fover" : "", | ||
293 | (temp & FSTAT_FR) ? " fready" : "", | ||
294 | (temp & FSTAT_FULL) ? " ffull" : "", | ||
295 | (temp & FSTAT_ALRM) ? " falarm" : "", | ||
296 | (temp & FSTAT_EMPTY) ? " fempty" : ""); | ||
297 | } | ||
298 | |||
299 | static void dump_req(const char *label, struct imx_ep_struct *imx_ep, struct usb_request *req) | ||
300 | { | ||
301 | int i; | ||
302 | |||
303 | if (!req || !req->buf) { | ||
304 | dev_dbg(imx_ep->imx_usb->dev, "<%s> req or req buf is free\n", label); | ||
305 | return; | ||
306 | } | ||
307 | |||
308 | if ((!EP_NO(imx_ep) && imx_ep->imx_usb->ep0state == EP0_IN_DATA_PHASE) | ||
309 | || (EP_NO(imx_ep) && EP_DIR(imx_ep))) { | ||
310 | |||
311 | dev_dbg(imx_ep->imx_usb->dev, "<%s> request dump <", label); | ||
312 | for (i = 0; i < req->length; i++) | ||
313 | printk("%02x-", *((u8 *)req->buf + i)); | ||
314 | printk(">\n"); | ||
315 | } | ||
316 | } | ||
317 | |||
318 | #else | ||
319 | #define dump_ep_stat(x, y) do {} while (0) | ||
320 | #define dump_usb_stat(x, y) do {} while (0) | ||
321 | #define dump_req(x, y, z) do {} while (0) | ||
322 | #endif /* DEBUG_DUMP */ | ||
323 | |||
324 | #ifdef DEBUG_ERR | ||
325 | #define D_ERR(dev, args...) dev_dbg(dev, ## args) | ||
326 | #else | ||
327 | #define D_ERR(dev, args...) do {} while (0) | ||
328 | #endif | ||
329 | |||
330 | #else | ||
331 | #define D_REQ(dev, args...) do {} while (0) | ||
332 | #define D_TRX(dev, args...) do {} while (0) | ||
333 | #define D_INI(dev, args...) do {} while (0) | ||
334 | #define D_EP0(dev, args...) do {} while (0) | ||
335 | #define D_EPX(dev, args...) do {} while (0) | ||
336 | #define dump_ep_intr(x, y, z, i) do {} while (0) | ||
337 | #define dump_intr(x, y, z) do {} while (0) | ||
338 | #define dump_ep_stat(x, y) do {} while (0) | ||
339 | #define dump_usb_stat(x, y) do {} while (0) | ||
340 | #define dump_req(x, y, z) do {} while (0) | ||
341 | #define D_ERR(dev, args...) do {} while (0) | ||
342 | #endif /* DEBUG */ | ||
343 | |||
344 | #endif /* __LINUX_USB_GADGET_IMX_H */ | ||
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index 3a8879ec2061..43dcf9e1af6b 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c | |||
@@ -1546,8 +1546,6 @@ static void nop_completion(struct usb_ep *ep, struct usb_request *r) | |||
1546 | { | 1546 | { |
1547 | } | 1547 | } |
1548 | 1548 | ||
1549 | #define resource_len(r) (((r)->end - (r)->start) + 1) | ||
1550 | |||
1551 | static int __init m66592_probe(struct platform_device *pdev) | 1549 | static int __init m66592_probe(struct platform_device *pdev) |
1552 | { | 1550 | { |
1553 | struct resource *res; | 1551 | struct resource *res; |
@@ -1560,11 +1558,10 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1560 | int ret = 0; | 1558 | int ret = 0; |
1561 | int i; | 1559 | int i; |
1562 | 1560 | ||
1563 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | 1561 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1564 | (char *)udc_name); | ||
1565 | if (!res) { | 1562 | if (!res) { |
1566 | ret = -ENODEV; | 1563 | ret = -ENODEV; |
1567 | pr_err("platform_get_resource_byname error.\n"); | 1564 | pr_err("platform_get_resource error.\n"); |
1568 | goto clean_up; | 1565 | goto clean_up; |
1569 | } | 1566 | } |
1570 | 1567 | ||
@@ -1575,7 +1572,7 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1575 | goto clean_up; | 1572 | goto clean_up; |
1576 | } | 1573 | } |
1577 | 1574 | ||
1578 | reg = ioremap(res->start, resource_len(res)); | 1575 | reg = ioremap(res->start, resource_size(res)); |
1579 | if (reg == NULL) { | 1576 | if (reg == NULL) { |
1580 | ret = -ENOMEM; | 1577 | ret = -ENOMEM; |
1581 | pr_err("ioremap error.\n"); | 1578 | pr_err("ioremap error.\n"); |
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c index 8ae70de2c37d..12c6d83b218c 100644 --- a/drivers/usb/gadget/net2280.c +++ b/drivers/usb/gadget/net2280.c | |||
@@ -669,7 +669,7 @@ fill_dma_desc (struct net2280_ep *ep, struct net2280_request *req, int valid) | |||
669 | 669 | ||
670 | /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */ | 670 | /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */ |
671 | wmb (); | 671 | wmb (); |
672 | td->dmacount = cpu_to_le32p (&dmacount); | 672 | td->dmacount = cpu_to_le32(dmacount); |
673 | } | 673 | } |
674 | 674 | ||
675 | static const u32 dmactl_default = | 675 | static const u32 dmactl_default = |
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c index 34e9e393f929..57d9641c6bf8 100644 --- a/drivers/usb/gadget/omap_udc.c +++ b/drivers/usb/gadget/omap_udc.c | |||
@@ -3006,7 +3006,7 @@ cleanup1: | |||
3006 | 3006 | ||
3007 | cleanup0: | 3007 | cleanup0: |
3008 | if (xceiv) | 3008 | if (xceiv) |
3009 | put_device(xceiv->dev); | 3009 | otg_put_transceiver(xceiv); |
3010 | 3010 | ||
3011 | if (cpu_is_omap16xx() || cpu_is_omap24xx()) { | 3011 | if (cpu_is_omap16xx() || cpu_is_omap24xx()) { |
3012 | clk_disable(hhc_clk); | 3012 | clk_disable(hhc_clk); |
@@ -3034,7 +3034,7 @@ static int __exit omap_udc_remove(struct platform_device *pdev) | |||
3034 | 3034 | ||
3035 | pullup_disable(udc); | 3035 | pullup_disable(udc); |
3036 | if (udc->transceiver) { | 3036 | if (udc->transceiver) { |
3037 | put_device(udc->transceiver->dev); | 3037 | otg_put_transceiver(udc->transceiver); |
3038 | udc->transceiver = NULL; | 3038 | udc->transceiver = NULL; |
3039 | } | 3039 | } |
3040 | omap_writew(0, UDC_SYSCON1); | 3040 | omap_writew(0, UDC_SYSCON1); |
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c index 697a0ca349bf..9b36205c5759 100644 --- a/drivers/usb/gadget/pxa25x_udc.c +++ b/drivers/usb/gadget/pxa25x_udc.c | |||
@@ -2198,7 +2198,7 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev) | |||
2198 | udc_disable(dev); | 2198 | udc_disable(dev); |
2199 | udc_reinit(dev); | 2199 | udc_reinit(dev); |
2200 | 2200 | ||
2201 | dev->vbus = is_vbus_present(); | 2201 | dev->vbus = !!is_vbus_present(); |
2202 | 2202 | ||
2203 | /* irq setup after old hardware state is cleaned up */ | 2203 | /* irq setup after old hardware state is cleaned up */ |
2204 | retval = request_irq(irq, pxa25x_udc_irq, | 2204 | retval = request_irq(irq, pxa25x_udc_irq, |
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c index 65110d02a206..990f40f988d4 100644 --- a/drivers/usb/gadget/pxa27x_udc.c +++ b/drivers/usb/gadget/pxa27x_udc.c | |||
@@ -430,7 +430,6 @@ static void pio_irq_enable(struct pxa_ep *ep) | |||
430 | /** | 430 | /** |
431 | * pio_irq_disable - Disables irq generation for one endpoint | 431 | * pio_irq_disable - Disables irq generation for one endpoint |
432 | * @ep: udc endpoint | 432 | * @ep: udc endpoint |
433 | * @index: endpoint number | ||
434 | */ | 433 | */ |
435 | static void pio_irq_disable(struct pxa_ep *ep) | 434 | static void pio_irq_disable(struct pxa_ep *ep) |
436 | { | 435 | { |
@@ -586,7 +585,6 @@ static void inc_ep_stats_reqs(struct pxa_ep *ep, int is_in) | |||
586 | * inc_ep_stats_bytes - Update ep stats counts | 585 | * inc_ep_stats_bytes - Update ep stats counts |
587 | * @ep: physical endpoint | 586 | * @ep: physical endpoint |
588 | * @count: bytes transfered on endpoint | 587 | * @count: bytes transfered on endpoint |
589 | * @req: usb request | ||
590 | * @is_in: ep direction (USB_DIR_IN or 0) | 588 | * @is_in: ep direction (USB_DIR_IN or 0) |
591 | */ | 589 | */ |
592 | static void inc_ep_stats_bytes(struct pxa_ep *ep, int count, int is_in) | 590 | static void inc_ep_stats_bytes(struct pxa_ep *ep, int count, int is_in) |
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index c7e255636803..9a2b8920532d 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/interrupt.h> | 36 | #include <linux/interrupt.h> |
37 | #include <linux/platform_device.h> | 37 | #include <linux/platform_device.h> |
38 | #include <linux/clk.h> | 38 | #include <linux/clk.h> |
39 | #include <linux/gpio.h> | ||
39 | 40 | ||
40 | #include <linux/debugfs.h> | 41 | #include <linux/debugfs.h> |
41 | #include <linux/seq_file.h> | 42 | #include <linux/seq_file.h> |
@@ -51,7 +52,6 @@ | |||
51 | #include <mach/irqs.h> | 52 | #include <mach/irqs.h> |
52 | 53 | ||
53 | #include <mach/hardware.h> | 54 | #include <mach/hardware.h> |
54 | #include <mach/regs-gpio.h> | ||
55 | 55 | ||
56 | #include <plat/regs-udc.h> | 56 | #include <plat/regs-udc.h> |
57 | #include <plat/udc.h> | 57 | #include <plat/udc.h> |
@@ -1510,11 +1510,7 @@ static irqreturn_t s3c2410_udc_vbus_irq(int irq, void *_dev) | |||
1510 | 1510 | ||
1511 | dprintk(DEBUG_NORMAL, "%s()\n", __func__); | 1511 | dprintk(DEBUG_NORMAL, "%s()\n", __func__); |
1512 | 1512 | ||
1513 | /* some cpus cannot read from an line configured to IRQ! */ | 1513 | value = gpio_get_value(udc_info->vbus_pin) ? 1 : 0; |
1514 | s3c2410_gpio_cfgpin(udc_info->vbus_pin, S3C2410_GPIO_INPUT); | ||
1515 | value = s3c2410_gpio_getpin(udc_info->vbus_pin); | ||
1516 | s3c2410_gpio_cfgpin(udc_info->vbus_pin, S3C2410_GPIO_SFN2); | ||
1517 | |||
1518 | if (udc_info->vbus_pin_inverted) | 1514 | if (udc_info->vbus_pin_inverted) |
1519 | value = !value; | 1515 | value = !value; |
1520 | 1516 | ||
@@ -1802,7 +1798,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev) | |||
1802 | struct s3c2410_udc *udc = &memory; | 1798 | struct s3c2410_udc *udc = &memory; |
1803 | struct device *dev = &pdev->dev; | 1799 | struct device *dev = &pdev->dev; |
1804 | int retval; | 1800 | int retval; |
1805 | unsigned int irq; | 1801 | int irq; |
1806 | 1802 | ||
1807 | dev_dbg(dev, "%s()\n", __func__); | 1803 | dev_dbg(dev, "%s()\n", __func__); |
1808 | 1804 | ||
@@ -1861,7 +1857,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev) | |||
1861 | 1857 | ||
1862 | /* irq setup after old hardware state is cleaned up */ | 1858 | /* irq setup after old hardware state is cleaned up */ |
1863 | retval = request_irq(IRQ_USBD, s3c2410_udc_irq, | 1859 | retval = request_irq(IRQ_USBD, s3c2410_udc_irq, |
1864 | IRQF_DISABLED, gadget_name, udc); | 1860 | IRQF_DISABLED, gadget_name, udc); |
1865 | 1861 | ||
1866 | if (retval != 0) { | 1862 | if (retval != 0) { |
1867 | dev_err(dev, "cannot get irq %i, err %d\n", IRQ_USBD, retval); | 1863 | dev_err(dev, "cannot get irq %i, err %d\n", IRQ_USBD, retval); |
@@ -1872,17 +1868,28 @@ static int s3c2410_udc_probe(struct platform_device *pdev) | |||
1872 | dev_dbg(dev, "got irq %i\n", IRQ_USBD); | 1868 | dev_dbg(dev, "got irq %i\n", IRQ_USBD); |
1873 | 1869 | ||
1874 | if (udc_info && udc_info->vbus_pin > 0) { | 1870 | if (udc_info && udc_info->vbus_pin > 0) { |
1875 | irq = s3c2410_gpio_getirq(udc_info->vbus_pin); | 1871 | retval = gpio_request(udc_info->vbus_pin, "udc vbus"); |
1872 | if (retval < 0) { | ||
1873 | dev_err(dev, "cannot claim vbus pin\n"); | ||
1874 | goto err_int; | ||
1875 | } | ||
1876 | |||
1877 | irq = gpio_to_irq(udc_info->vbus_pin); | ||
1878 | if (irq < 0) { | ||
1879 | dev_err(dev, "no irq for gpio vbus pin\n"); | ||
1880 | goto err_gpio_claim; | ||
1881 | } | ||
1882 | |||
1876 | retval = request_irq(irq, s3c2410_udc_vbus_irq, | 1883 | retval = request_irq(irq, s3c2410_udc_vbus_irq, |
1877 | IRQF_DISABLED | IRQF_TRIGGER_RISING | 1884 | IRQF_DISABLED | IRQF_TRIGGER_RISING |
1878 | | IRQF_TRIGGER_FALLING | IRQF_SHARED, | 1885 | | IRQF_TRIGGER_FALLING | IRQF_SHARED, |
1879 | gadget_name, udc); | 1886 | gadget_name, udc); |
1880 | 1887 | ||
1881 | if (retval != 0) { | 1888 | if (retval != 0) { |
1882 | dev_err(dev, "can't get vbus irq %i, err %d\n", | 1889 | dev_err(dev, "can't get vbus irq %d, err %d\n", |
1883 | irq, retval); | 1890 | irq, retval); |
1884 | retval = -EBUSY; | 1891 | retval = -EBUSY; |
1885 | goto err_int; | 1892 | goto err_gpio_claim; |
1886 | } | 1893 | } |
1887 | 1894 | ||
1888 | dev_dbg(dev, "got irq %i\n", irq); | 1895 | dev_dbg(dev, "got irq %i\n", irq); |
@@ -1902,6 +1909,9 @@ static int s3c2410_udc_probe(struct platform_device *pdev) | |||
1902 | 1909 | ||
1903 | return 0; | 1910 | return 0; |
1904 | 1911 | ||
1912 | err_gpio_claim: | ||
1913 | if (udc_info && udc_info->vbus_pin > 0) | ||
1914 | gpio_free(udc_info->vbus_pin); | ||
1905 | err_int: | 1915 | err_int: |
1906 | free_irq(IRQ_USBD, udc); | 1916 | free_irq(IRQ_USBD, udc); |
1907 | err_map: | 1917 | err_map: |
@@ -1927,7 +1937,7 @@ static int s3c2410_udc_remove(struct platform_device *pdev) | |||
1927 | debugfs_remove(udc->regs_info); | 1937 | debugfs_remove(udc->regs_info); |
1928 | 1938 | ||
1929 | if (udc_info && udc_info->vbus_pin > 0) { | 1939 | if (udc_info && udc_info->vbus_pin > 0) { |
1930 | irq = s3c2410_gpio_getirq(udc_info->vbus_pin); | 1940 | irq = gpio_to_irq(udc_info->vbus_pin); |
1931 | free_irq(irq, udc); | 1941 | free_irq(irq, udc); |
1932 | } | 1942 | } |
1933 | 1943 | ||
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index d9739d52f8f5..96d65ca06ecd 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -716,6 +716,14 @@ static int __init get_ether_addr(const char *str, u8 *dev_addr) | |||
716 | 716 | ||
717 | static struct eth_dev *the_dev; | 717 | static struct eth_dev *the_dev; |
718 | 718 | ||
719 | static const struct net_device_ops eth_netdev_ops = { | ||
720 | .ndo_open = eth_open, | ||
721 | .ndo_stop = eth_stop, | ||
722 | .ndo_start_xmit = eth_start_xmit, | ||
723 | .ndo_change_mtu = ueth_change_mtu, | ||
724 | .ndo_set_mac_address = eth_mac_addr, | ||
725 | .ndo_validate_addr = eth_validate_addr, | ||
726 | }; | ||
719 | 727 | ||
720 | /** | 728 | /** |
721 | * gether_setup - initialize one ethernet-over-usb link | 729 | * gether_setup - initialize one ethernet-over-usb link |
@@ -764,12 +772,8 @@ int __init gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) | |||
764 | if (ethaddr) | 772 | if (ethaddr) |
765 | memcpy(ethaddr, dev->host_mac, ETH_ALEN); | 773 | memcpy(ethaddr, dev->host_mac, ETH_ALEN); |
766 | 774 | ||
767 | net->change_mtu = ueth_change_mtu; | 775 | net->netdev_ops = ð_netdev_ops; |
768 | net->hard_start_xmit = eth_start_xmit; | 776 | |
769 | net->open = eth_open; | ||
770 | net->stop = eth_stop; | ||
771 | /* watchdog_timeo, tx_timeout ... */ | ||
772 | /* set_multicast_list */ | ||
773 | SET_ETHTOOL_OPS(net, &ops); | 777 | SET_ETHTOOL_OPS(net, &ops); |
774 | 778 | ||
775 | /* two kinds of host-initiated state changes: | 779 | /* two kinds of host-initiated state changes: |
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index f3a75a929e0a..2b476b6b3d4d 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig | |||
@@ -96,6 +96,19 @@ config USB_EHCI_HCD_PPC_OF | |||
96 | Enables support for the USB controller present on the PowerPC | 96 | Enables support for the USB controller present on the PowerPC |
97 | OpenFirmware platform bus. | 97 | OpenFirmware platform bus. |
98 | 98 | ||
99 | config USB_OXU210HP_HCD | ||
100 | tristate "OXU210HP HCD support" | ||
101 | depends on USB | ||
102 | ---help--- | ||
103 | The OXU210HP is an USB host/OTG/device controller. Enable this | ||
104 | option if your board has this chip. If unsure, say N. | ||
105 | |||
106 | This driver does not support isochronous transfers and doesn't | ||
107 | implement OTG nor USB device controllers. | ||
108 | |||
109 | To compile this driver as a module, choose M here: the | ||
110 | module will be called oxu210hp-hcd. | ||
111 | |||
99 | config USB_ISP116X_HCD | 112 | config USB_ISP116X_HCD |
100 | tristate "ISP116X HCD support" | 113 | tristate "ISP116X HCD support" |
101 | depends on USB | 114 | depends on USB |
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 23be22224044..e5f3f20787e4 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile | |||
@@ -13,6 +13,7 @@ obj-$(CONFIG_USB_WHCI_HCD) += whci/ | |||
13 | obj-$(CONFIG_PCI) += pci-quirks.o | 13 | obj-$(CONFIG_PCI) += pci-quirks.o |
14 | 14 | ||
15 | obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o | 15 | obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o |
16 | obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o | ||
16 | obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o | 17 | obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o |
17 | obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o | 18 | obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o |
18 | obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o | 19 | obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o |
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index 0cb53ca8d343..7f4ace73d44a 100644 --- a/drivers/usb/host/ehci-dbg.c +++ b/drivers/usb/host/ehci-dbg.c | |||
@@ -455,9 +455,7 @@ static void qh_lines ( | |||
455 | (scratch >> 16) & 0x7fff, | 455 | (scratch >> 16) & 0x7fff, |
456 | scratch, | 456 | scratch, |
457 | td->urb); | 457 | td->urb); |
458 | if (temp < 0) | 458 | if (size < temp) |
459 | temp = 0; | ||
460 | else if (size < temp) | ||
461 | temp = size; | 459 | temp = size; |
462 | size -= temp; | 460 | size -= temp; |
463 | next += temp; | 461 | next += temp; |
@@ -466,9 +464,7 @@ static void qh_lines ( | |||
466 | } | 464 | } |
467 | 465 | ||
468 | temp = snprintf (next, size, "\n"); | 466 | temp = snprintf (next, size, "\n"); |
469 | if (temp < 0) | 467 | if (size < temp) |
470 | temp = 0; | ||
471 | else if (size < temp) | ||
472 | temp = size; | 468 | temp = size; |
473 | size -= temp; | 469 | size -= temp; |
474 | next += temp; | 470 | next += temp; |
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 218f9660d7ee..97a53a48a3d8 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c | |||
@@ -194,6 +194,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd) | |||
194 | u32 temp; | 194 | u32 temp; |
195 | u32 power_okay; | 195 | u32 power_okay; |
196 | int i; | 196 | int i; |
197 | u8 resume_needed = 0; | ||
197 | 198 | ||
198 | if (time_before (jiffies, ehci->next_statechange)) | 199 | if (time_before (jiffies, ehci->next_statechange)) |
199 | msleep(5); | 200 | msleep(5); |
@@ -228,7 +229,9 @@ static int ehci_bus_resume (struct usb_hcd *hcd) | |||
228 | 229 | ||
229 | /* Some controller/firmware combinations need a delay during which | 230 | /* Some controller/firmware combinations need a delay during which |
230 | * they set up the port statuses. See Bugzilla #8190. */ | 231 | * they set up the port statuses. See Bugzilla #8190. */ |
231 | mdelay(8); | 232 | spin_unlock_irq(&ehci->lock); |
233 | msleep(8); | ||
234 | spin_lock_irq(&ehci->lock); | ||
232 | 235 | ||
233 | /* manually resume the ports we suspended during bus_suspend() */ | 236 | /* manually resume the ports we suspended during bus_suspend() */ |
234 | i = HCS_N_PORTS (ehci->hcs_params); | 237 | i = HCS_N_PORTS (ehci->hcs_params); |
@@ -236,12 +239,21 @@ static int ehci_bus_resume (struct usb_hcd *hcd) | |||
236 | temp = ehci_readl(ehci, &ehci->regs->port_status [i]); | 239 | temp = ehci_readl(ehci, &ehci->regs->port_status [i]); |
237 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); | 240 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); |
238 | if (test_bit(i, &ehci->bus_suspended) && | 241 | if (test_bit(i, &ehci->bus_suspended) && |
239 | (temp & PORT_SUSPEND)) | 242 | (temp & PORT_SUSPEND)) { |
240 | temp |= PORT_RESUME; | 243 | temp |= PORT_RESUME; |
244 | resume_needed = 1; | ||
245 | } | ||
241 | ehci_writel(ehci, temp, &ehci->regs->port_status [i]); | 246 | ehci_writel(ehci, temp, &ehci->regs->port_status [i]); |
242 | } | 247 | } |
248 | |||
249 | /* msleep for 20ms only if code is trying to resume port */ | ||
250 | if (resume_needed) { | ||
251 | spin_unlock_irq(&ehci->lock); | ||
252 | msleep(20); | ||
253 | spin_lock_irq(&ehci->lock); | ||
254 | } | ||
255 | |||
243 | i = HCS_N_PORTS (ehci->hcs_params); | 256 | i = HCS_N_PORTS (ehci->hcs_params); |
244 | mdelay (20); | ||
245 | while (i--) { | 257 | while (i--) { |
246 | temp = ehci_readl(ehci, &ehci->regs->port_status [i]); | 258 | temp = ehci_readl(ehci, &ehci->regs->port_status [i]); |
247 | if (test_bit(i, &ehci->bus_suspended) && | 259 | if (test_bit(i, &ehci->bus_suspended) && |
@@ -422,8 +434,15 @@ static int check_reset_complete ( | |||
422 | port_status &= ~PORT_RWC_BITS; | 434 | port_status &= ~PORT_RWC_BITS; |
423 | ehci_writel(ehci, port_status, status_reg); | 435 | ehci_writel(ehci, port_status, status_reg); |
424 | 436 | ||
425 | } else | 437 | /* ensure 440EPX ohci controller state is operational */ |
438 | if (ehci->has_amcc_usb23) | ||
439 | set_ohci_hcfs(ehci, 1); | ||
440 | } else { | ||
426 | ehci_dbg (ehci, "port %d high speed\n", index + 1); | 441 | ehci_dbg (ehci, "port %d high speed\n", index + 1); |
442 | /* ensure 440EPx ohci controller state is suspended */ | ||
443 | if (ehci->has_amcc_usb23) | ||
444 | set_ohci_hcfs(ehci, 0); | ||
445 | } | ||
427 | 446 | ||
428 | return port_status; | 447 | return port_status; |
429 | } | 448 | } |
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c index 36864f958444..bdc6e86e1f8b 100644 --- a/drivers/usb/host/ehci-pci.c +++ b/drivers/usb/host/ehci-pci.c | |||
@@ -219,15 +219,19 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
219 | /* Serial Bus Release Number is at PCI 0x60 offset */ | 219 | /* Serial Bus Release Number is at PCI 0x60 offset */ |
220 | pci_read_config_byte(pdev, 0x60, &ehci->sbrn); | 220 | pci_read_config_byte(pdev, 0x60, &ehci->sbrn); |
221 | 221 | ||
222 | /* Workaround current PCI init glitch: wakeup bits aren't | 222 | /* Keep this around for a while just in case some EHCI |
223 | * being set from PCI PM capability. | 223 | * implementation uses legacy PCI PM support. This test |
224 | * can be removed on 17 Dec 2009 if the dev_warn() hasn't | ||
225 | * been triggered by then. | ||
224 | */ | 226 | */ |
225 | if (!device_can_wakeup(&pdev->dev)) { | 227 | if (!device_can_wakeup(&pdev->dev)) { |
226 | u16 port_wake; | 228 | u16 port_wake; |
227 | 229 | ||
228 | pci_read_config_word(pdev, 0x62, &port_wake); | 230 | pci_read_config_word(pdev, 0x62, &port_wake); |
229 | if (port_wake & 0x0001) | 231 | if (port_wake & 0x0001) { |
232 | dev_warn(&pdev->dev, "Enabling legacy PCI PM\n"); | ||
230 | device_init_wakeup(&pdev->dev, 1); | 233 | device_init_wakeup(&pdev->dev, 1); |
234 | } | ||
231 | } | 235 | } |
232 | 236 | ||
233 | #ifdef CONFIG_USB_SUSPEND | 237 | #ifdef CONFIG_USB_SUSPEND |
@@ -428,6 +432,8 @@ static struct pci_driver ehci_pci_driver = { | |||
428 | 432 | ||
429 | #ifdef CONFIG_PM | 433 | #ifdef CONFIG_PM |
430 | .suspend = usb_hcd_pci_suspend, | 434 | .suspend = usb_hcd_pci_suspend, |
435 | .suspend_late = usb_hcd_pci_suspend_late, | ||
436 | .resume_early = usb_hcd_pci_resume_early, | ||
431 | .resume = usb_hcd_pci_resume, | 437 | .resume = usb_hcd_pci_resume, |
432 | #endif | 438 | #endif |
433 | .shutdown = usb_hcd_pci_shutdown, | 439 | .shutdown = usb_hcd_pci_shutdown, |
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c index b018deed2e8f..ef732b704f53 100644 --- a/drivers/usb/host/ehci-ppc-of.c +++ b/drivers/usb/host/ehci-ppc-of.c | |||
@@ -107,11 +107,13 @@ ehci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match) | |||
107 | { | 107 | { |
108 | struct device_node *dn = op->node; | 108 | struct device_node *dn = op->node; |
109 | struct usb_hcd *hcd; | 109 | struct usb_hcd *hcd; |
110 | struct ehci_hcd *ehci; | 110 | struct ehci_hcd *ehci = NULL; |
111 | struct resource res; | 111 | struct resource res; |
112 | int irq; | 112 | int irq; |
113 | int rv; | 113 | int rv; |
114 | 114 | ||
115 | struct device_node *np; | ||
116 | |||
115 | if (usb_disabled()) | 117 | if (usb_disabled()) |
116 | return -ENODEV; | 118 | return -ENODEV; |
117 | 119 | ||
@@ -149,6 +151,20 @@ ehci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match) | |||
149 | } | 151 | } |
150 | 152 | ||
151 | ehci = hcd_to_ehci(hcd); | 153 | ehci = hcd_to_ehci(hcd); |
154 | np = of_find_compatible_node(NULL, NULL, "ibm,usb-ohci-440epx"); | ||
155 | if (np != NULL) { | ||
156 | /* claim we really affected by usb23 erratum */ | ||
157 | if (!of_address_to_resource(np, 0, &res)) | ||
158 | ehci->ohci_hcctrl_reg = ioremap(res.start + | ||
159 | OHCI_HCCTRL_OFFSET, OHCI_HCCTRL_LEN); | ||
160 | else | ||
161 | pr_debug(__FILE__ ": no ohci offset in fdt\n"); | ||
162 | if (!ehci->ohci_hcctrl_reg) { | ||
163 | pr_debug(__FILE__ ": ioremap for ohci hcctrl failed\n"); | ||
164 | } else { | ||
165 | ehci->has_amcc_usb23 = 1; | ||
166 | } | ||
167 | } | ||
152 | 168 | ||
153 | if (of_get_property(dn, "big-endian", NULL)) { | 169 | if (of_get_property(dn, "big-endian", NULL)) { |
154 | ehci->big_endian_mmio = 1; | 170 | ehci->big_endian_mmio = 1; |
@@ -181,6 +197,9 @@ err_ioremap: | |||
181 | irq_dispose_mapping(irq); | 197 | irq_dispose_mapping(irq); |
182 | err_irq: | 198 | err_irq: |
183 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 199 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
200 | |||
201 | if (ehci->has_amcc_usb23) | ||
202 | iounmap(ehci->ohci_hcctrl_reg); | ||
184 | err_rmr: | 203 | err_rmr: |
185 | usb_put_hcd(hcd); | 204 | usb_put_hcd(hcd); |
186 | 205 | ||
@@ -191,6 +210,11 @@ err_rmr: | |||
191 | static int ehci_hcd_ppc_of_remove(struct of_device *op) | 210 | static int ehci_hcd_ppc_of_remove(struct of_device *op) |
192 | { | 211 | { |
193 | struct usb_hcd *hcd = dev_get_drvdata(&op->dev); | 212 | struct usb_hcd *hcd = dev_get_drvdata(&op->dev); |
213 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
214 | |||
215 | struct device_node *np; | ||
216 | struct resource res; | ||
217 | |||
194 | dev_set_drvdata(&op->dev, NULL); | 218 | dev_set_drvdata(&op->dev, NULL); |
195 | 219 | ||
196 | dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n"); | 220 | dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n"); |
@@ -201,6 +225,25 @@ static int ehci_hcd_ppc_of_remove(struct of_device *op) | |||
201 | irq_dispose_mapping(hcd->irq); | 225 | irq_dispose_mapping(hcd->irq); |
202 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 226 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
203 | 227 | ||
228 | /* use request_mem_region to test if the ohci driver is loaded. if so | ||
229 | * ensure the ohci core is operational. | ||
230 | */ | ||
231 | if (ehci->has_amcc_usb23) { | ||
232 | np = of_find_compatible_node(NULL, NULL, "ibm,usb-ohci-440epx"); | ||
233 | if (np != NULL) { | ||
234 | if (!of_address_to_resource(np, 0, &res)) | ||
235 | if (!request_mem_region(res.start, | ||
236 | 0x4, hcd_name)) | ||
237 | set_ohci_hcfs(ehci, 1); | ||
238 | else | ||
239 | release_mem_region(res.start, 0x4); | ||
240 | else | ||
241 | pr_debug(__FILE__ ": no ohci offset in fdt\n"); | ||
242 | of_node_put(np); | ||
243 | } | ||
244 | |||
245 | iounmap(ehci->ohci_hcctrl_reg); | ||
246 | } | ||
204 | usb_put_hcd(hcd); | 247 | usb_put_hcd(hcd); |
205 | 248 | ||
206 | return 0; | 249 | return 0; |
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index c7d4b5a06bdb..fb7054ccf4fc 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h | |||
@@ -120,6 +120,16 @@ struct ehci_hcd { /* one per controller */ | |||
120 | unsigned has_fsl_port_bug:1; /* FreeScale */ | 120 | unsigned has_fsl_port_bug:1; /* FreeScale */ |
121 | unsigned big_endian_mmio:1; | 121 | unsigned big_endian_mmio:1; |
122 | unsigned big_endian_desc:1; | 122 | unsigned big_endian_desc:1; |
123 | unsigned has_amcc_usb23:1; | ||
124 | |||
125 | /* required for usb32 quirk */ | ||
126 | #define OHCI_CTRL_HCFS (3 << 6) | ||
127 | #define OHCI_USB_OPER (2 << 6) | ||
128 | #define OHCI_USB_SUSPEND (3 << 6) | ||
129 | |||
130 | #define OHCI_HCCTRL_OFFSET 0x4 | ||
131 | #define OHCI_HCCTRL_LEN 0x4 | ||
132 | __hc32 *ohci_hcctrl_reg; | ||
123 | 133 | ||
124 | u8 sbrn; /* packed release number */ | 134 | u8 sbrn; /* packed release number */ |
125 | 135 | ||
@@ -636,6 +646,30 @@ static inline void ehci_writel(const struct ehci_hcd *ehci, | |||
636 | #endif | 646 | #endif |
637 | } | 647 | } |
638 | 648 | ||
649 | /* | ||
650 | * On certain ppc-44x SoC there is a HW issue, that could only worked around with | ||
651 | * explicit suspend/operate of OHCI. This function hereby makes sense only on that arch. | ||
652 | * Other common bits are dependant on has_amcc_usb23 quirk flag. | ||
653 | */ | ||
654 | #ifdef CONFIG_44x | ||
655 | static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational) | ||
656 | { | ||
657 | u32 hc_control; | ||
658 | |||
659 | hc_control = (readl_be(ehci->ohci_hcctrl_reg) & ~OHCI_CTRL_HCFS); | ||
660 | if (operational) | ||
661 | hc_control |= OHCI_USB_OPER; | ||
662 | else | ||
663 | hc_control |= OHCI_USB_SUSPEND; | ||
664 | |||
665 | writel_be(hc_control, ehci->ohci_hcctrl_reg); | ||
666 | (void) readl_be(ehci->ohci_hcctrl_reg); | ||
667 | } | ||
668 | #else | ||
669 | static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational) | ||
670 | { } | ||
671 | #endif | ||
672 | |||
639 | /*-------------------------------------------------------------------------*/ | 673 | /*-------------------------------------------------------------------------*/ |
640 | 674 | ||
641 | /* | 675 | /* |
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c index 8017f1cf78e2..b899f1a59c26 100644 --- a/drivers/usb/host/isp1760-hcd.c +++ b/drivers/usb/host/isp1760-hcd.c | |||
@@ -435,14 +435,13 @@ static int isp1760_hc_setup(struct usb_hcd *hcd) | |||
435 | 435 | ||
436 | /* | 436 | /* |
437 | * PORT 1 Control register of the ISP1760 is the OTG control | 437 | * PORT 1 Control register of the ISP1760 is the OTG control |
438 | * register on ISP1761. | 438 | * register on ISP1761. Since there is no OTG or device controller |
439 | * support in this driver, we use port 1 as a "normal" USB host port on | ||
440 | * both chips. | ||
439 | */ | 441 | */ |
440 | if (!(priv->devflags & ISP1760_FLAG_ISP1761) && | 442 | isp1760_writel(PORT1_POWER | PORT1_INIT2, |
441 | !(priv->devflags & ISP1760_FLAG_PORT1_DIS)) { | 443 | hcd->regs + HC_PORT1_CTRL); |
442 | isp1760_writel(PORT1_POWER | PORT1_INIT2, | 444 | mdelay(10); |
443 | hcd->regs + HC_PORT1_CTRL); | ||
444 | mdelay(10); | ||
445 | } | ||
446 | 445 | ||
447 | priv->hcs_params = isp1760_readl(hcd->regs + HC_HCSPARAMS); | 446 | priv->hcs_params = isp1760_readl(hcd->regs + HC_HCSPARAMS); |
448 | 447 | ||
diff --git a/drivers/usb/host/isp1760-hcd.h b/drivers/usb/host/isp1760-hcd.h index 4377277667d9..a9daea587962 100644 --- a/drivers/usb/host/isp1760-hcd.h +++ b/drivers/usb/host/isp1760-hcd.h | |||
@@ -135,7 +135,6 @@ typedef void (packet_enqueue)(struct usb_hcd *hcd, struct isp1760_qh *qh, | |||
135 | * indicate the most "atypical" case, so that a devflags of 0 is | 135 | * indicate the most "atypical" case, so that a devflags of 0 is |
136 | * a sane default configuration. | 136 | * a sane default configuration. |
137 | */ | 137 | */ |
138 | #define ISP1760_FLAG_PORT1_DIS 0x00000001 /* Port 1 disabled */ | ||
139 | #define ISP1760_FLAG_BUS_WIDTH_16 0x00000002 /* 16-bit data bus width */ | 138 | #define ISP1760_FLAG_BUS_WIDTH_16 0x00000002 /* 16-bit data bus width */ |
140 | #define ISP1760_FLAG_OTG_EN 0x00000004 /* Port 1 supports OTG */ | 139 | #define ISP1760_FLAG_OTG_EN 0x00000004 /* Port 1 supports OTG */ |
141 | #define ISP1760_FLAG_ANALOG_OC 0x00000008 /* Analog overcurrent */ | 140 | #define ISP1760_FLAG_ANALOG_OC 0x00000008 /* Analog overcurrent */ |
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c index b87ca7cf4b37..4cf7ca428b33 100644 --- a/drivers/usb/host/isp1760-if.c +++ b/drivers/usb/host/isp1760-if.c | |||
@@ -60,9 +60,6 @@ static int of_isp1760_probe(struct of_device *dev, | |||
60 | if (of_device_is_compatible(dp, "nxp,usb-isp1761")) | 60 | if (of_device_is_compatible(dp, "nxp,usb-isp1761")) |
61 | devflags |= ISP1760_FLAG_ISP1761; | 61 | devflags |= ISP1760_FLAG_ISP1761; |
62 | 62 | ||
63 | if (of_get_property(dp, "port1-disable", NULL) != NULL) | ||
64 | devflags |= ISP1760_FLAG_PORT1_DIS; | ||
65 | |||
66 | /* Some systems wire up only 16 of the 32 data lines */ | 63 | /* Some systems wire up only 16 of the 32 data lines */ |
67 | prop = of_get_property(dp, "bus-width", NULL); | 64 | prop = of_get_property(dp, "bus-width", NULL); |
68 | if (prop && *prop == 16) | 65 | if (prop && *prop == 16) |
@@ -129,23 +126,23 @@ static struct of_platform_driver isp1760_of_driver = { | |||
129 | #endif | 126 | #endif |
130 | 127 | ||
131 | #ifdef CONFIG_PCI | 128 | #ifdef CONFIG_PCI |
132 | static u32 nxp_pci_io_base; | ||
133 | static u32 iolength; | ||
134 | static u32 pci_mem_phy0; | ||
135 | static u32 length; | ||
136 | static u8 __iomem *chip_addr; | ||
137 | static u8 __iomem *iobase; | ||
138 | |||
139 | static int __devinit isp1761_pci_probe(struct pci_dev *dev, | 129 | static int __devinit isp1761_pci_probe(struct pci_dev *dev, |
140 | const struct pci_device_id *id) | 130 | const struct pci_device_id *id) |
141 | { | 131 | { |
142 | u8 latency, limit; | 132 | u8 latency, limit; |
143 | __u32 reg_data; | 133 | __u32 reg_data; |
144 | int retry_count; | 134 | int retry_count; |
145 | int length; | ||
146 | int status = 1; | ||
147 | struct usb_hcd *hcd; | 135 | struct usb_hcd *hcd; |
148 | unsigned int devflags = 0; | 136 | unsigned int devflags = 0; |
137 | int ret_status = 0; | ||
138 | |||
139 | resource_size_t pci_mem_phy0; | ||
140 | resource_size_t memlength; | ||
141 | |||
142 | u8 __iomem *chip_addr; | ||
143 | u8 __iomem *iobase; | ||
144 | resource_size_t nxp_pci_io_base; | ||
145 | resource_size_t iolength; | ||
149 | 146 | ||
150 | if (usb_disabled()) | 147 | if (usb_disabled()) |
151 | return -ENODEV; | 148 | return -ENODEV; |
@@ -168,26 +165,30 @@ static int __devinit isp1761_pci_probe(struct pci_dev *dev, | |||
168 | iobase = ioremap_nocache(nxp_pci_io_base, iolength); | 165 | iobase = ioremap_nocache(nxp_pci_io_base, iolength); |
169 | if (!iobase) { | 166 | if (!iobase) { |
170 | printk(KERN_ERR "ioremap #1\n"); | 167 | printk(KERN_ERR "ioremap #1\n"); |
171 | release_mem_region(nxp_pci_io_base, iolength); | 168 | ret_status = -ENOMEM; |
172 | return -ENOMEM; | 169 | goto cleanup1; |
173 | } | 170 | } |
174 | /* Grab the PLX PCI shared memory of the ISP 1761 we need */ | 171 | /* Grab the PLX PCI shared memory of the ISP 1761 we need */ |
175 | pci_mem_phy0 = pci_resource_start(dev, 3); | 172 | pci_mem_phy0 = pci_resource_start(dev, 3); |
176 | length = pci_resource_len(dev, 3); | 173 | memlength = pci_resource_len(dev, 3); |
177 | 174 | if (memlength < 0xffff) { | |
178 | if (length < 0xffff) { | 175 | printk(KERN_ERR "memory length for this resource is wrong\n"); |
179 | printk(KERN_ERR "memory length for this resource is less than " | 176 | ret_status = -ENOMEM; |
180 | "required\n"); | 177 | goto cleanup2; |
181 | release_mem_region(nxp_pci_io_base, iolength); | ||
182 | iounmap(iobase); | ||
183 | return -ENOMEM; | ||
184 | } | 178 | } |
185 | 179 | ||
186 | if (!request_mem_region(pci_mem_phy0, length, "ISP-PCI")) { | 180 | if (!request_mem_region(pci_mem_phy0, memlength, "ISP-PCI")) { |
187 | printk(KERN_ERR "host controller already in use\n"); | 181 | printk(KERN_ERR "host controller already in use\n"); |
188 | release_mem_region(nxp_pci_io_base, iolength); | 182 | ret_status = -EBUSY; |
189 | iounmap(iobase); | 183 | goto cleanup2; |
190 | return -EBUSY; | 184 | } |
185 | |||
186 | /* map available memory */ | ||
187 | chip_addr = ioremap_nocache(pci_mem_phy0,memlength); | ||
188 | if (!chip_addr) { | ||
189 | printk(KERN_ERR "Error ioremap failed\n"); | ||
190 | ret_status = -ENOMEM; | ||
191 | goto cleanup3; | ||
191 | } | 192 | } |
192 | 193 | ||
193 | /* bad pci latencies can contribute to overruns */ | 194 | /* bad pci latencies can contribute to overruns */ |
@@ -210,39 +211,54 @@ static int __devinit isp1761_pci_probe(struct pci_dev *dev, | |||
210 | * */ | 211 | * */ |
211 | writel(0xface, chip_addr + HC_SCRATCH_REG); | 212 | writel(0xface, chip_addr + HC_SCRATCH_REG); |
212 | udelay(100); | 213 | udelay(100); |
213 | reg_data = readl(chip_addr + HC_SCRATCH_REG); | 214 | reg_data = readl(chip_addr + HC_SCRATCH_REG) & 0x0000ffff; |
214 | retry_count--; | 215 | retry_count--; |
215 | } | 216 | } |
216 | 217 | ||
218 | iounmap(chip_addr); | ||
219 | |||
217 | /* Host Controller presence is detected by writing to scratch register | 220 | /* Host Controller presence is detected by writing to scratch register |
218 | * and reading back and checking the contents are same or not | 221 | * and reading back and checking the contents are same or not |
219 | */ | 222 | */ |
220 | if (reg_data != 0xFACE) { | 223 | if (reg_data != 0xFACE) { |
221 | dev_err(&dev->dev, "scratch register mismatch %x\n", reg_data); | 224 | dev_err(&dev->dev, "scratch register mismatch %x\n", reg_data); |
222 | goto clean; | 225 | ret_status = -ENOMEM; |
226 | goto cleanup3; | ||
223 | } | 227 | } |
224 | 228 | ||
225 | pci_set_master(dev); | 229 | pci_set_master(dev); |
226 | 230 | ||
227 | status = readl(iobase + 0x68); | 231 | /* configure PLX PCI chip to pass interrupts */ |
228 | status |= 0x900; | 232 | #define PLX_INT_CSR_REG 0x68 |
229 | writel(status, iobase + 0x68); | 233 | reg_data = readl(iobase + PLX_INT_CSR_REG); |
234 | reg_data |= 0x900; | ||
235 | writel(reg_data, iobase + PLX_INT_CSR_REG); | ||
230 | 236 | ||
231 | dev->dev.dma_mask = NULL; | 237 | dev->dev.dma_mask = NULL; |
232 | hcd = isp1760_register(pci_mem_phy0, length, dev->irq, | 238 | hcd = isp1760_register(pci_mem_phy0, memlength, dev->irq, |
233 | IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev), | 239 | IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev), |
234 | devflags); | 240 | devflags); |
235 | if (!IS_ERR(hcd)) { | 241 | if (IS_ERR(hcd)) { |
236 | pci_set_drvdata(dev, hcd); | 242 | ret_status = -ENODEV; |
237 | return 0; | 243 | goto cleanup3; |
238 | } | 244 | } |
239 | clean: | 245 | |
240 | status = -ENODEV; | 246 | /* done with PLX IO access */ |
247 | iounmap(iobase); | ||
248 | release_mem_region(nxp_pci_io_base, iolength); | ||
249 | |||
250 | pci_set_drvdata(dev, hcd); | ||
251 | return 0; | ||
252 | |||
253 | cleanup3: | ||
254 | release_mem_region(pci_mem_phy0, memlength); | ||
255 | cleanup2: | ||
241 | iounmap(iobase); | 256 | iounmap(iobase); |
242 | release_mem_region(pci_mem_phy0, length); | 257 | cleanup1: |
243 | release_mem_region(nxp_pci_io_base, iolength); | 258 | release_mem_region(nxp_pci_io_base, iolength); |
244 | return status; | 259 | return ret_status; |
245 | } | 260 | } |
261 | |||
246 | static void isp1761_pci_remove(struct pci_dev *dev) | 262 | static void isp1761_pci_remove(struct pci_dev *dev) |
247 | { | 263 | { |
248 | struct usb_hcd *hcd; | 264 | struct usb_hcd *hcd; |
@@ -255,12 +271,6 @@ static void isp1761_pci_remove(struct pci_dev *dev) | |||
255 | usb_put_hcd(hcd); | 271 | usb_put_hcd(hcd); |
256 | 272 | ||
257 | pci_disable_device(dev); | 273 | pci_disable_device(dev); |
258 | |||
259 | iounmap(iobase); | ||
260 | iounmap(chip_addr); | ||
261 | |||
262 | release_mem_region(nxp_pci_io_base, iolength); | ||
263 | release_mem_region(pci_mem_phy0, length); | ||
264 | } | 274 | } |
265 | 275 | ||
266 | static void isp1761_pci_shutdown(struct pci_dev *dev) | 276 | static void isp1761_pci_shutdown(struct pci_dev *dev) |
@@ -268,12 +278,16 @@ static void isp1761_pci_shutdown(struct pci_dev *dev) | |||
268 | printk(KERN_ERR "ips1761_pci_shutdown\n"); | 278 | printk(KERN_ERR "ips1761_pci_shutdown\n"); |
269 | } | 279 | } |
270 | 280 | ||
271 | static const struct pci_device_id isp1760_plx [] = { { | 281 | static const struct pci_device_id isp1760_plx [] = { |
272 | /* handle any USB 2.0 EHCI controller */ | 282 | { |
273 | PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_OTHER << 8) | (0x06 << 16)), ~0), | 283 | .class = PCI_CLASS_BRIDGE_OTHER << 8, |
274 | .driver_data = 0, | 284 | .class_mask = ~0, |
275 | }, | 285 | .vendor = PCI_VENDOR_ID_PLX, |
276 | { /* end: all zeroes */ } | 286 | .device = 0x5406, |
287 | .subvendor = PCI_VENDOR_ID_PLX, | ||
288 | .subdevice = 0x9054, | ||
289 | }, | ||
290 | { } | ||
277 | }; | 291 | }; |
278 | MODULE_DEVICE_TABLE(pci, isp1760_plx); | 292 | MODULE_DEVICE_TABLE(pci, isp1760_plx); |
279 | 293 | ||
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index 8aa3f4556a32..65a9609f4ad6 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c | |||
@@ -589,13 +589,15 @@ static int ohci_run (struct ohci_hcd *ohci) | |||
589 | /* also: power/overcurrent flags in roothub.a */ | 589 | /* also: power/overcurrent flags in roothub.a */ |
590 | } | 590 | } |
591 | 591 | ||
592 | /* Reset USB nearly "by the book". RemoteWakeupConnected was | 592 | /* Reset USB nearly "by the book". RemoteWakeupConnected has |
593 | * saved if boot firmware (BIOS/SMM/...) told us it's connected, | 593 | * to be checked in case boot firmware (BIOS/SMM/...) has set up |
594 | * or if bus glue did the same (e.g. for PCI add-in cards with | 594 | * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM). |
595 | * PCI PM support). | 595 | * If the bus glue detected wakeup capability then it should |
596 | * already be enabled. Either way, if wakeup should be enabled | ||
597 | * but isn't, we'll enable it now. | ||
596 | */ | 598 | */ |
597 | if ((ohci->hc_control & OHCI_CTRL_RWC) != 0 | 599 | if ((ohci->hc_control & OHCI_CTRL_RWC) != 0 |
598 | && !device_may_wakeup(hcd->self.controller)) | 600 | && !device_can_wakeup(hcd->self.controller)) |
599 | device_init_wakeup(hcd->self.controller, 1); | 601 | device_init_wakeup(hcd->self.controller, 1); |
600 | 602 | ||
601 | switch (ohci->hc_control & OHCI_CTRL_HCFS) { | 603 | switch (ohci->hc_control & OHCI_CTRL_HCFS) { |
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c index a9c2ae36c7ad..8b28ae7865ba 100644 --- a/drivers/usb/host/ohci-pci.c +++ b/drivers/usb/host/ohci-pci.c | |||
@@ -355,9 +355,9 @@ static int __devinit ohci_pci_start (struct usb_hcd *hcd) | |||
355 | 355 | ||
356 | /* RWC may not be set for add-in PCI cards, since boot | 356 | /* RWC may not be set for add-in PCI cards, since boot |
357 | * firmware probably ignored them. This transfers PCI | 357 | * firmware probably ignored them. This transfers PCI |
358 | * PM wakeup capabilities (once the PCI layer is fixed). | 358 | * PM wakeup capabilities. |
359 | */ | 359 | */ |
360 | if (device_may_wakeup(&pdev->dev)) | 360 | if (device_can_wakeup(&pdev->dev)) |
361 | ohci->hc_control |= OHCI_CTRL_RWC; | 361 | ohci->hc_control |= OHCI_CTRL_RWC; |
362 | } | 362 | } |
363 | #endif /* CONFIG_PM */ | 363 | #endif /* CONFIG_PM */ |
@@ -487,6 +487,8 @@ static struct pci_driver ohci_pci_driver = { | |||
487 | 487 | ||
488 | #ifdef CONFIG_PM | 488 | #ifdef CONFIG_PM |
489 | .suspend = usb_hcd_pci_suspend, | 489 | .suspend = usb_hcd_pci_suspend, |
490 | .suspend_late = usb_hcd_pci_suspend_late, | ||
491 | .resume_early = usb_hcd_pci_resume_early, | ||
490 | .resume = usb_hcd_pci_resume, | 492 | .resume = usb_hcd_pci_resume, |
491 | #endif | 493 | #endif |
492 | 494 | ||
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c index e306ca6aef3d..100bf3d8437c 100644 --- a/drivers/usb/host/ohci-pnx4008.c +++ b/drivers/usb/host/ohci-pnx4008.c | |||
@@ -106,65 +106,34 @@ extern int ocpi_enable(void); | |||
106 | 106 | ||
107 | static struct clk *usb_clk; | 107 | static struct clk *usb_clk; |
108 | 108 | ||
109 | static int isp1301_probe(struct i2c_adapter *adap); | ||
110 | static int isp1301_detach(struct i2c_client *client); | ||
111 | |||
112 | static const unsigned short normal_i2c[] = | 109 | static const unsigned short normal_i2c[] = |
113 | { ISP1301_I2C_ADDR, ISP1301_I2C_ADDR + 1, I2C_CLIENT_END }; | 110 | { ISP1301_I2C_ADDR, ISP1301_I2C_ADDR + 1, I2C_CLIENT_END }; |
114 | static const unsigned short dummy_i2c_addrlist[] = { I2C_CLIENT_END }; | ||
115 | |||
116 | static struct i2c_client_address_data addr_data = { | ||
117 | .normal_i2c = normal_i2c, | ||
118 | .probe = dummy_i2c_addrlist, | ||
119 | .ignore = dummy_i2c_addrlist, | ||
120 | }; | ||
121 | |||
122 | struct i2c_driver isp1301_driver = { | ||
123 | .driver = { | ||
124 | .name = "isp1301_pnx", | ||
125 | }, | ||
126 | .attach_adapter = isp1301_probe, | ||
127 | .detach_client = isp1301_detach, | ||
128 | }; | ||
129 | 111 | ||
130 | static int isp1301_attach(struct i2c_adapter *adap, int addr, int kind) | 112 | static int isp1301_probe(struct i2c_client *client, |
113 | const struct i2c_device_id *id) | ||
131 | { | 114 | { |
132 | struct i2c_client *c; | ||
133 | int err; | ||
134 | |||
135 | c = kzalloc(sizeof(*c), GFP_KERNEL); | ||
136 | if (!c) | ||
137 | return -ENOMEM; | ||
138 | |||
139 | strlcpy(c->name, "isp1301_pnx", I2C_NAME_SIZE); | ||
140 | c->flags = 0; | ||
141 | c->addr = addr; | ||
142 | c->adapter = adap; | ||
143 | c->driver = &isp1301_driver; | ||
144 | |||
145 | err = i2c_attach_client(c); | ||
146 | if (err) { | ||
147 | kfree(c); | ||
148 | return err; | ||
149 | } | ||
150 | |||
151 | isp1301_i2c_client = c; | ||
152 | |||
153 | return 0; | 115 | return 0; |
154 | } | 116 | } |
155 | 117 | ||
156 | static int isp1301_probe(struct i2c_adapter *adap) | 118 | static int isp1301_remove(struct i2c_client *client) |
157 | { | 119 | { |
158 | return i2c_probe(adap, &addr_data, isp1301_attach); | ||
159 | } | ||
160 | |||
161 | static int isp1301_detach(struct i2c_client *client) | ||
162 | { | ||
163 | i2c_detach_client(client); | ||
164 | kfree(isp1301_i2c_client); | ||
165 | return 0; | 120 | return 0; |
166 | } | 121 | } |
167 | 122 | ||
123 | const struct i2c_device_id isp1301_id[] = { | ||
124 | { "isp1301_pnx", 0 }, | ||
125 | { } | ||
126 | }; | ||
127 | |||
128 | struct i2c_driver isp1301_driver = { | ||
129 | .driver = { | ||
130 | .name = "isp1301_pnx", | ||
131 | }, | ||
132 | .probe = isp1301_probe, | ||
133 | .remove = isp1301_remove, | ||
134 | .id_table = isp1301_id, | ||
135 | }; | ||
136 | |||
168 | static void i2c_write(u8 buf, u8 subaddr) | 137 | static void i2c_write(u8 buf, u8 subaddr) |
169 | { | 138 | { |
170 | char tmpbuf[2]; | 139 | char tmpbuf[2]; |
@@ -328,6 +297,8 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev) | |||
328 | struct usb_hcd *hcd = 0; | 297 | struct usb_hcd *hcd = 0; |
329 | struct ohci_hcd *ohci; | 298 | struct ohci_hcd *ohci; |
330 | const struct hc_driver *driver = &ohci_pnx4008_hc_driver; | 299 | const struct hc_driver *driver = &ohci_pnx4008_hc_driver; |
300 | struct i2c_adapter *i2c_adap; | ||
301 | struct i2c_board_info i2c_info; | ||
331 | 302 | ||
332 | int ret = 0, irq; | 303 | int ret = 0, irq; |
333 | 304 | ||
@@ -351,9 +322,20 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev) | |||
351 | 322 | ||
352 | ret = i2c_add_driver(&isp1301_driver); | 323 | ret = i2c_add_driver(&isp1301_driver); |
353 | if (ret < 0) { | 324 | if (ret < 0) { |
354 | err("failed to connect I2C to ISP1301 USB Transceiver"); | 325 | err("failed to add ISP1301 driver"); |
355 | goto out; | 326 | goto out; |
356 | } | 327 | } |
328 | i2c_adap = i2c_get_adapter(2); | ||
329 | memset(&i2c_info, 0, sizeof(struct i2c_board_info)); | ||
330 | strlcpy(i2c_info.name, "isp1301_pnx", I2C_NAME_SIZE); | ||
331 | isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, | ||
332 | normal_i2c); | ||
333 | i2c_put_adapter(i2c_adap); | ||
334 | if (!isp1301_i2c_client) { | ||
335 | err("failed to connect I2C to ISP1301 USB Transceiver"); | ||
336 | ret = -ENODEV; | ||
337 | goto out_i2c_driver; | ||
338 | } | ||
357 | 339 | ||
358 | isp1301_configure(); | 340 | isp1301_configure(); |
359 | 341 | ||
@@ -429,6 +411,9 @@ out3: | |||
429 | out2: | 411 | out2: |
430 | clk_put(usb_clk); | 412 | clk_put(usb_clk); |
431 | out1: | 413 | out1: |
414 | i2c_unregister_client(isp1301_i2c_client); | ||
415 | isp1301_i2c_client = NULL; | ||
416 | out_i2c_driver: | ||
432 | i2c_del_driver(&isp1301_driver); | 417 | i2c_del_driver(&isp1301_driver); |
433 | out: | 418 | out: |
434 | return ret; | 419 | return ret; |
@@ -445,6 +430,8 @@ static int usb_hcd_pnx4008_remove(struct platform_device *pdev) | |||
445 | pnx4008_unset_usb_bits(); | 430 | pnx4008_unset_usb_bits(); |
446 | clk_disable(usb_clk); | 431 | clk_disable(usb_clk); |
447 | clk_put(usb_clk); | 432 | clk_put(usb_clk); |
433 | i2c_unregister_client(isp1301_i2c_client); | ||
434 | isp1301_i2c_client = NULL; | ||
448 | i2c_del_driver(&isp1301_driver); | 435 | i2c_del_driver(&isp1301_driver); |
449 | 436 | ||
450 | platform_set_drvdata(pdev, NULL); | 437 | platform_set_drvdata(pdev, NULL); |
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c index 7ac53264ead3..68a301710297 100644 --- a/drivers/usb/host/ohci-ppc-of.c +++ b/drivers/usb/host/ohci-ppc-of.c | |||
@@ -91,6 +91,7 @@ ohci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match) | |||
91 | 91 | ||
92 | int rv; | 92 | int rv; |
93 | int is_bigendian; | 93 | int is_bigendian; |
94 | struct device_node *np; | ||
94 | 95 | ||
95 | if (usb_disabled()) | 96 | if (usb_disabled()) |
96 | return -ENODEV; | 97 | return -ENODEV; |
@@ -147,6 +148,30 @@ ohci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match) | |||
147 | if (rv == 0) | 148 | if (rv == 0) |
148 | return 0; | 149 | return 0; |
149 | 150 | ||
151 | /* by now, 440epx is known to show usb_23 erratum */ | ||
152 | np = of_find_compatible_node(NULL, NULL, "ibm,usb-ehci-440epx"); | ||
153 | |||
154 | /* Work around - At this point ohci_run has executed, the | ||
155 | * controller is running, everything, the root ports, etc., is | ||
156 | * set up. If the ehci driver is loaded, put the ohci core in | ||
157 | * the suspended state. The ehci driver will bring it out of | ||
158 | * suspended state when / if a non-high speed USB device is | ||
159 | * attached to the USB Host port. If the ehci driver is not | ||
160 | * loaded, do nothing. request_mem_region is used to test if | ||
161 | * the ehci driver is loaded. | ||
162 | */ | ||
163 | if (np != NULL) { | ||
164 | if (!of_address_to_resource(np, 0, &res)) { | ||
165 | if (!request_mem_region(res.start, 0x4, hcd_name)) { | ||
166 | writel_be((readl_be(&ohci->regs->control) | | ||
167 | OHCI_USB_SUSPEND), &ohci->regs->control); | ||
168 | (void) readl_be(&ohci->regs->control); | ||
169 | } else | ||
170 | release_mem_region(res.start, 0x4); | ||
171 | } else | ||
172 | pr_debug(__FILE__ ": cannot get ehci offset from fdt\n"); | ||
173 | } | ||
174 | |||
150 | iounmap(hcd->regs); | 175 | iounmap(hcd->regs); |
151 | err_ioremap: | 176 | err_ioremap: |
152 | irq_dispose_mapping(irq); | 177 | irq_dispose_mapping(irq); |
diff --git a/drivers/usb/host/ohci-tmio.c b/drivers/usb/host/ohci-tmio.c index f9f134af0bd1..8dabe8e31d8c 100644 --- a/drivers/usb/host/ohci-tmio.c +++ b/drivers/usb/host/ohci-tmio.c | |||
@@ -201,7 +201,7 @@ static int __devinit ohci_hcd_tmio_drv_probe(struct platform_device *dev) | |||
201 | if (!cell) | 201 | if (!cell) |
202 | return -EINVAL; | 202 | return -EINVAL; |
203 | 203 | ||
204 | hcd = usb_create_hcd(&ohci_tmio_hc_driver, &dev->dev, dev->dev.bus_id); | 204 | hcd = usb_create_hcd(&ohci_tmio_hc_driver, &dev->dev, dev_name(&dev->dev)); |
205 | if (!hcd) { | 205 | if (!hcd) { |
206 | ret = -ENOMEM; | 206 | ret = -ENOMEM; |
207 | goto err_usb_create_hcd; | 207 | goto err_usb_create_hcd; |
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c new file mode 100644 index 000000000000..75548f7c716b --- /dev/null +++ b/drivers/usb/host/oxu210hp-hcd.c | |||
@@ -0,0 +1,3985 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Rodolfo Giometti <giometti@linux.it> | ||
3 | * Copyright (c) 2008 Eurotech S.p.A. <info@eurtech.it> | ||
4 | * | ||
5 | * This code is *strongly* based on EHCI-HCD code by David Brownell since | ||
6 | * the chip is a quasi-EHCI compatible. | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, but | ||
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
16 | * for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software Foundation, | ||
20 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | */ | ||
22 | |||
23 | #include <linux/module.h> | ||
24 | #include <linux/pci.h> | ||
25 | #include <linux/dmapool.h> | ||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/ioport.h> | ||
29 | #include <linux/sched.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <linux/errno.h> | ||
32 | #include <linux/init.h> | ||
33 | #include <linux/timer.h> | ||
34 | #include <linux/list.h> | ||
35 | #include <linux/interrupt.h> | ||
36 | #include <linux/reboot.h> | ||
37 | #include <linux/usb.h> | ||
38 | #include <linux/moduleparam.h> | ||
39 | #include <linux/dma-mapping.h> | ||
40 | #include <linux/io.h> | ||
41 | |||
42 | #include "../core/hcd.h" | ||
43 | |||
44 | #include <asm/irq.h> | ||
45 | #include <asm/system.h> | ||
46 | #include <asm/unaligned.h> | ||
47 | |||
48 | #include <linux/irq.h> | ||
49 | #include <linux/platform_device.h> | ||
50 | |||
51 | #include "oxu210hp.h" | ||
52 | |||
53 | #define DRIVER_VERSION "0.0.50" | ||
54 | |||
55 | /* | ||
56 | * Main defines | ||
57 | */ | ||
58 | |||
59 | #define oxu_dbg(oxu, fmt, args...) \ | ||
60 | dev_dbg(oxu_to_hcd(oxu)->self.controller , fmt , ## args) | ||
61 | #define oxu_err(oxu, fmt, args...) \ | ||
62 | dev_err(oxu_to_hcd(oxu)->self.controller , fmt , ## args) | ||
63 | #define oxu_info(oxu, fmt, args...) \ | ||
64 | dev_info(oxu_to_hcd(oxu)->self.controller , fmt , ## args) | ||
65 | |||
66 | static inline struct usb_hcd *oxu_to_hcd(struct oxu_hcd *oxu) | ||
67 | { | ||
68 | return container_of((void *) oxu, struct usb_hcd, hcd_priv); | ||
69 | } | ||
70 | |||
71 | static inline struct oxu_hcd *hcd_to_oxu(struct usb_hcd *hcd) | ||
72 | { | ||
73 | return (struct oxu_hcd *) (hcd->hcd_priv); | ||
74 | } | ||
75 | |||
76 | /* | ||
77 | * Debug stuff | ||
78 | */ | ||
79 | |||
80 | #undef OXU_URB_TRACE | ||
81 | #undef OXU_VERBOSE_DEBUG | ||
82 | |||
83 | #ifdef OXU_VERBOSE_DEBUG | ||
84 | #define oxu_vdbg oxu_dbg | ||
85 | #else | ||
86 | #define oxu_vdbg(oxu, fmt, args...) /* Nop */ | ||
87 | #endif | ||
88 | |||
89 | #ifdef DEBUG | ||
90 | |||
91 | static int __attribute__((__unused__)) | ||
92 | dbg_status_buf(char *buf, unsigned len, const char *label, u32 status) | ||
93 | { | ||
94 | return scnprintf(buf, len, "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s", | ||
95 | label, label[0] ? " " : "", status, | ||
96 | (status & STS_ASS) ? " Async" : "", | ||
97 | (status & STS_PSS) ? " Periodic" : "", | ||
98 | (status & STS_RECL) ? " Recl" : "", | ||
99 | (status & STS_HALT) ? " Halt" : "", | ||
100 | (status & STS_IAA) ? " IAA" : "", | ||
101 | (status & STS_FATAL) ? " FATAL" : "", | ||
102 | (status & STS_FLR) ? " FLR" : "", | ||
103 | (status & STS_PCD) ? " PCD" : "", | ||
104 | (status & STS_ERR) ? " ERR" : "", | ||
105 | (status & STS_INT) ? " INT" : "" | ||
106 | ); | ||
107 | } | ||
108 | |||
109 | static int __attribute__((__unused__)) | ||
110 | dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable) | ||
111 | { | ||
112 | return scnprintf(buf, len, "%s%sintrenable %02x%s%s%s%s%s%s", | ||
113 | label, label[0] ? " " : "", enable, | ||
114 | (enable & STS_IAA) ? " IAA" : "", | ||
115 | (enable & STS_FATAL) ? " FATAL" : "", | ||
116 | (enable & STS_FLR) ? " FLR" : "", | ||
117 | (enable & STS_PCD) ? " PCD" : "", | ||
118 | (enable & STS_ERR) ? " ERR" : "", | ||
119 | (enable & STS_INT) ? " INT" : "" | ||
120 | ); | ||
121 | } | ||
122 | |||
123 | static const char *const fls_strings[] = | ||
124 | { "1024", "512", "256", "??" }; | ||
125 | |||
126 | static int dbg_command_buf(char *buf, unsigned len, | ||
127 | const char *label, u32 command) | ||
128 | { | ||
129 | return scnprintf(buf, len, | ||
130 | "%s%scommand %06x %s=%d ithresh=%d%s%s%s%s period=%s%s %s", | ||
131 | label, label[0] ? " " : "", command, | ||
132 | (command & CMD_PARK) ? "park" : "(park)", | ||
133 | CMD_PARK_CNT(command), | ||
134 | (command >> 16) & 0x3f, | ||
135 | (command & CMD_LRESET) ? " LReset" : "", | ||
136 | (command & CMD_IAAD) ? " IAAD" : "", | ||
137 | (command & CMD_ASE) ? " Async" : "", | ||
138 | (command & CMD_PSE) ? " Periodic" : "", | ||
139 | fls_strings[(command >> 2) & 0x3], | ||
140 | (command & CMD_RESET) ? " Reset" : "", | ||
141 | (command & CMD_RUN) ? "RUN" : "HALT" | ||
142 | ); | ||
143 | } | ||
144 | |||
145 | static int dbg_port_buf(char *buf, unsigned len, const char *label, | ||
146 | int port, u32 status) | ||
147 | { | ||
148 | char *sig; | ||
149 | |||
150 | /* signaling state */ | ||
151 | switch (status & (3 << 10)) { | ||
152 | case 0 << 10: | ||
153 | sig = "se0"; | ||
154 | break; | ||
155 | case 1 << 10: | ||
156 | sig = "k"; /* low speed */ | ||
157 | break; | ||
158 | case 2 << 10: | ||
159 | sig = "j"; | ||
160 | break; | ||
161 | default: | ||
162 | sig = "?"; | ||
163 | break; | ||
164 | } | ||
165 | |||
166 | return scnprintf(buf, len, | ||
167 | "%s%sport %d status %06x%s%s sig=%s%s%s%s%s%s%s%s%s%s", | ||
168 | label, label[0] ? " " : "", port, status, | ||
169 | (status & PORT_POWER) ? " POWER" : "", | ||
170 | (status & PORT_OWNER) ? " OWNER" : "", | ||
171 | sig, | ||
172 | (status & PORT_RESET) ? " RESET" : "", | ||
173 | (status & PORT_SUSPEND) ? " SUSPEND" : "", | ||
174 | (status & PORT_RESUME) ? " RESUME" : "", | ||
175 | (status & PORT_OCC) ? " OCC" : "", | ||
176 | (status & PORT_OC) ? " OC" : "", | ||
177 | (status & PORT_PEC) ? " PEC" : "", | ||
178 | (status & PORT_PE) ? " PE" : "", | ||
179 | (status & PORT_CSC) ? " CSC" : "", | ||
180 | (status & PORT_CONNECT) ? " CONNECT" : "" | ||
181 | ); | ||
182 | } | ||
183 | |||
184 | #else | ||
185 | |||
186 | static inline int __attribute__((__unused__)) | ||
187 | dbg_status_buf(char *buf, unsigned len, const char *label, u32 status) | ||
188 | { return 0; } | ||
189 | |||
190 | static inline int __attribute__((__unused__)) | ||
191 | dbg_command_buf(char *buf, unsigned len, const char *label, u32 command) | ||
192 | { return 0; } | ||
193 | |||
194 | static inline int __attribute__((__unused__)) | ||
195 | dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable) | ||
196 | { return 0; } | ||
197 | |||
198 | static inline int __attribute__((__unused__)) | ||
199 | dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status) | ||
200 | { return 0; } | ||
201 | |||
202 | #endif /* DEBUG */ | ||
203 | |||
204 | /* functions have the "wrong" filename when they're output... */ | ||
205 | #define dbg_status(oxu, label, status) { \ | ||
206 | char _buf[80]; \ | ||
207 | dbg_status_buf(_buf, sizeof _buf, label, status); \ | ||
208 | oxu_dbg(oxu, "%s\n", _buf); \ | ||
209 | } | ||
210 | |||
211 | #define dbg_cmd(oxu, label, command) { \ | ||
212 | char _buf[80]; \ | ||
213 | dbg_command_buf(_buf, sizeof _buf, label, command); \ | ||
214 | oxu_dbg(oxu, "%s\n", _buf); \ | ||
215 | } | ||
216 | |||
217 | #define dbg_port(oxu, label, port, status) { \ | ||
218 | char _buf[80]; \ | ||
219 | dbg_port_buf(_buf, sizeof _buf, label, port, status); \ | ||
220 | oxu_dbg(oxu, "%s\n", _buf); \ | ||
221 | } | ||
222 | |||
223 | /* | ||
224 | * Module parameters | ||
225 | */ | ||
226 | |||
227 | /* Initial IRQ latency: faster than hw default */ | ||
228 | static int log2_irq_thresh; /* 0 to 6 */ | ||
229 | module_param(log2_irq_thresh, int, S_IRUGO); | ||
230 | MODULE_PARM_DESC(log2_irq_thresh, "log2 IRQ latency, 1-64 microframes"); | ||
231 | |||
232 | /* Initial park setting: slower than hw default */ | ||
233 | static unsigned park; | ||
234 | module_param(park, uint, S_IRUGO); | ||
235 | MODULE_PARM_DESC(park, "park setting; 1-3 back-to-back async packets"); | ||
236 | |||
237 | /* For flakey hardware, ignore overcurrent indicators */ | ||
238 | static int ignore_oc; | ||
239 | module_param(ignore_oc, bool, S_IRUGO); | ||
240 | MODULE_PARM_DESC(ignore_oc, "ignore bogus hardware overcurrent indications"); | ||
241 | |||
242 | |||
243 | static void ehci_work(struct oxu_hcd *oxu); | ||
244 | static int oxu_hub_control(struct usb_hcd *hcd, | ||
245 | u16 typeReq, u16 wValue, u16 wIndex, | ||
246 | char *buf, u16 wLength); | ||
247 | |||
248 | /* | ||
249 | * Local functions | ||
250 | */ | ||
251 | |||
252 | /* Low level read/write registers functions */ | ||
253 | static inline u32 oxu_readl(void *base, u32 reg) | ||
254 | { | ||
255 | return readl(base + reg); | ||
256 | } | ||
257 | |||
258 | static inline void oxu_writel(void *base, u32 reg, u32 val) | ||
259 | { | ||
260 | writel(val, base + reg); | ||
261 | } | ||
262 | |||
263 | static inline void timer_action_done(struct oxu_hcd *oxu, | ||
264 | enum ehci_timer_action action) | ||
265 | { | ||
266 | clear_bit(action, &oxu->actions); | ||
267 | } | ||
268 | |||
269 | static inline void timer_action(struct oxu_hcd *oxu, | ||
270 | enum ehci_timer_action action) | ||
271 | { | ||
272 | if (!test_and_set_bit(action, &oxu->actions)) { | ||
273 | unsigned long t; | ||
274 | |||
275 | switch (action) { | ||
276 | case TIMER_IAA_WATCHDOG: | ||
277 | t = EHCI_IAA_JIFFIES; | ||
278 | break; | ||
279 | case TIMER_IO_WATCHDOG: | ||
280 | t = EHCI_IO_JIFFIES; | ||
281 | break; | ||
282 | case TIMER_ASYNC_OFF: | ||
283 | t = EHCI_ASYNC_JIFFIES; | ||
284 | break; | ||
285 | case TIMER_ASYNC_SHRINK: | ||
286 | default: | ||
287 | t = EHCI_SHRINK_JIFFIES; | ||
288 | break; | ||
289 | } | ||
290 | t += jiffies; | ||
291 | /* all timings except IAA watchdog can be overridden. | ||
292 | * async queue SHRINK often precedes IAA. while it's ready | ||
293 | * to go OFF neither can matter, and afterwards the IO | ||
294 | * watchdog stops unless there's still periodic traffic. | ||
295 | */ | ||
296 | if (action != TIMER_IAA_WATCHDOG | ||
297 | && t > oxu->watchdog.expires | ||
298 | && timer_pending(&oxu->watchdog)) | ||
299 | return; | ||
300 | mod_timer(&oxu->watchdog, t); | ||
301 | } | ||
302 | } | ||
303 | |||
304 | /* | ||
305 | * handshake - spin reading hc until handshake completes or fails | ||
306 | * @ptr: address of hc register to be read | ||
307 | * @mask: bits to look at in result of read | ||
308 | * @done: value of those bits when handshake succeeds | ||
309 | * @usec: timeout in microseconds | ||
310 | * | ||
311 | * Returns negative errno, or zero on success | ||
312 | * | ||
313 | * Success happens when the "mask" bits have the specified value (hardware | ||
314 | * handshake done). There are two failure modes: "usec" have passed (major | ||
315 | * hardware flakeout), or the register reads as all-ones (hardware removed). | ||
316 | * | ||
317 | * That last failure should_only happen in cases like physical cardbus eject | ||
318 | * before driver shutdown. But it also seems to be caused by bugs in cardbus | ||
319 | * bridge shutdown: shutting down the bridge before the devices using it. | ||
320 | */ | ||
321 | static int handshake(struct oxu_hcd *oxu, void __iomem *ptr, | ||
322 | u32 mask, u32 done, int usec) | ||
323 | { | ||
324 | u32 result; | ||
325 | |||
326 | do { | ||
327 | result = readl(ptr); | ||
328 | if (result == ~(u32)0) /* card removed */ | ||
329 | return -ENODEV; | ||
330 | result &= mask; | ||
331 | if (result == done) | ||
332 | return 0; | ||
333 | udelay(1); | ||
334 | usec--; | ||
335 | } while (usec > 0); | ||
336 | return -ETIMEDOUT; | ||
337 | } | ||
338 | |||
339 | /* Force HC to halt state from unknown (EHCI spec section 2.3) */ | ||
340 | static int ehci_halt(struct oxu_hcd *oxu) | ||
341 | { | ||
342 | u32 temp = readl(&oxu->regs->status); | ||
343 | |||
344 | /* disable any irqs left enabled by previous code */ | ||
345 | writel(0, &oxu->regs->intr_enable); | ||
346 | |||
347 | if ((temp & STS_HALT) != 0) | ||
348 | return 0; | ||
349 | |||
350 | temp = readl(&oxu->regs->command); | ||
351 | temp &= ~CMD_RUN; | ||
352 | writel(temp, &oxu->regs->command); | ||
353 | return handshake(oxu, &oxu->regs->status, | ||
354 | STS_HALT, STS_HALT, 16 * 125); | ||
355 | } | ||
356 | |||
357 | /* Put TDI/ARC silicon into EHCI mode */ | ||
358 | static void tdi_reset(struct oxu_hcd *oxu) | ||
359 | { | ||
360 | u32 __iomem *reg_ptr; | ||
361 | u32 tmp; | ||
362 | |||
363 | reg_ptr = (u32 __iomem *)(((u8 __iomem *)oxu->regs) + 0x68); | ||
364 | tmp = readl(reg_ptr); | ||
365 | tmp |= 0x3; | ||
366 | writel(tmp, reg_ptr); | ||
367 | } | ||
368 | |||
369 | /* Reset a non-running (STS_HALT == 1) controller */ | ||
370 | static int ehci_reset(struct oxu_hcd *oxu) | ||
371 | { | ||
372 | int retval; | ||
373 | u32 command = readl(&oxu->regs->command); | ||
374 | |||
375 | command |= CMD_RESET; | ||
376 | dbg_cmd(oxu, "reset", command); | ||
377 | writel(command, &oxu->regs->command); | ||
378 | oxu_to_hcd(oxu)->state = HC_STATE_HALT; | ||
379 | oxu->next_statechange = jiffies; | ||
380 | retval = handshake(oxu, &oxu->regs->command, | ||
381 | CMD_RESET, 0, 250 * 1000); | ||
382 | |||
383 | if (retval) | ||
384 | return retval; | ||
385 | |||
386 | tdi_reset(oxu); | ||
387 | |||
388 | return retval; | ||
389 | } | ||
390 | |||
391 | /* Idle the controller (from running) */ | ||
392 | static void ehci_quiesce(struct oxu_hcd *oxu) | ||
393 | { | ||
394 | u32 temp; | ||
395 | |||
396 | #ifdef DEBUG | ||
397 | if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) | ||
398 | BUG(); | ||
399 | #endif | ||
400 | |||
401 | /* wait for any schedule enables/disables to take effect */ | ||
402 | temp = readl(&oxu->regs->command) << 10; | ||
403 | temp &= STS_ASS | STS_PSS; | ||
404 | if (handshake(oxu, &oxu->regs->status, STS_ASS | STS_PSS, | ||
405 | temp, 16 * 125) != 0) { | ||
406 | oxu_to_hcd(oxu)->state = HC_STATE_HALT; | ||
407 | return; | ||
408 | } | ||
409 | |||
410 | /* then disable anything that's still active */ | ||
411 | temp = readl(&oxu->regs->command); | ||
412 | temp &= ~(CMD_ASE | CMD_IAAD | CMD_PSE); | ||
413 | writel(temp, &oxu->regs->command); | ||
414 | |||
415 | /* hardware can take 16 microframes to turn off ... */ | ||
416 | if (handshake(oxu, &oxu->regs->status, STS_ASS | STS_PSS, | ||
417 | 0, 16 * 125) != 0) { | ||
418 | oxu_to_hcd(oxu)->state = HC_STATE_HALT; | ||
419 | return; | ||
420 | } | ||
421 | } | ||
422 | |||
423 | static int check_reset_complete(struct oxu_hcd *oxu, int index, | ||
424 | u32 __iomem *status_reg, int port_status) | ||
425 | { | ||
426 | if (!(port_status & PORT_CONNECT)) { | ||
427 | oxu->reset_done[index] = 0; | ||
428 | return port_status; | ||
429 | } | ||
430 | |||
431 | /* if reset finished and it's still not enabled -- handoff */ | ||
432 | if (!(port_status & PORT_PE)) { | ||
433 | oxu_dbg(oxu, "Failed to enable port %d on root hub TT\n", | ||
434 | index+1); | ||
435 | return port_status; | ||
436 | } else | ||
437 | oxu_dbg(oxu, "port %d high speed\n", index + 1); | ||
438 | |||
439 | return port_status; | ||
440 | } | ||
441 | |||
442 | static void ehci_hub_descriptor(struct oxu_hcd *oxu, | ||
443 | struct usb_hub_descriptor *desc) | ||
444 | { | ||
445 | int ports = HCS_N_PORTS(oxu->hcs_params); | ||
446 | u16 temp; | ||
447 | |||
448 | desc->bDescriptorType = 0x29; | ||
449 | desc->bPwrOn2PwrGood = 10; /* oxu 1.0, 2.3.9 says 20ms max */ | ||
450 | desc->bHubContrCurrent = 0; | ||
451 | |||
452 | desc->bNbrPorts = ports; | ||
453 | temp = 1 + (ports / 8); | ||
454 | desc->bDescLength = 7 + 2 * temp; | ||
455 | |||
456 | /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ | ||
457 | memset(&desc->bitmap[0], 0, temp); | ||
458 | memset(&desc->bitmap[temp], 0xff, temp); | ||
459 | |||
460 | temp = 0x0008; /* per-port overcurrent reporting */ | ||
461 | if (HCS_PPC(oxu->hcs_params)) | ||
462 | temp |= 0x0001; /* per-port power control */ | ||
463 | else | ||
464 | temp |= 0x0002; /* no power switching */ | ||
465 | desc->wHubCharacteristics = (__force __u16)cpu_to_le16(temp); | ||
466 | } | ||
467 | |||
468 | |||
469 | /* Allocate an OXU210HP on-chip memory data buffer | ||
470 | * | ||
471 | * An on-chip memory data buffer is required for each OXU210HP USB transfer. | ||
472 | * Each transfer descriptor has one or more on-chip memory data buffers. | ||
473 | * | ||
474 | * Data buffers are allocated from a fix sized pool of data blocks. | ||
475 | * To minimise fragmentation and give reasonable memory utlisation, | ||
476 | * data buffers are allocated with sizes the power of 2 multiples of | ||
477 | * the block size, starting on an address a multiple of the allocated size. | ||
478 | * | ||
479 | * FIXME: callers of this function require a buffer to be allocated for | ||
480 | * len=0. This is a waste of on-chip memory and should be fix. Then this | ||
481 | * function should be changed to not allocate a buffer for len=0. | ||
482 | */ | ||
483 | static int oxu_buf_alloc(struct oxu_hcd *oxu, struct ehci_qtd *qtd, int len) | ||
484 | { | ||
485 | int n_blocks; /* minium blocks needed to hold len */ | ||
486 | int a_blocks; /* blocks allocated */ | ||
487 | int i, j; | ||
488 | |||
489 | /* Don't allocte bigger than supported */ | ||
490 | if (len > BUFFER_SIZE * BUFFER_NUM) { | ||
491 | oxu_err(oxu, "buffer too big (%d)\n", len); | ||
492 | return -ENOMEM; | ||
493 | } | ||
494 | |||
495 | spin_lock(&oxu->mem_lock); | ||
496 | |||
497 | /* Number of blocks needed to hold len */ | ||
498 | n_blocks = (len + BUFFER_SIZE - 1) / BUFFER_SIZE; | ||
499 | |||
500 | /* Round the number of blocks up to the power of 2 */ | ||
501 | for (a_blocks = 1; a_blocks < n_blocks; a_blocks <<= 1) | ||
502 | ; | ||
503 | |||
504 | /* Find a suitable available data buffer */ | ||
505 | for (i = 0; i < BUFFER_NUM; | ||
506 | i += max(a_blocks, (int)oxu->db_used[i])) { | ||
507 | |||
508 | /* Check all the required blocks are available */ | ||
509 | for (j = 0; j < a_blocks; j++) | ||
510 | if (oxu->db_used[i + j]) | ||
511 | break; | ||
512 | |||
513 | if (j != a_blocks) | ||
514 | continue; | ||
515 | |||
516 | /* Allocate blocks found! */ | ||
517 | qtd->buffer = (void *) &oxu->mem->db_pool[i]; | ||
518 | qtd->buffer_dma = virt_to_phys(qtd->buffer); | ||
519 | |||
520 | qtd->qtd_buffer_len = BUFFER_SIZE * a_blocks; | ||
521 | oxu->db_used[i] = a_blocks; | ||
522 | |||
523 | spin_unlock(&oxu->mem_lock); | ||
524 | |||
525 | return 0; | ||
526 | } | ||
527 | |||
528 | /* Failed */ | ||
529 | |||
530 | spin_unlock(&oxu->mem_lock); | ||
531 | |||
532 | return -ENOMEM; | ||
533 | } | ||
534 | |||
535 | static void oxu_buf_free(struct oxu_hcd *oxu, struct ehci_qtd *qtd) | ||
536 | { | ||
537 | int index; | ||
538 | |||
539 | spin_lock(&oxu->mem_lock); | ||
540 | |||
541 | index = (qtd->buffer - (void *) &oxu->mem->db_pool[0]) | ||
542 | / BUFFER_SIZE; | ||
543 | oxu->db_used[index] = 0; | ||
544 | qtd->qtd_buffer_len = 0; | ||
545 | qtd->buffer_dma = 0; | ||
546 | qtd->buffer = NULL; | ||
547 | |||
548 | spin_unlock(&oxu->mem_lock); | ||
549 | |||
550 | return; | ||
551 | } | ||
552 | |||
553 | static inline void ehci_qtd_init(struct ehci_qtd *qtd, dma_addr_t dma) | ||
554 | { | ||
555 | memset(qtd, 0, sizeof *qtd); | ||
556 | qtd->qtd_dma = dma; | ||
557 | qtd->hw_token = cpu_to_le32(QTD_STS_HALT); | ||
558 | qtd->hw_next = EHCI_LIST_END; | ||
559 | qtd->hw_alt_next = EHCI_LIST_END; | ||
560 | INIT_LIST_HEAD(&qtd->qtd_list); | ||
561 | } | ||
562 | |||
563 | static inline void oxu_qtd_free(struct oxu_hcd *oxu, struct ehci_qtd *qtd) | ||
564 | { | ||
565 | int index; | ||
566 | |||
567 | if (qtd->buffer) | ||
568 | oxu_buf_free(oxu, qtd); | ||
569 | |||
570 | spin_lock(&oxu->mem_lock); | ||
571 | |||
572 | index = qtd - &oxu->mem->qtd_pool[0]; | ||
573 | oxu->qtd_used[index] = 0; | ||
574 | |||
575 | spin_unlock(&oxu->mem_lock); | ||
576 | |||
577 | return; | ||
578 | } | ||
579 | |||
580 | static struct ehci_qtd *ehci_qtd_alloc(struct oxu_hcd *oxu) | ||
581 | { | ||
582 | int i; | ||
583 | struct ehci_qtd *qtd = NULL; | ||
584 | |||
585 | spin_lock(&oxu->mem_lock); | ||
586 | |||
587 | for (i = 0; i < QTD_NUM; i++) | ||
588 | if (!oxu->qtd_used[i]) | ||
589 | break; | ||
590 | |||
591 | if (i < QTD_NUM) { | ||
592 | qtd = (struct ehci_qtd *) &oxu->mem->qtd_pool[i]; | ||
593 | memset(qtd, 0, sizeof *qtd); | ||
594 | |||
595 | qtd->hw_token = cpu_to_le32(QTD_STS_HALT); | ||
596 | qtd->hw_next = EHCI_LIST_END; | ||
597 | qtd->hw_alt_next = EHCI_LIST_END; | ||
598 | INIT_LIST_HEAD(&qtd->qtd_list); | ||
599 | |||
600 | qtd->qtd_dma = virt_to_phys(qtd); | ||
601 | |||
602 | oxu->qtd_used[i] = 1; | ||
603 | } | ||
604 | |||
605 | spin_unlock(&oxu->mem_lock); | ||
606 | |||
607 | return qtd; | ||
608 | } | ||
609 | |||
610 | static void oxu_qh_free(struct oxu_hcd *oxu, struct ehci_qh *qh) | ||
611 | { | ||
612 | int index; | ||
613 | |||
614 | spin_lock(&oxu->mem_lock); | ||
615 | |||
616 | index = qh - &oxu->mem->qh_pool[0]; | ||
617 | oxu->qh_used[index] = 0; | ||
618 | |||
619 | spin_unlock(&oxu->mem_lock); | ||
620 | |||
621 | return; | ||
622 | } | ||
623 | |||
624 | static void qh_destroy(struct kref *kref) | ||
625 | { | ||
626 | struct ehci_qh *qh = container_of(kref, struct ehci_qh, kref); | ||
627 | struct oxu_hcd *oxu = qh->oxu; | ||
628 | |||
629 | /* clean qtds first, and know this is not linked */ | ||
630 | if (!list_empty(&qh->qtd_list) || qh->qh_next.ptr) { | ||
631 | oxu_dbg(oxu, "unused qh not empty!\n"); | ||
632 | BUG(); | ||
633 | } | ||
634 | if (qh->dummy) | ||
635 | oxu_qtd_free(oxu, qh->dummy); | ||
636 | oxu_qh_free(oxu, qh); | ||
637 | } | ||
638 | |||
639 | static struct ehci_qh *oxu_qh_alloc(struct oxu_hcd *oxu) | ||
640 | { | ||
641 | int i; | ||
642 | struct ehci_qh *qh = NULL; | ||
643 | |||
644 | spin_lock(&oxu->mem_lock); | ||
645 | |||
646 | for (i = 0; i < QHEAD_NUM; i++) | ||
647 | if (!oxu->qh_used[i]) | ||
648 | break; | ||
649 | |||
650 | if (i < QHEAD_NUM) { | ||
651 | qh = (struct ehci_qh *) &oxu->mem->qh_pool[i]; | ||
652 | memset(qh, 0, sizeof *qh); | ||
653 | |||
654 | kref_init(&qh->kref); | ||
655 | qh->oxu = oxu; | ||
656 | qh->qh_dma = virt_to_phys(qh); | ||
657 | INIT_LIST_HEAD(&qh->qtd_list); | ||
658 | |||
659 | /* dummy td enables safe urb queuing */ | ||
660 | qh->dummy = ehci_qtd_alloc(oxu); | ||
661 | if (qh->dummy == NULL) { | ||
662 | oxu_dbg(oxu, "no dummy td\n"); | ||
663 | oxu->qh_used[i] = 0; | ||
664 | |||
665 | return NULL; | ||
666 | } | ||
667 | |||
668 | oxu->qh_used[i] = 1; | ||
669 | } | ||
670 | |||
671 | spin_unlock(&oxu->mem_lock); | ||
672 | |||
673 | return qh; | ||
674 | } | ||
675 | |||
676 | /* to share a qh (cpu threads, or hc) */ | ||
677 | static inline struct ehci_qh *qh_get(struct ehci_qh *qh) | ||
678 | { | ||
679 | kref_get(&qh->kref); | ||
680 | return qh; | ||
681 | } | ||
682 | |||
683 | static inline void qh_put(struct ehci_qh *qh) | ||
684 | { | ||
685 | kref_put(&qh->kref, qh_destroy); | ||
686 | } | ||
687 | |||
688 | static void oxu_murb_free(struct oxu_hcd *oxu, struct oxu_murb *murb) | ||
689 | { | ||
690 | int index; | ||
691 | |||
692 | spin_lock(&oxu->mem_lock); | ||
693 | |||
694 | index = murb - &oxu->murb_pool[0]; | ||
695 | oxu->murb_used[index] = 0; | ||
696 | |||
697 | spin_unlock(&oxu->mem_lock); | ||
698 | |||
699 | return; | ||
700 | } | ||
701 | |||
702 | static struct oxu_murb *oxu_murb_alloc(struct oxu_hcd *oxu) | ||
703 | |||
704 | { | ||
705 | int i; | ||
706 | struct oxu_murb *murb = NULL; | ||
707 | |||
708 | spin_lock(&oxu->mem_lock); | ||
709 | |||
710 | for (i = 0; i < MURB_NUM; i++) | ||
711 | if (!oxu->murb_used[i]) | ||
712 | break; | ||
713 | |||
714 | if (i < MURB_NUM) { | ||
715 | murb = &(oxu->murb_pool)[i]; | ||
716 | |||
717 | oxu->murb_used[i] = 1; | ||
718 | } | ||
719 | |||
720 | spin_unlock(&oxu->mem_lock); | ||
721 | |||
722 | return murb; | ||
723 | } | ||
724 | |||
725 | /* The queue heads and transfer descriptors are managed from pools tied | ||
726 | * to each of the "per device" structures. | ||
727 | * This is the initialisation and cleanup code. | ||
728 | */ | ||
729 | static void ehci_mem_cleanup(struct oxu_hcd *oxu) | ||
730 | { | ||
731 | kfree(oxu->murb_pool); | ||
732 | oxu->murb_pool = NULL; | ||
733 | |||
734 | if (oxu->async) | ||
735 | qh_put(oxu->async); | ||
736 | oxu->async = NULL; | ||
737 | |||
738 | del_timer(&oxu->urb_timer); | ||
739 | |||
740 | oxu->periodic = NULL; | ||
741 | |||
742 | /* shadow periodic table */ | ||
743 | kfree(oxu->pshadow); | ||
744 | oxu->pshadow = NULL; | ||
745 | } | ||
746 | |||
747 | /* Remember to add cleanup code (above) if you add anything here. | ||
748 | */ | ||
749 | static int ehci_mem_init(struct oxu_hcd *oxu, gfp_t flags) | ||
750 | { | ||
751 | int i; | ||
752 | |||
753 | for (i = 0; i < oxu->periodic_size; i++) | ||
754 | oxu->mem->frame_list[i] = EHCI_LIST_END; | ||
755 | for (i = 0; i < QHEAD_NUM; i++) | ||
756 | oxu->qh_used[i] = 0; | ||
757 | for (i = 0; i < QTD_NUM; i++) | ||
758 | oxu->qtd_used[i] = 0; | ||
759 | |||
760 | oxu->murb_pool = kcalloc(MURB_NUM, sizeof(struct oxu_murb), flags); | ||
761 | if (!oxu->murb_pool) | ||
762 | goto fail; | ||
763 | |||
764 | for (i = 0; i < MURB_NUM; i++) | ||
765 | oxu->murb_used[i] = 0; | ||
766 | |||
767 | oxu->async = oxu_qh_alloc(oxu); | ||
768 | if (!oxu->async) | ||
769 | goto fail; | ||
770 | |||
771 | oxu->periodic = (__le32 *) &oxu->mem->frame_list; | ||
772 | oxu->periodic_dma = virt_to_phys(oxu->periodic); | ||
773 | |||
774 | for (i = 0; i < oxu->periodic_size; i++) | ||
775 | oxu->periodic[i] = EHCI_LIST_END; | ||
776 | |||
777 | /* software shadow of hardware table */ | ||
778 | oxu->pshadow = kcalloc(oxu->periodic_size, sizeof(void *), flags); | ||
779 | if (oxu->pshadow != NULL) | ||
780 | return 0; | ||
781 | |||
782 | fail: | ||
783 | oxu_dbg(oxu, "couldn't init memory\n"); | ||
784 | ehci_mem_cleanup(oxu); | ||
785 | return -ENOMEM; | ||
786 | } | ||
787 | |||
788 | /* Fill a qtd, returning how much of the buffer we were able to queue up. | ||
789 | */ | ||
790 | static int qtd_fill(struct ehci_qtd *qtd, dma_addr_t buf, size_t len, | ||
791 | int token, int maxpacket) | ||
792 | { | ||
793 | int i, count; | ||
794 | u64 addr = buf; | ||
795 | |||
796 | /* one buffer entry per 4K ... first might be short or unaligned */ | ||
797 | qtd->hw_buf[0] = cpu_to_le32((u32)addr); | ||
798 | qtd->hw_buf_hi[0] = cpu_to_le32((u32)(addr >> 32)); | ||
799 | count = 0x1000 - (buf & 0x0fff); /* rest of that page */ | ||
800 | if (likely(len < count)) /* ... iff needed */ | ||
801 | count = len; | ||
802 | else { | ||
803 | buf += 0x1000; | ||
804 | buf &= ~0x0fff; | ||
805 | |||
806 | /* per-qtd limit: from 16K to 20K (best alignment) */ | ||
807 | for (i = 1; count < len && i < 5; i++) { | ||
808 | addr = buf; | ||
809 | qtd->hw_buf[i] = cpu_to_le32((u32)addr); | ||
810 | qtd->hw_buf_hi[i] = cpu_to_le32((u32)(addr >> 32)); | ||
811 | buf += 0x1000; | ||
812 | if ((count + 0x1000) < len) | ||
813 | count += 0x1000; | ||
814 | else | ||
815 | count = len; | ||
816 | } | ||
817 | |||
818 | /* short packets may only terminate transfers */ | ||
819 | if (count != len) | ||
820 | count -= (count % maxpacket); | ||
821 | } | ||
822 | qtd->hw_token = cpu_to_le32((count << 16) | token); | ||
823 | qtd->length = count; | ||
824 | |||
825 | return count; | ||
826 | } | ||
827 | |||
828 | static inline void qh_update(struct oxu_hcd *oxu, | ||
829 | struct ehci_qh *qh, struct ehci_qtd *qtd) | ||
830 | { | ||
831 | /* writes to an active overlay are unsafe */ | ||
832 | BUG_ON(qh->qh_state != QH_STATE_IDLE); | ||
833 | |||
834 | qh->hw_qtd_next = QTD_NEXT(qtd->qtd_dma); | ||
835 | qh->hw_alt_next = EHCI_LIST_END; | ||
836 | |||
837 | /* Except for control endpoints, we make hardware maintain data | ||
838 | * toggle (like OHCI) ... here (re)initialize the toggle in the QH, | ||
839 | * and set the pseudo-toggle in udev. Only usb_clear_halt() will | ||
840 | * ever clear it. | ||
841 | */ | ||
842 | if (!(qh->hw_info1 & cpu_to_le32(1 << 14))) { | ||
843 | unsigned is_out, epnum; | ||
844 | |||
845 | is_out = !(qtd->hw_token & cpu_to_le32(1 << 8)); | ||
846 | epnum = (le32_to_cpup(&qh->hw_info1) >> 8) & 0x0f; | ||
847 | if (unlikely(!usb_gettoggle(qh->dev, epnum, is_out))) { | ||
848 | qh->hw_token &= ~__constant_cpu_to_le32(QTD_TOGGLE); | ||
849 | usb_settoggle(qh->dev, epnum, is_out, 1); | ||
850 | } | ||
851 | } | ||
852 | |||
853 | /* HC must see latest qtd and qh data before we clear ACTIVE+HALT */ | ||
854 | wmb(); | ||
855 | qh->hw_token &= __constant_cpu_to_le32(QTD_TOGGLE | QTD_STS_PING); | ||
856 | } | ||
857 | |||
858 | /* If it weren't for a common silicon quirk (writing the dummy into the qh | ||
859 | * overlay, so qh->hw_token wrongly becomes inactive/halted), only fault | ||
860 | * recovery (including urb dequeue) would need software changes to a QH... | ||
861 | */ | ||
862 | static void qh_refresh(struct oxu_hcd *oxu, struct ehci_qh *qh) | ||
863 | { | ||
864 | struct ehci_qtd *qtd; | ||
865 | |||
866 | if (list_empty(&qh->qtd_list)) | ||
867 | qtd = qh->dummy; | ||
868 | else { | ||
869 | qtd = list_entry(qh->qtd_list.next, | ||
870 | struct ehci_qtd, qtd_list); | ||
871 | /* first qtd may already be partially processed */ | ||
872 | if (cpu_to_le32(qtd->qtd_dma) == qh->hw_current) | ||
873 | qtd = NULL; | ||
874 | } | ||
875 | |||
876 | if (qtd) | ||
877 | qh_update(oxu, qh, qtd); | ||
878 | } | ||
879 | |||
880 | static void qtd_copy_status(struct oxu_hcd *oxu, struct urb *urb, | ||
881 | size_t length, u32 token) | ||
882 | { | ||
883 | /* count IN/OUT bytes, not SETUP (even short packets) */ | ||
884 | if (likely(QTD_PID(token) != 2)) | ||
885 | urb->actual_length += length - QTD_LENGTH(token); | ||
886 | |||
887 | /* don't modify error codes */ | ||
888 | if (unlikely(urb->status != -EINPROGRESS)) | ||
889 | return; | ||
890 | |||
891 | /* force cleanup after short read; not always an error */ | ||
892 | if (unlikely(IS_SHORT_READ(token))) | ||
893 | urb->status = -EREMOTEIO; | ||
894 | |||
895 | /* serious "can't proceed" faults reported by the hardware */ | ||
896 | if (token & QTD_STS_HALT) { | ||
897 | if (token & QTD_STS_BABBLE) { | ||
898 | /* FIXME "must" disable babbling device's port too */ | ||
899 | urb->status = -EOVERFLOW; | ||
900 | } else if (token & QTD_STS_MMF) { | ||
901 | /* fs/ls interrupt xfer missed the complete-split */ | ||
902 | urb->status = -EPROTO; | ||
903 | } else if (token & QTD_STS_DBE) { | ||
904 | urb->status = (QTD_PID(token) == 1) /* IN ? */ | ||
905 | ? -ENOSR /* hc couldn't read data */ | ||
906 | : -ECOMM; /* hc couldn't write data */ | ||
907 | } else if (token & QTD_STS_XACT) { | ||
908 | /* timeout, bad crc, wrong PID, etc; retried */ | ||
909 | if (QTD_CERR(token)) | ||
910 | urb->status = -EPIPE; | ||
911 | else { | ||
912 | oxu_dbg(oxu, "devpath %s ep%d%s 3strikes\n", | ||
913 | urb->dev->devpath, | ||
914 | usb_pipeendpoint(urb->pipe), | ||
915 | usb_pipein(urb->pipe) ? "in" : "out"); | ||
916 | urb->status = -EPROTO; | ||
917 | } | ||
918 | /* CERR nonzero + no errors + halt --> stall */ | ||
919 | } else if (QTD_CERR(token)) | ||
920 | urb->status = -EPIPE; | ||
921 | else /* unknown */ | ||
922 | urb->status = -EPROTO; | ||
923 | |||
924 | oxu_vdbg(oxu, "dev%d ep%d%s qtd token %08x --> status %d\n", | ||
925 | usb_pipedevice(urb->pipe), | ||
926 | usb_pipeendpoint(urb->pipe), | ||
927 | usb_pipein(urb->pipe) ? "in" : "out", | ||
928 | token, urb->status); | ||
929 | } | ||
930 | } | ||
931 | |||
932 | static void ehci_urb_done(struct oxu_hcd *oxu, struct urb *urb) | ||
933 | __releases(oxu->lock) | ||
934 | __acquires(oxu->lock) | ||
935 | { | ||
936 | if (likely(urb->hcpriv != NULL)) { | ||
937 | struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv; | ||
938 | |||
939 | /* S-mask in a QH means it's an interrupt urb */ | ||
940 | if ((qh->hw_info2 & __constant_cpu_to_le32(QH_SMASK)) != 0) { | ||
941 | |||
942 | /* ... update hc-wide periodic stats (for usbfs) */ | ||
943 | oxu_to_hcd(oxu)->self.bandwidth_int_reqs--; | ||
944 | } | ||
945 | qh_put(qh); | ||
946 | } | ||
947 | |||
948 | urb->hcpriv = NULL; | ||
949 | switch (urb->status) { | ||
950 | case -EINPROGRESS: /* success */ | ||
951 | urb->status = 0; | ||
952 | default: /* fault */ | ||
953 | break; | ||
954 | case -EREMOTEIO: /* fault or normal */ | ||
955 | if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) | ||
956 | urb->status = 0; | ||
957 | break; | ||
958 | case -ECONNRESET: /* canceled */ | ||
959 | case -ENOENT: | ||
960 | break; | ||
961 | } | ||
962 | |||
963 | #ifdef OXU_URB_TRACE | ||
964 | oxu_dbg(oxu, "%s %s urb %p ep%d%s status %d len %d/%d\n", | ||
965 | __func__, urb->dev->devpath, urb, | ||
966 | usb_pipeendpoint(urb->pipe), | ||
967 | usb_pipein(urb->pipe) ? "in" : "out", | ||
968 | urb->status, | ||
969 | urb->actual_length, urb->transfer_buffer_length); | ||
970 | #endif | ||
971 | |||
972 | /* complete() can reenter this HCD */ | ||
973 | spin_unlock(&oxu->lock); | ||
974 | usb_hcd_giveback_urb(oxu_to_hcd(oxu), urb, urb->status); | ||
975 | spin_lock(&oxu->lock); | ||
976 | } | ||
977 | |||
978 | static void start_unlink_async(struct oxu_hcd *oxu, struct ehci_qh *qh); | ||
979 | static void unlink_async(struct oxu_hcd *oxu, struct ehci_qh *qh); | ||
980 | |||
981 | static void intr_deschedule(struct oxu_hcd *oxu, struct ehci_qh *qh); | ||
982 | static int qh_schedule(struct oxu_hcd *oxu, struct ehci_qh *qh); | ||
983 | |||
984 | #define HALT_BIT __constant_cpu_to_le32(QTD_STS_HALT) | ||
985 | |||
986 | /* Process and free completed qtds for a qh, returning URBs to drivers. | ||
987 | * Chases up to qh->hw_current. Returns number of completions called, | ||
988 | * indicating how much "real" work we did. | ||
989 | */ | ||
990 | static unsigned qh_completions(struct oxu_hcd *oxu, struct ehci_qh *qh) | ||
991 | { | ||
992 | struct ehci_qtd *last = NULL, *end = qh->dummy; | ||
993 | struct list_head *entry, *tmp; | ||
994 | int stopped; | ||
995 | unsigned count = 0; | ||
996 | int do_status = 0; | ||
997 | u8 state; | ||
998 | struct oxu_murb *murb = NULL; | ||
999 | |||
1000 | if (unlikely(list_empty(&qh->qtd_list))) | ||
1001 | return count; | ||
1002 | |||
1003 | /* completions (or tasks on other cpus) must never clobber HALT | ||
1004 | * till we've gone through and cleaned everything up, even when | ||
1005 | * they add urbs to this qh's queue or mark them for unlinking. | ||
1006 | * | ||
1007 | * NOTE: unlinking expects to be done in queue order. | ||
1008 | */ | ||
1009 | state = qh->qh_state; | ||
1010 | qh->qh_state = QH_STATE_COMPLETING; | ||
1011 | stopped = (state == QH_STATE_IDLE); | ||
1012 | |||
1013 | /* remove de-activated QTDs from front of queue. | ||
1014 | * after faults (including short reads), cleanup this urb | ||
1015 | * then let the queue advance. | ||
1016 | * if queue is stopped, handles unlinks. | ||
1017 | */ | ||
1018 | list_for_each_safe(entry, tmp, &qh->qtd_list) { | ||
1019 | struct ehci_qtd *qtd; | ||
1020 | struct urb *urb; | ||
1021 | u32 token = 0; | ||
1022 | |||
1023 | qtd = list_entry(entry, struct ehci_qtd, qtd_list); | ||
1024 | urb = qtd->urb; | ||
1025 | |||
1026 | /* Clean up any state from previous QTD ...*/ | ||
1027 | if (last) { | ||
1028 | if (likely(last->urb != urb)) { | ||
1029 | if (last->urb->complete == NULL) { | ||
1030 | murb = (struct oxu_murb *) last->urb; | ||
1031 | last->urb = murb->main; | ||
1032 | if (murb->last) { | ||
1033 | ehci_urb_done(oxu, last->urb); | ||
1034 | count++; | ||
1035 | } | ||
1036 | oxu_murb_free(oxu, murb); | ||
1037 | } else { | ||
1038 | ehci_urb_done(oxu, last->urb); | ||
1039 | count++; | ||
1040 | } | ||
1041 | } | ||
1042 | oxu_qtd_free(oxu, last); | ||
1043 | last = NULL; | ||
1044 | } | ||
1045 | |||
1046 | /* ignore urbs submitted during completions we reported */ | ||
1047 | if (qtd == end) | ||
1048 | break; | ||
1049 | |||
1050 | /* hardware copies qtd out of qh overlay */ | ||
1051 | rmb(); | ||
1052 | token = le32_to_cpu(qtd->hw_token); | ||
1053 | |||
1054 | /* always clean up qtds the hc de-activated */ | ||
1055 | if ((token & QTD_STS_ACTIVE) == 0) { | ||
1056 | |||
1057 | if ((token & QTD_STS_HALT) != 0) { | ||
1058 | stopped = 1; | ||
1059 | |||
1060 | /* magic dummy for some short reads; qh won't advance. | ||
1061 | * that silicon quirk can kick in with this dummy too. | ||
1062 | */ | ||
1063 | } else if (IS_SHORT_READ(token) && | ||
1064 | !(qtd->hw_alt_next & EHCI_LIST_END)) { | ||
1065 | stopped = 1; | ||
1066 | goto halt; | ||
1067 | } | ||
1068 | |||
1069 | /* stop scanning when we reach qtds the hc is using */ | ||
1070 | } else if (likely(!stopped && | ||
1071 | HC_IS_RUNNING(oxu_to_hcd(oxu)->state))) { | ||
1072 | break; | ||
1073 | |||
1074 | } else { | ||
1075 | stopped = 1; | ||
1076 | |||
1077 | if (unlikely(!HC_IS_RUNNING(oxu_to_hcd(oxu)->state))) | ||
1078 | urb->status = -ESHUTDOWN; | ||
1079 | |||
1080 | /* ignore active urbs unless some previous qtd | ||
1081 | * for the urb faulted (including short read) or | ||
1082 | * its urb was canceled. we may patch qh or qtds. | ||
1083 | */ | ||
1084 | if (likely(urb->status == -EINPROGRESS)) | ||
1085 | continue; | ||
1086 | |||
1087 | /* issue status after short control reads */ | ||
1088 | if (unlikely(do_status != 0) | ||
1089 | && QTD_PID(token) == 0 /* OUT */) { | ||
1090 | do_status = 0; | ||
1091 | continue; | ||
1092 | } | ||
1093 | |||
1094 | /* token in overlay may be most current */ | ||
1095 | if (state == QH_STATE_IDLE | ||
1096 | && cpu_to_le32(qtd->qtd_dma) | ||
1097 | == qh->hw_current) | ||
1098 | token = le32_to_cpu(qh->hw_token); | ||
1099 | |||
1100 | /* force halt for unlinked or blocked qh, so we'll | ||
1101 | * patch the qh later and so that completions can't | ||
1102 | * activate it while we "know" it's stopped. | ||
1103 | */ | ||
1104 | if ((HALT_BIT & qh->hw_token) == 0) { | ||
1105 | halt: | ||
1106 | qh->hw_token |= HALT_BIT; | ||
1107 | wmb(); | ||
1108 | } | ||
1109 | } | ||
1110 | |||
1111 | /* Remove it from the queue */ | ||
1112 | qtd_copy_status(oxu, urb->complete ? | ||
1113 | urb : ((struct oxu_murb *) urb)->main, | ||
1114 | qtd->length, token); | ||
1115 | if ((usb_pipein(qtd->urb->pipe)) && | ||
1116 | (NULL != qtd->transfer_buffer)) | ||
1117 | memcpy(qtd->transfer_buffer, qtd->buffer, qtd->length); | ||
1118 | do_status = (urb->status == -EREMOTEIO) | ||
1119 | && usb_pipecontrol(urb->pipe); | ||
1120 | |||
1121 | if (stopped && qtd->qtd_list.prev != &qh->qtd_list) { | ||
1122 | last = list_entry(qtd->qtd_list.prev, | ||
1123 | struct ehci_qtd, qtd_list); | ||
1124 | last->hw_next = qtd->hw_next; | ||
1125 | } | ||
1126 | list_del(&qtd->qtd_list); | ||
1127 | last = qtd; | ||
1128 | } | ||
1129 | |||
1130 | /* last urb's completion might still need calling */ | ||
1131 | if (likely(last != NULL)) { | ||
1132 | if (last->urb->complete == NULL) { | ||
1133 | murb = (struct oxu_murb *) last->urb; | ||
1134 | last->urb = murb->main; | ||
1135 | if (murb->last) { | ||
1136 | ehci_urb_done(oxu, last->urb); | ||
1137 | count++; | ||
1138 | } | ||
1139 | oxu_murb_free(oxu, murb); | ||
1140 | } else { | ||
1141 | ehci_urb_done(oxu, last->urb); | ||
1142 | count++; | ||
1143 | } | ||
1144 | oxu_qtd_free(oxu, last); | ||
1145 | } | ||
1146 | |||
1147 | /* restore original state; caller must unlink or relink */ | ||
1148 | qh->qh_state = state; | ||
1149 | |||
1150 | /* be sure the hardware's done with the qh before refreshing | ||
1151 | * it after fault cleanup, or recovering from silicon wrongly | ||
1152 | * overlaying the dummy qtd (which reduces DMA chatter). | ||
1153 | */ | ||
1154 | if (stopped != 0 || qh->hw_qtd_next == EHCI_LIST_END) { | ||
1155 | switch (state) { | ||
1156 | case QH_STATE_IDLE: | ||
1157 | qh_refresh(oxu, qh); | ||
1158 | break; | ||
1159 | case QH_STATE_LINKED: | ||
1160 | /* should be rare for periodic transfers, | ||
1161 | * except maybe high bandwidth ... | ||
1162 | */ | ||
1163 | if ((__constant_cpu_to_le32(QH_SMASK) | ||
1164 | & qh->hw_info2) != 0) { | ||
1165 | intr_deschedule(oxu, qh); | ||
1166 | (void) qh_schedule(oxu, qh); | ||
1167 | } else | ||
1168 | unlink_async(oxu, qh); | ||
1169 | break; | ||
1170 | /* otherwise, unlink already started */ | ||
1171 | } | ||
1172 | } | ||
1173 | |||
1174 | return count; | ||
1175 | } | ||
1176 | |||
1177 | /* High bandwidth multiplier, as encoded in highspeed endpoint descriptors */ | ||
1178 | #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03)) | ||
1179 | /* ... and packet size, for any kind of endpoint descriptor */ | ||
1180 | #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff) | ||
1181 | |||
1182 | /* Reverse of qh_urb_transaction: free a list of TDs. | ||
1183 | * used for cleanup after errors, before HC sees an URB's TDs. | ||
1184 | */ | ||
1185 | static void qtd_list_free(struct oxu_hcd *oxu, | ||
1186 | struct urb *urb, struct list_head *qtd_list) | ||
1187 | { | ||
1188 | struct list_head *entry, *temp; | ||
1189 | |||
1190 | list_for_each_safe(entry, temp, qtd_list) { | ||
1191 | struct ehci_qtd *qtd; | ||
1192 | |||
1193 | qtd = list_entry(entry, struct ehci_qtd, qtd_list); | ||
1194 | list_del(&qtd->qtd_list); | ||
1195 | oxu_qtd_free(oxu, qtd); | ||
1196 | } | ||
1197 | } | ||
1198 | |||
1199 | /* Create a list of filled qtds for this URB; won't link into qh. | ||
1200 | */ | ||
1201 | static struct list_head *qh_urb_transaction(struct oxu_hcd *oxu, | ||
1202 | struct urb *urb, | ||
1203 | struct list_head *head, | ||
1204 | gfp_t flags) | ||
1205 | { | ||
1206 | struct ehci_qtd *qtd, *qtd_prev; | ||
1207 | dma_addr_t buf; | ||
1208 | int len, maxpacket; | ||
1209 | int is_input; | ||
1210 | u32 token; | ||
1211 | void *transfer_buf = NULL; | ||
1212 | int ret; | ||
1213 | |||
1214 | /* | ||
1215 | * URBs map to sequences of QTDs: one logical transaction | ||
1216 | */ | ||
1217 | qtd = ehci_qtd_alloc(oxu); | ||
1218 | if (unlikely(!qtd)) | ||
1219 | return NULL; | ||
1220 | list_add_tail(&qtd->qtd_list, head); | ||
1221 | qtd->urb = urb; | ||
1222 | |||
1223 | token = QTD_STS_ACTIVE; | ||
1224 | token |= (EHCI_TUNE_CERR << 10); | ||
1225 | /* for split transactions, SplitXState initialized to zero */ | ||
1226 | |||
1227 | len = urb->transfer_buffer_length; | ||
1228 | is_input = usb_pipein(urb->pipe); | ||
1229 | if (!urb->transfer_buffer && urb->transfer_buffer_length && is_input) | ||
1230 | urb->transfer_buffer = phys_to_virt(urb->transfer_dma); | ||
1231 | |||
1232 | if (usb_pipecontrol(urb->pipe)) { | ||
1233 | /* SETUP pid */ | ||
1234 | ret = oxu_buf_alloc(oxu, qtd, sizeof(struct usb_ctrlrequest)); | ||
1235 | if (ret) | ||
1236 | goto cleanup; | ||
1237 | |||
1238 | qtd_fill(qtd, qtd->buffer_dma, sizeof(struct usb_ctrlrequest), | ||
1239 | token | (2 /* "setup" */ << 8), 8); | ||
1240 | memcpy(qtd->buffer, qtd->urb->setup_packet, | ||
1241 | sizeof(struct usb_ctrlrequest)); | ||
1242 | |||
1243 | /* ... and always at least one more pid */ | ||
1244 | token ^= QTD_TOGGLE; | ||
1245 | qtd_prev = qtd; | ||
1246 | qtd = ehci_qtd_alloc(oxu); | ||
1247 | if (unlikely(!qtd)) | ||
1248 | goto cleanup; | ||
1249 | qtd->urb = urb; | ||
1250 | qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); | ||
1251 | list_add_tail(&qtd->qtd_list, head); | ||
1252 | |||
1253 | /* for zero length DATA stages, STATUS is always IN */ | ||
1254 | if (len == 0) | ||
1255 | token |= (1 /* "in" */ << 8); | ||
1256 | } | ||
1257 | |||
1258 | /* | ||
1259 | * Data transfer stage: buffer setup | ||
1260 | */ | ||
1261 | |||
1262 | ret = oxu_buf_alloc(oxu, qtd, len); | ||
1263 | if (ret) | ||
1264 | goto cleanup; | ||
1265 | |||
1266 | buf = qtd->buffer_dma; | ||
1267 | transfer_buf = urb->transfer_buffer; | ||
1268 | |||
1269 | if (!is_input) | ||
1270 | memcpy(qtd->buffer, qtd->urb->transfer_buffer, len); | ||
1271 | |||
1272 | if (is_input) | ||
1273 | token |= (1 /* "in" */ << 8); | ||
1274 | /* else it's already initted to "out" pid (0 << 8) */ | ||
1275 | |||
1276 | maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input)); | ||
1277 | |||
1278 | /* | ||
1279 | * buffer gets wrapped in one or more qtds; | ||
1280 | * last one may be "short" (including zero len) | ||
1281 | * and may serve as a control status ack | ||
1282 | */ | ||
1283 | for (;;) { | ||
1284 | int this_qtd_len; | ||
1285 | |||
1286 | this_qtd_len = qtd_fill(qtd, buf, len, token, maxpacket); | ||
1287 | qtd->transfer_buffer = transfer_buf; | ||
1288 | len -= this_qtd_len; | ||
1289 | buf += this_qtd_len; | ||
1290 | transfer_buf += this_qtd_len; | ||
1291 | if (is_input) | ||
1292 | qtd->hw_alt_next = oxu->async->hw_alt_next; | ||
1293 | |||
1294 | /* qh makes control packets use qtd toggle; maybe switch it */ | ||
1295 | if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0) | ||
1296 | token ^= QTD_TOGGLE; | ||
1297 | |||
1298 | if (likely(len <= 0)) | ||
1299 | break; | ||
1300 | |||
1301 | qtd_prev = qtd; | ||
1302 | qtd = ehci_qtd_alloc(oxu); | ||
1303 | if (unlikely(!qtd)) | ||
1304 | goto cleanup; | ||
1305 | if (likely(len > 0)) { | ||
1306 | ret = oxu_buf_alloc(oxu, qtd, len); | ||
1307 | if (ret) | ||
1308 | goto cleanup; | ||
1309 | } | ||
1310 | qtd->urb = urb; | ||
1311 | qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); | ||
1312 | list_add_tail(&qtd->qtd_list, head); | ||
1313 | } | ||
1314 | |||
1315 | /* unless the bulk/interrupt caller wants a chance to clean | ||
1316 | * up after short reads, hc should advance qh past this urb | ||
1317 | */ | ||
1318 | if (likely((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 | ||
1319 | || usb_pipecontrol(urb->pipe))) | ||
1320 | qtd->hw_alt_next = EHCI_LIST_END; | ||
1321 | |||
1322 | /* | ||
1323 | * control requests may need a terminating data "status" ack; | ||
1324 | * bulk ones may need a terminating short packet (zero length). | ||
1325 | */ | ||
1326 | if (likely(urb->transfer_buffer_length != 0)) { | ||
1327 | int one_more = 0; | ||
1328 | |||
1329 | if (usb_pipecontrol(urb->pipe)) { | ||
1330 | one_more = 1; | ||
1331 | token ^= 0x0100; /* "in" <--> "out" */ | ||
1332 | token |= QTD_TOGGLE; /* force DATA1 */ | ||
1333 | } else if (usb_pipebulk(urb->pipe) | ||
1334 | && (urb->transfer_flags & URB_ZERO_PACKET) | ||
1335 | && !(urb->transfer_buffer_length % maxpacket)) { | ||
1336 | one_more = 1; | ||
1337 | } | ||
1338 | if (one_more) { | ||
1339 | qtd_prev = qtd; | ||
1340 | qtd = ehci_qtd_alloc(oxu); | ||
1341 | if (unlikely(!qtd)) | ||
1342 | goto cleanup; | ||
1343 | qtd->urb = urb; | ||
1344 | qtd_prev->hw_next = QTD_NEXT(qtd->qtd_dma); | ||
1345 | list_add_tail(&qtd->qtd_list, head); | ||
1346 | |||
1347 | /* never any data in such packets */ | ||
1348 | qtd_fill(qtd, 0, 0, token, 0); | ||
1349 | } | ||
1350 | } | ||
1351 | |||
1352 | /* by default, enable interrupt on urb completion */ | ||
1353 | qtd->hw_token |= __constant_cpu_to_le32(QTD_IOC); | ||
1354 | return head; | ||
1355 | |||
1356 | cleanup: | ||
1357 | qtd_list_free(oxu, urb, head); | ||
1358 | return NULL; | ||
1359 | } | ||
1360 | |||
1361 | /* Each QH holds a qtd list; a QH is used for everything except iso. | ||
1362 | * | ||
1363 | * For interrupt urbs, the scheduler must set the microframe scheduling | ||
1364 | * mask(s) each time the QH gets scheduled. For highspeed, that's | ||
1365 | * just one microframe in the s-mask. For split interrupt transactions | ||
1366 | * there are additional complications: c-mask, maybe FSTNs. | ||
1367 | */ | ||
1368 | static struct ehci_qh *qh_make(struct oxu_hcd *oxu, | ||
1369 | struct urb *urb, gfp_t flags) | ||
1370 | { | ||
1371 | struct ehci_qh *qh = oxu_qh_alloc(oxu); | ||
1372 | u32 info1 = 0, info2 = 0; | ||
1373 | int is_input, type; | ||
1374 | int maxp = 0; | ||
1375 | |||
1376 | if (!qh) | ||
1377 | return qh; | ||
1378 | |||
1379 | /* | ||
1380 | * init endpoint/device data for this QH | ||
1381 | */ | ||
1382 | info1 |= usb_pipeendpoint(urb->pipe) << 8; | ||
1383 | info1 |= usb_pipedevice(urb->pipe) << 0; | ||
1384 | |||
1385 | is_input = usb_pipein(urb->pipe); | ||
1386 | type = usb_pipetype(urb->pipe); | ||
1387 | maxp = usb_maxpacket(urb->dev, urb->pipe, !is_input); | ||
1388 | |||
1389 | /* Compute interrupt scheduling parameters just once, and save. | ||
1390 | * - allowing for high bandwidth, how many nsec/uframe are used? | ||
1391 | * - split transactions need a second CSPLIT uframe; same question | ||
1392 | * - splits also need a schedule gap (for full/low speed I/O) | ||
1393 | * - qh has a polling interval | ||
1394 | * | ||
1395 | * For control/bulk requests, the HC or TT handles these. | ||
1396 | */ | ||
1397 | if (type == PIPE_INTERRUPT) { | ||
1398 | qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, | ||
1399 | is_input, 0, | ||
1400 | hb_mult(maxp) * max_packet(maxp))); | ||
1401 | qh->start = NO_FRAME; | ||
1402 | |||
1403 | if (urb->dev->speed == USB_SPEED_HIGH) { | ||
1404 | qh->c_usecs = 0; | ||
1405 | qh->gap_uf = 0; | ||
1406 | |||
1407 | qh->period = urb->interval >> 3; | ||
1408 | if (qh->period == 0 && urb->interval != 1) { | ||
1409 | /* NOTE interval 2 or 4 uframes could work. | ||
1410 | * But interval 1 scheduling is simpler, and | ||
1411 | * includes high bandwidth. | ||
1412 | */ | ||
1413 | dbg("intr period %d uframes, NYET!", | ||
1414 | urb->interval); | ||
1415 | goto done; | ||
1416 | } | ||
1417 | } else { | ||
1418 | struct usb_tt *tt = urb->dev->tt; | ||
1419 | int think_time; | ||
1420 | |||
1421 | /* gap is f(FS/LS transfer times) */ | ||
1422 | qh->gap_uf = 1 + usb_calc_bus_time(urb->dev->speed, | ||
1423 | is_input, 0, maxp) / (125 * 1000); | ||
1424 | |||
1425 | /* FIXME this just approximates SPLIT/CSPLIT times */ | ||
1426 | if (is_input) { /* SPLIT, gap, CSPLIT+DATA */ | ||
1427 | qh->c_usecs = qh->usecs + HS_USECS(0); | ||
1428 | qh->usecs = HS_USECS(1); | ||
1429 | } else { /* SPLIT+DATA, gap, CSPLIT */ | ||
1430 | qh->usecs += HS_USECS(1); | ||
1431 | qh->c_usecs = HS_USECS(0); | ||
1432 | } | ||
1433 | |||
1434 | think_time = tt ? tt->think_time : 0; | ||
1435 | qh->tt_usecs = NS_TO_US(think_time + | ||
1436 | usb_calc_bus_time(urb->dev->speed, | ||
1437 | is_input, 0, max_packet(maxp))); | ||
1438 | qh->period = urb->interval; | ||
1439 | } | ||
1440 | } | ||
1441 | |||
1442 | /* support for tt scheduling, and access to toggles */ | ||
1443 | qh->dev = urb->dev; | ||
1444 | |||
1445 | /* using TT? */ | ||
1446 | switch (urb->dev->speed) { | ||
1447 | case USB_SPEED_LOW: | ||
1448 | info1 |= (1 << 12); /* EPS "low" */ | ||
1449 | /* FALL THROUGH */ | ||
1450 | |||
1451 | case USB_SPEED_FULL: | ||
1452 | /* EPS 0 means "full" */ | ||
1453 | if (type != PIPE_INTERRUPT) | ||
1454 | info1 |= (EHCI_TUNE_RL_TT << 28); | ||
1455 | if (type == PIPE_CONTROL) { | ||
1456 | info1 |= (1 << 27); /* for TT */ | ||
1457 | info1 |= 1 << 14; /* toggle from qtd */ | ||
1458 | } | ||
1459 | info1 |= maxp << 16; | ||
1460 | |||
1461 | info2 |= (EHCI_TUNE_MULT_TT << 30); | ||
1462 | info2 |= urb->dev->ttport << 23; | ||
1463 | |||
1464 | /* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */ | ||
1465 | |||
1466 | break; | ||
1467 | |||
1468 | case USB_SPEED_HIGH: /* no TT involved */ | ||
1469 | info1 |= (2 << 12); /* EPS "high" */ | ||
1470 | if (type == PIPE_CONTROL) { | ||
1471 | info1 |= (EHCI_TUNE_RL_HS << 28); | ||
1472 | info1 |= 64 << 16; /* usb2 fixed maxpacket */ | ||
1473 | info1 |= 1 << 14; /* toggle from qtd */ | ||
1474 | info2 |= (EHCI_TUNE_MULT_HS << 30); | ||
1475 | } else if (type == PIPE_BULK) { | ||
1476 | info1 |= (EHCI_TUNE_RL_HS << 28); | ||
1477 | info1 |= 512 << 16; /* usb2 fixed maxpacket */ | ||
1478 | info2 |= (EHCI_TUNE_MULT_HS << 30); | ||
1479 | } else { /* PIPE_INTERRUPT */ | ||
1480 | info1 |= max_packet(maxp) << 16; | ||
1481 | info2 |= hb_mult(maxp) << 30; | ||
1482 | } | ||
1483 | break; | ||
1484 | default: | ||
1485 | dbg("bogus dev %p speed %d", urb->dev, urb->dev->speed); | ||
1486 | done: | ||
1487 | qh_put(qh); | ||
1488 | return NULL; | ||
1489 | } | ||
1490 | |||
1491 | /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */ | ||
1492 | |||
1493 | /* init as live, toggle clear, advance to dummy */ | ||
1494 | qh->qh_state = QH_STATE_IDLE; | ||
1495 | qh->hw_info1 = cpu_to_le32(info1); | ||
1496 | qh->hw_info2 = cpu_to_le32(info2); | ||
1497 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, 1); | ||
1498 | qh_refresh(oxu, qh); | ||
1499 | return qh; | ||
1500 | } | ||
1501 | |||
1502 | /* Move qh (and its qtds) onto async queue; maybe enable queue. | ||
1503 | */ | ||
1504 | static void qh_link_async(struct oxu_hcd *oxu, struct ehci_qh *qh) | ||
1505 | { | ||
1506 | __le32 dma = QH_NEXT(qh->qh_dma); | ||
1507 | struct ehci_qh *head; | ||
1508 | |||
1509 | /* (re)start the async schedule? */ | ||
1510 | head = oxu->async; | ||
1511 | timer_action_done(oxu, TIMER_ASYNC_OFF); | ||
1512 | if (!head->qh_next.qh) { | ||
1513 | u32 cmd = readl(&oxu->regs->command); | ||
1514 | |||
1515 | if (!(cmd & CMD_ASE)) { | ||
1516 | /* in case a clear of CMD_ASE didn't take yet */ | ||
1517 | (void)handshake(oxu, &oxu->regs->status, | ||
1518 | STS_ASS, 0, 150); | ||
1519 | cmd |= CMD_ASE | CMD_RUN; | ||
1520 | writel(cmd, &oxu->regs->command); | ||
1521 | oxu_to_hcd(oxu)->state = HC_STATE_RUNNING; | ||
1522 | /* posted write need not be known to HC yet ... */ | ||
1523 | } | ||
1524 | } | ||
1525 | |||
1526 | /* clear halt and/or toggle; and maybe recover from silicon quirk */ | ||
1527 | if (qh->qh_state == QH_STATE_IDLE) | ||
1528 | qh_refresh(oxu, qh); | ||
1529 | |||
1530 | /* splice right after start */ | ||
1531 | qh->qh_next = head->qh_next; | ||
1532 | qh->hw_next = head->hw_next; | ||
1533 | wmb(); | ||
1534 | |||
1535 | head->qh_next.qh = qh; | ||
1536 | head->hw_next = dma; | ||
1537 | |||
1538 | qh->qh_state = QH_STATE_LINKED; | ||
1539 | /* qtd completions reported later by interrupt */ | ||
1540 | } | ||
1541 | |||
1542 | #define QH_ADDR_MASK __constant_cpu_to_le32(0x7f) | ||
1543 | |||
1544 | /* | ||
1545 | * For control/bulk/interrupt, return QH with these TDs appended. | ||
1546 | * Allocates and initializes the QH if necessary. | ||
1547 | * Returns null if it can't allocate a QH it needs to. | ||
1548 | * If the QH has TDs (urbs) already, that's great. | ||
1549 | */ | ||
1550 | static struct ehci_qh *qh_append_tds(struct oxu_hcd *oxu, | ||
1551 | struct urb *urb, struct list_head *qtd_list, | ||
1552 | int epnum, void **ptr) | ||
1553 | { | ||
1554 | struct ehci_qh *qh = NULL; | ||
1555 | |||
1556 | qh = (struct ehci_qh *) *ptr; | ||
1557 | if (unlikely(qh == NULL)) { | ||
1558 | /* can't sleep here, we have oxu->lock... */ | ||
1559 | qh = qh_make(oxu, urb, GFP_ATOMIC); | ||
1560 | *ptr = qh; | ||
1561 | } | ||
1562 | if (likely(qh != NULL)) { | ||
1563 | struct ehci_qtd *qtd; | ||
1564 | |||
1565 | if (unlikely(list_empty(qtd_list))) | ||
1566 | qtd = NULL; | ||
1567 | else | ||
1568 | qtd = list_entry(qtd_list->next, struct ehci_qtd, | ||
1569 | qtd_list); | ||
1570 | |||
1571 | /* control qh may need patching ... */ | ||
1572 | if (unlikely(epnum == 0)) { | ||
1573 | |||
1574 | /* usb_reset_device() briefly reverts to address 0 */ | ||
1575 | if (usb_pipedevice(urb->pipe) == 0) | ||
1576 | qh->hw_info1 &= ~QH_ADDR_MASK; | ||
1577 | } | ||
1578 | |||
1579 | /* just one way to queue requests: swap with the dummy qtd. | ||
1580 | * only hc or qh_refresh() ever modify the overlay. | ||
1581 | */ | ||
1582 | if (likely(qtd != NULL)) { | ||
1583 | struct ehci_qtd *dummy; | ||
1584 | dma_addr_t dma; | ||
1585 | __le32 token; | ||
1586 | |||
1587 | /* to avoid racing the HC, use the dummy td instead of | ||
1588 | * the first td of our list (becomes new dummy). both | ||
1589 | * tds stay deactivated until we're done, when the | ||
1590 | * HC is allowed to fetch the old dummy (4.10.2). | ||
1591 | */ | ||
1592 | token = qtd->hw_token; | ||
1593 | qtd->hw_token = HALT_BIT; | ||
1594 | wmb(); | ||
1595 | dummy = qh->dummy; | ||
1596 | |||
1597 | dma = dummy->qtd_dma; | ||
1598 | *dummy = *qtd; | ||
1599 | dummy->qtd_dma = dma; | ||
1600 | |||
1601 | list_del(&qtd->qtd_list); | ||
1602 | list_add(&dummy->qtd_list, qtd_list); | ||
1603 | list_splice(qtd_list, qh->qtd_list.prev); | ||
1604 | |||
1605 | ehci_qtd_init(qtd, qtd->qtd_dma); | ||
1606 | qh->dummy = qtd; | ||
1607 | |||
1608 | /* hc must see the new dummy at list end */ | ||
1609 | dma = qtd->qtd_dma; | ||
1610 | qtd = list_entry(qh->qtd_list.prev, | ||
1611 | struct ehci_qtd, qtd_list); | ||
1612 | qtd->hw_next = QTD_NEXT(dma); | ||
1613 | |||
1614 | /* let the hc process these next qtds */ | ||
1615 | dummy->hw_token = (token & ~(0x80)); | ||
1616 | wmb(); | ||
1617 | dummy->hw_token = token; | ||
1618 | |||
1619 | urb->hcpriv = qh_get(qh); | ||
1620 | } | ||
1621 | } | ||
1622 | return qh; | ||
1623 | } | ||
1624 | |||
1625 | static int submit_async(struct oxu_hcd *oxu, struct urb *urb, | ||
1626 | struct list_head *qtd_list, gfp_t mem_flags) | ||
1627 | { | ||
1628 | struct ehci_qtd *qtd; | ||
1629 | int epnum; | ||
1630 | unsigned long flags; | ||
1631 | struct ehci_qh *qh = NULL; | ||
1632 | int rc = 0; | ||
1633 | |||
1634 | qtd = list_entry(qtd_list->next, struct ehci_qtd, qtd_list); | ||
1635 | epnum = urb->ep->desc.bEndpointAddress; | ||
1636 | |||
1637 | #ifdef OXU_URB_TRACE | ||
1638 | oxu_dbg(oxu, "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n", | ||
1639 | __func__, urb->dev->devpath, urb, | ||
1640 | epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out", | ||
1641 | urb->transfer_buffer_length, | ||
1642 | qtd, urb->ep->hcpriv); | ||
1643 | #endif | ||
1644 | |||
1645 | spin_lock_irqsave(&oxu->lock, flags); | ||
1646 | if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, | ||
1647 | &oxu_to_hcd(oxu)->flags))) { | ||
1648 | rc = -ESHUTDOWN; | ||
1649 | goto done; | ||
1650 | } | ||
1651 | |||
1652 | qh = qh_append_tds(oxu, urb, qtd_list, epnum, &urb->ep->hcpriv); | ||
1653 | if (unlikely(qh == NULL)) { | ||
1654 | rc = -ENOMEM; | ||
1655 | goto done; | ||
1656 | } | ||
1657 | |||
1658 | /* Control/bulk operations through TTs don't need scheduling, | ||
1659 | * the HC and TT handle it when the TT has a buffer ready. | ||
1660 | */ | ||
1661 | if (likely(qh->qh_state == QH_STATE_IDLE)) | ||
1662 | qh_link_async(oxu, qh_get(qh)); | ||
1663 | done: | ||
1664 | spin_unlock_irqrestore(&oxu->lock, flags); | ||
1665 | if (unlikely(qh == NULL)) | ||
1666 | qtd_list_free(oxu, urb, qtd_list); | ||
1667 | return rc; | ||
1668 | } | ||
1669 | |||
1670 | /* The async qh for the qtds being reclaimed are now unlinked from the HC */ | ||
1671 | |||
1672 | static void end_unlink_async(struct oxu_hcd *oxu) | ||
1673 | { | ||
1674 | struct ehci_qh *qh = oxu->reclaim; | ||
1675 | struct ehci_qh *next; | ||
1676 | |||
1677 | timer_action_done(oxu, TIMER_IAA_WATCHDOG); | ||
1678 | |||
1679 | qh->qh_state = QH_STATE_IDLE; | ||
1680 | qh->qh_next.qh = NULL; | ||
1681 | qh_put(qh); /* refcount from reclaim */ | ||
1682 | |||
1683 | /* other unlink(s) may be pending (in QH_STATE_UNLINK_WAIT) */ | ||
1684 | next = qh->reclaim; | ||
1685 | oxu->reclaim = next; | ||
1686 | oxu->reclaim_ready = 0; | ||
1687 | qh->reclaim = NULL; | ||
1688 | |||
1689 | qh_completions(oxu, qh); | ||
1690 | |||
1691 | if (!list_empty(&qh->qtd_list) | ||
1692 | && HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) | ||
1693 | qh_link_async(oxu, qh); | ||
1694 | else { | ||
1695 | qh_put(qh); /* refcount from async list */ | ||
1696 | |||
1697 | /* it's not free to turn the async schedule on/off; leave it | ||
1698 | * active but idle for a while once it empties. | ||
1699 | */ | ||
1700 | if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state) | ||
1701 | && oxu->async->qh_next.qh == NULL) | ||
1702 | timer_action(oxu, TIMER_ASYNC_OFF); | ||
1703 | } | ||
1704 | |||
1705 | if (next) { | ||
1706 | oxu->reclaim = NULL; | ||
1707 | start_unlink_async(oxu, next); | ||
1708 | } | ||
1709 | } | ||
1710 | |||
1711 | /* makes sure the async qh will become idle */ | ||
1712 | /* caller must own oxu->lock */ | ||
1713 | |||
1714 | static void start_unlink_async(struct oxu_hcd *oxu, struct ehci_qh *qh) | ||
1715 | { | ||
1716 | int cmd = readl(&oxu->regs->command); | ||
1717 | struct ehci_qh *prev; | ||
1718 | |||
1719 | #ifdef DEBUG | ||
1720 | assert_spin_locked(&oxu->lock); | ||
1721 | if (oxu->reclaim || (qh->qh_state != QH_STATE_LINKED | ||
1722 | && qh->qh_state != QH_STATE_UNLINK_WAIT)) | ||
1723 | BUG(); | ||
1724 | #endif | ||
1725 | |||
1726 | /* stop async schedule right now? */ | ||
1727 | if (unlikely(qh == oxu->async)) { | ||
1728 | /* can't get here without STS_ASS set */ | ||
1729 | if (oxu_to_hcd(oxu)->state != HC_STATE_HALT | ||
1730 | && !oxu->reclaim) { | ||
1731 | /* ... and CMD_IAAD clear */ | ||
1732 | writel(cmd & ~CMD_ASE, &oxu->regs->command); | ||
1733 | wmb(); | ||
1734 | /* handshake later, if we need to */ | ||
1735 | timer_action_done(oxu, TIMER_ASYNC_OFF); | ||
1736 | } | ||
1737 | return; | ||
1738 | } | ||
1739 | |||
1740 | qh->qh_state = QH_STATE_UNLINK; | ||
1741 | oxu->reclaim = qh = qh_get(qh); | ||
1742 | |||
1743 | prev = oxu->async; | ||
1744 | while (prev->qh_next.qh != qh) | ||
1745 | prev = prev->qh_next.qh; | ||
1746 | |||
1747 | prev->hw_next = qh->hw_next; | ||
1748 | prev->qh_next = qh->qh_next; | ||
1749 | wmb(); | ||
1750 | |||
1751 | if (unlikely(oxu_to_hcd(oxu)->state == HC_STATE_HALT)) { | ||
1752 | /* if (unlikely(qh->reclaim != 0)) | ||
1753 | * this will recurse, probably not much | ||
1754 | */ | ||
1755 | end_unlink_async(oxu); | ||
1756 | return; | ||
1757 | } | ||
1758 | |||
1759 | oxu->reclaim_ready = 0; | ||
1760 | cmd |= CMD_IAAD; | ||
1761 | writel(cmd, &oxu->regs->command); | ||
1762 | (void) readl(&oxu->regs->command); | ||
1763 | timer_action(oxu, TIMER_IAA_WATCHDOG); | ||
1764 | } | ||
1765 | |||
1766 | static void scan_async(struct oxu_hcd *oxu) | ||
1767 | { | ||
1768 | struct ehci_qh *qh; | ||
1769 | enum ehci_timer_action action = TIMER_IO_WATCHDOG; | ||
1770 | |||
1771 | if (!++(oxu->stamp)) | ||
1772 | oxu->stamp++; | ||
1773 | timer_action_done(oxu, TIMER_ASYNC_SHRINK); | ||
1774 | rescan: | ||
1775 | qh = oxu->async->qh_next.qh; | ||
1776 | if (likely(qh != NULL)) { | ||
1777 | do { | ||
1778 | /* clean any finished work for this qh */ | ||
1779 | if (!list_empty(&qh->qtd_list) | ||
1780 | && qh->stamp != oxu->stamp) { | ||
1781 | int temp; | ||
1782 | |||
1783 | /* unlinks could happen here; completion | ||
1784 | * reporting drops the lock. rescan using | ||
1785 | * the latest schedule, but don't rescan | ||
1786 | * qhs we already finished (no looping). | ||
1787 | */ | ||
1788 | qh = qh_get(qh); | ||
1789 | qh->stamp = oxu->stamp; | ||
1790 | temp = qh_completions(oxu, qh); | ||
1791 | qh_put(qh); | ||
1792 | if (temp != 0) | ||
1793 | goto rescan; | ||
1794 | } | ||
1795 | |||
1796 | /* unlink idle entries, reducing HC PCI usage as well | ||
1797 | * as HCD schedule-scanning costs. delay for any qh | ||
1798 | * we just scanned, there's a not-unusual case that it | ||
1799 | * doesn't stay idle for long. | ||
1800 | * (plus, avoids some kind of re-activation race.) | ||
1801 | */ | ||
1802 | if (list_empty(&qh->qtd_list)) { | ||
1803 | if (qh->stamp == oxu->stamp) | ||
1804 | action = TIMER_ASYNC_SHRINK; | ||
1805 | else if (!oxu->reclaim | ||
1806 | && qh->qh_state == QH_STATE_LINKED) | ||
1807 | start_unlink_async(oxu, qh); | ||
1808 | } | ||
1809 | |||
1810 | qh = qh->qh_next.qh; | ||
1811 | } while (qh); | ||
1812 | } | ||
1813 | if (action == TIMER_ASYNC_SHRINK) | ||
1814 | timer_action(oxu, TIMER_ASYNC_SHRINK); | ||
1815 | } | ||
1816 | |||
1817 | /* | ||
1818 | * periodic_next_shadow - return "next" pointer on shadow list | ||
1819 | * @periodic: host pointer to qh/itd/sitd | ||
1820 | * @tag: hardware tag for type of this record | ||
1821 | */ | ||
1822 | static union ehci_shadow *periodic_next_shadow(union ehci_shadow *periodic, | ||
1823 | __le32 tag) | ||
1824 | { | ||
1825 | switch (tag) { | ||
1826 | default: | ||
1827 | case Q_TYPE_QH: | ||
1828 | return &periodic->qh->qh_next; | ||
1829 | } | ||
1830 | } | ||
1831 | |||
1832 | /* caller must hold oxu->lock */ | ||
1833 | static void periodic_unlink(struct oxu_hcd *oxu, unsigned frame, void *ptr) | ||
1834 | { | ||
1835 | union ehci_shadow *prev_p = &oxu->pshadow[frame]; | ||
1836 | __le32 *hw_p = &oxu->periodic[frame]; | ||
1837 | union ehci_shadow here = *prev_p; | ||
1838 | |||
1839 | /* find predecessor of "ptr"; hw and shadow lists are in sync */ | ||
1840 | while (here.ptr && here.ptr != ptr) { | ||
1841 | prev_p = periodic_next_shadow(prev_p, Q_NEXT_TYPE(*hw_p)); | ||
1842 | hw_p = here.hw_next; | ||
1843 | here = *prev_p; | ||
1844 | } | ||
1845 | /* an interrupt entry (at list end) could have been shared */ | ||
1846 | if (!here.ptr) | ||
1847 | return; | ||
1848 | |||
1849 | /* update shadow and hardware lists ... the old "next" pointers | ||
1850 | * from ptr may still be in use, the caller updates them. | ||
1851 | */ | ||
1852 | *prev_p = *periodic_next_shadow(&here, Q_NEXT_TYPE(*hw_p)); | ||
1853 | *hw_p = *here.hw_next; | ||
1854 | } | ||
1855 | |||
1856 | /* how many of the uframe's 125 usecs are allocated? */ | ||
1857 | static unsigned short periodic_usecs(struct oxu_hcd *oxu, | ||
1858 | unsigned frame, unsigned uframe) | ||
1859 | { | ||
1860 | __le32 *hw_p = &oxu->periodic[frame]; | ||
1861 | union ehci_shadow *q = &oxu->pshadow[frame]; | ||
1862 | unsigned usecs = 0; | ||
1863 | |||
1864 | while (q->ptr) { | ||
1865 | switch (Q_NEXT_TYPE(*hw_p)) { | ||
1866 | case Q_TYPE_QH: | ||
1867 | default: | ||
1868 | /* is it in the S-mask? */ | ||
1869 | if (q->qh->hw_info2 & cpu_to_le32(1 << uframe)) | ||
1870 | usecs += q->qh->usecs; | ||
1871 | /* ... or C-mask? */ | ||
1872 | if (q->qh->hw_info2 & cpu_to_le32(1 << (8 + uframe))) | ||
1873 | usecs += q->qh->c_usecs; | ||
1874 | hw_p = &q->qh->hw_next; | ||
1875 | q = &q->qh->qh_next; | ||
1876 | break; | ||
1877 | } | ||
1878 | } | ||
1879 | #ifdef DEBUG | ||
1880 | if (usecs > 100) | ||
1881 | oxu_err(oxu, "uframe %d sched overrun: %d usecs\n", | ||
1882 | frame * 8 + uframe, usecs); | ||
1883 | #endif | ||
1884 | return usecs; | ||
1885 | } | ||
1886 | |||
1887 | static int enable_periodic(struct oxu_hcd *oxu) | ||
1888 | { | ||
1889 | u32 cmd; | ||
1890 | int status; | ||
1891 | |||
1892 | /* did clearing PSE did take effect yet? | ||
1893 | * takes effect only at frame boundaries... | ||
1894 | */ | ||
1895 | status = handshake(oxu, &oxu->regs->status, STS_PSS, 0, 9 * 125); | ||
1896 | if (status != 0) { | ||
1897 | oxu_to_hcd(oxu)->state = HC_STATE_HALT; | ||
1898 | return status; | ||
1899 | } | ||
1900 | |||
1901 | cmd = readl(&oxu->regs->command) | CMD_PSE; | ||
1902 | writel(cmd, &oxu->regs->command); | ||
1903 | /* posted write ... PSS happens later */ | ||
1904 | oxu_to_hcd(oxu)->state = HC_STATE_RUNNING; | ||
1905 | |||
1906 | /* make sure ehci_work scans these */ | ||
1907 | oxu->next_uframe = readl(&oxu->regs->frame_index) | ||
1908 | % (oxu->periodic_size << 3); | ||
1909 | return 0; | ||
1910 | } | ||
1911 | |||
1912 | static int disable_periodic(struct oxu_hcd *oxu) | ||
1913 | { | ||
1914 | u32 cmd; | ||
1915 | int status; | ||
1916 | |||
1917 | /* did setting PSE not take effect yet? | ||
1918 | * takes effect only at frame boundaries... | ||
1919 | */ | ||
1920 | status = handshake(oxu, &oxu->regs->status, STS_PSS, STS_PSS, 9 * 125); | ||
1921 | if (status != 0) { | ||
1922 | oxu_to_hcd(oxu)->state = HC_STATE_HALT; | ||
1923 | return status; | ||
1924 | } | ||
1925 | |||
1926 | cmd = readl(&oxu->regs->command) & ~CMD_PSE; | ||
1927 | writel(cmd, &oxu->regs->command); | ||
1928 | /* posted write ... */ | ||
1929 | |||
1930 | oxu->next_uframe = -1; | ||
1931 | return 0; | ||
1932 | } | ||
1933 | |||
1934 | /* periodic schedule slots have iso tds (normal or split) first, then a | ||
1935 | * sparse tree for active interrupt transfers. | ||
1936 | * | ||
1937 | * this just links in a qh; caller guarantees uframe masks are set right. | ||
1938 | * no FSTN support (yet; oxu 0.96+) | ||
1939 | */ | ||
1940 | static int qh_link_periodic(struct oxu_hcd *oxu, struct ehci_qh *qh) | ||
1941 | { | ||
1942 | unsigned i; | ||
1943 | unsigned period = qh->period; | ||
1944 | |||
1945 | dev_dbg(&qh->dev->dev, | ||
1946 | "link qh%d-%04x/%p start %d [%d/%d us]\n", | ||
1947 | period, le32_to_cpup(&qh->hw_info2) & (QH_CMASK | QH_SMASK), | ||
1948 | qh, qh->start, qh->usecs, qh->c_usecs); | ||
1949 | |||
1950 | /* high bandwidth, or otherwise every microframe */ | ||
1951 | if (period == 0) | ||
1952 | period = 1; | ||
1953 | |||
1954 | for (i = qh->start; i < oxu->periodic_size; i += period) { | ||
1955 | union ehci_shadow *prev = &oxu->pshadow[i]; | ||
1956 | __le32 *hw_p = &oxu->periodic[i]; | ||
1957 | union ehci_shadow here = *prev; | ||
1958 | __le32 type = 0; | ||
1959 | |||
1960 | /* skip the iso nodes at list head */ | ||
1961 | while (here.ptr) { | ||
1962 | type = Q_NEXT_TYPE(*hw_p); | ||
1963 | if (type == Q_TYPE_QH) | ||
1964 | break; | ||
1965 | prev = periodic_next_shadow(prev, type); | ||
1966 | hw_p = &here.qh->hw_next; | ||
1967 | here = *prev; | ||
1968 | } | ||
1969 | |||
1970 | /* sorting each branch by period (slow-->fast) | ||
1971 | * enables sharing interior tree nodes | ||
1972 | */ | ||
1973 | while (here.ptr && qh != here.qh) { | ||
1974 | if (qh->period > here.qh->period) | ||
1975 | break; | ||
1976 | prev = &here.qh->qh_next; | ||
1977 | hw_p = &here.qh->hw_next; | ||
1978 | here = *prev; | ||
1979 | } | ||
1980 | /* link in this qh, unless some earlier pass did that */ | ||
1981 | if (qh != here.qh) { | ||
1982 | qh->qh_next = here; | ||
1983 | if (here.qh) | ||
1984 | qh->hw_next = *hw_p; | ||
1985 | wmb(); | ||
1986 | prev->qh = qh; | ||
1987 | *hw_p = QH_NEXT(qh->qh_dma); | ||
1988 | } | ||
1989 | } | ||
1990 | qh->qh_state = QH_STATE_LINKED; | ||
1991 | qh_get(qh); | ||
1992 | |||
1993 | /* update per-qh bandwidth for usbfs */ | ||
1994 | oxu_to_hcd(oxu)->self.bandwidth_allocated += qh->period | ||
1995 | ? ((qh->usecs + qh->c_usecs) / qh->period) | ||
1996 | : (qh->usecs * 8); | ||
1997 | |||
1998 | /* maybe enable periodic schedule processing */ | ||
1999 | if (!oxu->periodic_sched++) | ||
2000 | return enable_periodic(oxu); | ||
2001 | |||
2002 | return 0; | ||
2003 | } | ||
2004 | |||
2005 | static void qh_unlink_periodic(struct oxu_hcd *oxu, struct ehci_qh *qh) | ||
2006 | { | ||
2007 | unsigned i; | ||
2008 | unsigned period; | ||
2009 | |||
2010 | /* FIXME: | ||
2011 | * IF this isn't high speed | ||
2012 | * and this qh is active in the current uframe | ||
2013 | * (and overlay token SplitXstate is false?) | ||
2014 | * THEN | ||
2015 | * qh->hw_info1 |= __constant_cpu_to_le32(1 << 7 "ignore"); | ||
2016 | */ | ||
2017 | |||
2018 | /* high bandwidth, or otherwise part of every microframe */ | ||
2019 | period = qh->period; | ||
2020 | if (period == 0) | ||
2021 | period = 1; | ||
2022 | |||
2023 | for (i = qh->start; i < oxu->periodic_size; i += period) | ||
2024 | periodic_unlink(oxu, i, qh); | ||
2025 | |||
2026 | /* update per-qh bandwidth for usbfs */ | ||
2027 | oxu_to_hcd(oxu)->self.bandwidth_allocated -= qh->period | ||
2028 | ? ((qh->usecs + qh->c_usecs) / qh->period) | ||
2029 | : (qh->usecs * 8); | ||
2030 | |||
2031 | dev_dbg(&qh->dev->dev, | ||
2032 | "unlink qh%d-%04x/%p start %d [%d/%d us]\n", | ||
2033 | qh->period, | ||
2034 | le32_to_cpup(&qh->hw_info2) & (QH_CMASK | QH_SMASK), | ||
2035 | qh, qh->start, qh->usecs, qh->c_usecs); | ||
2036 | |||
2037 | /* qh->qh_next still "live" to HC */ | ||
2038 | qh->qh_state = QH_STATE_UNLINK; | ||
2039 | qh->qh_next.ptr = NULL; | ||
2040 | qh_put(qh); | ||
2041 | |||
2042 | /* maybe turn off periodic schedule */ | ||
2043 | oxu->periodic_sched--; | ||
2044 | if (!oxu->periodic_sched) | ||
2045 | (void) disable_periodic(oxu); | ||
2046 | } | ||
2047 | |||
2048 | static void intr_deschedule(struct oxu_hcd *oxu, struct ehci_qh *qh) | ||
2049 | { | ||
2050 | unsigned wait; | ||
2051 | |||
2052 | qh_unlink_periodic(oxu, qh); | ||
2053 | |||
2054 | /* simple/paranoid: always delay, expecting the HC needs to read | ||
2055 | * qh->hw_next or finish a writeback after SPLIT/CSPLIT ... and | ||
2056 | * expect khubd to clean up after any CSPLITs we won't issue. | ||
2057 | * active high speed queues may need bigger delays... | ||
2058 | */ | ||
2059 | if (list_empty(&qh->qtd_list) | ||
2060 | || (__constant_cpu_to_le32(QH_CMASK) & qh->hw_info2) != 0) | ||
2061 | wait = 2; | ||
2062 | else | ||
2063 | wait = 55; /* worst case: 3 * 1024 */ | ||
2064 | |||
2065 | udelay(wait); | ||
2066 | qh->qh_state = QH_STATE_IDLE; | ||
2067 | qh->hw_next = EHCI_LIST_END; | ||
2068 | wmb(); | ||
2069 | } | ||
2070 | |||
2071 | static int check_period(struct oxu_hcd *oxu, | ||
2072 | unsigned frame, unsigned uframe, | ||
2073 | unsigned period, unsigned usecs) | ||
2074 | { | ||
2075 | int claimed; | ||
2076 | |||
2077 | /* complete split running into next frame? | ||
2078 | * given FSTN support, we could sometimes check... | ||
2079 | */ | ||
2080 | if (uframe >= 8) | ||
2081 | return 0; | ||
2082 | |||
2083 | /* | ||
2084 | * 80% periodic == 100 usec/uframe available | ||
2085 | * convert "usecs we need" to "max already claimed" | ||
2086 | */ | ||
2087 | usecs = 100 - usecs; | ||
2088 | |||
2089 | /* we "know" 2 and 4 uframe intervals were rejected; so | ||
2090 | * for period 0, check _every_ microframe in the schedule. | ||
2091 | */ | ||
2092 | if (unlikely(period == 0)) { | ||
2093 | do { | ||
2094 | for (uframe = 0; uframe < 7; uframe++) { | ||
2095 | claimed = periodic_usecs(oxu, frame, uframe); | ||
2096 | if (claimed > usecs) | ||
2097 | return 0; | ||
2098 | } | ||
2099 | } while ((frame += 1) < oxu->periodic_size); | ||
2100 | |||
2101 | /* just check the specified uframe, at that period */ | ||
2102 | } else { | ||
2103 | do { | ||
2104 | claimed = periodic_usecs(oxu, frame, uframe); | ||
2105 | if (claimed > usecs) | ||
2106 | return 0; | ||
2107 | } while ((frame += period) < oxu->periodic_size); | ||
2108 | } | ||
2109 | |||
2110 | return 1; | ||
2111 | } | ||
2112 | |||
2113 | static int check_intr_schedule(struct oxu_hcd *oxu, | ||
2114 | unsigned frame, unsigned uframe, | ||
2115 | const struct ehci_qh *qh, __le32 *c_maskp) | ||
2116 | { | ||
2117 | int retval = -ENOSPC; | ||
2118 | |||
2119 | if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ | ||
2120 | goto done; | ||
2121 | |||
2122 | if (!check_period(oxu, frame, uframe, qh->period, qh->usecs)) | ||
2123 | goto done; | ||
2124 | if (!qh->c_usecs) { | ||
2125 | retval = 0; | ||
2126 | *c_maskp = 0; | ||
2127 | goto done; | ||
2128 | } | ||
2129 | |||
2130 | done: | ||
2131 | return retval; | ||
2132 | } | ||
2133 | |||
2134 | /* "first fit" scheduling policy used the first time through, | ||
2135 | * or when the previous schedule slot can't be re-used. | ||
2136 | */ | ||
2137 | static int qh_schedule(struct oxu_hcd *oxu, struct ehci_qh *qh) | ||
2138 | { | ||
2139 | int status; | ||
2140 | unsigned uframe; | ||
2141 | __le32 c_mask; | ||
2142 | unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ | ||
2143 | |||
2144 | qh_refresh(oxu, qh); | ||
2145 | qh->hw_next = EHCI_LIST_END; | ||
2146 | frame = qh->start; | ||
2147 | |||
2148 | /* reuse the previous schedule slots, if we can */ | ||
2149 | if (frame < qh->period) { | ||
2150 | uframe = ffs(le32_to_cpup(&qh->hw_info2) & QH_SMASK); | ||
2151 | status = check_intr_schedule(oxu, frame, --uframe, | ||
2152 | qh, &c_mask); | ||
2153 | } else { | ||
2154 | uframe = 0; | ||
2155 | c_mask = 0; | ||
2156 | status = -ENOSPC; | ||
2157 | } | ||
2158 | |||
2159 | /* else scan the schedule to find a group of slots such that all | ||
2160 | * uframes have enough periodic bandwidth available. | ||
2161 | */ | ||
2162 | if (status) { | ||
2163 | /* "normal" case, uframing flexible except with splits */ | ||
2164 | if (qh->period) { | ||
2165 | frame = qh->period - 1; | ||
2166 | do { | ||
2167 | for (uframe = 0; uframe < 8; uframe++) { | ||
2168 | status = check_intr_schedule(oxu, | ||
2169 | frame, uframe, qh, | ||
2170 | &c_mask); | ||
2171 | if (status == 0) | ||
2172 | break; | ||
2173 | } | ||
2174 | } while (status && frame--); | ||
2175 | |||
2176 | /* qh->period == 0 means every uframe */ | ||
2177 | } else { | ||
2178 | frame = 0; | ||
2179 | status = check_intr_schedule(oxu, 0, 0, qh, &c_mask); | ||
2180 | } | ||
2181 | if (status) | ||
2182 | goto done; | ||
2183 | qh->start = frame; | ||
2184 | |||
2185 | /* reset S-frame and (maybe) C-frame masks */ | ||
2186 | qh->hw_info2 &= __constant_cpu_to_le32(~(QH_CMASK | QH_SMASK)); | ||
2187 | qh->hw_info2 |= qh->period | ||
2188 | ? cpu_to_le32(1 << uframe) | ||
2189 | : __constant_cpu_to_le32(QH_SMASK); | ||
2190 | qh->hw_info2 |= c_mask; | ||
2191 | } else | ||
2192 | oxu_dbg(oxu, "reused qh %p schedule\n", qh); | ||
2193 | |||
2194 | /* stuff into the periodic schedule */ | ||
2195 | status = qh_link_periodic(oxu, qh); | ||
2196 | done: | ||
2197 | return status; | ||
2198 | } | ||
2199 | |||
2200 | static int intr_submit(struct oxu_hcd *oxu, struct urb *urb, | ||
2201 | struct list_head *qtd_list, gfp_t mem_flags) | ||
2202 | { | ||
2203 | unsigned epnum; | ||
2204 | unsigned long flags; | ||
2205 | struct ehci_qh *qh; | ||
2206 | int status = 0; | ||
2207 | struct list_head empty; | ||
2208 | |||
2209 | /* get endpoint and transfer/schedule data */ | ||
2210 | epnum = urb->ep->desc.bEndpointAddress; | ||
2211 | |||
2212 | spin_lock_irqsave(&oxu->lock, flags); | ||
2213 | |||
2214 | if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, | ||
2215 | &oxu_to_hcd(oxu)->flags))) { | ||
2216 | status = -ESHUTDOWN; | ||
2217 | goto done; | ||
2218 | } | ||
2219 | |||
2220 | /* get qh and force any scheduling errors */ | ||
2221 | INIT_LIST_HEAD(&empty); | ||
2222 | qh = qh_append_tds(oxu, urb, &empty, epnum, &urb->ep->hcpriv); | ||
2223 | if (qh == NULL) { | ||
2224 | status = -ENOMEM; | ||
2225 | goto done; | ||
2226 | } | ||
2227 | if (qh->qh_state == QH_STATE_IDLE) { | ||
2228 | status = qh_schedule(oxu, qh); | ||
2229 | if (status != 0) | ||
2230 | goto done; | ||
2231 | } | ||
2232 | |||
2233 | /* then queue the urb's tds to the qh */ | ||
2234 | qh = qh_append_tds(oxu, urb, qtd_list, epnum, &urb->ep->hcpriv); | ||
2235 | BUG_ON(qh == NULL); | ||
2236 | |||
2237 | /* ... update usbfs periodic stats */ | ||
2238 | oxu_to_hcd(oxu)->self.bandwidth_int_reqs++; | ||
2239 | |||
2240 | done: | ||
2241 | spin_unlock_irqrestore(&oxu->lock, flags); | ||
2242 | if (status) | ||
2243 | qtd_list_free(oxu, urb, qtd_list); | ||
2244 | |||
2245 | return status; | ||
2246 | } | ||
2247 | |||
2248 | static inline int itd_submit(struct oxu_hcd *oxu, struct urb *urb, | ||
2249 | gfp_t mem_flags) | ||
2250 | { | ||
2251 | oxu_dbg(oxu, "iso support is missing!\n"); | ||
2252 | return -ENOSYS; | ||
2253 | } | ||
2254 | |||
2255 | static inline int sitd_submit(struct oxu_hcd *oxu, struct urb *urb, | ||
2256 | gfp_t mem_flags) | ||
2257 | { | ||
2258 | oxu_dbg(oxu, "split iso support is missing!\n"); | ||
2259 | return -ENOSYS; | ||
2260 | } | ||
2261 | |||
2262 | static void scan_periodic(struct oxu_hcd *oxu) | ||
2263 | { | ||
2264 | unsigned frame, clock, now_uframe, mod; | ||
2265 | unsigned modified; | ||
2266 | |||
2267 | mod = oxu->periodic_size << 3; | ||
2268 | |||
2269 | /* | ||
2270 | * When running, scan from last scan point up to "now" | ||
2271 | * else clean up by scanning everything that's left. | ||
2272 | * Touches as few pages as possible: cache-friendly. | ||
2273 | */ | ||
2274 | now_uframe = oxu->next_uframe; | ||
2275 | if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) | ||
2276 | clock = readl(&oxu->regs->frame_index); | ||
2277 | else | ||
2278 | clock = now_uframe + mod - 1; | ||
2279 | clock %= mod; | ||
2280 | |||
2281 | for (;;) { | ||
2282 | union ehci_shadow q, *q_p; | ||
2283 | __le32 type, *hw_p; | ||
2284 | unsigned uframes; | ||
2285 | |||
2286 | /* don't scan past the live uframe */ | ||
2287 | frame = now_uframe >> 3; | ||
2288 | if (frame == (clock >> 3)) | ||
2289 | uframes = now_uframe & 0x07; | ||
2290 | else { | ||
2291 | /* safe to scan the whole frame at once */ | ||
2292 | now_uframe |= 0x07; | ||
2293 | uframes = 8; | ||
2294 | } | ||
2295 | |||
2296 | restart: | ||
2297 | /* scan each element in frame's queue for completions */ | ||
2298 | q_p = &oxu->pshadow[frame]; | ||
2299 | hw_p = &oxu->periodic[frame]; | ||
2300 | q.ptr = q_p->ptr; | ||
2301 | type = Q_NEXT_TYPE(*hw_p); | ||
2302 | modified = 0; | ||
2303 | |||
2304 | while (q.ptr != NULL) { | ||
2305 | union ehci_shadow temp; | ||
2306 | int live; | ||
2307 | |||
2308 | live = HC_IS_RUNNING(oxu_to_hcd(oxu)->state); | ||
2309 | switch (type) { | ||
2310 | case Q_TYPE_QH: | ||
2311 | /* handle any completions */ | ||
2312 | temp.qh = qh_get(q.qh); | ||
2313 | type = Q_NEXT_TYPE(q.qh->hw_next); | ||
2314 | q = q.qh->qh_next; | ||
2315 | modified = qh_completions(oxu, temp.qh); | ||
2316 | if (unlikely(list_empty(&temp.qh->qtd_list))) | ||
2317 | intr_deschedule(oxu, temp.qh); | ||
2318 | qh_put(temp.qh); | ||
2319 | break; | ||
2320 | default: | ||
2321 | dbg("corrupt type %d frame %d shadow %p", | ||
2322 | type, frame, q.ptr); | ||
2323 | q.ptr = NULL; | ||
2324 | } | ||
2325 | |||
2326 | /* assume completion callbacks modify the queue */ | ||
2327 | if (unlikely(modified)) | ||
2328 | goto restart; | ||
2329 | } | ||
2330 | |||
2331 | /* Stop when we catch up to the HC */ | ||
2332 | |||
2333 | /* FIXME: this assumes we won't get lapped when | ||
2334 | * latencies climb; that should be rare, but... | ||
2335 | * detect it, and just go all the way around. | ||
2336 | * FLR might help detect this case, so long as latencies | ||
2337 | * don't exceed periodic_size msec (default 1.024 sec). | ||
2338 | */ | ||
2339 | |||
2340 | /* FIXME: likewise assumes HC doesn't halt mid-scan */ | ||
2341 | |||
2342 | if (now_uframe == clock) { | ||
2343 | unsigned now; | ||
2344 | |||
2345 | if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) | ||
2346 | break; | ||
2347 | oxu->next_uframe = now_uframe; | ||
2348 | now = readl(&oxu->regs->frame_index) % mod; | ||
2349 | if (now_uframe == now) | ||
2350 | break; | ||
2351 | |||
2352 | /* rescan the rest of this frame, then ... */ | ||
2353 | clock = now; | ||
2354 | } else { | ||
2355 | now_uframe++; | ||
2356 | now_uframe %= mod; | ||
2357 | } | ||
2358 | } | ||
2359 | } | ||
2360 | |||
2361 | /* On some systems, leaving remote wakeup enabled prevents system shutdown. | ||
2362 | * The firmware seems to think that powering off is a wakeup event! | ||
2363 | * This routine turns off remote wakeup and everything else, on all ports. | ||
2364 | */ | ||
2365 | static void ehci_turn_off_all_ports(struct oxu_hcd *oxu) | ||
2366 | { | ||
2367 | int port = HCS_N_PORTS(oxu->hcs_params); | ||
2368 | |||
2369 | while (port--) | ||
2370 | writel(PORT_RWC_BITS, &oxu->regs->port_status[port]); | ||
2371 | } | ||
2372 | |||
2373 | static void ehci_port_power(struct oxu_hcd *oxu, int is_on) | ||
2374 | { | ||
2375 | unsigned port; | ||
2376 | |||
2377 | if (!HCS_PPC(oxu->hcs_params)) | ||
2378 | return; | ||
2379 | |||
2380 | oxu_dbg(oxu, "...power%s ports...\n", is_on ? "up" : "down"); | ||
2381 | for (port = HCS_N_PORTS(oxu->hcs_params); port > 0; ) | ||
2382 | (void) oxu_hub_control(oxu_to_hcd(oxu), | ||
2383 | is_on ? SetPortFeature : ClearPortFeature, | ||
2384 | USB_PORT_FEAT_POWER, | ||
2385 | port--, NULL, 0); | ||
2386 | msleep(20); | ||
2387 | } | ||
2388 | |||
2389 | /* Called from some interrupts, timers, and so on. | ||
2390 | * It calls driver completion functions, after dropping oxu->lock. | ||
2391 | */ | ||
2392 | static void ehci_work(struct oxu_hcd *oxu) | ||
2393 | { | ||
2394 | timer_action_done(oxu, TIMER_IO_WATCHDOG); | ||
2395 | if (oxu->reclaim_ready) | ||
2396 | end_unlink_async(oxu); | ||
2397 | |||
2398 | /* another CPU may drop oxu->lock during a schedule scan while | ||
2399 | * it reports urb completions. this flag guards against bogus | ||
2400 | * attempts at re-entrant schedule scanning. | ||
2401 | */ | ||
2402 | if (oxu->scanning) | ||
2403 | return; | ||
2404 | oxu->scanning = 1; | ||
2405 | scan_async(oxu); | ||
2406 | if (oxu->next_uframe != -1) | ||
2407 | scan_periodic(oxu); | ||
2408 | oxu->scanning = 0; | ||
2409 | |||
2410 | /* the IO watchdog guards against hardware or driver bugs that | ||
2411 | * misplace IRQs, and should let us run completely without IRQs. | ||
2412 | * such lossage has been observed on both VT6202 and VT8235. | ||
2413 | */ | ||
2414 | if (HC_IS_RUNNING(oxu_to_hcd(oxu)->state) && | ||
2415 | (oxu->async->qh_next.ptr != NULL || | ||
2416 | oxu->periodic_sched != 0)) | ||
2417 | timer_action(oxu, TIMER_IO_WATCHDOG); | ||
2418 | } | ||
2419 | |||
2420 | static void unlink_async(struct oxu_hcd *oxu, struct ehci_qh *qh) | ||
2421 | { | ||
2422 | /* if we need to use IAA and it's busy, defer */ | ||
2423 | if (qh->qh_state == QH_STATE_LINKED | ||
2424 | && oxu->reclaim | ||
2425 | && HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) { | ||
2426 | struct ehci_qh *last; | ||
2427 | |||
2428 | for (last = oxu->reclaim; | ||
2429 | last->reclaim; | ||
2430 | last = last->reclaim) | ||
2431 | continue; | ||
2432 | qh->qh_state = QH_STATE_UNLINK_WAIT; | ||
2433 | last->reclaim = qh; | ||
2434 | |||
2435 | /* bypass IAA if the hc can't care */ | ||
2436 | } else if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->state) && oxu->reclaim) | ||
2437 | end_unlink_async(oxu); | ||
2438 | |||
2439 | /* something else might have unlinked the qh by now */ | ||
2440 | if (qh->qh_state == QH_STATE_LINKED) | ||
2441 | start_unlink_async(oxu, qh); | ||
2442 | } | ||
2443 | |||
2444 | /* | ||
2445 | * USB host controller methods | ||
2446 | */ | ||
2447 | |||
2448 | static irqreturn_t oxu210_hcd_irq(struct usb_hcd *hcd) | ||
2449 | { | ||
2450 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
2451 | u32 status, pcd_status = 0; | ||
2452 | int bh; | ||
2453 | |||
2454 | spin_lock(&oxu->lock); | ||
2455 | |||
2456 | status = readl(&oxu->regs->status); | ||
2457 | |||
2458 | /* e.g. cardbus physical eject */ | ||
2459 | if (status == ~(u32) 0) { | ||
2460 | oxu_dbg(oxu, "device removed\n"); | ||
2461 | goto dead; | ||
2462 | } | ||
2463 | |||
2464 | status &= INTR_MASK; | ||
2465 | if (!status) { /* irq sharing? */ | ||
2466 | spin_unlock(&oxu->lock); | ||
2467 | return IRQ_NONE; | ||
2468 | } | ||
2469 | |||
2470 | /* clear (just) interrupts */ | ||
2471 | writel(status, &oxu->regs->status); | ||
2472 | readl(&oxu->regs->command); /* unblock posted write */ | ||
2473 | bh = 0; | ||
2474 | |||
2475 | #ifdef OXU_VERBOSE_DEBUG | ||
2476 | /* unrequested/ignored: Frame List Rollover */ | ||
2477 | dbg_status(oxu, "irq", status); | ||
2478 | #endif | ||
2479 | |||
2480 | /* INT, ERR, and IAA interrupt rates can be throttled */ | ||
2481 | |||
2482 | /* normal [4.15.1.2] or error [4.15.1.1] completion */ | ||
2483 | if (likely((status & (STS_INT|STS_ERR)) != 0)) | ||
2484 | bh = 1; | ||
2485 | |||
2486 | /* complete the unlinking of some qh [4.15.2.3] */ | ||
2487 | if (status & STS_IAA) { | ||
2488 | oxu->reclaim_ready = 1; | ||
2489 | bh = 1; | ||
2490 | } | ||
2491 | |||
2492 | /* remote wakeup [4.3.1] */ | ||
2493 | if (status & STS_PCD) { | ||
2494 | unsigned i = HCS_N_PORTS(oxu->hcs_params); | ||
2495 | pcd_status = status; | ||
2496 | |||
2497 | /* resume root hub? */ | ||
2498 | if (!(readl(&oxu->regs->command) & CMD_RUN)) | ||
2499 | usb_hcd_resume_root_hub(hcd); | ||
2500 | |||
2501 | while (i--) { | ||
2502 | int pstatus = readl(&oxu->regs->port_status[i]); | ||
2503 | |||
2504 | if (pstatus & PORT_OWNER) | ||
2505 | continue; | ||
2506 | if (!(pstatus & PORT_RESUME) | ||
2507 | || oxu->reset_done[i] != 0) | ||
2508 | continue; | ||
2509 | |||
2510 | /* start 20 msec resume signaling from this port, | ||
2511 | * and make khubd collect PORT_STAT_C_SUSPEND to | ||
2512 | * stop that signaling. | ||
2513 | */ | ||
2514 | oxu->reset_done[i] = jiffies + msecs_to_jiffies(20); | ||
2515 | oxu_dbg(oxu, "port %d remote wakeup\n", i + 1); | ||
2516 | mod_timer(&hcd->rh_timer, oxu->reset_done[i]); | ||
2517 | } | ||
2518 | } | ||
2519 | |||
2520 | /* PCI errors [4.15.2.4] */ | ||
2521 | if (unlikely((status & STS_FATAL) != 0)) { | ||
2522 | /* bogus "fatal" IRQs appear on some chips... why? */ | ||
2523 | status = readl(&oxu->regs->status); | ||
2524 | dbg_cmd(oxu, "fatal", readl(&oxu->regs->command)); | ||
2525 | dbg_status(oxu, "fatal", status); | ||
2526 | if (status & STS_HALT) { | ||
2527 | oxu_err(oxu, "fatal error\n"); | ||
2528 | dead: | ||
2529 | ehci_reset(oxu); | ||
2530 | writel(0, &oxu->regs->configured_flag); | ||
2531 | /* generic layer kills/unlinks all urbs, then | ||
2532 | * uses oxu_stop to clean up the rest | ||
2533 | */ | ||
2534 | bh = 1; | ||
2535 | } | ||
2536 | } | ||
2537 | |||
2538 | if (bh) | ||
2539 | ehci_work(oxu); | ||
2540 | spin_unlock(&oxu->lock); | ||
2541 | if (pcd_status & STS_PCD) | ||
2542 | usb_hcd_poll_rh_status(hcd); | ||
2543 | return IRQ_HANDLED; | ||
2544 | } | ||
2545 | |||
2546 | static irqreturn_t oxu_irq(struct usb_hcd *hcd) | ||
2547 | { | ||
2548 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
2549 | int ret = IRQ_HANDLED; | ||
2550 | |||
2551 | u32 status = oxu_readl(hcd->regs, OXU_CHIPIRQSTATUS); | ||
2552 | u32 enable = oxu_readl(hcd->regs, OXU_CHIPIRQEN_SET); | ||
2553 | |||
2554 | /* Disable all interrupt */ | ||
2555 | oxu_writel(hcd->regs, OXU_CHIPIRQEN_CLR, enable); | ||
2556 | |||
2557 | if ((oxu->is_otg && (status & OXU_USBOTGI)) || | ||
2558 | (!oxu->is_otg && (status & OXU_USBSPHI))) | ||
2559 | oxu210_hcd_irq(hcd); | ||
2560 | else | ||
2561 | ret = IRQ_NONE; | ||
2562 | |||
2563 | /* Enable all interrupt back */ | ||
2564 | oxu_writel(hcd->regs, OXU_CHIPIRQEN_SET, enable); | ||
2565 | |||
2566 | return ret; | ||
2567 | } | ||
2568 | |||
2569 | static void oxu_watchdog(unsigned long param) | ||
2570 | { | ||
2571 | struct oxu_hcd *oxu = (struct oxu_hcd *) param; | ||
2572 | unsigned long flags; | ||
2573 | |||
2574 | spin_lock_irqsave(&oxu->lock, flags); | ||
2575 | |||
2576 | /* lost IAA irqs wedge things badly; seen with a vt8235 */ | ||
2577 | if (oxu->reclaim) { | ||
2578 | u32 status = readl(&oxu->regs->status); | ||
2579 | if (status & STS_IAA) { | ||
2580 | oxu_vdbg(oxu, "lost IAA\n"); | ||
2581 | writel(STS_IAA, &oxu->regs->status); | ||
2582 | oxu->reclaim_ready = 1; | ||
2583 | } | ||
2584 | } | ||
2585 | |||
2586 | /* stop async processing after it's idled a bit */ | ||
2587 | if (test_bit(TIMER_ASYNC_OFF, &oxu->actions)) | ||
2588 | start_unlink_async(oxu, oxu->async); | ||
2589 | |||
2590 | /* oxu could run by timer, without IRQs ... */ | ||
2591 | ehci_work(oxu); | ||
2592 | |||
2593 | spin_unlock_irqrestore(&oxu->lock, flags); | ||
2594 | } | ||
2595 | |||
2596 | /* One-time init, only for memory state. | ||
2597 | */ | ||
2598 | static int oxu_hcd_init(struct usb_hcd *hcd) | ||
2599 | { | ||
2600 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
2601 | u32 temp; | ||
2602 | int retval; | ||
2603 | u32 hcc_params; | ||
2604 | |||
2605 | spin_lock_init(&oxu->lock); | ||
2606 | |||
2607 | init_timer(&oxu->watchdog); | ||
2608 | oxu->watchdog.function = oxu_watchdog; | ||
2609 | oxu->watchdog.data = (unsigned long) oxu; | ||
2610 | |||
2611 | /* | ||
2612 | * hw default: 1K periodic list heads, one per frame. | ||
2613 | * periodic_size can shrink by USBCMD update if hcc_params allows. | ||
2614 | */ | ||
2615 | oxu->periodic_size = DEFAULT_I_TDPS; | ||
2616 | retval = ehci_mem_init(oxu, GFP_KERNEL); | ||
2617 | if (retval < 0) | ||
2618 | return retval; | ||
2619 | |||
2620 | /* controllers may cache some of the periodic schedule ... */ | ||
2621 | hcc_params = readl(&oxu->caps->hcc_params); | ||
2622 | if (HCC_ISOC_CACHE(hcc_params)) /* full frame cache */ | ||
2623 | oxu->i_thresh = 8; | ||
2624 | else /* N microframes cached */ | ||
2625 | oxu->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); | ||
2626 | |||
2627 | oxu->reclaim = NULL; | ||
2628 | oxu->reclaim_ready = 0; | ||
2629 | oxu->next_uframe = -1; | ||
2630 | |||
2631 | /* | ||
2632 | * dedicate a qh for the async ring head, since we couldn't unlink | ||
2633 | * a 'real' qh without stopping the async schedule [4.8]. use it | ||
2634 | * as the 'reclamation list head' too. | ||
2635 | * its dummy is used in hw_alt_next of many tds, to prevent the qh | ||
2636 | * from automatically advancing to the next td after short reads. | ||
2637 | */ | ||
2638 | oxu->async->qh_next.qh = NULL; | ||
2639 | oxu->async->hw_next = QH_NEXT(oxu->async->qh_dma); | ||
2640 | oxu->async->hw_info1 = cpu_to_le32(QH_HEAD); | ||
2641 | oxu->async->hw_token = cpu_to_le32(QTD_STS_HALT); | ||
2642 | oxu->async->hw_qtd_next = EHCI_LIST_END; | ||
2643 | oxu->async->qh_state = QH_STATE_LINKED; | ||
2644 | oxu->async->hw_alt_next = QTD_NEXT(oxu->async->dummy->qtd_dma); | ||
2645 | |||
2646 | /* clear interrupt enables, set irq latency */ | ||
2647 | if (log2_irq_thresh < 0 || log2_irq_thresh > 6) | ||
2648 | log2_irq_thresh = 0; | ||
2649 | temp = 1 << (16 + log2_irq_thresh); | ||
2650 | if (HCC_CANPARK(hcc_params)) { | ||
2651 | /* HW default park == 3, on hardware that supports it (like | ||
2652 | * NVidia and ALI silicon), maximizes throughput on the async | ||
2653 | * schedule by avoiding QH fetches between transfers. | ||
2654 | * | ||
2655 | * With fast usb storage devices and NForce2, "park" seems to | ||
2656 | * make problems: throughput reduction (!), data errors... | ||
2657 | */ | ||
2658 | if (park) { | ||
2659 | park = min(park, (unsigned) 3); | ||
2660 | temp |= CMD_PARK; | ||
2661 | temp |= park << 8; | ||
2662 | } | ||
2663 | oxu_dbg(oxu, "park %d\n", park); | ||
2664 | } | ||
2665 | if (HCC_PGM_FRAMELISTLEN(hcc_params)) { | ||
2666 | /* periodic schedule size can be smaller than default */ | ||
2667 | temp &= ~(3 << 2); | ||
2668 | temp |= (EHCI_TUNE_FLS << 2); | ||
2669 | } | ||
2670 | oxu->command = temp; | ||
2671 | |||
2672 | return 0; | ||
2673 | } | ||
2674 | |||
2675 | /* Called during probe() after chip reset completes. | ||
2676 | */ | ||
2677 | static int oxu_reset(struct usb_hcd *hcd) | ||
2678 | { | ||
2679 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
2680 | int ret; | ||
2681 | |||
2682 | spin_lock_init(&oxu->mem_lock); | ||
2683 | INIT_LIST_HEAD(&oxu->urb_list); | ||
2684 | oxu->urb_len = 0; | ||
2685 | |||
2686 | /* FIMXE */ | ||
2687 | hcd->self.controller->dma_mask = 0UL; | ||
2688 | |||
2689 | if (oxu->is_otg) { | ||
2690 | oxu->caps = hcd->regs + OXU_OTG_CAP_OFFSET; | ||
2691 | oxu->regs = hcd->regs + OXU_OTG_CAP_OFFSET + \ | ||
2692 | HC_LENGTH(readl(&oxu->caps->hc_capbase)); | ||
2693 | |||
2694 | oxu->mem = hcd->regs + OXU_SPH_MEM; | ||
2695 | } else { | ||
2696 | oxu->caps = hcd->regs + OXU_SPH_CAP_OFFSET; | ||
2697 | oxu->regs = hcd->regs + OXU_SPH_CAP_OFFSET + \ | ||
2698 | HC_LENGTH(readl(&oxu->caps->hc_capbase)); | ||
2699 | |||
2700 | oxu->mem = hcd->regs + OXU_OTG_MEM; | ||
2701 | } | ||
2702 | |||
2703 | oxu->hcs_params = readl(&oxu->caps->hcs_params); | ||
2704 | oxu->sbrn = 0x20; | ||
2705 | |||
2706 | ret = oxu_hcd_init(hcd); | ||
2707 | if (ret) | ||
2708 | return ret; | ||
2709 | |||
2710 | return 0; | ||
2711 | } | ||
2712 | |||
2713 | static int oxu_run(struct usb_hcd *hcd) | ||
2714 | { | ||
2715 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
2716 | int retval; | ||
2717 | u32 temp, hcc_params; | ||
2718 | |||
2719 | hcd->uses_new_polling = 1; | ||
2720 | hcd->poll_rh = 0; | ||
2721 | |||
2722 | /* EHCI spec section 4.1 */ | ||
2723 | retval = ehci_reset(oxu); | ||
2724 | if (retval != 0) { | ||
2725 | ehci_mem_cleanup(oxu); | ||
2726 | return retval; | ||
2727 | } | ||
2728 | writel(oxu->periodic_dma, &oxu->regs->frame_list); | ||
2729 | writel((u32) oxu->async->qh_dma, &oxu->regs->async_next); | ||
2730 | |||
2731 | /* hcc_params controls whether oxu->regs->segment must (!!!) | ||
2732 | * be used; it constrains QH/ITD/SITD and QTD locations. | ||
2733 | * pci_pool consistent memory always uses segment zero. | ||
2734 | * streaming mappings for I/O buffers, like pci_map_single(), | ||
2735 | * can return segments above 4GB, if the device allows. | ||
2736 | * | ||
2737 | * NOTE: the dma mask is visible through dma_supported(), so | ||
2738 | * drivers can pass this info along ... like NETIF_F_HIGHDMA, | ||
2739 | * Scsi_Host.highmem_io, and so forth. It's readonly to all | ||
2740 | * host side drivers though. | ||
2741 | */ | ||
2742 | hcc_params = readl(&oxu->caps->hcc_params); | ||
2743 | if (HCC_64BIT_ADDR(hcc_params)) | ||
2744 | writel(0, &oxu->regs->segment); | ||
2745 | |||
2746 | oxu->command &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE | | ||
2747 | CMD_ASE | CMD_RESET); | ||
2748 | oxu->command |= CMD_RUN; | ||
2749 | writel(oxu->command, &oxu->regs->command); | ||
2750 | dbg_cmd(oxu, "init", oxu->command); | ||
2751 | |||
2752 | /* | ||
2753 | * Start, enabling full USB 2.0 functionality ... usb 1.1 devices | ||
2754 | * are explicitly handed to companion controller(s), so no TT is | ||
2755 | * involved with the root hub. (Except where one is integrated, | ||
2756 | * and there's no companion controller unless maybe for USB OTG.) | ||
2757 | */ | ||
2758 | hcd->state = HC_STATE_RUNNING; | ||
2759 | writel(FLAG_CF, &oxu->regs->configured_flag); | ||
2760 | readl(&oxu->regs->command); /* unblock posted writes */ | ||
2761 | |||
2762 | temp = HC_VERSION(readl(&oxu->caps->hc_capbase)); | ||
2763 | oxu_info(oxu, "USB %x.%x started, quasi-EHCI %x.%02x, driver %s%s\n", | ||
2764 | ((oxu->sbrn & 0xf0)>>4), (oxu->sbrn & 0x0f), | ||
2765 | temp >> 8, temp & 0xff, DRIVER_VERSION, | ||
2766 | ignore_oc ? ", overcurrent ignored" : ""); | ||
2767 | |||
2768 | writel(INTR_MASK, &oxu->regs->intr_enable); /* Turn On Interrupts */ | ||
2769 | |||
2770 | return 0; | ||
2771 | } | ||
2772 | |||
2773 | static void oxu_stop(struct usb_hcd *hcd) | ||
2774 | { | ||
2775 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
2776 | |||
2777 | /* Turn off port power on all root hub ports. */ | ||
2778 | ehci_port_power(oxu, 0); | ||
2779 | |||
2780 | /* no more interrupts ... */ | ||
2781 | del_timer_sync(&oxu->watchdog); | ||
2782 | |||
2783 | spin_lock_irq(&oxu->lock); | ||
2784 | if (HC_IS_RUNNING(hcd->state)) | ||
2785 | ehci_quiesce(oxu); | ||
2786 | |||
2787 | ehci_reset(oxu); | ||
2788 | writel(0, &oxu->regs->intr_enable); | ||
2789 | spin_unlock_irq(&oxu->lock); | ||
2790 | |||
2791 | /* let companion controllers work when we aren't */ | ||
2792 | writel(0, &oxu->regs->configured_flag); | ||
2793 | |||
2794 | /* root hub is shut down separately (first, when possible) */ | ||
2795 | spin_lock_irq(&oxu->lock); | ||
2796 | if (oxu->async) | ||
2797 | ehci_work(oxu); | ||
2798 | spin_unlock_irq(&oxu->lock); | ||
2799 | ehci_mem_cleanup(oxu); | ||
2800 | |||
2801 | dbg_status(oxu, "oxu_stop completed", readl(&oxu->regs->status)); | ||
2802 | } | ||
2803 | |||
2804 | /* Kick in for silicon on any bus (not just pci, etc). | ||
2805 | * This forcibly disables dma and IRQs, helping kexec and other cases | ||
2806 | * where the next system software may expect clean state. | ||
2807 | */ | ||
2808 | static void oxu_shutdown(struct usb_hcd *hcd) | ||
2809 | { | ||
2810 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
2811 | |||
2812 | (void) ehci_halt(oxu); | ||
2813 | ehci_turn_off_all_ports(oxu); | ||
2814 | |||
2815 | /* make BIOS/etc use companion controller during reboot */ | ||
2816 | writel(0, &oxu->regs->configured_flag); | ||
2817 | |||
2818 | /* unblock posted writes */ | ||
2819 | readl(&oxu->regs->configured_flag); | ||
2820 | } | ||
2821 | |||
2822 | /* Non-error returns are a promise to giveback() the urb later | ||
2823 | * we drop ownership so next owner (or urb unlink) can get it | ||
2824 | * | ||
2825 | * urb + dev is in hcd.self.controller.urb_list | ||
2826 | * we're queueing TDs onto software and hardware lists | ||
2827 | * | ||
2828 | * hcd-specific init for hcpriv hasn't been done yet | ||
2829 | * | ||
2830 | * NOTE: control, bulk, and interrupt share the same code to append TDs | ||
2831 | * to a (possibly active) QH, and the same QH scanning code. | ||
2832 | */ | ||
2833 | static int __oxu_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, | ||
2834 | gfp_t mem_flags) | ||
2835 | { | ||
2836 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
2837 | struct list_head qtd_list; | ||
2838 | |||
2839 | INIT_LIST_HEAD(&qtd_list); | ||
2840 | |||
2841 | switch (usb_pipetype(urb->pipe)) { | ||
2842 | case PIPE_CONTROL: | ||
2843 | case PIPE_BULK: | ||
2844 | default: | ||
2845 | if (!qh_urb_transaction(oxu, urb, &qtd_list, mem_flags)) | ||
2846 | return -ENOMEM; | ||
2847 | return submit_async(oxu, urb, &qtd_list, mem_flags); | ||
2848 | |||
2849 | case PIPE_INTERRUPT: | ||
2850 | if (!qh_urb_transaction(oxu, urb, &qtd_list, mem_flags)) | ||
2851 | return -ENOMEM; | ||
2852 | return intr_submit(oxu, urb, &qtd_list, mem_flags); | ||
2853 | |||
2854 | case PIPE_ISOCHRONOUS: | ||
2855 | if (urb->dev->speed == USB_SPEED_HIGH) | ||
2856 | return itd_submit(oxu, urb, mem_flags); | ||
2857 | else | ||
2858 | return sitd_submit(oxu, urb, mem_flags); | ||
2859 | } | ||
2860 | } | ||
2861 | |||
2862 | /* This function is responsible for breaking URBs with big data size | ||
2863 | * into smaller size and processing small urbs in sequence. | ||
2864 | */ | ||
2865 | static int oxu_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, | ||
2866 | gfp_t mem_flags) | ||
2867 | { | ||
2868 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
2869 | int num, rem; | ||
2870 | int transfer_buffer_length; | ||
2871 | void *transfer_buffer; | ||
2872 | struct urb *murb; | ||
2873 | int i, ret; | ||
2874 | |||
2875 | /* If not bulk pipe just enqueue the URB */ | ||
2876 | if (!usb_pipebulk(urb->pipe)) | ||
2877 | return __oxu_urb_enqueue(hcd, urb, mem_flags); | ||
2878 | |||
2879 | /* Otherwise we should verify the USB transfer buffer size! */ | ||
2880 | transfer_buffer = urb->transfer_buffer; | ||
2881 | transfer_buffer_length = urb->transfer_buffer_length; | ||
2882 | |||
2883 | num = urb->transfer_buffer_length / 4096; | ||
2884 | rem = urb->transfer_buffer_length % 4096; | ||
2885 | if (rem != 0) | ||
2886 | num++; | ||
2887 | |||
2888 | /* If URB is smaller than 4096 bytes just enqueue it! */ | ||
2889 | if (num == 1) | ||
2890 | return __oxu_urb_enqueue(hcd, urb, mem_flags); | ||
2891 | |||
2892 | /* Ok, we have more job to do! :) */ | ||
2893 | |||
2894 | for (i = 0; i < num - 1; i++) { | ||
2895 | /* Get free micro URB poll till a free urb is recieved */ | ||
2896 | |||
2897 | do { | ||
2898 | murb = (struct urb *) oxu_murb_alloc(oxu); | ||
2899 | if (!murb) | ||
2900 | schedule(); | ||
2901 | } while (!murb); | ||
2902 | |||
2903 | /* Coping the urb */ | ||
2904 | memcpy(murb, urb, sizeof(struct urb)); | ||
2905 | |||
2906 | murb->transfer_buffer_length = 4096; | ||
2907 | murb->transfer_buffer = transfer_buffer + i * 4096; | ||
2908 | |||
2909 | /* Null pointer for the encodes that this is a micro urb */ | ||
2910 | murb->complete = NULL; | ||
2911 | |||
2912 | ((struct oxu_murb *) murb)->main = urb; | ||
2913 | ((struct oxu_murb *) murb)->last = 0; | ||
2914 | |||
2915 | /* This loop is to guarantee urb to be processed when there's | ||
2916 | * not enough resources at a particular time by retrying. | ||
2917 | */ | ||
2918 | do { | ||
2919 | ret = __oxu_urb_enqueue(hcd, murb, mem_flags); | ||
2920 | if (ret) | ||
2921 | schedule(); | ||
2922 | } while (ret); | ||
2923 | } | ||
2924 | |||
2925 | /* Last urb requires special handling */ | ||
2926 | |||
2927 | /* Get free micro URB poll till a free urb is recieved */ | ||
2928 | do { | ||
2929 | murb = (struct urb *) oxu_murb_alloc(oxu); | ||
2930 | if (!murb) | ||
2931 | schedule(); | ||
2932 | } while (!murb); | ||
2933 | |||
2934 | /* Coping the urb */ | ||
2935 | memcpy(murb, urb, sizeof(struct urb)); | ||
2936 | |||
2937 | murb->transfer_buffer_length = rem > 0 ? rem : 4096; | ||
2938 | murb->transfer_buffer = transfer_buffer + (num - 1) * 4096; | ||
2939 | |||
2940 | /* Null pointer for the encodes that this is a micro urb */ | ||
2941 | murb->complete = NULL; | ||
2942 | |||
2943 | ((struct oxu_murb *) murb)->main = urb; | ||
2944 | ((struct oxu_murb *) murb)->last = 1; | ||
2945 | |||
2946 | do { | ||
2947 | ret = __oxu_urb_enqueue(hcd, murb, mem_flags); | ||
2948 | if (ret) | ||
2949 | schedule(); | ||
2950 | } while (ret); | ||
2951 | |||
2952 | return ret; | ||
2953 | } | ||
2954 | |||
2955 | /* Remove from hardware lists. | ||
2956 | * Completions normally happen asynchronously | ||
2957 | */ | ||
2958 | static int oxu_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | ||
2959 | { | ||
2960 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
2961 | struct ehci_qh *qh; | ||
2962 | unsigned long flags; | ||
2963 | |||
2964 | spin_lock_irqsave(&oxu->lock, flags); | ||
2965 | switch (usb_pipetype(urb->pipe)) { | ||
2966 | case PIPE_CONTROL: | ||
2967 | case PIPE_BULK: | ||
2968 | default: | ||
2969 | qh = (struct ehci_qh *) urb->hcpriv; | ||
2970 | if (!qh) | ||
2971 | break; | ||
2972 | unlink_async(oxu, qh); | ||
2973 | break; | ||
2974 | |||
2975 | case PIPE_INTERRUPT: | ||
2976 | qh = (struct ehci_qh *) urb->hcpriv; | ||
2977 | if (!qh) | ||
2978 | break; | ||
2979 | switch (qh->qh_state) { | ||
2980 | case QH_STATE_LINKED: | ||
2981 | intr_deschedule(oxu, qh); | ||
2982 | /* FALL THROUGH */ | ||
2983 | case QH_STATE_IDLE: | ||
2984 | qh_completions(oxu, qh); | ||
2985 | break; | ||
2986 | default: | ||
2987 | oxu_dbg(oxu, "bogus qh %p state %d\n", | ||
2988 | qh, qh->qh_state); | ||
2989 | goto done; | ||
2990 | } | ||
2991 | |||
2992 | /* reschedule QH iff another request is queued */ | ||
2993 | if (!list_empty(&qh->qtd_list) | ||
2994 | && HC_IS_RUNNING(hcd->state)) { | ||
2995 | int status; | ||
2996 | |||
2997 | status = qh_schedule(oxu, qh); | ||
2998 | spin_unlock_irqrestore(&oxu->lock, flags); | ||
2999 | |||
3000 | if (status != 0) { | ||
3001 | /* shouldn't happen often, but ... | ||
3002 | * FIXME kill those tds' urbs | ||
3003 | */ | ||
3004 | err("can't reschedule qh %p, err %d", | ||
3005 | qh, status); | ||
3006 | } | ||
3007 | return status; | ||
3008 | } | ||
3009 | break; | ||
3010 | } | ||
3011 | done: | ||
3012 | spin_unlock_irqrestore(&oxu->lock, flags); | ||
3013 | return 0; | ||
3014 | } | ||
3015 | |||
3016 | /* Bulk qh holds the data toggle */ | ||
3017 | static void oxu_endpoint_disable(struct usb_hcd *hcd, | ||
3018 | struct usb_host_endpoint *ep) | ||
3019 | { | ||
3020 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
3021 | unsigned long flags; | ||
3022 | struct ehci_qh *qh, *tmp; | ||
3023 | |||
3024 | /* ASSERT: any requests/urbs are being unlinked */ | ||
3025 | /* ASSERT: nobody can be submitting urbs for this any more */ | ||
3026 | |||
3027 | rescan: | ||
3028 | spin_lock_irqsave(&oxu->lock, flags); | ||
3029 | qh = ep->hcpriv; | ||
3030 | if (!qh) | ||
3031 | goto done; | ||
3032 | |||
3033 | /* endpoints can be iso streams. for now, we don't | ||
3034 | * accelerate iso completions ... so spin a while. | ||
3035 | */ | ||
3036 | if (qh->hw_info1 == 0) { | ||
3037 | oxu_vdbg(oxu, "iso delay\n"); | ||
3038 | goto idle_timeout; | ||
3039 | } | ||
3040 | |||
3041 | if (!HC_IS_RUNNING(hcd->state)) | ||
3042 | qh->qh_state = QH_STATE_IDLE; | ||
3043 | switch (qh->qh_state) { | ||
3044 | case QH_STATE_LINKED: | ||
3045 | for (tmp = oxu->async->qh_next.qh; | ||
3046 | tmp && tmp != qh; | ||
3047 | tmp = tmp->qh_next.qh) | ||
3048 | continue; | ||
3049 | /* periodic qh self-unlinks on empty */ | ||
3050 | if (!tmp) | ||
3051 | goto nogood; | ||
3052 | unlink_async(oxu, qh); | ||
3053 | /* FALL THROUGH */ | ||
3054 | case QH_STATE_UNLINK: /* wait for hw to finish? */ | ||
3055 | idle_timeout: | ||
3056 | spin_unlock_irqrestore(&oxu->lock, flags); | ||
3057 | schedule_timeout_uninterruptible(1); | ||
3058 | goto rescan; | ||
3059 | case QH_STATE_IDLE: /* fully unlinked */ | ||
3060 | if (list_empty(&qh->qtd_list)) { | ||
3061 | qh_put(qh); | ||
3062 | break; | ||
3063 | } | ||
3064 | /* else FALL THROUGH */ | ||
3065 | default: | ||
3066 | nogood: | ||
3067 | /* caller was supposed to have unlinked any requests; | ||
3068 | * that's not our job. just leak this memory. | ||
3069 | */ | ||
3070 | oxu_err(oxu, "qh %p (#%02x) state %d%s\n", | ||
3071 | qh, ep->desc.bEndpointAddress, qh->qh_state, | ||
3072 | list_empty(&qh->qtd_list) ? "" : "(has tds)"); | ||
3073 | break; | ||
3074 | } | ||
3075 | ep->hcpriv = NULL; | ||
3076 | done: | ||
3077 | spin_unlock_irqrestore(&oxu->lock, flags); | ||
3078 | return; | ||
3079 | } | ||
3080 | |||
3081 | static int oxu_get_frame(struct usb_hcd *hcd) | ||
3082 | { | ||
3083 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
3084 | |||
3085 | return (readl(&oxu->regs->frame_index) >> 3) % | ||
3086 | oxu->periodic_size; | ||
3087 | } | ||
3088 | |||
3089 | /* Build "status change" packet (one or two bytes) from HC registers */ | ||
3090 | static int oxu_hub_status_data(struct usb_hcd *hcd, char *buf) | ||
3091 | { | ||
3092 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
3093 | u32 temp, mask, status = 0; | ||
3094 | int ports, i, retval = 1; | ||
3095 | unsigned long flags; | ||
3096 | |||
3097 | /* if !USB_SUSPEND, root hub timers won't get shut down ... */ | ||
3098 | if (!HC_IS_RUNNING(hcd->state)) | ||
3099 | return 0; | ||
3100 | |||
3101 | /* init status to no-changes */ | ||
3102 | buf[0] = 0; | ||
3103 | ports = HCS_N_PORTS(oxu->hcs_params); | ||
3104 | if (ports > 7) { | ||
3105 | buf[1] = 0; | ||
3106 | retval++; | ||
3107 | } | ||
3108 | |||
3109 | /* Some boards (mostly VIA?) report bogus overcurrent indications, | ||
3110 | * causing massive log spam unless we completely ignore them. It | ||
3111 | * may be relevant that VIA VT8235 controlers, where PORT_POWER is | ||
3112 | * always set, seem to clear PORT_OCC and PORT_CSC when writing to | ||
3113 | * PORT_POWER; that's surprising, but maybe within-spec. | ||
3114 | */ | ||
3115 | if (!ignore_oc) | ||
3116 | mask = PORT_CSC | PORT_PEC | PORT_OCC; | ||
3117 | else | ||
3118 | mask = PORT_CSC | PORT_PEC; | ||
3119 | |||
3120 | /* no hub change reports (bit 0) for now (power, ...) */ | ||
3121 | |||
3122 | /* port N changes (bit N)? */ | ||
3123 | spin_lock_irqsave(&oxu->lock, flags); | ||
3124 | for (i = 0; i < ports; i++) { | ||
3125 | temp = readl(&oxu->regs->port_status[i]); | ||
3126 | |||
3127 | /* | ||
3128 | * Return status information even for ports with OWNER set. | ||
3129 | * Otherwise khubd wouldn't see the disconnect event when a | ||
3130 | * high-speed device is switched over to the companion | ||
3131 | * controller by the user. | ||
3132 | */ | ||
3133 | |||
3134 | if (!(temp & PORT_CONNECT)) | ||
3135 | oxu->reset_done[i] = 0; | ||
3136 | if ((temp & mask) != 0 || ((temp & PORT_RESUME) != 0 && | ||
3137 | time_after_eq(jiffies, oxu->reset_done[i]))) { | ||
3138 | if (i < 7) | ||
3139 | buf[0] |= 1 << (i + 1); | ||
3140 | else | ||
3141 | buf[1] |= 1 << (i - 7); | ||
3142 | status = STS_PCD; | ||
3143 | } | ||
3144 | } | ||
3145 | /* FIXME autosuspend idle root hubs */ | ||
3146 | spin_unlock_irqrestore(&oxu->lock, flags); | ||
3147 | return status ? retval : 0; | ||
3148 | } | ||
3149 | |||
3150 | /* Returns the speed of a device attached to a port on the root hub. */ | ||
3151 | static inline unsigned int oxu_port_speed(struct oxu_hcd *oxu, | ||
3152 | unsigned int portsc) | ||
3153 | { | ||
3154 | switch ((portsc >> 26) & 3) { | ||
3155 | case 0: | ||
3156 | return 0; | ||
3157 | case 1: | ||
3158 | return 1 << USB_PORT_FEAT_LOWSPEED; | ||
3159 | case 2: | ||
3160 | default: | ||
3161 | return 1 << USB_PORT_FEAT_HIGHSPEED; | ||
3162 | } | ||
3163 | } | ||
3164 | |||
3165 | #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) | ||
3166 | static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq, | ||
3167 | u16 wValue, u16 wIndex, char *buf, u16 wLength) | ||
3168 | { | ||
3169 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
3170 | int ports = HCS_N_PORTS(oxu->hcs_params); | ||
3171 | u32 __iomem *status_reg = &oxu->regs->port_status[wIndex - 1]; | ||
3172 | u32 temp, status; | ||
3173 | unsigned long flags; | ||
3174 | int retval = 0; | ||
3175 | unsigned selector; | ||
3176 | |||
3177 | /* | ||
3178 | * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR. | ||
3179 | * HCS_INDICATOR may say we can change LEDs to off/amber/green. | ||
3180 | * (track current state ourselves) ... blink for diagnostics, | ||
3181 | * power, "this is the one", etc. EHCI spec supports this. | ||
3182 | */ | ||
3183 | |||
3184 | spin_lock_irqsave(&oxu->lock, flags); | ||
3185 | switch (typeReq) { | ||
3186 | case ClearHubFeature: | ||
3187 | switch (wValue) { | ||
3188 | case C_HUB_LOCAL_POWER: | ||
3189 | case C_HUB_OVER_CURRENT: | ||
3190 | /* no hub-wide feature/status flags */ | ||
3191 | break; | ||
3192 | default: | ||
3193 | goto error; | ||
3194 | } | ||
3195 | break; | ||
3196 | case ClearPortFeature: | ||
3197 | if (!wIndex || wIndex > ports) | ||
3198 | goto error; | ||
3199 | wIndex--; | ||
3200 | temp = readl(status_reg); | ||
3201 | |||
3202 | /* | ||
3203 | * Even if OWNER is set, so the port is owned by the | ||
3204 | * companion controller, khubd needs to be able to clear | ||
3205 | * the port-change status bits (especially | ||
3206 | * USB_PORT_FEAT_C_CONNECTION). | ||
3207 | */ | ||
3208 | |||
3209 | switch (wValue) { | ||
3210 | case USB_PORT_FEAT_ENABLE: | ||
3211 | writel(temp & ~PORT_PE, status_reg); | ||
3212 | break; | ||
3213 | case USB_PORT_FEAT_C_ENABLE: | ||
3214 | writel((temp & ~PORT_RWC_BITS) | PORT_PEC, status_reg); | ||
3215 | break; | ||
3216 | case USB_PORT_FEAT_SUSPEND: | ||
3217 | if (temp & PORT_RESET) | ||
3218 | goto error; | ||
3219 | if (temp & PORT_SUSPEND) { | ||
3220 | if ((temp & PORT_PE) == 0) | ||
3221 | goto error; | ||
3222 | /* resume signaling for 20 msec */ | ||
3223 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); | ||
3224 | writel(temp | PORT_RESUME, status_reg); | ||
3225 | oxu->reset_done[wIndex] = jiffies | ||
3226 | + msecs_to_jiffies(20); | ||
3227 | } | ||
3228 | break; | ||
3229 | case USB_PORT_FEAT_C_SUSPEND: | ||
3230 | /* we auto-clear this feature */ | ||
3231 | break; | ||
3232 | case USB_PORT_FEAT_POWER: | ||
3233 | if (HCS_PPC(oxu->hcs_params)) | ||
3234 | writel(temp & ~(PORT_RWC_BITS | PORT_POWER), | ||
3235 | status_reg); | ||
3236 | break; | ||
3237 | case USB_PORT_FEAT_C_CONNECTION: | ||
3238 | writel((temp & ~PORT_RWC_BITS) | PORT_CSC, status_reg); | ||
3239 | break; | ||
3240 | case USB_PORT_FEAT_C_OVER_CURRENT: | ||
3241 | writel((temp & ~PORT_RWC_BITS) | PORT_OCC, status_reg); | ||
3242 | break; | ||
3243 | case USB_PORT_FEAT_C_RESET: | ||
3244 | /* GetPortStatus clears reset */ | ||
3245 | break; | ||
3246 | default: | ||
3247 | goto error; | ||
3248 | } | ||
3249 | readl(&oxu->regs->command); /* unblock posted write */ | ||
3250 | break; | ||
3251 | case GetHubDescriptor: | ||
3252 | ehci_hub_descriptor(oxu, (struct usb_hub_descriptor *) | ||
3253 | buf); | ||
3254 | break; | ||
3255 | case GetHubStatus: | ||
3256 | /* no hub-wide feature/status flags */ | ||
3257 | memset(buf, 0, 4); | ||
3258 | break; | ||
3259 | case GetPortStatus: | ||
3260 | if (!wIndex || wIndex > ports) | ||
3261 | goto error; | ||
3262 | wIndex--; | ||
3263 | status = 0; | ||
3264 | temp = readl(status_reg); | ||
3265 | |||
3266 | /* wPortChange bits */ | ||
3267 | if (temp & PORT_CSC) | ||
3268 | status |= 1 << USB_PORT_FEAT_C_CONNECTION; | ||
3269 | if (temp & PORT_PEC) | ||
3270 | status |= 1 << USB_PORT_FEAT_C_ENABLE; | ||
3271 | if ((temp & PORT_OCC) && !ignore_oc) | ||
3272 | status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT; | ||
3273 | |||
3274 | /* whoever resumes must GetPortStatus to complete it!! */ | ||
3275 | if (temp & PORT_RESUME) { | ||
3276 | |||
3277 | /* Remote Wakeup received? */ | ||
3278 | if (!oxu->reset_done[wIndex]) { | ||
3279 | /* resume signaling for 20 msec */ | ||
3280 | oxu->reset_done[wIndex] = jiffies | ||
3281 | + msecs_to_jiffies(20); | ||
3282 | /* check the port again */ | ||
3283 | mod_timer(&oxu_to_hcd(oxu)->rh_timer, | ||
3284 | oxu->reset_done[wIndex]); | ||
3285 | } | ||
3286 | |||
3287 | /* resume completed? */ | ||
3288 | else if (time_after_eq(jiffies, | ||
3289 | oxu->reset_done[wIndex])) { | ||
3290 | status |= 1 << USB_PORT_FEAT_C_SUSPEND; | ||
3291 | oxu->reset_done[wIndex] = 0; | ||
3292 | |||
3293 | /* stop resume signaling */ | ||
3294 | temp = readl(status_reg); | ||
3295 | writel(temp & ~(PORT_RWC_BITS | PORT_RESUME), | ||
3296 | status_reg); | ||
3297 | retval = handshake(oxu, status_reg, | ||
3298 | PORT_RESUME, 0, 2000 /* 2msec */); | ||
3299 | if (retval != 0) { | ||
3300 | oxu_err(oxu, | ||
3301 | "port %d resume error %d\n", | ||
3302 | wIndex + 1, retval); | ||
3303 | goto error; | ||
3304 | } | ||
3305 | temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10)); | ||
3306 | } | ||
3307 | } | ||
3308 | |||
3309 | /* whoever resets must GetPortStatus to complete it!! */ | ||
3310 | if ((temp & PORT_RESET) | ||
3311 | && time_after_eq(jiffies, | ||
3312 | oxu->reset_done[wIndex])) { | ||
3313 | status |= 1 << USB_PORT_FEAT_C_RESET; | ||
3314 | oxu->reset_done[wIndex] = 0; | ||
3315 | |||
3316 | /* force reset to complete */ | ||
3317 | writel(temp & ~(PORT_RWC_BITS | PORT_RESET), | ||
3318 | status_reg); | ||
3319 | /* REVISIT: some hardware needs 550+ usec to clear | ||
3320 | * this bit; seems too long to spin routinely... | ||
3321 | */ | ||
3322 | retval = handshake(oxu, status_reg, | ||
3323 | PORT_RESET, 0, 750); | ||
3324 | if (retval != 0) { | ||
3325 | oxu_err(oxu, "port %d reset error %d\n", | ||
3326 | wIndex + 1, retval); | ||
3327 | goto error; | ||
3328 | } | ||
3329 | |||
3330 | /* see what we found out */ | ||
3331 | temp = check_reset_complete(oxu, wIndex, status_reg, | ||
3332 | readl(status_reg)); | ||
3333 | } | ||
3334 | |||
3335 | /* transfer dedicated ports to the companion hc */ | ||
3336 | if ((temp & PORT_CONNECT) && | ||
3337 | test_bit(wIndex, &oxu->companion_ports)) { | ||
3338 | temp &= ~PORT_RWC_BITS; | ||
3339 | temp |= PORT_OWNER; | ||
3340 | writel(temp, status_reg); | ||
3341 | oxu_dbg(oxu, "port %d --> companion\n", wIndex + 1); | ||
3342 | temp = readl(status_reg); | ||
3343 | } | ||
3344 | |||
3345 | /* | ||
3346 | * Even if OWNER is set, there's no harm letting khubd | ||
3347 | * see the wPortStatus values (they should all be 0 except | ||
3348 | * for PORT_POWER anyway). | ||
3349 | */ | ||
3350 | |||
3351 | if (temp & PORT_CONNECT) { | ||
3352 | status |= 1 << USB_PORT_FEAT_CONNECTION; | ||
3353 | /* status may be from integrated TT */ | ||
3354 | status |= oxu_port_speed(oxu, temp); | ||
3355 | } | ||
3356 | if (temp & PORT_PE) | ||
3357 | status |= 1 << USB_PORT_FEAT_ENABLE; | ||
3358 | if (temp & (PORT_SUSPEND|PORT_RESUME)) | ||
3359 | status |= 1 << USB_PORT_FEAT_SUSPEND; | ||
3360 | if (temp & PORT_OC) | ||
3361 | status |= 1 << USB_PORT_FEAT_OVER_CURRENT; | ||
3362 | if (temp & PORT_RESET) | ||
3363 | status |= 1 << USB_PORT_FEAT_RESET; | ||
3364 | if (temp & PORT_POWER) | ||
3365 | status |= 1 << USB_PORT_FEAT_POWER; | ||
3366 | |||
3367 | #ifndef OXU_VERBOSE_DEBUG | ||
3368 | if (status & ~0xffff) /* only if wPortChange is interesting */ | ||
3369 | #endif | ||
3370 | dbg_port(oxu, "GetStatus", wIndex + 1, temp); | ||
3371 | put_unaligned(cpu_to_le32(status), (__le32 *) buf); | ||
3372 | break; | ||
3373 | case SetHubFeature: | ||
3374 | switch (wValue) { | ||
3375 | case C_HUB_LOCAL_POWER: | ||
3376 | case C_HUB_OVER_CURRENT: | ||
3377 | /* no hub-wide feature/status flags */ | ||
3378 | break; | ||
3379 | default: | ||
3380 | goto error; | ||
3381 | } | ||
3382 | break; | ||
3383 | case SetPortFeature: | ||
3384 | selector = wIndex >> 8; | ||
3385 | wIndex &= 0xff; | ||
3386 | if (!wIndex || wIndex > ports) | ||
3387 | goto error; | ||
3388 | wIndex--; | ||
3389 | temp = readl(status_reg); | ||
3390 | if (temp & PORT_OWNER) | ||
3391 | break; | ||
3392 | |||
3393 | temp &= ~PORT_RWC_BITS; | ||
3394 | switch (wValue) { | ||
3395 | case USB_PORT_FEAT_SUSPEND: | ||
3396 | if ((temp & PORT_PE) == 0 | ||
3397 | || (temp & PORT_RESET) != 0) | ||
3398 | goto error; | ||
3399 | if (device_may_wakeup(&hcd->self.root_hub->dev)) | ||
3400 | temp |= PORT_WAKE_BITS; | ||
3401 | writel(temp | PORT_SUSPEND, status_reg); | ||
3402 | break; | ||
3403 | case USB_PORT_FEAT_POWER: | ||
3404 | if (HCS_PPC(oxu->hcs_params)) | ||
3405 | writel(temp | PORT_POWER, status_reg); | ||
3406 | break; | ||
3407 | case USB_PORT_FEAT_RESET: | ||
3408 | if (temp & PORT_RESUME) | ||
3409 | goto error; | ||
3410 | /* line status bits may report this as low speed, | ||
3411 | * which can be fine if this root hub has a | ||
3412 | * transaction translator built in. | ||
3413 | */ | ||
3414 | oxu_vdbg(oxu, "port %d reset\n", wIndex + 1); | ||
3415 | temp |= PORT_RESET; | ||
3416 | temp &= ~PORT_PE; | ||
3417 | |||
3418 | /* | ||
3419 | * caller must wait, then call GetPortStatus | ||
3420 | * usb 2.0 spec says 50 ms resets on root | ||
3421 | */ | ||
3422 | oxu->reset_done[wIndex] = jiffies | ||
3423 | + msecs_to_jiffies(50); | ||
3424 | writel(temp, status_reg); | ||
3425 | break; | ||
3426 | |||
3427 | /* For downstream facing ports (these): one hub port is put | ||
3428 | * into test mode according to USB2 11.24.2.13, then the hub | ||
3429 | * must be reset (which for root hub now means rmmod+modprobe, | ||
3430 | * or else system reboot). See EHCI 2.3.9 and 4.14 for info | ||
3431 | * about the EHCI-specific stuff. | ||
3432 | */ | ||
3433 | case USB_PORT_FEAT_TEST: | ||
3434 | if (!selector || selector > 5) | ||
3435 | goto error; | ||
3436 | ehci_quiesce(oxu); | ||
3437 | ehci_halt(oxu); | ||
3438 | temp |= selector << 16; | ||
3439 | writel(temp, status_reg); | ||
3440 | break; | ||
3441 | |||
3442 | default: | ||
3443 | goto error; | ||
3444 | } | ||
3445 | readl(&oxu->regs->command); /* unblock posted writes */ | ||
3446 | break; | ||
3447 | |||
3448 | default: | ||
3449 | error: | ||
3450 | /* "stall" on error */ | ||
3451 | retval = -EPIPE; | ||
3452 | } | ||
3453 | spin_unlock_irqrestore(&oxu->lock, flags); | ||
3454 | return retval; | ||
3455 | } | ||
3456 | |||
3457 | #ifdef CONFIG_PM | ||
3458 | |||
3459 | static int oxu_bus_suspend(struct usb_hcd *hcd) | ||
3460 | { | ||
3461 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
3462 | int port; | ||
3463 | int mask; | ||
3464 | |||
3465 | oxu_dbg(oxu, "suspend root hub\n"); | ||
3466 | |||
3467 | if (time_before(jiffies, oxu->next_statechange)) | ||
3468 | msleep(5); | ||
3469 | |||
3470 | port = HCS_N_PORTS(oxu->hcs_params); | ||
3471 | spin_lock_irq(&oxu->lock); | ||
3472 | |||
3473 | /* stop schedules, clean any completed work */ | ||
3474 | if (HC_IS_RUNNING(hcd->state)) { | ||
3475 | ehci_quiesce(oxu); | ||
3476 | hcd->state = HC_STATE_QUIESCING; | ||
3477 | } | ||
3478 | oxu->command = readl(&oxu->regs->command); | ||
3479 | if (oxu->reclaim) | ||
3480 | oxu->reclaim_ready = 1; | ||
3481 | ehci_work(oxu); | ||
3482 | |||
3483 | /* Unlike other USB host controller types, EHCI doesn't have | ||
3484 | * any notion of "global" or bus-wide suspend. The driver has | ||
3485 | * to manually suspend all the active unsuspended ports, and | ||
3486 | * then manually resume them in the bus_resume() routine. | ||
3487 | */ | ||
3488 | oxu->bus_suspended = 0; | ||
3489 | while (port--) { | ||
3490 | u32 __iomem *reg = &oxu->regs->port_status[port]; | ||
3491 | u32 t1 = readl(reg) & ~PORT_RWC_BITS; | ||
3492 | u32 t2 = t1; | ||
3493 | |||
3494 | /* keep track of which ports we suspend */ | ||
3495 | if ((t1 & PORT_PE) && !(t1 & PORT_OWNER) && | ||
3496 | !(t1 & PORT_SUSPEND)) { | ||
3497 | t2 |= PORT_SUSPEND; | ||
3498 | set_bit(port, &oxu->bus_suspended); | ||
3499 | } | ||
3500 | |||
3501 | /* enable remote wakeup on all ports */ | ||
3502 | if (device_may_wakeup(&hcd->self.root_hub->dev)) | ||
3503 | t2 |= PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E; | ||
3504 | else | ||
3505 | t2 &= ~(PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E); | ||
3506 | |||
3507 | if (t1 != t2) { | ||
3508 | oxu_vdbg(oxu, "port %d, %08x -> %08x\n", | ||
3509 | port + 1, t1, t2); | ||
3510 | writel(t2, reg); | ||
3511 | } | ||
3512 | } | ||
3513 | |||
3514 | /* turn off now-idle HC */ | ||
3515 | del_timer_sync(&oxu->watchdog); | ||
3516 | ehci_halt(oxu); | ||
3517 | hcd->state = HC_STATE_SUSPENDED; | ||
3518 | |||
3519 | /* allow remote wakeup */ | ||
3520 | mask = INTR_MASK; | ||
3521 | if (!device_may_wakeup(&hcd->self.root_hub->dev)) | ||
3522 | mask &= ~STS_PCD; | ||
3523 | writel(mask, &oxu->regs->intr_enable); | ||
3524 | readl(&oxu->regs->intr_enable); | ||
3525 | |||
3526 | oxu->next_statechange = jiffies + msecs_to_jiffies(10); | ||
3527 | spin_unlock_irq(&oxu->lock); | ||
3528 | return 0; | ||
3529 | } | ||
3530 | |||
3531 | /* Caller has locked the root hub, and should reset/reinit on error */ | ||
3532 | static int oxu_bus_resume(struct usb_hcd *hcd) | ||
3533 | { | ||
3534 | struct oxu_hcd *oxu = hcd_to_oxu(hcd); | ||
3535 | u32 temp; | ||
3536 | int i; | ||
3537 | |||
3538 | if (time_before(jiffies, oxu->next_statechange)) | ||
3539 | msleep(5); | ||
3540 | spin_lock_irq(&oxu->lock); | ||
3541 | |||
3542 | /* Ideally and we've got a real resume here, and no port's power | ||
3543 | * was lost. (For PCI, that means Vaux was maintained.) But we | ||
3544 | * could instead be restoring a swsusp snapshot -- so that BIOS was | ||
3545 | * the last user of the controller, not reset/pm hardware keeping | ||
3546 | * state we gave to it. | ||
3547 | */ | ||
3548 | temp = readl(&oxu->regs->intr_enable); | ||
3549 | oxu_dbg(oxu, "resume root hub%s\n", temp ? "" : " after power loss"); | ||
3550 | |||
3551 | /* at least some APM implementations will try to deliver | ||
3552 | * IRQs right away, so delay them until we're ready. | ||
3553 | */ | ||
3554 | writel(0, &oxu->regs->intr_enable); | ||
3555 | |||
3556 | /* re-init operational registers */ | ||
3557 | writel(0, &oxu->regs->segment); | ||
3558 | writel(oxu->periodic_dma, &oxu->regs->frame_list); | ||
3559 | writel((u32) oxu->async->qh_dma, &oxu->regs->async_next); | ||
3560 | |||
3561 | /* restore CMD_RUN, framelist size, and irq threshold */ | ||
3562 | writel(oxu->command, &oxu->regs->command); | ||
3563 | |||
3564 | /* Some controller/firmware combinations need a delay during which | ||
3565 | * they set up the port statuses. See Bugzilla #8190. */ | ||
3566 | mdelay(8); | ||
3567 | |||
3568 | /* manually resume the ports we suspended during bus_suspend() */ | ||
3569 | i = HCS_N_PORTS(oxu->hcs_params); | ||
3570 | while (i--) { | ||
3571 | temp = readl(&oxu->regs->port_status[i]); | ||
3572 | temp &= ~(PORT_RWC_BITS | ||
3573 | | PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E); | ||
3574 | if (test_bit(i, &oxu->bus_suspended) && (temp & PORT_SUSPEND)) { | ||
3575 | oxu->reset_done[i] = jiffies + msecs_to_jiffies(20); | ||
3576 | temp |= PORT_RESUME; | ||
3577 | } | ||
3578 | writel(temp, &oxu->regs->port_status[i]); | ||
3579 | } | ||
3580 | i = HCS_N_PORTS(oxu->hcs_params); | ||
3581 | mdelay(20); | ||
3582 | while (i--) { | ||
3583 | temp = readl(&oxu->regs->port_status[i]); | ||
3584 | if (test_bit(i, &oxu->bus_suspended) && (temp & PORT_SUSPEND)) { | ||
3585 | temp &= ~(PORT_RWC_BITS | PORT_RESUME); | ||
3586 | writel(temp, &oxu->regs->port_status[i]); | ||
3587 | oxu_vdbg(oxu, "resumed port %d\n", i + 1); | ||
3588 | } | ||
3589 | } | ||
3590 | (void) readl(&oxu->regs->command); | ||
3591 | |||
3592 | /* maybe re-activate the schedule(s) */ | ||
3593 | temp = 0; | ||
3594 | if (oxu->async->qh_next.qh) | ||
3595 | temp |= CMD_ASE; | ||
3596 | if (oxu->periodic_sched) | ||
3597 | temp |= CMD_PSE; | ||
3598 | if (temp) { | ||
3599 | oxu->command |= temp; | ||
3600 | writel(oxu->command, &oxu->regs->command); | ||
3601 | } | ||
3602 | |||
3603 | oxu->next_statechange = jiffies + msecs_to_jiffies(5); | ||
3604 | hcd->state = HC_STATE_RUNNING; | ||
3605 | |||
3606 | /* Now we can safely re-enable irqs */ | ||
3607 | writel(INTR_MASK, &oxu->regs->intr_enable); | ||
3608 | |||
3609 | spin_unlock_irq(&oxu->lock); | ||
3610 | return 0; | ||
3611 | } | ||
3612 | |||
3613 | #else | ||
3614 | |||
3615 | static int oxu_bus_suspend(struct usb_hcd *hcd) | ||
3616 | { | ||
3617 | return 0; | ||
3618 | } | ||
3619 | |||
3620 | static int oxu_bus_resume(struct usb_hcd *hcd) | ||
3621 | { | ||
3622 | return 0; | ||
3623 | } | ||
3624 | |||
3625 | #endif /* CONFIG_PM */ | ||
3626 | |||
3627 | static const struct hc_driver oxu_hc_driver = { | ||
3628 | .description = "oxu210hp_hcd", | ||
3629 | .product_desc = "oxu210hp HCD", | ||
3630 | .hcd_priv_size = sizeof(struct oxu_hcd), | ||
3631 | |||
3632 | /* | ||
3633 | * Generic hardware linkage | ||
3634 | */ | ||
3635 | .irq = oxu_irq, | ||
3636 | .flags = HCD_MEMORY | HCD_USB2, | ||
3637 | |||
3638 | /* | ||
3639 | * Basic lifecycle operations | ||
3640 | */ | ||
3641 | .reset = oxu_reset, | ||
3642 | .start = oxu_run, | ||
3643 | .stop = oxu_stop, | ||
3644 | .shutdown = oxu_shutdown, | ||
3645 | |||
3646 | /* | ||
3647 | * Managing i/o requests and associated device resources | ||
3648 | */ | ||
3649 | .urb_enqueue = oxu_urb_enqueue, | ||
3650 | .urb_dequeue = oxu_urb_dequeue, | ||
3651 | .endpoint_disable = oxu_endpoint_disable, | ||
3652 | |||
3653 | /* | ||
3654 | * Scheduling support | ||
3655 | */ | ||
3656 | .get_frame_number = oxu_get_frame, | ||
3657 | |||
3658 | /* | ||
3659 | * Root hub support | ||
3660 | */ | ||
3661 | .hub_status_data = oxu_hub_status_data, | ||
3662 | .hub_control = oxu_hub_control, | ||
3663 | .bus_suspend = oxu_bus_suspend, | ||
3664 | .bus_resume = oxu_bus_resume, | ||
3665 | }; | ||
3666 | |||
3667 | /* | ||
3668 | * Module stuff | ||
3669 | */ | ||
3670 | |||
3671 | static void oxu_configuration(struct platform_device *pdev, void *base) | ||
3672 | { | ||
3673 | u32 tmp; | ||
3674 | |||
3675 | /* Initialize top level registers. | ||
3676 | * First write ever | ||
3677 | */ | ||
3678 | oxu_writel(base, OXU_HOSTIFCONFIG, 0x0000037D); | ||
3679 | oxu_writel(base, OXU_SOFTRESET, OXU_SRESET); | ||
3680 | oxu_writel(base, OXU_HOSTIFCONFIG, 0x0000037D); | ||
3681 | |||
3682 | tmp = oxu_readl(base, OXU_PIOBURSTREADCTRL); | ||
3683 | oxu_writel(base, OXU_PIOBURSTREADCTRL, tmp | 0x0040); | ||
3684 | |||
3685 | oxu_writel(base, OXU_ASO, OXU_SPHPOEN | OXU_OVRCCURPUPDEN | | ||
3686 | OXU_COMPARATOR | OXU_ASO_OP); | ||
3687 | |||
3688 | tmp = oxu_readl(base, OXU_CLKCTRL_SET); | ||
3689 | oxu_writel(base, OXU_CLKCTRL_SET, tmp | OXU_SYSCLKEN | OXU_USBOTGCLKEN); | ||
3690 | |||
3691 | /* Clear all top interrupt enable */ | ||
3692 | oxu_writel(base, OXU_CHIPIRQEN_CLR, 0xff); | ||
3693 | |||
3694 | /* Clear all top interrupt status */ | ||
3695 | oxu_writel(base, OXU_CHIPIRQSTATUS, 0xff); | ||
3696 | |||
3697 | /* Enable all needed top interrupt except OTG SPH core */ | ||
3698 | oxu_writel(base, OXU_CHIPIRQEN_SET, OXU_USBSPHLPWUI | OXU_USBOTGLPWUI); | ||
3699 | } | ||
3700 | |||
3701 | static int oxu_verify_id(struct platform_device *pdev, void *base) | ||
3702 | { | ||
3703 | u32 id; | ||
3704 | char *bo[] = { | ||
3705 | "reserved", | ||
3706 | "128-pin LQFP", | ||
3707 | "84-pin TFBGA", | ||
3708 | "reserved", | ||
3709 | }; | ||
3710 | |||
3711 | /* Read controller signature register to find a match */ | ||
3712 | id = oxu_readl(base, OXU_DEVICEID); | ||
3713 | dev_info(&pdev->dev, "device ID %x\n", id); | ||
3714 | if ((id & OXU_REV_MASK) != (OXU_REV_2100 << OXU_REV_SHIFT)) | ||
3715 | return -1; | ||
3716 | |||
3717 | dev_info(&pdev->dev, "found device %x %s (%04x:%04x)\n", | ||
3718 | id >> OXU_REV_SHIFT, | ||
3719 | bo[(id & OXU_BO_MASK) >> OXU_BO_SHIFT], | ||
3720 | (id & OXU_MAJ_REV_MASK) >> OXU_MAJ_REV_SHIFT, | ||
3721 | (id & OXU_MIN_REV_MASK) >> OXU_MIN_REV_SHIFT); | ||
3722 | |||
3723 | return 0; | ||
3724 | } | ||
3725 | |||
3726 | static const struct hc_driver oxu_hc_driver; | ||
3727 | static struct usb_hcd *oxu_create(struct platform_device *pdev, | ||
3728 | unsigned long memstart, unsigned long memlen, | ||
3729 | void *base, int irq, int otg) | ||
3730 | { | ||
3731 | struct device *dev = &pdev->dev; | ||
3732 | |||
3733 | struct usb_hcd *hcd; | ||
3734 | struct oxu_hcd *oxu; | ||
3735 | int ret; | ||
3736 | |||
3737 | /* Set endian mode and host mode */ | ||
3738 | oxu_writel(base + (otg ? OXU_OTG_CORE_OFFSET : OXU_SPH_CORE_OFFSET), | ||
3739 | OXU_USBMODE, | ||
3740 | OXU_CM_HOST_ONLY | OXU_ES_LITTLE | OXU_VBPS); | ||
3741 | |||
3742 | hcd = usb_create_hcd(&oxu_hc_driver, dev, | ||
3743 | otg ? "oxu210hp_otg" : "oxu210hp_sph"); | ||
3744 | if (!hcd) | ||
3745 | return ERR_PTR(-ENOMEM); | ||
3746 | |||
3747 | hcd->rsrc_start = memstart; | ||
3748 | hcd->rsrc_len = memlen; | ||
3749 | hcd->regs = base; | ||
3750 | hcd->irq = irq; | ||
3751 | hcd->state = HC_STATE_HALT; | ||
3752 | |||
3753 | oxu = hcd_to_oxu(hcd); | ||
3754 | oxu->is_otg = otg; | ||
3755 | |||
3756 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); | ||
3757 | if (ret < 0) | ||
3758 | return ERR_PTR(ret); | ||
3759 | |||
3760 | return hcd; | ||
3761 | } | ||
3762 | |||
3763 | static int oxu_init(struct platform_device *pdev, | ||
3764 | unsigned long memstart, unsigned long memlen, | ||
3765 | void *base, int irq) | ||
3766 | { | ||
3767 | struct oxu_info *info = platform_get_drvdata(pdev); | ||
3768 | struct usb_hcd *hcd; | ||
3769 | int ret; | ||
3770 | |||
3771 | /* First time configuration at start up */ | ||
3772 | oxu_configuration(pdev, base); | ||
3773 | |||
3774 | ret = oxu_verify_id(pdev, base); | ||
3775 | if (ret) { | ||
3776 | dev_err(&pdev->dev, "no devices found!\n"); | ||
3777 | return -ENODEV; | ||
3778 | } | ||
3779 | |||
3780 | /* Create the OTG controller */ | ||
3781 | hcd = oxu_create(pdev, memstart, memlen, base, irq, 1); | ||
3782 | if (IS_ERR(hcd)) { | ||
3783 | dev_err(&pdev->dev, "cannot create OTG controller!\n"); | ||
3784 | ret = PTR_ERR(hcd); | ||
3785 | goto error_create_otg; | ||
3786 | } | ||
3787 | info->hcd[0] = hcd; | ||
3788 | |||
3789 | /* Create the SPH host controller */ | ||
3790 | hcd = oxu_create(pdev, memstart, memlen, base, irq, 0); | ||
3791 | if (IS_ERR(hcd)) { | ||
3792 | dev_err(&pdev->dev, "cannot create SPH controller!\n"); | ||
3793 | ret = PTR_ERR(hcd); | ||
3794 | goto error_create_sph; | ||
3795 | } | ||
3796 | info->hcd[1] = hcd; | ||
3797 | |||
3798 | oxu_writel(base, OXU_CHIPIRQEN_SET, | ||
3799 | oxu_readl(base, OXU_CHIPIRQEN_SET) | 3); | ||
3800 | |||
3801 | return 0; | ||
3802 | |||
3803 | error_create_sph: | ||
3804 | usb_remove_hcd(info->hcd[0]); | ||
3805 | usb_put_hcd(info->hcd[0]); | ||
3806 | |||
3807 | error_create_otg: | ||
3808 | return ret; | ||
3809 | } | ||
3810 | |||
3811 | static int oxu_drv_probe(struct platform_device *pdev) | ||
3812 | { | ||
3813 | struct resource *res; | ||
3814 | void *base; | ||
3815 | unsigned long memstart, memlen; | ||
3816 | int irq, ret; | ||
3817 | struct oxu_info *info; | ||
3818 | |||
3819 | if (usb_disabled()) | ||
3820 | return -ENODEV; | ||
3821 | |||
3822 | /* | ||
3823 | * Get the platform resources | ||
3824 | */ | ||
3825 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
3826 | if (!res) { | ||
3827 | dev_err(&pdev->dev, | ||
3828 | "no IRQ! Check %s setup!\n", dev_name(&pdev->dev)); | ||
3829 | return -ENODEV; | ||
3830 | } | ||
3831 | irq = res->start; | ||
3832 | dev_dbg(&pdev->dev, "IRQ resource %d\n", irq); | ||
3833 | |||
3834 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
3835 | if (!res) { | ||
3836 | dev_err(&pdev->dev, "no registers address! Check %s setup!\n", | ||
3837 | dev_name(&pdev->dev)); | ||
3838 | return -ENODEV; | ||
3839 | } | ||
3840 | memstart = res->start; | ||
3841 | memlen = res->end - res->start + 1; | ||
3842 | dev_dbg(&pdev->dev, "MEM resource %lx-%lx\n", memstart, memlen); | ||
3843 | if (!request_mem_region(memstart, memlen, | ||
3844 | oxu_hc_driver.description)) { | ||
3845 | dev_dbg(&pdev->dev, "memory area already in use\n"); | ||
3846 | return -EBUSY; | ||
3847 | } | ||
3848 | |||
3849 | ret = set_irq_type(irq, IRQF_TRIGGER_FALLING); | ||
3850 | if (ret) { | ||
3851 | dev_err(&pdev->dev, "error setting irq type\n"); | ||
3852 | ret = -EFAULT; | ||
3853 | goto error_set_irq_type; | ||
3854 | } | ||
3855 | |||
3856 | base = ioremap(memstart, memlen); | ||
3857 | if (!base) { | ||
3858 | dev_dbg(&pdev->dev, "error mapping memory\n"); | ||
3859 | ret = -EFAULT; | ||
3860 | goto error_ioremap; | ||
3861 | } | ||
3862 | |||
3863 | /* Allocate a driver data struct to hold useful info for both | ||
3864 | * SPH & OTG devices | ||
3865 | */ | ||
3866 | info = kzalloc(sizeof(struct oxu_info), GFP_KERNEL); | ||
3867 | if (!info) { | ||
3868 | dev_dbg(&pdev->dev, "error allocating memory\n"); | ||
3869 | ret = -EFAULT; | ||
3870 | goto error_alloc; | ||
3871 | } | ||
3872 | platform_set_drvdata(pdev, info); | ||
3873 | |||
3874 | ret = oxu_init(pdev, memstart, memlen, base, irq); | ||
3875 | if (ret < 0) { | ||
3876 | dev_dbg(&pdev->dev, "cannot init USB devices\n"); | ||
3877 | goto error_init; | ||
3878 | } | ||
3879 | |||
3880 | dev_info(&pdev->dev, "devices enabled and running\n"); | ||
3881 | platform_set_drvdata(pdev, info); | ||
3882 | |||
3883 | return 0; | ||
3884 | |||
3885 | error_init: | ||
3886 | kfree(info); | ||
3887 | platform_set_drvdata(pdev, NULL); | ||
3888 | |||
3889 | error_alloc: | ||
3890 | iounmap(base); | ||
3891 | |||
3892 | error_set_irq_type: | ||
3893 | error_ioremap: | ||
3894 | release_mem_region(memstart, memlen); | ||
3895 | |||
3896 | dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret); | ||
3897 | return ret; | ||
3898 | } | ||
3899 | |||
3900 | static void oxu_remove(struct platform_device *pdev, struct usb_hcd *hcd) | ||
3901 | { | ||
3902 | usb_remove_hcd(hcd); | ||
3903 | usb_put_hcd(hcd); | ||
3904 | } | ||
3905 | |||
3906 | static int oxu_drv_remove(struct platform_device *pdev) | ||
3907 | { | ||
3908 | struct oxu_info *info = platform_get_drvdata(pdev); | ||
3909 | unsigned long memstart = info->hcd[0]->rsrc_start, | ||
3910 | memlen = info->hcd[0]->rsrc_len; | ||
3911 | void *base = info->hcd[0]->regs; | ||
3912 | |||
3913 | oxu_remove(pdev, info->hcd[0]); | ||
3914 | oxu_remove(pdev, info->hcd[1]); | ||
3915 | |||
3916 | iounmap(base); | ||
3917 | release_mem_region(memstart, memlen); | ||
3918 | |||
3919 | kfree(info); | ||
3920 | platform_set_drvdata(pdev, NULL); | ||
3921 | |||
3922 | return 0; | ||
3923 | } | ||
3924 | |||
3925 | static void oxu_drv_shutdown(struct platform_device *pdev) | ||
3926 | { | ||
3927 | oxu_drv_remove(pdev); | ||
3928 | } | ||
3929 | |||
3930 | #if 0 | ||
3931 | /* FIXME: TODO */ | ||
3932 | static int oxu_drv_suspend(struct device *dev) | ||
3933 | { | ||
3934 | struct platform_device *pdev = to_platform_device(dev); | ||
3935 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
3936 | |||
3937 | return 0; | ||
3938 | } | ||
3939 | |||
3940 | static int oxu_drv_resume(struct device *dev) | ||
3941 | { | ||
3942 | struct platform_device *pdev = to_platform_device(dev); | ||
3943 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
3944 | |||
3945 | return 0; | ||
3946 | } | ||
3947 | #else | ||
3948 | #define oxu_drv_suspend NULL | ||
3949 | #define oxu_drv_resume NULL | ||
3950 | #endif | ||
3951 | |||
3952 | static struct platform_driver oxu_driver = { | ||
3953 | .probe = oxu_drv_probe, | ||
3954 | .remove = oxu_drv_remove, | ||
3955 | .shutdown = oxu_drv_shutdown, | ||
3956 | .suspend = oxu_drv_suspend, | ||
3957 | .resume = oxu_drv_resume, | ||
3958 | .driver = { | ||
3959 | .name = "oxu210hp-hcd", | ||
3960 | .bus = &platform_bus_type | ||
3961 | } | ||
3962 | }; | ||
3963 | |||
3964 | static int __init oxu_module_init(void) | ||
3965 | { | ||
3966 | int retval = 0; | ||
3967 | |||
3968 | retval = platform_driver_register(&oxu_driver); | ||
3969 | if (retval < 0) | ||
3970 | return retval; | ||
3971 | |||
3972 | return retval; | ||
3973 | } | ||
3974 | |||
3975 | static void __exit oxu_module_cleanup(void) | ||
3976 | { | ||
3977 | platform_driver_unregister(&oxu_driver); | ||
3978 | } | ||
3979 | |||
3980 | module_init(oxu_module_init); | ||
3981 | module_exit(oxu_module_cleanup); | ||
3982 | |||
3983 | MODULE_DESCRIPTION("Oxford OXU210HP HCD driver - ver. " DRIVER_VERSION); | ||
3984 | MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); | ||
3985 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/host/oxu210hp.h b/drivers/usb/host/oxu210hp.h new file mode 100644 index 000000000000..8910e271cc7d --- /dev/null +++ b/drivers/usb/host/oxu210hp.h | |||
@@ -0,0 +1,447 @@ | |||
1 | /* | ||
2 | * Host interface registers | ||
3 | */ | ||
4 | |||
5 | #define OXU_DEVICEID 0x00 | ||
6 | #define OXU_REV_MASK 0xffff0000 | ||
7 | #define OXU_REV_SHIFT 16 | ||
8 | #define OXU_REV_2100 0x2100 | ||
9 | #define OXU_BO_SHIFT 8 | ||
10 | #define OXU_BO_MASK (0x3 << OXU_BO_SHIFT) | ||
11 | #define OXU_MAJ_REV_SHIFT 4 | ||
12 | #define OXU_MAJ_REV_MASK (0xf << OXU_MAJ_REV_SHIFT) | ||
13 | #define OXU_MIN_REV_SHIFT 0 | ||
14 | #define OXU_MIN_REV_MASK (0xf << OXU_MIN_REV_SHIFT) | ||
15 | #define OXU_HOSTIFCONFIG 0x04 | ||
16 | #define OXU_SOFTRESET 0x08 | ||
17 | #define OXU_SRESET (1 << 0) | ||
18 | |||
19 | #define OXU_PIOBURSTREADCTRL 0x0C | ||
20 | |||
21 | #define OXU_CHIPIRQSTATUS 0x10 | ||
22 | #define OXU_CHIPIRQEN_SET 0x14 | ||
23 | #define OXU_CHIPIRQEN_CLR 0x18 | ||
24 | #define OXU_USBSPHLPWUI 0x00000080 | ||
25 | #define OXU_USBOTGLPWUI 0x00000040 | ||
26 | #define OXU_USBSPHI 0x00000002 | ||
27 | #define OXU_USBOTGI 0x00000001 | ||
28 | |||
29 | #define OXU_CLKCTRL_SET 0x1C | ||
30 | #define OXU_SYSCLKEN 0x00000008 | ||
31 | #define OXU_USBSPHCLKEN 0x00000002 | ||
32 | #define OXU_USBOTGCLKEN 0x00000001 | ||
33 | |||
34 | #define OXU_ASO 0x68 | ||
35 | #define OXU_SPHPOEN 0x00000100 | ||
36 | #define OXU_OVRCCURPUPDEN 0x00000800 | ||
37 | #define OXU_ASO_OP (1 << 10) | ||
38 | #define OXU_COMPARATOR 0x000004000 | ||
39 | |||
40 | #define OXU_USBMODE 0x1A8 | ||
41 | #define OXU_VBPS 0x00000020 | ||
42 | #define OXU_ES_LITTLE 0x00000000 | ||
43 | #define OXU_CM_HOST_ONLY 0x00000003 | ||
44 | |||
45 | /* | ||
46 | * Proper EHCI structs & defines | ||
47 | */ | ||
48 | |||
49 | /* Magic numbers that can affect system performance */ | ||
50 | #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */ | ||
51 | #define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */ | ||
52 | #define EHCI_TUNE_RL_TT 0 | ||
53 | #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */ | ||
54 | #define EHCI_TUNE_MULT_TT 1 | ||
55 | #define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */ | ||
56 | |||
57 | struct oxu_hcd; | ||
58 | |||
59 | /* EHCI register interface, corresponds to EHCI Revision 0.95 specification */ | ||
60 | |||
61 | /* Section 2.2 Host Controller Capability Registers */ | ||
62 | struct ehci_caps { | ||
63 | /* these fields are specified as 8 and 16 bit registers, | ||
64 | * but some hosts can't perform 8 or 16 bit PCI accesses. | ||
65 | */ | ||
66 | u32 hc_capbase; | ||
67 | #define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */ | ||
68 | #define HC_VERSION(p) (((p)>>16)&0xffff) /* bits 31:16 */ | ||
69 | u32 hcs_params; /* HCSPARAMS - offset 0x4 */ | ||
70 | #define HCS_DEBUG_PORT(p) (((p)>>20)&0xf) /* bits 23:20, debug port? */ | ||
71 | #define HCS_INDICATOR(p) ((p)&(1 << 16)) /* true: has port indicators */ | ||
72 | #define HCS_N_CC(p) (((p)>>12)&0xf) /* bits 15:12, #companion HCs */ | ||
73 | #define HCS_N_PCC(p) (((p)>>8)&0xf) /* bits 11:8, ports per CC */ | ||
74 | #define HCS_PORTROUTED(p) ((p)&(1 << 7)) /* true: port routing */ | ||
75 | #define HCS_PPC(p) ((p)&(1 << 4)) /* true: port power control */ | ||
76 | #define HCS_N_PORTS(p) (((p)>>0)&0xf) /* bits 3:0, ports on HC */ | ||
77 | |||
78 | u32 hcc_params; /* HCCPARAMS - offset 0x8 */ | ||
79 | #define HCC_EXT_CAPS(p) (((p)>>8)&0xff) /* for pci extended caps */ | ||
80 | #define HCC_ISOC_CACHE(p) ((p)&(1 << 7)) /* true: can cache isoc frame */ | ||
81 | #define HCC_ISOC_THRES(p) (((p)>>4)&0x7) /* bits 6:4, uframes cached */ | ||
82 | #define HCC_CANPARK(p) ((p)&(1 << 2)) /* true: can park on async qh */ | ||
83 | #define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1)) /* true: periodic_size changes*/ | ||
84 | #define HCC_64BIT_ADDR(p) ((p)&(1)) /* true: can use 64-bit addr */ | ||
85 | u8 portroute[8]; /* nibbles for routing - offset 0xC */ | ||
86 | } __attribute__ ((packed)); | ||
87 | |||
88 | |||
89 | /* Section 2.3 Host Controller Operational Registers */ | ||
90 | struct ehci_regs { | ||
91 | /* USBCMD: offset 0x00 */ | ||
92 | u32 command; | ||
93 | /* 23:16 is r/w intr rate, in microframes; default "8" == 1/msec */ | ||
94 | #define CMD_PARK (1<<11) /* enable "park" on async qh */ | ||
95 | #define CMD_PARK_CNT(c) (((c)>>8)&3) /* how many transfers to park for */ | ||
96 | #define CMD_LRESET (1<<7) /* partial reset (no ports, etc) */ | ||
97 | #define CMD_IAAD (1<<6) /* "doorbell" interrupt async advance */ | ||
98 | #define CMD_ASE (1<<5) /* async schedule enable */ | ||
99 | #define CMD_PSE (1<<4) /* periodic schedule enable */ | ||
100 | /* 3:2 is periodic frame list size */ | ||
101 | #define CMD_RESET (1<<1) /* reset HC not bus */ | ||
102 | #define CMD_RUN (1<<0) /* start/stop HC */ | ||
103 | |||
104 | /* USBSTS: offset 0x04 */ | ||
105 | u32 status; | ||
106 | #define STS_ASS (1<<15) /* Async Schedule Status */ | ||
107 | #define STS_PSS (1<<14) /* Periodic Schedule Status */ | ||
108 | #define STS_RECL (1<<13) /* Reclamation */ | ||
109 | #define STS_HALT (1<<12) /* Not running (any reason) */ | ||
110 | /* some bits reserved */ | ||
111 | /* these STS_* flags are also intr_enable bits (USBINTR) */ | ||
112 | #define STS_IAA (1<<5) /* Interrupted on async advance */ | ||
113 | #define STS_FATAL (1<<4) /* such as some PCI access errors */ | ||
114 | #define STS_FLR (1<<3) /* frame list rolled over */ | ||
115 | #define STS_PCD (1<<2) /* port change detect */ | ||
116 | #define STS_ERR (1<<1) /* "error" completion (overflow, ...) */ | ||
117 | #define STS_INT (1<<0) /* "normal" completion (short, ...) */ | ||
118 | |||
119 | #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) | ||
120 | |||
121 | /* USBINTR: offset 0x08 */ | ||
122 | u32 intr_enable; | ||
123 | |||
124 | /* FRINDEX: offset 0x0C */ | ||
125 | u32 frame_index; /* current microframe number */ | ||
126 | /* CTRLDSSEGMENT: offset 0x10 */ | ||
127 | u32 segment; /* address bits 63:32 if needed */ | ||
128 | /* PERIODICLISTBASE: offset 0x14 */ | ||
129 | u32 frame_list; /* points to periodic list */ | ||
130 | /* ASYNCLISTADDR: offset 0x18 */ | ||
131 | u32 async_next; /* address of next async queue head */ | ||
132 | |||
133 | u32 reserved[9]; | ||
134 | |||
135 | /* CONFIGFLAG: offset 0x40 */ | ||
136 | u32 configured_flag; | ||
137 | #define FLAG_CF (1<<0) /* true: we'll support "high speed" */ | ||
138 | |||
139 | /* PORTSC: offset 0x44 */ | ||
140 | u32 port_status[0]; /* up to N_PORTS */ | ||
141 | /* 31:23 reserved */ | ||
142 | #define PORT_WKOC_E (1<<22) /* wake on overcurrent (enable) */ | ||
143 | #define PORT_WKDISC_E (1<<21) /* wake on disconnect (enable) */ | ||
144 | #define PORT_WKCONN_E (1<<20) /* wake on connect (enable) */ | ||
145 | /* 19:16 for port testing */ | ||
146 | #define PORT_LED_OFF (0<<14) | ||
147 | #define PORT_LED_AMBER (1<<14) | ||
148 | #define PORT_LED_GREEN (2<<14) | ||
149 | #define PORT_LED_MASK (3<<14) | ||
150 | #define PORT_OWNER (1<<13) /* true: companion hc owns this port */ | ||
151 | #define PORT_POWER (1<<12) /* true: has power (see PPC) */ | ||
152 | #define PORT_USB11(x) (((x)&(3<<10)) == (1<<10)) /* USB 1.1 device */ | ||
153 | /* 11:10 for detecting lowspeed devices (reset vs release ownership) */ | ||
154 | /* 9 reserved */ | ||
155 | #define PORT_RESET (1<<8) /* reset port */ | ||
156 | #define PORT_SUSPEND (1<<7) /* suspend port */ | ||
157 | #define PORT_RESUME (1<<6) /* resume it */ | ||
158 | #define PORT_OCC (1<<5) /* over current change */ | ||
159 | #define PORT_OC (1<<4) /* over current active */ | ||
160 | #define PORT_PEC (1<<3) /* port enable change */ | ||
161 | #define PORT_PE (1<<2) /* port enable */ | ||
162 | #define PORT_CSC (1<<1) /* connect status change */ | ||
163 | #define PORT_CONNECT (1<<0) /* device connected */ | ||
164 | #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) | ||
165 | } __attribute__ ((packed)); | ||
166 | |||
167 | /* Appendix C, Debug port ... intended for use with special "debug devices" | ||
168 | * that can help if there's no serial console. (nonstandard enumeration.) | ||
169 | */ | ||
170 | struct ehci_dbg_port { | ||
171 | u32 control; | ||
172 | #define DBGP_OWNER (1<<30) | ||
173 | #define DBGP_ENABLED (1<<28) | ||
174 | #define DBGP_DONE (1<<16) | ||
175 | #define DBGP_INUSE (1<<10) | ||
176 | #define DBGP_ERRCODE(x) (((x)>>7)&0x07) | ||
177 | # define DBGP_ERR_BAD 1 | ||
178 | # define DBGP_ERR_SIGNAL 2 | ||
179 | #define DBGP_ERROR (1<<6) | ||
180 | #define DBGP_GO (1<<5) | ||
181 | #define DBGP_OUT (1<<4) | ||
182 | #define DBGP_LEN(x) (((x)>>0)&0x0f) | ||
183 | u32 pids; | ||
184 | #define DBGP_PID_GET(x) (((x)>>16)&0xff) | ||
185 | #define DBGP_PID_SET(data, tok) (((data)<<8)|(tok)) | ||
186 | u32 data03; | ||
187 | u32 data47; | ||
188 | u32 address; | ||
189 | #define DBGP_EPADDR(dev, ep) (((dev)<<8)|(ep)) | ||
190 | } __attribute__ ((packed)); | ||
191 | |||
192 | |||
193 | #define QTD_NEXT(dma) cpu_to_le32((u32)dma) | ||
194 | |||
195 | /* | ||
196 | * EHCI Specification 0.95 Section 3.5 | ||
197 | * QTD: describe data transfer components (buffer, direction, ...) | ||
198 | * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram". | ||
199 | * | ||
200 | * These are associated only with "QH" (Queue Head) structures, | ||
201 | * used with control, bulk, and interrupt transfers. | ||
202 | */ | ||
203 | struct ehci_qtd { | ||
204 | /* first part defined by EHCI spec */ | ||
205 | __le32 hw_next; /* see EHCI 3.5.1 */ | ||
206 | __le32 hw_alt_next; /* see EHCI 3.5.2 */ | ||
207 | __le32 hw_token; /* see EHCI 3.5.3 */ | ||
208 | #define QTD_TOGGLE (1 << 31) /* data toggle */ | ||
209 | #define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff) | ||
210 | #define QTD_IOC (1 << 15) /* interrupt on complete */ | ||
211 | #define QTD_CERR(tok) (((tok)>>10) & 0x3) | ||
212 | #define QTD_PID(tok) (((tok)>>8) & 0x3) | ||
213 | #define QTD_STS_ACTIVE (1 << 7) /* HC may execute this */ | ||
214 | #define QTD_STS_HALT (1 << 6) /* halted on error */ | ||
215 | #define QTD_STS_DBE (1 << 5) /* data buffer error (in HC) */ | ||
216 | #define QTD_STS_BABBLE (1 << 4) /* device was babbling (qtd halted) */ | ||
217 | #define QTD_STS_XACT (1 << 3) /* device gave illegal response */ | ||
218 | #define QTD_STS_MMF (1 << 2) /* incomplete split transaction */ | ||
219 | #define QTD_STS_STS (1 << 1) /* split transaction state */ | ||
220 | #define QTD_STS_PING (1 << 0) /* issue PING? */ | ||
221 | __le32 hw_buf[5]; /* see EHCI 3.5.4 */ | ||
222 | __le32 hw_buf_hi[5]; /* Appendix B */ | ||
223 | |||
224 | /* the rest is HCD-private */ | ||
225 | dma_addr_t qtd_dma; /* qtd address */ | ||
226 | struct list_head qtd_list; /* sw qtd list */ | ||
227 | struct urb *urb; /* qtd's urb */ | ||
228 | size_t length; /* length of buffer */ | ||
229 | |||
230 | u32 qtd_buffer_len; | ||
231 | void *buffer; | ||
232 | dma_addr_t buffer_dma; | ||
233 | void *transfer_buffer; | ||
234 | void *transfer_dma; | ||
235 | } __attribute__ ((aligned(32))); | ||
236 | |||
237 | /* mask NakCnt+T in qh->hw_alt_next */ | ||
238 | #define QTD_MASK __constant_cpu_to_le32 (~0x1f) | ||
239 | |||
240 | #define IS_SHORT_READ(token) (QTD_LENGTH(token) != 0 && QTD_PID(token) == 1) | ||
241 | |||
242 | /* Type tag from {qh, itd, sitd, fstn}->hw_next */ | ||
243 | #define Q_NEXT_TYPE(dma) ((dma) & __constant_cpu_to_le32 (3 << 1)) | ||
244 | |||
245 | /* values for that type tag */ | ||
246 | #define Q_TYPE_QH __constant_cpu_to_le32 (1 << 1) | ||
247 | |||
248 | /* next async queue entry, or pointer to interrupt/periodic QH */ | ||
249 | #define QH_NEXT(dma) (cpu_to_le32(((u32)dma)&~0x01f)|Q_TYPE_QH) | ||
250 | |||
251 | /* for periodic/async schedules and qtd lists, mark end of list */ | ||
252 | #define EHCI_LIST_END __constant_cpu_to_le32(1) /* "null pointer" to hw */ | ||
253 | |||
254 | /* | ||
255 | * Entries in periodic shadow table are pointers to one of four kinds | ||
256 | * of data structure. That's dictated by the hardware; a type tag is | ||
257 | * encoded in the low bits of the hardware's periodic schedule. Use | ||
258 | * Q_NEXT_TYPE to get the tag. | ||
259 | * | ||
260 | * For entries in the async schedule, the type tag always says "qh". | ||
261 | */ | ||
262 | union ehci_shadow { | ||
263 | struct ehci_qh *qh; /* Q_TYPE_QH */ | ||
264 | __le32 *hw_next; /* (all types) */ | ||
265 | void *ptr; | ||
266 | }; | ||
267 | |||
268 | /* | ||
269 | * EHCI Specification 0.95 Section 3.6 | ||
270 | * QH: describes control/bulk/interrupt endpoints | ||
271 | * See Fig 3-7 "Queue Head Structure Layout". | ||
272 | * | ||
273 | * These appear in both the async and (for interrupt) periodic schedules. | ||
274 | */ | ||
275 | |||
276 | struct ehci_qh { | ||
277 | /* first part defined by EHCI spec */ | ||
278 | __le32 hw_next; /* see EHCI 3.6.1 */ | ||
279 | __le32 hw_info1; /* see EHCI 3.6.2 */ | ||
280 | #define QH_HEAD 0x00008000 | ||
281 | __le32 hw_info2; /* see EHCI 3.6.2 */ | ||
282 | #define QH_SMASK 0x000000ff | ||
283 | #define QH_CMASK 0x0000ff00 | ||
284 | #define QH_HUBADDR 0x007f0000 | ||
285 | #define QH_HUBPORT 0x3f800000 | ||
286 | #define QH_MULT 0xc0000000 | ||
287 | __le32 hw_current; /* qtd list - see EHCI 3.6.4 */ | ||
288 | |||
289 | /* qtd overlay (hardware parts of a struct ehci_qtd) */ | ||
290 | __le32 hw_qtd_next; | ||
291 | __le32 hw_alt_next; | ||
292 | __le32 hw_token; | ||
293 | __le32 hw_buf[5]; | ||
294 | __le32 hw_buf_hi[5]; | ||
295 | |||
296 | /* the rest is HCD-private */ | ||
297 | dma_addr_t qh_dma; /* address of qh */ | ||
298 | union ehci_shadow qh_next; /* ptr to qh; or periodic */ | ||
299 | struct list_head qtd_list; /* sw qtd list */ | ||
300 | struct ehci_qtd *dummy; | ||
301 | struct ehci_qh *reclaim; /* next to reclaim */ | ||
302 | |||
303 | struct oxu_hcd *oxu; | ||
304 | struct kref kref; | ||
305 | unsigned stamp; | ||
306 | |||
307 | u8 qh_state; | ||
308 | #define QH_STATE_LINKED 1 /* HC sees this */ | ||
309 | #define QH_STATE_UNLINK 2 /* HC may still see this */ | ||
310 | #define QH_STATE_IDLE 3 /* HC doesn't see this */ | ||
311 | #define QH_STATE_UNLINK_WAIT 4 /* LINKED and on reclaim q */ | ||
312 | #define QH_STATE_COMPLETING 5 /* don't touch token.HALT */ | ||
313 | |||
314 | /* periodic schedule info */ | ||
315 | u8 usecs; /* intr bandwidth */ | ||
316 | u8 gap_uf; /* uframes split/csplit gap */ | ||
317 | u8 c_usecs; /* ... split completion bw */ | ||
318 | u16 tt_usecs; /* tt downstream bandwidth */ | ||
319 | unsigned short period; /* polling interval */ | ||
320 | unsigned short start; /* where polling starts */ | ||
321 | #define NO_FRAME ((unsigned short)~0) /* pick new start */ | ||
322 | struct usb_device *dev; /* access to TT */ | ||
323 | } __attribute__ ((aligned(32))); | ||
324 | |||
325 | /* | ||
326 | * Proper OXU210HP structs | ||
327 | */ | ||
328 | |||
329 | #define OXU_OTG_CORE_OFFSET 0x00400 | ||
330 | #define OXU_OTG_CAP_OFFSET (OXU_OTG_CORE_OFFSET + 0x100) | ||
331 | #define OXU_SPH_CORE_OFFSET 0x00800 | ||
332 | #define OXU_SPH_CAP_OFFSET (OXU_SPH_CORE_OFFSET + 0x100) | ||
333 | |||
334 | #define OXU_OTG_MEM 0xE000 | ||
335 | #define OXU_SPH_MEM 0x16000 | ||
336 | |||
337 | /* Only how many elements & element structure are specifies here. */ | ||
338 | /* 2 host controllers are enabled - total size <= 28 kbytes */ | ||
339 | #define DEFAULT_I_TDPS 1024 | ||
340 | #define QHEAD_NUM 16 | ||
341 | #define QTD_NUM 32 | ||
342 | #define SITD_NUM 8 | ||
343 | #define MURB_NUM 8 | ||
344 | |||
345 | #define BUFFER_NUM 8 | ||
346 | #define BUFFER_SIZE 512 | ||
347 | |||
348 | struct oxu_info { | ||
349 | struct usb_hcd *hcd[2]; | ||
350 | }; | ||
351 | |||
352 | struct oxu_buf { | ||
353 | u8 buffer[BUFFER_SIZE]; | ||
354 | } __attribute__ ((aligned(BUFFER_SIZE))); | ||
355 | |||
356 | struct oxu_onchip_mem { | ||
357 | struct oxu_buf db_pool[BUFFER_NUM]; | ||
358 | |||
359 | u32 frame_list[DEFAULT_I_TDPS]; | ||
360 | struct ehci_qh qh_pool[QHEAD_NUM]; | ||
361 | struct ehci_qtd qtd_pool[QTD_NUM]; | ||
362 | } __attribute__ ((aligned(4 << 10))); | ||
363 | |||
364 | #define EHCI_MAX_ROOT_PORTS 15 /* see HCS_N_PORTS */ | ||
365 | |||
366 | struct oxu_murb { | ||
367 | struct urb urb; | ||
368 | struct urb *main; | ||
369 | u8 last; | ||
370 | }; | ||
371 | |||
372 | struct oxu_hcd { /* one per controller */ | ||
373 | unsigned int is_otg:1; | ||
374 | |||
375 | u8 qh_used[QHEAD_NUM]; | ||
376 | u8 qtd_used[QTD_NUM]; | ||
377 | u8 db_used[BUFFER_NUM]; | ||
378 | u8 murb_used[MURB_NUM]; | ||
379 | |||
380 | struct oxu_onchip_mem __iomem *mem; | ||
381 | spinlock_t mem_lock; | ||
382 | |||
383 | struct timer_list urb_timer; | ||
384 | |||
385 | struct ehci_caps __iomem *caps; | ||
386 | struct ehci_regs __iomem *regs; | ||
387 | |||
388 | __u32 hcs_params; /* cached register copy */ | ||
389 | spinlock_t lock; | ||
390 | |||
391 | /* async schedule support */ | ||
392 | struct ehci_qh *async; | ||
393 | struct ehci_qh *reclaim; | ||
394 | unsigned reclaim_ready:1; | ||
395 | unsigned scanning:1; | ||
396 | |||
397 | /* periodic schedule support */ | ||
398 | unsigned periodic_size; | ||
399 | __le32 *periodic; /* hw periodic table */ | ||
400 | dma_addr_t periodic_dma; | ||
401 | unsigned i_thresh; /* uframes HC might cache */ | ||
402 | |||
403 | union ehci_shadow *pshadow; /* mirror hw periodic table */ | ||
404 | int next_uframe; /* scan periodic, start here */ | ||
405 | unsigned periodic_sched; /* periodic activity count */ | ||
406 | |||
407 | /* per root hub port */ | ||
408 | unsigned long reset_done[EHCI_MAX_ROOT_PORTS]; | ||
409 | /* bit vectors (one bit per port) */ | ||
410 | unsigned long bus_suspended; /* which ports were | ||
411 | * already suspended at the | ||
412 | * start of a bus suspend | ||
413 | */ | ||
414 | unsigned long companion_ports;/* which ports are dedicated | ||
415 | * to the companion controller | ||
416 | */ | ||
417 | |||
418 | struct timer_list watchdog; | ||
419 | unsigned long actions; | ||
420 | unsigned stamp; | ||
421 | unsigned long next_statechange; | ||
422 | u32 command; | ||
423 | |||
424 | /* SILICON QUIRKS */ | ||
425 | struct list_head urb_list; /* this is the head to urb | ||
426 | * queue that didn't get enough | ||
427 | * resources | ||
428 | */ | ||
429 | struct oxu_murb *murb_pool; /* murb per split big urb */ | ||
430 | unsigned urb_len; | ||
431 | |||
432 | u8 sbrn; /* packed release number */ | ||
433 | }; | ||
434 | |||
435 | #define EHCI_IAA_JIFFIES (HZ/100) /* arbitrary; ~10 msec */ | ||
436 | #define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ | ||
437 | #define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */ | ||
438 | #define EHCI_SHRINK_JIFFIES (HZ/200) /* async qh unlink delay */ | ||
439 | |||
440 | enum ehci_timer_action { | ||
441 | TIMER_IO_WATCHDOG, | ||
442 | TIMER_IAA_WATCHDOG, | ||
443 | TIMER_ASYNC_SHRINK, | ||
444 | TIMER_ASYNC_OFF, | ||
445 | }; | ||
446 | |||
447 | #include <linux/oxu210hp.h> | ||
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c index ae6e70edd745..75b69847918e 100644 --- a/drivers/usb/host/pci-quirks.c +++ b/drivers/usb/host/pci-quirks.c | |||
@@ -172,9 +172,9 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev) | |||
172 | if (!mmio_resource_enabled(pdev, 0)) | 172 | if (!mmio_resource_enabled(pdev, 0)) |
173 | return; | 173 | return; |
174 | 174 | ||
175 | base = ioremap_nocache(pci_resource_start(pdev, 0), | 175 | base = pci_ioremap_bar(pdev, 0); |
176 | pci_resource_len(pdev, 0)); | 176 | if (base == NULL) |
177 | if (base == NULL) return; | 177 | return; |
178 | 178 | ||
179 | /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */ | 179 | /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */ |
180 | #ifndef __hppa__ | 180 | #ifndef __hppa__ |
@@ -221,9 +221,9 @@ static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev) | |||
221 | if (!mmio_resource_enabled(pdev, 0)) | 221 | if (!mmio_resource_enabled(pdev, 0)) |
222 | return; | 222 | return; |
223 | 223 | ||
224 | base = ioremap_nocache(pci_resource_start(pdev, 0), | 224 | base = pci_ioremap_bar(pdev, 0); |
225 | pci_resource_len(pdev, 0)); | 225 | if (base == NULL) |
226 | if (base == NULL) return; | 226 | return; |
227 | 227 | ||
228 | cap_length = readb(base); | 228 | cap_length = readb(base); |
229 | op_reg_base = base + cap_length; | 229 | op_reg_base = base + cap_length; |
@@ -271,7 +271,7 @@ static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev) | |||
271 | /* if boot firmware now owns EHCI, spin till | 271 | /* if boot firmware now owns EHCI, spin till |
272 | * it hands it over. | 272 | * it hands it over. |
273 | */ | 273 | */ |
274 | msec = 5000; | 274 | msec = 1000; |
275 | while ((cap & EHCI_USBLEGSUP_BIOS) && (msec > 0)) { | 275 | while ((cap & EHCI_USBLEGSUP_BIOS) && (msec > 0)) { |
276 | tried_handoff = 1; | 276 | tried_handoff = 1; |
277 | msleep(10); | 277 | msleep(10); |
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c index c21f14e0666a..319041205b57 100644 --- a/drivers/usb/host/r8a66597-hcd.c +++ b/drivers/usb/host/r8a66597-hcd.c | |||
@@ -2275,7 +2275,6 @@ static int __init_or_module r8a66597_remove(struct platform_device *pdev) | |||
2275 | return 0; | 2275 | return 0; |
2276 | } | 2276 | } |
2277 | 2277 | ||
2278 | #define resource_len(r) (((r)->end - (r)->start) + 1) | ||
2279 | static int __init r8a66597_probe(struct platform_device *pdev) | 2278 | static int __init r8a66597_probe(struct platform_device *pdev) |
2280 | { | 2279 | { |
2281 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK) | 2280 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK) |
@@ -2296,11 +2295,10 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
2296 | goto clean_up; | 2295 | goto clean_up; |
2297 | } | 2296 | } |
2298 | 2297 | ||
2299 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | 2298 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
2300 | (char *)hcd_name); | ||
2301 | if (!res) { | 2299 | if (!res) { |
2302 | ret = -ENODEV; | 2300 | ret = -ENODEV; |
2303 | dev_err(&pdev->dev, "platform_get_resource_byname error.\n"); | 2301 | dev_err(&pdev->dev, "platform_get_resource error.\n"); |
2304 | goto clean_up; | 2302 | goto clean_up; |
2305 | } | 2303 | } |
2306 | 2304 | ||
@@ -2315,7 +2313,7 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
2315 | irq = ires->start; | 2313 | irq = ires->start; |
2316 | irq_trigger = ires->flags & IRQF_TRIGGER_MASK; | 2314 | irq_trigger = ires->flags & IRQF_TRIGGER_MASK; |
2317 | 2315 | ||
2318 | reg = ioremap(res->start, resource_len(res)); | 2316 | reg = ioremap(res->start, resource_size(res)); |
2319 | if (reg == NULL) { | 2317 | if (reg == NULL) { |
2320 | ret = -ENOMEM; | 2318 | ret = -ENOMEM; |
2321 | dev_err(&pdev->dev, "ioremap error.\n"); | 2319 | dev_err(&pdev->dev, "ioremap error.\n"); |
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c index cf5e4cf7ea42..4e221060f58c 100644 --- a/drivers/usb/host/uhci-hcd.c +++ b/drivers/usb/host/uhci-hcd.c | |||
@@ -942,6 +942,8 @@ static struct pci_driver uhci_pci_driver = { | |||
942 | 942 | ||
943 | #ifdef CONFIG_PM | 943 | #ifdef CONFIG_PM |
944 | .suspend = usb_hcd_pci_suspend, | 944 | .suspend = usb_hcd_pci_suspend, |
945 | .suspend_late = usb_hcd_pci_suspend_late, | ||
946 | .resume_early = usb_hcd_pci_resume_early, | ||
945 | .resume = usb_hcd_pci_resume, | 947 | .resume = usb_hcd_pci_resume, |
946 | #endif /* PM */ | 948 | #endif /* PM */ |
947 | }; | 949 | }; |
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c index 885867a86de8..4541dfcea88f 100644 --- a/drivers/usb/image/microtek.c +++ b/drivers/usb/image/microtek.c | |||
@@ -350,17 +350,16 @@ static int mts_scsi_abort(struct scsi_cmnd *srb) | |||
350 | static int mts_scsi_host_reset(struct scsi_cmnd *srb) | 350 | static int mts_scsi_host_reset(struct scsi_cmnd *srb) |
351 | { | 351 | { |
352 | struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]); | 352 | struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]); |
353 | int result, rc; | 353 | int result; |
354 | 354 | ||
355 | MTS_DEBUG_GOT_HERE(); | 355 | MTS_DEBUG_GOT_HERE(); |
356 | mts_debug_dump(desc); | 356 | mts_debug_dump(desc); |
357 | 357 | ||
358 | rc = usb_lock_device_for_reset(desc->usb_dev, desc->usb_intf); | 358 | result = usb_lock_device_for_reset(desc->usb_dev, desc->usb_intf); |
359 | if (rc < 0) | 359 | if (result == 0) { |
360 | return FAILED; | 360 | result = usb_reset_device(desc->usb_dev); |
361 | result = usb_reset_device(desc->usb_dev); | ||
362 | if (rc) | ||
363 | usb_unlock_device(desc->usb_dev); | 361 | usb_unlock_device(desc->usb_dev); |
362 | } | ||
364 | return result ? FAILED : SUCCESS; | 363 | return result ? FAILED : SUCCESS; |
365 | } | 364 | } |
366 | 365 | ||
diff --git a/drivers/usb/misc/berry_charge.c b/drivers/usb/misc/berry_charge.c index 24e2dc3148a4..c05a85bc5925 100644 --- a/drivers/usb/misc/berry_charge.c +++ b/drivers/usb/misc/berry_charge.c | |||
@@ -123,6 +123,11 @@ static int berry_probe(struct usb_interface *intf, | |||
123 | { | 123 | { |
124 | struct usb_device *udev = interface_to_usbdev(intf); | 124 | struct usb_device *udev = interface_to_usbdev(intf); |
125 | 125 | ||
126 | if (udev->bus_mA < 500) { | ||
127 | dbg(&udev->dev, "Not enough power to charge available\n"); | ||
128 | return -ENODEV; | ||
129 | } | ||
130 | |||
126 | dbg(&udev->dev, "Power is set to %dmA\n", | 131 | dbg(&udev->dev, "Power is set to %dmA\n", |
127 | udev->actconfig->desc.bMaxPower * 2); | 132 | udev->actconfig->desc.bMaxPower * 2); |
128 | 133 | ||
diff --git a/drivers/usb/misc/emi26.c b/drivers/usb/misc/emi26.c index e762beb5f3c6..879a980ca8c4 100644 --- a/drivers/usb/misc/emi26.c +++ b/drivers/usb/misc/emi26.c | |||
@@ -160,7 +160,7 @@ static int emi26_load_firmware (struct usb_device *dev) | |||
160 | err("%s - error loading firmware: error = %d", __func__, err); | 160 | err("%s - error loading firmware: error = %d", __func__, err); |
161 | goto wraperr; | 161 | goto wraperr; |
162 | } | 162 | } |
163 | } while (i > 0); | 163 | } while (rec); |
164 | 164 | ||
165 | /* Assert reset (stop the CPU in the EMI) */ | 165 | /* Assert reset (stop the CPU in the EMI) */ |
166 | err = emi26_set_reset(dev,1); | 166 | err = emi26_set_reset(dev,1); |
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index 444c69c447be..5f1a19d1497d 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c | |||
@@ -192,8 +192,6 @@ static struct urb *simple_alloc_urb ( | |||
192 | { | 192 | { |
193 | struct urb *urb; | 193 | struct urb *urb; |
194 | 194 | ||
195 | if (bytes < 0) | ||
196 | return NULL; | ||
197 | urb = usb_alloc_urb (0, GFP_KERNEL); | 195 | urb = usb_alloc_urb (0, GFP_KERNEL); |
198 | if (!urb) | 196 | if (!urb) |
199 | return urb; | 197 | return urb; |
diff --git a/drivers/usb/mon/Kconfig b/drivers/usb/mon/Kconfig index deb9ddffa402..f28f350cd96a 100644 --- a/drivers/usb/mon/Kconfig +++ b/drivers/usb/mon/Kconfig | |||
@@ -3,14 +3,13 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | config USB_MON | 5 | config USB_MON |
6 | bool "USB Monitor" | 6 | tristate "USB Monitor" |
7 | depends on USB!=n | 7 | depends on USB |
8 | default y | 8 | default y if USB=y |
9 | default m if USB=m | ||
9 | help | 10 | help |
10 | If you say Y here, a component which captures the USB traffic | 11 | If you select this option, a component which captures the USB traffic |
11 | between peripheral-specific drivers and HC drivers will be built. | 12 | between peripheral-specific drivers and HC drivers will be built. |
12 | For more information, see <file:Documentation/usb/usbmon.txt>. | 13 | For more information, see <file:Documentation/usb/usbmon.txt>. |
13 | 14 | ||
14 | This is somewhat experimental at this time, but it should be safe. | 15 | If unsure, say Y (if allowed), otherwise M. |
15 | |||
16 | If unsure, say Y. | ||
diff --git a/drivers/usb/mon/Makefile b/drivers/usb/mon/Makefile index 0f76ed5e1617..c6516b566731 100644 --- a/drivers/usb/mon/Makefile +++ b/drivers/usb/mon/Makefile | |||
@@ -4,5 +4,4 @@ | |||
4 | 4 | ||
5 | usbmon-objs := mon_main.o mon_stat.o mon_text.o mon_bin.o mon_dma.o | 5 | usbmon-objs := mon_main.o mon_stat.o mon_text.o mon_bin.o mon_dma.o |
6 | 6 | ||
7 | # This does not use CONFIG_USB_MON because we want this to use a tristate. | 7 | obj-$(CONFIG_USB_MON) += usbmon.o |
8 | obj-$(CONFIG_USB) += usbmon.o | ||
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig index 4b9542bbb35c..5af7379cd9a3 100644 --- a/drivers/usb/musb/Kconfig +++ b/drivers/usb/musb/Kconfig | |||
@@ -11,7 +11,7 @@ config USB_MUSB_HDRC | |||
11 | depends on (USB || USB_GADGET) && HAVE_CLK | 11 | depends on (USB || USB_GADGET) && HAVE_CLK |
12 | depends on !SUPERH | 12 | depends on !SUPERH |
13 | select TWL4030_USB if MACH_OMAP_3430SDP | 13 | select TWL4030_USB if MACH_OMAP_3430SDP |
14 | tristate 'Inventra Highspeed Dual Role Controller (TI, ...)' | 14 | tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' |
15 | help | 15 | help |
16 | Say Y here if your system has a dual role high speed USB | 16 | Say Y here if your system has a dual role high speed USB |
17 | controller based on the Mentor Graphics silicon IP. Then | 17 | controller based on the Mentor Graphics silicon IP. Then |
@@ -22,6 +22,9 @@ config USB_MUSB_HDRC | |||
22 | Texas Instruments parts using this IP include DaVinci 644x, | 22 | Texas Instruments parts using this IP include DaVinci 644x, |
23 | OMAP 243x, OMAP 343x, and TUSB 6010. | 23 | OMAP 243x, OMAP 343x, and TUSB 6010. |
24 | 24 | ||
25 | Analog Devices parts using this IP include Blackfin BF54x, | ||
26 | BF525 and BF527. | ||
27 | |||
25 | If you do not know what this is, please say N. | 28 | If you do not know what this is, please say N. |
26 | 29 | ||
27 | To compile this driver as a module, choose M here; the | 30 | To compile this driver as a module, choose M here; the |
@@ -33,6 +36,8 @@ config USB_MUSB_SOC | |||
33 | default y if ARCH_DAVINCI | 36 | default y if ARCH_DAVINCI |
34 | default y if ARCH_OMAP2430 | 37 | default y if ARCH_OMAP2430 |
35 | default y if ARCH_OMAP34XX | 38 | default y if ARCH_OMAP34XX |
39 | default y if (BF54x && !BF544) | ||
40 | default y if (BF52x && !BF522 && !BF523) | ||
36 | 41 | ||
37 | comment "DaVinci 644x USB support" | 42 | comment "DaVinci 644x USB support" |
38 | depends on USB_MUSB_HDRC && ARCH_DAVINCI | 43 | depends on USB_MUSB_HDRC && ARCH_DAVINCI |
@@ -43,6 +48,9 @@ comment "OMAP 243x high speed USB support" | |||
43 | comment "OMAP 343x high speed USB support" | 48 | comment "OMAP 343x high speed USB support" |
44 | depends on USB_MUSB_HDRC && ARCH_OMAP34XX | 49 | depends on USB_MUSB_HDRC && ARCH_OMAP34XX |
45 | 50 | ||
51 | comment "Blackfin high speed USB Support" | ||
52 | depends on USB_MUSB_HDRC && (BF54x && !BF544) || (BF52x && !BF522 && !BF523) | ||
53 | |||
46 | config USB_TUSB6010 | 54 | config USB_TUSB6010 |
47 | boolean "TUSB 6010 support" | 55 | boolean "TUSB 6010 support" |
48 | depends on USB_MUSB_HDRC && !USB_MUSB_SOC | 56 | depends on USB_MUSB_HDRC && !USB_MUSB_SOC |
@@ -142,7 +150,7 @@ config MUSB_PIO_ONLY | |||
142 | config USB_INVENTRA_DMA | 150 | config USB_INVENTRA_DMA |
143 | bool | 151 | bool |
144 | depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY | 152 | depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY |
145 | default ARCH_OMAP2430 || ARCH_OMAP34XX | 153 | default ARCH_OMAP2430 || ARCH_OMAP34XX || BLACKFIN |
146 | help | 154 | help |
147 | Enable DMA transfers using Mentor's engine. | 155 | Enable DMA transfers using Mentor's engine. |
148 | 156 | ||
diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile index b6af0d687a73..85710ccc1887 100644 --- a/drivers/usb/musb/Makefile +++ b/drivers/usb/musb/Makefile | |||
@@ -22,6 +22,14 @@ ifeq ($(CONFIG_ARCH_OMAP3430),y) | |||
22 | musb_hdrc-objs += omap2430.o | 22 | musb_hdrc-objs += omap2430.o |
23 | endif | 23 | endif |
24 | 24 | ||
25 | ifeq ($(CONFIG_BF54x),y) | ||
26 | musb_hdrc-objs += blackfin.o | ||
27 | endif | ||
28 | |||
29 | ifeq ($(CONFIG_BF52x),y) | ||
30 | musb_hdrc-objs += blackfin.o | ||
31 | endif | ||
32 | |||
25 | ifeq ($(CONFIG_USB_GADGET_MUSB_HDRC),y) | 33 | ifeq ($(CONFIG_USB_GADGET_MUSB_HDRC),y) |
26 | musb_hdrc-objs += musb_gadget_ep0.o musb_gadget.o | 34 | musb_hdrc-objs += musb_gadget_ep0.o musb_gadget.o |
27 | endif | 35 | endif |
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c new file mode 100644 index 000000000000..786134852092 --- /dev/null +++ b/drivers/usb/musb/blackfin.c | |||
@@ -0,0 +1,320 @@ | |||
1 | /* | ||
2 | * MUSB OTG controller driver for Blackfin Processors | ||
3 | * | ||
4 | * Copyright 2006-2008 Analog Devices Inc. | ||
5 | * | ||
6 | * Enter bugs at http://blackfin.uclinux.org/ | ||
7 | * | ||
8 | * Licensed under the GPL-2 or later. | ||
9 | */ | ||
10 | |||
11 | #include <linux/module.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/sched.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/list.h> | ||
17 | #include <linux/clk.h> | ||
18 | #include <linux/gpio.h> | ||
19 | #include <linux/io.h> | ||
20 | |||
21 | #include <asm/cacheflush.h> | ||
22 | |||
23 | #include "musb_core.h" | ||
24 | #include "blackfin.h" | ||
25 | |||
26 | /* | ||
27 | * Load an endpoint's FIFO | ||
28 | */ | ||
29 | void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src) | ||
30 | { | ||
31 | void __iomem *fifo = hw_ep->fifo; | ||
32 | void __iomem *epio = hw_ep->regs; | ||
33 | |||
34 | prefetch((u8 *)src); | ||
35 | |||
36 | musb_writew(epio, MUSB_TXCOUNT, len); | ||
37 | |||
38 | DBG(4, "TX ep%d fifo %p count %d buf %p, epio %p\n", | ||
39 | hw_ep->epnum, fifo, len, src, epio); | ||
40 | |||
41 | dump_fifo_data(src, len); | ||
42 | |||
43 | if (unlikely((unsigned long)src & 0x01)) | ||
44 | outsw_8((unsigned long)fifo, src, | ||
45 | len & 0x01 ? (len >> 1) + 1 : len >> 1); | ||
46 | else | ||
47 | outsw((unsigned long)fifo, src, | ||
48 | len & 0x01 ? (len >> 1) + 1 : len >> 1); | ||
49 | } | ||
50 | |||
51 | /* | ||
52 | * Unload an endpoint's FIFO | ||
53 | */ | ||
54 | void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) | ||
55 | { | ||
56 | void __iomem *fifo = hw_ep->fifo; | ||
57 | u8 epnum = hw_ep->epnum; | ||
58 | u16 dma_reg = 0; | ||
59 | |||
60 | DBG(4, "%cX ep%d fifo %p count %d buf %p\n", | ||
61 | 'R', hw_ep->epnum, fifo, len, dst); | ||
62 | |||
63 | #ifdef CONFIG_BF52x | ||
64 | invalidate_dcache_range((unsigned int)dst, | ||
65 | (unsigned int)(dst + len)); | ||
66 | |||
67 | /* Setup DMA address register */ | ||
68 | dma_reg = (u16) ((u32) dst & 0xFFFF); | ||
69 | bfin_write16(USB_DMA_REG(epnum, USB_DMAx_ADDR_LOW), dma_reg); | ||
70 | SSYNC(); | ||
71 | |||
72 | dma_reg = (u16) (((u32) dst >> 16) & 0xFFFF); | ||
73 | bfin_write16(USB_DMA_REG(epnum, USB_DMAx_ADDR_HIGH), dma_reg); | ||
74 | SSYNC(); | ||
75 | |||
76 | /* Setup DMA count register */ | ||
77 | bfin_write16(USB_DMA_REG(epnum, USB_DMAx_COUNT_LOW), len); | ||
78 | bfin_write16(USB_DMA_REG(epnum, USB_DMAx_COUNT_HIGH), 0); | ||
79 | SSYNC(); | ||
80 | |||
81 | /* Enable the DMA */ | ||
82 | dma_reg = (epnum << 4) | DMA_ENA | INT_ENA; | ||
83 | bfin_write16(USB_DMA_REG(epnum, USB_DMAx_CTRL), dma_reg); | ||
84 | SSYNC(); | ||
85 | |||
86 | /* Wait for compelete */ | ||
87 | while (!(bfin_read_USB_DMA_INTERRUPT() & (1 << epnum))) | ||
88 | cpu_relax(); | ||
89 | |||
90 | /* acknowledge dma interrupt */ | ||
91 | bfin_write_USB_DMA_INTERRUPT(1 << epnum); | ||
92 | SSYNC(); | ||
93 | |||
94 | /* Reset DMA */ | ||
95 | bfin_write16(USB_DMA_REG(epnum, USB_DMAx_CTRL), 0); | ||
96 | SSYNC(); | ||
97 | #else | ||
98 | if (unlikely((unsigned long)dst & 0x01)) | ||
99 | insw_8((unsigned long)fifo, dst, | ||
100 | len & 0x01 ? (len >> 1) + 1 : len >> 1); | ||
101 | else | ||
102 | insw((unsigned long)fifo, dst, | ||
103 | len & 0x01 ? (len >> 1) + 1 : len >> 1); | ||
104 | #endif | ||
105 | |||
106 | dump_fifo_data(dst, len); | ||
107 | } | ||
108 | |||
109 | static irqreturn_t blackfin_interrupt(int irq, void *__hci) | ||
110 | { | ||
111 | unsigned long flags; | ||
112 | irqreturn_t retval = IRQ_NONE; | ||
113 | struct musb *musb = __hci; | ||
114 | |||
115 | spin_lock_irqsave(&musb->lock, flags); | ||
116 | |||
117 | musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); | ||
118 | musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); | ||
119 | musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); | ||
120 | |||
121 | if (musb->int_usb || musb->int_tx || musb->int_rx) { | ||
122 | musb_writeb(musb->mregs, MUSB_INTRUSB, musb->int_usb); | ||
123 | musb_writew(musb->mregs, MUSB_INTRTX, musb->int_tx); | ||
124 | musb_writew(musb->mregs, MUSB_INTRRX, musb->int_rx); | ||
125 | retval = musb_interrupt(musb); | ||
126 | } | ||
127 | |||
128 | spin_unlock_irqrestore(&musb->lock, flags); | ||
129 | |||
130 | /* REVISIT we sometimes get spurious IRQs on g_ep0 | ||
131 | * not clear why... fall in BF54x too. | ||
132 | */ | ||
133 | if (retval != IRQ_HANDLED) | ||
134 | DBG(5, "spurious?\n"); | ||
135 | |||
136 | return IRQ_HANDLED; | ||
137 | } | ||
138 | |||
139 | static void musb_conn_timer_handler(unsigned long _musb) | ||
140 | { | ||
141 | struct musb *musb = (void *)_musb; | ||
142 | unsigned long flags; | ||
143 | u16 val; | ||
144 | |||
145 | spin_lock_irqsave(&musb->lock, flags); | ||
146 | switch (musb->xceiv.state) { | ||
147 | case OTG_STATE_A_IDLE: | ||
148 | case OTG_STATE_A_WAIT_BCON: | ||
149 | /* Start a new session */ | ||
150 | val = musb_readw(musb->mregs, MUSB_DEVCTL); | ||
151 | val |= MUSB_DEVCTL_SESSION; | ||
152 | musb_writew(musb->mregs, MUSB_DEVCTL, val); | ||
153 | |||
154 | val = musb_readw(musb->mregs, MUSB_DEVCTL); | ||
155 | if (!(val & MUSB_DEVCTL_BDEVICE)) { | ||
156 | gpio_set_value(musb->config->gpio_vrsel, 1); | ||
157 | musb->xceiv.state = OTG_STATE_A_WAIT_BCON; | ||
158 | } else { | ||
159 | gpio_set_value(musb->config->gpio_vrsel, 0); | ||
160 | |||
161 | /* Ignore VBUSERROR and SUSPEND IRQ */ | ||
162 | val = musb_readb(musb->mregs, MUSB_INTRUSBE); | ||
163 | val &= ~MUSB_INTR_VBUSERROR; | ||
164 | musb_writeb(musb->mregs, MUSB_INTRUSBE, val); | ||
165 | |||
166 | val = MUSB_INTR_SUSPEND | MUSB_INTR_VBUSERROR; | ||
167 | musb_writeb(musb->mregs, MUSB_INTRUSB, val); | ||
168 | |||
169 | val = MUSB_POWER_HSENAB; | ||
170 | musb_writeb(musb->mregs, MUSB_POWER, val); | ||
171 | } | ||
172 | mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); | ||
173 | break; | ||
174 | |||
175 | default: | ||
176 | DBG(1, "%s state not handled\n", otg_state_string(musb)); | ||
177 | break; | ||
178 | } | ||
179 | spin_unlock_irqrestore(&musb->lock, flags); | ||
180 | |||
181 | DBG(4, "state is %s\n", otg_state_string(musb)); | ||
182 | } | ||
183 | |||
184 | void musb_platform_enable(struct musb *musb) | ||
185 | { | ||
186 | if (is_host_enabled(musb)) { | ||
187 | mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); | ||
188 | musb->a_wait_bcon = TIMER_DELAY; | ||
189 | } | ||
190 | } | ||
191 | |||
192 | void musb_platform_disable(struct musb *musb) | ||
193 | { | ||
194 | } | ||
195 | |||
196 | static void bfin_vbus_power(struct musb *musb, int is_on, int sleeping) | ||
197 | { | ||
198 | } | ||
199 | |||
200 | static void bfin_set_vbus(struct musb *musb, int is_on) | ||
201 | { | ||
202 | if (is_on) | ||
203 | gpio_set_value(musb->config->gpio_vrsel, 1); | ||
204 | else | ||
205 | gpio_set_value(musb->config->gpio_vrsel, 0); | ||
206 | |||
207 | DBG(1, "VBUS %s, devctl %02x " | ||
208 | /* otg %3x conf %08x prcm %08x */ "\n", | ||
209 | otg_state_string(musb), | ||
210 | musb_readb(musb->mregs, MUSB_DEVCTL)); | ||
211 | } | ||
212 | |||
213 | static int bfin_set_power(struct otg_transceiver *x, unsigned mA) | ||
214 | { | ||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | void musb_platform_try_idle(struct musb *musb, unsigned long timeout) | ||
219 | { | ||
220 | if (is_host_enabled(musb)) | ||
221 | mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); | ||
222 | } | ||
223 | |||
224 | int musb_platform_get_vbus_status(struct musb *musb) | ||
225 | { | ||
226 | return 0; | ||
227 | } | ||
228 | |||
229 | void musb_platform_set_mode(struct musb *musb, u8 musb_mode) | ||
230 | { | ||
231 | } | ||
232 | |||
233 | int __init musb_platform_init(struct musb *musb) | ||
234 | { | ||
235 | |||
236 | /* | ||
237 | * Rev 1.0 BF549 EZ-KITs require PE7 to be high for both DEVICE | ||
238 | * and OTG HOST modes, while rev 1.1 and greater require PE7 to | ||
239 | * be low for DEVICE mode and high for HOST mode. We set it high | ||
240 | * here because we are in host mode | ||
241 | */ | ||
242 | |||
243 | if (gpio_request(musb->config->gpio_vrsel, "USB_VRSEL")) { | ||
244 | printk(KERN_ERR "Failed ro request USB_VRSEL GPIO_%d \n", | ||
245 | musb->config->gpio_vrsel); | ||
246 | return -ENODEV; | ||
247 | } | ||
248 | gpio_direction_output(musb->config->gpio_vrsel, 0); | ||
249 | |||
250 | if (ANOMALY_05000346) { | ||
251 | bfin_write_USB_APHY_CALIB(ANOMALY_05000346_value); | ||
252 | SSYNC(); | ||
253 | } | ||
254 | |||
255 | if (ANOMALY_05000347) { | ||
256 | bfin_write_USB_APHY_CNTRL(0x0); | ||
257 | SSYNC(); | ||
258 | } | ||
259 | |||
260 | /* TODO | ||
261 | * Set SIC-IVG register | ||
262 | */ | ||
263 | |||
264 | /* Configure PLL oscillator register */ | ||
265 | bfin_write_USB_PLLOSC_CTRL(0x30a8); | ||
266 | SSYNC(); | ||
267 | |||
268 | bfin_write_USB_SRP_CLKDIV((get_sclk()/1000) / 32 - 1); | ||
269 | SSYNC(); | ||
270 | |||
271 | bfin_write_USB_EP_NI0_RXMAXP(64); | ||
272 | SSYNC(); | ||
273 | |||
274 | bfin_write_USB_EP_NI0_TXMAXP(64); | ||
275 | SSYNC(); | ||
276 | |||
277 | /* Route INTRUSB/INTR_RX/INTR_TX to USB_INT0*/ | ||
278 | bfin_write_USB_GLOBINTR(0x7); | ||
279 | SSYNC(); | ||
280 | |||
281 | bfin_write_USB_GLOBAL_CTL(GLOBAL_ENA | EP1_TX_ENA | EP2_TX_ENA | | ||
282 | EP3_TX_ENA | EP4_TX_ENA | EP5_TX_ENA | | ||
283 | EP6_TX_ENA | EP7_TX_ENA | EP1_RX_ENA | | ||
284 | EP2_RX_ENA | EP3_RX_ENA | EP4_RX_ENA | | ||
285 | EP5_RX_ENA | EP6_RX_ENA | EP7_RX_ENA); | ||
286 | SSYNC(); | ||
287 | |||
288 | if (is_host_enabled(musb)) { | ||
289 | musb->board_set_vbus = bfin_set_vbus; | ||
290 | setup_timer(&musb_conn_timer, | ||
291 | musb_conn_timer_handler, (unsigned long) musb); | ||
292 | } | ||
293 | if (is_peripheral_enabled(musb)) | ||
294 | musb->xceiv.set_power = bfin_set_power; | ||
295 | |||
296 | musb->isr = blackfin_interrupt; | ||
297 | |||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | int musb_platform_suspend(struct musb *musb) | ||
302 | { | ||
303 | return 0; | ||
304 | } | ||
305 | |||
306 | int musb_platform_resume(struct musb *musb) | ||
307 | { | ||
308 | return 0; | ||
309 | } | ||
310 | |||
311 | |||
312 | int musb_platform_exit(struct musb *musb) | ||
313 | { | ||
314 | |||
315 | bfin_vbus_power(musb, 0 /*off*/, 1); | ||
316 | gpio_free(musb->config->gpio_vrsel); | ||
317 | musb_platform_suspend(musb); | ||
318 | |||
319 | return 0; | ||
320 | } | ||
diff --git a/drivers/usb/musb/blackfin.h b/drivers/usb/musb/blackfin.h new file mode 100644 index 000000000000..a240c1e53d16 --- /dev/null +++ b/drivers/usb/musb/blackfin.h | |||
@@ -0,0 +1,52 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007 by Analog Devices, Inc. | ||
3 | * | ||
4 | * The Inventra Controller Driver for Linux is free software; you | ||
5 | * can redistribute it and/or modify it under the terms of the GNU | ||
6 | * General Public License version 2 as published by the Free Software | ||
7 | * Foundation. | ||
8 | */ | ||
9 | |||
10 | #ifndef __MUSB_BLACKFIN_H__ | ||
11 | #define __MUSB_BLACKFIN_H__ | ||
12 | |||
13 | /* | ||
14 | * Blackfin specific definitions | ||
15 | */ | ||
16 | |||
17 | #undef DUMP_FIFO_DATA | ||
18 | #ifdef DUMP_FIFO_DATA | ||
19 | static void dump_fifo_data(u8 *buf, u16 len) | ||
20 | { | ||
21 | u8 *tmp = buf; | ||
22 | int i; | ||
23 | |||
24 | for (i = 0; i < len; i++) { | ||
25 | if (!(i % 16) && i) | ||
26 | pr_debug("\n"); | ||
27 | pr_debug("%02x ", *tmp++); | ||
28 | } | ||
29 | pr_debug("\n"); | ||
30 | } | ||
31 | #else | ||
32 | #define dump_fifo_data(buf, len) do {} while (0) | ||
33 | #endif | ||
34 | |||
35 | #ifdef CONFIG_BF52x | ||
36 | |||
37 | #define USB_DMA_BASE USB_DMA_INTERRUPT | ||
38 | #define USB_DMAx_CTRL 0x04 | ||
39 | #define USB_DMAx_ADDR_LOW 0x08 | ||
40 | #define USB_DMAx_ADDR_HIGH 0x0C | ||
41 | #define USB_DMAx_COUNT_LOW 0x10 | ||
42 | #define USB_DMAx_COUNT_HIGH 0x14 | ||
43 | |||
44 | #define USB_DMA_REG(ep, reg) (USB_DMA_BASE + 0x20 * ep + reg) | ||
45 | #endif | ||
46 | |||
47 | /* Almost 1 second */ | ||
48 | #define TIMER_DELAY (1 * HZ) | ||
49 | |||
50 | static struct timer_list musb_conn_timer; | ||
51 | |||
52 | #endif /* __MUSB_BLACKFIN_H__ */ | ||
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c index dfb3bcbe00fc..0d566dc5ce06 100644 --- a/drivers/usb/musb/davinci.c +++ b/drivers/usb/musb/davinci.c | |||
@@ -32,9 +32,9 @@ | |||
32 | #include <linux/io.h> | 32 | #include <linux/io.h> |
33 | #include <linux/gpio.h> | 33 | #include <linux/gpio.h> |
34 | 34 | ||
35 | #include <asm/arch/hardware.h> | 35 | #include <mach/arch/hardware.h> |
36 | #include <asm/arch/memory.h> | 36 | #include <mach/arch/memory.h> |
37 | #include <asm/arch/gpio.h> | 37 | #include <mach/arch/gpio.h> |
38 | #include <asm/mach-types.h> | 38 | #include <asm/mach-types.h> |
39 | 39 | ||
40 | #include "musb_core.h" | 40 | #include "musb_core.h" |
@@ -364,6 +364,18 @@ static irqreturn_t davinci_interrupt(int irq, void *__hci) | |||
364 | return IRQ_HANDLED; | 364 | return IRQ_HANDLED; |
365 | } | 365 | } |
366 | 366 | ||
367 | int musb_platform_set_mode(struct musb *musb, u8 mode) | ||
368 | { | ||
369 | /* EVM can't do this (right?) */ | ||
370 | return -EIO; | ||
371 | } | ||
372 | |||
373 | int musb_platform_set_mode(struct musb *musb, u8 mode) | ||
374 | { | ||
375 | /* EVM can't do this (right?) */ | ||
376 | return -EIO; | ||
377 | } | ||
378 | |||
367 | int __init musb_platform_init(struct musb *musb) | 379 | int __init musb_platform_init(struct musb *musb) |
368 | { | 380 | { |
369 | void __iomem *tibase = musb->ctrl_base; | 381 | void __iomem *tibase = musb->ctrl_base; |
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 5280dba9b1fb..6c7faacfb535 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c | |||
@@ -148,7 +148,8 @@ static inline struct musb *dev_to_musb(struct device *dev) | |||
148 | 148 | ||
149 | /*-------------------------------------------------------------------------*/ | 149 | /*-------------------------------------------------------------------------*/ |
150 | 150 | ||
151 | #ifndef CONFIG_USB_TUSB6010 | 151 | #if !defined(CONFIG_USB_TUSB6010) && !defined(CONFIG_BLACKFIN) |
152 | |||
152 | /* | 153 | /* |
153 | * Load an endpoint's FIFO | 154 | * Load an endpoint's FIFO |
154 | */ | 155 | */ |
@@ -1124,25 +1125,25 @@ fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep, | |||
1124 | #endif | 1125 | #endif |
1125 | switch (cfg->style) { | 1126 | switch (cfg->style) { |
1126 | case FIFO_TX: | 1127 | case FIFO_TX: |
1127 | musb_writeb(mbase, MUSB_TXFIFOSZ, c_size); | 1128 | musb_write_txfifosz(mbase, c_size); |
1128 | musb_writew(mbase, MUSB_TXFIFOADD, c_off); | 1129 | musb_write_txfifoadd(mbase, c_off); |
1129 | hw_ep->tx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB); | 1130 | hw_ep->tx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB); |
1130 | hw_ep->max_packet_sz_tx = maxpacket; | 1131 | hw_ep->max_packet_sz_tx = maxpacket; |
1131 | break; | 1132 | break; |
1132 | case FIFO_RX: | 1133 | case FIFO_RX: |
1133 | musb_writeb(mbase, MUSB_RXFIFOSZ, c_size); | 1134 | musb_write_rxfifosz(mbase, c_size); |
1134 | musb_writew(mbase, MUSB_RXFIFOADD, c_off); | 1135 | musb_write_rxfifoadd(mbase, c_off); |
1135 | hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB); | 1136 | hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB); |
1136 | hw_ep->max_packet_sz_rx = maxpacket; | 1137 | hw_ep->max_packet_sz_rx = maxpacket; |
1137 | break; | 1138 | break; |
1138 | case FIFO_RXTX: | 1139 | case FIFO_RXTX: |
1139 | musb_writeb(mbase, MUSB_TXFIFOSZ, c_size); | 1140 | musb_write_txfifosz(mbase, c_size); |
1140 | musb_writew(mbase, MUSB_TXFIFOADD, c_off); | 1141 | musb_write_txfifoadd(mbase, c_off); |
1141 | hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB); | 1142 | hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB); |
1142 | hw_ep->max_packet_sz_rx = maxpacket; | 1143 | hw_ep->max_packet_sz_rx = maxpacket; |
1143 | 1144 | ||
1144 | musb_writeb(mbase, MUSB_RXFIFOSZ, c_size); | 1145 | musb_write_rxfifosz(mbase, c_size); |
1145 | musb_writew(mbase, MUSB_RXFIFOADD, c_off); | 1146 | musb_write_rxfifoadd(mbase, c_off); |
1146 | hw_ep->tx_double_buffered = hw_ep->rx_double_buffered; | 1147 | hw_ep->tx_double_buffered = hw_ep->rx_double_buffered; |
1147 | hw_ep->max_packet_sz_tx = maxpacket; | 1148 | hw_ep->max_packet_sz_tx = maxpacket; |
1148 | 1149 | ||
@@ -1212,7 +1213,7 @@ static int __init ep_config_from_table(struct musb *musb) | |||
1212 | if (epn >= musb->config->num_eps) { | 1213 | if (epn >= musb->config->num_eps) { |
1213 | pr_debug("%s: invalid ep %d\n", | 1214 | pr_debug("%s: invalid ep %d\n", |
1214 | musb_driver_name, epn); | 1215 | musb_driver_name, epn); |
1215 | continue; | 1216 | return -EINVAL; |
1216 | } | 1217 | } |
1217 | offset = fifo_setup(musb, hw_ep + epn, cfg++, offset); | 1218 | offset = fifo_setup(musb, hw_ep + epn, cfg++, offset); |
1218 | if (offset < 0) { | 1219 | if (offset < 0) { |
@@ -1246,9 +1247,10 @@ static int __init ep_config_from_table(struct musb *musb) | |||
1246 | */ | 1247 | */ |
1247 | static int __init ep_config_from_hw(struct musb *musb) | 1248 | static int __init ep_config_from_hw(struct musb *musb) |
1248 | { | 1249 | { |
1249 | u8 epnum = 0, reg; | 1250 | u8 epnum = 0; |
1250 | struct musb_hw_ep *hw_ep; | 1251 | struct musb_hw_ep *hw_ep; |
1251 | void *mbase = musb->mregs; | 1252 | void *mbase = musb->mregs; |
1253 | int ret = 0; | ||
1252 | 1254 | ||
1253 | DBG(2, "<== static silicon ep config\n"); | 1255 | DBG(2, "<== static silicon ep config\n"); |
1254 | 1256 | ||
@@ -1258,26 +1260,9 @@ static int __init ep_config_from_hw(struct musb *musb) | |||
1258 | musb_ep_select(mbase, epnum); | 1260 | musb_ep_select(mbase, epnum); |
1259 | hw_ep = musb->endpoints + epnum; | 1261 | hw_ep = musb->endpoints + epnum; |
1260 | 1262 | ||
1261 | /* read from core using indexed model */ | 1263 | ret = musb_read_fifosize(musb, hw_ep, epnum); |
1262 | reg = musb_readb(hw_ep->regs, 0x10 + MUSB_FIFOSIZE); | 1264 | if (ret < 0) |
1263 | if (!reg) { | ||
1264 | /* 0's returned when no more endpoints */ | ||
1265 | break; | 1265 | break; |
1266 | } | ||
1267 | musb->nr_endpoints++; | ||
1268 | musb->epmask |= (1 << epnum); | ||
1269 | |||
1270 | hw_ep->max_packet_sz_tx = 1 << (reg & 0x0f); | ||
1271 | |||
1272 | /* shared TX/RX FIFO? */ | ||
1273 | if ((reg & 0xf0) == 0xf0) { | ||
1274 | hw_ep->max_packet_sz_rx = hw_ep->max_packet_sz_tx; | ||
1275 | hw_ep->is_shared_fifo = true; | ||
1276 | continue; | ||
1277 | } else { | ||
1278 | hw_ep->max_packet_sz_rx = 1 << ((reg & 0xf0) >> 4); | ||
1279 | hw_ep->is_shared_fifo = false; | ||
1280 | } | ||
1281 | 1266 | ||
1282 | /* FIXME set up hw_ep->{rx,tx}_double_buffered */ | 1267 | /* FIXME set up hw_ep->{rx,tx}_double_buffered */ |
1283 | 1268 | ||
@@ -1326,7 +1311,7 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb) | |||
1326 | 1311 | ||
1327 | /* log core options (read using indexed model) */ | 1312 | /* log core options (read using indexed model) */ |
1328 | musb_ep_select(mbase, 0); | 1313 | musb_ep_select(mbase, 0); |
1329 | reg = musb_readb(mbase, 0x10 + MUSB_CONFIGDATA); | 1314 | reg = musb_read_configdata(mbase); |
1330 | 1315 | ||
1331 | strcpy(aInfo, (reg & MUSB_CONFIGDATA_UTMIDW) ? "UTMI-16" : "UTMI-8"); | 1316 | strcpy(aInfo, (reg & MUSB_CONFIGDATA_UTMIDW) ? "UTMI-16" : "UTMI-8"); |
1332 | if (reg & MUSB_CONFIGDATA_DYNFIFO) | 1317 | if (reg & MUSB_CONFIGDATA_DYNFIFO) |
@@ -1391,7 +1376,7 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb) | |||
1391 | } | 1376 | } |
1392 | 1377 | ||
1393 | /* log release info */ | 1378 | /* log release info */ |
1394 | hwvers = musb_readw(mbase, MUSB_HWVERS); | 1379 | hwvers = musb_read_hwvers(mbase); |
1395 | rev_major = (hwvers >> 10) & 0x1f; | 1380 | rev_major = (hwvers >> 10) & 0x1f; |
1396 | rev_minor = hwvers & 0x3ff; | 1381 | rev_minor = hwvers & 0x3ff; |
1397 | snprintf(aRevision, 32, "%d.%d%s", rev_major, | 1382 | snprintf(aRevision, 32, "%d.%d%s", rev_major, |
@@ -1400,8 +1385,7 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb) | |||
1400 | musb_driver_name, type, aRevision, aDate); | 1385 | musb_driver_name, type, aRevision, aDate); |
1401 | 1386 | ||
1402 | /* configure ep0 */ | 1387 | /* configure ep0 */ |
1403 | musb->endpoints[0].max_packet_sz_tx = MUSB_EP0_FIFOSIZE; | 1388 | musb_configure_ep0(musb); |
1404 | musb->endpoints[0].max_packet_sz_rx = MUSB_EP0_FIFOSIZE; | ||
1405 | 1389 | ||
1406 | /* discover endpoint configuration */ | 1390 | /* discover endpoint configuration */ |
1407 | musb->nr_endpoints = 1; | 1391 | musb->nr_endpoints = 1; |
@@ -1445,7 +1429,7 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb) | |||
1445 | 1429 | ||
1446 | hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase; | 1430 | hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase; |
1447 | #ifdef CONFIG_USB_MUSB_HDRC_HCD | 1431 | #ifdef CONFIG_USB_MUSB_HDRC_HCD |
1448 | hw_ep->target_regs = MUSB_BUSCTL_OFFSET(i, 0) + mbase; | 1432 | hw_ep->target_regs = musb_read_target_reg_base(i, mbase); |
1449 | hw_ep->rx_reinit = 1; | 1433 | hw_ep->rx_reinit = 1; |
1450 | hw_ep->tx_reinit = 1; | 1434 | hw_ep->tx_reinit = 1; |
1451 | #endif | 1435 | #endif |
@@ -1671,17 +1655,20 @@ musb_mode_store(struct device *dev, struct device_attribute *attr, | |||
1671 | { | 1655 | { |
1672 | struct musb *musb = dev_to_musb(dev); | 1656 | struct musb *musb = dev_to_musb(dev); |
1673 | unsigned long flags; | 1657 | unsigned long flags; |
1658 | int status; | ||
1674 | 1659 | ||
1675 | spin_lock_irqsave(&musb->lock, flags); | 1660 | spin_lock_irqsave(&musb->lock, flags); |
1676 | if (!strncmp(buf, "host", 4)) | 1661 | if (sysfs_streq(buf, "host")) |
1677 | musb_platform_set_mode(musb, MUSB_HOST); | 1662 | status = musb_platform_set_mode(musb, MUSB_HOST); |
1678 | if (!strncmp(buf, "peripheral", 10)) | 1663 | else if (sysfs_streq(buf, "peripheral")) |
1679 | musb_platform_set_mode(musb, MUSB_PERIPHERAL); | 1664 | status = musb_platform_set_mode(musb, MUSB_PERIPHERAL); |
1680 | if (!strncmp(buf, "otg", 3)) | 1665 | else if (sysfs_streq(buf, "otg")) |
1681 | musb_platform_set_mode(musb, MUSB_OTG); | 1666 | status = musb_platform_set_mode(musb, MUSB_OTG); |
1667 | else | ||
1668 | status = -EINVAL; | ||
1682 | spin_unlock_irqrestore(&musb->lock, flags); | 1669 | spin_unlock_irqrestore(&musb->lock, flags); |
1683 | 1670 | ||
1684 | return n; | 1671 | return (status == 0) ? n : status; |
1685 | } | 1672 | } |
1686 | static DEVICE_ATTR(mode, 0644, musb_mode_show, musb_mode_store); | 1673 | static DEVICE_ATTR(mode, 0644, musb_mode_show, musb_mode_store); |
1687 | 1674 | ||
@@ -1781,7 +1768,7 @@ allocate_instance(struct device *dev, | |||
1781 | #ifdef CONFIG_USB_MUSB_HDRC_HCD | 1768 | #ifdef CONFIG_USB_MUSB_HDRC_HCD |
1782 | struct usb_hcd *hcd; | 1769 | struct usb_hcd *hcd; |
1783 | 1770 | ||
1784 | hcd = usb_create_hcd(&musb_hc_driver, dev, dev->bus_id); | 1771 | hcd = usb_create_hcd(&musb_hc_driver, dev, dev_name(dev)); |
1785 | if (!hcd) | 1772 | if (!hcd) |
1786 | return NULL; | 1773 | return NULL; |
1787 | /* usbcore sets dev->driver_data to hcd, and sometimes uses that... */ | 1774 | /* usbcore sets dev->driver_data to hcd, and sometimes uses that... */ |
@@ -1810,7 +1797,6 @@ allocate_instance(struct device *dev, | |||
1810 | for (epnum = 0, ep = musb->endpoints; | 1797 | for (epnum = 0, ep = musb->endpoints; |
1811 | epnum < musb->config->num_eps; | 1798 | epnum < musb->config->num_eps; |
1812 | epnum++, ep++) { | 1799 | epnum++, ep++) { |
1813 | |||
1814 | ep->musb = musb; | 1800 | ep->musb = musb; |
1815 | ep->epnum = epnum; | 1801 | ep->epnum = epnum; |
1816 | } | 1802 | } |
@@ -1838,7 +1824,7 @@ static void musb_free(struct musb *musb) | |||
1838 | musb_gadget_cleanup(musb); | 1824 | musb_gadget_cleanup(musb); |
1839 | #endif | 1825 | #endif |
1840 | 1826 | ||
1841 | if (musb->nIrq >= 0) { | 1827 | if (musb->nIrq >= 0 && musb->irq_wake) { |
1842 | disable_irq_wake(musb->nIrq); | 1828 | disable_irq_wake(musb->nIrq); |
1843 | free_irq(musb->nIrq, musb); | 1829 | free_irq(musb->nIrq, musb); |
1844 | } | 1830 | } |
@@ -1984,15 +1970,19 @@ bad_config: | |||
1984 | INIT_WORK(&musb->irq_work, musb_irq_work); | 1970 | INIT_WORK(&musb->irq_work, musb_irq_work); |
1985 | 1971 | ||
1986 | /* attach to the IRQ */ | 1972 | /* attach to the IRQ */ |
1987 | if (request_irq(nIrq, musb->isr, 0, dev->bus_id, musb)) { | 1973 | if (request_irq(nIrq, musb->isr, 0, dev_name(dev), musb)) { |
1988 | dev_err(dev, "request_irq %d failed!\n", nIrq); | 1974 | dev_err(dev, "request_irq %d failed!\n", nIrq); |
1989 | status = -ENODEV; | 1975 | status = -ENODEV; |
1990 | goto fail2; | 1976 | goto fail2; |
1991 | } | 1977 | } |
1992 | musb->nIrq = nIrq; | 1978 | musb->nIrq = nIrq; |
1993 | /* FIXME this handles wakeup irqs wrong */ | 1979 | /* FIXME this handles wakeup irqs wrong */ |
1994 | if (enable_irq_wake(nIrq) == 0) | 1980 | if (enable_irq_wake(nIrq) == 0) { |
1981 | musb->irq_wake = 1; | ||
1995 | device_init_wakeup(dev, 1); | 1982 | device_init_wakeup(dev, 1); |
1983 | } else { | ||
1984 | musb->irq_wake = 0; | ||
1985 | } | ||
1996 | 1986 | ||
1997 | pr_info("%s: USB %s mode controller at %p using %s, IRQ %d\n", | 1987 | pr_info("%s: USB %s mode controller at %p using %s, IRQ %d\n", |
1998 | musb_driver_name, | 1988 | musb_driver_name, |
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index 82227251931b..630946a2d9fc 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h | |||
@@ -191,7 +191,7 @@ enum musb_g_ep0_state { | |||
191 | */ | 191 | */ |
192 | 192 | ||
193 | #if defined(CONFIG_ARCH_DAVINCI) || defined(CONFIG_ARCH_OMAP2430) \ | 193 | #if defined(CONFIG_ARCH_DAVINCI) || defined(CONFIG_ARCH_OMAP2430) \ |
194 | || defined(CONFIG_ARCH_OMAP3430) | 194 | || defined(CONFIG_ARCH_OMAP3430) || defined(CONFIG_BLACKFIN) |
195 | /* REVISIT indexed access seemed to | 195 | /* REVISIT indexed access seemed to |
196 | * misbehave (on DaVinci) for at least peripheral IN ... | 196 | * misbehave (on DaVinci) for at least peripheral IN ... |
197 | */ | 197 | */ |
@@ -359,6 +359,7 @@ struct musb { | |||
359 | struct otg_transceiver xceiv; | 359 | struct otg_transceiver xceiv; |
360 | 360 | ||
361 | int nIrq; | 361 | int nIrq; |
362 | unsigned irq_wake:1; | ||
362 | 363 | ||
363 | struct musb_hw_ep endpoints[MUSB_C_NUM_EPS]; | 364 | struct musb_hw_ep endpoints[MUSB_C_NUM_EPS]; |
364 | #define control_ep endpoints | 365 | #define control_ep endpoints |
@@ -447,6 +448,70 @@ static inline struct musb *gadget_to_musb(struct usb_gadget *g) | |||
447 | } | 448 | } |
448 | #endif | 449 | #endif |
449 | 450 | ||
451 | #ifdef CONFIG_BLACKFIN | ||
452 | static inline int musb_read_fifosize(struct musb *musb, | ||
453 | struct musb_hw_ep *hw_ep, u8 epnum) | ||
454 | { | ||
455 | musb->nr_endpoints++; | ||
456 | musb->epmask |= (1 << epnum); | ||
457 | |||
458 | if (epnum < 5) { | ||
459 | hw_ep->max_packet_sz_tx = 128; | ||
460 | hw_ep->max_packet_sz_rx = 128; | ||
461 | } else { | ||
462 | hw_ep->max_packet_sz_tx = 1024; | ||
463 | hw_ep->max_packet_sz_rx = 1024; | ||
464 | } | ||
465 | hw_ep->is_shared_fifo = false; | ||
466 | |||
467 | return 0; | ||
468 | } | ||
469 | |||
470 | static inline void musb_configure_ep0(struct musb *musb) | ||
471 | { | ||
472 | musb->endpoints[0].max_packet_sz_tx = MUSB_EP0_FIFOSIZE; | ||
473 | musb->endpoints[0].max_packet_sz_rx = MUSB_EP0_FIFOSIZE; | ||
474 | musb->endpoints[0].is_shared_fifo = true; | ||
475 | } | ||
476 | |||
477 | #else | ||
478 | |||
479 | static inline int musb_read_fifosize(struct musb *musb, | ||
480 | struct musb_hw_ep *hw_ep, u8 epnum) | ||
481 | { | ||
482 | u8 reg = 0; | ||
483 | |||
484 | /* read from core using indexed model */ | ||
485 | reg = musb_readb(hw_ep->regs, 0x10 + MUSB_FIFOSIZE); | ||
486 | /* 0's returned when no more endpoints */ | ||
487 | if (!reg) | ||
488 | return -ENODEV; | ||
489 | |||
490 | musb->nr_endpoints++; | ||
491 | musb->epmask |= (1 << epnum); | ||
492 | |||
493 | hw_ep->max_packet_sz_tx = 1 << (reg & 0x0f); | ||
494 | |||
495 | /* shared TX/RX FIFO? */ | ||
496 | if ((reg & 0xf0) == 0xf0) { | ||
497 | hw_ep->max_packet_sz_rx = hw_ep->max_packet_sz_tx; | ||
498 | hw_ep->is_shared_fifo = true; | ||
499 | return 0; | ||
500 | } else { | ||
501 | hw_ep->max_packet_sz_rx = 1 << ((reg & 0xf0) >> 4); | ||
502 | hw_ep->is_shared_fifo = false; | ||
503 | } | ||
504 | |||
505 | return 0; | ||
506 | } | ||
507 | |||
508 | static inline void musb_configure_ep0(struct musb *musb) | ||
509 | { | ||
510 | musb->endpoints[0].max_packet_sz_tx = MUSB_EP0_FIFOSIZE; | ||
511 | musb->endpoints[0].max_packet_sz_rx = MUSB_EP0_FIFOSIZE; | ||
512 | } | ||
513 | #endif /* CONFIG_BLACKFIN */ | ||
514 | |||
450 | 515 | ||
451 | /***************************** Glue it together *****************************/ | 516 | /***************************** Glue it together *****************************/ |
452 | 517 | ||
@@ -467,16 +532,16 @@ extern void musb_platform_disable(struct musb *musb); | |||
467 | 532 | ||
468 | extern void musb_hnp_stop(struct musb *musb); | 533 | extern void musb_hnp_stop(struct musb *musb); |
469 | 534 | ||
470 | extern void musb_platform_set_mode(struct musb *musb, u8 musb_mode); | 535 | extern int musb_platform_set_mode(struct musb *musb, u8 musb_mode); |
471 | 536 | ||
472 | #if defined(CONFIG_USB_TUSB6010) || \ | 537 | #if defined(CONFIG_USB_TUSB6010) || defined(CONFIG_BLACKFIN) || \ |
473 | defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX) | 538 | defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX) |
474 | extern void musb_platform_try_idle(struct musb *musb, unsigned long timeout); | 539 | extern void musb_platform_try_idle(struct musb *musb, unsigned long timeout); |
475 | #else | 540 | #else |
476 | #define musb_platform_try_idle(x, y) do {} while (0) | 541 | #define musb_platform_try_idle(x, y) do {} while (0) |
477 | #endif | 542 | #endif |
478 | 543 | ||
479 | #ifdef CONFIG_USB_TUSB6010 | 544 | #if defined(CONFIG_USB_TUSB6010) || defined(CONFIG_BLACKFIN) |
480 | extern int musb_platform_get_vbus_status(struct musb *musb); | 545 | extern int musb_platform_get_vbus_status(struct musb *musb); |
481 | #else | 546 | #else |
482 | #define musb_platform_get_vbus_status(x) 0 | 547 | #define musb_platform_get_vbus_status(x) 0 |
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index d6a802c224fa..6197daeab8f9 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c | |||
@@ -1633,7 +1633,7 @@ int __init musb_gadget_setup(struct musb *musb) | |||
1633 | musb->g.speed = USB_SPEED_UNKNOWN; | 1633 | musb->g.speed = USB_SPEED_UNKNOWN; |
1634 | 1634 | ||
1635 | /* this "gadget" abstracts/virtualizes the controller */ | 1635 | /* this "gadget" abstracts/virtualizes the controller */ |
1636 | strcpy(musb->g.dev.bus_id, "gadget"); | 1636 | dev_set_name(&musb->g.dev, "gadget"); |
1637 | musb->g.dev.parent = musb->controller; | 1637 | musb->g.dev.parent = musb->controller; |
1638 | musb->g.dev.dma_mask = musb->controller->dma_mask; | 1638 | musb->g.dev.dma_mask = musb->controller->dma_mask; |
1639 | musb->g.dev.release = musb_gadget_release; | 1639 | musb->g.dev.release = musb_gadget_release; |
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c index cc64462d4c4e..99fa61234876 100644 --- a/drivers/usb/musb/musb_host.c +++ b/drivers/usb/musb/musb_host.c | |||
@@ -112,18 +112,21 @@ static void musb_h_tx_flush_fifo(struct musb_hw_ep *ep) | |||
112 | { | 112 | { |
113 | void __iomem *epio = ep->regs; | 113 | void __iomem *epio = ep->regs; |
114 | u16 csr; | 114 | u16 csr; |
115 | u16 lastcsr = 0; | ||
115 | int retries = 1000; | 116 | int retries = 1000; |
116 | 117 | ||
117 | csr = musb_readw(epio, MUSB_TXCSR); | 118 | csr = musb_readw(epio, MUSB_TXCSR); |
118 | while (csr & MUSB_TXCSR_FIFONOTEMPTY) { | 119 | while (csr & MUSB_TXCSR_FIFONOTEMPTY) { |
119 | DBG(5, "Host TX FIFONOTEMPTY csr: %02x\n", csr); | 120 | if (csr != lastcsr) |
121 | DBG(3, "Host TX FIFONOTEMPTY csr: %02x\n", csr); | ||
122 | lastcsr = csr; | ||
120 | csr |= MUSB_TXCSR_FLUSHFIFO; | 123 | csr |= MUSB_TXCSR_FLUSHFIFO; |
121 | musb_writew(epio, MUSB_TXCSR, csr); | 124 | musb_writew(epio, MUSB_TXCSR, csr); |
122 | csr = musb_readw(epio, MUSB_TXCSR); | 125 | csr = musb_readw(epio, MUSB_TXCSR); |
123 | if (retries-- < 1) { | 126 | if (WARN(retries-- < 1, |
124 | ERR("Could not flush host TX fifo: csr: %04x\n", csr); | 127 | "Could not flush host TX%d fifo: csr: %04x\n", |
128 | ep->epnum, csr)) | ||
125 | return; | 129 | return; |
126 | } | ||
127 | mdelay(1); | 130 | mdelay(1); |
128 | } | 131 | } |
129 | } | 132 | } |
@@ -268,7 +271,7 @@ __musb_giveback(struct musb *musb, struct urb *urb, int status) | |||
268 | __releases(musb->lock) | 271 | __releases(musb->lock) |
269 | __acquires(musb->lock) | 272 | __acquires(musb->lock) |
270 | { | 273 | { |
271 | DBG(({ int level; switch (urb->status) { | 274 | DBG(({ int level; switch (status) { |
272 | case 0: | 275 | case 0: |
273 | level = 4; | 276 | level = 4; |
274 | break; | 277 | break; |
@@ -283,8 +286,8 @@ __acquires(musb->lock) | |||
283 | level = 2; | 286 | level = 2; |
284 | break; | 287 | break; |
285 | }; level; }), | 288 | }; level; }), |
286 | "complete %p (%d), dev%d ep%d%s, %d/%d\n", | 289 | "complete %p %pF (%d), dev%d ep%d%s, %d/%d\n", |
287 | urb, urb->status, | 290 | urb, urb->complete, status, |
288 | usb_pipedevice(urb->pipe), | 291 | usb_pipedevice(urb->pipe), |
289 | usb_pipeendpoint(urb->pipe), | 292 | usb_pipeendpoint(urb->pipe), |
290 | usb_pipein(urb->pipe) ? "in" : "out", | 293 | usb_pipein(urb->pipe) ? "in" : "out", |
@@ -593,12 +596,10 @@ musb_rx_reinit(struct musb *musb, struct musb_qh *qh, struct musb_hw_ep *ep) | |||
593 | 596 | ||
594 | /* target addr and (for multipoint) hub addr/port */ | 597 | /* target addr and (for multipoint) hub addr/port */ |
595 | if (musb->is_multipoint) { | 598 | if (musb->is_multipoint) { |
596 | musb_writeb(ep->target_regs, MUSB_RXFUNCADDR, | 599 | musb_write_rxfunaddr(ep->target_regs, qh->addr_reg); |
597 | qh->addr_reg); | 600 | musb_write_rxhubaddr(ep->target_regs, qh->h_addr_reg); |
598 | musb_writeb(ep->target_regs, MUSB_RXHUBADDR, | 601 | musb_write_rxhubport(ep->target_regs, qh->h_port_reg); |
599 | qh->h_addr_reg); | 602 | |
600 | musb_writeb(ep->target_regs, MUSB_RXHUBPORT, | ||
601 | qh->h_port_reg); | ||
602 | } else | 603 | } else |
603 | musb_writeb(musb->mregs, MUSB_FADDR, qh->addr_reg); | 604 | musb_writeb(musb->mregs, MUSB_FADDR, qh->addr_reg); |
604 | 605 | ||
@@ -712,15 +713,9 @@ static void musb_ep_program(struct musb *musb, u8 epnum, | |||
712 | 713 | ||
713 | /* target addr and (for multipoint) hub addr/port */ | 714 | /* target addr and (for multipoint) hub addr/port */ |
714 | if (musb->is_multipoint) { | 715 | if (musb->is_multipoint) { |
715 | musb_writeb(mbase, | 716 | musb_write_txfunaddr(mbase, epnum, qh->addr_reg); |
716 | MUSB_BUSCTL_OFFSET(epnum, MUSB_TXFUNCADDR), | 717 | musb_write_txhubaddr(mbase, epnum, qh->h_addr_reg); |
717 | qh->addr_reg); | 718 | musb_write_txhubport(mbase, epnum, qh->h_port_reg); |
718 | musb_writeb(mbase, | ||
719 | MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBADDR), | ||
720 | qh->h_addr_reg); | ||
721 | musb_writeb(mbase, | ||
722 | MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBPORT), | ||
723 | qh->h_port_reg); | ||
724 | /* FIXME if !epnum, do the same for RX ... */ | 719 | /* FIXME if !epnum, do the same for RX ... */ |
725 | } else | 720 | } else |
726 | musb_writeb(mbase, MUSB_FADDR, qh->addr_reg); | 721 | musb_writeb(mbase, MUSB_FADDR, qh->addr_reg); |
@@ -988,8 +983,10 @@ static bool musb_h_ep0_continue(struct musb *musb, u16 len, struct urb *urb) | |||
988 | if (fifo_count) { | 983 | if (fifo_count) { |
989 | fifo_dest = (u8 *) (urb->transfer_buffer | 984 | fifo_dest = (u8 *) (urb->transfer_buffer |
990 | + urb->actual_length); | 985 | + urb->actual_length); |
991 | DBG(3, "Sending %d bytes to %p\n", | 986 | DBG(3, "Sending %d byte%s to ep0 fifo %p\n", |
992 | fifo_count, fifo_dest); | 987 | fifo_count, |
988 | (fifo_count == 1) ? "" : "s", | ||
989 | fifo_dest); | ||
993 | musb_write_fifo(hw_ep, fifo_count, fifo_dest); | 990 | musb_write_fifo(hw_ep, fifo_count, fifo_dest); |
994 | 991 | ||
995 | urb->actual_length += fifo_count; | 992 | urb->actual_length += fifo_count; |
diff --git a/drivers/usb/musb/musb_io.h b/drivers/usb/musb/musb_io.h index 223f0a514094..b06e9ef00cfc 100644 --- a/drivers/usb/musb/musb_io.h +++ b/drivers/usb/musb/musb_io.h | |||
@@ -39,7 +39,7 @@ | |||
39 | 39 | ||
40 | #if !defined(CONFIG_ARM) && !defined(CONFIG_SUPERH) \ | 40 | #if !defined(CONFIG_ARM) && !defined(CONFIG_SUPERH) \ |
41 | && !defined(CONFIG_AVR32) && !defined(CONFIG_PPC32) \ | 41 | && !defined(CONFIG_AVR32) && !defined(CONFIG_PPC32) \ |
42 | && !defined(CONFIG_PPC64) | 42 | && !defined(CONFIG_PPC64) && !defined(CONFIG_BLACKFIN) |
43 | static inline void readsl(const void __iomem *addr, void *buf, int len) | 43 | static inline void readsl(const void __iomem *addr, void *buf, int len) |
44 | { insl((unsigned long)addr, buf, len); } | 44 | { insl((unsigned long)addr, buf, len); } |
45 | static inline void readsw(const void __iomem *addr, void *buf, int len) | 45 | static inline void readsw(const void __iomem *addr, void *buf, int len) |
@@ -56,6 +56,8 @@ static inline void writesb(const void __iomem *addr, const void *buf, int len) | |||
56 | 56 | ||
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | #ifndef CONFIG_BLACKFIN | ||
60 | |||
59 | /* NOTE: these offsets are all in bytes */ | 61 | /* NOTE: these offsets are all in bytes */ |
60 | 62 | ||
61 | static inline u16 musb_readw(const void __iomem *addr, unsigned offset) | 63 | static inline u16 musb_readw(const void __iomem *addr, unsigned offset) |
@@ -114,4 +116,26 @@ static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data) | |||
114 | 116 | ||
115 | #endif /* CONFIG_USB_TUSB6010 */ | 117 | #endif /* CONFIG_USB_TUSB6010 */ |
116 | 118 | ||
119 | #else | ||
120 | |||
121 | static inline u8 musb_readb(const void __iomem *addr, unsigned offset) | ||
122 | { return (u8) (bfin_read16(addr + offset)); } | ||
123 | |||
124 | static inline u16 musb_readw(const void __iomem *addr, unsigned offset) | ||
125 | { return bfin_read16(addr + offset); } | ||
126 | |||
127 | static inline u32 musb_readl(const void __iomem *addr, unsigned offset) | ||
128 | { return (u32) (bfin_read16(addr + offset)); } | ||
129 | |||
130 | static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data) | ||
131 | { bfin_write16(addr + offset, (u16) data); } | ||
132 | |||
133 | static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data) | ||
134 | { bfin_write16(addr + offset, data); } | ||
135 | |||
136 | static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data) | ||
137 | { bfin_write16(addr + offset, (u16) data); } | ||
138 | |||
139 | #endif /* CONFIG_BLACKFIN */ | ||
140 | |||
117 | #endif | 141 | #endif |
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h index 9c228661aa5a..de3b2f18db44 100644 --- a/drivers/usb/musb/musb_regs.h +++ b/drivers/usb/musb/musb_regs.h | |||
@@ -38,97 +38,6 @@ | |||
38 | #define MUSB_EP0_FIFOSIZE 64 /* This is non-configurable */ | 38 | #define MUSB_EP0_FIFOSIZE 64 /* This is non-configurable */ |
39 | 39 | ||
40 | /* | 40 | /* |
41 | * Common USB registers | ||
42 | */ | ||
43 | |||
44 | #define MUSB_FADDR 0x00 /* 8-bit */ | ||
45 | #define MUSB_POWER 0x01 /* 8-bit */ | ||
46 | |||
47 | #define MUSB_INTRTX 0x02 /* 16-bit */ | ||
48 | #define MUSB_INTRRX 0x04 | ||
49 | #define MUSB_INTRTXE 0x06 | ||
50 | #define MUSB_INTRRXE 0x08 | ||
51 | #define MUSB_INTRUSB 0x0A /* 8 bit */ | ||
52 | #define MUSB_INTRUSBE 0x0B /* 8 bit */ | ||
53 | #define MUSB_FRAME 0x0C | ||
54 | #define MUSB_INDEX 0x0E /* 8 bit */ | ||
55 | #define MUSB_TESTMODE 0x0F /* 8 bit */ | ||
56 | |||
57 | /* Get offset for a given FIFO from musb->mregs */ | ||
58 | #ifdef CONFIG_USB_TUSB6010 | ||
59 | #define MUSB_FIFO_OFFSET(epnum) (0x200 + ((epnum) * 0x20)) | ||
60 | #else | ||
61 | #define MUSB_FIFO_OFFSET(epnum) (0x20 + ((epnum) * 4)) | ||
62 | #endif | ||
63 | |||
64 | /* | ||
65 | * Additional Control Registers | ||
66 | */ | ||
67 | |||
68 | #define MUSB_DEVCTL 0x60 /* 8 bit */ | ||
69 | |||
70 | /* These are always controlled through the INDEX register */ | ||
71 | #define MUSB_TXFIFOSZ 0x62 /* 8-bit (see masks) */ | ||
72 | #define MUSB_RXFIFOSZ 0x63 /* 8-bit (see masks) */ | ||
73 | #define MUSB_TXFIFOADD 0x64 /* 16-bit offset shifted right 3 */ | ||
74 | #define MUSB_RXFIFOADD 0x66 /* 16-bit offset shifted right 3 */ | ||
75 | |||
76 | /* REVISIT: vctrl/vstatus: optional vendor utmi+phy register at 0x68 */ | ||
77 | #define MUSB_HWVERS 0x6C /* 8 bit */ | ||
78 | |||
79 | #define MUSB_EPINFO 0x78 /* 8 bit */ | ||
80 | #define MUSB_RAMINFO 0x79 /* 8 bit */ | ||
81 | #define MUSB_LINKINFO 0x7a /* 8 bit */ | ||
82 | #define MUSB_VPLEN 0x7b /* 8 bit */ | ||
83 | #define MUSB_HS_EOF1 0x7c /* 8 bit */ | ||
84 | #define MUSB_FS_EOF1 0x7d /* 8 bit */ | ||
85 | #define MUSB_LS_EOF1 0x7e /* 8 bit */ | ||
86 | |||
87 | /* Offsets to endpoint registers */ | ||
88 | #define MUSB_TXMAXP 0x00 | ||
89 | #define MUSB_TXCSR 0x02 | ||
90 | #define MUSB_CSR0 MUSB_TXCSR /* Re-used for EP0 */ | ||
91 | #define MUSB_RXMAXP 0x04 | ||
92 | #define MUSB_RXCSR 0x06 | ||
93 | #define MUSB_RXCOUNT 0x08 | ||
94 | #define MUSB_COUNT0 MUSB_RXCOUNT /* Re-used for EP0 */ | ||
95 | #define MUSB_TXTYPE 0x0A | ||
96 | #define MUSB_TYPE0 MUSB_TXTYPE /* Re-used for EP0 */ | ||
97 | #define MUSB_TXINTERVAL 0x0B | ||
98 | #define MUSB_NAKLIMIT0 MUSB_TXINTERVAL /* Re-used for EP0 */ | ||
99 | #define MUSB_RXTYPE 0x0C | ||
100 | #define MUSB_RXINTERVAL 0x0D | ||
101 | #define MUSB_FIFOSIZE 0x0F | ||
102 | #define MUSB_CONFIGDATA MUSB_FIFOSIZE /* Re-used for EP0 */ | ||
103 | |||
104 | /* Offsets to endpoint registers in indexed model (using INDEX register) */ | ||
105 | #define MUSB_INDEXED_OFFSET(_epnum, _offset) \ | ||
106 | (0x10 + (_offset)) | ||
107 | |||
108 | /* Offsets to endpoint registers in flat models */ | ||
109 | #define MUSB_FLAT_OFFSET(_epnum, _offset) \ | ||
110 | (0x100 + (0x10*(_epnum)) + (_offset)) | ||
111 | |||
112 | #ifdef CONFIG_USB_TUSB6010 | ||
113 | /* TUSB6010 EP0 configuration register is special */ | ||
114 | #define MUSB_TUSB_OFFSET(_epnum, _offset) \ | ||
115 | (0x10 + _offset) | ||
116 | #include "tusb6010.h" /* Needed "only" for TUSB_EP0_CONF */ | ||
117 | #endif | ||
118 | |||
119 | /* "bus control"/target registers, for host side multipoint (external hubs) */ | ||
120 | #define MUSB_TXFUNCADDR 0x00 | ||
121 | #define MUSB_TXHUBADDR 0x02 | ||
122 | #define MUSB_TXHUBPORT 0x03 | ||
123 | |||
124 | #define MUSB_RXFUNCADDR 0x04 | ||
125 | #define MUSB_RXHUBADDR 0x06 | ||
126 | #define MUSB_RXHUBPORT 0x07 | ||
127 | |||
128 | #define MUSB_BUSCTL_OFFSET(_epnum, _offset) \ | ||
129 | (0x80 + (8*(_epnum)) + (_offset)) | ||
130 | |||
131 | /* | ||
132 | * MUSB Register bits | 41 | * MUSB Register bits |
133 | */ | 42 | */ |
134 | 43 | ||
@@ -228,7 +137,6 @@ | |||
228 | 137 | ||
229 | /* TXCSR in Peripheral and Host mode */ | 138 | /* TXCSR in Peripheral and Host mode */ |
230 | #define MUSB_TXCSR_AUTOSET 0x8000 | 139 | #define MUSB_TXCSR_AUTOSET 0x8000 |
231 | #define MUSB_TXCSR_MODE 0x2000 | ||
232 | #define MUSB_TXCSR_DMAENAB 0x1000 | 140 | #define MUSB_TXCSR_DMAENAB 0x1000 |
233 | #define MUSB_TXCSR_FRCDATATOG 0x0800 | 141 | #define MUSB_TXCSR_FRCDATATOG 0x0800 |
234 | #define MUSB_TXCSR_DMAMODE 0x0400 | 142 | #define MUSB_TXCSR_DMAMODE 0x0400 |
@@ -297,4 +205,309 @@ | |||
297 | /* HUBADDR */ | 205 | /* HUBADDR */ |
298 | #define MUSB_HUBADDR_MULTI_TT 0x80 | 206 | #define MUSB_HUBADDR_MULTI_TT 0x80 |
299 | 207 | ||
208 | |||
209 | #ifndef CONFIG_BLACKFIN | ||
210 | |||
211 | /* | ||
212 | * Common USB registers | ||
213 | */ | ||
214 | |||
215 | #define MUSB_FADDR 0x00 /* 8-bit */ | ||
216 | #define MUSB_POWER 0x01 /* 8-bit */ | ||
217 | |||
218 | #define MUSB_INTRTX 0x02 /* 16-bit */ | ||
219 | #define MUSB_INTRRX 0x04 | ||
220 | #define MUSB_INTRTXE 0x06 | ||
221 | #define MUSB_INTRRXE 0x08 | ||
222 | #define MUSB_INTRUSB 0x0A /* 8 bit */ | ||
223 | #define MUSB_INTRUSBE 0x0B /* 8 bit */ | ||
224 | #define MUSB_FRAME 0x0C | ||
225 | #define MUSB_INDEX 0x0E /* 8 bit */ | ||
226 | #define MUSB_TESTMODE 0x0F /* 8 bit */ | ||
227 | |||
228 | /* Get offset for a given FIFO from musb->mregs */ | ||
229 | #ifdef CONFIG_USB_TUSB6010 | ||
230 | #define MUSB_FIFO_OFFSET(epnum) (0x200 + ((epnum) * 0x20)) | ||
231 | #else | ||
232 | #define MUSB_FIFO_OFFSET(epnum) (0x20 + ((epnum) * 4)) | ||
233 | #endif | ||
234 | |||
235 | /* | ||
236 | * Additional Control Registers | ||
237 | */ | ||
238 | |||
239 | #define MUSB_DEVCTL 0x60 /* 8 bit */ | ||
240 | |||
241 | /* These are always controlled through the INDEX register */ | ||
242 | #define MUSB_TXFIFOSZ 0x62 /* 8-bit (see masks) */ | ||
243 | #define MUSB_RXFIFOSZ 0x63 /* 8-bit (see masks) */ | ||
244 | #define MUSB_TXFIFOADD 0x64 /* 16-bit offset shifted right 3 */ | ||
245 | #define MUSB_RXFIFOADD 0x66 /* 16-bit offset shifted right 3 */ | ||
246 | |||
247 | /* REVISIT: vctrl/vstatus: optional vendor utmi+phy register at 0x68 */ | ||
248 | #define MUSB_HWVERS 0x6C /* 8 bit */ | ||
249 | |||
250 | #define MUSB_EPINFO 0x78 /* 8 bit */ | ||
251 | #define MUSB_RAMINFO 0x79 /* 8 bit */ | ||
252 | #define MUSB_LINKINFO 0x7a /* 8 bit */ | ||
253 | #define MUSB_VPLEN 0x7b /* 8 bit */ | ||
254 | #define MUSB_HS_EOF1 0x7c /* 8 bit */ | ||
255 | #define MUSB_FS_EOF1 0x7d /* 8 bit */ | ||
256 | #define MUSB_LS_EOF1 0x7e /* 8 bit */ | ||
257 | |||
258 | /* Offsets to endpoint registers */ | ||
259 | #define MUSB_TXMAXP 0x00 | ||
260 | #define MUSB_TXCSR 0x02 | ||
261 | #define MUSB_CSR0 MUSB_TXCSR /* Re-used for EP0 */ | ||
262 | #define MUSB_RXMAXP 0x04 | ||
263 | #define MUSB_RXCSR 0x06 | ||
264 | #define MUSB_RXCOUNT 0x08 | ||
265 | #define MUSB_COUNT0 MUSB_RXCOUNT /* Re-used for EP0 */ | ||
266 | #define MUSB_TXTYPE 0x0A | ||
267 | #define MUSB_TYPE0 MUSB_TXTYPE /* Re-used for EP0 */ | ||
268 | #define MUSB_TXINTERVAL 0x0B | ||
269 | #define MUSB_NAKLIMIT0 MUSB_TXINTERVAL /* Re-used for EP0 */ | ||
270 | #define MUSB_RXTYPE 0x0C | ||
271 | #define MUSB_RXINTERVAL 0x0D | ||
272 | #define MUSB_FIFOSIZE 0x0F | ||
273 | #define MUSB_CONFIGDATA MUSB_FIFOSIZE /* Re-used for EP0 */ | ||
274 | |||
275 | /* Offsets to endpoint registers in indexed model (using INDEX register) */ | ||
276 | #define MUSB_INDEXED_OFFSET(_epnum, _offset) \ | ||
277 | (0x10 + (_offset)) | ||
278 | |||
279 | /* Offsets to endpoint registers in flat models */ | ||
280 | #define MUSB_FLAT_OFFSET(_epnum, _offset) \ | ||
281 | (0x100 + (0x10*(_epnum)) + (_offset)) | ||
282 | |||
283 | #ifdef CONFIG_USB_TUSB6010 | ||
284 | /* TUSB6010 EP0 configuration register is special */ | ||
285 | #define MUSB_TUSB_OFFSET(_epnum, _offset) \ | ||
286 | (0x10 + _offset) | ||
287 | #include "tusb6010.h" /* Needed "only" for TUSB_EP0_CONF */ | ||
288 | #endif | ||
289 | |||
290 | #define MUSB_TXCSR_MODE 0x2000 | ||
291 | |||
292 | /* "bus control"/target registers, for host side multipoint (external hubs) */ | ||
293 | #define MUSB_TXFUNCADDR 0x00 | ||
294 | #define MUSB_TXHUBADDR 0x02 | ||
295 | #define MUSB_TXHUBPORT 0x03 | ||
296 | |||
297 | #define MUSB_RXFUNCADDR 0x04 | ||
298 | #define MUSB_RXHUBADDR 0x06 | ||
299 | #define MUSB_RXHUBPORT 0x07 | ||
300 | |||
301 | #define MUSB_BUSCTL_OFFSET(_epnum, _offset) \ | ||
302 | (0x80 + (8*(_epnum)) + (_offset)) | ||
303 | |||
304 | static inline void musb_write_txfifosz(void __iomem *mbase, u8 c_size) | ||
305 | { | ||
306 | musb_writeb(mbase, MUSB_TXFIFOSZ, c_size); | ||
307 | } | ||
308 | |||
309 | static inline void musb_write_txfifoadd(void __iomem *mbase, u16 c_off) | ||
310 | { | ||
311 | musb_writew(mbase, MUSB_TXFIFOADD, c_off); | ||
312 | } | ||
313 | |||
314 | static inline void musb_write_rxfifosz(void __iomem *mbase, u8 c_size) | ||
315 | { | ||
316 | musb_writeb(mbase, MUSB_RXFIFOSZ, c_size); | ||
317 | } | ||
318 | |||
319 | static inline void musb_write_rxfifoadd(void __iomem *mbase, u16 c_off) | ||
320 | { | ||
321 | musb_writew(mbase, MUSB_RXFIFOADD, c_off); | ||
322 | } | ||
323 | |||
324 | static inline u8 musb_read_configdata(void __iomem *mbase) | ||
325 | { | ||
326 | return musb_readb(mbase, 0x10 + MUSB_CONFIGDATA); | ||
327 | } | ||
328 | |||
329 | static inline u16 musb_read_hwvers(void __iomem *mbase) | ||
330 | { | ||
331 | return musb_readw(mbase, MUSB_HWVERS); | ||
332 | } | ||
333 | |||
334 | static inline void __iomem *musb_read_target_reg_base(u8 i, void __iomem *mbase) | ||
335 | { | ||
336 | return (MUSB_BUSCTL_OFFSET(i, 0) + mbase); | ||
337 | } | ||
338 | |||
339 | static inline void musb_write_rxfunaddr(void __iomem *ep_target_regs, | ||
340 | u8 qh_addr_reg) | ||
341 | { | ||
342 | musb_writeb(ep_target_regs, MUSB_RXFUNCADDR, qh_addr_reg); | ||
343 | } | ||
344 | |||
345 | static inline void musb_write_rxhubaddr(void __iomem *ep_target_regs, | ||
346 | u8 qh_h_addr_reg) | ||
347 | { | ||
348 | musb_writeb(ep_target_regs, MUSB_RXHUBADDR, qh_h_addr_reg); | ||
349 | } | ||
350 | |||
351 | static inline void musb_write_rxhubport(void __iomem *ep_target_regs, | ||
352 | u8 qh_h_port_reg) | ||
353 | { | ||
354 | musb_writeb(ep_target_regs, MUSB_RXHUBPORT, qh_h_port_reg); | ||
355 | } | ||
356 | |||
357 | static inline void musb_write_txfunaddr(void __iomem *mbase, u8 epnum, | ||
358 | u8 qh_addr_reg) | ||
359 | { | ||
360 | musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXFUNCADDR), | ||
361 | qh_addr_reg); | ||
362 | } | ||
363 | |||
364 | static inline void musb_write_txhubaddr(void __iomem *mbase, u8 epnum, | ||
365 | u8 qh_addr_reg) | ||
366 | { | ||
367 | musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBADDR), | ||
368 | qh_addr_reg); | ||
369 | } | ||
370 | |||
371 | static inline void musb_write_txhubport(void __iomem *mbase, u8 epnum, | ||
372 | u8 qh_h_port_reg) | ||
373 | { | ||
374 | musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBPORT), | ||
375 | qh_h_port_reg); | ||
376 | } | ||
377 | |||
378 | #else /* CONFIG_BLACKFIN */ | ||
379 | |||
380 | #define USB_BASE USB_FADDR | ||
381 | #define USB_OFFSET(reg) (reg - USB_BASE) | ||
382 | |||
383 | /* | ||
384 | * Common USB registers | ||
385 | */ | ||
386 | #define MUSB_FADDR USB_OFFSET(USB_FADDR) /* 8-bit */ | ||
387 | #define MUSB_POWER USB_OFFSET(USB_POWER) /* 8-bit */ | ||
388 | #define MUSB_INTRTX USB_OFFSET(USB_INTRTX) /* 16-bit */ | ||
389 | #define MUSB_INTRRX USB_OFFSET(USB_INTRRX) | ||
390 | #define MUSB_INTRTXE USB_OFFSET(USB_INTRTXE) | ||
391 | #define MUSB_INTRRXE USB_OFFSET(USB_INTRRXE) | ||
392 | #define MUSB_INTRUSB USB_OFFSET(USB_INTRUSB) /* 8 bit */ | ||
393 | #define MUSB_INTRUSBE USB_OFFSET(USB_INTRUSBE)/* 8 bit */ | ||
394 | #define MUSB_FRAME USB_OFFSET(USB_FRAME) | ||
395 | #define MUSB_INDEX USB_OFFSET(USB_INDEX) /* 8 bit */ | ||
396 | #define MUSB_TESTMODE USB_OFFSET(USB_TESTMODE)/* 8 bit */ | ||
397 | |||
398 | /* Get offset for a given FIFO from musb->mregs */ | ||
399 | #define MUSB_FIFO_OFFSET(epnum) \ | ||
400 | (USB_OFFSET(USB_EP0_FIFO) + ((epnum) * 8)) | ||
401 | |||
402 | /* | ||
403 | * Additional Control Registers | ||
404 | */ | ||
405 | |||
406 | #define MUSB_DEVCTL USB_OFFSET(USB_OTG_DEV_CTL) /* 8 bit */ | ||
407 | |||
408 | #define MUSB_LINKINFO USB_OFFSET(USB_LINKINFO)/* 8 bit */ | ||
409 | #define MUSB_VPLEN USB_OFFSET(USB_VPLEN) /* 8 bit */ | ||
410 | #define MUSB_HS_EOF1 USB_OFFSET(USB_HS_EOF1) /* 8 bit */ | ||
411 | #define MUSB_FS_EOF1 USB_OFFSET(USB_FS_EOF1) /* 8 bit */ | ||
412 | #define MUSB_LS_EOF1 USB_OFFSET(USB_LS_EOF1) /* 8 bit */ | ||
413 | |||
414 | /* Offsets to endpoint registers */ | ||
415 | #define MUSB_TXMAXP 0x00 | ||
416 | #define MUSB_TXCSR 0x04 | ||
417 | #define MUSB_CSR0 MUSB_TXCSR /* Re-used for EP0 */ | ||
418 | #define MUSB_RXMAXP 0x08 | ||
419 | #define MUSB_RXCSR 0x0C | ||
420 | #define MUSB_RXCOUNT 0x10 | ||
421 | #define MUSB_COUNT0 MUSB_RXCOUNT /* Re-used for EP0 */ | ||
422 | #define MUSB_TXTYPE 0x14 | ||
423 | #define MUSB_TYPE0 MUSB_TXTYPE /* Re-used for EP0 */ | ||
424 | #define MUSB_TXINTERVAL 0x18 | ||
425 | #define MUSB_NAKLIMIT0 MUSB_TXINTERVAL /* Re-used for EP0 */ | ||
426 | #define MUSB_RXTYPE 0x1C | ||
427 | #define MUSB_RXINTERVAL 0x20 | ||
428 | #define MUSB_TXCOUNT 0x28 | ||
429 | |||
430 | /* Offsets to endpoint registers in indexed model (using INDEX register) */ | ||
431 | #define MUSB_INDEXED_OFFSET(_epnum, _offset) \ | ||
432 | (0x40 + (_offset)) | ||
433 | |||
434 | /* Offsets to endpoint registers in flat models */ | ||
435 | #define MUSB_FLAT_OFFSET(_epnum, _offset) \ | ||
436 | (USB_OFFSET(USB_EP_NI0_TXMAXP) + (0x40 * (_epnum)) + (_offset)) | ||
437 | |||
438 | /* Not implemented - HW has seperate Tx/Rx FIFO */ | ||
439 | #define MUSB_TXCSR_MODE 0x0000 | ||
440 | |||
441 | /* | ||
442 | * Dummy stub for clk framework, it will be removed | ||
443 | * until Blackfin supports clk framework | ||
444 | */ | ||
445 | #define clk_get(dev, id) NULL | ||
446 | #define clk_put(clock) do {} while (0) | ||
447 | #define clk_enable(clock) do {} while (0) | ||
448 | #define clk_disable(clock) do {} while (0) | ||
449 | |||
450 | static inline void musb_write_txfifosz(void __iomem *mbase, u8 c_size) | ||
451 | { | ||
452 | } | ||
453 | |||
454 | static inline void musb_write_txfifoadd(void __iomem *mbase, u16 c_off) | ||
455 | { | ||
456 | } | ||
457 | |||
458 | static inline void musb_write_rxfifosz(void __iomem *mbase, u8 c_size) | ||
459 | { | ||
460 | } | ||
461 | |||
462 | static inline void musb_write_rxfifoadd(void __iomem *mbase, u16 c_off) | ||
463 | { | ||
464 | } | ||
465 | |||
466 | static inline u8 musb_read_configdata(void __iomem *mbase) | ||
467 | { | ||
468 | return 0; | ||
469 | } | ||
470 | |||
471 | static inline u16 musb_read_hwvers(void __iomem *mbase) | ||
472 | { | ||
473 | return 0; | ||
474 | } | ||
475 | |||
476 | static inline u16 musb_read_target_reg_base(u8 i, void __iomem *mbase) | ||
477 | { | ||
478 | return 0; | ||
479 | } | ||
480 | |||
481 | static inline void musb_write_rxfunaddr(void __iomem *ep_target_regs, | ||
482 | u8 qh_addr_req) | ||
483 | { | ||
484 | } | ||
485 | |||
486 | static inline void musb_write_rxhubaddr(void __iomem *ep_target_regs, | ||
487 | u8 qh_h_addr_reg) | ||
488 | { | ||
489 | } | ||
490 | |||
491 | static inline void musb_write_rxhubport(void __iomem *ep_target_regs, | ||
492 | u8 qh_h_port_reg) | ||
493 | { | ||
494 | } | ||
495 | |||
496 | static inline void musb_write_txfunaddr(void __iomem *mbase, u8 epnum, | ||
497 | u8 qh_addr_reg) | ||
498 | { | ||
499 | } | ||
500 | |||
501 | static inline void musb_write_txhubaddr(void __iomem *mbase, u8 epnum, | ||
502 | u8 qh_addr_reg) | ||
503 | { | ||
504 | } | ||
505 | |||
506 | static inline void musb_write_txhubport(void __iomem *mbase, u8 epnum, | ||
507 | u8 qh_h_port_reg) | ||
508 | { | ||
509 | } | ||
510 | |||
511 | #endif /* CONFIG_BLACKFIN */ | ||
512 | |||
300 | #endif /* __MUSB_REGS_H__ */ | 513 | #endif /* __MUSB_REGS_H__ */ |
diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c index 8c734ef2c1ed..8662e9e159c3 100644 --- a/drivers/usb/musb/musbhsdma.c +++ b/drivers/usb/musb/musbhsdma.c | |||
@@ -34,58 +34,7 @@ | |||
34 | #include <linux/interrupt.h> | 34 | #include <linux/interrupt.h> |
35 | #include <linux/platform_device.h> | 35 | #include <linux/platform_device.h> |
36 | #include "musb_core.h" | 36 | #include "musb_core.h" |
37 | 37 | #include "musbhsdma.h" | |
38 | #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430) | ||
39 | #include "omap2430.h" | ||
40 | #endif | ||
41 | |||
42 | #define MUSB_HSDMA_BASE 0x200 | ||
43 | #define MUSB_HSDMA_INTR (MUSB_HSDMA_BASE + 0) | ||
44 | #define MUSB_HSDMA_CONTROL 0x4 | ||
45 | #define MUSB_HSDMA_ADDRESS 0x8 | ||
46 | #define MUSB_HSDMA_COUNT 0xc | ||
47 | |||
48 | #define MUSB_HSDMA_CHANNEL_OFFSET(_bchannel, _offset) \ | ||
49 | (MUSB_HSDMA_BASE + (_bchannel << 4) + _offset) | ||
50 | |||
51 | /* control register (16-bit): */ | ||
52 | #define MUSB_HSDMA_ENABLE_SHIFT 0 | ||
53 | #define MUSB_HSDMA_TRANSMIT_SHIFT 1 | ||
54 | #define MUSB_HSDMA_MODE1_SHIFT 2 | ||
55 | #define MUSB_HSDMA_IRQENABLE_SHIFT 3 | ||
56 | #define MUSB_HSDMA_ENDPOINT_SHIFT 4 | ||
57 | #define MUSB_HSDMA_BUSERROR_SHIFT 8 | ||
58 | #define MUSB_HSDMA_BURSTMODE_SHIFT 9 | ||
59 | #define MUSB_HSDMA_BURSTMODE (3 << MUSB_HSDMA_BURSTMODE_SHIFT) | ||
60 | #define MUSB_HSDMA_BURSTMODE_UNSPEC 0 | ||
61 | #define MUSB_HSDMA_BURSTMODE_INCR4 1 | ||
62 | #define MUSB_HSDMA_BURSTMODE_INCR8 2 | ||
63 | #define MUSB_HSDMA_BURSTMODE_INCR16 3 | ||
64 | |||
65 | #define MUSB_HSDMA_CHANNELS 8 | ||
66 | |||
67 | struct musb_dma_controller; | ||
68 | |||
69 | struct musb_dma_channel { | ||
70 | struct dma_channel channel; | ||
71 | struct musb_dma_controller *controller; | ||
72 | u32 start_addr; | ||
73 | u32 len; | ||
74 | u16 max_packet_sz; | ||
75 | u8 idx; | ||
76 | u8 epnum; | ||
77 | u8 transmit; | ||
78 | }; | ||
79 | |||
80 | struct musb_dma_controller { | ||
81 | struct dma_controller controller; | ||
82 | struct musb_dma_channel channel[MUSB_HSDMA_CHANNELS]; | ||
83 | void *private_data; | ||
84 | void __iomem *base; | ||
85 | u8 channel_count; | ||
86 | u8 used_channels; | ||
87 | u8 irq; | ||
88 | }; | ||
89 | 38 | ||
90 | static int dma_controller_start(struct dma_controller *c) | 39 | static int dma_controller_start(struct dma_controller *c) |
91 | { | 40 | { |
@@ -203,12 +152,8 @@ static void configure_channel(struct dma_channel *channel, | |||
203 | : 0); | 152 | : 0); |
204 | 153 | ||
205 | /* address/count */ | 154 | /* address/count */ |
206 | musb_writel(mbase, | 155 | musb_write_hsdma_addr(mbase, bchannel, dma_addr); |
207 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS), | 156 | musb_write_hsdma_count(mbase, bchannel, len); |
208 | dma_addr); | ||
209 | musb_writel(mbase, | ||
210 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT), | ||
211 | len); | ||
212 | 157 | ||
213 | /* control (this should start things) */ | 158 | /* control (this should start things) */ |
214 | musb_writew(mbase, | 159 | musb_writew(mbase, |
@@ -279,13 +224,8 @@ static int dma_channel_abort(struct dma_channel *channel) | |||
279 | musb_writew(mbase, | 224 | musb_writew(mbase, |
280 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_CONTROL), | 225 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_CONTROL), |
281 | 0); | 226 | 0); |
282 | musb_writel(mbase, | 227 | musb_write_hsdma_addr(mbase, bchannel, 0); |
283 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS), | 228 | musb_write_hsdma_count(mbase, bchannel, 0); |
284 | 0); | ||
285 | musb_writel(mbase, | ||
286 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT), | ||
287 | 0); | ||
288 | |||
289 | channel->status = MUSB_DMA_STATUS_FREE; | 229 | channel->status = MUSB_DMA_STATUS_FREE; |
290 | } | 230 | } |
291 | 231 | ||
@@ -333,10 +273,8 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data) | |||
333 | } else { | 273 | } else { |
334 | u8 devctl; | 274 | u8 devctl; |
335 | 275 | ||
336 | addr = musb_readl(mbase, | 276 | addr = musb_read_hsdma_addr(mbase, |
337 | MUSB_HSDMA_CHANNEL_OFFSET( | 277 | bchannel); |
338 | bchannel, | ||
339 | MUSB_HSDMA_ADDRESS)); | ||
340 | channel->actual_len = addr | 278 | channel->actual_len = addr |
341 | - musb_channel->start_addr; | 279 | - musb_channel->start_addr; |
342 | 280 | ||
@@ -375,6 +313,12 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data) | |||
375 | } | 313 | } |
376 | } | 314 | } |
377 | } | 315 | } |
316 | |||
317 | #ifdef CONFIG_BLACKFIN | ||
318 | /* Clear DMA interrup flags */ | ||
319 | musb_writeb(mbase, MUSB_HSDMA_INTR, int_hsdma); | ||
320 | #endif | ||
321 | |||
378 | retval = IRQ_HANDLED; | 322 | retval = IRQ_HANDLED; |
379 | done: | 323 | done: |
380 | spin_unlock_irqrestore(&musb->lock, flags); | 324 | spin_unlock_irqrestore(&musb->lock, flags); |
@@ -424,7 +368,7 @@ dma_controller_create(struct musb *musb, void __iomem *base) | |||
424 | controller->controller.channel_abort = dma_channel_abort; | 368 | controller->controller.channel_abort = dma_channel_abort; |
425 | 369 | ||
426 | if (request_irq(irq, dma_controller_irq, IRQF_DISABLED, | 370 | if (request_irq(irq, dma_controller_irq, IRQF_DISABLED, |
427 | musb->controller->bus_id, &controller->controller)) { | 371 | dev_name(musb->controller), &controller->controller)) { |
428 | dev_err(dev, "request_irq %d failed!\n", irq); | 372 | dev_err(dev, "request_irq %d failed!\n", irq); |
429 | dma_controller_destroy(&controller->controller); | 373 | dma_controller_destroy(&controller->controller); |
430 | 374 | ||
diff --git a/drivers/usb/musb/musbhsdma.h b/drivers/usb/musb/musbhsdma.h new file mode 100644 index 000000000000..1299d92dc83f --- /dev/null +++ b/drivers/usb/musb/musbhsdma.h | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | * MUSB OTG driver - support for Mentor's DMA controller | ||
3 | * | ||
4 | * Copyright 2005 Mentor Graphics Corporation | ||
5 | * Copyright (C) 2005-2007 by Texas Instruments | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
19 | * 02110-1301 USA | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED | ||
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN | ||
24 | * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
26 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
28 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
30 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
31 | * | ||
32 | */ | ||
33 | |||
34 | #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430) | ||
35 | #include "omap2430.h" | ||
36 | #endif | ||
37 | |||
38 | #ifndef CONFIG_BLACKFIN | ||
39 | |||
40 | #define MUSB_HSDMA_BASE 0x200 | ||
41 | #define MUSB_HSDMA_INTR (MUSB_HSDMA_BASE + 0) | ||
42 | #define MUSB_HSDMA_CONTROL 0x4 | ||
43 | #define MUSB_HSDMA_ADDRESS 0x8 | ||
44 | #define MUSB_HSDMA_COUNT 0xc | ||
45 | |||
46 | #define MUSB_HSDMA_CHANNEL_OFFSET(_bchannel, _offset) \ | ||
47 | (MUSB_HSDMA_BASE + (_bchannel << 4) + _offset) | ||
48 | |||
49 | #define musb_read_hsdma_addr(mbase, bchannel) \ | ||
50 | musb_readl(mbase, \ | ||
51 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS)) | ||
52 | |||
53 | #define musb_write_hsdma_addr(mbase, bchannel, addr) \ | ||
54 | musb_writel(mbase, \ | ||
55 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS), \ | ||
56 | addr) | ||
57 | |||
58 | #define musb_write_hsdma_count(mbase, bchannel, len) \ | ||
59 | musb_writel(mbase, \ | ||
60 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT), \ | ||
61 | len) | ||
62 | #else | ||
63 | |||
64 | #define MUSB_HSDMA_BASE 0x400 | ||
65 | #define MUSB_HSDMA_INTR (MUSB_HSDMA_BASE + 0) | ||
66 | #define MUSB_HSDMA_CONTROL 0x04 | ||
67 | #define MUSB_HSDMA_ADDR_LOW 0x08 | ||
68 | #define MUSB_HSDMA_ADDR_HIGH 0x0C | ||
69 | #define MUSB_HSDMA_COUNT_LOW 0x10 | ||
70 | #define MUSB_HSDMA_COUNT_HIGH 0x14 | ||
71 | |||
72 | #define MUSB_HSDMA_CHANNEL_OFFSET(_bchannel, _offset) \ | ||
73 | (MUSB_HSDMA_BASE + (_bchannel * 0x20) + _offset) | ||
74 | |||
75 | static inline u32 musb_read_hsdma_addr(void __iomem *mbase, u8 bchannel) | ||
76 | { | ||
77 | u32 addr = musb_readw(mbase, | ||
78 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_HIGH)); | ||
79 | |||
80 | addr = addr << 16; | ||
81 | |||
82 | addr |= musb_readw(mbase, | ||
83 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_LOW)); | ||
84 | |||
85 | return addr; | ||
86 | } | ||
87 | |||
88 | static inline void musb_write_hsdma_addr(void __iomem *mbase, | ||
89 | u8 bchannel, dma_addr_t dma_addr) | ||
90 | { | ||
91 | musb_writew(mbase, | ||
92 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_LOW), | ||
93 | ((u16)((u32) dma_addr & 0xFFFF))); | ||
94 | musb_writew(mbase, | ||
95 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_HIGH), | ||
96 | ((u16)(((u32) dma_addr >> 16) & 0xFFFF))); | ||
97 | } | ||
98 | |||
99 | static inline void musb_write_hsdma_count(void __iomem *mbase, | ||
100 | u8 bchannel, u32 len) | ||
101 | { | ||
102 | musb_writew(mbase, | ||
103 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_LOW), | ||
104 | ((u16)((u32) len & 0xFFFF))); | ||
105 | musb_writew(mbase, | ||
106 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_HIGH), | ||
107 | ((u16)(((u32) len >> 16) & 0xFFFF))); | ||
108 | } | ||
109 | |||
110 | #endif /* CONFIG_BLACKFIN */ | ||
111 | |||
112 | /* control register (16-bit): */ | ||
113 | #define MUSB_HSDMA_ENABLE_SHIFT 0 | ||
114 | #define MUSB_HSDMA_TRANSMIT_SHIFT 1 | ||
115 | #define MUSB_HSDMA_MODE1_SHIFT 2 | ||
116 | #define MUSB_HSDMA_IRQENABLE_SHIFT 3 | ||
117 | #define MUSB_HSDMA_ENDPOINT_SHIFT 4 | ||
118 | #define MUSB_HSDMA_BUSERROR_SHIFT 8 | ||
119 | #define MUSB_HSDMA_BURSTMODE_SHIFT 9 | ||
120 | #define MUSB_HSDMA_BURSTMODE (3 << MUSB_HSDMA_BURSTMODE_SHIFT) | ||
121 | #define MUSB_HSDMA_BURSTMODE_UNSPEC 0 | ||
122 | #define MUSB_HSDMA_BURSTMODE_INCR4 1 | ||
123 | #define MUSB_HSDMA_BURSTMODE_INCR8 2 | ||
124 | #define MUSB_HSDMA_BURSTMODE_INCR16 3 | ||
125 | |||
126 | #define MUSB_HSDMA_CHANNELS 8 | ||
127 | |||
128 | struct musb_dma_controller; | ||
129 | |||
130 | struct musb_dma_channel { | ||
131 | struct dma_channel channel; | ||
132 | struct musb_dma_controller *controller; | ||
133 | u32 start_addr; | ||
134 | u32 len; | ||
135 | u16 max_packet_sz; | ||
136 | u8 idx; | ||
137 | u8 epnum; | ||
138 | u8 transmit; | ||
139 | }; | ||
140 | |||
141 | struct musb_dma_controller { | ||
142 | struct dma_controller controller; | ||
143 | struct musb_dma_channel channel[MUSB_HSDMA_CHANNELS]; | ||
144 | void *private_data; | ||
145 | void __iomem *base; | ||
146 | u8 channel_count; | ||
147 | u8 used_channels; | ||
148 | u8 irq; | ||
149 | }; | ||
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index ce6c162920f7..901dffdf23b1 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c | |||
@@ -58,10 +58,10 @@ static void musb_do_idle(unsigned long _musb) | |||
58 | #endif | 58 | #endif |
59 | u8 devctl; | 59 | u8 devctl; |
60 | 60 | ||
61 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | ||
62 | |||
63 | spin_lock_irqsave(&musb->lock, flags); | 61 | spin_lock_irqsave(&musb->lock, flags); |
64 | 62 | ||
63 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | ||
64 | |||
65 | switch (musb->xceiv.state) { | 65 | switch (musb->xceiv.state) { |
66 | case OTG_STATE_A_WAIT_BCON: | 66 | case OTG_STATE_A_WAIT_BCON: |
67 | devctl &= ~MUSB_DEVCTL_SESSION; | 67 | devctl &= ~MUSB_DEVCTL_SESSION; |
@@ -196,7 +196,7 @@ static int omap_set_power(struct otg_transceiver *x, unsigned mA) | |||
196 | 196 | ||
197 | static int musb_platform_resume(struct musb *musb); | 197 | static int musb_platform_resume(struct musb *musb); |
198 | 198 | ||
199 | void musb_platform_set_mode(struct musb *musb, u8 musb_mode) | 199 | int musb_platform_set_mode(struct musb *musb, u8 musb_mode) |
200 | { | 200 | { |
201 | u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | 201 | u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
202 | 202 | ||
@@ -204,15 +204,24 @@ void musb_platform_set_mode(struct musb *musb, u8 musb_mode) | |||
204 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | 204 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
205 | 205 | ||
206 | switch (musb_mode) { | 206 | switch (musb_mode) { |
207 | #ifdef CONFIG_USB_MUSB_HDRC_HCD | ||
207 | case MUSB_HOST: | 208 | case MUSB_HOST: |
208 | otg_set_host(&musb->xceiv, musb->xceiv.host); | 209 | otg_set_host(&musb->xceiv, musb->xceiv.host); |
209 | break; | 210 | break; |
211 | #endif | ||
212 | #ifdef CONFIG_USB_GADGET_MUSB_HDRC | ||
210 | case MUSB_PERIPHERAL: | 213 | case MUSB_PERIPHERAL: |
211 | otg_set_peripheral(&musb->xceiv, musb->xceiv.gadget); | 214 | otg_set_peripheral(&musb->xceiv, musb->xceiv.gadget); |
212 | break; | 215 | break; |
216 | #endif | ||
217 | #ifdef CONFIG_USB_MUSB_OTG | ||
213 | case MUSB_OTG: | 218 | case MUSB_OTG: |
214 | break; | 219 | break; |
220 | #endif | ||
221 | default: | ||
222 | return -EINVAL; | ||
215 | } | 223 | } |
224 | return 0; | ||
216 | } | 225 | } |
217 | 226 | ||
218 | int __init musb_platform_init(struct musb *musb) | 227 | int __init musb_platform_init(struct musb *musb) |
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c index ee8fca92a4ac..9e20fd070d71 100644 --- a/drivers/usb/musb/tusb6010.c +++ b/drivers/usb/musb/tusb6010.c | |||
@@ -598,7 +598,7 @@ static void tusb_source_power(struct musb *musb, int is_on) | |||
598 | * and peripheral modes in non-OTG configurations by reconfiguring hardware | 598 | * and peripheral modes in non-OTG configurations by reconfiguring hardware |
599 | * and then setting musb->board_mode. For now, only support OTG mode. | 599 | * and then setting musb->board_mode. For now, only support OTG mode. |
600 | */ | 600 | */ |
601 | void musb_platform_set_mode(struct musb *musb, u8 musb_mode) | 601 | int musb_platform_set_mode(struct musb *musb, u8 musb_mode) |
602 | { | 602 | { |
603 | void __iomem *tbase = musb->ctrl_base; | 603 | void __iomem *tbase = musb->ctrl_base; |
604 | u32 otg_stat, phy_otg_ctrl, phy_otg_ena, dev_conf; | 604 | u32 otg_stat, phy_otg_ctrl, phy_otg_ena, dev_conf; |
@@ -641,7 +641,8 @@ void musb_platform_set_mode(struct musb *musb, u8 musb_mode) | |||
641 | #endif | 641 | #endif |
642 | 642 | ||
643 | default: | 643 | default: |
644 | DBG(2, "Trying to set unknown mode %i\n", musb_mode); | 644 | DBG(2, "Trying to set mode %i\n", musb_mode); |
645 | return -EINVAL; | ||
645 | } | 646 | } |
646 | 647 | ||
647 | musb_writel(tbase, TUSB_PHY_OTG_CTRL, | 648 | musb_writel(tbase, TUSB_PHY_OTG_CTRL, |
@@ -655,6 +656,8 @@ void musb_platform_set_mode(struct musb *musb, u8 musb_mode) | |||
655 | !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS)) | 656 | !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS)) |
656 | INFO("Cannot be peripheral with mini-A cable " | 657 | INFO("Cannot be peripheral with mini-A cable " |
657 | "otg_stat: %08x\n", otg_stat); | 658 | "otg_stat: %08x\n", otg_stat); |
659 | |||
660 | return 0; | ||
658 | } | 661 | } |
659 | 662 | ||
660 | static inline unsigned long | 663 | static inline unsigned long |
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig new file mode 100644 index 000000000000..8e8dbdb9b39b --- /dev/null +++ b/drivers/usb/otg/Kconfig | |||
@@ -0,0 +1,54 @@ | |||
1 | # | ||
2 | # USB OTG infrastructure may be needed for peripheral-only, host-only, | ||
3 | # or OTG-capable configurations when OTG transceivers or controllers | ||
4 | # are used. | ||
5 | # | ||
6 | |||
7 | comment "OTG and related infrastructure" | ||
8 | |||
9 | if USB || USB_GADGET | ||
10 | |||
11 | config USB_OTG_UTILS | ||
12 | bool | ||
13 | help | ||
14 | Select this to make sure the build includes objects from | ||
15 | the OTG infrastructure directory. | ||
16 | |||
17 | # | ||
18 | # USB Transceiver Drivers | ||
19 | # | ||
20 | config USB_GPIO_VBUS | ||
21 | tristate "GPIO based peripheral-only VBUS sensing 'transceiver'" | ||
22 | depends on GENERIC_GPIO | ||
23 | select USB_OTG_UTILS | ||
24 | help | ||
25 | Provides simple GPIO VBUS sensing for controllers with an | ||
26 | internal transceiver via the otg_transceiver interface, and | ||
27 | optionally control of a D+ pullup GPIO as well as a VBUS | ||
28 | current limit regulator. | ||
29 | |||
30 | config ISP1301_OMAP | ||
31 | tristate "Philips ISP1301 with OMAP OTG" | ||
32 | depends on I2C && ARCH_OMAP_OTG | ||
33 | select USB_OTG_UTILS | ||
34 | help | ||
35 | If you say yes here you get support for the Philips ISP1301 | ||
36 | USB-On-The-Go transceiver working with the OMAP OTG controller. | ||
37 | The ISP1301 is a full speed USB transceiver which is used in | ||
38 | products including H2, H3, and H4 development boards for Texas | ||
39 | Instruments OMAP processors. | ||
40 | |||
41 | This driver can also be built as a module. If so, the module | ||
42 | will be called isp1301_omap. | ||
43 | |||
44 | config TWL4030_USB | ||
45 | tristate "TWL4030 USB Transceiver Driver" | ||
46 | depends on TWL4030_CORE | ||
47 | select USB_OTG_UTILS | ||
48 | help | ||
49 | Enable this to support the USB OTG transceiver on TWL4030 | ||
50 | family chips (including the TWL5030 and TPS659x0 devices). | ||
51 | This transceiver supports high and full speed devices plus, | ||
52 | in host mode, low speed. | ||
53 | |||
54 | endif # USB || OTG | ||
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile new file mode 100644 index 000000000000..d73c7cf5e2f7 --- /dev/null +++ b/drivers/usb/otg/Makefile | |||
@@ -0,0 +1,15 @@ | |||
1 | # | ||
2 | # OTG infrastructure and transceiver drivers | ||
3 | # | ||
4 | |||
5 | # infrastructure | ||
6 | obj-$(CONFIG_USB_OTG_UTILS) += otg.o | ||
7 | |||
8 | # transceiver drivers | ||
9 | obj-$(CONFIG_USB_GPIO_VBUS) += gpio_vbus.o | ||
10 | obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o | ||
11 | obj-$(CONFIG_TWL4030_USB) += twl4030-usb.o | ||
12 | |||
13 | ccflags-$(CONFIG_USB_DEBUG) += -DDEBUG | ||
14 | ccflags-$(CONFIG_USB_GADGET_DEBUG) += -DDEBUG | ||
15 | |||
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/otg/gpio_vbus.c new file mode 100644 index 000000000000..63a6036f04be --- /dev/null +++ b/drivers/usb/otg/gpio_vbus.c | |||
@@ -0,0 +1,335 @@ | |||
1 | /* | ||
2 | * gpio-vbus.c - simple GPIO VBUS sensing driver for B peripheral devices | ||
3 | * | ||
4 | * Copyright (c) 2008 Philipp Zabel <philipp.zabel@gmail.com> | ||
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 version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/platform_device.h> | ||
13 | #include <linux/gpio.h> | ||
14 | #include <linux/interrupt.h> | ||
15 | #include <linux/usb.h> | ||
16 | |||
17 | #include <linux/regulator/consumer.h> | ||
18 | |||
19 | #include <linux/usb/gadget.h> | ||
20 | #include <linux/usb/gpio_vbus.h> | ||
21 | #include <linux/usb/otg.h> | ||
22 | |||
23 | |||
24 | /* | ||
25 | * A simple GPIO VBUS sensing driver for B peripheral only devices | ||
26 | * with internal transceivers. It can control a D+ pullup GPIO and | ||
27 | * a regulator to limit the current drawn from VBUS. | ||
28 | * | ||
29 | * Needs to be loaded before the UDC driver that will use it. | ||
30 | */ | ||
31 | struct gpio_vbus_data { | ||
32 | struct otg_transceiver otg; | ||
33 | struct device *dev; | ||
34 | struct regulator *vbus_draw; | ||
35 | int vbus_draw_enabled; | ||
36 | unsigned mA; | ||
37 | }; | ||
38 | |||
39 | |||
40 | /* | ||
41 | * This driver relies on "both edges" triggering. VBUS has 100 msec to | ||
42 | * stabilize, so the peripheral controller driver may need to cope with | ||
43 | * some bouncing due to current surges (e.g. charging local capacitance) | ||
44 | * and contact chatter. | ||
45 | * | ||
46 | * REVISIT in desperate straits, toggling between rising and falling | ||
47 | * edges might be workable. | ||
48 | */ | ||
49 | #define VBUS_IRQ_FLAGS \ | ||
50 | ( IRQF_SAMPLE_RANDOM | IRQF_SHARED \ | ||
51 | | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING ) | ||
52 | |||
53 | |||
54 | /* interface to regulator framework */ | ||
55 | static void set_vbus_draw(struct gpio_vbus_data *gpio_vbus, unsigned mA) | ||
56 | { | ||
57 | struct regulator *vbus_draw = gpio_vbus->vbus_draw; | ||
58 | int enabled; | ||
59 | |||
60 | if (!vbus_draw) | ||
61 | return; | ||
62 | |||
63 | enabled = gpio_vbus->vbus_draw_enabled; | ||
64 | if (mA) { | ||
65 | regulator_set_current_limit(vbus_draw, 0, 1000 * mA); | ||
66 | if (!enabled) { | ||
67 | regulator_enable(vbus_draw); | ||
68 | gpio_vbus->vbus_draw_enabled = 1; | ||
69 | } | ||
70 | } else { | ||
71 | if (enabled) { | ||
72 | regulator_disable(vbus_draw); | ||
73 | gpio_vbus->vbus_draw_enabled = 0; | ||
74 | } | ||
75 | } | ||
76 | gpio_vbus->mA = mA; | ||
77 | } | ||
78 | |||
79 | /* VBUS change IRQ handler */ | ||
80 | static irqreturn_t gpio_vbus_irq(int irq, void *data) | ||
81 | { | ||
82 | struct platform_device *pdev = data; | ||
83 | struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; | ||
84 | struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev); | ||
85 | int gpio, vbus; | ||
86 | |||
87 | vbus = gpio_get_value(pdata->gpio_vbus); | ||
88 | if (pdata->gpio_vbus_inverted) | ||
89 | vbus = !vbus; | ||
90 | |||
91 | dev_dbg(&pdev->dev, "VBUS %s (gadget: %s)\n", | ||
92 | vbus ? "supplied" : "inactive", | ||
93 | gpio_vbus->otg.gadget ? gpio_vbus->otg.gadget->name : "none"); | ||
94 | |||
95 | if (!gpio_vbus->otg.gadget) | ||
96 | return IRQ_HANDLED; | ||
97 | |||
98 | /* Peripheral controllers which manage the pullup themselves won't have | ||
99 | * gpio_pullup configured here. If it's configured here, we'll do what | ||
100 | * isp1301_omap::b_peripheral() does and enable the pullup here... although | ||
101 | * that may complicate usb_gadget_{,dis}connect() support. | ||
102 | */ | ||
103 | gpio = pdata->gpio_pullup; | ||
104 | if (vbus) { | ||
105 | gpio_vbus->otg.state = OTG_STATE_B_PERIPHERAL; | ||
106 | usb_gadget_vbus_connect(gpio_vbus->otg.gadget); | ||
107 | |||
108 | /* drawing a "unit load" is *always* OK, except for OTG */ | ||
109 | set_vbus_draw(gpio_vbus, 100); | ||
110 | |||
111 | /* optionally enable D+ pullup */ | ||
112 | if (gpio_is_valid(gpio)) | ||
113 | gpio_set_value(gpio, !pdata->gpio_pullup_inverted); | ||
114 | } else { | ||
115 | /* optionally disable D+ pullup */ | ||
116 | if (gpio_is_valid(gpio)) | ||
117 | gpio_set_value(gpio, pdata->gpio_pullup_inverted); | ||
118 | |||
119 | set_vbus_draw(gpio_vbus, 0); | ||
120 | |||
121 | usb_gadget_vbus_disconnect(gpio_vbus->otg.gadget); | ||
122 | gpio_vbus->otg.state = OTG_STATE_B_IDLE; | ||
123 | } | ||
124 | |||
125 | return IRQ_HANDLED; | ||
126 | } | ||
127 | |||
128 | /* OTG transceiver interface */ | ||
129 | |||
130 | /* bind/unbind the peripheral controller */ | ||
131 | static int gpio_vbus_set_peripheral(struct otg_transceiver *otg, | ||
132 | struct usb_gadget *gadget) | ||
133 | { | ||
134 | struct gpio_vbus_data *gpio_vbus; | ||
135 | struct gpio_vbus_mach_info *pdata; | ||
136 | struct platform_device *pdev; | ||
137 | int gpio, irq; | ||
138 | |||
139 | gpio_vbus = container_of(otg, struct gpio_vbus_data, otg); | ||
140 | pdev = to_platform_device(gpio_vbus->dev); | ||
141 | pdata = gpio_vbus->dev->platform_data; | ||
142 | irq = gpio_to_irq(pdata->gpio_vbus); | ||
143 | gpio = pdata->gpio_pullup; | ||
144 | |||
145 | if (!gadget) { | ||
146 | dev_dbg(&pdev->dev, "unregistering gadget '%s'\n", | ||
147 | otg->gadget->name); | ||
148 | |||
149 | /* optionally disable D+ pullup */ | ||
150 | if (gpio_is_valid(gpio)) | ||
151 | gpio_set_value(gpio, pdata->gpio_pullup_inverted); | ||
152 | |||
153 | set_vbus_draw(gpio_vbus, 0); | ||
154 | |||
155 | usb_gadget_vbus_disconnect(otg->gadget); | ||
156 | otg->state = OTG_STATE_UNDEFINED; | ||
157 | |||
158 | otg->gadget = NULL; | ||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | otg->gadget = gadget; | ||
163 | dev_dbg(&pdev->dev, "registered gadget '%s'\n", gadget->name); | ||
164 | |||
165 | /* initialize connection state */ | ||
166 | gpio_vbus_irq(irq, pdev); | ||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | /* effective for B devices, ignored for A-peripheral */ | ||
171 | static int gpio_vbus_set_power(struct otg_transceiver *otg, unsigned mA) | ||
172 | { | ||
173 | struct gpio_vbus_data *gpio_vbus; | ||
174 | |||
175 | gpio_vbus = container_of(otg, struct gpio_vbus_data, otg); | ||
176 | |||
177 | if (otg->state == OTG_STATE_B_PERIPHERAL) | ||
178 | set_vbus_draw(gpio_vbus, mA); | ||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | /* for non-OTG B devices: set/clear transceiver suspend mode */ | ||
183 | static int gpio_vbus_set_suspend(struct otg_transceiver *otg, int suspend) | ||
184 | { | ||
185 | struct gpio_vbus_data *gpio_vbus; | ||
186 | |||
187 | gpio_vbus = container_of(otg, struct gpio_vbus_data, otg); | ||
188 | |||
189 | /* draw max 0 mA from vbus in suspend mode; or the previously | ||
190 | * recorded amount of current if not suspended | ||
191 | * | ||
192 | * NOTE: high powered configs (mA > 100) may draw up to 2.5 mA | ||
193 | * if they're wake-enabled ... we don't handle that yet. | ||
194 | */ | ||
195 | return gpio_vbus_set_power(otg, suspend ? 0 : gpio_vbus->mA); | ||
196 | } | ||
197 | |||
198 | /* platform driver interface */ | ||
199 | |||
200 | static int __init gpio_vbus_probe(struct platform_device *pdev) | ||
201 | { | ||
202 | struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; | ||
203 | struct gpio_vbus_data *gpio_vbus; | ||
204 | struct resource *res; | ||
205 | int err, gpio, irq; | ||
206 | |||
207 | if (!pdata || !gpio_is_valid(pdata->gpio_vbus)) | ||
208 | return -EINVAL; | ||
209 | gpio = pdata->gpio_vbus; | ||
210 | |||
211 | gpio_vbus = kzalloc(sizeof(struct gpio_vbus_data), GFP_KERNEL); | ||
212 | if (!gpio_vbus) | ||
213 | return -ENOMEM; | ||
214 | |||
215 | platform_set_drvdata(pdev, gpio_vbus); | ||
216 | gpio_vbus->dev = &pdev->dev; | ||
217 | gpio_vbus->otg.label = "gpio-vbus"; | ||
218 | gpio_vbus->otg.state = OTG_STATE_UNDEFINED; | ||
219 | gpio_vbus->otg.set_peripheral = gpio_vbus_set_peripheral; | ||
220 | gpio_vbus->otg.set_power = gpio_vbus_set_power; | ||
221 | gpio_vbus->otg.set_suspend = gpio_vbus_set_suspend; | ||
222 | |||
223 | err = gpio_request(gpio, "vbus_detect"); | ||
224 | if (err) { | ||
225 | dev_err(&pdev->dev, "can't request vbus gpio %d, err: %d\n", | ||
226 | gpio, err); | ||
227 | goto err_gpio; | ||
228 | } | ||
229 | gpio_direction_input(gpio); | ||
230 | |||
231 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
232 | if (res) { | ||
233 | irq = res->start; | ||
234 | res->flags &= IRQF_TRIGGER_MASK; | ||
235 | res->flags |= IRQF_SAMPLE_RANDOM | IRQF_SHARED; | ||
236 | } else | ||
237 | irq = gpio_to_irq(gpio); | ||
238 | |||
239 | /* if data line pullup is in use, initialize it to "not pulling up" */ | ||
240 | gpio = pdata->gpio_pullup; | ||
241 | if (gpio_is_valid(gpio)) { | ||
242 | err = gpio_request(gpio, "udc_pullup"); | ||
243 | if (err) { | ||
244 | dev_err(&pdev->dev, | ||
245 | "can't request pullup gpio %d, err: %d\n", | ||
246 | gpio, err); | ||
247 | gpio_free(pdata->gpio_vbus); | ||
248 | goto err_gpio; | ||
249 | } | ||
250 | gpio_direction_output(gpio, pdata->gpio_pullup_inverted); | ||
251 | } | ||
252 | |||
253 | err = request_irq(irq, gpio_vbus_irq, VBUS_IRQ_FLAGS, | ||
254 | "vbus_detect", pdev); | ||
255 | if (err) { | ||
256 | dev_err(&pdev->dev, "can't request irq %i, err: %d\n", | ||
257 | irq, err); | ||
258 | goto err_irq; | ||
259 | } | ||
260 | |||
261 | /* only active when a gadget is registered */ | ||
262 | err = otg_set_transceiver(&gpio_vbus->otg); | ||
263 | if (err) { | ||
264 | dev_err(&pdev->dev, "can't register transceiver, err: %d\n", | ||
265 | err); | ||
266 | goto err_otg; | ||
267 | } | ||
268 | |||
269 | gpio_vbus->vbus_draw = regulator_get(&pdev->dev, "vbus_draw"); | ||
270 | if (IS_ERR(gpio_vbus->vbus_draw)) { | ||
271 | dev_dbg(&pdev->dev, "can't get vbus_draw regulator, err: %ld\n", | ||
272 | PTR_ERR(gpio_vbus->vbus_draw)); | ||
273 | gpio_vbus->vbus_draw = NULL; | ||
274 | } | ||
275 | |||
276 | return 0; | ||
277 | err_otg: | ||
278 | free_irq(irq, &pdev->dev); | ||
279 | err_irq: | ||
280 | if (gpio_is_valid(pdata->gpio_pullup)) | ||
281 | gpio_free(pdata->gpio_pullup); | ||
282 | gpio_free(pdata->gpio_vbus); | ||
283 | err_gpio: | ||
284 | platform_set_drvdata(pdev, NULL); | ||
285 | kfree(gpio_vbus); | ||
286 | return err; | ||
287 | } | ||
288 | |||
289 | static int __exit gpio_vbus_remove(struct platform_device *pdev) | ||
290 | { | ||
291 | struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev); | ||
292 | struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; | ||
293 | int gpio = pdata->gpio_vbus; | ||
294 | |||
295 | regulator_put(gpio_vbus->vbus_draw); | ||
296 | |||
297 | otg_set_transceiver(NULL); | ||
298 | |||
299 | free_irq(gpio_to_irq(gpio), &pdev->dev); | ||
300 | if (gpio_is_valid(pdata->gpio_pullup)) | ||
301 | gpio_free(pdata->gpio_pullup); | ||
302 | gpio_free(gpio); | ||
303 | platform_set_drvdata(pdev, NULL); | ||
304 | kfree(gpio_vbus); | ||
305 | |||
306 | return 0; | ||
307 | } | ||
308 | |||
309 | /* NOTE: the gpio-vbus device may *NOT* be hotplugged */ | ||
310 | |||
311 | MODULE_ALIAS("platform:gpio-vbus"); | ||
312 | |||
313 | static struct platform_driver gpio_vbus_driver = { | ||
314 | .driver = { | ||
315 | .name = "gpio-vbus", | ||
316 | .owner = THIS_MODULE, | ||
317 | }, | ||
318 | .remove = __exit_p(gpio_vbus_remove), | ||
319 | }; | ||
320 | |||
321 | static int __init gpio_vbus_init(void) | ||
322 | { | ||
323 | return platform_driver_probe(&gpio_vbus_driver, gpio_vbus_probe); | ||
324 | } | ||
325 | module_init(gpio_vbus_init); | ||
326 | |||
327 | static void __exit gpio_vbus_exit(void) | ||
328 | { | ||
329 | platform_driver_unregister(&gpio_vbus_driver); | ||
330 | } | ||
331 | module_exit(gpio_vbus_exit); | ||
332 | |||
333 | MODULE_DESCRIPTION("simple GPIO controlled OTG transceiver driver"); | ||
334 | MODULE_AUTHOR("Philipp Zabel"); | ||
335 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/otg/isp1301_omap.c new file mode 100644 index 000000000000..e0d56ef2bcb0 --- /dev/null +++ b/drivers/usb/otg/isp1301_omap.c | |||
@@ -0,0 +1,1683 @@ | |||
1 | /* | ||
2 | * isp1301_omap - ISP 1301 USB transceiver, talking to OMAP OTG controller | ||
3 | * | ||
4 | * Copyright (C) 2004 Texas Instruments | ||
5 | * Copyright (C) 2004 David Brownell | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/gpio.h> | ||
29 | #include <linux/usb/ch9.h> | ||
30 | #include <linux/usb/gadget.h> | ||
31 | #include <linux/usb.h> | ||
32 | #include <linux/usb/otg.h> | ||
33 | #include <linux/i2c.h> | ||
34 | #include <linux/workqueue.h> | ||
35 | |||
36 | #include <asm/irq.h> | ||
37 | #include <asm/mach-types.h> | ||
38 | |||
39 | #include <mach/usb.h> | ||
40 | #include <mach/mux.h> | ||
41 | |||
42 | |||
43 | #ifndef DEBUG | ||
44 | #undef VERBOSE | ||
45 | #endif | ||
46 | |||
47 | |||
48 | #define DRIVER_VERSION "24 August 2004" | ||
49 | #define DRIVER_NAME (isp1301_driver.driver.name) | ||
50 | |||
51 | MODULE_DESCRIPTION("ISP1301 USB OTG Transceiver Driver"); | ||
52 | MODULE_LICENSE("GPL"); | ||
53 | |||
54 | struct isp1301 { | ||
55 | struct otg_transceiver otg; | ||
56 | struct i2c_client *client; | ||
57 | void (*i2c_release)(struct device *dev); | ||
58 | |||
59 | int irq_type; | ||
60 | |||
61 | u32 last_otg_ctrl; | ||
62 | unsigned working:1; | ||
63 | |||
64 | struct timer_list timer; | ||
65 | |||
66 | /* use keventd context to change the state for us */ | ||
67 | struct work_struct work; | ||
68 | |||
69 | unsigned long todo; | ||
70 | # define WORK_UPDATE_ISP 0 /* update ISP from OTG */ | ||
71 | # define WORK_UPDATE_OTG 1 /* update OTG from ISP */ | ||
72 | # define WORK_HOST_RESUME 4 /* resume host */ | ||
73 | # define WORK_TIMER 6 /* timer fired */ | ||
74 | # define WORK_STOP 7 /* don't resubmit */ | ||
75 | }; | ||
76 | |||
77 | |||
78 | /* bits in OTG_CTRL */ | ||
79 | |||
80 | #define OTG_XCEIV_OUTPUTS \ | ||
81 | (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID) | ||
82 | #define OTG_XCEIV_INPUTS \ | ||
83 | (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID) | ||
84 | #define OTG_CTRL_BITS \ | ||
85 | (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP) | ||
86 | /* and OTG_PULLUP is sometimes written */ | ||
87 | |||
88 | #define OTG_CTRL_MASK (OTG_DRIVER_SEL| \ | ||
89 | OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \ | ||
90 | OTG_CTRL_BITS) | ||
91 | |||
92 | |||
93 | /*-------------------------------------------------------------------------*/ | ||
94 | |||
95 | /* board-specific PM hooks */ | ||
96 | |||
97 | #if defined(CONFIG_MACH_OMAP_H2) || defined(CONFIG_MACH_OMAP_H3) | ||
98 | |||
99 | #if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE) | ||
100 | |||
101 | #include <linux/i2c/tps65010.h> | ||
102 | |||
103 | #else | ||
104 | |||
105 | static inline int tps65010_set_vbus_draw(unsigned mA) | ||
106 | { | ||
107 | pr_debug("tps65010: draw %d mA (STUB)\n", mA); | ||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | #endif | ||
112 | |||
113 | static void enable_vbus_draw(struct isp1301 *isp, unsigned mA) | ||
114 | { | ||
115 | int status = tps65010_set_vbus_draw(mA); | ||
116 | if (status < 0) | ||
117 | pr_debug(" VBUS %d mA error %d\n", mA, status); | ||
118 | } | ||
119 | |||
120 | static void enable_vbus_source(struct isp1301 *isp) | ||
121 | { | ||
122 | /* this board won't supply more than 8mA vbus power. | ||
123 | * some boards can switch a 100ma "unit load" (or more). | ||
124 | */ | ||
125 | } | ||
126 | |||
127 | |||
128 | /* products will deliver OTG messages with LEDs, GUI, etc */ | ||
129 | static inline void notresponding(struct isp1301 *isp) | ||
130 | { | ||
131 | printk(KERN_NOTICE "OTG device not responding.\n"); | ||
132 | } | ||
133 | |||
134 | |||
135 | #endif | ||
136 | |||
137 | #if defined(CONFIG_MACH_OMAP_H4) | ||
138 | |||
139 | static void enable_vbus_draw(struct isp1301 *isp, unsigned mA) | ||
140 | { | ||
141 | /* H4 controls this by DIP switch S2.4; no soft control. | ||
142 | * ON means the charger is always enabled. Leave it OFF | ||
143 | * unless the OTG port is used only in B-peripheral mode. | ||
144 | */ | ||
145 | } | ||
146 | |||
147 | static void enable_vbus_source(struct isp1301 *isp) | ||
148 | { | ||
149 | /* this board won't supply more than 8mA vbus power. | ||
150 | * some boards can switch a 100ma "unit load" (or more). | ||
151 | */ | ||
152 | } | ||
153 | |||
154 | |||
155 | /* products will deliver OTG messages with LEDs, GUI, etc */ | ||
156 | static inline void notresponding(struct isp1301 *isp) | ||
157 | { | ||
158 | printk(KERN_NOTICE "OTG device not responding.\n"); | ||
159 | } | ||
160 | |||
161 | |||
162 | #endif | ||
163 | |||
164 | /*-------------------------------------------------------------------------*/ | ||
165 | |||
166 | static struct i2c_driver isp1301_driver; | ||
167 | |||
168 | /* smbus apis are used for portability */ | ||
169 | |||
170 | static inline u8 | ||
171 | isp1301_get_u8(struct isp1301 *isp, u8 reg) | ||
172 | { | ||
173 | return i2c_smbus_read_byte_data(isp->client, reg + 0); | ||
174 | } | ||
175 | |||
176 | static inline int | ||
177 | isp1301_get_u16(struct isp1301 *isp, u8 reg) | ||
178 | { | ||
179 | return i2c_smbus_read_word_data(isp->client, reg); | ||
180 | } | ||
181 | |||
182 | static inline int | ||
183 | isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits) | ||
184 | { | ||
185 | return i2c_smbus_write_byte_data(isp->client, reg + 0, bits); | ||
186 | } | ||
187 | |||
188 | static inline int | ||
189 | isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits) | ||
190 | { | ||
191 | return i2c_smbus_write_byte_data(isp->client, reg + 1, bits); | ||
192 | } | ||
193 | |||
194 | /*-------------------------------------------------------------------------*/ | ||
195 | |||
196 | /* identification */ | ||
197 | #define ISP1301_VENDOR_ID 0x00 /* u16 read */ | ||
198 | #define ISP1301_PRODUCT_ID 0x02 /* u16 read */ | ||
199 | #define ISP1301_BCD_DEVICE 0x14 /* u16 read */ | ||
200 | |||
201 | #define I2C_VENDOR_ID_PHILIPS 0x04cc | ||
202 | #define I2C_PRODUCT_ID_PHILIPS_1301 0x1301 | ||
203 | |||
204 | /* operational registers */ | ||
205 | #define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */ | ||
206 | # define MC1_SPEED (1 << 0) | ||
207 | # define MC1_SUSPEND (1 << 1) | ||
208 | # define MC1_DAT_SE0 (1 << 2) | ||
209 | # define MC1_TRANSPARENT (1 << 3) | ||
210 | # define MC1_BDIS_ACON_EN (1 << 4) | ||
211 | # define MC1_OE_INT_EN (1 << 5) | ||
212 | # define MC1_UART_EN (1 << 6) | ||
213 | # define MC1_MASK 0x7f | ||
214 | #define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */ | ||
215 | # define MC2_GLOBAL_PWR_DN (1 << 0) | ||
216 | # define MC2_SPD_SUSP_CTRL (1 << 1) | ||
217 | # define MC2_BI_DI (1 << 2) | ||
218 | # define MC2_TRANSP_BDIR0 (1 << 3) | ||
219 | # define MC2_TRANSP_BDIR1 (1 << 4) | ||
220 | # define MC2_AUDIO_EN (1 << 5) | ||
221 | # define MC2_PSW_EN (1 << 6) | ||
222 | # define MC2_EN2V7 (1 << 7) | ||
223 | #define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */ | ||
224 | # define OTG1_DP_PULLUP (1 << 0) | ||
225 | # define OTG1_DM_PULLUP (1 << 1) | ||
226 | # define OTG1_DP_PULLDOWN (1 << 2) | ||
227 | # define OTG1_DM_PULLDOWN (1 << 3) | ||
228 | # define OTG1_ID_PULLDOWN (1 << 4) | ||
229 | # define OTG1_VBUS_DRV (1 << 5) | ||
230 | # define OTG1_VBUS_DISCHRG (1 << 6) | ||
231 | # define OTG1_VBUS_CHRG (1 << 7) | ||
232 | #define ISP1301_OTG_STATUS 0x10 /* u8 readonly */ | ||
233 | # define OTG_B_SESS_END (1 << 6) | ||
234 | # define OTG_B_SESS_VLD (1 << 7) | ||
235 | |||
236 | #define ISP1301_INTERRUPT_SOURCE 0x08 /* u8 read */ | ||
237 | #define ISP1301_INTERRUPT_LATCH 0x0A /* u8 read, set, +1 clear */ | ||
238 | |||
239 | #define ISP1301_INTERRUPT_FALLING 0x0C /* u8 read, set, +1 clear */ | ||
240 | #define ISP1301_INTERRUPT_RISING 0x0E /* u8 read, set, +1 clear */ | ||
241 | |||
242 | /* same bitfields in all interrupt registers */ | ||
243 | # define INTR_VBUS_VLD (1 << 0) | ||
244 | # define INTR_SESS_VLD (1 << 1) | ||
245 | # define INTR_DP_HI (1 << 2) | ||
246 | # define INTR_ID_GND (1 << 3) | ||
247 | # define INTR_DM_HI (1 << 4) | ||
248 | # define INTR_ID_FLOAT (1 << 5) | ||
249 | # define INTR_BDIS_ACON (1 << 6) | ||
250 | # define INTR_CR_INT (1 << 7) | ||
251 | |||
252 | /*-------------------------------------------------------------------------*/ | ||
253 | |||
254 | static const char *state_string(enum usb_otg_state state) | ||
255 | { | ||
256 | switch (state) { | ||
257 | case OTG_STATE_A_IDLE: return "a_idle"; | ||
258 | case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise"; | ||
259 | case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon"; | ||
260 | case OTG_STATE_A_HOST: return "a_host"; | ||
261 | case OTG_STATE_A_SUSPEND: return "a_suspend"; | ||
262 | case OTG_STATE_A_PERIPHERAL: return "a_peripheral"; | ||
263 | case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall"; | ||
264 | case OTG_STATE_A_VBUS_ERR: return "a_vbus_err"; | ||
265 | case OTG_STATE_B_IDLE: return "b_idle"; | ||
266 | case OTG_STATE_B_SRP_INIT: return "b_srp_init"; | ||
267 | case OTG_STATE_B_PERIPHERAL: return "b_peripheral"; | ||
268 | case OTG_STATE_B_WAIT_ACON: return "b_wait_acon"; | ||
269 | case OTG_STATE_B_HOST: return "b_host"; | ||
270 | default: return "UNDEFINED"; | ||
271 | } | ||
272 | } | ||
273 | |||
274 | static inline const char *state_name(struct isp1301 *isp) | ||
275 | { | ||
276 | return state_string(isp->otg.state); | ||
277 | } | ||
278 | |||
279 | /*-------------------------------------------------------------------------*/ | ||
280 | |||
281 | /* NOTE: some of this ISP1301 setup is specific to H2 boards; | ||
282 | * not everything is guarded by board-specific checks, or even using | ||
283 | * omap_usb_config data to deduce MC1_DAT_SE0 and MC2_BI_DI. | ||
284 | * | ||
285 | * ALSO: this currently doesn't use ISP1301 low-power modes | ||
286 | * while OTG is running. | ||
287 | */ | ||
288 | |||
289 | static void power_down(struct isp1301 *isp) | ||
290 | { | ||
291 | isp->otg.state = OTG_STATE_UNDEFINED; | ||
292 | |||
293 | // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN); | ||
294 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND); | ||
295 | |||
296 | isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_ID_PULLDOWN); | ||
297 | isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); | ||
298 | } | ||
299 | |||
300 | static void power_up(struct isp1301 *isp) | ||
301 | { | ||
302 | // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN); | ||
303 | isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND); | ||
304 | |||
305 | /* do this only when cpu is driving transceiver, | ||
306 | * so host won't see a low speed device... | ||
307 | */ | ||
308 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); | ||
309 | } | ||
310 | |||
311 | #define NO_HOST_SUSPEND | ||
312 | |||
313 | static int host_suspend(struct isp1301 *isp) | ||
314 | { | ||
315 | #ifdef NO_HOST_SUSPEND | ||
316 | return 0; | ||
317 | #else | ||
318 | struct device *dev; | ||
319 | |||
320 | if (!isp->otg.host) | ||
321 | return -ENODEV; | ||
322 | |||
323 | /* Currently ASSUMES only the OTG port matters; | ||
324 | * other ports could be active... | ||
325 | */ | ||
326 | dev = isp->otg.host->controller; | ||
327 | return dev->driver->suspend(dev, 3, 0); | ||
328 | #endif | ||
329 | } | ||
330 | |||
331 | static int host_resume(struct isp1301 *isp) | ||
332 | { | ||
333 | #ifdef NO_HOST_SUSPEND | ||
334 | return 0; | ||
335 | #else | ||
336 | struct device *dev; | ||
337 | |||
338 | if (!isp->otg.host) | ||
339 | return -ENODEV; | ||
340 | |||
341 | dev = isp->otg.host->controller; | ||
342 | return dev->driver->resume(dev, 0); | ||
343 | #endif | ||
344 | } | ||
345 | |||
346 | static int gadget_suspend(struct isp1301 *isp) | ||
347 | { | ||
348 | isp->otg.gadget->b_hnp_enable = 0; | ||
349 | isp->otg.gadget->a_hnp_support = 0; | ||
350 | isp->otg.gadget->a_alt_hnp_support = 0; | ||
351 | return usb_gadget_vbus_disconnect(isp->otg.gadget); | ||
352 | } | ||
353 | |||
354 | /*-------------------------------------------------------------------------*/ | ||
355 | |||
356 | #define TIMER_MINUTES 10 | ||
357 | #define TIMER_JIFFIES (TIMER_MINUTES * 60 * HZ) | ||
358 | |||
359 | /* Almost all our I2C messaging comes from a work queue's task context. | ||
360 | * NOTE: guaranteeing certain response times might mean we shouldn't | ||
361 | * share keventd's work queue; a realtime task might be safest. | ||
362 | */ | ||
363 | static void isp1301_defer_work(struct isp1301 *isp, int work) | ||
364 | { | ||
365 | int status; | ||
366 | |||
367 | if (isp && !test_and_set_bit(work, &isp->todo)) { | ||
368 | (void) get_device(&isp->client->dev); | ||
369 | status = schedule_work(&isp->work); | ||
370 | if (!status && !isp->working) | ||
371 | dev_vdbg(&isp->client->dev, | ||
372 | "work item %d may be lost\n", work); | ||
373 | } | ||
374 | } | ||
375 | |||
376 | /* called from irq handlers */ | ||
377 | static void a_idle(struct isp1301 *isp, const char *tag) | ||
378 | { | ||
379 | u32 l; | ||
380 | |||
381 | if (isp->otg.state == OTG_STATE_A_IDLE) | ||
382 | return; | ||
383 | |||
384 | isp->otg.default_a = 1; | ||
385 | if (isp->otg.host) { | ||
386 | isp->otg.host->is_b_host = 0; | ||
387 | host_suspend(isp); | ||
388 | } | ||
389 | if (isp->otg.gadget) { | ||
390 | isp->otg.gadget->is_a_peripheral = 1; | ||
391 | gadget_suspend(isp); | ||
392 | } | ||
393 | isp->otg.state = OTG_STATE_A_IDLE; | ||
394 | l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS; | ||
395 | omap_writel(l, OTG_CTRL); | ||
396 | isp->last_otg_ctrl = l; | ||
397 | pr_debug(" --> %s/%s\n", state_name(isp), tag); | ||
398 | } | ||
399 | |||
400 | /* called from irq handlers */ | ||
401 | static void b_idle(struct isp1301 *isp, const char *tag) | ||
402 | { | ||
403 | u32 l; | ||
404 | |||
405 | if (isp->otg.state == OTG_STATE_B_IDLE) | ||
406 | return; | ||
407 | |||
408 | isp->otg.default_a = 0; | ||
409 | if (isp->otg.host) { | ||
410 | isp->otg.host->is_b_host = 1; | ||
411 | host_suspend(isp); | ||
412 | } | ||
413 | if (isp->otg.gadget) { | ||
414 | isp->otg.gadget->is_a_peripheral = 0; | ||
415 | gadget_suspend(isp); | ||
416 | } | ||
417 | isp->otg.state = OTG_STATE_B_IDLE; | ||
418 | l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS; | ||
419 | omap_writel(l, OTG_CTRL); | ||
420 | isp->last_otg_ctrl = l; | ||
421 | pr_debug(" --> %s/%s\n", state_name(isp), tag); | ||
422 | } | ||
423 | |||
424 | static void | ||
425 | dump_regs(struct isp1301 *isp, const char *label) | ||
426 | { | ||
427 | #ifdef DEBUG | ||
428 | u8 ctrl = isp1301_get_u8(isp, ISP1301_OTG_CONTROL_1); | ||
429 | u8 status = isp1301_get_u8(isp, ISP1301_OTG_STATUS); | ||
430 | u8 src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE); | ||
431 | |||
432 | pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n", | ||
433 | omap_readl(OTG_CTRL), label, state_name(isp), | ||
434 | ctrl, status, src); | ||
435 | /* mode control and irq enables don't change much */ | ||
436 | #endif | ||
437 | } | ||
438 | |||
439 | /*-------------------------------------------------------------------------*/ | ||
440 | |||
441 | #ifdef CONFIG_USB_OTG | ||
442 | |||
443 | /* | ||
444 | * The OMAP OTG controller handles most of the OTG state transitions. | ||
445 | * | ||
446 | * We translate isp1301 outputs (mostly voltage comparator status) into | ||
447 | * OTG inputs; OTG outputs (mostly pullup/pulldown controls) and HNP state | ||
448 | * flags into isp1301 inputs ... and infer state transitions. | ||
449 | */ | ||
450 | |||
451 | #ifdef VERBOSE | ||
452 | |||
453 | static void check_state(struct isp1301 *isp, const char *tag) | ||
454 | { | ||
455 | enum usb_otg_state state = OTG_STATE_UNDEFINED; | ||
456 | u8 fsm = omap_readw(OTG_TEST) & 0x0ff; | ||
457 | unsigned extra = 0; | ||
458 | |||
459 | switch (fsm) { | ||
460 | |||
461 | /* default-b */ | ||
462 | case 0x0: | ||
463 | state = OTG_STATE_B_IDLE; | ||
464 | break; | ||
465 | case 0x3: | ||
466 | case 0x7: | ||
467 | extra = 1; | ||
468 | case 0x1: | ||
469 | state = OTG_STATE_B_PERIPHERAL; | ||
470 | break; | ||
471 | case 0x11: | ||
472 | state = OTG_STATE_B_SRP_INIT; | ||
473 | break; | ||
474 | |||
475 | /* extra dual-role default-b states */ | ||
476 | case 0x12: | ||
477 | case 0x13: | ||
478 | case 0x16: | ||
479 | extra = 1; | ||
480 | case 0x17: | ||
481 | state = OTG_STATE_B_WAIT_ACON; | ||
482 | break; | ||
483 | case 0x34: | ||
484 | state = OTG_STATE_B_HOST; | ||
485 | break; | ||
486 | |||
487 | /* default-a */ | ||
488 | case 0x36: | ||
489 | state = OTG_STATE_A_IDLE; | ||
490 | break; | ||
491 | case 0x3c: | ||
492 | state = OTG_STATE_A_WAIT_VFALL; | ||
493 | break; | ||
494 | case 0x7d: | ||
495 | state = OTG_STATE_A_VBUS_ERR; | ||
496 | break; | ||
497 | case 0x9e: | ||
498 | case 0x9f: | ||
499 | extra = 1; | ||
500 | case 0x89: | ||
501 | state = OTG_STATE_A_PERIPHERAL; | ||
502 | break; | ||
503 | case 0xb7: | ||
504 | state = OTG_STATE_A_WAIT_VRISE; | ||
505 | break; | ||
506 | case 0xb8: | ||
507 | state = OTG_STATE_A_WAIT_BCON; | ||
508 | break; | ||
509 | case 0xb9: | ||
510 | state = OTG_STATE_A_HOST; | ||
511 | break; | ||
512 | case 0xba: | ||
513 | state = OTG_STATE_A_SUSPEND; | ||
514 | break; | ||
515 | default: | ||
516 | break; | ||
517 | } | ||
518 | if (isp->otg.state == state && !extra) | ||
519 | return; | ||
520 | pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag, | ||
521 | state_string(state), fsm, state_name(isp), | ||
522 | omap_readl(OTG_CTRL)); | ||
523 | } | ||
524 | |||
525 | #else | ||
526 | |||
527 | static inline void check_state(struct isp1301 *isp, const char *tag) { } | ||
528 | |||
529 | #endif | ||
530 | |||
531 | /* outputs from ISP1301_INTERRUPT_SOURCE */ | ||
532 | static void update_otg1(struct isp1301 *isp, u8 int_src) | ||
533 | { | ||
534 | u32 otg_ctrl; | ||
535 | |||
536 | otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK; | ||
537 | otg_ctrl &= ~OTG_XCEIV_INPUTS; | ||
538 | otg_ctrl &= ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD); | ||
539 | |||
540 | if (int_src & INTR_SESS_VLD) | ||
541 | otg_ctrl |= OTG_ASESSVLD; | ||
542 | else if (isp->otg.state == OTG_STATE_A_WAIT_VFALL) { | ||
543 | a_idle(isp, "vfall"); | ||
544 | otg_ctrl &= ~OTG_CTRL_BITS; | ||
545 | } | ||
546 | if (int_src & INTR_VBUS_VLD) | ||
547 | otg_ctrl |= OTG_VBUSVLD; | ||
548 | if (int_src & INTR_ID_GND) { /* default-A */ | ||
549 | if (isp->otg.state == OTG_STATE_B_IDLE | ||
550 | || isp->otg.state == OTG_STATE_UNDEFINED) { | ||
551 | a_idle(isp, "init"); | ||
552 | return; | ||
553 | } | ||
554 | } else { /* default-B */ | ||
555 | otg_ctrl |= OTG_ID; | ||
556 | if (isp->otg.state == OTG_STATE_A_IDLE | ||
557 | || isp->otg.state == OTG_STATE_UNDEFINED) { | ||
558 | b_idle(isp, "init"); | ||
559 | return; | ||
560 | } | ||
561 | } | ||
562 | omap_writel(otg_ctrl, OTG_CTRL); | ||
563 | } | ||
564 | |||
565 | /* outputs from ISP1301_OTG_STATUS */ | ||
566 | static void update_otg2(struct isp1301 *isp, u8 otg_status) | ||
567 | { | ||
568 | u32 otg_ctrl; | ||
569 | |||
570 | otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK; | ||
571 | otg_ctrl &= ~OTG_XCEIV_INPUTS; | ||
572 | otg_ctrl &= ~(OTG_BSESSVLD | OTG_BSESSEND); | ||
573 | if (otg_status & OTG_B_SESS_VLD) | ||
574 | otg_ctrl |= OTG_BSESSVLD; | ||
575 | else if (otg_status & OTG_B_SESS_END) | ||
576 | otg_ctrl |= OTG_BSESSEND; | ||
577 | omap_writel(otg_ctrl, OTG_CTRL); | ||
578 | } | ||
579 | |||
580 | /* inputs going to ISP1301 */ | ||
581 | static void otg_update_isp(struct isp1301 *isp) | ||
582 | { | ||
583 | u32 otg_ctrl, otg_change; | ||
584 | u8 set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP; | ||
585 | |||
586 | otg_ctrl = omap_readl(OTG_CTRL); | ||
587 | otg_change = otg_ctrl ^ isp->last_otg_ctrl; | ||
588 | isp->last_otg_ctrl = otg_ctrl; | ||
589 | otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS; | ||
590 | |||
591 | switch (isp->otg.state) { | ||
592 | case OTG_STATE_B_IDLE: | ||
593 | case OTG_STATE_B_PERIPHERAL: | ||
594 | case OTG_STATE_B_SRP_INIT: | ||
595 | if (!(otg_ctrl & OTG_PULLUP)) { | ||
596 | // if (otg_ctrl & OTG_B_HNPEN) { | ||
597 | if (isp->otg.gadget->b_hnp_enable) { | ||
598 | isp->otg.state = OTG_STATE_B_WAIT_ACON; | ||
599 | pr_debug(" --> b_wait_acon\n"); | ||
600 | } | ||
601 | goto pulldown; | ||
602 | } | ||
603 | pullup: | ||
604 | set |= OTG1_DP_PULLUP; | ||
605 | clr |= OTG1_DP_PULLDOWN; | ||
606 | break; | ||
607 | case OTG_STATE_A_SUSPEND: | ||
608 | case OTG_STATE_A_PERIPHERAL: | ||
609 | if (otg_ctrl & OTG_PULLUP) | ||
610 | goto pullup; | ||
611 | /* FALLTHROUGH */ | ||
612 | // case OTG_STATE_B_WAIT_ACON: | ||
613 | default: | ||
614 | pulldown: | ||
615 | set |= OTG1_DP_PULLDOWN; | ||
616 | clr |= OTG1_DP_PULLUP; | ||
617 | break; | ||
618 | } | ||
619 | |||
620 | # define toggle(OTG,ISP) do { \ | ||
621 | if (otg_ctrl & OTG) set |= ISP; \ | ||
622 | else clr |= ISP; \ | ||
623 | } while (0) | ||
624 | |||
625 | if (!(isp->otg.host)) | ||
626 | otg_ctrl &= ~OTG_DRV_VBUS; | ||
627 | |||
628 | switch (isp->otg.state) { | ||
629 | case OTG_STATE_A_SUSPEND: | ||
630 | if (otg_ctrl & OTG_DRV_VBUS) { | ||
631 | set |= OTG1_VBUS_DRV; | ||
632 | break; | ||
633 | } | ||
634 | /* HNP failed for some reason (A_AIDL_BDIS timeout) */ | ||
635 | notresponding(isp); | ||
636 | |||
637 | /* FALLTHROUGH */ | ||
638 | case OTG_STATE_A_VBUS_ERR: | ||
639 | isp->otg.state = OTG_STATE_A_WAIT_VFALL; | ||
640 | pr_debug(" --> a_wait_vfall\n"); | ||
641 | /* FALLTHROUGH */ | ||
642 | case OTG_STATE_A_WAIT_VFALL: | ||
643 | /* FIXME usbcore thinks port power is still on ... */ | ||
644 | clr |= OTG1_VBUS_DRV; | ||
645 | break; | ||
646 | case OTG_STATE_A_IDLE: | ||
647 | if (otg_ctrl & OTG_DRV_VBUS) { | ||
648 | isp->otg.state = OTG_STATE_A_WAIT_VRISE; | ||
649 | pr_debug(" --> a_wait_vrise\n"); | ||
650 | } | ||
651 | /* FALLTHROUGH */ | ||
652 | default: | ||
653 | toggle(OTG_DRV_VBUS, OTG1_VBUS_DRV); | ||
654 | } | ||
655 | |||
656 | toggle(OTG_PU_VBUS, OTG1_VBUS_CHRG); | ||
657 | toggle(OTG_PD_VBUS, OTG1_VBUS_DISCHRG); | ||
658 | |||
659 | # undef toggle | ||
660 | |||
661 | isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, set); | ||
662 | isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, clr); | ||
663 | |||
664 | /* HNP switch to host or peripheral; and SRP */ | ||
665 | if (otg_change & OTG_PULLUP) { | ||
666 | u32 l; | ||
667 | |||
668 | switch (isp->otg.state) { | ||
669 | case OTG_STATE_B_IDLE: | ||
670 | if (clr & OTG1_DP_PULLUP) | ||
671 | break; | ||
672 | isp->otg.state = OTG_STATE_B_PERIPHERAL; | ||
673 | pr_debug(" --> b_peripheral\n"); | ||
674 | break; | ||
675 | case OTG_STATE_A_SUSPEND: | ||
676 | if (clr & OTG1_DP_PULLUP) | ||
677 | break; | ||
678 | isp->otg.state = OTG_STATE_A_PERIPHERAL; | ||
679 | pr_debug(" --> a_peripheral\n"); | ||
680 | break; | ||
681 | default: | ||
682 | break; | ||
683 | } | ||
684 | l = omap_readl(OTG_CTRL); | ||
685 | l |= OTG_PULLUP; | ||
686 | omap_writel(l, OTG_CTRL); | ||
687 | } | ||
688 | |||
689 | check_state(isp, __func__); | ||
690 | dump_regs(isp, "otg->isp1301"); | ||
691 | } | ||
692 | |||
693 | static irqreturn_t omap_otg_irq(int irq, void *_isp) | ||
694 | { | ||
695 | u16 otg_irq = omap_readw(OTG_IRQ_SRC); | ||
696 | u32 otg_ctrl; | ||
697 | int ret = IRQ_NONE; | ||
698 | struct isp1301 *isp = _isp; | ||
699 | |||
700 | /* update ISP1301 transciever from OTG controller */ | ||
701 | if (otg_irq & OPRT_CHG) { | ||
702 | omap_writew(OPRT_CHG, OTG_IRQ_SRC); | ||
703 | isp1301_defer_work(isp, WORK_UPDATE_ISP); | ||
704 | ret = IRQ_HANDLED; | ||
705 | |||
706 | /* SRP to become b_peripheral failed */ | ||
707 | } else if (otg_irq & B_SRP_TMROUT) { | ||
708 | pr_debug("otg: B_SRP_TIMEOUT, %06x\n", omap_readl(OTG_CTRL)); | ||
709 | notresponding(isp); | ||
710 | |||
711 | /* gadget drivers that care should monitor all kinds of | ||
712 | * remote wakeup (SRP, normal) using their own timer | ||
713 | * to give "check cable and A-device" messages. | ||
714 | */ | ||
715 | if (isp->otg.state == OTG_STATE_B_SRP_INIT) | ||
716 | b_idle(isp, "srp_timeout"); | ||
717 | |||
718 | omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC); | ||
719 | ret = IRQ_HANDLED; | ||
720 | |||
721 | /* HNP to become b_host failed */ | ||
722 | } else if (otg_irq & B_HNP_FAIL) { | ||
723 | pr_debug("otg: %s B_HNP_FAIL, %06x\n", | ||
724 | state_name(isp), omap_readl(OTG_CTRL)); | ||
725 | notresponding(isp); | ||
726 | |||
727 | otg_ctrl = omap_readl(OTG_CTRL); | ||
728 | otg_ctrl |= OTG_BUSDROP; | ||
729 | otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; | ||
730 | omap_writel(otg_ctrl, OTG_CTRL); | ||
731 | |||
732 | /* subset of b_peripheral()... */ | ||
733 | isp->otg.state = OTG_STATE_B_PERIPHERAL; | ||
734 | pr_debug(" --> b_peripheral\n"); | ||
735 | |||
736 | omap_writew(B_HNP_FAIL, OTG_IRQ_SRC); | ||
737 | ret = IRQ_HANDLED; | ||
738 | |||
739 | /* detect SRP from B-device ... */ | ||
740 | } else if (otg_irq & A_SRP_DETECT) { | ||
741 | pr_debug("otg: %s SRP_DETECT, %06x\n", | ||
742 | state_name(isp), omap_readl(OTG_CTRL)); | ||
743 | |||
744 | isp1301_defer_work(isp, WORK_UPDATE_OTG); | ||
745 | switch (isp->otg.state) { | ||
746 | case OTG_STATE_A_IDLE: | ||
747 | if (!isp->otg.host) | ||
748 | break; | ||
749 | isp1301_defer_work(isp, WORK_HOST_RESUME); | ||
750 | otg_ctrl = omap_readl(OTG_CTRL); | ||
751 | otg_ctrl |= OTG_A_BUSREQ; | ||
752 | otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ) | ||
753 | & ~OTG_XCEIV_INPUTS | ||
754 | & OTG_CTRL_MASK; | ||
755 | omap_writel(otg_ctrl, OTG_CTRL); | ||
756 | break; | ||
757 | default: | ||
758 | break; | ||
759 | } | ||
760 | |||
761 | omap_writew(A_SRP_DETECT, OTG_IRQ_SRC); | ||
762 | ret = IRQ_HANDLED; | ||
763 | |||
764 | /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise) | ||
765 | * we don't track them separately | ||
766 | */ | ||
767 | } else if (otg_irq & A_REQ_TMROUT) { | ||
768 | otg_ctrl = omap_readl(OTG_CTRL); | ||
769 | pr_info("otg: BCON_TMOUT from %s, %06x\n", | ||
770 | state_name(isp), otg_ctrl); | ||
771 | notresponding(isp); | ||
772 | |||
773 | otg_ctrl |= OTG_BUSDROP; | ||
774 | otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; | ||
775 | omap_writel(otg_ctrl, OTG_CTRL); | ||
776 | isp->otg.state = OTG_STATE_A_WAIT_VFALL; | ||
777 | |||
778 | omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC); | ||
779 | ret = IRQ_HANDLED; | ||
780 | |||
781 | /* A-supplied voltage fell too low; overcurrent */ | ||
782 | } else if (otg_irq & A_VBUS_ERR) { | ||
783 | otg_ctrl = omap_readl(OTG_CTRL); | ||
784 | printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n", | ||
785 | state_name(isp), otg_irq, otg_ctrl); | ||
786 | |||
787 | otg_ctrl |= OTG_BUSDROP; | ||
788 | otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; | ||
789 | omap_writel(otg_ctrl, OTG_CTRL); | ||
790 | isp->otg.state = OTG_STATE_A_VBUS_ERR; | ||
791 | |||
792 | omap_writew(A_VBUS_ERR, OTG_IRQ_SRC); | ||
793 | ret = IRQ_HANDLED; | ||
794 | |||
795 | /* switch driver; the transciever code activates it, | ||
796 | * ungating the udc clock or resuming OHCI. | ||
797 | */ | ||
798 | } else if (otg_irq & DRIVER_SWITCH) { | ||
799 | int kick = 0; | ||
800 | |||
801 | otg_ctrl = omap_readl(OTG_CTRL); | ||
802 | printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n", | ||
803 | state_name(isp), | ||
804 | (otg_ctrl & OTG_DRIVER_SEL) | ||
805 | ? "gadget" : "host", | ||
806 | otg_ctrl); | ||
807 | isp1301_defer_work(isp, WORK_UPDATE_ISP); | ||
808 | |||
809 | /* role is peripheral */ | ||
810 | if (otg_ctrl & OTG_DRIVER_SEL) { | ||
811 | switch (isp->otg.state) { | ||
812 | case OTG_STATE_A_IDLE: | ||
813 | b_idle(isp, __func__); | ||
814 | break; | ||
815 | default: | ||
816 | break; | ||
817 | } | ||
818 | isp1301_defer_work(isp, WORK_UPDATE_ISP); | ||
819 | |||
820 | /* role is host */ | ||
821 | } else { | ||
822 | if (!(otg_ctrl & OTG_ID)) { | ||
823 | otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; | ||
824 | omap_writel(otg_ctrl | OTG_A_BUSREQ, OTG_CTRL); | ||
825 | } | ||
826 | |||
827 | if (isp->otg.host) { | ||
828 | switch (isp->otg.state) { | ||
829 | case OTG_STATE_B_WAIT_ACON: | ||
830 | isp->otg.state = OTG_STATE_B_HOST; | ||
831 | pr_debug(" --> b_host\n"); | ||
832 | kick = 1; | ||
833 | break; | ||
834 | case OTG_STATE_A_WAIT_BCON: | ||
835 | isp->otg.state = OTG_STATE_A_HOST; | ||
836 | pr_debug(" --> a_host\n"); | ||
837 | break; | ||
838 | case OTG_STATE_A_PERIPHERAL: | ||
839 | isp->otg.state = OTG_STATE_A_WAIT_BCON; | ||
840 | pr_debug(" --> a_wait_bcon\n"); | ||
841 | break; | ||
842 | default: | ||
843 | break; | ||
844 | } | ||
845 | isp1301_defer_work(isp, WORK_HOST_RESUME); | ||
846 | } | ||
847 | } | ||
848 | |||
849 | omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC); | ||
850 | ret = IRQ_HANDLED; | ||
851 | |||
852 | if (kick) | ||
853 | usb_bus_start_enum(isp->otg.host, | ||
854 | isp->otg.host->otg_port); | ||
855 | } | ||
856 | |||
857 | check_state(isp, __func__); | ||
858 | return ret; | ||
859 | } | ||
860 | |||
861 | static struct platform_device *otg_dev; | ||
862 | |||
863 | static int otg_init(struct isp1301 *isp) | ||
864 | { | ||
865 | u32 l; | ||
866 | |||
867 | if (!otg_dev) | ||
868 | return -ENODEV; | ||
869 | |||
870 | dump_regs(isp, __func__); | ||
871 | /* some of these values are board-specific... */ | ||
872 | l = omap_readl(OTG_SYSCON_2); | ||
873 | l |= OTG_EN | ||
874 | /* for B-device: */ | ||
875 | | SRP_GPDATA /* 9msec Bdev D+ pulse */ | ||
876 | | SRP_GPDVBUS /* discharge after VBUS pulse */ | ||
877 | // | (3 << 24) /* 2msec VBUS pulse */ | ||
878 | /* for A-device: */ | ||
879 | | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */ | ||
880 | | SRP_DPW /* detect 167+ns SRP pulses */ | ||
881 | | SRP_DATA | SRP_VBUS /* accept both kinds of SRP pulse */ | ||
882 | ; | ||
883 | omap_writel(l, OTG_SYSCON_2); | ||
884 | |||
885 | update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE)); | ||
886 | update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS)); | ||
887 | |||
888 | check_state(isp, __func__); | ||
889 | pr_debug("otg: %s, %s %06x\n", | ||
890 | state_name(isp), __func__, omap_readl(OTG_CTRL)); | ||
891 | |||
892 | omap_writew(DRIVER_SWITCH | OPRT_CHG | ||
893 | | B_SRP_TMROUT | B_HNP_FAIL | ||
894 | | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT, OTG_IRQ_EN); | ||
895 | |||
896 | l = omap_readl(OTG_SYSCON_2); | ||
897 | l |= OTG_EN; | ||
898 | omap_writel(l, OTG_SYSCON_2); | ||
899 | |||
900 | return 0; | ||
901 | } | ||
902 | |||
903 | static int otg_probe(struct platform_device *dev) | ||
904 | { | ||
905 | // struct omap_usb_config *config = dev->platform_data; | ||
906 | |||
907 | otg_dev = dev; | ||
908 | return 0; | ||
909 | } | ||
910 | |||
911 | static int otg_remove(struct platform_device *dev) | ||
912 | { | ||
913 | otg_dev = NULL; | ||
914 | return 0; | ||
915 | } | ||
916 | |||
917 | static struct platform_driver omap_otg_driver = { | ||
918 | .probe = otg_probe, | ||
919 | .remove = otg_remove, | ||
920 | .driver = { | ||
921 | .owner = THIS_MODULE, | ||
922 | .name = "omap_otg", | ||
923 | }, | ||
924 | }; | ||
925 | |||
926 | static int otg_bind(struct isp1301 *isp) | ||
927 | { | ||
928 | int status; | ||
929 | |||
930 | if (otg_dev) | ||
931 | return -EBUSY; | ||
932 | |||
933 | status = platform_driver_register(&omap_otg_driver); | ||
934 | if (status < 0) | ||
935 | return status; | ||
936 | |||
937 | if (otg_dev) | ||
938 | status = request_irq(otg_dev->resource[1].start, omap_otg_irq, | ||
939 | IRQF_DISABLED, DRIVER_NAME, isp); | ||
940 | else | ||
941 | status = -ENODEV; | ||
942 | |||
943 | if (status < 0) | ||
944 | platform_driver_unregister(&omap_otg_driver); | ||
945 | return status; | ||
946 | } | ||
947 | |||
948 | static void otg_unbind(struct isp1301 *isp) | ||
949 | { | ||
950 | if (!otg_dev) | ||
951 | return; | ||
952 | free_irq(otg_dev->resource[1].start, isp); | ||
953 | } | ||
954 | |||
955 | #else | ||
956 | |||
957 | /* OTG controller isn't clocked */ | ||
958 | |||
959 | #endif /* CONFIG_USB_OTG */ | ||
960 | |||
961 | /*-------------------------------------------------------------------------*/ | ||
962 | |||
963 | static void b_peripheral(struct isp1301 *isp) | ||
964 | { | ||
965 | u32 l; | ||
966 | |||
967 | l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS; | ||
968 | omap_writel(l, OTG_CTRL); | ||
969 | |||
970 | usb_gadget_vbus_connect(isp->otg.gadget); | ||
971 | |||
972 | #ifdef CONFIG_USB_OTG | ||
973 | enable_vbus_draw(isp, 8); | ||
974 | otg_update_isp(isp); | ||
975 | #else | ||
976 | enable_vbus_draw(isp, 100); | ||
977 | /* UDC driver just set OTG_BSESSVLD */ | ||
978 | isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP); | ||
979 | isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN); | ||
980 | isp->otg.state = OTG_STATE_B_PERIPHERAL; | ||
981 | pr_debug(" --> b_peripheral\n"); | ||
982 | dump_regs(isp, "2periph"); | ||
983 | #endif | ||
984 | } | ||
985 | |||
986 | static void isp_update_otg(struct isp1301 *isp, u8 stat) | ||
987 | { | ||
988 | u8 isp_stat, isp_bstat; | ||
989 | enum usb_otg_state state = isp->otg.state; | ||
990 | |||
991 | if (stat & INTR_BDIS_ACON) | ||
992 | pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp)); | ||
993 | |||
994 | /* start certain state transitions right away */ | ||
995 | isp_stat = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE); | ||
996 | if (isp_stat & INTR_ID_GND) { | ||
997 | if (isp->otg.default_a) { | ||
998 | switch (state) { | ||
999 | case OTG_STATE_B_IDLE: | ||
1000 | a_idle(isp, "idle"); | ||
1001 | /* FALLTHROUGH */ | ||
1002 | case OTG_STATE_A_IDLE: | ||
1003 | enable_vbus_source(isp); | ||
1004 | /* FALLTHROUGH */ | ||
1005 | case OTG_STATE_A_WAIT_VRISE: | ||
1006 | /* we skip over OTG_STATE_A_WAIT_BCON, since | ||
1007 | * the HC will transition to A_HOST (or | ||
1008 | * A_SUSPEND!) without our noticing except | ||
1009 | * when HNP is used. | ||
1010 | */ | ||
1011 | if (isp_stat & INTR_VBUS_VLD) | ||
1012 | isp->otg.state = OTG_STATE_A_HOST; | ||
1013 | break; | ||
1014 | case OTG_STATE_A_WAIT_VFALL: | ||
1015 | if (!(isp_stat & INTR_SESS_VLD)) | ||
1016 | a_idle(isp, "vfell"); | ||
1017 | break; | ||
1018 | default: | ||
1019 | if (!(isp_stat & INTR_VBUS_VLD)) | ||
1020 | isp->otg.state = OTG_STATE_A_VBUS_ERR; | ||
1021 | break; | ||
1022 | } | ||
1023 | isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS); | ||
1024 | } else { | ||
1025 | switch (state) { | ||
1026 | case OTG_STATE_B_PERIPHERAL: | ||
1027 | case OTG_STATE_B_HOST: | ||
1028 | case OTG_STATE_B_WAIT_ACON: | ||
1029 | usb_gadget_vbus_disconnect(isp->otg.gadget); | ||
1030 | break; | ||
1031 | default: | ||
1032 | break; | ||
1033 | } | ||
1034 | if (state != OTG_STATE_A_IDLE) | ||
1035 | a_idle(isp, "id"); | ||
1036 | if (isp->otg.host && state == OTG_STATE_A_IDLE) | ||
1037 | isp1301_defer_work(isp, WORK_HOST_RESUME); | ||
1038 | isp_bstat = 0; | ||
1039 | } | ||
1040 | } else { | ||
1041 | u32 l; | ||
1042 | |||
1043 | /* if user unplugged mini-A end of cable, | ||
1044 | * don't bypass A_WAIT_VFALL. | ||
1045 | */ | ||
1046 | if (isp->otg.default_a) { | ||
1047 | switch (state) { | ||
1048 | default: | ||
1049 | isp->otg.state = OTG_STATE_A_WAIT_VFALL; | ||
1050 | break; | ||
1051 | case OTG_STATE_A_WAIT_VFALL: | ||
1052 | state = OTG_STATE_A_IDLE; | ||
1053 | /* khubd may take a while to notice and | ||
1054 | * handle this disconnect, so don't go | ||
1055 | * to B_IDLE quite yet. | ||
1056 | */ | ||
1057 | break; | ||
1058 | case OTG_STATE_A_IDLE: | ||
1059 | host_suspend(isp); | ||
1060 | isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, | ||
1061 | MC1_BDIS_ACON_EN); | ||
1062 | isp->otg.state = OTG_STATE_B_IDLE; | ||
1063 | l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK; | ||
1064 | l &= ~OTG_CTRL_BITS; | ||
1065 | omap_writel(l, OTG_CTRL); | ||
1066 | break; | ||
1067 | case OTG_STATE_B_IDLE: | ||
1068 | break; | ||
1069 | } | ||
1070 | } | ||
1071 | isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS); | ||
1072 | |||
1073 | switch (isp->otg.state) { | ||
1074 | case OTG_STATE_B_PERIPHERAL: | ||
1075 | case OTG_STATE_B_WAIT_ACON: | ||
1076 | case OTG_STATE_B_HOST: | ||
1077 | if (likely(isp_bstat & OTG_B_SESS_VLD)) | ||
1078 | break; | ||
1079 | enable_vbus_draw(isp, 0); | ||
1080 | #ifndef CONFIG_USB_OTG | ||
1081 | /* UDC driver will clear OTG_BSESSVLD */ | ||
1082 | isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, | ||
1083 | OTG1_DP_PULLDOWN); | ||
1084 | isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, | ||
1085 | OTG1_DP_PULLUP); | ||
1086 | dump_regs(isp, __func__); | ||
1087 | #endif | ||
1088 | /* FALLTHROUGH */ | ||
1089 | case OTG_STATE_B_SRP_INIT: | ||
1090 | b_idle(isp, __func__); | ||
1091 | l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS; | ||
1092 | omap_writel(l, OTG_CTRL); | ||
1093 | /* FALLTHROUGH */ | ||
1094 | case OTG_STATE_B_IDLE: | ||
1095 | if (isp->otg.gadget && (isp_bstat & OTG_B_SESS_VLD)) { | ||
1096 | #ifdef CONFIG_USB_OTG | ||
1097 | update_otg1(isp, isp_stat); | ||
1098 | update_otg2(isp, isp_bstat); | ||
1099 | #endif | ||
1100 | b_peripheral(isp); | ||
1101 | } else if (!(isp_stat & (INTR_VBUS_VLD|INTR_SESS_VLD))) | ||
1102 | isp_bstat |= OTG_B_SESS_END; | ||
1103 | break; | ||
1104 | case OTG_STATE_A_WAIT_VFALL: | ||
1105 | break; | ||
1106 | default: | ||
1107 | pr_debug("otg: unsupported b-device %s\n", | ||
1108 | state_name(isp)); | ||
1109 | break; | ||
1110 | } | ||
1111 | } | ||
1112 | |||
1113 | if (state != isp->otg.state) | ||
1114 | pr_debug(" isp, %s -> %s\n", | ||
1115 | state_string(state), state_name(isp)); | ||
1116 | |||
1117 | #ifdef CONFIG_USB_OTG | ||
1118 | /* update the OTG controller state to match the isp1301; may | ||
1119 | * trigger OPRT_CHG irqs for changes going to the isp1301. | ||
1120 | */ | ||
1121 | update_otg1(isp, isp_stat); | ||
1122 | update_otg2(isp, isp_bstat); | ||
1123 | check_state(isp, __func__); | ||
1124 | #endif | ||
1125 | |||
1126 | dump_regs(isp, "isp1301->otg"); | ||
1127 | } | ||
1128 | |||
1129 | /*-------------------------------------------------------------------------*/ | ||
1130 | |||
1131 | static u8 isp1301_clear_latch(struct isp1301 *isp) | ||
1132 | { | ||
1133 | u8 latch = isp1301_get_u8(isp, ISP1301_INTERRUPT_LATCH); | ||
1134 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, latch); | ||
1135 | return latch; | ||
1136 | } | ||
1137 | |||
1138 | static void | ||
1139 | isp1301_work(struct work_struct *work) | ||
1140 | { | ||
1141 | struct isp1301 *isp = container_of(work, struct isp1301, work); | ||
1142 | int stop; | ||
1143 | |||
1144 | /* implicit lock: we're the only task using this device */ | ||
1145 | isp->working = 1; | ||
1146 | do { | ||
1147 | stop = test_bit(WORK_STOP, &isp->todo); | ||
1148 | |||
1149 | #ifdef CONFIG_USB_OTG | ||
1150 | /* transfer state from otg engine to isp1301 */ | ||
1151 | if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) { | ||
1152 | otg_update_isp(isp); | ||
1153 | put_device(&isp->client->dev); | ||
1154 | } | ||
1155 | #endif | ||
1156 | /* transfer state from isp1301 to otg engine */ | ||
1157 | if (test_and_clear_bit(WORK_UPDATE_OTG, &isp->todo)) { | ||
1158 | u8 stat = isp1301_clear_latch(isp); | ||
1159 | |||
1160 | isp_update_otg(isp, stat); | ||
1161 | put_device(&isp->client->dev); | ||
1162 | } | ||
1163 | |||
1164 | if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) { | ||
1165 | u32 otg_ctrl; | ||
1166 | |||
1167 | /* | ||
1168 | * skip A_WAIT_VRISE; hc transitions invisibly | ||
1169 | * skip A_WAIT_BCON; same. | ||
1170 | */ | ||
1171 | switch (isp->otg.state) { | ||
1172 | case OTG_STATE_A_WAIT_BCON: | ||
1173 | case OTG_STATE_A_WAIT_VRISE: | ||
1174 | isp->otg.state = OTG_STATE_A_HOST; | ||
1175 | pr_debug(" --> a_host\n"); | ||
1176 | otg_ctrl = omap_readl(OTG_CTRL); | ||
1177 | otg_ctrl |= OTG_A_BUSREQ; | ||
1178 | otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ) | ||
1179 | & OTG_CTRL_MASK; | ||
1180 | omap_writel(otg_ctrl, OTG_CTRL); | ||
1181 | break; | ||
1182 | case OTG_STATE_B_WAIT_ACON: | ||
1183 | isp->otg.state = OTG_STATE_B_HOST; | ||
1184 | pr_debug(" --> b_host (acon)\n"); | ||
1185 | break; | ||
1186 | case OTG_STATE_B_HOST: | ||
1187 | case OTG_STATE_B_IDLE: | ||
1188 | case OTG_STATE_A_IDLE: | ||
1189 | break; | ||
1190 | default: | ||
1191 | pr_debug(" host resume in %s\n", | ||
1192 | state_name(isp)); | ||
1193 | } | ||
1194 | host_resume(isp); | ||
1195 | // mdelay(10); | ||
1196 | put_device(&isp->client->dev); | ||
1197 | } | ||
1198 | |||
1199 | if (test_and_clear_bit(WORK_TIMER, &isp->todo)) { | ||
1200 | #ifdef VERBOSE | ||
1201 | dump_regs(isp, "timer"); | ||
1202 | if (!stop) | ||
1203 | mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); | ||
1204 | #endif | ||
1205 | put_device(&isp->client->dev); | ||
1206 | } | ||
1207 | |||
1208 | if (isp->todo) | ||
1209 | dev_vdbg(&isp->client->dev, | ||
1210 | "work done, todo = 0x%lx\n", | ||
1211 | isp->todo); | ||
1212 | if (stop) { | ||
1213 | dev_dbg(&isp->client->dev, "stop\n"); | ||
1214 | break; | ||
1215 | } | ||
1216 | } while (isp->todo); | ||
1217 | isp->working = 0; | ||
1218 | } | ||
1219 | |||
1220 | static irqreturn_t isp1301_irq(int irq, void *isp) | ||
1221 | { | ||
1222 | isp1301_defer_work(isp, WORK_UPDATE_OTG); | ||
1223 | return IRQ_HANDLED; | ||
1224 | } | ||
1225 | |||
1226 | static void isp1301_timer(unsigned long _isp) | ||
1227 | { | ||
1228 | isp1301_defer_work((void *)_isp, WORK_TIMER); | ||
1229 | } | ||
1230 | |||
1231 | /*-------------------------------------------------------------------------*/ | ||
1232 | |||
1233 | static void isp1301_release(struct device *dev) | ||
1234 | { | ||
1235 | struct isp1301 *isp; | ||
1236 | |||
1237 | isp = dev_get_drvdata(dev); | ||
1238 | |||
1239 | /* FIXME -- not with a "new style" driver, it doesn't!! */ | ||
1240 | |||
1241 | /* ugly -- i2c hijacks our memory hook to wait_for_completion() */ | ||
1242 | if (isp->i2c_release) | ||
1243 | isp->i2c_release(dev); | ||
1244 | kfree (isp); | ||
1245 | } | ||
1246 | |||
1247 | static struct isp1301 *the_transceiver; | ||
1248 | |||
1249 | static int __exit isp1301_remove(struct i2c_client *i2c) | ||
1250 | { | ||
1251 | struct isp1301 *isp; | ||
1252 | |||
1253 | isp = i2c_get_clientdata(i2c); | ||
1254 | |||
1255 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0); | ||
1256 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0); | ||
1257 | free_irq(i2c->irq, isp); | ||
1258 | #ifdef CONFIG_USB_OTG | ||
1259 | otg_unbind(isp); | ||
1260 | #endif | ||
1261 | if (machine_is_omap_h2()) | ||
1262 | gpio_free(2); | ||
1263 | |||
1264 | isp->timer.data = 0; | ||
1265 | set_bit(WORK_STOP, &isp->todo); | ||
1266 | del_timer_sync(&isp->timer); | ||
1267 | flush_scheduled_work(); | ||
1268 | |||
1269 | put_device(&i2c->dev); | ||
1270 | the_transceiver = NULL; | ||
1271 | |||
1272 | return 0; | ||
1273 | } | ||
1274 | |||
1275 | /*-------------------------------------------------------------------------*/ | ||
1276 | |||
1277 | /* NOTE: three modes are possible here, only one of which | ||
1278 | * will be standards-conformant on any given system: | ||
1279 | * | ||
1280 | * - OTG mode (dual-role), required if there's a Mini-AB connector | ||
1281 | * - HOST mode, for when there's one or more A (host) connectors | ||
1282 | * - DEVICE mode, for when there's a B/Mini-B (device) connector | ||
1283 | * | ||
1284 | * As a rule, you won't have an isp1301 chip unless it's there to | ||
1285 | * support the OTG mode. Other modes help testing USB controllers | ||
1286 | * in isolation from (full) OTG support, or maybe so later board | ||
1287 | * revisions can help to support those feature. | ||
1288 | */ | ||
1289 | |||
1290 | #ifdef CONFIG_USB_OTG | ||
1291 | |||
1292 | static int isp1301_otg_enable(struct isp1301 *isp) | ||
1293 | { | ||
1294 | power_up(isp); | ||
1295 | otg_init(isp); | ||
1296 | |||
1297 | /* NOTE: since we don't change this, this provides | ||
1298 | * a few more interrupts than are strictly needed. | ||
1299 | */ | ||
1300 | isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, | ||
1301 | INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND); | ||
1302 | isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, | ||
1303 | INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND); | ||
1304 | |||
1305 | dev_info(&isp->client->dev, "ready for dual-role USB ...\n"); | ||
1306 | |||
1307 | return 0; | ||
1308 | } | ||
1309 | |||
1310 | #endif | ||
1311 | |||
1312 | /* add or disable the host device+driver */ | ||
1313 | static int | ||
1314 | isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host) | ||
1315 | { | ||
1316 | struct isp1301 *isp = container_of(otg, struct isp1301, otg); | ||
1317 | |||
1318 | if (!otg || isp != the_transceiver) | ||
1319 | return -ENODEV; | ||
1320 | |||
1321 | if (!host) { | ||
1322 | omap_writew(0, OTG_IRQ_EN); | ||
1323 | power_down(isp); | ||
1324 | isp->otg.host = NULL; | ||
1325 | return 0; | ||
1326 | } | ||
1327 | |||
1328 | #ifdef CONFIG_USB_OTG | ||
1329 | isp->otg.host = host; | ||
1330 | dev_dbg(&isp->client->dev, "registered host\n"); | ||
1331 | host_suspend(isp); | ||
1332 | if (isp->otg.gadget) | ||
1333 | return isp1301_otg_enable(isp); | ||
1334 | return 0; | ||
1335 | |||
1336 | #elif !defined(CONFIG_USB_GADGET_OMAP) | ||
1337 | // FIXME update its refcount | ||
1338 | isp->otg.host = host; | ||
1339 | |||
1340 | power_up(isp); | ||
1341 | |||
1342 | if (machine_is_omap_h2()) | ||
1343 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); | ||
1344 | |||
1345 | dev_info(&isp->client->dev, "A-Host sessions ok\n"); | ||
1346 | isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, | ||
1347 | INTR_ID_GND); | ||
1348 | isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, | ||
1349 | INTR_ID_GND); | ||
1350 | |||
1351 | /* If this has a Mini-AB connector, this mode is highly | ||
1352 | * nonstandard ... but can be handy for testing, especially with | ||
1353 | * the Mini-A end of an OTG cable. (Or something nonstandard | ||
1354 | * like MiniB-to-StandardB, maybe built with a gender mender.) | ||
1355 | */ | ||
1356 | isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_VBUS_DRV); | ||
1357 | |||
1358 | dump_regs(isp, __func__); | ||
1359 | |||
1360 | return 0; | ||
1361 | |||
1362 | #else | ||
1363 | dev_dbg(&isp->client->dev, "host sessions not allowed\n"); | ||
1364 | return -EINVAL; | ||
1365 | #endif | ||
1366 | |||
1367 | } | ||
1368 | |||
1369 | static int | ||
1370 | isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget) | ||
1371 | { | ||
1372 | struct isp1301 *isp = container_of(otg, struct isp1301, otg); | ||
1373 | #ifndef CONFIG_USB_OTG | ||
1374 | u32 l; | ||
1375 | #endif | ||
1376 | |||
1377 | if (!otg || isp != the_transceiver) | ||
1378 | return -ENODEV; | ||
1379 | |||
1380 | if (!gadget) { | ||
1381 | omap_writew(0, OTG_IRQ_EN); | ||
1382 | if (!isp->otg.default_a) | ||
1383 | enable_vbus_draw(isp, 0); | ||
1384 | usb_gadget_vbus_disconnect(isp->otg.gadget); | ||
1385 | isp->otg.gadget = NULL; | ||
1386 | power_down(isp); | ||
1387 | return 0; | ||
1388 | } | ||
1389 | |||
1390 | #ifdef CONFIG_USB_OTG | ||
1391 | isp->otg.gadget = gadget; | ||
1392 | dev_dbg(&isp->client->dev, "registered gadget\n"); | ||
1393 | /* gadget driver may be suspended until vbus_connect () */ | ||
1394 | if (isp->otg.host) | ||
1395 | return isp1301_otg_enable(isp); | ||
1396 | return 0; | ||
1397 | |||
1398 | #elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE) | ||
1399 | isp->otg.gadget = gadget; | ||
1400 | // FIXME update its refcount | ||
1401 | |||
1402 | l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK; | ||
1403 | l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS); | ||
1404 | l |= OTG_ID; | ||
1405 | omap_writel(l, OTG_CTRL); | ||
1406 | |||
1407 | power_up(isp); | ||
1408 | isp->otg.state = OTG_STATE_B_IDLE; | ||
1409 | |||
1410 | if (machine_is_omap_h2() || machine_is_omap_h3()) | ||
1411 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); | ||
1412 | |||
1413 | isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, | ||
1414 | INTR_SESS_VLD); | ||
1415 | isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, | ||
1416 | INTR_VBUS_VLD); | ||
1417 | dev_info(&isp->client->dev, "B-Peripheral sessions ok\n"); | ||
1418 | dump_regs(isp, __func__); | ||
1419 | |||
1420 | /* If this has a Mini-AB connector, this mode is highly | ||
1421 | * nonstandard ... but can be handy for testing, so long | ||
1422 | * as you don't plug a Mini-A cable into the jack. | ||
1423 | */ | ||
1424 | if (isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE) & INTR_VBUS_VLD) | ||
1425 | b_peripheral(isp); | ||
1426 | |||
1427 | return 0; | ||
1428 | |||
1429 | #else | ||
1430 | dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n"); | ||
1431 | return -EINVAL; | ||
1432 | #endif | ||
1433 | } | ||
1434 | |||
1435 | |||
1436 | /*-------------------------------------------------------------------------*/ | ||
1437 | |||
1438 | static int | ||
1439 | isp1301_set_power(struct otg_transceiver *dev, unsigned mA) | ||
1440 | { | ||
1441 | if (!the_transceiver) | ||
1442 | return -ENODEV; | ||
1443 | if (dev->state == OTG_STATE_B_PERIPHERAL) | ||
1444 | enable_vbus_draw(the_transceiver, mA); | ||
1445 | return 0; | ||
1446 | } | ||
1447 | |||
1448 | static int | ||
1449 | isp1301_start_srp(struct otg_transceiver *dev) | ||
1450 | { | ||
1451 | struct isp1301 *isp = container_of(dev, struct isp1301, otg); | ||
1452 | u32 otg_ctrl; | ||
1453 | |||
1454 | if (!dev || isp != the_transceiver | ||
1455 | || isp->otg.state != OTG_STATE_B_IDLE) | ||
1456 | return -ENODEV; | ||
1457 | |||
1458 | otg_ctrl = omap_readl(OTG_CTRL); | ||
1459 | if (!(otg_ctrl & OTG_BSESSEND)) | ||
1460 | return -EINVAL; | ||
1461 | |||
1462 | otg_ctrl |= OTG_B_BUSREQ; | ||
1463 | otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK; | ||
1464 | omap_writel(otg_ctrl, OTG_CTRL); | ||
1465 | isp->otg.state = OTG_STATE_B_SRP_INIT; | ||
1466 | |||
1467 | pr_debug("otg: SRP, %s ... %06x\n", state_name(isp), | ||
1468 | omap_readl(OTG_CTRL)); | ||
1469 | #ifdef CONFIG_USB_OTG | ||
1470 | check_state(isp, __func__); | ||
1471 | #endif | ||
1472 | return 0; | ||
1473 | } | ||
1474 | |||
1475 | static int | ||
1476 | isp1301_start_hnp(struct otg_transceiver *dev) | ||
1477 | { | ||
1478 | #ifdef CONFIG_USB_OTG | ||
1479 | struct isp1301 *isp = container_of(dev, struct isp1301, otg); | ||
1480 | u32 l; | ||
1481 | |||
1482 | if (!dev || isp != the_transceiver) | ||
1483 | return -ENODEV; | ||
1484 | if (isp->otg.default_a && (isp->otg.host == NULL | ||
1485 | || !isp->otg.host->b_hnp_enable)) | ||
1486 | return -ENOTCONN; | ||
1487 | if (!isp->otg.default_a && (isp->otg.gadget == NULL | ||
1488 | || !isp->otg.gadget->b_hnp_enable)) | ||
1489 | return -ENOTCONN; | ||
1490 | |||
1491 | /* We want hardware to manage most HNP protocol timings. | ||
1492 | * So do this part as early as possible... | ||
1493 | */ | ||
1494 | switch (isp->otg.state) { | ||
1495 | case OTG_STATE_B_HOST: | ||
1496 | isp->otg.state = OTG_STATE_B_PERIPHERAL; | ||
1497 | /* caller will suspend next */ | ||
1498 | break; | ||
1499 | case OTG_STATE_A_HOST: | ||
1500 | #if 0 | ||
1501 | /* autoconnect mode avoids irq latency bugs */ | ||
1502 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, | ||
1503 | MC1_BDIS_ACON_EN); | ||
1504 | #endif | ||
1505 | /* caller must suspend then clear A_BUSREQ */ | ||
1506 | usb_gadget_vbus_connect(isp->otg.gadget); | ||
1507 | l = omap_readl(OTG_CTRL); | ||
1508 | l |= OTG_A_SETB_HNPEN; | ||
1509 | omap_writel(l, OTG_CTRL); | ||
1510 | |||
1511 | break; | ||
1512 | case OTG_STATE_A_PERIPHERAL: | ||
1513 | /* initiated by B-Host suspend */ | ||
1514 | break; | ||
1515 | default: | ||
1516 | return -EILSEQ; | ||
1517 | } | ||
1518 | pr_debug("otg: HNP %s, %06x ...\n", | ||
1519 | state_name(isp), omap_readl(OTG_CTRL)); | ||
1520 | check_state(isp, __func__); | ||
1521 | return 0; | ||
1522 | #else | ||
1523 | /* srp-only */ | ||
1524 | return -EINVAL; | ||
1525 | #endif | ||
1526 | } | ||
1527 | |||
1528 | /*-------------------------------------------------------------------------*/ | ||
1529 | |||
1530 | static int __init | ||
1531 | isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id) | ||
1532 | { | ||
1533 | int status; | ||
1534 | struct isp1301 *isp; | ||
1535 | |||
1536 | if (the_transceiver) | ||
1537 | return 0; | ||
1538 | |||
1539 | isp = kzalloc(sizeof *isp, GFP_KERNEL); | ||
1540 | if (!isp) | ||
1541 | return 0; | ||
1542 | |||
1543 | INIT_WORK(&isp->work, isp1301_work); | ||
1544 | init_timer(&isp->timer); | ||
1545 | isp->timer.function = isp1301_timer; | ||
1546 | isp->timer.data = (unsigned long) isp; | ||
1547 | |||
1548 | i2c_set_clientdata(i2c, isp); | ||
1549 | isp->client = i2c; | ||
1550 | |||
1551 | /* verify the chip (shouldn't be necesary) */ | ||
1552 | status = isp1301_get_u16(isp, ISP1301_VENDOR_ID); | ||
1553 | if (status != I2C_VENDOR_ID_PHILIPS) { | ||
1554 | dev_dbg(&i2c->dev, "not philips id: %d\n", status); | ||
1555 | goto fail; | ||
1556 | } | ||
1557 | status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID); | ||
1558 | if (status != I2C_PRODUCT_ID_PHILIPS_1301) { | ||
1559 | dev_dbg(&i2c->dev, "not isp1301, %d\n", status); | ||
1560 | goto fail; | ||
1561 | } | ||
1562 | isp->i2c_release = i2c->dev.release; | ||
1563 | i2c->dev.release = isp1301_release; | ||
1564 | |||
1565 | /* initial development used chiprev 2.00 */ | ||
1566 | status = i2c_smbus_read_word_data(i2c, ISP1301_BCD_DEVICE); | ||
1567 | dev_info(&i2c->dev, "chiprev %x.%02x, driver " DRIVER_VERSION "\n", | ||
1568 | status >> 8, status & 0xff); | ||
1569 | |||
1570 | /* make like power-on reset */ | ||
1571 | isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_MASK); | ||
1572 | |||
1573 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_BI_DI); | ||
1574 | isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, ~MC2_BI_DI); | ||
1575 | |||
1576 | isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, | ||
1577 | OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN); | ||
1578 | isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, | ||
1579 | ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN)); | ||
1580 | |||
1581 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, ~0); | ||
1582 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0); | ||
1583 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0); | ||
1584 | |||
1585 | #ifdef CONFIG_USB_OTG | ||
1586 | status = otg_bind(isp); | ||
1587 | if (status < 0) { | ||
1588 | dev_dbg(&i2c->dev, "can't bind OTG\n"); | ||
1589 | goto fail; | ||
1590 | } | ||
1591 | #endif | ||
1592 | |||
1593 | if (machine_is_omap_h2()) { | ||
1594 | /* full speed signaling by default */ | ||
1595 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, | ||
1596 | MC1_SPEED); | ||
1597 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, | ||
1598 | MC2_SPD_SUSP_CTRL); | ||
1599 | |||
1600 | /* IRQ wired at M14 */ | ||
1601 | omap_cfg_reg(M14_1510_GPIO2); | ||
1602 | if (gpio_request(2, "isp1301") == 0) | ||
1603 | gpio_direction_input(2); | ||
1604 | isp->irq_type = IRQF_TRIGGER_FALLING; | ||
1605 | } | ||
1606 | |||
1607 | isp->irq_type |= IRQF_SAMPLE_RANDOM; | ||
1608 | status = request_irq(i2c->irq, isp1301_irq, | ||
1609 | isp->irq_type, DRIVER_NAME, isp); | ||
1610 | if (status < 0) { | ||
1611 | dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n", | ||
1612 | i2c->irq, status); | ||
1613 | goto fail; | ||
1614 | } | ||
1615 | |||
1616 | isp->otg.dev = &i2c->dev; | ||
1617 | isp->otg.label = DRIVER_NAME; | ||
1618 | |||
1619 | isp->otg.set_host = isp1301_set_host, | ||
1620 | isp->otg.set_peripheral = isp1301_set_peripheral, | ||
1621 | isp->otg.set_power = isp1301_set_power, | ||
1622 | isp->otg.start_srp = isp1301_start_srp, | ||
1623 | isp->otg.start_hnp = isp1301_start_hnp, | ||
1624 | |||
1625 | enable_vbus_draw(isp, 0); | ||
1626 | power_down(isp); | ||
1627 | the_transceiver = isp; | ||
1628 | |||
1629 | #ifdef CONFIG_USB_OTG | ||
1630 | update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE)); | ||
1631 | update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS)); | ||
1632 | #endif | ||
1633 | |||
1634 | dump_regs(isp, __func__); | ||
1635 | |||
1636 | #ifdef VERBOSE | ||
1637 | mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); | ||
1638 | dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES); | ||
1639 | #endif | ||
1640 | |||
1641 | status = otg_set_transceiver(&isp->otg); | ||
1642 | if (status < 0) | ||
1643 | dev_err(&i2c->dev, "can't register transceiver, %d\n", | ||
1644 | status); | ||
1645 | |||
1646 | return 0; | ||
1647 | |||
1648 | fail: | ||
1649 | kfree(isp); | ||
1650 | return -ENODEV; | ||
1651 | } | ||
1652 | |||
1653 | static const struct i2c_device_id isp1301_id[] = { | ||
1654 | { "isp1301_omap", 0 }, | ||
1655 | { } | ||
1656 | }; | ||
1657 | MODULE_DEVICE_TABLE(i2c, isp1301_id); | ||
1658 | |||
1659 | static struct i2c_driver isp1301_driver = { | ||
1660 | .driver = { | ||
1661 | .name = "isp1301_omap", | ||
1662 | }, | ||
1663 | .probe = isp1301_probe, | ||
1664 | .remove = __exit_p(isp1301_remove), | ||
1665 | .id_table = isp1301_id, | ||
1666 | }; | ||
1667 | |||
1668 | /*-------------------------------------------------------------------------*/ | ||
1669 | |||
1670 | static int __init isp_init(void) | ||
1671 | { | ||
1672 | return i2c_add_driver(&isp1301_driver); | ||
1673 | } | ||
1674 | module_init(isp_init); | ||
1675 | |||
1676 | static void __exit isp_exit(void) | ||
1677 | { | ||
1678 | if (the_transceiver) | ||
1679 | otg_set_transceiver(NULL); | ||
1680 | i2c_del_driver(&isp1301_driver); | ||
1681 | } | ||
1682 | module_exit(isp_exit); | ||
1683 | |||
diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c new file mode 100644 index 000000000000..ff318fae7d4d --- /dev/null +++ b/drivers/usb/otg/otg.c | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | * otg.c -- USB OTG utility code | ||
3 | * | ||
4 | * Copyright (C) 2004 Texas Instruments | ||
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 | |||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/device.h> | ||
14 | |||
15 | #include <linux/usb/otg.h> | ||
16 | |||
17 | static struct otg_transceiver *xceiv; | ||
18 | |||
19 | /** | ||
20 | * otg_get_transceiver - find the (single) OTG transceiver | ||
21 | * | ||
22 | * Returns the transceiver driver, after getting a refcount to it; or | ||
23 | * null if there is no such transceiver. The caller is responsible for | ||
24 | * calling otg_put_transceiver() to release that count. | ||
25 | * | ||
26 | * For use by USB host and peripheral drivers. | ||
27 | */ | ||
28 | struct otg_transceiver *otg_get_transceiver(void) | ||
29 | { | ||
30 | if (xceiv) | ||
31 | get_device(xceiv->dev); | ||
32 | return xceiv; | ||
33 | } | ||
34 | EXPORT_SYMBOL(otg_get_transceiver); | ||
35 | |||
36 | /** | ||
37 | * otg_put_transceiver - release the (single) OTG transceiver | ||
38 | * @x: the transceiver returned by otg_get_transceiver() | ||
39 | * | ||
40 | * Releases a refcount the caller received from otg_get_transceiver(). | ||
41 | * | ||
42 | * For use by USB host and peripheral drivers. | ||
43 | */ | ||
44 | void otg_put_transceiver(struct otg_transceiver *x) | ||
45 | { | ||
46 | put_device(x->dev); | ||
47 | } | ||
48 | EXPORT_SYMBOL(otg_put_transceiver); | ||
49 | |||
50 | /** | ||
51 | * otg_set_transceiver - declare the (single) OTG transceiver | ||
52 | * @x: the USB OTG transceiver to be used; or NULL | ||
53 | * | ||
54 | * This call is exclusively for use by transceiver drivers, which | ||
55 | * coordinate the activities of drivers for host and peripheral | ||
56 | * controllers, and in some cases for VBUS current regulation. | ||
57 | */ | ||
58 | int otg_set_transceiver(struct otg_transceiver *x) | ||
59 | { | ||
60 | if (xceiv && x) | ||
61 | return -EBUSY; | ||
62 | xceiv = x; | ||
63 | return 0; | ||
64 | } | ||
65 | EXPORT_SYMBOL(otg_set_transceiver); | ||
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c new file mode 100644 index 000000000000..416e4410be02 --- /dev/null +++ b/drivers/usb/otg/twl4030-usb.c | |||
@@ -0,0 +1,721 @@ | |||
1 | /* | ||
2 | * twl4030_usb - TWL4030 USB transceiver, talking to OMAP OTG controller | ||
3 | * | ||
4 | * Copyright (C) 2004-2007 Texas Instruments | ||
5 | * Copyright (C) 2008 Nokia Corporation | ||
6 | * Contact: Felipe Balbi <felipe.balbi@nokia.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 as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | * | ||
22 | * Current status: | ||
23 | * - HS USB ULPI mode works. | ||
24 | * - 3-pin mode support may be added in future. | ||
25 | */ | ||
26 | |||
27 | #include <linux/module.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/interrupt.h> | ||
30 | #include <linux/platform_device.h> | ||
31 | #include <linux/spinlock.h> | ||
32 | #include <linux/workqueue.h> | ||
33 | #include <linux/io.h> | ||
34 | #include <linux/delay.h> | ||
35 | #include <linux/usb/otg.h> | ||
36 | #include <linux/i2c/twl4030.h> | ||
37 | |||
38 | |||
39 | /* Register defines */ | ||
40 | |||
41 | #define VENDOR_ID_LO 0x00 | ||
42 | #define VENDOR_ID_HI 0x01 | ||
43 | #define PRODUCT_ID_LO 0x02 | ||
44 | #define PRODUCT_ID_HI 0x03 | ||
45 | |||
46 | #define FUNC_CTRL 0x04 | ||
47 | #define FUNC_CTRL_SET 0x05 | ||
48 | #define FUNC_CTRL_CLR 0x06 | ||
49 | #define FUNC_CTRL_SUSPENDM (1 << 6) | ||
50 | #define FUNC_CTRL_RESET (1 << 5) | ||
51 | #define FUNC_CTRL_OPMODE_MASK (3 << 3) /* bits 3 and 4 */ | ||
52 | #define FUNC_CTRL_OPMODE_NORMAL (0 << 3) | ||
53 | #define FUNC_CTRL_OPMODE_NONDRIVING (1 << 3) | ||
54 | #define FUNC_CTRL_OPMODE_DISABLE_BIT_NRZI (2 << 3) | ||
55 | #define FUNC_CTRL_TERMSELECT (1 << 2) | ||
56 | #define FUNC_CTRL_XCVRSELECT_MASK (3 << 0) /* bits 0 and 1 */ | ||
57 | #define FUNC_CTRL_XCVRSELECT_HS (0 << 0) | ||
58 | #define FUNC_CTRL_XCVRSELECT_FS (1 << 0) | ||
59 | #define FUNC_CTRL_XCVRSELECT_LS (2 << 0) | ||
60 | #define FUNC_CTRL_XCVRSELECT_FS4LS (3 << 0) | ||
61 | |||
62 | #define IFC_CTRL 0x07 | ||
63 | #define IFC_CTRL_SET 0x08 | ||
64 | #define IFC_CTRL_CLR 0x09 | ||
65 | #define IFC_CTRL_INTERFACE_PROTECT_DISABLE (1 << 7) | ||
66 | #define IFC_CTRL_AUTORESUME (1 << 4) | ||
67 | #define IFC_CTRL_CLOCKSUSPENDM (1 << 3) | ||
68 | #define IFC_CTRL_CARKITMODE (1 << 2) | ||
69 | #define IFC_CTRL_FSLSSERIALMODE_3PIN (1 << 1) | ||
70 | |||
71 | #define TWL4030_OTG_CTRL 0x0A | ||
72 | #define TWL4030_OTG_CTRL_SET 0x0B | ||
73 | #define TWL4030_OTG_CTRL_CLR 0x0C | ||
74 | #define TWL4030_OTG_CTRL_DRVVBUS (1 << 5) | ||
75 | #define TWL4030_OTG_CTRL_CHRGVBUS (1 << 4) | ||
76 | #define TWL4030_OTG_CTRL_DISCHRGVBUS (1 << 3) | ||
77 | #define TWL4030_OTG_CTRL_DMPULLDOWN (1 << 2) | ||
78 | #define TWL4030_OTG_CTRL_DPPULLDOWN (1 << 1) | ||
79 | #define TWL4030_OTG_CTRL_IDPULLUP (1 << 0) | ||
80 | |||
81 | #define USB_INT_EN_RISE 0x0D | ||
82 | #define USB_INT_EN_RISE_SET 0x0E | ||
83 | #define USB_INT_EN_RISE_CLR 0x0F | ||
84 | #define USB_INT_EN_FALL 0x10 | ||
85 | #define USB_INT_EN_FALL_SET 0x11 | ||
86 | #define USB_INT_EN_FALL_CLR 0x12 | ||
87 | #define USB_INT_STS 0x13 | ||
88 | #define USB_INT_LATCH 0x14 | ||
89 | #define USB_INT_IDGND (1 << 4) | ||
90 | #define USB_INT_SESSEND (1 << 3) | ||
91 | #define USB_INT_SESSVALID (1 << 2) | ||
92 | #define USB_INT_VBUSVALID (1 << 1) | ||
93 | #define USB_INT_HOSTDISCONNECT (1 << 0) | ||
94 | |||
95 | #define CARKIT_CTRL 0x19 | ||
96 | #define CARKIT_CTRL_SET 0x1A | ||
97 | #define CARKIT_CTRL_CLR 0x1B | ||
98 | #define CARKIT_CTRL_MICEN (1 << 6) | ||
99 | #define CARKIT_CTRL_SPKRIGHTEN (1 << 5) | ||
100 | #define CARKIT_CTRL_SPKLEFTEN (1 << 4) | ||
101 | #define CARKIT_CTRL_RXDEN (1 << 3) | ||
102 | #define CARKIT_CTRL_TXDEN (1 << 2) | ||
103 | #define CARKIT_CTRL_IDGNDDRV (1 << 1) | ||
104 | #define CARKIT_CTRL_CARKITPWR (1 << 0) | ||
105 | #define CARKIT_PLS_CTRL 0x22 | ||
106 | #define CARKIT_PLS_CTRL_SET 0x23 | ||
107 | #define CARKIT_PLS_CTRL_CLR 0x24 | ||
108 | #define CARKIT_PLS_CTRL_SPKRRIGHT_BIASEN (1 << 3) | ||
109 | #define CARKIT_PLS_CTRL_SPKRLEFT_BIASEN (1 << 2) | ||
110 | #define CARKIT_PLS_CTRL_RXPLSEN (1 << 1) | ||
111 | #define CARKIT_PLS_CTRL_TXPLSEN (1 << 0) | ||
112 | |||
113 | #define MCPC_CTRL 0x30 | ||
114 | #define MCPC_CTRL_SET 0x31 | ||
115 | #define MCPC_CTRL_CLR 0x32 | ||
116 | #define MCPC_CTRL_RTSOL (1 << 7) | ||
117 | #define MCPC_CTRL_EXTSWR (1 << 6) | ||
118 | #define MCPC_CTRL_EXTSWC (1 << 5) | ||
119 | #define MCPC_CTRL_VOICESW (1 << 4) | ||
120 | #define MCPC_CTRL_OUT64K (1 << 3) | ||
121 | #define MCPC_CTRL_RTSCTSSW (1 << 2) | ||
122 | #define MCPC_CTRL_HS_UART (1 << 0) | ||
123 | |||
124 | #define MCPC_IO_CTRL 0x33 | ||
125 | #define MCPC_IO_CTRL_SET 0x34 | ||
126 | #define MCPC_IO_CTRL_CLR 0x35 | ||
127 | #define MCPC_IO_CTRL_MICBIASEN (1 << 5) | ||
128 | #define MCPC_IO_CTRL_CTS_NPU (1 << 4) | ||
129 | #define MCPC_IO_CTRL_RXD_PU (1 << 3) | ||
130 | #define MCPC_IO_CTRL_TXDTYP (1 << 2) | ||
131 | #define MCPC_IO_CTRL_CTSTYP (1 << 1) | ||
132 | #define MCPC_IO_CTRL_RTSTYP (1 << 0) | ||
133 | |||
134 | #define MCPC_CTRL2 0x36 | ||
135 | #define MCPC_CTRL2_SET 0x37 | ||
136 | #define MCPC_CTRL2_CLR 0x38 | ||
137 | #define MCPC_CTRL2_MCPC_CK_EN (1 << 0) | ||
138 | |||
139 | #define OTHER_FUNC_CTRL 0x80 | ||
140 | #define OTHER_FUNC_CTRL_SET 0x81 | ||
141 | #define OTHER_FUNC_CTRL_CLR 0x82 | ||
142 | #define OTHER_FUNC_CTRL_BDIS_ACON_EN (1 << 4) | ||
143 | #define OTHER_FUNC_CTRL_FIVEWIRE_MODE (1 << 2) | ||
144 | |||
145 | #define OTHER_IFC_CTRL 0x83 | ||
146 | #define OTHER_IFC_CTRL_SET 0x84 | ||
147 | #define OTHER_IFC_CTRL_CLR 0x85 | ||
148 | #define OTHER_IFC_CTRL_OE_INT_EN (1 << 6) | ||
149 | #define OTHER_IFC_CTRL_CEA2011_MODE (1 << 5) | ||
150 | #define OTHER_IFC_CTRL_FSLSSERIALMODE_4PIN (1 << 4) | ||
151 | #define OTHER_IFC_CTRL_HIZ_ULPI_60MHZ_OUT (1 << 3) | ||
152 | #define OTHER_IFC_CTRL_HIZ_ULPI (1 << 2) | ||
153 | #define OTHER_IFC_CTRL_ALT_INT_REROUTE (1 << 0) | ||
154 | |||
155 | #define OTHER_INT_EN_RISE 0x86 | ||
156 | #define OTHER_INT_EN_RISE_SET 0x87 | ||
157 | #define OTHER_INT_EN_RISE_CLR 0x88 | ||
158 | #define OTHER_INT_EN_FALL 0x89 | ||
159 | #define OTHER_INT_EN_FALL_SET 0x8A | ||
160 | #define OTHER_INT_EN_FALL_CLR 0x8B | ||
161 | #define OTHER_INT_STS 0x8C | ||
162 | #define OTHER_INT_LATCH 0x8D | ||
163 | #define OTHER_INT_VB_SESS_VLD (1 << 7) | ||
164 | #define OTHER_INT_DM_HI (1 << 6) /* not valid for "latch" reg */ | ||
165 | #define OTHER_INT_DP_HI (1 << 5) /* not valid for "latch" reg */ | ||
166 | #define OTHER_INT_BDIS_ACON (1 << 3) /* not valid for "fall" regs */ | ||
167 | #define OTHER_INT_MANU (1 << 1) | ||
168 | #define OTHER_INT_ABNORMAL_STRESS (1 << 0) | ||
169 | |||
170 | #define ID_STATUS 0x96 | ||
171 | #define ID_RES_FLOAT (1 << 4) | ||
172 | #define ID_RES_440K (1 << 3) | ||
173 | #define ID_RES_200K (1 << 2) | ||
174 | #define ID_RES_102K (1 << 1) | ||
175 | #define ID_RES_GND (1 << 0) | ||
176 | |||
177 | #define POWER_CTRL 0xAC | ||
178 | #define POWER_CTRL_SET 0xAD | ||
179 | #define POWER_CTRL_CLR 0xAE | ||
180 | #define POWER_CTRL_OTG_ENAB (1 << 5) | ||
181 | |||
182 | #define OTHER_IFC_CTRL2 0xAF | ||
183 | #define OTHER_IFC_CTRL2_SET 0xB0 | ||
184 | #define OTHER_IFC_CTRL2_CLR 0xB1 | ||
185 | #define OTHER_IFC_CTRL2_ULPI_STP_LOW (1 << 4) | ||
186 | #define OTHER_IFC_CTRL2_ULPI_TXEN_POL (1 << 3) | ||
187 | #define OTHER_IFC_CTRL2_ULPI_4PIN_2430 (1 << 2) | ||
188 | #define OTHER_IFC_CTRL2_USB_INT_OUTSEL_MASK (3 << 0) /* bits 0 and 1 */ | ||
189 | #define OTHER_IFC_CTRL2_USB_INT_OUTSEL_INT1N (0 << 0) | ||
190 | #define OTHER_IFC_CTRL2_USB_INT_OUTSEL_INT2N (1 << 0) | ||
191 | |||
192 | #define REG_CTRL_EN 0xB2 | ||
193 | #define REG_CTRL_EN_SET 0xB3 | ||
194 | #define REG_CTRL_EN_CLR 0xB4 | ||
195 | #define REG_CTRL_ERROR 0xB5 | ||
196 | #define ULPI_I2C_CONFLICT_INTEN (1 << 0) | ||
197 | |||
198 | #define OTHER_FUNC_CTRL2 0xB8 | ||
199 | #define OTHER_FUNC_CTRL2_SET 0xB9 | ||
200 | #define OTHER_FUNC_CTRL2_CLR 0xBA | ||
201 | #define OTHER_FUNC_CTRL2_VBAT_TIMER_EN (1 << 0) | ||
202 | |||
203 | /* following registers do not have separate _clr and _set registers */ | ||
204 | #define VBUS_DEBOUNCE 0xC0 | ||
205 | #define ID_DEBOUNCE 0xC1 | ||
206 | #define VBAT_TIMER 0xD3 | ||
207 | #define PHY_PWR_CTRL 0xFD | ||
208 | #define PHY_PWR_PHYPWD (1 << 0) | ||
209 | #define PHY_CLK_CTRL 0xFE | ||
210 | #define PHY_CLK_CTRL_CLOCKGATING_EN (1 << 2) | ||
211 | #define PHY_CLK_CTRL_CLK32K_EN (1 << 1) | ||
212 | #define REQ_PHY_DPLL_CLK (1 << 0) | ||
213 | #define PHY_CLK_CTRL_STS 0xFF | ||
214 | #define PHY_DPLL_CLK (1 << 0) | ||
215 | |||
216 | /* In module TWL4030_MODULE_PM_MASTER */ | ||
217 | #define PROTECT_KEY 0x0E | ||
218 | |||
219 | /* In module TWL4030_MODULE_PM_RECEIVER */ | ||
220 | #define VUSB_DEDICATED1 0x7D | ||
221 | #define VUSB_DEDICATED2 0x7E | ||
222 | #define VUSB1V5_DEV_GRP 0x71 | ||
223 | #define VUSB1V5_TYPE 0x72 | ||
224 | #define VUSB1V5_REMAP 0x73 | ||
225 | #define VUSB1V8_DEV_GRP 0x74 | ||
226 | #define VUSB1V8_TYPE 0x75 | ||
227 | #define VUSB1V8_REMAP 0x76 | ||
228 | #define VUSB3V1_DEV_GRP 0x77 | ||
229 | #define VUSB3V1_TYPE 0x78 | ||
230 | #define VUSB3V1_REMAP 0x79 | ||
231 | |||
232 | /* In module TWL4030_MODULE_INTBR */ | ||
233 | #define PMBR1 0x0D | ||
234 | #define GPIO_USB_4PIN_ULPI_2430C (3 << 0) | ||
235 | |||
236 | |||
237 | |||
238 | enum linkstat { | ||
239 | USB_LINK_UNKNOWN = 0, | ||
240 | USB_LINK_NONE, | ||
241 | USB_LINK_VBUS, | ||
242 | USB_LINK_ID, | ||
243 | }; | ||
244 | |||
245 | struct twl4030_usb { | ||
246 | struct otg_transceiver otg; | ||
247 | struct device *dev; | ||
248 | |||
249 | /* for vbus reporting with irqs disabled */ | ||
250 | spinlock_t lock; | ||
251 | |||
252 | /* pin configuration */ | ||
253 | enum twl4030_usb_mode usb_mode; | ||
254 | |||
255 | int irq; | ||
256 | u8 linkstat; | ||
257 | u8 asleep; | ||
258 | bool irq_enabled; | ||
259 | }; | ||
260 | |||
261 | /* internal define on top of container_of */ | ||
262 | #define xceiv_to_twl(x) container_of((x), struct twl4030_usb, otg); | ||
263 | |||
264 | /*-------------------------------------------------------------------------*/ | ||
265 | |||
266 | static int twl4030_i2c_write_u8_verify(struct twl4030_usb *twl, | ||
267 | u8 module, u8 data, u8 address) | ||
268 | { | ||
269 | u8 check; | ||
270 | |||
271 | if ((twl4030_i2c_write_u8(module, data, address) >= 0) && | ||
272 | (twl4030_i2c_read_u8(module, &check, address) >= 0) && | ||
273 | (check == data)) | ||
274 | return 0; | ||
275 | dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", | ||
276 | 1, module, address, check, data); | ||
277 | |||
278 | /* Failed once: Try again */ | ||
279 | if ((twl4030_i2c_write_u8(module, data, address) >= 0) && | ||
280 | (twl4030_i2c_read_u8(module, &check, address) >= 0) && | ||
281 | (check == data)) | ||
282 | return 0; | ||
283 | dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", | ||
284 | 2, module, address, check, data); | ||
285 | |||
286 | /* Failed again: Return error */ | ||
287 | return -EBUSY; | ||
288 | } | ||
289 | |||
290 | #define twl4030_usb_write_verify(twl, address, data) \ | ||
291 | twl4030_i2c_write_u8_verify(twl, TWL4030_MODULE_USB, (data), (address)) | ||
292 | |||
293 | static inline int twl4030_usb_write(struct twl4030_usb *twl, | ||
294 | u8 address, u8 data) | ||
295 | { | ||
296 | int ret = 0; | ||
297 | |||
298 | ret = twl4030_i2c_write_u8(TWL4030_MODULE_USB, data, address); | ||
299 | if (ret < 0) | ||
300 | dev_dbg(twl->dev, | ||
301 | "TWL4030:USB:Write[0x%x] Error %d\n", address, ret); | ||
302 | return ret; | ||
303 | } | ||
304 | |||
305 | static inline int twl4030_readb(struct twl4030_usb *twl, u8 module, u8 address) | ||
306 | { | ||
307 | u8 data; | ||
308 | int ret = 0; | ||
309 | |||
310 | ret = twl4030_i2c_read_u8(module, &data, address); | ||
311 | if (ret >= 0) | ||
312 | ret = data; | ||
313 | else | ||
314 | dev_dbg(twl->dev, | ||
315 | "TWL4030:readb[0x%x,0x%x] Error %d\n", | ||
316 | module, address, ret); | ||
317 | |||
318 | return ret; | ||
319 | } | ||
320 | |||
321 | static inline int twl4030_usb_read(struct twl4030_usb *twl, u8 address) | ||
322 | { | ||
323 | return twl4030_readb(twl, TWL4030_MODULE_USB, address); | ||
324 | } | ||
325 | |||
326 | /*-------------------------------------------------------------------------*/ | ||
327 | |||
328 | static inline int | ||
329 | twl4030_usb_set_bits(struct twl4030_usb *twl, u8 reg, u8 bits) | ||
330 | { | ||
331 | return twl4030_usb_write(twl, reg + 1, bits); | ||
332 | } | ||
333 | |||
334 | static inline int | ||
335 | twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits) | ||
336 | { | ||
337 | return twl4030_usb_write(twl, reg + 2, bits); | ||
338 | } | ||
339 | |||
340 | /*-------------------------------------------------------------------------*/ | ||
341 | |||
342 | static enum linkstat twl4030_usb_linkstat(struct twl4030_usb *twl) | ||
343 | { | ||
344 | int status; | ||
345 | int linkstat = USB_LINK_UNKNOWN; | ||
346 | |||
347 | /* STS_HW_CONDITIONS */ | ||
348 | status = twl4030_readb(twl, TWL4030_MODULE_PM_MASTER, 0x0f); | ||
349 | if (status < 0) | ||
350 | dev_err(twl->dev, "USB link status err %d\n", status); | ||
351 | else if (status & BIT(7)) | ||
352 | linkstat = USB_LINK_VBUS; | ||
353 | else if (status & BIT(2)) | ||
354 | linkstat = USB_LINK_ID; | ||
355 | else | ||
356 | linkstat = USB_LINK_NONE; | ||
357 | |||
358 | dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", | ||
359 | status, status, linkstat); | ||
360 | |||
361 | /* REVISIT this assumes host and peripheral controllers | ||
362 | * are registered, and that both are active... | ||
363 | */ | ||
364 | |||
365 | spin_lock_irq(&twl->lock); | ||
366 | twl->linkstat = linkstat; | ||
367 | if (linkstat == USB_LINK_ID) { | ||
368 | twl->otg.default_a = true; | ||
369 | twl->otg.state = OTG_STATE_A_IDLE; | ||
370 | } else { | ||
371 | twl->otg.default_a = false; | ||
372 | twl->otg.state = OTG_STATE_B_IDLE; | ||
373 | } | ||
374 | spin_unlock_irq(&twl->lock); | ||
375 | |||
376 | return linkstat; | ||
377 | } | ||
378 | |||
379 | static void twl4030_usb_set_mode(struct twl4030_usb *twl, int mode) | ||
380 | { | ||
381 | twl->usb_mode = mode; | ||
382 | |||
383 | switch (mode) { | ||
384 | case T2_USB_MODE_ULPI: | ||
385 | twl4030_usb_clear_bits(twl, IFC_CTRL, IFC_CTRL_CARKITMODE); | ||
386 | twl4030_usb_set_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); | ||
387 | twl4030_usb_clear_bits(twl, FUNC_CTRL, | ||
388 | FUNC_CTRL_XCVRSELECT_MASK | | ||
389 | FUNC_CTRL_OPMODE_MASK); | ||
390 | break; | ||
391 | case -1: | ||
392 | /* FIXME: power on defaults */ | ||
393 | break; | ||
394 | default: | ||
395 | dev_err(twl->dev, "unsupported T2 transceiver mode %d\n", | ||
396 | mode); | ||
397 | break; | ||
398 | }; | ||
399 | } | ||
400 | |||
401 | static void twl4030_i2c_access(struct twl4030_usb *twl, int on) | ||
402 | { | ||
403 | unsigned long timeout; | ||
404 | int val = twl4030_usb_read(twl, PHY_CLK_CTRL); | ||
405 | |||
406 | if (val >= 0) { | ||
407 | if (on) { | ||
408 | /* enable DPLL to access PHY registers over I2C */ | ||
409 | val |= REQ_PHY_DPLL_CLK; | ||
410 | WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL, | ||
411 | (u8)val) < 0); | ||
412 | |||
413 | timeout = jiffies + HZ; | ||
414 | while (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) & | ||
415 | PHY_DPLL_CLK) | ||
416 | && time_before(jiffies, timeout)) | ||
417 | udelay(10); | ||
418 | if (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) & | ||
419 | PHY_DPLL_CLK)) | ||
420 | dev_err(twl->dev, "Timeout setting T2 HSUSB " | ||
421 | "PHY DPLL clock\n"); | ||
422 | } else { | ||
423 | /* let ULPI control the DPLL clock */ | ||
424 | val &= ~REQ_PHY_DPLL_CLK; | ||
425 | WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL, | ||
426 | (u8)val) < 0); | ||
427 | } | ||
428 | } | ||
429 | } | ||
430 | |||
431 | static void twl4030_phy_power(struct twl4030_usb *twl, int on) | ||
432 | { | ||
433 | u8 pwr; | ||
434 | |||
435 | pwr = twl4030_usb_read(twl, PHY_PWR_CTRL); | ||
436 | if (on) { | ||
437 | pwr &= ~PHY_PWR_PHYPWD; | ||
438 | WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0); | ||
439 | twl4030_usb_write(twl, PHY_CLK_CTRL, | ||
440 | twl4030_usb_read(twl, PHY_CLK_CTRL) | | ||
441 | (PHY_CLK_CTRL_CLOCKGATING_EN | | ||
442 | PHY_CLK_CTRL_CLK32K_EN)); | ||
443 | } else { | ||
444 | pwr |= PHY_PWR_PHYPWD; | ||
445 | WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0); | ||
446 | } | ||
447 | } | ||
448 | |||
449 | static void twl4030_phy_suspend(struct twl4030_usb *twl, int controller_off) | ||
450 | { | ||
451 | if (twl->asleep) | ||
452 | return; | ||
453 | |||
454 | twl4030_phy_power(twl, 0); | ||
455 | twl->asleep = 1; | ||
456 | } | ||
457 | |||
458 | static void twl4030_phy_resume(struct twl4030_usb *twl) | ||
459 | { | ||
460 | if (!twl->asleep) | ||
461 | return; | ||
462 | |||
463 | twl4030_phy_power(twl, 1); | ||
464 | twl4030_i2c_access(twl, 1); | ||
465 | twl4030_usb_set_mode(twl, twl->usb_mode); | ||
466 | if (twl->usb_mode == T2_USB_MODE_ULPI) | ||
467 | twl4030_i2c_access(twl, 0); | ||
468 | twl->asleep = 0; | ||
469 | } | ||
470 | |||
471 | static void twl4030_usb_ldo_init(struct twl4030_usb *twl) | ||
472 | { | ||
473 | /* Enable writing to power configuration registers */ | ||
474 | twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0xC0, PROTECT_KEY); | ||
475 | twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0x0C, PROTECT_KEY); | ||
476 | |||
477 | /* put VUSB3V1 LDO in active state */ | ||
478 | twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2); | ||
479 | |||
480 | /* input to VUSB3V1 LDO is from VBAT, not VBUS */ | ||
481 | twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x14, VUSB_DEDICATED1); | ||
482 | |||
483 | /* turn on 3.1V regulator */ | ||
484 | twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x20, VUSB3V1_DEV_GRP); | ||
485 | twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB3V1_TYPE); | ||
486 | |||
487 | /* turn on 1.5V regulator */ | ||
488 | twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x20, VUSB1V5_DEV_GRP); | ||
489 | twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE); | ||
490 | |||
491 | /* turn on 1.8V regulator */ | ||
492 | twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x20, VUSB1V8_DEV_GRP); | ||
493 | twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE); | ||
494 | |||
495 | /* disable access to power configuration registers */ | ||
496 | twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, PROTECT_KEY); | ||
497 | } | ||
498 | |||
499 | static ssize_t twl4030_usb_vbus_show(struct device *dev, | ||
500 | struct device_attribute *attr, char *buf) | ||
501 | { | ||
502 | struct twl4030_usb *twl = dev_get_drvdata(dev); | ||
503 | unsigned long flags; | ||
504 | int ret = -EINVAL; | ||
505 | |||
506 | spin_lock_irqsave(&twl->lock, flags); | ||
507 | ret = sprintf(buf, "%s\n", | ||
508 | (twl->linkstat == USB_LINK_VBUS) ? "on" : "off"); | ||
509 | spin_unlock_irqrestore(&twl->lock, flags); | ||
510 | |||
511 | return ret; | ||
512 | } | ||
513 | static DEVICE_ATTR(vbus, 0444, twl4030_usb_vbus_show, NULL); | ||
514 | |||
515 | static irqreturn_t twl4030_usb_irq(int irq, void *_twl) | ||
516 | { | ||
517 | struct twl4030_usb *twl = _twl; | ||
518 | int status; | ||
519 | |||
520 | #ifdef CONFIG_LOCKDEP | ||
521 | /* WORKAROUND for lockdep forcing IRQF_DISABLED on us, which | ||
522 | * we don't want and can't tolerate. Although it might be | ||
523 | * friendlier not to borrow this thread context... | ||
524 | */ | ||
525 | local_irq_enable(); | ||
526 | #endif | ||
527 | |||
528 | status = twl4030_usb_linkstat(twl); | ||
529 | if (status != USB_LINK_UNKNOWN) { | ||
530 | |||
531 | /* FIXME add a set_power() method so that B-devices can | ||
532 | * configure the charger appropriately. It's not always | ||
533 | * correct to consume VBUS power, and how much current to | ||
534 | * consume is a function of the USB configuration chosen | ||
535 | * by the host. | ||
536 | * | ||
537 | * REVISIT usb_gadget_vbus_connect(...) as needed, ditto | ||
538 | * its disconnect() sibling, when changing to/from the | ||
539 | * USB_LINK_VBUS state. musb_hdrc won't care until it | ||
540 | * starts to handle softconnect right. | ||
541 | */ | ||
542 | twl4030charger_usb_en(status == USB_LINK_VBUS); | ||
543 | |||
544 | if (status == USB_LINK_NONE) | ||
545 | twl4030_phy_suspend(twl, 0); | ||
546 | else | ||
547 | twl4030_phy_resume(twl); | ||
548 | } | ||
549 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); | ||
550 | |||
551 | return IRQ_HANDLED; | ||
552 | } | ||
553 | |||
554 | static int twl4030_set_suspend(struct otg_transceiver *x, int suspend) | ||
555 | { | ||
556 | struct twl4030_usb *twl = xceiv_to_twl(x); | ||
557 | |||
558 | if (suspend) | ||
559 | twl4030_phy_suspend(twl, 1); | ||
560 | else | ||
561 | twl4030_phy_resume(twl); | ||
562 | |||
563 | return 0; | ||
564 | } | ||
565 | |||
566 | static int twl4030_set_peripheral(struct otg_transceiver *x, | ||
567 | struct usb_gadget *gadget) | ||
568 | { | ||
569 | struct twl4030_usb *twl; | ||
570 | |||
571 | if (!x) | ||
572 | return -ENODEV; | ||
573 | |||
574 | twl = xceiv_to_twl(x); | ||
575 | twl->otg.gadget = gadget; | ||
576 | if (!gadget) | ||
577 | twl->otg.state = OTG_STATE_UNDEFINED; | ||
578 | |||
579 | return 0; | ||
580 | } | ||
581 | |||
582 | static int twl4030_set_host(struct otg_transceiver *x, struct usb_bus *host) | ||
583 | { | ||
584 | struct twl4030_usb *twl; | ||
585 | |||
586 | if (!x) | ||
587 | return -ENODEV; | ||
588 | |||
589 | twl = xceiv_to_twl(x); | ||
590 | twl->otg.host = host; | ||
591 | if (!host) | ||
592 | twl->otg.state = OTG_STATE_UNDEFINED; | ||
593 | |||
594 | return 0; | ||
595 | } | ||
596 | |||
597 | static int __init twl4030_usb_probe(struct platform_device *pdev) | ||
598 | { | ||
599 | struct twl4030_usb_data *pdata = pdev->dev.platform_data; | ||
600 | struct twl4030_usb *twl; | ||
601 | int status; | ||
602 | |||
603 | if (!pdata) { | ||
604 | dev_dbg(&pdev->dev, "platform_data not available\n"); | ||
605 | return -EINVAL; | ||
606 | } | ||
607 | |||
608 | twl = kzalloc(sizeof *twl, GFP_KERNEL); | ||
609 | if (!twl) | ||
610 | return -ENOMEM; | ||
611 | |||
612 | twl->dev = &pdev->dev; | ||
613 | twl->irq = platform_get_irq(pdev, 0); | ||
614 | twl->otg.dev = twl->dev; | ||
615 | twl->otg.label = "twl4030"; | ||
616 | twl->otg.set_host = twl4030_set_host; | ||
617 | twl->otg.set_peripheral = twl4030_set_peripheral; | ||
618 | twl->otg.set_suspend = twl4030_set_suspend; | ||
619 | twl->usb_mode = pdata->usb_mode; | ||
620 | twl->asleep = 1; | ||
621 | |||
622 | /* init spinlock for workqueue */ | ||
623 | spin_lock_init(&twl->lock); | ||
624 | |||
625 | twl4030_usb_ldo_init(twl); | ||
626 | otg_set_transceiver(&twl->otg); | ||
627 | |||
628 | platform_set_drvdata(pdev, twl); | ||
629 | if (device_create_file(&pdev->dev, &dev_attr_vbus)) | ||
630 | dev_warn(&pdev->dev, "could not create sysfs file\n"); | ||
631 | |||
632 | /* Our job is to use irqs and status from the power module | ||
633 | * to keep the transceiver disabled when nothing's connected. | ||
634 | * | ||
635 | * FIXME we actually shouldn't start enabling it until the | ||
636 | * USB controller drivers have said they're ready, by calling | ||
637 | * set_host() and/or set_peripheral() ... OTG_capable boards | ||
638 | * need both handles, otherwise just one suffices. | ||
639 | */ | ||
640 | twl->irq_enabled = true; | ||
641 | status = request_irq(twl->irq, twl4030_usb_irq, | ||
642 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, | ||
643 | "twl4030_usb", twl); | ||
644 | if (status < 0) { | ||
645 | dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n", | ||
646 | twl->irq, status); | ||
647 | kfree(twl); | ||
648 | return status; | ||
649 | } | ||
650 | |||
651 | /* The IRQ handler just handles changes from the previous states | ||
652 | * of the ID and VBUS pins ... in probe() we must initialize that | ||
653 | * previous state. The easy way: fake an IRQ. | ||
654 | * | ||
655 | * REVISIT: a real IRQ might have happened already, if PREEMPT is | ||
656 | * enabled. Else the IRQ may not yet be configured or enabled, | ||
657 | * because of scheduling delays. | ||
658 | */ | ||
659 | twl4030_usb_irq(twl->irq, twl); | ||
660 | |||
661 | dev_info(&pdev->dev, "Initialized TWL4030 USB module\n"); | ||
662 | return 0; | ||
663 | } | ||
664 | |||
665 | static int __exit twl4030_usb_remove(struct platform_device *pdev) | ||
666 | { | ||
667 | struct twl4030_usb *twl = platform_get_drvdata(pdev); | ||
668 | int val; | ||
669 | |||
670 | free_irq(twl->irq, twl); | ||
671 | device_remove_file(twl->dev, &dev_attr_vbus); | ||
672 | |||
673 | /* set transceiver mode to power on defaults */ | ||
674 | twl4030_usb_set_mode(twl, -1); | ||
675 | |||
676 | /* autogate 60MHz ULPI clock, | ||
677 | * clear dpll clock request for i2c access, | ||
678 | * disable 32KHz | ||
679 | */ | ||
680 | val = twl4030_usb_read(twl, PHY_CLK_CTRL); | ||
681 | if (val >= 0) { | ||
682 | val |= PHY_CLK_CTRL_CLOCKGATING_EN; | ||
683 | val &= ~(PHY_CLK_CTRL_CLK32K_EN | REQ_PHY_DPLL_CLK); | ||
684 | twl4030_usb_write(twl, PHY_CLK_CTRL, (u8)val); | ||
685 | } | ||
686 | |||
687 | /* disable complete OTG block */ | ||
688 | twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); | ||
689 | |||
690 | twl4030_phy_power(twl, 0); | ||
691 | |||
692 | kfree(twl); | ||
693 | |||
694 | return 0; | ||
695 | } | ||
696 | |||
697 | static struct platform_driver twl4030_usb_driver = { | ||
698 | .probe = twl4030_usb_probe, | ||
699 | .remove = __exit_p(twl4030_usb_remove), | ||
700 | .driver = { | ||
701 | .name = "twl4030_usb", | ||
702 | .owner = THIS_MODULE, | ||
703 | }, | ||
704 | }; | ||
705 | |||
706 | static int __init twl4030_usb_init(void) | ||
707 | { | ||
708 | return platform_driver_register(&twl4030_usb_driver); | ||
709 | } | ||
710 | subsys_initcall(twl4030_usb_init); | ||
711 | |||
712 | static void __exit twl4030_usb_exit(void) | ||
713 | { | ||
714 | platform_driver_unregister(&twl4030_usb_driver); | ||
715 | } | ||
716 | module_exit(twl4030_usb_exit); | ||
717 | |||
718 | MODULE_ALIAS("platform:twl4030_usb"); | ||
719 | MODULE_AUTHOR("Texas Instruments, Inc, Nokia Corporation"); | ||
720 | MODULE_DESCRIPTION("TWL4030 USB transceiver driver"); | ||
721 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig index 70338f4ec918..b361f05cafac 100644 --- a/drivers/usb/serial/Kconfig +++ b/drivers/usb/serial/Kconfig | |||
@@ -496,6 +496,14 @@ config USB_SERIAL_SAFE_PADDED | |||
496 | bool "USB Secure Encapsulated Driver - Padded" | 496 | bool "USB Secure Encapsulated Driver - Padded" |
497 | depends on USB_SERIAL_SAFE | 497 | depends on USB_SERIAL_SAFE |
498 | 498 | ||
499 | config USB_SERIAL_SIEMENS_MPI | ||
500 | tristate "USB Siemens MPI driver" | ||
501 | help | ||
502 | Say M here if you want to use a Siemens USB/MPI adapter. | ||
503 | |||
504 | To compile this driver as a module, choose M here: the | ||
505 | module will be called siemens_mpi. | ||
506 | |||
499 | config USB_SERIAL_SIERRAWIRELESS | 507 | config USB_SERIAL_SIERRAWIRELESS |
500 | tristate "USB Sierra Wireless Driver" | 508 | tristate "USB Sierra Wireless Driver" |
501 | help | 509 | help |
@@ -565,6 +573,15 @@ config USB_SERIAL_OMNINET | |||
565 | To compile this driver as a module, choose M here: the | 573 | To compile this driver as a module, choose M here: the |
566 | module will be called omninet. | 574 | module will be called omninet. |
567 | 575 | ||
576 | config USB_SERIAL_OPTICON | ||
577 | tristate "USB Opticon Barcode driver (serial mode)" | ||
578 | help | ||
579 | Say Y here if you want to use a Opticon USB Barcode device | ||
580 | in serial emulation mode. | ||
581 | |||
582 | To compile this driver as a module, choose M here: the | ||
583 | module will be called opticon. | ||
584 | |||
568 | config USB_SERIAL_DEBUG | 585 | config USB_SERIAL_DEBUG |
569 | tristate "USB Debugging Device" | 586 | tristate "USB Debugging Device" |
570 | help | 587 | help |
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile index 6047f818adfe..b75be91eb8f1 100644 --- a/drivers/usb/serial/Makefile +++ b/drivers/usb/serial/Makefile | |||
@@ -41,10 +41,12 @@ obj-$(CONFIG_USB_SERIAL_MOS7840) += mos7840.o | |||
41 | obj-$(CONFIG_USB_SERIAL_MOTOROLA) += moto_modem.o | 41 | obj-$(CONFIG_USB_SERIAL_MOTOROLA) += moto_modem.o |
42 | obj-$(CONFIG_USB_SERIAL_NAVMAN) += navman.o | 42 | obj-$(CONFIG_USB_SERIAL_NAVMAN) += navman.o |
43 | obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o | 43 | obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o |
44 | obj-$(CONFIG_USB_SERIAL_OPTICON) += opticon.o | ||
44 | obj-$(CONFIG_USB_SERIAL_OPTION) += option.o | 45 | obj-$(CONFIG_USB_SERIAL_OPTION) += option.o |
45 | obj-$(CONFIG_USB_SERIAL_OTI6858) += oti6858.o | 46 | obj-$(CONFIG_USB_SERIAL_OTI6858) += oti6858.o |
46 | obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o | 47 | obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o |
47 | obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o | 48 | obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o |
49 | obj-$(CONFIG_USB_SERIAL_SIEMENS_MPI) += siemens_mpi.o | ||
48 | obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o | 50 | obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o |
49 | obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o | 51 | obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o |
50 | obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o | 52 | obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o |
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index 69f84f0ea6fe..38ba4ea8b6bf 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c | |||
@@ -635,8 +635,7 @@ static int digi_write_oob_command(struct usb_serial_port *port, | |||
635 | 635 | ||
636 | spin_lock_irqsave(&oob_priv->dp_port_lock, flags); | 636 | spin_lock_irqsave(&oob_priv->dp_port_lock, flags); |
637 | while (count > 0) { | 637 | while (count > 0) { |
638 | while (oob_port->write_urb->status == -EINPROGRESS | 638 | while (oob_priv->dp_write_urb_in_use) { |
639 | || oob_priv->dp_write_urb_in_use) { | ||
640 | cond_wait_interruptible_timeout_irqrestore( | 639 | cond_wait_interruptible_timeout_irqrestore( |
641 | &oob_port->write_wait, DIGI_RETRY_TIMEOUT, | 640 | &oob_port->write_wait, DIGI_RETRY_TIMEOUT, |
642 | &oob_priv->dp_port_lock, flags); | 641 | &oob_priv->dp_port_lock, flags); |
@@ -699,9 +698,8 @@ static int digi_write_inb_command(struct usb_serial_port *port, | |||
699 | 698 | ||
700 | spin_lock_irqsave(&priv->dp_port_lock, flags); | 699 | spin_lock_irqsave(&priv->dp_port_lock, flags); |
701 | while (count > 0 && ret == 0) { | 700 | while (count > 0 && ret == 0) { |
702 | while ((port->write_urb->status == -EINPROGRESS | 701 | while (priv->dp_write_urb_in_use && |
703 | || priv->dp_write_urb_in_use) | 702 | time_before(jiffies, timeout)) { |
704 | && time_before(jiffies, timeout)) { | ||
705 | cond_wait_interruptible_timeout_irqrestore( | 703 | cond_wait_interruptible_timeout_irqrestore( |
706 | &port->write_wait, DIGI_RETRY_TIMEOUT, | 704 | &port->write_wait, DIGI_RETRY_TIMEOUT, |
707 | &priv->dp_port_lock, flags); | 705 | &priv->dp_port_lock, flags); |
@@ -779,8 +777,7 @@ static int digi_set_modem_signals(struct usb_serial_port *port, | |||
779 | spin_lock_irqsave(&oob_priv->dp_port_lock, flags); | 777 | spin_lock_irqsave(&oob_priv->dp_port_lock, flags); |
780 | spin_lock(&port_priv->dp_port_lock); | 778 | spin_lock(&port_priv->dp_port_lock); |
781 | 779 | ||
782 | while (oob_port->write_urb->status == -EINPROGRESS || | 780 | while (oob_priv->dp_write_urb_in_use) { |
783 | oob_priv->dp_write_urb_in_use) { | ||
784 | spin_unlock(&port_priv->dp_port_lock); | 781 | spin_unlock(&port_priv->dp_port_lock); |
785 | cond_wait_interruptible_timeout_irqrestore( | 782 | cond_wait_interruptible_timeout_irqrestore( |
786 | &oob_port->write_wait, DIGI_RETRY_TIMEOUT, | 783 | &oob_port->write_wait, DIGI_RETRY_TIMEOUT, |
@@ -1168,12 +1165,10 @@ static int digi_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
1168 | 1165 | ||
1169 | /* be sure only one write proceeds at a time */ | 1166 | /* be sure only one write proceeds at a time */ |
1170 | /* there are races on the port private buffer */ | 1167 | /* there are races on the port private buffer */ |
1171 | /* and races to check write_urb->status */ | ||
1172 | spin_lock_irqsave(&priv->dp_port_lock, flags); | 1168 | spin_lock_irqsave(&priv->dp_port_lock, flags); |
1173 | 1169 | ||
1174 | /* wait for urb status clear to submit another urb */ | 1170 | /* wait for urb status clear to submit another urb */ |
1175 | if (port->write_urb->status == -EINPROGRESS || | 1171 | if (priv->dp_write_urb_in_use) { |
1176 | priv->dp_write_urb_in_use) { | ||
1177 | /* buffer data if count is 1 (probably put_char) if possible */ | 1172 | /* buffer data if count is 1 (probably put_char) if possible */ |
1178 | if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) { | 1173 | if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) { |
1179 | priv->dp_out_buf[priv->dp_out_buf_len++] = *buf; | 1174 | priv->dp_out_buf[priv->dp_out_buf_len++] = *buf; |
@@ -1236,7 +1231,7 @@ static void digi_write_bulk_callback(struct urb *urb) | |||
1236 | int ret = 0; | 1231 | int ret = 0; |
1237 | int status = urb->status; | 1232 | int status = urb->status; |
1238 | 1233 | ||
1239 | dbg("digi_write_bulk_callback: TOP, urb->status=%d", status); | 1234 | dbg("digi_write_bulk_callback: TOP, status=%d", status); |
1240 | 1235 | ||
1241 | /* port and serial sanity check */ | 1236 | /* port and serial sanity check */ |
1242 | if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) { | 1237 | if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) { |
@@ -1266,8 +1261,7 @@ static void digi_write_bulk_callback(struct urb *urb) | |||
1266 | /* try to send any buffered data on this port, if it is open */ | 1261 | /* try to send any buffered data on this port, if it is open */ |
1267 | spin_lock(&priv->dp_port_lock); | 1262 | spin_lock(&priv->dp_port_lock); |
1268 | priv->dp_write_urb_in_use = 0; | 1263 | priv->dp_write_urb_in_use = 0; |
1269 | if (port->port.count && port->write_urb->status != -EINPROGRESS | 1264 | if (port->port.count && priv->dp_out_buf_len > 0) { |
1270 | && priv->dp_out_buf_len > 0) { | ||
1271 | *((unsigned char *)(port->write_urb->transfer_buffer)) | 1265 | *((unsigned char *)(port->write_urb->transfer_buffer)) |
1272 | = (unsigned char)DIGI_CMD_SEND_DATA; | 1266 | = (unsigned char)DIGI_CMD_SEND_DATA; |
1273 | *((unsigned char *)(port->write_urb->transfer_buffer) + 1) | 1267 | *((unsigned char *)(port->write_urb->transfer_buffer) + 1) |
@@ -1305,8 +1299,7 @@ static int digi_write_room(struct tty_struct *tty) | |||
1305 | 1299 | ||
1306 | spin_lock_irqsave(&priv->dp_port_lock, flags); | 1300 | spin_lock_irqsave(&priv->dp_port_lock, flags); |
1307 | 1301 | ||
1308 | if (port->write_urb->status == -EINPROGRESS || | 1302 | if (priv->dp_write_urb_in_use) |
1309 | priv->dp_write_urb_in_use) | ||
1310 | room = 0; | 1303 | room = 0; |
1311 | else | 1304 | else |
1312 | room = port->bulk_out_size - 2 - priv->dp_out_buf_len; | 1305 | room = port->bulk_out_size - 2 - priv->dp_out_buf_len; |
@@ -1322,8 +1315,7 @@ static int digi_chars_in_buffer(struct tty_struct *tty) | |||
1322 | struct usb_serial_port *port = tty->driver_data; | 1315 | struct usb_serial_port *port = tty->driver_data; |
1323 | struct digi_port *priv = usb_get_serial_port_data(port); | 1316 | struct digi_port *priv = usb_get_serial_port_data(port); |
1324 | 1317 | ||
1325 | if (port->write_urb->status == -EINPROGRESS | 1318 | if (priv->dp_write_urb_in_use) { |
1326 | || priv->dp_write_urb_in_use) { | ||
1327 | dbg("digi_chars_in_buffer: port=%d, chars=%d", | 1319 | dbg("digi_chars_in_buffer: port=%d, chars=%d", |
1328 | priv->dp_port_num, port->bulk_out_size - 2); | 1320 | priv->dp_port_num, port->bulk_out_size - 2); |
1329 | /* return(port->bulk_out_size - 2); */ | 1321 | /* return(port->bulk_out_size - 2); */ |
@@ -1702,7 +1694,7 @@ static int digi_read_inb_callback(struct urb *urb) | |||
1702 | /* short/multiple packet check */ | 1694 | /* short/multiple packet check */ |
1703 | if (urb->actual_length != len + 2) { | 1695 | if (urb->actual_length != len + 2) { |
1704 | dev_err(&port->dev, "%s: INCOMPLETE OR MULTIPLE PACKET, " | 1696 | dev_err(&port->dev, "%s: INCOMPLETE OR MULTIPLE PACKET, " |
1705 | "urb->status=%d, port=%d, opcode=%d, len=%d, " | 1697 | "status=%d, port=%d, opcode=%d, len=%d, " |
1706 | "actual_length=%d, status=%d\n", __func__, status, | 1698 | "actual_length=%d, status=%d\n", __func__, status, |
1707 | priv->dp_port_num, opcode, len, urb->actual_length, | 1699 | priv->dp_port_num, opcode, len, urb->actual_length, |
1708 | port_status); | 1700 | port_status); |
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index ef6cfa5a447f..c70a8f667d85 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c | |||
@@ -2030,7 +2030,7 @@ static void ftdi_process_read(struct work_struct *work) | |||
2030 | spin_unlock_irqrestore(&priv->rx_lock, flags); | 2030 | spin_unlock_irqrestore(&priv->rx_lock, flags); |
2031 | dbg("%s - deferring remainder until unthrottled", | 2031 | dbg("%s - deferring remainder until unthrottled", |
2032 | __func__); | 2032 | __func__); |
2033 | return; | 2033 | goto out; |
2034 | } | 2034 | } |
2035 | spin_unlock_irqrestore(&priv->rx_lock, flags); | 2035 | spin_unlock_irqrestore(&priv->rx_lock, flags); |
2036 | /* if the port is closed stop trying to read */ | 2036 | /* if the port is closed stop trying to read */ |
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 8e6a66e38db2..a26a0e2cdb4a 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c | |||
@@ -1056,7 +1056,7 @@ static void garmin_write_bulk_callback(struct urb *urb) | |||
1056 | 1056 | ||
1057 | if (status) { | 1057 | if (status) { |
1058 | dbg("%s - nonzero write bulk status received: %d", | 1058 | dbg("%s - nonzero write bulk status received: %d", |
1059 | __func__, urb->status); | 1059 | __func__, status); |
1060 | spin_lock_irqsave(&garmin_data_p->lock, flags); | 1060 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
1061 | garmin_data_p->flags |= CLEAR_HALT_REQUIRED; | 1061 | garmin_data_p->flags |= CLEAR_HALT_REQUIRED; |
1062 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | 1062 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c index 3ac59a8a980f..f530032ed93d 100644 --- a/drivers/usb/serial/ipw.c +++ b/drivers/usb/serial/ipw.c | |||
@@ -473,7 +473,7 @@ static struct usb_serial_driver ipw_device = { | |||
473 | 473 | ||
474 | 474 | ||
475 | 475 | ||
476 | static int usb_ipw_init(void) | 476 | static int __init usb_ipw_init(void) |
477 | { | 477 | { |
478 | int retval; | 478 | int retval; |
479 | 479 | ||
@@ -490,7 +490,7 @@ static int usb_ipw_init(void) | |||
490 | return 0; | 490 | return 0; |
491 | } | 491 | } |
492 | 492 | ||
493 | static void usb_ipw_exit(void) | 493 | static void __exit usb_ipw_exit(void) |
494 | { | 494 | { |
495 | usb_deregister(&usb_ipw_driver); | 495 | usb_deregister(&usb_ipw_driver); |
496 | usb_serial_deregister(&ipw_device); | 496 | usb_serial_deregister(&ipw_device); |
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c index e320972cb227..2314c6ae4fc2 100644 --- a/drivers/usb/serial/iuu_phoenix.c +++ b/drivers/usb/serial/iuu_phoenix.c | |||
@@ -190,10 +190,12 @@ static void iuu_rxcmd(struct urb *urb) | |||
190 | { | 190 | { |
191 | struct usb_serial_port *port = urb->context; | 191 | struct usb_serial_port *port = urb->context; |
192 | int result; | 192 | int result; |
193 | int status = urb->status; | ||
194 | |||
193 | dbg("%s - enter", __func__); | 195 | dbg("%s - enter", __func__); |
194 | 196 | ||
195 | if (urb->status) { | 197 | if (status) { |
196 | dbg("%s - urb->status = %d", __func__, urb->status); | 198 | dbg("%s - status = %d", __func__, status); |
197 | /* error stop all */ | 199 | /* error stop all */ |
198 | return; | 200 | return; |
199 | } | 201 | } |
@@ -245,10 +247,12 @@ static void iuu_update_status_callback(struct urb *urb) | |||
245 | struct usb_serial_port *port = urb->context; | 247 | struct usb_serial_port *port = urb->context; |
246 | struct iuu_private *priv = usb_get_serial_port_data(port); | 248 | struct iuu_private *priv = usb_get_serial_port_data(port); |
247 | u8 *st; | 249 | u8 *st; |
250 | int status = urb->status; | ||
251 | |||
248 | dbg("%s - enter", __func__); | 252 | dbg("%s - enter", __func__); |
249 | 253 | ||
250 | if (urb->status) { | 254 | if (status) { |
251 | dbg("%s - urb->status = %d", __func__, urb->status); | 255 | dbg("%s - status = %d", __func__, status); |
252 | /* error stop all */ | 256 | /* error stop all */ |
253 | return; | 257 | return; |
254 | } | 258 | } |
@@ -274,9 +278,9 @@ static void iuu_status_callback(struct urb *urb) | |||
274 | { | 278 | { |
275 | struct usb_serial_port *port = urb->context; | 279 | struct usb_serial_port *port = urb->context; |
276 | int result; | 280 | int result; |
277 | dbg("%s - enter", __func__); | 281 | int status = urb->status; |
278 | 282 | ||
279 | dbg("%s - urb->status = %d", __func__, urb->status); | 283 | dbg("%s - status = %d", __func__, status); |
280 | usb_fill_bulk_urb(port->read_urb, port->serial->dev, | 284 | usb_fill_bulk_urb(port->read_urb, port->serial->dev, |
281 | usb_rcvbulkpipe(port->serial->dev, | 285 | usb_rcvbulkpipe(port->serial->dev, |
282 | port->bulk_in_endpointAddress), | 286 | port->bulk_in_endpointAddress), |
@@ -618,11 +622,12 @@ static void read_buf_callback(struct urb *urb) | |||
618 | struct usb_serial_port *port = urb->context; | 622 | struct usb_serial_port *port = urb->context; |
619 | unsigned char *data = urb->transfer_buffer; | 623 | unsigned char *data = urb->transfer_buffer; |
620 | struct tty_struct *tty; | 624 | struct tty_struct *tty; |
621 | dbg("%s - urb->status = %d", __func__, urb->status); | 625 | int status = urb->status; |
622 | 626 | ||
623 | if (urb->status) { | 627 | dbg("%s - status = %d", __func__, status); |
624 | dbg("%s - urb->status = %d", __func__, urb->status); | 628 | |
625 | if (urb->status == -EPROTO) { | 629 | if (status) { |
630 | if (status == -EPROTO) { | ||
626 | /* reschedule needed */ | 631 | /* reschedule needed */ |
627 | } | 632 | } |
628 | return; | 633 | return; |
@@ -695,7 +700,7 @@ static void iuu_uart_read_callback(struct urb *urb) | |||
695 | struct usb_serial_port *port = urb->context; | 700 | struct usb_serial_port *port = urb->context; |
696 | struct iuu_private *priv = usb_get_serial_port_data(port); | 701 | struct iuu_private *priv = usb_get_serial_port_data(port); |
697 | unsigned long flags; | 702 | unsigned long flags; |
698 | int status; | 703 | int status = urb->status; |
699 | int error = 0; | 704 | int error = 0; |
700 | int len = 0; | 705 | int len = 0; |
701 | unsigned char *data = urb->transfer_buffer; | 706 | unsigned char *data = urb->transfer_buffer; |
@@ -703,8 +708,8 @@ static void iuu_uart_read_callback(struct urb *urb) | |||
703 | 708 | ||
704 | dbg("%s - enter", __func__); | 709 | dbg("%s - enter", __func__); |
705 | 710 | ||
706 | if (urb->status) { | 711 | if (status) { |
707 | dbg("%s - urb->status = %d", __func__, urb->status); | 712 | dbg("%s - status = %d", __func__, status); |
708 | /* error stop all */ | 713 | /* error stop all */ |
709 | return; | 714 | return; |
710 | } | 715 | } |
@@ -782,12 +787,11 @@ static void read_rxcmd_callback(struct urb *urb) | |||
782 | { | 787 | { |
783 | struct usb_serial_port *port = urb->context; | 788 | struct usb_serial_port *port = urb->context; |
784 | int result; | 789 | int result; |
785 | dbg("%s - enter", __func__); | 790 | int status = urb->status; |
786 | 791 | ||
787 | dbg("%s - urb->status = %d", __func__, urb->status); | 792 | dbg("%s - status = %d", __func__, status); |
788 | 793 | ||
789 | if (urb->status) { | 794 | if (status) { |
790 | dbg("%s - urb->status = %d", __func__, urb->status); | ||
791 | /* error stop all */ | 795 | /* error stop all */ |
792 | return; | 796 | return; |
793 | } | 797 | } |
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 96a8c7713212..2c20e88a91b3 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c | |||
@@ -214,6 +214,7 @@ struct moschip_port { | |||
214 | spinlock_t pool_lock; | 214 | spinlock_t pool_lock; |
215 | struct urb *write_urb_pool[NUM_URBS]; | 215 | struct urb *write_urb_pool[NUM_URBS]; |
216 | char busy[NUM_URBS]; | 216 | char busy[NUM_URBS]; |
217 | bool read_urb_busy; | ||
217 | }; | 218 | }; |
218 | 219 | ||
219 | 220 | ||
@@ -679,26 +680,30 @@ static void mos7840_bulk_in_callback(struct urb *urb) | |||
679 | struct tty_struct *tty; | 680 | struct tty_struct *tty; |
680 | int status = urb->status; | 681 | int status = urb->status; |
681 | 682 | ||
682 | if (status) { | ||
683 | dbg("nonzero read bulk status received: %d", status); | ||
684 | return; | ||
685 | } | ||
686 | |||
687 | mos7840_port = urb->context; | 683 | mos7840_port = urb->context; |
688 | if (!mos7840_port) { | 684 | if (!mos7840_port) { |
689 | dbg("%s", "NULL mos7840_port pointer \n"); | 685 | dbg("%s", "NULL mos7840_port pointer \n"); |
686 | mos7840_port->read_urb_busy = false; | ||
687 | return; | ||
688 | } | ||
689 | |||
690 | if (status) { | ||
691 | dbg("nonzero read bulk status received: %d", status); | ||
692 | mos7840_port->read_urb_busy = false; | ||
690 | return; | 693 | return; |
691 | } | 694 | } |
692 | 695 | ||
693 | port = (struct usb_serial_port *)mos7840_port->port; | 696 | port = (struct usb_serial_port *)mos7840_port->port; |
694 | if (mos7840_port_paranoia_check(port, __func__)) { | 697 | if (mos7840_port_paranoia_check(port, __func__)) { |
695 | dbg("%s", "Port Paranoia failed \n"); | 698 | dbg("%s", "Port Paranoia failed \n"); |
699 | mos7840_port->read_urb_busy = false; | ||
696 | return; | 700 | return; |
697 | } | 701 | } |
698 | 702 | ||
699 | serial = mos7840_get_usb_serial(port, __func__); | 703 | serial = mos7840_get_usb_serial(port, __func__); |
700 | if (!serial) { | 704 | if (!serial) { |
701 | dbg("%s\n", "Bad serial pointer "); | 705 | dbg("%s\n", "Bad serial pointer "); |
706 | mos7840_port->read_urb_busy = false; | ||
702 | return; | 707 | return; |
703 | } | 708 | } |
704 | 709 | ||
@@ -725,17 +730,19 @@ static void mos7840_bulk_in_callback(struct urb *urb) | |||
725 | 730 | ||
726 | if (!mos7840_port->read_urb) { | 731 | if (!mos7840_port->read_urb) { |
727 | dbg("%s", "URB KILLED !!!\n"); | 732 | dbg("%s", "URB KILLED !!!\n"); |
733 | mos7840_port->read_urb_busy = false; | ||
728 | return; | 734 | return; |
729 | } | 735 | } |
730 | 736 | ||
731 | 737 | ||
732 | mos7840_port->read_urb->dev = serial->dev; | 738 | mos7840_port->read_urb->dev = serial->dev; |
733 | 739 | ||
740 | mos7840_port->read_urb_busy = true; | ||
734 | retval = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); | 741 | retval = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); |
735 | 742 | ||
736 | if (retval) { | 743 | if (retval) { |
737 | dbg(" usb_submit_urb(read bulk) failed, retval = %d", | 744 | dbg("usb_submit_urb(read bulk) failed, retval = %d", retval); |
738 | retval); | 745 | mos7840_port->read_urb_busy = false; |
739 | } | 746 | } |
740 | } | 747 | } |
741 | 748 | ||
@@ -1055,10 +1062,12 @@ static int mos7840_open(struct tty_struct *tty, | |||
1055 | 1062 | ||
1056 | dbg("mos7840_open: bulkin endpoint is %d\n", | 1063 | dbg("mos7840_open: bulkin endpoint is %d\n", |
1057 | port->bulk_in_endpointAddress); | 1064 | port->bulk_in_endpointAddress); |
1065 | mos7840_port->read_urb_busy = true; | ||
1058 | response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL); | 1066 | response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL); |
1059 | if (response) { | 1067 | if (response) { |
1060 | dev_err(&port->dev, "%s - Error %d submitting control urb\n", | 1068 | dev_err(&port->dev, "%s - Error %d submitting control urb\n", |
1061 | __func__, response); | 1069 | __func__, response); |
1070 | mos7840_port->read_urb_busy = false; | ||
1062 | } | 1071 | } |
1063 | 1072 | ||
1064 | /* initialize our wait queues */ | 1073 | /* initialize our wait queues */ |
@@ -1227,6 +1236,7 @@ static void mos7840_close(struct tty_struct *tty, | |||
1227 | if (mos7840_port->read_urb) { | 1236 | if (mos7840_port->read_urb) { |
1228 | dbg("%s", "Shutdown bulk read\n"); | 1237 | dbg("%s", "Shutdown bulk read\n"); |
1229 | usb_kill_urb(mos7840_port->read_urb); | 1238 | usb_kill_urb(mos7840_port->read_urb); |
1239 | mos7840_port->read_urb_busy = false; | ||
1230 | } | 1240 | } |
1231 | if ((&mos7840_port->control_urb)) { | 1241 | if ((&mos7840_port->control_urb)) { |
1232 | dbg("%s", "Shutdown control read\n"); | 1242 | dbg("%s", "Shutdown control read\n"); |
@@ -2043,14 +2053,14 @@ static void mos7840_change_port_settings(struct tty_struct *tty, | |||
2043 | Data = 0x0c; | 2053 | Data = 0x0c; |
2044 | mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); | 2054 | mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
2045 | 2055 | ||
2046 | if (mos7840_port->read_urb->status != -EINPROGRESS) { | 2056 | if (mos7840_port->read_urb_busy == false) { |
2047 | mos7840_port->read_urb->dev = serial->dev; | 2057 | mos7840_port->read_urb->dev = serial->dev; |
2048 | 2058 | mos7840_port->read_urb_busy = true; | |
2049 | status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); | 2059 | status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); |
2050 | |||
2051 | if (status) { | 2060 | if (status) { |
2052 | dbg(" usb_submit_urb(read bulk) failed, status = %d", | 2061 | dbg("usb_submit_urb(read bulk) failed, status = %d", |
2053 | status); | 2062 | status); |
2063 | mos7840_port->read_urb_busy = false; | ||
2054 | } | 2064 | } |
2055 | } | 2065 | } |
2056 | wake_up(&mos7840_port->delta_msr_wait); | 2066 | wake_up(&mos7840_port->delta_msr_wait); |
@@ -2117,12 +2127,14 @@ static void mos7840_set_termios(struct tty_struct *tty, | |||
2117 | return; | 2127 | return; |
2118 | } | 2128 | } |
2119 | 2129 | ||
2120 | if (mos7840_port->read_urb->status != -EINPROGRESS) { | 2130 | if (mos7840_port->read_urb_busy == false) { |
2121 | mos7840_port->read_urb->dev = serial->dev; | 2131 | mos7840_port->read_urb->dev = serial->dev; |
2132 | mos7840_port->read_urb_busy = true; | ||
2122 | status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); | 2133 | status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); |
2123 | if (status) { | 2134 | if (status) { |
2124 | dbg(" usb_submit_urb(read bulk) failed, status = %d", | 2135 | dbg("usb_submit_urb(read bulk) failed, status = %d", |
2125 | status); | 2136 | status); |
2137 | mos7840_port->read_urb_busy = false; | ||
2126 | } | 2138 | } |
2127 | } | 2139 | } |
2128 | return; | 2140 | return; |
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c new file mode 100644 index 000000000000..cea326f1f105 --- /dev/null +++ b/drivers/usb/serial/opticon.c | |||
@@ -0,0 +1,358 @@ | |||
1 | /* | ||
2 | * Opticon USB barcode to serial driver | ||
3 | * | ||
4 | * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de> | ||
5 | * Copyright (C) 2008 Novell Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License version | ||
9 | * 2 as published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/tty.h> | ||
15 | #include <linux/tty_driver.h> | ||
16 | #include <linux/tty_flip.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/usb.h> | ||
19 | #include <linux/usb/serial.h> | ||
20 | #include <linux/uaccess.h> | ||
21 | |||
22 | static int debug; | ||
23 | |||
24 | static struct usb_device_id id_table[] = { | ||
25 | { USB_DEVICE(0x065a, 0x0009) }, | ||
26 | { }, | ||
27 | }; | ||
28 | MODULE_DEVICE_TABLE(usb, id_table); | ||
29 | |||
30 | /* This structure holds all of the individual device information */ | ||
31 | struct opticon_private { | ||
32 | struct usb_device *udev; | ||
33 | struct usb_serial *serial; | ||
34 | struct usb_serial_port *port; | ||
35 | unsigned char *bulk_in_buffer; | ||
36 | struct urb *bulk_read_urb; | ||
37 | int buffer_size; | ||
38 | u8 bulk_address; | ||
39 | spinlock_t lock; /* protects the following flags */ | ||
40 | bool throttled; | ||
41 | bool actually_throttled; | ||
42 | bool rts; | ||
43 | }; | ||
44 | |||
45 | static void opticon_bulk_callback(struct urb *urb) | ||
46 | { | ||
47 | struct opticon_private *priv = urb->context; | ||
48 | unsigned char *data = urb->transfer_buffer; | ||
49 | struct usb_serial_port *port = priv->port; | ||
50 | int status = urb->status; | ||
51 | struct tty_struct *tty; | ||
52 | int result; | ||
53 | int available_room = 0; | ||
54 | int data_length; | ||
55 | |||
56 | dbg("%s - port %d", __func__, port->number); | ||
57 | |||
58 | switch (status) { | ||
59 | case 0: | ||
60 | /* success */ | ||
61 | break; | ||
62 | case -ECONNRESET: | ||
63 | case -ENOENT: | ||
64 | case -ESHUTDOWN: | ||
65 | /* this urb is terminated, clean up */ | ||
66 | dbg("%s - urb shutting down with status: %d", | ||
67 | __func__, status); | ||
68 | return; | ||
69 | default: | ||
70 | dbg("%s - nonzero urb status received: %d", | ||
71 | __func__, status); | ||
72 | goto exit; | ||
73 | } | ||
74 | |||
75 | usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, | ||
76 | data); | ||
77 | |||
78 | if (urb->actual_length > 2) { | ||
79 | data_length = urb->actual_length - 2; | ||
80 | |||
81 | /* | ||
82 | * Data from the device comes with a 2 byte header: | ||
83 | * | ||
84 | * <0x00><0x00>data... | ||
85 | * This is real data to be sent to the tty layer | ||
86 | * <0x00><0x01)level | ||
87 | * This is a RTS level change, the third byte is the RTS | ||
88 | * value (0 for low, 1 for high). | ||
89 | */ | ||
90 | if ((data[0] == 0x00) && (data[1] == 0x00)) { | ||
91 | /* real data, send it to the tty layer */ | ||
92 | tty = tty_port_tty_get(&port->port); | ||
93 | if (tty) { | ||
94 | available_room = tty_buffer_request_room(tty, | ||
95 | data_length); | ||
96 | if (available_room) { | ||
97 | tty_insert_flip_string(tty, data, | ||
98 | available_room); | ||
99 | tty_flip_buffer_push(tty); | ||
100 | } | ||
101 | tty_kref_put(tty); | ||
102 | } | ||
103 | } else { | ||
104 | if ((data[0] == 0x00) && (data[1] == 0x01)) { | ||
105 | if (data[2] == 0x00) | ||
106 | priv->rts = false; | ||
107 | else | ||
108 | priv->rts = true; | ||
109 | /* FIXME change the RTS level */ | ||
110 | } else { | ||
111 | dev_dbg(&priv->udev->dev, | ||
112 | "Unknown data packet received from the device:" | ||
113 | " %2x %2x\n", | ||
114 | data[0], data[1]); | ||
115 | } | ||
116 | } | ||
117 | } else { | ||
118 | dev_dbg(&priv->udev->dev, | ||
119 | "Improper ammount of data received from the device, " | ||
120 | "%d bytes", urb->actual_length); | ||
121 | } | ||
122 | |||
123 | exit: | ||
124 | spin_lock(&priv->lock); | ||
125 | |||
126 | /* Continue trying to always read if we should */ | ||
127 | if (!priv->throttled) { | ||
128 | usb_fill_bulk_urb(priv->bulk_read_urb, priv->udev, | ||
129 | usb_rcvbulkpipe(priv->udev, | ||
130 | priv->bulk_address), | ||
131 | priv->bulk_in_buffer, priv->buffer_size, | ||
132 | opticon_bulk_callback, priv); | ||
133 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | ||
134 | if (result) | ||
135 | dev_err(&port->dev, | ||
136 | "%s - failed resubmitting read urb, error %d\n", | ||
137 | __func__, result); | ||
138 | } else | ||
139 | priv->actually_throttled = true; | ||
140 | spin_unlock(&priv->lock); | ||
141 | } | ||
142 | |||
143 | static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port, | ||
144 | struct file *filp) | ||
145 | { | ||
146 | struct opticon_private *priv = usb_get_serial_data(port->serial); | ||
147 | unsigned long flags; | ||
148 | int result = 0; | ||
149 | |||
150 | dbg("%s - port %d", __func__, port->number); | ||
151 | |||
152 | spin_lock_irqsave(&priv->lock, flags); | ||
153 | priv->throttled = false; | ||
154 | priv->actually_throttled = false; | ||
155 | priv->port = port; | ||
156 | spin_unlock_irqrestore(&priv->lock, flags); | ||
157 | |||
158 | /* | ||
159 | * Force low_latency on so that our tty_push actually forces the data | ||
160 | * through, otherwise it is scheduled, and with high data rates (like | ||
161 | * with OHCI) data can get lost. | ||
162 | */ | ||
163 | if (tty) | ||
164 | tty->low_latency = 1; | ||
165 | |||
166 | /* Start reading from the device */ | ||
167 | usb_fill_bulk_urb(priv->bulk_read_urb, priv->udev, | ||
168 | usb_rcvbulkpipe(priv->udev, | ||
169 | priv->bulk_address), | ||
170 | priv->bulk_in_buffer, priv->buffer_size, | ||
171 | opticon_bulk_callback, priv); | ||
172 | result = usb_submit_urb(priv->bulk_read_urb, GFP_KERNEL); | ||
173 | if (result) | ||
174 | dev_err(&port->dev, | ||
175 | "%s - failed resubmitting read urb, error %d\n", | ||
176 | __func__, result); | ||
177 | return result; | ||
178 | } | ||
179 | |||
180 | static void opticon_close(struct tty_struct *tty, struct usb_serial_port *port, | ||
181 | struct file *filp) | ||
182 | { | ||
183 | struct opticon_private *priv = usb_get_serial_data(port->serial); | ||
184 | |||
185 | dbg("%s - port %d", __func__, port->number); | ||
186 | |||
187 | /* shutdown our urbs */ | ||
188 | usb_kill_urb(priv->bulk_read_urb); | ||
189 | } | ||
190 | |||
191 | static void opticon_throttle(struct tty_struct *tty) | ||
192 | { | ||
193 | struct usb_serial_port *port = tty->driver_data; | ||
194 | struct opticon_private *priv = usb_get_serial_data(port->serial); | ||
195 | unsigned long flags; | ||
196 | |||
197 | dbg("%s - port %d", __func__, port->number); | ||
198 | spin_lock_irqsave(&priv->lock, flags); | ||
199 | priv->throttled = true; | ||
200 | spin_unlock_irqrestore(&priv->lock, flags); | ||
201 | } | ||
202 | |||
203 | |||
204 | static void opticon_unthrottle(struct tty_struct *tty) | ||
205 | { | ||
206 | struct usb_serial_port *port = tty->driver_data; | ||
207 | struct opticon_private *priv = usb_get_serial_data(port->serial); | ||
208 | unsigned long flags; | ||
209 | int result; | ||
210 | |||
211 | dbg("%s - port %d", __func__, port->number); | ||
212 | |||
213 | spin_lock_irqsave(&priv->lock, flags); | ||
214 | priv->throttled = false; | ||
215 | priv->actually_throttled = false; | ||
216 | spin_unlock_irqrestore(&priv->lock, flags); | ||
217 | |||
218 | priv->bulk_read_urb->dev = port->serial->dev; | ||
219 | result = usb_submit_urb(priv->bulk_read_urb, GFP_ATOMIC); | ||
220 | if (result) | ||
221 | dev_err(&port->dev, | ||
222 | "%s - failed submitting read urb, error %d\n", | ||
223 | __func__, result); | ||
224 | } | ||
225 | |||
226 | static int opticon_startup(struct usb_serial *serial) | ||
227 | { | ||
228 | struct opticon_private *priv; | ||
229 | struct usb_host_interface *intf; | ||
230 | int i; | ||
231 | int retval = -ENOMEM; | ||
232 | bool bulk_in_found = false; | ||
233 | |||
234 | /* create our private serial structure */ | ||
235 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | ||
236 | if (priv == NULL) { | ||
237 | dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); | ||
238 | return -ENOMEM; | ||
239 | } | ||
240 | spin_lock_init(&priv->lock); | ||
241 | priv->serial = serial; | ||
242 | priv->port = serial->port[0]; | ||
243 | priv->udev = serial->dev; | ||
244 | |||
245 | /* find our bulk endpoint */ | ||
246 | intf = serial->interface->altsetting; | ||
247 | for (i = 0; i < intf->desc.bNumEndpoints; ++i) { | ||
248 | struct usb_endpoint_descriptor *endpoint; | ||
249 | |||
250 | endpoint = &intf->endpoint[i].desc; | ||
251 | if (!usb_endpoint_is_bulk_in(endpoint)) | ||
252 | continue; | ||
253 | |||
254 | priv->bulk_read_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
255 | if (!priv->bulk_read_urb) { | ||
256 | dev_err(&priv->udev->dev, "out of memory\n"); | ||
257 | goto error; | ||
258 | } | ||
259 | |||
260 | priv->buffer_size = le16_to_cpu(endpoint->wMaxPacketSize) * 2; | ||
261 | priv->bulk_in_buffer = kmalloc(priv->buffer_size, GFP_KERNEL); | ||
262 | if (!priv->bulk_in_buffer) { | ||
263 | dev_err(&priv->udev->dev, "out of memory\n"); | ||
264 | goto error; | ||
265 | } | ||
266 | |||
267 | priv->bulk_address = endpoint->bEndpointAddress; | ||
268 | |||
269 | /* set up our bulk urb */ | ||
270 | usb_fill_bulk_urb(priv->bulk_read_urb, priv->udev, | ||
271 | usb_rcvbulkpipe(priv->udev, | ||
272 | endpoint->bEndpointAddress), | ||
273 | priv->bulk_in_buffer, priv->buffer_size, | ||
274 | opticon_bulk_callback, priv); | ||
275 | |||
276 | bulk_in_found = true; | ||
277 | break; | ||
278 | } | ||
279 | |||
280 | if (!bulk_in_found) { | ||
281 | dev_err(&priv->udev->dev, | ||
282 | "Error - the proper endpoints were not found!\n"); | ||
283 | goto error; | ||
284 | } | ||
285 | |||
286 | usb_set_serial_data(serial, priv); | ||
287 | return 0; | ||
288 | |||
289 | error: | ||
290 | usb_free_urb(priv->bulk_read_urb); | ||
291 | kfree(priv->bulk_in_buffer); | ||
292 | kfree(priv); | ||
293 | return retval; | ||
294 | } | ||
295 | |||
296 | static void opticon_shutdown(struct usb_serial *serial) | ||
297 | { | ||
298 | struct opticon_private *priv = usb_get_serial_data(serial); | ||
299 | |||
300 | dbg("%s", __func__); | ||
301 | |||
302 | usb_kill_urb(priv->bulk_read_urb); | ||
303 | usb_free_urb(priv->bulk_read_urb); | ||
304 | kfree(priv->bulk_in_buffer); | ||
305 | kfree(priv); | ||
306 | usb_set_serial_data(serial, NULL); | ||
307 | } | ||
308 | |||
309 | |||
310 | static struct usb_driver opticon_driver = { | ||
311 | .name = "opticon", | ||
312 | .probe = usb_serial_probe, | ||
313 | .disconnect = usb_serial_disconnect, | ||
314 | .id_table = id_table, | ||
315 | .no_dynamic_id = 1, | ||
316 | }; | ||
317 | |||
318 | static struct usb_serial_driver opticon_device = { | ||
319 | .driver = { | ||
320 | .owner = THIS_MODULE, | ||
321 | .name = "opticon", | ||
322 | }, | ||
323 | .id_table = id_table, | ||
324 | .usb_driver = &opticon_driver, | ||
325 | .num_ports = 1, | ||
326 | .attach = opticon_startup, | ||
327 | .open = opticon_open, | ||
328 | .close = opticon_close, | ||
329 | .shutdown = opticon_shutdown, | ||
330 | .throttle = opticon_throttle, | ||
331 | .unthrottle = opticon_unthrottle, | ||
332 | }; | ||
333 | |||
334 | static int __init opticon_init(void) | ||
335 | { | ||
336 | int retval; | ||
337 | |||
338 | retval = usb_serial_register(&opticon_device); | ||
339 | if (retval) | ||
340 | return retval; | ||
341 | retval = usb_register(&opticon_driver); | ||
342 | if (retval) | ||
343 | usb_serial_deregister(&opticon_device); | ||
344 | return retval; | ||
345 | } | ||
346 | |||
347 | static void __exit opticon_exit(void) | ||
348 | { | ||
349 | usb_deregister(&opticon_driver); | ||
350 | usb_serial_deregister(&opticon_device); | ||
351 | } | ||
352 | |||
353 | module_init(opticon_init); | ||
354 | module_exit(opticon_exit); | ||
355 | MODULE_LICENSE("GPL"); | ||
356 | |||
357 | module_param(debug, bool, S_IRUGO | S_IWUSR); | ||
358 | MODULE_PARM_DESC(debug, "Debug enabled or not"); | ||
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index 809697b3c7fc..5ed183477aaf 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c | |||
@@ -522,9 +522,9 @@ static int debug; | |||
522 | /* per port private data */ | 522 | /* per port private data */ |
523 | 523 | ||
524 | #define N_IN_URB 4 | 524 | #define N_IN_URB 4 |
525 | #define N_OUT_URB 1 | 525 | #define N_OUT_URB 4 |
526 | #define IN_BUFLEN 4096 | 526 | #define IN_BUFLEN 4096 |
527 | #define OUT_BUFLEN 128 | 527 | #define OUT_BUFLEN 4096 |
528 | 528 | ||
529 | struct option_port_private { | 529 | struct option_port_private { |
530 | /* Input endpoints and buffer for this port */ | 530 | /* Input endpoints and buffer for this port */ |
@@ -654,10 +654,6 @@ static int option_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
654 | usb_unlink_urb(this_urb); | 654 | usb_unlink_urb(this_urb); |
655 | continue; | 655 | continue; |
656 | } | 656 | } |
657 | if (this_urb->status != 0) | ||
658 | dbg("usb_write %p failed (err=%d)", | ||
659 | this_urb, this_urb->status); | ||
660 | |||
661 | dbg("%s: endpoint %d buf %d", __func__, | 657 | dbg("%s: endpoint %d buf %d", __func__, |
662 | usb_pipeendpoint(this_urb->pipe), i); | 658 | usb_pipeendpoint(this_urb->pipe), i); |
663 | 659 | ||
@@ -669,8 +665,7 @@ static int option_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
669 | err = usb_submit_urb(this_urb, GFP_ATOMIC); | 665 | err = usb_submit_urb(this_urb, GFP_ATOMIC); |
670 | if (err) { | 666 | if (err) { |
671 | dbg("usb_submit_urb %p (write bulk) failed " | 667 | dbg("usb_submit_urb %p (write bulk) failed " |
672 | "(%d, has %d)", this_urb, | 668 | "(%d)", this_urb, err); |
673 | err, this_urb->status); | ||
674 | clear_bit(i, &portdata->out_busy); | 669 | clear_bit(i, &portdata->out_busy); |
675 | continue; | 670 | continue; |
676 | } | 671 | } |
diff --git a/drivers/usb/serial/siemens_mpi.c b/drivers/usb/serial/siemens_mpi.c new file mode 100644 index 000000000000..951ea0c6ba77 --- /dev/null +++ b/drivers/usb/serial/siemens_mpi.c | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | * Siemens USB-MPI Serial USB driver | ||
3 | * | ||
4 | * Copyright (C) 2005 Thomas Hergenhahn <thomas.hergenhahn@suse.de> | ||
5 | * Copyright (C) 2005,2008 Greg Kroah-Hartman <gregkh@suse.de> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License version | ||
9 | * 2 as published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/tty.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/usb.h> | ||
17 | #include <linux/usb/serial.h> | ||
18 | |||
19 | /* Version Information */ | ||
20 | #define DRIVER_VERSION "Version 0.1 09/26/2005" | ||
21 | #define DRIVER_AUTHOR "Thomas Hergenhahn@web.de http://libnodave.sf.net" | ||
22 | #define DRIVER_DESC "Driver for Siemens USB/MPI adapter" | ||
23 | |||
24 | |||
25 | static struct usb_device_id id_table[] = { | ||
26 | /* Vendor and product id for 6ES7-972-0CB20-0XA0 */ | ||
27 | { USB_DEVICE(0x908, 0x0004) }, | ||
28 | { }, | ||
29 | }; | ||
30 | MODULE_DEVICE_TABLE(usb, id_table); | ||
31 | |||
32 | static struct usb_driver siemens_usb_mpi_driver = { | ||
33 | .name = "siemens_mpi", | ||
34 | .probe = usb_serial_probe, | ||
35 | .disconnect = usb_serial_disconnect, | ||
36 | .id_table = id_table, | ||
37 | }; | ||
38 | |||
39 | static struct usb_serial_driver siemens_usb_mpi_device = { | ||
40 | .driver = { | ||
41 | .owner = THIS_MODULE, | ||
42 | .name = "siemens_mpi", | ||
43 | }, | ||
44 | .id_table = id_table, | ||
45 | .num_ports = 1, | ||
46 | }; | ||
47 | |||
48 | static int __init siemens_usb_mpi_init(void) | ||
49 | { | ||
50 | int retval; | ||
51 | |||
52 | retval = usb_serial_register(&siemens_usb_mpi_device); | ||
53 | if (retval) | ||
54 | goto failed_usb_serial_register; | ||
55 | retval = usb_register(&siemens_usb_mpi_driver); | ||
56 | if (retval) | ||
57 | goto failed_usb_register; | ||
58 | printk(KERN_INFO DRIVER_DESC "\n"); | ||
59 | printk(KERN_INFO DRIVER_VERSION " " DRIVER_AUTHOR "\n"); | ||
60 | return retval; | ||
61 | failed_usb_register: | ||
62 | usb_serial_deregister(&siemens_usb_mpi_device); | ||
63 | failed_usb_serial_register: | ||
64 | return retval; | ||
65 | } | ||
66 | |||
67 | static void __exit siemens_usb_mpi_exit(void) | ||
68 | { | ||
69 | usb_deregister(&siemens_usb_mpi_driver); | ||
70 | usb_serial_deregister(&siemens_usb_mpi_device); | ||
71 | } | ||
72 | |||
73 | module_init(siemens_usb_mpi_init); | ||
74 | module_exit(siemens_usb_mpi_exit); | ||
75 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
76 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
77 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c index a65bc2bd8e71..5e7528cc81a8 100644 --- a/drivers/usb/serial/spcp8x5.c +++ b/drivers/usb/serial/spcp8x5.c | |||
@@ -709,21 +709,20 @@ static void spcp8x5_read_bulk_callback(struct urb *urb) | |||
709 | unsigned char *data = urb->transfer_buffer; | 709 | unsigned char *data = urb->transfer_buffer; |
710 | unsigned long flags; | 710 | unsigned long flags; |
711 | int i; | 711 | int i; |
712 | int result; | 712 | int result = urb->status; |
713 | u8 status = 0; | 713 | u8 status; |
714 | char tty_flag; | 714 | char tty_flag; |
715 | 715 | ||
716 | dev_dbg(&port->dev, "start, urb->status = %d, " | 716 | dev_dbg(&port->dev, "start, result = %d, urb->actual_length = %d\n,", |
717 | "urb->actual_length = %d\n,", urb->status, urb->actual_length); | 717 | result, urb->actual_length); |
718 | 718 | ||
719 | /* check the urb status */ | 719 | /* check the urb status */ |
720 | if (urb->status) { | 720 | if (result) { |
721 | if (!port->port.count) | 721 | if (!port->port.count) |
722 | return; | 722 | return; |
723 | if (urb->status == -EPROTO) { | 723 | if (result == -EPROTO) { |
724 | /* spcp8x5 mysteriously fails with -EPROTO */ | 724 | /* spcp8x5 mysteriously fails with -EPROTO */ |
725 | /* reschedule the read */ | 725 | /* reschedule the read */ |
726 | urb->status = 0; | ||
727 | urb->dev = port->serial->dev; | 726 | urb->dev = port->serial->dev; |
728 | result = usb_submit_urb(urb , GFP_ATOMIC); | 727 | result = usb_submit_urb(urb , GFP_ATOMIC); |
729 | if (result) | 728 | if (result) |
@@ -833,8 +832,9 @@ static void spcp8x5_write_bulk_callback(struct urb *urb) | |||
833 | struct usb_serial_port *port = urb->context; | 832 | struct usb_serial_port *port = urb->context; |
834 | struct spcp8x5_private *priv = usb_get_serial_port_data(port); | 833 | struct spcp8x5_private *priv = usb_get_serial_port_data(port); |
835 | int result; | 834 | int result; |
835 | int status = urb->status; | ||
836 | 836 | ||
837 | switch (urb->status) { | 837 | switch (status) { |
838 | case 0: | 838 | case 0: |
839 | /* success */ | 839 | /* success */ |
840 | break; | 840 | break; |
@@ -843,14 +843,14 @@ static void spcp8x5_write_bulk_callback(struct urb *urb) | |||
843 | case -ESHUTDOWN: | 843 | case -ESHUTDOWN: |
844 | /* this urb is terminated, clean up */ | 844 | /* this urb is terminated, clean up */ |
845 | dev_dbg(&port->dev, "urb shutting down with status: %d\n", | 845 | dev_dbg(&port->dev, "urb shutting down with status: %d\n", |
846 | urb->status); | 846 | status); |
847 | priv->write_urb_in_use = 0; | 847 | priv->write_urb_in_use = 0; |
848 | return; | 848 | return; |
849 | default: | 849 | default: |
850 | /* error in the urb, so we have to resubmit it */ | 850 | /* error in the urb, so we have to resubmit it */ |
851 | dbg("%s - Overflow in write", __func__); | 851 | dbg("%s - Overflow in write", __func__); |
852 | dbg("%s - nonzero write bulk status received: %d", | 852 | dbg("%s - nonzero write bulk status received: %d", |
853 | __func__, urb->status); | 853 | __func__, status); |
854 | port->write_urb->transfer_buffer_length = 1; | 854 | port->write_urb->transfer_buffer_length = 1; |
855 | port->write_urb->dev = port->serial->dev; | 855 | port->write_urb->dev = port->serial->dev; |
856 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | 856 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index 01d0c70d60e9..3cf41df302d7 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c | |||
@@ -145,7 +145,7 @@ static int ti_command_in_sync(struct ti_device *tdev, __u8 command, | |||
145 | static int ti_write_byte(struct ti_device *tdev, unsigned long addr, | 145 | static int ti_write_byte(struct ti_device *tdev, unsigned long addr, |
146 | __u8 mask, __u8 byte); | 146 | __u8 mask, __u8 byte); |
147 | 147 | ||
148 | static int ti_download_firmware(struct ti_device *tdev, int type); | 148 | static int ti_download_firmware(struct ti_device *tdev); |
149 | 149 | ||
150 | /* circular buffer */ | 150 | /* circular buffer */ |
151 | static struct circ_buf *ti_buf_alloc(void); | 151 | static struct circ_buf *ti_buf_alloc(void); |
@@ -176,9 +176,14 @@ static unsigned int product_5052_count; | |||
176 | /* the array dimension is the number of default entries plus */ | 176 | /* the array dimension is the number of default entries plus */ |
177 | /* TI_EXTRA_VID_PID_COUNT user defined entries plus 1 terminating */ | 177 | /* TI_EXTRA_VID_PID_COUNT user defined entries plus 1 terminating */ |
178 | /* null entry */ | 178 | /* null entry */ |
179 | static struct usb_device_id ti_id_table_3410[1+TI_EXTRA_VID_PID_COUNT+1] = { | 179 | static struct usb_device_id ti_id_table_3410[7+TI_EXTRA_VID_PID_COUNT+1] = { |
180 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, | 180 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, |
181 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, | 181 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, |
182 | { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) }, | ||
183 | { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_NO_FW_PRODUCT_ID) }, | ||
184 | { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_PRODUCT_ID) }, | ||
185 | { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_PRODUCT_ID) }, | ||
186 | { USB_DEVICE(MTS_VENDOR_ID, MTS_EDGE_PRODUCT_ID) }, | ||
182 | }; | 187 | }; |
183 | 188 | ||
184 | static struct usb_device_id ti_id_table_5052[4+TI_EXTRA_VID_PID_COUNT+1] = { | 189 | static struct usb_device_id ti_id_table_5052[4+TI_EXTRA_VID_PID_COUNT+1] = { |
@@ -188,9 +193,14 @@ static struct usb_device_id ti_id_table_5052[4+TI_EXTRA_VID_PID_COUNT+1] = { | |||
188 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_FIRMWARE_PRODUCT_ID) }, | 193 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_FIRMWARE_PRODUCT_ID) }, |
189 | }; | 194 | }; |
190 | 195 | ||
191 | static struct usb_device_id ti_id_table_combined[] = { | 196 | static struct usb_device_id ti_id_table_combined[6+2*TI_EXTRA_VID_PID_COUNT+1] = { |
192 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, | 197 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, |
193 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, | 198 | { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, |
199 | { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) }, | ||
200 | { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_NO_FW_PRODUCT_ID) }, | ||
201 | { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_PRODUCT_ID) }, | ||
202 | { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_PRODUCT_ID) }, | ||
203 | { USB_DEVICE(MTS_VENDOR_ID, MTS_EDGE_PRODUCT_ID) }, | ||
194 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_BOOT_PRODUCT_ID) }, | 204 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_BOOT_PRODUCT_ID) }, |
195 | { USB_DEVICE(TI_VENDOR_ID, TI_5152_BOOT_PRODUCT_ID) }, | 205 | { USB_DEVICE(TI_VENDOR_ID, TI_5152_BOOT_PRODUCT_ID) }, |
196 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_EEPROM_PRODUCT_ID) }, | 206 | { USB_DEVICE(TI_VENDOR_ID, TI_5052_EEPROM_PRODUCT_ID) }, |
@@ -272,6 +282,9 @@ MODULE_LICENSE("GPL"); | |||
272 | 282 | ||
273 | MODULE_FIRMWARE("ti_3410.fw"); | 283 | MODULE_FIRMWARE("ti_3410.fw"); |
274 | MODULE_FIRMWARE("ti_5052.fw"); | 284 | MODULE_FIRMWARE("ti_5052.fw"); |
285 | MODULE_FIRMWARE("mts_cdma.fw"); | ||
286 | MODULE_FIRMWARE("mts_gsm.fw"); | ||
287 | MODULE_FIRMWARE("mts_edge.fw"); | ||
275 | 288 | ||
276 | module_param(debug, bool, S_IRUGO | S_IWUSR); | 289 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
277 | MODULE_PARM_DESC(debug, "Enable debugging, 0=no, 1=yes"); | 290 | MODULE_PARM_DESC(debug, "Enable debugging, 0=no, 1=yes"); |
@@ -304,21 +317,28 @@ MODULE_DEVICE_TABLE(usb, ti_id_table_combined); | |||
304 | 317 | ||
305 | static int __init ti_init(void) | 318 | static int __init ti_init(void) |
306 | { | 319 | { |
307 | int i, j; | 320 | int i, j, c; |
308 | int ret; | 321 | int ret; |
309 | 322 | ||
310 | /* insert extra vendor and product ids */ | 323 | /* insert extra vendor and product ids */ |
324 | c = ARRAY_SIZE(ti_id_table_combined) - 2 * TI_EXTRA_VID_PID_COUNT - 1; | ||
311 | j = ARRAY_SIZE(ti_id_table_3410) - TI_EXTRA_VID_PID_COUNT - 1; | 325 | j = ARRAY_SIZE(ti_id_table_3410) - TI_EXTRA_VID_PID_COUNT - 1; |
312 | for (i = 0; i < min(vendor_3410_count, product_3410_count); i++, j++) { | 326 | for (i = 0; i < min(vendor_3410_count, product_3410_count); i++, j++, c++) { |
313 | ti_id_table_3410[j].idVendor = vendor_3410[i]; | 327 | ti_id_table_3410[j].idVendor = vendor_3410[i]; |
314 | ti_id_table_3410[j].idProduct = product_3410[i]; | 328 | ti_id_table_3410[j].idProduct = product_3410[i]; |
315 | ti_id_table_3410[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE; | 329 | ti_id_table_3410[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE; |
330 | ti_id_table_combined[c].idVendor = vendor_3410[i]; | ||
331 | ti_id_table_combined[c].idProduct = product_3410[i]; | ||
332 | ti_id_table_combined[c].match_flags = USB_DEVICE_ID_MATCH_DEVICE; | ||
316 | } | 333 | } |
317 | j = ARRAY_SIZE(ti_id_table_5052) - TI_EXTRA_VID_PID_COUNT - 1; | 334 | j = ARRAY_SIZE(ti_id_table_5052) - TI_EXTRA_VID_PID_COUNT - 1; |
318 | for (i = 0; i < min(vendor_5052_count, product_5052_count); i++, j++) { | 335 | for (i = 0; i < min(vendor_5052_count, product_5052_count); i++, j++, c++) { |
319 | ti_id_table_5052[j].idVendor = vendor_5052[i]; | 336 | ti_id_table_5052[j].idVendor = vendor_5052[i]; |
320 | ti_id_table_5052[j].idProduct = product_5052[i]; | 337 | ti_id_table_5052[j].idProduct = product_5052[i]; |
321 | ti_id_table_5052[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE; | 338 | ti_id_table_5052[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE; |
339 | ti_id_table_combined[c].idVendor = vendor_5052[i]; | ||
340 | ti_id_table_combined[c].idProduct = product_5052[i]; | ||
341 | ti_id_table_combined[c].match_flags = USB_DEVICE_ID_MATCH_DEVICE; | ||
322 | } | 342 | } |
323 | 343 | ||
324 | ret = usb_serial_register(&ti_1port_device); | 344 | ret = usb_serial_register(&ti_1port_device); |
@@ -390,11 +410,7 @@ static int ti_startup(struct usb_serial *serial) | |||
390 | 410 | ||
391 | /* if we have only 1 configuration, download firmware */ | 411 | /* if we have only 1 configuration, download firmware */ |
392 | if (dev->descriptor.bNumConfigurations == 1) { | 412 | if (dev->descriptor.bNumConfigurations == 1) { |
393 | if (tdev->td_is_3410) | 413 | if ((status = ti_download_firmware(tdev)) != 0) |
394 | status = ti_download_firmware(tdev, 3410); | ||
395 | else | ||
396 | status = ti_download_firmware(tdev, 5052); | ||
397 | if (status) | ||
398 | goto free_tdev; | 414 | goto free_tdev; |
399 | 415 | ||
400 | /* 3410 must be reset, 5052 resets itself */ | 416 | /* 3410 must be reset, 5052 resets itself */ |
@@ -1671,9 +1687,9 @@ static int ti_do_download(struct usb_device *dev, int pipe, | |||
1671 | return status; | 1687 | return status; |
1672 | } | 1688 | } |
1673 | 1689 | ||
1674 | static int ti_download_firmware(struct ti_device *tdev, int type) | 1690 | static int ti_download_firmware(struct ti_device *tdev) |
1675 | { | 1691 | { |
1676 | int status = -ENOMEM; | 1692 | int status; |
1677 | int buffer_size; | 1693 | int buffer_size; |
1678 | __u8 *buffer; | 1694 | __u8 *buffer; |
1679 | struct usb_device *dev = tdev->td_serial->dev; | 1695 | struct usb_device *dev = tdev->td_serial->dev; |
@@ -1681,9 +1697,34 @@ static int ti_download_firmware(struct ti_device *tdev, int type) | |||
1681 | tdev->td_serial->port[0]->bulk_out_endpointAddress); | 1697 | tdev->td_serial->port[0]->bulk_out_endpointAddress); |
1682 | const struct firmware *fw_p; | 1698 | const struct firmware *fw_p; |
1683 | char buf[32]; | 1699 | char buf[32]; |
1684 | sprintf(buf, "ti_usb-%d.bin", type); | ||
1685 | 1700 | ||
1686 | if (request_firmware(&fw_p, buf, &dev->dev)) { | 1701 | /* try ID specific firmware first, then try generic firmware */ |
1702 | sprintf(buf, "ti_usb-v%04x-p%04x.fw", dev->descriptor.idVendor, | ||
1703 | dev->descriptor.idProduct); | ||
1704 | if ((status = request_firmware(&fw_p, buf, &dev->dev)) != 0) { | ||
1705 | buf[0] = '\0'; | ||
1706 | if (dev->descriptor.idVendor == MTS_VENDOR_ID) { | ||
1707 | switch (dev->descriptor.idProduct) { | ||
1708 | case MTS_CDMA_PRODUCT_ID: | ||
1709 | strcpy(buf, "mts_cdma.fw"); | ||
1710 | break; | ||
1711 | case MTS_GSM_PRODUCT_ID: | ||
1712 | strcpy(buf, "mts_gsm.fw"); | ||
1713 | break; | ||
1714 | case MTS_EDGE_PRODUCT_ID: | ||
1715 | strcpy(buf, "mts_edge.fw"); | ||
1716 | break; | ||
1717 | } | ||
1718 | } | ||
1719 | if (buf[0] == '\0') { | ||
1720 | if (tdev->td_is_3410) | ||
1721 | strcpy(buf, "ti_3410.fw"); | ||
1722 | else | ||
1723 | strcpy(buf, "ti_5052.fw"); | ||
1724 | } | ||
1725 | status = request_firmware(&fw_p, buf, &dev->dev); | ||
1726 | } | ||
1727 | if (status) { | ||
1687 | dev_err(&dev->dev, "%s - firmware not found\n", __func__); | 1728 | dev_err(&dev->dev, "%s - firmware not found\n", __func__); |
1688 | return -ENOENT; | 1729 | return -ENOENT; |
1689 | } | 1730 | } |
@@ -1699,6 +1740,8 @@ static int ti_download_firmware(struct ti_device *tdev, int type) | |||
1699 | memset(buffer + fw_p->size, 0xff, buffer_size - fw_p->size); | 1740 | memset(buffer + fw_p->size, 0xff, buffer_size - fw_p->size); |
1700 | status = ti_do_download(dev, pipe, buffer, fw_p->size); | 1741 | status = ti_do_download(dev, pipe, buffer, fw_p->size); |
1701 | kfree(buffer); | 1742 | kfree(buffer); |
1743 | } else { | ||
1744 | status = -ENOMEM; | ||
1702 | } | 1745 | } |
1703 | release_firmware(fw_p); | 1746 | release_firmware(fw_p); |
1704 | if (status) { | 1747 | if (status) { |
diff --git a/drivers/usb/serial/ti_usb_3410_5052.h b/drivers/usb/serial/ti_usb_3410_5052.h index b5541bf991ba..7e4752fbf232 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.h +++ b/drivers/usb/serial/ti_usb_3410_5052.h | |||
@@ -34,6 +34,14 @@ | |||
34 | #define TI_5052_EEPROM_PRODUCT_ID 0x505A /* EEPROM, no firmware */ | 34 | #define TI_5052_EEPROM_PRODUCT_ID 0x505A /* EEPROM, no firmware */ |
35 | #define TI_5052_FIRMWARE_PRODUCT_ID 0x505F /* firmware is running */ | 35 | #define TI_5052_FIRMWARE_PRODUCT_ID 0x505F /* firmware is running */ |
36 | 36 | ||
37 | /* Multi-Tech vendor and product ids */ | ||
38 | #define MTS_VENDOR_ID 0x06E0 | ||
39 | #define MTS_GSM_NO_FW_PRODUCT_ID 0xF108 | ||
40 | #define MTS_CDMA_NO_FW_PRODUCT_ID 0xF109 | ||
41 | #define MTS_CDMA_PRODUCT_ID 0xF110 | ||
42 | #define MTS_GSM_PRODUCT_ID 0xF111 | ||
43 | #define MTS_EDGE_PRODUCT_ID 0xF112 | ||
44 | |||
37 | /* Commands */ | 45 | /* Commands */ |
38 | #define TI_GET_VERSION 0x01 | 46 | #define TI_GET_VERSION 0x01 |
39 | #define TI_GET_PORT_STATUS 0x02 | 47 | #define TI_GET_PORT_STATUS 0x02 |
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 080ade223d53..cfcfd5ab06ce 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -511,9 +511,6 @@ static void usb_serial_port_work(struct work_struct *work) | |||
511 | 511 | ||
512 | dbg("%s - port %d", __func__, port->number); | 512 | dbg("%s - port %d", __func__, port->number); |
513 | 513 | ||
514 | if (!port) | ||
515 | return; | ||
516 | |||
517 | tty = tty_port_tty_get(&port->port); | 514 | tty = tty_port_tty_get(&port->port); |
518 | if (!tty) | 515 | if (!tty) |
519 | return; | 516 | return; |
diff --git a/drivers/usb/serial/usb_debug.c b/drivers/usb/serial/usb_debug.c index fc5d9952b03b..6c9cbb59552a 100644 --- a/drivers/usb/serial/usb_debug.c +++ b/drivers/usb/serial/usb_debug.c | |||
@@ -31,7 +31,7 @@ static struct usb_driver debug_driver = { | |||
31 | .no_dynamic_id = 1, | 31 | .no_dynamic_id = 1, |
32 | }; | 32 | }; |
33 | 33 | ||
34 | int usb_debug_open(struct tty_struct *tty, struct usb_serial_port *port, | 34 | static int usb_debug_open(struct tty_struct *tty, struct usb_serial_port *port, |
35 | struct file *filp) | 35 | struct file *filp) |
36 | { | 36 | { |
37 | port->bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE; | 37 | port->bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE; |
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig index c68b738900bd..9df6887b91f6 100644 --- a/drivers/usb/storage/Kconfig +++ b/drivers/usb/storage/Kconfig | |||
@@ -61,13 +61,6 @@ config USB_STORAGE_ISD200 | |||
61 | - CyQ've CQ8060A CDRW drive | 61 | - CyQ've CQ8060A CDRW drive |
62 | - Planex eXtreme Drive RX-25HU USB-IDE cable (not model RX-25U) | 62 | - Planex eXtreme Drive RX-25HU USB-IDE cable (not model RX-25U) |
63 | 63 | ||
64 | config USB_STORAGE_DPCM | ||
65 | bool "Microtech/ZiO! CompactFlash/SmartMedia support" | ||
66 | depends on USB_STORAGE | ||
67 | help | ||
68 | Say Y here to support the Microtech/ZiO! CompactFlash reader. | ||
69 | There is a web page at <http://www.ziocorp.com/products/>. | ||
70 | |||
71 | config USB_STORAGE_USBAT | 64 | config USB_STORAGE_USBAT |
72 | bool "USBAT/USBAT02-based storage support" | 65 | bool "USBAT/USBAT02-based storage support" |
73 | depends on USB_STORAGE | 66 | depends on USB_STORAGE |
@@ -90,12 +83,12 @@ config USB_STORAGE_USBAT | |||
90 | - Sandisk ImageMate SDDR-05b | 83 | - Sandisk ImageMate SDDR-05b |
91 | 84 | ||
92 | config USB_STORAGE_SDDR09 | 85 | config USB_STORAGE_SDDR09 |
93 | bool "SanDisk SDDR-09 (and other SmartMedia) support" | 86 | bool "SanDisk SDDR-09 (and other SmartMedia, including DPCM) support" |
94 | depends on USB_STORAGE | 87 | depends on USB_STORAGE |
95 | help | 88 | help |
96 | Say Y here to include additional code to support the Sandisk SDDR-09 | 89 | Say Y here to include additional code to support the Sandisk SDDR-09 |
97 | SmartMedia reader in the USB Mass Storage driver. | 90 | SmartMedia reader in the USB Mass Storage driver. |
98 | Also works for the Microtech Zio! SmartMedia reader. | 91 | Also works for the Microtech Zio! CompactFlash/SmartMedia reader. |
99 | 92 | ||
100 | config USB_STORAGE_SDDR55 | 93 | config USB_STORAGE_SDDR55 |
101 | bool "SanDisk SDDR-55 SmartMedia support" | 94 | bool "SanDisk SDDR-55 SmartMedia support" |
diff --git a/drivers/usb/storage/Makefile b/drivers/usb/storage/Makefile index 7f8beb5366ae..b32069313390 100644 --- a/drivers/usb/storage/Makefile +++ b/drivers/usb/storage/Makefile | |||
@@ -14,7 +14,6 @@ usb-storage-obj-$(CONFIG_USB_STORAGE_USBAT) += shuttle_usbat.o | |||
14 | usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR09) += sddr09.o | 14 | usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR09) += sddr09.o |
15 | usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR55) += sddr55.o | 15 | usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR55) += sddr55.o |
16 | usb-storage-obj-$(CONFIG_USB_STORAGE_FREECOM) += freecom.o | 16 | usb-storage-obj-$(CONFIG_USB_STORAGE_FREECOM) += freecom.o |
17 | usb-storage-obj-$(CONFIG_USB_STORAGE_DPCM) += dpcm.o | ||
18 | usb-storage-obj-$(CONFIG_USB_STORAGE_ISD200) += isd200.o | 17 | usb-storage-obj-$(CONFIG_USB_STORAGE_ISD200) += isd200.o |
19 | usb-storage-obj-$(CONFIG_USB_STORAGE_DATAFAB) += datafab.o | 18 | usb-storage-obj-$(CONFIG_USB_STORAGE_DATAFAB) += datafab.o |
20 | usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o | 19 | usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o |
@@ -24,7 +23,7 @@ usb-storage-obj-$(CONFIG_USB_STORAGE_KARMA) += karma.o | |||
24 | usb-storage-obj-$(CONFIG_USB_STORAGE_CYPRESS_ATACB) += cypress_atacb.o | 23 | usb-storage-obj-$(CONFIG_USB_STORAGE_CYPRESS_ATACB) += cypress_atacb.o |
25 | 24 | ||
26 | usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \ | 25 | usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \ |
27 | initializers.o sierra_ms.o $(usb-storage-obj-y) | 26 | initializers.o sierra_ms.o option_ms.o $(usb-storage-obj-y) |
28 | 27 | ||
29 | ifneq ($(CONFIG_USB_LIBUSUAL),) | 28 | ifneq ($(CONFIG_USB_LIBUSUAL),) |
30 | obj-$(CONFIG_USB) += libusual.o | 29 | obj-$(CONFIG_USB) += libusual.o |
diff --git a/drivers/usb/storage/dpcm.c b/drivers/usb/storage/dpcm.c deleted file mode 100644 index 939923471af4..000000000000 --- a/drivers/usb/storage/dpcm.c +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | /* Driver for Microtech DPCM-USB CompactFlash/SmartMedia reader | ||
2 | * | ||
3 | * DPCM driver v0.1: | ||
4 | * | ||
5 | * First release | ||
6 | * | ||
7 | * Current development and maintenance by: | ||
8 | * (c) 2000 Brian Webb (webbb@earthlink.net) | ||
9 | * | ||
10 | * This device contains both a CompactFlash card reader, which | ||
11 | * uses the Control/Bulk w/o Interrupt protocol and | ||
12 | * a SmartMedia card reader that uses the same protocol | ||
13 | * as the SDDR09. | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or modify it | ||
16 | * under the terms of the GNU General Public License as published by the | ||
17 | * Free Software Foundation; either version 2, or (at your option) any | ||
18 | * later version. | ||
19 | * | ||
20 | * This program is distributed in the hope that it will be useful, but | ||
21 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
23 | * General Public License for more details. | ||
24 | * | ||
25 | * You should have received a copy of the GNU General Public License along | ||
26 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
27 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
28 | */ | ||
29 | |||
30 | #include <scsi/scsi.h> | ||
31 | #include <scsi/scsi_cmnd.h> | ||
32 | #include <scsi/scsi_device.h> | ||
33 | |||
34 | #include "usb.h" | ||
35 | #include "transport.h" | ||
36 | #include "protocol.h" | ||
37 | #include "debug.h" | ||
38 | #include "dpcm.h" | ||
39 | #include "sddr09.h" | ||
40 | |||
41 | /* | ||
42 | * Transport for the Microtech DPCM-USB | ||
43 | * | ||
44 | */ | ||
45 | int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us) | ||
46 | { | ||
47 | int ret; | ||
48 | |||
49 | if (srb == NULL) | ||
50 | return USB_STOR_TRANSPORT_ERROR; | ||
51 | |||
52 | US_DEBUGP("dpcm_transport: LUN=%d\n", srb->device->lun); | ||
53 | |||
54 | switch (srb->device->lun) { | ||
55 | case 0: | ||
56 | |||
57 | /* | ||
58 | * LUN 0 corresponds to the CompactFlash card reader. | ||
59 | */ | ||
60 | ret = usb_stor_CB_transport(srb, us); | ||
61 | break; | ||
62 | |||
63 | #ifdef CONFIG_USB_STORAGE_SDDR09 | ||
64 | case 1: | ||
65 | |||
66 | /* | ||
67 | * LUN 1 corresponds to the SmartMedia card reader. | ||
68 | */ | ||
69 | |||
70 | /* | ||
71 | * Set the LUN to 0 (just in case). | ||
72 | */ | ||
73 | srb->device->lun = 0; us->srb->device->lun = 0; | ||
74 | ret = sddr09_transport(srb, us); | ||
75 | srb->device->lun = 1; us->srb->device->lun = 1; | ||
76 | break; | ||
77 | |||
78 | #endif | ||
79 | |||
80 | default: | ||
81 | US_DEBUGP("dpcm_transport: Invalid LUN %d\n", srb->device->lun); | ||
82 | ret = USB_STOR_TRANSPORT_ERROR; | ||
83 | break; | ||
84 | } | ||
85 | return ret; | ||
86 | } | ||
diff --git a/drivers/usb/storage/dpcm.h b/drivers/usb/storage/dpcm.h deleted file mode 100644 index e7b7b0f120d7..000000000000 --- a/drivers/usb/storage/dpcm.h +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | /* Driver for Microtech DPCM-USB CompactFlash/SmartMedia reader | ||
2 | * | ||
3 | * DPCM driver v0.1: | ||
4 | * | ||
5 | * First release | ||
6 | * | ||
7 | * Current development and maintenance by: | ||
8 | * (c) 2000 Brian Webb (webbb@earthlink.net) | ||
9 | * | ||
10 | * See dpcm.c for more explanation | ||
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, or (at your option) any | ||
15 | * later version. | ||
16 | * | ||
17 | * This program is distributed in the hope that it will be useful, but | ||
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
20 | * General Public License for more details. | ||
21 | * | ||
22 | * You should have received a copy of the GNU General Public License along | ||
23 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
24 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
25 | */ | ||
26 | |||
27 | #ifndef _MICROTECH_DPCM_USB_H | ||
28 | #define _MICROTECH_DPCM_USB_H | ||
29 | |||
30 | extern int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us); | ||
31 | |||
32 | #endif | ||
diff --git a/drivers/usb/storage/libusual.c b/drivers/usb/storage/libusual.c index d617e8ae6b00..f970b27ba308 100644 --- a/drivers/usb/storage/libusual.c +++ b/drivers/usb/storage/libusual.c | |||
@@ -46,6 +46,12 @@ static int usu_probe_thread(void *arg); | |||
46 | { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax), \ | 46 | { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax), \ |
47 | .driver_info = (flags)|(USB_US_TYPE_STOR<<24) } | 47 | .driver_info = (flags)|(USB_US_TYPE_STOR<<24) } |
48 | 48 | ||
49 | #define COMPLIANT_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \ | ||
50 | vendorName, productName, useProtocol, useTransport, \ | ||
51 | initFunction, flags) \ | ||
52 | { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ | ||
53 | .driver_info = (flags) } | ||
54 | |||
49 | #define USUAL_DEV(useProto, useTrans, useType) \ | 55 | #define USUAL_DEV(useProto, useTrans, useType) \ |
50 | { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans), \ | 56 | { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans), \ |
51 | .driver_info = ((useType)<<24) } | 57 | .driver_info = ((useType)<<24) } |
@@ -57,6 +63,7 @@ struct usb_device_id storage_usb_ids [] = { | |||
57 | 63 | ||
58 | #undef USUAL_DEV | 64 | #undef USUAL_DEV |
59 | #undef UNUSUAL_DEV | 65 | #undef UNUSUAL_DEV |
66 | #undef COMPLIANT_DEV | ||
60 | 67 | ||
61 | MODULE_DEVICE_TABLE(usb, storage_usb_ids); | 68 | MODULE_DEVICE_TABLE(usb, storage_usb_ids); |
62 | EXPORT_SYMBOL_GPL(storage_usb_ids); | 69 | EXPORT_SYMBOL_GPL(storage_usb_ids); |
diff --git a/drivers/usb/storage/option_ms.c b/drivers/usb/storage/option_ms.c new file mode 100644 index 000000000000..353f922939a4 --- /dev/null +++ b/drivers/usb/storage/option_ms.c | |||
@@ -0,0 +1,147 @@ | |||
1 | /* | ||
2 | * Driver for Option High Speed Mobile Devices. | ||
3 | * | ||
4 | * (c) 2008 Dan Williams <dcbw@redhat.com> | ||
5 | * | ||
6 | * Inspiration taken from sierra_ms.c by Kevin Lloyd <klloyd@sierrawireless.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 as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, but | ||
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License along | ||
19 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
20 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | */ | ||
22 | |||
23 | #include <linux/usb.h> | ||
24 | |||
25 | #include "usb.h" | ||
26 | #include "transport.h" | ||
27 | #include "option_ms.h" | ||
28 | #include "debug.h" | ||
29 | |||
30 | #define ZCD_FORCE_MODEM 0x01 | ||
31 | #define ZCD_ALLOW_MS 0x02 | ||
32 | |||
33 | static unsigned int option_zero_cd = ZCD_FORCE_MODEM; | ||
34 | module_param(option_zero_cd, uint, S_IRUGO | S_IWUSR); | ||
35 | MODULE_PARM_DESC(option_zero_cd, "ZeroCD mode (1=Force Modem (default)," | ||
36 | " 2=Allow CD-Rom"); | ||
37 | |||
38 | #define RESPONSE_LEN 1024 | ||
39 | |||
40 | static int option_rezero(struct us_data *us, int ep_in, int ep_out) | ||
41 | { | ||
42 | const unsigned char rezero_msg[] = { | ||
43 | 0x55, 0x53, 0x42, 0x43, 0x78, 0x56, 0x34, 0x12, | ||
44 | 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x06, 0x01, | ||
45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
47 | }; | ||
48 | char *buffer; | ||
49 | int result; | ||
50 | |||
51 | US_DEBUGP("Option MS: %s", "DEVICE MODE SWITCH\n"); | ||
52 | |||
53 | buffer = kzalloc(RESPONSE_LEN, GFP_KERNEL); | ||
54 | if (buffer == NULL) | ||
55 | return USB_STOR_TRANSPORT_ERROR; | ||
56 | |||
57 | memcpy(buffer, rezero_msg, sizeof (rezero_msg)); | ||
58 | result = usb_stor_bulk_transfer_buf(us, | ||
59 | usb_sndbulkpipe(us->pusb_dev, ep_out), | ||
60 | buffer, sizeof (rezero_msg), NULL); | ||
61 | if (result != USB_STOR_XFER_GOOD) { | ||
62 | result = USB_STOR_XFER_ERROR; | ||
63 | goto out; | ||
64 | } | ||
65 | |||
66 | /* Some of the devices need to be asked for a response, but we don't | ||
67 | * care what that response is. | ||
68 | */ | ||
69 | result = usb_stor_bulk_transfer_buf(us, | ||
70 | usb_sndbulkpipe(us->pusb_dev, ep_out), | ||
71 | buffer, RESPONSE_LEN, NULL); | ||
72 | result = USB_STOR_XFER_GOOD; | ||
73 | |||
74 | out: | ||
75 | kfree(buffer); | ||
76 | return result; | ||
77 | } | ||
78 | |||
79 | int option_ms_init(struct us_data *us) | ||
80 | { | ||
81 | struct usb_device *udev; | ||
82 | struct usb_interface *intf; | ||
83 | struct usb_host_interface *iface_desc; | ||
84 | struct usb_endpoint_descriptor *endpoint = NULL; | ||
85 | u8 ep_in = 0, ep_out = 0; | ||
86 | int ep_in_size = 0, ep_out_size = 0; | ||
87 | int i, result; | ||
88 | |||
89 | udev = us->pusb_dev; | ||
90 | intf = us->pusb_intf; | ||
91 | |||
92 | /* Ensure it's really a ZeroCD device; devices that are already | ||
93 | * in modem mode return 0xFF for class, subclass, and protocol. | ||
94 | */ | ||
95 | if (udev->descriptor.bDeviceClass != 0 || | ||
96 | udev->descriptor.bDeviceSubClass != 0 || | ||
97 | udev->descriptor.bDeviceProtocol != 0) | ||
98 | return USB_STOR_TRANSPORT_GOOD; | ||
99 | |||
100 | US_DEBUGP("Option MS: option_ms_init called\n"); | ||
101 | |||
102 | /* Find the right mass storage interface */ | ||
103 | iface_desc = intf->cur_altsetting; | ||
104 | if (iface_desc->desc.bInterfaceClass != 0x8 || | ||
105 | iface_desc->desc.bInterfaceSubClass != 0x6 || | ||
106 | iface_desc->desc.bInterfaceProtocol != 0x50) { | ||
107 | US_DEBUGP("Option MS: mass storage interface not found, no action " | ||
108 | "required\n"); | ||
109 | return USB_STOR_TRANSPORT_GOOD; | ||
110 | } | ||
111 | |||
112 | /* Find the mass storage bulk endpoints */ | ||
113 | for (i = 0; i < iface_desc->desc.bNumEndpoints && (!ep_in_size || !ep_out_size); ++i) { | ||
114 | endpoint = &iface_desc->endpoint[i].desc; | ||
115 | |||
116 | if (usb_endpoint_is_bulk_in(endpoint)) { | ||
117 | ep_in = usb_endpoint_num(endpoint); | ||
118 | ep_in_size = le16_to_cpu(endpoint->wMaxPacketSize); | ||
119 | } else if (usb_endpoint_is_bulk_out(endpoint)) { | ||
120 | ep_out = usb_endpoint_num(endpoint); | ||
121 | ep_out_size = le16_to_cpu(endpoint->wMaxPacketSize); | ||
122 | } | ||
123 | } | ||
124 | |||
125 | /* Can't find the mass storage endpoints */ | ||
126 | if (!ep_in_size || !ep_out_size) { | ||
127 | US_DEBUGP("Option MS: mass storage endpoints not found, no action " | ||
128 | "required\n"); | ||
129 | return USB_STOR_TRANSPORT_GOOD; | ||
130 | } | ||
131 | |||
132 | /* Force Modem mode */ | ||
133 | if (option_zero_cd == ZCD_FORCE_MODEM) { | ||
134 | US_DEBUGP("Option MS: %s", "Forcing Modem Mode\n"); | ||
135 | result = option_rezero(us, ep_in, ep_out); | ||
136 | if (result != USB_STOR_XFER_GOOD) | ||
137 | US_DEBUGP("Option MS: Failed to switch to modem mode.\n"); | ||
138 | return -EIO; | ||
139 | } else if (option_zero_cd == ZCD_ALLOW_MS) { | ||
140 | /* Allow Mass Storage mode (keep CD-Rom) */ | ||
141 | US_DEBUGP("Option MS: %s", "Allowing Mass Storage Mode if device" | ||
142 | " requests it\n"); | ||
143 | } | ||
144 | |||
145 | return USB_STOR_TRANSPORT_GOOD; | ||
146 | } | ||
147 | |||
diff --git a/drivers/usb/storage/option_ms.h b/drivers/usb/storage/option_ms.h new file mode 100644 index 000000000000..b6e448cab039 --- /dev/null +++ b/drivers/usb/storage/option_ms.h | |||
@@ -0,0 +1,4 @@ | |||
1 | #ifndef _OPTION_MS_H_ | ||
2 | #define _OPTION_MS_H_ | ||
3 | extern int option_ms_init(struct us_data *us); | ||
4 | #endif | ||
diff --git a/drivers/usb/storage/protocol.c b/drivers/usb/storage/protocol.c index 3b3357e20ea7..be441d84bc64 100644 --- a/drivers/usb/storage/protocol.c +++ b/drivers/usb/storage/protocol.c | |||
@@ -56,9 +56,9 @@ | |||
56 | * Protocol routines | 56 | * Protocol routines |
57 | ***********************************************************************/ | 57 | ***********************************************************************/ |
58 | 58 | ||
59 | void usb_stor_qic157_command(struct scsi_cmnd *srb, struct us_data *us) | 59 | void usb_stor_pad12_command(struct scsi_cmnd *srb, struct us_data *us) |
60 | { | 60 | { |
61 | /* Pad the ATAPI command with zeros | 61 | /* Pad the SCSI command with zeros out to 12 bytes |
62 | * | 62 | * |
63 | * NOTE: This only works because a scsi_cmnd struct field contains | 63 | * NOTE: This only works because a scsi_cmnd struct field contains |
64 | * a unsigned char cmnd[16], so we know we have storage available | 64 | * a unsigned char cmnd[16], so we know we have storage available |
@@ -73,26 +73,6 @@ void usb_stor_qic157_command(struct scsi_cmnd *srb, struct us_data *us) | |||
73 | usb_stor_invoke_transport(srb, us); | 73 | usb_stor_invoke_transport(srb, us); |
74 | } | 74 | } |
75 | 75 | ||
76 | void usb_stor_ATAPI_command(struct scsi_cmnd *srb, struct us_data *us) | ||
77 | { | ||
78 | /* Pad the ATAPI command with zeros | ||
79 | * | ||
80 | * NOTE: This only works because a scsi_cmnd struct field contains | ||
81 | * a unsigned char cmnd[16], so we know we have storage available | ||
82 | */ | ||
83 | |||
84 | /* Pad the ATAPI command with zeros */ | ||
85 | for (; srb->cmd_len<12; srb->cmd_len++) | ||
86 | srb->cmnd[srb->cmd_len] = 0; | ||
87 | |||
88 | /* set command length to 12 bytes */ | ||
89 | srb->cmd_len = 12; | ||
90 | |||
91 | /* send the command to the transport layer */ | ||
92 | usb_stor_invoke_transport(srb, us); | ||
93 | } | ||
94 | |||
95 | |||
96 | void usb_stor_ufi_command(struct scsi_cmnd *srb, struct us_data *us) | 76 | void usb_stor_ufi_command(struct scsi_cmnd *srb, struct us_data *us) |
97 | { | 77 | { |
98 | /* fix some commands -- this is a form of mode translation | 78 | /* fix some commands -- this is a form of mode translation |
diff --git a/drivers/usb/storage/protocol.h b/drivers/usb/storage/protocol.h index 487056ffb516..ffc3e2af0156 100644 --- a/drivers/usb/storage/protocol.h +++ b/drivers/usb/storage/protocol.h | |||
@@ -40,8 +40,7 @@ | |||
40 | #define _PROTOCOL_H_ | 40 | #define _PROTOCOL_H_ |
41 | 41 | ||
42 | /* Protocol handling routines */ | 42 | /* Protocol handling routines */ |
43 | extern void usb_stor_ATAPI_command(struct scsi_cmnd*, struct us_data*); | 43 | extern void usb_stor_pad12_command(struct scsi_cmnd*, struct us_data*); |
44 | extern void usb_stor_qic157_command(struct scsi_cmnd*, struct us_data*); | ||
45 | extern void usb_stor_ufi_command(struct scsi_cmnd*, struct us_data*); | 44 | extern void usb_stor_ufi_command(struct scsi_cmnd*, struct us_data*); |
46 | extern void usb_stor_transparent_scsi_command(struct scsi_cmnd*, | 45 | extern void usb_stor_transparent_scsi_command(struct scsi_cmnd*, |
47 | struct us_data*); | 46 | struct us_data*); |
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c index 09779f6a8179..2a42b862aa9f 100644 --- a/drivers/usb/storage/scsiglue.c +++ b/drivers/usb/storage/scsiglue.c | |||
@@ -59,6 +59,13 @@ | |||
59 | #include "transport.h" | 59 | #include "transport.h" |
60 | #include "protocol.h" | 60 | #include "protocol.h" |
61 | 61 | ||
62 | /* Vendor IDs for companies that seem to include the READ CAPACITY bug | ||
63 | * in all their devices | ||
64 | */ | ||
65 | #define VENDOR_ID_NOKIA 0x0421 | ||
66 | #define VENDOR_ID_NIKON 0x04b0 | ||
67 | #define VENDOR_ID_MOTOROLA 0x22b8 | ||
68 | |||
62 | /*********************************************************************** | 69 | /*********************************************************************** |
63 | * Host functions | 70 | * Host functions |
64 | ***********************************************************************/ | 71 | ***********************************************************************/ |
@@ -129,11 +136,35 @@ static int slave_configure(struct scsi_device *sdev) | |||
129 | max_sectors); | 136 | max_sectors); |
130 | } | 137 | } |
131 | 138 | ||
139 | /* Some USB host controllers can't do DMA; they have to use PIO. | ||
140 | * They indicate this by setting their dma_mask to NULL. For | ||
141 | * such controllers we need to make sure the block layer sets | ||
142 | * up bounce buffers in addressable memory. | ||
143 | */ | ||
144 | if (!us->pusb_dev->bus->controller->dma_mask) | ||
145 | blk_queue_bounce_limit(sdev->request_queue, BLK_BOUNCE_HIGH); | ||
146 | |||
132 | /* We can't put these settings in slave_alloc() because that gets | 147 | /* We can't put these settings in slave_alloc() because that gets |
133 | * called before the device type is known. Consequently these | 148 | * called before the device type is known. Consequently these |
134 | * settings can't be overridden via the scsi devinfo mechanism. */ | 149 | * settings can't be overridden via the scsi devinfo mechanism. */ |
135 | if (sdev->type == TYPE_DISK) { | 150 | if (sdev->type == TYPE_DISK) { |
136 | 151 | ||
152 | /* Some vendors seem to put the READ CAPACITY bug into | ||
153 | * all their devices -- primarily makers of cell phones | ||
154 | * and digital cameras. Since these devices always use | ||
155 | * flash media and can be expected to have an even number | ||
156 | * of sectors, we will always enable the CAPACITY_HEURISTICS | ||
157 | * flag unless told otherwise. */ | ||
158 | switch (le16_to_cpu(us->pusb_dev->descriptor.idVendor)) { | ||
159 | case VENDOR_ID_NOKIA: | ||
160 | case VENDOR_ID_NIKON: | ||
161 | case VENDOR_ID_MOTOROLA: | ||
162 | if (!(us->fflags & (US_FL_FIX_CAPACITY | | ||
163 | US_FL_CAPACITY_OK))) | ||
164 | us->fflags |= US_FL_CAPACITY_HEURISTICS; | ||
165 | break; | ||
166 | } | ||
167 | |||
137 | /* Disk-type devices use MODE SENSE(6) if the protocol | 168 | /* Disk-type devices use MODE SENSE(6) if the protocol |
138 | * (SubClass) is Transparent SCSI, otherwise they use | 169 | * (SubClass) is Transparent SCSI, otherwise they use |
139 | * MODE SENSE(10). */ | 170 | * MODE SENSE(10). */ |
@@ -170,6 +201,10 @@ static int slave_configure(struct scsi_device *sdev) | |||
170 | if (us->fflags & US_FL_CAPACITY_HEURISTICS) | 201 | if (us->fflags & US_FL_CAPACITY_HEURISTICS) |
171 | sdev->guess_capacity = 1; | 202 | sdev->guess_capacity = 1; |
172 | 203 | ||
204 | /* assume SPC3 or latter devices support sense size > 18 */ | ||
205 | if (sdev->scsi_level > SCSI_SPC_2) | ||
206 | us->fflags |= US_FL_SANE_SENSE; | ||
207 | |||
173 | /* Some devices report a SCSI revision level above 2 but are | 208 | /* Some devices report a SCSI revision level above 2 but are |
174 | * unable to handle the REPORT LUNS command (for which | 209 | * unable to handle the REPORT LUNS command (for which |
175 | * support is mandatory at level 3). Since we already have | 210 | * support is mandatory at level 3). Since we already have |
@@ -196,6 +231,14 @@ static int slave_configure(struct scsi_device *sdev) | |||
196 | * sector in a larger then 1 sector read, since the performance | 231 | * sector in a larger then 1 sector read, since the performance |
197 | * impact is negible we set this flag for all USB disks */ | 232 | * impact is negible we set this flag for all USB disks */ |
198 | sdev->last_sector_bug = 1; | 233 | sdev->last_sector_bug = 1; |
234 | |||
235 | /* Enable last-sector hacks for single-target devices using | ||
236 | * the Bulk-only transport, unless we already know the | ||
237 | * capacity will be decremented or is correct. */ | ||
238 | if (!(us->fflags & (US_FL_FIX_CAPACITY | US_FL_CAPACITY_OK | | ||
239 | US_FL_SCM_MULT_TARG)) && | ||
240 | us->protocol == US_PR_BULK) | ||
241 | us->use_last_sector_hacks = 1; | ||
199 | } else { | 242 | } else { |
200 | 243 | ||
201 | /* Non-disk-type devices don't need to blacklist any pages | 244 | /* Non-disk-type devices don't need to blacklist any pages |
diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c index c5a54b872c24..531ae5c5abf3 100644 --- a/drivers/usb/storage/sddr09.c +++ b/drivers/usb/storage/sddr09.c | |||
@@ -45,6 +45,7 @@ | |||
45 | 45 | ||
46 | #include <scsi/scsi.h> | 46 | #include <scsi/scsi.h> |
47 | #include <scsi/scsi_cmnd.h> | 47 | #include <scsi/scsi_cmnd.h> |
48 | #include <scsi/scsi_device.h> | ||
48 | 49 | ||
49 | #include "usb.h" | 50 | #include "usb.h" |
50 | #include "transport.h" | 51 | #include "transport.h" |
@@ -1446,6 +1447,48 @@ usb_stor_sddr09_dpcm_init(struct us_data *us) { | |||
1446 | } | 1447 | } |
1447 | 1448 | ||
1448 | /* | 1449 | /* |
1450 | * Transport for the Microtech DPCM-USB | ||
1451 | */ | ||
1452 | int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us) | ||
1453 | { | ||
1454 | int ret; | ||
1455 | |||
1456 | US_DEBUGP("dpcm_transport: LUN=%d\n", srb->device->lun); | ||
1457 | |||
1458 | switch (srb->device->lun) { | ||
1459 | case 0: | ||
1460 | |||
1461 | /* | ||
1462 | * LUN 0 corresponds to the CompactFlash card reader. | ||
1463 | */ | ||
1464 | ret = usb_stor_CB_transport(srb, us); | ||
1465 | break; | ||
1466 | |||
1467 | case 1: | ||
1468 | |||
1469 | /* | ||
1470 | * LUN 1 corresponds to the SmartMedia card reader. | ||
1471 | */ | ||
1472 | |||
1473 | /* | ||
1474 | * Set the LUN to 0 (just in case). | ||
1475 | */ | ||
1476 | srb->device->lun = 0; | ||
1477 | ret = sddr09_transport(srb, us); | ||
1478 | srb->device->lun = 1; | ||
1479 | break; | ||
1480 | |||
1481 | default: | ||
1482 | US_DEBUGP("dpcm_transport: Invalid LUN %d\n", | ||
1483 | srb->device->lun); | ||
1484 | ret = USB_STOR_TRANSPORT_ERROR; | ||
1485 | break; | ||
1486 | } | ||
1487 | return ret; | ||
1488 | } | ||
1489 | |||
1490 | |||
1491 | /* | ||
1449 | * Transport for the Sandisk SDDR-09 | 1492 | * Transport for the Sandisk SDDR-09 |
1450 | */ | 1493 | */ |
1451 | int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us) | 1494 | int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us) |
diff --git a/drivers/usb/storage/sddr09.h b/drivers/usb/storage/sddr09.h index e50033ad7b19..b701172e12e3 100644 --- a/drivers/usb/storage/sddr09.h +++ b/drivers/usb/storage/sddr09.h | |||
@@ -28,8 +28,11 @@ | |||
28 | /* Sandisk SDDR-09 stuff */ | 28 | /* Sandisk SDDR-09 stuff */ |
29 | 29 | ||
30 | extern int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us); | 30 | extern int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us); |
31 | extern int usb_stor_sddr09_init(struct us_data *us); | ||
32 | |||
33 | /* Microtech DPCM-USB stuff */ | ||
31 | 34 | ||
35 | extern int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us); | ||
32 | extern int usb_stor_sddr09_dpcm_init(struct us_data *us); | 36 | extern int usb_stor_sddr09_dpcm_init(struct us_data *us); |
33 | extern int usb_stor_sddr09_init(struct us_data *us); | ||
34 | 37 | ||
35 | #endif | 38 | #endif |
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c index 79108d5d3171..1d5438e6363b 100644 --- a/drivers/usb/storage/transport.c +++ b/drivers/usb/storage/transport.c | |||
@@ -57,6 +57,9 @@ | |||
57 | #include "scsiglue.h" | 57 | #include "scsiglue.h" |
58 | #include "debug.h" | 58 | #include "debug.h" |
59 | 59 | ||
60 | #include <linux/blkdev.h> | ||
61 | #include "../../scsi/sd.h" | ||
62 | |||
60 | 63 | ||
61 | /*********************************************************************** | 64 | /*********************************************************************** |
62 | * Data transfer routines | 65 | * Data transfer routines |
@@ -511,6 +514,110 @@ int usb_stor_bulk_transfer_sg(struct us_data* us, unsigned int pipe, | |||
511 | * Transport routines | 514 | * Transport routines |
512 | ***********************************************************************/ | 515 | ***********************************************************************/ |
513 | 516 | ||
517 | /* There are so many devices that report the capacity incorrectly, | ||
518 | * this routine was written to counteract some of the resulting | ||
519 | * problems. | ||
520 | */ | ||
521 | static void last_sector_hacks(struct us_data *us, struct scsi_cmnd *srb) | ||
522 | { | ||
523 | struct gendisk *disk; | ||
524 | struct scsi_disk *sdkp; | ||
525 | u32 sector; | ||
526 | |||
527 | /* To Report "Medium Error: Record Not Found */ | ||
528 | static unsigned char record_not_found[18] = { | ||
529 | [0] = 0x70, /* current error */ | ||
530 | [2] = MEDIUM_ERROR, /* = 0x03 */ | ||
531 | [7] = 0x0a, /* additional length */ | ||
532 | [12] = 0x14 /* Record Not Found */ | ||
533 | }; | ||
534 | |||
535 | /* If last-sector problems can't occur, whether because the | ||
536 | * capacity was already decremented or because the device is | ||
537 | * known to report the correct capacity, then we don't need | ||
538 | * to do anything. | ||
539 | */ | ||
540 | if (!us->use_last_sector_hacks) | ||
541 | return; | ||
542 | |||
543 | /* Was this command a READ(10) or a WRITE(10)? */ | ||
544 | if (srb->cmnd[0] != READ_10 && srb->cmnd[0] != WRITE_10) | ||
545 | goto done; | ||
546 | |||
547 | /* Did this command access the last sector? */ | ||
548 | sector = (srb->cmnd[2] << 24) | (srb->cmnd[3] << 16) | | ||
549 | (srb->cmnd[4] << 8) | (srb->cmnd[5]); | ||
550 | disk = srb->request->rq_disk; | ||
551 | if (!disk) | ||
552 | goto done; | ||
553 | sdkp = scsi_disk(disk); | ||
554 | if (!sdkp) | ||
555 | goto done; | ||
556 | if (sector + 1 != sdkp->capacity) | ||
557 | goto done; | ||
558 | |||
559 | if (srb->result == SAM_STAT_GOOD && scsi_get_resid(srb) == 0) { | ||
560 | |||
561 | /* The command succeeded. If the capacity is odd | ||
562 | * (i.e., if the sector number is even) then the | ||
563 | * "always-even" heuristic would be wrong for this | ||
564 | * device. Issue a WARN() so that the kerneloops.org | ||
565 | * project will be notified and we will then know to | ||
566 | * mark the device with a CAPACITY_OK flag. Hopefully | ||
567 | * this will occur for only a few devices. | ||
568 | * | ||
569 | * Use the sign of us->last_sector_hacks to tell whether | ||
570 | * the warning has already been issued; we don't need | ||
571 | * more than one warning per device. | ||
572 | */ | ||
573 | if (!(sector & 1) && us->use_last_sector_hacks > 0) { | ||
574 | unsigned vid = le16_to_cpu( | ||
575 | us->pusb_dev->descriptor.idVendor); | ||
576 | unsigned pid = le16_to_cpu( | ||
577 | us->pusb_dev->descriptor.idProduct); | ||
578 | unsigned rev = le16_to_cpu( | ||
579 | us->pusb_dev->descriptor.bcdDevice); | ||
580 | |||
581 | WARN(1, "%s: Successful last sector success at %u, " | ||
582 | "device %04x:%04x:%04x\n", | ||
583 | sdkp->disk->disk_name, sector, | ||
584 | vid, pid, rev); | ||
585 | us->use_last_sector_hacks = -1; | ||
586 | } | ||
587 | |||
588 | } else { | ||
589 | /* The command failed. Allow up to 3 retries in case this | ||
590 | * is some normal sort of failure. After that, assume the | ||
591 | * capacity is wrong and we're trying to access the sector | ||
592 | * beyond the end. Replace the result code and sense data | ||
593 | * with values that will cause the SCSI core to fail the | ||
594 | * command immediately, instead of going into an infinite | ||
595 | * (or even just a very long) retry loop. | ||
596 | */ | ||
597 | if (++us->last_sector_retries < 3) | ||
598 | return; | ||
599 | srb->result = SAM_STAT_CHECK_CONDITION; | ||
600 | memcpy(srb->sense_buffer, record_not_found, | ||
601 | sizeof(record_not_found)); | ||
602 | |||
603 | /* In theory we might want to issue a WARN() here if the | ||
604 | * capacity is even, since it could indicate the device | ||
605 | * has the READ CAPACITY bug _and_ the real capacity is | ||
606 | * odd. But it could also indicate that the device | ||
607 | * simply can't access its last sector, a failure mode | ||
608 | * which is surprisingly common. So no warning. | ||
609 | */ | ||
610 | } | ||
611 | |||
612 | done: | ||
613 | /* Don't reset the retry counter for TEST UNIT READY commands, | ||
614 | * because they get issued after device resets which might be | ||
615 | * caused by a failed last-sector access. | ||
616 | */ | ||
617 | if (srb->cmnd[0] != TEST_UNIT_READY) | ||
618 | us->last_sector_retries = 0; | ||
619 | } | ||
620 | |||
514 | /* Invoke the transport and basic error-handling/recovery methods | 621 | /* Invoke the transport and basic error-handling/recovery methods |
515 | * | 622 | * |
516 | * This is used by the protocol layers to actually send the message to | 623 | * This is used by the protocol layers to actually send the message to |
@@ -544,6 +651,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) | |||
544 | /* if the transport provided its own sense data, don't auto-sense */ | 651 | /* if the transport provided its own sense data, don't auto-sense */ |
545 | if (result == USB_STOR_TRANSPORT_NO_SENSE) { | 652 | if (result == USB_STOR_TRANSPORT_NO_SENSE) { |
546 | srb->result = SAM_STAT_CHECK_CONDITION; | 653 | srb->result = SAM_STAT_CHECK_CONDITION; |
654 | last_sector_hacks(us, srb); | ||
547 | return; | 655 | return; |
548 | } | 656 | } |
549 | 657 | ||
@@ -579,6 +687,20 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) | |||
579 | } | 687 | } |
580 | 688 | ||
581 | /* | 689 | /* |
690 | * Determine if this device is SAT by seeing if the | ||
691 | * command executed successfully. Otherwise we'll have | ||
692 | * to wait for at least one CHECK_CONDITION to determine | ||
693 | * SANE_SENSE support | ||
694 | */ | ||
695 | if ((srb->cmnd[0] == ATA_16 || srb->cmnd[0] == ATA_12) && | ||
696 | result == USB_STOR_TRANSPORT_GOOD && | ||
697 | !(us->fflags & US_FL_SANE_SENSE) && | ||
698 | !(srb->cmnd[2] & 0x20)) { | ||
699 | US_DEBUGP("-- SAT supported, increasing auto-sense\n"); | ||
700 | us->fflags |= US_FL_SANE_SENSE; | ||
701 | } | ||
702 | |||
703 | /* | ||
582 | * A short transfer on a command where we don't expect it | 704 | * A short transfer on a command where we don't expect it |
583 | * is unusual, but it doesn't mean we need to auto-sense. | 705 | * is unusual, but it doesn't mean we need to auto-sense. |
584 | */ | 706 | */ |
@@ -595,10 +717,15 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) | |||
595 | if (need_auto_sense) { | 717 | if (need_auto_sense) { |
596 | int temp_result; | 718 | int temp_result; |
597 | struct scsi_eh_save ses; | 719 | struct scsi_eh_save ses; |
720 | int sense_size = US_SENSE_SIZE; | ||
721 | |||
722 | /* device supports and needs bigger sense buffer */ | ||
723 | if (us->fflags & US_FL_SANE_SENSE) | ||
724 | sense_size = ~0; | ||
598 | 725 | ||
599 | US_DEBUGP("Issuing auto-REQUEST_SENSE\n"); | 726 | US_DEBUGP("Issuing auto-REQUEST_SENSE\n"); |
600 | 727 | ||
601 | scsi_eh_prep_cmnd(srb, &ses, NULL, 0, US_SENSE_SIZE); | 728 | scsi_eh_prep_cmnd(srb, &ses, NULL, 0, sense_size); |
602 | 729 | ||
603 | /* FIXME: we must do the protocol translation here */ | 730 | /* FIXME: we must do the protocol translation here */ |
604 | if (us->subclass == US_SC_RBC || us->subclass == US_SC_SCSI || | 731 | if (us->subclass == US_SC_RBC || us->subclass == US_SC_SCSI || |
@@ -632,6 +759,25 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) | |||
632 | return; | 759 | return; |
633 | } | 760 | } |
634 | 761 | ||
762 | /* If the sense data returned is larger than 18-bytes then we | ||
763 | * assume this device supports requesting more in the future. | ||
764 | * The response code must be 70h through 73h inclusive. | ||
765 | */ | ||
766 | if (srb->sense_buffer[7] > (US_SENSE_SIZE - 8) && | ||
767 | !(us->fflags & US_FL_SANE_SENSE) && | ||
768 | (srb->sense_buffer[0] & 0x7C) == 0x70) { | ||
769 | US_DEBUGP("-- SANE_SENSE support enabled\n"); | ||
770 | us->fflags |= US_FL_SANE_SENSE; | ||
771 | |||
772 | /* Indicate to the user that we truncated their sense | ||
773 | * because we didn't know it supported larger sense. | ||
774 | */ | ||
775 | US_DEBUGP("-- Sense data truncated to %i from %i\n", | ||
776 | US_SENSE_SIZE, | ||
777 | srb->sense_buffer[7] + 8); | ||
778 | srb->sense_buffer[7] = (US_SENSE_SIZE - 8); | ||
779 | } | ||
780 | |||
635 | US_DEBUGP("-- Result from auto-sense is %d\n", temp_result); | 781 | US_DEBUGP("-- Result from auto-sense is %d\n", temp_result); |
636 | US_DEBUGP("-- code: 0x%x, key: 0x%x, ASC: 0x%x, ASCQ: 0x%x\n", | 782 | US_DEBUGP("-- code: 0x%x, key: 0x%x, ASC: 0x%x, ASCQ: 0x%x\n", |
637 | srb->sense_buffer[0], | 783 | srb->sense_buffer[0], |
@@ -667,6 +813,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) | |||
667 | scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow) | 813 | scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow) |
668 | srb->result = (DID_ERROR << 16) | (SUGGEST_RETRY << 24); | 814 | srb->result = (DID_ERROR << 16) | (SUGGEST_RETRY << 24); |
669 | 815 | ||
816 | last_sector_hacks(us, srb); | ||
670 | return; | 817 | return; |
671 | 818 | ||
672 | /* Error and abort processing: try to resynchronize with the device | 819 | /* Error and abort processing: try to resynchronize with the device |
@@ -694,6 +841,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) | |||
694 | us->transport_reset(us); | 841 | us->transport_reset(us); |
695 | } | 842 | } |
696 | clear_bit(US_FLIDX_RESETTING, &us->dflags); | 843 | clear_bit(US_FLIDX_RESETTING, &us->dflags); |
844 | last_sector_hacks(us, srb); | ||
697 | } | 845 | } |
698 | 846 | ||
699 | /* Stop the current URB transfer */ | 847 | /* Stop the current URB transfer */ |
@@ -718,10 +866,10 @@ void usb_stor_stop_transport(struct us_data *us) | |||
718 | } | 866 | } |
719 | 867 | ||
720 | /* | 868 | /* |
721 | * Control/Bulk/Interrupt transport | 869 | * Control/Bulk and Control/Bulk/Interrupt transport |
722 | */ | 870 | */ |
723 | 871 | ||
724 | int usb_stor_CBI_transport(struct scsi_cmnd *srb, struct us_data *us) | 872 | int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us) |
725 | { | 873 | { |
726 | unsigned int transfer_length = scsi_bufflen(srb); | 874 | unsigned int transfer_length = scsi_bufflen(srb); |
727 | unsigned int pipe = 0; | 875 | unsigned int pipe = 0; |
@@ -763,6 +911,13 @@ int usb_stor_CBI_transport(struct scsi_cmnd *srb, struct us_data *us) | |||
763 | } | 911 | } |
764 | 912 | ||
765 | /* STATUS STAGE */ | 913 | /* STATUS STAGE */ |
914 | |||
915 | /* NOTE: CB does not have a status stage. Silly, I know. So | ||
916 | * we have to catch this at a higher level. | ||
917 | */ | ||
918 | if (us->protocol != US_PR_CBI) | ||
919 | return USB_STOR_TRANSPORT_GOOD; | ||
920 | |||
766 | result = usb_stor_intr_transfer(us, us->iobuf, 2); | 921 | result = usb_stor_intr_transfer(us, us->iobuf, 2); |
767 | US_DEBUGP("Got interrupt data (0x%x, 0x%x)\n", | 922 | US_DEBUGP("Got interrupt data (0x%x, 0x%x)\n", |
768 | us->iobuf[0], us->iobuf[1]); | 923 | us->iobuf[0], us->iobuf[1]); |
@@ -817,56 +972,6 @@ int usb_stor_CBI_transport(struct scsi_cmnd *srb, struct us_data *us) | |||
817 | } | 972 | } |
818 | 973 | ||
819 | /* | 974 | /* |
820 | * Control/Bulk transport | ||
821 | */ | ||
822 | int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us) | ||
823 | { | ||
824 | unsigned int transfer_length = scsi_bufflen(srb); | ||
825 | int result; | ||
826 | |||
827 | /* COMMAND STAGE */ | ||
828 | /* let's send the command via the control pipe */ | ||
829 | result = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe, | ||
830 | US_CBI_ADSC, | ||
831 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0, | ||
832 | us->ifnum, srb->cmnd, srb->cmd_len); | ||
833 | |||
834 | /* check the return code for the command */ | ||
835 | US_DEBUGP("Call to usb_stor_ctrl_transfer() returned %d\n", result); | ||
836 | |||
837 | /* if we stalled the command, it means command failed */ | ||
838 | if (result == USB_STOR_XFER_STALLED) { | ||
839 | return USB_STOR_TRANSPORT_FAILED; | ||
840 | } | ||
841 | |||
842 | /* Uh oh... serious problem here */ | ||
843 | if (result != USB_STOR_XFER_GOOD) { | ||
844 | return USB_STOR_TRANSPORT_ERROR; | ||
845 | } | ||
846 | |||
847 | /* DATA STAGE */ | ||
848 | /* transfer the data payload for this command, if one exists*/ | ||
849 | if (transfer_length) { | ||
850 | unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? | ||
851 | us->recv_bulk_pipe : us->send_bulk_pipe; | ||
852 | result = usb_stor_bulk_srb(us, pipe, srb); | ||
853 | US_DEBUGP("CB data stage result is 0x%x\n", result); | ||
854 | |||
855 | /* if we stalled the data transfer it means command failed */ | ||
856 | if (result == USB_STOR_XFER_STALLED) | ||
857 | return USB_STOR_TRANSPORT_FAILED; | ||
858 | if (result > USB_STOR_XFER_STALLED) | ||
859 | return USB_STOR_TRANSPORT_ERROR; | ||
860 | } | ||
861 | |||
862 | /* STATUS STAGE */ | ||
863 | /* NOTE: CB does not have a status stage. Silly, I know. So | ||
864 | * we have to catch this at a higher level. | ||
865 | */ | ||
866 | return USB_STOR_TRANSPORT_GOOD; | ||
867 | } | ||
868 | |||
869 | /* | ||
870 | * Bulk only transport | 975 | * Bulk only transport |
871 | */ | 976 | */ |
872 | 977 | ||
@@ -1173,10 +1278,9 @@ int usb_stor_Bulk_reset(struct us_data *us) | |||
1173 | */ | 1278 | */ |
1174 | int usb_stor_port_reset(struct us_data *us) | 1279 | int usb_stor_port_reset(struct us_data *us) |
1175 | { | 1280 | { |
1176 | int result, rc_lock; | 1281 | int result; |
1177 | 1282 | ||
1178 | result = rc_lock = | 1283 | result = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf); |
1179 | usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf); | ||
1180 | if (result < 0) | 1284 | if (result < 0) |
1181 | US_DEBUGP("unable to lock device for reset: %d\n", result); | 1285 | US_DEBUGP("unable to lock device for reset: %d\n", result); |
1182 | else { | 1286 | else { |
@@ -1189,8 +1293,7 @@ int usb_stor_port_reset(struct us_data *us) | |||
1189 | US_DEBUGP("usb_reset_device returns %d\n", | 1293 | US_DEBUGP("usb_reset_device returns %d\n", |
1190 | result); | 1294 | result); |
1191 | } | 1295 | } |
1192 | if (rc_lock) | 1296 | usb_unlock_device(us->pusb_dev); |
1193 | usb_unlock_device(us->pusb_dev); | ||
1194 | } | 1297 | } |
1195 | return result; | 1298 | return result; |
1196 | } | 1299 | } |
diff --git a/drivers/usb/storage/transport.h b/drivers/usb/storage/transport.h index e70b88182f0e..242ff5e791a5 100644 --- a/drivers/usb/storage/transport.h +++ b/drivers/usb/storage/transport.h | |||
@@ -113,8 +113,6 @@ struct bulk_cs_wrap { | |||
113 | 113 | ||
114 | #define US_CBI_ADSC 0 | 114 | #define US_CBI_ADSC 0 |
115 | 115 | ||
116 | extern int usb_stor_CBI_transport(struct scsi_cmnd *, struct us_data*); | ||
117 | |||
118 | extern int usb_stor_CB_transport(struct scsi_cmnd *, struct us_data*); | 116 | extern int usb_stor_CB_transport(struct scsi_cmnd *, struct us_data*); |
119 | extern int usb_stor_CB_reset(struct us_data*); | 117 | extern int usb_stor_CB_reset(struct us_data*); |
120 | 118 | ||
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h index bfcc1fe82518..a7f9513fa19d 100644 --- a/drivers/usb/storage/unusual_devs.h +++ b/drivers/usb/storage/unusual_devs.h | |||
@@ -27,7 +27,8 @@ | |||
27 | 27 | ||
28 | /* IMPORTANT NOTE: This file must be included in another file which does | 28 | /* IMPORTANT NOTE: This file must be included in another file which does |
29 | * the following thing for it to work: | 29 | * the following thing for it to work: |
30 | * The macro UNUSUAL_DEV() must be defined before this file is included | 30 | * The UNUSUAL_DEV, COMPLIANT_DEV, and USUAL_DEV macros must be defined |
31 | * before this file is included. | ||
31 | */ | 32 | */ |
32 | 33 | ||
33 | /* If you edit this file, please try to keep it sorted first by VendorID, | 34 | /* If you edit this file, please try to keep it sorted first by VendorID, |
@@ -46,6 +47,12 @@ | |||
46 | * <usb-storage@lists.one-eyed-alien.net> | 47 | * <usb-storage@lists.one-eyed-alien.net> |
47 | */ | 48 | */ |
48 | 49 | ||
50 | /* Note: If you add an entry only in order to set the CAPACITY_OK flag, | ||
51 | * use the COMPLIANT_DEV macro instead of UNUSUAL_DEV. This is | ||
52 | * because such entries mark devices which actually work correctly, | ||
53 | * as opposed to devices that do something strangely or wrongly. | ||
54 | */ | ||
55 | |||
49 | /* patch submitted by Vivian Bregier <Vivian.Bregier@imag.fr> | 56 | /* patch submitted by Vivian Bregier <Vivian.Bregier@imag.fr> |
50 | */ | 57 | */ |
51 | UNUSUAL_DEV( 0x03eb, 0x2002, 0x0100, 0x0100, | 58 | UNUSUAL_DEV( 0x03eb, 0x2002, 0x0100, 0x0100, |
@@ -85,6 +92,13 @@ UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001, | |||
85 | US_SC_8070, US_PR_USBAT, init_usbat_cd, 0), | 92 | US_SC_8070, US_PR_USBAT, init_usbat_cd, 0), |
86 | #endif | 93 | #endif |
87 | 94 | ||
95 | /* Reported by Ben Efros <ben@pc-doctor.com> */ | ||
96 | UNUSUAL_DEV( 0x03f0, 0x070c, 0x0000, 0x0000, | ||
97 | "HP", | ||
98 | "Personal Media Drive", | ||
99 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
100 | US_FL_SANE_SENSE ), | ||
101 | |||
88 | /* Reported by Grant Grundler <grundler@parisc-linux.org> | 102 | /* Reported by Grant Grundler <grundler@parisc-linux.org> |
89 | * HP r707 camera in "Disk" mode with 2.00.23 or 2.00.24 firmware. | 103 | * HP r707 camera in "Disk" mode with 2.00.23 or 2.00.24 firmware. |
90 | */ | 104 | */ |
@@ -160,34 +174,6 @@ UNUSUAL_DEV( 0x0421, 0x0019, 0x0592, 0x0592, | |||
160 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 174 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
161 | US_FL_MAX_SECTORS_64 ), | 175 | US_FL_MAX_SECTORS_64 ), |
162 | 176 | ||
163 | /* Reported by Filip Joelsson <filip@blueturtle.nu> */ | ||
164 | UNUSUAL_DEV( 0x0421, 0x005d, 0x0001, 0x0600, | ||
165 | "Nokia", | ||
166 | "Nokia 3110c", | ||
167 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
168 | US_FL_FIX_CAPACITY ), | ||
169 | |||
170 | /* Reported by Ozan Sener <themgzzy@gmail.com> */ | ||
171 | UNUSUAL_DEV( 0x0421, 0x0060, 0x0551, 0x0551, | ||
172 | "Nokia", | ||
173 | "3500c", | ||
174 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
175 | US_FL_FIX_CAPACITY ), | ||
176 | |||
177 | /* Reported by CSECSY Laszlo <boobaa@frugalware.org> */ | ||
178 | UNUSUAL_DEV( 0x0421, 0x0063, 0x0001, 0x0601, | ||
179 | "Nokia", | ||
180 | "Nokia 3109c", | ||
181 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
182 | US_FL_FIX_CAPACITY ), | ||
183 | |||
184 | /* Patch for Nokia 5310 capacity */ | ||
185 | UNUSUAL_DEV( 0x0421, 0x006a, 0x0000, 0x0701, | ||
186 | "Nokia", | ||
187 | "5310", | ||
188 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
189 | US_FL_FIX_CAPACITY ), | ||
190 | |||
191 | /* Reported by Mario Rettig <mariorettig@web.de> */ | 177 | /* Reported by Mario Rettig <mariorettig@web.de> */ |
192 | UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100, | 178 | UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100, |
193 | "Nokia", | 179 | "Nokia", |
@@ -253,35 +239,6 @@ UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370, | |||
253 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 239 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
254 | US_FL_MAX_SECTORS_64 ), | 240 | US_FL_MAX_SECTORS_64 ), |
255 | 241 | ||
256 | /* Reported by Cedric Godin <cedric@belbone.be> */ | ||
257 | UNUSUAL_DEV( 0x0421, 0x04b9, 0x0500, 0x0551, | ||
258 | "Nokia", | ||
259 | "5300", | ||
260 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
261 | US_FL_FIX_CAPACITY ), | ||
262 | |||
263 | /* Reported by Richard Nauber <RichardNauber@web.de> */ | ||
264 | UNUSUAL_DEV( 0x0421, 0x04fa, 0x0550, 0x0660, | ||
265 | "Nokia", | ||
266 | "6300", | ||
267 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
268 | US_FL_FIX_CAPACITY ), | ||
269 | |||
270 | /* Patch for Nokia 5310 capacity */ | ||
271 | UNUSUAL_DEV( 0x0421, 0x006a, 0x0000, 0x0591, | ||
272 | "Nokia", | ||
273 | "5310", | ||
274 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
275 | US_FL_FIX_CAPACITY ), | ||
276 | |||
277 | /* Submitted by Ricky Wong Yung Fei <evilbladewarrior@gmail.com> */ | ||
278 | /* Nokia 7610 Supernova - Too many sectors reported in usb storage mode */ | ||
279 | UNUSUAL_DEV( 0x0421, 0x00f5, 0x0000, 0x0470, | ||
280 | "Nokia", | ||
281 | "7610 Supernova", | ||
282 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
283 | US_FL_FIX_CAPACITY ), | ||
284 | |||
285 | /* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */ | 242 | /* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */ |
286 | UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210, | 243 | UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210, |
287 | "SMSC", | 244 | "SMSC", |
@@ -289,11 +246,17 @@ UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210, | |||
289 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 246 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
290 | US_FL_SINGLE_LUN ), | 247 | US_FL_SINGLE_LUN ), |
291 | 248 | ||
292 | #ifdef CONFIG_USB_STORAGE_DPCM | 249 | #ifdef CONFIG_USB_STORAGE_SDDR09 |
293 | UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100, | 250 | UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100, |
294 | "Microtech", | 251 | "Microtech", |
295 | "CameraMate (DPCM_USB)", | 252 | "CameraMate (DPCM_USB)", |
296 | US_SC_SCSI, US_PR_DPCM_USB, NULL, 0 ), | 253 | US_SC_SCSI, US_PR_DPCM_USB, NULL, 0 ), |
254 | #else | ||
255 | UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100, | ||
256 | "Microtech", | ||
257 | "CameraMate", | ||
258 | US_SC_SCSI, US_PR_CB, NULL, | ||
259 | US_FL_SINGLE_LUN ), | ||
297 | #endif | 260 | #endif |
298 | 261 | ||
299 | /* Patch submitted by Daniel Drake <dsd@gentoo.org> | 262 | /* Patch submitted by Daniel Drake <dsd@gentoo.org> |
@@ -388,6 +351,15 @@ UNUSUAL_DEV( 0x04a4, 0x0004, 0x0001, 0x0001, | |||
388 | "DVD-CAM DZ-MV100A Camcorder", | 351 | "DVD-CAM DZ-MV100A Camcorder", |
389 | US_SC_SCSI, US_PR_CB, NULL, US_FL_SINGLE_LUN), | 352 | US_SC_SCSI, US_PR_CB, NULL, US_FL_SINGLE_LUN), |
390 | 353 | ||
354 | /* BENQ DC5330 | ||
355 | * Reported by Manuel Fombuena <mfombuena@ya.com> and | ||
356 | * Frank Copeland <fjc@thingy.apana.org.au> */ | ||
357 | UNUSUAL_DEV( 0x04a5, 0x3010, 0x0100, 0x0100, | ||
358 | "Tekom Technologies, Inc", | ||
359 | "300_CAMERA", | ||
360 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
361 | US_FL_IGNORE_RESIDUE ), | ||
362 | |||
391 | /* Patch for Nikon coolpix 2000 | 363 | /* Patch for Nikon coolpix 2000 |
392 | * Submitted by Fabien Cosse <fabien.cosse@wanadoo.fr>*/ | 364 | * Submitted by Fabien Cosse <fabien.cosse@wanadoo.fr>*/ |
393 | UNUSUAL_DEV( 0x04b0, 0x0301, 0x0010, 0x0010, | 365 | UNUSUAL_DEV( 0x04b0, 0x0301, 0x0010, 0x0010, |
@@ -396,83 +368,6 @@ UNUSUAL_DEV( 0x04b0, 0x0301, 0x0010, 0x0010, | |||
396 | US_SC_DEVICE, US_PR_DEVICE,NULL, | 368 | US_SC_DEVICE, US_PR_DEVICE,NULL, |
397 | US_FL_NOT_LOCKABLE ), | 369 | US_FL_NOT_LOCKABLE ), |
398 | 370 | ||
399 | /* Reported by Stefan de Konink <skinkie@xs4all.nl> */ | ||
400 | UNUSUAL_DEV( 0x04b0, 0x0401, 0x0200, 0x0200, | ||
401 | "NIKON", | ||
402 | "NIKON DSC D100", | ||
403 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
404 | US_FL_FIX_CAPACITY), | ||
405 | |||
406 | /* Reported by Tobias Kunze Briseno <t-linux@fictive.com> */ | ||
407 | UNUSUAL_DEV( 0x04b0, 0x0403, 0x0200, 0x0200, | ||
408 | "NIKON", | ||
409 | "NIKON DSC D2H", | ||
410 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
411 | US_FL_FIX_CAPACITY), | ||
412 | |||
413 | /* Reported by Milinevsky Dmitry <niam.niam@gmail.com> */ | ||
414 | UNUSUAL_DEV( 0x04b0, 0x0409, 0x0100, 0x0100, | ||
415 | "NIKON", | ||
416 | "NIKON DSC D50", | ||
417 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
418 | US_FL_FIX_CAPACITY), | ||
419 | |||
420 | /* Reported by Andreas Bockhold <andreas@bockionline.de> */ | ||
421 | UNUSUAL_DEV( 0x04b0, 0x0405, 0x0100, 0x0100, | ||
422 | "NIKON", | ||
423 | "NIKON DSC D70", | ||
424 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
425 | US_FL_FIX_CAPACITY), | ||
426 | |||
427 | /* Reported by Jamie Kitson <jamie@staberinde.fsnet.co.uk> */ | ||
428 | UNUSUAL_DEV( 0x04b0, 0x040d, 0x0100, 0x0100, | ||
429 | "NIKON", | ||
430 | "NIKON DSC D70s", | ||
431 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
432 | US_FL_FIX_CAPACITY), | ||
433 | |||
434 | /* Reported by Graber and Mike Pagano <mpagano-kernel@mpagano.com> */ | ||
435 | UNUSUAL_DEV( 0x04b0, 0x040f, 0x0100, 0x0200, | ||
436 | "NIKON", | ||
437 | "NIKON DSC D200", | ||
438 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
439 | US_FL_FIX_CAPACITY), | ||
440 | |||
441 | /* Reported by Emil Larsson <emil@swip.net> */ | ||
442 | UNUSUAL_DEV( 0x04b0, 0x0411, 0x0100, 0x0111, | ||
443 | "NIKON", | ||
444 | "NIKON DSC D80", | ||
445 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
446 | US_FL_FIX_CAPACITY), | ||
447 | |||
448 | /* Reported by Ortwin Glueck <odi@odi.ch> */ | ||
449 | UNUSUAL_DEV( 0x04b0, 0x0413, 0x0110, 0x0111, | ||
450 | "NIKON", | ||
451 | "NIKON DSC D40", | ||
452 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
453 | US_FL_FIX_CAPACITY), | ||
454 | |||
455 | /* Reported by Paul Check <paul@openstreet.com> */ | ||
456 | UNUSUAL_DEV( 0x04b0, 0x0415, 0x0100, 0x0100, | ||
457 | "NIKON", | ||
458 | "NIKON DSC D2Xs", | ||
459 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
460 | US_FL_FIX_CAPACITY), | ||
461 | |||
462 | /* Reported by Shan Destromp (shansan@gmail.com) */ | ||
463 | UNUSUAL_DEV( 0x04b0, 0x0417, 0x0100, 0x0100, | ||
464 | "NIKON", | ||
465 | "NIKON DSC D40X", | ||
466 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
467 | US_FL_FIX_CAPACITY), | ||
468 | |||
469 | /* Reported by paul ready <lxtwin@homecall.co.uk> */ | ||
470 | UNUSUAL_DEV( 0x04b0, 0x0419, 0x0100, 0x0200, | ||
471 | "NIKON", | ||
472 | "NIKON DSC D300", | ||
473 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
474 | US_FL_FIX_CAPACITY), | ||
475 | |||
476 | /* Reported by Doug Maxey (dwm@austin.ibm.com) */ | 371 | /* Reported by Doug Maxey (dwm@austin.ibm.com) */ |
477 | UNUSUAL_DEV( 0x04b3, 0x4001, 0x0110, 0x0110, | 372 | UNUSUAL_DEV( 0x04b3, 0x4001, 0x0110, 0x0110, |
478 | "IBM", | 373 | "IBM", |
@@ -480,15 +375,6 @@ UNUSUAL_DEV( 0x04b3, 0x4001, 0x0110, 0x0110, | |||
480 | US_SC_DEVICE, US_PR_CB, NULL, | 375 | US_SC_DEVICE, US_PR_CB, NULL, |
481 | US_FL_MAX_SECTORS_MIN), | 376 | US_FL_MAX_SECTORS_MIN), |
482 | 377 | ||
483 | /* BENQ DC5330 | ||
484 | * Reported by Manuel Fombuena <mfombuena@ya.com> and | ||
485 | * Frank Copeland <fjc@thingy.apana.org.au> */ | ||
486 | UNUSUAL_DEV( 0x04a5, 0x3010, 0x0100, 0x0100, | ||
487 | "Tekom Technologies, Inc", | ||
488 | "300_CAMERA", | ||
489 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
490 | US_FL_IGNORE_RESIDUE ), | ||
491 | |||
492 | #ifdef CONFIG_USB_STORAGE_CYPRESS_ATACB | 378 | #ifdef CONFIG_USB_STORAGE_CYPRESS_ATACB |
493 | /* CY7C68300 : support atacb */ | 379 | /* CY7C68300 : support atacb */ |
494 | UNUSUAL_DEV( 0x04b4, 0x6830, 0x0000, 0x9999, | 380 | UNUSUAL_DEV( 0x04b4, 0x6830, 0x0000, 0x9999, |
@@ -594,6 +480,12 @@ UNUSUAL_DEV( 0x04e6, 0x0005, 0x0100, 0x0208, | |||
594 | "eUSB SmartMedia / CompactFlash Adapter", | 480 | "eUSB SmartMedia / CompactFlash Adapter", |
595 | US_SC_SCSI, US_PR_DPCM_USB, usb_stor_sddr09_dpcm_init, | 481 | US_SC_SCSI, US_PR_DPCM_USB, usb_stor_sddr09_dpcm_init, |
596 | 0), | 482 | 0), |
483 | #else | ||
484 | UNUSUAL_DEV( 0x04e6, 0x0005, 0x0100, 0x0208, | ||
485 | "SCM Microsystems", | ||
486 | "eUSB CompactFlash Adapter", | ||
487 | US_SC_SCSI, US_PR_CB, NULL, | ||
488 | US_FL_SINGLE_LUN), | ||
597 | #endif | 489 | #endif |
598 | 490 | ||
599 | /* Reported by Markus Demleitner <msdemlei@cl.uni-heidelberg.de> */ | 491 | /* Reported by Markus Demleitner <msdemlei@cl.uni-heidelberg.de> */ |
@@ -685,6 +577,13 @@ UNUSUAL_DEV( 0x0525, 0xa140, 0x0100, 0x0100, | |||
685 | US_SC_8070, US_PR_DEVICE, NULL, | 577 | US_SC_8070, US_PR_DEVICE, NULL, |
686 | US_FL_FIX_INQUIRY ), | 578 | US_FL_FIX_INQUIRY ), |
687 | 579 | ||
580 | /* Added by Alan Stern <stern@rowland.harvard.edu> */ | ||
581 | COMPLIANT_DEV(0x0525, 0xa4a5, 0x0000, 0x9999, | ||
582 | "Linux", | ||
583 | "File-backed Storage Gadget", | ||
584 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
585 | US_FL_CAPACITY_OK ), | ||
586 | |||
688 | /* Yakumo Mega Image 37 | 587 | /* Yakumo Mega Image 37 |
689 | * Submitted by Stephan Fuhrmann <atomenergie@t-online.de> */ | 588 | * Submitted by Stephan Fuhrmann <atomenergie@t-online.de> */ |
690 | UNUSUAL_DEV( 0x052b, 0x1801, 0x0100, 0x0100, | 589 | UNUSUAL_DEV( 0x052b, 0x1801, 0x0100, 0x0100, |
@@ -807,15 +706,15 @@ UNUSUAL_DEV( 0x054c, 0x006d, 0x0000, 0x9999, | |||
807 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 706 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
808 | US_FL_FIX_INQUIRY ), | 707 | US_FL_FIX_INQUIRY ), |
809 | 708 | ||
810 | /* Submitted by Mike Alborn <malborn@deandra.homeip.net> */ | 709 | /* Submitted by Frank Engel <frankie@cse.unsw.edu.au> */ |
811 | UNUSUAL_DEV( 0x054c, 0x016a, 0x0000, 0x9999, | 710 | UNUSUAL_DEV( 0x054c, 0x0099, 0x0000, 0x9999, |
812 | "Sony", | 711 | "Sony", |
813 | "PEG Mass Storage", | 712 | "PEG Mass Storage", |
814 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 713 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
815 | US_FL_FIX_INQUIRY ), | 714 | US_FL_FIX_INQUIRY ), |
816 | 715 | ||
817 | /* Submitted by Frank Engel <frankie@cse.unsw.edu.au> */ | 716 | /* Submitted by Mike Alborn <malborn@deandra.homeip.net> */ |
818 | UNUSUAL_DEV( 0x054c, 0x0099, 0x0000, 0x9999, | 717 | UNUSUAL_DEV( 0x054c, 0x016a, 0x0000, 0x9999, |
819 | "Sony", | 718 | "Sony", |
820 | "PEG Mass Storage", | 719 | "PEG Mass Storage", |
821 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 720 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
@@ -966,6 +865,18 @@ UNUSUAL_DEV( 0x05ac, 0x120a, 0x0000, 0x9999, | |||
966 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 865 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
967 | US_FL_FIX_CAPACITY ), | 866 | US_FL_FIX_CAPACITY ), |
968 | 867 | ||
868 | /* Reported by Dan Williams <dcbw@redhat.com> | ||
869 | * Option N.V. mobile broadband modems | ||
870 | * Ignore driver CD mode and force into modem mode by default. | ||
871 | */ | ||
872 | |||
873 | /* Globetrotter HSDPA; mass storage shows up as Qualcomm for vendor */ | ||
874 | UNUSUAL_DEV( 0x05c6, 0x1000, 0x0000, 0x9999, | ||
875 | "Option N.V.", | ||
876 | "Mass Storage", | ||
877 | US_SC_DEVICE, US_PR_DEVICE, option_ms_init, | ||
878 | 0), | ||
879 | |||
969 | #ifdef CONFIG_USB_STORAGE_JUMPSHOT | 880 | #ifdef CONFIG_USB_STORAGE_JUMPSHOT |
970 | UNUSUAL_DEV( 0x05dc, 0x0001, 0x0000, 0x0001, | 881 | UNUSUAL_DEV( 0x05dc, 0x0001, 0x0000, 0x0001, |
971 | "Lexar", | 882 | "Lexar", |
@@ -1004,6 +915,13 @@ UNUSUAL_DEV( 0x05e3, 0x0702, 0x0000, 0xffff, | |||
1004 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 915 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1005 | US_FL_GO_SLOW | US_FL_MAX_SECTORS_64 ), | 916 | US_FL_GO_SLOW | US_FL_MAX_SECTORS_64 ), |
1006 | 917 | ||
918 | /* Reported by Ben Efros <ben@pc-doctor.com> */ | ||
919 | UNUSUAL_DEV( 0x05e3, 0x0723, 0x9451, 0x9451, | ||
920 | "Genesys Logic", | ||
921 | "USB to SATA", | ||
922 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
923 | US_FL_SANE_SENSE ), | ||
924 | |||
1007 | /* Reported by Hanno Boeck <hanno@gmx.de> | 925 | /* Reported by Hanno Boeck <hanno@gmx.de> |
1008 | * Taken from the Lycoris Kernel */ | 926 | * Taken from the Lycoris Kernel */ |
1009 | UNUSUAL_DEV( 0x0636, 0x0003, 0x0000, 0x9999, | 927 | UNUSUAL_DEV( 0x0636, 0x0003, 0x0000, 0x9999, |
@@ -1040,7 +958,7 @@ UNUSUAL_DEV( 0x067b, 0x2507, 0x0100, 0x0100, | |||
1040 | US_FL_FIX_CAPACITY | US_FL_GO_SLOW ), | 958 | US_FL_FIX_CAPACITY | US_FL_GO_SLOW ), |
1041 | 959 | ||
1042 | /* Reported by Alex Butcher <alex.butcher@assursys.co.uk> */ | 960 | /* Reported by Alex Butcher <alex.butcher@assursys.co.uk> */ |
1043 | UNUSUAL_DEV( 0x067b, 0x3507, 0x0001, 0x0001, | 961 | UNUSUAL_DEV( 0x067b, 0x3507, 0x0001, 0x0101, |
1044 | "Prolific Technology Inc.", | 962 | "Prolific Technology Inc.", |
1045 | "ATAPI-6 Bridge Controller", | 963 | "ATAPI-6 Bridge Controller", |
1046 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 964 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
@@ -1161,11 +1079,17 @@ UNUSUAL_DEV( 0x07af, 0x0005, 0x0100, 0x0100, | |||
1161 | US_SC_DEVICE, US_PR_DEVICE, usb_stor_euscsi_init, | 1079 | US_SC_DEVICE, US_PR_DEVICE, usb_stor_euscsi_init, |
1162 | US_FL_SCM_MULT_TARG ), | 1080 | US_FL_SCM_MULT_TARG ), |
1163 | 1081 | ||
1164 | #ifdef CONFIG_USB_STORAGE_DPCM | 1082 | #ifdef CONFIG_USB_STORAGE_SDDR09 |
1165 | UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100, | 1083 | UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100, |
1166 | "Microtech", | 1084 | "Microtech", |
1167 | "CameraMate (DPCM_USB)", | 1085 | "CameraMate (DPCM_USB)", |
1168 | US_SC_SCSI, US_PR_DPCM_USB, NULL, 0 ), | 1086 | US_SC_SCSI, US_PR_DPCM_USB, NULL, 0 ), |
1087 | #else | ||
1088 | UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100, | ||
1089 | "Microtech", | ||
1090 | "CameraMate", | ||
1091 | US_SC_SCSI, US_PR_CB, NULL, | ||
1092 | US_FL_SINGLE_LUN ), | ||
1169 | #endif | 1093 | #endif |
1170 | 1094 | ||
1171 | #ifdef CONFIG_USB_STORAGE_ALAUDA | 1095 | #ifdef CONFIG_USB_STORAGE_ALAUDA |
@@ -1320,6 +1244,13 @@ UNUSUAL_DEV( 0x0840, 0x0082, 0x0001, 0x0001, | |||
1320 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1244 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1321 | US_FL_FIX_CAPACITY), | 1245 | US_FL_FIX_CAPACITY), |
1322 | 1246 | ||
1247 | /* Reported and patched by Nguyen Anh Quynh <aquynh@gmail.com> */ | ||
1248 | UNUSUAL_DEV( 0x0840, 0x0084, 0x0001, 0x0001, | ||
1249 | "Argosy", | ||
1250 | "Storage", | ||
1251 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1252 | US_FL_FIX_CAPACITY), | ||
1253 | |||
1323 | /* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>. | 1254 | /* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>. |
1324 | * Flag will support Bulk devices which use a standards-violating 32-byte | 1255 | * Flag will support Bulk devices which use a standards-violating 32-byte |
1325 | * Command Block Wrapper. Here, the "DC2MEGA" cameras (several brands) with | 1256 | * Command Block Wrapper. Here, the "DC2MEGA" cameras (several brands) with |
@@ -1343,17 +1274,6 @@ UNUSUAL_DEV( 0x0851, 0x1543, 0x0200, 0x0200, | |||
1343 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1274 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1344 | US_FL_NOT_LOCKABLE), | 1275 | US_FL_NOT_LOCKABLE), |
1345 | 1276 | ||
1346 | /* Andrew Lunn <andrew@lunn.ch> | ||
1347 | * PanDigital Digital Picture Frame. Does not like ALLOW_MEDIUM_REMOVAL | ||
1348 | * on LUN 4. | ||
1349 | * Note: Vend:Prod clash with "Ltd Maxell WS30 Slim Digital Camera" | ||
1350 | */ | ||
1351 | UNUSUAL_DEV( 0x0851, 0x1543, 0x0200, 0x0200, | ||
1352 | "PanDigital", | ||
1353 | "Photo Frame", | ||
1354 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1355 | US_FL_NOT_LOCKABLE), | ||
1356 | |||
1357 | /* Submitted by Jan De Luyck <lkml@kcore.org> */ | 1277 | /* Submitted by Jan De Luyck <lkml@kcore.org> */ |
1358 | UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000, | 1278 | UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000, |
1359 | "CITIZEN", | 1279 | "CITIZEN", |
@@ -1425,6 +1345,13 @@ UNUSUAL_DEV( 0x0a17, 0x006, 0x0000, 0xffff, | |||
1425 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1345 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1426 | US_FL_FIX_INQUIRY ), | 1346 | US_FL_FIX_INQUIRY ), |
1427 | 1347 | ||
1348 | /* Reported by Jaak Ristioja <Ristioja@gmail.com> */ | ||
1349 | UNUSUAL_DEV( 0x0a17, 0x006e, 0x0100, 0x0100, | ||
1350 | "Pentax", | ||
1351 | "K10D", | ||
1352 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1353 | US_FL_FIX_CAPACITY ), | ||
1354 | |||
1428 | /* These are virtual windows driver CDs, which the zd1211rw driver | 1355 | /* These are virtual windows driver CDs, which the zd1211rw driver |
1429 | * automatically converts into WLAN devices. */ | 1356 | * automatically converts into WLAN devices. */ |
1430 | UNUSUAL_DEV( 0x0ace, 0x2011, 0x0101, 0x0101, | 1357 | UNUSUAL_DEV( 0x0ace, 0x2011, 0x0101, 0x0101, |
@@ -1439,6 +1366,18 @@ UNUSUAL_DEV( 0x0ace, 0x20ff, 0x0101, 0x0101, | |||
1439 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1366 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1440 | US_FL_IGNORE_DEVICE ), | 1367 | US_FL_IGNORE_DEVICE ), |
1441 | 1368 | ||
1369 | /* Reported by Dan Williams <dcbw@redhat.com> | ||
1370 | * Option N.V. mobile broadband modems | ||
1371 | * Ignore driver CD mode and force into modem mode by default. | ||
1372 | */ | ||
1373 | |||
1374 | /* iCON 225 */ | ||
1375 | UNUSUAL_DEV( 0x0af0, 0x6971, 0x0000, 0x9999, | ||
1376 | "Option N.V.", | ||
1377 | "Mass Storage", | ||
1378 | US_SC_DEVICE, US_PR_DEVICE, option_ms_init, | ||
1379 | 0), | ||
1380 | |||
1442 | /* Reported by F. Aben <f.aben@option.com> | 1381 | /* Reported by F. Aben <f.aben@option.com> |
1443 | * This device (wrongly) has a vendor-specific device descriptor. | 1382 | * This device (wrongly) has a vendor-specific device descriptor. |
1444 | * The entry is needed so usb-storage can bind to it's mass-storage | 1383 | * The entry is needed so usb-storage can bind to it's mass-storage |
@@ -1449,6 +1388,13 @@ UNUSUAL_DEV( 0x0af0, 0x7401, 0x0000, 0x0000, | |||
1449 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1388 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1450 | 0 ), | 1389 | 0 ), |
1451 | 1390 | ||
1391 | /* Reported by Ben Efros <ben@pc-doctor.com> */ | ||
1392 | UNUSUAL_DEV( 0x0bc2, 0x3010, 0x0000, 0x0000, | ||
1393 | "Seagate", | ||
1394 | "FreeAgent Pro", | ||
1395 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1396 | US_FL_SANE_SENSE ), | ||
1397 | |||
1452 | #ifdef CONFIG_USB_STORAGE_ISD200 | 1398 | #ifdef CONFIG_USB_STORAGE_ISD200 |
1453 | UNUSUAL_DEV( 0x0bf6, 0xa001, 0x0100, 0x0110, | 1399 | UNUSUAL_DEV( 0x0bf6, 0xa001, 0x0100, 0x0110, |
1454 | "ATI", | 1400 | "ATI", |
@@ -1472,6 +1418,22 @@ UNUSUAL_DEV( 0x0c0b, 0xa109, 0x0000, 0xffff, | |||
1472 | US_FL_SINGLE_LUN ), | 1418 | US_FL_SINGLE_LUN ), |
1473 | #endif | 1419 | #endif |
1474 | 1420 | ||
1421 | UNUSUAL_DEV( 0x0d49, 0x7310, 0x0000, 0x9999, | ||
1422 | "Maxtor", | ||
1423 | "USB to SATA", | ||
1424 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1425 | US_FL_SANE_SENSE), | ||
1426 | |||
1427 | /* | ||
1428 | * Pete Zaitcev <zaitcev@yahoo.com>, bz#164688. | ||
1429 | * The device blatantly ignores LUN and returns 1 in GetMaxLUN. | ||
1430 | */ | ||
1431 | UNUSUAL_DEV( 0x0c45, 0x1060, 0x0100, 0x0100, | ||
1432 | "Unknown", | ||
1433 | "Unknown", | ||
1434 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1435 | US_FL_SINGLE_LUN ), | ||
1436 | |||
1475 | /* Submitted by: Nick Sillik <n.sillik@temple.edu> | 1437 | /* Submitted by: Nick Sillik <n.sillik@temple.edu> |
1476 | * Needed for OneTouch extension to usb-storage | 1438 | * Needed for OneTouch extension to usb-storage |
1477 | * | 1439 | * |
@@ -1489,16 +1451,6 @@ UNUSUAL_DEV( 0x0c0b, 0xa109, 0x0000, 0xffff, | |||
1489 | 0), | 1451 | 0), |
1490 | #endif | 1452 | #endif |
1491 | 1453 | ||
1492 | /* | ||
1493 | * Pete Zaitcev <zaitcev@yahoo.com>, bz#164688. | ||
1494 | * The device blatantly ignores LUN and returns 1 in GetMaxLUN. | ||
1495 | */ | ||
1496 | UNUSUAL_DEV( 0x0c45, 0x1060, 0x0100, 0x0100, | ||
1497 | "Unknown", | ||
1498 | "Unknown", | ||
1499 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1500 | US_FL_SINGLE_LUN ), | ||
1501 | |||
1502 | /* Submitted by Joris Struyve <joris@struyve.be> */ | 1454 | /* Submitted by Joris Struyve <joris@struyve.be> */ |
1503 | UNUSUAL_DEV( 0x0d96, 0x410a, 0x0001, 0xffff, | 1455 | UNUSUAL_DEV( 0x0d96, 0x410a, 0x0001, 0xffff, |
1504 | "Medion", | 1456 | "Medion", |
@@ -1516,6 +1468,13 @@ UNUSUAL_DEV( 0x0d96, 0x5200, 0x0001, 0x0200, | |||
1516 | "JD 5200 z3", | 1468 | "JD 5200 z3", |
1517 | US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_FIX_INQUIRY), | 1469 | US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_FIX_INQUIRY), |
1518 | 1470 | ||
1471 | /* Reported by Jason Johnston <killean@shaw.ca> */ | ||
1472 | UNUSUAL_DEV( 0x0dc4, 0x0073, 0x0000, 0x0000, | ||
1473 | "Macpower Technology Co.LTD.", | ||
1474 | "USB 2.0 3.5\" DEVICE", | ||
1475 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1476 | US_FL_FIX_CAPACITY), | ||
1477 | |||
1519 | /* Reported by Lubomir Blaha <tritol@trilogic.cz> | 1478 | /* Reported by Lubomir Blaha <tritol@trilogic.cz> |
1520 | * I _REALLY_ don't know what 3rd, 4th number and all defines mean, but this | 1479 | * I _REALLY_ don't know what 3rd, 4th number and all defines mean, but this |
1521 | * works for me. Can anybody correct these values? (I able to test corrected | 1480 | * works for me. Can anybody correct these values? (I able to test corrected |
@@ -1638,13 +1597,6 @@ UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000, | |||
1638 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1597 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1639 | US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ), | 1598 | US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ), |
1640 | 1599 | ||
1641 | /* Reported by Ricardo Barberis <ricardo@dattatec.com> */ | ||
1642 | UNUSUAL_DEV( 0x0fce, 0xe092, 0x0000, 0x0000, | ||
1643 | "Sony Ericsson", | ||
1644 | "P1i", | ||
1645 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1646 | US_FL_IGNORE_RESIDUE ), | ||
1647 | |||
1648 | /* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */ | 1600 | /* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */ |
1649 | UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000, | 1601 | UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000, |
1650 | "Sony Ericsson", | 1602 | "Sony Ericsson", |
@@ -1652,6 +1604,13 @@ UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000, | |||
1652 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1604 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1653 | US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), | 1605 | US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), |
1654 | 1606 | ||
1607 | /* Reported by Ricardo Barberis <ricardo@dattatec.com> */ | ||
1608 | UNUSUAL_DEV( 0x0fce, 0xe092, 0x0000, 0x0000, | ||
1609 | "Sony Ericsson", | ||
1610 | "P1i", | ||
1611 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1612 | US_FL_IGNORE_RESIDUE ), | ||
1613 | |||
1655 | /* Reported by Kevin Cernekee <kpc-usbdev@gelato.uiuc.edu> | 1614 | /* Reported by Kevin Cernekee <kpc-usbdev@gelato.uiuc.edu> |
1656 | * Tested on hardware version 1.10. | 1615 | * Tested on hardware version 1.10. |
1657 | * Entry is needed only for the initializer function override. | 1616 | * Entry is needed only for the initializer function override. |
@@ -1664,6 +1623,12 @@ UNUSUAL_DEV( 0x1019, 0x0c55, 0x0000, 0x0110, | |||
1664 | US_SC_DEVICE, US_PR_DEVICE, usb_stor_ucr61s2b_init, | 1623 | US_SC_DEVICE, US_PR_DEVICE, usb_stor_ucr61s2b_init, |
1665 | 0 ), | 1624 | 0 ), |
1666 | 1625 | ||
1626 | UNUSUAL_DEV( 0x1058, 0x0704, 0x0000, 0x9999, | ||
1627 | "Western Digital", | ||
1628 | "External HDD", | ||
1629 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1630 | US_FL_SANE_SENSE), | ||
1631 | |||
1667 | /* Reported by Fabio Venturi <f.venturi@tdnet.it> | 1632 | /* Reported by Fabio Venturi <f.venturi@tdnet.it> |
1668 | * The device reports a vendor-specific bDeviceClass. | 1633 | * The device reports a vendor-specific bDeviceClass. |
1669 | */ | 1634 | */ |
@@ -2053,10 +2018,10 @@ UNUSUAL_DEV( 0x14cd, 0x6600, 0x0201, 0x0201, | |||
2053 | * JMicron responds to USN and several other SCSI ioctls with a | 2018 | * JMicron responds to USN and several other SCSI ioctls with a |
2054 | * residue that causes subsequent I/O requests to fail. */ | 2019 | * residue that causes subsequent I/O requests to fail. */ |
2055 | UNUSUAL_DEV( 0x152d, 0x2329, 0x0100, 0x0100, | 2020 | UNUSUAL_DEV( 0x152d, 0x2329, 0x0100, 0x0100, |
2056 | "JMicron", | 2021 | "JMicron", |
2057 | "USB to ATA/ATAPI Bridge", | 2022 | "USB to ATA/ATAPI Bridge", |
2058 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 2023 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
2059 | US_FL_IGNORE_RESIDUE ), | 2024 | US_FL_IGNORE_RESIDUE | US_FL_SANE_SENSE ), |
2060 | 2025 | ||
2061 | /* Reported by Robert Schedel <r.schedel@yahoo.de> | 2026 | /* Reported by Robert Schedel <r.schedel@yahoo.de> |
2062 | * Note: this is a 'super top' device like the above 14cd/6600 device */ | 2027 | * Note: this is a 'super top' device like the above 14cd/6600 device */ |
@@ -2086,27 +2051,6 @@ UNUSUAL_DEV( 0x22b8, 0x3010, 0x0001, 0x0001, | |||
2086 | US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ), | 2051 | US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ), |
2087 | 2052 | ||
2088 | /* | 2053 | /* |
2089 | * Patch by Pete Zaitcev <zaitcev@redhat.com> | ||
2090 | * Report by Mark Patton. Red Hat bz#208928. | ||
2091 | * Added support for rev 0x0002 (Motorola ROKR W5) | ||
2092 | * by Javier Smaldone <javier@smaldone.com.ar> | ||
2093 | */ | ||
2094 | UNUSUAL_DEV( 0x22b8, 0x4810, 0x0001, 0x0002, | ||
2095 | "Motorola", | ||
2096 | "RAZR V3i/ROKR W5", | ||
2097 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
2098 | US_FL_FIX_CAPACITY), | ||
2099 | |||
2100 | /* | ||
2101 | * Patch by Jost Diederichs <jost@qdusa.com> | ||
2102 | */ | ||
2103 | UNUSUAL_DEV(0x22b8, 0x6410, 0x0001, 0x9999, | ||
2104 | "Motorola Inc.", | ||
2105 | "Motorola Phone (RAZRV3xx)", | ||
2106 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
2107 | US_FL_FIX_CAPACITY), | ||
2108 | |||
2109 | /* | ||
2110 | * Patch by Constantin Baranov <const@tltsu.ru> | 2054 | * Patch by Constantin Baranov <const@tltsu.ru> |
2111 | * Report by Andreas Koenecke. | 2055 | * Report by Andreas Koenecke. |
2112 | * Motorola ROKR Z6. | 2056 | * Motorola ROKR Z6. |
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 27016fd2cad1..4becf495ca2d 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c | |||
@@ -75,9 +75,6 @@ | |||
75 | #ifdef CONFIG_USB_STORAGE_SDDR55 | 75 | #ifdef CONFIG_USB_STORAGE_SDDR55 |
76 | #include "sddr55.h" | 76 | #include "sddr55.h" |
77 | #endif | 77 | #endif |
78 | #ifdef CONFIG_USB_STORAGE_DPCM | ||
79 | #include "dpcm.h" | ||
80 | #endif | ||
81 | #ifdef CONFIG_USB_STORAGE_FREECOM | 78 | #ifdef CONFIG_USB_STORAGE_FREECOM |
82 | #include "freecom.h" | 79 | #include "freecom.h" |
83 | #endif | 80 | #endif |
@@ -103,6 +100,7 @@ | |||
103 | #include "cypress_atacb.h" | 100 | #include "cypress_atacb.h" |
104 | #endif | 101 | #endif |
105 | #include "sierra_ms.h" | 102 | #include "sierra_ms.h" |
103 | #include "option_ms.h" | ||
106 | 104 | ||
107 | /* Some informational data */ | 105 | /* Some informational data */ |
108 | MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>"); | 106 | MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>"); |
@@ -113,6 +111,10 @@ static unsigned int delay_use = 5; | |||
113 | module_param(delay_use, uint, S_IRUGO | S_IWUSR); | 111 | module_param(delay_use, uint, S_IRUGO | S_IWUSR); |
114 | MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device"); | 112 | MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device"); |
115 | 113 | ||
114 | static char quirks[128]; | ||
115 | module_param_string(quirks, quirks, sizeof(quirks), S_IRUGO | S_IWUSR); | ||
116 | MODULE_PARM_DESC(quirks, "supplemental list of device IDs and their quirks"); | ||
117 | |||
116 | 118 | ||
117 | /* | 119 | /* |
118 | * The entries in this table correspond, line for line, | 120 | * The entries in this table correspond, line for line, |
@@ -126,6 +128,8 @@ MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device"); | |||
126 | { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax), \ | 128 | { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax), \ |
127 | .driver_info = (flags)|(USB_US_TYPE_STOR<<24) } | 129 | .driver_info = (flags)|(USB_US_TYPE_STOR<<24) } |
128 | 130 | ||
131 | #define COMPLIANT_DEV UNUSUAL_DEV | ||
132 | |||
129 | #define USUAL_DEV(useProto, useTrans, useType) \ | 133 | #define USUAL_DEV(useProto, useTrans, useType) \ |
130 | { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans), \ | 134 | { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans), \ |
131 | .driver_info = (USB_US_TYPE_STOR<<24) } | 135 | .driver_info = (USB_US_TYPE_STOR<<24) } |
@@ -134,6 +138,7 @@ static struct usb_device_id storage_usb_ids [] = { | |||
134 | 138 | ||
135 | # include "unusual_devs.h" | 139 | # include "unusual_devs.h" |
136 | #undef UNUSUAL_DEV | 140 | #undef UNUSUAL_DEV |
141 | #undef COMPLIANT_DEV | ||
137 | #undef USUAL_DEV | 142 | #undef USUAL_DEV |
138 | /* Terminating entry */ | 143 | /* Terminating entry */ |
139 | { } | 144 | { } |
@@ -164,6 +169,8 @@ MODULE_DEVICE_TABLE (usb, storage_usb_ids); | |||
164 | .initFunction = init_function, \ | 169 | .initFunction = init_function, \ |
165 | } | 170 | } |
166 | 171 | ||
172 | #define COMPLIANT_DEV UNUSUAL_DEV | ||
173 | |||
167 | #define USUAL_DEV(use_protocol, use_transport, use_type) \ | 174 | #define USUAL_DEV(use_protocol, use_transport, use_type) \ |
168 | { \ | 175 | { \ |
169 | .useProtocol = use_protocol, \ | 176 | .useProtocol = use_protocol, \ |
@@ -173,6 +180,7 @@ MODULE_DEVICE_TABLE (usb, storage_usb_ids); | |||
173 | static struct us_unusual_dev us_unusual_dev_list[] = { | 180 | static struct us_unusual_dev us_unusual_dev_list[] = { |
174 | # include "unusual_devs.h" | 181 | # include "unusual_devs.h" |
175 | # undef UNUSUAL_DEV | 182 | # undef UNUSUAL_DEV |
183 | # undef COMPLIANT_DEV | ||
176 | # undef USUAL_DEV | 184 | # undef USUAL_DEV |
177 | 185 | ||
178 | /* Terminating entry */ | 186 | /* Terminating entry */ |
@@ -464,13 +472,83 @@ static int associate_dev(struct us_data *us, struct usb_interface *intf) | |||
464 | US_DEBUGP("I/O buffer allocation failed\n"); | 472 | US_DEBUGP("I/O buffer allocation failed\n"); |
465 | return -ENOMEM; | 473 | return -ENOMEM; |
466 | } | 474 | } |
475 | return 0; | ||
476 | } | ||
467 | 477 | ||
468 | us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL); | 478 | /* Works only for digits and letters, but small and fast */ |
469 | if (!us->sensebuf) { | 479 | #define TOLOWER(x) ((x) | 0x20) |
470 | US_DEBUGP("Sense buffer allocation failed\n"); | 480 | |
471 | return -ENOMEM; | 481 | /* Adjust device flags based on the "quirks=" module parameter */ |
482 | static void adjust_quirks(struct us_data *us) | ||
483 | { | ||
484 | char *p; | ||
485 | u16 vid = le16_to_cpu(us->pusb_dev->descriptor.idVendor); | ||
486 | u16 pid = le16_to_cpu(us->pusb_dev->descriptor.idProduct); | ||
487 | unsigned f = 0; | ||
488 | unsigned int mask = (US_FL_SANE_SENSE | US_FL_FIX_CAPACITY | | ||
489 | US_FL_CAPACITY_HEURISTICS | US_FL_IGNORE_DEVICE | | ||
490 | US_FL_NOT_LOCKABLE | US_FL_MAX_SECTORS_64 | | ||
491 | US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE | | ||
492 | US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT); | ||
493 | |||
494 | p = quirks; | ||
495 | while (*p) { | ||
496 | /* Each entry consists of VID:PID:flags */ | ||
497 | if (vid == simple_strtoul(p, &p, 16) && | ||
498 | *p == ':' && | ||
499 | pid == simple_strtoul(p+1, &p, 16) && | ||
500 | *p == ':') | ||
501 | break; | ||
502 | |||
503 | /* Move forward to the next entry */ | ||
504 | while (*p) { | ||
505 | if (*p++ == ',') | ||
506 | break; | ||
507 | } | ||
472 | } | 508 | } |
473 | return 0; | 509 | if (!*p) /* No match */ |
510 | return; | ||
511 | |||
512 | /* Collect the flags */ | ||
513 | while (*++p && *p != ',') { | ||
514 | switch (TOLOWER(*p)) { | ||
515 | case 'a': | ||
516 | f |= US_FL_SANE_SENSE; | ||
517 | break; | ||
518 | case 'c': | ||
519 | f |= US_FL_FIX_CAPACITY; | ||
520 | break; | ||
521 | case 'h': | ||
522 | f |= US_FL_CAPACITY_HEURISTICS; | ||
523 | break; | ||
524 | case 'i': | ||
525 | f |= US_FL_IGNORE_DEVICE; | ||
526 | break; | ||
527 | case 'l': | ||
528 | f |= US_FL_NOT_LOCKABLE; | ||
529 | break; | ||
530 | case 'm': | ||
531 | f |= US_FL_MAX_SECTORS_64; | ||
532 | break; | ||
533 | case 'o': | ||
534 | f |= US_FL_CAPACITY_OK; | ||
535 | break; | ||
536 | case 'r': | ||
537 | f |= US_FL_IGNORE_RESIDUE; | ||
538 | break; | ||
539 | case 's': | ||
540 | f |= US_FL_SINGLE_LUN; | ||
541 | break; | ||
542 | case 'w': | ||
543 | f |= US_FL_NO_WP_DETECT; | ||
544 | break; | ||
545 | /* Ignore unrecognized flag characters */ | ||
546 | } | ||
547 | } | ||
548 | us->fflags = (us->fflags & ~mask) | f; | ||
549 | dev_info(&us->pusb_intf->dev, "Quirks match for " | ||
550 | "vid %04x pid %04x: %x\n", | ||
551 | vid, pid, f); | ||
474 | } | 552 | } |
475 | 553 | ||
476 | /* Find an unusual_dev descriptor (always succeeds in the current code) */ | 554 | /* Find an unusual_dev descriptor (always succeeds in the current code) */ |
@@ -497,6 +575,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id) | |||
497 | idesc->bInterfaceProtocol : | 575 | idesc->bInterfaceProtocol : |
498 | unusual_dev->useTransport; | 576 | unusual_dev->useTransport; |
499 | us->fflags = USB_US_ORIG_FLAGS(id->driver_info); | 577 | us->fflags = USB_US_ORIG_FLAGS(id->driver_info); |
578 | adjust_quirks(us); | ||
500 | 579 | ||
501 | if (us->fflags & US_FL_IGNORE_DEVICE) { | 580 | if (us->fflags & US_FL_IGNORE_DEVICE) { |
502 | printk(KERN_INFO USB_STORAGE "device ignored\n"); | 581 | printk(KERN_INFO USB_STORAGE "device ignored\n"); |
@@ -562,7 +641,7 @@ static int get_transport(struct us_data *us) | |||
562 | 641 | ||
563 | case US_PR_CBI: | 642 | case US_PR_CBI: |
564 | us->transport_name = "Control/Bulk/Interrupt"; | 643 | us->transport_name = "Control/Bulk/Interrupt"; |
565 | us->transport = usb_stor_CBI_transport; | 644 | us->transport = usb_stor_CB_transport; |
566 | us->transport_reset = usb_stor_CB_reset; | 645 | us->transport_reset = usb_stor_CB_reset; |
567 | us->max_lun = 7; | 646 | us->max_lun = 7; |
568 | break; | 647 | break; |
@@ -675,19 +754,19 @@ static int get_protocol(struct us_data *us) | |||
675 | 754 | ||
676 | case US_SC_8020: | 755 | case US_SC_8020: |
677 | us->protocol_name = "8020i"; | 756 | us->protocol_name = "8020i"; |
678 | us->proto_handler = usb_stor_ATAPI_command; | 757 | us->proto_handler = usb_stor_pad12_command; |
679 | us->max_lun = 0; | 758 | us->max_lun = 0; |
680 | break; | 759 | break; |
681 | 760 | ||
682 | case US_SC_QIC: | 761 | case US_SC_QIC: |
683 | us->protocol_name = "QIC-157"; | 762 | us->protocol_name = "QIC-157"; |
684 | us->proto_handler = usb_stor_qic157_command; | 763 | us->proto_handler = usb_stor_pad12_command; |
685 | us->max_lun = 0; | 764 | us->max_lun = 0; |
686 | break; | 765 | break; |
687 | 766 | ||
688 | case US_SC_8070: | 767 | case US_SC_8070: |
689 | us->protocol_name = "8070i"; | 768 | us->protocol_name = "8070i"; |
690 | us->proto_handler = usb_stor_ATAPI_command; | 769 | us->proto_handler = usb_stor_pad12_command; |
691 | us->max_lun = 0; | 770 | us->max_lun = 0; |
692 | break; | 771 | break; |
693 | 772 | ||
@@ -840,8 +919,6 @@ static void dissociate_dev(struct us_data *us) | |||
840 | { | 919 | { |
841 | US_DEBUGP("-- %s\n", __func__); | 920 | US_DEBUGP("-- %s\n", __func__); |
842 | 921 | ||
843 | kfree(us->sensebuf); | ||
844 | |||
845 | /* Free the device-related DMA-mapped buffers */ | 922 | /* Free the device-related DMA-mapped buffers */ |
846 | if (us->cr) | 923 | if (us->cr) |
847 | usb_buffer_free(us->pusb_dev, sizeof(*us->cr), us->cr, | 924 | usb_buffer_free(us->pusb_dev, sizeof(*us->cr), us->cr, |
@@ -1064,6 +1141,7 @@ static struct usb_driver usb_storage_driver = { | |||
1064 | static int __init usb_stor_init(void) | 1141 | static int __init usb_stor_init(void) |
1065 | { | 1142 | { |
1066 | int retval; | 1143 | int retval; |
1144 | |||
1067 | printk(KERN_INFO "Initializing USB Mass Storage driver...\n"); | 1145 | printk(KERN_INFO "Initializing USB Mass Storage driver...\n"); |
1068 | 1146 | ||
1069 | /* register the driver, return usb_register return code if error */ | 1147 | /* register the driver, return usb_register return code if error */ |
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h index a4ad73bd832d..65e674e4be99 100644 --- a/drivers/usb/storage/usb.h +++ b/drivers/usb/storage/usb.h | |||
@@ -138,7 +138,6 @@ struct us_data { | |||
138 | struct usb_ctrlrequest *cr; /* control requests */ | 138 | struct usb_ctrlrequest *cr; /* control requests */ |
139 | struct usb_sg_request current_sg; /* scatter-gather req. */ | 139 | struct usb_sg_request current_sg; /* scatter-gather req. */ |
140 | unsigned char *iobuf; /* I/O buffer */ | 140 | unsigned char *iobuf; /* I/O buffer */ |
141 | unsigned char *sensebuf; /* sense data buffer */ | ||
142 | dma_addr_t cr_dma; /* buffer DMA addresses */ | 141 | dma_addr_t cr_dma; /* buffer DMA addresses */ |
143 | dma_addr_t iobuf_dma; | 142 | dma_addr_t iobuf_dma; |
144 | struct task_struct *ctl_thread; /* the control thread */ | 143 | struct task_struct *ctl_thread; /* the control thread */ |
@@ -155,6 +154,10 @@ struct us_data { | |||
155 | #ifdef CONFIG_PM | 154 | #ifdef CONFIG_PM |
156 | pm_hook suspend_resume_hook; | 155 | pm_hook suspend_resume_hook; |
157 | #endif | 156 | #endif |
157 | |||
158 | /* hacks for READ CAPACITY bug handling */ | ||
159 | int use_last_sector_hacks; | ||
160 | int last_sector_retries; | ||
158 | }; | 161 | }; |
159 | 162 | ||
160 | /* Convert between us_data and the corresponding Scsi_Host */ | 163 | /* Convert between us_data and the corresponding Scsi_Host */ |
diff --git a/drivers/usb/wusbcore/rh.c b/drivers/usb/wusbcore/rh.c index 407a9fcc89cc..9fe4246cecb9 100644 --- a/drivers/usb/wusbcore/rh.c +++ b/drivers/usb/wusbcore/rh.c | |||
@@ -329,7 +329,7 @@ static int wusbhc_rh_clear_port_feat(struct wusbhc *wusbhc, u16 feature, | |||
329 | static int wusbhc_rh_get_port_status(struct wusbhc *wusbhc, u16 port_idx, | 329 | static int wusbhc_rh_get_port_status(struct wusbhc *wusbhc, u16 port_idx, |
330 | u32 *_buf, u16 wLength) | 330 | u32 *_buf, u16 wLength) |
331 | { | 331 | { |
332 | u16 *buf = (u16 *) _buf; | 332 | __le16 *buf = (__le16 *)_buf; |
333 | 333 | ||
334 | if (port_idx > wusbhc->ports_max) | 334 | if (port_idx > wusbhc->ports_max) |
335 | return -EINVAL; | 335 | return -EINVAL; |