Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp2260225rwl; Sat, 5 Nov 2022 04:35:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5sX7cBiyxs2JLARMW3MaE6SDTW+ywZiliiFfle6IuAQ6qK4Q9uIvKnx61E3ONSihWXt1eA X-Received: by 2002:a05:6a00:150b:b0:56b:e358:5c08 with SMTP id q11-20020a056a00150b00b0056be3585c08mr39771012pfu.37.1667648122200; Sat, 05 Nov 2022 04:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667648122; cv=none; d=google.com; s=arc-20160816; b=EjPZJTPY94vnyQzXDscFxtecxfmlVJqPDnejojoXBjYIc3gzYyqtb/2pZnYwbXzNLi fw/QnIV+jTllOBueGIQQv7BUibmBxPAkPSKJIg0T5JjZv1+GhizFFuatbelI4JjdP89o yPwcECFjTycc47qGEf7HWwkGDD+Cwf7nT+OE6MYvVFmhrFL5k1Ea6oQ3ftblE4jVtKuJ Gsbbe1LbaK6vmT3w10ewxe/JBLQto1hTWpIr6XV2Hu7DX9kp5kdAExAVZchQnhlA4HXT 4G353+b3sDJae5FmAnOR7J+eC+EDzUm8dvjVJewgeJbgFejUHh7avmClAoClRX9D8umN uazA== 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 Return-Path: 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.35.09; Sat, 05 Nov 2022 04:35:22 -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 + 96 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 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) { -- 1.9.1