xref: /rk3399_rockchip-uboot/drivers/usb/gadget/f_rockusb.c (revision c3e08fa050aa3e8eb31fbd76f4d1e28c00ffe0b4)
1 /*
2  * Copyright 2017 Rockchip Electronics Co., Ltd
3  * Frank Wang <frank.wang@rock-chips.com>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #include <asm/io.h>
9 #include <asm/arch/boot_mode.h>
10 #include <asm/arch/chip_info.h>
11 #include <write_keybox.h>
12 #include <linux/mtd/mtd.h>
13 
14 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION
15 #include <asm/arch/vendor.h>
16 #endif
17 
18 #include <rockusb.h>
19 
20 #define ROCKUSB_INTERFACE_CLASS	0xff
21 #define ROCKUSB_INTERFACE_SUB_CLASS	0x06
22 #define ROCKUSB_INTERFACE_PROTOCOL	0x05
23 
24 #define ROCKCHIP_FLASH_BLOCK_SIZE	1024
25 #define ROCKCHIP_FLASH_PAGE_SIZE	4
26 
27 static struct usb_interface_descriptor rkusb_intf_desc = {
28 	.bLength		= USB_DT_INTERFACE_SIZE,
29 	.bDescriptorType	= USB_DT_INTERFACE,
30 	.bInterfaceNumber	= 0x00,
31 	.bAlternateSetting	= 0x00,
32 	.bNumEndpoints		= 0x02,
33 	.bInterfaceClass	= ROCKUSB_INTERFACE_CLASS,
34 	.bInterfaceSubClass	= ROCKUSB_INTERFACE_SUB_CLASS,
35 	.bInterfaceProtocol	= ROCKUSB_INTERFACE_PROTOCOL,
36 };
37 
38 static struct usb_descriptor_header *rkusb_fs_function[] = {
39 	(struct usb_descriptor_header *)&rkusb_intf_desc,
40 	(struct usb_descriptor_header *)&fsg_fs_bulk_in_desc,
41 	(struct usb_descriptor_header *)&fsg_fs_bulk_out_desc,
42 	NULL,
43 };
44 
45 static struct usb_descriptor_header *rkusb_hs_function[] = {
46 	(struct usb_descriptor_header *)&rkusb_intf_desc,
47 	(struct usb_descriptor_header *)&fsg_hs_bulk_in_desc,
48 	(struct usb_descriptor_header *)&fsg_hs_bulk_out_desc,
49 	NULL,
50 };
51 
52 static struct usb_descriptor_header *rkusb_ss_function[] = {
53 	(struct usb_descriptor_header *)&rkusb_intf_desc,
54 	(struct usb_descriptor_header *)&fsg_ss_bulk_in_desc,
55 	(struct usb_descriptor_header *)&fsg_ss_bulk_in_comp_desc,
56 	(struct usb_descriptor_header *)&fsg_ss_bulk_out_desc,
57 	(struct usb_descriptor_header *)&fsg_ss_bulk_out_comp_desc,
58 	NULL,
59 };
60 
61 struct rk_flash_info {
62 	u32	flash_size;
63 	u16	block_size;
64 	u8	page_size;
65 	u8	ecc_bits;
66 	u8	access_time;
67 	u8	manufacturer;
68 	u8	flash_mask;
69 } __packed;
70 
71 static int rkusb_rst_code; /* The subcode in reset command (0xFF) */
72 
73 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
74 {
75 	if (IS_RKUSB_UMS_DNL(name)) {
76 		/* Fix to Rockchip's VID and PID */
77 		dev->idVendor  = __constant_cpu_to_le16(0x2207);
78 		dev->idProduct = __constant_cpu_to_le16(CONFIG_ROCKUSB_G_DNL_PID);
79 
80 		/* Enumerate as a loader device */
81 #if defined(CONFIG_SUPPORT_USBPLUG)
82 		dev->bcdUSB = cpu_to_le16(0x0200);
83 #else
84 		dev->bcdUSB = cpu_to_le16(0x0201);
85 #endif
86 	} else if (!strncmp(name, "usb_dnl_fastboot", 16)) {
87 		/* Fix to Google's VID and PID */
88 		dev->idVendor  = __constant_cpu_to_le16(0x18d1);
89 		dev->idProduct = __constant_cpu_to_le16(0xd00d);
90 	} else if (!strncmp(name, "usb_dnl_dfu", 11)) {
91 		/* Fix to Rockchip's VID and PID for DFU */
92 		dev->idVendor  = cpu_to_le16(0x2207);
93 		dev->idProduct = cpu_to_le16(0x0107);
94 	}
95 
96 	return 0;
97 }
98 
99 __maybe_unused
100 static inline void dump_cbw(struct fsg_bulk_cb_wrap *cbw)
101 {
102 	assert(!cbw);
103 
104 	debug("%s:\n", __func__);
105 	debug("Signature %x\n", cbw->Signature);
106 	debug("Tag %x\n", cbw->Tag);
107 	debug("DataTransferLength %x\n", cbw->DataTransferLength);
108 	debug("Flags %x\n", cbw->Flags);
109 	debug("LUN %x\n", cbw->Lun);
110 	debug("Length %x\n", cbw->Length);
111 	debug("OptionCode %x\n", cbw->CDB[0]);
112 	debug("SubCode %x\n", cbw->CDB[1]);
113 	debug("SectorAddr %x\n", get_unaligned_be32(&cbw->CDB[2]));
114 	debug("BlkSectors %x\n\n", get_unaligned_be16(&cbw->CDB[7]));
115 }
116 
117 static int rkusb_check_lun(struct fsg_common *common)
118 {
119 	struct fsg_lun *curlun;
120 
121 	/* Check the LUN */
122 	if (common->lun >= 0 && common->lun < common->nluns) {
123 		curlun = &common->luns[common->lun];
124 		if (common->cmnd[0] != SC_REQUEST_SENSE) {
125 			curlun->sense_data = SS_NO_SENSE;
126 			curlun->info_valid = 0;
127 		}
128 	} else {
129 		curlun = NULL;
130 		common->bad_lun_okay = 0;
131 
132 		/*
133 		 * INQUIRY and REQUEST SENSE commands are explicitly allowed
134 		 * to use unsupported LUNs; all others may not.
135 		 */
136 		if (common->cmnd[0] != SC_INQUIRY &&
137 		    common->cmnd[0] != SC_REQUEST_SENSE) {
138 			debug("unsupported LUN %d\n", common->lun);
139 			return -EINVAL;
140 		}
141 	}
142 
143 	return 0;
144 }
145 
146 static void __do_reset(struct usb_ep *ep, struct usb_request *req)
147 {
148 	u32 boot_flag = BOOT_NORMAL;
149 
150 	if (rkusb_rst_code == 0x03)
151 		boot_flag = BOOT_BROM_DOWNLOAD;
152 
153 	rkusb_rst_code = 0; /* restore to default */
154 	writel(boot_flag, (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG);
155 
156 	do_reset(NULL, 0, 0, NULL);
157 }
158 
159 static int rkusb_do_reset(struct fsg_common *common,
160 			  struct fsg_buffhd *bh)
161 {
162 	common->data_size_from_cmnd = common->cmnd[4];
163 	common->residue = 0;
164 	bh->inreq->complete = __do_reset;
165 	bh->state = BUF_STATE_EMPTY;
166 
167 	rkusb_rst_code = !common->cmnd[1] ? 0xff : common->cmnd[1];
168 	return 0;
169 }
170 
171 static int rkusb_do_test_unit_ready(struct fsg_common *common,
172 				    struct fsg_buffhd *bh)
173 {
174 	common->residue = 0x06 << 24; /* Max block xfer support from host */
175 	common->data_dir = DATA_DIR_NONE;
176 	bh->state = BUF_STATE_EMPTY;
177 
178 	return 0;
179 }
180 
181 static int rkusb_do_read_flash_id(struct fsg_common *common,
182 				  struct fsg_buffhd *bh)
183 {
184 	u8 *buf = (u8 *)bh->buf;
185 	u32 len = 5;
186 	enum if_type type = ums[common->lun].block_dev.if_type;
187 
188 	if (type == IF_TYPE_MMC)
189 		memcpy((void *)&buf[0], "EMMC ", 5);
190 	else if (type == IF_TYPE_RKNAND)
191 		memcpy((void *)&buf[0], "NAND ", 5);
192 	else
193 		memcpy((void *)&buf[0], "UNKN ", 5); /* unknown */
194 
195 	/* Set data xfer size */
196 	common->residue = common->data_size_from_cmnd = len;
197 	common->data_size = len;
198 
199 	return len;
200 }
201 
202 static int rkusb_do_test_bad_block(struct fsg_common *common,
203 				   struct fsg_buffhd *bh)
204 {
205 	u8 *buf = (u8 *)bh->buf;
206 	u32 len = 64;
207 
208 	memset((void *)&buf[0], 0, len);
209 
210 	/* Set data xfer size */
211 	common->residue = common->data_size_from_cmnd = len;
212 	common->data_size = len;
213 
214 	return len;
215 }
216 
217 static int rkusb_do_read_flash_info(struct fsg_common *common,
218 				    struct fsg_buffhd *bh)
219 {
220 	struct blk_desc *desc = &ums[common->lun].block_dev;
221 	u8 *buf = (u8 *)bh->buf;
222 	u32 len = sizeof(struct rk_flash_info);
223 	struct rk_flash_info finfo = {
224 		.block_size = ROCKCHIP_FLASH_BLOCK_SIZE,
225 		.ecc_bits = 0,
226 		.page_size = ROCKCHIP_FLASH_PAGE_SIZE,
227 		.access_time = 40,
228 		.manufacturer = 0,
229 		.flash_mask = 0
230 	};
231 
232 	finfo.flash_size = (u32)desc->lba;
233 
234 	if (desc->if_type == IF_TYPE_MTD &&
235 	    (desc->devnum == BLK_MTD_NAND ||
236 	    desc->devnum == BLK_MTD_SPI_NAND)) {
237 		struct mtd_info *mtd = (struct mtd_info *)desc->bdev->priv;
238 
239 		if (mtd) {
240 			finfo.block_size = mtd->erasesize >> 9;
241 			finfo.page_size = mtd->writesize >> 9;
242 		}
243 	}
244 
245 	debug("Flash info: block_size= %x page_size= %x\n", finfo.block_size,
246 	      finfo.page_size);
247 
248 	if (finfo.flash_size)
249 		finfo.flash_mask = 1;
250 
251 	memset((void *)&buf[0], 0, len);
252 	memcpy((void *)&buf[0], (void *)&finfo, len);
253 
254 	/* Set data xfer size */
255 	common->residue = common->data_size_from_cmnd = len;
256         /* legacy upgrade_tool does not set correct transfer size */
257 	common->data_size = len;
258 
259 	return len;
260 }
261 
262 static int rkusb_do_get_chip_info(struct fsg_common *common,
263 				  struct fsg_buffhd *bh)
264 {
265 	u8 *buf = (u8 *)bh->buf;
266 	u32 len = common->data_size;
267 	u32 chip_info[4];
268 
269 	memset((void *)chip_info, 0, sizeof(chip_info));
270 	rockchip_rockusb_get_chip_info(chip_info);
271 
272 	memset((void *)&buf[0], 0, len);
273 	memcpy((void *)&buf[0], (void *)chip_info, len);
274 
275 	/* Set data xfer size */
276 	common->residue = common->data_size_from_cmnd = len;
277 
278 	return len;
279 }
280 
281 static int rkusb_do_lba_erase(struct fsg_common *common,
282 			      struct fsg_buffhd *bh)
283 {
284 	struct fsg_lun *curlun = &common->luns[common->lun];
285 	u32 lba, amount;
286 	loff_t file_offset;
287 	int rc;
288 
289 	lba = get_unaligned_be32(&common->cmnd[2]);
290 	if (lba >= curlun->num_sectors) {
291 		curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
292 		rc = -EINVAL;
293 		goto out;
294 	}
295 
296 	file_offset = ((loff_t) lba) << 9;
297 	amount = get_unaligned_be16(&common->cmnd[7]) << 9;
298 	if (unlikely(amount == 0)) {
299 		curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
300 		rc = -EIO;
301 		goto out;
302 	}
303 
304 	/* Perform the erase */
305 	rc = ums[common->lun].erase_sector(&ums[common->lun],
306 			       file_offset / SECTOR_SIZE,
307 			       amount / SECTOR_SIZE);
308 	if (!rc) {
309 		curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
310 		rc = -EIO;
311 	}
312 
313 out:
314 	common->data_dir = DATA_DIR_NONE;
315 	bh->state = BUF_STATE_EMPTY;
316 
317 	return rc;
318 }
319 
320 static int rkusb_do_erase_force(struct fsg_common *common,
321 				struct fsg_buffhd *bh)
322 {
323 	struct blk_desc *desc = &ums[common->lun].block_dev;
324 	struct fsg_lun *curlun = &common->luns[common->lun];
325 	u16 block_size = ROCKCHIP_FLASH_BLOCK_SIZE;
326 	u32 lba, amount;
327 	loff_t file_offset;
328 	int rc;
329 
330 	lba = get_unaligned_be32(&common->cmnd[2]);
331 	if (lba >= curlun->num_sectors) {
332 		curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
333 		rc = -EINVAL;
334 		goto out;
335 	}
336 
337 	if (desc->if_type == IF_TYPE_MTD &&
338 	    (desc->devnum == BLK_MTD_NAND ||
339 	    desc->devnum == BLK_MTD_SPI_NAND)) {
340 		struct mtd_info *mtd = (struct mtd_info *)desc->bdev->priv;
341 
342 		if (mtd)
343 			block_size = mtd->erasesize >> 9;
344 	}
345 
346 	file_offset = ((loff_t)lba) * block_size;
347 	amount = get_unaligned_be16(&common->cmnd[7]) * block_size;
348 
349 	debug("%s lba= %x, nsec= %x\n", __func__, lba,
350 	      (u32)get_unaligned_be16(&common->cmnd[7]));
351 
352 	if (unlikely(amount == 0)) {
353 		curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
354 		rc = -EIO;
355 		goto out;
356 	}
357 
358 	/* Perform the erase */
359 	rc = ums[common->lun].erase_sector(&ums[common->lun],
360 					   file_offset,
361 					   amount);
362 	if (!rc) {
363 		curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
364 		rc = -EIO;
365 	}
366 
367 out:
368 	common->data_dir = DATA_DIR_NONE;
369 	bh->state = BUF_STATE_EMPTY;
370 
371 	return rc;
372 }
373 
374 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION
375 static int rkusb_do_vs_write(struct fsg_common *common)
376 {
377 	struct fsg_lun		*curlun = &common->luns[common->lun];
378 	u16			type = get_unaligned_be16(&common->cmnd[4]);
379 	struct vendor_item	*vhead;
380 	struct fsg_buffhd	*bh;
381 	void			*data;
382 	int			rc;
383 
384 	if (common->data_size >= (u32)65536) {
385 		/* _MUST_ small than 64K */
386 		curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
387 		return -EINVAL;
388 	}
389 
390 	common->residue         = common->data_size;
391 	common->usb_amount_left = common->data_size;
392 
393 	/* Carry out the file writes */
394 	if (unlikely(common->data_size == 0))
395 		return -EIO; /* No data to write */
396 
397 	for (;;) {
398 		if (common->usb_amount_left > 0) {
399 			/* Wait for the next buffer to become available */
400 			bh = common->next_buffhd_to_fill;
401 			if (bh->state != BUF_STATE_EMPTY)
402 				goto wait;
403 
404 			/* Request the next buffer */
405 			common->usb_amount_left      -= common->data_size;
406 			bh->outreq->length	     = common->data_size;
407 			bh->bulk_out_intended_length = common->data_size;
408 			bh->outreq->short_not_ok     = 1;
409 
410 			START_TRANSFER_OR(common, bulk_out, bh->outreq,
411 					  &bh->outreq_busy, &bh->state)
412 				/*
413 				 * Don't know what to do if
414 				 * common->fsg is NULL
415 				 */
416 				return -EIO;
417 			common->next_buffhd_to_fill = bh->next;
418 		} else {
419 			/* Then, wait for the data to become available */
420 			bh = common->next_buffhd_to_drain;
421 			if (bh->state != BUF_STATE_FULL)
422 				goto wait;
423 
424 			common->next_buffhd_to_drain = bh->next;
425 			bh->state = BUF_STATE_EMPTY;
426 
427 			/* Did something go wrong with the transfer? */
428 			if (bh->outreq->status != 0) {
429 				curlun->sense_data = SS_COMMUNICATION_FAILURE;
430 				curlun->info_valid = 1;
431 				break;
432 			}
433 
434 			/* Perform the write */
435 			vhead = (struct vendor_item *)bh->buf;
436 			data  = bh->buf + sizeof(struct vendor_item);
437 
438 			if (!type) {
439 				/* Vendor storage */
440 				rc = vendor_storage_write(vhead->id,
441 							  (char __user *)data,
442 							  vhead->size);
443 				if (rc < 0) {
444 					curlun->sense_data = SS_WRITE_ERROR;
445 					return -EIO;
446 				}
447 			} else {
448 				/* RPMB */
449 				rc =
450 				write_keybox_to_secure_storage((u8 *)data,
451 							       vhead->size);
452 				if (rc < 0) {
453 					curlun->sense_data = SS_WRITE_ERROR;
454 					return -EIO;
455 				}
456 			}
457 
458 			common->residue -= common->data_size;
459 
460 			/* Did the host decide to stop early? */
461 			if (bh->outreq->actual != bh->outreq->length)
462 				common->short_packet_received = 1;
463 			break; /* Command done */
464 		}
465 wait:
466 		/* Wait for something to happen */
467 		rc = sleep_thread(common);
468 		if (rc)
469 			return rc;
470 	}
471 
472 	return -EIO; /* No default reply */
473 }
474 
475 static int rkusb_do_vs_read(struct fsg_common *common)
476 {
477 	struct fsg_lun		*curlun = &common->luns[common->lun];
478 	u16			type = get_unaligned_be16(&common->cmnd[4]);
479 	struct vendor_item	*vhead;
480 	struct fsg_buffhd	*bh;
481 	void			*data;
482 	int			rc;
483 
484 	if (common->data_size >= (u32)65536) {
485 		/* _MUST_ small than 64K */
486 		curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
487 		return -EINVAL;
488 	}
489 
490 	common->residue         = common->data_size;
491 	common->usb_amount_left = common->data_size;
492 
493 	/* Carry out the file reads */
494 	if (unlikely(common->data_size == 0))
495 		return -EIO; /* No default reply */
496 
497 	for (;;) {
498 		/* Wait for the next buffer to become available */
499 		bh = common->next_buffhd_to_fill;
500 		while (bh->state != BUF_STATE_EMPTY) {
501 			rc = sleep_thread(common);
502 			if (rc)
503 				return rc;
504 		}
505 
506 		memset(bh->buf, 0, FSG_BUFLEN);
507 		vhead = (struct vendor_item *)bh->buf;
508 		data  = bh->buf + sizeof(struct vendor_item);
509 		vhead->id = get_unaligned_be16(&common->cmnd[2]);
510 
511 		if (!type) {
512 			/* Vendor storage */
513 			rc = vendor_storage_read(vhead->id,
514 						 (char __user *)data,
515 						 common->data_size);
516 			if (!rc) {
517 				curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
518 				return -EIO;
519 			}
520 			vhead->size = rc;
521 		} else {
522 			/* RPMB */
523 			rc =
524 			read_raw_data_from_secure_storage((u8 *)data,
525 							  common->data_size);
526 			if (!rc) {
527 				curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
528 				return -EIO;
529 			}
530 			vhead->size = rc;
531 		}
532 
533 		common->residue   -= common->data_size;
534 		bh->inreq->length = common->data_size;
535 		bh->state         = BUF_STATE_FULL;
536 
537 		break; /* No more left to read */
538 	}
539 
540 	return -EIO; /* No default reply */
541 }
542 #endif
543 
544 static int rkusb_do_read_capacity(struct fsg_common *common,
545 				  struct fsg_buffhd *bh)
546 {
547 	u8 *buf = (u8 *)bh->buf;
548 	u32 len = common->data_size;
549 	enum if_type type = ums[common->lun].block_dev.if_type;
550 	int devnum = ums[common->lun].block_dev.devnum;
551 
552 	/*
553 	 * bit[0]: Direct LBA, 0: Disabled;
554 	 * bit[1]: Vendor Storage API, 0: Disabed (default);
555 	 * bit[2]: First 4M Access, 0: Disabled;
556 	 * bit[3]: Read LBA On, 0: Disabed (default);
557 	 * bit[4]: New Vendor Storage API, 0: Disabed;
558 	 * bit[5:63}: Reserved.
559 	 */
560 	memset((void *)&buf[0], 0, len);
561 	if (type == IF_TYPE_MMC || type == IF_TYPE_SD)
562 		buf[0] = BIT(0) | BIT(2) | BIT(4);
563 	else
564 		buf[0] = BIT(0) | BIT(4);
565 
566 	if (type == IF_TYPE_MTD &&
567 	    (devnum == BLK_MTD_NAND ||
568 	    devnum == BLK_MTD_SPI_NAND))
569 		buf[0] |= (1 << 6);
570 
571 #if defined(CONFIG_ROCKCHIP_RK3568)
572 	buf[1] = BIT(0);
573 #endif
574 	/* Set data xfer size */
575 	common->residue = len;
576 	common->data_size_from_cmnd = len;
577 
578 	return len;
579 }
580 
581 static void rkusb_fixup_cbwcb(struct fsg_common *common,
582 			      struct fsg_buffhd *bh)
583 {
584 	struct usb_request      *req = bh->outreq;
585 	struct fsg_bulk_cb_wrap *cbw = req->buf;
586 
587 	/* FIXME cbw.DataTransferLength was not set by Upgrade Tool */
588 	common->data_size = le32_to_cpu(cbw->DataTransferLength);
589 	if (common->data_size == 0) {
590 		common->data_size =
591 		get_unaligned_be16(&common->cmnd[7]) << 9;
592 		printf("Trasfer Length NOT set, please use new version tool\n");
593 		debug("%s %d, cmnd1 %x\n", __func__,
594 		      get_unaligned_be16(&common->cmnd[7]),
595 		      get_unaligned_be16(&common->cmnd[1]));
596 	}
597 	if (cbw->Flags & USB_BULK_IN_FLAG)
598 		common->data_dir = DATA_DIR_TO_HOST;
599 	else
600 		common->data_dir = DATA_DIR_FROM_HOST;
601 
602 	/* Not support */
603 	common->cmnd[1] = 0;
604 }
605 
606 static int rkusb_cmd_process(struct fsg_common *common,
607 			     struct fsg_buffhd *bh, int *reply)
608 {
609 	struct usb_request	*req = bh->outreq;
610 	struct fsg_bulk_cb_wrap	*cbw = req->buf;
611 	int rc;
612 
613 	dump_cbw(cbw);
614 
615 	if (rkusb_check_lun(common)) {
616 		*reply = -EINVAL;
617 		return RKUSB_RC_ERROR;
618 	}
619 
620 	switch (common->cmnd[0]) {
621 	case RKUSB_TEST_UNIT_READY:
622 		*reply = rkusb_do_test_unit_ready(common, bh);
623 		rc = RKUSB_RC_FINISHED;
624 		break;
625 
626 	case RKUSB_READ_FLASH_ID:
627 		*reply = rkusb_do_read_flash_id(common, bh);
628 		rc = RKUSB_RC_FINISHED;
629 		break;
630 
631 	case RKUSB_TEST_BAD_BLOCK:
632 		*reply = rkusb_do_test_bad_block(common, bh);
633 		rc = RKUSB_RC_FINISHED;
634 		break;
635 
636 	case RKUSB_ERASE_10_FORCE:
637 		*reply = rkusb_do_erase_force(common, bh);
638 		rc = RKUSB_RC_FINISHED;
639 		break;
640 
641 	case RKUSB_LBA_READ_10:
642 		rkusb_fixup_cbwcb(common, bh);
643 		common->cmnd[0] = SC_READ_10;
644 		common->cmnd[1] = 0; /* Not support */
645 		rc = RKUSB_RC_CONTINUE;
646 		break;
647 
648 	case RKUSB_LBA_WRITE_10:
649 		rkusb_fixup_cbwcb(common, bh);
650 		common->cmnd[0] = SC_WRITE_10;
651 		common->cmnd[1] = 0; /* Not support */
652 		rc = RKUSB_RC_CONTINUE;
653 		break;
654 
655 	case RKUSB_READ_FLASH_INFO:
656 		*reply = rkusb_do_read_flash_info(common, bh);
657 		rc = RKUSB_RC_FINISHED;
658 		break;
659 
660 	case RKUSB_GET_CHIP_VER:
661 		*reply = rkusb_do_get_chip_info(common, bh);
662 		rc = RKUSB_RC_FINISHED;
663 		break;
664 
665 	case RKUSB_LBA_ERASE:
666 		*reply = rkusb_do_lba_erase(common, bh);
667 		rc = RKUSB_RC_FINISHED;
668 		break;
669 
670 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION
671 	case RKUSB_VS_WRITE:
672 		*reply = rkusb_do_vs_write(common);
673 		rc = RKUSB_RC_FINISHED;
674 		break;
675 
676 	case RKUSB_VS_READ:
677 		*reply = rkusb_do_vs_read(common);
678 		rc = RKUSB_RC_FINISHED;
679 		break;
680 #endif
681 
682 	case RKUSB_READ_CAPACITY:
683 		*reply = rkusb_do_read_capacity(common, bh);
684 		rc = RKUSB_RC_FINISHED;
685 		break;
686 
687 	case RKUSB_RESET:
688 		*reply = rkusb_do_reset(common, bh);
689 		rc = RKUSB_RC_FINISHED;
690 		break;
691 
692 	case RKUSB_READ_10:
693 	case RKUSB_WRITE_10:
694 		printf("CMD Not support, pls use new version Tool\n");
695 	case RKUSB_SET_DEVICE_ID:
696 	case RKUSB_ERASE_10:
697 	case RKUSB_WRITE_SPARE:
698 	case RKUSB_READ_SPARE:
699 	case RKUSB_GET_VERSION:
700 	case RKUSB_ERASE_SYS_DISK:
701 	case RKUSB_SDRAM_READ_10:
702 	case RKUSB_SDRAM_WRITE_10:
703 	case RKUSB_SDRAM_EXECUTE:
704 	case RKUSB_LOW_FORMAT:
705 	case RKUSB_SET_RESET_FLAG:
706 	case RKUSB_SPI_READ_10:
707 	case RKUSB_SPI_WRITE_10:
708 	case RKUSB_SESSION:
709 		/* Fall through */
710 	default:
711 		rc = RKUSB_RC_UNKNOWN_CMND;
712 		break;
713 	}
714 
715 	return rc;
716 }
717 
718 DECLARE_GADGET_BIND_CALLBACK(rkusb_ums_dnl, fsg_add);
719