clk-fixed-rate.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
  3. * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org>
  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 version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Fixed rate clock implementation
  10. */
  11. #include <linux/clk-provider.h>
  12. #include <linux/module.h>
  13. #include <linux/slab.h>
  14. #include <linux/io.h>
  15. #include <linux/err.h>
  16. /*
  17. * DOC: basic fixed-rate clock that cannot gate
  18. *
  19. * Traits of this clock:
  20. * prepare - clk_(un)prepare only ensures parents are prepared
  21. * enable - clk_enable only ensures parents are enabled
  22. * rate - rate is always a fixed value. No clk_set_rate support
  23. * parent - fixed parent. No clk_set_parent support
  24. */
  25. #define to_clk_fixed_rate(_hw) container_of(_hw, struct clk_fixed_rate, hw)
  26. static unsigned long clk_fixed_rate_recalc_rate(struct clk_hw *hw,
  27. unsigned long parent_rate)
  28. {
  29. return to_clk_fixed_rate(hw)->fixed_rate;
  30. }
  31. struct clk_ops clk_fixed_rate_ops = {
  32. .recalc_rate = clk_fixed_rate_recalc_rate,
  33. };
  34. EXPORT_SYMBOL_GPL(clk_fixed_rate_ops);
  35. struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
  36. const char *parent_name, unsigned long flags,
  37. unsigned long fixed_rate)
  38. {
  39. struct clk_fixed_rate *fixed;
  40. char **parent_names = NULL;
  41. u8 len;
  42. fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
  43. if (!fixed) {
  44. pr_err("%s: could not allocate fixed clk\n", __func__);
  45. return ERR_PTR(-ENOMEM);
  46. }
  47. /* struct clk_fixed_rate assignments */
  48. fixed->fixed_rate = fixed_rate;
  49. if (parent_name) {
  50. parent_names = kmalloc(sizeof(char *), GFP_KERNEL);
  51. if (! parent_names)
  52. goto out;
  53. len = sizeof(char) * strlen(parent_name);
  54. parent_names[0] = kmalloc(len, GFP_KERNEL);
  55. if (!parent_names[0])
  56. goto out;
  57. strncpy(parent_names[0], parent_name, len);
  58. }
  59. out:
  60. return clk_register(dev, name,
  61. &clk_fixed_rate_ops, &fixed->hw,
  62. parent_names,
  63. (parent_name ? 1 : 0),
  64. flags);
  65. }