From patchwork Tue Feb 5 17:43:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Miguel Silva X-Patchwork-Id: 157507 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5445252jaa; Tue, 5 Feb 2019 09:43:57 -0800 (PST) X-Google-Smtp-Source: AHgI3IZnPoOreRzr49v1RRVYb9gnDKj2Ibyoah8RK5orHhVnbXlNvlUwuh62IQXOccICbKCWGfjM X-Received: by 2002:a63:5723:: with SMTP id l35mr5407133pgb.228.1549388637358; Tue, 05 Feb 2019 09:43:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549388637; cv=none; d=google.com; s=arc-20160816; b=Y6e9ftf5oQ4/08SYGs+QUlybLQ/A6L4+6bvolij0+YIVKhOJrUdS+oTgsjr+HKLLWj 3bldPBuccT9dYcudzLqhJWcpMXEKMWHoUcqpe0g+UwpGtjUHTMaGWQyL4H1OTdEqx1Wv 5a6RNOdrrmb1BqL3+VH0TvE/Kpu9O9ybLmVi9YLZxI05uBLv8nyTKRhFtDAdOWLsnpIk oPSrzUbbLaoKBUum05KD00gQKK2XTuGQqxPXtkD2ts+Rj+KpOyMrQy8IkB85xXk18Mdj Q3tPToSn7t+zOQEyG1SzSD/Z2fvaBwBUWtgfX0FUnBemXvBy9SMLXIfX8hA3CJUr3I/x kQ4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2luiUc6gzFLBKKxk29xFnHm2KXg4oKTSaw5uIVColWk=; b=LjIxaw40006M6gRQxSTnPxgLBtDn6EvXIjYkA8hStlsKFSm+aeM5esVyDiuoBLbRtx 4Dt3V8p3pZs9oOylDerj3lNnFbbkrpA+hxPQSsexe8oG8MfxKJlzkt0n1jzkr9+gE2qd SFcOgILmK56AnedhOIGHU9UXuDbx/J6lnpDB5Vz+0XXJahnWbbAZcf+PWHwP/faOa5FX vQgFny90AjU2RKGO6X/YMVbJ6Vs5XCw7/Kq2256hkwRtNUN0hYyK8RlCSI0IDNxDjzX6 woMRxf8pGSYQ6BL4jgIJkUDD8yKVo0gzZE0MxogrZ8qY069ERFDF6jX92vugRlQlLiRM xgDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rjVwGa4L; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g8si3413699pgb.128.2019.02.05.09.43.57; Tue, 05 Feb 2019 09:43:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-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=@linaro.org header.s=google header.b=rjVwGa4L; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728740AbfBERn4 (ORCPT + 7 others); Tue, 5 Feb 2019 12:43:56 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:53308 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728614AbfBERn4 (ORCPT ); Tue, 5 Feb 2019 12:43:56 -0500 Received: by mail-wm1-f68.google.com with SMTP id d15so4581097wmb.3 for ; Tue, 05 Feb 2019 09:43:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2luiUc6gzFLBKKxk29xFnHm2KXg4oKTSaw5uIVColWk=; b=rjVwGa4L999FeZ3SVbbJ4+aGsJWVX8rXVl+QWAqfkR5qA43P+71VQlBAjbrZUMxrQ5 ZUm5cIEOfvR+X+85JftO81d8SCgK1DNvTy9eFvmi+ChncIEyh6DZGEZqmNuj7pDlBdVU IcGnvDmnG7yRtw4Quk/8/Yun87pQOSe0LT1WXe/g+vrcziA4y3cEjwgylvQF45TIW7G1 pbyD0oZRZZlKHT853SdWekLwi3Q6TJaiin5vredXltaYgykbIbQ+LmK6lpYA1oCrufMv QhCTBFh2JiC1swzaE5aVbkEWOy5vQvJgnMaae1btA9BZtf1J26iMuI2OTr+a+G1xWa9L 1NCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2luiUc6gzFLBKKxk29xFnHm2KXg4oKTSaw5uIVColWk=; b=SvWzSmFRHh2gRF3+Rt6ddeVbKPExqM4KkaMKdZjPKOq8jNDF+hh5/vJLL25XqK9lEd 6Zbq6zrXA1UDBvhm8Nsd8ZJu3mnB9WGPo4jKn0V+jFu0OYR9oyAlt5SvdtRwr2jHDDiZ YsfrZkwwvAMhumzgCVCh2vC3IUIeesf0e4Q9aGS+3f5XRS44qz7z3N7tyyVtLtxGFMeP /blUenNLsrAr4ZgWSTjsNods4wthdMJ4k4zv50ONkDcnT3X4dHwBAD2Dbi3ECfA/kZsp 9nbzRrMhL6OSnHiWl8fdcfjTzO5tOb6WDkAuid+oLo1zV+G//Jvi9kC8UrNG3GtsloJh pkkg== X-Gm-Message-State: AHQUAuZ7kJzExgS6UNghbRRNtFw61caefNkmC6badeKj3PMY2MK6bTWr cvs5AyznPQ+qSQhPgCB0+oW7hA== X-Received: by 2002:a7b:c1d7:: with SMTP id a23mr4475270wmj.48.1549388633646; Tue, 05 Feb 2019 09:43:53 -0800 (PST) Received: from arch-late.local (a109-49-46-234.cpe.netcabo.pt. [109.49.46.234]) by smtp.gmail.com with ESMTPSA id s132sm12225751wmf.28.2019.02.05.09.43.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Feb 2019 09:43:53 -0800 (PST) From: Rui Miguel Silva To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Shawn Guo , Rob Herring , Fabio Estevam Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Rui Miguel Silva Subject: [PATCH v2 3/5] iio: gyro: fxas2100x: add i2c driver Date: Tue, 5 Feb 2019 17:43:31 +0000 Message-Id: <20190205174333.17672-4-rui.silva@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190205174333.17672-1-rui.silva@linaro.org> References: <20190205174333.17672-1-rui.silva@linaro.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This add the real driver to talk over i2c and use the fxas2100x core for the main tasks. Signed-off-by: Rui Miguel Silva --- drivers/iio/gyro/Kconfig | 6 +++ drivers/iio/gyro/Makefile | 1 + drivers/iio/gyro/fxas2100x_i2c.c | 73 ++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 drivers/iio/gyro/fxas2100x_i2c.c -- 2.20.1 diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig index c168aa63de3b..1f9bfc51febb 100644 --- a/drivers/iio/gyro/Kconfig +++ b/drivers/iio/gyro/Kconfig @@ -77,6 +77,8 @@ config FXAS2100X tristate "NXP FXAS2100X Gyro Sensor" select IIO_BUFFER select IIO_TRIGGERED_BUFFER + select FXAS2100X_I2C if (I2C) + depends on (I2C || SPI_MASTER) help Say yes here to build support for NXP FXAS2100X family Tri-axis Gyro Sensor driver connected via I2C or SPI. @@ -84,6 +86,10 @@ config FXAS2100X This driver can also be built as a module. If so, the module will be called fxas2100x_i2c or fxas2100x_spi. +config FXAS2100X_I2C + tristate + select REGMAP_I2C + config HID_SENSOR_GYRO_3D depends on HID_SENSOR_HUB select IIO_BUFFER diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile index 9e2395185a6e..8b1540ddbbce 100644 --- a/drivers/iio/gyro/Makefile +++ b/drivers/iio/gyro/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_BMG160) += bmg160_core.o obj-$(CONFIG_BMG160_I2C) += bmg160_i2c.o obj-$(CONFIG_BMG160_SPI) += bmg160_spi.o obj-$(CONFIG_FXAS2100X) += fxas2100x_core.o +obj-$(CONFIG_FXAS2100X_I2C) += fxas2100x_i2c.o obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o diff --git a/drivers/iio/gyro/fxas2100x_i2c.c b/drivers/iio/gyro/fxas2100x_i2c.c new file mode 100644 index 000000000000..b8f6d2b7f6dd --- /dev/null +++ b/drivers/iio/gyro/fxas2100x_i2c.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Driver for NXP FXAS2100x Gyroscope - I2C + * + * Copyright (C) 2018 Linaro Ltd. + * + */ +#include +#include +#include +#include + +#include "fxas2100x.h" + +static const struct regmap_config fxas2100x_regmap_i2c_conf = { + .reg_bits = 8, + .val_bits = 8, + .max_register = FXAS2100X_REG_CTRL3, +}; + +static int fxas2100x_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) +{ + struct regmap *regmap; + const char *name = NULL; + + regmap = devm_regmap_init_i2c(i2c, &fxas2100x_regmap_i2c_conf); + if (IS_ERR(regmap)) { + dev_err(&i2c->dev, "Failed to register i2c regmap: %ld\n", + PTR_ERR(regmap)); + return PTR_ERR(regmap); + } + + if (id) + name = id->name; + + return fxas2100x_core_probe(&i2c->dev, regmap, i2c->irq, name); +} + +static int fxas2100x_i2c_remove(struct i2c_client *i2c) +{ + fxas2100x_core_remove(&i2c->dev); + + return 0; +} + +static const struct i2c_device_id fxas2100x_i2c_id[] = { + { "fxas2100x", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, fxas2100x_i2c_id); + +static const struct of_device_id fxas2100x_i2c_of_match[] = { + { .compatible = "nxp,fxas21002", }, + { }, +}; +MODULE_DEVICE_TABLE(of, fxas2100x_i2c_of_match); + +static struct i2c_driver fxas2100x_i2c_driver = { + .driver = { + .name = "fxas2100x_i2c", + .pm = &fxas2100x_pm_ops, + .of_match_table = of_match_ptr(fxas2100x_i2c_of_match), + }, + .probe = fxas2100x_i2c_probe, + .remove = fxas2100x_i2c_remove, + .id_table = fxas2100x_i2c_id, +}; +module_i2c_driver(fxas2100x_i2c_driver); + +MODULE_AUTHOR("Rui Miguel Silva "); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("FXAS2100X I2C Gyro driver");