Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2190524imu; Sun, 16 Dec 2018 19:26:57 -0800 (PST) X-Google-Smtp-Source: AFSGD/XUt8Pjn69txVIirdmfnz0bAOzBAxQHhXAUxOE7hnC8y5EUl3MfuGmSZta4SsbLorBqiU/l X-Received: by 2002:a62:7796:: with SMTP id s144mr11379030pfc.26.1545017217557; Sun, 16 Dec 2018 19:26:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545017217; cv=none; d=google.com; s=arc-20160816; b=1BQvkvj/nPrnGzRiShmS9cB9IhumjbxNNgP1ZxrdIkpz0OgDsJ3lcAtprjn8rYCNSm MkGwTombqQE1ejDmWTZybm07gdp3PNSM0D5gHPFTNIKK1ueCuwB5ut5y6tMZuTVhhtFu YTZ+cKEIPPxT4ORIKDfh6hAYQFZVIvVNH2ckiEnIXTVTt1tnyFbJTfny9o3z65f+yOmK +hp7roeRl2yhTcqKlklPYPDLUuNUtFbD3pazGDk9RhOKVd5IQtwUWUX5o27FVM9r2UJP kcMvAYrfLCe3FVnd0wCKATFyINnxItBf5o1FmjpReJADfWHuatOdtnt4IhdHivUcM/MR uUUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:message-id:date:thread-index:thread-topic:subject :cc:to:from:dkim-signature; bh=LRADkM+JTsQwiSMAy8JruNmHI8jNZoO2jb0bkJMAVZ4=; b=Mc2rXrYGmIdKwb64SbOfXdyfeb0lw4WAXQWTVs18r7xoSK3YYFehlMOL8lmYt68VCl tMA/Zm/3e3r3mYvkF6S5nVzfIGuEdQUk1CQeDJ31BTlbxp872bN97/ygc9JVXbPcZOU4 FlddwDf8CLiA2Kt1+0SvpM5kjQubUQdlLYX+hK/IEga/YIAi7LMw/S+doVN/XQpoWcO8 YVZclMwU04QV3lm+RwCHnDerv1I2xdh/L5X5HcyB6NZK1yE++53qqifE3Wrn865UG5rK mFBJ+ttpaDcPeO8t4rXjBbJfoimyEM7PJq+Y/MNh+uuU6AmyhFBs6GgCCZ4UmQ3odJMG CuFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=A1dAGTqE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9si10288314pgb.105.2018.12.16.19.26.42; Sun, 16 Dec 2018 19:26:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=A1dAGTqE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726387AbeLQDZY (ORCPT + 99 others); Sun, 16 Dec 2018 22:25:24 -0500 Received: from mail-eopbgr40083.outbound.protection.outlook.com ([40.107.4.83]:11587 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726267AbeLQDZY (ORCPT ); Sun, 16 Dec 2018 22:25:24 -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=LRADkM+JTsQwiSMAy8JruNmHI8jNZoO2jb0bkJMAVZ4=; b=A1dAGTqEqB0b9NDCipAco0kyJ+HZvS1etTAfPR/3/eAPMvkmxxxZTzeaoWutAulNpjV2yqs6/pyU47FGt1BSzIiuvVv5TYuQ77471rpOLEF6VDsr08Xl4QgL01y1KTLXrKZOo8fa+SQvGRaoKGJh78xDPiQp2qFMI3m6MR4ZL60= Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com (52.134.72.18) by DB3PR0402MB3658.eurprd04.prod.outlook.com (52.134.65.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.19; Mon, 17 Dec 2018 03:25:17 +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.021; Mon, 17 Dec 2018 03:25:17 +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 V7] iio: light: isl29018: add vcc regulator operation support Thread-Topic: [PATCH V7] iio: light: isl29018: add vcc regulator operation support Thread-Index: AQHUlbghL8UoJu3CiUOnqyrpi++urw== Date: Mon, 17 Dec 2018 03:25:17 +0000 Message-ID: <1545016752-9865-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: HK0PR01CA0006.apcprd01.prod.exchangelabs.com (2603:1096:203:92::18) 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;DB3PR0402MB3658;6:Qah2zcJmZT5nx8PV4wpOsrl9/GhLlQyXY/OF/6GN71/xtXi2+yuvuIovspl0bbuUDbE4YMDTVbGk28gDKml1BHts/SHSoAOZo1maCMdsK7el/TrMP0QLg+uvdE/470BwUlu8P7lBxqGQGyTG98uQB8N/0G24lxpwqX5FEgHGjUr37W2IUhSdD2hJQp2iW30SmrIroQU9PFRdMdf8cZ0WidiiOIgIqqbclpL07PNth2+l9SqnrDTWwj/G5RIzxX14T546FgkUir7x3wqcm2tdAY2Aev0Y1J1v0zpcHoYVTrm8eABHu2e+DutJpgpt2n17/TaJn4eeBPaGcJulkafiqDrlIB+ri3gYpdBawTD7GrOT3Pj1kOwFwxuZxHYNz+qrFmztgtr4bnUxsq4eFDy0b/dE/9/IAvNU2Agrh3SgkOoPX0faQkkNlinS8mkL+9W4jHZRtLQy+F14sukYuluKfw==;5:qCFF9WUkWwmWXO8EFWo8TbtPmIhK5Rgl5JbXuZzPC2FJhPqYbXLVp/dAgKL6OUqMh7kwpxvK7puWMqN+0WjJGACQdDK6ftoIjfURjU7/ga3ru9vvGwQMUrHEWf66YtApCFQIXPJQvuPNqH0jvHF1oubxwihOWx/JK1qZFSY50UY=;7:gI4UoEXrOSOYPuAVEevxd088tu5TgUx9fRAUUQBP8p7Ewq40MVn4Ptc4Xk7KI8tiNzRagflTGtUB1335wdu/EJe7yLbiYWPc8unvEp3RRnJWNzwZcH0n1kv8V8yHIlO+Wu7AayCtfVRQttJbqhLrZw== x-ms-office365-filtering-correlation-id: 02912b1d-7287-4fec-0895-08d663cf440d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:DB3PR0402MB3658; x-ms-traffictypediagnostic: DB3PR0402MB3658: 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)(3002001)(3231475)(944501520)(52105112)(93006095)(93001095)(10201501046)(6055026)(148016)(149066)(150057)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051)(76991095);SRVR:DB3PR0402MB3658;BCL:0;PCL:0;RULEID:;SRVR:DB3PR0402MB3658; x-forefront-prvs: 08897B549D x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(136003)(366004)(346002)(376002)(39860400002)(54534003)(189003)(199004)(52314003)(6436002)(7736002)(25786009)(106356001)(97736004)(105586002)(68736007)(305945005)(6486002)(36756003)(99286004)(4326008)(39060400002)(6512007)(5660300001)(52116002)(14444005)(256004)(53936002)(316002)(110136005)(386003)(102836004)(81156014)(6506007)(2616005)(486006)(2906002)(86362001)(476003)(50226002)(2201001)(66066001)(2501003)(6116002)(478600001)(71190400001)(71200400001)(8936002)(3846002)(186003)(81166006)(14454004)(26005)(8676002);DIR:OUT;SFP:1101;SCL:1;SRVR:DB3PR0402MB3658;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: BrNTzDa3gdE3dP8WDZPm8CIlYAmgyV+NQPF25eyhumfub93Q4mlKQeCQQK7NXIEyCf6ak5o1VYYEWDbHbTlOeRDSE1cTTpnB+tM/KwOPOtcF0YvIA6nOIC9kp1ZIzMKV/bjkQHYZsTna3+EbznxenHXf5lZhVOwNI2Ct+N/pM1gF3oier6oD4D4NQBfRRDsTe0VY7xuxcCVVapybcgrOK5tGu+gJTalZ8fzuvC9/8iYaV7gK0xmO2SF9141jpe/WIZDHaKQmMjviT5wLRd1JKeBcmsBRB+e6Kdw6FvFJ9fonCxc/PoZ2Si+yPqLqEsZz spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02912b1d-7287-4fec-0895-08d663cf440d X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Dec 2018 03:25:17.5572 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0402MB3658 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The light sensor's power supply could be controllable 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 vcc regulator operation support. Signed-off-by: Anson Huang --- ChangeLog since V6 - using devm_regulator_get() instead of devm_regulator_get_optional() s= ince the regulator is there anyway, if dtb does NOT specify one, regulator framework will a= ssign dummy regulator for it; - Setup devm action for cleaning up regulator resource for error handli= ng. --- drivers/iio/light/isl29018.c | 58 ++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 58 insertions(+) diff --git a/drivers/iio/light/isl29018.c b/drivers/iio/light/isl29018.c index b45400f..63f7b9d 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; }; =20 static int isl29018_set_integration_time(struct isl29018_chip *chip, @@ -708,6 +710,17 @@ static const char *isl29018_match_acpi_device(struct d= evice *dev, int *data) return dev_name(dev); } =20 +static void isl29018_disable_regulator_action(void *_data) +{ + struct isl29018_chip *chip =3D _data; + int err; + + err =3D regulator_disable(chip->vcc_reg); + if (err) + dev_err(regmap_get_device(chip->regmap), + "failed to disable VCC regulator!\n"); +} + static int isl29018_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -742,6 +755,37 @@ static int isl29018_probe(struct i2c_client *client, chip->scale =3D isl29018_scales[chip->int_time][0]; chip->suspended =3D false; =20 + chip->vcc_reg =3D devm_regulator_get(&client->dev, "vcc"); + if (IS_ERR(chip->vcc_reg)) { + err =3D PTR_ERR(chip->vcc_reg); + if (err !=3D -EPROBE_DEFER) + dev_err(&client->dev, "failed to get VCC regulator!\n"); + return err; + } + + err =3D regulator_enable(chip->vcc_reg); + if (err) { + dev_err(&client->dev, "failed to enable VCC regulator!\n"); + return err; + } + + chip->regmap =3D devm_regmap_init_i2c(client, + isl29018_chip_info_tbl[dev_id].regmap_cfg); + if (IS_ERR(chip->regmap)) { + err =3D PTR_ERR(chip->regmap); + dev_err(&client->dev, "regmap initialization fails: %d\n", err); + regulator_disable(chip->vcc_reg); + return err; + } + + err =3D devm_add_action(&client->dev, isl29018_disable_regulator_action, + chip); + if (err) { + isl29018_disable_regulator_action(chip); + dev_err(&client->dev, "failed to setup regulator cleanup action!\n"); + return err; + } + chip->regmap =3D devm_regmap_init_i2c(client, isl29018_chip_info_tbl[dev_id].regmap_cfg); if (IS_ERR(chip->regmap)) { @@ -768,6 +812,7 @@ static int isl29018_probe(struct i2c_client *client, static int isl29018_suspend(struct device *dev) { struct isl29018_chip *chip =3D iio_priv(dev_get_drvdata(dev)); + int ret; =20 mutex_lock(&chip->lock); =20 @@ -777,6 +822,12 @@ static int isl29018_suspend(struct device *dev) * So we do not have much to do here. */ chip->suspended =3D true; + ret =3D regulator_disable(chip->vcc_reg); + if (ret) { + dev_err(dev, "failed to disable VCC regulator\n"); + mutex_unlock(&chip->lock); + return ret; + } =20 mutex_unlock(&chip->lock); =20 @@ -790,6 +841,13 @@ static int isl29018_resume(struct device *dev) =20 mutex_lock(&chip->lock); =20 + err =3D regulator_enable(chip->vcc_reg); + if (err) { + dev_err(dev, "failed to enable VCC regulator\n"); + mutex_unlock(&chip->lock); + return err; + } + err =3D isl29018_chip_init(chip); if (!err) chip->suspended =3D false; --=20 2.7.4