1 // SPDX-License-Identifier: GPL-2.0
3 * Zynq UltraScale+ MPSoC mux
5 * Copyright (C) 2016-2018 Xilinx
8 #include <linux/clk-provider.h>
9 #include <linux/slab.h>
10 #include "clk-zynqmp.h"
13 * DOC: basic adjustable multiplexer clock that cannot gate
15 * Traits of this clock:
16 * prepare - clk_prepare only ensures that parents are prepared
17 * enable - clk_enable only ensures that parents are enabled
18 * rate - rate is only affected by parent switching. No clk_set_rate support
19 * parent - parent is adjustable through clk_set_parent
23 * struct zynqmp_clk_mux - multiplexer clock
25 * @hw: handle between common and hardware-specific interfaces
26 * @flags: hardware-specific flags
27 * @clk_id: Id of clock
29 struct zynqmp_clk_mux
{
35 #define to_zynqmp_clk_mux(_hw) container_of(_hw, struct zynqmp_clk_mux, hw)
38 * zynqmp_clk_mux_get_parent() - Get parent of clock
39 * @hw: handle between common and hardware-specific interfaces
41 * Return: Parent index
43 static u8
zynqmp_clk_mux_get_parent(struct clk_hw
*hw
)
45 struct zynqmp_clk_mux
*mux
= to_zynqmp_clk_mux(hw
);
46 const char *clk_name
= clk_hw_get_name(hw
);
47 u32 clk_id
= mux
->clk_id
;
50 const struct zynqmp_eemi_ops
*eemi_ops
= zynqmp_pm_get_eemi_ops();
52 ret
= eemi_ops
->clock_getparent(clk_id
, &val
);
55 pr_warn_once("%s() getparent failed for clock: %s, ret = %d\n",
56 __func__
, clk_name
, ret
);
62 * zynqmp_clk_mux_set_parent() - Set parent of clock
63 * @hw: handle between common and hardware-specific interfaces
64 * @index: Parent index
66 * Return: 0 on success else error+reason
68 static int zynqmp_clk_mux_set_parent(struct clk_hw
*hw
, u8 index
)
70 struct zynqmp_clk_mux
*mux
= to_zynqmp_clk_mux(hw
);
71 const char *clk_name
= clk_hw_get_name(hw
);
72 u32 clk_id
= mux
->clk_id
;
74 const struct zynqmp_eemi_ops
*eemi_ops
= zynqmp_pm_get_eemi_ops();
76 ret
= eemi_ops
->clock_setparent(clk_id
, index
);
79 pr_warn_once("%s() set parent failed for clock: %s, ret = %d\n",
80 __func__
, clk_name
, ret
);
85 static const struct clk_ops zynqmp_clk_mux_ops
= {
86 .get_parent
= zynqmp_clk_mux_get_parent
,
87 .set_parent
= zynqmp_clk_mux_set_parent
,
88 .determine_rate
= __clk_mux_determine_rate
,
91 static const struct clk_ops zynqmp_clk_mux_ro_ops
= {
92 .get_parent
= zynqmp_clk_mux_get_parent
,
96 * zynqmp_clk_register_mux() - Register a mux table with the clock
98 * @name: Name of this clock
99 * @clk_id: Id of this clock
100 * @parents: Name of this clock's parents
101 * @num_parents: Number of parents
102 * @nodes: Clock topology node
104 * Return: clock hardware of the registered clock mux
106 struct clk_hw
*zynqmp_clk_register_mux(const char *name
, u32 clk_id
,
107 const char * const *parents
,
109 const struct clock_topology
*nodes
)
111 struct zynqmp_clk_mux
*mux
;
113 struct clk_init_data init
;
116 mux
= kzalloc(sizeof(*mux
), GFP_KERNEL
);
118 return ERR_PTR(-ENOMEM
);
121 if (nodes
->type_flag
& CLK_MUX_READ_ONLY
)
122 init
.ops
= &zynqmp_clk_mux_ro_ops
;
124 init
.ops
= &zynqmp_clk_mux_ops
;
125 init
.flags
= nodes
->flag
;
126 init
.parent_names
= parents
;
127 init
.num_parents
= num_parents
;
128 mux
->flags
= nodes
->type_flag
;
129 mux
->hw
.init
= &init
;
130 mux
->clk_id
= clk_id
;
133 ret
= clk_hw_register(NULL
, hw
);