All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Mack <zonque@gmail.com>
To: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>
Subject: Re: [PATCH v2 1/2] Input: rotary-encoder: Add 'stepped' irq handler
Date: Fri, 04 Oct 2013 15:18:26 +0200	[thread overview]
Message-ID: <524EC022.2050203@gmail.com> (raw)
In-Reply-To: <1380891203-17617-2-git-send-email-ezequiel@vanguardiasur.com.ar>

On 04.10.2013 14:53, Ezequiel Garcia wrote:
> 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.

I think you can squash patch 2/2 into this one. It doesn't make much
sense to have a one-liner patch to just update the documenation separately.

Other than that, the code looks fine to me.

  Acked-by: Daniel Mack <zonque@gmail.com>


Thanks,
Daniel


> 
> Cc: Daniel Mack <zonque@gmail.com>
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
> ---
> 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__ */
> 


  reply	other threads:[~2013-10-04 13:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-04 12:53 [PATCH v2 0/2] rotary-encoder: Add new interruption handler Ezequiel Garcia
2013-10-04 12:53 ` Ezequiel Garcia
2013-10-04 12:53 ` [PATCH v2 1/2] Input: rotary-encoder: Add 'stepped' irq handler Ezequiel Garcia
2013-10-04 12:53   ` Ezequiel Garcia
2013-10-04 13:18   ` Daniel Mack [this message]
2013-10-12 16:58     ` Ezequiel García
2013-10-12 16:58       ` Ezequiel García
     [not found] ` <1380891203-17617-1-git-send-email-ezequiel-30ULvvUtt6G51wMPkGsGjgyUoB5FGQPZ@public.gmane.org>
2013-10-04 12:53   ` [PATCH v2 2/2] input: rotary-encoder: Add 'on-each-step' to binding documentation Ezequiel Garcia
2013-10-04 12:53     ` Ezequiel Garcia
2013-10-04 13:19     ` Mark Rutland
2013-10-04 14:09       ` Ezequiel Garcia
2013-10-04 14:09         ` Ezequiel Garcia
2013-10-10 13:55         ` Ezequiel García
2013-10-10 13:55           ` Ezequiel García

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=524EC022.2050203@gmail.com \
    --to=zonque@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.