.. | .. |
---|
26 | 26 | |
---|
27 | 27 | MODULE_DESCRIPTION("Driver for ENE UB6250 reader"); |
---|
28 | 28 | MODULE_LICENSE("GPL"); |
---|
| 29 | +MODULE_IMPORT_NS(USB_STORAGE); |
---|
29 | 30 | MODULE_FIRMWARE(SD_INIT1_FIRMWARE); |
---|
30 | 31 | MODULE_FIRMWARE(SD_INIT2_FIRMWARE); |
---|
31 | 32 | MODULE_FIRMWARE(SD_RW_FIRMWARE); |
---|
.. | .. |
---|
236 | 237 | #define memstick_logaddr(logadr1, logadr0) ((((u16)(logadr1)) << 8) | (logadr0)) |
---|
237 | 238 | |
---|
238 | 239 | |
---|
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 */ |
---|
249 | 249 | |
---|
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 */ |
---|
260 | 259 | |
---|
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) |
---|
269 | 267 | |
---|
270 | 268 | struct ms_bootblock_cis { |
---|
271 | 269 | u8 bCistplDEVICE[6]; /* 0 */ |
---|
.. | .. |
---|
436 | 434 | u8 *bbuf; |
---|
437 | 435 | |
---|
438 | 436 | /* 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; |
---|
442 | 440 | |
---|
443 | 441 | /* ----- SD Control Data ---------------- */ |
---|
444 | 442 | /*SD_REGISTER SD_Regs; */ |
---|
.. | .. |
---|
560 | 558 | residue = min(residue, transfer_length); |
---|
561 | 559 | if (us->srb != NULL) |
---|
562 | 560 | scsi_set_resid(us->srb, max(scsi_get_resid(us->srb), |
---|
563 | | - (int)residue)); |
---|
| 561 | + residue)); |
---|
564 | 562 | } |
---|
565 | 563 | |
---|
566 | 564 | if (bcs->Status != US_BULK_STAT_OK) |
---|
.. | .. |
---|
601 | 599 | { |
---|
602 | 600 | struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; |
---|
603 | 601 | |
---|
604 | | - if (info->SD_Status.Insert && info->SD_Status.Ready) |
---|
| 602 | + if ((info->SD_Status & SD_Insert) && (info->SD_Status & SD_Ready)) |
---|
605 | 603 | return USB_STOR_TRANSPORT_GOOD; |
---|
606 | 604 | else { |
---|
607 | 605 | ene_sd_init(us); |
---|
.. | .. |
---|
621 | 619 | 0x0b, 0x00, 0x80, 0x08, 0x00, 0x00, |
---|
622 | 620 | 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 }; |
---|
623 | 621 | |
---|
624 | | - if (info->SD_Status.WtP) |
---|
| 622 | + if (info->SD_Status & SD_WtP) |
---|
625 | 623 | usb_stor_set_xfer_buf(mediaWP, 12, srb); |
---|
626 | 624 | else |
---|
627 | 625 | usb_stor_set_xfer_buf(mediaNoWP, 12, srb); |
---|
.. | .. |
---|
640 | 638 | struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; |
---|
641 | 639 | |
---|
642 | 640 | usb_stor_dbg(us, "sd_scsi_read_capacity\n"); |
---|
643 | | - if (info->SD_Status.HiCapacity) { |
---|
| 641 | + if (info->SD_Status & SD_HiCapacity) { |
---|
644 | 642 | bl_len = 0x200; |
---|
645 | | - if (info->SD_Status.IsMMC) |
---|
| 643 | + if (info->SD_Status & SD_IsMMC) |
---|
646 | 644 | bl_num = info->HC_C_SIZE-1; |
---|
647 | 645 | else |
---|
648 | 646 | bl_num = (info->HC_C_SIZE + 1) * 1024 - 1; |
---|
.. | .. |
---|
692 | 690 | return USB_STOR_TRANSPORT_ERROR; |
---|
693 | 691 | } |
---|
694 | 692 | |
---|
695 | | - if (info->SD_Status.HiCapacity) |
---|
| 693 | + if (info->SD_Status & SD_HiCapacity) |
---|
696 | 694 | bnByte = bn; |
---|
697 | 695 | |
---|
698 | 696 | /* set up the command wrapper */ |
---|
.. | .. |
---|
732 | 730 | return USB_STOR_TRANSPORT_ERROR; |
---|
733 | 731 | } |
---|
734 | 732 | |
---|
735 | | - if (info->SD_Status.HiCapacity) |
---|
| 733 | + if (info->SD_Status & SD_HiCapacity) |
---|
736 | 734 | bnByte = bn; |
---|
737 | 735 | |
---|
738 | 736 | /* set up the command wrapper */ |
---|
.. | .. |
---|
940 | 938 | struct ms_lib_type_extdat ExtraData; |
---|
941 | 939 | struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; |
---|
942 | 940 | |
---|
943 | | - PageBuffer = kmalloc(MS_BYTES_PER_PAGE, GFP_KERNEL); |
---|
| 941 | + PageBuffer = kzalloc(MS_BYTES_PER_PAGE * 2, GFP_KERNEL); |
---|
944 | 942 | if (PageBuffer == NULL) |
---|
945 | 943 | return (u32)-1; |
---|
946 | 944 | |
---|
.. | .. |
---|
1131 | 1129 | |
---|
1132 | 1130 | ms_lib_clear_writebuf(us); |
---|
1133 | 1131 | |
---|
1134 | | -return 0; |
---|
| 1132 | + return 0; |
---|
1135 | 1133 | } |
---|
1136 | 1134 | |
---|
1137 | 1135 | static int ms_lib_force_setlogical_pair(struct us_data *us, u16 logblk, u16 phyblk) |
---|
.. | .. |
---|
1454 | 1452 | struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra); |
---|
1455 | 1453 | |
---|
1456 | 1454 | /* 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)) { |
---|
1458 | 1456 | return USB_STOR_TRANSPORT_GOOD; |
---|
1459 | 1457 | } else { |
---|
1460 | 1458 | ene_ms_init(us); |
---|
.. | .. |
---|
1474 | 1472 | 0x0b, 0x00, 0x80, 0x08, 0x00, 0x00, |
---|
1475 | 1473 | 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 }; |
---|
1476 | 1474 | |
---|
1477 | | - if (info->MS_Status.WtP) |
---|
| 1475 | + if (info->MS_Status & MS_WtP) |
---|
1478 | 1476 | usb_stor_set_xfer_buf(mediaWP, 12, srb); |
---|
1479 | 1477 | else |
---|
1480 | 1478 | usb_stor_set_xfer_buf(mediaNoWP, 12, srb); |
---|
.. | .. |
---|
1493 | 1491 | |
---|
1494 | 1492 | usb_stor_dbg(us, "ms_scsi_read_capacity\n"); |
---|
1495 | 1493 | bl_len = 0x200; |
---|
1496 | | - if (info->MS_Status.IsMSPro) |
---|
| 1494 | + if (info->MS_Status & MS_IsMSPro) |
---|
1497 | 1495 | bl_num = info->MSP_TotalBlock - 1; |
---|
1498 | 1496 | else |
---|
1499 | 1497 | bl_num = info->MS_Lib.NumberOfLogBlock * info->MS_Lib.blockSize * 2 - 1; |
---|
.. | .. |
---|
1648 | 1646 | if (bn > info->bl_num) |
---|
1649 | 1647 | return USB_STOR_TRANSPORT_ERROR; |
---|
1650 | 1648 | |
---|
1651 | | - if (info->MS_Status.IsMSPro) { |
---|
| 1649 | + if (info->MS_Status & MS_IsMSPro) { |
---|
1652 | 1650 | result = ene_load_bincode(us, MSP_RW_PATTERN); |
---|
1653 | 1651 | if (result != USB_STOR_XFER_GOOD) { |
---|
1654 | 1652 | usb_stor_dbg(us, "Load MPS RW pattern Fail !!\n"); |
---|
.. | .. |
---|
1749 | 1747 | if (bn > info->bl_num) |
---|
1750 | 1748 | return USB_STOR_TRANSPORT_ERROR; |
---|
1751 | 1749 | |
---|
1752 | | - if (info->MS_Status.IsMSPro) { |
---|
| 1750 | + if (info->MS_Status & MS_IsMSPro) { |
---|
1753 | 1751 | result = ene_load_bincode(us, MSP_RW_PATTERN); |
---|
1754 | 1752 | if (result != USB_STOR_XFER_GOOD) { |
---|
1755 | 1753 | pr_info("Load MSP RW pattern Fail !!\n"); |
---|
.. | .. |
---|
1857 | 1855 | |
---|
1858 | 1856 | tmpreg = (u16) reg4b; |
---|
1859 | 1857 | 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)) |
---|
1861 | 1859 | info->HC_C_SIZE = (reg4b >> 8) & 0x3fffff; |
---|
1862 | 1860 | |
---|
1863 | 1861 | info->SD_C_SIZE = ((tmpreg & 0x03) << 10) | (u16)(reg4b >> 22); |
---|
1864 | 1862 | 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)) |
---|
1866 | 1864 | info->HC_C_SIZE = *(u32 *)(&buf[0x100]); |
---|
1867 | 1865 | |
---|
1868 | 1866 | if (info->SD_READ_BL_LEN > SD_BLOCK_LEN) { |
---|
.. | .. |
---|
2074 | 2072 | u16 MSP_BlockSize, MSP_UserAreaBlocks; |
---|
2075 | 2073 | struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; |
---|
2076 | 2074 | u8 *bbuf = info->bbuf; |
---|
| 2075 | + unsigned int s; |
---|
2077 | 2076 | |
---|
2078 | 2077 | printk(KERN_INFO "transport --- ENE_MSInit\n"); |
---|
2079 | 2078 | |
---|
.. | .. |
---|
2098 | 2097 | return USB_STOR_TRANSPORT_ERROR; |
---|
2099 | 2098 | } |
---|
2100 | 2099 | /* the same part to test ENE */ |
---|
2101 | | - info->MS_Status = *(struct MS_STATUS *) bbuf; |
---|
| 2100 | + info->MS_Status = bbuf[0]; |
---|
2102 | 2101 | |
---|
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) { |
---|
2110 | 2110 | MSP_BlockSize = (bbuf[6] << 8) | bbuf[7]; |
---|
2111 | 2111 | MSP_UserAreaBlocks = (bbuf[10] << 8) | bbuf[11]; |
---|
2112 | 2112 | info->MSP_TotalBlock = MSP_BlockSize * MSP_UserAreaBlocks; |
---|
.. | .. |
---|
2167 | 2167 | return USB_STOR_TRANSPORT_ERROR; |
---|
2168 | 2168 | } |
---|
2169 | 2169 | |
---|
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; |
---|
2173 | 2173 | |
---|
2174 | 2174 | 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)); |
---|
2181 | 2181 | } else { |
---|
2182 | 2182 | usb_stor_dbg(us, "SD Card Not Ready --- %x\n", bbuf[0]); |
---|
2183 | 2183 | return USB_STOR_TRANSPORT_ERROR; |
---|
.. | .. |
---|
2199 | 2199 | |
---|
2200 | 2200 | misc_reg03 = bbuf[0]; |
---|
2201 | 2201 | if (misc_reg03 & 0x01) { |
---|
2202 | | - if (!info->SD_Status.Ready) { |
---|
| 2202 | + if (!(info->SD_Status & SD_Ready)) { |
---|
2203 | 2203 | result = ene_sd_init(us); |
---|
2204 | 2204 | if (result != USB_STOR_XFER_GOOD) |
---|
2205 | 2205 | return USB_STOR_TRANSPORT_ERROR; |
---|
2206 | 2206 | } |
---|
2207 | 2207 | } |
---|
2208 | 2208 | if (misc_reg03 & 0x02) { |
---|
2209 | | - if (!info->MS_Status.Ready) { |
---|
| 2209 | + if (!(info->MS_Status & MS_Ready)) { |
---|
2210 | 2210 | result = ene_ms_init(us); |
---|
2211 | 2211 | if (result != USB_STOR_XFER_GOOD) |
---|
2212 | 2212 | return USB_STOR_TRANSPORT_ERROR; |
---|
.. | .. |
---|
2305 | 2305 | |
---|
2306 | 2306 | /*US_DEBUG(usb_stor_show_command(us, srb)); */ |
---|
2307 | 2307 | 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))) |
---|
2309 | 2309 | result = ene_init(us); |
---|
2310 | 2310 | if (result == USB_STOR_XFER_GOOD) { |
---|
2311 | 2311 | result = USB_STOR_TRANSPORT_ERROR; |
---|
2312 | | - if (info->SD_Status.Ready) |
---|
| 2312 | + if (info->SD_Status & SD_Ready) |
---|
2313 | 2313 | result = sd_scsi_irp(us, srb); |
---|
2314 | 2314 | |
---|
2315 | | - if (info->MS_Status.Ready) |
---|
| 2315 | + if (info->MS_Status & MS_Ready) |
---|
2316 | 2316 | result = ms_scsi_irp(us, srb); |
---|
2317 | 2317 | } |
---|
2318 | 2318 | return result; |
---|
.. | .. |
---|
2376 | 2376 | |
---|
2377 | 2377 | static int ene_ub6250_resume(struct usb_interface *iface) |
---|
2378 | 2378 | { |
---|
2379 | | - u8 tmp = 0; |
---|
2380 | 2379 | struct us_data *us = usb_get_intfdata(iface); |
---|
2381 | 2380 | struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra); |
---|
2382 | 2381 | |
---|
.. | .. |
---|
2388 | 2387 | mutex_unlock(&us->dev_mutex); |
---|
2389 | 2388 | |
---|
2390 | 2389 | 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; |
---|
2395 | 2394 | |
---|
2396 | 2395 | return 0; |
---|
2397 | 2396 | } |
---|
2398 | 2397 | |
---|
2399 | 2398 | static int ene_ub6250_reset_resume(struct usb_interface *iface) |
---|
2400 | 2399 | { |
---|
2401 | | - u8 tmp = 0; |
---|
2402 | 2400 | struct us_data *us = usb_get_intfdata(iface); |
---|
2403 | 2401 | struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra); |
---|
2404 | 2402 | |
---|
.. | .. |
---|
2410 | 2408 | * the device |
---|
2411 | 2409 | */ |
---|
2412 | 2410 | 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; |
---|
2417 | 2415 | |
---|
2418 | 2416 | return 0; |
---|
2419 | 2417 | } |
---|