2 * clkgen-mux.c: ST GEN-MUX Clock driver
4 * Copyright (C) 2014 STMicroelectronics (R&D) Limited
6 * Authors: Stephen Gallimore <stephen.gallimore@st.com>
7 * Pankaj Dev <pankaj.dev@st.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
16 #include <linux/slab.h>
17 #include <linux/of_address.h>
18 #include <linux/clk.h>
19 #include <linux/clk-provider.h>
22 static const char ** __init
clkgen_mux_get_parents(struct device_node
*np
,
26 unsigned int nparents
;
28 nparents
= of_clk_get_parent_count(np
);
29 if (WARN_ON(!nparents
))
30 return ERR_PTR(-EINVAL
);
32 parents
= kcalloc(nparents
, sizeof(const char *), GFP_KERNEL
);
34 return ERR_PTR(-ENOMEM
);
36 *num_parents
= of_clk_parent_fill(np
, parents
, nparents
);
40 struct clkgen_mux_data
{
45 unsigned long clk_flags
;
49 static struct clkgen_mux_data stih407_a9_mux_data
= {
53 .lock
= &clkgen_a9_lock
,
56 static void __init
st_of_clkgen_mux_setup(struct device_node
*np
,
57 struct clkgen_mux_data
*data
)
64 reg
= of_iomap(np
, 0);
66 pr_err("%s: Failed to get base address\n", __func__
);
70 parents
= clkgen_mux_get_parents(np
, &num_parents
);
71 if (IS_ERR(parents
)) {
72 pr_err("%s: Failed to get parents (%ld)\n",
73 __func__
, PTR_ERR(parents
));
77 clk
= clk_register_mux(NULL
, np
->name
, parents
, num_parents
,
78 data
->clk_flags
| CLK_SET_RATE_PARENT
,
80 data
->shift
, data
->width
, data
->mux_flags
,
85 pr_debug("%s: parent %s rate %u\n",
87 __clk_get_name(clk_get_parent(clk
)),
88 (unsigned int)clk_get_rate(clk
));
91 of_clk_add_provider(np
, of_clk_src_simple_get
, clk
);
100 static void __init
st_of_clkgen_a9_mux_setup(struct device_node
*np
)
102 st_of_clkgen_mux_setup(np
, &stih407_a9_mux_data
);
104 CLK_OF_DECLARE(clkgen_a9mux
, "st,stih407-clkgen-a9-mux",
105 st_of_clkgen_a9_mux_setup
);