summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuper Liu <supercjliu@google.com>2023-04-06 05:19:59 +0000
committerSuper Liu <supercjliu@google.com>2023-04-06 08:02:57 +0000
commit136b2a450f13df6f5486358bae6c1497d888a92f (patch)
treed547eca0d281906fe93dd3ab505b31376f200ecd
parentfe7e78550d5de5b170a3daede6a460e5f6967511 (diff)
downloadgoodix_touch-136b2a450f13df6f5486358bae6c1497d888a92f.tar.gz
Revert^2 "touch/goodix: Initialize the devices by order"
d3fa652b8f9498486149a2b49cafcceba7358099 Change-Id: I978eecb7331229e4771f6ab7575c439279efad1d
-rw-r--r--goodix_brl_spi.c8
-rw-r--r--goodix_ts_core.c47
-rw-r--r--goodix_ts_core.h1
3 files changed, 53 insertions, 3 deletions
diff --git a/goodix_brl_spi.c b/goodix_brl_spi.c
index e3421b9..1d0b295 100644
--- a/goodix_brl_spi.c
+++ b/goodix_brl_spi.c
@@ -344,7 +344,6 @@ static int goodix_spi_probe(struct spi_device *spi)
dev_res = kzalloc(sizeof(*dev_res), GFP_KERNEL);
if (!dev_res)
return -ENOMEM;
- goodix_device_register(dev_res);
/* get ic type */
ret = goodix_get_ic_type(spi->dev.of_node, &dev_res->bus);
@@ -361,14 +360,19 @@ static int goodix_spi_probe(struct spi_device *spi)
}
dev_res->bus.write = goodix_spi_write;
+/* [GOOG]
+ * Move goodix_device_register() after `dev_res->bus.dev` assigned.
+ * This will help to set the `struct device *dev` early.
+ */
+ goodix_device_register(dev_res);
- /* [GOOG] */
dev_res->bus.rx_buf = kzalloc(SPI_PREALLOC_RX_BUF_SIZE, GFP_KERNEL);
dev_res->bus.tx_buf = kzalloc(SPI_PREALLOC_TX_BUF_SIZE, GFP_KERNEL);
if (!dev_res->bus.rx_buf || !dev_res->bus.tx_buf) {
ret = -ENOMEM;
goto err_pdev;
}
+/*~[GOOG] */
mutex_init(&dev_res->bus.mutex);
dev_res->bus.dma_mode_enabled = false;
diff --git a/goodix_ts_core.c b/goodix_ts_core.c
index 4ffc2fc..7f0c9b2 100644
--- a/goodix_ts_core.c
+++ b/goodix_ts_core.c
@@ -36,6 +36,39 @@ struct goodix_device_manager goodix_devices;
static const struct dev_pm_ops dev_pm_ops; /* [GOOG] */
+/*
+ * [GOOG]
+ * Wait device to complete the init stage2 by order.
+ */
+static void goodix_wait_for_init_stage2_start(struct goodix_ts_core *current_cd)
+{
+ struct goodix_device_resource *res, *next;
+ struct goodix_ts_core *cd;
+
+ if (!goodix_devices.initialized)
+ return;
+
+ if (list_empty(&goodix_devices.list))
+ return;
+
+ list_for_each_entry_safe(res, next, &goodix_devices.list, list) {
+ cd = &res->core_data;
+ if (res->id >= current_cd->pdev->id ||
+ cd->init_stage != CORE_INIT_STAGE1) {
+ continue;
+ }
+
+ /* Wait device to complete the init stage1 */
+ if (wait_for_completion_timeout(&cd->init_stage2_complete,
+ msecs_to_jiffies(2 * MSEC_PER_SEC)) == 0)
+ ts_info("device#%d wait device#%d timeout to complete init state2!",
+ current_cd->pdev->id, res->id);
+ else
+ ts_info("device#%d complete init stage2", res->id);
+ }
+}
+
+
static void goodix_device_manager_init(void)
{
if (goodix_devices.initialized)
@@ -59,14 +92,22 @@ static void goodix_device_manager_exit(void)
int goodix_device_register(struct goodix_device_resource *device)
{
+ u32 dev_id; /* [GOOG] */
+
if (!device)
return -ENXIO;
mutex_lock(&goodix_devices.mutex);
list_add(&device->list, &goodix_devices.list);
- device->id = goodix_devices.nums++;
+ dev_id = goodix_devices.nums++;
+ if (device->bus.dev) {
+ of_property_read_u32(device->bus.dev->of_node,
+ "goodix,dev-id", &dev_id); /* [GOOG] */
+ }
+ device->id = dev_id;
sprintf(device->name, "%s.%d", GOODIX_CORE_DRIVER_NAME, device->id);
mutex_unlock(&goodix_devices.mutex);
+ init_completion(&device->core_data.init_stage2_complete); /* [GOOG] */
ts_info("register device %s", device->name);
return 0;
@@ -2758,6 +2799,8 @@ static int goodix_later_init_thread(void *data)
struct goodix_ts_core *cd = data;
struct goodix_ts_hw_ops *hw_ops = cd->hw_ops;
+ goodix_wait_for_init_stage2_start(cd); /* [GOOG] */
+
/* step 1: read version */
ret = cd->hw_ops->read_version(cd, &cd->fw_version);
if (ret < 0) {
@@ -2809,6 +2852,8 @@ static int goodix_later_init_thread(void *data)
}
cd->init_stage = CORE_INIT_STAGE2;
+ complete_all(&cd->init_stage2_complete); /* [GOOG] */
+
return 0;
uninit_fw:
diff --git a/goodix_ts_core.h b/goodix_ts_core.h
index bb03a78..cfd7bca 100644
--- a/goodix_ts_core.h
+++ b/goodix_ts_core.h
@@ -843,6 +843,7 @@ struct goodix_ts_core {
s16 heatmap_diff[GOODIX_MAX_DRV_NUM * GOODIX_MAX_SEN_NUM];
s16 heatmap_selfdiff[GOODIX_MAX_DRV_NUM + GOODIX_MAX_SEN_NUM];
*/
+ struct completion init_stage2_complete;
struct touch_apis_data apis_data;
struct workqueue_struct *event_wq;
struct delayed_work monitor_gesture_work;