2 * linux/drivers/mmc/sdio.c
4 * Copyright 2006-2007 Pierre Ossman
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
12 #include <linux/err.h>
14 #include <linux/mmc/host.h>
15 #include <linux/mmc/card.h>
24 * Host is being removed. Free up the current card.
26 static void mmc_sdio_remove(struct mmc_host *host)
31 mmc_remove_card(host->card);
36 * Card detection callback from host.
38 static void mmc_sdio_detect(struct mmc_host *host)
48 * Just check if our card has been removed.
50 err = mmc_select_card(host->card);
52 mmc_release_host(host);
55 mmc_sdio_remove(host);
59 mmc_release_host(host);
64 static const struct mmc_bus_ops mmc_sdio_ops = {
65 .remove = mmc_sdio_remove,
66 .detect = mmc_sdio_detect,
71 * Starting point for SDIO card init.
73 int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
77 struct mmc_card *card;
80 BUG_ON(!host->claimed);
82 mmc_attach_bus(host, &mmc_sdio_ops);
85 * Sanity check the voltages that the card claims to
89 printk(KERN_WARNING "%s: card claims to support voltages "
90 "below the defined range. These will be ignored.\n",
95 if (ocr & MMC_VDD_165_195) {
96 printk(KERN_WARNING "%s: SDIO card claims to support the "
97 "incompletely defined 'low voltage range'. This "
98 "will be ignored.\n", mmc_hostname(host));
99 ocr &= ~MMC_VDD_165_195;
102 host->ocr = mmc_select_voltage(host, ocr);
105 * Can we support the voltage(s) of the card(s)?
113 * Inform the card of the voltage
115 err = mmc_send_io_op_cond(host, host->ocr, &ocr);
120 * The number of functions on the card is encoded inside
123 funcs = (ocr & 0x70000000) >> 28;
126 * Allocate card structure.
128 card = mmc_alloc_card(host);
134 card->type = MMC_TYPE_SDIO;
139 err = mmc_send_relative_addr(host, &card->rca);
143 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
146 * Select card, as all following commands rely on that.
148 err = mmc_select_card(card);
154 mmc_release_host(host);
156 err = mmc_add_card(host->card);
163 mmc_claim_host(host);
165 mmc_remove_card(card);
168 mmc_detach_bus(host);
169 mmc_release_host(host);
171 printk(KERN_ERR "%s: error %d whilst initialising SDIO card\n",
172 mmc_hostname(host), err);