aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/stmpe.c
diff options
context:
space:
mode:
authorSundar R Iyer <sundar.iyer@stericsson.com>2010-07-21 02:11:07 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2010-08-12 05:28:00 -0400
commit5981f4e65cb455a820b3d07b8e4bac506233f3ea (patch)
tree541a0ba41593bda73d1ce9b3ce004de43dcccd85 /drivers/mfd/stmpe.c
parent3faeb35ccc57e1af70c54b82063fdf4a88846084 (diff)
mfd: Add stmpe auto sleep feature
Some STMPE devices support entering sleep mode automatically on a specified timeout of inactivity on the I2C bus with the host system. Acked-by: Linus Walleij <linus.walleij@stericsson.com> Acked-by: Rabin Vincent <rabin.vincent@stericsson.com> Signed-off-by: Sundar R Iyer <sundar.iyer@stericsson.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd/stmpe.c')
-rw-r--r--drivers/mfd/stmpe.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index a7f3099fdcfd..0754c5e91995 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -455,6 +455,67 @@ static struct stmpe_variant_block stmpe1601_blocks[] = {
455 }, 455 },
456}; 456};
457 457
458/* supported autosleep timeout delay (in msecs) */
459static const int stmpe_autosleep_delay[] = {
460 4, 16, 32, 64, 128, 256, 512, 1024,
461};
462
463static int stmpe_round_timeout(int timeout)
464{
465 int i;
466
467 for (i = 0; i < ARRAY_SIZE(stmpe_autosleep_delay); i++) {
468 if (stmpe_autosleep_delay[i] >= timeout)
469 return i;
470 }
471
472 /*
473 * requests for delays longer than supported should not return the
474 * longest supported delay
475 */
476 return -EINVAL;
477}
478
479static int stmpe_autosleep(struct stmpe *stmpe, int autosleep_timeout)
480{
481 int ret;
482
483 if (!stmpe->variant->enable_autosleep)
484 return -ENOSYS;
485
486 mutex_lock(&stmpe->lock);
487 ret = stmpe->variant->enable_autosleep(stmpe, autosleep_timeout);
488 mutex_unlock(&stmpe->lock);
489
490 return ret;
491}
492
493/*
494 * Both stmpe 1601/2403 support same layout for autosleep
495 */
496static int stmpe1601_autosleep(struct stmpe *stmpe,
497 int autosleep_timeout)
498{
499 int ret, timeout;
500
501 /* choose the best available timeout */
502 timeout = stmpe_round_timeout(autosleep_timeout);
503 if (timeout < 0) {
504 dev_err(stmpe->dev, "invalid timeout\n");
505 return timeout;
506 }
507
508 ret = __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2,
509 STMPE1601_AUTOSLEEP_TIMEOUT_MASK,
510 timeout);
511 if (ret < 0)
512 return ret;
513
514 return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2,
515 STPME1601_AUTOSLEEP_ENABLE,
516 STPME1601_AUTOSLEEP_ENABLE);
517}
518
458static int stmpe1601_enable(struct stmpe *stmpe, unsigned int blocks, 519static int stmpe1601_enable(struct stmpe *stmpe, unsigned int blocks,
459 bool enable) 520 bool enable)
460{ 521{
@@ -497,6 +558,7 @@ static struct stmpe_variant_info stmpe1601 = {
497 .num_irqs = STMPE1601_NR_INTERNAL_IRQS, 558 .num_irqs = STMPE1601_NR_INTERNAL_IRQS,
498 .enable = stmpe1601_enable, 559 .enable = stmpe1601_enable,
499 .get_altfunc = stmpe1601_get_altfunc, 560 .get_altfunc = stmpe1601_get_altfunc,
561 .enable_autosleep = stmpe1601_autosleep,
500}; 562};
501 563
502/* 564/*
@@ -589,6 +651,7 @@ static struct stmpe_variant_info stmpe2403 = {
589 .num_irqs = STMPE24XX_NR_INTERNAL_IRQS, 651 .num_irqs = STMPE24XX_NR_INTERNAL_IRQS,
590 .enable = stmpe24xx_enable, 652 .enable = stmpe24xx_enable,
591 .get_altfunc = stmpe24xx_get_altfunc, 653 .get_altfunc = stmpe24xx_get_altfunc,
654 .enable_autosleep = stmpe1601_autosleep, /* same as stmpe1601 */
592}; 655};
593 656
594static struct stmpe_variant_info *stmpe_variant_info[] = { 657static struct stmpe_variant_info *stmpe_variant_info[] = {
@@ -731,6 +794,7 @@ static void stmpe_irq_remove(struct stmpe *stmpe)
731static int __devinit stmpe_chip_init(struct stmpe *stmpe) 794static int __devinit stmpe_chip_init(struct stmpe *stmpe)
732{ 795{
733 unsigned int irq_trigger = stmpe->pdata->irq_trigger; 796 unsigned int irq_trigger = stmpe->pdata->irq_trigger;
797 int autosleep_timeout = stmpe->pdata->autosleep_timeout;
734 struct stmpe_variant_info *variant = stmpe->variant; 798 struct stmpe_variant_info *variant = stmpe->variant;
735 u8 icr = STMPE_ICR_LSB_GIM; 799 u8 icr = STMPE_ICR_LSB_GIM;
736 unsigned int id; 800 unsigned int id;
@@ -766,6 +830,12 @@ static int __devinit stmpe_chip_init(struct stmpe *stmpe)
766 if (stmpe->pdata->irq_invert_polarity) 830 if (stmpe->pdata->irq_invert_polarity)
767 icr ^= STMPE_ICR_LSB_HIGH; 831 icr ^= STMPE_ICR_LSB_HIGH;
768 832
833 if (stmpe->pdata->autosleep) {
834 ret = stmpe_autosleep(stmpe, autosleep_timeout);
835 if (ret)
836 return ret;
837 }
838
769 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr); 839 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr);
770} 840}
771 841