Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 1 | /* 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 | |
| 16 | static struct acpuclk_data *acpuclk_data; |
| 17 | |
| 18 | unsigned 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 | |
| 26 | int 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 | |
| 34 | uint32_t acpuclk_get_switch_time(void) |
| 35 | { |
| 36 | return acpuclk_data->switch_time_us; |
| 37 | } |
| 38 | |
| 39 | unsigned 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 | |
| 47 | unsigned 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 | |
| 55 | void __init acpuclk_register(struct acpuclk_data *data) |
| 56 | { |
| 57 | acpuclk_data = data; |
| 58 | } |
| 59 | |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 60 | int __init acpuclk_init(struct acpuclk_soc_data *soc_data) |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 61 | { |
| 62 | int rc; |
| 63 | |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 64 | if (!soc_data->init) |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 65 | return -EINVAL; |
| 66 | |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 67 | rc = soc_data->init(soc_data); |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 68 | if (rc) |
| 69 | return rc; |
| 70 | |
| 71 | if (!acpuclk_data) |
| 72 | return -ENODEV; |
| 73 | |
| 74 | return 0; |
| 75 | } |