1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * clkgen-mux.c: ST GEN-MUX Clock driver
5 * Copyright (C) 2014 STMicroelectronics (R&D) Limited
7 * Authors: Stephen Gallimore <stephen.gallimore@st.com>
8 * Pankaj Dev <pankaj.dev@st.com>
11 #include <linux/slab.h>
13 #include <linux/of_address.h>
14 #include <linux/clk.h>
15 #include <linux/clk-provider.h>
18 static const char ** __init
clkgen_mux_get_parents(struct device_node
*np
,
22 unsigned int nparents
;
24 nparents
= of_clk_get_parent_count(np
);
25 if (WARN_ON(!nparents
))
26 return ERR_PTR(-EINVAL
);
28 parents
= kcalloc(nparents
, sizeof(const char *), GFP_KERNEL
);
30 return ERR_PTR(-ENOMEM
);
32 *num_parents
= of_clk_parent_fill(np
, parents
, nparents
);
36 struct clkgen_mux_data
{
41 unsigned long clk_flags
;
45 static struct clkgen_mux_data stih407_a9_mux_data
= {
49 .lock
= &clkgen_a9_lock
,
52 static void __init
st_of_clkgen_mux_setup(struct device_node
*np
,
53 struct clkgen_mux_data
*data
)
60 reg
= of_iomap(np
, 0);
62 pr_err("%s: Failed to get base address\n", __func__
);
66 parents
= clkgen_mux_get_parents(np
, &num_parents
);
67 if (IS_ERR(parents
)) {
68 pr_err("%s: Failed to get parents (%ld)\n",
69 __func__
, PTR_ERR(parents
));
73 clk
= clk_register_mux(NULL
, np
->name
, parents
, num_parents
,
74 data
->clk_flags
| CLK_SET_RATE_PARENT
,
76 data
->shift
, data
->width
, data
->mux_flags
,
81 pr_debug("%s: parent %s rate %u\n",
83 __clk_get_name(clk_get_parent(clk
)),
84 (unsigned int)clk_get_rate(clk
));
87 of_clk_add_provider(np
, of_clk_src_simple_get
, clk
);
96 static void __init
st_of_clkgen_a9_mux_setup(struct device_node
*np
)
98 st_of_clkgen_mux_setup(np
, &stih407_a9_mux_data
);
100 CLK_OF_DECLARE(clkgen_a9mux
, "st,stih407-clkgen-a9-mux",
101 st_of_clkgen_a9_mux_setup
);