clk-sun8i-apb0.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (C) 2014 Chen-Yu Tsai
  3. * Author: Chen-Yu Tsai <wens@csie.org>
  4. *
  5. * Allwinner A23 APB0 clock driver
  6. *
  7. * License Terms: GNU General Public License v2
  8. *
  9. * Based on clk-sun6i-apb0.c
  10. * Allwinner A31 APB0 clock driver
  11. *
  12. * Copyright (C) 2014 Free Electrons
  13. * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
  14. *
  15. */
  16. #include <linux/clk-provider.h>
  17. #include <linux/module.h>
  18. #include <linux/of.h>
  19. #include <linux/platform_device.h>
  20. static int sun8i_a23_apb0_clk_probe(struct platform_device *pdev)
  21. {
  22. struct device_node *np = pdev->dev.of_node;
  23. const char *clk_name = np->name;
  24. const char *clk_parent;
  25. struct resource *r;
  26. void __iomem *reg;
  27. struct clk *clk;
  28. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  29. reg = devm_ioremap_resource(&pdev->dev, r);
  30. if (IS_ERR(reg))
  31. return PTR_ERR(reg);
  32. clk_parent = of_clk_get_parent_name(np, 0);
  33. if (!clk_parent)
  34. return -EINVAL;
  35. of_property_read_string(np, "clock-output-names", &clk_name);
  36. /* The A23 APB0 clock is a standard 2 bit wide divider clock */
  37. clk = clk_register_divider(&pdev->dev, clk_name, clk_parent, 0, reg,
  38. 0, 2, CLK_DIVIDER_POWER_OF_TWO, NULL);
  39. if (IS_ERR(clk))
  40. return PTR_ERR(clk);
  41. return of_clk_add_provider(np, of_clk_src_simple_get, clk);
  42. }
  43. static const struct of_device_id sun8i_a23_apb0_clk_dt_ids[] = {
  44. { .compatible = "allwinner,sun8i-a23-apb0-clk" },
  45. { /* sentinel */ }
  46. };
  47. MODULE_DEVICE_TABLE(of, sun8i_a23_apb0_clk_dt_ids);
  48. static struct platform_driver sun8i_a23_apb0_clk_driver = {
  49. .driver = {
  50. .name = "sun8i-a23-apb0-clk",
  51. .of_match_table = sun8i_a23_apb0_clk_dt_ids,
  52. },
  53. .probe = sun8i_a23_apb0_clk_probe,
  54. };
  55. module_platform_driver(sun8i_a23_apb0_clk_driver);
  56. MODULE_AUTHOR("Chen-Yu Tsai <wens@csie.org>");
  57. MODULE_DESCRIPTION("Allwinner A23 APB0 clock Driver");
  58. MODULE_LICENSE("GPL v2");