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>
14 #include <linux/of_platform.h>
15 #include <linux/platform_device.h>
16 #include <linux/amba/bus.h>
19 * struct pl353_smc_data - Private smc driver structure
20 * @memclk: Pointer to the peripheral clock
21 * @aclk: Pointer to the AXI peripheral clock
23 struct pl353_smc_data {
28 static int __maybe_unused pl353_smc_suspend(struct device *dev)
30 struct pl353_smc_data *pl353_smc = dev_get_drvdata(dev);
32 clk_disable(pl353_smc->memclk);
33 clk_disable(pl353_smc->aclk);
38 static int __maybe_unused pl353_smc_resume(struct device *dev)
40 struct pl353_smc_data *pl353_smc = dev_get_drvdata(dev);
43 ret = clk_enable(pl353_smc->aclk);
45 dev_err(dev, "Cannot enable axi domain clock.\n");
49 ret = clk_enable(pl353_smc->memclk);
51 dev_err(dev, "Cannot enable memory clock.\n");
52 clk_disable(pl353_smc->aclk);
59 static SIMPLE_DEV_PM_OPS(pl353_smc_dev_pm_ops, pl353_smc_suspend,
62 static const struct of_device_id pl353_smc_supported_children[] = {
64 .compatible = "cfi-flash"
67 .compatible = "arm,pl353-nand-r2p1",
72 static int pl353_smc_probe(struct amba_device *adev, const struct amba_id *id)
74 struct device_node *of_node = adev->dev.of_node;
75 const struct of_device_id *match = NULL;
76 struct pl353_smc_data *pl353_smc;
77 struct device_node *child;
80 pl353_smc = devm_kzalloc(&adev->dev, sizeof(*pl353_smc), GFP_KERNEL);
84 pl353_smc->aclk = devm_clk_get(&adev->dev, "apb_pclk");
85 if (IS_ERR(pl353_smc->aclk)) {
86 dev_err(&adev->dev, "aclk clock not found.\n");
87 return PTR_ERR(pl353_smc->aclk);
90 pl353_smc->memclk = devm_clk_get(&adev->dev, "memclk");
91 if (IS_ERR(pl353_smc->memclk)) {
92 dev_err(&adev->dev, "memclk clock not found.\n");
93 return PTR_ERR(pl353_smc->memclk);
96 err = clk_prepare_enable(pl353_smc->aclk);
98 dev_err(&adev->dev, "Unable to enable AXI clock.\n");
102 err = clk_prepare_enable(pl353_smc->memclk);
104 dev_err(&adev->dev, "Unable to enable memory clock.\n");
105 goto disable_axi_clk;
108 amba_set_drvdata(adev, pl353_smc);
110 /* Find compatible children. Only a single child is supported */
111 for_each_available_child_of_node(of_node, child) {
112 match = of_match_node(pl353_smc_supported_children, child);
114 dev_warn(&adev->dev, "unsupported child node\n");
121 dev_err(&adev->dev, "no matching children\n");
122 goto disable_mem_clk;
125 of_platform_device_create(child, NULL, &adev->dev);
131 clk_disable_unprepare(pl353_smc->memclk);
133 clk_disable_unprepare(pl353_smc->aclk);
138 static void pl353_smc_remove(struct amba_device *adev)
140 struct pl353_smc_data *pl353_smc = amba_get_drvdata(adev);
142 clk_disable_unprepare(pl353_smc->memclk);
143 clk_disable_unprepare(pl353_smc->aclk);
146 static const struct amba_id pl353_ids[] = {
153 MODULE_DEVICE_TABLE(amba, pl353_ids);
155 static struct amba_driver pl353_smc_driver = {
157 .owner = THIS_MODULE,
159 .pm = &pl353_smc_dev_pm_ops,
161 .id_table = pl353_ids,
162 .probe = pl353_smc_probe,
163 .remove = pl353_smc_remove,
166 module_amba_driver(pl353_smc_driver);
168 MODULE_AUTHOR("Xilinx, Inc.");
169 MODULE_DESCRIPTION("ARM PL353 SMC Driver");
170 MODULE_LICENSE("GPL");