ccu_common.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #define CCU_FEATURE_ALL_PREDIV BIT(4)
  22. #define CCU_FEATURE_LOCK_REG BIT(5)
  23. struct device_node;
  24. #define CLK_HW_INIT(_name, _parent, _ops, _flags) \
  25. &(struct clk_init_data) { \
  26. .flags = _flags, \
  27. .name = _name, \
  28. .parent_names = (const char *[]) { _parent }, \
  29. .num_parents = 1, \
  30. .ops = _ops, \
  31. }
  32. #define CLK_HW_INIT_PARENTS(_name, _parents, _ops, _flags) \
  33. &(struct clk_init_data) { \
  34. .flags = _flags, \
  35. .name = _name, \
  36. .parent_names = _parents, \
  37. .num_parents = ARRAY_SIZE(_parents), \
  38. .ops = _ops, \
  39. }
  40. #define CLK_FIXED_FACTOR(_struct, _name, _parent, \
  41. _div, _mult, _flags) \
  42. struct clk_fixed_factor _struct = { \
  43. .div = _div, \
  44. .mult = _mult, \
  45. .hw.init = CLK_HW_INIT(_name, \
  46. _parent, \
  47. &clk_fixed_factor_ops, \
  48. _flags), \
  49. }
  50. struct ccu_common {
  51. void __iomem *base;
  52. u16 reg;
  53. u16 lock_reg;
  54. u32 prediv;
  55. unsigned long features;
  56. spinlock_t *lock;
  57. struct clk_hw hw;
  58. };
  59. static inline struct ccu_common *hw_to_ccu_common(struct clk_hw *hw)
  60. {
  61. return container_of(hw, struct ccu_common, hw);
  62. }
  63. struct sunxi_ccu_desc {
  64. struct ccu_common **ccu_clks;
  65. unsigned long num_ccu_clks;
  66. struct clk_hw_onecell_data *hw_clks;
  67. struct ccu_reset_map *resets;
  68. unsigned long num_resets;
  69. };
  70. void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock);
  71. struct ccu_pll_nb {
  72. struct notifier_block clk_nb;
  73. struct ccu_common *common;
  74. u32 enable;
  75. u32 lock;
  76. };
  77. #define to_ccu_pll_nb(_nb) container_of(_nb, struct ccu_pll_nb, clk_nb)
  78. int ccu_pll_notifier_register(struct ccu_pll_nb *pll_nb);
  79. int sunxi_ccu_probe(struct device_node *node, void __iomem *reg,
  80. const struct sunxi_ccu_desc *desc);
  81. #endif /* _COMMON_H_ */