2 * Copyright (C) 2017 Synopsys.
4 * Synopsys AXS10x reset driver.
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/reset-controller.h>
16 #define to_axs10x_rst(p) container_of((p), struct axs10x_rst, rcdev)
18 #define AXS10X_MAX_RESETS 32
21 void __iomem *regs_rst;
23 struct reset_controller_dev rcdev;
26 static int axs10x_reset_reset(struct reset_controller_dev *rcdev,
29 struct axs10x_rst *rst = to_axs10x_rst(rcdev);
32 spin_lock_irqsave(&rst->lock, flags);
33 writel(BIT(id), rst->regs_rst);
34 spin_unlock_irqrestore(&rst->lock, flags);
39 static const struct reset_control_ops axs10x_reset_ops = {
40 .reset = axs10x_reset_reset,
43 static int axs10x_reset_probe(struct platform_device *pdev)
45 struct axs10x_rst *rst;
48 rst = devm_kzalloc(&pdev->dev, sizeof(*rst), GFP_KERNEL);
52 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
53 rst->regs_rst = devm_ioremap_resource(&pdev->dev, mem);
54 if (IS_ERR(rst->regs_rst))
55 return PTR_ERR(rst->regs_rst);
57 spin_lock_init(&rst->lock);
59 rst->rcdev.owner = THIS_MODULE;
60 rst->rcdev.ops = &axs10x_reset_ops;
61 rst->rcdev.of_node = pdev->dev.of_node;
62 rst->rcdev.nr_resets = AXS10X_MAX_RESETS;
64 return devm_reset_controller_register(&pdev->dev, &rst->rcdev);
67 static const struct of_device_id axs10x_reset_dt_match[] = {
68 { .compatible = "snps,axs10x-reset" },
72 static struct platform_driver axs10x_reset_driver = {
73 .probe = axs10x_reset_probe,
75 .name = "axs10x-reset",
76 .of_match_table = axs10x_reset_dt_match,
79 builtin_platform_driver(axs10x_reset_driver);
81 MODULE_AUTHOR("Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>");
82 MODULE_DESCRIPTION("Synopsys AXS10x reset driver");
83 MODULE_LICENSE("GPL v2");