ccu_mux.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef _CCU_MUX_H_
  2. #define _CCU_MUX_H_
  3. #include <linux/clk-provider.h>
  4. #include "ccu_common.h"
  5. struct ccu_mux_internal {
  6. u8 shift;
  7. u8 width;
  8. struct {
  9. u8 index;
  10. u8 div;
  11. } fixed_prediv;
  12. struct {
  13. u8 index;
  14. u8 shift;
  15. u8 width;
  16. } variable_prediv;
  17. };
  18. #define SUNXI_CLK_MUX(_shift, _width) \
  19. { \
  20. .shift = _shift, \
  21. .width = _width, \
  22. }
  23. struct ccu_mux {
  24. u16 reg;
  25. u32 enable;
  26. struct ccu_mux_internal mux;
  27. struct ccu_common common;
  28. };
  29. #define SUNXI_CCU_MUX(_struct, _name, _parents, _reg, _shift, _width, _flags) \
  30. struct ccu_mux _struct = { \
  31. .mux = SUNXI_CLK_MUX(_shift, _width), \
  32. .common = { \
  33. .reg = _reg, \
  34. .hw.init = CLK_HW_INIT_PARENTS(_name, \
  35. _parents, \
  36. &ccu_mux_ops, \
  37. _flags), \
  38. } \
  39. }
  40. #define SUNXI_CCU_MUX_WITH_GATE(_struct, _name, _parents, _reg, \
  41. _shift, _width, _gate, _flags) \
  42. struct ccu_mux _struct = { \
  43. .enable = _gate, \
  44. .mux = SUNXI_CLK_MUX(_shift, _width), \
  45. .common = { \
  46. .reg = _reg, \
  47. .hw.init = CLK_HW_INIT_PARENTS(_name, \
  48. _parents, \
  49. &ccu_mux_ops, \
  50. _flags), \
  51. } \
  52. }
  53. static inline struct ccu_mux *hw_to_ccu_mux(struct clk_hw *hw)
  54. {
  55. struct ccu_common *common = hw_to_ccu_common(hw);
  56. return container_of(common, struct ccu_mux, common);
  57. }
  58. extern const struct clk_ops ccu_mux_ops;
  59. void ccu_mux_helper_adjust_parent_for_prediv(struct ccu_common *common,
  60. struct ccu_mux_internal *cm,
  61. int parent_index,
  62. unsigned long *parent_rate);
  63. int ccu_mux_helper_determine_rate(struct ccu_common *common,
  64. struct ccu_mux_internal *cm,
  65. struct clk_rate_request *req,
  66. unsigned long (*round)(struct ccu_mux_internal *,
  67. unsigned long,
  68. unsigned long,
  69. void *),
  70. void *data);
  71. u8 ccu_mux_helper_get_parent(struct ccu_common *common,
  72. struct ccu_mux_internal *cm);
  73. int ccu_mux_helper_set_parent(struct ccu_common *common,
  74. struct ccu_mux_internal *cm,
  75. u8 index);
  76. #endif /* _CCU_MUX_H_ */