clk: mediatek: clk-mtk: Introduce clk_mtk_pdev_{probe,remove}()
authorAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Mon, 6 Mar 2023 14:04:51 +0000 (15:04 +0100)
committerStephen Boyd <sboyd@kernel.org>
Mon, 13 Mar 2023 18:50:13 +0000 (11:50 -0700)
Introduce functions clk_mtk_pdev_probe() and clk_mtk_pdev_remove():
these will be useful to commonize the probe and remove handlers for
multimedia (clk-mtxxxx-mm) drivers as these are registered by the
mtk-mmsys driver instead of having their own devicetree compatible.

In order to do this, the main logic of clk_mtk_simple{probe,remove}()
was moved to new static __clk_mtk_simple_{probe,remove}() functions
that take as parameter a pointer to struct device_node because when
registering the clocks from mtk-mmsys we want to pass a pointer to
the clock driver's parent (which is, obviously, mtk-mmsys) struct
device_node instead.

As for the clock driver's platform data: for the devicetree case, we
keep using the standard match_data mechanism, else we retrieve it
from an id_table.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Tested-by: Miles Chen <miles.chen@mediatek.com>
Tested-by: Chen-Yu Tsai <wenst@chromium.org>
Link: https://lore.kernel.org/r/20230306140543.1813621-3-angelogioacchino.delregno@collabora.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/mediatek/clk-mtk.c
drivers/clk/mediatek/clk-mtk.h

index f0b7233..990be3d 100644 (file)
@@ -462,17 +462,25 @@ void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num,
 }
 EXPORT_SYMBOL_GPL(mtk_clk_unregister_dividers);
 
-int mtk_clk_simple_probe(struct platform_device *pdev)
+static int __mtk_clk_simple_probe(struct platform_device *pdev,
+                                 struct device_node *node)
 {
+       const struct platform_device_id *id;
        const struct mtk_clk_desc *mcd;
        struct clk_hw_onecell_data *clk_data;
-       struct device_node *node = pdev->dev.of_node;
        void __iomem *base;
        int num_clks, r;
 
        mcd = device_get_match_data(&pdev->dev);
-       if (!mcd)
-               return -EINVAL;
+       if (!mcd) {
+               /* Clock driver wasn't registered from devicetree */
+               id = platform_get_device_id(pdev);
+               if (id)
+                       mcd = (const struct mtk_clk_desc *)id->driver_data;
+
+               if (!mcd)
+                       return -EINVAL;
+       }
 
        /* Composite clocks needs us to pass iomem pointer */
        if (mcd->composite_clks) {
@@ -581,13 +589,12 @@ free_data:
                iounmap(base);
        return r;
 }
-EXPORT_SYMBOL_GPL(mtk_clk_simple_probe);
 
-int mtk_clk_simple_remove(struct platform_device *pdev)
+static int __mtk_clk_simple_remove(struct platform_device *pdev,
+                                  struct device_node *node)
 {
-       const struct mtk_clk_desc *mcd = device_get_match_data(&pdev->dev);
        struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-       struct device_node *node = pdev->dev.of_node;
+       const struct mtk_clk_desc *mcd = device_get_match_data(&pdev->dev);
 
        of_clk_del_provider(node);
        if (mcd->clks)
@@ -608,6 +615,37 @@ int mtk_clk_simple_remove(struct platform_device *pdev)
 
        return 0;
 }
+
+int mtk_clk_pdev_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct device_node *node = dev->parent->of_node;
+
+       return __mtk_clk_simple_probe(pdev, node);
+}
+EXPORT_SYMBOL_GPL(mtk_clk_pdev_probe);
+
+int mtk_clk_simple_probe(struct platform_device *pdev)
+{
+       struct device_node *node = pdev->dev.of_node;
+
+       return __mtk_clk_simple_probe(pdev, node);
+}
+EXPORT_SYMBOL_GPL(mtk_clk_simple_probe);
+
+int mtk_clk_pdev_remove(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct device_node *node = dev->parent->of_node;
+
+       return __mtk_clk_simple_remove(pdev, node);
+}
+EXPORT_SYMBOL_GPL(mtk_clk_pdev_remove);
+
+int mtk_clk_simple_remove(struct platform_device *pdev)
+{
+       return __mtk_clk_simple_remove(pdev, pdev->dev.of_node);
+}
 EXPORT_SYMBOL_GPL(mtk_clk_simple_remove);
 
 MODULE_LICENSE("GPL");
index 41f4fa3..b8e0ff8 100644 (file)
@@ -236,6 +236,8 @@ struct mtk_clk_desc {
        unsigned int mfg_clk_idx;
 };
 
+int mtk_clk_pdev_probe(struct platform_device *pdev);
+int mtk_clk_pdev_remove(struct platform_device *pdev);
 int mtk_clk_simple_probe(struct platform_device *pdev);
 int mtk_clk_simple_remove(struct platform_device *pdev);