blob: 1c545f9f92307f68b4d7daa28c2feae35ae043f7 [file] [log] [blame]
Chandan Uddarajufcc15f52009-11-17 21:02:46 -08001/*
Ajay Dudanib1b7d102009-11-25 14:47:20 -08002 * Copyright (c) 2008, Google Inc.
Chandan Uddarajufcc15f52009-11-17 21:02:46 -08003 * All rights reserved.
4 * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <stdint.h>
31#include <kernel/thread.h>
32#include <platform/iomap.h>
33#include <reg.h>
34
35#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
36
37#define A11S_CLK_CNTL_ADDR (MSM_CSR_BASE + 0x100)
38#define A11S_CLK_SEL_ADDR (MSM_CSR_BASE + 0x104)
39#define VDD_SVS_PLEVEL_ADDR (MSM_CSR_BASE + 0x124)
40
41#define PLL1 1
42#define PLL2 2
43#define SRC_SEL_PLL1 1 /* PLL1. */
44#define SRC_SEL_PLL2 2 /* PLL2. */
45#define DIV_4 3
46#define DIV_2 1
47#define WAIT_CNT 100
48#define VDD_LEVEL 7
49#define MIN_AXI_HZ 120000000
50
51void pll_request(unsigned pll, unsigned enable);
52void axi_clock_init(unsigned rate);
53
54/* The stepping frequencies have been choosen to make sure the step
55 * is <= 256 MHz for both turbo mode and normal mode targets. The
56 * table also assumes the ACPU is running at TCXO freq and AHB div is
57 * set to DIV_1.
58 *
59 * To use the tables:
60 * - Start at location 0/1 depending on clock source sel bit.
61 * - Set values till end of table skipping every other entry.
62 * - When you reach the end of the table, you are done scaling.
63 *
64 * TODO: Need to fix SRC_SEL_PLL1 for 7x25.
65 */
66uint32_t const clk_cntl_reg_val[] = {
67 (WAIT_CNT << 16) | (SRC_SEL_PLL1 << 4) | DIV_4,
68 (WAIT_CNT << 16) | (SRC_SEL_PLL1 << 12) | (DIV_4 << 8),
69 (WAIT_CNT << 16) | (SRC_SEL_PLL1 << 12) | (DIV_2 << 8),
70 (WAIT_CNT << 16) | (SRC_SEL_PLL1 << 12) | DIV_2,
71 (WAIT_CNT << 16) | (SRC_SEL_PLL2 << 4) | DIV_2,
72 (WAIT_CNT << 16) | (SRC_SEL_PLL2 << 12) | (DIV_2 << 8),
73};
74
75/* Using DIV_4 for all cases to avoid worrying about turbo vs. normal
76 * mode. Able to use DIV_4 for all steps because it's the largest AND
77 * the final value. */
78uint32_t const clk_sel_reg_val[] = {
79 DIV_4 << 1 | 1,
80 DIV_4 << 1 | 0,
81 DIV_4 << 1 | 0,
82 DIV_4 << 1 | 1,
83 DIV_4 << 1 | 1,
84 DIV_4 << 1 | 0,
85};
86
Chandan Uddaraju852cd2c2009-12-17 14:28:28 -080087void mdelay(unsigned msecs);
88
89
Chandan Uddarajufcc15f52009-11-17 21:02:46 -080090void acpu_clock_init(void)
91{
92 unsigned i;
93
Chandan Uddaraju96501972009-12-14 23:24:21 -080094#if (!ENABLE_NANDWRITE)
95 int *modem_stat_check = (MSM_SHARED_BASE + 0x14);
96
97 /* Wait for modem to be ready before clock init */
98 while (readl(modem_stat_check) != 1);
99#endif
100
Chandan Uddarajufcc15f52009-11-17 21:02:46 -0800101 /* Increase VDD level to the final value. */
102 writel((1 << 7) | (VDD_LEVEL << 3), VDD_SVS_PLEVEL_ADDR);
Chandan Uddaraju852cd2c2009-12-17 14:28:28 -0800103#if (!ENABLE_NANDWRITE)
Chandan Uddarajufcc15f52009-11-17 21:02:46 -0800104 thread_sleep(1);
Chandan Uddaraju852cd2c2009-12-17 14:28:28 -0800105#else
106 mdelay(1);
107#endif
Chandan Uddarajufcc15f52009-11-17 21:02:46 -0800108
109 /* Read clock source select bit. */
110 i = readl(A11S_CLK_SEL_ADDR) & 1;
111
112 /* Jump into table and set every other entry. */
113 for(; i < ARRAY_SIZE(clk_cntl_reg_val); i += 2) {
114 writel(clk_cntl_reg_val[i], A11S_CLK_CNTL_ADDR);
115 /* Would need a dmb() here but the whole address space is
116 * strongly ordered, so it should be fine.
117 */
118 writel(clk_sel_reg_val[i], A11S_CLK_SEL_ADDR);
Chandan Uddaraju852cd2c2009-12-17 14:28:28 -0800119#if (!ENABLE_NANDWRITE)
Chandan Uddarajufcc15f52009-11-17 21:02:46 -0800120 thread_sleep(1);
Chandan Uddaraju852cd2c2009-12-17 14:28:28 -0800121#else
122 mdelay(1);
123#endif
Chandan Uddarajufcc15f52009-11-17 21:02:46 -0800124 }
Chandan Uddarajufcc15f52009-11-17 21:02:46 -0800125}