sata.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 <blk.h>
  14. #include <dm.h>
  15. #include <part.h>
  16. #include <sata.h>
  17. #ifndef CONFIG_AHCI
  18. struct blk_desc sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE];
  19. #endif
  20. int sata_reset(struct udevice *dev)
  21. {
  22. struct ahci_ops *ops = ahci_get_ops(dev);
  23. if (!ops->reset)
  24. return -ENOSYS;
  25. return ops->reset(dev);
  26. }
  27. int sata_dm_port_status(struct udevice *dev, int port)
  28. {
  29. struct ahci_ops *ops = ahci_get_ops(dev);
  30. if (!ops->port_status)
  31. return -ENOSYS;
  32. return ops->port_status(dev, port);
  33. }
  34. int sata_scan(struct udevice *dev)
  35. {
  36. struct ahci_ops *ops = ahci_get_ops(dev);
  37. if (!ops->scan)
  38. return -ENOSYS;
  39. return ops->scan(dev);
  40. }
  41. #ifndef CONFIG_AHCI
  42. #ifdef CONFIG_PARTITIONS
  43. struct blk_desc *sata_get_dev(int dev)
  44. {
  45. return (dev < CONFIG_SYS_SATA_MAX_DEVICE) ? &sata_dev_desc[dev] : NULL;
  46. }
  47. #endif
  48. #endif
  49. #ifdef CONFIG_BLK
  50. static unsigned long sata_bread(struct udevice *dev, lbaint_t start,
  51. lbaint_t blkcnt, void *dst)
  52. {
  53. return -ENOSYS;
  54. }
  55. static unsigned long sata_bwrite(struct udevice *dev, lbaint_t start,
  56. lbaint_t blkcnt, const void *buffer)
  57. {
  58. return -ENOSYS;
  59. }
  60. #else
  61. static unsigned long sata_bread(struct blk_desc *block_dev, lbaint_t start,
  62. lbaint_t blkcnt, void *dst)
  63. {
  64. return sata_read(block_dev->devnum, start, blkcnt, dst);
  65. }
  66. static unsigned long sata_bwrite(struct blk_desc *block_dev, lbaint_t start,
  67. lbaint_t blkcnt, const void *buffer)
  68. {
  69. return sata_write(block_dev->devnum, start, blkcnt, buffer);
  70. }
  71. #endif
  72. #ifndef CONFIG_AHCI
  73. int __sata_initialize(void)
  74. {
  75. int rc, ret = -1;
  76. int i;
  77. for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++) {
  78. memset(&sata_dev_desc[i], 0, sizeof(struct blk_desc));
  79. sata_dev_desc[i].if_type = IF_TYPE_SATA;
  80. sata_dev_desc[i].devnum = i;
  81. sata_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
  82. sata_dev_desc[i].type = DEV_TYPE_HARDDISK;
  83. sata_dev_desc[i].lba = 0;
  84. sata_dev_desc[i].blksz = 512;
  85. sata_dev_desc[i].log2blksz = LOG2(sata_dev_desc[i].blksz);
  86. #ifndef CONFIG_BLK
  87. sata_dev_desc[i].block_read = sata_bread;
  88. sata_dev_desc[i].block_write = sata_bwrite;
  89. #endif
  90. rc = init_sata(i);
  91. if (!rc) {
  92. rc = scan_sata(i);
  93. if (!rc && sata_dev_desc[i].lba > 0 &&
  94. sata_dev_desc[i].blksz > 0) {
  95. part_init(&sata_dev_desc[i]);
  96. ret = i;
  97. }
  98. }
  99. }
  100. return ret;
  101. }
  102. int sata_initialize(void) __attribute__((weak, alias("__sata_initialize")));
  103. __weak int __sata_stop(void)
  104. {
  105. int i, err = 0;
  106. for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++)
  107. err |= reset_sata(i);
  108. if (err)
  109. printf("Could not reset some SATA devices\n");
  110. return err;
  111. }
  112. int sata_stop(void) __attribute__((weak, alias("__sata_stop")));
  113. #endif
  114. #ifdef CONFIG_BLK
  115. static const struct blk_ops sata_blk_ops = {
  116. .read = sata_bread,
  117. .write = sata_bwrite,
  118. };
  119. U_BOOT_DRIVER(sata_blk) = {
  120. .name = "sata_blk",
  121. .id = UCLASS_BLK,
  122. .ops = &sata_blk_ops,
  123. };
  124. #else
  125. U_BOOT_LEGACY_BLK(sata) = {
  126. .if_typename = "sata",
  127. .if_type = IF_TYPE_SATA,
  128. .max_devs = CONFIG_SYS_SATA_MAX_DEVICE,
  129. .desc = sata_dev_desc,
  130. };
  131. #endif