clk-sun6i-apb0.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2014 Free Electrons
  4. *
  5. * Author: Boris BREZILLON <[email protected]>
  6. *
  7. * Allwinner A31 APB0 clock driver
  8. */
  9. #include <linux/clk-provider.h>
  10. #include <linux/init.h>
  11. #include <linux/of.h>
  12. #include <linux/platform_device.h>
  13. /*
  14. * The APB0 clk has a configurable divisor.
  15. *
  16. * We must use a clk_div_table and not a regular power of 2
  17. * divisor here, because the first 2 values divide the clock
  18. * by 2.
  19. */
  20. static const struct clk_div_table sun6i_a31_apb0_divs[] = {
  21. { .val = 0, .div = 2, },
  22. { .val = 1, .div = 2, },
  23. { .val = 2, .div = 4, },
  24. { .val = 3, .div = 8, },
  25. { /* sentinel */ },
  26. };
  27. static int sun6i_a31_apb0_clk_probe(struct platform_device *pdev)
  28. {
  29. struct device_node *np = pdev->dev.of_node;
  30. const char *clk_name = np->name;
  31. const char *clk_parent;
  32. void __iomem *reg;
  33. struct clk *clk;
  34. reg = devm_platform_ioremap_resource(pdev, 0);
  35. if (IS_ERR(reg))
  36. return PTR_ERR(reg);
  37. clk_parent = of_clk_get_parent_name(np, 0);
  38. if (!clk_parent)
  39. return -EINVAL;
  40. of_property_read_string(np, "clock-output-names", &clk_name);
  41. clk = clk_register_divider_table(&pdev->dev, clk_name, clk_parent,
  42. 0, reg, 0, 2, 0, sun6i_a31_apb0_divs,
  43. NULL);
  44. if (IS_ERR(clk))
  45. return PTR_ERR(clk);
  46. return of_clk_add_provider(np, of_clk_src_simple_get, clk);
  47. }
  48. static const struct of_device_id sun6i_a31_apb0_clk_dt_ids[] = {
  49. { .compatible = "allwinner,sun6i-a31-apb0-clk" },
  50. { /* sentinel */ }
  51. };
  52. static struct platform_driver sun6i_a31_apb0_clk_driver = {
  53. .driver = {
  54. .name = "sun6i-a31-apb0-clk",
  55. .of_match_table = sun6i_a31_apb0_clk_dt_ids,
  56. },
  57. .probe = sun6i_a31_apb0_clk_probe,
  58. };
  59. builtin_platform_driver(sun6i_a31_apb0_clk_driver);