From patchwork Sun Jul 9 02:16:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Breck X-Patchwork-Id: 9831593 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 09093602BD for ; Sun, 9 Jul 2017 02:17:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E71B5251F4 for ; Sun, 9 Jul 2017 02:17:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB7142656B; Sun, 9 Jul 2017 02:17:44 +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 84583251F4 for ; Sun, 9 Jul 2017 02:17:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751906AbdGICRn (ORCPT ); Sat, 8 Jul 2017 22:17:43 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:36277 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751654AbdGICRn (ORCPT ); Sat, 8 Jul 2017 22:17:43 -0400 Received: by mail-pf0-f195.google.com with SMTP id z6so9736878pfk.3 for ; Sat, 08 Jul 2017 19:17:42 -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=09+ulgYN95JCwzJ+tpIeBrBKUO0V6oyMbFC+Uk/teKY=; b=qjOVChWmjtyZ8KoxDSpf+8vGTcV3h6nJpJJ9AgH7gSvLJDoTWDHlWgwkE6BE2fbzsO 0R+4TRx+OEzuQdfpaoKjcqTNQZkyGSSMjs5pGIGQbonGXgaPk9k0OPPCBaijMDs7llwV J7vAb9RoVLKU6msrEv+UjyS+jS0kmqxSVWiFjCuelHDIOfstDyF4Ri3Dq3fEZFjn0RGl U+/VF0HedypVdhwS5fCJlgW7AJm969a5+xN1mXPPyMWDxk4PZKxpaObXnsDStDk0Ll97 KgE7bUjtXsAeZ6AnjP80QQ+dyG3dH6cZT1IMQjeWuIQIf94BTi2vMCXwEeD7tFucMMPi KQfg== 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=09+ulgYN95JCwzJ+tpIeBrBKUO0V6oyMbFC+Uk/teKY=; b=a+ddB5ISSGNo72d6UPy/j8ve0yFCoAtY6wFXN7WFIRs57wGH+l7ho0AKv617PqJUfD TmXfBl3XXRZtG4N+HQlExMiY9ytzjqACwNVfuaLrVdxymLKyxHXgCZgaGV6GaSvoRkq1 eeLrlgpgfaLPQsR9tQ3aTqvp19ii3/sxhS7sGgn1+fJ+Z86xl+0+3gnxKGGYEoZyFZHx CR388Rjud8CuUHIixBwRufUjii/eum1ww/uuYap1XWUUzGqevP6xk+lxRjyLmTMBZ293 9/doxLvQLIJUC8Mw9GCSH2m2bfbgbSTMDyDVC20nNpg3K05IHqHtKpGthEjoXnygXd/P pCew== X-Gm-Message-State: AIVw1127Cvj+2MjY478FjiDeO8tVbwOb+liAGIG5wNc5bQw69FLpvmpS AFC33a9qjvOBfQ== X-Received: by 10.99.54.205 with SMTP id d196mr5426346pga.79.1499566662326; Sat, 08 Jul 2017 19:17:42 -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 h184sm14994026pge.66.2017.07.08.19.17.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Jul 2017 19:17:41 -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: [RFC v1 5/6] power: supply: bq27xxx: Flag identical chip data when in debug mode Date: Sat, 8 Jul 2017 19:16:59 -0700 Message-Id: <20170709021700.14354-6-liam@networkimprov.net> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170709021700.14354-1-liam@networkimprov.net> References: <20170709021700.14354-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 | 36 +++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c index 5d3893a9..54755c88 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 = bq27##ref##_props, \ .props_size = ARRAY_SIZE(bq27##ref##_props) } -static struct { +static struct bq27xxx_chip_datum { u32 opts; int acts_like; //todo drop this when opts fully implemented u32 unseal_key; @@ -918,6 +918,38 @@ static struct { [BQ27621] = BQ27XXX_DATA(621, BQ27421, 0x80008000, BQ27XXX_O_CFGUP | BQ27XXX_O_RAM), }; +static void __maybe_unused bq27xxx_battery_dbg_dupes(struct bq27xxx_device_info *di) +{ + 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; + + 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)) + dev_warn(di->dev, msg, i, "props", j, "props"); + + if (a->dm_regs != b->dm_regs && + !memcmp(a->dm_regs, b->dm_regs, sizeof(bq27500_dm_regs))) + dev_warn(di->dev, msg, i, "dm_regs", j, "dm_regs"); + } + } +} +#ifndef DEBUG +#define bq27xxx_battery_dbg_dupes(di) +#endif + static DEFINE_MUTEX(bq27xxx_list_lock); static LIST_HEAD(bq27xxx_battery_devices); @@ -1989,6 +2021,8 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di) .drv_data = di, }; + bq27xxx_battery_dbg_dupes(di); + INIT_DELAYED_WORK(&di->work, bq27xxx_battery_poll); mutex_init(&di->lock);