Vikram Mulukutla | 892656a | 2013-03-11 12:10:45 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 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 Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 14 | #include <linux/smp.h> |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 15 | #include "acpuclock.h" |
Matt Wagantall | 7c57b5d | 2012-07-30 19:19:52 -0700 | [diff] [blame] | 16 | #include <trace/events/power.h> |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 17 | |
| 18 | static struct acpuclk_data *acpuclk_data; |
| 19 | |
| 20 | unsigned long acpuclk_get_rate(int cpu) |
| 21 | { |
Vikram Mulukutla | 892656a | 2013-03-11 12:10:45 -0700 | [diff] [blame] | 22 | if (!acpuclk_data || !acpuclk_data->get_rate) |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 23 | return 0; |
| 24 | |
| 25 | return acpuclk_data->get_rate(cpu); |
| 26 | } |
| 27 | |
| 28 | int acpuclk_set_rate(int cpu, unsigned long rate, enum setrate_reason reason) |
| 29 | { |
Matt Wagantall | 7c57b5d | 2012-07-30 19:19:52 -0700 | [diff] [blame] | 30 | int ret; |
| 31 | |
Vikram Mulukutla | 892656a | 2013-03-11 12:10:45 -0700 | [diff] [blame] | 32 | if (!acpuclk_data || !acpuclk_data->set_rate) |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 33 | return 0; |
| 34 | |
Matt Wagantall | 7c57b5d | 2012-07-30 19:19:52 -0700 | [diff] [blame] | 35 | trace_cpu_frequency_switch_start(acpuclk_get_rate(cpu), rate, cpu); |
| 36 | ret = acpuclk_data->set_rate(cpu, rate, reason); |
| 37 | if (!ret) { |
| 38 | trace_cpu_frequency_switch_end(cpu); |
| 39 | trace_cpu_frequency(rate, cpu); |
| 40 | } |
| 41 | |
| 42 | return ret; |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | uint32_t acpuclk_get_switch_time(void) |
| 46 | { |
| 47 | return acpuclk_data->switch_time_us; |
| 48 | } |
| 49 | |
| 50 | unsigned long acpuclk_power_collapse(void) |
| 51 | { |
| 52 | unsigned long rate = acpuclk_get_rate(smp_processor_id()); |
| 53 | acpuclk_set_rate(smp_processor_id(), acpuclk_data->power_collapse_khz, |
| 54 | SETRATE_PC); |
| 55 | return rate; |
| 56 | } |
| 57 | |
| 58 | unsigned long acpuclk_wait_for_irq(void) |
| 59 | { |
| 60 | unsigned long rate = acpuclk_get_rate(smp_processor_id()); |
| 61 | acpuclk_set_rate(smp_processor_id(), acpuclk_data->wait_for_irq_khz, |
| 62 | SETRATE_SWFI); |
| 63 | return rate; |
| 64 | } |
| 65 | |
Matt Wagantall | bf430eb | 2012-03-22 11:45:49 -0700 | [diff] [blame] | 66 | void __devinit acpuclk_register(struct acpuclk_data *data) |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 67 | { |
| 68 | acpuclk_data = data; |
| 69 | } |