From patchwork Thu Jul 18 22:53:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11049603 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 1A71314DB for ; Thu, 18 Jul 2019 22:54:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A81D28884 for ; Thu, 18 Jul 2019 22:54:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F372E288AA; Thu, 18 Jul 2019 22:54:30 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 900CE28884 for ; Thu, 18 Jul 2019 22:54:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728083AbfGRWya (ORCPT ); Thu, 18 Jul 2019 18:54:30 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:20848 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727972AbfGRWya (ORCPT ); Thu, 18 Jul 2019 18:54:30 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6IMpZql027763; Fri, 19 Jul 2019 00:54:25 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=K/51DZ5UXNtNAtxxfOlgGd59QZXnzug5FDLoGzO0n1I=; b=tuxtj2Nk0a7NZelvtDinhkhTtzndbWjqLi4615ktOiKUzJ5NwQ5mg2+snvLo/hakA0ou SXuRqFCmy+IjAKuKqRVQTC3XuTVzodBJQCkjT9XLEW8FUgzD37VInzWZjIHUcVPnTQRB 0Wxz1lR8Q49dbG60URtPx84BhL3Mn5wDKf7zOHDJ5TY09tGcGKYQtW/7RecoWDe2LTQI gq/2mWcjUZRq6jOgliRn2u7r9Nw6zJHdIBpi35Bc7xrFzy/BZ7FQmuo9PHLHoWZwTiYR rdZ74WKO+PyI3VW9N6qeOhY0C3jsvtSANI/kW7j3oSPAh4tXYmOypZKrvhJuN63fC1RU fQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2tq4s24j55-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 19 Jul 2019 00:54:25 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7C29F31; Thu, 18 Jul 2019 22:54:24 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6655E10A4; Thu, 18 Jul 2019 22:54:24 +0000 (GMT) Received: from localhost (10.75.127.47) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 19 Jul 2019 00:54:23 +0200 From: Denis Ciocca To: , , Subject: [PATCH v2 01/11] iio:common:st_sensors: add st_sensors_get_settings_index() helper function Date: Thu, 18 Jul 2019 15:53:43 -0700 Message-ID: <20190718225353.2078-2-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718225353.2078-1-denis.ciocca@st.com> References: <20190718225353.2078-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG4NODE2.st.com (10.75.127.11) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-18_12:,, signatures=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 Extract from st_sensors_check_device_support() function the code that is used to get the specific settings for a device. This will be used as generic extractor by each ST driver. Signed-off-by: Denis Ciocca --- Changes in v2: return immediately in st_sensors_settings_index after device name is found remove err initialization inside st_sensors_check_device_support .../iio/common/st_sensors/st_sensors_core.c | 49 +++++++++++++------ include/linux/iio/common/st_sensors.h | 4 ++ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index 8b22dc241482..3610ca9eaa87 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -633,28 +633,47 @@ static int st_sensors_init_interface_mode(struct iio_dev *indio_dev, return 0; } +/* + * st_sensors_get_settings_index() - get index of the sensor settings for a + * specific device from list of settings + * @name: device name buffer reference. + * @list: sensor settings list. + * @list_length: length of sensor settings list. + * + * Return: non negative number on success (valid index), + * negative error code otherwise. + */ +int st_sensors_get_settings_index(const char *name, + const struct st_sensor_settings *list, + const int list_length) +{ + int i, n; + + for (i = 0; i < list_length; i++) { + for (n = 0; n < ST_SENSORS_MAX_4WAI; n++) { + if (strcmp(name, list[i].sensors_supported[n]) == 0) + return i; + } + } + + return -ENODEV; +} +EXPORT_SYMBOL(st_sensors_get_settings_index); + int st_sensors_check_device_support(struct iio_dev *indio_dev, int num_sensors_list, const struct st_sensor_settings *sensor_settings) { - int i, n, err = 0; - u8 wai; struct st_sensor_data *sdata = iio_priv(indio_dev); + int i, err; + u8 wai; - for (i = 0; i < num_sensors_list; i++) { - for (n = 0; n < ST_SENSORS_MAX_4WAI; n++) { - if (strcmp(indio_dev->name, - sensor_settings[i].sensors_supported[n]) == 0) { - break; - } - } - if (n < ST_SENSORS_MAX_4WAI) - break; - } - if (i == num_sensors_list) { + i = st_sensors_get_settings_index(indio_dev->name, + sensor_settings, num_sensors_list); + if (i < 0) { dev_err(&indio_dev->dev, "device name %s not recognized.\n", - indio_dev->name); - return -ENODEV; + indio_dev->name); + return i; } err = st_sensors_init_interface_mode(indio_dev, &sensor_settings[i]); diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h index 2948ac99e2da..17fbf3e9b013 100644 --- a/include/linux/iio/common/st_sensors.h +++ b/include/linux/iio/common/st_sensors.h @@ -334,6 +334,10 @@ int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev, int scale); int st_sensors_read_info_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *ch, int *val); +int st_sensors_get_settings_index(const char *name, + const struct st_sensor_settings *list, + const int list_length); + int st_sensors_check_device_support(struct iio_dev *indio_dev, int num_sensors_list, const struct st_sensor_settings *sensor_settings); From patchwork Thu Jul 18 22:53:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11049605 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 8D67314F6 for ; Thu, 18 Jul 2019 22:54:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CC5228884 for ; Thu, 18 Jul 2019 22:54:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FF62288AA; Thu, 18 Jul 2019 22:54:33 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 15CF628884 for ; Thu, 18 Jul 2019 22:54:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728135AbfGRWyc (ORCPT ); Thu, 18 Jul 2019 18:54:32 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:20832 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727972AbfGRWyc (ORCPT ); Thu, 18 Jul 2019 18:54:32 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6IMqMZw028227; Fri, 19 Jul 2019 00:54:27 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=6Nz7EPP+a0kHR6d7/m52e/KJ0fQBrUsVhslfauSBf/0=; b=ZeoGDNcVJh1hPg+/rC8tC69pU0wApVwLyyu1JIymTJggRuxARyuZUuIMdBTsVu1YLc/u znBvAIIhR0DhND1tQr/gwNGdXTeo/yZ+Kf/j24pviYj2Im8gf6rOo9FkAhjoAHKOflCL 1gENZBXpB2Qqs/5RQHJbpFwT3w3E2oX38hcrYNbynrt50s1J99B1v7YhePsky8pZ7j3c uwZ4Pd3JwqfZvPm/TAqGwGl9GgoU3jKl70AZeLmJBFcuyfsF/JsML1s55uxlRC4xUoU2 Zk7HnQ2fBIm9fH89RHEFjIaBo7koFBL97k0SlbJmzGQySzAs+D/PL+oYAar0eSHXAmie Lw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2tq4s24j5c-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 19 Jul 2019 00:54:27 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2A61231; Thu, 18 Jul 2019 22:54:27 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 14BE210A4; Thu, 18 Jul 2019 22:54:27 +0000 (GMT) Received: from localhost (10.75.127.50) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 19 Jul 2019 00:54:26 +0200 From: Denis Ciocca To: , , Subject: [PATCH v2 02/11] iio:accel: introduce st_accel_get_settings() function Date: Thu, 18 Jul 2019 15:53:44 -0700 Message-ID: <20190718225353.2078-3-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718225353.2078-1-denis.ciocca@st.com> References: <20190718225353.2078-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG3NODE2.st.com (10.75.127.8) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-18_12:,, signatures=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 The function is introduced to retrieve accel device settings. It will be used by probe in order to configure regmap. Signed-off-by: Denis Ciocca --- Changes in v2: not there in v1. This meant to replace "iio:accel:introduce st_accel_multiread_bit() function" drivers/iio/accel/st_accel.h | 1 + drivers/iio/accel/st_accel_core.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h index 979ab9679b99..af09943f38c9 100644 --- a/drivers/iio/accel/st_accel.h +++ b/drivers/iio/accel/st_accel.h @@ -68,6 +68,7 @@ static const struct st_sensors_platform_data default_accel_pdata = { .drdy_int_pin = 1, }; +const struct st_sensor_settings *st_accel_get_settings(const char *name); int st_accel_common_probe(struct iio_dev *indio_dev); void st_accel_common_remove(struct iio_dev *indio_dev); diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index e02b79931979..6fc490ffef7e 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c @@ -1147,6 +1147,24 @@ static int apply_acpi_orientation(struct iio_dev *indio_dev, #endif } +/* + * st_accel_get_settings() - get sensor settings from device name + * @name: device name buffer reference. + * + * Return: valid reference on success, NULL otherwise. + */ +const struct st_sensor_settings *st_accel_get_settings(const char *name) +{ + int index = st_sensors_get_settings_index(name, + st_accel_sensors_settings, + ARRAY_SIZE(st_accel_sensors_settings)); + if (index < 0) + return NULL; + + return &st_accel_sensors_settings[index]; +} +EXPORT_SYMBOL(st_accel_get_settings); + int st_accel_common_probe(struct iio_dev *indio_dev) { struct st_sensor_data *adata = iio_priv(indio_dev); From patchwork Thu Jul 18 22:53:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11049607 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 7038814F6 for ; Thu, 18 Jul 2019 22:54:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60E6A28884 for ; Thu, 18 Jul 2019 22:54:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52AAD288AA; Thu, 18 Jul 2019 22:54:36 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 F097828884 for ; Thu, 18 Jul 2019 22:54:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728140AbfGRWyf (ORCPT ); Thu, 18 Jul 2019 18:54:35 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:33829 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727972AbfGRWyf (ORCPT ); Thu, 18 Jul 2019 18:54:35 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6IMpdDN000798; Fri, 19 Jul 2019 00:54:30 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=kCBpfdygLsVqShagbH65jZjfUCI4W94hVsFdCWU0mzE=; b=Ao1ABXnUOnbvH3S7axwU0E52m51FtxBqHJNoxPHDgP1mMmK44GW9L34Lmh3g//ovhq7q 6oNhbCzztu6V4h9Crmwk3938nHC2LjCvOW4o+40KH3JWRdNDWIowoZHsp8kuYqRPK7+b I+/L4iHVjxoF5CpSwWAeWyV97c0haxD8mrMXrhcOnBicTZvq80eMg/1zeh1NCsOZJDKi iVxg1o+0pN2bOkk0pP8dfxA5is0zu7fQriHS8akvfAREymIxUqg3QLNd4XQ9R/l2pxE5 p00K+Avi4tv4gkKR+SDL/a6tqE+yYqeeTkFAn3xEjuZJI+8ZS9yC8orNnQ1Ta/Fxv2mx 9g== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2tsdepr8wj-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 19 Jul 2019 00:54:30 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D24C031; Thu, 18 Jul 2019 22:54:29 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id BED1810A4; Thu, 18 Jul 2019 22:54:29 +0000 (GMT) Received: from localhost (10.75.127.47) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 19 Jul 2019 00:54:29 +0200 From: Denis Ciocca To: , , Subject: [PATCH v2 03/11] iio:gyro: introduce st_gyro_get_settings() function Date: Thu, 18 Jul 2019 15:53:45 -0700 Message-ID: <20190718225353.2078-4-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718225353.2078-1-denis.ciocca@st.com> References: <20190718225353.2078-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG3NODE3.st.com (10.75.127.9) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-18_12:,, signatures=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 The function is introduced to retrieve gyro device settings. It will be used by probe in order to configure regmap. Signed-off-by: Denis Ciocca --- Changes in v2: not there in v1. This meant to replace "iio:gyro:introduce st_gyro_multiread_bit() function" drivers/iio/gyro/st_gyro.h | 1 + drivers/iio/gyro/st_gyro_core.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/iio/gyro/st_gyro.h b/drivers/iio/gyro/st_gyro.h index 460d190be4a4..592f6b34e987 100644 --- a/drivers/iio/gyro/st_gyro.h +++ b/drivers/iio/gyro/st_gyro.h @@ -32,6 +32,7 @@ static const struct st_sensors_platform_data gyro_pdata = { .drdy_int_pin = 2, }; +const struct st_sensor_settings *st_gyro_get_settings(const char *name); int st_gyro_common_probe(struct iio_dev *indio_dev); void st_gyro_common_remove(struct iio_dev *indio_dev); diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c index e995dc77e30e..5cc63d41d855 100644 --- a/drivers/iio/gyro/st_gyro_core.c +++ b/drivers/iio/gyro/st_gyro_core.c @@ -368,6 +368,24 @@ static const struct iio_trigger_ops st_gyro_trigger_ops = { #define ST_GYRO_TRIGGER_OPS NULL #endif +/* + * st_gyro_get_settings() - get sensor settings from device name + * @name: device name buffer reference. + * + * Return: valid reference on success, NULL otherwise. + */ +const struct st_sensor_settings *st_gyro_get_settings(const char *name) +{ + int index = st_sensors_get_settings_index(name, + st_gyro_sensors_settings, + ARRAY_SIZE(st_gyro_sensors_settings)); + if (index < 0) + return NULL; + + return &st_gyro_sensors_settings[index]; +} +EXPORT_SYMBOL(st_gyro_get_settings); + int st_gyro_common_probe(struct iio_dev *indio_dev) { struct st_sensor_data *gdata = iio_priv(indio_dev); From patchwork Thu Jul 18 22:53:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11049609 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 B8EDB14DB for ; Thu, 18 Jul 2019 22:54:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A95E228884 for ; Thu, 18 Jul 2019 22:54:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E042288AA; Thu, 18 Jul 2019 22:54:37 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 470D928884 for ; Thu, 18 Jul 2019 22:54:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727972AbfGRWyg (ORCPT ); Thu, 18 Jul 2019 18:54:36 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:5378 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728139AbfGRWyg (ORCPT ); Thu, 18 Jul 2019 18:54:36 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6IMpxnD028505; Fri, 19 Jul 2019 00:54:32 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=OpeuH215fjiXx/oZtF+bFjaM3RDujqMQIoOnm1MpsK0=; b=GpEhVrDosMYG0MhCt2uLu2c9GbL1dT8SGb3gpFwNYOOz0C/9zeC3AJcZhv24kUbOd+ha Anvxq4dbB+yrkU7ndStTYvPu3TS480iXo7rJvTA5qSnRuvNAr2Xi6jf0e6Mtv7Jc0DIO pEszXPMrjyUPDojnM/Q0bni5U1HKzZ2dO0bNhACH0l2D5uxxUQ5IRtHdReblnsboJQTY nmgzoUwIpQDQLk9MdiR/eH5lxen/oPbC/04vvJbC9RS5H7M288vHT4fAXVg8Y0PZji2e eaL9HAU96KHqV769RtgHCOtoIComAOHIo5Sw17Eg9fw0cSrYXgBgWAzX5Puo8W1lUJwL 6A== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2tq4e9da8v-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 19 Jul 2019 00:54:32 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 628CA31; Thu, 18 Jul 2019 22:54:32 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 50F9510A4; Thu, 18 Jul 2019 22:54:32 +0000 (GMT) Received: from localhost (10.75.127.47) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 19 Jul 2019 00:54:31 +0200 From: Denis Ciocca To: , , Subject: [PATCH v2 04/11] iio:magn: introduce st_magn_get_settings() function Date: Thu, 18 Jul 2019 15:53:46 -0700 Message-ID: <20190718225353.2078-5-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718225353.2078-1-denis.ciocca@st.com> References: <20190718225353.2078-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG7NODE3.st.com (10.75.127.21) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-18_12:,, signatures=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 The function is introduced to retrieve magn device settings. It will be used by probe in order to configure regmap. Signed-off-by: Denis Ciocca --- Changes in v2: not there in v1. This meant to replace "iio:magn:introduce st_magn_multiread_bit() function" drivers/iio/magnetometer/st_magn.h | 1 + drivers/iio/magnetometer/st_magn_core.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h index d69ef9b2a731..204b285725c8 100644 --- a/drivers/iio/magnetometer/st_magn.h +++ b/drivers/iio/magnetometer/st_magn.h @@ -22,6 +22,7 @@ #define LIS2MDL_MAGN_DEV_NAME "lis2mdl" #define LSM9DS1_MAGN_DEV_NAME "lsm9ds1_magn" +const struct st_sensor_settings *st_magn_get_settings(const char *name); 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 2f7a1dbcdeb3..43a49a52c81a 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -470,6 +470,24 @@ static const struct iio_trigger_ops st_magn_trigger_ops = { #define ST_MAGN_TRIGGER_OPS NULL #endif +/* + * st_magn_get_settings() - get sensor settings from device name + * @name: device name buffer reference. + * + * Return: valid reference on success, NULL otherwise. + */ +const struct st_sensor_settings *st_magn_get_settings(const char *name) +{ + int index = st_sensors_get_settings_index(name, + st_magn_sensors_settings, + ARRAY_SIZE(st_magn_sensors_settings)); + if (index < 0) + return NULL; + + return &st_magn_sensors_settings[index]; +} +EXPORT_SYMBOL(st_magn_get_settings); + int st_magn_common_probe(struct iio_dev *indio_dev) { struct st_sensor_data *mdata = iio_priv(indio_dev); From patchwork Thu Jul 18 22:53:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11049611 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 D8D1414F6 for ; Thu, 18 Jul 2019 22:54:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8F0F28884 for ; Thu, 18 Jul 2019 22:54:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD4D5288AA; Thu, 18 Jul 2019 22:54:41 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 66B6228884 for ; Thu, 18 Jul 2019 22:54:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728152AbfGRWyl (ORCPT ); Thu, 18 Jul 2019 18:54:41 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:19162 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728139AbfGRWyk (ORCPT ); Thu, 18 Jul 2019 18:54:40 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6IMpdDO000798; Fri, 19 Jul 2019 00:54:35 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=7wb+gtWVn319P4TbpaHV41P1pin95o2BXMGl3c7pnek=; b=PSBc1cxno/OEjqz37od9H8EGprCI2jx9gBX/wj6Dp4X/9HzIZrIh4gqkOc66Jn2znYyg c0DipfDhVZhomYCQch6zoKsqk2VA1rF+dgNAVPxs/YxrZLRT3aNF4Ps7BE8yPwySUM7Y yi3rRfOkHOis1mu92wG47ERc6U7sqJ6RFP8GIe25DlztW3Bf0CPNHGN57TfX7/X7PGQY a/lPv8em6x6FryT2NEaakQpAK9aa33IMgQzQ04BySyN60HYngOP5NffjcZ7ZmDXATToW 5N+DpNB0vcEkRA+RC56XRE+Rsgei3IJkQNveXrW15uQs/Zl962yoYuHxlDXv5Jk71/mK vA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2tsdepr8wx-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 19 Jul 2019 00:54:35 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1166731; Thu, 18 Jul 2019 22:54:35 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id F3AD910A4; Thu, 18 Jul 2019 22:54:34 +0000 (GMT) Received: from localhost (10.75.127.49) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 19 Jul 2019 00:54:34 +0200 From: Denis Ciocca To: , , Subject: [PATCH v2 05/11] iio:pressure: introduce st_press_get_settings() function Date: Thu, 18 Jul 2019 15:53:47 -0700 Message-ID: <20190718225353.2078-6-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718225353.2078-1-denis.ciocca@st.com> References: <20190718225353.2078-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-18_12:,, signatures=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 The function is introduced to retrieve press device settings. It will be used by probe in order to configure regmap. Signed-off-by: Denis Ciocca --- Changes in v2: not there in v1. This meant to replace "iio:pressure:introduce st_press_multiread_bit() function" drivers/iio/pressure/st_pressure.h | 1 + drivers/iio/pressure/st_pressure_core.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/iio/pressure/st_pressure.h b/drivers/iio/pressure/st_pressure.h index 6a720cfb5686..c2e47a6c3118 100644 --- a/drivers/iio/pressure/st_pressure.h +++ b/drivers/iio/pressure/st_pressure.h @@ -41,6 +41,7 @@ static const struct st_sensors_platform_data default_press_pdata = { .drdy_int_pin = 1, }; +const struct st_sensor_settings *st_press_get_settings(const char *name); int st_press_common_probe(struct iio_dev *indio_dev); void st_press_common_remove(struct iio_dev *indio_dev); diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c index b960e76f7dfd..35d80ff27464 100644 --- a/drivers/iio/pressure/st_pressure_core.c +++ b/drivers/iio/pressure/st_pressure_core.c @@ -664,6 +664,24 @@ static const struct iio_trigger_ops st_press_trigger_ops = { #define ST_PRESS_TRIGGER_OPS NULL #endif +/* + * st_press_get_settings() - get sensor settings from device name + * @name: device name buffer reference. + * + * Return: valid reference on success, NULL otherwise. + */ +const struct st_sensor_settings *st_press_get_settings(const char *name) +{ + int index = st_sensors_get_settings_index(name, + st_press_sensors_settings, + ARRAY_SIZE(st_press_sensors_settings)); + if (index < 0) + return NULL; + + return &st_press_sensors_settings[index]; +} +EXPORT_SYMBOL(st_press_get_settings); + int st_press_common_probe(struct iio_dev *indio_dev) { struct st_sensor_data *press_data = iio_priv(indio_dev); From patchwork Thu Jul 18 22:53:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11049613 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 C130314F6 for ; Thu, 18 Jul 2019 22:54:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B183828884 for ; Thu, 18 Jul 2019 22:54:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5CE7288AA; Thu, 18 Jul 2019 22:54:44 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 47C4828884 for ; Thu, 18 Jul 2019 22:54:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391318AbfGRWyo (ORCPT ); Thu, 18 Jul 2019 18:54:44 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:19122 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728157AbfGRWyn (ORCPT ); Thu, 18 Jul 2019 18:54:43 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6IMpdDP000798; Fri, 19 Jul 2019 00:54:38 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=TAKhK57YEVfQaySPa7Z6bNxY/RPPIVyCrG3PGbQ2mxM=; b=EsvcLE4rWhmw96bxPo8B+7lZBfYO0zfn++hWnACNB5Mbh9CuuQuRdSnc4FpeN112mlfL /9f6oOZNmuZNzgX/h2at5JUPS6DKlHca6lyIlG7FJ4Irsn9+b3+486UrAu9raiA2Yfne kWqGr5RjWUIhsrWYq5xjbCVC8K+/I72Id0W7nOPKPAFQ9RYm+WjJa5m3XAIY7tpt35+d T/ag93ut6aghgUpkaDjbGYmhadChgeZ8XP1FFQKzA49h472lNpTl6fZA2zrosiJ0EBZ1 VutoRHKkgAMuuHfXIX7ymKidO2ZPWqN4m3LlZWGUB0NPazTS9IL4CrGdv0rr7+sWSEwN Jw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2tsdepr8x1-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 19 Jul 2019 00:54:38 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D2D2C31; Thu, 18 Jul 2019 22:54:37 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id BC7D210A4; Thu, 18 Jul 2019 22:54:37 +0000 (GMT) Received: from localhost (10.75.127.48) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 19 Jul 2019 00:54:36 +0200 From: Denis Ciocca To: , , Subject: [PATCH v2 06/11] iio:accel: device settings are set immediately during probe Date: Thu, 18 Jul 2019 15:53:48 -0700 Message-ID: <20190718225353.2078-7-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718225353.2078-1-denis.ciocca@st.com> References: <20190718225353.2078-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-18_12:,, signatures=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 This patch set accel settings right after probe start. This is done in preparation of regmap that needs different configuration based on multiread bit value. Signed-off-by: Denis Ciocca --- Changes in v2: not there in v1. drivers/iio/accel/st_accel_i2c.c | 19 ++++++++++++++----- drivers/iio/accel/st_accel_spi.c | 16 +++++++++++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c index c3c8f2e73c2a..a92cf776031e 100644 --- a/drivers/iio/accel/st_accel_i2c.c +++ b/drivers/iio/accel/st_accel_i2c.c @@ -150,20 +150,29 @@ MODULE_DEVICE_TABLE(i2c, st_accel_id_table); static int st_accel_i2c_probe(struct i2c_client *client) { - struct iio_dev *indio_dev; + const struct st_sensor_settings *settings; struct st_sensor_data *adata; + struct iio_dev *indio_dev; const char *match; int ret; + match = device_get_match_data(&client->dev); + if (match) + strlcpy(client->name, match, sizeof(client->name)); + + settings = st_accel_get_settings(client->name); + if (!settings) { + dev_err(&client->dev, "device name %s not recognized.\n", + client->name); + return -ENODEV; + } + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata)); if (!indio_dev) return -ENOMEM; adata = iio_priv(indio_dev); - - match = device_get_match_data(&client->dev); - if (match) - strlcpy(client->name, match, sizeof(client->name)); + adata->sensor_settings = (struct st_sensor_settings *)settings; st_sensors_i2c_configure(indio_dev, client, adata); diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c index 474742e35d92..c0556db9d60a 100644 --- a/drivers/iio/accel/st_accel_spi.c +++ b/drivers/iio/accel/st_accel_spi.c @@ -102,18 +102,28 @@ MODULE_DEVICE_TABLE(of, st_accel_of_match); static int st_accel_spi_probe(struct spi_device *spi) { - struct iio_dev *indio_dev; + const struct st_sensor_settings *settings; struct st_sensor_data *adata; + struct iio_dev *indio_dev; int err; + st_sensors_of_name_probe(&spi->dev, st_accel_of_match, + spi->modalias, sizeof(spi->modalias)); + + settings = st_accel_get_settings(spi->modalias); + if (!settings) { + dev_err(&spi->dev, "device name %s not recognized.\n", + spi->modalias); + return -ENODEV; + } + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adata)); if (!indio_dev) return -ENOMEM; adata = iio_priv(indio_dev); + adata->sensor_settings = (struct st_sensor_settings *)settings; - st_sensors_of_name_probe(&spi->dev, st_accel_of_match, - spi->modalias, sizeof(spi->modalias)); st_sensors_spi_configure(indio_dev, spi, adata); err = st_accel_common_probe(indio_dev); From patchwork Thu Jul 18 22:53:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11049615 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 D172414DB for ; Thu, 18 Jul 2019 22:54:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1DBE28884 for ; Thu, 18 Jul 2019 22:54:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B634F288AA; Thu, 18 Jul 2019 22:54:46 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 5830828884 for ; Thu, 18 Jul 2019 22:54:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728157AbfGRWyq (ORCPT ); Thu, 18 Jul 2019 18:54:46 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:33704 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728139AbfGRWyp (ORCPT ); Thu, 18 Jul 2019 18:54:45 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6IMkxUR008016; Fri, 19 Jul 2019 00:54:41 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=IYVoBhs2EVsmX5p8pytQyzJyIYb3t3KqBJRnurGufE8=; b=jY3GmfoPoBZK4kJFOK67FUpe3lalymMJrfo39dAC1L0dgn4I6vFBL6TSQoOWkY3XVwd5 OqKQ8LXxArfB1V+naVN4MfRciXElcm7EwJ/eLaX18zC4yoABv3y6VRC7PzAArMCyspAv mHS8bbZAsWqIbZa2cHBEMu0QUK+0RENtauCE5lC1oAe++iqQ1TjfPEoaREx0useYJs4q sK3xWsl1ku31Lk572Z5YVBfEq625mhwbYMCD6gh32V9jE73uGmswxUsRWkrsCLGjjnsP LtjY6+fgUWNWsaKOG9r0cHFQ5y+fZDmoTghvSwws1FWpwgG5VhJXR6tgW2A36pUhgqBC fQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2tq66hmuq8-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 19 Jul 2019 00:54:41 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8628834; Thu, 18 Jul 2019 22:54:40 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 734D910A4; Thu, 18 Jul 2019 22:54:40 +0000 (GMT) Received: from localhost (10.75.127.47) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 19 Jul 2019 00:54:39 +0200 From: Denis Ciocca To: , , Subject: [PATCH v2 07/11] iio:gyro: device settings are set immediately during probe Date: Thu, 18 Jul 2019 15:53:49 -0700 Message-ID: <20190718225353.2078-8-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718225353.2078-1-denis.ciocca@st.com> References: <20190718225353.2078-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG3NODE1.st.com (10.75.127.7) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-18_12:,, signatures=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 This patch set gyro settings right after probe start. This is done in preparation of regmap that needs different configuration based on multiread bit value. Signed-off-by: Denis Ciocca --- Changes in v2: not there in v1. drivers/iio/gyro/st_gyro_i2c.c | 18 ++++++++++++++---- drivers/iio/gyro/st_gyro_spi.c | 16 +++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c index f2a8683db7d9..fa71e94b76f4 100644 --- a/drivers/iio/gyro/st_gyro_i2c.c +++ b/drivers/iio/gyro/st_gyro_i2c.c @@ -63,19 +63,29 @@ MODULE_DEVICE_TABLE(of, st_gyro_of_match); #endif static int st_gyro_i2c_probe(struct i2c_client *client, - const struct i2c_device_id *id) + const struct i2c_device_id *id) { - struct iio_dev *indio_dev; + const struct st_sensor_settings *settings; struct st_sensor_data *gdata; + struct iio_dev *indio_dev; int err; + st_sensors_of_name_probe(&client->dev, st_gyro_of_match, + client->name, sizeof(client->name)); + + settings = st_gyro_get_settings(client->name); + if (!settings) { + dev_err(&client->dev, "device name %s not recognized.\n", + client->name); + return -ENODEV; + } + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*gdata)); if (!indio_dev) return -ENOMEM; gdata = iio_priv(indio_dev); - st_sensors_of_name_probe(&client->dev, st_gyro_of_match, - client->name, sizeof(client->name)); + gdata->sensor_settings = (struct st_sensor_settings *)settings; st_sensors_i2c_configure(indio_dev, client, gdata); diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c index 93c48248bea6..bb7082055f85 100644 --- a/drivers/iio/gyro/st_gyro_spi.c +++ b/drivers/iio/gyro/st_gyro_spi.c @@ -69,18 +69,28 @@ MODULE_DEVICE_TABLE(of, st_gyro_of_match); static int st_gyro_spi_probe(struct spi_device *spi) { - struct iio_dev *indio_dev; + const struct st_sensor_settings *settings; struct st_sensor_data *gdata; + struct iio_dev *indio_dev; int err; + st_sensors_of_name_probe(&spi->dev, st_gyro_of_match, + spi->modalias, sizeof(spi->modalias)); + + settings = st_gyro_get_settings(spi->modalias); + if (!settings) { + dev_err(&spi->dev, "device name %s not recognized.\n", + spi->modalias); + return -ENODEV; + } + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*gdata)); if (!indio_dev) return -ENOMEM; gdata = iio_priv(indio_dev); + gdata->sensor_settings = (struct st_sensor_settings *)settings; - st_sensors_of_name_probe(&spi->dev, st_gyro_of_match, - spi->modalias, sizeof(spi->modalias)); st_sensors_spi_configure(indio_dev, spi, gdata); err = st_gyro_common_probe(indio_dev); From patchwork Thu Jul 18 22:53:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11049617 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 BA3D714DB for ; Thu, 18 Jul 2019 22:54:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9F4128884 for ; Thu, 18 Jul 2019 22:54:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DEAF288AA; Thu, 18 Jul 2019 22:54:49 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 3EF2D28884 for ; Thu, 18 Jul 2019 22:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391355AbfGRWys (ORCPT ); Thu, 18 Jul 2019 18:54:48 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:12236 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728139AbfGRWys (ORCPT ); Thu, 18 Jul 2019 18:54:48 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6IMpK2X028031; Fri, 19 Jul 2019 00:54:43 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=vpmJ1038BeiU2wkWfjl6bJqlVvIXCgFOHZ7ZNpXVk54=; b=IrAdKrKprD+ciwR0pei5F/SHm1hm0I50F6Leh81fIfUqUH90+JutZ29ySUyGudOfFfbu 2XwVBoJlwbwQ8WcVTR7savMItxadFGjIlpHY0R/8RsnjDxunnKFnPi4pIqm3Ug7td2dc bfyX82agQTFGHbu/KCLITLKzzSf01Fdg4BS3pRUteUQ0Jk/S6C+Ye3YVO/9+2JQfCXDo dXLvfrUypSbGfIldhEl9SXVFjn7xFA2EurdWa4VWvEn1IyFGUxEqj40yRRej40tv9uN8 uhFy7i85ynO4AKZmKoV9t63IpQTz+4QdYI3cifWo0ilMiTqcEgb0p9XK8cz6l+xGLnxo RA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2tq4e9da9k-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 19 Jul 2019 00:54:43 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5176A34; Thu, 18 Jul 2019 22:54:43 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3C61F10AC; Thu, 18 Jul 2019 22:54:43 +0000 (GMT) Received: from localhost (10.75.127.44) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 19 Jul 2019 00:54:42 +0200 From: Denis Ciocca To: , , Subject: [PATCH v2 08/11] iio:magn: device settings are set immediately during probe Date: Thu, 18 Jul 2019 15:53:50 -0700 Message-ID: <20190718225353.2078-9-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718225353.2078-1-denis.ciocca@st.com> References: <20190718225353.2078-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG7NODE1.st.com (10.75.127.19) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-18_12:,, signatures=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 This patch set magn settings right after probe start. This is done in preparation of regmap that needs different configuration based on multiread bit value. Signed-off-by: Denis Ciocca --- Changes in v2: not there in v1. drivers/iio/magnetometer/st_magn_i2c.c | 18 ++++++++++++++---- drivers/iio/magnetometer/st_magn_spi.c | 16 +++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c index 4d014fd1aeb0..d5d565639bed 100644 --- a/drivers/iio/magnetometer/st_magn_i2c.c +++ b/drivers/iio/magnetometer/st_magn_i2c.c @@ -55,19 +55,29 @@ MODULE_DEVICE_TABLE(of, st_magn_of_match); #endif static int st_magn_i2c_probe(struct i2c_client *client, - const struct i2c_device_id *id) + const struct i2c_device_id *id) { - struct iio_dev *indio_dev; + const struct st_sensor_settings *settings; struct st_sensor_data *mdata; + struct iio_dev *indio_dev; int err; + st_sensors_of_name_probe(&client->dev, st_magn_of_match, + client->name, sizeof(client->name)); + + settings = st_magn_get_settings(client->name); + if (!settings) { + dev_err(&client->dev, "device name %s not recognized.\n", + client->name); + return -ENODEV; + } + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*mdata)); if (!indio_dev) return -ENOMEM; mdata = iio_priv(indio_dev); - st_sensors_of_name_probe(&client->dev, st_magn_of_match, - client->name, sizeof(client->name)); + mdata->sensor_settings = (struct st_sensor_settings *)settings; st_sensors_i2c_configure(indio_dev, client, mdata); diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c index 0d47070611b1..a3045afc6b53 100644 --- a/drivers/iio/magnetometer/st_magn_spi.c +++ b/drivers/iio/magnetometer/st_magn_spi.c @@ -51,18 +51,28 @@ MODULE_DEVICE_TABLE(of, st_magn_of_match); static int st_magn_spi_probe(struct spi_device *spi) { - struct iio_dev *indio_dev; + const struct st_sensor_settings *settings; struct st_sensor_data *mdata; + struct iio_dev *indio_dev; int err; + st_sensors_of_name_probe(&spi->dev, st_magn_of_match, + spi->modalias, sizeof(spi->modalias)); + + settings = st_magn_get_settings(spi->modalias); + if (!settings) { + dev_err(&spi->dev, "device name %s not recognized.\n", + spi->modalias); + return -ENODEV; + } + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*mdata)); if (!indio_dev) return -ENOMEM; mdata = iio_priv(indio_dev); + mdata->sensor_settings = (struct st_sensor_settings *)settings; - st_sensors_of_name_probe(&spi->dev, st_magn_of_match, - spi->modalias, sizeof(spi->modalias)); st_sensors_spi_configure(indio_dev, spi, mdata); err = st_magn_common_probe(indio_dev); From patchwork Thu Jul 18 22:53:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11049619 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 042E114F6 for ; Thu, 18 Jul 2019 22:54:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8ED328884 for ; Thu, 18 Jul 2019 22:54:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD7BD288AA; Thu, 18 Jul 2019 22:54:52 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 785C228884 for ; Thu, 18 Jul 2019 22:54:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391375AbfGRWyw (ORCPT ); Thu, 18 Jul 2019 18:54:52 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:65224 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728139AbfGRWyw (ORCPT ); Thu, 18 Jul 2019 18:54:52 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6IMqFnn028128; Fri, 19 Jul 2019 00:54:46 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=F6/mt0v/4lRGrQuZxyoylBUmAtkgi1SRGt/2PKBnngg=; b=jHYEeACwTMFppMwwS1bR41csxMOuTKbaKPLwxGgOhvZxnjTvO39SBhuRSfQUr9ElQ1uE SvDLIuL6AxOfz4uc+zl/LjtArEVwt+9KQX0n/af97UZ2GuUhBocNEsDKh1ME43pqs8AT qiWdVlx+pN8TC+xMNiHJGhd6SZsCCB2frJr1XAhQyqIVy3dq5UvYz76/5PyQ9CHVFTFW ZB+gPCfytm2lpU/IT46E6axpv9eKmCUI8QL4fOLHcfAvr4Ny6aSqryXumUa4fq/erpq8 DXY5buQl+HT+kuR9zZZihQ3xwZ8lz7aKhF7dk+qXzTHM6xJSYyWAXCzOeZHCFgG8ObKM Gw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2tq4s24j71-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 19 Jul 2019 00:54:46 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1463D31; Thu, 18 Jul 2019 22:54:46 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 007C810AD; Thu, 18 Jul 2019 22:54:45 +0000 (GMT) Received: from localhost (10.75.127.47) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 19 Jul 2019 00:54:45 +0200 From: Denis Ciocca To: , , Subject: [PATCH v2 09/11] iio:pressure: device settings are set immediately during probe Date: Thu, 18 Jul 2019 15:53:51 -0700 Message-ID: <20190718225353.2078-10-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718225353.2078-1-denis.ciocca@st.com> References: <20190718225353.2078-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG3NODE3.st.com (10.75.127.9) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-18_12:,, signatures=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 This patch set pressure settings right after probe start. This is done in preparation of regmap that needs different configuration based on multiread bit value. Signed-off-by: Denis Ciocca --- Changes in v2: not there in v1. drivers/iio/pressure/st_pressure_i2c.c | 27 +++++++++++++++++--------- drivers/iio/pressure/st_pressure_spi.c | 18 +++++++++++++---- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c index b7d9ba706abc..466e7dde5eae 100644 --- a/drivers/iio/pressure/st_pressure_i2c.c +++ b/drivers/iio/pressure/st_pressure_i2c.c @@ -78,18 +78,13 @@ static const struct i2c_device_id st_press_id_table[] = { MODULE_DEVICE_TABLE(i2c, st_press_id_table); static int st_press_i2c_probe(struct i2c_client *client, - const struct i2c_device_id *id) + const struct i2c_device_id *id) { - struct iio_dev *indio_dev; + const struct st_sensor_settings *settings; struct st_sensor_data *press_data; + struct iio_dev *indio_dev; int ret; - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data)); - if (!indio_dev) - return -ENOMEM; - - press_data = iio_priv(indio_dev); - if (client->dev.of_node) { st_sensors_of_name_probe(&client->dev, st_press_of_match, client->name, sizeof(client->name)); @@ -99,10 +94,24 @@ static int st_press_i2c_probe(struct i2c_client *client, return -ENODEV; strlcpy(client->name, st_press_id_table[ret].name, - sizeof(client->name)); + sizeof(client->name)); } else if (!id) return -ENODEV; + settings = st_press_get_settings(client->name); + if (!settings) { + dev_err(&client->dev, "device name %s not recognized.\n", + client->name); + return -ENODEV; + } + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data)); + if (!indio_dev) + return -ENOMEM; + + press_data = iio_priv(indio_dev); + press_data->sensor_settings = (struct st_sensor_settings *)settings; + st_sensors_i2c_configure(indio_dev, client, press_data); ret = st_press_common_probe(indio_dev); diff --git a/drivers/iio/pressure/st_pressure_spi.c b/drivers/iio/pressure/st_pressure_spi.c index ef61401c41d3..3e8c1ffe001e 100644 --- a/drivers/iio/pressure/st_pressure_spi.c +++ b/drivers/iio/pressure/st_pressure_spi.c @@ -61,18 +61,28 @@ MODULE_DEVICE_TABLE(of, st_press_of_match); static int st_press_spi_probe(struct spi_device *spi) { - struct iio_dev *indio_dev; + const struct st_sensor_settings *settings; struct st_sensor_data *press_data; + struct iio_dev *indio_dev; int err; + st_sensors_of_name_probe(&spi->dev, st_press_of_match, + spi->modalias, sizeof(spi->modalias)); + + settings = st_press_get_settings(spi->modalias); + if (!settings) { + dev_err(&spi->dev, "device name %s not recognized.\n", + spi->modalias); + return -ENODEV; + } + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*press_data)); - if (indio_dev == NULL) + if (!indio_dev) return -ENOMEM; press_data = iio_priv(indio_dev); + press_data->sensor_settings = (struct st_sensor_settings *)settings; - st_sensors_of_name_probe(&spi->dev, st_press_of_match, - spi->modalias, sizeof(spi->modalias)); st_sensors_spi_configure(indio_dev, spi, press_data); err = st_press_common_probe(indio_dev); From patchwork Thu Jul 18 22:53:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11049621 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 F143E14F6 for ; Thu, 18 Jul 2019 22:54:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFA1828884 for ; Thu, 18 Jul 2019 22:54:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3F57288AA; Thu, 18 Jul 2019 22:54:57 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 F2F9128884 for ; Thu, 18 Jul 2019 22:54:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391428AbfGRWy4 (ORCPT ); Thu, 18 Jul 2019 18:54:56 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:19088 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728139AbfGRWy4 (ORCPT ); Thu, 18 Jul 2019 18:54:56 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6IMpbVw000784; Fri, 19 Jul 2019 00:54:49 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=/yg59GywDmWkLvRNkTWla8ps6oS+gSH2nD8hWCw1m2o=; b=qS7kNlEhvEAuNecxcN2TFWT5NPEqgGdLz92RGDuKkS3ErFmRx4vex8K+iEJlb9TM9yHM MJbb0SfRjBgAmDXt8bdyCgXQM7Gxxa41SPAAZY1p7XK2IMG5rC2gNSpZ7WSoAY38eZv9 dnVhcTZyjzdbNgf6OryzZXYyusnYgOulaSmTDYm7KZ62R0zD29Ng+Kpck/A3SXowoBVF JpKMDx5KvPNKBrq7CTbnUhyI1murn4oZVBgeA1dVvvlOHYbSm3V6hwRkfbwR2CzA1NMn S2GHhtjkyPEipdoTIz474yah/vHm/Pxai8bs4aWeTyuLimufcDLr3pVwpEXvV6Csw6u/ lw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2tsdepr8xt-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 19 Jul 2019 00:54:49 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0806A31; Thu, 18 Jul 2019 22:54:49 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E125A10AD; Thu, 18 Jul 2019 22:54:48 +0000 (GMT) Received: from localhost (10.75.127.49) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 19 Jul 2019 00:54:47 +0200 From: Denis Ciocca To: , , Subject: [PATCH v2 10/11] iio: move 3-wire spi initialization to st_sensors_spi Date: Thu, 18 Jul 2019 15:53:52 -0700 Message-ID: <20190718225353.2078-11-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718225353.2078-1-denis.ciocca@st.com> References: <20190718225353.2078-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG8NODE1.st.com (10.75.127.22) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-18_12:,, signatures=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 Some devices need to be configured with special bit in order to use spi 3-wire. This was done during device identification phase. Instead, let's move this part as spi specific. Doing this the check_device_support function becomes a simple device id check, so let's rename it. Signed-off-by: Denis Ciocca --- Changes in v2: not there in v1. drivers/iio/accel/st_accel_core.c | 4 +- drivers/iio/accel/st_accel_spi.c | 4 +- .../iio/common/st_sensors/st_sensors_core.c | 64 +++++------------- .../iio/common/st_sensors/st_sensors_spi.c | 65 ++++++++++++++++++- drivers/iio/gyro/st_gyro_core.c | 4 +- drivers/iio/gyro/st_gyro_spi.c | 4 +- drivers/iio/magnetometer/st_magn_core.c | 4 +- drivers/iio/magnetometer/st_magn_spi.c | 4 +- drivers/iio/pressure/st_pressure_core.c | 4 +- drivers/iio/pressure/st_pressure_spi.c | 4 +- include/linux/iio/common/st_sensors.h | 3 +- include/linux/iio/common/st_sensors_spi.h | 4 +- 12 files changed, 97 insertions(+), 71 deletions(-) diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index 6fc490ffef7e..630909702a19 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c @@ -1183,9 +1183,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev) if (err) return err; - err = st_sensors_check_device_support(indio_dev, - ARRAY_SIZE(st_accel_sensors_settings), - st_accel_sensors_settings); + err = st_sensors_verify_id(indio_dev); if (err < 0) goto st_accel_power_off; diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c index c0556db9d60a..8af7027d5598 100644 --- a/drivers/iio/accel/st_accel_spi.c +++ b/drivers/iio/accel/st_accel_spi.c @@ -124,7 +124,9 @@ static int st_accel_spi_probe(struct spi_device *spi) adata = iio_priv(indio_dev); adata->sensor_settings = (struct st_sensor_settings *)settings; - st_sensors_spi_configure(indio_dev, spi, adata); + err = st_sensors_spi_configure(indio_dev, spi); + if (err < 0) + return err; err = st_accel_common_probe(indio_dev); if (err < 0) diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index 3610ca9eaa87..40977d2ee400 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -608,31 +608,6 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev, } EXPORT_SYMBOL(st_sensors_read_info_raw); -static int st_sensors_init_interface_mode(struct iio_dev *indio_dev, - const struct st_sensor_settings *sensor_settings) -{ - struct st_sensor_data *sdata = iio_priv(indio_dev); - struct device_node *np = sdata->dev->of_node; - struct st_sensors_platform_data *pdata; - - pdata = (struct st_sensors_platform_data *)sdata->dev->platform_data; - if (((np && of_property_read_bool(np, "spi-3wire")) || - (pdata && pdata->spi_3wire)) && sensor_settings->sim.addr) { - int err; - - err = sdata->tf->write_byte(&sdata->tb, sdata->dev, - sensor_settings->sim.addr, - sensor_settings->sim.value); - if (err < 0) { - dev_err(&indio_dev->dev, - "failed to init interface mode\n"); - return err; - } - } - - return 0; -} - /* * st_sensors_get_settings_index() - get index of the sensor settings for a * specific device from list of settings @@ -660,36 +635,30 @@ int st_sensors_get_settings_index(const char *name, } EXPORT_SYMBOL(st_sensors_get_settings_index); -int st_sensors_check_device_support(struct iio_dev *indio_dev, - int num_sensors_list, - const struct st_sensor_settings *sensor_settings) +/* + * st_sensors_verify_id() - verify sensor ID (WhoAmI) is matching with the + * expected value + * @indio_dev: IIO device reference. + * + * Return: 0 on success (valid sensor ID), else a negative error code. + */ +int st_sensors_verify_id(struct iio_dev *indio_dev) { struct st_sensor_data *sdata = iio_priv(indio_dev); - int i, err; + int err; u8 wai; - i = st_sensors_get_settings_index(indio_dev->name, - sensor_settings, num_sensors_list); - if (i < 0) { - dev_err(&indio_dev->dev, "device name %s not recognized.\n", - indio_dev->name); - return i; - } - - err = st_sensors_init_interface_mode(indio_dev, &sensor_settings[i]); - if (err < 0) - return err; - - if (sensor_settings[i].wai_addr) { + if (settings->wai_addr) { err = sdata->tf->read_byte(&sdata->tb, sdata->dev, - sensor_settings[i].wai_addr, &wai); + sdata->sensor_settings->wai_addr, + &wai); if (err < 0) { dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n"); return err; } - if (sensor_settings[i].wai != wai) { + if (sdata->sensor_settings->wai != wai) { dev_err(&indio_dev->dev, "%s: WhoAmI mismatch (0x%x).\n", indio_dev->name, wai); @@ -697,12 +666,9 @@ int st_sensors_check_device_support(struct iio_dev *indio_dev, } } - sdata->sensor_settings = - (struct st_sensor_settings *)&sensor_settings[i]; - - return i; + return 0; } -EXPORT_SYMBOL(st_sensors_check_device_support); +EXPORT_SYMBOL(st_sensors_verify_id); ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev, struct device_attribute *attr, char *buf) diff --git a/drivers/iio/common/st_sensors/st_sensors_spi.c b/drivers/iio/common/st_sensors/st_sensors_spi.c index 2213843f02cb..a57cd648975c 100644 --- a/drivers/iio/common/st_sensors/st_sensors_spi.c +++ b/drivers/iio/common/st_sensors/st_sensors_spi.c @@ -102,9 +102,68 @@ static const struct st_sensor_transfer_function st_sensors_tf_spi = { .read_multiple_byte = st_sensors_spi_read_multiple_byte, }; -void st_sensors_spi_configure(struct iio_dev *indio_dev, - struct spi_device *spi, struct st_sensor_data *sdata) +/* + * st_sensors_is_spi_3_wire() - check if SPI 3-wire mode has been selected + * @spi: spi device reference. + * + * Return: true if SPI 3-wire mode is selected, false otherwise. + */ +static bool st_sensors_is_spi_3_wire(struct spi_device *spi) +{ + struct device_node *np = spi->dev.of_node; + struct st_sensors_platform_data *pdata; + + pdata = (struct st_sensors_platform_data *)spi->dev.platform_data; + if ((np && of_property_read_bool(np, "spi-3wire")) || + (pdata && pdata->spi_3wire)) { + return true; + } + + return false; +} + +/* + * st_sensors_configure_spi_3_wire() - configure SPI 3-wire if needed + * @spi: spi device reference. + * @settings: sensor specific settings reference. + * + * Return: 0 on success, else a negative error code. + */ +static int st_sensors_configure_spi_3_wire(struct spi_device *spi, + struct st_sensor_settings *settings) +{ + if (settings->sim.addr) { + u8 buffer[] = { + settings->sim.addr, + settings->sim.value + }; + + return spi_write(spi, buffer, 2); + } + + return 0; +} + +/* + * st_sensors_spi_configure() - configure SPI interface + * @indio_dev: IIO device reference. + * @spi: spi device reference. + * + * Return: 0 on success, else a negative error code. + */ +int st_sensors_spi_configure(struct iio_dev *indio_dev, + struct spi_device *spi) { + struct st_sensor_data *sdata = iio_priv(indio_dev); + int err; + + if (st_sensors_is_spi_3_wire(spi)) { + err = st_sensors_configure_spi_3_wire(spi, + sdata->sensor_settings); + if (err < 0) + return err; + } + spi_set_drvdata(spi, indio_dev); indio_dev->dev.parent = &spi->dev; @@ -113,6 +172,8 @@ void st_sensors_spi_configure(struct iio_dev *indio_dev, sdata->dev = &spi->dev; sdata->tf = &st_sensors_tf_spi; sdata->get_irq_data_ready = st_sensors_spi_get_irq; + + return 0; } EXPORT_SYMBOL(st_sensors_spi_configure); diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c index 5cc63d41d855..4b87e79aa744 100644 --- a/drivers/iio/gyro/st_gyro_core.c +++ b/drivers/iio/gyro/st_gyro_core.c @@ -400,9 +400,7 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) if (err) return err; - err = st_sensors_check_device_support(indio_dev, - ARRAY_SIZE(st_gyro_sensors_settings), - st_gyro_sensors_settings); + err = st_sensors_verify_id(indio_dev); if (err < 0) goto st_gyro_power_off; diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c index bb7082055f85..b5c624251231 100644 --- a/drivers/iio/gyro/st_gyro_spi.c +++ b/drivers/iio/gyro/st_gyro_spi.c @@ -91,7 +91,9 @@ static int st_gyro_spi_probe(struct spi_device *spi) gdata = iio_priv(indio_dev); gdata->sensor_settings = (struct st_sensor_settings *)settings; - st_sensors_spi_configure(indio_dev, spi, gdata); + err = st_sensors_spi_configure(indio_dev, spi); + if (err < 0) + return err; err = st_gyro_common_probe(indio_dev); if (err < 0) diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c index 43a49a52c81a..3f313aefece6 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -502,9 +502,7 @@ int st_magn_common_probe(struct iio_dev *indio_dev) if (err) return err; - err = st_sensors_check_device_support(indio_dev, - ARRAY_SIZE(st_magn_sensors_settings), - st_magn_sensors_settings); + err = st_sensors_verify_id(indio_dev); if (err < 0) goto st_magn_power_off; diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c index a3045afc6b53..fbf909bde841 100644 --- a/drivers/iio/magnetometer/st_magn_spi.c +++ b/drivers/iio/magnetometer/st_magn_spi.c @@ -73,7 +73,9 @@ static int st_magn_spi_probe(struct spi_device *spi) mdata = iio_priv(indio_dev); mdata->sensor_settings = (struct st_sensor_settings *)settings; - st_sensors_spi_configure(indio_dev, spi, mdata); + err = st_sensors_spi_configure(indio_dev, spi); + if (err < 0) + return err; err = st_magn_common_probe(indio_dev); if (err < 0) diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c index 35d80ff27464..a783fc075c26 100644 --- a/drivers/iio/pressure/st_pressure_core.c +++ b/drivers/iio/pressure/st_pressure_core.c @@ -698,9 +698,7 @@ int st_press_common_probe(struct iio_dev *indio_dev) if (err) return err; - err = st_sensors_check_device_support(indio_dev, - ARRAY_SIZE(st_press_sensors_settings), - st_press_sensors_settings); + err = st_sensors_verify_id(indio_dev); if (err < 0) goto st_press_power_off; diff --git a/drivers/iio/pressure/st_pressure_spi.c b/drivers/iio/pressure/st_pressure_spi.c index 3e8c1ffe001e..7c8b70221e70 100644 --- a/drivers/iio/pressure/st_pressure_spi.c +++ b/drivers/iio/pressure/st_pressure_spi.c @@ -83,7 +83,9 @@ static int st_press_spi_probe(struct spi_device *spi) press_data = iio_priv(indio_dev); press_data->sensor_settings = (struct st_sensor_settings *)settings; - st_sensors_spi_configure(indio_dev, spi, press_data); + err = st_sensors_spi_configure(indio_dev, spi); + if (err < 0) + return err; err = st_press_common_probe(indio_dev); if (err < 0) diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h index 17fbf3e9b013..566b955e2980 100644 --- a/include/linux/iio/common/st_sensors.h +++ b/include/linux/iio/common/st_sensors.h @@ -338,8 +338,7 @@ int st_sensors_get_settings_index(const char *name, const struct st_sensor_settings *list, const int list_length); -int st_sensors_check_device_support(struct iio_dev *indio_dev, - int num_sensors_list, const struct st_sensor_settings *sensor_settings); +int st_sensors_verify_id(struct iio_dev *indio_dev); ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev, struct device_attribute *attr, char *buf); diff --git a/include/linux/iio/common/st_sensors_spi.h b/include/linux/iio/common/st_sensors_spi.h index 6020f7167859..90b25f087f06 100644 --- a/include/linux/iio/common/st_sensors_spi.h +++ b/include/linux/iio/common/st_sensors_spi.h @@ -13,7 +13,7 @@ #include #include -void st_sensors_spi_configure(struct iio_dev *indio_dev, - struct spi_device *spi, struct st_sensor_data *sdata); +int st_sensors_spi_configure(struct iio_dev *indio_dev, + struct spi_device *spi); #endif /* ST_SENSORS_SPI_H */ From patchwork Thu Jul 18 22:53:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11049623 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 E10AF14DB for ; Thu, 18 Jul 2019 22:55:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB76628884 for ; Thu, 18 Jul 2019 22:55:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBF9E288AA; Thu, 18 Jul 2019 22:55:02 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 2289F28884 for ; Thu, 18 Jul 2019 22:55:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728040AbfGRWzA (ORCPT ); Thu, 18 Jul 2019 18:55:00 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:65198 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391326AbfGRWzA (ORCPT ); Thu, 18 Jul 2019 18:55:00 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6IMqFnq028128; Fri, 19 Jul 2019 00:54:53 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=asIeISpOgkx+TiCcFdnLkb6JZYvkc7jtrC5nUgiix0M=; b=KlaQifU/iYRDw+EzQWPMTcde+Ax29+I4TMquIrsEC6LaC1vuYoGGm+toAty5wa8cprHl BZFppkdK2AcYYeehwvgdJg+z6anye+KzIKU1Cax9fV4KwDrEV1B3trew0Sdej7TPgdTW n6/c2BurK41uJw6CkJQzc5Tff0ogZXGauaEbIF2NuxvaTio5JFN4f9oDPm3+TRWahy3w XNo8BxFU+So3xsnOr3AnBZ9E7xEIJLJ1xYmc4JoEaZx4RlXdfq3Kz3bL4xNA+Nkg9+1U 2fj7GdVDkNE+xwQk0VmE0JlGezEEn14gSlsy2fYzoIMeXjUNac6cGmqx5W9L2vNQP0q7 +w== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2tq4s24j7b-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 19 Jul 2019 00:54:53 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2F24431; Thu, 18 Jul 2019 22:54:52 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0A56910AD; Thu, 18 Jul 2019 22:54:52 +0000 (GMT) Received: from localhost (10.75.127.44) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 19 Jul 2019 00:54:50 +0200 From: Denis Ciocca To: , , Subject: [PATCH v2 11/11] iio: make st_sensors drivers use regmap Date: Thu, 18 Jul 2019 15:53:53 -0700 Message-ID: <20190718225353.2078-12-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718225353.2078-1-denis.ciocca@st.com> References: <20190718225353.2078-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG3NODE1.st.com (10.75.127.7) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-18_12:,, signatures=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 This patch is meant to replace the i2c/spi transfer functions with regmap. SPI framework requires DMA safe buffers so let's add GFP_DMA flag for memory allocation used by bulk_read functions. Signed-off-by: Denis Ciocca --- Changes in v2: memory allocation uses GFP_DMA if buffer is used in bulk_read fix struct fields doc drivers/iio/accel/st_accel_buffer.c | 3 +- drivers/iio/accel/st_accel_core.c | 3 - drivers/iio/accel/st_accel_i2c.c | 4 +- .../iio/common/st_sensors/st_sensors_buffer.c | 10 +- .../iio/common/st_sensors/st_sensors_core.c | 41 +++---- .../iio/common/st_sensors/st_sensors_i2c.c | 73 ++++++------- .../iio/common/st_sensors/st_sensors_spi.c | 100 ++++-------------- .../common/st_sensors/st_sensors_trigger.c | 10 +- drivers/iio/gyro/st_gyro_buffer.c | 3 +- drivers/iio/gyro/st_gyro_core.c | 3 - drivers/iio/gyro/st_gyro_i2c.c | 4 +- drivers/iio/magnetometer/st_magn_buffer.c | 3 +- drivers/iio/magnetometer/st_magn_core.c | 3 - drivers/iio/magnetometer/st_magn_i2c.c | 4 +- drivers/iio/pressure/st_pressure_buffer.c | 3 +- drivers/iio/pressure/st_pressure_core.c | 3 - drivers/iio/pressure/st_pressure_i2c.c | 4 +- include/linux/iio/common/st_sensors.h | 40 +------ include/linux/iio/common/st_sensors_i2c.h | 4 +- 19 files changed, 105 insertions(+), 213 deletions(-) diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c index 0205c0167cdd..05f9aea431e2 100644 --- a/drivers/iio/accel/st_accel_buffer.c +++ b/drivers/iio/accel/st_accel_buffer.c @@ -39,7 +39,8 @@ static int st_accel_buffer_postenable(struct iio_dev *indio_dev) int err; struct st_sensor_data *adata = iio_priv(indio_dev); - adata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); + adata->buffer_data = kmalloc(indio_dev->scan_bytes, + GFP_DMA | GFP_KERNEL); if (adata->buffer_data == NULL) { err = -ENOMEM; goto allocate_memory_error; diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index 630909702a19..0b17004cb12e 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -1177,7 +1176,6 @@ int st_accel_common_probe(struct iio_dev *indio_dev) indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &accel_info; - mutex_init(&adata->tb.buf_lock); err = st_sensors_power_enable(indio_dev); if (err) @@ -1188,7 +1186,6 @@ int st_accel_common_probe(struct iio_dev *indio_dev) goto st_accel_power_off; adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS; - adata->multiread_bit = adata->sensor_settings->multi_read_bit; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; channels_size = indio_dev->num_channels * sizeof(struct iio_chan_spec); diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c index a92cf776031e..50fa0fc32baa 100644 --- a/drivers/iio/accel/st_accel_i2c.c +++ b/drivers/iio/accel/st_accel_i2c.c @@ -174,7 +174,9 @@ static int st_accel_i2c_probe(struct i2c_client *client) adata = iio_priv(indio_dev); adata->sensor_settings = (struct st_sensor_settings *)settings; - st_sensors_i2c_configure(indio_dev, client, adata); + ret = st_sensors_i2c_configure(indio_dev, client); + if (ret < 0) + return ret; ret = st_accel_common_probe(indio_dev); if (ret < 0) diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c index 4a68669dc555..eee30130ae23 100644 --- a/drivers/iio/common/st_sensors/st_sensors_buffer.c +++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c @@ -17,15 +17,16 @@ #include #include #include +#include #include static int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) { - int i; struct st_sensor_data *sdata = iio_priv(indio_dev); unsigned int num_data_channels = sdata->num_data_channels; + int i; for_each_set_bit(i, indio_dev->active_scan_mask, num_data_channels) { const struct iio_chan_spec *channel = &indio_dev->channels[i]; @@ -36,11 +37,8 @@ static int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) channel->scan_type.storagebits >> 3; buf = PTR_ALIGN(buf, storage_bytes); - if (sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, - channel->address, - bytes_to_read, buf, - sdata->multiread_bit) < - bytes_to_read) + if (regmap_bulk_read(sdata->regmap, channel->address, + buf, bytes_to_read) < 0) return -EIO; /* Advance the buffer pointer */ diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index 40977d2ee400..4a3064fb6cd9 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -28,19 +29,10 @@ static inline u32 st_sensors_get_unaligned_le24(const u8 *p) int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, u8 reg_addr, u8 mask, u8 data) { - int err; - u8 new_data; struct st_sensor_data *sdata = iio_priv(indio_dev); - err = sdata->tf->read_byte(&sdata->tb, sdata->dev, reg_addr, &new_data); - if (err < 0) - goto st_sensors_write_data_with_mask_error; - - new_data = ((new_data & (~mask)) | ((data << __ffs(mask)) & mask)); - err = sdata->tf->write_byte(&sdata->tb, sdata->dev, reg_addr, new_data); - -st_sensors_write_data_with_mask_error: - return err; + return regmap_update_bits(sdata->regmap, + reg_addr, mask, data << __ffs(mask)); } int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev, @@ -48,19 +40,15 @@ int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev, unsigned *readval) { struct st_sensor_data *sdata = iio_priv(indio_dev); - u8 readdata; int err; if (!readval) - return sdata->tf->write_byte(&sdata->tb, sdata->dev, - (u8)reg, (u8)writeval); + return regmap_write(sdata->regmap, reg, writeval); - err = sdata->tf->read_byte(&sdata->tb, sdata->dev, (u8)reg, &readdata); + err = regmap_read(sdata->regmap, reg, readval); if (err < 0) return err; - *readval = (unsigned)readdata; - return 0; } EXPORT_SYMBOL(st_sensors_debugfs_reg_access); @@ -545,7 +533,7 @@ int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev, int scale) EXPORT_SYMBOL(st_sensors_set_fullscale_by_gain); static int st_sensors_read_axis_data(struct iio_dev *indio_dev, - struct iio_chan_spec const *ch, int *data) + struct iio_chan_spec const *ch, int *data) { int err; u8 *outdata; @@ -554,13 +542,12 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev, byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits + ch->scan_type.shift, 8); - outdata = kmalloc(byte_for_channel, GFP_KERNEL); + outdata = kmalloc(byte_for_channel, GFP_DMA | GFP_KERNEL); if (!outdata) return -ENOMEM; - err = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, - ch->address, byte_for_channel, - outdata, sdata->multiread_bit); + err = regmap_bulk_read(sdata->regmap, ch->address, + outdata, byte_for_channel); if (err < 0) goto st_sensors_free_memory; @@ -645,13 +632,11 @@ EXPORT_SYMBOL(st_sensors_get_settings_index); int st_sensors_verify_id(struct iio_dev *indio_dev) { struct st_sensor_data *sdata = iio_priv(indio_dev); - int err; - u8 wai; + int wai, err; - if (settings->wai_addr) { - err = sdata->tf->read_byte(&sdata->tb, sdata->dev, - sdata->sensor_settings->wai_addr, - &wai); + if (sdata->sensor_settings->wai_addr) { + err = regmap_read(sdata->regmap, + sdata->sensor_settings->wai_addr, &wai); if (err < 0) { dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n"); diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c index b1c9812407e7..9240625534df 100644 --- a/drivers/iio/common/st_sensors/st_sensors_i2c.c +++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -26,55 +27,51 @@ static unsigned int st_sensors_i2c_get_irq(struct iio_dev *indio_dev) return to_i2c_client(sdata->dev)->irq; } -static int st_sensors_i2c_read_byte(struct st_sensor_transfer_buffer *tb, - struct device *dev, u8 reg_addr, u8 *res_byte) -{ - int err; - - err = i2c_smbus_read_byte_data(to_i2c_client(dev), reg_addr); - if (err < 0) - goto st_accel_i2c_read_byte_error; - - *res_byte = err & 0xff; - -st_accel_i2c_read_byte_error: - return err < 0 ? err : 0; -} - -static int st_sensors_i2c_read_multiple_byte( - struct st_sensor_transfer_buffer *tb, struct device *dev, - u8 reg_addr, int len, u8 *data, bool multiread_bit) -{ - if (multiread_bit) - reg_addr |= ST_SENSORS_I2C_MULTIREAD; - - return i2c_smbus_read_i2c_block_data_or_emulated(to_i2c_client(dev), - reg_addr, len, data); -} - -static int st_sensors_i2c_write_byte(struct st_sensor_transfer_buffer *tb, - struct device *dev, u8 reg_addr, u8 data) -{ - return i2c_smbus_write_byte_data(to_i2c_client(dev), reg_addr, data); -} +static const struct regmap_config st_sensors_i2c_regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; -static const struct st_sensor_transfer_function st_sensors_tf_i2c = { - .read_byte = st_sensors_i2c_read_byte, - .write_byte = st_sensors_i2c_write_byte, - .read_multiple_byte = st_sensors_i2c_read_multiple_byte, +static const struct regmap_config st_sensors_i2c_regmap_multiread_bit_config = { + .reg_bits = 8, + .val_bits = 8, + .read_flag_mask = ST_SENSORS_I2C_MULTIREAD, }; -void st_sensors_i2c_configure(struct iio_dev *indio_dev, - struct i2c_client *client, struct st_sensor_data *sdata) +/* + * st_sensors_i2c_configure() - configure I2C interface + * @indio_dev: IIO device reference. + * @client: i2c client reference. + * + * Return: 0 on success, else a negative error code. + */ +int st_sensors_i2c_configure(struct iio_dev *indio_dev, + struct i2c_client *client) { + struct st_sensor_data *sdata = iio_priv(indio_dev); + const struct regmap_config *config; + + if (sdata->sensor_settings->multi_read_bit) + config = &st_sensors_i2c_regmap_multiread_bit_config; + else + config = &st_sensors_i2c_regmap_config; + + sdata->regmap = devm_regmap_init_i2c(client, config); + if (IS_ERR(sdata->regmap)) { + dev_err(&client->dev, "Failed to register i2c regmap (%d)\n", + (int)PTR_ERR(sdata->regmap)); + return PTR_ERR(sdata->regmap); + } + i2c_set_clientdata(client, indio_dev); indio_dev->dev.parent = &client->dev; indio_dev->name = client->name; sdata->dev = &client->dev; - sdata->tf = &st_sensors_tf_i2c; sdata->get_irq_data_ready = st_sensors_i2c_get_irq; + + return 0; } EXPORT_SYMBOL(st_sensors_i2c_configure); diff --git a/drivers/iio/common/st_sensors/st_sensors_spi.c b/drivers/iio/common/st_sensors/st_sensors_spi.c index a57cd648975c..9c0661a283d0 100644 --- a/drivers/iio/common/st_sensors/st_sensors_spi.c +++ b/drivers/iio/common/st_sensors/st_sensors_spi.c @@ -11,12 +11,12 @@ #include #include #include +#include #include - +#include "st_sensors_core.h" #define ST_SENSORS_SPI_MULTIREAD 0xc0 -#define ST_SENSORS_SPI_READ 0x80 static unsigned int st_sensors_spi_get_irq(struct iio_dev *indio_dev) { @@ -25,81 +25,15 @@ static unsigned int st_sensors_spi_get_irq(struct iio_dev *indio_dev) return to_spi_device(sdata->dev)->irq; } -static int st_sensors_spi_read(struct st_sensor_transfer_buffer *tb, - struct device *dev, u8 reg_addr, int len, u8 *data, bool multiread_bit) -{ - int err; - - struct spi_transfer xfers[] = { - { - .tx_buf = tb->tx_buf, - .bits_per_word = 8, - .len = 1, - }, - { - .rx_buf = tb->rx_buf, - .bits_per_word = 8, - .len = len, - } - }; - - mutex_lock(&tb->buf_lock); - if ((multiread_bit) && (len > 1)) - tb->tx_buf[0] = reg_addr | ST_SENSORS_SPI_MULTIREAD; - else - tb->tx_buf[0] = reg_addr | ST_SENSORS_SPI_READ; - - err = spi_sync_transfer(to_spi_device(dev), xfers, ARRAY_SIZE(xfers)); - if (err) - goto acc_spi_read_error; - - memcpy(data, tb->rx_buf, len); - mutex_unlock(&tb->buf_lock); - return len; - -acc_spi_read_error: - mutex_unlock(&tb->buf_lock); - return err; -} - -static int st_sensors_spi_read_byte(struct st_sensor_transfer_buffer *tb, - struct device *dev, u8 reg_addr, u8 *res_byte) -{ - return st_sensors_spi_read(tb, dev, reg_addr, 1, res_byte, false); -} - -static int st_sensors_spi_read_multiple_byte( - struct st_sensor_transfer_buffer *tb, struct device *dev, - u8 reg_addr, int len, u8 *data, bool multiread_bit) -{ - return st_sensors_spi_read(tb, dev, reg_addr, len, data, multiread_bit); -} - -static int st_sensors_spi_write_byte(struct st_sensor_transfer_buffer *tb, - struct device *dev, u8 reg_addr, u8 data) -{ - int err; - - struct spi_transfer xfers = { - .tx_buf = tb->tx_buf, - .bits_per_word = 8, - .len = 2, - }; - - mutex_lock(&tb->buf_lock); - tb->tx_buf[0] = reg_addr; - tb->tx_buf[1] = data; - - err = spi_sync_transfer(to_spi_device(dev), &xfers, 1); - mutex_unlock(&tb->buf_lock); - - return err; -} +static const struct regmap_config st_sensors_spi_regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; -static const struct st_sensor_transfer_function st_sensors_tf_spi = { - .read_byte = st_sensors_spi_read_byte, - .write_byte = st_sensors_spi_write_byte, - .read_multiple_byte = st_sensors_spi_read_multiple_byte, +static const struct regmap_config st_sensors_spi_regmap_multiread_bit_config = { + .reg_bits = 8, + .val_bits = 8, + .read_flag_mask = ST_SENSORS_SPI_MULTIREAD, }; /* @@ -155,6 +89,7 @@ int st_sensors_spi_configure(struct iio_dev *indio_dev, struct spi_device *spi) { struct st_sensor_data *sdata = iio_priv(indio_dev); + const struct regmap_config *config; int err; if (st_sensors_is_spi_3_wire(spi)) { @@ -164,13 +99,24 @@ int st_sensors_spi_configure(struct iio_dev *indio_dev, return err; } + if (sdata->sensor_settings->multi_read_bit) + config = &st_sensors_spi_regmap_multiread_bit_config; + else + config = &st_sensors_spi_regmap_config; + + sdata->regmap = devm_regmap_init_spi(spi, config); + if (IS_ERR(sdata->regmap)) { + dev_err(&spi->dev, "Failed to register spi regmap (%d)\n", + (int)PTR_ERR(sdata->regmap)); + return PTR_ERR(sdata->regmap); + } + spi_set_drvdata(spi, indio_dev); indio_dev->dev.parent = &spi->dev; indio_dev->name = spi->modalias; sdata->dev = &spi->dev; - sdata->tf = &st_sensors_tf_spi; sdata->get_irq_data_ready = st_sensors_spi_get_irq; return 0; diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c index 630c8cb35e8b..bed7b8682b17 100644 --- a/drivers/iio/common/st_sensors/st_sensors_trigger.c +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "st_sensors_core.h" @@ -26,8 +27,7 @@ static int st_sensors_new_samples_available(struct iio_dev *indio_dev, struct st_sensor_data *sdata) { - u8 status; - int ret; + int ret, status; /* How would I know if I can't check it? */ if (!sdata->sensor_settings->drdy_irq.stat_drdy.addr) @@ -37,9 +37,9 @@ static int st_sensors_new_samples_available(struct iio_dev *indio_dev, if (!indio_dev->active_scan_mask) return 0; - ret = sdata->tf->read_byte(&sdata->tb, sdata->dev, - sdata->sensor_settings->drdy_irq.stat_drdy.addr, - &status); + ret = regmap_read(sdata->regmap, + sdata->sensor_settings->drdy_irq.stat_drdy.addr, + &status); if (ret < 0) { dev_err(sdata->dev, "error checking samples available\n"); diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c index 6e362f735e92..21360681d4dd 100644 --- a/drivers/iio/gyro/st_gyro_buffer.c +++ b/drivers/iio/gyro/st_gyro_buffer.c @@ -39,7 +39,8 @@ static int st_gyro_buffer_postenable(struct iio_dev *indio_dev) int err; struct st_sensor_data *gdata = iio_priv(indio_dev); - gdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); + gdata->buffer_data = kmalloc(indio_dev->scan_bytes, + GFP_DMA | GFP_KERNEL); if (gdata->buffer_data == NULL) { err = -ENOMEM; goto allocate_memory_error; diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c index 4b87e79aa744..02e42c945181 100644 --- a/drivers/iio/gyro/st_gyro_core.c +++ b/drivers/iio/gyro/st_gyro_core.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -394,7 +393,6 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &gyro_info; - mutex_init(&gdata->tb.buf_lock); err = st_sensors_power_enable(indio_dev); if (err) @@ -405,7 +403,6 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) goto st_gyro_power_off; gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS; - gdata->multiread_bit = gdata->sensor_settings->multi_read_bit; indio_dev->channels = gdata->sensor_settings->ch; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c index fa71e94b76f4..05a1a0874bd5 100644 --- a/drivers/iio/gyro/st_gyro_i2c.c +++ b/drivers/iio/gyro/st_gyro_i2c.c @@ -87,7 +87,9 @@ static int st_gyro_i2c_probe(struct i2c_client *client, gdata = iio_priv(indio_dev); gdata->sensor_settings = (struct st_sensor_settings *)settings; - st_sensors_i2c_configure(indio_dev, client, gdata); + err = st_sensors_i2c_configure(indio_dev, client); + if (err < 0) + return err; err = st_gyro_common_probe(indio_dev); if (err < 0) diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c index 11d7806655bc..9dba93539a99 100644 --- a/drivers/iio/magnetometer/st_magn_buffer.c +++ b/drivers/iio/magnetometer/st_magn_buffer.c @@ -34,7 +34,8 @@ static int st_magn_buffer_postenable(struct iio_dev *indio_dev) int err; struct st_sensor_data *mdata = iio_priv(indio_dev); - mdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); + mdata->buffer_data = kmalloc(indio_dev->scan_bytes, + GFP_DMA | GFP_KERNEL); if (mdata->buffer_data == NULL) { err = -ENOMEM; goto allocate_memory_error; diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c index 3f313aefece6..804353a483c7 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -496,7 +495,6 @@ int st_magn_common_probe(struct iio_dev *indio_dev) indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &magn_info; - mutex_init(&mdata->tb.buf_lock); err = st_sensors_power_enable(indio_dev); if (err) @@ -507,7 +505,6 @@ int st_magn_common_probe(struct iio_dev *indio_dev) goto st_magn_power_off; mdata->num_data_channels = ST_MAGN_NUMBER_DATA_CHANNELS; - mdata->multiread_bit = mdata->sensor_settings->multi_read_bit; indio_dev->channels = mdata->sensor_settings->ch; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c index d5d565639bed..fdba480a12be 100644 --- a/drivers/iio/magnetometer/st_magn_i2c.c +++ b/drivers/iio/magnetometer/st_magn_i2c.c @@ -79,7 +79,9 @@ static int st_magn_i2c_probe(struct i2c_client *client, mdata = iio_priv(indio_dev); mdata->sensor_settings = (struct st_sensor_settings *)settings; - st_sensors_i2c_configure(indio_dev, client, mdata); + err = st_sensors_i2c_configure(indio_dev, client); + if (err < 0) + return err; err = st_magn_common_probe(indio_dev); if (err < 0) diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c index 4566e08a64a1..f21b630abaa0 100644 --- a/drivers/iio/pressure/st_pressure_buffer.c +++ b/drivers/iio/pressure/st_pressure_buffer.c @@ -39,7 +39,8 @@ static int st_press_buffer_postenable(struct iio_dev *indio_dev) int err; struct st_sensor_data *press_data = iio_priv(indio_dev); - press_data->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); + press_data->buffer_data = kmalloc(indio_dev->scan_bytes, + GFP_DMA | GFP_KERNEL); if (press_data->buffer_data == NULL) { err = -ENOMEM; goto allocate_memory_error; diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c index a783fc075c26..9ef92a501286 100644 --- a/drivers/iio/pressure/st_pressure_core.c +++ b/drivers/iio/pressure/st_pressure_core.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -692,7 +691,6 @@ int st_press_common_probe(struct iio_dev *indio_dev) indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &press_info; - mutex_init(&press_data->tb.buf_lock); err = st_sensors_power_enable(indio_dev); if (err) @@ -709,7 +707,6 @@ int st_press_common_probe(struct iio_dev *indio_dev) * element. */ press_data->num_data_channels = press_data->sensor_settings->num_ch - 1; - press_data->multiread_bit = press_data->sensor_settings->multi_read_bit; indio_dev->channels = press_data->sensor_settings->ch; indio_dev->num_channels = press_data->sensor_settings->num_ch; diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c index 466e7dde5eae..71d2ed6b4948 100644 --- a/drivers/iio/pressure/st_pressure_i2c.c +++ b/drivers/iio/pressure/st_pressure_i2c.c @@ -112,7 +112,9 @@ static int st_press_i2c_probe(struct i2c_client *client, press_data = iio_priv(indio_dev); press_data->sensor_settings = (struct st_sensor_settings *)settings; - st_sensors_i2c_configure(indio_dev, client, press_data); + ret = st_sensors_i2c_configure(indio_dev, client); + if (ret < 0) + return ret; ret = st_press_common_probe(indio_dev); if (ret < 0) diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h index 566b955e2980..28fc1f9fa7d5 100644 --- a/include/linux/iio/common/st_sensors.h +++ b/include/linux/iio/common/st_sensors.h @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -169,36 +170,6 @@ struct st_sensor_data_ready_irq { } ig1; }; -/** - * struct st_sensor_transfer_buffer - ST sensor device I/O buffer - * @buf_lock: Mutex to protect rx and tx buffers. - * @tx_buf: Buffer used by SPI transfer function to send data to the sensors. - * This buffer is used to avoid DMA not-aligned issue. - * @rx_buf: Buffer used by SPI transfer to receive data from sensors. - * This buffer is used to avoid DMA not-aligned issue. - */ -struct st_sensor_transfer_buffer { - struct mutex buf_lock; - u8 rx_buf[ST_SENSORS_RX_MAX_LENGTH]; - u8 tx_buf[ST_SENSORS_TX_MAX_LENGTH] ____cacheline_aligned; -}; - -/** - * struct st_sensor_transfer_function - ST sensor device I/O function - * @read_byte: Function used to read one byte. - * @write_byte: Function used to write one byte. - * @read_multiple_byte: Function used to read multiple byte. - */ -struct st_sensor_transfer_function { - int (*read_byte) (struct st_sensor_transfer_buffer *tb, - struct device *dev, u8 reg_addr, u8 *res_byte); - int (*write_byte) (struct st_sensor_transfer_buffer *tb, - struct device *dev, u8 reg_addr, u8 data); - int (*read_multiple_byte) (struct st_sensor_transfer_buffer *tb, - struct device *dev, u8 reg_addr, int len, u8 *data, - bool multiread_bit); -}; - /** * struct st_sensor_settings - ST specific sensor settings * @wai: Contents of WhoAmI register. @@ -242,16 +213,14 @@ struct st_sensor_settings { * @current_fullscale: Maximum range of measure by the sensor. * @vdd: Pointer to sensor's Vdd power supply * @vdd_io: Pointer to sensor's Vdd-IO power supply + * @regmap: Pointer to specific sensor regmap configuration. * @enabled: Status of the sensor (false->off, true->on). - * @multiread_bit: Use or not particular bit for [I2C/SPI] multiread. * @buffer_data: Data used by buffer part. * @odr: Output data rate of the sensor [Hz]. * num_data_channels: Number of data channels used in buffer. * @drdy_int_pin: Redirect DRDY on pin 1 (1) or pin 2 (2). * @int_pin_open_drain: Set the interrupt/DRDY to open drain. * @get_irq_data_ready: Function to get the IRQ used for data ready signal. - * @tf: Transfer function structure used by I/O operations. - * @tb: Transfer buffers and mutex used by I/O operations. * @edge_irq: the IRQ triggers on edges and need special handling. * @hw_irq_trigger: if we're using the hardware interrupt on the sensor. * @hw_timestamp: Latest timestamp from the interrupt handler, when in use. @@ -264,9 +233,9 @@ struct st_sensor_data { struct st_sensor_fullscale_avl *current_fullscale; struct regulator *vdd; struct regulator *vdd_io; + struct regmap *regmap; bool enabled; - bool multiread_bit; char *buffer_data; @@ -278,9 +247,6 @@ struct st_sensor_data { unsigned int (*get_irq_data_ready) (struct iio_dev *indio_dev); - const struct st_sensor_transfer_function *tf; - struct st_sensor_transfer_buffer tb; - bool edge_irq; bool hw_irq_trigger; s64 hw_timestamp; diff --git a/include/linux/iio/common/st_sensors_i2c.h b/include/linux/iio/common/st_sensors_i2c.h index 5ada89944698..01e424e2af4f 100644 --- a/include/linux/iio/common/st_sensors_i2c.h +++ b/include/linux/iio/common/st_sensors_i2c.h @@ -14,8 +14,8 @@ #include #include -void st_sensors_i2c_configure(struct iio_dev *indio_dev, - struct i2c_client *client, struct st_sensor_data *sdata); +int st_sensors_i2c_configure(struct iio_dev *indio_dev, + struct i2c_client *client); #ifdef CONFIG_ACPI int st_sensors_match_acpi_device(struct device *dev);