From patchwork Tue Nov 1 19:53:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivaylo Dimitrov X-Patchwork-Id: 13858 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3176388wru; Tue, 1 Nov 2022 12:58:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7LbTOXegP8ojVMIaOdtG9xwRpPVOv4TRAv7sZ3Tqu70MBPB73mabrL5x6BO9QHwXVv19hn X-Received: by 2002:a17:902:7d87:b0:17f:9cd0:2e03 with SMTP id a7-20020a1709027d8700b0017f9cd02e03mr21053161plm.164.1667332692644; Tue, 01 Nov 2022 12:58:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667332692; cv=none; d=google.com; s=arc-20160816; b=enhO4jixIi8BKeakfs54b4gXgxDFDP6TsF9FjbgSSojUotMm8FzkgcCFbnIMvPpG1a 1OKosIbXCjXPzfPokeVKM/Vk+ndsvr7DCmklF/urUWu5HpYh/G16tv+myWjAkEgEgrGk 8ga/29uQi4U70vzr0HkCewIdvdLkwJrH9Lp3oAxxKJkXtXLQ89DsOGkZ/e9+JGNIlK9A 1N+koCnH26vJOVJj7UIFBsVDSJug2AR9+rmg0RHbP0sttgmcqKFirkIrJcNnV/VuQ77K zN2XkuK37Pqog8Q7x+FXIlyxjdC6ctvGcm2+7Tp7qTa3sDORGOeI75mS+miw0T72aAe9 GMfg== 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=vye8HxSgbJ5V+jvH1roXnBTgLilfVcEjREHvPLd1+J4=; b=Zs4R2QaZ32yQWBvDCmUwXkBUIuTiZmWdUV8QYIVpVe1RyjGG+zE8C85I0lw48y2MID CZ8f9cNe1pk2mQ+L79/IYw3K+KjBZH53qPYbg+JSEM5U52sRf2DQqwyv2LuEnXiSM6LU u5WiWO1joWnw3l0ORig6246D8W4vmjGx96SpupeRUs6307vJ5wRFQC9PEp4RmFcmuJqN /Xbqm2wkxD3b8e2uzuSX4ukM3TgRCrYILx/+0c1jOr/28C2YAkd5LsZdlrCCRwhgbYpg 8Z0V6Krh1HOakxWILzscsdesdBUMPvGJ6wWcPuR9uwZA55ylpSWMIrTi8BLM0x9iO+dR CDNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZKjLYhzC; 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 cn9-20020a056a00340900b00565c337c562si12987706pfb.100.2022.11.01.12.57.59; Tue, 01 Nov 2022 12:58:12 -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=ZKjLYhzC; 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 S230010AbiKATyU (ORCPT + 99 others); Tue, 1 Nov 2022 15:54:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229819AbiKATyL (ORCPT ); Tue, 1 Nov 2022 15:54:11 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEE321838B; Tue, 1 Nov 2022 12:54:08 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id m29-20020a05600c3b1d00b003c6bf423c71so13378wms.0; Tue, 01 Nov 2022 12:54:08 -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=vye8HxSgbJ5V+jvH1roXnBTgLilfVcEjREHvPLd1+J4=; b=ZKjLYhzCb5kTc/pGMmnAS+QjR79KN9xMzxUqE9fSAXuiSt1COUtdggm2+he/fVBjDa UffrpFN+eIv7RsNliCrL6iST546Gm1g7qlnvFoMYmS4yGMTyUCTBhl2Xy0G9lJR6HkKZ WI90Zk+RDl8caGilT5dFVlcaaisOfw1t+TfZzooPW9ZD4we02xZKRHsNspb5mNqZrihY 6X2+A0XBLeSZSco4dafmOQ5SBzya0LOS5e3Cb8fJRa2fO7CVoO9oRIHP5K9aMeOFbN76 QIam82coNksFbpinnUe6jEV/WrdaeKDXBEijrPI0YVs89kBirAnfVT9GzWUPi4egyvQC Dl3g== 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=vye8HxSgbJ5V+jvH1roXnBTgLilfVcEjREHvPLd1+J4=; b=m7yegr31mTC1R6ziJUC3NvEs47TTI/bfNBIK3qmqbtBWSKEn1+e0dq9j2fKFMfI4qS FHAsdU+O9UvTNqJElF9zpnyQOTYN1J8CO9qNH6Fmb/RJEgPwx17oB9c/3etDoMEkbMum ngfKukWjJXL1xvCajY31U5Yj+7Iw0sUD3At2rHeqoM0+7mBeTm4olHh/C6wWn5+Kqw6R dRrtLsi08QVy/oR5731yNcvbZ2gux0kq0DOfJYMjnD6lVL23VESZ13tA8lBtEYPyz7fz g0bMJrRHQFQHg2J77YJvCdnCIIL3K7RB5OWbQyz7Hp2xDWUVSceb3dBDkdut1bfbXA+U Zw5A== X-Gm-Message-State: ACrzQf0oauxjTCZ3gM2VtMC7AK7GDIe0goUpll85ULCSrrKD3F5WkbZF yyjuf2KYm3MQUOQPDwxlihA= X-Received: by 2002:a7b:c5d6:0:b0:3c6:f970:e755 with SMTP id n22-20020a7bc5d6000000b003c6f970e755mr13080991wmk.132.1667332447328; Tue, 01 Nov 2022 12:54:07 -0700 (PDT) Received: from localhost.localdomain ([46.249.74.23]) by smtp.gmail.com with ESMTPSA id p11-20020a05600c468b00b003cf75213bb9sm6092617wmo.8.2022.11.01.12.54.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Nov 2022 12:54:06 -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: Tue, 1 Nov 2022 21:53:44 +0200 Message-Id: <1667332425-12536-3-git-send-email-ivo.g.dimitrov.75@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1667332425-12536-1-git-send-email-ivo.g.dimitrov.75@gmail.com> References: <1667332425-12536-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?1748325045826315889?= X-GMAIL-MSGID: =?utf-8?q?1748325045826315889?= 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 2659df7..4cfc325 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) {