From patchwork Wed May 12 13:09:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jelle Martijn Kok X-Patchwork-Id: 99005 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4CD9stl004406 for ; Wed, 12 May 2010 13:09:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751435Ab0ELNJy (ORCPT ); Wed, 12 May 2010 09:09:54 -0400 Received: from lime.solrad.nl ([213.193.238.107]:49555 "EHLO lime.solrad.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751194Ab0ELNJx (ORCPT ); Wed, 12 May 2010 09:09:53 -0400 Received: from green.youcom.nl (green.youcom.nl [::ffff:195.64.93.233]) (TLS: TLSv1/SSLv3,256bits,AES256-SHA) by lime.solrad.nl with esmtp; Wed, 12 May 2010 15:09:52 +0200 id 000D6AD3.4BEAA8A0.00002D37 Received: from [192.168.5.122] ([::ffff:192.168.5.122]) (AUTH: LOGIN jmkok) by green.youcom.nl with esmtp; Wed, 12 May 2010 15:09:52 +0200 id 0000000001F28543.000000004BEAA8A0.00007F9D Message-ID: <4BEAA89F.10509@youcom.nl> Date: Wed, 12 May 2010 15:09:51 +0200 From: Jelle Martijn Kok Organization: You/Com Audiocommunicatie BV User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4 MIME-Version: 1.0 To: linux-input@vger.kernel.org Subject: [PATCH 2/3] rotary_encoder: added initial_value, min_value and max_value Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 12 May 2010 13:09:55 +0000 (UTC) diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index 24621b8..1c9728f 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -70,17 +70,18 @@ static irqreturn_t rotary_encoder_irq(int irq, void *dev_id) if (dir == -1) { /* turning counter-clockwise */ - if (pdata->rollover) - pos += pdata->steps; - if (pos) + if (pos > pdata->min_value) pos--; - } else { + else if (pdata->rollover) + pos = pdata->max_value; + } + else { /* turning clockwise */ - if (pdata->rollover || pos < pdata->steps) + if (pos < pdata->max_value) pos++; + else if (pdata->rollover) + pos = pdata->min_value; } - if (pdata->rollover) - pos %= pdata->steps; encoder->pos = pos; input_report_abs(encoder->input, pdata->axis, encoder->pos); @@ -119,6 +120,10 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) encoder->pdata = pdata; encoder->irq_a = gpio_to_irq(pdata->gpio_a); encoder->irq_b = gpio_to_irq(pdata->gpio_b); + encoder->pos = pdata->initial_value; + /* ensure backwards compatibility with the steps parameter */ + if (!pdata->max_value) + pdata->max_value = pdata->steps-1; /* create and register the input driver */ input->name = pdev->name; @@ -131,7 +136,7 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) } else { input->evbit[0] = BIT_MASK(EV_ABS); input_set_abs_params(encoder->input, - pdata->axis, 0, pdata->steps, 0, 1); + pdata->axis, pdata->min_value, pdata->max_value, 0, 1); } err = input_register_device(input); diff --git a/include/linux/rotary_encoder.h b/include/linux/rotary_encoder.h index 215278b..a0d15d9 100644 --- a/include/linux/rotary_encoder.h +++ b/include/linux/rotary_encoder.h @@ -2,7 +2,10 @@ #define __ROTARY_ENCODER_H__ struct rotary_encoder_platform_data { - unsigned int steps; + unsigned int steps; /* deprecated, use max_value instead */ + unsigned int initial_value; + unsigned int min_value; + unsigned int max_value; unsigned int axis; unsigned int gpio_a; unsigned int gpio_b;