11802d0beSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
216a624a9SSascha Hauer /*
316a624a9SSascha Hauer * Copyright (c) 2015 Pengutronix, Sascha Hauer <kernel@pengutronix.de>
416a624a9SSascha Hauer */
516a624a9SSascha Hauer
616a624a9SSascha Hauer #include <linux/export.h>
716a624a9SSascha Hauer #include <linux/jiffies.h>
816a624a9SSascha Hauer #include <linux/regmap.h>
9*dcfd5192SAlyssa Rosenzweig #include <linux/mfd/syscon.h>
1016a624a9SSascha Hauer #include <linux/soc/mediatek/infracfg.h>
1116a624a9SSascha Hauer #include <asm/processor.h>
1216a624a9SSascha Hauer
13090c6243SSean Wang #define MTK_POLL_DELAY_US 10
14090c6243SSean Wang #define MTK_POLL_TIMEOUT (jiffies_to_usecs(HZ))
15090c6243SSean Wang
1616a624a9SSascha Hauer /**
1716a624a9SSascha Hauer * mtk_infracfg_set_bus_protection - enable bus protection
1811b490c6SKrzysztof Kozlowski * @infracfg: The infracfg regmap
1916a624a9SSascha Hauer * @mask: The mask containing the protection bits to be enabled.
20fa7e843aSweiyi.lu@mediatek.com * @reg_update: The boolean flag determines to set the protection bits
21fa7e843aSweiyi.lu@mediatek.com * by regmap_update_bits with enable register(PROTECTEN) or
22fa7e843aSweiyi.lu@mediatek.com * by regmap_write with set register(PROTECTEN_SET).
2316a624a9SSascha Hauer *
2416a624a9SSascha Hauer * This function enables the bus protection bits for disabled power
2516a624a9SSascha Hauer * domains so that the system does not hang when some unit accesses the
2616a624a9SSascha Hauer * bus while in power down.
2716a624a9SSascha Hauer */
mtk_infracfg_set_bus_protection(struct regmap * infracfg,u32 mask,bool reg_update)28fa7e843aSweiyi.lu@mediatek.com int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask,
29fa7e843aSweiyi.lu@mediatek.com bool reg_update)
3016a624a9SSascha Hauer {
3116a624a9SSascha Hauer u32 val;
3216a624a9SSascha Hauer int ret;
3316a624a9SSascha Hauer
34fa7e843aSweiyi.lu@mediatek.com if (reg_update)
35fa7e843aSweiyi.lu@mediatek.com regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask,
36fa7e843aSweiyi.lu@mediatek.com mask);
37fa7e843aSweiyi.lu@mediatek.com else
38fa7e843aSweiyi.lu@mediatek.com regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_SET, mask);
3916a624a9SSascha Hauer
40090c6243SSean Wang ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1,
41090c6243SSean Wang val, (val & mask) == mask,
42090c6243SSean Wang MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
4316a624a9SSascha Hauer
4416a624a9SSascha Hauer return ret;
4516a624a9SSascha Hauer }
4616a624a9SSascha Hauer
4716a624a9SSascha Hauer /**
4816a624a9SSascha Hauer * mtk_infracfg_clear_bus_protection - disable bus protection
4911b490c6SKrzysztof Kozlowski * @infracfg: The infracfg regmap
5016a624a9SSascha Hauer * @mask: The mask containing the protection bits to be disabled.
51fa7e843aSweiyi.lu@mediatek.com * @reg_update: The boolean flag determines to clear the protection bits
52fa7e843aSweiyi.lu@mediatek.com * by regmap_update_bits with enable register(PROTECTEN) or
53fa7e843aSweiyi.lu@mediatek.com * by regmap_write with clear register(PROTECTEN_CLR).
5416a624a9SSascha Hauer *
5516a624a9SSascha Hauer * This function disables the bus protection bits previously enabled with
5616a624a9SSascha Hauer * mtk_infracfg_set_bus_protection.
5716a624a9SSascha Hauer */
58fa7e843aSweiyi.lu@mediatek.com
mtk_infracfg_clear_bus_protection(struct regmap * infracfg,u32 mask,bool reg_update)59fa7e843aSweiyi.lu@mediatek.com int mtk_infracfg_clear_bus_protection(struct regmap *infracfg, u32 mask,
60fa7e843aSweiyi.lu@mediatek.com bool reg_update)
6116a624a9SSascha Hauer {
6216a624a9SSascha Hauer int ret;
63090c6243SSean Wang u32 val;
6416a624a9SSascha Hauer
65fa7e843aSweiyi.lu@mediatek.com if (reg_update)
6616a624a9SSascha Hauer regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask, 0);
67fa7e843aSweiyi.lu@mediatek.com else
68fa7e843aSweiyi.lu@mediatek.com regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_CLR, mask);
6916a624a9SSascha Hauer
70090c6243SSean Wang ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1,
71090c6243SSean Wang val, !(val & mask),
72090c6243SSean Wang MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
7316a624a9SSascha Hauer
7416a624a9SSascha Hauer return ret;
7516a624a9SSascha Hauer }
76*dcfd5192SAlyssa Rosenzweig
mtk_infracfg_init(void)77*dcfd5192SAlyssa Rosenzweig static int __init mtk_infracfg_init(void)
78*dcfd5192SAlyssa Rosenzweig {
79*dcfd5192SAlyssa Rosenzweig struct regmap *infracfg;
80*dcfd5192SAlyssa Rosenzweig
81*dcfd5192SAlyssa Rosenzweig /*
82*dcfd5192SAlyssa Rosenzweig * MT8192 has an experimental path to route GPU traffic to the DSU's
83*dcfd5192SAlyssa Rosenzweig * Accelerator Coherency Port, which is inadvertently enabled by
84*dcfd5192SAlyssa Rosenzweig * default. It turns out not to work, so disable it to prevent spurious
85*dcfd5192SAlyssa Rosenzweig * GPU faults.
86*dcfd5192SAlyssa Rosenzweig */
87*dcfd5192SAlyssa Rosenzweig infracfg = syscon_regmap_lookup_by_compatible("mediatek,mt8192-infracfg");
88*dcfd5192SAlyssa Rosenzweig if (!IS_ERR(infracfg))
89*dcfd5192SAlyssa Rosenzweig regmap_set_bits(infracfg, MT8192_INFRA_CTRL,
90*dcfd5192SAlyssa Rosenzweig MT8192_INFRA_CTRL_DISABLE_MFG2ACP);
91*dcfd5192SAlyssa Rosenzweig return 0;
92*dcfd5192SAlyssa Rosenzweig }
93*dcfd5192SAlyssa Rosenzweig postcore_initcall(mtk_infracfg_init);
94