sdhci-pltfm.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 "sdhci.h"
  29. /*****************************************************************************\
  30. * *
  31. * SDHCI core callbacks *
  32. * *
  33. \*****************************************************************************/
  34. static struct sdhci_ops sdhci_pltfm_ops = {
  35. };
  36. /*****************************************************************************\
  37. * *
  38. * Device probing/removal *
  39. * *
  40. \*****************************************************************************/
  41. static int __devinit sdhci_pltfm_probe(struct platform_device *pdev)
  42. {
  43. struct sdhci_host *host;
  44. struct resource *iomem;
  45. int ret;
  46. BUG_ON(pdev == NULL);
  47. iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  48. if (!iomem) {
  49. ret = -ENOMEM;
  50. goto err;
  51. }
  52. if (resource_size(iomem) != 0x100)
  53. dev_err(&pdev->dev, "Invalid iomem size. You may "
  54. "experience problems.\n");
  55. if (pdev->dev.parent)
  56. host = sdhci_alloc_host(pdev->dev.parent, 0);
  57. else
  58. host = sdhci_alloc_host(&pdev->dev, 0);
  59. if (IS_ERR(host)) {
  60. ret = PTR_ERR(host);
  61. goto err;
  62. }
  63. host->hw_name = "platform";
  64. host->ops = &sdhci_pltfm_ops;
  65. host->irq = platform_get_irq(pdev, 0);
  66. if (!request_mem_region(iomem->start, resource_size(iomem),
  67. mmc_hostname(host->mmc))) {
  68. dev_err(&pdev->dev, "cannot request region\n");
  69. ret = -EBUSY;
  70. goto err_request;
  71. }
  72. host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  73. if (!host->ioaddr) {
  74. dev_err(&pdev->dev, "failed to remap registers\n");
  75. ret = -ENOMEM;
  76. goto err_remap;
  77. }
  78. ret = sdhci_add_host(host);
  79. if (ret)
  80. goto err_add_host;
  81. platform_set_drvdata(pdev, host);
  82. return 0;
  83. err_add_host:
  84. iounmap(host->ioaddr);
  85. err_remap:
  86. release_mem_region(iomem->start, resource_size(iomem));
  87. err_request:
  88. sdhci_free_host(host);
  89. err:
  90. printk(KERN_ERR"Probing of sdhci-pltfm failed: %d\n", ret);
  91. return ret;
  92. }
  93. static int __devexit sdhci_pltfm_remove(struct platform_device *pdev)
  94. {
  95. struct sdhci_host *host = platform_get_drvdata(pdev);
  96. struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  97. int dead;
  98. u32 scratch;
  99. dead = 0;
  100. scratch = readl(host->ioaddr + SDHCI_INT_STATUS);
  101. if (scratch == (u32)-1)
  102. dead = 1;
  103. sdhci_remove_host(host, dead);
  104. iounmap(host->ioaddr);
  105. release_mem_region(iomem->start, resource_size(iomem));
  106. sdhci_free_host(host);
  107. platform_set_drvdata(pdev, NULL);
  108. return 0;
  109. }
  110. static struct platform_driver sdhci_pltfm_driver = {
  111. .driver = {
  112. .name = "sdhci",
  113. .owner = THIS_MODULE,
  114. },
  115. .probe = sdhci_pltfm_probe,
  116. .remove = __devexit_p(sdhci_pltfm_remove),
  117. };
  118. /*****************************************************************************\
  119. * *
  120. * Driver init/exit *
  121. * *
  122. \*****************************************************************************/
  123. static int __init sdhci_drv_init(void)
  124. {
  125. return platform_driver_register(&sdhci_pltfm_driver);
  126. }
  127. static void __exit sdhci_drv_exit(void)
  128. {
  129. platform_driver_unregister(&sdhci_pltfm_driver);
  130. }
  131. module_init(sdhci_drv_init);
  132. module_exit(sdhci_drv_exit);
  133. MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
  134. MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
  135. MODULE_LICENSE("GPL v2");
  136. MODULE_ALIAS("platform:sdhci");