1fee10bd2SNaga Sureshkumar Relli // SPDX-License-Identifier: GPL-2.0
2fee10bd2SNaga Sureshkumar Relli /*
3fee10bd2SNaga Sureshkumar Relli * ARM PL353 SMC driver
4fee10bd2SNaga Sureshkumar Relli *
5fee10bd2SNaga Sureshkumar Relli * Copyright (C) 2012 - 2018 Xilinx, Inc
6fee10bd2SNaga Sureshkumar Relli * Author: Punnaiah Choudary Kalluri <punnaiah@xilinx.com>
7fee10bd2SNaga Sureshkumar Relli * Author: Naga Sureshkumar Relli <nagasure@xilinx.com>
8fee10bd2SNaga Sureshkumar Relli */
9fee10bd2SNaga Sureshkumar Relli
10fee10bd2SNaga Sureshkumar Relli #include <linux/clk.h>
11fee10bd2SNaga Sureshkumar Relli #include <linux/kernel.h>
12fee10bd2SNaga Sureshkumar Relli #include <linux/module.h>
130b483871SRob Herring #include <linux/of.h>
14fee10bd2SNaga Sureshkumar Relli #include <linux/of_platform.h>
15fee10bd2SNaga Sureshkumar Relli #include <linux/platform_device.h>
16fee10bd2SNaga Sureshkumar Relli #include <linux/amba/bus.h>
17fee10bd2SNaga Sureshkumar Relli
18fee10bd2SNaga Sureshkumar Relli /**
19fee10bd2SNaga Sureshkumar Relli * struct pl353_smc_data - Private smc driver structure
20fee10bd2SNaga Sureshkumar Relli * @memclk: Pointer to the peripheral clock
219d7bb449SMiquel Raynal * @aclk: Pointer to the AXI peripheral clock
22fee10bd2SNaga Sureshkumar Relli */
23fee10bd2SNaga Sureshkumar Relli struct pl353_smc_data {
24fee10bd2SNaga Sureshkumar Relli struct clk *memclk;
25fee10bd2SNaga Sureshkumar Relli struct clk *aclk;
26fee10bd2SNaga Sureshkumar Relli };
27fee10bd2SNaga Sureshkumar Relli
pl353_smc_suspend(struct device * dev)28fee10bd2SNaga Sureshkumar Relli static int __maybe_unused pl353_smc_suspend(struct device *dev)
29fee10bd2SNaga Sureshkumar Relli {
30fee10bd2SNaga Sureshkumar Relli struct pl353_smc_data *pl353_smc = dev_get_drvdata(dev);
31fee10bd2SNaga Sureshkumar Relli
32fee10bd2SNaga Sureshkumar Relli clk_disable(pl353_smc->memclk);
33fee10bd2SNaga Sureshkumar Relli clk_disable(pl353_smc->aclk);
34fee10bd2SNaga Sureshkumar Relli
35fee10bd2SNaga Sureshkumar Relli return 0;
36fee10bd2SNaga Sureshkumar Relli }
37fee10bd2SNaga Sureshkumar Relli
pl353_smc_resume(struct device * dev)38fee10bd2SNaga Sureshkumar Relli static int __maybe_unused pl353_smc_resume(struct device *dev)
39fee10bd2SNaga Sureshkumar Relli {
40fee10bd2SNaga Sureshkumar Relli struct pl353_smc_data *pl353_smc = dev_get_drvdata(dev);
41df6c2646SMiquel Raynal int ret;
42fee10bd2SNaga Sureshkumar Relli
43fee10bd2SNaga Sureshkumar Relli ret = clk_enable(pl353_smc->aclk);
44fee10bd2SNaga Sureshkumar Relli if (ret) {
45fee10bd2SNaga Sureshkumar Relli dev_err(dev, "Cannot enable axi domain clock.\n");
46fee10bd2SNaga Sureshkumar Relli return ret;
47fee10bd2SNaga Sureshkumar Relli }
48fee10bd2SNaga Sureshkumar Relli
49fee10bd2SNaga Sureshkumar Relli ret = clk_enable(pl353_smc->memclk);
50fee10bd2SNaga Sureshkumar Relli if (ret) {
51fee10bd2SNaga Sureshkumar Relli dev_err(dev, "Cannot enable memory clock.\n");
52fee10bd2SNaga Sureshkumar Relli clk_disable(pl353_smc->aclk);
53fee10bd2SNaga Sureshkumar Relli return ret;
54fee10bd2SNaga Sureshkumar Relli }
55fee10bd2SNaga Sureshkumar Relli
56fee10bd2SNaga Sureshkumar Relli return ret;
57fee10bd2SNaga Sureshkumar Relli }
58fee10bd2SNaga Sureshkumar Relli
59fee10bd2SNaga Sureshkumar Relli static SIMPLE_DEV_PM_OPS(pl353_smc_dev_pm_ops, pl353_smc_suspend,
60fee10bd2SNaga Sureshkumar Relli pl353_smc_resume);
61fee10bd2SNaga Sureshkumar Relli
62fee10bd2SNaga Sureshkumar Relli static const struct of_device_id pl353_smc_supported_children[] = {
63fee10bd2SNaga Sureshkumar Relli {
64fee10bd2SNaga Sureshkumar Relli .compatible = "cfi-flash"
65fee10bd2SNaga Sureshkumar Relli },
66fee10bd2SNaga Sureshkumar Relli {
67fee10bd2SNaga Sureshkumar Relli .compatible = "arm,pl353-nand-r2p1",
68fee10bd2SNaga Sureshkumar Relli },
69fee10bd2SNaga Sureshkumar Relli {}
70fee10bd2SNaga Sureshkumar Relli };
71fee10bd2SNaga Sureshkumar Relli
pl353_smc_probe(struct amba_device * adev,const struct amba_id * id)72fee10bd2SNaga Sureshkumar Relli static int pl353_smc_probe(struct amba_device *adev, const struct amba_id *id)
73fee10bd2SNaga Sureshkumar Relli {
74df6c2646SMiquel Raynal struct device_node *of_node = adev->dev.of_node;
75df6c2646SMiquel Raynal const struct of_device_id *match = NULL;
76fee10bd2SNaga Sureshkumar Relli struct pl353_smc_data *pl353_smc;
77fee10bd2SNaga Sureshkumar Relli
78fee10bd2SNaga Sureshkumar Relli pl353_smc = devm_kzalloc(&adev->dev, sizeof(*pl353_smc), GFP_KERNEL);
79fee10bd2SNaga Sureshkumar Relli if (!pl353_smc)
80fee10bd2SNaga Sureshkumar Relli return -ENOMEM;
81fee10bd2SNaga Sureshkumar Relli
82ce536578SKrzysztof Kozlowski pl353_smc->aclk = devm_clk_get_enabled(&adev->dev, "apb_pclk");
8349ee2e84SKrzysztof Kozlowski if (IS_ERR(pl353_smc->aclk))
8449ee2e84SKrzysztof Kozlowski return dev_err_probe(&adev->dev, PTR_ERR(pl353_smc->aclk),
8549ee2e84SKrzysztof Kozlowski "aclk clock not found.\n");
86fee10bd2SNaga Sureshkumar Relli
87ce536578SKrzysztof Kozlowski pl353_smc->memclk = devm_clk_get_enabled(&adev->dev, "memclk");
8849ee2e84SKrzysztof Kozlowski if (IS_ERR(pl353_smc->memclk))
8949ee2e84SKrzysztof Kozlowski return dev_err_probe(&adev->dev, PTR_ERR(pl353_smc->memclk),
9049ee2e84SKrzysztof Kozlowski "memclk clock not found.\n");
91fee10bd2SNaga Sureshkumar Relli
92fee10bd2SNaga Sureshkumar Relli amba_set_drvdata(adev, pl353_smc);
93fee10bd2SNaga Sureshkumar Relli
94fee10bd2SNaga Sureshkumar Relli /* Find compatible children. Only a single child is supported */
95*32960b4fSKrzysztof Kozlowski for_each_available_child_of_node_scoped(of_node, child) {
96fee10bd2SNaga Sureshkumar Relli match = of_match_node(pl353_smc_supported_children, child);
97fee10bd2SNaga Sureshkumar Relli if (!match) {
98fee10bd2SNaga Sureshkumar Relli dev_warn(&adev->dev, "unsupported child node\n");
99fee10bd2SNaga Sureshkumar Relli continue;
100fee10bd2SNaga Sureshkumar Relli }
101*32960b4fSKrzysztof Kozlowski of_platform_device_create(child, NULL, &adev->dev);
102fee10bd2SNaga Sureshkumar Relli break;
103fee10bd2SNaga Sureshkumar Relli }
104fee10bd2SNaga Sureshkumar Relli if (!match) {
105fee10bd2SNaga Sureshkumar Relli dev_err(&adev->dev, "no matching children\n");
106ce536578SKrzysztof Kozlowski return -ENODEV;
107fee10bd2SNaga Sureshkumar Relli }
108fee10bd2SNaga Sureshkumar Relli
109fee10bd2SNaga Sureshkumar Relli return 0;
110fee10bd2SNaga Sureshkumar Relli }
111fee10bd2SNaga Sureshkumar Relli
112fee10bd2SNaga Sureshkumar Relli static const struct amba_id pl353_ids[] = {
113fee10bd2SNaga Sureshkumar Relli {
114fee10bd2SNaga Sureshkumar Relli .id = 0x00041353,
115fee10bd2SNaga Sureshkumar Relli .mask = 0x000fffff,
116fee10bd2SNaga Sureshkumar Relli },
117fee10bd2SNaga Sureshkumar Relli { 0, 0 },
118fee10bd2SNaga Sureshkumar Relli };
119fee10bd2SNaga Sureshkumar Relli MODULE_DEVICE_TABLE(amba, pl353_ids);
120fee10bd2SNaga Sureshkumar Relli
121fee10bd2SNaga Sureshkumar Relli static struct amba_driver pl353_smc_driver = {
122fee10bd2SNaga Sureshkumar Relli .drv = {
123fee10bd2SNaga Sureshkumar Relli .name = "pl353-smc",
124fee10bd2SNaga Sureshkumar Relli .pm = &pl353_smc_dev_pm_ops,
125fee10bd2SNaga Sureshkumar Relli },
126fee10bd2SNaga Sureshkumar Relli .id_table = pl353_ids,
127fee10bd2SNaga Sureshkumar Relli .probe = pl353_smc_probe,
128fee10bd2SNaga Sureshkumar Relli };
129fee10bd2SNaga Sureshkumar Relli
130fee10bd2SNaga Sureshkumar Relli module_amba_driver(pl353_smc_driver);
131fee10bd2SNaga Sureshkumar Relli
132fee10bd2SNaga Sureshkumar Relli MODULE_AUTHOR("Xilinx, Inc.");
133fee10bd2SNaga Sureshkumar Relli MODULE_DESCRIPTION("ARM PL353 SMC Driver");
134fee10bd2SNaga Sureshkumar Relli MODULE_LICENSE("GPL");
135