@@ -9,6 +9,7 @@ config COMMON_CLK_MEDIATEK
tristate
select RESET_CONTROLLER
select RESET_MEDIATEK_SYSCLK
+ select AUXILIARY_BUS
help
MediaTek SoCs' clock support.
@@ -58,7 +58,7 @@ static int clk_mt2701_eth_probe(struct platform_device *pdev)
"could not register clock provider: %s: %d\n",
pdev->name, r);
- mtk_reset_init_with_dev(&pdev->dev, "mt2701-eth-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt2701-eth-rst");
return r;
}
@@ -52,7 +52,7 @@ static int clk_mt2701_g3dsys_init(struct platform_device *pdev)
"could not register clock provider: %s: %d\n",
pdev->name, r);
- mtk_reset_init_with_dev(&pdev->dev, "mt2701-g3d-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt2701-g3d-rst");
return r;
}
@@ -57,7 +57,7 @@ static int clk_mt2701_hif_probe(struct platform_device *pdev)
return r;
}
- mtk_reset_init_with_dev(&pdev->dev, "mt2701-hif-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt2701-hif-rst");
return 0;
}
@@ -787,7 +787,7 @@ static int mtk_infrasys_init(struct platform_device *pdev)
if (r)
return r;
- mtk_reset_init_with_dev(&pdev->dev, "mt2701-infrasys-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt2701-infrasys-rst");
return 0;
}
@@ -910,7 +910,7 @@ static int mtk_pericfg_init(struct platform_device *pdev)
if (r)
return r;
- mtk_reset_init_with_dev(&pdev->dev, "mt2701-pericfg-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt2701-pericfg-rst");
return 0;
}
@@ -1361,7 +1361,7 @@ static int clk_mt2712_infra_probe(struct platform_device *pdev)
pr_err("%s(): could not register clock provider: %d\n",
__func__, r);
- mtk_reset_init_with_dev(&pdev->dev, "mt2712-infra-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt2712-infra-rst");
return r;
}
@@ -1383,7 +1383,7 @@ static int clk_mt2712_peri_probe(struct platform_device *pdev)
pr_err("%s(): could not register clock provider: %d\n",
__func__, r);
- mtk_reset_init_with_dev(&pdev->dev, "mt2712-peri-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt2712-peri-rst");
return r;
}
@@ -77,7 +77,7 @@ static int clk_mt6795_infracfg_probe(struct platform_device *pdev)
if (!clk_data)
return -ENOMEM;
- ret = mtk_reset_init_with_dev(&pdev->dev, "mt6795-ifa");
+ ret = mtk_reset_controller_register(&pdev->dev, "mt6795-ifa");
if (ret)
goto free_clk_data;
@@ -87,7 +87,7 @@ static int clk_mt6795_pericfg_probe(struct platform_device *pdev)
if (!clk_data)
return -ENOMEM;
- ret = mtk_reset_init_with_dev(&pdev->dev, "mt6795-peri");
+ ret = mtk_reset_controller_register(&pdev->dev, "mt6795-peri");
if (ret)
goto free_clk_data;
@@ -82,7 +82,7 @@ static int clk_mt7622_ethsys_init(struct platform_device *pdev)
"could not register clock provider: %s: %d\n",
pdev->name, r);
- mtk_reset_init_with_dev(&pdev->dev, "mt7622-eth-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt7622-eth-rst");
return r;
}
@@ -93,7 +93,7 @@ static int clk_mt7622_ssusbsys_init(struct platform_device *pdev)
"could not register clock provider: %s: %d\n",
pdev->name, r);
- mtk_reset_init_with_dev(&pdev->dev, "mt7622-usb-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt7622-usb-rst");
return r;
}
@@ -115,7 +115,7 @@ static int clk_mt7622_pciesys_init(struct platform_device *pdev)
"could not register clock provider: %s: %d\n",
pdev->name, r);
- mtk_reset_init_with_dev(&pdev->dev, "mt7622-pcie-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt7622-pcie-rst");
return r;
}
@@ -663,7 +663,7 @@ static int mtk_infrasys_init(struct platform_device *pdev)
if (r)
return r;
- mtk_reset_init_with_dev(&pdev->dev, "mt7622-infrasys-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt7622-infrasys-rst");
return 0;
}
@@ -714,7 +714,7 @@ static int mtk_pericfg_init(struct platform_device *pdev)
clk_prepare_enable(clk_data->hws[CLK_PERI_UART0_PD]->clk);
- mtk_reset_init_with_dev(&pdev->dev, "mt7622-pericfg-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt7622-pericfg-rst");
return 0;
}
@@ -92,7 +92,7 @@ static int clk_mt7629_ethsys_init(struct platform_device *pdev)
"could not register clock provider: %s: %d\n",
pdev->name, r);
- mtk_reset_init_with_dev(&pdev->dev, "mt7629-ethsys-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt7629-ethsys-rst");
return r;
}
@@ -88,7 +88,7 @@ static int clk_mt7629_ssusbsys_init(struct platform_device *pdev)
"could not register clock provider: %s: %d\n",
pdev->name, r);
- mtk_reset_init_with_dev(&pdev->dev, "mt7629-usb-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt7629-usb-rst");
return r;
}
@@ -110,7 +110,7 @@ static int clk_mt7629_pciesys_init(struct platform_device *pdev)
"could not register clock provider: %s: %d\n",
pdev->name, r);
- mtk_reset_init_with_dev(&pdev->dev, "mt7629-pcie-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt7629-pcie-rst");
return r;
}
@@ -1265,7 +1265,7 @@ static int clk_mt8183_infra_probe(struct platform_device *pdev)
return r;
}
- mtk_reset_init_with_dev(&pdev->dev, "mt8183-infra-rst");
+ mtk_reset_controller_register(&pdev->dev, "mt8183-infra-rst");
return r;
}
@@ -1112,7 +1112,7 @@ static int clk_mt8192_infra_probe(struct platform_device *pdev)
if (r)
goto free_clk_data;
- r = mtk_reset_init_with_dev(&pdev->dev, "mt8192-infra-rst");
+ r = mtk_reset_controller_register(&pdev->dev, "mt8192-infra-rst");
if (r)
goto free_clk_data;
@@ -444,6 +444,63 @@ void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num,
}
EXPORT_SYMBOL_GPL(mtk_clk_unregister_dividers);
+static void mtk_reset_unregister_adev(void *_adev)
+{
+ struct auxiliary_device *adev = _adev;
+
+ auxiliary_device_delete(adev);
+}
+
+static void mtk_reset_adev_release(struct device *dev)
+{
+ struct auxiliary_device *adev = to_auxiliary_dev(dev);
+
+ auxiliary_device_uninit(adev);
+
+ kfree(adev);
+}
+
+static struct auxiliary_device *mtk_reset_adev_alloc(struct device *dev, const char *name)
+{
+ struct auxiliary_device *adev;
+ int ret;
+
+ adev = kzalloc(sizeof(*adev), GFP_KERNEL);
+ if (!adev)
+ return ERR_PTR(-ENOMEM);
+
+ adev->name = name;
+ adev->dev.parent = dev;
+ adev->dev.release = mtk_reset_adev_release;
+
+ ret = auxiliary_device_init(adev);
+ if (ret) {
+ kfree(adev);
+ return ERR_PTR(ret);
+ }
+
+ return adev;
+}
+
+int mtk_reset_controller_register(struct device *dev, const char *name)
+{
+ struct auxiliary_device *adev;
+ int ret;
+
+ adev = mtk_reset_adev_alloc(dev, name);
+ if (IS_ERR(adev))
+ return PTR_ERR(adev);
+
+ ret = auxiliary_device_add(adev);
+ if (ret) {
+ auxiliary_device_uninit(adev);
+ return ret;
+ }
+
+ return devm_add_action_or_reset(dev, mtk_reset_unregister_adev, adev);
+}
+EXPORT_SYMBOL_GPL(mtk_reset_controller_register);
+
int mtk_clk_simple_probe(struct platform_device *pdev)
{
const struct mtk_clk_desc *mcd;
@@ -471,7 +528,7 @@ int mtk_clk_simple_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, clk_data);
if (mcd->rst_name) {
- r = mtk_reset_init_with_dev(&pdev->dev, mcd->rst_name);
+ r = mtk_reset_controller_register(&pdev->dev, mcd->rst_name);
if (r)
goto unregister_clks;
}
@@ -7,6 +7,7 @@
#ifndef __DRV_CLK_MTK_H
#define __DRV_CLK_MTK_H
+#include <linux/auxiliary_bus.h>
#include <linux/clk-provider.h>
#include <linux/io.h>
#include <linux/kernel.h>
@@ -200,4 +201,6 @@ struct mtk_clk_desc {
int mtk_clk_simple_probe(struct platform_device *pdev);
int mtk_clk_simple_remove(struct platform_device *pdev);
+int mtk_reset_controller_register(struct device *dev, const char *name);
+
#endif /* __DRV_CLK_MTK_H */