powerpc/eeh: Fix PE#0 check in eeh_add_to_parent_pe()
[linux/fpc-iii.git] / drivers / net / wireless / rsi / rsi_91x_sdio.c
blob8428858204a6763a6d4ccfbeb6c2c81a12e7a33f
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 "rsi_sdio.h"
20 #include "rsi_common.h"
22 /**
23 * rsi_sdio_set_cmd52_arg() - This function prepares cmd 52 read/write arg.
24 * @rw: Read/write
25 * @func: function number
26 * @raw: indicates whether to perform read after write
27 * @address: address to which to read/write
28 * @writedata: data to write
30 * Return: argument
32 static u32 rsi_sdio_set_cmd52_arg(bool rw,
33 u8 func,
34 u8 raw,
35 u32 address,
36 u8 writedata)
38 return ((rw & 1) << 31) | ((func & 0x7) << 28) |
39 ((raw & 1) << 27) | (1 << 26) |
40 ((address & 0x1FFFF) << 9) | (1 << 8) |
41 (writedata & 0xFF);
44 /**
45 * rsi_cmd52writebyte() - This function issues cmd52 byte write onto the card.
46 * @card: Pointer to the mmc_card.
47 * @address: Address to write.
48 * @byte: Data to write.
50 * Return: Write status.
52 static int rsi_cmd52writebyte(struct mmc_card *card,
53 u32 address,
54 u8 byte)
56 struct mmc_command io_cmd;
57 u32 arg;
59 memset(&io_cmd, 0, sizeof(io_cmd));
60 arg = rsi_sdio_set_cmd52_arg(1, 0, 0, address, byte);
61 io_cmd.opcode = SD_IO_RW_DIRECT;
62 io_cmd.arg = arg;
63 io_cmd.flags = MMC_RSP_R5 | MMC_CMD_AC;
65 return mmc_wait_for_cmd(card->host, &io_cmd, 0);
68 /**
69 * rsi_cmd52readbyte() - This function issues cmd52 byte read onto the card.
70 * @card: Pointer to the mmc_card.
71 * @address: Address to read from.
72 * @byte: Variable to store read value.
74 * Return: Read status.
76 static int rsi_cmd52readbyte(struct mmc_card *card,
77 u32 address,
78 u8 *byte)
80 struct mmc_command io_cmd;
81 u32 arg;
82 int err;
84 memset(&io_cmd, 0, sizeof(io_cmd));
85 arg = rsi_sdio_set_cmd52_arg(0, 0, 0, address, 0);
86 io_cmd.opcode = SD_IO_RW_DIRECT;
87 io_cmd.arg = arg;
88 io_cmd.flags = MMC_RSP_R5 | MMC_CMD_AC;
90 err = mmc_wait_for_cmd(card->host, &io_cmd, 0);
91 if ((!err) && (byte))
92 *byte = io_cmd.resp[0] & 0xFF;
93 return err;
96 /**
97 * rsi_issue_sdiocommand() - This function issues sdio commands.
98 * @func: Pointer to the sdio_func structure.
99 * @opcode: Opcode value.
100 * @arg: Arguments to pass.
101 * @flags: Flags which are set.
102 * @resp: Pointer to store response.
104 * Return: err: command status as 0 or -1.
106 static int rsi_issue_sdiocommand(struct sdio_func *func,
107 u32 opcode,
108 u32 arg,
109 u32 flags,
110 u32 *resp)
112 struct mmc_command cmd;
113 struct mmc_host *host;
114 int err;
116 host = func->card->host;
118 memset(&cmd, 0, sizeof(struct mmc_command));
119 cmd.opcode = opcode;
120 cmd.arg = arg;
121 cmd.flags = flags;
122 err = mmc_wait_for_cmd(host, &cmd, 3);
124 if ((!err) && (resp))
125 *resp = cmd.resp[0];
127 return err;
131 * rsi_handle_interrupt() - This function is called upon the occurence
132 * of an interrupt.
133 * @function: Pointer to the sdio_func structure.
135 * Return: None.
137 static void rsi_handle_interrupt(struct sdio_func *function)
139 struct rsi_hw *adapter = sdio_get_drvdata(function);
141 sdio_release_host(function);
142 rsi_interrupt_handler(adapter);
143 sdio_claim_host(function);
147 * rsi_reset_card() - This function resets and re-initializes the card.
148 * @pfunction: Pointer to the sdio_func structure.
150 * Return: None.
152 static void rsi_reset_card(struct sdio_func *pfunction)
154 int ret = 0;
155 int err;
156 struct mmc_card *card = pfunction->card;
157 struct mmc_host *host = card->host;
158 s32 bit = (fls(host->ocr_avail) - 1);
159 u8 cmd52_resp;
160 u32 clock, resp, i;
161 u16 rca;
163 /* Reset 9110 chip */
164 ret = rsi_cmd52writebyte(pfunction->card,
165 SDIO_CCCR_ABORT,
166 (1 << 3));
168 /* Card will not send any response as it is getting reset immediately
169 * Hence expect a timeout status from host controller
171 if (ret != -ETIMEDOUT)
172 rsi_dbg(ERR_ZONE, "%s: Reset failed : %d\n", __func__, ret);
174 /* Wait for few milli seconds to get rid of residue charges if any */
175 msleep(20);
177 /* Initialize the SDIO card */
178 host->ios.vdd = bit;
179 host->ios.chip_select = MMC_CS_DONTCARE;
180 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
181 host->ios.power_mode = MMC_POWER_UP;
182 host->ios.bus_width = MMC_BUS_WIDTH_1;
183 host->ios.timing = MMC_TIMING_LEGACY;
184 host->ops->set_ios(host, &host->ios);
187 * This delay should be sufficient to allow the power supply
188 * to reach the minimum voltage.
190 msleep(20);
192 host->ios.clock = host->f_min;
193 host->ios.power_mode = MMC_POWER_ON;
194 host->ops->set_ios(host, &host->ios);
197 * This delay must be at least 74 clock sizes, or 1 ms, or the
198 * time required to reach a stable voltage.
200 msleep(20);
202 /* Issue CMD0. Goto idle state */
203 host->ios.chip_select = MMC_CS_HIGH;
204 host->ops->set_ios(host, &host->ios);
205 msleep(20);
206 err = rsi_issue_sdiocommand(pfunction,
207 MMC_GO_IDLE_STATE,
209 (MMC_RSP_NONE | MMC_CMD_BC),
210 NULL);
211 host->ios.chip_select = MMC_CS_DONTCARE;
212 host->ops->set_ios(host, &host->ios);
213 msleep(20);
214 host->use_spi_crc = 0;
216 if (err)
217 rsi_dbg(ERR_ZONE, "%s: CMD0 failed : %d\n", __func__, err);
219 if (!host->ocr_avail) {
220 /* Issue CMD5, arg = 0 */
221 err = rsi_issue_sdiocommand(pfunction,
222 SD_IO_SEND_OP_COND,
224 (MMC_RSP_R4 | MMC_CMD_BCR),
225 &resp);
226 if (err)
227 rsi_dbg(ERR_ZONE, "%s: CMD5 failed : %d\n",
228 __func__, err);
229 host->ocr_avail = resp;
232 /* Issue CMD5, arg = ocr. Wait till card is ready */
233 for (i = 0; i < 100; i++) {
234 err = rsi_issue_sdiocommand(pfunction,
235 SD_IO_SEND_OP_COND,
236 host->ocr_avail,
237 (MMC_RSP_R4 | MMC_CMD_BCR),
238 &resp);
239 if (err) {
240 rsi_dbg(ERR_ZONE, "%s: CMD5 failed : %d\n",
241 __func__, err);
242 break;
245 if (resp & MMC_CARD_BUSY)
246 break;
247 msleep(20);
250 if ((i == 100) || (err)) {
251 rsi_dbg(ERR_ZONE, "%s: card in not ready : %d %d\n",
252 __func__, i, err);
253 return;
256 /* Issue CMD3, get RCA */
257 err = rsi_issue_sdiocommand(pfunction,
258 SD_SEND_RELATIVE_ADDR,
260 (MMC_RSP_R6 | MMC_CMD_BCR),
261 &resp);
262 if (err) {
263 rsi_dbg(ERR_ZONE, "%s: CMD3 failed : %d\n", __func__, err);
264 return;
266 rca = resp >> 16;
267 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
268 host->ops->set_ios(host, &host->ios);
270 /* Issue CMD7, select card */
271 err = rsi_issue_sdiocommand(pfunction,
272 MMC_SELECT_CARD,
273 (rca << 16),
274 (MMC_RSP_R1 | MMC_CMD_AC),
275 NULL);
276 if (err) {
277 rsi_dbg(ERR_ZONE, "%s: CMD7 failed : %d\n", __func__, err);
278 return;
281 /* Enable high speed */
282 if (card->host->caps & MMC_CAP_SD_HIGHSPEED) {
283 rsi_dbg(ERR_ZONE, "%s: Set high speed mode\n", __func__);
284 err = rsi_cmd52readbyte(card, SDIO_CCCR_SPEED, &cmd52_resp);
285 if (err) {
286 rsi_dbg(ERR_ZONE, "%s: CCCR speed reg read failed: %d\n",
287 __func__, err);
288 } else {
289 err = rsi_cmd52writebyte(card,
290 SDIO_CCCR_SPEED,
291 (cmd52_resp | SDIO_SPEED_EHS));
292 if (err) {
293 rsi_dbg(ERR_ZONE,
294 "%s: CCR speed regwrite failed %d\n",
295 __func__, err);
296 return;
298 host->ios.timing = MMC_TIMING_SD_HS;
299 host->ops->set_ios(host, &host->ios);
303 /* Set clock */
304 if (mmc_card_hs(card))
305 clock = 50000000;
306 else
307 clock = card->cis.max_dtr;
309 if (clock > host->f_max)
310 clock = host->f_max;
312 host->ios.clock = clock;
313 host->ops->set_ios(host, &host->ios);
315 if (card->host->caps & MMC_CAP_4_BIT_DATA) {
316 /* CMD52: Set bus width & disable card detect resistor */
317 err = rsi_cmd52writebyte(card,
318 SDIO_CCCR_IF,
319 (SDIO_BUS_CD_DISABLE |
320 SDIO_BUS_WIDTH_4BIT));
321 if (err) {
322 rsi_dbg(ERR_ZONE, "%s: Set bus mode failed : %d\n",
323 __func__, err);
324 return;
326 host->ios.bus_width = MMC_BUS_WIDTH_4;
327 host->ops->set_ios(host, &host->ios);
332 * rsi_setclock() - This function sets the clock frequency.
333 * @adapter: Pointer to the adapter structure.
334 * @freq: Clock frequency.
336 * Return: None.
338 static void rsi_setclock(struct rsi_hw *adapter, u32 freq)
340 struct rsi_91x_sdiodev *dev =
341 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
342 struct mmc_host *host = dev->pfunction->card->host;
343 u32 clock;
345 clock = freq * 1000;
346 if (clock > host->f_max)
347 clock = host->f_max;
348 host->ios.clock = clock;
349 host->ops->set_ios(host, &host->ios);
353 * rsi_setblocklength() - This function sets the host block length.
354 * @adapter: Pointer to the adapter structure.
355 * @length: Block length to be set.
357 * Return: status: 0 on success, -1 on failure.
359 static int rsi_setblocklength(struct rsi_hw *adapter, u32 length)
361 struct rsi_91x_sdiodev *dev =
362 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
363 int status;
364 rsi_dbg(INIT_ZONE, "%s: Setting the block length\n", __func__);
366 status = sdio_set_block_size(dev->pfunction, length);
367 dev->pfunction->max_blksize = 256;
369 rsi_dbg(INFO_ZONE,
370 "%s: Operational blk length is %d\n", __func__, length);
371 return status;
375 * rsi_setupcard() - This function queries and sets the card's features.
376 * @adapter: Pointer to the adapter structure.
378 * Return: status: 0 on success, -1 on failure.
380 static int rsi_setupcard(struct rsi_hw *adapter)
382 struct rsi_91x_sdiodev *dev =
383 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
384 int status = 0;
386 rsi_setclock(adapter, 50000);
388 dev->tx_blk_size = 256;
389 status = rsi_setblocklength(adapter, dev->tx_blk_size);
390 if (status)
391 rsi_dbg(ERR_ZONE,
392 "%s: Unable to set block length\n", __func__);
393 return status;
397 * rsi_sdio_read_register() - This function reads one byte of information
398 * from a register.
399 * @adapter: Pointer to the adapter structure.
400 * @addr: Address of the register.
401 * @data: Pointer to the data that stores the data read.
403 * Return: 0 on success, -1 on failure.
405 int rsi_sdio_read_register(struct rsi_hw *adapter,
406 u32 addr,
407 u8 *data)
409 struct rsi_91x_sdiodev *dev =
410 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
411 u8 fun_num = 0;
412 int status;
414 sdio_claim_host(dev->pfunction);
416 if (fun_num == 0)
417 *data = sdio_f0_readb(dev->pfunction, addr, &status);
418 else
419 *data = sdio_readb(dev->pfunction, addr, &status);
421 sdio_release_host(dev->pfunction);
423 return status;
427 * rsi_sdio_write_register() - This function writes one byte of information
428 * into a register.
429 * @adapter: Pointer to the adapter structure.
430 * @function: Function Number.
431 * @addr: Address of the register.
432 * @data: Pointer to the data tha has to be written.
434 * Return: 0 on success, -1 on failure.
436 int rsi_sdio_write_register(struct rsi_hw *adapter,
437 u8 function,
438 u32 addr,
439 u8 *data)
441 struct rsi_91x_sdiodev *dev =
442 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
443 int status = 0;
445 sdio_claim_host(dev->pfunction);
447 if (function == 0)
448 sdio_f0_writeb(dev->pfunction, *data, addr, &status);
449 else
450 sdio_writeb(dev->pfunction, *data, addr, &status);
452 sdio_release_host(dev->pfunction);
454 return status;
458 * rsi_sdio_ack_intr() - This function acks the interrupt received.
459 * @adapter: Pointer to the adapter structure.
460 * @int_bit: Interrupt bit to write into register.
462 * Return: None.
464 void rsi_sdio_ack_intr(struct rsi_hw *adapter, u8 int_bit)
466 int status;
467 status = rsi_sdio_write_register(adapter,
469 (SDIO_FUN1_INTR_CLR_REG |
470 RSI_SD_REQUEST_MASTER),
471 &int_bit);
472 if (status)
473 rsi_dbg(ERR_ZONE, "%s: unable to send ack\n", __func__);
479 * rsi_sdio_read_register_multiple() - This function read multiple bytes of
480 * information from the SD card.
481 * @adapter: Pointer to the adapter structure.
482 * @addr: Address of the register.
483 * @count: Number of multiple bytes to be read.
484 * @data: Pointer to the read data.
486 * Return: 0 on success, -1 on failure.
488 static int rsi_sdio_read_register_multiple(struct rsi_hw *adapter,
489 u32 addr,
490 u32 count,
491 u8 *data)
493 struct rsi_91x_sdiodev *dev =
494 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
495 u32 status;
497 sdio_claim_host(dev->pfunction);
499 status = sdio_readsb(dev->pfunction, data, addr, count);
501 sdio_release_host(dev->pfunction);
503 if (status != 0)
504 rsi_dbg(ERR_ZONE, "%s: Synch Cmd53 read failed\n", __func__);
505 return status;
509 * rsi_sdio_write_register_multiple() - This function writes multiple bytes of
510 * information to the SD card.
511 * @adapter: Pointer to the adapter structure.
512 * @addr: Address of the register.
513 * @data: Pointer to the data that has to be written.
514 * @count: Number of multiple bytes to be written.
516 * Return: 0 on success, -1 on failure.
518 int rsi_sdio_write_register_multiple(struct rsi_hw *adapter,
519 u32 addr,
520 u8 *data,
521 u32 count)
523 struct rsi_91x_sdiodev *dev =
524 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
525 int status;
527 if (dev->write_fail > 1) {
528 rsi_dbg(ERR_ZONE, "%s: Stopping card writes\n", __func__);
529 return 0;
530 } else if (dev->write_fail == 1) {
532 * Assuming it is a CRC failure, we want to allow another
533 * card write
535 rsi_dbg(ERR_ZONE, "%s: Continue card writes\n", __func__);
536 dev->write_fail++;
539 sdio_claim_host(dev->pfunction);
541 status = sdio_writesb(dev->pfunction, addr, data, count);
543 sdio_release_host(dev->pfunction);
545 if (status) {
546 rsi_dbg(ERR_ZONE, "%s: Synch Cmd53 write failed %d\n",
547 __func__, status);
548 dev->write_fail = 2;
549 } else {
550 memcpy(dev->prev_desc, data, FRAME_DESC_SZ);
552 return status;
556 * rsi_sdio_host_intf_write_pkt() - This function writes the packet to device.
557 * @adapter: Pointer to the adapter structure.
558 * @pkt: Pointer to the data to be written on to the device.
559 * @len: length of the data to be written on to the device.
561 * Return: 0 on success, -1 on failure.
563 static int rsi_sdio_host_intf_write_pkt(struct rsi_hw *adapter,
564 u8 *pkt,
565 u32 len)
567 struct rsi_91x_sdiodev *dev =
568 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
569 u32 block_size = dev->tx_blk_size;
570 u32 num_blocks, address, length;
571 u32 queueno;
572 int status;
574 queueno = ((pkt[1] >> 4) & 0xf);
576 num_blocks = len / block_size;
578 if (len % block_size)
579 num_blocks++;
581 address = (num_blocks * block_size | (queueno << 12));
582 length = num_blocks * block_size;
584 status = rsi_sdio_write_register_multiple(adapter,
585 address,
586 (u8 *)pkt,
587 length);
588 if (status)
589 rsi_dbg(ERR_ZONE, "%s: Unable to write onto the card: %d\n",
590 __func__, status);
591 rsi_dbg(DATA_TX_ZONE, "%s: Successfully written onto card\n", __func__);
592 return status;
596 * rsi_sdio_host_intf_read_pkt() - This function reads the packet
597 from the device.
598 * @adapter: Pointer to the adapter data structure.
599 * @pkt: Pointer to the packet data to be read from the the device.
600 * @length: Length of the data to be read from the device.
602 * Return: 0 on success, -1 on failure.
604 int rsi_sdio_host_intf_read_pkt(struct rsi_hw *adapter,
605 u8 *pkt,
606 u32 length)
608 int status = -EINVAL;
610 if (!length) {
611 rsi_dbg(ERR_ZONE, "%s: Pkt size is zero\n", __func__);
612 return status;
615 status = rsi_sdio_read_register_multiple(adapter,
616 length,
617 length, /*num of bytes*/
618 (u8 *)pkt);
620 if (status)
621 rsi_dbg(ERR_ZONE, "%s: Failed to read frame: %d\n", __func__,
622 status);
623 return status;
627 * rsi_init_sdio_interface() - This function does init specific to SDIO.
629 * @adapter: Pointer to the adapter data structure.
630 * @pkt: Pointer to the packet data to be read from the the device.
632 * Return: 0 on success, -1 on failure.
635 static int rsi_init_sdio_interface(struct rsi_hw *adapter,
636 struct sdio_func *pfunction)
638 struct rsi_91x_sdiodev *rsi_91x_dev;
639 int status = -ENOMEM;
641 rsi_91x_dev = kzalloc(sizeof(*rsi_91x_dev), GFP_KERNEL);
642 if (!rsi_91x_dev)
643 return status;
645 adapter->rsi_dev = rsi_91x_dev;
647 sdio_claim_host(pfunction);
649 pfunction->enable_timeout = 100;
650 status = sdio_enable_func(pfunction);
651 if (status) {
652 rsi_dbg(ERR_ZONE, "%s: Failed to enable interface\n", __func__);
653 sdio_release_host(pfunction);
654 return status;
657 rsi_dbg(INIT_ZONE, "%s: Enabled the interface\n", __func__);
659 rsi_91x_dev->pfunction = pfunction;
660 adapter->device = &pfunction->dev;
662 sdio_set_drvdata(pfunction, adapter);
664 status = rsi_setupcard(adapter);
665 if (status) {
666 rsi_dbg(ERR_ZONE, "%s: Failed to setup card\n", __func__);
667 goto fail;
670 rsi_dbg(INIT_ZONE, "%s: Setup card succesfully\n", __func__);
672 status = rsi_init_sdio_slave_regs(adapter);
673 if (status) {
674 rsi_dbg(ERR_ZONE, "%s: Failed to init slave regs\n", __func__);
675 goto fail;
677 sdio_release_host(pfunction);
679 adapter->host_intf_write_pkt = rsi_sdio_host_intf_write_pkt;
680 adapter->host_intf_read_pkt = rsi_sdio_host_intf_read_pkt;
681 adapter->determine_event_timeout = rsi_sdio_determine_event_timeout;
682 adapter->check_hw_queue_status = rsi_sdio_read_buffer_status_register;
684 #ifdef CONFIG_RSI_DEBUGFS
685 adapter->num_debugfs_entries = MAX_DEBUGFS_ENTRIES;
686 #endif
687 return status;
688 fail:
689 sdio_disable_func(pfunction);
690 sdio_release_host(pfunction);
691 return status;
695 * rsi_probe() - This function is called by kernel when the driver provided
696 * Vendor and device IDs are matched. All the initialization
697 * work is done here.
698 * @pfunction: Pointer to the sdio_func structure.
699 * @id: Pointer to sdio_device_id structure.
701 * Return: 0 on success, 1 on failure.
703 static int rsi_probe(struct sdio_func *pfunction,
704 const struct sdio_device_id *id)
706 struct rsi_hw *adapter;
708 rsi_dbg(INIT_ZONE, "%s: Init function called\n", __func__);
710 adapter = rsi_91x_init();
711 if (!adapter) {
712 rsi_dbg(ERR_ZONE, "%s: Failed to init os intf ops\n",
713 __func__);
714 return 1;
717 if (rsi_init_sdio_interface(adapter, pfunction)) {
718 rsi_dbg(ERR_ZONE, "%s: Failed to init sdio interface\n",
719 __func__);
720 goto fail;
723 if (rsi_sdio_device_init(adapter->priv)) {
724 rsi_dbg(ERR_ZONE, "%s: Failed in device init\n", __func__);
725 sdio_claim_host(pfunction);
726 sdio_disable_func(pfunction);
727 sdio_release_host(pfunction);
728 goto fail;
731 sdio_claim_host(pfunction);
732 if (sdio_claim_irq(pfunction, rsi_handle_interrupt)) {
733 rsi_dbg(ERR_ZONE, "%s: Failed to request IRQ\n", __func__);
734 sdio_release_host(pfunction);
735 goto fail;
738 sdio_release_host(pfunction);
739 rsi_dbg(INIT_ZONE, "%s: Registered Interrupt handler\n", __func__);
741 return 0;
742 fail:
743 rsi_91x_deinit(adapter);
744 rsi_dbg(ERR_ZONE, "%s: Failed in probe...Exiting\n", __func__);
745 return 1;
749 * rsi_disconnect() - This function performs the reverse of the probe function.
750 * @pfunction: Pointer to the sdio_func structure.
752 * Return: void.
754 static void rsi_disconnect(struct sdio_func *pfunction)
756 struct rsi_hw *adapter = sdio_get_drvdata(pfunction);
757 struct rsi_91x_sdiodev *dev;
759 if (!adapter)
760 return;
762 dev = (struct rsi_91x_sdiodev *)adapter->rsi_dev;
764 dev->write_fail = 2;
765 rsi_mac80211_detach(adapter);
767 sdio_claim_host(pfunction);
768 sdio_release_irq(pfunction);
769 sdio_disable_func(pfunction);
770 rsi_91x_deinit(adapter);
771 /* Resetting to take care of the case, where-in driver is re-loaded */
772 rsi_reset_card(pfunction);
773 sdio_release_host(pfunction);
776 #ifdef CONFIG_PM
777 static int rsi_suspend(struct device *dev)
779 /* Not yet implemented */
780 return -ENOSYS;
783 static int rsi_resume(struct device *dev)
785 /* Not yet implemented */
786 return -ENOSYS;
789 static const struct dev_pm_ops rsi_pm_ops = {
790 .suspend = rsi_suspend,
791 .resume = rsi_resume,
793 #endif
795 static const struct sdio_device_id rsi_dev_table[] = {
796 { SDIO_DEVICE(0x303, 0x100) },
797 { SDIO_DEVICE(0x041B, 0x0301) },
798 { SDIO_DEVICE(0x041B, 0x0201) },
799 { SDIO_DEVICE(0x041B, 0x9330) },
800 { /* Blank */},
803 static struct sdio_driver rsi_driver = {
804 .name = "RSI-SDIO WLAN",
805 .probe = rsi_probe,
806 .remove = rsi_disconnect,
807 .id_table = rsi_dev_table,
808 #ifdef CONFIG_PM
809 .drv = {
810 .pm = &rsi_pm_ops,
812 #endif
816 * rsi_module_init() - This function registers the sdio module.
817 * @void: Void.
819 * Return: 0 on success.
821 static int rsi_module_init(void)
823 int ret;
825 ret = sdio_register_driver(&rsi_driver);
826 rsi_dbg(INIT_ZONE, "%s: Registering driver\n", __func__);
827 return ret;
831 * rsi_module_exit() - This function unregisters the sdio module.
832 * @void: Void.
834 * Return: None.
836 static void rsi_module_exit(void)
838 sdio_unregister_driver(&rsi_driver);
839 rsi_dbg(INFO_ZONE, "%s: Unregistering driver\n", __func__);
842 module_init(rsi_module_init);
843 module_exit(rsi_module_exit);
845 MODULE_AUTHOR("Redpine Signals Inc");
846 MODULE_DESCRIPTION("Common SDIO layer for RSI drivers");
847 MODULE_SUPPORTED_DEVICE("RSI-91x");
848 MODULE_DEVICE_TABLE(sdio, rsi_dev_table);
849 MODULE_FIRMWARE(FIRMWARE_RSI9113);
850 MODULE_VERSION("0.1");
851 MODULE_LICENSE("Dual BSD/GPL");