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