From patchwork Thu Sep 26 10:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 830885 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 A42441AE846; Thu, 26 Sep 2024 10:20:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346058; cv=none; b=nJkH0KVO9mBNnuUOr7Lcfv5JZkjE73jjVYQNwbDgYI+nj2IJsAmFllXGscfOs0xBAUqq4hPpxTzgRH6yyu5WNupN8JXsIE+bPRWLE5gZ7s82Cxm7o6GvVwQNGmS4zrDW5DbDCuINOGqwN6+C5U3OYCYfbXO7w8z2etfk62T0XR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346058; c=relaxed/simple; bh=uxXb5xMrAeZA/PGCI0cjUzdsJNW6qdUaqZhiqHlS0Us=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WNdeeI66QudAQkd38D/Q/KibFFQ/XZ56ymIcSP1BZhHno5w8U3JLU7ptklKR0cdiT93LbwHTt80PE2hGsN4cBHiDutkaAfL7lnCtFx6A0Bl8hBDGrsmD1kOf1y10OMPxoHRbKZcUna8LJ63O+iU54rn1emZ7GS+Ccigz2YrFn6Y= 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=Hy4Hdxbc; arc=none smtp.client-ip=209.85.208.172 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="Hy4Hdxbc" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2f754d4a6e4so9356471fa.3; Thu, 26 Sep 2024 03:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727346055; x=1727950855; 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=mCnK0YaRfOlDi/MQIp9RVs5sdcIVgQygzC7gFn5dGeU=; b=Hy4HdxbckSlUGQXa8zkTHVJVtVRFwGLgSBb5gfUOTQNd18qaua3wny3jJMM6dAdiya leM2tfqSfRBK9MAGjh+E6A2wUhuHkYqu9IednNBJ7Yh/QICqd/A7T7j3zmD9y3I9hHyb CyLqu3yAOLflyMNSHtuwQ9xIIzGkGdE9+/YzeJPEolBTWlTapiHNIrkYtjoSYz7rUGn0 kGJMEK0k8a6cB1FYOzKkdfkTZPjlprJE/gmOA2a18XB/Spm80dJbCfirDjo9eSbLkQD7 EmkQriJYkZqEUo+Lt/kGDKYZIUiYJ8Fbq75fFZYi4rgaoQPztugegqgh1+45NoZiIACi geTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727346055; x=1727950855; 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=mCnK0YaRfOlDi/MQIp9RVs5sdcIVgQygzC7gFn5dGeU=; b=m38Rq39OzBD98cUKzI4hVjtwant+S8ZU9QjDlkjSbN7dpquA/rwHDgoJyh0gFiOgeO Pm7KuhH6+kuJjoSW+LrwvAVAWCJBqsfTeciFwGccnLY2pneGv8vSgAwLV4F+dLbMJd1/ PYiPpj20WrFM2GzcOVbswNFc6YwNiFLKrIrixNDFtHzN8hSnFFI9eOEDzeNMbmxxlkzg aDiSPSb1BHIG+1XMi6844Rr0io0HhpaDPbpXDUyVy9iCRTVxAeVUqRCVgQApMx6isirY DezVDAMK+2Imy3hmTARCZAq8HXu45JrgL/3To7SfqA9/nQW5AnbCu8JudaDZysRu966s WxRg== X-Forwarded-Encrypted: i=1; AJvYcCUxjGxCgVJjMoDOv/My00zF7zyKLaCDnsC2q6cTZ6+f9sfJsT1lP2XIouqOBE3V7xpfXIov/8EZz2ROASLT@vger.kernel.org, AJvYcCVJvh5/R+RygzBFy7ysva50B8DQVO9QuiX1bssXegvcheoTG7b/JTLYAbhqjrelSfNcJrLfx4qSer4OFtY=@vger.kernel.org, AJvYcCVKu21mEmIH03G10314/LSd/+jBg6DWOKS8ylrPVAJzwWvVts8MigonF0FlBGNPZ+9vOk3MNTGu0Ea7dQ==@vger.kernel.org, AJvYcCWjnjelSWK6M3+SqQbu9FURu1BWO+I8tefrjgQ2RjY3qlZOCbiJUZTmWtXxgF3VmxY+1kF+FRaW9CWc@vger.kernel.org X-Gm-Message-State: AOJu0Yz3foj6ryVUznqsQEnBbSz9Kfq5PTRqZrEIXVAiBdHjPSkyiMcJ aNQ/OHH3X0d2qQtSq7TOwcLoV3A+l+qX99Y5VOMRh0ud73miJtHk X-Google-Smtp-Source: AGHT+IFLi7YOGKzuax+KcCUegsiaf2QaWmNNgn1R7oRerwNKtavza4YaP78iTb6sd/Szi7OA/3PUyg== X-Received: by 2002:a05:6512:128b:b0:536:54df:bffa with SMTP id 2adb3069b0e04-5387755cc03mr3766963e87.45.1727346054440; Thu, 26 Sep 2024 03:20:54 -0700 (PDT) Received: from [127.0.1.1] (mm-20-1-84-93.mgts.dynamic.pppoe.byfly.by. [93.84.1.20]) by smtp.googlemail.com with ESMTPSA id 2adb3069b0e04-537a85ee54esm759071e87.96.2024.09.26.03.20.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 03:20:53 -0700 (PDT) From: Dzmitry Sankouski Date: Thu, 26 Sep 2024 13:20:19 +0300 Subject: [PATCH v5 2/7] dt-bindings: mfd: add maxim,max77705 Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240617-starqltechn_integration_upstream-v5-2-e0033f141d17@gmail.com> References: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> In-Reply-To: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> To: Sebastian Reichel , Chanwoo Choi , Krzysztof Kozlowski , Lee Jones , Rob Herring , Conor Dooley , Dmitry Torokhov , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1727346045; l=5974; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=uxXb5xMrAeZA/PGCI0cjUzdsJNW6qdUaqZhiqHlS0Us=; b=WXRUTUfi2U1BjuENigKHUDmWDT0lBX+fbUF5LD0EuF/KT7VFRrJLiL8dbWy0RmsryYXiCJuqp w5uLmcubT2EArJjmQ14n3WaNxJBIoY3OLJ2fWM0M10TJd6g6E38kGk3 X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Add maxim,max77705 core binding part. Signed-off-by: Dzmitry Sankouski --- Changes in v5: - formatting changes - add unevaluatedProperties: false for nodes referencing common schemas - remove additionalProperties on nodes with unevaluatedProperties: false - add min and max to led index Changes in v4: - change dts example intendation from tabs to spaces - remove interrupt-names property - remove obvious reg description - split long(>80) lines --- Documentation/devicetree/bindings/mfd/maxim,max77705.yaml | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 178 insertions(+) diff --git a/Documentation/devicetree/bindings/mfd/maxim,max77705.yaml b/Documentation/devicetree/bindings/mfd/maxim,max77705.yaml new file mode 100644 index 000000000000..214515f84c85 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/maxim,max77705.yaml @@ -0,0 +1,177 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/maxim,max77705.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim MAX77705 Companion Power Management IC and USB Type-C interface IC + +maintainers: + - Dzmitry Sankouski + +description: | + This is a part of device tree bindings for Maxim MAX77705 multi functional + device. + + The Maxim MAX77705 is a Companion Power Management and Type-C + interface IC which includes charger, fuelgauge, LED, haptic motor driver and + Type-C management IC. + +properties: + compatible: + const: maxim,max77705 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + charger: + $ref: /schemas/power/supply/power-supply.yaml + unevaluatedProperties: true + properties: + compatible: + const: maxim,max77705-charger + + required: + - compatible + - monitored-battery + + fuel-gauge: + $ref: /schemas/power/supply/power-supply.yaml + type: object + unevaluatedProperties: true + description: MAX77705 fuel gauge with ModelGauge m5 EZ algorithm support. + + properties: + compatible: + const: maxim,max77705-fuel-gauge + + shunt-resistor-micro-ohms: + description: + The value of current sense resistor in microohms. + + required: + - compatible + - shunt-resistor-micro-ohms + - monitored-battery + - power-supplies + + haptic: + type: object + additionalProperties: false + + properties: + compatible: + const: maxim,max77705-haptic + + haptic-supply: true + + pwms: + maxItems: 1 + + required: + - compatible + - haptic-supply + - pwms + + leds: + type: object + additionalProperties: false + description: + Up to 4 LEDs supported. One LED is represented by one child node. + + properties: + compatible: + const: maxim,max77705-led + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + + patternProperties: + "^led@[0-3]$": + $ref: /schemas/leds/common.yaml# + type: object + unevaluatedProperties: false + + properties: + reg: + description: LED index. + minimum: 0 + maximum: 3 + + required: + - reg + + required: + - compatible + - "#address-cells" + - "#size-cells" + +required: + - compatible + +additionalProperties: false + +examples: + - | + #include + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pmic@66 { + compatible = "maxim,max77705"; + reg = <0x66>; + interrupt-parent = <&pm8998_gpios>; + interrupts = <11 IRQ_TYPE_LEVEL_LOW>; + pinctrl-0 = <&chg_int_default>; + pinctrl-names = "default"; + + leds { + compatible = "maxim,max77705-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@1 { + reg = <1>; + label = "red:usr1"; + }; + + led@2 { + reg = <2>; + label = "green:usr2"; + }; + + led@3 { + reg = <3>; + label = "blue:usr3"; + }; + }; + + max77705_charger: charger { + compatible = "maxim,max77705-charger"; + monitored-battery = <&battery>; + }; + + fuel-gauge { + compatible = "maxim,max77705-fuel-gauge"; + monitored-battery = <&battery>; + power-supplies = <&max77705_charger>; + shunt-resistor-micro-ohms = <5000>; + }; + + + haptic { + compatible = "maxim,max77705-haptic"; + haptic-supply = <&vib_regulator>; + pwms = <&vib_pwm 0 50000>; + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 5e467ba71e3b..5e5829f28631 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14069,6 +14069,7 @@ B: mailto:linux-samsung-soc@vger.kernel.org F: Documentation/devicetree/bindings/*/maxim,max14577.yaml F: Documentation/devicetree/bindings/*/maxim,max77686.yaml F: Documentation/devicetree/bindings/*/maxim,max77693.yaml +F: Documentation/devicetree/bindings/*/maxim,max77705*.yaml F: Documentation/devicetree/bindings/*/maxim,max77843.yaml F: Documentation/devicetree/bindings/clock/maxim,max77686.txt F: drivers/*/*max77843.c From patchwork Thu Sep 26 10:20:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 830884 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.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 B5CB01AD3E3; Thu, 26 Sep 2024 10:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346063; cv=none; b=RqhkOtsdMNpXM/vfMz+GGbUn6G2fNSgoNWtKmzAuS/mSSmijclfBmWRSZhpl+/4PECHgItCYFQFO0RNiylcyTKvsyDTZecBy1q9JJZjscn6RXGGLFEWp/AZROPXks1s7t/0fJl8uXnMutd33X3f4GmQ/tEdetCsaHmzjwRv/MO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346063; c=relaxed/simple; bh=JLT3fRS+yl6/Mb+tf79ZnYVcgNkISumMGZ+lQQFDBZo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pvTAamRjkvz+b/LfzUcoXVtWEQ85UBLuf0CdFQl/Sd+oSKb9riW1f3f/Q+nrkzmCukvkoAlodXEk4tOHH8chIVqOfTe7fp+IRd3B2ma4KDSC0DbFh46jdcmX5nQ8VY8yiXO97AjB3ZZL8ej93XvlAjyZVgRKzEk8xaNKo6Xr9s4= 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=CL++dYzT; arc=none smtp.client-ip=209.85.167.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="CL++dYzT" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-536584f6c84so1066274e87.0; Thu, 26 Sep 2024 03:21:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727346060; x=1727950860; 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=KGV3WmFsQ+1pAhEILcS0ZUWipFofO4AxkBOKtNoxFJE=; b=CL++dYzTNo/LnW50RKp3Rzg5/b7apbB0mWRwA+cCwi4BXWJWGA+R5onVEptCDUayP9 jQ3Gjz7x+w0tLK7KzYZL8Cl915cbdz5dZMYN5iR0pQGHSwOWJMy91mUydy6Z47a+cHMT Dl4mQwuU9UdIsrj5B88BAD12+wHvy/m8HTFMN0pNxMhqGw869WRNxPd2AYfuUtfgjwbj I5dwt+rrB5QiStQ5V2OaYVWchmYsuLafOqK4f7Pr7r+3IbZgJHy8Wa5dUA7/qEUQMZFz NnwJH5vAUeLRlhyH7BVjEeZU6fZK8Jj4n/58ROJG7O571sNLrj6LYFhbJwb6xQCoAweT A1Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727346060; x=1727950860; 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=KGV3WmFsQ+1pAhEILcS0ZUWipFofO4AxkBOKtNoxFJE=; b=M//lFnkvMjKQk3EjDvS4f+G8o0wydnBtlTiS7nQKnWJFDg80d6bOqc9+jNJkTjGOrR ryjAvEr6xFhMf1yRtWlg6CGTvMb4cQGBSfpXPNg2QisJkFBtmWCH84L8MSHqx7uDixo0 dvvRXkoHF1S5IQxj4xVRS21lIwogOyxkktH9S+SHNL2n4htIiD2Dz7PEgkp4a1bnqD/B uwcnIVdXc/fLMkI8lLUegVcF+qin7vnhl/ztCwYC+Und9RtWq3umySjrMbLqmPx691R4 OF2hSbCsTVr5XHR8mO9wp0Qp4L+mkmB1zwYrm2hntIGUfOl0HoR1ZrO+xnnyJY09kG6V an1Q== X-Forwarded-Encrypted: i=1; AJvYcCUv77thuFoJL/TIJxj0de/wyudQnz4zqnzySJ8I0fky/MJOvEJppWwDEcwcORzZtcjV/mWF39cdhXfbag==@vger.kernel.org, AJvYcCVRr/k6KXDU3IcVCA44ee+xB27wMaL+i4+er6dArURQMGIbYAndd2/W+UIoZpUtAI9hqEK9T14N5B3t6bI=@vger.kernel.org, AJvYcCVrYZMY9rmEjGBddzGqYA8tpv1WPhNQwNVt2lf42esds2pfJw1pn7SzTK8qgykMQoSn+qfJROteGgSo@vger.kernel.org, AJvYcCW62UuDuQ3y/J2FCr3KWqg9KcNS2/rph3FoW6c7Ngmu2dVqlTcNgRCk8Kpt2ZDRFuEfuz+MzhCUmFQTKZUp@vger.kernel.org X-Gm-Message-State: AOJu0Ywn+v3c3kfxLEN7cDls+PzxpeobGpbFpJa7fsL264Nptr3iA9hj pPbQId3CE41GByGhStbF+ZFIx5e8e5FgmJmUfhHl/5p9xbFN2YrU X-Google-Smtp-Source: AGHT+IGUK6vZAJ++SUbmFGRptqkZIW9Ifvw5nZrFnUuGWC2xWTh37TlzTVTJiCgFnetJ0OjEsCkz9w== X-Received: by 2002:a05:6512:2310:b0:52e:9b4f:dd8c with SMTP id 2adb3069b0e04-53877537650mr3638945e87.35.1727346059505; Thu, 26 Sep 2024 03:20:59 -0700 (PDT) Received: from [127.0.1.1] (mm-20-1-84-93.mgts.dynamic.pppoe.byfly.by. [93.84.1.20]) by smtp.googlemail.com with ESMTPSA id 2adb3069b0e04-537a85ee54esm759071e87.96.2024.09.26.03.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 03:20:59 -0700 (PDT) From: Dzmitry Sankouski Date: Thu, 26 Sep 2024 13:20:21 +0300 Subject: [PATCH v5 4/7] input: max77693: add max77705 haptic support Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240617-starqltechn_integration_upstream-v5-4-e0033f141d17@gmail.com> References: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> In-Reply-To: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> To: Sebastian Reichel , Chanwoo Choi , Krzysztof Kozlowski , Lee Jones , Rob Herring , Conor Dooley , Dmitry Torokhov , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1727346045; l=4227; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=JLT3fRS+yl6/Mb+tf79ZnYVcgNkISumMGZ+lQQFDBZo=; b=eyhotNhJjShydlq/boHbobSgpvDEaXyMUCGayFGopjNkVFTTUItWfAQNn8qcRjca/d8VTpUF4 oQVsU0AeULEBdB4rCd5VcigfpwPxZUvUXA+TbfFtO2Rxf94Y8MZKJ5e X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Add support for haptic controller on MAX77705 Multifunction device. This driver supports external pwm and LRA (Linear Resonant Actuator) motor. User can control the haptic device via force feedback framework. Signed-off-by: Dzmitry Sankouski Acked-by: Dmitry Torokhov --- Changes in v4: - add max77705 haptic support to max77693 driver - delete max77705-haptic --- drivers/input/misc/Kconfig | 4 ++-- drivers/input/misc/Makefile | 1 + drivers/input/misc/max77693-haptic.c | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 6a852c76331b..b4515c4e5cf6 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -241,11 +241,11 @@ config INPUT_MAX77650_ONKEY config INPUT_MAX77693_HAPTIC tristate "MAXIM MAX77693/MAX77843 haptic controller support" - depends on (MFD_MAX77693 || MFD_MAX77843) && PWM + depends on (MFD_MAX77693 || MFD_MAX77705 || MFD_MAX77843) && PWM select INPUT_FF_MEMLESS help This option enables support for the haptic controller on - MAXIM MAX77693 and MAX77843 chips. + MAXIM MAX77693, MAX77705 and MAX77843 chips. To compile this driver as module, choose M here: the module will be called max77693-haptic. diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 4f7f736831ba..3e3532b27990 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o obj-$(CONFIG_INPUT_MAX77650_ONKEY) += max77650-onkey.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC) += max77693-haptic.o +obj-$(CONFIG_INPUT_MAX77705_HAPTIC) += max77705-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o obj-$(CONFIG_INPUT_MAX8997_HAPTIC) += max8997_haptic.o obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) += mc13783-pwrbutton.o diff --git a/drivers/input/misc/max77693-haptic.c b/drivers/input/misc/max77693-haptic.c index 0e646f1b257b..c3b9d33608d7 100644 --- a/drivers/input/misc/max77693-haptic.c +++ b/drivers/input/misc/max77693-haptic.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #define MAX_MAGNITUDE_SHIFT 16 @@ -115,6 +116,13 @@ static int max77693_haptic_configure(struct max77693_haptic *haptic, MAX77693_HAPTIC_PWM_DIVISOR_128); config_reg = MAX77693_HAPTIC_REG_CONFIG2; break; + case TYPE_MAX77705: + value = ((haptic->type << MAX77693_CONFIG2_MODE) | + (enable << MAX77693_CONFIG2_MEN) | + (haptic->mode << MAX77693_CONFIG2_HTYP) | + MAX77693_HAPTIC_PWM_DIVISOR_128); + config_reg = MAX77705_PMIC_REG_MCONFIG; + break; case TYPE_MAX77843: value = (haptic->type << MCONFIG_MODE_SHIFT) | (enable << MCONFIG_MEN_SHIFT) | @@ -312,6 +320,9 @@ static int max77693_haptic_probe(struct platform_device *pdev) case TYPE_MAX77693: haptic->regmap_haptic = max77693->regmap_haptic; break; + case TYPE_MAX77705: + haptic->regmap_haptic = max77693->regmap; + break; case TYPE_MAX77843: haptic->regmap_haptic = max77693->regmap; break; @@ -407,6 +418,7 @@ static DEFINE_SIMPLE_DEV_PM_OPS(max77693_haptic_pm_ops, static const struct platform_device_id max77693_haptic_id[] = { { "max77693-haptic", }, + { "max77705-haptic", }, { "max77843-haptic", }, {}, }; @@ -414,6 +426,7 @@ MODULE_DEVICE_TABLE(platform, max77693_haptic_id); static const struct of_device_id of_max77693_haptic_dt_match[] = { { .compatible = "maxim,max77693-haptic", }, + { .compatible = "maxim,max77705-haptic", }, { .compatible = "maxim,max77843-haptic", }, { /* sentinel */ }, }; @@ -432,5 +445,5 @@ module_platform_driver(max77693_haptic_driver); MODULE_AUTHOR("Jaewon Kim "); MODULE_AUTHOR("Krzysztof Kozlowski "); -MODULE_DESCRIPTION("MAXIM 77693/77843 Haptic driver"); +MODULE_DESCRIPTION("MAXIM 77693/77705/77843 Haptic driver"); MODULE_LICENSE("GPL"); From patchwork Thu Sep 26 10:20:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 830883 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 3ADE91AF4F0; Thu, 26 Sep 2024 10:21:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346070; cv=none; b=Fs4GO9i/AbhQXQLO4HsEVi8CYyFDEZS+QB2GUW+lflbEbO/1TjRMKtGVwKtNsebCPrcP1jX34gK79Mw4BqRdfBVRZDZMeEgu9bx5O05gv7n0iDkvg+xos0KmrZnYZohp7IqKdts0KuQPFyECc0jnjFJCPAhbFD+jT2tHbJd8+4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346070; c=relaxed/simple; bh=pmvkF5DtT2tmmiaElv+VfSPDpulxzT5Dno7m2B4J74Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RSxCDawrjIEEYvtGlYuqqL+1OtLtwbEoMtRFgW5FFIT2rgtzs27OCksKIOIZAo837wJ9skGXXXSEA76PoLmg0fsr/PD2MFjt1qZ2sq7fxPei4Ns3AVKsbh+/h7Xg6YnuZraJ7jLF0H/zTD6gYbsZZj4Dv5rdgrG2oUzk4PGV0Dg= 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=dGl/gtdE; arc=none smtp.client-ip=209.85.167.42 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="dGl/gtdE" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5356aa9a0afso1206890e87.2; Thu, 26 Sep 2024 03:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727346066; x=1727950866; 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=DYPbY+ziBAPO5jR7eDpx5rUqOZ3MUmEYqNjEU7hZvD8=; b=dGl/gtdEDGc3vi8BNtCdHiAfGr3IE53Tkv/XswqdE85IyjDXjm50QEV+Cl/Q4V9f5T 9XZ63tfrmCiowCwZbxnHMILkruNnaUHmn4PL2vwZ3EM/mCRxbss8QmxZgGZd0BJYutnp xX0yzXgulpOBEVSfLfBDvIYEnNlPaIyuy7zBlffL7WeSYeACvq3rbzJkH5atSrFFXIBq Sl7Z+6rRPWKi/j1YgHYewM7mVipZ2z614oRToNnKv4y2QDS5O8YOke34sH5AwY6dfXyG ocO9b/YziHCK4U7ecOweS7n9taXjloaz8F00v1Joocghi6plBW+yJm8VlJ5gZneuRT3N PObw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727346066; x=1727950866; 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=DYPbY+ziBAPO5jR7eDpx5rUqOZ3MUmEYqNjEU7hZvD8=; b=Mtb6sbXv1JZtmysK5OcmcQWMhxBbT7LjEZYrv3FDN4g6uiPOAVb5vtGM17vxUgRJZ+ t8Zs/8l8XmcohsmBgOM7dsnyA3D+UVHqpVkoUkXb7YxOfJdWeiRQhxaux1auglDHbyxm BQGZ8Ge+L3JSxgGuTrSPROHHLe0ctHdxtvtfTkiJezAHywiAefDlFhImzj4cojiXKFec 5ZI+ZeNGOW08M4uSgpy92WUw86mQ8uaKjJm38/Xqwqt+lQDnx2qB/LpmCarAD/P7uj7M bB0Qdu7+k7FcvImy/JHskwYeToYB8YwhBZg32A3TXrgNKNCULkjE1U579Yuw4tftdgo6 8+2g== X-Forwarded-Encrypted: i=1; AJvYcCUcJrcIGQMNXmPagattEy5Wy7UE7Ca9B+waa8aly3DLxtf07fQTDEbtVK1KGATI8uwdpEC//vTaTYlpu0U=@vger.kernel.org, AJvYcCV335hR4LEwaQ3k7MdI6dn56tnmVKAZuZqoEJbuFwAgeJa3XTl7xzzmjacJkAJvCkcGHyXs0vzj9PS5+YKi@vger.kernel.org, AJvYcCWTM8ayM0eaDb0gxCTmhA4trqy1z1lud0/oKEaMODK9DTrXR/pvt4RnrmpURGfH6Ml+F8WbpN7GWXYw@vger.kernel.org, AJvYcCX7TkTbhzllMxYaupXqgfu2KGXnVXFxgZNW2T4c/B6x1NtHFrX0ESTl0rpc6W8WL2I9YCWihKctw43IGg==@vger.kernel.org X-Gm-Message-State: AOJu0Yz9E1E83wppdzOEZKRgFYLfGsSl0yfeP4EwzDlNW7BCF5egjx2X 0jof1tC5gA8nuulYbR7ppJ0zAfJ7oz/nibb2xrxCDzY6EqI6E+BI X-Google-Smtp-Source: AGHT+IGeFagfipeL/Z+MsN7DcEomqRhLCEAe4WsvE5ifV6/I97KYHVROeaZIqa/JRAm15MzwriKdrg== X-Received: by 2002:a05:6512:2256:b0:535:6951:9e1c with SMTP id 2adb3069b0e04-538704969e9mr5244605e87.15.1727346065851; Thu, 26 Sep 2024 03:21:05 -0700 (PDT) Received: from [127.0.1.1] (mm-20-1-84-93.mgts.dynamic.pppoe.byfly.by. [93.84.1.20]) by smtp.googlemail.com with ESMTPSA id 2adb3069b0e04-537a85ee54esm759071e87.96.2024.09.26.03.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 03:21:04 -0700 (PDT) From: Dzmitry Sankouski Date: Thu, 26 Sep 2024 13:20:23 +0300 Subject: [PATCH v5 6/7] power: supply: max77705: Add fuel gauge driver for Maxim 77705 Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240617-starqltechn_integration_upstream-v5-6-e0033f141d17@gmail.com> References: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> In-Reply-To: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> To: Sebastian Reichel , Chanwoo Choi , Krzysztof Kozlowski , Lee Jones , Rob Herring , Conor Dooley , Dmitry Torokhov , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1727346045; l=15093; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=pmvkF5DtT2tmmiaElv+VfSPDpulxzT5Dno7m2B4J74Q=; b=s5U8jxzTSTU9pUKmRhnD0k3SXD7RZBKGBCLRnRY37IcQE9m/ywVGgg+Lxjz3vldh3vhLOqI+8 o5tSYqMMbqPCgapkYs1l2jpT0hlyj0RJhhya2TTIfu5gA73TY4y/Ph0 X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Add driver for Maxim 77705 fuel gauge (part of max77705 MFD driver) providing power supply class information to userspace. The driver is configured through DTS (battery and system related settings). Signed-off-by: Dzmitry Sankouski --- Changes for v5: - fix license - use same hardware name in Kconfig and module descriptions - fix email, and module author Changes for v4: - rework driver from scratch - change word delimiters in filenames to "_" - remove debugfs code - cleanup header --- drivers/power/supply/Kconfig | 7 ++ drivers/power/supply/Makefile | 1 + drivers/power/supply/max77705_fuel_gauge.c | 348 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/power/max77705_fuelgauge.h | 65 ++++++++++++++++ 4 files changed, 421 insertions(+) diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index fe84d2004f57..7c16403c263d 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -579,6 +579,13 @@ config CHARGER_MAX77705 help Say Y to enable support for the Maxim MAX77705 battery charger. +config FUEL_GAUGE_MAX77705 + tristate "Maxim MAX77705 fuel gauge driver" + depends on MFD_MAX77705 + default n + help + Say Y to enable support for MAXIM MAX77705 fuel gauge driver. + config CHARGER_MAX77976 tristate "Maxim MAX77976 battery charger driver" depends on I2C diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile index daa9228fa04b..b949600a6207 100644 --- a/drivers/power/supply/Makefile +++ b/drivers/power/supply/Makefile @@ -80,6 +80,7 @@ obj-$(CONFIG_CHARGER_DETECTOR_MAX14656) += max14656_charger_detector.o obj-$(CONFIG_CHARGER_MAX77650) += max77650-charger.o obj-$(CONFIG_CHARGER_MAX77693) += max77693_charger.o obj-$(CONFIG_CHARGER_MAX77705) += max77705_charger.o +obj-$(CONFIG_FUEL_GAUGE_MAX77705) += max77705_fuel_gauge.o obj-$(CONFIG_CHARGER_MAX77976) += max77976_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o diff --git a/drivers/power/supply/max77705_fuel_gauge.c b/drivers/power/supply/max77705_fuel_gauge.c new file mode 100644 index 000000000000..bd3dfcf8fdda --- /dev/null +++ b/drivers/power/supply/max77705_fuel_gauge.c @@ -0,0 +1,348 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (C) 2024 Dzmitry Sankouski +// +// Fuel gauge driver for MAXIM 77705 charger/power-supply. + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const char *max77705_fuelgauge_model = "max77705"; +static const char *max77705_fuelgauge_manufacturer = "Maxim Integrated"; + +static enum power_supply_property max77705_fuelgauge_props[] = { + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_VOLTAGE_OCV, + POWER_SUPPLY_PROP_VOLTAGE_AVG, + POWER_SUPPLY_PROP_CURRENT_NOW, + POWER_SUPPLY_PROP_CURRENT_AVG, + POWER_SUPPLY_PROP_CHARGE_NOW, + POWER_SUPPLY_PROP_CHARGE_FULL, + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, + POWER_SUPPLY_PROP_CAPACITY, + POWER_SUPPLY_PROP_TEMP, + POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, + POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, +}; + +static int max77705_fg_read_reg(struct max77705_fuelgauge_data *fuelgauge, + unsigned int reg, unsigned int *val) +{ + struct regmap *regmap = fuelgauge->regmap; + u8 data[2]; + int ret; + + ret = regmap_noinc_read(regmap, reg, data, sizeof(data)); + if (ret < 0) + return ret; + + *val = (data[1] << 8) + data[0]; + + return 0; +} + +static int max77705_fg_read_temp(struct max77705_fuelgauge_data *fuelgauge, + int *val) +{ + struct regmap *regmap = fuelgauge->regmap; + u8 data[2] = { 0, 0 }; + int ret, temperature = 0; + + ret = regmap_noinc_read(regmap, TEMPERATURE_REG, data, sizeof(data)); + if (ret < 0) + return ret; + + if (data[1] & BIT(7)) + temperature = ((~(data[1])) & 0xFF) + 1; + else + temperature = data[1] & 0x7f; + + temperature *= 10; + temperature += data[0] * 10 / 256; + *val = temperature; + + return 0; +} + +static int max77705_fg_check_battery_present(struct max77705_fuelgauge_data + *fuelgauge, int *val) +{ + struct regmap *regmap = fuelgauge->regmap; + u8 status_data[2]; + int ret; + + ret = regmap_noinc_read(regmap, STATUS_REG, status_data, sizeof(status_data)); + if (ret < 0) + return ret; + + *val = !(status_data[0] & MAX77705_BAT_ABSENT_MASK); + + return 0; +} + +static int max77705_battery_get_status(struct max77705_fuelgauge_data *fuelgauge, + int *val) +{ + int current_now; + int am_i_supplied; + int ret; + unsigned int soc_rep; + + am_i_supplied = power_supply_am_i_supplied(fuelgauge->psy_fg); + if (am_i_supplied) { + if (am_i_supplied == -ENODEV) { + dev_err(fuelgauge->dev, + "power supply not found, fall back to current-based status checking\n"); + } else { + *val = POWER_SUPPLY_STATUS_CHARGING; + return 0; + } + } + ret = max77705_fg_read_reg(fuelgauge, SOCREP_REG, &soc_rep); + if (ret) + return ret; + + if (soc_rep < 100) { + ret = max77705_fg_read_reg(fuelgauge, CURRENT_REG, ¤t_now); + if (ret) + return ret; + + if (current_now > 0) + *val = POWER_SUPPLY_STATUS_CHARGING; + else if (current_now < 0) + *val = POWER_SUPPLY_STATUS_DISCHARGING; + else + *val = POWER_SUPPLY_STATUS_NOT_CHARGING; + } else { + *val = POWER_SUPPLY_STATUS_FULL; + } + + return 0; +} + +static void max77705_unit_adjustment(struct max77705_fuelgauge_data *fuelgauge, + enum power_supply_property psp, + union power_supply_propval *val) +{ + const unsigned int base_unit_conversion = 1000; + + switch (psp) { + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + case POWER_SUPPLY_PROP_VOLTAGE_OCV: + case POWER_SUPPLY_PROP_VOLTAGE_AVG: + val->intval = max77705_fg_vs_convert(val->intval); + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: + case POWER_SUPPLY_PROP_CURRENT_AVG: + val->intval = max77705_fg_cs_convert(val->intval, + fuelgauge->rsense_conductance); + break; + case POWER_SUPPLY_PROP_CHARGE_NOW: + case POWER_SUPPLY_PROP_CHARGE_FULL: + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + val->intval *= base_unit_conversion; + break; + case POWER_SUPPLY_PROP_CAPACITY: + val->intval = min(val->intval, 100); + break; + default: + dev_dbg(fuelgauge->dev, + "%s: no need for unit conversion %d\n", __func__, psp); + } +} + +static int max77705_fg_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct max77705_fuelgauge_data *fuelgauge = + power_supply_get_drvdata(psy); + int ret; + + switch (psp) { + case POWER_SUPPLY_PROP_STATUS: + ret = max77705_battery_get_status(fuelgauge, &val->intval); + break; + case POWER_SUPPLY_PROP_PRESENT: + ret = max77705_fg_check_battery_present(fuelgauge, &val->intval); + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + ret = max77705_fg_read_reg(fuelgauge, VCELL_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_VOLTAGE_OCV: + ret = max77705_fg_read_reg(fuelgauge, VFOCV_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_VOLTAGE_AVG: + ret = max77705_fg_read_reg(fuelgauge, AVR_VCELL_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: + ret = max77705_fg_read_reg(fuelgauge, CURRENT_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CURRENT_AVG: + ret = max77705_fg_read_reg(fuelgauge, AVG_CURRENT_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CHARGE_NOW: + ret = max77705_fg_read_reg(fuelgauge, REMCAP_REP_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CHARGE_FULL: + ret = max77705_fg_read_reg(fuelgauge, FULLCAP_REP_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + ret = max77705_fg_read_reg(fuelgauge, DESIGNCAP_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CAPACITY: + ret = max77705_fg_read_reg(fuelgauge, SOCREP_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_TEMP: + ret = max77705_fg_read_temp(fuelgauge, &val->intval); + break; + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW: + ret = max77705_fg_read_reg(fuelgauge, TIME_TO_EMPTY_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: + ret = max77705_fg_read_reg(fuelgauge, TIME_TO_FULL_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CYCLE_COUNT: + ret = max77705_fg_read_reg(fuelgauge, CYCLES_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_MODEL_NAME: + val->strval = max77705_fuelgauge_model; + break; + case POWER_SUPPLY_PROP_MANUFACTURER: + val->strval = max77705_fuelgauge_manufacturer; + break; + default: + return -EINVAL; + } + + if (ret) + return ret; + + max77705_unit_adjustment(fuelgauge, psp, val); + + return 0; +} + +static const struct power_supply_desc max77705_fg_desc = { + .name = "max77705-fuel-gauge", + .type = POWER_SUPPLY_TYPE_BATTERY, + .properties = max77705_fuelgauge_props, + .num_properties = ARRAY_SIZE(max77705_fuelgauge_props), + .get_property = max77705_fg_get_property, +}; + +static int max77705_fg_set_charge_design(struct regmap *regmap, int value) +{ + u8 data[2]; + int value_mah; + + value_mah = value / 1000; + data[0] = value_mah & 0xFF; + data[1] = (value_mah >> 8) & 0xFF; + + return regmap_noinc_write(regmap, DESIGNCAP_REG, data, sizeof(data)); +} + +static int max77705_battery_settings(struct max77705_fuelgauge_data *fuelgauge) +{ + struct power_supply_battery_info *info; + struct regmap *regmap = fuelgauge->regmap; + int ret; + + ret = power_supply_get_battery_info(fuelgauge->psy_fg, &info); + if (ret) + return ret; + + fuelgauge->bat_info = info; + + if (info->energy_full_design_uwh != info->charge_full_design_uah) { + if (info->charge_full_design_uah == -EINVAL) + dev_warn(fuelgauge->dev, "missing battery:charge-full-design-microamp-hours\n"); + ret = max77705_fg_set_charge_design(regmap, info->charge_full_design_uah); + } + + return ret; +} + +static int max77705_fuelgauge_parse_dt(struct max77705_fuelgauge_data + *fuelgauge) +{ + struct device *dev = fuelgauge->dev; + struct device_node *np = dev->of_node; + int ret; + unsigned int rsense; + + if (!np) { + dev_err(dev, "no fuelgauge OF node\n"); + return -EINVAL; + } + ret = of_property_read_u32(np, "shunt-resistor-micro-ohms", + &rsense); + if (ret < 0) { + dev_warn(dev, "No shunt-resistor-micro-ohms property, assume default\n"); + fuelgauge->rsense_conductance = 100; + } else + fuelgauge->rsense_conductance = 1000000 / rsense; /* rsense conductance in Ohm^-1 */ + + return 0; +} + +static int max77705_fuelgauge_probe(struct platform_device *pdev) +{ + struct max77693_dev *max77705 = dev_get_drvdata(pdev->dev.parent); + struct max77705_fuelgauge_data *fuelgauge; + struct power_supply_config fuelgauge_cfg = { }; + struct device *dev = &pdev->dev; + int ret = 0; + + fuelgauge = devm_kzalloc(dev, sizeof(*fuelgauge), GFP_KERNEL); + if (!fuelgauge) + return -ENOMEM; + + fuelgauge->dev = dev; + fuelgauge->regmap = max77705->regmap_fg; + + ret = max77705_fuelgauge_parse_dt(fuelgauge); + if (ret < 0) + return ret; + + fuelgauge_cfg.drv_data = fuelgauge; + fuelgauge_cfg.of_node = fuelgauge->dev->of_node; + + fuelgauge->psy_fg = devm_power_supply_register(&pdev->dev, + &max77705_fg_desc, + &fuelgauge_cfg); + + if (IS_ERR(fuelgauge->psy_fg)) + return PTR_ERR(fuelgauge->psy_fg); + + return max77705_battery_settings(fuelgauge); +} + +static const struct of_device_id max77705_fg_of_match[] = { + { .compatible = "maxim,max77705-fuel-gauge" }, + { } +}; +MODULE_DEVICE_TABLE(of, max77705_fg_of_match); + +static struct platform_driver max77705_fuelgauge_driver = { + .driver = { + .name = "max77705-fuel-gauge", + .of_match_table = max77705_fg_of_match, + }, + .probe = max77705_fuelgauge_probe, +}; +module_platform_driver(max77705_fuelgauge_driver); + +MODULE_DESCRIPTION("Maxim MAX77705 Fuel Gauge Driver"); +MODULE_AUTHOR("Dzmitry Sankouski "); +MODULE_LICENSE("GPL"); diff --git a/include/linux/power/max77705_fuelgauge.h b/include/linux/power/max77705_fuelgauge.h new file mode 100644 index 000000000000..dfd91f097817 --- /dev/null +++ b/include/linux/power/max77705_fuelgauge.h @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +// +// Copyright (C) 2024 Dzmitry Sankouski +// +// Fuel gauge driver header for MAXIM 77705 charger/power-supply. + +#ifndef __MAX77705_FUELGAUGE_H +#define __MAX77705_FUELGAUGE_H __FILE__ + +#include +#include +#include + +#define ALERT_EN 4 +#define CAPACITY_SCALE_DEFAULT_CURRENT 1000 +#define CAPACITY_SCALE_HV_CURRENT 600 +// Current and capacity values are displayed as a voltage +// and must be divided by the sense resistor to determine Amps or Amp-hours. +// This should be applied to all current, charge, energy registers, +// except ModelGauge m5 Algorithm related ones. +// current sense resolution +#define MAX77705_FG_CS_ADC_RESOLUTION 15625 // 1.5625 microvolts +// voltage sense resolution +#define MAX77705_FG_VS_ADC_RESOLUTION 78125 // 78.125 microvolts +// CONFIG_REG register +#define MAX77705_SOC_ALERT_EN_MASK BIT(2) +// When set to 1, external temperature measurements should be written from the host +#define MAX77705_TEX_MASK BIT(8) +// Enable Thermistor +#define MAX77705_ETHRM_MASK BIT(5) +// CONFIG2_REG register +#define MAX77705_AUTO_DISCHARGE_EN_MASK BIT(9) +// STATUS_REG register +#define MAX77705_BAT_ABSENT_MASK BIT(3) + +// @brief Convert voltage register value to micro volts +// @param reg_val - register value +// @return voltage in micro Volts +inline u64 max77705_fg_vs_convert(u16 reg_val) +{ + u64 result = (u64)reg_val * MAX77705_FG_VS_ADC_RESOLUTION; + + return result / 1000; +} + +// @brief Convert current register value to micro volts +// @param reg_val - register value +// @param rsense_conductance - current sense resistor conductance in Ohm^-1 +// @return voltage in micro Volts +inline s32 max77705_fg_cs_convert(s16 reg_val, u32 rsense_conductance) +{ + s64 result = (s64)reg_val * rsense_conductance * MAX77705_FG_CS_ADC_RESOLUTION; + + return result / 10000; +} + +struct max77705_fuelgauge_data { + struct device *dev; + struct regmap *regmap; + struct power_supply *psy_fg; + struct power_supply_battery_info *bat_info; + u32 rsense_conductance; +}; + +#endif // __MAX77705_FUELGAUGE_H