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