1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*
* Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
*/
/*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/
#include <linux/types.h>
#include <linux/module.h>
#include <asm/io.h>
#include <asm/arch/hardware.h>
#include <asm/arch/spba.h>
/*!
* @file plat-mxc/spba.c
*
* @brief This file contains the SPBA API implementation details.
*
* @ingroup SPBA
*/
static DEFINE_SPINLOCK(spba_lock);
#define SPBA_MASTER_MIN 1
#define SPBA_MASTER_MAX 7
/*!
* the base addresses for the SPBA modules
*/
static unsigned long spba_base = (unsigned long)IO_ADDRESS(SPBA_CTRL_BASE_ADDR);
/*!
* This function allows the three masters (A, B, C) to take ownership of a
* shared peripheral.
*
* @param mod specified module as defined in \b enum \b #spba_module
* @param master one of more (or-ed together) masters as defined in \b enum \b #spba_masters
*
* @return 0 if successful; -1 otherwise.
*/
int spba_take_ownership(int mod, int master)
{
unsigned long spba_flags;
__u32 rtn_val = -1;
if (master < SPBA_MASTER_MIN || master > SPBA_MASTER_MAX) {
printk("spba_take_ownership() invalide master= %d\n", master);
BUG(); /* oops */
}
spin_lock_irqsave(&spba_lock, spba_flags);
__raw_writel(master, spba_base + mod);
if ((__raw_readl(spba_base + mod) & MXC_SPBA_RAR_MASK) == master) {
rtn_val = 0;
}
spin_unlock_irqrestore(&spba_lock, spba_flags);
return rtn_val;
}
/*!
* This function releases the ownership for a shared peripheral.
*
* @param mod specified module as defined in \b enum \b #spba_module
* @param master one of more (or-ed together) masters as defined in \b enum \b #spba_masters
*
* @return 0 if successful; -1 otherwise.
*/
int spba_rel_ownership(int mod, int master)
{
unsigned long spba_flags;
volatile unsigned long rar;
if (master < SPBA_MASTER_MIN || master > SPBA_MASTER_MAX) {
printk("spba_take_ownership() invalide master= %d\n", master);
BUG(); /* oops */
}
if ((__raw_readl(spba_base + mod) & master) == 0) {
return 0; /* does not own it */
}
spin_lock_irqsave(&spba_lock, spba_flags);
/* Since only the last 3 bits are writeable, doesn't need to mask off
bits 31-3 */
rar = __raw_readl(spba_base + mod) & (~master);
__raw_writel(rar, spba_base + mod);
if ((__raw_readl(spba_base + mod) & master) != 0) {
spin_unlock_irqrestore(&spba_lock, spba_flags);
return -1;
}
spin_unlock_irqrestore(&spba_lock, spba_flags);
return 0;
}
EXPORT_SYMBOL(spba_take_ownership);
EXPORT_SYMBOL(spba_rel_ownership);
MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("SPBA");
MODULE_LICENSE("GPL");
|