diff options
| author | Roger Tseng <rogerable@realtek.com> | 2014-02-12 05:00:36 -0500 |
|---|---|---|
| committer | Lee Jones <lee.jones@linaro.org> | 2014-03-19 04:58:18 -0400 |
| commit | 730876be256603b4ee7225a125467d97a7ce9060 (patch) | |
| tree | 8c4f3b6156db3bb733d7d34a04a022993a25b953 /include/linux/mfd | |
| parent | c88fd91bcd016b84e5f7d7ebd583e073e5ead48a (diff) | |
mfd: Add realtek USB card reader driver
Realtek USB card reader provides a channel to transfer command or data to flash
memory cards. This driver exports host instances for mmc and memstick subsystems
and handles basic works.
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Roger Tseng <rogerable@realtek.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'include/linux/mfd')
| -rw-r--r-- | include/linux/mfd/rtsx_usb.h | 628 |
1 files changed, 628 insertions, 0 deletions
diff --git a/include/linux/mfd/rtsx_usb.h b/include/linux/mfd/rtsx_usb.h new file mode 100644 index 000000000000..c446e4fd6b5c --- /dev/null +++ b/include/linux/mfd/rtsx_usb.h | |||
| @@ -0,0 +1,628 @@ | |||
| 1 | /* Driver for Realtek RTS5139 USB card reader | ||
| 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 | #ifndef __RTSX_USB_H | ||
| 22 | #define __RTSX_USB_H | ||
| 23 | |||
| 24 | #include <linux/usb.h> | ||
| 25 | |||
| 26 | /* related module names */ | ||
| 27 | #define RTSX_USB_SD_CARD 0 | ||
| 28 | #define RTSX_USB_MS_CARD 1 | ||
| 29 | |||
| 30 | /* endpoint numbers */ | ||
| 31 | #define EP_BULK_OUT 1 | ||
| 32 | #define EP_BULK_IN 2 | ||
| 33 | #define EP_INTR_IN 3 | ||
| 34 | |||
| 35 | /* USB vendor requests */ | ||
| 36 | #define RTSX_USB_REQ_REG_OP 0x00 | ||
| 37 | #define RTSX_USB_REQ_POLL 0x02 | ||
| 38 | |||
| 39 | /* miscellaneous parameters */ | ||
| 40 | #define MIN_DIV_N 60 | ||
| 41 | #define MAX_DIV_N 120 | ||
| 42 | |||
| 43 | #define MAX_PHASE 15 | ||
| 44 | #define RX_TUNING_CNT 3 | ||
| 45 | |||
| 46 | #define QFN24 0 | ||
| 47 | #define LQFP48 1 | ||
| 48 | #define CHECK_PKG(ucr, pkg) ((ucr)->package == (pkg)) | ||
| 49 | |||
| 50 | /* data structures */ | ||
| 51 | struct rtsx_ucr { | ||
| 52 | u16 vendor_id; | ||
| 53 | u16 product_id; | ||
| 54 | |||
| 55 | int package; | ||
| 56 | u8 ic_version; | ||
| 57 | bool is_rts5179; | ||
| 58 | |||
| 59 | unsigned int cur_clk; | ||
| 60 | |||
| 61 | u8 *cmd_buf; | ||
| 62 | unsigned int cmd_idx; | ||
| 63 | u8 *rsp_buf; | ||
| 64 | |||
| 65 | struct usb_device *pusb_dev; | ||
| 66 | struct usb_interface *pusb_intf; | ||
| 67 | struct usb_sg_request current_sg; | ||
| 68 | unsigned char *iobuf; | ||
| 69 | dma_addr_t iobuf_dma; | ||
| 70 | |||
| 71 | struct timer_list sg_timer; | ||
| 72 | struct mutex dev_mutex; | ||
| 73 | }; | ||
| 74 | |||
| 75 | /* buffer size */ | ||
| 76 | #define IOBUF_SIZE 1024 | ||
| 77 | |||
| 78 | /* prototypes of exported functions */ | ||
| 79 | extern int rtsx_usb_get_card_status(struct rtsx_ucr *ucr, u16 *status); | ||
| 80 | |||
| 81 | extern int rtsx_usb_read_register(struct rtsx_ucr *ucr, u16 addr, u8 *data); | ||
| 82 | extern int rtsx_usb_write_register(struct rtsx_ucr *ucr, u16 addr, u8 mask, | ||
| 83 | u8 data); | ||
| 84 | |||
| 85 | extern int rtsx_usb_ep0_write_register(struct rtsx_ucr *ucr, u16 addr, u8 mask, | ||
| 86 | u8 data); | ||
| 87 | extern int rtsx_usb_ep0_read_register(struct rtsx_ucr *ucr, u16 addr, | ||
| 88 | u8 *data); | ||
| 89 | |||
| 90 | extern void rtsx_usb_add_cmd(struct rtsx_ucr *ucr, u8 cmd_type, | ||
| 91 | u16 reg_addr, u8 mask, u8 data); | ||
| 92 | extern int rtsx_usb_send_cmd(struct rtsx_ucr *ucr, u8 flag, int timeout); | ||
| 93 | extern int rtsx_usb_get_rsp(struct rtsx_ucr *ucr, int rsp_len, int timeout); | ||
| 94 | extern int rtsx_usb_transfer_data(struct rtsx_ucr *ucr, unsigned int pipe, | ||
| 95 | void *buf, unsigned int len, int use_sg, | ||
| 96 | unsigned int *act_len, int timeout); | ||
| 97 | |||
| 98 | extern int rtsx_usb_read_ppbuf(struct rtsx_ucr *ucr, u8 *buf, int buf_len); | ||
| 99 | extern int rtsx_usb_write_ppbuf(struct rtsx_ucr *ucr, u8 *buf, int buf_len); | ||
| 100 | extern int rtsx_usb_switch_clock(struct rtsx_ucr *ucr, unsigned int card_clock, | ||
| 101 | u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk); | ||
| 102 | extern int rtsx_usb_card_exclusive_check(struct rtsx_ucr *ucr, int card); | ||
| 103 | |||
| 104 | /* card status */ | ||
| 105 | #define SD_CD 0x01 | ||
| 106 | #define MS_CD 0x02 | ||
| 107 | #define XD_CD 0x04 | ||
| 108 | #define CD_MASK (SD_CD | MS_CD | XD_CD) | ||
| 109 | #define SD_WP 0x08 | ||
| 110 | |||
| 111 | /* reader command field offset & parameters */ | ||
| 112 | #define READ_REG_CMD 0 | ||
| 113 | #define WRITE_REG_CMD 1 | ||
| 114 | #define CHECK_REG_CMD 2 | ||
| 115 | |||
| 116 | #define PACKET_TYPE 4 | ||
| 117 | #define CNT_H 5 | ||
| 118 | #define CNT_L 6 | ||
| 119 | #define STAGE_FLAG 7 | ||
| 120 | #define CMD_OFFSET 8 | ||
| 121 | #define SEQ_WRITE_DATA_OFFSET 12 | ||
| 122 | |||
| 123 | #define BATCH_CMD 0 | ||
| 124 | #define SEQ_READ 1 | ||
| 125 | #define SEQ_WRITE 2 | ||
| 126 | |||
| 127 | #define STAGE_R 0x01 | ||
| 128 | #define STAGE_DI 0x02 | ||
| 129 | #define STAGE_DO 0x04 | ||
| 130 | #define STAGE_MS_STATUS 0x08 | ||
| 131 | #define STAGE_XD_STATUS 0x10 | ||
| 132 | #define MODE_C 0x00 | ||
| 133 | #define MODE_CR (STAGE_R) | ||
| 134 | #define MODE_CDIR (STAGE_R | STAGE_DI) | ||
| 135 | #define MODE_CDOR (STAGE_R | STAGE_DO) | ||
| 136 | |||
| 137 | #define EP0_OP_SHIFT 14 | ||
| 138 | #define EP0_READ_REG_CMD 2 | ||
| 139 | #define EP0_WRITE_REG_CMD 3 | ||
| 140 | |||
| 141 | #define rtsx_usb_cmd_hdr_tag(ucr) \ | ||
| 142 | do { \ | ||
| 143 | ucr->cmd_buf[0] = 'R'; \ | ||
| 144 | ucr->cmd_buf[1] = 'T'; \ | ||
| 145 | ucr->cmd_buf[2] = 'C'; \ | ||
| 146 | ucr->cmd_buf[3] = 'R'; \ | ||
| 147 | } while (0) | ||
| 148 | |||
| 149 | static inline void rtsx_usb_init_cmd(struct rtsx_ucr *ucr) | ||
| 150 | { | ||
| 151 | rtsx_usb_cmd_hdr_tag(ucr); | ||
| 152 | ucr->cmd_idx = 0; | ||
| 153 | ucr->cmd_buf[PACKET_TYPE] = BATCH_CMD; | ||
| 154 | } | ||
| 155 | |||
| 156 | /* internal register address */ | ||
| 157 | #define FPDCTL 0xFC00 | ||
| 158 | #define SSC_DIV_N_0 0xFC07 | ||
| 159 | #define SSC_CTL1 0xFC09 | ||
| 160 | #define SSC_CTL2 0xFC0A | ||
| 161 | #define CFG_MODE 0xFC0E | ||
| 162 | #define CFG_MODE_1 0xFC0F | ||
| 163 | #define RCCTL 0xFC14 | ||
| 164 | #define SOF_WDOG 0xFC28 | ||
| 165 | #define SYS_DUMMY0 0xFC30 | ||
| 166 | |||
| 167 | #define MS_BLKEND 0xFD30 | ||
| 168 | #define MS_READ_START 0xFD31 | ||
| 169 | #define MS_READ_COUNT 0xFD32 | ||
| 170 | #define MS_WRITE_START 0xFD33 | ||
| 171 | #define MS_WRITE_COUNT 0xFD34 | ||
| 172 | #define MS_COMMAND 0xFD35 | ||
| 173 | #define MS_OLD_BLOCK_0 0xFD36 | ||
| 174 | #define MS_OLD_BLOCK_1 0xFD37 | ||
| 175 | #define MS_NEW_BLOCK_0 0xFD38 | ||
| 176 | #define MS_NEW_BLOCK_1 0xFD39 | ||
| 177 | #define MS_LOG_BLOCK_0 0xFD3A | ||
| 178 | #define MS_LOG_BLOCK_1 0xFD3B | ||
| 179 | #define MS_BUS_WIDTH 0xFD3C | ||
| 180 | #define MS_PAGE_START 0xFD3D | ||
| 181 | #define MS_PAGE_LENGTH 0xFD3E | ||
| 182 | #define MS_CFG 0xFD40 | ||
| 183 | #define MS_TPC 0xFD41 | ||
| 184 | #define MS_TRANS_CFG 0xFD42 | ||
| 185 | #define MS_TRANSFER 0xFD43 | ||
| 186 | #define MS_INT_REG 0xFD44 | ||
| 187 | #define MS_BYTE_CNT 0xFD45 | ||
| 188 | #define MS_SECTOR_CNT_L 0xFD46 | ||
| 189 | #define MS_SECTOR_CNT_H 0xFD47 | ||
| 190 | #define MS_DBUS_H 0xFD48 | ||
| 191 | |||
| 192 | #define CARD_DMA1_CTL 0xFD5C | ||
| 193 | #define CARD_PULL_CTL1 0xFD60 | ||
| 194 | #define CARD_PULL_CTL2 0xFD61 | ||
| 195 | #define CARD_PULL_CTL3 0xFD62 | ||
| 196 | #define CARD_PULL_CTL4 0xFD63 | ||
| 197 | #define CARD_PULL_CTL5 0xFD64 | ||
| 198 | #define CARD_PULL_CTL6 0xFD65 | ||
| 199 | #define CARD_EXIST 0xFD6F | ||
| 200 | #define CARD_INT_PEND 0xFD71 | ||
| 201 | |||
| 202 | #define LDO_POWER_CFG 0xFD7B | ||
| 203 | |||
| 204 | #define SD_CFG1 0xFDA0 | ||
| 205 | #define SD_CFG2 0xFDA1 | ||
| 206 | #define SD_CFG3 0xFD | ||
