Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Allwinner SoCs Reset Controller driver |
| 4 | * |
| 5 | * Copyright 2013 Maxime Ripard |
| 6 | * |
| 7 | * Maxime Ripard <maxime.ripard@free-electrons.com> |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/err.h> |
| 11 | #include <linux/io.h> |
Paul Gortmaker | c4742ed | 2016-06-13 14:03:36 -0400 | [diff] [blame] | 12 | #include <linux/init.h> |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 13 | #include <linux/of.h> |
| 14 | #include <linux/of_address.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/reset-controller.h> |
Maxime Ripard | 9357b046 | 2020-05-27 17:47:31 +0200 | [diff] [blame] | 17 | #include <linux/reset/reset-simple.h> |
Philipp Zabel | fdce6078 | 2018-12-13 12:22:32 +0100 | [diff] [blame] | 18 | #include <linux/reset/sunxi.h> |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 19 | #include <linux/slab.h> |
| 20 | #include <linux/spinlock.h> |
| 21 | #include <linux/types.h> |
| 22 | |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 23 | static int sunxi_reset_init(struct device_node *np) |
| 24 | { |
Philipp Zabel | e13c205 | 2017-08-11 12:58:43 +0200 | [diff] [blame] | 25 | struct reset_simple_data *data; |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 26 | struct resource res; |
| 27 | resource_size_t size; |
| 28 | int ret; |
| 29 | |
| 30 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 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_alloc; |
| 48 | } |
| 49 | |
Tyler Baker | 41544f9 | 2015-01-12 07:54:46 -0800 | [diff] [blame] | 50 | spin_lock_init(&data->lock); |
| 51 | |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 52 | data->rcdev.owner = THIS_MODULE; |
Philipp Zabel | 726cc79 | 2017-08-11 12:33:57 +0200 | [diff] [blame] | 53 | data->rcdev.nr_resets = size * 8; |
Philipp Zabel | e13c205 | 2017-08-11 12:58:43 +0200 | [diff] [blame] | 54 | data->rcdev.ops = &reset_simple_ops; |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 55 | data->rcdev.of_node = np; |
Philipp Zabel | e13c205 | 2017-08-11 12:58:43 +0200 | [diff] [blame] | 56 | data->active_low = true; |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 57 | |
Masahiro Yamada | d1f15aa | 2015-11-05 14:54:56 +0900 | [diff] [blame] | 58 | return reset_controller_register(&data->rcdev); |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 59 | |
| 60 | err_alloc: |
| 61 | kfree(data); |
| 62 | return ret; |
| 63 | }; |
| 64 | |
| 65 | /* |
| 66 | * These are the reset controller we need to initialize early on in |
| 67 | * our system, before we can even think of using a regular device |
| 68 | * driver for it. |
Philipp Zabel | e13c205 | 2017-08-11 12:58:43 +0200 | [diff] [blame] | 69 | * The controllers that we can register through the regular device |
| 70 | * model are handled by the simple reset driver directly. |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 71 | */ |
Philipp Zabel | fddad17 | 2015-10-29 09:59:34 +0100 | [diff] [blame] | 72 | static const struct of_device_id sunxi_early_reset_dt_ids[] __initconst = { |
Maxime Ripard | 8f1ae77 | 2013-09-24 11:07:43 +0300 | [diff] [blame] | 73 | { .compatible = "allwinner,sun6i-a31-ahb1-reset", }, |
| 74 | { /* sentinel */ }, |
| 75 | }; |
| 76 | |
| 77 | void __init sun6i_reset_init(void) |
| 78 | { |
| 79 | struct device_node *np; |
| 80 | |
| 81 | for_each_matching_node(np, sunxi_early_reset_dt_ids) |
| 82 | sunxi_reset_init(np); |
| 83 | } |