Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 1 | /* |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 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> |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 18 | #include <linux/io.h> |
Patrick Daly | af8808e | 2013-03-20 12:57:00 -0700 | [diff] [blame^] | 19 | #include <linux/clk.h> |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 20 | #include <linux/errno.h> |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 22 | #include <linux/regulator/consumer.h> |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 23 | |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 24 | #include <mach/msm_bus.h> |
| 25 | #include <mach/msm_bus_board.h> |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 26 | #include <mach/clk-provider.h> |
| 27 | #include <mach/rpm-regulator-smd.h> |
| 28 | |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 29 | #include "acpuclock-cortex.h" |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 30 | |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 31 | #define RCG_CONFIG_PGM_DATA_BIT BIT(11) |
| 32 | #define RCG_CONFIG_PGM_ENA_BIT BIT(10) |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 33 | #define GPLL0_TO_A5_ALWAYS_ENABLE BIT(18) |
| 34 | |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 35 | static struct msm_bus_paths bw_level_tbl[] = { |
| 36 | [0] = BW_MBPS(152), /* At least 19 MHz on bus. */ |
| 37 | [1] = BW_MBPS(264), /* At least 33 MHz on bus. */ |
| 38 | [2] = BW_MBPS(528), /* At least 66 MHz on bus. */ |
| 39 | [3] = BW_MBPS(664), /* At least 83 MHz on bus. */ |
| 40 | [4] = BW_MBPS(1064), /* At least 133 MHz on bus. */ |
| 41 | [5] = BW_MBPS(1328), /* At least 166 MHz on bus. */ |
| 42 | [6] = BW_MBPS(2128), /* At least 266 MHz on bus. */ |
| 43 | [7] = BW_MBPS(2664), /* At least 333 MHz on bus. */ |
| 44 | }; |
| 45 | |
| 46 | static struct msm_bus_scale_pdata bus_client_pdata = { |
| 47 | .usecase = bw_level_tbl, |
| 48 | .num_usecases = ARRAY_SIZE(bw_level_tbl), |
| 49 | .active_only = 1, |
| 50 | .name = "acpuclock", |
| 51 | }; |
| 52 | |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 53 | /* TODO: |
| 54 | * 1) Update MX voltage when they are avaiable |
| 55 | * 2) Update bus bandwidth |
| 56 | */ |
| 57 | static struct clkctl_acpu_speed acpu_freq_tbl[] = { |
| 58 | { 0, 19200, CXO, 0, 0, LVL_LOW, 950000, 0 }, |
| 59 | { 1, 300000, PLL0, 1, 2, LVL_LOW, 950000, 4 }, |
| 60 | { 1, 600000, PLL0, 1, 0, LVL_NOM, 950000, 4 }, |
| 61 | { 1, 748800, ACPUPLL, 5, 0, LVL_HIGH, 1050000, 7 }, |
| 62 | { 1, 998400, ACPUPLL, 5, 0, LVL_HIGH, 1050000, 7 }, |
| 63 | { 0 } |
| 64 | }; |
| 65 | |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 66 | static struct acpuclk_drv_data drv_data = { |
| 67 | .freq_tbl = acpu_freq_tbl, |
| 68 | .current_speed = &(struct clkctl_acpu_speed){ 0 }, |
| 69 | .bus_scale = &bus_client_pdata, |
| 70 | .vdd_max_cpu = LVL_HIGH, |
| 71 | .vdd_max_mem = 1050000, |
| 72 | .src_clocks = { |
| 73 | [PLL0].name = "pll0", |
| 74 | [ACPUPLL].name = "pll14", |
| 75 | }, |
| 76 | .reg_data = { |
| 77 | .cfg_src_mask = BM(2, 0), |
| 78 | .cfg_src_shift = 0, |
| 79 | .cfg_div_mask = BM(7, 3), |
| 80 | .cfg_div_shift = 3, |
| 81 | .update_mask = RCG_CONFIG_PGM_DATA_BIT | RCG_CONFIG_PGM_ENA_BIT, |
| 82 | .poll_mask = RCG_CONFIG_PGM_DATA_BIT, |
| 83 | }, |
Patrick Daly | af8808e | 2013-03-20 12:57:00 -0700 | [diff] [blame^] | 84 | .power_collapse_khz = 19200, |
| 85 | .wait_for_irq_khz = 19200, |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | static int __init acpuclk_9625_probe(struct platform_device *pdev) |
| 89 | { |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 90 | struct resource *res; |
Patrick Daly | af8808e | 2013-03-20 12:57:00 -0700 | [diff] [blame^] | 91 | u32 regval, i; |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 92 | |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 93 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rcg_base"); |
| 94 | if (!res) |
| 95 | return -EINVAL; |
| 96 | |
Patrick Daly | af8808e | 2013-03-20 12:57:00 -0700 | [diff] [blame^] | 97 | drv_data.apcs_rcg_config = devm_ioremap(&pdev->dev, res->start, |
| 98 | resource_size(res)); |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 99 | if (!drv_data.apcs_rcg_config) |
| 100 | return -ENOMEM; |
| 101 | |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 102 | drv_data.apcs_rcg_cmd = drv_data.apcs_rcg_config; |
| 103 | |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 104 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pwr_base"); |
| 105 | if (!res) |
| 106 | return -EINVAL; |
| 107 | |
| 108 | drv_data.apcs_cpu_pwr_ctl = ioremap(res->start, resource_size(res)); |
| 109 | if (!drv_data.apcs_cpu_pwr_ctl) |
| 110 | return -ENOMEM; |
| 111 | |
Patrick Daly | 0962ada | 2013-03-13 16:37:40 -0700 | [diff] [blame] | 112 | drv_data.vdd_cpu = devm_regulator_get(&pdev->dev, "a5_cpu"); |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 113 | if (IS_ERR(drv_data.vdd_cpu)) { |
| 114 | dev_err(&pdev->dev, "regulator for %s get failed\n", "a5_cpu"); |
| 115 | return PTR_ERR(drv_data.vdd_cpu); |
| 116 | } |
| 117 | |
Patrick Daly | 0962ada | 2013-03-13 16:37:40 -0700 | [diff] [blame] | 118 | drv_data.vdd_mem = devm_regulator_get(&pdev->dev, "a5_mem"); |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 119 | if (IS_ERR(drv_data.vdd_mem)) { |
| 120 | dev_err(&pdev->dev, "regulator for %s get failed\n", "a5_mem"); |
| 121 | return PTR_ERR(drv_data.vdd_mem); |
| 122 | } |
| 123 | |
Patrick Daly | af8808e | 2013-03-20 12:57:00 -0700 | [diff] [blame^] | 124 | for (i = 0; i < NUM_SRC; i++) { |
| 125 | if (!drv_data.src_clocks[i].name) |
| 126 | continue; |
| 127 | drv_data.src_clocks[i].clk = |
| 128 | devm_clk_get(&pdev->dev, drv_data.src_clocks[i].name); |
| 129 | if (IS_ERR(drv_data.src_clocks[i].clk)) { |
| 130 | dev_err(&pdev->dev, "Unable to get clock %s\n", |
| 131 | drv_data.src_clocks[i].name); |
| 132 | return -EPROBE_DEFER; |
| 133 | } |
| 134 | } |
| 135 | |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 136 | /* Disable hardware gating of gpll0 to A5SS */ |
| 137 | regval = readl_relaxed(drv_data.apcs_cpu_pwr_ctl); |
| 138 | regval |= GPLL0_TO_A5_ALWAYS_ENABLE; |
| 139 | writel_relaxed(regval, drv_data.apcs_cpu_pwr_ctl); |
| 140 | |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 141 | return acpuclk_cortex_init(pdev, &drv_data); |
Tianyi Gou | 7395a7e | 2012-10-19 14:12:21 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static struct of_device_id acpuclk_9625_match_table[] = { |
| 145 | {.compatible = "qcom,acpuclk-9625"}, |
| 146 | {} |
| 147 | }; |
| 148 | |
| 149 | static struct platform_driver acpuclk_9625_driver = { |
| 150 | .driver = { |
| 151 | .name = "acpuclk-9625", |
| 152 | .of_match_table = acpuclk_9625_match_table, |
| 153 | .owner = THIS_MODULE, |
| 154 | }, |
| 155 | }; |
| 156 | |
| 157 | static int __init acpuclk_9625_init(void) |
| 158 | { |
| 159 | return platform_driver_probe(&acpuclk_9625_driver, acpuclk_9625_probe); |
| 160 | } |
| 161 | device_initcall(acpuclk_9625_init); |