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)  * ROHM BU21023/24 Dual touch support resistive touch screen driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright (C) 2012 ROHM CO.,LTD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/input/mt.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/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #define BU21023_NAME			"bu21023_ts"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #define BU21023_FIRMWARE_NAME		"bu21023.bin"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #define MAX_CONTACTS			2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #define AXIS_ADJUST			4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #define AXIS_OFFSET			8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #define FIRMWARE_BLOCK_SIZE		32U
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #define FIRMWARE_RETRY_MAX		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #define SAMPLING_DELAY			12	/* msec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #define CALIBRATION_RETRY_MAX		6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #define ROHM_TS_ABS_X_MIN		40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #define ROHM_TS_ABS_X_MAX		990
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #define ROHM_TS_ABS_Y_MIN		160
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #define ROHM_TS_ABS_Y_MAX		920
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #define ROHM_TS_DISPLACEMENT_MAX	0	/* zero for infinite */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  * BU21023GUL/BU21023MUV/BU21024FV-M registers map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #define VADOUT_YP_H		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #define VADOUT_YP_L		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #define VADOUT_XP_H		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #define VADOUT_XP_L		0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #define VADOUT_YN_H		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #define VADOUT_YN_L		0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #define VADOUT_XN_H		0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #define VADOUT_XN_L		0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #define PRM1_X_H		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #define PRM1_X_L		0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #define PRM1_Y_H		0x0a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #define PRM1_Y_L		0x0b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #define PRM2_X_H		0x0c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #define PRM2_X_L		0x0d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define PRM2_Y_H		0x0e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #define PRM2_Y_L		0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #define MLT_PRM_MONI_X		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #define MLT_PRM_MONI_Y		0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #define DEBUG_MONI_1		0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #define DEBUG_MONI_2		0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #define VADOUT_ZX_H		0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #define VADOUT_ZX_L		0x15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #define VADOUT_ZY_H		0x16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #define VADOUT_ZY_L		0x17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #define Z_PARAM_H		0x18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #define Z_PARAM_L		0x19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)  * Value for VADOUT_*_L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) #define VADOUT_L_MASK		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)  * Value for PRM*_*_L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #define PRM_L_MASK		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #define POS_X1_H		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #define POS_X1_L		0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) #define POS_Y1_H		0x22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #define POS_Y1_L		0x23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #define POS_X2_H		0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #define POS_X2_L		0x25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) #define POS_Y2_H		0x26
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #define POS_Y2_L		0x27
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  * Value for POS_*_L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) #define POS_L_MASK		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) #define TOUCH			0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) #define TOUCH_DETECT		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) #define TOUCH_GESTURE		0x29
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) #define SINGLE_TOUCH		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) #define DUAL_TOUCH		0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) #define TOUCH_MASK		0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) #define CALIBRATION_REQUEST	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) #define CALIBRATION_STATUS	0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) #define CALIBRATION_MASK	0x0c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) #define GESTURE_SPREAD		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) #define GESTURE_PINCH		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) #define GESTURE_ROTATE_R	0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) #define GESTURE_ROTATE_L	0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) #define INT_STATUS		0x2a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) #define INT_MASK		0x3d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) #define INT_CLEAR		0x3e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)  * Values for INT_*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) #define COORD_UPDATE		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) #define CALIBRATION_DONE	0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) #define SLEEP_IN		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) #define SLEEP_OUT		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) #define PROGRAM_LOAD_DONE	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) #define ERROR			0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) #define INT_ALL			0x9f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) #define ERR_STATUS		0x2b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) #define ERR_MASK		0x3f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129)  * Values for ERR_*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) #define ADC_TIMEOUT		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) #define CPU_TIMEOUT		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) #define CALIBRATION_ERR		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) #define PROGRAM_LOAD_ERR	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) #define COMMON_SETUP1			0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) #define PROGRAM_LOAD_HOST		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) #define PROGRAM_LOAD_EEPROM		0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) #define CENSOR_4PORT			0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) #define CENSOR_8PORT			0x00	/* Not supported by BU21023 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) #define CALIBRATION_TYPE_DEFAULT	0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) #define CALIBRATION_TYPE_SPECIAL	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) #define INT_ACTIVE_HIGH			0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) #define INT_ACTIVE_LOW			0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) #define AUTO_CALIBRATION		0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) #define MANUAL_CALIBRATION		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) #define COMMON_SETUP1_DEFAULT		0x4e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) #define COMMON_SETUP2		0x31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) #define MAF_NONE		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) #define MAF_1SAMPLE		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) #define MAF_3SAMPLES		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) #define MAF_5SAMPLES		0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) #define INV_Y			0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) #define INV_X			0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) #define SWAP_XY			0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) #define COMMON_SETUP3		0x32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) #define EN_SLEEP		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) #define EN_MULTI		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) #define EN_GESTURE		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) #define EN_INTVL		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) #define SEL_STEP		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) #define SEL_MULTI		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) #define SEL_TBL_DEFAULT		0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) #define INTERVAL_TIME		0x33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) #define INTERVAL_TIME_DEFAULT	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) #define STEP_X			0x34
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) #define STEP_X_DEFAULT		0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) #define STEP_Y			0x35
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) #define STEP_Y_DEFAULT		0x8d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) #define OFFSET_X		0x38
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) #define OFFSET_X_DEFAULT	0x0c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) #define OFFSET_Y		0x39
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) #define OFFSET_Y_DEFAULT	0x0c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) #define THRESHOLD_TOUCH		0x3a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) #define THRESHOLD_TOUCH_DEFAULT	0xa0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) #define THRESHOLD_GESTURE		0x3b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) #define THRESHOLD_GESTURE_DEFAULT	0x17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) #define SYSTEM			0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) #define ANALOG_POWER_ON		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) #define ANALOG_POWER_OFF	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) #define CPU_POWER_ON		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) #define CPU_POWER_OFF		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) #define FORCE_CALIBRATION	0x42
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) #define FORCE_CALIBRATION_ON	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) #define FORCE_CALIBRATION_OFF	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) #define CPU_FREQ		0x50	/* 10 / (reg + 1) MHz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) #define CPU_FREQ_10MHZ		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) #define CPU_FREQ_5MHZ		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) #define CPU_FREQ_1MHZ		0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) #define EEPROM_ADDR		0x51
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) #define CALIBRATION_ADJUST		0x52
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) #define CALIBRATION_ADJUST_DEFAULT	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) #define THRESHOLD_SLEEP_IN	0x53
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) #define EVR_XY			0x56
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) #define EVR_XY_DEFAULT		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) #define PRM_SWOFF_TIME		0x57
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) #define PRM_SWOFF_TIME_DEFAULT	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) #define PROGRAM_VERSION		0x5f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) #define ADC_CTRL		0x60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) #define ADC_DIV_MASK		0x1f	/* The minimum value is 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) #define ADC_DIV_DEFAULT		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) #define ADC_WAIT		0x61
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) #define ADC_WAIT_DEFAULT	0x0a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) #define SWCONT			0x62
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) #define SWCONT_DEFAULT		0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) #define EVR_X			0x63
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) #define EVR_X_DEFAULT		0x86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) #define EVR_Y			0x64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) #define EVR_Y_DEFAULT		0x64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) #define TEST1			0x65
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) #define DUALTOUCH_STABILIZE_ON	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) #define DUALTOUCH_STABILIZE_OFF	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) #define DUALTOUCH_REG_ON	0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) #define DUALTOUCH_REG_OFF	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) #define CALIBRATION_REG1		0x68
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) #define CALIBRATION_REG1_DEFAULT	0xd9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) #define CALIBRATION_REG2		0x69
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) #define CALIBRATION_REG2_DEFAULT	0x36
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) #define CALIBRATION_REG3		0x6a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) #define CALIBRATION_REG3_DEFAULT	0x32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) #define EX_ADDR_H		0x70
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) #define EX_ADDR_L		0x71
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) #define EX_WDAT			0x72
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) #define EX_RDAT			0x73
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) #define EX_CHK_SUM1		0x74
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) #define EX_CHK_SUM2		0x75
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) #define EX_CHK_SUM3		0x76
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) struct rohm_ts_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	bool initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	unsigned int contact_count[MAX_CONTACTS + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	int finger_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	u8 setup2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270)  * rohm_i2c_burst_read - execute combined I2C message for ROHM BU21023/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271)  * @client: Handle to ROHM BU21023/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272)  * @start: Where to start read address from ROHM BU21023/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273)  * @buf: Where to store read data from ROHM BU21023/24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274)  * @len: How many bytes to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276)  * Returns negative errno, else zero on success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278)  * Note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279)  * In BU21023/24 burst read, stop condition is needed after "address write".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280)  * Therefore, transmission is performed in 2 steps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) static int rohm_i2c_burst_read(struct i2c_client *client, u8 start, void *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 			       size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	struct i2c_adapter *adap = client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	struct i2c_msg msg[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	int i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	msg[0].addr = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	msg[0].flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	msg[0].len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	msg[0].buf = &start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	msg[1].addr = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	msg[1].flags = I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	msg[1].len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	msg[1].buf = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	i2c_lock_bus(adap, I2C_LOCK_SEGMENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		if (__i2c_transfer(adap, &msg[i], 1) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	i2c_unlock_bus(adap, I2C_LOCK_SEGMENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) static int rohm_ts_manual_calibration(struct rohm_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	u8 buf[33];	/* for PRM1_X_H(0x08)-TOUCH(0x28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	int retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	bool success = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	bool first_time = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	bool calibration_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	u8 reg1, reg2, reg3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	s32 reg1_orig, reg2_orig, reg3_orig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	s32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	int calib_x = 0, calib_y = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	int reg_x, reg_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	int err_x, err_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	int error, error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	reg1_orig = i2c_smbus_read_byte_data(client, CALIBRATION_REG1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	if (reg1_orig < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		return reg1_orig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	reg2_orig = i2c_smbus_read_byte_data(client, CALIBRATION_REG2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	if (reg2_orig < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		return reg2_orig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	reg3_orig = i2c_smbus_read_byte_data(client, CALIBRATION_REG3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	if (reg3_orig < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		return reg3_orig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	error = i2c_smbus_write_byte_data(client, INT_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 					  COORD_UPDATE | SLEEP_IN | SLEEP_OUT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 					  PROGRAM_LOAD_DONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	error = i2c_smbus_write_byte_data(client, TEST1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 					  DUALTOUCH_STABILIZE_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	for (retry = 0; retry < CALIBRATION_RETRY_MAX; retry++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		/* wait 2 sampling for update */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		mdelay(2 * SAMPLING_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) #define READ_CALIB_BUF(reg)	buf[((reg) - PRM1_X_H)]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		error = rohm_i2c_burst_read(client, PRM1_X_H, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		if (READ_CALIB_BUF(TOUCH) & TOUCH_DETECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		if (first_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			/* generate calibration parameter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 			calib_x = ((int)READ_CALIB_BUF(PRM1_X_H) << 2 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 				READ_CALIB_BUF(PRM1_X_L)) - AXIS_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 			calib_y = ((int)READ_CALIB_BUF(PRM1_Y_H) << 2 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 				READ_CALIB_BUF(PRM1_Y_L)) - AXIS_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 			error = i2c_smbus_write_byte_data(client, TEST1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 				DUALTOUCH_STABILIZE_ON | DUALTOUCH_REG_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 			if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 			first_time = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 			/* generate adjustment parameter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 			err_x = (int)READ_CALIB_BUF(PRM1_X_H) << 2 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 				READ_CALIB_BUF(PRM1_X_L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 			err_y = (int)READ_CALIB_BUF(PRM1_Y_H) << 2 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 				READ_CALIB_BUF(PRM1_Y_L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 			/* X axis ajust */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 			if (err_x <= 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 				calib_x -= AXIS_ADJUST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			else if (err_x >= 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 				calib_x += AXIS_ADJUST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 			/* Y axis ajust */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 			if (err_y <= 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 				calib_y -= AXIS_ADJUST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 			else if (err_y >= 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 				calib_y += AXIS_ADJUST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		/* generate calibration setting value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		reg_x = calib_x + ((calib_x & 0x200) << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		reg_y = calib_y + ((calib_y & 0x200) << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		/* convert for register format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		reg1 = reg_x >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		reg2 = (reg_y & 0x7) << 4 | (reg_x & 0x7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		reg3 = reg_y >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		error = i2c_smbus_write_byte_data(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 						  CALIBRATION_REG1, reg1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		error = i2c_smbus_write_byte_data(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 						  CALIBRATION_REG2, reg2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		error = i2c_smbus_write_byte_data(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 						  CALIBRATION_REG3, reg3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 			goto out;
^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) 		 * force calibration sequcence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		error = i2c_smbus_write_byte_data(client, FORCE_CALIBRATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 						  FORCE_CALIBRATION_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		error = i2c_smbus_write_byte_data(client, FORCE_CALIBRATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 						  FORCE_CALIBRATION_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		/* clear all interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		error = i2c_smbus_write_byte_data(client, INT_CLEAR, 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		 * Wait for the status change of calibration, max 10 sampling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		calibration_done = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		for (i = 0; i < 10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 			mdelay(SAMPLING_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 			val = i2c_smbus_read_byte_data(client, TOUCH_GESTURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 			if (!(val & CALIBRATION_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 				calibration_done = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 			} else if (val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 				error = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		if (calibration_done) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 			val = i2c_smbus_read_byte_data(client, INT_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 			if (val == CALIBRATION_DONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 				success = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 			} else if (val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 				error = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 			dev_warn(dev, "calibration timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	if (!success) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		error = i2c_smbus_write_byte_data(client, CALIBRATION_REG1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 						  reg1_orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		error = i2c_smbus_write_byte_data(client, CALIBRATION_REG2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 						  reg2_orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		error = i2c_smbus_write_byte_data(client, CALIBRATION_REG3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 						  reg3_orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		/* calibration data enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		error = i2c_smbus_write_byte_data(client, TEST1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 						  DUALTOUCH_STABILIZE_ON |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 						  DUALTOUCH_REG_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		/* wait 10 sampling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		mdelay(10 * SAMPLING_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		error = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	error2 = i2c_smbus_write_byte_data(client, INT_MASK, INT_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	if (!error2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		/* Clear all interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		error2 = i2c_smbus_write_byte_data(client, INT_CLEAR, 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	return error ? error : error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) static const unsigned int untouch_threshold[3] = { 0, 1, 5 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) static const unsigned int single_touch_threshold[3] = { 0, 0, 4 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) static const unsigned int dual_touch_threshold[3] = { 10, 8, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) static irqreturn_t rohm_ts_soft_irq(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	struct rohm_ts_data *ts = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	struct input_dev *input_dev = ts->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	u8 buf[10];	/* for POS_X1_H(0x20)-TOUCH_GESTURE(0x29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	struct input_mt_pos pos[MAX_CONTACTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	int slots[MAX_CONTACTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	u8 touch_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	unsigned int threshold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	int finger_count = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	int prev_finger_count = ts->finger_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	error = i2c_smbus_write_byte_data(client, INT_MASK, INT_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	/* Clear all interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	error = i2c_smbus_write_byte_data(client, INT_CLEAR, 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) #define READ_POS_BUF(reg)	buf[((reg) - POS_X1_H)]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	error = rohm_i2c_burst_read(client, POS_X1_H, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	touch_flags = READ_POS_BUF(TOUCH_GESTURE) & TOUCH_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	if (touch_flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		/* generate coordinates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		pos[0].x = ((s16)READ_POS_BUF(POS_X1_H) << 2) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 			   READ_POS_BUF(POS_X1_L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		pos[0].y = ((s16)READ_POS_BUF(POS_Y1_H) << 2) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 			   READ_POS_BUF(POS_Y1_L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		pos[1].x = ((s16)READ_POS_BUF(POS_X2_H) << 2) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 			   READ_POS_BUF(POS_X2_L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 		pos[1].y = ((s16)READ_POS_BUF(POS_Y2_H) << 2) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 			   READ_POS_BUF(POS_Y2_L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	switch (touch_flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		threshold = untouch_threshold[prev_finger_count];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		if (++ts->contact_count[0] >= threshold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 			finger_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	case SINGLE_TOUCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		threshold = single_touch_threshold[prev_finger_count];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		if (++ts->contact_count[1] >= threshold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 			finger_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		if (finger_count == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 			if (pos[1].x != 0 && pos[1].y != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 				pos[0].x = pos[1].x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 				pos[0].y = pos[1].y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 				pos[1].x = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 				pos[1].y = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	case DUAL_TOUCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		threshold = dual_touch_threshold[prev_finger_count];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		if (++ts->contact_count[2] >= threshold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 			finger_count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		dev_dbg(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			"Three or more touches are not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	if (finger_count >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		if (prev_finger_count != finger_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 			count = ts->contact_count[finger_count];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 			memset(ts->contact_count, 0, sizeof(ts->contact_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 			ts->contact_count[finger_count] = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		input_mt_assign_slots(input_dev, slots, pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 				      finger_count, ROHM_TS_DISPLACEMENT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		for (i = 0; i < finger_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 			input_mt_slot(input_dev, slots[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			input_mt_report_slot_state(input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 						   MT_TOOL_FINGER, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 			input_report_abs(input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 					 ABS_MT_POSITION_X, pos[i].x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 			input_report_abs(input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 					 ABS_MT_POSITION_Y, pos[i].y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		input_mt_sync_frame(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		input_mt_report_pointer_emulation(input_dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		input_sync(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		ts->finger_count = finger_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	if (READ_POS_BUF(TOUCH_GESTURE) & CALIBRATION_REQUEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		error = rohm_ts_manual_calibration(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 			dev_warn(dev, "manual calibration failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 				 error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	i2c_smbus_write_byte_data(client, INT_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 				  CALIBRATION_DONE | SLEEP_OUT | SLEEP_IN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 				  PROGRAM_LOAD_DONE);
^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 rohm_ts_load_firmware(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 				 const char *firmware_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	const struct firmware *fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	s32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	unsigned int offset, len, xfer_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	unsigned int retry = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	int error, error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	error = request_firmware(&fw, firmware_name, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		dev_err(dev, "unable to retrieve firmware %s: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 			firmware_name, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	error = i2c_smbus_write_byte_data(client, INT_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 					  COORD_UPDATE | CALIBRATION_DONE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 					  SLEEP_IN | SLEEP_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		if (retry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 			dev_warn(dev, "retrying firmware load\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 			/* settings for retry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 			error = i2c_smbus_write_byte_data(client, EX_WDAT, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 			if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		error = i2c_smbus_write_byte_data(client, EX_ADDR_H, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		error = i2c_smbus_write_byte_data(client, EX_ADDR_L, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		error = i2c_smbus_write_byte_data(client, COMMON_SETUP1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 						  COMMON_SETUP1_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		/* firmware load to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		len = fw->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		while (len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 			xfer_len = min(FIRMWARE_BLOCK_SIZE, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 			error = i2c_smbus_write_i2c_block_data(client, EX_WDAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 						xfer_len, &fw->data[offset]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 			if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 			len -= xfer_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 			offset += xfer_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		/* check firmware load result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		status = i2c_smbus_read_byte_data(client, INT_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 			error = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		/* clear all interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		error = i2c_smbus_write_byte_data(client, INT_CLEAR, 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		if (status == PROGRAM_LOAD_DONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	} while (++retry <= FIRMWARE_RETRY_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	error2 = i2c_smbus_write_byte_data(client, INT_MASK, INT_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	return error ? error : error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) static ssize_t swap_xy_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 			    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	struct rohm_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	return sprintf(buf, "%d\n", !!(ts->setup2 & SWAP_XY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) static ssize_t swap_xy_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			     const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	struct rohm_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	error = kstrtouint(buf, 0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	error = mutex_lock_interruptible(&ts->input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		ts->setup2 |= SWAP_XY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		ts->setup2 &= ~SWAP_XY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	if (ts->initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 						  ts->setup2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	mutex_unlock(&ts->input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	return error ? error : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) static ssize_t inv_x_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 			  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	struct rohm_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	return sprintf(buf, "%d\n", !!(ts->setup2 & INV_X));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) static ssize_t inv_x_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 			   const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	struct rohm_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	error = kstrtouint(buf, 0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	error = mutex_lock_interruptible(&ts->input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		ts->setup2 |= INV_X;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		ts->setup2 &= ~INV_X;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	if (ts->initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 		error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 						  ts->setup2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	mutex_unlock(&ts->input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	return error ? error : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) static ssize_t inv_y_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 			  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	struct rohm_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	return sprintf(buf, "%d\n", !!(ts->setup2 & INV_Y));
^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) static ssize_t inv_y_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			   const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	struct rohm_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	error = kstrtouint(buf, 0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	error = mutex_lock_interruptible(&ts->input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		ts->setup2 |= INV_Y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		ts->setup2 &= ~INV_Y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	if (ts->initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		error = i2c_smbus_write_byte_data(client, COMMON_SETUP2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 						  ts->setup2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	mutex_unlock(&ts->input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	return error ? error : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) static DEVICE_ATTR_RW(swap_xy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) static DEVICE_ATTR_RW(inv_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) static DEVICE_ATTR_RW(inv_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) static struct attribute *rohm_ts_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	&dev_attr_swap_xy.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	&dev_attr_inv_x.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	&dev_attr_inv_y.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) static const struct attribute_group rohm_ts_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	.attrs = rohm_ts_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) static int rohm_ts_device_init(struct i2c_client *client, u8 setup2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	disable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	 * Wait 200usec for reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	udelay(200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	/* Release analog reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	error = i2c_smbus_write_byte_data(client, SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 					  ANALOG_POWER_ON | CPU_POWER_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	/* Waiting for the analog warm-up, max. 200usec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	udelay(200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	/* clear all interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	error = i2c_smbus_write_byte_data(client, INT_CLEAR, 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	error = i2c_smbus_write_byte_data(client, EX_WDAT, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	error = i2c_smbus_write_byte_data(client, COMMON_SETUP1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	error = i2c_smbus_write_byte_data(client, COMMON_SETUP2, setup2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	error = i2c_smbus_write_byte_data(client, COMMON_SETUP3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 					  SEL_TBL_DEFAULT | EN_MULTI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	error = i2c_smbus_write_byte_data(client, THRESHOLD_GESTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 					  THRESHOLD_GESTURE_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	error = i2c_smbus_write_byte_data(client, INTERVAL_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 					  INTERVAL_TIME_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	error = i2c_smbus_write_byte_data(client, CPU_FREQ, CPU_FREQ_10MHZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	error = i2c_smbus_write_byte_data(client, PRM_SWOFF_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 					  PRM_SWOFF_TIME_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	error = i2c_smbus_write_byte_data(client, ADC_CTRL, ADC_DIV_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	error = i2c_smbus_write_byte_data(client, ADC_WAIT, ADC_WAIT_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	 * Panel setup, these values change with the panel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	error = i2c_smbus_write_byte_data(client, STEP_X, STEP_X_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	error = i2c_smbus_write_byte_data(client, STEP_Y, STEP_Y_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	error = i2c_smbus_write_byte_data(client, OFFSET_X, OFFSET_X_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	error = i2c_smbus_write_byte_data(client, OFFSET_Y, OFFSET_Y_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	error = i2c_smbus_write_byte_data(client, THRESHOLD_TOUCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 					  THRESHOLD_TOUCH_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	error = i2c_smbus_write_byte_data(client, EVR_XY, EVR_XY_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	error = i2c_smbus_write_byte_data(client, EVR_X, EVR_X_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	error = i2c_smbus_write_byte_data(client, EVR_Y, EVR_Y_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	/* Fixed value settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	error = i2c_smbus_write_byte_data(client, CALIBRATION_ADJUST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 					  CALIBRATION_ADJUST_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	error = i2c_smbus_write_byte_data(client, SWCONT, SWCONT_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	error = i2c_smbus_write_byte_data(client, TEST1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 					  DUALTOUCH_STABILIZE_ON |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 					  DUALTOUCH_REG_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	error = rohm_ts_load_firmware(client, BU21023_FIRMWARE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		dev_err(dev, "failed to load firmware: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		return error;
^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) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	 * Manual calibration results are not changed in same environment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	 * If the force calibration is performed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	 * the controller will not require calibration request interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	 * when the typical values are set to the calibration registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	error = i2c_smbus_write_byte_data(client, CALIBRATION_REG1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 					  CALIBRATION_REG1_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	error = i2c_smbus_write_byte_data(client, CALIBRATION_REG2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 					  CALIBRATION_REG2_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	error = i2c_smbus_write_byte_data(client, CALIBRATION_REG3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 					  CALIBRATION_REG3_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	error = i2c_smbus_write_byte_data(client, FORCE_CALIBRATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 					  FORCE_CALIBRATION_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	error = i2c_smbus_write_byte_data(client, FORCE_CALIBRATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 					  FORCE_CALIBRATION_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	/* Clear all interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	error = i2c_smbus_write_byte_data(client, INT_CLEAR, 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	/* Enable coordinates update interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	error = i2c_smbus_write_byte_data(client, INT_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 					  CALIBRATION_DONE | SLEEP_OUT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 					  SLEEP_IN | PROGRAM_LOAD_DONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	error = i2c_smbus_write_byte_data(client, ERR_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 					  PROGRAM_LOAD_ERR | CPU_TIMEOUT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 					  ADC_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	/* controller CPU power on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	error = i2c_smbus_write_byte_data(client, SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 					  ANALOG_POWER_ON | CPU_POWER_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	enable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) static int rohm_ts_power_off(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	error = i2c_smbus_write_byte_data(client, SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 					  ANALOG_POWER_ON | CPU_POWER_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 			"failed to power off device CPU: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	error = i2c_smbus_write_byte_data(client, SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 					  ANALOG_POWER_OFF | CPU_POWER_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 			"failed to power off the device: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) static int rohm_ts_open(struct input_dev *input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	struct rohm_ts_data *ts = input_get_drvdata(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	if (!ts->initialized) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		error = rohm_ts_device_init(client, ts->setup2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 			dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 				"device initialization failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		ts->initialized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) static void rohm_ts_close(struct input_dev *input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	struct rohm_ts_data *ts = input_get_drvdata(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	rohm_ts_power_off(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	ts->initialized = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) static int rohm_bu21023_i2c_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 				  const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	struct rohm_ts_data *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	if (!client->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		dev_err(dev, "IRQ is not assigned\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	if (!client->adapter->algo->master_xfer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		dev_err(dev, "I2C level transfers not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	/* Turn off CPU just in case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	error = rohm_ts_power_off(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	ts = devm_kzalloc(dev, sizeof(struct rohm_ts_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	if (!ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	ts->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	ts->setup2 = MAF_1SAMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	i2c_set_clientdata(client, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	input = devm_input_allocate_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	input->name = BU21023_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	input->open = rohm_ts_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	input->close = rohm_ts_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	ts->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	input_set_drvdata(input, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	input_set_abs_params(input, ABS_MT_POSITION_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 			     ROHM_TS_ABS_X_MIN, ROHM_TS_ABS_X_MAX, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	input_set_abs_params(input, ABS_MT_POSITION_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 			     ROHM_TS_ABS_Y_MIN, ROHM_TS_ABS_Y_MAX, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	error = input_mt_init_slots(input, MAX_CONTACTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 				    INPUT_MT_DIRECT | INPUT_MT_TRACK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 				    INPUT_MT_DROP_UNUSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		dev_err(dev, "failed to multi touch slots initialization\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	error = devm_request_threaded_irq(dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 					  NULL, rohm_ts_soft_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 					  IRQF_ONESHOT, client->name, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		dev_err(dev, "failed to request IRQ: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	error = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 		dev_err(dev, "failed to register input device: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	error = devm_device_add_group(dev, &rohm_ts_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 		dev_err(dev, "failed to create sysfs group: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) static const struct i2c_device_id rohm_bu21023_i2c_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	{ BU21023_NAME, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	{ /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) MODULE_DEVICE_TABLE(i2c, rohm_bu21023_i2c_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) static struct i2c_driver rohm_bu21023_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		.name = BU21023_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	.probe = rohm_bu21023_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	.id_table = rohm_bu21023_i2c_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) module_i2c_driver(rohm_bu21023_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) MODULE_DESCRIPTION("ROHM BU21023/24 Touchscreen driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) MODULE_AUTHOR("ROHM Co., Ltd.");