From patchwork Thu Nov 28 09:01:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13887803 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 AF8F714E2DA; Thu, 28 Nov 2024 09:01:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784520; cv=none; b=InMra2o4aueXzRcfTlv51i3CklznX39zr4QuBM4ymewFIJzL5zN/kiVAnvtu2/67H2XFv0OLsB+RhYaoc4qjOmcikThLyS+cqZtK93hBTzm2/BwuTA0RUaiDwB7Gug/1bG8YJNdCcjODAaZ3v6RiVopG/mEgPZgkXgTz07lrmw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784520; c=relaxed/simple; bh=9iAKaGh/DbLk003XwnkBukVNgkdYG557ngzrsYJV5+8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Gv6fIxVhOJdtP7+LK9K8aPJgmvcgGSme3CG3a3v0DRer2IZCQyJYYhsawxx+bxJY9SjeMEbY7PEEBQliKzWSffIhcU2bpfke+VXdE7/5Z12rw/iR2S9DHzKQVOoYRsRbqZSZUXSpLUWWbfzzshoJJcW5V5vc/o/q9/8hAtTcp3A= 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=l0A1PnIh; arc=none smtp.client-ip=209.85.167.48 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="l0A1PnIh" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-53dd668c5easo647442e87.1; Thu, 28 Nov 2024 01:01:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732784517; x=1733389317; 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=LbQqOlzyfbKc10JjBshjc/RutnEOn1xDG4DaodXmXpI=; b=l0A1PnIhj5I4iz/zNvrsAju4dbx6VFZ1Pz2QvHS3BvBo7F14A1JB3gpOp65h8pBHZC 7YnffSSwOCmcyGcWsuFyMTI/I6l3jxYUjtIjRF5A6I30ZHG1cWGlsDHIImj5eGHGS55A e7JbbFBMPhupGKoXZQrv0hBA6Nyk6eXbY49TITRKWPx1kp8wIVR8/gXFaa1EqbBxSN+D SChAku8QJu3OIEepp1Gr57xeVJX0uSoVro5B0MJP6PfoP4L+zDImBi0Q8EdDKZ/0Ft8s 2EBKO0kpSJFiGKT/X16Vmmwnius2eDTy4JO90C3Hal8wIexqPfXM1oZz1lGd7/A5HtYa O2vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732784517; x=1733389317; 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=LbQqOlzyfbKc10JjBshjc/RutnEOn1xDG4DaodXmXpI=; b=fumYOD+AZEEfacR+gqPSw5qFhenIick388JvKMGRKe7UbcawfSpWHb5c3GvLbl8WTr 3yTEEhPvM6KBR3Z90BmA4/5h/BYtrBVINbwArWi8BpTs8HeQvHs7BPaX8NN2ZM7DXY3b Fbb1zumFkPbEA4J/xW+a+32SAOFt/SbJeccZeT7ZHFHnufFptIFC01tyMzb7sjc5XFVE 6yzpxfP4+MWfuNRMf1y4a2eguaORmIEUtDEeZXWvYdrqh15WK4xReUw8gmCcmCPbnKBJ l5b7ATBug2GA0TL9sdJrTLtERnxkowZNuEd/SxpPAPtoF11g5nARDGinGPCgBEH6X0G5 sYMw== X-Forwarded-Encrypted: i=1; AJvYcCViuFGWDJbXvnPOQDBmCPwmsdHIM7jx+oIPddYLQFAzEmtpctlIiIlf/gV9IwDVDJGQDInbP/1GcoEtq1YX@vger.kernel.org, AJvYcCWILNDHekI6JnDRpii7sbQKPbrWJV1qurbwHy6lx7IfYNxZKxNyWqTaXxeCIKx/NV2MVx0BBgDoSSEq@vger.kernel.org, AJvYcCXmAZO2dWE9EXcIA/LHzeGSfr3SThnWl9ZARNbtNQaC4BORRsmt7YZI8BJnUDWmZcjTzHDCrZ2aL7ru@vger.kernel.org X-Gm-Message-State: AOJu0YzbnrJ1fY9CHfFbn/RTas6PZ9vj2LJCUY5MFgPLs1Nc88AVs+ej AK0ERRi5v+aHYI5Gj2hgv2weotLKIjM9kwyhICw5pqO4Vqnv/St6 X-Gm-Gg: ASbGncsOEZzWkgwFK2tgHO2y55VuVpoUBvcgJbrMsM11gWCKX9V9maLQXpUqZRVf3nX 0aweId8Hy8SjqaDjn+C1sjCJUpG3DAMFKpRFD/JBefFU4uoZrSudgpQH7M92D0DaMxaIsjbDS+/ ST77vTbZAs6AU0xKHbGP67l86UH0bo24notHvZdWcn6CaeEwgZWvwgGdC/IndwWjLcHxVq1xm9n BYbQwR1z5iHy7Nf3S48mojJh3tT6CBhnBkSqqwe6NohZcWnByNt X-Google-Smtp-Source: AGHT+IH7b7LC8Gj4Da9G3lVJLBr0b5tyTNivx9nqJbSGKQjXhyr7EugaEPgGYa4XTpFLOju08KI95A== X-Received: by 2002:a05:6512:2806:b0:53d:f7f5:bede with SMTP id 2adb3069b0e04-53df7f5bef1mr240716e87.25.1732784516450; Thu, 28 Nov 2024 01:01:56 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53df6496864sm115023e87.217.2024.11.28.01.01.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 01:01:54 -0800 (PST) Date: Thu, 28 Nov 2024 11:01:48 +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 v3 1/7] iio: accel: kx022a: Use cleanup.h helpers Message-ID: <4785f841ad5f131356ba78b4f3c76f676d86a2e8.1732783834.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: 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 --- Revision history: v2 => v3: - patch number changed because patches were dropped. v1 => v2: - patch number changed because a change was added to the series. - rebased on iio/testing to avoid conflicts with queued fixes. --- 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 b6664299e0d5..98953178a580 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 Thu Nov 28 09:02:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13887804 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 53C9652F88; Thu, 28 Nov 2024 09:02:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784546; cv=none; b=Fvf3YixDVCn8UuBgQaWIPHuMuY9BtMz0aLpW9bVRUozcaYH3jMBizeE9AlO87VZRShsXwVJn2GaQoidIJBDMXJd9Rt7ZhRliW4r0yILrldJ2cYAQt1m1Rri3Lid+87bHY9+LYLZfQwauQOiUHksOZb5BbvoQVNUCLLOWYlodYJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784546; c=relaxed/simple; bh=r/eeg3om9ivU0+M1FKxsElEgfHpj09dDPhesON/f1Vo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LMyFAOSI08Hy3U2rkA3iieQSN02MN+5McQi5RNscLTZyV9HHy89okax8NIqEy5h9EJ/tbD+MdznFLoEYlu1Ia4nN+KflXkXW/Jx6ksQkm5TMoJnYmvExtMtVCWjI85Q6AXycL7XgcKmp1q3NlXqIU9/xfEAXW/us8eujsmDGMSo= 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=MWwcxoj8; arc=none smtp.client-ip=209.85.208.179 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="MWwcxoj8" Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2ffdf564190so5540391fa.3; Thu, 28 Nov 2024 01:02:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732784542; x=1733389342; 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=JS8d/eTEBGERRIVkh1QG1hDjxDaJ+9ipo4AmlFs0eGo=; b=MWwcxoj896SBdHm019ej10eFf5Odg1ZO78tMvyNXnGIWfkCLiITCZLnUX91Nf2jRGF FA6R+QB0qvnm6c7AiqWZHJGCNbkvc5amVk1jOqPvd1BnXZFf8WisVaHNTecZKC6W/tql E30YoyZse4VgrW0r3ANr4KTCdEwSESSLhErI78h9TEgfweZx1Dh8oiwEfsmri0ElPwaL 9Sr9LR9yIW88d4sijwNT/kqmJgze5sbGNjXIZtG8NlMh7j3l2rPlCW2BD6BQ+dXq5Epd 1WeJ379fu+WmRv4m0BHIcSOKg//KQWUZE5wbAxQMqyOCHieIEC0BF6cydNqABKaLZHZC WNWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732784542; x=1733389342; 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=JS8d/eTEBGERRIVkh1QG1hDjxDaJ+9ipo4AmlFs0eGo=; b=O+7nHfyHUwrL76u7nclqwQo7jre9mn4p560MEfqBsbDZqBbW0t/EAoK+jtZCUXJDEq kkYv2wLSsl4CIFUi3t2T7C7s1Njre2LEghxgA9ug+mia2594Dyovli798WUoK/nu3Uys uV2b6kLct0cpRdj6AMj7FjqIuLT5KC8dPZYU05bmHnR7FJvoEFi5bEqbAwbZQjq81NKa ugvYiopug6NGEYcBlel9aSEvytPhTIszUt8JGD1Fs6PWs7vP7bgwcErlWdNYCbBT9V+M u/ItkfV51bwUwmM8+7gxZXMv/EXdkgrERr49FA9XixGyd7mgycks8WiYFCE1iTmHC/wk Ex5A== X-Forwarded-Encrypted: i=1; AJvYcCWYtawEWVjopVodx8TaW19Vf7trjrQz1gUUtbFJwazKpx5Mm1I9LHaLA17iQnx8T+HZNrDEWn4QDsbe@vger.kernel.org, AJvYcCWm/Bq6aKOyqdyjpdaMbUr4+RKtyulbghzAMg6sHE4PcM0rWZlGeyg/gCxA4r4Sym31GfhErPK1Dfmb@vger.kernel.org, AJvYcCXPlrgOr3AqW3Lr5ViMlF1Nm8EBIwhjS5uTk5v1lnZ4SUWLW1TS9cwu6+cWtkT9df0a/jW11COZS5Ch6bYU@vger.kernel.org X-Gm-Message-State: AOJu0YxxGDZBZ7g2/0JR8JgyKY4ARS9jji+zjQfUN7otaEN6tYfx/46o kLxskCQTQpfItyh0BCkXUrBNoL5BLT9D+2lLiAdlwyj+B6wOk/dj X-Gm-Gg: ASbGncvN2xmegqpDhsv4WNB8WxIVxsuVCyd2MbhdtFnFJxZUaNFhRAXlxm+iY8MiKRs o4HNLGcS/wsvb9Xs1xbd5Okgo2tku2iqGDZDeqM5D91oaeqdTZgiqNDexU4LDmWv38SjQbOkXfZ 6HmVhrlPTR8lrheizTkFA7d+EbQURxHWGxm0LKkbZHWQjbC7QzlPxZ64+wSjVDvNcBOtGk4Cmbb 8LaBqm9eNTZLHGJyKX/uXL3De2QUYDGv05XdvmQCRLkpBotXRfI X-Google-Smtp-Source: AGHT+IERYLeFqFfPV04lEE2WfX3aJ7m9wgmeo3ZuOuY/JPUNDf6zq9SQcQxYSBf9juZwJNHJKTVdWw== X-Received: by 2002:a05:651c:2119:b0:2fb:593c:2bf2 with SMTP id 38308e7fff4ca-2ffd5fcd5cemr32880701fa.3.1732784542031; Thu, 28 Nov 2024 01:02:22 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ffdfca2907sm1333331fa.110.2024.11.28.01.02.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 01:02:20 -0800 (PST) Date: Thu, 28 Nov 2024 11:02:15 +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 v3 2/7] iio: accel: kx022a: Support ICs with different G-ranges 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. 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 --- Revision history: v2 => v3: - patch number changed because patches were dropped. v1 => v2: - patch number changed because a change was added to the series. - rebased on iio/testing to avoid conflicts with queued fixes. --- 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 98953178a580..b23a27623a46 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; } @@ -1148,6 +1149,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, @@ -1173,6 +1177,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, @@ -1206,6 +1213,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 Thu Nov 28 09:02:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13887805 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 0EE2552F88; Thu, 28 Nov 2024 09:02:39 +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=1732784561; cv=none; b=pZIuAcrRYbfE6P4ZqtltAMN3uMGcu/jLNbCIEQvR1FoAn22mNcODXxts4TgtqFl2Kw6YqunqszfPew2uGqCGLa7akPqvKn0vFBG4MPS5t2ICYRCzYOZRJItPUi1kaTcPwPS9jJ24EqWkEYT1uIGlrJMULIX1gVeuDoeGgwrWYqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784561; c=relaxed/simple; bh=wogo9VGIJAygc2Sr0Tv8SWUOA4RuthVnDtCsa9yr6Kg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CrLjVnU0vyetbM7WUsYd1gGD+s1jMwQVSLIMvinZUf5W5PbvJ9FMOjKzm/4WXPN6VKebVHImsiY6zZe0LTOLDH+QBa2CSpSyKOhCPMBd7BB82JQ/QGTumDC0oiugcAxX65TLKiMiFmCJMI9XpFWOgsxMN/TyEKQtuHHt+HiDsNc= 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=NUkk9yYa; 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="NUkk9yYa" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-53ddb99e9dcso485210e87.3; Thu, 28 Nov 2024 01:02:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732784558; x=1733389358; 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=pkaT6GSi0h0USs77Nou+cNjAX2d6sAXqEVvVzHMrazM=; b=NUkk9yYaiVK/FQKlG3vvk8skYeyu2mlIDfEUZCaJrYUNgvx1np1fxUCR4kOVPQJJlV OHO2wRvPgKZYYaLC8fKpHYi/uLxvPDTcqP/CdJ5uLk9HQJbpoSeynXpDrLkgHkojmFHm 5fVf1nnv25BS72YW0kbRQN3u2Kzgu3m3LMseoAXOPIdpqKPpVsKhMYL8vJR8L0wxC56Q GR6KQCiWfjNHq8aIoGesPuozaMC72FqufA1VE4Fx3Nvw3ywk4CUZ/Q/wcCXhLCi+uc1D PaIKx7eTOa09rubUisYGKpCuKLqykIkygEZfMt6mKyMtRzwsjiVzM1uJxT8RYuJklcCY 4C1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732784558; x=1733389358; 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=pkaT6GSi0h0USs77Nou+cNjAX2d6sAXqEVvVzHMrazM=; b=lHEEKFTEsg/7D1phS+1u7ilk5vaKKzzny7Pu521K/X8ZoTlREZeCpg+yPrLSqNWBW9 u56Ijf0tpaIZyzKK8g+cZdkPsU74A2AYLuSeeDIhfYXbGnNpSvyXJ4xmIIV0sk+jtN7w JS0KFPP4Dzatu/d1px6YVGgBp6bC0RYI4FqoXLaGRRgGXUFLdmOrd9VJ+JZaDz7USw7D FE6uae29VQlC2cZe4LEIR3S1NDsGbL76Q9mEVxnOrsQRLLIdsphpTmqKnCk5eCw2J/zW KxOcY25VMBenELl+sIBQhBNKyhPLu8Zq83WBJ7A38cZ6W06eVPMup3FqKi6EoF2Qvw3w dgbQ== X-Forwarded-Encrypted: i=1; AJvYcCUFrkpzu8K+JRqwkHd2BlV3lfhEyYDSLdAL+Ykdyom1CkuQlxvT1dVxdj117WWahHH1LNS7Ny5WIRwO@vger.kernel.org, AJvYcCVmCi3Xz0lGsPkd0MrwjQpwg6dc0jhYZgxGQqgsPOIxeZXqnnGfHbI43UIzw+qiIUA2jAOG9BZOtAiSLsa7@vger.kernel.org, AJvYcCXc0gEJRs7OrO11ZmLofHRgMgAXoD5NIqOrssiM5GDO2uvbvEmDZsFswWEKzVN5Y7Sgj+sbRqVG/RAg@vger.kernel.org X-Gm-Message-State: AOJu0YwpMB4x/kAwwGEUfF3/sepSo7O/nlmV0jATa8jBfo91K1JYva7h kC57x3Eh+9oQJwLv90+PXGapdWbSjCnjep6u4KKhv4xsvXgT7K69 X-Gm-Gg: ASbGnctyTe5xN1A5R0V0d0p0dVtCTp2NWnxgYfnhUu3uglkqJoSSrrKoNkdwsuATKdR 34jl391yAUPeKfRG9uxZ7AlOVtg6BuYnMCZH2k+fTG6yplzxpvIdshONrpA6nMifOGA21cyuoMT 0eWbifM1+VbYwIgSeWmowwpqOZmy2gAoxD9SaSHJ1nmsLfU6pwpxPLdoVhCBJp96D7CJm7lWFIU UBKhqqKt1Y/dN0hE1JAyc54ptVBGE+hav/oBWsAmgU3kCnBNsuG X-Google-Smtp-Source: AGHT+IGLT+OKjkl9lcTLnLsX6TsK+HNSFvnOVrxJ9IZlF/dGdG3pyUlg5ez9GA9aFKI6XkZMMUF3/g== X-Received: by 2002:ac2:4884:0:b0:53d:f0ff:d244 with SMTP id 2adb3069b0e04-53df0ffd256mr2534506e87.22.1732784557955; Thu, 28 Nov 2024 01:02:37 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53df6449d7asm116544e87.107.2024.11.28.01.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 01:02:36 -0800 (PST) Date: Thu, 28 Nov 2024 11:02:29 +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 v3 3/7] dt-bindings: ROHM KX134ACR-LBZ Message-ID: <2efe2bf7078704be3f020663960fef563ab21aca.1732783834.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: From the software point of view, the KX134ACR-LBZ is almost identical to the KX132ACR-LBZ. They, however, have different g ranges and ID register values which makes them incompatible. Add compatible and information for ROHM KX134ACR-LBZ accelerometer. Acked-by: Conor Dooley Signed-off-by: Matti Vaittinen --- Revision history: v2 => v3: - patch number changed because patches were dropped. v1 => v2: - Improve commit message by explaining why compatible is needed. - patch number changed because a change was added to the series. - rebased on iio/testing to avoid conflicts with queued fixes. --- .../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 Thu Nov 28 09:02:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13887806 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 28BC6154C17; Thu, 28 Nov 2024 09:02:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784577; cv=none; b=VTKVM8GU1Y0FD8BzC+1bUgp8rqT4mVU0ksv7XdEGDvc1yWgyCVYPq2xg47xi6uZ39YEPO5t5rKr9RyYLfRO1p/8WEfMKnl9O2XMpWbDOVLo2xm4qx6/ITZ1+rdJR91ffpA1lRVlFdBBEwVdOrw3dtUluitgPh9u39cSnr6OhDSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784577; c=relaxed/simple; bh=fjW6D3iIw02hXTHuiiDDX2Yp1fZBRd7dCiCdiiPOwF4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PFo618fOB5pMMv0O7cMOdLKi33TcDWyMcUNBB6p1qHr1IiA2yP0RUhS4gx4f3TW9xT/jXD2MKy3kmdBhntnhw8vh5xV0BWgdIeFkycM3PBO75aPk+PJcXBe3yvsvWcIxcuiu9tjqtMDe7ZJnGsxmqkA5aPonHe2SkObfBwvv2Zg= 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=njdC85wN; arc=none smtp.client-ip=209.85.167.49 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="njdC85wN" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-53ded167ae3so685665e87.0; Thu, 28 Nov 2024 01:02:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732784573; x=1733389373; 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=oF/+3kCu9KXAtvcNzSgI4p1+vhLomCHXaKzHdk+jh3g=; b=njdC85wNgN9horKL3nIE/ItdKVWjF4akocO4DqJKjAB6fQXzr8vu4BZUVo4yAdsMMo i/C9q+Li+cwc17wdh1Y7cfKfB5t/sW+uxBw6R8sKi9kcYRhISlZ0hHqSsa/u+ve5IkuM lRNx+t6fQ5JQgnyErkixUmEwLgpgmNVvAdXBoCEuh2/F1Xk5HH3tX6QFNVCxNCQGyzZx 5V7uJ8E1ahtUEiRTbHa5VT2Egbeek2YemJdORiAs0QJKMYpLp8ng1NKUffgKySr1Ilz8 Hr+g63CtlGDraV46QlJ1Zdv0HN+gkzxXDGur3ez9kv+I+mSFEl0YYwW0RiOpljDRdn5W 0AeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732784573; x=1733389373; 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=oF/+3kCu9KXAtvcNzSgI4p1+vhLomCHXaKzHdk+jh3g=; b=Ppf5Y1tdCBWhXIDIto3fI/N0eWDMWt5GX9rWNGh2QZsCBFGoYViiXoMc58S/dc8X/l Mxum82rOUICww16tEQJ+qoCSSldBmKlsasCKYc9iB3wXqxL+CD++S2Vc9XERdOBTlDbs a6qApV52SufBM1bGZtVcc0tbg9TSrIrm6bPjOlj+Bptn4ufHbGLtqpeR41q0U82yRiUx PsdgoIOUX49CPI1z1+BsF5Ksuk4gn5y4zmy6AXmCKcx8d6nknpw3xAp2LI1gHkFlxOIP 88Javib2bBYczxHMxjexlaTnhRvLYbaFtiztwfZ5FnyVdWL6dl7o7cfotw8Iq8MbntQH qAxg== X-Forwarded-Encrypted: i=1; AJvYcCUuEuXmMEmT98LwjAIDP4G48UK+8nRD6FQv2H79AQKD40jy0EWCueYWpQqFoudQ09XeNMAskm7DX/3o@vger.kernel.org, AJvYcCW7cs7IexyeavvS0gTFhTGi+/kBUJvgkFCLLHF/+5iSt/Z8WGtfYK3U2/WTEU6mqlTpk6kb0BQsQr89m+wD@vger.kernel.org, AJvYcCWLPSGNUVWeAulKVvHrww9ODGzDzYwe7Tts134uGCL/u+AhIqzqX1cIBv9gNaBhwaqFdRYxdXLZ4ViD@vger.kernel.org X-Gm-Message-State: AOJu0YyFHRQ53G7kwSU+FKdTfuk+cWorC9xQu2T8OkJFC7LklgHyUMOs WfLE0eUmzjiKcY1jt6QNGGzRMqRtFZWj6usruuU5ttslFMtCzszI X-Gm-Gg: ASbGncvxWRuxuEYk4XU/a1yAeZHg/05b/bQGnIc+ab0i8VGXyZnHYg4/q5105PeZtrz R2s/V9fEWOoaslCM6vo+ootRVRVyBCsVBXKgBj5nTz3KPu/J/M69ztZOyiSvouBmOL1bza5YjVJ 03bxlXOup0jqyk1KYYF8ZkvjKCyIaDp+pbnX9W62lo0IydRr/EnTzIsQlXHNN7AtCqC/5XGcMmX g607PKnL39rala0pJYxWfvEfvSe4Pzhz0Izkh2DVEIiTr9scBff X-Google-Smtp-Source: AGHT+IErq4imRX3wLkkf5SH9n7pslkqAr9BpQxDOICuCh4OpJMn9bEk6NOCRZ3vHCt+KUJimkXQeKw== X-Received: by 2002:a05:6512:32a8:b0:53d:f09e:99d3 with SMTP id 2adb3069b0e04-53df09e9a97mr2590488e87.0.1732784572968; Thu, 28 Nov 2024 01:02:52 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53df6430e74sm118560e87.9.2024.11.28.01.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 01:02:50 -0800 (PST) Date: Thu, 28 Nov 2024 11:02:45 +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 v3 4/7] iio: kx022a: Support ROHM KX134ACR-LBZ Message-ID: <27c43c595de1f3f698ace671922d4f5a48c3cd54.1732783834.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. 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 --- Revision history: v2 => v3: - patch number changed because patches were dropped. v1 => v2: - patch number changed because a change was added to the series. - rebased on iio/testing to avoid conflicts with queued fixes. --- 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 b23a27623a46..9fe16802c125 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, @@ -1236,6 +1244,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 From patchwork Thu Nov 28 09:03:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13887807 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 5C0901547EE; Thu, 28 Nov 2024 09:03:12 +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=1732784594; cv=none; b=fv/KWGHMrAa9QXyR5SwPZ57jmCc6/hqj79OXqDvVgsArwenKIUz/hynL5MGgi7jrDwIsqcmtSvl6cx36ThLoG5y8DgztcF6QCbmMF/eApkmZIyWM8CxVVfDFr9xY3f7/plTbmNdbEUuEuNu3jUSULQqeA5OqaeRaGuwZeGnXrso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784594; c=relaxed/simple; bh=iAQrajyZwAKlx0GJCBgLYQqerCJHLKdAJsNL5fRH1EU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OAlGSo9v0CiPQiT82rWXdQ+5SpBJXVP5HoHQc38n0sKiyGiKZ0e9F/SeoYj8mJuhvFdYtdCRPPhD5HQ//K5HN6u9vq4epM/B9I888Ow8Xytb09bJWkL6AOyOTMMhNeqaOAKPOlNVptRw+IcFwEtusdBTK/vVsjmc/61XqHbMkVs= 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=LIBYsQPD; 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="LIBYsQPD" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-53de79c2be4so563846e87.2; Thu, 28 Nov 2024 01:03:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732784590; x=1733389390; 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=lfhFYuYieXmvJXDGOA9mP/3xPmE5z5AUMkwtuYyYGmw=; b=LIBYsQPDDH17CjkRxsPsmLv8OTg6QYYZy30POkMCO6YV+2PgD5GKfP9hJQ/LQWsAUZ H9HIFyU87uKoZfZTMqa8WeCm+ksmb5Rbh5eIpcvo0r45NWTriBxN3gZQOvEptGD6AT1V 0PYY7p3oE395tManixYTH14dCh8ddjKhaX1BvrhsNiMiKJBoZxqwPhiSkH3pRo9eFLd7 NEIy1ZJYOOdbiDcwjCty4bgR1522BmZ/W3anInaRBM10if593ipTrVmU3owcfmc5kGih v1XVL6dpV8Pum0JpcQF/Tv/qQjInG3CNBCqbV+AE0jotsQTql9fWDVvIBNaJkvFd6YJe X97w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732784590; x=1733389390; 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=lfhFYuYieXmvJXDGOA9mP/3xPmE5z5AUMkwtuYyYGmw=; b=LECE/wova1hgnNWJYj6VIrH19MmEckhx/cKFyxjj/nKAuLfT2zeZBby3FJvPM5Ybaq HKbcy4z9EImMET8+5PxKdsfTNJcsYa/dT86qkNqPm8hnYLtNLGGhANS6hCrM+PYW4vLY DFtkdATKWIsugSRHoXNakRLtww9h/LQCCyN7Sst12j8xxwC6N35X4vkLqQNPwHXvhf// pfIszbOugMR1ReAplGRbAsco2d1mTj75YCrSdVcYdLrR+rpmcF4h7QhZEy+rCEYD9Vz8 Q7dYhLTiRKUK44hVLvZhRHIHr+cfEYGue7zxyisIB5igOfLhBvKQawriFeAR0gIRFIL8 7L9Q== X-Forwarded-Encrypted: i=1; AJvYcCUkHHDqVWDU++VNl3YkRZ/HtPCalElhU+XFA8mi/UvUNex7TtzxEszhwwYbRqftZyIAXN/6E9xJtpbJ@vger.kernel.org, AJvYcCUtEWExq4ZyyL7K/NEFz8ktBeeQ3OoPQLNDzUf4XXk18R0C4TgIRB8h9CILBomTCC3BKSl2Ezhgf3F9GfyJ@vger.kernel.org, AJvYcCW4NTTPZ6Wap3BhadlTHJjZ1dyVeV/OLRGjwlm78TgovvnbX8aVIiBvIuRW4V4nvFpKk45qYgVMuv8F@vger.kernel.org X-Gm-Message-State: AOJu0YwSRn+Kf6ihqpyPQcoRE6LZJacK76lY47WxPQ71TrgNjLnJY0w0 rdZSW+tvtcOGrkBE4CIe+x2tl4U3njI6470IQzVqHA/NiWXF9Psu1I1ewA== X-Gm-Gg: ASbGncvNsZ0sAfFlpJbOWMPGOTdnKxs+eMfk8VSTa8ac45qoXhOiq5b4/ZUz5Hdz1Ld Q7pZcqcSt8/XdrPbVzNPUmr1NfsSKkJdvHk0vUWXUHpxc6W4JrGVZDh5mcWrTq61leYLcM5tgBF ASmWd3GUiJYIKzLExs2BlJIWfw7T2vBsAyMlGhZxbbr5FptrErRT2b54pJ6BOAxV+llKaXrcm6g tAGTw+s7lY/X+bnAyJckwE2d33T6N59loYpOpMzNp9GSU16dIfk X-Google-Smtp-Source: AGHT+IEWEZPLwI4fPFTskvYqirjFAckRCvq1D6tvPFe2z73gUpZu4Bod6skEOn+aYKVpRCH1gy7cpQ== X-Received: by 2002:a05:6512:690:b0:53d:eec1:a03b with SMTP id 2adb3069b0e04-53df00aa172mr3631254e87.3.1732784590213; Thu, 28 Nov 2024 01:03:10 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53df644aa9dsm117739e87.110.2024.11.28.01.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 01:03:08 -0800 (PST) Date: Thu, 28 Nov 2024 11:03:02 +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 v3 5/7] dt-bindings: iio: kx022a: Support KX134-1211 Message-ID: <48b50cbda3d6c3a58a7b7c9ff23ed4dc7f418a5e.1732783834.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 ROHM KX134-1211 is very similar to KX132-1211. The main difference is supported g-ranges. The KX132-1211 can measure ranges from +/- 2g to +/-16g where the KX134-1211 supports measuring ranges +/- 8g to +/- 64g. Support the ROHM KX134-1211. Acked-by: Conor Dooley Signed-off-by: Matti Vaittinen --- Revision history: v2 => v3: - patch number changed because patches were dropped. v1 => v2: - new patch. --- .../devicetree/bindings/iio/accel/kionix,kx022a.yaml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml b/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml index c973f4941a6d..f07c70e51c45 100644 --- a/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml +++ b/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml @@ -4,23 +4,24 @@ $id: http://devicetree.org/schemas/iio/accel/kionix,kx022a.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: ROHM/Kionix KX022A, KX132-1211 and KX132ACR-LBZ Accelerometers +title: ROHM/Kionix KX022A, KX132/134-1211 and KX132/134ACR-LBZ Accelerometers maintainers: - Matti Vaittinen description: | KX022A, KX132ACR-LBZ and KX132-1211 are 3-axis accelerometers supporting - +/- 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. + +/- 2G, 4G, 8G and 16G ranges. The KX134ACR-LBZ and KX134-1211 support + +/- 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. properties: compatible: enum: - kionix,kx022a - kionix,kx132-1211 + - kionix,kx134-1211 - rohm,kx132acr-lbz - rohm,kx134acr-lbz From patchwork Thu Nov 28 09:03:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13887808 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 62ED414E2DA; Thu, 28 Nov 2024 09:03:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784609; cv=none; b=j4WGx6Fb8UngIAJ23zewjbfWEu9qiMSuxI7x1waaK8O0WdVAJk9ccBRmQx4Lc4G16j4P/imJ3z63XLXCV/vnir2uZDatwIz3NKXiqCeM+SCu9owDL9RhR45svnfJRdmsoyQrGvEWQk2gaOrM5yybA/eCyvVUxNzwvVXA1Dvw8V8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784609; c=relaxed/simple; bh=BozK0bq0GagTzyJ41FfQ1odVfcFYg553FMs4RIHWzos=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uHn4g51Gl0TWr+FFuSC82D/ErrFmt7Cx+HTvZaaEcM7MP9scGl4qp4VIC0lnNpKUXdWBeaTPvsqOE1NnMhRdSjbGmDkwuaWbC7nq6XXdMWHz6m1sVUI5uH9getpiQhjDyXU2qeUnMSW45uAzNeJE5lvKRQVkgenPpZ0E9frKm/4= 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=iB7yISXa; arc=none smtp.client-ip=209.85.208.175 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="iB7yISXa" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2ffa8092e34so6574191fa.1; Thu, 28 Nov 2024 01:03:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732784605; x=1733389405; 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=UhDJcJyfVDqNgtZQFZmRTeTfoWRpV0TeVifUOwYfPdA=; b=iB7yISXa7ZdyHfRUaFnjKGETM5xg1kSpe9WOOra9CU7N0fco5Kqdlx/Nkt37ShCxFE Z2KEf8fR1fGb1UF8fc04j7hrX5L38LoVUTM7xxR/70S2fX6Lmmv6igbluy/4ZxwXS+cA F5nqKvY42JPvabWOc3LSFBZyDnu0P2H//1RormorMfhQ8qhUzpAJev/oCqW7/756KYFu 1i4Lb4o4iFbrNILAJzu5ZeYYYVpqz1F/VPUKiiWYngrT7Z7ONC4SjpOs6JoHmzJk19Ne lURtEecRfYAG/jwgDvzBc86US+jyFpt2nb7Qmgm3GdSehXPByVBpn+MXwmUJ71zlqZSo HgcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732784605; x=1733389405; 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=UhDJcJyfVDqNgtZQFZmRTeTfoWRpV0TeVifUOwYfPdA=; b=g1inseTS4+oZuRIE2sS+AQy2wtNuAiWVWRNg4k9e8HI639KlFgegQH7+2bdFyU2BN3 hdWu2pofDKPVEPllnaLk6u+Zgxyn1nd8qr8EAxwghzV0cYqhNfk/9oFI+NvEPLDsy9W1 wj6jdpi0p206mtvHoYQvEQeFGkS33WTiOKbgQsW/XHRiWmPrd4SgPn7slD9R/2p1VxBK CubCg6xGCxqyjI2NQWJlsndFwJrFaz4xRswydHw93iPVhDhxm26oRtQ/VHrveSq7Xdd8 G6Gnz71iME10p6jHtPg6jOG/JRqefMFCXJTFOCmmhyqz8z5m59aZkLnNuhxTtJ/H1RC7 iJYg== X-Forwarded-Encrypted: i=1; AJvYcCVWG/jjjEHQBIR9V0Atflw85PABG0/RPT2337NwcjKkNJVsbGOZ+0jpl8Z7t3pIV3hjoOXEs6PH/KjoM/Xx@vger.kernel.org, AJvYcCXRlCjsE8mgQpDoobCXVu1oo63Wb5a/OPm9OLw+6ikSd5hiZBUqGWQaPQJPRggY9k+up62XQXf90xVF@vger.kernel.org, AJvYcCXjb9eAGDhVNAPbTpZFN0GGNjgyl+ZQ5TN5Rcz2M2zDwvRoQSSLiDbatQun8jvKGZK4kjRIGjdrnfur@vger.kernel.org X-Gm-Message-State: AOJu0YyRBbdpaOmHbfO18aMQuUNuczK2kIYViVMR1aPRwfCAFycP6R/t tS6ULWe3xOqeiJImcuDOUedPCCyryrDYvv4SEQX84WoeV7ybm+is X-Gm-Gg: ASbGncuT9UB7H5lvMGAucz4uLs1nnLJfd8Gt7LwcpZVlHgSoY56v+AlllcdrefDh1JB 3BxAoX/jmI2VXzC0Te0XKCFa50kl3jcpy+kEVq8Jwbqx2TCOoNd2++Ck86JJ2Ow1/FEYPQ0MALl qHByPxUPik/sZ8Oyeafhg64285Vwet5BB2FmuuCdhnZVMAMeau3SEzlsZiy0FJuHydudzJbczoP VtSjIc13sOC71n0aU7LWMYsgL49bXTypfucbTdUxc8KsXORKvfH X-Google-Smtp-Source: AGHT+IEd31/l4Hn6iVqfw/sNeigPCk4lTB2+2SQj9dPA4fH+L/MtoSg1LKaHziMq7LvtIzr9hbZplQ== X-Received: by 2002:a05:6512:3d04:b0:53d:de69:debd with SMTP id 2adb3069b0e04-53df00d05ecmr3750528e87.17.1732784605315; Thu, 28 Nov 2024 01:03:25 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53df6430cbcsm117127e87.1.2024.11.28.01.03.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 01:03:23 -0800 (PST) Date: Thu, 28 Nov 2024 11:03:18 +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 v3 6/7] iio: accel: kx022a: Support KX134-1211 Message-ID: <6e95af6b425df6a5ff5218825ec8923f1341f7c3.1732783834.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 ROHM KX134-1211 has very similar register interface as KX132-1211 does. The main differencies are the content of the "Who am I" identification register and different g-ranges. The KX132-1211 can measure ranges from +/- 2g to +/-16g where the KX134-1211 supports measuring ranges +/- 8g to +/- 64g. Support the ROHM KX134-1211. Signed-off-by: Matti Vaittinen --- Revision history: v2 => v3: - patch number changed because patches were dropped. v1 => v2: - new patch. --- drivers/iio/accel/kionix-kx022a-i2c.c | 2 ++ drivers/iio/accel/kionix-kx022a-spi.c | 2 ++ drivers/iio/accel/kionix-kx022a.c | 30 +++++++++++++++++++++++++++ drivers/iio/accel/kionix-kx022a.h | 2 ++ 4 files changed, 36 insertions(+) diff --git a/drivers/iio/accel/kionix-kx022a-i2c.c b/drivers/iio/accel/kionix-kx022a-i2c.c index 9fd049c2b62e..7359073ae0c0 100644 --- a/drivers/iio/accel/kionix-kx022a-i2c.c +++ b/drivers/iio/accel/kionix-kx022a-i2c.c @@ -38,6 +38,7 @@ static int kx022a_i2c_probe(struct i2c_client *i2c) 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 = "kx134-1211", .driver_data = (kernel_ulong_t)&kx134_chip_info }, { .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info }, { .name = "kx134acr-lbz", .driver_data = (kernel_ulong_t)&kx134acr_chip_info }, { } @@ -47,6 +48,7 @@ MODULE_DEVICE_TABLE(i2c, kx022a_i2c_id); 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 = "kionix,kx134-1211", .data = &kx134_chip_info }, { .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info }, { .compatible = "rohm,kx134acr-lbz", .data = &kx134acr_chip_info }, { } diff --git a/drivers/iio/accel/kionix-kx022a-spi.c b/drivers/iio/accel/kionix-kx022a-spi.c index b20978afc565..50aeaafc56ec 100644 --- a/drivers/iio/accel/kionix-kx022a-spi.c +++ b/drivers/iio/accel/kionix-kx022a-spi.c @@ -38,6 +38,7 @@ static int kx022a_spi_probe(struct spi_device *spi) 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 = "kx134-1211", .driver_data = (kernel_ulong_t)&kx134_chip_info }, { .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info }, { .name = "kx134acr-lbz", .driver_data = (kernel_ulong_t)&kx134acr_chip_info }, { } @@ -47,6 +48,7 @@ MODULE_DEVICE_TABLE(spi, kx022a_id); 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 = "kionix,kx134-1211", .data = &kx134_chip_info }, { .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info }, { .compatible = "rohm,kx134acr-lbz", .data = &kx134acr_chip_info }, { } diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c index 9fe16802c125..e3986dd65337 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -1209,6 +1209,36 @@ const struct kx022a_chip_info kx132_chip_info = { }; EXPORT_SYMBOL_NS_GPL(kx132_chip_info, IIO_KX022A); +const struct kx022a_chip_info kx134_chip_info = { + .name = "kx134-1211", + .regmap_config = &kx132_regmap_config, + .channels = kx132_channels, + .num_channels = ARRAY_SIZE(kx132_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 = KX132_FIFO_LENGTH, + .who = KX132_REG_WHO, + .id = KX134_1211_ID, + .cntl = KX132_REG_CNTL, + .cntl2 = KX132_REG_CNTL2, + .odcntl = KX132_REG_ODCNTL, + .buf_cntl1 = KX132_REG_BUF_CNTL1, + .buf_cntl2 = KX132_REG_BUF_CNTL2, + .buf_clear = KX132_REG_BUF_CLEAR, + .buf_status1 = KX132_REG_BUF_STATUS_1, + .buf_smp_lvl_mask = KX132_MASK_BUF_SMP_LVL, + .buf_read = KX132_REG_BUF_READ, + .inc1 = KX132_REG_INC1, + .inc4 = KX132_REG_INC4, + .inc5 = KX132_REG_INC5, + .inc6 = KX132_REG_INC6, + .xout_l = KX132_REG_XOUT_L, + .get_fifo_bytes_available = kx132_get_fifo_bytes_available, +}; +EXPORT_SYMBOL_NS_GPL(kx134_chip_info, IIO_KX022A); + + /* * Despite the naming, KX132ACR-LBZ is not similar to KX132-1211 but it is * exact subset of KX022A. KX132ACR-LBZ is meant to be used for industrial diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h index ea32fd252a38..142652ff4b22 100644 --- a/drivers/iio/accel/kionix-kx022a.h +++ b/drivers/iio/accel/kionix-kx022a.h @@ -78,6 +78,7 @@ #define KX132_REG_WHO 0x13 #define KX132_ID 0x3d +#define KX134_1211_ID 0x46 #define KX132_FIFO_LENGTH 86 @@ -190,6 +191,7 @@ 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 kx134_chip_info; extern const struct kx022a_chip_info kx132acr_chip_info; extern const struct kx022a_chip_info kx134acr_chip_info; From patchwork Thu Nov 28 09:03:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13887812 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 45FD8143C5D; Thu, 28 Nov 2024 09:03:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784632; cv=none; b=mJnfa9TP64TcpwOZz4xkf1KHkfRoZNAvTd7xl0AorxFZFxb/I9GUMAMbx3slz0FNFAXQe1qPeSS1EeXPyFr8RIEWApvNbhjQ/iAWrhbzFhi2lR3znVRLO9qnmWb0DsyxbN7Dpbk0TOrhJDOfSBlIPtd4x5LgDAw23O6xlROoZnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732784632; c=relaxed/simple; bh=IaKwCAviFT17kCDoPb1NhuAN6iU0GIhtG2w1ksZ6gnM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TVS7Eqoa4oMyh0lVCnRPVzft8maOVQERmDm7ApOHOX/PHslX9d1smzeIvIYDIbS5ZEkj+bE+L2piyaDDfjMRPpWhih5a5xMkDZ9OBknSuHu4eEtgfxGqIwLkQ6t2kRg2D92b5tEU+nX95hddDEBiyVFAx780RdLzUn2uyOheIFU= 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=fascyJ+A; arc=none smtp.client-ip=209.85.208.178 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="fascyJ+A" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2ffa974b2b0so6001541fa.3; Thu, 28 Nov 2024 01:03:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732784628; x=1733389428; 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=Xfeu9TZePGwuuY0/7mH2oC/puuOE3ENCwSxH44663Nk=; b=fascyJ+AeG9/iFeXcAl46evg0kuBPJertPR7MNR3FneGMKKlsXpUB8S6Mw8GLsPwvh R390U2w8BLdq67bmrL46ISvoQlPZHtrEgj/rhWKd2ujO4FRY4TUGDDzUFReyhpLiJRLT Q/kc7c5xryzFsdJ417Pynj7UhxEpK7YjjVyQ9txhP7TTdHmdjN5ip34deHtEOfztKhZS z9QoeD+Rvxt8xGKm/Qc28x/tzz1wUXCTs+/dYMILZyxu7LWwnsSKjY63EwFT8a872cqh B5zDaDOOpZWRxQDiyJXwUt7/LnPbkBbOTPq7Z0RPon7DNTwOAT40XzH+BgrQVe5pEhYt dOZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732784628; x=1733389428; 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=Xfeu9TZePGwuuY0/7mH2oC/puuOE3ENCwSxH44663Nk=; b=qBgXU7St82RJWjAZEgMNPkMnx46R7vj/C4Lf/yyhtvYk19XSxmNuKwfWXU/G4Oanq1 tF8UW/hPU+qW6HUd6ynSP5HJF5d4vmzs1N08K9r/PJjGdrDT9L2RF7AoQArVnWCap+j4 UOJIXb+pQCy6BGsdhyqfxn4lfMt3WvzPcRMiW4NcgmEoRLpEpzI/jNJhiFyzsP9B6ON7 39LLV9Eygu1swCWfEakOnYm1kh4/bpvGyor9wJkY+ua0LXytUrxBjgBnBgDJzlu8k1iD kriQoSSyIalPqD0YxakxFbm4quDoZw2o6oLsqNXUy24QvN1JGftZvV/F03GXfGtxn/EM gnGQ== X-Forwarded-Encrypted: i=1; AJvYcCUpfuJvspSk26R/YKSFCxlR6HK1soa1amW2kUcWrppwoXb8mEbNcTI3cCSe1WVmHdlA/gpODX9/aify+S+F@vger.kernel.org, AJvYcCVSjAgJJujrnxXVH8CpPgSx7mh3A9EShkN2WwIOJrlcD/Fb0Ua+CTDYs/VPLuA1AWH5ecLnCRRcnE56@vger.kernel.org, AJvYcCX4oJKtZ4P+SIWOnxQlz8D8mDo+4kG/hf0zt3wXdiBzjo1OLABjID6nSOIYw/qPBBtJz6vxwOYI2Rzi@vger.kernel.org X-Gm-Message-State: AOJu0Yy00OUWz6tdIL4V48nsl5OOkQbWzJkhhFAIIL/mVlue3uEaYVG9 luu8G3PPvULOTasTVxI/qoNpGU0T6bCgKMpv59ldMuw/Llal33NE X-Gm-Gg: ASbGncu27h2+HT52vPfH13AvGKiV1gdm+mMQQWvsHZNgnwI3G/+fCWIdIGsKBHKVhkL eLy0fO7rdXVU9V/y37Io76uIymu4ppmuH1w8M69LHKPpZ0bgpYuzjVNsA1fTey/Rp50g3d9yy7H X/N7MlX+7ONoO0f2Sakq7YVj+CXWtBDYCs+0IDiz/XaYntrmetUWW241XgHqFLDF4O7j3jFUllq QlIAzOfqOQxbTfZKbFbJ8YVZfhSrMJsSEV6aAC/tA/PdrU7PslF X-Google-Smtp-Source: AGHT+IHCL14oIGUcWNrPBgY/h8Q75ld14hsP3N5seAHgRcLOoorWjcaDTqttv4CePWd0hEPyyQ7Cig== X-Received: by 2002:a2e:bccd:0:b0:2ff:c69c:db0f with SMTP id 38308e7fff4ca-2ffd6130ae4mr37338731fa.34.1732784627759; Thu, 28 Nov 2024 01:03:47 -0800 (PST) Received: from mva-rohm ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ffdfc747eesm1337841fa.76.2024.11.28.01.03.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 01:03:45 -0800 (PST) Date: Thu, 28 Nov 2024 11:03:40 +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 v3 7/7] iio: accel: kx022a: align with subsystem way Message-ID: <9b63813ecf10b1cd0126cb950bc09514c4287b9a.1732783834.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: Many of the Kionix/ROHM accelerometers have a "PC1 - bit" which enables the accelerometer. While a sensor configuration like ODR, g-range, FIFO status etc. are changed, the PC1 bit must be cleared (sensor must be disabled). (See the description for different CNTL registers [1]) In order to ensure this the kx022a driver uses a mutex, which is locked when the PC1 bit is cleared, and held for the duration of the configuration, and released after PC1 bit is set again (enabling the sensor). The locking and PC1 bit toggling was implemented using functions: kx022a_turn_off_lock() and kx022a_turn_on_unlock(). Based on a discussions [2], the IIO subsystem prefers open-coding the locking with scoped_guard() over these functions. Drop the kx022a_turn_off_lock() and kx022a_turn_on_unlock() and use scoped_guard() instead. [1]: https://fscdn.rohm.com/kionix/en/datasheet/kx022acr-z-e.pdf [2]: https://lore.kernel.org/all/20241126175550.4a8bedf3@jic23-huawei/ Signed-off-by: Matti Vaittinen --- Revision history: v2 => v3: - New patch NOTE: This patch uses the if_not_cond_guard() which is currently missing the iio_testing. https://lore.kernel.org/all/20241001-cleanup-if_not_cond_guard-v1-1-7753810b0f7a@baylibre.com/T/#m69982b23da9f71e72d84855b34e9b142cb3a1920 --- drivers/iio/accel/kionix-kx022a.c | 121 ++++++++++++------------------ 1 file changed, 48 insertions(+), 73 deletions(-) diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c index e3986dd65337..a34cf8da2860 100644 --- a/drivers/iio/accel/kionix-kx022a.c +++ b/drivers/iio/accel/kionix-kx022a.c @@ -458,7 +458,7 @@ static void kx022a_reg2scale(struct kx022a_data *data, unsigned int val, *val2 = data->chip_info->scale_table[val][1]; } -static int __kx022a_turn_on_off(struct kx022a_data *data, bool on) +static int kx022a_turn_on_off(struct kx022a_data *data, bool on) { int ret; @@ -474,28 +474,6 @@ static int __kx022a_turn_on_off(struct kx022a_data *data, bool on) return ret; } -static int kx022a_turn_off_lock(struct kx022a_data *data) -{ - int ret; - - mutex_lock(&data->mutex); - ret = __kx022a_turn_on_off(data, false); - if (ret) - mutex_unlock(&data->mutex); - - return ret; -} - -static int kx022a_turn_on_unlock(struct kx022a_data *data) -{ - int ret; - - ret = __kx022a_turn_on_off(data, true); - mutex_unlock(&data->mutex); - - return ret; -} - static int kx022a_write_raw_get_fmt(struct iio_dev *idev, struct iio_chan_spec const *chan, long mask) @@ -526,9 +504,8 @@ static int kx022a_write_raw(struct iio_dev *idev, * issues if users trust the watermark to be reached within known * time-limit). */ - ret = iio_device_claim_direct_mode(idev); - if (ret) - return ret; + if_not_cond_guard(iio_claim_direct_try, idev) + return -EBUSY; switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ: @@ -538,20 +515,20 @@ static int kx022a_write_raw(struct iio_dev *idev, if (val == kx022a_accel_samp_freq_table[n][0] && val2 == kx022a_accel_samp_freq_table[n][1]) break; - if (n < 0) { - ret = -EINVAL; - goto unlock_out; - } - ret = kx022a_turn_off_lock(data); - if (ret) - break; + if (n < 0) + return -EINVAL; - ret = regmap_update_bits(data->regmap, - data->chip_info->odcntl, - KX022A_MASK_ODR, n); - data->odr_ns = kx022a_odrs[n]; - kx022a_turn_on_unlock(data); - break; + scoped_guard(mutex, &data->mutex) { + ret = kx022a_turn_on_off(data, false); + if (ret) + return ret; + + ret = regmap_update_bits(data->regmap, + data->chip_info->odcntl, + KX022A_MASK_ODR, n); + data->odr_ns = kx022a_odrs[n]; + return kx022a_turn_on_off(data, true); + } case IIO_CHAN_INFO_SCALE: n = data->chip_info->scale_table_size / 2; @@ -559,29 +536,27 @@ static int kx022a_write_raw(struct iio_dev *idev, if (val == data->chip_info->scale_table[n][0] && val2 == data->chip_info->scale_table[n][1]) break; - if (n < 0) { - ret = -EINVAL; - goto unlock_out; - } + if (n < 0) + return -EINVAL; - ret = kx022a_turn_off_lock(data); - if (ret) - break; + scoped_guard(mutex, &data->mutex) { + ret = kx022a_turn_on_off(data, false); + if (ret) + return ret; - ret = regmap_update_bits(data->regmap, data->chip_info->cntl, - KX022A_MASK_GSEL, - n << KX022A_GSEL_SHIFT); - kx022a_turn_on_unlock(data); - break; + ret = regmap_update_bits(data->regmap, + data->chip_info->cntl, + KX022A_MASK_GSEL, + n << KX022A_GSEL_SHIFT); + kx022a_turn_on_off(data, true); + + return ret; + } default: - ret = -EINVAL; break; } -unlock_out: - iio_device_release_direct_mode(idev); - - return ret; + return -EINVAL; } static int kx022a_fifo_set_wmi(struct kx022a_data *data) @@ -923,7 +898,7 @@ static int kx022a_fifo_disable(struct kx022a_data *data) int ret = 0; guard(mutex)(&data->mutex); - ret = __kx022a_turn_on_off(data, false); + ret = kx022a_turn_on_off(data, false); if (ret) return ret; @@ -942,7 +917,7 @@ static int kx022a_fifo_disable(struct kx022a_data *data) kfree(data->fifo_buffer); - return __kx022a_turn_on_off(data, true); + return kx022a_turn_on_off(data, true); } static int kx022a_buffer_predisable(struct iio_dev *idev) @@ -966,7 +941,7 @@ static int kx022a_fifo_enable(struct kx022a_data *data) return -ENOMEM; guard(mutex)(&data->mutex); - ret = __kx022a_turn_on_off(data, false); + ret = kx022a_turn_on_off(data, false); if (ret) return ret; @@ -987,7 +962,7 @@ static int kx022a_fifo_enable(struct kx022a_data *data) if (ret) return ret; - return __kx022a_turn_on_off(data, true); + return kx022a_turn_on_off(data, true); } static int kx022a_buffer_postenable(struct iio_dev *idev) @@ -1089,7 +1064,7 @@ static int kx022a_trigger_set_state(struct iio_trigger *trig, return -EBUSY; } - ret = __kx022a_turn_on_off(data, false); + ret = kx022a_turn_on_off(data, false); if (ret) return ret; @@ -1098,7 +1073,7 @@ static int kx022a_trigger_set_state(struct iio_trigger *trig, if (ret) return ret; - return __kx022a_turn_on_off(data, true); + return kx022a_turn_on_off(data, true); } static const struct iio_trigger_ops kx022a_trigger_ops = { @@ -1379,19 +1354,19 @@ int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chi return ret; /* The sensor must be turned off for configuration */ - ret = kx022a_turn_off_lock(data); - if (ret) - return ret; + scoped_guard(mutex, &data->mutex) { + ret = kx022a_turn_on_off(data, false); + if (ret) + return ret; - ret = kx022a_chip_init(data); - if (ret) { - mutex_unlock(&data->mutex); - return ret; - } + ret = kx022a_chip_init(data); + if (ret) + return ret; - ret = kx022a_turn_on_unlock(data); - if (ret) - return ret; + ret = kx022a_turn_on_off(data, true); + if (ret) + return ret; + } ret = devm_iio_triggered_buffer_setup_ext(dev, idev, &iio_pollfunc_store_time,