Skip to content

Commit 3d963c7

Browse files
weiszgpopcornmix
authored andcommitted
MMC: added alternative MMC driver
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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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: #1327 Signed-off-by: Phil Elwell <[email protected]> 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: #2350 Signed-off-by: Phil Elwell <[email protected]> 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: #2728 Signed-off-by: Phil Elwell <[email protected]> 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 <[email protected]> Cc: Frank Pavlic <[email protected]> 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 <[email protected]> Cc: Frank Pavlic <[email protected]> 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 <[email protected]> Cc: Frank Pavlic <[email protected]> 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 <[email protected]> Cc: Frank Pavlic <[email protected]> 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 <[email protected]> Cc: Frank Pavlic <[email protected]> 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 <[email protected]> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav Rosomakho <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <[email protected]> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) 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. Signed-off-by: Juerg Haefliger <[email protected]> Signed-off-by: Phil Elwell <[email protected]> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <[email protected]> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <[email protected]>
1 parent 8137bff commit 3d963c7

File tree

9 files changed

+1635
-5
lines changed

9 files changed

+1635
-5
lines changed

drivers/mmc/core/block.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ static DEFINE_MUTEX(open_lock);
218218
module_param(perdev_minors, int, 0444);
219219
MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device");
220220

221+
/*
222+
* Allow quirks to be overridden for the current card
223+
*/
224+
static char *card_quirks;
225+
module_param(card_quirks, charp, 0644);
226+
MODULE_PARM_DESC(card_quirks, "Force the use of the indicated quirks (a bitfield)");
227+
221228
static inline int mmc_blk_part_switch(struct mmc_card *card,
222229
unsigned int part_type);
223230
static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
@@ -3315,14 +3322,25 @@ static int mmc_blk_probe(struct mmc_card *card)
33153322
{
33163323
struct mmc_blk_data *md;
33173324
int ret = 0;
3325+
char quirk_str[24];
3326+
char cap_str[10];
33183327

33193328
/*
33203329
* Check that the card supports the command class(es) we need.
33213330
*/
33223331
if (!(card->csd.cmdclass & CCC_BLOCK_READ))
33233332
return -ENODEV;
33243333

3325-
mmc_fixup_device(card, mmc_blk_fixups);
3334+
if (card_quirks) {
3335+
unsigned long quirks;
3336+
if (kstrtoul(card_quirks, 0, &quirks) == 0)
3337+
card->quirks = (unsigned int)quirks;
3338+
else
3339+
pr_err("mmc_block: Invalid card_quirks parameter '%s'\n",
3340+
card_quirks);
3341+
}
3342+
else
3343+
mmc_fixup_device(card, mmc_blk_fixups);
33263344

33273345
card->complete_wq = alloc_workqueue("mmc_complete",
33283346
WQ_MEM_RECLAIM | WQ_HIGHPRI, 0);
@@ -3337,6 +3355,17 @@ static int mmc_blk_probe(struct mmc_card *card)
33373355
goto out_free;
33383356
}
33393357

3358+
string_get_size((u64)get_capacity(md->disk), 512, STRING_UNITS_2,
3359+
cap_str, sizeof(cap_str));
3360+
if (card->quirks)
3361+
snprintf(quirk_str, sizeof(quirk_str),
3362+
" (quirks 0x%08x)", card->quirks);
3363+
else
3364+
quirk_str[0] = '\0';
3365+
pr_info("%s: %s %s %s%s%s\n",
3366+
md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
3367+
cap_str, md->read_only ? " (ro)" : "", quirk_str);
3368+
33403369
ret = mmc_blk_alloc_parts(card, md);
33413370
if (ret)
33423371
goto out;

drivers/mmc/core/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,8 @@ EXPORT_SYMBOL(mmc_erase);
18391839

18401840
int mmc_can_erase(struct mmc_card *card)
18411841
{
1842-
if (card->csd.cmdclass & CCC_ERASE && card->erase_size)
1842+
if (card->csd.cmdclass & CCC_ERASE && card->erase_size &&
1843+
!(card->quirks & MMC_QUIRK_ERASE_BROKEN))
18431844
return 1;
18441845
return 0;
18451846
}

drivers/mmc/core/quirks.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ static const struct mmc_fixup __maybe_unused mmc_blk_fixups[] = {
143143
MMC_FIXUP(CID_NAME_ANY, CID_MANFID_SANDISK_SD, 0x5344, add_quirk_sd,
144144
MMC_QUIRK_BROKEN_SD_DISCARD),
145145

146+
/*
147+
* On some Kingston SD cards, multiple erases of less than 64
148+
* sectors can cause corruption.
149+
*/
150+
MMC_FIXUP("SD16G", 0x41, 0x3432, add_quirk, MMC_QUIRK_ERASE_BROKEN),
151+
MMC_FIXUP("SD32G", 0x41, 0x3432, add_quirk, MMC_QUIRK_ERASE_BROKEN),
152+
MMC_FIXUP("SD64G", 0x41, 0x3432, add_quirk, MMC_QUIRK_ERASE_BROKEN),
153+
146154
END_FIXUP
147155
};
148156

drivers/mmc/host/Kconfig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@
55

66
comment "MMC/SD/SDIO Host Controller Drivers"
77

8+
config MMC_BCM2835_MMC
9+
tristate "MMC support on BCM2835"
10+
depends on MACH_BCM2708 || MACH_BCM2709 || ARCH_BCM2835
11+
help
12+
This selects the MMC Interface on BCM2835.
13+
14+
If you have a controller with this interface, say Y or M here.
15+
16+
If unsure, say N.
17+
18+
config MMC_BCM2835_DMA
19+
bool "DMA support on BCM2835 Arasan controller"
20+
depends on MMC_BCM2835_MMC
21+
help
22+
Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
23+
based chips.
24+
25+
If unsure, say N.
26+
27+
config MMC_BCM2835_PIO_DMA_BARRIER
28+
int "Block count limit for PIO transfers"
29+
depends on MMC_BCM2835_MMC && MMC_BCM2835_DMA
30+
range 0 256
31+
default 2
32+
help
33+
The inclusive limit in bytes under which PIO will be used instead of DMA
34+
35+
If unsure, say 2 here.
36+
837
config MMC_DEBUG
938
bool "MMC host drivers debugging"
1039
depends on MMC != n

drivers/mmc/host/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ obj-$(CONFIG_MMC_SDHCI_F_SDH30) += sdhci_f_sdh30.o
2323
obj-$(CONFIG_MMC_SDHCI_MILBEAUT) += sdhci-milbeaut.o
2424
obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
2525
obj-$(CONFIG_MMC_SDHCI_AM654) += sdhci_am654.o
26+
obj-$(CONFIG_MMC_BCM2835_MMC) += bcm2835-mmc.o
2627
obj-$(CONFIG_MMC_WBSD) += wbsd.o
2728
obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
2829
obj-$(CONFIG_MMC_ALCOR) += alcor.o

0 commit comments

Comments
 (0)