0224-Revert-bcm2835-sdhost-Adjust-to-core-clock-changes.patch 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. From 14c3f0b3a4fd51c2bb98146b3395ddc69a2b50ab Mon Sep 17 00:00:00 2001
  2. From: Phil Elwell <phil@raspberrypi.org>
  3. Date: Mon, 4 Apr 2016 12:35:51 +0100
  4. Subject: [PATCH 224/381] Revert "bcm2835-sdhost: Adjust to core clock changes"
  5. This reverts commit 4b89d07fd299a0f4e25321920cb74416ba2e638e.
  6. ---
  7. drivers/mmc/host/Kconfig | 1 -
  8. drivers/mmc/host/bcm2835-sdhost.c | 140 ++++++--------------------------------
  9. 2 files changed, 22 insertions(+), 119 deletions(-)
  10. --- a/drivers/mmc/host/Kconfig
  11. +++ b/drivers/mmc/host/Kconfig
  12. @@ -36,7 +36,6 @@ config MMC_BCM2835_PIO_DMA_BARRIER
  13. config MMC_BCM2835_SDHOST
  14. tristate "Support for the SDHost controller on BCM2708/9"
  15. depends on MACH_BCM2708 || MACH_BCM2709 || ARCH_BCM2835
  16. - depends on RASPBERRYPI_FIRMWARE
  17. help
  18. This selects the SDHost controller on BCM2835/6.
  19. --- a/drivers/mmc/host/bcm2835-sdhost.c
  20. +++ b/drivers/mmc/host/bcm2835-sdhost.c
  21. @@ -50,10 +50,6 @@
  22. #include <linux/of_dma.h>
  23. #include <linux/time.h>
  24. #include <linux/workqueue.h>
  25. -#include <linux/cpufreq.h>
  26. -#include <linux/semaphore.h>
  27. -#include <soc/bcm2835/raspberrypi-firmware.h>
  28. -
  29. #define DRIVER_NAME "sdhost-bcm2835"
  30. @@ -140,8 +136,6 @@
  31. #define MHZ 1000000
  32. -#define RPI_FIRMWARE_CLOCK_CORE 4
  33. -
  34. struct bcm2835_host {
  35. spinlock_t lock;
  36. @@ -157,9 +151,7 @@ struct bcm2835_host {
  37. bool slow_card; /* Force 11-bit divisor */
  38. - unsigned int max_clk; /* Max src clock freq */
  39. - unsigned int min_clk; /* Min src clock freq */
  40. - unsigned int cur_clk; /* Current src clock freq */
  41. + unsigned int max_clk; /* Max possible freq */
  42. struct tasklet_struct finish_tasklet; /* Tasklet structures */
  43. @@ -191,7 +183,6 @@ struct bcm2835_host {
  44. unsigned int use_sbc:1; /* Send CMD23 */
  45. unsigned int debug:1; /* Enable debug output */
  46. - unsigned int variable_clock:1; /* The core clock may change */
  47. /*DMA part*/
  48. struct dma_chan *dma_chan_rxtx; /* DMA channel for reads and writes */
  49. @@ -217,9 +208,6 @@ struct bcm2835_host {
  50. u32 pio_limit; /* Maximum block count for PIO (0 = always DMA) */
  51. u32 sectors; /* Cached card size in sectors */
  52. -
  53. - struct notifier_block cpufreq_nb; /* The cpufreq callback list item */
  54. - struct semaphore cpufreq_semaphore; /* Interlock between SD activity and cpufreq changes */
  55. };
  56. #if ENABLE_LOG
  57. @@ -239,10 +227,6 @@ static u32 sdhost_log_idx;
  58. static spinlock_t log_lock;
  59. static void __iomem *timer_base;
  60. -static int bcm2835_sdhost_cpufreq_callback(struct notifier_block *nb,
  61. - unsigned long action, void *data);
  62. -static unsigned int get_core_clock(unsigned int mode);
  63. -
  64. #define LOG_ENTRIES (256*1)
  65. #define LOG_SIZE (sizeof(LOG_ENTRY_T)*LOG_ENTRIES)
  66. @@ -464,14 +448,20 @@ static void bcm2835_sdhost_reset(struct
  67. static void bcm2835_sdhost_set_ios(struct mmc_host *mmc, struct mmc_ios *ios);
  68. -static void bcm2835_sdhost_init(struct bcm2835_host *host)
  69. +static void bcm2835_sdhost_init(struct bcm2835_host *host, int soft)
  70. {
  71. - pr_debug("bcm2835_sdhost_init()\n");
  72. + pr_debug("bcm2835_sdhost_init(%d)\n", soft);
  73. /* Set interrupt enables */
  74. host->hcfg = SDHCFG_BUSY_IRPT_EN;
  75. bcm2835_sdhost_reset_internal(host);
  76. +
  77. + if (soft) {
  78. + /* force clock reconfiguration */
  79. + host->clock = 0;
  80. + bcm2835_sdhost_set_ios(host->mmc, &host->mmc->ios);
  81. + }
  82. }
  83. static void bcm2835_sdhost_wait_transfer_complete(struct bcm2835_host *host)
  84. @@ -1509,10 +1499,10 @@ static irqreturn_t bcm2835_sdhost_irq(in
  85. return result;
  86. }
  87. -void bcm2835_sdhost_set_clock(struct bcm2835_host *host)
  88. +void bcm2835_sdhost_set_clock(struct bcm2835_host *host, unsigned int clock)
  89. {
  90. int div = 0; /* Initialized for compiler warning */
  91. - unsigned int clock = host->clock;
  92. + unsigned int input_clock = clock;
  93. if (host->debug)
  94. pr_info("%s: set_clock(%d)\n", mmc_hostname(host->mmc), clock);
  95. @@ -1553,17 +1543,17 @@ void bcm2835_sdhost_set_clock(struct bcm
  96. return;
  97. }
  98. - div = host->cur_clk / clock;
  99. + div = host->max_clk / clock;
  100. if (div < 2)
  101. div = 2;
  102. - if ((host->cur_clk / div) > clock)
  103. + if ((host->max_clk / div) > clock)
  104. div++;
  105. div -= 2;
  106. if (div > SDCDIV_MAX_CDIV)
  107. div = SDCDIV_MAX_CDIV;
  108. - clock = host->cur_clk / (div + 2);
  109. + clock = host->max_clk / (div + 2);
  110. host->mmc->actual_clock = clock;
  111. /* Calibrate some delays */
  112. @@ -1571,7 +1561,7 @@ void bcm2835_sdhost_set_clock(struct bcm
  113. host->ns_per_fifo_word = (1000000000/clock) *
  114. ((host->mmc->caps & MMC_CAP_4_BIT_DATA) ? 8 : 32);
  115. - if (clock > host->clock) {
  116. + if (clock > input_clock) {
  117. /* Save the closest value, to make it easier
  118. to reduce in the event of error */
  119. host->overclock_50 = (clock/MHZ);
  120. @@ -1597,9 +1587,9 @@ void bcm2835_sdhost_set_clock(struct bcm
  121. bcm2835_sdhost_write(host, host->mmc->actual_clock/2, SDTOUT);
  122. if (host->debug)
  123. - pr_info("%s: clock=%d -> cur_clk=%d, cdiv=%x (actual clock %d)\n",
  124. - mmc_hostname(host->mmc), host->clock,
  125. - host->cur_clk, host->cdiv, host->mmc->actual_clock);
  126. + pr_info("%s: clock=%d -> max_clk=%d, cdiv=%x (actual clock %d)\n",
  127. + mmc_hostname(host->mmc), input_clock,
  128. + host->max_clk, host->cdiv, host->mmc->actual_clock);
  129. }
  130. static void bcm2835_sdhost_request(struct mmc_host *mmc, struct mmc_request *mrq)
  131. @@ -1648,13 +1638,6 @@ static void bcm2835_sdhost_request(struc
  132. (mrq->data->blocks > host->pio_limit))
  133. bcm2835_sdhost_prepare_dma(host, mrq->data);
  134. - if (host->variable_clock &&
  135. - (down_killable(&host->cpufreq_semaphore) != 0)) {
  136. - mrq->cmd->error = -EINTR;
  137. - mmc_request_done(mmc, mrq);
  138. - return;
  139. - }
  140. -
  141. spin_lock_irqsave(&host->lock, flags);
  142. WARN_ON(host->mrq != NULL);
  143. @@ -1704,52 +1687,6 @@ static void bcm2835_sdhost_request(struc
  144. spin_unlock_irqrestore(&host->lock, flags);
  145. }
  146. -static int bcm2835_sdhost_cpufreq_callback(struct notifier_block *nb,
  147. - unsigned long action, void *data)
  148. -{
  149. - struct cpufreq_freqs *freq = data;
  150. - struct bcm2835_host *host;
  151. -
  152. - host = container_of(nb, struct bcm2835_host, cpufreq_nb);
  153. -
  154. - if (freq->cpu == 0) {
  155. - switch (action) {
  156. - case CPUFREQ_PRECHANGE:
  157. - if (down_killable(&host->cpufreq_semaphore) != 0)
  158. - return NOTIFY_BAD;
  159. - break;
  160. - case CPUFREQ_POSTCHANGE:
  161. - if (freq->new > freq->old)
  162. - host->cur_clk = host->max_clk;
  163. - else
  164. - host->cur_clk = host->min_clk;
  165. - bcm2835_sdhost_set_clock(host);
  166. - up(&host->cpufreq_semaphore);
  167. - break;
  168. - default:
  169. - break;
  170. - }
  171. - }
  172. - return NOTIFY_OK;
  173. -}
  174. -
  175. -static unsigned int get_core_clock(unsigned int mode)
  176. -{
  177. - struct rpi_firmware *fw = rpi_firmware_get(NULL);
  178. - struct {
  179. - u32 id;
  180. - u32 val;
  181. - } packet;
  182. - int ret;
  183. -
  184. - packet.id = RPI_FIRMWARE_CLOCK_CORE;
  185. - ret = rpi_firmware_property(fw, mode, &packet, sizeof(packet));
  186. - if (ret)
  187. - return 0;
  188. -
  189. - return packet.val;
  190. -}
  191. -
  192. static void bcm2835_sdhost_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  193. {
  194. @@ -1763,16 +1700,13 @@ static void bcm2835_sdhost_set_ios(struc
  195. ios->clock, ios->power_mode, ios->bus_width,
  196. ios->timing, ios->signal_voltage, ios->drv_type);
  197. - if (ios->clock && !host->cur_clk)
  198. - host->cur_clk = get_core_clock(RPI_FIRMWARE_GET_CLOCK_RATE);
  199. -
  200. spin_lock_irqsave(&host->lock, flags);
  201. log_event("IOS<", ios->clock, 0);
  202. if (!ios->clock || ios->clock != host->clock) {
  203. + bcm2835_sdhost_set_clock(host, ios->clock);
  204. host->clock = ios->clock;
  205. - bcm2835_sdhost_set_clock(host);
  206. }
  207. /* set bus width */
  208. @@ -1861,7 +1795,7 @@ static void bcm2835_sdhost_tasklet_finis
  209. host->overclock_50--;
  210. pr_warn("%s: reducing overclock due to errors\n",
  211. mmc_hostname(host->mmc));
  212. - bcm2835_sdhost_set_clock(host);
  213. + bcm2835_sdhost_set_clock(host,50*MHZ);
  214. mrq->cmd->error = -EILSEQ;
  215. mrq->cmd->retries = 1;
  216. }
  217. @@ -1879,9 +1813,6 @@ static void bcm2835_sdhost_tasklet_finis
  218. spin_unlock_irqrestore(&host->lock, flags);
  219. - if (host->variable_clock)
  220. - up(&host->cpufreq_semaphore);
  221. -
  222. if (terminate_chan)
  223. {
  224. int err = dmaengine_terminate_all(terminate_chan);
  225. @@ -1984,10 +1915,10 @@ int bcm2835_sdhost_add_host(struct bcm28
  226. setup_timer(&host->timer, bcm2835_sdhost_timeout,
  227. (unsigned long)host);
  228. - bcm2835_sdhost_init(host);
  229. + bcm2835_sdhost_init(host, 0);
  230. ret = request_irq(host->irq, bcm2835_sdhost_irq, 0 /*IRQF_SHARED*/,
  231. - mmc_hostname(mmc), host);
  232. + mmc_hostname(mmc), host);
  233. if (ret) {
  234. pr_err("%s: failed to request IRQ %d: %d\n",
  235. mmc_hostname(mmc), host->irq, ret);
  236. @@ -2022,7 +1953,6 @@ static int bcm2835_sdhost_probe(struct p
  237. struct bcm2835_host *host;
  238. struct mmc_host *mmc;
  239. const __be32 *addr;
  240. - unsigned int max_clk;
  241. int ret;
  242. pr_debug("bcm2835_sdhost_probe\n");
  243. @@ -2132,28 +2062,6 @@ static int bcm2835_sdhost_probe(struct p
  244. if (ret)
  245. goto err;
  246. - /* Query the core clock frequencies */
  247. - host->min_clk = get_core_clock(RPI_FIRMWARE_GET_MIN_CLOCK_RATE);
  248. - max_clk = get_core_clock(RPI_FIRMWARE_GET_MAX_CLOCK_RATE);
  249. - if (max_clk != host->max_clk) {
  250. - pr_warn("%s: Expected max clock %d, found %d\n",
  251. - mmc_hostname(mmc), host->max_clk, max_clk);
  252. - host->max_clk = max_clk;
  253. - }
  254. -
  255. - if (host->min_clk != host->max_clk) {
  256. - host->cpufreq_nb.notifier_call =
  257. - bcm2835_sdhost_cpufreq_callback;
  258. - sema_init(&host->cpufreq_semaphore, 1);
  259. - cpufreq_register_notifier(&host->cpufreq_nb,
  260. - CPUFREQ_TRANSITION_NOTIFIER);
  261. - host->variable_clock = 1;
  262. - host->cur_clk = 0; /* Get this later */
  263. - } else {
  264. - host->variable_clock = 0;
  265. - host->cur_clk = host->max_clk;
  266. - }
  267. -
  268. platform_set_drvdata(pdev, host);
  269. pr_debug("bcm2835_sdhost_probe -> OK\n");
  270. @@ -2173,10 +2081,6 @@ static int bcm2835_sdhost_remove(struct
  271. pr_debug("bcm2835_sdhost_remove\n");
  272. - if (host->variable_clock)
  273. - cpufreq_unregister_notifier(&host->cpufreq_nb,
  274. - CPUFREQ_TRANSITION_NOTIFIER);
  275. -
  276. mmc_remove_host(host->mmc);
  277. bcm2835_sdhost_set_power(host, false);