0258-clk-bcm2835-expose-raw-clock-registers-via-debugfs.patch 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. From db6d450ea27bd6e355561539c0eedaa54c923471 Mon Sep 17 00:00:00 2001
  2. From: Martin Sperl <kernel@martin.sperl.org>
  3. Date: Mon, 29 Feb 2016 14:20:15 +0000
  4. Subject: [PATCH] clk: bcm2835: expose raw clock-registers via debugfs
  5. For debugging purposes under some circumstance
  6. it helps to be able to see the actual clock registers.
  7. E.g: when looking at the clock divider it is helpful to
  8. see what the actual clock divider is.
  9. This patch exposes all the clock registers specific to each
  10. clock/pll/pll-divider via debugfs.
  11. Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
  12. Signed-off-by: Eric Anholt <eric@anholt.net>
  13. Acked-by: Eric Anholt <eric@anholt.net>
  14. (cherry picked from commit 96bf9c69d5729781018a00f08e2ae395ec3346b4)
  15. ---
  16. drivers/clk/bcm/clk-bcm2835.c | 101 ++++++++++++++++++++++++++++++++++++++++++
  17. 1 file changed, 101 insertions(+)
  18. --- a/drivers/clk/bcm/clk-bcm2835.c
  19. +++ b/drivers/clk/bcm/clk-bcm2835.c
  20. @@ -37,6 +37,7 @@
  21. #include <linux/clk-provider.h>
  22. #include <linux/clkdev.h>
  23. #include <linux/clk/bcm2835.h>
  24. +#include <linux/debugfs.h>
  25. #include <linux/module.h>
  26. #include <linux/of.h>
  27. #include <linux/platform_device.h>
  28. @@ -313,6 +314,27 @@ static inline u32 cprman_read(struct bcm
  29. return readl(cprman->regs + reg);
  30. }
  31. +static int bcm2835_debugfs_regset(struct bcm2835_cprman *cprman, u32 base,
  32. + struct debugfs_reg32 *regs, size_t nregs,
  33. + struct dentry *dentry)
  34. +{
  35. + struct dentry *regdump;
  36. + struct debugfs_regset32 *regset;
  37. +
  38. + regset = devm_kzalloc(cprman->dev, sizeof(*regset), GFP_KERNEL);
  39. + if (!regset)
  40. + return -ENOMEM;
  41. +
  42. + regset->regs = regs;
  43. + regset->nregs = nregs;
  44. + regset->base = cprman->regs + base;
  45. +
  46. + regdump = debugfs_create_regset32("regdump", S_IRUGO, dentry,
  47. + regset);
  48. +
  49. + return regdump ? 0 : -ENOMEM;
  50. +}
  51. +
  52. /*
  53. * These are fixed clocks. They're probably not all root clocks and it may
  54. * be possible to turn them on and off but until this is mapped out better
  55. @@ -1050,6 +1072,36 @@ static int bcm2835_pll_set_rate(struct c
  56. return 0;
  57. }
  58. +static int bcm2835_pll_debug_init(struct clk_hw *hw,
  59. + struct dentry *dentry)
  60. +{
  61. + struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  62. + struct bcm2835_cprman *cprman = pll->cprman;
  63. + const struct bcm2835_pll_data *data = pll->data;
  64. + struct debugfs_reg32 *regs;
  65. +
  66. + regs = devm_kzalloc(cprman->dev, 7 * sizeof(*regs), GFP_KERNEL);
  67. + if (!regs)
  68. + return -ENOMEM;
  69. +
  70. + regs[0].name = "cm_ctrl";
  71. + regs[0].offset = data->cm_ctrl_reg;
  72. + regs[1].name = "a2w_ctrl";
  73. + regs[1].offset = data->a2w_ctrl_reg;
  74. + regs[2].name = "frac";
  75. + regs[2].offset = data->frac_reg;
  76. + regs[3].name = "ana0";
  77. + regs[3].offset = data->ana_reg_base + 0 * 4;
  78. + regs[4].name = "ana1";
  79. + regs[4].offset = data->ana_reg_base + 1 * 4;
  80. + regs[5].name = "ana2";
  81. + regs[5].offset = data->ana_reg_base + 2 * 4;
  82. + regs[6].name = "ana3";
  83. + regs[6].offset = data->ana_reg_base + 3 * 4;
  84. +
  85. + return bcm2835_debugfs_regset(cprman, 0, regs, 7, dentry);
  86. +}
  87. +
  88. static const struct clk_ops bcm2835_pll_clk_ops = {
  89. .is_prepared = bcm2835_pll_is_on,
  90. .prepare = bcm2835_pll_on,
  91. @@ -1057,6 +1109,7 @@ static const struct clk_ops bcm2835_pll_
  92. .recalc_rate = bcm2835_pll_get_rate,
  93. .set_rate = bcm2835_pll_set_rate,
  94. .round_rate = bcm2835_pll_round_rate,
  95. + .debug_init = bcm2835_pll_debug_init,
  96. };
  97. struct bcm2835_pll_divider {
  98. @@ -1159,6 +1212,26 @@ static int bcm2835_pll_divider_set_rate(
  99. return 0;
  100. }
  101. +static int bcm2835_pll_divider_debug_init(struct clk_hw *hw,
  102. + struct dentry *dentry)
  103. +{
  104. + struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
  105. + struct bcm2835_cprman *cprman = divider->cprman;
  106. + const struct bcm2835_pll_divider_data *data = divider->data;
  107. + struct debugfs_reg32 *regs;
  108. +
  109. + regs = devm_kzalloc(cprman->dev, 7 * sizeof(*regs), GFP_KERNEL);
  110. + if (!regs)
  111. + return -ENOMEM;
  112. +
  113. + regs[0].name = "cm";
  114. + regs[0].offset = data->cm_reg;
  115. + regs[1].name = "a2w";
  116. + regs[1].offset = data->a2w_reg;
  117. +
  118. + return bcm2835_debugfs_regset(cprman, 0, regs, 2, dentry);
  119. +}
  120. +
  121. static const struct clk_ops bcm2835_pll_divider_clk_ops = {
  122. .is_prepared = bcm2835_pll_divider_is_on,
  123. .prepare = bcm2835_pll_divider_on,
  124. @@ -1166,6 +1239,7 @@ static const struct clk_ops bcm2835_pll_
  125. .recalc_rate = bcm2835_pll_divider_get_rate,
  126. .set_rate = bcm2835_pll_divider_set_rate,
  127. .round_rate = bcm2835_pll_divider_round_rate,
  128. + .debug_init = bcm2835_pll_divider_debug_init,
  129. };
  130. /*
  131. @@ -1407,6 +1481,31 @@ static u8 bcm2835_clock_get_parent(struc
  132. return (src & CM_SRC_MASK) >> CM_SRC_SHIFT;
  133. }
  134. +static struct debugfs_reg32 bcm2835_debugfs_clock_reg32[] = {
  135. + {
  136. + .name = "ctl",
  137. + .offset = 0,
  138. + },
  139. + {
  140. + .name = "div",
  141. + .offset = 4,
  142. + },
  143. +};
  144. +
  145. +static int bcm2835_clock_debug_init(struct clk_hw *hw,
  146. + struct dentry *dentry)
  147. +{
  148. + struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  149. + struct bcm2835_cprman *cprman = clock->cprman;
  150. + const struct bcm2835_clock_data *data = clock->data;
  151. +
  152. + return bcm2835_debugfs_regset(
  153. + cprman, data->ctl_reg,
  154. + bcm2835_debugfs_clock_reg32,
  155. + ARRAY_SIZE(bcm2835_debugfs_clock_reg32),
  156. + dentry);
  157. +}
  158. +
  159. static const struct clk_ops bcm2835_clock_clk_ops = {
  160. .is_prepared = bcm2835_clock_is_on,
  161. .prepare = bcm2835_clock_on,
  162. @@ -1416,6 +1515,7 @@ static const struct clk_ops bcm2835_cloc
  163. .determine_rate = bcm2835_clock_determine_rate,
  164. .set_parent = bcm2835_clock_set_parent,
  165. .get_parent = bcm2835_clock_get_parent,
  166. + .debug_init = bcm2835_clock_debug_init,
  167. };
  168. static int bcm2835_vpu_clock_is_on(struct clk_hw *hw)
  169. @@ -1434,6 +1534,7 @@ static const struct clk_ops bcm2835_vpu_
  170. .determine_rate = bcm2835_clock_determine_rate,
  171. .set_parent = bcm2835_clock_set_parent,
  172. .get_parent = bcm2835_clock_get_parent,
  173. + .debug_init = bcm2835_clock_debug_init,
  174. };
  175. static struct clk *bcm2835_register_pll(struct bcm2835_cprman *cprman,