From patchwork Sun Jun 14 23:58:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 209479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4431CC433DF for ; Mon, 15 Jun 2020 00:00:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A9C020768 for ; Mon, 15 Jun 2020 00:00:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NKZC7N2D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728068AbgFOAAX (ORCPT ); Sun, 14 Jun 2020 20:00:23 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:33330 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728060AbgFOAAV (ORCPT ); Sun, 14 Jun 2020 20:00:21 -0400 Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B05C31250; Mon, 15 Jun 2020 02:00:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1592179213; bh=6lIwMDPvKgYPI+JwF/2nL+6il7im5lRCeEGGl/bGOEI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NKZC7N2DR+A0DerPmloWxxSlLMFnMaNPB/dzCqJCFLpGNH9JuhKiqoGP1YZ71NgPj 0zJxEjo5bOl0BJacbmZEkN5UWrm98+sjQiAXLqeHuHACivJhFjMsPmRl+wpetXfiKX Phtz5Fu3Br6vBosFNfN6fQszPsT7lwM5kWBHlQBE= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Tomi Valkeinen , Benoit Parrot Subject: [PATCH v1 008/107] media: ti-vpe: cal: Turn reg_(read|write)_field() into inline functions Date: Mon, 15 Jun 2020 02:58:05 +0300 Message-Id: <20200614235944.17716-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200614235944.17716-1-laurent.pinchart@ideasonboard.com> References: <20200614235944.17716-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Turn the reg_(read|write)_field() macros into inline functions for additional type safety. Use the FIELD_GET() and FIELD_PREP() macros internally instead of reinventing the wheel. Signed-off-by: Laurent Pinchart --- drivers/media/platform/ti-vpe/cal.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c index fa86a53882cc..8c068af936f0 100644 --- a/drivers/media/platform/ti-vpe/cal.c +++ b/drivers/media/platform/ti-vpe/cal.c @@ -6,6 +6,7 @@ * Benoit Parrot, */ +#include #include #include #include @@ -76,13 +77,6 @@ static const struct v4l2_fract #define reg_read(dev, offset) ioread32(dev->base + offset) #define reg_write(dev, offset, val) iowrite32(val, dev->base + offset) -#define reg_read_field(dev, offset, mask) get_field(reg_read(dev, offset), \ - mask) -#define reg_write_field(dev, offset, field, mask) { \ - u32 val = reg_read(dev, offset); \ - set_field(&val, field, mask); \ - reg_write(dev, offset, val); } - /* ------------------------------------------------------------------ * Basic structures * ------------------------------------------------------------------ @@ -418,6 +412,21 @@ struct cal_ctx { bool dma_act; }; +static inline u32 reg_read_field(struct cal_dev *dev, u32 offset, u32 mask) +{ + return FIELD_GET(mask, reg_read(dev, offset)); +} + +static inline void reg_write_field(struct cal_dev *dev, u32 offset, u32 value, + u32 mask) +{ + u32 val = reg_read(dev, offset); + + val &= ~mask; + val |= FIELD_PREP(mask, value); + reg_write(dev, offset, val); +} + static const struct cal_fmt *find_format_by_pix(struct cal_ctx *ctx, u32 pixelformat) { @@ -453,11 +462,6 @@ static inline struct cal_ctx *notifier_to_ctx(struct v4l2_async_notifier *n) return container_of(n, struct cal_ctx, notifier); } -static inline int get_field(u32 value, u32 mask) -{ - return (value & mask) >> __ffs(mask); -} - static inline void set_field(u32 *valp, u32 field, u32 mask) { u32 val = *valp;