Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp602307ybl; Thu, 12 Dec 2019 01:42:57 -0800 (PST) X-Google-Smtp-Source: APXvYqyedmBM7RHVHeuWUiLeC4JS7RFvtS1ukWN4ebltNV0aWYs/F0MMlNqlrJei2SzLP2Ft6SYq X-Received: by 2002:a05:6830:1607:: with SMTP id g7mr7237623otr.320.1576143777253; Thu, 12 Dec 2019 01:42:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576143777; cv=none; d=google.com; s=arc-20160816; b=z2fdZXivM105aVhKFCFvQ5DoHd5ny6KpiCy0riY5q5OLc+5nwy7VOk9mJHg594T5Os 0chMY6IdNy7xnbIM1WSxkx89Kfv4Z0wqQwHb7FroLf0Tby5FLlL1W1wmnzBeRh25J5mj NCZNp8HLCJjMbz0emT3BL+EEFK19Uxl8VnmyjEXQIWMoE7SQRcfWGptlLAgBXP/zktEh QcBcVaMRDf0zfvxjQALYnDSgjX64BUGMykKK91g13t+NbXOLeTwRP+fhQ8f/bPgn13EQ X4n1GxFTTcxBY+AW20XnjVZ9Zpv3d1TQEV2G1CfpzJDNivmmiKUhMchu0/TLMlU7gPW3 yBFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=nqldGoReHAqAk+cCLWay8D5xD350FZnLqhYpYXAhHH8=; b=sV3er7uc9QlSR4smi+Nav0Y8cGdM6dZ5OiaoXh8D5H7XQb4hh493ndg/FHduylO0ts odmXHXBWoKLHshmx84X3or/Op9TI8MTUaVEyOemFLjqlRiJrld46sEMuVLCT7MNmALdk Uqsro1wFQijv1Mkz7ceBQvlsUCumZCF+eVaEBoFm13fQAN+2AS29ig9w/lmXUqPWT5eM 9dMjWg5U2R5Qk4dfVhPOX2jqKRqck3NWyKibZLxop1nV6xnbFcJBRuizVFOeNLiPelzV qfQprLkl1mOGovRYkYmymqWhc8GXq9Yy0P7EGrmX2cOpCPcPKEhOaD56rEt3enmo5yJT Acqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=u5SBg2z8; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j71si2722429oib.213.2019.12.12.01.42.44; Thu, 12 Dec 2019 01:42: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=@gmail.com header.s=20161025 header.b=u5SBg2z8; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728571AbfLLJl6 (ORCPT + 99 others); Thu, 12 Dec 2019 04:41:58 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:42054 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728501AbfLLJlz (ORCPT ); Thu, 12 Dec 2019 04:41:55 -0500 Received: by mail-pf1-f195.google.com with SMTP id 4so456832pfz.9; Thu, 12 Dec 2019 01:41:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nqldGoReHAqAk+cCLWay8D5xD350FZnLqhYpYXAhHH8=; b=u5SBg2z8I1z6zoptoyt6jacu8N12W2nd3dbifd6S7GkMnSTSjCEiQvh5vJsnRQ+g7j fINT2UX1NBiHZM3W2BpO2Zvn7GNYZ3cg2qu0gvCgVMWef0rVn1i9W5k0WCsKWeDTYLMA DMJldK8o52HZEw1ko+313+V2B7LLOWP7+4GzRkWyWz4TG0ttF+/Sn8JAHsuiI7aDX9G5 XWj7mG/x5lEDCxcHkxRO8JgXgd7z/P081ojMzNkG0K6eWElzwJn2iNM3oCN9oZ5qxJNe bzSc3S+5IC6aUsRXtipHOSCDkILXmncLffLi/z7Ru9qHy7yDR54fOsLiFuOSialwOMCz B3fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nqldGoReHAqAk+cCLWay8D5xD350FZnLqhYpYXAhHH8=; b=oxH7v3aQCLe2tyzLPTz9+7sRH4QLBY1jlcZleU3IahjQs7vgFPa7zJl3Fv6NBTEzmN o25gv3SHCLGNBsQDEYT4WSdOReCWFeXErCQRrxZzalRkveTlHbMvxnIi6+EYMtYX396/ nXEMkUYkONdYwDMiwurLISPgUCA5ztdzg/a4WxCBcS+QYUCR/7wxt2Dgru7KylgwaZku 38SD6nOCFDeybmPLPf1Upnoor43HSYnxIRYUEjCqlz5fz/EBkNPOgTM0K0c/7z1JiBeJ uklC5FFUh/uCG34OxJ6Tj4zuulhXqmX8zz0REVy8iF4t0Co/G5wqfHEHdOqChFLOWenC yKdw== X-Gm-Message-State: APjAAAXX3AX0+baRfKSdYads9R5JF5t6j8Bl/45q5fQC9keI2NtNwsSp hGbUvxzuyrMCvT7+qo6PXwjgCPHmCcjlQmjS06I= X-Received: by 2002:a63:e14a:: with SMTP id h10mr9241444pgk.74.1576143714981; Thu, 12 Dec 2019 01:41:54 -0800 (PST) MIME-Version: 1.0 References: <20191211010308.1525-1-dan@dlrobertson.com> <20191211010308.1525-3-dan@dlrobertson.com> <20191212001735.GA4667@nessie> In-Reply-To: <20191212001735.GA4667@nessie> From: Andy Shevchenko Date: Thu, 12 Dec 2019 11:41:45 +0200 Message-ID: Subject: Re: [PATCH v6 2/2] iio: (bma400) add driver for the BMA400 To: Dan Robertson Cc: Jonathan Cameron , linux-iio , Peter Meerwald-Stadler , devicetree , Hartmut Knaack , Rob Herring , Mark Rutland , Linux Kernel Mailing List , Randy Dunlap , Joe Perches Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 12, 2019 at 2:33 AM Dan Robertson wrote: > On Wed, Dec 11, 2019 at 03:21:56PM +0200, Andy Shevchenko wrote: > > On Wed, Dec 11, 2019 at 3:20 AM Dan Robertson wrote: > > > +#define BMA400_LP_OSR_SHIFT 0x05 > > > +#define BMA400_NP_OSR_SHIFT 0x04 > > > +#define BMA400_SCALE_SHIFT 0x06 > > > > I'm not sure why this is being defined as hex number instead of plain decimal... > > Sounds good. > > > > +#define BMA400_TWO_BITS_MASK GENMASK(1, 0) > > > +#define BMA400_LP_OSR_MASK GENMASK(6, BMA400_LP_OSR_SHIFT) > > > +#define BMA400_NP_OSR_MASK GENMASK(5, BMA400_NP_OSR_SHIFT) > > > +#define BMA400_ACC_ODR_MASK GENMASK(3, 0) > > > +#define BMA400_ACC_SCALE_MASK GENMASK(7, BMA400_SCALE_SHIFT) > > > > And here simple better to put same numbers. It will help to read. > > Do you mean for the shift or for the mask? SHIFTs -> plain decimals > > > +EXPORT_SYMBOL(bma400_regmap_config); > > > > I'm not sure I got the idea why this one is being exported. > > It needs to be exported so that it can be used in the bma400_i2c module and the > future bma400_spi module. In theory, if we _really_ do not want to export this, > then we can define separate regmap configs in each of the bma400_i2c and > (future) bma400_spi modules, but then we would have to export the is_volitile_reg > and is_writable_reg functions. As a result, I do not see any benefits to that > method over exporting the config, but I could be convinced otherwise. I think there might be better way to do this. But I leave it to you and maintainer to agree on (I will be fine with any solution you will come to). > > > + if (uhz || hz % BMA400_ACC_ODR_MIN_WHOLE_HZ) > > > + return -EINVAL; > > > + > > > + val = hz / BMA400_ACC_ODR_MIN_WHOLE_HZ; > > > + idx = __ffs(val); > > > + > > > > > + if (val ^ BIT(idx)) > > > > Seems like funny way of checking is_power_of_2(). But it's up to maintainers. > > And your variant may even be better here (in code generation perspective)... > > > > However, the whole idea here is, IIUC, to have something like > > > > hz = 2^idx * BMA400_ACC_ODR_MIN_WHOLE_HZ > > > > I think you may do it without divisions, i.e. call __ffs() first and then do > > idx = __ffs(...); > > val = hz >> idx; > > if (val != BMA400_ACC_ODR_MIN_WHOLE_HZ) > > return -EINVAL; > > > > or something like above. > > It would be more obvious what is being done here with is_power_of_two. I'll > revisit this function with your suggestions. If I can make it simpler, I'll > go this route. The main point here to get rid of divisions. Is it achievable? > > > + return -EINVAL; > > > > ... > > > + ret = regmap_read(data->regmap, BMA400_ACC_CONFIG0_REG, &val); > > > + if (ret < 0) > > > > I'm wondering if in all of these regmap_read()... > > > > > + return ret; > > > > > + ret = regmap_write(data->regmap, BMA400_ACC_CONFIG0_REG, > > > + mode | (val & ~BMA400_TWO_BITS_MASK)); > > > + if (ret < 0) { > > > > ...and regmap_write() calls you ever can get a positive returned code. > > From the regmap_read/regmap_write docs: > > > * A value of zero will be returned on success, a negative errno will > > * be returned in error cases. > > So I assume ret <= 0 There is no positive codes mentioned at all. And you assume right. But why we care about positive codes if they never can be returned? -- With Best Regards, Andy Shevchenko