dw_mmc-pci.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 SYNOPSYS_DW_MCI_VENDOR_ID 0x700
  23. #define SYNOPSYS_DW_MCI_DEVICE_ID 0x1107
  24. /* Defining the Capabilities */
  25. #define DW_MCI_CAPABILITIES (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED |\
  26. MMC_CAP_SD_HIGHSPEED | MMC_CAP_8_BIT_DATA |\
  27. MMC_CAP_SDIO_IRQ)
  28. static struct dw_mci_board pci_board_data = {
  29. .num_slots = 1,
  30. .caps = DW_MCI_CAPABILITIES,
  31. .bus_hz = 33 * 1000 * 1000,
  32. .detect_delay_ms = 200,
  33. .fifo_depth = 32,
  34. };
  35. static int dw_mci_pci_probe(struct pci_dev *pdev,
  36. const struct pci_device_id *entries)
  37. {
  38. struct dw_mci *host;
  39. int ret;
  40. ret = pcim_enable_device(pdev);
  41. if (ret)
  42. return ret;
  43. host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL);
  44. if (!host)
  45. return -ENOMEM;
  46. host->irq = pdev->irq;
  47. host->irq_flags = IRQF_SHARED;
  48. host->dev = &pdev->dev;
  49. host->pdata = &pci_board_data;
  50. ret = pcim_iomap_regions(pdev, 1 << PCI_BAR_NO, pci_name(pdev));
  51. if (ret)
  52. return ret;
  53. host->regs = pcim_iomap_table(pdev)[PCI_BAR_NO];
  54. pci_set_master(pdev);
  55. ret = dw_mci_probe(host);
  56. if (ret)
  57. return ret;
  58. pci_set_drvdata(pdev, host);
  59. return 0;
  60. }
  61. static void dw_mci_pci_remove(struct pci_dev *pdev)
  62. {
  63. struct dw_mci *host = pci_get_drvdata(pdev);
  64. dw_mci_remove(host);
  65. }
  66. #ifdef CONFIG_PM_SLEEP
  67. static int dw_mci_pci_suspend(struct device *dev)
  68. {
  69. struct pci_dev *pdev = to_pci_dev(dev);
  70. struct dw_mci *host = pci_get_drvdata(pdev);
  71. return dw_mci_suspend(host);
  72. }
  73. static int dw_mci_pci_resume(struct device *dev)
  74. {
  75. struct pci_dev *pdev = to_pci_dev(dev);
  76. struct dw_mci *host = pci_get_drvdata(pdev);
  77. return dw_mci_resume(host);
  78. }
  79. #endif /* CONFIG_PM_SLEEP */
  80. static SIMPLE_DEV_PM_OPS(dw_mci_pci_pmops, dw_mci_pci_suspend, dw_mci_pci_resume);
  81. static const struct pci_device_id dw_mci_pci_id[] = {
  82. { PCI_DEVICE(SYNOPSYS_DW_MCI_VENDOR_ID, SYNOPSYS_DW_MCI_DEVICE_ID) },
  83. {}
  84. };
  85. MODULE_DEVICE_TABLE(pci, dw_mci_pci_id);
  86. static struct pci_driver dw_mci_pci_driver = {
  87. .name = "dw_mmc_pci",
  88. .id_table = dw_mci_pci_id,
  89. .probe = dw_mci_pci_probe,
  90. .remove = dw_mci_pci_remove,
  91. .driver = {
  92. .pm = &dw_mci_pci_pmops
  93. },
  94. };
  95. module_pci_driver(dw_mci_pci_driver);
  96. MODULE_DESCRIPTION("DW Multimedia Card PCI Interface driver");
  97. MODULE_AUTHOR("Shashidhar Hiremath <shashidharh@vayavyalabs.com>");
  98. MODULE_LICENSE("GPL v2");