ddr_phy_access.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2021 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. * https://spdx.org/licenses
  6. */
  7. #include "ddr_phy_access.h"
  8. #include <lib/mmio.h>
  9. #include <drivers/marvell/ccu.h>
  10. #include <errno.h>
  11. #define DDR_PHY_END_ADDRESS 0x100000
  12. #ifdef DDR_PHY_DEBUG
  13. #define debug_printf(...) printf(__VA_ARGS__)
  14. #else
  15. #define debug_printf(...)
  16. #endif
  17. /*
  18. * This routine writes 'data' to specified 'address' offset,
  19. * with optional debug print support
  20. */
  21. int snps_fw_write(uintptr_t offset, uint16_t data)
  22. {
  23. debug_printf("In %s\n", __func__);
  24. if (offset < DDR_PHY_END_ADDRESS) {
  25. mmio_write_16(DDR_PHY_BASE_ADDR + (2 * offset), data);
  26. return 0;
  27. }
  28. debug_printf("%s: illegal offset value: 0x%x\n", __func__, offset);
  29. return -EINVAL;
  30. }
  31. int snps_fw_read(uintptr_t offset, uint16_t *read)
  32. {
  33. debug_printf("In %s\n", __func__);
  34. if (offset < DDR_PHY_END_ADDRESS) {
  35. *read = mmio_read_16(DDR_PHY_BASE_ADDR + (2 * offset));
  36. return 0;
  37. }
  38. debug_printf("%s: illegal offset value: 0x%x\n", __func__, offset);
  39. return -EINVAL;
  40. }
  41. int mvebu_ddr_phy_write(uintptr_t offset, uint16_t data)
  42. {
  43. return snps_fw_write(offset, data);
  44. }
  45. int mvebu_ddr_phy_read(uintptr_t offset, uint16_t *read)
  46. {
  47. return snps_fw_read(offset, read);
  48. }