From patchwork Wed Oct 30 15:30:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 13856749 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 BA4403EA9A for ; Wed, 30 Oct 2024 15:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730302232; cv=none; b=cH98GZY0XLODaF7eVd94NkYAdLHpiV+oZ/vbU0LpVgP8BERbrxsFEMz1fI18KZ9jdf7OpszXvP3ESswCmfQpBnz5Qv/cdC3UXwE/sfxIGtJ1uB0zV02lzAmR9cTzuP2QBgHn//KhcqCr4561ur9ztzZdbZVToEaVoRFo1mn/NpA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730302232; c=relaxed/simple; bh=AXp9R9SIchOWcn52tYxCXMRJHbP1cxB3uaJJrIOcnfc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GHWB0Wyujfcsu2JlFXIowfbVXaungsK2Tg8laP80+yTPOvwzhqos+7qS9zT37DguUXWGxz+HTUfuU/0QS2ewSz7ktOTdEYGQKII76Cco68S3f2T7+kjSzNAENv/muccH4kZKBYBUOtY7SoxB7i+4e93zwnHpMHamWO5f2RyGObU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ZWo1ZbUT; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ZWo1ZbUT" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-37d55f0cf85so4520f8f.3 for ; Wed, 30 Oct 2024 08:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730302228; x=1730907028; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=zRMi/UaCb3Fk6BdW82ihmAT7XSEnqkfXgGS7TLc7snw=; b=ZWo1ZbUT85ZHDoJYncj6d3A9Gr//peFQr9lHTiOX7TnyVQBi/OAbuu0NdTj9e79P32 bHhgbzCq4lfCTZDLZ3IiFqvv3IiKBGjuH1qAu9EL1NAqdpq3ukv2qXMqg0o/WDIwPb8c QzvF1C5gC8AhxLjWBVd3BbJz+GWMTgHRXz0/mN7+rL/R/gtYnT6ifPvV6Q/HOT5ChT5w U3Nzoa/fE9iQWXCSFRGagSzYLNBuoRaV1IcloenWjMUzY/qCfPNTUnKrKVIUl7aRWJ7w kNtWX61Or2I7tg1htecYJ58J0j/K0dg1ozFNF5EUm6KA3SGG3uIEe5yYDPCMpyS7JaqM yiIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730302228; x=1730907028; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zRMi/UaCb3Fk6BdW82ihmAT7XSEnqkfXgGS7TLc7snw=; b=qIaBxxjXZjOHQ4ci+tIAiyFLMykQjKS4zXUfdp2ls8PP4X/JRPAai2+aCyLUwqxS/n ZFPmyeemA1ZnAPxHdIzOWVz7Q92y3ddf5Qd5WpIbQToXgUvTMfBex2U9s3rXabdt0HwS opDLv1sinVK/qG0Her79EsDe5n1Qp4yMfyIlEMs7vqOLQCvEil+vOsFXflyj3OjtaUnb NZkShHYDDoOSUvilg3FJGCiHB6QDVToi/CnFRG9kRT+kBzkL9KJjsdmWdGmGS4uvUVVz TttmOxZqoZ6X08m6SBfVD8w3kGuZmdup+IbI9RtBT7Ir0Y+lnb6DyULMtwUfJXBczyfZ 9CwA== X-Forwarded-Encrypted: i=1; AJvYcCUFfn53Zs9Usi5DZLf7BpxttwcBQxQudW56eGuAKalG0/UtJlqfI3NC0C9MXp98e4E/vHm5laW/VD8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4IvyCFRKI723WL7Djkv9rgq7MAunQvA0TDzMLj7aly0yuTYOf Z6YAlHLkN4c68r2XL89R896YKtueAm9l5BqTk/WwwT4V3dSKA6k2uHHAbQnm06U= X-Google-Smtp-Source: AGHT+IHoRp+AdkV7muEM98FjpmsQbqUcxsFuiT8bojj04qgoJZnxfDR3JyQ/xauio6JUyi0Vrf9CtQ== X-Received: by 2002:a5d:59a2:0:b0:37d:5129:f454 with SMTP id ffacd0b85a97d-381be776c81mr12116f8f.15.1730302228060; Wed, 30 Oct 2024 08:30:28 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:8261:5fff:fe11:bdda]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b3c236sm15604040f8f.35.2024.10.30.08.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 08:30:27 -0700 (PDT) From: Neil Armstrong Date: Wed, 30 Oct 2024 16:30:22 +0100 Subject: [PATCH v4 1/3] dt-bindings: vendor-prefixes: Add Allegro MicroSystems, Inc Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241030-topic-input-upstream-als31300-v4-1-494297c9e50a@linaro.org> References: <20241030-topic-input-upstream-als31300-v4-0-494297c9e50a@linaro.org> In-Reply-To: <20241030-topic-input-upstream-als31300-v4-0-494297c9e50a@linaro.org> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen Cc: Andy Shevchenko , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Neil Armstrong X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=912; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=AXp9R9SIchOWcn52tYxCXMRJHbP1cxB3uaJJrIOcnfc=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBnIlERgWKlWKr/QYDLiS94tIIuQ28hSEKf/QKE4h+o ljU27P+JAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZyJREQAKCRB33NvayMhJ0fsUD/ 9NlYyVfmCDfpCI+AViO8eI3UNt/HOm7t3yz2OZ/HVqdJq4YRcCYtmeOucCLpW2mIxarptNqaqUEQUZ QTHE/J3S1WEh/oUtrsExS9V5phxjyBdLu0VKWZFT5Ru+GWiS1vv8GKFVAHxOTYXfETCfhp57ZhPByl pyKahQapTopn4gurnbn9WKc9X/VPyJ7lN6PJBm8ftwWhMoLzaxtJNttO8CbRTv8aUwxdsjYfAMgrhv qlB0yBj8iFpugYYscZ6TjnUTmHUF7Gpb6J8dJorjIPjSbDVgOL5bA73WMHbRsm8JTNmWGdo6GRPRV5 OQZCuMHTk6uuVlqsZFQO6S2ZT7izcbWnQkKUhsAlekOVdQK5EIGcquZjJTnIYpJH2wnF0IgaM0yvGa Ifr3Pmn+NaMc0m1EjdNUYbevnFDPcCKajahGBgTLoASld7D9Cb6fOvj56ij61+/fIgPSDt4H238kuz r7gdCU0D0P3xQuS3sa8f+hAhYGi3AhQVoZWCjPxakXAybdaJx89CJprke7qucoeV9HE07rIgxg8Wwl LM15BFsM5nQr9e4AKlbCgGeftmp2Ikek8NoplvWbpI85AAmvO467C9KkAROt5LO1UpI/S8qAIUqaat RYlM+qaoLK+kGG0IAPNzjIQ2Vixkq5PyuUMKbRqRj429AUS8BNA+W+BQ52ig== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Link: https://www.allegromicro.com/en/about-allegro Acked-by: Rob Herring (Arm) Signed-off-by: Neil Armstrong --- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml index 15877574a4172cbd9395bed531555cfb009ff010..b90355c2b45ada6e20335cd5bb2aace9410e4d3a 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -83,6 +83,8 @@ patternProperties: description: ALFA Network Inc. "^allegro,.*": description: Allegro DVT + "^allegromicro,.*": + description: Allegro MicroSystems, Inc. "^alliedvision,.*": description: Allied Vision Technologies GmbH "^allo,.*": From patchwork Wed Oct 30 15:30:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 13856750 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 92BEB2139A7 for ; Wed, 30 Oct 2024 15:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730302233; cv=none; b=he87hRtv6sTGuOqQYnO5M8g6vvvwa9nPeVit70VaA8h6njzsow6K1HI2oU9f4UOPZdfMQrtYEminp+cutqavO+jmr+pQg9VCtyNXcRKyuqwKdIxlO8HPB5N/MS3byiIesXbvhHVz2y1+B7SLlJEk+xj5iE4sBfBYXi5v/r+V7Z4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730302233; c=relaxed/simple; bh=VCywuuwYQzUwDiW7Kdz78e0AbhF/gpt3Et+zeQEyoQ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=alvlg3gLIX2qXQRLMyZdlk08QUz1DJJzWrOYj8gR2E2JDQEv3blC72Zbf0WbABKy8C3qn2hWqhkQt2/J8N3TFl6nkeisLjPUfCJlmNdrPInp0FpddDjgpPFPLrVZCNj7jUmP9a30MRTn3MM7tOhpg6zXUDz5KJCrxJF9UXixKm0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=nBd3ana+; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="nBd3ana+" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4314c452180so7017175e9.0 for ; Wed, 30 Oct 2024 08:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730302229; x=1730907029; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7Ouv8MfLcp6Kh4uX/Oe/HUpjciTuIWZJObxnGJ4zstA=; b=nBd3ana+aZ6oUGFfNZqxG/Mnr6Rgdj6NlVaZzkUTx+NmLGH0ngkr47+64T8zqZDhFi wephGOV3AXzozstG2SQ5EkjmEaEGI/xT18erEDv4sf6nkLvMoyVUsSE2USdWRhQBXTr3 P0nKQfjjQFfYH+ES4ALXFtDCn1kLoNHzOduSrCvneOOcYZeK5WYPE3G2PvEGSEMkhcIz gvDAp26k3cIWHx3AK5kjqsrSaZRXcv2W7T2irLhHyamIGGCx3weRP9y2tTnJEAEajvDn KCeZ9Xqgwy5uLS44YZjpTGKHNaUr9f2lR95WSi3HvtZKt6CXkgZPzpNyFlg0ADfa/5jM BEwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730302229; x=1730907029; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7Ouv8MfLcp6Kh4uX/Oe/HUpjciTuIWZJObxnGJ4zstA=; b=YFJ6k1A/M1GkkqRjvsRGcvmQ3VoEMHbCVJ3QEEn/RGqJ7VMwWaJrWqSgJxbhhoZArK CcgbVW/Kvf5CVxEhnd6CE07kZt7bBoURFs1Bofegy8OurtHsrw0r5H5OdB4mGP1Es2pO pRkSiQ8PCLjq18yl4JCqXySISEalk7VUeKpbt322rUKFhEfTWSiThpgIW3IAzHLqCpl4 AQM9I2+fzysEvWYdKFFpugr/ZuWQQV4ae9JaGw8IQ2XdeFDq4N7SjA07lVvPCHOWRO55 8RwWdcdcJmNyWFoWK7NPMHAhoD8MPHK9udJ7K011eTRf0tUddV4DdHPZPZ+mgcbWLASW IF1Q== X-Forwarded-Encrypted: i=1; AJvYcCWlN+GJvEl4HYQV8Sm7CcuvxcrCLMGJdpMQHjz/xLTCEaxt375TZzbe3ZPBF13K2fIPuyG9fvwuF78=@vger.kernel.org X-Gm-Message-State: AOJu0YwLWOt+nPfc2phWDIKZVOzlh+fdRaLCsBvSjToYYe83xbsRFqeX AQ53yxFithHQrM48KAhSpVfFwC4Bf20oEXU9yHyqPyAIrzV7b2hmfBYUVgxB0P0= X-Google-Smtp-Source: AGHT+IFdcA3r60tQ/UYq/rCP94zXhnuaDucY2c1LJoUNA2Iuh28irk5zqOSChwj/5NLjkJ/efzP4ZA== X-Received: by 2002:a5d:5d85:0:b0:381:b20b:ff3e with SMTP id ffacd0b85a97d-381b20bffa5mr4537680f8f.26.1730302228838; Wed, 30 Oct 2024 08:30:28 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:8261:5fff:fe11:bdda]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b3c236sm15604040f8f.35.2024.10.30.08.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 08:30:28 -0700 (PDT) From: Neil Armstrong Date: Wed, 30 Oct 2024 16:30:23 +0100 Subject: [PATCH v4 2/3] dt-bindings: iio: magnetometer: document the Allegro MicroSystems ALS31300 3-D Linear Hall Effect Sensor Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241030-topic-input-upstream-als31300-v4-2-494297c9e50a@linaro.org> References: <20241030-topic-input-upstream-als31300-v4-0-494297c9e50a@linaro.org> In-Reply-To: <20241030-topic-input-upstream-als31300-v4-0-494297c9e50a@linaro.org> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen Cc: Andy Shevchenko , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Neil Armstrong X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2381; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=VCywuuwYQzUwDiW7Kdz78e0AbhF/gpt3Et+zeQEyoQ0=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBnIlER0KyvyI/liH7ZKTXqG/Vj/JCaNfHcFA9dhJvm eBe8taGJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZyJREQAKCRB33NvayMhJ0TeND/ 4ji6YXqtO2WEH2zX7NFGwzIQWGaX4r4K62XKUKx+tNj5nsQB9Hbzasv8qKTIQSuGpj+cQ37l3z6JjE zqte7593seE8Fe4v5hudBgZOg4nVXozcXGr08PiVwH5EBYU1ixqwrJFoLFt5P46kRJhaG2KrSqlWYW jUJWSjLYZ24TsaK4lVAYt2BD9V7VE3Z+Y27jpnJ+XOw5lMEn/1yV8fX4l89R371tOF1qWVkpCfaPcv VaW6vxt8p7SozHrzTfyiKqOWgI+295rQriBCPuiEGgdpgBHrf3sRbGjTrgaNAFL6CnvxA6watDMIG9 L3gZomb1SLvam4xWGCYpiOOnnxFzPDGO89yhEHO5BFdhHbrXSdbtsBQGZmyynh/dMFVMEPJRM9b/XC Ywncp38GpAg17s9d96kkOSShCmiwfcwnR6UengHz5YBERYGTOZGC/WrvY1YslM9vwz/lfDCjd6QnfK CrqTuiy9ZxZv2vCRlySwRYhvwuSZvpQDe9ysOAs4FkblKjkwsDlJoLwTIzSV0dDxcKs4qwQAjFodjU h1/Aq3DPMQQHou0TM8nu71YxzvWK2APU1d++zwWCPA3Pv3IM/Q2qEMbiZoyoIjuhnszWTW4XDv65D4 t8ndPzrt0X4F9zjNqdL/YL4ZbU6N1BbNmxJwrfCUkFX+XT7mTjUP7BAfC7vQ== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Document the bindings for the Allegro MicroSystems ALS31300 3-D Linear Hall Effect Sensor controller by an I2C interface, mainly used in 3D head-on motion sensing applications. The device can be configured with different sensitivities in factory, but the sensitivity value used to calculate value into the Gauss unit is not available from registers, thus the sensitivity is provided by the compatible/device-id string which is based on the part number as described in the datasheet page 2. Datasheet: https://www.allegromicro.com/-/media/files/datasheets/als31300-datasheet.pdf Reviewed-by: Rob Herring (Arm) Signed-off-by: Neil Armstrong --- .../iio/magnetometer/allegromicro,als31300.yaml | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/magnetometer/allegromicro,als31300.yaml b/Documentation/devicetree/bindings/iio/magnetometer/allegromicro,als31300.yaml new file mode 100644 index 0000000000000000000000000000000000000000..52e3781834ee9d98aa84c5d340ae75ffbf76f925 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/magnetometer/allegromicro,als31300.yaml @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/magnetometer/allegromicro,als31300.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Allegro MicroSystems ALS31300 3-D Linear Hall Effect sensor + +maintainers: + - Neil Armstrong + +properties: + $nodename: + pattern: '^magnetometer@[0-9a-f]+$' + + compatible: + enum: + - allegromicro,als31300-500 # Factory configured at 500 Gauss input range + - allegromicro,als31300-1000 # Factory configured at 1000 Gauss input range + - allegromicro,als31300-2000 # Factory configured at 2000 Gauss input range + + reg: + maxItems: 1 + + vcc-supply: + description: 5.5V supply + + interrupts: + maxItems: 1 + +required: + - compatible + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + magnetometer@61 { + compatible = "allegromicro,als31300-500"; + reg = <0x61>; + vcc-supply = <&hall_vcc>; + }; + }; From patchwork Wed Oct 30 15:30:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 13856751 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.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 AD967213EC9 for ; Wed, 30 Oct 2024 15:30:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730302235; cv=none; b=nMvbz3zlQy0AXrO4SoNIi4qR5tWbJxaf+UREu/2lZbE0yGUct7KsqG11PqNoB2Gw8lXdvXrgdaV8J53yX2FLiQSplPwIHmlvUJvfuS6FkCkcmaba9nz3uWaSrNMChaNqalFAHrQQFqvW/7JqOhLeiH2WPGYY5wKQ+qIGYC35oEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730302235; c=relaxed/simple; bh=eBIMnCBQaNpLn7U3M2W2glS1xKvGKBEbt3HjuFgJPmU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S5vnHSAscunPTMod3Pn7frP/EMxg7gQLHnBfhY2VAh1ZvfoEHnvgcFN6qyg0oYJ+6cw4zuR91t7c4Q+OFdCjBWb7ECfETx+u1V9R/088R2PL+oW/WBCVoangNPOny62hEClexaxIKf6l2nJoeTMVNfTLmiglfXttdsHuOgyY2qk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=n6K++rq1; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="n6K++rq1" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-37d8901cb98so731079f8f.0 for ; Wed, 30 Oct 2024 08:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730302230; x=1730907030; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=EjKcunrCqABMsfKlxzqU1Ip8DOGMIT1Kxye1UV2fjx4=; b=n6K++rq1onJC+AP7knN+siJMElflpUApdYQHAjMpnfCd9QDS30fqqvrbggH0NQd6WX 5+IfXqP97nhmhHD+vTcpt9JxLVrL4mMELoihLht36EfuwGuRrUYULInEGUaGZH+lOcb6 xsTOzCMZGy1ZT/S9aH0XgNBhuwxT8P9ZPnfttHw69Tj6oDbt0rr23cNSUqGXTcpoan+d tWkC6s0yomyBfxIPiXBsnJF6sI4NLGUitJd5vfICz9PaJepX+ddP8J/Rx/vgiN7xvaYP vNHO3s5W4246tyWfOb1WUBg9N5Dy35Wj1+Kmt00MKmBHnqNgnSgsG662mh5k3hKWC1fC aF4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730302230; x=1730907030; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EjKcunrCqABMsfKlxzqU1Ip8DOGMIT1Kxye1UV2fjx4=; b=omFv0nuMUtMdXR5iTFqcfUvhg+YpdODZCGREpTY/rvRs2l34kU/7QZiL56C8gO6zMq W25VNLltx1vRYhYKhL6NeNJCvq+Cnpau9PxSRU/9KXBVHC7POr6OnYZGt7k/gGnyzG// rKJHmwJWs2K3v5QQSXRA3gy0I8aZ4C5gup5sJYFpbGincWrzH2fHRPSpZlvBOJBIrVT7 DBTj7iexy44Z/OKMe4wNcWv+udl+XxRs8tpLomKqkFVA5xut2oNWUKlbwZaL7qGBQA/8 kuxBwbnexElRvh4wdBsXBrKvQAI72/Uz5N2JShmetnH7EmSN1ph1rLQyqyLXjztEbaGv gdDg== X-Forwarded-Encrypted: i=1; AJvYcCU+FWLPgCo/klRhXkulzoMphKU9BiUspVbkbHNr6tu7vobgw8qq2F4iXS4e5UPDT9WV37oRzwy7AGA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywee50cmLCLsQURLDR4ruUhIKk7mfihc+2X1Y5i10WKBC2KuqEt 4OOtjJAvjOoozCbEvJZzXmMBMe9Z4Trg+d8DtHp6UVPJ3l6zjnGxyEe4CEEgwVo= X-Google-Smtp-Source: AGHT+IHfBCtOgUgkZAkJ11CMypXtDw0ZxLKNpZGCaF44/M73Ql+TqyQy0VF9AgOWsH5HOFfKI4JmyA== X-Received: by 2002:adf:e742:0:b0:37d:4610:dca with SMTP id ffacd0b85a97d-38186a22c7dmr4997143f8f.31.1730302229783; Wed, 30 Oct 2024 08:30:29 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:8261:5fff:fe11:bdda]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b3c236sm15604040f8f.35.2024.10.30.08.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 08:30:29 -0700 (PDT) From: Neil Armstrong Date: Wed, 30 Oct 2024 16:30:24 +0100 Subject: [PATCH v4 3/3] iio: magnetometer: add Allegro MicroSystems ALS31300 3-D Linear Hall Effect driver Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241030-topic-input-upstream-als31300-v4-3-494297c9e50a@linaro.org> References: <20241030-topic-input-upstream-als31300-v4-0-494297c9e50a@linaro.org> In-Reply-To: <20241030-topic-input-upstream-als31300-v4-0-494297c9e50a@linaro.org> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen Cc: Andy Shevchenko , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Neil Armstrong , Andy Shevchenko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=16893; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=eBIMnCBQaNpLn7U3M2W2glS1xKvGKBEbt3HjuFgJPmU=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBnIlERx3371zLVpUEseNQgapQfPxNy238UakfGXWHo 6TEQxBGJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZyJREQAKCRB33NvayMhJ0Y9ND/ 9kNuFYnykly3KPbZXEzljuNJS3ADHoy3AI/g3odzyh9hmiEEaevC/Odix0nc5KUAtL2HH/8ZZMcNbE XXbYU54IT583fV9aW29dFsYKP3AsIsXPyJyVNbiClInFzc6IgLy4wvtyMZAVC9w/16q3Aj4In2Mkka S8Ab1MkneTMIy54IYvXBP1tgmPOQ1D6uzpvTQ8mJ2o97F6DdoW1uTIeUyIjJ5rElzTTO7uGsZbz8p/ YRkAXSRiXpHqn/yTTquZ17sqNHCOz30x9VwGYW2WZrWqQ8meTXs7Y30QO+6pDYZOBrvNhax6Oy7E8D IvGsmAI9th6XNiJbjWuRCWrKSCo66HfVzoOhTawyyt0ip/cF93QXWqPgQnn3ubN8s7o8IAg7X2APcR JXAUaInDU3NN/90dxavx4Tzzudepe2XD++IJud64rOyurDPT3F58vDhkFq8fFpxpLnyY32cFTqmtd7 zQDBUT6vQvRjMWxoZAuW75jkr+/hGGZsJf56PiwVlYa9ZCDu1RIhBOBcqqYtG1x8/8lVU5yP1FAx5u 4F4uoJt8H3asPmosTQ4UcuLB1bLvl5/mFl/dqSvFwfLUqX+ASC63uDBLJ4To0JyP+o/Fo3qbPYa15h s9elKNvDgoVTmIFup76gldOl7b48hRsvJDRUKOKR9lIFgLt2jHsWRXuhjptw== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE The Allegro MicroSystems ALS31300 is a 3-D Linear Hall Effect Sensor mainly used for 3D head-on motion sensing applications. The device is configured over I2C, and as part of the Sensor data the temperature core is also provided. While the device provides an IRQ gpio, it depends on a configuration programmed into the internal EEPROM, thus only the default mode is supported and buffered input via trigger is also supported to allow streaming values with the same sensing timestamp. The device can be configured with different sensitivities in factory, but the sensitivity value used to calculate value into the Gauss unit is not available from registers, thus the sensitivity is provided by the compatible/device-id string which is based on the part number as described in the datasheet page 2. Reviewed-by: Andy Shevchenko Signed-off-by: Neil Armstrong --- drivers/iio/magnetometer/Kconfig | 13 + drivers/iio/magnetometer/Makefile | 1 + drivers/iio/magnetometer/als31300.c | 494 ++++++++++++++++++++++++++++++++++++ 3 files changed, 508 insertions(+) diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig index 8eb718f5e50f3591082d33618b680ea22608fde8..e7adc11049d6f71b76da4569be4756e65f9dfd28 100644 --- a/drivers/iio/magnetometer/Kconfig +++ b/drivers/iio/magnetometer/Kconfig @@ -52,6 +52,19 @@ config AK09911 help Deprecated: AK09911 is now supported by AK8975 driver. +config ALS31300 + tristate "Allegro MicroSystems ALS31300 3-D Linear Hall Effect Sensor" + depends on I2C + select REGMAP_I2C + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + Say yes here to build support for the Allegro MicroSystems + ALS31300 Hall Effect Sensor through its I2C interface. + + To compile this driver as a module, choose M here: the + module will be called als31300. + config BMC150_MAGN tristate select IIO_BUFFER diff --git a/drivers/iio/magnetometer/Makefile b/drivers/iio/magnetometer/Makefile index ec5c46fbf999b6403593de2c425079cf69a29cac..3e4c2ecd9adf865025d169a0d1d5feffd012e2f3 100644 --- a/drivers/iio/magnetometer/Makefile +++ b/drivers/iio/magnetometer/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_AF8133J) += af8133j.o obj-$(CONFIG_AK8974) += ak8974.o obj-$(CONFIG_AK8975) += ak8975.o +obj-$(CONFIG_ALS31300) += als31300.o obj-$(CONFIG_BMC150_MAGN) += bmc150_magn.o obj-$(CONFIG_BMC150_MAGN_I2C) += bmc150_magn_i2c.o obj-$(CONFIG_BMC150_MAGN_SPI) += bmc150_magn_spi.o diff --git a/drivers/iio/magnetometer/als31300.c b/drivers/iio/magnetometer/als31300.c new file mode 100644 index 0000000000000000000000000000000000000000..87b60c4e81fa1c9d8d6e8b083c5bcb605baf8ee9 --- /dev/null +++ b/drivers/iio/magnetometer/als31300.c @@ -0,0 +1,494 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Driver for the Allegro MicroSystems ALS31300 3-D Linear Hall Effect Sensor + * + * Copyright (c) 2024 Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +/* + * The Allegro MicroSystems ALS31300 has an EEPROM space to configure how + * the device works and how the interrupt line behaves. + * Only the default setup with external trigger is supported. + * + * While the bindings supports declaring an interrupt line, those + * events are not supported. + * + * It should be possible to adapt the driver to the current + * device EEPROM setup at runtime. + */ + +#define ALS31300_EEPROM_CONFIG 0x02 +#define ALS31300_EEPROM_INTERRUPT 0x03 +#define ALS31300_EEPROM_CUSTOMER_1 0x0d +#define ALS31300_EEPROM_CUSTOMER_2 0x0e +#define ALS31300_EEPROM_CUSTOMER_3 0x0f +#define ALS31300_VOL_MODE 0x27 +#define ALS31300_VOL_MODE_LPDCM GENMASK(6, 4) +#define ALS31300_LPDCM_INACTIVE_0_5_MS 0 +#define ALS31300_LPDCM_INACTIVE_1_0_MS 1 +#define ALS31300_LPDCM_INACTIVE_5_0_MS 2 +#define ALS31300_LPDCM_INACTIVE_10_0_MS 3 +#define ALS31300_LPDCM_INACTIVE_50_0_MS 4 +#define ALS31300_LPDCM_INACTIVE_100_0_MS 5 +#define ALS31300_LPDCM_INACTIVE_500_0_MS 6 +#define ALS31300_LPDCM_INACTIVE_1000_0_MS 7 +#define ALS31300_VOL_MODE_SLEEP GENMASK(1, 0) +#define ALS31300_VOL_MODE_ACTIVE_MODE 0 +#define ALS31300_VOL_MODE_SLEEP_MODE 1 +#define ALS31300_VOL_MODE_LPDCM_MODE 2 +#define ALS31300_VOL_MSB 0x28 +#define ALS31300_VOL_MSB_TEMPERATURE GENMASK(5, 0) +#define ALS31300_VOL_MSB_INTERRUPT BIT(6) +#define ALS31300_VOL_MSB_NEW_DATA BIT(7) +#define ALS31300_VOL_MSB_Z_AXIS GENMASK(15, 8) +#define ALS31300_VOL_MSB_Y_AXIS GENMASK(23, 16) +#define ALS31300_VOL_MSB_X_AXIS GENMASK(31, 24) +#define ALS31300_VOL_LSB 0x29 +#define ALS31300_VOL_LSB_TEMPERATURE GENMASK(5, 0) +#define ALS31300_VOL_LSB_HALL_STATUS GENMASK(7, 7) +#define ALS31300_VOL_LSB_Z_AXIS GENMASK(11, 8) +#define ALS31300_VOL_LSB_Y_AXIS GENMASK(15, 12) +#define ALS31300_VOL_LSB_X_AXIS GENMASK(19, 16) +#define ALS31300_VOL_LSB_INTERRUPT_WRITE BIT(20) +#define ALS31300_CUSTOMER_ACCESS 0x35 + +#define ALS31300_DATA_X_GET(b) \ + sign_extend32(FIELD_GET(ALS31300_VOL_MSB_X_AXIS, b[0]) << 4 | \ + FIELD_GET(ALS31300_VOL_LSB_X_AXIS, b[1]), 11) +#define ALS31300_DATA_Y_GET(b) \ + sign_extend32(FIELD_GET(ALS31300_VOL_MSB_Y_AXIS, b[0]) << 4 | \ + FIELD_GET(ALS31300_VOL_LSB_Y_AXIS, b[1]), 11) +#define ALS31300_DATA_Z_GET(b) \ + sign_extend32(FIELD_GET(ALS31300_VOL_MSB_Z_AXIS, b[0]) << 4 | \ + FIELD_GET(ALS31300_VOL_LSB_Z_AXIS, b[1]), 11) +#define ALS31300_TEMPERATURE_GET(b) \ + (FIELD_GET(ALS31300_VOL_MSB_TEMPERATURE, b[0]) << 6 | \ + FIELD_GET(ALS31300_VOL_LSB_TEMPERATURE, b[1])) + +enum als31300_channels { + TEMPERATURE = 0, + AXIS_X, + AXIS_Y, + AXIS_Z, +}; + +struct als31300_variant_info { + u8 sensitivity; +}; + +struct als31300_data { + struct device *dev; + /* protects power on/off the device and access HW */ + struct mutex mutex; + const struct als31300_variant_info *variant_info; + struct regmap *map; +}; + +/* The whole measure is split into 2x32-bit registers, we need to read them both at once */ +static int als31300_get_measure(struct als31300_data *data, + u16 *t, s16 *x, s16 *y, s16 *z) +{ + u32 buf[2]; + int ret, err; + + guard(mutex)(&data->mutex); + + ret = pm_runtime_resume_and_get(data->dev); + if (ret) + return ret; + + /* + * Loop until data is valid, new data should have the + * ALS31300_VOL_MSB_NEW_DATA bit set to 1. + * Max update rate is 2KHz, wait up to 1ms. + */ + ret = read_poll_timeout(regmap_bulk_read, err, + err || FIELD_GET(ALS31300_VOL_MSB_NEW_DATA, buf[0]), + 20, USEC_PER_MSEC, false, + data->map, ALS31300_VOL_MSB, buf, ARRAY_SIZE(buf)); + /* Bail out on read_poll_timeout() error */ + if (ret) + goto out; + + /* Bail out on regmap_bulk_read() error */ + if (err) { + dev_err(data->dev, "read data failed, error %d\n", ret); + ret = err; + goto out; + } + + *t = ALS31300_TEMPERATURE_GET(buf); + *x = ALS31300_DATA_X_GET(buf); + *y = ALS31300_DATA_Y_GET(buf); + *z = ALS31300_DATA_Z_GET(buf); + +out: + pm_runtime_mark_last_busy(data->dev); + pm_runtime_put_autosuspend(data->dev); + + return ret; +} + +static int als31300_read_raw(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, int *val, + int *val2, long mask) +{ + struct als31300_data *data = iio_priv(indio_dev); + s16 x, y, z; + u16 t; + int ret; + + switch (mask) { + case IIO_CHAN_INFO_PROCESSED: + case IIO_CHAN_INFO_RAW: + ret = als31300_get_measure(data, &t, &x, &y, &z); + if (ret) + return ret; + + switch (chan->address) { + case TEMPERATURE: + *val = t; + return IIO_VAL_INT; + case AXIS_X: + *val = x; + return IIO_VAL_INT; + case AXIS_Y: + *val = y; + return IIO_VAL_INT; + case AXIS_Z: + *val = z; + return IIO_VAL_INT; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_TEMP: + /* + * Fractional part of: + * 1000 * 302 * (value - 1708) + * temp = ---------------------------- + * 4096 + * to convert temperature in millicelcius. + */ + *val = MILLI * 302; + *val2 = 4096; + return IIO_VAL_FRACTIONAL; + case IIO_MAGN: + /* + * Devices are configured in factory + * with different sensitivities: + * - 500 GAUSS <-> 4 LSB/Gauss + * - 1000 GAUSS <-> 2 LSB/Gauss + * - 2000 GAUSS <-> 1 LSB/Gauss + * with translates by a division of the returned + * value to get Gauss value. + * The sensitivity cannot be read at runtime + * so the value depends on the model compatible + * or device id. + */ + *val = 1; + *val2 = data->variant_info->sensitivity; + return IIO_VAL_FRACTIONAL; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_OFFSET: + switch (chan->type) { + case IIO_TEMP: + *val = -1708; + return IIO_VAL_INT; + default: + return -EINVAL; + } + default: + return -EINVAL; + } +} + +static irqreturn_t als31300_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct als31300_data *data = iio_priv(indio_dev); + struct { + u16 temperature; + s16 channels[3]; + aligned_s64 timestamp; + } scan; + s16 x, y, z; + int ret; + u16 t; + + ret = als31300_get_measure(data, &t, &x, &y, &z); + if (ret) + goto trigger_out; + + scan.temperature = t; + scan.channels[0] = x; + scan.channels[1] = y; + scan.channels[2] = z; + iio_push_to_buffers_with_timestamp(indio_dev, &scan, + pf->timestamp); + +trigger_out: + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + +#define ALS31300_AXIS_CHANNEL(axis, index) \ + { \ + .type = IIO_MAGN, \ + .modified = 1, \ + .channel2 = IIO_MOD_##axis, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .address = index, \ + .scan_index = index, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 12, \ + .storagebits = 16, \ + .endianness = IIO_CPU, \ + }, \ + } + +static const struct iio_chan_spec als31300_channels[] = { + { + .type = IIO_TEMP, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_OFFSET), + .address = TEMPERATURE, + .scan_index = TEMPERATURE, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .endianness = IIO_CPU, + }, + }, + ALS31300_AXIS_CHANNEL(X, AXIS_X), + ALS31300_AXIS_CHANNEL(Y, AXIS_Y), + ALS31300_AXIS_CHANNEL(Z, AXIS_Z), + IIO_CHAN_SOFT_TIMESTAMP(4), +}; + +static const struct iio_info als31300_info = { + .read_raw = als31300_read_raw, +}; + +static int als31300_set_operating_mode(struct als31300_data *data, + unsigned int val) +{ + int ret; + + ret = regmap_update_bits(data->map, ALS31300_VOL_MODE, + ALS31300_VOL_MODE_SLEEP, val); + if (ret) { + dev_err(data->dev, "failed to set operating mode (%pe)\n", ERR_PTR(ret)); + return ret; + } + + /* The time it takes to exit sleep mode is equivalent to Power-On Delay Time */ + if (val == ALS31300_VOL_MODE_ACTIVE_MODE) + fsleep(600); + + return 0; +} + +static void als31300_power_down(void *data) +{ + als31300_set_operating_mode(data, ALS31300_VOL_MODE_SLEEP_MODE); +} + +static const struct iio_buffer_setup_ops als31300_setup_ops = {}; + +static const unsigned long als31300_scan_masks[] = { GENMASK(3, 0), 0 }; + +static bool als31300_volatile_reg(struct device *dev, unsigned int reg) +{ + return reg == ALS31300_VOL_MSB || reg == ALS31300_VOL_LSB; +} + +static const struct regmap_config als31300_regmap_config = { + .reg_bits = 8, + .val_bits = 32, + .max_register = ALS31300_CUSTOMER_ACCESS, + .volatile_reg = als31300_volatile_reg, +}; + +static int als31300_probe(struct i2c_client *i2c) +{ + struct device *dev = &i2c->dev; + struct als31300_data *data; + struct iio_dev *indio_dev; + int ret; + + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + data->dev = dev; + i2c_set_clientdata(i2c, indio_dev); + + ret = devm_mutex_init(dev, &data->mutex); + if (ret) + return ret; + + data->variant_info = i2c_get_match_data(i2c); + if (!data->variant_info) + return -EINVAL; + + data->map = devm_regmap_init_i2c(i2c, &als31300_regmap_config); + if (IS_ERR(data->map)) + return dev_err_probe(dev, PTR_ERR(data->map), + "failed to allocate register map\n"); + + ret = devm_regulator_get_enable(dev, "vcc"); + if (ret) + return dev_err_probe(dev, ret, "failed to enable regulator\n"); + + ret = als31300_set_operating_mode(data, ALS31300_VOL_MODE_ACTIVE_MODE); + if (ret) + return dev_err_probe(dev, ret, "failed to power on device\n"); + + ret = devm_add_action_or_reset(dev, als31300_power_down, data); + if (ret) + return dev_err_probe(dev, ret, "failed to add powerdown action\n"); + + indio_dev->info = &als31300_info; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->name = i2c->name; + indio_dev->channels = als31300_channels; + indio_dev->num_channels = ARRAY_SIZE(als31300_channels); + indio_dev->available_scan_masks = als31300_scan_masks; + + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, + iio_pollfunc_store_time, + als31300_trigger_handler, + &als31300_setup_ops); + if (ret < 0) + return dev_err_probe(dev, ret, "iio triggered buffer setup failed\n"); + + ret = pm_runtime_set_active(dev); + if (ret < 0) + return ret; + + ret = devm_pm_runtime_enable(dev); + if (ret) + return ret; + + pm_runtime_get_noresume(dev); + pm_runtime_set_autosuspend_delay(dev, 200); + pm_runtime_use_autosuspend(dev); + + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + + ret = devm_iio_device_register(dev, indio_dev); + if (ret) + return dev_err_probe(dev, ret, "device register failed\n"); + + return 0; +} + +static int als31300_runtime_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct als31300_data *data = iio_priv(indio_dev); + + return als31300_set_operating_mode(data, ALS31300_VOL_MODE_SLEEP_MODE); +} + +static int als31300_runtime_resume(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct als31300_data *data = iio_priv(indio_dev); + + return als31300_set_operating_mode(data, ALS31300_VOL_MODE_ACTIVE_MODE); +} + +static DEFINE_RUNTIME_DEV_PM_OPS(als31300_pm_ops, + als31300_runtime_suspend, als31300_runtime_resume, + NULL); + +static const struct als31300_variant_info al31300_variant_500 = { + .sensitivity = 4, +}; + +static const struct als31300_variant_info al31300_variant_1000 = { + .sensitivity = 2, +}; + +static const struct als31300_variant_info al31300_variant_2000 = { + .sensitivity = 1, +}; + +static const struct i2c_device_id als31300_id[] = { + { + .name = "als31300-500", + .driver_data = (kernel_ulong_t)&al31300_variant_500, + }, + { + .name = "als31300-1000", + .driver_data = (kernel_ulong_t)&al31300_variant_1000, + }, + { + .name = "als31300-2000", + .driver_data = (kernel_ulong_t)&al31300_variant_2000, + }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(i2c, als31300_id); + +static const struct of_device_id als31300_of_match[] = { + { + .compatible = "allegromicro,als31300-500", + .data = &al31300_variant_500, + }, + { + .compatible = "allegromicro,als31300-1000", + .data = &al31300_variant_1000, + }, + { + .compatible = "allegromicro,als31300-2000", + .data = &al31300_variant_2000, + }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, als31300_of_match); + +static struct i2c_driver als31300_driver = { + .driver = { + .name = "als31300", + .of_match_table = als31300_of_match, + .pm = pm_ptr(&als31300_pm_ops), + }, + .probe = als31300_probe, + .id_table = als31300_id, +}; +module_i2c_driver(als31300_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("ALS31300 3-D Linear Hall Effect Driver"); +MODULE_AUTHOR("Neil Armstrong ");