From patchwork Thu Aug 1 07:35:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuhong Yuan X-Patchwork-Id: 11070199 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 BBC0014E5 for ; Thu, 1 Aug 2019 07:36:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD23B26E1A for ; Thu, 1 Aug 2019 07:36:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0F4626E90; Thu, 1 Aug 2019 07:36:05 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,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 53F0226E1A for ; Thu, 1 Aug 2019 07:36:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730273AbfHAHgE (ORCPT ); Thu, 1 Aug 2019 03:36:04 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38478 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbfHAHgE (ORCPT ); Thu, 1 Aug 2019 03:36:04 -0400 Received: by mail-pf1-f193.google.com with SMTP id y15so33542312pfn.5; Thu, 01 Aug 2019 00:36:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=597pY9Kj5buXouikKKcPGi6CbrKSQkJ/79MmJjTSgIc=; b=GazRMYuiUG6jfbiu9xtaR/nAmPosdElzAPRrMgo0PeB3sVkZmtZmawRo964S/f3IJw T5V0yytJEo62VgwA2kxCfVsO4espuJlumlFYNhmHmSiKgwUMv1Rv8lOS47d1LMze5CnK hDUzlKuppcPHS9CPzTeaCNDhP7fp1t6Gbk6pPdmqai6E1gmQBTzwQrt5+A0WEYa2HroH EDLrOtJZ+tQ/avhroiKLab+nRVyIiSnNgBsSIrtQDe+BgXiY5Qkbx4SrJ9v+azzdywAc KEs8gXXNZLSJwYIzA67+9mbm4zsf23DqjG7do5jP2Le2wsfHU17m+/P4ZwjMJ4WonaMr uTEw== 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:mime-version :content-transfer-encoding; bh=597pY9Kj5buXouikKKcPGi6CbrKSQkJ/79MmJjTSgIc=; b=EYfmQxbdNP5NNWhvVFd/Wq8hfsPovBGsSDsjuBdcDzGRwMHyvD+lG3UFCS62r64CHz hWIsYUbfZ9leVZIn3ZPmcQFuu6OvHhi8WlJeVahVIxpTcCVcPIB7UYzO73GiGi0vAg+5 TEjY7yV91XE3kmX9cf1TC2yzmK//kTye4MZ1fVRibQIrAkycahWVjt3JH2uLjYzHAzgE Ec/+4+wg8iqb6+ZZDXH+I8xbpDaKUGC+pUinjLwfNkwzm71DWh5jv3p6oIE72VHtkjXr pfMjKVSIx6TQhypTHu9CWYeQY1Qrn4NLB/WQlE/dUw4JQ0k4UV2FR4jaiBWsPCMNTKh2 DeXQ== X-Gm-Message-State: APjAAAWFGRDCiF2HJP4NsHVrLOhubMcik6ihdcCEWOGspnXKLOjk9gwY wyw8ELmRfoNjtV5OvCQsgpo= X-Google-Smtp-Source: APXvYqxqyW4nnGI/FudfI2dJfNy9z6omFHUN1l/3nOWQ16bOZV/E2/92mI2cwI0Nk1QsddPgT9pdQQ== X-Received: by 2002:a62:5253:: with SMTP id g80mr51416327pfb.179.1564644964064; Thu, 01 Aug 2019 00:36:04 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id 81sm64899993pfa.86.2019.08.01.00.36.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 00:36:03 -0700 (PDT) From: Chuhong Yuan Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Brian Masney , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v4 1/4] iio: tsl2772: Use devm_add_action_or_reset Date: Thu, 1 Aug 2019 15:35:57 +0800 Message-Id: <20190801073557.9578-1-hslester96@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use devm_add_action_or_reset to remove the call to tsl2772_disable_regulators_action to simplify the error path. Signed-off-by: Chuhong Yuan Reviewed-by: Brian Masney Tested-by: Brian Masney --- Changes in v4: - Split v3 into three patches. - Revise description to make it more precise. drivers/iio/light/tsl2772.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c index 83cece921843..29cfd8ae2700 100644 --- a/drivers/iio/light/tsl2772.c +++ b/drivers/iio/light/tsl2772.c @@ -1807,10 +1807,10 @@ static int tsl2772_probe(struct i2c_client *clientp, return PTR_ERR(chip->vdd_supply); } - ret = devm_add_action(&clientp->dev, tsl2772_disable_regulators_action, - chip); + ret = devm_add_action_or_reset(&clientp->dev, + tsl2772_disable_regulators_action, + chip); if (ret < 0) { - tsl2772_disable_regulators_action(chip); dev_err(&clientp->dev, "Failed to setup regulator cleanup action %d\n", ret); return ret; From patchwork Thu Aug 1 07:36:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuhong Yuan X-Patchwork-Id: 11070201 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 6F14F14E5 for ; Thu, 1 Aug 2019 07:36:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6139F28488 for ; Thu, 1 Aug 2019 07:36:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 554CC28492; Thu, 1 Aug 2019 07:36:12 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,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 040F728488 for ; Thu, 1 Aug 2019 07:36:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730916AbfHAHgL (ORCPT ); Thu, 1 Aug 2019 03:36:11 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:42830 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbfHAHgL (ORCPT ); Thu, 1 Aug 2019 03:36:11 -0400 Received: by mail-pf1-f194.google.com with SMTP id q10so33519120pff.9; Thu, 01 Aug 2019 00:36:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FEKRFdCKMpkSeVMIdG4ipy7CLi0KrDkFAlXZaWu5PvE=; b=QYIPysX3gk7gePWu04a+uSdFFoECYk9d4x7/ixCMLdWbWsxKefmv4UOXOAx2qZoKdz XZVDLd+G4Nr3SbkCiwypxC93qWVuZxG/jH1ejT1g/Hi5U3UG/A+PI7ZN2eR7TTDqwjPL 5EmiHAT6IqEqIi3IDrkvYuCDyht8SnnNAoSZn8wS5QgZ2VyPMBjHESGYbTwaOZAvtxnG mArp7Oal41UErDsI+W9jp4ETWvRFK73LJKqgnFnN0PR92/o162HnPrn3SD5G63/P1HNa tBBAVnJ8Lk2B29yIcVApDPfIWO2CKzZfEcXh/lk+KeHUsLWWKlEH+vSxY0lQRsYcK0zz VTkQ== 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:mime-version :content-transfer-encoding; bh=FEKRFdCKMpkSeVMIdG4ipy7CLi0KrDkFAlXZaWu5PvE=; b=DNDcMmJwtmInoYFD3NReVhHPxrAeqbM5sxLPGG6HlxugD/JLFcSQ7rnzLryLw5jKuz 5+pRGIZwqBaalDUo5s9oJMFxoxyv4h9bqCkzqAJvAtpRGYGzGFgMtDyI23uA0lRpIY5Q yqL8mUzxfnGg08KIlDIxi/mfmE6u/7BAJh9YiPAnTv5QkK6cB+b6TWgTLIQCtxHE/SRV 4SttNhhxp5L56F4BEgh6LolYLOIrxrLiTxGMyrLSNj0Qmwh4QbR6A+IwHeedB91aAuH/ QX0/d/Jm30la69sGUVvRlVZRwpL0uTZ8uGknrYitbob+Sah3L2FYdHtbr06V+HODunbM HuzA== X-Gm-Message-State: APjAAAW+CLdl4Tbc2w98c4KZYc63VDbfi4GqTwUp6LEqgKRtNDdfJ5x2 mXO4tuD9jm58280MWvIueis= X-Google-Smtp-Source: APXvYqyEdZc4RRfJnxFx0LwafaLBOctTzJ6k8b1ZC6wiPksEt3+pnArkk58FuDvqCNOKLh/0S66L8A== X-Received: by 2002:a63:dd0b:: with SMTP id t11mr77496230pgg.410.1564644970565; Thu, 01 Aug 2019 00:36:10 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id e13sm88345565pff.45.2019.08.01.00.36.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 00:36:10 -0700 (PDT) From: Chuhong Yuan Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Brian Masney , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v4 2/4] iio: tsl2772: Use devm_add_action_or_reset for tsl2772_chip_off Date: Thu, 1 Aug 2019 15:36:05 +0800 Message-Id: <20190801073605.9635-1-hslester96@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use devm_add_action_or_reset to call tsl2772_chip_off when the device is removed. This also fixes the issue that the chip is turned off before the device is unregistered. Fixes: 4e24c1719f34 ("staging: iio: tsl2x7x: rename driver to tsl2772") Signed-off-by: Chuhong Yuan --- Changes in v4: - Split v3 into three patches. - Revise description to make it more precise. drivers/iio/light/tsl2772.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c index 29cfd8ae2700..e866ae40f157 100644 --- a/drivers/iio/light/tsl2772.c +++ b/drivers/iio/light/tsl2772.c @@ -860,6 +860,13 @@ static int tsl2772_chip_off(struct iio_dev *indio_dev) return tsl2772_write_control_reg(chip, 0x00); } +static void tsl2772_chip_off_action(void *data) +{ + struct iio_dev *indio_dev = data; + + tsl2772_chip_off(indio_dev); +} + /** * tsl2772_invoke_change - power cycle the device to implement the user * parameters @@ -1877,9 +1884,14 @@ static int tsl2772_probe(struct i2c_client *clientp, if (ret < 0) return ret; + ret = devm_add_action_or_reset(&clientp->dev, + tsl2772_chip_off_action, + indio_dev); + if (ret < 0) + return ret; + ret = iio_device_register(indio_dev); if (ret) { - tsl2772_chip_off(indio_dev); dev_err(&clientp->dev, "%s: iio registration failed\n", __func__); return ret; @@ -1926,8 +1938,6 @@ static int tsl2772_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); - tsl2772_chip_off(indio_dev); - iio_device_unregister(indio_dev); return 0; From patchwork Thu Aug 1 07:36:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuhong Yuan X-Patchwork-Id: 11070203 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 1E96813A0 for ; Thu, 1 Aug 2019 07:36:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 106942848F for ; Thu, 1 Aug 2019 07:36:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04A4E28495; Thu, 1 Aug 2019 07:36:19 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,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 A72A42848F for ; Thu, 1 Aug 2019 07:36:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730328AbfHAHgS (ORCPT ); Thu, 1 Aug 2019 03:36:18 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:46068 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbfHAHgR (ORCPT ); Thu, 1 Aug 2019 03:36:17 -0400 Received: by mail-pl1-f196.google.com with SMTP id y8so31819296plr.12; Thu, 01 Aug 2019 00:36:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=v/gvKPwp4eeyfrmzYZ9gkfiwDX7eYIoi/YCwtEUkbyQ=; b=j0wCGZR08O0pbBhOW87OhXo3bh1GJ00hPYvCIFHV7GkKEtiTqjBUfnX7arW9O5d5iC zVzDz+1bMiA70Jxh1CP0EmqNkn8/UEAOoSC3VkxMJBj3V44iCx9OFSZlT1v6ljvMRMIo gwbJOMFzueepLb/QxjRm0fgCMNdrjz3D2DJZ7vfBJDvFwXyIl9QXxBuPl5EWN1NT4kTj bXIooDgCcYsQHrC8YWmnSQd/bcBVC4txp8CAkTNpZGVtadNlZvvDfYgXLxBW6K0o2iSs WonAJruTCuXCOQ27C0/HjCYx8JFBPTqXyEbOh82Fpeh+RFUGeXSEaDCf1rQcHTKsxPsH CEyg== 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:mime-version :content-transfer-encoding; bh=v/gvKPwp4eeyfrmzYZ9gkfiwDX7eYIoi/YCwtEUkbyQ=; b=ac0dJxapin1FMUlvg3Wl2ju7E0YhGgFew28tH2SuyYNg4yyVSHGlTlnZvrUOHCZkk3 5a6Sqrj1Egh6LuWksxHg+JfJPe/Q7uqhdlLFWBP6W1CU58h1mzgyDN/DcUnIGl9ZAaQV +Av5vQslvm2AzYTomuSAcoSPvlAy59xrA3JrZIFxK65ipSn+J+zm6Yi17W4JKlvhtRH6 bYbat9S5bR0ULXitWBGtuZKS6Twp59vDe+q9pYy5Bx8LYQPzdHTSIicFrpTS/Guznpsa 1b+k3k+X5zTWRxQzEuNscQr1xLfte8f6P8CklZzzTtdxiw4ZtacWENe5E8BaDpvI7Wfd 5Feg== X-Gm-Message-State: APjAAAW3epSNWzpFyA5BTO8X/ZFEgyrN3jQLvxfoSAM/JHZC5ubVYc1O uA0hR/59eKPnViUNVUmOHNI= X-Google-Smtp-Source: APXvYqyHgg7EzKTsVbuQjwY4rn99nm6rfwVtef+hW6GWR8QaoF1JCi2lMX3QescCrLBSS+hKg41bxg== X-Received: by 2002:a17:902:4643:: with SMTP id o61mr95913407pld.101.1564644977294; Thu, 01 Aug 2019 00:36:17 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id q198sm74635337pfq.155.2019.08.01.00.36.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 00:36:16 -0700 (PDT) From: Chuhong Yuan Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Brian Masney , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v4 3/4] iio: tsl2772: Use devm_iio_device_register Date: Thu, 1 Aug 2019 15:36:12 +0800 Message-Id: <20190801073612.9689-1-hslester96@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use devm_iio_device_register, which removes the tsl2772_remove function. Signed-off-by: Chuhong Yuan --- Changes in v4: - Split v3 into three patches. - Revise description to make it more precise. drivers/iio/light/tsl2772.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c index e866ae40f157..680afdb078d2 100644 --- a/drivers/iio/light/tsl2772.c +++ b/drivers/iio/light/tsl2772.c @@ -1890,14 +1890,7 @@ static int tsl2772_probe(struct i2c_client *clientp, if (ret < 0) return ret; - ret = iio_device_register(indio_dev); - if (ret) { - dev_err(&clientp->dev, - "%s: iio registration failed\n", __func__); - return ret; - } - - return 0; + return devm_iio_device_register(&clientp->dev, indio_dev); } static int tsl2772_suspend(struct device *dev) @@ -1934,15 +1927,6 @@ static int tsl2772_resume(struct device *dev) return tsl2772_chip_on(indio_dev); } -static int tsl2772_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - - return 0; -} - static const struct i2c_device_id tsl2772_idtable[] = { { "tsl2571", tsl2571 }, { "tsl2671", tsl2671 }, @@ -1989,7 +1973,6 @@ static struct i2c_driver tsl2772_driver = { }, .id_table = tsl2772_idtable, .probe = tsl2772_probe, - .remove = tsl2772_remove, }; module_i2c_driver(tsl2772_driver); From patchwork Thu Aug 1 07:36:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuhong Yuan X-Patchwork-Id: 11070205 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 56BE113A0 for ; Thu, 1 Aug 2019 07:36:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 478CD28488 for ; Thu, 1 Aug 2019 07:36:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BA1A28492; Thu, 1 Aug 2019 07:36:27 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,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 BA04428488 for ; Thu, 1 Aug 2019 07:36:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726407AbfHAHg0 (ORCPT ); Thu, 1 Aug 2019 03:36:26 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:39147 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbfHAHg0 (ORCPT ); Thu, 1 Aug 2019 03:36:26 -0400 Received: by mail-pf1-f196.google.com with SMTP id f17so29540511pfn.6; Thu, 01 Aug 2019 00:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=aDlg6KGiZjR/ZSqeO5LTT2diSeBDVpED/ds/lS7zO2Y=; b=TJAoCm+UV+/2N1KYfLrH18ZxUdT3KzN4coCEAXjX2HjMl0nI1vdCa4rKkm3NGaj9/Q 8wGxgsBegOEjI92eppUvuksLq0WABzawI69B8DNzpWrwKJL2z8qcco6Y9qYvFF4Psygi V0MPBtR6OYAjMHNcQ2aHbiOarOSBPJQNFdiDF+MctHnC8ShKgYcJR/Mc8WzN1z8+bDf6 lR4rwDCPUX5Oq7SiMlMQOhbmOZa+UhJlnPPszblkCRYtucXmxwFopLtjTn6eFo6EoR9V whYRsKju+D8sm3wstEj+5rXTO60akotme0uadfVk8z68oLDn5JyumPJHlqcUP2hv9lPm E2qw== 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:mime-version :content-transfer-encoding; bh=aDlg6KGiZjR/ZSqeO5LTT2diSeBDVpED/ds/lS7zO2Y=; b=OjYNgnWvPXRAoqo2Ly8UI2bo6e/0ARz3ZdWpRZrT/WMwJWBB9mq17h60/arygmFawH VRm4FPxvOTM5ILG71idaRIZbGToXkmOl4tv+kWb0d4DSJP00fbfsobviSvxEiO87UWbk dXg453kZb70I2Jhdc5H0AjxqpKY/rSkg73KCMtHWmSOKA6DkGc0VWnB+A/qTNZM7eW5s lzlO5pmEb8POFNT/+JPImHHO8OGAF6+xtfqzBXqWC6IEBDwZ9q4Hf1OOviXc8uMEQz6m hB62vKn8mMzRoTtma+718b7fDRnEtFe88hImphYrVQe2RPHsuB7BmkL3Rc15x7Xqz94Z VipA== X-Gm-Message-State: APjAAAUGjaXbWI316gTgwLv+Vg4zOxfh/T32rzsAbcNf0LG34sh3gv9q EJu2ROWqtw73R0C/MAzaAJ4= X-Google-Smtp-Source: APXvYqwPTee4ZVGW/6xy7FMMXOeGLJQAy4y1fWk4sVlP9/l6uhQL8NgD/P6GePdM3bGUPAo3Uvh4Cw== X-Received: by 2002:aa7:81d9:: with SMTP id c25mr52604884pfn.255.1564644985107; Thu, 01 Aug 2019 00:36:25 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id h70sm65467748pgc.36.2019.08.01.00.36.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 00:36:24 -0700 (PDT) From: Chuhong Yuan Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Brian Masney , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v4 4/4] iio: tsl2772: Use regulator_bulk_() APIs Date: Thu, 1 Aug 2019 15:36:19 +0800 Message-Id: <20190801073619.9743-1-hslester96@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use regulator_bulk_() APIs to shrink driver size. Signed-off-by: Chuhong Yuan --- Changes in v4: - Change the var name of regulator_bulk_data. - Adjust alignment. - Add a new line between two if blocks. drivers/iio/light/tsl2772.c | 87 +++++++++++++------------------------ 1 file changed, 29 insertions(+), 58 deletions(-) diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c index 680afdb078d2..be37fcbd4654 100644 --- a/drivers/iio/light/tsl2772.c +++ b/drivers/iio/light/tsl2772.c @@ -134,6 +134,12 @@ enum { TSL2772_CHIP_SUSPENDED = 2 }; +enum { + TSL2772_SUPPLY_VDD = 0, + TSL2772_SUPPLY_VDDIO = 1, + TSL2772_NUM_SUPPLIES = 2 +}; + /* Per-device data */ struct tsl2772_als_info { u16 als_ch0; @@ -161,8 +167,7 @@ struct tsl2772_chip { struct mutex prox_mutex; struct mutex als_mutex; struct i2c_client *client; - struct regulator *vdd_supply; - struct regulator *vddio_supply; + struct regulator_bulk_data supplies[TSL2772_NUM_SUPPLIES]; u16 prox_data; struct tsl2772_als_info als_cur_info; struct tsl2772_settings settings; @@ -697,46 +702,7 @@ static void tsl2772_disable_regulators_action(void *_data) { struct tsl2772_chip *chip = _data; - regulator_disable(chip->vdd_supply); - regulator_disable(chip->vddio_supply); -} - -static int tsl2772_enable_regulator(struct tsl2772_chip *chip, - struct regulator *regulator) -{ - int ret; - - ret = regulator_enable(regulator); - if (ret < 0) { - dev_err(&chip->client->dev, "Failed to enable regulator: %d\n", - ret); - return ret; - } - - return 0; -} - -static struct regulator *tsl2772_get_regulator(struct tsl2772_chip *chip, - char *name) -{ - struct regulator *regulator; - int ret; - - regulator = devm_regulator_get(&chip->client->dev, name); - if (IS_ERR(regulator)) { - if (PTR_ERR(regulator) != -EPROBE_DEFER) - dev_err(&chip->client->dev, - "Failed to get %s regulator %d\n", - name, (int)PTR_ERR(regulator)); - - return regulator; - } - - ret = tsl2772_enable_regulator(chip, regulator); - if (ret < 0) - return ERR_PTR(ret); - - return regulator; + regulator_bulk_disable(ARRAY_SIZE(chip->supplies), chip->supplies); } static int tsl2772_chip_on(struct iio_dev *indio_dev) @@ -1804,14 +1770,26 @@ static int tsl2772_probe(struct i2c_client *clientp, chip->client = clientp; i2c_set_clientdata(clientp, indio_dev); - chip->vddio_supply = tsl2772_get_regulator(chip, "vddio"); - if (IS_ERR(chip->vddio_supply)) - return PTR_ERR(chip->vddio_supply); + chip->supplies[TSL2772_SUPPLY_VDD].supply = "vdd"; + chip->supplies[TSL2772_SUPPLY_VDDIO].supply = "vddio"; - chip->vdd_supply = tsl2772_get_regulator(chip, "vdd"); - if (IS_ERR(chip->vdd_supply)) { - regulator_disable(chip->vddio_supply); - return PTR_ERR(chip->vdd_supply); + ret = devm_regulator_bulk_get(&clientp->dev, + ARRAY_SIZE(chip->supplies), + chip->supplies); + if (ret < 0) { + if (ret != -EPROBE_DEFER) + dev_err(&clientp->dev, + "Failed to get regulators: %d\n", + ret); + + return ret; + } + + ret = regulator_bulk_enable(ARRAY_SIZE(chip->supplies), chip->supplies); + if (ret < 0) { + dev_err(&clientp->dev, "Failed to enable regulators: %d\n", + ret); + return ret; } ret = devm_add_action_or_reset(&clientp->dev, @@ -1900,8 +1878,7 @@ static int tsl2772_suspend(struct device *dev) int ret; ret = tsl2772_chip_off(indio_dev); - regulator_disable(chip->vdd_supply); - regulator_disable(chip->vddio_supply); + regulator_bulk_disable(ARRAY_SIZE(chip->supplies), chip->supplies); return ret; } @@ -1912,16 +1889,10 @@ static int tsl2772_resume(struct device *dev) struct tsl2772_chip *chip = iio_priv(indio_dev); int ret; - ret = tsl2772_enable_regulator(chip, chip->vddio_supply); + ret = regulator_bulk_enable(ARRAY_SIZE(chip->supplies), chip->supplies); if (ret < 0) return ret; - ret = tsl2772_enable_regulator(chip, chip->vdd_supply); - if (ret < 0) { - regulator_disable(chip->vddio_supply); - return ret; - } - usleep_range(TSL2772_BOOT_MIN_SLEEP_TIME, TSL2772_BOOT_MAX_SLEEP_TIME); return tsl2772_chip_on(indio_dev);