Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * TI Fixed Factor Clock
4 *
5 * Copyright (C) 2013 Texas Instruments, Inc.
6 *
7 * Tero Kristo <t-kristo@ti.com>
8 */
9
10#include <linux/clk-provider.h>
11#include <linux/slab.h>
12#include <linux/err.h>
13#include <linux/of.h>
14#include <linux/of_address.h>
15#include <linux/clk/ti.h>
16
17#include "clock.h"
18
19#undef pr_fmt
20#define pr_fmt(fmt) "%s: " fmt, __func__
21
22/**
23 * of_ti_fixed_factor_clk_setup - Setup function for TI fixed factor clock
24 * @node: device node for this clock
25 *
26 * Sets up a simple fixed factor clock based on device tree info.
27 */
28static void __init of_ti_fixed_factor_clk_setup(struct device_node *node)
29{
30 struct clk *clk;
31 const char *clk_name = ti_dt_clk_name(node);
32 const char *parent_name;
33 u32 div, mult;
34 u32 flags = 0;
35
36 if (of_property_read_u32(node, "ti,clock-div", &div)) {
37 pr_err("%pOFn must have a clock-div property\n", node);
38 return;
39 }
40
41 if (of_property_read_u32(node, "ti,clock-mult", &mult)) {
42 pr_err("%pOFn must have a clock-mult property\n", node);
43 return;
44 }
45
46 if (of_property_read_bool(node, "ti,set-rate-parent"))
47 flags |= CLK_SET_RATE_PARENT;
48
49 parent_name = of_clk_get_parent_name(node, 0);
50
51 clk = clk_register_fixed_factor(NULL, clk_name, parent_name, flags,
52 mult, div);
53
54 if (!IS_ERR(clk)) {
55 of_clk_add_provider(node, of_clk_src_simple_get, clk);
56 of_ti_clk_autoidle_setup(node);
57 ti_clk_add_alias(clk, clk_name);
58 }
59}
60CLK_OF_DECLARE(ti_fixed_factor_clk, "ti,fixed-factor-clock",
61 of_ti_fixed_factor_clk_setup);
1/*
2 * TI Fixed Factor Clock
3 *
4 * Copyright (C) 2013 Texas Instruments, Inc.
5 *
6 * Tero Kristo <t-kristo@ti.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 version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <linux/clk-provider.h>
19#include <linux/slab.h>
20#include <linux/err.h>
21#include <linux/of.h>
22#include <linux/of_address.h>
23#include <linux/clk/ti.h>
24
25#undef pr_fmt
26#define pr_fmt(fmt) "%s: " fmt, __func__
27
28/**
29 * of_ti_fixed_factor_clk_setup - Setup function for TI fixed factor clock
30 * @node: device node for this clock
31 *
32 * Sets up a simple fixed factor clock based on device tree info.
33 */
34static void __init of_ti_fixed_factor_clk_setup(struct device_node *node)
35{
36 struct clk *clk;
37 const char *clk_name = node->name;
38 const char *parent_name;
39 u32 div, mult;
40 u32 flags = 0;
41
42 if (of_property_read_u32(node, "ti,clock-div", &div)) {
43 pr_err("%s must have a clock-div property\n", node->name);
44 return;
45 }
46
47 if (of_property_read_u32(node, "ti,clock-mult", &mult)) {
48 pr_err("%s must have a clock-mult property\n", node->name);
49 return;
50 }
51
52 if (of_property_read_bool(node, "ti,set-rate-parent"))
53 flags |= CLK_SET_RATE_PARENT;
54
55 parent_name = of_clk_get_parent_name(node, 0);
56
57 clk = clk_register_fixed_factor(NULL, clk_name, parent_name, flags,
58 mult, div);
59
60 if (!IS_ERR(clk)) {
61 of_clk_add_provider(node, of_clk_src_simple_get, clk);
62 of_ti_clk_autoidle_setup(node);
63 }
64}
65CLK_OF_DECLARE(ti_fixed_factor_clk, "ti,fixed-factor-clock",
66 of_ti_fixed_factor_clk_setup);