]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
usb: properly detect empty mass storage media reader
authorVincent Palatin <vpalatin@chromium.org>
Thu, 13 Dec 2012 01:55:29 +0000 (17:55 -0800)
committerMarek Vasut <marex@denx.de>
Mon, 17 Dec 2012 14:38:15 +0000 (15:38 +0100)
When a USB card reader is empty, it will return "Not Ready - medium not
present" as Key Code Qualifier. In that situation, it's useless waiting
for the full timeout since the result won't change until the user
inserts a card.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
common/usb_storage.c

index 2d92ee1bb3e95c5af8e6cc66ddcfa1c4aa61bac8..fb322b4015fe0ba2ea72d82a1f7171ae7bfee2e3 100644 (file)
@@ -970,6 +970,16 @@ static int usb_test_unit_ready(ccb *srb, struct us_data *ss)
                        return 0;
                }
                usb_request_sense(srb, ss);
+               /*
+                * Check the Key Code Qualifier, if it matches
+                * "Not Ready - medium not present"
+                * (the sense Key equals 0x2 and the ASC is 0x3a)
+                * return immediately as the medium being absent won't change
+                * unless there is a user action.
+                */
+               if ((srb->sense_buf[2] == 0x02) &&
+                   (srb->sense_buf[12] == 0x3a))
+                       return -1;
                mdelay(100);
        } while (retries--);