WIP FPC-III support
[linux/fpc-iii.git] / drivers / soc / mediatek / mtk-infracfg.c
blob0590b68e0d78be0385c0e91201b193f55114f0c8
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2015 Pengutronix, Sascha Hauer <kernel@pengutronix.de>
4 */
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))
15 /**
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,
28 bool reg_update)
30 u32 val;
31 int ret;
33 if (reg_update)
34 regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask,
35 mask);
36 else
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);
43 return ret;
46 /**
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,
59 bool reg_update)
61 int ret;
62 u32 val;
64 if (reg_update)
65 regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask, 0);
66 else
67 regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_CLR, mask);
69 ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1,
70 val, !(val & mask),
71 MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
73 return ret;