From: ChiYuan Huang <[email protected]>
This patch series is to add Richtek RT5120 PMIC support.
In RT5120, it integrates four channels of buck converter, one channel of LDO,
and one external enable channel to control the external power source.
rt5120-regulator can be referred in the below link
Link: https://lore.kernel.org/lkml/[email protected]/
Since v4:
- Add "Copyright" string and refine for GPL version string.
- Refine the comma usage in mfd. For the last uncertain terminated element in
struct arrays, put the comma for it to keep the extensibility.
Since v3:
- Use a 'dev' variable and dev_err_probe to decrease the LOC in mfd.
- 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 v2:
- Add 'unevaluatedProperties: false' for regulator buck1~4/ldo/exten.
- Fix indention and remove status for powerkey.
- Refine powerkey description for more HW details.
- For the regulator property parsing, use of_property_read_u32 instead.
- Not to overwrite regulator constraint.
- Refine regulator desc coding.
ChiYuan Huang (3):
dt-binding: mfd: Add Richtek RT5120 PMIC support
mfd: rt5120: Add Richtek PMIC support
input: misc: rt5120: Add power key support
.../devicetree/bindings/mfd/richtek,rt5120.yaml | 178 +++++++++++++++++++++
drivers/input/misc/Kconfig | 9 ++
drivers/input/misc/Makefile | 1 +
drivers/input/misc/rt5120-pwrkey.c | 109 +++++++++++++
drivers/mfd/Kconfig | 12 ++
drivers/mfd/Makefile | 1 +
drivers/mfd/rt5120.c | 124 ++++++++++++++
7 files changed, 434 insertions(+)
create mode 100644 Documentation/devicetree/bindings/mfd/richtek,rt5120.yaml
create mode 100644 drivers/input/misc/rt5120-pwrkey.c
create mode 100644 drivers/mfd/rt5120.c
--
2.7.4
From: ChiYuan Huang <[email protected]>
Add Richtek RT5120 PMIC devicetree document.
Reviewed-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: ChiYuan Huang <[email protected]>
---
Since v2:
- Add 'unevaluatedProperties: false' for regulator buck1~4/ldo/exten.
- Fix indention and remove status for powerkey.
- Refine powerkey description for more HW details.
---
.../devicetree/bindings/mfd/richtek,rt5120.yaml | 178 +++++++++++++++++++++
1 file changed, 178 insertions(+)
create mode 100644 Documentation/devicetree/bindings/mfd/richtek,rt5120.yaml
diff --git a/Documentation/devicetree/bindings/mfd/richtek,rt5120.yaml b/Documentation/devicetree/bindings/mfd/richtek,rt5120.yaml
new file mode 100644
index 00000000..f73b8b2
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/richtek,rt5120.yaml
@@ -0,0 +1,178 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/richtek,rt5120.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Richtek RT5120 PMIC
+
+maintainers:
+ - ChiYuan Huang <[email protected]>
+
+description: |
+ The RT5120 provides four high-efficiency buck converters and one LDO voltage
+ regulator. The device is targeted at providingthe processor voltage, memory,
+ I/O, and peripheral rails in home entertainment devices. The I2C interface is
+ used for dynamic voltage scaling of the processor voltage, power rails on/off
+ sequence control, operation mode selection.
+
+properties:
+ compatible:
+ enum:
+ - richtek,rt5120
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ maxItems: 1
+
+ interrupt-controller: true
+
+ "#interrupt-cells":
+ const: 1
+
+ wakeup-source: true
+
+ richtek,enable-undervolt-hiccup:
+ type: boolean
+ description: |
+ If used, under voltage protection trigger hiccup behavior, else latchup as
+ default
+
+ richtek,enable-overvolt-hiccup:
+ type: boolean
+ description:
+ Like as 'enable-uv-hiccup', it configures over voltage protection to
+ hiccup, else latchup as default
+
+ vin1-supply:
+ description: phandle for buck1 input power source
+
+ vin2-supply:
+ description: phandle for buck2 input power source
+
+ vin3-supply:
+ description: phandle for buck3 input power source
+
+ vin4-supply:
+ description: phandle for buck4 input power source
+
+ vinldo-supply:
+ description: phandle for ldo input power source
+
+ regulators:
+ type: object
+
+ patternProperties:
+ "^buck[1-4]$":
+ type: object
+ $ref: /schemas/regulator/regulator.yaml#
+ unevaluatedProperties: false
+
+ properties:
+ regulator-allowed-modes:
+ description: |
+ Used to specify the allowed buck converter operating mode
+ mode mapping:
+ 0: auto mode
+ 1: force pwm mode
+ items:
+ enum: [0, 1]
+
+ "^(ldo|exten)$":
+ type: object
+ $ref: /schemas/regulator/regulator.yaml#
+ unevaluatedProperties: false
+
+ additionalProperties: false
+
+ powerkey:
+ type: object
+ description:
+ PON key that connected to RT5120 PMIC.
+
+ properties:
+ compatible:
+ enum:
+ - richtek,rt5120-pwrkey
+
+ required:
+ - compatible
+
+ additionalProperties: false
+
+required:
+ - compatible
+ - reg
+ - interrupts
+ - '#interrupt-cells'
+ - interrupt-controller
+ - regulators
+ - powerkey
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ pmic@62 {
+ compatible = "richtek,rt5120";
+ reg = <0x62>;
+ interrupts-extended = <&gpio_intc 32 IRQ_TYPE_LEVEL_LOW>;
+ interrupt-controller;
+ #interrupt-cells = <1>;
+ wakeup-source;
+
+ regulators {
+ buck1 {
+ regulator-name = "rt5120-buck1";
+ regulator-min-microvolt = <600000>;
+ regulator-max-microvolt = <1393750>;
+ regulator-allowed-modes = <0 1>;
+ regulator-boot-on;
+ };
+ buck2 {
+ regulator-name = "rt5120-buck2";
+ regulator-min-microvolt = <1100000>;
+ regulator-max-microvolt = <1100000>;
+ regulator-allowed-modes = <0 1>;
+ regulator-always-on;
+ };
+ buck3 {
+ regulator-name = "rt5120-buck3";
+ regulator-min-microvolt = <1800000>;
+ regulator-max-microvolt = <1800000>;
+ regulator-allowed-modes = <0 1>;
+ regulator-always-on;
+ };
+ buck4 {
+ regulator-name = "rt5120-buck4";
+ regulator-min-microvolt = <3300000>;
+ regulator-max-microvolt = <3300000>;
+ regulator-allowed-modes = <0 1>;
+ regulator-always-on;
+ };
+ ldo {
+ regulator-name = "rt5120-ldo";
+ regulator-min-microvolt = <1800000>;
+ regulator-max-microvolt = <1800000>;
+ regulator-always-on;
+ };
+ exten {
+ regulator-name = "rt5120-exten";
+ regulator-min-microvolt = <3000000>;
+ regulator-max-microvolt = <3000000>;
+ regulator-always-on;
+ };
+ };
+ powerkey {
+ compatible = "richtek,rt5120-pwrkey";
+ };
+ };
+ };
--
2.7.4
From: ChiYuan Huang <[email protected]>
Add Richtek RT5120 PMIC I2C driver.
Signed-off-by: ChiYuan Huang <[email protected]>
---
Since v4:
- Add "Copyright" string and refine for GPL version string.
- For the last uncertain terminated element in struct arrays, put the comma
for it to keep the extensibility.
Since v3:
- Use a 'dev' variable and dev_err_probe to decrease the LOC in mfd.
---
drivers/mfd/Kconfig | 12 +++++
drivers/mfd/Makefile | 1 +
drivers/mfd/rt5120.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 137 insertions(+)
create mode 100644 drivers/mfd/rt5120.c
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index abb58ab..bfceece 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1128,6 +1128,18 @@ config MFD_RT5033
sub-devices like charger, fuel gauge, flash LED, current source,
LDO and Buck.
+config MFD_RT5120
+ tristate "Richtek RT5120 Power Management IC"
+ depends on I2C
+ select MFD_CORE
+ select REGMAP_I2C
+ select REGMAP_IRQ
+ help
+ The enables support for Richtek RT5120 PMIC. It includes four high
+ efficiency buck converters and one LDO voltage regulator. The device
+ is targeted at providing the CPU voltage, memory, I/O and peripheral
+ power rails in home entertainment devices.
+
config MFD_RC5T583
bool "Ricoh RC5T583 Power Management system device"
depends on I2C=y
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 858cacf..27e8add 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -234,6 +234,7 @@ obj-$(CONFIG_MFD_HI655X_PMIC) += hi655x-pmic.o
obj-$(CONFIG_MFD_DLN2) += dln2.o
obj-$(CONFIG_MFD_RT4831) += rt4831.o
obj-$(CONFIG_MFD_RT5033) += rt5033.o
+obj-$(CONFIG_MFD_RT5120) += rt5120.o
obj-$(CONFIG_MFD_SKY81452) += sky81452.o
intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o
diff --git a/drivers/mfd/rt5120.c b/drivers/mfd/rt5120.c
new file mode 100644
index 00000000..8046e38
--- /dev/null
+++ b/drivers/mfd/rt5120.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022 Richtek Technology Corp.
+ * Author: ChiYuan Huang <[email protected]>
+ */
+
+#include <linux/i2c.h>
+#include <linux/kernel.h>
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/regmap.h>
+
+#define RT5120_REG_INTENABLE 0x1D
+#define RT5120_REG_INTSTAT 0x1E
+#define RT5120_REG_FZCMODE 0x44
+
+#define RT5120_INT_HOTDIE 0
+#define RT5120_INT_PWRKEY_REL 5
+#define RT5120_INT_PWRKEY_PRESS 6
+
+static const struct regmap_range rt5120_rd_yes_ranges[] = {
+ regmap_reg_range(0x03, 0x13),
+ regmap_reg_range(0x1c, 0x20),
+ regmap_reg_range(0x44, 0x44),
+};
+
+static const struct regmap_range rt5120_wr_yes_ranges[] = {
+ regmap_reg_range(0x06, 0x13),
+ regmap_reg_range(0x1c, 0x20),
+ regmap_reg_range(0x44, 0x44),
+};
+
+static const struct regmap_access_table rt5120_rd_table = {
+ .yes_ranges = rt5120_rd_yes_ranges,
+ .n_yes_ranges = ARRAY_SIZE(rt5120_rd_yes_ranges),
+};
+
+static const struct regmap_access_table rt5120_wr_table = {
+ .yes_ranges = rt5120_wr_yes_ranges,
+ .n_yes_ranges = ARRAY_SIZE(rt5120_wr_yes_ranges),
+};
+
+static const struct regmap_config rt5120_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = RT5120_REG_FZCMODE,
+
+ .wr_table = &rt5120_wr_table,
+ .rd_table = &rt5120_rd_table,
+};
+
+static const struct regmap_irq rt5120_irqs[] = {
+ REGMAP_IRQ_REG_LINE(RT5120_INT_HOTDIE, 8),
+ REGMAP_IRQ_REG_LINE(RT5120_INT_PWRKEY_REL, 8),
+ REGMAP_IRQ_REG_LINE(RT5120_INT_PWRKEY_PRESS, 8),
+};
+
+static const struct regmap_irq_chip rt5120_irq_chip = {
+ .name = "rt5120-pmic",
+ .status_base = RT5120_REG_INTSTAT,
+ .mask_base = RT5120_REG_INTENABLE,
+ .ack_base = RT5120_REG_INTSTAT,
+ .mask_invert = true,
+ .use_ack = true,
+ .num_regs = 1,
+ .irqs = rt5120_irqs,
+ .num_irqs = ARRAY_SIZE(rt5120_irqs),
+};
+
+static const struct resource rt5120_regulator_resources[] = {
+ DEFINE_RES_IRQ(RT5120_INT_HOTDIE),
+};
+
+static const struct resource rt5120_pwrkey_resources[] = {
+ DEFINE_RES_IRQ_NAMED(RT5120_INT_PWRKEY_PRESS, "pwrkey-press"),
+ DEFINE_RES_IRQ_NAMED(RT5120_INT_PWRKEY_REL, "pwrkey-release"),
+};
+
+static const struct mfd_cell rt5120_devs[] = {
+ MFD_CELL_RES("rt5120-regulator", rt5120_regulator_resources),
+ MFD_CELL_OF("rt5120-pwrkey", rt5120_pwrkey_resources, NULL, 0, 0, "richtek,rt5120-pwrkey"),
+};
+
+static int rt5120_probe(struct i2c_client *i2c)
+{
+ struct device *dev = &i2c->dev;
+ struct regmap *regmap;
+ struct regmap_irq_chip_data *irq_data;
+ int ret;
+
+ regmap = devm_regmap_init_i2c(i2c, &rt5120_regmap_config);
+ if (IS_ERR(regmap))
+ return dev_err_probe(dev, PTR_ERR(regmap),
+ "Failed to init regmap\n");
+
+ ret = devm_regmap_add_irq_chip(dev, regmap, i2c->irq, IRQF_ONESHOT, 0,
+ &rt5120_irq_chip, &irq_data);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to add IRQ chip\n");
+
+ return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, rt5120_devs,
+ ARRAY_SIZE(rt5120_devs), NULL, 0,
+ regmap_irq_get_domain(irq_data));
+}
+
+static const struct of_device_id rt5120_device_match_table[] = {
+ { .compatible = "richtek,rt5120" },
+ {}
+};
+MODULE_DEVICE_TABLE(of, rt5120_device_match_table);
+
+static struct i2c_driver rt5120_driver = {
+ .driver = {
+ .name = "rt5120",
+ .of_match_table = rt5120_device_match_table,
+ },
+ .probe_new = rt5120_probe,
+};
+module_i2c_driver(rt5120_driver);
+
+MODULE_AUTHOR("ChiYuan Huang <[email protected]>");
+MODULE_DESCRIPTION("Richtek RT5120 I2C driver");
+MODULE_LICENSE("GPL v2");
--
2.7.4
From: ChiYuan Huang <[email protected]>
Add RT5120 PMIC power key support.
Signed-off-by: ChiYuan Huang <[email protected]>
---
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
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 <[email protected]>
+ */
+
+#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 <[email protected]>");
+MODULE_DESCRIPTION("Richtek RT5120 power key driver");
+MODULE_LICENSE("GPL v2");
--
2.7.4
On Wed, 10 Aug 2022, cy_huang wrote:
> From: ChiYuan Huang <[email protected]>
>
> Add Richtek RT5120 PMIC I2C driver.
>
> Signed-off-by: ChiYuan Huang <[email protected]>
> ---
> Since v4:
> - Add "Copyright" string and refine for GPL version string.
> - For the last uncertain terminated element in struct arrays, put the comma
> for it to keep the extensibility.
>
> Since v3:
> - Use a 'dev' variable and dev_err_probe to decrease the LOC in mfd.
>
> ---
> drivers/mfd/Kconfig | 12 +++++
> drivers/mfd/Makefile | 1 +
> drivers/mfd/rt5120.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 137 insertions(+)
> create mode 100644 drivers/mfd/rt5120.c
Applied, thanks.
--
Lee Jones [李琼斯]
On Wed, 10 Aug 2022, cy_huang wrote:
> From: ChiYuan Huang <[email protected]>
>
> Add Richtek RT5120 PMIC devicetree document.
>
> Reviewed-by: Krzysztof Kozlowski <[email protected]>
> Signed-off-by: ChiYuan Huang <[email protected]>
> ---
> Since v2:
> - Add 'unevaluatedProperties: false' for regulator buck1~4/ldo/exten.
> - Fix indention and remove status for powerkey.
> - Refine powerkey description for more HW details.
>
> ---
> .../devicetree/bindings/mfd/richtek,rt5120.yaml | 178 +++++++++++++++++++++
> 1 file changed, 178 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/mfd/richtek,rt5120.yaml
Applied, thanks.
--
Lee Jones [李琼斯]
Dear reviewers:
cy_huang <[email protected]> 於 2022年8月10日 週三 上午10:55寫道:
>
> From: ChiYuan Huang <[email protected]>
>
> Add RT5120 PMIC power key support.
>
> Signed-off-by: ChiYuan Huang <[email protected]>
> ---
> 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 <[email protected]>
> + */
> +
> +#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 <[email protected]>");
> +MODULE_DESCRIPTION("Richtek RT5120 power key driver");
> +MODULE_LICENSE("GPL v2");
> --
> 2.7.4
>
Hi ChiYuan,
On Wed, Aug 10, 2022 at 10:55:42AM +0800, cy_huang wrote:
> +MODULE_AUTHOR("ChiYuan Huang <[email protected]>");
> +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.
--
Dmitry
Dmitry Torokhov <[email protected]> 於 2022年9月1日 週四 清晨6:47寫道:
>
> Hi ChiYuan,
>
> On Wed, Aug 10, 2022 at 10:55:42AM +0800, cy_huang wrote:
> > +MODULE_AUTHOR("ChiYuan Huang <[email protected]>");
> > +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
On Thu, Sep 01, 2022 at 08:39:05AM +0800, ChiYuan Huang wrote:
> Dmitry Torokhov <[email protected]> 於 2022年9月1日 週四 清晨6:47寫道:
> >
> > Hi ChiYuan,
> >
> > On Wed, Aug 10, 2022 at 10:55:42AM +0800, cy_huang wrote:
> > > +MODULE_AUTHOR("ChiYuan Huang <[email protected]>");
> > > +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.
--
Dmitry