1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2015 Pengutronix, Sascha Hauer <kernel@pengutronix.de>
6 #include <linux/export.h>
7 #include <linux/jiffies.h>
8 #include <linux/regmap.h>
9 #include <linux/soc/mediatek/infracfg.h>
10 #include <asm/processor.h>
12 #define MTK_POLL_DELAY_US 10
13 #define MTK_POLL_TIMEOUT (jiffies_to_usecs(HZ))
16 * mtk_infracfg_set_bus_protection - enable bus protection
17 * @infracfg: The infracfg regmap
18 * @mask: The mask containing the protection bits to be enabled.
19 * @reg_update: The boolean flag determines to set the protection bits
20 * by regmap_update_bits with enable register(PROTECTEN) or
21 * by regmap_write with set register(PROTECTEN_SET).
23 * This function enables the bus protection bits for disabled power
24 * domains so that the system does not hang when some unit accesses the
25 * bus while in power down.
27 int mtk_infracfg_set_bus_protection(struct regmap
*infracfg
, u32 mask
,
34 regmap_update_bits(infracfg
, INFRA_TOPAXI_PROTECTEN
, mask
,
37 regmap_write(infracfg
, INFRA_TOPAXI_PROTECTEN_SET
, mask
);
39 ret
= regmap_read_poll_timeout(infracfg
, INFRA_TOPAXI_PROTECTSTA1
,
40 val
, (val
& mask
) == mask
,
41 MTK_POLL_DELAY_US
, MTK_POLL_TIMEOUT
);
47 * mtk_infracfg_clear_bus_protection - disable bus protection
48 * @infracfg: The infracfg regmap
49 * @mask: The mask containing the protection bits to be disabled.
50 * @reg_update: The boolean flag determines to clear the protection bits
51 * by regmap_update_bits with enable register(PROTECTEN) or
52 * by regmap_write with clear register(PROTECTEN_CLR).
54 * This function disables the bus protection bits previously enabled with
55 * mtk_infracfg_set_bus_protection.
58 int mtk_infracfg_clear_bus_protection(struct regmap
*infracfg
, u32 mask
,
65 regmap_update_bits(infracfg
, INFRA_TOPAXI_PROTECTEN
, mask
, 0);
67 regmap_write(infracfg
, INFRA_TOPAXI_PROTECTEN_CLR
, mask
);
69 ret
= regmap_read_poll_timeout(infracfg
, INFRA_TOPAXI_PROTECTSTA1
,
71 MTK_POLL_DELAY_US
, MTK_POLL_TIMEOUT
);