The MediaTek MT6358 PMIC has support for two buttons: PWR and HOME.
The interrupt logic is a little different than other PMICs from the
same family:
* for MT6323 and MT6397, we have one interrupt source per button
* for MT6358, we have two interrupts lines per button: the press and
* release interrupts are distinct sources.
These series:
* Fix a NULL ptr error when we use mtk-pmic-keys without dts code
* Rework the mt6397 driver to prepare for this different interrupt logic
* Add support for the MT6358 power buttons
This has been functionally tested (using evtest) on
the mt8183-pumpkin board on linux/master
It has also been used for a couple of months in a downstream
tree based on v5.4.
Mattijs Korpershoek (7):
Input: mtk-pmic-keys - check for NULL on of_match_device()
mfd: mt6397: add mt6358 register definitions for power key
mfd: mt6397: keys: use named IRQs instead of index
dt-bindings: input: mtk-pmic-keys: add MT6358 binding definition
Input: mtk-pmic-keys - add support for MT6358
mfd: mt6397: Add PMIC keys for MT6358
arm64: dts: mt6358: add mt6358-keys node
.../bindings/input/mtk-pmic-keys.txt | 5 +-
arch/arm64/boot/dts/mediatek/mt6358.dtsi | 12 ++++
drivers/input/keyboard/mtk-pmic-keys.c | 59 +++++++++++++++++--
drivers/mfd/mt6397-core.c | 20 +++++--
include/linux/mfd/mt6358/registers.h | 2 +
5 files changed, 89 insertions(+), 9 deletions(-)
base-commit: 4a0225c3d208cfa6e4550f2210ffd9114a952a81
--
2.27.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
mtk-pmic-keys being a child device of mt6397, it will always get probed
when mt6397_probe() is called.
This also happens when we have no device tree node matching
mediatek,mt6397-keys.
In that case, the mfd core warns us:
[ 0.352175] mtk-pmic-keys: Failed to locate of_node [id: -1]
Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.
In case of NULL print error message and return -ENODEV
Signed-off-by: Mattijs Korpershoek <redacted>
---
drivers/input/keyboard/mtk-pmic-keys.c | 3 +++
1 file changed, 3 insertions(+)
For some compatible pmics (such as MT6358), there are two IRQs per
physical key: one for press event, another for release event.
Currently, the mtk-pmic-keys driver assumes that each key only has one
IRQ. The key index and the RES_IRQ resource index have a 1/1 mapping.
This won't work for MT6358, as we have multiple resources (2) for one key.
To prepare mtk-pmic-keys to support MT6358, retrieve IRQs by name
instead of by index.
Note: The keys_resources are not part of the device-tree bindings so
this won't break any DT schemas.
Signed-off-by: Mattijs Korpershoek <redacted>
---
drivers/input/keyboard/mtk-pmic-keys.c | 7 +++++--
drivers/mfd/mt6397-core.c | 8 ++++----
2 files changed, 9 insertions(+), 6 deletions(-)
@@ -241,6 +241,7 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)unsignedintkeycount;structmt6397_chip*pmic_chip=dev_get_drvdata(pdev->dev.parent);structdevice_node*node=pdev->dev.of_node,*child;+staticconstchar*constirqnames[]={"powerkey","homekey"};structmtk_pmic_keys*keys;conststructmtk_pmic_regs*mtk_pmic_regs;structinput_dev*input_dev;
@@ -271,7 +272,8 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)input_dev->id.version=0x0001;keycount=of_get_available_child_count(node);-if(keycount>MTK_PMIC_MAX_KEY_COUNT){+if(keycount>MTK_PMIC_MAX_KEY_COUNT||+keycount>ARRAY_SIZE(irqnames)){dev_err(keys->dev,"too many keys defined (%d)\n",keycount);return-EINVAL;}
@@ -279,7 +281,8 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)for_each_child_of_node(node,child){keys->keys[index].regs=&mtk_pmic_regs->keys_regs[index];-keys->keys[index].irq=platform_get_irq(pdev,index);+keys->keys[index].irq=+platform_get_irq_byname(pdev,irqnames[index]);if(keys->keys[index].irq<0){of_node_put(child);returnkeys->keys[index].irq;
Add the binding documentation of the mtk-pmic-keys for the MT6358 PMICs.
MT6358 is a little different since it used separate IRQs for the
release key (_r) event
Signed-off-by: Mattijs Korpershoek <redacted>
---
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
In order to support power/home key detection, add definitions for
two more MT6358 PMIC registers:
- TOPSTATUS: homekey and powerkey debounce status
- TOP_RST_MISC: controls homekey,powerkey long press reset time
Signed-off-by: Mattijs Korpershoek <redacted>
---
include/linux/mfd/mt6358/registers.h | 2 ++
1 file changed, 2 insertions(+)
This patch adds compatible strings and interrupts for pmic keys
which serves as child device of MFD.
MT6358 has two interrupts per key: one for press, another one for
release (_R)
Signed-off-by: Mattijs Korpershoek <redacted>
---
drivers/mfd/mt6397-core.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
MT6358 pmic keys behave differently than mt6397 and mt6323: there are
two interrupts per key: one for press, the other one for release (_r)
Signed-off-by: Mattijs Korpershoek <redacted>
---
drivers/input/keyboard/mtk-pmic-keys.c | 49 ++++++++++++++++++++++++--
1 file changed, 47 insertions(+), 2 deletions(-)
Hi Mattijs,
On Wed, Apr 28, 2021 at 06:42:13PM +0200, Mattijs Korpershoek wrote:
mtk-pmic-keys being a child device of mt6397, it will always get probed
when mt6397_probe() is called.
This also happens when we have no device tree node matching
mediatek,mt6397-keys.
It sounds for me that creating a platform device instance in case where
we know need OF node, but do not have one, is wasteful. Can
mt6397-core.c and/or MFD core be adjusted to not do that.
quoted hunk
In that case, the mfd core warns us:
[ 0.352175] mtk-pmic-keys: Failed to locate of_node [id: -1]
Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.
In case of NULL print error message and return -ENODEV
Signed-off-by: Mattijs Korpershoek <redacted>
---
drivers/input/keyboard/mtk-pmic-keys.c | 3 +++
1 file changed, 3 insertions(+)
@@ -247,6 +247,9 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)conststructof_device_id*of_id=of_match_device(of_mtk_pmic_keys_match_tbl,&pdev->dev);+if(!of_id)+return-ENODEV;+
So if we make MFD/6396 core smarter we would not be needing this. I
guess there is still a possibility of someone stuffing "mtk-pmic-keys"
into "driver_override" attribute of a random platform device but I
wonder if we really need to take care of such scenarios...
Hi Mattijs,
On Wed, Apr 28, 2021 at 06:42:13PM +0200, Mattijs Korpershoek wrote:
quoted
mtk-pmic-keys being a child device of mt6397, it will always get probed
when mt6397_probe() is called.
This also happens when we have no device tree node matching
mediatek,mt6397-keys.
It sounds for me that creating a platform device instance in case where
we know need OF node, but do not have one, is wasteful. Can
mt6397-core.c and/or MFD core be adjusted to not do that.
You are right. Maybe I can fix MFD core instead. I will look into it.
Thanks for your review.
quoted
In that case, the mfd core warns us:
[ 0.352175] mtk-pmic-keys: Failed to locate of_node [id: -1]
Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.
In case of NULL print error message and return -ENODEV
Signed-off-by: Mattijs Korpershoek <redacted>
---
drivers/input/keyboard/mtk-pmic-keys.c | 3 +++
1 file changed, 3 insertions(+)
@@ -247,6 +247,9 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)conststructof_device_id*of_id=of_match_device(of_mtk_pmic_keys_match_tbl,&pdev->dev);+if(!of_id)+return-ENODEV;+
So if we make MFD/6396 core smarter we would not be needing this. I
guess there is still a possibility of someone stuffing "mtk-pmic-keys"
into "driver_override" attribute of a random platform device but I
wonder if we really need to take care of such scenarios...
Hi Dmitry,
Mattijs Korpershoek [off-list ref] writes:
Hi Dmitry,
Dmitry Torokhov [off-list ref] writes:
quoted
Hi Mattijs,
On Wed, Apr 28, 2021 at 06:42:13PM +0200, Mattijs Korpershoek wrote:
quoted
mtk-pmic-keys being a child device of mt6397, it will always get probed
when mt6397_probe() is called.
This also happens when we have no device tree node matching
mediatek,mt6397-keys.
It sounds for me that creating a platform device instance in case where
we know need OF node, but do not have one, is wasteful. Can
mt6397-core.c and/or MFD core be adjusted to not do that.
You are right. Maybe I can fix MFD core instead. I will look into it.
Thanks for your review.
quoted
quoted
In that case, the mfd core warns us:
[ 0.352175] mtk-pmic-keys: Failed to locate of_node [id: -1]
Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.
In case of NULL print error message and return -ENODEV
Signed-off-by: Mattijs Korpershoek <redacted>
---
drivers/input/keyboard/mtk-pmic-keys.c | 3 +++
1 file changed, 3 insertions(+)
@@ -247,6 +247,9 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)conststructof_device_id*of_id=of_match_device(of_mtk_pmic_keys_match_tbl,&pdev->dev);+if(!of_id)+return-ENODEV;+
So if we make MFD/6396 core smarter we would not be needing this. I
guess there is still a possibility of someone stuffing "mtk-pmic-keys"
into "driver_override" attribute of a random platform device but I
wonder if we really need to take care of such scenarios...
Hi Matthias, Dmitry, Lee,
Mattijs Korpershoek [off-list ref] writes:
Please ignore this series for now
The MediaTek MT6358 PMIC has support for two buttons: PWR and HOME.
The interrupt logic is a little different than other PMICs from the
same family:
* for MT6323 and MT6397, we have one interrupt source per button
* for MT6358, we have two interrupts lines per button: the press and
* release interrupts are distinct sources.
These series:
* Fix a NULL ptr error when we use mtk-pmic-keys without dts code
* Rework the mt6397 driver to prepare for this different interrupt logic
* Add support for the MT6358 power buttons
This has been functionally tested (using evtest) on
the mt8183-pumpkin board on linux/master
It has also been used for a couple of months in a downstream
tree based on v5.4.
Mattijs Korpershoek (7):
Input: mtk-pmic-keys - check for NULL on of_match_device()
mfd: mt6397: add mt6358 register definitions for power key
mfd: mt6397: keys: use named IRQs instead of index
dt-bindings: input: mtk-pmic-keys: add MT6358 binding definition
Input: mtk-pmic-keys - add support for MT6358
From: Rob Herring <robh@kernel.org> Date: 2021-05-03 19:28:47
On Wed, 28 Apr 2021 18:42:16 +0200, Mattijs Korpershoek wrote:
Add the binding documentation of the mtk-pmic-keys for the MT6358 PMICs.
MT6358 is a little different since it used separate IRQs for the
release key (_r) event
Signed-off-by: Mattijs Korpershoek <redacted>
---
Documentation/devicetree/bindings/input/mtk-pmic-keys.txt | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)