140-clk-qcom-Add-support-for-Krait-clocks.patch 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. Content-Type: text/plain; charset="utf-8"
  2. MIME-Version: 1.0
  3. Content-Transfer-Encoding: 7bit
  4. Subject: [v3,09/13] clk: qcom: Add support for Krait clocks
  5. From: Stephen Boyd <sboyd@codeaurora.org>
  6. X-Patchwork-Id: 6063251
  7. Message-Id: <1426920332-9340-10-git-send-email-sboyd@codeaurora.org>
  8. To: Mike Turquette <mturquette@linaro.org>, Stephen Boyd <sboyd@codeaurora.org>
  9. Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
  10. linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
  11. Viresh Kumar <viresh.kumar@linaro.org>
  12. Date: Fri, 20 Mar 2015 23:45:28 -0700
  13. The Krait clocks are made up of a series of muxes and a divider
  14. that choose between a fixed rate clock and dedicated HFPLLs for
  15. each CPU. Instead of using mmio accesses to remux parents, the
  16. Krait implementation exposes the remux control via cp15
  17. registers. Support these clocks.
  18. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
  19. ---
  20. drivers/clk/qcom/Kconfig | 4 ++
  21. drivers/clk/qcom/Makefile | 1 +
  22. drivers/clk/qcom/clk-krait.c | 166 +++++++++++++++++++++++++++++++++++++++++++
  23. drivers/clk/qcom/clk-krait.h | 49 +++++++++++++
  24. 4 files changed, 220 insertions(+)
  25. create mode 100644 drivers/clk/qcom/clk-krait.c
  26. create mode 100644 drivers/clk/qcom/clk-krait.h
  27. --- a/drivers/clk/qcom/Kconfig
  28. +++ b/drivers/clk/qcom/Kconfig
  29. @@ -143,3 +143,7 @@ config QCOM_HFPLL
  30. Support for the high-frequency PLLs present on Qualcomm devices.
  31. Say Y if you want to support CPU frequency scaling on devices
  32. such as MSM8974, APQ8084, etc.
  33. +
  34. +config KRAIT_CLOCKS
  35. + bool
  36. + select KRAIT_L2_ACCESSORS
  37. --- a/drivers/clk/qcom/Makefile
  38. +++ b/drivers/clk/qcom/Makefile
  39. @@ -8,6 +8,7 @@ clk-qcom-y += clk-rcg2.o
  40. clk-qcom-y += clk-branch.o
  41. clk-qcom-y += clk-regmap-divider.o
  42. clk-qcom-y += clk-regmap-mux.o
  43. +clk-qcom-$(CONFIG_KRAIT_CLOCKS) += clk-krait.o
  44. clk-qcom-y += clk-hfpll.o
  45. clk-qcom-y += reset.o
  46. clk-qcom-$(CONFIG_QCOM_GDSC) += gdsc.o
  47. --- /dev/null
  48. +++ b/drivers/clk/qcom/clk-krait.c
  49. @@ -0,0 +1,167 @@
  50. +/*
  51. + * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  52. + *
  53. + * This program is free software; you can redistribute it and/or modify
  54. + * it under the terms of the GNU General Public License version 2 and
  55. + * only version 2 as published by the Free Software Foundation.
  56. + *
  57. + * This program is distributed in the hope that it will be useful,
  58. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  59. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  60. + * GNU General Public License for more details.
  61. + */
  62. +
  63. +#include <linux/kernel.h>
  64. +#include <linux/module.h>
  65. +#include <linux/init.h>
  66. +#include <linux/io.h>
  67. +#include <linux/delay.h>
  68. +#include <linux/err.h>
  69. +#include <linux/clk-provider.h>
  70. +#include <linux/spinlock.h>
  71. +
  72. +#include <asm/krait-l2-accessors.h>
  73. +
  74. +#include "clk-krait.h"
  75. +
  76. +/* Secondary and primary muxes share the same cp15 register */
  77. +static DEFINE_SPINLOCK(krait_clock_reg_lock);
  78. +
  79. +#define LPL_SHIFT 8
  80. +static void __krait_mux_set_sel(struct krait_mux_clk *mux, int sel)
  81. +{
  82. + unsigned long flags;
  83. + u32 regval;
  84. +
  85. + spin_lock_irqsave(&krait_clock_reg_lock, flags);
  86. + regval = krait_get_l2_indirect_reg(mux->offset);
  87. + regval &= ~(mux->mask << mux->shift);
  88. + regval |= (sel & mux->mask) << mux->shift;
  89. + if (mux->lpl) {
  90. + regval &= ~(mux->mask << (mux->shift + LPL_SHIFT));
  91. + regval |= (sel & mux->mask) << (mux->shift + LPL_SHIFT);
  92. + }
  93. + krait_set_l2_indirect_reg(mux->offset, regval);
  94. + spin_unlock_irqrestore(&krait_clock_reg_lock, flags);
  95. +
  96. + /* Wait for switch to complete. */
  97. + mb();
  98. + udelay(1);
  99. +}
  100. +
  101. +static int krait_mux_set_parent(struct clk_hw *hw, u8 index)
  102. +{
  103. + struct krait_mux_clk *mux = to_krait_mux_clk(hw);
  104. + u32 sel;
  105. +
  106. + sel = clk_mux_reindex(index, mux->parent_map, 0);
  107. + mux->en_mask = sel;
  108. + /* Don't touch mux if CPU is off as it won't work */
  109. + if (__clk_is_enabled(hw->clk))
  110. + __krait_mux_set_sel(mux, sel);
  111. + return 0;
  112. +}
  113. +
  114. +static u8 krait_mux_get_parent(struct clk_hw *hw)
  115. +{
  116. + struct krait_mux_clk *mux = to_krait_mux_clk(hw);
  117. + u32 sel;
  118. +
  119. + sel = krait_get_l2_indirect_reg(mux->offset);
  120. + sel >>= mux->shift;
  121. + sel &= mux->mask;
  122. + mux->en_mask = sel;
  123. +
  124. + return clk_mux_get_parent(hw, sel, mux->parent_map, 0);
  125. +}
  126. +
  127. +static struct clk_hw *krait_mux_get_safe_parent(struct clk_hw *hw,
  128. + unsigned long *safe_freq)
  129. +{
  130. + int i;
  131. + struct krait_mux_clk *mux = to_krait_mux_clk(hw);
  132. + int num_parents = clk_hw_get_num_parents(hw);
  133. +
  134. + i = mux->safe_sel;
  135. + for (i = 0; i < num_parents; i++)
  136. + if (mux->safe_sel == mux->parent_map[i])
  137. + break;
  138. +
  139. + return clk_hw_get_parent_by_index(hw, i);
  140. +}
  141. +
  142. +static int krait_mux_enable(struct clk_hw *hw)
  143. +{
  144. + struct krait_mux_clk *mux = to_krait_mux_clk(hw);
  145. +
  146. + __krait_mux_set_sel(mux, mux->en_mask);
  147. +
  148. + return 0;
  149. +}
  150. +
  151. +static void krait_mux_disable(struct clk_hw *hw)
  152. +{
  153. + struct krait_mux_clk *mux = to_krait_mux_clk(hw);
  154. +
  155. + __krait_mux_set_sel(mux, mux->safe_sel);
  156. +}
  157. +
  158. +const struct clk_ops krait_mux_clk_ops = {
  159. + .enable = krait_mux_enable,
  160. + .disable = krait_mux_disable,
  161. + .set_parent = krait_mux_set_parent,
  162. + .get_parent = krait_mux_get_parent,
  163. + .determine_rate = __clk_mux_determine_rate_closest,
  164. + .get_safe_parent = krait_mux_get_safe_parent,
  165. +};
  166. +EXPORT_SYMBOL_GPL(krait_mux_clk_ops);
  167. +
  168. +/* The divider can divide by 2, 4, 6 and 8. But we only really need div-2. */
  169. +static long krait_div2_round_rate(struct clk_hw *hw, unsigned long rate,
  170. + unsigned long *parent_rate)
  171. +{
  172. + *parent_rate = clk_hw_round_rate(clk_hw_get_parent(hw), rate * 2);
  173. + return DIV_ROUND_UP(*parent_rate, 2);
  174. +}
  175. +
  176. +static int krait_div2_set_rate(struct clk_hw *hw, unsigned long rate,
  177. + unsigned long parent_rate)
  178. +{
  179. + struct krait_div2_clk *d = to_krait_div2_clk(hw);
  180. + unsigned long flags;
  181. + u32 val;
  182. + u32 mask = BIT(d->width) - 1;
  183. +
  184. + if (d->lpl)
  185. + mask = mask << (d->shift + LPL_SHIFT) | mask << d->shift;
  186. +
  187. + spin_lock_irqsave(&krait_clock_reg_lock, flags);
  188. + val = krait_get_l2_indirect_reg(d->offset);
  189. + val &= ~mask;
  190. + krait_set_l2_indirect_reg(d->offset, val);
  191. + spin_unlock_irqrestore(&krait_clock_reg_lock, flags);
  192. +
  193. + return 0;
  194. +}
  195. +
  196. +static unsigned long
  197. +krait_div2_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
  198. +{
  199. + struct krait_div2_clk *d = to_krait_div2_clk(hw);
  200. + u32 mask = BIT(d->width) - 1;
  201. + u32 div;
  202. +
  203. + div = krait_get_l2_indirect_reg(d->offset);
  204. + div >>= d->shift;
  205. + div &= mask;
  206. + div = (div + 1) * 2;
  207. +
  208. + return DIV_ROUND_UP(parent_rate, div);
  209. +}
  210. +
  211. +const struct clk_ops krait_div2_clk_ops = {
  212. + .round_rate = krait_div2_round_rate,
  213. + .set_rate = krait_div2_set_rate,
  214. + .recalc_rate = krait_div2_recalc_rate,
  215. +};
  216. +EXPORT_SYMBOL_GPL(krait_div2_clk_ops);
  217. --- /dev/null
  218. +++ b/drivers/clk/qcom/clk-krait.h
  219. @@ -0,0 +1,49 @@
  220. +/*
  221. + * Copyright (c) 2013, The Linux Foundation. All rights reserved.
  222. + *
  223. + * This program is free software; you can redistribute it and/or modify
  224. + * it under the terms of the GNU General Public License version 2 and
  225. + * only version 2 as published by the Free Software Foundation.
  226. + *
  227. + * This program is distributed in the hope that it will be useful,
  228. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  229. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  230. + * GNU General Public License for more details.
  231. + */
  232. +
  233. +#ifndef __QCOM_CLK_KRAIT_H
  234. +#define __QCOM_CLK_KRAIT_H
  235. +
  236. +#include <linux/clk-provider.h>
  237. +
  238. +struct krait_mux_clk {
  239. + unsigned int *parent_map;
  240. + bool has_safe_parent;
  241. + u8 safe_sel;
  242. + u32 offset;
  243. + u32 mask;
  244. + u32 shift;
  245. + u32 en_mask;
  246. + bool lpl;
  247. +
  248. + struct clk_hw hw;
  249. +};
  250. +
  251. +#define to_krait_mux_clk(_hw) container_of(_hw, struct krait_mux_clk, hw)
  252. +
  253. +extern const struct clk_ops krait_mux_clk_ops;
  254. +
  255. +struct krait_div2_clk {
  256. + u32 offset;
  257. + u8 width;
  258. + u32 shift;
  259. + bool lpl;
  260. +
  261. + struct clk_hw hw;
  262. +};
  263. +
  264. +#define to_krait_div2_clk(_hw) container_of(_hw, struct krait_div2_clk, hw)
  265. +
  266. +extern const struct clk_ops krait_div2_clk_ops;
  267. +
  268. +#endif