clk-regmap.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2018 BayLibre, SAS.
  4. * Author: Jerome Brunet <[email protected]>
  5. */
  6. #ifndef __CLK_REGMAP_H
  7. #define __CLK_REGMAP_H
  8. #include <linux/clk-provider.h>
  9. #include <linux/regmap.h>
  10. /**
  11. * struct clk_regmap - regmap backed clock
  12. *
  13. * @hw: handle between common and hardware-specific interfaces
  14. * @map: pointer to the regmap structure controlling the clock
  15. * @data: data specific to the clock type
  16. *
  17. * Clock which is controlled by regmap backed registers. The actual type of
  18. * of the clock is controlled by the clock_ops and data.
  19. */
  20. struct clk_regmap {
  21. struct clk_hw hw;
  22. struct regmap *map;
  23. void *data;
  24. };
  25. static inline struct clk_regmap *to_clk_regmap(struct clk_hw *hw)
  26. {
  27. return container_of(hw, struct clk_regmap, hw);
  28. }
  29. /**
  30. * struct clk_regmap_gate_data - regmap backed gate specific data
  31. *
  32. * @offset: offset of the register controlling gate
  33. * @bit_idx: single bit controlling gate
  34. * @flags: hardware-specific flags
  35. *
  36. * Flags:
  37. * Same as clk_gate except CLK_GATE_HIWORD_MASK which is ignored
  38. */
  39. struct clk_regmap_gate_data {
  40. unsigned int offset;
  41. u8 bit_idx;
  42. u8 flags;
  43. };
  44. static inline struct clk_regmap_gate_data *
  45. clk_get_regmap_gate_data(struct clk_regmap *clk)
  46. {
  47. return (struct clk_regmap_gate_data *)clk->data;
  48. }
  49. extern const struct clk_ops clk_regmap_gate_ops;
  50. extern const struct clk_ops clk_regmap_gate_ro_ops;
  51. /**
  52. * struct clk_regmap_div_data - regmap backed adjustable divider specific data
  53. *
  54. * @offset: offset of the register controlling the divider
  55. * @shift: shift to the divider bit field
  56. * @width: width of the divider bit field
  57. * @table: array of value/divider pairs, last entry should have div = 0
  58. *
  59. * Flags:
  60. * Same as clk_divider except CLK_DIVIDER_HIWORD_MASK which is ignored
  61. */
  62. struct clk_regmap_div_data {
  63. unsigned int offset;
  64. u8 shift;
  65. u8 width;
  66. u8 flags;
  67. const struct clk_div_table *table;
  68. };
  69. static inline struct clk_regmap_div_data *
  70. clk_get_regmap_div_data(struct clk_regmap *clk)
  71. {
  72. return (struct clk_regmap_div_data *)clk->data;
  73. }
  74. extern const struct clk_ops clk_regmap_divider_ops;
  75. extern const struct clk_ops clk_regmap_divider_ro_ops;
  76. /**
  77. * struct clk_regmap_mux_data - regmap backed multiplexer clock specific data
  78. *
  79. * @hw: handle between common and hardware-specific interfaces
  80. * @offset: offset of theregister controlling multiplexer
  81. * @table: array of parent indexed register values
  82. * @shift: shift to multiplexer bit field
  83. * @mask: mask of mutliplexer bit field
  84. * @flags: hardware-specific flags
  85. *
  86. * Flags:
  87. * Same as clk_divider except CLK_MUX_HIWORD_MASK which is ignored
  88. */
  89. struct clk_regmap_mux_data {
  90. unsigned int offset;
  91. u32 *table;
  92. u32 mask;
  93. u8 shift;
  94. u8 flags;
  95. };
  96. static inline struct clk_regmap_mux_data *
  97. clk_get_regmap_mux_data(struct clk_regmap *clk)
  98. {
  99. return (struct clk_regmap_mux_data *)clk->data;
  100. }
  101. extern const struct clk_ops clk_regmap_mux_ops;
  102. extern const struct clk_ops clk_regmap_mux_ro_ops;
  103. #define __MESON_PCLK(_name, _reg, _bit, _ops, _pname) \
  104. struct clk_regmap _name = { \
  105. .data = &(struct clk_regmap_gate_data){ \
  106. .offset = (_reg), \
  107. .bit_idx = (_bit), \
  108. }, \
  109. .hw.init = &(struct clk_init_data) { \
  110. .name = #_name, \
  111. .ops = _ops, \
  112. .parent_hws = (const struct clk_hw *[]) { _pname }, \
  113. .num_parents = 1, \
  114. .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED), \
  115. }, \
  116. }
  117. #define MESON_PCLK(_name, _reg, _bit, _pname) \
  118. __MESON_PCLK(_name, _reg, _bit, &clk_regmap_gate_ops, _pname)
  119. #define MESON_PCLK_RO(_name, _reg, _bit, _pname) \
  120. __MESON_PCLK(_name, _reg, _bit, &clk_regmap_gate_ro_ops, _pname)
  121. #endif /* __CLK_REGMAP_H */