2 * AR71xx Reset Controller Driver
5 * Copyright (C) 2015 Alban Bedel <albeu@free.fr>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
21 #include <linux/reset-controller.h>
22 #include <linux/reboot.h>
25 struct reset_controller_dev rcdev;
26 struct notifier_block restart_nb;
31 #define FULL_CHIP_RESET 24
33 static int ath79_reset_update(struct reset_controller_dev *rcdev,
34 unsigned long id, bool assert)
36 struct ath79_reset *ath79_reset =
37 container_of(rcdev, struct ath79_reset, rcdev);
41 spin_lock_irqsave(&ath79_reset->lock, flags);
42 val = readl(ath79_reset->base);
47 writel(val, ath79_reset->base);
48 spin_unlock_irqrestore(&ath79_reset->lock, flags);
53 static int ath79_reset_assert(struct reset_controller_dev *rcdev,
56 return ath79_reset_update(rcdev, id, true);
59 static int ath79_reset_deassert(struct reset_controller_dev *rcdev,
62 return ath79_reset_update(rcdev, id, false);
65 static int ath79_reset_status(struct reset_controller_dev *rcdev,
68 struct ath79_reset *ath79_reset =
69 container_of(rcdev, struct ath79_reset, rcdev);
72 val = readl(ath79_reset->base);
74 return !!(val & BIT(id));
77 static const struct reset_control_ops ath79_reset_ops = {
78 .assert = ath79_reset_assert,
79 .deassert = ath79_reset_deassert,
80 .status = ath79_reset_status,
83 static int ath79_reset_restart_handler(struct notifier_block *nb,
84 unsigned long action, void *data)
86 struct ath79_reset *ath79_reset =
87 container_of(nb, struct ath79_reset, restart_nb);
89 ath79_reset_assert(&ath79_reset->rcdev, FULL_CHIP_RESET);
94 static int ath79_reset_probe(struct platform_device *pdev)
96 struct ath79_reset *ath79_reset;
100 ath79_reset = devm_kzalloc(&pdev->dev,
101 sizeof(*ath79_reset), GFP_KERNEL);
105 platform_set_drvdata(pdev, ath79_reset);
107 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
108 ath79_reset->base = devm_ioremap_resource(&pdev->dev, res);
109 if (IS_ERR(ath79_reset->base))
110 return PTR_ERR(ath79_reset->base);
112 spin_lock_init(&ath79_reset->lock);
113 ath79_reset->rcdev.ops = &ath79_reset_ops;
114 ath79_reset->rcdev.owner = THIS_MODULE;
115 ath79_reset->rcdev.of_node = pdev->dev.of_node;
116 ath79_reset->rcdev.of_reset_n_cells = 1;
117 ath79_reset->rcdev.nr_resets = 32;
119 err = devm_reset_controller_register(&pdev->dev, &ath79_reset->rcdev);
123 ath79_reset->restart_nb.notifier_call = ath79_reset_restart_handler;
124 ath79_reset->restart_nb.priority = 128;
126 err = register_restart_handler(&ath79_reset->restart_nb);
128 dev_warn(&pdev->dev, "Failed to register restart handler\n");
133 static const struct of_device_id ath79_reset_dt_ids[] = {
134 { .compatible = "qca,ar7100-reset", },
138 static struct platform_driver ath79_reset_driver = {
139 .probe = ath79_reset_probe,
141 .name = "ath79-reset",
142 .of_match_table = ath79_reset_dt_ids,
143 .suppress_bind_attrs = true,
146 builtin_platform_driver(ath79_reset_driver);