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
20 #include <linux/mmc/card.h>
21 #include <linux/mmc/host.h>
24 #include "card.h"
34 struct mmc_card *card = mmc_dev_to_card(dev); in type_show() local
36 switch (card->type) { in type_show()
38 return sysfs_emit(buf, "MMC\n"); in type_show()
46 return -EFAULT; in type_show()
60 const struct mmc_card *card = mmc_dev_to_card(dev); in mmc_bus_uevent() local
65 switch (card->type) { in mmc_bus_uevent()
67 type = "MMC"; in mmc_bus_uevent()
88 if (mmc_card_sdio(card) || mmc_card_sd_combo(card)) { in mmc_bus_uevent()
90 card->cis.vendor, card->cis.device); in mmc_bus_uevent()
95 card->major_rev, card->minor_rev); in mmc_bus_uevent()
99 for (i = 0; i < card->num_info; i++) { in mmc_bus_uevent()
100 retval = add_uevent_var(env, "SDIO_INFO%u=%s", i+1, card->info[i]); in mmc_bus_uevent()
107 * SDIO (non-combo) cards are not handled by mmc_block driver and do not in mmc_bus_uevent()
110 if (mmc_card_sdio(card)) in mmc_bus_uevent()
113 retval = add_uevent_var(env, "MMC_NAME=%s", mmc_card_name(card)); in mmc_bus_uevent()
121 retval = add_uevent_var(env, "MODALIAS=mmc:block"); in mmc_bus_uevent()
128 struct mmc_driver *drv = to_mmc_driver(dev->driver); in mmc_bus_probe()
129 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_bus_probe() local
131 return drv->probe(card); in mmc_bus_probe()
136 struct mmc_driver *drv = to_mmc_driver(dev->driver); in mmc_bus_remove()
137 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_bus_remove() local
139 drv->remove(card); in mmc_bus_remove()
144 struct mmc_driver *drv = to_mmc_driver(dev->driver); in mmc_bus_shutdown()
145 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_bus_shutdown() local
146 struct mmc_host *host = card->host; in mmc_bus_shutdown()
149 if (dev->driver && drv->shutdown) in mmc_bus_shutdown()
150 drv->shutdown(card); in mmc_bus_shutdown()
154 if (host->bus_ops->shutdown) { in mmc_bus_shutdown()
155 ret = host->bus_ops->shutdown(host); in mmc_bus_shutdown()
165 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_bus_suspend() local
166 struct mmc_host *host = card->host; in mmc_bus_suspend()
173 ret = host->bus_ops->suspend(host); in mmc_bus_suspend()
182 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_bus_resume() local
183 struct mmc_host *host = card->host; in mmc_bus_resume()
186 ret = host->bus_ops->resume(host); in mmc_bus_resume()
188 pr_warn("%s: error %d during resume (card was removed?)\n", in mmc_bus_resume()
199 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_runtime_suspend() local
200 struct mmc_host *host = card->host; in mmc_runtime_suspend()
202 return host->bus_ops->runtime_suspend(host); in mmc_runtime_suspend()
207 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_runtime_resume() local
208 struct mmc_host *host = card->host; in mmc_runtime_resume()
210 return host->bus_ops->runtime_resume(host); in mmc_runtime_resume()
220 .name = "mmc",
240 * mmc_register_driver - register a media driver
241 * @drv: MMC media driver
245 drv->drv.bus = &mmc_bus_type; in mmc_register_driver()
246 return driver_register(&drv->drv); in mmc_register_driver()
252 * mmc_unregister_driver - unregister a media driver
253 * @drv: MMC media driver
257 drv->drv.bus = &mmc_bus_type; in mmc_unregister_driver()
258 driver_unregister(&drv->drv); in mmc_unregister_driver()
265 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_release_card() local
267 sdio_free_common_cis(card); in mmc_release_card()
269 kfree(card->info); in mmc_release_card()
271 kfree(card); in mmc_release_card()
275 * Allocate and initialise a new MMC card structure.
279 struct mmc_card *card; in mmc_alloc_card() local
281 card = kzalloc(sizeof(struct mmc_card), GFP_KERNEL); in mmc_alloc_card()
282 if (!card) in mmc_alloc_card()
283 return ERR_PTR(-ENOMEM); in mmc_alloc_card()
285 card->host = host; in mmc_alloc_card()
287 device_initialize(&card->dev); in mmc_alloc_card()
289 card->dev.parent = mmc_classdev(host); in mmc_alloc_card()
290 card->dev.bus = &mmc_bus_type; in mmc_alloc_card()
291 card->dev.release = mmc_release_card; in mmc_alloc_card()
292 card->dev.type = type; in mmc_alloc_card()
294 return card; in mmc_alloc_card()
298 * Register a new MMC card with the driver model.
300 int mmc_add_card(struct mmc_card *card) in mmc_add_card() argument
315 dev_set_name(&card->dev, "%s:%04x", mmc_hostname(card->host), card->rca); in mmc_add_card()
316 dev_set_removable(&card->dev, in mmc_add_card()
317 mmc_card_is_removable(card->host) ? in mmc_add_card()
320 switch (card->type) { in mmc_add_card()
322 type = "MMC"; in mmc_add_card()
326 if (mmc_card_blockaddr(card)) { in mmc_add_card()
327 if (mmc_card_ult_capacity(card)) in mmc_add_card()
329 else if (mmc_card_ext_capacity(card)) in mmc_add_card()
339 type = "SD-combo"; in mmc_add_card()
340 if (mmc_card_blockaddr(card)) in mmc_add_card()
341 type = "SDHC-combo"; in mmc_add_card()
348 if (mmc_card_hs(card)) in mmc_add_card()
350 else if (mmc_card_uhs(card)) in mmc_add_card()
351 speed_mode = "UHS-I speed "; in mmc_add_card()
352 else if (mmc_card_uhs2(card->host)) in mmc_add_card()
353 speed_mode = "UHS-II speed "; in mmc_add_card()
354 else if (mmc_card_ddr52(card)) in mmc_add_card()
356 else if (mmc_card_hs200(card)) in mmc_add_card()
358 else if (mmc_card_hs400es(card)) in mmc_add_card()
360 else if (mmc_card_hs400(card)) in mmc_add_card()
363 if (mmc_card_uhs(card) && in mmc_add_card()
364 (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds))) in mmc_add_card()
365 uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed]; in mmc_add_card()
367 if (mmc_host_is_spi(card->host)) in mmc_add_card()
368 pr_info("%s: new %s%s card on SPI\n", in mmc_add_card()
369 mmc_hostname(card->host), speed_mode, type); in mmc_add_card()
371 pr_info("%s: new %s%s%s card at address %04x\n", in mmc_add_card()
372 mmc_hostname(card->host), speed_mode, in mmc_add_card()
373 uhs_bus_speed_mode, type, card->rca); in mmc_add_card()
375 mmc_add_card_debugfs(card); in mmc_add_card()
376 card->dev.of_node = mmc_of_find_child_device(card->host, 0); in mmc_add_card()
378 device_enable_async_suspend(&card->dev); in mmc_add_card()
380 ret = device_add(&card->dev); in mmc_add_card()
384 mmc_card_set_present(card); in mmc_add_card()
390 * Unregister a new MMC card with the driver model, and
393 void mmc_remove_card(struct mmc_card *card) in mmc_remove_card() argument
395 struct mmc_host *host = card->host; in mmc_remove_card()
397 mmc_remove_card_debugfs(card); in mmc_remove_card()
399 if (mmc_card_present(card)) { in mmc_remove_card()
400 if (mmc_host_is_spi(card->host)) { in mmc_remove_card()
401 pr_info("%s: SPI card removed\n", in mmc_remove_card()
402 mmc_hostname(card->host)); in mmc_remove_card()
404 pr_info("%s: card %04x removed\n", in mmc_remove_card()
405 mmc_hostname(card->host), card->rca); in mmc_remove_card()
407 device_del(&card->dev); in mmc_remove_card()
408 of_node_put(card->dev.of_node); in mmc_remove_card()
411 if (host->cqe_enabled) { in mmc_remove_card()
412 host->cqe_ops->cqe_disable(host); in mmc_remove_card()
413 host->cqe_enabled = false; in mmc_remove_card()
416 put_device(&card->dev); in mmc_remove_card()