From patchwork Fri Oct 4 12:53:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 2988691 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7BEDF9F245 for ; Fri, 4 Oct 2013 12:53:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5F9B320353 for ; Fri, 4 Oct 2013 12:53:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B0E412035D for ; Fri, 4 Oct 2013 12:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754533Ab3JDMx1 (ORCPT ); Fri, 4 Oct 2013 08:53:27 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:48268 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754477Ab3JDMxZ (ORCPT ); Fri, 4 Oct 2013 08:53:25 -0400 Received: by mail-wi0-f182.google.com with SMTP id ez12so1592896wid.3 for ; Fri, 04 Oct 2013 05:53:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UxP4ey7Q86/msMVp09TAvJEkuvOF7cBZkQ7EvwbyYWY=; b=chsGECvrKHOo5kDEkdZfaam30iCxXxo9BrMz8Cjeehti89v+/rk4c3r0BanJE/QSuD 7BuD4Rh9HIlvPkdvaym0Ar58hKf4GUEmCnfknbPJgFYvQEnBAMGsDFkrN8QbyE0YAssq dxLMwMDqdNsLMg3g7se7zRe91z2Y+0wy1Vx7GDqCf561nP3h1fT0oj6AGmGnnenjtFDv spNDSI1AFpLRQr3MZVlMRBw4niOJgp8NC9zMDCOyKToeqfDzi6u/OaDBIa1x85MrRLNZ maJWYQC9CdLg/YP5pW45FylWQiN8jRC04zRSqq7corkvvRWq+YT/qG5CIgUK5OG6iR/A ZhbA== X-Gm-Message-State: ALoCoQlTmbZPJrwj+bDA/frDtJlmUUb/I56Qqspzs04JnjyzakbqD7LQaXqtJAHjLNsp2YmEL/Sp X-Received: by 10.180.20.46 with SMTP id k14mr7310849wie.39.1380891203896; Fri, 04 Oct 2013 05:53:23 -0700 (PDT) Received: from localhost.localdomain ([190.2.109.48]) by mx.google.com with ESMTPSA id ev4sm9386566wib.7.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2013 05:53:23 -0700 (PDT) From: Ezequiel Garcia To: , Cc: Ezequiel Garcia , Daniel Mack , Dmitry Torokhov Subject: [PATCH v2 1/2] Input: rotary-encoder: Add 'stepped' irq handler Date: Fri, 4 Oct 2013 09:53:22 -0300 Message-Id: <1380891203-17617-2-git-send-email-ezequiel@vanguardiasur.com.ar> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1380891203-17617-1-git-send-email-ezequiel@vanguardiasur.com.ar> References: <1380891203-17617-1-git-send-email-ezequiel@vanguardiasur.com.ar> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some rotary-encoder devices (such as those with detents) are capable of producing a stable event on each step. This commit adds support for this case, by implementing a new interruption handler. The handler needs only detect the direction of the turn and generate an event according to this detection. Cc: Daniel Mack Cc: Dmitry Torokhov Signed-off-by: Ezequiel Garcia --- v1->v2: * Add DT property handling * Replace binary representation by hexa-decimal in the sum encoding drivers/input/misc/rotary_encoder.c | 41 +++++++++++++++++++++++++++++++++++++ include/linux/rotary_encoder.h | 1 + 2 files changed, 42 insertions(+) diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index 5b1aff8..6c7a554 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -117,6 +117,42 @@ static irqreturn_t rotary_encoder_irq(int irq, void *dev_id) return IRQ_HANDLED; } +static irqreturn_t rotary_encoder_stepped_irq(int irq, void *dev_id) +{ + struct rotary_encoder *encoder = dev_id; + int state; + unsigned char sum; + + state = rotary_encoder_get_state(encoder->pdata); + + /* + * We encode the previous and the current state using a byte. + * The previous state in the MSB nibble, the current state in the LSB + * nibble. Then use a table to decide the direction of the turn. + */ + sum = (encoder->last_stable << 4) + state; + switch (sum) { + case 0x31: + case 0x10: + case 0x02: + case 0x23: + encoder->dir = 0; /* clockwise */ + break; + /* + * TODO: Add the other case, and the illegal values should + * say a WARN (it's a BUG, but we won't stop the kernel for it :) + */ + default: + encoder->dir = 1; + } + + rotary_encoder_report_event(encoder); + + encoder->last_stable = state; + + return IRQ_HANDLED; +} + static irqreturn_t rotary_encoder_half_period_irq(int irq, void *dev_id) { struct rotary_encoder *encoder = dev_id; @@ -180,6 +216,8 @@ static struct rotary_encoder_platform_data *rotary_encoder_parse_dt(struct devic "rotary-encoder,rollover", NULL); pdata->half_period = !!of_get_property(np, "rotary-encoder,half-period", NULL); + pdata->on_each_step = !!of_get_property(np, + "rotary-encoder,on-each-step", NULL); return pdata; } @@ -254,6 +292,9 @@ static int rotary_encoder_probe(struct platform_device *pdev) if (pdata->half_period) { handler = &rotary_encoder_half_period_irq; encoder->last_stable = rotary_encoder_get_state(pdata); + } else if (pdata->on_each_step) { + handler = &rotary_encoder_stepped_irq; + encoder->last_stable = rotary_encoder_get_state(pdata); } else { handler = &rotary_encoder_irq; } diff --git a/include/linux/rotary_encoder.h b/include/linux/rotary_encoder.h index 3f594dc..499f6f7 100644 --- a/include/linux/rotary_encoder.h +++ b/include/linux/rotary_encoder.h @@ -11,6 +11,7 @@ struct rotary_encoder_platform_data { bool relative_axis; bool rollover; bool half_period; + bool on_each_step; }; #endif /* __ROTARY_ENCODER_H__ */