Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9297456ybi; Wed, 10 Jul 2019 07:58:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzaQiFTt3v+M8uvi7MjqsQ2Qkx7AgQPd4zAtYGWPO+BpClWILT69dP32KGvix328CKsS6iL X-Received: by 2002:a63:c442:: with SMTP id m2mr25086269pgg.286.1562770688938; Wed, 10 Jul 2019 07:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562770688; cv=none; d=google.com; s=arc-20160816; b=tjlibbUZG0jVE8AKACNOAUKMoLNuSF6aCK9ONIIPSVtDxGCND3tcVVbOhfFkeHidV0 NbqweUPpKz8VVIfRhGUv+iNK2zuYOaPLs6SjO5x2W0UOJrmlkRzb2TDgwe7KRRnnfcEe zwDthmulgn+PpCqtXS5efewPrl6vzfdzVP+Q/hi4sJwdbd6emb5wi+qVK0HMrsUwB6KD AQPoxN0fgc8mOuZu9VNi8uBk+rKVfaDrCSlTsqn3CAZW7UDb30XkTkR7bUj5QwIXvfhP fNjmYJi6sJMvl8HLZh2mRlxyeVo6LcpVgSwyKx7LnzcjEfWSMDMExZUvUvF4cE84KiBn 7n4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=aG0EWLgpW5qbP9aOhsP77bsa/og0Np1ghF7cfyGV8LY=; b=mMDdtDtXxEoRKlXw7uF+6nUh8+9hCPyi5Rfpkzqi3NK0a/AZZBtW+Hl9VxGMKm1KZC ppH/v7F2YPw8SuYt5RfO2h1ukjPEEvPJ9kIHC0J8kViCzvuN4YC9VpwLKDEqH/wyhOxL 1lv0w85YWO5270yhMrzheg8C0m7iTK20+kaG+T2ZJBZoZLgh3M3EjFagPzqeCWWtkblv miP8syE9Sg8SCF2VRsAz0Q1Ulzp0gydeiuibeDeAAwMOW4WPeWwfDrqxwvPxsLbH7HPe ufQqvfaBHjZw/kqGwGvRDS1DwdiPPDGY4/FPDLehUjxqTonoAskeLyvdQVnjnyOCOzCW 441g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=LKToBncg; 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=NONE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k13si2450563pfk.162.2019.07.10.07.57.52; Wed, 10 Jul 2019 07:58:08 -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; dkim=pass header.i=@synopsys.com header.s=mail header.b=LKToBncg; 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=NONE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727938AbfGJO4q (ORCPT + 99 others); Wed, 10 Jul 2019 10:56:46 -0400 Received: from smtprelay-out1.synopsys.com ([198.182.47.102]:46678 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725956AbfGJO4o (ORCPT ); Wed, 10 Jul 2019 10:56:44 -0400 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id BFFCDC29DA; Wed, 10 Jul 2019 14:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1562770604; bh=1V12/8vGPInih5p0qyGvRVu7+Sn4cjnbPSEjTahhJIU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=LKToBncgunSxfr2w1kcVAXG8s8lQF8yjGRfJUNWE8SXCQ1Qh/5SxyYlE0kee+Wv79 3uUsg0CKONgCu3UP3mUzOgRlDSer4Crk7zer/ZpK2bNJq2mp4l58UVdHNDy+span9j z2CLPkbdZRIBnxMFHTSXDmTzVvC73UirF/GHw6cUkMzDDWX8Tt0D+Y4EO40Ba/fPAh TYS3ULJ2IgTME+H5EB1OukR831gVIPv7jt41bDIYtve/KIc/FYMD+WZoxCiNpKDB04 YugI3T4lgi1npV1n4kB8N+v4xBqpJS1IbLr+uuImiY28oKrrhswAjhC1tZGxmEKvaT GUZp3jsTjR4dQ== Received: from de02.synopsys.com (de02.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id 48A7CA005C; Wed, 10 Jul 2019 14:56:42 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id 061C23FA39; Wed, 10 Jul 2019 16:56:42 +0200 (CEST) From: Vitor Soares To: linux-iio@vger.kernel.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Cc: broonie@kernel.org, lorenzo@kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org, bbrezillon@knernel.org, Joao.Pinto@synopsys.com, Vitor Soares Subject: [PATCH v3 3/3] iio: imu: st_lsm6dsx: add i3c basic support for LSM6DSO and LSM6DSR Date: Wed, 10 Jul 2019 16:56:39 +0200 Message-Id: <73955529ae0c31f428221abb88031ab3b4165659.1562767521.git.vitor.soares@synopsys.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For today the st_lsm6dsx driver support LSM6DSO and LSM6DSR sensor only in spi and i2c mode. The LSM6DSO and LSM6DSR are also i3c capable so lets give i3c support to them. Signed-off-by: Vitor Soares Acked-by: Lorenzo Bianconi --- Changes in v3: Remove unnecessary st_lsm6dsx_i3c_data table used to hold device name Use st_lsm6dsx_probe new form Changes in v2: Add support for LSM6DSR Set pm_ops to st_lsm6dsx_pm_ops drivers/iio/imu/st_lsm6dsx/Kconfig | 8 +++- drivers/iio/imu/st_lsm6dsx/Makefile | 1 + drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c | 61 +++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c diff --git a/drivers/iio/imu/st_lsm6dsx/Kconfig b/drivers/iio/imu/st_lsm6dsx/Kconfig index 9e59297..6b5a73c 100644 --- a/drivers/iio/imu/st_lsm6dsx/Kconfig +++ b/drivers/iio/imu/st_lsm6dsx/Kconfig @@ -1,11 +1,12 @@ config IIO_ST_LSM6DSX tristate "ST_LSM6DSx driver for STM 6-axis IMU MEMS sensors" - depends on (I2C || SPI) + depends on (I2C || SPI || I3C) select IIO_BUFFER select IIO_KFIFO_BUF select IIO_ST_LSM6DSX_I2C if (I2C) select IIO_ST_LSM6DSX_SPI if (SPI_MASTER) + select IIO_ST_LSM6DSX_I3C if (I3C) help Say yes here to build support for STMicroelectronics LSM6DSx imu sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm, @@ -23,3 +24,8 @@ config IIO_ST_LSM6DSX_SPI tristate depends on IIO_ST_LSM6DSX select REGMAP_SPI + +config IIO_ST_LSM6DSX_I3C + tristate + depends on IIO_ST_LSM6DSX + select REGMAP_I3C diff --git a/drivers/iio/imu/st_lsm6dsx/Makefile b/drivers/iio/imu/st_lsm6dsx/Makefile index e5f733c..c676965 100644 --- a/drivers/iio/imu/st_lsm6dsx/Makefile +++ b/drivers/iio/imu/st_lsm6dsx/Makefile @@ -4,3 +4,4 @@ st_lsm6dsx-y := st_lsm6dsx_core.o st_lsm6dsx_buffer.o \ obj-$(CONFIG_IIO_ST_LSM6DSX) += st_lsm6dsx.o obj-$(CONFIG_IIO_ST_LSM6DSX_I2C) += st_lsm6dsx_i2c.o obj-$(CONFIG_IIO_ST_LSM6DSX_SPI) += st_lsm6dsx_spi.o +obj-$(CONFIG_IIO_ST_LSM6DSX_I3C) += st_lsm6dsx_i3c.o diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c new file mode 100644 index 0000000..f683754 --- /dev/null +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2018 Synopsys, Inc. and/or its affiliates. + * + * Author: Vitor Soares + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "st_lsm6dsx.h" + +static const struct i3c_device_id st_lsm6dsx_i3c_ids[]; + +static const struct regmap_config st_lsm6dsx_i3c_regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; + +static int st_lsm6dsx_i3c_probe(struct i3c_device *i3cdev) +{ + const struct i3c_device_id *id = i3c_device_match_id(i3cdev, + st_lsm6dsx_i3c_ids); + struct regmap *regmap; + int hw_id = (int)id->data; + + regmap = devm_regmap_init_i3c(i3cdev, &st_lsm6dsx_i3c_regmap_config); + if (IS_ERR(regmap)) { + dev_err(&i3cdev->dev, "Failed to register i3c regmap %d\n", + (int)PTR_ERR(regmap)); + return PTR_ERR(regmap); + } + + return st_lsm6dsx_probe(&i3cdev->dev, 0, hw_id, regmap); +} + +static const struct i3c_device_id st_lsm6dsx_i3c_ids[] = { + I3C_DEVICE(0x0104, 0x006C, (void *)ST_LSM6DSO_ID), + I3C_DEVICE(0x0104, 0x006B, (void *)ST_LSM6DSR_ID), + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(i3c, st_lsm6dsx_i3c_ids); + +static struct i3c_driver st_lsm6dsx_driver = { + .driver = { + .name = "st_lsm6dsx_i3c", + .pm = &st_lsm6dsx_pm_ops, + }, + .probe = st_lsm6dsx_i3c_probe, + .id_table = st_lsm6dsx_i3c_ids, +}; +module_i3c_driver(st_lsm6dsx_driver); + +MODULE_AUTHOR("Vitor Soares "); +MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i3c driver"); +MODULE_LICENSE("GPL v2"); -- 2.7.4