mux.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Spreadtrum multiplexer clock driver
  4. //
  5. // Copyright (C) 2017 Spreadtrum, Inc.
  6. // Author: Chunyan Zhang <chunyan.zhang@spreadtrum.com>
  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_TABLE(_struct, _name, _parents, _table, \
  34. _reg, _shift, _width, \
  35. _flags) \
  36. struct sprd_mux _struct = { \
  37. .mux = _SPRD_MUX_CLK(_shift, _width, _table), \
  38. .common = { \
  39. .regmap = NULL, \
  40. .reg = _reg, \
  41. .hw.init = CLK_HW_INIT_PARENTS(_name, \
  42. _parents, \
  43. &sprd_mux_ops, \
  44. _flags), \
  45. } \
  46. }
  47. #define SPRD_MUX_CLK(_struct, _name, _parents, _reg, \
  48. _shift, _width, _flags) \
  49. SPRD_MUX_CLK_TABLE(_struct, _name, _parents, NULL, \
  50. _reg, _shift, _width, _flags)
  51. static inline struct sprd_mux *hw_to_sprd_mux(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_mux, common);
  55. }
  56. extern const struct clk_ops sprd_mux_ops;
  57. u8 sprd_mux_helper_get_parent(const struct sprd_clk_common *common,
  58. const struct sprd_mux_ssel *mux);
  59. int sprd_mux_helper_set_parent(const struct sprd_clk_common *common,
  60. const struct sprd_mux_ssel *mux,
  61. u8 index);
  62. #endif /* _SPRD_MUX_H_ */