Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 1 | /* |
| 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 Daly | af8808e | 2013-03-20 12:57:00 -0700 | [diff] [blame] | 20 | #include <linux/clk.h> |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/regulator/consumer.h> |
Patrick Daly | f9451d2 | 2013-03-20 14:20:12 -0700 | [diff] [blame] | 23 | #include <linux/regulator/cpr-regulator.h> |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 24 | |
| 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 Mulukutla | 8f30773 | 2013-04-15 18:19:27 -0700 | [diff] [blame] | 29 | #include <mach/socinfo.h> |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 30 | |
| 31 | #include "acpuclock-cortex.h" |
| 32 | |
| 33 | #define RCG_CONFIG_UPDATE_BIT BIT(0) |
| 34 | |
Vikram Mulukutla | 8f30773 | 2013-04-15 18:19:27 -0700 | [diff] [blame] | 35 | static struct msm_bus_paths bw_level_tbl_8226[] = { |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 36 | [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 Mulukutla | 8f30773 | 2013-04-15 18:19:27 -0700 | [diff] [blame] | 46 | static 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. */ |
Vikram Mulukutla | 3df2868 | 2013-09-18 19:29:35 -0700 | [diff] [blame] | 52 | [5] = BW_MBPS(2664), /* At least 333 MHz on bus. */ |
Vikram Mulukutla | 8f30773 | 2013-04-15 18:19:27 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 55 | static struct msm_bus_scale_pdata bus_client_pdata = { |
Vikram Mulukutla | 8f30773 | 2013-04-15 18:19:27 -0700 | [diff] [blame] | 56 | .usecase = bw_level_tbl_8226, |
| 57 | .num_usecases = ARRAY_SIZE(bw_level_tbl_8226), |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 58 | .active_only = 1, |
| 59 | .name = "acpuclock", |
| 60 | }; |
| 61 | |
Patrick Daly | 66e32aa | 2013-05-30 15:11:52 -0700 | [diff] [blame] | 62 | static struct clkctl_acpu_speed acpu_freq_tbl_8226_1p1[] = { |
Patrick Daly | 18748a7 | 2013-04-24 18:59:22 -0700 | [diff] [blame] | 63 | { 1, 300000, PLL0, 4, 2, CPR_CORNER_SVS, 0, 4 }, |
Patrick Daly | 8380603 | 2013-03-25 15:18:24 -0700 | [diff] [blame] | 64 | { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_SVS, 0, 4 }, |
Patrick Daly | 18748a7 | 2013-04-24 18:59:22 -0700 | [diff] [blame] | 65 | { 1, 600000, PLL0, 4, 0, CPR_CORNER_NORMAL, 0, 6 }, |
Patrick Daly | 87c62ed | 2013-09-24 19:35:29 -0700 | [diff] [blame] | 66 | { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_NORMAL, 0, 6 }, |
Patrick Daly | f363c25 | 2013-03-21 12:08:37 -0700 | [diff] [blame] | 67 | { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 }, |
| 68 | { 1, 1094400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 }, |
Patrick Daly | 18748a7 | 2013-04-24 18:59:22 -0700 | [diff] [blame] | 69 | { 0, 1190400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 }, |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 70 | { 0 } |
| 71 | }; |
| 72 | |
Patrick Daly | 66e32aa | 2013-05-30 15:11:52 -0700 | [diff] [blame] | 73 | static 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 }, |
Patrick Daly | 87c62ed | 2013-09-24 19:35:29 -0700 | [diff] [blame] | 77 | { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_NORMAL, 0, 6 }, |
Patrick Daly | 66e32aa | 2013-05-30 15:11:52 -0700 | [diff] [blame] | 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 | |
| 84 | static 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 }, |
Patrick Daly | 87c62ed | 2013-09-24 19:35:29 -0700 | [diff] [blame] | 88 | { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_NORMAL, 0, 6 }, |
Patrick Daly | 66e32aa | 2013-05-30 15:11:52 -0700 | [diff] [blame] | 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 | |
Patrick Daly | 5a66c08 | 2013-08-02 10:58:56 -0700 | [diff] [blame] | 98 | static struct clkctl_acpu_speed acpu_freq_tbl_8226_1p6[] = { |
| 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 }, |
Patrick Daly | 87c62ed | 2013-09-24 19:35:29 -0700 | [diff] [blame] | 102 | { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_NORMAL, 0, 6 }, |
Patrick Daly | 5a66c08 | 2013-08-02 10:58:56 -0700 | [diff] [blame] | 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 }, |
| 109 | { 1, 1497600, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 }, |
| 110 | { 1, 1593600, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 7 }, |
Patrick Daly | 66e32aa | 2013-05-30 15:11:52 -0700 | [diff] [blame] | 111 | { 0 } |
| 112 | }; |
| 113 | |
Vikram Mulukutla | 8f30773 | 2013-04-15 18:19:27 -0700 | [diff] [blame] | 114 | static struct clkctl_acpu_speed acpu_freq_tbl_8610[] = { |
Patrick Daly | 18748a7 | 2013-04-24 18:59:22 -0700 | [diff] [blame] | 115 | { 1, 300000, PLL0, 4, 2, CPR_CORNER_SVS, 0, 3 }, |
Patrick Daly | 8380603 | 2013-03-25 15:18:24 -0700 | [diff] [blame] | 116 | { 1, 384000, ACPUPLL, 5, 2, CPR_CORNER_SVS, 0, 3 }, |
Patrick Daly | 18748a7 | 2013-04-24 18:59:22 -0700 | [diff] [blame] | 117 | { 1, 600000, PLL0, 4, 0, CPR_CORNER_NORMAL, 0, 4 }, |
| 118 | { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_NORMAL, 0, 4 }, |
Vikram Mulukutla | 56a3235 | 2013-04-30 14:53:53 -0700 | [diff] [blame] | 119 | { 1, 998400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 5 }, |
| 120 | { 1, 1190400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 0, 5 }, |
Vikram Mulukutla | 8f30773 | 2013-04-15 18:19:27 -0700 | [diff] [blame] | 121 | { 0 } |
| 122 | }; |
| 123 | |
Patrick Daly | 66e32aa | 2013-05-30 15:11:52 -0700 | [diff] [blame] | 124 | static struct clkctl_acpu_speed *pvs_tables_8226[NUM_SPEED_BIN] = { |
| 125 | [0] = acpu_freq_tbl_8226_1p2, |
| 126 | [6] = acpu_freq_tbl_8226_1p2, |
| 127 | [2] = acpu_freq_tbl_8226_1p4, |
| 128 | [5] = acpu_freq_tbl_8226_1p4, |
Patrick Daly | 94dedff | 2013-09-26 12:59:18 -0700 | [diff] [blame] | 129 | [4] = acpu_freq_tbl_8226_1p4, |
| 130 | [7] = acpu_freq_tbl_8226_1p4, |
Patrick Daly | 5a66c08 | 2013-08-02 10:58:56 -0700 | [diff] [blame] | 131 | [1] = acpu_freq_tbl_8226_1p6, |
Patrick Daly | 66e32aa | 2013-05-30 15:11:52 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 134 | static struct acpuclk_drv_data drv_data = { |
Patrick Daly | 66e32aa | 2013-05-30 15:11:52 -0700 | [diff] [blame] | 135 | .freq_tbl = acpu_freq_tbl_8226_1p1, |
| 136 | .pvs_tables = pvs_tables_8226, |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 137 | .bus_scale = &bus_client_pdata, |
Patrick Daly | f9451d2 | 2013-03-20 14:20:12 -0700 | [diff] [blame] | 138 | .vdd_max_cpu = CPR_CORNER_TURBO, |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 139 | .src_clocks = { |
| 140 | [PLL0].name = "gpll0", |
| 141 | [ACPUPLL].name = "a7sspll", |
| 142 | }, |
| 143 | .reg_data = { |
| 144 | .cfg_src_mask = BM(10, 8), |
| 145 | .cfg_src_shift = 8, |
| 146 | .cfg_div_mask = BM(4, 0), |
| 147 | .cfg_div_shift = 0, |
| 148 | .update_mask = RCG_CONFIG_UPDATE_BIT, |
| 149 | .poll_mask = RCG_CONFIG_UPDATE_BIT, |
| 150 | }, |
Patrick Daly | af8808e | 2013-03-20 12:57:00 -0700 | [diff] [blame] | 151 | .power_collapse_khz = 300000, |
| 152 | .wait_for_irq_khz = 300000, |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | static int __init acpuclk_a7_probe(struct platform_device *pdev) |
| 156 | { |
| 157 | struct resource *res; |
Patrick Daly | af8808e | 2013-03-20 12:57:00 -0700 | [diff] [blame] | 158 | u32 i; |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 159 | |
| 160 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rcg_base"); |
| 161 | if (!res) |
| 162 | return -EINVAL; |
| 163 | |
Patrick Daly | af8808e | 2013-03-20 12:57:00 -0700 | [diff] [blame] | 164 | drv_data.apcs_rcg_cmd = devm_ioremap(&pdev->dev, res->start, |
| 165 | resource_size(res)); |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 166 | if (!drv_data.apcs_rcg_cmd) |
| 167 | return -ENOMEM; |
| 168 | |
| 169 | drv_data.apcs_rcg_config = drv_data.apcs_rcg_cmd + 4; |
| 170 | |
Patrick Daly | 66e32aa | 2013-05-30 15:11:52 -0700 | [diff] [blame] | 171 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pte_efuse"); |
| 172 | if (res) { |
| 173 | drv_data.pte_efuse_base = devm_ioremap(&pdev->dev, res->start, |
| 174 | resource_size(res)); |
| 175 | if (!drv_data.pte_efuse_base) |
| 176 | return -ENOMEM; |
| 177 | } |
| 178 | |
Patrick Daly | 0962ada | 2013-03-13 16:37:40 -0700 | [diff] [blame] | 179 | drv_data.vdd_cpu = devm_regulator_get(&pdev->dev, "a7_cpu"); |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 180 | if (IS_ERR(drv_data.vdd_cpu)) { |
| 181 | dev_err(&pdev->dev, "regulator for %s get failed\n", "a7_cpu"); |
| 182 | return PTR_ERR(drv_data.vdd_cpu); |
| 183 | } |
| 184 | |
Patrick Daly | af8808e | 2013-03-20 12:57:00 -0700 | [diff] [blame] | 185 | for (i = 0; i < NUM_SRC; i++) { |
| 186 | if (!drv_data.src_clocks[i].name) |
| 187 | continue; |
| 188 | drv_data.src_clocks[i].clk = |
| 189 | devm_clk_get(&pdev->dev, drv_data.src_clocks[i].name); |
| 190 | if (IS_ERR(drv_data.src_clocks[i].clk)) { |
| 191 | dev_err(&pdev->dev, "Unable to get clock %s\n", |
| 192 | drv_data.src_clocks[i].name); |
| 193 | return -EPROBE_DEFER; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /* Enable the always on source */ |
| 198 | clk_prepare_enable(drv_data.src_clocks[PLL0].clk); |
| 199 | |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 200 | return acpuclk_cortex_init(pdev, &drv_data); |
| 201 | } |
| 202 | |
| 203 | static struct of_device_id acpuclk_a7_match_table[] = { |
| 204 | {.compatible = "qcom,acpuclk-a7"}, |
| 205 | {} |
| 206 | }; |
| 207 | |
| 208 | static struct platform_driver acpuclk_a7_driver = { |
| 209 | .driver = { |
| 210 | .name = "acpuclk-a7", |
| 211 | .of_match_table = acpuclk_a7_match_table, |
| 212 | .owner = THIS_MODULE, |
| 213 | }, |
| 214 | }; |
| 215 | |
Vikram Mulukutla | 8f30773 | 2013-04-15 18:19:27 -0700 | [diff] [blame] | 216 | void msm8610_acpu_init(void) |
| 217 | { |
| 218 | drv_data.bus_scale->usecase = bw_level_tbl_8610; |
| 219 | drv_data.bus_scale->num_usecases = ARRAY_SIZE(bw_level_tbl_8610); |
| 220 | drv_data.freq_tbl = acpu_freq_tbl_8610; |
| 221 | } |
| 222 | |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 223 | static int __init acpuclk_a7_init(void) |
| 224 | { |
Vikram Mulukutla | 8f30773 | 2013-04-15 18:19:27 -0700 | [diff] [blame] | 225 | if (cpu_is_msm8610()) |
| 226 | msm8610_acpu_init(); |
| 227 | |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 228 | return platform_driver_probe(&acpuclk_a7_driver, acpuclk_a7_probe); |
| 229 | } |
| 230 | device_initcall(acpuclk_a7_init); |