From patchwork Thu Dec 13 06:18:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anson Huang X-Patchwork-Id: 10728065 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 13CD514BD for ; Thu, 13 Dec 2018 06:18:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB30729B58 for ; Thu, 13 Dec 2018 06:18:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEFCA29EB0; Thu, 13 Dec 2018 06:18:15 +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,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 AF8D729B58 for ; Thu, 13 Dec 2018 06:18:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726729AbeLMGSN (ORCPT ); Thu, 13 Dec 2018 01:18:13 -0500 Received: from mail-eopbgr60080.outbound.protection.outlook.com ([40.107.6.80]:51744 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726542AbeLMGSN (ORCPT ); Thu, 13 Dec 2018 01:18:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mBuouQq9oX/xhf4zhpnNd0flUFxnOkJf8oAZ7I9nGc4=; b=A4/SQ8k1PqxltWgSUwQZye2kTxIc0YBkal5hXHwNSZdgGgC6BlwiJRxJ+8Zwdp5wfyY5KFrPhSW5HUiQmJaRqcRmTzjLfrzeOOFvgTNqQ4O4Y+ZBwk//GSUqEVwYxFq/C47VxEc037uFrAGvoXSwYA9MPgf8czAogjokdBx0nWY= Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com (52.134.72.18) by DB3PR0402MB3929.eurprd04.prod.outlook.com (52.134.70.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.19; Thu, 13 Dec 2018 06:18:07 +0000 Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::adf8:f49d:deb4:58fd]) by DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::adf8:f49d:deb4:58fd%3]) with mapi id 15.20.1425.016; Thu, 13 Dec 2018 06:18:07 +0000 From: Anson Huang To: "jic23@kernel.org" , "knaack.h@gmx.de" , "lars@metafoo.de" , "pmeerw@pmeerw.net" , "linux-iio@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "festevam@gmail.com" , "preid@electromag.com.au" CC: dl-linux-imx Subject: [PATCH V6] iio: light: isl29018: add optional vcc regulator operation support Thread-Topic: [PATCH V6] iio: light: isl29018: add optional vcc regulator operation support Thread-Index: AQHUkqud8y4XSsxEr0uoMW5Daqk9NQ== Date: Thu, 13 Dec 2018 06:18:07 +0000 Message-ID: <1544681529-22268-1-git-send-email-Anson.Huang@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: HK2PR03CA0056.apcprd03.prod.outlook.com (2603:1096:202:17::26) To DB3PR0402MB3916.eurprd04.prod.outlook.com (2603:10a6:8:10::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=anson.huang@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DB3PR0402MB3929;6:iv/LfId60lqePx4l+ObfopSAIWSu8tTxcluBoE76d/k3E1XNHxdj5xNrk5IaKIEC4f4L52Fm68tKYgRh9O9T2itF7ALUbGrOQhWwCzmvaFSPOzPs2/k5GVEnS0+NvEOwqw3oGcVIPABfe9Tvq3TyYO0gLRh+dbh80pia5z+P//gOdTcrXbzredc2V7OCSeo8ia4Hd3qCjUQzxvFYNsxcqGLlrO1Pd9dsvAirw7M7DyH4j8wLG7RRE5lrDpm0YYfeJapiRh3thrVnHngM+h8wsi45LThOPULBPVmVrKJkcAN2GZsqCsuBIbmPh50zUNLKHj9LV14dO/g5eFrqlj5BiVmqxCZCZEqlDyrjquxwSfKHWYrSLN7JchR1+NxSrmmqFx+2S55ePZMjeJeM8NfDZCS8yn+7aFlhU8RbXCoBC782w6VyYE8ONp+j8umL24ZvVG9xPMIOZ3LY7Pflxrhb5A==;5:d62GA53JBQnnNNpLq0QkiWAebEkpy9vLnBulN6gnZJuktwdY5VIpztOSFIFwmRhV86P8du1+Ealk4CE5yVUqEUblRP6/pKnncyuwY5izKV1kL+uGnGwmghCf0ufZGHPXa61mAmwmBQnxALLv+j4ZYJaSq2EsbsKKWz1xBFRah/I=;7:F8PFRApdOdn0AodpfLBcKGJOfKdCeIJ7hAzr76tmK5eVr+FSa2bOHyxvxqlRsnHqAlnTkqQPsx2HaXH+WsqT71+7Om+UBqOeKFyICBdwJc28O9lxL4szx3xS+yNODEjWlY4V5SOny7XZtAp7mWWC+w== x-ms-office365-filtering-correlation-id: a6c05300-c4a1-466c-93c9-08d660c2bf82 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:DB3PR0402MB3929; x-ms-traffictypediagnostic: DB3PR0402MB3929: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(3230021)(999002)(6040522)(2401047)(5005006)(8121501046)(3231475)(944501520)(52105112)(3002001)(93006095)(93001095)(10201501046)(6055026)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(201708071742011)(7699051)(76991095);SRVR:DB3PR0402MB3929;BCL:0;PCL:0;RULEID:;SRVR:DB3PR0402MB3929; x-forefront-prvs: 088552DE73 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(366004)(39860400002)(136003)(396003)(346002)(376002)(54534003)(189003)(199004)(486006)(53936002)(6436002)(99286004)(6512007)(8676002)(478600001)(81166006)(4326008)(97736004)(81156014)(105586002)(6486002)(8936002)(316002)(39060400002)(86362001)(25786009)(50226002)(71190400001)(36756003)(476003)(71200400001)(110136005)(2501003)(106356001)(2616005)(66066001)(102836004)(2906002)(52116002)(14444005)(256004)(186003)(26005)(68736007)(14454004)(3846002)(7736002)(6116002)(2201001)(6506007)(386003)(305945005)(5660300001);DIR:OUT;SFP:1101;SCL:1;SRVR:DB3PR0402MB3929;H:DB3PR0402MB3916.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: dP6tvD81YyeiB8xW0h71J+ornVS5wLftEdF08Mi1CPhQ7O7tB8cMMwum86IVjFXnIF2H1FE/52h1/PJTZ5pPiRxEosqv5SaMM85zS4Y8HfVEQcmXKSXtWhHbKN8cBFKFXh3jPIh6KzI+RdSoYU9LtENtmBaiqefKhb2JQio7oWzOYZW8KFCNmvg8YU+m57CLDcIDATZQ4IDVEYOMa3x/GjtNpG6Gehjov9IvpBoxowp7W0CRBPsVySq/wz1k8oP3WwzQUWo8zPPdIRzg9piqy7kAs+9zi0pfebMvRiU6Vw22mPj/qOGyR8Va6FW+00vS spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6c05300-c4a1-466c-93c9-08d660c2bf82 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Dec 2018 06:18:07.6585 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0402MB3929 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 The light sensor's power supply could be controlled by regulator on some platforms, such as i.MX6Q-SABRESD board, the light sensor isl29023's power supply is controlled by a GPIO fixed regulator, need to make sure the regulator is enabled before any operation of sensor, this patch adds optional vcc regulator operation support. Signed-off-by: Anson Huang --- ChangeLog since V5: Since the dt-binding doc states the power supply name is "vdd" and many dts files already using "vcc" as the power supply name, althoug it does NOT match the datasheet which has "vdd", to make it NOT breaking existing dtb files, just use "vcc" as the regulator name. --- drivers/iio/light/isl29018.c | 47 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/drivers/iio/light/isl29018.c b/drivers/iio/light/isl29018.c index b45400f..76c3a48 100644 --- a/drivers/iio/light/isl29018.c +++ b/drivers/iio/light/isl29018.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -95,6 +96,7 @@ struct isl29018_chip { struct isl29018_scale scale; int prox_scheme; bool suspended; + struct regulator *vcc_reg; }; static int isl29018_set_integration_time(struct isl29018_chip *chip, @@ -735,6 +737,19 @@ static int isl29018_probe(struct i2c_client *client, mutex_init(&chip->lock); + chip->vcc_reg = devm_regulator_get_optional(&client->dev, "vcc"); + if (!IS_ERR(chip->vcc_reg)) { + err = regulator_enable(chip->vcc_reg); + if (err) { + dev_err(&client->dev, "failed to enable VCC regulator\n"); + return err; + } + } else { + err = PTR_ERR(chip->vcc_reg); + if (err != -ENODEV) + return err; + } + chip->type = dev_id; chip->calibscale = 1; chip->ucalibscale = 0; @@ -747,12 +762,12 @@ static int isl29018_probe(struct i2c_client *client, if (IS_ERR(chip->regmap)) { err = PTR_ERR(chip->regmap); dev_err(&client->dev, "regmap initialization fails: %d\n", err); - return err; + goto disable_regulator; } err = isl29018_chip_init(chip); if (err) - return err; + goto disable_regulator; indio_dev->info = isl29018_chip_info_tbl[dev_id].indio_info; indio_dev->channels = isl29018_chip_info_tbl[dev_id].channels; @@ -761,13 +776,22 @@ static int isl29018_probe(struct i2c_client *client, indio_dev->dev.parent = &client->dev; indio_dev->modes = INDIO_DIRECT_MODE; - return devm_iio_device_register(&client->dev, indio_dev); + err = devm_iio_device_register(&client->dev, indio_dev); + if (!err) + return 0; + +disable_regulator: + if (!IS_ERR(chip->vcc_reg)) + regulator_disable(chip->vcc_reg); + + return err; } #ifdef CONFIG_PM_SLEEP static int isl29018_suspend(struct device *dev) { struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev)); + int ret; mutex_lock(&chip->lock); @@ -777,6 +801,14 @@ static int isl29018_suspend(struct device *dev) * So we do not have much to do here. */ chip->suspended = true; + if (!IS_ERR(chip->vcc_reg)) { + ret = regulator_disable(chip->vcc_reg); + if (ret) { + dev_err(dev, "failed to disable VCC regulator\n"); + mutex_unlock(&chip->lock); + return ret; + } + } mutex_unlock(&chip->lock); @@ -790,6 +822,15 @@ static int isl29018_resume(struct device *dev) mutex_lock(&chip->lock); + if (!IS_ERR(chip->vcc_reg)) { + err = regulator_enable(chip->vcc_reg); + if (err) { + dev_err(dev, "failed to enable VCC regulator\n"); + mutex_unlock(&chip->lock); + return err; + } + } + err = isl29018_chip_init(chip); if (!err) chip->suspended = false;