realtek_cr.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. /* Driver for Realtek RTS51xx USB card reader
  2. *
  3. * Copyright(c) 2009 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 as published by the
  7. * Free Software Foundation; either version 2, or (at your option) any
  8. * later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * Author:
  19. * wwang (wei_wang@realsil.com.cn)
  20. * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
  21. */
  22. #include <linux/module.h>
  23. #include <linux/blkdev.h>
  24. #include <linux/kthread.h>
  25. #include <linux/sched.h>
  26. #include <linux/workqueue.h>
  27. #include <linux/kernel.h>
  28. #include <linux/version.h>
  29. #include <scsi/scsi.h>
  30. #include <scsi/scsi_cmnd.h>
  31. #include <scsi/scsi_device.h>
  32. #include <linux/cdrom.h>
  33. #include <linux/usb.h>
  34. #include <linux/slab.h>
  35. #include <linux/usb_usual.h>
  36. #include "usb.h"
  37. #include "transport.h"
  38. #include "protocol.h"
  39. #include "debug.h"
  40. MODULE_DESCRIPTION("Driver for Realtek USB Card Reader");
  41. MODULE_AUTHOR("wwang <wei_wang@realsil.com.cn>");
  42. MODULE_LICENSE("GPL");
  43. MODULE_VERSION("1.03");
  44. static int auto_delink_en = 1;
  45. module_param(auto_delink_en, int, S_IRUGO | S_IWUSR);
  46. MODULE_PARM_DESC(auto_delink_en, "enable auto delink");
  47. struct rts51x_status {
  48. u16 vid;
  49. u16 pid;
  50. u8 cur_lun;
  51. u8 card_type;
  52. u8 total_lun;
  53. u16 fw_ver;
  54. u8 phy_exist;
  55. u8 multi_flag;
  56. u8 multi_card;
  57. u8 log_exist;
  58. union {
  59. u8 detailed_type1;
  60. u8 detailed_type2;
  61. } detailed_type;
  62. u8 function[2];
  63. };
  64. struct rts51x_chip {
  65. u16 vendor_id;
  66. u16 product_id;
  67. char max_lun;
  68. struct rts51x_status *status;
  69. int status_len;
  70. u32 flag;
  71. };
  72. /* flag definition */
  73. #define FLIDX_AUTO_DELINK 0x01
  74. #define SCSI_LUN(srb) ((srb)->device->lun)
  75. /* Bit Operation */
  76. #define SET_BIT(data, idx) ((data) |= 1 << (idx))
  77. #define CLR_BIT(data, idx) ((data) &= ~(1 << (idx)))
  78. #define CHK_BIT(data, idx) ((data) & (1 << (idx)))
  79. #define SET_AUTO_DELINK(chip) ((chip)->flag |= FLIDX_AUTO_DELINK)
  80. #define CLR_AUTO_DELINK(chip) ((chip)->flag &= ~FLIDX_AUTO_DELINK)
  81. #define CHK_AUTO_DELINK(chip) ((chip)->flag & FLIDX_AUTO_DELINK)
  82. #define RTS51X_GET_VID(chip) ((chip)->vendor_id)
  83. #define RTS51X_GET_PID(chip) ((chip)->product_id)
  84. #define FW_VERSION(chip) ((chip)->status[0].fw_ver)
  85. #define STATUS_LEN(chip) ((chip)->status_len)
  86. /* Check card reader function */
  87. #define SUPPORT_DETAILED_TYPE1(chip) \
  88. CHK_BIT((chip)->status[0].function[0], 1)
  89. #define SUPPORT_OT(chip) \
  90. CHK_BIT((chip)->status[0].function[0], 2)
  91. #define SUPPORT_OC(chip) \
  92. CHK_BIT((chip)->status[0].function[0], 3)
  93. #define SUPPORT_AUTO_DELINK(chip) \
  94. CHK_BIT((chip)->status[0].function[0], 4)
  95. #define SUPPORT_SDIO(chip) \
  96. CHK_BIT((chip)->status[0].function[1], 0)
  97. #define SUPPORT_DETAILED_TYPE2(chip) \
  98. CHK_BIT((chip)->status[0].function[1], 1)
  99. #define CHECK_PID(chip, pid) (RTS51X_GET_PID(chip) == (pid))
  100. #define CHECK_FW_VER(chip, fw_ver) (FW_VERSION(chip) == (fw_ver))
  101. #define CHECK_ID(chip, pid, fw_ver) \
  102. (CHECK_PID((chip), (pid)) && CHECK_FW_VER((chip), (fw_ver)))
  103. #define wait_timeout_x(task_state, msecs) \
  104. do { \
  105. set_current_state((task_state)); \
  106. schedule_timeout((msecs) * HZ / 1000); \
  107. } while (0)
  108. #define wait_timeout(msecs) \
  109. wait_timeout_x(TASK_INTERRUPTIBLE, (msecs))
  110. static int init_realtek_cr(struct us_data *us);
  111. /*
  112. * The table of devices
  113. */
  114. #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
  115. vendorName, productName, useProtocol, useTransport, \
  116. initFunction, flags) \
  117. {\
  118. USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
  119. .driver_info = (flags)|(USB_US_TYPE_STOR<<24)\
  120. }
  121. static const struct usb_device_id realtek_cr_ids[] = {
  122. # include "unusual_realtek.h"
  123. {} /* Terminating entry */
  124. };
  125. MODULE_DEVICE_TABLE(usb, realtek_cr_ids);
  126. #undef UNUSUAL_DEV
  127. /*
  128. * The flags table
  129. */
  130. #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
  131. vendor_name, product_name, use_protocol, use_transport, \
  132. init_function, Flags) \
  133. { \
  134. .vendorName = vendor_name, \
  135. .productName = product_name, \
  136. .useProtocol = use_protocol, \
  137. .useTransport = use_transport, \
  138. .initFunction = init_function, \
  139. }
  140. static struct us_unusual_dev realtek_cr_unusual_dev_list[] = {
  141. # include "unusual_realtek.h"
  142. {} /* Terminating entry */
  143. };
  144. #undef UNUSUAL_DEV
  145. static int rts51x_bulk_transport(struct us_data *us, u8 lun,
  146. u8 *cmd, int cmd_len, u8 *buf, int buf_len,
  147. enum dma_data_direction dir, int *act_len)
  148. {
  149. struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *)us->iobuf;
  150. struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *)us->iobuf;
  151. int result;
  152. unsigned int residue;
  153. unsigned int cswlen;
  154. unsigned int cbwlen = US_BULK_CB_WRAP_LEN;
  155. /* set up the command wrapper */
  156. bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
  157. bcb->DataTransferLength = cpu_to_le32(buf_len);
  158. bcb->Flags = (dir == DMA_FROM_DEVICE) ? 1 << 7 : 0;
  159. bcb->Tag = ++us->tag;
  160. bcb->Lun = lun;
  161. bcb->Length = cmd_len;
  162. /* copy the command payload */
  163. memset(bcb->CDB, 0, sizeof(bcb->CDB));
  164. memcpy(bcb->CDB, cmd, bcb->Length);
  165. /* send it to out endpoint */
  166. result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
  167. bcb, cbwlen, NULL);
  168. if (result != USB_STOR_XFER_GOOD)
  169. return USB_STOR_TRANSPORT_ERROR;
  170. /* DATA STAGE */
  171. /* send/receive data payload, if there is any */
  172. if (buf && buf_len) {
  173. unsigned int pipe = (dir == DMA_FROM_DEVICE) ?
  174. us->recv_bulk_pipe : us->send_bulk_pipe;
  175. result = usb_stor_bulk_transfer_buf(us, pipe,
  176. buf, buf_len, NULL);
  177. if (result == USB_STOR_XFER_ERROR)
  178. return USB_STOR_TRANSPORT_ERROR;
  179. }
  180. /* get CSW for device status */
  181. result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
  182. bcs, US_BULK_CS_WRAP_LEN, &cswlen);
  183. if (result != USB_STOR_XFER_GOOD)
  184. return USB_STOR_TRANSPORT_ERROR;
  185. /* check bulk status */
  186. if (bcs->Signature != cpu_to_le32(US_BULK_CS_SIGN)) {
  187. US_DEBUGP("Signature mismatch: got %08X, expecting %08X\n",
  188. le32_to_cpu(bcs->Signature), US_BULK_CS_SIGN);
  189. return USB_STOR_TRANSPORT_ERROR;
  190. }
  191. residue = bcs->Residue;
  192. if (bcs->Tag != us->tag)
  193. return USB_STOR_TRANSPORT_ERROR;
  194. /* try to compute the actual residue, based on how much data
  195. * was really transferred and what the device tells us */
  196. if (residue)
  197. residue = residue < buf_len ? residue : buf_len;
  198. if (act_len)
  199. *act_len = buf_len - residue;
  200. /* based on the status code, we report good or bad */
  201. switch (bcs->Status) {
  202. case US_BULK_STAT_OK:
  203. /* command good -- note that data could be short */
  204. return USB_STOR_TRANSPORT_GOOD;
  205. case US_BULK_STAT_FAIL:
  206. /* command failed */
  207. return USB_STOR_TRANSPORT_FAILED;
  208. case US_BULK_STAT_PHASE:
  209. /* phase error -- note that a transport reset will be
  210. * invoked by the invoke_transport() function
  211. */
  212. return USB_STOR_TRANSPORT_ERROR;
  213. }
  214. /* we should never get here, but if we do, we're in trouble */
  215. return USB_STOR_TRANSPORT_ERROR;
  216. }
  217. /* Determine what the maximum LUN supported is */
  218. static int rts51x_get_max_lun(struct us_data *us)
  219. {
  220. int result;
  221. /* issue the command */
  222. us->iobuf[0] = 0;
  223. result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
  224. US_BULK_GET_MAX_LUN,
  225. USB_DIR_IN | USB_TYPE_CLASS |
  226. USB_RECIP_INTERFACE,
  227. 0, us->ifnum, us->iobuf, 1, 10 * HZ);
  228. US_DEBUGP("GetMaxLUN command result is %d, data is %d\n",
  229. result, us->iobuf[0]);
  230. /* if we have a successful request, return the result */
  231. if (result > 0)
  232. return us->iobuf[0];
  233. return 0;
  234. }
  235. static int rts51x_read_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
  236. {
  237. int retval;
  238. u8 cmnd[12] = { 0 };
  239. US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len);
  240. cmnd[0] = 0xF0;
  241. cmnd[1] = 0x0D;
  242. cmnd[2] = (u8) (addr >> 8);
  243. cmnd[3] = (u8) addr;
  244. cmnd[4] = (u8) (len >> 8);
  245. cmnd[5] = (u8) len;
  246. retval = rts51x_bulk_transport(us, 0, cmnd, 12,
  247. data, len, DMA_FROM_DEVICE, NULL);
  248. if (retval != USB_STOR_TRANSPORT_GOOD)
  249. return -EIO;
  250. return 0;
  251. }
  252. static int rts51x_write_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
  253. {
  254. int retval;
  255. u8 cmnd[12] = { 0 };
  256. US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len);
  257. cmnd[0] = 0xF0;
  258. cmnd[1] = 0x0E;
  259. cmnd[2] = (u8) (addr >> 8);
  260. cmnd[3] = (u8) addr;
  261. cmnd[4] = (u8) (len >> 8);
  262. cmnd[5] = (u8) len;
  263. retval = rts51x_bulk_transport(us, 0, cmnd, 12,
  264. data, len, DMA_TO_DEVICE, NULL);
  265. if (retval != USB_STOR_TRANSPORT_GOOD)
  266. return -EIO;
  267. return 0;
  268. }
  269. static int rts51x_read_status(struct us_data *us,
  270. u8 lun, u8 *status, int len, int *actlen)
  271. {
  272. int retval;
  273. u8 cmnd[12] = { 0 };
  274. US_DEBUGP("%s, lun = %d\n", __func__, lun);
  275. cmnd[0] = 0xF0;
  276. cmnd[1] = 0x09;
  277. retval = rts51x_bulk_transport(us, lun, cmnd, 12,
  278. status, len, DMA_FROM_DEVICE, actlen);
  279. if (retval != USB_STOR_TRANSPORT_GOOD)
  280. return -EIO;
  281. return 0;
  282. }
  283. static int rts51x_check_status(struct us_data *us, u8 lun)
  284. {
  285. struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
  286. int retval;
  287. u8 buf[16];
  288. retval = rts51x_read_status(us, lun, buf, 16, &(chip->status_len));
  289. if (retval < 0)
  290. return -EIO;
  291. US_DEBUGP("chip->status_len = %d\n", chip->status_len);
  292. chip->status[lun].vid = ((u16) buf[0] << 8) | buf[1];
  293. chip->status[lun].pid = ((u16) buf[2] << 8) | buf[3];
  294. chip->status[lun].cur_lun = buf[4];
  295. chip->status[lun].card_type = buf[5];
  296. chip->status[lun].total_lun = buf[6];
  297. chip->status[lun].fw_ver = ((u16) buf[7] << 8) | buf[8];
  298. chip->status[lun].phy_exist = buf[9];
  299. chip->status[lun].multi_flag = buf[10];
  300. chip->status[lun].multi_card = buf[11];
  301. chip->status[lun].log_exist = buf[12];
  302. if (chip->status_len == 16) {
  303. chip->status[lun].detailed_type.detailed_type1 = buf[13];
  304. chip->status[lun].function[0] = buf[14];
  305. chip->status[lun].function[1] = buf[15];
  306. }
  307. return 0;
  308. }
  309. static int enable_oscillator(struct us_data *us)
  310. {
  311. int retval;
  312. u8 value;
  313. retval = rts51x_read_mem(us, 0xFE77, &value, 1);
  314. if (retval < 0)
  315. return -EIO;
  316. value |= 0x04;
  317. retval = rts51x_write_mem(us, 0xFE77, &value, 1);
  318. if (retval < 0)
  319. return -EIO;
  320. retval = rts51x_read_mem(us, 0xFE77, &value, 1);
  321. if (retval < 0)
  322. return -EIO;
  323. if (!(value & 0x04))
  324. return -EIO;
  325. return 0;
  326. }
  327. static int do_config_autodelink(struct us_data *us, int enable, int force)
  328. {
  329. int retval;
  330. u8 value;
  331. retval = rts51x_read_mem(us, 0xFE47, &value, 1);
  332. if (retval < 0)
  333. return -EIO;
  334. if (enable) {
  335. if (force)
  336. value |= 0x03;
  337. else
  338. value |= 0x01;
  339. } else {
  340. value &= ~0x03;
  341. }
  342. US_DEBUGP("In %s,set 0xfe47 to 0x%x\n", __func__, value);
  343. retval = rts51x_write_mem(us, 0xFE47, &value, 1);
  344. if (retval < 0)
  345. return -EIO;
  346. return 0;
  347. }
  348. static int config_autodelink_after_power_on(struct us_data *us)
  349. {
  350. struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
  351. int retval;
  352. u8 value;
  353. if (!CHK_AUTO_DELINK(chip))
  354. return 0;
  355. retval = rts51x_read_mem(us, 0xFE47, &value, 1);
  356. if (retval < 0)
  357. return -EIO;
  358. if (auto_delink_en) {
  359. CLR_BIT(value, 0);
  360. CLR_BIT(value, 1);
  361. SET_BIT(value, 2);
  362. if (CHECK_ID(chip, 0x0138, 0x3882))
  363. CLR_BIT(value, 2);
  364. SET_BIT(value, 7);
  365. retval = rts51x_write_mem(us, 0xFE47, &value, 1);
  366. if (retval < 0)
  367. return -EIO;
  368. retval = enable_oscillator(us);
  369. if (retval == 0)
  370. (void)do_config_autodelink(us, 1, 0);
  371. } else {
  372. /* Autodelink controlled by firmware */
  373. SET_BIT(value, 2);
  374. if (CHECK_ID(chip, 0x0138, 0x3882))
  375. CLR_BIT(value, 2);
  376. if (CHECK_ID(chip, 0x0159, 0x5889) ||
  377. CHECK_ID(chip, 0x0138, 0x3880)) {
  378. CLR_BIT(value, 0);
  379. CLR_BIT(value, 7);
  380. }
  381. retval = rts51x_write_mem(us, 0xFE47, &value, 1);
  382. if (retval < 0)
  383. return -EIO;
  384. if (CHECK_ID(chip, 0x0159, 0x5888)) {
  385. value = 0xFF;
  386. retval = rts51x_write_mem(us, 0xFE79, &value, 1);
  387. if (retval < 0)
  388. return -EIO;
  389. value = 0x01;
  390. retval = rts51x_write_mem(us, 0x48, &value, 1);
  391. if (retval < 0)
  392. return -EIO;
  393. }
  394. }
  395. return 0;
  396. }
  397. static int config_autodelink_before_power_down(struct us_data *us)
  398. {
  399. struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
  400. int retval;
  401. u8 value;
  402. if (!CHK_AUTO_DELINK(chip))
  403. return 0;
  404. if (auto_delink_en) {
  405. retval = rts51x_read_mem(us, 0xFE77, &value, 1);
  406. if (retval < 0)
  407. return -EIO;
  408. SET_BIT(value, 2);
  409. retval = rts51x_write_mem(us, 0xFE77, &value, 1);
  410. if (retval < 0)
  411. return -EIO;
  412. if (CHECK_ID(chip, 0x0159, 0x5888)) {
  413. value = 0x01;
  414. retval = rts51x_write_mem(us, 0x48, &value, 1);
  415. if (retval < 0)
  416. return -EIO;
  417. }
  418. retval = rts51x_read_mem(us, 0xFE47, &value, 1);
  419. if (retval < 0)
  420. return -EIO;
  421. SET_BIT(value, 0);
  422. if (CHECK_ID(chip, 0x0138, 0x3882))
  423. SET_BIT(value, 2);
  424. retval = rts51x_write_mem(us, 0xFE77, &value, 1);
  425. if (retval < 0)
  426. return -EIO;
  427. } else {
  428. if (CHECK_ID(chip, 0x0159, 0x5889) ||
  429. CHECK_ID(chip, 0x0138, 0x3880) ||
  430. CHECK_ID(chip, 0x0138, 0x3882)) {
  431. retval = rts51x_read_mem(us, 0xFE47, &value, 1);
  432. if (retval < 0)
  433. return -EIO;
  434. if (CHECK_ID(chip, 0x0159, 0x5889) ||
  435. CHECK_ID(chip, 0x0138, 0x3880)) {
  436. SET_BIT(value, 0);
  437. SET_BIT(value, 7);
  438. }
  439. if (CHECK_ID(chip, 0x0138, 0x3882))
  440. SET_BIT(value, 2);
  441. retval = rts51x_write_mem(us, 0xFE47, &value, 1);
  442. if (retval < 0)
  443. return -EIO;
  444. }
  445. if (CHECK_ID(chip, 0x0159, 0x5888)) {
  446. value = 0x01;
  447. retval = rts51x_write_mem(us, 0x48, &value, 1);
  448. if (retval < 0)
  449. return -EIO;
  450. }
  451. }
  452. return 0;
  453. }
  454. static void realtek_cr_destructor(void *extra)
  455. {
  456. struct rts51x_chip *chip = (struct rts51x_chip *)extra;
  457. if (!chip)
  458. return;
  459. kfree(chip->status);
  460. }
  461. #ifdef CONFIG_PM
  462. static void realtek_pm_hook(struct us_data *us, int pm_state)
  463. {
  464. if (pm_state == US_SUSPEND)
  465. (void)config_autodelink_before_power_down(us);
  466. }
  467. #endif
  468. static int init_realtek_cr(struct us_data *us)
  469. {
  470. struct rts51x_chip *chip;
  471. int size, i, retval;
  472. chip = kzalloc(sizeof(struct rts51x_chip), GFP_KERNEL);
  473. if (!chip)
  474. return -ENOMEM;
  475. us->extra = chip;
  476. us->extra_destructor = realtek_cr_destructor;
  477. #ifdef CONFIG_PM
  478. us->suspend_resume_hook = realtek_pm_hook;
  479. #endif
  480. us->max_lun = chip->max_lun = rts51x_get_max_lun(us);
  481. US_DEBUGP("chip->max_lun = %d\n", chip->max_lun);
  482. size = (chip->max_lun + 1) * sizeof(struct rts51x_status);
  483. chip->status = kzalloc(size, GFP_KERNEL);
  484. if (!chip->status)
  485. goto INIT_FAIL;
  486. for (i = 0; i <= (int)(chip->max_lun); i++) {
  487. retval = rts51x_check_status(us, (u8) i);
  488. if (retval < 0)
  489. goto INIT_FAIL;
  490. }
  491. if (CHECK_FW_VER(chip, 0x5888) || CHECK_FW_VER(chip, 0x5889) ||
  492. CHECK_FW_VER(chip, 0x5901))
  493. SET_AUTO_DELINK(chip);
  494. if (STATUS_LEN(chip) == 16) {
  495. if (SUPPORT_AUTO_DELINK(chip))
  496. SET_AUTO_DELINK(chip);
  497. }
  498. US_DEBUGP("chip->flag = 0x%x\n", chip->flag);
  499. (void)config_autodelink_after_power_on(us);
  500. return 0;
  501. INIT_FAIL:
  502. if (us->extra) {
  503. kfree(chip->status);
  504. kfree(us->extra);
  505. us->extra = NULL;
  506. }
  507. return -EIO;
  508. }
  509. static int realtek_cr_probe(struct usb_interface *intf,
  510. const struct usb_device_id *id)
  511. {
  512. struct us_data *us;
  513. int result;
  514. US_DEBUGP("Probe Realtek Card Reader!\n");
  515. result = usb_stor_probe1(&us, intf, id,
  516. (id - realtek_cr_ids) +
  517. realtek_cr_unusual_dev_list);
  518. if (result)
  519. return result;
  520. result = usb_stor_probe2(us);
  521. return result;
  522. }
  523. static struct usb_driver realtek_cr_driver = {
  524. .name = "ums-realtek",
  525. .probe = realtek_cr_probe,
  526. .disconnect = usb_stor_disconnect,
  527. .suspend = usb_stor_suspend,
  528. .resume = usb_stor_resume,
  529. .reset_resume = usb_stor_reset_resume,
  530. .pre_reset = usb_stor_pre_reset,
  531. .post_reset = usb_stor_post_reset,
  532. .id_table = realtek_cr_ids,
  533. .soft_unbind = 1,
  534. };
  535. static int __init realtek_cr_init(void)
  536. {
  537. return usb_register(&realtek_cr_driver);
  538. }
  539. static void __exit realtek_cr_exit(void)
  540. {
  541. usb_deregister(&realtek_cr_driver);
  542. }
  543. module_init(realtek_cr_init);
  544. module_exit(realtek_cr_exit);