clk-rockchip.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2013 MundoReader S.L.
  3. * Author: Heiko Stuebner <heiko@sntech.de>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/clk-provider.h>
  16. #include <linux/clkdev.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. static DEFINE_SPINLOCK(clk_lock);
  20. /*
  21. * Gate clocks
  22. */
  23. static void __init rk2928_gate_clk_init(struct device_node *node,
  24. void *data)
  25. {
  26. struct clk_onecell_data *clk_data;
  27. const char *clk_parent;
  28. const char *clk_name;
  29. void __iomem *reg;
  30. void __iomem *reg_idx;
  31. int flags;
  32. int qty;
  33. int reg_bit;
  34. int clkflags = CLK_SET_RATE_PARENT;
  35. int i;
  36. qty = of_property_count_strings(node, "clock-output-names");
  37. if (qty < 0) {
  38. pr_err("%s: error in clock-output-names %d\n", __func__, qty);
  39. return;
  40. }
  41. if (qty == 0) {
  42. pr_info("%s: nothing to do\n", __func__);
  43. return;
  44. }
  45. reg = of_iomap(node, 0);
  46. clk_data = kzalloc(sizeof(struct clk_onecell_data), GFP_KERNEL);
  47. if (!clk_data)
  48. return;
  49. clk_data->clks = kzalloc(qty * sizeof(struct clk *), GFP_KERNEL);
  50. if (!clk_data->clks) {
  51. kfree(clk_data);
  52. return;
  53. }
  54. flags = CLK_GATE_HIWORD_MASK | CLK_GATE_SET_TO_DISABLE;
  55. for (i = 0; i < qty; i++) {
  56. of_property_read_string_index(node, "clock-output-names",
  57. i, &clk_name);
  58. /* ignore empty slots */
  59. if (!strcmp("reserved", clk_name))
  60. continue;
  61. clk_parent = of_clk_get_parent_name(node, i);
  62. /* keep all gates untouched for now */
  63. clkflags |= CLK_IGNORE_UNUSED;
  64. reg_idx = reg + (4 * (i / 16));
  65. reg_bit = (i % 16);
  66. clk_data->clks[i] = clk_register_gate(NULL, clk_name,
  67. clk_parent, clkflags,
  68. reg_idx, reg_bit,
  69. flags,
  70. &clk_lock);
  71. WARN_ON(IS_ERR(clk_data->clks[i]));
  72. }
  73. clk_data->clk_num = qty;
  74. of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  75. }
  76. CLK_OF_DECLARE(rk2928_gate, "rockchip,rk2928-gate-clk", rk2928_gate_clk_init);