123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849 |
- /**
- * Copyright (c) 2014 Redpine Signals Inc.
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- */
- #include <linux/module.h>
- #include "rsi_sdio.h"
- #include "rsi_common.h"
- /**
- * rsi_sdio_set_cmd52_arg() - This function prepares cmd 52 read/write arg.
- * @rw: Read/write
- * @func: function number
- * @raw: indicates whether to perform read after write
- * @address: address to which to read/write
- * @writedata: data to write
- *
- * Return: argument
- */
- static u32 rsi_sdio_set_cmd52_arg(bool rw,
- u8 func,
- u8 raw,
- u32 address,
- u8 writedata)
- {
- return ((rw & 1) << 31) | ((func & 0x7) << 28) |
- ((raw & 1) << 27) | (1 << 26) |
- ((address & 0x1FFFF) << 9) | (1 << 8) |
- (writedata & 0xFF);
- }
- /**
- * rsi_cmd52writebyte() - This function issues cmd52 byte write onto the card.
- * @card: Pointer to the mmc_card.
- * @address: Address to write.
- * @byte: Data to write.
- *
- * Return: Write status.
- */
- static int rsi_cmd52writebyte(struct mmc_card *card,
- u32 address,
- u8 byte)
- {
- struct mmc_command io_cmd;
- u32 arg;
- memset(&io_cmd, 0, sizeof(io_cmd));
- arg = rsi_sdio_set_cmd52_arg(1, 0, 0, address, byte);
- io_cmd.opcode = SD_IO_RW_DIRECT;
- io_cmd.arg = arg;
- io_cmd.flags = MMC_RSP_R5 | MMC_CMD_AC;
- return mmc_wait_for_cmd(card->host, &io_cmd, 0);
- }
- /**
- * rsi_cmd52readbyte() - This function issues cmd52 byte read onto the card.
- * @card: Pointer to the mmc_card.
- * @address: Address to read from.
- * @byte: Variable to store read value.
- *
- * Return: Read status.
- */
- static int rsi_cmd52readbyte(struct mmc_card *card,
- u32 address,
- u8 *byte)
- {
- struct mmc_command io_cmd;
- u32 arg;
- int err;
- memset(&io_cmd, 0, sizeof(io_cmd));
- arg = rsi_sdio_set_cmd52_arg(0, 0, 0, address, 0);
- io_cmd.opcode = SD_IO_RW_DIRECT;
- io_cmd.arg = arg;
- io_cmd.flags = MMC_RSP_R5 | MMC_CMD_AC;
- err = mmc_wait_for_cmd(card->host, &io_cmd, 0);
- if ((!err) && (byte))
- *byte = io_cmd.resp[0] & 0xFF;
- return err;
- }
- /**
- * rsi_issue_sdiocommand() - This function issues sdio commands.
- * @func: Pointer to the sdio_func structure.
- * @opcode: Opcode value.
- * @arg: Arguments to pass.
- * @flags: Flags which are set.
- * @resp: Pointer to store response.
- *
- * Return: err: command status as 0 or -1.
- */
- static int rsi_issue_sdiocommand(struct sdio_func *func,
- u32 opcode,
- u32 arg,
- u32 flags,
- u32 *resp)
- {
- struct mmc_command cmd;
- struct mmc_host *host;
- int err;
- host = func->card->host;
- memset(&cmd, 0, sizeof(struct mmc_command));
- cmd.opcode = opcode;
- cmd.arg = arg;
- cmd.flags = flags;
- err = mmc_wait_for_cmd(host, &cmd, 3);
- if ((!err) && (resp))
- *resp = cmd.resp[0];
- return err;
- }
- /**
- * rsi_handle_interrupt() - This function is called upon the occurence
- * of an interrupt.
- * @function: Pointer to the sdio_func structure.
- *
- * Return: None.
- */
- static void rsi_handle_interrupt(struct sdio_func *function)
- {
- struct rsi_hw *adapter = sdio_get_drvdata(function);
- sdio_release_host(function);
- rsi_interrupt_handler(adapter);
- sdio_claim_host(function);
- }
- /**
- * rsi_reset_card() - This function resets and re-initializes the card.
- * @pfunction: Pointer to the sdio_func structure.
- *
- * Return: None.
- */
- static void rsi_reset_card(struct sdio_func *pfunction)
- {
- int ret = 0;
- int err;
- struct mmc_card *card = pfunction->card;
- struct mmc_host *host = card->host;
- u8 cmd52_resp;
- u32 clock, resp, i;
- u16 rca;
- /* Reset 9110 chip */
- ret = rsi_cmd52writebyte(pfunction->card,
- SDIO_CCCR_ABORT,
- (1 << 3));
- /* Card will not send any response as it is getting reset immediately
- * Hence expect a timeout status from host controller
- */
- if (ret != -ETIMEDOUT)
- rsi_dbg(ERR_ZONE, "%s: Reset failed : %d\n", __func__, ret);
- /* Wait for few milli seconds to get rid of residue charges if any */
- msleep(20);
- /* Initialize the SDIO card */
- host->ios.chip_select = MMC_CS_DONTCARE;
- host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
- host->ios.power_mode = MMC_POWER_UP;
- host->ios.bus_width = MMC_BUS_WIDTH_1;
- host->ios.timing = MMC_TIMING_LEGACY;
- host->ops->set_ios(host, &host->ios);
- /*
- * This delay should be sufficient to allow the power supply
- * to reach the minimum voltage.
- */
- msleep(20);
- host->ios.clock = host->f_min;
- host->ios.power_mode = MMC_POWER_ON;
- host->ops->set_ios(host, &host->ios);
- /*
- * This delay must be at least 74 clock sizes, or 1 ms, or the
- * time required to reach a stable voltage.
- */
- msleep(20);
- /* Issue CMD0. Goto idle state */
- host->ios.chip_select = MMC_CS_HIGH;
- host->ops->set_ios(host, &host->ios);
- msleep(20);
- err = rsi_issue_sdiocommand(pfunction,
- MMC_GO_IDLE_STATE,
- 0,
- (MMC_RSP_NONE | MMC_CMD_BC),
- NULL);
- host->ios.chip_select = MMC_CS_DONTCARE;
- host->ops->set_ios(host, &host->ios);
- msleep(20);
- host->use_spi_crc = 0;
- if (err)
- rsi_dbg(ERR_ZONE, "%s: CMD0 failed : %d\n", __func__, err);
- if (!host->ocr_avail) {
- /* Issue CMD5, arg = 0 */
- err = rsi_issue_sdiocommand(pfunction,
- SD_IO_SEND_OP_COND,
- 0,
- (MMC_RSP_R4 | MMC_CMD_BCR),
- &resp);
- if (err)
- rsi_dbg(ERR_ZONE, "%s: CMD5 failed : %d\n",
- __func__, err);
- host->ocr_avail = resp;
- }
- /* Issue CMD5, arg = ocr. Wait till card is ready */
- for (i = 0; i < 100; i++) {
- err = rsi_issue_sdiocommand(pfunction,
- SD_IO_SEND_OP_COND,
- host->ocr_avail,
- (MMC_RSP_R4 | MMC_CMD_BCR),
- &resp);
- if (err) {
- rsi_dbg(ERR_ZONE, "%s: CMD5 failed : %d\n",
- __func__, err);
- break;
- }
- if (resp & MMC_CARD_BUSY)
- break;
- msleep(20);
- }
- if ((i == 100) || (err)) {
- rsi_dbg(ERR_ZONE, "%s: card in not ready : %d %d\n",
- __func__, i, err);
- return;
- }
- /* Issue CMD3, get RCA */
- err = rsi_issue_sdiocommand(pfunction,
- SD_SEND_RELATIVE_ADDR,
- 0,
- (MMC_RSP_R6 | MMC_CMD_BCR),
- &resp);
- if (err) {
- rsi_dbg(ERR_ZONE, "%s: CMD3 failed : %d\n", __func__, err);
- return;
- }
- rca = resp >> 16;
- host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
- host->ops->set_ios(host, &host->ios);
- /* Issue CMD7, select card */
- err = rsi_issue_sdiocommand(pfunction,
- MMC_SELECT_CARD,
- (rca << 16),
- (MMC_RSP_R1 | MMC_CMD_AC),
- NULL);
- if (err) {
- rsi_dbg(ERR_ZONE, "%s: CMD7 failed : %d\n", __func__, err);
- return;
- }
- /* Enable high speed */
- if (card->host->caps & MMC_CAP_SD_HIGHSPEED) {
- rsi_dbg(ERR_ZONE, "%s: Set high speed mode\n", __func__);
- err = rsi_cmd52readbyte(card, SDIO_CCCR_SPEED, &cmd52_resp);
- if (err) {
- rsi_dbg(ERR_ZONE, "%s: CCCR speed reg read failed: %d\n",
- __func__, err);
- } else {
- err = rsi_cmd52writebyte(card,
- SDIO_CCCR_SPEED,
- (cmd52_resp | SDIO_SPEED_EHS));
- if (err) {
- rsi_dbg(ERR_ZONE,
- "%s: CCR speed regwrite failed %d\n",
- __func__, err);
- return;
- }
- host->ios.timing = MMC_TIMING_SD_HS;
- host->ops->set_ios(host, &host->ios);
- }
- }
- /* Set clock */
- if (mmc_card_hs(card))
- clock = 50000000;
- else
- clock = card->cis.max_dtr;
- if (clock > host->f_max)
- clock = host->f_max;
- host->ios.clock = clock;
- host->ops->set_ios(host, &host->ios);
- if (card->host->caps & MMC_CAP_4_BIT_DATA) {
- /* CMD52: Set bus width & disable card detect resistor */
- err = rsi_cmd52writebyte(card,
- SDIO_CCCR_IF,
- (SDIO_BUS_CD_DISABLE |
- SDIO_BUS_WIDTH_4BIT));
- if (err) {
- rsi_dbg(ERR_ZONE, "%s: Set bus mode failed : %d\n",
- __func__, err);
- return;
- }
- host->ios.bus_width = MMC_BUS_WIDTH_4;
- host->ops->set_ios(host, &host->ios);
- }
- }
- /**
- * rsi_setclock() - This function sets the clock frequency.
- * @adapter: Pointer to the adapter structure.
- * @freq: Clock frequency.
- *
- * Return: None.
- */
- static void rsi_setclock(struct rsi_hw *adapter, u32 freq)
- {
- struct rsi_91x_sdiodev *dev =
- (struct rsi_91x_sdiodev *)adapter->rsi_dev;
- struct mmc_host *host = dev->pfunction->card->host;
- u32 clock;
- clock = freq * 1000;
- if (clock > host->f_max)
- clock = host->f_max;
- host->ios.clock = clock;
- host->ops->set_ios(host, &host->ios);
- }
- /**
- * rsi_setblocklength() - This function sets the host block length.
- * @adapter: Pointer to the adapter structure.
- * @length: Block length to be set.
- *
- * Return: status: 0 on success, -1 on failure.
- */
- static int rsi_setblocklength(struct rsi_hw *adapter, u32 length)
- {
- struct rsi_91x_sdiodev *dev =
- (struct rsi_91x_sdiodev *)adapter->rsi_dev;
- int status;
- rsi_dbg(INIT_ZONE, "%s: Setting the block length\n", __func__);
- status = sdio_set_block_size(dev->pfunction, length);
- dev->pfunction->max_blksize = 256;
- rsi_dbg(INFO_ZONE,
- "%s: Operational blk length is %d\n", __func__, length);
- return status;
- }
- /**
- * rsi_setupcard() - This function queries and sets the card's features.
- * @adapter: Pointer to the adapter structure.
- *
- * Return: status: 0 on success, -1 on failure.
- */
- static int rsi_setupcard(struct rsi_hw *adapter)
- {
- struct rsi_91x_sdiodev *dev =
- (struct rsi_91x_sdiodev *)adapter->rsi_dev;
- int status = 0;
- rsi_setclock(adapter, 50000);
- dev->tx_blk_size = 256;
- status = rsi_setblocklength(adapter, dev->tx_blk_size);
- if (status)
- rsi_dbg(ERR_ZONE,
- "%s: Unable to set block length\n", __func__);
- return status;
- }
- /**
- * rsi_sdio_read_register() - This function reads one byte of information
- * from a register.
- * @adapter: Pointer to the adapter structure.
- * @addr: Address of the register.
- * @data: Pointer to the data that stores the data read.
- *
- * Return: 0 on success, -1 on failure.
- */
- int rsi_sdio_read_register(struct rsi_hw *adapter,
- u32 addr,
- u8 *data)
- {
- struct rsi_91x_sdiodev *dev =
- (struct rsi_91x_sdiodev *)adapter->rsi_dev;
- u8 fun_num = 0;
- int status;
- sdio_claim_host(dev->pfunction);
- if (fun_num == 0)
- *data = sdio_f0_readb(dev->pfunction, addr, &status);
- else
- *data = sdio_readb(dev->pfunction, addr, &status);
- sdio_release_host(dev->pfunction);
- return status;
- }
- /**
- * rsi_sdio_write_register() - This function writes one byte of information
- * into a register.
- * @adapter: Pointer to the adapter structure.
- * @function: Function Number.
- * @addr: Address of the register.
- * @data: Pointer to the data tha has to be written.
- *
- * Return: 0 on success, -1 on failure.
- */
- int rsi_sdio_write_register(struct rsi_hw *adapter,
- u8 function,
- u32 addr,
- u8 *data)
- {
- struct rsi_91x_sdiodev *dev =
- (struct rsi_91x_sdiodev *)adapter->rsi_dev;
- int status = 0;
- sdio_claim_host(dev->pfunction);
- if (function == 0)
- sdio_f0_writeb(dev->pfunction, *data, addr, &status);
- else
- sdio_writeb(dev->pfunction, *data, addr, &status);
- sdio_release_host(dev->pfunction);
- return status;
- }
- /**
- * rsi_sdio_ack_intr() - This function acks the interrupt received.
- * @adapter: Pointer to the adapter structure.
- * @int_bit: Interrupt bit to write into register.
- *
- * Return: None.
- */
- void rsi_sdio_ack_intr(struct rsi_hw *adapter, u8 int_bit)
- {
- int status;
- status = rsi_sdio_write_register(adapter,
- 1,
- (SDIO_FUN1_INTR_CLR_REG |
- RSI_SD_REQUEST_MASTER),
- &int_bit);
- if (status)
- rsi_dbg(ERR_ZONE, "%s: unable to send ack\n", __func__);
- }
- /**
- * rsi_sdio_read_register_multiple() - This function read multiple bytes of
- * information from the SD card.
- * @adapter: Pointer to the adapter structure.
- * @addr: Address of the register.
- * @count: Number of multiple bytes to be read.
- * @data: Pointer to the read data.
- *
- * Return: 0 on success, -1 on failure.
- */
- static int rsi_sdio_read_register_multiple(struct rsi_hw *adapter,
- u32 addr,
- u32 count,
- u8 *data)
- {
- struct rsi_91x_sdiodev *dev =
- (struct rsi_91x_sdiodev *)adapter->rsi_dev;
- u32 status;
- sdio_claim_host(dev->pfunction);
- status = sdio_readsb(dev->pfunction, data, addr, count);
- sdio_release_host(dev->pfunction);
- if (status != 0)
- rsi_dbg(ERR_ZONE, "%s: Synch Cmd53 read failed\n", __func__);
- return status;
- }
- /**
- * rsi_sdio_write_register_multiple() - This function writes multiple bytes of
- * information to the SD card.
- * @adapter: Pointer to the adapter structure.
- * @addr: Address of the register.
- * @data: Pointer to the data that has to be written.
- * @count: Number of multiple bytes to be written.
- *
- * Return: 0 on success, -1 on failure.
- */
- int rsi_sdio_write_register_multiple(struct rsi_hw *adapter,
- u32 addr,
- u8 *data,
- u32 count)
- {
- struct rsi_91x_sdiodev *dev =
- (struct rsi_91x_sdiodev *)adapter->rsi_dev;
- int status;
- if (dev->write_fail > 1) {
- rsi_dbg(ERR_ZONE, "%s: Stopping card writes\n", __func__);
- return 0;
- } else if (dev->write_fail == 1) {
- /**
- * Assuming it is a CRC failure, we want to allow another
- * card write
- */
- rsi_dbg(ERR_ZONE, "%s: Continue card writes\n", __func__);
- dev->write_fail++;
- }
- sdio_claim_host(dev->pfunction);
- status = sdio_writesb(dev->pfunction, addr, data, count);
- sdio_release_host(dev->pfunction);
- if (status) {
- rsi_dbg(ERR_ZONE, "%s: Synch Cmd53 write failed %d\n",
- __func__, status);
- dev->write_fail = 2;
- } else {
- memcpy(dev->prev_desc, data, FRAME_DESC_SZ);
- }
- return status;
- }
- /**
- * rsi_sdio_host_intf_write_pkt() - This function writes the packet to device.
- * @adapter: Pointer to the adapter structure.
- * @pkt: Pointer to the data to be written on to the device.
- * @len: length of the data to be written on to the device.
- *
- * Return: 0 on success, -1 on failure.
- */
- static int rsi_sdio_host_intf_write_pkt(struct rsi_hw *adapter,
- u8 *pkt,
- u32 len)
- {
- struct rsi_91x_sdiodev *dev =
- (struct rsi_91x_sdiodev *)adapter->rsi_dev;
- u32 block_size = dev->tx_blk_size;
- u32 num_blocks, address, length;
- u32 queueno;
- int status;
- queueno = ((pkt[1] >> 4) & 0xf);
- num_blocks = len / block_size;
- if (len % block_size)
- num_blocks++;
- address = (num_blocks * block_size | (queueno << 12));
- length = num_blocks * block_size;
- status = rsi_sdio_write_register_multiple(adapter,
- address,
- (u8 *)pkt,
- length);
- if (status)
- rsi_dbg(ERR_ZONE, "%s: Unable to write onto the card: %d\n",
- __func__, status);
- rsi_dbg(DATA_TX_ZONE, "%s: Successfully written onto card\n", __func__);
- return status;
- }
- /**
- * rsi_sdio_host_intf_read_pkt() - This function reads the packet
- from the device.
- * @adapter: Pointer to the adapter data structure.
- * @pkt: Pointer to the packet data to be read from the the device.
- * @length: Length of the data to be read from the device.
- *
- * Return: 0 on success, -1 on failure.
- */
- int rsi_sdio_host_intf_read_pkt(struct rsi_hw *adapter,
- u8 *pkt,
- u32 length)
- {
- int status = -EINVAL;
- if (!length) {
- rsi_dbg(ERR_ZONE, "%s: Pkt size is zero\n", __func__);
- return status;
- }
- status = rsi_sdio_read_register_multiple(adapter,
- length,
- length, /*num of bytes*/
- (u8 *)pkt);
- if (status)
- rsi_dbg(ERR_ZONE, "%s: Failed to read frame: %d\n", __func__,
- status);
- return status;
- }
- /**
- * rsi_init_sdio_interface() - This function does init specific to SDIO.
- *
- * @adapter: Pointer to the adapter data structure.
- * @pkt: Pointer to the packet data to be read from the the device.
- *
- * Return: 0 on success, -1 on failure.
- */
- static int rsi_init_sdio_interface(struct rsi_hw *adapter,
- struct sdio_func *pfunction)
- {
- struct rsi_91x_sdiodev *rsi_91x_dev;
- int status = -ENOMEM;
- rsi_91x_dev = kzalloc(sizeof(*rsi_91x_dev), GFP_KERNEL);
- if (!rsi_91x_dev)
- return status;
- adapter->rsi_dev = rsi_91x_dev;
- sdio_claim_host(pfunction);
- pfunction->enable_timeout = 100;
- status = sdio_enable_func(pfunction);
- if (status) {
- rsi_dbg(ERR_ZONE, "%s: Failed to enable interface\n", __func__);
- sdio_release_host(pfunction);
- return status;
- }
- rsi_dbg(INIT_ZONE, "%s: Enabled the interface\n", __func__);
- rsi_91x_dev->pfunction = pfunction;
- adapter->device = &pfunction->dev;
- sdio_set_drvdata(pfunction, adapter);
- status = rsi_setupcard(adapter);
- if (status) {
- rsi_dbg(ERR_ZONE, "%s: Failed to setup card\n", __func__);
- goto fail;
- }
- rsi_dbg(INIT_ZONE, "%s: Setup card succesfully\n", __func__);
- status = rsi_init_sdio_slave_regs(adapter);
- if (status) {
- rsi_dbg(ERR_ZONE, "%s: Failed to init slave regs\n", __func__);
- goto fail;
- }
- sdio_release_host(pfunction);
- adapter->host_intf_write_pkt = rsi_sdio_host_intf_write_pkt;
- adapter->host_intf_read_pkt = rsi_sdio_host_intf_read_pkt;
- adapter->determine_event_timeout = rsi_sdio_determine_event_timeout;
- adapter->check_hw_queue_status = rsi_sdio_read_buffer_status_register;
- #ifdef CONFIG_RSI_DEBUGFS
- adapter->num_debugfs_entries = MAX_DEBUGFS_ENTRIES;
- #endif
- return status;
- fail:
- sdio_disable_func(pfunction);
- sdio_release_host(pfunction);
- return status;
- }
- /**
- * rsi_probe() - This function is called by kernel when the driver provided
- * Vendor and device IDs are matched. All the initialization
- * work is done here.
- * @pfunction: Pointer to the sdio_func structure.
- * @id: Pointer to sdio_device_id structure.
- *
- * Return: 0 on success, 1 on failure.
- */
- static int rsi_probe(struct sdio_func *pfunction,
- const struct sdio_device_id *id)
- {
- struct rsi_hw *adapter;
- rsi_dbg(INIT_ZONE, "%s: Init function called\n", __func__);
- adapter = rsi_91x_init();
- if (!adapter) {
- rsi_dbg(ERR_ZONE, "%s: Failed to init os intf ops\n",
- __func__);
- return 1;
- }
- if (rsi_init_sdio_interface(adapter, pfunction)) {
- rsi_dbg(ERR_ZONE, "%s: Failed to init sdio interface\n",
- __func__);
- goto fail;
- }
- if (rsi_sdio_device_init(adapter->priv)) {
- rsi_dbg(ERR_ZONE, "%s: Failed in device init\n", __func__);
- sdio_claim_host(pfunction);
- sdio_disable_func(pfunction);
- sdio_release_host(pfunction);
- goto fail;
- }
- sdio_claim_host(pfunction);
- if (sdio_claim_irq(pfunction, rsi_handle_interrupt)) {
- rsi_dbg(ERR_ZONE, "%s: Failed to request IRQ\n", __func__);
- sdio_release_host(pfunction);
- goto fail;
- }
- sdio_release_host(pfunction);
- rsi_dbg(INIT_ZONE, "%s: Registered Interrupt handler\n", __func__);
- return 0;
- fail:
- rsi_91x_deinit(adapter);
- rsi_dbg(ERR_ZONE, "%s: Failed in probe...Exiting\n", __func__);
- return 1;
- }
- /**
- * rsi_disconnect() - This function performs the reverse of the probe function.
- * @pfunction: Pointer to the sdio_func structure.
- *
- * Return: void.
- */
- static void rsi_disconnect(struct sdio_func *pfunction)
- {
- struct rsi_hw *adapter = sdio_get_drvdata(pfunction);
- struct rsi_91x_sdiodev *dev;
- if (!adapter)
- return;
- dev = (struct rsi_91x_sdiodev *)adapter->rsi_dev;
- dev->write_fail = 2;
- rsi_mac80211_detach(adapter);
- sdio_claim_host(pfunction);
- sdio_release_irq(pfunction);
- sdio_disable_func(pfunction);
- rsi_91x_deinit(adapter);
- /* Resetting to take care of the case, where-in driver is re-loaded */
- rsi_reset_card(pfunction);
- sdio_release_host(pfunction);
- }
- #ifdef CONFIG_PM
- static int rsi_suspend(struct device *dev)
- {
- /* Not yet implemented */
- return -ENOSYS;
- }
- static int rsi_resume(struct device *dev)
- {
- /* Not yet implemented */
- return -ENOSYS;
- }
- static const struct dev_pm_ops rsi_pm_ops = {
- .suspend = rsi_suspend,
- .resume = rsi_resume,
- };
- #endif
- static const struct sdio_device_id rsi_dev_table[] = {
- { SDIO_DEVICE(0x303, 0x100) },
- { SDIO_DEVICE(0x041B, 0x0301) },
- { SDIO_DEVICE(0x041B, 0x0201) },
- { SDIO_DEVICE(0x041B, 0x9330) },
- { /* Blank */},
- };
- static struct sdio_driver rsi_driver = {
- .name = "RSI-SDIO WLAN",
- .probe = rsi_probe,
- .remove = rsi_disconnect,
- .id_table = rsi_dev_table,
- #ifdef CONFIG_PM
- .drv = {
- .pm = &rsi_pm_ops,
- }
- #endif
- };
- /**
- * rsi_module_init() - This function registers the sdio module.
- * @void: Void.
- *
- * Return: 0 on success.
- */
- static int rsi_module_init(void)
- {
- int ret;
- ret = sdio_register_driver(&rsi_driver);
- rsi_dbg(INIT_ZONE, "%s: Registering driver\n", __func__);
- return ret;
- }
- /**
- * rsi_module_exit() - This function unregisters the sdio module.
- * @void: Void.
- *
- * Return: None.
- */
- static void rsi_module_exit(void)
- {
- sdio_unregister_driver(&rsi_driver);
- rsi_dbg(INFO_ZONE, "%s: Unregistering driver\n", __func__);
- }
- module_init(rsi_module_init);
- module_exit(rsi_module_exit);
- MODULE_AUTHOR("Redpine Signals Inc");
- MODULE_DESCRIPTION("Common SDIO layer for RSI drivers");
- MODULE_SUPPORTED_DEVICE("RSI-91x");
- MODULE_DEVICE_TABLE(sdio, rsi_dev_table);
- MODULE_FIRMWARE(FIRMWARE_RSI9113);
- MODULE_VERSION("0.1");
- MODULE_LICENSE("Dual BSD/GPL");
|