![Thomas Gleixner](/assets/img/avatar_default.png)
Based on 1 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public license version 2 as published by the free software foundation 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 extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 655 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Allison Randal <allison@lohutok.net> Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Richard Fontana <rfontana@redhat.com> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190527070034.575739538@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
80 lines
2.4 KiB
C
80 lines
2.4 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (c) 2015 Pengutronix, Sascha Hauer <kernel@pengutronix.de>
|
|
*/
|
|
|
|
#include <linux/export.h>
|
|
#include <linux/jiffies.h>
|
|
#include <linux/regmap.h>
|
|
#include <linux/soc/mediatek/infracfg.h>
|
|
#include <asm/processor.h>
|
|
|
|
#define MTK_POLL_DELAY_US 10
|
|
#define MTK_POLL_TIMEOUT (jiffies_to_usecs(HZ))
|
|
|
|
#define INFRA_TOPAXI_PROTECTEN 0x0220
|
|
#define INFRA_TOPAXI_PROTECTSTA1 0x0228
|
|
#define INFRA_TOPAXI_PROTECTEN_SET 0x0260
|
|
#define INFRA_TOPAXI_PROTECTEN_CLR 0x0264
|
|
|
|
/**
|
|
* mtk_infracfg_set_bus_protection - enable bus protection
|
|
* @regmap: The infracfg regmap
|
|
* @mask: The mask containing the protection bits to be enabled.
|
|
* @reg_update: The boolean flag determines to set the protection bits
|
|
* by regmap_update_bits with enable register(PROTECTEN) or
|
|
* by regmap_write with set register(PROTECTEN_SET).
|
|
*
|
|
* This function enables the bus protection bits for disabled power
|
|
* domains so that the system does not hang when some unit accesses the
|
|
* bus while in power down.
|
|
*/
|
|
int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask,
|
|
bool reg_update)
|
|
{
|
|
u32 val;
|
|
int ret;
|
|
|
|
if (reg_update)
|
|
regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask,
|
|
mask);
|
|
else
|
|
regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_SET, mask);
|
|
|
|
ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1,
|
|
val, (val & mask) == mask,
|
|
MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* mtk_infracfg_clear_bus_protection - disable bus protection
|
|
* @regmap: The infracfg regmap
|
|
* @mask: The mask containing the protection bits to be disabled.
|
|
* @reg_update: The boolean flag determines to clear the protection bits
|
|
* by regmap_update_bits with enable register(PROTECTEN) or
|
|
* by regmap_write with clear register(PROTECTEN_CLR).
|
|
*
|
|
* This function disables the bus protection bits previously enabled with
|
|
* mtk_infracfg_set_bus_protection.
|
|
*/
|
|
|
|
int mtk_infracfg_clear_bus_protection(struct regmap *infracfg, u32 mask,
|
|
bool reg_update)
|
|
{
|
|
int ret;
|
|
u32 val;
|
|
|
|
if (reg_update)
|
|
regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask, 0);
|
|
else
|
|
regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_CLR, mask);
|
|
|
|
ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1,
|
|
val, !(val & mask),
|
|
MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
|
|
|
|
return ret;
|
|
}
|