fixed-factor.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * TI Fixed Factor Clock
  4. *
  5. * Copyright (C) 2013 Texas Instruments, Inc.
  6. *
  7. * Tero Kristo <[email protected]>
  8. */
  9. #include <linux/clk-provider.h>
  10. #include <linux/slab.h>
  11. #include <linux/err.h>
  12. #include <linux/of.h>
  13. #include <linux/of_address.h>
  14. #include <linux/clk/ti.h>
  15. #include "clock.h"
  16. #undef pr_fmt
  17. #define pr_fmt(fmt) "%s: " fmt, __func__
  18. /**
  19. * of_ti_fixed_factor_clk_setup - Setup function for TI fixed factor clock
  20. * @node: device node for this clock
  21. *
  22. * Sets up a simple fixed factor clock based on device tree info.
  23. */
  24. static void __init of_ti_fixed_factor_clk_setup(struct device_node *node)
  25. {
  26. struct clk *clk;
  27. const char *clk_name = ti_dt_clk_name(node);
  28. const char *parent_name;
  29. u32 div, mult;
  30. u32 flags = 0;
  31. if (of_property_read_u32(node, "ti,clock-div", &div)) {
  32. pr_err("%pOFn must have a clock-div property\n", node);
  33. return;
  34. }
  35. if (of_property_read_u32(node, "ti,clock-mult", &mult)) {
  36. pr_err("%pOFn must have a clock-mult property\n", node);
  37. return;
  38. }
  39. if (of_property_read_bool(node, "ti,set-rate-parent"))
  40. flags |= CLK_SET_RATE_PARENT;
  41. parent_name = of_clk_get_parent_name(node, 0);
  42. clk = clk_register_fixed_factor(NULL, clk_name, parent_name, flags,
  43. mult, div);
  44. if (!IS_ERR(clk)) {
  45. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  46. of_ti_clk_autoidle_setup(node);
  47. ti_clk_add_alias(clk, clk_name);
  48. }
  49. }
  50. CLK_OF_DECLARE(ti_fixed_factor_clk, "ti,fixed-factor-clock",
  51. of_ti_fixed_factor_clk_setup);