1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014 Chen-Yu Tsai
4 * Author: Chen-Yu Tsai <wens@csie.org>
6 * Allwinner A23 APB0 clock driver
8 * Based on clk-sun6i-apb0.c
9 * Allwinner A31 APB0 clock driver
11 * Copyright (C) 2014 Free Electrons
12 * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
15 #include <linux/clk-provider.h>
16 #include <linux/init.h>
19 #include <linux/of_address.h>
20 #include <linux/platform_device.h>
22 static struct clk
*sun8i_a23_apb0_register(struct device_node
*node
,
25 const char *clk_name
= node
->name
;
26 const char *clk_parent
;
30 clk_parent
= of_clk_get_parent_name(node
, 0);
32 return ERR_PTR(-EINVAL
);
34 of_property_read_string(node
, "clock-output-names", &clk_name
);
36 /* The A23 APB0 clock is a standard 2 bit wide divider clock */
37 clk
= clk_register_divider(NULL
, clk_name
, clk_parent
, 0, reg
,
42 ret
= of_clk_add_provider(node
, of_clk_src_simple_get
, clk
);
49 clk_unregister_divider(clk
);
54 static void sun8i_a23_apb0_setup(struct device_node
*node
)
60 reg
= of_io_request_and_map(node
, 0, of_node_full_name(node
));
63 * This happens with clk nodes instantiated through mfd,
64 * as those do not have their resources assigned in the
65 * device tree. Do not print an error in this case.
67 if (PTR_ERR(reg
) != -EINVAL
)
68 pr_err("Could not get registers for a23-apb0-clk\n");
73 clk
= sun8i_a23_apb0_register(node
, reg
);
81 of_address_to_resource(node
, 0, &res
);
82 release_mem_region(res
.start
, resource_size(&res
));
84 CLK_OF_DECLARE_DRIVER(sun8i_a23_apb0
, "allwinner,sun8i-a23-apb0-clk",
85 sun8i_a23_apb0_setup
);
87 static int sun8i_a23_apb0_clk_probe(struct platform_device
*pdev
)
89 struct device_node
*np
= pdev
->dev
.of_node
;
94 r
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
95 reg
= devm_ioremap_resource(&pdev
->dev
, r
);
99 clk
= sun8i_a23_apb0_register(np
, reg
);
100 return PTR_ERR_OR_ZERO(clk
);
103 static const struct of_device_id sun8i_a23_apb0_clk_dt_ids
[] = {
104 { .compatible
= "allwinner,sun8i-a23-apb0-clk" },
108 static struct platform_driver sun8i_a23_apb0_clk_driver
= {
110 .name
= "sun8i-a23-apb0-clk",
111 .of_match_table
= sun8i_a23_apb0_clk_dt_ids
,
113 .probe
= sun8i_a23_apb0_clk_probe
,
115 builtin_platform_driver(sun8i_a23_apb0_clk_driver
);