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