blob: 9ea00c167b29e129c3a2b7d37eff2ff7c585d981 [file] [log] [blame]
Patrick Daly985c14b2012-12-03 17:12:37 -08001/*
2 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#define pr_fmt(fmt) "%s: " fmt, __func__
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/errno.h>
19#include <linux/io.h>
Patrick Dalyaf8808e2013-03-20 12:57:00 -070020#include <linux/clk.h>
Patrick Daly985c14b2012-12-03 17:12:37 -080021#include <linux/platform_device.h>
22#include <linux/regulator/consumer.h>
Patrick Dalyf9451d22013-03-20 14:20:12 -070023#include <linux/regulator/cpr-regulator.h>
Patrick Daly985c14b2012-12-03 17:12:37 -080024
25#include <mach/clk-provider.h>
26#include <mach/msm_bus.h>
27#include <mach/msm_bus_board.h>
28#include <mach/rpm-regulator-smd.h>
Vikram Mulukutla8f307732013-04-15 18:19:27 -070029#include <mach/socinfo.h>
Patrick Daly985c14b2012-12-03 17:12:37 -080030
31#include "acpuclock-cortex.h"
32
33#define RCG_CONFIG_UPDATE_BIT BIT(0)
34
Vikram Mulukutla8f307732013-04-15 18:19:27 -070035static struct msm_bus_paths bw_level_tbl_8226[] = {
Patrick Daly985c14b2012-12-03 17:12:37 -080036 [0] = BW_MBPS(152), /* At least 19 MHz on bus. */
37 [1] = BW_MBPS(300), /* At least 37.5 MHz on bus. */
38 [2] = BW_MBPS(400), /* At least 50 MHz on bus. */
39 [3] = BW_MBPS(800), /* At least 100 MHz on bus. */
40 [4] = BW_MBPS(1600), /* At least 200 MHz on bus. */
41 [5] = BW_MBPS(2128), /* At least 266 MHz on bus. */
42 [6] = BW_MBPS(3200), /* At least 400 MHz on bus. */
43 [7] = BW_MBPS(4264), /* At least 533 MHz on bus. */
44};
45
Vikram Mulukutla8f307732013-04-15 18:19:27 -070046static struct msm_bus_paths bw_level_tbl_8610[] = {
47 [0] = BW_MBPS(152), /* At least 19 MHz on bus. */
48 [1] = BW_MBPS(300), /* At least 37.5 MHz on bus. */
49 [2] = BW_MBPS(400), /* At least 50 MHz on bus. */
50 [3] = BW_MBPS(800), /* At least 100 MHz on bus. */
51 [4] = BW_MBPS(1600), /* At least 200 MHz on bus. */
52 [5] = BW_MBPS(2128), /* At least 266 MHz on bus. */
53};
54
Patrick Daly985c14b2012-12-03 17:12:37 -080055static struct msm_bus_scale_pdata bus_client_pdata = {
Vikram Mulukutla8f307732013-04-15 18:19:27 -070056 .usecase = bw_level_tbl_8226,
57 .num_usecases = ARRAY_SIZE(bw_level_tbl_8226),
Patrick Daly985c14b2012-12-03 17:12:37 -080058 .active_only = 1,
59 .name = "acpuclock",
60};
61
Patrick Daly66e32aa2013-05-30 15:11:52 -070062static struct clkctl_acpu_speed acpu_freq_tbl_8226_1p1[] = {
Patrick Daly18748a72013-04-24 18:59:22 -070063 { 1, 300000, PLL0, 4, 2, CPR_CORNER_SVS, 0, 4 },
Patrick Daly83806032013-03-25 15:18:24 -070064 { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_SVS, 0, 4 },
Patrick Daly18748a72013-04-24 18:59:22 -070065 { 1, 600000, PLL0, 4, 0, CPR_CORNER_NORMAL, 0, 6 },
66 { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_NORMAL, 0, 7 },
Patrick Dalyf363c252013-03-21 12:08:37 -070067 { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
68 { 1, 1094400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
Patrick Daly18748a72013-04-24 18:59:22 -070069 { 0, 1190400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
Patrick Daly985c14b2012-12-03 17:12:37 -080070 { 0 }
71};
72
Patrick Daly66e32aa2013-05-30 15:11:52 -070073static struct clkctl_acpu_speed acpu_freq_tbl_8226_1p2[] = {
74 { 1, 300000, PLL0, 4, 2, CPR_CORNER_SVS, 0, 4 },
75 { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_SVS, 0, 4 },
76 { 1, 600000, PLL0, 4, 0, CPR_CORNER_NORMAL, 0, 6 },
77 { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_NORMAL, 0, 7 },
78 { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
79 { 1, 1094400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
80 { 1, 1190400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
81 { 0 }
82};
83
84static struct clkctl_acpu_speed acpu_freq_tbl_8226_1p4[] = {
85 { 1, 300000, PLL0, 4, 2, CPR_CORNER_SVS, 0, 4 },
86 { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_SVS, 0, 4 },
87 { 1, 600000, PLL0, 4, 0, CPR_CORNER_NORMAL, 0, 6 },
88 { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_NORMAL, 0, 7 },
89 { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
90 { 1, 1094400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
91 { 1, 1190400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
92 { 1, 1305600, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
93 { 1, 1344000, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
94 { 1, 1401600, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
95 { 0 }
96};
97
98static struct clkctl_acpu_speed acpu_freq_tbl_8226_1p5[] = {
99 { 1, 300000, PLL0, 4, 2, CPR_CORNER_SVS, 0, 4 },
100 { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_SVS, 0, 4 },
101 { 1, 600000, PLL0, 4, 0, CPR_CORNER_NORMAL, 0, 6 },
102 { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_NORMAL, 0, 7 },
103 { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
104 { 1, 1094400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
105 { 1, 1190400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
106 { 1, 1305600, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
107 { 1, 1344000, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
108 { 1, 1401600, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
Patrick Daly5a66c082013-08-02 10:58:56 -0700109 { 1, 1497600, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
110 { 0 }
111};
112
113static struct clkctl_acpu_speed acpu_freq_tbl_8226_1p6[] = {
114 { 1, 300000, PLL0, 4, 2, CPR_CORNER_SVS, 0, 4 },
115 { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_SVS, 0, 4 },
116 { 1, 600000, PLL0, 4, 0, CPR_CORNER_NORMAL, 0, 6 },
117 { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_NORMAL, 0, 7 },
118 { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
119 { 1, 1094400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
120 { 1, 1190400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
121 { 1, 1305600, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
122 { 1, 1344000, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
123 { 1, 1401600, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
124 { 1, 1497600, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
125 { 1, 1593600, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 },
Patrick Daly66e32aa2013-05-30 15:11:52 -0700126 { 0 }
127};
128
Vikram Mulukutla8f307732013-04-15 18:19:27 -0700129static struct clkctl_acpu_speed acpu_freq_tbl_8610[] = {
Patrick Daly18748a72013-04-24 18:59:22 -0700130 { 1, 300000, PLL0, 4, 2, CPR_CORNER_SVS, 0, 3 },
Patrick Daly83806032013-03-25 15:18:24 -0700131 { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_SVS, 0, 3 },
Patrick Daly18748a72013-04-24 18:59:22 -0700132 { 1, 600000, PLL0, 4, 0, CPR_CORNER_NORMAL, 0, 4 },
133 { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_NORMAL, 0, 4 },
Vikram Mulukutla56a32352013-04-30 14:53:53 -0700134 { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 5 },
135 { 1, 1190400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 5 },
Vikram Mulukutla8f307732013-04-15 18:19:27 -0700136 { 0 }
137};
138
Patrick Daly66e32aa2013-05-30 15:11:52 -0700139static struct clkctl_acpu_speed *pvs_tables_8226[NUM_SPEED_BIN] = {
140 [0] = acpu_freq_tbl_8226_1p2,
141 [6] = acpu_freq_tbl_8226_1p2,
142 [2] = acpu_freq_tbl_8226_1p4,
143 [5] = acpu_freq_tbl_8226_1p4,
Patrick Daly66e32aa2013-05-30 15:11:52 -0700144 [4] = acpu_freq_tbl_8226_1p5,
Patrick Daly5a66c082013-08-02 10:58:56 -0700145 [7] = acpu_freq_tbl_8226_1p5,
146 [1] = acpu_freq_tbl_8226_1p6,
Patrick Daly66e32aa2013-05-30 15:11:52 -0700147};
148
Patrick Daly985c14b2012-12-03 17:12:37 -0800149static struct acpuclk_drv_data drv_data = {
Patrick Daly66e32aa2013-05-30 15:11:52 -0700150 .freq_tbl = acpu_freq_tbl_8226_1p1,
151 .pvs_tables = pvs_tables_8226,
Patrick Daly985c14b2012-12-03 17:12:37 -0800152 .bus_scale = &bus_client_pdata,
Patrick Dalyf9451d22013-03-20 14:20:12 -0700153 .vdd_max_cpu = CPR_CORNER_TURBO,
Patrick Daly985c14b2012-12-03 17:12:37 -0800154 .src_clocks = {
155 [PLL0].name = "gpll0",
156 [ACPUPLL].name = "a7sspll",
157 },
158 .reg_data = {
159 .cfg_src_mask = BM(10, 8),
160 .cfg_src_shift = 8,
161 .cfg_div_mask = BM(4, 0),
162 .cfg_div_shift = 0,
163 .update_mask = RCG_CONFIG_UPDATE_BIT,
164 .poll_mask = RCG_CONFIG_UPDATE_BIT,
165 },
Patrick Dalyaf8808e2013-03-20 12:57:00 -0700166 .power_collapse_khz = 300000,
167 .wait_for_irq_khz = 300000,
Patrick Daly985c14b2012-12-03 17:12:37 -0800168};
169
170static int __init acpuclk_a7_probe(struct platform_device *pdev)
171{
172 struct resource *res;
Patrick Dalyaf8808e2013-03-20 12:57:00 -0700173 u32 i;
Patrick Daly985c14b2012-12-03 17:12:37 -0800174
175 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rcg_base");
176 if (!res)
177 return -EINVAL;
178
Patrick Dalyaf8808e2013-03-20 12:57:00 -0700179 drv_data.apcs_rcg_cmd = devm_ioremap(&pdev->dev, res->start,
180 resource_size(res));
Patrick Daly985c14b2012-12-03 17:12:37 -0800181 if (!drv_data.apcs_rcg_cmd)
182 return -ENOMEM;
183
184 drv_data.apcs_rcg_config = drv_data.apcs_rcg_cmd + 4;
185
Patrick Daly66e32aa2013-05-30 15:11:52 -0700186 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pte_efuse");
187 if (res) {
188 drv_data.pte_efuse_base = devm_ioremap(&pdev->dev, res->start,
189 resource_size(res));
190 if (!drv_data.pte_efuse_base)
191 return -ENOMEM;
192 }
193
Patrick Daly0962ada2013-03-13 16:37:40 -0700194 drv_data.vdd_cpu = devm_regulator_get(&pdev->dev, "a7_cpu");
Patrick Daly985c14b2012-12-03 17:12:37 -0800195 if (IS_ERR(drv_data.vdd_cpu)) {
196 dev_err(&pdev->dev, "regulator for %s get failed\n", "a7_cpu");
197 return PTR_ERR(drv_data.vdd_cpu);
198 }
199
Patrick Dalyaf8808e2013-03-20 12:57:00 -0700200 for (i = 0; i < NUM_SRC; i++) {
201 if (!drv_data.src_clocks[i].name)
202 continue;
203 drv_data.src_clocks[i].clk =
204 devm_clk_get(&pdev->dev, drv_data.src_clocks[i].name);
205 if (IS_ERR(drv_data.src_clocks[i].clk)) {
206 dev_err(&pdev->dev, "Unable to get clock %s\n",
207 drv_data.src_clocks[i].name);
208 return -EPROBE_DEFER;
209 }
210 }
211
212 /* Enable the always on source */
213 clk_prepare_enable(drv_data.src_clocks[PLL0].clk);
214
Patrick Daly985c14b2012-12-03 17:12:37 -0800215 return acpuclk_cortex_init(pdev, &drv_data);
216}
217
218static struct of_device_id acpuclk_a7_match_table[] = {
219 {.compatible = "qcom,acpuclk-a7"},
220 {}
221};
222
223static struct platform_driver acpuclk_a7_driver = {
224 .driver = {
225 .name = "acpuclk-a7",
226 .of_match_table = acpuclk_a7_match_table,
227 .owner = THIS_MODULE,
228 },
229};
230
Vikram Mulukutla8f307732013-04-15 18:19:27 -0700231void msm8610_acpu_init(void)
232{
233 drv_data.bus_scale->usecase = bw_level_tbl_8610;
234 drv_data.bus_scale->num_usecases = ARRAY_SIZE(bw_level_tbl_8610);
235 drv_data.freq_tbl = acpu_freq_tbl_8610;
236}
237
Patrick Daly985c14b2012-12-03 17:12:37 -0800238static int __init acpuclk_a7_init(void)
239{
Vikram Mulukutla8f307732013-04-15 18:19:27 -0700240 if (cpu_is_msm8610())
241 msm8610_acpu_init();
242
Patrick Daly985c14b2012-12-03 17:12:37 -0800243 return platform_driver_probe(&acpuclk_a7_driver, acpuclk_a7_probe);
244}
245device_initcall(acpuclk_a7_init);