2
0

103-clk-sunxi-add-h3-clksupport.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. From ab6e23a4e388f5f2696b8e92c350f845142da118 Mon Sep 17 00:00:00 2001
  2. From: Jens Kuske <jenskuske@gmail.com>
  3. Date: Fri, 4 Dec 2015 22:24:40 +0100
  4. Subject: [PATCH] clk: sunxi: Add H3 clocks support
  5. The H3 clock control unit is similar to the those of other sun8i family
  6. members like the A23.
  7. It adds a new bus gates clock similar to the simple gates, but with a
  8. different parent clock for each single gate.
  9. Some of the gates use the new AHB2 clock as parent, whose clock source
  10. is muxable between AHB1 and PLL6/2. The documentation isn't totally clear
  11. about which devices belong to AHB2 now, especially USB EHIC/OHIC, so it
  12. is mostly based on Allwinner kernel source code.
  13. Signed-off-by: Jens Kuske <jenskuske@gmail.com>
  14. Acked-by: Rob Herring <robh@kernel.org>
  15. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
  16. ---
  17. Documentation/devicetree/bindings/clock/sunxi.txt | 2 +
  18. drivers/clk/sunxi/Makefile | 1 +
  19. drivers/clk/sunxi/clk-sun8i-bus-gates.c | 112 ++++++++++++++++++++++
  20. drivers/clk/sunxi/clk-sunxi.c | 6 ++
  21. 4 files changed, 121 insertions(+)
  22. create mode 100644 drivers/clk/sunxi/clk-sun8i-bus-gates.c
  23. --- a/drivers/clk/sunxi/Makefile
  24. +++ b/drivers/clk/sunxi/Makefile
  25. @@ -10,6 +10,7 @@ obj-y += clk-a10-pll2.o
  26. obj-y += clk-a20-gmac.o
  27. obj-y += clk-mod0.o
  28. obj-y += clk-simple-gates.o
  29. +obj-y += clk-sun8i-bus-gates.o
  30. obj-y += clk-sun8i-mbus.o
  31. obj-y += clk-sun9i-core.o
  32. obj-y += clk-sun9i-mmc.o
  33. --- /dev/null
  34. +++ b/drivers/clk/sunxi/clk-sun8i-bus-gates.c
  35. @@ -0,0 +1,112 @@
  36. +/*
  37. + * Copyright (C) 2015 Jens Kuske <jenskuske@gmail.com>
  38. + *
  39. + * Based on clk-simple-gates.c, which is:
  40. + * Copyright 2015 Maxime Ripard
  41. + *
  42. + * Maxime Ripard <maxime.ripard@free-electrons.com>
  43. + *
  44. + * This program is free software; you can redistribute it and/or modify
  45. + * it under the terms of the GNU General Public License as published by
  46. + * the Free Software Foundation; either version 2 of the License, or
  47. + * (at your option) any later version.
  48. + *
  49. + * This program is distributed in the hope that it will be useful,
  50. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  51. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  52. + * GNU General Public License for more details.
  53. + */
  54. +
  55. +#include <linux/clk.h>
  56. +#include <linux/clk-provider.h>
  57. +#include <linux/of.h>
  58. +#include <linux/of_address.h>
  59. +#include <linux/slab.h>
  60. +#include <linux/spinlock.h>
  61. +
  62. +static DEFINE_SPINLOCK(gates_lock);
  63. +
  64. +static void __init sun8i_h3_bus_gates_init(struct device_node *node)
  65. +{
  66. + static const char * const names[] = { "ahb1", "ahb2", "apb1", "apb2" };
  67. + enum { AHB1, AHB2, APB1, APB2, PARENT_MAX } clk_parent;
  68. + const char *parents[PARENT_MAX];
  69. + struct clk_onecell_data *clk_data;
  70. + const char *clk_name;
  71. + struct property *prop;
  72. + struct resource res;
  73. + void __iomem *clk_reg;
  74. + void __iomem *reg;
  75. + const __be32 *p;
  76. + int number, i;
  77. + u8 clk_bit;
  78. + u32 index;
  79. +
  80. + reg = of_io_request_and_map(node, 0, of_node_full_name(node));
  81. + if (IS_ERR(reg))
  82. + return;
  83. +
  84. + for (i = 0; i < ARRAY_SIZE(names); i++) {
  85. + index = of_property_match_string(node, "clock-names",
  86. + names[i]);
  87. + if (index < 0)
  88. + return;
  89. +
  90. + parents[i] = of_clk_get_parent_name(node, index);
  91. + }
  92. +
  93. + clk_data = kmalloc(sizeof(struct clk_onecell_data), GFP_KERNEL);
  94. + if (!clk_data)
  95. + goto err_unmap;
  96. +
  97. + number = of_property_count_u32_elems(node, "clock-indices");
  98. + of_property_read_u32_index(node, "clock-indices", number - 1, &number);
  99. +
  100. + clk_data->clks = kcalloc(number + 1, sizeof(struct clk *), GFP_KERNEL);
  101. + if (!clk_data->clks)
  102. + goto err_free_data;
  103. +
  104. + i = 0;
  105. + of_property_for_each_u32(node, "clock-indices", prop, p, index) {
  106. + of_property_read_string_index(node, "clock-output-names",
  107. + i, &clk_name);
  108. +
  109. + if (index == 17 || (index >= 29 && index <= 31))
  110. + clk_parent = AHB2;
  111. + else if (index <= 63 || index >= 128)
  112. + clk_parent = AHB1;
  113. + else if (index >= 64 && index <= 95)
  114. + clk_parent = APB1;
  115. + else if (index >= 96 && index <= 127)
  116. + clk_parent = APB2;
  117. +
  118. + clk_reg = reg + 4 * (index / 32);
  119. + clk_bit = index % 32;
  120. +
  121. + clk_data->clks[index] = clk_register_gate(NULL, clk_name,
  122. + parents[clk_parent],
  123. + 0, clk_reg, clk_bit,
  124. + 0, &gates_lock);
  125. + i++;
  126. +
  127. + if (IS_ERR(clk_data->clks[index])) {
  128. + WARN_ON(true);
  129. + continue;
  130. + }
  131. + }
  132. +
  133. + clk_data->clk_num = number + 1;
  134. + of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  135. +
  136. + return;
  137. +
  138. +err_free_data:
  139. + kfree(clk_data);
  140. +err_unmap:
  141. + iounmap(reg);
  142. + of_address_to_resource(node, 0, &res);
  143. + release_mem_region(res.start, resource_size(&res));
  144. +}
  145. +
  146. +CLK_OF_DECLARE(sun8i_h3_bus_gates, "allwinner,sun8i-h3-bus-gates-clk",
  147. + sun8i_h3_bus_gates_init);
  148. --- a/drivers/clk/sunxi/clk-sunxi.c
  149. +++ b/drivers/clk/sunxi/clk-sunxi.c
  150. @@ -778,6 +778,10 @@ static const struct mux_data sun6i_a31_a
  151. .shift = 12,
  152. };
  153. +static const struct mux_data sun8i_h3_ahb2_mux_data __initconst = {
  154. + .shift = 0,
  155. +};
  156. +
  157. static void __init sunxi_mux_clk_setup(struct device_node *node,
  158. struct mux_data *data)
  159. {
  160. @@ -1130,6 +1134,7 @@ static const struct of_device_id clk_div
  161. static const struct of_device_id clk_mux_match[] __initconst = {
  162. {.compatible = "allwinner,sun4i-a10-cpu-clk", .data = &sun4i_cpu_mux_data,},
  163. {.compatible = "allwinner,sun6i-a31-ahb1-mux-clk", .data = &sun6i_a31_ahb1_mux_data,},
  164. + {.compatible = "allwinner,sun8i-h3-ahb2-clk", .data = &sun8i_h3_ahb2_mux_data,},
  165. {}
  166. };
  167. @@ -1212,6 +1217,7 @@ CLK_OF_DECLARE(sun6i_a31_clk_init, "allw
  168. CLK_OF_DECLARE(sun6i_a31s_clk_init, "allwinner,sun6i-a31s", sun6i_init_clocks);
  169. CLK_OF_DECLARE(sun8i_a23_clk_init, "allwinner,sun8i-a23", sun6i_init_clocks);
  170. CLK_OF_DECLARE(sun8i_a33_clk_init, "allwinner,sun8i-a33", sun6i_init_clocks);
  171. +CLK_OF_DECLARE(sun8i_h3_clk_init, "allwinner,sun8i-h3", sun6i_init_clocks);
  172. static void __init sun9i_init_clocks(struct device_node *node)
  173. {