diff mbox series

[v2,1/3] Input: mtk-pmic-keys - Transfer per-key bit in mtk_pmic_keys_regs

Message ID 20220524093505.85438-2-angelogioacchino.delregno@collabora.com (mailing list archive)
State Accepted
Commit b581acb49aec5c3b0af9ab1c537fb73481b79069
Headers show
Series MediaTek Helio X10 MT6795 - MT6331 PMIC Keys | expand

Commit Message

AngeloGioacchino Del Regno May 24, 2022, 9:35 a.m. UTC
Place the key bit in struct mtk_pmic_keys_regs to enhance this
driver's flexibility, in preparation for adding support for more
PMICs.

While at it, remove the definition of MTK_PMIC_RST_KEY_MASK as
we are now dynamically setting the keymask relatively to the keys
that are defined in the newly added rst_en_mask variable, on a
per-key basis.

This commit brings no functional changes.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/input/keyboard/mtk-pmic-keys.c | 30 ++++++++++++++++----------
 1 file changed, 19 insertions(+), 11 deletions(-)

Comments

Mattijs Korpershoek May 24, 2022, 12:05 p.m. UTC | #1
On mar., mai 24, 2022 at 11:35, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> wrote:

> Place the key bit in struct mtk_pmic_keys_regs to enhance this
> driver's flexibility, in preparation for adding support for more
> PMICs.
>
> While at it, remove the definition of MTK_PMIC_RST_KEY_MASK as
> we are now dynamically setting the keymask relatively to the keys
> that are defined in the newly added rst_en_mask variable, on a
> per-key basis.
>
> This commit brings no functional changes.
>
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

> ---
>  drivers/input/keyboard/mtk-pmic-keys.c | 30 ++++++++++++++++----------
>  1 file changed, 19 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
> index d2f0db245ff6..2509a349a173 100644
> --- a/drivers/input/keyboard/mtk-pmic-keys.c
> +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> @@ -20,7 +20,6 @@
>  
>  #define MTK_PMIC_RST_DU_MASK	GENMASK(9, 8)
>  #define MTK_PMIC_RST_DU_SHIFT	8
> -#define MTK_PMIC_RST_KEY_MASK	GENMASK(6, 5)
>  #define MTK_PMIC_PWRKEY_RST	BIT(6)
>  #define MTK_PMIC_HOMEKEY_RST	BIT(5)
>  
> @@ -33,15 +32,17 @@ struct mtk_pmic_keys_regs {
>  	u32 deb_mask;
>  	u32 intsel_reg;
>  	u32 intsel_mask;
> +	u32 rst_en_mask;
>  };
>  
>  #define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask,		\
> -	_intsel_reg, _intsel_mask)			\
> +	_intsel_reg, _intsel_mask, _rst_mask)		\
>  {							\
>  	.deb_reg		= _deb_reg,		\
>  	.deb_mask		= _deb_mask,		\
>  	.intsel_reg		= _intsel_reg,		\
>  	.intsel_mask		= _intsel_mask,		\
> +	.rst_en_mask		= _rst_mask,		\
>  }
>  
>  struct mtk_pmic_regs {
> @@ -52,30 +53,32 @@ struct mtk_pmic_regs {
>  static const struct mtk_pmic_regs mt6397_regs = {
>  	.keys_regs[MTK_PMIC_PWRKEY_INDEX] =
>  		MTK_PMIC_KEYS_REGS(MT6397_CHRSTATUS,
> -		0x8, MT6397_INT_RSV, 0x10),
> +		0x8, MT6397_INT_RSV, 0x10, MTK_PMIC_PWRKEY_RST),
>  	.keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
>  		MTK_PMIC_KEYS_REGS(MT6397_OCSTATUS2,
> -		0x10, MT6397_INT_RSV, 0x8),
> +		0x10, MT6397_INT_RSV, 0x8, MTK_PMIC_HOMEKEY_RST),
>  	.pmic_rst_reg = MT6397_TOP_RST_MISC,
>  };
>  
>  static const struct mtk_pmic_regs mt6323_regs = {
>  	.keys_regs[MTK_PMIC_PWRKEY_INDEX] =
>  		MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
> -		0x2, MT6323_INT_MISC_CON, 0x10),
> +		0x2, MT6323_INT_MISC_CON, 0x10, MTK_PMIC_PWRKEY_RST),
>  	.keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
>  		MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
> -		0x4, MT6323_INT_MISC_CON, 0x8),
> +		0x4, MT6323_INT_MISC_CON, 0x8, MTK_PMIC_HOMEKEY_RST),
>  	.pmic_rst_reg = MT6323_TOP_RST_MISC,
>  };
>  
>  static const struct mtk_pmic_regs mt6358_regs = {
>  	.keys_regs[MTK_PMIC_PWRKEY_INDEX] =
>  		MTK_PMIC_KEYS_REGS(MT6358_TOPSTATUS,
> -				   0x2, MT6358_PSC_TOP_INT_CON0, 0x5),
> +				   0x2, MT6358_PSC_TOP_INT_CON0, 0x5,
> +				   MTK_PMIC_PWRKEY_RST),
>  	.keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
>  		MTK_PMIC_KEYS_REGS(MT6358_TOPSTATUS,
> -				   0x8, MT6358_PSC_TOP_INT_CON0, 0xa),
> +				   0x8, MT6358_PSC_TOP_INT_CON0, 0xa,
> +				   MTK_PMIC_HOMEKEY_RST),
>  	.pmic_rst_reg = MT6358_TOP_RST_MISC,
>  };
>  
> @@ -104,10 +107,14 @@ enum mtk_pmic_keys_lp_mode {
>  static void mtk_pmic_keys_lp_reset_setup(struct mtk_pmic_keys *keys,
>  					 u32 pmic_rst_reg)
>  {
> +	const struct mtk_pmic_keys_regs *kregs_home, *kregs_pwr;
>  	u32 long_press_mode, long_press_debounce;
>  	u32 value, mask;
>  	int error;
>  
> +	kregs_home = keys->keys[MTK_PMIC_HOMEKEY_INDEX].regs;
> +	kregs_pwr = keys->keys[MTK_PMIC_PWRKEY_INDEX].regs;
> +
>  	error = of_property_read_u32(keys->dev->of_node, "power-off-time-sec",
>  				     &long_press_debounce);
>  	if (error)
> @@ -124,15 +131,16 @@ static void mtk_pmic_keys_lp_reset_setup(struct mtk_pmic_keys *keys,
>  
>  	switch (long_press_mode) {
>  	case LP_TWOKEY:
> -		value |= MTK_PMIC_HOMEKEY_RST;
> +		value |= kregs_home->rst_en_mask;
>  		fallthrough;
>  
>  	case LP_ONEKEY:
> -		value |= MTK_PMIC_PWRKEY_RST;
> +		value |= kregs_pwr->rst_en_mask;
>  		fallthrough;
>  
>  	case LP_DISABLE:
> -		mask |= MTK_PMIC_RST_KEY_MASK;
> +		mask |= kregs_home->rst_en_mask;
> +		mask |= kregs_pwr->rst_en_mask;
>  		break;
>  
>  	default:
> -- 
> 2.35.1
Dmitry Torokhov May 27, 2022, 5:34 a.m. UTC | #2
On Tue, May 24, 2022 at 11:35:03AM +0200, AngeloGioacchino Del Regno wrote:
> Place the key bit in struct mtk_pmic_keys_regs to enhance this
> driver's flexibility, in preparation for adding support for more
> PMICs.
> 
> While at it, remove the definition of MTK_PMIC_RST_KEY_MASK as
> we are now dynamically setting the keymask relatively to the keys
> that are defined in the newly added rst_en_mask variable, on a
> per-key basis.
> 
> This commit brings no functional changes.

AngeloGioacchino,

Could you please tell me if these devices (currently supported by the
driver) have 2 fully independent reset settings for HOME and PWR keys,
or is there are actually 2 separate bits, one to enable/disable key
reset, and another controlling what keys will cause the reset - only PWR
or either PWR or HOME?

Thanks.
AngeloGioacchino Del Regno May 30, 2022, 9 a.m. UTC | #3
Il 27/05/22 07:34, Dmitry Torokhov ha scritto:
> On Tue, May 24, 2022 at 11:35:03AM +0200, AngeloGioacchino Del Regno wrote:
>> Place the key bit in struct mtk_pmic_keys_regs to enhance this
>> driver's flexibility, in preparation for adding support for more
>> PMICs.
>>
>> While at it, remove the definition of MTK_PMIC_RST_KEY_MASK as
>> we are now dynamically setting the keymask relatively to the keys
>> that are defined in the newly added rst_en_mask variable, on a
>> per-key basis.
>>
>> This commit brings no functional changes.
> 
> AngeloGioacchino,
> 
> Could you please tell me if these devices (currently supported by the
> driver) have 2 fully independent reset settings for HOME and PWR keys,
> or is there are actually 2 separate bits, one to enable/disable key
> reset, and another controlling what keys will cause the reset - only PWR
> or either PWR or HOME?
> 
> Thanks.
> 


Hello Dmitry,

there are two separate bits for the "Long Press Reset", you can achieve
reset with either holding the power button, volume up button (register
name is HOMEKEY because on very old devices this was a "home" button),
or both - for a certain amount of time.
If both {HOME,PWR}KEY_RST_EN bits are *not set*, the long press reset
PMIC trigger will be disabled.
Long-press time is controlled with the RST_DU register.

Regards,
Angelo
diff mbox series

Patch

diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
index d2f0db245ff6..2509a349a173 100644
--- a/drivers/input/keyboard/mtk-pmic-keys.c
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -20,7 +20,6 @@ 
 
 #define MTK_PMIC_RST_DU_MASK	GENMASK(9, 8)
 #define MTK_PMIC_RST_DU_SHIFT	8
-#define MTK_PMIC_RST_KEY_MASK	GENMASK(6, 5)
 #define MTK_PMIC_PWRKEY_RST	BIT(6)
 #define MTK_PMIC_HOMEKEY_RST	BIT(5)
 
@@ -33,15 +32,17 @@  struct mtk_pmic_keys_regs {
 	u32 deb_mask;
 	u32 intsel_reg;
 	u32 intsel_mask;
+	u32 rst_en_mask;
 };
 
 #define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask,		\
-	_intsel_reg, _intsel_mask)			\
+	_intsel_reg, _intsel_mask, _rst_mask)		\
 {							\
 	.deb_reg		= _deb_reg,		\
 	.deb_mask		= _deb_mask,		\
 	.intsel_reg		= _intsel_reg,		\
 	.intsel_mask		= _intsel_mask,		\
+	.rst_en_mask		= _rst_mask,		\
 }
 
 struct mtk_pmic_regs {
@@ -52,30 +53,32 @@  struct mtk_pmic_regs {
 static const struct mtk_pmic_regs mt6397_regs = {
 	.keys_regs[MTK_PMIC_PWRKEY_INDEX] =
 		MTK_PMIC_KEYS_REGS(MT6397_CHRSTATUS,
-		0x8, MT6397_INT_RSV, 0x10),
+		0x8, MT6397_INT_RSV, 0x10, MTK_PMIC_PWRKEY_RST),
 	.keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
 		MTK_PMIC_KEYS_REGS(MT6397_OCSTATUS2,
-		0x10, MT6397_INT_RSV, 0x8),
+		0x10, MT6397_INT_RSV, 0x8, MTK_PMIC_HOMEKEY_RST),
 	.pmic_rst_reg = MT6397_TOP_RST_MISC,
 };
 
 static const struct mtk_pmic_regs mt6323_regs = {
 	.keys_regs[MTK_PMIC_PWRKEY_INDEX] =
 		MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
-		0x2, MT6323_INT_MISC_CON, 0x10),
+		0x2, MT6323_INT_MISC_CON, 0x10, MTK_PMIC_PWRKEY_RST),
 	.keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
 		MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
-		0x4, MT6323_INT_MISC_CON, 0x8),
+		0x4, MT6323_INT_MISC_CON, 0x8, MTK_PMIC_HOMEKEY_RST),
 	.pmic_rst_reg = MT6323_TOP_RST_MISC,
 };
 
 static const struct mtk_pmic_regs mt6358_regs = {
 	.keys_regs[MTK_PMIC_PWRKEY_INDEX] =
 		MTK_PMIC_KEYS_REGS(MT6358_TOPSTATUS,
-				   0x2, MT6358_PSC_TOP_INT_CON0, 0x5),
+				   0x2, MT6358_PSC_TOP_INT_CON0, 0x5,
+				   MTK_PMIC_PWRKEY_RST),
 	.keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
 		MTK_PMIC_KEYS_REGS(MT6358_TOPSTATUS,
-				   0x8, MT6358_PSC_TOP_INT_CON0, 0xa),
+				   0x8, MT6358_PSC_TOP_INT_CON0, 0xa,
+				   MTK_PMIC_HOMEKEY_RST),
 	.pmic_rst_reg = MT6358_TOP_RST_MISC,
 };
 
@@ -104,10 +107,14 @@  enum mtk_pmic_keys_lp_mode {
 static void mtk_pmic_keys_lp_reset_setup(struct mtk_pmic_keys *keys,
 					 u32 pmic_rst_reg)
 {
+	const struct mtk_pmic_keys_regs *kregs_home, *kregs_pwr;
 	u32 long_press_mode, long_press_debounce;
 	u32 value, mask;
 	int error;
 
+	kregs_home = keys->keys[MTK_PMIC_HOMEKEY_INDEX].regs;
+	kregs_pwr = keys->keys[MTK_PMIC_PWRKEY_INDEX].regs;
+
 	error = of_property_read_u32(keys->dev->of_node, "power-off-time-sec",
 				     &long_press_debounce);
 	if (error)
@@ -124,15 +131,16 @@  static void mtk_pmic_keys_lp_reset_setup(struct mtk_pmic_keys *keys,
 
 	switch (long_press_mode) {
 	case LP_TWOKEY:
-		value |= MTK_PMIC_HOMEKEY_RST;
+		value |= kregs_home->rst_en_mask;
 		fallthrough;
 
 	case LP_ONEKEY:
-		value |= MTK_PMIC_PWRKEY_RST;
+		value |= kregs_pwr->rst_en_mask;
 		fallthrough;
 
 	case LP_DISABLE:
-		mask |= MTK_PMIC_RST_KEY_MASK;
+		mask |= kregs_home->rst_en_mask;
+		mask |= kregs_pwr->rst_en_mask;
 		break;
 
 	default: