From patchwork Mon Feb 4 17:00:10 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: 157442 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4137517jaa; Mon, 4 Feb 2019 09:00:33 -0800 (PST) X-Google-Smtp-Source: AHgI3IZYZCHIQhRuraEEDdEmzu7fo5vP6nkBhsEm3nIgmNpsICXWPGMILM2F0NFKZJJaPz3t09iL X-Received: by 2002:a63:193:: with SMTP id 141mr333051pgb.136.1549299633403; Mon, 04 Feb 2019 09:00:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549299633; cv=none; d=google.com; s=arc-20160816; b=FLveRe5QmjtuC+dhyNEwu/SdGlPrmZkByBm4a0ezMkfsHfBrrH9Bb4RZEs8i0YK33E jmz3yQKd98kY8kqUpLkoB1Bi3EJXx5LuSvYXwlkcmGw8REZWCqfIOJqVlYC2zNk3NGKp NpND3Gq1HcZH/M7YvgWfGQT1zFg5ebdlJHwe5Z+vzzKjqQjmkMXODXRKTtFclpIFHImZ LP8G1PxJg5eHwGhoMfSjxwy7AdTrsFjRL7UFYS8OgXIcs6lFCGgzYEXVB4hBMOBmN7FS Zd7IRHufDc9Z1hkiWeYHb6KmMRral0UGejRvORKas3wo3hAPIxzOck0mnvJXIB2LljrW VGhw== 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=5f8oMTPzqMVYaxal2igosMLVQNNuQ7nNTfzq//5p9Iw=; b=1D3Gf3mYD7Yxmv10vmzpBb/5ZStACVaWWhfdwyHITEe0qRsLqMqDW7Ejd+68gafcth eOb7HHOsxrT/U3qpnhDPO6o0KIDBeGfRSpPWh7QC0GTd5335rckAhb4JxahpnEm78ufk YUYrrrm0FoCOVq+T8tmSFnf1J7w3IvQMH8CJRSn2L2bOYD+acxArnZZ+/hbqWH/zS1UL CFu5/ciD1dAjNykbUO/eAGwB2tnjjysYi0899ubK5WuPHHthCPw3q9h+tc9Ctf7R7l6W h+mixjahHC7jiHu7NnJyvTOmSD5zRBpPp3VcDB0B0Er0xiKxQYNybjGFJ+g60x1YZKRk NNgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aYObJGOh; 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 m64si502677pfb.224.2019.02.04.09.00.33; Mon, 04 Feb 2019 09:00:33 -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=aYObJGOh; 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 S1728937AbfBDRAc (ORCPT + 7 others); Mon, 4 Feb 2019 12:00:32 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38493 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728861AbfBDRAc (ORCPT ); Mon, 4 Feb 2019 12:00:32 -0500 Received: by mail-wm1-f67.google.com with SMTP id m22so677280wml.3 for ; Mon, 04 Feb 2019 09:00:30 -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=5f8oMTPzqMVYaxal2igosMLVQNNuQ7nNTfzq//5p9Iw=; b=aYObJGOhZohn7H47dJU7KBgYnT5NmbtMXBE1lpevT+oKYzTmH21o4e7NqzOlpzyoON iOdadJpCNyDfZQfj+bYpZVkYLjcKtk9wMWzAweYO75oYp++ktnu7pEMtsMUkcy4I66Aq uYC2p1rHW3+UK21ps119uCA5d0EAdHNTuanzI= 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=5f8oMTPzqMVYaxal2igosMLVQNNuQ7nNTfzq//5p9Iw=; b=PniO9lo94lvoTIu0ZuxhUxPeN6kROlK5wLbDYbhBcJILVUQ5MKEkRH6Sr6TP54knL4 QMxJ0dS4UT4dlIfGzF31rTU6KtGXYXb8T1rwymOYEZXJqiQS5ZhSHKGtyQEMMc1A43zU c0hYo8122IrstfG7gh32g9aJ4hhhSUIVuCZRMGo56WsAKYUfZJmfKwnn9fOPJMkZyb+h wT3CsR3p9Cp6RqVUy7oahxEIs4d65r9vUeHEfqwrbfM046XbMSGjkFQ2sKsugqEyTWrb bzVTG8LB5XHHcgtXfKlOBYZb5mLuDSH+xEB1ihdN4W4AGcHoRoLAeakkBmXRudMKaQAF AdrA== X-Gm-Message-State: AHQUAuaOXoaW/CbxmCgVS0qW6DktCYz48T7rYr7NioO2o2bv0+vSh+1Q BUmVFo0hcrFldNtyoeqwhRdGAQ== X-Received: by 2002:a7b:cb86:: with SMTP id m6mr249233wmi.61.1549299629980; Mon, 04 Feb 2019 09:00:29 -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 i186sm19352297wmd.19.2019.02.04.09.00.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Feb 2019 09:00:29 -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 3/5] iio: gyro: fxas2100x: add i2c driver Date: Mon, 4 Feb 2019 17:00:10 +0000 Message-Id: <20190204170012.13617-4-rui.silva@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204170012.13617-1-rui.silva@linaro.org> References: <20190204170012.13617-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..af4e8af6d301 --- /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,fxas2100x", }, + { }, +}; +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");