perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / drivers / net / wireless / rsi / rsi_91x_usb.c
blobf360690396dd02a536ac7664a2c477028b3c2524
1 /**
2 * Copyright (c) 2014 Redpine Signals Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/module.h>
19 #include <net/rsi_91x.h>
20 #include "rsi_usb.h"
21 #include "rsi_hal.h"
22 #include "rsi_coex.h"
24 /* Default operating mode is wlan STA + BT */
25 static u16 dev_oper_mode = DEV_OPMODE_STA_BT_DUAL;
26 module_param(dev_oper_mode, ushort, 0444);
27 MODULE_PARM_DESC(dev_oper_mode,
28 "1[Wi-Fi], 4[BT], 8[BT LE], 5[Wi-Fi STA + BT classic]\n"
29 "9[Wi-Fi STA + BT LE], 13[Wi-Fi STA + BT classic + BT LE]\n"
30 "6[AP + BT classic], 14[AP + BT classic + BT LE]");
32 static int rsi_rx_urb_submit(struct rsi_hw *adapter, u8 ep_num);
34 /**
35 * rsi_usb_card_write() - This function writes to the USB Card.
36 * @adapter: Pointer to the adapter structure.
37 * @buf: Pointer to the buffer from where the data has to be taken.
38 * @len: Length to be written.
39 * @endpoint: Type of endpoint.
41 * Return: status: 0 on success, a negative error code on failure.
43 static int rsi_usb_card_write(struct rsi_hw *adapter,
44 u8 *buf,
45 u16 len,
46 u8 endpoint)
48 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
49 int status;
50 u8 *seg = dev->tx_buffer;
51 int transfer;
52 int ep = dev->bulkout_endpoint_addr[endpoint - 1];
54 memset(seg, 0, len + RSI_USB_TX_HEAD_ROOM);
55 memcpy(seg + RSI_USB_TX_HEAD_ROOM, buf, len);
56 len += RSI_USB_TX_HEAD_ROOM;
57 transfer = len;
58 status = usb_bulk_msg(dev->usbdev,
59 usb_sndbulkpipe(dev->usbdev, ep),
60 (void *)seg,
61 (int)len,
62 &transfer,
63 HZ * 5);
65 if (status < 0) {
66 rsi_dbg(ERR_ZONE,
67 "Card write failed with error code :%10d\n", status);
68 dev->write_fail = 1;
70 return status;
73 /**
74 * rsi_write_multiple() - This function writes multiple bytes of information
75 * to the USB card.
76 * @adapter: Pointer to the adapter structure.
77 * @addr: Address of the register.
78 * @data: Pointer to the data that has to be written.
79 * @count: Number of multiple bytes to be written.
81 * Return: 0 on success, a negative error code on failure.
83 static int rsi_write_multiple(struct rsi_hw *adapter,
84 u8 endpoint,
85 u8 *data,
86 u32 count)
88 struct rsi_91x_usbdev *dev;
90 if (!adapter)
91 return -ENODEV;
93 if (endpoint == 0)
94 return -EINVAL;
96 dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
97 if (dev->write_fail)
98 return -ENETDOWN;
100 return rsi_usb_card_write(adapter, data, count, endpoint);
104 * rsi_find_bulk_in_and_out_endpoints() - This function initializes the bulk
105 * endpoints to the device.
106 * @interface: Pointer to the USB interface structure.
107 * @adapter: Pointer to the adapter structure.
109 * Return: ret_val: 0 on success, -ENOMEM on failure.
111 static int rsi_find_bulk_in_and_out_endpoints(struct usb_interface *interface,
112 struct rsi_hw *adapter)
114 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
115 struct usb_host_interface *iface_desc;
116 struct usb_endpoint_descriptor *endpoint;
117 __le16 buffer_size;
118 int ii, bin_found = 0, bout_found = 0;
120 iface_desc = &(interface->altsetting[0]);
122 for (ii = 0; ii < iface_desc->desc.bNumEndpoints; ++ii) {
123 endpoint = &(iface_desc->endpoint[ii].desc);
125 if (!dev->bulkin_endpoint_addr[bin_found] &&
126 (endpoint->bEndpointAddress & USB_DIR_IN) &&
127 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
128 USB_ENDPOINT_XFER_BULK)) {
129 buffer_size = endpoint->wMaxPacketSize;
130 dev->bulkin_size[bin_found] = buffer_size;
131 dev->bulkin_endpoint_addr[bin_found] =
132 endpoint->bEndpointAddress;
133 bin_found++;
136 if (!dev->bulkout_endpoint_addr[bout_found] &&
137 !(endpoint->bEndpointAddress & USB_DIR_IN) &&
138 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
139 USB_ENDPOINT_XFER_BULK)) {
140 buffer_size = endpoint->wMaxPacketSize;
141 dev->bulkout_endpoint_addr[bout_found] =
142 endpoint->bEndpointAddress;
143 dev->bulkout_size[bout_found] = buffer_size;
144 bout_found++;
147 if (bin_found >= MAX_BULK_EP || bout_found >= MAX_BULK_EP)
148 break;
151 if (!(dev->bulkin_endpoint_addr[0]) &&
152 dev->bulkout_endpoint_addr[0])
153 return -EINVAL;
155 return 0;
158 #define RSI_USB_REQ_OUT (USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE)
159 #define RSI_USB_REQ_IN (USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE)
161 /* rsi_usb_reg_read() - This function reads data from given register address.
162 * @usbdev: Pointer to the usb_device structure.
163 * @reg: Address of the register to be read.
164 * @value: Value to be read.
165 * @len: length of data to be read.
167 * Return: status: 0 on success, a negative error code on failure.
169 static int rsi_usb_reg_read(struct usb_device *usbdev,
170 u32 reg,
171 u16 *value,
172 u16 len)
174 u8 *buf;
175 int status = -ENOMEM;
177 if (len > RSI_USB_CTRL_BUF_SIZE)
178 return -EINVAL;
180 buf = kmalloc(RSI_USB_CTRL_BUF_SIZE, GFP_KERNEL);
181 if (!buf)
182 return status;
184 status = usb_control_msg(usbdev,
185 usb_rcvctrlpipe(usbdev, 0),
186 USB_VENDOR_REGISTER_READ,
187 RSI_USB_REQ_IN,
188 ((reg & 0xffff0000) >> 16), (reg & 0xffff),
189 (void *)buf,
190 len,
191 USB_CTRL_GET_TIMEOUT);
193 *value = (buf[0] | (buf[1] << 8));
194 if (status < 0) {
195 rsi_dbg(ERR_ZONE,
196 "%s: Reg read failed with error code :%d\n",
197 __func__, status);
199 kfree(buf);
201 return status;
205 * rsi_usb_reg_write() - This function writes the given data into the given
206 * register address.
207 * @usbdev: Pointer to the usb_device structure.
208 * @reg: Address of the register.
209 * @value: Value to write.
210 * @len: Length of data to be written.
212 * Return: status: 0 on success, a negative error code on failure.
214 static int rsi_usb_reg_write(struct usb_device *usbdev,
215 u32 reg,
216 u16 value,
217 u16 len)
219 u8 *usb_reg_buf;
220 int status = -ENOMEM;
222 if (len > RSI_USB_CTRL_BUF_SIZE)
223 return -EINVAL;
225 usb_reg_buf = kmalloc(RSI_USB_CTRL_BUF_SIZE, GFP_KERNEL);
226 if (!usb_reg_buf)
227 return status;
229 usb_reg_buf[0] = (value & 0x00ff);
230 usb_reg_buf[1] = (value & 0xff00) >> 8;
231 usb_reg_buf[2] = 0x0;
232 usb_reg_buf[3] = 0x0;
234 status = usb_control_msg(usbdev,
235 usb_sndctrlpipe(usbdev, 0),
236 USB_VENDOR_REGISTER_WRITE,
237 RSI_USB_REQ_OUT,
238 ((reg & 0xffff0000) >> 16),
239 (reg & 0xffff),
240 (void *)usb_reg_buf,
241 len,
242 USB_CTRL_SET_TIMEOUT);
243 if (status < 0) {
244 rsi_dbg(ERR_ZONE,
245 "%s: Reg write failed with error code :%d\n",
246 __func__, status);
248 kfree(usb_reg_buf);
250 return status;
254 * rsi_rx_done_handler() - This function is called when a packet is received
255 * from USB stack. This is callback to recieve done.
256 * @urb: Received URB.
258 * Return: None.
260 static void rsi_rx_done_handler(struct urb *urb)
262 struct rx_usb_ctrl_block *rx_cb = urb->context;
263 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)rx_cb->data;
264 int status = -EINVAL;
266 if (urb->status)
267 goto out;
269 if (urb->actual_length <= 0 ||
270 urb->actual_length > rx_cb->rx_skb->len) {
271 rsi_dbg(INFO_ZONE, "%s: Invalid packet length = %d\n",
272 __func__, urb->actual_length);
273 goto out;
275 if (skb_queue_len(&dev->rx_q) >= RSI_MAX_RX_PKTS) {
276 rsi_dbg(INFO_ZONE, "Max RX packets reached\n");
277 goto out;
279 skb_trim(rx_cb->rx_skb, urb->actual_length);
280 skb_queue_tail(&dev->rx_q, rx_cb->rx_skb);
282 rsi_set_event(&dev->rx_thread.event);
283 status = 0;
285 out:
286 if (rsi_rx_urb_submit(dev->priv, rx_cb->ep_num))
287 rsi_dbg(ERR_ZONE, "%s: Failed in urb submission", __func__);
289 if (status)
290 dev_kfree_skb(rx_cb->rx_skb);
294 * rsi_rx_urb_submit() - This function submits the given URB to the USB stack.
295 * @adapter: Pointer to the adapter structure.
297 * Return: 0 on success, a negative error code on failure.
299 static int rsi_rx_urb_submit(struct rsi_hw *adapter, u8 ep_num)
301 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
302 struct rx_usb_ctrl_block *rx_cb = &dev->rx_cb[ep_num - 1];
303 struct urb *urb = rx_cb->rx_urb;
304 int status;
305 struct sk_buff *skb;
306 u8 dword_align_bytes = 0;
308 #define RSI_MAX_RX_USB_PKT_SIZE 3000
309 skb = dev_alloc_skb(RSI_MAX_RX_USB_PKT_SIZE);
310 if (!skb)
311 return -ENOMEM;
312 skb_reserve(skb, MAX_DWORD_ALIGN_BYTES);
313 skb_put(skb, RSI_MAX_RX_USB_PKT_SIZE - MAX_DWORD_ALIGN_BYTES);
314 dword_align_bytes = (unsigned long)skb->data & 0x3f;
315 if (dword_align_bytes > 0)
316 skb_push(skb, dword_align_bytes);
317 urb->transfer_buffer = skb->data;
318 rx_cb->rx_skb = skb;
320 usb_fill_bulk_urb(urb,
321 dev->usbdev,
322 usb_rcvbulkpipe(dev->usbdev,
323 dev->bulkin_endpoint_addr[ep_num - 1]),
324 urb->transfer_buffer,
325 skb->len,
326 rsi_rx_done_handler,
327 rx_cb);
329 status = usb_submit_urb(urb, GFP_KERNEL);
330 if (status)
331 rsi_dbg(ERR_ZONE, "%s: Failed in urb submission\n", __func__);
333 return status;
336 static int rsi_usb_read_register_multiple(struct rsi_hw *adapter, u32 addr,
337 u8 *data, u16 count)
339 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
340 u8 *buf;
341 u16 transfer;
342 int status;
344 if (!addr)
345 return -EINVAL;
347 buf = kzalloc(RSI_USB_BUF_SIZE, GFP_KERNEL);
348 if (!buf)
349 return -ENOMEM;
351 while (count) {
352 transfer = min_t(u16, count, RSI_USB_BUF_SIZE);
353 status = usb_control_msg(dev->usbdev,
354 usb_rcvctrlpipe(dev->usbdev, 0),
355 USB_VENDOR_REGISTER_READ,
356 RSI_USB_REQ_IN,
357 ((addr & 0xffff0000) >> 16),
358 (addr & 0xffff), (void *)buf,
359 transfer, USB_CTRL_GET_TIMEOUT);
360 if (status < 0) {
361 rsi_dbg(ERR_ZONE,
362 "Reg read failed with error code :%d\n",
363 status);
364 kfree(buf);
365 return status;
367 memcpy(data, buf, transfer);
368 count -= transfer;
369 data += transfer;
370 addr += transfer;
372 kfree(buf);
373 return 0;
377 * rsi_usb_write_register_multiple() - This function writes multiple bytes of
378 * information to multiple registers.
379 * @adapter: Pointer to the adapter structure.
380 * @addr: Address of the register.
381 * @data: Pointer to the data that has to be written.
382 * @count: Number of multiple bytes to be written on to the registers.
384 * Return: status: 0 on success, a negative error code on failure.
386 static int rsi_usb_write_register_multiple(struct rsi_hw *adapter, u32 addr,
387 u8 *data, u16 count)
389 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
390 u8 *buf;
391 u16 transfer;
392 int status = 0;
394 buf = kzalloc(RSI_USB_BUF_SIZE, GFP_KERNEL);
395 if (!buf)
396 return -ENOMEM;
398 while (count) {
399 transfer = min_t(u16, count, RSI_USB_BUF_SIZE);
400 memcpy(buf, data, transfer);
401 status = usb_control_msg(dev->usbdev,
402 usb_sndctrlpipe(dev->usbdev, 0),
403 USB_VENDOR_REGISTER_WRITE,
404 RSI_USB_REQ_OUT,
405 ((addr & 0xffff0000) >> 16),
406 (addr & 0xffff),
407 (void *)buf,
408 transfer,
409 USB_CTRL_SET_TIMEOUT);
410 if (status < 0) {
411 rsi_dbg(ERR_ZONE,
412 "Reg write failed with error code :%d\n",
413 status);
414 kfree(buf);
415 return status;
417 count -= transfer;
418 data += transfer;
419 addr += transfer;
422 kfree(buf);
423 return 0;
427 *rsi_usb_host_intf_write_pkt() - This function writes the packet to the
428 * USB card.
429 * @adapter: Pointer to the adapter structure.
430 * @pkt: Pointer to the data to be written on to the card.
431 * @len: Length of the data to be written on to the card.
433 * Return: 0 on success, a negative error code on failure.
435 static int rsi_usb_host_intf_write_pkt(struct rsi_hw *adapter,
436 u8 *pkt,
437 u32 len)
439 u32 queueno = ((pkt[1] >> 4) & 0x7);
440 u8 endpoint;
442 endpoint = ((queueno == RSI_WIFI_MGMT_Q || queueno == RSI_WIFI_DATA_Q ||
443 queueno == RSI_COEX_Q) ? WLAN_EP : BT_EP);
445 return rsi_write_multiple(adapter,
446 endpoint,
447 (u8 *)pkt,
448 len);
451 static int rsi_usb_master_reg_read(struct rsi_hw *adapter, u32 reg,
452 u32 *value, u16 len)
454 struct usb_device *usbdev =
455 ((struct rsi_91x_usbdev *)adapter->rsi_dev)->usbdev;
456 u16 temp;
457 int ret;
459 ret = rsi_usb_reg_read(usbdev, reg, &temp, len);
460 if (ret < 0)
461 return ret;
462 *value = temp;
464 return 0;
467 static int rsi_usb_master_reg_write(struct rsi_hw *adapter,
468 unsigned long reg,
469 unsigned long value, u16 len)
471 struct usb_device *usbdev =
472 ((struct rsi_91x_usbdev *)adapter->rsi_dev)->usbdev;
474 return rsi_usb_reg_write(usbdev, reg, value, len);
477 static int rsi_usb_load_data_master_write(struct rsi_hw *adapter,
478 u32 base_address,
479 u32 instructions_sz, u16 block_size,
480 u8 *ta_firmware)
482 u16 num_blocks;
483 u32 cur_indx, i;
484 u8 temp_buf[256];
485 int status;
487 num_blocks = instructions_sz / block_size;
488 rsi_dbg(INFO_ZONE, "num_blocks: %d\n", num_blocks);
490 for (cur_indx = 0, i = 0; i < num_blocks; i++, cur_indx += block_size) {
491 memcpy(temp_buf, ta_firmware + cur_indx, block_size);
492 status = rsi_usb_write_register_multiple(adapter, base_address,
493 (u8 *)(temp_buf),
494 block_size);
495 if (status < 0)
496 return status;
498 rsi_dbg(INFO_ZONE, "%s: loading block: %d\n", __func__, i);
499 base_address += block_size;
502 if (instructions_sz % block_size) {
503 memset(temp_buf, 0, block_size);
504 memcpy(temp_buf, ta_firmware + cur_indx,
505 instructions_sz % block_size);
506 status = rsi_usb_write_register_multiple
507 (adapter, base_address,
508 (u8 *)temp_buf,
509 instructions_sz % block_size);
510 if (status < 0)
511 return status;
512 rsi_dbg(INFO_ZONE,
513 "Written Last Block in Address 0x%x Successfully\n",
514 cur_indx);
516 return 0;
519 static struct rsi_host_intf_ops usb_host_intf_ops = {
520 .write_pkt = rsi_usb_host_intf_write_pkt,
521 .read_reg_multiple = rsi_usb_read_register_multiple,
522 .write_reg_multiple = rsi_usb_write_register_multiple,
523 .master_reg_read = rsi_usb_master_reg_read,
524 .master_reg_write = rsi_usb_master_reg_write,
525 .load_data_master_write = rsi_usb_load_data_master_write,
529 * rsi_deinit_usb_interface() - This function deinitializes the usb interface.
530 * @adapter: Pointer to the adapter structure.
532 * Return: None.
534 static void rsi_deinit_usb_interface(struct rsi_hw *adapter)
536 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
538 rsi_kill_thread(&dev->rx_thread);
540 usb_free_urb(dev->rx_cb[0].rx_urb);
541 if (adapter->priv->coex_mode > 1)
542 usb_free_urb(dev->rx_cb[1].rx_urb);
544 kfree(dev->tx_buffer);
547 static int rsi_usb_init_rx(struct rsi_hw *adapter)
549 struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
550 struct rx_usb_ctrl_block *rx_cb;
551 u8 idx, num_rx_cb;
553 num_rx_cb = (adapter->priv->coex_mode > 1 ? 2 : 1);
555 for (idx = 0; idx < num_rx_cb; idx++) {
556 rx_cb = &dev->rx_cb[idx];
558 rx_cb->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
559 if (!rx_cb->rx_urb) {
560 rsi_dbg(ERR_ZONE, "Failed alloc rx urb[%d]\n", idx);
561 goto err;
563 rx_cb->ep_num = idx + 1;
564 rx_cb->data = (void *)dev;
566 skb_queue_head_init(&dev->rx_q);
567 rsi_init_event(&dev->rx_thread.event);
568 if (rsi_create_kthread(adapter->priv, &dev->rx_thread,
569 rsi_usb_rx_thread, "RX-Thread")) {
570 rsi_dbg(ERR_ZONE, "%s: Unable to init rx thrd\n", __func__);
571 goto err;
574 return 0;
576 err:
577 usb_free_urb(dev->rx_cb[0].rx_urb);
578 if (adapter->priv->coex_mode > 1)
579 usb_free_urb(dev->rx_cb[1].rx_urb);
581 return -1;
585 * rsi_init_usb_interface() - This function initializes the usb interface.
586 * @adapter: Pointer to the adapter structure.
587 * @pfunction: Pointer to USB interface structure.
589 * Return: 0 on success, a negative error code on failure.
591 static int rsi_init_usb_interface(struct rsi_hw *adapter,
592 struct usb_interface *pfunction)
594 struct rsi_91x_usbdev *rsi_dev;
595 int status;
597 rsi_dev = kzalloc(sizeof(*rsi_dev), GFP_KERNEL);
598 if (!rsi_dev)
599 return -ENOMEM;
601 adapter->rsi_dev = rsi_dev;
602 rsi_dev->usbdev = interface_to_usbdev(pfunction);
603 rsi_dev->priv = (void *)adapter;
605 if (rsi_find_bulk_in_and_out_endpoints(pfunction, adapter)) {
606 status = -EINVAL;
607 goto fail_eps;
610 adapter->device = &pfunction->dev;
611 usb_set_intfdata(pfunction, adapter);
613 rsi_dev->tx_buffer = kmalloc(2048, GFP_KERNEL);
614 if (!rsi_dev->tx_buffer) {
615 status = -ENOMEM;
616 goto fail_eps;
619 if (rsi_usb_init_rx(adapter)) {
620 rsi_dbg(ERR_ZONE, "Failed to init RX handle\n");
621 status = -ENOMEM;
622 goto fail_rx;
625 rsi_dev->tx_blk_size = 252;
626 adapter->block_size = rsi_dev->tx_blk_size;
628 /* Initializing function callbacks */
629 adapter->check_hw_queue_status = rsi_usb_check_queue_status;
630 adapter->determine_event_timeout = rsi_usb_event_timeout;
631 adapter->rsi_host_intf = RSI_HOST_INTF_USB;
632 adapter->host_intf_ops = &usb_host_intf_ops;
634 #ifdef CONFIG_RSI_DEBUGFS
635 /* In USB, one less than the MAX_DEBUGFS_ENTRIES entries is required */
636 adapter->num_debugfs_entries = (MAX_DEBUGFS_ENTRIES - 1);
637 #endif
639 rsi_dbg(INIT_ZONE, "%s: Enabled the interface\n", __func__);
640 return 0;
642 fail_rx:
643 kfree(rsi_dev->tx_buffer);
645 fail_eps:
646 kfree(rsi_dev);
648 return status;
651 static int usb_ulp_read_write(struct rsi_hw *adapter, u16 addr, u32 data,
652 u16 len_in_bits)
654 int ret;
656 ret = rsi_usb_master_reg_write
657 (adapter, RSI_GSPI_DATA_REG1,
658 ((addr << 6) | ((data >> 16) & 0xffff)), 2);
659 if (ret < 0)
660 return ret;
662 ret = rsi_usb_master_reg_write(adapter, RSI_GSPI_DATA_REG0,
663 (data & 0xffff), 2);
664 if (ret < 0)
665 return ret;
667 /* Initializing GSPI for ULP read/writes */
668 rsi_usb_master_reg_write(adapter, RSI_GSPI_CTRL_REG0,
669 RSI_GSPI_CTRL_REG0_VALUE, 2);
671 ret = rsi_usb_master_reg_write(adapter, RSI_GSPI_CTRL_REG1,
672 ((len_in_bits - 1) | RSI_GSPI_TRIG), 2);
673 if (ret < 0)
674 return ret;
676 msleep(20);
678 return 0;
681 static int rsi_reset_card(struct rsi_hw *adapter)
683 int ret;
685 rsi_dbg(INFO_ZONE, "Resetting Card...\n");
686 rsi_usb_master_reg_write(adapter, RSI_TA_HOLD_REG, 0xE, 4);
688 /* This msleep will ensure Thread-Arch processor to go to hold
689 * and any pending dma transfers to rf in device to finish.
691 msleep(100);
693 ret = rsi_usb_master_reg_write(adapter, SWBL_REGOUT,
694 RSI_FW_WDT_DISABLE_REQ,
695 RSI_COMMON_REG_SIZE);
696 if (ret < 0) {
697 rsi_dbg(ERR_ZONE, "Disabling firmware watchdog timer failed\n");
698 goto fail;
701 ret = usb_ulp_read_write(adapter, RSI_WATCH_DOG_TIMER_1,
702 RSI_ULP_WRITE_2, 32);
703 if (ret < 0)
704 goto fail;
705 ret = usb_ulp_read_write(adapter, RSI_WATCH_DOG_TIMER_2,
706 RSI_ULP_WRITE_0, 32);
707 if (ret < 0)
708 goto fail;
709 ret = usb_ulp_read_write(adapter, RSI_WATCH_DOG_DELAY_TIMER_1,
710 RSI_ULP_WRITE_50, 32);
711 if (ret < 0)
712 goto fail;
713 ret = usb_ulp_read_write(adapter, RSI_WATCH_DOG_DELAY_TIMER_2,
714 RSI_ULP_WRITE_0, 32);
715 if (ret < 0)
716 goto fail;
717 ret = usb_ulp_read_write(adapter, RSI_WATCH_DOG_TIMER_ENABLE,
718 RSI_ULP_TIMER_ENABLE, 32);
719 if (ret < 0)
720 goto fail;
722 rsi_dbg(INFO_ZONE, "Reset card done\n");
723 return ret;
725 fail:
726 rsi_dbg(ERR_ZONE, "Reset card failed\n");
727 return ret;
731 * rsi_probe() - This function is called by kernel when the driver provided
732 * Vendor and device IDs are matched. All the initialization
733 * work is done here.
734 * @pfunction: Pointer to the USB interface structure.
735 * @id: Pointer to the usb_device_id structure.
737 * Return: 0 on success, a negative error code on failure.
739 static int rsi_probe(struct usb_interface *pfunction,
740 const struct usb_device_id *id)
742 struct rsi_hw *adapter;
743 struct rsi_91x_usbdev *dev;
744 u16 fw_status;
745 int status;
747 rsi_dbg(INIT_ZONE, "%s: Init function called\n", __func__);
749 adapter = rsi_91x_init(dev_oper_mode);
750 if (!adapter) {
751 rsi_dbg(ERR_ZONE, "%s: Failed to init os intf ops\n",
752 __func__);
753 return -ENOMEM;
755 adapter->rsi_host_intf = RSI_HOST_INTF_USB;
757 status = rsi_init_usb_interface(adapter, pfunction);
758 if (status) {
759 rsi_dbg(ERR_ZONE, "%s: Failed to init usb interface\n",
760 __func__);
761 goto err;
764 rsi_dbg(ERR_ZONE, "%s: Initialized os intf ops\n", __func__);
766 dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
768 status = rsi_usb_reg_read(dev->usbdev, FW_STATUS_REG, &fw_status, 2);
769 if (status < 0)
770 goto err1;
771 else
772 fw_status &= 1;
774 if (!fw_status) {
775 rsi_dbg(INIT_ZONE, "Loading firmware...\n");
776 status = rsi_hal_device_init(adapter);
777 if (status) {
778 rsi_dbg(ERR_ZONE, "%s: Failed in device init\n",
779 __func__);
780 goto err1;
782 rsi_dbg(INIT_ZONE, "%s: Device Init Done\n", __func__);
785 status = rsi_rx_urb_submit(adapter, WLAN_EP);
786 if (status)
787 goto err1;
789 if (adapter->priv->coex_mode > 1) {
790 status = rsi_rx_urb_submit(adapter, BT_EP);
791 if (status)
792 goto err1;
795 return 0;
796 err1:
797 rsi_deinit_usb_interface(adapter);
798 err:
799 rsi_91x_deinit(adapter);
800 rsi_dbg(ERR_ZONE, "%s: Failed in probe...Exiting\n", __func__);
801 return status;
805 * rsi_disconnect() - This function performs the reverse of the probe function,
806 * it deinitialize the driver structure.
807 * @pfunction: Pointer to the USB interface structure.
809 * Return: None.
811 static void rsi_disconnect(struct usb_interface *pfunction)
813 struct rsi_hw *adapter = usb_get_intfdata(pfunction);
815 if (!adapter)
816 return;
818 rsi_mac80211_detach(adapter);
819 rsi_reset_card(adapter);
820 rsi_deinit_usb_interface(adapter);
821 rsi_91x_deinit(adapter);
823 rsi_dbg(INFO_ZONE, "%s: Deinitialization completed\n", __func__);
826 #ifdef CONFIG_PM
827 static int rsi_suspend(struct usb_interface *intf, pm_message_t message)
829 /* Not yet implemented */
830 return -ENOSYS;
833 static int rsi_resume(struct usb_interface *intf)
835 /* Not yet implemented */
836 return -ENOSYS;
838 #endif
840 static const struct usb_device_id rsi_dev_table[] = {
841 { USB_DEVICE(RSI_USB_VID_9113, RSI_USB_PID_9113) },
842 { /* Blank */},
845 static struct usb_driver rsi_driver = {
846 .name = "RSI-USB WLAN",
847 .probe = rsi_probe,
848 .disconnect = rsi_disconnect,
849 .id_table = rsi_dev_table,
850 #ifdef CONFIG_PM
851 .suspend = rsi_suspend,
852 .resume = rsi_resume,
853 #endif
856 module_usb_driver(rsi_driver);
858 MODULE_AUTHOR("Redpine Signals Inc");
859 MODULE_DESCRIPTION("Common USB layer for RSI drivers");
860 MODULE_SUPPORTED_DEVICE("RSI-91x");
861 MODULE_DEVICE_TABLE(usb, rsi_dev_table);
862 MODULE_FIRMWARE(FIRMWARE_RSI9113);
863 MODULE_VERSION("0.1");
864 MODULE_LICENSE("Dual BSD/GPL");