Merge tag 'riscv-for-linus-4.15-rc2_cleanups' of git://git.kernel.org/pub/scm/linux...
[linux/fpc-iii.git] / drivers / reset / reset-sunxi.c
blobdb9a1a75523f420b7bab02d6c11e44159d2be194
1 /*
2 * Allwinner SoCs Reset Controller driver
4 * Copyright 2013 Maxime Ripard
6 * Maxime Ripard <maxime.ripard@free-electrons.com>
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.
14 #include <linux/err.h>
15 #include <linux/io.h>
16 #include <linux/init.h>
17 #include <linux/of.h>
18 #include <linux/of_address.h>
19 #include <linux/platform_device.h>
20 #include <linux/reset-controller.h>
21 #include <linux/slab.h>
22 #include <linux/spinlock.h>
23 #include <linux/types.h>
25 #include "reset-simple.h"
27 static int sunxi_reset_init(struct device_node *np)
29 struct reset_simple_data *data;
30 struct resource res;
31 resource_size_t size;
32 int ret;
34 data = kzalloc(sizeof(*data), GFP_KERNEL);
35 if (!data)
36 return -ENOMEM;
38 ret = of_address_to_resource(np, 0, &res);
39 if (ret)
40 goto err_alloc;
42 size = resource_size(&res);
43 if (!request_mem_region(res.start, size, np->name)) {
44 ret = -EBUSY;
45 goto err_alloc;
48 data->membase = ioremap(res.start, size);
49 if (!data->membase) {
50 ret = -ENOMEM;
51 goto err_alloc;
54 spin_lock_init(&data->lock);
56 data->rcdev.owner = THIS_MODULE;
57 data->rcdev.nr_resets = size * 8;
58 data->rcdev.ops = &reset_simple_ops;
59 data->rcdev.of_node = np;
60 data->active_low = true;
62 return reset_controller_register(&data->rcdev);
64 err_alloc:
65 kfree(data);
66 return ret;
70 * These are the reset controller we need to initialize early on in
71 * our system, before we can even think of using a regular device
72 * driver for it.
73 * The controllers that we can register through the regular device
74 * model are handled by the simple reset driver directly.
76 static const struct of_device_id sunxi_early_reset_dt_ids[] __initconst = {
77 { .compatible = "allwinner,sun6i-a31-ahb1-reset", },
78 { /* sentinel */ },
81 void __init sun6i_reset_init(void)
83 struct device_node *np;
85 for_each_matching_node(np, sunxi_early_reset_dt_ids)
86 sunxi_reset_init(np);