clk-sun6i-apb0.c 2.0 KB

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