Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1787535ybl; Thu, 19 Dec 2019 03:03:31 -0800 (PST) X-Google-Smtp-Source: APXvYqwrYoLFk00t1sByl5pEzVAa8H+mM+oeofZrn6qndvlC6HgsausRe/+J8rr4Mv42A7IQlgLD X-Received: by 2002:aca:bb02:: with SMTP id l2mr1916031oif.60.1576753411434; Thu, 19 Dec 2019 03:03:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576753411; cv=none; d=google.com; s=arc-20160816; b=YK6yLy3cYyKHfQeiJ6FSmPLeiDBubq5asZtcii7nzEzgm6+SDpwc/qswHzvXvxfA6U Rk/4jWLPJMs2q3Gon1WFDGQwt5d+1D6HHxjNmq8eqe+R+G1WHHlDS5uzczlGTJlIlsTo RyPG7lidOq7KFZ8Dzy3ZA94dzsuUlkPY9aOYfYZOcYk+rUhEizSd5pRkt/tl9cCfQJjU 42tNc3tWFoE2Fq8KgtQ++Ep2rCoYQ4dXlKBCWL8hinOaJLN7PXQdcztioiu98dSOqZdD t1FNpTCCioo/pCk/GWYTnlU7oXQWOjAuKu4yF2DSyaQnbKPhC8ogvr6oHxvBRwwkkvpa xX8A== 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=O+r1HKCBriFzIoCX8L5uyYociaU+Sa1uGxae7TY0vSs=; b=g8mbkjP3e/WOwm7U8jGVZCZO9XAc4+B9chNzUSqh5UNiUmaS+KSuUkbLQX7HK/H3uW T4456nU+9iWu7sSGT6BlC01xTBR+uFLGMHpVzq47VSETx9l4dpsOIRSZeC7kKWLgeiNy 1z51jYUamDBW+bG2AcoOx714Sr5ZO8ndhJo7L1DpzJM1q1Zc4dCr6zlgy/rrfH5VWAvV 4j7Yh4TjqurAKmr3vt1smZEHCcxuNLUaDlQBrhvrM+r/6SeW9/U8FwMyO4ihPTELch/o Y2r7ZuymYwj5c6MjNAVvoCld0pDNV3yvsYg9k+KOlK1Xhu8HIowzxdU4guK6yCTrGp1A dCAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cfkeeELX; 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 25si2919008oiz.230.2019.12.19.03.03.19; Thu, 19 Dec 2019 03:03:31 -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=cfkeeELX; 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 S1726754AbfLSLCj (ORCPT + 99 others); Thu, 19 Dec 2019 06:02:39 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:36994 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbfLSLCi (ORCPT ); Thu, 19 Dec 2019 06:02:38 -0500 Received: by mail-pj1-f66.google.com with SMTP id m13so2360246pjb.2; Thu, 19 Dec 2019 03:02:38 -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=O+r1HKCBriFzIoCX8L5uyYociaU+Sa1uGxae7TY0vSs=; b=cfkeeELXTz7NjDjxtICyJ0BLK0YJLg+sxrMl9yJklc26hsc7dYlv3icbSsPy4Q+UQX NSli7tEK1jcAVg3uuG281j8Eep439Go8DxsAhIPwr1F1eI7+5PsoLqOf4BT4dLlD8iXR fFW2xvxBMIeNLVj6YMYufCUPgtNP3+lqIcostBYzT0vD3sLlDDd5NJG6Iszm/YM4BCtV HSJqbQPg6iOpq4jiJHvG3GTvOQKGlBzz4W8aTaGW32bGjS1LrySk4Oukp2sqzOpt7gTO yTUjIk7xV0VwCct5MtNZ+BlMjBJpkNYEcjXnUk7C+YyV3Sp4dEuMbG6tdYJIZB754PFl Obdg== 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=O+r1HKCBriFzIoCX8L5uyYociaU+Sa1uGxae7TY0vSs=; b=qND02OEV8paEEXwNDHiioDFri67CdAuzFN+5xvSOjYou6D0egwomyjqA7AK8h8WwZs ihT0lTky5EF/BBAb8I2flqI3T1OXeJ/fLNoXs6SQSXZKLY24UbyDTlCWXuYlzRYPvoTT TjFEsdGsyMZ7cvk7qUDBCKzqip3K2+a/P9G/mkamoDW7isSeVGTunE7NnFGN7Szrat40 +KdWQamPqkhCD2ckkkrWA7tyHYiAHUXHyYkIA/q6/FAkleuO+oMlEdvLOTec26FdMbDu fpsHgL/WBnYJZTxTgOh7O2Iuw1NSRhl5+P846QsX2+7xRHmDJFpuHVEoop1/rxf/MoZa 3qTg== X-Gm-Message-State: APjAAAXQfeeVdiFrhJZKqGjXvWW/FHpyuF8AQCJ8F4hNWsL4f9YjGqS/ bBOsoi4XJR0QCFOf9F+LPtcvlk1lcXqcQKuX0SUsEDMo X-Received: by 2002:a17:902:6901:: with SMTP id j1mr8660446plk.18.1576753357972; Thu, 19 Dec 2019 03:02:37 -0800 (PST) MIME-Version: 1.0 References: <20191219041039.23396-1-dan@dlrobertson.com> <20191219041039.23396-3-dan@dlrobertson.com> In-Reply-To: <20191219041039.23396-3-dan@dlrobertson.com> From: Andy Shevchenko Date: Thu, 19 Dec 2019 13:02:28 +0200 Message-ID: Subject: Re: [PATCH v7 2/3] 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 , Linus Walleij 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 19, 2019 at 6:27 AM Dan Robertson wrote: > Add a IIO driver for the Bosch BMA400 3-axes ultra-low power accelerometer. > The driver supports reading from the acceleration and temperature > registers. The driver also supports reading and configuring the output data > rate, oversampling ratio, and scale. ... > +static int bma400_set_accel_output_data_rate(struct bma400_data *data, > + int hz, int uhz) > +{ > + unsigned int idx; > + unsigned int odr; > + unsigned int val; > + int ret; > + > + if (hz >= BMA400_ACC_ODR_MIN_WHOLE_HZ) { > + if (uhz || hz % BMA400_ACC_ODR_MIN_WHOLE_HZ) > + return -EINVAL; > + > + val = hz / BMA400_ACC_ODR_MIN_WHOLE_HZ; Again, AFAICS division may be avoided in both cases (% and / above) because of is_power_of_2() check below. Can you revisit this? > + if (!is_power_of_2(val)) > + return -EINVAL; > + > + idx = __ffs(val) + BMA400_ACC_ODR_MIN_RAW + 1; > + } else if (hz == BMA400_ACC_ODR_MIN_HZ && uhz == 500000) { > + idx = BMA400_ACC_ODR_MIN_RAW; > + } else { > + return -EINVAL; > + } > + > + ret = regmap_read(data->regmap, BMA400_ACC_CONFIG1_REG, &val); > + if (ret) > + return ret; > + > + /* preserve the range and normal mode osr */ > + odr = idx | (~BMA400_ACC_ODR_MASK & val); Yoda style? > + > + ret = regmap_write(data->regmap, BMA400_ACC_CONFIG1_REG, odr); > + if (ret) > + return ret; > + > + bma400_output_data_rate_from_raw(idx, &data->sample_freq.hz, > + &data->sample_freq.uhz); > + return 0; > +} ... > +int bma400_accel_scale_to_raw(struct bma400_data *data, unsigned int val) > +{ > + int scale = val / BMA400_SCALE_MIN; > + int raw; > + > + if (scale == 0) > + return -EINVAL; > + > + raw = __ffs(scale); > + > + if (val % BMA400_SCALE_MIN || !is_power_of_2(scale)) > + return -EINVAL; Ditto. > + > + return raw; > +} ... > +out: Make a little sense. Why not return directly? > + return ret; ... > + ret = bma400_init(data); > + if (ret < 0) May it be positive value returned? > + return ret; ... > +static int bma400_i2c_probe(struct i2c_client *client, > + const struct i2c_device_id *id) > +{ > + struct regmap *regmap; > + > + regmap = devm_regmap_init_i2c(client, &bma400_regmap_config); > + Redundant blank line. > + if (IS_ERR(regmap)) { > + dev_err(&client->dev, "failed to create regmap\n"); > + return PTR_ERR(regmap); > + } > + > + return bma400_probe(&client->dev, regmap, id->name); > +} -- With Best Regards, Andy Shevchenko