dwc_ahci.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * DWC SATA platform driver
  3. *
  4. * (C) Copyright 2016
  5. * Texas Instruments Incorporated, <www.ti.com>
  6. *
  7. * Author: Mugunthan V N <mugunthanvnm@ti.com>
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <dm.h>
  13. #include <ahci.h>
  14. #include <scsi.h>
  15. #include <sata.h>
  16. #include <asm/arch/sata.h>
  17. #include <asm/io.h>
  18. #include <generic-phy.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. struct dwc_ahci_priv {
  21. void *base;
  22. void *wrapper_base;
  23. };
  24. static int dwc_ahci_ofdata_to_platdata(struct udevice *dev)
  25. {
  26. struct dwc_ahci_priv *priv = dev_get_priv(dev);
  27. struct scsi_platdata *plat = dev_get_uclass_platdata(dev);
  28. fdt_addr_t addr;
  29. plat->max_id = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev),
  30. "max-id", CONFIG_SYS_SCSI_MAX_SCSI_ID);
  31. plat->max_lun = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev),
  32. "max-lun", CONFIG_SYS_SCSI_MAX_LUN);
  33. priv->base = map_physmem(devfdt_get_addr(dev), sizeof(void *),
  34. MAP_NOCACHE);
  35. addr = devfdt_get_addr_index(dev, 1);
  36. if (addr != FDT_ADDR_T_NONE) {
  37. priv->wrapper_base = map_physmem(addr, sizeof(void *),
  38. MAP_NOCACHE);
  39. } else {
  40. priv->wrapper_base = NULL;
  41. }
  42. return 0;
  43. }
  44. static int dwc_ahci_probe(struct udevice *dev)
  45. {
  46. struct dwc_ahci_priv *priv = dev_get_priv(dev);
  47. int ret;
  48. struct phy phy;
  49. ret = generic_phy_get_by_name(dev, "sata-phy", &phy);
  50. if (ret) {
  51. pr_err("can't get the phy from DT\n");
  52. return ret;
  53. }
  54. ret = generic_phy_init(&phy);
  55. if (ret) {
  56. pr_err("unable to initialize the sata phy\n");
  57. return ret;
  58. }
  59. ret = generic_phy_power_on(&phy);
  60. if (ret) {
  61. pr_err("unable to power on the sata phy\n");
  62. return ret;
  63. }
  64. if (priv->wrapper_base) {
  65. u32 val = TI_SATA_IDLE_NO | TI_SATA_STANDBY_NO;
  66. /* Enable SATA module, No Idle, No Standby */
  67. writel(val, priv->wrapper_base + TI_SATA_SYSCONFIG);
  68. }
  69. ret = ahci_init_dm(dev, priv->base);
  70. if (ret)
  71. return ret;
  72. return achi_start_ports_dm(dev);
  73. }
  74. static const struct udevice_id dwc_ahci_ids[] = {
  75. { .compatible = "snps,dwc-ahci" },
  76. { }
  77. };
  78. U_BOOT_DRIVER(dwc_ahci) = {
  79. .name = "dwc_ahci",
  80. .id = UCLASS_SCSI,
  81. .of_match = dwc_ahci_ids,
  82. .ofdata_to_platdata = dwc_ahci_ofdata_to_platdata,
  83. .ops = &scsi_ops,
  84. .probe = dwc_ahci_probe,
  85. .priv_auto_alloc_size = sizeof(struct dwc_ahci_priv),
  86. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  87. };