composite.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. //
  3. // Spreadtrum composite clock driver
  4. //
  5. // Copyright (C) 2017 Spreadtrum, Inc.
  6. // Author: Chunyan Zhang <chunyan.zhang@spreadtrum.com>
  7. #ifndef _SPRD_COMPOSITE_H_
  8. #define _SPRD_COMPOSITE_H_
  9. #include "common.h"
  10. #include "mux.h"
  11. #include "div.h"
  12. struct sprd_comp {
  13. struct sprd_mux_ssel mux;
  14. struct sprd_div_internal div;
  15. struct sprd_clk_common common;
  16. };
  17. #define SPRD_COMP_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, _table, \
  18. _mshift, _mwidth, _doffset, _dshift, \
  19. _dwidth, _flags, _fn) \
  20. struct sprd_comp _struct = { \
  21. .mux = _SPRD_MUX_CLK(_mshift, _mwidth, _table), \
  22. .div = _SPRD_DIV_CLK(_doffset, _dshift, _dwidth), \
  23. .common = { \
  24. .regmap = NULL, \
  25. .reg = _reg, \
  26. .hw.init = _fn(_name, _parent, \
  27. &sprd_comp_ops, _flags), \
  28. } \
  29. }
  30. #define SPRD_COMP_CLK_TABLE(_struct, _name, _parent, _reg, _table, \
  31. _mshift, _mwidth, _dshift, _dwidth, _flags) \
  32. SPRD_COMP_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, _table, \
  33. _mshift, _mwidth, 0x0, _dshift, \
  34. _dwidth, _flags, CLK_HW_INIT_PARENTS)
  35. #define SPRD_COMP_CLK(_struct, _name, _parent, _reg, _mshift, \
  36. _mwidth, _dshift, _dwidth, _flags) \
  37. SPRD_COMP_CLK_TABLE(_struct, _name, _parent, _reg, NULL, \
  38. _mshift, _mwidth, _dshift, _dwidth, _flags)
  39. #define SPRD_COMP_CLK_DATA_TABLE(_struct, _name, _parent, _reg, _table, \
  40. _mshift, _mwidth, _dshift, \
  41. _dwidth, _flags) \
  42. SPRD_COMP_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, _table, \
  43. _mshift, _mwidth, 0x0, _dshift, \
  44. _dwidth, _flags, \
  45. CLK_HW_INIT_PARENTS_DATA)
  46. #define SPRD_COMP_CLK_DATA(_struct, _name, _parent, _reg, _mshift, \
  47. _mwidth, _dshift, _dwidth, _flags) \
  48. SPRD_COMP_CLK_DATA_TABLE(_struct, _name, _parent, _reg, NULL, \
  49. _mshift, _mwidth, _dshift, _dwidth, \
  50. _flags)
  51. #define SPRD_COMP_CLK_DATA_TABLE_OFFSET(_struct, _name, _parent, _reg, \
  52. _table, _mshift, _mwidth, \
  53. _doffset, _dshift, _dwidth, \
  54. _flags) \
  55. SPRD_COMP_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, _table, \
  56. _mshift, _mwidth, _doffset, _dshift, \
  57. _dwidth, _flags, \
  58. CLK_HW_INIT_PARENTS_DATA)
  59. #define SPRD_COMP_CLK_DATA_OFFSET(_struct, _name, _parent, _reg, \
  60. _mshift, _mwidth, _doffset, _dshift, \
  61. _dwidth, _flags) \
  62. SPRD_COMP_CLK_DATA_TABLE_OFFSET(_struct, _name, _parent, _reg, \
  63. NULL, _mshift, _mwidth, \
  64. _doffset, _dshift, _dwidth, \
  65. _flags)
  66. static inline struct sprd_comp *hw_to_sprd_comp(const struct clk_hw *hw)
  67. {
  68. struct sprd_clk_common *common = hw_to_sprd_clk_common(hw);
  69. return container_of(common, struct sprd_comp, common);
  70. }
  71. extern const struct clk_ops sprd_comp_ops;
  72. #endif /* _SPRD_COMPOSITE_H_ */