summaryrefslogtreecommitdiff
path: root/drivers/memstick
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/memstick')
-rw-r--r--drivers/memstick/core/memstick.c68
-rw-r--r--drivers/memstick/core/ms_block.c23
-rw-r--r--drivers/memstick/core/mspro_block.c16
-rw-r--r--drivers/memstick/host/Kconfig10
-rw-r--r--drivers/memstick/host/Makefile1
-rw-r--r--drivers/memstick/host/jmb38x_ms.c7
-rw-r--r--drivers/memstick/host/r592.c8
-rw-r--r--drivers/memstick/host/rtsx_pci_ms.c638
-rw-r--r--drivers/memstick/host/rtsx_usb_ms.c11
-rw-r--r--drivers/memstick/host/tifm_ms.c9
10 files changed, 75 insertions, 716 deletions
diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index 23fea51ecbdd..acafc910bbac 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -26,7 +26,7 @@ static DEFINE_IDR(memstick_host_idr);
static DEFINE_SPINLOCK(memstick_host_lock);
static int memstick_dev_match(struct memstick_dev *card,
- struct memstick_device_id *id)
+ const struct memstick_device_id *id)
{
if (id->match_flags & MEMSTICK_MATCH_ALL) {
if ((id->type == card->id.type)
@@ -38,14 +38,13 @@ static int memstick_dev_match(struct memstick_dev *card,
return 0;
}
-static int memstick_bus_match(struct device *dev, struct device_driver *drv)
+static int memstick_bus_match(struct device *dev, const struct device_driver *drv)
{
struct memstick_dev *card = container_of(dev, struct memstick_dev,
dev);
- struct memstick_driver *ms_drv = container_of(drv,
- struct memstick_driver,
- driver);
- struct memstick_device_id *ids = ms_drv->id_table;
+ const struct memstick_driver *ms_drv = container_of_const(drv, struct memstick_driver,
+ driver);
+ const struct memstick_device_id *ids = ms_drv->id_table;
if (ids) {
while (ids->match_flags) {
@@ -201,7 +200,7 @@ static int memstick_dummy_check(struct memstick_dev *card)
/**
* memstick_detect_change - schedule media detection on memstick host
- * @host - host to use
+ * @host: host to use
*/
void memstick_detect_change(struct memstick_host *host)
{
@@ -211,13 +210,15 @@ EXPORT_SYMBOL(memstick_detect_change);
/**
* memstick_next_req - called by host driver to obtain next request to process
- * @host - host to use
- * @mrq - pointer to stick the request to
+ * @host: host to use
+ * @mrq: pointer to stick the request to
*
* Host calls this function from idle state (*mrq == NULL) or after finishing
* previous request (*mrq should point to it). If previous request was
- * unsuccessful, it is retried for predetermined number of times. Return value
- * of 0 means that new request was assigned to the host.
+ * unsuccessful, it is retried for predetermined number of times.
+ *
+ * Returns: value of 0 means that new request was assigned to the host.
+ * Otherwise a negative error code is returned.
*/
int memstick_next_req(struct memstick_host *host, struct memstick_request **mrq)
{
@@ -243,7 +244,7 @@ EXPORT_SYMBOL(memstick_next_req);
/**
* memstick_new_req - notify the host that some requests are pending
- * @host - host to use
+ * @host: host to use
*/
void memstick_new_req(struct memstick_host *host)
{
@@ -257,9 +258,9 @@ EXPORT_SYMBOL(memstick_new_req);
/**
* memstick_init_req_sg - set request fields needed for bulk data transfer
- * @mrq - request to use
- * @tpc - memstick Transport Protocol Command
- * @sg - TPC argument
+ * @mrq: request to use
+ * @tpc: memstick Transport Protocol Command
+ * @sg: TPC argument
*/
void memstick_init_req_sg(struct memstick_request *mrq, unsigned char tpc,
const struct scatterlist *sg)
@@ -282,10 +283,10 @@ EXPORT_SYMBOL(memstick_init_req_sg);
/**
* memstick_init_req - set request fields needed for short data transfer
- * @mrq - request to use
- * @tpc - memstick Transport Protocol Command
- * @buf - TPC argument buffer
- * @length - TPC argument size
+ * @mrq: request to use
+ * @tpc: memstick Transport Protocol Command
+ * @buf: TPC argument buffer
+ * @length: TPC argument size
*
* The intended use of this function (transfer of data items several bytes
* in size) allows us to just copy the value between request structure and
@@ -323,7 +324,7 @@ EXPORT_SYMBOL(memstick_init_req);
static int h_memstick_read_dev_id(struct memstick_dev *card,
struct memstick_request **mrq)
{
- struct ms_id_register id_reg;
+ struct ms_id_register id_reg = {};
if (!(*mrq)) {
memstick_init_req(&card->current_mrq, MS_TPC_READ_REG, &id_reg,
@@ -361,13 +362,17 @@ static int h_memstick_set_rw_addr(struct memstick_dev *card,
/**
* memstick_set_rw_addr - issue SET_RW_REG_ADDR request and wait for it to
* complete
- * @card - media device to use
+ * @card: media device to use
+ *
+ * Returns: error setting for the current request
*/
int memstick_set_rw_addr(struct memstick_dev *card)
{
card->next_request = h_memstick_set_rw_addr;
memstick_new_req(card->host);
- wait_for_completion(&card->mrq_complete);
+ if (!wait_for_completion_timeout(&card->mrq_complete,
+ msecs_to_jiffies(500)))
+ card->current_mrq.error = -ETIMEDOUT;
return card->current_mrq.error;
}
@@ -401,7 +406,9 @@ static struct memstick_dev *memstick_alloc_card(struct memstick_host *host)
card->next_request = h_memstick_read_dev_id;
memstick_new_req(host);
- wait_for_completion(&card->mrq_complete);
+ if (!wait_for_completion_timeout(&card->mrq_complete,
+ msecs_to_jiffies(500)))
+ card->current_mrq.error = -ETIMEDOUT;
if (card->current_mrq.error)
goto err_out;
@@ -488,6 +495,8 @@ out_power_off:
* memstick_alloc_host - allocate a memstick_host structure
* @extra: size of the user private data to allocate
* @dev: parent device of the host
+ *
+ * Returns: %NULL on failure or the allocated &memstick_host pointer on success
*/
struct memstick_host *memstick_alloc_host(unsigned int extra,
struct device *dev)
@@ -508,7 +517,9 @@ EXPORT_SYMBOL(memstick_alloc_host);
/**
* memstick_add_host - start request processing on memstick host
- * @host - host to use
+ * @host: host to use
+ *
+ * Returns: %0 on success or a negative error code on failure
*/
int memstick_add_host(struct memstick_host *host)
{
@@ -544,11 +555,10 @@ EXPORT_SYMBOL(memstick_add_host);
/**
* memstick_remove_host - stop request processing on memstick host
- * @host - host to use
+ * @host: host to use
*/
void memstick_remove_host(struct memstick_host *host)
{
- host->removing = 1;
flush_workqueue(workqueue);
mutex_lock(&host->lock);
if (host->card)
@@ -566,7 +576,7 @@ EXPORT_SYMBOL(memstick_remove_host);
/**
* memstick_free_host - free memstick host
- * @host - host to use
+ * @host: host to use
*/
void memstick_free_host(struct memstick_host *host)
{
@@ -577,7 +587,7 @@ EXPORT_SYMBOL(memstick_free_host);
/**
* memstick_suspend_host - notify bus driver of host suspension
- * @host - host to use
+ * @host: host to use
*/
void memstick_suspend_host(struct memstick_host *host)
{
@@ -589,7 +599,7 @@ EXPORT_SYMBOL(memstick_suspend_host);
/**
* memstick_resume_host - notify bus driver of host resumption
- * @host - host to use
+ * @host: host to use
*/
void memstick_resume_host(struct memstick_host *host)
{
diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
index 47a314a4eb6f..1af157ce0a63 100644
--- a/drivers/memstick/core/ms_block.c
+++ b/drivers/memstick/core/ms_block.c
@@ -996,7 +996,7 @@ static int msb_verify_block(struct msb_data *msb, u16 pba,
return 0;
}
-/* Writes exectly one block + oob */
+/* Writes exactly one block + oob */
static int msb_write_block(struct msb_data *msb,
u16 pba, u32 lba, struct scatterlist *sg, int offset)
{
@@ -1498,7 +1498,7 @@ static int msb_ftl_scan(struct msb_data *msb)
static void msb_cache_flush_timer(struct timer_list *t)
{
- struct msb_data *msb = from_timer(msb, t, cache_flush_timer);
+ struct msb_data *msb = timer_container_of(msb, t, cache_flush_timer);
msb->need_flush_cache = true;
queue_work(msb->io_queue, &msb->io_work);
@@ -1510,7 +1510,7 @@ static void msb_cache_discard(struct msb_data *msb)
if (msb->cache_block_lba == MS_BLOCK_INVALID)
return;
- del_timer_sync(&msb->cache_flush_timer);
+ timer_delete_sync(&msb->cache_flush_timer);
dbg_verbose("Discarding the write cache");
msb->cache_block_lba = MS_BLOCK_INVALID;
@@ -1684,7 +1684,7 @@ static int msb_cache_read(struct msb_data *msb, int lba,
*/
static const struct chs_entry chs_table[] = {
-/* size sectors cylynders heads */
+/* size sectors cylinders heads */
{ 4, 16, 247, 2 },
{ 8, 16, 495, 2 },
{ 16, 16, 495, 4 },
@@ -1729,7 +1729,7 @@ static int msb_init_card(struct memstick_dev *card)
boot_block = &msb->boot_page[0];
- /* Save intersting attributes from boot page */
+ /* Save interesting attributes from boot page */
msb->block_count = boot_block->attr.number_of_blocks;
msb->page_size = boot_block->attr.page_size;
@@ -1904,7 +1904,7 @@ static void msb_io_work(struct work_struct *work)
/* process the request */
dbg_verbose("IO: processing new request");
- blk_rq_map_sg(msb->queue, req, sg);
+ blk_rq_map_sg(req, sg);
lba = blk_rq_pos(req);
@@ -1953,10 +1953,10 @@ static void msb_data_clear(struct msb_data *msb)
msb->card = NULL;
}
-static int msb_bd_getgeo(struct block_device *bdev,
+static int msb_bd_getgeo(struct gendisk *disk,
struct hd_geometry *geo)
{
- struct msb_data *msb = bdev->bd_disk->private_data;
+ struct msb_data *msb = disk->private_data;
*geo = msb->geometry;
return 0;
}
@@ -2027,7 +2027,7 @@ static void msb_stop(struct memstick_dev *card)
msb->io_queue_stopped = true;
spin_unlock_irqrestore(&msb->q_lock, flags);
- del_timer_sync(&msb->cache_flush_timer);
+ timer_delete_sync(&msb->cache_flush_timer);
flush_workqueue(msb->io_queue);
spin_lock_irqsave(&msb->q_lock, flags);
@@ -2094,8 +2094,7 @@ static int msb_init_disk(struct memstick_dev *card)
if (msb->disk_id < 0)
return msb->disk_id;
- rc = blk_mq_alloc_sq_tag_set(&msb->tag_set, &msb_mq_ops, 2,
- BLK_MQ_F_SHOULD_MERGE);
+ rc = blk_mq_alloc_sq_tag_set(&msb->tag_set, &msb_mq_ops, 2, 0);
if (rc)
goto out_release_id;
@@ -2279,7 +2278,7 @@ out:
#endif /* CONFIG_PM */
-static struct memstick_device_id msb_id_tbl[] = {
+static const struct memstick_device_id msb_id_tbl[] = {
{MEMSTICK_MATCH_ALL, MEMSTICK_TYPE_LEGACY, MEMSTICK_CATEGORY_STORAGE,
MEMSTICK_CLASS_FLASH},
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index 49accfdc89d6..e507bb11c802 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -189,10 +189,10 @@ static void mspro_block_bd_free_disk(struct gendisk *disk)
kfree(msb);
}
-static int mspro_block_bd_getgeo(struct block_device *bdev,
+static int mspro_block_bd_getgeo(struct gendisk *disk,
struct hd_geometry *geo)
{
- struct mspro_block_data *msb = bdev->bd_disk->private_data;
+ struct mspro_block_data *msb = disk->private_data;
geo->heads = msb->heads;
geo->sectors = msb->sectors_per_track;
@@ -560,8 +560,7 @@ has_int_reg:
t_offset += msb->current_page * msb->page_size;
sg_set_page(&t_sg,
- nth_page(sg_page(&(msb->req_sg[msb->current_seg])),
- t_offset >> PAGE_SHIFT),
+ sg_page(&(msb->req_sg[msb->current_seg])) + (t_offset >> PAGE_SHIFT),
msb->page_size, offset_in_page(t_offset));
memstick_init_req_sg(*mrq, msb->data_dir == READ
@@ -627,9 +626,7 @@ static int mspro_block_issue_req(struct memstick_dev *card)
while (true) {
msb->current_page = 0;
msb->current_seg = 0;
- msb->seg_count = blk_rq_map_sg(msb->block_req->q,
- msb->block_req,
- msb->req_sg);
+ msb->seg_count = blk_rq_map_sg(msb->block_req, msb->req_sg);
if (!msb->seg_count) {
unsigned int bytes = blk_rq_cur_bytes(msb->block_req);
@@ -1139,8 +1136,7 @@ static int mspro_block_init_disk(struct memstick_dev *card)
if (disk_id < 0)
return disk_id;
- rc = blk_mq_alloc_sq_tag_set(&msb->tag_set, &mspro_mq_ops, 2,
- BLK_MQ_F_SHOULD_MERGE);
+ rc = blk_mq_alloc_sq_tag_set(&msb->tag_set, &mspro_mq_ops, 2, 0);
if (rc)
goto out_release_id;
@@ -1349,7 +1345,7 @@ out_unlock:
#endif /* CONFIG_PM */
-static struct memstick_device_id mspro_block_id_tbl[] = {
+static const struct memstick_device_id mspro_block_id_tbl[] = {
{MEMSTICK_MATCH_ALL, MEMSTICK_TYPE_PRO, MEMSTICK_CATEGORY_STORAGE_DUO,
MEMSTICK_CLASS_DUO},
{}
diff --git a/drivers/memstick/host/Kconfig b/drivers/memstick/host/Kconfig
index 4113343da056..fcd2c2cc3cb4 100644
--- a/drivers/memstick/host/Kconfig
+++ b/drivers/memstick/host/Kconfig
@@ -44,16 +44,6 @@ config MEMSTICK_R592
To compile this driver as a module, choose M here: the module will
be called r592.
-config MEMSTICK_REALTEK_PCI
- tristate "Realtek PCI-E Memstick Card Interface Driver"
- depends on MISC_RTSX_PCI
- help
- Say Y here to include driver code to support Memstick card interface
- of Realtek PCI-E card reader
-
- To compile this driver as a module, choose M here: the module will
- be called rtsx_pci_ms.
-
config MEMSTICK_REALTEK_USB
tristate "Realtek USB Memstick Card Interface Driver"
depends on MISC_RTSX_USB
diff --git a/drivers/memstick/host/Makefile b/drivers/memstick/host/Makefile
index 1abaa03ee68c..0c90df33165d 100644
--- a/drivers/memstick/host/Makefile
+++ b/drivers/memstick/host/Makefile
@@ -6,5 +6,4 @@
obj-$(CONFIG_MEMSTICK_TIFM_MS) += tifm_ms.o
obj-$(CONFIG_MEMSTICK_JMICRON_38X) += jmb38x_ms.o
obj-$(CONFIG_MEMSTICK_R592) += r592.o
-obj-$(CONFIG_MEMSTICK_REALTEK_PCI) += rtsx_pci_ms.o
obj-$(CONFIG_MEMSTICK_REALTEK_USB) += rtsx_usb_ms.o
diff --git a/drivers/memstick/host/jmb38x_ms.c b/drivers/memstick/host/jmb38x_ms.c
index e77eb8b0eb12..79e66e30417c 100644
--- a/drivers/memstick/host/jmb38x_ms.c
+++ b/drivers/memstick/host/jmb38x_ms.c
@@ -317,8 +317,7 @@ static int jmb38x_ms_transfer_data(struct jmb38x_ms_host *host)
unsigned int p_off;
if (host->req->long_data) {
- pg = nth_page(sg_page(&host->req->sg),
- off >> PAGE_SHIFT);
+ pg = sg_page(&host->req->sg) + (off >> PAGE_SHIFT);
p_off = offset_in_page(off);
p_cnt = PAGE_SIZE - p_off;
p_cnt = min(p_cnt, length);
@@ -469,7 +468,7 @@ static void jmb38x_ms_complete_cmd(struct memstick_host *msh, int last)
unsigned int t_val = 0;
int rc;
- del_timer(&host->timer);
+ timer_delete(&host->timer);
dev_dbg(&msh->dev, "c control %08x\n",
readl(host->addr + HOST_CONTROL));
@@ -590,7 +589,7 @@ static irqreturn_t jmb38x_ms_isr(int irq, void *dev_id)
static void jmb38x_ms_abort(struct timer_list *t)
{
- struct jmb38x_ms_host *host = from_timer(host, t, timer);
+ struct jmb38x_ms_host *host = timer_container_of(host, t, timer);
struct memstick_host *msh = host->msh;
unsigned long flags;
diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
index 461f5ffd02bc..605b2265536f 100644
--- a/drivers/memstick/host/r592.c
+++ b/drivers/memstick/host/r592.c
@@ -614,7 +614,7 @@ static void r592_update_card_detect(struct r592_device *dev)
/* Timer routine that fires 1 second after last card detection event, */
static void r592_detect_timer(struct timer_list *t)
{
- struct r592_device *dev = from_timer(dev, t, detect_timer);
+ struct r592_device *dev = timer_container_of(dev, t, detect_timer);
r592_update_card_detect(dev);
memstick_detect_change(dev->host);
}
@@ -675,7 +675,7 @@ static irqreturn_t r592_irq(int irq, void *data)
return ret;
}
-/* External inteface: set settings */
+/* External interface: set settings */
static int r592_set_param(struct memstick_host *host,
enum memstick_param param, int value)
{
@@ -827,7 +827,7 @@ static void r592_remove(struct pci_dev *pdev)
/* Stop the processing thread.
That ensures that we won't take any more requests */
kthread_stop(dev->io_thread);
- del_timer_sync(&dev->detect_timer);
+ timer_delete_sync(&dev->detect_timer);
r592_enable_device(dev, false);
while (!error && dev->req) {
@@ -854,7 +854,7 @@ static int r592_suspend(struct device *core_dev)
r592_clear_interrupts(dev);
memstick_suspend_host(dev->host);
- del_timer_sync(&dev->detect_timer);
+ timer_delete_sync(&dev->detect_timer);
return 0;
}
diff --git a/drivers/memstick/host/rtsx_pci_ms.c b/drivers/memstick/host/rtsx_pci_ms.c
deleted file mode 100644
index 980a54513e6c..000000000000
--- a/drivers/memstick/host/rtsx_pci_ms.c
+++ /dev/null
@@ -1,638 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/* Realtek PCI-Express Memstick Card Interface driver
- *
- * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
- *
- * Author:
- * Wei WANG <wei_wang@realsil.com.cn>
- */
-
-#include <linux/module.h>
-#include <linux/highmem.h>
-#include <linux/delay.h>
-#include <linux/platform_device.h>
-#include <linux/memstick.h>
-#include <linux/rtsx_pci.h>
-#include <asm/unaligned.h>
-
-struct realtek_pci_ms {
- struct platform_device *pdev;
- struct rtsx_pcr *pcr;
- struct memstick_host *msh;
- struct memstick_request *req;
-
- struct mutex host_mutex;
- struct work_struct handle_req;
-
- u8 ssc_depth;
- unsigned int clock;
- unsigned char ifmode;
- bool eject;
-};
-
-static inline struct device *ms_dev(struct realtek_pci_ms *host)
-{
- return &(host->pdev->dev);
-}
-
-static inline void ms_clear_error(struct realtek_pci_ms *host)
-{
- rtsx_pci_write_register(host->pcr, CARD_STOP,
- MS_STOP | MS_CLR_ERR, MS_STOP | MS_CLR_ERR);
-}
-
-#ifdef DEBUG
-
-static void ms_print_debug_regs(struct realtek_pci_ms *host)
-{
- struct rtsx_pcr *pcr = host->pcr;
- u16 i;
- u8 *ptr;
-
- /* Print MS host internal registers */
- rtsx_pci_init_cmd(pcr);
- for (i = 0xFD40; i <= 0xFD44; i++)
- rtsx_pci_add_cmd(pcr, READ_REG_CMD, i, 0, 0);
- for (i = 0xFD52; i <= 0xFD69; i++)
- rtsx_pci_add_cmd(pcr, READ_REG_CMD, i, 0, 0);
- rtsx_pci_send_cmd(pcr, 100);
-
- ptr = rtsx_pci_get_cmd_data(pcr);
- for (i = 0xFD40; i <= 0xFD44; i++)
- dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", i, *(ptr++));
- for (i = 0xFD52; i <= 0xFD69; i++)
- dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", i, *(ptr++));
-}
-
-#else
-
-#define ms_print_debug_regs(host)
-
-#endif
-
-static int ms_power_on(struct realtek_pci_ms *host)
-{
- struct rtsx_pcr *pcr = host->pcr;
- int err;
-
- rtsx_pci_init_cmd(pcr);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_SELECT, 0x07, MS_MOD_SEL);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_SHARE_MODE,
- CARD_SHARE_MASK, CARD_SHARE_48_MS);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_CLK_EN,
- MS_CLK_EN, MS_CLK_EN);
- err = rtsx_pci_send_cmd(pcr, 100);
- if (err < 0)
- return err;
-
- err = rtsx_pci_card_pull_ctl_enable(pcr, RTSX_MS_CARD);
- if (err < 0)
- return err;
-
- err = rtsx_pci_card_power_on(pcr, RTSX_MS_CARD);
- if (err < 0)
- return err;
-
- /* Wait ms power stable */
- msleep(150);
-
- err = rtsx_pci_write_register(pcr, CARD_OE,
- MS_OUTPUT_EN, MS_OUTPUT_EN);
- if (err < 0)
- return err;
-
- return 0;
-}
-
-static int ms_power_off(struct realtek_pci_ms *host)
-{
- struct rtsx_pcr *pcr = host->pcr;
- int err;
-
- rtsx_pci_init_cmd(pcr);
-
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_CLK_EN, MS_CLK_EN, 0);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_OE, MS_OUTPUT_EN, 0);
-
- err = rtsx_pci_send_cmd(pcr, 100);
- if (err < 0)
- return err;
-
- err = rtsx_pci_card_power_off(pcr, RTSX_MS_CARD);
- if (err < 0)
- return err;
-
- return rtsx_pci_card_pull_ctl_disable(pcr, RTSX_MS_CARD);
-}
-
-static int ms_transfer_data(struct realtek_pci_ms *host, unsigned char data_dir,
- u8 tpc, u8 cfg, struct scatterlist *sg)
-{
- struct rtsx_pcr *pcr = host->pcr;
- int err;
- unsigned int length = sg->length;
- u16 sec_cnt = (u16)(length / 512);
- u8 val, trans_mode, dma_dir;
- struct memstick_dev *card = host->msh->card;
- bool pro_card = card->id.type == MEMSTICK_TYPE_PRO;
-
- dev_dbg(ms_dev(host), "%s: tpc = 0x%02x, data_dir = %s, length = %d\n",
- __func__, tpc, (data_dir == READ) ? "READ" : "WRITE",
- length);
-
- if (data_dir == READ) {
- dma_dir = DMA_DIR_FROM_CARD;
- trans_mode = pro_card ? MS_TM_AUTO_READ : MS_TM_NORMAL_READ;
- } else {
- dma_dir = DMA_DIR_TO_CARD;
- trans_mode = pro_card ? MS_TM_AUTO_WRITE : MS_TM_NORMAL_WRITE;
- }
-
- rtsx_pci_init_cmd(pcr);
-
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_TPC, 0xFF, tpc);
- if (pro_card) {
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_SECTOR_CNT_H,
- 0xFF, (u8)(sec_cnt >> 8));
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_SECTOR_CNT_L,
- 0xFF, (u8)sec_cnt);
- }
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_TRANS_CFG, 0xFF, cfg);
-
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, IRQSTAT0,
- DMA_DONE_INT, DMA_DONE_INT);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, DMATC3, 0xFF, (u8)(length >> 24));
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, DMATC2, 0xFF, (u8)(length >> 16));
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, DMATC1, 0xFF, (u8)(length >> 8));
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, DMATC0, 0xFF, (u8)length);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, DMACTL,
- 0x03 | DMA_PACK_SIZE_MASK, dma_dir | DMA_EN | DMA_512);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_DATA_SOURCE,
- 0x01, RING_BUFFER);
-
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_TRANSFER,
- 0xFF, MS_TRANSFER_START | trans_mode);
- rtsx_pci_add_cmd(pcr, CHECK_REG_CMD, MS_TRANSFER,
- MS_TRANSFER_END, MS_TRANSFER_END);
-
- rtsx_pci_send_cmd_no_wait(pcr);
-
- err = rtsx_pci_transfer_data(pcr, sg, 1, data_dir == READ, 10000);
- if (err < 0) {
- ms_clear_error(host);
- return err;
- }
-
- rtsx_pci_read_register(pcr, MS_TRANS_CFG, &val);
- if (pro_card) {
- if (val & (MS_INT_CMDNK | MS_INT_ERR |
- MS_CRC16_ERR | MS_RDY_TIMEOUT))
- return -EIO;
- } else {
- if (val & (MS_CRC16_ERR | MS_RDY_TIMEOUT))
- return -EIO;
- }
-
- return 0;
-}
-
-static int ms_write_bytes(struct realtek_pci_ms *host, u8 tpc,
- u8 cfg, u8 cnt, u8 *data, u8 *int_reg)
-{
- struct rtsx_pcr *pcr = host->pcr;
- int err, i;
-
- dev_dbg(ms_dev(host), "%s: tpc = 0x%02x\n", __func__, tpc);
-
- if (!data)
- return -EINVAL;
-
- rtsx_pci_init_cmd(pcr);
-
- for (i = 0; i < cnt; i++)
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD,
- PPBUF_BASE2 + i, 0xFF, data[i]);
- if (cnt % 2)
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD,
- PPBUF_BASE2 + i, 0xFF, 0xFF);
-
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_TPC, 0xFF, tpc);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_BYTE_CNT, 0xFF, cnt);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_TRANS_CFG, 0xFF, cfg);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_DATA_SOURCE,
- 0x01, PINGPONG_BUFFER);
-
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_TRANSFER,
- 0xFF, MS_TRANSFER_START | MS_TM_WRITE_BYTES);
- rtsx_pci_add_cmd(pcr, CHECK_REG_CMD, MS_TRANSFER,
- MS_TRANSFER_END, MS_TRANSFER_END);
- if (int_reg)
- rtsx_pci_add_cmd(pcr, READ_REG_CMD, MS_TRANS_CFG, 0, 0);
-
- err = rtsx_pci_send_cmd(pcr, 5000);
- if (err < 0) {
- u8 val;
-
- rtsx_pci_read_register(pcr, MS_TRANS_CFG, &val);
- dev_dbg(ms_dev(host), "MS_TRANS_CFG: 0x%02x\n", val);
-
- if (int_reg)
- *int_reg = val & 0x0F;
-
- ms_print_debug_regs(host);
-
- ms_clear_error(host);
-
- if (!(tpc & 0x08)) {
- if (val & MS_CRC16_ERR)
- return -EIO;
- } else {
- if (!(val & 0x80)) {
- if (val & (MS_INT_ERR | MS_INT_CMDNK))
- return -EIO;
- }
- }
-
- return -ETIMEDOUT;
- }
-
- if (int_reg) {
- u8 *ptr = rtsx_pci_get_cmd_data(pcr) + 1;
- *int_reg = *ptr & 0x0F;
- }
-
- return 0;
-}
-
-static int ms_read_bytes(struct realtek_pci_ms *host, u8 tpc,
- u8 cfg, u8 cnt, u8 *data, u8 *int_reg)
-{
- struct rtsx_pcr *pcr = host->pcr;
- int err, i;
- u8 *ptr;
-
- dev_dbg(ms_dev(host), "%s: tpc = 0x%02x\n", __func__, tpc);
-
- if (!data)
- return -EINVAL;
-
- rtsx_pci_init_cmd(pcr);
-
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_TPC, 0xFF, tpc);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_BYTE_CNT, 0xFF, cnt);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_TRANS_CFG, 0xFF, cfg);
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_DATA_SOURCE,
- 0x01, PINGPONG_BUFFER);
-
- rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, MS_TRANSFER,
- 0xFF, MS_TRANSFER_START | MS_TM_READ_BYTES);
- rtsx_pci_add_cmd(pcr, CHECK_REG_CMD, MS_TRANSFER,
- MS_TRANSFER_END, MS_TRANSFER_END);
- for (i = 0; i < cnt - 1; i++)
- rtsx_pci_add_cmd(pcr, READ_REG_CMD, PPBUF_BASE2 + i, 0, 0);
- if (cnt % 2)
- rtsx_pci_add_cmd(pcr, READ_REG_CMD, PPBUF_BASE2 + cnt, 0, 0);
- else
- rtsx_pci_add_cmd(pcr, READ_REG_CMD,
- PPBUF_BASE2 + cnt - 1, 0, 0);
- if (int_reg)
- rtsx_pci_add_cmd(pcr, READ_REG_CMD, MS_TRANS_CFG, 0, 0);
-
- err = rtsx_pci_send_cmd(pcr, 5000);
- if (err < 0) {
- u8 val;
-
- rtsx_pci_read_register(pcr, MS_TRANS_CFG, &val);
- dev_dbg(ms_dev(host), "MS_TRANS_CFG: 0x%02x\n", val);
-
- if (int_reg)
- *int_reg = val & 0x0F;
-
- ms_print_debug_regs(host);
-
- ms_clear_error(host);
-
- if (!(tpc & 0x08)) {
- if (val & MS_CRC16_ERR)
- return -EIO;
- } else {
- if (!(val & 0x80)) {
- if (val & (MS_INT_ERR | MS_INT_CMDNK))
- return -EIO;
- }
- }
-
- return -ETIMEDOUT;
- }
-
- ptr = rtsx_pci_get_cmd_data(pcr) + 1;
- for (i = 0; i < cnt; i++)
- data[i] = *ptr++;
-
- if (int_reg)
- *int_reg = *ptr & 0x0F;
-
- return 0;
-}
-
-static int rtsx_pci_ms_issue_cmd(struct realtek_pci_ms *host)
-{
- struct memstick_request *req = host->req;
- int err = 0;
- u8 cfg = 0, int_reg;
-
- dev_dbg(ms_dev(host), "%s\n", __func__);
-
- if (req->need_card_int) {
- if (host->ifmode != MEMSTICK_SERIAL)
- cfg = WAIT_INT;
- }
-
- if (req->long_data) {
- err = ms_transfer_data(host, req->data_dir,
- req->tpc, cfg, &(req->sg));
- } else {
- if (req->data_dir == READ) {
- err = ms_read_bytes(host, req->tpc, cfg,
- req->data_len, req->data, &int_reg);
- } else {
- err = ms_write_bytes(host, req->tpc, cfg,
- req->data_len, req->data, &int_reg);
- }
- }
- if (err < 0)
- return err;
-
- if (req->need_card_int && (host->ifmode == MEMSTICK_SERIAL)) {
- err = ms_read_bytes(host, MS_TPC_GET_INT,
- NO_WAIT_INT, 1, &int_reg, NULL);
- if (err < 0)
- return err;
- }
-
- if (req->need_card_int) {
- dev_dbg(ms_dev(host), "int_reg: 0x%02x\n", int_reg);
-
- if (int_reg & MS_INT_CMDNK)
- req->int_reg |= MEMSTICK_INT_CMDNAK;
- if (int_reg & MS_INT_BREQ)
- req->int_reg |= MEMSTICK_INT_BREQ;
- if (int_reg & MS_INT_ERR)
- req->int_reg |= MEMSTICK_INT_ERR;
- if (int_reg & MS_INT_CED)
- req->int_reg |= MEMSTICK_INT_CED;
- }
-
- return 0;
-}
-
-static void rtsx_pci_ms_handle_req(struct work_struct *work)
-{
- struct realtek_pci_ms *host = container_of(work,
- struct realtek_pci_ms, handle_req);
- struct rtsx_pcr *pcr = host->pcr;
- struct memstick_host *msh = host->msh;
- int rc;
-
- mutex_lock(&pcr->pcr_mutex);
-
- rtsx_pci_start_run(pcr);
-
- rtsx_pci_switch_clock(host->pcr, host->clock, host->ssc_depth,
- false, true, false);
- rtsx_pci_write_register(pcr, CARD_SELECT, 0x07, MS_MOD_SEL);
- rtsx_pci_write_register(pcr, CARD_SHARE_MODE,
- CARD_SHARE_MASK, CARD_SHARE_48_MS);
-
- if (!host->req) {
- do {
- rc = memstick_next_req(msh, &host->req);
- dev_dbg(ms_dev(host), "next req %d\n", rc);
-
- if (!rc)
- host->req->error = rtsx_pci_ms_issue_cmd(host);
- } while (!rc);
- }
-
- mutex_unlock(&pcr->pcr_mutex);
-}
-
-static void rtsx_pci_ms_request(struct memstick_host *msh)
-{
- struct realtek_pci_ms *host = memstick_priv(msh);
-
- dev_dbg(ms_dev(host), "--> %s\n", __func__);
-
- if (rtsx_pci_card_exclusive_check(host->pcr, RTSX_MS_CARD))
- return;
-
- schedule_work(&host->handle_req);
-}
-
-static int rtsx_pci_ms_set_param(struct memstick_host *msh,
- enum memstick_param param, int value)
-{
- struct realtek_pci_ms *host = memstick_priv(msh);
- struct rtsx_pcr *pcr = host->pcr;
- unsigned int clock = 0;
- u8 ssc_depth = 0;
- int err;
-
- dev_dbg(ms_dev(host), "%s: param = %d, value = %d\n",
- __func__, param, value);
-
- err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_MS_CARD);
- if (err)
- return err;
-
- switch (param) {
- case MEMSTICK_POWER:
- if (value == MEMSTICK_POWER_ON)
- err = ms_power_on(host);
- else if (value == MEMSTICK_POWER_OFF)
- err = ms_power_off(host);
- else
- return -EINVAL;
- break;
-
- case MEMSTICK_INTERFACE:
- if (value == MEMSTICK_SERIAL) {
- clock = 19000000;
- ssc_depth = RTSX_SSC_DEPTH_500K;
-
- err = rtsx_pci_write_register(pcr, MS_CFG, 0x58,
- MS_BUS_WIDTH_1 | PUSH_TIME_DEFAULT);
- if (err < 0)
- return err;
- } else if (value == MEMSTICK_PAR4) {
- clock = 39000000;
- ssc_depth = RTSX_SSC_DEPTH_1M;
-
- err = rtsx_pci_write_register(pcr, MS_CFG,
- 0x58, MS_BUS_WIDTH_4 | PUSH_TIME_ODD);
- if (err < 0)
- return err;
- } else {
- return -EINVAL;
- }
-
- err = rtsx_pci_switch_clock(pcr, clock,
- ssc_depth, false, true, false);
- if (err < 0)
- return err;
-
- host->ssc_depth = ssc_depth;
- host->clock = clock;
- host->ifmode = value;
- break;
- }
-
- return 0;
-}
-
-#ifdef CONFIG_PM
-
-static int rtsx_pci_ms_suspend(struct platform_device *pdev, pm_message_t state)
-{
- struct realtek_pci_ms *host = platform_get_drvdata(pdev);
- struct memstick_host *msh = host->msh;
-
- dev_dbg(ms_dev(host), "--> %s\n", __func__);
-
- memstick_suspend_host(msh);
- return 0;
-}
-
-static int rtsx_pci_ms_resume(struct platform_device *pdev)
-{
- struct realtek_pci_ms *host = platform_get_drvdata(pdev);
- struct memstick_host *msh = host->msh;
-
- dev_dbg(ms_dev(host), "--> %s\n", __func__);
-
- memstick_resume_host(msh);
- return 0;
-}
-
-#else /* CONFIG_PM */
-
-#define rtsx_pci_ms_suspend NULL
-#define rtsx_pci_ms_resume NULL
-
-#endif /* CONFIG_PM */
-
-static void rtsx_pci_ms_card_event(struct platform_device *pdev)
-{
- struct realtek_pci_ms *host = platform_get_drvdata(pdev);
-
- memstick_detect_change(host->msh);
-}
-
-static int rtsx_pci_ms_drv_probe(struct platform_device *pdev)
-{
- struct memstick_host *msh;
- struct realtek_pci_ms *host;
- struct rtsx_pcr *pcr;
- struct pcr_handle *handle = pdev->dev.platform_data;
- int rc;
-
- if (!handle)
- return -ENXIO;
-
- pcr = handle->pcr;
- if (!pcr)
- return -ENXIO;
-
- dev_dbg(&(pdev->dev),
- ": Realtek PCI-E Memstick controller found\n");
-
- msh = memstick_alloc_host(sizeof(*host), &pdev->dev);
- if (!msh)
- return -ENOMEM;
-
- host = memstick_priv(msh);
- host->pcr = pcr;
- host->msh = msh;
- host->pdev = pdev;
- platform_set_drvdata(pdev, host);
- pcr->slots[RTSX_MS_CARD].p_dev = pdev;
- pcr->slots[RTSX_MS_CARD].card_event = rtsx_pci_ms_card_event;
-
- mutex_init(&host->host_mutex);
-
- INIT_WORK(&host->handle_req, rtsx_pci_ms_handle_req);
- msh->request = rtsx_pci_ms_request;
- msh->set_param = rtsx_pci_ms_set_param;
- msh->caps = MEMSTICK_CAP_PAR4;
-
- rc = memstick_add_host(msh);
- if (rc) {
- memstick_free_host(msh);
- return rc;
- }
-
- return 0;
-}
-
-static void rtsx_pci_ms_drv_remove(struct platform_device *pdev)
-{
- struct realtek_pci_ms *host = platform_get_drvdata(pdev);
- struct rtsx_pcr *pcr;
- struct memstick_host *msh;
- int rc;
-
- pcr = host->pcr;
- pcr->slots[RTSX_MS_CARD].p_dev = NULL;
- pcr->slots[RTSX_MS_CARD].card_event = NULL;
- msh = host->msh;
- host->eject = true;
- cancel_work_sync(&host->handle_req);
-
- mutex_lock(&host->host_mutex);
- if (host->req) {
- dev_dbg(&(pdev->dev),
- "%s: Controller removed during transfer\n",
- dev_name(&msh->dev));
-
- rtsx_pci_complete_unfinished_transfer(pcr);
-
- host->req->error = -ENOMEDIUM;
- do {
- rc = memstick_next_req(msh, &host->req);
- if (!rc)
- host->req->error = -ENOMEDIUM;
- } while (!rc);
- }
- mutex_unlock(&host->host_mutex);
-
- memstick_remove_host(msh);
- memstick_free_host(msh);
-
- dev_dbg(&(pdev->dev),
- ": Realtek PCI-E Memstick controller has been removed\n");
-}
-
-static struct platform_device_id rtsx_pci_ms_ids[] = {
- {
- .name = DRV_NAME_RTSX_PCI_MS,
- }, {
- /* sentinel */
- }
-};
-MODULE_DEVICE_TABLE(platform, rtsx_pci_ms_ids);
-
-static struct platform_driver rtsx_pci_ms_driver = {
- .probe = rtsx_pci_ms_drv_probe,
- .remove_new = rtsx_pci_ms_drv_remove,
- .id_table = rtsx_pci_ms_ids,
- .suspend = rtsx_pci_ms_suspend,
- .resume = rtsx_pci_ms_resume,
- .driver = {
- .name = DRV_NAME_RTSX_PCI_MS,
- },
-};
-module_platform_driver(rtsx_pci_ms_driver);
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Wei WANG <wei_wang@realsil.com.cn>");
-MODULE_DESCRIPTION("Realtek PCI-E Memstick Card Host Driver");
diff --git a/drivers/memstick/host/rtsx_usb_ms.c b/drivers/memstick/host/rtsx_usb_ms.c
index 246876ac713c..beadc389f15f 100644
--- a/drivers/memstick/host/rtsx_usb_ms.c
+++ b/drivers/memstick/host/rtsx_usb_ms.c
@@ -19,7 +19,7 @@
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/completion.h>
-#include <asm/unaligned.h>
+#include <linux/unaligned.h>
struct rtsx_usb_ms {
struct platform_device *pdev;
@@ -216,7 +216,10 @@ static int ms_power_off(struct rtsx_usb_ms *host)
rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_CLK_EN, MS_CLK_EN, 0);
rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_OE, MS_OUTPUT_EN, 0);
-
+ rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PWR_CTL,
+ POWER_MASK, POWER_OFF);
+ rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PWR_CTL,
+ POWER_MASK | LDO3318_PWR_MASK, POWER_OFF | LDO_SUSPEND);
err = rtsx_usb_send_cmd(ucr, MODE_C, 100);
if (err < 0)
return err;
@@ -812,7 +815,9 @@ static void rtsx_usb_ms_drv_remove(struct platform_device *pdev)
int err;
host->eject = true;
+ msh->removing = true;
cancel_work_sync(&host->handle_req);
+ cancel_delayed_work_sync(&host->poll_card);
mutex_lock(&host->host_mutex);
if (host->req) {
@@ -853,7 +858,7 @@ MODULE_DEVICE_TABLE(platform, rtsx_usb_ms_ids);
static struct platform_driver rtsx_usb_ms_driver = {
.probe = rtsx_usb_ms_drv_probe,
- .remove_new = rtsx_usb_ms_drv_remove,
+ .remove = rtsx_usb_ms_drv_remove,
.id_table = rtsx_usb_ms_ids,
.driver = {
.name = "rtsx_usb_ms",
diff --git a/drivers/memstick/host/tifm_ms.c b/drivers/memstick/host/tifm_ms.c
index c272453670be..0b6a90661eee 100644
--- a/drivers/memstick/host/tifm_ms.c
+++ b/drivers/memstick/host/tifm_ms.c
@@ -201,8 +201,7 @@ static unsigned int tifm_ms_transfer_data(struct tifm_ms *host)
unsigned int p_off;
if (host->req->long_data) {
- pg = nth_page(sg_page(&host->req->sg),
- off >> PAGE_SHIFT);
+ pg = sg_page(&host->req->sg) + (off >> PAGE_SHIFT);
p_off = offset_in_page(off);
p_cnt = PAGE_SIZE - p_off;
p_cnt = min(p_cnt, length);
@@ -337,7 +336,7 @@ static void tifm_ms_complete_cmd(struct tifm_ms *host)
struct memstick_host *msh = tifm_get_drvdata(sock);
int rc;
- del_timer(&host->timer);
+ timer_delete(&host->timer);
host->req->int_reg = readl(sock->addr + SOCK_MS_STATUS) & 0xff;
host->req->int_reg = (host->req->int_reg & 1)
@@ -535,7 +534,7 @@ static int tifm_ms_set_param(struct memstick_host *msh,
static void tifm_ms_abort(struct timer_list *t)
{
- struct tifm_ms *host = from_timer(host, t, timer);
+ struct tifm_ms *host = timer_container_of(host, t, timer);
dev_dbg(&host->dev->dev, "status %x\n",
readl(host->dev->addr + SOCK_MS_STATUS));
@@ -600,7 +599,7 @@ static void tifm_ms_remove(struct tifm_dev *sock)
spin_lock_irqsave(&sock->lock, flags);
host->eject = 1;
if (host->req) {
- del_timer(&host->timer);
+ timer_delete(&host->timer);
writel(TIFM_FIFO_INT_SETALL,
sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR);
writel(TIFM_DMA_RESET, sock->addr + SOCK_DMA_CONTROL);