meson-eeclk.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2019 BayLibre, SAS.
  4. * Author: Jerome Brunet <[email protected]>
  5. */
  6. #include <linux/clk-provider.h>
  7. #include <linux/of_device.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/mfd/syscon.h>
  10. #include <linux/regmap.h>
  11. #include <linux/module.h>
  12. #include "clk-regmap.h"
  13. #include "meson-eeclk.h"
  14. int meson_eeclkc_probe(struct platform_device *pdev)
  15. {
  16. const struct meson_eeclkc_data *data;
  17. struct device *dev = &pdev->dev;
  18. struct device_node *np;
  19. struct regmap *map;
  20. int ret, i;
  21. data = of_device_get_match_data(dev);
  22. if (!data)
  23. return -EINVAL;
  24. /* Get the hhi system controller node */
  25. np = of_get_parent(dev->of_node);
  26. map = syscon_node_to_regmap(np);
  27. of_node_put(np);
  28. if (IS_ERR(map)) {
  29. dev_err(dev,
  30. "failed to get HHI regmap\n");
  31. return PTR_ERR(map);
  32. }
  33. if (data->init_count)
  34. regmap_multi_reg_write(map, data->init_regs, data->init_count);
  35. /* Populate regmap for the regmap backed clocks */
  36. for (i = 0; i < data->regmap_clk_num; i++)
  37. data->regmap_clks[i]->map = map;
  38. for (i = 0; i < data->hw_onecell_data->num; i++) {
  39. /* array might be sparse */
  40. if (!data->hw_onecell_data->hws[i])
  41. continue;
  42. ret = devm_clk_hw_register(dev, data->hw_onecell_data->hws[i]);
  43. if (ret) {
  44. dev_err(dev, "Clock registration failed\n");
  45. return ret;
  46. }
  47. }
  48. return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
  49. data->hw_onecell_data);
  50. }
  51. EXPORT_SYMBOL_GPL(meson_eeclkc_probe);
  52. MODULE_LICENSE("GPL v2");