linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Damien Riegel <damien.riegel@savoirfairelinux.com>
Cc: linux-input@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	kernel@savoirfairelinux.com
Subject: Re: [PATCH 4/6] Input: pm8xxx-vib: handle separate enable register
Date: Sat, 1 Apr 2017 10:06:55 -0700	[thread overview]
Message-ID: <20170401170655.GG17130@dtor-ws> (raw)
In-Reply-To: <20170331161538.11657-4-damien.riegel@savoirfairelinux.com>

On Fri, Mar 31, 2017 at 12:15:36PM -0400, Damien Riegel wrote:
> Some PMIC vibrator IPs use a separate enable register to turn the
> vibrator on and off. To detect if a vibrator uses this feature, rely on
> the enable_mask being non-zero.
> 
> If they use it, the device tree is queried to retrieve the base address
> of the control and enable registers.
> 
> Signed-off-by: Damien Riegel <damien.riegel@savoirfairelinux.com>
> ---
>  drivers/input/misc/pm8xxx-vibrator.c | 29 ++++++++++++++++++++++++++++-
>  1 file changed, 28 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c
> index f1daae08a8c2..803bc75d5531 100644
> --- a/drivers/input/misc/pm8xxx-vibrator.c
> +++ b/drivers/input/misc/pm8xxx-vibrator.c
> @@ -14,6 +14,7 @@
>  #include <linux/input.h>
>  #include <linux/kernel.h>
>  #include <linux/module.h>
> +#include <linux/of.h>
>  #include <linux/of_device.h>
>  #include <linux/platform_device.h>
>  #include <linux/regmap.h>
> @@ -26,6 +27,9 @@
>  #define MAX_FF_SPEED		0xff
>  
>  struct pm8xxx_regs {
> +	unsigned int enable_addr;
> +	unsigned int enable_mask;
> +
>  	unsigned int drv_addr;
>  	unsigned int drv_mask;
>  	unsigned int drv_shift;
> @@ -82,7 +86,14 @@ static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on)
>  		return rc;
>  
>  	vib->reg_vib_drv = val;
> -	return 0;
> +
> +	if (regs->enable_mask) {
> +		unsigned int val = on ? regs->enable_mask : 0;
> +		rc = regmap_update_bits(vib->regmap, regs->enable_addr,
> +					regs->enable_mask, val);
> +	}
> +
> +	return rc;
>  }
>  
>  /**
> @@ -179,6 +190,22 @@ static int pm8xxx_vib_probe(struct platform_device *pdev)
>  
>  	regs = (struct pm8xxx_regs *)of_device_get_match_data(&pdev->dev);
>  
> +	/*
> +	 * If enable_mask is not zero, that means we're using a vibrator that
> +	 * requires multiple registers to be controlled, the value read in the
> +	 * device tree is the base address of these registers.
> +	 */
> +	if (regs->enable_mask) {
> +		u32 base;
> +
> +		error = of_property_read_u32(pdev->dev.of_node, "reg", &base);
> +		if (error)
> +			return error;

Is it really configurable? Shouldn't it be in chip-spoecific instance of
regs to begin with?

> +
> +		regs->drv_addr += base;
> +		regs->enable_addr += base;

Regs should be const, you should not change it (what happens if there
are 2 devices?).

> +	}
> +
>  	/* operate in manual mode */
>  	error = regmap_read(vib->regmap, regs->drv_addr, &val);
>  	if (error < 0)
> -- 
> 2.12.0
> 

Thanks.

-- 
Dmitry

  reply	other threads:[~2017-04-01 17:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-31 16:15 [PATCH 1/6] Input: pm8xxx-vib: reorder header alphabetically Damien Riegel
2017-03-31 16:15 ` [PATCH 2/6] Input: pm8xxx-vib: sync device tree bindings doc with the driver Damien Riegel
2017-04-01 16:54   ` Dmitry Torokhov
2017-04-01 17:51     ` Damien Riegel
2017-04-01 18:06       ` Dmitry Torokhov
2017-04-01 18:57         ` Damien Riegel
2017-04-03 18:31           ` Dmitry Torokhov
2017-03-31 16:15 ` [PATCH 3/6] Input: pm8xxx-vib: parametrize " Damien Riegel
2017-04-01 17:04   ` Dmitry Torokhov
2017-03-31 16:15 ` [PATCH 4/6] Input: pm8xxx-vib: handle separate enable register Damien Riegel
2017-04-01 17:06   ` Dmitry Torokhov [this message]
2017-03-31 16:15 ` [PATCH 5/6] Input: pm8xxx-vib: add pm8916-vib device tree bindings Damien Riegel
2017-03-31 16:15 ` [PATCH 6/6] Input: pm8xxx-vib: add support for pm8916's vibrator Damien Riegel

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=20170401170655.GG17130@dtor-ws \
    --to=dmitry.torokhov@gmail.com \
    --cc=damien.riegel@savoirfairelinux.com \
    --cc=kernel@savoirfairelinux.com \
    --cc=linux-input@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@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).