ccu_common.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2016 Maxime Ripard. All rights reserved.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _COMMON_H_
  14. #define _COMMON_H_
  15. #include <linux/compiler.h>
  16. #include <linux/clk-provider.h>
  17. #define CCU_FEATURE_FRACTIONAL BIT(0)
  18. #define CCU_FEATURE_VARIABLE_PREDIV BIT(1)
  19. #define CCU_FEATURE_FIXED_PREDIV BIT(2)
  20. #define CCU_FEATURE_FIXED_POSTDIV BIT(3)
  21. struct device_node;
  22. #define CLK_HW_INIT(_name, _parent, _ops, _flags) \
  23. &(struct clk_init_data) { \
  24. .flags = _flags, \
  25. .name = _name, \
  26. .parent_names = (const char *[]) { _parent }, \
  27. .num_parents = 1, \
  28. .ops = _ops, \
  29. }
  30. #define CLK_HW_INIT_PARENTS(_name, _parents, _ops, _flags) \
  31. &(struct clk_init_data) { \
  32. .flags = _flags, \
  33. .name = _name, \
  34. .parent_names = _parents, \
  35. .num_parents = ARRAY_SIZE(_parents), \
  36. .ops = _ops, \
  37. }
  38. #define CLK_FIXED_FACTOR(_struct, _name, _parent, \
  39. _div, _mult, _flags) \
  40. struct clk_fixed_factor _struct = { \
  41. .div = _div, \
  42. .mult = _mult, \
  43. .hw.init = CLK_HW_INIT(_name, \
  44. _parent, \
  45. &clk_fixed_factor_ops, \
  46. _flags), \
  47. }
  48. struct ccu_common {
  49. void __iomem *base;
  50. u16 reg;
  51. unsigned long features;
  52. spinlock_t *lock;
  53. struct clk_hw hw;
  54. };
  55. static inline struct ccu_common *hw_to_ccu_common(struct clk_hw *hw)
  56. {
  57. return container_of(hw, struct ccu_common, hw);
  58. }
  59. struct sunxi_ccu_desc {
  60. struct ccu_common **ccu_clks;
  61. unsigned long num_ccu_clks;
  62. struct clk_hw_onecell_data *hw_clks;
  63. struct ccu_reset_map *resets;
  64. unsigned long num_resets;
  65. };
  66. void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock);
  67. int sunxi_ccu_probe(struct device_node *node, void __iomem *reg,
  68. const struct sunxi_ccu_desc *desc);
  69. #endif /* _COMMON_H_ */