Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * twl4030_keypad.c - driver for 8x8 keypad controller in twl4030 chips
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2007 Texas Instruments, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2008 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Code re-written for 2430SDP by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Syed Mohammed Khasim <x0khasim@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Initial Code:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Manjunatha G K <manjugk@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/mfd/twl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * The TWL4030 family chips include a keypad controller that supports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * up to an 8x8 switch matrix.  The controller can issue system wakeup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * events, since it uses only the always-on 32KiHz oscillator, and has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * an internal state machine that decodes pressed keys, including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * multi-key combinations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * This driver lets boards define what keycodes they wish to report for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * which scancodes, as part of the "struct twl4030_keypad_data" used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * the probe() routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * See the TPS65950 documentation; that's the general availability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * version of the TWL5030 second generation part.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define TWL4030_MAX_ROWS	8	/* TWL4030 hard limit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define TWL4030_MAX_COLS	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * Note that we add space for an extra column so that we can handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * row lines connected to the gnd (see twl4030_col_xlate()).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define TWL4030_ROW_SHIFT	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define TWL4030_KEYMAP_SIZE	(TWL4030_MAX_ROWS << TWL4030_ROW_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) struct twl4030_keypad {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	unsigned short	keymap[TWL4030_KEYMAP_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	u16		kp_state[TWL4030_MAX_ROWS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	bool		autorepeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	unsigned int	n_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned int	n_cols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	int		irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct device *dbg_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) /*----------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) /* arbitrary prescaler value 0..7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define PTV_PRESCALER			4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /* Register Offsets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define KEYP_CTRL			0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define KEYP_DEB			0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define KEYP_LONG_KEY			0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define KEYP_LK_PTV			0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define KEYP_TIMEOUT_L			0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define KEYP_TIMEOUT_H			0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #define KEYP_KBC			0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define KEYP_KBR			0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define KEYP_SMS			0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #define KEYP_FULL_CODE_7_0		0x09	/* row 0 column status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define KEYP_FULL_CODE_15_8		0x0a	/* ... row 1 ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #define KEYP_FULL_CODE_23_16		0x0b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define KEYP_FULL_CODE_31_24		0x0c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define KEYP_FULL_CODE_39_32		0x0d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #define KEYP_FULL_CODE_47_40		0x0e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #define KEYP_FULL_CODE_55_48		0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #define KEYP_FULL_CODE_63_56		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #define KEYP_ISR1			0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) #define KEYP_IMR1			0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define KEYP_ISR2			0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #define KEYP_IMR2			0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #define KEYP_SIR			0x15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #define KEYP_EDR			0x16	/* edge triggers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #define KEYP_SIH_CTRL			0x17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) /* KEYP_CTRL_REG Fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #define KEYP_CTRL_SOFT_NRST		BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) #define KEYP_CTRL_SOFTMODEN		BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #define KEYP_CTRL_LK_EN			BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #define KEYP_CTRL_TOE_EN		BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #define KEYP_CTRL_TOLE_EN		BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #define KEYP_CTRL_RP_EN			BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) #define KEYP_CTRL_KBD_ON		BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) /* KEYP_DEB, KEYP_LONG_KEY, KEYP_TIMEOUT_x*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define KEYP_PERIOD_US(t, prescale)	((t) / (31 << ((prescale) + 1)) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* KEYP_LK_PTV_REG Fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define KEYP_LK_PTV_PTV_SHIFT		5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* KEYP_{IMR,ISR,SIR} Fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define KEYP_IMR1_MIS			BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define KEYP_IMR1_TO			BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define KEYP_IMR1_LK			BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define KEYP_IMR1_KP			BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* KEYP_EDR Fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define KEYP_EDR_KP_FALLING		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define KEYP_EDR_KP_RISING		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define KEYP_EDR_KP_BOTH		0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define KEYP_EDR_LK_FALLING		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define KEYP_EDR_LK_RISING		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define KEYP_EDR_TO_FALLING		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define KEYP_EDR_TO_RISING		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define KEYP_EDR_MIS_FALLING		0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define KEYP_EDR_MIS_RISING		0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /*----------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static int twl4030_kpread(struct twl4030_keypad *kp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		u8 *data, u32 reg, u8 num_bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	int ret = twl_i2c_read(TWL4030_MODULE_KEYPAD, data, reg, num_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		dev_warn(kp->dbg_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			"Couldn't read TWL4030: %X - ret %d[%x]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			 reg, ret, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int twl4030_kpwrite_u8(struct twl4030_keypad *kp, u8 data, u32 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int ret = twl_i2c_write_u8(TWL4030_MODULE_KEYPAD, data, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		dev_warn(kp->dbg_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			"Could not write TWL4030: %X - ret %d[%x]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			 reg, ret, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static inline u16 twl4030_col_xlate(struct twl4030_keypad *kp, u8 col)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 * If all bits in a row are active for all columns then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 * we have that row line connected to gnd. Mark this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	 * key on as if it was on matrix position n_cols (i.e.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	 * one higher than the size of the matrix).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (col == 0xFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return 1 << kp->n_cols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		return col & ((1 << kp->n_cols) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int twl4030_read_kp_matrix_state(struct twl4030_keypad *kp, u16 *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	u8 new_state[TWL4030_MAX_ROWS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int row;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	int ret = twl4030_kpread(kp, new_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				 KEYP_FULL_CODE_7_0, kp->n_rows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		for (row = 0; row < kp->n_rows; row++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			state[row] = twl4030_col_xlate(kp, new_state[row]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static bool twl4030_is_in_ghost_state(struct twl4030_keypad *kp, u16 *key_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	u16 check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	for (i = 0; i < kp->n_rows; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		u16 col = key_state[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		if ((col & check) && hweight16(col) > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		check |= col;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static void twl4030_kp_scan(struct twl4030_keypad *kp, bool release_all)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	struct input_dev *input = kp->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	u16 new_state[TWL4030_MAX_ROWS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	int col, row;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (release_all) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		memset(new_state, 0, sizeof(new_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		/* check for any changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		int ret = twl4030_read_kp_matrix_state(kp, new_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		if (ret < 0)	/* panic ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (twl4030_is_in_ghost_state(kp, new_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	/* check for changes and print those */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	for (row = 0; row < kp->n_rows; row++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		int changed = new_state[row] ^ kp->kp_state[row];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		if (!changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		/* Extra column handles "all gnd" rows */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		for (col = 0; col < kp->n_cols + 1; col++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			int code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			if (!(changed & (1 << col)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			dev_dbg(kp->dbg_dev, "key [%d:%d] %s\n", row, col,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 				(new_state[row] & (1 << col)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 				"press" : "release");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			code = MATRIX_SCAN_CODE(row, col, TWL4030_ROW_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			input_event(input, EV_MSC, MSC_SCAN, code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			input_report_key(input, kp->keymap[code],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 					 new_state[row] & (1 << col));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		kp->kp_state[row] = new_state[row];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  * Keypad interrupt handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static irqreturn_t do_kp_irq(int irq, void *_kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	struct twl4030_keypad *kp = _kp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	/* Read & Clear TWL4030 pending interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	ret = twl4030_kpread(kp, &reg, KEYP_ISR1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	 * Release all keys if I2C has gone bad or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	 * the KEYP has gone to idle state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (ret >= 0 && (reg & KEYP_IMR1_KP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		twl4030_kp_scan(kp, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		twl4030_kp_scan(kp, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static int twl4030_kp_program(struct twl4030_keypad *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	/* Enable controller, with hardware decoding but not autorepeat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	reg = KEYP_CTRL_SOFT_NRST | KEYP_CTRL_SOFTMODEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		| KEYP_CTRL_TOE_EN | KEYP_CTRL_KBD_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (twl4030_kpwrite_u8(kp, reg, KEYP_CTRL) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	 * NOTE: we could use sih_setup() here to package keypad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	 * event sources as four different IRQs ... but we don't.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	/* Enable TO rising and KP rising and falling edge detection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	reg = KEYP_EDR_KP_BOTH | KEYP_EDR_TO_RISING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (twl4030_kpwrite_u8(kp, reg, KEYP_EDR) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	/* Set PTV prescaler Field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	reg = (PTV_PRESCALER << KEYP_LK_PTV_PTV_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (twl4030_kpwrite_u8(kp, reg, KEYP_LK_PTV) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	/* Set key debounce time to 20 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	i = KEYP_PERIOD_US(20000, PTV_PRESCALER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (twl4030_kpwrite_u8(kp, i, KEYP_DEB) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	/* Set timeout period to 200 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	i = KEYP_PERIOD_US(200000, PTV_PRESCALER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (twl4030_kpwrite_u8(kp, (i & 0xFF), KEYP_TIMEOUT_L) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (twl4030_kpwrite_u8(kp, (i >> 8), KEYP_TIMEOUT_H) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	 * Enable Clear-on-Read; disable remembering events that fire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	 * after the IRQ but before our handler acks (reads) them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	reg = TWL4030_SIH_CTRL_COR_MASK | TWL4030_SIH_CTRL_PENDDIS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (twl4030_kpwrite_u8(kp, reg, KEYP_SIH_CTRL) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	/* initialize key state; irqs update it from here on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (twl4030_read_kp_matrix_state(kp, kp->kp_state) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * Registers keypad device with input subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * and configures TWL4030 keypad registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static int twl4030_kp_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	struct twl4030_keypad_data *pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	const struct matrix_keymap_data *keymap_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	struct twl4030_keypad *kp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	if (!kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	input = devm_input_allocate_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	/* get the debug device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	kp->dbg_dev		= &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	kp->input		= input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	/* setup input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	input->name		= "TWL4030 Keypad";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	input->phys		= "twl4030_keypad/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	input->id.bustype	= BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	input->id.vendor	= 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	input->id.product	= 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	input->id.version	= 0x0003;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	if (pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		if (!pdata->rows || !pdata->cols || !pdata->keymap_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			dev_err(&pdev->dev, "Missing platform_data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		kp->n_rows = pdata->rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		kp->n_cols = pdata->cols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		kp->autorepeat = pdata->rep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		keymap_data = pdata->keymap_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		error = matrix_keypad_parse_properties(&pdev->dev, &kp->n_rows,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 						       &kp->n_cols);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		kp->autorepeat = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	if (kp->n_rows > TWL4030_MAX_ROWS || kp->n_cols > TWL4030_MAX_COLS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 			"Invalid rows/cols amount specified in platform/devicetree data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	kp->irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (kp->irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		return kp->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	error = matrix_keypad_build_keymap(keymap_data, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 					   TWL4030_MAX_ROWS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 					   1 << TWL4030_ROW_SHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 					   kp->keymap, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		dev_err(kp->dbg_dev, "Failed to build keymap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	input_set_capability(input, EV_MSC, MSC_SCAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/* Enable auto repeat feature of Linux input subsystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (kp->autorepeat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		__set_bit(EV_REP, input->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	error = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		dev_err(kp->dbg_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 			"Unable to register twl4030 keypad device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	error = twl4030_kp_program(kp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	 * This ISR will always execute in kernel thread context because of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	 * the need to access the TWL4030 over the I2C bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	 * NOTE:  we assume this host is wired to TWL4040 INT1, not INT2 ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	error = devm_request_threaded_irq(&pdev->dev, kp->irq, NULL, do_kp_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 					  0, pdev->name, kp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		dev_info(kp->dbg_dev, "request_irq failed for irq no=%d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			kp->irq, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	/* Enable KP and TO interrupts now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	reg = (u8) ~(KEYP_IMR1_KP | KEYP_IMR1_TO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (twl4030_kpwrite_u8(kp, reg, KEYP_IMR1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		/* mask all events - we don't care about the result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		(void) twl4030_kpwrite_u8(kp, 0xff, KEYP_IMR1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static const struct of_device_id twl4030_keypad_dt_match_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	{ .compatible = "ti,twl4030-keypad" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) MODULE_DEVICE_TABLE(of, twl4030_keypad_dt_match_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  * NOTE: twl4030 are multi-function devices connected via I2C.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  * So this device is a child of an I2C parent, thus it needs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  * support unplug/replug (which most platform devices don't).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static struct platform_driver twl4030_kp_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	.probe		= twl4030_kp_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		.name	= "twl4030_keypad",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		.of_match_table = of_match_ptr(twl4030_keypad_dt_match_table),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) module_platform_driver(twl4030_kp_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) MODULE_AUTHOR("Texas Instruments");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) MODULE_DESCRIPTION("TWL4030 Keypad Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) MODULE_ALIAS("platform:twl4030_keypad");