blob: e5a3f8b93d901f9312a73a802256397fd7f90506 [file] [log] [blame]
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/cpu.h>
14#include "acpuclock.h"
15
16static struct acpuclk_data *acpuclk_data;
17
18unsigned long acpuclk_get_rate(int cpu)
19{
20 if (!acpuclk_data->get_rate)
21 return 0;
22
23 return acpuclk_data->get_rate(cpu);
24}
25
26int acpuclk_set_rate(int cpu, unsigned long rate, enum setrate_reason reason)
27{
28 if (!acpuclk_data->set_rate)
29 return 0;
30
31 return acpuclk_data->set_rate(cpu, rate, reason);
32}
33
34uint32_t acpuclk_get_switch_time(void)
35{
36 return acpuclk_data->switch_time_us;
37}
38
39unsigned long acpuclk_power_collapse(void)
40{
41 unsigned long rate = acpuclk_get_rate(smp_processor_id());
42 acpuclk_set_rate(smp_processor_id(), acpuclk_data->power_collapse_khz,
43 SETRATE_PC);
44 return rate;
45}
46
47unsigned long acpuclk_wait_for_irq(void)
48{
49 unsigned long rate = acpuclk_get_rate(smp_processor_id());
50 acpuclk_set_rate(smp_processor_id(), acpuclk_data->wait_for_irq_khz,
51 SETRATE_SWFI);
52 return rate;
53}
54
55void __init acpuclk_register(struct acpuclk_data *data)
56{
57 acpuclk_data = data;
58}
59
Matt Wagantallec57f062011-08-16 23:54:46 -070060int __init acpuclk_init(struct acpuclk_soc_data *soc_data)
Matt Wagantall6d9ebee2011-08-26 12:15:24 -070061{
62 int rc;
63
Matt Wagantallec57f062011-08-16 23:54:46 -070064 if (!soc_data->init)
Matt Wagantall6d9ebee2011-08-26 12:15:24 -070065 return -EINVAL;
66
Matt Wagantallec57f062011-08-16 23:54:46 -070067 rc = soc_data->init(soc_data);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -070068 if (rc)
69 return rc;
70
71 if (!acpuclk_data)
72 return -ENODEV;
73
74 return 0;
75}