0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/io.h>
0012 #include <linux/module.h>
0013 #include <linux/mod_devicetable.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/reset-controller.h>
0016
0017 #define to_axs10x_rst(p) container_of((p), struct axs10x_rst, rcdev)
0018
0019 #define AXS10X_MAX_RESETS 32
0020
0021 struct axs10x_rst {
0022 void __iomem *regs_rst;
0023 spinlock_t lock;
0024 struct reset_controller_dev rcdev;
0025 };
0026
0027 static int axs10x_reset_reset(struct reset_controller_dev *rcdev,
0028 unsigned long id)
0029 {
0030 struct axs10x_rst *rst = to_axs10x_rst(rcdev);
0031 unsigned long flags;
0032
0033 spin_lock_irqsave(&rst->lock, flags);
0034 writel(BIT(id), rst->regs_rst);
0035 spin_unlock_irqrestore(&rst->lock, flags);
0036
0037 return 0;
0038 }
0039
0040 static const struct reset_control_ops axs10x_reset_ops = {
0041 .reset = axs10x_reset_reset,
0042 };
0043
0044 static int axs10x_reset_probe(struct platform_device *pdev)
0045 {
0046 struct axs10x_rst *rst;
0047 struct resource *mem;
0048
0049 rst = devm_kzalloc(&pdev->dev, sizeof(*rst), GFP_KERNEL);
0050 if (!rst)
0051 return -ENOMEM;
0052
0053 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0054 rst->regs_rst = devm_ioremap_resource(&pdev->dev, mem);
0055 if (IS_ERR(rst->regs_rst))
0056 return PTR_ERR(rst->regs_rst);
0057
0058 spin_lock_init(&rst->lock);
0059
0060 rst->rcdev.owner = THIS_MODULE;
0061 rst->rcdev.ops = &axs10x_reset_ops;
0062 rst->rcdev.of_node = pdev->dev.of_node;
0063 rst->rcdev.nr_resets = AXS10X_MAX_RESETS;
0064
0065 return devm_reset_controller_register(&pdev->dev, &rst->rcdev);
0066 }
0067
0068 static const struct of_device_id axs10x_reset_dt_match[] = {
0069 { .compatible = "snps,axs10x-reset" },
0070 { },
0071 };
0072
0073 static struct platform_driver axs10x_reset_driver = {
0074 .probe = axs10x_reset_probe,
0075 .driver = {
0076 .name = "axs10x-reset",
0077 .of_match_table = axs10x_reset_dt_match,
0078 },
0079 };
0080 builtin_platform_driver(axs10x_reset_driver);
0081
0082 MODULE_AUTHOR("Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>");
0083 MODULE_DESCRIPTION("Synopsys AXS10x reset driver");
0084 MODULE_LICENSE("GPL v2");