From patchwork Thu Sep 26 10:20:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 831714 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 BA4161AD9C8; Thu, 26 Sep 2024 10:20:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346055; cv=none; b=Q2XOxK/x4Y8EF5/3pDacFobrINEP0PJDYPKYNeGDM5OedAtfNFDJY294TkV9OBJZ7Ay6S5oMIW9sMOPn6uu8a/J28/1pq24woJiVhLPeBLWH4VOO6m7orNoxOe3Z91z0LfQHjWradlMO0hlueJ/BlvB5aG0ygx2iDXpPEfrmy98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346055; c=relaxed/simple; bh=HJ0A6QCUdODL8Ly5y32DEfhcMGJG5BnjTSkz0jr8Gvw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RME7jFVA4n0THG4gMi5v2KBIWXR5GTVBZcjvGE78UfuZMipvmz8nlh9gn7LgB+luQ/bS3uEYajRcrSzmvCw2nGeh2nGvFQr4u5UPDVa6zWemW8o3Cx7uUuk+gRTec00RVySVOKkBzu5Zmbaw4bvDeReULobeefDLtuiUaT06L2s= 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=E2hQlHQk; arc=none smtp.client-ip=209.85.167.54 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="E2hQlHQk" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-535694d67eeso869946e87.0; Thu, 26 Sep 2024 03:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727346052; x=1727950852; 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=zZslR+ik1mCYyj1qO5cyJZQJ3YEIIi44NJsP0OMl+IU=; b=E2hQlHQk8Cmp2zWbnedx8ToJ2CsWeeMMBbgup4BHs9ceO3wHkQ/BqbSw2HtZjrfdKE Ui4HlNJLTWpCOOiJw1xwRtWi0cNp7U4rryHEQa+dpznn7oexddetWcm3fY9MA9pT5SCY piyJNKF8Rkc3SSctuu3McU7TSHU898/AIsAB+6rlPxU1SL7Ev8c29WiVZrPl7H+vrjV6 fnIGjJ9rAhTlQcSirpTw1i2p6O4F4iPDN2Kfw/aGnEKFpnaf6706yiWQ5k5eaGqukghn V2vXAf9rkirtWgLqSjG74/L1VI8IevGCc5v/ToXADNk/D62+DfOvH69hrEe1sa1BBatc SnIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727346052; x=1727950852; 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=zZslR+ik1mCYyj1qO5cyJZQJ3YEIIi44NJsP0OMl+IU=; b=KQdXHvzhaX4Rbwc4EJ1oSp7jS8y6l+dbB6FI40uUSCebi1fI73kinlJAnJd6lOvwFc YdUHf3s0LHHU19QWVRxlJv/jkPhegp8SlJXniJNcUp3EHatVPbvEyJ3eEQ/Or7EzaKsW q7O5Gxqwe7I7kF7GYYuAKJBMBw7QzW4USBp/oSfoK+GVDKtomtIFWsJFmSb34k7apWHV 8IOkEa1WWAGBT0hTWdc77ojSLrHa02udZVgakcY0g9zEiihssEKhFfBaerCPYGyEn1op 9ETieaHPdUbudeIsUYz3qySCAtTX1OmRHvkU38KILdStv0fJyLhJCoVvanWkIyqsyMoC Onpw== X-Forwarded-Encrypted: i=1; AJvYcCVJxTX0Cd5agS4qOL7B2YtOHK/yenE7No5fHEkzSVp6IROP5UtEMoVasC2jzgFWRCDrAvgf/7R0fGym6Zk=@vger.kernel.org, AJvYcCWHKCKdnH/+P6+Sr33yQaB+TOKku3s8lkMDO4mpkRrgja2CJloHuiTIob6dy04SChMgNAdVl2etQ5Wb5g==@vger.kernel.org, AJvYcCWLsCwaSowU7Te7JmjYOEPqjwB4iDwblIVK/JdidIXqTDqTQI6Ro0mEgGltehUBaoxst8mtoX2RsjgWUNBn@vger.kernel.org, AJvYcCXt9OvUyi95oQZRainFKot4Gpnd6h61ftUFy+JW8TWTJkKzSxBR8TgDuucbWV8xyRIMPSqyv2yL2Deq@vger.kernel.org X-Gm-Message-State: AOJu0YxelIYpsMN+JLUtL5GuU20oV/WdTBREW/gqxMnGKZz0m/TYWmMV LdP2wDDy96V9gcwVhQ1TjHhK4vcYI8kFxvvcMjdXjJz6wRE9g0yT X-Google-Smtp-Source: AGHT+IH3Ylwe/kFzrXSbmzZR/5UQJwqKoRLCcmz8RbSfDAbTdwsnudyXoV35V9nqhTEZH2KRt8gRBQ== X-Received: by 2002:a05:6512:3c8b:b0:52c:ad70:6feb with SMTP id 2adb3069b0e04-53896bf39efmr782010e87.20.1727346051454; Thu, 26 Sep 2024 03:20:51 -0700 (PDT) Received: from [127.0.1.1] (mm-20-1-84-93.mgts.dynamic.pppoe.byfly.by. [93.84.1.20]) by smtp.googlemail.com with ESMTPSA id 2adb3069b0e04-537a85ee54esm759071e87.96.2024.09.26.03.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 03:20:50 -0700 (PDT) From: Dzmitry Sankouski Date: Thu, 26 Sep 2024 13:20:18 +0300 Subject: [PATCH v5 1/7] power: supply: add undervoltage health status property Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240617-starqltechn_integration_upstream-v5-1-e0033f141d17@gmail.com> References: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> In-Reply-To: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> To: Sebastian Reichel , Chanwoo Choi , Krzysztof Kozlowski , Lee Jones , Rob Herring , Conor Dooley , Dmitry Torokhov , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1727346045; l=2343; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=HJ0A6QCUdODL8Ly5y32DEfhcMGJG5BnjTSkz0jr8Gvw=; b=Zyi92JtQM5vD+tEI53WaReJHGeLrefiOfI9MNeTN+E1MopZhBG3GeTe7rsmq5ITOV14/2hpxp PuAE6itfR1TBmR76GclBJqklWVwZLqRfwl+TVsSO5uBeclG+vPUUBhn 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/ABI/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: 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/supply/power_supply_sysfs.c index 16b3c5880cd8..82b2275de465 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[] = { [POWER_SUPPLY_HEALTH_OVERHEAT] = "Overheat", [POWER_SUPPLY_HEALTH_DEAD] = "Dead", [POWER_SUPPLY_HEALTH_OVERVOLTAGE] = "Over voltage", + [POWER_SUPPLY_HEALTH_UNDERVOLTAGE] = "Under voltage", [POWER_SUPPLY_HEALTH_UNSPEC_FAILURE] = "Unspecified failure", [POWER_SUPPLY_HEALTH_COLD] = "Cold", [POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE] = "Watchdog timer expire", diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 910d407ebe63..8682e6466544 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, From patchwork Thu Sep 26 10:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 830938 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A42441AE846; Thu, 26 Sep 2024 10:20:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346058; cv=none; b=nJkH0KVO9mBNnuUOr7Lcfv5JZkjE73jjVYQNwbDgYI+nj2IJsAmFllXGscfOs0xBAUqq4hPpxTzgRH6yyu5WNupN8JXsIE+bPRWLE5gZ7s82Cxm7o6GvVwQNGmS4zrDW5DbDCuINOGqwN6+C5U3OYCYfbXO7w8z2etfk62T0XR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346058; c=relaxed/simple; bh=uxXb5xMrAeZA/PGCI0cjUzdsJNW6qdUaqZhiqHlS0Us=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WNdeeI66QudAQkd38D/Q/KibFFQ/XZ56ymIcSP1BZhHno5w8U3JLU7ptklKR0cdiT93LbwHTt80PE2hGsN4cBHiDutkaAfL7lnCtFx6A0Bl8hBDGrsmD1kOf1y10OMPxoHRbKZcUna8LJ63O+iU54rn1emZ7GS+Ccigz2YrFn6Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Hy4Hdxbc; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hy4Hdxbc" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2f754d4a6e4so9356471fa.3; Thu, 26 Sep 2024 03:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727346055; x=1727950855; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=mCnK0YaRfOlDi/MQIp9RVs5sdcIVgQygzC7gFn5dGeU=; b=Hy4HdxbckSlUGQXa8zkTHVJVtVRFwGLgSBb5gfUOTQNd18qaua3wny3jJMM6dAdiya leM2tfqSfRBK9MAGjh+E6A2wUhuHkYqu9IednNBJ7Yh/QICqd/A7T7j3zmD9y3I9hHyb CyLqu3yAOLflyMNSHtuwQ9xIIzGkGdE9+/YzeJPEolBTWlTapiHNIrkYtjoSYz7rUGn0 kGJMEK0k8a6cB1FYOzKkdfkTZPjlprJE/gmOA2a18XB/Spm80dJbCfirDjo9eSbLkQD7 EmkQriJYkZqEUo+Lt/kGDKYZIUiYJ8Fbq75fFZYi4rgaoQPztugegqgh1+45NoZiIACi geTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727346055; x=1727950855; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mCnK0YaRfOlDi/MQIp9RVs5sdcIVgQygzC7gFn5dGeU=; b=m38Rq39OzBD98cUKzI4hVjtwant+S8ZU9QjDlkjSbN7dpquA/rwHDgoJyh0gFiOgeO Pm7KuhH6+kuJjoSW+LrwvAVAWCJBqsfTeciFwGccnLY2pneGv8vSgAwLV4F+dLbMJd1/ PYiPpj20WrFM2GzcOVbswNFc6YwNiFLKrIrixNDFtHzN8hSnFFI9eOEDzeNMbmxxlkzg aDiSPSb1BHIG+1XMi6844Rr0io0HhpaDPbpXDUyVy9iCRTVxAeVUqRCVgQApMx6isirY DezVDAMK+2Imy3hmTARCZAq8HXu45JrgL/3To7SfqA9/nQW5AnbCu8JudaDZysRu966s WxRg== X-Forwarded-Encrypted: i=1; AJvYcCUxjGxCgVJjMoDOv/My00zF7zyKLaCDnsC2q6cTZ6+f9sfJsT1lP2XIouqOBE3V7xpfXIov/8EZz2ROASLT@vger.kernel.org, AJvYcCVJvh5/R+RygzBFy7ysva50B8DQVO9QuiX1bssXegvcheoTG7b/JTLYAbhqjrelSfNcJrLfx4qSer4OFtY=@vger.kernel.org, AJvYcCVKu21mEmIH03G10314/LSd/+jBg6DWOKS8ylrPVAJzwWvVts8MigonF0FlBGNPZ+9vOk3MNTGu0Ea7dQ==@vger.kernel.org, AJvYcCWjnjelSWK6M3+SqQbu9FURu1BWO+I8tefrjgQ2RjY3qlZOCbiJUZTmWtXxgF3VmxY+1kF+FRaW9CWc@vger.kernel.org X-Gm-Message-State: AOJu0Yz3foj6ryVUznqsQEnBbSz9Kfq5PTRqZrEIXVAiBdHjPSkyiMcJ aNQ/OHH3X0d2qQtSq7TOwcLoV3A+l+qX99Y5VOMRh0ud73miJtHk X-Google-Smtp-Source: AGHT+IFLi7YOGKzuax+KcCUegsiaf2QaWmNNgn1R7oRerwNKtavza4YaP78iTb6sd/Szi7OA/3PUyg== X-Received: by 2002:a05:6512:128b:b0:536:54df:bffa with SMTP id 2adb3069b0e04-5387755cc03mr3766963e87.45.1727346054440; Thu, 26 Sep 2024 03:20:54 -0700 (PDT) Received: from [127.0.1.1] (mm-20-1-84-93.mgts.dynamic.pppoe.byfly.by. [93.84.1.20]) by smtp.googlemail.com with ESMTPSA id 2adb3069b0e04-537a85ee54esm759071e87.96.2024.09.26.03.20.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 03:20:53 -0700 (PDT) From: Dzmitry Sankouski Date: Thu, 26 Sep 2024 13:20:19 +0300 Subject: [PATCH v5 2/7] dt-bindings: mfd: add maxim,max77705 Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240617-starqltechn_integration_upstream-v5-2-e0033f141d17@gmail.com> References: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> In-Reply-To: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> To: Sebastian Reichel , Chanwoo Choi , Krzysztof Kozlowski , Lee Jones , Rob Herring , Conor Dooley , Dmitry Torokhov , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1727346045; l=5974; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=uxXb5xMrAeZA/PGCI0cjUzdsJNW6qdUaqZhiqHlS0Us=; b=WXRUTUfi2U1BjuENigKHUDmWDT0lBX+fbUF5LD0EuF/KT7VFRrJLiL8dbWy0RmsryYXiCJuqp w5uLmcubT2EArJjmQ14n3WaNxJBIoY3OLJ2fWM0M10TJd6g6E38kGk3 X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Add maxim,max77705 core binding part. Signed-off-by: Dzmitry Sankouski --- Changes in v5: - formatting changes - add unevaluatedProperties: false for nodes referencing common schemas - remove additionalProperties on nodes with unevaluatedProperties: false - add min and max to led index Changes in v4: - change dts example intendation from tabs to spaces - remove interrupt-names property - remove obvious reg description - split long(>80) lines --- Documentation/devicetree/bindings/mfd/maxim,max77705.yaml | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 178 insertions(+) diff --git a/Documentation/devicetree/bindings/mfd/maxim,max77705.yaml b/Documentation/devicetree/bindings/mfd/maxim,max77705.yaml new file mode 100644 index 000000000000..214515f84c85 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/maxim,max77705.yaml @@ -0,0 +1,177 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/maxim,max77705.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim MAX77705 Companion Power Management IC and USB Type-C interface IC + +maintainers: + - Dzmitry Sankouski + +description: | + This is a part of device tree bindings for Maxim MAX77705 multi functional + device. + + The Maxim MAX77705 is a Companion Power Management and Type-C + interface IC which includes charger, fuelgauge, LED, haptic motor driver and + Type-C management IC. + +properties: + compatible: + const: maxim,max77705 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + charger: + $ref: /schemas/power/supply/power-supply.yaml + unevaluatedProperties: true + properties: + compatible: + const: maxim,max77705-charger + + required: + - compatible + - monitored-battery + + fuel-gauge: + $ref: /schemas/power/supply/power-supply.yaml + type: object + unevaluatedProperties: true + description: MAX77705 fuel gauge with ModelGauge m5 EZ algorithm support. + + properties: + compatible: + const: maxim,max77705-fuel-gauge + + shunt-resistor-micro-ohms: + description: + The value of current sense resistor in microohms. + + required: + - compatible + - shunt-resistor-micro-ohms + - monitored-battery + - power-supplies + + haptic: + type: object + additionalProperties: false + + properties: + compatible: + const: maxim,max77705-haptic + + haptic-supply: true + + pwms: + maxItems: 1 + + required: + - compatible + - haptic-supply + - pwms + + leds: + type: object + additionalProperties: false + description: + Up to 4 LEDs supported. One LED is represented by one child node. + + properties: + compatible: + const: maxim,max77705-led + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + + patternProperties: + "^led@[0-3]$": + $ref: /schemas/leds/common.yaml# + type: object + unevaluatedProperties: false + + properties: + reg: + description: LED index. + minimum: 0 + maximum: 3 + + required: + - reg + + required: + - compatible + - "#address-cells" + - "#size-cells" + +required: + - compatible + +additionalProperties: false + +examples: + - | + #include + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pmic@66 { + compatible = "maxim,max77705"; + reg = <0x66>; + interrupt-parent = <&pm8998_gpios>; + interrupts = <11 IRQ_TYPE_LEVEL_LOW>; + pinctrl-0 = <&chg_int_default>; + pinctrl-names = "default"; + + leds { + compatible = "maxim,max77705-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@1 { + reg = <1>; + label = "red:usr1"; + }; + + led@2 { + reg = <2>; + label = "green:usr2"; + }; + + led@3 { + reg = <3>; + label = "blue:usr3"; + }; + }; + + max77705_charger: charger { + compatible = "maxim,max77705-charger"; + monitored-battery = <&battery>; + }; + + fuel-gauge { + compatible = "maxim,max77705-fuel-gauge"; + monitored-battery = <&battery>; + power-supplies = <&max77705_charger>; + shunt-resistor-micro-ohms = <5000>; + }; + + + haptic { + compatible = "maxim,max77705-haptic"; + haptic-supply = <&vib_regulator>; + pwms = <&vib_pwm 0 50000>; + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 5e467ba71e3b..5e5829f28631 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14069,6 +14069,7 @@ B: mailto:linux-samsung-soc@vger.kernel.org F: Documentation/devicetree/bindings/*/maxim,max14577.yaml F: Documentation/devicetree/bindings/*/maxim,max77686.yaml F: Documentation/devicetree/bindings/*/maxim,max77693.yaml +F: Documentation/devicetree/bindings/*/maxim,max77705*.yaml F: Documentation/devicetree/bindings/*/maxim,max77843.yaml F: Documentation/devicetree/bindings/clock/maxim,max77686.txt F: drivers/*/*max77843.c From patchwork Thu Sep 26 10:20:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 831713 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 B8D0F1AE870; Thu, 26 Sep 2024 10:20:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346062; cv=none; b=lFkebC/6IrAOpD4BM7pr6uqxJJA2iDsMUe4cQ82ZGsVa4hGbsrKUf6C5kqYvNqB62yAsVa5k/9NEGRaP6r8n1452iuyngNdE6d652KDFqDPT2+UQDjZitqQkKEiv+c1M1ijUWtdkJNYlRwhoJQzYvtkiAHnJvdANHI+su4cXP04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346062; c=relaxed/simple; bh=p5Y/lJbvoOrfKkfFr0ukcPnq2d08db9jYAi3DPZm75E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pNUGPtT3dvR9hIrCWZMt9qdk4ZzKWNB3JU5wZxLq4MHZs1XkpHMf71XNUph4QR//PE0D/N6P/2z+GeeswKPt8wyuVc4pm0Y6q2AkuWieO3NlSDDdzHmTH1XlKtRBpuYEX3QwGfM0erxIMR++JsDaR7Hoj3K/KJIfmU69D08bSQY= 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=Gfn4ISVQ; arc=none smtp.client-ip=209.85.167.43 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="Gfn4ISVQ" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5366fd6fdf1so1082840e87.0; Thu, 26 Sep 2024 03:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727346058; x=1727950858; 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=b+NEpZH6KLuRAYhtDzOt7H1iFZ18nnrB83Qbm6BxXHc=; b=Gfn4ISVQsRvBHVcBgrrsB5geRaka977cP5zwGujnJT0eTldZcAyaWXCC5QJQcmi/iB g39QZ6FazQs8mAD+489v698qvT2GAfBYwP6OfoOBnuDm5xja00NKetyQBF804Sit7pcZ rmWGmTOdsqYokwMdrHEc6YcZAJOGrOhOfEoUOXOb1an3WxRVRlRYvT2R3yEGP/hGj/Qy frAgi/9yYJxYtOj/xa5X6yrFhpW7fVck8sQ/xFvO8wmCSsPBn9HqToeBJIsSsSrBGgcK GvQdV9NvWNcGDwb7zpchFtduj7HsGLR+qJe0XRoc5WmyBDB67f4F4k+o1o/xrjV3uR4P yisQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727346058; x=1727950858; 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=b+NEpZH6KLuRAYhtDzOt7H1iFZ18nnrB83Qbm6BxXHc=; b=bHwHgfKdbzSRzrjnbN8JwG36iLB5360KQQSLF/lI3ipZf7Q7nYfnEhgKpohhZYVo85 hjxMB9Pm6+DbgbTHF36xmg6Xu2gDdKOwM4/yYZYIDWgSivNV424zxV4q52Pe7plxjmtJ xBmg2GAmYYC2ooh3kVn29Bo3HC4ajsfLplStyu5I+e7850vbGR24MhPJdo3ilMqUK031 G3Kb70Kz3/OAtwbIsw5qnwc/7ure83z+BT2ZshMmEHYMkboEtjFVWF0Mv66uygABFTqV 0qpyLqQLEGSC6E2UOuayMbq90n6sF5vFqs5jsS+2oKJ1gtNmda21sD/rvezWbAcUbn4K 4I3Q== X-Forwarded-Encrypted: i=1; AJvYcCU0nZsVjpqW+95OLGDpQOp+X1ftdwC1bUQWzD/WkWQKrhOBaIc4jY8mebbcQDdbvr0ekFej3H0fB4mKwbs=@vger.kernel.org, AJvYcCWv6nXlB8dkCl1+zq1fpe//hsLpNuGVhpUuw/SeHE4iPA5gevS1K0y1fi8zM6lowIKN6yIIzihqImO14Q==@vger.kernel.org, AJvYcCXAIaeD6VmSefZlnsv1MPpJHdEP8QDekvo+VcZvibdlWhrqANqbg2DNdVU3kP3I1LFK6BUgpLPqO1i/@vger.kernel.org, AJvYcCXMfYeaLSEj9wqbrPrElBmLTInBgRcfPVjmxajvN2ZNucHJEQXwpWVlBBw4Z2MRwd05g2T3p6JhpTM+pVfq@vger.kernel.org X-Gm-Message-State: AOJu0Yw7rmma67ZiHCGy4oTPouzSHZI6Vl5x6WwHhhUyu2jQVYVv7zw6 x4Tq3m6DBsXBmHbBEkM76fMFNTYAm9GBhdvVCOAVq8CHHb4rfIjY X-Google-Smtp-Source: AGHT+IHFwxKFglzO85v4o2K8jgzMeUhIowxK5dvxbhCGGnB5jrPP51vTZlwrqz4uH0Jfk8LMyZYp5g== X-Received: by 2002:a05:6512:281f:b0:530:aa3f:7889 with SMTP id 2adb3069b0e04-5387c590f37mr3897058e87.56.1727346057358; Thu, 26 Sep 2024 03:20:57 -0700 (PDT) Received: from [127.0.1.1] (mm-20-1-84-93.mgts.dynamic.pppoe.byfly.by. [93.84.1.20]) by smtp.googlemail.com with ESMTPSA id 2adb3069b0e04-537a85ee54esm759071e87.96.2024.09.26.03.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 03:20:56 -0700 (PDT) From: Dzmitry Sankouski Date: Thu, 26 Sep 2024 13:20:20 +0300 Subject: [PATCH v5 3/7] mfd: Add new driver for MAX77705 PMIC Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240617-starqltechn_integration_upstream-v5-3-e0033f141d17@gmail.com> References: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> In-Reply-To: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> To: Sebastian Reichel , Chanwoo Choi , Krzysztof Kozlowski , Lee Jones , Rob Herring , Conor Dooley , Dmitry Torokhov , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1727346045; l=18747; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=p5Y/lJbvoOrfKkfFr0ukcPnq2d08db9jYAi3DPZm75E=; b=72mECttBpL75wb2LxXKj8dTzJH6PMfPjnWisPlzsAtsW3i/C/64q5HDuV7Elh0NvQM57X4rwd ZBB0gkP8y2LBSgsqxMZFleLD6Y08BynDaMnbmJrxVrsgxCp54ssFpFK 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 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 | 248 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/max77693-common.h | 6 ++- include/linux/mfd/max77705-private.h | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 449 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 5e5829f28631..e45bbafbb938 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14076,6 +14076,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 @@ -14083,6 +14084,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 MAXIRADIO FM RADIO RECEIVER DRIVER M: Hans Verkuil diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index f9325bcce1b9..090eb3fb3d67 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -904,6 +904,18 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. +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. + 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 2a9f91e81af8..3dc5742c6aeb 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -167,6 +167,7 @@ obj-$(CONFIG_MFD_MAX77620) += max77620.o obj-$(CONFIG_MFD_MAX77650) += max77650.o obj-$(CONFIG_MFD_MAX77686) += max77686.o obj-$(CONFIG_MFD_MAX77693) += max77693.o +obj-$(CONFIG_MFD_MAX77705) += max77705.o obj-$(CONFIG_MFD_MAX77714) += max77714.o obj-$(CONFIG_MFD_MAX77843) += max77843.o obj-$(CONFIG_MFD_MAX8907) += max8907.o @@ -232,6 +233,7 @@ obj-$(CONFIG_MFD_RK8XX_I2C) += rk8xx-i2c.o obj-$(CONFIG_MFD_RK8XX_SPI) += rk8xx-spi.o obj-$(CONFIG_MFD_RN5T618) += rn5t618.o obj-$(CONFIG_MFD_SEC_CORE) += sec-core.o sec-irq.o +obj-$(CONFIG_MFD_S2DOS05) += s2dos05.o obj-$(CONFIG_MFD_SYSCON) += syscon.o obj-$(CONFIG_MFD_LM3533) += lm3533-core.o lm3533-ctrlbank.o obj-$(CONFIG_MFD_VEXPRESS_SYSREG) += vexpress-sysreg.o diff --git a/drivers/mfd/max77705.c b/drivers/mfd/max77705.c new file mode 100644 index 000000000000..553f20a6cdd5 --- /dev/null +++ b/drivers/mfd/max77705.c @@ -0,0 +1,248 @@ +// SPDX-License-Identifier: GPL-2.0+ +// +// max77705.c - mfd core driver for the MAX77705 +// +// Copyright (C) 2024 Dzmitry Sankouski + +#include +#include +#include +#include +#include +#include +#include +#include + +#define I2C_ADDR_CHG (0xD2 >> 1) +#define I2C_ADDR_FG (0x6C >> 1) + +static struct mfd_cell max77705_devs[] = { + { + .name = "leds-max77705-rgb", + .of_compatible = "maxim,max77705-led", + }, + { + .name = "max77705-fuel-gauge", + .of_compatible = "maxim,max77705-fuel-gauge", + }, + { + .name = "max77705-charger", + .of_compatible = "maxim,max77705-charger", + }, + { + .name = "max77705-haptic", + .of_compatible = "maxim,max77705-haptic", + }, +}; + +static const struct regmap_range max77705_readable_ranges[] = { + regmap_reg_range(MAX77705_PMIC_REG_PMICID1, MAX77705_PMIC_REG_BSTOUT_MASK), + regmap_reg_range(MAX77705_PMIC_REG_INTSRC, MAX77705_PMIC_REG_RESERVED_29), + regmap_reg_range(MAX77705_PMIC_REG_BOOSTCONTROL1, MAX77705_PMIC_REG_BOOSTCONTROL1), + 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_BOOSTCONTROL1), + regmap_reg_range(MAX77705_PMIC_REG_BOOSTCONTROL2, MAX77705_PMIC_REG_BOOSTCONTROL2), + regmap_reg_range(MAX77705_PMIC_REG_SW_RESET, MAX77705_PMIC_REG_USBC_RESET), +}; + +static const struct regmap_range max77705_writable_ranges[] = { + regmap_reg_range(MAX77705_PMIC_REG_MAINCTRL1, MAX77705_PMIC_REG_BSTOUT_MASK), + regmap_reg_range(MAX77705_PMIC_REG_INTSRC, MAX77705_PMIC_REG_RESERVED_29), + regmap_reg_range(MAX77705_PMIC_REG_BOOSTCONTROL1, MAX77705_PMIC_REG_BOOSTCONTROL1), + 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_BOOSTCONTROL1), + regmap_reg_range(MAX77705_PMIC_REG_BOOSTCONTROL2, MAX77705_PMIC_REG_BOOSTCONTROL2), + regmap_reg_range(MAX77705_PMIC_REG_SW_RESET, MAX77705_PMIC_REG_USBC_RESET), + +}; + +static const struct regmap_access_table max77705_readable_table = { + .yes_ranges = max77705_readable_ranges, + .n_yes_ranges = ARRAY_SIZE(max77705_readable_ranges), +}; + +static const struct regmap_access_table max77705_writable_table = { + .yes_ranges = max77705_writable_ranges, + .n_yes_ranges = ARRAY_SIZE(max77705_writable_ranges), +}; + +static const struct regmap_config max77705_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .rd_table = &max77705_readable_table, + .wr_table = &max77705_writable_table, + .max_register = MAX77705_PMIC_REG_USBC_RESET, +}; + +static const struct regmap_config max77705_leds_regmap_config = { + .reg_base = MAX77705_RGBLED_REG_BASE, + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77705_LED_REG_END, +}; + +static const struct regmap_config max77705_chg_regmap_config = { + .reg_base = MAX77705_CHG_REG_BASE, + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77705_CHG_REG_SAFEOUT_CTRL, +}; + +static const struct regmap_config max77705_fg_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77705_FG_END, +}; + +static const struct regmap_irq max77705_topsys_irqs[] = { + { .mask = MAX77705_SYSTEM_IRQ_BSTEN_INT, }, + { .mask = MAX77705_SYSTEM_IRQ_SYSUVLO_INT, }, + { .mask = MAX77705_SYSTEM_IRQ_SYSOVLO_INT, }, + { .mask = MAX77705_SYSTEM_IRQ_TSHDN_INT, }, + { .mask = MAX77705_SYSTEM_IRQ_TM_INT, }, +}; + +static const struct regmap_irq_chip max77705_topsys_irq_chip = { + .name = "max77705-topsys", + .status_base = MAX77705_PMIC_REG_SYSTEM_INT, + .mask_base = MAX77705_PMIC_REG_SYSTEM_INT_MASK, + .num_regs = 1, + .irqs = max77705_topsys_irqs, + .num_irqs = ARRAY_SIZE(max77705_topsys_irqs), +}; + +static int max77705_i2c_probe(struct i2c_client *i2c) +{ + struct max77693_dev *max77705; + struct i2c_client *i2c_chg; + struct i2c_client *i2c_fg; + struct regmap_irq_chip_data *irq_data; + struct irq_domain *domain; + int ret; + unsigned int pmic_rev_value; + u8 pmic_ver, pmic_rev; + + + max77705 = devm_kzalloc(&i2c->dev, sizeof(struct max77693_dev), + GFP_KERNEL); + if (!max77705) + return -ENOMEM; + + max77705->dev = &i2c->dev; + max77705->irq = i2c->irq; + max77705->type = TYPE_MAX77705; + i2c_set_clientdata(i2c, max77705); + + max77705->regmap = 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_value) < 0) + return -ENODEV; + + pmic_rev = (pmic_rev_value & MAX77705_REVISION_MASK); + pmic_ver = ((pmic_rev_value & MAX77705_VERSION_MASK) >> MAX77705_VERSION_SHIFT); + dev_dbg(max77705->dev, "device found: rev.0x%x, ver.0x%x\n", + pmic_rev, pmic_ver); + if (pmic_rev != MAX77705_PASS3) { + dev_err(max77705->dev, "rev.0x%x is not tested", + pmic_rev); + return -ENODEV; + } + + max77705->regmap_leds = devm_regmap_init_i2c(i2c, &max77705_leds_regmap_config); + if (IS_ERR(max77705->regmap_leds)) + return PTR_ERR(max77705->regmap_leds); + + i2c_chg = devm_i2c_new_dummy_device(max77705->dev, + i2c->adapter, I2C_ADDR_CHG); + max77705->regmap_chg = devm_regmap_init_i2c(i2c_chg, + &max77705_chg_regmap_config); + if (IS_ERR(max77705->regmap_chg)) + return PTR_ERR(max77705->regmap_chg); + + i2c_fg = devm_i2c_new_dummy_device(max77705->dev, i2c->adapter, + I2C_ADDR_FG); + max77705->regmap_fg = devm_regmap_init_i2c(i2c_fg, + &max77705_fg_regmap_config); + if (IS_ERR(max77705->regmap_fg)) + return PTR_ERR(max77705->regmap_fg); + + ret = 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 = 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); + + domain = regmap_irq_get_domain(irq_data); + ret = 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 add MFD 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 = to_i2c_client(dev); + struct max77693_dev *max77705 = 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 = to_i2c_client(dev); + struct max77693_dev *max77705 = 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_resume); + +static const struct of_device_id max77705_i2c_dt_ids[] = { + { .compatible = "maxim,max77705" }, + { }, +}; +MODULE_DEVICE_TABLE(of, max77705_i2c_dt_ids); + +static struct i2c_driver max77705_i2c_driver = { + .driver = { + .name = "max77705", + .of_match_table = max77705_i2c_dt_ids, + .pm = pm_sleep_ptr(&max77705_pm_ops), + .suppress_bind_attrs = true, + }, + .probe = max77705_i2c_probe, +}; +module_i2c_driver(max77705_i2c_driver); + +MODULE_DESCRIPTION("Maxim MAX77705 MFD core driver"); +MODULE_AUTHOR("Dzmitry Sankouski "); +MODULE_LICENSE("GPL"); diff --git a/include/linux/mfd/max77693-common.h b/include/linux/mfd/max77693-common.h index a5bce099f1ed..1b87b1ada21c 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, 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 */ enum max77693_types type; @@ -32,6 +34,8 @@ struct max77693_dev { struct regmap *regmap_muic; struct regmap *regmap_haptic; /* Only MAX77693 */ struct regmap *regmap_chg; /* Only MAX77843 */ + struct regmap *regmap_fg; /* Only MAX77705 */ + struct regmap *regmap_leds; /* Only MAX77705 */ 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/max77705-private.h new file mode 100644 index 000000000000..8479d1b6cbe4 --- /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 = 1, + MAX77705_PASS2, + MAX77705_PASS3, +}; + +enum max77705_reg { + MAX77705_PMIC_REG_PMICID1 = 0x00, + MAX77705_PMIC_REG_PMICREV = 0x01, + MAX77705_PMIC_REG_MAINCTRL1 = 0x02, + MAX77705_PMIC_REG_BSTOUT_MASK = 0x03, + MAX77705_PMIC_REG_FORCE_EN_MASK = 0x08, + MAX77705_PMIC_REG_MCONFIG = 0x10, + MAX77705_PMIC_REG_MCONFIG2 = 0x11, + MAX77705_PMIC_REG_INTSRC = 0x22, + MAX77705_PMIC_REG_INTSRC_MASK = 0x23, + MAX77705_PMIC_REG_SYSTEM_INT = 0x24, + MAX77705_PMIC_REG_RESERVED_25 = 0x25, + MAX77705_PMIC_REG_SYSTEM_INT_MASK = 0x26, + MAX77705_PMIC_REG_RESERVED_27 = 0x27, + MAX77705_PMIC_REG_RESERVED_28 = 0x28, + MAX77705_PMIC_REG_RESERVED_29 = 0x29, + MAX77705_PMIC_REG_BOOSTCONTROL1 = 0x4C, + MAX77705_PMIC_REG_BOOSTCONTROL2 = 0x4F, + MAX77705_PMIC_REG_SW_RESET = 0x50, + MAX77705_PMIC_REG_USBC_RESET = 0x51, + + MAX77705_PMIC_REG_END, +}; + +enum max77705_chg_reg { + MAX77705_CHG_REG_BASE = 0xB0, + MAX77705_CHG_REG_INT = 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 = 0x00, + VALRT_THRESHOLD_REG = 0x01, + TALRT_THRESHOLD_REG = 0x02, + SALRT_THRESHOLD_REG = 0x03, + REMCAP_REP_REG = 0x05, + SOCREP_REG = 0x06, + TEMPERATURE_REG = 0x08, + VCELL_REG = 0x09, + TIME_TO_EMPTY_REG = 0x11, + FULLSOCTHR_REG = 0x13, + CURRENT_REG = 0x0A, + AVG_CURRENT_REG = 0x0B, + SOCMIX_REG = 0x0D, + SOCAV_REG = 0x0E, + REMCAP_MIX_REG = 0x0F, + FULLCAP_REG = 0x10, + RFAST_REG = 0x15, + AVR_TEMPERATURE_REG = 0x16, + CYCLES_REG = 0x17, + DESIGNCAP_REG = 0x18, + AVR_VCELL_REG = 0x19, + TIME_TO_FULL_REG = 0x20, + CONFIG_REG = 0x1D, + ICHGTERM_REG = 0x1E, + REMCAP_AV_REG = 0x1F, + FULLCAP_NOM_REG = 0x23, + LEARN_CFG_REG = 0x28, + FILTER_CFG_REG = 0x29, + MISCCFG_REG = 0x2B, + QRTABLE20_REG = 0x32, + FULLCAP_REP_REG = 0x35, + RCOMP_REG = 0x38, + VEMPTY_REG = 0x3A, + FSTAT_REG = 0x3D, + DISCHARGE_THRESHOLD_REG = 0x40, + QRTABLE30_REG = 0x42, + ISYS_REG = 0x43, + DQACC_REG = 0x45, + DPACC_REG = 0x46, + AVGISYS_REG = 0x4B, + QH_REG = 0x4D, + VSYS_REG = 0xB1, + TALRTTH2_REG = 0xB2, + VBYP_REG = 0xB3, + CONFIG2_REG = 0xBB, + IIN_REG = 0xD0, + OCV_REG = 0xEE, + VFOCV_REG = 0xFB, + VFSOC_REG = 0xFF, + + MAX77705_FG_END, +}; + +enum max77705_led_reg { + MAX77705_RGBLED_REG_BASE = 0x30, + MAX77705_RGBLED_REG_LEDEN = 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 = 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 */ From patchwork Thu Sep 26 10:20:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 830937 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5CB01AD3E3; Thu, 26 Sep 2024 10:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346063; cv=none; b=RqhkOtsdMNpXM/vfMz+GGbUn6G2fNSgoNWtKmzAuS/mSSmijclfBmWRSZhpl+/4PECHgItCYFQFO0RNiylcyTKvsyDTZecBy1q9JJZjscn6RXGGLFEWp/AZROPXks1s7t/0fJl8uXnMutd33X3f4GmQ/tEdetCsaHmzjwRv/MO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346063; c=relaxed/simple; bh=JLT3fRS+yl6/Mb+tf79ZnYVcgNkISumMGZ+lQQFDBZo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pvTAamRjkvz+b/LfzUcoXVtWEQ85UBLuf0CdFQl/Sd+oSKb9riW1f3f/Q+nrkzmCukvkoAlodXEk4tOHH8chIVqOfTe7fp+IRd3B2ma4KDSC0DbFh46jdcmX5nQ8VY8yiXO97AjB3ZZL8ej93XvlAjyZVgRKzEk8xaNKo6Xr9s4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CL++dYzT; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CL++dYzT" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-536584f6c84so1066274e87.0; Thu, 26 Sep 2024 03:21:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727346060; x=1727950860; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=KGV3WmFsQ+1pAhEILcS0ZUWipFofO4AxkBOKtNoxFJE=; b=CL++dYzTNo/LnW50RKp3Rzg5/b7apbB0mWRwA+cCwi4BXWJWGA+R5onVEptCDUayP9 jQ3Gjz7x+w0tLK7KzYZL8Cl915cbdz5dZMYN5iR0pQGHSwOWJMy91mUydy6Z47a+cHMT Dl4mQwuU9UdIsrj5B88BAD12+wHvy/m8HTFMN0pNxMhqGw869WRNxPd2AYfuUtfgjwbj I5dwt+rrB5QiStQ5V2OaYVWchmYsuLafOqK4f7Pr7r+3IbZgJHy8Wa5dUA7/qEUQMZFz NnwJH5vAUeLRlhyH7BVjEeZU6fZK8Jj4n/58ROJG7O571sNLrj6LYFhbJwb6xQCoAweT A1Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727346060; x=1727950860; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KGV3WmFsQ+1pAhEILcS0ZUWipFofO4AxkBOKtNoxFJE=; b=M//lFnkvMjKQk3EjDvS4f+G8o0wydnBtlTiS7nQKnWJFDg80d6bOqc9+jNJkTjGOrR ryjAvEr6xFhMf1yRtWlg6CGTvMb4cQGBSfpXPNg2QisJkFBtmWCH84L8MSHqx7uDixo0 dvvRXkoHF1S5IQxj4xVRS21lIwogOyxkktH9S+SHNL2n4htIiD2Dz7PEgkp4a1bnqD/B uwcnIVdXc/fLMkI8lLUegVcF+qin7vnhl/ztCwYC+Und9RtWq3umySjrMbLqmPx691R4 OF2hSbCsTVr5XHR8mO9wp0Qp4L+mkmB1zwYrm2hntIGUfOl0HoR1ZrO+xnnyJY09kG6V an1Q== X-Forwarded-Encrypted: i=1; AJvYcCUv77thuFoJL/TIJxj0de/wyudQnz4zqnzySJ8I0fky/MJOvEJppWwDEcwcORzZtcjV/mWF39cdhXfbag==@vger.kernel.org, AJvYcCVRr/k6KXDU3IcVCA44ee+xB27wMaL+i4+er6dArURQMGIbYAndd2/W+UIoZpUtAI9hqEK9T14N5B3t6bI=@vger.kernel.org, AJvYcCVrYZMY9rmEjGBddzGqYA8tpv1WPhNQwNVt2lf42esds2pfJw1pn7SzTK8qgykMQoSn+qfJROteGgSo@vger.kernel.org, AJvYcCW62UuDuQ3y/J2FCr3KWqg9KcNS2/rph3FoW6c7Ngmu2dVqlTcNgRCk8Kpt2ZDRFuEfuz+MzhCUmFQTKZUp@vger.kernel.org X-Gm-Message-State: AOJu0Ywn+v3c3kfxLEN7cDls+PzxpeobGpbFpJa7fsL264Nptr3iA9hj pPbQId3CE41GByGhStbF+ZFIx5e8e5FgmJmUfhHl/5p9xbFN2YrU X-Google-Smtp-Source: AGHT+IGUK6vZAJ++SUbmFGRptqkZIW9Ifvw5nZrFnUuGWC2xWTh37TlzTVTJiCgFnetJ0OjEsCkz9w== X-Received: by 2002:a05:6512:2310:b0:52e:9b4f:dd8c with SMTP id 2adb3069b0e04-53877537650mr3638945e87.35.1727346059505; Thu, 26 Sep 2024 03:20:59 -0700 (PDT) Received: from [127.0.1.1] (mm-20-1-84-93.mgts.dynamic.pppoe.byfly.by. [93.84.1.20]) by smtp.googlemail.com with ESMTPSA id 2adb3069b0e04-537a85ee54esm759071e87.96.2024.09.26.03.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 03:20:59 -0700 (PDT) From: Dzmitry Sankouski Date: Thu, 26 Sep 2024 13:20:21 +0300 Subject: [PATCH v5 4/7] input: max77693: add max77705 haptic support Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240617-starqltechn_integration_upstream-v5-4-e0033f141d17@gmail.com> References: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> In-Reply-To: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> To: Sebastian Reichel , Chanwoo Choi , Krzysztof Kozlowski , Lee Jones , Rob Herring , Conor Dooley , Dmitry Torokhov , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1727346045; l=4227; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=JLT3fRS+yl6/Mb+tf79ZnYVcgNkISumMGZ+lQQFDBZo=; b=eyhotNhJjShydlq/boHbobSgpvDEaXyMUCGayFGopjNkVFTTUItWfAQNn8qcRjca/d8VTpUF4 oQVsU0AeULEBdB4rCd5VcigfpwPxZUvUXA+TbfFtO2Rxf94Y8MZKJ5e X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Add support for haptic controller on MAX77705 Multifunction device. This driver supports external pwm and LRA (Linear Resonant Actuator) motor. User can control the haptic device via force feedback framework. Signed-off-by: Dzmitry Sankouski Acked-by: Dmitry Torokhov --- Changes in v4: - add max77705 haptic support to max77693 driver - delete max77705-haptic --- drivers/input/misc/Kconfig | 4 ++-- drivers/input/misc/Makefile | 1 + drivers/input/misc/max77693-haptic.c | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 6a852c76331b..b4515c4e5cf6 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -241,11 +241,11 @@ config INPUT_MAX77650_ONKEY config INPUT_MAX77693_HAPTIC tristate "MAXIM MAX77693/MAX77843 haptic controller support" - depends on (MFD_MAX77693 || MFD_MAX77843) && PWM + depends on (MFD_MAX77693 || MFD_MAX77705 || MFD_MAX77843) && PWM select INPUT_FF_MEMLESS help This option enables support for the haptic controller on - MAXIM MAX77693 and MAX77843 chips. + MAXIM MAX77693, MAX77705 and MAX77843 chips. To compile this driver as module, choose M here: the module will be called max77693-haptic. diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 4f7f736831ba..3e3532b27990 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o obj-$(CONFIG_INPUT_MAX77650_ONKEY) += max77650-onkey.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC) += max77693-haptic.o +obj-$(CONFIG_INPUT_MAX77705_HAPTIC) += max77705-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o obj-$(CONFIG_INPUT_MAX8997_HAPTIC) += max8997_haptic.o obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) += mc13783-pwrbutton.o diff --git a/drivers/input/misc/max77693-haptic.c b/drivers/input/misc/max77693-haptic.c index 0e646f1b257b..c3b9d33608d7 100644 --- a/drivers/input/misc/max77693-haptic.c +++ b/drivers/input/misc/max77693-haptic.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #define MAX_MAGNITUDE_SHIFT 16 @@ -115,6 +116,13 @@ static int max77693_haptic_configure(struct max77693_haptic *haptic, MAX77693_HAPTIC_PWM_DIVISOR_128); config_reg = MAX77693_HAPTIC_REG_CONFIG2; break; + case TYPE_MAX77705: + value = ((haptic->type << MAX77693_CONFIG2_MODE) | + (enable << MAX77693_CONFIG2_MEN) | + (haptic->mode << MAX77693_CONFIG2_HTYP) | + MAX77693_HAPTIC_PWM_DIVISOR_128); + config_reg = MAX77705_PMIC_REG_MCONFIG; + break; case TYPE_MAX77843: value = (haptic->type << MCONFIG_MODE_SHIFT) | (enable << MCONFIG_MEN_SHIFT) | @@ -312,6 +320,9 @@ static int max77693_haptic_probe(struct platform_device *pdev) case TYPE_MAX77693: haptic->regmap_haptic = max77693->regmap_haptic; break; + case TYPE_MAX77705: + haptic->regmap_haptic = max77693->regmap; + break; case TYPE_MAX77843: haptic->regmap_haptic = max77693->regmap; break; @@ -407,6 +418,7 @@ static DEFINE_SIMPLE_DEV_PM_OPS(max77693_haptic_pm_ops, static const struct platform_device_id max77693_haptic_id[] = { { "max77693-haptic", }, + { "max77705-haptic", }, { "max77843-haptic", }, {}, }; @@ -414,6 +426,7 @@ MODULE_DEVICE_TABLE(platform, max77693_haptic_id); static const struct of_device_id of_max77693_haptic_dt_match[] = { { .compatible = "maxim,max77693-haptic", }, + { .compatible = "maxim,max77705-haptic", }, { .compatible = "maxim,max77843-haptic", }, { /* sentinel */ }, }; @@ -432,5 +445,5 @@ module_platform_driver(max77693_haptic_driver); MODULE_AUTHOR("Jaewon Kim "); MODULE_AUTHOR("Krzysztof Kozlowski "); -MODULE_DESCRIPTION("MAXIM 77693/77843 Haptic driver"); +MODULE_DESCRIPTION("MAXIM 77693/77705/77843 Haptic driver"); MODULE_LICENSE("GPL"); From patchwork Thu Sep 26 10:20:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 831712 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.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 E83C51AED59; Thu, 26 Sep 2024 10:21:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346067; cv=none; b=dSTCYDGvrNO/Lwj84Ru1+mMG0ZyEoDI2dkQOyYxE+Xx+o+h/FN28QWFMNKS/kh8fxuEOzbx+K/gmk774WF/GZDU0dXanoG8OlAi1Edh8UqqvO4EIuhZJnuNB/8mWID4jzMPgyxQTcM+qce7mdeXnvTE3PGwEVj/xwy6fx+hnhZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346067; c=relaxed/simple; bh=qW9UzfSEpbF4PIRD1MoizEtKKqoEMcUSUJsAac4XSuI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d3WXuvUA3ldlzUzqBWduPxWPIpKRbaT90oPzbZRcqnbZnfxe8LziXHN9SY1b4FmUgnIkM+lNEg474PVx2n4t0UmNqj9K26pnzKWll/Y8z70G6rZnTT45R2GsLFsy0z366tTHW65nVNs9CaQyYVVKZ3EC3vQKKNQasqv1BdGHGzk= 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=HVBeQ9rd; arc=none smtp.client-ip=209.85.167.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="HVBeQ9rd" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-53659867cbdso1294088e87.3; Thu, 26 Sep 2024 03:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727346063; x=1727950863; 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=dpPbi7nNGcROCERM70CR7JgPcbCzDrL3zEMPaait1uc=; b=HVBeQ9rdEQKALtj7C34ElCBXE5JFweMmUgVD3ZZl0wuFG0NJdpsaDHbkXNs8HRQDvy 2KVy5mBXhLGOZrWeZ3znESlce+0XLT17/ei2IgEBWSmwJKsegEvIWCZkIswGZW6cw88V o1I6YY6NkvjqCCH7Q+AThmVvuT9MbiiZmGF95a7qUsUUr4CihHo6iqcka5g9JKwXkukZ jn+w3EfH/gAiI+v9Tq8g0svd5lmK5ylVAE+DN8EozGmwt0oChMk7WSgmuKMBHLoDwa3G /Vahl3NhhuTDceWUF2G4Q1x5TZXkpXncgHGWCbfei0jdhxUvJISvBuq+amaSZ2lkFFBu UQNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727346063; x=1727950863; 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=dpPbi7nNGcROCERM70CR7JgPcbCzDrL3zEMPaait1uc=; b=flKvbraZZtKJCH2X1SelWhpkuRiV178ahVjP1AeniEbxWJjlok099YU5LIG1ETPxZh FD1unwjEJ7TK6YqMSNzHEpizGtmdBEjxG1hu8FMOCIYx8ZsbgtlW/c8Gk8avHqA5Ke8+ yDndVUZUHK5UzXl7FjxYENFlHzcSQ/t4J/mlaI5Za1FZ0Yk7NQHXFlC8X8z/Q11AzJCt gjoLsOg9g4Wyz7rfq0+rLv+qjJHG8Q4cf56kMJ8LZv5hVu3KOKXoXzF9OF5ultX+b6Ri gJLWMnpzo/t30YH7xqnOXIdXGYfOxoF0VnfBwKgOll7ZWg0cZN9bpSCe+xTccqlwC66e 4Z5w== X-Forwarded-Encrypted: i=1; AJvYcCUOGUnmq/F7SKSj1PX6tzmOS3tUiYlku9P+TCfaxjKylVy5hdBlBE1qVnqqlwemuoUPcC4cKES5e0fPD+jL@vger.kernel.org, AJvYcCVLicucMIH2FIFu92L3b4ED4QPrXiP7xXGoSRw0Tj5TJZcS4I6iRTWS2gO4EuvO67ldllcZq+p+kBbjd8E=@vger.kernel.org, AJvYcCWK4XfC8j5Rs5g33huPA24pSgkTBFNssqGjdYYpJn9nWwuLOSWpfQy3LzfXU8OlXh4wEtOIH+AK7PV7@vger.kernel.org, AJvYcCXGkRpOZGee0vDGwYeR+9jH0RR0ge71zFOpfh6c+j7/h4IFEQ98t8cRi7oPQfOEICyhxdFrbDSusfdCKA==@vger.kernel.org X-Gm-Message-State: AOJu0YxppDKvK5R19An3uu1LRhXGIsaG6WD5xGQlFE/lZ+M7+OqfX3QF k6g3PZcdqb6lfzDNmMXdEdvkTa2evfvALIb21z/DC1FfhyevM9gbqDr7hQ== X-Google-Smtp-Source: AGHT+IFRkP7GB1jAk+/bySYYgH+rfd+TwNqfybV5zjetRqar9oEdGrxhtk6f5nV9sml1/UsA1eHPaA== X-Received: by 2002:a05:6512:33d2:b0:536:7377:7d23 with SMTP id 2adb3069b0e04-5387755cf84mr5504502e87.40.1727346062520; Thu, 26 Sep 2024 03:21:02 -0700 (PDT) Received: from [127.0.1.1] (mm-20-1-84-93.mgts.dynamic.pppoe.byfly.by. [93.84.1.20]) by smtp.googlemail.com with ESMTPSA id 2adb3069b0e04-537a85ee54esm759071e87.96.2024.09.26.03.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 03:21:01 -0700 (PDT) From: Dzmitry Sankouski Date: Thu, 26 Sep 2024 13:20:22 +0300 Subject: [PATCH v5 5/7] power: supply: max77705: Add charger driver for Maxim 77705 Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240617-starqltechn_integration_upstream-v5-5-e0033f141d17@gmail.com> References: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> In-Reply-To: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> To: Sebastian Reichel , Chanwoo Choi , Krzysztof Kozlowski , Lee Jones , Rob Herring , Conor Dooley , Dmitry Torokhov , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1727346045; l=27129; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=qW9UzfSEpbF4PIRD1MoizEtKKqoEMcUSUJsAac4XSuI=; b=+g6D/tnwf9ASv/6TFYzLmpJre6j/NWR8wa+ZP9z1joHZ+PL5a8466MmemPtpglztLMbhpyoj6 ykWQQ1V5rFsDe8YgkzYkoM/x1c3wjrkhwkc+yVHIJa17lAxHaUtmL1g 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 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 | 585 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/power/max77705_charger.h | 215 ++++++++++++++++++++++++++++++++ 4 files changed, 807 insertions(+) diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index bcfa63fb9f1e..fe84d2004f57 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -573,6 +573,12 @@ config CHARGER_MAX77693 help Say Y to enable support for the Maxim MAX77693 battery charger. +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 8dcb41545317..daa9228fa04b 100644 --- a/drivers/power/supply/Makefile +++ b/drivers/power/supply/Makefile @@ -79,6 +79,7 @@ obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o obj-$(CONFIG_CHARGER_DETECTOR_MAX14656) += max14656_charger_detector.o obj-$(CONFIG_CHARGER_MAX77650) += max77650-charger.o obj-$(CONFIG_CHARGER_MAX77693) += max77693_charger.o +obj-$(CONFIG_CHARGER_MAX77705) += max77705_charger.o obj-$(CONFIG_CHARGER_MAX77976) += max77976_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o diff --git a/drivers/power/supply/max77705_charger.c b/drivers/power/supply/max77705_charger.c new file mode 100644 index 000000000000..77ad85deb794 --- /dev/null +++ b/drivers/power/supply/max77705_charger.c @@ -0,0 +1,585 @@ +// 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 + +static const char *max77705_charger_model = "max77705"; +static const char *max77705_charger_manufacturer = "Maxim Integrated"; + +static enum power_supply_property max77705_charger_props[] = { + 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 = irq_drv_data; + + queue_work(charger->wqueue, &charger->chgin_work); + + return 0; +} + +static const struct regmap_irq max77705_charger_irqs[] = { + { .mask = MAX77705_BYP_IM, }, + { .mask = MAX77705_INP_LIMIT_IM, }, + { .mask = MAX77705_BATP_IM, }, + { .mask = MAX77705_BAT_IM, }, + { .mask = MAX77705_CHG_IM, }, + { .mask = MAX77705_WCIN_IM, }, + { .mask = MAX77705_CHGIN_IM, }, + { .mask = MAX77705_AICL_IM, }, +}; + +static struct regmap_irq_chip max77705_charger_irq_chip = { + .name = "max77705-charger", + .status_base = MAX77705_CHG_REG_INT, + .mask_base = MAX77705_CHG_REG_INT_MASK, + .handle_post_irq = max77705_chgin_irq, + .num_regs = 1, + .irqs = max77705_charger_irqs, + .num_irqs = ARRAY_SIZE(max77705_charger_irqs), +}; + +static int max77705_charger_enable(struct max77705_charger_data *chg) +{ + int rv; + + rv = 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 = 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 = regmap_read(regmap, MAX77705_CHG_REG_INT_OK, &data); + if (ret < 0) + return ret; + + *val = !!(data & MAX77705_CHGIN_OK); + + return 0; +} + +static int max77705_check_battery(struct max77705_charger_data *charger, int *val) +{ + unsigned int reg_data; + unsigned int reg_data2; + struct regmap *regmap = 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 = true; + else + *val = false; + + return 0; +} + +static int max77705_get_charge_type(struct max77705_charger_data *charger, int *val) +{ + struct regmap *regmap = charger->regmap; + unsigned int reg_data; + + regmap_read(regmap, MAX77705_CHG_REG_CNFG_09, ®_data); + if (!MAX77705_CHARGER_CHG_CHARGING(reg_data)) { + *val = POWER_SUPPLY_CHARGE_TYPE_NONE; + return 0; + } + + regmap_read(regmap, MAX77705_CHG_REG_DETAILS_01, ®_data); + reg_data &= MAX77705_CHG_DTLS; + + switch (reg_data) { + case 0x0: + case MAX77705_CHARGER_CONSTANT_CURRENT: + case MAX77705_CHARGER_CONSTANT_VOLTAGE: + *val = POWER_SUPPLY_CHARGE_TYPE_FAST; + return 0; + default: + *val = POWER_SUPPLY_CHARGE_TYPE_NONE; + return 0; + } + + return 0; +} + +static int max77705_get_status(struct max77705_charger_data *charger, int *val) +{ + struct regmap *regmap = charger->regmap; + unsigned int reg_data; + + regmap_read(regmap, MAX77705_CHG_REG_CNFG_09, ®_data); + if (!MAX77705_CHARGER_CHG_CHARGING(reg_data)) { + *val = POWER_SUPPLY_CHARGE_TYPE_NONE; + return 0; + } + + regmap_read(regmap, MAX77705_CHG_REG_DETAILS_01, ®_data); + reg_data &= MAX77705_CHG_DTLS; + + switch (reg_data) { + case 0x0: + case MAX77705_CHARGER_CONSTANT_CURRENT: + case MAX77705_CHARGER_CONSTANT_VOLTAGE: + *val = POWER_SUPPLY_STATUS_CHARGING; + return 0; + case MAX77705_CHARGER_END_OF_CHARGE: + case MAX77705_CHARGER_DONE: + *val = 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 = POWER_SUPPLY_STATUS_NOT_CHARGING; + return 0; + case 0x08: + case 0xA: + case 0xB: + *val = POWER_SUPPLY_STATUS_DISCHARGING; + return 0; + default: + *val = 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 = regmap_read(regmap, MAX77705_CHG_REG_DETAILS_00, &charge_dtls); + if (ret) + return ret; + + charge_dtls = ((charge_dtls & MAX77705_CHGIN_DTLS) >> + MAX77705_CHGIN_DTLS_SHIFT); + + switch (charge_dtls) { + case 0x00: + *value = POWER_SUPPLY_HEALTH_UNDERVOLTAGE; + break; + case 0x01: + *value = POWER_SUPPLY_HEALTH_UNDERVOLTAGE; + break; + case 0x02: + *value = POWER_SUPPLY_HEALTH_OVERVOLTAGE; + break; + case 0x03: + *value = POWER_SUPPLY_HEALTH_GOOD; + break; + default: + return 0; + } + return 0; +} + +static int max77705_get_battery_health(struct max77705_charger_data *charger, + int *value) +{ + struct regmap *regmap = charger->regmap; + unsigned int bat_dtls; + + regmap_read(regmap, MAX77705_CHG_REG_DETAILS_01, &bat_dtls); + bat_dtls = ((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 = 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 = POWER_SUPPLY_HEALTH_DEAD; + break; + case MAX77705_BATTERY_GOOD: + case MAX77705_BATTERY_LOWVOLTAGE: + *value = POWER_SUPPLY_HEALTH_GOOD; + break; + case MAX77705_BATTERY_OVERVOLTAGE: + dev_dbg(charger->dev, "%s: battery ovp\n", __func__); + *value = POWER_SUPPLY_HEALTH_OVERVOLTAGE; + break; + default: + dev_dbg(charger->dev, "%s: battery unknown\n", __func__); + *value = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; + break; + } + + return 0; +} + +static int max77705_get_health(struct max77705_charger_data *charger, int *val) +{ + struct regmap *regmap = charger->regmap; + int ret, is_online = 0; + + ret = max77705_get_online(regmap, &is_online); + if (ret) + return ret; + if (is_online) { + ret = max77705_get_vbus_state(regmap, val); + if (ret || (*val != POWER_SUPPLY_HEALTH_GOOD)) + return ret; + } + return max77705_get_battery_health(charger, val); +} + +static int max77705_get_input_current(struct max77705_charger_data *charger, + int *val) +{ + unsigned int reg_data; + int get_current = 0; + struct regmap *regmap = charger->regmap; + + regmap_read(regmap, + MAX77705_CHG_REG_CNFG_09, ®_data); + + reg_data &= MAX77705_CHG_CHGIN_LIM_MASK; + + if (reg_data <= 3) + get_current = 100; + else if (reg_data >= MAX77705_CHG_CHGIN_LIM_MASK) + get_current = MAX77705_CURRENT_CHGIN_MAX; + else + get_current = (reg_data + 1) * 25; + + *val = get_current; + + return 0; +} + +static int max77705_get_charge_current(struct max77705_charger_data *charger, + int *val) +{ + unsigned int reg_data; + struct regmap *regmap = charger->regmap; + + + regmap_read(regmap, MAX77705_CHG_REG_CNFG_02, ®_data); + reg_data &= MAX77705_CHG_CC; + + *val = reg_data <= 0x2 ? 100 : reg_data * 50; + + return 0; +} + +static int max77705_set_float_voltage(struct max77705_charger_data *charger, + int float_voltage) +{ + int float_voltage_mv; + unsigned int reg_data = 0; + struct regmap *regmap = charger->regmap; + + float_voltage_mv = float_voltage / 1000; + reg_data = float_voltage_mv <= 4000 ? 0x0 : + float_voltage_mv >= 4500 ? 0x23 : + (float_voltage_mv <= 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 *charger, + int *val) +{ + unsigned int reg_data = 0; + struct regmap *regmap = charger->regmap; + + regmap_read(regmap, MAX77705_CHG_REG_CNFG_04, ®_data); + reg_data &= MAX77705_CHG_PRM_MASK; + *val = reg_data <= 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 = power_supply_get_drvdata(psy); + struct regmap *regmap = 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 = charger->bat_info->voltage_max_design_uv; + break; + case POWER_SUPPLY_PROP_MODEL_NAME: + val->strval = max77705_charger_model; + break; + case POWER_SUPPLY_PROP_MANUFACTURER: + val->strval = max77705_charger_manufacturer; + break; + default: + return -EINVAL; + } + return 0; +} + +static const struct power_supply_desc max77705_charger_psy_desc = { + .name = "max77705-charger", + .type = POWER_SUPPLY_TYPE_USB, + .properties = max77705_charger_props, + .num_properties = ARRAY_SIZE(max77705_charger_props), + .get_property = max77705_chg_get_property, +}; + +static void max77705_chgin_isr_work(struct work_struct *work) +{ + struct max77705_charger_data *charger = + 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 = chg->regmap; + + if (power_supply_get_battery_info(chg->psy_chg, &info) < 0) + return; + + chg->bat_info = info; + + // unlock charger setting protect + // slowest LX slope + reg_data = 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 = (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 = (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=5.0V + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_11, MAX77705_VBYPSET_MASK, 0); + + // Switching Frequency : 1.5MHz + regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_08, MAX77705_REG_FSW_MASK, + (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 = {}; + struct max77693_dev *max77705; + struct max77705_charger_data *chg; + struct device *dev, *parent; + struct regmap_irq_chip_data *irq_data; + int ret; + + dev = &pdev->dev; + parent = dev->parent; + max77705 = dev_get_drvdata(parent); + + chg = devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL); + if (!chg) + return -ENOMEM; + + platform_set_drvdata(pdev, chg); + + chg->regmap = max77705->regmap_chg; + if (!chg->regmap) + return -ENODEV; + + chg->dev = dev; + + max77705_charger_irq_chip.irq_drv_data = chg; + ret = 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 = regmap_update_bits(chg->regmap, + MAX77705_CHG_REG_INT_MASK, + MAX77705_CHGIN_IM, 0); + + if (ret) + return ret; + + chg->wqueue = 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 = dev->of_node; + pscfg.drv_data = chg; + + chg->psy_chg = devm_power_supply_register(dev, &max77705_charger_psy_desc, + &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 = platform_get_drvdata(pdev); + + max77705_charger_disable(chg); +} + +static const struct of_device_id max77705_charger_of_match[] = { + { .compatible = "maxim,max77705-charger" }, + { } +}; +MODULE_DEVICE_TABLE(of, max77705_charger_of_match); + +static struct platform_driver max77705_charger_driver = { + .driver = { + .name = "max77705-charger", + .of_match_table = max77705_charger_of_match, + }, + .probe = max77705_charger_probe, + .remove_new = 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/max77705_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=4.5V, UVLO=4.7V +#define MAX77705_VCHGIN_4_5 0 +// REG=4.5V, UVLO=4.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 From patchwork Thu Sep 26 10:20:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 830936 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3ADE91AF4F0; Thu, 26 Sep 2024 10:21:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346070; cv=none; b=Fs4GO9i/AbhQXQLO4HsEVi8CYyFDEZS+QB2GUW+lflbEbO/1TjRMKtGVwKtNsebCPrcP1jX34gK79Mw4BqRdfBVRZDZMeEgu9bx5O05gv7n0iDkvg+xos0KmrZnYZohp7IqKdts0KuQPFyECc0jnjFJCPAhbFD+jT2tHbJd8+4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346070; c=relaxed/simple; bh=pmvkF5DtT2tmmiaElv+VfSPDpulxzT5Dno7m2B4J74Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RSxCDawrjIEEYvtGlYuqqL+1OtLtwbEoMtRFgW5FFIT2rgtzs27OCksKIOIZAo837wJ9skGXXXSEA76PoLmg0fsr/PD2MFjt1qZ2sq7fxPei4Ns3AVKsbh+/h7Xg6YnuZraJ7jLF0H/zTD6gYbsZZj4Dv5rdgrG2oUzk4PGV0Dg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dGl/gtdE; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dGl/gtdE" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5356aa9a0afso1206890e87.2; Thu, 26 Sep 2024 03:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727346066; x=1727950866; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DYPbY+ziBAPO5jR7eDpx5rUqOZ3MUmEYqNjEU7hZvD8=; b=dGl/gtdEDGc3vi8BNtCdHiAfGr3IE53Tkv/XswqdE85IyjDXjm50QEV+Cl/Q4V9f5T 9XZ63tfrmCiowCwZbxnHMILkruNnaUHmn4PL2vwZ3EM/mCRxbss8QmxZgGZd0BJYutnp xX0yzXgulpOBEVSfLfBDvIYEnNlPaIyuy7zBlffL7WeSYeACvq3rbzJkH5atSrFFXIBq Sl7Z+6rRPWKi/j1YgHYewM7mVipZ2z614oRToNnKv4y2QDS5O8YOke34sH5AwY6dfXyG ocO9b/YziHCK4U7ecOweS7n9taXjloaz8F00v1Joocghi6plBW+yJm8VlJ5gZneuRT3N PObw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727346066; x=1727950866; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DYPbY+ziBAPO5jR7eDpx5rUqOZ3MUmEYqNjEU7hZvD8=; b=Mtb6sbXv1JZtmysK5OcmcQWMhxBbT7LjEZYrv3FDN4g6uiPOAVb5vtGM17vxUgRJZ+ t8Zs/8l8XmcohsmBgOM7dsnyA3D+UVHqpVkoUkXb7YxOfJdWeiRQhxaux1auglDHbyxm BQGZ8Ge+L3JSxgGuTrSPROHHLe0ctHdxtvtfTkiJezAHywiAefDlFhImzj4cojiXKFec 5ZI+ZeNGOW08M4uSgpy92WUw86mQ8uaKjJm38/Xqwqt+lQDnx2qB/LpmCarAD/P7uj7M bB0Qdu7+k7FcvImy/JHskwYeToYB8YwhBZg32A3TXrgNKNCULkjE1U579Yuw4tftdgo6 8+2g== X-Forwarded-Encrypted: i=1; AJvYcCUcJrcIGQMNXmPagattEy5Wy7UE7Ca9B+waa8aly3DLxtf07fQTDEbtVK1KGATI8uwdpEC//vTaTYlpu0U=@vger.kernel.org, AJvYcCV335hR4LEwaQ3k7MdI6dn56tnmVKAZuZqoEJbuFwAgeJa3XTl7xzzmjacJkAJvCkcGHyXs0vzj9PS5+YKi@vger.kernel.org, AJvYcCWTM8ayM0eaDb0gxCTmhA4trqy1z1lud0/oKEaMODK9DTrXR/pvt4RnrmpURGfH6Ml+F8WbpN7GWXYw@vger.kernel.org, AJvYcCX7TkTbhzllMxYaupXqgfu2KGXnVXFxgZNW2T4c/B6x1NtHFrX0ESTl0rpc6W8WL2I9YCWihKctw43IGg==@vger.kernel.org X-Gm-Message-State: AOJu0Yz9E1E83wppdzOEZKRgFYLfGsSl0yfeP4EwzDlNW7BCF5egjx2X 0jof1tC5gA8nuulYbR7ppJ0zAfJ7oz/nibb2xrxCDzY6EqI6E+BI X-Google-Smtp-Source: AGHT+IGeFagfipeL/Z+MsN7DcEomqRhLCEAe4WsvE5ifV6/I97KYHVROeaZIqa/JRAm15MzwriKdrg== X-Received: by 2002:a05:6512:2256:b0:535:6951:9e1c with SMTP id 2adb3069b0e04-538704969e9mr5244605e87.15.1727346065851; Thu, 26 Sep 2024 03:21:05 -0700 (PDT) Received: from [127.0.1.1] (mm-20-1-84-93.mgts.dynamic.pppoe.byfly.by. [93.84.1.20]) by smtp.googlemail.com with ESMTPSA id 2adb3069b0e04-537a85ee54esm759071e87.96.2024.09.26.03.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 03:21:04 -0700 (PDT) From: Dzmitry Sankouski Date: Thu, 26 Sep 2024 13:20:23 +0300 Subject: [PATCH v5 6/7] power: supply: max77705: Add fuel gauge driver for Maxim 77705 Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240617-starqltechn_integration_upstream-v5-6-e0033f141d17@gmail.com> References: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> In-Reply-To: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> To: Sebastian Reichel , Chanwoo Choi , Krzysztof Kozlowski , Lee Jones , Rob Herring , Conor Dooley , Dmitry Torokhov , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1727346045; l=15093; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=pmvkF5DtT2tmmiaElv+VfSPDpulxzT5Dno7m2B4J74Q=; b=s5U8jxzTSTU9pUKmRhnD0k3SXD7RZBKGBCLRnRY37IcQE9m/ywVGgg+Lxjz3vldh3vhLOqI+8 o5tSYqMMbqPCgapkYs1l2jpT0hlyj0RJhhya2TTIfu5gA73TY4y/Ph0 X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Add driver for Maxim 77705 fuel gauge (part of max77705 MFD driver) providing power supply class information to userspace. The driver is configured through DTS (battery and system related settings). Signed-off-by: Dzmitry Sankouski --- Changes for v5: - fix license - use same hardware name in Kconfig and module descriptions - fix email, and module author Changes for v4: - rework driver from scratch - change word delimiters in filenames to "_" - remove debugfs code - cleanup header --- drivers/power/supply/Kconfig | 7 ++ drivers/power/supply/Makefile | 1 + drivers/power/supply/max77705_fuel_gauge.c | 348 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/power/max77705_fuelgauge.h | 65 ++++++++++++++++ 4 files changed, 421 insertions(+) diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index fe84d2004f57..7c16403c263d 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -579,6 +579,13 @@ config CHARGER_MAX77705 help Say Y to enable support for the Maxim MAX77705 battery charger. +config FUEL_GAUGE_MAX77705 + tristate "Maxim MAX77705 fuel gauge driver" + depends on MFD_MAX77705 + default n + help + Say Y to enable support for MAXIM MAX77705 fuel gauge driver. + config CHARGER_MAX77976 tristate "Maxim MAX77976 battery charger driver" depends on I2C diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile index daa9228fa04b..b949600a6207 100644 --- a/drivers/power/supply/Makefile +++ b/drivers/power/supply/Makefile @@ -80,6 +80,7 @@ obj-$(CONFIG_CHARGER_DETECTOR_MAX14656) += max14656_charger_detector.o obj-$(CONFIG_CHARGER_MAX77650) += max77650-charger.o obj-$(CONFIG_CHARGER_MAX77693) += max77693_charger.o obj-$(CONFIG_CHARGER_MAX77705) += max77705_charger.o +obj-$(CONFIG_FUEL_GAUGE_MAX77705) += max77705_fuel_gauge.o obj-$(CONFIG_CHARGER_MAX77976) += max77976_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o diff --git a/drivers/power/supply/max77705_fuel_gauge.c b/drivers/power/supply/max77705_fuel_gauge.c new file mode 100644 index 000000000000..bd3dfcf8fdda --- /dev/null +++ b/drivers/power/supply/max77705_fuel_gauge.c @@ -0,0 +1,348 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (C) 2024 Dzmitry Sankouski +// +// Fuel gauge driver for MAXIM 77705 charger/power-supply. + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const char *max77705_fuelgauge_model = "max77705"; +static const char *max77705_fuelgauge_manufacturer = "Maxim Integrated"; + +static enum power_supply_property max77705_fuelgauge_props[] = { + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_VOLTAGE_OCV, + POWER_SUPPLY_PROP_VOLTAGE_AVG, + POWER_SUPPLY_PROP_CURRENT_NOW, + POWER_SUPPLY_PROP_CURRENT_AVG, + POWER_SUPPLY_PROP_CHARGE_NOW, + POWER_SUPPLY_PROP_CHARGE_FULL, + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, + POWER_SUPPLY_PROP_CAPACITY, + POWER_SUPPLY_PROP_TEMP, + POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, + POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, +}; + +static int max77705_fg_read_reg(struct max77705_fuelgauge_data *fuelgauge, + unsigned int reg, unsigned int *val) +{ + struct regmap *regmap = fuelgauge->regmap; + u8 data[2]; + int ret; + + ret = regmap_noinc_read(regmap, reg, data, sizeof(data)); + if (ret < 0) + return ret; + + *val = (data[1] << 8) + data[0]; + + return 0; +} + +static int max77705_fg_read_temp(struct max77705_fuelgauge_data *fuelgauge, + int *val) +{ + struct regmap *regmap = fuelgauge->regmap; + u8 data[2] = { 0, 0 }; + int ret, temperature = 0; + + ret = regmap_noinc_read(regmap, TEMPERATURE_REG, data, sizeof(data)); + if (ret < 0) + return ret; + + if (data[1] & BIT(7)) + temperature = ((~(data[1])) & 0xFF) + 1; + else + temperature = data[1] & 0x7f; + + temperature *= 10; + temperature += data[0] * 10 / 256; + *val = temperature; + + return 0; +} + +static int max77705_fg_check_battery_present(struct max77705_fuelgauge_data + *fuelgauge, int *val) +{ + struct regmap *regmap = fuelgauge->regmap; + u8 status_data[2]; + int ret; + + ret = regmap_noinc_read(regmap, STATUS_REG, status_data, sizeof(status_data)); + if (ret < 0) + return ret; + + *val = !(status_data[0] & MAX77705_BAT_ABSENT_MASK); + + return 0; +} + +static int max77705_battery_get_status(struct max77705_fuelgauge_data *fuelgauge, + int *val) +{ + int current_now; + int am_i_supplied; + int ret; + unsigned int soc_rep; + + am_i_supplied = power_supply_am_i_supplied(fuelgauge->psy_fg); + if (am_i_supplied) { + if (am_i_supplied == -ENODEV) { + dev_err(fuelgauge->dev, + "power supply not found, fall back to current-based status checking\n"); + } else { + *val = POWER_SUPPLY_STATUS_CHARGING; + return 0; + } + } + ret = max77705_fg_read_reg(fuelgauge, SOCREP_REG, &soc_rep); + if (ret) + return ret; + + if (soc_rep < 100) { + ret = max77705_fg_read_reg(fuelgauge, CURRENT_REG, ¤t_now); + if (ret) + return ret; + + if (current_now > 0) + *val = POWER_SUPPLY_STATUS_CHARGING; + else if (current_now < 0) + *val = POWER_SUPPLY_STATUS_DISCHARGING; + else + *val = POWER_SUPPLY_STATUS_NOT_CHARGING; + } else { + *val = POWER_SUPPLY_STATUS_FULL; + } + + return 0; +} + +static void max77705_unit_adjustment(struct max77705_fuelgauge_data *fuelgauge, + enum power_supply_property psp, + union power_supply_propval *val) +{ + const unsigned int base_unit_conversion = 1000; + + switch (psp) { + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + case POWER_SUPPLY_PROP_VOLTAGE_OCV: + case POWER_SUPPLY_PROP_VOLTAGE_AVG: + val->intval = max77705_fg_vs_convert(val->intval); + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: + case POWER_SUPPLY_PROP_CURRENT_AVG: + val->intval = max77705_fg_cs_convert(val->intval, + fuelgauge->rsense_conductance); + break; + case POWER_SUPPLY_PROP_CHARGE_NOW: + case POWER_SUPPLY_PROP_CHARGE_FULL: + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + val->intval *= base_unit_conversion; + break; + case POWER_SUPPLY_PROP_CAPACITY: + val->intval = min(val->intval, 100); + break; + default: + dev_dbg(fuelgauge->dev, + "%s: no need for unit conversion %d\n", __func__, psp); + } +} + +static int max77705_fg_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct max77705_fuelgauge_data *fuelgauge = + power_supply_get_drvdata(psy); + int ret; + + switch (psp) { + case POWER_SUPPLY_PROP_STATUS: + ret = max77705_battery_get_status(fuelgauge, &val->intval); + break; + case POWER_SUPPLY_PROP_PRESENT: + ret = max77705_fg_check_battery_present(fuelgauge, &val->intval); + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + ret = max77705_fg_read_reg(fuelgauge, VCELL_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_VOLTAGE_OCV: + ret = max77705_fg_read_reg(fuelgauge, VFOCV_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_VOLTAGE_AVG: + ret = max77705_fg_read_reg(fuelgauge, AVR_VCELL_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: + ret = max77705_fg_read_reg(fuelgauge, CURRENT_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CURRENT_AVG: + ret = max77705_fg_read_reg(fuelgauge, AVG_CURRENT_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CHARGE_NOW: + ret = max77705_fg_read_reg(fuelgauge, REMCAP_REP_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CHARGE_FULL: + ret = max77705_fg_read_reg(fuelgauge, FULLCAP_REP_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + ret = max77705_fg_read_reg(fuelgauge, DESIGNCAP_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CAPACITY: + ret = max77705_fg_read_reg(fuelgauge, SOCREP_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_TEMP: + ret = max77705_fg_read_temp(fuelgauge, &val->intval); + break; + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW: + ret = max77705_fg_read_reg(fuelgauge, TIME_TO_EMPTY_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: + ret = max77705_fg_read_reg(fuelgauge, TIME_TO_FULL_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_CYCLE_COUNT: + ret = max77705_fg_read_reg(fuelgauge, CYCLES_REG, &val->intval); + break; + case POWER_SUPPLY_PROP_MODEL_NAME: + val->strval = max77705_fuelgauge_model; + break; + case POWER_SUPPLY_PROP_MANUFACTURER: + val->strval = max77705_fuelgauge_manufacturer; + break; + default: + return -EINVAL; + } + + if (ret) + return ret; + + max77705_unit_adjustment(fuelgauge, psp, val); + + return 0; +} + +static const struct power_supply_desc max77705_fg_desc = { + .name = "max77705-fuel-gauge", + .type = POWER_SUPPLY_TYPE_BATTERY, + .properties = max77705_fuelgauge_props, + .num_properties = ARRAY_SIZE(max77705_fuelgauge_props), + .get_property = max77705_fg_get_property, +}; + +static int max77705_fg_set_charge_design(struct regmap *regmap, int value) +{ + u8 data[2]; + int value_mah; + + value_mah = value / 1000; + data[0] = value_mah & 0xFF; + data[1] = (value_mah >> 8) & 0xFF; + + return regmap_noinc_write(regmap, DESIGNCAP_REG, data, sizeof(data)); +} + +static int max77705_battery_settings(struct max77705_fuelgauge_data *fuelgauge) +{ + struct power_supply_battery_info *info; + struct regmap *regmap = fuelgauge->regmap; + int ret; + + ret = power_supply_get_battery_info(fuelgauge->psy_fg, &info); + if (ret) + return ret; + + fuelgauge->bat_info = info; + + if (info->energy_full_design_uwh != info->charge_full_design_uah) { + if (info->charge_full_design_uah == -EINVAL) + dev_warn(fuelgauge->dev, "missing battery:charge-full-design-microamp-hours\n"); + ret = max77705_fg_set_charge_design(regmap, info->charge_full_design_uah); + } + + return ret; +} + +static int max77705_fuelgauge_parse_dt(struct max77705_fuelgauge_data + *fuelgauge) +{ + struct device *dev = fuelgauge->dev; + struct device_node *np = dev->of_node; + int ret; + unsigned int rsense; + + if (!np) { + dev_err(dev, "no fuelgauge OF node\n"); + return -EINVAL; + } + ret = of_property_read_u32(np, "shunt-resistor-micro-ohms", + &rsense); + if (ret < 0) { + dev_warn(dev, "No shunt-resistor-micro-ohms property, assume default\n"); + fuelgauge->rsense_conductance = 100; + } else + fuelgauge->rsense_conductance = 1000000 / rsense; /* rsense conductance in Ohm^-1 */ + + return 0; +} + +static int max77705_fuelgauge_probe(struct platform_device *pdev) +{ + struct max77693_dev *max77705 = dev_get_drvdata(pdev->dev.parent); + struct max77705_fuelgauge_data *fuelgauge; + struct power_supply_config fuelgauge_cfg = { }; + struct device *dev = &pdev->dev; + int ret = 0; + + fuelgauge = devm_kzalloc(dev, sizeof(*fuelgauge), GFP_KERNEL); + if (!fuelgauge) + return -ENOMEM; + + fuelgauge->dev = dev; + fuelgauge->regmap = max77705->regmap_fg; + + ret = max77705_fuelgauge_parse_dt(fuelgauge); + if (ret < 0) + return ret; + + fuelgauge_cfg.drv_data = fuelgauge; + fuelgauge_cfg.of_node = fuelgauge->dev->of_node; + + fuelgauge->psy_fg = devm_power_supply_register(&pdev->dev, + &max77705_fg_desc, + &fuelgauge_cfg); + + if (IS_ERR(fuelgauge->psy_fg)) + return PTR_ERR(fuelgauge->psy_fg); + + return max77705_battery_settings(fuelgauge); +} + +static const struct of_device_id max77705_fg_of_match[] = { + { .compatible = "maxim,max77705-fuel-gauge" }, + { } +}; +MODULE_DEVICE_TABLE(of, max77705_fg_of_match); + +static struct platform_driver max77705_fuelgauge_driver = { + .driver = { + .name = "max77705-fuel-gauge", + .of_match_table = max77705_fg_of_match, + }, + .probe = max77705_fuelgauge_probe, +}; +module_platform_driver(max77705_fuelgauge_driver); + +MODULE_DESCRIPTION("Maxim MAX77705 Fuel Gauge Driver"); +MODULE_AUTHOR("Dzmitry Sankouski "); +MODULE_LICENSE("GPL"); diff --git a/include/linux/power/max77705_fuelgauge.h b/include/linux/power/max77705_fuelgauge.h new file mode 100644 index 000000000000..dfd91f097817 --- /dev/null +++ b/include/linux/power/max77705_fuelgauge.h @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +// +// Copyright (C) 2024 Dzmitry Sankouski +// +// Fuel gauge driver header for MAXIM 77705 charger/power-supply. + +#ifndef __MAX77705_FUELGAUGE_H +#define __MAX77705_FUELGAUGE_H __FILE__ + +#include +#include +#include + +#define ALERT_EN 4 +#define CAPACITY_SCALE_DEFAULT_CURRENT 1000 +#define CAPACITY_SCALE_HV_CURRENT 600 +// Current and capacity values are displayed as a voltage +// and must be divided by the sense resistor to determine Amps or Amp-hours. +// This should be applied to all current, charge, energy registers, +// except ModelGauge m5 Algorithm related ones. +// current sense resolution +#define MAX77705_FG_CS_ADC_RESOLUTION 15625 // 1.5625 microvolts +// voltage sense resolution +#define MAX77705_FG_VS_ADC_RESOLUTION 78125 // 78.125 microvolts +// CONFIG_REG register +#define MAX77705_SOC_ALERT_EN_MASK BIT(2) +// When set to 1, external temperature measurements should be written from the host +#define MAX77705_TEX_MASK BIT(8) +// Enable Thermistor +#define MAX77705_ETHRM_MASK BIT(5) +// CONFIG2_REG register +#define MAX77705_AUTO_DISCHARGE_EN_MASK BIT(9) +// STATUS_REG register +#define MAX77705_BAT_ABSENT_MASK BIT(3) + +// @brief Convert voltage register value to micro volts +// @param reg_val - register value +// @return voltage in micro Volts +inline u64 max77705_fg_vs_convert(u16 reg_val) +{ + u64 result = (u64)reg_val * MAX77705_FG_VS_ADC_RESOLUTION; + + return result / 1000; +} + +// @brief Convert current register value to micro volts +// @param reg_val - register value +// @param rsense_conductance - current sense resistor conductance in Ohm^-1 +// @return voltage in micro Volts +inline s32 max77705_fg_cs_convert(s16 reg_val, u32 rsense_conductance) +{ + s64 result = (s64)reg_val * rsense_conductance * MAX77705_FG_CS_ADC_RESOLUTION; + + return result / 10000; +} + +struct max77705_fuelgauge_data { + struct device *dev; + struct regmap *regmap; + struct power_supply *psy_fg; + struct power_supply_battery_info *bat_info; + u32 rsense_conductance; +}; + +#endif // __MAX77705_FUELGAUGE_H From patchwork Thu Sep 26 10:20:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 831711 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 5410F1AF4F2; Thu, 26 Sep 2024 10:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346072; cv=none; b=TvgSW+KqimuiTERNVyB5AnrO8rxIJ3S0QMm9wTpJZx160l3urE+6Mze1HO5SyFKI/F2lMU8f5azvIzUS8EHzZWC0MoIGmtPVUvFPYfcvy2fPL8jV4aFs0cxg33WMNcsnL+r98gsZk2eZrJxgZSHTouUpHeoGXEMMrgN1X3DK1/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727346072; c=relaxed/simple; bh=ggv866krfI3IOdjHfV2G9/rH2G2ucI4aiHOZpBnyZCs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Z+u4/A9QLkvvwH9dPKy5OWJ2o0hyJN4zLeD/8AI79a0yOCGWpwziZuIgnZdeF+hr5ZVb8Rn4Yri8sHkP4AIfaN4h3BzHeuZRmaQHhqDKEdbhKR6Qh/1wyXPiAvZsouuJJP+gpUYVJ1Hfsdu95Ce2eceTSBSfG9LStsiekp9Yh74= 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=T6pgX5qs; arc=none smtp.client-ip=209.85.208.182 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="T6pgX5qs" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2f75aaaade6so9267811fa.1; Thu, 26 Sep 2024 03:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727346068; x=1727950868; 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=hctV0d113DynEI0DnnWoIOQtcCpUeJRxl1mrlI4KZWs=; b=T6pgX5qsmviT6E3zGlRaPbFQ9lM2lN+O0xyy344m/+kDDC0CUC7FvF9rw/6yMgy4jG i4aWuWHwGD8tLm08bQUJHbzuM4lbZExVekm29cIl98eXYjOaGNzX3THbgV6XyA3Y+nkS GebDOrgqH0qsVGKhaGapGmPkL5KrvaQFJXP0TUgRoqVK0017/r+S6ie8XfX2+UkUTNC4 /eWT/dxpsTJ7frXKw444GfHsHfZJEO5/hNbk7en7+hrJQi+RcEGrpyPgSeCcfDpiN+sX rRNY4F8FNFWTADJydMmKHnFLAIfOB+F4DejJbxrDUYMaIjLFJqs/cvDvSKN7d9YLWdr9 0WrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727346068; x=1727950868; 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=hctV0d113DynEI0DnnWoIOQtcCpUeJRxl1mrlI4KZWs=; b=rxwx6HJ0URzg3DNL6kec44sZivWNXdUetM+wSsS21yCMMqljyhG3NejeO27lxo4rre dW0okqOd5xhwfNqnr9qx2F6W7CD4R3kr9ulxTJfBBvgljm8sJwDn2mwumHsJHq8InkHj vsq9f/ZLl92FK8UtOaV5nkWElQ3VwJn+XVbtdm4Zy7uFxjYuGRCbefpYkzyw0s4K/S59 c3xZg7a6koTorFFbpwLfu/qTUmnhMkz+KRxqaUrEhi/0G4SNkA60F1XvUytp9XM6s/01 c5FuONjUOvTMpXG0+/+LhFWnTrBQhZQ9eZEjDc+6NOynw4gDT0lAtWdvnzlB2ZzVD6fY drWg== X-Forwarded-Encrypted: i=1; AJvYcCVa/6SQpA/EJGLpdGvp49wSNcCyOhhqc1kD7Z41/1dIE+9PP7g/IAPeDFZMSjDJ40WUJv3nya0GEljXWw==@vger.kernel.org, AJvYcCVsV2n3fERthcegi7nD4MjwyC/z66LHGYnsv0J7yKgk2EskZezoJMh/mRJPgrefNAfUJJS599EIU3s2h2+t@vger.kernel.org, AJvYcCWbAPGXX2ynsLdY7cXXJZZjBr5ZZaoTMSbmF0WXU9KmAF4kuToYj2XKx9J+7bmEKHj+TWsXVeShstTkG9k=@vger.kernel.org, AJvYcCXguUcx3MrsxCTeRv16qeQlfSBeyoPEJeLsJjeuEipTTLeJkQdp9ceMwV1qSkut7aIL/XfCeD/Q11VQ@vger.kernel.org X-Gm-Message-State: AOJu0Yyy6MxVRUAicozw1eiktVvnhhSJQb1UfMoPzDSbU2syysA85LHH aSX5slNaDotpZLMm/eMiYXfyZzeMqG201sPfFJUJoO/SbCkHB5HSDzJY/Q== X-Google-Smtp-Source: AGHT+IG6XPSvZPE2s/YeanEABUzbGl4MV75iMai42OiVbePz66YsGF0V3Wbw2X0jmspS4SXFZgfjPw== X-Received: by 2002:a05:6512:128b:b0:536:54df:bffa with SMTP id 2adb3069b0e04-5387755cc03mr3767539e87.45.1727346068226; Thu, 26 Sep 2024 03:21:08 -0700 (PDT) Received: from [127.0.1.1] (mm-20-1-84-93.mgts.dynamic.pppoe.byfly.by. [93.84.1.20]) by smtp.googlemail.com with ESMTPSA id 2adb3069b0e04-537a85ee54esm759071e87.96.2024.09.26.03.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 03:21:06 -0700 (PDT) From: Dzmitry Sankouski Date: Thu, 26 Sep 2024 13:20:24 +0300 Subject: [PATCH v5 7/7] leds: max77705: Add LEDs support Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240617-starqltechn_integration_upstream-v5-7-e0033f141d17@gmail.com> References: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> In-Reply-To: <20240617-starqltechn_integration_upstream-v5-0-e0033f141d17@gmail.com> To: Sebastian Reichel , Chanwoo Choi , Krzysztof Kozlowski , Lee Jones , Rob Herring , Conor Dooley , Dmitry Torokhov , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1727346045; l=6867; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=ggv866krfI3IOdjHfV2G9/rH2G2ucI4aiHOZpBnyZCs=; b=e9Kp/kKXhBaZIpJZZafLyD334j2QBxRMpGXnVg5em2noLh44KorysHU2oG+7BPIxs19t+cIV/ 0ejLd2uDK3BCZ69xMcNeGAjuQuHvWcqd1VB3n8O06ajSMZ6najNEFHU 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 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 | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 165 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index e45bbafbb938..8f26416617a4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14077,6 +14077,7 @@ F: drivers/*/max14577*.c F: drivers/*/max77686*.c F: drivers/*/max77693*.c F: drivers/*/max77705*.c +F: drivers/leds/leds-max77705.c F: drivers/clk/clk-max77686.c F: drivers/extcon/extcon-max14577.c F: drivers/extcon/extcon-max77693.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index b784bb74a837..a8492623caa4 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. +config LEDS_MAX77705 + tristate "LED support for Maxim MAX77705 PMIC" + depends on MFD_MAX77705 && LEDS_CLASS && I2C + help + LED driver for MAX77705 MFD chip 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) += leds-lp8860.o obj-$(CONFIG_LEDS_LT3593) += leds-lt3593.o obj-$(CONFIG_LEDS_MAX5970) += leds-max5970.o obj-$(CONFIG_LEDS_MAX77650) += leds-max77650.o +obj-$(CONFIG_LEDS_MAX77705) += leds-max77705.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.o obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o diff --git a/drivers/leds/leds-max77705.c b/drivers/leds/leds-max77705.c new file mode 100644 index 000000000000..50af81fb7324 --- /dev/null +++ b/drivers/leds/leds-max77705.c @@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Based on leds-max77650 driver: +// Copyright (C) 2018 BayLibre SAS +// Author: Bartosz Golaszewski +// +// LED driver for MAXIM 77705 MFD. +// 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 = max77705_to_led(cdev); + int value, on_value, off_value; + + on_value = (((*delay_on < 100) ? 0 : + (*delay_on < 500) ? *delay_on/100 - 1 : + (*delay_on < 3250) ? (*delay_on - 500) / 250 + 4 : 15) << 4); + off_value = ((*delay_off < 1) ? 0x00 : + (*delay_off < 500) ? 0x01 : + (*delay_off < 5000) ? *delay_off / 500 : + (*delay_off < 8000) ? (*delay_off - 5000) / 1000 + 10 : + (*delay_off < 12000) ? (*delay_off - 8000) / 2000 + 13 : 15); + value = 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 = max77705_to_led(cdev); + int ret; + unsigned long blink_default = 0; + + if (brightness == LED_OFF) { + // Flash OFF + ret = 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 = regmap_write(led->regmap, + led->reg_brightness, brightness); + if (ret < 0) + return ret; + + ret = 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 fwnode_handle *child; + struct max77705_led *leds, *led; + struct device *dev; + struct regmap *map; + int rv, num_leds; + u32 reg; + + dev = &pdev->dev; + + leds = devm_kcalloc(dev, sizeof(*leds), + MAX77705_LED_NUM_LEDS, GFP_KERNEL); + if (!leds) + return -ENOMEM; + + map = dev_get_regmap(dev->parent, NULL); + if (!map) + return -ENODEV; + + num_leds = device_get_child_node_count(dev); + if (!num_leds || num_leds > MAX77705_LED_NUM_LEDS) + return -ENODEV; + + device_for_each_child_node(dev, child) { + struct led_init_data init_data = {}; + + rv = fwnode_property_read_u32(child, "reg", ®); + if (rv || reg >= MAX77705_LED_NUM_LEDS) { + rv = -EINVAL; + goto err_node_put; + } + + led = &leds[reg]; + led->regmap = map; + led->reg_brightness = MAX77705_RGBLED_REG_LED0BRT + reg; + led->en_shift = 2 * reg; + led->cdev.brightness_set_blocking = max77705_led_brightness_set; + led->cdev.blink_set = max77705_rgb_blink; + led->cdev.max_brightness = MAX77705_LED_MAX_BRIGHTNESS; + + init_data.fwnode = child; + init_data.devicename = "max77705"; + + rv = devm_led_classdev_register_ext(dev, &led->cdev, + &init_data); + if (rv) + goto err_node_put; + + rv = max77705_led_brightness_set(&led->cdev, LED_OFF); + if (rv) + goto err_node_put; + } + + return 0; +err_node_put: + fwnode_handle_put(child); + return rv; +} + +static const struct of_device_id max77705_led_of_match[] = { + { .compatible = "maxim,max77705-led" }, + { } +}; +MODULE_DEVICE_TABLE(of, max77705_led_of_match); + +static struct platform_driver max77705_led_driver = { + .driver = { + .name = "max77705-led", + .of_match_table = max77705_led_of_match, + }, + .probe = max77705_led_probe, +}; +module_platform_driver(max77705_led_driver); + +MODULE_DESCRIPTION("Maxim MAX77705 LED driver"); +MODULE_AUTHOR("Dzmitry Sankouski "); +MODULE_LICENSE("GPL");