blob: 632173186a6950a28949e6fad9d2478bc40e5f9b [file] [log] [blame]
Daniel Walker5e96da52010-05-12 13:43:28 -07001/*
2 * Copyright (C) 2007 Google, Inc.
3 * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved.
4 *
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
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15
16#include <linux/err.h>
Stephen Boyd421faca2013-06-17 10:43:18 -070017#include <linux/platform_device.h>
18#include <linux/module.h>
19
Daniel Walker5e96da52010-05-12 13:43:28 -070020#include <mach/clk.h>
21
22#include "proc_comm.h"
23#include "clock.h"
Stephen Boydce1c80f2011-01-26 16:20:53 -080024#include "clock-pcom.h"
Daniel Walker5e96da52010-05-12 13:43:28 -070025
26/*
27 * glue for the proc_comm interface
28 */
Stephen Boyd56417052012-08-22 15:55:44 -070029static int pc_clk_enable(unsigned id)
Daniel Walker5e96da52010-05-12 13:43:28 -070030{
31 int rc = msm_proc_comm(PCOM_CLKCTL_RPC_ENABLE, &id, NULL);
32 if (rc < 0)
33 return rc;
34 else
35 return (int)id < 0 ? -EINVAL : 0;
36}
37
Stephen Boyd56417052012-08-22 15:55:44 -070038static void pc_clk_disable(unsigned id)
Daniel Walker5e96da52010-05-12 13:43:28 -070039{
40 msm_proc_comm(PCOM_CLKCTL_RPC_DISABLE, &id, NULL);
41}
42
43int pc_clk_reset(unsigned id, enum clk_reset_action action)
44{
45 int rc;
46
47 if (action == CLK_RESET_ASSERT)
48 rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_ASSERT, &id, NULL);
49 else
50 rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_DEASSERT, &id, NULL);
51
52 if (rc < 0)
53 return rc;
54 else
55 return (int)id < 0 ? -EINVAL : 0;
56}
57
Stephen Boyd56417052012-08-22 15:55:44 -070058static int pc_clk_set_rate(unsigned id, unsigned rate)
Daniel Walker5e96da52010-05-12 13:43:28 -070059{
60 /* 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
62 * that the exact rate was set successfully.
63 */
64 int rc = msm_proc_comm(PCOM_CLKCTL_RPC_SET_RATE, &id, &rate);
65 if (rc < 0)
66 return rc;
67 else
68 return (int)id < 0 ? -EINVAL : 0;
69}
70
Stephen Boyd56417052012-08-22 15:55:44 -070071static int pc_clk_set_min_rate(unsigned id, unsigned rate)
Daniel Walker5e96da52010-05-12 13:43:28 -070072{
73 int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MIN_RATE, &id, &rate);
74 if (rc < 0)
75 return rc;
76 else
77 return (int)id < 0 ? -EINVAL : 0;
78}
79
Stephen Boyd56417052012-08-22 15:55:44 -070080static int pc_clk_set_max_rate(unsigned id, unsigned rate)
Daniel Walker5e96da52010-05-12 13:43:28 -070081{
82 int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MAX_RATE, &id, &rate);
83 if (rc < 0)
84 return rc;
85 else
86 return (int)id < 0 ? -EINVAL : 0;
87}
88
Stephen Boyd56417052012-08-22 15:55:44 -070089static unsigned pc_clk_get_rate(unsigned id)
Daniel Walker5e96da52010-05-12 13:43:28 -070090{
91 if (msm_proc_comm(PCOM_CLKCTL_RPC_RATE, &id, NULL))
92 return 0;
93 else
94 return id;
95}
96
Stephen Boyd56417052012-08-22 15:55:44 -070097static unsigned pc_clk_is_enabled(unsigned id)
Daniel Walker5e96da52010-05-12 13:43:28 -070098{
99 if (msm_proc_comm(PCOM_CLKCTL_RPC_ENABLED, &id, NULL))
100 return 0;
101 else
102 return id;
103}
104
Stephen Boyd56417052012-08-22 15:55:44 -0700105static long pc_clk_round_rate(unsigned id, unsigned rate)
Daniel Walker5e96da52010-05-12 13:43:28 -0700106{
107
108 /* Not really supported; pc_clk_set_rate() does rounding on it's own. */
109 return rate;
110}
111
Stephen Boyd2a522202011-02-23 09:37:41 -0800112static bool pc_clk_is_local(unsigned id)
113{
114 return false;
115}
116
Daniel Walker5e96da52010-05-12 13:43:28 -0700117struct clk_ops clk_ops_pcom = {
118 .enable = pc_clk_enable,
119 .disable = pc_clk_disable,
120 .auto_off = pc_clk_disable,
121 .reset = pc_clk_reset,
122 .set_rate = pc_clk_set_rate,
123 .set_min_rate = pc_clk_set_min_rate,
124 .set_max_rate = pc_clk_set_max_rate,
Daniel Walker5e96da52010-05-12 13:43:28 -0700125 .get_rate = pc_clk_get_rate,
126 .is_enabled = pc_clk_is_enabled,
127 .round_rate = pc_clk_round_rate,
Stephen Boyd2a522202011-02-23 09:37:41 -0800128 .is_local = pc_clk_is_local,
Daniel Walker5e96da52010-05-12 13:43:28 -0700129};
Stephen Boyd421faca2013-06-17 10:43:18 -0700130
131static int msm_clock_pcom_probe(struct platform_device *pdev)
132{
133 const struct pcom_clk_pdata *pdata = pdev->dev.platform_data;
134 msm_clock_init(pdata->lookup, pdata->num_lookups);
135 return 0;
136}
137
138static struct platform_driver msm_clock_pcom_driver = {
139 .probe = msm_clock_pcom_probe,
140 .driver = {
141 .name = "msm-clock-pcom",
142 .owner = THIS_MODULE,
143 },
144};
145module_platform_driver(msm_clock_pcom_driver);
146
147MODULE_LICENSE("GPL v2");