From nobody Mon Nov 25 05:34:34 2024 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 53F8C206E82 for ; Tue, 29 Oct 2024 14:13:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730211225; cv=none; b=VZ4ETrYB0RVskGcJPegsedj6zdX9T4XaIFtAA5F/L8koHVwoqd0lTU2HdN+tpDSPp/5ocsw7s4Fif0NgierDt3mOEejXy79VUzmSBnBscAKi1pSnEHMUnyJBYR9ChcO/+lAXD9Ff8AwaSK4PdSwOYQiPp08qfpXv8V0F519QNPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730211225; c=relaxed/simple; bh=AXp9R9SIchOWcn52tYxCXMRJHbP1cxB3uaJJrIOcnfc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A75nv0xS2q5z15qEEQj21Ej4SFJDYF7Nr6tVHMnqRkkojfM1i1ljX/IWlytGak8No6q0RiMiwhivNKAb1AkApaiKPMeAGSYvL8oz1L6eoC/07Cmpa2uSDfD3zQxyxe9DIvqqJlR529em+CXmrJq9Lfbw3F0xXG01xj2mA8RjSjI= 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=CCuA58Og; arc=none smtp.client-ip=209.85.221.51 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="CCuA58Og" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-37d447de11dso3964843f8f.1 for ; Tue, 29 Oct 2024 07:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730211222; x=1730816022; 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=CCuA58OgDYBbBjFyh1CAqzNsQhoEVgojZpWroDbROB/7Q9LpVU2I8kHNO+jpwjnisv p/otTc2QcmtWD2fsHoLZjjagSpa8Igzr5zAKRO6fslZZGLil1lTn/n9PGZUVfNJAe1l2 rZmVCsUYzw/6UFqDsRoTdrh1aWHm4PVYJRWFpB/INILZudckrrLAuNsm1kfDd6I8w98f eehTfQuEX9f0QzsFDAJ6CkC+9j7u7E+Do2X50QXIbBD7IWTcl6UDgXwmvec4KSxiyyKy qtWz+PTO0/cCk/EuWmYtNosTKW5/RkI5iLVO82+sDqLUoUWBpYKo0kd/DsZ0iTr6nFhZ K2uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730211222; x=1730816022; 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=wdNxPMgkuoOk9UUtJwQ0tCO8uOm0Z5BqFFcby5F22KOWG2ob8U2cMu+IEhuPnZoe7V fK0yTOBHSPlQAp03zR56lhHm4mfXrmYnFihLQ0DMKgBhDOX4Xkb6XBqu+LFgPOyQkUCd ZyMQ72EphZmDMjM1wQ0uB+xqdyte4xjVcm1fb7VrYaPywy9qtx0Oz4SzT4hJ0b1NzrJl h9Ta+jx34fu29cDfkPM/412DVkxfMOhU2oHqOsfKtCVIL4IQXmnJBlCDo5kOhQ/W5hX1 YO7DrYiasp51JRH7V5n8hUr9V6dZJ4qwfPhBHB8nadqQklE0VRiA/yttL4KaB0/B7ZdB WI1g== X-Forwarded-Encrypted: i=1; AJvYcCVn0HhqKwqYWIF/9hSPp/lcH0Y8CMsvTxCyGCauw9OfxGjMVTB1cfBWyClW4hiEhJzJB24bwV2mj4W6URg=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5n2B9c1Ckkgpa6DEWniEgEVZfc6RXcz8XZxf7MjsC50EUfeD7 yfRhayj0PVlgalnXnALNAqomHTSjYvKHRa/u6xqgda9wL6e1W+GMVGhEPzZmzgM= X-Google-Smtp-Source: AGHT+IG/hANPxkI3R9mBrqcqUgKe6T1qP2N9UPHnkqj3K1X9544Fi2caie3EUqjCpOM1e1Zz2xCWIQ== X-Received: by 2002:adf:e84f:0:b0:37c:cbd4:ec9 with SMTP id ffacd0b85a97d-3806110a2d1mr8704442f8f.5.1730211221583; Tue, 29 Oct 2024 07:13:41 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b714fesm12645871f8f.71.2024.10.29.07.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 07:13:41 -0700 (PDT) From: Neil Armstrong Date: Tue, 29 Oct 2024 15:13:37 +0100 Subject: [PATCH v3 1/3] dt-bindings: vendor-prefixes: Add Allegro MicroSystems, Inc Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-topic-input-upstream-als31300-v3-1-147926dd63b3@linaro.org> References: <20241029-topic-input-upstream-als31300-v3-0-147926dd63b3@linaro.org> In-Reply-To: <20241029-topic-input-upstream-als31300-v3-0-147926dd63b3@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/ZANAwAKAXfc29rIyEnRAcsmYgBnIO2SZASliDAzrjxamRLhdEuyRSBI+fHNaTvToFWt tSqwr2KJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZyDtkgAKCRB33NvayMhJ0eHAD/ 9RjQH7h0Oyev8CZhPUhsgRTdRv56Wwh1n3zN7PK6GSARAU1V5O6e22pkrwe5vVD/dNJ0AnLnqC+UM/ CR2fF6o1mh2K8wXYREBQRlsRt8s96ATSIzjGyZT3sLtGogcRY2nJf8an5SqlqCm8A2ff3or2vt24Fg HsD2F7RKMbeyBcWpmjpTLcYBuG6H63Uz0PE6vr+nQIuEtW012FFMrrNDwcPRghA/S1i750wxp4J7RS zIVzqH/AOxzR9758J9FGM3xECG27opGfmBsMfB7Ol1JYD1Utzd+cBG7l1pn/ccG39oDvZK4XrpIIKH fhYQMXLRlaZ62fl8Yh9e3BeHAls2Azm93wbvvEItw6B5dFdlqj0ylbeuUqHgGjsW09YlY0nkDMaAYo YBXURLYxATu2UBH/WofqvRpeO8cCUkXTXb+ClAi5d4PK95HzzqaV/07Z/DYz/Mteen6vWLYPUubAbZ AWBie9SQs+A6JznwFTfLU9TuejHMIcSKazY84DHW0HBp1nv75e4KDJojLdB1R5Axhoj5glktu1W0tR 7VApgDIeHQjMvTOuZ40WDxp68qeQO9RbMpp0IF2OFHwbJgDR6mMjv5ixYkKOeWnnBzuX7QlB61jGu8 ou0yVbBM5r/v7ogI+qqxdRnRVaXfwHBklkLaNqMFSiYazPYDUohUP7lZUjrg== 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/Docum= entation/devicetree/bindings/vendor-prefixes.yaml index 15877574a4172cbd9395bed531555cfb009ff010..b90355c2b45ada6e20335cd5bb2= aace9410e4d3a 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,.*": --=20 2.34.1 From nobody Mon Nov 25 05:34:34 2024 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 1EBB9206E9C for ; Tue, 29 Oct 2024 14:13:43 +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=1730211227; cv=none; b=mpRc9g6t2+yEE2Rm9x6XaEHSBp8BwdBof1APkSg02058IDGZU3PKIyoUJmcfMtOUC5+2gV/8MwSV4+7zpR019Mc3Xw6w/UejJoO2eYqhms3PgObEpl2HEmx/7VrG8ojDfLRKomAW8rZgozDZIsMkncVfy4Vi6d2kkuDT/vm2U6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730211227; c=relaxed/simple; bh=VCywuuwYQzUwDiW7Kdz78e0AbhF/gpt3Et+zeQEyoQ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nkMNsMyXEk1HZel3ROhB0yOvWh92JCeUmsDUwpjNer0EZiAJYjILAXjX5dZwsKnmGY6cNjXBJKD2Ct1F4eFrrsdEs6+fE/O35YGiaLXuBKJcBEUBRGfpGImYFfaOHttKh50sluZdm6T3Du50M6bclKgK1QG52Q0oTt1+3OpP68M= 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=w0B6H6gr; 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="w0B6H6gr" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-37d51055097so3622512f8f.3 for ; Tue, 29 Oct 2024 07:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730211222; x=1730816022; 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=w0B6H6grrZTf9LYuCqniN7K+4zleCPWAo8pBC/Bx9lvRcRH37WOrSUi+zr4Pj+RGzI f5Ixd4iQZcWDVfTcmy78cPa9Vlniiua9X6uBDq6oULFFKp2dW7vRJKmh8h24YFUjCdWo clTSZqGQFof7sXOQ3+Y2A7MIiQFQOmPMIx485HK2U6a0Zr7L0UFK8uxyLovMdiqeyExj Bi297J+9QhyMPj7jluMhzl/xewqp9s7+EcZmoTaDdLWtytPnW6ju7AIHRLR96LKNDyD/ iAreSzeBkDKcvAuYSfBp77oNMAiF8dZcbtUXkMMUsKN0lUWklEDLU7JzP65LGN8WzgO9 82iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730211222; x=1730816022; 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=F7PAZS3dixF7dZaLov1ATrh1fm40bFQNdsN6yJGBHpncGE+H1G46QGlL9CZvjWTndE Kf87QJLEuQrjIJ+kKUgI1aUw2ixJvac+oV/xELo6OA4ZZotk/W0p9SchWO8q3gRfRw0A tRBtRPXbfNxB8SmpnXwDMKO8z29dBVdMvK92s32F2yTlAHUcOBCMLtPayTod+k7C/sm3 2/9MSLmf/pYhmshHz8zwNCCTFFlrww0DdmLehecljEM8a+y04b637AB3abmU/ig1PKbj Fd1nTiiL9kMdzIT30buJWDJ1H2bIwyiKUReL0lQbvYJQ4qAwxx7+9DofFVkKcd74vYbh 9A/A== X-Forwarded-Encrypted: i=1; AJvYcCWmSPItzhAIwn0VhHSkDdwxhx2hiwsfgW5WmgyzPRq03IC2FBK3jWkMbFozZa6cswNn6rFbm++2rsMu/Eg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw6nQlqj5/0q/y5DEUwZeoxywe3hGnRZZj/JMq8puMgOQwQgXOH DtkPqt7mi6JX3kuqm9bneAvfX2YitRp2uk1KS23Ku/60g+vHPmrj/dnbSTBSQ1U= X-Google-Smtp-Source: AGHT+IEhSzI6MkzwuSBStylVFC99ApyDudmpuZxswYmr9kO8wAK54bjE2YK9NngMaJuM8w1OYco1Aw== X-Received: by 2002:adf:ff87:0:b0:37d:4dcc:7fb4 with SMTP id ffacd0b85a97d-380610f4425mr8604397f8f.10.1730211222424; Tue, 29 Oct 2024 07:13:42 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b714fesm12645871f8f.71.2024.10.29.07.13.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 07:13:42 -0700 (PDT) From: Neil Armstrong Date: Tue, 29 Oct 2024 15:13:38 +0100 Subject: [PATCH v3 2/3] dt-bindings: iio: magnetometer: document the Allegro MicroSystems ALS31300 3-D Linear Hall Effect Sensor Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-topic-input-upstream-als31300-v3-2-147926dd63b3@linaro.org> References: <20241029-topic-input-upstream-als31300-v3-0-147926dd63b3@linaro.org> In-Reply-To: <20241029-topic-input-upstream-als31300-v3-0-147926dd63b3@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/ZANAwAKAXfc29rIyEnRAcsmYgBnIO2Tl/Vg2+ITYFpFcJV1+DuC8PrAmVDuyChXwu1/ hvWYioSJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZyDtkwAKCRB33NvayMhJ0WxKEA CLoWyTN9jcuu4PtCNp7x468keVemyG4Goe59+9t+JRbNQvh3mavFYoB5rWhZJQnlmGK5C2H0ZrhmYK UDm+zC3ziHxJzc3UK3Oi0gSZ3U9RRW6cL9zwG2SiZFasblB2xK2rpmAw/4wyHqp1XbHOfpquV3uLbc zXxyvY4WXhmW1jPk8RXIzNgMsp7zkWlI6lp6HiEoB7Qfz8bETrCvwTAp+LnmYHr3k63TfYuEuMRFwF eAUkQyI/WtCdwT2IYKNOETxdqYCDFSntOOWMSzATnWWRWTpwkZk92M6A7QZ0BtjNpcao8y9lVFPtYo FAUVbRZa/Eh+dwQtZB/59E73blGeD3tg1S8rydHsKms7XK+Au4lf2QWqCydh01HJk+QsfmN3vet/Yx gSHPrc62Q8D7fpyAZ9gt+Td03t9WjgDqUF6y/JugYoGPnm4JXkydtBklNX+FdAym4SF7Y6xu1Q27rR qCVpz7pCjEJcmuCrLZC13qYAcYjxe3BZqd6TBX/t2pGIX4nlnxFbkKQhHN5baVhvsxhP1gZuCjYRu6 sHAF4K0pTsHzHX3g8rxjNQdnhkJ7Y0qZCueXBYynR2v1KHjHwzSwxE7V2eDADSVT5gDb4A6up5QMAO xe27VY5Zdi1Taxmdmv/j7btsYDXVePzh1Lv/gvG1C0PJKS6/D8S9HK+5AsPQ== 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-d= atasheet.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/allegromicr= o,als31300.yaml b/Documentation/devicetree/bindings/iio/magnetometer/allegr= omicro,als31300.yaml new file mode 100644 index 0000000000000000000000000000000000000000..52e3781834ee9d98aa84c5d340a= e75ffbf76f925 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/magnetometer/allegromicro,als31= 300.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 inpu= t range + - allegromicro,als31300-2000 # Factory configured at 2000 Gauss inpu= t range + + reg: + maxItems: 1 + + vcc-supply: + description: 5.5V supply + + interrupts: + maxItems: 1 + +required: + - compatible + +additionalProperties: false + +examples: + - | + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + magnetometer@61 { + compatible =3D "allegromicro,als31300-500"; + reg =3D <0x61>; + vcc-supply =3D <&hall_vcc>; + }; + }; --=20 2.34.1 From nobody Mon Nov 25 05:34:34 2024 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.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 0EAD6206E9A for ; Tue, 29 Oct 2024 14:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730211229; cv=none; b=Gp37WyR5A+yLHWEHQvAst8qKqQHyq4uvv3oBD7S/cESDWHxVBNjLzHNrJ2YXkpCOl3dUpBDvyGHTzl4cnz1wPS9eSwCEqwJkkchttwP65OZL5QnrJbeuHU2xXxN/1FGMG1RAL62itABGZudqef+ipXBUKF1FmCOX1qTAJq7rwpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730211229; c=relaxed/simple; bh=BXdjI2YlKCR7g+MKVbJZnNL02lIFvK1zn+GNQyze4Qk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uJYV0bWRAi34sPjReQ9E8lAvU0dZCWj5g0N5D9K6QLpKd4cvGy5KG9DPlD0kdUQzbimpTR0M3XkxKM7JQsPx0DWz7yFCbe+7GDEuCt2r0YLBEnO29xOWag/ThagJ4By3xtxyUWK/MtHwuS8NVbfo/HckvsNePq0OaJuHRFYERl0= 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=tzxIMJcE; arc=none smtp.client-ip=209.85.221.49 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="tzxIMJcE" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-37d4d1b48f3so4059815f8f.1 for ; Tue, 29 Oct 2024 07:13:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730211223; x=1730816023; 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=RxIS8WnfphWdKVLUFiCF93GyflCiZBVANXevZugUg+g=; b=tzxIMJcEvg+6YfJPRCR/bcEhcXlfCUn7rGLSCfjCB3mseXiPg/WV85xfPqLizLRpW6 vLHiaVLpp+5NlDi2mbbpCJuha/DXmKDO91AF/PQKuVrN1Z3rhGjt8j7s1ucq6Qs4h1gv Qu0G5dkruZoDdTzJEqei9DcenV8Ys3HVB+2Yp9OxcmMOSOqaAzuGlYNgoyfVsvWEIAej 7luT0MAyAp4lOAMXTKg1G5vEsjq2fj5hrpStuOv5ylhCUNuMv7qskVc9+lfJgqmwpdHv YSlZ9Q5Ol+s9sr+YGophC/CMA9ANGUCIRrIqnjPXztsx4hytYV3PPnSiqhDbb6EWr7fK dqwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730211223; x=1730816023; 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=RxIS8WnfphWdKVLUFiCF93GyflCiZBVANXevZugUg+g=; b=hESS3Q6K28MW8RxGZboXK7oxNqtcLC3noBEhCE0sfVPsI7XHVYnrASl5SmlXHonX3F MyfoXhs01J5NtPCWH+jkZZQlwL+2Rxc1HJIqoTt141RsDfi0FXn9J3RheK11YmeGRQPs 8W1VlCXxrAm43ymbYoAODARQgAT2rVv1/axwvgjw5brodTlgSlO3eNk5UzoHRdQqul2D ZKUwG0Ox4mUtqaG9YnxPmnflbfqaoqOLB6o/+dJbAS8BWI1NGHg3hah7zbV6Y8IjLNuK 5hXoRo/bc9Po205cRvePKZ55Oz2dsBLK85yTL0hsMtqOD1D9fmqwTJ1vK8ADxQI7Lebm 7XEA== X-Forwarded-Encrypted: i=1; AJvYcCUkFpnxrXnWmgZBw/3STfddCJecoBdkbXQQGv01RNB0GAo4QsqdaMzOlmGTRceYhZx2BdkqAbpECWGImrM=@vger.kernel.org X-Gm-Message-State: AOJu0YyK4kEjMOT4JtUguP8a3m4jj8ALcXpXEzyywuZYl5kddMWUzEhp ukMOWmM8k7kT3/b38PXPv794cDUAfTXcMLQjuWHThs9kCUhQik9m13+LXlc+ar0= X-Google-Smtp-Source: AGHT+IFf89MRh/3FsABXLHVZ5TiIgJ7DTf+gOc2x1sK1H0Yy5yRS3BDP+K9+vtPRc1vT92s5uOaJ7Q== X-Received: by 2002:a05:6000:149:b0:37c:d23a:1e4 with SMTP id ffacd0b85a97d-380611515eemr8852096f8f.30.1730211223364; Tue, 29 Oct 2024 07:13:43 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b714fesm12645871f8f.71.2024.10.29.07.13.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 07:13:42 -0700 (PDT) From: Neil Armstrong Date: Tue, 29 Oct 2024 15:13:39 +0100 Subject: [PATCH v3 3/3] iio: magnetometer: add Allegro MicroSystems ALS31300 3-D Linear Hall Effect driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-topic-input-upstream-als31300-v3-3-147926dd63b3@linaro.org> References: <20241029-topic-input-upstream-als31300-v3-0-147926dd63b3@linaro.org> In-Reply-To: <20241029-topic-input-upstream-als31300-v3-0-147926dd63b3@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=16824; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=BXdjI2YlKCR7g+MKVbJZnNL02lIFvK1zn+GNQyze4Qk=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBnIO2TkBX1s2PysOZmats1WfQMhwafBeS39Q2OvNch S6RPHumJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZyDtkwAKCRB33NvayMhJ0cC0D/ wIOJ9nejJtnakWtv9gr+RkwjXLtvQ6oRa+gwzNbYcyt6/EQRl+8REkLxWl5Azk+Wm657uEDAUYFcLj n8Tk2CfYtL8bx1AfLbIXLViA7lhacwtI/zzXXJnXUC1vqYDQ59BgX/5j/U4DP28w/J7ZwOfKlE65U8 oDFwQaA4crkj7rgh6MjGCCqA6mghf61zGUF/h5c4NLTzPSr/5JxaOnC4m0qKXlIaE2vZ8TG+ufI1sD 8xS+v2bUx9A/RMJ7NwhB8OD9pW1XMvMRcTvSYOWwdYWeC0tSbfqsgwGA3mjyhiqYP4X4PT46ddQPjY 3xVEQZQaxd03Tvafs9bfMonQdhCKnlBhFSPxRCegngS15GU0e/4H6SV/3lTiu45D4c1Oty2e3YhElY D+iuhXD6AaERSZohv5CVSZId3vAQw0mCMG+srSHZ6uW/PUcHnf1IOpiWlZVTmEjfSCbr0oYgWdjasy dppTLnJZejR5OhMpxY5knxcGCJt1PhjIhWfAM7dtJT4YWQVVCbFmSmXtAraQQHY/rTFn/5FSn5MCVD Ma/8yVOkRxFXuo+95LXpckK8p2T9/TXoNl3yiEEwdnac9w3UyTofr42z5ul3DN9CpRBsKA4l79zYqW 9+OcigvDtRkTn60octrO34AywZ8xmLBs913+TnhMR5f7tbygFe3gHS2EFbwg== 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. Signed-off-by: Neil Armstrong Reviewed-by: Andy Shevchenko --- drivers/iio/magnetometer/Kconfig | 13 + drivers/iio/magnetometer/Makefile | 1 + drivers/iio/magnetometer/als31300.c | 493 ++++++++++++++++++++++++++++++++= ++++ 3 files changed, 507 insertions(+) diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kc= onfig index 8eb718f5e50f3591082d33618b680ea22608fde8..e7adc11049d6f71b76da4569be4= 756e65f9dfd28 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. =20 +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/M= akefile index ec5c46fbf999b6403593de2c425079cf69a29cac..3e4c2ecd9adf865025d169a0d1d= 5feffd012e2f3 100644 --- a/drivers/iio/magnetometer/Makefile +++ b/drivers/iio/magnetometer/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_AF8133J) +=3D af8133j.o obj-$(CONFIG_AK8974) +=3D ak8974.o obj-$(CONFIG_AK8975) +=3D ak8975.o +obj-$(CONFIG_ALS31300) +=3D als31300.o obj-$(CONFIG_BMC150_MAGN) +=3D bmc150_magn.o obj-$(CONFIG_BMC150_MAGN_I2C) +=3D bmc150_magn_i2c.o obj-$(CONFIG_BMC150_MAGN_SPI) +=3D bmc150_magn_spi.o diff --git a/drivers/iio/magnetometer/als31300.c b/drivers/iio/magnetometer= /als31300.c new file mode 100644 index 0000000000000000000000000000000000000000..1cceac18c5ddd05ab8c81a541c0= e9dc30e404ab2 --- /dev/null +++ b/drivers/iio/magnetometer/als31300.c @@ -0,0 +1,493 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Driver for the Allegro MicroSystems ALS31300 3-D Linear Hall Effect Sen= sor + * + * 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 =3D 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 2x32bit 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 =3D 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 =3D 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 =3D err; + goto out; + } + + *t =3D ALS31300_TEMPERATURE_GET(buf); + *x =3D ALS31300_DATA_X_GET(buf); + *y =3D ALS31300_DATA_Y_GET(buf); + *z =3D 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 =3D 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 =3D als31300_get_measure(data, &t, &x, &y, &z); + if (ret) + return ret; + + switch (chan->address) { + case TEMPERATURE: + *val =3D t; + return IIO_VAL_INT; + case AXIS_X: + *val =3D x; + return IIO_VAL_INT; + case AXIS_Y: + *val =3D y; + return IIO_VAL_INT; + case AXIS_Z: + *val =3D 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 =3D ---------------------------- + * 4096 + * to convert temperature in millicelcius + */ + *val =3D MILLI * 302; + *val2 =3D 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 sensisitivity cannot be read at runtime + * so the value depends on the model compatible + * or device id. + */ + *val =3D 1; + *val2 =3D data->variant_info->sensitivity; + return IIO_VAL_FRACTIONAL; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_OFFSET: + switch (chan->type) { + case IIO_TEMP: + *val =3D -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 =3D p; + struct iio_dev *indio_dev =3D pf->indio_dev; + struct als31300_data *data =3D iio_priv(indio_dev); + struct { + u16 temperature; + s16 channels[3]; + aligned_s64 timestamp; + } scan; + s16 x, y, z; + int ret; + u16 t; + + ret =3D als31300_get_measure(data, &t, &x, &y, &z); + if (ret) + goto trigger_out; + + scan.temperature =3D t; + scan.channels[0] =3D x; + scan.channels[1] =3D y; + scan.channels[2] =3D 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 =3D IIO_MAGN, \ + .modified =3D 1, \ + .channel2 =3D IIO_MOD_##axis, \ + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .address =3D index, \ + .scan_index =3D index, \ + .scan_type =3D { \ + .sign =3D 's', \ + .realbits =3D 12, \ + .storagebits =3D 16, \ + .endianness =3D IIO_CPU, \ + }, \ + } + +static const struct iio_chan_spec als31300_channels[] =3D { + { + .type =3D IIO_TEMP, + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_OFFSET), + .address =3D TEMPERATURE, + .scan_index =3D TEMPERATURE, + .scan_type =3D { + .sign =3D 'u', + .realbits =3D 16, + .storagebits =3D 16, + .endianness =3D 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 =3D { + .read_raw =3D als31300_read_raw, +}; + +static int als31300_set_operating_mode(struct als31300_data *data, + unsigned int val) +{ + int ret; + + ret =3D 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 T= ime */ + if (val =3D=3D ALS31300_VOL_MODE_ACTIVE_MODE) + usleep_range(600, 650); + + 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 =3D {}; + +static const unsigned long als31300_scan_masks[] =3D { GENMASK(3, 0), 0 }; + +static bool als31300_volatile_reg(struct device *dev, unsigned int reg) +{ + return reg =3D=3D ALS31300_VOL_MSB || reg =3D=3D ALS31300_VOL_LSB; +} + +static const struct regmap_config als31300_regmap_config =3D { + .reg_bits =3D 8, + .val_bits =3D 32, + .max_register =3D ALS31300_CUSTOMER_ACCESS, + .volatile_reg =3D als31300_volatile_reg, +}; + +static int als31300_probe(struct i2c_client *i2c) +{ + struct device *dev =3D &i2c->dev; + struct als31300_data *data; + struct iio_dev *indio_dev; + int ret; + + indio_dev =3D devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data =3D iio_priv(indio_dev); + data->dev =3D dev; + i2c_set_clientdata(i2c, indio_dev); + + devm_mutex_init(dev, &data->mutex); + + data->variant_info =3D i2c_get_match_data(i2c); + if (!data->variant_info) + return -EINVAL; + + data->map =3D 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 =3D devm_regulator_get_enable(dev, "vcc"); + if (ret) + return dev_err_probe(dev, ret, "failed to enable regulator\n"); + + ret =3D 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 =3D 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 =3D &als31300_info; + indio_dev->modes =3D INDIO_DIRECT_MODE; + indio_dev->name =3D i2c->name; + indio_dev->channels =3D als31300_channels; + indio_dev->num_channels =3D ARRAY_SIZE(als31300_channels); + indio_dev->available_scan_masks =3D als31300_scan_masks; + + ret =3D 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 =3D pm_runtime_set_active(dev); + if (ret < 0) + return ret; + + ret =3D 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 =3D 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 =3D dev_get_drvdata(dev); + struct als31300_data *data =3D 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 =3D dev_get_drvdata(dev); + struct als31300_data *data =3D 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 =3D { + .sensitivity =3D 4, +}; + +static const struct als31300_variant_info al31300_variant_1000 =3D { + .sensitivity =3D 2, +}; + +static const struct als31300_variant_info al31300_variant_2000 =3D { + .sensitivity =3D 1, +}; + +static const struct i2c_device_id als31300_id[] =3D { + { + .name =3D "als31300-500", + .driver_data =3D (kernel_ulong_t)&al31300_variant_500, + }, + { + .name =3D "als31300-1000", + .driver_data =3D (kernel_ulong_t)&al31300_variant_1000, + }, + { + .name =3D "als31300-2000", + .driver_data =3D (kernel_ulong_t)&al31300_variant_2000, + }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(i2c, als31300_id); + +static const struct of_device_id als31300_of_match[] =3D { + { + .compatible =3D "allegromicro,als31300-500", + .data =3D &al31300_variant_500, + }, + { + .compatible =3D "allegromicro,als31300-1000", + .data =3D &al31300_variant_1000, + }, + { + .compatible =3D "allegromicro,als31300-2000", + .data =3D &al31300_variant_2000, + }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, als31300_of_match); + +static struct i2c_driver als31300_driver =3D { + .driver =3D { + .name =3D "als31300", + .of_match_table =3D als31300_of_match, + .pm =3D pm_ptr(&als31300_pm_ops), + }, + .probe =3D als31300_probe, + .id_table =3D als31300_id, +}; +module_i2c_driver(als31300_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("ALS31300 3-D Linear Hall Effect Driver"); +MODULE_AUTHOR("Neil Armstrong "); --=20 2.34.1