clk-fixed-rate.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. EXPORT_SYMBOL_GPL(clk_fixed_rate_recalc_rate);
  32. struct clk_ops clk_fixed_rate_ops = {
  33. .recalc_rate = clk_fixed_rate_recalc_rate,
  34. };
  35. EXPORT_SYMBOL_GPL(clk_fixed_rate_ops);
  36. struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
  37. const char *parent_name, unsigned long flags,
  38. unsigned long fixed_rate)
  39. {
  40. struct clk_fixed_rate *fixed;
  41. char **parent_names = NULL;
  42. u8 len;
  43. fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
  44. if (!fixed) {
  45. pr_err("%s: could not allocate fixed clk\n", __func__);
  46. return ERR_PTR(-ENOMEM);
  47. }
  48. /* struct clk_fixed_rate assignments */
  49. fixed->fixed_rate = fixed_rate;
  50. if (parent_name) {
  51. parent_names = kmalloc(sizeof(char *), GFP_KERNEL);
  52. if (! parent_names)
  53. goto out;
  54. len = sizeof(char) * strlen(parent_name);
  55. parent_names[0] = kmalloc(len, GFP_KERNEL);
  56. if (!parent_names[0])
  57. goto out;
  58. strncpy(parent_names[0], parent_name, len);
  59. }
  60. out:
  61. return clk_register(dev, name,
  62. &clk_fixed_rate_ops, &fixed->hw,
  63. parent_names,
  64. (parent_name ? 1 : 0),
  65. flags);
  66. }