sata.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2000-2005, DENX Software Engineering
  4. * Wolfgang Denk <wd@denx.de>
  5. * Copyright (C) Procsys. All rights reserved.
  6. * Mushtaq Khan <mushtaq_k@procsys.com>
  7. * <mushtaqk_921@yahoo.co.in>
  8. * Copyright (C) 2008 Freescale Semiconductor, Inc.
  9. * Dave Liu <daveliu@freescale.com>
  10. */
  11. #include <common.h>
  12. #include <ahci.h>
  13. #include <dm.h>
  14. #include <sata.h>
  15. #ifndef CONFIG_AHCI
  16. struct blk_desc sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE];
  17. #endif
  18. int sata_reset(struct udevice *dev)
  19. {
  20. struct ahci_ops *ops = ahci_get_ops(dev);
  21. if (!ops->reset)
  22. return -ENOSYS;
  23. return ops->reset(dev);
  24. }
  25. int sata_dm_port_status(struct udevice *dev, int port)
  26. {
  27. struct ahci_ops *ops = ahci_get_ops(dev);
  28. if (!ops->port_status)
  29. return -ENOSYS;
  30. return ops->port_status(dev, port);
  31. }
  32. int sata_scan(struct udevice *dev)
  33. {
  34. struct ahci_ops *ops = ahci_get_ops(dev);
  35. if (!ops->scan)
  36. return -ENOSYS;
  37. return ops->scan(dev);
  38. }
  39. #ifndef CONFIG_AHCI
  40. #ifdef CONFIG_PARTITIONS
  41. struct blk_desc *sata_get_dev(int dev)
  42. {
  43. return (dev < CONFIG_SYS_SATA_MAX_DEVICE) ? &sata_dev_desc[dev] : NULL;
  44. }
  45. #endif
  46. #endif
  47. #ifdef CONFIG_BLK
  48. static unsigned long sata_bread(struct udevice *dev, lbaint_t start,
  49. lbaint_t blkcnt, void *dst)
  50. {
  51. return -ENOSYS;
  52. }
  53. static unsigned long sata_bwrite(struct udevice *dev, lbaint_t start,
  54. lbaint_t blkcnt, const void *buffer)
  55. {
  56. return -ENOSYS;
  57. }
  58. #else
  59. static unsigned long sata_bread(struct blk_desc *block_dev, lbaint_t start,
  60. lbaint_t blkcnt, void *dst)
  61. {
  62. return sata_read(block_dev->devnum, start, blkcnt, dst);
  63. }
  64. static unsigned long sata_bwrite(struct blk_desc *block_dev, lbaint_t start,
  65. lbaint_t blkcnt, const void *buffer)
  66. {
  67. return sata_write(block_dev->devnum, start, blkcnt, buffer);
  68. }
  69. #endif
  70. #ifndef CONFIG_AHCI
  71. int __sata_initialize(void)
  72. {
  73. int rc, ret = -1;
  74. int i;
  75. for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++) {
  76. memset(&sata_dev_desc[i], 0, sizeof(struct blk_desc));
  77. sata_dev_desc[i].if_type = IF_TYPE_SATA;
  78. sata_dev_desc[i].devnum = i;
  79. sata_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
  80. sata_dev_desc[i].type = DEV_TYPE_HARDDISK;
  81. sata_dev_desc[i].lba = 0;
  82. sata_dev_desc[i].blksz = 512;
  83. sata_dev_desc[i].log2blksz = LOG2(sata_dev_desc[i].blksz);
  84. #ifndef CONFIG_BLK
  85. sata_dev_desc[i].block_read = sata_bread;
  86. sata_dev_desc[i].block_write = sata_bwrite;
  87. #endif
  88. rc = init_sata(i);
  89. if (!rc) {
  90. rc = scan_sata(i);
  91. if (!rc && sata_dev_desc[i].lba > 0 &&
  92. sata_dev_desc[i].blksz > 0) {
  93. part_init(&sata_dev_desc[i]);
  94. ret = i;
  95. }
  96. }
  97. }
  98. return ret;
  99. }
  100. int sata_initialize(void) __attribute__((weak, alias("__sata_initialize")));
  101. __weak int __sata_stop(void)
  102. {
  103. int i, err = 0;
  104. for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++)
  105. err |= reset_sata(i);
  106. if (err)
  107. printf("Could not reset some SATA devices\n");
  108. return err;
  109. }
  110. int sata_stop(void) __attribute__((weak, alias("__sata_stop")));
  111. #endif
  112. #ifdef CONFIG_BLK
  113. static const struct blk_ops sata_blk_ops = {
  114. .read = sata_bread,
  115. .write = sata_bwrite,
  116. };
  117. U_BOOT_DRIVER(sata_blk) = {
  118. .name = "sata_blk",
  119. .id = UCLASS_BLK,
  120. .ops = &sata_blk_ops,
  121. };
  122. #else
  123. U_BOOT_LEGACY_BLK(sata) = {
  124. .if_typename = "sata",
  125. .if_type = IF_TYPE_SATA,
  126. .max_devs = CONFIG_SYS_SATA_MAX_DEVICE,
  127. .desc = sata_dev_desc,
  128. };
  129. #endif