···203203 * and the irq configuration should be set to Falling Edge Trigger204204 */205205/* Control IRQ / Polling option */206206-static int polling_req;206206+static bool polling_req;207207module_param(polling_req, bool, 0444);208208MODULE_PARM_DESC(polling_req, "Request Polling. Default = 0 (use irq)");209209···217217 struct i2c_client *client;218218 struct input_dev *input;219219 struct delayed_work dwork;220220+ spinlock_t lock;220221 int no_data_count;221222 int no_decel_param;222223 int reduce_report_param;···367366 return xy_delta || gesture;368367}369368369369+static void synaptics_i2c_reschedule_work(struct synaptics_i2c *touch,370370+ unsigned long delay)371371+{372372+ unsigned long flags;373373+374374+ spin_lock_irqsave(&touch->lock, flags);375375+376376+ /*377377+ * If work is already scheduled then subsequent schedules will not378378+ * change the scheduled time that's why we have to cancel it first.379379+ */380380+ __cancel_delayed_work(&touch->dwork);381381+ schedule_delayed_work(&touch->dwork, delay);382382+383383+ spin_unlock_irqrestore(&touch->lock, flags);384384+}385385+370386static irqreturn_t synaptics_i2c_irq(int irq, void *dev_id)371387{372388 struct synaptics_i2c *touch = dev_id;373389374374- /*375375- * We want to have the work run immediately but it might have376376- * already been scheduled with a delay, that's why we have to377377- * cancel it first.378378- */379379- cancel_delayed_work(&touch->dwork);380380- schedule_delayed_work(&touch->dwork, 0);390390+ synaptics_i2c_reschedule_work(touch, 0);381391382392 return IRQ_HANDLED;383393}···464452 * We poll the device once in THREAD_IRQ_SLEEP_SECS and465453 * if error is detected, we try to reset and reconfigure the touchpad.466454 */467467- schedule_delayed_work(&touch->dwork, delay);455455+ synaptics_i2c_reschedule_work(touch, delay);468456}469457470458static int synaptics_i2c_open(struct input_dev *input)···477465 return ret;478466479467 if (polling_req)480480- schedule_delayed_work(&touch->dwork,481481- msecs_to_jiffies(NO_DATA_SLEEP_MSECS));468468+ synaptics_i2c_reschedule_work(touch,469469+ msecs_to_jiffies(NO_DATA_SLEEP_MSECS));482470483471 return 0;484472}···533521 touch->scan_rate_param = scan_rate;534522 set_scan_rate(touch, scan_rate);535523 INIT_DELAYED_WORK(&touch->dwork, synaptics_i2c_work_handler);524524+ spin_lock_init(&touch->lock);536525537526 return touch;538527}···548535 if (!touch)549536 return -ENOMEM;550537551551- i2c_set_clientdata(client, touch);552552-553538 ret = synaptics_i2c_reset_config(client);554539 if (ret)555540 goto err_mem_free;556541557542 if (client->irq < 1)558558- polling_req = 1;543543+ polling_req = true;559544560545 touch->input = input_allocate_device();561546 if (!touch->input) {···574563 dev_warn(&touch->client->dev,575564 "IRQ request failed: %d, "576565 "falling back to polling\n", ret);577577- polling_req = 1;566566+ polling_req = true;578567 synaptics_i2c_reg_set(touch->client,579568 INTERRUPT_EN_REG, 0);580569 }···591580 "Input device register failed: %d\n", ret);592581 goto err_input_free;593582 }583583+584584+ i2c_set_clientdata(client, touch);585585+594586 return 0;595587596588err_input_free:597589 input_free_device(touch->input);598590err_mem_free:599599- i2c_set_clientdata(client, NULL);600591 kfree(touch);601592602593 return ret;···609596 struct synaptics_i2c *touch = i2c_get_clientdata(client);610597611598 if (!polling_req)612612- free_irq(touch->client->irq, touch);599599+ free_irq(client->irq, touch);613600614601 input_unregister_device(touch->input);615602 i2c_set_clientdata(client, NULL);···640627 if (ret)641628 return ret;642629643643- schedule_delayed_work(&touch->dwork,644644- msecs_to_jiffies(NO_DATA_SLEEP_MSECS));630630+ synaptics_i2c_reschedule_work(touch,631631+ msecs_to_jiffies(NO_DATA_SLEEP_MSECS));645632646633 return 0;647634}