From patchwork Mon May 17 23:33:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12263349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5A52C433ED for ; Mon, 17 May 2021 23:35:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA032610CC for ; Mon, 17 May 2021 23:35:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239302AbhEQXgu (ORCPT ); Mon, 17 May 2021 19:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235189AbhEQXgt (ORCPT ); Mon, 17 May 2021 19:36:49 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C741C061573 for ; Mon, 17 May 2021 16:35:31 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id v5so9269001ljg.12 for ; Mon, 17 May 2021 16:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GDsfl8BtnMrIaPegpt8K35ViaVv1v2HfOtAAQSHJJnQ=; b=dM5HTpqTzypLbOt2sI0RVqq7FaMCqVr9GfnOtlMgM09omyNxB8EZNVGiOpu64DOChU RUV5IjNhDYXGJ9tZksPZTxhnVtcPi2JEExnp0z7tW2lCcwjCRw2QlxNvB3DaEG1NhMim P+fa2wETZXUdfuJS3zrDfGomrWoAdTUg/ilj3mea/QBVg+JwiMRYuJPS9NFnYy34js1t 3PqeYyJiswyPkBSwiRHlGfrlMOOwYGKwSqxYIRKnbbf8bTLROAXL1qW9kBxO5rmbtHrW Q2ikiRXDAQHkbVbBs4UFxM4vo1Hb6BD9FgzQU1u6XDTuzan0qSqTZoKokJrkuZnOlg5E yetQ== 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:mime-version :content-transfer-encoding; bh=GDsfl8BtnMrIaPegpt8K35ViaVv1v2HfOtAAQSHJJnQ=; b=FHETR7uxAn0kBTxps+MNKtry9pE9ZwGDwk5tU/BZrTqcX726AB5e7/2efHFaWQdfAL JuSsXosVSw9UV5pH2Ngt9hBYHvoVLcdL7OoDlTwJX0MLwL6xN6MW7NZLTFo2Q9CWiyca qfrM2JO+IaQOBMQsu74e7SCbMKceByPjrFMlImwu1xtHTOCBGrOdp557nTiwFrPibiTW 0inxDWjs3umqEU429WobspTecoDe/yJNfqzcrBekCM5pIjUG7+c8TqLNt81RTIYA1XQe Rr9+7hTzfQo/KvTsrmYceU91JzbUCJAvFduIc7Ou3jo/B+qweiLtGKB7oEPPBu9sF22q uBrA== X-Gm-Message-State: AOAM532u/QV0Ev8dgWqqm+ITPENYb512P+mYIDCGw9L8+J2s97xpGL61 TgYekcw6yNvxe1xF5THGs3UkZw== X-Google-Smtp-Source: ABdhPJyaisHV5NEBBUZ9qIUyF1/UMcgWZgMh/aRySgBD+81/16Okkvm3Mwm5WRf4K5x5A1Q1LTrxBQ== X-Received: by 2002:a2e:9dd7:: with SMTP id x23mr1528825ljj.79.1621294529921; Mon, 17 May 2021 16:35:29 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r10sm168425lfe.110.2021.05.17.16.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 16:35:29 -0700 (PDT) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Linus Walleij , Andy Shevchenko , Denis Ciocca , Daniel Drake , Stephan Gerhold Subject: [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro Date: Tue, 18 May 2021 01:33:18 +0200 Message-Id: <20210517233322.383043-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Extend ST_SENSORS_LSM_CHANNELS() to a version that will accept extended attributes named ST_SENSORS_LSM_CHANNELS_EXT() and wrap the former as a specialized version of the former. Cc: Andy Shevchenko Cc: Denis Ciocca Cc: Daniel Drake Signed-off-by: Stephan Gerhold Signed-off-by: Linus Walleij Reviewed-by: Andy Shevchenko --- ChangeLog v1->v2: - New helper patch from Stephan. --- include/linux/iio/common/st_sensors.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h index 33e939977444..704217a5c3ba 100644 --- a/include/linux/iio/common/st_sensors.h +++ b/include/linux/iio/common/st_sensors.h @@ -46,8 +46,8 @@ #define ST_SENSORS_MAX_NAME 17 #define ST_SENSORS_MAX_4WAI 8 -#define ST_SENSORS_LSM_CHANNELS(device_type, mask, index, mod, \ - ch2, s, endian, rbits, sbits, addr) \ +#define ST_SENSORS_LSM_CHANNELS_EXT(device_type, mask, index, mod, \ + ch2, s, endian, rbits, sbits, addr, ext) \ { \ .type = device_type, \ .modified = mod, \ @@ -63,8 +63,14 @@ .storagebits = sbits, \ .endianness = endian, \ }, \ + .ext_info = ext, \ } +#define ST_SENSORS_LSM_CHANNELS(device_type, mask, index, mod, \ + ch2, s, endian, rbits, sbits, addr) \ + ST_SENSORS_LSM_CHANNELS_EXT(device_type, mask, index, mod, \ + ch2, s, endian, rbits, sbits, addr, NULL) + #define ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL() \ IIO_DEV_ATTR_SAMP_FREQ_AVAIL( \ st_sensors_sysfs_sampling_frequency_avail) From patchwork Mon May 17 23:33:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12263351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13A4AC433B4 for ; Mon, 17 May 2021 23:38:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA1F961185 for ; Mon, 17 May 2021 23:38:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237234AbhEQXkF (ORCPT ); Mon, 17 May 2021 19:40:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237188AbhEQXkE (ORCPT ); Mon, 17 May 2021 19:40:04 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 888F9C061573 for ; Mon, 17 May 2021 16:38:47 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id q7so9946406lfr.6 for ; Mon, 17 May 2021 16:38:47 -0700 (PDT) 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=Gr2bd/IlUNejl3K0rcvE9FZjaLIFul6JRBTsT2hWOtg=; b=WZvu2KrJ7ATVXnuLO24fmCfb5k/ELHX1rVa8uVrO49nYQCWowCTHf/MbqAZtE89nT7 SN0svku5E82VrDrC9Zjt8NzPJ4Ib1llwfU4lRchzATsfFLI2CE/OugY6RMsxjeoX4GaO ai6gT6P5iCfwwb8q+jVf0R3MmaI5rhRLgAlJs8TfGeOQDPTZ6m2drd6K9Pq2JDkXfb1N QpjZQMTr9foUfa7mAHlaF+Pe5X5EpfJRh3BD0ccflMGXXSRRl+vZH7dMWSdUV28joy8K 5TFXvmCC+yqWFqgAq7yzMSAPwxLV6iR6+HvM92TGwtg+N47B4q0WDM2eMQ0rqp7ZhO23 6lbw== 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=Gr2bd/IlUNejl3K0rcvE9FZjaLIFul6JRBTsT2hWOtg=; b=EgFa43srHZT212my7LNxcgLlJDL+z168whmggxM4CDZ+0H+CpJaV9spWoWMyJ+v31a RjYKcQDEg7fLgfgBW3NryAwfOaeIPgo/NM8OMmAKek/jW1y3CHVm2SOIiaUTVic0Dpgn 3QBnFZbPPobxV1DR6Fq1rJG76ethnJuJtlx1KQsYC+lHXDGtXlt+tSrFdhB4FV7EZec8 XfGowuZgFj1rFp+zhMVqOwMmYnnRiLd/h8aJ0WIQLjSn8AsNqaefN4yVdJfjIn6xxVE/ VRS6/N4WkyZwxQKqCXoEqRpapiszM+YjsZelalg/QQNqyVKJOlw15OJ8jDIdUxF9Dq73 RxkA== X-Gm-Message-State: AOAM532RrI/KpqJtb30ne1QUJ6Hqh0Igp8FD82JBpWNulALK2/kWoyWR flLr0jR7NXZ+VPU6MavFZjVTrw== X-Google-Smtp-Source: ABdhPJxK4XDohBmTcwUSfDhpmuzVCQnGYORiGq1r3xIktU8LQ63W1vVWN1NdfZ+UpQskljvXuTTJXw== X-Received: by 2002:a19:e002:: with SMTP id x2mr1711767lfg.448.1621294726052; Mon, 17 May 2021 16:38:46 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r10sm168425lfe.110.2021.05.17.16.38.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 16:38:45 -0700 (PDT) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Linus Walleij , Andy Shevchenko , Denis Ciocca , Daniel Drake , Stephan Gerhold Subject: [PATCH 2/5 v2] iio: accel: st_sensors: Support generic mounting matrix Date: Tue, 18 May 2021 01:33:19 +0200 Message-Id: <20210517233322.383043-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517233322.383043-1-linus.walleij@linaro.org> References: <20210517233322.383043-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The ST accelerators support a special type of quirky mounting matrix found in ACPI systems, but not a generic mounting matrix such as from the device tree. Augment the ACPI hack to be a bit more generic and accept a mounting matrix from device properties. This makes it possible to fix orientation on the Ux500 HREF device. Cc: Andy Shevchenko Cc: Denis Ciocca Cc: Daniel Drake Signed-off-by: Stephan Gerhold Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Make the .mount_matrix member of st_sensor_data a full member instead of a pointer so we get rid of a bunch of unneeded allocations that could fail. - Make a drive-by fix to the kerneldoc. - Use the new ST_SENSORS_LSM_CHANNELS_EXT() to define the channels with the extended attribute for mounting matrix. - Demote the error message at the end of apply_acpi_orientation() to dev_dbg() and only print it of ret != 0. --- drivers/iio/accel/st_accel_core.c | 110 +++++++++++++------------- include/linux/iio/common/st_sensors.h | 4 +- 2 files changed, 60 insertions(+), 54 deletions(-) diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index 43c50167d220..8044b8ae7ead 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c @@ -41,51 +41,74 @@ #define ST_ACCEL_FS_AVL_200G 200 #define ST_ACCEL_FS_AVL_400G 400 +static const struct iio_mount_matrix * +st_accel_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct st_sensor_data *adata = iio_priv(indio_dev); + + return &adata->mount_matrix; +} + +static const struct iio_chan_spec_ext_info st_accel_mount_matrix_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_accel_get_mount_matrix), + { }, +}; + static const struct iio_chan_spec st_accel_8bit_channels[] = { - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 8, 8, - ST_ACCEL_DEFAULT_OUT_X_L_ADDR+1), - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + ST_ACCEL_DEFAULT_OUT_X_L_ADDR+1, + st_accel_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 8, 8, - ST_ACCEL_DEFAULT_OUT_Y_L_ADDR+1), - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + ST_ACCEL_DEFAULT_OUT_Y_L_ADDR+1, + st_accel_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 8, 8, - ST_ACCEL_DEFAULT_OUT_Z_L_ADDR+1), + ST_ACCEL_DEFAULT_OUT_Z_L_ADDR+1, + st_accel_mount_matrix_ext_info), IIO_CHAN_SOFT_TIMESTAMP(3) }; static const struct iio_chan_spec st_accel_12bit_channels[] = { - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 12, 16, - ST_ACCEL_DEFAULT_OUT_X_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + ST_ACCEL_DEFAULT_OUT_X_L_ADDR, + st_accel_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 12, 16, - ST_ACCEL_DEFAULT_OUT_Y_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + ST_ACCEL_DEFAULT_OUT_Y_L_ADDR, + st_accel_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 12, 16, - ST_ACCEL_DEFAULT_OUT_Z_L_ADDR), + ST_ACCEL_DEFAULT_OUT_Z_L_ADDR, + st_accel_mount_matrix_ext_info), IIO_CHAN_SOFT_TIMESTAMP(3) }; static const struct iio_chan_spec st_accel_16bit_channels[] = { - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16, - ST_ACCEL_DEFAULT_OUT_X_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + ST_ACCEL_DEFAULT_OUT_X_L_ADDR, + st_accel_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16, - ST_ACCEL_DEFAULT_OUT_Y_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + ST_ACCEL_DEFAULT_OUT_Y_L_ADDR, + st_accel_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16, - ST_ACCEL_DEFAULT_OUT_Z_L_ADDR), + ST_ACCEL_DEFAULT_OUT_Z_L_ADDR, + st_accel_mount_matrix_ext_info), IIO_CHAN_SOFT_TIMESTAMP(3) }; @@ -1070,25 +1093,10 @@ static const struct iio_trigger_ops st_accel_trigger_ops = { #endif #ifdef CONFIG_ACPI -static const struct iio_mount_matrix * -get_mount_matrix(const struct iio_dev *indio_dev, - const struct iio_chan_spec *chan) -{ - struct st_sensor_data *adata = iio_priv(indio_dev); - - return adata->mount_matrix; -} - -static const struct iio_chan_spec_ext_info mount_matrix_ext_info[] = { - IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, get_mount_matrix), - { }, -}; - /* Read ST-specific _ONT orientation data from ACPI and generate an * appropriate mount matrix. */ -static int apply_acpi_orientation(struct iio_dev *indio_dev, - struct iio_chan_spec *channels) +static int apply_acpi_orientation(struct iio_dev *indio_dev) { struct st_sensor_data *adata = iio_priv(indio_dev); struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; @@ -1177,14 +1185,6 @@ static int apply_acpi_orientation(struct iio_dev *indio_dev, } /* Convert our integer matrix to a string-based iio_mount_matrix */ - adata->mount_matrix = devm_kmalloc(&indio_dev->dev, - sizeof(*adata->mount_matrix), - GFP_KERNEL); - if (!adata->mount_matrix) { - ret = -ENOMEM; - goto out; - } - for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { int matrix_val = final_ont[i][j]; @@ -1203,26 +1203,25 @@ static int apply_acpi_orientation(struct iio_dev *indio_dev, default: goto out; } - adata->mount_matrix->rotation[i * 3 + j] = str_value; + adata->mount_matrix.rotation[i * 3 + j] = str_value; } } - /* Expose the mount matrix via ext_info */ - for (i = 0; i < indio_dev->num_channels; i++) - channels[i].ext_info = mount_matrix_ext_info; - ret = 0; dev_info(&indio_dev->dev, "computed mount matrix from ACPI\n"); out: kfree(buffer.pointer); + if (ret) + dev_dbg(&indio_dev->dev, + "failed to apply ACPI orientation data: %d\n", ret); + return ret; } #else /* !CONFIG_ACPI */ -static int apply_acpi_orientation(struct iio_dev *indio_dev, - struct iio_chan_spec *channels) +static int apply_acpi_orientation(struct iio_dev *indio_dev) { - return 0; + return -EINVAL; } #endif @@ -1275,9 +1274,14 @@ int st_accel_common_probe(struct iio_dev *indio_dev) goto st_accel_power_off; } - if (apply_acpi_orientation(indio_dev, channels)) - dev_warn(&indio_dev->dev, - "failed to apply ACPI orientation data: %d\n", err); + /* First try ACPI orientation then try the generic function */ + err = apply_acpi_orientation(indio_dev); + if (err) { + err = iio_read_mount_matrix(adata->dev, "mount-matrix", + &adata->mount_matrix); + if (err) + goto st_accel_power_off; + } indio_dev->channels = channels; adata->current_fullscale = &adata->sensor_settings->fs.fs_avl[0]; diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h index 704217a5c3ba..9ac456973688 100644 --- a/include/linux/iio/common/st_sensors.h +++ b/include/linux/iio/common/st_sensors.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -219,6 +220,7 @@ struct st_sensor_settings { * struct st_sensor_data - ST sensor device status * @dev: Pointer to instance of struct device (I2C or SPI). * @trig: The trigger in use by the core driver. + * @mount_matrix: The mounting matrix of the sensor. * @sensor_settings: Pointer to the specific sensor settings in use. * @current_fullscale: Maximum range of measure by the sensor. * @vdd: Pointer to sensor's Vdd power supply @@ -238,7 +240,7 @@ struct st_sensor_settings { struct st_sensor_data { struct device *dev; struct iio_trigger *trig; - struct iio_mount_matrix *mount_matrix; + struct iio_mount_matrix mount_matrix; struct st_sensor_settings *sensor_settings; struct st_sensor_fullscale_avl *current_fullscale; struct regulator *vdd; From patchwork Mon May 17 23:33:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12263353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 593B1C433ED for ; Mon, 17 May 2021 23:38:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34E1861285 for ; Mon, 17 May 2021 23:38:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238990AbhEQXkG (ORCPT ); Mon, 17 May 2021 19:40:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237188AbhEQXkG (ORCPT ); Mon, 17 May 2021 19:40:06 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71DD8C061573 for ; Mon, 17 May 2021 16:38:49 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id z13so11298857lft.1 for ; Mon, 17 May 2021 16:38:49 -0700 (PDT) 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=P/Y6XbDTCvgW3VbQmCGY1JGa9deJDrj59RfruZ1XQjk=; b=sru8k50MpkalCjWFw9AGoQQoYas/rugjXPU7ig1vluTw52zTAgov5ttFQ2I4a5Uah+ bd/rH1jYhRReDa/XCLNf3rbrnCHDtw1lBFd/3QV7UyQmYb/tbxbyw8XqzTeSTPe0RIKK XRaYtFHHo/IF/cVWy8/InWUygEUk7GzG1pwPpryEO4lJmaVa28EcAOmiXH9in01dLBxF 9JnVlOPFGOn5uA3wascNCzKzWIy2QBNznvTqwV8vEb5zGfNT3pqDuVUqh7XhLcoup8W+ glKiruubgiUItpoaWFHeWFGA33E6Dq8+gwSAQ1jUytUQ46Mg0UyixYHR/FlH8EESGw9l trcQ== 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=P/Y6XbDTCvgW3VbQmCGY1JGa9deJDrj59RfruZ1XQjk=; b=ue4/AYZPoz5/rj7up9nIbvEQPZtuFGo2/kMTtoxxMXntP4zn6bAZlZmtFmrnjYTkyh 6BCFaxk4qMSb27fOS06fwlAEPiZvo3zBPu+aOiT/9GRSW3cjOCW6ND6pHWVLbBKKrHRU anzpkabNS+EWaLdUB6v0awT8I9WSSyuhQo7KipoQe2DfVrrbLtCkgAz7jlb/5jFel4dx pcqMogUUeEgOfYsRAzFFl/Jgw7Ma1/NxfRKedGdMlXsIhQ1zcRY8M4JDh0dQg/ZPH1Fv EXndXXb2fgjLduJ/vA3oxVrAi6AzslDuy6RBd2y8zgrDmnkFS9MVaTKWjWMzr75qWeMh Sv2A== X-Gm-Message-State: AOAM531BAs1dHk1aAxjxNtPAhXISoKrnGoBcZOHt+AULK6fQ+sgIJiKq h51nTfOHg5PccQ1LpJiXthapVlGfP6tEjw== X-Google-Smtp-Source: ABdhPJx2TQ0rxZ4OYrlhhDwJFbW3Ai+caOO8By59k9Stc0lSiqRaj0DdddRhEj6vO3YiY75UU/KPAA== X-Received: by 2002:a05:6512:6c5:: with SMTP id u5mr1456477lff.260.1621294727904; Mon, 17 May 2021 16:38:47 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r10sm168425lfe.110.2021.05.17.16.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 16:38:47 -0700 (PDT) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Linus Walleij , Andy Shevchenko , Denis Ciocca , Daniel Drake , Stephan Gerhold Subject: [PATCH 3/5 v2] iio: accel: st_sensors: Stop copying channels Date: Tue, 18 May 2021 01:33:20 +0200 Message-Id: <20210517233322.383043-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517233322.383043-1-linus.walleij@linaro.org> References: <20210517233322.383043-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The channels were copied only so that the .ext_info member should become assignable. We now have compile-time static assignment so drop this code. Cc: Andy Shevchenko Cc: Denis Ciocca Cc: Daniel Drake Signed-off-by: Stephan Gerhold Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Improvement found by Stephan. --- drivers/iio/accel/st_accel_core.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index 8044b8ae7ead..fa06a3ef84e7 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c @@ -1247,8 +1247,6 @@ int st_accel_common_probe(struct iio_dev *indio_dev) { struct st_sensor_data *adata = iio_priv(indio_dev); struct st_sensors_platform_data *pdata = dev_get_platdata(adata->dev); - struct iio_chan_spec *channels; - size_t channels_size; int err; indio_dev->modes = INDIO_DIRECT_MODE; @@ -1263,17 +1261,9 @@ int st_accel_common_probe(struct iio_dev *indio_dev) goto st_accel_power_off; adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS; + indio_dev->channels = adata->sensor_settings->ch; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; - channels_size = indio_dev->num_channels * sizeof(struct iio_chan_spec); - channels = devm_kmemdup(&indio_dev->dev, - adata->sensor_settings->ch, - channels_size, GFP_KERNEL); - if (!channels) { - err = -ENOMEM; - goto st_accel_power_off; - } - /* First try ACPI orientation then try the generic function */ err = apply_acpi_orientation(indio_dev); if (err) { @@ -1283,7 +1273,6 @@ int st_accel_common_probe(struct iio_dev *indio_dev) goto st_accel_power_off; } - indio_dev->channels = channels; adata->current_fullscale = &adata->sensor_settings->fs.fs_avl[0]; adata->odr = adata->sensor_settings->odr.odr_avl[0].hz; From patchwork Mon May 17 23:33:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12263355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UPPERCASE_50_75, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71315C433B4 for ; Mon, 17 May 2021 23:38:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54BEA611BE for ; Mon, 17 May 2021 23:38:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238991AbhEQXkI (ORCPT ); Mon, 17 May 2021 19:40:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237188AbhEQXkH (ORCPT ); Mon, 17 May 2021 19:40:07 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E89DC061573 for ; Mon, 17 May 2021 16:38:50 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id z13so11298908lft.1 for ; Mon, 17 May 2021 16:38:50 -0700 (PDT) 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=ns0IeTXIw3KSjl4Ix5g2K8C3nNLeIG8gC2PZ6mGVwaE=; b=h76lCMFB0fwGQEiFoBjnk+nh8kzMCpD20iyPbp0TOKo7YQZzJp3IXibjPqHAP+GznE Jp6QYUmAxrDSh7faWZlECaQjJG7Z858mlVIrEDgxq3ahJE9SAA0nzFuJibyhvLSoAxbw PQsy+Mi1/1rIdo6/32tsgvRAn1sNe4PAIFx+RejvXneTy0fDaO+VjF17HSlPmz4KU2K7 PHbBbLEpvVEMAS0BvZklhuvBysrD0KewzONiZMtlrhuSJj7SZDoec6nFgM9ZJ0C72OIG GZRIkzY5uUxu2C6jXu2ryDC4MGKAWl605eonKKcLuI++lyZ7JVC1cSyIOCfG/Zh3xkpL fhIQ== 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=ns0IeTXIw3KSjl4Ix5g2K8C3nNLeIG8gC2PZ6mGVwaE=; b=ZPxP/SvTXqrkf8VNWioIPyFStyY4cHccD9lBdfxUEQiW85t28jOGifa/bHZcrh5tPU /Dk2ZNR4N+42AdsRR8STXCssrWDXvknev8Hg/0CY0xVhDI/Tl5YB7sela3khGnbEpGNk zQ5VzYTXxtd2o2B5JzDs6bxGSEfMSXsJCLIi/WDgx2m/oQD7HxY7O42V/8wE8T+HVoul v1X6JGWYihcHCBafXVzHisHVZ3+coszMUycNDa/tt3BwoQmSSx6I0VuhoUcu4WLWXSkI Sk+IjHkJHUt20EtQTRlxBV8XX2fF2Jx6vUNbPr2BrJx6iY8Ufs2+ppIdZ5D1GQkteRVb sQhQ== X-Gm-Message-State: AOAM532olKR1V4A1EbZyPRCjDcR5d+2m+lTaEAFbYwZsD73zdC9PYHq8 WavDKi2p5IE56uGV/LzRpVrI/w== X-Google-Smtp-Source: ABdhPJxPdMYFgqSS9vptOlUmpiVPp8/iWXjiIN5pLUQEXl+KzNTBvpxU9SAEYr0TVP2Fapnp6e1aSg== X-Received: by 2002:ac2:546b:: with SMTP id e11mr1646748lfn.395.1621294729132; Mon, 17 May 2021 16:38:49 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r10sm168425lfe.110.2021.05.17.16.38.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 16:38:48 -0700 (PDT) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Linus Walleij , Andy Shevchenko , Denis Ciocca , Daniel Drake , Stephan Gerhold Subject: [PATCH 4/5 v2] iio: magnetometer: st_magn: Support mount matrix Date: Tue, 18 May 2021 01:33:21 +0200 Message-Id: <20210517233322.383043-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517233322.383043-1-linus.walleij@linaro.org> References: <20210517233322.383043-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support to read and present the mounting matrix on ST magnetometers. Cc: Andy Shevchenko Cc: Denis Ciocca Cc: Daniel Drake Cc: Stephan Gerhold Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - New patch because why not. --- drivers/iio/magnetometer/st_magn_core.c | 64 ++++++++++++++++++------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c index 71faebd07feb..fa587975cb85 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -53,51 +53,74 @@ #define ST_MAGN_3_OUT_Y_L_ADDR 0x6a #define ST_MAGN_3_OUT_Z_L_ADDR 0x6c +static const struct iio_mount_matrix * +st_magn_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct st_sensor_data *mdata = iio_priv(indio_dev); + + return &mdata->mount_matrix; +} + +static const struct iio_chan_spec_ext_info st_magn_mount_matrix_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_magn_get_mount_matrix), + { }, +}; + static const struct iio_chan_spec st_magn_16bit_channels[] = { - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_BE, 16, 16, - ST_MAGN_DEFAULT_OUT_X_H_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + ST_MAGN_DEFAULT_OUT_X_H_ADDR, + st_magn_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_BE, 16, 16, - ST_MAGN_DEFAULT_OUT_Y_H_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + ST_MAGN_DEFAULT_OUT_Y_H_ADDR, + st_magn_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_BE, 16, 16, - ST_MAGN_DEFAULT_OUT_Z_H_ADDR), + ST_MAGN_DEFAULT_OUT_Z_H_ADDR, + st_magn_mount_matrix_ext_info), IIO_CHAN_SOFT_TIMESTAMP(3) }; static const struct iio_chan_spec st_magn_2_16bit_channels[] = { - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16, - ST_MAGN_2_OUT_X_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + ST_MAGN_2_OUT_X_L_ADDR, + st_magn_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16, - ST_MAGN_2_OUT_Y_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + ST_MAGN_2_OUT_Y_L_ADDR, + st_magn_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16, - ST_MAGN_2_OUT_Z_L_ADDR), + ST_MAGN_2_OUT_Z_L_ADDR, + st_magn_mount_matrix_ext_info), IIO_CHAN_SOFT_TIMESTAMP(3) }; static const struct iio_chan_spec st_magn_3_16bit_channels[] = { - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16, - ST_MAGN_3_OUT_X_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + ST_MAGN_3_OUT_X_L_ADDR, + st_magn_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16, - ST_MAGN_3_OUT_Y_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + ST_MAGN_3_OUT_Y_L_ADDR, + st_magn_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16, - ST_MAGN_3_OUT_Z_L_ADDR), + ST_MAGN_3_OUT_Z_L_ADDR, + st_magn_mount_matrix_ext_info), IIO_CHAN_SOFT_TIMESTAMP(3) }; @@ -507,6 +530,11 @@ int st_magn_common_probe(struct iio_dev *indio_dev) indio_dev->channels = mdata->sensor_settings->ch; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; + err = iio_read_mount_matrix(mdata->dev, "mount-matrix", + &mdata->mount_matrix); + if (err) + goto st_magn_power_off; + mdata->current_fullscale = &mdata->sensor_settings->fs.fs_avl[0]; mdata->odr = mdata->sensor_settings->odr.odr_avl[0].hz; From patchwork Mon May 17 23:33:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12263357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA73BC433ED for ; Mon, 17 May 2021 23:38:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BDBF61185 for ; Mon, 17 May 2021 23:38:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239185AbhEQXkK (ORCPT ); Mon, 17 May 2021 19:40:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237188AbhEQXkJ (ORCPT ); Mon, 17 May 2021 19:40:09 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F22F7C061573 for ; Mon, 17 May 2021 16:38:51 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id a2so11249068lfc.9 for ; Mon, 17 May 2021 16:38:51 -0700 (PDT) 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=dfYSzKVBAdi2ps5q+TR9Wlw4r6ze7XJcF8+xEewP07s=; b=x+s94XDTjXLCyhWGu7XxGYjMKxGZs1zwFJ609GKwyLz+LFqdRmbrJ81Wvrr8M/zzNI m9YOKSbhu3ZUyYzbUG3s4lu1N0jWx86d8KPssAbS2lcwI1BFw3neisNf15IpkSOpavz0 fM5ghyn9K5X0rDowAJUe6/1ZT7Sg+Wru2/VQC/qOjoP29YRha8v9NHL87X+fyMc0qet9 4da1PXijou4cV6bFxlcirdgcpeplLoG/XfRyHtavKsM3w3K+IROTtLD8TFc2VZqxjhe/ ToQXfgbEzsoT4nb22viJjqlmV8FhkzfgMzXgWhXbgNHpFiCyT/7iYqGWpORZOQzBEQVU obZA== 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=dfYSzKVBAdi2ps5q+TR9Wlw4r6ze7XJcF8+xEewP07s=; b=jH7/Rp8TdujXBCciLBrjDGMd/y6m1Fu45keOY8j8jBqkLgZoJ1Ud/eD43NqWY+PvPZ xVqNSdn4UR763n8zqSbI4v3JzKRI9NWSo4IPQv0yD9QN/8lP0Jgm90C7GCBQbrv+YqqL x4EvTtLarR5ehSIAkhOd3BgDU6qC0ezgwIXmPVRrvKN0+2J+xxleg7TqZIEZoC6oP//F twgVbmm6UkKzww/HseCRmqaJRvFtFWor2PAs0BWw9P2un+FfuNwaPmhv2iDaAkXgVBwD V89juQ8d2f5stbMNRQ9jYtWBVDH0g4bUOfW7rBhUOo8NvEbnewBOVt2hd+SW9euS4NLu rSEg== X-Gm-Message-State: AOAM5323JIL7qhTt16LXHFT/lt/HhaiN2peDydIrEgDqy11m2deRH+7Z AfOgiBIZ0mJD6tt38g6RGwn1vQ== X-Google-Smtp-Source: ABdhPJzAehTHbNZ8IefWSgeoCaGQtZLZiqaVK5vSr9xwB/G4Fc1ydVht41SLOXWQQD+uu5hdk3Nw8A== X-Received: by 2002:ac2:5dd5:: with SMTP id x21mr1764412lfq.503.1621294730542; Mon, 17 May 2021 16:38:50 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r10sm168425lfe.110.2021.05.17.16.38.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 16:38:50 -0700 (PDT) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Linus Walleij , Andy Shevchenko , Denis Ciocca , Daniel Drake , Stephan Gerhold Subject: [PATCH 5/5 v2] iio: gyro: st_gyro: Support mount matrix Date: Tue, 18 May 2021 01:33:22 +0200 Message-Id: <20210517233322.383043-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517233322.383043-1-linus.walleij@linaro.org> References: <20210517233322.383043-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support to read and present the mounting matrix on ST gyroscopes. Cc: Andy Shevchenko Cc: Denis Ciocca Cc: Daniel Drake Cc: Stephan Gerhold Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - New patch because why not. --- drivers/iio/gyro/st_gyro_core.c | 34 +++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c index c8aa051995d3..bf06a531bed3 100644 --- a/drivers/iio/gyro/st_gyro_core.c +++ b/drivers/iio/gyro/st_gyro_core.c @@ -37,19 +37,36 @@ #define ST_GYRO_FS_AVL_500DPS 500 #define ST_GYRO_FS_AVL_2000DPS 2000 +static const struct iio_mount_matrix * +st_gyro_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct st_sensor_data *gdata = iio_priv(indio_dev); + + return &gdata->mount_matrix; +} + +static const struct iio_chan_spec_ext_info st_gyro_mount_matrix_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_gyro_get_mount_matrix), + { }, +}; + static const struct iio_chan_spec st_gyro_16bit_channels[] = { - ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, + ST_SENSORS_LSM_CHANNELS_EXT(IIO_ANGL_VEL, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16, - ST_GYRO_DEFAULT_OUT_X_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, + ST_GYRO_DEFAULT_OUT_X_L_ADDR, + st_gyro_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_ANGL_VEL, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16, - ST_GYRO_DEFAULT_OUT_Y_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, + ST_GYRO_DEFAULT_OUT_Y_L_ADDR, + st_gyro_mount_matrix_ext_info), + ST_SENSORS_LSM_CHANNELS_EXT(IIO_ANGL_VEL, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16, - ST_GYRO_DEFAULT_OUT_Z_L_ADDR), + ST_GYRO_DEFAULT_OUT_Z_L_ADDR, + st_gyro_mount_matrix_ext_info), IIO_CHAN_SOFT_TIMESTAMP(3) }; @@ -478,6 +495,11 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) indio_dev->channels = gdata->sensor_settings->ch; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; + err = iio_read_mount_matrix(gdata->dev, "mount-matrix", + &gdata->mount_matrix); + if (err) + goto st_gyro_power_off; + gdata->current_fullscale = &gdata->sensor_settings->fs.fs_avl[0]; gdata->odr = gdata->sensor_settings->odr.odr_avl[0].hz;