From patchwork Wed Apr 30 12:36:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 29415 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C6B37203F3 for ; Wed, 30 Apr 2014 12:37:01 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rd18sf8386214iec.4 for ; Wed, 30 Apr 2014 05:37:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=h8KkGGZNJxbb3UsAzKNccIaLAIHWy/j5jAoNzNOFMYI=; b=mBzhZec1D0dgN+/czGHMiia242BYa0loH2spTbvx/UD8Rr1ZLiosi1jVgzNjjFyLRe hbWk/LDNdmrwlYvDBvgnD1MamkKn/1+G1GLZYL6Kqs35snJqCnj/sIykxyohCWbT8uRf pPDoP+9m63QRiQxR1bV8brNDOEJVSPtw2B6SeSrnhSA8lAY4woj3X1R/pntzdvczHoi/ 86mrpZG6sVQDGpMDyAV2gjYgpTvUi0dymMm7f75yrHYIajEV/hilu56X8//cgYTCsARx OIKLmlTXnCVtpeJDHbbqAML06v3Gbbg9m++P3y1oEq43H7qH6Kmyto2+4P4UnhXtJDyy /koA== X-Gm-Message-State: ALoCoQkPQ8dLmJluCTXxVdJVVoKxmufwrzUdXZYvK8JNndc1yPsAWzjcr2HYU/efAdOMCxAhWImu X-Received: by 10.43.94.71 with SMTP id bx7mr1963605icc.2.1398861419406; Wed, 30 Apr 2014 05:36:59 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.70 with SMTP id u64ls558783qgd.80.gmail; Wed, 30 Apr 2014 05:36:59 -0700 (PDT) X-Received: by 10.220.161.8 with SMTP id p8mr3796911vcx.4.1398861419231; Wed, 30 Apr 2014 05:36:59 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id vb6si5283926vec.20.2014.04.30.05.36.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Apr 2014 05:36:59 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id ik5so2057456vcb.18 for ; Wed, 30 Apr 2014 05:36:59 -0700 (PDT) X-Received: by 10.58.31.136 with SMTP id a8mr3951754vei.20.1398861419149; Wed, 30 Apr 2014 05:36:59 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp275347vcb; Wed, 30 Apr 2014 05:36:58 -0700 (PDT) X-Received: by 10.66.231.40 with SMTP id td8mr7988318pac.103.1398861418330; Wed, 30 Apr 2014 05:36:58 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fd9si16857279pad.347.2014.04.30.05.36.57; Wed, 30 Apr 2014 05:36:57 -0700 (PDT) Received-SPF: none (google.com: linux-input-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758914AbaD3Mgu (ORCPT ); Wed, 30 Apr 2014 08:36:50 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:52556 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750711AbaD3Mgs (ORCPT ); Wed, 30 Apr 2014 08:36:48 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s3UCaifS006549; Wed, 30 Apr 2014 07:36:44 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s3UCaiQT031481; Wed, 30 Apr 2014 07:36:44 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Wed, 30 Apr 2014 07:36:44 -0500 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s3UCaZTC018190; Wed, 30 Apr 2014 07:36:42 -0500 From: Roger Quadros To: CC: , , , , , , , , Roger Quadros Subject: [PATCH v3 2/7] Input: pixcir_i2c_ts: Initialize interrupt mode and power mode Date: Wed, 30 Apr 2014 15:36:27 +0300 Message-ID: <1398861392-8959-3-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398861392-8959-1-git-send-email-rogerq@ti.com> References: <1398861392-8959-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rogerq@ti.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Introduce helper functions to configure power and interrupt registers. Default to IDLE mode on probe as device supports auto wakeup to ACVIE mode on detecting finger touch. Configure interrupt mode and polarity on start up. Power down on device closure or module removal. Signed-off-by: Roger Quadros Acked-by: Mugunthan V N --- drivers/input/touchscreen/pixcir_i2c_ts.c | 179 +++++++++++++++++++++++++++++- include/linux/input/pixcir_ts.h | 42 +++++++ 2 files changed, 218 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/pixcir_i2c_ts.c b/drivers/input/touchscreen/pixcir_i2c_ts.c index 45bc2d1..670aa6e 100644 --- a/drivers/input/touchscreen/pixcir_i2c_ts.c +++ b/drivers/input/touchscreen/pixcir_i2c_ts.c @@ -100,6 +100,168 @@ static irqreturn_t pixcir_ts_isr(int irq, void *dev_id) return IRQ_HANDLED; } +static int pixcir_set_power_mode(struct pixcir_i2c_ts_data *ts, + enum pixcir_power_mode mode) +{ + struct device *dev = &ts->client->dev; + int ret; + + ret = i2c_smbus_read_byte_data(ts->client, PIXCIR_REG_POWER_MODE); + if (ret < 0) { + dev_err(dev, "%s: can't read reg 0x%x : %d\n", + __func__, PIXCIR_REG_POWER_MODE, ret); + return ret; + } + + ret &= ~PIXCIR_POWER_MODE_MASK; + ret |= mode; + + /* Always AUTO_IDLE */ + ret |= PIXCIR_POWER_ALLOW_IDLE; + + ret = i2c_smbus_write_byte_data(ts->client, PIXCIR_REG_POWER_MODE, ret); + if (ret < 0) { + dev_err(dev, "%s: can't write reg 0x%x : %d\n", + __func__, PIXCIR_REG_POWER_MODE, ret); + return ret; + } + + return 0; +} + +/* + * Set the interrupt mode for the device i.e. ATTB line behaviour + * + * @polarity : 1 for active high, 0 for active low. + */ +static int pixcir_set_int_mode(struct pixcir_i2c_ts_data *ts, + enum pixcir_int_mode mode, + bool polarity) +{ + struct device *dev = &ts->client->dev; + int ret; + + ret = i2c_smbus_read_byte_data(ts->client, PIXCIR_REG_INT_MODE); + if (ret < 0) { + dev_err(dev, "%s: can't read reg 0x%x : %d\n", + __func__, PIXCIR_REG_INT_MODE, ret); + return ret; + } + + ret &= ~PIXCIR_INT_MODE_MASK; + ret |= mode; + + if (polarity) + ret |= PIXCIR_INT_POL_HIGH; + else + ret &= ~PIXCIR_INT_POL_HIGH; + + ret = i2c_smbus_write_byte_data(ts->client, PIXCIR_REG_INT_MODE, ret); + if (ret < 0) { + dev_err(dev, "%s: can't write reg 0x%x : %d\n", + __func__, PIXCIR_REG_INT_MODE, ret); + return ret; + } + + return 0; +} + +/* + * Enable/disable interrupt generation + */ +static int pixcir_int_enable(struct pixcir_i2c_ts_data *ts, bool enable) +{ + struct device *dev = &ts->client->dev; + int ret; + + ret = i2c_smbus_read_byte_data(ts->client, PIXCIR_REG_INT_MODE); + if (ret < 0) { + dev_err(dev, "%s: can't read reg 0x%x : %d\n", + __func__, PIXCIR_REG_INT_MODE, ret); + return ret; + } + + if (enable) + ret |= PIXCIR_INT_ENABLE; + else + ret &= ~PIXCIR_INT_ENABLE; + + ret = i2c_smbus_write_byte_data(ts->client, PIXCIR_REG_INT_MODE, ret); + if (ret < 0) { + dev_err(dev, "%s: can't write reg 0x%x : %d\n", + __func__, PIXCIR_REG_INT_MODE, ret); + return ret; + } + + return 0; +} + +static int pixcir_start(struct pixcir_i2c_ts_data *ts) +{ + struct device *dev = &ts->client->dev; + int ret; + + /* LEVEL_TOUCH interrupt with active low polarity */ + ret = pixcir_set_int_mode(ts, PIXCIR_INT_LEVEL_TOUCH, 0); + if (ret) { + dev_err(dev, "Failed to set interrupt mode\n"); + return ret; + } + + ts->exiting = false; + mb(); /* Update status before IRQ can fire */ + + /* enable interrupt generation */ + ret = pixcir_int_enable(ts, 1); + if (ret) { + dev_err(dev, "Failed to enable interrupt generation\n"); + return ret; + } + + return 0; +} + +static int pixcir_stop(struct pixcir_i2c_ts_data *ts) +{ + struct device *dev = &ts->client->dev; + int ret; + + /* exit ISR if running, no more report parsing */ + ts->exiting = true; + mb(); /* update status before we synchronize irq */ + + /* disable ISR from running again */ + disable_irq(ts->client->irq); + + /* wait till running ISR complete */ + synchronize_irq(ts->client->irq); + + /* disable interrupt generation */ + ret = pixcir_int_enable(ts, 0); + if (ret) + dev_err(dev, "Failed to disable interrupt generation\n"); + + /* restore IRQ */ + enable_irq(ts->client->irq); + + return ret; +} + +static int pixcir_input_open(struct input_dev *dev) +{ + struct pixcir_i2c_ts_data *ts = input_get_drvdata(dev); + + return pixcir_start(ts); +} + +static void pixcir_input_close(struct input_dev *dev) +{ + struct pixcir_i2c_ts_data *ts = input_get_drvdata(dev); + + pixcir_stop(ts); +} + + #ifdef CONFIG_PM_SLEEP static int pixcir_i2c_ts_suspend(struct device *dev) { @@ -157,6 +319,8 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, input->name = client->name; input->id.bustype = BUS_I2C; input->dev.parent = &client->dev; + input->open = pixcir_input_open; + input->close = pixcir_input_close; __set_bit(EV_KEY, input->evbit); __set_bit(EV_ABS, input->evbit); @@ -176,6 +340,18 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, return error; } + /* Always be in IDLE mode to save power, device supports auto wake */ + error = pixcir_set_power_mode(tsdata, PIXCIR_POWER_IDLE); + if (error) { + dev_err(dev, "Failed to set IDLE mode\n"); + return error; + } + + /* Stop device till opened */ + error = pixcir_stop(tsdata); + if (error) + return error; + error = input_register_device(input); if (error) return error; @@ -192,9 +368,6 @@ static int pixcir_i2c_ts_remove(struct i2c_client *client) device_init_wakeup(&client->dev, 0); - tsdata->exiting = true; - mb(); - input_unregister_device(tsdata->input); return 0; diff --git a/include/linux/input/pixcir_ts.h b/include/linux/input/pixcir_ts.h index 7163d91..7942804 100644 --- a/include/linux/input/pixcir_ts.h +++ b/include/linux/input/pixcir_ts.h @@ -1,6 +1,48 @@ #ifndef _PIXCIR_I2C_TS_H #define _PIXCIR_I2C_TS_H +/* + * Register map + */ +#define PIXCIR_REG_POWER_MODE 51 +#define PIXCIR_REG_INT_MODE 52 + +/* + * Power modes: + * active: max scan speed + * idle: lower scan speed with automatic transition to active on touch + * halt: datasheet says sleep but this is more like halt as the chip + * clocks are cut and it can only be brought out of this mode + * using the RESET pin. + */ +enum pixcir_power_mode { + PIXCIR_POWER_ACTIVE, + PIXCIR_POWER_IDLE, + PIXCIR_POWER_HALT, +}; + +#define PIXCIR_POWER_MODE_MASK 0x03 +#define PIXCIR_POWER_ALLOW_IDLE (1UL << 2) + +/* + * Interrupt modes: + * periodical: interrupt is asserted periodicaly + * diff coordinates: interrupt is asserted when coordinates change + * level on touch: interrupt level asserted during touch + * pulse on touch: interrupt pulse asserted druing touch + * + */ +enum pixcir_int_mode { + PIXCIR_INT_PERIODICAL, + PIXCIR_INT_DIFF_COORD, + PIXCIR_INT_LEVEL_TOUCH, + PIXCIR_INT_PULSE_TOUCH, +}; + +#define PIXCIR_INT_MODE_MASK 0x03 +#define PIXCIR_INT_ENABLE (1UL << 3) +#define PIXCIR_INT_POL_HIGH (1UL << 2) + struct pixcir_ts_platform_data { int (*attb_read_val)(void); int x_max;