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 <linux/types.h>
20 #include <net/rsi_91x.h>
25 /* Default operating mode is wlan STA + BT */
26 static u16 dev_oper_mode
= DEV_OPMODE_STA_BT_DUAL
;
27 module_param(dev_oper_mode
, ushort
, 0444);
28 MODULE_PARM_DESC(dev_oper_mode
,
29 "1[Wi-Fi], 4[BT], 8[BT LE], 5[Wi-Fi STA + BT classic]\n"
30 "9[Wi-Fi STA + BT LE], 13[Wi-Fi STA + BT classic + BT LE]\n"
31 "6[AP + BT classic], 14[AP + BT classic + BT LE]");
33 static int rsi_rx_urb_submit(struct rsi_hw
*adapter
, u8 ep_num
, gfp_t flags
);
36 * rsi_usb_card_write() - This function writes to the USB Card.
37 * @adapter: Pointer to the adapter structure.
38 * @buf: Pointer to the buffer from where the data has to be taken.
39 * @len: Length to be written.
40 * @endpoint: Type of endpoint.
42 * Return: status: 0 on success, a negative error code on failure.
44 static int rsi_usb_card_write(struct rsi_hw
*adapter
,
49 struct rsi_91x_usbdev
*dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
51 u8
*seg
= dev
->tx_buffer
;
53 int ep
= dev
->bulkout_endpoint_addr
[endpoint
- 1];
55 memset(seg
, 0, len
+ RSI_USB_TX_HEAD_ROOM
);
56 memcpy(seg
+ RSI_USB_TX_HEAD_ROOM
, buf
, len
);
57 len
+= RSI_USB_TX_HEAD_ROOM
;
59 status
= usb_bulk_msg(dev
->usbdev
,
60 usb_sndbulkpipe(dev
->usbdev
, ep
),
68 "Card write failed with error code :%10d\n", status
);
75 * rsi_write_multiple() - This function writes multiple bytes of information
77 * @adapter: Pointer to the adapter structure.
78 * @endpoint: Type of endpoint.
79 * @data: Pointer to the data that has to be written.
80 * @count: Number of multiple bytes to be written.
82 * Return: 0 on success, a negative error code on failure.
84 static int rsi_write_multiple(struct rsi_hw
*adapter
,
89 struct rsi_91x_usbdev
*dev
;
97 dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
101 return rsi_usb_card_write(adapter
, data
, count
, endpoint
);
105 * rsi_find_bulk_in_and_out_endpoints() - This function initializes the bulk
106 * endpoints to the device.
107 * @interface: Pointer to the USB interface structure.
108 * @adapter: Pointer to the adapter structure.
110 * Return: ret_val: 0 on success, -ENOMEM on failure.
112 static int rsi_find_bulk_in_and_out_endpoints(struct usb_interface
*interface
,
113 struct rsi_hw
*adapter
)
115 struct rsi_91x_usbdev
*dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
116 struct usb_host_interface
*iface_desc
;
117 struct usb_endpoint_descriptor
*endpoint
;
119 int ii
, bin_found
= 0, bout_found
= 0;
121 iface_desc
= interface
->cur_altsetting
;
123 for (ii
= 0; ii
< iface_desc
->desc
.bNumEndpoints
; ++ii
) {
124 endpoint
= &(iface_desc
->endpoint
[ii
].desc
);
126 if (!dev
->bulkin_endpoint_addr
[bin_found
] &&
127 (endpoint
->bEndpointAddress
& USB_DIR_IN
) &&
128 ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) ==
129 USB_ENDPOINT_XFER_BULK
)) {
130 buffer_size
= endpoint
->wMaxPacketSize
;
131 dev
->bulkin_size
[bin_found
] = buffer_size
;
132 dev
->bulkin_endpoint_addr
[bin_found
] =
133 endpoint
->bEndpointAddress
;
137 if (!dev
->bulkout_endpoint_addr
[bout_found
] &&
138 !(endpoint
->bEndpointAddress
& USB_DIR_IN
) &&
139 ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) ==
140 USB_ENDPOINT_XFER_BULK
)) {
141 buffer_size
= endpoint
->wMaxPacketSize
;
142 dev
->bulkout_endpoint_addr
[bout_found
] =
143 endpoint
->bEndpointAddress
;
144 dev
->bulkout_size
[bout_found
] = buffer_size
;
148 if (bin_found
>= MAX_BULK_EP
|| bout_found
>= MAX_BULK_EP
)
152 if (!(dev
->bulkin_endpoint_addr
[0] && dev
->bulkout_endpoint_addr
[0])) {
153 dev_err(&interface
->dev
, "missing wlan bulk endpoints\n");
157 if (adapter
->priv
->coex_mode
> 1) {
158 if (!dev
->bulkin_endpoint_addr
[1]) {
159 dev_err(&interface
->dev
, "missing bt bulk-in endpoint\n");
167 #define RSI_USB_REQ_OUT (USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE)
168 #define RSI_USB_REQ_IN (USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE)
170 /* rsi_usb_reg_read() - This function reads data from given register address.
171 * @usbdev: Pointer to the usb_device structure.
172 * @reg: Address of the register to be read.
173 * @value: Value to be read.
174 * @len: length of data to be read.
176 * Return: status: 0 on success, a negative error code on failure.
178 static int rsi_usb_reg_read(struct usb_device
*usbdev
,
184 int status
= -ENOMEM
;
186 if (len
> RSI_USB_CTRL_BUF_SIZE
)
189 buf
= kmalloc(RSI_USB_CTRL_BUF_SIZE
, GFP_KERNEL
);
193 status
= usb_control_msg(usbdev
,
194 usb_rcvctrlpipe(usbdev
, 0),
195 USB_VENDOR_REGISTER_READ
,
197 ((reg
& 0xffff0000) >> 16), (reg
& 0xffff),
200 USB_CTRL_GET_TIMEOUT
);
202 *value
= (buf
[0] | (buf
[1] << 8));
205 "%s: Reg read failed with error code :%d\n",
214 * rsi_usb_reg_write() - This function writes the given data into the given
216 * @usbdev: Pointer to the usb_device structure.
217 * @reg: Address of the register.
218 * @value: Value to write.
219 * @len: Length of data to be written.
221 * Return: status: 0 on success, a negative error code on failure.
223 static int rsi_usb_reg_write(struct usb_device
*usbdev
,
229 int status
= -ENOMEM
;
231 if (len
> RSI_USB_CTRL_BUF_SIZE
)
234 usb_reg_buf
= kmalloc(RSI_USB_CTRL_BUF_SIZE
, GFP_KERNEL
);
238 usb_reg_buf
[0] = (cpu_to_le32(value
) & 0x00ff);
239 usb_reg_buf
[1] = (cpu_to_le32(value
) & 0xff00) >> 8;
240 usb_reg_buf
[2] = (cpu_to_le32(value
) & 0x00ff0000) >> 16;
241 usb_reg_buf
[3] = (cpu_to_le32(value
) & 0xff000000) >> 24;
243 status
= usb_control_msg(usbdev
,
244 usb_sndctrlpipe(usbdev
, 0),
245 USB_VENDOR_REGISTER_WRITE
,
247 ((cpu_to_le32(reg
) & 0xffff0000) >> 16),
248 (cpu_to_le32(reg
) & 0xffff),
251 USB_CTRL_SET_TIMEOUT
);
254 "%s: Reg write failed with error code :%d\n",
263 * rsi_rx_done_handler() - This function is called when a packet is received
264 * from USB stack. This is callback to receive done.
265 * @urb: Received URB.
269 static void rsi_rx_done_handler(struct urb
*urb
)
271 struct rx_usb_ctrl_block
*rx_cb
= urb
->context
;
272 struct rsi_91x_usbdev
*dev
= (struct rsi_91x_usbdev
*)rx_cb
->data
;
273 int status
= -EINVAL
;
276 dev_kfree_skb(rx_cb
->rx_skb
);
280 if (urb
->actual_length
<= 0 ||
281 urb
->actual_length
> rx_cb
->rx_skb
->len
) {
282 rsi_dbg(INFO_ZONE
, "%s: Invalid packet length = %d\n",
283 __func__
, urb
->actual_length
);
286 if (skb_queue_len(&dev
->rx_q
) >= RSI_MAX_RX_PKTS
) {
287 rsi_dbg(INFO_ZONE
, "Max RX packets reached\n");
290 skb_trim(rx_cb
->rx_skb
, urb
->actual_length
);
291 skb_queue_tail(&dev
->rx_q
, rx_cb
->rx_skb
);
293 rsi_set_event(&dev
->rx_thread
.event
);
297 if (rsi_rx_urb_submit(dev
->priv
, rx_cb
->ep_num
, GFP_ATOMIC
))
298 rsi_dbg(ERR_ZONE
, "%s: Failed in urb submission", __func__
);
301 dev_kfree_skb(rx_cb
->rx_skb
);
304 static void rsi_rx_urb_kill(struct rsi_hw
*adapter
, u8 ep_num
)
306 struct rsi_91x_usbdev
*dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
307 struct rx_usb_ctrl_block
*rx_cb
= &dev
->rx_cb
[ep_num
- 1];
308 struct urb
*urb
= rx_cb
->rx_urb
;
314 * rsi_rx_urb_submit() - This function submits the given URB to the USB stack.
315 * @adapter: Pointer to the adapter structure.
316 * @ep_num: Endpoint number.
317 * @mem_flags: The type of memory to allocate.
319 * Return: 0 on success, a negative error code on failure.
321 static int rsi_rx_urb_submit(struct rsi_hw
*adapter
, u8 ep_num
, gfp_t mem_flags
)
323 struct rsi_91x_usbdev
*dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
324 struct rx_usb_ctrl_block
*rx_cb
= &dev
->rx_cb
[ep_num
- 1];
325 struct urb
*urb
= rx_cb
->rx_urb
;
328 u8 dword_align_bytes
= 0;
330 #define RSI_MAX_RX_USB_PKT_SIZE 3000
331 skb
= dev_alloc_skb(RSI_MAX_RX_USB_PKT_SIZE
);
334 skb_reserve(skb
, MAX_DWORD_ALIGN_BYTES
);
335 skb_put(skb
, RSI_MAX_RX_USB_PKT_SIZE
- MAX_DWORD_ALIGN_BYTES
);
336 dword_align_bytes
= (unsigned long)skb
->data
& 0x3f;
337 if (dword_align_bytes
> 0)
338 skb_push(skb
, dword_align_bytes
);
339 urb
->transfer_buffer
= skb
->data
;
342 usb_fill_bulk_urb(urb
,
344 usb_rcvbulkpipe(dev
->usbdev
,
345 dev
->bulkin_endpoint_addr
[ep_num
- 1]),
346 urb
->transfer_buffer
,
351 status
= usb_submit_urb(urb
, mem_flags
);
353 rsi_dbg(ERR_ZONE
, "%s: Failed in urb submission\n", __func__
);
360 static int rsi_usb_read_register_multiple(struct rsi_hw
*adapter
, u32 addr
,
363 struct rsi_91x_usbdev
*dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
371 buf
= kzalloc(RSI_USB_BUF_SIZE
, GFP_KERNEL
);
376 transfer
= min_t(u16
, count
, RSI_USB_BUF_SIZE
);
377 status
= usb_control_msg(dev
->usbdev
,
378 usb_rcvctrlpipe(dev
->usbdev
, 0),
379 USB_VENDOR_REGISTER_READ
,
381 ((addr
& 0xffff0000) >> 16),
382 (addr
& 0xffff), (void *)buf
,
383 transfer
, USB_CTRL_GET_TIMEOUT
);
386 "Reg read failed with error code :%d\n",
391 memcpy(data
, buf
, transfer
);
401 * rsi_usb_write_register_multiple() - This function writes multiple bytes of
402 * information to multiple registers.
403 * @adapter: Pointer to the adapter structure.
404 * @addr: Address of the register.
405 * @data: Pointer to the data that has to be written.
406 * @count: Number of multiple bytes to be written on to the registers.
408 * Return: status: 0 on success, a negative error code on failure.
410 static int rsi_usb_write_register_multiple(struct rsi_hw
*adapter
, u32 addr
,
413 struct rsi_91x_usbdev
*dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
418 buf
= kzalloc(RSI_USB_BUF_SIZE
, GFP_KERNEL
);
423 transfer
= min_t(u16
, count
, RSI_USB_BUF_SIZE
);
424 memcpy(buf
, data
, transfer
);
425 status
= usb_control_msg(dev
->usbdev
,
426 usb_sndctrlpipe(dev
->usbdev
, 0),
427 USB_VENDOR_REGISTER_WRITE
,
429 ((addr
& 0xffff0000) >> 16),
433 USB_CTRL_SET_TIMEOUT
);
436 "Reg write failed with error code :%d\n",
451 *rsi_usb_host_intf_write_pkt() - This function writes the packet to the
453 * @adapter: Pointer to the adapter structure.
454 * @pkt: Pointer to the data to be written on to the card.
455 * @len: Length of the data to be written on to the card.
457 * Return: 0 on success, a negative error code on failure.
459 static int rsi_usb_host_intf_write_pkt(struct rsi_hw
*adapter
,
463 u32 queueno
= ((pkt
[1] >> 4) & 0x7);
466 endpoint
= ((queueno
== RSI_WIFI_MGMT_Q
|| queueno
== RSI_WIFI_DATA_Q
||
467 queueno
== RSI_COEX_Q
) ? WLAN_EP
: BT_EP
);
469 return rsi_write_multiple(adapter
,
475 static int rsi_usb_master_reg_read(struct rsi_hw
*adapter
, u32 reg
,
478 struct usb_device
*usbdev
=
479 ((struct rsi_91x_usbdev
*)adapter
->rsi_dev
)->usbdev
;
483 ret
= rsi_usb_reg_read(usbdev
, reg
, &temp
, len
);
491 static int rsi_usb_master_reg_write(struct rsi_hw
*adapter
,
493 unsigned long value
, u16 len
)
495 struct usb_device
*usbdev
=
496 ((struct rsi_91x_usbdev
*)adapter
->rsi_dev
)->usbdev
;
498 return rsi_usb_reg_write(usbdev
, reg
, value
, len
);
501 static int rsi_usb_load_data_master_write(struct rsi_hw
*adapter
,
503 u32 instructions_sz
, u16 block_size
,
511 num_blocks
= instructions_sz
/ block_size
;
512 rsi_dbg(INFO_ZONE
, "num_blocks: %d\n", num_blocks
);
514 for (cur_indx
= 0, i
= 0; i
< num_blocks
; i
++, cur_indx
+= block_size
) {
515 memcpy(temp_buf
, ta_firmware
+ cur_indx
, block_size
);
516 status
= rsi_usb_write_register_multiple(adapter
, base_address
,
522 rsi_dbg(INFO_ZONE
, "%s: loading block: %d\n", __func__
, i
);
523 base_address
+= block_size
;
526 if (instructions_sz
% block_size
) {
527 memset(temp_buf
, 0, block_size
);
528 memcpy(temp_buf
, ta_firmware
+ cur_indx
,
529 instructions_sz
% block_size
);
530 status
= rsi_usb_write_register_multiple
531 (adapter
, base_address
,
533 instructions_sz
% block_size
);
537 "Written Last Block in Address 0x%x Successfully\n",
543 static struct rsi_host_intf_ops usb_host_intf_ops
= {
544 .write_pkt
= rsi_usb_host_intf_write_pkt
,
545 .read_reg_multiple
= rsi_usb_read_register_multiple
,
546 .write_reg_multiple
= rsi_usb_write_register_multiple
,
547 .master_reg_read
= rsi_usb_master_reg_read
,
548 .master_reg_write
= rsi_usb_master_reg_write
,
549 .load_data_master_write
= rsi_usb_load_data_master_write
,
553 * rsi_deinit_usb_interface() - This function deinitializes the usb interface.
554 * @adapter: Pointer to the adapter structure.
558 static void rsi_deinit_usb_interface(struct rsi_hw
*adapter
)
560 struct rsi_91x_usbdev
*dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
562 rsi_kill_thread(&dev
->rx_thread
);
564 usb_free_urb(dev
->rx_cb
[0].rx_urb
);
565 if (adapter
->priv
->coex_mode
> 1)
566 usb_free_urb(dev
->rx_cb
[1].rx_urb
);
568 kfree(dev
->tx_buffer
);
571 static int rsi_usb_init_rx(struct rsi_hw
*adapter
)
573 struct rsi_91x_usbdev
*dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
574 struct rx_usb_ctrl_block
*rx_cb
;
577 num_rx_cb
= (adapter
->priv
->coex_mode
> 1 ? 2 : 1);
579 for (idx
= 0; idx
< num_rx_cb
; idx
++) {
580 rx_cb
= &dev
->rx_cb
[idx
];
582 rx_cb
->rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
583 if (!rx_cb
->rx_urb
) {
584 rsi_dbg(ERR_ZONE
, "Failed alloc rx urb[%d]\n", idx
);
587 rx_cb
->ep_num
= idx
+ 1;
588 rx_cb
->data
= (void *)dev
;
590 skb_queue_head_init(&dev
->rx_q
);
591 rsi_init_event(&dev
->rx_thread
.event
);
592 if (rsi_create_kthread(adapter
->priv
, &dev
->rx_thread
,
593 rsi_usb_rx_thread
, "RX-Thread")) {
594 rsi_dbg(ERR_ZONE
, "%s: Unable to init rx thrd\n", __func__
);
601 usb_free_urb(dev
->rx_cb
[0].rx_urb
);
602 if (adapter
->priv
->coex_mode
> 1)
603 usb_free_urb(dev
->rx_cb
[1].rx_urb
);
609 * rsi_init_usb_interface() - This function initializes the usb interface.
610 * @adapter: Pointer to the adapter structure.
611 * @pfunction: Pointer to USB interface structure.
613 * Return: 0 on success, a negative error code on failure.
615 static int rsi_init_usb_interface(struct rsi_hw
*adapter
,
616 struct usb_interface
*pfunction
)
618 struct rsi_91x_usbdev
*rsi_dev
;
621 rsi_dev
= kzalloc(sizeof(*rsi_dev
), GFP_KERNEL
);
625 adapter
->rsi_dev
= rsi_dev
;
626 rsi_dev
->usbdev
= interface_to_usbdev(pfunction
);
627 rsi_dev
->priv
= (void *)adapter
;
629 if (rsi_find_bulk_in_and_out_endpoints(pfunction
, adapter
)) {
634 adapter
->device
= &pfunction
->dev
;
635 usb_set_intfdata(pfunction
, adapter
);
637 rsi_dev
->tx_buffer
= kmalloc(2048, GFP_KERNEL
);
638 if (!rsi_dev
->tx_buffer
) {
643 if (rsi_usb_init_rx(adapter
)) {
644 rsi_dbg(ERR_ZONE
, "Failed to init RX handle\n");
649 rsi_dev
->tx_blk_size
= 252;
650 adapter
->block_size
= rsi_dev
->tx_blk_size
;
652 /* Initializing function callbacks */
653 adapter
->check_hw_queue_status
= rsi_usb_check_queue_status
;
654 adapter
->determine_event_timeout
= rsi_usb_event_timeout
;
655 adapter
->rsi_host_intf
= RSI_HOST_INTF_USB
;
656 adapter
->host_intf_ops
= &usb_host_intf_ops
;
658 #ifdef CONFIG_RSI_DEBUGFS
659 /* In USB, one less than the MAX_DEBUGFS_ENTRIES entries is required */
660 adapter
->num_debugfs_entries
= (MAX_DEBUGFS_ENTRIES
- 1);
663 rsi_dbg(INIT_ZONE
, "%s: Enabled the interface\n", __func__
);
667 kfree(rsi_dev
->tx_buffer
);
674 static int usb_ulp_read_write(struct rsi_hw
*adapter
, u16 addr
, u32 data
,
679 ret
= rsi_usb_master_reg_write
680 (adapter
, RSI_GSPI_DATA_REG1
,
681 ((addr
<< 6) | ((data
>> 16) & 0xffff)), 2);
685 ret
= rsi_usb_master_reg_write(adapter
, RSI_GSPI_DATA_REG0
,
690 /* Initializing GSPI for ULP read/writes */
691 rsi_usb_master_reg_write(adapter
, RSI_GSPI_CTRL_REG0
,
692 RSI_GSPI_CTRL_REG0_VALUE
, 2);
694 ret
= rsi_usb_master_reg_write(adapter
, RSI_GSPI_CTRL_REG1
,
695 ((len_in_bits
- 1) | RSI_GSPI_TRIG
), 2);
704 static int rsi_reset_card(struct rsi_hw
*adapter
)
708 rsi_dbg(INFO_ZONE
, "Resetting Card...\n");
709 rsi_usb_master_reg_write(adapter
, RSI_TA_HOLD_REG
, 0xE, 4);
711 /* This msleep will ensure Thread-Arch processor to go to hold
712 * and any pending dma transfers to rf in device to finish.
716 ret
= rsi_usb_master_reg_write(adapter
, SWBL_REGOUT
,
717 RSI_FW_WDT_DISABLE_REQ
,
718 RSI_COMMON_REG_SIZE
);
720 rsi_dbg(ERR_ZONE
, "Disabling firmware watchdog timer failed\n");
724 if (adapter
->device_model
!= RSI_DEV_9116
) {
725 ret
= usb_ulp_read_write(adapter
, RSI_WATCH_DOG_TIMER_1
,
726 RSI_ULP_WRITE_2
, 32);
729 ret
= usb_ulp_read_write(adapter
, RSI_WATCH_DOG_TIMER_2
,
730 RSI_ULP_WRITE_0
, 32);
733 ret
= usb_ulp_read_write(adapter
, RSI_WATCH_DOG_DELAY_TIMER_1
,
734 RSI_ULP_WRITE_50
, 32);
737 ret
= usb_ulp_read_write(adapter
, RSI_WATCH_DOG_DELAY_TIMER_2
,
738 RSI_ULP_WRITE_0
, 32);
741 ret
= usb_ulp_read_write(adapter
, RSI_WATCH_DOG_TIMER_ENABLE
,
742 RSI_ULP_TIMER_ENABLE
, 32);
746 ret
= rsi_usb_master_reg_write(adapter
,
747 NWP_WWD_INTERRUPT_TIMER
,
748 NWP_WWD_INT_TIMER_CLKS
,
752 ret
= rsi_usb_master_reg_write(adapter
,
753 NWP_WWD_SYSTEM_RESET_TIMER
,
754 NWP_WWD_SYS_RESET_TIMER_CLKS
,
758 ret
= rsi_usb_master_reg_write(adapter
,
759 NWP_WWD_MODE_AND_RSTART
,
760 NWP_WWD_TIMER_DISABLE
,
766 rsi_dbg(INFO_ZONE
, "Reset card done\n");
770 rsi_dbg(ERR_ZONE
, "Reset card failed\n");
775 * rsi_probe() - This function is called by kernel when the driver provided
776 * Vendor and device IDs are matched. All the initialization
778 * @pfunction: Pointer to the USB interface structure.
779 * @id: Pointer to the usb_device_id structure.
781 * Return: 0 on success, a negative error code on failure.
783 static int rsi_probe(struct usb_interface
*pfunction
,
784 const struct usb_device_id
*id
)
786 struct rsi_hw
*adapter
;
787 struct rsi_91x_usbdev
*dev
;
791 rsi_dbg(INIT_ZONE
, "%s: Init function called\n", __func__
);
793 adapter
= rsi_91x_init(dev_oper_mode
);
795 rsi_dbg(ERR_ZONE
, "%s: Failed to init os intf ops\n",
799 adapter
->rsi_host_intf
= RSI_HOST_INTF_USB
;
801 status
= rsi_init_usb_interface(adapter
, pfunction
);
803 rsi_dbg(ERR_ZONE
, "%s: Failed to init usb interface\n",
808 rsi_dbg(ERR_ZONE
, "%s: Initialized os intf ops\n", __func__
);
810 if (id
->idProduct
== RSI_USB_PID_9113
) {
811 rsi_dbg(INIT_ZONE
, "%s: 9113 module detected\n", __func__
);
812 adapter
->device_model
= RSI_DEV_9113
;
813 } else if (id
->idProduct
== RSI_USB_PID_9116
) {
814 rsi_dbg(INIT_ZONE
, "%s: 9116 module detected\n", __func__
);
815 adapter
->device_model
= RSI_DEV_9116
;
817 rsi_dbg(ERR_ZONE
, "%s: Unsupported RSI device id 0x%x\n",
818 __func__
, id
->idProduct
);
822 dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
824 status
= rsi_usb_reg_read(dev
->usbdev
, FW_STATUS_REG
, &fw_status
, 2);
831 rsi_dbg(INIT_ZONE
, "Loading firmware...\n");
832 status
= rsi_hal_device_init(adapter
);
834 rsi_dbg(ERR_ZONE
, "%s: Failed in device init\n",
838 rsi_dbg(INIT_ZONE
, "%s: Device Init Done\n", __func__
);
841 status
= rsi_rx_urb_submit(adapter
, WLAN_EP
, GFP_KERNEL
);
845 if (adapter
->priv
->coex_mode
> 1) {
846 status
= rsi_rx_urb_submit(adapter
, BT_EP
, GFP_KERNEL
);
848 goto err_kill_wlan_urb
;
854 rsi_rx_urb_kill(adapter
, WLAN_EP
);
856 rsi_deinit_usb_interface(adapter
);
858 rsi_91x_deinit(adapter
);
859 rsi_dbg(ERR_ZONE
, "%s: Failed in probe...Exiting\n", __func__
);
864 * rsi_disconnect() - This function performs the reverse of the probe function,
865 * it deinitialize the driver structure.
866 * @pfunction: Pointer to the USB interface structure.
870 static void rsi_disconnect(struct usb_interface
*pfunction
)
872 struct rsi_hw
*adapter
= usb_get_intfdata(pfunction
);
877 rsi_mac80211_detach(adapter
);
879 if (IS_ENABLED(CONFIG_RSI_COEX
) && adapter
->priv
->coex_mode
> 1 &&
880 adapter
->priv
->bt_adapter
) {
881 rsi_bt_ops
.detach(adapter
->priv
->bt_adapter
);
882 adapter
->priv
->bt_adapter
= NULL
;
885 if (adapter
->priv
->coex_mode
> 1)
886 rsi_rx_urb_kill(adapter
, BT_EP
);
887 rsi_rx_urb_kill(adapter
, WLAN_EP
);
889 rsi_reset_card(adapter
);
890 rsi_deinit_usb_interface(adapter
);
891 rsi_91x_deinit(adapter
);
893 rsi_dbg(INFO_ZONE
, "%s: Deinitialization completed\n", __func__
);
897 static int rsi_suspend(struct usb_interface
*intf
, pm_message_t message
)
899 /* Not yet implemented */
903 static int rsi_resume(struct usb_interface
*intf
)
905 /* Not yet implemented */
910 static const struct usb_device_id rsi_dev_table
[] = {
911 { USB_DEVICE(RSI_USB_VENDOR_ID
, RSI_USB_PID_9113
) },
912 { USB_DEVICE(RSI_USB_VENDOR_ID
, RSI_USB_PID_9116
) },
916 static struct usb_driver rsi_driver
= {
917 .name
= "RSI-USB WLAN",
919 .disconnect
= rsi_disconnect
,
920 .id_table
= rsi_dev_table
,
922 .suspend
= rsi_suspend
,
923 .resume
= rsi_resume
,
927 module_usb_driver(rsi_driver
);
929 MODULE_AUTHOR("Redpine Signals Inc");
930 MODULE_DESCRIPTION("Common USB layer for RSI drivers");
931 MODULE_SUPPORTED_DEVICE("RSI-91x");
932 MODULE_DEVICE_TABLE(usb
, rsi_dev_table
);
933 MODULE_FIRMWARE(FIRMWARE_RSI9113
);
934 MODULE_VERSION("0.1");
935 MODULE_LICENSE("Dual BSD/GPL");