Commit | Line | Data |
---|---|---|
2874c5fd | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
8f1ae77f MR |
2 | /* |
3 | * Allwinner SoCs Reset Controller driver | |
4 | * | |
5 | * Copyright 2013 Maxime Ripard | |
6 | * | |
7 | * Maxime Ripard <maxime.ripard@free-electrons.com> | |
8f1ae77f MR |
8 | */ |
9 | ||
10 | #include <linux/err.h> | |
11 | #include <linux/io.h> | |
c4742ed3 | 12 | #include <linux/init.h> |
8f1ae77f MR |
13 | #include <linux/of.h> |
14 | #include <linux/of_address.h> | |
15 | #include <linux/platform_device.h> | |
16 | #include <linux/reset-controller.h> | |
fdce6078 | 17 | #include <linux/reset/sunxi.h> |
8f1ae77f MR |
18 | #include <linux/slab.h> |
19 | #include <linux/spinlock.h> | |
20 | #include <linux/types.h> | |
21 | ||
e13c205a | 22 | #include "reset-simple.h" |
8f1ae77f MR |
23 | |
24 | static int sunxi_reset_init(struct device_node *np) | |
25 | { | |
e13c205a | 26 | struct reset_simple_data *data; |
8f1ae77f MR |
27 | struct resource res; |
28 | resource_size_t size; | |
29 | int ret; | |
30 | ||
31 | data = kzalloc(sizeof(*data), GFP_KERNEL); | |
32 | if (!data) | |
33 | return -ENOMEM; | |
34 | ||
35 | ret = of_address_to_resource(np, 0, &res); | |
36 | if (ret) | |
37 | goto err_alloc; | |
38 | ||
39 | size = resource_size(&res); | |
40 | if (!request_mem_region(res.start, size, np->name)) { | |
41 | ret = -EBUSY; | |
42 | goto err_alloc; | |
43 | } | |
44 | ||
45 | data->membase = ioremap(res.start, size); | |
46 | if (!data->membase) { | |
47 | ret = -ENOMEM; | |
48 | goto err_alloc; | |
49 | } | |
50 | ||
41544f9f TB |
51 | spin_lock_init(&data->lock); |
52 | ||
8f1ae77f | 53 | data->rcdev.owner = THIS_MODULE; |
726cc791 | 54 | data->rcdev.nr_resets = size * 8; |
e13c205a | 55 | data->rcdev.ops = &reset_simple_ops; |
8f1ae77f | 56 | data->rcdev.of_node = np; |
e13c205a | 57 | data->active_low = true; |
8f1ae77f | 58 | |
d1f15aa0 | 59 | return reset_controller_register(&data->rcdev); |
8f1ae77f MR |
60 | |
61 | err_alloc: | |
62 | kfree(data); | |
63 | return ret; | |
64 | }; | |
65 | ||
66 | /* | |
67 | * These are the reset controller we need to initialize early on in | |
68 | * our system, before we can even think of using a regular device | |
69 | * driver for it. | |
e13c205a PZ |
70 | * The controllers that we can register through the regular device |
71 | * model are handled by the simple reset driver directly. | |
8f1ae77f | 72 | */ |
fddad17e | 73 | static const struct of_device_id sunxi_early_reset_dt_ids[] __initconst = { |
8f1ae77f MR |
74 | { .compatible = "allwinner,sun6i-a31-ahb1-reset", }, |
75 | { /* sentinel */ }, | |
76 | }; | |
77 | ||
78 | void __init sun6i_reset_init(void) | |
79 | { | |
80 | struct device_node *np; | |
81 | ||
82 | for_each_matching_node(np, sunxi_early_reset_dt_ids) | |
83 | sunxi_reset_init(np); | |
84 | } |