From patchwork Wed Oct 24 01:39:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10654111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E0F514BD for ; Wed, 24 Oct 2018 03:15:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 227E229F77 for ; Wed, 24 Oct 2018 03:15:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1653E2A209; Wed, 24 Oct 2018 03:15:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A42D329F77 for ; Wed, 24 Oct 2018 03:15:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726301AbeJXLl0 (ORCPT ); Wed, 24 Oct 2018 07:41:26 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:39461 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725952AbeJXLl0 (ORCPT ); Wed, 24 Oct 2018 07:41:26 -0400 Received: by mail-pl1-f196.google.com with SMTP id e67-v6so1567406plb.6 for ; Tue, 23 Oct 2018 20:15:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martingkelly-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=0C/jgL0qR5hjEgdfyqIDTpOWwLl3IM7ncgI4KZ5XNuM=; b=qY8rn7VQbQ8ZEjhGywcPpIAKMPPrt/nyY6yo7qhD2ksXKudJz+BYTxoPTh9P+thcsI yGoEL1ucDGN1Wkc+kUCIbrO9P0hLpX7tS1lj/SZfvmH5EpO9Tct33gfob9tXlkXv+yEz wRd07sv00C76BqVNiCa6njsMpV3kXC2RUgjoKxXoE2pa2/i6UkYlpsjQQ35NBF3ZOGq2 yaeTQszxCDS/uTXCUPr8RbZm3jlb2rB4DYmzW5/BdnqQAPMoPbAi733RkaLR1WDPUNs4 YlMHsu3a9GeHu1RA5fcrtGXnUYDo06dSODiBGGMy0vABvRR8GGsp4/GBKYbtWi1Gp6l9 9kVA== 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; bh=0C/jgL0qR5hjEgdfyqIDTpOWwLl3IM7ncgI4KZ5XNuM=; b=ctm5GizSJWscZ8lgHKn2ZnJiA0gaouYIji/PB0tbb7bdFA4I8+i0bmdAgTM6gsylXZ ZDYpoWf9BnA2lLs0sxS8+36Z1RC4u+a1NMcFLccIM8kpAOtn5DEoa4328+joCWUH5iuD BVXS+Yl1hQgFWp0ElM2n/RCkFFix3RLZ+khV9Aa+eoGHIPUAH99uje7s8bMMA4NZwJ35 iCtQgoDsvLPqQsBeQihyUmuvC/eZz/zNaYTSsZg6fS0EqaENTVWRciHTLvjM2Ok7p+9Q S7H16D55I/+LoJ/X23vZNdl01FtdMXHkiv4CyCTqkbHGir80L6mzNVM/7m6Cj9bhndXz Sqcg== X-Gm-Message-State: AGRZ1gLb452Ec/mgUqCAElFVc3QlVuEqAWlJV4wn71xwUVuiy2M/y9ye jBrRVYgYCEvgMMTDMjXHZa587qtd1cB8ag== X-Google-Smtp-Source: AJdET5fdoGEWGJfhJeDNFsaNt9fSU4Uy+U9Py34KeYrZyW4DlRZthSz30BUBaOwjgKiA4CAY0zcVIA== X-Received: by 2002:a17:902:aa84:: with SMTP id d4-v6mr638997plr.25.1540345201176; Tue, 23 Oct 2018 18:40:01 -0700 (PDT) Received: from cascade.Home (71-212-17-184.tukw.qwest.net. [71.212.17.184]) by smtp.gmail.com with ESMTPSA id x23-v6sm3221043pfh.56.2018.10.23.18.40.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Oct 2018 18:40:00 -0700 (PDT) From: Martin Kelly X-Google-Original-From: Martin Kelly , Denis Ciocca , Jonathan Cameron , Rob Herring , Mark Rutland , Martin Kelly Subject: [PATCH 1/2] iio:magnetometer: st_magn: add LSM9DS1 support Date: Tue, 23 Oct 2018 18:39:47 -0700 Message-Id: <20181024013948.16326-1-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Kelly Update the sensor settings to support the LSM9DS1 sensor. Although the LSM9DS1 accelerometer and gyroscope are coupled together to use the same FIFO, the magnetometer is separate and can be cleanly supported without refactoring the existing driver. Signed-off-by: Martin Kelly --- drivers/iio/magnetometer/st_magn.h | 1 + drivers/iio/magnetometer/st_magn_core.c | 68 +++++++++++++++++++++++++++++++++ drivers/iio/magnetometer/st_magn_spi.c | 5 +++ 3 files changed, 74 insertions(+) diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h index 8fe51ce427bd..3a4abcd1f106 100644 --- a/drivers/iio/magnetometer/st_magn.h +++ b/drivers/iio/magnetometer/st_magn.h @@ -20,6 +20,7 @@ #define LIS3MDL_MAGN_DEV_NAME "lis3mdl" #define LSM303AGR_MAGN_DEV_NAME "lsm303agr_magn" #define LIS2MDL_MAGN_DEV_NAME "lis2mdl" +#define LSM9DS1_MAGN_DEV_NAME "lsm9ds1" int st_magn_common_probe(struct iio_dev *indio_dev); void st_magn_common_remove(struct iio_dev *indio_dev); diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c index 72f6d1335a04..dfbdeb428467 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -378,6 +378,74 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = { .multi_read_bit = false, .bootime = 2, }, + { + .wai = 0x3d, + .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, + .sensors_supported = { + [0] = LSM9DS1_MAGN_DEV_NAME, + }, + .ch = (struct iio_chan_spec *)st_magn_2_16bit_channels, + .odr = { + /* Fast ODR mode currently not supported. */ + .addr = 0x20, + .mask = 0x1c, + .odr_avl = { + { .hz = 5, .value = 0x03 }, + { .hz = 10, .value = 0x04 }, + { .hz = 20, .value = 0x05 }, + { .hz = 40, .value = 0x06 }, + { .hz = 80, .value = 0x07 }, + }, + }, + .pw = { + .addr = 0x22, + .mask = 0x03, + .value_on = 0x00, + .value_off = 0x03, + }, + .fs = { + .addr = 0x21, + .mask = 0x60, + .fs_avl = { + [0] = { + .num = ST_MAGN_FS_AVL_4000MG, + .value = 0x00, + .gain = 140, + }, + [1] = { + .num = ST_MAGN_FS_AVL_8000MG, + .value = 0x01, + .gain = 290, + }, + [2] = { + .num = ST_MAGN_FS_AVL_12000MG, + .value = 0x02, + .gain = 430, + }, + [3] = { + .num = ST_MAGN_FS_AVL_16000MG, + .value = 0x03, + .gain = 580, + }, + }, + }, + .bdu = { + .addr = 0x24, + .mask = 0x40, + }, + .drdy_irq = { + .stat_drdy = { + .addr = ST_SENSORS_DEFAULT_STAT_ADDR, + .mask = 0x07, + }, + }, + .sim = { + .addr = 0x22, + .value = BIT(2), + }, + .multi_read_bit = true, + .bootime = 2, + }, }; static int st_magn_read_raw(struct iio_dev *indio_dev, diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c index 7b7cd08fcc32..433456920673 100644 --- a/drivers/iio/magnetometer/st_magn_spi.c +++ b/drivers/iio/magnetometer/st_magn_spi.c @@ -37,6 +37,10 @@ static const struct of_device_id st_magn_of_match[] = { .compatible = "st,lis2mdl", .data = LIS2MDL_MAGN_DEV_NAME, }, + { + .compatible = "st,lsm9ds1", + .data = LSM9DS1_MAGN_DEV_NAME, + }, {} }; MODULE_DEVICE_TABLE(of, st_magn_of_match); @@ -79,6 +83,7 @@ static const struct spi_device_id st_magn_id_table[] = { { LIS3MDL_MAGN_DEV_NAME }, { LSM303AGR_MAGN_DEV_NAME }, { LIS2MDL_MAGN_DEV_NAME }, + { LSM9DS1_MAGN_DEV_NAME }, {}, }; MODULE_DEVICE_TABLE(spi, st_magn_id_table);