fixed-factor.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * TI Fixed Factor Clock
  3. *
  4. * Copyright (C) 2013 Texas Instruments, Inc.
  5. *
  6. * Tero Kristo <t-kristo@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  13. * kind, whether express or implied; without even the implied warranty
  14. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/clk-provider.h>
  18. #include <linux/slab.h>
  19. #include <linux/err.h>
  20. #include <linux/of.h>
  21. #include <linux/of_address.h>
  22. #include <linux/clk/ti.h>
  23. #include "clock.h"
  24. #undef pr_fmt
  25. #define pr_fmt(fmt) "%s: " fmt, __func__
  26. /**
  27. * of_ti_fixed_factor_clk_setup - Setup function for TI fixed factor clock
  28. * @node: device node for this clock
  29. *
  30. * Sets up a simple fixed factor clock based on device tree info.
  31. */
  32. static void __init of_ti_fixed_factor_clk_setup(struct device_node *node)
  33. {
  34. struct clk *clk;
  35. const char *clk_name = node->name;
  36. const char *parent_name;
  37. u32 div, mult;
  38. u32 flags = 0;
  39. if (of_property_read_u32(node, "ti,clock-div", &div)) {
  40. pr_err("%s must have a clock-div property\n", node->name);
  41. return;
  42. }
  43. if (of_property_read_u32(node, "ti,clock-mult", &mult)) {
  44. pr_err("%s must have a clock-mult property\n", node->name);
  45. return;
  46. }
  47. if (of_property_read_bool(node, "ti,set-rate-parent"))
  48. flags |= CLK_SET_RATE_PARENT;
  49. parent_name = of_clk_get_parent_name(node, 0);
  50. clk = clk_register_fixed_factor(NULL, clk_name, parent_name, flags,
  51. mult, div);
  52. if (!IS_ERR(clk)) {
  53. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  54. of_ti_clk_autoidle_setup(node);
  55. }
  56. }
  57. CLK_OF_DECLARE(ti_fixed_factor_clk, "ti,fixed-factor-clock",
  58. of_ti_fixed_factor_clk_setup);