cpu.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2004 Texas Instruments.
  4. * Copyright (C) 2009 David Brownell
  5. */
  6. #include <common.h>
  7. #include <init.h>
  8. #include <asm/arch/hardware.h>
  9. #include <asm/io.h>
  10. DECLARE_GLOBAL_DATA_PTR;
  11. /* offsets from PLL controller base */
  12. #define PLLC_PLLCTL 0x100
  13. #define PLLC_PLLM 0x110
  14. #define PLLC_PREDIV 0x114
  15. #define PLLC_PLLDIV1 0x118
  16. #define PLLC_PLLDIV2 0x11c
  17. #define PLLC_PLLDIV3 0x120
  18. #define PLLC_POSTDIV 0x128
  19. #define PLLC_BPDIV 0x12c
  20. #define PLLC_PLLDIV4 0x160
  21. #define PLLC_PLLDIV5 0x164
  22. #define PLLC_PLLDIV6 0x168
  23. #define PLLC_PLLDIV7 0x16c
  24. #define PLLC_PLLDIV8 0x170
  25. #define PLLC_PLLDIV9 0x174
  26. unsigned int sysdiv[9] = {
  27. PLLC_PLLDIV1, PLLC_PLLDIV2, PLLC_PLLDIV3, PLLC_PLLDIV4, PLLC_PLLDIV5,
  28. PLLC_PLLDIV6, PLLC_PLLDIV7, PLLC_PLLDIV8, PLLC_PLLDIV9
  29. };
  30. int clk_get(enum davinci_clk_ids id)
  31. {
  32. int pre_div;
  33. int pllm;
  34. int post_div;
  35. int pll_out;
  36. unsigned int pll_base;
  37. pll_out = CONFIG_SYS_OSCIN_FREQ;
  38. if (id == DAVINCI_AUXCLK_CLKID)
  39. goto out;
  40. if ((id >> 16) == 1)
  41. pll_base = (unsigned int)davinci_pllc1_regs;
  42. else
  43. pll_base = (unsigned int)davinci_pllc0_regs;
  44. id &= 0xFFFF;
  45. /*
  46. * Lets keep this simple. Combining operations can result in
  47. * unexpected approximations
  48. */
  49. pre_div = (readl(pll_base + PLLC_PREDIV) &
  50. DAVINCI_PLLC_DIV_MASK) + 1;
  51. pllm = readl(pll_base + PLLC_PLLM) + 1;
  52. pll_out /= pre_div;
  53. pll_out *= pllm;
  54. if (id == DAVINCI_PLLM_CLKID)
  55. goto out;
  56. post_div = (readl(pll_base + PLLC_POSTDIV) &
  57. DAVINCI_PLLC_DIV_MASK) + 1;
  58. pll_out /= post_div;
  59. if (id == DAVINCI_PLLC_CLKID)
  60. goto out;
  61. pll_out /= (readl(pll_base + sysdiv[id - 1]) &
  62. DAVINCI_PLLC_DIV_MASK) + 1;
  63. out:
  64. return pll_out;
  65. }
  66. int set_cpu_clk_info(void)
  67. {
  68. gd->bd->bi_arm_freq = clk_get(DAVINCI_ARM_CLKID) / 1000000;
  69. /* DDR PHY uses an x2 input clock */
  70. gd->bd->bi_ddr_freq = cpu_is_da830() ? 0 :
  71. (clk_get(DAVINCI_DDR_CLKID) / 1000000);
  72. gd->bd->bi_dsp_freq = 0;
  73. return 0;
  74. }