From patchwork Wed Nov 13 11:19:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13873462 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C66111FA279; Wed, 13 Nov 2024 11:19:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496790; cv=none; b=qoQXAa6kl/zNnrj1HdvMaY+ua/rIE1dZaMUcGRB9AhiNo/teO6wvKq2x48IJjNqAesiCJSGjUYGaKzUU035QP0YJ9Lfa2pjPXXtzsFPNnXOrobLFSOcB7UllWUQVGud1zErCrdhN/f/ltnSdNOmS/iFC7N6hLOsyEObGk8QwT7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496790; c=relaxed/simple; bh=vu1G/K3iUOYc77Q2pZ4u5yw9IRJOBW0fw06l8wMIUuA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DJUbgS5yeZv9bZLE9pr9MRwG4JICGdN5HLfs44c06f3D15xunG+wy+h2QV5Hf+ncV6wQsOJAQ3nJap6d58BXuBzup+t6irAZ+c+ahfpp7sO6pbvNmRLUJm8K16yCvlYS6qTYOKtM28UcMGn2XCop37qq8k7DnXqUBSgLifEiPAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DzMkH+cf; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DzMkH+cf" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2fb51e00c05so80476301fa.0; Wed, 13 Nov 2024 03:19:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731496787; x=1732101587; darn=vger.kernel.org; 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=OVyD+0LvveRPdZcA7UwxKxYNGvXm4cKi4+Ze2YrwQt8=; b=DzMkH+cfl0tDSLKZhHQu+mVdKka3AzLO2k9ON6lDLerFfq5NAAYzOZ1JyvSUTP7PNb TjGjNfVmtJrPTO4UVWd8ypSpc68R2tLccxSFt52Vb1WXSiKfVVMgnLBEjD/ayHo/5TUB 7bcGq+SB5T8puiqEKeATXemCMvHhw82MQ0GiB0LJOxsAhriB0F5oROMQ/x93tgQAf4W2 zCPipZi2QUGj/Yke6Wqb8oBPNvTbcE28suKwLYKpXY61TIKQm/fbPaBbtJS7F5CIaIsU 0zRhHrl4Ds91CQ54Gc0gbtYUWaxAyj/Cjkx76OklcPGO2m5vS46idnnlBPJDaqo96ip0 Bnmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731496787; x=1732101587; 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=OVyD+0LvveRPdZcA7UwxKxYNGvXm4cKi4+Ze2YrwQt8=; b=lWWWTx++IzPEM6Zg0JH07ykezF9rGU3RllQTtW1AFWewQEjQU3zEy9GXBQwGzYNdzW PWTNg9uRtvEodGmWpgw/kA6r5nNRSpus1zhc70hh1tuVqxvvcJU6emIdodsdv3AvXlua s/2Qb61UqU9QMM/R/XQ4nSOHKVxd2WhYnvSV11vClqB0BsMvg9dxJ1AjgziiequmAHmp +xrlmczBg9p2x8M/yqru5MHJE0D/IplrDiVReSlA2/MwT4JjkUBUcQDDAbd4zrKKW7EL Y+SrNNvGREpQWf8FGscXTEegJItBjQlob0p+UqeIwwHVtZZk/FGqYInGlg4k5Th7milt GSxw== X-Forwarded-Encrypted: i=1; AJvYcCUXpfcL6zdRFcCvW/2FnHYUHMGy3vpRov53ctMjGyG4BeG34VEXGeMlKwJjHv/x8w4XCqPF6bnqtvQTB25y@vger.kernel.org, AJvYcCVrbH2SLV3DQCvHLHdXla60JeXzUmn7jekRvKTlWLSBzJMEJBPDgkMB73mevXasmqXmFJ/V9cNM6O5h@vger.kernel.org, AJvYcCWbdbIR2gelaagjgp7jtaG5X2SC76Cz2DZ5W3q4wft5r425bHVixC/25W4CLADRgrd1OS2LLvki0rss@vger.kernel.org X-Gm-Message-State: AOJu0YxhnNxh5couJTMAbsfUilYkKCoLWHk4cS3rlL1zdUneZzIfrUFg upgLtDwV/KEMyOzKX8gXNwPRY5NaKzdNJd1RJVsO+zsO+z+zFwV5 X-Google-Smtp-Source: AGHT+IEaQgpg0/aLF4pYWyIyyKOugIN2gsZBC22UsZsmIceAVgA64VsbH6WuqDqITQEnEDhc8M93Lw== X-Received: by 2002:a05:6512:3096:b0:53d:a214:386 with SMTP id 2adb3069b0e04-53da2140599mr1201785e87.27.1731496786624; Wed, 13 Nov 2024 03:19:46 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53da2191b35sm103761e87.72.2024.11.13.03.19.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 03:19:45 -0800 (PST) Date: Wed, 13 Nov 2024 13:19:41 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matti Vaittinen , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] iio: gts: Simplify using __free Message-ID: <4db5d44854c9af1b7ec8a70b28f03d8488628868.1731495937.git.mazziesaccount@gmail.com> References: Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The error path in the gain_to_scaletables() uses goto for unwinding an allocation on failure. This can be slightly simplified by using the automated free when exiting the scope. Use __free(kfree) and drop the goto based error handling. Signed-off-by: Matti Vaittinen --- drivers/iio/industrialio-gts-helper.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c index 5f131bc1a01e..85b43441b5d1 100644 --- a/drivers/iio/industrialio-gts-helper.c +++ b/drivers/iio/industrialio-gts-helper.c @@ -4,6 +4,7 @@ * Copyright (c) 2023 Matti Vaittinen */ +#include #include #include #include @@ -168,7 +169,7 @@ static int iio_gts_gain_cmp(const void *a, const void *b) static int gain_to_scaletables(struct iio_gts *gts, int **gains, int **scales) { int ret, i, j, new_idx, time_idx; - int *all_gains; + int *all_gains __free(kfree) = NULL; size_t gain_bytes; for (i = 0; i < gts->num_itime; i++) { @@ -232,10 +233,9 @@ static int gain_to_scaletables(struct iio_gts *gts, int **gains, int **scales) gts->avail_all_scales_table = kcalloc(new_idx, 2 * sizeof(int), GFP_KERNEL); - if (!gts->avail_all_scales_table) { - ret = -ENOMEM; - goto free_out; - } + if (!gts->avail_all_scales_table) + return -ENOMEM; + gts->num_avail_all_scales = new_idx; for (i = 0; i < gts->num_avail_all_scales; i++) { @@ -246,14 +246,11 @@ static int gain_to_scaletables(struct iio_gts *gts, int **gains, int **scales) if (ret) { kfree(gts->avail_all_scales_table); gts->num_avail_all_scales = 0; - goto free_out; + return ret; } } -free_out: - kfree(all_gains); - - return ret; + return 0; } /** From patchwork Wed Nov 13 11:20:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13873463 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F171200B8F; Wed, 13 Nov 2024 11:20:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496817; cv=none; b=qmQgkvNQYJ6te9dtSP2xiUe0YJK06kab177WqO3INj0peDq/K2UwbIKyLCh4RpdXCGzadXMMtO9qtKYCCmSOdWDMj1fHx+d9tN+VdgzKXXTOdDvx6SbtW9VUpfE9OWLKgMwaadV1Qbu0Pf1S+KY6cY/BLSxdlxFZ/S276a8Qj6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496817; c=relaxed/simple; bh=os6NKRV3DiBYSPOB+jwd9UanJgfU0jAP2AO4Z1GIi2I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AhWdQBSG49ZaiF2paAPgWdbbDJ9PN3R4tO75Rh9xKSAvzDDGbiZ5mQBUiiuODWucyr5CHvjgtcFZlijMuCwwgzTtedwkn7NKUDtB4T2oJvfuTDvYXHmj18NNXpGSMgg8gvpyuHyAzZYfZDdNKl7TEf5i+9XnrubQGNIZN1I/LHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GM1JRGqO; arc=none smtp.client-ip=209.85.208.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GM1JRGqO" Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2fc96f9c41fso6709441fa.0; Wed, 13 Nov 2024 03:20:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731496814; x=1732101614; darn=vger.kernel.org; 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=1hbj9OsuVyivUpj0F9cGsgeSME0OksJ9+laGHOnSVXE=; b=GM1JRGqO4uKE1wmXGsOrn8O4nYnyAtHRAOAdpzCTvi5Zn9ado4u89eC5vXHl+5NVDX yE+UoKdcH21gfqSrNTx+Sy0Z5eLHSssSAPIScjZlpXpIIOtZljcA5lPzmyfsnOq8zBLx sgoFouzHi7XMgQ/Wxcjg3ZzbDhSYTtEq9C2jgXASiJRupBdfjUJ0wtV08u5qA8oPnA5M jfF6nlHHl9WmlKtqcQ0EyqED7IA5Z1lzg4TOFeg6KNH1CrbyvoF8RbNyatsLrZnll+Wu NNSerlGiIkEoim13M0kty3KCqudOeafx+wvLlh8VRZ9tsZqgQSfhV1SsX3UukHzMG9sY LjCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731496814; x=1732101614; 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=1hbj9OsuVyivUpj0F9cGsgeSME0OksJ9+laGHOnSVXE=; b=VhgXREUFYUAZ3LqYjAYliX4AEFBi6mt07kKEYnZJtNPnt5G7PgcaMONfEgzM/SJqx0 JK11J7wO7opeB4623rieDx8A+3mmxFkEIRBYyw+GIG84tw40ocbxZcvg/ZTuiWcMznlA s0xpUH9PjWIt3MZ/3qf739vD2fNjN0jArp6rrNB/+k2EWmM7Us+L2DF3Utf1w5Vf7cFt AsdoQSQG/wIiSAvTd+dt7cvFk5hZmB67fHqr0xpzWg3ob5rCBVisOk3Ir1NBFooJMXeW WwkGSsMrmoeEtIiXEUc8rSB39MRMDXuwkQYah0an5XfrhN8vRzJvCRPP81EiJ6rAmFKr Rx/A== X-Forwarded-Encrypted: i=1; AJvYcCUkhh38Wf0uc1AjVD3+/IoQzRGjXENa+CJcqE1IgM9lhkgf5vHtYIpLjKV7GLmnvfoasn9d9kezrK0l@vger.kernel.org, AJvYcCVwfpVXzxGth9f3V4VO9w074SrT6Lb5mGKTN72dFxZ5RmjSVi50AWQr6GfAndWxdQciJHrDQCjLfosl@vger.kernel.org, AJvYcCWKmxCkwgR3bCyfkur+D+BqkaKwzSiQMWiDLVXz7KhiZvlLuViHRpQRorUMS0k1xcefMo+lYhy1rFsa1pVM@vger.kernel.org X-Gm-Message-State: AOJu0YwTsU5dVvm+EOMioiDxOzmb0CY9zGRAwKObe9A4shz1tw21jJ4w qah6eTbpKMwmxvpa6mnp4DKfuOZjWpRLHEK22fijN76Ocz+Dh0JR X-Google-Smtp-Source: AGHT+IHXn4iXxA2U9pThQOnrrgVLz1QpNkFzGPtAT6wxdiOH2IWX7M5CPlQrdjoqW45JdSEFgXqZ+Q== X-Received: by 2002:a2e:9ac7:0:b0:2fb:5bd1:c293 with SMTP id 38308e7fff4ca-2ff209f4d0amr50833241fa.21.1731496813985; Wed, 13 Nov 2024 03:20:13 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ff179d4aa8sm23347541fa.97.2024.11.13.03.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 03:20:13 -0800 (PST) Date: Wed, 13 Nov 2024 13:20:04 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matti Vaittinen , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] iio: accel: kx022a: Use cleanup.h helpers Message-ID: References: Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: A few functions in KX022A need to use mutex for protecting the enabling/disabling of the measurement while configurations are being made. Some of the functions can be slightly simplified by using the __cleanup based scoped mutexes, which allows dropping the goto based unlocking at error path. Simplify error paths using guard(mutex). Signed-off-by: Matti Vaittinen --- drivers/iio/accel/kionix-kx022a.c | 61 ++++++++++++------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c index 32387819995d..321bb2c35578 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -5,6 +5,7 @@ * ROHM/KIONIX accelerometer driver */ +#include #include #include #include @@ -448,7 +449,7 @@ static void kx022a_reg2scale(unsigned int val, unsigned int *val1, *val2 = kx022a_scale_table[val][1]; } -static int kx022a_turn_on_off_unlocked(struct kx022a_data *data, bool on) +static int __kx022a_turn_on_off(struct kx022a_data *data, bool on) { int ret; @@ -469,7 +470,7 @@ static int kx022a_turn_off_lock(struct kx022a_data *data) int ret; mutex_lock(&data->mutex); - ret = kx022a_turn_on_off_unlocked(data, false); + ret = __kx022a_turn_on_off(data, false); if (ret) mutex_unlock(&data->mutex); @@ -480,7 +481,7 @@ static int kx022a_turn_on_unlock(struct kx022a_data *data) { int ret; - ret = kx022a_turn_on_off_unlocked(data, true); + ret = __kx022a_turn_on_off(data, true); mutex_unlock(&data->mutex); return ret; @@ -912,18 +913,19 @@ static int kx022a_fifo_disable(struct kx022a_data *data) { int ret = 0; - ret = kx022a_turn_off_lock(data); + guard(mutex)(&data->mutex); + ret = __kx022a_turn_on_off(data, false); if (ret) return ret; ret = regmap_clear_bits(data->regmap, data->ien_reg, KX022A_MASK_WMI); if (ret) - goto unlock_out; + return ret; ret = regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2, KX022A_MASK_BUF_EN); if (ret) - goto unlock_out; + return ret; data->state &= ~KX022A_STATE_FIFO; @@ -931,12 +933,7 @@ static int kx022a_fifo_disable(struct kx022a_data *data) kfree(data->fifo_buffer); - return kx022a_turn_on_unlock(data); - -unlock_out: - mutex_unlock(&data->mutex); - - return ret; + return __kx022a_turn_on_off(data, true); } static int kx022a_buffer_predisable(struct iio_dev *idev) @@ -959,33 +956,29 @@ static int kx022a_fifo_enable(struct kx022a_data *data) if (!data->fifo_buffer) return -ENOMEM; - ret = kx022a_turn_off_lock(data); + guard(mutex)(&data->mutex); + ret = __kx022a_turn_on_off(data, false); if (ret) return ret; /* Update watermark to HW */ ret = kx022a_fifo_set_wmi(data); if (ret) - goto unlock_out; + return ret; /* Enable buffer */ ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2, KX022A_MASK_BUF_EN); if (ret) - goto unlock_out; + return ret; data->state |= KX022A_STATE_FIFO; ret = regmap_set_bits(data->regmap, data->ien_reg, KX022A_MASK_WMI); if (ret) - goto unlock_out; - - return kx022a_turn_on_unlock(data); - -unlock_out: - mutex_unlock(&data->mutex); + return ret; - return ret; + return __kx022a_turn_on_off(data, true); } static int kx022a_buffer_postenable(struct iio_dev *idev) @@ -1053,7 +1046,7 @@ static irqreturn_t kx022a_irq_thread_handler(int irq, void *private) struct kx022a_data *data = iio_priv(idev); irqreturn_t ret = IRQ_NONE; - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); if (data->trigger_enabled) { iio_trigger_poll_nested(data->trig); @@ -1068,8 +1061,6 @@ static irqreturn_t kx022a_irq_thread_handler(int irq, void *private) ret = IRQ_HANDLED; } - mutex_unlock(&data->mutex); - return ret; } @@ -1079,32 +1070,26 @@ static int kx022a_trigger_set_state(struct iio_trigger *trig, struct kx022a_data *data = iio_trigger_get_drvdata(trig); int ret = 0; - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); if (data->trigger_enabled == state) - goto unlock_out; + return 0; if (data->state & KX022A_STATE_FIFO) { dev_warn(data->dev, "Can't set trigger when FIFO enabled\n"); - ret = -EBUSY; - goto unlock_out; + return -EBUSY; } - ret = kx022a_turn_on_off_unlocked(data, false); + ret = __kx022a_turn_on_off(data, false); if (ret) - goto unlock_out; + return ret; data->trigger_enabled = state; ret = kx022a_set_drdy_irq(data, state); if (ret) - goto unlock_out; - - ret = kx022a_turn_on_off_unlocked(data, true); - -unlock_out: - mutex_unlock(&data->mutex); + return ret; - return ret; + return __kx022a_turn_on_off(data, true); } static const struct iio_trigger_ops kx022a_trigger_ops = { From patchwork Wed Nov 13 11:20:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13873464 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F6C31FF5E5; Wed, 13 Nov 2024 11:20:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496837; cv=none; b=g7SNV5BAzWwzrSdlMaRShw+MO6ovDe6gwyiEgSW9A3OIoV9py/nts+kROJVrS0B3Wr/snTUWAkqGToIwza2Leim74qELiR3+1ebQdlmfMjvPRwhi9kx5RCTmo5t/Ud4B5YWwiRFDnjUurlTYmfVFeQteOI/z9z+5/xMBpC2+LEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496837; c=relaxed/simple; bh=U1n36CoErKiW0PdZw+ayzm0kwFFBLzKR5JG6iNgBoHE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lHBm0Cah2nrCNmoYEwTfgS8YzCcHD6ezTKo9zlMofpwxGg5zYuXpveJpwwoKvvHwFzo+RZEuf7JtZyuZFHpbLWlgFYBxYU3jgkuI9tvfCI/yKg+pB3XQrIDfvPqPBXbYmgL9XbRLQVbHQbwotK7RdJ90h6q9v0RTLlNGQTASCZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DX15IScd; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DX15IScd" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-539f84907caso7629708e87.3; Wed, 13 Nov 2024 03:20:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731496833; x=1732101633; darn=vger.kernel.org; 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=JSAf5erNRaQJKP71Ai70DIwS8n0/VvSIv+3u/yhIIdo=; b=DX15IScd1D9ChYZ2R5TyYdc9EO6bAeFmKfEXUrFJHFS1WQKW1+E3lpFXFKsYTV5e3j pcJbGO/kFulKHSQo6WKCDYBNXoMc0Kwt9hCwwyYm8kkJHJi5CAyToE6fP//gBPf1Z0Me KpudQgNmGX6LCokAfND9CbMUM3S6VSMAsZ3AD5h3+As9sUH3Xd2uORra2YAiD8bCwsfy jGEZsA6eMSuxaqmuwcRv0sSje+x25XWhiVmrThUyUFIf6ettb25JNvpvn71IqsU7EBdX i46DTnH/rHWnen9E6sTnscx1pgMkmif15JZivcv2LXtokLWttLCl1hZWnks5d1XmWo6z P6BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731496833; x=1732101633; 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=JSAf5erNRaQJKP71Ai70DIwS8n0/VvSIv+3u/yhIIdo=; b=MKAZCzr54xq4ea4Z/GLd7B5YqW2+fY832VY90qUo7v1xctXAj6xECoMEJVlVwpGBuY 8gjF878gb6Tb4lap+8DR0h0UP6q6v7dmnkHPWlBY2RItAJs/fSrsKJjB/AZxkxnJlNTv 8EOVI25RDlQ9/VZq8e3WLnNuTFcuKXNQHnVlV6iOACsVLUpb0bWWc9fZouAp3cBbe94E 5usoS/00JVIZeBGDa300hBc6vJhx+6dyfsxHCXIwFQ0sJ8cMH+/LbuGCGgc6SRljROcZ grBbmoWCtp0TsuAgBzbkqhT0sLR3/7mdemRTXUDuGa0a3iSIXupFWIg+B4rMRFsS+C85 sfLA== X-Forwarded-Encrypted: i=1; AJvYcCUcZIAx7raT0yJz++a6pEdYWE6VFg0jC5PtrHKh4xSlp4mIcQdlJwGV1rwPoqsn4JWgihosmsdgfJC5@vger.kernel.org, AJvYcCVVBIZL3qnM6DkNknoU1EQEbgy2OfrfD6cLL/S6+MEcMPZOQm7XM0ZgPqGTz3pzLyxc/oEZaxsQE0tZ@vger.kernel.org, AJvYcCWphGDVBzjOeZwqaLfoRgeakA2DDEiDwGxDD9eMRD8vNynlK+QvKC24EJWTS+V631JEZDL7RrgNhzWV7DSk@vger.kernel.org X-Gm-Message-State: AOJu0Yz8eWrIKYRILnD9Do2llIrqQEXL7oKLoI6ACwv3+QtrnOl7GLxd Ssuze7AQNogAB0MLu9+gr/XToY/WKqJ4cqlECgiCN5QNtekW1XnD X-Google-Smtp-Source: AGHT+IH7JkALubcn0oc/gipIDR5MpOA2xnur135kdnz3s/idRAQt+/kwYNUY0/qT67KWvTTTV4Xkfw== X-Received: by 2002:a05:6512:b17:b0:52f:c13f:23d2 with SMTP id 2adb3069b0e04-53d862cae67mr9690920e87.25.1731496833088; Wed, 13 Nov 2024 03:20:33 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53d826888dfsm2137157e87.106.2024.11.13.03.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 03:20:31 -0800 (PST) Date: Wed, 13 Nov 2024 13:20:26 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matti Vaittinen , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] iio: accel: kx022a: Support ICs with different G-ranges Message-ID: <75b415b60f6c29bb01766db8b5628cc67bacc940.1731495937.git.mazziesaccount@gmail.com> References: Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The register interface of the ROHM KX134ACR-LBZ accelerometer is almost identical to the KX132ACR-LBZ. Main difference between these accelerometers is that the KX134ACR-LBZ supports G-ranges +/- 8, 16, 32 and 64G. All the other sensors supported by the kx022a driver can measure +/- 2, 4, 8 and 16G. Prepare supporting the KX134ACR-LBZ with different G-ranges by storing a pointer to the scale tables in IC specific structure. Signed-off-by: Matti Vaittinen --- drivers/iio/accel/kionix-kx022a.c | 32 ++++++++++++++++++++----------- drivers/iio/accel/kionix-kx022a.h | 2 ++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c index 321bb2c35578..e2e41dea9d9f 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -413,6 +413,8 @@ static int kx022a_read_avail(struct iio_dev *indio_dev, const int **vals, int *type, int *length, long mask) { + struct kx022a_data *data = iio_priv(indio_dev); + switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ: *vals = (const int *)kx022a_accel_samp_freq_table; @@ -421,9 +423,8 @@ static int kx022a_read_avail(struct iio_dev *indio_dev, *type = IIO_VAL_INT_PLUS_MICRO; return IIO_AVAIL_LIST; case IIO_CHAN_INFO_SCALE: - *vals = (const int *)kx022a_scale_table; - *length = ARRAY_SIZE(kx022a_scale_table) * - ARRAY_SIZE(kx022a_scale_table[0]); + *vals = (const int *)data->chip_info->scale_table; + *length = data->chip_info->scale_table_size; *type = IIO_VAL_INT_PLUS_NANO; return IIO_AVAIL_LIST; default: @@ -439,14 +440,14 @@ static void kx022a_reg2freq(unsigned int val, int *val1, int *val2) *val2 = kx022a_accel_samp_freq_table[val & KX022A_MASK_ODR][1]; } -static void kx022a_reg2scale(unsigned int val, unsigned int *val1, - unsigned int *val2) +static void kx022a_reg2scale(struct kx022a_data *data, unsigned int val, + unsigned int *val1, unsigned int *val2) { val &= KX022A_MASK_GSEL; val >>= KX022A_GSEL_SHIFT; - *val1 = kx022a_scale_table[val][0]; - *val2 = kx022a_scale_table[val][1]; + *val1 = data->chip_info->scale_table[val][0]; + *val2 = data->chip_info->scale_table[val][1]; } static int __kx022a_turn_on_off(struct kx022a_data *data, bool on) @@ -544,11 +545,11 @@ static int kx022a_write_raw(struct iio_dev *idev, kx022a_turn_on_unlock(data); break; case IIO_CHAN_INFO_SCALE: - n = ARRAY_SIZE(kx022a_scale_table); + n = data->chip_info->scale_table_size / 2; while (n-- > 0) - if (val == kx022a_scale_table[n][0] && - val2 == kx022a_scale_table[n][1]) + if (val == data->chip_info->scale_table[n][0] && + val2 == data->chip_info->scale_table[n][1]) break; if (n < 0) { ret = -EINVAL; @@ -643,7 +644,7 @@ static int kx022a_read_raw(struct iio_dev *idev, if (ret < 0) return ret; - kx022a_reg2scale(regval, val, val2); + kx022a_reg2scale(data, regval, val, val2); return IIO_VAL_INT_PLUS_NANO; } @@ -1143,6 +1144,9 @@ const struct kx022a_chip_info kx022a_chip_info = { .regmap_config = &kx022a_regmap_config, .channels = kx022a_channels, .num_channels = ARRAY_SIZE(kx022a_channels), + .scale_table = kx022a_scale_table, + .scale_table_size = ARRAY_SIZE(kx022a_scale_table) * + ARRAY_SIZE(kx022a_scale_table[0]), .fifo_length = KX022A_FIFO_LENGTH, .who = KX022A_REG_WHO, .id = KX022A_ID, @@ -1168,6 +1172,9 @@ const struct kx022a_chip_info kx132_chip_info = { .regmap_config = &kx132_regmap_config, .channels = kx132_channels, .num_channels = ARRAY_SIZE(kx132_channels), + .scale_table = kx022a_scale_table, + .scale_table_size = ARRAY_SIZE(kx022a_scale_table) * + ARRAY_SIZE(kx022a_scale_table[0]), .fifo_length = KX132_FIFO_LENGTH, .who = KX132_REG_WHO, .id = KX132_ID, @@ -1201,6 +1208,9 @@ const struct kx022a_chip_info kx132acr_chip_info = { .regmap_config = &kx022a_regmap_config, .channels = kx022a_channels, .num_channels = ARRAY_SIZE(kx022a_channels), + .scale_table = kx022a_scale_table, + .scale_table_size = ARRAY_SIZE(kx022a_scale_table) * + ARRAY_SIZE(kx022a_scale_table[0]), .fifo_length = KX022A_FIFO_LENGTH, .who = KX022A_REG_WHO, .id = KX132ACR_LBZ_ID, diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h index 7060438ad88c..36e9d9de8c13 100644 --- a/drivers/iio/accel/kionix-kx022a.h +++ b/drivers/iio/accel/kionix-kx022a.h @@ -161,6 +161,8 @@ struct kx022a_data; struct kx022a_chip_info { const char *name; const struct regmap_config *regmap_config; + const int (*scale_table)[2]; + const int scale_table_size; const struct iio_chan_spec *channels; unsigned int num_channels; unsigned int fifo_length; From patchwork Wed Nov 13 11:20:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13873465 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C99321FDFBD; Wed, 13 Nov 2024 11:20:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496859; cv=none; b=P9BY6lqy7n/TZqwH8Onuh9CCkcwH5Xhc/Xnm58E2TzI9o3t5tpW65bQdsp8EUDZ3lROBuJty0KIbbKUJ0Ot3a7J38xyrN0Mih5ozN8CI5YBfwEVG3aZ51NB00B2udOn+8Wiln4PStO6/s2G2m02irUhxXuDot9zoG/mjc80H1E4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496859; c=relaxed/simple; bh=dXXwawVq71PejwQn8YySdZi3Za4V5+AbxkyetvK7poQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sGpvYv3tPqm6e4w1Ew0esPbQPTIkO0s1nqAjgrfColaoF/1hd98eDoATS5vVbWPkMomf7++y9xciQshYb7ZSMwkLgG86ClAABaxEkgT2ZYp9Bb7vtl4u/ICY6ODv34jz+5WK1NnIPY6ANENT3BvqdoO2xtf8CMp/1NKB6abqVbg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=f2IHR05B; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f2IHR05B" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-53da353eb35so176239e87.0; Wed, 13 Nov 2024 03:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731496856; x=1732101656; darn=vger.kernel.org; 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=v0JthOn1E+unP/ANhBdZcgI5VGqlvtj51Bz6TfmN4co=; b=f2IHR05BCqszfIjwXAO5tW7nPFxXgxxCx8wyTKRtV27mGgK1waQ+VDNSYNclEJMdVo OmrGXb1gqMrOaYbNY/5+8U253A5tM8c9vD9KrREwmbAw8bHXxnC3QaqXpUT7aC+S4ABV 2h5TBW1hTyiVmcL2+qVeDAqzNqOoLKJXy74Ii0DN0YreakWNjf9vqLPF2pdlBUrKVWvD JNbnC8sdDJAGyTlIm/eQFuG8FmPBebMzXYXskaLSgd3slo1PoQfI0y4gVmAfl1sQRCas cJqQj0yyG/BomYdgvsmWjliO84f2ikTYIlbRuhKwmo77JPbGOJtzWBDacW/8bRjte9kK ZJiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731496856; x=1732101656; 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=v0JthOn1E+unP/ANhBdZcgI5VGqlvtj51Bz6TfmN4co=; b=XTozsFyCBU7snSHnnZZJlnJaavifVZGOS4xQ8YJwA1aVqlPe1BmvTOXbC5bMultPld piTYhZ0dDviQOju/qgsVjCwvsgJLUawcSnqfzHKv4Ug4KgDofSi6HYO3OxQLktHd3MUb SWzOiFO243PwoXgTet9E65UAe/Mzz8bjZl2SbV/bbdPoML0LnTqcGaV5yFel/xpN+Jm7 cxlUlO170lk1W5cGEAh3lTgh6vwFQdDcSgeEwFoRmuG0yHn5sdkQ0V0UZjx04xgvsVLW xcMwFaYg3dkTBKQcZyL0eMSGxLwjfhazvh7YfiQ2hjmsUBJtKlTn321E4e9a8Y99NA0u P4sA== X-Forwarded-Encrypted: i=1; AJvYcCUvE5LvRY3V/t56Sn2KKCwzk6I6Bqw23Gjj8YxByPfm3tQDb+5bVQSMFwuf07ZkDvTI0mffTtKxfBQQ@vger.kernel.org, AJvYcCXIHePOJ7N18DypiyZOlY76VQhwb4r9KldYqp5jr69idt2fOO3BgOYT7rs/eNryav2z+/tglvwG/VyW@vger.kernel.org, AJvYcCXzXr4MK+O4S9aiRFXpgdvy5GrFxQ3PEy6Xmjm5A1UX0yqABLrJmvv5qHleCc+ORaZjaEDXkO12ec8KCmPg@vger.kernel.org X-Gm-Message-State: AOJu0YwZCRr+QY2XbeFCF0bgwjmYOQJABmZYvn4bH/w8H4wtlG+SKHDM tdbI5psuSPlqEgUAjP7xuiE7If8Zz2rWxLHF9TCDPERkt5KhqCly X-Google-Smtp-Source: AGHT+IErCFAo4rgn2aiZG1HrU/7vrnVIVlRoLj0+JBHt3WvHqLQYCo+Og0CObPXKNZh0o3kgSTKwbg== X-Received: by 2002:a05:6512:124f:b0:53d:a34d:70b1 with SMTP id 2adb3069b0e04-53da34d71b4mr254762e87.29.1731496855391; Wed, 13 Nov 2024 03:20:55 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53d826aeb59sm2171448e87.234.2024.11.13.03.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 03:20:54 -0800 (PST) Date: Wed, 13 Nov 2024 13:20:49 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matti Vaittinen , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] dt-bindings: ROHM KX134ACR-LBZ Message-ID: References: Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Add compatible and information for ROHM KX134ACR-LBZ accelerometer. Signed-off-by: Matti Vaittinen Acked-by: Conor Dooley --- .../devicetree/bindings/iio/accel/kionix,kx022a.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml b/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml index 66ea894dbe55..c973f4941a6d 100644 --- a/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml +++ b/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml @@ -11,7 +11,8 @@ maintainers: description: | KX022A, KX132ACR-LBZ and KX132-1211 are 3-axis accelerometers supporting - +/- 2G, 4G, 8G and 16G ranges, variable output data-rates and a + +/- 2G, 4G, 8G and 16G ranges. The KX134ACR-LBZ supports +/- 8G, 16G, + 32G and 64G. All the sensors also have variable output data-rates and a hardware-fifo buffering. These accelerometers can be accessed either via I2C or SPI. @@ -21,6 +22,7 @@ properties: - kionix,kx022a - kionix,kx132-1211 - rohm,kx132acr-lbz + - rohm,kx134acr-lbz reg: maxItems: 1 From patchwork Wed Nov 13 11:21:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13873466 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D02BA18A6B8; Wed, 13 Nov 2024 11:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496877; cv=none; b=axw7ztop414f680ZrE3x1sfJqOFy8rTsj8X6zwUvprjGpHASx/a69ZqXBl3tXmPQxXy8X9E4Di/1uA/J+4Oyosn6pwwUGIH8fX2VLwUr3pzq8/u6+r8p+5JPhjlUYaEq2+4HKMn5umB0Q4P0Cd4TXWVzUfKQcR9WOv4k3hiwvY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731496877; c=relaxed/simple; bh=A9+H5DYChc9i1OraBfq2YKkXC8djpjb1+M0L+QHxpec=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bfS437WTR6amEeFwXR4SmI0Whgad/BLy6yhaWKvKFD2EiJuYDWeiDdhhUoB5nv3Argz09B6Uk2k3qLd2TbcHol7zXgAhBzUeJ36xKib82+9UBLYkx2ic+gQhLgtC1V6dA+fJ6/SoVJ7+YSwGSfKOXjg42CI7pF/sI40E4Ou1j8M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZhfscpQY; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZhfscpQY" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-53da353eb35so176534e87.0; Wed, 13 Nov 2024 03:21:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731496873; x=1732101673; darn=vger.kernel.org; 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=gNcaPkh2M7fZ1XR/E+G2gkC3Hxx73FT6z4UhoVfTABo=; b=ZhfscpQYufhmmF6Tj/u5+H2B5f6YOytIfuPJHFPOG1LuIETs4RReUapv1QIbJaYlap w8dIVZC5IW8AzffokhU8fnAID7bDYHvJdUIA2mRqU9rOdHVvmcrMMaP9rsykrsx0pViz 1YrUVnInDTfr2XrC8azLlFSYG+WE8PVbVoCXR7i08ZVuJCtmnxqyZzXljJ5BXoQF+aBP z0Kcdu2OjiqOtLyzO4frEImv7yY3b8GBUlB1HqZWJ7BHvN7jbvk4vq0uZxFhvf1A4UmJ GN83q9AseEoAl6+tsL/6pLahgR0VUznnTJeSVGcIQEV+TsIGbNOKy7zSf/+WAIcSPS+W NdXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731496873; x=1732101673; 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=gNcaPkh2M7fZ1XR/E+G2gkC3Hxx73FT6z4UhoVfTABo=; b=oTRp8iaSSkRNr1k1JHLEyOqvYFunPt9OZlc64MtV2p/q2U72fe/Gp5GPgPH2AN4Hbv L3YRJwD9IiHj08+i3tm3ClJ9hBHxbZJmtk68jpa6ptI1yp7jfES7fkyrtewSgZ8MAWMl rr9UxWSn5U/cLilr0PFzMDrETt14ri/dlXd+dmg9guDyTYlUI9p20sFpa8qUqKZzPQlU 9PYE4J98HmgZkXQ+lOBkYDJfr1cQeF065hI1zHAIwDbytYUW7CUZCXPhhufphvjroSQg rSyUDgH0fLKnwZ1z5RuVCvHwxh+imDNc223BSB9pNCP2ZfoqAd42/xk+6oKNN/D9SOjJ hu+g== X-Forwarded-Encrypted: i=1; AJvYcCUQn2/gh9at+YHCsfpuLer42Wc3L0vesQpe/m1sFLoTfIkEbRoSM/ZYGbmuP2ctoUCkHNoQu/KNrBkjYNhM@vger.kernel.org, AJvYcCVDXaQfn7hbBBvjFTXcCGj22h8NQUDuhu63wEQat9BRhfFL0vS1Tfv7V8xK4FUHGYCi4D0j+A7WbtYN@vger.kernel.org, AJvYcCWusFGFyDvMnqW0OPVICoyH1cNH8pJryoElm3iNV07rSg1BFDz0n2HxGMzdZy0JY4Mi2p0i9npwDPKl@vger.kernel.org X-Gm-Message-State: AOJu0Yz5FTtK+DZv3UVjuxJ3HsBixAfZsHGWl7UwFLxmWu6S2Bgb8H1c P9a4M1titnRZsmke5CXp9n6B39oRHof2uKdoZYKwpmcNbFhUCGz3 X-Google-Smtp-Source: AGHT+IFYQ76KJydVCSCuMqiDn5p3lMtFd+RiBmDDgbWEaeGnLPLzEVqafbvV1b1AVaz1pQ8vogbotg== X-Received: by 2002:a05:6512:3e1a:b0:539:e2cc:d380 with SMTP id 2adb3069b0e04-53d9fe89333mr1218893e87.27.1731496872570; Wed, 13 Nov 2024 03:21:12 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53d88bc8213sm1646240e87.166.2024.11.13.03.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 03:21:10 -0800 (PST) Date: Wed, 13 Nov 2024 13:21:05 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matti Vaittinen , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] iio: kx022a: Support ROHM KX134ACR-LBZ Message-ID: References: Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The register interface of the ROHM KX134ACR-LBZ accelerometer is almost identical to the KX132ACR-LBZ. The main difference between these accelerometers is that the KX134ACR-LBZ supports different G-ranges. The driver can model this by informing different scale to users. Also, the content of the "who_am_I" register is different. Add an ID and scales for the KX134ACR-LBZ. Signed-off-by: Matti Vaittinen --- drivers/iio/accel/kionix-kx022a-i2c.c | 2 ++ drivers/iio/accel/kionix-kx022a-spi.c | 2 ++ drivers/iio/accel/kionix-kx022a.c | 36 +++++++++++++++++++++++++++ drivers/iio/accel/kionix-kx022a.h | 2 ++ 4 files changed, 42 insertions(+) diff --git a/drivers/iio/accel/kionix-kx022a-i2c.c b/drivers/iio/accel/kionix-kx022a-i2c.c index 8a1d4fc28ddd..9fd049c2b62e 100644 --- a/drivers/iio/accel/kionix-kx022a-i2c.c +++ b/drivers/iio/accel/kionix-kx022a-i2c.c @@ -39,6 +39,7 @@ static const struct i2c_device_id kx022a_i2c_id[] = { { .name = "kx022a", .driver_data = (kernel_ulong_t)&kx022a_chip_info }, { .name = "kx132-1211", .driver_data = (kernel_ulong_t)&kx132_chip_info }, { .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info }, + { .name = "kx134acr-lbz", .driver_data = (kernel_ulong_t)&kx134acr_chip_info }, { } }; MODULE_DEVICE_TABLE(i2c, kx022a_i2c_id); @@ -47,6 +48,7 @@ static const struct of_device_id kx022a_of_match[] = { { .compatible = "kionix,kx022a", .data = &kx022a_chip_info }, { .compatible = "kionix,kx132-1211", .data = &kx132_chip_info }, { .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info }, + { .compatible = "rohm,kx134acr-lbz", .data = &kx134acr_chip_info }, { } }; MODULE_DEVICE_TABLE(of, kx022a_of_match); diff --git a/drivers/iio/accel/kionix-kx022a-spi.c b/drivers/iio/accel/kionix-kx022a-spi.c index f798b964d0b5..b20978afc565 100644 --- a/drivers/iio/accel/kionix-kx022a-spi.c +++ b/drivers/iio/accel/kionix-kx022a-spi.c @@ -39,6 +39,7 @@ static const struct spi_device_id kx022a_id[] = { { .name = "kx022a", .driver_data = (kernel_ulong_t)&kx022a_chip_info }, { .name = "kx132-1211", .driver_data = (kernel_ulong_t)&kx132_chip_info }, { .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info }, + { .name = "kx134acr-lbz", .driver_data = (kernel_ulong_t)&kx134acr_chip_info }, { } }; MODULE_DEVICE_TABLE(spi, kx022a_id); @@ -47,6 +48,7 @@ static const struct of_device_id kx022a_of_match[] = { { .compatible = "kionix,kx022a", .data = &kx022a_chip_info }, { .compatible = "kionix,kx132-1211", .data = &kx132_chip_info }, { .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info }, + { .compatible = "rohm,kx134acr-lbz", .data = &kx134acr_chip_info }, { } }; MODULE_DEVICE_TABLE(of, kx022a_of_match); diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c index e2e41dea9d9f..e3b47a6eac18 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -408,6 +408,14 @@ static const int kx022a_scale_table[][2] = { { 0, 4788403 }, }; +/* KX134ACR-LBZ ranges are (+/-) 8, 16, 32, 64 G */ +static const int kx134acr_lbz_scale_table[][2] = { + { 0, 2394202 }, + { 0, 4788403 }, + { 0, 9576807 }, + { 0, 19153613 }, +}; + static int kx022a_read_avail(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, const int **vals, int *type, int *length, @@ -1231,6 +1239,34 @@ const struct kx022a_chip_info kx132acr_chip_info = { }; EXPORT_SYMBOL_NS_GPL(kx132acr_chip_info, IIO_KX022A); +const struct kx022a_chip_info kx134acr_chip_info = { + .name = "kx134acr-lbz", + .regmap_config = &kx022a_regmap_config, + .channels = kx022a_channels, + .num_channels = ARRAY_SIZE(kx022a_channels), + .scale_table = kx134acr_lbz_scale_table, + .scale_table_size = ARRAY_SIZE(kx134acr_lbz_scale_table) * + ARRAY_SIZE(kx134acr_lbz_scale_table[0]), + .fifo_length = KX022A_FIFO_LENGTH, + .who = KX022A_REG_WHO, + .id = KX134ACR_LBZ_ID, + .cntl = KX022A_REG_CNTL, + .cntl2 = KX022A_REG_CNTL2, + .odcntl = KX022A_REG_ODCNTL, + .buf_cntl1 = KX022A_REG_BUF_CNTL1, + .buf_cntl2 = KX022A_REG_BUF_CNTL2, + .buf_clear = KX022A_REG_BUF_CLEAR, + .buf_status1 = KX022A_REG_BUF_STATUS_1, + .buf_read = KX022A_REG_BUF_READ, + .inc1 = KX022A_REG_INC1, + .inc4 = KX022A_REG_INC4, + .inc5 = KX022A_REG_INC5, + .inc6 = KX022A_REG_INC6, + .xout_l = KX022A_REG_XOUT_L, + .get_fifo_bytes_available = kx022a_get_fifo_bytes_available, +}; +EXPORT_SYMBOL_NS_GPL(kx134acr_chip_info, IIO_KX022A); + int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info) { static const char * const regulator_names[] = {"io-vdd", "vdd"}; diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h index 36e9d9de8c13..ea32fd252a38 100644 --- a/drivers/iio/accel/kionix-kx022a.h +++ b/drivers/iio/accel/kionix-kx022a.h @@ -14,6 +14,7 @@ #define KX022A_REG_WHO 0x0f #define KX022A_ID 0xc8 #define KX132ACR_LBZ_ID 0xd8 +#define KX134ACR_LBZ_ID 0xcc #define KX022A_REG_CNTL2 0x19 #define KX022A_MASK_SRST BIT(7) @@ -190,5 +191,6 @@ int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chi extern const struct kx022a_chip_info kx022a_chip_info; extern const struct kx022a_chip_info kx132_chip_info; extern const struct kx022a_chip_info kx132acr_chip_info; +extern const struct kx022a_chip_info kx134acr_chip_info; #endif