clk-div.c 1.2 KB

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