Add modules for realtek USB card reader
Subsystems (3)
cover Add modules for realtek USB card reader
From: Roger Tseng <[email protected]>
This patchset adds modules to support Realtek USB vendor specific class flash card reader: one base module in MFD subsystem and two host modules in both mmc and memstick subsystems. The architecture is similar to rtsx_pci.
This work is done primarily to replace the staging driver: staging/rts5139, which doesn't utilize mmc nor memstick subsystems. Once the patchset or its revision is applied, we may need Greg's help to remove the staging one.
Roger Tseng (3):
mfd: Add realtek USB card reader driver
mmc: Add realtek USB sdmmc host driver
memstick: Add realtek USB memstick host driver
drivers/memstick/host/Kconfig | 10 + drivers/memstick/host/Makefile | 1 + drivers/memstick/host/rtsx_usb_ms.c | 856 ++++++++++++++++++++ drivers/mfd/Kconfig | 10 + drivers/mfd/Makefile | 1 + drivers/mfd/rtsx_usb.c | 794 ++++++++++++++++++ drivers/mmc/host/Kconfig | 7 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/rtsx_usb_sdmmc.c | 1511 +++++++++++++++++++++++++++++++++++ include/linux/mfd/rtsx_usb.h | 609 ++++++++++++++ 10 files changed, 3800 insertions(+) create mode 100644 drivers/memstick/host/rtsx_usb_ms.c create mode 100644 drivers/mfd/rtsx_usb.c create mode 100644 drivers/mmc/host/rtsx_usb_sdmmc.c create mode 100644 include/linux/mfd/rtsx_usb.h
Signature · 1 line
1.8.2
PATCH 1/3 mfd: Add realtek USB card reader driver
From: Roger Tseng <[email protected]>
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.
--- drivers/mfd/Kconfig | 10 + drivers/mfd/Makefile | 1 + drivers/mfd/rtsx_usb.c | 794 +++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/rtsx_usb.h | 609 +++++++++++++++++++++++++++++++++ 4 files changed, 1414 insertions(+) create mode 100644 drivers/mfd/rtsx_usb.c create mode 100644 include/linux/mfd/rtsx_usb.h
drivers/mfd/Kconfig +10 -0
@@ -507,6 +507,16 @@ config MFD_RTSX_PCI types of memory cards, such as Memory Stick, Memory Stick Pro, Secure Digital and MultiMediaCard. +config MFD_RTSX_USB + tristate "Realtek USB card reader" + depends on USB + select MFD_CORE + help + Select this option to get support for Realtek USB 2.0 card readers + including RTS5129, RTS5139, RTS5179 and RTS5170. + Realtek card reader supports access to many types of memory cards, + such as Memory Stick Pro, Secure Digital and MultiMediaCard. + config MFD_RC5T583 bool "Ricoh RC5T583 Power Management system device" depends on I2C=y
drivers/mfd/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_MFD_CROS_EC_SPI) += cros_ec_spi.o rtsx_pci-objs := rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o obj-$(CONFIG_MFD_RTSX_PCI) += rtsx_pci.o +obj-$(CONFIG_MFD_RTSX_USB) += rtsx_usb.o obj-$(CONFIG_HTC_EGPIO) += htc-egpio.o obj-$(CONFIG_HTC_PASIC3) += htc-pasic3.o
drivers/mfd/rtsx_usb.c new file +794 -0
794 lines not on this page · raw message
include/linux/mfd/rtsx_usb.h new file +609 -0
609 lines not on this page · raw message
Signature · 1 line
1.8.2
Re: [PATCH 1/3] mfd: Add realtek USB card reader driver
drivers/mfd/rtsx_usb.c line 103
Quoted 10 lines · On Mon, Dec 23, 2013 at 05:52:05PM +0800, [email protected] wrote:
drivers/mfd/rtsx_usb.c new file +10
-0+static int rtsx_usb_seq_write_register (struct rtsx_ucr *ucr, +u16 addr,u16 len,u8 *data) +{ +u16 cmd_len = len +12 ; + +if (data ==NULL ) +return -EINVAL ; + + cmd_len = (cmd_len <=CMD_BUF_LEN ) ? cmd_len :CMD_BUF_LEN ; +
I do not like how you have three names for the same buffer length.
include/linux/mfd/rtsx_usb.h line 79
Quoted 3 lines
include/linux/mfd/rtsx_usb.h new file +3
-0+#define IOBUF_SIZE 1024 +#define CMD_BUF_LEN 1024 +#define RSP_BUF_LEN 1024
The buffer is allocated as IOBUF_SIZE and then CMD_BUF_LEN is used as a limiter here and one other place. RSP_BUF_LEN is not used at all.
Quoted 6 lines
drivers/mfd/rtsx_usb.c new file +6
-0+if (cmd_len %4 ) + cmd_len += (4 - cmd_len %4 ); + + + ucr->cmd_buf[0 ] ='R' ; + ucr->cmd_buf[1 ] ='T' ;
drivers/mfd/rtsx_usb.c line 119
Quoted 10 lines
drivers/mfd/rtsx_usb.c new file +10
-0+ ucr->cmd_buf[2 ] ='C' ; + ucr->cmd_buf[3 ] ='R' ; + ucr->cmd_buf[PACKET_TYPE ] =SEQ_WRITE ; + ucr->cmd_buf[5 ] = (u8)(len >>8 ); + ucr->cmd_buf[6 ] = (u8 )len; + ucr->cmd_buf[STAGE_FLAG ] =0 ; + ucr->cmd_buf[8 ] = (u8)(addr >>8 ); + ucr->cmd_buf[9 ] = (u8 )addr; + +memcpy (ucr->cmd_buf +12 , data, len);
Buffer overflow here because ->cmd_buf is only IOBUF_SIZE long. Probably the earlier two uses of "len" are buffer overflows as well.
drivers/mfd/rtsx_usb.c line 192
Quoted 7 lines
drivers/mfd/rtsx_usb.c new file +7
-0+int rtsx_usb_ep0_write_register (struct rtsx_ucr *ucr,u16 addr, +u8 mask,u8 data) +{ +u16 value =0 , index =0 ; + + value |= (u16)(3 &0x03 ) <<14 ; + value |= (u16)(addr &0x3FFF );
Don't do pointless things:
value |= 0x03 << 14; value |= addr & 0x3FFF;
Review
Quoted 1 line
(quoted diff) +1
-0+ value = ((value << 8) & 0xFF00) | ((value >> 8) & 0x00FF);
This is an endian conversion? It is buggy. Use the kernel endian conversion functions cpu_to_le16().
Quoted 10 lines
drivers/mfd/rtsx_usb.c new file +10
-0+ index |= (u16 )mask; + index |= (u16 )data <<8 ; + +return usb_control_msg (ucr->pusb_dev, +usb_sndctrlpipe (ucr->pusb_dev,0 ),0 ,0x40 , + value, index,NULL ,0 ,100 ); +} +EXPORT_SYMBOL_GPL (rtsx_usb_ep0_write_register); + +int rtsx_usb_ep0_read_register (struct rtsx_ucr *ucr,u16 addr,u8 *data)
drivers/mfd/rtsx_usb.c line 213
Quoted 10 lines
drivers/mfd/rtsx_usb.c new file +10
-0+{ +u16 value =0 ; + +if (data ==NULL ) +return -EINVAL ; + *data =0 ; + + value |= (u16)(2 &0x03 ) <<14 ; + value |= (u16)(addr &0x3FFF ); + value = ((value <<8 ) &0xFF00 ) | ((value >>8 ) &0x00FF );
same.
The rest of my comments below are minor white space nits.
Quoted 34 lines
drivers/mfd/rtsx_usb.c new file +34
-0+ +return usb_control_msg (ucr->pusb_dev, +usb_rcvctrlpipe (ucr->pusb_dev,0 ),0 ,0xC0 , + value,0 , data,1 ,100 ); +} +EXPORT_SYMBOL_GPL (rtsx_usb_ep0_read_register); + +void rtsx_usb_add_cmd (struct rtsx_ucr *ucr, +u8 cmd_type, +u16 reg_addr, +u8 mask, +u8 data) +{ +int i; + +if (ucr->cmd_idx < ((CMD_BUF_LEN -CMD_OFFSET ) /4 )) { + i =CMD_OFFSET + ucr->cmd_idx *4 ; + + ucr->cmd_buf[i++] = ((cmd_type &0x03 ) <<6 ) | + (u8)((reg_addr >>8 ) &0x3F ); + ucr->cmd_buf[i++] = (u8 )reg_addr; + ucr->cmd_buf[i++] = mask; + ucr->cmd_buf[i++] = data; + + ucr->cmd_idx++; + } +} +EXPORT_SYMBOL_GPL (rtsx_usb_add_cmd); + +int rtsx_usb_send_cmd (struct rtsx_ucr *ucr,u8 flag,int timeout) +{ +int ret; + + ucr->cmd_buf[CNT_H ] = (u8)(ucr->cmd_idx >>8 );
drivers/mfd/rtsx_usb.c line 257
Quoted 10 lines
drivers/mfd/rtsx_usb.c new file +10
-0+ ucr->cmd_buf[CNT_L ] = (u8)(ucr->cmd_idx); + ucr->cmd_buf[STAGE_FLAG ] = flag; + + ret =rtsx_usb_transfer_data (ucr, +usb_sndbulkpipe (ucr->pusb_dev,EP_BULK_OUT ), + ucr->cmd_buf, ucr->cmd_idx *4 +CMD_OFFSET , +0 ,NULL , timeout); +if (ret) { +/* clear HW error*/ +rtsx_usb_ep0_write_register (ucr,SFSM_ED ,0xf8 ,0xf8 );
Make this into a function and remove the comment.
rtsx_usb_ep0_clear_hw_error(ucr);
Quoted 28 lines
drivers/mfd/rtsx_usb.c new file +28
-0+return ret; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (rtsx_usb_send_cmd); + +int rtsx_usb_get_rsp (struct rtsx_ucr *ucr,int rsp_len,int timeout) +{ +if (rsp_len <=0 ) +return -EINVAL ; + +if (rsp_len %4 ) + rsp_len += (4 - rsp_len %4 ); + +return rtsx_usb_transfer_data (ucr, +usb_rcvbulkpipe (ucr->pusb_dev,EP_BULK_IN ), + ucr->rsp_buf, rsp_len,0 ,NULL , timeout); +} +EXPORT_SYMBOL_GPL (rtsx_usb_get_rsp); + +static int rtsx_usb_get_status_with_bulk (struct rtsx_ucr *ucr,u16 *status) +{ +int ret; + +rtsx_usb_init_cmd (ucr); +rtsx_usb_add_cmd (ucr,READ_REG_CMD ,CARD_EXIST ,0x00 ,0x00 ); +rtsx_usb_add_cmd (ucr,READ_REG_CMD ,OCPSTAT ,0x00 ,0x00 );
drivers/mfd/rtsx_usb.c line 295
Quoted 10 lines
drivers/mfd/rtsx_usb.c new file +10
-0+ ret =rtsx_usb_send_cmd (ucr,MODE_CR ,100 ); +if (ret) +return ret; + + ret =rtsx_usb_get_rsp (ucr,2 ,100 ); +if (ret) +return ret; + + *status = (u16)((ucr->rsp_buf[0 ] >>2 ) &0x0f ) | + ((ucr->rsp_buf[1 ] &0x03 ) <<4 );
The cast to u16 is not needed. Align it like this:
*status = ((ucr->rsp_buf[0] >> 2) & 0x0f) | ((ucr->rsp_buf[1] & 0x03) << 4);
Quoted 4 lines
drivers/mfd/rtsx_usb.c new file +4
-0+ +return 0 ; +} +
[ snip ]
Quoted 29 lines
drivers/mfd/rtsx_usb.c new file +29
-0+int rtsx_usb_switch_clock (struct rtsx_ucr *ucr,unsigned int card_clock, +u8 ssc_depth,bool initial_mode,bool double_clk,bool vpclk) +{ +int ret; +u8 n, clk_divider, mcu_cnt, div; + +if (!card_clock) { + ucr->cur_clk =0 ; +return 0 ; + } + +if (initial_mode) { +/* We use 250k(around) here, in initial stage */ + clk_divider =SD_CLK_DIVIDE_128 ; + card_clock =30000000 ; + }else { + clk_divider =SD_CLK_DIVIDE_0 ; + } + + ret =rtsx_usb_write_register (ucr,SD_CFG1 , +SD_CLK_DIVIDE_MASK , clk_divider); +if (ret <0 ) +return ret; + + card_clock /=1000000 ; +dev_dbg (&ucr->pusb_intf->dev, +"Switch card clock to %dMHz\n" , card_clock); + +if (!initial_mode && double_clk)
drivers/mfd/rtsx_usb.c line 430
Quoted 10 lines
drivers/mfd/rtsx_usb.c new file +10
-0+ card_clock *=2 ; +dev_dbg (&ucr->pusb_intf->dev, +"Internal SSC clock: %dMHz (cur_clk = %d)\n" , + card_clock, ucr->cur_clk); + +if (card_clock == ucr->cur_clk) +return 0 ; + +/* Converting clock value into internal settings: n and div */ + n = (u8)(card_clock -2 );
Unneeded cast.
drivers/mfd/rtsx_usb.c line 434
Quoted 4 lines
drivers/mfd/rtsx_usb.c new file +4
-0+if ((card_clock <=2 ) || (n >MAX_DIV_N )) +return -EINVAL ; + + mcu_cnt = (u8)(60 /card_clock +3 );
Unneeded cast. Obviously it fits in u8.
drivers/mfd/rtsx_usb.c line 441
Quoted 7 lines
drivers/mfd/rtsx_usb.c new file +7
-0+if (mcu_cnt >15 ) + mcu_cnt =15 ; + +/* Make sure that the SSC clock div_n is not less than MIN_DIV_N */ + + div =CLK_DIV_1 ; +while ((n <MIN_DIV_N ) && (div <CLK_DIV_4 )) {
Unneeded parenthesis.
Quoted 3 lines
drivers/mfd/rtsx_usb.c new file +3
-0+ n = (n +2 ) *2 -2 ; + div++; + }
[ snip ]
Quoted 44 lines
drivers/mfd/rtsx_usb.c new file +44
-0+static int rtsx_usb_init_chip (struct rtsx_ucr *ucr) +{ +int ret; +u8 val; + +/* clear HW error*/ +rtsx_usb_ep0_write_register (ucr,SFSM_ED ,0xf8 ,0xf8 ); + +/* power on SSC*/ + ret =rtsx_usb_write_register (ucr, +FPDCTL ,SSC_POWER_MASK ,SSC_POWER_ON ); +if (ret) + goto err_out; + +usleep_range (100 ,1000 ); + ret =rtsx_usb_write_register (ucr,CLK_DIV ,CLK_CHANGE ,0x00 ); +if (ret) + goto err_out; + +/* determine IC version */ + ret =rtsx_usb_read_register (ucr,HW_VERSION , &val); +if (ret) + goto err_out; + + ucr->ic_version = val &HW_VER_MASK ; + +/* determine package */ + ret =rtsx_usb_read_register (ucr,CARD_SHARE_MODE , &val); +if (ret) + goto err_out; +if (val &CARD_SHARE_LQFP_SEL ) { + ucr->package =LQFP48 ; +dev_dbg (&ucr->pusb_intf->dev,"Package: LQFP48\n" ); + }else { + ucr->package =QFN24 ; +dev_dbg (&ucr->pusb_intf->dev,"Package: QFN24\n" ); + } + +/* determine IC variations */ +rtsx_usb_read_register (ucr,CFG_MODE_1 , &val); +if (val &RTS5179 ) { + ucr->is_rts5179 =1 ; +dev_dbg (&ucr->pusb_intf->dev,"Device is rts5179\n" ); + }else {
drivers/mfd/rtsx_usb.c line 623
Quoted 10 lines
drivers/mfd/rtsx_usb.c new file +10
-0+ ucr->is_rts5179 =0 ; + } + + ret =rtsx_usb_reset_chip (ucr); +if (ret) + goto err_out; + +return 0 ; +err_out: +return ret;
Gar... Just return directly instead of adding do-nothing-gotos... No one likes skipping back and forth within a function to find what a goto does and then it does nothing, it just returns.
Quoted 7 lines
drivers/mfd/rtsx_usb.c new file +7
-0+} + +static int rtsx_usb_probe (struct usb_interface *intf, +const struct usb_device_id *id) +{ +struct usb_device *usb_dev =interface_to_usbdev (intf); +struct rtsx_ucr *ucr;
drivers/mfd/rtsx_usb.c line 640
Quoted 10 lines
drivers/mfd/rtsx_usb.c new file +10
-0+int i; +int ret; + +dev_dbg (&intf->dev, +": Realtek USB Card Reader found at bus %03d address %03d\n" , + usb_dev->bus->busnum, usb_dev->devnum); + + ucr =kzalloc (sizeof (struct rtsx_ucr ),GFP_KERNEL ); +if (!ucr) { +dev_err (&intf->dev,"Out of memory\n" );
This printk is pointless. kzalloc() already has a much usefull printk().
Quoted 26 lines
drivers/mfd/rtsx_usb.c new file +26
-0+return -ENOMEM ; + } + + ucr->pusb_dev = usb_dev; + +/* alloc coherent buffer */ + ucr->iobuf =usb_alloc_coherent (ucr->pusb_dev,IOBUF_SIZE , +GFP_KERNEL , &ucr->iobuf_dma); +if (!ucr->iobuf) { + ret = -ENOMEM ; + goto out_free_chip; + } + +/* set USB interface data */ +usb_set_intfdata (intf, ucr); + + ucr->vendor_id = id->idVendor; + ucr->product_id = id->idProduct; + ucr->cmd_buf = ucr->rsp_buf = ucr->iobuf; + +mutex_init (&ucr->dev_mutex); + + ucr->pusb_intf = intf; + +/* initialize */ + ret =rtsx_usb_init_chip (ucr);
drivers/mfd/rtsx_usb.c line 676
Quoted 10 lines
drivers/mfd/rtsx_usb.c new file +10
-0+if (ret) + goto out_init_fail; + +for (i =0 ; i <ARRAY_SIZE (rtsx_usb_cells); i++) { + rtsx_usb_cells[i].platform_data = &ucr; + rtsx_usb_cells[i].pdata_size =sizeof (*ucr); + } + ret =mfd_add_devices (&intf->dev, usb_dev->devnum, rtsx_usb_cells, +ARRAY_SIZE (rtsx_usb_cells),NULL ,0 ,NULL ); +
Don't put a blank line here.
Quoted 22 lines
drivers/mfd/rtsx_usb.c new file +22
-0+if (ret) + goto out_init_fail; +/* initialize USB SG transfer timer */ +init_timer (&ucr->sg_timer); +setup_timer (&ucr->sg_timer, rtsx_usb_sg_timed_out, (unsigned long ) ucr); +#ifdef CONFIG_PM + intf->needs_remote_wakeup =1 ; +usb_enable_autosuspend (usb_dev); +#endif + +return 0 ; + +out_init_fail: +usb_set_intfdata (ucr->pusb_intf,NULL ); +usb_free_coherent (ucr->pusb_dev,IOBUF_SIZE , ucr->iobuf, + ucr->iobuf_dma); + +out_free_chip: +kfree (ucr); +dev_err (&intf->dev,"%s failed\n" , __func__); +return ret; +}
[ snip ]
include/linux/mfd/rtsx_usb.h line 192
Quoted 8 lines
include/linux/mfd/rtsx_usb.h new file +8
-0+#define CARD_DMA1_CTL 0xFD5C +#define CARD_PULL_CTL1 0xFD60 +#define CARD_PULL_CTL2 0xFD61 +#define CARD_PULL_CTL3 0xFD62 +#define CARD_PULL_CTL4 0xFD63 +#define CARD_PULL_CTL5 0xFD64 +#define CARD_PULL_CTL6 0xFD65 +#define CARD_EXIST 0xFD6F
In the email CARD_EXIST looks aligned correctly, but in the actual .h file then it's out of line.
Quoted 2 lines
include/linux/mfd/rtsx_usb.h new file +2
-0+#define CARD_INT_PEND 0xFD71 +
[ snip ]
include/linux/mfd/rtsx_usb.h line 272
Quoted 9 lines
include/linux/mfd/rtsx_usb.h new file +9
-0+#define MC_IRQ 0xFF00 +#define MC_IRQEN 0xFF01 +#define MC_FIFO_CTL 0xFF02 +#define MC_FIFO_BC0 0xFF03 +#define MC_FIFO_BC1 0xFF04 +#define MC_FIFO_STAT 0xFF05 +#define MC_FIFO_MODE 0xFF06 +#define MC_FIFO_RD_PTR0 0xFF07 +#define MC_FIFO_RD_PTR1 0xFF08
MC_FIFO_RD_PTR0 and MC_FIFO_RD_PTR1 are not aligned correctly.
include/linux/mfd/rtsx_usb.h line 274
Quoted 2 lines
include/linux/mfd/rtsx_usb.h new file +2
-0+#define MC_DMA_CTL 0xFF10 +#define MC_DMA_TC0 0xFF11
regards,
dan carpenter
RE: [PATCH 1/3] mfd: Add realtek USB card reader driver
Hi Dan,
Quoted 10 lines
drivers/mfd/rtsx_usb.c line 192
Quoted 7 lines
drivers/mfd/rtsx_usb.c new file +7
-0+int rtsx_usb_ep0_write_register (struct rtsx_ucr *ucr,u16 addr, +u8 mask,u8 data) +{ +u16 value =0 , index =0 ; + + value |= (u16)(3 &0x03 ) <<14 ; + value |= (u16)(addr &0x3FFF );Don't do pointless things:
Quoted 7 lines
value |= 0x03 << 14; value |= addr & 0x3FFF;Quoted 1 line
+ value = ((value << 8) &
0xFF00) | ((value >> 8) &0x00FF);This is an endian conversion? It is buggy. Use the kernel endian conversion functions
cpu_to_le16().
This is not a conversion for endianess with respect to CPU but for command format of the device. It should always be performed regardless of platform.
In other words, it could be equivalent to:
value |= 0x03 << 6; // lower byte
value |= (addr & 0x3F00) >> 8; // lower byte
value |= (addr & 0xFF) << 8; //higher byteWe think the previous form is easier to read. Should we keep it or change to the later one?
Re: [PATCH 1/3] mfd: Add realtek USB card reader driver
Quoted 24 lines · Roger Tseng
Hi Dan,
Quoted 10 lines
drivers/mfd/rtsx_usb.c line 192
Quoted 7 lines
drivers/mfd/rtsx_usb.c new file +7
-0+int rtsx_usb_ep0_write_register (struct rtsx_ucr *ucr,u16 addr, +u8 mask,u8 data) +{ +u16 value =0 , index =0 ; + + value |= (u16)(3 &0x03 ) <<14 ; + value |= (u16)(addr &0x3FFF );Don't do pointless things:
Quoted 7 lines
value |= 0x03 << 14; value |= addr & 0x3FFF;Quoted 1 line
+ value = ((value << 8) &
0xFF00) | ((value >> 8) &0x00FF);This is an endian conversion? It is buggy. Use the kernel endian conversion functions
cpu_to_le16().This is not a conversion for endianess with respect to CPU but for command format of the device. It should always be performed regardless of platform.
Quoted 7 lines
In other words, it could be equivalent to:
value |= 0x03 << 6; // lower byte value |= (addr & 0x3F00) >> 8; // lower byte value |= (addr & 0xFF) << 8; //higher byteWe think the previous form is easier to read. Should we keep it or change to the later one?
To me it's really weird that the standard would specify that the address is in byte swapped reversed CPU-endian order. But if that's what it says then I don't care about formatting details. The original code is fine.
regards,
dan carpenter
Re: [PATCH 1/3] mfd: Add realtek USB card reader driver
In reply to [email protected]Quoted 5 lines · On Mon, 2013-12-23 at 17:52 +0800, [email protected] wrote:
From: Roger Tseng <[email protected]>
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.
Thank you for writing this driver.
A few remarks about the code and sorry for the delay in reviewing.
drivers/mfd/rtsx_usb.c line 49
Quoted 10 lines
Signed-off-by Roger Tseng <[email protected]>drivers/mfd/rtsx_usb.c new file +8
-0+static void rtsx_usb_sg_timed_out (unsigned long data) +{ +struct rtsx_ucr *ucr = (struct rtsx_ucr *)data; + +dev_dbg (&ucr->pusb_intf->dev,"%s: sg transfer timed out" , __func__); +usb_sg_cancel (&ucr->current_sg); + +/* we know the cancellation is caused by time-out */
How do you know? You know it won't complete here, but it may have completed for another reason.
Quoted 14 lines
drivers/mfd/rtsx_usb.c new file +13
-0+ ucr->current_sg.status = -ETIMEDOUT ; +} +static int rtsx_usb_seq_write_register (struct rtsx_ucr *ucr, +u16 addr,u16 len,u8 *data) +{ +u16 cmd_len = len +12 ; + +if (data ==NULL ) +return -EINVAL ; + + cmd_len = (cmd_len <=CMD_BUF_LEN ) ? cmd_len :CMD_BUF_LEN ; + +if (cmd_len %4 )
drivers/mfd/rtsx_usb.c line 114
Quoted 10 lines
drivers/mfd/rtsx_usb.c new file +10
-0+ cmd_len += (4 - cmd_len %4 ); + + + ucr->cmd_buf[0 ] ='R' ; + ucr->cmd_buf[1 ] ='T' ; + ucr->cmd_buf[2 ] ='C' ; + ucr->cmd_buf[3 ] ='R' ; + ucr->cmd_buf[PACKET_TYPE ] =SEQ_WRITE ; + ucr->cmd_buf[5 ] = (u8)(len >>8 ); + ucr->cmd_buf[6 ] = (u8 )len;
Please use the macros the kernel provides.
drivers/mfd/rtsx_usb.c line 117
Quoted 3 lines
drivers/mfd/rtsx_usb.c new file +3
-0+ ucr->cmd_buf[STAGE_FLAG ] =0 ; + ucr->cmd_buf[8 ] = (u8)(addr >>8 ); + ucr->cmd_buf[9 ] = (u8 )addr;
Likewise.
Quoted 11 lines
drivers/mfd/rtsx_usb.c new file +10
-0+ +memcpy (ucr->cmd_buf +12 , data, len); + +return rtsx_usb_transfer_data (ucr, +usb_sndbulkpipe (ucr->pusb_dev,EP_BULK_OUT ), + ucr->cmd_buf, cmd_len,0 ,NULL ,100 ); +} +int rtsx_usb_send_cmd (struct rtsx_ucr *ucr,u8 flag,int timeout) +{ +int ret;
drivers/mfd/rtsx_usb.c line 255
Quoted 10 lines
drivers/mfd/rtsx_usb.c new file +10
-0+ + ucr->cmd_buf[CNT_H ] = (u8)(ucr->cmd_idx >>8 ); + ucr->cmd_buf[CNT_L ] = (u8)(ucr->cmd_idx); + ucr->cmd_buf[STAGE_FLAG ] = flag; + + ret =rtsx_usb_transfer_data (ucr, +usb_sndbulkpipe (ucr->pusb_dev,EP_BULK_OUT ), + ucr->cmd_buf, ucr->cmd_idx *4 +CMD_OFFSET , +0 ,NULL , timeout); +if (ret) {
Even for fatal errors?
Quoted 17 lines
drivers/mfd/rtsx_usb.c new file +16
-0+/* clear HW error*/ +rtsx_usb_ep0_write_register (ucr,SFSM_ED ,0xf8 ,0xf8 ); +return ret; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (rtsx_usb_send_cmd); +#ifdef CONFIG_PM +static int rtsx_usb_suspend (struct usb_interface *intf,pm_message_t message) +{ +struct rtsx_ucr *ucr = + (struct rtsx_ucr *)usb_get_intfdata (intf); + +dev_dbg (&intf->dev,"%s called with pm message 0x%04u\n" , + __func__, message.event);
drivers/mfd/rtsx_usb.c line 732
Quoted 10 lines
drivers/mfd/rtsx_usb.c new file +10
-0+ +mutex_lock (&ucr->dev_mutex); +rtsx_usb_turn_off_led (ucr); +mutex_unlock (&ucr->dev_mutex); +return 0 ; +} + +static int rtsx_usb_resume (struct usb_interface *intf) +{ +return 0 ;
Don't you want to turn the LED back on?
drivers/mfd/rtsx_usb.c line 786
Quoted 13 lines
drivers/mfd/rtsx_usb.c new file +12
-0+} +static struct usb_driver rtsx_usb_driver = { + .name =DRV_NAME_RTSX_USB , + .probe = rtsx_usb_probe, + .disconnect = rtsx_usb_disconnect, + .suspend = rtsx_usb_suspend, + .resume = rtsx_usb_resume, + .reset_resume = rtsx_usb_reset_resume, + .pre_reset = rtsx_usb_pre_reset, + .post_reset = rtsx_usb_post_reset, + .id_table = rtsx_usb_usb_ids, + .supports_autosuspend =1 ,
This is good, but what do you need remote wakeup for?
Quoted 3 lines
drivers/mfd/rtsx_usb.c new file +3
-0+ .soft_unbind = 1, +}; +
PATCH 2/3 mmc: Add realtek USB sdmmc host driver
In reply to [email protected]From: Roger Tseng <[email protected]>
Realtek USB SD/MMC host driver provides mmc host support based on the Realtek USB card reader MFD driver.
--- drivers/mmc/host/Kconfig | 7 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/rtsx_usb_sdmmc.c | 1511 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1519 insertions(+) create mode 100644 drivers/mmc/host/rtsx_usb_sdmmc.c
drivers/mmc/host/Kconfig +7 -0
@@ -665,3 +665,10 @@ config MMC_REALTEK_PCI help Say Y here to include driver code to support SD/MMC card interface of Realtek PCI-E card reader + +config MMC_REALTEK_USB + tristate "Realtek USB SD/MMC Card Interface Driver" + depends on MFD_RTSX_USB + help + Say Y here to include driver code to support SD/MMC card interface + of Realtek RTS5129/39 series card reader
drivers/mmc/host/Makefile +1 -0
@@ -51,6 +51,7 @@ obj-$(CONFIG_MMC_USHC) += ushc.o obj-$(CONFIG_MMC_WMT) += wmt-sdmmc.o obj-$(CONFIG_MMC_REALTEK_PCI) += rtsx_pci_sdmmc.o +obj-$(CONFIG_MMC_REALTEK_USB) += rtsx_usb_sdmmc.o obj-$(CONFIG_MMC_SDHCI_PLTFM) += sdhci-pltfm.o obj-$(CONFIG_MMC_SDHCI_CNS3XXX) += sdhci-cns3xxx.o
drivers/mmc/host/rtsx_usb_sdmmc.c new file +1511 -0
1,511 lines not on this page · raw message
Signature · 1 line
1.8.2
Re: [PATCH 2/3] mmc: Add realtek USB sdmmc host driver
Quoted 8 lines · On Mon, 2013-12-23 at 17:52 +0800, [email protected] wrote:
From: Roger Tseng <[email protected]>
Realtek USB SD/MMC host driver provides mmc host support based on the Realtek USB card reader MFD driver.
Signed-off-by Roger Tseng <[email protected]>+#ifdef DEBUG
Dynamic debugging would be nice.
Quoted 6 lines
drivers/mmc/host/rtsx_usb_sdmmc.c new file +6
-0+static void sd_print_debug_regs (struct rtsx_usb_sdmmc *host) +{ +struct rtsx_ucr *ucr = host->ucr; +u8 val =0 ; + +rtsx_usb_ep0_read_register (ucr,SD_STAT1 , &val);
drivers/mmc/host/rtsx_usb_sdmmc.c line 104
Quoted 10 lines
drivers/mmc/host/rtsx_usb_sdmmc.c new file +10
-0+dev_dbg (sdmmc_dev (host),"SD_STAT1: 0x%x\n" , val); +rtsx_usb_ep0_read_register (ucr,SD_STAT2 , &val); +dev_dbg (sdmmc_dev (host),"SD_STAT2: 0x%x\n" , val); +rtsx_usb_ep0_read_register (ucr,SD_BUS_STAT , &val); + dev_dbg(sdmmc_dev(host), "SD_BUS_STAT: 0x%x\n", val); +} +#else +#define sd_print_debug_regs (host) +#endif /* DEBUG */ +
Regards
Oliver
PATCH 3/3 memstick: Add realtek USB memstick host driver
In reply to [email protected]From: Roger Tseng <[email protected]>
Realtek USB memstick host driver provides memstick host support based on the Realtek USB card reader MFD driver.
--- drivers/memstick/host/Kconfig | 10 + drivers/memstick/host/Makefile | 1 + drivers/memstick/host/rtsx_usb_ms.c | 856 ++++++++++++++++++++++++++++++++++++ 3 files changed, 867 insertions(+) create mode 100644 drivers/memstick/host/rtsx_usb_ms.c
drivers/memstick/host/Kconfig +10 -0
@@ -52,3 +52,13 @@ config MEMSTICK_REALTEK_PCI 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 MFD_RTSX_USB + help + Say Y here to include driver code to support Memstick card interface + of Realtek RTS5129/39 series USB card reader + + To compile this driver as a module, choose M here: the module will + be called rts5139_ms.
drivers/memstick/host/Makefile +1 -0
@@ -6,3 +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
drivers/memstick/host/rtsx_usb_ms.c new file +856 -0
856 lines not on this page · raw message
Signature · 1 line
1.8.2