2019-06-04 16:11:33 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2007-02-28 22:33:10 +08:00
|
|
|
* linux/drivers/mmc/core/core.h
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Russell King, All Rights Reserved.
|
2006-12-25 05:46:55 +08:00
|
|
|
* Copyright 2007 Pierre Ossman
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2006-12-25 05:46:55 +08:00
|
|
|
#ifndef _MMC_CORE_CORE_H
|
|
|
|
#define _MMC_CORE_CORE_H
|
2005-08-19 16:41:24 +08:00
|
|
|
|
2006-12-25 05:46:55 +08:00
|
|
|
#include <linux/delay.h>
|
2017-01-13 21:14:07 +08:00
|
|
|
#include <linux/sched.h>
|
|
|
|
|
|
|
|
struct mmc_host;
|
|
|
|
struct mmc_card;
|
2017-01-13 21:14:08 +08:00
|
|
|
struct mmc_request;
|
2006-12-25 05:46:55 +08:00
|
|
|
|
|
|
|
#define MMC_CMD_RETRIES 3
|
|
|
|
|
2006-12-31 07:11:32 +08:00
|
|
|
struct mmc_bus_ops {
|
|
|
|
void (*remove)(struct mmc_host *);
|
|
|
|
void (*detect)(struct mmc_host *);
|
2013-06-10 23:03:37 +08:00
|
|
|
int (*pre_suspend)(struct mmc_host *);
|
2009-09-23 07:45:29 +08:00
|
|
|
int (*suspend)(struct mmc_host *);
|
|
|
|
int (*resume)(struct mmc_host *);
|
2013-05-02 20:02:37 +08:00
|
|
|
int (*runtime_suspend)(struct mmc_host *);
|
|
|
|
int (*runtime_resume)(struct mmc_host *);
|
2011-11-28 22:22:00 +08:00
|
|
|
int (*alive)(struct mmc_host *);
|
2013-06-10 23:03:41 +08:00
|
|
|
int (*shutdown)(struct mmc_host *);
|
2018-04-05 19:24:43 +08:00
|
|
|
int (*hw_reset)(struct mmc_host *);
|
2018-04-05 19:42:00 +08:00
|
|
|
int (*sw_reset)(struct mmc_host *);
|
2021-04-25 14:02:06 +08:00
|
|
|
bool (*cache_enabled)(struct mmc_host *);
|
2021-05-06 22:58:28 +08:00
|
|
|
int (*flush_cache)(struct mmc_host *);
|
2006-12-31 07:11:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
|
|
|
|
void mmc_detach_bus(struct mmc_host *host);
|
|
|
|
|
2014-06-30 17:07:25 +08:00
|
|
|
struct device_node *mmc_of_find_child_device(struct mmc_host *host,
|
|
|
|
unsigned func_num);
|
|
|
|
|
mmc: add erase, secure erase, trim and secure trim operations
SD/MMC cards tend to support an erase operation. In addition, eMMC v4.4
cards can support secure erase, trim and secure trim operations that are
all variants of the basic erase command.
SD/MMC device attributes "erase_size" and "preferred_erase_size" have been
added.
"erase_size" is the minimum size, in bytes, of an erase operation. For
MMC, "erase_size" is the erase group size reported by the card. Note that
"erase_size" does not apply to trim or secure trim operations where the
minimum size is always one 512 byte sector. For SD, "erase_size" is 512
if the card is block-addressed, 0 otherwise.
SD/MMC cards can erase an arbitrarily large area up to and
including the whole card. When erasing a large area it may
be desirable to do it in smaller chunks for three reasons:
1. A single erase command will make all other I/O on the card
wait. This is not a problem if the whole card is being erased, but
erasing one partition will make I/O for another partition on the
same card wait for the duration of the erase - which could be a
several minutes.
2. To be able to inform the user of erase progress.
3. The erase timeout becomes too large to be very useful.
Because the erase timeout contains a margin which is multiplied by
the size of the erase area, the value can end up being several
minutes for large areas.
"erase_size" is not the most efficient unit to erase (especially for SD
where it is just one sector), hence "preferred_erase_size" provides a good
chunk size for erasing large areas.
For MMC, "preferred_erase_size" is the high-capacity erase size if a card
specifies one, otherwise it is based on the capacity of the card.
For SD, "preferred_erase_size" is the allocation unit size specified by
the card.
"preferred_erase_size" is in bytes.
Signed-off-by: Adrian Hunter <adrian.hunter@nokia.com>
Acked-by: Jens Axboe <axboe@kernel.dk>
Cc: Kyungmin Park <kmpark@infradead.org>
Cc: Madhusudhan Chikkature <madhu.cr@ti.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Ben Gardiner <bengardiner@nanometrics.ca>
Cc: <linux-mmc@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-08-12 05:17:46 +08:00
|
|
|
void mmc_init_erase(struct mmc_card *card);
|
|
|
|
|
2006-12-25 05:46:55 +08:00
|
|
|
void mmc_set_chip_select(struct mmc_host *host, int mode);
|
2006-12-31 07:11:32 +08:00
|
|
|
void mmc_set_clock(struct mmc_host *host, unsigned int hz);
|
|
|
|
void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
|
|
|
|
void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
|
|
|
|
u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
|
2017-01-25 17:25:01 +08:00
|
|
|
int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr);
|
2017-09-25 16:29:03 +08:00
|
|
|
int mmc_host_set_uhs_voltage(struct mmc_host *host);
|
2017-01-25 18:12:34 +08:00
|
|
|
int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
|
2018-04-06 03:24:15 +08:00
|
|
|
void mmc_set_initial_signal_voltage(struct mmc_host *host);
|
2006-12-31 07:11:32 +08:00
|
|
|
void mmc_set_timing(struct mmc_host *host, unsigned int timing);
|
2011-05-05 14:48:59 +08:00
|
|
|
void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
|
2015-02-06 20:12:55 +08:00
|
|
|
int mmc_select_drive_strength(struct mmc_card *card, unsigned int max_dtr,
|
|
|
|
int card_drv_type, int *drv_type);
|
2013-09-12 20:36:53 +08:00
|
|
|
void mmc_power_up(struct mmc_host *host, u32 ocr);
|
2011-09-22 02:08:13 +08:00
|
|
|
void mmc_power_off(struct mmc_host *host);
|
2013-09-12 20:36:53 +08:00
|
|
|
void mmc_power_cycle(struct mmc_host *host, u32 ocr);
|
2014-11-06 21:46:54 +08:00
|
|
|
void mmc_set_initial_state(struct mmc_host *host);
|
2019-02-14 01:10:37 +08:00
|
|
|
u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max);
|
2006-12-31 07:11:32 +08:00
|
|
|
|
2006-12-25 05:46:55 +08:00
|
|
|
static inline void mmc_delay(unsigned int ms)
|
|
|
|
{
|
2017-11-15 06:55:20 +08:00
|
|
|
if (ms <= 20)
|
|
|
|
usleep_range(ms * 1000, ms * 1250);
|
|
|
|
else
|
2006-12-25 05:46:55 +08:00
|
|
|
msleep(ms);
|
|
|
|
}
|
2006-10-04 17:15:41 +08:00
|
|
|
|
2007-05-19 20:06:24 +08:00
|
|
|
void mmc_rescan(struct work_struct *work);
|
|
|
|
void mmc_start_host(struct mmc_host *host);
|
2021-12-03 22:15:54 +08:00
|
|
|
void __mmc_stop_host(struct mmc_host *host);
|
2007-05-19 20:06:24 +08:00
|
|
|
void mmc_stop_host(struct mmc_host *host);
|
|
|
|
|
mmc: core: Re-work HW reset for SDIO cards
It have turned out that it's not a good idea to unconditionally do a power
cycle and then to re-initialize the SDIO card, as currently done through
mmc_hw_reset() -> mmc_sdio_hw_reset(). This because there may be multiple
SDIO func drivers probed, who also shares the same SDIO card.
To address these scenarios, one may be tempted to use a notification
mechanism, as to allow the core to inform each of the probed func drivers,
about an ongoing HW reset. However, supporting such an operation from the
func driver point of view, may not be entirely trivial.
Therefore, let's use a more simplistic approach to solve the problem, by
instead forcing the card to be removed and re-detected, via scheduling a
rescan-work. In this way, we can rely on existing infrastructure, as the
func driver's ->remove() and ->probe() callbacks, becomes invoked to deal
with the cleanup and the re-initialization.
This solution may be considered as rather heavy, especially if a func
driver doesn't share its card with other func drivers. To address this,
let's keep the current immediate HW reset option as well, but run it only
when there is one func driver probed for the card.
Finally, to allow the caller of mmc_hw_reset(), to understand if the reset
is being asynchronously managed from a scheduled work, it returns 1
(propagated from mmc_sdio_hw_reset()). If the HW reset is executed
successfully and synchronously it returns 0, which maintains the existing
behaviour.
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Douglas Anderson <dianders@chromium.org>
Cc: stable@vger.kernel.org # v5.4+
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2019-10-17 21:25:36 +08:00
|
|
|
void _mmc_detect_change(struct mmc_host *host, unsigned long delay,
|
|
|
|
bool cd_irq);
|
2011-11-28 22:22:00 +08:00
|
|
|
int _mmc_detect_card_removed(struct mmc_host *host);
|
2017-01-13 21:14:08 +08:00
|
|
|
int mmc_detect_card_removed(struct mmc_host *host);
|
2011-11-28 22:22:00 +08:00
|
|
|
|
2011-01-04 02:36:56 +08:00
|
|
|
int mmc_attach_mmc(struct mmc_host *host);
|
|
|
|
int mmc_attach_sd(struct mmc_host *host);
|
|
|
|
int mmc_attach_sdio(struct mmc_host *host);
|
2008-04-14 02:15:50 +08:00
|
|
|
|
2009-12-15 10:01:29 +08:00
|
|
|
/* Module parameters */
|
2012-01-13 07:02:20 +08:00
|
|
|
extern bool use_spi_crc;
|
MMC core learns about SPI
Teach the MMC/SD/SDIO core about using SPI mode.
- Use mmc_host_is_spi() so enumeration works through SPI signaling
and protocols, not just the native versions.
- Provide the SPI response type flags with each request issued,
including requests from the new lock/unlock code.
- Understand that cmd->resp[0] and mmc_get_status() results for SPI
return different values than for "native" MMC/SD protocol; this
affects resetting, checking card lock status, and some others.
- Understand that some commands act a bit differently ... notably:
* OP_COND command doesn't return the OCR
* APP_CMD status doesn't have an R1_APP_CMD analogue
Those changes required some new and updated primitives:
- Provide utilities to access two SPI-only requests, and one
request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only (override by module parm)
* mmc_send_cid() ... for use without broadcast mode
- Updated internal routines:
* Previous mmc_send_csd() modified into mmc_send_cxd_native();
it uses native "R2" responses, which include 16 bytes of data.
* Previous mmc_send_ext_csd() becomes new mmc_send_cxd_data()
helper for command-and-data access
* Bugfix to that mmc_send_cxd_data() code: dma-to-stack is
unsafe/nonportable, so kmalloc a bounce buffer instead.
- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper
- Modified mmc_send_csd(), and new mmc_spi_send_cid(), routines use
those helper routines based on whether they're native or SPI
The newest categories of cards supported by the MMC stack aren't expected
to work yet with SPI: MMC or SD cards with over 4GB data, and SDIO.
All those cards support SPI mode, so eventually they should work too.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
2007-08-09 00:11:32 +08:00
|
|
|
|
2008-07-24 20:18:57 +08:00
|
|
|
/* Debugfs information for hosts and cards */
|
|
|
|
void mmc_add_host_debugfs(struct mmc_host *host);
|
|
|
|
void mmc_remove_host_debugfs(struct mmc_host *host);
|
|
|
|
|
2008-07-24 20:18:58 +08:00
|
|
|
void mmc_add_card_debugfs(struct mmc_card *card);
|
|
|
|
void mmc_remove_card_debugfs(struct mmc_card *card);
|
|
|
|
|
2014-12-06 01:40:59 +08:00
|
|
|
int mmc_execute_tuning(struct mmc_card *card);
|
2015-05-07 18:10:20 +08:00
|
|
|
int mmc_hs200_to_hs400(struct mmc_card *card);
|
|
|
|
int mmc_hs400_to_hs200(struct mmc_card *card);
|
2014-12-06 01:40:59 +08:00
|
|
|
|
2017-01-13 21:14:08 +08:00
|
|
|
void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq);
|
|
|
|
bool mmc_is_req_done(struct mmc_host *host, struct mmc_request *mrq);
|
|
|
|
|
2017-09-22 20:36:59 +08:00
|
|
|
int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq);
|
|
|
|
|
2017-01-13 21:14:08 +08:00
|
|
|
int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
|
|
|
|
unsigned int arg);
|
|
|
|
int mmc_can_erase(struct mmc_card *card);
|
|
|
|
int mmc_can_trim(struct mmc_card *card);
|
|
|
|
int mmc_can_discard(struct mmc_card *card);
|
|
|
|
int mmc_can_sanitize(struct mmc_card *card);
|
|
|
|
int mmc_can_secure_erase_trim(struct mmc_card *card);
|
|
|
|
int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
|
|
|
|
unsigned int nr);
|
|
|
|
unsigned int mmc_calc_max_discard(struct mmc_card *card);
|
|
|
|
|
|
|
|
int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen);
|
|
|
|
|
2017-09-22 20:36:51 +08:00
|
|
|
int __mmc_claim_host(struct mmc_host *host, struct mmc_ctx *ctx,
|
|
|
|
atomic_t *abort);
|
2017-01-13 21:14:08 +08:00
|
|
|
void mmc_release_host(struct mmc_host *host);
|
2017-09-22 20:36:51 +08:00
|
|
|
void mmc_get_card(struct mmc_card *card, struct mmc_ctx *ctx);
|
|
|
|
void mmc_put_card(struct mmc_card *card, struct mmc_ctx *ctx);
|
2017-01-13 21:14:08 +08:00
|
|
|
|
2021-08-20 08:45:35 +08:00
|
|
|
int mmc_card_alternative_gpt_sector(struct mmc_card *card, sector_t *sector);
|
|
|
|
|
2017-01-13 21:14:08 +08:00
|
|
|
/**
|
|
|
|
* mmc_claim_host - exclusively claim a host
|
|
|
|
* @host: mmc host to claim
|
|
|
|
*
|
|
|
|
* Claim a host for a set of operations.
|
|
|
|
*/
|
|
|
|
static inline void mmc_claim_host(struct mmc_host *host)
|
|
|
|
{
|
2017-09-22 20:36:51 +08:00
|
|
|
__mmc_claim_host(host, NULL, NULL);
|
2017-01-13 21:14:08 +08:00
|
|
|
}
|
2006-12-25 05:46:55 +08:00
|
|
|
|
2017-09-22 20:36:52 +08:00
|
|
|
int mmc_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq);
|
|
|
|
void mmc_cqe_post_req(struct mmc_host *host, struct mmc_request *mrq);
|
|
|
|
int mmc_cqe_recovery(struct mmc_host *host);
|
|
|
|
|
2017-11-29 21:41:00 +08:00
|
|
|
/**
|
|
|
|
* mmc_pre_req - Prepare for a new request
|
|
|
|
* @host: MMC host to prepare command
|
|
|
|
* @mrq: MMC request to prepare for
|
|
|
|
*
|
|
|
|
* mmc_pre_req() is called in prior to mmc_start_req() to let
|
|
|
|
* host prepare for the new request. Preparation of a request may be
|
|
|
|
* performed while another request is running on the host.
|
|
|
|
*/
|
|
|
|
static inline void mmc_pre_req(struct mmc_host *host, struct mmc_request *mrq)
|
|
|
|
{
|
|
|
|
if (host->ops->pre_req)
|
|
|
|
host->ops->pre_req(host, mrq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mmc_post_req - Post process a completed request
|
|
|
|
* @host: MMC host to post process command
|
|
|
|
* @mrq: MMC request to post process for
|
|
|
|
* @err: Error, if non zero, clean up any resources made in pre_req
|
|
|
|
*
|
|
|
|
* Let the host post process a completed request. Post processing of
|
|
|
|
* a request may be performed while another request is running.
|
|
|
|
*/
|
|
|
|
static inline void mmc_post_req(struct mmc_host *host, struct mmc_request *mrq,
|
|
|
|
int err)
|
|
|
|
{
|
|
|
|
if (host->ops->post_req)
|
|
|
|
host->ops->post_req(host, mrq, err);
|
|
|
|
}
|
|
|
|
|
2021-04-25 14:02:06 +08:00
|
|
|
static inline bool mmc_cache_enabled(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
if (host->bus_ops->cache_enabled)
|
|
|
|
return host->bus_ops->cache_enabled(host);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-06 22:58:28 +08:00
|
|
|
static inline int mmc_flush_cache(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
if (host->bus_ops->flush_cache)
|
|
|
|
return host->bus_ops->flush_cache(host);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-13 21:14:08 +08:00
|
|
|
#endif
|