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>
20 #include "rsi_common.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]");
33 * rsi_sdio_set_cmd52_arg() - This function prepares cmd 52 read/write arg.
35 * @func: function number
36 * @raw: indicates whether to perform read after write
37 * @address: address to which to read/write
38 * @writedata: data to write
42 static u32
rsi_sdio_set_cmd52_arg(bool rw
,
48 return ((rw
& 1) << 31) | ((func
& 0x7) << 28) |
49 ((raw
& 1) << 27) | (1 << 26) |
50 ((address
& 0x1FFFF) << 9) | (1 << 8) |
55 * rsi_cmd52writebyte() - This function issues cmd52 byte write onto the card.
56 * @card: Pointer to the mmc_card.
57 * @address: Address to write.
58 * @byte: Data to write.
60 * Return: Write status.
62 static int rsi_cmd52writebyte(struct mmc_card
*card
,
66 struct mmc_command io_cmd
;
69 memset(&io_cmd
, 0, sizeof(io_cmd
));
70 arg
= rsi_sdio_set_cmd52_arg(1, 0, 0, address
, byte
);
71 io_cmd
.opcode
= SD_IO_RW_DIRECT
;
73 io_cmd
.flags
= MMC_RSP_R5
| MMC_CMD_AC
;
75 return mmc_wait_for_cmd(card
->host
, &io_cmd
, 0);
79 * rsi_cmd52readbyte() - This function issues cmd52 byte read onto the card.
80 * @card: Pointer to the mmc_card.
81 * @address: Address to read from.
82 * @byte: Variable to store read value.
84 * Return: Read status.
86 static int rsi_cmd52readbyte(struct mmc_card
*card
,
90 struct mmc_command io_cmd
;
94 memset(&io_cmd
, 0, sizeof(io_cmd
));
95 arg
= rsi_sdio_set_cmd52_arg(0, 0, 0, address
, 0);
96 io_cmd
.opcode
= SD_IO_RW_DIRECT
;
98 io_cmd
.flags
= MMC_RSP_R5
| MMC_CMD_AC
;
100 err
= mmc_wait_for_cmd(card
->host
, &io_cmd
, 0);
101 if ((!err
) && (byte
))
102 *byte
= io_cmd
.resp
[0] & 0xFF;
107 * rsi_issue_sdiocommand() - This function issues sdio commands.
108 * @func: Pointer to the sdio_func structure.
109 * @opcode: Opcode value.
110 * @arg: Arguments to pass.
111 * @flags: Flags which are set.
112 * @resp: Pointer to store response.
114 * Return: err: command status as 0 or -1.
116 static int rsi_issue_sdiocommand(struct sdio_func
*func
,
122 struct mmc_command cmd
;
123 struct mmc_host
*host
;
126 host
= func
->card
->host
;
128 memset(&cmd
, 0, sizeof(struct mmc_command
));
132 err
= mmc_wait_for_cmd(host
, &cmd
, 3);
134 if ((!err
) && (resp
))
141 * rsi_handle_interrupt() - This function is called upon the occurence
143 * @function: Pointer to the sdio_func structure.
147 static void rsi_handle_interrupt(struct sdio_func
*function
)
149 struct rsi_hw
*adapter
= sdio_get_drvdata(function
);
150 struct rsi_91x_sdiodev
*dev
=
151 (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
153 if (adapter
->priv
->fsm_state
== FSM_FW_NOT_LOADED
)
156 dev
->sdio_irq_task
= current
;
157 rsi_interrupt_handler(adapter
);
158 dev
->sdio_irq_task
= NULL
;
162 * rsi_reset_card() - This function resets and re-initializes the card.
163 * @pfunction: Pointer to the sdio_func structure.
167 static void rsi_reset_card(struct sdio_func
*pfunction
)
171 struct mmc_card
*card
= pfunction
->card
;
172 struct mmc_host
*host
= card
->host
;
177 /* Reset 9110 chip */
178 ret
= rsi_cmd52writebyte(pfunction
->card
,
182 /* Card will not send any response as it is getting reset immediately
183 * Hence expect a timeout status from host controller
185 if (ret
!= -ETIMEDOUT
)
186 rsi_dbg(ERR_ZONE
, "%s: Reset failed : %d\n", __func__
, ret
);
188 /* Wait for few milli seconds to get rid of residue charges if any */
191 /* Initialize the SDIO card */
192 host
->ios
.chip_select
= MMC_CS_DONTCARE
;
193 host
->ios
.bus_mode
= MMC_BUSMODE_OPENDRAIN
;
194 host
->ios
.power_mode
= MMC_POWER_UP
;
195 host
->ios
.bus_width
= MMC_BUS_WIDTH_1
;
196 host
->ios
.timing
= MMC_TIMING_LEGACY
;
197 host
->ops
->set_ios(host
, &host
->ios
);
200 * This delay should be sufficient to allow the power supply
201 * to reach the minimum voltage.
205 host
->ios
.clock
= host
->f_min
;
206 host
->ios
.power_mode
= MMC_POWER_ON
;
207 host
->ops
->set_ios(host
, &host
->ios
);
210 * This delay must be at least 74 clock sizes, or 1 ms, or the
211 * time required to reach a stable voltage.
215 /* Issue CMD0. Goto idle state */
216 host
->ios
.chip_select
= MMC_CS_HIGH
;
217 host
->ops
->set_ios(host
, &host
->ios
);
219 err
= rsi_issue_sdiocommand(pfunction
,
222 (MMC_RSP_NONE
| MMC_CMD_BC
),
224 host
->ios
.chip_select
= MMC_CS_DONTCARE
;
225 host
->ops
->set_ios(host
, &host
->ios
);
227 host
->use_spi_crc
= 0;
230 rsi_dbg(ERR_ZONE
, "%s: CMD0 failed : %d\n", __func__
, err
);
232 /* Issue CMD5, arg = 0 */
233 err
= rsi_issue_sdiocommand(pfunction
, SD_IO_SEND_OP_COND
, 0,
234 (MMC_RSP_R4
| MMC_CMD_BCR
), &resp
);
236 rsi_dbg(ERR_ZONE
, "%s: CMD5 failed : %d\n", __func__
, err
);
239 /* Issue CMD5, arg = ocr. Wait till card is ready */
240 for (i
= 0; i
< 100; i
++) {
241 err
= rsi_issue_sdiocommand(pfunction
, SD_IO_SEND_OP_COND
,
243 (MMC_RSP_R4
| MMC_CMD_BCR
), &resp
);
245 rsi_dbg(ERR_ZONE
, "%s: CMD5 failed : %d\n",
250 if (resp
& MMC_CARD_BUSY
)
255 if ((i
== 100) || (err
)) {
256 rsi_dbg(ERR_ZONE
, "%s: card in not ready : %d %d\n",
261 /* Issue CMD3, get RCA */
262 err
= rsi_issue_sdiocommand(pfunction
,
263 SD_SEND_RELATIVE_ADDR
,
265 (MMC_RSP_R6
| MMC_CMD_BCR
),
268 rsi_dbg(ERR_ZONE
, "%s: CMD3 failed : %d\n", __func__
, err
);
272 host
->ios
.bus_mode
= MMC_BUSMODE_PUSHPULL
;
273 host
->ops
->set_ios(host
, &host
->ios
);
275 /* Issue CMD7, select card */
276 err
= rsi_issue_sdiocommand(pfunction
,
279 (MMC_RSP_R1
| MMC_CMD_AC
),
282 rsi_dbg(ERR_ZONE
, "%s: CMD7 failed : %d\n", __func__
, err
);
286 /* Enable high speed */
287 if (card
->host
->caps
& MMC_CAP_SD_HIGHSPEED
) {
288 rsi_dbg(ERR_ZONE
, "%s: Set high speed mode\n", __func__
);
289 err
= rsi_cmd52readbyte(card
, SDIO_CCCR_SPEED
, &cmd52_resp
);
291 rsi_dbg(ERR_ZONE
, "%s: CCCR speed reg read failed: %d\n",
294 err
= rsi_cmd52writebyte(card
,
296 (cmd52_resp
| SDIO_SPEED_EHS
));
299 "%s: CCR speed regwrite failed %d\n",
303 host
->ios
.timing
= MMC_TIMING_SD_HS
;
304 host
->ops
->set_ios(host
, &host
->ios
);
309 if (mmc_card_hs(card
))
312 clock
= card
->cis
.max_dtr
;
314 if (clock
> host
->f_max
)
317 host
->ios
.clock
= clock
;
318 host
->ops
->set_ios(host
, &host
->ios
);
320 if (card
->host
->caps
& MMC_CAP_4_BIT_DATA
) {
321 /* CMD52: Set bus width & disable card detect resistor */
322 err
= rsi_cmd52writebyte(card
,
324 (SDIO_BUS_CD_DISABLE
|
325 SDIO_BUS_WIDTH_4BIT
));
327 rsi_dbg(ERR_ZONE
, "%s: Set bus mode failed : %d\n",
331 host
->ios
.bus_width
= MMC_BUS_WIDTH_4
;
332 host
->ops
->set_ios(host
, &host
->ios
);
337 * rsi_setclock() - This function sets the clock frequency.
338 * @adapter: Pointer to the adapter structure.
339 * @freq: Clock frequency.
343 static void rsi_setclock(struct rsi_hw
*adapter
, u32 freq
)
345 struct rsi_91x_sdiodev
*dev
=
346 (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
347 struct mmc_host
*host
= dev
->pfunction
->card
->host
;
351 if (clock
> host
->f_max
)
353 host
->ios
.clock
= clock
;
354 host
->ops
->set_ios(host
, &host
->ios
);
358 * rsi_setblocklength() - This function sets the host block length.
359 * @adapter: Pointer to the adapter structure.
360 * @length: Block length to be set.
362 * Return: status: 0 on success, -1 on failure.
364 static int rsi_setblocklength(struct rsi_hw
*adapter
, u32 length
)
366 struct rsi_91x_sdiodev
*dev
=
367 (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
369 rsi_dbg(INIT_ZONE
, "%s: Setting the block length\n", __func__
);
371 status
= sdio_set_block_size(dev
->pfunction
, length
);
372 dev
->pfunction
->max_blksize
= 256;
373 adapter
->block_size
= dev
->pfunction
->max_blksize
;
376 "%s: Operational blk length is %d\n", __func__
, length
);
381 * rsi_setupcard() - This function queries and sets the card's features.
382 * @adapter: Pointer to the adapter structure.
384 * Return: status: 0 on success, -1 on failure.
386 static int rsi_setupcard(struct rsi_hw
*adapter
)
388 struct rsi_91x_sdiodev
*dev
=
389 (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
392 rsi_setclock(adapter
, 50000);
394 dev
->tx_blk_size
= 256;
395 status
= rsi_setblocklength(adapter
, dev
->tx_blk_size
);
398 "%s: Unable to set block length\n", __func__
);
403 * rsi_sdio_read_register() - This function reads one byte of information
405 * @adapter: Pointer to the adapter structure.
406 * @addr: Address of the register.
407 * @data: Pointer to the data that stores the data read.
409 * Return: 0 on success, -1 on failure.
411 int rsi_sdio_read_register(struct rsi_hw
*adapter
,
415 struct rsi_91x_sdiodev
*dev
=
416 (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
420 if (likely(dev
->sdio_irq_task
!= current
))
421 sdio_claim_host(dev
->pfunction
);
424 *data
= sdio_f0_readb(dev
->pfunction
, addr
, &status
);
426 *data
= sdio_readb(dev
->pfunction
, addr
, &status
);
428 if (likely(dev
->sdio_irq_task
!= current
))
429 sdio_release_host(dev
->pfunction
);
435 * rsi_sdio_write_register() - This function writes one byte of information
437 * @adapter: Pointer to the adapter structure.
438 * @function: Function Number.
439 * @addr: Address of the register.
440 * @data: Pointer to the data tha has to be written.
442 * Return: 0 on success, -1 on failure.
444 int rsi_sdio_write_register(struct rsi_hw
*adapter
,
449 struct rsi_91x_sdiodev
*dev
=
450 (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
453 if (likely(dev
->sdio_irq_task
!= current
))
454 sdio_claim_host(dev
->pfunction
);
457 sdio_f0_writeb(dev
->pfunction
, *data
, addr
, &status
);
459 sdio_writeb(dev
->pfunction
, *data
, addr
, &status
);
461 if (likely(dev
->sdio_irq_task
!= current
))
462 sdio_release_host(dev
->pfunction
);
468 * rsi_sdio_ack_intr() - This function acks the interrupt received.
469 * @adapter: Pointer to the adapter structure.
470 * @int_bit: Interrupt bit to write into register.
474 void rsi_sdio_ack_intr(struct rsi_hw
*adapter
, u8 int_bit
)
477 status
= rsi_sdio_write_register(adapter
,
479 (SDIO_FUN1_INTR_CLR_REG
|
480 RSI_SD_REQUEST_MASTER
),
483 rsi_dbg(ERR_ZONE
, "%s: unable to send ack\n", __func__
);
489 * rsi_sdio_read_register_multiple() - This function read multiple bytes of
490 * information from the SD card.
491 * @adapter: Pointer to the adapter structure.
492 * @addr: Address of the register.
493 * @count: Number of multiple bytes to be read.
494 * @data: Pointer to the read data.
496 * Return: 0 on success, -1 on failure.
498 static int rsi_sdio_read_register_multiple(struct rsi_hw
*adapter
,
503 struct rsi_91x_sdiodev
*dev
=
504 (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
507 if (likely(dev
->sdio_irq_task
!= current
))
508 sdio_claim_host(dev
->pfunction
);
510 status
= sdio_readsb(dev
->pfunction
, data
, addr
, count
);
512 if (likely(dev
->sdio_irq_task
!= current
))
513 sdio_release_host(dev
->pfunction
);
516 rsi_dbg(ERR_ZONE
, "%s: Synch Cmd53 read failed\n", __func__
);
521 * rsi_sdio_write_register_multiple() - This function writes multiple bytes of
522 * information to the SD card.
523 * @adapter: Pointer to the adapter structure.
524 * @addr: Address of the register.
525 * @data: Pointer to the data that has to be written.
526 * @count: Number of multiple bytes to be written.
528 * Return: 0 on success, -1 on failure.
530 int rsi_sdio_write_register_multiple(struct rsi_hw
*adapter
,
535 struct rsi_91x_sdiodev
*dev
=
536 (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
539 if (dev
->write_fail
> 1) {
540 rsi_dbg(ERR_ZONE
, "%s: Stopping card writes\n", __func__
);
542 } else if (dev
->write_fail
== 1) {
544 * Assuming it is a CRC failure, we want to allow another
547 rsi_dbg(ERR_ZONE
, "%s: Continue card writes\n", __func__
);
551 if (likely(dev
->sdio_irq_task
!= current
))
552 sdio_claim_host(dev
->pfunction
);
554 status
= sdio_writesb(dev
->pfunction
, addr
, data
, count
);
556 if (likely(dev
->sdio_irq_task
!= current
))
557 sdio_release_host(dev
->pfunction
);
560 rsi_dbg(ERR_ZONE
, "%s: Synch Cmd53 write failed %d\n",
564 memcpy(dev
->prev_desc
, data
, FRAME_DESC_SZ
);
569 static int rsi_sdio_load_data_master_write(struct rsi_hw
*adapter
,
575 u32 num_blocks
, offset
, i
;
576 u16 msb_address
, lsb_address
;
580 num_blocks
= instructions_sz
/ block_size
;
581 msb_address
= base_address
>> 16;
583 rsi_dbg(INFO_ZONE
, "ins_size: %d, num_blocks: %d\n",
584 instructions_sz
, num_blocks
);
586 temp_buf
= kmalloc(block_size
, GFP_KERNEL
);
590 /* Loading DM ms word in the sdio slave */
591 status
= rsi_sdio_master_access_msword(adapter
, msb_address
);
593 rsi_dbg(ERR_ZONE
, "%s: Unable to set ms word reg\n", __func__
);
597 for (offset
= 0, i
= 0; i
< num_blocks
; i
++, offset
+= block_size
) {
598 memcpy(temp_buf
, ta_firmware
+ offset
, block_size
);
599 lsb_address
= (u16
)base_address
;
600 status
= rsi_sdio_write_register_multiple
602 lsb_address
| RSI_SD_REQUEST_MASTER
,
603 temp_buf
, block_size
);
605 rsi_dbg(ERR_ZONE
, "%s: failed to write\n", __func__
);
608 rsi_dbg(INFO_ZONE
, "%s: loading block: %d\n", __func__
, i
);
609 base_address
+= block_size
;
611 if ((base_address
>> 16) != msb_address
) {
614 /* Loading DM ms word in the sdio slave */
615 status
= rsi_sdio_master_access_msword(adapter
,
619 "%s: Unable to set ms word reg\n",
626 if (instructions_sz
% block_size
) {
627 memset(temp_buf
, 0, block_size
);
628 memcpy(temp_buf
, ta_firmware
+ offset
,
629 instructions_sz
% block_size
);
630 lsb_address
= (u16
)base_address
;
631 status
= rsi_sdio_write_register_multiple
633 lsb_address
| RSI_SD_REQUEST_MASTER
,
635 instructions_sz
% block_size
);
639 "Written Last Block in Address 0x%x Successfully\n",
640 offset
| RSI_SD_REQUEST_MASTER
);
649 #define FLASH_SIZE_ADDR 0x04000016
650 static int rsi_sdio_master_reg_read(struct rsi_hw
*adapter
, u32 addr
,
651 u32
*read_buf
, u16 size
)
653 u32 addr_on_bus
, *data
;
657 data
= kzalloc(RSI_MASTER_REG_BUF_SIZE
, GFP_KERNEL
);
661 ms_addr
= (addr
>> 16);
662 status
= rsi_sdio_master_access_msword(adapter
, ms_addr
);
665 "%s: Unable to set ms word to common reg\n",
671 addr_on_bus
= (addr
& 0xFF000000);
672 if ((addr_on_bus
== (FLASH_SIZE_ADDR
& 0xFF000000)) ||
673 (addr_on_bus
== 0x0))
674 addr_on_bus
= (addr
& ~(0x3));
678 /* Bring TA out of reset */
679 status
= rsi_sdio_read_register_multiple
681 (addr_on_bus
| RSI_SD_REQUEST_MASTER
),
684 rsi_dbg(ERR_ZONE
, "%s: AHB register read failed\n", __func__
);
688 if ((addr
& 0x3) == 0)
691 *read_buf
= (*data
>> 16);
692 *read_buf
= (*read_buf
& 0xFFFF);
693 } else if (size
== 1) {
694 if ((addr
& 0x3) == 0)
696 else if ((addr
& 0x3) == 1)
697 *read_buf
= (*data
>> 8);
698 else if ((addr
& 0x3) == 2)
699 *read_buf
= (*data
>> 16);
701 *read_buf
= (*data
>> 24);
702 *read_buf
= (*read_buf
& 0xFF);
712 static int rsi_sdio_master_reg_write(struct rsi_hw
*adapter
,
714 unsigned long data
, u16 size
)
716 unsigned long *data_aligned
;
719 data_aligned
= kzalloc(RSI_MASTER_REG_BUF_SIZE
, GFP_KERNEL
);
724 *data_aligned
= ((data
<< 16) | (data
& 0xFFFF));
725 } else if (size
== 1) {
726 u32 temp_data
= data
& 0xFF;
728 *data_aligned
= ((temp_data
<< 24) | (temp_data
<< 16) |
729 (temp_data
<< 8) | temp_data
);
731 *data_aligned
= data
;
735 status
= rsi_sdio_master_access_msword(adapter
, (addr
>> 16));
738 "%s: Unable to set ms word to common reg\n",
743 addr
= addr
& 0xFFFF;
745 /* Bring TA out of reset */
746 status
= rsi_sdio_write_register_multiple
748 (addr
| RSI_SD_REQUEST_MASTER
),
749 (u8
*)data_aligned
, size
);
752 "%s: Unable to do AHB reg write\n", __func__
);
759 * rsi_sdio_host_intf_write_pkt() - This function writes the packet to device.
760 * @adapter: Pointer to the adapter structure.
761 * @pkt: Pointer to the data to be written on to the device.
762 * @len: length of the data to be written on to the device.
764 * Return: 0 on success, -1 on failure.
766 static int rsi_sdio_host_intf_write_pkt(struct rsi_hw
*adapter
,
770 struct rsi_91x_sdiodev
*dev
=
771 (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
772 u32 block_size
= dev
->tx_blk_size
;
773 u32 num_blocks
, address
, length
;
777 queueno
= ((pkt
[1] >> 4) & 0xf);
778 if (queueno
== RSI_BT_MGMT_Q
|| queueno
== RSI_BT_DATA_Q
)
781 num_blocks
= len
/ block_size
;
783 if (len
% block_size
)
786 address
= (num_blocks
* block_size
| (queueno
<< 12));
787 length
= num_blocks
* block_size
;
789 status
= rsi_sdio_write_register_multiple(adapter
,
794 rsi_dbg(ERR_ZONE
, "%s: Unable to write onto the card: %d\n",
796 rsi_dbg(DATA_TX_ZONE
, "%s: Successfully written onto card\n", __func__
);
801 * rsi_sdio_host_intf_read_pkt() - This function reads the packet
803 * @adapter: Pointer to the adapter data structure.
804 * @pkt: Pointer to the packet data to be read from the the device.
805 * @length: Length of the data to be read from the device.
807 * Return: 0 on success, -1 on failure.
809 int rsi_sdio_host_intf_read_pkt(struct rsi_hw
*adapter
,
813 int status
= -EINVAL
;
816 rsi_dbg(ERR_ZONE
, "%s: Pkt size is zero\n", __func__
);
820 status
= rsi_sdio_read_register_multiple(adapter
,
823 length
); /*num of bytes*/
826 rsi_dbg(ERR_ZONE
, "%s: Failed to read frame: %d\n", __func__
,
832 * rsi_init_sdio_interface() - This function does init specific to SDIO.
834 * @adapter: Pointer to the adapter data structure.
835 * @pkt: Pointer to the packet data to be read from the the device.
837 * Return: 0 on success, -1 on failure.
840 static int rsi_init_sdio_interface(struct rsi_hw
*adapter
,
841 struct sdio_func
*pfunction
)
843 struct rsi_91x_sdiodev
*rsi_91x_dev
;
844 int status
= -ENOMEM
;
846 rsi_91x_dev
= kzalloc(sizeof(*rsi_91x_dev
), GFP_KERNEL
);
850 adapter
->rsi_dev
= rsi_91x_dev
;
852 sdio_claim_host(pfunction
);
854 pfunction
->enable_timeout
= 100;
855 status
= sdio_enable_func(pfunction
);
857 rsi_dbg(ERR_ZONE
, "%s: Failed to enable interface\n", __func__
);
858 sdio_release_host(pfunction
);
862 rsi_dbg(INIT_ZONE
, "%s: Enabled the interface\n", __func__
);
864 rsi_91x_dev
->pfunction
= pfunction
;
865 adapter
->device
= &pfunction
->dev
;
867 sdio_set_drvdata(pfunction
, adapter
);
869 status
= rsi_setupcard(adapter
);
871 rsi_dbg(ERR_ZONE
, "%s: Failed to setup card\n", __func__
);
875 rsi_dbg(INIT_ZONE
, "%s: Setup card succesfully\n", __func__
);
877 status
= rsi_init_sdio_slave_regs(adapter
);
879 rsi_dbg(ERR_ZONE
, "%s: Failed to init slave regs\n", __func__
);
882 sdio_release_host(pfunction
);
884 adapter
->determine_event_timeout
= rsi_sdio_determine_event_timeout
;
885 adapter
->check_hw_queue_status
= rsi_sdio_check_buffer_status
;
887 #ifdef CONFIG_RSI_DEBUGFS
888 adapter
->num_debugfs_entries
= MAX_DEBUGFS_ENTRIES
;
892 sdio_disable_func(pfunction
);
893 sdio_release_host(pfunction
);
897 static int rsi_sdio_reinit_device(struct rsi_hw
*adapter
)
899 struct rsi_91x_sdiodev
*sdev
= adapter
->rsi_dev
;
900 struct sdio_func
*pfunction
= sdev
->pfunction
;
903 for (ii
= 0; ii
< NUM_SOFT_QUEUES
; ii
++)
904 skb_queue_purge(&adapter
->priv
->tx_queue
[ii
]);
906 /* Initialize device again */
907 sdio_claim_host(pfunction
);
909 sdio_release_irq(pfunction
);
910 rsi_reset_card(pfunction
);
912 sdio_enable_func(pfunction
);
913 rsi_setupcard(adapter
);
914 rsi_init_sdio_slave_regs(adapter
);
915 sdio_claim_irq(pfunction
, rsi_handle_interrupt
);
916 rsi_hal_device_init(adapter
);
918 sdio_release_host(pfunction
);
923 static struct rsi_host_intf_ops sdio_host_intf_ops
= {
924 .write_pkt
= rsi_sdio_host_intf_write_pkt
,
925 .read_pkt
= rsi_sdio_host_intf_read_pkt
,
926 .master_access_msword
= rsi_sdio_master_access_msword
,
927 .read_reg_multiple
= rsi_sdio_read_register_multiple
,
928 .write_reg_multiple
= rsi_sdio_write_register_multiple
,
929 .master_reg_read
= rsi_sdio_master_reg_read
,
930 .master_reg_write
= rsi_sdio_master_reg_write
,
931 .load_data_master_write
= rsi_sdio_load_data_master_write
,
932 .reinit_device
= rsi_sdio_reinit_device
,
936 * rsi_probe() - This function is called by kernel when the driver provided
937 * Vendor and device IDs are matched. All the initialization
939 * @pfunction: Pointer to the sdio_func structure.
940 * @id: Pointer to sdio_device_id structure.
942 * Return: 0 on success, 1 on failure.
944 static int rsi_probe(struct sdio_func
*pfunction
,
945 const struct sdio_device_id
*id
)
947 struct rsi_hw
*adapter
;
948 struct rsi_91x_sdiodev
*sdev
;
951 rsi_dbg(INIT_ZONE
, "%s: Init function called\n", __func__
);
953 adapter
= rsi_91x_init(dev_oper_mode
);
955 rsi_dbg(ERR_ZONE
, "%s: Failed to init os intf ops\n",
959 adapter
->rsi_host_intf
= RSI_HOST_INTF_SDIO
;
960 adapter
->host_intf_ops
= &sdio_host_intf_ops
;
962 if (rsi_init_sdio_interface(adapter
, pfunction
)) {
963 rsi_dbg(ERR_ZONE
, "%s: Failed to init sdio interface\n",
966 goto fail_free_adapter
;
968 sdev
= (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
969 rsi_init_event(&sdev
->rx_thread
.event
);
970 status
= rsi_create_kthread(adapter
->priv
, &sdev
->rx_thread
,
971 rsi_sdio_rx_thread
, "SDIO-RX-Thread");
973 rsi_dbg(ERR_ZONE
, "%s: Unable to init rx thrd\n", __func__
);
974 goto fail_kill_thread
;
976 skb_queue_head_init(&sdev
->rx_q
.head
);
977 sdev
->rx_q
.num_rx_pkts
= 0;
979 sdio_claim_host(pfunction
);
980 if (sdio_claim_irq(pfunction
, rsi_handle_interrupt
)) {
981 rsi_dbg(ERR_ZONE
, "%s: Failed to request IRQ\n", __func__
);
982 sdio_release_host(pfunction
);
986 sdio_release_host(pfunction
);
987 rsi_dbg(INIT_ZONE
, "%s: Registered Interrupt handler\n", __func__
);
989 if (rsi_hal_device_init(adapter
)) {
990 rsi_dbg(ERR_ZONE
, "%s: Failed in device init\n", __func__
);
994 rsi_dbg(INFO_ZONE
, "===> RSI Device Init Done <===\n");
996 if (rsi_sdio_master_access_msword(adapter
, MISC_CFG_BASE_ADDR
)) {
997 rsi_dbg(ERR_ZONE
, "%s: Unable to set ms word reg\n", __func__
);
1002 adapter
->priv
->hibernate_resume
= false;
1003 adapter
->priv
->reinit_hw
= false;
1007 sdio_claim_host(pfunction
);
1008 sdio_release_irq(pfunction
);
1009 sdio_release_host(pfunction
);
1011 rsi_kill_thread(&sdev
->rx_thread
);
1013 sdio_claim_host(pfunction
);
1014 sdio_disable_func(pfunction
);
1015 sdio_release_host(pfunction
);
1017 rsi_91x_deinit(adapter
);
1018 rsi_dbg(ERR_ZONE
, "%s: Failed in probe...Exiting\n", __func__
);
1022 static void ulp_read_write(struct rsi_hw
*adapter
, u16 addr
, u32 data
,
1025 rsi_sdio_master_reg_write(adapter
, RSI_GSPI_DATA_REG1
,
1026 ((addr
<< 6) | ((data
>> 16) & 0xffff)), 2);
1027 rsi_sdio_master_reg_write(adapter
, RSI_GSPI_DATA_REG0
,
1028 (data
& 0xffff), 2);
1029 rsi_sdio_master_reg_write(adapter
, RSI_GSPI_CTRL_REG0
,
1030 RSI_GSPI_CTRL_REG0_VALUE
, 2);
1031 rsi_sdio_master_reg_write(adapter
, RSI_GSPI_CTRL_REG1
,
1032 ((len_in_bits
- 1) | RSI_GSPI_TRIG
), 2);
1036 /*This function resets and re-initializes the chip.*/
1037 static void rsi_reset_chip(struct rsi_hw
*adapter
)
1040 u8 sdio_interrupt_status
= 0;
1044 data
= kzalloc(sizeof(u32
), GFP_KERNEL
);
1048 rsi_dbg(INFO_ZONE
, "Writing disable to wakeup register\n");
1049 ret
= rsi_sdio_write_register(adapter
, 0, SDIO_WAKEUP_REG
, &request
);
1052 "%s: Failed to write SDIO wakeup register\n", __func__
);
1056 ret
= rsi_sdio_read_register(adapter
, RSI_FN1_INT_REGISTER
,
1057 &sdio_interrupt_status
);
1059 rsi_dbg(ERR_ZONE
, "%s: Failed to Read Intr Status Register\n",
1063 rsi_dbg(INFO_ZONE
, "%s: Intr Status Register value = %d\n",
1064 __func__
, sdio_interrupt_status
);
1066 /* Put Thread-Arch processor on hold */
1067 if (rsi_sdio_master_access_msword(adapter
, TA_BASE_ADDR
)) {
1069 "%s: Unable to set ms word to common reg\n",
1074 put_unaligned_le32(TA_HOLD_THREAD_VALUE
, data
);
1075 if (rsi_sdio_write_register_multiple(adapter
, TA_HOLD_THREAD_REG
|
1076 RSI_SD_REQUEST_MASTER
,
1079 "%s: Unable to hold Thread-Arch processor threads\n",
1084 /* This msleep will ensure Thread-Arch processor to go to hold
1085 * and any pending dma transfers to rf spi in device to finish.
1089 ulp_read_write(adapter
, RSI_ULP_RESET_REG
, RSI_ULP_WRITE_0
, 32);
1090 ulp_read_write(adapter
, RSI_WATCH_DOG_TIMER_1
, RSI_ULP_WRITE_2
, 32);
1091 ulp_read_write(adapter
, RSI_WATCH_DOG_TIMER_2
, RSI_ULP_WRITE_0
, 32);
1092 ulp_read_write(adapter
, RSI_WATCH_DOG_DELAY_TIMER_1
, RSI_ULP_WRITE_50
,
1094 ulp_read_write(adapter
, RSI_WATCH_DOG_DELAY_TIMER_2
, RSI_ULP_WRITE_0
,
1096 ulp_read_write(adapter
, RSI_WATCH_DOG_TIMER_ENABLE
,
1097 RSI_ULP_TIMER_ENABLE
, 32);
1098 /* This msleep will be sufficient for the ulp
1099 * read write operations to complete for chip reset.
1108 * rsi_disconnect() - This function performs the reverse of the probe function.
1109 * @pfunction: Pointer to the sdio_func structure.
1113 static void rsi_disconnect(struct sdio_func
*pfunction
)
1115 struct rsi_hw
*adapter
= sdio_get_drvdata(pfunction
);
1116 struct rsi_91x_sdiodev
*dev
;
1121 dev
= (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
1123 rsi_kill_thread(&dev
->rx_thread
);
1124 sdio_claim_host(pfunction
);
1125 sdio_release_irq(pfunction
);
1126 sdio_release_host(pfunction
);
1129 rsi_mac80211_detach(adapter
);
1133 rsi_reset_chip(adapter
);
1135 /* Resetting to take care of the case, where-in driver is re-loaded */
1136 sdio_claim_host(pfunction
);
1137 rsi_reset_card(pfunction
);
1138 sdio_disable_func(pfunction
);
1139 sdio_release_host(pfunction
);
1140 dev
->write_fail
= 2;
1141 rsi_91x_deinit(adapter
);
1142 rsi_dbg(ERR_ZONE
, "##### RSI SDIO device disconnected #####\n");
1147 static int rsi_set_sdio_pm_caps(struct rsi_hw
*adapter
)
1149 struct rsi_91x_sdiodev
*dev
=
1150 (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
1151 struct sdio_func
*func
= dev
->pfunction
;
1154 ret
= sdio_set_host_pm_flags(func
, MMC_PM_KEEP_POWER
);
1156 rsi_dbg(ERR_ZONE
, "Set sdio keep pwr flag failed: %d\n", ret
);
1161 static int rsi_sdio_disable_interrupts(struct sdio_func
*pfunc
)
1163 struct rsi_hw
*adapter
= sdio_get_drvdata(pfunc
);
1164 u8 isr_status
= 0, data
= 0;
1168 rsi_dbg(INFO_ZONE
, "Waiting for interrupts to be cleared..");
1171 rsi_sdio_read_register(adapter
, RSI_FN1_INT_REGISTER
,
1173 rsi_dbg(INFO_ZONE
, ".");
1174 } while ((isr_status
) && (jiffies_to_msecs(jiffies
- t1
) < 20));
1175 rsi_dbg(INFO_ZONE
, "Interrupts cleared\n");
1177 sdio_claim_host(pfunc
);
1178 ret
= rsi_cmd52readbyte(pfunc
->card
, RSI_INT_ENABLE_REGISTER
, &data
);
1181 "%s: Failed to read int enable register\n",
1186 data
&= RSI_INT_ENABLE_MASK
;
1187 ret
= rsi_cmd52writebyte(pfunc
->card
, RSI_INT_ENABLE_REGISTER
, data
);
1190 "%s: Failed to write to int enable register\n",
1194 ret
= rsi_cmd52readbyte(pfunc
->card
, RSI_INT_ENABLE_REGISTER
, &data
);
1197 "%s: Failed to read int enable register\n",
1201 rsi_dbg(INFO_ZONE
, "int enable reg content = %x\n", data
);
1204 sdio_release_host(pfunc
);
1208 static int rsi_sdio_enable_interrupts(struct sdio_func
*pfunc
)
1212 struct rsi_hw
*adapter
= sdio_get_drvdata(pfunc
);
1213 struct rsi_common
*common
= adapter
->priv
;
1215 sdio_claim_host(pfunc
);
1216 ret
= rsi_cmd52readbyte(pfunc
->card
, RSI_INT_ENABLE_REGISTER
, &data
);
1219 "%s: Failed to read int enable register\n", __func__
);
1223 data
|= ~RSI_INT_ENABLE_MASK
& 0xff;
1225 ret
= rsi_cmd52writebyte(pfunc
->card
, RSI_INT_ENABLE_REGISTER
, data
);
1228 "%s: Failed to write to int enable register\n",
1233 if ((common
->wow_flags
& RSI_WOW_ENABLED
) &&
1234 (common
->wow_flags
& RSI_WOW_NO_CONNECTION
))
1236 "##### Device can not wake up through WLAN\n");
1238 ret
= rsi_cmd52readbyte(pfunc
->card
, RSI_INT_ENABLE_REGISTER
, &data
);
1241 "%s: Failed to read int enable register\n", __func__
);
1244 rsi_dbg(INFO_ZONE
, "int enable reg content = %x\n", data
);
1247 sdio_release_host(pfunc
);
1251 static int rsi_suspend(struct device
*dev
)
1254 struct sdio_func
*pfunction
= dev_to_sdio_func(dev
);
1255 struct rsi_hw
*adapter
= sdio_get_drvdata(pfunction
);
1256 struct rsi_common
*common
;
1259 rsi_dbg(ERR_ZONE
, "Device is not ready\n");
1262 common
= adapter
->priv
;
1263 rsi_sdio_disable_interrupts(pfunction
);
1265 ret
= rsi_set_sdio_pm_caps(adapter
);
1268 "Setting power management caps failed\n");
1269 common
->fsm_state
= FSM_CARD_NOT_READY
;
1274 static int rsi_resume(struct device
*dev
)
1276 struct sdio_func
*pfunction
= dev_to_sdio_func(dev
);
1277 struct rsi_hw
*adapter
= sdio_get_drvdata(pfunction
);
1278 struct rsi_common
*common
= adapter
->priv
;
1280 common
->fsm_state
= FSM_MAC_INIT_DONE
;
1281 rsi_sdio_enable_interrupts(pfunction
);
1286 static int rsi_freeze(struct device
*dev
)
1289 struct sdio_func
*pfunction
= dev_to_sdio_func(dev
);
1290 struct rsi_hw
*adapter
= sdio_get_drvdata(pfunction
);
1291 struct rsi_common
*common
;
1292 struct rsi_91x_sdiodev
*sdev
;
1294 rsi_dbg(INFO_ZONE
, "SDIO Bus freeze ===>\n");
1297 rsi_dbg(ERR_ZONE
, "Device is not ready\n");
1300 common
= adapter
->priv
;
1301 sdev
= (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
1303 if ((common
->wow_flags
& RSI_WOW_ENABLED
) &&
1304 (common
->wow_flags
& RSI_WOW_NO_CONNECTION
))
1306 "##### Device can not wake up through WLAN\n");
1308 ret
= rsi_sdio_disable_interrupts(pfunction
);
1310 if (sdev
->write_fail
)
1311 rsi_dbg(INFO_ZONE
, "###### Device is not ready #######\n");
1313 ret
= rsi_set_sdio_pm_caps(adapter
);
1315 rsi_dbg(INFO_ZONE
, "Setting power management caps failed\n");
1317 rsi_dbg(INFO_ZONE
, "***** RSI module freezed *****\n");
1322 static int rsi_thaw(struct device
*dev
)
1324 struct sdio_func
*pfunction
= dev_to_sdio_func(dev
);
1325 struct rsi_hw
*adapter
= sdio_get_drvdata(pfunction
);
1326 struct rsi_common
*common
= adapter
->priv
;
1328 rsi_dbg(ERR_ZONE
, "SDIO Bus thaw =====>\n");
1330 common
->hibernate_resume
= true;
1331 common
->fsm_state
= FSM_CARD_NOT_READY
;
1332 common
->iface_down
= true;
1334 rsi_sdio_enable_interrupts(pfunction
);
1336 rsi_dbg(INFO_ZONE
, "***** RSI module thaw done *****\n");
1341 static void rsi_shutdown(struct device
*dev
)
1343 struct sdio_func
*pfunction
= dev_to_sdio_func(dev
);
1344 struct rsi_hw
*adapter
= sdio_get_drvdata(pfunction
);
1345 struct rsi_91x_sdiodev
*sdev
=
1346 (struct rsi_91x_sdiodev
*)adapter
->rsi_dev
;
1347 struct ieee80211_hw
*hw
= adapter
->hw
;
1348 struct cfg80211_wowlan
*wowlan
= hw
->wiphy
->wowlan_config
;
1350 rsi_dbg(ERR_ZONE
, "SDIO Bus shutdown =====>\n");
1352 if (rsi_config_wowlan(adapter
, wowlan
))
1353 rsi_dbg(ERR_ZONE
, "Failed to configure WoWLAN\n");
1355 rsi_sdio_disable_interrupts(sdev
->pfunction
);
1357 if (sdev
->write_fail
)
1358 rsi_dbg(INFO_ZONE
, "###### Device is not ready #######\n");
1360 if (rsi_set_sdio_pm_caps(adapter
))
1361 rsi_dbg(INFO_ZONE
, "Setting power management caps failed\n");
1363 rsi_dbg(INFO_ZONE
, "***** RSI module shut down *****\n");
1366 static int rsi_restore(struct device
*dev
)
1368 struct sdio_func
*pfunction
= dev_to_sdio_func(dev
);
1369 struct rsi_hw
*adapter
= sdio_get_drvdata(pfunction
);
1370 struct rsi_common
*common
= adapter
->priv
;
1372 rsi_dbg(INFO_ZONE
, "SDIO Bus restore ======>\n");
1373 common
->hibernate_resume
= true;
1374 common
->fsm_state
= FSM_FW_NOT_LOADED
;
1375 common
->iface_down
= true;
1377 adapter
->sc_nvifs
= 0;
1378 ieee80211_restart_hw(adapter
->hw
);
1380 common
->wow_flags
= 0;
1381 common
->iface_down
= false;
1383 rsi_dbg(INFO_ZONE
, "RSI module restored\n");
1387 static const struct dev_pm_ops rsi_pm_ops
= {
1388 .suspend
= rsi_suspend
,
1389 .resume
= rsi_resume
,
1390 .freeze
= rsi_freeze
,
1392 .restore
= rsi_restore
,
1396 static const struct sdio_device_id rsi_dev_table
[] = {
1397 { SDIO_DEVICE(0x303, 0x100) },
1398 { SDIO_DEVICE(0x041B, 0x0301) },
1399 { SDIO_DEVICE(0x041B, 0x0201) },
1400 { SDIO_DEVICE(0x041B, 0x9330) },
1404 static struct sdio_driver rsi_driver
= {
1405 .name
= "RSI-SDIO WLAN",
1407 .remove
= rsi_disconnect
,
1408 .id_table
= rsi_dev_table
,
1412 .shutdown
= rsi_shutdown
,
1418 * rsi_module_init() - This function registers the sdio module.
1421 * Return: 0 on success.
1423 static int rsi_module_init(void)
1427 ret
= sdio_register_driver(&rsi_driver
);
1428 rsi_dbg(INIT_ZONE
, "%s: Registering driver\n", __func__
);
1433 * rsi_module_exit() - This function unregisters the sdio module.
1438 static void rsi_module_exit(void)
1440 sdio_unregister_driver(&rsi_driver
);
1441 rsi_dbg(INFO_ZONE
, "%s: Unregistering driver\n", __func__
);
1444 module_init(rsi_module_init
);
1445 module_exit(rsi_module_exit
);
1447 MODULE_AUTHOR("Redpine Signals Inc");
1448 MODULE_DESCRIPTION("Common SDIO layer for RSI drivers");
1449 MODULE_SUPPORTED_DEVICE("RSI-91x");
1450 MODULE_DEVICE_TABLE(sdio
, rsi_dev_table
);
1451 MODULE_FIRMWARE(FIRMWARE_RSI9113
);
1452 MODULE_VERSION("0.1");
1453 MODULE_LICENSE("Dual BSD/GPL");