Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2944517imm; Thu, 24 May 2018 19:36:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoC54DzqFMdyZcDmjbZ67xOfjntam+WauTwuhnGjj/gQ/tFmM5R2RntaulblR4ORB0rZ030 X-Received: by 2002:a62:211c:: with SMTP id h28-v6mr536702pfh.249.1527215792452; Thu, 24 May 2018 19:36:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527215792; cv=none; d=google.com; s=arc-20160816; b=ojoJ9SuDXpgq2mkfQnUhifJrFVB1i4HZU1wBMzLkYCMoZFosGi7zRvV+SAEIjEJ/Aj TXgloI/DJEsgCnZf9Ea2m+v0Uwc2v2Wum8YnI4sZ2nTy/2KRnXJj5TGwNqqSe2R9uA4L hAa5DWiKQ3v3yRzc+0s3ND0NVxJ0z9nuv3cGIM2D+jZCYDthSoxG2z5OZLRwYG6M11vK Pnv9Uj329vfaxFYX52JqW2KB4I+i13MkMTHKTVQenZK9HAX3s4AzFTfsne1j0OP+uJyi iFgCgkszyol15PRN3Iipk/FtPAg3Zi3tOl3Ga7od6npzNZCWAW9UXjD3/6I0qsgIcqbg lJpg== 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 :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from :arc-authentication-results; bh=6cwRA38q5O3pSBDau9EjUpM/LfgjXewdIM3JmTmURjY=; b=uGLH1vKO9zHra4kXhOCIrVHXGKkQyg+ovNECg0jnh7YoCVVwd9XDSIU1+jyNB2A6dx tO7M2j4KkrO4T/CuUvTPrQYT74Cgzakphgw6LidMFn0XIW+1wMJAgkdRHUo/nxMmvI5g 0m3XB44QG5ITpwtQa1oljImZ/NVQs6eEBumjvp6umxGph752O+A/UgG1XWSuqPncg2A8 2kGtmvHKMeeo/hrg/riwoP9zAaKi2faiz17kR9O7WoN9LSzyvilZlCDdT2UsuWRAVo9m uqtD5uSUrWGtEMWSL7gz7xDqYxMp3whxqnqwL/9IAL4UrTxtPU3/cVx5+jC6FcQDbyr8 uWHA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u10-v6si3484754plr.553.2018.05.24.19.36.18; Thu, 24 May 2018 19:36:32 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968573AbeEXSGf convert rfc822-to-8bit (ORCPT + 99 others); Thu, 24 May 2018 14:06:35 -0400 Received: from mailgate1.rohmeurope.com ([178.15.145.194]:64523 "EHLO mailgate1.rohmeurope.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968546AbeEXSGb (ORCPT ); Thu, 24 May 2018 14:06:31 -0400 X-Greylist: delayed 901 seconds by postgrey-1.27 at vger.kernel.org; Thu, 24 May 2018 14:06:30 EDT X-AuditID: c0a8fbf4-fcfff70000000f28-36-5b06fba026b3 Received: from smtp.reu.rohmeu.com (will-cas002.reu.rohmeu.com [192.168.251.178]) by mailgate1.rohmeurope.com (Symantec Messaging Gateway) with SMTP id B6.C3.03880.0ABF60B5; Thu, 24 May 2018 19:51:28 +0200 (CEST) Received: from WILL-MAIL002.REu.RohmEu.com ([fe80::e0c3:e88c:5f22:d174]) by WILL-CAS002.REu.RohmEu.com ([fe80::fc24:4cbc:e287:8659%12]) with mapi id 14.03.0382.000; Thu, 24 May 2018 19:51:27 +0200 From: "Vaittinen, Matti" To: Mark Brown CC: "mturquette@baylibre.com" , "sboyd@kernel.org" , "robh+dt@kernel.org" , "mark.rutland@arm.com" , "lee.jones@linaro.org" , "lgirdwood@gmail.com" , "mazziesaccount@gmail.com" , "linux-clk@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Mutanen, Mikko" , "Haikola, Heikki" Subject: RE: [PATCH 8/9] regulator: bd71837: BD71837 PMIC regulator driver Thread-Topic: [PATCH 8/9] regulator: bd71837: BD71837 PMIC regulator driver Thread-Index: AQHT82mISKOyi8FfiUKQkM/afomaOaQ/JCHb Date: Thu, 24 May 2018 17:51:27 +0000 Message-ID: <042F8805D2046347BB8420BEAE397A4016C06B60@WILL-MAIL002.REu.RohmEu.com> References: <20180524060036.GI4249@localhost.localdomain>,<20180524141427.GU4828@sirena.org.uk> In-Reply-To: <20180524141427.GU4828@sirena.org.uk> Accept-Language: en-US, de-DE Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [213.216.252.121] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkk+LIzCtJLcpLzFFi42I5sOL3Jt0Fv9miDRbfYreY+vAJm8X8I+dY Le5/Pcpo8e1KB5PFx557rBaXd81hs1h6/SKTxZylJ1gsLp5ytWjde4Td4t+1jSwO3B5r5q1h 9Hh/o5XdY+esu+wem1Z1snncubaHzePzJrkAtihum6TEkrLgzPQ8fbsE7owFMywKjslUNNye w9TAeEi0i5GTQ0LARGLl7BfMXYxcHEIC1xgltjy9zgrhnGCU6G5+ytjFyMHBJmAj0XWTHaRB REBZ4ur3vSwgNcwCv1gktmy4BZYQFvCS2PzyLjNEkbfE/8PTWCBsI4krj+6wgdgsAqoS16/f ZAWxeQWCJPoa34L1CgnES9x9MIUJxOYEqm88sRushlFAVqKz4R1YnFlAXOLWk/lMEFcLSCzZ c54ZwhaVePn4HyuErSyx5tRONoh6HYkFuz9B2doSyxa+ZobYKyhxcuYTlgmMorOQjJ2FpGUW kpZZSFoWMLKsYpTITczMSU8sSTXUK0ot1SvKz8gFUsn5uZsYIdH6ZQfj/0OehxgFOBiVeHjb vrBFC7EmlhVX5h5ilORgUhLlZXgFFOJLyk+pzEgszogvKs1JLT7EKMHBrCTC2/0LKMebklhZ lVqUD5OS5mBREueNOv8rSkgAZHN2ampBahFMVoaDQ0mC9whIo2BRanpqRVpmTglCmomDE2Q4 l5RIcWpeSmpRYmlJRjwoWcQXA9MFSIoHaC/zb5C9xQWJuUBRiNZTjJJS4rxvfgIlBEASGaV5 cGNfMYoDfSfM2wWylQeYruG6XgENZAIaeHE5M8jAkkSElFQD494/su3v/vIGTS2US7QRvf/o E2txbgfXPOv5u2bXPrDvOVRy1LaRpWzt5jvCht9zQo+Ja3/bWqehar3RZ0XbzJ+mRRtO/3i9 6trbc+ynuwzK51aoGQglfHllquw6MUFOJpPhTGRPvHrsL9f/q19+u9s+8ULyjSbh4J2FWaK9 1wqtKqwyHOrmK7EUZyQaajEXFScCACNOnAyUAwAA Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Brown [broonie@kernel.org] > Sent: Thursday, May 24, 2018 5:14 PM > > On Thu, May 24, 2018 at 09:00:36AM +0300, Matti Vaittinen wrote: > > > @@ -0,0 +1,683 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* Copyright (C) 2018 ROHM Semiconductors */ > > +/* > > + * bd71837-regulator.c ROHM BD71837MWV regulator driver > > + */ > > +#include > > Make the entire comment block a C++ comment so it looks more intentional I will change this to C++ - but the verison of checkpatch.pl I used did complain if I used C++ style comments in C-files or if I used C-style comments in header. I guess the sscript should be fixed unless it is already done. > and add a blank line before the headers for legibility. Will do. > > +static int bd71837_regulator_set_regmap(struct regulator_dev *rdev, int set) > > +{ > > + int ret = -EINVAL; > > + struct bd71837_pmic *pmic = rdev->reg_data; > > + > > + if (pmic) { > > + mutex_lock(&pmic->mtx); > > + if (!set) > > + ret = regulator_disable_regmap(rdev); > > + else > > + ret = regulator_enable_regmap(rdev); > > + mutex_unlock(&pmic->mtx); > > + } > > This looks very weird - why might we not have a parent PMIC, I'll remove the check. I've just adopted habit of adding NULL checks for pointers "jsut in case". > what is the lock doing and what is this wrapper function intended to do? This was the other spot which I was unsure how to handle. Datasheet for the chip says that if voltage is to be changed, the regulator must be disabled. Thus my voltage changing function checks if regulator is enabled and disables it for duration of voltage change (if it was enabled). This lock is used to protect the voltage change so that no one enables the regulator during voltage change. I don't know what would have been correct way of doing this, or if disabling regulator for voltage change is Ok - but this was the only way I could think of. I am again grateful for any tips. > Similar > issues apply to the voltage functions, if there's any need for this it > needs to be better documented but it really doesn't look like a good > idea. If the solution with lock and wrapper (to prevent race during state check and voltage change) is Ok, then I will add comment which explains this, > > + err = > > + regmap_update_bits(pmic->mfd->regmap, BD71837_REG_REGLOCK, > > + (REGLOCK_PWRSEQ | REGLOCK_VREG), 0); > > + if (err) { > > + dev_err(&pmic->pdev->dev, "Failed to unlock PMIC (%d)\n", err); > > + goto err; > > + } else > > + dev_dbg(&pmic->pdev->dev, "%s: Unlocked lock register 0x%x\n", > > + __func__, BD71837_REG_REGLOCK); > > There's loads of coding style problems with this code, please refer to > the coding style - indentation is weird and if there's { } on one side > of an else it should be on both. Will fix it. > > + rdev = regulator_register(desc, &config); > > + if (IS_ERR(rdev)) { > > devm_regulator_regster() Makes sense. Thanks Best Regards Matti Vaittinen