sdio-dw-pci.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-12-06 GuEe-GUI first version
  9. */
  10. #include "dev_sdio_dw.h"
  11. #include <mmu.h>
  12. #define SYNOPSYS_DW_MCI_VENDOR_ID 0x0700
  13. #define SYNOPSYS_DW_MCI_DEVICE_ID 0x1107
  14. #define MCI_REG_NO 2
  15. static const struct sdio_dw_drv_data sdio_dw_pci_drv_data =
  16. {
  17. };
  18. static rt_err_t sdio_dw_pci_probe(struct rt_pci_device *pdev)
  19. {
  20. rt_err_t err;
  21. struct sdio_dw *sd = rt_calloc(1, sizeof(*sd));
  22. if (!sd)
  23. {
  24. return -RT_ENOMEM;
  25. }
  26. sd->bus_dev = &pdev->parent;
  27. sd->base = rt_pci_iomap(pdev, MCI_REG_NO);
  28. if (!sd->base)
  29. {
  30. goto _fail;
  31. }
  32. sd->irq = pdev->irq;
  33. rt_pci_irq_unmask(pdev);
  34. sd->base_phy = (rt_ubase_t)rt_kmem_v2p(sd->base);
  35. sd->drv_data = &sdio_dw_pci_drv_data;
  36. /* board data */
  37. sd->bus_hz = 33 * 1000 * 1000;
  38. sd->detect_delay_ms = 200;
  39. sd->fifo_depth = 32;
  40. pdev->parent.user_data = sd;
  41. if ((err = sdio_dw_probe(sd)))
  42. {
  43. goto _fail;
  44. }
  45. return RT_EOK;
  46. _fail:
  47. if (sd->base)
  48. {
  49. rt_iounmap(sd->base);
  50. }
  51. rt_free(sd);
  52. return err;
  53. }
  54. static rt_err_t sdio_dw_pci_remove(struct rt_pci_device *pdev)
  55. {
  56. struct sdio_dw *sd = pdev->parent.user_data;
  57. sdio_dw_remove(sd);
  58. rt_iounmap(sd->base);
  59. rt_free(sd);
  60. return RT_EOK;
  61. }
  62. static const struct rt_pci_device_id sdio_dw_pci_pci_ids[] =
  63. {
  64. { RT_PCI_DEVICE_ID(SYNOPSYS_DW_MCI_VENDOR_ID, SYNOPSYS_DW_MCI_DEVICE_ID) },
  65. { /* sentinel */ }
  66. };
  67. static struct rt_pci_driver sdio_dw_pci_driver =
  68. {
  69. .name = "dw-mmc-pci",
  70. .ids = sdio_dw_pci_pci_ids,
  71. .probe = sdio_dw_pci_probe,
  72. .remove = sdio_dw_pci_remove,
  73. };
  74. RT_PCI_DRIVER_EXPORT(sdio_dw_pci_driver);