From patchwork Sat Sep 28 18:26:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 2958701 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 441F1BFF0B for ; Sat, 28 Sep 2013 18:27:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3D58820263 for ; Sat, 28 Sep 2013 18:27:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 334A22025A for ; Sat, 28 Sep 2013 18:27:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751184Ab3I1S1O (ORCPT ); Sat, 28 Sep 2013 14:27:14 -0400 Received: from mail-wg0-f50.google.com ([74.125.82.50]:44236 "EHLO mail-wg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751078Ab3I1S1N (ORCPT ); Sat, 28 Sep 2013 14:27:13 -0400 Received: by mail-wg0-f50.google.com with SMTP id f12so3995647wgh.17 for ; Sat, 28 Sep 2013 11:27:12 -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=V1hXkrKq/2SrhMQeial4Q9TLnL9WBLlviY0J1elojVE=; b=IMvRAnykha9Q37xW+FQ8yPNJfWU1WAB2jx7hv9quVkosQvE88qsCZXs+jymRqrOuVg O4NJMtTu1ULtsQG5WSAS/9jfTZNZKY1Y8ieGr/NBos2qytBwZV8HKjMZ3hQ0Tly8vHab jXD7jXFL5WhB61HUzM1SI3lyxyoOpo4JFY85uAvarQM8d5qNRfeWt559V0Gmdji2cWIW VezYZqwAa97MR/71rnPDzv9bE28QnuAVHcPvU8kZ1qK1ZsRqZMonXVkXlGsCx3Q2lgGb gOTY2j3QK4qodXzEjlSCBz9N8dV8iKinuZwYzpvSRGcSF6TW6hZ/iO3LMt4i9DlLznZ1 BmNg== X-Gm-Message-State: ALoCoQldb/8qI8TAKRniyKFXn41NiInNlop71sSQx4NOV7+U+l+3PkSUYKdosx/KDeyotNe/8dUj X-Received: by 10.180.185.10 with SMTP id ey10mr7345851wic.29.1380392832713; Sat, 28 Sep 2013 11:27:12 -0700 (PDT) Received: from localhost.localdomain ([190.2.109.48]) by mx.google.com with ESMTPSA id sh5sm4538678wic.11.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 28 Sep 2013 11:27:12 -0700 (PDT) From: Ezequiel Garcia To: linux-input@vger.kernel.org Cc: Ezequiel Garcia , Daniel Mack , Dmitry Torokhov Subject: [PATCH 1/1] Input: rotary-encoder: Add 'stepped' irq handler Date: Sat, 28 Sep 2013 15:26:38 -0300 Message-Id: <1380392798-23345-2-git-send-email-ezequiel@vanguardiasur.com.ar> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1380392798-23345-1-git-send-email-ezequiel@vanguardiasur.com.ar> References: <1380392798-23345-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=-9.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 --- drivers/input/misc/rotary_encoder.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/rotary_encoder.h | 1 + 2 files changed, 35 insertions(+) diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index 5b1aff8..8802221 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -117,6 +117,37 @@ 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, sum; + + state = rotary_encoder_get_state(encoder->pdata); + + /* + * We encode the previous and the current state, + * in the 'sum' variable and then use a table + * to decide the direction of the turn. + */ + sum = (encoder->last_stable << 2) + state; + switch (sum) { + case 0b1101: + case 0b0100: + case 0b0010: + case 0b1011: + encoder->dir = 0; /* clockwise */ + break; + 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; @@ -254,6 +285,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__ */