Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 2 | * Copyright (c) 2011-2012, The Linux Foundation. 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> |
Matt Wagantall | d1fd566 | 2012-06-08 13:49:43 -0700 | [diff] [blame] | 17 | #include <asm/cputype.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 18 | |
| 19 | DEFINE_RAW_SPINLOCK(l2_access_lock); |
| 20 | |
| 21 | u32 set_get_l2_indirect_reg(u32 reg_addr, u32 val) |
| 22 | { |
| 23 | unsigned long flags; |
| 24 | u32 ret_val; |
Matt Wagantall | d1fd566 | 2012-06-08 13:49:43 -0700 | [diff] [blame] | 25 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | raw_spin_lock_irqsave(&l2_access_lock, flags); |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 27 | mb(); |
| 28 | asm volatile ("mcr p15, 3, %[l2cpselr], c15, c0, 6\n\t" |
Stepan Moskovchenko | 4d05561 | 2012-03-08 12:22:22 -0800 | [diff] [blame] | 29 | "isb\n\t" |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 30 | "mcr p15, 3, %[l2cpdr], c15, c0, 7\n\t" |
Stepan Moskovchenko | 4d05561 | 2012-03-08 12:22:22 -0800 | [diff] [blame] | 31 | "isb\n\t" |
| 32 | "mrc p15, 3, %[l2cpdr_read], c15, c0, 7\n\t" |
| 33 | : [l2cpdr_read]"=r" (ret_val) |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 34 | : [l2cpselr]"r" (reg_addr), [l2cpdr]"r" (val) |
| 35 | ); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 36 | raw_spin_unlock_irqrestore(&l2_access_lock, flags); |
| 37 | |
| 38 | return ret_val; |
| 39 | } |
Suren Eda Naarayana Kulothungan | 88d37fb | 2011-10-21 11:33:06 -0400 | [diff] [blame] | 40 | EXPORT_SYMBOL(set_get_l2_indirect_reg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 41 | |
| 42 | void set_l2_indirect_reg(u32 reg_addr, u32 val) |
| 43 | { |
| 44 | unsigned long flags; |
Matt Wagantall | d1fd566 | 2012-06-08 13:49:43 -0700 | [diff] [blame] | 45 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | raw_spin_lock_irqsave(&l2_access_lock, flags); |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 47 | mb(); |
| 48 | asm volatile ("mcr p15, 3, %[l2cpselr], c15, c0, 6\n\t" |
Stepan Moskovchenko | 4d05561 | 2012-03-08 12:22:22 -0800 | [diff] [blame] | 49 | "isb\n\t" |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 50 | "mcr p15, 3, %[l2cpdr], c15, c0, 7\n\t" |
Stepan Moskovchenko | 4d05561 | 2012-03-08 12:22:22 -0800 | [diff] [blame] | 51 | "isb\n\t" |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 52 | : |
| 53 | : [l2cpselr]"r" (reg_addr), [l2cpdr]"r" (val) |
| 54 | ); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 55 | raw_spin_unlock_irqrestore(&l2_access_lock, flags); |
| 56 | } |
Suren Eda Naarayana Kulothungan | 88d37fb | 2011-10-21 11:33:06 -0400 | [diff] [blame] | 57 | EXPORT_SYMBOL(set_l2_indirect_reg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 58 | |
| 59 | u32 get_l2_indirect_reg(u32 reg_addr) |
| 60 | { |
| 61 | u32 val; |
| 62 | unsigned long flags; |
| 63 | |
| 64 | raw_spin_lock_irqsave(&l2_access_lock, flags); |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 65 | asm volatile ("mcr p15, 3, %[l2cpselr], c15, c0, 6\n\t" |
Stepan Moskovchenko | 4d05561 | 2012-03-08 12:22:22 -0800 | [diff] [blame] | 66 | "isb\n\t" |
Stephen Boyd | 387ac2e | 2011-09-28 10:29:43 -0700 | [diff] [blame] | 67 | "mrc p15, 3, %[l2cpdr], c15, c0, 7\n\t" |
| 68 | : [l2cpdr]"=r" (val) |
| 69 | : [l2cpselr]"r" (reg_addr) |
| 70 | ); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 71 | raw_spin_unlock_irqrestore(&l2_access_lock, flags); |
| 72 | |
| 73 | return val; |
| 74 | } |
Suren Eda Naarayana Kulothungan | 88d37fb | 2011-10-21 11:33:06 -0400 | [diff] [blame] | 75 | EXPORT_SYMBOL(get_l2_indirect_reg); |