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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2014 Chen-Yu Tsai
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Author: Chen-Yu Tsai <wens@csie.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Allwinner A23 APB0 clock driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Based on clk-sun6i-apb0.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Allwinner A31 APB0 clock driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Copyright (C) 2014 Free Electrons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/clk-provider.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static struct clk *sun8i_a23_apb0_register(struct device_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 					   void __iomem *reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	const char *clk_name = node->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	const char *clk_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct clk *clk;
^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) 	clk_parent = of_clk_get_parent_name(node, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (!clk_parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	of_property_read_string(node, "clock-output-names", &clk_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	/* The A23 APB0 clock is a standard 2 bit wide divider clock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	clk = clk_register_divider(NULL, clk_name, clk_parent, 0, reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 				   0, 2, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (IS_ERR(clk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		return clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	ret = of_clk_add_provider(node, of_clk_src_simple_get, clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		goto err_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	return clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) err_unregister:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	clk_unregister_divider(clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static void sun8i_a23_apb0_setup(struct device_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	void __iomem *reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct resource res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (IS_ERR(reg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		 * This happens with clk nodes instantiated through mfd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		 * as those do not have their resources assigned in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		 * device tree. Do not print an error in this case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		if (PTR_ERR(reg) != -EINVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			pr_err("Could not get registers for a23-apb0-clk\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	clk = sun8i_a23_apb0_register(node, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (IS_ERR(clk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		goto err_unmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) err_unmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	iounmap(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	of_address_to_resource(node, 0, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	release_mem_region(res.start, resource_size(&res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) CLK_OF_DECLARE_DRIVER(sun8i_a23_apb0, "allwinner,sun8i-a23-apb0-clk",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		      sun8i_a23_apb0_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static int sun8i_a23_apb0_clk_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct resource *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	void __iomem *reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	reg = devm_ioremap_resource(&pdev->dev, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (IS_ERR(reg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		return PTR_ERR(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	clk = sun8i_a23_apb0_register(np, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return PTR_ERR_OR_ZERO(clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static const struct of_device_id sun8i_a23_apb0_clk_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	{ .compatible = "allwinner,sun8i-a23-apb0-clk" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	{ /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static struct platform_driver sun8i_a23_apb0_clk_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		.name = "sun8i-a23-apb0-clk",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		.of_match_table = sun8i_a23_apb0_clk_dt_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	.probe = sun8i_a23_apb0_clk_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) builtin_platform_driver(sun8i_a23_apb0_clk_driver);