clk.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2019 DENX Software Engineering
  4. * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
  5. */
  6. #include <common.h>
  7. #include <clk-uclass.h>
  8. #include <log.h>
  9. #include <dm/device.h>
  10. #include <dm/uclass.h>
  11. #include <dm/lists.h>
  12. #include <dm/device-internal.h>
  13. #include <clk.h>
  14. int clk_register(struct clk *clk, const char *drv_name,
  15. const char *name, const char *parent_name)
  16. {
  17. struct udevice *parent;
  18. struct driver *drv;
  19. int ret;
  20. ret = uclass_get_device_by_name(UCLASS_CLK, parent_name, &parent);
  21. if (ret) {
  22. printf("%s: failed to get %s device (parent of %s)\n",
  23. __func__, parent_name, name);
  24. } else {
  25. debug("%s: name: %s parent: %s [0x%p]\n", __func__, name,
  26. parent->name, parent);
  27. }
  28. drv = lists_driver_lookup_name(drv_name);
  29. if (!drv) {
  30. printf("%s: %s is not a valid driver name\n",
  31. __func__, drv_name);
  32. return -ENOENT;
  33. }
  34. ret = device_bind(parent, drv, name, NULL, -1, &clk->dev);
  35. if (ret) {
  36. printf("%s: CLK: %s driver bind error [%d]!\n", __func__, name,
  37. ret);
  38. return ret;
  39. }
  40. clk->enable_count = 0;
  41. /* Store back pointer to clk from udevice */
  42. clk->dev->uclass_priv = clk;
  43. return 0;
  44. }
  45. ulong clk_generic_get_rate(struct clk *clk)
  46. {
  47. return clk_get_parent_rate(clk);
  48. }
  49. const char *clk_hw_get_name(const struct clk *hw)
  50. {
  51. assert(hw);
  52. assert(hw->dev);
  53. return hw->dev->name;
  54. }
  55. bool clk_dev_binded(struct clk *clk)
  56. {
  57. if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
  58. return true;
  59. return false;
  60. }