Lines Matching +full:mmc +full:- +full:card
1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/mmc/core/bus.c
8 * MMC card bus driver model
19 #include <linux/mmc/card.h>
20 #include <linux/mmc/host.h>
23 #include "card.h"
33 struct mmc_card *card = mmc_dev_to_card(dev); in type_show() local
35 switch (card->type) { in type_show()
37 return sprintf(buf, "MMC\n"); in type_show()
45 return -EFAULT; in type_show()
57 * This currently matches any MMC driver to any MMC card - drivers
58 * themselves make the decision whether to drive this card in their
69 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_bus_uevent() local
74 switch (card->type) { in mmc_bus_uevent()
76 type = "MMC"; in mmc_bus_uevent()
97 if (card->type == MMC_TYPE_SDIO || card->type == MMC_TYPE_SD_COMBO) { in mmc_bus_uevent()
99 card->cis.vendor, card->cis.device); in mmc_bus_uevent()
104 card->major_rev, card->minor_rev); in mmc_bus_uevent()
108 for (i = 0; i < card->num_info; i++) { in mmc_bus_uevent()
109 retval = add_uevent_var(env, "SDIO_INFO%u=%s", i+1, card->info[i]); in mmc_bus_uevent()
116 * SDIO (non-combo) cards are not handled by mmc_block driver and do not in mmc_bus_uevent()
119 if (card->type == MMC_TYPE_SDIO) in mmc_bus_uevent()
122 retval = add_uevent_var(env, "MMC_NAME=%s", mmc_card_name(card)); in mmc_bus_uevent()
130 retval = add_uevent_var(env, "MODALIAS=mmc:block"); in mmc_bus_uevent()
137 struct mmc_driver *drv = to_mmc_driver(dev->driver); in mmc_bus_probe()
138 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_bus_probe() local
140 return drv->probe(card); in mmc_bus_probe()
145 struct mmc_driver *drv = to_mmc_driver(dev->driver); in mmc_bus_remove()
146 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_bus_remove() local
148 drv->remove(card); in mmc_bus_remove()
155 struct mmc_driver *drv = to_mmc_driver(dev->driver); in mmc_bus_shutdown()
156 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_bus_shutdown() local
157 struct mmc_host *host = card->host; in mmc_bus_shutdown()
160 if (dev->driver && drv->shutdown) in mmc_bus_shutdown()
161 drv->shutdown(card); in mmc_bus_shutdown()
163 if (host->bus_ops->shutdown) { in mmc_bus_shutdown()
164 ret = host->bus_ops->shutdown(host); in mmc_bus_shutdown()
174 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_bus_suspend() local
175 struct mmc_host *host = card->host; in mmc_bus_suspend()
182 ret = host->bus_ops->suspend(host); in mmc_bus_suspend()
191 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_bus_resume() local
192 struct mmc_host *host = card->host; in mmc_bus_resume()
195 ret = host->bus_ops->resume(host); in mmc_bus_resume()
197 pr_warn("%s: error %d during resume (card was removed?)\n", in mmc_bus_resume()
208 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_runtime_suspend() local
209 struct mmc_host *host = card->host; in mmc_runtime_suspend()
211 return host->bus_ops->runtime_suspend(host); in mmc_runtime_suspend()
216 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_runtime_resume() local
217 struct mmc_host *host = card->host; in mmc_runtime_resume()
219 return host->bus_ops->runtime_resume(host); in mmc_runtime_resume()
229 .name = "mmc",
250 * mmc_register_driver - register a media driver
251 * @drv: MMC media driver
255 drv->drv.bus = &mmc_bus_type; in mmc_register_driver()
256 return driver_register(&drv->drv); in mmc_register_driver()
262 * mmc_unregister_driver - unregister a media driver
263 * @drv: MMC media driver
267 drv->drv.bus = &mmc_bus_type; in mmc_unregister_driver()
268 driver_unregister(&drv->drv); in mmc_unregister_driver()
275 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_release_card() local
277 sdio_free_common_cis(card); in mmc_release_card()
279 kfree(card->info); in mmc_release_card()
281 kfree(card); in mmc_release_card()
285 * Allocate and initialise a new MMC card structure.
289 struct mmc_card *card; in mmc_alloc_card() local
291 card = kzalloc(sizeof(struct mmc_card), GFP_KERNEL); in mmc_alloc_card()
292 if (!card) in mmc_alloc_card()
293 return ERR_PTR(-ENOMEM); in mmc_alloc_card()
295 card->host = host; in mmc_alloc_card()
297 device_initialize(&card->dev); in mmc_alloc_card()
299 card->dev.parent = mmc_classdev(host); in mmc_alloc_card()
300 card->dev.bus = &mmc_bus_type; in mmc_alloc_card()
301 card->dev.release = mmc_release_card; in mmc_alloc_card()
302 card->dev.type = type; in mmc_alloc_card()
304 return card; in mmc_alloc_card()
308 * Register a new MMC card with the driver model.
310 int mmc_add_card(struct mmc_card *card) in mmc_add_card() argument
324 dev_set_name(&card->dev, "%s:%04x", mmc_hostname(card->host), card->rca); in mmc_add_card()
326 switch (card->type) { in mmc_add_card()
328 type = "MMC"; in mmc_add_card()
332 if (mmc_card_blockaddr(card)) { in mmc_add_card()
333 if (mmc_card_ext_capacity(card)) in mmc_add_card()
343 type = "SD-combo"; in mmc_add_card()
344 if (mmc_card_blockaddr(card)) in mmc_add_card()
345 type = "SDHC-combo"; in mmc_add_card()
352 if (mmc_card_uhs(card) && in mmc_add_card()
353 (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds))) in mmc_add_card()
354 uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed]; in mmc_add_card()
356 if (mmc_host_is_spi(card->host)) { in mmc_add_card()
357 pr_info("%s: new %s%s%s card on SPI\n", in mmc_add_card()
358 mmc_hostname(card->host), in mmc_add_card()
359 mmc_card_hs(card) ? "high speed " : "", in mmc_add_card()
360 mmc_card_ddr52(card) ? "DDR " : "", in mmc_add_card()
363 pr_info("%s: new %s%s%s%s%s%s card at address %04x\n", in mmc_add_card()
364 mmc_hostname(card->host), in mmc_add_card()
365 mmc_card_uhs(card) ? "ultra high speed " : in mmc_add_card()
366 (mmc_card_hs(card) ? "high speed " : ""), in mmc_add_card()
367 mmc_card_hs400(card) ? "HS400 " : in mmc_add_card()
368 (mmc_card_hs200(card) ? "HS200 " : ""), in mmc_add_card()
369 mmc_card_hs400es(card) ? "Enhanced strobe " : "", in mmc_add_card()
370 mmc_card_ddr52(card) ? "DDR " : "", in mmc_add_card()
371 uhs_bus_speed_mode, type, card->rca); in mmc_add_card()
375 mmc_add_card_debugfs(card); in mmc_add_card()
377 card->dev.of_node = mmc_of_find_child_device(card->host, 0); in mmc_add_card()
379 device_enable_async_suspend(&card->dev); in mmc_add_card()
381 ret = device_add(&card->dev); in mmc_add_card()
385 mmc_card_set_present(card); in mmc_add_card()
391 * Unregister a new MMC card with the driver model, and
394 void mmc_remove_card(struct mmc_card *card) in mmc_remove_card() argument
396 struct mmc_host *host = card->host; in mmc_remove_card()
399 mmc_remove_card_debugfs(card); in mmc_remove_card()
402 if (host->cqe_enabled) { in mmc_remove_card()
403 host->cqe_ops->cqe_disable(host); in mmc_remove_card()
404 host->cqe_enabled = false; in mmc_remove_card()
407 if (mmc_card_present(card)) { in mmc_remove_card()
408 if (mmc_host_is_spi(card->host)) { in mmc_remove_card()
409 pr_info("%s: SPI card removed\n", in mmc_remove_card()
410 mmc_hostname(card->host)); in mmc_remove_card()
412 pr_info("%s: card %04x removed\n", in mmc_remove_card()
413 mmc_hostname(card->host), card->rca); in mmc_remove_card()
415 device_del(&card->dev); in mmc_remove_card()
416 of_node_put(card->dev.of_node); in mmc_remove_card()
419 put_device(&card->dev); in mmc_remove_card()