]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - drivers/reset/reset-ath79.c
Merge tag 'wireless-drivers-for-davem-2019-02-04' of git://git.kernel.org/pub/scm...
[mirror_ubuntu-focal-kernel.git] / drivers / reset / reset-ath79.c
CommitLineData
ff591a91 1/*
90ce95ab
PG
2 * AR71xx Reset Controller Driver
3 * Author: Alban Bedel
4 *
ff591a91
AB
5 * Copyright (C) 2015 Alban Bedel <albeu@free.fr>
6 *
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.
11 *
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.
16 */
17
9e9ba091 18#include <linux/io.h>
90ce95ab 19#include <linux/init.h>
ac316725 20#include <linux/mod_devicetable.h>
ff591a91
AB
21#include <linux/platform_device.h>
22#include <linux/reset-controller.h>
ba64e27e 23#include <linux/reboot.h>
ff591a91
AB
24
25struct ath79_reset {
26 struct reset_controller_dev rcdev;
ba64e27e 27 struct notifier_block restart_nb;
ff591a91
AB
28 void __iomem *base;
29 spinlock_t lock;
30};
31
ba64e27e
AB
32#define FULL_CHIP_RESET 24
33
ff591a91
AB
34static int ath79_reset_update(struct reset_controller_dev *rcdev,
35 unsigned long id, bool assert)
36{
37 struct ath79_reset *ath79_reset =
38 container_of(rcdev, struct ath79_reset, rcdev);
39 unsigned long flags;
40 u32 val;
41
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);
50
51 return 0;
52}
53
54static int ath79_reset_assert(struct reset_controller_dev *rcdev,
55 unsigned long id)
56{
57 return ath79_reset_update(rcdev, id, true);
58}
59
60static int ath79_reset_deassert(struct reset_controller_dev *rcdev,
61 unsigned long id)
62{
63 return ath79_reset_update(rcdev, id, false);
64}
65
66static int ath79_reset_status(struct reset_controller_dev *rcdev,
67 unsigned long id)
68{
69 struct ath79_reset *ath79_reset =
70 container_of(rcdev, struct ath79_reset, rcdev);
71 u32 val;
72
73 val = readl(ath79_reset->base);
74
75 return !!(val & BIT(id));
76}
77
d2f79f22 78static const struct reset_control_ops ath79_reset_ops = {
ff591a91
AB
79 .assert = ath79_reset_assert,
80 .deassert = ath79_reset_deassert,
81 .status = ath79_reset_status,
82};
83
ba64e27e
AB
84static int ath79_reset_restart_handler(struct notifier_block *nb,
85 unsigned long action, void *data)
86{
87 struct ath79_reset *ath79_reset =
88 container_of(nb, struct ath79_reset, restart_nb);
89
90 ath79_reset_assert(&ath79_reset->rcdev, FULL_CHIP_RESET);
91
92 return NOTIFY_DONE;
93}
94
ff591a91
AB
95static int ath79_reset_probe(struct platform_device *pdev)
96{
97 struct ath79_reset *ath79_reset;
98 struct resource *res;
ba64e27e 99 int err;
ff591a91
AB
100
101 ath79_reset = devm_kzalloc(&pdev->dev,
102 sizeof(*ath79_reset), GFP_KERNEL);
103 if (!ath79_reset)
104 return -ENOMEM;
105
106 platform_set_drvdata(pdev, ath79_reset);
107
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);
112
f319cb84 113 spin_lock_init(&ath79_reset->lock);
ff591a91
AB
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;
119
56865f45 120 err = devm_reset_controller_register(&pdev->dev, &ath79_reset->rcdev);
ba64e27e
AB
121 if (err)
122 return err;
123
124 ath79_reset->restart_nb.notifier_call = ath79_reset_restart_handler;
125 ath79_reset->restart_nb.priority = 128;
126
127 err = register_restart_handler(&ath79_reset->restart_nb);
128 if (err)
129 dev_warn(&pdev->dev, "Failed to register restart handler\n");
130
131 return 0;
ff591a91
AB
132}
133
ff591a91
AB
134static const struct of_device_id ath79_reset_dt_ids[] = {
135 { .compatible = "qca,ar7100-reset", },
136 { },
137};
ff591a91
AB
138
139static struct platform_driver ath79_reset_driver = {
140 .probe = ath79_reset_probe,
ff591a91 141 .driver = {
90ce95ab
PG
142 .name = "ath79-reset",
143 .of_match_table = ath79_reset_dt_ids,
144 .suppress_bind_attrs = true,
ff591a91
AB
145 },
146};
90ce95ab 147builtin_platform_driver(ath79_reset_driver);