emmc_csl_sd.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2016 - 2020, Broadcom
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef CSL_SD_H
  7. #define CSL_SD_H
  8. #define SD_CLOCK_BASE 104000000
  9. #define SD_CLOCK_52MHZ 52000000
  10. #define SD_CLOCK_26MHZ 26000000
  11. #define SD_CLOCK_17MHZ 17330000
  12. #define SD_CLOCK_13MHZ 13000000
  13. #define SD_CLOCK_10MHZ 10000000
  14. #define SD_CLOCK_9MHZ 9000000
  15. #define SD_CLOCK_7MHZ 7000000
  16. #define SD_CLOCK_5MHZ 5000000
  17. #define SD_CLOCK_1MHZ 1000000
  18. #define SD_CLOCK_400KHZ 400000
  19. #define SD_DRIVE_STRENGTH_MASK 0x38000000
  20. #if defined(_BCM213x1_) || defined(_BCM21551_) || defined(_ATHENA_)
  21. #define SD_DRIVE_STRENGTH 0x28000000
  22. #elif defined(_BCM2153_)
  23. #define SD_DRIVE_STRENGTH 0x38000000
  24. #else
  25. #define SD_DRIVE_STRENGTH 0x00000000
  26. #endif
  27. #define SD_NUM_HOST 2
  28. #define SD_CARD_UNLOCK 0
  29. #define SD_CARD_LOCK 0x4
  30. #define SD_CARD_CLEAR_PWD 0x2
  31. #define SD_CARD_SET_PWD 0x1
  32. #define SD_CARD_ERASE_PWD 0x8
  33. #define SD_CARD_LOCK_STATUS 0x02000000
  34. #define SD_CARD_UNLOCK_STATUS 0x01000000
  35. #define SD_CMD_ERROR_FLAGS (0x18F << 16)
  36. #define SD_DATA_ERROR_FLAGS (0x70 << 16)
  37. #define SD_AUTO_CMD12_ERROR_FLAGS (0x9F)
  38. #define SD_CARD_STATUS_ERROR 0x10000000
  39. #define SD_CMD_MISSING 0x80000000
  40. #define SD_TRAN_HIGH_SPEED 0x32
  41. #define SD_CARD_HIGH_CAPACITY 0x40000000
  42. #define SD_CARD_POWER_UP_STATUS 0x80000000
  43. struct sd_dev_info {
  44. uint32_t mode; /* interrupt or polling */
  45. uint32_t dma; /* dma enabled or disabled */
  46. uint32_t voltage; /* voltage level */
  47. uint32_t slot; /* if the HC is locatd at slot 0 or slot 1 */
  48. uint32_t version; /* 1.0 or 2.0 */
  49. uint32_t curSystemAddr; /* system address */
  50. uint32_t dataWidth; /* data width for the controller */
  51. uint32_t clock; /* clock rate */
  52. uint32_t status; /* if device is active on transfer or not */
  53. };
  54. void data_xfer_setup(struct sd_handle *handle, uint8_t *data,
  55. uint32_t length, int dir);
  56. int reset_card(struct sd_handle *handle);
  57. int reset_host_ctrl(struct sd_handle *handle);
  58. int init_card(struct sd_handle *handle, int detection);
  59. int init_mmc_card(struct sd_handle *handle);
  60. int write_buffer(struct sd_handle *handle, uint32_t len, uint8_t *buffer);
  61. int read_buffer(struct sd_handle *handle, uint32_t len, uint8_t *buffer);
  62. int select_blk_sz(struct sd_handle *handle, uint16_t size);
  63. int check_error(struct sd_handle *handle, uint32_t ints);
  64. int process_data_xfer(struct sd_handle *handle, uint8_t *buffer,
  65. uint32_t addr, uint32_t length, int dir);
  66. int read_block(struct sd_handle *handle, uint8_t *dst, uint32_t addr,
  67. uint32_t len);
  68. #ifdef INCLUDE_EMMC_DRIVER_ERASE_CODE
  69. int erase_card(struct sd_handle *handle, uint32_t addr, uint32_t blocks);
  70. #endif
  71. int write_block(struct sd_handle *handle, uint8_t *src, uint32_t addr,
  72. uint32_t len);
  73. int process_cmd_response(struct sd_handle *handle, uint32_t cmdIndex,
  74. uint32_t rsp0, uint32_t rsp1, uint32_t rsp2,
  75. uint32_t rsp3, struct sd_resp *resp);
  76. int32_t set_config(struct sd_handle *handle, uint32_t speed,
  77. uint32_t retry, uint32_t dma, uint32_t dmaBound,
  78. uint32_t blkSize, uint32_t wfe_retry);
  79. uint32_t wait_for_event(struct sd_handle *handle, uint32_t mask,
  80. uint32_t retry);
  81. int set_boot_config(struct sd_handle *handle, uint32_t config);
  82. int mmc_cmd1(struct sd_handle *handle);
  83. #endif /* CSL_SD_H */