Input: mt6779-keypad - fix hw code logic and row/col selection
Subsystems (4)
v3 cover Input: mt6779-keypad - fix hw code logic and row/col selection
Input: mt6779-keypad - fix hw code logic and row/col selection
This serie is the first follow-up on the mt6779-keypad in order to enable it on the MediaTek mt8183-pumpkin board.
To fully enable it on mt8183-pumpkin, we still need:
* double key support
* dts changes
To ease up reviewing, I preferred sending this first.
The first patch fixes a logic bug based on the (non-public) datasheet I have.
The second patch configures the keypad correctly in order to not report bogus values.
Thank you,
Mattijs
Changes in v3:
* reworked row/column logic as discussed in [1]
* Dropped Angelo's review since patch 1 changed
Changes in v2:
* Simplified SEL_COL/ROW_MASK macros as suggested by Dmitry
* Added Angelo's Reviewed-by on patch 1
Mattijs Korpershoek (2):
Input: mt6779-keypad - match hardware matrix organization
Input: mt6779-keypad - implement row/column selection
drivers/input/keyboard/mt6779-keypad.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
[1] https://lore.kernel.org/r/YpMDZORAlHmg/x/[email protected]
base-commit: c4bcc1b99b8b8acdfe673e4701a9c2acb6b8b2fb
Signature · 1 line
2.34.1
PATCH RESEND v3 1/2 Input: mt6779-keypad - match hardware matrix organization
The MediaTek keypad has a set of bits representing keys, from KEY0 to KEY77, arranged in 5 chunks of 15 bits split into 5 32-bit registers.
In our implementation, we simply decided to use register number as row and offset in the register as column when encoding our "matrix".
Because of this, we can have a 5x32 matrix which does not match the hardware at all, which is confusing.
Change the row/column calculation to match the hardware.
--- drivers/input/keyboard/mt6779-keypad.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/input/keyboard/mt6779-keypad.c +5 -3
@@ -42,7 +42,7 @@ static irqreturn_t mt6779_keypad_irq_handler(int irq, void *dev_id)const unsigned short *keycode = keypad->input_dev->keycode;DECLARE_BITMAP (new_state,MTK_KPD_NUM_BITS );DECLARE_BITMAP (change,MTK_KPD_NUM_BITS ); -unsigned int bit_nr; +unsigned int bit_nr, key;unsigned int row, col;unsigned int scancode;unsigned int row_shift =get_count_order (keypad->n_cols);
@@ -61,8 +61,10 @@ static irqreturn_t mt6779_keypad_irq_handler(int irq, void *dev_id)if (bit_nr %32 >=16 )continue ; - row = bit_nr /32 ; - col = bit_nr %32 ; + key = bit_nr /32 *16 + bit_nr %32 ; + row = key /9 ; + col = key %9 ; + scancode =MATRIX_SCAN_CODE (row, col, row_shift);/* 1: not pressed, 0: pressed */ pressed = !test_bit (bit_nr, new_state);
Signature · 1 line
2.34.1
PATCH RESEND v3 2/2 Input: mt6779-keypad - implement row/column selection
In reply to Mattijs KorpershoekThe MediaTek keypad has a total of 6 input rows and 6 input columns. By default, rows/columns 0-2 are enabled.
This is controlled by the KP_SEL register:
- bits[9:4] control row selection
- bits[15:10] control column selection
Each bit enables the corresponding row/column number (e.g KP_SEL[4] enables ROW0)
Depending on how the keypad is wired, this may result in wrong readings of the keypad state.
Program the KP_SEL register to limit the key detection to n_rows, n_cols we retrieve from the device tree.
--- drivers/input/keyboard/mt6779-keypad.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/input/keyboard/mt6779-keypad.c +10 -0
@@ -17,6 +17,11 @@#define MTK_KPD_DEBOUNCE 0x0018#define MTK_KPD_DEBOUNCE_MASK GENMASK(13, 0)#define MTK_KPD_DEBOUNCE_MAX_MS 256 +#define MTK_KPD_SEL 0x0020 +#define MTK_KPD_SEL_COL GENMASK(15, 10) +#define MTK_KPD_SEL_ROW GENMASK(9, 4) +#define MTK_KPD_SEL_COLMASK (c) GENMASK((c) + 9, 10) +#define MTK_KPD_SEL_ROWMASK (r) GENMASK((r) + 3, 4)#define MTK_KPD_NUM_MEMS 5#define MTK_KPD_NUM_BITS 136/* 4*32+8 MEM5 only use 8 BITS */
@@ -161,6 +166,11 @@ static int mt6779_keypad_pdrv_probe(struct platform_device *pdev)regmap_write (keypad->regmap,MTK_KPD_DEBOUNCE , (debounce * (1 <<5 )) &MTK_KPD_DEBOUNCE_MASK ); +regmap_update_bits (keypad->regmap,MTK_KPD_SEL ,MTK_KPD_SEL_ROW , +MTK_KPD_SEL_ROWMASK (keypad->n_rows)); +regmap_update_bits (keypad->regmap,MTK_KPD_SEL ,MTK_KPD_SEL_COL , +MTK_KPD_SEL_COLMASK (keypad->n_cols)); + keypad->clk =devm_clk_get (&pdev->dev,"kpd" );if (IS_ERR (keypad->clk))return PTR_ERR (keypad->clk);
Signature · 1 line
2.34.1
Quoted 31 lines · Mattijs Korpershoek
Input: mt6779-keypad - fix hw code logic and row/col selection
This serie is the first follow-up on the mt6779-keypad in order to enable it on the MediaTek mt8183-pumpkin board.
To fully enable it on mt8183-pumpkin, we still need:
* double key support
* dts changesTo ease up reviewing, I preferred sending this first.
The first patch fixes a logic bug based on the (non-public) datasheet I have.
The second patch configures the keypad correctly in order to not report bogus values.Thank you,
MattijsChanges in v3:
* reworked row/column logic as discussed in [1]
* Dropped Angelo's review since patch 1 changedChanges in v2:
* Simplified SEL_COL/ROW_MASK macros as suggested by Dmitry
* Added Angelo's Reviewed-by on patch 1Mattijs Korpershoek (2):
Input: mt6779-keypad - match hardware matrix organization
Input: mt6779-keypad - implement row/column selection
Quoted 9 lines
drivers/input/keyboard/mt6779-keypad.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)[1] https://lore.kernel.org/r/YpMDZORAlHmg/x/[email protected]
base-commit:
c4bcc1b99b8b8acdfe673e4701a9c2acb6b8b2fbSignature · 1 line
2.34.1
Applied the series, thank you.
Signature · 1 line
Dmitry