forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/usb/storage/ene_ub6250.c
....@@ -26,6 +26,7 @@
2626
2727 MODULE_DESCRIPTION("Driver for ENE UB6250 reader");
2828 MODULE_LICENSE("GPL");
29
+MODULE_IMPORT_NS(USB_STORAGE);
2930 MODULE_FIRMWARE(SD_INIT1_FIRMWARE);
3031 MODULE_FIRMWARE(SD_INIT2_FIRMWARE);
3132 MODULE_FIRMWARE(SD_RW_FIRMWARE);
....@@ -236,36 +237,33 @@
236237 #define memstick_logaddr(logadr1, logadr0) ((((u16)(logadr1)) << 8) | (logadr0))
237238
238239
239
-struct SD_STATUS {
240
- u8 Insert:1;
241
- u8 Ready:1;
242
- u8 MediaChange:1;
243
- u8 IsMMC:1;
244
- u8 HiCapacity:1;
245
- u8 HiSpeed:1;
246
- u8 WtP:1;
247
- u8 Reserved:1;
248
-};
240
+/* SD_STATUS bits */
241
+#define SD_Insert BIT(0)
242
+#define SD_Ready BIT(1)
243
+#define SD_MediaChange BIT(2)
244
+#define SD_IsMMC BIT(3)
245
+#define SD_HiCapacity BIT(4)
246
+#define SD_HiSpeed BIT(5)
247
+#define SD_WtP BIT(6)
248
+ /* Bit 7 reserved */
249249
250
-struct MS_STATUS {
251
- u8 Insert:1;
252
- u8 Ready:1;
253
- u8 MediaChange:1;
254
- u8 IsMSPro:1;
255
- u8 IsMSPHG:1;
256
- u8 Reserved1:1;
257
- u8 WtP:1;
258
- u8 Reserved2:1;
259
-};
250
+/* MS_STATUS bits */
251
+#define MS_Insert BIT(0)
252
+#define MS_Ready BIT(1)
253
+#define MS_MediaChange BIT(2)
254
+#define MS_IsMSPro BIT(3)
255
+#define MS_IsMSPHG BIT(4)
256
+ /* Bit 5 reserved */
257
+#define MS_WtP BIT(6)
258
+ /* Bit 7 reserved */
260259
261
-struct SM_STATUS {
262
- u8 Insert:1;
263
- u8 Ready:1;
264
- u8 MediaChange:1;
265
- u8 Reserved:3;
266
- u8 WtP:1;
267
- u8 IsMS:1;
268
-};
260
+/* SM_STATUS bits */
261
+#define SM_Insert BIT(0)
262
+#define SM_Ready BIT(1)
263
+#define SM_MediaChange BIT(2)
264
+ /* Bits 3-5 reserved */
265
+#define SM_WtP BIT(6)
266
+#define SM_IsMS BIT(7)
269267
270268 struct ms_bootblock_cis {
271269 u8 bCistplDEVICE[6]; /* 0 */
....@@ -436,9 +434,9 @@
436434 u8 *bbuf;
437435
438436 /* for 6250 code */
439
- struct SD_STATUS SD_Status;
440
- struct MS_STATUS MS_Status;
441
- struct SM_STATUS SM_Status;
437
+ u8 SD_Status;
438
+ u8 MS_Status;
439
+ u8 SM_Status;
442440
443441 /* ----- SD Control Data ---------------- */
444442 /*SD_REGISTER SD_Regs; */
....@@ -560,7 +558,7 @@
560558 residue = min(residue, transfer_length);
561559 if (us->srb != NULL)
562560 scsi_set_resid(us->srb, max(scsi_get_resid(us->srb),
563
- (int)residue));
561
+ residue));
564562 }
565563
566564 if (bcs->Status != US_BULK_STAT_OK)
....@@ -601,7 +599,7 @@
601599 {
602600 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
603601
604
- if (info->SD_Status.Insert && info->SD_Status.Ready)
602
+ if ((info->SD_Status & SD_Insert) && (info->SD_Status & SD_Ready))
605603 return USB_STOR_TRANSPORT_GOOD;
606604 else {
607605 ene_sd_init(us);
....@@ -621,7 +619,7 @@
621619 0x0b, 0x00, 0x80, 0x08, 0x00, 0x00,
622620 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
623621
624
- if (info->SD_Status.WtP)
622
+ if (info->SD_Status & SD_WtP)
625623 usb_stor_set_xfer_buf(mediaWP, 12, srb);
626624 else
627625 usb_stor_set_xfer_buf(mediaNoWP, 12, srb);
....@@ -640,9 +638,9 @@
640638 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
641639
642640 usb_stor_dbg(us, "sd_scsi_read_capacity\n");
643
- if (info->SD_Status.HiCapacity) {
641
+ if (info->SD_Status & SD_HiCapacity) {
644642 bl_len = 0x200;
645
- if (info->SD_Status.IsMMC)
643
+ if (info->SD_Status & SD_IsMMC)
646644 bl_num = info->HC_C_SIZE-1;
647645 else
648646 bl_num = (info->HC_C_SIZE + 1) * 1024 - 1;
....@@ -692,7 +690,7 @@
692690 return USB_STOR_TRANSPORT_ERROR;
693691 }
694692
695
- if (info->SD_Status.HiCapacity)
693
+ if (info->SD_Status & SD_HiCapacity)
696694 bnByte = bn;
697695
698696 /* set up the command wrapper */
....@@ -732,7 +730,7 @@
732730 return USB_STOR_TRANSPORT_ERROR;
733731 }
734732
735
- if (info->SD_Status.HiCapacity)
733
+ if (info->SD_Status & SD_HiCapacity)
736734 bnByte = bn;
737735
738736 /* set up the command wrapper */
....@@ -940,7 +938,7 @@
940938 struct ms_lib_type_extdat ExtraData;
941939 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
942940
943
- PageBuffer = kmalloc(MS_BYTES_PER_PAGE, GFP_KERNEL);
941
+ PageBuffer = kzalloc(MS_BYTES_PER_PAGE * 2, GFP_KERNEL);
944942 if (PageBuffer == NULL)
945943 return (u32)-1;
946944
....@@ -1131,7 +1129,7 @@
11311129
11321130 ms_lib_clear_writebuf(us);
11331131
1134
-return 0;
1132
+ return 0;
11351133 }
11361134
11371135 static int ms_lib_force_setlogical_pair(struct us_data *us, u16 logblk, u16 phyblk)
....@@ -1454,7 +1452,7 @@
14541452 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra);
14551453
14561454 /* pr_info("MS_SCSI_Test_Unit_Ready\n"); */
1457
- if (info->MS_Status.Insert && info->MS_Status.Ready) {
1455
+ if ((info->MS_Status & MS_Insert) && (info->MS_Status & MS_Ready)) {
14581456 return USB_STOR_TRANSPORT_GOOD;
14591457 } else {
14601458 ene_ms_init(us);
....@@ -1474,7 +1472,7 @@
14741472 0x0b, 0x00, 0x80, 0x08, 0x00, 0x00,
14751473 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
14761474
1477
- if (info->MS_Status.WtP)
1475
+ if (info->MS_Status & MS_WtP)
14781476 usb_stor_set_xfer_buf(mediaWP, 12, srb);
14791477 else
14801478 usb_stor_set_xfer_buf(mediaNoWP, 12, srb);
....@@ -1493,7 +1491,7 @@
14931491
14941492 usb_stor_dbg(us, "ms_scsi_read_capacity\n");
14951493 bl_len = 0x200;
1496
- if (info->MS_Status.IsMSPro)
1494
+ if (info->MS_Status & MS_IsMSPro)
14971495 bl_num = info->MSP_TotalBlock - 1;
14981496 else
14991497 bl_num = info->MS_Lib.NumberOfLogBlock * info->MS_Lib.blockSize * 2 - 1;
....@@ -1648,7 +1646,7 @@
16481646 if (bn > info->bl_num)
16491647 return USB_STOR_TRANSPORT_ERROR;
16501648
1651
- if (info->MS_Status.IsMSPro) {
1649
+ if (info->MS_Status & MS_IsMSPro) {
16521650 result = ene_load_bincode(us, MSP_RW_PATTERN);
16531651 if (result != USB_STOR_XFER_GOOD) {
16541652 usb_stor_dbg(us, "Load MPS RW pattern Fail !!\n");
....@@ -1749,7 +1747,7 @@
17491747 if (bn > info->bl_num)
17501748 return USB_STOR_TRANSPORT_ERROR;
17511749
1752
- if (info->MS_Status.IsMSPro) {
1750
+ if (info->MS_Status & MS_IsMSPro) {
17531751 result = ene_load_bincode(us, MSP_RW_PATTERN);
17541752 if (result != USB_STOR_XFER_GOOD) {
17551753 pr_info("Load MSP RW pattern Fail !!\n");
....@@ -1857,12 +1855,12 @@
18571855
18581856 tmpreg = (u16) reg4b;
18591857 reg4b = *(u32 *)(&buf[0x14]);
1860
- if (info->SD_Status.HiCapacity && !info->SD_Status.IsMMC)
1858
+ if ((info->SD_Status & SD_HiCapacity) && !(info->SD_Status & SD_IsMMC))
18611859 info->HC_C_SIZE = (reg4b >> 8) & 0x3fffff;
18621860
18631861 info->SD_C_SIZE = ((tmpreg & 0x03) << 10) | (u16)(reg4b >> 22);
18641862 info->SD_C_SIZE_MULT = (u8)(reg4b >> 7) & 0x07;
1865
- if (info->SD_Status.HiCapacity && info->SD_Status.IsMMC)
1863
+ if ((info->SD_Status & SD_HiCapacity) && (info->SD_Status & SD_IsMMC))
18661864 info->HC_C_SIZE = *(u32 *)(&buf[0x100]);
18671865
18681866 if (info->SD_READ_BL_LEN > SD_BLOCK_LEN) {
....@@ -2074,6 +2072,7 @@
20742072 u16 MSP_BlockSize, MSP_UserAreaBlocks;
20752073 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
20762074 u8 *bbuf = info->bbuf;
2075
+ unsigned int s;
20772076
20782077 printk(KERN_INFO "transport --- ENE_MSInit\n");
20792078
....@@ -2098,15 +2097,16 @@
20982097 return USB_STOR_TRANSPORT_ERROR;
20992098 }
21002099 /* the same part to test ENE */
2101
- info->MS_Status = *(struct MS_STATUS *) bbuf;
2100
+ info->MS_Status = bbuf[0];
21022101
2103
- if (info->MS_Status.Insert && info->MS_Status.Ready) {
2104
- printk(KERN_INFO "Insert = %x\n", info->MS_Status.Insert);
2105
- printk(KERN_INFO "Ready = %x\n", info->MS_Status.Ready);
2106
- printk(KERN_INFO "IsMSPro = %x\n", info->MS_Status.IsMSPro);
2107
- printk(KERN_INFO "IsMSPHG = %x\n", info->MS_Status.IsMSPHG);
2108
- printk(KERN_INFO "WtP= %x\n", info->MS_Status.WtP);
2109
- if (info->MS_Status.IsMSPro) {
2102
+ s = info->MS_Status;
2103
+ if ((s & MS_Insert) && (s & MS_Ready)) {
2104
+ printk(KERN_INFO "Insert = %x\n", !!(s & MS_Insert));
2105
+ printk(KERN_INFO "Ready = %x\n", !!(s & MS_Ready));
2106
+ printk(KERN_INFO "IsMSPro = %x\n", !!(s & MS_IsMSPro));
2107
+ printk(KERN_INFO "IsMSPHG = %x\n", !!(s & MS_IsMSPHG));
2108
+ printk(KERN_INFO "WtP= %x\n", !!(s & MS_WtP));
2109
+ if (s & MS_IsMSPro) {
21102110 MSP_BlockSize = (bbuf[6] << 8) | bbuf[7];
21112111 MSP_UserAreaBlocks = (bbuf[10] << 8) | bbuf[11];
21122112 info->MSP_TotalBlock = MSP_BlockSize * MSP_UserAreaBlocks;
....@@ -2167,17 +2167,17 @@
21672167 return USB_STOR_TRANSPORT_ERROR;
21682168 }
21692169
2170
- info->SD_Status = *(struct SD_STATUS *) bbuf;
2171
- if (info->SD_Status.Insert && info->SD_Status.Ready) {
2172
- struct SD_STATUS *s = &info->SD_Status;
2170
+ info->SD_Status = bbuf[0];
2171
+ if ((info->SD_Status & SD_Insert) && (info->SD_Status & SD_Ready)) {
2172
+ unsigned int s = info->SD_Status;
21732173
21742174 ene_get_card_status(us, bbuf);
2175
- usb_stor_dbg(us, "Insert = %x\n", s->Insert);
2176
- usb_stor_dbg(us, "Ready = %x\n", s->Ready);
2177
- usb_stor_dbg(us, "IsMMC = %x\n", s->IsMMC);
2178
- usb_stor_dbg(us, "HiCapacity = %x\n", s->HiCapacity);
2179
- usb_stor_dbg(us, "HiSpeed = %x\n", s->HiSpeed);
2180
- usb_stor_dbg(us, "WtP = %x\n", s->WtP);
2175
+ usb_stor_dbg(us, "Insert = %x\n", !!(s & SD_Insert));
2176
+ usb_stor_dbg(us, "Ready = %x\n", !!(s & SD_Ready));
2177
+ usb_stor_dbg(us, "IsMMC = %x\n", !!(s & SD_IsMMC));
2178
+ usb_stor_dbg(us, "HiCapacity = %x\n", !!(s & SD_HiCapacity));
2179
+ usb_stor_dbg(us, "HiSpeed = %x\n", !!(s & SD_HiSpeed));
2180
+ usb_stor_dbg(us, "WtP = %x\n", !!(s & SD_WtP));
21812181 } else {
21822182 usb_stor_dbg(us, "SD Card Not Ready --- %x\n", bbuf[0]);
21832183 return USB_STOR_TRANSPORT_ERROR;
....@@ -2199,14 +2199,14 @@
21992199
22002200 misc_reg03 = bbuf[0];
22012201 if (misc_reg03 & 0x01) {
2202
- if (!info->SD_Status.Ready) {
2202
+ if (!(info->SD_Status & SD_Ready)) {
22032203 result = ene_sd_init(us);
22042204 if (result != USB_STOR_XFER_GOOD)
22052205 return USB_STOR_TRANSPORT_ERROR;
22062206 }
22072207 }
22082208 if (misc_reg03 & 0x02) {
2209
- if (!info->MS_Status.Ready) {
2209
+ if (!(info->MS_Status & MS_Ready)) {
22102210 result = ene_ms_init(us);
22112211 if (result != USB_STOR_XFER_GOOD)
22122212 return USB_STOR_TRANSPORT_ERROR;
....@@ -2305,14 +2305,14 @@
23052305
23062306 /*US_DEBUG(usb_stor_show_command(us, srb)); */
23072307 scsi_set_resid(srb, 0);
2308
- if (unlikely(!(info->SD_Status.Ready || info->MS_Status.Ready)))
2308
+ if (unlikely(!(info->SD_Status & SD_Ready) || (info->MS_Status & MS_Ready)))
23092309 result = ene_init(us);
23102310 if (result == USB_STOR_XFER_GOOD) {
23112311 result = USB_STOR_TRANSPORT_ERROR;
2312
- if (info->SD_Status.Ready)
2312
+ if (info->SD_Status & SD_Ready)
23132313 result = sd_scsi_irp(us, srb);
23142314
2315
- if (info->MS_Status.Ready)
2315
+ if (info->MS_Status & MS_Ready)
23162316 result = ms_scsi_irp(us, srb);
23172317 }
23182318 return result;
....@@ -2376,7 +2376,6 @@
23762376
23772377 static int ene_ub6250_resume(struct usb_interface *iface)
23782378 {
2379
- u8 tmp = 0;
23802379 struct us_data *us = usb_get_intfdata(iface);
23812380 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra);
23822381
....@@ -2388,17 +2387,16 @@
23882387 mutex_unlock(&us->dev_mutex);
23892388
23902389 info->Power_IsResum = true;
2391
- /*info->SD_Status.Ready = 0; */
2392
- info->SD_Status = *(struct SD_STATUS *)&tmp;
2393
- info->MS_Status = *(struct MS_STATUS *)&tmp;
2394
- info->SM_Status = *(struct SM_STATUS *)&tmp;
2390
+ /* info->SD_Status &= ~SD_Ready; */
2391
+ info->SD_Status = 0;
2392
+ info->MS_Status = 0;
2393
+ info->SM_Status = 0;
23952394
23962395 return 0;
23972396 }
23982397
23992398 static int ene_ub6250_reset_resume(struct usb_interface *iface)
24002399 {
2401
- u8 tmp = 0;
24022400 struct us_data *us = usb_get_intfdata(iface);
24032401 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra);
24042402
....@@ -2410,10 +2408,10 @@
24102408 * the device
24112409 */
24122410 info->Power_IsResum = true;
2413
- /*info->SD_Status.Ready = 0; */
2414
- info->SD_Status = *(struct SD_STATUS *)&tmp;
2415
- info->MS_Status = *(struct MS_STATUS *)&tmp;
2416
- info->SM_Status = *(struct SM_STATUS *)&tmp;
2411
+ /* info->SD_Status &= ~SD_Ready; */
2412
+ info->SD_Status = 0;
2413
+ info->MS_Status = 0;
2414
+ info->SM_Status = 0;
24172415
24182416 return 0;
24192417 }