mv_ddr_common.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) Marvell International Ltd. and its affiliates
  4. */
  5. #include "mv_ddr_common.h"
  6. #include "ddr_ml_wrapper.h"
  7. void mv_ddr_ver_print(void)
  8. {
  9. printf("%s %s\n", mv_ddr_version_string, mv_ddr_build_message);
  10. }
  11. /* ceiling division for positive integers */
  12. unsigned int ceil_div(unsigned int x, unsigned int y)
  13. {
  14. return (x % y) ? (x / y + 1) : (x / y);
  15. }
  16. /*
  17. * time to number of clocks calculation based on the rounding algorithm
  18. * using 97.4% inverse factor per JEDEC Standard No. 21-C, 4.1.2.L-4:
  19. * Serial Presence Detect (SPD) for DDR4 SDRAM Modules
  20. */
  21. unsigned int time_to_nclk(unsigned int t, unsigned int tclk)
  22. {
  23. /* t & tclk parameters are in ps */
  24. return ((unsigned long)t * 1000 / tclk + 974) / 1000;
  25. }
  26. /* round division of two positive integers to the nearest whole number */
  27. int round_div(unsigned int dividend, unsigned int divisor, unsigned int *quotient)
  28. {
  29. if (quotient == NULL) {
  30. printf("%s: error: NULL quotient pointer found\n", __func__);
  31. return MV_FAIL;
  32. }
  33. if (divisor == 0) {
  34. printf("%s: error: division by zero\n", __func__);
  35. return MV_FAIL;
  36. } else {
  37. *quotient = (dividend + divisor / 2) / divisor;
  38. }
  39. return MV_OK;
  40. }