Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp2572691pxb; Sat, 19 Feb 2022 16:02:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcydUg66M8T9IcQQzNvVHPcqN0tu2fujQqgWu8BEK6mNtG3sBPppmkxcoTdP47pzZ3p22q X-Received: by 2002:a17:906:3e4b:b0:6cf:7f02:9332 with SMTP id t11-20020a1709063e4b00b006cf7f029332mr11064810eji.404.1645315355936; Sat, 19 Feb 2022 16:02:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645315355; cv=none; d=google.com; s=arc-20160816; b=wyQrbInXXJXYYe7TrpMEft0Dg5+GH/kTtPNeem92ijZ0YFiVxIefmH68tKe2DXd2cM 2fNv7M1Al7sKIx19Q0HmV/qWgOYNW068Z8IjCqAJ8ZJr/aOh23wRt1LE/jiafK6oafSh OyCB5OvG2D3iHL2e/SwLsNpo5SPS857cxO2ImpJPqUYvd55EIyz/dDm5DfW4yE4dcI4A 2UFYNXFJ/xDWln9zwMSCTeQ3NNcCSqOXXrniMwV9m8f2f6oIHhoUg51ZZSdsE7fBPKHa XJN6o+XXT1lItBcigjaAOJ2W7cZTJadlttjHsDhoy3udzk/x2fN0bFVIYJIaTKipq00m ljFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=etehltvEP/pgLTGMQujptQ6/1hpx+5nDP9N67+ogigA=; b=aS6wsu3nQOD851gCcOm/eXqHOxHqGaMiRQRIebqhOXDGT2NpuxujonViNwi4xrmR67 qBXPJfBUwT8NbkGamuv9k5BXP7hVF+SGaaa/YYDSsu+WfuHCusDQYGBh1nxk+uw3N7ds H1iUe1oKuGXQO0virKp7V3gVMGepcifXb23mZWzPIS2Rx1O2uvxcP2sqkLxGz3xHdL1Q NL49numEej6y5sI0LOG2lkN83xuvDGzUOIQcI1EjopjejAUD3BRbnwn1YITABc4kd7Ka rriWVJdZkNGjIAYxuesGc5pkw5ag6DBtR3MjZWMERvgZ1YpkFcnpSvoy0czjLEWI4KKv q1og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="BCcJ/ZzL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fz1si8272951ejc.338.2022.02.19.16.02.12; Sat, 19 Feb 2022 16:02:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="BCcJ/ZzL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242670AbiBSQ4w (ORCPT + 99 others); Sat, 19 Feb 2022 11:56:52 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:35492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242620AbiBSQ4s (ORCPT ); Sat, 19 Feb 2022 11:56:48 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80E3D20F6E; Sat, 19 Feb 2022 08:56:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2C0B9B80881; Sat, 19 Feb 2022 16:56:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B58C2C004E1; Sat, 19 Feb 2022 16:56:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645289785; bh=cino2dQZWLjiKLJnkvRKaH07YeivuoFw+I6EHne7xus=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=BCcJ/ZzLcTG8DdctXxnw8eXj6r0O6bCjWZgVs0Hz9J9aGZfIfZD04IhKQ63G+VEDd 9dANNr8A9Js8uQFeYg89X+d21LcWYhJwjbG0rgvjApT/2OsGwCY8Wr2QHm3Lckh39r /jkWhfhbHm9TAX2cuu1+vjrWa5OcogTG8l/Js+yMaCug4Lxyc/itY3AbHexCXcwza8 ZlSLymgCtEI95pZ27iym+5O/uHROSqc97TQVhhp6qbOJgrTr89YZvn3PaMZWjqtKvm lkQSjkZaiQaimZBOgFv3fW3kqy3XdzebRew1XbmH26lQDkKwcugXhV44eFfjB73kiV M1eCniyuKfZHQ== Date: Sat, 19 Feb 2022 17:03:13 +0000 From: Jonathan Cameron To: Andrea Merello Cc: mchehab+huawei@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, lars@metafoo.de, robh+dt@kernel.org, andy.shevchenko@gmail.com, matt.ranostay@konsulko.com, ardeleanalex@gmail.com, jacopo@jmondi.org, Andrea Merello Subject: Re: [v3 12/13] iio: imu: add BNO055 I2C driver Message-ID: <20220219170313.78e64ddd@jic23-huawei> In-Reply-To: <20220217162710.33615-13-andrea.merello@gmail.com> References: <20220217162710.33615-1-andrea.merello@gmail.com> <20220217162710.33615-13-andrea.merello@gmail.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 17 Feb 2022 17:27:09 +0100 Andrea Merello wrote: > This path adds an I2C driver for communicating to a BNO055 IMU via I2C > bus and it enables the BNO055 core driver to work in this scenario. > > Signed-off-by: Andrea Merello Minor comment inline to add an of_device_id table. Isn't i2c so much nicer than serial? :) Thanks, Jonathan > --- > drivers/iio/imu/bno055/Kconfig | 11 +++++++ > drivers/iio/imu/bno055/Makefile | 1 + > drivers/iio/imu/bno055/bno055_i2c.c | 50 +++++++++++++++++++++++++++++ > 3 files changed, 62 insertions(+) > create mode 100644 drivers/iio/imu/bno055/bno055_i2c.c > > diff --git a/drivers/iio/imu/bno055/Kconfig b/drivers/iio/imu/bno055/Kconfig > index 8a83639ad2a9..3693a408e270 100644 > --- a/drivers/iio/imu/bno055/Kconfig > +++ b/drivers/iio/imu/bno055/Kconfig > @@ -12,3 +12,14 @@ config BOSCH_BNO055_SERIAL > > This driver can also be built as a module. If so, the module will be > called bno055_sl. > + > +config BOSCH_BNO055_I2C > + tristate "Bosch BNO055 attached via I2C bus" > + depends on I2C > + select REGMAP_I2C > + select BOSCH_BNO055_IIO > + help > + Enable this to support Bosch BNO055 IMUs attached via I2C bus. > + > + This driver can also be built as a module. If so, the module will be > + called bno055_i2c. > diff --git a/drivers/iio/imu/bno055/Makefile b/drivers/iio/imu/bno055/Makefile > index 416f0ff96de5..2fe2b0857903 100644 > --- a/drivers/iio/imu/bno055/Makefile > +++ b/drivers/iio/imu/bno055/Makefile > @@ -2,3 +2,4 @@ > > obj-$(CONFIG_BOSCH_BNO055_IIO) += bno055.o > obj-$(CONFIG_BOSCH_BNO055_SERIAL) += bno055_sl.o > +obj-$(CONFIG_BOSCH_BNO055_I2C) += bno055_i2c.o > diff --git a/drivers/iio/imu/bno055/bno055_i2c.c b/drivers/iio/imu/bno055/bno055_i2c.c > new file mode 100644 > index 000000000000..9900e2a4d905 > --- /dev/null > +++ b/drivers/iio/imu/bno055/bno055_i2c.c > @@ -0,0 +1,50 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Support for I2C-interfaced Bosch BNO055 IMU. > + * > + * Copyright (C) 2021 Istituto Italiano di Tecnologia > + * Electronic Design Laboratory > + * Written by Andrea Merello > + */ > + > +#include > +#include > +#include > + > +#include "bno055.h" > + > +#define BNO055_I2C_XFER_BURST_BREAK_THRESHOLD 3 /* FIXME */ > + > +static int bno055_i2c_probe(struct i2c_client *client, > + const struct i2c_device_id *id) > +{ > + struct regmap *regmap = > + devm_regmap_init_i2c(client, &bno055_regmap_config); > + > + if (IS_ERR(regmap)) { > + dev_err(&client->dev, "Unable to init register map"); > + return PTR_ERR(regmap); > + } > + > + return bno055_probe(&client->dev, regmap, > + BNO055_I2C_XFER_BURST_BREAK_THRESHOLD, true); > +} > + > +static const struct i2c_device_id bno055_i2c_id[] = { > + {"bno055", 0}, > + { } > +}; > +MODULE_DEVICE_TABLE(i2c, bno055_i2c_id); No of_device_id table? Whilst the fallback path that usese the i2c_device_id will mostly work, it leaves us in theory more susceptible to naming clashes and is generally not as nice. Hence definitely prefer it if we have an of_device_id table as well as the i2c_device_id one. > + > +static struct i2c_driver bno055_driver = { > + .driver = { > + .name = "bno055-i2c", > + }, > + .probe = bno055_i2c_probe, > + .id_table = bno055_i2c_id > +}; > +module_i2c_driver(bno055_driver); > + > +MODULE_AUTHOR("Andrea Merello"); > +MODULE_DESCRIPTION("Bosch BNO055 I2C interface"); > +MODULE_LICENSE("GPL v2");