From patchwork Thu Aug 24 03:36:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Breck X-Patchwork-Id: 9918953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1A0D8603FA for ; Thu, 24 Aug 2017 03:37:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1016928B0E for ; Thu, 24 Aug 2017 03:37:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04EC328B1B; Thu, 24 Aug 2017 03:37:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FB3C28B1A for ; Thu, 24 Aug 2017 03:36:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751133AbdHXDg6 (ORCPT ); Wed, 23 Aug 2017 23:36:58 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35842 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751062AbdHXDg5 (ORCPT ); Wed, 23 Aug 2017 23:36:57 -0400 Received: by mail-pg0-f66.google.com with SMTP id m7so1961400pga.3 for ; Wed, 23 Aug 2017 20:36:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=8WPjkwhMgjWiRWZeVNFkFHGFFNsTDOjeLd0NIi1gQic=; b=lydNJD/nf5PG5acnR0YPm/7tiNmq5WKKj9skkbdIjcmTDYYJAONTKSRlIWx3MWVAZv gskgJTh2TIDig646WnHWlRSLxvHJO6xOJpanEA0MWibmjN5O2q1gXJ09VrljAhZzTMAY oSW+AbcAn1pZObKVA67udOtZ/Dqikzh6Z7lkRXxHSTnmUw1+GECWe0k0U8n2iSmstzUh zAoM+SXUcLUH9H2kGEGeDsaXG58C0ChgZxRB9CkUOE/zWOdJuxfbitrfCryln8Lqbeje P3R2jkt4eK5IgHCulwhKC5pDHSZB7Xpbsy6CCB0bH5yhO/V7Ip19G149+wDVSWuybcAD ZOEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=8WPjkwhMgjWiRWZeVNFkFHGFFNsTDOjeLd0NIi1gQic=; b=JEhYsEJOir9LKFEbj76Oj66crsZ0OTR45qN6BNgYvT3ZYrijENKUQn+DCDslzzjDFM gUpdCTLBdqwRypM2weD4jmfpuQMXjz3exG+irp6FLmsBuqLM9WiwGsjH1VD5kiihb2yB dog4cQy8OGP2Xkdpqe9tJl//+qSpcUtO+N9CZ5j9P6QqNqhO2mDwQnsQKF/CQ2iWyF1x 9gZ4PYkMzirtcHpUWGbunhWux1kYsksVb8Bsio3XV2Nx1WyPBLZbVuJtmUtvJXK7gogX Uica963zXgENWhqStpS3qtN/XKJezXb5G255iab3NAGqeI0hERx0zxwbjQ1RhnpJO82U 2FqQ== X-Gm-Message-State: AHYfb5hyO2h1+iYQ3xEMG2+LB2FFk04cXbQ8Dts8b+/40titFZ5tAqh3 mgn2epRDM6G87w== X-Received: by 10.84.128.75 with SMTP id 69mr5373863pla.58.1503545817477; Wed, 23 Aug 2017 20:36:57 -0700 (PDT) Received: from localhost.localdomain (c-73-223-93-234.hsd1.ca.comcast.net. [73.223.93.234]) by smtp.gmail.com with ESMTPSA id d69sm5094236pfe.49.2017.08.23.20.36.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Aug 2017 20:36:56 -0700 (PDT) From: Liam Breck To: Sebastian Reichel , =?UTF-8?q?Pali=20Roh=C3=A1r?= , linux-pm@vger.kernel.org Cc: Paul Kocialkowski , Liam Breck Subject: [PATCH v3 4/5] power: supply: bq27xxx: Flag identical chip data when in debug mode Date: Wed, 23 Aug 2017 20:36:16 -0700 Message-Id: <20170824033617.20840-5-liam@networkimprov.net> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170824033617.20840-1-liam@networkimprov.net> References: <20170824033617.20840-1-liam@networkimprov.net> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Liam Breck The driver has 13 unique register maps, several of which are shared by multiple chips. When adding support for a new chip, it's easy to add a duplicate map by mistake. In debug mode we now scan bq27xxx_chip_data[n].regs/props/dm_regs for duplicates. Signed-off-by: Liam Breck --- drivers/power/supply/bq27xxx_battery.c | 39 +++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c index f2e55b90..3a6b9549 100644 --- a/drivers/power/supply/bq27xxx_battery.c +++ b/drivers/power/supply/bq27xxx_battery.c @@ -883,7 +883,7 @@ static struct bq27xxx_dm_reg bq27621_dm_regs[] = { .props = ref##_props, \ .props_size = ARRAY_SIZE(ref##_props) } -static struct { +static struct bq27xxx_chip_datum { u32 opts; u32 unseal_key; u8 *regs; @@ -917,6 +917,39 @@ static struct { [BQ27621] = BQ27XXX_DATA(bq27621, 0x80008000, BQ27XXX_O_UTOT | BQ27XXX_O_CFGUP | BQ27XXX_O_RAM), }; +static void __maybe_unused bq27xxx_battery_dbg_dupes(struct bq27xxx_device_info *di) +{ + static bool once = false; + const size_t max = ARRAY_SIZE(bq27xxx_chip_data); + const char * const msg = "bq27xxx_chip_data[%d].%s & [%d].%s are identical\n"; + struct bq27xxx_chip_datum *a, *b; + int i, j; + + if (once) + return; + once = true; + + for (i = 1; i < max-1; i++) { + a = bq27xxx_chip_data + i; + + for (j = i+1; j < max; j++) { + b = bq27xxx_chip_data + j; + + if (a->regs != b->regs && + !memcmp(a->regs, b->regs, sizeof(bq27000_regs))) + dev_warn(di->dev, msg, i, "regs", j, "regs"); + + if (a->props != b->props && a->props_size == b->props_size && + !memcmp(a->props, b->props, a->props_size * sizeof(a->props[0]))) + dev_warn(di->dev, msg, i, "props", j, "props"); + + if (a->dm_regs != b->dm_regs && a->dm_regs && b->dm_regs && + !memcmp(a->dm_regs, b->dm_regs, sizeof(bq27425_dm_regs))) + dev_warn(di->dev, msg, i, "dm_regs", j, "dm_regs"); + } + } +} + static DEFINE_MUTEX(bq27xxx_list_lock); static LIST_HEAD(bq27xxx_battery_devices); @@ -1974,6 +2007,10 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di) .drv_data = di, }; +#ifdef DEBUG + bq27xxx_battery_dbg_dupes(di); +#endif + INIT_DELAYED_WORK(&di->work, bq27xxx_battery_poll); mutex_init(&di->lock);