PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/target/linux/sunxi/patches-3.13/113-clk-sunxi-register-factors-clocks.patch

https://gitlab.com/shinvdu/openwrt
Patch | 223 lines | 209 code | 14 blank | 0 comment | 0 complexity | 4e90592c70d1376bb9269cfca70c44ba MD5 | raw file
  1. From 9212bc4a3752e9a4db2f73afd99278eb28e5dcff Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Emilio=20L=C3=B3pez?= <emilio@elopez.com.ar>
  3. Date: Mon, 23 Dec 2013 00:32:32 -0300
  4. Subject: [PATCH] clk: sunxi: register factors clocks behind composite
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. This commit reworks factors clock registration to be done behind a
  9. composite clock. This allows us to additionally add a gate, mux or
  10. divisors, as it will be needed by some future PLLs.
  11. Signed-off-by: Emilio López <emilio@elopez.com.ar>
  12. Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
  13. ---
  14. drivers/clk/sunxi/clk-factors.c | 63 +------------------------------------
  15. drivers/clk/sunxi/clk-factors.h | 16 +++++-----
  16. drivers/clk/sunxi/clk-sunxi.c | 70 ++++++++++++++++++++++++++++++++++++++---
  17. 3 files changed, 76 insertions(+), 73 deletions(-)
  18. --- a/drivers/clk/sunxi/clk-factors.c
  19. +++ b/drivers/clk/sunxi/clk-factors.c
  20. @@ -30,14 +30,6 @@
  21. * parent - fixed parent. No clk_set_parent support
  22. */
  23. -struct clk_factors {
  24. - struct clk_hw hw;
  25. - void __iomem *reg;
  26. - struct clk_factors_config *config;
  27. - void (*get_factors) (u32 *rate, u32 parent, u8 *n, u8 *k, u8 *m, u8 *p);
  28. - spinlock_t *lock;
  29. -};
  30. -
  31. #define to_clk_factors(_hw) container_of(_hw, struct clk_factors, hw)
  32. #define SETMASK(len, pos) (((1U << (len)) - 1) << (pos))
  33. @@ -120,61 +112,8 @@ static int clk_factors_set_rate(struct c
  34. return 0;
  35. }
  36. -static const struct clk_ops clk_factors_ops = {
  37. +const struct clk_ops clk_factors_ops = {
  38. .recalc_rate = clk_factors_recalc_rate,
  39. .round_rate = clk_factors_round_rate,
  40. .set_rate = clk_factors_set_rate,
  41. };
  42. -
  43. -/**
  44. - * clk_register_factors - register a factors clock with
  45. - * the clock framework
  46. - * @dev: device registering this clock
  47. - * @name: name of this clock
  48. - * @parent_name: name of clock's parent
  49. - * @flags: framework-specific flags
  50. - * @reg: register address to adjust factors
  51. - * @config: shift and width of factors n, k, m and p
  52. - * @get_factors: function to calculate the factors for a given frequency
  53. - * @lock: shared register lock for this clock
  54. - */
  55. -struct clk *clk_register_factors(struct device *dev, const char *name,
  56. - const char *parent_name,
  57. - unsigned long flags, void __iomem *reg,
  58. - struct clk_factors_config *config,
  59. - void (*get_factors)(u32 *rate, u32 parent,
  60. - u8 *n, u8 *k, u8 *m, u8 *p),
  61. - spinlock_t *lock)
  62. -{
  63. - struct clk_factors *factors;
  64. - struct clk *clk;
  65. - struct clk_init_data init;
  66. -
  67. - /* allocate the factors */
  68. - factors = kzalloc(sizeof(struct clk_factors), GFP_KERNEL);
  69. - if (!factors) {
  70. - pr_err("%s: could not allocate factors clk\n", __func__);
  71. - return ERR_PTR(-ENOMEM);
  72. - }
  73. -
  74. - init.name = name;
  75. - init.ops = &clk_factors_ops;
  76. - init.flags = flags;
  77. - init.parent_names = (parent_name ? &parent_name : NULL);
  78. - init.num_parents = (parent_name ? 1 : 0);
  79. -
  80. - /* struct clk_factors assignments */
  81. - factors->reg = reg;
  82. - factors->config = config;
  83. - factors->lock = lock;
  84. - factors->hw.init = &init;
  85. - factors->get_factors = get_factors;
  86. -
  87. - /* register the clock */
  88. - clk = clk_register(dev, &factors->hw);
  89. -
  90. - if (IS_ERR(clk))
  91. - kfree(factors);
  92. -
  93. - return clk;
  94. -}
  95. --- a/drivers/clk/sunxi/clk-factors.h
  96. +++ b/drivers/clk/sunxi/clk-factors.h
  97. @@ -17,11 +17,13 @@ struct clk_factors_config {
  98. u8 pwidth;
  99. };
  100. -struct clk *clk_register_factors(struct device *dev, const char *name,
  101. - const char *parent_name,
  102. - unsigned long flags, void __iomem *reg,
  103. - struct clk_factors_config *config,
  104. - void (*get_factors) (u32 *rate, u32 parent_rate,
  105. - u8 *n, u8 *k, u8 *m, u8 *p),
  106. - spinlock_t *lock);
  107. +struct clk_factors {
  108. + struct clk_hw hw;
  109. + void __iomem *reg;
  110. + struct clk_factors_config *config;
  111. + void (*get_factors) (u32 *rate, u32 parent, u8 *n, u8 *k, u8 *m, u8 *p);
  112. + spinlock_t *lock;
  113. +};
  114. +
  115. +extern const struct clk_ops clk_factors_ops;
  116. #endif
  117. --- a/drivers/clk/sunxi/clk-sunxi.c
  118. +++ b/drivers/clk/sunxi/clk-sunxi.c
  119. @@ -23,6 +23,9 @@
  120. static DEFINE_SPINLOCK(clk_lock);
  121. +/* Maximum number of parents our clocks have */
  122. +#define SUNXI_MAX_PARENTS 5
  123. +
  124. /**
  125. * sun4i_osc_clk_setup() - Setup function for gatable oscillator
  126. */
  127. @@ -261,7 +264,11 @@ static void sun4i_get_apb1_factors(u32 *
  128. * sunxi_factors_clk_setup() - Setup function for factor clocks
  129. */
  130. +#define SUNXI_FACTORS_MUX_MASK 0x3
  131. +
  132. struct factors_data {
  133. + int enable;
  134. + int mux;
  135. struct clk_factors_config *table;
  136. void (*getter) (u32 *rate, u32 parent_rate, u8 *n, u8 *k, u8 *m, u8 *p);
  137. };
  138. @@ -312,16 +319,71 @@ static void __init sunxi_factors_clk_set
  139. struct factors_data *data)
  140. {
  141. struct clk *clk;
  142. + struct clk_factors *factors;
  143. + struct clk_gate *gate = NULL;
  144. + struct clk_mux *mux = NULL;
  145. + struct clk_hw *gate_hw = NULL;
  146. + struct clk_hw *mux_hw = NULL;
  147. const char *clk_name = node->name;
  148. - const char *parent;
  149. + const char *parents[SUNXI_MAX_PARENTS];
  150. void *reg;
  151. + int i = 0;
  152. reg = of_iomap(node, 0);
  153. - parent = of_clk_get_parent_name(node, 0);
  154. + /* if we have a mux, we will have >1 parents */
  155. + while (i < SUNXI_MAX_PARENTS &&
  156. + (parents[i] = of_clk_get_parent_name(node, i)) != NULL)
  157. + i++;
  158. +
  159. + factors = kzalloc(sizeof(struct clk_factors), GFP_KERNEL);
  160. + if (!factors)
  161. + return;
  162. +
  163. + /* Add a gate if this factor clock can be gated */
  164. + if (data->enable) {
  165. + gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
  166. + if (!gate) {
  167. + kfree(factors);
  168. + return;
  169. + }
  170. +
  171. + /* set up gate properties */
  172. + gate->reg = reg;
  173. + gate->bit_idx = data->enable;
  174. + gate->lock = &clk_lock;
  175. + gate_hw = &gate->hw;
  176. + }
  177. +
  178. + /* Add a mux if this factor clock can be muxed */
  179. + if (data->mux) {
  180. + mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL);
  181. + if (!mux) {
  182. + kfree(factors);
  183. + kfree(gate);
  184. + return;
  185. + }
  186. +
  187. + /* set up gate properties */
  188. + mux->reg = reg;
  189. + mux->shift = data->mux;
  190. + mux->mask = SUNXI_FACTORS_MUX_MASK;
  191. + mux->lock = &clk_lock;
  192. + mux_hw = &mux->hw;
  193. + }
  194. - clk = clk_register_factors(NULL, clk_name, parent, 0, reg,
  195. - data->table, data->getter, &clk_lock);
  196. + /* set up factors properties */
  197. + factors->reg = reg;
  198. + factors->config = data->table;
  199. + factors->get_factors = data->getter;
  200. + factors->lock = &clk_lock;
  201. +
  202. + clk = clk_register_composite(NULL, clk_name,
  203. + parents, i,
  204. + mux_hw, &clk_mux_ops,
  205. + &factors->hw, &clk_factors_ops,
  206. + gate_hw, &clk_gate_ops,
  207. + i ? 0 : CLK_IS_ROOT);
  208. if (!IS_ERR(clk)) {
  209. of_clk_add_provider(node, of_clk_src_simple_get, clk);