diff mbox series

[v4,3/3] input: misc: rt5120: Add power key support

Message ID 1660100142-32493-4-git-send-email-u0084500@gmail.com (mailing list archive)
State Accepted
Commit ed3d5bd20dcdfdbe110feeabf120cba7bd329ad8
Headers show
Series Add Richtek RT5120 PMIC support | expand

Commit Message

ChiYuan Huang Aug. 10, 2022, 2:55 a.m. UTC
From: ChiYuan Huang <cy_huang@richtek.com>

Add RT5120 PMIC power key support.

Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
---
Since v4:
- Add "Copyright" string and refine for GPL version string.

Since v3:
- Simplify the power key irq handler key report
- Since press and release irq not needed to keep in private data, change 'press',
  'release' irq as local variable only.
- Fix Kconfig typo for pwrkey.

---
 drivers/input/misc/Kconfig         |   9 +++
 drivers/input/misc/Makefile        |   1 +
 drivers/input/misc/rt5120-pwrkey.c | 109 +++++++++++++++++++++++++++++++++++++
 3 files changed, 119 insertions(+)
 create mode 100644 drivers/input/misc/rt5120-pwrkey.c

Comments

ChiYuan Huang Aug. 22, 2022, 1:12 a.m. UTC | #1
Dear reviewers:

cy_huang <u0084500@gmail.com> 於 2022年8月10日 週三 上午10:55寫道:
>
> From: ChiYuan Huang <cy_huang@richtek.com>
>
> Add RT5120 PMIC power key support.
>
> Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
> ---
> Since v4:
> - Add "Copyright" string and refine for GPL version string.
>
> Since v3:
> - Simplify the power key irq handler key report
> - Since press and release irq not needed to keep in private data, change 'press',
>   'release' irq as local variable only.
> - Fix Kconfig typo for pwrkey.
>
Since binding/mfd/regulator are all applied, only this one is left.
Any update about this pwrkey patch?
> ---
>  drivers/input/misc/Kconfig         |   9 +++
>  drivers/input/misc/Makefile        |   1 +
>  drivers/input/misc/rt5120-pwrkey.c | 109 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 119 insertions(+)
>  create mode 100644 drivers/input/misc/rt5120-pwrkey.c
>
> diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> index a18ab73..92daa4d 100644
> --- a/drivers/input/misc/Kconfig
> +++ b/drivers/input/misc/Kconfig
> @@ -891,6 +891,15 @@ config INPUT_SC27XX_VIBRA
>           To compile this driver as a module, choose M here. The module will
>           be called sc27xx_vibra.
>
> +config INPUT_RT5120_PWRKEY
> +       tristate "RT5120 PMIC power key support"
> +       depends on MFD_RT5120
> +       help
> +         This enables support for RT5120 PMIC power key driver.
> +
> +         To compile this driver as a module, choose M here. the module will
> +         be called rt5120-pwrkey.
> +
>  config INPUT_STPMIC1_ONKEY
>         tristate "STPMIC1 PMIC Onkey support"
>         depends on MFD_STPMIC1
> diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
> index 28dfc44..d1fb00e 100644
> --- a/drivers/input/misc/Makefile
> +++ b/drivers/input/misc/Makefile
> @@ -69,6 +69,7 @@ obj-$(CONFIG_INPUT_RAVE_SP_PWRBUTTON) += rave-sp-pwrbutton.o
>  obj-$(CONFIG_INPUT_RB532_BUTTON)       += rb532_button.o
>  obj-$(CONFIG_INPUT_REGULATOR_HAPTIC)   += regulator-haptic.o
>  obj-$(CONFIG_INPUT_RETU_PWRBUTTON)     += retu-pwrbutton.o
> +obj-$(CONFIG_INPUT_RT5120_PWRKEY)      += rt5120-pwrkey.o
>  obj-$(CONFIG_INPUT_AXP20X_PEK)         += axp20x-pek.o
>  obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER)        += rotary_encoder.o
>  obj-$(CONFIG_INPUT_RK805_PWRKEY)       += rk805-pwrkey.o
> diff --git a/drivers/input/misc/rt5120-pwrkey.c b/drivers/input/misc/rt5120-pwrkey.c
> new file mode 100644
> index 00000000..94d25ba
> --- /dev/null
> +++ b/drivers/input/misc/rt5120-pwrkey.c
> @@ -0,0 +1,109 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2022 Richtek Technology Corp.
> + * Author: ChiYuan Huang <cy_huang@richtek.com>
> + */
> +
> +#include <linux/bits.h>
> +#include <linux/input.h>
> +#include <linux/interrupt.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +
> +#define RT5120_REG_INTSTAT     0x1E
> +#define RT5120_PWRKEYSTAT_MASK BIT(7)
> +
> +struct rt5120_priv {
> +       struct regmap *regmap;
> +       struct input_dev *input;
> +};
> +
> +static irqreturn_t rt5120_pwrkey_handler(int irq, void *devid)
> +{
> +       struct rt5120_priv *priv = devid;
> +       unsigned int stat;
> +       int ret;
> +
> +       ret = regmap_read(priv->regmap, RT5120_REG_INTSTAT, &stat);
> +       if (ret)
> +               return IRQ_NONE;
> +
> +       input_report_key(priv->input, KEY_POWER,
> +                        !(stat & RT5120_PWRKEYSTAT_MASK));
> +       input_sync(priv->input);
> +
> +       return IRQ_HANDLED;
> +}
> +
> +static int rt5120_pwrkey_probe(struct platform_device *pdev)
> +{
> +       struct rt5120_priv *priv;
> +       struct device *dev = &pdev->dev;
> +       int press_irq, release_irq;
> +       int ret;
> +
> +       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> +       if (!priv)
> +               return -ENOMEM;
> +
> +       priv->regmap = dev_get_regmap(dev->parent, NULL);
> +       if (!priv->regmap)
> +               return dev_err_probe(dev, -ENODEV, "Failed to init regmap\n");
> +
> +       press_irq = platform_get_irq_byname(pdev, "pwrkey-press");
> +       if (press_irq < 0)
> +               return press_irq;
> +
> +       release_irq = platform_get_irq_byname(pdev, "pwrkey-release");
> +       if (release_irq < 0)
> +               return release_irq;
> +
> +       /* Make input device be device resource managed */
> +       priv->input = devm_input_allocate_device(dev);
> +       if (!priv->input)
> +               return dev_err_probe(dev, -ENOMEM,
> +                                    "Failed to allocate input device\n");
> +
> +       priv->input->name = "rt5120_pwrkey";
> +       priv->input->phys = "rt5120_pwrkey/input0";
> +       priv->input->id.bustype = BUS_I2C;
> +       input_set_capability(priv->input, EV_KEY, KEY_POWER);
> +
> +       ret = input_register_device(priv->input);
> +       if (ret)
> +               return dev_err_probe(dev, ret,
> +                                    "Failed to register input device\n");
> +
> +       ret = devm_request_threaded_irq(dev, press_irq, NULL,
> +                                       rt5120_pwrkey_handler, 0,
> +                                       "pwrkey-press", priv);
> +       if (ret)
> +               return dev_err_probe(dev, ret,
> +                                    "Failed to register pwrkey press irq\n");
> +
> +       return devm_request_threaded_irq(dev, release_irq, NULL,
> +                                        rt5120_pwrkey_handler, 0,
> +                                        "pwrkey-release", priv);
> +}
> +
> +static const struct of_device_id r5120_pwrkey_match_table[] = {
> +       { .compatible = "richtek,rt5120-pwrkey" },
> +       {}
> +};
> +MODULE_DEVICE_TABLE(of, r5120_pwrkey_match_table);
> +
> +static struct platform_driver rt5120_pwrkey_driver = {
> +       .driver = {
> +               .name = "rt5120-pwrkey",
> +               .of_match_table = r5120_pwrkey_match_table,
> +       },
> +       .probe = rt5120_pwrkey_probe,
> +};
> +module_platform_driver(rt5120_pwrkey_driver);
> +
> +MODULE_AUTHOR("ChiYuan Huang <cy_huang@richtek.com>");
> +MODULE_DESCRIPTION("Richtek RT5120 power key driver");
> +MODULE_LICENSE("GPL v2");
> --
> 2.7.4
>
Dmitry Torokhov Aug. 31, 2022, 10:47 p.m. UTC | #2
Hi ChiYuan,

On Wed, Aug 10, 2022 at 10:55:42AM +0800, cy_huang wrote:
> +MODULE_AUTHOR("ChiYuan Huang <cy_huang@richtek.com>");
> +MODULE_DESCRIPTION("Richtek RT5120 power key driver");
> +MODULE_LICENSE("GPL v2");

I changed this to be simply "GPL" (per checkpatch.pl, see commit
'bf7fbeeae6db module: Cure the MODULE_LICENSE "GPL" vs. "GPL v2"
bogosity' for details) + did a couple of minor edits, and applied, thank
you.
ChiYuan Huang Sept. 1, 2022, 12:39 a.m. UTC | #3
Dmitry Torokhov <dmitry.torokhov@gmail.com> 於 2022年9月1日 週四 清晨6:47寫道:
>
> Hi ChiYuan,
>
> On Wed, Aug 10, 2022 at 10:55:42AM +0800, cy_huang wrote:
> > +MODULE_AUTHOR("ChiYuan Huang <cy_huang@richtek.com>");
> > +MODULE_DESCRIPTION("Richtek RT5120 power key driver");
> > +MODULE_LICENSE("GPL v2");
>
> I changed this to be simply "GPL" (per checkpatch.pl, see commit
> 'bf7fbeeae6db module: Cure the MODULE_LICENSE "GPL" vs. "GPL v2"
> bogosity' for details) + did a couple of minor edits, and applied, thank
> you.
>
Ok, got it.
Old "GPL" text as GPL v2 or "later", and  the "later" keyword is the problem.
This patch is to fix it.

How about the SPDX license string? The same definition?

> --
> Dmitry
Dmitry Torokhov Sept. 1, 2022, 2:12 a.m. UTC | #4
On Thu, Sep 01, 2022 at 08:39:05AM +0800, ChiYuan Huang wrote:
> Dmitry Torokhov <dmitry.torokhov@gmail.com> 於 2022年9月1日 週四 清晨6:47寫道:
> >
> > Hi ChiYuan,
> >
> > On Wed, Aug 10, 2022 at 10:55:42AM +0800, cy_huang wrote:
> > > +MODULE_AUTHOR("ChiYuan Huang <cy_huang@richtek.com>");
> > > +MODULE_DESCRIPTION("Richtek RT5120 power key driver");
> > > +MODULE_LICENSE("GPL v2");
> >
> > I changed this to be simply "GPL" (per checkpatch.pl, see commit
> > 'bf7fbeeae6db module: Cure the MODULE_LICENSE "GPL" vs. "GPL v2"
> > bogosity' for details) + did a couple of minor edits, and applied, thank
> > you.
> >
> Ok, got it.
> Old "GPL" text as GPL v2 or "later", and  the "later" keyword is the problem.
> This patch is to fix it.
> 
> How about the SPDX license string? The same definition?

No, MODULE_LICENSE() is sorely for symbol resolution during module
loading, so GPL vs GPLv2 or later, etc is all the same. SPDX denotes
the actual license for the source code that governs derivative works,
etc. and I did not change it - it is left exactly as you sent it:

// SPDX-License-Identifier: GPL-2.0-only

Thanks.
diff mbox series

Patch

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index a18ab73..92daa4d 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -891,6 +891,15 @@  config INPUT_SC27XX_VIBRA
 	  To compile this driver as a module, choose M here. The module will
 	  be called sc27xx_vibra.
 
+config INPUT_RT5120_PWRKEY
+	tristate "RT5120 PMIC power key support"
+	depends on MFD_RT5120
+	help
+	  This enables support for RT5120 PMIC power key driver.
+
+	  To compile this driver as a module, choose M here. the module will
+	  be called rt5120-pwrkey.
+
 config INPUT_STPMIC1_ONKEY
 	tristate "STPMIC1 PMIC Onkey support"
 	depends on MFD_STPMIC1
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 28dfc44..d1fb00e 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -69,6 +69,7 @@  obj-$(CONFIG_INPUT_RAVE_SP_PWRBUTTON)	+= rave-sp-pwrbutton.o
 obj-$(CONFIG_INPUT_RB532_BUTTON)	+= rb532_button.o
 obj-$(CONFIG_INPUT_REGULATOR_HAPTIC)	+= regulator-haptic.o
 obj-$(CONFIG_INPUT_RETU_PWRBUTTON)	+= retu-pwrbutton.o
+obj-$(CONFIG_INPUT_RT5120_PWRKEY)	+= rt5120-pwrkey.o
 obj-$(CONFIG_INPUT_AXP20X_PEK)		+= axp20x-pek.o
 obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER)	+= rotary_encoder.o
 obj-$(CONFIG_INPUT_RK805_PWRKEY)	+= rk805-pwrkey.o
diff --git a/drivers/input/misc/rt5120-pwrkey.c b/drivers/input/misc/rt5120-pwrkey.c
new file mode 100644
index 00000000..94d25ba
--- /dev/null
+++ b/drivers/input/misc/rt5120-pwrkey.c
@@ -0,0 +1,109 @@ 
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022 Richtek Technology Corp.
+ * Author: ChiYuan Huang <cy_huang@richtek.com>
+ */
+
+#include <linux/bits.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+#define RT5120_REG_INTSTAT	0x1E
+#define RT5120_PWRKEYSTAT_MASK	BIT(7)
+
+struct rt5120_priv {
+	struct regmap *regmap;
+	struct input_dev *input;
+};
+
+static irqreturn_t rt5120_pwrkey_handler(int irq, void *devid)
+{
+	struct rt5120_priv *priv = devid;
+	unsigned int stat;
+	int ret;
+
+	ret = regmap_read(priv->regmap, RT5120_REG_INTSTAT, &stat);
+	if (ret)
+		return IRQ_NONE;
+
+	input_report_key(priv->input, KEY_POWER,
+			 !(stat & RT5120_PWRKEYSTAT_MASK));
+	input_sync(priv->input);
+
+	return IRQ_HANDLED;
+}
+
+static int rt5120_pwrkey_probe(struct platform_device *pdev)
+{
+	struct rt5120_priv *priv;
+	struct device *dev = &pdev->dev;
+	int press_irq, release_irq;
+	int ret;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->regmap = dev_get_regmap(dev->parent, NULL);
+	if (!priv->regmap)
+		return dev_err_probe(dev, -ENODEV, "Failed to init regmap\n");
+
+	press_irq = platform_get_irq_byname(pdev, "pwrkey-press");
+	if (press_irq < 0)
+		return press_irq;
+
+	release_irq = platform_get_irq_byname(pdev, "pwrkey-release");
+	if (release_irq < 0)
+		return release_irq;
+
+	/* Make input device be device resource managed */
+	priv->input = devm_input_allocate_device(dev);
+	if (!priv->input)
+		return dev_err_probe(dev, -ENOMEM,
+				     "Failed to allocate input device\n");
+
+	priv->input->name = "rt5120_pwrkey";
+	priv->input->phys = "rt5120_pwrkey/input0";
+	priv->input->id.bustype = BUS_I2C;
+	input_set_capability(priv->input, EV_KEY, KEY_POWER);
+
+	ret = input_register_device(priv->input);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed to register input device\n");
+
+	ret = devm_request_threaded_irq(dev, press_irq, NULL,
+					rt5120_pwrkey_handler, 0,
+					"pwrkey-press", priv);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed to register pwrkey press irq\n");
+
+	return devm_request_threaded_irq(dev, release_irq, NULL,
+					 rt5120_pwrkey_handler, 0,
+					 "pwrkey-release", priv);
+}
+
+static const struct of_device_id r5120_pwrkey_match_table[] = {
+	{ .compatible = "richtek,rt5120-pwrkey" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, r5120_pwrkey_match_table);
+
+static struct platform_driver rt5120_pwrkey_driver = {
+	.driver = {
+		.name = "rt5120-pwrkey",
+		.of_match_table = r5120_pwrkey_match_table,
+	},
+	.probe = rt5120_pwrkey_probe,
+};
+module_platform_driver(rt5120_pwrkey_driver);
+
+MODULE_AUTHOR("ChiYuan Huang <cy_huang@richtek.com>");
+MODULE_DESCRIPTION("Richtek RT5120 power key driver");
+MODULE_LICENSE("GPL v2");