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 * rsi_sdio_set_cmd52_arg() - This function prepares cmd 52 read/write arg.
26 * @func: function number
27 * @raw: indicates whether to perform read after write
28 * @address: address to which to read/write
29 * @writedata: data to write
33 static u32 rsi_sdio_set_cmd52_arg(bool rw,
39 return ((rw & 1) << 31) | ((func & 0x7) << 28) |
40 ((raw & 1) << 27) | (1 << 26) |
41 ((address & 0x1FFFF) << 9) | (1 << 8) |
46 * rsi_cmd52writebyte() - This function issues cmd52 byte write onto the card.
47 * @card: Pointer to the mmc_card.
48 * @address: Address to write.
49 * @byte: Data to write.
51 * Return: Write status.
53 static int rsi_cmd52writebyte(struct mmc_card *card,
57 struct mmc_command io_cmd;
60 memset(&io_cmd, 0, sizeof(io_cmd));
61 arg = rsi_sdio_set_cmd52_arg(1, 0, 0, address, byte);
62 io_cmd.opcode = SD_IO_RW_DIRECT;
64 io_cmd.flags = MMC_RSP_R5 | MMC_CMD_AC;
66 return mmc_wait_for_cmd(card->host, &io_cmd, 0);
70 * rsi_cmd52readbyte() - This function issues cmd52 byte read onto the card.
71 * @card: Pointer to the mmc_card.
72 * @address: Address to read from.
73 * @byte: Variable to store read value.
75 * Return: Read status.
77 static int rsi_cmd52readbyte(struct mmc_card *card,
81 struct mmc_command io_cmd;
85 memset(&io_cmd, 0, sizeof(io_cmd));
86 arg = rsi_sdio_set_cmd52_arg(0, 0, 0, address, 0);
87 io_cmd.opcode = SD_IO_RW_DIRECT;
89 io_cmd.flags = MMC_RSP_R5 | MMC_CMD_AC;
91 err = mmc_wait_for_cmd(card->host, &io_cmd, 0);
93 *byte = io_cmd.resp[0] & 0xFF;
98 * rsi_issue_sdiocommand() - This function issues sdio commands.
99 * @func: Pointer to the sdio_func structure.
100 * @opcode: Opcode value.
101 * @arg: Arguments to pass.
102 * @flags: Flags which are set.
103 * @resp: Pointer to store response.
105 * Return: err: command status as 0 or -1.
107 static int rsi_issue_sdiocommand(struct sdio_func *func,
113 struct mmc_command cmd;
114 struct mmc_host *host;
117 host = func->card->host;
119 memset(&cmd, 0, sizeof(struct mmc_command));
123 err = mmc_wait_for_cmd(host, &cmd, 3);
125 if ((!err) && (resp))
132 * rsi_handle_interrupt() - This function is called upon the occurence
134 * @function: Pointer to the sdio_func structure.
138 static void rsi_handle_interrupt(struct sdio_func *function)
140 struct rsi_hw *adapter = sdio_get_drvdata(function);
141 struct rsi_91x_sdiodev *dev =
142 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
144 if (adapter->priv->fsm_state == FSM_FW_NOT_LOADED)
147 dev->sdio_irq_task = current;
148 rsi_interrupt_handler(adapter);
149 dev->sdio_irq_task = NULL;
153 * rsi_reset_card() - This function resets and re-initializes the card.
154 * @pfunction: Pointer to the sdio_func structure.
158 static void rsi_reset_card(struct sdio_func *pfunction)
162 struct mmc_card *card = pfunction->card;
163 struct mmc_host *host = card->host;
168 /* Reset 9110 chip */
169 ret = rsi_cmd52writebyte(pfunction->card,
173 /* Card will not send any response as it is getting reset immediately
174 * Hence expect a timeout status from host controller
176 if (ret != -ETIMEDOUT)
177 rsi_dbg(ERR_ZONE, "%s: Reset failed : %d\n", __func__, ret);
179 /* Wait for few milli seconds to get rid of residue charges if any */
182 /* Initialize the SDIO card */
183 host->ios.chip_select = MMC_CS_DONTCARE;
184 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
185 host->ios.power_mode = MMC_POWER_UP;
186 host->ios.bus_width = MMC_BUS_WIDTH_1;
187 host->ios.timing = MMC_TIMING_LEGACY;
188 host->ops->set_ios(host, &host->ios);
191 * This delay should be sufficient to allow the power supply
192 * to reach the minimum voltage.
196 host->ios.clock = host->f_min;
197 host->ios.power_mode = MMC_POWER_ON;
198 host->ops->set_ios(host, &host->ios);
201 * This delay must be at least 74 clock sizes, or 1 ms, or the
202 * time required to reach a stable voltage.
206 /* Issue CMD0. Goto idle state */
207 host->ios.chip_select = MMC_CS_HIGH;
208 host->ops->set_ios(host, &host->ios);
210 err = rsi_issue_sdiocommand(pfunction,
213 (MMC_RSP_NONE | MMC_CMD_BC),
215 host->ios.chip_select = MMC_CS_DONTCARE;
216 host->ops->set_ios(host, &host->ios);
218 host->use_spi_crc = 0;
221 rsi_dbg(ERR_ZONE, "%s: CMD0 failed : %d\n", __func__, err);
223 /* Issue CMD5, arg = 0 */
224 err = rsi_issue_sdiocommand(pfunction, SD_IO_SEND_OP_COND, 0,
225 (MMC_RSP_R4 | MMC_CMD_BCR), &resp);
227 rsi_dbg(ERR_ZONE, "%s: CMD5 failed : %d\n", __func__, err);
230 /* Issue CMD5, arg = ocr. Wait till card is ready */
231 for (i = 0; i < 100; i++) {
232 err = rsi_issue_sdiocommand(pfunction, SD_IO_SEND_OP_COND,
234 (MMC_RSP_R4 | MMC_CMD_BCR), &resp);
236 rsi_dbg(ERR_ZONE, "%s: CMD5 failed : %d\n",
241 if (resp & MMC_CARD_BUSY)
246 if ((i == 100) || (err)) {
247 rsi_dbg(ERR_ZONE, "%s: card in not ready : %d %d\n",
252 /* Issue CMD3, get RCA */
253 err = rsi_issue_sdiocommand(pfunction,
254 SD_SEND_RELATIVE_ADDR,
256 (MMC_RSP_R6 | MMC_CMD_BCR),
259 rsi_dbg(ERR_ZONE, "%s: CMD3 failed : %d\n", __func__, err);
263 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
264 host->ops->set_ios(host, &host->ios);
266 /* Issue CMD7, select card */
267 err = rsi_issue_sdiocommand(pfunction,
270 (MMC_RSP_R1 | MMC_CMD_AC),
273 rsi_dbg(ERR_ZONE, "%s: CMD7 failed : %d\n", __func__, err);
277 /* Enable high speed */
278 if (card->host->caps & MMC_CAP_SD_HIGHSPEED) {
279 rsi_dbg(ERR_ZONE, "%s: Set high speed mode\n", __func__);
280 err = rsi_cmd52readbyte(card, SDIO_CCCR_SPEED, &cmd52_resp);
282 rsi_dbg(ERR_ZONE, "%s: CCCR speed reg read failed: %d\n",
285 err = rsi_cmd52writebyte(card,
287 (cmd52_resp | SDIO_SPEED_EHS));
290 "%s: CCR speed regwrite failed %d\n",
294 host->ios.timing = MMC_TIMING_SD_HS;
295 host->ops->set_ios(host, &host->ios);
300 if (mmc_card_hs(card))
303 clock = card->cis.max_dtr;
305 if (clock > host->f_max)
308 host->ios.clock = clock;
309 host->ops->set_ios(host, &host->ios);
311 if (card->host->caps & MMC_CAP_4_BIT_DATA) {
312 /* CMD52: Set bus width & disable card detect resistor */
313 err = rsi_cmd52writebyte(card,
315 (SDIO_BUS_CD_DISABLE |
316 SDIO_BUS_WIDTH_4BIT));
318 rsi_dbg(ERR_ZONE, "%s: Set bus mode failed : %d\n",
322 host->ios.bus_width = MMC_BUS_WIDTH_4;
323 host->ops->set_ios(host, &host->ios);
328 * rsi_setclock() - This function sets the clock frequency.
329 * @adapter: Pointer to the adapter structure.
330 * @freq: Clock frequency.
334 static void rsi_setclock(struct rsi_hw *adapter, u32 freq)
336 struct rsi_91x_sdiodev *dev =
337 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
338 struct mmc_host *host = dev->pfunction->card->host;
342 if (clock > host->f_max)
344 host->ios.clock = clock;
345 host->ops->set_ios(host, &host->ios);
349 * rsi_setblocklength() - This function sets the host block length.
350 * @adapter: Pointer to the adapter structure.
351 * @length: Block length to be set.
353 * Return: status: 0 on success, -1 on failure.
355 static int rsi_setblocklength(struct rsi_hw *adapter, u32 length)
357 struct rsi_91x_sdiodev *dev =
358 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
360 rsi_dbg(INIT_ZONE, "%s: Setting the block length\n", __func__);
362 status = sdio_set_block_size(dev->pfunction, length);
363 dev->pfunction->max_blksize = 256;
364 adapter->block_size = dev->pfunction->max_blksize;
367 "%s: Operational blk length is %d\n", __func__, length);
372 * rsi_setupcard() - This function queries and sets the card's features.
373 * @adapter: Pointer to the adapter structure.
375 * Return: status: 0 on success, -1 on failure.
377 static int rsi_setupcard(struct rsi_hw *adapter)
379 struct rsi_91x_sdiodev *dev =
380 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
383 rsi_setclock(adapter, 50000);
385 dev->tx_blk_size = 256;
386 status = rsi_setblocklength(adapter, dev->tx_blk_size);
389 "%s: Unable to set block length\n", __func__);
394 * rsi_sdio_read_register() - This function reads one byte of information
396 * @adapter: Pointer to the adapter structure.
397 * @addr: Address of the register.
398 * @data: Pointer to the data that stores the data read.
400 * Return: 0 on success, -1 on failure.
402 int rsi_sdio_read_register(struct rsi_hw *adapter,
406 struct rsi_91x_sdiodev *dev =
407 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
411 if (likely(dev->sdio_irq_task != current))
412 sdio_claim_host(dev->pfunction);
415 *data = sdio_f0_readb(dev->pfunction, addr, &status);
417 *data = sdio_readb(dev->pfunction, addr, &status);
419 if (likely(dev->sdio_irq_task != current))
420 sdio_release_host(dev->pfunction);
426 * rsi_sdio_write_register() - This function writes one byte of information
428 * @adapter: Pointer to the adapter structure.
429 * @function: Function Number.
430 * @addr: Address of the register.
431 * @data: Pointer to the data tha has to be written.
433 * Return: 0 on success, -1 on failure.
435 int rsi_sdio_write_register(struct rsi_hw *adapter,
440 struct rsi_91x_sdiodev *dev =
441 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
444 if (likely(dev->sdio_irq_task != current))
445 sdio_claim_host(dev->pfunction);
448 sdio_f0_writeb(dev->pfunction, *data, addr, &status);
450 sdio_writeb(dev->pfunction, *data, addr, &status);
452 if (likely(dev->sdio_irq_task != current))
453 sdio_release_host(dev->pfunction);
459 * rsi_sdio_ack_intr() - This function acks the interrupt received.
460 * @adapter: Pointer to the adapter structure.
461 * @int_bit: Interrupt bit to write into register.
465 void rsi_sdio_ack_intr(struct rsi_hw *adapter, u8 int_bit)
468 status = rsi_sdio_write_register(adapter,
470 (SDIO_FUN1_INTR_CLR_REG |
471 RSI_SD_REQUEST_MASTER),
474 rsi_dbg(ERR_ZONE, "%s: unable to send ack\n", __func__);
480 * rsi_sdio_read_register_multiple() - This function read multiple bytes of
481 * information from the SD card.
482 * @adapter: Pointer to the adapter structure.
483 * @addr: Address of the register.
484 * @count: Number of multiple bytes to be read.
485 * @data: Pointer to the read data.
487 * Return: 0 on success, -1 on failure.
489 static int rsi_sdio_read_register_multiple(struct rsi_hw *adapter,
494 struct rsi_91x_sdiodev *dev =
495 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
498 if (likely(dev->sdio_irq_task != current))
499 sdio_claim_host(dev->pfunction);
501 status = sdio_readsb(dev->pfunction, data, addr, count);
503 if (likely(dev->sdio_irq_task != current))
504 sdio_release_host(dev->pfunction);
507 rsi_dbg(ERR_ZONE, "%s: Synch Cmd53 read failed\n", __func__);
512 * rsi_sdio_write_register_multiple() - This function writes multiple bytes of
513 * information to the SD card.
514 * @adapter: Pointer to the adapter structure.
515 * @addr: Address of the register.
516 * @data: Pointer to the data that has to be written.
517 * @count: Number of multiple bytes to be written.
519 * Return: 0 on success, -1 on failure.
521 int rsi_sdio_write_register_multiple(struct rsi_hw *adapter,
526 struct rsi_91x_sdiodev *dev =
527 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
530 if (dev->write_fail > 1) {
531 rsi_dbg(ERR_ZONE, "%s: Stopping card writes\n", __func__);
533 } else if (dev->write_fail == 1) {
535 * Assuming it is a CRC failure, we want to allow another
538 rsi_dbg(ERR_ZONE, "%s: Continue card writes\n", __func__);
542 if (likely(dev->sdio_irq_task != current))
543 sdio_claim_host(dev->pfunction);
545 status = sdio_writesb(dev->pfunction, addr, data, count);
547 if (likely(dev->sdio_irq_task != current))
548 sdio_release_host(dev->pfunction);
551 rsi_dbg(ERR_ZONE, "%s: Synch Cmd53 write failed %d\n",
555 memcpy(dev->prev_desc, data, FRAME_DESC_SZ);
560 static int rsi_sdio_load_data_master_write(struct rsi_hw *adapter,
566 u32 num_blocks, offset, i;
567 u16 msb_address, lsb_address;
568 u8 temp_buf[block_size];
571 num_blocks = instructions_sz / block_size;
572 msb_address = base_address >> 16;
574 rsi_dbg(INFO_ZONE, "ins_size: %d, num_blocks: %d\n",
575 instructions_sz, num_blocks);
577 /* Loading DM ms word in the sdio slave */
578 status = rsi_sdio_master_access_msword(adapter, msb_address);
580 rsi_dbg(ERR_ZONE, "%s: Unable to set ms word reg\n", __func__);
584 for (offset = 0, i = 0; i < num_blocks; i++, offset += block_size) {
585 memcpy(temp_buf, ta_firmware + offset, block_size);
586 lsb_address = (u16)base_address;
587 status = rsi_sdio_write_register_multiple
589 lsb_address | RSI_SD_REQUEST_MASTER,
590 temp_buf, block_size);
592 rsi_dbg(ERR_ZONE, "%s: failed to write\n", __func__);
595 rsi_dbg(INFO_ZONE, "%s: loading block: %d\n", __func__, i);
596 base_address += block_size;
598 if ((base_address >> 16) != msb_address) {
601 /* Loading DM ms word in the sdio slave */
602 status = rsi_sdio_master_access_msword(adapter,
606 "%s: Unable to set ms word reg\n",
613 if (instructions_sz % block_size) {
614 memset(temp_buf, 0, block_size);
615 memcpy(temp_buf, ta_firmware + offset,
616 instructions_sz % block_size);
617 lsb_address = (u16)base_address;
618 status = rsi_sdio_write_register_multiple
620 lsb_address | RSI_SD_REQUEST_MASTER,
622 instructions_sz % block_size);
626 "Written Last Block in Address 0x%x Successfully\n",
627 offset | RSI_SD_REQUEST_MASTER);
632 #define FLASH_SIZE_ADDR 0x04000016
633 static int rsi_sdio_master_reg_read(struct rsi_hw *adapter, u32 addr,
634 u32 *read_buf, u16 size)
636 u32 addr_on_bus, *data;
640 data = kzalloc(RSI_MASTER_REG_BUF_SIZE, GFP_KERNEL);
644 data = PTR_ALIGN(data, 8);
646 ms_addr = (addr >> 16);
647 status = rsi_sdio_master_access_msword(adapter, ms_addr);
650 "%s: Unable to set ms word to common reg\n",
656 addr_on_bus = (addr & 0xFF000000);
657 if ((addr_on_bus == (FLASH_SIZE_ADDR & 0xFF000000)) ||
658 (addr_on_bus == 0x0))
659 addr_on_bus = (addr & ~(0x3));
663 /* Bring TA out of reset */
664 status = rsi_sdio_read_register_multiple
666 (addr_on_bus | RSI_SD_REQUEST_MASTER),
669 rsi_dbg(ERR_ZONE, "%s: AHB register read failed\n", __func__);
673 if ((addr & 0x3) == 0)
676 *read_buf = (*data >> 16);
677 *read_buf = (*read_buf & 0xFFFF);
678 } else if (size == 1) {
679 if ((addr & 0x3) == 0)
681 else if ((addr & 0x3) == 1)
682 *read_buf = (*data >> 8);
683 else if ((addr & 0x3) == 2)
684 *read_buf = (*data >> 16);
686 *read_buf = (*data >> 24);
687 *read_buf = (*read_buf & 0xFF);
697 static int rsi_sdio_master_reg_write(struct rsi_hw *adapter,
699 unsigned long data, u16 size)
701 unsigned long *data_aligned;
704 data_aligned = kzalloc(RSI_MASTER_REG_BUF_SIZE, GFP_KERNEL);
708 data_aligned = PTR_ALIGN(data_aligned, 8);
711 *data_aligned = ((data << 16) | (data & 0xFFFF));
712 } else if (size == 1) {
713 u32 temp_data = data & 0xFF;
715 *data_aligned = ((temp_data << 24) | (temp_data << 16) |
716 (temp_data << 8) | temp_data);
718 *data_aligned = data;
722 status = rsi_sdio_master_access_msword(adapter, (addr >> 16));
725 "%s: Unable to set ms word to common reg\n",
730 addr = addr & 0xFFFF;
732 /* Bring TA out of reset */
733 status = rsi_sdio_write_register_multiple
735 (addr | RSI_SD_REQUEST_MASTER),
736 (u8 *)data_aligned, size);
739 "%s: Unable to do AHB reg write\n", __func__);
746 * rsi_sdio_host_intf_write_pkt() - This function writes the packet to device.
747 * @adapter: Pointer to the adapter structure.
748 * @pkt: Pointer to the data to be written on to the device.
749 * @len: length of the data to be written on to the device.
751 * Return: 0 on success, -1 on failure.
753 static int rsi_sdio_host_intf_write_pkt(struct rsi_hw *adapter,
757 struct rsi_91x_sdiodev *dev =
758 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
759 u32 block_size = dev->tx_blk_size;
760 u32 num_blocks, address, length;
764 queueno = ((pkt[1] >> 4) & 0xf);
766 num_blocks = len / block_size;
768 if (len % block_size)
771 address = (num_blocks * block_size | (queueno << 12));
772 length = num_blocks * block_size;
774 status = rsi_sdio_write_register_multiple(adapter,
779 rsi_dbg(ERR_ZONE, "%s: Unable to write onto the card: %d\n",
781 rsi_dbg(DATA_TX_ZONE, "%s: Successfully written onto card\n", __func__);
786 * rsi_sdio_host_intf_read_pkt() - This function reads the packet
788 * @adapter: Pointer to the adapter data structure.
789 * @pkt: Pointer to the packet data to be read from the the device.
790 * @length: Length of the data to be read from the device.
792 * Return: 0 on success, -1 on failure.
794 int rsi_sdio_host_intf_read_pkt(struct rsi_hw *adapter,
798 int status = -EINVAL;
801 rsi_dbg(ERR_ZONE, "%s: Pkt size is zero\n", __func__);
805 status = rsi_sdio_read_register_multiple(adapter,
808 length); /*num of bytes*/
811 rsi_dbg(ERR_ZONE, "%s: Failed to read frame: %d\n", __func__,
817 * rsi_init_sdio_interface() - This function does init specific to SDIO.
819 * @adapter: Pointer to the adapter data structure.
820 * @pkt: Pointer to the packet data to be read from the the device.
822 * Return: 0 on success, -1 on failure.
825 static int rsi_init_sdio_interface(struct rsi_hw *adapter,
826 struct sdio_func *pfunction)
828 struct rsi_91x_sdiodev *rsi_91x_dev;
829 int status = -ENOMEM;
831 rsi_91x_dev = kzalloc(sizeof(*rsi_91x_dev), GFP_KERNEL);
835 adapter->rsi_dev = rsi_91x_dev;
837 sdio_claim_host(pfunction);
839 pfunction->enable_timeout = 100;
840 status = sdio_enable_func(pfunction);
842 rsi_dbg(ERR_ZONE, "%s: Failed to enable interface\n", __func__);
843 sdio_release_host(pfunction);
847 rsi_dbg(INIT_ZONE, "%s: Enabled the interface\n", __func__);
849 rsi_91x_dev->pfunction = pfunction;
850 adapter->device = &pfunction->dev;
852 sdio_set_drvdata(pfunction, adapter);
854 status = rsi_setupcard(adapter);
856 rsi_dbg(ERR_ZONE, "%s: Failed to setup card\n", __func__);
860 rsi_dbg(INIT_ZONE, "%s: Setup card succesfully\n", __func__);
862 status = rsi_init_sdio_slave_regs(adapter);
864 rsi_dbg(ERR_ZONE, "%s: Failed to init slave regs\n", __func__);
867 sdio_release_host(pfunction);
869 adapter->determine_event_timeout = rsi_sdio_determine_event_timeout;
870 adapter->check_hw_queue_status = rsi_sdio_check_buffer_status;
872 #ifdef CONFIG_RSI_DEBUGFS
873 adapter->num_debugfs_entries = MAX_DEBUGFS_ENTRIES;
877 sdio_disable_func(pfunction);
878 sdio_release_host(pfunction);
882 static struct rsi_host_intf_ops sdio_host_intf_ops = {
883 .write_pkt = rsi_sdio_host_intf_write_pkt,
884 .read_pkt = rsi_sdio_host_intf_read_pkt,
885 .master_access_msword = rsi_sdio_master_access_msword,
886 .read_reg_multiple = rsi_sdio_read_register_multiple,
887 .write_reg_multiple = rsi_sdio_write_register_multiple,
888 .master_reg_read = rsi_sdio_master_reg_read,
889 .master_reg_write = rsi_sdio_master_reg_write,
890 .load_data_master_write = rsi_sdio_load_data_master_write,
894 * rsi_probe() - This function is called by kernel when the driver provided
895 * Vendor and device IDs are matched. All the initialization
897 * @pfunction: Pointer to the sdio_func structure.
898 * @id: Pointer to sdio_device_id structure.
900 * Return: 0 on success, 1 on failure.
902 static int rsi_probe(struct sdio_func *pfunction,
903 const struct sdio_device_id *id)
905 struct rsi_hw *adapter;
907 rsi_dbg(INIT_ZONE, "%s: Init function called\n", __func__);
909 adapter = rsi_91x_init();
911 rsi_dbg(ERR_ZONE, "%s: Failed to init os intf ops\n",
915 adapter->rsi_host_intf = RSI_HOST_INTF_SDIO;
916 adapter->host_intf_ops = &sdio_host_intf_ops;
918 if (rsi_init_sdio_interface(adapter, pfunction)) {
919 rsi_dbg(ERR_ZONE, "%s: Failed to init sdio interface\n",
923 sdio_claim_host(pfunction);
924 if (sdio_claim_irq(pfunction, rsi_handle_interrupt)) {
925 rsi_dbg(ERR_ZONE, "%s: Failed to request IRQ\n", __func__);
926 sdio_release_host(pfunction);
929 sdio_release_host(pfunction);
930 rsi_dbg(INIT_ZONE, "%s: Registered Interrupt handler\n", __func__);
932 if (rsi_hal_device_init(adapter)) {
933 rsi_dbg(ERR_ZONE, "%s: Failed in device init\n", __func__);
934 sdio_claim_host(pfunction);
935 sdio_release_irq(pfunction);
936 sdio_disable_func(pfunction);
937 sdio_release_host(pfunction);
940 rsi_dbg(INFO_ZONE, "===> RSI Device Init Done <===\n");
942 if (rsi_sdio_master_access_msword(adapter, MISC_CFG_BASE_ADDR)) {
943 rsi_dbg(ERR_ZONE, "%s: Unable to set ms word reg\n", __func__);
949 rsi_91x_deinit(adapter);
950 rsi_dbg(ERR_ZONE, "%s: Failed in probe...Exiting\n", __func__);
954 static void ulp_read_write(struct rsi_hw *adapter, u16 addr, u32 data,
957 rsi_sdio_master_reg_write(adapter, RSI_GSPI_DATA_REG1,
958 ((addr << 6) | ((data >> 16) & 0xffff)), 2);
959 rsi_sdio_master_reg_write(adapter, RSI_GSPI_DATA_REG0,
961 rsi_sdio_master_reg_write(adapter, RSI_GSPI_CTRL_REG0,
962 RSI_GSPI_CTRL_REG0_VALUE, 2);
963 rsi_sdio_master_reg_write(adapter, RSI_GSPI_CTRL_REG1,
964 ((len_in_bits - 1) | RSI_GSPI_TRIG), 2);
968 /*This function resets and re-initializes the chip.*/
969 static void rsi_reset_chip(struct rsi_hw *adapter)
972 u8 sdio_interrupt_status = 0;
976 data = kzalloc(sizeof(u32), GFP_KERNEL);
980 rsi_dbg(INFO_ZONE, "Writing disable to wakeup register\n");
981 ret = rsi_sdio_write_register(adapter, 0, SDIO_WAKEUP_REG, &request);
984 "%s: Failed to write SDIO wakeup register\n", __func__);
988 ret = rsi_sdio_read_register(adapter, RSI_FN1_INT_REGISTER,
989 &sdio_interrupt_status);
991 rsi_dbg(ERR_ZONE, "%s: Failed to Read Intr Status Register\n",
995 rsi_dbg(INFO_ZONE, "%s: Intr Status Register value = %d\n",
996 __func__, sdio_interrupt_status);
998 /* Put Thread-Arch processor on hold */
999 if (rsi_sdio_master_access_msword(adapter, TA_BASE_ADDR)) {
1001 "%s: Unable to set ms word to common reg\n",
1006 put_unaligned_le32(TA_HOLD_THREAD_VALUE, data);
1007 if (rsi_sdio_write_register_multiple(adapter, TA_HOLD_THREAD_REG |
1008 RSI_SD_REQUEST_MASTER,
1011 "%s: Unable to hold Thread-Arch processor threads\n",
1016 /* This msleep will ensure Thread-Arch processor to go to hold
1017 * and any pending dma transfers to rf spi in device to finish.
1021 ulp_read_write(adapter, RSI_ULP_RESET_REG, RSI_ULP_WRITE_0, 32);
1022 ulp_read_write(adapter, RSI_WATCH_DOG_TIMER_1, RSI_ULP_WRITE_2, 32);
1023 ulp_read_write(adapter, RSI_WATCH_DOG_TIMER_2, RSI_ULP_WRITE_0, 32);
1024 ulp_read_write(adapter, RSI_WATCH_DOG_DELAY_TIMER_1, RSI_ULP_WRITE_50,
1026 ulp_read_write(adapter, RSI_WATCH_DOG_DELAY_TIMER_2, RSI_ULP_WRITE_0,
1028 ulp_read_write(adapter, RSI_WATCH_DOG_TIMER_ENABLE,
1029 RSI_ULP_TIMER_ENABLE, 32);
1030 /* This msleep will be sufficient for the ulp
1031 * read write operations to complete for chip reset.
1040 * rsi_disconnect() - This function performs the reverse of the probe function.
1041 * @pfunction: Pointer to the sdio_func structure.
1045 static void rsi_disconnect(struct sdio_func *pfunction)
1047 struct rsi_hw *adapter = sdio_get_drvdata(pfunction);
1048 struct rsi_91x_sdiodev *dev;
1053 dev = (struct rsi_91x_sdiodev *)adapter->rsi_dev;
1054 sdio_claim_host(pfunction);
1055 sdio_release_irq(pfunction);
1056 sdio_release_host(pfunction);
1059 rsi_mac80211_detach(adapter);
1063 rsi_reset_chip(adapter);
1065 /* Resetting to take care of the case, where-in driver is re-loaded */
1066 sdio_claim_host(pfunction);
1067 rsi_reset_card(pfunction);
1068 sdio_disable_func(pfunction);
1069 sdio_release_host(pfunction);
1070 dev->write_fail = 2;
1071 rsi_91x_deinit(adapter);
1072 rsi_dbg(ERR_ZONE, "##### RSI SDIO device disconnected #####\n");
1077 static int rsi_suspend(struct device *dev)
1079 /* Not yet implemented */
1083 static int rsi_resume(struct device *dev)
1085 /* Not yet implemented */
1089 static const struct dev_pm_ops rsi_pm_ops = {
1090 .suspend = rsi_suspend,
1091 .resume = rsi_resume,
1095 static const struct sdio_device_id rsi_dev_table[] = {
1096 { SDIO_DEVICE(0x303, 0x100) },
1097 { SDIO_DEVICE(0x041B, 0x0301) },
1098 { SDIO_DEVICE(0x041B, 0x0201) },
1099 { SDIO_DEVICE(0x041B, 0x9330) },
1103 static struct sdio_driver rsi_driver = {
1104 .name = "RSI-SDIO WLAN",
1106 .remove = rsi_disconnect,
1107 .id_table = rsi_dev_table,
1116 * rsi_module_init() - This function registers the sdio module.
1119 * Return: 0 on success.
1121 static int rsi_module_init(void)
1125 ret = sdio_register_driver(&rsi_driver);
1126 rsi_dbg(INIT_ZONE, "%s: Registering driver\n", __func__);
1131 * rsi_module_exit() - This function unregisters the sdio module.
1136 static void rsi_module_exit(void)
1138 sdio_unregister_driver(&rsi_driver);
1139 rsi_dbg(INFO_ZONE, "%s: Unregistering driver\n", __func__);
1142 module_init(rsi_module_init);
1143 module_exit(rsi_module_exit);
1145 MODULE_AUTHOR("Redpine Signals Inc");
1146 MODULE_DESCRIPTION("Common SDIO layer for RSI drivers");
1147 MODULE_SUPPORTED_DEVICE("RSI-91x");
1148 MODULE_DEVICE_TABLE(sdio, rsi_dev_table);
1150 MODULE_VERSION("0.1");
1151 MODULE_LICENSE("Dual BSD/GPL");