提交 41e568d1 编写于 作者: H huajun li 提交者: Greg Kroah-Hartman

Staging: Merge ENE UB6250 SD card codes from keucr to drivers/usb/storage

The usb portion of this driver can now go into drivers/usb/storage.
This leaves the non-usb portion of the code still in staging.
Signed-off-by: NHuajun Li <huajun.li.lee@gmail.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 153775d9
config USB_ENESTORAGE
tristate "USB ENE card reader support"
tristate "USB ENE SM/MS card reader support"
depends on USB && SCSI && m
---help---
Say Y here if you wish to control a ENE Card reader.
Say Y here if you wish to control a ENE SM/MS Card reader.
To use SD card, please build driver/usb/storage/ums-eneub6250.ko
This option depends on 'SCSI' support being enabled, but you
probably also need 'SCSI device support: SCSI disk support'
......
......@@ -7,7 +7,6 @@ keucr-y := \
scsiglue.o \
transport.o \
init.o \
sdscsi.o \
msscsi.o \
ms.o \
smscsi.o \
......
......@@ -30,14 +30,6 @@ int ENE_InitMedia(struct us_data *us)
}
printk(KERN_INFO "MiscReg03 = %x\n", MiscReg03);
if (MiscReg03 & 0x01) {
if (!us->SD_Status.Ready) {
result = ENE_SDInit(us);
if (result != USB_STOR_XFER_GOOD)
return USB_STOR_TRANSPORT_ERROR;
}
}
if (MiscReg03 & 0x02) {
if (!us->SM_Status.Ready && !us->MS_Status.Ready) {
result = ENE_SMInit(us);
......@@ -72,69 +64,6 @@ int ENE_Read_BYTE(struct us_data *us, WORD index, void *buf)
return result;
}
/*
* ENE_SDInit():
*/
int ENE_SDInit(struct us_data *us)
{
struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
int result;
BYTE buf[0x200];
printk(KERN_INFO "transport --- ENE_SDInit\n");
/* SD Init Part-1 */
result = ENE_LoadBinCode(us, SD_INIT1_PATTERN);
if (result != USB_STOR_XFER_GOOD) {
printk(KERN_ERR "Load SD Init Code Part-1 Fail !!\n");
return USB_STOR_TRANSPORT_ERROR;
}
memset(bcb, 0, sizeof(struct bulk_cb_wrap));
bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
bcb->Flags = 0x80;
bcb->CDB[0] = 0xF2;
result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0);
if (result != USB_STOR_XFER_GOOD) {
printk(KERN_ERR "Exection SD Init Code Fail !!\n");
return USB_STOR_TRANSPORT_ERROR;
}
/* SD Init Part-2 */
result = ENE_LoadBinCode(us, SD_INIT2_PATTERN);
if (result != USB_STOR_XFER_GOOD) {
printk(KERN_ERR "Load SD Init Code Part-2 Fail !!\n");
return USB_STOR_TRANSPORT_ERROR;
}
memset(bcb, 0, sizeof(struct bulk_cb_wrap));
bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
bcb->DataTransferLength = 0x200;
bcb->Flags = 0x80;
bcb->CDB[0] = 0xF1;
result = ENE_SendScsiCmd(us, FDIR_READ, &buf, 0);
if (result != USB_STOR_XFER_GOOD) {
printk(KERN_ERR "Exection SD Init Code Fail !!\n");
return USB_STOR_TRANSPORT_ERROR;
}
us->SD_Status = *(PSD_STATUS)&buf[0];
if (us->SD_Status.Insert && us->SD_Status.Ready) {
ENE_ReadSDReg(us, (PBYTE)&buf);
printk(KERN_INFO "Insert = %x\n", us->SD_Status.Insert);
printk(KERN_INFO "Ready = %x\n", us->SD_Status.Ready);
printk(KERN_INFO "IsMMC = %x\n", us->SD_Status.IsMMC);
printk(KERN_INFO "HiCapacity = %x\n", us->SD_Status.HiCapacity);
printk(KERN_INFO "HiSpeed = %x\n", us->SD_Status.HiSpeed);
printk(KERN_INFO "WtP = %x\n", us->SD_Status.WtP);
} else {
printk(KERN_ERR "SD Card Not Ready --- %x\n", buf[0]);
return USB_STOR_TRANSPORT_ERROR;
}
return USB_STOR_TRANSPORT_GOOD;
}
/*
* ENE_MSInit():
*/
......@@ -241,38 +170,6 @@ int ENE_SMInit(struct us_data *us)
return USB_STOR_TRANSPORT_GOOD;
}
/*
* ENE_ReadSDReg()
*/
int ENE_ReadSDReg(struct us_data *us, u8 *RdBuf)
{
WORD tmpreg;
DWORD reg4b;
/* printk(KERN_INFO "transport --- ENE_ReadSDReg\n"); */
reg4b = *(PDWORD)&RdBuf[0x18];
us->SD_READ_BL_LEN = (BYTE)((reg4b >> 8) & 0x0f);
tmpreg = (WORD) reg4b;
reg4b = *(PDWORD)(&RdBuf[0x14]);
if (us->SD_Status.HiCapacity && !us->SD_Status.IsMMC)
us->HC_C_SIZE = (reg4b >> 8) & 0x3fffff;
us->SD_C_SIZE = ((tmpreg & 0x03) << 10) | (WORD)(reg4b >> 22);
us->SD_C_SIZE_MULT = (BYTE)(reg4b >> 7) & 0x07;
if (us->SD_Status.HiCapacity && us->SD_Status.IsMMC)
us->HC_C_SIZE = *(PDWORD)(&RdBuf[0x100]);
if (us->SD_READ_BL_LEN > SD_BLOCK_LEN) {
us->SD_Block_Mult =
1 << (us->SD_READ_BL_LEN - SD_BLOCK_LEN);
us->SD_READ_BL_LEN = SD_BLOCK_LEN;
} else {
us->SD_Block_Mult = 1;
}
return USB_STOR_TRANSPORT_GOOD;
}
/*
* ENE_LoadBinCode()
*/
......@@ -291,19 +188,6 @@ int ENE_LoadBinCode(struct us_data *us, BYTE flag)
if (buf == NULL)
return USB_STOR_TRANSPORT_ERROR;
switch (flag) {
/* For SD */
case SD_INIT1_PATTERN:
printk(KERN_INFO "SD_INIT1_PATTERN\n");
memcpy(buf, SD_Init1, 0x800);
break;
case SD_INIT2_PATTERN:
printk(KERN_INFO "SD_INIT2_PATTERN\n");
memcpy(buf, SD_Init2, 0x800);
break;
case SD_RW_PATTERN:
printk(KERN_INFO "SD_RW_PATTERN\n");
memcpy(buf, SD_Rdwr, 0x800);
break;
/* For MS */
case MS_INIT_PATTERN:
printk(KERN_INFO "MS_INIT_PATTERN\n");
......@@ -412,8 +296,9 @@ int ENE_SendScsiCmd(struct us_data *us, BYTE fDir, void *buf, int use_sg)
*/
if (residue && !(us->fflags & US_FL_IGNORE_RESIDUE)) {
residue = min(residue, transfer_length);
scsi_set_resid(us->srb, max(scsi_get_resid(us->srb),
(int) residue));
if (us->srb)
scsi_set_resid(us->srb, max(scsi_get_resid(us->srb),
(int) residue));
}
if (bcs->Status != US_BULK_STAT_OK)
......@@ -558,4 +443,3 @@ void usb_stor_print_cmd(struct scsi_cmnd *srb)
blen = 0;
}
此差异已折叠。
#include <linux/sched.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <scsi/scsi.h>
#include <scsi/scsi_eh.h>
#include <scsi/scsi_device.h>
#include "usb.h"
#include "scsiglue.h"
#include "transport.h"
int SD_SCSI_Test_Unit_Ready (struct us_data *us, struct scsi_cmnd *srb);
int SD_SCSI_Inquiry (struct us_data *us, struct scsi_cmnd *srb);
int SD_SCSI_Mode_Sense (struct us_data *us, struct scsi_cmnd *srb);
int SD_SCSI_Start_Stop (struct us_data *us, struct scsi_cmnd *srb);
int SD_SCSI_Read_Capacity (struct us_data *us, struct scsi_cmnd *srb);
int SD_SCSI_Read (struct us_data *us, struct scsi_cmnd *srb);
int SD_SCSI_Write (struct us_data *us, struct scsi_cmnd *srb);
//----- SD_SCSIIrp() --------------------------------------------------
int SD_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb)
{
int result;
us->SrbStatus = SS_SUCCESS;
switch (srb->cmnd[0])
{
case TEST_UNIT_READY : result = SD_SCSI_Test_Unit_Ready (us, srb); break; //0x00
case INQUIRY : result = SD_SCSI_Inquiry (us, srb); break; //0x12
case MODE_SENSE : result = SD_SCSI_Mode_Sense (us, srb); break; //0x1A
// case START_STOP : result = SD_SCSI_Start_Stop (us, srb); break; //0x1B
case READ_CAPACITY : result = SD_SCSI_Read_Capacity (us, srb); break; //0x25
case READ_10 : result = SD_SCSI_Read (us, srb); break; //0x28
case WRITE_10 : result = SD_SCSI_Write (us, srb); break; //0x2A
default:
us->SrbStatus = SS_ILLEGAL_REQUEST;
result = USB_STOR_TRANSPORT_FAILED;
break;
}
return result;
}
//----- SD_SCSI_Test_Unit_Ready() --------------------------------------------------
int SD_SCSI_Test_Unit_Ready(struct us_data *us, struct scsi_cmnd *srb)
{
//printk("SD_SCSI_Test_Unit_Ready\n");
if (us->SD_Status.Insert && us->SD_Status.Ready)
return USB_STOR_TRANSPORT_GOOD;
else
{
ENE_SDInit(us);
return USB_STOR_TRANSPORT_GOOD;
}
return USB_STOR_TRANSPORT_GOOD;
}
//----- SD_SCSI_Inquiry() --------------------------------------------------
int SD_SCSI_Inquiry(struct us_data *us, struct scsi_cmnd *srb)
{
//printk("SD_SCSI_Inquiry\n");
BYTE data_ptr[36] = {0x00, 0x80, 0x02, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x55, 0x53, 0x42, 0x32, 0x2E, 0x30, 0x20, 0x20, 0x43, 0x61, 0x72, 0x64, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x30, 0x30};
usb_stor_set_xfer_buf(us, data_ptr, 36, srb, TO_XFER_BUF);
return USB_STOR_TRANSPORT_GOOD;
}
//----- SD_SCSI_Mode_Sense() --------------------------------------------------
int SD_SCSI_Mode_Sense(struct us_data *us, struct scsi_cmnd *srb)
{
BYTE mediaNoWP[12] = {0x0b,0x00,0x00,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00};
BYTE mediaWP[12] = {0x0b,0x00,0x80,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00};
if (us->SD_Status.WtP)
usb_stor_set_xfer_buf(us, mediaWP, 12, srb, TO_XFER_BUF);
else
usb_stor_set_xfer_buf(us, mediaNoWP, 12, srb, TO_XFER_BUF);
return USB_STOR_TRANSPORT_GOOD;
}
//----- SD_SCSI_Read_Capacity() --------------------------------------------------
int SD_SCSI_Read_Capacity(struct us_data *us, struct scsi_cmnd *srb)
{
unsigned int offset = 0;
struct scatterlist *sg = NULL;
DWORD bl_num;
WORD bl_len;
BYTE buf[8];
printk("SD_SCSI_Read_Capacity\n");
if ( us->SD_Status.HiCapacity )
{
bl_len = 0x200;
if (us->SD_Status.IsMMC)
bl_num = us->HC_C_SIZE-1;
else
bl_num = (us->HC_C_SIZE + 1) * 1024 - 1;
}
else
{
bl_len = 1<<(us->SD_READ_BL_LEN);
bl_num = us->SD_Block_Mult*(us->SD_C_SIZE+1)*(1<<(us->SD_C_SIZE_MULT+2)) - 1;
}
us->bl_num = bl_num;
printk("bl_len = %x\n", bl_len);
printk("bl_num = %x\n", bl_num);
//srb->request_bufflen = 8;
buf[0] = (bl_num>>24) & 0xff;
buf[1] = (bl_num>>16) & 0xff;
buf[2] = (bl_num>> 8) & 0xff;
buf[3] = (bl_num>> 0) & 0xff;
buf[4] = (bl_len>>24) & 0xff;
buf[5] = (bl_len>>16) & 0xff;
buf[6] = (bl_len>> 8) & 0xff;
buf[7] = (bl_len>> 0) & 0xff;
usb_stor_access_xfer_buf(us, buf, 8, srb, &sg, &offset, TO_XFER_BUF);
//usb_stor_set_xfer_buf(us, buf, srb->request_bufflen, srb, TO_XFER_BUF);
return USB_STOR_TRANSPORT_GOOD;
}
//----- SD_SCSI_Read() --------------------------------------------------
int SD_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb)
{
struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
int result;
PBYTE Cdb = srb->cmnd;
DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) |
((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff);
WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff);
DWORD bnByte = bn * 0x200;
DWORD blenByte = blen * 0x200;
if (bn > us->bl_num)
return USB_STOR_TRANSPORT_ERROR;
result = ENE_LoadBinCode(us, SD_RW_PATTERN);
if (result != USB_STOR_XFER_GOOD)
{
printk("Load SD RW pattern Fail !!\n");
return USB_STOR_TRANSPORT_ERROR;
}
if ( us->SD_Status.HiCapacity )
bnByte = bn;
// set up the command wrapper
memset(bcb, 0, sizeof(struct bulk_cb_wrap));
bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
bcb->DataTransferLength = blenByte;
bcb->Flags = 0x80;
bcb->CDB[0] = 0xF1;
bcb->CDB[5] = (BYTE)(bnByte);
bcb->CDB[4] = (BYTE)(bnByte>>8);
bcb->CDB[3] = (BYTE)(bnByte>>16);
bcb->CDB[2] = (BYTE)(bnByte>>24);
result = ENE_SendScsiCmd(us, FDIR_READ, scsi_sglist(srb), 1);
return result;
}
//----- SD_SCSI_Write() --------------------------------------------------
int SD_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb)
{
struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
int result;
PBYTE Cdb = srb->cmnd;
DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) |
((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff);
WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff);
DWORD bnByte = bn * 0x200;
DWORD blenByte = blen * 0x200;
if (bn > us->bl_num)
return USB_STOR_TRANSPORT_ERROR;
result = ENE_LoadBinCode(us, SD_RW_PATTERN);
if (result != USB_STOR_XFER_GOOD)
{
printk("Load SD RW pattern Fail !!\n");
return USB_STOR_TRANSPORT_ERROR;
}
if ( us->SD_Status.HiCapacity )
bnByte = bn;
// set up the command wrapper
memset(bcb, 0, sizeof(struct bulk_cb_wrap));
bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
bcb->DataTransferLength = blenByte;
bcb->Flags = 0x00;
bcb->CDB[0] = 0xF0;
bcb->CDB[5] = (BYTE)(bnByte);
bcb->CDB[4] = (BYTE)(bnByte>>8);
bcb->CDB[3] = (BYTE)(bnByte>>16);
bcb->CDB[2] = (BYTE)(bnByte>>24);
result = ENE_SendScsiCmd(us, FDIR_WRITE, scsi_sglist(srb), 1);
return result;
}
......@@ -413,7 +413,7 @@ void ENE_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
usb_stor_print_cmd(srb);
/* send the command to the transport layer */
scsi_set_resid(srb, 0);
if ( !(us->SD_Status.Ready || us->MS_Status.Ready || us->SM_Status.Ready) )
if (!(us->MS_Status.Ready || us->SM_Status.Ready))
result = ENE_InitMedia(us);
if (us->Power_IsResum == true) {
......@@ -421,7 +421,6 @@ void ENE_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
us->Power_IsResum = false;
}
if (us->SD_Status.Ready) result = SD_SCSIIrp(us, srb);
if (us->MS_Status.Ready) result = MS_SCSIIrp(us, srb);
if (us->SM_Status.Ready) result = SM_SCSIIrp(us, srb);
......
......@@ -92,10 +92,8 @@ extern void usb_stor_set_xfer_buf(struct us_data*, unsigned char *buffer, unsign
// ENE scsi function
extern void ENE_stor_invoke_transport(struct scsi_cmnd *, struct us_data*);
extern int ENE_InitMedia(struct us_data*);
extern int ENE_SDInit(struct us_data*);
extern int ENE_MSInit(struct us_data*);
extern int ENE_SMInit(struct us_data*);
extern int ENE_ReadSDReg(struct us_data*, u8*);
extern int ENE_SendScsiCmd(struct us_data*, BYTE, void*, int);
extern int ENE_LoadBinCode(struct us_data*, BYTE);
extern int ENE_Read_BYTE(struct us_data*, WORD index, void *buf);
......@@ -104,7 +102,6 @@ extern int ENE_Write_Data(struct us_data*, void *buf, unsigned int length);
extern void BuildSenseBuffer(struct scsi_cmnd *, int);
// ENE scsi function
extern int SD_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb);
extern int MS_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb);
extern int SM_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb);
......
......@@ -74,7 +74,6 @@ int eucr_resume(struct usb_interface *iface)
us->Power_IsResum = true;
//
//us->SD_Status.Ready = 0; //??
us->SD_Status = *(PSD_STATUS)&tmp;
us->MS_Status = *(PMS_STATUS)&tmp;
us->SM_Status = *(PSM_STATUS)&tmp;
......@@ -98,7 +97,6 @@ int eucr_reset_resume(struct usb_interface *iface)
us->Power_IsResum = true;
//
//us->SD_Status.Ready = 0; //??
us->SD_Status = *(PSD_STATUS)&tmp;
us->MS_Status = *(PMS_STATUS)&tmp;
us->SM_Status = *(PSM_STATUS)&tmp;
return 0;
......@@ -582,6 +580,7 @@ static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id
struct Scsi_Host *host;
struct us_data *us;
int result;
BYTE MiscReg03 = 0;
struct task_struct *th;
printk("usb --- eucr_probe\n");
......@@ -647,6 +646,24 @@ static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id
goto BadDevice;
}
wake_up_process(th);
/* probe card type */
result = ENE_Read_BYTE(us, REG_CARD_STATUS, &MiscReg03);
if (result != USB_STOR_XFER_GOOD) {
result = USB_STOR_TRANSPORT_ERROR;
quiesce_and_remove_host(us);
goto BadDevice;
}
if (!(MiscReg03 & 0x02)) {
result = -ENODEV;
quiesce_and_remove_host(us);
printk(KERN_NOTICE "keucr: The driver only supports SM/MS card.\
To use SD card, \
please build driver/usb/storage/ums-eneub6250.ko\n");
goto BadDevice;
}
return 0;
/* We come here if there are any problems */
......
......@@ -198,3 +198,17 @@ config USB_LIBUSUAL
options libusual bias="ub"
If unsure, say N.
config USB_STORAGE_ENE_UB6250
tristate "USB ENE card reader support"
depends on USB && SCSI
---help---
Say Y here if you wish to control a ENE SD Card reader.
To use SM/MS card, please build driver/staging/keucr/keucr.ko
This option depends on 'SCSI' support being enabled, but you
probably also need 'SCSI device support: SCSI disk support'
(BLK_DEV_SD) for most USB storage devices.
To compile this driver as a module, choose M here: the
module will be called ums-eneub6250.
......@@ -25,6 +25,7 @@ endif
obj-$(CONFIG_USB_STORAGE_ALAUDA) += ums-alauda.o
obj-$(CONFIG_USB_STORAGE_CYPRESS_ATACB) += ums-cypress.o
obj-$(CONFIG_USB_STORAGE_DATAFAB) += ums-datafab.o
obj-$(CONFIG_USB_STORAGE_ENE_UB6250) += ums-eneub6250.o
obj-$(CONFIG_USB_STORAGE_FREECOM) += ums-freecom.o
obj-$(CONFIG_USB_STORAGE_ISD200) += ums-isd200.o
obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += ums-jumpshot.o
......@@ -37,6 +38,7 @@ obj-$(CONFIG_USB_STORAGE_USBAT) += ums-usbat.o
ums-alauda-y := alauda.o
ums-cypress-y := cypress_atacb.o
ums-datafab-y := datafab.o
ums-eneub6250-y := ene_ub6250.o
ums-freecom-y := freecom.o
ums-isd200-y := isd200.o
ums-jumpshot-y := jumpshot.o
......
此差异已折叠。
/*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if defined(CONFIG_USB_STORAGE_ENE_UB6250) || \
defined(CONFIG_USB_STORAGE_ENE_UB6250_MODULE)
UNUSUAL_DEV(0x0cf2, 0x6250, 0x0000, 0x9999,
"ENE",
"ENE UB6250 reader",
USB_SC_DEVICE, USB_PR_DEVICE, NULL, 0),
#endif /* defined(CONFIG_USB_STORAGE_ENE_UB6250) || ... */
......@@ -80,6 +80,7 @@ static struct ignore_entry ignore_ids[] = {
# include "unusual_alauda.h"
# include "unusual_cypress.h"
# include "unusual_datafab.h"
# include "unusual_ene_ub6250.h"
# include "unusual_freecom.h"
# include "unusual_isd200.h"
# include "unusual_jumpshot.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册