aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clk/clk.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/clk/clk.c')
-rw-r--r--drivers/clk/clk.c56
1 files changed, 34 insertions, 22 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index a004769528e6..2cf2ea6b77a1 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1080,13 +1080,16 @@ unsigned long clk_get_rate(struct clk *clk)
1080} 1080}
1081EXPORT_SYMBOL_GPL(clk_get_rate); 1081EXPORT_SYMBOL_GPL(clk_get_rate);
1082 1082
1083static u8 clk_fetch_parent_index(struct clk *clk, struct clk *parent) 1083static int clk_fetch_parent_index(struct clk *clk, struct clk *parent)
1084{ 1084{
1085 u8 i; 1085 int i;
1086 1086
1087 if (!clk->parents) 1087 if (!clk->parents) {
1088 clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents), 1088 clk->parents = kcalloc(clk->num_parents,
1089 GFP_KERNEL); 1089 sizeof(struct clk *), GFP_KERNEL);
1090 if (!clk->parents)
1091 return -ENOMEM;
1092 }
1090 1093
1091 /* 1094 /*
1092 * find index of new parent clock using cached parent ptrs, 1095 * find index of new parent clock using cached parent ptrs,
@@ -1094,16 +1097,19 @@ static u8 clk_fetch_parent_index(struct clk *clk, struct clk *parent)
1094 * them now to avoid future calls to __clk_lookup. 1097 * them now to avoid future calls to __clk_lookup.
1095 */ 1098 */
1096 for (i = 0; i < clk->num_parents; i++) { 1099 for (i = 0; i < clk->num_parents; i++) {
1097 if (clk->parents && clk->parents[i] == parent) 1100 if (clk->parents[i] == parent)
1098 break; 1101 return i;
1099 else if (!strcmp(clk->parent_names[i], parent->name)) { 1102
1100 if (clk->parents) 1103 if (clk->parents[i])
1101 clk->parents[i] = __clk_lookup(parent->name); 1104 continue;
1102 break; 1105
1106 if (!strcmp(clk->parent_names[i], parent->name)) {
1107 clk->parents[i] = __clk_lookup(parent->name);
1108 return i;
1103 } 1109 }
1104 } 1110 }
1105 1111
1106 return i; 1112 return -EINVAL;
1107} 1113}
1108 1114
1109static void clk_reparent(struct clk *clk, struct clk *new_parent) 1115static void clk_reparent(struct clk *clk, struct clk *new_parent)
@@ -1265,7 +1271,7 @@ static struct clk *clk_calc_new_rates(struct clk *clk, unsigned long rate)
1265 struct clk *old_parent, *parent; 1271 struct clk *old_parent, *parent;
1266 unsigned long best_parent_rate = 0; 1272 unsigned long best_parent_rate = 0;
1267 unsigned long new_rate; 1273 unsigned long new_rate;
1268 u8 p_index = 0; 1274 int p_index = 0;
1269 1275
1270 /* sanity */ 1276 /* sanity */
1271 if (IS_ERR_OR_NULL(clk)) 1277 if (IS_ERR_OR_NULL(clk))
@@ -1306,7 +1312,7 @@ static struct clk *clk_calc_new_rates(struct clk *clk, unsigned long rate)
1306 /* try finding the new parent index */ 1312 /* try finding the new parent index */
1307 if (parent) { 1313 if (parent) {
1308 p_index = clk_fetch_parent_index(clk, parent); 1314 p_index = clk_fetch_parent_index(clk, parent);
1309 if (p_index == clk->num_parents) { 1315 if (p_index < 0) {
1310 pr_debug("%s: clk %s can not be parent of clk %s\n", 1316 pr_debug("%s: clk %s can not be parent of clk %s\n",
1311 __func__, parent->name, clk->name); 1317 __func__, parent->name, clk->name);
1312 return NULL; 1318 return NULL;
@@ -1532,7 +1538,7 @@ static struct clk *__clk_init_parent(struct clk *clk)
1532 1538
1533 if (!clk->parents) 1539 if (!clk->parents)
1534 clk->parents = 1540 clk->parents =
1535 kzalloc((sizeof(struct clk*) * clk->num_parents), 1541 kcalloc(clk->num_parents, sizeof(struct clk *),
1536 GFP_KERNEL); 1542 GFP_KERNEL);
1537 1543
1538 ret = clk_get_parent_by_index(clk, index); 1544 ret = clk_get_parent_by_index(clk, index);
@@ -1568,7 +1574,7 @@ void __clk_reparent(struct clk *clk, struct clk *new_parent)
1568int clk_set_parent(struct clk *clk, struct clk *parent) 1574int clk_set_parent(struct clk *clk, struct clk *parent)
1569{ 1575{
1570 int ret = 0; 1576 int ret = 0;
1571 u8 p_index = 0; 1577 int p_index = 0;
1572 unsigned long p_rate = 0; 1578 unsigned long p_rate = 0;
1573 1579
1574 if (!clk) 1580 if (!clk)
@@ -1597,10 +1603,10 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
1597 if (parent) { 1603 if (parent) {
1598 p_index = clk_fetch_parent_index(clk, parent); 1604 p_index = clk_fetch_parent_index(clk, parent);
1599 p_rate = parent->rate; 1605 p_rate = parent->rate;
1600 if (p_index == clk->num_parents) { 1606 if (p_index < 0) {
1601 pr_debug("%s: clk %s can not be parent of clk %s\n", 1607 pr_debug("%s: clk %s can not be parent of clk %s\n",
1602 __func__, parent->name, clk->name); 1608 __func__, parent->name, clk->name);
1603 ret = -EINVAL; 1609 ret = p_index;
1604 goto out; 1610 goto out;
1605 } 1611 }
1606 } 1612 }
@@ -1689,8 +1695,8 @@ int __clk_init(struct device *dev, struct clk *clk)
1689 * for clock drivers to statically initialize clk->parents. 1695 * for clock drivers to statically initialize clk->parents.
1690 */ 1696 */
1691 if (clk->num_parents > 1 && !clk->parents) { 1697 if (clk->num_parents > 1 && !clk->parents) {
1692 clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents), 1698 clk->parents = kcalloc(clk->num_parents, sizeof(struct clk *),
1693 GFP_KERNEL); 1699 GFP_KERNEL);
1694 /* 1700 /*
1695 * __clk_lookup returns NULL for parents that have not been 1701 * __clk_lookup returns NULL for parents that have not been
1696 * clk_init'd; thus any access to clk->parents[] must check 1702 * clk_init'd; thus any access to clk->parents[] must check
@@ -1830,8 +1836,8 @@ static int _clk_register(struct device *dev, struct clk_hw *hw, struct clk *clk)
1830 hw->clk = clk; 1836 hw->clk = clk;
1831 1837
1832 /* allocate local copy in case parent_names is __initdata */ 1838 /* allocate local copy in case parent_names is __initdata */
1833 clk->parent_names = kzalloc((sizeof(char*) * clk->num_parents), 1839 clk->parent_names = kcalloc(clk->num_parents, sizeof(char *),
1834 GFP_KERNEL); 1840 GFP_KERNEL);
1835 1841
1836 if (!clk->parent_names) { 1842 if (!clk->parent_names) {
1837 pr_err("%s: could not allocate clk->parent_names\n", __func__); 1843 pr_err("%s: could not allocate clk->parent_names\n", __func__);
@@ -2196,6 +2202,12 @@ struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
2196 return clk; 2202 return clk;
2197} 2203}
2198 2204
2205int of_clk_get_parent_count(struct device_node *np)
2206{
2207 return of_count_phandle_with_args(np, "clocks", "#clock-cells");
2208}
2209EXPORT_SYMBOL_GPL(of_clk_get_parent_count);
2210
2199const char *of_clk_get_parent_name(struct device_node *np, int index) 2211const char *of_clk_get_parent_name(struct device_node *np, int index)
2200{ 2212{
2201 struct of_phandle_args clkspec; 2213 struct of_phandle_args clkspec;