1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright Intel Corporation (C) 2017. All Rights Reserved
5 * Reset driver for Altera Arria10 MAX5 System Resource Chip
7 * Adapted from reset-socfpga.c
10 #include <linux/err.h>
11 #include <linux/mfd/altera-a10sr.h>
12 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/reset-controller.h>
17 #include <dt-bindings/reset/altr,rst-mgr-a10sr.h>
20 struct reset_controller_dev rcdev;
21 struct regmap *regmap;
24 static inline struct a10sr_reset *to_a10sr_rst(struct reset_controller_dev *rc)
26 return container_of(rc, struct a10sr_reset, rcdev);
29 static inline int a10sr_reset_shift(unsigned long id)
32 case A10SR_RESET_ENET_HPS:
34 case A10SR_RESET_PCIE:
35 case A10SR_RESET_FILE:
36 case A10SR_RESET_BQSPI:
44 static int a10sr_reset_update(struct reset_controller_dev *rcdev,
45 unsigned long id, bool assert)
47 struct a10sr_reset *a10r = to_a10sr_rst(rcdev);
48 int offset = a10sr_reset_shift(id);
49 u8 mask = ALTR_A10SR_REG_BIT_MASK(offset);
50 int index = ALTR_A10SR_HPS_RST_REG + ALTR_A10SR_REG_OFFSET(offset);
52 return regmap_update_bits(a10r->regmap, index, mask, assert ? 0 : mask);
55 static int a10sr_reset_assert(struct reset_controller_dev *rcdev,
58 return a10sr_reset_update(rcdev, id, true);
61 static int a10sr_reset_deassert(struct reset_controller_dev *rcdev,
64 return a10sr_reset_update(rcdev, id, false);
67 static int a10sr_reset_status(struct reset_controller_dev *rcdev,
71 struct a10sr_reset *a10r = to_a10sr_rst(rcdev);
72 int offset = a10sr_reset_shift(id);
73 u8 mask = ALTR_A10SR_REG_BIT_MASK(offset);
74 int index = ALTR_A10SR_HPS_RST_REG + ALTR_A10SR_REG_OFFSET(offset);
77 ret = regmap_read(a10r->regmap, index, &value);
81 return !!(value & mask);
84 static const struct reset_control_ops a10sr_reset_ops = {
85 .assert = a10sr_reset_assert,
86 .deassert = a10sr_reset_deassert,
87 .status = a10sr_reset_status,
90 static int a10sr_reset_probe(struct platform_device *pdev)
92 struct altr_a10sr *a10sr = dev_get_drvdata(pdev->dev.parent);
93 struct a10sr_reset *a10r;
95 a10r = devm_kzalloc(&pdev->dev, sizeof(struct a10sr_reset),
100 a10r->rcdev.owner = THIS_MODULE;
101 a10r->rcdev.nr_resets = A10SR_RESET_NUM;
102 a10r->rcdev.ops = &a10sr_reset_ops;
103 a10r->rcdev.of_node = pdev->dev.of_node;
104 a10r->regmap = a10sr->regmap;
106 platform_set_drvdata(pdev, a10r);
108 return devm_reset_controller_register(&pdev->dev, &a10r->rcdev);
111 static const struct of_device_id a10sr_reset_of_match[] = {
112 { .compatible = "altr,a10sr-reset" },
115 MODULE_DEVICE_TABLE(of, a10sr_reset_of_match);
117 static struct platform_driver a10sr_reset_driver = {
118 .probe = a10sr_reset_probe,
120 .name = "altr_a10sr_reset",
121 .of_match_table = a10sr_reset_of_match,
124 module_platform_driver(a10sr_reset_driver);
126 MODULE_AUTHOR("Thor Thayer <thor.thayer@linux.intel.com>");
127 MODULE_DESCRIPTION("Altera Arria10 System Resource Reset Controller Driver");
128 MODULE_LICENSE("GPL v2");