port-work; won't compile or even work
[ppcskel.git] / usb / drivers / class / storage.h
1 /*
2  * Copyright (c) 2007, Benedikt Sauter <sauter@ixbat.de>
3  * All rights reserved.
4  *
5  * Short descripton of file:
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without 
9  * modification, are permitted provided that the following conditions 
10  * are met:
11  *
12  *   * Redistributions of source code must retain the above copyright 
13  *     notice, this list of conditions and the following disclaimer.
14  *   * Redistributions in binary form must reproduce the above 
15  *     copyright notice, this list of conditions and the following 
16  *     disclaimer in the documentation and/or other materials provided 
17  *     with the distribution.
18  *   * Neither the name of the FH Augsburg nor the names of its 
19  *     contributors may be used to endorse or promote products derived 
20  *     from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
26  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #ifndef __STORAGE_H
36 #define __STORAGE_H
37 void usb_storage_probe();
38 void usb_storage_check();
39
40 /* CSW Status Definitions */
41 #define CSW_CMD_PASSED                  0x00
42 #define CSW_CMD_FAILED                  0x01
43 #define CSW_PHASE_ERROR                 0x02
44
45
46 /* SCSI Commands */
47 #define SCSI_TEST_UNIT_READY            0x00
48 #define SCSI_REQUEST_SENSE              0x03
49 #define SCSI_FORMAT_UNIT                0x04
50 #define SCSI_INQUIRY                    0x12
51 #define SCSI_MODE_SELECT6               0x15
52 #define SCSI_MODE_SENSE6                0x1A
53 #define SCSI_START_STOP_UNIT            0x1B
54 #define SCSI_MEDIA_REMOVAL              0x1E
55 #define SCSI_READ_FORMAT_CAPACITIES     0x23
56 #define SCSI_READ_CAPACITY              0x25
57 #define SCSI_READ10                     0x28
58 #define SCSI_WRITE10                    0x2A
59 #define SCSI_VERIFY10                   0x2F
60 #define SCSI_MODE_SELECT10              0x55
61 #define SCSI_MODE_SENSE10               0x5A
62
63
64 typedef struct usb_storage_cbw_t usb_storage_cbw;
65 struct usb_storage_cbw_t {
66         u32 dCBWSignature;
67         u32 dCBWTag;
68         u32 dCBWDataTransferLength;
69         u8  bCWDFlags;
70         u8  bCBWLun;
71         u8  bCBWCBLength;
72         u8  CBWCB[16];
73 };
74
75 typedef struct usb_storage_csw_t usb_storage_csw;
76 struct usb_storage_csw_t {
77         u32 dCSWSignature;
78         u32 dCSWTag;
79         u32 dCSWDataResidue;
80         u8  bCSWStatus;
81 };
82
83
84 void usb_storage_init();
85
86 u8 usb_storage_open(u8 device);
87
88 u8 usb_storage_read_capacity(u8 device);
89 u8 usb_storage_inquiry(u8 device);
90 u8 usb_storage_read_sector(u8 device, u32 sector, char * buf);
91 u8 usb_storage_write_sector(u8 device, u32 sector, char * buf);
92
93 #define USBSTORAGE_OK                   0
94 #define USBSTORAGE_ENOINTERFACE         -10000
95 #define USBSTORAGE_ESENSE               -10001
96 #define USBSTORAGE_ESHORTWRITE          -10002
97 #define USBSTORAGE_ESHORTREAD           -10003
98 #define USBSTORAGE_ESIGNATURE           -10004
99 #define USBSTORAGE_ETAG                 -10005
100 #define USBSTORAGE_ESTATUS              -10006
101 #define USBSTORAGE_EDATARESIDUE         -10007
102 #define USBSTORAGE_ETIMEDOUT            -10008
103 #define USBSTORAGE_EINIT                -10009
104 #define USBSTORAGE_PROCESSING   -10010
105
106 typedef struct
107 {
108         u8 configuration;
109         u32 interface;
110         u32 altInterface;
111
112         u8 ep_in;
113         u8 ep_out;
114
115         u8 max_lun;
116         u32 *sector_size;
117
118         s32 usb_fd;
119
120         s32 retval;
121
122         u32 tag;
123         u8 suspended;
124
125         u8 *buffer;
126 } usbstorage_handle;
127
128 s32 USBStorage_Initialize();
129
130 s32 USBStorage_Open(usbstorage_handle *dev, const char *bus, u16 vid, u16 pid);
131 s32 USBStorage_Close(usbstorage_handle *dev);
132 s32 USBStorage_Reset(usbstorage_handle *dev);
133
134 s32 USBStorage_GetMaxLUN(usbstorage_handle *dev);
135 s32 USBStorage_MountLUN(usbstorage_handle *dev, u8 lun);
136 s32 USBStorage_Suspend(usbstorage_handle *dev);
137
138 s32 USBStorage_ReadCapacity(usbstorage_handle *dev, u8 lun, u32 *sector_size, u32 *n_sectors);
139 s32 USBStorage_Read(usbstorage_handle *dev, u8 lun, u32 sector, u16 n_sectors, u8 *buffer);
140 s32 USBStorage_Write(usbstorage_handle *dev, u8 lun, u32 sector, u16 n_sectors, const u8 *buffer);
141
142 #if 0
143 #define DEVICE_TYPE_WII_USB (('W'<<24)|('U'<<16)|('S'<<8)|'B')
144
145 extern const DISC_INTERFACE __io_usbstorage;
146 #endif
147 #define __stwbrx(base,index,value)      \
148         __asm__ volatile ("stwbrx       %0,%1,%2" : : "r"(value), "b%"(index), "r"(base) : "memory")
149
150 #define __lwbrx(base,index)                     \
151 ({      register u32 res;                               \
152         __asm__ volatile ("lwbrx        %0,%1,%2" : "=r"(res) : "b%"(index), "r"(base) : "memory"); \
153         res; })
154
155 #endif /* __STORAGE_H */