diff options
| author | Roger Tseng <rogerable@realtek.com> | 2014-04-11 02:53:23 -0400 |
|---|---|---|
| committer | Lee Jones <lee.jones@linaro.org> | 2014-04-28 06:02:46 -0400 |
| commit | 99451dceeb5fdd789f0a2eeb3ee029e80d2ccc40 (patch) | |
| tree | 33f0c80f7f6434354638faac8fed6f3bf27caa5f /drivers/memstick | |
| parent | 1d14310abb74011dc5523baf0aee75b94070861a (diff) | |
memstick: Add realtek USB memstick host driver
Realtek USB memstick host driver provides memstick host support based on the
Realtek USB card reader MFD driver.
Signed-off-by: Roger Tseng <rogerable@realtek.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'drivers/memstick')
| -rw-r--r-- | drivers/memstick/host/Kconfig | 10 | ||||
| -rw-r--r-- | drivers/memstick/host/Makefile | 1 | ||||
| -rw-r--r-- | drivers/memstick/host/rtsx_usb_ms.c | 839 |
3 files changed, 850 insertions, 0 deletions
diff --git a/drivers/memstick/host/Kconfig b/drivers/memstick/host/Kconfig index 1b37cf8cd204..7310e32b5991 100644 --- a/drivers/memstick/host/Kconfig +++ b/drivers/memstick/host/Kconfig | |||
| @@ -52,3 +52,13 @@ config MEMSTICK_REALTEK_PCI | |||
| 52 | 52 | ||
| 53 | To compile this driver as a module, choose M here: the module will | 53 | To compile this driver as a module, choose M here: the module will |
| 54 | be called rtsx_pci_ms. | 54 | be called rtsx_pci_ms. |
| 55 | |||
| 56 | config MEMSTICK_REALTEK_USB | ||
| 57 | tristate "Realtek USB Memstick Card Interface Driver" | ||
| 58 | depends on MFD_RTSX_USB | ||
| 59 | help | ||
| 60 | Say Y here to include driver code to support Memstick card interface | ||
| 61 | of Realtek RTS5129/39 series USB card reader | ||
| 62 | |||
| 63 | To compile this driver as a module, choose M here: the module will | ||
| 64 | be called rts5139_ms. | ||
diff --git a/drivers/memstick/host/Makefile b/drivers/memstick/host/Makefile index af3459d7686e..491c9557441d 100644 --- a/drivers/memstick/host/Makefile +++ b/drivers/memstick/host/Makefile | |||
| @@ -6,3 +6,4 @@ obj-$(CONFIG_MEMSTICK_TIFM_MS) += tifm_ms.o | |||
| 6 | obj-$(CONFIG_MEMSTICK_JMICRON_38X) += jmb38x_ms.o | 6 | obj-$(CONFIG_MEMSTICK_JMICRON_38X) += jmb38x_ms.o |
| 7 | obj-$(CONFIG_MEMSTICK_R592) += r592.o | 7 | obj-$(CONFIG_MEMSTICK_R592) += r592.o |
| 8 | obj-$(CONFIG_MEMSTICK_REALTEK_PCI) += rtsx_pci_ms.o | 8 | obj-$(CONFIG_MEMSTICK_REALTEK_PCI) += rtsx_pci_ms.o |
| 9 | obj-$(CONFIG_MEMSTICK_REALTEK_USB) += rtsx_usb_ms.o | ||
diff --git a/drivers/memstick/host/rtsx_usb_ms.c b/drivers/memstick/host/rtsx_usb_ms.c new file mode 100644 index 000000000000..a7282b7d4de8 --- /dev/null +++ b/drivers/memstick/host/rtsx_usb_ms.c | |||
| @@ -0,0 +1,839 @@ | |||
| 1 | /* Realtek USB Memstick Card Interface driver | ||
| 2 | * | ||
| 3 | * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved. | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 | ||
| 7 | * as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License along | ||
| 15 | * with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | * | ||
| 17 | * Author: | ||
| 18 | * Roger Tseng <rogerable@realtek.com> | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <linux/module.h> | ||
| 22 | #include <linux/highmem.h> | ||
| 23 | #include <linux/delay.h> | ||
| 24 | #include <linux/platform_device.h> | ||
| 25 | #include <linux/workqueue.h> | ||
| 26 | #include <linux/memstick.h> | ||
| 27 | #include <linux/kthread.h> | ||
| 28 | #include <linux/mfd/rtsx_usb.h> | ||
| 29 | #include <linux/pm_runtime.h> | ||
| 30 | #include <linux/mutex.h> | ||
| 31 | #include <linux/sched.h> | ||
| 32 | #include <linux/completion.h> | ||
| 33 | #include <asm/unaligned.h> | ||
| 34 | |||
| 35 | struct rtsx_usb_ms { | ||
| 36 | struct platform_device *pdev; | ||
| 37 | struct rtsx_ucr *ucr; | ||
| 38 | struct memstick_host *msh; | ||
| 39 | struct memstick_request *req; | ||
| 40 | |||
| 41 | struct mutex host_mutex; | ||
| 42 | struct work_struct handle_req; | ||
| 43 | |||
| 44 | struct task_struct *detect_ms; | ||
| 45 | struct completion detect_ms_exit; | ||
| 46 | |||
| 47 | u8 ssc_depth; | ||
| 48 | unsigned int clock; | ||
| 49 | int power_mode; | ||
| 50 | unsigned char ifmode; | ||
| 51 | bool eject; | ||
| 52 | }; | ||
| 53 | |||
| 54 | static inline struct device *ms_dev(struct rtsx_usb_ms *host) | ||
| 55 | { | ||
| 56 | return &(host->pdev->dev); | ||
| 57 | } | ||
| 58 | |||
| 59 | static inline void ms_clear_error(struct rtsx_usb_ms *host) | ||
| 60 | { | ||
| 61 | struct rtsx_ucr *ucr = host->ucr; | ||
| 62 | rtsx_usb_ep0_write_register(ucr, CARD_STOP, | ||
| 63 | MS_STOP | MS_CLR_ERR, | ||
| 64 | MS_STOP | MS_CLR_ERR); | ||
| 65 | |||
| 66 | rtsx_usb_clear_dma_err(ucr); | ||
| 67 | rtsx_usb_clear_fsm_err(ucr); | ||
| 68 | } | ||
| 69 | |||
| 70 | #ifdef DEBUG | ||
| 71 | |||
| 72 | static void ms_print_debug_regs(struct rtsx_usb_ms *host) | ||
| 73 | { | ||
| 74 | struct rtsx_ucr *ucr = host->ucr; | ||
| 75 | u16 i; | ||
| 76 | u8 *ptr; | ||
| 77 | |||
| 78 | /* Print MS host internal registers */ | ||
| 79 | rtsx_usb_init_cmd(ucr); | ||
| 80 | |||
| 81 | /* MS_CFG to MS_INT_REG */ | ||
| 82 | for (i = 0xFD40; i <= 0xFD44; i++) | ||
| 83 | rtsx_usb_add_cmd(ucr, READ_REG_CMD, i, 0, 0); | ||
| 84 | |||
| 85 | /* CARD_SHARE_MODE to CARD_GPIO */ | ||
| 86 | for (i = 0xFD51; i <= 0xFD56; i++) | ||
| 87 | rtsx_usb_add_cmd(ucr, READ_REG_CMD, i, 0, 0); | ||
| 88 | |||
| 89 | /* CARD_PULL_CTLx */ | ||
| 90 | for (i = 0xFD60; i <= 0xFD65; i++) | ||
| 91 | rtsx_usb_add_cmd(ucr, READ_REG_CMD, i, 0, 0); | ||
| 92 | |||
| 93 | /* CARD_DATA_SOURCE, CARD_SELECT, CARD_CLK_EN, CARD_PWR_CTL */ | ||
| 94 | rtsx_usb_add_cmd(ucr, READ_REG_CMD, CARD_DATA_SOURCE, 0, 0); | ||
| 95 | rtsx_usb_add_cmd(ucr, READ_REG_CMD, CARD_SELECT, 0, 0); | ||
| 96 | rtsx_usb_add_cmd(ucr, READ_REG_CMD, CARD_CLK_EN, 0, 0); | ||
| 97 | rtsx_usb_add_cmd(ucr, READ_REG_CMD, CARD_PWR_CTL, 0, 0); | ||
| 98 | |||
| 99 | rtsx_usb_send_cmd(ucr, MODE_CR, 100); | ||
| 100 | rtsx_usb_get_rsp(ucr, 21, 100); | ||
| 101 | |||
| 102 | ptr = ucr->rsp_buf; | ||
| 103 | for (i = 0xFD40; i <= 0xFD44; i++) | ||
| 104 | dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", i, *(ptr++)); | ||
| 105 | for (i = 0xFD51; i <= 0xFD56; i++) | ||
| 106 | dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", i, *(ptr++)); | ||
| 107 | for (i = 0xFD60; i <= 0xFD65; i++) | ||
| 108 | dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", i, *(ptr++)); | ||
| 109 | |||
| 110 | dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", CARD_DATA_SOURCE, *(ptr++)); | ||
| 111 | dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", CARD_SELECT, *(ptr++)); | ||
| 112 | dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", CARD_CLK_EN, *(ptr++)); | ||
| 113 | dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", CARD_PWR_CTL, *(ptr++)); | ||
| 114 | } | ||
| 115 | |||
| 116 | #else | ||
| 117 | |||
| 118 | static void ms_print_debug_regs(struct rtsx_usb_ms *host) | ||
| 119 | { | ||
| 120 | } | ||
| 121 | |||
| 122 | #endif | ||
| 123 | |||
| 124 | static int ms_pull_ctl_disable_lqfp48(struct rtsx_ucr *ucr) | ||
| 125 | { | ||
| 126 | rtsx_usb_init_cmd(ucr); | ||
| 127 | |||
| 128 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL1, 0xFF, 0x55); | ||
| 129 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL2, 0xFF, 0x55); | ||
| 130 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL3, 0xFF, 0x95); | ||
| 131 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL4, 0xFF, 0x55); | ||
| 132 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL5, 0xFF, 0x55); | ||
| 133 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL6, 0xFF, 0xA5); | ||
| 134 | |||
| 135 | return rtsx_usb_send_cmd(ucr, MODE_C, 100); | ||
| 136 | } | ||
| 137 | |||
| 138 | static int ms_pull_ctl_disable_qfn24(struct rtsx_ucr *ucr) | ||
| 139 | { | ||
| 140 | rtsx_usb_init_cmd(ucr); | ||
| 141 | |||
| 142 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL1, 0xFF, 0x65); | ||
| 143 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL2, 0xFF, 0x55); | ||
| 144 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL3, 0xFF, 0x95); | ||
| 145 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL4, 0xFF, 0x55); | ||
| 146 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL5, 0xFF, 0x56); | ||
| 147 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL6, 0xFF, 0x59); | ||
| 148 | |||
| 149 | return rtsx_usb_send_cmd(ucr, MODE_C, 100); | ||
| 150 | } | ||
| 151 | |||
| 152 | static int ms_pull_ctl_enable_lqfp48(struct rtsx_ucr *ucr) | ||
| 153 | { | ||
| 154 | rtsx_usb_init_cmd(ucr); | ||
| 155 | |||
| 156 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL1, 0xFF, 0x55); | ||
| 157 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL2, 0xFF, 0x55); | ||
| 158 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL3, 0xFF, 0x95); | ||
| 159 | rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL4, 0xFF, 0x55); | ||
