clk-rockchip.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. {
  25. struct clk_onecell_data *clk_data;
  26. const char *clk_parent;
  27. const char *clk_name;
  28. void __iomem *reg;
  29. void __iomem *reg_idx;
  30. int flags;
  31. int qty;
  32. int reg_bit;
  33. int clkflags = CLK_SET_RATE_PARENT;
  34. int i;
  35. qty = of_property_count_strings(node, "clock-output-names");
  36. if (qty < 0) {
  37. pr_err("%s: error in clock-output-names %d\n", __func__, qty);
  38. return;
  39. }
  40. if (qty == 0) {
  41. pr_info("%s: nothing to do\n", __func__);
  42. return;
  43. }
  44. reg = of_iomap(node, 0);
  45. clk_data = kzalloc(sizeof(struct clk_onecell_data), GFP_KERNEL);
  46. if (!clk_data)
  47. return;
  48. clk_data->clks = kzalloc(qty * sizeof(struct clk *), GFP_KERNEL);
  49. if (!clk_data->clks) {
  50. kfree(clk_data);
  51. return;
  52. }
  53. flags = CLK_GATE_HIWORD_MASK | CLK_GATE_SET_TO_DISABLE;
  54. for (i = 0; i < qty; i++) {
  55. of_property_read_string_index(node, "clock-output-names",
  56. i, &clk_name);
  57. /* ignore empty slots */
  58. if (!strcmp("reserved", clk_name))
  59. continue;
  60. clk_parent = of_clk_get_parent_name(node, i);
  61. /* keep all gates untouched for now */
  62. clkflags |= CLK_IGNORE_UNUSED;
  63. reg_idx = reg + (4 * (i / 16));
  64. reg_bit = (i % 16);
  65. clk_data->clks[i] = clk_register_gate(NULL, clk_name,
  66. clk_parent, clkflags,
  67. reg_idx, reg_bit,
  68. flags,
  69. &clk_lock);
  70. WARN_ON(IS_ERR(clk_data->clks[i]));
  71. }
  72. clk_data->clk_num = qty;
  73. of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  74. }
  75. CLK_OF_DECLARE(rk2928_gate, "rockchip,rk2928-gate-clk", rk2928_gate_clk_init);