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> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/regulator/consumer.h> |
Patrick Daly | f9451d2 | 2013-03-20 14:20:12 -0700 | [diff] [blame] | 22 | #include <linux/regulator/cpr-regulator.h> |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 23 | |
| 24 | #include <mach/clk-provider.h> |
| 25 | #include <mach/msm_bus.h> |
| 26 | #include <mach/msm_bus_board.h> |
| 27 | #include <mach/rpm-regulator-smd.h> |
| 28 | |
| 29 | #include "acpuclock-cortex.h" |
| 30 | |
| 31 | #define RCG_CONFIG_UPDATE_BIT BIT(0) |
| 32 | |
| 33 | static struct msm_bus_paths bw_level_tbl[] = { |
| 34 | [0] = BW_MBPS(152), /* At least 19 MHz on bus. */ |
| 35 | [1] = BW_MBPS(300), /* At least 37.5 MHz on bus. */ |
| 36 | [2] = BW_MBPS(400), /* At least 50 MHz on bus. */ |
| 37 | [3] = BW_MBPS(800), /* At least 100 MHz on bus. */ |
| 38 | [4] = BW_MBPS(1600), /* At least 200 MHz on bus. */ |
| 39 | [5] = BW_MBPS(2128), /* At least 266 MHz on bus. */ |
| 40 | [6] = BW_MBPS(3200), /* At least 400 MHz on bus. */ |
| 41 | [7] = BW_MBPS(4264), /* At least 533 MHz on bus. */ |
| 42 | }; |
| 43 | |
| 44 | static struct msm_bus_scale_pdata bus_client_pdata = { |
| 45 | .usecase = bw_level_tbl, |
| 46 | .num_usecases = ARRAY_SIZE(bw_level_tbl), |
| 47 | .active_only = 1, |
| 48 | .name = "acpuclock", |
| 49 | }; |
| 50 | |
| 51 | /* TODO: |
| 52 | * 1) Update MX voltage when data is avaiable |
| 53 | * 2) Update bus bandwidth |
| 54 | * 3) Depending on Frodo version, may need minimum of LVL_NOM |
| 55 | */ |
| 56 | static struct clkctl_acpu_speed acpu_freq_tbl[] = { |
Patrick Daly | f9451d2 | 2013-03-20 14:20:12 -0700 | [diff] [blame] | 57 | { 0, 19200, CXO, 0, 0, CPR_CORNER_SVS, 1150000, 0 }, |
| 58 | { 1, 300000, PLL0, 4, 2, CPR_CORNER_SVS, 1150000, 4 }, |
| 59 | { 1, 384000, ACPUPLL, 5, 0, CPR_CORNER_SVS, 1150000, 4 }, |
| 60 | { 1, 600000, PLL0, 4, 0, CPR_CORNER_NORMAL, 1150000, 6 }, |
| 61 | { 1, 787200, ACPUPLL, 5, 0, CPR_CORNER_NORMAL, 1150000, 7 }, |
| 62 | { 0, 998400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 1150000, 7 }, |
| 63 | { 0, 1190400, ACPUPLL, 5, 0, CPR_CORNER_TURBO, 1150000, 7 }, |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 64 | { 0 } |
| 65 | }; |
| 66 | |
| 67 | static struct acpuclk_drv_data drv_data = { |
| 68 | .freq_tbl = acpu_freq_tbl, |
| 69 | .current_speed = &(struct clkctl_acpu_speed){ 0 }, |
| 70 | .bus_scale = &bus_client_pdata, |
Patrick Daly | f9451d2 | 2013-03-20 14:20:12 -0700 | [diff] [blame] | 71 | .vdd_max_cpu = CPR_CORNER_TURBO, |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 72 | .vdd_max_mem = 1150000, |
| 73 | .src_clocks = { |
| 74 | [PLL0].name = "gpll0", |
| 75 | [ACPUPLL].name = "a7sspll", |
| 76 | }, |
| 77 | .reg_data = { |
| 78 | .cfg_src_mask = BM(10, 8), |
| 79 | .cfg_src_shift = 8, |
| 80 | .cfg_div_mask = BM(4, 0), |
| 81 | .cfg_div_shift = 0, |
| 82 | .update_mask = RCG_CONFIG_UPDATE_BIT, |
| 83 | .poll_mask = RCG_CONFIG_UPDATE_BIT, |
| 84 | }, |
| 85 | }; |
| 86 | |
| 87 | static int __init acpuclk_a7_probe(struct platform_device *pdev) |
| 88 | { |
| 89 | struct resource *res; |
| 90 | |
| 91 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rcg_base"); |
| 92 | if (!res) |
| 93 | return -EINVAL; |
| 94 | |
| 95 | drv_data.apcs_rcg_cmd = ioremap(res->start, resource_size(res)); |
| 96 | if (!drv_data.apcs_rcg_cmd) |
| 97 | return -ENOMEM; |
| 98 | |
| 99 | drv_data.apcs_rcg_config = drv_data.apcs_rcg_cmd + 4; |
| 100 | |
Patrick Daly | 0962ada | 2013-03-13 16:37:40 -0700 | [diff] [blame] | 101 | drv_data.vdd_cpu = devm_regulator_get(&pdev->dev, "a7_cpu"); |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 102 | if (IS_ERR(drv_data.vdd_cpu)) { |
| 103 | dev_err(&pdev->dev, "regulator for %s get failed\n", "a7_cpu"); |
| 104 | return PTR_ERR(drv_data.vdd_cpu); |
| 105 | } |
| 106 | |
Patrick Daly | 0962ada | 2013-03-13 16:37:40 -0700 | [diff] [blame] | 107 | drv_data.vdd_mem = devm_regulator_get(&pdev->dev, "a7_mem"); |
Patrick Daly | 985c14b | 2012-12-03 17:12:37 -0800 | [diff] [blame] | 108 | if (IS_ERR(drv_data.vdd_mem)) { |
| 109 | dev_err(&pdev->dev, "regulator for %s get failed\n", "a7_mem"); |
| 110 | return PTR_ERR(drv_data.vdd_mem); |
| 111 | } |
| 112 | |
| 113 | return acpuclk_cortex_init(pdev, &drv_data); |
| 114 | } |
| 115 | |
| 116 | static struct of_device_id acpuclk_a7_match_table[] = { |
| 117 | {.compatible = "qcom,acpuclk-a7"}, |
| 118 | {} |
| 119 | }; |
| 120 | |
| 121 | static struct platform_driver acpuclk_a7_driver = { |
| 122 | .driver = { |
| 123 | .name = "acpuclk-a7", |
| 124 | .of_match_table = acpuclk_a7_match_table, |
| 125 | .owner = THIS_MODULE, |
| 126 | }, |
| 127 | }; |
| 128 | |
| 129 | static int __init acpuclk_a7_init(void) |
| 130 | { |
| 131 | return platform_driver_probe(&acpuclk_a7_driver, acpuclk_a7_probe); |
| 132 | } |
| 133 | device_initcall(acpuclk_a7_init); |