From patchwork Sat Nov 5 11:25:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivaylo Dimitrov X-Patchwork-Id: 15954 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp940911wru; Sat, 5 Nov 2022 04:34:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6OAqA4yVkXaT9HvqefA2EI79m3xVF1kj/8Vyy/w+uSl4OB/ImIdM+99AdjwSIiEAnb8jS2 X-Received: by 2002:a17:903:2446:b0:187:11c6:6a1b with SMTP id l6-20020a170903244600b0018711c66a1bmr34256517pls.39.1667648083722; Sat, 05 Nov 2022 04:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667648083; cv=none; d=google.com; s=arc-20160816; b=A1yFj9Lo1c018KoMgM7wLV1ThN627LmwyTlobivpL38eS3pLRKvsV3GpU1B3OXhd3g G7803FBKgwAwnAD45CIgsgffhV9FgOzg82aBEqfGYq4cVhiQo5eUUb9t3HshWSVGwxg8 vnQbco6TEMKw0WPUg67WfIkqnlsXh3xL9rEBYrdfwjvVKZxyx58XJCGrXh2qbeG6Qpky NPjtM6olo0OmhU1XEyDWLQtkVeL96pfQ9KOTlzCFgNM9KjEQLffDv/LL0dbDXZYYqoWF m01L1A/cVaoREMZpFXubBTQ88yhKJMFzIaii8rfgAJvm4iqSogAOUWIHJpqsJaAvlOgX s2QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=mvbWRnJLjkEbJwbK1HqoKZYYWWWpHEGeJghtyoGl4P0=; b=fv6oqf2iK2SvB8mNMB4ou1gqY++0mG8jwm6qY/chh9rWIeEr5wJieWm13epYlRgvRx qh86QkJ8+5+BuNANjFJDS5Mz1AGyX+68lC6lXXwIeSGtakyWOROsmlAKcrUrwyb1U/XK ZaPszShQOa1j3IIQ7UyVFKHMoCXj8zwQe4/X8NBohlQ//Oys+OJHv3w/YIuN6eUX9V4u SkfC2+86cybxU7U+xvJizSJmp00W4ZtwcnUvXOFwfWdiwU0z3nJ71yx/6RLPq9YAlzDj tdkpCtSl+uRcFtZJeZI+Gqy6XVpBZLjrw4+YdBbpGhDLdKhYGP80WD3wLglvHeLOjQb8 DkeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=C8gR2s0A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f7-20020a170902ce8700b0016ce3d67e7csi3233265plg.387.2022.11.05.04.34.30; Sat, 05 Nov 2022 04:34:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=C8gR2s0A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229805AbiKEL02 (ORCPT + 99 others); Sat, 5 Nov 2022 07:26:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229776AbiKEL0S (ORCPT ); Sat, 5 Nov 2022 07:26:18 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E9F21C93B; Sat, 5 Nov 2022 04:26:17 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id b2so19256128eja.6; Sat, 05 Nov 2022 04:26:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=mvbWRnJLjkEbJwbK1HqoKZYYWWWpHEGeJghtyoGl4P0=; b=C8gR2s0AAAG6uGJhhbsKl5NJ2n+1peuiSWA7QXTiZTMalCVYF+kWkYB4pzVxrQPawu RKLgbkvoQDXSjjiuyYupi3fNKABc1mppEqnPCuuNxIswwNEdB9js1on29IY/Y3KZYxp6 nnWbgja5HcwueVtL5j5vmXpzGc491l49mzUnQo+fIUJhPmEyQ4KPGnLsaX+y+8Zp08Ca ErkVwbpcVmFgQ3egvFuvyQOuEPy++nUCS2tf1zq0r+4wxAyTXX05mP3J4WFH28Mbe82V J868hOcDys45rd3Z7hxksZkNznnB+4q7796VJXRrIbDdnpB17jFdYItX5VVZhWRRpQDm W8yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mvbWRnJLjkEbJwbK1HqoKZYYWWWpHEGeJghtyoGl4P0=; b=P4GUQiILJkv+yQk9hvxhchX2xjR/8VviVHdN5pY3HY84szVXOQysHKIjfSfHVFuqHn 1m262+HrVjTVvVVaZNBQsffHapLdDexC+rfr+XOI7Cym77cEal9FssAQuwo/VAa+nesa 7ln8uumdi/SiW4iSoBldAX2jkJ6s86BjhOPvCq1ioo8m/BCCYIvRo+QmLwOBIBPCow4o hy1j57IcVbqpGLMbY7nUaKvP/YYngLEgxLUA3fV2WuzV256VzuaBftWo+kHsqotNMpwH 3rdHB7nv4I5sWuD53ZEzJYNTgEheLr8UCOalM4fi8ENqcBwfKLMJZnhmZiD0fIxyYbD5 EtRg== X-Gm-Message-State: ACrzQf3tRs7afrX78re9n43+jdmZKw5FE1yU+bxfJOoM0j0uS9+vEuba yeNDRRsqNCRvu/bh6nra/DQ= X-Received: by 2002:a17:907:608f:b0:78e:1b60:60e2 with SMTP id ht15-20020a170907608f00b0078e1b6060e2mr39212115ejc.382.1667647576266; Sat, 05 Nov 2022 04:26:16 -0700 (PDT) Received: from localhost.localdomain ([46.249.74.23]) by smtp.gmail.com with ESMTPSA id u18-20020a509512000000b004611c230bd0sm1050069eda.37.2022.11.05.04.26.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Nov 2022 04:26:15 -0700 (PDT) From: Ivaylo Dimitrov To: sre@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, tony@atomide.com, philipp@uvos.xyz, Ivaylo Dimitrov Subject: [PATCH 2/3] power: supply: cpcap-battery: Fix battery identification Date: Sat, 5 Nov 2022 13:25:43 +0200 Message-Id: <1667647544-12945-3-git-send-email-ivo.g.dimitrov.75@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1667647544-12945-1-git-send-email-ivo.g.dimitrov.75@gmail.com> References: <1667647544-12945-1-git-send-email-ivo.g.dimitrov.75@gmail.com> X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748655757142301385?= X-GMAIL-MSGID: =?utf-8?q?1748655757142301385?= Use the same logic to identify genuine batteries as Android does. Signed-off-by: Ivaylo Dimitrov --- drivers/power/supply/cpcap-battery.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 8869067..ca6ee2b 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -422,7 +422,7 @@ static int cpcap_battery_cc_to_ua(struct cpcap_battery_ddata *ddata, static int cpcap_battery_match_nvmem(struct device *dev, const void *data) { - if (strcmp(dev_name(dev), "89-500029ba0f73") == 0) + if (strncmp(dev_name(dev), "89-500", 6) == 0) return 1; else return 0; @@ -439,10 +439,19 @@ static void cpcap_battery_detect_battery_type(struct cpcap_battery_ddata *ddata) if (IS_ERR_OR_NULL(nvmem)) { ddata->check_nvmem = true; dev_info_once(ddata->dev, "Can not find battery nvmem device. Assuming generic lipo battery\n"); - } else if (nvmem_device_read(nvmem, 2, 1, &battery_id) < 0) { - battery_id = 0; - ddata->check_nvmem = true; - dev_warn(ddata->dev, "Can not read battery nvmem device. Assuming generic lipo battery\n"); + } else { + char buf[24]; + + if (nvmem_device_read(nvmem, 96, 4, buf) < 0 || + strncmp(buf, "COPR", 4) != 0 || + nvmem_device_read(nvmem, 104, 24, buf) < 0 || + strncmp(buf, "MOTOROLA E.P CHARGE ONLY", 24) != 0 || + nvmem_device_read(nvmem, 2, 1, &battery_id) < 0) { + battery_id = 0; + ddata->check_nvmem = true; + dev_warn(ddata->dev, "Can not read battery nvmem device. Assuming generic lipo battery\n"); + } + } switch (battery_id) {