armada-37xx-xtal.c 2.2 KB

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