clk-fixed-rate.c 2.2 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. const 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. /**
  36. * clk_register_fixed_rate - register fixed-rate clock with the clock framework
  37. * @dev: device that is registering this clock
  38. * @name: name of this clock
  39. * @parent_name: name of clock's parent
  40. * @flags: framework-specific flags
  41. * @fixed_rate: non-adjustable clock rate
  42. */
  43. struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
  44. const char *parent_name, unsigned long flags,
  45. unsigned long fixed_rate)
  46. {
  47. struct clk_fixed_rate *fixed;
  48. struct clk *clk;
  49. struct clk_init_data init;
  50. /* allocate fixed-rate clock */
  51. fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
  52. if (!fixed) {
  53. pr_err("%s: could not allocate fixed clk\n", __func__);
  54. return ERR_PTR(-ENOMEM);
  55. }
  56. init.name = name;
  57. init.ops = &clk_fixed_rate_ops;
  58. init.flags = flags;
  59. init.parent_names = (parent_name ? &parent_name: NULL);
  60. init.num_parents = (parent_name ? 1 : 0);
  61. /* struct clk_fixed_rate assignments */
  62. fixed->fixed_rate = fixed_rate;
  63. fixed->hw.init = &init;
  64. /* register the clock */
  65. clk = clk_register(dev, &fixed->hw);
  66. if (IS_ERR(clk))
  67. kfree(fixed);
  68. return clk;
  69. }