mux.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. //
  3. // Spreadtrum multiplexer clock driver
  4. //
  5. // Copyright (C) 2017 Spreadtrum, Inc.
  6. // Author: Chunyan Zhang <[email protected]>
  7. #ifndef _SPRD_MUX_H_
  8. #define _SPRD_MUX_H_
  9. #include "common.h"
  10. /**
  11. * struct sprd_mux_ssel - Mux clock's source select bits in its register
  12. * @shift: Bit offset of the divider in its register
  13. * @width: Width of the divider field in its register
  14. * @table: For some mux clocks, not all sources are used on some special
  15. * chips, this matches the value of mux clock's register and the
  16. * sources which are used for this mux clock
  17. */
  18. struct sprd_mux_ssel {
  19. u8 shift;
  20. u8 width;
  21. const u8 *table;
  22. };
  23. struct sprd_mux {
  24. struct sprd_mux_ssel mux;
  25. struct sprd_clk_common common;
  26. };
  27. #define _SPRD_MUX_CLK(_shift, _width, _table) \
  28. { \
  29. .shift = _shift, \
  30. .width = _width, \
  31. .table = _table, \
  32. }
  33. #define SPRD_MUX_CLK_HW_INIT_FN(_struct, _name, _parents, _table, \
  34. _reg, _shift, _width, _flags, _fn) \
  35. struct sprd_mux _struct = { \
  36. .mux = _SPRD_MUX_CLK(_shift, _width, _table), \
  37. .common = { \
  38. .regmap = NULL, \
  39. .reg = _reg, \
  40. .hw.init = _fn(_name, _parents, \
  41. &sprd_mux_ops, _flags), \
  42. } \
  43. }
  44. #define SPRD_MUX_CLK_TABLE(_struct, _name, _parents, _table, \
  45. _reg, _shift, _width, _flags) \
  46. SPRD_MUX_CLK_HW_INIT_FN(_struct, _name, _parents, _table, \
  47. _reg, _shift, _width, _flags, \
  48. CLK_HW_INIT_PARENTS)
  49. #define SPRD_MUX_CLK(_struct, _name, _parents, _reg, \
  50. _shift, _width, _flags) \
  51. SPRD_MUX_CLK_TABLE(_struct, _name, _parents, NULL, \
  52. _reg, _shift, _width, _flags)
  53. #define SPRD_MUX_CLK_DATA_TABLE(_struct, _name, _parents, _table, \
  54. _reg, _shift, _width, _flags) \
  55. SPRD_MUX_CLK_HW_INIT_FN(_struct, _name, _parents, _table, \
  56. _reg, _shift, _width, _flags, \
  57. CLK_HW_INIT_PARENTS_DATA)
  58. #define SPRD_MUX_CLK_DATA(_struct, _name, _parents, _reg, \
  59. _shift, _width, _flags) \
  60. SPRD_MUX_CLK_DATA_TABLE(_struct, _name, _parents, NULL, \
  61. _reg, _shift, _width, _flags)
  62. static inline struct sprd_mux *hw_to_sprd_mux(const struct clk_hw *hw)
  63. {
  64. struct sprd_clk_common *common = hw_to_sprd_clk_common(hw);
  65. return container_of(common, struct sprd_mux, common);
  66. }
  67. extern const struct clk_ops sprd_mux_ops;
  68. u8 sprd_mux_helper_get_parent(const struct sprd_clk_common *common,
  69. const struct sprd_mux_ssel *mux);
  70. int sprd_mux_helper_set_parent(const struct sprd_clk_common *common,
  71. const struct sprd_mux_ssel *mux,
  72. u8 index);
  73. #endif /* _SPRD_MUX_H_ */