mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-07 18:40:10 +00:00
mmc: Disable CMD23 transfers on all cards Pending wire-level investigation of these types of transfers and associated errors on bcm2835-mmc, disable for now. Fallback of CMD18/CMD25 transfers will be used automatically by the MMC layer. Reported/Tested-by: Gellert Weisz <gellert@raspberrypi.org> mmc: bcm2835-mmc: enable DT support for all architectures Both ARCH_BCM2835 and ARCH_BCM270x are built with OF now. Enable Device Tree support for all architectures. Signed-off-by: Noralf Trønnes <noralf@tronnes.org> mmc: bcm2835-mmc: fix probe error handling Probe error handling is broken in several places. Simplify error handling by using device managed functions. Replace pr_{err,info} with dev_{err,info}. Signed-off-by: Noralf Trønnes <noralf@tronnes.org> bcm2835-mmc: Add locks when accessing sdhost registers bcm2835-mmc: Add range of debug options for slowing things down bcm2835-mmc: Add option to disable some delays bcm2835-mmc: Add option to disable MMC_QUIRK_BLK_NO_CMD23 bcm2835-mmc: Default to disabling MMC_QUIRK_BLK_NO_CMD23 bcm2835-mmc: Adding overclocking option Allow a different clock speed to be substitued for a requested 50MHz. This option is exposed using the "overclock_50" DT parameter. Note that the mmc interface is restricted to EVEN integer divisions of 250MHz, and the highest sensible option is 63 (250/4 = 62.5), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-mmc: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. mmc: bcm2835-mmc: Make available on ARCH_BCM2835 Make the bcm2835-mmc driver available for use on ARCH_BCM2835. Signed-off-by: Noralf Trønnes <noralf@tronnes.org> BCM270x_DT: add bcm2835-mmc entry Add Device Tree entry for bcm2835-mmc. In non-DT mode, don't add the device in the board file. Signed-off-by: Noralf Trønnes <noralf@tronnes.org> bcm2835-mmc: Don't overwrite MMC capabilities from DT bcm2835-mmc: Don't override bus width capabilities from devicetree Take out the force setting of the MMC_CAP_4_BIT_DATA host capability so that the result read from devicetree via mmc_of_parse() is preserved. bcm2835-mmc: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-mmc driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: https://github.com/raspberrypi/linux/issues/1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: New timer API mmc: bcm2835-mmc: Support underclocking Support underclocking of the SD bus using the max-frequency DT property (which currently has no DT parameter). The sd_overclock parameter already provides another way to achieve the same thing which should be equivalent in end result, but it is a bug not to support max-frequency as well. See: https://github.com/raspberrypi/linux/issues/2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835: Recover from MMC_SEND_EXT_CSD If the user issues an "mmc extcsd read", the SD controller receives what it thinks is a SEND_IF_COND command with an unexpected data block. The resulting operations leave the FSM stuck in READWAIT, a state which persists until the MMC framework resets the controller, by which point the root filesystem is likely to have been unmounted. A less heavyweight solution is to detect the condition and nudge the FSM by asserting the (self-clearing) FORCE_DATA_MODE bit. N.B. This workaround was essentially discovered by accident and without a full understanding the inner workings of the controller, so it is fortunate that the "fix" only modifies error paths. See: https://github.com/raspberrypi/linux/issues/2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: Fix DMA channel leak The BCM2835 MMC host driver requests a DMA channel on probe but neglects to release the channel in the probe error path and on driver unbind. I'm seeing this happen on every boot of the Compute Module 3: On first driver probe, DMA channel 2 is allocated and then leaked with a "could not get clk, deferring probe" message. On second driver probe, channel 4 is allocated. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> Cc: Frank Pavlic <f.pavlic@kunbus.de> bcm2835-mmc: Fix struct mmc_host leak on probe The BCM2835 MMC host driver requests the bus address of the host's register map on probe. If that fails, the driver leaks the struct mmc_host allocated earlier. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> Cc: Frank Pavlic <f.pavlic@kunbus.de> bcm2835-mmc: Fix duplicate free_irq() on remove The BCM2835 MMC host driver requests its interrupt as a device-managed resource, so the interrupt is automatically freed after the driver is unbound. However on driver unbind, bcm2835_mmc_remove() frees the interrupt explicitly to avoid invocation of the interrupt handler after driver structures have been torn down. The interrupt is thus freed twice, leading to a WARN splat in __free_irq(). Fix by not requesting the interrupt as a device-managed resource. Signed-off-by: Lukas Wunner <lukas@wunner.de> Cc: Frank Pavlic <f.pavlic@kunbus.de> bcm2835-mmc: Handle mmc_add_host() errors The BCM2835 MMC host driver calls mmc_add_host() but doesn't check its return value. Errors occurring in that function are therefore not handled. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> Cc: Frank Pavlic <f.pavlic@kunbus.de> bcm2835-mmc: Deduplicate reset of driver data on remove The BCM2835 MMC host driver sets the device's driver data pointer to NULL on ->remove() even though the driver core subsequently does the same in __device_release_driver(). Drop the duplicate assignment. Signed-off-by: Lukas Wunner <lukas@wunner.de> Cc: Frank Pavlic <f.pavlic@kunbus.de> bcm2835_mmc: Remove vestigial threaded IRQ With SDIO processing now managed by the MMC framework with a workqueue, the bcm2835_mmc driver no longer needs a threaded IRQ. Signed-off-by: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav Rosomakho <yaroslavros@gmail.com> Limit max_req_size under arm64 (or any other platform that uses swiotlb) to prevent potential buffer overflow due to bouncing. Signed-off-by: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more
182 lines
6.3 KiB
C
182 lines
6.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* This file contains work-arounds for many known SD/MMC
|
|
* and SDIO hardware bugs.
|
|
*
|
|
* Copyright (c) 2011 Andrei Warkentin <andreiw@motorola.com>
|
|
* Copyright (c) 2011 Pierre Tardy <tardyp@gmail.com>
|
|
* Inspired from pci fixup code:
|
|
* Copyright (c) 1999 Martin Mares <mj@ucw.cz>
|
|
*
|
|
*/
|
|
|
|
#include <linux/mmc/sdio_ids.h>
|
|
|
|
#include "card.h"
|
|
|
|
static const struct mmc_fixup __maybe_unused mmc_blk_fixups[] = {
|
|
#define INAND_CMD38_ARG_EXT_CSD 113
|
|
#define INAND_CMD38_ARG_ERASE 0x00
|
|
#define INAND_CMD38_ARG_TRIM 0x01
|
|
#define INAND_CMD38_ARG_SECERASE 0x80
|
|
#define INAND_CMD38_ARG_SECTRIM1 0x81
|
|
#define INAND_CMD38_ARG_SECTRIM2 0x88
|
|
/* CMD38 argument is passed through EXT_CSD[113] */
|
|
MMC_FIXUP("SEM02G", CID_MANFID_SANDISK, 0x100, add_quirk,
|
|
MMC_QUIRK_INAND_CMD38),
|
|
MMC_FIXUP("SEM04G", CID_MANFID_SANDISK, 0x100, add_quirk,
|
|
MMC_QUIRK_INAND_CMD38),
|
|
MMC_FIXUP("SEM08G", CID_MANFID_SANDISK, 0x100, add_quirk,
|
|
MMC_QUIRK_INAND_CMD38),
|
|
MMC_FIXUP("SEM16G", CID_MANFID_SANDISK, 0x100, add_quirk,
|
|
MMC_QUIRK_INAND_CMD38),
|
|
MMC_FIXUP("SEM32G", CID_MANFID_SANDISK, 0x100, add_quirk,
|
|
MMC_QUIRK_INAND_CMD38),
|
|
|
|
/*
|
|
* Some MMC cards experience performance degradation with CMD23
|
|
* instead of CMD12-bounded multiblock transfers. For now we'll
|
|
* black list what's bad...
|
|
* - Certain Toshiba cards.
|
|
*
|
|
* N.B. This doesn't affect SD cards.
|
|
*/
|
|
MMC_FIXUP("SDMB-32", CID_MANFID_SANDISK, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_BLK_NO_CMD23),
|
|
MMC_FIXUP("SDM032", CID_MANFID_SANDISK, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_BLK_NO_CMD23),
|
|
MMC_FIXUP("MMC08G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_BLK_NO_CMD23),
|
|
MMC_FIXUP("MMC16G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_BLK_NO_CMD23),
|
|
MMC_FIXUP("MMC32G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_BLK_NO_CMD23),
|
|
|
|
/*
|
|
* Some SD cards lockup while using CMD23 multiblock transfers.
|
|
*/
|
|
MMC_FIXUP("AF SD", CID_MANFID_ATP, CID_OEMID_ANY, add_quirk_sd,
|
|
MMC_QUIRK_BLK_NO_CMD23),
|
|
MMC_FIXUP("APUSD", CID_MANFID_APACER, 0x5048, add_quirk_sd,
|
|
MMC_QUIRK_BLK_NO_CMD23),
|
|
|
|
/*
|
|
* Some MMC cards need longer data read timeout than indicated in CSD.
|
|
*/
|
|
MMC_FIXUP(CID_NAME_ANY, CID_MANFID_MICRON, 0x200, add_quirk_mmc,
|
|
MMC_QUIRK_LONG_READ_TIME),
|
|
MMC_FIXUP("008GE0", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_LONG_READ_TIME),
|
|
|
|
/*
|
|
* On these Samsung MoviNAND parts, performing secure erase or
|
|
* secure trim can result in unrecoverable corruption due to a
|
|
* firmware bug.
|
|
*/
|
|
MMC_FIXUP("M8G2FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
|
|
MMC_FIXUP("MAG4FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
|
|
MMC_FIXUP("MBG8FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
|
|
MMC_FIXUP("MCGAFA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
|
|
MMC_FIXUP("VAL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
|
|
MMC_FIXUP("VYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
|
|
MMC_FIXUP("KYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
|
|
MMC_FIXUP("VZL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
|
|
|
|
/*
|
|
* On Some Kingston eMMCs, performing trim can result in
|
|
* unrecoverable data conrruption occasionally due to a firmware bug.
|
|
*/
|
|
MMC_FIXUP("V10008", CID_MANFID_KINGSTON, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_TRIM_BROKEN),
|
|
MMC_FIXUP("V10016", CID_MANFID_KINGSTON, CID_OEMID_ANY, add_quirk_mmc,
|
|
MMC_QUIRK_TRIM_BROKEN),
|
|
|
|
/*
|
|
* On some Kingston SD cards, multiple erases of less than 64
|
|
* sectors can cause corruption.
|
|
*/
|
|
MMC_FIXUP("SD16G", 0x41, 0x3432, add_quirk, MMC_QUIRK_ERASE_BROKEN),
|
|
MMC_FIXUP("SD32G", 0x41, 0x3432, add_quirk, MMC_QUIRK_ERASE_BROKEN),
|
|
MMC_FIXUP("SD64G", 0x41, 0x3432, add_quirk, MMC_QUIRK_ERASE_BROKEN),
|
|
|
|
END_FIXUP
|
|
};
|
|
|
|
static const struct mmc_fixup __maybe_unused mmc_ext_csd_fixups[] = {
|
|
/*
|
|
* Certain Hynix eMMC 4.41 cards might get broken when HPI feature
|
|
* is used so disable the HPI feature for such buggy cards.
|
|
*/
|
|
MMC_FIXUP_EXT_CSD_REV(CID_NAME_ANY, CID_MANFID_HYNIX,
|
|
0x014a, add_quirk, MMC_QUIRK_BROKEN_HPI, 5),
|
|
/*
|
|
* Certain Micron (Numonyx) eMMC 4.5 cards might get broken when HPI
|
|
* feature is used so disable the HPI feature for such buggy cards.
|
|
*/
|
|
MMC_FIXUP_EXT_CSD_REV(CID_NAME_ANY, CID_MANFID_NUMONYX,
|
|
0x014e, add_quirk, MMC_QUIRK_BROKEN_HPI, 6),
|
|
|
|
END_FIXUP
|
|
};
|
|
|
|
|
|
static const struct mmc_fixup __maybe_unused sdio_fixup_methods[] = {
|
|
SDIO_FIXUP(SDIO_VENDOR_ID_TI_WL1251, SDIO_DEVICE_ID_TI_WL1251,
|
|
add_quirk, MMC_QUIRK_NONSTD_FUNC_IF),
|
|
|
|
SDIO_FIXUP(SDIO_VENDOR_ID_TI_WL1251, SDIO_DEVICE_ID_TI_WL1251,
|
|
add_quirk, MMC_QUIRK_DISABLE_CD),
|
|
|
|
SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
|
|
add_quirk, MMC_QUIRK_NONSTD_FUNC_IF),
|
|
|
|
SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
|
|
add_quirk, MMC_QUIRK_DISABLE_CD),
|
|
|
|
SDIO_FIXUP(SDIO_VENDOR_ID_STE, SDIO_DEVICE_ID_STE_CW1200,
|
|
add_quirk, MMC_QUIRK_BROKEN_BYTE_MODE_512),
|
|
|
|
SDIO_FIXUP(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797_F0,
|
|
add_quirk, MMC_QUIRK_BROKEN_IRQ_POLLING),
|
|
|
|
SDIO_FIXUP(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8887_F0,
|
|
add_limit_rate_quirk, 150000000),
|
|
|
|
END_FIXUP
|
|
};
|
|
|
|
static inline void mmc_fixup_device(struct mmc_card *card,
|
|
const struct mmc_fixup *table)
|
|
{
|
|
const struct mmc_fixup *f;
|
|
u64 rev = cid_rev_card(card);
|
|
|
|
for (f = table; f->vendor_fixup; f++) {
|
|
if ((f->manfid == CID_MANFID_ANY ||
|
|
f->manfid == card->cid.manfid) &&
|
|
(f->oemid == CID_OEMID_ANY ||
|
|
f->oemid == card->cid.oemid) &&
|
|
(f->name == CID_NAME_ANY ||
|
|
!strncmp(f->name, card->cid.prod_name,
|
|
sizeof(card->cid.prod_name))) &&
|
|
(f->cis_vendor == card->cis.vendor ||
|
|
f->cis_vendor == (u16) SDIO_ANY_ID) &&
|
|
(f->cis_device == card->cis.device ||
|
|
f->cis_device == (u16) SDIO_ANY_ID) &&
|
|
(f->ext_csd_rev == EXT_CSD_REV_ANY ||
|
|
f->ext_csd_rev == card->ext_csd.rev) &&
|
|
rev >= f->rev_start && rev <= f->rev_end) {
|
|
dev_dbg(&card->dev, "calling %ps\n", f->vendor_fixup);
|
|
f->vendor_fixup(card, f->data);
|
|
}
|
|
}
|
|
}
|