armada-37xx-xtal.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Marvell Armada 37xx SoC xtal clocks
  4. *
  5. * Copyright (C) 2016 Marvell
  6. *
  7. * Gregory CLEMENT <gregory.clement@free-electrons.com>
  8. *
  9. */
  10. #include <linux/clk-provider.h>
  11. #include <linux/mfd/syscon.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/regmap.h>
  14. #define NB_GPIO1_LATCH 0x8
  15. #define XTAL_MODE BIT(9)
  16. static int armada_3700_xtal_clock_probe(struct platform_device *pdev)
  17. {
  18. struct device_node *np = pdev->dev.of_node;
  19. const char *xtal_name = "xtal";
  20. struct device_node *parent;
  21. struct regmap *regmap;
  22. struct clk_hw *xtal_hw;
  23. unsigned int rate;
  24. u32 reg;
  25. int ret;
  26. xtal_hw = devm_kzalloc(&pdev->dev, sizeof(*xtal_hw), GFP_KERNEL);
  27. if (!xtal_hw)
  28. return -ENOMEM;
  29. platform_set_drvdata(pdev, xtal_hw);
  30. parent = np->parent;
  31. if (!parent) {
  32. dev_err(&pdev->dev, "no parent\n");
  33. return -ENODEV;
  34. }
  35. regmap = syscon_node_to_regmap(parent);
  36. if (IS_ERR(regmap)) {
  37. dev_err(&pdev->dev, "cannot get regmap\n");
  38. return PTR_ERR(regmap);
  39. }
  40. ret = regmap_read(regmap, NB_GPIO1_LATCH, &reg);
  41. if (ret) {
  42. dev_err(&pdev->dev, "cannot read from regmap\n");
  43. return ret;
  44. }
  45. if (reg & XTAL_MODE)
  46. rate = 40000000;
  47. else
  48. rate = 25000000;
  49. of_property_read_string_index(np, "clock-output-names", 0, &xtal_name);
  50. xtal_hw = clk_hw_register_fixed_rate(NULL, xtal_name, NULL, 0, rate);
  51. if (IS_ERR(xtal_hw))
  52. return PTR_ERR(xtal_hw);
  53. ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, xtal_hw);
  54. return ret;
  55. }
  56. static int armada_3700_xtal_clock_remove(struct platform_device *pdev)
  57. {
  58. of_clk_del_provider(pdev->dev.of_node);
  59. return 0;
  60. }
  61. static const struct of_device_id armada_3700_xtal_clock_of_match[] = {
  62. { .compatible = "marvell,armada-3700-xtal-clock", },
  63. { }
  64. };
  65. static struct platform_driver armada_3700_xtal_clock_driver = {
  66. .probe = armada_3700_xtal_clock_probe,
  67. .remove = armada_3700_xtal_clock_remove,
  68. .driver = {
  69. .name = "marvell-armada-3700-xtal-clock",
  70. .of_match_table = armada_3700_xtal_clock_of_match,
  71. },
  72. };
  73. builtin_platform_driver(armada_3700_xtal_clock_driver);