1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2012 - 2018 Xilinx, Inc
6 * Author: Punnaiah Choudary Kalluri <punnaiah@xilinx.com>
7 * Author: Naga Sureshkumar Relli <nagasure@xilinx.com>
10 #include <linux/clk.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/of_platform.h>
14 #include <linux/platform_device.h>
15 #include <linux/amba/bus.h>
18 * struct pl353_smc_data - Private smc driver structure
19 * @memclk: Pointer to the peripheral clock
20 * @aclk: Pointer to the AXI peripheral clock
22 struct pl353_smc_data {
27 static int __maybe_unused pl353_smc_suspend(struct device *dev)
29 struct pl353_smc_data *pl353_smc = dev_get_drvdata(dev);
31 clk_disable(pl353_smc->memclk);
32 clk_disable(pl353_smc->aclk);
37 static int __maybe_unused pl353_smc_resume(struct device *dev)
39 struct pl353_smc_data *pl353_smc = dev_get_drvdata(dev);
42 ret = clk_enable(pl353_smc->aclk);
44 dev_err(dev, "Cannot enable axi domain clock.\n");
48 ret = clk_enable(pl353_smc->memclk);
50 dev_err(dev, "Cannot enable memory clock.\n");
51 clk_disable(pl353_smc->aclk);
58 static SIMPLE_DEV_PM_OPS(pl353_smc_dev_pm_ops, pl353_smc_suspend,
61 static const struct of_device_id pl353_smc_supported_children[] = {
63 .compatible = "cfi-flash"
66 .compatible = "arm,pl353-nand-r2p1",
71 static int pl353_smc_probe(struct amba_device *adev, const struct amba_id *id)
73 struct device_node *of_node = adev->dev.of_node;
74 const struct of_device_id *match = NULL;
75 struct pl353_smc_data *pl353_smc;
76 struct device_node *child;
79 pl353_smc = devm_kzalloc(&adev->dev, sizeof(*pl353_smc), GFP_KERNEL);
83 pl353_smc->aclk = devm_clk_get(&adev->dev, "apb_pclk");
84 if (IS_ERR(pl353_smc->aclk)) {
85 dev_err(&adev->dev, "aclk clock not found.\n");
86 return PTR_ERR(pl353_smc->aclk);
89 pl353_smc->memclk = devm_clk_get(&adev->dev, "memclk");
90 if (IS_ERR(pl353_smc->memclk)) {
91 dev_err(&adev->dev, "memclk clock not found.\n");
92 return PTR_ERR(pl353_smc->memclk);
95 err = clk_prepare_enable(pl353_smc->aclk);
97 dev_err(&adev->dev, "Unable to enable AXI clock.\n");
101 err = clk_prepare_enable(pl353_smc->memclk);
103 dev_err(&adev->dev, "Unable to enable memory clock.\n");
104 goto disable_axi_clk;
107 amba_set_drvdata(adev, pl353_smc);
109 /* Find compatible children. Only a single child is supported */
110 for_each_available_child_of_node(of_node, child) {
111 match = of_match_node(pl353_smc_supported_children, child);
113 dev_warn(&adev->dev, "unsupported child node\n");
120 dev_err(&adev->dev, "no matching children\n");
121 goto disable_mem_clk;
124 of_platform_device_create(child, NULL, &adev->dev);
130 clk_disable_unprepare(pl353_smc->memclk);
132 clk_disable_unprepare(pl353_smc->aclk);
137 static void pl353_smc_remove(struct amba_device *adev)
139 struct pl353_smc_data *pl353_smc = amba_get_drvdata(adev);
141 clk_disable_unprepare(pl353_smc->memclk);
142 clk_disable_unprepare(pl353_smc->aclk);
145 static const struct amba_id pl353_ids[] = {
152 MODULE_DEVICE_TABLE(amba, pl353_ids);
154 static struct amba_driver pl353_smc_driver = {
156 .owner = THIS_MODULE,
158 .pm = &pl353_smc_dev_pm_ops,
160 .id_table = pl353_ids,
161 .probe = pl353_smc_probe,
162 .remove = pl353_smc_remove,
165 module_amba_driver(pl353_smc_driver);
167 MODULE_AUTHOR("Xilinx, Inc.");
168 MODULE_DESCRIPTION("ARM PL353 SMC Driver");
169 MODULE_LICENSE("GPL");