blob: 91071c47259fc651a33cc97c0cc8255e278a942c [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>
Steve Mucklef132c6c2012-06-06 18:30:57 -070014#include <linux/smp.h>
Matt Wagantall6d9ebee2011-08-26 12:15:24 -070015#include "acpuclock.h"
16
17static struct acpuclk_data *acpuclk_data;
18
19unsigned long acpuclk_get_rate(int cpu)
20{
21 if (!acpuclk_data->get_rate)
22 return 0;
23
24 return acpuclk_data->get_rate(cpu);
25}
26
27int acpuclk_set_rate(int cpu, unsigned long rate, enum setrate_reason reason)
28{
29 if (!acpuclk_data->set_rate)
30 return 0;
31
32 return acpuclk_data->set_rate(cpu, rate, reason);
33}
34
35uint32_t acpuclk_get_switch_time(void)
36{
37 return acpuclk_data->switch_time_us;
38}
39
40unsigned long acpuclk_power_collapse(void)
41{
42 unsigned long rate = acpuclk_get_rate(smp_processor_id());
43 acpuclk_set_rate(smp_processor_id(), acpuclk_data->power_collapse_khz,
44 SETRATE_PC);
45 return rate;
46}
47
48unsigned long acpuclk_wait_for_irq(void)
49{
50 unsigned long rate = acpuclk_get_rate(smp_processor_id());
51 acpuclk_set_rate(smp_processor_id(), acpuclk_data->wait_for_irq_khz,
52 SETRATE_SWFI);
53 return rate;
54}
55
56void __init acpuclk_register(struct acpuclk_data *data)
57{
58 acpuclk_data = data;
59}
60
Matt Wagantallec57f062011-08-16 23:54:46 -070061int __init acpuclk_init(struct acpuclk_soc_data *soc_data)
Matt Wagantall6d9ebee2011-08-26 12:15:24 -070062{
63 int rc;
64
Matt Wagantallec57f062011-08-16 23:54:46 -070065 if (!soc_data->init)
Matt Wagantall6d9ebee2011-08-26 12:15:24 -070066 return -EINVAL;
67
Matt Wagantallec57f062011-08-16 23:54:46 -070068 rc = soc_data->init(soc_data);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -070069 if (rc)
70 return rc;
71
72 if (!acpuclk_data)
73 return -ENODEV;
74
75 return 0;
76}