clk-branch.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2013, The Linux Foundation. All rights reserved. */
  3. #ifndef __QCOM_CLK_BRANCH_H__
  4. #define __QCOM_CLK_BRANCH_H__
  5. #include <linux/bitfield.h>
  6. #include <linux/clk-provider.h>
  7. #include "clk-regmap.h"
  8. /**
  9. * struct clk_branch - gating clock with status bit and dynamic hardware gating
  10. *
  11. * @hwcg_reg: dynamic hardware clock gating register
  12. * @hwcg_bit: ORed with @hwcg_reg to enable dynamic hardware clock gating
  13. * @halt_reg: halt register
  14. * @halt_bit: ANDed with @halt_reg to test for clock halted
  15. * @halt_check: type of halt checking to perform
  16. * @clkr: handle between common and hardware-specific interfaces
  17. *
  18. * Clock which can gate its output.
  19. */
  20. struct clk_branch {
  21. u32 hwcg_reg;
  22. u32 halt_reg;
  23. u8 hwcg_bit;
  24. u8 halt_bit;
  25. u8 halt_check;
  26. #define BRANCH_VOTED BIT(7) /* Delay on disable */
  27. #define BRANCH_HALT 0 /* pol: 1 = halt */
  28. #define BRANCH_HALT_VOTED (BRANCH_HALT | BRANCH_VOTED)
  29. #define BRANCH_HALT_ENABLE 1 /* pol: 0 = halt */
  30. #define BRANCH_HALT_ENABLE_VOTED (BRANCH_HALT_ENABLE | BRANCH_VOTED)
  31. #define BRANCH_HALT_DELAY 2 /* No bit to check; just delay */
  32. #define BRANCH_HALT_SKIP 3 /* Don't check halt bit */
  33. struct clk_regmap clkr;
  34. };
  35. /**
  36. * struct clk_mem_branch - gating clock which are associated with memories
  37. *
  38. * @mem_enable_reg: branch clock memory gating register
  39. * @mem_ack_reg: branch clock memory ack register
  40. * @mem_enable_ack_mask: branch clock memory enable and ack field in @mem_ack_reg
  41. * @branch: branch clock gating handle
  42. *
  43. * Clock which can gate its memories.
  44. */
  45. struct clk_mem_branch {
  46. u32 mem_enable_reg;
  47. u32 mem_ack_reg;
  48. u32 mem_enable_ack_mask;
  49. struct clk_branch branch;
  50. };
  51. /* Branch clock common bits for HLOS-owned clocks */
  52. #define CBCR_CLK_OFF BIT(31)
  53. #define CBCR_NOC_FSM_STATUS GENMASK(30, 28)
  54. #define FSM_STATUS_ON BIT(1)
  55. #define CBCR_FORCE_MEM_CORE_ON BIT(14)
  56. #define CBCR_FORCE_MEM_PERIPH_ON BIT(13)
  57. #define CBCR_FORCE_MEM_PERIPH_OFF BIT(12)
  58. #define CBCR_WAKEUP GENMASK(11, 8)
  59. #define CBCR_SLEEP GENMASK(7, 4)
  60. #define CBCR_CLOCK_ENABLE BIT(0)
  61. static inline void qcom_branch_set_force_mem_core(struct regmap *regmap,
  62. struct clk_branch clk, bool on)
  63. {
  64. regmap_update_bits(regmap, clk.halt_reg, CBCR_FORCE_MEM_CORE_ON,
  65. on ? CBCR_FORCE_MEM_CORE_ON : 0);
  66. }
  67. static inline void qcom_branch_set_force_periph_on(struct regmap *regmap,
  68. struct clk_branch clk, bool on)
  69. {
  70. regmap_update_bits(regmap, clk.halt_reg, CBCR_FORCE_MEM_PERIPH_ON,
  71. on ? CBCR_FORCE_MEM_PERIPH_ON : 0);
  72. }
  73. static inline void qcom_branch_set_force_periph_off(struct regmap *regmap,
  74. struct clk_branch clk, bool on)
  75. {
  76. regmap_update_bits(regmap, clk.halt_reg, CBCR_FORCE_MEM_PERIPH_OFF,
  77. on ? CBCR_FORCE_MEM_PERIPH_OFF : 0);
  78. }
  79. static inline void qcom_branch_set_wakeup(struct regmap *regmap, struct clk_branch clk, u32 val)
  80. {
  81. regmap_update_bits(regmap, clk.halt_reg, CBCR_WAKEUP,
  82. FIELD_PREP(CBCR_WAKEUP, val));
  83. }
  84. static inline void qcom_branch_set_sleep(struct regmap *regmap, struct clk_branch clk, u32 val)
  85. {
  86. regmap_update_bits(regmap, clk.halt_reg, CBCR_SLEEP,
  87. FIELD_PREP(CBCR_SLEEP, val));
  88. }
  89. static inline void qcom_branch_set_clk_en(struct regmap *regmap, u32 cbcr)
  90. {
  91. regmap_update_bits(regmap, cbcr, CBCR_CLOCK_ENABLE, CBCR_CLOCK_ENABLE);
  92. }
  93. extern const struct clk_ops clk_branch_ops;
  94. extern const struct clk_ops clk_branch2_ops;
  95. extern const struct clk_ops clk_branch_simple_ops;
  96. extern const struct clk_ops clk_branch2_aon_ops;
  97. extern const struct clk_ops clk_branch2_mem_ops;
  98. extern const struct clk_ops clk_branch2_prepare_ops;
  99. #define to_clk_branch(_hw) \
  100. container_of(to_clk_regmap(_hw), struct clk_branch, clkr)
  101. #define to_clk_mem_branch(_hw) \
  102. container_of(to_clk_branch(_hw), struct clk_mem_branch, branch)
  103. #endif