aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/storage/shuttle_usbat.c
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2009-02-12 14:48:08 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2009-03-24 19:20:34 -0400
commit26d6818f19d0ab018f28a20d699511c1efdf508b (patch)
tree78c8307da63551997421dd54ac362365cada39d4 /drivers/usb/storage/shuttle_usbat.c
parentfcdb51401f7f695b7fb782721b2e33372c5a06ce (diff)
usb-storage: make shuttle_usbat a separate module
This patch (as1211) converts usb-storage's shuttle_usbat subdriver into a separate module. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/storage/shuttle_usbat.c')
-rw-r--r--drivers/usb/storage/shuttle_usbat.c199
1 files changed, 178 insertions, 21 deletions
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index ae6d64810d2a..d4fe0bb327a7 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -42,6 +42,7 @@
42 */ 42 */
43 43
44#include <linux/errno.h> 44#include <linux/errno.h>
45#include <linux/module.h>
45#include <linux/slab.h> 46#include <linux/slab.h>
46#include <linux/cdrom.h> 47#include <linux/cdrom.h>
47 48
@@ -52,7 +53,97 @@
52#include "transport.h" 53#include "transport.h"
53#include "protocol.h" 54#include "protocol.h"
54#include "debug.h" 55#include "debug.h"
55#include "shuttle_usbat.h" 56
57
58/* Supported device types */
59#define USBAT_DEV_HP8200 0x01
60#define USBAT_DEV_FLASH 0x02
61
62#define USBAT_EPP_PORT 0x10
63#define USBAT_EPP_REGISTER 0x30
64#define USBAT_ATA 0x40
65#define USBAT_ISA 0x50
66
67/* Commands (need to be logically OR'd with an access type */
68#define USBAT_CMD_READ_REG 0x00
69#define USBAT_CMD_WRITE_REG 0x01
70#define USBAT_CMD_READ_BLOCK 0x02
71#define USBAT_CMD_WRITE_BLOCK 0x03
72#define USBAT_CMD_COND_READ_BLOCK 0x04
73#define USBAT_CMD_COND_WRITE_BLOCK 0x05
74#define USBAT_CMD_WRITE_REGS 0x07
75
76/* Commands (these don't need an access type) */
77#define USBAT_CMD_EXEC_CMD 0x80
78#define USBAT_CMD_SET_FEAT 0x81
79#define USBAT_CMD_UIO 0x82
80
81/* Methods of accessing UIO register */
82#define USBAT_UIO_READ 1
83#define USBAT_UIO_WRITE 0
84
85/* Qualifier bits */
86#define USBAT_QUAL_FCQ 0x20 /* full compare */
87#define USBAT_QUAL_ALQ 0x10 /* auto load subcount */
88
89/* USBAT Flash Media status types */
90#define USBAT_FLASH_MEDIA_NONE 0
91#define USBAT_FLASH_MEDIA_CF 1
92
93/* USBAT Flash Media change types */
94#define USBAT_FLASH_MEDIA_SAME 0
95#define USBAT_FLASH_MEDIA_CHANGED 1
96
97/* USBAT ATA registers */
98#define USBAT_ATA_DATA 0x10 /* read/write data (R/W) */
99#define USBAT_ATA_FEATURES 0x11 /* set features (W) */
100#define USBAT_ATA_ERROR 0x11 /* error (R) */
101#define USBAT_ATA_SECCNT 0x12 /* sector count (R/W) */
102#define USBAT_ATA_SECNUM 0x13 /* sector number (R/W) */
103#define USBAT_ATA_LBA_ME 0x14 /* cylinder low (R/W) */
104#define USBAT_ATA_LBA_HI 0x15 /* cylinder high (R/W) */
105#define USBAT_ATA_DEVICE 0x16 /* head/device selection (R/W) */
106#define USBAT_ATA_STATUS 0x17 /* device status (R) */
107#define USBAT_ATA_CMD 0x17 /* device command (W) */
108#define USBAT_ATA_ALTSTATUS 0x0E /* status (no clear IRQ) (R) */
109
110/* USBAT User I/O Data registers */
111#define USBAT_UIO_EPAD 0x80 /* Enable Peripheral Control Signals */
112#define USBAT_UIO_CDT 0x40 /* Card Detect (Read Only) */
113 /* CDT = ACKD & !UI1 & !UI0 */
114#define USBAT_UIO_1 0x20 /* I/O 1 */
115#define USBAT_UIO_0 0x10 /* I/O 0 */
116#define USBAT_UIO_EPP_ATA 0x08 /* 1=EPP mode, 0=ATA mode */
117#define USBAT_UIO_UI1 0x04 /* Input 1 */
118#define USBAT_UIO_UI0 0x02 /* Input 0 */
119#define USBAT_UIO_INTR_ACK 0x01 /* Interrupt (ATA/ISA)/Acknowledge (EPP) */
120
121/* USBAT User I/O Enable registers */
122#define USBAT_UIO_DRVRST 0x80 /* Reset Peripheral */
123#define USBAT_UIO_ACKD 0x40 /* Enable Card Detect */
124#define USBAT_UIO_OE1 0x20 /* I/O 1 set=output/clr=input */
125 /* If ACKD=1, set OE1 to 1 also. */
126#define USBAT_UIO_OE0 0x10 /* I/O 0 set=output/clr=input */
127#define USBAT_UIO_ADPRST 0x01 /* Reset SCM chip */
128
129/* USBAT Features */
130#define USBAT_FEAT_ETEN 0x80 /* External trigger enable */
131#define USBAT_FEAT_U1 0x08
132#define USBAT_FEAT_U0 0x04
133#define USBAT_FEAT_ET1 0x02
134#define USBAT_FEAT_ET2 0x01
135
136struct usbat_info {
137 int devicetype;
138
139 /* Used for Flash readers only */
140 unsigned long sectors; /* total sector count */
141 unsigned long ssize; /* sector size in bytes */
142
143 unsigned char sense_key;
144 unsigned long sense_asc; /* additional sense code */
145 unsigned long sense_ascq; /* additional sense code qualifier */
146};
56 147
57#define short_pack(LSB,MSB) ( ((u16)(LSB)) | ( ((u16)(MSB))<<8 ) ) 148#define short_pack(LSB,MSB) ( ((u16)(LSB)) | ( ((u16)(MSB))<<8 ) )
58#define LSB_of(s) ((s)&0xFF) 149#define LSB_of(s) ((s)&0xFF)
@@ -63,6 +154,48 @@ static int transferred = 0;
63static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us); 154static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us);
64static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us); 155static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us);
65 156
157static int init_usbat_cd(struct us_data *us);
158static int init_usbat_flash(struct us_data *us);
159
160
161/*
162 * The table of devices
163 */
164#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
165 vendorName, productName, useProtocol, useTransport, \
166 initFunction, flags) \
167{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
168 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
169
170struct usb_device_id usbat_usb_ids[] = {
171# include "unusual_usbat.h"
172 { } /* Terminating entry */
173};
174MODULE_DEVICE_TABLE(usb, usbat_usb_ids);
175
176#undef UNUSUAL_DEV
177
178/*
179 * The flags table
180 */
181#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
182 vendor_name, product_name, use_protocol, use_transport, \
183 init_function, Flags) \
184{ \
185 .vendorName = vendor_name, \
186 .productName = product_name, \
187 .useProtocol = use_protocol, \
188 .useTransport = use_transport, \
189 .initFunction = init_function, \
190}
191
192static struct us_unusual_dev usbat_unusual_dev_list[] = {
193# include "unusual_usbat.h"
194 { } /* Terminating entry */
195};
196
197#undef UNUSUAL_DEV
198
66/* 199/*
67 * Convenience function to produce an ATA read/write sectors command 200 * Convenience function to produce an ATA read/write sectors command
68 * Use cmd=0x20 for read, cmd=0x30 for write 201 * Use cmd=0x20 for read, cmd=0x30 for write
@@ -1684,37 +1817,61 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1684 return USB_STOR_TRANSPORT_FAILED; 1817 return USB_STOR_TRANSPORT_FAILED;
1685} 1818}
1686 1819
1687int init_usbat_cd(struct us_data *us) 1820static int init_usbat_cd(struct us_data *us)
1688{ 1821{
1689 return init_usbat(us, USBAT_DEV_HP8200); 1822 return init_usbat(us, USBAT_DEV_HP8200);
1690} 1823}
1691 1824
1692 1825static int init_usbat_flash(struct us_data *us)
1693int init_usbat_flash(struct us_data *us)
1694{ 1826{
1695 return init_usbat(us, USBAT_DEV_FLASH); 1827 return init_usbat(us, USBAT_DEV_FLASH);
1696} 1828}
1697 1829
1698int init_usbat_probe(struct us_data *us) 1830static int usbat_probe(struct usb_interface *intf,
1831 const struct usb_device_id *id)
1699{ 1832{
1700 return init_usbat(us, 0); 1833 struct us_data *us;
1834 int result;
1835
1836 result = usb_stor_probe1(&us, intf, id,
1837 (id - usbat_usb_ids) + usbat_unusual_dev_list);
1838 if (result)
1839 return result;
1840
1841 /* The actual transport will be determined later by the
1842 * initialization routine; this is just a placeholder.
1843 */
1844 us->transport_name = "Shuttle USBAT";
1845 us->transport = usbat_flash_transport;
1846 us->transport_reset = usb_stor_CB_reset;
1847 us->max_lun = 1;
1848
1849 result = usb_stor_probe2(us);
1850 return result;
1701} 1851}
1702 1852
1703/* 1853static struct usb_driver usbat_driver = {
1704 * Default transport function. Attempts to detect which transport function 1854 .name = "ums-usbat",
1705 * should be called, makes it the new default, and calls it. 1855 .probe = usbat_probe,
1706 * 1856 .disconnect = usb_stor_disconnect,
1707 * This function should never be called. Our usbat_init() function detects the 1857 .suspend = usb_stor_suspend,
1708 * device type and changes the us->transport ptr to the transport function 1858 .resume = usb_stor_resume,
1709 * relevant to the device. 1859 .reset_resume = usb_stor_reset_resume,
1710 * However, we'll support this impossible(?) case anyway. 1860 .pre_reset = usb_stor_pre_reset,
1711 */ 1861 .post_reset = usb_stor_post_reset,
1712int usbat_transport(struct scsi_cmnd *srb, struct us_data *us) 1862 .id_table = usbat_usb_ids,
1863 .soft_unbind = 1,
1864};
1865
1866static int __init usbat_init(void)
1713{ 1867{
1714 struct usbat_info *info = (struct usbat_info*) (us->extra); 1868 return usb_register(&usbat_driver);
1715 1869}
1716 if (usbat_set_transport(us, info, 0))
1717 return USB_STOR_TRANSPORT_ERROR;
1718 1870
1719 return us->transport(srb, us); 1871static void __exit usbat_exit(void)
1872{
1873 usb_deregister(&usbat_driver);
1720} 1874}
1875
1876module_init(usbat_init);
1877module_exit(usbat_exit);