]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
USB Storage: add rio karma eject support
authorMatthew Dharm <mdharm-usb@one-eyed-alien.net>
Mon, 14 Aug 2006 00:30:14 +0000 (17:30 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 27 Sep 2006 18:58:54 +0000 (11:58 -0700)
This changeset from Keith Bennett (via Bob Copeland) moves the Karma
initializer to its own file and adds trapping of the START_STOP command to
enable eject of the device.

Signed-off-by: Keith Bennett <keith@mcs.st-and.ac.uk>
Signed-off-by: Bob Copeland <me@bobcopeland.com>
Signed-off-by: Matthew Dharm <mdharm-usb@one-eyed-alien.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/storage/Kconfig
drivers/usb/storage/Makefile
drivers/usb/storage/initializers.c
drivers/usb/storage/initializers.h
drivers/usb/storage/karma.c [new file with mode: 0644]
drivers/usb/storage/karma.h [new file with mode: 0644]
drivers/usb/storage/unusual_devs.h
drivers/usb/storage/usb.c
include/linux/usb_usual.h

index be9eec2257436c2152aecd9e0d20462f69902b2e..86e48c42d6af3cf955c2cb4320bb33eeda29f77e 100644 (file)
@@ -135,6 +135,18 @@ config USB_STORAGE_ONETOUCH
          this input in any keybinding software. (e.g. gnome's keyboard short-
          cuts)
 
+config USB_STORAGE_KARMA
+       bool "Support for Rio Karma music player"
+       depends on USB_STORAGE
+       help
+         Say Y here to include additional code to support the Rio Karma
+         USB interface.
+
+         This code places the Rio Karma into mass storage mode, enabling
+         it to be mounted as an ordinary filesystem. Performing an eject
+         on the resulting scsi device node returns the Karma to normal
+         operation.
+
 config USB_LIBUSUAL
        bool "The shared table of common (or usual) storage devices"
        depends on USB
index 8cbba22508a47d77d3a39897d4138e7be5a7f7ae..023969b4385b689265b3836cb130a6dd8de64fad 100644 (file)
@@ -20,6 +20,7 @@ usb-storage-obj-$(CONFIG_USB_STORAGE_DATAFAB) += datafab.o
 usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o
 usb-storage-obj-$(CONFIG_USB_STORAGE_ALAUDA)   += alauda.o
 usb-storage-obj-$(CONFIG_USB_STORAGE_ONETOUCH) += onetouch.o
+usb-storage-obj-$(CONFIG_USB_STORAGE_KARMA)    += karma.o
 
 usb-storage-objs :=    scsiglue.o protocol.o transport.o usb.o \
                        initializers.o $(usb-storage-obj-y)
index ab173b30076eb1b7ac2ec3a2fe257a78863918d5..5b06f9240d05caa2b348c7cf55cf520ff2ca2240 100644 (file)
 #include "debug.h"
 #include "transport.h"
 
-#define RIO_MSC 0x08
-#define RIOP_INIT "RIOP\x00\x01\x08"
-#define RIOP_INIT_LEN 7
-#define RIO_SEND_LEN 40
-#define RIO_RECV_LEN 0x200
-
 /* This places the Shuttle/SCM USB<->SCSI bridge devices in multi-target
  * mode */
 int usb_stor_euscsi_init(struct us_data *us)
@@ -97,70 +91,3 @@ int usb_stor_ucr61s2b_init(struct us_data *us)
 
        return (res ? -1 : 0);
 }
-
-/* Place the Rio Karma into mass storage mode.
- *
- * The initialization begins by sending 40 bytes starting
- * RIOP\x00\x01\x08\x00, which the device will ack with a 512-byte
- * packet with the high four bits set and everything else null.
- *
- * Next, we send RIOP\x80\x00\x08\x00.  Each time, a 512 byte response
- * must be read, but we must loop until byte 5 in the response is 0x08,
- * indicating success.  */
-int rio_karma_init(struct us_data *us)
-{
-       int result, partial;
-       char *recv;
-       unsigned long timeout;
-
-       // us->iobuf is big enough to hold cmd but not receive
-       if (!(recv = kmalloc(RIO_RECV_LEN, GFP_KERNEL)))
-               goto die_nomem;
-
-       US_DEBUGP("Initializing Karma...\n");
-
-       memset(us->iobuf, 0, RIO_SEND_LEN);
-       memcpy(us->iobuf, RIOP_INIT, RIOP_INIT_LEN);
-
-       result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
-               us->iobuf, RIO_SEND_LEN, &partial);
-       if (result != USB_STOR_XFER_GOOD)
-               goto die;
-
-       result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
-               recv, RIO_RECV_LEN, &partial);
-       if (result != USB_STOR_XFER_GOOD)
-               goto die;
-
-       us->iobuf[4] = 0x80;
-       us->iobuf[5] = 0;
-       timeout = jiffies + msecs_to_jiffies(3000);
-       for (;;) {
-               US_DEBUGP("Sending init command\n");
-               result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
-                       us->iobuf, RIO_SEND_LEN, &partial);
-               if (result != USB_STOR_XFER_GOOD)
-                       goto die;
-
-               result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
-                       recv, RIO_RECV_LEN, &partial);
-               if (result != USB_STOR_XFER_GOOD)
-                       goto die;
-
-               if (recv[5] == RIO_MSC)
-                       break;
-               if (time_after(jiffies, timeout))
-                       goto die;
-               msleep(10);
-       }
-       US_DEBUGP("Karma initialized.\n");
-       kfree(recv);
-       return 0;
-
-die:
-       kfree(recv);
-die_nomem:
-       US_DEBUGP("Could not initialize karma.\n");
-       return USB_STOR_TRANSPORT_FAILED;
-}
-
index 927f7781080f0afebff4b1e5ee4602cf27b6526a..e2967a4d48a2e30d0fa694f233d10941ec88121a 100644 (file)
@@ -47,4 +47,3 @@ int usb_stor_euscsi_init(struct us_data *us);
 /* This function is required to activate all four slots on the UCR-61S2B
  * flash reader */
 int usb_stor_ucr61s2b_init(struct us_data *us);
-int rio_karma_init(struct us_data *us);
diff --git a/drivers/usb/storage/karma.c b/drivers/usb/storage/karma.c
new file mode 100644 (file)
index 0000000..0d79ae5
--- /dev/null
@@ -0,0 +1,155 @@
+/* Driver for Rio Karma
+ *
+ *   (c) 2006 Bob Copeland <me@bobcopeland.com>
+ *   (c) 2006 Keith Bennett <keith@mcs.st-and.ac.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_device.h>
+
+#include "usb.h"
+#include "transport.h"
+#include "debug.h"
+#include "karma.h"
+
+#define RIO_PREFIX "RIOP\x00"
+#define RIO_PREFIX_LEN 5
+#define RIO_SEND_LEN 40
+#define RIO_RECV_LEN 0x200
+
+#define RIO_ENTER_STORAGE 0x1
+#define RIO_LEAVE_STORAGE 0x2
+#define RIO_RESET 0xC
+
+extern int usb_stor_Bulk_transport(struct scsi_cmnd *, struct us_data *);
+
+struct karma_data {
+       int in_storage;
+       char *recv;
+};
+
+/*
+ * Send commands to Rio Karma.
+ *
+ * For each command we send 40 bytes starting 'RIOP\0' followed by
+ * the command number and a sequence number, which the device will ack
+ * with a 512-byte packet with the high four bits set and everything
+ * else null.  Then we send 'RIOP\x80' followed by a zero and the
+ * sequence number, until byte 5 in the response repeats the sequence
+ * number.
+ */
+static int rio_karma_send_command(char cmd, struct us_data *us)
+{
+       int result, partial;
+       unsigned long timeout;
+       static unsigned char seq = 1;
+       struct karma_data *data = (struct karma_data *) us->extra;
+
+       US_DEBUGP("karma: sending command %04x\n", cmd);
+       memset(us->iobuf, 0, RIO_SEND_LEN);
+       memcpy(us->iobuf, RIO_PREFIX, RIO_PREFIX_LEN);
+       us->iobuf[5] = cmd;
+       us->iobuf[6] = seq;
+
+       timeout = jiffies + msecs_to_jiffies(6000);
+       for (;;) {
+               result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
+                       us->iobuf, RIO_SEND_LEN, &partial);
+               if (result != USB_STOR_XFER_GOOD)
+                       goto err;
+
+               result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
+                       data->recv, RIO_RECV_LEN, &partial);
+               if (result != USB_STOR_XFER_GOOD)
+                       goto err;
+
+               if (data->recv[5] == seq)
+                       break;
+
+               if (time_after(jiffies, timeout))
+                       goto err;
+
+               us->iobuf[4] = 0x80;
+               us->iobuf[5] = 0;
+               msleep(50);
+       }
+
+       seq++;
+       if (seq == 0)
+               seq = 1;
+
+       US_DEBUGP("karma: sent command %04x\n", cmd);
+       return 0;
+err:
+       US_DEBUGP("karma: command %04x failed\n", cmd);
+       return USB_STOR_TRANSPORT_FAILED;
+}
+
+/*
+ * Trap START_STOP and READ_10 to leave/re-enter storage mode.
+ * Everything else is propagated to the normal bulk layer.
+ */
+int rio_karma_transport(struct scsi_cmnd *srb, struct us_data *us)
+{
+       int ret;
+       struct karma_data *data = (struct karma_data *) us->extra;
+
+       if (srb->cmnd[0] == READ_10 && !data->in_storage) {
+               ret = rio_karma_send_command(RIO_ENTER_STORAGE, us);
+               if (ret)
+                       return ret;
+
+               data->in_storage = 1;
+               return usb_stor_Bulk_transport(srb, us);
+       } else if (srb->cmnd[0] == START_STOP) {
+               ret = rio_karma_send_command(RIO_LEAVE_STORAGE, us);
+               if (ret)
+                       return ret;
+
+               data->in_storage = 0;
+               return rio_karma_send_command(RIO_RESET, us);
+       }
+       return usb_stor_Bulk_transport(srb, us);
+}
+
+static void rio_karma_destructor(void *extra)
+{
+       struct karma_data *data = (struct karma_data *) extra;
+       kfree(data->recv);
+}
+
+int rio_karma_init(struct us_data *us)
+{
+       int ret = 0;
+       struct karma_data *data = kzalloc(sizeof(struct karma_data), GFP_NOIO);
+       if (!data)
+               goto out;
+
+       data->recv = kmalloc(RIO_RECV_LEN, GFP_NOIO);
+       if (!data->recv) {
+               kfree(data);
+               goto out;
+       }
+
+       us->extra = data;
+       us->extra_destructor = rio_karma_destructor;
+       ret = rio_karma_send_command(RIO_ENTER_STORAGE, us);
+       data->in_storage = (ret == 0);
+out:
+       return ret;
+}
diff --git a/drivers/usb/storage/karma.h b/drivers/usb/storage/karma.h
new file mode 100644 (file)
index 0000000..8a60972
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef _KARMA_USB_H
+#define _KARMA_USB_H
+
+extern int rio_karma_init(struct us_data *us);
+extern int rio_karma_transport(struct scsi_cmnd *srb, struct us_data *us);
+
+#endif
index fa49357289c4b5006b82f734b35cb369f1a2543e..1f11c9d44eaab1ba11c7cbbd228cfd383693bde9 100644 (file)
@@ -221,7 +221,7 @@ UNUSUAL_DEV(  0x0457, 0x0151, 0x0100, 0x0100,
 UNUSUAL_DEV(  0x045a, 0x5210, 0x0101, 0x0101,
                "Rio",
                "Rio Karma",
-               US_SC_SCSI, US_PR_BULK, rio_karma_init, 0),
+               US_SC_SCSI, US_PR_KARMA, rio_karma_init, 0),
 
 /* Patch submitted by Philipp Friedrich <philipp@void.at> */
 UNUSUAL_DEV(  0x0482, 0x0100, 0x0100, 0x0100,
index 8d7bdcb5924d402f891cbf1a07c2584400a28cb3..b8d6031b09750245ce4bdece07ed7528e4a7e6c1 100644 (file)
@@ -98,6 +98,9 @@
 #ifdef CONFIG_USB_STORAGE_ALAUDA
 #include "alauda.h"
 #endif
+#ifdef CONFIG_USB_STORAGE_KARMA
+#include "karma.h"
+#endif
 
 /* Some informational data */
 MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>");
@@ -646,6 +649,14 @@ static int get_transport(struct us_data *us)
                break;
 #endif
 
+#ifdef CONFIG_USB_STORAGE_KARMA
+       case US_PR_KARMA:
+               us->transport_name = "Rio Karma/Bulk";
+               us->transport = rio_karma_transport;
+               us->transport_reset = usb_stor_Bulk_reset;
+               break;
+#endif
+
        default:
                return -EIO;
        }
index e7fc5fed5b98b8044d940fa4a7ded769a09a0452..2ae76fe52ff75e483806cd48c2f3e29fadfd89ac 100644 (file)
@@ -108,6 +108,9 @@ enum { US_DO_ALL_FLAGS };
 #ifdef CONFIG_USB_STORAGE_ALAUDA
 #define US_PR_ALAUDA    0xf4           /* Alauda chipsets */
 #endif
+#ifdef CONFIG_USB_STORAGE_KARMA
+#define US_PR_KARMA     0xf5           /* Rio Karma */
+#endif
 
 #define US_PR_DEVICE   0xff            /* Use device's value */