linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Michal Vokáč" <michal.vokac@ysoft.com>
Cc: Rob Herring <robh+dt@kernel.org>, Shawn Guo <shawnguo@kernel.org>,
	Fabio Estevam <festevam@gmail.com>,
	linux-input@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 4/5] Input: mpr121: Add polling mode
Date: Tue, 15 Oct 2019 17:24:13 -0700	[thread overview]
Message-ID: <20191016002413.GM105649@dtor-ws> (raw)
In-Reply-To: <1570083176-8231-5-git-send-email-michal.vokac@ysoft.com>

On Thu, Oct 03, 2019 at 08:12:55AM +0200, Michal Vokáč wrote:
> In case the interrupt line is not available, polling can be used
> to read out the state of the keys. Period of the polling needs to
> be configured by the poll-interval DT property.
> 
> Signed-off-by: Michal Vokáč <michal.vokac@ysoft.com>

Applied, thank you.

> ---
> Changes since v2:
>  - None
> 
> Changes since v1:
>  - Use poll-interval property name instead of linux,poll-interval.
> 
>  drivers/input/keyboard/mpr121_touchkey.c | 69 +++++++++++++++++++++++---------
>  1 file changed, 51 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c
> index ee80de44ce3f..40d6e5087cde 100644
> --- a/drivers/input/keyboard/mpr121_touchkey.c
> +++ b/drivers/input/keyboard/mpr121_touchkey.c
> @@ -54,6 +54,9 @@
>  /* MPR121 has 12 keys */
>  #define MPR121_MAX_KEY_COUNT		12
>  
> +#define MPR121_MIN_POLL_INTERVAL	10
> +#define MPR121_MAX_POLL_INTERVAL	200
> +
>  struct mpr121_touchkey {
>  	struct i2c_client	*client;
>  	struct input_dev	*input_dev;
> @@ -115,11 +118,11 @@ static struct regulator *mpr121_vdd_supply_init(struct device *dev)
>  	return vdd_supply;
>  }
>  
> -static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
> +static void mpr_touchkey_report(struct input_dev *dev)
>  {
> -	struct mpr121_touchkey *mpr121 = dev_id;
> -	struct i2c_client *client = mpr121->client;
> +	struct mpr121_touchkey *mpr121 = input_get_drvdata(dev);
>  	struct input_dev *input = mpr121->input_dev;
> +	struct i2c_client *client = mpr121->client;
>  	unsigned long bit_changed;
>  	unsigned int key_num;
>  	int reg;
> @@ -127,14 +130,14 @@ static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
>  	reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR);
>  	if (reg < 0) {
>  		dev_err(&client->dev, "i2c read error [%d]\n", reg);
> -		goto out;
> +		return;
>  	}
>  
>  	reg <<= 8;
>  	reg |= i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_0_ADDR);
>  	if (reg < 0) {
>  		dev_err(&client->dev, "i2c read error [%d]\n", reg);
> -		goto out;
> +		return;
>  	}
>  
>  	reg &= TOUCH_STATUS_MASK;
> @@ -155,8 +158,14 @@ static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
>  
>  	}
>  	input_sync(input);
> +}
> +
> +static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
> +{
> +	struct mpr121_touchkey *mpr121 = dev_id;
> +
> +	mpr_touchkey_report(mpr121->input_dev);
>  
> -out:
>  	return IRQ_HANDLED;
>  }
>  
> @@ -229,14 +238,10 @@ static int mpr_touchkey_probe(struct i2c_client *client,
>  	int vdd_uv;
>  	struct mpr121_touchkey *mpr121;
>  	struct input_dev *input_dev;
> +	u32 poll_interval = 0;
>  	int error;
>  	int i;
>  
> -	if (!client->irq) {
> -		dev_err(dev, "irq number should not be zero\n");
> -		return -EINVAL;
> -	}
> -
>  	vdd_supply = mpr121_vdd_supply_init(dev);
>  	if (IS_ERR(vdd_supply))
>  		return PTR_ERR(vdd_supply);
> @@ -274,6 +279,7 @@ static int mpr_touchkey_probe(struct i2c_client *client,
>  	if (device_property_read_bool(dev, "autorepeat"))
>  		__set_bit(EV_REP, input_dev->evbit);
>  	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
> +	input_set_drvdata(input_dev, mpr121);
>  
>  	input_dev->keycode = mpr121->keycodes;
>  	input_dev->keycodesize = sizeof(mpr121->keycodes[0]);
> @@ -288,13 +294,40 @@ static int mpr_touchkey_probe(struct i2c_client *client,
>  		return error;
>  	}
>  
> -	error = devm_request_threaded_irq(dev, client->irq, NULL,
> -					  mpr_touchkey_interrupt,
> -					  IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
> -					  dev->driver->name, mpr121);
> -	if (error) {
> -		dev_err(dev, "Failed to register interrupt\n");
> -		return error;
> +	device_property_read_u32(dev, "poll-interval", &poll_interval);
> +
> +	if (client->irq) {
> +		error = devm_request_threaded_irq(dev, client->irq, NULL,
> +						  mpr_touchkey_interrupt,
> +						  IRQF_TRIGGER_FALLING |
> +						  IRQF_ONESHOT,
> +						  dev->driver->name, mpr121);
> +		if (error) {
> +			dev_err(dev, "Failed to register interrupt\n");
> +			return error;
> +		}
> +	} else if (poll_interval) {
> +		if (poll_interval < MPR121_MIN_POLL_INTERVAL)
> +			return -EINVAL;
> +
> +		if (poll_interval > MPR121_MAX_POLL_INTERVAL)
> +			return -EINVAL;
> +
> +		error = input_setup_polling(input_dev, mpr_touchkey_report);
> +		if (error) {
> +			dev_err(dev, "Failed to setup polling\n");
> +			return error;
> +		}
> +
> +		input_set_poll_interval(input_dev, poll_interval);
> +		input_set_min_poll_interval(input_dev,
> +					    MPR121_MIN_POLL_INTERVAL);
> +		input_set_max_poll_interval(input_dev,
> +					    MPR121_MAX_POLL_INTERVAL);
> +	} else {
> +		dev_err(dev,
> +			"invalid IRQ number and polling not configured\n");
> +		return -EINVAL;
>  	}
>  
>  	error = input_register_device(input_dev);
> -- 
> 2.1.4
> 

-- 
Dmitry

  reply	other threads:[~2019-10-16  0:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03  6:12 [PATCH v3 0/5] Add polling mode to the MPR121 touchkey Michal Vokáč
2019-10-03  6:12 ` [PATCH v3 1/5] dt-bindings: input: Add common input binding in json-schema Michal Vokáč
2019-10-10 19:35   ` Rob Herring
2019-10-16  0:23     ` Dmitry Torokhov
2019-10-03  6:12 ` [PATCH v3 2/5] dt-bindings: input: Convert mpr121 binding to json-schema Michal Vokáč
2019-10-04 13:58   ` Michal Vokáč
2019-10-10 19:36   ` Rob Herring
2019-10-16  0:24     ` Dmitry Torokhov
2019-10-03  6:12 ` [PATCH v3 3/5] dt-bindings: input: Add poll-interval property Michal Vokáč
2019-10-10 19:40   ` Rob Herring
2019-10-10 20:01     ` Dmitry Torokhov
2019-10-11  8:03       ` Michal Vokáč
2019-10-16  0:23         ` Dmitry Torokhov
2019-10-16  5:52           ` Michal Vokáč
2019-10-03  6:12 ` [PATCH v3 4/5] Input: mpr121: Add polling mode Michal Vokáč
2019-10-16  0:24   ` Dmitry Torokhov [this message]
2019-10-03  6:12 ` [PATCH v3 5/5] ARM: dts: imx6dl-yapp4: Enable the MPR121 touchkey controller on Hydra Michal Vokáč
2019-10-16  6:07   ` Michal Vokáč
2019-10-25  2:48     ` Shawn Guo

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=20191016002413.GM105649@dtor-ws \
    --to=dmitry.torokhov@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=festevam@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=michal.vokac@ysoft.com \
    --cc=robh+dt@kernel.org \
    --cc=shawnguo@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).