Skip to contentSkip to conversation

Input: pm8941-pwrkey: add resin key capabilities

PATCH Superseded Tirupathi Reddy 4 participants 5 messages Mar 13, 2018 – Mar 15, 2018

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Input: pm8941-pwrkey: add resin key capabilities

Add resin key support to handle different types of key events defined in different platforms.

---
 .../bindings/input/qcom,pm8941-pwrkey.txt          | 20 ++++++-
 drivers/input/misc/pm8941-pwrkey.c                 | 65 +++++++++++++++++++++-
 2 files changed, 83 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +19 -1
index 07bf55f..f499cf8 100644
@@ -20,6 +20,14 @@ PROPERTIES
 		    defined by the binding document describing the node's
 		    interrupt parent.
 
+- interrupt-names:
+	Usage: required
+	Value type: <stringlist>
+	Definition: Interrupt names.  This list must match up 1-to-1 with the
+		    interrupts specified in the 'interrupts' property. "kpdpwr"
+		    must be specified and should be the first entry of the list.
+		    "resin" may be specified for some platforms.
+
 - debounce:
 	Usage: optional
 	Value type: <u32>
@@ -32,12 +40,22 @@ PROPERTIES
 	Definition: presence of this property indicates that the KPDPWR_N pin
 		    should be configured for pull up.
 
+- linux,code:
+	Usage: required for "resin" key
+	Value type: <u32>
+	Definition: The input key-code associated with the resin key.
+		    Use the linux event codes defined in
+		    include/dt-bindings/input/linux-event-codes.h
+
 EXAMPLE
 
 	pwrkey@800 {
 		compatible = "qcom,pm8941-pwrkey";
 		reg = <0x800>;
-		interrupts = <0x0 0x8 0 IRQ_TYPE_EDGE_BOTH>;
+		interrupts = <0x0 0x8 0 IRQ_TYPE_EDGE_BOTH>,
+			     <0x0 0x8 1 IRQ_TYPE_EDGE_BOTH>;
+		interrupt-names = "kpdpwr", "resin";
 		debounce = <15625>;
 		bias-pull-up;
+		linux,code = <KEY_VOLUMEDOWN>;
 	};
drivers/input/misc/pm8941-pwrkey.c +64 -1

100 lines not on this page · raw message

Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw

Hi Tirupathi,

Quoted 2 lines · Tirupathi Reddy

Add resin key support to handle different types of key events defined in different platforms.

Describe "resin"  in the commit text? or just call it same as power key or different purpose?

drivers/input/misc/pm8941-pwrkey.c static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data) · line 144

Quoted 11 lines
drivers/input/misc/pm8941-pwrkey.c +10 -0
+static irqreturn_t pm8941_resinkey_irq(int irq, void *_data)
+{
+	struct pm8941_pwrkey *pwrkey = _data;
+	unsigned int sts;
+	int error;
+
+	error = regmap_read(pwrkey->regmap,
+			    pwrkey->baseaddr + PON_RT_STS, &sts);
+	if (error)
+		return IRQ_HANDLED;

You may want to document here why you still return as IRQ_HANDLED on the error after reading the status register?

Quoted 6 lines
drivers/input/misc/pm8941-pwrkey.c +5 -0
+	resin_irq = platform_get_irq_byname(pdev, "resin");
+	if (resin_irq < 0 && resin_irq != -ENXIO) {
+		if (resin_irq != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "failed to get resin irq\n");
+		return resin_irq;

drivers/input/misc/pm8941-pwrkey.c static int pm8941_pwrkey_probe(struct platform_device *pdev) · line 306

Quoted 10 lines
drivers/input/misc/pm8941-pwrkey.c +10 -0
+	} else if (resin_irq >= 0) {
+		/* resin key capabilities are defined in device node */
+		error = pm8941_resin_key_init(pwrkey, resin_irq);
+		if (error) {
+			dev_err(&pdev->dev, "failed resin key initialization: %d\n",
+				error);
+			return error;
+		}
+	}
+

Any reason you don't want to create different driver for "resin" key? Is this going to be physically different key on the platform? Please describe why it needs to be part of the power key driver.

---Trilok Soni

Signature · 1 line
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
#2 lore raw
In reply to Tirupathi Reddy
Quoted 29 lines · Tirupathi Reddy

Add resin key support to handle different types of key events defined in different platforms.

---
 .../bindings/input/qcom,pm8941-pwrkey.txt          | 20 ++++++-
 drivers/input/misc/pm8941-pwrkey.c                 | 65 +++++++++++++++++++++-
 2 files changed, 83 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +8 -0
index 07bf55f..f499cf8 100644
@@ -20,6 +20,14 @@ PROPERTIES
 		    defined by the binding document describing the node's
 		    interrupt parent.
 
+- interrupt-names:
+	Usage: required
+	Value type: <stringlist>
+	Definition: Interrupt names.  This list must match up 1-to-1 with the
+		    interrupts specified in the 'interrupts' property. "kpdpwr"
+		    must be specified and should be the first entry of the list.
+		    "resin" may be specified for some platforms.
+
 - debounce:
 	Usage: optional
 	Value type: <u32>

Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt PROPERTIES · line 48

Quoted 9 lines
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +6 -0
@@ -32,12 +40,22 @@ PROPERTIES
 	Definition: presence of this property indicates that the KPDPWR_N pin
 		    should be configured for pull up.
 
+- linux,code:
+	Usage: required for "resin" key
+	Value type: <u32>
+	Definition: The input key-code associated with the resin key.
+		    Use the linux event codes defined in
+		    include/dt-bindings/input/linux-event-codes.h

For completeness sake I think this should list both the key code for the power key and for the RESIN key.

Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt PROPERTIES · line 59

Quoted 12 lines
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +4 -1
+
 EXAMPLE
 
 	pwrkey@800 {
 		compatible = "qcom,pm8941-pwrkey";
 		reg = <0x800>;
-		interrupts = <0x0 0x8 0 IRQ_TYPE_EDGE_BOTH>;
+		interrupts = <0x0 0x8 0 IRQ_TYPE_EDGE_BOTH>,
+			     <0x0 0x8 1 IRQ_TYPE_EDGE_BOTH>;
+		interrupt-names = "kpdpwr", "resin";
 		debounce = <15625>;
 		bias-pull-up;

Do we need to support defining the bias for the resin as well?

Perhaps it makes more sense to describe the RESIN key with a separate compatible and define that in a node of its own (we can still implement this in the same driver - if there's any chance of reuse...).

Quoted 24 lines
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +1 -0
+		linux,code = <KEY_VOLUMEDOWN>;
 	};
drivers/input/misc/pm8941-pwrkey.c +2 -0
index 18ad956..2fffc7c 100644
@@ -28,6 +28,7 @@
 
 #define PON_RT_STS			0x10
 #define  PON_KPDPWR_N_SET		BIT(0)
+#define  PON_RESIN_N_SET		BIT(1)
 
 #define PON_PS_HOLD_RST_CTL		0x5a
 #define PON_PS_HOLD_RST_CTL2		0x5b
@@ -46,6 +47,7 @@
 struct pm8941_pwrkey {
 	struct device *dev;
 	int irq;
+	u32 resin_key_code;
 	u32 baseaddr;
 	struct regmap *regmap;
 	struct input_dev *input;
@@ -130,6 +132,24 @@ static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data)
 	return IRQ_HANDLED;

drivers/input/misc/pm8941-pwrkey.c static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data) · line 142

Quoted 10 lines
drivers/input/misc/pm8941-pwrkey.c +8 -0
 }
 
+static irqreturn_t pm8941_resinkey_irq(int irq, void *_data)
+{
+	struct pm8941_pwrkey *pwrkey = _data;
+	unsigned int sts;
+	int error;
+
+	error = regmap_read(pwrkey->regmap,
+			    pwrkey->baseaddr + PON_RT_STS, &sts);

This needs to be broken because the line is 81 chars long, if you use a shorter name for the return value (e.g. "ret") you don't need to do this.

drivers/input/misc/pm8941-pwrkey.c static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data) · line 147

Quoted 5 lines
drivers/input/misc/pm8941-pwrkey.c +5 -0
+	if (error)
+		return IRQ_HANDLED;
+
+	input_report_key(pwrkey->input, pwrkey->resin_key_code,
+			 !!(sts & PON_RESIN_N_SET));

Put pwrkey->resin_key_code in a local variable named "key" (or even key_code) and you don't need to line wrap this one.

drivers/input/misc/pm8941-pwrkey.c static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data) · line 152

Quoted 5 lines
drivers/input/misc/pm8941-pwrkey.c +5 -0
+	input_sync(pwrkey->input);
+
+	return IRQ_HANDLED;
+}
+

Regards,
Bjorn

maintainer
#3 lore raw
Quoted 89 lines · Bjorn Andersson
Quoted 29 lines · Tirupathi Reddy

Add resin key support to handle different types of key events defined in different platforms.

---
 .../bindings/input/qcom,pm8941-pwrkey.txt          | 20 ++++++-
 drivers/input/misc/pm8941-pwrkey.c                 | 65 +++++++++++++++++++++-
 2 files changed, 83 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +8 -0
index 07bf55f..f499cf8 100644
@@ -20,6 +20,14 @@ PROPERTIES
 		    defined by the binding document describing the node's
 		    interrupt parent.
 
+- interrupt-names:
+	Usage: required
+	Value type: <stringlist>
+	Definition: Interrupt names.  This list must match up 1-to-1 with the
+		    interrupts specified in the 'interrupts' property. "kpdpwr"
+		    must be specified and should be the first entry of the list.
+		    "resin" may be specified for some platforms.
+
 - debounce:
 	Usage: optional
 	Value type: <u32>

Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt PROPERTIES · line 48

Quoted 9 lines
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +6 -0
@@ -32,12 +40,22 @@ PROPERTIES
 	Definition: presence of this property indicates that the KPDPWR_N pin
 		    should be configured for pull up.
 
+- linux,code:
+	Usage: required for "resin" key
+	Value type: <u32>
+	Definition: The input key-code associated with the resin key.
+		    Use the linux event codes defined in
+		    include/dt-bindings/input/linux-event-codes.h

For completeness sake I think this should list both the key code for the power key and for the RESIN key.

Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt PROPERTIES · line 59

Quoted 12 lines
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +4 -1
+
 EXAMPLE
 
 	pwrkey@800 {
 		compatible = "qcom,pm8941-pwrkey";
 		reg = <0x800>;
-		interrupts = <0x0 0x8 0 IRQ_TYPE_EDGE_BOTH>;
+		interrupts = <0x0 0x8 0 IRQ_TYPE_EDGE_BOTH>,
+			     <0x0 0x8 1 IRQ_TYPE_EDGE_BOTH>;
+		interrupt-names = "kpdpwr", "resin";
 		debounce = <15625>;
 		bias-pull-up;

Do we need to support defining the bias for the resin as well?

Perhaps it makes more sense to describe the RESIN key with a separate compatible and define that in a node of its own (we can still implement this in the same driver - if there's any chance of reuse...).

Quoted 26 lines
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +1 -0
+		linux,code = <KEY_VOLUMEDOWN>;
 	};
drivers/input/misc/pm8941-pwrkey.c +2 -0
index 18ad956..2fffc7c 100644
@@ -28,6 +28,7 @@
 
 #define PON_RT_STS			0x10
 #define  PON_KPDPWR_N_SET		BIT(0)
+#define  PON_RESIN_N_SET		BIT(1)
 
 #define PON_PS_HOLD_RST_CTL		0x5a
 #define PON_PS_HOLD_RST_CTL2		0x5b
@@ -46,6 +47,7 @@
 struct pm8941_pwrkey {
 	struct device *dev;
 	int irq;
+	u32 resin_key_code;
 	u32 baseaddr;
 	struct regmap *regmap;
 	struct input_dev *input;
@@ -130,6 +132,24 @@ static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data)
 	return IRQ_HANDLED;
 }
 
Quoted 12 lines

drivers/input/misc/pm8941-pwrkey.c static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data) · line 142

Quoted 8 lines
drivers/input/misc/pm8941-pwrkey.c +8 -0
+static irqreturn_t pm8941_resinkey_irq(int irq, void *_data)
+{
+	struct pm8941_pwrkey *pwrkey = _data;
+	unsigned int sts;
+	int error;
+
+	error = regmap_read(pwrkey->regmap,
+			    pwrkey->baseaddr + PON_RT_STS, &sts);

This needs to be broken because the line is 81 chars long, if you use a shorter name for the return value (e.g. "ret") you don't need to do this.

I prefer keeping it as "error" please.

Quoted 18 lines

drivers/input/misc/pm8941-pwrkey.c static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data) · line 147

Quoted 6 lines
drivers/input/misc/pm8941-pwrkey.c +5 -0
+	if (error)
+		return IRQ_HANDLED;
+
+	input_report_key(pwrkey->input, pwrkey->resin_key_code,
+			 !!(sts & PON_RESIN_N_SET));

Put pwrkey->resin_key_code in a local variable named "key" (or even key_code) and you don't need to line wrap this one.

drivers/input/misc/pm8941-pwrkey.c static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data) · line 152

Quoted 5 lines
drivers/input/misc/pm8941-pwrkey.c +5 -0
+	input_sync(pwrkey->input);
+
+	return IRQ_HANDLED;
+}
+

Regards,
Bjorn

Signature · 1 line
Dmitry
#4 lore raw

Hi,

Quoted 35 lines · Dmitry Torokhov
Quoted 34 lines · Bjorn Andersson
Quoted 32 lines · Tirupathi Reddy

Add resin key support to handle different types of key events defined in different platforms.

---
  .../bindings/input/qcom,pm8941-pwrkey.txt          | 20 ++++++-
  drivers/input/misc/pm8941-pwrkey.c                 | 65 +++++++++++++++++++++-
  2 files changed, 83 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +8 -0
index 07bf55f..f499cf8 100644
@@ -20,6 +20,14 @@ PROPERTIES
  		    defined by the binding document describing the node's
  		    interrupt parent.
 
+- interrupt-names:
+	Usage: required
+	Value type: <stringlist>
+	Definition: Interrupt names.  This list must match up 1-to-1 with the
+		    interrupts specified in the 'interrupts' property. "kpdpwr"
+		    must be specified and should be the first entry of the list.
+		    "resin" may be specified for some platforms.
+
  - debounce:
  	Usage: optional
  	Value type: <u32>
@@ -32,12 +40,22 @@ PROPERTIES
  	Definition: presence of this property indicates that the KPDPWR_N pin
  		    should be configured for pull up.
 
Quoted 8 lines
Quoted 8 lines

Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt PROPERTIES · line 48

Quoted 6 lines
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +6 -0
+- linux,code:
+	Usage: required for "resin" key
+	Value type: <u32>
+	Definition: The input key-code associated with the resin key.
+		    Use the linux event codes defined in
+		    include/dt-bindings/input/linux-event-codes.h

For completeness sake I think this should list both the key code for the power key and for the RESIN key.

Then it breaks existing DT nodes.
Since pwrkey functionality is fixed across platforms, "linux,code" specification through device tree is not required for it.

Quoted 13 lines
Quoted 13 lines

Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt PROPERTIES · line 59

Quoted 12 lines
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +4 -1
+
  EXAMPLE
 
  	pwrkey@800 {
  		compatible = "qcom,pm8941-pwrkey";
  		reg = <0x800>;
-		interrupts = <0x0 0x8 0 IRQ_TYPE_EDGE_BOTH>;
+		interrupts = <0x0 0x8 0 IRQ_TYPE_EDGE_BOTH>,
+			     <0x0 0x8 1 IRQ_TYPE_EDGE_BOTH>;
+		interrupt-names = "kpdpwr", "resin";
  		debounce = <15625>;
  		bias-pull-up;

Do we need to support defining the bias for the resin as well?

Good point, will add this support in Patch V3. Also, the debounce configuration in HW is common across power-key and resin.

Quoted 4 lines
Quoted 4 lines

Perhaps it makes more sense to describe the RESIN key with a separate compatible and define that in a node of its own (we can still implement this in the same driver - if there's any chance of reuse...).

The PMIC peripheral/module called PON(Power  on) generates these key events. Pwrkey(KPDPWR_N) is the primary supported key by this module, the others are optional. The resin may be supported a "defined" key. How about using the below logic for resin key without breaking the existing DTs as shown below:

    pwrkey@800 {
           compatible = "qcom,pm8941-pwrkey"; reg = <0x800>;
           interrupts = <0x0 0x8 0 IRQ_TYPE_EDGE_BOTH>; debounce = <15625>;
           bias-pull-up;

           resin {
                   interrupts = <0x0 0x8 1 IRQ_TYPE_EDGE_BOTH>; linux,code = <KEY_VOLUMEDOWN>; bias-pull-up;
           };
    };

Quoted 37 lines
Quoted 26 lines
Quoted 26 lines
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +1 -0
+		linux,code = <KEY_VOLUMEDOWN>;
  	};
drivers/input/misc/pm8941-pwrkey.c +2 -0
index 18ad956..2fffc7c 100644
@@ -28,6 +28,7 @@
 
  #define PON_RT_STS			0x10
  #define  PON_KPDPWR_N_SET		BIT(0)
+#define  PON_RESIN_N_SET		BIT(1)
 
  #define PON_PS_HOLD_RST_CTL		0x5a
  #define PON_PS_HOLD_RST_CTL2		0x5b
@@ -46,6 +47,7 @@
  struct pm8941_pwrkey {
  	struct device *dev;
  	int irq;
+	u32 resin_key_code;
  	u32 baseaddr;
  	struct regmap *regmap;
  	struct input_dev *input;
@@ -130,6 +132,24 @@ static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data)
  	return IRQ_HANDLED;
  }
 
Quoted 11 lines

drivers/input/misc/pm8941-pwrkey.c static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data) · line 142

Quoted 8 lines
drivers/input/misc/pm8941-pwrkey.c +8 -0
+static irqreturn_t pm8941_resinkey_irq(int irq, void *_data)
+{
+	struct pm8941_pwrkey *pwrkey = _data;
+	unsigned int sts;
+	int error;
+
+	error = regmap_read(pwrkey->regmap,
+			    pwrkey->baseaddr + PON_RT_STS, &sts);

This needs to be broken because the line is 81 chars long, if you use a shorter name for the return value (e.g. "ret") you don't need to do this.

Quoted 1 line

I prefer keeping it as "error" please.

Okay. I will keep it as "error".

Quoted 7 lines
Quoted 7 lines

drivers/input/misc/pm8941-pwrkey.c static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data) · line 147

Quoted 5 lines
drivers/input/misc/pm8941-pwrkey.c +5 -0
+	if (error)
+		return IRQ_HANDLED;
+
+	input_report_key(pwrkey->input, pwrkey->resin_key_code,
+			 !!(sts & PON_RESIN_N_SET));

Put pwrkey->resin_key_code in a local variable named "key" (or even key_code) and you don't need to line wrap this one.

Okay. I will address it in Patch V3.

Quoted 7 lines
Quoted 7 lines

drivers/input/misc/pm8941-pwrkey.c static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data) · line 152

Quoted 5 lines
drivers/input/misc/pm8941-pwrkey.c +5 -0
+	input_sync(pwrkey->input);
+
+	return IRQ_HANDLED;
+}
+

Regards,
Bjorn