sdhci-pltfm.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * sdhci-pltfm.c Support for SDHCI platform devices
  3. * Copyright (c) 2009 Intel Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. /* Supports:
  19. * SDHCI platform devices
  20. *
  21. * Inspired by sdhci-pci.c, by Pierre Ossman
  22. */
  23. #include <linux/delay.h>
  24. #include <linux/highmem.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/mmc/host.h>
  27. #include <linux/io.h>
  28. #include <linux/sdhci-pltfm.h>
  29. #include "sdhci.h"
  30. /*****************************************************************************\
  31. * *
  32. * SDHCI core callbacks *
  33. * *
  34. \*****************************************************************************/
  35. static struct sdhci_ops sdhci_pltfm_ops = {
  36. };
  37. /*****************************************************************************\
  38. * *
  39. * Device probing/removal *
  40. * *
  41. \*****************************************************************************/
  42. static int __devinit sdhci_pltfm_probe(struct platform_device *pdev)
  43. {
  44. struct sdhci_pltfm_data *pdata = pdev->dev.platform_data;
  45. struct sdhci_host *host;
  46. struct resource *iomem;
  47. int ret;
  48. iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  49. if (!iomem) {
  50. ret = -ENOMEM;
  51. goto err;
  52. }
  53. if (resource_size(iomem) < 0x100)
  54. dev_err(&pdev->dev, "Invalid iomem size. You may "
  55. "experience problems.\n");
  56. if (pdev->dev.parent)
  57. host = sdhci_alloc_host(pdev->dev.parent, 0);
  58. else
  59. host = sdhci_alloc_host(&pdev->dev, 0);
  60. if (IS_ERR(host)) {
  61. ret = PTR_ERR(host);
  62. goto err;
  63. }
  64. host->hw_name = "platform";
  65. if (pdata && pdata->ops)
  66. host->ops = pdata->ops;
  67. else
  68. host->ops = &sdhci_pltfm_ops;
  69. if (pdata)
  70. host->quirks = pdata->quirks;
  71. host->irq = platform_get_irq(pdev, 0);
  72. if (!request_mem_region(iomem->start, resource_size(iomem),
  73. mmc_hostname(host->mmc))) {
  74. dev_err(&pdev->dev, "cannot request region\n");
  75. ret = -EBUSY;
  76. goto err_request;
  77. }
  78. host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  79. if (!host->ioaddr) {
  80. dev_err(&pdev->dev, "failed to remap registers\n");
  81. ret = -ENOMEM;
  82. goto err_remap;
  83. }
  84. if (pdata && pdata->init) {
  85. ret = pdata->init(host);
  86. if (ret)
  87. goto err_plat_init;
  88. }
  89. ret = sdhci_add_host(host);
  90. if (ret)
  91. goto err_add_host;
  92. platform_set_drvdata(pdev, host);
  93. return 0;
  94. err_add_host:
  95. if (pdata && pdata->exit)
  96. pdata->exit(host);
  97. err_plat_init:
  98. iounmap(host->ioaddr);
  99. err_remap:
  100. release_mem_region(iomem->start, resource_size(iomem));
  101. err_request:
  102. sdhci_free_host(host);
  103. err:
  104. printk(KERN_ERR"Probing of sdhci-pltfm failed: %d\n", ret);
  105. return ret;
  106. }
  107. static int __devexit sdhci_pltfm_remove(struct platform_device *pdev)
  108. {
  109. struct sdhci_pltfm_data *pdata = pdev->dev.platform_data;
  110. struct sdhci_host *host = platform_get_drvdata(pdev);
  111. struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  112. int dead;
  113. u32 scratch;
  114. dead = 0;
  115. scratch = readl(host->ioaddr + SDHCI_INT_STATUS);
  116. if (scratch == (u32)-1)
  117. dead = 1;
  118. sdhci_remove_host(host, dead);
  119. if (pdata && pdata->exit)
  120. pdata->exit(host);
  121. iounmap(host->ioaddr);
  122. release_mem_region(iomem->start, resource_size(iomem));
  123. sdhci_free_host(host);
  124. platform_set_drvdata(pdev, NULL);
  125. return 0;
  126. }
  127. static struct platform_driver sdhci_pltfm_driver = {
  128. .driver = {
  129. .name = "sdhci",
  130. .owner = THIS_MODULE,
  131. },
  132. .probe = sdhci_pltfm_probe,
  133. .remove = __devexit_p(sdhci_pltfm_remove),
  134. };
  135. /*****************************************************************************\
  136. * *
  137. * Driver init/exit *
  138. * *
  139. \*****************************************************************************/
  140. static int __init sdhci_drv_init(void)
  141. {
  142. return platform_driver_register(&sdhci_pltfm_driver);
  143. }
  144. static void __exit sdhci_drv_exit(void)
  145. {
  146. platform_driver_unregister(&sdhci_pltfm_driver);
  147. }
  148. module_init(sdhci_drv_init);
  149. module_exit(sdhci_drv_exit);
  150. MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
  151. MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
  152. MODULE_LICENSE("GPL v2");
  153. MODULE_ALIAS("platform:sdhci");