Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 1 | /* |
Anji Jonnala | 5063e04 | 2013-03-09 09:49:11 +0530 | [diff] [blame] | 2 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <asm/mach-types.h> |
| 17 | #include <asm/cputype.h> |
| 18 | #include "avs.h" |
Anji Jonnala | 5063e04 | 2013-03-09 09:49:11 +0530 | [diff] [blame] | 19 | #include "spm.h" |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 20 | |
| 21 | u32 avs_get_avscsr(void) |
| 22 | { |
| 23 | u32 val = 0; |
| 24 | |
| 25 | asm volatile ("mrc p15, 7, %[avscsr], c15, c1, 7\n\t" |
| 26 | : [avscsr]"=r" (val) |
| 27 | ); |
| 28 | |
| 29 | return val; |
| 30 | } |
| 31 | EXPORT_SYMBOL(avs_get_avscsr); |
| 32 | |
| 33 | void avs_set_avscsr(u32 avscsr) |
| 34 | { |
| 35 | asm volatile ("mcr p15, 7, %[avscsr], c15, c1, 7\n\t" |
| 36 | "isb\n\t" |
| 37 | : |
| 38 | : [avscsr]"r" (avscsr) |
| 39 | ); |
| 40 | } |
| 41 | EXPORT_SYMBOL(avs_set_avscsr); |
| 42 | |
| 43 | u32 avs_get_avsdscr(void) |
| 44 | { |
| 45 | u32 val = 0; |
| 46 | |
| 47 | asm volatile ("mrc p15, 7, %[avsdscr], c15, c0, 6\n\t" |
| 48 | : [avsdscr]"=r" (val) |
| 49 | ); |
| 50 | |
| 51 | return val; |
| 52 | } |
| 53 | EXPORT_SYMBOL(avs_get_avsdscr); |
| 54 | |
| 55 | void avs_set_avsdscr(u32 avsdscr) |
| 56 | { |
| 57 | asm volatile("mcr p15, 7, %[avsdscr], c15, c0, 6\n\t" |
| 58 | "isb\n\t" |
| 59 | : |
| 60 | : [avsdscr]"r" (avsdscr) |
| 61 | ); |
| 62 | } |
| 63 | EXPORT_SYMBOL(avs_set_avsdscr); |
| 64 | |
| 65 | static void avs_enable_local(void *data) |
| 66 | { |
| 67 | u32 avsdscr = (u32) data; |
| 68 | u32 avscsr_enable = 0x61; |
| 69 | |
| 70 | avs_set_avsdscr(avsdscr); |
| 71 | avs_set_avscsr(avscsr_enable); |
| 72 | } |
| 73 | |
| 74 | static void avs_disable_local(void *data) |
| 75 | { |
Anji Jonnala | 5063e04 | 2013-03-09 09:49:11 +0530 | [diff] [blame] | 76 | int cpu = smp_processor_id(); |
| 77 | |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 78 | avs_set_avscsr(0); |
Anji Jonnala | 5063e04 | 2013-03-09 09:49:11 +0530 | [diff] [blame] | 79 | msm_spm_set_vdd(cpu, msm_spm_get_vdd(cpu)); |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void avs_enable(int cpu, u32 avsdscr) |
| 83 | { |
| 84 | int ret; |
| 85 | |
| 86 | ret = smp_call_function_single(cpu, avs_enable_local, |
| 87 | (void *)avsdscr, true); |
| 88 | WARN_ON(ret); |
| 89 | } |
| 90 | EXPORT_SYMBOL(avs_enable); |
| 91 | |
| 92 | void avs_disable(int cpu) |
| 93 | { |
| 94 | int ret; |
| 95 | |
| 96 | ret = smp_call_function_single(cpu, avs_disable_local, |
| 97 | (void *) 0, true); |
| 98 | WARN_ON(ret); |
| 99 | } |
| 100 | EXPORT_SYMBOL(avs_disable); |