From patchwork Fri Jan 25 17:50:42 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: 10781769 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 E102E13BF for ; Fri, 25 Jan 2019 17:51:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6F9330339 for ; Fri, 25 Jan 2019 17:51:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB7BE3030B; Fri, 25 Jan 2019 17:51:28 +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 4385130338 for ; Fri, 25 Jan 2019 17:51:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729354AbfAYRuz (ORCPT ); Fri, 25 Jan 2019 12:50:55 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:43005 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbfAYRux (ORCPT ); Fri, 25 Jan 2019 12:50:53 -0500 Received: by mail-lj1-f195.google.com with SMTP id l15-v6so9084163lja.9; Fri, 25 Jan 2019 09:50:51 -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=YtdKYC1cMTw55JdBBHfZAU6HnadYIoDV9dvqtWpcWmU=; b=YmTuPevgvOUOOi3z6+pZGPOUHjib4bWLNyYuxJHSgBDuI3rMPRzVgNrU+J4xMwEe45 sieuQ+Ri/Dpf+zQmeHVGVQlBpz7b6nYpuv1urFWK1ciVkJGkXeyrg2t/EFNrgo6R5+DZ ji3SCuSqZM/QT2N6nkI5xxMMtl6Cvc9hV/Yjq/bW06P8YxobpQovPFT7C6H3FjV9Ezlt qJ7Zad53nqaKh0uFUPQ9eMi5ObbG+orBV6xA19IIy3nsWjCRynhlJ23teVf+A8JUpD4k 7mXUiiyky4K5cpY7Bn50gJ2RPlgmo/UbwGhGAkYifGZxUUVd721o3N3LTmDrXJ4J3Z6O Fkyw== 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=YtdKYC1cMTw55JdBBHfZAU6HnadYIoDV9dvqtWpcWmU=; b=uj6RJuY7sNEYDVKXaAF5nyYG8AZgcnJb6kXIL9mgWRdKievCqfF7O7kKKJmAAxHnOT 2sto9K4sbfNcXnm3w70FkM7XX3/6EIiJkunFNMTiPD1X1KwkXXf0lIYyY20G7vSkk6ks HvbaSMt1NJbe6fmm8YyLbcNepUIaciubmUnJzOJKxfMnX0e6rS/eEH9Nz2m7sAAk5GXO IeiodLIDBrkJfYsuafl+jgInm54Bi2BXL7gk3coSJg+f0ziOwNHhR9ULVZ1kzDCWXR0A lEk/b9a6ubngVkVberalMLRW9S8PVw5+NC59pL3j3w2+0gIjZ7aIPjIQ+TaYAjpExKti zoVg== X-Gm-Message-State: AJcUukelC7zUyuVbPjzHT3oXkkGgof7JXFHiuiaANmGAi6BucptzEtw/ Tr50J+XrMnpB33QYONpWIKk= X-Google-Smtp-Source: ALg8bN7utHtsx0w25xuuxjDR2zwYT+EvDohrCfYoDgLuwVZ6gbTuMcYkjE/8YYvrs5EyVu/6NF9xKQ== X-Received: by 2002:a2e:5c07:: with SMTP id q7-v6mr9608125ljb.119.1548438650620; Fri, 25 Jan 2019 09:50:50 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:6921:1f1d:2918:d853]) by smtp.googlemail.com with ESMTPSA id l21-v6sm1575606ljj.48.2019.01.25.09.50.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Jan 2019 09:50:49 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: dmitry.torokhov@gmail.com Cc: robh+dt@kernel.org, mark.rutland@arm.com, mchehab+samsung@kernel.org, colyli@suse.de, ckeepax@opensource.wolfsonmicro.com, andrew.smirnov@gmail.com, arnd@arndb.de, xiaotong.lu@spreadtrum.com, xc-racer2@live.ca, pawel.mikolaj.chmiel@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 1/4] input: misc: gp2a: Use managed resource helpers Date: Fri, 25 Jan 2019 18:50:42 +0100 Message-Id: <20190125175045.22576-2-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190125175045.22576-1-pawel.mikolaj.chmiel@gmail.com> References: <20190125175045.22576-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 Simplify cleanup of failures by using managed resource helpers Signed-off-by: Jonathan Bakker Signed-off-by: Paweł Chmiel --- drivers/input/misc/gp2ap002a00f.c | 37 ++++++++++--------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/drivers/input/misc/gp2ap002a00f.c b/drivers/input/misc/gp2ap002a00f.c index c6a29e57b5e4..79c8c4c56d1a 100644 --- a/drivers/input/misc/gp2ap002a00f.c +++ b/drivers/input/misc/gp2ap002a00f.c @@ -138,14 +138,15 @@ static int gp2a_probe(struct i2c_client *client, return error; } - error = gpio_request_one(pdata->vout_gpio, GPIOF_IN, GP2A_I2C_NAME); + error = devm_gpio_request_one(&client->dev, pdata->vout_gpio, + GPIOF_IN, GP2A_I2C_NAME); if (error) goto err_hw_shutdown; - dt = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL); + dt = devm_kzalloc(&client->dev, sizeof(struct gp2a_data), GFP_KERNEL); if (!dt) { error = -ENOMEM; - goto err_free_gpio; + goto err_hw_shutdown; } dt->pdata = pdata; @@ -153,12 +154,12 @@ static int gp2a_probe(struct i2c_client *client, error = gp2a_initialize(dt); if (error < 0) - goto err_free_mem; + goto err_hw_shutdown; - dt->input = input_allocate_device(); + dt->input = devm_input_allocate_device(&client->dev); if (!dt->input) { error = -ENOMEM; - goto err_free_mem; + goto err_hw_shutdown; } input_set_drvdata(dt->input, dt); @@ -171,19 +172,18 @@ static int gp2a_probe(struct i2c_client *client, input_set_capability(dt->input, EV_SW, SW_FRONT_PROXIMITY); - error = request_threaded_irq(client->irq, NULL, gp2a_irq, - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | - IRQF_ONESHOT, - GP2A_I2C_NAME, dt); + error = devm_request_threaded_irq(&client->dev, client->irq, NULL, + gp2a_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | + IRQF_ONESHOT, GP2A_I2C_NAME, dt); if (error) { dev_err(&client->dev, "irq request failed\n"); - goto err_free_input_dev; + goto err_hw_shutdown; } error = input_register_device(dt->input); if (error) { dev_err(&client->dev, "device registration failed\n"); - goto err_free_irq; + goto err_hw_shutdown; } device_init_wakeup(&client->dev, pdata->wakeup); @@ -191,14 +191,6 @@ static int gp2a_probe(struct i2c_client *client, return 0; -err_free_irq: - free_irq(client->irq, dt); -err_free_input_dev: - input_free_device(dt->input); -err_free_mem: - kfree(dt); -err_free_gpio: - gpio_free(pdata->vout_gpio); err_hw_shutdown: if (pdata->hw_shutdown) pdata->hw_shutdown(client); @@ -210,12 +202,7 @@ static int gp2a_remove(struct i2c_client *client) struct gp2a_data *dt = i2c_get_clientdata(client); const struct gp2a_platform_data *pdata = dt->pdata; - free_irq(client->irq, dt); - input_unregister_device(dt->input); - kfree(dt); - - gpio_free(pdata->vout_gpio); if (pdata->hw_shutdown) pdata->hw_shutdown(client); From patchwork Fri Jan 25 17:50:43 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: 10781773 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 38EE2746 for ; Fri, 25 Jan 2019 17:51:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 265883030A for ; Fri, 25 Jan 2019 17:51:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AB7530346; Fri, 25 Jan 2019 17:51:51 +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 79DEA3033B for ; Fri, 25 Jan 2019 17:51:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729454AbfAYRva (ORCPT ); Fri, 25 Jan 2019 12:51:30 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:45261 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729342AbfAYRuz (ORCPT ); Fri, 25 Jan 2019 12:50:55 -0500 Received: by mail-lf1-f68.google.com with SMTP id b20so7518716lfa.12; Fri, 25 Jan 2019 09:50:53 -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=mdcWJxzksVATppwqbwI/hcPn8CHwTYbubmN30c+0kzs=; b=ZIOqdQ4nEKXudrs3ns2vSN5FkXUfjNQexPUrxf+F69O1K0aPkDY2Or6BFgx+ooYd+q vOWU6BuIUn/7FMOaDrgRB4NjU/3auJFCI4jZfvcbb/OKlY4Wche2hOJfdy2ZTRD2atly iLS0Fq+glZRvafcuLtZtHfnuxweZT4sOB48FePh9cj5dsG1FeQpPSZ+SYfi2WpM39i1s F3FY+XRe4qdt5w3RdRfMlLymLIal890sQO42wUwOL9N69jBKVRB3oC1+pfL2SNjgoqNC RF3AcvEPiQN/N19zzrFIfukxJwbE+qgU3JM8v3lh4TV3bU79EZD7ykHyadfIjmCjC64n r59w== 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=mdcWJxzksVATppwqbwI/hcPn8CHwTYbubmN30c+0kzs=; b=Bp+l0eGPESxHYZGoZY6eMloWzOJnjLIM77r61MNOvXYSNAT3tiF87mu+tQOeoR+Pmb w9EuXgJhxk+xPbSknClMl7x5gbycNnSPFYamwP6lg0w0WkdEMDVWIxC5ga+bgf38iNZq +Gs+ZuR14KcXSt0bEBU7TFLZU+uhs7YFgv6gh1haJohYfEc19F/THplqfy37HKLIom7P YmIs4cRamjOqHflmZ8TPzmXBxVza6oczlvIW+ezOOEYPUZa4kc2of3S9uJOMdznSW+4D RNlbRPqmZUV1rRsWQm1ztzxwoO5y6EIWPu3u0OMDi4Ya523PaFGt5vCIoGtblHn+Z4uW ISfw== X-Gm-Message-State: AJcUukeIymqckfdJqCH8WTdhTzjKx1h0DNd2I93rGE9mhQWCr3yDlNCX Bnoj8K0IJamTfDaVxDyqL0Q= X-Google-Smtp-Source: ALg8bN4kbOp/qU4cpBt7mIikPndzHszbQnHXSbZ2K1orKXrsFLiiRuWcshuQlfxLrxWx5Lm0onI2Bw== X-Received: by 2002:a19:1f54:: with SMTP id f81mr9472210lff.153.1548438652020; Fri, 25 Jan 2019 09:50:52 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:6921:1f1d:2918:d853]) by smtp.googlemail.com with ESMTPSA id l21-v6sm1575606ljj.48.2019.01.25.09.50.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Jan 2019 09:50:51 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: dmitry.torokhov@gmail.com Cc: robh+dt@kernel.org, mark.rutland@arm.com, mchehab+samsung@kernel.org, colyli@suse.de, ckeepax@opensource.wolfsonmicro.com, andrew.smirnov@gmail.com, arnd@arndb.de, xiaotong.lu@spreadtrum.com, xc-racer2@live.ca, pawel.mikolaj.chmiel@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 2/4] input: misc: gp2a: Add support for light sensor Date: Fri, 25 Jan 2019 18:50:43 +0100 Message-Id: <20190125175045.22576-3-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190125175045.22576-1-pawel.mikolaj.chmiel@gmail.com> References: <20190125175045.22576-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 gp2a driver previously only supported the proximity part of the sensor while the hardware supports both. Signed-off-by: Jonathan Bakker Signed-off-by: Paweł Chmiel --- drivers/input/misc/Kconfig | 2 + drivers/input/misc/gp2ap002a00f.c | 71 +++++++++++++++++++++++++++++- include/linux/input/gp2ap002a00f.h | 4 ++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index ca59a2be9bc5..a532efb4e6d8 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -252,6 +252,8 @@ config INPUT_GP2A tristate "Sharp GP2AP002A00F I2C Proximity/Opto sensor driver" depends on I2C depends on GPIOLIB || COMPILE_TEST + depends on IIO + select INPUT_POLLDEV help Say Y here if you have a Sharp GP2AP002A00F proximity/als combo-chip hooked to an I2C bus. diff --git a/drivers/input/misc/gp2ap002a00f.c b/drivers/input/misc/gp2ap002a00f.c index 79c8c4c56d1a..090c8c313295 100644 --- a/drivers/input/misc/gp2ap002a00f.c +++ b/drivers/input/misc/gp2ap002a00f.c @@ -10,9 +10,12 @@ */ #include +#include +#include #include #include #include +#include #include #include #include @@ -20,7 +23,9 @@ #include struct gp2a_data { + struct iio_channel *channel; struct input_dev *input; + struct input_polled_dev *poll_dev; const struct gp2a_platform_data *pdata; struct i2c_client *i2c_client; }; @@ -58,6 +63,19 @@ static irqreturn_t gp2a_irq(int irq, void *handle) return IRQ_HANDLED; } +static void gp2a_poll(struct input_polled_dev *dev) +{ + struct gp2a_data *dt = dev->private; + int ret, value; + + ret = iio_read_channel_processed(dt->channel, &value); + if (ret < 0) + dev_err(&dt->i2c_client->dev, "failed to read value!"); + + input_report_abs(dev->input, ABS_MISC, value); + input_sync(dev->input); +} + static int gp2a_enable(struct gp2a_data *dt) { return i2c_smbus_write_byte_data(dt->i2c_client, GP2A_ADDR_OPMOD, @@ -127,7 +145,7 @@ static int gp2a_probe(struct i2c_client *client, { const struct gp2a_platform_data *pdata = dev_get_platdata(&client->dev); struct gp2a_data *dt; - int error; + int error, value; if (!pdata) return -EINVAL; @@ -152,6 +170,49 @@ static int gp2a_probe(struct i2c_client *client, dt->pdata = pdata; dt->i2c_client = client; + dt->channel = devm_iio_channel_get(&client->dev, "light"); + if (!IS_ERR(dt->channel)) { + if (!dt->channel->indio_dev) { + error = -ENXIO; + goto err_hw_shutdown; + } + + if (dt->pdata->light_adc_max <= 0 || + dt->pdata->light_adc_fuzz <= 0) { + error = -EINVAL; + goto err_hw_shutdown; + } + + dt->poll_dev = devm_input_allocate_polled_device(&client->dev); + if (!dt->poll_dev) { + dev_err(&client->dev, + "failed to allocate polled input device"); + error = -ENOMEM; + goto err_hw_shutdown; + } + + if (!device_property_read_u32(&client->dev, "poll-interval", + &value)) + dt->poll_dev->poll_interval = value; + + dt->poll_dev->poll = gp2a_poll; + dt->poll_dev->private = dt; + + dt->poll_dev->input->name = GP2A_I2C_NAME; + + input_set_capability(dt->poll_dev->input, EV_ABS, ABS_MISC); + input_set_abs_params(dt->poll_dev->input, ABS_MISC, 0, + dt->pdata->light_adc_max, + dt->pdata->light_adc_fuzz, 0); + + error = input_register_polled_device(dt->poll_dev); + if (error) + goto err_hw_shutdown; + } else if (PTR_ERR(dt->channel) == -EPROBE_DEFER) { + error = -EPROBE_DEFER; + goto err_hw_shutdown; + } + error = gp2a_initialize(dt); if (error < 0) goto err_hw_shutdown; @@ -203,6 +264,8 @@ static int gp2a_remove(struct i2c_client *client) const struct gp2a_platform_data *pdata = dt->pdata; input_unregister_device(dt->input); + if (dt->poll_dev) + input_unregister_polled_device(dt->poll_dev); if (pdata->hw_shutdown) pdata->hw_shutdown(client); @@ -243,6 +306,12 @@ static int __maybe_unused gp2a_resume(struct device *dev) mutex_unlock(&dt->input->mutex); } + if (dt->poll_dev) { + /* Out of range value so real value goes through next */ + input_abs_set_val(dt->poll_dev->input, ABS_MISC, + -dt->pdata->light_adc_max); + } + return retval; } diff --git a/include/linux/input/gp2ap002a00f.h b/include/linux/input/gp2ap002a00f.h index 3614a13a8297..0212948897b4 100644 --- a/include/linux/input/gp2ap002a00f.h +++ b/include/linux/input/gp2ap002a00f.h @@ -12,12 +12,16 @@ * @wakeup: Set to true if the proximity can wake the device from suspend * @hw_setup: Callback for setting up hardware such as gpios and vregs * @hw_shutdown: Callback for properly shutting down hardware + * @light_adc_max: Maximum adc value the light sensor will read + * @light_adc_fuzz: Fuzz value for light adc sensor */ struct gp2a_platform_data { int vout_gpio; bool wakeup; int (*hw_setup)(struct i2c_client *client); int (*hw_shutdown)(struct i2c_client *client); + int light_adc_max; + int light_adc_fuzz; }; #endif From patchwork Fri Jan 25 17:50:44 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: 10781765 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 554CB13BF for ; Fri, 25 Jan 2019 17:50:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44620302F3 for ; Fri, 25 Jan 2019 17:50:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3746030318; Fri, 25 Jan 2019 17:50:59 +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 C70DC302F3 for ; Fri, 25 Jan 2019 17:50:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729400AbfAYRu5 (ORCPT ); Fri, 25 Jan 2019 12:50:57 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:39815 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729350AbfAYRu4 (ORCPT ); Fri, 25 Jan 2019 12:50:56 -0500 Received: by mail-lj1-f193.google.com with SMTP id t9-v6so9069995ljh.6; Fri, 25 Jan 2019 09:50:54 -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=sR7vptffNLJhjIvvskAjl+NHWhoMeph6+VUdWpkkqW4=; b=cCSaI/fOBgL5ExarI/S0UAKgNuCZcxXU7Ur/+tS4AXBHRSJvfp/iLRkc+wdjcX1ruD oW6Q7krkWyToDQioVWoBid5J3MD1UhIOR9u+GrXR1lAS1uzBeGTvaEw0N3G/EkLx1M8K me9aBqrtuWRtTgwWwnzzP82pRVTbdi7dBjfh3fHVz3pBTjMhpQ567axkmYccQCUrWRGE VjAL1MU1PAO8AFvUz7ifRi6G9p+RZUECeHIQ1QzZhk1spH7R8B9gFVF/l5n9qWq9ChQf PBoNSkG3xlk1Ok0zxAybylDUoSbNyHTW+VBzhgSM1zSly9KLzYLXZheZMuuNv2Q7R8dv 7V6g== 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=sR7vptffNLJhjIvvskAjl+NHWhoMeph6+VUdWpkkqW4=; b=TG1HayL/eQH8pE6wJftuG9Qxil+PhhP04X/jdTKnLXj7fszSudkizHz5ixPSSE14ew vBOIyf3+w42UvS1ZM7Sccj3fOtZqRp9UxHuuRztd7jxTfy1jpZVa38imjketpU2fWI2H xvVSnzBxdXkZDyoDK/HVp+BXaPMrE7Nljjwd0/L90lrk83NFBTO1EGJTCkct+STjtbDY grtN1dFmlJ5jKOwvN0A1Q/ls7YDLZRL6qkdupQuQnoGUxuOT4JbG3aMLs85hWhvfjJRW RXGbM2O77L4bWhbfNqG7Hmfy1FJpLDWOeHBm60GLxuSrxznavbjIBho/QNaTzfHjcV9J Ps7w== X-Gm-Message-State: AJcUukcuNQsUCV1FZL2hPzoIZxi6XD6zoW4RzJ3mQtM+6YbayyjQ8uL1 qttWVWQLEh60auxLFPOr+nc= X-Google-Smtp-Source: ALg8bN6TrjB4C4tB+FKsiRIGTG13D6kj9UV/xv0cvzF/wIaljotm4+/VaoApUnsJtVuuN1W9TB6g0g== X-Received: by 2002:a2e:197:: with SMTP id f23-v6mr9922603lji.144.1548438653913; Fri, 25 Jan 2019 09:50:53 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:6921:1f1d:2918:d853]) by smtp.googlemail.com with ESMTPSA id l21-v6sm1575606ljj.48.2019.01.25.09.50.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Jan 2019 09:50:53 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: dmitry.torokhov@gmail.com Cc: robh+dt@kernel.org, mark.rutland@arm.com, mchehab+samsung@kernel.org, colyli@suse.de, ckeepax@opensource.wolfsonmicro.com, andrew.smirnov@gmail.com, arnd@arndb.de, xiaotong.lu@spreadtrum.com, xc-racer2@live.ca, pawel.mikolaj.chmiel@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 3/4] input: misc: gp2a: Enable device tree Date: Fri, 25 Jan 2019 18:50:44 +0100 Message-Id: <20190125175045.22576-4-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190125175045.22576-1-pawel.mikolaj.chmiel@gmail.com> References: <20190125175045.22576-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 Enable probing of gp2a via device tree via a simple of_match table Signed-off-by: Jonathan Bakker Signed-off-by: Paweł Chmiel --- drivers/input/misc/gp2ap002a00f.c | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/input/misc/gp2ap002a00f.c b/drivers/input/misc/gp2ap002a00f.c index 090c8c313295..01a7d44ae921 100644 --- a/drivers/input/misc/gp2ap002a00f.c +++ b/drivers/input/misc/gp2ap002a00f.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include struct gp2a_data { struct iio_channel *channel; @@ -140,6 +142,35 @@ static int gp2a_initialize(struct gp2a_data *dt) return error; } +static struct gp2a_platform_data *gp2a_parse_dt_pdata(struct device *dev) +{ + struct gp2a_platform_data *pdata; + int ret; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return ERR_PTR(-ENOMEM); + + pdata->wakeup = of_property_read_bool(dev->of_node, "wakeup"); + + pdata->vout_gpio = of_get_named_gpio(dev->of_node, "vout-gpio", 0); + if (pdata->vout_gpio < 0) { + dev_err(dev, "failed to find vout-gpio"); + return ERR_PTR(-EINVAL); + } + + ret = device_property_read_u32(dev, "light-adc-max", + &pdata->light_adc_max); + if (ret) + pdata->light_adc_max = 4096; + ret = device_property_read_u32(dev, "light-adc-fuzz", + &pdata->light_adc_fuzz); + if (ret) + pdata->light_adc_fuzz = 80; + + return pdata; +} + static int gp2a_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -147,6 +178,12 @@ static int gp2a_probe(struct i2c_client *client, struct gp2a_data *dt; int error, value; + if (IS_ENABLED(CONFIG_OF) && client->dev.of_node) { + pdata = gp2a_parse_dt_pdata(&client->dev); + if (IS_ERR(pdata)) + return PTR_ERR(pdata); + } + if (!pdata) return -EINVAL; @@ -317,6 +354,14 @@ static int __maybe_unused gp2a_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(gp2a_pm, gp2a_suspend, gp2a_resume); +#if IS_ENABLED(CONFIG_OF) +static const struct of_device_id gp2a_of_match[] = { + { .compatible = "sharp,gp2ap002a00f" }, + { }, +}; +MODULE_DEVICE_TABLE(of, gp2a_of_match); +#endif + static const struct i2c_device_id gp2a_i2c_id[] = { { GP2A_I2C_NAME, 0 }, { } @@ -326,6 +371,7 @@ MODULE_DEVICE_TABLE(i2c, gp2a_i2c_id); static struct i2c_driver gp2a_i2c_driver = { .driver = { .name = GP2A_I2C_NAME, + .of_match_table = of_match_ptr(gp2a_of_match), .pm = &gp2a_pm, }, .probe = gp2a_probe, From patchwork Fri Jan 25 17:50:45 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: 10781767 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 06D86746 for ; Fri, 25 Jan 2019 17:51:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB2DD3031A for ; Fri, 25 Jan 2019 17:51:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D13243030A; Fri, 25 Jan 2019 17:51:00 +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 75883300C5 for ; Fri, 25 Jan 2019 17:51:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729413AbfAYRu7 (ORCPT ); Fri, 25 Jan 2019 12:50:59 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:39817 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729385AbfAYRu6 (ORCPT ); Fri, 25 Jan 2019 12:50:58 -0500 Received: by mail-lj1-f193.google.com with SMTP id t9-v6so9070064ljh.6; Fri, 25 Jan 2019 09:50:56 -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=+CYllznRYt133KTflL22y4PX2RmV6ZawSJvxIL4oFhI=; b=B3YV4XDWHgZ3WJWKjy56eilIMuCNkNAe0setxKIu7hH78elM5xmPC9Sc6n9MxnGO9D aIu+LLW4aPwsP5n2oB3Fh1EtgE1m0IHO7N2Xj3q1MhjrtnmjxCqHcpaA/NnP10mDNIWB niLglWg+YDTQl8gCMvO8mxN1+yD8KLFp+iCQNeC3uq6+FAiRVQTBXYX7j1CTGjeAgMRJ 3VRZvevDHvvAtoTZe7aIJ5T+XIb+/7SMbGu2hZzZ3aU5is1mbP3HW3/bDzu2qHhZb+r6 2s6e6AzTfevp3ZZ3UpoDa3B/BoCgORuTsLohhbLqEpQn/WTeHNPH3u+MDLvPPXv03A3B pckw== 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=+CYllznRYt133KTflL22y4PX2RmV6ZawSJvxIL4oFhI=; b=R7v6l9kd7NJhw1n084nlfqbAbLwB6m2n0oJ/9z6iDj26c3X985K1dCR9X82zAPb/k1 bKAE/H71dULDvWDlxj6WBOrbhijBo5QpRGlfoaFRwlzr2+1ah/5K06pUJYxlE+B9NXxx jvLSFsYi77ulgxaQVmEW9C13pYoBaoNScYP/8U96nbIKW1F126PrUQyRlFYoyp6D3vbq PO+EOCBUWCdqL/RC1l1v6k2AAOUtEJpwbLxlTmJ5lKFlPLH8fpGtKpJd7g5nSpBEPhTE ezdFtN/4bcItImW7SiVEyvatVRblWELbR0zqFdlKPaRB+lShPYmEguJypOvFPub4RgoI h5Uw== X-Gm-Message-State: AJcUukeeQAhh+4ObLM7NXfEw5zjyADp3KuaKlSrjOc6LJKG8k76qlglM 2h7tepid9kX4D3PHfcxXYrI= X-Google-Smtp-Source: ALg8bN4ZoDLupjfEqshy8up98rOi636cGtoFBdatp7hFnV7CO27XwPFdkXdw5MOeuLLkp2/uT4xhAw== X-Received: by 2002:a2e:8951:: with SMTP id b17-v6mr10570925ljk.142.1548438655548; Fri, 25 Jan 2019 09:50:55 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:6921:1f1d:2918:d853]) by smtp.googlemail.com with ESMTPSA id l21-v6sm1575606ljj.48.2019.01.25.09.50.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Jan 2019 09:50:54 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: dmitry.torokhov@gmail.com Cc: robh+dt@kernel.org, mark.rutland@arm.com, mchehab+samsung@kernel.org, colyli@suse.de, ckeepax@opensource.wolfsonmicro.com, andrew.smirnov@gmail.com, arnd@arndb.de, xiaotong.lu@spreadtrum.com, xc-racer2@live.ca, pawel.mikolaj.chmiel@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 4/4] dt-bindings: input: Add documentation for gp2a sensor Date: Fri, 25 Jan 2019 18:50:45 +0100 Message-Id: <20190125175045.22576-5-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190125175045.22576-1-pawel.mikolaj.chmiel@gmail.com> References: <20190125175045.22576-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 This commit adds documentation for Sharp GP2AP002A00F. It's Proximity/Opto Sensor connected over i2c. Signed-off-by: Jonathan Bakker Signed-off-by: Paweł Chmiel --- .../bindings/input/sharp,gp2ap002a00f.txt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/sharp,gp2ap002a00f.txt diff --git a/Documentation/devicetree/bindings/input/sharp,gp2ap002a00f.txt b/Documentation/devicetree/bindings/input/sharp,gp2ap002a00f.txt new file mode 100644 index 000000000000..c524eb7d3d60 --- /dev/null +++ b/Documentation/devicetree/bindings/input/sharp,gp2ap002a00f.txt @@ -0,0 +1,29 @@ +* Sharp GP2AP002A00F I2C Proximity/Opto Sensor + +Required properties: +- compatible : Should be "sharp,gp2ap002a00f" +- reg : The I2C address of the sensor +- vout-gpio : The gpio connected to the vout pin +- interrupt-parent : should be the phandle for the interrupt controller +- interrupts : Interrupt mapping for GPIO IRQ, it should by configured with + flags IRQ_TYPE_EDGE_BOTH + +Optional properties: +- wakeup : If the device is capable of waking up the system +- io-channels : Phandle to an ADC channel connected to the light sensor +- io-channel-names = "light"; +- poll-interval : Poll interval time in milliseconds, default 500ms +- light-adc-max : Maximum light value reported, default 4096 +- light-adc-fuzz : Fuzz value for reported light value, default 80 + +Example: + +gp2a@44 { + compatible = "sharp,gp2ap002a00f"; + reg = <0x44>; + vout-gpio = <&gph0 2 GPIO_ACTIVE_HIGH>; + interrupt-parent = <&gph0>; + interrupts = <2 IRQ_TYPE_EDGE_BOTH>; + io-channels = <&adc 9>; + io-channel-names = "light"; +};