From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 88D6D3EF678 for ; Fri, 10 Jul 2026 08:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783672599; cv=none; b=GvzlcoaGM0c2R59OFHU5N7FBMLK2naYn0s6NjQoQOiE7Hk9/6pVGVmlrfanGoY8wqlaOjsSjAvAiZdwZw1S8mps3HRrRiUdEwXEgNj5qjeS3kaTKdxIEvTh47NWmu3nJLFmUjT40n8MCwRypZGz1SzA7SRGkUnszKqzCMuQL5Us= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783672599; c=relaxed/simple; bh=/nKSNbpEdL+T6GQ95kGzOqJewbxvRukWfExTHwG8WQY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JTzqXVgQ5Y4Y1l3mEmTkLLwzUvqipqtwx0fpGIw2wFxflrU6FxPUdRTXmmZy8wTkevI+dsN1zkfzRF1J+UC9N/977bM1XO328+sITpmO0WGDdMhrPI2ZSuuQAwob1JiH1sfJ8kFLWCBKZA5CS9BWwZRKeceW4Af2xK8Ch5bLMQU= 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=icFukE1t; arc=none smtp.client-ip=209.85.128.47 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="icFukE1t" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-493b966dd74so2211005e9.3 for ; Fri, 10 Jul 2026 01:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783672596; x=1784277396; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=pA1HEGDtcWaQ9J5As0L2Cw9LkRzBGT6/pW+NLlqfsl8=; b=icFukE1tGsSnIDjBDOxIlOJ5tL0kOU3LuQQ4l3mTnIKjI9ukDfSDHHy++EDNTb3lqW qm/flp1X8hgRa4r6wI2JzXGgRRTVz2vnrMx6tssRj6UNNJaDZHgOogv+9TiLw59wpa2a C+bAfXMQM2GltMPhzr18DMyi1CJDDfryQBnpDlFzrLuvuTv5GxEGzX2S06jnWmxSbAim 9McOd93+hlfTAZ86QnXPZoQ3ojgSbAZxnNHzWvprLFWN7lwmccfes8fBi9pdiYDW/pNz NyndiY8oBSP6jQIsBhjrQqpHxTVqXOcksQcbvahzCagf+OfEdrVM+cSaNbVfVrbVXx4i Pn4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783672596; x=1784277396; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pA1HEGDtcWaQ9J5As0L2Cw9LkRzBGT6/pW+NLlqfsl8=; b=g124YFOcfMwgH/oz07pGidaUOpKy6QnxsLc15b7yD3ClhsNznkveZ1VxDx9ws0upLG C2+3RmTUc0ud73+EuPCCgWRWaky0W5+GHLkutA3OAk/NlIwUVwWDciNDOaDB7LLN0NQA ijIHL1cwGOv77cnuEvwf30DawQKec26kF4bUR8BcZtBY0yw87VAffzuJ4YtjXMQkw3zU wPHidnyJdKGFmzWVW3ObqN1pE++A75HcQ8fnrtL235kzAkYvBqXgb6loDhNPkN6abMDI tRjNZ1fT8oJqdD72xkfuCBko24eoLxb7j5b4DwmR6hq0S6y2FpjhmSg+LLByMUdNtkRb QqJg== X-Forwarded-Encrypted: i=1; AHgh+RqHKTnSP8lOtY0Ju0Mg9akluFc9qGiGgfL+yfqDfUnBLLG0FR+ixOiN3PE4OT3g0KAs9uNwNxWmnV4tdgw=@vger.kernel.org X-Gm-Message-State: AOJu0Yyp1wIUrBggXtptlfj8AZuVwpMx0dwFBTqgRJ7TFl5uZwy7rKUX OdFeFCdGbj9U6pttesd9u1ljm7e502wQ2Wik4jckAZf97jwv+847uD8F X-Gm-Gg: AfdE7cl7u1EdACDmt4v4w17MRNacod49XKZjFR/VWeKE22fMP5RB1GUnjbzIdU9SZRk OU9qX22bskp59zcxId+t5R9/tmx8MRorTfld5ax1Z4YA/mVIDYDg2+DBYlUJrhMsEScc7qvzydX hKgp2RxJA0oopN/FPE7c81aj6kb2gloN+tHJBA1agYP4ShZU8maD8ivatHYtedsavWm6kPvR+Ij FdoCY9e2bPzLtIwl7T2l2Lwo5OWA9ZF8SkV8RDgeZC+41P0gdnYZvmiM2rppDKuC1eQtCbIYVV4 cTaNCTBV2xPOOMWaxEShDllrqw8H6Q1yljdIsrqiBJ/Zda4uho9L2c59y0S+IrJ+MmS5P/Pytbp vMPrPolBOudcnY7CEkJaQ59zdIiMlSChk1OmU8Y6eqv9Wc3QlVPtrX/mOZclmowNXCX8XpkJ9SL SffSbGdNiTYA8bH+O646nwAYio/lbNpLbsNxxK/RNusU6yboRIDDnFhBSeVE3tIfWHL6QN6l1Ko wBY68260zHIkgRXTaQ= X-Received: by 2002:a05:600c:828c:b0:493:e460:1f6 with SMTP id 5b1f17b1804b1-493e65f1b02mr104587255e9.0.1783672595783; Fri, 10 Jul 2026 01:36:35 -0700 (PDT) Received: from workstation.speedport.ip (p200300d5070afe7db3148fa84ed2ac78.dip0.t-ipconnect.de. [2003:d5:70a:fe7d:b314:8fa8:4ed2:ac78]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493eb6e8844sm134592985e9.10.2026.07.10.01.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 01:36:35 -0700 (PDT) From: Mert Seftali To: Jonathan Cameron Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Joshua Crofts , Jelle van der Waa , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Mert Seftali Subject: [PATCH v2] iio: accel: dmard09: Implement IIO_CHAN_INFO_SCALE Date: Fri, 10 Jul 2026 10:36:23 +0200 Message-ID: <20260710083623.84243-1-mertsftl@gmail.com> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Reading the in_accel_scale attribute on the DMARD09 has always returned -EINVAL: the channels advertise scale via info_mask_shared_by_type so the IIO core exposes the attribute, but dmard09_read_raw() only handles IIO_CHAN_INFO_RAW, so a SCALE read falls through to 'default: return -EINVAL': $ cat .../iio:deviceX/in_accel_scale cat: in_accel_scale: Invalid argument leaving userspace with raw counts it cannot convert to m/s^2. The driver was written from a vendor source [1] without a datasheet, and the scale was declared but never implemented. The vendor source carries the sensitivity: its conversion is acc = raw * GRAVITY_EARTH_1000 / sensitivity (then / 1000 -> m/s^2) with sensitivity = 32 and GRAVITY_EARTH_1000 = 9807 ("about (9.80665)*1000"), i.e. 32 counts correspond to 1 g. That sensitivity applies to the value this driver already reports as raw: the vendor reduces each 16-bit sample to a signed 9-bit value, and the preparation in dmard09_read_raw() yields the same value. It is self-consistent: 256 counts / 32 = 8 g full scale, matching the +/-8g range. Implement the scale derived from that sensitivity using standard gravity: scale = 9.80665 / 32 = 0.3064578125 m/s^2 per LSB Link: https://github.com/minstrelsy/mediatek/blob/1f49d8c87b839651bc89afc870277e8e0f2e2d55/custom/common/kernel/accelerometer/dmard09/dmard09.c [1] Fixes: a4fa6509dda4 ("iio: accel: add support for the Domintech DMARD09 3-axis accelerometer") Signed-off-by: Mert Seftali --- Changes in v2: - Reword the opening around reading the attribute and merge the duplicated explanation into it. - Describe the sample as a signed 9-bit value in plain language instead of the register bit operations (the vendor code is in the link). - Turn the vendor-source URL into a Link: tag. - Express the scale via the IIO_G_TO_M_S_2() helper instead of a precomputed constant. - Add a blank line before the return in the SCALE case. drivers/iio/accel/dmard09.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/accel/dmard09.c b/drivers/iio/accel/dmard09.c index fe35a1270786..6f0497ab6133 100644 --- a/drivers/iio/accel/dmard09.c +++ b/drivers/iio/accel/dmard09.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #define DMARD09_DRV_NAME "dmard09" @@ -79,6 +80,12 @@ static int dmard09_read_raw(struct iio_dev *indio_dev, *val = accel; return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = 0; + /* 1 g / 32 LSB, in m/s^2 */ + *val2 = IIO_G_TO_M_S_2(NANO / 32); + + return IIO_VAL_INT_PLUS_NANO; default: return -EINVAL; } -- 2.55.0