From patchwork Sat Feb 2 15:18:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pawe=C5=82_Chmiel?= X-Patchwork-Id: 10794335 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 89C9413BF for ; Sat, 2 Feb 2019 15:18:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B0D03012E for ; Sat, 2 Feb 2019 15:18:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F6F03013F; Sat, 2 Feb 2019 15:18:45 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 0046E3012E for ; Sat, 2 Feb 2019 15:18:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728052AbfBBPSP (ORCPT ); Sat, 2 Feb 2019 10:18:15 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:42713 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727974AbfBBPSP (ORCPT ); Sat, 2 Feb 2019 10:18:15 -0500 Received: by mail-lj1-f194.google.com with SMTP id l15-v6so8259608lja.9; Sat, 02 Feb 2019 07:18:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NM8+91JdLr+V8EUKlKWq7jbt+WdAKn3F2/NnaalcLGQ=; b=MT09cRHHEtVHU4sIS89bhCnLOq/o5fw150K04EhfB8cT7ua7aZG+V8tRH8wJPgbhPy DVyvudb1ZrDhSMmdBaXlYviZK6W/PHm5iemQKwJJe/+d2csZE0tKsDCJ/T5niPdW8jTT TRNObAe3Rd2RojJijawqStc2xcYEVrIhDM+M+9avmBClrPfPAWwhHBhasPqyuVwNA6ZA SUXGUV1Ej9d942MHMfZ7qNXDPUmgLXiCZTweS7l0t+X8Sm4wdJfWWRqjejZu3x3tvhlc rwmYAxga3Yx3kYYmqLQPuYfcGUgqZY62sRqFqE2piP6CBZxR6KePqXoydGY/dKvelFEB a15g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NM8+91JdLr+V8EUKlKWq7jbt+WdAKn3F2/NnaalcLGQ=; b=GZJ337QKqcdSGCWbsh1XRc1US7W56WydaNRzaoUhe7ngRsaBtQoPGH4auMGlQzuDdT OBd1/N0J6JHTirkO5PbRYtnWHBEIRF1Fo7cLuTiO/lo2u3Faj+Imcgq0Kbfg9As8fj0P SzSr1zwOX/X+3psrR7QvbKx9PMlTP0/WgOTsqo8nSM6pDIkN2dHvNG8BYXQ+Wsa8GY9i +C2yQ5SUUnu5m8PJAOq46mD1YMIxIJn32FttcAB2nrnhlzaLTAdLAKP1EBuHQ6CI/c8t BFKaidaqO/ATYmRcQA4JeNPWntCC4g2O0cjilJhK3xtmBl22z8eKbzppL1KZU0ILfTso 0QPg== X-Gm-Message-State: AJcUukfxv4SOZdBumUxtO/9Xq2DBO4EHFxIAj9mdyKBgjIwrr9SLC14f dlQUOfqTCcgpi1Qj9UgVEAUuDZVg X-Google-Smtp-Source: ALg8bN50qIhktagaEu1zM46IVWljVr5osKjCbau1BwCKQjWT16eY37pCI8drUxWa7yXFBo436r8sHw== X-Received: by 2002:a2e:91c1:: with SMTP id u1-v6mr31712366ljg.188.1549120691688; Sat, 02 Feb 2019 07:18:11 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:6cb2:9e25:2436:6eda]) by smtp.googlemail.com with ESMTPSA id l21-v6sm1863245ljj.48.2019.02.02.07.18.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 07:18:11 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: dmitry.torokhov@gmail.com Cc: robh+dt@kernel.org, mark.rutland@arm.com, pawel.mikolaj.chmiel@gmail.com, xc-racer2@live.ca, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/5] dt-bindings: input: Add binding for bma150 sensor Date: Sat, 2 Feb 2019 16:18:02 +0100 Message-Id: <20190202151806.9064-2-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190202151806.9064-1-pawel.mikolaj.chmiel@gmail.com> References: <20190202151806.9064-1-pawel.mikolaj.chmiel@gmail.com> MIME-Version: 1.0 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 From: Jonathan Bakker Add device tree bindings for Bosch BMA150 Accelerometer Sensor Changes from v1: - Add properties for all of bma150_cfg - Correct IRQ type in example Signed-off-by: Jonathan Bakker Signed-off-by: Paweł Chmiel --- .../bindings/input/bosch,bma150.txt | 38 +++++++++++++++++++ include/dt-bindings/input/bma150.h | 22 +++++++++++ include/linux/bma150.h | 13 +------ 3 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 Documentation/devicetree/bindings/input/bosch,bma150.txt create mode 100644 include/dt-bindings/input/bma150.h diff --git a/Documentation/devicetree/bindings/input/bosch,bma150.txt b/Documentation/devicetree/bindings/input/bosch,bma150.txt new file mode 100644 index 000000000000..f644d132f79c --- /dev/null +++ b/Documentation/devicetree/bindings/input/bosch,bma150.txt @@ -0,0 +1,38 @@ +* Bosch BMA150 Accelerometer Sensor + +Also works for the SMB380 and BMA023 accelerometers + +Required properties: +- compatible : Should be "bosch,bma150" +- reg : The I2C address of the sensor + +Optional properties: +- interrupt-parent : should be the phandle for the interrupt controller +- interrupts : Interrupt mapping for IRQ. If not present device will be polled +- any-motion-int : bool for if the any motion interrupt should be enabled +- hg-int : bool for if the high-G interrupt should be enabled +- lg-int : bool for if the low-G interrupt should be enabled +- any-motion-cfg : array of integers for any motion duration and threshold +- hg-cfg : array of integers for high-G hysterisis, duration, and threshold +- lg-cfg : array of integers for low-G hysterisis, duration, and threshold +- range : configuration of range, one of BMA150_RANGE_* as defined in [1] +- bandwidth : refresh rate of device, one of BMA150_BW_* as defined in [1] + +Example: + +bma150@38 { + compatible = "bosch,bma150"; + reg = <0x38>; + interrupt-parent = <&gph0>; + interrupts = <1 IRQ_TYPE_EDGE_RISING>; + any-motion-int; + hg-int; + lg-int; + any-motion-cfg = <0 0>; + hg-cfg = <0 150 160>; + lg-cfg = <0 150 20>; + range = ; + bandwidth = ; +}; + +[1] include/dt-bindings/input/bma150.h diff --git a/include/dt-bindings/input/bma150.h b/include/dt-bindings/input/bma150.h new file mode 100644 index 000000000000..fb38ca787f0f --- /dev/null +++ b/include/dt-bindings/input/bma150.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * This header provides bindings for the BMA150 accelerometer + */ +#ifndef _DT_BINDINGS_INPUT_BMA150_H +#define _DT_BINDINGS_INPUT_BMA150_H + +/* Range */ +#define BMA150_RANGE_2G 0 +#define BMA150_RANGE_4G 1 +#define BMA150_RANGE_8G 2 + +/* Refresh rate */ +#define BMA150_BW_25HZ 0 +#define BMA150_BW_50HZ 1 +#define BMA150_BW_100HZ 2 +#define BMA150_BW_190HZ 3 +#define BMA150_BW_375HZ 4 +#define BMA150_BW_750HZ 5 +#define BMA150_BW_1500HZ 6 + +#endif /* _DT_BINDINGS_INPUT_BMA150_H */ diff --git a/include/linux/bma150.h b/include/linux/bma150.h index 97ade7cdc870..b85266a9c35c 100644 --- a/include/linux/bma150.h +++ b/include/linux/bma150.h @@ -20,19 +20,10 @@ #ifndef _BMA150_H_ #define _BMA150_H_ -#define BMA150_DRIVER "bma150" +#include -#define BMA150_RANGE_2G 0 -#define BMA150_RANGE_4G 1 -#define BMA150_RANGE_8G 2 +#define BMA150_DRIVER "bma150" -#define BMA150_BW_25HZ 0 -#define BMA150_BW_50HZ 1 -#define BMA150_BW_100HZ 2 -#define BMA150_BW_190HZ 3 -#define BMA150_BW_375HZ 4 -#define BMA150_BW_750HZ 5 -#define BMA150_BW_1500HZ 6 struct bma150_cfg { bool any_motion_int; /* Set to enable any-motion interrupt */ From patchwork Sat Feb 2 15:18:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pawe=C5=82_Chmiel?= X-Patchwork-Id: 10794333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA6F713BF for ; Sat, 2 Feb 2019 15:18:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA5853012E for ; Sat, 2 Feb 2019 15:18:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE46F3013F; Sat, 2 Feb 2019 15:18:42 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 42E7E3012E for ; Sat, 2 Feb 2019 15:18:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728104AbfBBPSQ (ORCPT ); Sat, 2 Feb 2019 10:18:16 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:37062 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728053AbfBBPSQ (ORCPT ); Sat, 2 Feb 2019 10:18:16 -0500 Received: by mail-lj1-f194.google.com with SMTP id t18-v6so8309721ljd.4; Sat, 02 Feb 2019 07:18:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9XW8JHW2HMbnk4KsLSLzGop36qwVdtujfqQY6TQl2+I=; b=McbOK6zBwtCf8cTjIBRcBTLAl51psFnrnQXdF0/qtjdggbSzOmm1pvcDvB85hqqSHf Ot2Jak4k3ffEzZNe/O2TpE0Lf9Iui3AK59GBBsYvXzAQSmdJWq3ef/kiaXT4jC6uW4HM WF37g7LHMJhrZpwYDFL8soVqxLBHGdaaOGNp4C1ZRH2VjNg6IXqcLfz4qOjQs1/DeW8y wkSOoJsmlk/pbfCHqfTjtRhlv6GQwZLKWU+YWDYDGYqvIfSYhSFRMHyFqxk7Lfxi2b+i tsbUOLGaVmOZH7GbHHLJ1VVCYrryHsjfuV12aHeXCR42LjTC6qutvbJGbOIXGo2t05qr gFLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9XW8JHW2HMbnk4KsLSLzGop36qwVdtujfqQY6TQl2+I=; b=FnO3+TNx+Jctu5zs5KCZSjGl6YvewV5dmMAziylvl/JBaN4DDBIZI6obdu/lPro7YD xsEwWpdotJlAcdo4yIIRMAnNwP3H9Z+AU3yLIb8DmWyNfPyOgEvKEXWFI/BGvUP5ztl4 nGd5nSri0B0l4kerHmbanULvsAlTdlWnar+HjlhosmVLayjdWUhhmFqTzlVpj/6kB19Q b4cvN4z6uPuCagcVaLTSQXG3e8+vtRmz8JEiwix81R1V8L5CI+C3O0+cdwPU8mCV2WF/ Q3FAqiOvGSMu+14wy6oqeptZ+h134pS2AFyJJH54RNSlUFaHcCSs67E3sxxmufWaq4F9 6FqQ== X-Gm-Message-State: AJcUukfraWDFMouDzkpF7sTm8P9X27mgNU3+ujLxieBSIvOOrOUxjyvI xZcFi0sukAjvAEuqwusucLLYYmVu X-Google-Smtp-Source: ALg8bN6/JwnoEAMNUQdoz41uxTtdZj1UTPIe8xDA2nKeKkFnOJQvcm1Sy5mtsbjIx+Mbgu7hYer+3g== X-Received: by 2002:a2e:9944:: with SMTP id r4-v6mr34837257ljj.185.1549120693264; Sat, 02 Feb 2019 07:18:13 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:6cb2:9e25:2436:6eda]) by smtp.googlemail.com with ESMTPSA id l21-v6sm1863245ljj.48.2019.02.02.07.18.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 07:18:12 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: dmitry.torokhov@gmail.com Cc: robh+dt@kernel.org, mark.rutland@arm.com, pawel.mikolaj.chmiel@gmail.com, xc-racer2@live.ca, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/5] input: misc: bma150: Use managed resources helpers Date: Sat, 2 Feb 2019 16:18:03 +0100 Message-Id: <20190202151806.9064-3-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190202151806.9064-1-pawel.mikolaj.chmiel@gmail.com> References: <20190202151806.9064-1-pawel.mikolaj.chmiel@gmail.com> MIME-Version: 1.0 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 From: Jonathan Bakker The driver can be cleaned up by using managed resource helpers Changes from v1: - Correct devm input unregistering Signed-off-by: Jonathan Bakker Signed-off-by: Paweł Chmiel --- drivers/input/misc/bma150.c | 44 ++++++++++--------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c index 1efcfdf9f8a8..79acaaf86b7e 100644 --- a/drivers/input/misc/bma150.c +++ b/drivers/input/misc/bma150.c @@ -471,7 +471,7 @@ static int bma150_register_input_device(struct bma150_data *bma150) struct input_dev *idev; int error; - idev = input_allocate_device(); + idev = devm_input_allocate_device(&bma150->client->dev); if (!idev) return -ENOMEM; @@ -482,10 +482,8 @@ static int bma150_register_input_device(struct bma150_data *bma150) input_set_drvdata(idev, bma150); error = input_register_device(idev); - if (error) { - input_free_device(idev); + if (error) return error; - } bma150->input = idev; return 0; @@ -496,7 +494,7 @@ static int bma150_register_polled_device(struct bma150_data *bma150) struct input_polled_dev *ipoll_dev; int error; - ipoll_dev = input_allocate_polled_device(); + ipoll_dev = devm_input_allocate_polled_device(&bma150->client->dev); if (!ipoll_dev) return -ENOMEM; @@ -511,10 +509,8 @@ static int bma150_register_polled_device(struct bma150_data *bma150) bma150_init_input_device(bma150, ipoll_dev->input); error = input_register_polled_device(ipoll_dev); - if (error) { - input_free_polled_device(ipoll_dev); + if (error) return error; - } bma150->input_polled = ipoll_dev; bma150->input = ipoll_dev->input; @@ -543,7 +539,8 @@ static int bma150_probe(struct i2c_client *client, return -EINVAL; } - bma150 = kzalloc(sizeof(struct bma150_data), GFP_KERNEL); + bma150 = devm_kzalloc(&client->dev, sizeof(struct bma150_data), + GFP_KERNEL); if (!bma150) return -ENOMEM; @@ -556,7 +553,7 @@ static int bma150_probe(struct i2c_client *client, dev_err(&client->dev, "IRQ GPIO conf. error %d, error %d\n", client->irq, error); - goto err_free_mem; + return error; } } cfg = &pdata->cfg; @@ -566,14 +563,14 @@ static int bma150_probe(struct i2c_client *client, error = bma150_initialize(bma150, cfg); if (error) - goto err_free_mem; + return error; if (client->irq > 0) { error = bma150_register_input_device(bma150); if (error) - goto err_free_mem; + return error; - error = request_threaded_irq(client->irq, + error = devm_request_threaded_irq(&client->dev, client->irq, NULL, bma150_irq_thread, IRQF_TRIGGER_RISING | IRQF_ONESHOT, BMA150_DRIVER, bma150); @@ -581,13 +578,12 @@ static int bma150_probe(struct i2c_client *client, dev_err(&client->dev, "irq request failed %d, error %d\n", client->irq, error); - input_unregister_device(bma150->input); - goto err_free_mem; + return error; } } else { error = bma150_register_polled_device(bma150); if (error) - goto err_free_mem; + return error; } i2c_set_clientdata(client, bma150); @@ -595,28 +591,12 @@ static int bma150_probe(struct i2c_client *client, pm_runtime_enable(&client->dev); return 0; - -err_free_mem: - kfree(bma150); - return error; } static int bma150_remove(struct i2c_client *client) { - struct bma150_data *bma150 = i2c_get_clientdata(client); - pm_runtime_disable(&client->dev); - if (client->irq > 0) { - free_irq(client->irq, bma150); - input_unregister_device(bma150->input); - } else { - input_unregister_polled_device(bma150->input_polled); - input_free_polled_device(bma150->input_polled); - } - - kfree(bma150); - return 0; } From patchwork Sat Feb 2 15:18:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pawe=C5=82_Chmiel?= X-Patchwork-Id: 10794331 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46E5F13A4 for ; Sat, 2 Feb 2019 15:18:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36B3B3012E for ; Sat, 2 Feb 2019 15:18:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AF893013F; Sat, 2 Feb 2019 15:18:40 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 0F2623012E for ; Sat, 2 Feb 2019 15:18:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728160AbfBBPST (ORCPT ); Sat, 2 Feb 2019 10:18:19 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:36836 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbfBBPSR (ORCPT ); Sat, 2 Feb 2019 10:18:17 -0500 Received: by mail-lf1-f66.google.com with SMTP id a16so7259708lfg.3; Sat, 02 Feb 2019 07:18:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FB/F5VbY7XSQ/g3rwzQi2XoWo9gRmJj9GxgZuRwAeKA=; b=MXxyPmsMq+4PBUdXSflnwP/8++u0kria9XU9iOjlHQ64ovtQLw/fa5tnIlQZO+6pr9 2kAE2QiJtXz64PZox1KkKw/RrWqQA7M6vwUsH7TZfJ8dMqEuCdkc6hBJyHfAkGNzsiXh /ATLMSt86e1uR0lU6v2veLMdAz9O9bNy7OzAUaS34T6shRebMWIeVDHbZEtYhnTs/Bzo PUPKzQ3qfP0AJTZZWPAfKpQPnsbx3L8kPFfk/Bcs8XZxMBEUP7heUhhtqG835cnfy81z +EbtziwefTt/elpT7pjlUiyMc0jNAcTslvWCnU7a/zVaMwG2RX3LLWJ8znNXNMHyhiCg KxuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FB/F5VbY7XSQ/g3rwzQi2XoWo9gRmJj9GxgZuRwAeKA=; b=ZwRBGcCSexntBi6Epl2iwra4uwsm0K4ZjMvqqhtw1AWPFywZD9eZ4qL3U4aymb8jAq IQNTfFV6fsLahuhNnIzeuhmTcURrwMyGBbqXVMMXnR2M02+s9xL6VvFQkW+5qLX4Piui gf6oEfECXmUNLJZtkL1FoVGYKL7aKloLUjg8DusiTDmD0MtEZHZHhHYucIJmkGiPwPkE oqZlOcCXrZTfxp+q7aqQkQJxrg3d2Ifc4aEH6XhoJ+LlsFb0/55QXFfvSnDXkOnfEO7e 8VSdJqz5VNsVkAiYAvlzojVu/CKvW0yxc696blPwW2lgXb+EPbkn2WEjEqyQx1emD8sB EbWQ== X-Gm-Message-State: AHQUAub/5NFJdNhjbQRXQJPmSjbKZeZ7PtVPCnyj6zcZCzQJD3j5ahAr gb+dkAMuhkYeHCEawZJWWN8= X-Google-Smtp-Source: AHgI3IYtbb4eWeF7YLEoamcbGRFdzC9yBGtuI/eXP0iKqv7rbgajLr7KLwbqcjg+rZEsD0fdhcmz6Q== X-Received: by 2002:ac2:5085:: with SMTP id f5mr8418352lfm.30.1549120694579; Sat, 02 Feb 2019 07:18:14 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:6cb2:9e25:2436:6eda]) by smtp.googlemail.com with ESMTPSA id l21-v6sm1863245ljj.48.2019.02.02.07.18.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 07:18:13 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: dmitry.torokhov@gmail.com Cc: robh+dt@kernel.org, mark.rutland@arm.com, pawel.mikolaj.chmiel@gmail.com, xc-racer2@live.ca, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/5] input: misc: bma150: Add support for device tree Date: Sat, 2 Feb 2019 16:18:04 +0100 Message-Id: <20190202151806.9064-4-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190202151806.9064-1-pawel.mikolaj.chmiel@gmail.com> References: <20190202151806.9064-1-pawel.mikolaj.chmiel@gmail.com> MIME-Version: 1.0 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 From: Jonathan Bakker Add of_match table to enable bma150 to be probed via DT Changes from v1: - Add properties for all of bma150_cfg Signed-off-by: Jonathan Bakker Signed-off-by: Paweł Chmiel --- drivers/input/misc/bma150.c | 64 ++++++++++++++++++++++++++++++++++++- include/linux/bma150.h | 20 ++++++------ 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c index 79acaaf86b7e..e86df79490ad 100644 --- a/drivers/input/misc/bma150.c +++ b/drivers/input/misc/bma150.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -146,7 +147,7 @@ struct bma150_data { * are stated and verified by Bosch Sensortec where they are configured * to provide a generic sensitivity performance. */ -static const struct bma150_cfg default_cfg = { +static struct bma150_cfg default_cfg = { .any_motion_int = 1, .hg_int = 1, .lg_int = 1, @@ -518,6 +519,51 @@ static int bma150_register_polled_device(struct bma150_data *bma150) return 0; } +int bma150_cfg_from_of(struct device_node *np) +{ + int error; + + default_cfg.any_motion_int = + of_property_read_bool(np, "any-motion-int"); + default_cfg.hg_int = + of_property_read_bool(np, "hg-int"); + default_cfg.lg_int = + of_property_read_bool(np, "lg-int"); + + error = of_property_read_u32_array(np, "any-motion-cfg", + &default_cfg.any_motion_dur, 2); + if (error < 0 && error != -EINVAL) + return error; + + error = of_property_read_u32_array(np, "hg-cfg", + &default_cfg.hg_hyst, 3); + if (error < 0 && error != -EINVAL) + return error; + + error = of_property_read_u32_array(np, "lg-cfg", + &default_cfg.lg_hyst, 3); + if (error < 0 && error != -EINVAL) + return error; + + error = of_property_read_u32(np, "range", + &default_cfg.range); + if (error < 0 && error != -EINVAL) + return error; + else if (default_cfg.range < BMA150_RANGE_2G || + default_cfg.range > BMA150_RANGE_8G) + return -EINVAL; + + error = of_property_read_u32(np, "bandwidth", + &default_cfg.bandwidth); + if (error < 0 && error != -EINVAL) + return error; + else if (default_cfg.bandwidth < BMA150_BW_25HZ || + default_cfg.bandwidth > BMA150_BW_1500HZ) + return -EINVAL; + + return 0; +} + static int bma150_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -557,6 +603,13 @@ static int bma150_probe(struct i2c_client *client, } } cfg = &pdata->cfg; + } else if (client->dev.of_node) { + error = bma150_cfg_from_of(client->dev.of_node); + if (error) { + dev_err(&client->dev, "Failed to parse of data\n"); + return error; + } + cfg = &default_cfg; } else { cfg = &default_cfg; } @@ -620,6 +673,14 @@ static int bma150_resume(struct device *dev) static UNIVERSAL_DEV_PM_OPS(bma150_pm, bma150_suspend, bma150_resume, NULL); +#if IS_ENABLED(CONFIG_OF) +static const struct of_device_id bma150_of_match[] = { + { .compatible = "bosch,bma150" }, + { }, +}; +MODULE_DEVICE_TABLE(of, bma150_of_match); +#endif + static const struct i2c_device_id bma150_id[] = { { "bma150", 0 }, { "smb380", 0 }, @@ -632,6 +693,7 @@ MODULE_DEVICE_TABLE(i2c, bma150_id); static struct i2c_driver bma150_driver = { .driver = { .name = BMA150_DRIVER, + .of_match_table = of_match_ptr(bma150_of_match), .pm = &bma150_pm, }, .class = I2C_CLASS_HWMON, diff --git a/include/linux/bma150.h b/include/linux/bma150.h index b85266a9c35c..ad19dc7a30d7 100644 --- a/include/linux/bma150.h +++ b/include/linux/bma150.h @@ -29,16 +29,16 @@ struct bma150_cfg { bool any_motion_int; /* Set to enable any-motion interrupt */ bool hg_int; /* Set to enable high-G interrupt */ bool lg_int; /* Set to enable low-G interrupt */ - unsigned char any_motion_dur; /* Any-motion duration */ - unsigned char any_motion_thres; /* Any-motion threshold */ - unsigned char hg_hyst; /* High-G hysterisis */ - unsigned char hg_dur; /* High-G duration */ - unsigned char hg_thres; /* High-G threshold */ - unsigned char lg_hyst; /* Low-G hysterisis */ - unsigned char lg_dur; /* Low-G duration */ - unsigned char lg_thres; /* Low-G threshold */ - unsigned char range; /* one of BMA0150_RANGE_xxx */ - unsigned char bandwidth; /* one of BMA0150_BW_xxx */ + u32 any_motion_dur; /* Any-motion duration */ + u32 any_motion_thres; /* Any-motion threshold */ + u32 hg_hyst; /* High-G hysterisis */ + u32 hg_dur; /* High-G duration */ + u32 hg_thres; /* High-G threshold */ + u32 lg_hyst; /* Low-G hysterisis */ + u32 lg_dur; /* Low-G duration */ + u32 lg_thres; /* Low-G threshold */ + u32 range; /* one of BMA0150_RANGE_xxx */ + u32 bandwidth; /* one of BMA0150_BW_xxx */ }; struct bma150_platform_data { From patchwork Sat Feb 2 15:18:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pawe=C5=82_Chmiel?= X-Patchwork-Id: 10794327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 40F4D13BF for ; Sat, 2 Feb 2019 15:18:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 329093012E for ; Sat, 2 Feb 2019 15:18:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25F603013F; Sat, 2 Feb 2019 15:18:31 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 BE5CD3012E for ; Sat, 2 Feb 2019 15:18:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728148AbfBBPST (ORCPT ); Sat, 2 Feb 2019 10:18:19 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:37864 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727974AbfBBPSS (ORCPT ); Sat, 2 Feb 2019 10:18:18 -0500 Received: by mail-lf1-f68.google.com with SMTP id n23so1898223lfl.4; Sat, 02 Feb 2019 07:18:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nAdENCgE82YRmVnjO7HwlMtyEtzqUQlTdhx3sh5cawA=; b=PZ345MV1cnqqS0Sv6kb4cxA8q1zO5C9BTMpCiNWPnh0pcMmvdL0Hj4aPZTmE7miXxL ADK1RiA/3AGxdWjQrXWaPNFj4epcJkK3hDcgQZI4uI61Kud+rCVRKc4ie+rANHI2SfuZ OcwT/TdrGyKHRLTl25UB5RqAZpNvu2fhEs/B43NX2GGRXUpBnESun1nswzvx6X5edm4A WAZ0T+pRigoQTy+NMhrpaKWx3cRJc6MalRBhDsY7xq73i4tw/JNzrnQmc9Fpo0TgoNlv vG4ZVCf+nhuXK36zmsEyXK4uhHVu3FZM/t4B82K5YvtP1lqMG1hCIcmUP3Mgc8nhMq9l 1BRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nAdENCgE82YRmVnjO7HwlMtyEtzqUQlTdhx3sh5cawA=; b=OkIRKLXUK6x8qtz3gKEzSTCB8dTkPqCkiW/SEnSHDX37s/fb+ILPXWtPYgYtlQMgOO 2eMRVDvsVS4KjJ2TIsT+G05/e9tJGVuC1C5DQ2g7KlCTgwSjzCVamGrWE74KuNIj9K90 3oP0TxENXzI1uUYu6ut6QDIsqjrsgb2zz05pCKpAoRQnQ+jGbWtVRp1hP+sX51yKeF/G tcV5iECx63WpIljBtwg+NLihI4AtyzXWL7Y2bPk9OHA3zuEGzM+CuRrATzyhwWwacXbm Nt/hHoE0v29k1JkAX9T3fpdsaUnPEs1weo+/Pqvdy28BbAshYWxhoc7jZ6sf8Z9z9tDX j/zQ== X-Gm-Message-State: AJcUukd2/e/ezgHrf2Rv1LKDjdnmtEhaXk2QEDalFn6aVIGrsmHrEoV+ ilb581zj1/rDc/apIhwoK9/0s8zd X-Google-Smtp-Source: ALg8bN7ZTYoVwLu1/UZxVi8jxevtnRMMNgQaSU0Us9Jd9I299n7oL8q8AesdS3Vkq2KdGuvuTNcj7A== X-Received: by 2002:a19:7111:: with SMTP id m17mr33772134lfc.64.1549120695968; Sat, 02 Feb 2019 07:18:15 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:6cb2:9e25:2436:6eda]) by smtp.googlemail.com with ESMTPSA id l21-v6sm1863245ljj.48.2019.02.02.07.18.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 07:18:15 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: dmitry.torokhov@gmail.com Cc: robh+dt@kernel.org, mark.rutland@arm.com, pawel.mikolaj.chmiel@gmail.com, xc-racer2@live.ca, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/5] input: misc: bma150: Drop platform data Date: Sat, 2 Feb 2019 16:18:05 +0100 Message-Id: <20190202151806.9064-5-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190202151806.9064-1-pawel.mikolaj.chmiel@gmail.com> References: <20190202151806.9064-1-pawel.mikolaj.chmiel@gmail.com> MIME-Version: 1.0 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 From: Jonathan Bakker bma150 supports DT now and as there are no in-kernel users of the platform data, remove it. Signed-off-by: Jonathan Bakker Signed-off-by: Paweł Chmiel --- drivers/input/misc/bma150.c | 27 +++++---------------------- include/linux/bma150.h | 5 ----- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c index e86df79490ad..1cdc8ce97968 100644 --- a/drivers/input/misc/bma150.c +++ b/drivers/input/misc/bma150.c @@ -567,8 +567,6 @@ int bma150_cfg_from_of(struct device_node *np) static int bma150_probe(struct i2c_client *client, const struct i2c_device_id *id) { - const struct bma150_platform_data *pdata = - dev_get_platdata(&client->dev); const struct bma150_cfg *cfg; struct bma150_data *bma150; int chip_id; @@ -592,27 +590,12 @@ static int bma150_probe(struct i2c_client *client, bma150->client = client; - if (pdata) { - if (pdata->irq_gpio_cfg) { - error = pdata->irq_gpio_cfg(); - if (error) { - dev_err(&client->dev, - "IRQ GPIO conf. error %d, error %d\n", - client->irq, error); - return error; - } - } - cfg = &pdata->cfg; - } else if (client->dev.of_node) { - error = bma150_cfg_from_of(client->dev.of_node); - if (error) { - dev_err(&client->dev, "Failed to parse of data\n"); - return error; - } - cfg = &default_cfg; - } else { - cfg = &default_cfg; + error = bma150_cfg_from_of(client->dev.of_node); + if (error) { + dev_err(&client->dev, "Failed to parse of data\n"); + return error; } + cfg = &default_cfg; error = bma150_initialize(bma150, cfg); if (error) diff --git a/include/linux/bma150.h b/include/linux/bma150.h index ad19dc7a30d7..650ffe9fa4cf 100644 --- a/include/linux/bma150.h +++ b/include/linux/bma150.h @@ -41,9 +41,4 @@ struct bma150_cfg { u32 bandwidth; /* one of BMA0150_BW_xxx */ }; -struct bma150_platform_data { - struct bma150_cfg cfg; - int (*irq_gpio_cfg)(void); -}; - #endif /* _BMA150_H_ */ From patchwork Sat Feb 2 15:18:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pawe=C5=82_Chmiel?= X-Patchwork-Id: 10794329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D16A313A4 for ; Sat, 2 Feb 2019 15:18:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C06AA3012E for ; Sat, 2 Feb 2019 15:18:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1DDD3013F; Sat, 2 Feb 2019 15:18:37 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 25D3A3012E for ; Sat, 2 Feb 2019 15:18:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728195AbfBBPSX (ORCPT ); Sat, 2 Feb 2019 10:18:23 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:33798 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728053AbfBBPSU (ORCPT ); Sat, 2 Feb 2019 10:18:20 -0500 Received: by mail-lf1-f65.google.com with SMTP id p6so7275231lfc.1; Sat, 02 Feb 2019 07:18:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5FqsdWNrwVpIkpI1KCzw2aeX63P4x3d77h9m6SbC+28=; b=e1QS2vlijvL7+oERYjEdug6nmZItdcdlmk5TAOUSGq3e/m3FGg+oneu0y0PVR8y2h6 hgRRxdvil5LrwWgsrSiU5sM1WbSLRKwGBsCuJHUrpv68mY9GvUFReoX/KEf/MonI0MPo JUe1Ac9sjsqmIyZpaa7mD6CeIzPrSatQSrADav2CTOh7SSrqVUGqWM8E2E/5TC0B6iry LrPlNKOJ5FxWS3nvXVYrmqUFRzCY91hWqZT7C85RmVpoQmtGEROhgKkaXb3NLmwd1QNE FqSU6KBgUiQu7DtMHP3Le20xbhrhg6QQyeJdvoQ/GC7htL2P7J1a0h03th3VqZbnSUNF /fBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5FqsdWNrwVpIkpI1KCzw2aeX63P4x3d77h9m6SbC+28=; b=rAQPTgEMCX/VGR/xnxckxzYkyv7szm9LLGBOM22Zz+c6Ep26v4xbhwIs7SAOdvL31n 0wcQlSiJSReLZEBMM8WuXCGgr7rNi062lvXsgALQELrj/zgRkwUduUnJxXxnxBaAWvCR /V/yV4yx6Lsw/5PYV0pP+7Uz66GFEqeJkeuruNyc/PMRQ9lU0oqO/FisU/jADpgdJD6k t1+y2+gCq1VvBxwiggKXxaWen6XQolyXa/ldeYdbyHTfsZbZgd0iWTn6t8rJiFSz9Vyq 9Y7f36VsIPTPFUxNpXoj+ZmFmo7bFJXSwwlAy8/LeD/cDRyKhjgFDl7VUP6DTkt6EbCC oDzw== X-Gm-Message-State: AHQUAuZL9KsiB1GpsrH3hoeOe9isVenP6TcgTWPRTJuY1GHuOLTlvee8 iU1lhE1M/E1RgBbAu/8jrjk= X-Google-Smtp-Source: AHgI3IYVxQtjfiYmkS7RhtpDNUBsaw5coqDJ5XHqR+KfVkQeQn3taZv8KfEnmWXMUoFxGgsTxMw3HA== X-Received: by 2002:a19:214c:: with SMTP id h73mr3496496lfh.149.1549120697426; Sat, 02 Feb 2019 07:18:17 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:6cb2:9e25:2436:6eda]) by smtp.googlemail.com with ESMTPSA id l21-v6sm1863245ljj.48.2019.02.02.07.18.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 07:18:16 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: dmitry.torokhov@gmail.com Cc: robh+dt@kernel.org, mark.rutland@arm.com, pawel.mikolaj.chmiel@gmail.com, xc-racer2@live.ca, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] input: misc: bma150: Register input device after setting private data Date: Sat, 2 Feb 2019 16:18:06 +0100 Message-Id: <20190202151806.9064-6-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190202151806.9064-1-pawel.mikolaj.chmiel@gmail.com> References: <20190202151806.9064-1-pawel.mikolaj.chmiel@gmail.com> MIME-Version: 1.0 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 From: Jonathan Bakker Otherwise we introduce a race condition where userspace can request input before we're ready leading to null pointer dereference such as input: bma150 as /devices/platform/i2c-gpio-2/i2c-5/5-0038/input/input3 Unable to handle kernel NULL pointer dereference at virtual address 00000018 pgd = (ptrval) [00000018] *pgd=55dac831, *pte=00000000, *ppte=00000000 Internal error: Oops: 17 [#1] PREEMPT ARM Modules linked in: bma150 input_polldev [last unloaded: bma150] CPU: 0 PID: 2870 Comm: accelerometer Not tainted 5.0.0-rc3-dirty #46 Hardware name: Samsung S5PC110/S5PV210-based board PC is at input_event+0x8/0x60 LR is at bma150_report_xyz+0x9c/0xe0 [bma150] pc : [<80450f70>] lr : [<7f0a614c>] psr: 800d0013 sp : a4c1fd78 ip : 00000081 fp : 00020000 r10: 00000000 r9 : a5e2944c r8 : a7455000 r7 : 00000016 r6 : 00000101 r5 : a7617940 r4 : 80909048 r3 : fffffff2 r2 : 00000000 r1 : 00000003 r0 : 00000000 Flags: Nzcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none Control: 10c5387d Table: 54e34019 DAC: 00000051 Process accelerometer (pid: 2870, stack limit = 0x(ptrval)) Stackck: (0xa4c1fd78 to 0xa4c20000) fd60: fffffff3 fc813f6c fd80: 40410581 d7530ce3 a5e2817c a7617f00 a5e29404 a5e2817c 00000000 7f008324 fda0: a5e28000 8044f59c a5fdd9d0 a5e2945c a46a4a00 a5e29668 a7455000 80454f10 fdc0: 80909048 a5e29668 a5fdd9d0 a46a4a00 806316d0 00000000 a46a4a00 801df5f0 fde0: 00000000 d7530ce3 a4c1fec0 a46a4a00 00000000 a5fdd9d0 a46a4a08 801df53c fe00: 00000000 801d74bc a4c1fec0 00000000 a4c1ff70 00000000 a7038da8 00000000 fe20: a46a4a00 801e91fc a411bbe0 801f2e88 00000004 00000000 80909048 00000041 fe40: 00000000 00020000 00000000 dead4ead a6a88da0 00000000 ffffe000 806fcae8 fe60: a4c1fec8 00000000 80909048 00000002 a5fdd9d0 a7660110 a411bab0 00000001 fe80: dead4ead ffffffff ffffffff a4c1fe8c a4c1fe8c d7530ce3 20000013 80909048 fea0: 80909048 a4c1ff70 00000001 fffff000 a4c1e000 00000005 00026038 801eabd8 fec0: a7660110 a411bab0 b9394901 00000006 a696201b 76fb3000 00000000 a7039720 fee0: a5fdd9d0 00000101 00000002 00000096 00000000 00000000 00000000 a4c1ff00 ff00: a6b310f4 805cb174 a6b310f4 00000010 00000fe0 00000010 a4c1e000 d7530ce3 ff20: 00000003 a5f41400 a5f41424 00000000 a6962000 00000000 00000003 00000002 ff40: ffffff9c 000a0000 80909048 d7530ce3 a6962000 00000003 80909048 ffffff9c ff60: a6962000 801d890c 00000000 00000000 00020000 a7590000 00000004 00000100 ff80: 00000001 d7530ce3 000288b8 00026320 000288b8 00000005 80101204 a4c1e000 ffa0: 00000005 80101000 000288b8 00026320 000288b8 000a0000 00000000 00000000 ffc0: 000288b8 00026320 000288b8 00000005 7eef3bac 000264e8 00028ad8 00026038 ffe0: 00000005 7eef3300 76f76e91 76f78546 800d0030 000288b8 00000000 00000000 [<80450f70>] (input_event) from [] (0xa5e2817c) Code: e1a08148 eaffffa8 e351001f 812fff1e (e590c018) ---[ end trace 1c691ee85f2ff243 ]--- Signed-off-by: Jonathan Bakker Signed-off-by: Paweł Chmiel --- drivers/input/misc/bma150.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c index 1cdc8ce97968..64caf43e5bca 100644 --- a/drivers/input/misc/bma150.c +++ b/drivers/input/misc/bma150.c @@ -470,7 +470,6 @@ static void bma150_init_input_device(struct bma150_data *bma150, static int bma150_register_input_device(struct bma150_data *bma150) { struct input_dev *idev; - int error; idev = devm_input_allocate_device(&bma150->client->dev); if (!idev) @@ -482,18 +481,14 @@ static int bma150_register_input_device(struct bma150_data *bma150) idev->close = bma150_irq_close; input_set_drvdata(idev, bma150); - error = input_register_device(idev); - if (error) - return error; - bma150->input = idev; - return 0; + + return input_register_device(idev); } static int bma150_register_polled_device(struct bma150_data *bma150) { struct input_polled_dev *ipoll_dev; - int error; ipoll_dev = devm_input_allocate_polled_device(&bma150->client->dev); if (!ipoll_dev) @@ -509,14 +504,10 @@ static int bma150_register_polled_device(struct bma150_data *bma150) bma150_init_input_device(bma150, ipoll_dev->input); - error = input_register_polled_device(ipoll_dev); - if (error) - return error; - bma150->input_polled = ipoll_dev; bma150->input = ipoll_dev->input; - return 0; + return input_register_polled_device(ipoll_dev); } int bma150_cfg_from_of(struct device_node *np)