sm8350-common: vibrator: Add logic to detect QTI haptics device

Check input device name to make sure a real QTI vibrator device is
detected instead of other input FF device with the same capability
being recognized wrongly as a QTI vibrator.

Change-Id: I54f00e777212b3bd19088faa183b0ff41019dfcc
This commit is contained in:
Fenglin Wu 2021-04-16 08:54:40 +08:00 committed by LuK1337
parent 298c65026f
commit 226203e348

View file

@ -53,7 +53,8 @@ namespace vibrator {
#define MEDIUM_MAGNITUDE 0x5fff #define MEDIUM_MAGNITUDE 0x5fff
#define LIGHT_MAGNITUDE 0x3fff #define LIGHT_MAGNITUDE 0x3fff
#define INVALID_VALUE -1 #define INVALID_VALUE -1
#define CUSTOM_DATA_LEN 3 #define CUSTOM_DATA_LEN 3
#define NAME_BUF_SIZE 32
#define MSM_CPU_LAHAINA 415 #define MSM_CPU_LAHAINA 415
#define APQ_CPU_LAHAINA 439 #define APQ_CPU_LAHAINA 439
@ -121,6 +122,7 @@ InputFFDevice::InputFFDevice()
uint8_t ffBitmask[FF_CNT / 8]; uint8_t ffBitmask[FF_CNT / 8];
char devicename[PATH_MAX]; char devicename[PATH_MAX];
const char *INPUT_DIR = "/dev/input/"; const char *INPUT_DIR = "/dev/input/";
char name[NAME_BUF_SIZE];
int fd, ret; int fd, ret;
int soc = property_get_int32("ro.vendor.qti.soc_id", -1); int soc = property_get_int32("ro.vendor.qti.soc_id", -1);
@ -152,6 +154,20 @@ InputFFDevice::InputFFDevice()
continue; continue;
} }
ret = TEMP_FAILURE_RETRY(ioctl(fd, EVIOCGNAME(sizeof(name)), name));
if (ret == -1) {
ALOGE("get input device name %s failed, errno = %d\n", devicename, errno);
close(fd);
continue;
}
if (strcmp(name, "qcom-hv-haptics") && strcmp(name, "qti-haptics")) {
ALOGD("not a qcom/qti haptics device\n");
close(fd);
continue;
}
ALOGI("%s is detected at %s\n", name, devicename);
ret = TEMP_FAILURE_RETRY(ioctl(fd, EVIOCGBIT(EV_FF, sizeof(ffBitmask)), ffBitmask)); ret = TEMP_FAILURE_RETRY(ioctl(fd, EVIOCGBIT(EV_FF, sizeof(ffBitmask)), ffBitmask));
if (ret == -1) { if (ret == -1) {
ALOGE("ioctl failed, errno = %d", errno); ALOGE("ioctl failed, errno = %d", errno);