2 * Copyright (C) 2015 Alban Bedel <albeu@free.fr>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/reset-controller.h>
20 struct reset_controller_dev rcdev
;
25 static int ath79_reset_update(struct reset_controller_dev
*rcdev
,
26 unsigned long id
, bool assert)
28 struct ath79_reset
*ath79_reset
=
29 container_of(rcdev
, struct ath79_reset
, rcdev
);
33 spin_lock_irqsave(&ath79_reset
->lock
, flags
);
34 val
= readl(ath79_reset
->base
);
39 writel(val
, ath79_reset
->base
);
40 spin_unlock_irqrestore(&ath79_reset
->lock
, flags
);
45 static int ath79_reset_assert(struct reset_controller_dev
*rcdev
,
48 return ath79_reset_update(rcdev
, id
, true);
51 static int ath79_reset_deassert(struct reset_controller_dev
*rcdev
,
54 return ath79_reset_update(rcdev
, id
, false);
57 static int ath79_reset_status(struct reset_controller_dev
*rcdev
,
60 struct ath79_reset
*ath79_reset
=
61 container_of(rcdev
, struct ath79_reset
, rcdev
);
64 val
= readl(ath79_reset
->base
);
66 return !!(val
& BIT(id
));
69 static struct reset_control_ops ath79_reset_ops
= {
70 .assert = ath79_reset_assert
,
71 .deassert
= ath79_reset_deassert
,
72 .status
= ath79_reset_status
,
75 static int ath79_reset_probe(struct platform_device
*pdev
)
77 struct ath79_reset
*ath79_reset
;
80 ath79_reset
= devm_kzalloc(&pdev
->dev
,
81 sizeof(*ath79_reset
), GFP_KERNEL
);
85 platform_set_drvdata(pdev
, ath79_reset
);
87 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
88 ath79_reset
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
89 if (IS_ERR(ath79_reset
->base
))
90 return PTR_ERR(ath79_reset
->base
);
92 spin_lock_init(&ath79_reset
->lock
);
93 ath79_reset
->rcdev
.ops
= &ath79_reset_ops
;
94 ath79_reset
->rcdev
.owner
= THIS_MODULE
;
95 ath79_reset
->rcdev
.of_node
= pdev
->dev
.of_node
;
96 ath79_reset
->rcdev
.of_reset_n_cells
= 1;
97 ath79_reset
->rcdev
.nr_resets
= 32;
99 return reset_controller_register(&ath79_reset
->rcdev
);
102 static int ath79_reset_remove(struct platform_device
*pdev
)
104 struct ath79_reset
*ath79_reset
= platform_get_drvdata(pdev
);
106 reset_controller_unregister(&ath79_reset
->rcdev
);
111 static const struct of_device_id ath79_reset_dt_ids
[] = {
112 { .compatible
= "qca,ar7100-reset", },
115 MODULE_DEVICE_TABLE(of
, ath79_reset_dt_ids
);
117 static struct platform_driver ath79_reset_driver
= {
118 .probe
= ath79_reset_probe
,
119 .remove
= ath79_reset_remove
,
121 .name
= "ath79-reset",
122 .of_match_table
= ath79_reset_dt_ids
,
125 module_platform_driver(ath79_reset_driver
);
127 MODULE_AUTHOR("Alban Bedel <albeu@free.fr>");
128 MODULE_DESCRIPTION("AR71xx Reset Controller Driver");
129 MODULE_LICENSE("GPL");