From 8e4bff4cab0ddac6060645b0715210484d02ff40 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Wed, 30 Aug 2017 08:25:59 +0000 Subject: Initial file dump from open source release --- drivers/platform/sprd/glb.c | 85 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 drivers/platform/sprd/glb.c (limited to 'drivers/platform/sprd/glb.c') diff --git a/drivers/platform/sprd/glb.c b/drivers/platform/sprd/glb.c new file mode 100644 index 00000000..2f9da396 --- /dev/null +++ b/drivers/platform/sprd/glb.c @@ -0,0 +1,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 +#include +#include +#include +#include +#include + +#include +#include +#include + +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); + -- cgit v1.3.1