Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
Stepan Moskovchenko | 4d05561 | 2012-03-08 12:22:22 -0800 | [diff] [blame] | 2 | * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -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/spinlock.h> |
Suren Eda Naarayana Kulothungan | 88d37fb | 2011-10-21 11:33:06 -0400 | [diff] [blame] | 15 | #include <linux/module.h> |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 16 | #include <asm/mach-types.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 17 | |
| 18 | DEFINE_RAW_SPINLOCK(l2_access_lock); |
| 19 | |
| 20 | u32 set_get_l2_indirect_reg(u32 reg_addr, u32 val) |
| 21 | { |
| 22 | unsigned long flags; |
| 23 | u32 ret_val; |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 24 | /* CP15 registers are not emulated on RUMI3. */ |
| 25 | if (machine_is_msm8960_rumi3()) |
| 26 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | |
| 28 | raw_spin_lock_irqsave(&l2_access_lock, flags); |
| 29 | |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 30 | mb(); |
| 31 | asm volatile ("mcr p15, 3, %[l2cpselr], c15, c0, 6\n\t" |
Stepan Moskovchenko | 4d05561 | 2012-03-08 12:22:22 -0800 | [diff] [blame] | 32 | "isb\n\t" |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 33 | "mcr p15, 3, %[l2cpdr], c15, c0, 7\n\t" |
Stepan Moskovchenko | 4d05561 | 2012-03-08 12:22:22 -0800 | [diff] [blame] | 34 | "isb\n\t" |
| 35 | "mrc p15, 3, %[l2cpdr_read], c15, c0, 7\n\t" |
| 36 | : [l2cpdr_read]"=r" (ret_val) |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 37 | : [l2cpselr]"r" (reg_addr), [l2cpdr]"r" (val) |
| 38 | ); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 39 | raw_spin_unlock_irqrestore(&l2_access_lock, flags); |
| 40 | |
| 41 | return ret_val; |
| 42 | } |
Suren Eda Naarayana Kulothungan | 88d37fb | 2011-10-21 11:33:06 -0400 | [diff] [blame] | 43 | EXPORT_SYMBOL(set_get_l2_indirect_reg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 44 | |
| 45 | void set_l2_indirect_reg(u32 reg_addr, u32 val) |
| 46 | { |
| 47 | unsigned long flags; |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 48 | /* CP15 registers are not emulated on RUMI3. */ |
| 49 | if (machine_is_msm8960_rumi3()) |
| 50 | return; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 51 | |
| 52 | raw_spin_lock_irqsave(&l2_access_lock, flags); |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 53 | mb(); |
| 54 | asm volatile ("mcr p15, 3, %[l2cpselr], c15, c0, 6\n\t" |
Stepan Moskovchenko | 4d05561 | 2012-03-08 12:22:22 -0800 | [diff] [blame] | 55 | "isb\n\t" |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 56 | "mcr p15, 3, %[l2cpdr], c15, c0, 7\n\t" |
Stepan Moskovchenko | 4d05561 | 2012-03-08 12:22:22 -0800 | [diff] [blame] | 57 | "isb\n\t" |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 58 | : |
| 59 | : [l2cpselr]"r" (reg_addr), [l2cpdr]"r" (val) |
| 60 | ); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 61 | raw_spin_unlock_irqrestore(&l2_access_lock, flags); |
| 62 | } |
Suren Eda Naarayana Kulothungan | 88d37fb | 2011-10-21 11:33:06 -0400 | [diff] [blame] | 63 | EXPORT_SYMBOL(set_l2_indirect_reg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 64 | |
| 65 | u32 get_l2_indirect_reg(u32 reg_addr) |
| 66 | { |
| 67 | u32 val; |
| 68 | unsigned long flags; |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 69 | /* CP15 registers are not emulated on RUMI3. */ |
| 70 | if (machine_is_msm8960_rumi3()) |
| 71 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 72 | |
| 73 | raw_spin_lock_irqsave(&l2_access_lock, flags); |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 74 | asm volatile ("mcr p15, 3, %[l2cpselr], c15, c0, 6\n\t" |
Stepan Moskovchenko | 4d05561 | 2012-03-08 12:22:22 -0800 | [diff] [blame] | 75 | "isb\n\t" |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 76 | "mrc p15, 3, %[l2cpdr], c15, c0, 7\n\t" |
| 77 | : [l2cpdr]"=r" (val) |
| 78 | : [l2cpselr]"r" (reg_addr) |
| 79 | ); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 80 | raw_spin_unlock_irqrestore(&l2_access_lock, flags); |
| 81 | |
| 82 | return val; |
| 83 | } |
Suren Eda Naarayana Kulothungan | 88d37fb | 2011-10-21 11:33:06 -0400 | [diff] [blame] | 84 | EXPORT_SYMBOL(get_l2_indirect_reg); |