xref: /OK3568_Linux_fs/kernel/drivers/usb/storage/initializers.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0+
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Special Initializers for certain USB Mass Storage devices
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Current development and maintenance by:
6*4882a593Smuzhiyun  *   (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * This driver is based on the 'USB Mass Storage Class' document. This
9*4882a593Smuzhiyun  * describes in detail the protocol used to communicate with such
10*4882a593Smuzhiyun  * devices.  Clearly, the designers had SCSI and ATAPI commands in
11*4882a593Smuzhiyun  * mind when they created this document.  The commands are all very
12*4882a593Smuzhiyun  * similar to commands in the SCSI-II and ATAPI specifications.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * It is important to note that in a number of cases this class
15*4882a593Smuzhiyun  * exhibits class-specific exemptions from the USB specification.
16*4882a593Smuzhiyun  * Notably the usage of NAK, STALL and ACK differs from the norm, in
17*4882a593Smuzhiyun  * that they are used to communicate wait, failed and OK on commands.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * Also, for certain devices, the interrupt endpoint is used to convey
20*4882a593Smuzhiyun  * status of a command.
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #include <linux/errno.h>
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #include "usb.h"
26*4882a593Smuzhiyun #include "initializers.h"
27*4882a593Smuzhiyun #include "debug.h"
28*4882a593Smuzhiyun #include "transport.h"
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /*
31*4882a593Smuzhiyun  * This places the Shuttle/SCM USB<->SCSI bridge devices in multi-target
32*4882a593Smuzhiyun  * mode
33*4882a593Smuzhiyun  */
usb_stor_euscsi_init(struct us_data * us)34*4882a593Smuzhiyun int usb_stor_euscsi_init(struct us_data *us)
35*4882a593Smuzhiyun {
36*4882a593Smuzhiyun 	int result;
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun 	usb_stor_dbg(us, "Attempting to init eUSCSI bridge...\n");
39*4882a593Smuzhiyun 	result = usb_stor_control_msg(us, us->send_ctrl_pipe,
40*4882a593Smuzhiyun 			0x0C, USB_RECIP_INTERFACE | USB_TYPE_VENDOR,
41*4882a593Smuzhiyun 			0x01, 0x0, NULL, 0x0, 5 * HZ);
42*4882a593Smuzhiyun 	usb_stor_dbg(us, "-- result is %d\n", result);
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun 	return 0;
45*4882a593Smuzhiyun }
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun /*
48*4882a593Smuzhiyun  * This function is required to activate all four slots on the UCR-61S2B
49*4882a593Smuzhiyun  * flash reader
50*4882a593Smuzhiyun  */
usb_stor_ucr61s2b_init(struct us_data * us)51*4882a593Smuzhiyun int usb_stor_ucr61s2b_init(struct us_data *us)
52*4882a593Smuzhiyun {
53*4882a593Smuzhiyun 	struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap*) us->iobuf;
54*4882a593Smuzhiyun 	struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap*) us->iobuf;
55*4882a593Smuzhiyun 	int res;
56*4882a593Smuzhiyun 	unsigned int partial;
57*4882a593Smuzhiyun 	static char init_string[] = "\xec\x0a\x06\x00$PCCHIPS";
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	usb_stor_dbg(us, "Sending UCR-61S2B initialization packet...\n");
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 	bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
62*4882a593Smuzhiyun 	bcb->Tag = 0;
63*4882a593Smuzhiyun 	bcb->DataTransferLength = cpu_to_le32(0);
64*4882a593Smuzhiyun 	bcb->Flags = bcb->Lun = 0;
65*4882a593Smuzhiyun 	bcb->Length = sizeof(init_string) - 1;
66*4882a593Smuzhiyun 	memset(bcb->CDB, 0, sizeof(bcb->CDB));
67*4882a593Smuzhiyun 	memcpy(bcb->CDB, init_string, sizeof(init_string) - 1);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 	res = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb,
70*4882a593Smuzhiyun 			US_BULK_CB_WRAP_LEN, &partial);
71*4882a593Smuzhiyun 	if (res)
72*4882a593Smuzhiyun 		return -EIO;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun 	usb_stor_dbg(us, "Getting status packet...\n");
75*4882a593Smuzhiyun 	res = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs,
76*4882a593Smuzhiyun 			US_BULK_CS_WRAP_LEN, &partial);
77*4882a593Smuzhiyun 	if (res)
78*4882a593Smuzhiyun 		return -EIO;
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	return 0;
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun /* This places the HUAWEI E220 devices in multi-port mode */
usb_stor_huawei_e220_init(struct us_data * us)84*4882a593Smuzhiyun int usb_stor_huawei_e220_init(struct us_data *us)
85*4882a593Smuzhiyun {
86*4882a593Smuzhiyun 	int result;
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun 	result = usb_stor_control_msg(us, us->send_ctrl_pipe,
89*4882a593Smuzhiyun 				      USB_REQ_SET_FEATURE,
90*4882a593Smuzhiyun 				      USB_TYPE_STANDARD | USB_RECIP_DEVICE,
91*4882a593Smuzhiyun 				      0x01, 0x0, NULL, 0x0, 1 * HZ);
92*4882a593Smuzhiyun 	usb_stor_dbg(us, "Huawei mode set result is %d\n", result);
93*4882a593Smuzhiyun 	return 0;
94*4882a593Smuzhiyun }
95