0135-bcm2835-sdhost-Add-debug_flags-dtparam.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. From 594abef9e9d240d6f97a22e8f6cdc6cf0c272cd7 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 135/381] bcm2835-sdhost: Add debug_flags dtparam
  5. Bit zero disables the single-read-sectors map:
  6. If the default MMC driver is bcm2835-mmc:
  7. dtoverlay=sdhost,debug_flags=1
  8. If the default MMC driver is bcm2835-sdhost:
  9. dtoverlay=sdtweak,debug_flags=1
  10. (although the sdhost overlay may also work, sdtweak is
  11. less invasive and will work in more circumstances).
  12. Also revert the timeout change, just in case.
  13. ---
  14. arch/arm/boot/dts/overlays/sdhost-overlay.dts | 2 ++
  15. arch/arm/boot/dts/overlays/sdtweak-overlay.dts | 2 ++
  16. drivers/mmc/host/bcm2835-sdhost.c | 26 +++++++++++++++++++++-----
  17. 3 files changed, 25 insertions(+), 5 deletions(-)
  18. --- a/arch/arm/boot/dts/overlays/sdhost-overlay.dts
  19. +++ b/arch/arm/boot/dts/overlays/sdhost-overlay.dts
  20. @@ -16,6 +16,7 @@
  21. frag1: __overlay__ {
  22. brcm,overclock-50 = <0>;
  23. brcm,pio-limit = <1>;
  24. + brcm,debug-flags = <0>;
  25. status = "okay";
  26. };
  27. };
  28. @@ -25,5 +26,6 @@
  29. force_pio = <&frag1>,"brcm,force-pio?";
  30. pio_limit = <&frag1>,"brcm,pio-limit:0";
  31. debug = <&frag1>,"brcm,debug?";
  32. + debug_flags = <&frag1>,"brcm,debug-flags:0";
  33. };
  34. };
  35. --- a/arch/arm/boot/dts/overlays/sdtweak-overlay.dts
  36. +++ b/arch/arm/boot/dts/overlays/sdtweak-overlay.dts
  37. @@ -9,6 +9,7 @@
  38. frag1: __overlay__ {
  39. brcm,overclock-50 = <0>;
  40. brcm,pio-limit = <1>;
  41. + brcm,debug-flags = <0>;
  42. };
  43. };
  44. @@ -17,5 +18,6 @@
  45. force_pio = <&frag1>,"brcm,force-pio?";
  46. pio_limit = <&frag1>,"brcm,pio-limit:0";
  47. debug = <&frag1>,"brcm,debug?";
  48. + debug_flags = <&frag1>,"brcm,debug-flags:0";
  49. };
  50. };
  51. --- a/drivers/mmc/host/bcm2835-sdhost.c
  52. +++ b/drivers/mmc/host/bcm2835-sdhost.c
  53. @@ -174,6 +174,8 @@ struct bcm2835_host {
  54. u32 overclock; /* Current frequency if overclocked, else zero */
  55. u32 pio_limit; /* Maximum block count for PIO (0 = always DMA) */
  56. + u32 debug_flags;
  57. +
  58. u32 sectors; /* Cached card size in sectors */
  59. u32 single_read_sectors[8];
  60. };
  61. @@ -682,7 +684,7 @@ static void bcm2835_sdhost_prepare_data(
  62. host->flush_fifo = 0;
  63. host->data->bytes_xfered = 0;
  64. - if (!host->sectors && host->mmc->card)
  65. + if (!host->sectors && host->mmc->card && !(host->debug_flags & 1))
  66. {
  67. struct mmc_card *card = host->mmc->card;
  68. if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) {
  69. @@ -1486,8 +1488,8 @@ void bcm2835_sdhost_set_clock(struct bcm
  70. host->cdiv = div;
  71. bcm2835_sdhost_write(host, host->cdiv, SDCDIV);
  72. - /* Set the timeout to 250ms */
  73. - bcm2835_sdhost_write(host, host->mmc->actual_clock/4, SDTOUT);
  74. + /* Set the timeout to 500ms */
  75. + bcm2835_sdhost_write(host, host->mmc->actual_clock/2, SDTOUT);
  76. if (host->debug)
  77. pr_info("%s: clock=%d -> max_clk=%d, cdiv=%x (actual clock %d)\n",
  78. @@ -1606,8 +1608,16 @@ static int bcm2835_sdhost_multi_io_quirk
  79. host = mmc_priv(card->host);
  80. - if (direction == MMC_DATA_READ)
  81. - {
  82. + if (!host->sectors) {
  83. + /* csd.capacity is in weird units - convert to sectors */
  84. + u32 card_sectors = (card->csd.capacity << (card->csd.read_blkbits - 9));
  85. + if ((direction == MMC_DATA_READ) &&
  86. + ((blk_pos + blk_size) == card_sectors))
  87. + blk_size--;
  88. + return blk_size;
  89. + }
  90. +
  91. + if (direction == MMC_DATA_READ) {
  92. int i;
  93. int sector;
  94. for (i = 0; blk_pos > (sector = host->single_read_sectors[i]); i++)
  95. @@ -1838,8 +1848,14 @@ static int bcm2835_sdhost_probe(struct p
  96. host->allow_dma = ALLOW_DMA &&
  97. !of_property_read_bool(node, "brcm,force-pio");
  98. host->debug = of_property_read_bool(node, "brcm,debug");
  99. + of_property_read_u32(node,
  100. + "brcm,debug-flags",
  101. + &host->debug_flags);
  102. }
  103. + if (host->debug_flags)
  104. + dev_err(dev, "debug_flags=%x\n", host->debug_flags);
  105. +
  106. if (host->allow_dma) {
  107. if (node) {
  108. host->dma_chan_tx =