Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2004 Texas Instruments. |
| 4 | * Copyright (C) 2009 David Brownell |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 9 | #include <asm/arch/hardware.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 11 | #include <asm/io.h> |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 12 | |
Hadli, Manjunath | 8f5d468 | 2012-02-06 00:30:44 +0000 | [diff] [blame] | 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 15 | /* offsets from PLL controller base */ |
| 16 | #define PLLC_PLLCTL 0x100 |
| 17 | #define PLLC_PLLM 0x110 |
| 18 | #define PLLC_PREDIV 0x114 |
| 19 | #define PLLC_PLLDIV1 0x118 |
| 20 | #define PLLC_PLLDIV2 0x11c |
| 21 | #define PLLC_PLLDIV3 0x120 |
| 22 | #define PLLC_POSTDIV 0x128 |
| 23 | #define PLLC_BPDIV 0x12c |
| 24 | #define PLLC_PLLDIV4 0x160 |
| 25 | #define PLLC_PLLDIV5 0x164 |
| 26 | #define PLLC_PLLDIV6 0x168 |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 27 | #define PLLC_PLLDIV7 0x16c |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 28 | #define PLLC_PLLDIV8 0x170 |
| 29 | #define PLLC_PLLDIV9 0x174 |
| 30 | |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 31 | unsigned int sysdiv[9] = { |
| 32 | PLLC_PLLDIV1, PLLC_PLLDIV2, PLLC_PLLDIV3, PLLC_PLLDIV4, PLLC_PLLDIV5, |
| 33 | PLLC_PLLDIV6, PLLC_PLLDIV7, PLLC_PLLDIV8, PLLC_PLLDIV9 |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | int clk_get(enum davinci_clk_ids id) |
| 37 | { |
| 38 | int pre_div; |
| 39 | int pllm; |
| 40 | int post_div; |
| 41 | int pll_out; |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 42 | unsigned int pll_base; |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 43 | |
| 44 | pll_out = CONFIG_SYS_OSCIN_FREQ; |
| 45 | |
| 46 | if (id == DAVINCI_AUXCLK_CLKID) |
| 47 | goto out; |
| 48 | |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 49 | if ((id >> 16) == 1) |
| 50 | pll_base = (unsigned int)davinci_pllc1_regs; |
| 51 | else |
| 52 | pll_base = (unsigned int)davinci_pllc0_regs; |
| 53 | |
| 54 | id &= 0xFFFF; |
| 55 | |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 56 | /* |
| 57 | * Lets keep this simple. Combining operations can result in |
| 58 | * unexpected approximations |
| 59 | */ |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 60 | pre_div = (readl(pll_base + PLLC_PREDIV) & |
| 61 | DAVINCI_PLLC_DIV_MASK) + 1; |
| 62 | pllm = readl(pll_base + PLLC_PLLM) + 1; |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 63 | |
| 64 | pll_out /= pre_div; |
| 65 | pll_out *= pllm; |
| 66 | |
| 67 | if (id == DAVINCI_PLLM_CLKID) |
| 68 | goto out; |
| 69 | |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 70 | post_div = (readl(pll_base + PLLC_POSTDIV) & |
| 71 | DAVINCI_PLLC_DIV_MASK) + 1; |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 72 | |
| 73 | pll_out /= post_div; |
| 74 | |
| 75 | if (id == DAVINCI_PLLC_CLKID) |
| 76 | goto out; |
| 77 | |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 78 | pll_out /= (readl(pll_base + sysdiv[id - 1]) & |
| 79 | DAVINCI_PLLC_DIV_MASK) + 1; |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 80 | |
| 81 | out: |
| 82 | return pll_out; |
| 83 | } |
Laurence Withers | be7d257 | 2012-07-30 23:30:37 +0000 | [diff] [blame] | 84 | |
| 85 | int set_cpu_clk_info(void) |
| 86 | { |
| 87 | gd->bd->bi_arm_freq = clk_get(DAVINCI_ARM_CLKID) / 1000000; |
| 88 | /* DDR PHY uses an x2 input clock */ |
| 89 | gd->bd->bi_ddr_freq = cpu_is_da830() ? 0 : |
| 90 | (clk_get(DAVINCI_DDR_CLKID) / 1000000); |
| 91 | gd->bd->bi_dsp_freq = 0; |
| 92 | return 0; |
| 93 | } |