1 From 99695e24b9c0d1b573846081c2f58ef3114a9f35 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Fri, 22 Jan 2016 16:03:24 +0000
4 Subject: [PATCH] bcm2835-sdhost: Add debug_flags dtparam
6 Bit zero disables the single-read-sectors map:
8 If the default MMC driver is bcm2835-mmc:
9 dtoverlay=sdhost,debug_flags=1
10 If the default MMC driver is bcm2835-sdhost:
11 dtoverlay=sdtweak,debug_flags=1
12 (although the sdhost overlay may also work, sdtweak is
13 less invasive and will work in more circumstances).
15 Also revert the timeout change, just in case.
17 arch/arm/boot/dts/overlays/sdhost-overlay.dts | 2 ++
18 arch/arm/boot/dts/overlays/sdtweak-overlay.dts | 2 ++
19 drivers/mmc/host/bcm2835-sdhost.c | 26 +++++++++++++++++++++-----
20 3 files changed, 25 insertions(+), 5 deletions(-)
22 --- a/arch/arm/boot/dts/overlays/sdhost-overlay.dts
23 +++ b/arch/arm/boot/dts/overlays/sdhost-overlay.dts
26 brcm,overclock-50 = <0>;
28 + brcm,debug-flags = <0>;
33 force_pio = <&frag1>,"brcm,force-pio?";
34 pio_limit = <&frag1>,"brcm,pio-limit:0";
35 debug = <&frag1>,"brcm,debug?";
36 + debug_flags = <&frag1>,"brcm,debug-flags:0";
39 --- a/arch/arm/boot/dts/overlays/sdtweak-overlay.dts
40 +++ b/arch/arm/boot/dts/overlays/sdtweak-overlay.dts
43 brcm,overclock-50 = <0>;
45 + brcm,debug-flags = <0>;
50 force_pio = <&frag1>,"brcm,force-pio?";
51 pio_limit = <&frag1>,"brcm,pio-limit:0";
52 debug = <&frag1>,"brcm,debug?";
53 + debug_flags = <&frag1>,"brcm,debug-flags:0";
56 --- a/drivers/mmc/host/bcm2835-sdhost.c
57 +++ b/drivers/mmc/host/bcm2835-sdhost.c
58 @@ -174,6 +174,8 @@ struct bcm2835_host {
59 u32 overclock; /* Current frequency if overclocked, else zero */
60 u32 pio_limit; /* Maximum block count for PIO (0 = always DMA) */
64 u32 sectors; /* Cached card size in sectors */
65 u32 single_read_sectors[8];
67 @@ -682,7 +684,7 @@ static void bcm2835_sdhost_prepare_data(
69 host->data->bytes_xfered = 0;
71 - if (!host->sectors && host->mmc->card)
72 + if (!host->sectors && host->mmc->card && !(host->debug_flags & 1))
74 struct mmc_card *card = host->mmc->card;
75 if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) {
76 @@ -1486,8 +1488,8 @@ void bcm2835_sdhost_set_clock(struct bcm
78 bcm2835_sdhost_write(host, host->cdiv, SDCDIV);
80 - /* Set the timeout to 250ms */
81 - bcm2835_sdhost_write(host, host->mmc->actual_clock/4, SDTOUT);
82 + /* Set the timeout to 500ms */
83 + bcm2835_sdhost_write(host, host->mmc->actual_clock/2, SDTOUT);
86 pr_info("%s: clock=%d -> max_clk=%d, cdiv=%x (actual clock %d)\n",
87 @@ -1606,8 +1608,16 @@ static int bcm2835_sdhost_multi_io_quirk
89 host = mmc_priv(card->host);
91 - if (direction == MMC_DATA_READ)
93 + if (!host->sectors) {
94 + /* csd.capacity is in weird units - convert to sectors */
95 + u32 card_sectors = (card->csd.capacity << (card->csd.read_blkbits - 9));
96 + if ((direction == MMC_DATA_READ) &&
97 + ((blk_pos + blk_size) == card_sectors))
102 + if (direction == MMC_DATA_READ) {
105 for (i = 0; blk_pos > (sector = host->single_read_sectors[i]); i++)
106 @@ -1838,8 +1848,14 @@ static int bcm2835_sdhost_probe(struct p
107 host->allow_dma = ALLOW_DMA &&
108 !of_property_read_bool(node, "brcm,force-pio");
109 host->debug = of_property_read_bool(node, "brcm,debug");
110 + of_property_read_u32(node,
111 + "brcm,debug-flags",
112 + &host->debug_flags);
115 + if (host->debug_flags)
116 + dev_err(dev, "debug_flags=%x\n", host->debug_flags);
118 if (host->allow_dma) {