Makefile: Export clang toolchain variables
[linux/fpc-iii.git] / drivers / reset / reset-ath79.c
bloba7455916e3961b9305936028aac78b6b556dff33
1 /*
2 * AR71xx Reset Controller Driver
3 * Author: Alban Bedel
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.
18 #include <linux/io.h>
19 #include <linux/init.h>
20 #include <linux/mod_devicetable.h>
21 #include <linux/platform_device.h>
22 #include <linux/reset-controller.h>
23 #include <linux/reboot.h>
25 struct ath79_reset {
26 struct reset_controller_dev rcdev;
27 struct notifier_block restart_nb;
28 void __iomem *base;
29 spinlock_t lock;
32 #define FULL_CHIP_RESET 24
34 static int ath79_reset_update(struct reset_controller_dev *rcdev,
35 unsigned long id, bool assert)
37 struct ath79_reset *ath79_reset =
38 container_of(rcdev, struct ath79_reset, rcdev);
39 unsigned long flags;
40 u32 val;
42 spin_lock_irqsave(&ath79_reset->lock, flags);
43 val = readl(ath79_reset->base);
44 if (assert)
45 val |= BIT(id);
46 else
47 val &= ~BIT(id);
48 writel(val, ath79_reset->base);
49 spin_unlock_irqrestore(&ath79_reset->lock, flags);
51 return 0;
54 static int ath79_reset_assert(struct reset_controller_dev *rcdev,
55 unsigned long id)
57 return ath79_reset_update(rcdev, id, true);
60 static int ath79_reset_deassert(struct reset_controller_dev *rcdev,
61 unsigned long id)
63 return ath79_reset_update(rcdev, id, false);
66 static int ath79_reset_status(struct reset_controller_dev *rcdev,
67 unsigned long id)
69 struct ath79_reset *ath79_reset =
70 container_of(rcdev, struct ath79_reset, rcdev);
71 u32 val;
73 val = readl(ath79_reset->base);
75 return !!(val & BIT(id));
78 static const struct reset_control_ops ath79_reset_ops = {
79 .assert = ath79_reset_assert,
80 .deassert = ath79_reset_deassert,
81 .status = ath79_reset_status,
84 static int ath79_reset_restart_handler(struct notifier_block *nb,
85 unsigned long action, void *data)
87 struct ath79_reset *ath79_reset =
88 container_of(nb, struct ath79_reset, restart_nb);
90 ath79_reset_assert(&ath79_reset->rcdev, FULL_CHIP_RESET);
92 return NOTIFY_DONE;
95 static int ath79_reset_probe(struct platform_device *pdev)
97 struct ath79_reset *ath79_reset;
98 struct resource *res;
99 int err;
101 ath79_reset = devm_kzalloc(&pdev->dev,
102 sizeof(*ath79_reset), GFP_KERNEL);
103 if (!ath79_reset)
104 return -ENOMEM;
106 platform_set_drvdata(pdev, ath79_reset);
108 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
109 ath79_reset->base = devm_ioremap_resource(&pdev->dev, res);
110 if (IS_ERR(ath79_reset->base))
111 return PTR_ERR(ath79_reset->base);
113 spin_lock_init(&ath79_reset->lock);
114 ath79_reset->rcdev.ops = &ath79_reset_ops;
115 ath79_reset->rcdev.owner = THIS_MODULE;
116 ath79_reset->rcdev.of_node = pdev->dev.of_node;
117 ath79_reset->rcdev.of_reset_n_cells = 1;
118 ath79_reset->rcdev.nr_resets = 32;
120 err = devm_reset_controller_register(&pdev->dev, &ath79_reset->rcdev);
121 if (err)
122 return err;
124 ath79_reset->restart_nb.notifier_call = ath79_reset_restart_handler;
125 ath79_reset->restart_nb.priority = 128;
127 err = register_restart_handler(&ath79_reset->restart_nb);
128 if (err)
129 dev_warn(&pdev->dev, "Failed to register restart handler\n");
131 return 0;
134 static const struct of_device_id ath79_reset_dt_ids[] = {
135 { .compatible = "qca,ar7100-reset", },
136 { },
139 static struct platform_driver ath79_reset_driver = {
140 .probe = ath79_reset_probe,
141 .driver = {
142 .name = "ath79-reset",
143 .of_match_table = ath79_reset_dt_ids,
144 .suppress_bind_attrs = true,
147 builtin_platform_driver(ath79_reset_driver);