div.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. //
  3. // Spreadtrum divider clock driver
  4. //
  5. // Copyright (C) 2017 Spreadtrum, Inc.
  6. // Author: Chunyan Zhang <[email protected]>
  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_HW_INIT_FN(_struct, _name, _parent, _reg, \
  33. _shift, _width, _flags, _fn) \
  34. struct sprd_div _struct = { \
  35. .div = _SPRD_DIV_CLK(_shift, _width), \
  36. .common = { \
  37. .regmap = NULL, \
  38. .reg = _reg, \
  39. .hw.init = _fn(_name, _parent, \
  40. &sprd_div_ops, _flags), \
  41. } \
  42. }
  43. #define SPRD_DIV_CLK(_struct, _name, _parent, _reg, \
  44. _shift, _width, _flags) \
  45. SPRD_DIV_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, \
  46. _shift, _width, _flags, CLK_HW_INIT)
  47. #define SPRD_DIV_CLK_HW(_struct, _name, _parent, _reg, \
  48. _shift, _width, _flags) \
  49. SPRD_DIV_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, \
  50. _shift, _width, _flags, CLK_HW_INIT_HW)
  51. static inline struct sprd_div *hw_to_sprd_div(const struct clk_hw *hw)
  52. {
  53. struct sprd_clk_common *common = hw_to_sprd_clk_common(hw);
  54. return container_of(common, struct sprd_div, common);
  55. }
  56. long sprd_div_helper_round_rate(struct sprd_clk_common *common,
  57. const struct sprd_div_internal *div,
  58. unsigned long rate,
  59. unsigned long *parent_rate);
  60. unsigned long sprd_div_helper_recalc_rate(struct sprd_clk_common *common,
  61. const struct sprd_div_internal *div,
  62. unsigned long parent_rate);
  63. int sprd_div_helper_set_rate(const struct sprd_clk_common *common,
  64. const struct sprd_div_internal *div,
  65. unsigned long rate,
  66. unsigned long parent_rate);
  67. extern const struct clk_ops sprd_div_ops;
  68. #endif /* _SPRD_DIV_H_ */