Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 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> |
Paul Gortmaker | c4742ed | 2016-06-13 14:03:36 -0400 | [diff] [blame] | 16 | #include <linux/init.h> |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 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> |
| 24 | |
Philipp Zabel | e13c205 | 2017-08-11 12:58:43 +0200 | [diff] [blame] | 25 | #include "reset-simple.h" |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 26 | |
| 27 | static int sunxi_reset_init(struct device_node *np) |
| 28 | { |
Philipp Zabel | e13c205 | 2017-08-11 12:58:43 +0200 | [diff] [blame] | 29 | struct reset_simple_data *data; |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 30 | struct resource res; |
| 31 | resource_size_t size; |
| 32 | int ret; |
| 33 | |
| 34 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 35 | if (!data) |
| 36 | return -ENOMEM; |
| 37 | |
| 38 | ret = of_address_to_resource(np, 0, &res); |
| 39 | if (ret) |
| 40 | goto err_alloc; |
| 41 | |
| 42 | size = resource_size(&res); |
| 43 | if (!request_mem_region(res.start, size, np->name)) { |
| 44 | ret = -EBUSY; |
| 45 | goto err_alloc; |
| 46 | } |
| 47 | |
| 48 | data->membase = ioremap(res.start, size); |
| 49 | if (!data->membase) { |
| 50 | ret = -ENOMEM; |
| 51 | goto err_alloc; |
| 52 | } |
| 53 | |
Tyler Baker | 41544f9 | 2015-01-12 07:54:46 -0800 | [diff] [blame] | 54 | spin_lock_init(&data->lock); |
| 55 | |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 56 | data->rcdev.owner = THIS_MODULE; |
Philipp Zabel | 726cc79 | 2017-08-11 12:33:57 +0200 | [diff] [blame] | 57 | data->rcdev.nr_resets = size * 8; |
Philipp Zabel | e13c205 | 2017-08-11 12:58:43 +0200 | [diff] [blame] | 58 | data->rcdev.ops = &reset_simple_ops; |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 59 | data->rcdev.of_node = np; |
Philipp Zabel | e13c205 | 2017-08-11 12:58:43 +0200 | [diff] [blame] | 60 | data->active_low = true; |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 61 | |
Masahiro Yamada | d1f15aa | 2015-11-05 14:54:56 +0900 | [diff] [blame] | 62 | return reset_controller_register(&data->rcdev); |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 63 | |
| 64 | err_alloc: |
| 65 | kfree(data); |
| 66 | return ret; |
| 67 | }; |
| 68 | |
| 69 | /* |
| 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. |
Philipp Zabel | e13c205 | 2017-08-11 12:58:43 +0200 | [diff] [blame] | 73 | * The controllers that we can register through the regular device |
| 74 | * model are handled by the simple reset driver directly. |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 75 | */ |
Philipp Zabel | fddad17 | 2015-10-29 09:59:34 +0100 | [diff] [blame] | 76 | static const struct of_device_id sunxi_early_reset_dt_ids[] __initconst = { |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 77 | { .compatible = "allwinner,sun6i-a31-ahb1-reset", }, |
| 78 | { /* sentinel */ }, |
| 79 | }; |
| 80 | |
| 81 | void __init sun6i_reset_init(void) |
| 82 | { |
| 83 | struct device_node *np; |
| 84 | |
| 85 | for_each_matching_node(np, sunxi_early_reset_dt_ids) |
| 86 | sunxi_reset_init(np); |
| 87 | } |