From 93f39379e683d49bb2bfcb6ec1d646322be0453c Mon Sep 17 00:00:00 2001 From: Fei Mao Date: Fri, 22 Jan 2021 19:32:35 +0800 Subject: [PATCH] input: touchscreen: focaltech: use proper dev When enable touch over SPI, choose the right device and avoid wrong pointers. Change-Id: I9198701fed915da22518430bba3c3cb1943f937e Signed-off-by: Fei Mao --- .../focaltech_touch/focaltech_core.c | 64 +++++++++++++------ .../focaltech_touch/focaltech_ex_fun.c | 44 ++----------- .../focaltech_touch/focaltech_i2c.c | 8 +-- 3 files changed, 53 insertions(+), 63 deletions(-) diff --git a/drivers/input/touchscreen/focaltech_touch/focaltech_core.c b/drivers/input/touchscreen/focaltech_touch/focaltech_core.c index 3a696b6f4c9d..911be28c23b6 100644 --- a/drivers/input/touchscreen/focaltech_touch/focaltech_core.c +++ b/drivers/input/touchscreen/focaltech_touch/focaltech_core.c @@ -152,7 +152,7 @@ static int fts_ts_populate_vm_info(struct fts_ts_data *fts_data) { int rc = 0; struct trusted_touch_vm_info *vm_info; - struct device_node *np = fts_data->client->dev.of_node; + struct device_node *np = fts_data->dev->of_node; int num_regs, num_sizes = 0; vm_info = kzalloc(sizeof(struct trusted_touch_vm_info), GFP_KERNEL); @@ -407,8 +407,12 @@ static void fts_ts_trusted_touch_tvm_vm_mode_enable(struct fts_ts_data *fts_data } fts_ts_trusted_touch_set_tvm_driver_state(fts_data, TVM_IOMEM_ACCEPTED); - /* Initiate i2c session on tvm */ - rc = pm_runtime_get_sync(fts_data->client->adapter->dev.parent); + /* Initiate session on tvm */ + if (fts_data->bus_type == BUS_TYPE_I2C) + rc = pm_runtime_get_sync(fts_data->client->adapter->dev.parent); + else + rc = pm_runtime_get_sync(fts_data->spi->master->dev.parent); + if (rc < 0) { pr_err("failed to get sync rc:%d\n", rc); goto acl_fail; @@ -581,7 +585,12 @@ static void fts_ts_trusted_touch_tvm_vm_mode_disable(struct fts_ts_data *fts_dat pr_debug("vm irq release succeded\n"); fts_release_all_finger(); - pm_runtime_put_sync(fts_data->client->adapter->dev.parent); + + if (fts_data->bus_type == BUS_TYPE_I2C) + pm_runtime_put_sync(fts_data->client->adapter->dev.parent); + else + pm_runtime_put_sync(fts_data->spi->master->dev.parent); + fts_ts_trusted_touch_set_tvm_driver_state(fts_data, TVM_I2C_SESSION_RELEASED); rc = fts_ts_vm_mem_release(fts_data); @@ -668,7 +677,10 @@ static void fts_ts_trusted_touch_abort_tvm(struct fts_ts_data *fts_data) case TVM_IOMEM_ACCEPTED: case TVM_IRQ_RELEASED: fts_release_all_finger(); - pm_runtime_put_sync(fts_data->client->adapter->dev.parent); + if (fts_data->bus_type == BUS_TYPE_I2C) + pm_runtime_put_sync(fts_data->client->adapter->dev.parent); + else + pm_runtime_put_sync(fts_data->spi->master->dev.parent); case TVM_I2C_SESSION_RELEASED: rc = fts_ts_vm_mem_release(fts_data); if (rc) @@ -779,30 +791,44 @@ static void fts_ts_clk_disable_unprepare(struct fts_ts_data *fts_data) static int fts_ts_bus_get(struct fts_ts_data *fts_data) { int rc = 0; + struct device *dev = NULL; cancel_work_sync(&fts_data->suspend_work); cancel_work_sync(&fts_data->resume_work); reinit_completion(&fts_data->trusted_touch_powerdown); fts_ts_enable_reg(fts_data, true); + + if (fts_data->bus_type == BUS_TYPE_I2C) + dev = fts_data->client->adapter->dev.parent; + else + dev = fts_data->spi->master->dev.parent; + mutex_lock(&fts_data->fts_clk_io_ctrl_mutex); - rc = pm_runtime_get_sync(fts_data->client->adapter->dev.parent); + rc = pm_runtime_get_sync(dev); if (rc >= 0 && fts_data->core_clk != NULL && fts_data->iface_clk != NULL) { rc = fts_ts_clk_prepare_enable(fts_data); if (rc) - pm_runtime_put_sync( - fts_data->client->adapter->dev.parent); + pm_runtime_put_sync(dev); } + mutex_unlock(&fts_data->fts_clk_io_ctrl_mutex); return rc; } static void fts_ts_bus_put(struct fts_ts_data *fts_data) { + struct device *dev = NULL; + + if (fts_data->bus_type == BUS_TYPE_I2C) + dev = fts_data->client->adapter->dev.parent; + else + dev = fts_data->spi->master->dev.parent; + mutex_lock(&fts_data->fts_clk_io_ctrl_mutex); if (fts_data->core_clk != NULL && fts_data->iface_clk != NULL) fts_ts_clk_disable_unprepare(fts_data); - pm_runtime_put_sync(fts_data->client->adapter->dev.parent); + pm_runtime_put_sync(dev); mutex_unlock(&fts_data->fts_clk_io_ctrl_mutex); complete(&fts_data->trusted_touch_powerdown); fts_ts_enable_reg(fts_data, false); @@ -1088,7 +1114,7 @@ int fts_ts_handle_trusted_touch_pvm(struct fts_ts_data *fts_data, int value) static void fts_ts_trusted_touch_event_notify(struct fts_ts_data *fts_data, int event) { atomic_set(&fts_data->trusted_touch_event, event); - sysfs_notify(&fts_data->client->dev.kobj, NULL, "trusted_touch_event"); + sysfs_notify(&fts_data->dev->kobj, NULL, "trusted_touch_event"); } static void fts_ts_trusted_touch_abort_handler(struct fts_ts_data *fts_data, int error) @@ -1154,7 +1180,7 @@ fail: static void fts_ts_dt_parse_trusted_touch_info(struct fts_ts_data *fts_data) { - struct device_node *np = fts_data->client->dev.of_node; + struct device_node *np = fts_data->dev->of_node; int rc = 0; const char *selection; const char *environment; @@ -1162,7 +1188,7 @@ static void fts_ts_dt_parse_trusted_touch_info(struct fts_ts_data *fts_data) rc = of_property_read_string(np, "focaltech,trusted-touch-mode", &selection); if (rc) { - dev_warn(&fts_data->client->dev, + dev_warn(fts_data->dev, "%s: No trusted touch mode selection made\n", __func__); atomic_set(&fts_data->trusted_touch_mode, TRUSTED_TOUCH_MODE_NONE); @@ -1182,7 +1208,7 @@ static void fts_ts_dt_parse_trusted_touch_info(struct fts_ts_data *fts_data) rc = of_property_read_string(np, "focaltech,touch-environment", &environment); if (rc) { - dev_warn(&fts_data->client->dev, + dev_warn(fts_data->dev, "%s: No trusted touch mode environment\n", __func__); } fts_data->touch_environment = environment; @@ -1204,19 +1230,19 @@ static void fts_ts_trusted_touch_init(struct fts_ts_data *fts_data) init_completion(&fts_data->trusted_touch_powerdown); /* Get clocks */ - fts_data->core_clk = devm_clk_get(fts_data->client->dev.parent, + fts_data->core_clk = devm_clk_get(fts_data->dev->parent, "m-ahb"); if (IS_ERR(fts_data->core_clk)) { fts_data->core_clk = NULL; - dev_warn(&fts_data->client->dev, + dev_warn(fts_data->dev, "%s: core_clk is not defined\n", __func__); } - fts_data->iface_clk = devm_clk_get(fts_data->client->dev.parent, + fts_data->iface_clk = devm_clk_get(fts_data->dev->parent, "se-clk"); if (IS_ERR(fts_data->iface_clk)) { fts_data->iface_clk = NULL; - dev_warn(&fts_data->client->dev, + dev_warn(fts_data->dev, "%s: iface_clk is not defined\n", __func__); } @@ -2914,7 +2940,8 @@ static int fts_ts_resume(struct device *dev) return 0; } -#ifdef CONFIG_ST_TRUSTED_TOUCH +#ifdef CONFIG_FTS_TRUSTED_TOUCH + if (atomic_read(&ts_data->trusted_touch_underway)) wait_for_completion_interruptible( &ts_data->trusted_touch_powerdown); @@ -3114,7 +3141,6 @@ static void __exit fts_ts_i2c_exit(void) i2c_del_driver(&fts_ts_i2c_driver); } - static int fts_ts_spi_probe(struct spi_device *spi) { int ret = 0; diff --git a/drivers/input/touchscreen/focaltech_touch/focaltech_ex_fun.c b/drivers/input/touchscreen/focaltech_touch/focaltech_ex_fun.c index f04ce3407518..902fbc37810a 100644 --- a/drivers/input/touchscreen/focaltech_touch/focaltech_ex_fun.c +++ b/drivers/input/touchscreen/focaltech_touch/focaltech_ex_fun.c @@ -1071,17 +1071,7 @@ static ssize_t fts_log_level_store( static ssize_t trusted_touch_enable_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct i2c_client *client = to_i2c_client(dev); - struct fts_ts_data *info; - - if (!client) - return scnprintf(buf, PAGE_SIZE, "client is null\n"); - - info = i2c_get_clientdata(client); - if (!info) { - FTS_ERROR("info is null\n"); - return scnprintf(buf, PAGE_SIZE, "info is null\n"); - } + struct fts_ts_data *info = fts_data; return scnprintf(buf, PAGE_SIZE, "%d", atomic_read(&info->trusted_touch_enabled)); @@ -1090,18 +1080,10 @@ static ssize_t trusted_touch_enable_show(struct device *dev, static ssize_t trusted_touch_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct fts_ts_data *info; + struct fts_ts_data *info = fts_data; unsigned long value; int err = 0; - if (!client) - return -EIO; - info = i2c_get_clientdata(client); - if (!info) { - FTS_ERROR("info is null\n"); - return -EIO; - } if (count > 2) return -EINVAL; err = kstrtoul(buf, 10, &value); @@ -1131,17 +1113,7 @@ static ssize_t trusted_touch_enable_store(struct device *dev, static ssize_t trusted_touch_event_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct i2c_client *client = to_i2c_client(dev); - struct fts_ts_data *info; - - if (!client) - return scnprintf(buf, PAGE_SIZE, "client is null\n"); - - info = i2c_get_clientdata(client); - if (!info) { - FTS_ERROR("info is null\n"); - return scnprintf(buf, PAGE_SIZE, "info is null\n"); - } + struct fts_ts_data *info = fts_data; return scnprintf(buf, PAGE_SIZE, "%d", atomic_read(&info->trusted_touch_event)); @@ -1150,18 +1122,10 @@ static ssize_t trusted_touch_event_show(struct device *dev, static ssize_t trusted_touch_event_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct fts_ts_data *info; + struct fts_ts_data *info = fts_data; unsigned long value; int err = 0; - if (!client) - return -EIO; - info = i2c_get_clientdata(client); - if (!info) { - FTS_ERROR("info is null\n"); - return -EIO; - } if (count > 2) return -EINVAL; diff --git a/drivers/input/touchscreen/focaltech_touch/focaltech_i2c.c b/drivers/input/touchscreen/focaltech_touch/focaltech_i2c.c index 7240ea24d243..8d439d3ac7d3 100644 --- a/drivers/input/touchscreen/focaltech_touch/focaltech_i2c.c +++ b/drivers/input/touchscreen/focaltech_touch/focaltech_i2c.c @@ -102,7 +102,7 @@ static int fts_i2c_read(u8 *cmd, u32 cmdlen, u8 *data, u32 datalen) for (i = 0; i < I2C_RETRY_NUMBER; i++) { ret = i2c_transfer(ts_data->client->adapter, msg, msg_num); if (ret < 0) { -#ifdef CONFIG_ST_TRUSTED_TOUCH +#ifdef CONFIG_FTS_TRUSTED_TOUCH #ifdef CONFIG_ARCH_QTI_VM if (atomic_read(&ts_data->trusted_touch_enabled) && ret == -ECONNRESET) { @@ -122,7 +122,7 @@ static int fts_i2c_read(u8 *cmd, u32 cmdlen, u8 *data, u32 datalen) } if (ret < 0) { -#ifdef CONFIG_ST_TRUSTED_TOUCH +#ifdef CONFIG_FTS_TRUSTED_TOUCH #ifdef CONFIG_ARCH_QTI_VM pr_err("initiating abort due to i2c xfer failure\n"); fts_ts_trusted_touch_tvm_i2c_failure_report(ts_data); @@ -156,7 +156,7 @@ static int fts_i2c_write(u8 *writebuf, u32 writelen) for (i = 0; i < I2C_RETRY_NUMBER; i++) { ret = i2c_transfer(ts_data->client->adapter, &msgs, 1); if (ret < 0) { -#ifdef CONFIG_ST_TRUSTED_TOUCH +#ifdef CONFIG_FTS_TRUSTED_TOUCH #ifdef CONFIG_ARCH_QTI_VM if (atomic_read(&ts_data->trusted_touch_enabled) && ret == -ECONNRESET){ @@ -175,7 +175,7 @@ static int fts_i2c_write(u8 *writebuf, u32 writelen) } if (ret < 0) { -#ifdef CONFIG_ST_TRUSTED_TOUCH +#ifdef CONFIG_FTS_TRUSTED_TOUCH #ifdef CONFIG_ARCH_QTI_VM pr_err("initiating abort due to i2c xfer failure\n"); fts_ts_trusted_touch_tvm_i2c_failure_report(ts_data);