Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp799611lqh; Thu, 28 Mar 2024 17:50:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW6uYk5O5QLhYX7YlvNXK6NtUMQXufpQEhqCGGzVfLDjWZzSx61qrftxf8MahYs0ief9RMq3HZYEtHiNE/8sXzmoy9pBj/S4bUkTFN9lQ== X-Google-Smtp-Source: AGHT+IGro3gBEyuUQbIgRpZfSVTa3EbEh4+PJgARfs0gSW+4r4V6imaYn5GEzCgOAw3OpBWnahJY X-Received: by 2002:a05:6a20:45d:b0:1a3:6864:9baa with SMTP id b29-20020a056a20045d00b001a368649baamr644276pzb.57.1711673420577; Thu, 28 Mar 2024 17:50:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711673420; cv=pass; d=google.com; s=arc-20160816; b=z2ByLeogiPE6M0sS3ePVl4cG48ojcXq6kXC5xmKFi+0orfYVyurrjoAsIst4O9TRHk ttXaMCxAfB5t4Ek5P/s5O3z/T3FX6eEWC5WcXGzxjNPg0tvDEDvq9d9FsppM2q88NQja KyYdh0S8MreScbjSUgXeDH7adgUh3Hxj9Dxmbx0WW78D605a/uuMDCpvoLwvXt/fY2fH sACioCQWrlgBlXA3eeXXwhmYRzYr5XDx0CKx/EKcdNnwPgVzJgO66cdlRgSblJBTRDdk Z+3lKDgEvzDGXMXOjz1XD3IMt88XotPmpHwxAzUaZdo6pjHkdPdJHsBd7mQbdrhJL2hx n9rQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=en74PRYThtLoO+VTh1LsA/OHt41VMEnZsO14VQkkbVY=; fh=/9tvPIW4bCLOn9mYXqyHTmEZQQnu1arnoXHtboJfyx0=; b=wYQoGH7UReVfXAsRIUO2gikFNC6lN3TX6RISXmlqNKrq3gVcrRxmpoJtgz+QejJ/XN qNAmkqgT7/GhTZWbSVBVymRLyBfw2oLuxEB0cS6gxi00CTmojHd9GPZnrnT8VDhhKb4E Oc4QB/Q1n5DnqVhNhzu0Bj28+IS5sGM+Kmt0t42uHYeWUJcQcTOzsayDddtBuBb5E3gq cu+Q1eFVDAKPri15HoY/RG0syLoYKdmuuAENZYDCNpVl4otkVJvH/hMeZ326tbkXHyjP fJSNk/hr6MiPdKbJ6mEEysD659XEMoBRzmXCiQ+nUennd9SIu3nUxtTsmsspYMcuyZMc 0+9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mSr3SP5E; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-123916-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123916-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j11-20020aa783cb000000b006ead086ea6bsi2485805pfn.87.2024.03.28.17.50.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 17:50:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123916-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mSr3SP5E; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-123916-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123916-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 011C628EE21 for ; Fri, 29 Mar 2024 00:41:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10E60154B1; Fri, 29 Mar 2024 00:40:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mSr3SP5E" 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 63CA95223; Fri, 29 Mar 2024 00:40:40 +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=1711672842; cv=none; b=duoqFBR2a+wzs4/PqCTK19Ear386EmdoCU+iMDhlw7CHEVpQLLXhQ7Owg42dkRkb9EWpkJilMfG/2Cc5lHWO04ofvfzqk0MpgD00GbAwSlrSogxtVK13+5bvNm1WjEyiIItkhhpk0YrN20uzEKTn5WqpXz3zn9/TfthoPCXzy2w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711672842; c=relaxed/simple; bh=Thuwc5jU/GgWSwwKqdNAbuidpQuzlLpjhLu2hWojAgA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A8eDOHUPpTIumRnGxzQqDrsSdwie/w1qGh7I2LWodiEKJvIiCLNXiImeYjrND7lSTbU+bCvn47aMccEWPPljMLasx/dO5QDVDPM03WXtB7jKa1Rw49CPrt46xIlO1V1BXLY4PgTpOYPfxOm81eIXBQjf/9v222NlL5lf1pd5xHo= 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=mSr3SP5E; 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 Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2d68cf90ec4so22552911fa.1; Thu, 28 Mar 2024 17:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711672838; x=1712277638; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=en74PRYThtLoO+VTh1LsA/OHt41VMEnZsO14VQkkbVY=; b=mSr3SP5EXoTN8Voh0QJzDBPfJ0SqMG1j2blUWHlDepcUCEb4YJQ8plSKlhEBQpgQtf dm1IfNK23TMyEzT61BOdMprJdcq40v3qTTZffSlQjX2Ig2DyeRRMXBB8pzx/WZQOGIu0 hus6KKFHYGy67ejUfaLT/PG7/tgTN8NTUHCfYuNXJH68DbOpLqo6W0eKn4AC8cDxQZL3 /Pmef/NFuIv0KgHrJFKMAj8c8LEQ5kaL1LCOu1Ae/GlRzMTMEcacOqak+OVf1PxsAOuv Ss+5+WE+V/9taqAgbMHD6sAM6k6GjZuXP+GFJtPWH41VoNdXP/8XuiMbOoKaomZ+n5xz nuRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711672838; x=1712277638; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=en74PRYThtLoO+VTh1LsA/OHt41VMEnZsO14VQkkbVY=; b=R1dt6L/se4dvgQj3ttgobJaIbxTTolDDu9MdHq1EQhFaZcHmRmi68CHRO9niBZM/pM OOK6SIJ5w9sdj8KBkREA3uwHzv4RMm+wU/pBF2z9aicqCeIDGBzwjJw/cyP4EBlnO/UJ 7GerFGZ27DbhyWFcga6k48LXBVT08IE+B4xol53gNnUGAvHSHJetoOcBPXgreOzSGp04 VQ+TeE0rO+KEUdrsVMExOq1hjeGwC566Evl+Zg3cVrl4czFKTvPvtMrRfH+GbRfYwj5D 8rYV9ZzLirzonfDKxw3OLsFcWk1thCQi1OvaF/mNkdw/Zsk/R69cF3kVGwtSLwqtw89c q1IA== X-Forwarded-Encrypted: i=1; AJvYcCUV6yt7RL6RvC567hkxqE5SgGpnJvxKZRtiXjt91IfFtqp3LuQCtzFLoZALBVIOAzxTHA+4fssScX7hLMtnP7fvKHUGQnYaslihNn23kaCxWKUOGyey+esZVNbv74eXcvQ1Dcd2yXVzEg== X-Gm-Message-State: AOJu0Yykv0syq9c4tdXAtvNdi/PCLJd667aS1uV6pZIItUoXjQdoyjHk bWn8u93W7+UokO3Jv+r4lU5zD2qmkwInJfSfKn2RxmuJhOHzdwaK X-Received: by 2002:a2e:a4c3:0:b0:2d4:83f9:2e21 with SMTP id p3-20020a2ea4c3000000b002d483f92e21mr356943ljm.42.1711672838244; Thu, 28 Mar 2024 17:40:38 -0700 (PDT) Received: from 13a4f82a8f12.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id h7-20020a0564020e0700b00568e3d3337bsm1391679edh.18.2024.03.28.17.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 17:40:37 -0700 (PDT) From: Lothar Rubusch To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, eraretuya@gmail.com, l.rubusch@gmail.com Subject: [PATCH v6 1/7] iio: accel: adxl345: Make data_range obsolete Date: Fri, 29 Mar 2024 00:40:24 +0000 Message-Id: <20240329004030.16153-2-l.rubusch@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240329004030.16153-1-l.rubusch@gmail.com> References: <20240329004030.16153-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Replace write() data_format by regmap_update_bits() to keep bus specific pre-configuration which might have happened before on the same register. The bus specific bits in data_format register then need to be masked out, Remove the data_range field from the struct adxl345_data, because it is not used anymore. Signed-off-by: Lothar Rubusch --- drivers/iio/accel/adxl345_core.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 8bd30a23e..f4dec5ff1 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -37,7 +37,11 @@ #define ADXL345_POWER_CTL_MEASURE BIT(3) #define ADXL345_POWER_CTL_STANDBY 0x00 -#define ADXL345_DATA_FORMAT_FULL_RES BIT(3) /* Up to 13-bits resolution */ +#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) /* Set the g range */ +#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) /* Left-justified (MSB) mode */ +#define ADXL345_DATA_FORMAT_FULL_RES BIT(3) /* Up to 13-bits resolution */ +#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7) /* Enable a self test */ + #define ADXL345_DATA_FORMAT_2G 0 #define ADXL345_DATA_FORMAT_4G 1 #define ADXL345_DATA_FORMAT_8G 2 @@ -48,7 +52,6 @@ struct adxl345_data { const struct adxl345_chip_info *info; struct regmap *regmap; - u8 data_range; }; #define ADXL345_CHANNEL(index, axis) { \ @@ -202,6 +205,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap) struct adxl345_data *data; struct iio_dev *indio_dev; u32 regval; + unsigned int data_format_mask; int ret; ret = regmap_read(regmap, ADXL345_REG_DEVID, ®val); @@ -218,15 +222,23 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap) data = iio_priv(indio_dev); data->regmap = regmap; - /* Enable full-resolution mode */ - data->data_range = ADXL345_DATA_FORMAT_FULL_RES; data->info = device_get_match_data(dev); if (!data->info) return -ENODEV; - ret = regmap_write(data->regmap, ADXL345_REG_DATA_FORMAT, - data->data_range); - if (ret < 0) + /* + * Only allow updates of bus independent bits to the data_format + * register. Keep the bus specific pre-configuration. + */ + data_format_mask = (ADXL345_DATA_FORMAT_RANGE | + ADXL345_DATA_FORMAT_JUSTIFY | + ADXL345_DATA_FORMAT_FULL_RES | + ADXL345_DATA_FORMAT_SELF_TEST); + + /* Enable full-resolution mode */ + ret = regmap_update_bits(regmap, ADXL345_REG_DATA_FORMAT, + data_format_mask, ADXL345_DATA_FORMAT_FULL_RES); + if (ret) return dev_err_probe(dev, ret, "Failed to set data range\n"); indio_dev->name = data->info->name; -- 2.25.1