From patchwork Wed Oct 23 19:42:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 837987 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (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 409C71E1322; Wed, 23 Oct 2024 19:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729712586; cv=none; b=McwS2lpMBn+fZfxQa4ScnnU3/qCsVY/HZaFg25C1bT426akvsYOcBHcgZbB5ND1D9FaEAqTPqt1kJoRcqn634tlK0r9QaFfLLvDBy1yX7owCYio54dydBcxAbXosalBKvR6nD2xl10JTlZ92YOF+2ofxHSsesy8jfoyvi/NK08M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729712586; c=relaxed/simple; bh=YFnNe+04ZW7T6FaMDt8f8dBNiHy+MpEDReCgmtW7/k4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YYyHF2YUps9t1Zro9u7/Xk3rlFs5skTemWstSXDYERVyX69EkgSB/tLopHi4vVQqEi39D25NrR61jMGPmTxvtCQcSKmLQE5feug/oSyMT/WQ3ElNCrQa+zHVQOpCZ3Wp5DSVZLTyymcz8fUZjVkCeNWbL5vCe28YhGt+dWhcEOE= 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=GJByTYQu; arc=none smtp.client-ip=209.85.208.45 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="GJByTYQu" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5c94861ee25so82428a12.0; Wed, 23 Oct 2024 12:43:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729712582; x=1730317382; 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=qOdPvgSZldfYAho7pM5Iu3076bZ8+xAOPGSdiV83Eps=; b=GJByTYQu8o0QfMEI3zS+pnMKXs/DKlMiZQ7J3769gIAXNcq4YrjKMLmntmfGi+Ea9Q LpQC5D8mBDZt9L2PQVlGw9FpibVouel/wvbGpjDGsrK/JksewO3mRmTWnIY4wbX15akW dHPvV0c0Oi6UMTPr0iey2hc2qzWagd+EE0QUENXSQaZ2Sboqw0Yij9beW0MzSbPQEsNV VFg9MnDxKMHRwTKhw7Tyb+8G5MukTI+nIB8oAiDs01KXfc208Aett25VQoC7xm2RnMfs 20OU3ecILcOqBZ1Ztviw1E/OWrh1L0fO18WqpJll8YDUm+QbWSuOhBhBdEVfmHR/51vA Nb5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729712582; x=1730317382; 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=qOdPvgSZldfYAho7pM5Iu3076bZ8+xAOPGSdiV83Eps=; b=Rh4BXvGYKr1vym+R++OahYl+EGzoMotOBAzuP+pCxf5mwF/EWo0y5R+rKzU9juCB3H Qbdn5XZuk7eERCsruGyvaCUXLhX33KYujSnGHcHMANMyrESP+jROzxuWdDRX0S6acVSO kyj4VbP/xrv9/iwgGI11FFKi8eKCiccwhThQk9zjiqaWoLC15ZobfnGJIaN5nBfbUrUT RHOpz+8HUgrmm/rvouANXd2jRxdTCq2szkZRVJ1G75bXeNp/swnD+1AIeOO7wJb6JPKm FDqWBv0roFrdInLJYd0e5aaHU5uHqw4kLyxujydzs0N5gHKi1znfkh6Jir99AEvrFZI2 Rfpw== X-Forwarded-Encrypted: i=1; AJvYcCURK8ibsmpYzxsgs8+CNvu294YYpyxsdwqvxx0Jk7b6wi0fuLYZZYcRghaEQJyni56pmj8Reizu9Iwt@vger.kernel.org, AJvYcCUcaUkI8Ff64IauunGv2jVYplCbWJgb3sKHY+APTF6+kxNbP8O+/c/A9zJeMG0P5qenRLqZKHkZcxuyXCw=@vger.kernel.org, AJvYcCUtpRbx39HrPxztlhsZ2JowAsjBAGDZaRnvVKHOT0kz+9m5zyL1QunQvt6gDXfiI0qOZYuV05Kv1tvz+Q==@vger.kernel.org, AJvYcCWtIdRCeOo8PmdCyAXRa8w8HlIHQdXi0V83wvKYiA5Md2rwqMol8LbP9AquT+5CDr+ox+qIqZiBl5GLFq/S@vger.kernel.org X-Gm-Message-State: AOJu0Yzf/COZPb5m7tjCT5u31ENjrIx3smQh01RDDgGeh8laJ22CR5/Y aHCj15aBAJQXJNBBmWC6RGpimdRf+psQVNnBnxx8evWSqxZq4/kjGtPDew== X-Google-Smtp-Source: AGHT+IG8zCkNAy6gj/LoO/ZO0JprTDhHy8Erjvxf7e+DQYAnQQNv38g6N+l7tODggE8QLzsX2kjfZQ== X-Received: by 2002:a05:6402:5d3:b0:5c8:9529:1b59 with SMTP id 4fb4d7f45d1cf-5cb8b1e9c71mr3269433a12.20.1729712582085; Wed, 23 Oct 2024 12:43:02 -0700 (PDT) Received: from [127.0.1.1] ([46.53.244.166]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b1d8sm4803940a12.72.2024.10.23.12.43.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 12:43:01 -0700 (PDT) From: Dzmitry Sankouski Date: Wed, 23 Oct 2024 22:42:50 +0300 Subject: [PATCH v7 2/7] dt-bindings: mfd: add maxim,max77705 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241023-starqltechn_integration_upstream-v7-2-9bfaa3f4a1a0@gmail.com> References: <20241023-starqltechn_integration_upstream-v7-0-9bfaa3f4a1a0@gmail.com> In-Reply-To: <20241023-starqltechn_integration_upstream-v7-0-9bfaa3f4a1a0@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.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729712576; l=6162; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=YFnNe+04ZW7T6FaMDt8f8dBNiHy+MpEDReCgmtW7/k4=; b=RhtDnD0cyKNaFgUIEGji+/iKwfDzkihgmViS9omRQrx4J04RrhqfnuBvOcEZLtx4q2ZSUWT9m Auf7hDVUIEWCozWmehXJyWUdt8Ywc9D5tTcdPuZq7O5CxSFvOEM8dfY X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Add maxim,max77705 core binding part. Reviewed-by: Rob Herring (Arm) Signed-off-by: Dzmitry Sankouski --- Changes in v6: - unevaluatedProperties must be false - drop excessive sentence from description, just describe the device - change leds compatible to maxim,max77705-rgb 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 | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 175 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..33dfc5b4fab7 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/maxim,max77705.yaml @@ -0,0 +1,174 @@ +# 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: | + 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: false + properties: + compatible: + const: maxim,max77705-charger + + required: + - compatible + - monitored-battery + + fuel-gauge: + $ref: /schemas/power/supply/power-supply.yaml + type: object + unevaluatedProperties: false + 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-rgb + + "#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 2ce38c6c0e6f..5c3de689a93b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14116,6 +14116,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 Wed Oct 23 19:42:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 837986 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 97CEF1EF08A; Wed, 23 Oct 2024 19:43:08 +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=1729712590; cv=none; b=N+b/bY6KnusCC57abeWqNbPWFYXv5/Y5iQBtQNknFKMle0RVqie/Lz9Yc9kLiLQiZ1qPP2N5kfNz7Vlatx+M4J6PKbb+PNIvXxQUkMSNlvFQuwSVDR60g7SWPZ/NgOzPHdvMx1W27OqsZuE4lPOl/5rs56aTEjVWrmsziz8hkSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729712590; c=relaxed/simple; bh=XJYEk/mCiry62oVQMajkS7XejvIef8TuTfCRS3x2m5g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mLtLodP+nRfHifCg4xVJ950/nK8P9+5IWJqFbbf6gOQcM2644rJJK598qv41MZI6ulQGdeQZSzOCft1/CApWtgr9G38vo89ToFdC7v2QnGK7MSuo6p3yxxMO9RFrDhqkFKdB3e+4OBrseZ0RebqmSW4YRyshG5mnj2Z6snbS+9c= 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=EYp+ZxZW; arc=none smtp.client-ip=209.85.221.53 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="EYp+ZxZW" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-37ec4e349f4so68098f8f.0; Wed, 23 Oct 2024 12:43:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729712587; x=1730317387; 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=JV5gv50tNIl9j7OCpfl/gJrWPboaYw/v/JR/D33ZJrY=; b=EYp+ZxZW51WNfkkzFmbdZiA8sW3FJ+c8SlAmkn1M/9IoULao1k0plOt8bxG8PfwJJS yZ0aI6orCpxkr49gmXq12177uZcRQM1u42cMIFAjIdfBG81cs5wKcYFmuyMSQ4gpWmmu 6kEWJU3Bs6sorp/4ABPJFBmg/GijARc0mFpqaJXwAEXkWi51PzxLxy95ZM7QR24Enbsu ad/peG42ICcYUgMK6fz77ZgRnZYbXY3ynfoEE67wu1gNLziG26cx5zZR2R6fRZFEfgAM Jxz41KhRnZDC+YQQv/cxPnL+2MFCIIdEKY/Ge5mi9UcqAHGFiQGh2nQDUBueATAzO35m QdOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729712587; x=1730317387; 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=JV5gv50tNIl9j7OCpfl/gJrWPboaYw/v/JR/D33ZJrY=; b=prIPvd83XaL/wEhhqZASdtNbd5r9/WJQV/iHZndNyNaVJ9HoWepDxQMT+j43imjPPx 1IV8MHASGFHdGKEqg9VfSSdaTavxMIrhdbcJmHvgq0b0v/G3OicJkqhnmjtF/Anc4Bpw NpQC+Hh3dJmt6RKnQ6gJmNZHKYvInkfcwmDtlvyb9Eq88jINc6tW1vUlZUphrBXwKSpU FvF1Hg1KbeFL4xMUDyprpFF2N0XXyCiQ6eBYq+8vGhDUp0ti/ykjV0tvD6V1ecsYZfV7 uNZiYKZvQNye2EBPPCuF8uhmu+4gOzWI7YDEDnPyRGgk8VuUh3FSsNwUHZcGe5UujLyw cUug== X-Forwarded-Encrypted: i=1; AJvYcCUJ7qTOZhrBe6A8Ge0Jh1AAuxneKKvHyoAuHD0iGZMosbHs/qksoViBX6FKAe/4L/ZPI7ou/6iTD4SN@vger.kernel.org, AJvYcCV4EOBH+ah2OhQmNx3rYgnWtSb7ErTsviVQY4AWxrmLyPOvHki7DZgOFJ9Hz9JZYHJQWlqvUhGOHcQhlbs=@vger.kernel.org, AJvYcCW3OpxApaOKXoEj8Mmy9BBcakZBjj4m23Cc3m2q3rXMhh6mivHI+MS1Nd3caAr2Fu9CB3MyE+KVf7/Xig==@vger.kernel.org, AJvYcCWLK5GVeB24N/2UgNDIVSe1UwUhw3ZJ743Y05ITTEM6KSBQm2oQL8f5xlIoRyWkAP05gKjeyQjTWNjGk5ij@vger.kernel.org X-Gm-Message-State: AOJu0YxNlSEi93UKpwzGHZFGGQY37ZmWGzXK0Nn3LW9YtISmtRw8mo1w UnaHpZDx7XpczonxhiXbEVvNMA5M5NjjpIje+Mkz/HxGPhNTXTliGF54wg== X-Google-Smtp-Source: AGHT+IHcMtuS4g5CWkPpDf1hqUOkbCoyak0zOYnMv4yfD9i4Ub3KEq3JJsYtM2gEQF4GAntU1tqs+w== X-Received: by 2002:adf:a301:0:b0:37d:377f:51e6 with SMTP id ffacd0b85a97d-37efcfaaef7mr2384296f8f.56.1729712586477; Wed, 23 Oct 2024 12:43:06 -0700 (PDT) Received: from [127.0.1.1] ([46.53.244.166]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b1d8sm4803940a12.72.2024.10.23.12.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 12:43:05 -0700 (PDT) From: Dzmitry Sankouski Date: Wed, 23 Oct 2024 22:42:52 +0300 Subject: [PATCH v7 4/7] input: max77693: add max77705 haptic support Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241023-starqltechn_integration_upstream-v7-4-9bfaa3f4a1a0@gmail.com> References: <20241023-starqltechn_integration_upstream-v7-0-9bfaa3f4a1a0@gmail.com> In-Reply-To: <20241023-starqltechn_integration_upstream-v7-0-9bfaa3f4a1a0@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.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729712576; l=4280; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=XJYEk/mCiry62oVQMajkS7XejvIef8TuTfCRS3x2m5g=; b=vdGJbC8Tannx7jJx39NwjAa6Nyn5HZL4aYawuFkqGjkV51bDTh2ePn+bvQXT106unynTkr8Al X00IHXSDBgZAJz9CaRlw1MByIuMejnUEET/mlr1iu2x5N7G5v1HdbNe 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. Acked-by: Dmitry Torokhov Signed-off-by: Dzmitry Sankouski --- 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 Wed Oct 23 19:42:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 837985 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 8A6831FCF7B; Wed, 23 Oct 2024 19:43:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729712595; cv=none; b=T7YtZjhTxFKzYh7ZBDxy5UC+IK+3zdzYOtQe/lLwIdeqfP5yvjaeHa1qiQm/VVGOV31baJhGW4ZhaPTeRILbzIZLykA1J0jJMuMXFTARnA46GlgBYWbTV5K/GrW+8u8mn6T5HN2pXQ0lhdt5EARhCwMHfKOE0IVMaVeW21zKbPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729712595; c=relaxed/simple; bh=d6rvOfGu4B8zT1wz85Jri8Q3WYEERaIIrHv2vY5vfNs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Nx21nU/esttGG9J+KFX9HarDnrChMsnMyM7XSB+gnCQdG+CQQYBs+jJeZd+wigX0qwN5Q0GjyboHHqo1ymWW8//pPk6LGCw2Nja8A6AogoaNBnaCZgyJKBo9XrfNHVhtveIDfMNWJhVloOd7otf1842SlCg2xovdR9D3KpDnlXc= 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=XYNLUVyW; arc=none smtp.client-ip=209.85.208.181 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="XYNLUVyW" Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2fb4ec17f5cso954311fa.3; Wed, 23 Oct 2024 12:43:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729712591; x=1730317391; 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=JwAoRGquy+aDIdZPwVk+mMEMgBMOZQ1nslIyGT6p3zI=; b=XYNLUVyWq5yteUCly+V54dPKg8XC19tbRq2OB1yJHYClx3HCxE/QtKDmjUr5+x+kd9 JmD70h+suQMF3yy3PpIzp3uGUlDvk0YSh4SMYVZzjtHwDdUIoEuO1HckFStaxfjq8XNa Q5g7dWSwme1Awk96KTe6aqDwDv14UKmN4CcCkeg+D/VLzRq+A0YUaf6DivztRwRQgxu4 fLzmjzwpEMng7vLW57YInCWVWHWcMPhn3qBxm5Pcb7rKyY8CNWRMKkzT4HvMNUwex6wV H5s6eGyVceI8l3nGQreZ1e5uMR4IseWUEj8/TLxZAuHi3SAK/QASJedZiD40u8xl+H7m huzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729712591; x=1730317391; 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=JwAoRGquy+aDIdZPwVk+mMEMgBMOZQ1nslIyGT6p3zI=; b=ghI5g5Z7+1aNvbFPpJ3Q+LeNwe4dEi1knDnmPK08GJ4D04L+qEvHKjILL5kmRI6OrY Niw4UTPKEjJNEaBnQHSSKJgyYCR7bcOJDI5BDdHkTvNaRApcDaPbNfzECV8cJh03+4r+ P0h/hfpUFyZxWnulG88LVBhLrJ29A6fEab8AimXCqn69yQP/5MZ1/0RPtZBiDB4bWzJD Mzy83mYEeUKMOSrJs3vrm4HXKBi8gc3TlxXkJUz5C9jRWQzyX5B56fQGB4TL/Ov5+DhM YRE3IuuI4UfHTBAwmZUcss5QVUg1yBavLYg7X6cBG4ak14LqVm3eW69l2yhQA/EdNV1P VeJQ== X-Forwarded-Encrypted: i=1; AJvYcCVGD/XWW8SfX30xeTQb/+4aw6/zbGeWqMPuZqkLXzBhcioWIpe6LU1I6LMm7FNTw0COzzR8iueADbEj5RE=@vger.kernel.org, AJvYcCX3WsSiKVeO7lJbOBmu2S1aphE7bRRvKXLJp+cNIpleDv2l8Nd1P3SXni/RP4maYb6XuBhw/uPLAWn68Q==@vger.kernel.org, AJvYcCXQ090uCLpcC5206VAVq3LMtyzU7/GsdAECkGfsllylDDy2xs/jU9pioppyRIbs3x3nLMAmZ4c9Qm4m@vger.kernel.org, AJvYcCXfjl/8NHmdDTHAEytxBFbrjfe4c0nXPk0Zn4HWCTnICMSPPF4CD7ZYGt5oDqivppnbaB/C535DpF9TQgdW@vger.kernel.org X-Gm-Message-State: AOJu0YyzgklkkEZzNodE81D5/lBYPV9MnzFxrYjRm/ucESKZjA9C9N+k /Pz1995Buz+H97C9O9iiNzL6mp9TzUmRF9qMatWocDExTxXk/WMXDBro5Q== X-Google-Smtp-Source: AGHT+IHTq14NsQIW4MFtw11h8oB5t0lPmP7NBYaReREJ0M/bsT0+vjEKN+rubAh4IEf+TdHOMYIDgg== X-Received: by 2002:a05:651c:211a:b0:2fb:8df2:13eb with SMTP id 38308e7fff4ca-2fc9d609971mr20134511fa.36.1729712591098; Wed, 23 Oct 2024 12:43:11 -0700 (PDT) Received: from [127.0.1.1] ([46.53.244.166]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b1d8sm4803940a12.72.2024.10.23.12.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 12:43:10 -0700 (PDT) From: Dzmitry Sankouski Date: Wed, 23 Oct 2024 22:42:54 +0300 Subject: [PATCH v7 6/7] power: supply: max77705: Add fuel gauge driver for Maxim 77705 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241023-starqltechn_integration_upstream-v7-6-9bfaa3f4a1a0@gmail.com> References: <20241023-starqltechn_integration_upstream-v7-0-9bfaa3f4a1a0@gmail.com> In-Reply-To: <20241023-starqltechn_integration_upstream-v7-0-9bfaa3f4a1a0@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.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729712576; l=15965; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=d6rvOfGu4B8zT1wz85Jri8Q3WYEERaIIrHv2vY5vfNs=; b=2k4D4hslzH6mZW2CHvlcosVYdPtkbuOWoHylwtMNdE0yQmWB4IPpzZ56QZ7DhVmTBhzL48IkW Avn28nVAvqZBwzH6sAsMjfnTCQvNj7RxmCXKzC7QFbAWC+42j5I1Mw3 X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Add driver for Maxim 77705 fuel gauge (part of max77705 PMIC) 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 v6: - add i2c init in driver - initialize unintialized ret value with 0 - remove unused CAPACITY_SCALE_* constants - max77705_*_convert: replace multiplication and divison with mult_frac helper to fix https://lore.kernel.org/oe-kbuild-all/202410111913.5ADtNHNM-lkp@intel.com/ - max77705_battery_settings: move out battery settings gathering and rename function - probe: do regmap setup last, because if power_supply_get_battery_info fails, we're going to probe again and fail with i2c bus busy error - remove MFD from commit message 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 | 364 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/power/max77705_fuelgauge.h | 60 +++++++++++++++++++++++ 4 files changed, 432 insertions(+) diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index 66264036b65d..9a3b17036ddc 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -589,6 +589,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 85d65b7aee1c..997049fc1795 100644 --- a/drivers/power/supply/Makefile +++ b/drivers/power/supply/Makefile @@ -81,6 +81,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..a62111bb3cc0 --- /dev/null +++ b/drivers/power/supply/max77705_fuel_gauge.c @@ -0,0 +1,364 @@ +// 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 + +#define I2C_ADDR_FG 0x36 + +static const char *max77705_fuelgauge_model = "max77705"; +static const char *max77705_fuelgauge_manufacturer = "Maxim Integrated"; + +static const struct regmap_config max77705_fg_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77705_FG_END, +}; + +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 method\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 = 0; + + 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_write_bat_info(struct max77705_fuelgauge_data *fuelgauge) +{ + struct power_supply_battery_info *info = fuelgauge->bat_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"); + return max77705_fg_set_charge_design(fuelgauge->regmap, + info->charge_full_design_uah); + } + + return 0; +} + +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 i2c_client *i2c_fg; + 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; + + 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); + + ret = power_supply_get_battery_info(fuelgauge->psy_fg, + &fuelgauge->bat_info); + + if (ret) + return ret; + + i2c_fg = devm_i2c_new_dummy_device(max77705->dev, max77705->i2c->adapter, + I2C_ADDR_FG); + + if (IS_ERR(i2c_fg)) + return PTR_ERR(i2c_fg); + + fuelgauge->regmap = devm_regmap_init_i2c(i2c_fg, + &max77705_fg_regmap_config); + + return max77705_write_bat_info(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..daa28dff4c00 --- /dev/null +++ b/include/linux/power/max77705_fuelgauge.h @@ -0,0 +1,60 @@ +/* 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 +// 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) +{ + return mult_frac(reg_val, MAX77705_FG_VS_ADC_RESOLUTION, 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) +{ + return mult_frac(reg_val * rsense_conductance, MAX77705_FG_CS_ADC_RESOLUTION, + 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