From patchwork Wed Sep 13 15:28:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 722429 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 67694EDEC74 for ; Wed, 13 Sep 2023 15:29:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229540AbjIMP3O (ORCPT ); Wed, 13 Sep 2023 11:29:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbjIMP2x (ORCPT ); Wed, 13 Sep 2023 11:28:53 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 994E51FF1 for ; Wed, 13 Sep 2023 08:28:49 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-31c73c21113so6569774f8f.1 for ; Wed, 13 Sep 2023 08:28:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694618928; x=1695223728; 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=beZoMnKS0MSopOSGjY5SkpDxz/1aMOYtMP8TIqV8c8uhmPazmJWgs7/EDlNcDP9ZDx dNUpNfQ6kLQSkieErjLj8ph6H8rzYqwxshxA8idDLhuTc7TCaXZTwWPGAxUCOJfnh3LT Ksim/krJodXEE2Ao8BydKvOJEP+Nhz8SV1H7/oYvOXEcdJSduaTo9yqE0ziEiyhTob/g QrYYeJfMb/fBnNR1CmPKUfVo9Usc7ceGmtlfBgIwQuZ/9j5WABQmBoHLgp8GfKWNkyoj QGr5PuauNjSFd7MQxqkoJxTRP7eiw/gItlHwiDv3ZW/AumYVIn32TxsmjIlD4yhRjctL a89Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694618928; x=1695223728; 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=fsSA9l7H0mQfeqRYScF3bn/7d0Ha2fx2uHkqHIwonVTVPxxS2GqexrNgsL/yMovq4G Ab4rFibCpZc/I6w3JHMglS/sVK4k7E2aNh5YxdHh3uiaOu01wmvgaJvJE/PuhB0UlJ74 WhB417JDuZkKKpgWmiXEwRJi4Qik/PNm2V77phpV+cbHCEwy7ZKAeSsQrg0310MFaBMH PM4HeS4kdFDwy+bk9O84z1nGYQ3aarWgL2q9AzsR7U1pY3dmjMRFefJ7j66Q6wrpKjtA R9EfEuCh0ZQ/JuVM7k0RgxgHfkxJNJiBsCsRYBrvwHQ3UDkfebMoJ0noGlheDXGd3QtK mXhw== X-Gm-Message-State: AOJu0YyjzHe1MYn3RkgVTxgCSfv9cNtwwAGVPAQjJgYgKHeEMrjHrvgH jjavZjRi3zuZ55XX1R3HksuNkMvyhyUy2VvQTcttEw== X-Google-Smtp-Source: AGHT+IEl11EKMfk5wSAmJ6oOzj+vGlYX5Osa7YOjrMlFE/PamB93QQH5/Vm/y33QO0yOFWOVhVzI0A== X-Received: by 2002:a05:6000:12d2:b0:31f:bdfd:5d30 with SMTP id l18-20020a05600012d200b0031fbdfd5d30mr2476573wrx.57.1694618928027; Wed, 13 Sep 2023 08:28:48 -0700 (PDT) Received: from [10.167.154.1] (178235177106.dynamic-4-waw-k-1-1-0.vectranet.pl. [178.235.177.106]) by smtp.gmail.com with ESMTPSA id a11-20020aa7d74b000000b0052a404e5929sm7391979eds.66.2023.09.13.08.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 08:28:47 -0700 (PDT) From: Konrad Dybcio Date: Wed, 13 Sep 2023 17:28:43 +0200 Subject: [PATCH v3 1/3] dt-bindings: vendor-prefixes: Add Mitsumi Electric Co., Ltd. MIME-Version: 1.0 Message-Id: <20230621-topic-mm8013-v3-1-781da361ec60@linaro.org> References: <20230621-topic-mm8013-v3-0-781da361ec60@linaro.org> In-Reply-To: <20230621-topic-mm8013-v3-0-781da361ec60@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=1694618924; l=1125; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=A4edAPC9JkBqokj8iLNvPGCrxmBfeXMUhLTyoYd19k8=; b=MZZTMWp/pnsC9RA4uTSiS1T0IUZR1TpSBUDNNCUmPeUI6H5w6C5cNgBUVRXJ4pU1lcLSfsIto Z3ye7OWXVQODysPmLFA45rchPF7iT0WsBI92FZxSYXNlcIoY/vYh/Vz 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 Wed Sep 13 15:28:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 722976 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 17018EDEC75 for ; Wed, 13 Sep 2023 15:29:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229722AbjIMP3X (ORCPT ); Wed, 13 Sep 2023 11:29:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbjIMP3B (ORCPT ); Wed, 13 Sep 2023 11:29:01 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1160D1FFC for ; Wed, 13 Sep 2023 08:28:51 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-52a40cf952dso9208312a12.2 for ; Wed, 13 Sep 2023 08:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694618929; x=1695223729; 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=tQr94KIOOvObTwS7tE00SK4URXS2zORS2LxtSW2Y8+eLpMHPb1BE2+CCperM32yPjH L0MEBTAenRIdtctYIR28uvApRVMCx/LgQP7vTzmMe/zKxaIYygYZb1XHwSCq9WDDJuim 0GB3n99MO6jUsEfVffWrJ9DWRgKeuJVwFM/7VCZ0ozlvWjR4StZ/6bnQ149WAGo/ZQ3k FyDjLIJIppqc/fjEda6qv2KZv1GEUJt+WLHlsJ3rl8x2ZdcW7tYVdnNQHcF1g1c2m7YG JQl+v+0maX+k3HuOAJfVzieNl+Jf+wuBy9IYy11KfrNk1zbOsEjZsDKNbwC6xSEYPPKZ aipg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694618929; x=1695223729; 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=NrCOmkVoYeHBgTG8iH053GqJZx8eTwlD1j1ldMPq6WP66gy4AMQ3STsJ10WGxvyWi/ k9pRJG5gSieSeL6DgSZU8II2FSfy6vfhcMO4G5RIBW40gblQ4kJDDEqz19tHa6AZWE7c 5Wqhml9+y894/E2I/bqFLdRC8MdH43fNLyTKzGE3bTmJCeGigyi21oYGKbsPe+ARjMkE X/e+C7l+jNqzINtb9FyBV/bT6eJzvh2TFyBKNXeb2RWVr4zEQwi+aenmfPNw3POv2yY9 th4mdHegVjaW91aTZjMBp8WE+KlpMX5kblI3sHKdBXs4zc8csbZxtEf6bf3KwmO+gOwc ul+w== X-Gm-Message-State: AOJu0YzTjN6DAfrBG5NRskKWiKrE03Mk+gAVvE/4FGjNXMKUpAMoF5Vj Kn7SSVvJmj8Qt//kKDA1HDWe2g== X-Google-Smtp-Source: AGHT+IF1N0dH7NBwdsld1dadU/38+DoZHPAaHw3QYfBoM6Clc3uyK0g/1qrDqxDnarlnUznHb+fc/w== X-Received: by 2002:aa7:c1d1:0:b0:52d:ea50:8b30 with SMTP id d17-20020aa7c1d1000000b0052dea508b30mr2868009edp.5.1694618929447; Wed, 13 Sep 2023 08:28:49 -0700 (PDT) Received: from [10.167.154.1] (178235177106.dynamic-4-waw-k-1-1-0.vectranet.pl. [178.235.177.106]) by smtp.gmail.com with ESMTPSA id a11-20020aa7d74b000000b0052a404e5929sm7391979eds.66.2023.09.13.08.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 08:28:49 -0700 (PDT) From: Konrad Dybcio Date: Wed, 13 Sep 2023 17:28:44 +0200 Subject: [PATCH v3 2/3] dt-bindings: power: supply: Document Mitsumi MM8013 fuel gauge MIME-Version: 1.0 Message-Id: <20230621-topic-mm8013-v3-2-781da361ec60@linaro.org> References: <20230621-topic-mm8013-v3-0-781da361ec60@linaro.org> In-Reply-To: <20230621-topic-mm8013-v3-0-781da361ec60@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=1694618924; l=1502; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=+uF0adwPQhjp9KC+P9UNR+pGm2F9OFhDZ4dy2nzuHuQ=; b=rZ2FLQkeXx9L1IBv/fSklUMLUVdwZob3h8heT6fA9q+Hucr4hgbUF50hNqd+auczPsRC6qSTt iekJ7LyR2zzD6wHc34nM126h9TzkIRmUEX4ut8mj/hJ0MXDaY3VXD8o 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 Wed Sep 13 15:28:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 722428 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 377AAEDEC77 for ; Wed, 13 Sep 2023 15:29:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229809AbjIMP3Y (ORCPT ); Wed, 13 Sep 2023 11:29:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbjIMP3B (ORCPT ); Wed, 13 Sep 2023 11:29:01 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35CBB210A for ; Wed, 13 Sep 2023 08:28:52 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-31dca134c83so7044474f8f.3 for ; Wed, 13 Sep 2023 08:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694618930; x=1695223730; 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=Gu++iTv7nZew3JrUz48Up2NLFQgID7zT3Mg6/75Peys=; b=pC/dbOTHyRd2pc3j2oL4SZvJ3KEsddzt+JH890mYXZ5/7NApGZmYIFenIZCjzd4i+j h/8RWiDVPY6BZkDUgTmY2I6xO61v2qBY6IDJAlIXwQQ9b2/aSi/nKuNmq8QUCq6W3IAS CagUN2UO5OAEsQpCDqjG5e/wYNnqE8ln3ZDAGv+JtVfb581pgA+TFhWWUUk9nI4cPivD quPuQ0lUvSXsdliFadU8AC5E4OPkgrsxdCxDGZZx1ItR4m2AK4UGp1g3ji8IbFCLyzPh E9+28dEHWscG/s7J+fcf+IStCZl5L+Rp+SwnUIt3UZDdoYiiKSP7FHrdwNt80S8EKEp5 aUMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694618930; x=1695223730; 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=Gu++iTv7nZew3JrUz48Up2NLFQgID7zT3Mg6/75Peys=; b=I5rcPy8X7n1CwidbmUkPwQVTpbBLgADymQ1qAaXSUnYDGZxIxggc4gv05Z4r2ZI2ms S16wT3mkuaWuylIFAf9y4s22KvPTBGrZtEZZ9ulc01avtvIXPywaZS+/2MF92HQPrnw1 mLL08jXqcmjFAVYsQWS94U0v1rPR5s9Lm0MHZe1EmsrpDxJWjNwRRKvIZ/myvv4yjbdu 9Ey+Ad/jEixRijflqGYIHOKBfFhrwAtWZryMu2VTzpjYWZrvoZb9p6njV1bgWlIXekah yuKvmqXigdLMGyqjPBt6zfnxA1GNxXfodUv+8/EZfw4XE3h1llyW907h9WPMhpcrMJ1j xadw== X-Gm-Message-State: AOJu0YzR2yo5HdKvHT9xogEW70nx8FKv+P6glNdBQvFvgoveBXRXdsv/ irYanERrDs5ng0005Ymx1+3CwQ== X-Google-Smtp-Source: AGHT+IH1zpd8y2R/6ASt3/v6W/xMW1QEFigEas9Xzugbh4IP6J5mWp9o1fNd52XL0xyS/QqKYSAKsw== X-Received: by 2002:a5d:42ca:0:b0:319:8c35:378 with SMTP id t10-20020a5d42ca000000b003198c350378mr2613451wrr.44.1694618930633; Wed, 13 Sep 2023 08:28:50 -0700 (PDT) Received: from [10.167.154.1] (178235177106.dynamic-4-waw-k-1-1-0.vectranet.pl. [178.235.177.106]) by smtp.gmail.com with ESMTPSA id a11-20020aa7d74b000000b0052a404e5929sm7391979eds.66.2023.09.13.08.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 08:28:50 -0700 (PDT) From: Konrad Dybcio Date: Wed, 13 Sep 2023 17:28:45 +0200 Subject: [PATCH v3 3/3] power: supply: Introduce MM8013 fuel gauge driver MIME-Version: 1.0 Message-Id: <20230621-topic-mm8013-v3-3-781da361ec60@linaro.org> References: <20230621-topic-mm8013-v3-0-781da361ec60@linaro.org> In-Reply-To: <20230621-topic-mm8013-v3-0-781da361ec60@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=1694618924; l=10078; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=G4IyeZVwoC9zRTk1IblprqWvXsPROJfnZzrBmmp9ewE=; b=RaO46BgZy7nUToNCRTaqc3de19nzJK8XXB1fUSqBbq+jKnoa2Vc+avBXT1GZyIQim1X2dVnMC 3tU0NSYIeCMABWmJEzLwr3RqflmEhTEDRk/4BbgquebIdN4T5Moao6I 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 --- MAINTAINERS | 5 + drivers/power/supply/Kconfig | 9 ++ drivers/power/supply/Makefile | 1 + drivers/power/supply/mm8013.c | 283 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 298 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 52d3cee7d8d4..bb79cc167b06 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14408,6 +14408,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 a61bb1283e19..b355847e001a 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..ce20c6078116 --- /dev/null +++ b/drivers/power/supply/mm8013.c @@ -0,0 +1,283 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2016-2019 The Linux Foundation. All rights reserved. + * Copyright (c) 2023, Linaro Limited + */ +#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; +}; + +static int mm8013_write_reg(struct i2c_client *client, u8 reg, u16 value) +{ + int ret; + + ret = i2c_smbus_write_word_data(client, reg, value); + if (ret < 0) + dev_err(&client->dev, "%s: err %d\n", __func__, ret); + + usleep_range(4000, 5000); + return ret; +} + +static int mm8013_read_reg(struct i2c_client *client, u8 reg) +{ + int ret; + + ret = i2c_smbus_read_word_data(client, reg); + if (ret < 0) + dev_err(&client->dev, "%s: err %d\n", __func__, ret); + + usleep_range(4000, 5000); + return ret; +} + +static int mm8013_checkdevice(struct mm8013_chip *chip) +{ + int battery_id, ret; + + ret = mm8013_write_reg(chip->client, REG_BATID, 0x0008); + if (ret < 0) + return ret; + + ret = mm8013_read_reg(chip->client, REG_BATID); + if (ret < 0) + return ret; + + if (ret == BATID_102) + battery_id = 2; + else if (ret == 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; + struct i2c_client *client = chip->client; + int ret = 0; + + switch (psp) { + case POWER_SUPPLY_PROP_CAPACITY: + ret = mm8013_read_reg(client, REG_STATE_OF_CHARGE); + if (ret < 0) + return ret; + + val->intval = ret; + break; + case POWER_SUPPLY_PROP_CHARGE_FULL: + ret = mm8013_read_reg(client, REG_FULL_CHARGE_CAPACITY); + if (ret < 0) + return ret; + + val->intval = ret; + break; + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + ret = mm8013_read_reg(client, REG_DESIGN_CAPACITY); + if (ret < 0) + return ret; + + val->intval = ret; + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: + ret = mm8013_read_reg(client, REG_AVERAGE_CURRENT); + if (ret < 0) + return ret; + + if (ret > S16_MAX) + val->intval -= (1 << 16); + else + val->intval = ret; + + val->intval *= -1000; + break; + case POWER_SUPPLY_PROP_CYCLE_COUNT: + ret = mm8013_read_reg(client, REG_CYCLE_COUNT); + if (ret < 0) + return ret; + + val->intval = ret; + break; + case POWER_SUPPLY_PROP_HEALTH: + ret = mm8013_read_reg(client, REG_FLAGS); + if (ret < 0) + return ret; + + if (ret & MM8013_FLAG_BATHI) + val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; + else if (ret & (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: + val->intval = mm8013_read_reg(client, REG_TEMPERATURE) > 0; + break; + case POWER_SUPPLY_PROP_STATUS: + ret = mm8013_read_reg(client, REG_FLAGS); + if (ret < 0) + return ret; + + if (ret & MM8013_FLAG_DSG) + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; + else if (ret & MM8013_FLAG_CHG) + val->intval = POWER_SUPPLY_STATUS_CHARGING; + else if (ret & MM8013_FLAG_FC) + val->intval = POWER_SUPPLY_STATUS_FULL; + else + val->intval = POWER_SUPPLY_STATUS_UNKNOWN; + break; + case POWER_SUPPLY_PROP_TEMP: + ret = mm8013_read_reg(client, REG_TEMPERATURE); + if (ret < 0) + return ret; + + val->intval = DECIKELVIN_TO_DECIDEGC(ret); + break; + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: + ret = mm8013_read_reg(client, REG_AVERAGE_TIME_TO_EMPTY); + if (ret < 0) + return ret; + + /* The estimation is not yet ready */ + if (ret == U16_MAX) + return -ENODATA; + + val->intval = ret; + break; + case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: + ret = mm8013_read_reg(client, REG_AVERAGE_TIME_TO_FULL); + if (ret < 0) + return ret; + + /* The estimation is not yet ready */ + if (ret == U16_MAX) + return -ENODATA; + + val->intval = ret; + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + ret = mm8013_read_reg(client, REG_VOLTAGE); + if (ret < 0) + return ret; + + val->intval = ret; + 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 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; + + ret = mm8013_checkdevice(chip); + if (ret) + return dev_err_probe(dev, -ENODEV, "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");