From patchwork Mon Apr 17 09:19:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13213500 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA28CC77B70 for ; Mon, 17 Apr 2023 09:20:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229833AbjDQJUW (ORCPT ); Mon, 17 Apr 2023 05:20:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbjDQJUV (ORCPT ); Mon, 17 Apr 2023 05:20:21 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8971421C; Mon, 17 Apr 2023 02:20:05 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2a8b62cfaceso11775461fa.2; Mon, 17 Apr 2023 02:20:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681723204; x=1684315204; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=RgrbmJtSLO84P/9uImcl/ILG4CYzql2cJa7HytOmSio=; b=EOlZMB3Qua8VqDYh8UvRT26spK208uMi3/t4NKBjbTh+tGhzY0xCMaEgBBGAOek8wM UCs7XiVcnOkwTY8MhYnjdV7sT6VQlTMnk1BbDzWtTECYhe6fALnLvCX+jrTEMWc3bPl+ zwdX7oO8/swY+9HjJR8Q7f47VkKh5SUGaEOEUffLnXtQllB+u850iuAmfFgPmxNmXEdZ 0t3Z0k8QxnV5cu5EbsC0FonmoTb6C8NV/WZX8uDZ2LXL7x84BMxa1AuERDxikpXx8K+9 8aPys25Ho2rj7mnUD3tvl2vj5p9ZBpXtFRal0Atbfo1YX3JLGOfXniOE3B/emUWDndks 1A4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681723204; x=1684315204; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RgrbmJtSLO84P/9uImcl/ILG4CYzql2cJa7HytOmSio=; b=dlrcE85R5C83mbI+8oSr2jPpjTnZhV7Z7c1aTAnGDR6NFpnTqhPqk5d7uAAvha8sd0 oJCKyf1nfev1zN7Zo+/VU/+MToLPmPEPU2m8SjD0eAzGvuM/mv1q8anJs82mGx7qgq0Z EyHm9T2iuD36L3yTeXsfh83ZLRuFeLtOC5G1W464vesw/FmJ5rdg5Lqj20HC3+JpNVii PXesTBH7pCc48lBJO79V+mxJDCRjm/Nl/8oM2+kb+XLI64eNkCXL+rm4PqQVpnzwnAYH 1YN00FblRsrknt9AwQVgWu13JqHNa3anvJifX5Pdp9CxDnfd9TfwjZ9SMH+fPllDkKgW 8RRA== X-Gm-Message-State: AAQBX9eC/vPBF9lgSXYWeOX5h70kFqZBcj0pavTPufoRIgv/COMHY2W1 ROXgmMon+dZBpybsVGKtrZ4= X-Google-Smtp-Source: AKy350akDTp90kvAlE1J5IpQpL0xybQXZiyBGwk9M6x2mkuH4dP9XQVBPQIJtXYbV3hBDI7Vqp5+zw== X-Received: by 2002:a19:f702:0:b0:4a4:68b8:f4f1 with SMTP id z2-20020a19f702000000b004a468b8f4f1mr1792676lfe.55.1681723203760; Mon, 17 Apr 2023 02:20:03 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::1]) by smtp.gmail.com with ESMTPSA id l9-20020ac25549000000b004eb00c0d417sm1983556lfk.130.2023.04.17.02.20.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 02:20:03 -0700 (PDT) Date: Mon, 17 Apr 2023 12:19:57 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Matti Vaittinen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] iio: bu27034: Fix integration time Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The bu27034 uses micro seconds for integration time configuration. This is incorrect as the ABI mandates use of seconds. Change BU27034 driver to use seconds for integration time. Signed-off-by: Matti Vaittinen --- drivers/iio/light/rohm-bu27034.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c index e486dcf35eba..25c9b79574a5 100644 --- a/drivers/iio/light/rohm-bu27034.c +++ b/drivers/iio/light/rohm-bu27034.c @@ -1167,11 +1167,12 @@ static int bu27034_read_raw(struct iio_dev *idev, switch (mask) { case IIO_CHAN_INFO_INT_TIME: - *val = bu27034_get_int_time(data); - if (*val < 0) - return *val; + *val = 0; + *val2 = bu27034_get_int_time(data); + if (*val2 < 0) + return *val2; - return IIO_VAL_INT; + return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_SCALE: return bu27034_get_scale(data, chan->channel, val, val2); @@ -1229,7 +1230,10 @@ static int bu27034_write_raw(struct iio_dev *idev, ret = bu27034_set_scale(data, chan->channel, val, val2); break; case IIO_CHAN_INFO_INT_TIME: - ret = bu27034_try_set_int_time(data, val); + if (!val) + ret = bu27034_try_set_int_time(data, val2); + else + ret = -EINVAL; break; default: ret = -EINVAL; From patchwork Mon Apr 17 09:20:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13213501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 473E5C77B70 for ; Mon, 17 Apr 2023 09:20:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230375AbjDQJUp (ORCPT ); Mon, 17 Apr 2023 05:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230416AbjDQJUn (ORCPT ); Mon, 17 Apr 2023 05:20:43 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AE2010E7; Mon, 17 Apr 2023 02:20:26 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2a8b8c80db9so11599531fa.1; Mon, 17 Apr 2023 02:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681723224; x=1684315224; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8b+q13nOOBtyDIGmwslVX6ZI5LmXIGzDuTS6Q5xdYVU=; b=swybqH6ujpUgYy6FrANHlG+F64x8pQ+8ITmzZB5kBHu0pBn5FczbQ4/WTQ0MgkIwyq LVZ6j3h0MiZdETdryg34CJ3tE1noLFpRC2Lo7Uqy0qdSxEVkCYmkjnd6qiSGOutlfme7 0007psIpqa8Jaw8oaBREtrCmq9meogBU9suALO4GW5dBDn5abkVBg/4RheliP00kRTLI 9NmxvnQEhsXq0QiU93M7kqB4QUoq5DONSS84uBfNkFu469nj2DnhT6Fj5NGl9Sw8AyNI 9pp6LUrIl/HsO7qqbQgnbeQlbJfweOCYKzRXKKCoHIZbN4z9uF27o5z5zmz+OgenMNYa 2zLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681723224; x=1684315224; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8b+q13nOOBtyDIGmwslVX6ZI5LmXIGzDuTS6Q5xdYVU=; b=MSIVwh7p7s8lmo8CrNL/fJ0DXhlHemmfmaYlb/DiPyvKSFbfW2I8l7xD21dQ/oFKhu vUizOG6vz5n+DeI1l8p3oc2S1i/Lda8+wEC0w6BzxYWOw7X3ILnV/fy52JdBJfbfyl9G hzcxVAj/26H4VYk7J+6ziHChjaN5xWzRvh8l9Ztzib+mhIkJKB7KmhzvzoXL2EW8XIm7 Q7x2KUTP7yHgWQ06VgdKjHiIs70WHwwzA5rr6CZgBQ1j1LVE9qasDMSnKHKfHNoJfvgu H/K4A9Ax1Akcsk9Ro25xq18dEt+gBzF2Q4Dch3wRLzCJD9bqwh/+u8xqH2hbrXQ6li2b Uaxw== X-Gm-Message-State: AAQBX9cbYXxZs7UwH6O5hQzZZZIT1MM+tr/0uUgCQoRXSV4tx43qsfhX CJ0pdUOjVpZVtE9Q2fcHPlirnBLOZOw= X-Google-Smtp-Source: AKy350Y9pqjKy4+i0byTFJuew9nA4Ou8wrb6zzGnvmYOIKikh+S6EDuU2WfjMGRU5d15Yw3h4Z68rg== X-Received: by 2002:a19:7608:0:b0:4eb:1495:44ee with SMTP id c8-20020a197608000000b004eb149544eemr1459094lff.48.1681723224373; Mon, 17 Apr 2023 02:20:24 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::1]) by smtp.gmail.com with ESMTPSA id p9-20020a2e8049000000b002a8c7bd0798sm426456ljg.86.2023.04.17.02.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 02:20:23 -0700 (PDT) Date: Mon, 17 Apr 2023 12:20:18 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Matti Vaittinen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] iio: gts-helpers: fix integration time units Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The IIO ABI mandates expressing integration times in seconds. The GTS helper errorneously uses micro seconds in integration_times_available. Fix this by converting the lists to IIO_VAL_INT_PLUS_MICRO. Signed-off-by: Matti Vaittinen --- drivers/iio/industrialio-gts-helper.c | 43 ++++++++++++++++++++------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c index 8bb68975b259..2ab8d2dce019 100644 --- a/drivers/iio/industrialio-gts-helper.c +++ b/drivers/iio/industrialio-gts-helper.c @@ -337,6 +337,17 @@ static int iio_gts_build_avail_scale_table(struct iio_gts *gts) return ret; } +static void iio_gts_us_to_int_micro(int *time_us, int *int_micro_times, + int num_times) +{ + int i; + + for (i = 0; i < num_times; i++) { + int_micro_times[i * 2] = time_us[i] / 1000000; + int_micro_times[i * 2 + 1] = time_us[i] % 1000000; + } +} + /** * iio_gts_build_avail_time_table - build table of available integration times * @gts: Gain time scale descriptor @@ -351,7 +362,7 @@ static int iio_gts_build_avail_scale_table(struct iio_gts *gts) */ static int iio_gts_build_avail_time_table(struct iio_gts *gts) { - int *times, i, j, idx = 0; + int *times, i, j, idx = 0, *int_micro_times; if (!gts->num_itime) return 0; @@ -360,6 +371,7 @@ static int iio_gts_build_avail_time_table(struct iio_gts *gts) if (!times) return -ENOMEM; + /* Sort times from all tables to one and remove duplicates */ for (i = gts->num_itime - 1; i >= 0; i--) { int new = gts->itime_table[i].time_us; @@ -378,13 +390,24 @@ static int iio_gts_build_avail_time_table(struct iio_gts *gts) } } } - gts->avail_time_tables = times; - /* - * This is just to survive a unlikely corner-case where times in the - * given time table were not unique. Else we could just trust the - * gts->num_itime. - */ - gts->num_avail_time_tables = idx; + + /* create a list of times formatted as list of IIO_VAL_INT_PLUS_MICRO */ + int_micro_times = kcalloc(idx, sizeof(int) * 2, GFP_KERNEL); + if (int_micro_times) { + /* + * This is just to survive a unlikely corner-case where times in + * the given time table were not unique. Else we could just + * trust the gts->num_itime. + */ + gts->num_avail_time_tables = idx; + iio_gts_us_to_int_micro(times, int_micro_times, idx); + } + + gts->avail_time_tables = int_micro_times; + kfree(times); + + if (!int_micro_times) + return -ENOMEM; return 0; } @@ -683,8 +706,8 @@ int iio_gts_avail_times(struct iio_gts *gts, const int **vals, int *type, return -EINVAL; *vals = gts->avail_time_tables; - *type = IIO_VAL_INT; - *length = gts->num_avail_time_tables; + *type = IIO_VAL_INT_PLUS_MICRO; + *length = gts->num_avail_time_tables * 2; return IIO_AVAIL_LIST; }