Skip to content

Commit 96bf9c6

Browse files
msperlanholt
authored andcommitted
clk: bcm2835: expose raw clock-registers via debugfs
For debugging purposes under some circumstance it helps to be able to see the actual clock registers. E.g: when looking at the clock divider it is helpful to see what the actual clock divider is. This patch exposes all the clock registers specific to each clock/pll/pll-divider via debugfs. Signed-off-by: Martin Sperl <[email protected]> Signed-off-by: Eric Anholt <[email protected]> Acked-by: Eric Anholt <[email protected]>
1 parent 6e1e60d commit 96bf9c6

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

drivers/clk/bcm/clk-bcm2835.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/clk-provider.h>
3838
#include <linux/clkdev.h>
3939
#include <linux/clk/bcm2835.h>
40+
#include <linux/debugfs.h>
4041
#include <linux/module.h>
4142
#include <linux/of.h>
4243
#include <linux/platform_device.h>
@@ -313,6 +314,27 @@ static inline u32 cprman_read(struct bcm2835_cprman *cprman, u32 reg)
313314
return readl(cprman->regs + reg);
314315
}
315316

317+
static int bcm2835_debugfs_regset(struct bcm2835_cprman *cprman, u32 base,
318+
struct debugfs_reg32 *regs, size_t nregs,
319+
struct dentry *dentry)
320+
{
321+
struct dentry *regdump;
322+
struct debugfs_regset32 *regset;
323+
324+
regset = devm_kzalloc(cprman->dev, sizeof(*regset), GFP_KERNEL);
325+
if (!regset)
326+
return -ENOMEM;
327+
328+
regset->regs = regs;
329+
regset->nregs = nregs;
330+
regset->base = cprman->regs + base;
331+
332+
regdump = debugfs_create_regset32("regdump", S_IRUGO, dentry,
333+
regset);
334+
335+
return regdump ? 0 : -ENOMEM;
336+
}
337+
316338
/*
317339
* These are fixed clocks. They're probably not all root clocks and it may
318340
* be possible to turn them on and off but until this is mapped out better
@@ -1037,13 +1059,44 @@ static int bcm2835_pll_set_rate(struct clk_hw *hw,
10371059
return 0;
10381060
}
10391061

1062+
static int bcm2835_pll_debug_init(struct clk_hw *hw,
1063+
struct dentry *dentry)
1064+
{
1065+
struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
1066+
struct bcm2835_cprman *cprman = pll->cprman;
1067+
const struct bcm2835_pll_data *data = pll->data;
1068+
struct debugfs_reg32 *regs;
1069+
1070+
regs = devm_kzalloc(cprman->dev, 7 * sizeof(*regs), GFP_KERNEL);
1071+
if (!regs)
1072+
return -ENOMEM;
1073+
1074+
regs[0].name = "cm_ctrl";
1075+
regs[0].offset = data->cm_ctrl_reg;
1076+
regs[1].name = "a2w_ctrl";
1077+
regs[1].offset = data->a2w_ctrl_reg;
1078+
regs[2].name = "frac";
1079+
regs[2].offset = data->frac_reg;
1080+
regs[3].name = "ana0";
1081+
regs[3].offset = data->ana_reg_base + 0 * 4;
1082+
regs[4].name = "ana1";
1083+
regs[4].offset = data->ana_reg_base + 1 * 4;
1084+
regs[5].name = "ana2";
1085+
regs[5].offset = data->ana_reg_base + 2 * 4;
1086+
regs[6].name = "ana3";
1087+
regs[6].offset = data->ana_reg_base + 3 * 4;
1088+
1089+
return bcm2835_debugfs_regset(cprman, 0, regs, 7, dentry);
1090+
}
1091+
10401092
static const struct clk_ops bcm2835_pll_clk_ops = {
10411093
.is_prepared = bcm2835_pll_is_on,
10421094
.prepare = bcm2835_pll_on,
10431095
.unprepare = bcm2835_pll_off,
10441096
.recalc_rate = bcm2835_pll_get_rate,
10451097
.set_rate = bcm2835_pll_set_rate,
10461098
.round_rate = bcm2835_pll_round_rate,
1099+
.debug_init = bcm2835_pll_debug_init,
10471100
};
10481101

10491102
struct bcm2835_pll_divider {
@@ -1135,13 +1188,34 @@ static int bcm2835_pll_divider_set_rate(struct clk_hw *hw,
11351188
return 0;
11361189
}
11371190

1191+
static int bcm2835_pll_divider_debug_init(struct clk_hw *hw,
1192+
struct dentry *dentry)
1193+
{
1194+
struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
1195+
struct bcm2835_cprman *cprman = divider->cprman;
1196+
const struct bcm2835_pll_divider_data *data = divider->data;
1197+
struct debugfs_reg32 *regs;
1198+
1199+
regs = devm_kzalloc(cprman->dev, 7 * sizeof(*regs), GFP_KERNEL);
1200+
if (!regs)
1201+
return -ENOMEM;
1202+
1203+
regs[0].name = "cm";
1204+
regs[0].offset = data->cm_reg;
1205+
regs[1].name = "a2w";
1206+
regs[1].offset = data->a2w_reg;
1207+
1208+
return bcm2835_debugfs_regset(cprman, 0, regs, 2, dentry);
1209+
}
1210+
11381211
static const struct clk_ops bcm2835_pll_divider_clk_ops = {
11391212
.is_prepared = bcm2835_pll_divider_is_on,
11401213
.prepare = bcm2835_pll_divider_on,
11411214
.unprepare = bcm2835_pll_divider_off,
11421215
.recalc_rate = bcm2835_pll_divider_get_rate,
11431216
.set_rate = bcm2835_pll_divider_set_rate,
11441217
.round_rate = bcm2835_pll_divider_round_rate,
1218+
.debug_init = bcm2835_pll_divider_debug_init,
11451219
};
11461220

11471221
/*
@@ -1383,6 +1457,31 @@ static u8 bcm2835_clock_get_parent(struct clk_hw *hw)
13831457
return (src & CM_SRC_MASK) >> CM_SRC_SHIFT;
13841458
}
13851459

1460+
static struct debugfs_reg32 bcm2835_debugfs_clock_reg32[] = {
1461+
{
1462+
.name = "ctl",
1463+
.offset = 0,
1464+
},
1465+
{
1466+
.name = "div",
1467+
.offset = 4,
1468+
},
1469+
};
1470+
1471+
static int bcm2835_clock_debug_init(struct clk_hw *hw,
1472+
struct dentry *dentry)
1473+
{
1474+
struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
1475+
struct bcm2835_cprman *cprman = clock->cprman;
1476+
const struct bcm2835_clock_data *data = clock->data;
1477+
1478+
return bcm2835_debugfs_regset(
1479+
cprman, data->ctl_reg,
1480+
bcm2835_debugfs_clock_reg32,
1481+
ARRAY_SIZE(bcm2835_debugfs_clock_reg32),
1482+
dentry);
1483+
}
1484+
13861485
static const struct clk_ops bcm2835_clock_clk_ops = {
13871486
.is_prepared = bcm2835_clock_is_on,
13881487
.prepare = bcm2835_clock_on,
@@ -1392,6 +1491,7 @@ static const struct clk_ops bcm2835_clock_clk_ops = {
13921491
.determine_rate = bcm2835_clock_determine_rate,
13931492
.set_parent = bcm2835_clock_set_parent,
13941493
.get_parent = bcm2835_clock_get_parent,
1494+
.debug_init = bcm2835_clock_debug_init,
13951495
};
13961496

13971497
static int bcm2835_vpu_clock_is_on(struct clk_hw *hw)
@@ -1410,6 +1510,7 @@ static const struct clk_ops bcm2835_vpu_clock_clk_ops = {
14101510
.determine_rate = bcm2835_clock_determine_rate,
14111511
.set_parent = bcm2835_clock_set_parent,
14121512
.get_parent = bcm2835_clock_get_parent,
1513+
.debug_init = bcm2835_clock_debug_init,
14131514
};
14141515

14151516
static struct clk *bcm2835_register_pll(struct bcm2835_cprman *cprman,

0 commit comments

Comments
 (0)