From patchwork Tue Dec 5 22:16:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 10094043 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 EE75460329 for ; Tue, 5 Dec 2017 22:34:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E041828731 for ; Tue, 5 Dec 2017 22:34:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4C31289B3; Tue, 5 Dec 2017 22:34:26 +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=unavailable 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 61E0428731 for ; Tue, 5 Dec 2017 22:34:26 +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:Subject:From:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ykHEuY9lFQ4jJQXbwBY1uaDdZfFJW78ehXbn9V9mn6E=; b=t6z0E+AeL87juI eqN0+Sw5ZtNmq5/SfH20bCFSRcbguxKNrFa8sLHmg0kLNc5FgcmzKxrXTvHT0W8Cpb0eGHp97L6so 2NEcPAfupF3NWrr2rl01JTpg0P80KSaj2SinBSkZmmlkLSNyHLMMkvdpd3WrytEZv5BPZbuB6iS0o zUHGf3M8BJAIbNh47ONG6nAurGhbaYfjSJSzSpC/Cu+4Io8CuPxtKPX3CGdRzoybcR2S5wjCoain6 LkD9LAyPt9Dj/M2bXNPpBUzNP3Oi7wUJVDCXu7wap4o5MO5DoEmBkkQfSRoNctWqiGdYIt0rjzswZ Zrm3O55kz/wHfs8a54DQ==; 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 1eMLnA-0003fH-Lv; Tue, 05 Dec 2017 22:34:20 +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 1eMLXF-0006zj-Oc; Tue, 05 Dec 2017 22:17:58 +0000 Received: by mail-wm0-x241.google.com with SMTP id l141so4042855wmg.1; Tue, 05 Dec 2017 14:17:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=lspATkBzejjlXE/LMzKG//71rlWUCYnY9i4ScaxitYM=; b=UphGIAqzzf83zgEplx8+Ysc0e6b8tYD5hKKG0yvl6Wg5zIe7JdRThkE52Qe8BHjatm 3ACbl+iQ428eI6Ta28WG2571o/9K3XRQb00bQdac86FwdmJUsDiHyuDhRGiD67J4NM4w OczyGv2L05OxPf6+fI7Q6Vt9uJpizidW69aktA1W/drZUz67sYhsDtzXxi6KiF2ChWs3 EvFS3YdotnZrFFewUYkTPEq7EedxBlEEsGyRYRee6fF42nL1hTVkt06CNzc9YCPiZvqd BYrmwPDNN2Pyvq8h4skrjiHaqW75WbzwmU/tVJ1h/AN+4HKT/Ac20LYymuSuonEEt5gz VAwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=lspATkBzejjlXE/LMzKG//71rlWUCYnY9i4ScaxitYM=; b=Ll9UR6W6H4bSxeI5X6i/FNDWBvshF2poaKsrI0si/5DZqGJe3gyT+gl7VqadtDS+WH soV8vKvKMNRfKCWK8M6sDqY4DdGuL74wDqYm+niiqfI7r9eB7aVQ2vZT06fthvtScKp6 TTZdJQK6Nb51p4WwPIf5GbdlKuEcqOHWmX7cnJQQJ2IiAN1P/YMqZ7QClKHXU2D/zp6O F29OpXm7+cIQGrykyTOipKqt30ZR6l8wA7OG3XzVIv5DqVj32Wm3WbqQTsGyMi7MwjoJ tOJDdZg/VE5ytheC/jYIfB/mk7dnE/4jRWIsVNigiGmfhcsQpa8ciJv6ct4Mq1jdqXFb 1jyQ== X-Gm-Message-State: AKGB3mKJtLIjPP5tzjn1jZPMIgZ6+jHI+zQ1U1eROK+tS0D31UodGo3G 8RfQfhtvJBxGNLvoPVAcFcI= X-Google-Smtp-Source: AGs4zMboWM7b+xayS5Qlc9mw8pvqVAZVHSvP48B2+NemE4UJYPu8n7lcQXoYGKYzlUixgQjXUzK62g== X-Received: by 10.28.214.145 with SMTP id n139mr7750364wmg.59.1512512251825; Tue, 05 Dec 2017 14:17:31 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:b595:9d9d:56de:88e3? (p200300EA8BC0E400B5959D9D56DE88E3.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:b595:9d9d:56de:88e3]) by smtp.googlemail.com with ESMTPSA id f18sm1182480wrg.66.2017.12.05.14.17.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Dec 2017 14:17:31 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 05/12] firmware: arm_scpi: improve handling of protocol and firmware version subfields To: Sudeep Holla References: <99220c79-8b35-2978-11d1-6d101ccb6772@gmail.com> Message-ID: Date: Tue, 5 Dec 2017 23:16:55 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <99220c79-8b35-2978-11d1-6d101ccb6772@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171205_141754_041874_EE3BCCCA X-CRM114-Status: UNSURE ( 9.26 ) X-CRM114-Notice: Please train this message. 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: "open list:ARM/Amlogic Meson..." , "linux-arm-kernel@lists.infradead.org" , Kevin Hilman 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 9eeb53b7..63441e40 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)) @@ -861,9 +856,9 @@ static ssize_t protocol_version_show(struct device *dev, { struct scpi_drvinfo *scpi_info = dev_get_drvdata(dev); - 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); @@ -872,10 +867,10 @@ static ssize_t firmware_version_show(struct device *dev, { struct scpi_drvinfo *scpi_info = dev_get_drvdata(dev); - 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); @@ -1031,12 +1026,12 @@ static int scpi_probe(struct platform_device *pdev) return ret; } - _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)); scpi_info->scpi_ops = &scpi_ops; ret = devm_device_add_groups(dev, versions_groups);