diff options
Diffstat (limited to 'drivers/staging/rts_pstor')
-rw-r--r-- | drivers/staging/rts_pstor/Makefile | 2 | ||||
-rw-r--r-- | drivers/staging/rts_pstor/ms.c | 3 | ||||
-rw-r--r-- | drivers/staging/rts_pstor/rtsx.c | 172 | ||||
-rw-r--r-- | drivers/staging/rts_pstor/rtsx.h | 20 | ||||
-rw-r--r-- | drivers/staging/rts_pstor/rtsx_chip.c | 6 | ||||
-rw-r--r-- | drivers/staging/rts_pstor/rtsx_scsi.c | 2 | ||||
-rw-r--r-- | drivers/staging/rts_pstor/rtsx_transport.c | 11 | ||||
-rw-r--r-- | drivers/staging/rts_pstor/sd.c | 99 | ||||
-rw-r--r-- | drivers/staging/rts_pstor/sd.h | 5 | ||||
-rw-r--r-- | drivers/staging/rts_pstor/spi.c | 2 |
10 files changed, 166 insertions, 156 deletions
diff --git a/drivers/staging/rts_pstor/Makefile b/drivers/staging/rts_pstor/Makefile index 61609ae..42533d3 100644 --- a/drivers/staging/rts_pstor/Makefile +++ b/drivers/staging/rts_pstor/Makefile @@ -1,4 +1,4 @@ -EXTRA_CFLAGS := -Idrivers/scsi +ccflags := -Idrivers/scsi obj-$(CONFIG_RTS_PSTOR) := rts_pstor.o diff --git a/drivers/staging/rts_pstor/ms.c b/drivers/staging/rts_pstor/ms.c index 2e82587..66341df 100644 --- a/drivers/staging/rts_pstor/ms.c +++ b/drivers/staging/rts_pstor/ms.c @@ -2064,11 +2064,10 @@ static int ms_init_l2p_tbl(struct rtsx_chip *chip) RTSX_DEBUGP("ms_card->segment_cnt = %d\n", ms_card->segment_cnt); size = ms_card->segment_cnt * sizeof(struct zone_entry); - ms_card->segment = (struct zone_entry *)vmalloc(size); + ms_card->segment = vzalloc(size); if (ms_card->segment == NULL) { TRACE_RET(chip, STATUS_FAIL); } - memset(ms_card->segment, 0, size); retval = ms_read_page(chip, ms_card->boot_block, 1); if (retval != STATUS_SUCCESS) { diff --git a/drivers/staging/rts_pstor/rtsx.c b/drivers/staging/rts_pstor/rtsx.c index 5ff59f2..115635f 100644 --- a/drivers/staging/rts_pstor/rtsx.c +++ b/drivers/staging/rts_pstor/rtsx.c @@ -36,7 +36,7 @@ #include "sd.h" #include "xd.h" -#define DRIVER_VERSION "v1.10" +#define DRIVER_VERSION "v1.10" MODULE_DESCRIPTION("Realtek PCI-Express card reader driver"); MODULE_LICENSE("GPL"); @@ -66,12 +66,6 @@ static int msi_en; module_param(msi_en, int, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(msi_en, "enable msi"); -/* These are used to make sure the module doesn't unload before all the - * threads have exited. - */ -static atomic_t total_threads = ATOMIC_INIT(0); -static DECLARE_COMPLETION(threads_gone); - static irqreturn_t rtsx_interrupt(int irq, void *dev_id); /*********************************************************************** @@ -83,7 +77,7 @@ static const char *host_info(struct Scsi_Host *host) return "SCSI emulation for PCI-Express Mass Storage devices"; } -static int slave_alloc (struct scsi_device *sdev) +static int slave_alloc(struct scsi_device *sdev) { /* * Set the INQUIRY transfer length to 36. We don't use any of @@ -136,7 +130,7 @@ static int slave_configure(struct scsi_device *sdev) #define SPRINTF(args...) \ do { if (pos < buffer+length) pos += sprintf(pos, ## args); } while (0) -static int proc_info (struct Scsi_Host *host, char *buffer, +static int proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length, int inout) { char *pos = buffer; @@ -192,7 +186,7 @@ static int queuecommand_lck(struct scsi_cmnd *srb, /* enqueue the command and wake up the control thread */ srb->scsi_done = done; chip->srb = srb; - up(&(dev->sema)); + complete(&dev->cmnd_ready); return 0; } @@ -475,7 +469,7 @@ static int rtsx_control_thread(void *__dev) current->flags |= PF_NOFREEZE; for (;;) { - if (down_interruptible(&dev->sema)) + if (wait_for_completion_interruptible(&dev->cmnd_ready)) break; /* lock the device pointers */ @@ -512,13 +506,15 @@ static int rtsx_control_thread(void *__dev) */ else if (chip->srb->device->id) { printk(KERN_ERR "Bad target number (%d:%d)\n", - chip->srb->device->id, chip->srb->device->lun); + chip->srb->device->id, + chip->srb->device->lun); chip->srb->result = DID_BAD_TARGET << 16; } else if (chip->srb->device->lun > chip->max_lun) { printk(KERN_ERR "Bad LUN (%d:%d)\n", - chip->srb->device->id, chip->srb->device->lun); + chip->srb->device->id, + chip->srb->device->lun); chip->srb->result = DID_BAD_TARGET << 16; } @@ -557,8 +553,6 @@ SkipForAbort: mutex_unlock(&dev->dev_mutex); } /* for (;;) */ - scsi_host_put(host); - /* notify the exit routine that we're actually exiting now * * complete()/wait_for_completion() is similar to up()/down(), @@ -573,7 +567,7 @@ SkipForAbort: * This is important in preemption kernels, which transfer the flow * of execution immediately upon a complete(). */ - complete_and_exit(&threads_gone, 0); + complete_and_exit(&dev->control_exit, 0); } @@ -581,7 +575,6 @@ static int rtsx_polling_thread(void *__dev) { struct rtsx_dev *dev = (struct rtsx_dev *)__dev; struct rtsx_chip *chip = dev->chip; - struct Scsi_Host *host = rtsx_to_host(dev); struct sd_info *sd_card = &(chip->sd_card); struct xd_info *xd_card = &(chip->xd_card); struct ms_info *ms_card = &(chip->ms_card); @@ -621,8 +614,7 @@ static int rtsx_polling_thread(void *__dev) mutex_unlock(&dev->dev_mutex); } - scsi_host_put(host); - complete_and_exit(&threads_gone, 0); + complete_and_exit(&dev->polling_exit, 0); } /* @@ -635,26 +627,23 @@ static irqreturn_t rtsx_interrupt(int irq, void *dev_id) int retval; u32 status; - if (dev) { + if (dev) chip = dev->chip; - } else { + else return IRQ_NONE; - } - if (!chip) { + if (!chip) return IRQ_NONE; - } spin_lock(&dev->reg_lock); retval = rtsx_pre_handle_interrupt(chip); if (retval == STATUS_FAIL) { spin_unlock(&dev->reg_lock); - if (chip->int_reg == 0xFFFFFFFF) { + if (chip->int_reg == 0xFFFFFFFF) return IRQ_HANDLED; - } else { + else return IRQ_NONE; - } } status = chip->int_reg; @@ -671,9 +660,8 @@ static irqreturn_t rtsx_interrupt(int irq, void *dev_id) if (status & (NEED_COMPLETE_INT | DELINK_INT)) { if (status & (TRANS_FAIL_INT | DELINK_INT)) { - if (status & DELINK_INT) { + if (status & DELINK_INT) RTSX_SET_DELINK(chip); - } dev->trans_result = TRANS_RESULT_FAIL; if (dev->done) complete(dev->done); @@ -699,29 +687,38 @@ static void rtsx_release_resources(struct rtsx_dev *dev) { printk(KERN_INFO "-- %s\n", __func__); + /* Tell the control thread to exit. The SCSI host must + * already have been removed so it won't try to queue + * any more commands. + */ + printk(KERN_INFO "-- sending exit command to thread\n"); + complete(&dev->cmnd_ready); + if (dev->ctl_thread) + wait_for_completion(&dev->control_exit); + if (dev->polling_thread) + wait_for_completion(&dev->polling_exit); + + wait_timeout(200); + if (dev->rtsx_resv_buf) { - dma_free_coherent(&(dev->pci->dev), HOST_CMDS_BUF_LEN, + dma_free_coherent(&(dev->pci->dev), RTSX_RESV_BUF_LEN, dev->rtsx_resv_buf, dev->rtsx_resv_buf_addr); dev->chip->host_cmds_ptr = NULL; dev->chip->host_sg_tbl_ptr = NULL; } - pci_disable_device(dev->pci); - pci_release_regions(dev->pci); - - if (dev->irq > 0) { + if (dev->irq > 0) free_irq(dev->irq, (void *)dev); - } - if (dev->chip->msi_en) { + if (dev->chip->msi_en) pci_disable_msi(dev->pci); - } + if (dev->remap_addr) + iounmap(dev->remap_addr); - /* Tell the control thread to exit. The SCSI host must - * already have been removed so it won't try to queue - * any more commands. - */ - printk(KERN_INFO "-- sending exit command to thread\n"); - up(&dev->sema); + pci_disable_device(dev->pci); + pci_release_regions(dev->pci); + + rtsx_release_chip(dev->chip); + kfree(dev->chip); } /* First stage of disconnect processing: stop all commands and remove @@ -739,6 +736,7 @@ static void quiesce_and_remove_host(struct rtsx_dev *dev) scsi_unlock(host); mutex_unlock(&dev->dev_mutex); wake_up(&dev->delay_wait); + wait_for_completion(&dev->scanning_done); /* Wait some time to let other threads exist */ wait_timeout(100); @@ -793,8 +791,7 @@ static int rtsx_scan_thread(void *__dev) /* Should we unbind if no devices were detected? */ } - scsi_host_put(rtsx_to_host(dev)); - complete_and_exit(&threads_gone, 0); + complete_and_exit(&dev->scanning_done, 0); } static void rtsx_init_options(struct rtsx_chip *chip) @@ -845,7 +842,9 @@ static void rtsx_init_options(struct rtsx_chip *chip) chip->ssc_en = 1; chip->sd_speed_prior = 0x01040203; chip->sd_current_prior = 0x00010203; - chip->sd_ctl = SD_PUSH_POINT_AUTO | SD_SAMPLE_POINT_AUTO | SUPPORT_MMC_DDR_MODE; + chip->sd_ctl = SD_PUSH_POINT_AUTO | + SD_SAMPLE_POINT_AUTO | + SUPPORT_MMC_DDR_MODE; chip->sd_ddr_tx_phase = 0; chip->mmc_ddr_tx_phase = 1; chip->sd_default_tx_phase = 15; @@ -897,7 +896,8 @@ static void rtsx_init_options(struct rtsx_chip *chip) chip->s3_pwr_off_delay = 1000; } -static int __devinit rtsx_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) +static int __devinit rtsx_probe(struct pci_dev *pci, + const struct pci_device_id *pci_id) { struct Scsi_Host *host; struct rtsx_dev *dev; @@ -914,7 +914,8 @@ static int __devinit rtsx_probe(struct pci_dev *pci, const struct pci_device_id err = pci_request_regions(pci, CR_DRIVER_NAME); if (err < 0) { - printk(KERN_ERR "PCI request regions for %s failed!\n", CR_DRIVER_NAME); + printk(KERN_ERR "PCI request regions for %s failed!\n", + CR_DRIVER_NAME); pci_disable_device(pci); return err; } @@ -935,20 +936,23 @@ static int __devinit rtsx_probe(struct pci_dev *pci, const struct pci_device_id memset(dev, 0, sizeof(struct rtsx_dev)); dev->chip = kzalloc(sizeof(struct rtsx_chip), GFP_KERNEL); - if (dev->chip == NULL) { + if (dev->chip == NULL) goto errout; - } spin_lock_init(&dev->reg_lock); mutex_init(&(dev->dev_mutex)); - sema_init(&(dev->sema), 0); + init_completion(&dev->cmnd_ready); + init_completion(&dev->control_exit); + init_completion(&dev->polling_exit); init_completion(&(dev->notify)); + init_completion(&dev->scanning_done); init_waitqueue_head(&dev->delay_wait); dev->pci = pci; dev->irq = -1; - printk(KERN_INFO "Resource length: 0x%x\n", (unsigned int)pci_resource_len(pci, 0)); + printk(KERN_INFO "Resource length: 0x%x\n", + (unsigned int)pci_resource_len(pci, 0)); dev->addr = pci_resource_start(pci, 0); dev->remap_addr = ioremap_nocache(dev->addr, pci_resource_len(pci, 0)); if (dev->remap_addr == NULL) { @@ -957,9 +961,12 @@ static int __devinit rtsx_probe(struct pci_dev *pci, const struct pci_device_id goto errout; } - /* Using "unsigned long" cast here to eliminate gcc warning in 64-bit system */ + /* + * Using "unsigned long" cast here to eliminate gcc warning in + * 64-bit system + */ printk(KERN_INFO "Original address: 0x%lx, remapped address: 0x%lx\n", - (unsigned long)(dev->addr), (unsigned long)(dev->remap_addr)); + (unsigned long)(dev->addr), (unsigned long)(dev->remap_addr)); dev->rtsx_resv_buf = dma_alloc_coherent(&(pci->dev), RTSX_RESV_BUF_LEN, &(dev->rtsx_resv_buf_addr), GFP_KERNEL); @@ -971,7 +978,8 @@ static int __devinit rtsx_probe(struct pci_dev *pci, const struct pci_device_id dev->chip->host_cmds_ptr = dev->rtsx_resv_buf; dev->chip->host_cmds_addr = dev->rtsx_resv_buf_addr; dev->chip->host_sg_tbl_ptr = dev->rtsx_resv_buf + HOST_CMDS_BUF_LEN; - dev->chip->host_sg_tbl_addr = dev->rtsx_resv_buf_addr + HOST_CMDS_BUF_LEN; + dev->chip->host_sg_tbl_addr = dev->rtsx_resv_buf_addr + + HOST_CMDS_BUF_LEN; dev->chip->rtsx = dev; @@ -992,60 +1000,44 @@ static int __devinit rtsx_probe(struct pci_dev *pci, const struct pci_device_id pci_set_master(pci); synchronize_irq(dev->irq); - err = scsi_add_host(host, &pci->dev); - if (err) { - printk(KERN_ERR "Unable to add the scsi host\n"); - goto errout; - } - rtsx_init_chip(dev->chip); /* Start up our control thread */ - th = kthread_create(rtsx_control_thread, dev, CR_DRIVER_NAME); + th = kthread_run(rtsx_control_thread, dev, CR_DRIVER_NAME); if (IS_ERR(th)) { printk(KERN_ERR "Unable to start control thread\n"); err = PTR_ERR(th); goto errout; } + dev->ctl_thread = th; - /* Take a reference to the host for the control thread and - * count it among all the threads we have launched. Then - * start it up. */ - scsi_host_get(rtsx_to_host(dev)); - atomic_inc(&total_threads); - wake_up_process(th); + err = scsi_add_host(host, &pci->dev); + if (err) { + printk(KERN_ERR "Unable to add the scsi host\n"); + goto errout; + } /* Start up the thread for delayed SCSI-device scanning */ th = kthread_create(rtsx_scan_thread, dev, "rtsx-scan"); if (IS_ERR(th)) { printk(KERN_ERR "Unable to start the device-scanning thread\n"); + complete(&dev->scanning_done); quiesce_and_remove_host(dev); err = PTR_ERR(th); goto errout; } - /* Take a reference to the host for the scanning thread and - * count it among all the threads we have launched. Then - * start it up. */ - scsi_host_get(rtsx_to_host(dev)); - atomic_inc(&total_threads); wake_up_process(th); /* Start up the thread for polling thread */ - th = kthread_create(rtsx_polling_thread, dev, "rtsx-polling"); + th = kthread_run(rtsx_polling_thread, dev, "rtsx-polling"); if (IS_ERR(th)) { printk(KERN_ERR "Unable to start the device-polling thread\n"); quiesce_and_remove_host(dev); err = PTR_ERR(th); goto errout; } - - /* Take a reference to the host for the polling thread and - * count it among all the threads we have launched. Then - * start it up. */ - scsi_host_get(rtsx_to_host(dev)); - atomic_inc(&total_threads); - wake_up_process(th); + dev->polling_thread = th; pci_set_drvdata(pci, dev); @@ -1073,10 +1065,10 @@ static void __devexit rtsx_remove(struct pci_dev *pci) } /* PCI IDs */ -static struct pci_device_id rtsx_ids[] = { - { 0x10EC, 0x5208, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_OTHERS << 16, 0xFF0000 }, - { 0x10EC, 0x5209, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_OTHERS << 16, 0xFF0000 }, - { 0x10EC, 0x5288, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_OTHERS << 16, 0xFF0000 }, +static DEFINE_PCI_DEVICE_TABLE(rtsx_ids) = { + { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x5208), PCI_CLASS_OTHERS << 16, 0xFF0000 }, + { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x5209), PCI_CLASS_OTHERS << 16, 0xFF0000 }, + { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x5288), PCI_CLASS_OTHERS << 16, 0xFF0000 }, { 0, }, }; @@ -1108,16 +1100,6 @@ static void __exit rtsx_exit(void) pci_unregister_driver(&driver); - /* Don't return until all of our control and scanning threads - * have exited. Since each thread signals threads_gone as its - * last act, we have to call wait_for_completion the right number - * of times. - */ - while (atomic_read(&total_threads) > 0) { - wait_for_completion(&threads_gone); - atomic_dec(&total_threads); - } - printk(KERN_INFO "%s module exit\n", CR_DRIVER_NAME); } diff --git a/drivers/staging/rts_pstor/rtsx.h b/drivers/staging/rts_pstor/rtsx.h index 6afb635..1ab42fc 100644 --- a/drivers/staging/rts_pstor/rtsx.h +++ b/drivers/staging/rts_pstor/rtsx.h @@ -24,12 +24,11 @@ #ifndef __REALTEK_RTSX_H #define __REALTEK_RTSX_H -#include <asm/io.h> -#include <asm/bitops.h> +#include <linux/io.h> +#include <linux/bitops.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/kernel.h> -#include <linux/version.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> @@ -81,7 +80,7 @@ #define wait_timeout_x(task_state, msecs) \ do { \ - set_current_state((task_state)); \ + set_current_state((task_state)); \ schedule_timeout((msecs) * HZ / 1000); \ } while (0) #define wait_timeout(msecs) wait_timeout_x(TASK_INTERRUPTIBLE, (msecs)) @@ -103,19 +102,26 @@ typedef unsigned long DELAY_PARA_T; struct rtsx_chip; struct rtsx_dev { - struct pci_dev *pci; + struct pci_dev *pci; /* pci resources */ unsigned long addr; void __iomem *remap_addr; - int irq; + int irq; /* locks */ spinlock_t reg_lock; + struct task_struct *ctl_thread; /* the control thread */ + struct task_struct *polling_thread; /* the polling thread */ + /* mutual exclusion and synchronization structures */ - struct semaphore sema; /* to sleep thread on */ + struct completion cmnd_ready; /* to sleep thread on */ + struct completion control_exit; /* control thread exit */ + struct completion polling_exit; /* polling thread exit */ struct completion notify; /* thread begin/end */ + struct completion scanning_done; /* wait for scan thread */ + wait_queue_head_t delay_wait; /* wait during scan, reset */ struct mutex dev_mutex; diff --git a/drivers/staging/rts_pstor/rtsx_chip.c b/drivers/staging/rts_pstor/rtsx_chip.c index 4e60780..5452069 100644 --- a/drivers/staging/rts_pstor/rtsx_chip.c +++ b/drivers/staging/rts_pstor/rtsx_chip.c @@ -1596,18 +1596,16 @@ int rtsx_write_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf, int l } RTSX_DEBUGP("dw_len = %d\n", dw_len); - data = (u32 *)vmalloc(dw_len * 4); + data = vzalloc(dw_len * 4); if (!data) { TRACE_RET(chip, STATUS_NOMEM); } - memset(data, 0, dw_len * 4); - mask = (u32 *)vmalloc(dw_len * 4); + mask = vzalloc(dw_len * 4); if (!mask) { vfree(data); TRACE_RET(chip, STATUS_NOMEM); } - memset(mask, 0, dw_len * 4); j = 0; for (i = 0; i < len; i++) { diff --git a/drivers/staging/rts_pstor/rtsx_scsi.c b/drivers/staging/rts_pstor/rtsx_scsi.c index 7de1fae..f2e5842 100644 --- a/drivers/staging/rts_pstor/rtsx_scsi.c +++ b/drivers/staging/rts_pstor/rtsx_scsi.c @@ -2730,7 +2730,7 @@ static int get_ms_information(struct scsi_cmnd *srb, struct rtsx_chip *chip) buf_len = data_len = 0x6A; } - buf = (u8 *)kmalloc(buf_len, GFP_KERNEL); + buf = kmalloc(buf_len, GFP_KERNEL); if (!buf) { TRACE_RET(chip, TRANSPORT_ERROR); } diff --git a/drivers/staging/rts_pstor/rtsx_transport.c b/drivers/staging/rts_pstor/rtsx_transport.c index 4e3d2c1..9b2e5c9 100644 --- a/drivers/staging/rts_pstor/rtsx_transport.c +++ b/drivers/staging/rts_pstor/rtsx_transport.c @@ -335,6 +335,7 @@ static int rtsx_transfer_sglist_adma_partial(struct rtsx_chip *chip, u8 card, int sg_cnt, i, resid; int err = 0; long timeleft; + struct scatterlist *sg_ptr; u32 val = TRIG_DMA; if ((sg == NULL) || (num_sg <= 0) || !offset || !index) @@ -371,7 +372,7 @@ static int rtsx_transfer_sglist_adma_partial(struct rtsx_chip *chip, u8 card, sg_cnt = dma_map_sg(&(rtsx->pci->dev), sg, num_sg, dma_dir); resid = size; - + sg_ptr = sg; chip->sgi = 0; /* Usually the next entry will be @sg@ + 1, but if this sg element * is part of a chained scatterlist, it could jump to the start of @@ -379,14 +380,14 @@ static int rtsx_transfer_sglist_adma_partial(struct rtsx_chip *chip, u8 card, * the proper sg */ for (i = 0; i < *index; i++) - sg = sg_next(sg); + sg_ptr = sg_next(sg_ptr); for (i = *index; i < sg_cnt; i++) { dma_addr_t addr; unsigned int len; u8 option; - addr = sg_dma_address(sg); - len = sg_dma_len(sg); + addr = sg_dma_address(sg_ptr); + len = sg_dma_len(sg_ptr); RTSX_DEBUGP("DMA addr: 0x%x, Len: 0x%x\n", (unsigned int)addr, len); @@ -415,7 +416,7 @@ static int rtsx_transfer_sglist_adma_partial(struct rtsx_chip *chip, u8 card, if (!resid) break; - sg = sg_next(sg); + sg_ptr = sg_next(sg_ptr); } RTSX_DEBUGP("SG table count = %d\n", chip->sgi); diff --git a/drivers/staging/rts_pstor/sd.c b/drivers/staging/rts_pstor/sd.c index cdae497..aab6909 100644 --- a/drivers/staging/rts_pstor/sd.c +++ b/drivers/staging/rts_pstor/sd.c @@ -2661,7 +2661,7 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width) retval = sd_send_cmd_get_rsp(chip, BUSTEST_W, 0, SD_RSP_TYPE_R1, NULL, 0); if (retval != STATUS_SUCCESS) { - TRACE_RET(chip, STATUS_FAIL); + TRACE_RET(chip, SWITCH_FAIL); } if (width == MMC_8BIT_BUS) { @@ -2678,7 +2678,9 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width) } if (!CHECK_PID(chip, 0x5209)) { - RTSX_WRITE_REG(chip, REG_SD_CFG3, 0x02, 0x02); + retval = rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0x02); + if (retval != STATUS_SUCCESS) + TRACE_RET(chip, SWITCH_ERR); } retval = sd_write_data(chip, SD_TM_AUTO_WRITE_3, @@ -2690,17 +2692,19 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width) rtsx_read_register(chip, REG_SD_STAT2, &val2); rtsx_clear_sd_error(chip); if ((val1 & 0xE0) || val2) { - TRACE_RET(chip, STATUS_FAIL); + TRACE_RET(chip, SWITCH_ERR); } } else { rtsx_clear_sd_error(chip); rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0); - TRACE_RET(chip, STATUS_FAIL); + TRACE_RET(chip, SWITCH_ERR); } } if (!CHECK_PID(chip, 0x5209)) { - RTSX_WRITE_REG(chip, REG_SD_CFG3, 0x02, 0); + retval = rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0); + if (retval != STATUS_SUCCESS) + TRACE_RET(chip, SWITCH_ERR); } RTSX_DEBUGP("SD/MMC CMD %d\n", BUSTEST_R); @@ -2733,7 +2737,7 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width) retval = rtsx_send_cmd(chip, SD_CARD, 100); if (retval < 0) { rtsx_clear_sd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + TRACE_RET(chip, SWITCH_ERR); } ptr = rtsx_get_cmd_data(chip) + 1; @@ -2751,7 +2755,7 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width) } retval = sd_send_cmd_get_rsp(chip, SWITCH, arg, SD_RSP_TYPE_R1b, rsp, 5); if ((retval == STATUS_SUCCESS) && !(rsp[4] & MMC_SWITCH_ERR)) { - return STATUS_SUCCESS; + return SWITCH_SUCCESS; } } } else { @@ -2767,12 +2771,12 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width) } retval = sd_send_cmd_get_rsp(chip, SWITCH, arg, SD_RSP_TYPE_R1b, rsp, 5); if ((retval == STATUS_SUCCESS) && !(rsp[4] & MMC_SWITCH_ERR)) { - return STATUS_SUCCESS; + return SWITCH_SUCCESS; } } } - TRACE_RET(chip, STATUS_FAIL); + TRACE_RET(chip, SWITCH_FAIL); } @@ -2880,21 +2884,30 @@ static int mmc_switch_timing_bus(struct rtsx_chip *chip, int switch_ddr) TRACE_RET(chip, STATUS_FAIL); } - if (mmc_test_switch_bus(chip, MMC_8BIT_BUS) == STATUS_SUCCESS) { + /* Test Bus Procedure */ + retval = mmc_test_switch_bus(chip, MMC_8BIT_BUS); + if (retval == SWITCH_SUCCESS) { SET_MMC_8BIT(sd_card); chip->card_bus_width[chip->card2lun[SD_CARD]] = 8; #ifdef SUPPORT_SD_LOCK sd_card->sd_lock_status &= ~SD_LOCK_1BIT_MODE; #endif - } else if (mmc_test_switch_bus(chip, MMC_4BIT_BUS) == STATUS_SUCCESS) { - SET_MMC_4BIT(sd_card); - chip->card_bus_width[chip->card2lun[SD_CARD]] = 4; + } else if (retval == SWITCH_FAIL) { + retval = mmc_test_switch_bus(chip, MMC_4BIT_BUS); + if (retval == SWITCH_SUCCESS) { + SET_MMC_4BIT(sd_card); + chip->card_bus_width[chip->card2lun[SD_CARD]] = 4; #ifdef SUPPORT_SD_LOCK - sd_card->sd_lock_status &= ~SD_LOCK_1BIT_MODE; + sd_card->sd_lock_status &= ~SD_LOCK_1BIT_MODE; #endif + } else if (retval == SWITCH_FAIL) { + CLR_MMC_8BIT(sd_card); + CLR_MMC_4BIT(sd_card); + } else { + TRACE_RET(chip, STATUS_FAIL); + } } else { - CLR_MMC_8BIT(sd_card); - CLR_MMC_4BIT(sd_card); + TRACE_RET(chip, STATUS_FAIL); } return STATUS_SUCCESS; @@ -2915,8 +2928,7 @@ static int reset_mmc(struct rtsx_chip *chip) goto MMC_UNLOCK_ENTRY; #endif -DDR_TUNING_FAIL: - +Switch_Fail: retval = sd_prepare_reset(chip); if (retval != STATUS_SUCCESS) { TRACE_RET(chip, retval); @@ -3017,7 +3029,15 @@ MMC_UNLOCK_ENTRY: if (!sd_card->mmc_dont_switch_bus) { if (spec_ver == 4) { - (void)mmc_switch_timing_bus(chip, switch_ddr); + /* MMC 4.x Cards */ + retval = mmc_switch_timing_bus(chip, switch_ddr); + if (retval != STATUS_SUCCESS) { + retval = sd_init_power(chip); + if (retval != STATUS_SUCCESS) + TRACE_RET(chip, STATUS_FAIL); + sd_card->mmc_dont_switch_bus = 1; + TRACE_GOTO(chip, Switch_Fail); + } } if (CHK_MMC_SECTOR_MODE(sd_card) && (sd_card->capacity == 0)) { @@ -3037,7 +3057,7 @@ MMC_UNLOCK_ENTRY: TRACE_RET(chip, STATUS_FAIL); } switch_ddr = 0; - goto DDR_TUNING_FAIL; + TRACE_GOTO(chip, Switch_Fail); } retval = sd_wait_state_data_ready(chip, 0x08, 1, 1000); @@ -3049,7 +3069,7 @@ MMC_UNLOCK_ENTRY: TRACE_RET(chip, STATUS_FAIL); } switch_ddr = 0; - goto DDR_TUNING_FAIL; + TRACE_GOTO(chip, Switch_Fail); } } } @@ -3114,41 +3134,40 @@ int reset_sd_card(struct rtsx_chip *chip) if (chip->sd_ctl & RESET_MMC_FIRST) { retval = reset_mmc(chip); - if ((retval != STATUS_SUCCESS) && !sd_check_err_code(chip, SD_NO_CARD)) { + if (retval != STATUS_SUCCESS) { + if (sd_check_err_code(chip, SD_NO_CARD)) + TRACE_RET(chip, STATUS_FAIL); + retval = reset_sd(chip); if (retval != STATUS_SUCCESS) { - if (CHECK_PID(chip, 0x5209)) { - retval = sd_change_bank_voltage(chip, SD_IO_3V3); - if (retval != STATUS_SUCCESS) { - TRACE_RET(chip, STATUS_FAIL); - } - } + if (CHECK_PID(chip, 0x5209)) + sd_change_bank_voltage(chip, SD_IO_3V3); + + TRACE_RET(chip, STATUS_FAIL); } } } else { retval = reset_sd(chip); if (retval != STATUS_SUCCESS) { - if (sd_check_err_code(chip, SD_NO_CARD)) { + if (sd_check_err_code(chip, SD_NO_CARD)) TRACE_RET(chip, STATUS_FAIL); - } if (CHECK_PID(chip, 0x5209)) { retval = sd_change_bank_voltage(chip, SD_IO_3V3); - if (retval != STATUS_SUCCESS) { + if (retval != STATUS_SUCCESS) TRACE_RET(chip, STATUS_FAIL); - } } - if (!chip->sd_io) { + if (chip->sd_io) { + TRACE_RET(chip, STATUS_FAIL); + } else { retval = reset_mmc(chip); + if (retval != STATUS_SUCCESS) + TRACE_RET(chip, STATUS_FAIL); } } } - if (retval != STATUS_SUCCESS) { - TRACE_RET(chip, STATUS_FAIL); - } - retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0); if (retval != STATUS_SUCCESS) { TRACE_RET(chip, STATUS_FAIL); @@ -3727,7 +3746,7 @@ RTY_SEND_CMD: if ((ptr[3] & 0x1E) != 0x04) { TRACE_RET(chip, STATUS_FAIL); } - } else if (rsp_type == SD_RSP_TYPE_R2) { + } else if (rsp_type == SD_RSP_TYPE_R0) { if ((ptr[3] & 0x1E) != 0x03) { TRACE_RET(chip, STATUS_FAIL); } @@ -4119,7 +4138,7 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) cmd[3] = srb->cmnd[5]; cmd[4] = srb->cmnd[6]; - buf = (u8 *)kmalloc(data_len, GFP_KERNEL); + buf = kmalloc(data_len, GFP_KERNEL); if (buf == NULL) { TRACE_RET(chip, TRANSPORT_ERROR); } @@ -4365,7 +4384,7 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) u16 i; u8 *buf; - buf = (u8 *)kmalloc(data_len, GFP_KERNEL); + buf = kmalloc(data_len, GFP_KERNEL); if (buf == NULL) { TRACE_RET(chip, TRANSPORT_ERROR); } diff --git a/drivers/staging/rts_pstor/sd.h b/drivers/staging/rts_pstor/sd.h index d62e690..1df1aa7 100644 --- a/drivers/staging/rts_pstor/sd.h +++ b/drivers/staging/rts_pstor/sd.h @@ -38,6 +38,11 @@ #define SD_RSP_TIMEOUT 0x04 #define SD_IO_ERR 0x02 +/* Return code for MMC switch bus */ +#define SWITCH_SUCCESS 0 +#define SWITCH_ERR 1 +#define SWITCH_FAIL 2 + /* MMC/SD Command Index */ /* Basic command (class 0) */ #define GO_IDLE_STATE 0 diff --git a/drivers/staging/rts_pstor/spi.c b/drivers/staging/rts_pstor/spi.c index c803ba6..6b36cc5 100644 --- a/drivers/staging/rts_pstor/spi.c +++ b/drivers/staging/rts_pstor/spi.c @@ -463,7 +463,7 @@ int spi_read_flash_id(struct scsi_cmnd *srb, struct rtsx_chip *chip) } if (len) { - buf = (u8 *)kmalloc(len, GFP_KERNEL); + buf = kmalloc(len, GFP_KERNEL); if (!buf) TRACE_RET(chip, STATUS_ERROR); |