summaryrefslogtreecommitdiff
path: root/drivers/platform/sprd/glb.c
blob: 2f9da396eeea3cd7053cbb88441b71c282315aaa (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
/*
 * Copyright (C) 2012 Spreadtrum Communications Inc.
 *
 * 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.
 *
 */
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/hwspinlock.h>
#include <linux/io.h>

#include <soc/sprd/sci.h>
#include <soc/sprd/sci_glb_regs.h>
#include <soc/sprd/arch_lock.h>

u32 sci_glb_read(unsigned long reg, u32 msk)
{
	return __raw_readl((void *)reg) & msk;
}

int sci_glb_write(unsigned long reg, u32 val, u32 msk)
{
	unsigned long flags;
	__arch_default_lock(HWLOCK_GLB, &flags);
	__raw_writel((__raw_readl((void *)reg) & ~msk) | val, (void *)reg);
	__arch_default_unlock(HWLOCK_GLB, &flags);
	return 0;
}

static int __is_glb(unsigned long reg)
{
#if	defined (CONFIG_ARCH_SCX35)
	return 0;
	return rounddown(reg, SZ_64K) == rounddown(REGS_GLB_BASE, SZ_64K) ||
	    rounddown(reg, SZ_64K) == rounddown(REGS_AHB_BASE, SZ_64K) ||
	    rounddown(reg, SZ_64K) == rounddown(REGS_AP_APB_BASE, SZ_64K) ||
	    rounddown(reg, SZ_64K) == rounddown(REGS_PMU_APB_BASE, SZ_64K);

#else
	return rounddown(reg, SZ_64K) == rounddown(REGS_GLB_BASE, SZ_64K) ||
	    rounddown(reg, SZ_64K) == rounddown(REGS_AHB_BASE, SZ_64K);
#endif
}

int sci_glb_set(unsigned long reg, u32 bit)
{
	if (__is_glb(reg)) {
		__raw_writel(bit, (void *)REG_GLB_SET(reg));
	} else {
		unsigned long flags;
		__arch_default_lock(HWLOCK_GLB, &flags);
		__raw_writel(__raw_readl((void *)reg) | bit, (void *)reg);
		__arch_default_unlock(HWLOCK_GLB, &flags);
	}
	return 0;
}

int sci_glb_clr(unsigned long reg, u32 bit)
{
	if (__is_glb(reg)) {
		__raw_writel(bit, (void *)REG_GLB_CLR(reg));
	} else {
		unsigned long flags;
		__arch_default_lock(HWLOCK_GLB, &flags);
		__raw_writel((__raw_readl((void *)reg) & ~bit), (void *)reg);
		__arch_default_unlock(HWLOCK_GLB, &flags);
	}
	return 0;
}

EXPORT_SYMBOL(sci_glb_read);
EXPORT_SYMBOL(sci_glb_write);
EXPORT_SYMBOL(sci_glb_set);
EXPORT_SYMBOL(sci_glb_clr);