div.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Spreadtrum divider clock driver
  4. //
  5. // Copyright (C) 2017 Spreadtrum, Inc.
  6. // Author: Chunyan Zhang <chunyan.zhang@spreadtrum.com>
  7. #ifndef _SPRD_DIV_H_
  8. #define _SPRD_DIV_H_
  9. #include "common.h"
  10. /**
  11. * struct sprd_div_internal - Internal divider description
  12. * @shift: Bit offset of the divider in its register
  13. * @width: Width of the divider field in its register
  14. *
  15. * That structure represents a single divider, and is meant to be
  16. * embedded in other structures representing the various clock
  17. * classes.
  18. */
  19. struct sprd_div_internal {
  20. u8 shift;
  21. u8 width;
  22. };
  23. #define _SPRD_DIV_CLK(_shift, _width) \
  24. { \
  25. .shift = _shift, \
  26. .width = _width, \
  27. }
  28. struct sprd_div {
  29. struct sprd_div_internal div;
  30. struct sprd_clk_common common;
  31. };
  32. #define SPRD_DIV_CLK(_struct, _name, _parent, _reg, \
  33. _shift, _width, _flags) \
  34. struct sprd_div _struct = { \
  35. .div = _SPRD_DIV_CLK(_shift, _width), \
  36. .common = { \
  37. .regmap = NULL, \
  38. .reg = _reg, \
  39. .hw.init = CLK_HW_INIT(_name, \
  40. _parent, \
  41. &sprd_div_ops, \
  42. _flags), \
  43. } \
  44. }
  45. static inline struct sprd_div *hw_to_sprd_div(const struct clk_hw *hw)
  46. {
  47. struct sprd_clk_common *common = hw_to_sprd_clk_common(hw);
  48. return container_of(common, struct sprd_div, common);
  49. }
  50. long sprd_div_helper_round_rate(struct sprd_clk_common *common,
  51. const struct sprd_div_internal *div,
  52. unsigned long rate,
  53. unsigned long *parent_rate);
  54. unsigned long sprd_div_helper_recalc_rate(struct sprd_clk_common *common,
  55. const struct sprd_div_internal *div,
  56. unsigned long parent_rate);
  57. int sprd_div_helper_set_rate(const struct sprd_clk_common *common,
  58. const struct sprd_div_internal *div,
  59. unsigned long rate,
  60. unsigned long parent_rate);
  61. extern const struct clk_ops sprd_div_ops;
  62. #endif /* _SPRD_DIV_H_ */