clk.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2021, STMicroelectronics - All Rights Reserved
  3. * Author(s): Ludovic Barre, <ludovic.barre@st.com> for STMicroelectronics.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <assert.h>
  8. #include <errno.h>
  9. #include <stdbool.h>
  10. #include <drivers/clk.h>
  11. static const struct clk_ops *ops;
  12. int clk_enable(unsigned long id)
  13. {
  14. assert((ops != NULL) && (ops->enable != NULL));
  15. return ops->enable(id);
  16. }
  17. void clk_disable(unsigned long id)
  18. {
  19. assert((ops != NULL) && (ops->disable != NULL));
  20. ops->disable(id);
  21. }
  22. unsigned long clk_get_rate(unsigned long id)
  23. {
  24. assert((ops != NULL) && (ops->get_rate != NULL));
  25. return ops->get_rate(id);
  26. }
  27. int clk_get_parent(unsigned long id)
  28. {
  29. assert((ops != NULL) && (ops->get_parent != NULL));
  30. return ops->get_parent(id);
  31. }
  32. bool clk_is_enabled(unsigned long id)
  33. {
  34. assert((ops != NULL) && (ops->is_enabled != NULL));
  35. return ops->is_enabled(id);
  36. }
  37. /*
  38. * Initialize the clk. The fields in the provided clk
  39. * ops pointer must be valid.
  40. */
  41. void clk_register(const struct clk_ops *ops_ptr)
  42. {
  43. assert((ops_ptr != NULL) &&
  44. (ops_ptr->enable != NULL) &&
  45. (ops_ptr->disable != NULL) &&
  46. (ops_ptr->get_rate != NULL) &&
  47. (ops_ptr->get_parent != NULL) &&
  48. (ops_ptr->is_enabled != NULL));
  49. ops = ops_ptr;
  50. }