dw_mmc-pci.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Synopsys DesignWare Multimedia Card PCI Interface driver
  3. *
  4. * Copyright (C) 2012 Vayavya Labs Pvt. Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/interrupt.h>
  12. #include <linux/module.h>
  13. #include <linux/io.h>
  14. #include <linux/irq.h>
  15. #include <linux/pci.h>
  16. #include <linux/slab.h>
  17. #include <linux/mmc/host.h>
  18. #include <linux/mmc/mmc.h>
  19. #include <linux/mmc/dw_mmc.h>
  20. #include "dw_mmc.h"
  21. #define PCI_BAR_NO 2
  22. #define COMPLETE_BAR 0
  23. #define SYNOPSYS_DW_MCI_VENDOR_ID 0x700
  24. #define SYNOPSYS_DW_MCI_DEVICE_ID 0x1107
  25. /* Defining the Capabilities */
  26. #define DW_MCI_CAPABILITIES (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED |\
  27. MMC_CAP_SD_HIGHSPEED | MMC_CAP_8_BIT_DATA |\
  28. MMC_CAP_SDIO_IRQ)
  29. static struct dw_mci_board pci_board_data = {
  30. .num_slots = 1,
  31. .caps = DW_MCI_CAPABILITIES,
  32. .bus_hz = 33 * 1000 * 1000,
  33. .detect_delay_ms = 200,
  34. .fifo_depth = 32,
  35. };
  36. static int __devinit dw_mci_pci_probe(struct pci_dev *pdev,
  37. const struct pci_device_id *entries)
  38. {
  39. struct dw_mci *host;
  40. int ret;
  41. ret = pci_enable_device(pdev);
  42. if (ret)
  43. return ret;
  44. if (pci_request_regions(pdev, "dw_mmc_pci")) {
  45. ret = -ENODEV;
  46. goto err_disable_dev;
  47. }
  48. host = kzalloc(sizeof(struct dw_mci), GFP_KERNEL);
  49. if (!host) {
  50. ret = -ENOMEM;
  51. goto err_release;
  52. }
  53. host->irq = pdev->irq;
  54. host->irq_flags = IRQF_SHARED;
  55. host->dev = pdev->dev;
  56. host->pdata = &pci_board_data;
  57. host->regs = pci_iomap(pdev, PCI_BAR_NO, COMPLETE_BAR);
  58. if (!host->regs) {
  59. ret = -EIO;
  60. goto err_unmap;
  61. }
  62. pci_set_drvdata(pdev, host);
  63. ret = dw_mci_probe(host);
  64. if (ret)
  65. goto err_probe_failed;
  66. return ret;
  67. err_probe_failed:
  68. pci_iounmap(pdev, host->regs);
  69. err_unmap:
  70. kfree(host);
  71. err_release:
  72. pci_release_regions(pdev);
  73. err_disable_dev:
  74. pci_disable_device(pdev);
  75. return ret;
  76. }
  77. static void __devexit dw_mci_pci_remove(struct pci_dev *pdev)
  78. {
  79. struct dw_mci *host = pci_get_drvdata(pdev);
  80. dw_mci_remove(host);
  81. pci_set_drvdata(pdev, NULL);
  82. pci_release_regions(pdev);
  83. pci_iounmap(pdev, host->regs);
  84. kfree(host);
  85. pci_disable_device(pdev);
  86. }
  87. #ifdef CONFIG_PM_SLEEP
  88. static int dw_mci_pci_suspend(struct device *dev)
  89. {
  90. int ret;
  91. struct pci_dev *pdev = to_pci_dev(dev);
  92. struct dw_mci *host = pci_get_drvdata(pdev);
  93. ret = dw_mci_suspend(host);
  94. return ret;
  95. }
  96. static int dw_mci_pci_resume(struct device *dev)
  97. {
  98. int ret;
  99. struct pci_dev *pdev = to_pci_dev(dev);
  100. struct dw_mci *host = pci_get_drvdata(pdev);
  101. ret = dw_mci_resume(host);
  102. return ret;
  103. }
  104. #else
  105. #define dw_mci_pci_suspend NULL
  106. #define dw_mci_pci_resume NULL
  107. #endif /* CONFIG_PM_SLEEP */
  108. static SIMPLE_DEV_PM_OPS(dw_mci_pci_pmops, dw_mci_pci_suspend, dw_mci_pci_resume);
  109. static DEFINE_PCI_DEVICE_TABLE(dw_mci_pci_id) = {
  110. { PCI_DEVICE(SYNOPSYS_DW_MCI_VENDOR_ID, SYNOPSYS_DW_MCI_DEVICE_ID) },
  111. {}
  112. };
  113. MODULE_DEVICE_TABLE(pci, dw_mci_pci_id);
  114. static struct pci_driver dw_mci_pci_driver = {
  115. .name = "dw_mmc_pci",
  116. .id_table = dw_mci_pci_id,
  117. .probe = dw_mci_pci_probe,
  118. .remove = dw_mci_pci_remove,
  119. .driver = {
  120. .pm = &dw_mci_pci_pmops
  121. },
  122. };
  123. static int __init dw_mci_init(void)
  124. {
  125. return pci_register_driver(&dw_mci_pci_driver);
  126. }
  127. static void __exit dw_mci_exit(void)
  128. {
  129. pci_unregister_driver(&dw_mci_pci_driver);
  130. }
  131. module_init(dw_mci_init);
  132. module_exit(dw_mci_exit);
  133. MODULE_DESCRIPTION("DW Multimedia Card PCI Interface driver");
  134. MODULE_AUTHOR("Shashidhar Hiremath <shashidharh@vayavyalabs.com>");
  135. MODULE_LICENSE("GPL v2");