Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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