Skip to contentSkip to conversation

Add MediaTek PMIC keys support

PATCH Superseded Chen Zhong 3 participants 12 messages Sep 17, 2017 – Sep 25, 2017

Subsystems (7)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Chen Zhong

author
#0 lore raw

v4 cover Add MediaTek PMIC keys support

Changes since v3:
- make the naming to be consistent as mtk_pmic or MTK_PMIC
- add suspend/resume functions to enable/disable irq
- change binding properties to define wakeup sources

Changes since v2:
- use standard properties for keycodes and debounce time
- change to use platform_get_irq in leaf drivers
- use better ways to define IRQ resources

Changes since v1:
- create irq mappings in mfd core driver instead of leaf drivers
- remove some unused parts in mtk-pmic-keys driver

MediaTek PMIC are multi-function devices that can handle key interrupts, typically there are two keys attached to PMIC, which called pwrkey and homekey. PWRKEY usually used to wake up system from sleep. Homekey can used as volume down key due to board design. Long press keys can shutdown PMIC, the mode can be choose to be one key only or two keys together.
This series add support for key functions for MediaTek PMIC MT6397/MT6323.

Chen Zhong (5):
mfd: mt6397: create irq mappings in mfd core driver
dt-bindings: input: Add document bindings for mtk-pmic-keys
dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
input: Add MediaTek PMIC keys support
mfd: mt6397: Add PMIC keys support to MT6397 driver

 .../devicetree/bindings/input/mtk-pmic-keys.txt    |   41 +++
 Documentation/devicetree/bindings/mfd/mt6397.txt   |    6 +
 drivers/input/keyboard/Kconfig                     |    9 +
 drivers/input/keyboard/Makefile                    |    1 +
 drivers/input/keyboard/mtk-pmic-keys.c             |  354 ++++++++++++++++++++
 drivers/mfd/mt6397-core.c                          |   26 +-
 drivers/rtc/rtc-mt6397.c                           |    7 +-
 7 files changed, 437 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

--
1.7.9.5

author
#1 lore raw

PATCH v4 1/5 mfd: mt6397: create irq mappings in mfd core driver

The core driver should create and manage irq mappings instead of leaf drivers. This patch change to pass irq domain to devm_mfd_add_devices() and it will create mapping for irq resources automatically. And remove irq mapping in rtc driver since this has been done in core driver.

---
 drivers/mfd/mt6397-core.c |    4 ++--
 drivers/rtc/rtc-mt6397.c  |    7 +++----
 2 files changed, 5 insertions(+), 6 deletions(-)
drivers/mfd/mt6397-core.c +2 -2
index 04a601f..6546d7f 100644
@@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
 		ret = devm_mfd_add_devices(&pdev->dev, -1, mt6323_devs,
 					   ARRAY_SIZE(mt6323_devs), NULL,
-					   0, NULL);
+					   0, pmic->irq_domain);
 		break;
 
 	case MT6397_CID_CODE:
@@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
 		ret = devm_mfd_add_devices(&pdev->dev, -1, mt6397_devs,
 					   ARRAY_SIZE(mt6397_devs), NULL,
-					   0, NULL);
+					   0, pmic->irq_domain);
 		break;
 
 	default:
drivers/rtc/rtc-mt6397.c +3 -4
index 1a61fa5..385f830 100644
@@ -322,10 +322,9 @@ static int mtk_rtc_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	rtc->addr_base = res->start;
 
-	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-	rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
-	if (rtc->irq <= 0)
-		return -EINVAL;
+	rtc->irq = platform_get_irq(pdev, 0);
+	if (rtc->irq < 0)
+		return rtc->irq;
 
 	rtc->regmap = mt6397_chip->regmap;
 	rtc->dev = &pdev->dev;
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH v4 2/5 dt-bindings: input: Add document bindings for mtk-pmic-keys

In reply to Chen Zhong

This patch adds the device tree binding documentation for the MediaTek pmic keys found on PMIC MT6397/MT6323.

---
 .../devicetree/bindings/input/mtk-pmic-keys.txt    |   41 ++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +41 -0
new file mode 100644
index 0000000..fd48ff7
@@ -0,0 +1,41 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: Specifies the numeric keycode values to
+	be used for reporting keys presses. The array can
+	contain up to 2 entries.
+
+Optional Properties:
+- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
+	or not. This can be customized depends on board design.
+- wakeup-source: PMIC keys can be used as wakeup sources.
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+	pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- debounce-interval: Long press key shutdown debouncing interval time
+	in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 0.
+
+Example:
+
+	pmic: mt6397 {
+		compatible = "mediatek,mt6397";
+
+		...
+
+		mt6397keys: mt6397keys {
+			compatible = "mediatek,mt6397-keys";
+			linux,keycodes = <116>, <114>;
+			mediatek,wakeup-keys = <1>, <0>;
+			wakeup-source;
+			mediatek,long-press-mode = <1>;
+			debounce-interval = <0>;
+		};
+	};
Signature · 1 line
1.7.9.5
maintainer
#3 lore raw

Re: [PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

Quoted 24 lines · Chen Zhong

This patch adds the device tree binding documentation for the MediaTek pmic keys found on PMIC MT6397/MT6323.

---
 .../devicetree/bindings/input/mtk-pmic-keys.txt    |   41 ++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +9 -0
new file mode 100644
index 0000000..fd48ff7
@@ -0,0 +1,41 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 19

Quoted 10 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +10 -0
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: Specifies the numeric keycode values to
+	be used for reporting keys presses. The array can
+	contain up to 2 entries.
+
+Optional Properties:
+- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
+	or not. This can be customized depends on board design.

I think this should be a common property if we're going to put into DT. Something like "wakeup-scancodes" to be clear the values are the raw scancodes. Alternatively, we could list Linux keycodes instead with something like "linux,wakeup-keycodes".

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 20

Quoted 1 line
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +1 -0
+- wakeup-source: PMIC keys can be used as wakeup sources.

Just "See ../power/wakeup-source.txt" for the description.

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 24

Quoted 4 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +4 -0
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+	pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- debounce-interval: Long press key shutdown debouncing interval time
+	in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 0.

This property units should be in milliseconds. However, this doesn't sound like debounce filtering time if 5-14 seconds. That sounds like forced power off time (i.e. for a hung device). This also should be common. I imagine we already have some drivers with similar properties.

Rob

maintainer
#4 lore raw

Re: [PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

Quoted 32 lines · Rob Herring
Quoted 31 lines · Chen Zhong

This patch adds the device tree binding documentation for the MediaTek pmic keys found on PMIC MT6397/MT6323.

---
 .../devicetree/bindings/input/mtk-pmic-keys.txt    |   41 ++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +16 -0
new file mode 100644
index 0000000..fd48ff7
@@ -0,0 +1,41 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: Specifies the numeric keycode values to
+	be used for reporting keys presses. The array can
+	contain up to 2 entries.
+
Quoted 8 lines

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 19

Quoted 3 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +3 -0
+Optional Properties:
+- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
+	or not. This can be customized depends on board design.

I think this should be a common property if we're going to put into DT. Something like "wakeup-scancodes" to be clear the values are the raw scancodes. Alternatively, we could list Linux keycodes instead with something like "linux,wakeup-keycodes".

Should we go the gpio-keys way and describe keys as sub-nodes, possibly using address as index?

		mt6397keys: mt6397keys {
			...

			power at 0 {
				linux,code = <116>;
				wakeup-source;
			};

			home at 1 {
				linux,code = <...>;
			};
		};

Thanks.

Signature · 1 line
Dmitry
author
#5 lore raw

Re: [PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

In reply to Rob Herring
Quoted 45 lines · Rob Herring
Quoted 24 lines · Chen Zhong

This patch adds the device tree binding documentation for the MediaTek pmic keys found on PMIC MT6397/MT6323.

---
 .../devicetree/bindings/input/mtk-pmic-keys.txt    |   41 ++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +9 -0
new file mode 100644
index 0000000..fd48ff7
@@ -0,0 +1,41 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 19

Quoted 10 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +10 -0
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: Specifies the numeric keycode values to
+	be used for reporting keys presses. The array can
+	contain up to 2 entries.
+
+Optional Properties:
+- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
+	or not. This can be customized depends on board design.

I think this should be a common property if we're going to put into DT. Something like "wakeup-scancodes" to be clear the values are the raw scancodes. Alternatively, we could list Linux keycodes instead with something like "linux,wakeup-keycodes".

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 20

Quoted 1 line
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +1 -0
+- wakeup-source: PMIC keys can be used as wakeup sources.

Just "See ../power/wakeup-source.txt" for the description.

Quoted 9 lines

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 24

Quoted 4 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +4 -0
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+	pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- debounce-interval: Long press key shutdown debouncing interval time
+	in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 0.

This property units should be in milliseconds. However, this doesn't sound like debounce filtering time if 5-14 seconds. That sounds like forced power off time (i.e. for a hung device). This also should be common. I imagine we already have some drivers with similar properties.

Hi Rob,

I searched in kernel documents and found a similar usage in "ti,palmas-pwrbutton.txt"
"- ti,palmas-long-press-seconds: Duration in seconds which the power
button should be kept pressed for Palmas to power off automatically."

Could I just wrote it like this?
mediatek,long-press-seconds = <0>;

And for the wakeup source part, how about Dmitry's suggestion? The whole device node would be:

mt6397keys: mt6397keys {
	compatible = "mediatek,mt6397-keys";
	mediatek,long-press-mode = <1>;
	mediatek,long-press-seconds = <0>;
	
	power at 0 {
		linux,code = <116>;
		wakeup-source;
	};

	home at 0 {
		linux,code = <114>;
	};
};

Thank you.

Quoted 2 lines

Rob

author
#6 lore raw

Re: [PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

Sorry for the typo.

Quoted 69 lines · Chen Zhong
Quoted 45 lines · Rob Herring
Quoted 24 lines · Chen Zhong

This patch adds the device tree binding documentation for the MediaTek pmic keys found on PMIC MT6397/MT6323.

---
 .../devicetree/bindings/input/mtk-pmic-keys.txt    |   41 ++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +9 -0
new file mode 100644
index 0000000..fd48ff7
@@ -0,0 +1,41 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 19

Quoted 10 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +10 -0
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: Specifies the numeric keycode values to
+	be used for reporting keys presses. The array can
+	contain up to 2 entries.
+
+Optional Properties:
+- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
+	or not. This can be customized depends on board design.

I think this should be a common property if we're going to put into DT. Something like "wakeup-scancodes" to be clear the values are the raw scancodes. Alternatively, we could list Linux keycodes instead with something like "linux,wakeup-keycodes".

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 20

Quoted 1 line
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +1 -0
+- wakeup-source: PMIC keys can be used as wakeup sources.

Just "See ../power/wakeup-source.txt" for the description.

Quoted 9 lines

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 24

Quoted 4 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +4 -0
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+	pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- debounce-interval: Long press key shutdown debouncing interval time
+	in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 0.

This property units should be in milliseconds. However, this doesn't sound like debounce filtering time if 5-14 seconds. That sounds like forced power off time (i.e. for a hung device). This also should be common. I imagine we already have some drivers with similar properties.

Hi Rob,

I searched in kernel documents and found a similar usage in "ti,palmas-pwrbutton.txt"
"- ti,palmas-long-press-seconds: Duration in seconds which the power
button should be kept pressed for Palmas to power off automatically."

Could I just wrote it like this?
mediatek,long-press-seconds = <0>;

And for the wakeup source part, how about Dmitry's suggestion? The whole device node would be:

Quoted 11 lines
mt6397keys: mt6397keys {
	compatible = "mediatek,mt6397-keys";
	mediatek,long-press-mode = <1>;
	mediatek,long-press-seconds = <0>;
	
	power at 0 {
		linux,code = <116>;
		wakeup-source;
	};

	home at 0 {

should be home at 1 {

Quoted 9 lines
		linux,code = <114>;
	};
};

Thank you.

Quoted 2 lines

Rob

maintainer
#7 lore raw

Re: [PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

Quoted 68 lines · Chen Zhong

Sorry for the typo.

Quoted 65 lines · Chen Zhong
Quoted 50 lines · Rob Herring
Quoted 24 lines · Chen Zhong

This patch adds the device tree binding documentation for the MediaTek pmic keys found on PMIC MT6397/MT6323.

---
 .../devicetree/bindings/input/mtk-pmic-keys.txt    |   41 ++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +9 -0
new file mode 100644
index 0000000..fd48ff7
@@ -0,0 +1,41 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 19

Quoted 10 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +10 -0
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: Specifies the numeric keycode values to
+ be used for reporting keys presses. The array can
+ contain up to 2 entries.
+
+Optional Properties:
+- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
+ or not. This can be customized depends on board design.

I think this should be a common property if we're going to put into DT. Something like "wakeup-scancodes" to be clear the values are the raw scancodes. Alternatively, we could list Linux keycodes instead with something like "linux,wakeup-keycodes".

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 20

Quoted 1 line
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +1 -0
+- wakeup-source: PMIC keys can be used as wakeup sources.

Just "See ../power/wakeup-source.txt" for the description.

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 24

Quoted 4 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +4 -0
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+ pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- debounce-interval: Long press key shutdown debouncing interval time
+ in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 0.
Quoted 4 lines

This property units should be in milliseconds. However, this doesn't sound like debounce filtering time if 5-14 seconds. That sounds like forced power off time (i.e. for a hung device). This also should be common. I imagine we already have some drivers with similar properties.

Hi Rob,

I searched in kernel documents and found a similar usage in "ti,palmas-pwrbutton.txt"
"- ti,palmas-long-press-seconds: Duration in seconds which the power
button should be kept pressed for Palmas to power off automatically."

Could I just wrote it like this?
mediatek,long-press-seconds = <0>;

That doesn't really tell what the long press does. How about "power-off-time-sec"? Surprisingly we don't have a common keyboard binding doc, so please start one and document it there. Then just refer to it.

Quoted 2 lines
Quoted 2 lines

And for the wakeup source part, how about Dmitry's suggestion?

It's fine for me.

Quoted 9 lines
Quoted 9 lines

The whole device node would be:

mt6397keys: mt6397keys {
      compatible = "mediatek,mt6397-keys";
      mediatek,long-press-mode = <1>;
      mediatek,long-press-seconds = <0>;

      power at 0 {
              linux,code = <116>;

linux,keycodes

Also, you either need a reg property with "0" or drop the unit address.

Quoted 16 lines
Quoted 4 lines
              wakeup-source;
      };

      home at 0 {

should be home at 1 {

Quoted 9 lines
              linux,code = <114>;
      };
};

Thank you.

Quoted 2 lines

Rob

author
#8 lore raw

Re: [PATCH v4 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys

Quoted 67 lines · Rob Herring
Quoted 66 lines · Chen Zhong

Sorry for the typo.

Quoted 63 lines · Chen Zhong
Quoted 50 lines · Rob Herring
Quoted 24 lines · Chen Zhong

This patch adds the device tree binding documentation for the MediaTek pmic keys found on PMIC MT6397/MT6323.

---
 .../devicetree/bindings/input/mtk-pmic-keys.txt    |   41 ++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +9 -0
new file mode 100644
index 0000000..fd48ff7
@@ -0,0 +1,41 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 19

Quoted 10 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +10 -0
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- linux,keycodes: Specifies the numeric keycode values to
+ be used for reporting keys presses. The array can
+ contain up to 2 entries.
+
+Optional Properties:
+- mediatek,wakeup-keys: Specifies each key can be used as a wakeup source
+ or not. This can be customized depends on board design.

I think this should be a common property if we're going to put into DT. Something like "wakeup-scancodes" to be clear the values are the raw scancodes. Alternatively, we could list Linux keycodes instead with something like "linux,wakeup-keycodes".

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 20

Quoted 1 line
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +1 -0
+- wakeup-source: PMIC keys can be used as wakeup sources.

Just "See ../power/wakeup-source.txt" for the description.

Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 24

Quoted 4 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +4 -0
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+ pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- debounce-interval: Long press key shutdown debouncing interval time
+ in seconds. 0/1/2/3 for 8/11/14/5 seconds. If not specified defaults to 0.
Quoted 4 lines

This property units should be in milliseconds. However, this doesn't sound like debounce filtering time if 5-14 seconds. That sounds like forced power off time (i.e. for a hung device). This also should be common. I imagine we already have some drivers with similar properties.

Hi Rob,

I searched in kernel documents and found a similar usage in "ti,palmas-pwrbutton.txt"
"- ti,palmas-long-press-seconds: Duration in seconds which the power
button should be kept pressed for Palmas to power off automatically."

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Could I just wrote it like this?
mediatek,long-press-seconds = <0>;

That doesn't really tell what the long press does. How about "power-off-time-sec"? Surprisingly we don't have a common keyboard binding doc, so please start one and document it there. Then just refer to it.

OK, I will add a common document named "keys.txt" and put the long press property "power-off-time-sec" there as a common property.

Quoted 12 lines
Quoted 2 lines
Quoted 2 lines

And for the wakeup source part, how about Dmitry's suggestion?

It's fine for me.

Quoted 7 lines
Quoted 7 lines

The whole device node would be:

mt6397keys: mt6397keys {
      compatible = "mediatek,mt6397-keys";
      mediatek,long-press-mode = <1>;
      mediatek,long-press-seconds = <0>;
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
      power at 0 {
              linux,code = <116>;

linux,keycodes

Also, you either need a reg property with "0" or drop the unit address.

There is no need to add reg property here, I'll drop the unit address.

Thank you.

Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
              wakeup-source;
      };

      home at 0 {

should be home at 1 {

Quoted 9 lines
              linux,code = <114>;
      };
};

Thank you.

Quoted 2 lines

Rob

author
#9 lore raw

PATCH v4 3/5 dt-bindings: mfd: Add bindings for the keys as subnode of PMIC

In reply to Chen Zhong

This patch adds documentation for device tree bindings for keys support as the subnode of MT6397/MT6323 PMIC.

---
 Documentation/devicetree/bindings/mfd/mt6397.txt |    6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/mfd/mt6397.txt +6 -0
index 522a3bb..d1df77f 100644
@@ -7,6 +7,7 @@ MT6397/MT6323 is a multifunction device with the following sub modules:
 - GPIO
 - Clock
 - LED
+- Keys
 
 It is interfaced to host controller using SPI interface by a proprietary hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
@@ -40,6 +41,11 @@ Optional subnodes:
 		- compatible: "mediatek,mt6323-led"
 	see Documentation/devicetree/bindings/leds/leds-mt6323.txt
 
+- keys
+	Required properties:
+		- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+	see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
+
 Example:
 	pwrap: pwrap at 1000f000 {
 		compatible = "mediatek,mt8135-pwrap";
Signature · 1 line
1.7.9.5
author
#10 lore raw

PATCH v4 4/5 input: Add MediaTek PMIC keys support

In reply to Chen Zhong

This patch add support to handle MediaTek PMIC MT6397/MT6323 key interrupts including pwrkey and homekey, also add setting for long press key shutdown behavior.

---
 drivers/input/keyboard/Kconfig         |    9 +
 drivers/input/keyboard/Makefile        |    1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  354 ++++++++++++++++++++++++++++++++
 3 files changed, 364 insertions(+)
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
drivers/input/keyboard/Kconfig +9 -0
index 4c4ab1c..bd4e20a 100644
@@ -756,4 +756,13 @@ config KEYBOARD_BCM
 	  To compile this driver as a module, choose M here: the
 	  module will be called bcm-keypad.
 
+config KEYBOARD_MTK_PMIC
+	tristate "MediaTek PMIC keys support"
+	depends on MFD_MT6397
+	help
+	  Say Y here if you want to use the pmic keys (powerkey/homekey).
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called pmic-keys.
+
 endif
drivers/input/keyboard/Makefile +1 -0
index d2338ba..20c0b98 100644
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX)		+= matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359)		+= max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS)		+= mcs_touchkey.o
 obj-$(CONFIG_KEYBOARD_MPR121)		+= mpr121_touchkey.o
+obj-$(CONFIG_KEYBOARD_MTK_PMIC) 	+= mtk-pmic-keys.o
 obj-$(CONFIG_KEYBOARD_NEWTON)		+= newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK)		+= nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)		+= nspire-keypad.o
drivers/input/keyboard/mtk-pmic-keys.c new file +354 -0

354 lines not on this page · raw message

Signature · 1 line
1.7.9.5
author
#11 lore raw

PATCH v4 5/5 mfd: mt6397: Add PMIC keys support to MT6397 driver

In reply to Chen Zhong

This patch adds compatible strings and interrupts for pmic keys which serves as child device of MFD.

---
 drivers/mfd/mt6397-core.c |   22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/mfd/mt6397-core.c +21 -1
index 6546d7f..77b64bd 100644
@@ -43,6 +43,16 @@
 	},
 };
 
+static const struct resource mt6323_keys_resources[] = {
+	DEFINE_RES_IRQ(MT6323_IRQ_STATUS_PWRKEY),
+	DEFINE_RES_IRQ(MT6323_IRQ_STATUS_FCHRKEY),
+};
+
+static const struct resource mt6397_keys_resources[] = {
+	DEFINE_RES_IRQ(MT6397_IRQ_PWRKEY),
+	DEFINE_RES_IRQ(MT6397_IRQ_HOMEKEY),
+};
+
 static const struct mfd_cell mt6323_devs[] = {
 	{
 		.name = "mt6323-regulator",
@@ -50,6 +60,11 @@
 	}, {
 		.name = "mt6323-led",
 		.of_compatible = "mediatek,mt6323-led"
+	}, {
+		.name = "mtk-pmic-keys",
+		.num_resources = ARRAY_SIZE(mt6323_keys_resources),
+		.resources = mt6323_keys_resources,
+		.of_compatible = "mediatek,mt6323-keys"
 	},
 };
 
@@ -71,7 +86,12 @@
 	}, {
 		.name = "mt6397-pinctrl",
 		.of_compatible = "mediatek,mt6397-pinctrl",
-	},
+	}, {
+		.name = "mtk-pmic-keys",
+		.num_resources = ARRAY_SIZE(mt6397_keys_resources),
+		.resources = mt6397_keys_resources,
+		.of_compatible = "mediatek,mt6397-keys"
+	}
 };
 
 static void mt6397_irq_lock(struct irq_data *data)
Signature · 1 line
1.7.9.5