Add MediaTek PMIC keys support
Subsystems (7)
v2 cover Add MediaTek PMIC keys support
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 | 36 +++ Documentation/devicetree/bindings/mfd/mt6397.txt | 6 + drivers/input/keyboard/Kconfig | 9 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/mtk-pmic-keys.c | 331 ++++++++++++++++++++ drivers/mfd/mt6397-core.c | 40 ++- drivers/rtc/rtc-mt6397.c | 2 +- 7 files changed, 421 insertions(+), 4 deletions(-) create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
Signature · 1 line
1.7.9.5
PATCH v2 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 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/mfd/mt6397-core.c +2 -2
@@ -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 +1 -1
@@ -323,7 +323,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) rtc->addr_base = res->start; res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); - rtc->irq =irq_create_mapping (mt6397_chip->irq_domain, res->start); + rtc->irq = res->start;if (rtc->irq <=0 )return -EINVAL ;
Signature · 1 line
1.7.9.5
Re: [PATCH v2 1/5] mfd: mt6397: create irq mappings in mfd core driver
Quoted 7 lines · Chen Zhong
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.Signed-off-by Chen Zhong <[email protected]>
For the RTC part:
Quoted 43 lines
--- drivers/mfd/mt6397-core.c | 4 ++-- drivers/rtc/rtc-mt6397.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/mfd/mt6397-core.c +2
-2@@ -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 +1
-1@@ -323,7 +323,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) rtc->addr_base = res->start; res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); - rtc->irq =irq_create_mapping (mt6397_chip->irq_domain, res->start); + rtc->irq = res->start;if (rtc->irq <=0 )return -EINVAL ;Signature · 1 line
1.7.9.5
Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Dmitry Torokhov
maintainerRe: [PATCH v2 1/5] mfd: mt6397: create irq mappings in mfd core driver
Quoted 46 lines · Alexandre Belloni
Quoted 7 lines · Chen Zhong
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.Signed-off-by Chen Zhong <[email protected]>For the RTC part:
Quoted 34 lines
--- drivers/mfd/mt6397-core.c | 4 ++-- drivers/rtc/rtc-mt6397.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/mfd/mt6397-core.c +2
-2@@ -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 +0
-0@@ -323,7 +323,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) rtc->addr_base = res->start;
Quoted 3 lines
drivers/rtc/rtc-mt6397.c static int mtk_rtc_probe(struct platform_device *pdev) · line 326
Quoted 3 lines
drivers/rtc/rtc-mt6397.c +1
-1res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); - rtc->irq =irq_create_mapping (mt6397_chip->irq_domain, res->start); + rtc->irq = res->start;
Why not
rtc->irq = platform_get_irq(pdev, 0); if (rtc->irq < 0) return rtc->irq;
?
This way you propagate error properly.
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH v2 1/5] mfd: mt6397: create irq mappings in mfd core driver
Quoted 53 lines · Dmitry Torokhov
Quoted 46 lines · Alexandre Belloni
Quoted 7 lines · Chen Zhong
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.Signed-off-by Chen Zhong <[email protected]>For the RTC part:
Quoted 34 lines
--- drivers/mfd/mt6397-core.c | 4 ++-- drivers/rtc/rtc-mt6397.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/mfd/mt6397-core.c +2
-2@@ -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 +0
-0@@ -323,7 +323,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) rtc->addr_base = res->start;Quoted 3 lines
drivers/rtc/rtc-mt6397.c static int mtk_rtc_probe(struct platform_device *pdev) · line 326
Quoted 3 lines
drivers/rtc/rtc-mt6397.c +1
-1res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); - rtc->irq =irq_create_mapping (mt6397_chip->irq_domain, res->start); + rtc->irq = res->start;Why not
Quoted 9 lines
rtc->irq = platform_get_irq(pdev, 0); if (rtc->irq < 0) return rtc->irq;?
This way you propagate error properly.
Thanks.
Hi Dmitry,
I'll modify it to get irq number via this way.
Thank you.
Re: [PATCH v2 1/5] mfd: mt6397: create irq mappings in mfd core driver
In reply to Chen ZhongQuoted 11 lines · Chen Zhong
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.Signed-off-by Chen Zhong <[email protected]>--- drivers/mfd/mt6397-core.c | 4 ++-- drivers/rtc/rtc-mt6397.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
Once you've fixed Dmitry's comment:
For my own reference:
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH v2 2/5 dt-bindings: input: Add document bindings for mtk-pmic-keys
In reply to Chen ZhongThis patch adds the device tree binding documentation for the MediaTek pmic keys found on PMIC MT6397/MT6323.
--- .../devicetree/bindings/input/mtk-pmic-keys.txt | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +36 -0
@@ -0,0 +1,36 @@ +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" +- mediatek,pwrkey-code: Keycode of pwrkey + +Optional Properties: +- mediatek,homekey-code: Keycode of homekey +- mediatek,long-press-mode: Long press key shutdown setting, 1 for + pwrkey only, 2 for pwrkey/homekey together, others for disabled. +- mediatek,long-press-duration: Long press key shutdown duration setting, + 0/1/2/3 for 8/11/14/5 seconds. + +Example: + + pmic: mt6397 { + compatible = "mediatek,mt6397"; + + ... + + mt6397keys: mt6397keys { + compatible = "mediatek,mt6397-keys"; + mediatek,pwrkey-code = <116>; + mediatek,homekey-code = <114>; + mediatek,long-press-mode = <1>; + mediatek,long-press-duration = <0>; + }; + };
Signature · 1 line
1.7.9.5
Rob Herring
maintainerRe: [PATCH v2 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys
Quoted 25 lines · Chen Zhong
This patch adds the device tree binding documentation for the MediaTek pmic keys found on PMIC MT6397/MT6323.
Signed-off-by Chen Zhong <[email protected]>--- .../devicetree/bindings/input/mtk-pmic-keys.txt | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txtDocumentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +10
-0@@ -0,0 +1,36 @@ +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 20
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" +- mediatek,pwrkey-code: Keycode of pwrkey + +Optional Properties: +- mediatek,homekey-code: Keycode of homekey +- mediatek,long-press-mode: Long press key shutdown setting, 1 for + pwrkey only, 2 for pwrkey/homekey together, others for disabled. +- mediatek,long-press-duration: Long press key shutdown duration setting, + 0/1/2/3 for 8/11/14/5 seconds.
Surely this could be a common property.
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 32
Quoted 12 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +12
-0+ +Example: + + pmic: mt6397 { + compatible = "mediatek,mt6397"; + + ... + + mt6397keys: mt6397keys { + compatible = "mediatek,mt6397-keys"; + mediatek,pwrkey-code = <116>; + mediatek,homekey-code = <114>;
We have a standard properties for keycodes.
Quoted 8 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +4
-0+ mediatek,long-press-mode = <1>; + mediatek,long-press-duration = <0>; + }; + };Signature · 1 line
1.7.9.5
Re: [PATCH v2 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys
Hi Rob,
Quoted 30 lines · Rob Herring
Quoted 29 lines · Chen Zhong
This patch adds the device tree binding documentation for the MediaTek pmic keys found on PMIC MT6397/MT6323.
Signed-off-by Chen Zhong <[email protected]>--- .../devicetree/bindings/input/mtk-pmic-keys.txt | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txtDocumentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +14
-0@@ -0,0 +1,36 @@ +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" +- mediatek,pwrkey-code: Keycode of pwrkey +
Quoted 8 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 20
Quoted 6 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +6
-0+Optional Properties: +- mediatek,homekey-code: Keycode of homekey +- mediatek,long-press-mode: Long press key shutdown setting, 1 for + pwrkey only, 2 for pwrkey/homekey together, others for disabled. +- mediatek,long-press-duration: Long press key shutdown duration setting, + 0/1/2/3 for 8/11/14/5 seconds.Surely this could be a common property.
Sorry I'm not very clear about this. Could i move this to required properties or remove the "mediatek" string here?
Quoted 15 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt line 32
Quoted 13 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +12
-0+ +Example: + + pmic: mt6397 { + compatible = "mediatek,mt6397"; + + ... + + mt6397keys: mt6397keys { + compatible = "mediatek,mt6397-keys"; + mediatek,pwrkey-code = <116>; + mediatek,homekey-code = <114>;We have a standard properties for keycodes.
Could i write them like this way?
linux,keycodes = <KEY_POWER>, <KEY_VOLUMEDOWN>
Quoted 9 lines
Quoted 9 lines
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt new file +4
-0+ mediatek,long-press-mode = <1>; + mediatek,long-press-duration = <0>; + }; + };Signature · 1 line
1.7.9.5
Thanks.
PATCH v2 3/5 dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
In reply to Chen ZhongThis 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
@@ -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
Re: [PATCH v2 3/5] dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
Quoted 7 lines · Chen Zhong
This patch adds documentation for device tree bindings for keys support as the subnode of MT6397/MT6323 PMIC.
Signed-off-by Chen Zhong <[email protected]>--- Documentation/devicetree/bindings/mfd/mt6397.txt | 6 ++++++ 1 file changed, 6 insertions(+)
PATCH v2 4/5 input: Add MediaTek PMIC keys support
In reply to Chen ZhongThis 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 | 331 ++++++++++++++++++++++++++++++++ 3 files changed, 341 insertions(+) create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
drivers/input/keyboard/Kconfig +9 -0
@@ -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 (pwrkey/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
@@ -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 +331 -0
331 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Dmitry Torokhov
maintainerRe: [PATCH v2 4/5] input: Add MediaTek PMIC keys support
Hi Chen,
Quoted 68 lines · 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.
Signed-off-by Chen Zhong <[email protected]>--- drivers/input/keyboard/Kconfig | 9 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/mtk-pmic-keys.c | 331 ++++++++++++++++++++++++++++++++ 3 files changed, 341 insertions(+) create mode 100644 drivers/input/keyboard/mtk-pmic-keys.cdrivers/input/keyboard/Kconfig +9
-0@@ -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 (pwrkey/homekey). + + To compile this driver as a module, choose M here: the + module will be called pmic-keys. + endifdrivers/input/keyboard/Makefile +1
-0@@ -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.odrivers/input/keyboard/mtk-pmic-keys.c new file +20
-0@@ -0,0 +1,331 @@ +/* +* Copyright (C) 2017 MediaTek, Inc. +* +* Author: Chen Zhong <[email protected]> +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/input.h> +#include <linux/interrupt.h>
drivers/input/keyboard/mtk-pmic-keys.c line 30
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+#include <linux/platform_device.h> +#include <linux/kernel.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/regmap.h> +#include <linux/mfd/mt6323/registers.h> +#include <linux/mfd/mt6397/registers.h> +#include <linux/mfd/mt6397/core.h> +#include <linux/slab.h> +#include <linux/irqdomain.h>
Not needed.
Quoted 47 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +47
-0+ +#define PWRKEY_RST_EN_MASK 0x1 +#define PWRKEY_RST_EN_SHIFT 6 +#define HOMEKEY_RST_EN_MASK 0x1 +#define HOMEKEY_RST_EN_SHIFT 5 +#define RST_DU_MASK 0x3 +#define RST_DU_SHIFT 8 + +struct pmic_keys_regs { +u32 deb_reg; +u32 deb_mask; +u32 intsel_reg; +u32 intsel_mask; +}; + +#define PMIC_KEYS_REGS (_deb_reg, _deb_mask, _intsel_reg, _intsel_mask) \ +{ \ + .deb_reg = _deb_reg, \ + .deb_mask = _deb_mask, \ + .intsel_reg = _intsel_reg, \ + .intsel_mask = _intsel_mask, \ +} + +struct pmic_regs { +const struct pmic_keys_regs pwrkey_regs; +const struct pmic_keys_regs homekey_regs; +u32 pmic_rst_reg; +}; + +static const struct pmic_regs mt6397_regs = { + .pwrkey_regs =PMIC_KEYS_REGS (MT6397_CHRSTATUS , +0x8 ,MT6397_INT_RSV ,0x10 ), + .homekey_regs =PMIC_KEYS_REGS (MT6397_OCSTATUS2 , +0x10 ,MT6397_INT_RSV ,0x8 ), + .pmic_rst_reg =MT6397_TOP_RST_MISC , +}; + +static const struct pmic_regs mt6323_regs = { + .pwrkey_regs =PMIC_KEYS_REGS (MT6323_CHRSTATUS , +0x2 ,MT6323_INT_MISC_CON ,0x10 ), + .homekey_regs =PMIC_KEYS_REGS (MT6323_CHRSTATUS , +0x4 ,MT6323_INT_MISC_CON ,0x8 ), + .pmic_rst_reg =MT6323_TOP_RST_MISC , +}; + +struct pmic_keys_info { +struct mtk_pmic_keys *keys;
drivers/input/keyboard/mtk-pmic-keys.c line 87
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+const struct pmic_keys_regs *regs; +int keycode; +int irq; +}; + +struct mtk_pmic_keys { +struct input_dev *input_dev; +struct device *dev; +struct regmap *regmap; +struct irq_domain *irq_domain;
Not needed.
Quoted 114 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +114
-0+struct pmic_keys_info pwrkey, homekey; +}; + +enum long_press_mode { +LP_DISABLE , +LP_ONEKEY , +LP_TWOKEY , +}; + +static void long_press_reset_setup (struct mtk_pmic_keys *keys,u32 pmic_rst_reg) +{ +int ret; +u32 long_press_mode, long_press_duration; + + ret =of_property_read_u32 (keys->dev->of_node, +"mediatek,long-press-duration" , &long_press_duration); +if (ret) + long_press_duration =0 ; + +regmap_update_bits (keys->regmap, pmic_rst_reg, +RST_DU_MASK <<RST_DU_SHIFT , + long_press_duration <<RST_DU_SHIFT ); + + ret =of_property_read_u32 (keys->dev->of_node, +"mediatek,long-press-mode" , &long_press_mode); +if (ret) + long_press_mode =LP_DISABLE ; + +switch (long_press_mode) { +case LP_ONEKEY : +regmap_update_bits (keys->regmap, pmic_rst_reg, +PWRKEY_RST_EN_MASK <<PWRKEY_RST_EN_SHIFT , +PWRKEY_RST_EN_MASK <<PWRKEY_RST_EN_SHIFT ); +regmap_update_bits (keys->regmap, pmic_rst_reg, +HOMEKEY_RST_EN_MASK <<HOMEKEY_RST_EN_SHIFT , +0 ); +break ; +case LP_TWOKEY : +regmap_update_bits (keys->regmap, pmic_rst_reg, +PWRKEY_RST_EN_MASK <<PWRKEY_RST_EN_SHIFT , +PWRKEY_RST_EN_MASK <<PWRKEY_RST_EN_SHIFT ); +regmap_update_bits (keys->regmap, pmic_rst_reg, +HOMEKEY_RST_EN_MASK <<HOMEKEY_RST_EN_SHIFT , +HOMEKEY_RST_EN_MASK <<HOMEKEY_RST_EN_SHIFT ); +break ; +case LP_DISABLE : +regmap_update_bits (keys->regmap, pmic_rst_reg, +PWRKEY_RST_EN_MASK <<PWRKEY_RST_EN_SHIFT , +0 ); +regmap_update_bits (keys->regmap, pmic_rst_reg, +HOMEKEY_RST_EN_MASK <<HOMEKEY_RST_EN_SHIFT , +0 ); +break ; +default : +break ; + } +} + +static irqreturn_t mtk_pmic_keys_irq_handler_thread (int irq,void *data) +{ +struct pmic_keys_info *info = data; +u32 key_deb, pressed; + +regmap_read (info->keys->regmap, info->regs->deb_reg, &key_deb); + + key_deb &= info->regs->deb_mask; + + pressed = !key_deb; + +input_report_key (info->keys->input_dev, info->keycode, pressed); +input_sync (info->keys->input_dev); + +dev_dbg (info->keys->dev,"[PMICKEYS] (%s) key =%d using PMIC\n" , + pressed ?"pressed" :"released" , info->keycode); + +return IRQ_HANDLED ; +} + +static int mtk_pmic_key_setup (struct mtk_pmic_keys *keys, +const char *propname,struct pmic_keys_info *info,bool wakeup) +{ +int ret; + + ret =of_property_read_u32 (keys->dev->of_node, + propname, &info->keycode); +if (ret) +return 0 ; + +if (!info->keycode) +return 0 ; + + info->keys = keys; + + ret =regmap_update_bits (keys->regmap, info->regs->intsel_reg, + info->regs->intsel_mask, + info->regs->intsel_mask); +if (ret <0 ) +return ret; + + ret =devm_request_threaded_irq (keys->dev, info->irq,NULL , + mtk_pmic_keys_irq_handler_thread, +IRQF_ONESHOT |IRQF_TRIGGER_HIGH , +"mtk-pmic-keys" , info); +if (ret) { +dev_err (keys->dev,"Failed to request IRQ: %d: %d\n" , + info->irq, ret); +return ret; + } + +if (wakeup) +irq_set_irq_wake (info->irq,1 ); + +input_set_capability (keys->input_dev,EV_KEY , info->keycode); +
drivers/input/keyboard/mtk-pmic-keys.c line 211
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+return 0 ; +} + +static void mtk_pmic_keys_dispose_irq (struct mtk_pmic_keys *keys) +{ +if (keys->pwrkey.irq) +irq_dispose_mapping (keys->pwrkey.irq); + +if (keys->homekey.irq) +irq_dispose_mapping (keys->homekey.irq);
You did not create the mapping, you should not destroy it.
Quoted 23 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +23
-0+} + +static const struct of_device_id of_pmic_keys_match_tbl[] = { + { + .compatible ="mediatek,mt6397-keys" , + .data = &mt6397_regs, + }, { + .compatible ="mediatek,mt6323-keys" , + .data = &mt6323_regs, + }, { +/* sentinel */ + } +}; +MODULE_DEVICE_TABLE (of, of_pmic_keys_match_tbl); + +static int mtk_pmic_keys_probe (struct platform_device *pdev) +{ +int ret; +struct resource *res_pwrkey, *res_homekey; +struct mt6397_chip *pmic_chip =dev_get_drvdata (pdev->dev.parent); +struct mtk_pmic_keys *keys; +const struct pmic_regs *pmic_regs; +struct input_dev *input_dev;
drivers/input/keyboard/mtk-pmic-keys.c line 244
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+const struct of_device_id *of_id = +of_match_device (of_pmic_keys_match_tbl, &pdev->dev); + + keys =devm_kzalloc (&pdev->dev,sizeof (*keys),GFP_KERNEL ); +if (!keys) +return -ENOMEM ; + + keys->dev = &pdev->dev; + keys->regmap = pmic_chip->regmap; + keys->irq_domain = pmic_chip->irq_domain;
Not needed.
Quoted 4 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +4
-0+ + pmic_regs = of_id->data; + keys->pwrkey.regs = &pmic_regs->pwrkey_regs; + keys->homekey.regs = &pmic_regs->homekey_regs;
drivers/input/keyboard/mtk-pmic-keys.c line 258
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+ + res_pwrkey =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); +if (!res_pwrkey) { +dev_err (&pdev->dev,"no IRQ resource\n" ); +return -ENODEV ; + } + + keys->pwrkey.irq = res_pwrkey->start; +if (keys->pwrkey.irq <=0 ) +return -EINVAL ;
Please do
keys->pwrkey.irq = platform_get_irq(pdev, 0); if (keys->pwrkey.irq < 0) return keys->pwrkey.irq;
drivers/input/keyboard/mtk-pmic-keys.c line 268
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+ + res_homekey =platform_get_resource (pdev,IORESOURCE_IRQ ,1 ); +if (!res_homekey) { +dev_err (&pdev->dev,"no IRQ resource\n" ); +return -ENODEV ; + } + + keys->homekey.irq = res_homekey->start; +if (keys->homekey.irq <=0 ) +return -EINVAL ;
Same as above.
drivers/input/keyboard/mtk-pmic-keys.c line 281
Quoted 13 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +13
-0+ + keys->input_dev = input_dev =devm_input_allocate_device (keys->dev); +if (!input_dev) { +dev_err (&pdev->dev,"[PMICKEYS] input allocate device fail.\n" ); +return -ENOMEM ; + } + + input_dev->name ="mtk-pmic-keys" ; + input_dev->id.bustype =BUS_HOST ; + input_dev->id.vendor =0x0001 ; + input_dev->id.product =0x0001 ; + input_dev->id.version =0x0001 ; + input_dev->dev.parent = &pdev->dev;
Not needed, devm_input_allocate_device() already does this.
drivers/input/keyboard/mtk-pmic-keys.c line 286
Quoted 5 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +5
-0+ + ret =mtk_pmic_key_setup (keys,"mediatek,pwrkey-code" , + &keys->pwrkey, true); +if (ret) + goto out_dispose_irq;
Can you please call this variable "error" and do
if (error) return error;
You are using devm and no longer creating mappings, so you can return directly and rely on devm infrastructure to unwind.
drivers/input/keyboard/mtk-pmic-keys.c line 296
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+ + ret =mtk_pmic_key_setup (keys,"mediatek,homekey-code" , + &keys->homekey, false); +if (ret) + goto out_dispose_irq; + + ret =input_register_device (input_dev); +if (ret) { +dev_err (&pdev->dev, +"[PMICKEYS] register input device failed (%d)\n" , ret);
No need for [PMICKEYS] prefix, dev_err prints device and driver already.
Quoted 7 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +7
-0+return ret; + } + +long_press_reset_setup (keys, pmic_regs->pmic_rst_reg); + +return 0 ; +
drivers/input/keyboard/mtk-pmic-keys.c line 313
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+out_dispose_irq: +mtk_pmic_keys_dispose_irq (keys); +return ret; +} + +static int mtk_pmic_keys_remove (struct platform_device *pdev) +{ +struct mtk_pmic_keys *keys =platform_get_drvdata (pdev); + +mtk_pmic_keys_dispose_irq (keys);
Not needed. The whole function is not needed.
Quoted 21 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +18
-0+ +return 0 ; +} + +static struct platform_driver pmic_keys_pdrv = { + .probe = mtk_pmic_keys_probe, + .remove = mtk_pmic_keys_remove, + .driver = { + .name ="mtk-pmic-keys" , + .of_match_table = of_pmic_keys_match_tbl, + }, +}; + +module_platform_driver (pmic_keys_pdrv); + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("Chen Zhong <[email protected]>" ); +MODULE_DESCRIPTION ("MTK pmic-keys driver v0.1" );Signature · 1 line
1.7.9.5
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH v2 4/5] input: Add MediaTek PMIC keys support
Hi Dmitry,
Thanks for your suggestions. I'll modify them and send the next version
later.
Quoted 75 lines · Dmitry Torokhov
Hi Chen,
Quoted 72 lines · 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.
Signed-off-by Chen Zhong <[email protected]>--- drivers/input/keyboard/Kconfig | 9 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/mtk-pmic-keys.c | 331 ++++++++++++++++++++++++++++++++ 3 files changed, 341 insertions(+) create mode 100644 drivers/input/keyboard/mtk-pmic-keys.cdrivers/input/keyboard/Kconfig +9
-0@@ -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 (pwrkey/homekey). + + To compile this driver as a module, choose M here: the + module will be called pmic-keys. + endifdrivers/input/keyboard/Makefile +1
-0@@ -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.odrivers/input/keyboard/mtk-pmic-keys.c new file +24
-0@@ -0,0 +1,331 @@ +/* +* Copyright (C) 2017 MediaTek, Inc. +* +* Author: Chen Zhong <[email protected]> +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/platform_device.h> +#include <linux/kernel.h> +#include <linux/of.h> +#include <linux/of_device.h>
Quoted 8 lines
drivers/input/keyboard/mtk-pmic-keys.c line 30
Quoted 6 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +6
-0+#include <linux/regmap.h> +#include <linux/mfd/mt6323/registers.h> +#include <linux/mfd/mt6397/registers.h> +#include <linux/mfd/mt6397/core.h> +#include <linux/slab.h> +#include <linux/irqdomain.h> Not needed.
Sorry for that. All not needed parts will be removed.
Quoted 179 lines
Quoted 48 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +47
-0+ +#define PWRKEY_RST_EN_MASK 0x1 +#define PWRKEY_RST_EN_SHIFT 6 +#define HOMEKEY_RST_EN_MASK 0x1 +#define HOMEKEY_RST_EN_SHIFT 5 +#define RST_DU_MASK 0x3 +#define RST_DU_SHIFT 8 + +struct pmic_keys_regs { +u32 deb_reg; +u32 deb_mask; +u32 intsel_reg; +u32 intsel_mask; +}; + +#define PMIC_KEYS_REGS (_deb_reg, _deb_mask, _intsel_reg, _intsel_mask) \ +{ \ + .deb_reg = _deb_reg, \ + .deb_mask = _deb_mask, \ + .intsel_reg = _intsel_reg, \ + .intsel_mask = _intsel_mask, \ +} + +struct pmic_regs { +const struct pmic_keys_regs pwrkey_regs; +const struct pmic_keys_regs homekey_regs; +u32 pmic_rst_reg; +}; + +static const struct pmic_regs mt6397_regs = { + .pwrkey_regs =PMIC_KEYS_REGS (MT6397_CHRSTATUS , +0x8 ,MT6397_INT_RSV ,0x10 ), + .homekey_regs =PMIC_KEYS_REGS (MT6397_OCSTATUS2 , +0x10 ,MT6397_INT_RSV ,0x8 ), + .pmic_rst_reg =MT6397_TOP_RST_MISC , +}; + +static const struct pmic_regs mt6323_regs = { + .pwrkey_regs =PMIC_KEYS_REGS (MT6323_CHRSTATUS , +0x2 ,MT6323_INT_MISC_CON ,0x10 ), + .homekey_regs =PMIC_KEYS_REGS (MT6323_CHRSTATUS , +0x4 ,MT6323_INT_MISC_CON ,0x8 ), + .pmic_rst_reg =MT6323_TOP_RST_MISC , +}; + +struct pmic_keys_info { +struct mtk_pmic_keys *keys;drivers/input/keyboard/mtk-pmic-keys.c line 87
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+const struct pmic_keys_regs *regs; +int keycode; +int irq; +}; + +struct mtk_pmic_keys { +struct input_dev *input_dev; +struct device *dev; +struct regmap *regmap; +struct irq_domain *irq_domain;Not needed.
Quoted 118 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +118
-0+struct pmic_keys_info pwrkey, homekey; +}; + +enum long_press_mode { +LP_DISABLE , +LP_ONEKEY , +LP_TWOKEY , +}; + +static void long_press_reset_setup (struct mtk_pmic_keys *keys,u32 pmic_rst_reg) +{ +int ret; +u32 long_press_mode, long_press_duration; + + ret =of_property_read_u32 (keys->dev->of_node, +"mediatek,long-press-duration" , &long_press_duration); +if (ret) + long_press_duration =0 ; + +regmap_update_bits (keys->regmap, pmic_rst_reg, +RST_DU_MASK <<RST_DU_SHIFT , + long_press_duration <<RST_DU_SHIFT ); + + ret =of_property_read_u32 (keys->dev->of_node, +"mediatek,long-press-mode" , &long_press_mode); +if (ret) + long_press_mode =LP_DISABLE ; + +switch (long_press_mode) { +case LP_ONEKEY : +regmap_update_bits (keys->regmap, pmic_rst_reg, +PWRKEY_RST_EN_MASK <<PWRKEY_RST_EN_SHIFT , +PWRKEY_RST_EN_MASK <<PWRKEY_RST_EN_SHIFT ); +regmap_update_bits (keys->regmap, pmic_rst_reg, +HOMEKEY_RST_EN_MASK <<HOMEKEY_RST_EN_SHIFT , +0 ); +break ; +case LP_TWOKEY : +regmap_update_bits (keys->regmap, pmic_rst_reg, +PWRKEY_RST_EN_MASK <<PWRKEY_RST_EN_SHIFT , +PWRKEY_RST_EN_MASK <<PWRKEY_RST_EN_SHIFT ); +regmap_update_bits (keys->regmap, pmic_rst_reg, +HOMEKEY_RST_EN_MASK <<HOMEKEY_RST_EN_SHIFT , +HOMEKEY_RST_EN_MASK <<HOMEKEY_RST_EN_SHIFT ); +break ; +case LP_DISABLE : +regmap_update_bits (keys->regmap, pmic_rst_reg, +PWRKEY_RST_EN_MASK <<PWRKEY_RST_EN_SHIFT , +0 ); +regmap_update_bits (keys->regmap, pmic_rst_reg, +HOMEKEY_RST_EN_MASK <<HOMEKEY_RST_EN_SHIFT , +0 ); +break ; +default : +break ; + } +} + +static irqreturn_t mtk_pmic_keys_irq_handler_thread (int irq,void *data) +{ +struct pmic_keys_info *info = data; +u32 key_deb, pressed; + +regmap_read (info->keys->regmap, info->regs->deb_reg, &key_deb); + + key_deb &= info->regs->deb_mask; + + pressed = !key_deb; + +input_report_key (info->keys->input_dev, info->keycode, pressed); +input_sync (info->keys->input_dev); + +dev_dbg (info->keys->dev,"[PMICKEYS] (%s) key =%d using PMIC\n" , + pressed ?"pressed" :"released" , info->keycode); + +return IRQ_HANDLED ; +} + +static int mtk_pmic_key_setup (struct mtk_pmic_keys *keys, +const char *propname,struct pmic_keys_info *info,bool wakeup) +{ +int ret; + + ret =of_property_read_u32 (keys->dev->of_node, + propname, &info->keycode); +if (ret) +return 0 ; + +if (!info->keycode) +return 0 ; + + info->keys = keys; + + ret =regmap_update_bits (keys->regmap, info->regs->intsel_reg, + info->regs->intsel_mask, + info->regs->intsel_mask); +if (ret <0 ) +return ret; + + ret =devm_request_threaded_irq (keys->dev, info->irq,NULL , + mtk_pmic_keys_irq_handler_thread, +IRQF_ONESHOT |IRQF_TRIGGER_HIGH , +"mtk-pmic-keys" , info); +if (ret) { +dev_err (keys->dev,"Failed to request IRQ: %d: %d\n" , + info->irq, ret); +return ret; + } + +if (wakeup) +irq_set_irq_wake (info->irq,1 ); + +input_set_capability (keys->input_dev,EV_KEY , info->keycode); + +return 0 ; +} + +static void mtk_pmic_keys_dispose_irq (struct mtk_pmic_keys *keys)
Quoted 8 lines
drivers/input/keyboard/mtk-pmic-keys.c line 211
Quoted 6 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +6
-0+{ +if (keys->pwrkey.irq) +irq_dispose_mapping (keys->pwrkey.irq); + +if (keys->homekey.irq) +irq_dispose_mapping (keys->homekey.irq);You did not create the mapping, you should not destroy it.
OK.
Quoted 54 lines
Quoted 24 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +23
-0+} + +static const struct of_device_id of_pmic_keys_match_tbl[] = { + { + .compatible ="mediatek,mt6397-keys" , + .data = &mt6397_regs, + }, { + .compatible ="mediatek,mt6323-keys" , + .data = &mt6323_regs, + }, { +/* sentinel */ + } +}; +MODULE_DEVICE_TABLE (of, of_pmic_keys_match_tbl); + +static int mtk_pmic_keys_probe (struct platform_device *pdev) +{ +int ret; +struct resource *res_pwrkey, *res_homekey; +struct mt6397_chip *pmic_chip =dev_get_drvdata (pdev->dev.parent); +struct mtk_pmic_keys *keys; +const struct pmic_regs *pmic_regs; +struct input_dev *input_dev;drivers/input/keyboard/mtk-pmic-keys.c line 244
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+const struct of_device_id *of_id = +of_match_device (of_pmic_keys_match_tbl, &pdev->dev); + + keys =devm_kzalloc (&pdev->dev,sizeof (*keys),GFP_KERNEL ); +if (!keys) +return -ENOMEM ; + + keys->dev = &pdev->dev; + keys->regmap = pmic_chip->regmap; + keys->irq_domain = pmic_chip->irq_domain;Not needed.
Quoted 4 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +4
-0+ + pmic_regs = of_id->data; + keys->pwrkey.regs = &pmic_regs->pwrkey_regs; + keys->homekey.regs = &pmic_regs->homekey_regs;drivers/input/keyboard/mtk-pmic-keys.c line 258
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+ + res_pwrkey =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); +if (!res_pwrkey) { +dev_err (&pdev->dev,"no IRQ resource\n" ); +return -ENODEV ; + } + + keys->pwrkey.irq = res_pwrkey->start; +if (keys->pwrkey.irq <=0 ) +return -EINVAL ;Please do
Quoted 4 lines
keys->pwrkey.irq = platform_get_irq(pdev, 0); if (keys->pwrkey.irq < 0) return keys->pwrkey.irq;
OK, I'll do this way.Thank you.
Quoted 37 lines
drivers/input/keyboard/mtk-pmic-keys.c line 268
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+ + res_homekey =platform_get_resource (pdev,IORESOURCE_IRQ ,1 ); +if (!res_homekey) { +dev_err (&pdev->dev,"no IRQ resource\n" ); +return -ENODEV ; + } + + keys->homekey.irq = res_homekey->start; +if (keys->homekey.irq <=0 ) +return -EINVAL ;Same as above.
drivers/input/keyboard/mtk-pmic-keys.c line 281
Quoted 13 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +13
-0+ + keys->input_dev = input_dev =devm_input_allocate_device (keys->dev); +if (!input_dev) { +dev_err (&pdev->dev,"[PMICKEYS] input allocate device fail.\n" ); +return -ENOMEM ; + } + + input_dev->name ="mtk-pmic-keys" ; + input_dev->id.bustype =BUS_HOST ; + input_dev->id.vendor =0x0001 ; + input_dev->id.product =0x0001 ; + input_dev->id.version =0x0001 ; + input_dev->dev.parent = &pdev->dev;Not needed,
devm_input_allocate_device()already does this.drivers/input/keyboard/mtk-pmic-keys.c line 286
Quoted 5 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +5
-0+ + ret =mtk_pmic_key_setup (keys,"mediatek,pwrkey-code" , + &keys->pwrkey, true); +if (ret) + goto out_dispose_irq;Can you please call this variable "error" and do
Quoted 3 lines
if (error) return error;
OK, I'll change that naming.
Quoted 60 lines
You are using devm and no longer creating mappings, so you can return directly and rely on devm infrastructure to unwind.
drivers/input/keyboard/mtk-pmic-keys.c line 296
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+ + ret =mtk_pmic_key_setup (keys,"mediatek,homekey-code" , + &keys->homekey, false); +if (ret) + goto out_dispose_irq; + + ret =input_register_device (input_dev); +if (ret) { +dev_err (&pdev->dev, +"[PMICKEYS] register input device failed (%d)\n" , ret);No need for [PMICKEYS] prefix,
dev_errprints device and driver already.Quoted 7 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +7
-0+return ret; + } + +long_press_reset_setup (keys, pmic_regs->pmic_rst_reg); + +return 0 ; +drivers/input/keyboard/mtk-pmic-keys.c line 313
Quoted 10 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +10
-0+out_dispose_irq: +mtk_pmic_keys_dispose_irq (keys); +return ret; +} + +static int mtk_pmic_keys_remove (struct platform_device *pdev) +{ +struct mtk_pmic_keys *keys =platform_get_drvdata (pdev); + +mtk_pmic_keys_dispose_irq (keys);Not needed. The whole function is not needed.
Quoted 21 lines
drivers/input/keyboard/mtk-pmic-keys.c new file +18
-0+ +return 0 ; +} + +static struct platform_driver pmic_keys_pdrv = { + .probe = mtk_pmic_keys_probe, + .remove = mtk_pmic_keys_remove, + .driver = { + .name ="mtk-pmic-keys" , + .of_match_table = of_pmic_keys_match_tbl, + }, +}; + +module_platform_driver (pmic_keys_pdrv); + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("Chen Zhong <[email protected]>" ); +MODULE_DESCRIPTION ("MTK pmic-keys driver v0.1" );Signature · 1 line
1.7.9.5Thanks.
PATCH v2 5/5 mfd: mt6397: Add PMIC keys support to MT6397 driver
In reply to Chen ZhongThis patch adds compatible strings and interrupts for pmic keys which serves as child device of MFD.
--- drivers/mfd/mt6397-core.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)
drivers/mfd/mt6397-core.c +35 -1
@@ -43,6 +43,30 @@ }, }; +static const struct resource mt6323_keys_resources[] = { + { + .start =MT6323_IRQ_STATUS_PWRKEY , + .end =MT6323_IRQ_STATUS_PWRKEY , + .flags =IORESOURCE_IRQ , + }, { + .start =MT6323_IRQ_STATUS_FCHRKEY , + .end =MT6323_IRQ_STATUS_FCHRKEY , + .flags =IORESOURCE_IRQ , + }, +}; + +static const struct resource mt6397_keys_resources[] = { + { + .start =MT6397_IRQ_PWRKEY , + .end =MT6397_IRQ_PWRKEY , + .flags =IORESOURCE_IRQ , + }, { + .start =MT6397_IRQ_HOMEKEY , + .end =MT6397_IRQ_HOMEKEY , + .flags =IORESOURCE_IRQ , + }, +}; +static const struct mfd_cell mt6323_devs[] = { { .name ="mt6323-regulator" ,
@@ -50,6 +74,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 +100,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
Re: [PATCH v2 5/5] mfd: mt6397: Add PMIC keys support to MT6397 driver
Quoted 29 lines · Chen Zhong
This patch adds compatible strings and interrupts for pmic keys which serves as child device of MFD.
Signed-off-by Chen Zhong <[email protected]>--- drivers/mfd/mt6397-core.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)drivers/mfd/mt6397-core.c +13
-0@@ -43,6 +43,30 @@ }, }; +static const struct resource mt6323_keys_resources[] = { + { + .start =MT6323_IRQ_STATUS_PWRKEY , + .end =MT6323_IRQ_STATUS_PWRKEY , + .flags =IORESOURCE_IRQ , + }, { + .start =MT6323_IRQ_STATUS_FCHRKEY , + .end =MT6323_IRQ_STATUS_FCHRKEY , + .flags =IORESOURCE_IRQ , + }, +}; + +static const struct resource mt6397_keys_resources[] = {
drivers/mfd/mt6397-core.c line 68
Quoted 10 lines
drivers/mfd/mt6397-core.c +10
-0+ { + .start = MT6397_IRQ_PWRKEY, + .end = MT6397_IRQ_PWRKEY, + .flags = IORESOURCE_IRQ, + }, { + .start = MT6397_IRQ_HOMEKEY, + .end = MT6397_IRQ_HOMEKEY, + .flags = IORESOURCE_IRQ, + }, +};
We have better ways to define these now.
Please grep for "DEFINE_RES_"
Quoted 29 lines
drivers/mfd/mt6397-core.c +11
-1static const struct mfd_cell mt6323_devs[] = { { .name ="mt6323-regulator" ,@@ -50,6 +74,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 +100,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 · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v2 5/5] mfd: mt6397: Add PMIC keys support to MT6397 driver
Quoted 44 lines · Lee Jones
Quoted 29 lines · Chen Zhong
This patch adds compatible strings and interrupts for pmic keys which serves as child device of MFD.
Signed-off-by Chen Zhong <[email protected]>--- drivers/mfd/mt6397-core.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)drivers/mfd/mt6397-core.c +13
-0@@ -43,6 +43,30 @@ }, }; +static const struct resource mt6323_keys_resources[] = { + { + .start =MT6323_IRQ_STATUS_PWRKEY , + .end =MT6323_IRQ_STATUS_PWRKEY , + .flags =IORESOURCE_IRQ , + }, { + .start =MT6323_IRQ_STATUS_FCHRKEY , + .end =MT6323_IRQ_STATUS_FCHRKEY , + .flags =IORESOURCE_IRQ , + }, +}; + +static const struct resource mt6397_keys_resources[] = {drivers/mfd/mt6397-core.c line 68
Quoted 10 lines
drivers/mfd/mt6397-core.c +10
-0+ { + .start = MT6397_IRQ_PWRKEY, + .end = MT6397_IRQ_PWRKEY, + .flags = IORESOURCE_IRQ, + }, { + .start = MT6397_IRQ_HOMEKEY, + .end = MT6397_IRQ_HOMEKEY, + .flags = IORESOURCE_IRQ, + }, +};We have better ways to define these now.
Quoted 1 line
Please grep for "
DEFINE_RES_"
I'll define these with "DEFINE_RES_IRQ" here, Thank you for your suggestion.
Quoted 31 lines
Quoted 30 lines
drivers/mfd/mt6397-core.c +11
-1static const struct mfd_cell mt6323_devs[] = { { .name ="mt6323-regulator" ,@@ -50,6 +74,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 +100,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)