blob: 3d341e31864621c07802a88d7223a1df8fec0f23 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/*
Stepan Moskovchenko4d055612012-03-08 12:22:22 -08002 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003 *
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 Kulothungan88d37fb2011-10-21 11:33:06 -040015#include <linux/module.h>
Stephen Boyd387ac2e2011-09-28 10:29:43 -070016#include <asm/mach-types.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070017
18DEFINE_RAW_SPINLOCK(l2_access_lock);
19
20u32 set_get_l2_indirect_reg(u32 reg_addr, u32 val)
21{
22 unsigned long flags;
23 u32 ret_val;
Stephen Boyd387ac2e2011-09-28 10:29:43 -070024 /* CP15 registers are not emulated on RUMI3. */
25 if (machine_is_msm8960_rumi3())
26 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027
28 raw_spin_lock_irqsave(&l2_access_lock, flags);
29
Stephen Boyd387ac2e2011-09-28 10:29:43 -070030 mb();
31 asm volatile ("mcr p15, 3, %[l2cpselr], c15, c0, 6\n\t"
Stepan Moskovchenko4d055612012-03-08 12:22:22 -080032 "isb\n\t"
Stephen Boyd387ac2e2011-09-28 10:29:43 -070033 "mcr p15, 3, %[l2cpdr], c15, c0, 7\n\t"
Stepan Moskovchenko4d055612012-03-08 12:22:22 -080034 "isb\n\t"
35 "mrc p15, 3, %[l2cpdr_read], c15, c0, 7\n\t"
36 : [l2cpdr_read]"=r" (ret_val)
Stephen Boyd387ac2e2011-09-28 10:29:43 -070037 : [l2cpselr]"r" (reg_addr), [l2cpdr]"r" (val)
38 );
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039 raw_spin_unlock_irqrestore(&l2_access_lock, flags);
40
41 return ret_val;
42}
Suren Eda Naarayana Kulothungan88d37fb2011-10-21 11:33:06 -040043EXPORT_SYMBOL(set_get_l2_indirect_reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070044
45void set_l2_indirect_reg(u32 reg_addr, u32 val)
46{
47 unsigned long flags;
Stephen Boyd387ac2e2011-09-28 10:29:43 -070048 /* CP15 registers are not emulated on RUMI3. */
49 if (machine_is_msm8960_rumi3())
50 return;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051
52 raw_spin_lock_irqsave(&l2_access_lock, flags);
Stephen Boyd387ac2e2011-09-28 10:29:43 -070053 mb();
54 asm volatile ("mcr p15, 3, %[l2cpselr], c15, c0, 6\n\t"
Stepan Moskovchenko4d055612012-03-08 12:22:22 -080055 "isb\n\t"
Stephen Boyd387ac2e2011-09-28 10:29:43 -070056 "mcr p15, 3, %[l2cpdr], c15, c0, 7\n\t"
Stepan Moskovchenko4d055612012-03-08 12:22:22 -080057 "isb\n\t"
Stephen Boyd387ac2e2011-09-28 10:29:43 -070058 :
59 : [l2cpselr]"r" (reg_addr), [l2cpdr]"r" (val)
60 );
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070061 raw_spin_unlock_irqrestore(&l2_access_lock, flags);
62}
Suren Eda Naarayana Kulothungan88d37fb2011-10-21 11:33:06 -040063EXPORT_SYMBOL(set_l2_indirect_reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070064
65u32 get_l2_indirect_reg(u32 reg_addr)
66{
67 u32 val;
68 unsigned long flags;
Stephen Boyd387ac2e2011-09-28 10:29:43 -070069 /* CP15 registers are not emulated on RUMI3. */
70 if (machine_is_msm8960_rumi3())
71 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070072
73 raw_spin_lock_irqsave(&l2_access_lock, flags);
Stephen Boyd387ac2e2011-09-28 10:29:43 -070074 asm volatile ("mcr p15, 3, %[l2cpselr], c15, c0, 6\n\t"
Stepan Moskovchenko4d055612012-03-08 12:22:22 -080075 "isb\n\t"
Stephen Boyd387ac2e2011-09-28 10:29:43 -070076 "mrc p15, 3, %[l2cpdr], c15, c0, 7\n\t"
77 : [l2cpdr]"=r" (val)
78 : [l2cpselr]"r" (reg_addr)
79 );
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070080 raw_spin_unlock_irqrestore(&l2_access_lock, flags);
81
82 return val;
83}
Suren Eda Naarayana Kulothungan88d37fb2011-10-21 11:33:06 -040084EXPORT_SYMBOL(get_l2_indirect_reg);