diff options
| author | Linus Walleij <linus.walleij@linaro.org> | 2014-10-02 01:55:41 -0400 |
|---|---|---|
| committer | Linus Walleij <linus.walleij@linaro.org> | 2014-10-02 10:06:59 -0400 |
| commit | 27ec8a9cb504e9995c123dc74e0cca0cba81d07f (patch) | |
| tree | 7f052c9e5ad3bb2b5babc505cc2cfc994868e36a | |
| parent | 1fe3bd9e347bcea63fa8be212001372720968765 (diff) | |
gpio: stmpe: add verbose debug code
To troubleshoot the STMPE GPIO driver, some more detailed
debug information giving the exact info on how each pin is
used will be helpful.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
| -rw-r--r-- | drivers/gpio/gpio-stmpe.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c index 866baa879473..85c5b1974294 100644 --- a/drivers/gpio/gpio-stmpe.c +++ b/drivers/gpio/gpio-stmpe.c | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <linux/interrupt.h> | 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/of.h> | 14 | #include <linux/of.h> |
| 15 | #include <linux/mfd/stmpe.h> | 15 | #include <linux/mfd/stmpe.h> |
| 16 | #include <linux/seq_file.h> | ||
| 16 | 17 | ||
| 17 | /* | 18 | /* |
| 18 | * These registers are modified under the irq bus lock and cached to avoid | 19 | * These registers are modified under the irq bus lock and cached to avoid |
| @@ -211,6 +212,77 @@ static void stmpe_gpio_irq_unmask(struct irq_data *d) | |||
| 211 | stmpe_gpio->regs[REG_IE][regoffset] |= mask; | 212 | stmpe_gpio->regs[REG_IE][regoffset] |= mask; |
| 212 | } | 213 | } |
| 213 | 214 | ||
| 215 | static void stmpe_dbg_show_one(struct seq_file *s, | ||
| 216 | struct gpio_chip *gc, | ||
| 217 | unsigned offset, unsigned gpio) | ||
| 218 | { | ||
| 219 | struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); | ||
| 220 | struct stmpe *stmpe = stmpe_gpio->stmpe; | ||
| 221 | const char *label = gpiochip_is_requested(gc, offset); | ||
| 222 | int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8); | ||
| 223 | bool val = !!stmpe_gpio_get(gc, offset); | ||
| 224 | u8 dir_reg = stmpe->regs[STMPE_IDX_GPDR_LSB] - (offset / 8); | ||
| 225 | u8 mask = 1 << (offset % 8); | ||
| 226 | int ret; | ||
| 227 | u8 dir; | ||
| 228 | |||
| 229 | ret = stmpe_reg_read(stmpe, dir_reg); | ||
| 230 | if (ret < 0) | ||
| 231 | return; | ||
| 232 | dir = !!(ret & mask); | ||
| 233 | |||
| 234 | if (dir) { | ||
| 235 | seq_printf(s, " gpio-%-3d (%-20.20s) out %s", | ||
| 236 | gpio, label ?: "(none)", | ||
| 237 | val ? "hi" : "lo"); | ||
| 238 | } else { | ||
| 239 | u8 edge_det_reg = stmpe->regs[STMPE_IDX_GPEDR_MSB] + num_banks - 1 - (offset / 8); | ||
| 240 | u8 rise_reg = stmpe->regs[STMPE_IDX_GPRER_LSB] - (offset / 8); | ||
| 241 | u8 fall_reg = stmpe->regs[STMPE_IDX_GPFER_LSB] - (offset / 8); | ||
| 242 | u8 irqen_reg = stmpe->regs[STMPE_IDX_IEGPIOR_LSB] - (offset / 8); | ||
| 243 | bool edge_det; | ||
| 244 | bool rise; | ||
| 245 | bool fall; | ||
| 246 | bool irqen; | ||
| 247 | |||
| 248 | ret = stmpe_reg_read(stmpe, edge_det_reg); | ||
| 249 | if (ret < 0) | ||
| 250 | return; | ||
| 251 | edge_det = !!(ret & mask); | ||
| 252 | ret = stmpe_reg_read(stmpe, rise_reg); | ||
| 253 | if (ret < 0) | ||
| 254 | return; | ||
| 255 | rise = !!(ret & mask); | ||
| 256 | ret = stmpe_reg_read(stmpe, fall_reg); | ||
| 257 | if (ret < 0) | ||
| 258 | return; | ||
| 259 | fall = !!(ret & mask); | ||
| 260 | ret = stmpe_reg_read(stmpe, irqen_reg); | ||
| 261 | if (ret < 0) | ||
| 262 | return; | ||
| 263 | irqen = !!(ret & mask); | ||
| 264 | |||
| 265 | seq_printf(s, " gpio-%-3d (%-20.20s) in %s %s %s%s%s", | ||
| 266 | gpio, label ?: "(none)", | ||
| 267 | val ? "hi" : "lo", | ||
| 268 | edge_det ? "edge-asserted" : "edge-inactive", | ||
| 269 | irqen ? "IRQ-enabled" : "", | ||
| 270 | rise ? " rising-edge-detection" : "", | ||
| 271 | fall ? " falling-edge-detection" : ""); | ||
| 272 | } | ||
| 273 | } | ||
| 274 | |||
| 275 | static void stmpe_dbg_show(struct seq_file *s, struct gpio_chip *gc) | ||
| 276 | { | ||
| 277 | unsigned i; | ||
| 278 | unsigned gpio = gc->base; | ||
| 279 | |||
| 280 | for (i = 0; i < gc->ngpio; i++, gpio++) { | ||
| 281 | stmpe_dbg_show_one(s, gc, i, gpio); | ||
| 282 | seq_printf(s, "\n"); | ||
| 283 | } | ||
| 284 | } | ||
| 285 | |||
| 214 | static struct irq_chip stmpe_gpio_irq_chip = { | 286 | static struct irq_chip stmpe_gpio_irq_chip = { |
| 215 | .name = "stmpe-gpio", | 287 | .name = "stmpe-gpio", |
| 216 | .irq_bus_lock = stmpe_gpio_irq_lock, | 288 | .irq_bus_lock = stmpe_gpio_irq_lock, |
| @@ -293,6 +365,9 @@ static int stmpe_gpio_probe(struct platform_device *pdev) | |||
| 293 | #endif | 365 | #endif |
| 294 | stmpe_gpio->chip.base = -1; | 366 | stmpe_gpio->chip.base = -1; |
| 295 | 367 | ||
| 368 | if (IS_ENABLED(CONFIG_DEBUG_FS)) | ||
| 369 | stmpe_gpio->chip.dbg_show = stmpe_dbg_show; | ||
| 370 | |||
| 296 | if (pdata) | 371 | if (pdata) |
| 297 | stmpe_gpio->norequest_mask = pdata->norequest_mask; | 372 | stmpe_gpio->norequest_mask = pdata->norequest_mask; |
| 298 | else if (np) | 373 | else if (np) |
