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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Description:  keypad driver for ADP5589, ADP5585
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *		 I2C QWERTY Keypad and IO Expander
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Bugs: Enter bugs at http://blackfin.uclinux.org/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Copyright (C) 2010-2011 Analog Devices Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/input/adp5589.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) /* ADP5589/ADP5585 Common Registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #define ADP5589_5_ID			0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #define ADP5589_5_INT_STATUS		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #define ADP5589_5_STATUS		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #define ADP5589_5_FIFO_1		0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #define ADP5589_5_FIFO_2		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #define ADP5589_5_FIFO_3		0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #define ADP5589_5_FIFO_4		0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #define ADP5589_5_FIFO_5		0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #define ADP5589_5_FIFO_6		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #define ADP5589_5_FIFO_7		0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #define ADP5589_5_FIFO_8		0x0A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #define ADP5589_5_FIFO_9		0x0B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #define ADP5589_5_FIFO_10		0x0C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #define ADP5589_5_FIFO_11		0x0D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #define ADP5589_5_FIFO_12		0x0E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #define ADP5589_5_FIFO_13		0x0F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #define ADP5589_5_FIFO_14		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #define ADP5589_5_FIFO_15		0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #define ADP5589_5_FIFO_16		0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #define ADP5589_5_GPI_INT_STAT_A	0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #define ADP5589_5_GPI_INT_STAT_B	0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) /* ADP5589 Registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #define ADP5589_GPI_INT_STAT_C		0x15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #define ADP5589_GPI_STATUS_A		0x16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #define ADP5589_GPI_STATUS_B		0x17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #define ADP5589_GPI_STATUS_C		0x18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #define ADP5589_RPULL_CONFIG_A		0x19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #define ADP5589_RPULL_CONFIG_B		0x1A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define ADP5589_RPULL_CONFIG_C		0x1B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #define ADP5589_RPULL_CONFIG_D		0x1C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #define ADP5589_RPULL_CONFIG_E		0x1D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #define ADP5589_GPI_INT_LEVEL_A		0x1E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #define ADP5589_GPI_INT_LEVEL_B		0x1F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #define ADP5589_GPI_INT_LEVEL_C		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #define ADP5589_GPI_EVENT_EN_A		0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #define ADP5589_GPI_EVENT_EN_B		0x22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #define ADP5589_GPI_EVENT_EN_C		0x23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #define ADP5589_GPI_INTERRUPT_EN_A	0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #define ADP5589_GPI_INTERRUPT_EN_B	0x25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #define ADP5589_GPI_INTERRUPT_EN_C	0x26
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #define ADP5589_DEBOUNCE_DIS_A		0x27
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #define ADP5589_DEBOUNCE_DIS_B		0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #define ADP5589_DEBOUNCE_DIS_C		0x29
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #define ADP5589_GPO_DATA_OUT_A		0x2A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #define ADP5589_GPO_DATA_OUT_B		0x2B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #define ADP5589_GPO_DATA_OUT_C		0x2C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define ADP5589_GPO_OUT_MODE_A		0x2D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #define ADP5589_GPO_OUT_MODE_B		0x2E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) #define ADP5589_GPO_OUT_MODE_C		0x2F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #define ADP5589_GPIO_DIRECTION_A	0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) #define ADP5589_GPIO_DIRECTION_B	0x31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #define ADP5589_GPIO_DIRECTION_C	0x32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #define ADP5589_UNLOCK1			0x33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #define ADP5589_UNLOCK2			0x34
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) #define ADP5589_EXT_LOCK_EVENT		0x35
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #define ADP5589_UNLOCK_TIMERS		0x36
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #define ADP5589_LOCK_CFG		0x37
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) #define ADP5589_RESET1_EVENT_A		0x38
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #define ADP5589_RESET1_EVENT_B		0x39
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #define ADP5589_RESET1_EVENT_C		0x3A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #define ADP5589_RESET2_EVENT_A		0x3B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) #define ADP5589_RESET2_EVENT_B		0x3C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #define ADP5589_RESET_CFG		0x3D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) #define ADP5589_PWM_OFFT_LOW		0x3E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) #define ADP5589_PWM_OFFT_HIGH		0x3F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #define ADP5589_PWM_ONT_LOW		0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) #define ADP5589_PWM_ONT_HIGH		0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) #define ADP5589_PWM_CFG			0x42
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) #define ADP5589_CLOCK_DIV_CFG		0x43
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) #define ADP5589_LOGIC_1_CFG		0x44
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) #define ADP5589_LOGIC_2_CFG		0x45
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) #define ADP5589_LOGIC_FF_CFG		0x46
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) #define ADP5589_LOGIC_INT_EVENT_EN	0x47
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) #define ADP5589_POLL_PTIME_CFG		0x48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) #define ADP5589_PIN_CONFIG_A		0x49
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) #define ADP5589_PIN_CONFIG_B		0x4A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) #define ADP5589_PIN_CONFIG_C		0x4B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) #define ADP5589_PIN_CONFIG_D		0x4C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) #define ADP5589_GENERAL_CFG		0x4D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) #define ADP5589_INT_EN			0x4E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) /* ADP5585 Registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) #define ADP5585_GPI_STATUS_A		0x15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) #define ADP5585_GPI_STATUS_B		0x16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) #define ADP5585_RPULL_CONFIG_A		0x17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) #define ADP5585_RPULL_CONFIG_B		0x18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) #define ADP5585_RPULL_CONFIG_C		0x19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) #define ADP5585_RPULL_CONFIG_D		0x1A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) #define ADP5585_GPI_INT_LEVEL_A		0x1B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) #define ADP5585_GPI_INT_LEVEL_B		0x1C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) #define ADP5585_GPI_EVENT_EN_A		0x1D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) #define ADP5585_GPI_EVENT_EN_B		0x1E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) #define ADP5585_GPI_INTERRUPT_EN_A	0x1F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) #define ADP5585_GPI_INTERRUPT_EN_B	0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) #define ADP5585_DEBOUNCE_DIS_A		0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) #define ADP5585_DEBOUNCE_DIS_B		0x22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) #define ADP5585_GPO_DATA_OUT_A		0x23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) #define ADP5585_GPO_DATA_OUT_B		0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) #define ADP5585_GPO_OUT_MODE_A		0x25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) #define ADP5585_GPO_OUT_MODE_B		0x26
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) #define ADP5585_GPIO_DIRECTION_A	0x27
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) #define ADP5585_GPIO_DIRECTION_B	0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) #define ADP5585_RESET1_EVENT_A		0x29
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) #define ADP5585_RESET1_EVENT_B		0x2A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) #define ADP5585_RESET1_EVENT_C		0x2B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) #define ADP5585_RESET2_EVENT_A		0x2C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) #define ADP5585_RESET2_EVENT_B		0x2D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) #define ADP5585_RESET_CFG		0x2E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) #define ADP5585_PWM_OFFT_LOW		0x2F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) #define ADP5585_PWM_OFFT_HIGH		0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) #define ADP5585_PWM_ONT_LOW		0x31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) #define ADP5585_PWM_ONT_HIGH		0x32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) #define ADP5585_PWM_CFG			0x33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) #define ADP5585_LOGIC_CFG		0x34
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) #define ADP5585_LOGIC_FF_CFG		0x35
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) #define ADP5585_LOGIC_INT_EVENT_EN	0x36
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) #define ADP5585_POLL_PTIME_CFG		0x37
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) #define ADP5585_PIN_CONFIG_A		0x38
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) #define ADP5585_PIN_CONFIG_B		0x39
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) #define ADP5585_PIN_CONFIG_D		0x3A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) #define ADP5585_GENERAL_CFG		0x3B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) #define ADP5585_INT_EN			0x3C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) /* ID Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) #define ADP5589_5_DEVICE_ID_MASK	0xF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) #define ADP5589_5_MAN_ID_MASK		0xF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) #define ADP5589_5_MAN_ID_SHIFT		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) #define ADP5589_5_MAN_ID		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) /* GENERAL_CFG Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) #define OSC_EN		(1 << 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) #define CORE_CLK(x)	(((x) & 0x3) << 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) #define LCK_TRK_LOGIC	(1 << 4)	/* ADP5589 only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) #define LCK_TRK_GPI	(1 << 3)	/* ADP5589 only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) #define INT_CFG		(1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) #define RST_CFG		(1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) /* INT_EN Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) #define LOGIC2_IEN	(1 << 5)	/* ADP5589 only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) #define LOGIC1_IEN	(1 << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) #define LOCK_IEN	(1 << 3)	/* ADP5589 only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) #define OVRFLOW_IEN	(1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) #define GPI_IEN		(1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) #define EVENT_IEN	(1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) /* Interrupt Status Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) #define LOGIC2_INT	(1 << 5)	/* ADP5589 only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) #define LOGIC1_INT	(1 << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) #define LOCK_INT	(1 << 3)	/* ADP5589 only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) #define OVRFLOW_INT	(1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) #define GPI_INT		(1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) #define EVENT_INT	(1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) /* STATUS Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) #define LOGIC2_STAT	(1 << 7)	/* ADP5589 only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) #define LOGIC1_STAT	(1 << 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) #define LOCK_STAT	(1 << 5)	/* ADP5589 only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) #define KEC		0x1F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) /* PIN_CONFIG_D Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) #define C4_EXTEND_CFG	(1 << 6)	/* RESET2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) #define R4_EXTEND_CFG	(1 << 5)	/* RESET1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) /* LOCK_CFG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) #define LOCK_EN		(1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) #define PTIME_MASK	0x3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) #define LTIME_MASK	0x3		/* ADP5589 only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) /* Key Event Register xy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) #define KEY_EV_PRESSED		(1 << 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) #define KEY_EV_MASK		(0x7F)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) #define KEYP_MAX_EVENT		16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) #define ADP5589_MAXGPIO		19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) #define ADP5585_MAXGPIO		11 /* 10 on the ADP5585-01, 11 on ADP5585-02 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	ADP5589,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	ADP5585_01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	ADP5585_02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) struct adp_constants {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	u8 maxgpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	u8 keymapsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	u8 gpi_pin_row_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	u8 gpi_pin_row_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	u8 gpi_pin_col_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	u8 gpi_pin_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	u8 gpi_pin_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	u8 gpimapsize_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	u8 max_row_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	u8 max_col_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	u8 row_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	u8 col_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	u8 col_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	u8 c4_extend_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	u8 (*bank) (u8 offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	u8 (*bit) (u8 offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	u8 (*reg) (u8 reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) struct adp5589_kpad {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	const struct adp_constants *var;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	unsigned short keycode[ADP5589_KEYMAPSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	const struct adp5589_gpi_map *gpimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	unsigned short gpimapsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	unsigned extend_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	bool is_adp5585;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	bool support_row5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) #ifdef CONFIG_GPIOLIB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	unsigned char gpiomap[ADP5589_MAXGPIO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	bool export_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	struct gpio_chip gc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	struct mutex gpio_lock;	/* Protect cached dir, dat_out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	u8 dat_out[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	u8 dir[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250)  *  ADP5589 / ADP5585 derivative / variant handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251)  */
^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) /* ADP5589 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) static unsigned char adp5589_bank(unsigned char offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	return offset >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) static unsigned char adp5589_bit(unsigned char offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	return 1u << (offset & 0x7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) static unsigned char adp5589_reg(unsigned char reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	return reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) static const struct adp_constants const_adp5589 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	.maxgpio		= ADP5589_MAXGPIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	.keymapsize		= ADP5589_KEYMAPSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	.gpi_pin_row_base	= ADP5589_GPI_PIN_ROW_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	.gpi_pin_row_end	= ADP5589_GPI_PIN_ROW_END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	.gpi_pin_col_base	= ADP5589_GPI_PIN_COL_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	.gpi_pin_base		= ADP5589_GPI_PIN_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	.gpi_pin_end		= ADP5589_GPI_PIN_END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	.gpimapsize_max		= ADP5589_GPIMAPSIZE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	.c4_extend_cfg		= 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	.max_row_num		= ADP5589_MAX_ROW_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	.max_col_num		= ADP5589_MAX_COL_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	.row_mask		= ADP5589_ROW_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	.col_mask		= ADP5589_COL_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	.col_shift		= ADP5589_COL_SHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	.bank			= adp5589_bank,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	.bit			= adp5589_bit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	.reg			= adp5589_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) /* ADP5585 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) static unsigned char adp5585_bank(unsigned char offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	return offset > ADP5585_MAX_ROW_NUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) static unsigned char adp5585_bit(unsigned char offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	return (offset > ADP5585_MAX_ROW_NUM) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		1u << (offset - ADP5585_COL_SHIFT) : 1u << offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) static const unsigned char adp5585_reg_lut[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	[ADP5589_GPI_STATUS_A]		= ADP5585_GPI_STATUS_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	[ADP5589_GPI_STATUS_B]		= ADP5585_GPI_STATUS_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	[ADP5589_RPULL_CONFIG_A]	= ADP5585_RPULL_CONFIG_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	[ADP5589_RPULL_CONFIG_B]	= ADP5585_RPULL_CONFIG_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	[ADP5589_RPULL_CONFIG_C]	= ADP5585_RPULL_CONFIG_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	[ADP5589_RPULL_CONFIG_D]	= ADP5585_RPULL_CONFIG_D,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	[ADP5589_GPI_INT_LEVEL_A]	= ADP5585_GPI_INT_LEVEL_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	[ADP5589_GPI_INT_LEVEL_B]	= ADP5585_GPI_INT_LEVEL_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	[ADP5589_GPI_EVENT_EN_A]	= ADP5585_GPI_EVENT_EN_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	[ADP5589_GPI_EVENT_EN_B]	= ADP5585_GPI_EVENT_EN_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	[ADP5589_GPI_INTERRUPT_EN_A]	= ADP5585_GPI_INTERRUPT_EN_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	[ADP5589_GPI_INTERRUPT_EN_B]	= ADP5585_GPI_INTERRUPT_EN_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	[ADP5589_DEBOUNCE_DIS_A]	= ADP5585_DEBOUNCE_DIS_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	[ADP5589_DEBOUNCE_DIS_B]	= ADP5585_DEBOUNCE_DIS_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	[ADP5589_GPO_DATA_OUT_A]	= ADP5585_GPO_DATA_OUT_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	[ADP5589_GPO_DATA_OUT_B]	= ADP5585_GPO_DATA_OUT_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	[ADP5589_GPO_OUT_MODE_A]	= ADP5585_GPO_OUT_MODE_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	[ADP5589_GPO_OUT_MODE_B]	= ADP5585_GPO_OUT_MODE_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	[ADP5589_GPIO_DIRECTION_A]	= ADP5585_GPIO_DIRECTION_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	[ADP5589_GPIO_DIRECTION_B]	= ADP5585_GPIO_DIRECTION_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	[ADP5589_RESET1_EVENT_A]	= ADP5585_RESET1_EVENT_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	[ADP5589_RESET1_EVENT_B]	= ADP5585_RESET1_EVENT_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	[ADP5589_RESET1_EVENT_C]	= ADP5585_RESET1_EVENT_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	[ADP5589_RESET2_EVENT_A]	= ADP5585_RESET2_EVENT_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	[ADP5589_RESET2_EVENT_B]	= ADP5585_RESET2_EVENT_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	[ADP5589_RESET_CFG]		= ADP5585_RESET_CFG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	[ADP5589_PWM_OFFT_LOW]		= ADP5585_PWM_OFFT_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	[ADP5589_PWM_OFFT_HIGH]		= ADP5585_PWM_OFFT_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	[ADP5589_PWM_ONT_LOW]		= ADP5585_PWM_ONT_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	[ADP5589_PWM_ONT_HIGH]		= ADP5585_PWM_ONT_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	[ADP5589_PWM_CFG]		= ADP5585_PWM_CFG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	[ADP5589_LOGIC_1_CFG]		= ADP5585_LOGIC_CFG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	[ADP5589_LOGIC_FF_CFG]		= ADP5585_LOGIC_FF_CFG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	[ADP5589_LOGIC_INT_EVENT_EN]	= ADP5585_LOGIC_INT_EVENT_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	[ADP5589_POLL_PTIME_CFG]	= ADP5585_POLL_PTIME_CFG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	[ADP5589_PIN_CONFIG_A]		= ADP5585_PIN_CONFIG_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	[ADP5589_PIN_CONFIG_B]		= ADP5585_PIN_CONFIG_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	[ADP5589_PIN_CONFIG_D]		= ADP5585_PIN_CONFIG_D,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	[ADP5589_GENERAL_CFG]		= ADP5585_GENERAL_CFG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	[ADP5589_INT_EN]		= ADP5585_INT_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) static unsigned char adp5585_reg(unsigned char reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	return adp5585_reg_lut[reg];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) static const struct adp_constants const_adp5585 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	.maxgpio		= ADP5585_MAXGPIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	.keymapsize		= ADP5585_KEYMAPSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	.gpi_pin_row_base	= ADP5585_GPI_PIN_ROW_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	.gpi_pin_row_end	= ADP5585_GPI_PIN_ROW_END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	.gpi_pin_col_base	= ADP5585_GPI_PIN_COL_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	.gpi_pin_base		= ADP5585_GPI_PIN_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	.gpi_pin_end		= ADP5585_GPI_PIN_END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	.gpimapsize_max		= ADP5585_GPIMAPSIZE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	.c4_extend_cfg		= 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	.max_row_num		= ADP5585_MAX_ROW_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	.max_col_num		= ADP5585_MAX_COL_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	.row_mask		= ADP5585_ROW_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	.col_mask		= ADP5585_COL_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	.col_shift		= ADP5585_COL_SHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	.bank			= adp5585_bank,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	.bit			= adp5585_bit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	.reg			= adp5585_reg,
^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) static int adp5589_read(struct i2c_client *client, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	int ret = i2c_smbus_read_byte_data(client, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		dev_err(&client->dev, "Read Error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) static int adp5589_write(struct i2c_client *client, u8 reg, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	return i2c_smbus_write_byte_data(client, reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) #ifdef CONFIG_GPIOLIB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) static int adp5589_gpio_get_value(struct gpio_chip *chip, unsigned off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	struct adp5589_kpad *kpad = gpiochip_get_data(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	return !!(adp5589_read(kpad->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 			       kpad->var->reg(ADP5589_GPI_STATUS_A) + bank) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 			       bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) static void adp5589_gpio_set_value(struct gpio_chip *chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 				   unsigned off, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	struct adp5589_kpad *kpad = gpiochip_get_data(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	mutex_lock(&kpad->gpio_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		kpad->dat_out[bank] |= bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		kpad->dat_out[bank] &= ~bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	adp5589_write(kpad->client, kpad->var->reg(ADP5589_GPO_DATA_OUT_A) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		      bank, kpad->dat_out[bank]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	mutex_unlock(&kpad->gpio_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) static int adp5589_gpio_direction_input(struct gpio_chip *chip, unsigned off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	struct adp5589_kpad *kpad = gpiochip_get_data(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	mutex_lock(&kpad->gpio_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	kpad->dir[bank] &= ~bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	ret = adp5589_write(kpad->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 			    kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 			    kpad->dir[bank]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	mutex_unlock(&kpad->gpio_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) static int adp5589_gpio_direction_output(struct gpio_chip *chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 					 unsigned off, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	struct adp5589_kpad *kpad = gpiochip_get_data(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	mutex_lock(&kpad->gpio_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	kpad->dir[bank] |= bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		kpad->dat_out[bank] |= bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		kpad->dat_out[bank] &= ~bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	ret = adp5589_write(kpad->client, kpad->var->reg(ADP5589_GPO_DATA_OUT_A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 			    + bank, kpad->dat_out[bank]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	ret |= adp5589_write(kpad->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 			     kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 			     kpad->dir[bank]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	mutex_unlock(&kpad->gpio_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) static int adp5589_build_gpiomap(struct adp5589_kpad *kpad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 				const struct adp5589_kpad_platform_data *pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	bool pin_used[ADP5589_MAXGPIO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	int n_unused = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	memset(pin_used, false, sizeof(pin_used));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	for (i = 0; i < kpad->var->maxgpio; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		if (pdata->keypad_en_mask & (1 << i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 			pin_used[i] = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	for (i = 0; i < kpad->gpimapsize; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		pin_used[kpad->gpimap[i].pin - kpad->var->gpi_pin_base] = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	if (kpad->extend_cfg & R4_EXTEND_CFG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		pin_used[4] = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	if (kpad->extend_cfg & C4_EXTEND_CFG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		pin_used[kpad->var->c4_extend_cfg] = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	if (!kpad->support_row5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		pin_used[5] = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	for (i = 0; i < kpad->var->maxgpio; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		if (!pin_used[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 			kpad->gpiomap[n_unused++] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	return n_unused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) static int adp5589_gpio_add(struct adp5589_kpad *kpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	struct device *dev = &kpad->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	const struct adp5589_kpad_platform_data *pdata = dev_get_platdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	const struct adp5589_gpio_platform_data *gpio_data = pdata->gpio_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	int i, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	if (!gpio_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	kpad->gc.parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	kpad->gc.ngpio = adp5589_build_gpiomap(kpad, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	if (kpad->gc.ngpio == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		dev_info(dev, "No unused gpios left to export\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	kpad->export_gpio = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	kpad->gc.direction_input = adp5589_gpio_direction_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	kpad->gc.direction_output = adp5589_gpio_direction_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	kpad->gc.get = adp5589_gpio_get_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	kpad->gc.set = adp5589_gpio_set_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	kpad->gc.can_sleep = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	kpad->gc.base = gpio_data->gpio_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	kpad->gc.label = kpad->client->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	kpad->gc.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	mutex_init(&kpad->gpio_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	error = gpiochip_add_data(&kpad->gc, kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		dev_err(dev, "gpiochip_add_data() failed, err: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	for (i = 0; i <= kpad->var->bank(kpad->var->maxgpio); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 		kpad->dat_out[i] = adp5589_read(kpad->client, kpad->var->reg(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 						ADP5589_GPO_DATA_OUT_A) + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		kpad->dir[i] = adp5589_read(kpad->client, kpad->var->reg(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 					    ADP5589_GPIO_DIRECTION_A) + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	if (gpio_data->setup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		error = gpio_data->setup(kpad->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 					 kpad->gc.base, kpad->gc.ngpio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 					 gpio_data->context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 			dev_warn(dev, "setup failed, %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) static void adp5589_gpio_remove(struct adp5589_kpad *kpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	struct device *dev = &kpad->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	const struct adp5589_kpad_platform_data *pdata = dev_get_platdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	const struct adp5589_gpio_platform_data *gpio_data = pdata->gpio_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	if (!kpad->export_gpio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	if (gpio_data->teardown) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 		error = gpio_data->teardown(kpad->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 					    kpad->gc.base, kpad->gc.ngpio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 					    gpio_data->context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 			dev_warn(dev, "teardown failed %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	gpiochip_remove(&kpad->gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) static inline int adp5589_gpio_add(struct adp5589_kpad *kpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) static inline void adp5589_gpio_remove(struct adp5589_kpad *kpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) static void adp5589_report_switches(struct adp5589_kpad *kpad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 				    int key, int key_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	for (i = 0; i < kpad->gpimapsize; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		if (key_val == kpad->gpimap[i].pin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 			input_report_switch(kpad->input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 					    kpad->gpimap[i].sw_evt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 					    key & KEY_EV_PRESSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) static void adp5589_report_events(struct adp5589_kpad *kpad, int ev_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	for (i = 0; i < ev_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		int key = adp5589_read(kpad->client, ADP5589_5_FIFO_1 + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		int key_val = key & KEY_EV_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		if (key_val >= kpad->var->gpi_pin_base &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		    key_val <= kpad->var->gpi_pin_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 			adp5589_report_switches(kpad, key, key_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 			input_report_key(kpad->input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 					 kpad->keycode[key_val - 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 					 key & KEY_EV_PRESSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) static irqreturn_t adp5589_irq(int irq, void *handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	struct adp5589_kpad *kpad = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	struct i2c_client *client = kpad->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	int status, ev_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	status = adp5589_read(client, ADP5589_5_INT_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	if (status & OVRFLOW_INT)	/* Unlikely and should never happen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		dev_err(&client->dev, "Event Overflow Error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	if (status & EVENT_INT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		ev_cnt = adp5589_read(client, ADP5589_5_STATUS) & KEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		if (ev_cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 			adp5589_report_events(kpad, ev_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 			input_sync(kpad->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	adp5589_write(client, ADP5589_5_INT_STATUS, status); /* Status is W1C */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) static int adp5589_get_evcode(struct adp5589_kpad *kpad, unsigned short key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	for (i = 0; i < kpad->var->keymapsize; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		if (key == kpad->keycode[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 			return (i + 1) | KEY_EV_PRESSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	dev_err(&kpad->client->dev, "RESET/UNLOCK key not in keycode map\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) static int adp5589_setup(struct adp5589_kpad *kpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	struct i2c_client *client = kpad->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	const struct adp5589_kpad_platform_data *pdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		dev_get_platdata(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	u8 (*reg) (u8) = kpad->var->reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	unsigned char evt_mode1 = 0, evt_mode2 = 0, evt_mode3 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	unsigned char pull_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	ret = adp5589_write(client, reg(ADP5589_PIN_CONFIG_A),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 			    pdata->keypad_en_mask & kpad->var->row_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	ret |= adp5589_write(client, reg(ADP5589_PIN_CONFIG_B),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 			     (pdata->keypad_en_mask >> kpad->var->col_shift) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 			     kpad->var->col_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	if (!kpad->is_adp5585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		ret |= adp5589_write(client, ADP5589_PIN_CONFIG_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 				     (pdata->keypad_en_mask >> 16) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	if (!kpad->is_adp5585 && pdata->en_keylock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		ret |= adp5589_write(client, ADP5589_UNLOCK1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 				     pdata->unlock_key1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		ret |= adp5589_write(client, ADP5589_UNLOCK2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 				     pdata->unlock_key2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		ret |= adp5589_write(client, ADP5589_UNLOCK_TIMERS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 				     pdata->unlock_timer & LTIME_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		ret |= adp5589_write(client, ADP5589_LOCK_CFG, LOCK_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	for (i = 0; i < KEYP_MAX_EVENT; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		ret |= adp5589_read(client, ADP5589_5_FIFO_1 + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	for (i = 0; i < pdata->gpimapsize; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		unsigned short pin = pdata->gpimap[i].pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		if (pin <= kpad->var->gpi_pin_row_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			evt_mode1 |= (1 << (pin - kpad->var->gpi_pin_row_base));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 			evt_mode2 |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 			    ((1 << (pin - kpad->var->gpi_pin_col_base)) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 			if (!kpad->is_adp5585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 				evt_mode3 |= ((1 << (pin -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 					kpad->var->gpi_pin_col_base)) >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	if (pdata->gpimapsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		ret |= adp5589_write(client, reg(ADP5589_GPI_EVENT_EN_A),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 				     evt_mode1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		ret |= adp5589_write(client, reg(ADP5589_GPI_EVENT_EN_B),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 				     evt_mode2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		if (!kpad->is_adp5585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 			ret |= adp5589_write(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 					     reg(ADP5589_GPI_EVENT_EN_C),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 					     evt_mode3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	if (pdata->pull_dis_mask & pdata->pullup_en_100k &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		pdata->pullup_en_300k & pdata->pulldown_en_300k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		dev_warn(&client->dev, "Conflicting pull resistor config\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	for (i = 0; i <= kpad->var->max_row_num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		unsigned val = 0, bit = (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		if (pdata->pullup_en_300k & bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 			val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		else if (pdata->pulldown_en_300k & bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 			val = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		else if (pdata->pullup_en_100k & bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 			val = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		else if (pdata->pull_dis_mask & bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 			val = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		pull_mask |= val << (2 * (i & 0x3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		if (i % 4 == 3 || i == kpad->var->max_row_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 			ret |= adp5589_write(client, reg(ADP5585_RPULL_CONFIG_A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 					     + (i >> 2), pull_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 			pull_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	for (i = 0; i <= kpad->var->max_col_num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		unsigned val = 0, bit = 1 << (i + kpad->var->col_shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		if (pdata->pullup_en_300k & bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		else if (pdata->pulldown_en_300k & bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 			val = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		else if (pdata->pullup_en_100k & bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 			val = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		else if (pdata->pull_dis_mask & bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			val = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		pull_mask |= val << (2 * (i & 0x3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		if (i % 4 == 3 || i == kpad->var->max_col_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 			ret |= adp5589_write(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 					     reg(ADP5585_RPULL_CONFIG_C) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 					     (i >> 2), pull_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 			pull_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	if (pdata->reset1_key_1 && pdata->reset1_key_2 && pdata->reset1_key_3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		ret |= adp5589_write(client, reg(ADP5589_RESET1_EVENT_A),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 				     adp5589_get_evcode(kpad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 							pdata->reset1_key_1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		ret |= adp5589_write(client, reg(ADP5589_RESET1_EVENT_B),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 				     adp5589_get_evcode(kpad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 							pdata->reset1_key_2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		ret |= adp5589_write(client, reg(ADP5589_RESET1_EVENT_C),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 				     adp5589_get_evcode(kpad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 							pdata->reset1_key_3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		kpad->extend_cfg |= R4_EXTEND_CFG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	if (pdata->reset2_key_1 && pdata->reset2_key_2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 		ret |= adp5589_write(client, reg(ADP5589_RESET2_EVENT_A),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 				     adp5589_get_evcode(kpad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 							pdata->reset2_key_1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		ret |= adp5589_write(client, reg(ADP5589_RESET2_EVENT_B),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 				     adp5589_get_evcode(kpad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 							pdata->reset2_key_2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		kpad->extend_cfg |= C4_EXTEND_CFG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	if (kpad->extend_cfg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		ret |= adp5589_write(client, reg(ADP5589_RESET_CFG),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 				     pdata->reset_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		ret |= adp5589_write(client, reg(ADP5589_PIN_CONFIG_D),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 				     kpad->extend_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	ret |= adp5589_write(client, reg(ADP5589_DEBOUNCE_DIS_A),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 			    pdata->debounce_dis_mask & kpad->var->row_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	ret |= adp5589_write(client, reg(ADP5589_DEBOUNCE_DIS_B),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 			     (pdata->debounce_dis_mask >> kpad->var->col_shift)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 			     & kpad->var->col_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	if (!kpad->is_adp5585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		ret |= adp5589_write(client, reg(ADP5589_DEBOUNCE_DIS_C),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 				     (pdata->debounce_dis_mask >> 16) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	ret |= adp5589_write(client, reg(ADP5589_POLL_PTIME_CFG),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 			     pdata->scan_cycle_time & PTIME_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	ret |= adp5589_write(client, ADP5589_5_INT_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 			     (kpad->is_adp5585 ? 0 : LOGIC2_INT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 			     LOGIC1_INT | OVRFLOW_INT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 			     (kpad->is_adp5585 ? 0 : LOCK_INT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 			     GPI_INT | EVENT_INT);	/* Status is W1C */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	ret |= adp5589_write(client, reg(ADP5589_GENERAL_CFG),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 			     INT_CFG | OSC_EN | CORE_CLK(3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	ret |= adp5589_write(client, reg(ADP5589_INT_EN),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 			     OVRFLOW_IEN | GPI_IEN | EVENT_IEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		dev_err(&client->dev, "Write Error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) static void adp5589_report_switch_state(struct adp5589_kpad *kpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	int gpi_stat_tmp, pin_loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	int gpi_stat1 = adp5589_read(kpad->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 				     kpad->var->reg(ADP5589_GPI_STATUS_A));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	int gpi_stat2 = adp5589_read(kpad->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 				     kpad->var->reg(ADP5589_GPI_STATUS_B));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	int gpi_stat3 = !kpad->is_adp5585 ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 			adp5589_read(kpad->client, ADP5589_GPI_STATUS_C) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	for (i = 0; i < kpad->gpimapsize; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		unsigned short pin = kpad->gpimap[i].pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		if (pin <= kpad->var->gpi_pin_row_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 			gpi_stat_tmp = gpi_stat1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 			pin_loc = pin - kpad->var->gpi_pin_row_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		} else if ((pin - kpad->var->gpi_pin_col_base) < 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 			gpi_stat_tmp = gpi_stat2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 			pin_loc = pin - kpad->var->gpi_pin_col_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 			gpi_stat_tmp = gpi_stat3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 			pin_loc = pin - kpad->var->gpi_pin_col_base - 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		if (gpi_stat_tmp < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 			dev_err(&kpad->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 				"Can't read GPIO_DAT_STAT switch %d, default to OFF\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 				pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 			gpi_stat_tmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		input_report_switch(kpad->input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 				    kpad->gpimap[i].sw_evt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 				    !(gpi_stat_tmp & (1 << pin_loc)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	input_sync(kpad->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) static int adp5589_keypad_add(struct adp5589_kpad *kpad, unsigned int revid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	struct i2c_client *client = kpad->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	const struct adp5589_kpad_platform_data *pdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		dev_get_platdata(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	if (!((pdata->keypad_en_mask & kpad->var->row_mask) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 			(pdata->keypad_en_mask >> kpad->var->col_shift)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 			!pdata->keymap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		dev_err(&client->dev, "no rows, cols or keymap from pdata\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	if (pdata->keymapsize != kpad->var->keymapsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		dev_err(&client->dev, "invalid keymapsize\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	if (!pdata->gpimap && pdata->gpimapsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		dev_err(&client->dev, "invalid gpimap from pdata\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	if (pdata->gpimapsize > kpad->var->gpimapsize_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		dev_err(&client->dev, "invalid gpimapsize\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	for (i = 0; i < pdata->gpimapsize; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		unsigned short pin = pdata->gpimap[i].pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		if (pin < kpad->var->gpi_pin_base ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 				pin > kpad->var->gpi_pin_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 			dev_err(&client->dev, "invalid gpi pin data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		if ((1 << (pin - kpad->var->gpi_pin_row_base)) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 				pdata->keypad_en_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 			dev_err(&client->dev, "invalid gpi row/col data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	if (!client->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		dev_err(&client->dev, "no IRQ?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	input = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	kpad->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	input->name = client->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	input->phys = "adp5589-keys/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	input->dev.parent = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	input_set_drvdata(input, kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	input->id.vendor = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	input->id.product = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	input->id.version = revid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	input->keycodesize = sizeof(kpad->keycode[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	input->keycodemax = pdata->keymapsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	input->keycode = kpad->keycode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	memcpy(kpad->keycode, pdata->keymap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	       pdata->keymapsize * input->keycodesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	kpad->gpimap = pdata->gpimap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	kpad->gpimapsize = pdata->gpimapsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	/* setup input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	__set_bit(EV_KEY, input->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	if (pdata->repeat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		__set_bit(EV_REP, input->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	for (i = 0; i < input->keycodemax; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		if (kpad->keycode[i] <= KEY_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			__set_bit(kpad->keycode[i], input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	__clear_bit(KEY_RESERVED, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	if (kpad->gpimapsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		__set_bit(EV_SW, input->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	for (i = 0; i < kpad->gpimapsize; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		__set_bit(kpad->gpimap[i].sw_evt, input->swbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	error = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		dev_err(&client->dev, "unable to register input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 		goto err_free_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	error = request_threaded_irq(client->irq, NULL, adp5589_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 				     IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 				     client->dev.driver->name, kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		dev_err(&client->dev, "irq %d busy?\n", client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		goto err_unreg_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	device_init_wakeup(&client->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) err_unreg_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	input_unregister_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) err_free_input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	input_free_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) static void adp5589_keypad_remove(struct adp5589_kpad *kpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	if (kpad->input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		free_irq(kpad->client->irq, kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		input_unregister_device(kpad->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) static int adp5589_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 			 const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	struct adp5589_kpad *kpad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	const struct adp5589_kpad_platform_data *pdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		dev_get_platdata(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	unsigned int revid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	int error, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	if (!i2c_check_functionality(client->adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 				     I2C_FUNC_SMBUS_BYTE_DATA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		dev_err(&client->dev, "SMBUS Byte Data not Supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	if (!pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 		dev_err(&client->dev, "no platform data?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	kpad = kzalloc(sizeof(*kpad), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	if (!kpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	kpad->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	switch (id->driver_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	case ADP5585_02:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		kpad->support_row5 = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	case ADP5585_01:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		kpad->is_adp5585 = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		kpad->var = &const_adp5585;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	case ADP5589:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		kpad->support_row5 = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		kpad->var = &const_adp5589;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	ret = adp5589_read(client, ADP5589_5_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		error = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	revid = (u8) ret & ADP5589_5_DEVICE_ID_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	if (pdata->keymapsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		error = adp5589_keypad_add(kpad, revid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 			goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	error = adp5589_setup(kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		goto err_keypad_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	if (kpad->gpimapsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		adp5589_report_switch_state(kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	error = adp5589_gpio_add(kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		goto err_keypad_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	i2c_set_clientdata(client, kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) err_keypad_remove:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	adp5589_keypad_remove(kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) err_free_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	kfree(kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) static int adp5589_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	struct adp5589_kpad *kpad = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	adp5589_write(client, kpad->var->reg(ADP5589_GENERAL_CFG), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	adp5589_keypad_remove(kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	adp5589_gpio_remove(kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	kfree(kpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) static int adp5589_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	struct adp5589_kpad *kpad = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	struct i2c_client *client = kpad->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	if (!kpad->input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	disable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	if (device_may_wakeup(&client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		enable_irq_wake(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) static int adp5589_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	struct adp5589_kpad *kpad = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	struct i2c_client *client = kpad->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	if (!kpad->input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	if (device_may_wakeup(&client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		disable_irq_wake(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	enable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) static SIMPLE_DEV_PM_OPS(adp5589_dev_pm_ops, adp5589_suspend, adp5589_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) static const struct i2c_device_id adp5589_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	{"adp5589-keys", ADP5589},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	{"adp5585-keys", ADP5585_01},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	{"adp5585-02-keys", ADP5585_02}, /* Adds ROW5 to ADP5585 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) MODULE_DEVICE_TABLE(i2c, adp5589_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) static struct i2c_driver adp5589_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 		.name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		.pm = &adp5589_dev_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	.probe = adp5589_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	.remove = adp5589_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	.id_table = adp5589_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) module_i2c_driver(adp5589_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) MODULE_DESCRIPTION("ADP5589/ADP5585 Keypad driver");