Skip to content

Commit 7c938f4

Browse files
idlethreaddlezcano
authored andcommitted
drivers: thermal: tsens: Add debugfs support
Dump some basic version info and sensor details into debugfs. Example from qcs404 below: --(/sys/kernel/debug) $ ls tsens/ 4a9000.thermal-sensor version --(/sys/kernel/debug) $ cat tsens/version 1.4.0 --(/sys/kernel/debug) $ cat tsens/4a9000.thermal-sensor/sensors max: 11 num: 10 id slope offset ------------------------ 0 3200 404000 1 3200 404000 2 3200 404000 3 3200 404000 4 3200 404000 5 3200 404000 6 3200 404000 7 3200 404000 8 3200 404000 9 3200 404000 Signed-off-by: Amit Kucheria <[email protected]> Reviewed-by: Stephen Boyd <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/16e39c1bbfc18b5cf6274620cd72cc63205f53a5.1572526427.git.amit.kucheria@linaro.org
1 parent 3795ad5 commit 7c938f4

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

drivers/thermal/qcom/tsens-common.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) 2015, The Linux Foundation. All rights reserved.
44
*/
55

6+
#include <linux/debugfs.h>
67
#include <linux/err.h>
78
#include <linux/io.h>
89
#include <linux/nvmem-consumer.h>
@@ -139,6 +140,77 @@ int get_temp_common(struct tsens_sensor *s, int *temp)
139140
return 0;
140141
}
141142

143+
#ifdef CONFIG_DEBUG_FS
144+
static int dbg_sensors_show(struct seq_file *s, void *data)
145+
{
146+
struct platform_device *pdev = s->private;
147+
struct tsens_priv *priv = platform_get_drvdata(pdev);
148+
int i;
149+
150+
seq_printf(s, "max: %2d\nnum: %2d\n\n",
151+
priv->feat->max_sensors, priv->num_sensors);
152+
153+
seq_puts(s, " id slope offset\n--------------------------\n");
154+
for (i = 0; i < priv->num_sensors; i++) {
155+
seq_printf(s, "%8d %8d %8d\n", priv->sensor[i].hw_id,
156+
priv->sensor[i].slope, priv->sensor[i].offset);
157+
}
158+
159+
return 0;
160+
}
161+
162+
static int dbg_version_show(struct seq_file *s, void *data)
163+
{
164+
struct platform_device *pdev = s->private;
165+
struct tsens_priv *priv = platform_get_drvdata(pdev);
166+
u32 maj_ver, min_ver, step_ver;
167+
int ret;
168+
169+
if (tsens_ver(priv) > VER_0_1) {
170+
ret = regmap_field_read(priv->rf[VER_MAJOR], &maj_ver);
171+
if (ret)
172+
return ret;
173+
ret = regmap_field_read(priv->rf[VER_MINOR], &min_ver);
174+
if (ret)
175+
return ret;
176+
ret = regmap_field_read(priv->rf[VER_STEP], &step_ver);
177+
if (ret)
178+
return ret;
179+
seq_printf(s, "%d.%d.%d\n", maj_ver, min_ver, step_ver);
180+
} else {
181+
seq_puts(s, "0.1.0\n");
182+
}
183+
184+
return 0;
185+
}
186+
187+
DEFINE_SHOW_ATTRIBUTE(dbg_version);
188+
DEFINE_SHOW_ATTRIBUTE(dbg_sensors);
189+
190+
static void tsens_debug_init(struct platform_device *pdev)
191+
{
192+
struct tsens_priv *priv = platform_get_drvdata(pdev);
193+
struct dentry *root, *file;
194+
195+
root = debugfs_lookup("tsens", NULL);
196+
if (!root)
197+
priv->debug_root = debugfs_create_dir("tsens", NULL);
198+
else
199+
priv->debug_root = root;
200+
201+
file = debugfs_lookup("version", priv->debug_root);
202+
if (!file)
203+
debugfs_create_file("version", 0444, priv->debug_root,
204+
pdev, &dbg_version_fops);
205+
206+
/* A directory for each instance of the TSENS IP */
207+
priv->debug = debugfs_create_dir(dev_name(&pdev->dev), priv->debug_root);
208+
debugfs_create_file("sensors", 0444, priv->debug, pdev, &dbg_sensors_fops);
209+
}
210+
#else
211+
static inline void tsens_debug_init(struct platform_device *pdev) {}
212+
#endif
213+
142214
static const struct regmap_config tsens_config = {
143215
.name = "tm",
144216
.reg_bits = 32,
@@ -199,6 +271,15 @@ int __init init_common(struct tsens_priv *priv)
199271
goto err_put_device;
200272
}
201273

274+
if (tsens_ver(priv) > VER_0_1) {
275+
for (i = VER_MAJOR; i <= VER_STEP; i++) {
276+
priv->rf[i] = devm_regmap_field_alloc(dev, priv->srot_map,
277+
priv->fields[i]);
278+
if (IS_ERR(priv->rf[i]))
279+
return PTR_ERR(priv->rf[i]);
280+
}
281+
}
282+
202283
priv->rf[TSENS_EN] = devm_regmap_field_alloc(dev, priv->srot_map,
203284
priv->fields[TSENS_EN]);
204285
if (IS_ERR(priv->rf[TSENS_EN])) {
@@ -238,6 +319,8 @@ int __init init_common(struct tsens_priv *priv)
238319
}
239320
}
240321

322+
tsens_debug_init(op);
323+
241324
return 0;
242325

243326
err_put_device:

drivers/thermal/qcom/tsens.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) 2015, The Linux Foundation. All rights reserved.
44
*/
55

6+
#include <linux/debugfs.h>
67
#include <linux/err.h>
78
#include <linux/module.h>
89
#include <linux/of.h>
@@ -176,6 +177,7 @@ static int tsens_remove(struct platform_device *pdev)
176177
{
177178
struct tsens_priv *priv = platform_get_drvdata(pdev);
178179

180+
debugfs_remove_recursive(priv->debug_root);
179181
if (priv->ops->disable)
180182
priv->ops->disable(priv);
181183

drivers/thermal/qcom/tsens.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ struct tsens_context {
293293
* @feat: features of the IP
294294
* @fields: bitfield locations
295295
* @ops: pointer to list of callbacks supported by this device
296+
* @debug_root: pointer to debugfs dentry for all tsens
297+
* @debug: pointer to debugfs dentry for tsens controller
296298
* @sensor: list of sensors attached to this device
297299
*/
298300
struct tsens_priv {
@@ -306,6 +308,10 @@ struct tsens_priv {
306308
const struct tsens_features *feat;
307309
const struct reg_field *fields;
308310
const struct tsens_ops *ops;
311+
312+
struct dentry *debug_root;
313+
struct dentry *debug;
314+
309315
struct tsens_sensor sensor[0];
310316
};
311317

0 commit comments

Comments
 (0)