devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: mturquette@baylibre.com, sboyd@kernel.org, robh+dt@kernel.org,
	mark.rutland@arm.com, lee.jones@linaro.org, lgirdwood@gmail.com,
	broonie@kernel.org, mazziesaccount@gmail.com, arnd@arndb.de,
	sre@kernel.org, chenjh@rock-chips.com, andrew.smirnov@gmail.com,
	linus.walleij@linaro.org, kstewart@linuxfoundation.org,
	heiko@sntech.de, gregkh@linuxfoundation.org,
	linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
	mikko.mutanen@fi.rohmeurope.com,
	heikki.haikola@fi.rohmeurope.com
Subject: Re: [PATCH v7 4/4] input/power: Add driver for BD71837/BD71847 PMIC power button
Date: Thu, 21 Jun 2018 13:25:47 +0300	[thread overview]
Message-ID: <20180621102547.GA6076@localhost.localdomain> (raw)
In-Reply-To: <20180620064316.GB28784@localhost.localdomain>

On Wed, Jun 20, 2018 at 09:43:16AM +0300, Matti Vaittinen wrote:
> On Tue, Jun 19, 2018 at 10:50:28AM -0700, Dmitry Torokhov wrote:
> > Hi Matti,
> > 
> > On Tue, Jun 19, 2018 at 01:57:09PM +0300, Matti Vaittinen wrote:
> > > ROHM BD71837 PMIC power button driver providing power-key press
> > > information to user-space.
> > > 
> > > Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> > > ---
> > >  drivers/input/misc/Kconfig          | 10 +++++
> > >  drivers/input/misc/Makefile         |  1 +
> > >  drivers/input/misc/bd718xx-pwrkey.c | 90 +++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 101 insertions(+)
> > >  create mode 100644 drivers/input/misc/bd718xx-pwrkey.c
> > > 
> > > +	platform_set_drvdata(pdev, pk);
> > > +	err = regmap_update_bits(pk->mfd->regmap,
> > > +				 BD71837_REG_PWRONCONFIG0,
> > > +				 BD718XX_PWRBTN_SHORT_PRESS_MASK,
> > > +				 BD718XX_PWRBTN_SHORT_PRESS_10MS);
> > 
> > This seems to be the only custom bit of set up in the driver, the rest I
> > think can easily be handled by gpio-keys.c in interrupt-only mode. Maybe
> > we could move this into MFD piece and drop this driver?

I did following in MFD driver - is this what you suggested:
+static struct gpio_keys_button btns[] = {
+       {
+               .code = KEY_POWER,
+               .gpio = -1,
+               .type = EV_KEY,
+       },
+};
+
+static struct gpio_keys_platform_data bd718xx_powerkey_data = {
+       .buttons = &btns[0],
+       .nbuttons = ARRAY_SIZE(btns),
+       .name = "bd718xx-pwrkey",
+};
+
+/* bd71837 multi function cells */
+
+static struct mfd_cell bd71837_mfd_cells[] = {
+       {
+               .name = "bd71837-clk",
+       }, {
+               .name = "gpio-keys",
+               .platform_data = &bd718xx_powerkey_data,
+               .pdata_size = sizeof(bd718xx_powerkey_data),
+       }, {

//snip

+static int bd71837_i2c_probe(struct i2c_client *i2c,
+                           const struct i2c_device_id *id)
+{

// snip

+       ret = regmap_add_irq_chip(bd71837->regmap, bd71837->chip_irq,
+               IRQF_ONESHOT, 0,
+               &bd71837_irq_chip, &bd71837->irq_data);
+       if (ret < 0) {
+               dev_err(bd71837->dev, "Failed to add irq_chip %d\n", ret);
+               goto err_out;
+       }
+       /* I think this should be done conditionally and only when pwrkey is used
+        * What would be the correct way to decide if we want to touch rhw button
+        * press detection times?
+        */
+       ret = regmap_update_bits(bd71837->regmap,
+                                BD71837_REG_PWRONCONFIG0,
+                                BD718XX_PWRBTN_PRESS_DURATION_MASK,
+                                BD718XX_PWRBTN_SHORT_PRESS_10MS);
+       if (ret < 0) {
+               dev_err(bd71837->dev, "Failed to configure button short press timeout %d\n", ret);
+               goto err_out;
+       }
+       /* According to BD71847 datasheet the HW default for long press detection
+        * is 10ms. So letch change it to 10 sec so we can actually get the short
+        * push and allow gracefull shut down
+        */
+       ret = regmap_update_bits(bd71837->regmap,
+                                BD71837_REG_PWRONCONFIG1,
+                                BD718XX_PWRBTN_PRESS_DURATION_MASK,
+                                BD718XX_PWRBTN_LONG_PRESS_10S);
+       if (ret < 0) {
+               dev_err(bd71837->dev, "Failed to configure button long press timeout %d\n", ret);
+               goto err_out;
+       }
+       btns[0].irq = regmap_irq_get_virq(bd71837->irq_data,
+                                         BD71837_INT_PWRBTN_S);
+
+       if (btns[0].irq < 0) {
+               ret = btns[0].irq;
+               goto err_out;
+       }
+
+       ret = mfd_add_devices(bd71837->dev, PLATFORM_DEVID_AUTO,
+                             bd71837_mfd_cells, ARRAY_SIZE(bd71837_mfd_cells),
+                             NULL, 0,
+                             regmap_irq_get_domain(bd71837->irq_data));

If looks is Ok I will send new patch with this approach at next week -
unless I get lost during the traditional midsummer festival here in
Finland.

> Finally, there may be cases when power button is not attached to PMIC
> or is needing different configuration for 'short push'. This is why I
> would prefer having own Kconfig option for this power-key driver. I am
> not sure if it is easily doable if we use gpio_keys?

What would be the preferred mechanism for skipping the button push duration
configurations (time it takes for PMIC to detect short or long push)? Or
setting the durations to values user(s) would prefer? To me this sounds again
something we could configure from DT. Would adding propereties
rohm,short-press-ms and rohm,long-press-ms sound reasonable? I will send
the first version with no option to skip/specify the configuration
(fixed 10ms for short press, 10 sec for long press) but I would like to add
support for specifying the duration as next step.

Br,
	Matti Vaittinen

  reply	other threads:[~2018-06-21 10:25 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-19 10:55 [PATCH v7 0/4] mfd/regulator/clk/input: bd71837: ROHM BD71837 PMIC driver Matti Vaittinen
2018-06-19 10:55 ` [PATCH v7 1/4] mfd: bd71837: mfd driver for ROHM BD71837 PMIC Matti Vaittinen
2018-06-26  9:06   ` Enric Balletbo Serra
2018-06-26 11:24     ` Matti Vaittinen
2018-06-26 11:40       ` Enric Balletbo Serra
2018-06-26 12:03         ` Matti Vaittinen
2018-06-26 14:24           ` Enric Balletbo Serra
2018-07-03  6:56             ` Lee Jones
2018-07-03  8:09               ` Enric Balletbo Serra
2018-07-03  6:53         ` Lee Jones
2018-07-04 14:56     ` Dmitry Torokhov
2018-07-04 16:57       ` Enric Balletbo Serra
2018-07-05  5:52         ` Lee Jones
2018-07-05  7:56         ` Matti Vaittinen
2018-07-06  6:38           ` Dmitry Torokhov
2018-07-06  7:05             ` Lee Jones
2018-07-06  7:49               ` Matti Vaittinen
2018-06-19 10:56 ` [PATCH v7 2/4] mfd: bd71837: Devicetree bindings " Matti Vaittinen
2018-06-19 10:56 ` [PATCH v7 3/4] clk: bd71837: Add driver for BD71837 PMIC clock Matti Vaittinen
2018-06-19 10:57 ` [PATCH v7 4/4] input/power: Add driver for BD71837/BD71847 PMIC power button Matti Vaittinen
2018-06-19 17:50   ` Dmitry Torokhov
2018-06-20  6:43     ` Matti Vaittinen
2018-06-21 10:25       ` Matti Vaittinen [this message]
2018-06-27  0:21         ` Dmitry Torokhov
2018-06-21 10:34 ` [PATCH v7 0/4] mfd/regulator/clk/input: bd71837: ROHM BD71837 PMIC driver Matti Vaittinen
2018-07-03  7:02   ` Lee Jones
2018-07-04  8:47     ` Matti Vaittinen
2018-07-04  9:21       ` Lee Jones

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=20180621102547.GA6076@localhost.localdomain \
    --to=matti.vaittinen@fi.rohmeurope.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=chenjh@rock-chips.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.haikola@fi.rohmeurope.com \
    --cc=heiko@sntech.de \
    --cc=kstewart@linuxfoundation.org \
    --cc=lee.jones@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mazziesaccount@gmail.com \
    --cc=mikko.mutanen@fi.rohmeurope.com \
    --cc=mturquette@baylibre.com \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=sre@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).