ARM: dts: imx7s: add snvs clock to pwrkey
Subsystems (5)
PATCH 1/3 ARM: dts: imx7s: add snvs clock to pwrkey
On i.MX7, the SNVS requires a clock. This is similar to the clock bound to the SNVS RTC node, but if the SNVS RTC driver isn't enabled, then SNVS doesn't work, and as such the pwrkey driver doesn't work (i.e. hangs the kernel, as the clock isn't enabled).
Also see commit ec2a844ef7c1
("ARM: dts: imx7s: add snvs rtc clock")
for a similar fix.
--- .../devicetree/bindings/crypto/fsl-sec4.txt | 17 +++++++++++++++++ arch/arm/boot/dts/imx7s.dtsi | 2 ++ 2 files changed, 19 insertions(+)
Documentation/devicetree/bindings/crypto/fsl-sec4.txt +17 -0
@@ -449,6 +449,19 @@ System ON/OFF key driver Value type: <phandle> Definition: this is phandle to the register map node. + - clocks + Usage: optional, required if SNVS LP requires explicit + enablement of clocks + Value type: <prop_encoded-array> + Definition: a clock specifier describing the clock required for + enabling and disabling SNVS LP RTC. + + - clock-names + Usage: optional, required if SNVS LP requires explicit + enablement of clocks + Value type: <string> + Definition: clock name string should be "snvs-pwrkey". + EXAMPLE: snvs-pwrkey@020cc000 { compatible = "fsl,sec-v4.0-pwrkey";
@@ -456,6 +469,8 @@ EXAMPLE: interrupts = <0 4 0x4> linux,keycode = <116>; /* KEY_POWER */ wakeup-source; + clocks = <&clks IMX7D_SNVS_CLK>; + clock-names = "snvs-pwrkey"; }; =====================================================================
@@ -547,6 +562,8 @@ FULL EXAMPLE interrupts = <0 4 0x4>; linux,keycode = <116>; /* KEY_POWER */ wakeup-source; + clocks = <&clks IMX7D_SNVS_CLK>; + clock-names = "snvs-pwrkey"; }; };
arch/arm/boot/dts/imx7s.dtsi +2 -0
@@ -614,6 +614,8 @@ linux,keycode = <KEY_POWER>; wakeup-source; status = "disabled"; + clocks = <&clks IMX7D_SNVS_CLK>; + clock-names = "snvs-pwrkey"; }; };
Signature · 1 line
2.23.0.rc1
PATCH 2/3 Input: snvs_pwrkey - enable snvs clock as needed
At the moment, enabling this driver without the SNVS RTC driver being active will hang the kernel as soon as the power button is pressed.
The reason is that in that case the SNVS isn't enabled, and any attempt to read the SNVS registers will simply hang forever.
Ensure the clock is enabled (during the interrupt handler) to make this driver work.
Also see commit 7f8993995410 ("drivers/rtc/rtc-snvs: add clock support") and commit edb190cb1734
("rtc: snvs: make sure clock is enabled for interrupt handle") for similar updates to the snvs rtc driver.
--- drivers/input/keyboard/snvs_pwrkey.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/input/keyboard/snvs_pwrkey.c +27 -0
@@ -16,6 +16,7 @@#include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/pm_wakeirq.h> +#include <linux/clk.h> #include <linux/mfd/syscon.h> #include <linux/regmap.h>
@@ -38,6 +39,7 @@ struct pwrkey_drv_data {int wakeup;struct timer_list check_timer;struct input_dev *input; +struct clk *clk;u8 minor_rev; };
@@ -72,6 +74,9 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id)struct input_dev *input = pdata->input;u32 lp_status; +if (pdata->clk) +clk_enable (pdata->clk); +pm_wakeup_event (input->dev.parent,0 );regmap_read (pdata->snvs,SNVS_LPSR_REG , &lp_status);
@@ -96,6 +101,9 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id)/* clear SPO status */ regmap_write (pdata->snvs,SNVS_LPSR_REG ,SNVS_LPSR_SPO ); +if (pdata->clk) +clk_disable (pdata->clk); +return IRQ_HANDLED ; }
@@ -140,6 +148,25 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev)if (pdata->irq <0 )return -EINVAL ; + pdata->clk =devm_clk_get (&pdev->dev,"snvs-pwrkey" ); +if (IS_ERR (pdata->clk)) { + pdata->clk =NULL ; + }else { + error =clk_prepare_enable (pdata->clk); +if (error) { +dev_err (&pdev->dev, +"Could not prepare or enable the snvs clock\n" ); +return error; + } + error =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + pdata->clk); +if (error) { +dev_err (&pdev->dev,"failed to add reset action on 'snvs-pwrkey'" ); +return error; + } + } +regmap_read (pdata->snvs,SNVS_HPVIDR1_REG , &vid); pdata->minor_rev = vid &0xff ;
Signature · 1 line
2.23.0.rc1
Re: [PATCH 2/3] Input: snvs_pwrkey - enable snvs clock as needed
Quoted 52 lines · André Draszik
At the moment, enabling this driver without the SNVS RTC driver being active will hang the kernel as soon as the power button is pressed.
The reason is that in that case the SNVS isn't enabled, and any attempt to read the SNVS registers will simply hang forever.
Ensure the clock is enabled (during the interrupt handler) to make this driver work.
Also see commit
7f8993995410("drivers/rtc/rtc-snvs: add clock support") and commitedb190cb1734
("rtc: snvs: make sure clock is enabled for interrupt handle") for similar updates to the snvs rtc driver.Signed-off-by André Draszik <[email protected]>Cc Anson Huang <[email protected]>Cc Dmitry Torokhov <[email protected]>Cc "Horia Geantă" <[email protected]>Cc Aymen Sghaier <[email protected]>Cc Herbert Xu <[email protected]>Cc "David S. Miller" <[email protected]>Cc Rob Herring <[email protected]>Cc Mark Rutland <[email protected]>--- drivers/input/keyboard/snvs_pwrkey.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)drivers/input/keyboard/snvs_pwrkey.c +2
-0@@ -16,6 +16,7 @@#include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/pm_wakeirq.h> +#include <linux/clk.h> #include <linux/mfd/syscon.h> #include <linux/regmap.h> @@ -38,6 +39,7 @@ struct pwrkey_drv_data {int wakeup;struct timer_list check_timer;struct input_dev *input; +struct clk *clk;u8 minor_rev; };
drivers/input/keyboard/snvs_pwrkey.c static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id) · line 79
Quoted 6 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-0@@ -72,6 +74,9 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id)struct input_dev *input = pdata->input;u32 lp_status; +if (pdata->clk) +clk_enable (pdata->clk); +
clk framework handles NULL pointers internally, the check is redundant.
Quoted 14 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-0pm_wakeup_event (input->dev.parent,0 );regmap_read (pdata->snvs,SNVS_LPSR_REG , &lp_status);@@ -96,6 +101,9 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id)/* clear SPO status */ regmap_write (pdata->snvs,SNVS_LPSR_REG ,SNVS_LPSR_SPO ); +if (pdata->clk) +clk_disable (pdata->clk); +return IRQ_HANDLED ; }
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 153
Quoted 6 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-0@@ -140,6 +148,25 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev)if (pdata->irq <0 )return -EINVAL ; + pdata->clk =devm_clk_get (&pdev->dev,"snvs-pwrkey" ); +if (IS_ERR (pdata->clk)) { + pdata->clk =NULL ;
Using devm_clk_get_optional() would simplify error handling.
Quoted 20 lines
drivers/input/keyboard/snvs_pwrkey.c +16
-0+ }else { + error =clk_prepare_enable (pdata->clk); +if (error) { +dev_err (&pdev->dev, +"Could not prepare or enable the snvs clock\n" ); +return error; + } + error =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + pdata->clk); +if (error) { +dev_err (&pdev->dev,"failed to add reset action on 'snvs-pwrkey'" ); +return error; + } + } +regmap_read (pdata->snvs,SNVS_HPVIDR1_REG , &vid); pdata->minor_rev = vid &0xff ;
Dmitry Torokhov
maintainerRe: [PATCH 2/3] Input: snvs_pwrkey - enable snvs clock as needed
Quoted 74 lines · Horia Geanta
Quoted 52 lines · André Draszik
At the moment, enabling this driver without the SNVS RTC driver being active will hang the kernel as soon as the power button is pressed.
The reason is that in that case the SNVS isn't enabled, and any attempt to read the SNVS registers will simply hang forever.
Ensure the clock is enabled (during the interrupt handler) to make this driver work.
Also see commit
7f8993995410("drivers/rtc/rtc-snvs: add clock support") and commitedb190cb1734
("rtc: snvs: make sure clock is enabled for interrupt handle") for similar updates to the snvs rtc driver.Signed-off-by André Draszik <[email protected]>Cc Anson Huang <[email protected]>Cc Dmitry Torokhov <[email protected]>Cc "Horia Geantă" <[email protected]>Cc Aymen Sghaier <[email protected]>Cc Herbert Xu <[email protected]>Cc "David S. Miller" <[email protected]>Cc Rob Herring <[email protected]>Cc Mark Rutland <[email protected]>--- drivers/input/keyboard/snvs_pwrkey.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)drivers/input/keyboard/snvs_pwrkey.c +2
-0@@ -16,6 +16,7 @@#include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/pm_wakeirq.h> +#include <linux/clk.h> #include <linux/mfd/syscon.h> #include <linux/regmap.h> @@ -38,6 +39,7 @@ struct pwrkey_drv_data {int wakeup;struct timer_list check_timer;struct input_dev *input; +struct clk *clk;u8 minor_rev; };drivers/input/keyboard/snvs_pwrkey.c static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id) · line 79
Quoted 6 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-0@@ -72,6 +74,9 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id)struct input_dev *input = pdata->input;u32 lp_status; +if (pdata->clk) +clk_enable (pdata->clk); +clk framework handles NULL pointers internally, the check is redundant.
Quoted 13 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-0pm_wakeup_event (input->dev.parent,0 );regmap_read (pdata->snvs,SNVS_LPSR_REG , &lp_status);@@ -96,6 +101,9 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id)/* clear SPO status */ regmap_write (pdata->snvs,SNVS_LPSR_REG ,SNVS_LPSR_SPO ); +if (pdata->clk) +clk_disable (pdata->clk); +return IRQ_HANDLED ; }
Quoted 8 lines
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 153
Quoted 7 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-0@@ -140,6 +148,25 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev)if (pdata->irq <0 )return -EINVAL ; + pdata->clk =devm_clk_get (&pdev->dev,"snvs-pwrkey" ); +if (IS_ERR (pdata->clk)) { + pdata->clk =NULL ;Using
devm_clk_get_optional()would simplify error handling.
It sounds to me that this clock is not at all optional and the driver currently "works" only by accident and therefore optional is not suitable here.
Quoted 3 lines
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 155
Quoted 3 lines
drivers/input/keyboard/snvs_pwrkey.c +2
-0+ }else { + error =clk_prepare_enable (pdata->clk);
So if you enable clock here and do not disable it, why do you need to enable it again in interrupt?
Thanks.
Signature · 1 line
Dmitry
RE: [PATCH 2/3] Input: snvs_pwrkey - enable snvs clock as needed
Quoted 11 lines · On 2020/02/10 Dmitry Torokhov <[email protected]> wrote:
Quoted 10 lines · Horia Geanta
Quoted 9 lines · André Draszik
At the moment, enabling this driver without the SNVS RTC driver being active will hang the kernel as soon as the power button is pressed.
The reason is that in that case the SNVS isn't enabled, and any attempt to read the SNVS registers will simply hang forever.
Ensure the clock is enabled (during the interrupt handler) to make this driver work.
Besides, need to add clock enabled in imx_imx_snvs_check_for_events where snvs register touched.
Quoted 73 lines
Quoted 44 lines
Quoted 44 lines
Also see commit
7f8993995410("drivers/rtc/rtc-snvs: add clock support") and commitedb190cb1734
("rtc: snvs: make sure clock is enabled for interrupt handle") for similar updates to the snvs rtc driver.Signed-off-by André Draszik <[email protected]>Cc Anson Huang <[email protected]>Cc Dmitry Torokhov <[email protected]>Cc "Horia Geantă" <[email protected]>Cc Aymen Sghaier <[email protected]>Cc Herbert Xu <[email protected]>Cc "David S. Miller" <[email protected]>Cc Rob Herring <[email protected]>Cc Mark Rutland <[email protected]>--- drivers/input/keyboard/snvs_pwrkey.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)drivers/input/keyboard/snvs_pwrkey.c +2
-0@@ -16,6 +16,7 @@#include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/pm_wakeirq.h> +#include <linux/clk.h> #include <linux/mfd/syscon.h> #include <linux/regmap.h> @@ -38,6 +39,7 @@ struct pwrkey_drv_data {int wakeup;struct timer_list check_timer;struct input_dev *input; +struct clk *clk;u8 minor_rev; };Quoted 1 line
drivers/input/keyboard/snvs_pwrkey.c static irqreturn_t imx_snvs_pwrkey_interrupt(int irq,
Quoted 1 line
drivers/input/keyboard/snvs_pwrkey.c +0
-0@@ -72,6 +74,9 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq,void
*dev_id)Quoted 12 lines
drivers/input/keyboard/snvs_pwrkey.c static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id) · line 79
Quoted 6 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-0struct input_dev *input = pdata->input;u32 lp_status; +if (pdata->clk) +clk_enable (pdata->clk); +clk framework handles NULL pointers internally, the check is redundant.
Quoted 4 lines
drivers/input/keyboard/snvs_pwrkey.c +1
-0pm_wakeup_event (input->dev.parent,0 ); regmap_read(pdata->snvs, SNVS_LPSR_REG, &lp_status); @@ -96,6 +101,9 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void
*dev_id)Quoted 10 lines
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct
Quoted 10 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-0/* clear SPO status */ regmap_write (pdata->snvs,SNVS_LPSR_REG ,SNVS_LPSR_SPO ); +if (pdata->clk) +clk_disable (pdata->clk); +return IRQ_HANDLED ; }@@ -140,6 +148,25 @@ static int imx_snvs_pwrkey_probe(struct
platform_device*pdev)Quoted 3 lines
Quoted 3 lines
drivers/input/keyboard/snvs_pwrkey.c +0
-0if (pdata->irq <0 )return -EINVAL ;
Quoted 7 lines
Quoted 4 lines
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 153
Quoted 3 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-0+ pdata->clk =devm_clk_get (&pdev->dev,"snvs-pwrkey" ); +if (IS_ERR (pdata->clk)) { + pdata->clk =NULL ;Using
devm_clk_get_optional()would simplify error handling.It sounds to me that this clock is not at all optional and the driver currently "works" only by accident and therefore optional is not suitable here.
Yes, then we need to add all snvs clk in dts for on legacy i.MX chips in this patchset to avoid any potential function broken.
Quoted 12 lines
Quoted 4 lines
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 155
Quoted 4 lines
drivers/input/keyboard/snvs_pwrkey.c +2
-0+ }else { + error =clk_prepare_enable (pdata->clk);So if you enable clock here and do not disable it, why do you need to enable it again in interrupt?
Thanks.
--
Dmitry
Re: [PATCH 2/3] Input: snvs_pwrkey - enable snvs clock as needed
Quoted 13 lines · Robin Gong
Quoted 12 lines · On 2020/02/10 Dmitry Torokhov <[email protected]> wrote:
Quoted 2 lines · Horia Geanta
Review static int imx_snvs_pwrkey_probe(struct
Quoted 1 line · André Draszik
(quoted diff) +0
-0@@ -140,6 +148,25 @@ static int imx_snvs_pwrkey_probe(struct
platform_device*pdev)Quoted 7 lines
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 153
Quoted 6 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-0if (pdata->irq <0 )return -EINVAL ; + pdata->clk =devm_clk_get (&pdev->dev,"snvs-pwrkey" ); +if (IS_ERR (pdata->clk)) { + pdata->clk =NULL ;Using
devm_clk_get_optional()would simplify error handling.
Quoted 4 lines
Quoted 2 lines
It sounds to me that this clock is not at all optional and the driver currently "works" only by accident and therefore optional is not suitable here.
Yes, then we need to add all snvs clk in dts for on legacy i.MX chips in this patchset to avoid any potential function broken.
In that case the DT binding should be updated too, to make the clock mandatory.
But before doing this all i.MX SoCs should be checked.
Thanks,
Horia
Dmitry Torokhov
maintainerRe: [PATCH 2/3] Input: snvs_pwrkey - enable snvs clock as needed
Quoted 14 lines · Horia Geanta
Quoted 13 lines · Robin Gong
Quoted 12 lines · On 2020/02/10 Dmitry Torokhov <[email protected]> wrote:
Quoted 2 lines · Horia Geanta
Review static int imx_snvs_pwrkey_probe(struct
Quoted 1 line · André Draszik
(quoted diff) +0
-0@@ -140,6 +148,25 @@ static int imx_snvs_pwrkey_probe(struct
platform_device*pdev)Quoted 7 lines
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 153
Quoted 6 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-0if (pdata->irq <0 )return -EINVAL ; + pdata->clk =devm_clk_get (&pdev->dev,"snvs-pwrkey" ); +if (IS_ERR (pdata->clk)) { + pdata->clk =NULL ;Using
devm_clk_get_optional()would simplify error handling.
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
It sounds to me that this clock is not at all optional and the driver currently "works" only by accident and therefore optional is not suitable here.
Yes, then we need to add all snvs clk in dts for on legacy i.MX chips in this patchset to avoid any potential function broken.
How many are there? I am not too terribly opposed of having the driver handle missing clk if there are very many legacy DTSes out there. But then we need to handle it properly (i.e. current iteration does not handle referral properly for example).
Quoted 2 lines
In that case the DT binding should be updated too, to make the clock mandatory.
I think this should be done in either case, as as far I understand the part can not function without the clock and it worked purely by chance on some systems as something else was turning the clock on.
Thanks.
Signature · 1 line
Dmitry
RE: [PATCH 2/3] Input: snvs_pwrkey - enable snvs clock as needed
Quoted 17 lines · On 2020/02/11 Dmitry Torokhov <[email protected]> wrote:
Quoted 9 lines · Horia Geanta
Quoted 8 lines · Robin Gong
Quoted 7 lines · On 2020/02/10 Dmitry Torokhov <[email protected]> wrote:
Quoted 2 lines · Horia Geanta
Review static int imx_snvs_pwrkey_probe(struct
Quoted 1 line · André Draszik
(quoted diff) +0
-0@@ -140,6 +148,25 @@ static int imx_snvs_pwrkey_probe(struct
platform_device*pdev)Quoted 3 lines
Quoted 3 lines
drivers/input/keyboard/snvs_pwrkey.c +0
-0if (pdata->irq <0 )return -EINVAL ;Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 153
Quoted 3 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-0+ pdata->clk =devm_clk_get (&pdev->dev,"snvs-pwrkey" ); +if (IS_ERR (pdata->clk)) { + pdata->clk =NULL ;Using
devm_clk_get_optional()would simplify error handling.It sounds to me that this clock is not at all optional and the driver currently "works" only by accident and therefore optional is not
Quoted 8 lines
suitable here.
Quoted 2 lines
Quoted 2 lines
Yes, then we need to add all snvs clk in dts for on legacy i.MX chips in this patchset to avoid any potential function broken.
How many are there? I am not too terribly opposed of having the driver handle missing clk if there are very many legacy DTSes out there. But then we need to handle it properly (i.e. current iteration does not handle referral properly for example).
There are four dtsi which have clock support in snvs-rtc including i.mx7s/i.mx8mq/8mm/8mn. So for this patch set, it's better update i.mx8mX dtsi except i.mx7s.
Quoted 7 lines
Quoted 3 lines
In that case the DT binding should be updated too, to make the clock mandatory.
I think this should be done in either case, as as far I understand the part can not function without the clock and it worked purely by chance on some systems as something else was turning the clock on.
Yes, for all chips snvs clk management added, snvs clock also has to been add in snvs_pwrkey dts, but for others legacy chips like i.mx6X which have no snvs clk management, snvs clock is always on, so no need such clk in snvs_pwrkey dts either, optional is better.
Quoted 5 lines
Thanks.
--
Dmitry
Re: [PATCH 2/3] Input: snvs_pwrkey - enable snvs clock as needed
Hi,
Quoted 32 lines · Robin Gong
Quoted 17 lines · On 2020/02/11 Dmitry Torokhov <[email protected]> wrote:
Quoted 9 lines · Horia Geanta
Quoted 8 lines · Robin Gong
Quoted 7 lines · On 2020/02/10 Dmitry Torokhov <[email protected]> wrote:
Quoted 2 lines · Horia Geanta
Review static int imx_snvs_pwrkey_probe(struct
Quoted 1 line · André Draszik
(quoted diff) +0
-0@@ -140,6 +148,25 @@ static int imx_snvs_pwrkey_probe(struct
platform_device*pdev)Quoted 3 lines
Quoted 3 lines
(quoted diff) +0
-0if (pdata->irq < 0) return -EINVAL;Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Review static int imx_snvs_pwrkey_probe(struct · line 153
Quoted 3 lines
(quoted diff) +3
-0+ pdata->clk = devm_clk_get(&pdev->dev, "snvs-pwrkey"); + if (IS_ERR(pdata->clk)) { + pdata->clk = NULL;Using
devm_clk_get_optional()would simplify error handling.It sounds to me that this clock is not at all optional and the driver currently "works" only by accident and therefore optional is not
Quoted 8 lines
suitable here.
Quoted 2 lines
Quoted 2 lines
Yes, then we need to add all snvs clk in dts for on legacy i.MX chips in this patchset to avoid any potential function broken.
How many are there? I am not too terribly opposed of having the driver handle missing clk if there are very many legacy DTSes out there. But then we need to handle it properly (i.e. current iteration does not handle referral properly for example).
There are four dtsi which have clock support in snvs-rtc including i.mx7s/i.mx8mq/8mm/8mn. So for this patch set, it's better update
i.mx8mX dtsi except i.mx7s.Quoted 3 lines
Quoted 2 lines
In that case the DT binding should be updated too, to make the clock mandatory.
Quoted 8 lines
Quoted 3 lines
I think this should be done in either case, as as far I understand the part can not function without the clock and it worked purely by chance on some systems as something else was turning the clock on.
Yes, for all chips snvs clk management added, snvs clock also has to been add in
snvs_pwrkeydts, but for others legacy chips like i.mx6X which have no snvs clk management, snvs clock is always on, so no need such clk insnvs_pwrkeydts either, optional is better.Quoted 1 line
Thanks.
It seems to me though that the clock should really be moved into the (parent) SNVS node itself, rather than duplicating
the clock in the the power key node and in
the RTC node. Is that possible? (I don't know)...
To summarise, I'll post an updated patchset within the next couple days so to:
* keep the clock optional (for i.MX6 platforms)
* convert to devm_clk_get_optional()
* only enable the clock in interrupt handler and imx_imx_snvs_check_for_events() but not during driver loading
* update all four DTSIs: imx8mm.dtsi imx8mn.dtsi imx8mq.dtsi imx7s.dtsi Note that I'll only be able to test onn the i.MX7
Cheers,
Andre'
RE: [PATCH 2/3] Input: snvs_pwrkey - enable snvs clock as needed
Quoted 44 lines · On 2020/02/11 André Draszik <[email protected]> wrote:
Hi,
Quoted 41 lines · Robin Gong
Quoted 19 lines · On 2020/02/11 Dmitry Torokhov <[email protected]> wrote:
Quoted 10 lines · Horia Geanta
Quoted 9 lines · Robin Gong
Quoted 8 lines · On 2020/02/10 Dmitry Torokhov <[email protected]> wrote:
Quoted 3 lines · Horia Geanta
Quoted 2 lines · André Draszik
(quoted diff) +0
-0@@ -140,6 +148,25 @@ static intimx_snvs_pwrkey_probe(struct
platform_device*pdev)Quoted 3 lines
Quoted 3 lines
(quoted diff) +0
-0if (pdata->irq < 0) return -EINVAL;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ pdata->clk = devm_clk_get(&pdev->dev, "snvs-pwrkey"); + if (IS_ERR(pdata->clk)) { + pdata->clk = NULL;Using
devm_clk_get_optional()would simplify error handling.It sounds to me that this clock is not at all optional and the driver currently "works" only by accident and therefore optional is not
Quoted 8 lines
suitable here.
Quoted 2 lines
Quoted 2 lines
Yes, then we need to add all snvs clk in dts for on legacy i.MX chips in this patchset to avoid any potential function broken.
How many are there? I am not too terribly opposed of having the driver handle missing clk if there are very many legacy DTSes out there. But then we need to handle it properly (i.e. current iteration does not handle referral properly for example).
There are four dtsi which have clock support in snvs-rtc including i.mx7s/i.mx8mq/8mm/8mn. So for this patch set, it's better update i.mx8mX dtsi except i.mx7s.
Quoted 6 lines
Quoted 2 lines
In that case the DT binding should be updated too, to make the clock mandatory.
I think this should be done in either case, as as far I understand the part can not function without the clock and it worked purely by chance on some systems as something else was turning the clock on.
Yes, for all chips snvs clk management added, snvs clock also has to been add in
snvs_pwrkeydts, but for others legacy chips like i.mx6X which have no snvs clk management, snvs clock is always on, so no need such clk insnvs_pwrkeydts either, optional is better.
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Thanks.
It seems to me though that the clock should really be moved into the (parent) SNVS node itself, rather than duplicating the clock in the the power key node and in the RTC node. Is that possible? (I don't know)...
That's possible but much code changes need to be added into snvs-rtc/snvs_pwrkey driver. Independent patch is better.
Quoted 10 lines
To summarise, I'll post an updated patchset within the next couple days so to:
* keep the clock optional (for i.MX6 platforms)
* convert todevm_clk_get_optional()
* only enable the clock in interrupt handler andimx_imx_snvs_check_for_events()
but not during driver loading
* update all four DTSIs:imx8mm.dtsiimx8mn.dtsiimx8mq.dtsiimx7s.dtsiNote that I'll only be able to test onn the i.MX7
Correct.
Quoted 5 lines
Cheers,
Andre'
PATCH 3/3 Input: snvs_pwrkey - only IRQ_HANDLED for our own events
In reply to André DraszikThe snvs_pwrkey shares the SNVS LPSR status register with the snvs_rtc.
This driver here should only return IRQ_HANDLED if the status register indicates that the event we're handling in the irq handler was genuinely intended for this driver. Otheriwse the interrupt subsystem will assume the interrupt was handled successfully even though it wasn't at all.
--- drivers/input/keyboard/snvs_pwrkey.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/input/keyboard/snvs_pwrkey.c +6 -5
@@ -80,7 +80,9 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id)pm_wakeup_event (input->dev.parent,0 );regmap_read (pdata->snvs,SNVS_LPSR_REG , &lp_status); -if (lp_status &SNVS_LPSR_SPO ) { + lp_status &=SNVS_LPSR_SPO ; + +if (lp_status) {if (pdata->minor_rev ==0 ) {/* * The first generation i.MX6 SoCs only sends an
@@ -96,15 +98,14 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id)mod_timer (&pdata->check_timer, jiffies +msecs_to_jiffies (DEBOUNCE_TIME )); } - } -/* clear SPO status */ -regmap_write (pdata->snvs,SNVS_LPSR_REG ,SNVS_LPSR_SPO ); +regmap_write (pdata->snvs,SNVS_LPSR_REG ,SNVS_LPSR_SPO ); + }if (pdata->clk)clk_disable (pdata->clk); -return IRQ_HANDLED ; +return lp_status ?IRQ_HANDLED :IRQ_NONE ; }static void imx_snvs_pwrkey_act (void *pdata)
Signature · 1 line
2.23.0.rc1
Quoted 21 lines · On Thu, 30 Jan 2020 20:45:14 +0000, =?UTF-8?q?Andr=C3=A9=20Draszik?= wrote:
On i.MX7, the SNVS requires a clock. This is similar to the clock bound to the SNVS RTC node, but if the SNVS RTC driver isn't enabled, then SNVS doesn't work, and as such the pwrkey driver doesn't work (i.e. hangs the kernel, as the clock isn't enabled).
Also see commit
ec2a844ef7c1
("ARM: dts: imx7s: add snvs rtc clock")
for a similar fix.Signed-off-by André Draszik <[email protected]>Cc Anson Huang <[email protected]>Cc Dmitry Torokhov <[email protected]>Cc "Horia Geantă" <[email protected]>Cc Aymen Sghaier <[email protected]>Cc Herbert Xu <[email protected]>Cc "David S. Miller" <[email protected]>Cc Rob Herring <[email protected]>Cc Mark Rutland <[email protected]>
Quoted 5 lines
--- .../devicetree/bindings/crypto/fsl-sec4.txt | 17 +++++++++++++++++ arch/arm/boot/dts/imx7s.dtsi | 2 ++ 2 files changed, 19 insertions(+)
Quoted 5 lines · André Draszik
On i.MX7, the SNVS requires a clock. This is similar to the clock bound to the SNVS RTC node, but if the SNVS RTC driver isn't enabled, then SNVS doesn't work, and as such the pwrkey driver doesn't work (i.e. hangs the kernel, as the clock isn't enabled).
This is true also for i.MX8M.
For this reason it would probably better splitting the DT bindings update in a separate patch.
Quoted 4 lines
Also see commit
ec2a844ef7c1
("ARM: dts: imx7s: add snvs rtc clock")
for a similar fix.
Quoted 12 lines
Signed-off-by André Draszik <[email protected]>Cc Anson Huang <[email protected]>Cc Dmitry Torokhov <[email protected]>Cc "Horia Geantă" <[email protected]>Cc Aymen Sghaier <[email protected]>Cc Herbert Xu <[email protected]>Cc "David S. Miller" <[email protected]>Cc Rob Herring <[email protected]>Cc Mark Rutland <[email protected]>
Quoted 61 lines
--- .../devicetree/bindings/crypto/fsl-sec4.txt | 17 +++++++++++++++++ arch/arm/boot/dts/imx7s.dtsi | 2 ++ 2 files changed, 19 insertions(+)Documentation/devicetree/bindings/crypto/fsl-sec4.txt +17
-0@@ -449,6 +449,19 @@ System ON/OFF key driver Value type: <phandle> Definition: this is phandle to the register map node. + - clocks + Usage: optional, required if SNVS LP requires explicit + enablement of clocks + Value type: <prop_encoded-array> + Definition: a clock specifier describing the clock required for + enabling and disabling SNVS LP RTC. + + - clock-names + Usage: optional, required if SNVS LP requires explicit + enablement of clocks + Value type: <string> + Definition: clock name string should be "snvs-pwrkey". + EXAMPLE: snvs-pwrkey@020cc000 { compatible = "fsl,sec-v4.0-pwrkey";@@ -456,6 +469,8 @@ EXAMPLE: interrupts = <0 4 0x4> linux,keycode = <116>; /* KEY_POWER */ wakeup-source; + clocks = <&clks IMX7D_SNVS_CLK>; + clock-names = "snvs-pwrkey"; }; =====================================================================@@ -547,6 +562,8 @@ FULL EXAMPLE interrupts = <0 4 0x4>; linux,keycode = <116>; /* KEY_POWER */ wakeup-source; + clocks = <&clks IMX7D_SNVS_CLK>; + clock-names = "snvs-pwrkey"; }; };arch/arm/boot/dts/imx7s.dtsi +2
-0@@ -614,6 +614,8 @@ linux,keycode = <KEY_POWER>; wakeup-source; status = "disabled"; + clocks = <&clks IMX7D_SNVS_CLK>; + clock-names = "snvs-pwrkey"; }; };