brcm2708: update linux 4.4 patches to latest version
[openwrt/staging/wigyori.git] / target / linux / brcm2708 / patches-4.4 / 0135-bcm2835-sdhost-Add-debug_flags-dtparam.patch
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
5
6 Bit zero disables the single-read-sectors map:
7
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).
14
15 Also revert the timeout change, just in case.
16 ---
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(-)
21
22 --- a/arch/arm/boot/dts/overlays/sdhost-overlay.dts
23 +++ b/arch/arm/boot/dts/overlays/sdhost-overlay.dts
24 @@ -16,6 +16,7 @@
25 frag1: __overlay__ {
26 brcm,overclock-50 = <0>;
27 brcm,pio-limit = <1>;
28 + brcm,debug-flags = <0>;
29 status = "okay";
30 };
31 };
32 @@ -25,5 +26,6 @@
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";
37 };
38 };
39 --- a/arch/arm/boot/dts/overlays/sdtweak-overlay.dts
40 +++ b/arch/arm/boot/dts/overlays/sdtweak-overlay.dts
41 @@ -9,6 +9,7 @@
42 frag1: __overlay__ {
43 brcm,overclock-50 = <0>;
44 brcm,pio-limit = <1>;
45 + brcm,debug-flags = <0>;
46 };
47 };
48
49 @@ -17,5 +18,6 @@
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";
54 };
55 };
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) */
61
62 + u32 debug_flags;
63 +
64 u32 sectors; /* Cached card size in sectors */
65 u32 single_read_sectors[8];
66 };
67 @@ -682,7 +684,7 @@ static void bcm2835_sdhost_prepare_data(
68 host->flush_fifo = 0;
69 host->data->bytes_xfered = 0;
70
71 - if (!host->sectors && host->mmc->card)
72 + if (!host->sectors && host->mmc->card && !(host->debug_flags & 1))
73 {
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
77 host->cdiv = div;
78 bcm2835_sdhost_write(host, host->cdiv, SDCDIV);
79
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);
84
85 if (host->debug)
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
88
89 host = mmc_priv(card->host);
90
91 - if (direction == MMC_DATA_READ)
92 - {
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))
98 + blk_size--;
99 + return blk_size;
100 + }
101 +
102 + if (direction == MMC_DATA_READ) {
103 int i;
104 int sector;
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);
113 }
114
115 + if (host->debug_flags)
116 + dev_err(dev, "debug_flags=%x\n", host->debug_flags);
117 +
118 if (host->allow_dma) {
119 if (node) {
120 host->dma_chan_tx =