sdhci-cns3xxx.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * SDHCI support for CNS3xxx SoC
  3. *
  4. * Copyright 2008 Cavium Networks
  5. * Copyright 2010 MontaVista Software, LLC.
  6. *
  7. * Authors: Scott Shu
  8. * Anton Vorontsov <avorontsov@mvista.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/device.h>
  16. #include <linux/mmc/host.h>
  17. #include <linux/module.h>
  18. #include <mach/cns3xxx.h>
  19. #include "sdhci-pltfm.h"
  20. static unsigned int sdhci_cns3xxx_get_max_clk(struct sdhci_host *host)
  21. {
  22. return 150000000;
  23. }
  24. static void sdhci_cns3xxx_set_clock(struct sdhci_host *host, unsigned int clock)
  25. {
  26. struct device *dev = mmc_dev(host->mmc);
  27. int div = 1;
  28. u16 clk;
  29. unsigned long timeout;
  30. if (clock == host->clock)
  31. return;
  32. sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
  33. if (clock == 0)
  34. goto out;
  35. while (host->max_clk / div > clock) {
  36. /*
  37. * On CNS3xxx divider grows linearly up to 4, and then
  38. * exponentially up to 256.
  39. */
  40. if (div < 4)
  41. div += 1;
  42. else if (div < 256)
  43. div *= 2;
  44. else
  45. break;
  46. }
  47. dev_dbg(dev, "desired SD clock: %d, actual: %d\n",
  48. clock, host->max_clk / div);
  49. /* Divide by 3 is special. */
  50. if (div != 3)
  51. div >>= 1;
  52. clk = div << SDHCI_DIVIDER_SHIFT;
  53. clk |= SDHCI_CLOCK_INT_EN;
  54. sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
  55. timeout = 20;
  56. while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
  57. & SDHCI_CLOCK_INT_STABLE)) {
  58. if (timeout == 0) {
  59. dev_warn(dev, "clock is unstable");
  60. break;
  61. }
  62. timeout--;
  63. mdelay(1);
  64. }
  65. clk |= SDHCI_CLOCK_CARD_EN;
  66. sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
  67. out:
  68. host->clock = clock;
  69. }
  70. static struct sdhci_ops sdhci_cns3xxx_ops = {
  71. .get_max_clock = sdhci_cns3xxx_get_max_clk,
  72. .set_clock = sdhci_cns3xxx_set_clock,
  73. };
  74. static struct sdhci_pltfm_data sdhci_cns3xxx_pdata = {
  75. .ops = &sdhci_cns3xxx_ops,
  76. .quirks = SDHCI_QUIRK_BROKEN_DMA |
  77. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  78. SDHCI_QUIRK_INVERTED_WRITE_PROTECT |
  79. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
  80. SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  81. SDHCI_QUIRK_NONSTANDARD_CLOCK,
  82. };
  83. static int __devinit sdhci_cns3xxx_probe(struct platform_device *pdev)
  84. {
  85. return sdhci_pltfm_register(pdev, &sdhci_cns3xxx_pdata);
  86. }
  87. static int __devexit sdhci_cns3xxx_remove(struct platform_device *pdev)
  88. {
  89. return sdhci_pltfm_unregister(pdev);
  90. }
  91. static struct platform_driver sdhci_cns3xxx_driver = {
  92. .driver = {
  93. .name = "sdhci-cns3xxx",
  94. .owner = THIS_MODULE,
  95. .pm = SDHCI_PLTFM_PMOPS,
  96. },
  97. .probe = sdhci_cns3xxx_probe,
  98. .remove = __devexit_p(sdhci_cns3xxx_remove),
  99. };
  100. module_platform_driver(sdhci_cns3xxx_driver);
  101. MODULE_DESCRIPTION("SDHCI driver for CNS3xxx");
  102. MODULE_AUTHOR("Scott Shu, "
  103. "Anton Vorontsov <avorontsov@mvista.com>");
  104. MODULE_LICENSE("GPL v2");