sdio-dw-platform.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 "sdio-dw-platform.h"
  11. #include <mmu.h>
  12. rt_err_t sdio_dw_platform_register(struct rt_platform_device *pdev,
  13. const struct sdio_dw_drv_data *drv_data)
  14. {
  15. rt_err_t err = RT_EOK;
  16. struct rt_device *dev = &pdev->parent;
  17. struct sdio_dw *sd = rt_calloc(1, sizeof(*sd));
  18. if (!sd)
  19. {
  20. return -RT_ENOMEM;
  21. }
  22. sd->bus_dev = &pdev->parent;
  23. sd->base = rt_dm_dev_iomap(dev, 0);
  24. if (!sd->base)
  25. {
  26. err = -RT_EIO;
  27. goto _fail;
  28. }
  29. sd->irq = rt_dm_dev_get_irq(dev, 0);
  30. if (sd->irq < 0)
  31. {
  32. err = sd->irq;
  33. goto _fail;
  34. }
  35. sd->parent.ofw_node = dev->ofw_node;
  36. sd->base_phy = (rt_ubase_t)rt_kmem_v2p(sd->base);
  37. sd->drv_data = drv_data;
  38. pdev->parent.user_data = sd;
  39. if ((err = sdio_dw_probe(sd)))
  40. {
  41. goto _fail;
  42. }
  43. return RT_EOK;
  44. _fail:
  45. if (sd->base)
  46. {
  47. rt_iounmap(sd->base);
  48. }
  49. rt_free(sd);
  50. return err;
  51. }
  52. static rt_err_t sdio_dw_platform_probe(struct rt_platform_device *pdev)
  53. {
  54. const struct sdio_dw_drv_data *drv_data = RT_NULL;
  55. if (pdev->parent.ofw_node)
  56. {
  57. drv_data = pdev->id->data;
  58. }
  59. return sdio_dw_platform_register(pdev, drv_data);
  60. }
  61. static rt_err_t sdio_dw_platform_remove(struct rt_platform_device *pdev)
  62. {
  63. struct sdio_dw *sd = pdev->parent.user_data;
  64. sdio_dw_remove(sd);
  65. rt_iounmap(sd->base);
  66. rt_free(sd);
  67. return RT_EOK;
  68. }
  69. static const struct rt_ofw_node_id sdio_dw_platform_ofw_ids[] =
  70. {
  71. { .compatible = "snps,dw-mshc", },
  72. { .compatible = "img,pistachio-dw-mshc", },
  73. { /* sentinel */ }
  74. };
  75. static struct rt_platform_driver sdio_dw_platform_driver =
  76. {
  77. .name = "dw-mmc",
  78. .ids = sdio_dw_platform_ofw_ids,
  79. .probe = sdio_dw_platform_probe,
  80. .remove = sdio_dw_platform_remove,
  81. };
  82. RT_PLATFORM_DRIVER_EXPORT(sdio_dw_platform_driver);