clk-div.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * H8/300 divide clock driver
  4. *
  5. * Copyright 2015 Yoshinori Sato <ysato@users.sourceforge.jp>
  6. */
  7. #include <linux/clk-provider.h>
  8. #include <linux/err.h>
  9. #include <linux/of.h>
  10. #include <linux/of_address.h>
  11. static DEFINE_SPINLOCK(clklock);
  12. static void __init h8300_div_clk_setup(struct device_node *node)
  13. {
  14. unsigned int num_parents;
  15. struct clk_hw *hw;
  16. const char *clk_name = node->name;
  17. const char *parent_name;
  18. void __iomem *divcr = NULL;
  19. int width;
  20. int offset;
  21. num_parents = of_clk_get_parent_count(node);
  22. if (!num_parents) {
  23. pr_err("%s: no parent found\n", clk_name);
  24. return;
  25. }
  26. divcr = of_iomap(node, 0);
  27. if (divcr == NULL) {
  28. pr_err("%s: failed to map divide register\n", clk_name);
  29. goto error;
  30. }
  31. offset = (unsigned long)divcr & 3;
  32. offset = (3 - offset) * 8;
  33. divcr = (void __iomem *)((unsigned long)divcr & ~3);
  34. parent_name = of_clk_get_parent_name(node, 0);
  35. of_property_read_u32(node, "renesas,width", &width);
  36. hw = clk_hw_register_divider(NULL, clk_name, parent_name,
  37. CLK_SET_RATE_GATE, divcr, offset, width,
  38. CLK_DIVIDER_POWER_OF_TWO, &clklock);
  39. if (!IS_ERR(hw)) {
  40. of_clk_add_hw_provider(node, of_clk_hw_simple_get, hw);
  41. return;
  42. }
  43. pr_err("%s: failed to register %s div clock (%ld)\n",
  44. __func__, clk_name, PTR_ERR(hw));
  45. error:
  46. if (divcr)
  47. iounmap(divcr);
  48. }
  49. CLK_OF_DECLARE(h8300_div_clk, "renesas,h8300-div-clock", h8300_div_clk_setup);