From nobody Mon Nov 25 23:18:42 2024 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (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 94A7B13BC11; Wed, 23 Oct 2024 19:43:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729712584; cv=none; b=u5jdltH5wR6MmswUlLqHW/wAZRCzKmlIyDtAPQiDVT/MPUi/0mZ8gwh7+KKPlxcuBWA1z5Yi/f2lYj9SKXDE8dmPAEktS2mB9JdgTuj4uDB36fvHh16wKW7RCfvD2bYvnOZGTJdtgNIEz9va/CjkYX2dLzr77TLxb5XHLWUuwIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729712584; c=relaxed/simple; bh=y/7jYmf1JcJqTTDBz6fJcxDfIXqmBQfVP45wXhvGGlI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KVj/i/TUNmms/UFVn2UUwf31pfwsznJ5e8wxV0hH0ii5BiYwKpEJ7+YbxZhh4081+8GI9cSADRzaNuPGqlxyLWIYAcx8mK4sYg0CafKhVpHSo68Kiujwzps5e6iC3ezZr+CVgmWip3z+FB1oHkpHay4DRrfHmslXo8UxtaIPmqM= 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=Tba2eaGK; arc=none smtp.client-ip=209.85.208.171 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="Tba2eaGK" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2fb5111747cso1236871fa.2; Wed, 23 Oct 2024 12:43:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729712580; x=1730317380; 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=qNk0fOb9DIQVLHw9i7VYExiUbdtUJ37rSb7ICr8WfBE=; b=Tba2eaGK26zTQHdr1eb0F/0NdTCkW5u4n6EW8CLB/OFrcIinI4CZlbqOTZxafq9k0u XoZMxv9XSle1u5T9JHhQXyriV5eiqkSV78JYI4J+OqI7aTybvw3iEzo6aO5EdDX2rJ8M 1kb/ay9Nse9L+kd/Utf8DC5bobz0DCANJPNYPAb72cC/WowE22Rw0kVH/ucpUMYxG7Nx 3NB/QqOKAP37Zyy4jfzM2UgAt0rQfdb6bw9LTfDYD4WbCnF+bbfTVt97ywHzpivFMNCN vA+ghgrAI7WLGoEdSfzBxHchvBBwOo3hdSgPgKqZWIqkNvoVjrJ2NrpEhkrE19nEpVbu Q6qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729712580; x=1730317380; 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=qNk0fOb9DIQVLHw9i7VYExiUbdtUJ37rSb7ICr8WfBE=; b=CnYDA8Ue7XszuY7Q1BOvBJE5UzZtQ22pOT56VlNKKnK5OlwV36zCjAU3s60uUYiFqU Ddj/0zobiMPUHr2qD5U92MCBWuD4VRDlzdFQooraqXWJwXZ7pi9ZvNO1jVkZ8LdDUowD Jsl0g3zPXmD8e5guryTXN91MTaVeXF68VnkBogNiIOEFhCnwyPlP6h75wIiiN3yTxrON csFQX7ixx0BCb+H2THjgZtOowJl0x006dwcZaxa7ymK5TZSeSnNBXJ4T1XUXx0aG6jcY sHELex/K6FIVvKv0iScgwLKB779C/zA0p3ytJP/CeG3tsoNiE0Q5VyQ1tV+2aIRPX7KC POYQ== X-Forwarded-Encrypted: i=1; AJvYcCV8ESfw6Kh6WL4XGS7bKUwLPJ11rIHwTWRW64BayQICBzKjexVGtlsDHy1QA7a4oKe4mCbUobyy97DO@vger.kernel.org, AJvYcCVze825EwAEluV7RzSkad2cDCSye/pzVmNHakA0A1/xsHed/HnLkSrYm0M2k3tG7FrcHJfKVsBnvg7JzpLF@vger.kernel.org, AJvYcCXOrqMoEOF34kFv/vRPq+4O6Ovnzz8fk9o5oKfRsRAj4b8YS9/WFYIjB3Y88WnEuBSbISBZ+fb0yL5txw==@vger.kernel.org, AJvYcCXj34lIaa6BK55C5IdUHRMljdLaQ6DmvBQCzpPHQI5DpxVx0ReAScSn8xlV7h48BJOIM8gArws83kViN/o=@vger.kernel.org X-Gm-Message-State: AOJu0YzsL3D9lxZEOCkfQhn2I/6bkGJyqKWjfrBy8LgHA4e3JrVEuATq zlsrm5JUFtrwpmBHLF4vZF6ZnMBAcXA+UaL5Z2bNsKaEFHDmKKSzOyFd6A== X-Google-Smtp-Source: AGHT+IGSlTSMEUDWa5zkqAnk1M/8JnSJQQ5A2rsUFZ0Eb9qxUx54wP4dKysIAXrGrIpNxfQ6BtJKqA== X-Received: by 2002:a2e:859:0:b0:2fb:5da7:47a1 with SMTP id 38308e7fff4ca-2fc9d353f9dmr17138871fa.16.1729712580233; Wed, 23 Oct 2024 12:43:00 -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.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 12:42:59 -0700 (PDT) From: Dzmitry Sankouski Date: Wed, 23 Oct 2024 22:42:49 +0300 Subject: [PATCH v7 1/7] power: supply: add undervoltage health status property 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: <20241023-starqltechn_integration_upstream-v7-1-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=2343; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=y/7jYmf1JcJqTTDBz6fJcxDfIXqmBQfVP45wXhvGGlI=; b=JneTa0BzvjMPdrKEaKH9Kn5fj3tHERa20ejeyse3FvfW2bQ2LwA/fP3Cz/5OjZiLPEhJW6mps rrfnJcGWEpJCA0knUGpxzovGy/dgsGiiXt4Qg4Da+LJOtHSWbN2kuVg X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Add POWER_SUPPLY_HEALTH_UNDERVOLTAGE status for power supply to report under voltage lockout failures. Signed-off-by: Dzmitry Sankouski --- Changes for v5: - update Documentation/ABI/testing/sysfs-class-power and drivers/power/supply/power_supply_sysfs.c --- Documentation/ABI/testing/sysfs-class-power | 2 +- drivers/power/supply/power_supply_sysfs.c | 1 + include/linux/power_supply.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/AB= I/testing/sysfs-class-power index 45180b62d426..32c018c5d088 100644 --- a/Documentation/ABI/testing/sysfs-class-power +++ b/Documentation/ABI/testing/sysfs-class-power @@ -433,7 +433,7 @@ Description: =20 Valid values: "Unknown", "Good", "Overheat", "Dead", - "Over voltage", "Unspecified failure", "Cold", + "Over voltage", "Under voltage", "Unspecified failure", "Cold", "Watchdog timer expire", "Safety timer expire", "Over current", "Calibration required", "Warm", "Cool", "Hot", "No battery" diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supp= ly/power_supply_sysfs.c index 571de43fcca9..247c2910ba34 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -99,6 +99,7 @@ static const char * const POWER_SUPPLY_HEALTH_TEXT[] =3D { [POWER_SUPPLY_HEALTH_OVERHEAT] =3D "Overheat", [POWER_SUPPLY_HEALTH_DEAD] =3D "Dead", [POWER_SUPPLY_HEALTH_OVERVOLTAGE] =3D "Over voltage", + [POWER_SUPPLY_HEALTH_UNDERVOLTAGE] =3D "Under voltage", [POWER_SUPPLY_HEALTH_UNSPEC_FAILURE] =3D "Unspecified failure", [POWER_SUPPLY_HEALTH_COLD] =3D "Cold", [POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE] =3D "Watchdog timer expire", diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index b98106e1a90f..e96d262f3c2b 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -58,6 +58,7 @@ enum { POWER_SUPPLY_HEALTH_OVERHEAT, POWER_SUPPLY_HEALTH_DEAD, POWER_SUPPLY_HEALTH_OVERVOLTAGE, + POWER_SUPPLY_HEALTH_UNDERVOLTAGE, POWER_SUPPLY_HEALTH_UNSPEC_FAILURE, POWER_SUPPLY_HEALTH_COLD, POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE, --=20 2.39.2 From nobody Mon Nov 25 23:18:42 2024 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-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: <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/Do= cumentation/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 interfa= ce 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 suppo= rt. + + 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 =3D <1>; + #size-cells =3D <0>; + + pmic@66 { + compatible =3D "maxim,max77705"; + reg =3D <0x66>; + interrupt-parent =3D <&pm8998_gpios>; + interrupts =3D <11 IRQ_TYPE_LEVEL_LOW>; + pinctrl-0 =3D <&chg_int_default>; + pinctrl-names =3D "default"; + + leds { + compatible =3D "maxim,max77705-led"; + #address-cells =3D <1>; + #size-cells =3D <0>; + + led@1 { + reg =3D <1>; + label =3D "red:usr1"; + }; + + led@2 { + reg =3D <2>; + label =3D "green:usr2"; + }; + + led@3 { + reg =3D <3>; + label =3D "blue:usr3"; + }; + }; + + max77705_charger: charger { + compatible =3D "maxim,max77705-charger"; + monitored-battery =3D <&battery>; + }; + + fuel-gauge { + compatible =3D "maxim,max77705-fuel-gauge"; + monitored-battery =3D <&battery>; + power-supplies =3D <&max77705_charger>; + shunt-resistor-micro-ohms =3D <5000>; + }; + + + haptic { + compatible =3D "maxim,max77705-haptic"; + haptic-supply =3D <&vib_regulator>; + pwms =3D <&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 --=20 2.39.2 From nobody Mon Nov 25 23:18:43 2024 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.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 D65EC1E8829; Wed, 23 Oct 2024 19:43:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729712589; cv=none; b=jd0YeS0wQs1XaoIUN2Z/BYVlT27U1OezptXN9NDAHV36x10/vRt0ZKF2wM2Rqhjxr8s/O1zIAfjsZDzOyDVphyo/GpjRzLqNYE35NVIGhwDUAHzvCwquCb0QwwzqYeM+KnnuTr46m8aFJ1YECWwlkoI0OrEag4M6DZ5hRlsIZ0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729712589; c=relaxed/simple; bh=IV6bpuQV+DJyL6HbGpCYcqEN5Bxtbbazk9dj/Ki0pPc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V6Pp00SIL5sqm9pyG3iJs3n22YpIJHCe9OlDJ1V+rI/ORPGvRo/O6RThu34kFBzMy5mekytV0khau5cIlNWMTvpX6OyLsevMdpjNzPMHWRHLu2AqC/c+BMyjzcAQAfvG3DXIne6D3zuZHtAZLpT1+iSXMVDDBBppVyy/Yp1AqZQ= 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=cb0Hz7/s; arc=none smtp.client-ip=209.85.208.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="cb0Hz7/s" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5c94c4ad9d8so164207a12.2; Wed, 23 Oct 2024 12:43:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729712585; x=1730317385; 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=y0DHDDulL8BSFwTAowiymVtsa+Dc7E/wtl5TgqcXC10=; b=cb0Hz7/sp9x6Dz4BNAm0Tp9/8ypvnleBhZpSK3L0j4Fydq4sjRDn5vrCX/AXhtWuHL coqQuSlw4FG6YNgPXT/0OtyZz9KAsl2lOh7kghFrxWWYl/ntycyv0daQnYGDSRZVBsRl NcnDK1XkGofxgOFlgNEh9fI0QKlZS0+OP02LSBAoAAcG3aLB8eMDBufX3/jtl/Hbgrcf HOst96xvkydsze29kayi+PpdFEXFDflTk6nhpwltELePpcQ/P+0t4QY4Qjy/K6KwQFSb gUOsu3PyRPWE3bafU7DQGy9eugeQsqGp1kmcyG5tr58xl+2bzFaLQtWK+f02bk4gfMOr LqCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729712585; x=1730317385; 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=y0DHDDulL8BSFwTAowiymVtsa+Dc7E/wtl5TgqcXC10=; b=RwCxVrYszQwZiY8nhCa13LWno5CfTZVg32GA0u/HtTvWI4UjD0Y2BQ/yj2xXql4OVC 9gKA0O2KiSEJPsBtZ+dxg2A43CIvqvnJimIuSZImgHNfil/9B5hHZzz9vZe3ZKP1Sk5M XYVth4FuRRYdUdsO/j9f1T7PU3HIDTOo4Hqtd/h2nGiARdNqqlkosGwEO1JxuiGzq+K3 gZdEYkXyKJgAYLbmpA48VGQ92HgtzPJvBpRGdabJCy+26gixomNU+dyj/XT22H0RDdFl KomomXgK23B1LPltsi64H0F8416xBzGdv7Ew8QiSmg2T5RMStkLfeP/QHG8slSdfAtiP IH/Q== X-Forwarded-Encrypted: i=1; AJvYcCUrXglmO27jDAuG4JbVmfvsMv7Sf4zAGSgE5swbRsO7zrWGvs+KckF9Z8F8S7GFhTM4S1qDTht84HQwWoM=@vger.kernel.org, AJvYcCVpNnz041PBWJ7h4LlxIxJHbdV0pfQjA8gyc+UaGoktGtmWnm9zaNEbk5gHKo4ZkF8Dn6KzYA46EOUHR82w@vger.kernel.org, AJvYcCWuYbuT+yjWkcAwFQ9fJ4Or095FFDUXgsIlxdkoscnPmo5wVg9CREU/xNOJOezj+aMN0Xsy3uR1U540@vger.kernel.org, AJvYcCX7cG3HJ8lo7mPIiugdu1tNwBLKMGY4KNi0Z2nDTT4tySZnpBiwJ9qlPC1cjyUIzedWJXHUjuydN69ziA==@vger.kernel.org X-Gm-Message-State: AOJu0YxMw99dOoAPjhGJAAed0IB4sFN5dDKT6krTJY9Yf/Jtv1dxV2jP UqiQfB27OC0YXtfMepzrrAvy7uDCTcxyzFBCP+ySTwZpcQREMtGZvSAYOg== X-Google-Smtp-Source: AGHT+IF5uVBGbmkpGhoBAGUc/tImyx6t2ntzCkAGX2fTEJ9fKdgeKDnD8NWL1Wc9VjzBe/5x6//GEA== X-Received: by 2002:a05:6402:520c:b0:5c4:4dfd:9fd5 with SMTP id 4fb4d7f45d1cf-5cb8af949f6mr2887546a12.29.1729712584607; Wed, 23 Oct 2024 12:43:04 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 12:43:03 -0700 (PDT) From: Dzmitry Sankouski Date: Wed, 23 Oct 2024 22:42:51 +0300 Subject: [PATCH v7 3/7] mfd: Add new driver for MAX77705 PMIC 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: <20241023-starqltechn_integration_upstream-v7-3-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=18104; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=IV6bpuQV+DJyL6HbGpCYcqEN5Bxtbbazk9dj/Ki0pPc=; b=YeIqcswZctPL/o5h2G49QGOZKKmzXWSVFFP4uDr23ln2EUbtC63mlyZWakppx3WSLncs1yG1K mN3bnjAk1XSAUg00jDMFhh9q3GKqT/hrtAjqSjJj/pTZ7+6CzockoP4 X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Add the core MFD driver for max77705 PMIC. We define five sub-devices for which the drivers will be added in subsequent patches. Signed-off-by: Dzmitry Sankouski --- Changes for v6: - add PMIC suffix in Kconfig - remove filename from file header - reorder headers alphabetically - move out fg and chg adresses definitions - rename led name and compatible - remove overbracketing - move charger and fuel gauge i2c initialization to their drivers - fix max77705_i2c_driver tabbing - formatting fixes Changes for v5: - license change to 2.0 - use same hardware name in Kconfig and module descriptions Changes for v4: - rework driver from scratch - migrate to regmap_add_irq_chip, remove max77705-irq.c, rename max77705-core.c to max77705.c - cleanup headers - remove debugfs code - migrate to use max77693_dev structure - remove max77705.h --- MAINTAINERS | 2 ++ drivers/mfd/Kconfig | 12 ++++++++ drivers/mfd/Makefile | 2 ++ drivers/mfd/max77705.c | 224 +++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++ include/linux/mfd/max77693-common.h | 5 +++- include/linux/mfd/max77705-private.h | 180 +++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++ 6 files changed, 424 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 5c3de689a93b..92700fc71db1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14123,6 +14123,7 @@ F: drivers/*/*max77843.c F: drivers/*/max14577*.c F: drivers/*/max77686*.c F: drivers/*/max77693*.c +F: drivers/*/max77705*.c F: drivers/clk/clk-max77686.c F: drivers/extcon/extcon-max14577.c F: drivers/extcon/extcon-max77693.c @@ -14130,6 +14131,7 @@ F: drivers/rtc/rtc-max77686.c F: include/linux/mfd/max14577*.h F: include/linux/mfd/max77686*.h F: include/linux/mfd/max77693*.h +F: include/linux/mfd/max77705*.h =20 MAXIRADIO FM RADIO RECEIVER DRIVER M: Hans Verkuil diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 03c1e4e3eea4..9bb19716d5cf 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -916,6 +916,18 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. =20 +config MFD_MAX77705 + tristate "Maxim MAX77705 PMIC Support" + depends on I2C + select MFD_CORE + help + Say yes here to add support for Maxim Integrated MAX77705 PMIC. + This is a Power Management IC with Charger, safe LDOs, Flash, Haptic + and MUIC controls on chip. + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + config MFD_MAX77714 tristate "Maxim Semiconductor MAX77714 PMIC Support" depends on I2C diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index e057d6d6faef..d981690b5a12 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -168,6 +168,7 @@ obj-$(CONFIG_MFD_MAX77620) +=3D max77620.o obj-$(CONFIG_MFD_MAX77650) +=3D max77650.o obj-$(CONFIG_MFD_MAX77686) +=3D max77686.o obj-$(CONFIG_MFD_MAX77693) +=3D max77693.o +obj-$(CONFIG_MFD_MAX77705) +=3D max77705.o obj-$(CONFIG_MFD_MAX77714) +=3D max77714.o obj-$(CONFIG_MFD_MAX77843) +=3D max77843.o obj-$(CONFIG_MFD_MAX8907) +=3D max8907.o @@ -233,6 +234,7 @@ obj-$(CONFIG_MFD_RK8XX_I2C) +=3D rk8xx-i2c.o obj-$(CONFIG_MFD_RK8XX_SPI) +=3D rk8xx-spi.o obj-$(CONFIG_MFD_RN5T618) +=3D rn5t618.o obj-$(CONFIG_MFD_SEC_CORE) +=3D sec-core.o sec-irq.o +obj-$(CONFIG_MFD_S2DOS05) +=3D s2dos05.o obj-$(CONFIG_MFD_SYSCON) +=3D syscon.o obj-$(CONFIG_MFD_LM3533) +=3D lm3533-core.o lm3533-ctrlbank.o obj-$(CONFIG_MFD_VEXPRESS_SYSREG) +=3D vexpress-sysreg.o diff --git a/drivers/mfd/max77705.c b/drivers/mfd/max77705.c new file mode 100644 index 000000000000..212df3f78da3 --- /dev/null +++ b/drivers/mfd/max77705.c @@ -0,0 +1,224 @@ +// SPDX-License-Identifier: GPL-2.0+ +// +// Maxim MAX77705 PMIC core driver +// +// Copyright (C) 2024 Dzmitry Sankouski + +#include +#include +#include +#include +#include +#include +#include +#include + +static struct mfd_cell max77705_devs[] =3D { + { + .name =3D "max77705-rgb", + .of_compatible =3D "maxim,max77705-rgb", + }, + { + .name =3D "max77705-fuel-gauge", + .of_compatible =3D "maxim,max77705-fuel-gauge", + }, + { + .name =3D "max77705-charger", + .of_compatible =3D "maxim,max77705-charger", + }, + { + .name =3D "max77705-haptic", + .of_compatible =3D "maxim,max77705-haptic", + }, +}; + +static const struct regmap_range max77705_readable_ranges[] =3D { + regmap_reg_range(MAX77705_PMIC_REG_PMICID1, MAX77705_PMIC_REG_BSTOUT_MAS= K), + regmap_reg_range(MAX77705_PMIC_REG_INTSRC, MAX77705_PMIC_REG_RESERVED_29= ), + regmap_reg_range(MAX77705_PMIC_REG_BOOSTCONTROL1, MAX77705_PMIC_REG_BOOST= CONTROL1), + regmap_reg_range(MAX77705_PMIC_REG_MCONFIG, MAX77705_PMIC_REG_MCONFIG2), + regmap_reg_range(MAX77705_PMIC_REG_FORCE_EN_MASK, MAX77705_PMIC_REG_FORCE= _EN_MASK), + regmap_reg_range(MAX77705_PMIC_REG_BOOSTCONTROL1, MAX77705_PMIC_REG_BOOST= CONTROL1), + regmap_reg_range(MAX77705_PMIC_REG_BOOSTCONTROL2, MAX77705_PMIC_REG_BOOST= CONTROL2), + regmap_reg_range(MAX77705_PMIC_REG_SW_RESET, MAX77705_PMIC_REG_USBC_RESE= T), +}; + +static const struct regmap_range max77705_writable_ranges[] =3D { + regmap_reg_range(MAX77705_PMIC_REG_MAINCTRL1, MAX77705_PMIC_REG_BSTOUT_M= ASK), + regmap_reg_range(MAX77705_PMIC_REG_INTSRC, MAX77705_PMIC_REG_RESERVED_29= ), + regmap_reg_range(MAX77705_PMIC_REG_BOOSTCONTROL1, MAX77705_PMIC_REG_BOOST= CONTROL1), + regmap_reg_range(MAX77705_PMIC_REG_MCONFIG, MAX77705_PMIC_REG_MCONFIG2), + regmap_reg_range(MAX77705_PMIC_REG_FORCE_EN_MASK, MAX77705_PMIC_REG_FORCE= _EN_MASK), + regmap_reg_range(MAX77705_PMIC_REG_BOOSTCONTROL1, MAX77705_PMIC_REG_BOOST= CONTROL1), + regmap_reg_range(MAX77705_PMIC_REG_BOOSTCONTROL2, MAX77705_PMIC_REG_BOOST= CONTROL2), + regmap_reg_range(MAX77705_PMIC_REG_SW_RESET, MAX77705_PMIC_REG_USBC_RESE= T), + +}; + +static const struct regmap_access_table max77705_readable_table =3D { + .yes_ranges =3D max77705_readable_ranges, + .n_yes_ranges =3D ARRAY_SIZE(max77705_readable_ranges), +}; + +static const struct regmap_access_table max77705_writable_table =3D { + .yes_ranges =3D max77705_writable_ranges, + .n_yes_ranges =3D ARRAY_SIZE(max77705_writable_ranges), +}; + +static const struct regmap_config max77705_regmap_config =3D { + .reg_bits =3D 8, + .val_bits =3D 8, + .rd_table =3D &max77705_readable_table, + .wr_table =3D &max77705_writable_table, + .max_register =3D MAX77705_PMIC_REG_USBC_RESET, +}; + +static const struct regmap_config max77705_leds_regmap_config =3D { + .reg_base =3D MAX77705_RGBLED_REG_BASE, + .reg_bits =3D 8, + .val_bits =3D 8, + .max_register =3D MAX77705_LED_REG_END, +}; + +static const struct regmap_irq max77705_topsys_irqs[] =3D { + { .mask =3D MAX77705_SYSTEM_IRQ_BSTEN_INT, }, + { .mask =3D MAX77705_SYSTEM_IRQ_SYSUVLO_INT, }, + { .mask =3D MAX77705_SYSTEM_IRQ_SYSOVLO_INT, }, + { .mask =3D MAX77705_SYSTEM_IRQ_TSHDN_INT, }, + { .mask =3D MAX77705_SYSTEM_IRQ_TM_INT, }, +}; + +static const struct regmap_irq_chip max77705_topsys_irq_chip =3D { + .name =3D "max77705-topsys", + .status_base =3D MAX77705_PMIC_REG_SYSTEM_INT, + .mask_base =3D MAX77705_PMIC_REG_SYSTEM_INT_MASK, + .num_regs =3D 1, + .irqs =3D max77705_topsys_irqs, + .num_irqs =3D ARRAY_SIZE(max77705_topsys_irqs), +}; + +static int max77705_i2c_probe(struct i2c_client *i2c) +{ + struct max77693_dev *max77705; + struct regmap_irq_chip_data *irq_data; + struct irq_domain *domain; + int ret; + unsigned int pmic_rev_value; + u8 pmic_ver, pmic_rev; + + + max77705 =3D devm_kzalloc(&i2c->dev, sizeof(*max77705), GFP_KERNEL); + if (!max77705) + return -ENOMEM; + + max77705->i2c =3D i2c; + max77705->dev =3D &i2c->dev; + max77705->irq =3D i2c->irq; + max77705->type =3D TYPE_MAX77705; + i2c_set_clientdata(i2c, max77705); + + max77705->regmap =3D devm_regmap_init_i2c(i2c, &max77705_regmap_config); + + if (IS_ERR(max77705->regmap)) + return PTR_ERR(max77705->regmap); + + if (regmap_read(max77705->regmap, MAX77705_PMIC_REG_PMICREV, &pmic_rev_va= lue) < 0) + return -ENODEV; + + pmic_rev =3D pmic_rev_value & MAX77705_REVISION_MASK; + pmic_ver =3D (pmic_rev_value & MAX77705_VERSION_MASK) >> MAX77705_VERSION= _SHIFT; + + if (pmic_rev !=3D MAX77705_PASS3) { + dev_err(max77705->dev, "rev.0x%x is not tested", + pmic_rev); + return -ENODEV; + } + + max77705->regmap_leds =3D devm_regmap_init_i2c(i2c, &max77705_leds_regmap= _config); + + if (IS_ERR(max77705->regmap_leds)) + return PTR_ERR(max77705->regmap_leds); + + ret =3D devm_regmap_add_irq_chip(max77705->dev, max77705->regmap, + max77705->irq, + IRQF_ONESHOT | IRQF_SHARED, 0, + &max77705_topsys_irq_chip, + &irq_data); + + if (ret) + dev_err(max77705->dev, "failed to add irq chip: %d\n", ret); + + /* Unmask interrupts from all blocks in interrupt source register */ + ret =3D regmap_update_bits(max77705->regmap, + MAX77705_PMIC_REG_INTSRC_MASK, + MAX77705_SRC_IRQ_ALL, (unsigned int)~MAX77705_SRC_IRQ_ALL); + + if (ret < 0) { + dev_err(max77705->dev, + "Could not unmask interrupts in INTSRC: %d\n", ret); + return ret; + } + + domain =3D regmap_irq_get_domain(irq_data); + + ret =3D devm_mfd_add_devices(max77705->dev, PLATFORM_DEVID_NONE, + max77705_devs, ARRAY_SIZE(max77705_devs), + NULL, 0, domain); + + if (ret) { + dev_err(max77705->dev, "Failed to register child devices: %d\n", ret); + return ret; + } + + device_init_wakeup(max77705->dev, true); + + return 0; +} + +static int max77705_suspend(struct device *dev) +{ + struct i2c_client *i2c =3D to_i2c_client(dev); + struct max77693_dev *max77705 =3D i2c_get_clientdata(i2c); + + disable_irq(max77705->irq); + + if (device_may_wakeup(dev)) + enable_irq_wake(max77705->irq); + + return 0; +} + +static int max77705_resume(struct device *dev) +{ + struct i2c_client *i2c =3D to_i2c_client(dev); + struct max77693_dev *max77705 =3D i2c_get_clientdata(i2c); + + if (device_may_wakeup(dev)) + disable_irq_wake(max77705->irq); + + enable_irq(max77705->irq); + + return 0; +} +DEFINE_SIMPLE_DEV_PM_OPS(max77705_pm_ops, max77705_suspend, max77705_resum= e); + +static const struct of_device_id max77705_i2c_of_match[] =3D { + { .compatible =3D "maxim,max77705" }, + { }, +}; +MODULE_DEVICE_TABLE(of, max77705_i2c_of_match); + +static struct i2c_driver max77705_i2c_driver =3D { + .driver =3D { + .name =3D "max77705", + .of_match_table =3D max77705_i2c_of_match, + .pm =3D pm_sleep_ptr(&max77705_pm_ops), + .suppress_bind_attrs =3D true, + }, + .probe =3D max77705_i2c_probe, +}; +module_i2c_driver(max77705_i2c_driver); + +MODULE_DESCRIPTION("Maxim MAX77705 PMIC core driver"); +MODULE_AUTHOR("Dzmitry Sankouski "); +MODULE_LICENSE("GPL"); diff --git a/include/linux/mfd/max77693-common.h b/include/linux/mfd/max776= 93-common.h index a5bce099f1ed..8665097892cd 100644 --- a/include/linux/mfd/max77693-common.h +++ b/include/linux/mfd/max77693-common.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Common data shared between Maxim 77693 and 77843 drivers + * Common data shared between Maxim 77693, 77705 and 77843 drivers * * Copyright (C) 2015 Samsung Electronics */ @@ -11,6 +11,7 @@ enum max77693_types { TYPE_MAX77693_UNKNOWN, TYPE_MAX77693, + TYPE_MAX77705, TYPE_MAX77843, =20 TYPE_MAX77693_NUM, @@ -25,6 +26,7 @@ struct max77693_dev { struct i2c_client *i2c_muic; /* 0x4A , MUIC */ struct i2c_client *i2c_haptic; /* MAX77693: 0x90 , Haptic */ struct i2c_client *i2c_chg; /* MAX77843: 0xD2, Charger */ + struct i2c_client *i2c_fg; /* MAX77843: 0xD2, Charger */ =20 enum max77693_types type; =20 @@ -32,6 +34,7 @@ struct max77693_dev { struct regmap *regmap_muic; struct regmap *regmap_haptic; /* Only MAX77693 */ struct regmap *regmap_chg; /* Only MAX77843 */ + struct regmap *regmap_leds; /* Only MAX77705 */ =20 struct regmap_irq_chip_data *irq_data_led; struct regmap_irq_chip_data *irq_data_topsys; diff --git a/include/linux/mfd/max77705-private.h b/include/linux/mfd/max77= 705-private.h new file mode 100644 index 000000000000..6eb2b2e07c12 --- /dev/null +++ b/include/linux/mfd/max77705-private.h @@ -0,0 +1,180 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +// +// Maxim MAX77705 definitions. +// +// Copyright (C) 2015 Samsung Electronics, Inc. +// Copyright (C) 2024 Dzmitry Sankouski + +#ifndef __LINUX_MFD_MAX77705_PRIV_H +#define __LINUX_MFD_MAX77705_PRIV_H + +#include + +#define MAX77705_SRC_IRQ_CHG BIT(0) +#define MAX77705_SRC_IRQ_TOP BIT(1) +#define MAX77705_SRC_IRQ_FG BIT(2) +#define MAX77705_SRC_IRQ_USBC BIT(3) +#define MAX77705_SRC_IRQ_ALL (MAX77705_SRC_IRQ_CHG | MAX77705_SRC_IRQ_TOP = | \ + MAX77705_SRC_IRQ_FG | MAX77705_SRC_IRQ_USBC) + +// MAX77705_PMIC_REG_PMICREV register +#define MAX77705_VERSION_SHIFT 3 +#define MAX77705_REVISION_MASK GENMASK(2, 0) +#define MAX77705_VERSION_MASK GENMASK(7, MAX77705_VERSION_SHIFT) +// MAX77705_PMIC_REG_MAINCTRL1 register +#define MAX77705_MAINCTRL1_BIASEN_SHIFT 7 +#define MAX77705_MAINCTRL1_BIASEN_MASK BIT(MAX77705_MAINCTRL1_BIASEN_SHIFT) +// MAX77705_PMIC_REG_MCONFIG2 (haptics) register +#define MAX77705_CONFIG2_MEN_SHIFT 6 +#define MAX77705_CONFIG2_MODE_SHIFT 7 +#define MAX77705_CONFIG2_HTYP_SHIFT 5 +// MAX77705_PMIC_REG_SYSTEM_INT_MASK register +#define MAX77705_SYSTEM_IRQ_BSTEN_INT BIT(3) +#define MAX77705_SYSTEM_IRQ_SYSUVLO_INT BIT(4) +#define MAX77705_SYSTEM_IRQ_SYSOVLO_INT BIT(5) +#define MAX77705_SYSTEM_IRQ_TSHDN_INT BIT(6) +#define MAX77705_SYSTEM_IRQ_TM_INT BIT(7) + +enum max77705_hw_rev { + MAX77705_PASS1 =3D 1, + MAX77705_PASS2, + MAX77705_PASS3, +}; + +enum max77705_reg { + MAX77705_PMIC_REG_PMICID1 =3D 0x00, + MAX77705_PMIC_REG_PMICREV =3D 0x01, + MAX77705_PMIC_REG_MAINCTRL1 =3D 0x02, + MAX77705_PMIC_REG_BSTOUT_MASK =3D 0x03, + MAX77705_PMIC_REG_FORCE_EN_MASK =3D 0x08, + MAX77705_PMIC_REG_MCONFIG =3D 0x10, + MAX77705_PMIC_REG_MCONFIG2 =3D 0x11, + MAX77705_PMIC_REG_INTSRC =3D 0x22, + MAX77705_PMIC_REG_INTSRC_MASK =3D 0x23, + MAX77705_PMIC_REG_SYSTEM_INT =3D 0x24, + MAX77705_PMIC_REG_RESERVED_25 =3D 0x25, + MAX77705_PMIC_REG_SYSTEM_INT_MASK =3D 0x26, + MAX77705_PMIC_REG_RESERVED_27 =3D 0x27, + MAX77705_PMIC_REG_RESERVED_28 =3D 0x28, + MAX77705_PMIC_REG_RESERVED_29 =3D 0x29, + MAX77705_PMIC_REG_BOOSTCONTROL1 =3D 0x4C, + MAX77705_PMIC_REG_BOOSTCONTROL2 =3D 0x4F, + MAX77705_PMIC_REG_SW_RESET =3D 0x50, + MAX77705_PMIC_REG_USBC_RESET =3D 0x51, + + MAX77705_PMIC_REG_END, +}; + +enum max77705_chg_reg { + MAX77705_CHG_REG_BASE =3D 0xB0, + MAX77705_CHG_REG_INT =3D 0, + MAX77705_CHG_REG_INT_MASK, + MAX77705_CHG_REG_INT_OK, + MAX77705_CHG_REG_DETAILS_00, + MAX77705_CHG_REG_DETAILS_01, + MAX77705_CHG_REG_DETAILS_02, + MAX77705_CHG_REG_DTLS_03, + MAX77705_CHG_REG_CNFG_00, + MAX77705_CHG_REG_CNFG_01, + MAX77705_CHG_REG_CNFG_02, + MAX77705_CHG_REG_CNFG_03, + MAX77705_CHG_REG_CNFG_04, + MAX77705_CHG_REG_CNFG_05, + MAX77705_CHG_REG_CNFG_06, + MAX77705_CHG_REG_CNFG_07, + MAX77705_CHG_REG_CNFG_08, + MAX77705_CHG_REG_CNFG_09, + MAX77705_CHG_REG_CNFG_10, + MAX77705_CHG_REG_CNFG_11, + MAX77705_CHG_REG_CNFG_12, + MAX77705_CHG_REG_CNFG_13, + MAX77705_CHG_REG_CNFG_14, + MAX77705_CHG_REG_SAFEOUT_CTRL, +}; + +enum max77705_fuelgauge_reg { + STATUS_REG =3D 0x00, + VALRT_THRESHOLD_REG =3D 0x01, + TALRT_THRESHOLD_REG =3D 0x02, + SALRT_THRESHOLD_REG =3D 0x03, + REMCAP_REP_REG =3D 0x05, + SOCREP_REG =3D 0x06, + TEMPERATURE_REG =3D 0x08, + VCELL_REG =3D 0x09, + TIME_TO_EMPTY_REG =3D 0x11, + FULLSOCTHR_REG =3D 0x13, + CURRENT_REG =3D 0x0A, + AVG_CURRENT_REG =3D 0x0B, + SOCMIX_REG =3D 0x0D, + SOCAV_REG =3D 0x0E, + REMCAP_MIX_REG =3D 0x0F, + FULLCAP_REG =3D 0x10, + RFAST_REG =3D 0x15, + AVR_TEMPERATURE_REG =3D 0x16, + CYCLES_REG =3D 0x17, + DESIGNCAP_REG =3D 0x18, + AVR_VCELL_REG =3D 0x19, + TIME_TO_FULL_REG =3D 0x20, + CONFIG_REG =3D 0x1D, + ICHGTERM_REG =3D 0x1E, + REMCAP_AV_REG =3D 0x1F, + FULLCAP_NOM_REG =3D 0x23, + LEARN_CFG_REG =3D 0x28, + FILTER_CFG_REG =3D 0x29, + MISCCFG_REG =3D 0x2B, + QRTABLE20_REG =3D 0x32, + FULLCAP_REP_REG =3D 0x35, + RCOMP_REG =3D 0x38, + VEMPTY_REG =3D 0x3A, + FSTAT_REG =3D 0x3D, + DISCHARGE_THRESHOLD_REG =3D 0x40, + QRTABLE30_REG =3D 0x42, + ISYS_REG =3D 0x43, + DQACC_REG =3D 0x45, + DPACC_REG =3D 0x46, + AVGISYS_REG =3D 0x4B, + QH_REG =3D 0x4D, + VSYS_REG =3D 0xB1, + TALRTTH2_REG =3D 0xB2, + VBYP_REG =3D 0xB3, + CONFIG2_REG =3D 0xBB, + IIN_REG =3D 0xD0, + OCV_REG =3D 0xEE, + VFOCV_REG =3D 0xFB, + VFSOC_REG =3D 0xFF, + + MAX77705_FG_END, +}; + +enum max77705_led_reg { + MAX77705_RGBLED_REG_BASE =3D 0x30, + MAX77705_RGBLED_REG_LEDEN =3D 0, + MAX77705_RGBLED_REG_LED0BRT, + MAX77705_RGBLED_REG_LED1BRT, + MAX77705_RGBLED_REG_LED2BRT, + MAX77705_RGBLED_REG_LED3BRT, + MAX77705_RGBLED_REG_LEDRMP, + MAX77705_RGBLED_REG_LEDBLNK, + MAX77705_LED_REG_END +}; + +enum max77705_charger_battery_state { + MAX77705_BATTERY_NOBAT, + MAX77705_BATTERY_PREQUALIFICATION, + MAX77705_BATTERY_DEAD, + MAX77705_BATTERY_GOOD, + MAX77705_BATTERY_LOWVOLTAGE, + MAX77705_BATTERY_OVERVOLTAGE, + MAX77705_BATTERY_RESERVED, +}; + +enum max77705_charger_charge_type { + MAX77705_CHARGER_CONSTANT_CURRENT =3D 1, + MAX77705_CHARGER_CONSTANT_VOLTAGE, + MAX77705_CHARGER_END_OF_CHARGE, + MAX77705_CHARGER_DONE, +}; + +extern const struct dev_pm_ops max77705_pm_ops; + +#endif /* __LINUX_MFD_MAX77705_PRIV_H */ --=20 2.39.2 From nobody Mon Nov 25 23:18:43 2024 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-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: <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 =20 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. =20 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) +=3D kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) +=3D m68kspkr.o obj-$(CONFIG_INPUT_MAX77650_ONKEY) +=3D max77650-onkey.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC) +=3D max77693-haptic.o +obj-$(CONFIG_INPUT_MAX77705_HAPTIC) +=3D max77705-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) +=3D max8925_onkey.o obj-$(CONFIG_INPUT_MAX8997_HAPTIC) +=3D max8997_haptic.o obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) +=3D mc13783-pwrbutton.o diff --git a/drivers/input/misc/max77693-haptic.c b/drivers/input/misc/max7= 7693-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 =20 #define MAX_MAGNITUDE_SHIFT 16 @@ -115,6 +116,13 @@ static int max77693_haptic_configure(struct max77693_h= aptic *haptic, MAX77693_HAPTIC_PWM_DIVISOR_128); config_reg =3D MAX77693_HAPTIC_REG_CONFIG2; break; + case TYPE_MAX77705: + value =3D ((haptic->type << MAX77693_CONFIG2_MODE) | + (enable << MAX77693_CONFIG2_MEN) | + (haptic->mode << MAX77693_CONFIG2_HTYP) | + MAX77693_HAPTIC_PWM_DIVISOR_128); + config_reg =3D MAX77705_PMIC_REG_MCONFIG; + break; case TYPE_MAX77843: value =3D (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 =3D max77693->regmap_haptic; break; + case TYPE_MAX77705: + haptic->regmap_haptic =3D max77693->regmap; + break; case TYPE_MAX77843: haptic->regmap_haptic =3D max77693->regmap; break; @@ -407,6 +418,7 @@ static DEFINE_SIMPLE_DEV_PM_OPS(max77693_haptic_pm_ops, =20 static const struct platform_device_id max77693_haptic_id[] =3D { { "max77693-haptic", }, + { "max77705-haptic", }, { "max77843-haptic", }, {}, }; @@ -414,6 +426,7 @@ MODULE_DEVICE_TABLE(platform, max77693_haptic_id); =20 static const struct of_device_id of_max77693_haptic_dt_match[] =3D { { .compatible =3D "maxim,max77693-haptic", }, + { .compatible =3D "maxim,max77705-haptic", }, { .compatible =3D "maxim,max77843-haptic", }, { /* sentinel */ }, }; @@ -432,5 +445,5 @@ module_platform_driver(max77693_haptic_driver); =20 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"); --=20 2.39.2 From nobody Mon Nov 25 23:18:43 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 C7ADE1DDA30; Wed, 23 Oct 2024 19:43:10 +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=1729712593; cv=none; b=Wgn5sskO2+rXSDrN30HwevbajGo+fOMrNs2kU5VhZakdqJD71Rh6sz2/pxmY0gF0PmZHgtL5IBy8NUZlF8VcDZvjTQq4exLV+J36Drv29hl9oiDA+zY/xxvDUGDIVUibuEEL6ARJUp9/g2zQ64TeWs7WtPmzo0Q+2xc0W72+Zsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729712593; c=relaxed/simple; bh=Yz8/XJmtJxDMf13+0rsX/EYIpcdRO3WuMOHDT4e26wk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aTBkl1j6r+la1WAdPx39youTrRCQkHOlCLOsaGtog7x+RHS1gPzzUJOm2i8mtBaP4hrNFX5pexqHycOJKrYmrXkjbtDqAQMH6MLeS+zvdVKrqE6Oc1wdjJGTFo41feDuRi2w+sKScwvbjtzQ5WL0U2PeeISTkaS9tOm58cQZB6w= 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=UmXkRJQ0; arc=none smtp.client-ip=209.85.221.52 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="UmXkRJQ0" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-37ed7eb07a4so54735f8f.2; Wed, 23 Oct 2024 12:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729712589; x=1730317389; 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=lVAM6SBl2qMXbH8xamCQr228mr/Ui43qe/ck+NVTqPI=; b=UmXkRJQ0ZonzVQWJIEsVqg7rI4NzMzcjBnLgoT/4DelVP5DyVAqyyE63g7JCCrfsJ5 eWlr3/+Mzia4uj1ky7nxOvD4EqxCkzsdBJ7V6DM2PZwwzjX+Ye5RuT0pW5sLafdUoxjx B6IIwPR8reSzTZivo5cVLqi8Ulh+Cwc3PzqxJtvdUfUyI8bSPHziypauYej+LeQZMKg0 0235r03tVORXb3DR8661mF101gRlJ06s/zztqMoYX7anz6bEDs0uNpFl/OIYgrRDzKKR nzWYWy9oBPrQXG2xBCSbIDMOK5b677a2JyCsbs+pP3j8oTlJ7eCvwfh2Ld4pLQ0oqlb8 rdLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729712589; x=1730317389; 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=lVAM6SBl2qMXbH8xamCQr228mr/Ui43qe/ck+NVTqPI=; b=EUg3Re4BMTRUMxhEBNr/KA/sL4062lLg0qkXFiAR1ZGSwuoo9uAvmBV1jPOyWwRI1o AfTRtoRf9NQI1SO7aH+cwzwWmbeZfVcwquHAml2TRjrVRauGvYhJNmvlQpj4vpUWXdNc HKemx7Y0GLfqpgFRtr+I4Jep69H+lU6wBWJoF5Dt/7pdGjcmebcIQrykYD20wezcGQQY pz7JvpoL6vrRNWNN6VUYAzMF1GJrvbiOgB1jvU3z9YG625ljTTLoTlNTg6ANA2Lil67V ewTLZWGwaAd2iUG7JhlakjcSotix8n+W5BIpjmuVnn9KMNNXaR/nmS5YwaAoDlQW4o5U afxA== X-Forwarded-Encrypted: i=1; AJvYcCVzlvAwKwbRPDDVE8LeZaB62d9AGRuI4B0q75O6JL1g6z96xreJV1svULSp3c8kwgV04cbpDL8cqLL4@vger.kernel.org, AJvYcCXiZTBLNO423c/VGrhHR6ixzwsFDTFNYa6NuBxCEHEGk6ChoQaeNlUcmAbvWcrQ0w65Wacn/c2xY12LJA==@vger.kernel.org, AJvYcCXjx04s5NkaKI1pNERRQN/dS4WFwNXMhNpkFMTKp3ALFXFE5TBTYbdfNRnQSq7yALBNgVLN48bKggiQN0k=@vger.kernel.org, AJvYcCXujuOdGoQvDcv75QBJK9PanzlXtx19lt+dO9lej6dne/Mc5YawZa5WBHiK7Zx3o1Ewq15AuJ6HcJRi2WUN@vger.kernel.org X-Gm-Message-State: AOJu0YwQBlWegda+nFY7Kz8FsIj32KjDUEynu/WV66iWsThy7OIaE2WB RCXOHYsmtFfaAguCw8ilviseSYDAIgqRLvnS6NJJn/2Dj7pYU0aUFzX3bA== X-Google-Smtp-Source: AGHT+IGOQDjpqCBaDlxHdFhCWu3l34ugG4FgXkMo3HAAgofUCC7/R8r+XeZ12tegzTMgoJrRA7lN3g== X-Received: by 2002:adf:ea47:0:b0:377:683f:617c with SMTP id ffacd0b85a97d-37efcf0b7afmr2694776f8f.23.1729712588505; Wed, 23 Oct 2024 12:43:08 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 12:43:08 -0700 (PDT) From: Dzmitry Sankouski Date: Wed, 23 Oct 2024 22:42:53 +0300 Subject: [PATCH v7 5/7] power: supply: max77705: Add charger driver for Maxim 77705 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: <20241023-starqltechn_integration_upstream-v7-5-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=27794; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=Yz8/XJmtJxDMf13+0rsX/EYIpcdRO3WuMOHDT4e26wk=; b=Zgc49JibfzZrOMI550LF3BYOGTP5j68AX9jy/W7yBjfjoevweHqYI19C5VbGvs8T9irSEHf7y lqMzaShR2SlDXpaYNCKr5OjZY7vwsmyial+O5Y9O0xCPdXq9JR5+mUe X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Add driver for Maxim 77705 switch-mode charger (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 v6: - add i2c init in driver - replace remove_new back on remove - handle IS_ERR(i2c_chg) Changes for v5: - remove const modifier from max77705_charger_irq_chip because it's modified with irq_drv_data in probe function - fix license to GPL 2.0 only, where old vendor code used GPL 2.0 only - move power header to power include dir - use same hardware name in Kconfig and module descriptions Changes for v4: - start from scratch - change word delimiters in filenames to '_' - use GENMASK in header - remove debugfs code - migrate to regmap_add_irq_chip - fix property getters to follow the same style --- drivers/power/supply/Kconfig | 6 ++ drivers/power/supply/Makefile | 1 + drivers/power/supply/max77705_charger.c | 602 ++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++ include/linux/power/max77705_charger.h | 215 ++++++++++++++++++++++++++++= ++++++++++++++++++++++ 4 files changed, 824 insertions(+) diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index 9f2eef6787f7..66264036b65d 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -583,6 +583,12 @@ config CHARGER_MAX77693 help Say Y to enable support for the Maxim MAX77693 battery charger. =20 +config CHARGER_MAX77705 + tristate "Maxim MAX77705 battery charger driver" + depends on MFD_MAX77705 + help + Say Y to enable support for the Maxim MAX77705 battery charger. + 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 59c4a9f40d28..85d65b7aee1c 100644 --- a/drivers/power/supply/Makefile +++ b/drivers/power/supply/Makefile @@ -80,6 +80,7 @@ obj-$(CONFIG_CHARGER_MAX14577) +=3D max14577_charger.o obj-$(CONFIG_CHARGER_DETECTOR_MAX14656) +=3D max14656_charger_detector.o obj-$(CONFIG_CHARGER_MAX77650) +=3D max77650-charger.o obj-$(CONFIG_CHARGER_MAX77693) +=3D max77693_charger.o +obj-$(CONFIG_CHARGER_MAX77705) +=3D max77705_charger.o obj-$(CONFIG_CHARGER_MAX77976) +=3D max77976_charger.o obj-$(CONFIG_CHARGER_MAX8997) +=3D max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) +=3D max8998_charger.o diff --git a/drivers/power/supply/max77705_charger.c b/drivers/power/supply= /max77705_charger.c new file mode 100644 index 000000000000..cf52cc06f367 --- /dev/null +++ b/drivers/power/supply/max77705_charger.c @@ -0,0 +1,602 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Based on max77650-charger.c: +// Copyright (C) 2018 BayLibre SAS +// Author: Bartosz Golaszewski +// +// Copyright (C) 2024 Dzmitry Sankouski +// +// Battery charger driver for MAXIM 77705 charger/power-supply. + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define I2C_ADDR_CHG 0x69 + +static const char *max77705_charger_model =3D "max77705"; +static const char *max77705_charger_manufacturer =3D "Maxim Integrated"; + +static const struct regmap_config max77705_chg_regmap_config =3D { + .reg_base =3D MAX77705_CHG_REG_BASE, + .reg_bits =3D 8, + .val_bits =3D 8, + .max_register =3D MAX77705_CHG_REG_SAFEOUT_CTRL, +}; + +static enum power_supply_property max77705_charger_props[] =3D { + POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_CHARGE_TYPE, + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, +}; + +static int max77705_chgin_irq(void *irq_drv_data) +{ + struct max77705_charger_data *charger =3D irq_drv_data; + + queue_work(charger->wqueue, &charger->chgin_work); + + return 0; +} + +static const struct regmap_irq max77705_charger_irqs[] =3D { + { .mask =3D MAX77705_BYP_IM, }, + { .mask =3D MAX77705_INP_LIMIT_IM, }, + { .mask =3D MAX77705_BATP_IM, }, + { .mask =3D MAX77705_BAT_IM, }, + { .mask =3D MAX77705_CHG_IM, }, + { .mask =3D MAX77705_WCIN_IM, }, + { .mask =3D MAX77705_CHGIN_IM, }, + { .mask =3D MAX77705_AICL_IM, }, +}; + +static struct regmap_irq_chip max77705_charger_irq_chip =3D { + .name =3D "max77705-charger", + .status_base =3D MAX77705_CHG_REG_INT, + .mask_base =3D MAX77705_CHG_REG_INT_MASK, + .handle_post_irq =3D max77705_chgin_irq, + .num_regs =3D 1, + .irqs =3D max77705_charger_irqs, + .num_irqs =3D ARRAY_SIZE(max77705_charger_irqs), +}; + +static int max77705_charger_enable(struct max77705_charger_data *chg) +{ + int rv; + + rv =3D regmap_update_bits(chg->regmap, MAX77705_CHG_REG_CNFG_09, + MAX77705_CHG_EN_MASK, MAX77705_CHG_EN_MASK); + if (rv) + dev_err(chg->dev, "unable to enable the charger: %d\n", rv); + + return rv; +} + +static void max77705_charger_disable(struct max77705_charger_data *chg) +{ + int rv; + + rv =3D regmap_update_bits(chg->regmap, + MAX77705_CHG_REG_CNFG_09, + MAX77705_CHG_EN_MASK, + MAX77705_CHG_DISABLE); + if (rv) + dev_err(chg->dev, "unable to disable the charger: %d\n", rv); +} + +static int max77705_get_online(struct regmap *regmap, int *val) +{ + unsigned int data; + int ret; + + ret =3D regmap_read(regmap, MAX77705_CHG_REG_INT_OK, &data); + if (ret < 0) + return ret; + + *val =3D !!(data & MAX77705_CHGIN_OK); + + return 0; +} + +static int max77705_check_battery(struct max77705_charger_data *charger, i= nt *val) +{ + unsigned int reg_data; + unsigned int reg_data2; + struct regmap *regmap =3D charger->regmap; + + + regmap_read(regmap, MAX77705_CHG_REG_INT_OK, ®_data); + + dev_dbg(charger->dev, "CHG_INT_OK(0x%x)\n", reg_data); + + regmap_read(regmap, + MAX77705_CHG_REG_DETAILS_00, ®_data2); + + dev_dbg(charger->dev, "CHG_DETAILS00(0x%x)\n", reg_data2); + + if ((reg_data & MAX77705_BATP_OK) || !(reg_data2 & MAX77705_BATP_DTLS)) + *val =3D true; + else + *val =3D false; + + return 0; +} + +static int max77705_get_charge_type(struct max77705_charger_data *charger,= int *val) +{ + struct regmap *regmap =3D charger->regmap; + unsigned int reg_data; + + regmap_read(regmap, MAX77705_CHG_REG_CNFG_09, ®_data); + if (!MAX77705_CHARGER_CHG_CHARGING(reg_data)) { + *val =3D POWER_SUPPLY_CHARGE_TYPE_NONE; + return 0; + } + + regmap_read(regmap, MAX77705_CHG_REG_DETAILS_01, ®_data); + reg_data &=3D MAX77705_CHG_DTLS; + + switch (reg_data) { + case 0x0: + case MAX77705_CHARGER_CONSTANT_CURRENT: + case MAX77705_CHARGER_CONSTANT_VOLTAGE: + *val =3D POWER_SUPPLY_CHARGE_TYPE_FAST; + return 0; + default: + *val =3D POWER_SUPPLY_CHARGE_TYPE_NONE; + return 0; + } + + return 0; +} + +static int max77705_get_status(struct max77705_charger_data *charger, int = *val) +{ + struct regmap *regmap =3D charger->regmap; + unsigned int reg_data; + + regmap_read(regmap, MAX77705_CHG_REG_CNFG_09, ®_data); + if (!MAX77705_CHARGER_CHG_CHARGING(reg_data)) { + *val =3D POWER_SUPPLY_CHARGE_TYPE_NONE; + return 0; + } + + regmap_read(regmap, MAX77705_CHG_REG_DETAILS_01, ®_data); + reg_data &=3D MAX77705_CHG_DTLS; + + switch (reg_data) { + case 0x0: + case MAX77705_CHARGER_CONSTANT_CURRENT: + case MAX77705_CHARGER_CONSTANT_VOLTAGE: + *val =3D POWER_SUPPLY_STATUS_CHARGING; + return 0; + case MAX77705_CHARGER_END_OF_CHARGE: + case MAX77705_CHARGER_DONE: + *val =3D POWER_SUPPLY_STATUS_FULL; + return 0; + // those values hard coded as in vendor kernel, because of + // failure to determine it's actual meaning. + case 0x05: + case 0x06: + case 0x07: + *val =3D POWER_SUPPLY_STATUS_NOT_CHARGING; + return 0; + case 0x08: + case 0xA: + case 0xB: + *val =3D POWER_SUPPLY_STATUS_DISCHARGING; + return 0; + default: + *val =3D POWER_SUPPLY_STATUS_UNKNOWN; + return 0; + } + + return 0; +} + +static int max77705_get_vbus_state(struct regmap *regmap, int *value) +{ + int ret; + unsigned int charge_dtls; + + ret =3D regmap_read(regmap, MAX77705_CHG_REG_DETAILS_00, &charge_dtls); + if (ret) + return ret; + + charge_dtls =3D ((charge_dtls & MAX77705_CHGIN_DTLS) >> + MAX77705_CHGIN_DTLS_SHIFT); + + switch (charge_dtls) { + case 0x00: + *value =3D POWER_SUPPLY_HEALTH_UNDERVOLTAGE; + break; + case 0x01: + *value =3D POWER_SUPPLY_HEALTH_UNDERVOLTAGE; + break; + case 0x02: + *value =3D POWER_SUPPLY_HEALTH_OVERVOLTAGE; + break; + case 0x03: + *value =3D POWER_SUPPLY_HEALTH_GOOD; + break; + default: + return 0; + } + return 0; +} + +static int max77705_get_battery_health(struct max77705_charger_data *charg= er, + int *value) +{ + struct regmap *regmap =3D charger->regmap; + unsigned int bat_dtls; + + regmap_read(regmap, MAX77705_CHG_REG_DETAILS_01, &bat_dtls); + bat_dtls =3D ((bat_dtls & MAX77705_BAT_DTLS) >> MAX77705_BAT_DTLS_SHIFT); + + switch (bat_dtls) { + case MAX77705_BATTERY_NOBAT: + dev_dbg(charger->dev, "%s: No battery and the charger is suspended\n", + __func__); + *value =3D POWER_SUPPLY_HEALTH_NO_BATTERY; + break; + case MAX77705_BATTERY_PREQUALIFICATION: + dev_dbg(charger->dev, "%s: battery is okay but its voltage is low(~VPQLB= )\n", + __func__); + break; + case MAX77705_BATTERY_DEAD: + dev_dbg(charger->dev, "%s: battery dead\n", __func__); + *value =3D POWER_SUPPLY_HEALTH_DEAD; + break; + case MAX77705_BATTERY_GOOD: + case MAX77705_BATTERY_LOWVOLTAGE: + *value =3D POWER_SUPPLY_HEALTH_GOOD; + break; + case MAX77705_BATTERY_OVERVOLTAGE: + dev_dbg(charger->dev, "%s: battery ovp\n", __func__); + *value =3D POWER_SUPPLY_HEALTH_OVERVOLTAGE; + break; + default: + dev_dbg(charger->dev, "%s: battery unknown\n", __func__); + *value =3D POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; + break; + } + + return 0; +} + +static int max77705_get_health(struct max77705_charger_data *charger, int = *val) +{ + struct regmap *regmap =3D charger->regmap; + int ret, is_online =3D 0; + + ret =3D max77705_get_online(regmap, &is_online); + if (ret) + return ret; + if (is_online) { + ret =3D max77705_get_vbus_state(regmap, val); + if (ret || (*val !=3D POWER_SUPPLY_HEALTH_GOOD)) + return ret; + } + return max77705_get_battery_health(charger, val); +} + +static int max77705_get_input_current(struct max77705_charger_data *charge= r, + int *val) +{ + unsigned int reg_data; + int get_current =3D 0; + struct regmap *regmap =3D charger->regmap; + + regmap_read(regmap, + MAX77705_CHG_REG_CNFG_09, ®_data); + + reg_data &=3D MAX77705_CHG_CHGIN_LIM_MASK; + + if (reg_data <=3D 3) + get_current =3D 100; + else if (reg_data >=3D MAX77705_CHG_CHGIN_LIM_MASK) + get_current =3D MAX77705_CURRENT_CHGIN_MAX; + else + get_current =3D (reg_data + 1) * 25; + + *val =3D get_current; + + return 0; +} + +static int max77705_get_charge_current(struct max77705_charger_data *charg= er, + int *val) +{ + unsigned int reg_data; + struct regmap *regmap =3D charger->regmap; + + + regmap_read(regmap, MAX77705_CHG_REG_CNFG_02, ®_data); + reg_data &=3D MAX77705_CHG_CC; + + *val =3D reg_data <=3D 0x2 ? 100 : reg_data * 50; + + return 0; +} + +static int max77705_set_float_voltage(struct max77705_charger_data *charge= r, + int float_voltage) +{ + int float_voltage_mv; + unsigned int reg_data =3D 0; + struct regmap *regmap =3D charger->regmap; + + float_voltage_mv =3D float_voltage / 1000; + reg_data =3D float_voltage_mv <=3D 4000 ? 0x0 : + float_voltage_mv >=3D 4500 ? 0x23 : + (float_voltage_mv <=3D 4200) ? (float_voltage_mv - 4000) / 50 : + (((float_voltage_mv - 4200) / 10) + 0x04); + + return regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_04, + MAX77705_CHG_CV_PRM_MASK, + (reg_data << MAX77705_CHG_CV_PRM_SHIFT)); +} + +static int max77705_get_float_voltage(struct max77705_charger_data *charge= r, + int *val) +{ + unsigned int reg_data =3D 0; + struct regmap *regmap =3D charger->regmap; + + regmap_read(regmap, MAX77705_CHG_REG_CNFG_04, ®_data); + reg_data &=3D MAX77705_CHG_PRM_MASK; + *val =3D reg_data <=3D 0x04 ? reg_data * 50 + 4000 : + (reg_data - 4) * 10 + 4200; + + return 0; +} + +static int max77705_chg_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct max77705_charger_data *charger =3D power_supply_get_drvdata(psy); + struct regmap *regmap =3D charger->regmap; + + switch (psp) { + case POWER_SUPPLY_PROP_ONLINE: + return max77705_get_online(regmap, &val->intval); + case POWER_SUPPLY_PROP_PRESENT: + return max77705_check_battery(charger, &val->intval); + case POWER_SUPPLY_PROP_STATUS: + return max77705_get_status(charger, &val->intval); + case POWER_SUPPLY_PROP_CHARGE_TYPE: + return max77705_get_charge_type(charger, &val->intval); + case POWER_SUPPLY_PROP_HEALTH: + return max77705_get_health(charger, &val->intval); + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + return max77705_get_input_current(charger, &val->intval); + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: + return max77705_get_charge_current(charger, &val->intval); + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: + return max77705_get_float_voltage(charger, &val->intval); + case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: + val->intval =3D charger->bat_info->voltage_max_design_uv; + break; + case POWER_SUPPLY_PROP_MODEL_NAME: + val->strval =3D max77705_charger_model; + break; + case POWER_SUPPLY_PROP_MANUFACTURER: + val->strval =3D max77705_charger_manufacturer; + break; + default: + return -EINVAL; + } + return 0; +} + +static const struct power_supply_desc max77705_charger_psy_desc =3D { + .name =3D "max77705-charger", + .type =3D POWER_SUPPLY_TYPE_USB, + .properties =3D max77705_charger_props, + .num_properties =3D ARRAY_SIZE(max77705_charger_props), + .get_property =3D max77705_chg_get_property, +}; + +static void max77705_chgin_isr_work(struct work_struct *work) +{ + struct max77705_charger_data *charger =3D + container_of(work, struct max77705_charger_data, chgin_work); + power_supply_changed(charger->psy_chg); +} + +static void max77705_charger_initialize(struct max77705_charger_data *chg) +{ + u8 reg_data; + struct power_supply_battery_info *info; + struct regmap *regmap =3D chg->regmap; + + if (power_supply_get_battery_info(chg->psy_chg, &info) < 0) + return; + + chg->bat_info =3D info; + + // unlock charger setting protect + // slowest LX slope + reg_data =3D MAX77705_CHGPROT_MASK | MAX77705_SLOWEST_LX_SLOPE; + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_06, reg_data, + reg_data); + + // fast charge timer disable + // restart threshold disable + // pre-qual charge disable + reg_data =3D (MAX77705_FCHGTIME_DISABLE << MAX77705_FCHGTIME_SHIFT) | + (MAX77705_CHG_RSTRT_DISABLE << MAX77705_CHG_RSTRT_SHIFT) | + (MAX77705_CHG_PQEN_DISABLE << MAX77705_PQEN_SHIFT); + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_01, + (MAX77705_FCHGTIME_MASK | + MAX77705_CHG_RSTRT_MASK | + MAX77705_PQEN_MASK), + reg_data); + + // OTG off(UNO on), boost off + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_00, + MAX77705_OTG_CTRL, 0); + + // charge current 450mA(default) + // otg current limit 900mA + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_02, + MAX77705_OTG_ILIM_MASK, + MAX77705_OTG_ILIM_900 << MAX77705_OTG_ILIM_SHIFT); + + // BAT to SYS OCP 4.80A + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_05, + MAX77705_REG_B2SOVRC_MASK, + MAX77705_B2SOVRC_4_8A << MAX77705_REG_B2SOVRC_SHIFT); + // top off current 150mA + // top off timer 30min + reg_data =3D (MAX77705_TO_ITH_150MA << MAX77705_TO_ITH_SHIFT) | + (MAX77705_TO_TIME_30M << MAX77705_TO_TIME_SHIFT) | + (MAX77705_SYS_TRACK_DISABLE << MAX77705_SYS_TRACK_DIS_SHIFT); + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_03, + (MAX77705_TO_ITH_MASK | + MAX77705_TO_TIME_MASK | + MAX77705_SYS_TRACK_DIS_MASK), reg_data); + + // cv voltage 4.2V or 4.35V + // MINVSYS 3.6V(default) + if (info->voltage_max_design_uv < 0) { + dev_warn(chg->dev, "missing battery:voltage-max-design-microvolt\n"); + max77705_set_float_voltage(chg, 4200000); + } else { + max77705_set_float_voltage(chg, info->voltage_max_design_uv); + } + + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_12, + MAX77705_VCHGIN_REG_MASK, MAX77705_VCHGIN_4_5); + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_12, + MAX77705_WCIN_REG_MASK, MAX77705_WCIN_4_5); + + // Watchdog timer + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_00, + MAX77705_WDTEN_MASK, 0); + + // Active Discharge Enable + regmap_update_bits(regmap, MAX77705_PMIC_REG_MAINCTRL1, 1, 1); + + // VBYPSET=3D5.0V + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_11, MAX77705_VBYPSET_MAS= K, 0); + + // Switching Frequency : 1.5MHz + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_08, MAX77705_REG_FSW_MAS= K, + (MAX77705_CHG_FSW_1_5MHz << MAX77705_REG_FSW_SHIFT)); + + // Auto skip mode + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_12, MAX77705_REG_DISKIP_= MASK, + (MAX77705_AUTO_SKIP << MAX77705_REG_DISKIP_SHIFT)); +} + +static int max77705_charger_probe(struct platform_device *pdev) +{ + struct power_supply_config pscfg =3D {}; + struct i2c_client *i2c_chg; + struct max77693_dev *max77705; + struct max77705_charger_data *chg; + struct device *dev, *parent; + struct regmap_irq_chip_data *irq_data; + int ret; + + dev =3D &pdev->dev; + parent =3D dev->parent; + max77705 =3D dev_get_drvdata(parent); + + chg =3D devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL); + if (!chg) + return -ENOMEM; + + platform_set_drvdata(pdev, chg); + + i2c_chg =3D devm_i2c_new_dummy_device(max77705->dev, + max77705->i2c->adapter, I2C_ADDR_CHG); + + if (IS_ERR(i2c_chg)) + return PTR_ERR(i2c_chg); + + chg->regmap =3D devm_regmap_init_i2c(i2c_chg, + &max77705_chg_regmap_config); + + if (IS_ERR(chg->regmap)) + return PTR_ERR(chg->regmap); + + chg->dev =3D dev; + max77705_charger_irq_chip.irq_drv_data =3D chg; + ret =3D devm_regmap_add_irq_chip(chg->dev, chg->regmap, max77705->irq, + IRQF_ONESHOT | IRQF_SHARED, 0, + &max77705_charger_irq_chip, + &irq_data); + if (ret) { + dev_err(dev, "failed to add irq chip: %d\n", ret); + return ret; + } + + ret =3D regmap_update_bits(chg->regmap, + MAX77705_CHG_REG_INT_MASK, + MAX77705_CHGIN_IM, 0); + + if (ret) + return ret; + + chg->wqueue =3D create_singlethread_workqueue(dev_name(dev)); + if (IS_ERR(chg->wqueue)) { + dev_err(dev, "failed to create workqueue\n"); + return PTR_ERR(chg->wqueue); + } + INIT_WORK(&chg->chgin_work, max77705_chgin_isr_work); + + pscfg.of_node =3D dev->of_node; + pscfg.drv_data =3D chg; + + chg->psy_chg =3D devm_power_supply_register(dev, &max77705_charger_psy_de= sc, + &pscfg); + if (IS_ERR(chg->psy_chg)) + return PTR_ERR(chg->psy_chg); + + max77705_charger_initialize(chg); + + return max77705_charger_enable(chg); +} + +static void max77705_charger_remove(struct platform_device *pdev) +{ + struct max77705_charger_data *chg =3D platform_get_drvdata(pdev); + + max77705_charger_disable(chg); +} + +static const struct of_device_id max77705_charger_of_match[] =3D { + { .compatible =3D "maxim,max77705-charger" }, + { } +}; +MODULE_DEVICE_TABLE(of, max77705_charger_of_match); + +static struct platform_driver max77705_charger_driver =3D { + .driver =3D { + .name =3D "max77705-charger", + .of_match_table =3D max77705_charger_of_match, + }, + .probe =3D max77705_charger_probe, + .remove =3D max77705_charger_remove, +}; +module_platform_driver(max77705_charger_driver); + +MODULE_AUTHOR("Dzmitry Sankouski "); +MODULE_DESCRIPTION("Maxim MAX77705 charger driver"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/power/max77705_charger.h b/include/linux/power/m= ax77705_charger.h new file mode 100644 index 000000000000..0abac9f91b2c --- /dev/null +++ b/include/linux/power/max77705_charger.h @@ -0,0 +1,215 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +// +// Maxim MAX77705 definitions. +// +// Copyright (C) 2015 Samsung Electronics, Inc. +// Copyright (C) 2024 Dzmitry Sankouski + +#ifndef __MAX77705_CHARGER_H +#define __MAX77705_CHARGER_H __FILE__ + +// MAX77705_CHG_REG_CHG_INT +#define MAX77705_BYP_I BIT(0) +#define MAX77705_INP_LIMIT_I BIT(1) +#define MAX77705_BATP_I BIT(2) +#define MAX77705_BAT_I BIT(3) +#define MAX77705_CHG_I BIT(4) +#define MAX77705_WCIN_I BIT(5) +#define MAX77705_CHGIN_I BIT(6) +#define MAX77705_AICL_I BIT(7) + +// MAX77705_CHG_REG_CHG_INT_MASK +#define MAX77705_BYP_IM BIT(0) +#define MAX77705_INP_LIMIT_IM BIT(1) +#define MAX77705_BATP_IM BIT(2) +#define MAX77705_BAT_IM BIT(3) +#define MAX77705_CHG_IM BIT(4) +#define MAX77705_WCIN_IM BIT(5) +#define MAX77705_CHGIN_IM BIT(6) +#define MAX77705_AICL_IM BIT(7) + +// MAX77705_CHG_REG_CHG_INT_OK +#define MAX77705_BYP_OK BIT(0) +#define MAX77705_DISQBAT_OK BIT(1) +#define MAX77705_BATP_OK BIT(2) +#define MAX77705_BAT_OK BIT(3) +#define MAX77705_CHG_OK BIT(4) +#define MAX77705_WCIN_OK BIT(5) +#define MAX77705_CHGIN_OK BIT(6) +#define MAX77705_AICL_OK BIT(7) + +// MAX77705_CHG_REG_DETAILS_00 +#define MAX77705_BATP_DTLS BIT(0) +#define MAX77705_WCIN_DTLS GENMASK(4, 3) +#define MAX77705_WCIN_DTLS_SHIFT 3 +#define MAX77705_CHGIN_DTLS GENMASK(6, 5) +#define MAX77705_CHGIN_DTLS_SHIFT 5 + +// MAX77705_CHG_REG_DETAILS_01 +#define MAX77705_CHG_DTLS GENMASK(3, 0) +#define MAX77705_CHG_DTLS_SHIFT 0 +#define MAX77705_BAT_DTLS GENMASK(6, 4) +#define MAX77705_BAT_DTLS_SHIFT 4 + +// MAX77705_CHG_REG_DETAILS_02 +#define MAX77705_BYP_DTLS GENMASK(3, 0) +#define MAX77705_BYP_DTLS_SHIFT 0 + +// MAX77705_CHG_REG_CNFG_00 +#define MAX77705_CHG_SHIFT 0 +#define MAX77705_UNO_SHIFT 1 +#define MAX77705_OTG_SHIFT 1 +#define MAX77705_BUCK_SHIFT 2 +#define MAX77705_BOOST_SHIFT 3 +#define MAX77705_WDTEN_SHIFT 4 +#define MAX77705_MODE_MASK GENMASK(3, 0) +#define MAX77705_CHG_MASK BIT(MAX77705_CHG_SHIFT) +#define MAX77705_UNO_MASK BIT(MAX77705_UNO_SHIFT) +#define MAX77705_OTG_MASK BIT(MAX77705_OTG_SHIFT) +#define MAX77705_BUCK_MASK BIT(MAX77705_BUCK_SHIFT) +#define MAX77705_BOOST_MASK BIT(MAX77705_BOOST_SHIFT) +#define MAX77705_WDTEN_MASK BIT(MAX77705_WDTEN_SHIFT) +#define MAX77705_UNO_CTRL (MAX77705_UNO_MASK | MAX77705_BOOST_MASK) +#define MAX77705_OTG_CTRL (MAX77705_OTG_MASK | MAX77705_BOOST_MASK) + +// MAX77705_CHG_REG_CNFG_01 +#define MAX77705_FCHGTIME_SHIFT 0 +#define MAX77705_FCHGTIME_MASK GENMASK(2, 0) +#define MAX77705_CHG_RSTRT_SHIFT 4 +#define MAX77705_CHG_RSTRT_MASK GENMASK(5, 4) +#define MAX77705_FCHGTIME_DISABLE 0 +#define MAX77705_CHG_RSTRT_DISABLE 0x3 + +#define MAX77705_PQEN_SHIFT 7 +#define MAX77705_PQEN_MASK BIT(7) +#define MAX77705_CHG_PQEN_DISABLE 0 +#define MAX77705_CHG_PQEN_ENABLE 1 + +// MAX77705_CHG_REG_CNFG_02 +#define MAX77705_OTG_ILIM_SHIFT 6 +#define MAX77705_OTG_ILIM_MASK GENMASK(7, 6) +#define MAX77705_OTG_ILIM_500 0 +#define MAX77705_OTG_ILIM_900 1 +#define MAX77705_OTG_ILIM_1200 2 +#define MAX77705_OTG_ILIM_1500 3 +#define MAX77705_CHG_CC GENMASK(5, 0) + +// MAX77705_CHG_REG_CNFG_03 +#define MAX77705_TO_ITH_SHIFT 0 +#define MAX77705_TO_ITH_MASK GENMASK(2, 0) +#define MAX77705_TO_TIME_SHIFT 3 +#define MAX77705_TO_TIME_MASK GENMASK(5, 3) +#define MAX77705_SYS_TRACK_DIS_SHIFT 7 +#define MAX77705_SYS_TRACK_DIS_MASK BIT(7) +#define MAX77705_TO_ITH_150MA 0 +#define MAX77705_TO_TIME_30M 3 +#define MAX77705_SYS_TRACK_ENABLE 0 +#define MAX77705_SYS_TRACK_DISABLE 1 + +// MAX77705_CHG_REG_CNFG_04 +#define MAX77705_CHG_MINVSYS_SHIFT 6 +#define MAX77705_CHG_MINVSYS_MASK GENMASK(7, 6) +#define MAX77705_CHG_PRM_SHIFT 0 +#define MAX77705_CHG_PRM_MASK GENMASK(5, 0) + +#define MAX77705_CHG_CV_PRM_SHIFT 0 +#define MAX77705_CHG_CV_PRM_MASK GENMASK(5, 0) + +// MAX77705_CHG_REG_CNFG_05 +#define MAX77705_REG_B2SOVRC_SHIFT 0 +#define MAX77705_REG_B2SOVRC_MASK GENMASK(3, 0) +#define MAX77705_B2SOVRC_DISABLE 0 +#define MAX77705_B2SOVRC_4_5A 6 +#define MAX77705_B2SOVRC_4_8A 8 +#define MAX77705_B2SOVRC_5_0A 9 + +// MAX77705_CHG_CNFG_06 +#define MAX77705_WDTCLR_SHIFT 0 +#define MAX77705_WDTCLR_MASK GENMASK(1, 0) +#define MAX77705_WDTCLR 1 +#define MAX77705_CHGPROT_MASK GENMASK(3, 2) +#define MAX77705_CHGPROT_UNLOCKED GENMASK(3, 2) +#define MAX77705_SLOWEST_LX_SLOPE GENMASK(6, 5) + +// MAX77705_CHG_REG_CNFG_07 +#define MAX77705_CHG_FMBST 4 +#define MAX77705_REG_FMBST_SHIFT 2 +#define MAX77705_REG_FMBST_MASK BIT(MAX77705_REG_FMBST_SHIFT) +#define MAX77705_REG_FGSRC_SHIFT 1 +#define MAX77705_REG_FGSRC_MASK BIT(MAX77705_REG_FGSRC_SHIFT) + +// MAX77705_CHG_REG_CNFG_08 +#define MAX77705_REG_FSW_SHIFT 0 +#define MAX77705_REG_FSW_MASK GENMASK(1, 0) +#define MAX77705_CHG_FSW_3MHz 0 +#define MAX77705_CHG_FSW_2MHz 1 +#define MAX77705_CHG_FSW_1_5MHz 2 + +// MAX77705_CHG_REG_CNFG_09 +#define MAX77705_CHG_CHGIN_LIM_MASK GENMASK(6, 0) +#define MAX77705_CHG_EN_MASK BIT(7) +#define MAX77705_CHG_DISABLE 0 +#define MAX77705_CHARGER_CHG_CHARGING(_reg) \ + (((_reg) & MAX77705_CHG_EN_MASK) > 1) + + +// MAX77705_CHG_REG_CNFG_10 +#define MAX77705_CHG_WCIN_LIM GENMASK(5, 0) + +// MAX77705_CHG_REG_CNFG_11 +#define MAX77705_VBYPSET_SHIFT 0 +#define MAX77705_VBYPSET_MASK GENMASK(6, 0) + +// MAX77705_CHG_REG_CNFG_12 +#define MAX77705_CHGINSEL_SHIFT 5 +#define MAX77705_CHGINSEL_MASK BIT(MAX77705_CHGINSEL_SHIFT) +#define MAX77705_WCINSEL_SHIFT 6 +#define MAX77705_WCINSEL_MASK BIT(MAX77705_WCINSEL_SHIFT) +#define MAX77705_VCHGIN_REG_MASK GENMASK(4, 3) +#define MAX77705_WCIN_REG_MASK GENMASK(2, 1) +#define MAX77705_REG_DISKIP_SHIFT 0 +#define MAX77705_REG_DISKIP_MASK BIT(MAX77705_REG_DISKIP_SHIFT) +// REG=3D4.5V, UVLO=3D4.7V +#define MAX77705_VCHGIN_4_5 0 +// REG=3D4.5V, UVLO=3D4.7V +#define MAX77705_WCIN_4_5 0 +#define MAX77705_DISABLE_SKIP 1 +#define MAX77705_AUTO_SKIP 0 + +// mA +#define MAX77705_CURRENT_STEP 25 +#define MAX77705_CURRENT_WCIN_MAX 1600 +#define MAX77705_CURRENT_CHGIN_MAX 3200 + +/* Convert current in mA to corresponding CNFG09 value */ +inline u8 max77705_convert_ma_to_chgin_ilim_value(unsigned int cur) +{ + if (cur < MAX77705_CURRENT_STEP) + return 0; + if (cur < MAX77705_CURRENT_CHGIN_MAX) + return (cur / MAX77705_CURRENT_STEP) - 1; + else + return (MAX77705_CURRENT_CHGIN_MAX / MAX77705_CURRENT_STEP) - 1; +} + +/* Convert current in mA to corresponding CNFG10 value */ +inline u8 max77705_convert_ma_to_wcin_ilim_value(unsigned int cur) +{ + if (cur < MAX77705_CURRENT_STEP) + return 0; + if (cur < MAX77705_CURRENT_WCIN_MAX) + return (cur / MAX77705_CURRENT_STEP) - 1; + else + return (MAX77705_CURRENT_WCIN_MAX / MAX77705_CURRENT_STEP) - 1; +} + +struct max77705_charger_data { + struct device *dev; + struct regmap *regmap; + struct power_supply_battery_info *bat_info; + struct workqueue_struct *wqueue; + struct work_struct chgin_work; + struct power_supply *psy_chg; +}; + +#endif // __MAX77705_CHARGER_H --=20 2.39.2 From nobody Mon Nov 25 23:18:43 2024 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-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: <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/20241011191= 3.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. =20 +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) +=3D max14656_cha= rger_detector.o obj-$(CONFIG_CHARGER_MAX77650) +=3D max77650-charger.o obj-$(CONFIG_CHARGER_MAX77693) +=3D max77693_charger.o obj-$(CONFIG_CHARGER_MAX77705) +=3D max77705_charger.o +obj-$(CONFIG_FUEL_GAUGE_MAX77705) +=3D max77705_fuel_gauge.o obj-$(CONFIG_CHARGER_MAX77976) +=3D max77976_charger.o obj-$(CONFIG_CHARGER_MAX8997) +=3D max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) +=3D max8998_charger.o diff --git a/drivers/power/supply/max77705_fuel_gauge.c b/drivers/power/sup= ply/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 =3D "max77705"; +static const char *max77705_fuelgauge_manufacturer =3D "Maxim Integrated"; + +static const struct regmap_config max77705_fg_regmap_config =3D { + .reg_bits =3D 8, + .val_bits =3D 8, + .max_register =3D MAX77705_FG_END, +}; + +static enum power_supply_property max77705_fuelgauge_props[] =3D { + 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 =3D fuelgauge->regmap; + u8 data[2]; + int ret; + + ret =3D regmap_noinc_read(regmap, reg, data, sizeof(data)); + if (ret < 0) + return ret; + + *val =3D (data[1] << 8) + data[0]; + + return 0; +} + +static int max77705_fg_read_temp(struct max77705_fuelgauge_data *fuelgauge, + int *val) +{ + struct regmap *regmap =3D fuelgauge->regmap; + u8 data[2] =3D { 0, 0 }; + int ret, temperature =3D 0; + + ret =3D regmap_noinc_read(regmap, TEMPERATURE_REG, data, sizeof(data)); + if (ret < 0) + return ret; + + if (data[1] & BIT(7)) + temperature =3D ((~(data[1])) & 0xFF) + 1; + else + temperature =3D data[1] & 0x7f; + + temperature *=3D 10; + temperature +=3D data[0] * 10 / 256; + *val =3D temperature; + + return 0; +} + +static int max77705_fg_check_battery_present(struct max77705_fuelgauge_data + *fuelgauge, int *val) +{ + struct regmap *regmap =3D fuelgauge->regmap; + u8 status_data[2]; + int ret; + + ret =3D regmap_noinc_read(regmap, STATUS_REG, status_data, sizeof(status_= data)); + if (ret < 0) + return ret; + + *val =3D !(status_data[0] & MAX77705_BAT_ABSENT_MASK); + + return 0; +} + +static int max77705_battery_get_status(struct max77705_fuelgauge_data *fue= lgauge, + int *val) +{ + int current_now; + int am_i_supplied; + int ret; + unsigned int soc_rep; + + am_i_supplied =3D power_supply_am_i_supplied(fuelgauge->psy_fg); + if (am_i_supplied) { + if (am_i_supplied =3D=3D -ENODEV) { + dev_err(fuelgauge->dev, + "power supply not found, fall back to current-based method\n"); + } else { + *val =3D POWER_SUPPLY_STATUS_CHARGING; + return 0; + } + } + ret =3D max77705_fg_read_reg(fuelgauge, SOCREP_REG, &soc_rep); + if (ret) + return ret; + + if (soc_rep < 100) { + ret =3D max77705_fg_read_reg(fuelgauge, CURRENT_REG, ¤t_now); + if (ret) + return ret; + + if (current_now > 0) + *val =3D POWER_SUPPLY_STATUS_CHARGING; + else if (current_now < 0) + *val =3D POWER_SUPPLY_STATUS_DISCHARGING; + else + *val =3D POWER_SUPPLY_STATUS_NOT_CHARGING; + } else { + *val =3D POWER_SUPPLY_STATUS_FULL; + } + + return 0; +} + +static void max77705_unit_adjustment(struct max77705_fuelgauge_data *fuelg= auge, + enum power_supply_property psp, + union power_supply_propval *val) +{ + const unsigned int base_unit_conversion =3D 1000; + + switch (psp) { + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + case POWER_SUPPLY_PROP_VOLTAGE_OCV: + case POWER_SUPPLY_PROP_VOLTAGE_AVG: + val->intval =3D max77705_fg_vs_convert(val->intval); + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: + case POWER_SUPPLY_PROP_CURRENT_AVG: + val->intval =3D 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 *=3D base_unit_conversion; + break; + case POWER_SUPPLY_PROP_CAPACITY: + val->intval =3D 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 =3D + power_supply_get_drvdata(psy); + int ret =3D 0; + + switch (psp) { + case POWER_SUPPLY_PROP_STATUS: + ret =3D max77705_battery_get_status(fuelgauge, &val->intval); + break; + case POWER_SUPPLY_PROP_PRESENT: + ret =3D max77705_fg_check_battery_present(fuelgauge, &val->intval); + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + ret =3D max77705_fg_read_reg(fuelgauge, VCELL_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_VOLTAGE_OCV: + ret =3D max77705_fg_read_reg(fuelgauge, VFOCV_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_VOLTAGE_AVG: + ret =3D max77705_fg_read_reg(fuelgauge, AVR_VCELL_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: + ret =3D max77705_fg_read_reg(fuelgauge, CURRENT_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CURRENT_AVG: + ret =3D max77705_fg_read_reg(fuelgauge, AVG_CURRENT_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CHARGE_NOW: + ret =3D max77705_fg_read_reg(fuelgauge, REMCAP_REP_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CHARGE_FULL: + ret =3D max77705_fg_read_reg(fuelgauge, FULLCAP_REP_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + ret =3D max77705_fg_read_reg(fuelgauge, DESIGNCAP_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CAPACITY: + ret =3D max77705_fg_read_reg(fuelgauge, SOCREP_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_TEMP: + ret =3D max77705_fg_read_temp(fuelgauge, &val->intval); + break; + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW: + ret =3D max77705_fg_read_reg(fuelgauge, TIME_TO_EMPTY_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: + ret =3D max77705_fg_read_reg(fuelgauge, TIME_TO_FULL_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CYCLE_COUNT: + ret =3D max77705_fg_read_reg(fuelgauge, CYCLES_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_MODEL_NAME: + val->strval =3D max77705_fuelgauge_model; + break; + case POWER_SUPPLY_PROP_MANUFACTURER: + val->strval =3D 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 =3D { + .name =3D "max77705-fuel-gauge", + .type =3D POWER_SUPPLY_TYPE_BATTERY, + .properties =3D max77705_fuelgauge_props, + .num_properties =3D ARRAY_SIZE(max77705_fuelgauge_props), + .get_property =3D max77705_fg_get_property, +}; + +static int max77705_fg_set_charge_design(struct regmap *regmap, int value) +{ + u8 data[2]; + int value_mah; + + value_mah =3D value / 1000; + data[0] =3D value_mah & 0xFF; + data[1] =3D (value_mah >> 8) & 0xFF; + + return regmap_noinc_write(regmap, DESIGNCAP_REG, data, sizeof(data)); +} + +static int max77705_write_bat_info(struct max77705_fuelgauge_data *fuelgau= ge) +{ + struct power_supply_battery_info *info =3D fuelgauge->bat_info; + + if (info->energy_full_design_uwh !=3D info->charge_full_design_uah) { + if (info->charge_full_design_uah =3D=3D -EINVAL) + dev_warn(fuelgauge->dev, "missing battery:charge-full-design-microamp-h= ours\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 =3D fuelgauge->dev; + struct device_node *np =3D dev->of_node; + int ret; + unsigned int rsense; + + if (!np) { + dev_err(dev, "no fuelgauge OF node\n"); + return -EINVAL; + } + ret =3D 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 =3D 100; + } else + fuelgauge->rsense_conductance =3D 1000000 / rsense; /* rsense conductanc= e in Ohm^-1 */ + + return 0; +} + +static int max77705_fuelgauge_probe(struct platform_device *pdev) +{ + struct i2c_client *i2c_fg; + struct max77693_dev *max77705 =3D dev_get_drvdata(pdev->dev.parent); + struct max77705_fuelgauge_data *fuelgauge; + struct power_supply_config fuelgauge_cfg =3D { }; + struct device *dev =3D &pdev->dev; + int ret =3D 0; + + fuelgauge =3D devm_kzalloc(dev, sizeof(*fuelgauge), GFP_KERNEL); + if (!fuelgauge) + return -ENOMEM; + + fuelgauge->dev =3D dev; + + ret =3D max77705_fuelgauge_parse_dt(fuelgauge); + if (ret < 0) + return ret; + + fuelgauge_cfg.drv_data =3D fuelgauge; + fuelgauge_cfg.of_node =3D fuelgauge->dev->of_node; + + fuelgauge->psy_fg =3D devm_power_supply_register(&pdev->dev, + &max77705_fg_desc, + &fuelgauge_cfg); + + if (IS_ERR(fuelgauge->psy_fg)) + return PTR_ERR(fuelgauge->psy_fg); + + ret =3D power_supply_get_battery_info(fuelgauge->psy_fg, + &fuelgauge->bat_info); + + if (ret) + return ret; + + i2c_fg =3D devm_i2c_new_dummy_device(max77705->dev, max77705->i2c->adapte= r, + I2C_ADDR_FG); + + if (IS_ERR(i2c_fg)) + return PTR_ERR(i2c_fg); + + fuelgauge->regmap =3D 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[] =3D { + { .compatible =3D "maxim,max77705-fuel-gauge" }, + { } +}; +MODULE_DEVICE_TABLE(of, max77705_fg_of_match); + +static struct platform_driver max77705_fuelgauge_driver =3D { + .driver =3D { + .name =3D "max77705-fuel-gauge", + .of_match_table =3D max77705_fg_of_match, + }, + .probe =3D 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-hour= s. +// 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_RESOLUT= ION, + 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 --=20 2.39.2 From nobody Mon Nov 25 23:18:43 2024 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 C79041FE101; Wed, 23 Oct 2024 19:43:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729712597; cv=none; b=pfoNYfzA6qVJnwYCcg+ssKb/n2unZIuDWoJgJgWBKuwpkL3YBv6uTh9ulgTmAlkR+GgYBHJksfXXLY0nk245p9ZquImRIYLCkayt7uzGiw5QxprYyPugyK8noI82jsUogTt7m/ShQvtqlDhMraw0MDJHUk2lXMp1ilXCoJCsRg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729712597; c=relaxed/simple; bh=9WJ8S/uipIPxiGfe4mLyTfT2gjVM59K76l71woFhhQQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MegZO4wWvX+Ll+h476FZTQg7YPYhHEu++KnFuG9QTTmSa6nVEMnke9KdjphQjLRPvh0kOkJ3Vj1i1EfFMvL5ZfS5RR1uj3hKbY5Wa7mfS3mMXH6r0Xkhs73+jFDaxhfcnTi5OX9ewZZMvvllqvJQJiJDt+8PcGGiQrc4vV29/AU= 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=NAX/WA5/; arc=none smtp.client-ip=209.85.208.41 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="NAX/WA5/" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5c9850ae22eso177191a12.3; Wed, 23 Oct 2024 12:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729712594; x=1730317394; 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=P8/q+z6hhLbXUdIRPd60V3PEMOvkNSPl6LwIAH68oig=; b=NAX/WA5/FOJbxDP42hPlRf8Igh9JIM+rzI7X3V9dvS924H2+qopBkrivm5bNaOATaz sKZfXpSC1X8K7AyAOlL5574e7yMKcoK9857VQ/OPlYYUaFfep9HTaT2bLDOzs1/X6+Wp Y3T+mqg2A222k7NlXBXwFYyQOEuWwOm7qqoQ0YDT8+u3AxdrE6R8LWyPt/Z00hBGhVZR kCHe80gmZy5Oply35+bYN1rAf+PUnbNUp40YEwt4mRWQ+sEPCtH8l8rgzUxrZOKcqqh6 Nvjda5joe1hXmDSi2hwvFSHCj1kTCUIkJQD9RFS4RGRgxrTe/5EY6wUZjCkfOWpitMTK HPuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729712594; x=1730317394; 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=P8/q+z6hhLbXUdIRPd60V3PEMOvkNSPl6LwIAH68oig=; b=QVUmnYNzIu5u0DSC15UgsvGEl3yiimu3ixBzMWtVT3yw98Kt/+Igs5toqiPVQNGATp yPD8JQ07Tp4LXqGUY4fwWN0RJot1c1yxJhxp+jJ4Q0FG3ImaV5nZHDgdPP2V4mp+DGYR kbjifp30Agiu37KIqpMUjrtW/IZUzPJTo+Y94TrFe97QKKJe49PPeOHmhIlTib610BHZ sqg9GODkRC1/w/u3wJ+zbv4gbgKq/c08XSxX7HnFUi+0dBOyMA271/A1n0HMrALtJWJZ vZnR+RJgpQMEwUqhxPxXZa9L0Ag2rmhSDh8LIdAxZu9Oo7Y6inkHrYD7JsIWuxhYCY4F 0uqg== X-Forwarded-Encrypted: i=1; AJvYcCUNGFlC7JsFdmWbt2Euo+aiJULw6J6eTDTP8bUd59kvXO7bDLcfJTN00mtMmNHMvEWtu25N1snx/pkJ0A==@vger.kernel.org, AJvYcCVVV9cBfUyfHQnr80XpZFd0WNooaUlo1gM7LhVmPC6E6ES+Q6bH3B+1raj4XdQLCx3+L5Z5gYFiA1B5jJQ=@vger.kernel.org, AJvYcCWE/07yuuLzGMRdmnCDZbr3fPNc/DrCfi7U3zf37uOOlNZEzZO3PfMpkR8cKmWDh2ODQS+1P1TVWVlJ@vger.kernel.org, AJvYcCXjXpyv+J+yQZKOk+yFvaK06eZbf2DwF9P7hnZi22h6ClQGs/rwdkHUjjD6VbQBcCVhwuIBO2xbw87KFPb7@vger.kernel.org X-Gm-Message-State: AOJu0YzvZccDkbU7clEPH0sZmz/JyO2A3dkrzXEmoElVkDPahGfzNHHg 3IE83B0ojcKuSWhaen5cJbAqJPUwfojnqhhUxtUYh143Tb//8bWkQzTbGA== X-Google-Smtp-Source: AGHT+IER2XZUJhVGUdudfWO/Wrth3J7SPV44qWzz9VwYrcI37W7IfZTEjLibiPy9nuwD+fJkoRpDTg== X-Received: by 2002:a05:6402:280d:b0:5c9:62c3:e7fd with SMTP id 4fb4d7f45d1cf-5cb8acecbbamr3476697a12.16.1729712593623; Wed, 23 Oct 2024 12:43:13 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 12:43:12 -0700 (PDT) From: Dzmitry Sankouski Date: Wed, 23 Oct 2024 22:42:55 +0300 Subject: [PATCH v7 7/7] leds: max77705: Add LEDs support 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: <20241023-starqltechn_integration_upstream-v7-7-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=9269; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=9WJ8S/uipIPxiGfe4mLyTfT2gjVM59K76l71woFhhQQ=; b=Shp9+oGRxlUY10hJIajAquV7LpNsxWJov6kwPtlCjf+dtnZegEeNYfoHAS0sX2YGNenN4FO/L psq/cDjVtpUDk0DGLJBxQ7pxSpoErOIE/HaCWjF/50bxYYwGmJ5bAI5 X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= This adds basic support for LEDs for the max77705 PMIC. Signed-off-by: Dzmitry Sankouski --- Changes for v6: - change compatible suffix to 'rgb' - remove I2C dependency in Kconfig - remove copyright and author from 'based on' header statement - replace MFD abbreviation with PMIC - MAINTAINERS: alphabetic order - max77705_rgb_blink: replace ternary operators with if..else if sequence - max77705_rgb_blink: move hardcoded numbers to constants - max77705_led_brightness_set: move ret to the bottom - s/map/regmap - replace device_for_each_child_node with scoped version - s/rv/ret Changes for v5: - use same hardware name in Kconfig and module descriptions - remove copyrighter owner from module authors Changes in v4: - inline BLINK_(ON|OFF) macro - remove camel case - drop backwards compatibility(new driver) - drop module alias --- MAINTAINERS | 1 + drivers/leds/Kconfig | 6 ++++++ drivers/leds/Makefile | 1 + drivers/leds/leds-max77705.c | 168 +++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++ include/linux/mfd/max77705-private.h | 18 ++++++++++++++++ 5 files changed, 194 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 92700fc71db1..b3076fa66d30 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14119,6 +14119,7 @@ F: Documentation/devicetree/bindings/*/maxim,max776= 93.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/leds/leds-max77705.c F: drivers/*/*max77843.c F: drivers/*/max14577*.c F: drivers/*/max77686*.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index b784bb74a837..27ce55b32543 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -753,6 +753,12 @@ config LEDS_MAX77650 help LEDs driver for MAX77650 family of PMICs from Maxim Integrated. =20 +config LEDS_MAX77705 + tristate "LED support for Maxim MAX77705 PMIC" + depends on MFD_MAX77705 && LEDS_CLASS + help + LED driver for MAX77705 PMIC from Maxim Integrated. + config LEDS_MAX8997 tristate "LED support for MAX8997 PMIC" depends on LEDS_CLASS && MFD_MAX8997 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 18afbb5a23ee..096bf244527d 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -60,6 +60,7 @@ obj-$(CONFIG_LEDS_LP8860) +=3D leds-lp8860.o obj-$(CONFIG_LEDS_LT3593) +=3D leds-lt3593.o obj-$(CONFIG_LEDS_MAX5970) +=3D leds-max5970.o obj-$(CONFIG_LEDS_MAX77650) +=3D leds-max77650.o +obj-$(CONFIG_LEDS_MAX77705) +=3D leds-max77705.o obj-$(CONFIG_LEDS_MAX8997) +=3D leds-max8997.o obj-$(CONFIG_LEDS_MC13783) +=3D leds-mc13783.o obj-$(CONFIG_LEDS_MENF21BMC) +=3D leds-menf21bmc.o diff --git a/drivers/leds/leds-max77705.c b/drivers/leds/leds-max77705.c new file mode 100644 index 000000000000..f0762216c4a7 --- /dev/null +++ b/drivers/leds/leds-max77705.c @@ -0,0 +1,168 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Based on leds-max77650 driver +// +// LED driver for MAXIM 77705 PMIC. +// Copyright (C) 2024 Dzmitry Sankouski + +#include +#include +#include +#include +#include +#include + +#define MAX77705_LED_NUM_LEDS 4 +#define MAX77705_LED_EN_MASK GENMASK(1, 0) +#define MAX77705_LED_MAX_BRIGHTNESS 0xff + +struct max77705_led { + struct led_classdev cdev; + struct regmap *regmap; + unsigned int en_shift; + unsigned int reg_brightness; +}; + +static struct max77705_led *max77705_to_led(struct led_classdev *cdev) +{ + return container_of(cdev, struct max77705_led, cdev); +} + +static int max77705_rgb_blink(struct led_classdev *cdev, + unsigned long *delay_on, + unsigned long *delay_off) +{ + struct max77705_led *led =3D max77705_to_led(cdev); + int value, on_value, off_value; + + if (*delay_on < MAX77705_RGB_DELAY_100_STEP) + on_value =3D 0; + else if (*delay_on < MAX77705_RGB_DELAY_100_STEP_LIM) + on_value =3D *delay_on / MAX77705_RGB_DELAY_100_STEP - 1; + else if (*delay_on < MAX77705_RGB_DELAY_250_STEP_LIM) + on_value =3D (*delay_on - MAX77705_RGB_DELAY_100_STEP_LIM) / + MAX77705_RGB_DELAY_250_STEP + + MAX77705_RGB_DELAY_100_STEP_COUNT; + else + on_value =3D 15; + + on_value <<=3D 4; + + if (*delay_off < 1) + off_value =3D 0; + else if (*delay_off < MAX77705_RGB_DELAY_500_STEP) + off_value =3D 1; + else if (*delay_off < MAX77705_RGB_DELAY_500_STEP_LIM) + off_value =3D *delay_off / MAX77705_RGB_DELAY_500_STEP; + else if (*delay_off < MAX77705_RGB_DELAY_1000_STEP_LIM) + off_value =3D (*delay_off - MAX77705_RGB_DELAY_1000_STEP_LIM) / + MAX77705_RGB_DELAY_1000_STEP + + MAX77705_RGB_DELAY_500_STEP_COUNT; + else if (*delay_off < MAX77705_RGB_DELAY_2000_STEP_LIM) + off_value =3D (*delay_off - MAX77705_RGB_DELAY_2000_STEP_LIM) / + MAX77705_RGB_DELAY_2000_STEP + + MAX77705_RGB_DELAY_1000_STEP_COUNT; + else + off_value =3D 15; + + value =3D on_value | off_value; + return regmap_write(led->regmap, MAX77705_RGBLED_REG_LEDBLNK, value); +} + +static int max77705_led_brightness_set(struct led_classdev *cdev, + enum led_brightness brightness) +{ + struct max77705_led *led =3D max77705_to_led(cdev); + unsigned long blink_default =3D 0; + int ret; + + if (brightness =3D=3D LED_OFF) { + // Flash OFF + ret =3D regmap_update_bits(led->regmap, + MAX77705_RGBLED_REG_LEDEN, + MAX77705_LED_EN_MASK << led->en_shift, 0); + max77705_rgb_blink(cdev, &blink_default, &blink_default); + } else { + // Set current + ret =3D regmap_write(led->regmap, + led->reg_brightness, brightness); + if (ret < 0) + return ret; + + ret =3D regmap_update_bits(led->regmap, + MAX77705_RGBLED_REG_LEDEN, LED_ON << led->en_shift, + MAX77705_LED_EN_MASK << led->en_shift); + } + + return ret; +} + +static int max77705_led_probe(struct platform_device *pdev) +{ + struct max77705_led *leds, *led; + struct device *dev =3D &pdev->dev; + struct regmap *regmap; + int ret, num_leds; + u32 reg; + + leds =3D devm_kcalloc(dev, sizeof(*leds), + MAX77705_LED_NUM_LEDS, GFP_KERNEL); + if (!leds) + return -ENOMEM; + + regmap =3D dev_get_regmap(dev->parent, NULL); + if (!regmap) + return -ENODEV; + + num_leds =3D device_get_child_node_count(dev); + if (num_leds < 0 || num_leds > MAX77705_LED_NUM_LEDS) + return -ENODEV; + + device_for_each_child_node_scoped(dev, child) { + struct led_init_data init_data =3D {}; + + ret =3D fwnode_property_read_u32(child, "reg", ®); + if (ret || reg >=3D MAX77705_LED_NUM_LEDS) + ret =3D -EINVAL; + + led =3D &leds[reg]; + led->regmap =3D regmap; + led->reg_brightness =3D MAX77705_RGBLED_REG_LED0BRT + reg; + led->en_shift =3D MAX77705_RGBLED_EN_WIDTH * reg; + led->cdev.brightness_set_blocking =3D max77705_led_brightness_set; + led->cdev.blink_set =3D max77705_rgb_blink; + led->cdev.max_brightness =3D MAX77705_LED_MAX_BRIGHTNESS; + + init_data.fwnode =3D child; + + ret =3D devm_led_classdev_register_ext(dev, &led->cdev, + &init_data); + if (ret) + return ret; + + ret =3D max77705_led_brightness_set(&led->cdev, LED_OFF); + if (ret) + return ret; + } + + return 0; +} + +static const struct of_device_id max77705_led_of_match[] =3D { + { .compatible =3D "maxim,max77705-rgb" }, + { } +}; +MODULE_DEVICE_TABLE(of, max77705_led_of_match); + +static struct platform_driver max77705_led_driver =3D { + .driver =3D { + .name =3D "max77705-led", + .of_match_table =3D max77705_led_of_match, + }, + .probe =3D max77705_led_probe, +}; +module_platform_driver(max77705_led_driver); + +MODULE_DESCRIPTION("Maxim MAX77705 LED driver"); +MODULE_AUTHOR("Dzmitry Sankouski "); +MODULE_LICENSE("GPL"); diff --git a/include/linux/mfd/max77705-private.h b/include/linux/mfd/max77= 705-private.h index 6eb2b2e07c12..3a9a0a3bd97e 100644 --- a/include/linux/mfd/max77705-private.h +++ b/include/linux/mfd/max77705-private.h @@ -34,6 +34,24 @@ #define MAX77705_SYSTEM_IRQ_SYSOVLO_INT BIT(5) #define MAX77705_SYSTEM_IRQ_TSHDN_INT BIT(6) #define MAX77705_SYSTEM_IRQ_TM_INT BIT(7) +// MAX77705_RGBLED_REG_LEDEN register +#define MAX77705_RGBLED_EN_WIDTH 2 +// MAX77705_RGBLED_REG_LEDBLNK register +#define MAX77705_RGB_DELAY_100_STEP_LIM 500 +#define MAX77705_RGB_DELAY_100_STEP_COUNT 4 +#define MAX77705_RGB_DELAY_100_STEP 100 +#define MAX77705_RGB_DELAY_250_STEP_LIM 3250 +#define MAX77705_RGB_DELAY_250_STEP 250 +#define MAX77705_RGB_DELAY_500_STEP 500 +#define MAX77705_RGB_DELAY_500_STEP_COUNT 10 +#define MAX77705_RGB_DELAY_500_STEP_LIM 5000 +#define MAX77705_RGB_DELAY_1000_STEP_LIM 8000 +#define MAX77705_RGB_DELAY_1000_STEP_COUNT 13 +#define MAX77705_RGB_DELAY_1000_STEP 1000 +#define MAX77705_RGB_DELAY_2000_STEP 2000 +#define MAX77705_RGB_DELAY_2000_STEP_COUNT 13 +#define MAX77705_RGB_DELAY_2000_STEP_LIM 12000 + =20 enum max77705_hw_rev { MAX77705_PASS1 =3D 1, --=20 2.39.2