From patchwork Fri Sep 15 12:45:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 723429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2B0BEE645A for ; Fri, 15 Sep 2023 12:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235079AbjIOMpc (ORCPT ); Fri, 15 Sep 2023 08:45:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235034AbjIOMp0 (ORCPT ); Fri, 15 Sep 2023 08:45:26 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC73A189 for ; Fri, 15 Sep 2023 05:45:21 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-50098cc8967so3392183e87.1 for ; Fri, 15 Sep 2023 05:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694781920; x=1695386720; 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=XWXo5chhD5Q8zfXo4/pVSr8fA6rgWTQ7OZCsmmyvZ+U=; b=iHSSIRsoS/05tM+Xw7F+5LkCbyKRMHN94Wc+ZtHDsO+TRbWhSPkeVmswNNZUkYsc2S 5cs4ZXrWCeeZgnmiVHoCIU8fyaLkyn6CW/oHhmmeEeopkEpClJfnb9fciaAedSCK8Th/ IldwFkqvM01z4LdmVJ16EwSVk+1fXKE2w1F92tTovJ+cmGtxBw4Hpo+7NxyRDAKAtpZi s1hC6GsBfxQEKeBPzoGAm+jhSbepnKTNxBhI2iC9x1WqADlKspNLKFyuGqEABaz7ZvNE QOGxpkq1jIwXFcenxA8j32Y8C7W2mxFnYOQMhsbxSwFVB1utqM+wIzep6BLE838WQ8l2 5bOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694781920; x=1695386720; 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=XWXo5chhD5Q8zfXo4/pVSr8fA6rgWTQ7OZCsmmyvZ+U=; b=e+iT9deJ+ZFm+3TxWfEfQiBrCOXYoEpCzJXF7Cr3whbhtVvzlcz42SuCa85lq+L34q UCxvj3WE3nJow9gTw/gFW/iuCJDdGR6juBOdg3qZ6d9x87VbDfvAb1vRt/VezTOZktKG mLeSrCyOauyeWWwytbedJ17QEFrnOl733SZdnPBP4YzUtU3YWjcM2omb4fwSaBf4lBY4 cbaPex20zu9R95/wf8fKRtEhpAZNL2db3F4c1lEkBMy9NodEofiCBcoNaK47+MBiFjCW Ct2edyYMBjnmHB9xQhsmCSXB5iE6Zo/hqrcc2SzfPT1e78F4+LIz3mdGLicd7VqDjSFc eF0A== X-Gm-Message-State: AOJu0YwGdS8tR4xyJK4xHX4oWU4A91GSumNQlOPtXz5JY4O7ERn2MRlW OxMM+jsioULycysnntCCsvpJrw== X-Google-Smtp-Source: AGHT+IGdDMpoIKg0YKx6oLLJBHuXrxtHb94NpjAH2/YLPOHxwc8J56huhdNfmaLlyugR7ZHihneDZQ== X-Received: by 2002:ac2:4d8b:0:b0:500:8022:3dc7 with SMTP id g11-20020ac24d8b000000b0050080223dc7mr1384525lfe.10.1694781920066; Fri, 15 Sep 2023 05:45:20 -0700 (PDT) Received: from [10.167.154.1] ([2a00:f41:cbe:bc7d:62a6:5d09:5ba7:be5b]) by smtp.gmail.com with ESMTPSA id f19-20020ac25333000000b004fe37199b87sm624752lfh.156.2023.09.15.05.45.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:45:19 -0700 (PDT) From: Konrad Dybcio Date: Fri, 15 Sep 2023 14:45:15 +0200 Subject: [PATCH v4 1/3] dt-bindings: vendor-prefixes: Add Mitsumi Electric Co., Ltd. MIME-Version: 1.0 Message-Id: <20230621-topic-mm8013-v4-1-975aecd173ed@linaro.org> References: <20230621-topic-mm8013-v4-0-975aecd173ed@linaro.org> In-Reply-To: <20230621-topic-mm8013-v4-0-975aecd173ed@linaro.org> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sebastian Reichel , Konrad Dybcio Cc: Marijn Suijten , Rob Herring , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Konrad Dybcio , Krzysztof Kozlowski X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1694781917; l=1125; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=A4edAPC9JkBqokj8iLNvPGCrxmBfeXMUhLTyoYd19k8=; b=SPPfJxzzjjn/0ariy8yePAF81eYjb0mRfNcN+r5HqRz3TC/meu7CZoD605+xRzr3LPtoGDs5A 7y3ap6quMxDA4a2vRNzfmz+1wb09t/gp9Cs0QH4IlwHqjRzAzhJFnjp X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Mitsumi was [1] a Japanese company making various electronics devices and components. They've merged into a new entity, MinebeaMitsumi in 2017. Their current main page is available at [2] [1] https://en.wikipedia.org/wiki/Mitsumi_Electric [2] https://product.minebeamitsumi.com/en/ Acked-by: Krzysztof Kozlowski Signed-off-by: Konrad Dybcio --- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml index 573578db9509..565b13fb429d 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -871,6 +871,8 @@ patternProperties: description: MiraMEMS Sensing Technology Co., Ltd. "^mitsubishi,.*": description: Mitsubishi Electric Corporation + "^mitsumi,.*": + description: Mitsumi Electric Co., Ltd. "^mixel,.*": description: Mixel, Inc. "^miyoo,.*": From patchwork Fri Sep 15 12:45:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 723845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B282DEE645B for ; Fri, 15 Sep 2023 12:45:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235089AbjIOMpd (ORCPT ); Fri, 15 Sep 2023 08:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235023AbjIOMp3 (ORCPT ); Fri, 15 Sep 2023 08:45:29 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18C2D19F for ; Fri, 15 Sep 2023 05:45:23 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-502f302b68dso1217130e87.2 for ; Fri, 15 Sep 2023 05:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694781921; x=1695386721; 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=rQKsjBFvt2/0L/1F7kjkJsmdL2N5EGcnErgcVOrwWbM=; b=SWLpz0NEfdsCLZKHQGhBETJNn8s6/HVA2gwabwLRnnGI5BthHRMTcRYIfXytemfFSD f45EIu1IClP5oKV2BbVJBUxmP43yFYM5Ku204ZoZH5Q1mDzNbYjTL0l7CSea0U5axxar 2+am1ZbkAZB7G4muxYmxqbWgfAhJ13QuK21Vq48EIdC5GelExGqqPspCJsod2DpSBexL xHK5/xnZCNf+Y8yAybnKPXEKrT7WnwiH6La1CEDflke/swMPvzi6A8WPC64iWDYY7bwv YCRm1OhVKf1FkyIRGPCPJeNYNfIaWi/BoHAWXaAtmed41oqZ2kZsaexCWxOVvZD0cU4E Xuzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694781921; x=1695386721; 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=rQKsjBFvt2/0L/1F7kjkJsmdL2N5EGcnErgcVOrwWbM=; b=oQV5kG+U5CsxWje6/QEXzFbGPdayfBl57NuaR/6iMoe1dxTDAeLdFgVQQX7Ve823iu aT0HlbDvEEwsUoUPl3fOWmNTugrs7zwW0uQSkuvSt31gSUWXqa0RIW4mSRozQhYYSWg9 sIcaXjEP0+nLhzJ4FSOr/onID+E/dyU5D1FmIeuye2FkOw1smHDp4VkCNiZBiJAgRjgE +jrHHBKKXaIUXx1YgOLIOs5ceWX2Fz6rebud4WRsbD7/H8sbAItWSLsb5VTxn8WWKwpt 5ncn0l10GlbgvohkMxrS+V/OQAcaYjIvvLw+tEr621IGaaqX7Zmi1R/cFkqh4ZPD491Q hstw== X-Gm-Message-State: AOJu0YxHRADsfum8rYUUNaMi1mr9x75/suJrS86r1vjhHpFs+uqZ7Gp7 b9kxRazWOoYRMR3OaH57Lv6zww== X-Google-Smtp-Source: AGHT+IEQc4h1ngKE2+VA6YGviDJVkrNplYwGZNRKiahgxgti51+UhFggRbJP8P7qeLRwC3QRRySPjA== X-Received: by 2002:a19:6714:0:b0:4fd:faf0:6591 with SMTP id b20-20020a196714000000b004fdfaf06591mr1278486lfc.10.1694781921357; Fri, 15 Sep 2023 05:45:21 -0700 (PDT) Received: from [10.167.154.1] ([2a00:f41:cbe:bc7d:62a6:5d09:5ba7:be5b]) by smtp.gmail.com with ESMTPSA id f19-20020ac25333000000b004fe37199b87sm624752lfh.156.2023.09.15.05.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:45:21 -0700 (PDT) From: Konrad Dybcio Date: Fri, 15 Sep 2023 14:45:16 +0200 Subject: [PATCH v4 2/3] dt-bindings: power: supply: Document Mitsumi MM8013 fuel gauge MIME-Version: 1.0 Message-Id: <20230621-topic-mm8013-v4-2-975aecd173ed@linaro.org> References: <20230621-topic-mm8013-v4-0-975aecd173ed@linaro.org> In-Reply-To: <20230621-topic-mm8013-v4-0-975aecd173ed@linaro.org> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sebastian Reichel , Konrad Dybcio Cc: Marijn Suijten , Rob Herring , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Konrad Dybcio , Krzysztof Kozlowski X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1694781917; l=1502; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=+uF0adwPQhjp9KC+P9UNR+pGm2F9OFhDZ4dy2nzuHuQ=; b=U5pry/nVMjoyOMh1xT2s8aR7A29Z8jFXV0S9o4qwUXQLL9gZW3+Ak2PhyqkWAUp0nNrxlytTv FGPps522HLrClcXhb2NAq+JYAZyH6NCq/za/WFoQxqrpWJBooJ1RxlY X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The Mitsumi MM8013 is an I2C fuel gauge for Li-Ion cells. The partial datasheet is available at [1]. Add bindings for this chip. [1] https://www.mitsumi.co.jp/latest-M/Catalog/pdf/battery_mm_8013_e.pdf Reviewed-by: Krzysztof Kozlowski Signed-off-by: Konrad Dybcio --- .../bindings/power/supply/mitsumi,mm8013.yaml | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Documentation/devicetree/bindings/power/supply/mitsumi,mm8013.yaml b/Documentation/devicetree/bindings/power/supply/mitsumi,mm8013.yaml new file mode 100644 index 000000000000..6865640cbdfa --- /dev/null +++ b/Documentation/devicetree/bindings/power/supply/mitsumi,mm8013.yaml @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/supply/mitsumi,mm8013.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Mitsumi MM8013 fuel gauge + +maintainers: + - Konrad Dybcio + +allOf: + - $ref: power-supply.yaml# + +properties: + compatible: + const: mitsumi,mm8013 + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + fuel-gauge@55 { + compatible = "mitsumi,mm8013"; + reg = <0x55>; + }; + }; From patchwork Fri Sep 15 12:45:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 723428 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 354CFEE6457 for ; Fri, 15 Sep 2023 12:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235060AbjIOMph (ORCPT ); Fri, 15 Sep 2023 08:45:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235078AbjIOMpc (ORCPT ); Fri, 15 Sep 2023 08:45:32 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 713BF2120 for ; Fri, 15 Sep 2023 05:45:24 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-501eec0a373so3386187e87.3 for ; Fri, 15 Sep 2023 05:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694781923; x=1695386723; 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=64O685rh5/+WceyOWRqSka2vt/nlTOc2EOjMCPDPopw=; b=U/ZozT7GKehDBYdy0Zs8M0i/4/8GZF3brPwcRU8Ccc9xV9Q6P544HU7/rLkCGuxO9l NzuuhilY5zAkXjleWAsdiTpEZFP55MPtuEPk5o/SE/NOoHo+yhz74kKKnNeWEYQqjs5S hWp+/zsBiE18IQONgz2gS4aNW2lcU9loqcp+kYsDVNOF0zCwk55JBKbv2JmFOtzufeGC /vC6siAcz+n/xks6IVMw11UYt9dLzIhdNXhkmNvpUC1ArygBVFPe/AgpHNiX7vEbW/Uf HZnGmpbZmASAgp2gkZh/OrIcaZmnrMOvisRfdBPam0avM8SZ8ubkN9FR5zyJ/awVWKDm u2RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694781923; x=1695386723; 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=64O685rh5/+WceyOWRqSka2vt/nlTOc2EOjMCPDPopw=; b=wbBUCARp2+bpiRfjqeatnvuXhxgvZ7fvWKDJwWnjV84mlTiYm0R8FSJ7QPgY1hl7nR OmtedtcbWdR9LUqDYOwRME4qVAjvaRpd8kcp6XtYdHxgh/q/ueZ4BAfXJeBx39dtDFMi 4VJocgBUTrApRnZB46GKsWoA4Of1zqQEQZFH7tUYFBjl2n38mKCrfhrXywyIX5NRovTP wbPMb+Kb3XZyd8fqUGOLNnZ4pryZEgxrS+URkuwSewyzLwajKXy9vOc4675hr/Cm/obg jutpbluzL0MrqRHfKmfIipxkqcO+RKiH/ffazEWZx4E43VJKkseefi53PHio/MN+aDUz 4QwA== X-Gm-Message-State: AOJu0Yw6EfbOywd354NiZyCJ5JVHOtaEbBpHL36/IWJ3lU6wyY9dt9NN dyXrksn8BXTKZZ+gF46vMCaltw== X-Google-Smtp-Source: AGHT+IGkDHYgV3kip0earhW8qVm96bbTxU9pilKgNREClOMWLZF8yMLIOibZL5pocXowUiXj3+h0pQ== X-Received: by 2002:a19:4f5b:0:b0:500:be66:e014 with SMTP id a27-20020a194f5b000000b00500be66e014mr1336911lfk.53.1694781922641; Fri, 15 Sep 2023 05:45:22 -0700 (PDT) Received: from [10.167.154.1] ([2a00:f41:cbe:bc7d:62a6:5d09:5ba7:be5b]) by smtp.gmail.com with ESMTPSA id f19-20020ac25333000000b004fe37199b87sm624752lfh.156.2023.09.15.05.45.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:45:22 -0700 (PDT) From: Konrad Dybcio Date: Fri, 15 Sep 2023 14:45:17 +0200 Subject: [PATCH v4 3/3] power: supply: Introduce MM8013 fuel gauge driver MIME-Version: 1.0 Message-Id: <20230621-topic-mm8013-v4-3-975aecd173ed@linaro.org> References: <20230621-topic-mm8013-v4-0-975aecd173ed@linaro.org> In-Reply-To: <20230621-topic-mm8013-v4-0-975aecd173ed@linaro.org> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sebastian Reichel , Konrad Dybcio Cc: Marijn Suijten , Rob Herring , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1694781917; l=10560; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=/d00LHDio/XkeskUxaF8XCxl9oQdSy+AyWbT9L2roW0=; b=nUMXPvy/czZfkY9otvDRLjk8nchC3JmwdJnGvA6TDWNWwUtMhn6KngmjWwoK7tuiKWy56aRT5 hAi9qGu/4TmBjX00GjHRDpKTpAME0N+jMHc+fGFInsPz6ohB7ELvvCV X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add a driver for the Mitsumi MM8013 fuel gauge. The driver is a vastly cleaned up and improved version of the one that shipped in some obscure Lenovo downstream kernel [1], with some register definitions borrowed from ChromeOS EC platform code [2]. [1] https://github.com/adazem009/kernel_lenovo_bengal/commit/b6b346427a871715709bd22aae449b9383f3b66b [2] https://chromium.googlesource.com/chromiumos/platform/ec/+/master/driver/battery/mm8013.h Signed-off-by: Konrad Dybcio --- uevent dump as of v4: POWER_SUPPLY_NAME=mm8013 POWER_SUPPLY_TYPE=Battery POWER_SUPPLY_CAPACITY=100 POWER_SUPPLY_CHARGE_FULL=7124000 POWER_SUPPLY_CHARGE_FULL_DESIGN=7500000 POWER_SUPPLY_CURRENT_NOW=0 POWER_SUPPLY_CYCLE_COUNT=27 POWER_SUPPLY_HEALTH=Good POWER_SUPPLY_PRESENT=1 POWER_SUPPLY_STATUS=Full POWER_SUPPLY_TEMP=300 POWER_SUPPLY_TIME_TO_EMPTY_AVG=888 POWER_SUPPLY_VOLTAGE_NOW=4402000 --- MAINTAINERS | 5 + drivers/power/supply/Kconfig | 9 ++ drivers/power/supply/Makefile | 1 + drivers/power/supply/mm8013.c | 274 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 289 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index fa7487b7729b..555403b9f011 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14409,6 +14409,11 @@ W: https://linuxtv.org T: git git://linuxtv.org/media_tree.git F: drivers/media/radio/radio-miropcm20* +MITSUMI MM8013 FG DRIVER +M: Konrad Dybcio +F: Documentation/devicetree/bindings/power/supply/mitsumi,mm8013.yaml +F: drivers/power/supply/mm8013.c + MMP SUPPORT R: Lubomir Rintel L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index 0c80c68fb0d7..3ef608d010f9 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -952,4 +952,13 @@ config CHARGER_QCOM_SMB2 adds support for the SMB2 switch mode battery charger found in PMI8998 and related PMICs. +config FUEL_GAUGE_MM8013 + tristate "Mitsumi MM8013 fuel gauge driver" + depends on I2C + help + Say Y here to enable the Mitsumi MM8013 fuel gauge driver. + It enables the monitoring of many battery parameters, including + the state of charge, temperature, cycle count, actual and design + capacity, etc. + endif # POWER_SUPPLY diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile index a8a9fa6de1e9..ba2c41f060be 100644 --- a/drivers/power/supply/Makefile +++ b/drivers/power/supply/Makefile @@ -111,3 +111,4 @@ obj-$(CONFIG_BATTERY_SURFACE) += surface_battery.o obj-$(CONFIG_CHARGER_SURFACE) += surface_charger.o obj-$(CONFIG_BATTERY_UG3105) += ug3105_battery.o obj-$(CONFIG_CHARGER_QCOM_SMB2) += qcom_pmi8998_charger.o +obj-$(CONFIG_FUEL_GAUGE_MM8013) += mm8013.o diff --git a/drivers/power/supply/mm8013.c b/drivers/power/supply/mm8013.c new file mode 100644 index 000000000000..bd8d54d6597f --- /dev/null +++ b/drivers/power/supply/mm8013.c @@ -0,0 +1,274 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2016-2019 The Linux Foundation. All rights reserved. + * Copyright (c) 2023, Linaro Limited + */ +#include +#include +#include +#include + +#define REG_BATID 0x00 /* This one is very unclear */ + #define BATID_101 0x0101 /* 107kOhm */ + #define BATID_102 0x0102 /* 10kOhm */ +#define REG_TEMPERATURE 0x06 +#define REG_VOLTAGE 0x08 +#define REG_FLAGS 0x0a + #define MM8013_FLAG_OTC BIT(15) + #define MM8013_FLAG_OTD BIT(14) + #define MM8013_FLAG_BATHI BIT(13) + #define MM8013_FLAG_FC BIT(9) + #define MM8013_FLAG_CHG BIT(8) + #define MM8013_FLAG_DSG BIT(0) +#define REG_FULL_CHARGE_CAPACITY 0x0e +#define REG_AVERAGE_CURRENT 0x14 +#define REG_AVERAGE_TIME_TO_EMPTY 0x16 +#define REG_AVERAGE_TIME_TO_FULL 0x18 +#define REG_CYCLE_COUNT 0x2a +#define REG_STATE_OF_CHARGE 0x2c +#define REG_DESIGN_CAPACITY 0x3c +/* TODO: 0x62-0x68 seem to contain 'MM8013C' in a length-prefixed, non-terminated string */ + +#define DECIKELVIN_TO_DECIDEGC(t) (t - 2731) + +struct mm8013_chip { + struct i2c_client *client; + struct regmap *regmap; +}; + +static int mm8013_checkdevice(struct mm8013_chip *chip) +{ + int battery_id, ret; + u32 val; + + ret = regmap_write(chip->regmap, REG_BATID, 0x0008); + if (ret < 0) + return ret; + + regmap_read(chip->regmap, REG_BATID, &val); + if (ret < 0) + return ret; + + if (val == BATID_102) + battery_id = 2; + else if (val == BATID_101) + battery_id = 1; + else + return -EINVAL; + + dev_dbg(&chip->client->dev, "battery_id: %d\n", battery_id); + + return 0; +} + +static enum power_supply_property mm8013_battery_props[] = { + POWER_SUPPLY_PROP_CAPACITY, + POWER_SUPPLY_PROP_CHARGE_FULL, + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, + POWER_SUPPLY_PROP_CURRENT_NOW, + POWER_SUPPLY_PROP_CYCLE_COUNT, + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_TEMP, + POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, + POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, + POWER_SUPPLY_PROP_VOLTAGE_NOW, +}; + +static int mm8013_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct mm8013_chip *chip = psy->drv_data; + int ret = 0; + u32 regval; + + switch (psp) { + case POWER_SUPPLY_PROP_CAPACITY: + ret = regmap_read(chip->regmap, REG_STATE_OF_CHARGE, ®val); + if (ret < 0) + return ret; + + val->intval = regval; + break; + case POWER_SUPPLY_PROP_CHARGE_FULL: + ret = regmap_read(chip->regmap, REG_FULL_CHARGE_CAPACITY, ®val); + if (ret < 0) + return ret; + + val->intval = 1000 * regval; + break; + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + ret = regmap_read(chip->regmap, REG_DESIGN_CAPACITY, ®val); + if (ret < 0) + return ret; + + val->intval = 1000 * regval; + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: + ret = regmap_read(chip->regmap, REG_AVERAGE_CURRENT, ®val); + if (ret < 0) + return ret; + + val->intval = -1000 * (s16)regval; + break; + case POWER_SUPPLY_PROP_CYCLE_COUNT: + ret = regmap_read(chip->regmap, REG_CYCLE_COUNT, ®val); + if (ret < 0) + return ret; + + val->intval = regval; + break; + case POWER_SUPPLY_PROP_HEALTH: + ret = regmap_read(chip->regmap, REG_FLAGS, ®val); + if (ret < 0) + return ret; + + if (regval & MM8013_FLAG_BATHI) + val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; + else if (regval & (MM8013_FLAG_OTD | MM8013_FLAG_OTC)) + val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; + else + val->intval = POWER_SUPPLY_HEALTH_GOOD; + break; + case POWER_SUPPLY_PROP_PRESENT: + ret = regmap_read(chip->regmap, REG_TEMPERATURE, ®val); + if (ret < 0) + return ret; + + val->intval = ((s16)regval > 0); + break; + case POWER_SUPPLY_PROP_STATUS: + ret = regmap_read(chip->regmap, REG_FLAGS, ®val); + if (ret < 0) + return ret; + + if (regval & MM8013_FLAG_DSG) + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; + else if (regval & MM8013_FLAG_CHG) + val->intval = POWER_SUPPLY_STATUS_CHARGING; + else if (regval & MM8013_FLAG_FC) + val->intval = POWER_SUPPLY_STATUS_FULL; + else + val->intval = POWER_SUPPLY_STATUS_UNKNOWN; + break; + case POWER_SUPPLY_PROP_TEMP: + ret = regmap_read(chip->regmap, REG_TEMPERATURE, ®val); + if (ret < 0) + return ret; + + val->intval = DECIKELVIN_TO_DECIDEGC(regval); + break; + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: + ret = regmap_read(chip->regmap, REG_AVERAGE_TIME_TO_EMPTY, ®val); + if (ret < 0) + return ret; + + /* The estimation is not yet ready */ + if (regval == U16_MAX) + return -ENODATA; + + val->intval = regval; + break; + case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: + ret = regmap_read(chip->regmap, REG_AVERAGE_TIME_TO_FULL, ®val); + if (ret < 0) + return ret; + + /* The estimation is not yet ready */ + if (regval == U16_MAX) + return -ENODATA; + + val->intval = regval; + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + ret = regmap_read(chip->regmap, REG_VOLTAGE, ®val); + if (ret < 0) + return ret; + + val->intval = 1000 * regval; + break; + default: + return -EINVAL; + } + + return 0; +} + +static const struct power_supply_desc mm8013_desc = { + .name = "mm8013", + .type = POWER_SUPPLY_TYPE_BATTERY, + .properties = mm8013_battery_props, + .num_properties = ARRAY_SIZE(mm8013_battery_props), + .get_property = mm8013_get_property, +}; + +static const struct regmap_config mm8013_regmap_config = { + .reg_bits = 8, + .val_bits = 16, + .max_register = 0x68, + .use_single_read = true, + .use_single_write = true, + .val_format_endian = REGMAP_ENDIAN_LITTLE, +}; + +static int mm8013_probe(struct i2c_client *client) +{ + struct power_supply_config psy_cfg = {}; + struct device *dev = &client->dev; + struct power_supply *psy; + struct mm8013_chip *chip; + int ret = 0; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) + return dev_err_probe(dev, -EIO, + "I2C_FUNC_SMBUS_WORD_DATA not supported\n"); + + chip = devm_kzalloc(dev, sizeof(struct mm8013_chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + chip->client = client; + + chip->regmap = devm_regmap_init_i2c(client, &mm8013_regmap_config); + if (IS_ERR(chip->regmap)) + return dev_err_probe(dev, ret, "Couldn't initialize regmap\n"); + + ret = mm8013_checkdevice(chip); + if (ret) + return dev_err_probe(dev, ret, "MM8013 not found\n"); + + psy_cfg.drv_data = chip; + psy_cfg.of_node = dev->of_node; + + psy = devm_power_supply_register(dev, &mm8013_desc, &psy_cfg); + if (IS_ERR(psy)) + return PTR_ERR(psy); + + return 0; +} + +static const struct i2c_device_id mm8013_id_table[] = { + { "mm8013", 0 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, mm8013_id_table); + +static const struct of_device_id mm8013_match_table[] = { + { .compatible = "mitsumi,mm8013" }, + {} +}; + +static struct i2c_driver mm8013_i2c_driver = { + .probe = mm8013_probe, + .id_table = mm8013_id_table, + .driver = { + .name = "mm8013", + .of_match_table = mm8013_match_table, + }, +}; +module_i2c_driver(mm8013_i2c_driver); + +MODULE_DESCRIPTION("MM8013 fuel gauge driver"); +MODULE_LICENSE("GPL");