From patchwork Sun Oct 9 20:12:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Assenat X-Patchwork-Id: 9368653 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 87CB1607D2 for ; Sun, 9 Oct 2016 20:12:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69E1928B16 for ; Sun, 9 Oct 2016 20:12:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48C1D28B64; Sun, 9 Oct 2016 20:12:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21BD428B16 for ; Sun, 9 Oct 2016 20:12:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751601AbcJIUMc (ORCPT ); Sun, 9 Oct 2016 16:12:32 -0400 Received: from mout.perfora.net ([74.208.4.194]:51271 "EHLO mout.perfora.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751066AbcJIUMb (ORCPT ); Sun, 9 Oct 2016 16:12:31 -0400 Received: from yggdrasil2.lan.raphnet.net ([24.201.146.26]) by mrelay.perfora.net (mreueus002) with ESMTPSA (Nemesis) id 0M10GX-1b160X1m8d-00v6ac for ; Sun, 09 Oct 2016 22:12:30 +0200 Received: from raph by yggdrasil2.lan.raphnet.net with local (Exim 4.72) (envelope-from ) id 1btKSS-0006zR-Qp for linux-input@vger.kernel.org; Sun, 09 Oct 2016 16:12:28 -0400 Date: Sun, 9 Oct 2016 16:12:28 -0400 From: Raphael Assenat To: linux-input@vger.kernel.org Subject: [PATCH] Initialize axis values in joydev_open_device() Message-ID: <20161009201228.GT24360@yggdrasil2.lan.raphnet.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-Provags-ID: V03:K0:SwrIJoVeuLwF7aD0M1GCoKYzR7NML6Yz1pwFl+pv45agQpXiFP/ HR8ErEblaxIU+pb3JUTZ0LLzg5F6pMFy0WZ1tB+sT0Ny0ej/K1HR4bOql/GLY0OKo0fMYfE y+IqqmXnwqynVlKAADSQV97shQuMiMPYjmXZj6OCO0oJV+Kc+4ZXAHmFBc93c9BWYEmA8nq 3bBEsiwQ8fmeMvmp5sZtA== X-UI-Out-Filterresults: notjunk:1; V01:K0:RpIWXd8qZxQ=:SqRJaFJZw7NBC48OpT0OPv jqh9NqQZvNJRgxzyUBdPR9Jqw3b3Xx3y+f0R6z76UTvWO8Y9FR8nm/8VxR0Sm2vryfCMDDB0p f0sKt7ApujnGZ79s8tJBxV9D0F9n4g9ZU1IZvBKWxEHT8WdLnDHNc685iDMKunrFDpdz9vhGD cV5ePyCDmMYK4PNQdFwWuMYvMSRZ4zi4jfsxGGC1RXZMh3acqNxpUbpUAnVSrOD5Q+Jnf4rA7 FJ19Vrujy3V0PprjzFwRJdyxdpfMpDNu3kZ7CSEofqWjaA5thlZqwxSWFvGzKspEQNxYtad81 phCZsBd+ygnYBTRzXXvGq0uBw2xTY5eaedPMhsZpDoVPNfUrMRrgTCSUDKfnD70j2NqVZW7wf jHQ9PBX+brK71R/DuKuIRo4hZa22KFcE9pwKBHOvxdOnJwaQLkTqKNg8wzJMxN2vQQtY2bp5y jbQQ1i9pyOENuYcsaRgbEDLztQtM3j49wCEjPipKdhCNHAe6fslK11e+fBS/1fJUkBDjhQ9N8 52EcIK7EKB5gDTY6v0coE50JA5VUN2u3q14kwI19CczgWwcWWo6i4rTppi/ZbOl6Xtc2qgFax jD/s7r0JBI0AKKD9BIA2tmNUlX0MzHyp4maMDtFeoZhT5IxFBzco/OkS9wxmaTVnj/dOWWJTv 6y8GAq5JrZm90akj22TksH0f6eCp19IC4tdK1RaNzq1L22THBSPOlsnOZezlHaj2JysU= Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Postpone axis initialization to the first open instead of doing it once in joydev_connect. This is to make sure the generated startup events are representative of the current joystick state rather than what it was when joydev_connect() was called, potentially much earlier. Signed-off-by: Raphael Assenat --- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c index 5d11fea..5b42e5a 100644 --- a/drivers/input/joydev.c +++ b/drivers/input/joydev.c @@ -156,6 +156,38 @@ static void joydev_event(struct input_handle *handle, wake_up_interruptible(&joydev->wait); } +static void joydev_refresh_state(struct joydev *joydev) +{ + struct input_dev *dev = joydev->handle.dev; + int i, j, t; + + for (i = 0; i < joydev->nabs; i++) { + j = joydev->abspam[i]; + if (input_abs_get_max(dev, j) == input_abs_get_min(dev, j)) { + joydev->corr[i].type = JS_CORR_NONE; + joydev->abs[i] = input_abs_get_val(dev, j); + continue; + } + joydev->corr[i].type = JS_CORR_BROKEN; + joydev->corr[i].prec = input_abs_get_fuzz(dev, j); + + t = (input_abs_get_max(dev, j) + input_abs_get_min(dev, j)) / 2; + joydev->corr[i].coef[0] = t - input_abs_get_flat(dev, j); + joydev->corr[i].coef[1] = t + input_abs_get_flat(dev, j); + + t = (input_abs_get_max(dev, j) - input_abs_get_min(dev, j)) / 2 + - 2 * input_abs_get_flat(dev, j); + if (t) { + joydev->corr[i].coef[2] = (1 << 29) / t; + joydev->corr[i].coef[3] = (1 << 29) / t; + + joydev->abs[i] = + joydev_correct(input_abs_get_val(dev, j), + joydev->corr + i); + } + } +} + static int joydev_fasync(int fd, struct file *file, int on) { struct joydev_client *client = file->private_data; @@ -202,6 +234,8 @@ static int joydev_open_device(struct joydev *joydev) retval = input_open_device(&joydev->handle); if (retval) joydev->open--; + else + joydev_refresh_state(joydev); } mutex_unlock(&joydev->mutex); @@ -816,7 +850,7 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id) { struct joydev *joydev; - int i, j, t, minor, dev_no; + int i, minor, dev_no; int error; minor = input_get_new_minor(JOYDEV_MINOR_BASE, JOYDEV_MINORS, true); @@ -869,31 +903,7 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev, joydev->nkey++; } - for (i = 0; i < joydev->nabs; i++) { - j = joydev->abspam[i]; - if (input_abs_get_max(dev, j) == input_abs_get_min(dev, j)) { - joydev->corr[i].type = JS_CORR_NONE; - joydev->abs[i] = input_abs_get_val(dev, j); - continue; - } - joydev->corr[i].type = JS_CORR_BROKEN; - joydev->corr[i].prec = input_abs_get_fuzz(dev, j); - - t = (input_abs_get_max(dev, j) + input_abs_get_min(dev, j)) / 2; - joydev->corr[i].coef[0] = t - input_abs_get_flat(dev, j); - joydev->corr[i].coef[1] = t + input_abs_get_flat(dev, j); - - t = (input_abs_get_max(dev, j) - input_abs_get_min(dev, j)) / 2 - - 2 * input_abs_get_flat(dev, j); - if (t) { - joydev->corr[i].coef[2] = (1 << 29) / t; - joydev->corr[i].coef[3] = (1 << 29) / t; - - joydev->abs[i] = - joydev_correct(input_abs_get_val(dev, j), - joydev->corr + i); - } - } + joydev_refresh_state(joydev); joydev->dev.devt = MKDEV(INPUT_MAJOR, minor); joydev->dev.class = &input_class;