From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4E055CD5BD1 for ; Sun, 31 May 2026 12:12:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=A1esNQJ7olBj4CU8C0Qcd/vQ6sMomOmQ443mXwfcwGk=; b=PPDPG8fwhnfbTc +lIDle/y5RzIxt5YRnqXK78dYRsQtu4ykwc098+ZwgBcU55FcYTPM/VpfNfx7dOadFLWj5crD1H/7 64lYL6Jrx17XyI9+XL3SY9PcHye0dA6PI8j6fdXinPYSBJukkc8dRnN+GhDk0yW7ylRkhTa5uomYR XN0RNO31iT7fAvEHxIowzLe7JH1i5q+QIoqlOozoJyGkef9BrVw8Cx4gLxsXCLTPGfMm4gUqLVHI3 KoVPysioFk8z06pyoGMux3O2B6Hf+viaLI/8GdW5vuQ9p/0zBJAnV21IJ6FYpPgFVOxSdEz6UuYM2 sqs6yQc+iC6Z5hY0dRWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wTf1R-00000009ZOJ-1WLg; Sun, 31 May 2026 12:12:05 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wTf1O-00000009ZNa-2jOy for linux-rockchip@lists.infradead.org; Sun, 31 May 2026 12:12:04 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id E900C41A63; Sun, 31 May 2026 12:12:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF2301F00893; Sun, 31 May 2026 12:11:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780229521; bh=leqiPf+NTSbTmkKH37kvObGoIRcbRTHncXBrq9GqQm8=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=BuI9zv7cJ5hxS8TPOfZweXKlE2BJ/HZlvUxZ8xqhyPvBaTZR7ryjgoNOv903e/ddr RDn9gCnRj0gLy91NP3OWoN4lAPNgEOL8fsTbnKKVeHVlOiAqmMjaPkeVwJNGeeJW0E s5YuR8zJkLDRwy3BovverP4SGGT9Ra7DGqjmnR1RMKT/4Zz9Yasu0Mu83JZZNsIw7+ wUrwx92bC2jIjvCDBWy7iU0Fa1qTkQDKpPIf1I87aDi5K0xZ0fjHFJRHTN8ssuimD9 k8v3q86f1lVfKXXMNcDHEJMtaf38lAwEIsPQhElCx8oACCtZReZFsMWnyzb4aiIrbZ 1wXfAP/HrdCnQ== Date: Sun, 31 May 2026 13:11:54 +0100 From: Jonathan Cameron To: Chris Morgan Cc: linux-iio@vger.kernel.org, andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com, jean-baptiste.maneyrol@tdk.com, linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, heiko@sntech.de, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, andriy.shevchenko@intel.com, Chris Morgan Subject: Re: [PATCH V9 03/11] iio: imu: inv_icm42607: Add inv_icm42607 Core Driver Message-ID: <20260531131154.047f33ce@jic23-huawei> In-Reply-To: <20260530031739.109063-4-macroalpha82@gmail.com> References: <20260530031739.109063-1-macroalpha82@gmail.com> <20260530031739.109063-4-macroalpha82@gmail.com> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260531_051202_894038_B56EED84 X-CRM114-Status: GOOD ( 29.76 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org On Fri, 29 May 2026 22:17:30 -0500 Chris Morgan wrote: > From: Chris Morgan > > Add the core component of a new inv_icm42607 driver. This includes > a few setup functions and the full register definition in the > header file. https://sashiko.dev/#/patchset/20260530031739.109063-1-macroalpha82%40gmail.com Again has some feedback. I've commented on them below to say whether I agree or not. Also a few other minor things inline. > > Signed-off-by: Chris Morgan > --- > drivers/iio/imu/inv_icm42607/inv_icm42607.h | 336 ++++++++++++++++++ > .../iio/imu/inv_icm42607/inv_icm42607_core.c | 206 +++++++++++ > 2 files changed, 542 insertions(+) > create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607.h > create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_core.c > > diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c > new file mode 100644 > index 000000000000..4801ece28058 > --- /dev/null > +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c > +static int inv_icm42607_set_conf(struct inv_icm42607_state *st, > + const struct inv_icm42607_conf *conf) > +{ > + unsigned int val; > + int ret; > + > + val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, conf->gyro.mode); > + val |= FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, conf->accel.mode); > + /* > + * No temperature enable reg in datasheet, but BSP driver selected RC > + * oscillator clock in LP mode when temperature was disabled. > + */ > + if (!conf->temp_en) > + val |= INV_ICM42607_PWR_MGMT0_ACCEL_LP_CLK_SEL; > + ret = regmap_write(st->map, INV_ICM42607_REG_PWR_MGMT0, val); > + if (ret) > + return ret; > + > + val = FIELD_PREP(INV_ICM42607_GYRO_CONFIG0_FS_SEL_MASK, conf->gyro.fs); > + val |= FIELD_PREP(INV_ICM42607_GYRO_CONFIG0_ODR_MASK, conf->gyro.odr); > + ret = regmap_write(st->map, INV_ICM42607_REG_GYRO_CONFIG0, val); > + if (ret) > + return ret; > + > + val = FIELD_PREP(INV_ICM42607_ACCEL_CONFIG0_FS_SEL_MASK, conf->accel.fs); > + val |= FIELD_PREP(INV_ICM42607_ACCEL_CONFIG0_ODR_MASK, conf->accel.odr); > + ret = regmap_write(st->map, INV_ICM42607_REG_ACCEL_CONFIG0, val); > + if (ret) > + return ret; > + > + val = FIELD_PREP(INV_ICM42607_GYRO_CONFIG1_FILTER_MASK, conf->gyro.filter); > + ret = regmap_write(st->map, INV_ICM42607_REG_GYRO_CONFIG1, val); > + if (ret) > + return ret; > + > + val = FIELD_PREP(INV_ICM42607_ACCEL_CONFIG1_FILTER_MASK, conf->accel.filter); > + ret = regmap_write(st->map, INV_ICM42607_REG_ACCEL_CONFIG1, val); > + if (ret) Sashiko points out that this is overwriting whatever is the INV_ICM42607_ACCEL_CONFIG1_AVG_MASK field. That isn't set at all yet, which is fine but I'd be tempted to make it clear what intent is here. Either explicitly set it to 0 as val |= FIELD_PREP(INV_ICM42607_ACCEL_CONFIG1_AVG_MASK, 0); or use regmap_update_bits as sashiko suggests. > + return ret; > + > + st->conf = *conf; > + > + return 0; > +} > + > +/** > + * inv_icm42607_setup() - check and setup chip > + * @st: driver internal state > + * @bus_setup: callback for setting up bus specific registers > + * > + * Returns 0 on success, a negative error code otherwise. > + */ > +static int inv_icm42607_setup(struct inv_icm42607_state *st, > + inv_icm42607_bus_setup bus_setup) > +{ > + const struct device *dev = regmap_get_device(st->map); > + unsigned int val; > + int ret; > + > + ret = regmap_read(st->map, INV_ICM42607_REG_WHOAMI, &val); > + if (ret) > + return ret; > + > + if (val != st->hw->whoami) > + dev_warn(dev, "Unknown whoami %#02x expected %#02x (%s)\n", > + val, st->hw->whoami, st->hw->name); > + > + ret = regmap_write(st->map, INV_ICM42607_REG_SIGNAL_PATH_RESET, > + INV_ICM42607_SIGNAL_PATH_RESET_SOFT_RESET); > + if (ret) > + return ret; > + > + fsleep(INV_ICM42607_RESET_TIME_MS * 1000); > + > + ret = regmap_read_poll_timeout(st->map, INV_ICM42607_REG_INT_STATUS, > + val, val & INV_ICM42607_INT_STATUS_RESET_DONE, > + INV_ICM42607_RESET_TIME_MS * 100, > + INV_ICM42607_RESET_TIME_MS * 10000); > + if (ret) > + return dev_err_probe(dev, ret, > + "reset error, reset done bit not set\n"); > + > + /* Sync the regcache again after a reset. */ > + ret = regcache_sync(st->map); I haven't checked sashiko's feedback on this but it seems plausible as there is a check in regcache_sync on whether the cache is dirty and no obvious path for it to get to that state here. > + if (ret) > + return ret; > + > + ret = bus_setup(st); > + if (ret) > + return ret; > + > + ret = regmap_set_bits(st->map, INV_ICM42607_REG_INTF_CONFIG0, > + INV_ICM42607_INTF_CONFIG0_SENSOR_DATA_ENDIAN); > + if (ret) > + return ret; > + > + ret = regmap_update_bits(st->map, INV_ICM42607_REG_INTF_CONFIG1, > + INV_ICM42607_INTF_CONFIG1_CLKSEL_MASK, > + INV_ICM42607_INTF_CONFIG1_CLKSEL_PLL); > + if (ret) > + return ret; > + > + return inv_icm42607_set_conf(st, st->hw->conf); > +} > +int inv_icm42607_core_probe(struct regmap *regmap, > + const struct inv_icm42607_hw *hw, > + inv_icm42607_bus_setup bus_setup) > +{ > + struct device *dev = regmap_get_device(regmap); > + struct inv_icm42607_state *st; > + int irq; > + int ret; > + > + irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT1"); > + if (irq < 0) > + return dev_err_probe(dev, irq, "Unable to get INT1 interrupt\n"); Sashiko comments on this and is correct that this only works on device tree with interrupt-names. Which is intentional! > + > + st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); > + if (!st) > + return -ENOMEM; > + > + dev_set_drvdata(dev, st); Really small thing. Is this used yet? I think this should be in a later patch. Probably patch 5. > + > + ret = devm_mutex_init(dev, &st->lock); > + if (ret) > + return ret; > + > + st->hw = hw; > + st->map = regmap; > + st->irq = irq; > + > + ret = iio_read_mount_matrix(dev, &st->orientation); > + if (ret) > + return dev_err_probe(dev, ret, > + "failed to retrieve mounting matrix %d\n", ret); > + > + ret = devm_regulator_get_enable(dev, "vdd"); > + if (ret) > + return dev_err_probe(dev, ret, > + "Failed to get vdd regulator\n"); > + > + st->vddio_supply = devm_regulator_get(dev, "vddio"); > + if (IS_ERR(st->vddio_supply)) > + return dev_err_probe(dev, PTR_ERR(st->vddio_supply), > + "Failed to get vddio regulator\n"); > + > + ret = inv_icm42607_enable_vddio_reg(st); > + if (ret) > + return ret; > + > + ret = devm_add_action_or_reset(dev, inv_icm42607_disable_vddio_reg, st); > + if (ret) > + return ret; > + > + /* Setup chip registers (includes WHOAMI check, reset check, bus setup) */ > + ret = inv_icm42607_setup(st, bus_setup); > + if (ret) > + return ret; > + > + return 0; > +} > +EXPORT_SYMBOL_NS_GPL(inv_icm42607_core_probe, "IIO_ICM42607"); > + > +MODULE_AUTHOR("InvenSense, Inc."); > +MODULE_DESCRIPTION("InvenSense ICM-42607x device driver"); > +MODULE_LICENSE("GPL"); > +MODULE_IMPORT_NS("IIO_INV_SENSORS_TIMESTAMP"); _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip