blob: f2e7602f99fc8a348bdd4f36f9e13cd73dd6c700 [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,
Patrick Daly985c14b2012-12-03 17:12:37 -080068 .bus_scale = &bus_client_pdata,
69 .vdd_max_cpu = LVL_HIGH,
70 .vdd_max_mem = 1050000,
71 .src_clocks = {
72 [PLL0].name = "pll0",
73 [ACPUPLL].name = "pll14",
74 },
75 .reg_data = {
76 .cfg_src_mask = BM(2, 0),
77 .cfg_src_shift = 0,
78 .cfg_div_mask = BM(7, 3),
79 .cfg_div_shift = 3,
80 .update_mask = RCG_CONFIG_PGM_DATA_BIT | RCG_CONFIG_PGM_ENA_BIT,
81 .poll_mask = RCG_CONFIG_PGM_DATA_BIT,
82 },
Tianyi Gou0ff7ccc2013-06-11 20:17:36 -070083 .power_collapse_khz = 300000,
84 .wait_for_irq_khz = 300000,
Tianyi Gou7395a7e2012-10-19 14:12:21 -070085};
86
87static int __init acpuclk_9625_probe(struct platform_device *pdev)
88{
Tianyi Gou7395a7e2012-10-19 14:12:21 -070089 struct resource *res;
Patrick Dalyaf8808e2013-03-20 12:57:00 -070090 u32 regval, i;
Tianyi Gou7395a7e2012-10-19 14:12:21 -070091
Tianyi Gou7395a7e2012-10-19 14:12:21 -070092 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rcg_base");
93 if (!res)
94 return -EINVAL;
95
Patrick Dalyaf8808e2013-03-20 12:57:00 -070096 drv_data.apcs_rcg_config = devm_ioremap(&pdev->dev, res->start,
97 resource_size(res));
Tianyi Gou7395a7e2012-10-19 14:12:21 -070098 if (!drv_data.apcs_rcg_config)
99 return -ENOMEM;
100
Patrick Daly985c14b2012-12-03 17:12:37 -0800101 drv_data.apcs_rcg_cmd = drv_data.apcs_rcg_config;
102
Tianyi Gou7395a7e2012-10-19 14:12:21 -0700103 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pwr_base");
104 if (!res)
105 return -EINVAL;
106
107 drv_data.apcs_cpu_pwr_ctl = ioremap(res->start, resource_size(res));
108 if (!drv_data.apcs_cpu_pwr_ctl)
109 return -ENOMEM;
110
Patrick Daly0962ada2013-03-13 16:37:40 -0700111 drv_data.vdd_cpu = devm_regulator_get(&pdev->dev, "a5_cpu");
Tianyi Gou7395a7e2012-10-19 14:12:21 -0700112 if (IS_ERR(drv_data.vdd_cpu)) {
113 dev_err(&pdev->dev, "regulator for %s get failed\n", "a5_cpu");
114 return PTR_ERR(drv_data.vdd_cpu);
115 }
116
Patrick Daly0962ada2013-03-13 16:37:40 -0700117 drv_data.vdd_mem = devm_regulator_get(&pdev->dev, "a5_mem");
Tianyi Gou7395a7e2012-10-19 14:12:21 -0700118 if (IS_ERR(drv_data.vdd_mem)) {
119 dev_err(&pdev->dev, "regulator for %s get failed\n", "a5_mem");
120 return PTR_ERR(drv_data.vdd_mem);
121 }
122
Patrick Dalyaf8808e2013-03-20 12:57:00 -0700123 for (i = 0; i < NUM_SRC; i++) {
124 if (!drv_data.src_clocks[i].name)
125 continue;
126 drv_data.src_clocks[i].clk =
127 devm_clk_get(&pdev->dev, drv_data.src_clocks[i].name);
128 if (IS_ERR(drv_data.src_clocks[i].clk)) {
129 dev_err(&pdev->dev, "Unable to get clock %s\n",
130 drv_data.src_clocks[i].name);
131 return -EPROBE_DEFER;
132 }
133 }
134
Tianyi Gou7395a7e2012-10-19 14:12:21 -0700135 /* Disable hardware gating of gpll0 to A5SS */
136 regval = readl_relaxed(drv_data.apcs_cpu_pwr_ctl);
137 regval |= GPLL0_TO_A5_ALWAYS_ENABLE;
138 writel_relaxed(regval, drv_data.apcs_cpu_pwr_ctl);
139
Tianyi Gou0ff7ccc2013-06-11 20:17:36 -0700140 /* Enable the always on source */
141 clk_prepare_enable(drv_data.src_clocks[PLL0].clk);
142
Patrick Daly985c14b2012-12-03 17:12:37 -0800143 return acpuclk_cortex_init(pdev, &drv_data);
Tianyi Gou7395a7e2012-10-19 14:12:21 -0700144}
145
146static struct of_device_id acpuclk_9625_match_table[] = {
147 {.compatible = "qcom,acpuclk-9625"},
148 {}
149};
150
151static struct platform_driver acpuclk_9625_driver = {
152 .driver = {
153 .name = "acpuclk-9625",
154 .of_match_table = acpuclk_9625_match_table,
155 .owner = THIS_MODULE,
156 },
157};
158
159static int __init acpuclk_9625_init(void)
160{
161 return platform_driver_probe(&acpuclk_9625_driver, acpuclk_9625_probe);
162}
163device_initcall(acpuclk_9625_init);