blob: 42659f9f11bb2690ea67262b9b09d5e53aeb3f6b [file] [log] [blame]
Tianyi Gou7395a7e2012-10-19 14:12:21 -07001/*
Patrick Daly985c14b2012-12-03 17:12:37 -08002 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Tianyi Gou7395a7e2012-10-19 14:12:21 -07003 *
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 Gou7395a7e2012-10-19 14:12:21 -070018#include <linux/io.h>
Patrick Dalyaf8808e2013-03-20 12:57:00 -070019#include <linux/clk.h>
Tianyi Gou7395a7e2012-10-19 14:12:21 -070020#include <linux/errno.h>
Tianyi Gou7395a7e2012-10-19 14:12:21 -070021#include <linux/platform_device.h>
Patrick Daly985c14b2012-12-03 17:12:37 -080022#include <linux/regulator/consumer.h>
Tianyi Gou7395a7e2012-10-19 14:12:21 -070023
Tianyi Gou7395a7e2012-10-19 14:12:21 -070024#include <mach/msm_bus.h>
25#include <mach/msm_bus_board.h>
Tianyi Gou7395a7e2012-10-19 14:12:21 -070026#include <mach/clk-provider.h>
27#include <mach/rpm-regulator-smd.h>
28
Patrick Daly985c14b2012-12-03 17:12:37 -080029#include "acpuclock-cortex.h"
Tianyi Gou7395a7e2012-10-19 14:12:21 -070030
Tianyi Gou7395a7e2012-10-19 14:12:21 -070031#define RCG_CONFIG_PGM_DATA_BIT BIT(11)
32#define RCG_CONFIG_PGM_ENA_BIT BIT(10)
Tianyi Gou7395a7e2012-10-19 14:12:21 -070033#define GPLL0_TO_A5_ALWAYS_ENABLE BIT(18)
34
Tianyi Gou7395a7e2012-10-19 14:12:21 -070035static 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
46static 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 Gou7395a7e2012-10-19 14:12:21 -070053/* TODO:
54 * 1) Update MX voltage when they are avaiable
55 * 2) Update bus bandwidth
56 */
57static 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 Daly985c14b2012-12-03 17:12:37 -080066static 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 Dalyaf8808e2013-03-20 12:57:00 -070084 .power_collapse_khz = 19200,
85 .wait_for_irq_khz = 19200,
Tianyi Gou7395a7e2012-10-19 14:12:21 -070086};
87
88static int __init acpuclk_9625_probe(struct platform_device *pdev)
89{
Tianyi Gou7395a7e2012-10-19 14:12:21 -070090 struct resource *res;
Patrick Dalyaf8808e2013-03-20 12:57:00 -070091 u32 regval, i;
Tianyi Gou7395a7e2012-10-19 14:12:21 -070092
Tianyi Gou7395a7e2012-10-19 14:12:21 -070093 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rcg_base");
94 if (!res)
95 return -EINVAL;
96
Patrick Dalyaf8808e2013-03-20 12:57:00 -070097 drv_data.apcs_rcg_config = devm_ioremap(&pdev->dev, res->start,
98 resource_size(res));
Tianyi Gou7395a7e2012-10-19 14:12:21 -070099 if (!drv_data.apcs_rcg_config)
100 return -ENOMEM;
101
Patrick Daly985c14b2012-12-03 17:12:37 -0800102 drv_data.apcs_rcg_cmd = drv_data.apcs_rcg_config;
103
Tianyi Gou7395a7e2012-10-19 14:12:21 -0700104 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 Daly0962ada2013-03-13 16:37:40 -0700112 drv_data.vdd_cpu = devm_regulator_get(&pdev->dev, "a5_cpu");
Tianyi Gou7395a7e2012-10-19 14:12:21 -0700113 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 Daly0962ada2013-03-13 16:37:40 -0700118 drv_data.vdd_mem = devm_regulator_get(&pdev->dev, "a5_mem");
Tianyi Gou7395a7e2012-10-19 14:12:21 -0700119 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 Dalyaf8808e2013-03-20 12:57:00 -0700124 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 Gou7395a7e2012-10-19 14:12:21 -0700136 /* 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 Daly985c14b2012-12-03 17:12:37 -0800141 return acpuclk_cortex_init(pdev, &drv_data);
Tianyi Gou7395a7e2012-10-19 14:12:21 -0700142}
143
144static struct of_device_id acpuclk_9625_match_table[] = {
145 {.compatible = "qcom,acpuclk-9625"},
146 {}
147};
148
149static 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
157static int __init acpuclk_9625_init(void)
158{
159 return platform_driver_probe(&acpuclk_9625_driver, acpuclk_9625_probe);
160}
161device_initcall(acpuclk_9625_init);