xref: /linux/drivers/reset/reset-axs10x.c (revision df34ecc52526480a1a4bb78bc75bfb009c6076a4)
1 /*
2  * Copyright (C) 2017 Synopsys.
3  *
4  * Synopsys AXS10x reset driver.
5  *
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.
9  */
10 
11 #include <linux/io.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/reset-controller.h>
15 
16 #define to_axs10x_rst(p)	container_of((p), struct axs10x_rst, rcdev)
17 
18 #define AXS10X_MAX_RESETS	32
19 
20 struct axs10x_rst {
21 	void __iomem			*regs_rst;
22 	spinlock_t			lock;
23 	struct reset_controller_dev	rcdev;
24 };
25 
26 static int axs10x_reset_reset(struct reset_controller_dev *rcdev,
27 			      unsigned long id)
28 {
29 	struct axs10x_rst *rst = to_axs10x_rst(rcdev);
30 	unsigned long flags;
31 
32 	spin_lock_irqsave(&rst->lock, flags);
33 	writel(BIT(id), rst->regs_rst);
34 	spin_unlock_irqrestore(&rst->lock, flags);
35 
36 	return 0;
37 }
38 
39 static const struct reset_control_ops axs10x_reset_ops = {
40 	.reset	= axs10x_reset_reset,
41 };
42 
43 static int axs10x_reset_probe(struct platform_device *pdev)
44 {
45 	struct axs10x_rst *rst;
46 
47 	rst = devm_kzalloc(&pdev->dev, sizeof(*rst), GFP_KERNEL);
48 	if (!rst)
49 		return -ENOMEM;
50 
51 	rst->regs_rst = devm_platform_ioremap_resource(pdev, 0);
52 	if (IS_ERR(rst->regs_rst))
53 		return PTR_ERR(rst->regs_rst);
54 
55 	spin_lock_init(&rst->lock);
56 
57 	rst->rcdev.owner = THIS_MODULE;
58 	rst->rcdev.ops = &axs10x_reset_ops;
59 	rst->rcdev.of_node = pdev->dev.of_node;
60 	rst->rcdev.nr_resets = AXS10X_MAX_RESETS;
61 
62 	return devm_reset_controller_register(&pdev->dev, &rst->rcdev);
63 }
64 
65 static const struct of_device_id axs10x_reset_dt_match[] = {
66 	{ .compatible = "snps,axs10x-reset" },
67 	{ },
68 };
69 
70 static struct platform_driver axs10x_reset_driver = {
71 	.probe	= axs10x_reset_probe,
72 	.driver	= {
73 		.name = "axs10x-reset",
74 		.of_match_table = axs10x_reset_dt_match,
75 	},
76 };
77 builtin_platform_driver(axs10x_reset_driver);
78 
79 MODULE_AUTHOR("Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>");
80 MODULE_DESCRIPTION("Synopsys AXS10x reset driver");
81 MODULE_LICENSE("GPL v2");
82