From patchwork Wed Oct 4 19:00:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9985399 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 56FFB60586 for ; Wed, 4 Oct 2017 19:06:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4643928BF1 for ; Wed, 4 Oct 2017 19:06:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B3AA28BF3; Wed, 4 Oct 2017 19:06:01 +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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 93D2828BF1 for ; Wed, 4 Oct 2017 19:06:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:References:To:From:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lcAd76WFg7LVQihxBrezkc0+fc+zutQymcOz0fxgieQ=; b=B8N9iKoB5ucBsC KvPH3OksDQM52RTGYjqvYy9F7LrfVo2SP1M7qCYtNrnYXZ4UruI+uH+qOIMdyXs/CCLXeS+30FeyO auXtO0mOYwz+f6xNQ4GhSHiON0N5aFT03cgnRuuJ374QJcO0SsUPda/AtdmEpiGC5oVHq9ixJUzXp mCgSEgNfzF5JhXEWdCnQFMIbeCYnp54eSieDLi9OFDsO4dPGBMbu/66O9dqVmGM9qsukRnCL4pTvN DuAOAl8KEY1umtoDi77CnihW5uqI8VNF2EJKcUhiGtmT4nyczzEAZyV8QSUROT7SQhCYJHw229cKi sbZ9pl8v9T1HyJtAnG2g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dzozQ-00036e-1H; Wed, 04 Oct 2017 19:05:52 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dzozM-00032r-Bu for linux-arm-kernel@lists.infradead.org; Wed, 04 Oct 2017 19:05:50 +0000 Received: by mail-wm0-x241.google.com with SMTP id 131so2123324wmk.3 for ; Wed, 04 Oct 2017 12:05:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=6uXbHMYsFh8FMzhUtXDcLJU7YQQ5OJ3SDbvOeUZHo24=; b=OAV4G9ryt8TmmcoCR69xrNn7kBA7jZJiLLXRLs3CXew76C62bC4vpTKHUYGGfSEmZw rY+ykGFsR6yNMSkoUBeZ108r1cQfCcK4Xu4FTj2uYIRHBVwoHt/5Xnft4M+glYyfwq5b UDffI/Quk0AS1X/sA5sBB1/BFOhYA81RVWOfFU0VtNaijjB2g2ZPkjoBtkX5Apy585kO f57ghgmQqi3lw1FeHKtCb4nErDa0ya1kWBwUeOjALHDmVEEMxYg1C6pP6yxjXVXujlpI K7OrCtMxMLdAdy+b/3sVMebHMiyLq3LTKq9QxZkzXsOxmEuz9vlsnu5T6t3cvSJzNwkx 3/KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=6uXbHMYsFh8FMzhUtXDcLJU7YQQ5OJ3SDbvOeUZHo24=; b=nCpJvDcJR58JVJKonE5kmZWgBOGYfCfaq3xaTWUJ6ErdBG8o4nvaeYyW1vStnNNqnb qjtzOhuR4AedD251+0O2eO7PYqlKSbWdsHbpq1AU5oYWhkEzeYyaqcygMBpsN/Lv2w16 CIJjfjH/gScrdAlQi9ed8sT843arpnD19EfKJ7UzQq7aTApQ/rmnE4BT6GdYQa2PJ7O2 wj24iNYH8VqhInBa22bD4DIxmmeA1VF1OHkwSehaMMIm/Wuc1RIaIhGSPZzzfNQfTKsI J0HXyEcjICufk+PIDPE6ovkINmJ4rpgj+VdkuozDP+EXdT3mnGt++mPnxbC6jDr1Z1yU HKAA== X-Gm-Message-State: AHPjjUhCAdKceDyaFY1UMqznzdbEAwzuJMyygLxCnR5gGBD8KX3SZxLg 9gb3sKxgiHHW9zb5WZFu68tXRA== X-Google-Smtp-Source: AOwi7QA9Utx+ggMBQ4ata5lh3DvyJWQnNIZjCHVwPuQAm1Th2c7V5qZZ5yoxx2YoztD12oN7dGHJag== X-Received: by 10.80.169.11 with SMTP id l11mr29031359edc.126.1507143926266; Wed, 04 Oct 2017 12:05:26 -0700 (PDT) Received: from ?IPv6:2003:ea:8bcb:c500:f1c6:db5b:325:736? (p200300EA8BCBC500F1C6DB5B03250736.dip0.t-ipconnect.de. [2003:ea:8bcb:c500:f1c6:db5b:325:736]) by smtp.googlemail.com with ESMTPSA id e50sm13463817ede.18.2017.10.04.12.05.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Oct 2017 12:05:25 -0700 (PDT) Subject: [PATCH 2/3] firmware: arm_scpi: improve handling of protocol and firmware version subfields From: Heiner Kallweit To: Sudeep Holla References: <16d1cd8c-e124-cc94-ca29-d7cb04ff26d9@gmail.com> Message-ID: <54b28f23-d650-5f74-7fb9-499864f57bc3@gmail.com> Date: Wed, 4 Oct 2017 21:00:39 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <16d1cd8c-e124-cc94-ca29-d7cb04ff26d9@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171004_120548_665721_F6F8D96A X-CRM114-Status: GOOD ( 10.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "linux-arm-kernel@lists.infradead.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP By using FIELD_GET and proper masks we can avoid quite some shifting and masking macro magic and make the code better readable. Signed-off-by: Heiner Kallweit --- drivers/firmware/arm_scpi.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index 412f1c4c..d305b926 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -28,6 +28,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include +#include #include #include #include @@ -73,18 +74,12 @@ #define MAX_DVFS_DOMAINS 8 #define MAX_DVFS_OPPS 16 -#define PROTOCOL_REV_MINOR_BITS 16 -#define PROTOCOL_REV_MINOR_MASK ((1U << PROTOCOL_REV_MINOR_BITS) - 1) -#define PROTOCOL_REV_MAJOR(x) ((x) >> PROTOCOL_REV_MINOR_BITS) -#define PROTOCOL_REV_MINOR(x) ((x) & PROTOCOL_REV_MINOR_MASK) +#define PROTO_REV_MAJOR_MASK GENMASK(31, 16) +#define PROTO_REV_MINOR_MASK GENMASK(15, 0) -#define FW_REV_MAJOR_BITS 24 -#define FW_REV_MINOR_BITS 16 -#define FW_REV_PATCH_MASK ((1U << FW_REV_MINOR_BITS) - 1) -#define FW_REV_MINOR_MASK ((1U << FW_REV_MAJOR_BITS) - 1) -#define FW_REV_MAJOR(x) ((x) >> FW_REV_MAJOR_BITS) -#define FW_REV_MINOR(x) (((x) & FW_REV_MINOR_MASK) >> FW_REV_MINOR_BITS) -#define FW_REV_PATCH(x) ((x) & FW_REV_PATCH_MASK) +#define FW_REV_MAJOR_MASK GENMASK(31, 24) +#define FW_REV_MINOR_MASK GENMASK(23, 16) +#define FW_REV_PATCH_MASK GENMASK(15, 0) #define MAX_RX_TIMEOUT (msecs_to_jiffies(30)) @@ -867,19 +862,19 @@ static int scpi_init_versions(struct scpi_drvinfo *info) static ssize_t protocol_version_show(struct device *dev, struct device_attribute *attr, char *buf) { - return sprintf(buf, "%d.%d\n", - PROTOCOL_REV_MAJOR(scpi_info->protocol_version), - PROTOCOL_REV_MINOR(scpi_info->protocol_version)); + return sprintf(buf, "%lu.%lu\n", + FIELD_GET(PROTO_REV_MAJOR_MASK, scpi_info->protocol_version), + FIELD_GET(PROTO_REV_MINOR_MASK, scpi_info->protocol_version)); } static DEVICE_ATTR_RO(protocol_version); static ssize_t firmware_version_show(struct device *dev, struct device_attribute *attr, char *buf) { - return sprintf(buf, "%d.%d.%d\n", - FW_REV_MAJOR(scpi_info->firmware_version), - FW_REV_MINOR(scpi_info->firmware_version), - FW_REV_PATCH(scpi_info->firmware_version)); + return sprintf(buf, "%lu.%lu.%lu\n", + FIELD_GET(FW_REV_MAJOR_MASK, scpi_info->firmware_version), + FIELD_GET(FW_REV_MINOR_MASK, scpi_info->firmware_version), + FIELD_GET(FW_REV_PATCH_MASK, scpi_info->firmware_version)); } static DEVICE_ATTR_RO(firmware_version); @@ -1021,12 +1016,12 @@ static int scpi_probe(struct platform_device *pdev) scpi_dvfs_populate(dev); - _dev_info(dev, "SCP Protocol %d.%d Firmware %d.%d.%d version\n", - PROTOCOL_REV_MAJOR(scpi_info->protocol_version), - PROTOCOL_REV_MINOR(scpi_info->protocol_version), - FW_REV_MAJOR(scpi_info->firmware_version), - FW_REV_MINOR(scpi_info->firmware_version), - FW_REV_PATCH(scpi_info->firmware_version)); + _dev_info(dev, "SCP Protocol %lu.%lu Firmware %lu.%lu.%lu version\n", + FIELD_GET(PROTO_REV_MAJOR_MASK, scpi_info->protocol_version), + FIELD_GET(PROTO_REV_MINOR_MASK, scpi_info->protocol_version), + FIELD_GET(FW_REV_MAJOR_MASK, scpi_info->firmware_version), + FIELD_GET(FW_REV_MINOR_MASK, scpi_info->firmware_version), + FIELD_GET(FW_REV_PATCH_MASK, scpi_info->firmware_version)); ret = devm_device_add_groups(dev, versions_groups); if (ret)