aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-stmpe.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpio/gpio-stmpe.c')
-rw-r--r--drivers/gpio/gpio-stmpe.c99
1 files changed, 90 insertions, 9 deletions
diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
index 845025a57240..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
@@ -127,19 +128,19 @@ static int stmpe_gpio_irq_set_type(struct irq_data *d, unsigned int type)
127 int regoffset = offset / 8; 128 int regoffset = offset / 8;
128 int mask = 1 << (offset % 8); 129 int mask = 1 << (offset % 8);
129 130
130 if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH) 131 if (type & IRQ_TYPE_LEVEL_LOW || type & IRQ_TYPE_LEVEL_HIGH)
131 return -EINVAL; 132 return -EINVAL;
132 133
133 /* STMPE801 doesn't have RE and FE registers */ 134 /* STMPE801 doesn't have RE and FE registers */
134 if (stmpe_gpio->stmpe->partnum == STMPE801) 135 if (stmpe_gpio->stmpe->partnum == STMPE801)
135 return 0; 136 return 0;
136 137
137 if (type == IRQ_TYPE_EDGE_RISING) 138 if (type & IRQ_TYPE_EDGE_RISING)
138 stmpe_gpio->regs[REG_RE][regoffset] |= mask; 139 stmpe_gpio->regs[REG_RE][regoffset] |= mask;
139 else 140 else
140 stmpe_gpio->regs[REG_RE][regoffset] &= ~mask; 141 stmpe_gpio->regs[REG_RE][regoffset] &= ~mask;
141 142
142 if (type == IRQ_TYPE_EDGE_FALLING) 143 if (type & IRQ_TYPE_EDGE_FALLING)
143 stmpe_gpio->regs[REG_FE][regoffset] |= mask; 144 stmpe_gpio->regs[REG_FE][regoffset] |= mask;
144 else 145 else
145 stmpe_gpio->regs[REG_FE][regoffset] &= ~mask; 146 stmpe_gpio->regs[REG_FE][regoffset] &= ~mask;
@@ -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
215static 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
275static 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
214static struct irq_chip stmpe_gpio_irq_chip = { 286static 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)
@@ -308,6 +383,12 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
308 if (ret) 383 if (ret)
309 goto out_free; 384 goto out_free;
310 385
386 ret = gpiochip_add(&stmpe_gpio->chip);
387 if (ret) {
388 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
389 goto out_disable;
390 }
391
311 if (irq > 0) { 392 if (irq > 0) {
312 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 393 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
313 stmpe_gpio_irq, IRQF_ONESHOT, 394 stmpe_gpio_irq, IRQF_ONESHOT,
@@ -324,14 +405,13 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
324 if (ret) { 405 if (ret) {
325 dev_err(&pdev->dev, 406 dev_err(&pdev->dev,
326 "could not connect irqchip to gpiochip\n"); 407 "could not connect irqchip to gpiochip\n");
327 return ret; 408 goto out_disable;
328 } 409 }
329 }
330 410
331 ret = gpiochip_add(&stmpe_gpio->chip); 411 gpiochip_set_chained_irqchip(&stmpe_gpio->chip,
332 if (ret) { 412 &stmpe_gpio_irq_chip,
333 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); 413 irq,
334 goto out_disable; 414 NULL);
335 } 415 }
336 416
337 if (pdata && pdata->setup) 417 if (pdata && pdata->setup)
@@ -343,6 +423,7 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
343 423
344out_disable: 424out_disable:
345 stmpe_disable(stmpe, STMPE_BLOCK_GPIO); 425 stmpe_disable(stmpe, STMPE_BLOCK_GPIO);
426 gpiochip_remove(&stmpe_gpio->chip);
346out_free: 427out_free:
347 kfree(stmpe_gpio); 428 kfree(stmpe_gpio);
348 return ret; 429 return ret;