summaryrefslogtreecommitdiff
path: root/plat/sun50iw1p1/scp/hwspinlock/hwspinlock.c
blob: 863d457c8186015e88fe181cc8dfc21396a81e4a (plain)
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
/*
 *  arch/arm/mach-sunxi/arisc/hwspinlock/hwspinlock.c
 *
 * Copyright (c) 2012 Allwinner.
 * 2012-10-01 Written by superm (superm@allwinnertech.com).
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "hwspinlock_i.h"

static struct arisc_hwspinlock arisc_hwspinlocks[ARISC_HW_SPINLOCK_NUM];
static uintptr_t base;

/**
 * initialize hwspinlock.
 * @para:  none.
 *
 * returns:  0 if initialize hwspinlock succeeded, others if failed.
 */
int arisc_hwspinlock_init(void)
{
	base = dts_cfg.hwspinlock.base;

	return 0;
}

/**
 * exit hwspinlock.
 * @para:none.
 *
 * returns:  0 if exit hwspinlock succeeded, others if failed.
 */
int arisc_hwspinlock_exit(void)
{
	return 0;
}

/**
 * lock an hwspinlock with timeout limit,
 * and hwspinlock will be unlocked in arisc_hwspin_unlock().
 * @hwid: an hwspinlock id which we want to lock.
 *
 * returns:  0 if lock hwspinlock succeeded, other if failed.
 */
int arisc_hwspin_lock(int hwid)
{
	arisc_hwspinlock_t *spinlock;

	if (hwid >= ARISC_HW_SPINLOCK_NUM) {
		ARISC_ERR("invalid hwspinlock id [%d] for trylock\n", hwid);
		return -EINVAL;
	}
	spinlock = &(arisc_hwspinlocks[hwid]);

	/* is lock already taken by another context on the local cpu ? */
	spin_lock(&(spinlock->lock));

	/* try to take spinlock */
	while (readl(base + AW_SPINLOCK_LOCK_REG(hwid)) == AW_SPINLOCK_TAKEN);

	return 0;
}

/**
 * unlock a specific hwspinlock.
 * hwid:  an hwspinlock id which we want to unlock.
 *
 * returns:  0 if unlock hwspinlock succeeded, other if failed.
 */
int arisc_hwspin_unlock(int hwid)
{
	arisc_hwspinlock_t *spinlock;

	if (hwid >= ARISC_HW_SPINLOCK_NUM) {
		ARISC_ERR("invalid hwspinlock id [%d] for unlock\n", hwid);
		return -EINVAL;
	}
	spinlock = &(arisc_hwspinlocks[hwid]);

	/* untaken the spinlock */
	writel(0x0, base + AW_SPINLOCK_LOCK_REG(hwid));

	spin_unlock(&(spinlock->lock));

	return 0;
}

int arisc_hwspinlock_standby_suspend(void)
{
	return 0;
}

int arisc_hwspinlock_standby_resume(void)
{
	return 0;
}