|
3 | 3 | * Copyright (c) 2015, The Linux Foundation. All rights reserved.
|
4 | 4 | */
|
5 | 5 |
|
| 6 | +#include <linux/debugfs.h> |
6 | 7 | #include <linux/err.h>
|
7 | 8 | #include <linux/io.h>
|
8 | 9 | #include <linux/nvmem-consumer.h>
|
@@ -139,6 +140,77 @@ int get_temp_common(struct tsens_sensor *s, int *temp)
|
139 | 140 | return 0;
|
140 | 141 | }
|
141 | 142 |
|
| 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 | + |
142 | 214 | static const struct regmap_config tsens_config = {
|
143 | 215 | .name = "tm",
|
144 | 216 | .reg_bits = 32,
|
@@ -199,6 +271,15 @@ int __init init_common(struct tsens_priv *priv)
|
199 | 271 | goto err_put_device;
|
200 | 272 | }
|
201 | 273 |
|
| 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 | + |
202 | 283 | priv->rf[TSENS_EN] = devm_regmap_field_alloc(dev, priv->srot_map,
|
203 | 284 | priv->fields[TSENS_EN]);
|
204 | 285 | if (IS_ERR(priv->rf[TSENS_EN])) {
|
@@ -238,6 +319,8 @@ int __init init_common(struct tsens_priv *priv)
|
238 | 319 | }
|
239 | 320 | }
|
240 | 321 |
|
| 322 | + tsens_debug_init(op); |
| 323 | + |
241 | 324 | return 0;
|
242 | 325 |
|
243 | 326 | err_put_device:
|
|
0 commit comments