aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-msm/clock-pcom.c
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@codeaurora.org>2013-06-17 13:43:19 -0400
committerDavid Brown <davidb@codeaurora.org>2013-06-24 16:08:05 -0400
commit8cc7f5338e729b79194e6c22e3c794faaef974b8 (patch)
treed9fad83dcb3e260ad862907a80431ad70d51883e /arch/arm/mach-msm/clock-pcom.c
parent421faca0b538d1ed5f2065cbbc6bbec38f49a54f (diff)
ARM: msm: Migrate to common clock framework
Move the existing clock code in mach-msm to the common clock framework. We lose our capability to set the rate of and enable a clock through debugfs. This is ok though because the debugfs features are mainly used for testing and development of new clock code. To maintain compatibility with the original MSM clock code we make a wrapper for clk_reset() that calls the struct msm_clk specific reset function. This is necessary for the usb and sdcc devices on MSM until a better suited API is made available. Cc: Saravana Kannan <skannan@codeaurora.org> Acked-by: Mike Turquette <mturquette@linaro.org> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: David Brown <davidb@codeaurora.org>
Diffstat (limited to 'arch/arm/mach-msm/clock-pcom.c')
-rw-r--r--arch/arm/mach-msm/clock-pcom.c118
1 files changed, 74 insertions, 44 deletions
diff --git a/arch/arm/mach-msm/clock-pcom.c b/arch/arm/mach-msm/clock-pcom.c
index 632173186a69..9a80449518e6 100644
--- a/arch/arm/mach-msm/clock-pcom.c
+++ b/arch/arm/mach-msm/clock-pcom.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 2007 Google, Inc. 2 * Copyright (C) 2007 Google, Inc.
3 * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved. 3 * Copyright (c) 2007-2012, The Linux Foundation. All rights reserved.
4 * 4 *
5 * This software is licensed under the terms of the GNU General Public 5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and 6 * License version 2, as published by the Free Software Foundation, and
@@ -13,9 +13,12 @@
13 * 13 *
14 */ 14 */
15 15
16#include <linux/kernel.h>
16#include <linux/err.h> 17#include <linux/err.h>
17#include <linux/platform_device.h> 18#include <linux/platform_device.h>
18#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/clk-provider.h>
21#include <linux/clkdev.h>
19 22
20#include <mach/clk.h> 23#include <mach/clk.h>
21 24
@@ -23,11 +26,20 @@
23#include "clock.h" 26#include "clock.h"
24#include "clock-pcom.h" 27#include "clock-pcom.h"
25 28
26/* 29struct clk_pcom {
27 * glue for the proc_comm interface 30 unsigned id;
28 */ 31 unsigned long flags;
29static int pc_clk_enable(unsigned id) 32 struct msm_clk msm_clk;
33};
34
35static inline struct clk_pcom *to_clk_pcom(struct clk_hw *hw)
30{ 36{
37 return container_of(to_msm_clk(hw), struct clk_pcom, msm_clk);
38}
39
40static int pc_clk_enable(struct clk_hw *hw)
41{
42 unsigned id = to_clk_pcom(hw)->id;
31 int rc = msm_proc_comm(PCOM_CLKCTL_RPC_ENABLE, &id, NULL); 43 int rc = msm_proc_comm(PCOM_CLKCTL_RPC_ENABLE, &id, NULL);
32 if (rc < 0) 44 if (rc < 0)
33 return rc; 45 return rc;
@@ -35,14 +47,16 @@ static int pc_clk_enable(unsigned id)
35 return (int)id < 0 ? -EINVAL : 0; 47 return (int)id < 0 ? -EINVAL : 0;
36} 48}
37 49
38static void pc_clk_disable(unsigned id) 50static void pc_clk_disable(struct clk_hw *hw)
39{ 51{
52 unsigned id = to_clk_pcom(hw)->id;
40 msm_proc_comm(PCOM_CLKCTL_RPC_DISABLE, &id, NULL); 53 msm_proc_comm(PCOM_CLKCTL_RPC_DISABLE, &id, NULL);
41} 54}
42 55
43int pc_clk_reset(unsigned id, enum clk_reset_action action) 56static int pc_clk_reset(struct clk_hw *hw, enum clk_reset_action action)
44{ 57{
45 int rc; 58 int rc;
59 unsigned id = to_clk_pcom(hw)->id;
46 60
47 if (action == CLK_RESET_ASSERT) 61 if (action == CLK_RESET_ASSERT)
48 rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_ASSERT, &id, NULL); 62 rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_ASSERT, &id, NULL);
@@ -55,83 +69,99 @@ int pc_clk_reset(unsigned id, enum clk_reset_action action)
55 return (int)id < 0 ? -EINVAL : 0; 69 return (int)id < 0 ? -EINVAL : 0;
56} 70}
57 71
58static int pc_clk_set_rate(unsigned id, unsigned rate) 72static int pc_clk_set_rate(struct clk_hw *hw, unsigned long new_rate,
73 unsigned long p_rate)
59{ 74{
60 /* The rate _might_ be rounded off to the nearest KHz value by the 75 struct clk_pcom *p = to_clk_pcom(hw);
76 unsigned id = p->id, rate = new_rate;
77 int rc;
78
79 /*
80 * The rate _might_ be rounded off to the nearest KHz value by the
61 * remote function. So a return value of 0 doesn't necessarily mean 81 * remote function. So a return value of 0 doesn't necessarily mean
62 * that the exact rate was set successfully. 82 * that the exact rate was set successfully.
63 */ 83 */
64 int rc = msm_proc_comm(PCOM_CLKCTL_RPC_SET_RATE, &id, &rate); 84 if (p->flags & CLKFLAG_MIN)
65 if (rc < 0) 85 rc = msm_proc_comm(PCOM_CLKCTL_RPC_MIN_RATE, &id, &rate);
66 return rc;
67 else
68 return (int)id < 0 ? -EINVAL : 0;
69}
70
71static int pc_clk_set_min_rate(unsigned id, unsigned rate)
72{
73 int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MIN_RATE, &id, &rate);
74 if (rc < 0)
75 return rc;
76 else 86 else
77 return (int)id < 0 ? -EINVAL : 0; 87 rc = msm_proc_comm(PCOM_CLKCTL_RPC_SET_RATE, &id, &rate);
78}
79
80static int pc_clk_set_max_rate(unsigned id, unsigned rate)
81{
82 int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MAX_RATE, &id, &rate);
83 if (rc < 0) 88 if (rc < 0)
84 return rc; 89 return rc;
85 else 90 else
86 return (int)id < 0 ? -EINVAL : 0; 91 return (int)id < 0 ? -EINVAL : 0;
87} 92}
88 93
89static unsigned pc_clk_get_rate(unsigned id) 94static unsigned long pc_clk_recalc_rate(struct clk_hw *hw, unsigned long p_rate)
90{ 95{
96 unsigned id = to_clk_pcom(hw)->id;
91 if (msm_proc_comm(PCOM_CLKCTL_RPC_RATE, &id, NULL)) 97 if (msm_proc_comm(PCOM_CLKCTL_RPC_RATE, &id, NULL))
92 return 0; 98 return 0;
93 else 99 else
94 return id; 100 return id;
95} 101}
96 102
97static unsigned pc_clk_is_enabled(unsigned id) 103static int pc_clk_is_enabled(struct clk_hw *hw)
98{ 104{
105 unsigned id = to_clk_pcom(hw)->id;
99 if (msm_proc_comm(PCOM_CLKCTL_RPC_ENABLED, &id, NULL)) 106 if (msm_proc_comm(PCOM_CLKCTL_RPC_ENABLED, &id, NULL))
100 return 0; 107 return 0;
101 else 108 else
102 return id; 109 return id;
103} 110}
104 111
105static long pc_clk_round_rate(unsigned id, unsigned rate) 112static long pc_clk_round_rate(struct clk_hw *hw, unsigned long rate,
113 unsigned long *p_rate)
106{ 114{
107
108 /* Not really supported; pc_clk_set_rate() does rounding on it's own. */ 115 /* Not really supported; pc_clk_set_rate() does rounding on it's own. */
109 return rate; 116 return rate;
110} 117}
111 118
112static bool pc_clk_is_local(unsigned id) 119static struct clk_ops clk_ops_pcom = {
113{
114 return false;
115}
116
117struct clk_ops clk_ops_pcom = {
118 .enable = pc_clk_enable, 120 .enable = pc_clk_enable,
119 .disable = pc_clk_disable, 121 .disable = pc_clk_disable,
120 .auto_off = pc_clk_disable,
121 .reset = pc_clk_reset,
122 .set_rate = pc_clk_set_rate, 122 .set_rate = pc_clk_set_rate,
123 .set_min_rate = pc_clk_set_min_rate, 123 .recalc_rate = pc_clk_recalc_rate,
124 .set_max_rate = pc_clk_set_max_rate,
125 .get_rate = pc_clk_get_rate,
126 .is_enabled = pc_clk_is_enabled, 124 .is_enabled = pc_clk_is_enabled,
127 .round_rate = pc_clk_round_rate, 125 .round_rate = pc_clk_round_rate,
128 .is_local = pc_clk_is_local,
129}; 126};
130 127
131static int msm_clock_pcom_probe(struct platform_device *pdev) 128static int msm_clock_pcom_probe(struct platform_device *pdev)
132{ 129{
133 const struct pcom_clk_pdata *pdata = pdev->dev.platform_data; 130 const struct pcom_clk_pdata *pdata = pdev->dev.platform_data;
134 msm_clock_init(pdata->lookup, pdata->num_lookups); 131 int i, ret;
132
133 for (i = 0; i < pdata->num_lookups; i++) {
134 const struct clk_pcom_desc *desc = &pdata->lookup[i];
135 struct clk *c;
136 struct clk_pcom *p;
137 struct clk_hw *hw;
138 struct clk_init_data init;
139
140 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
141 if (!p)
142 return -ENOMEM;
143
144 p->id = desc->id;
145 p->flags = desc->flags;
146 p->msm_clk.reset = pc_clk_reset;
147
148 hw = &p->msm_clk.hw;
149 hw->init = &init;
150
151 init.name = desc->name;
152 init.ops = &clk_ops_pcom;
153 init.num_parents = 0;
154 init.flags = CLK_IS_ROOT;
155
156 if (!(p->flags & CLKFLAG_AUTO_OFF))
157 init.flags |= CLK_IGNORE_UNUSED;
158
159 c = devm_clk_register(&pdev->dev, hw);
160 ret = clk_register_clkdev(c, desc->con, desc->dev);
161 if (ret)
162 return ret;
163 }
164
135 return 0; 165 return 0;
136} 166}
137 167