rsi: Add usb multi-byte read operation
authorPrameela Rani Garnepudi <prameela.j04cs@gmail.com>
Tue, 16 May 2017 10:01:13 +0000 (15:31 +0530)
committerKalle Valo <kvalo@codeaurora.org>
Wed, 24 May 2017 13:37:51 +0000 (16:37 +0300)
USB multibyte read will be used in the new firmware loading method
for RS9113 chipset.

Signed-off-by: Prameela Rani Garnepudi <prameela.j04cs@gmail.com>
Signed-off-by: Amitkumar Karwar <amit.karwar@redpinesignals.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/rsi/rsi_91x_usb.c

index a900a7288acb7fe18c437b99b7a8bcd95f324669..31f96f0f6e30d9de4cd150e4d9e1a885bfa26209 100644 (file)
@@ -276,6 +276,46 @@ static int rsi_rx_urb_submit(struct rsi_hw *adapter)
        return status;
 }
 
+static int rsi_usb_read_register_multiple(struct rsi_hw *adapter, u32 addr,
+                                         u8 *data, u16 count)
+{
+       struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
+       u8 *buf;
+       u16 transfer;
+       int status;
+
+       if (!addr)
+               return -EINVAL;
+
+       buf = kzalloc(RSI_USB_BUF_SIZE, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+       while (count) {
+               transfer = min_t(u16, count, RSI_USB_BUF_SIZE);
+               status = usb_control_msg(dev->usbdev,
+                                        usb_rcvctrlpipe(dev->usbdev, 0),
+                                        USB_VENDOR_REGISTER_READ,
+                                        RSI_USB_REQ_IN,
+                                        ((addr & 0xffff0000) >> 16),
+                                        (addr & 0xffff), (void *)buf,
+                                        transfer, USB_CTRL_GET_TIMEOUT);
+               if (status < 0) {
+                       rsi_dbg(ERR_ZONE,
+                               "Reg read failed with error code :%d\n",
+                                status);
+                       kfree(buf);
+                       return status;
+               }
+               memcpy(data, buf, transfer);
+               count -= transfer;
+               data += transfer;
+               addr += transfer;
+       }
+       kfree(buf);
+       return 0;
+}
+
 /**
  * rsi_usb_write_register_multiple() - This function writes multiple bytes of
  *                                    information to multiple registers.