From patchwork Sat Nov 11 10:41:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3000 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 394B33F057 for ; Sat, 11 Nov 2023 11:42:42 +0100 (CET) Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-542d910f34bsf2132658a12.3 for ; Sat, 11 Nov 2023 02:42:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699699362; cv=pass; d=google.com; s=arc-20160816; b=NRWGfxgUSTFd4PKTuQAmVMvmuhBXpBEFKxG28QPFrfxquZF4B1J89izbNpslISzAIo AoiLyZvW7EAxnklgMHWNdvNeMDGYGnR67bh3yxfvtiSUrRfPh33YZ9aLzzHupSJ/O6fl zdEXPMIQ1YMEav08Zp3GZrug11nf8D05MQ2Eykaq7QxCcP5m2jfSWWQlU8arRdjEVMbd +Z7OhbsSIexDHF+Cfp5r687guQ8Tm09dqkUlaCpnb4Wl+TjculGaOhDubnfPA7ji5IQu WvKEHRzky+Jhhv+/66v1LVu4cfraQQJigFMaxUK3OVPGY0IrJrpBqMQIVfKPqGhTjIGw RmZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=eFItHm4yzYce4R10MhN1KkWpSPlJbehp7eQirD960uw=; fh=CRQFspQ+XVmz3jTpDmawxjgq3paXQGVEDP+3Wpr+FXU=; b=pwJcHQdeNuymhecakjV4SygyUgfiFe5XfVtrDYqLFypBmT9UgEvcPkVPbWJr0shnda fDUM9XENizjXs3ZPeMyDtAP2dj5D0hR0N44PQf1rz3o0jeOvlMkmu73ruh6+kknmy1ti 14nsl4awzk+yhJTck6s5pkEGa8tazenE+ApGEv29yrMgH3olminXjIzxWNFWnWrMo2fV Z5kJ5l0ymd9ersEvAcmI9SlS/F2m8TizB+XJLLFMnkto5aDQ9ID/xCsWyu6Gcyt8cRIN RmgaONCBK1RYmTLeOL1P9wwJzy0w+kdWPR+TcVnPiS2LyNy0I+waaJcLCgXLr0Shfgck 8/VA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EQ2oF+Wo; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1699699362; x=1700304162; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=eFItHm4yzYce4R10MhN1KkWpSPlJbehp7eQirD960uw=; b=dRta5oMKMEs2M7mfNGghWb0A576ihTbXn+NOuVouI90QWunRF1o6Szf3ulkKaCqzbV 8uH2/MpsDJIArdoDPydjFypLabFtbC724ymrSeTZKyFqa9RoZAgot3zh77Gen9EEO65E IpKpTFHYajqnovYWZvGVcV/q1iMhB06HRa6x4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699699362; x=1700304162; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eFItHm4yzYce4R10MhN1KkWpSPlJbehp7eQirD960uw=; b=iHCnjh0mN8V3rvmXacCY2GMlJ3AenOjqa4+kWKNsg/reuJfFLLOYtxOlaNvvHIW09R moCqo5/610zsT0TdgustMz31/k3zTFQj/9Q4oenzHVkHtzuyS6nWbcxorMIOgMH04fC2 EOW3fxHV/OuY4TNFpUQmX6PRsy1iD3kzOCWFN3icEFJjYLJ3pDasWcmZJa+thC6qTC5e 5FVC420aGrqa8ywNolbceCeV6Un2zQUhUTiXQqNPvFeSz2pZMaNVsJS4ruG126gmjzrC M1PHZapN5f3FTUfl/XDsqwArYMQXoiQ6C961VDytTlr+LKkBIX3tC0gB7h+2tE8c3wQa fygw== X-Gm-Message-State: AOJu0YyFr4xTC3pVy3Hi5GGxkpnTVRN7+s21EbKF+AyRW5wbv+RGxXgU keSixRt0r+M+DKYi9JOq+/1Z4xbd X-Google-Smtp-Source: AGHT+IGZSDhlZ/WOZnLAj6/YHr81Q8JOVgmR4q/o+vjrkd92gwMh6floQHP0L0d9THTX1b7PSXtn7w== X-Received: by 2002:a05:6402:1042:b0:540:c989:fcdd with SMTP id e2-20020a056402104200b00540c989fcddmr1279868edu.11.1699699362048; Sat, 11 Nov 2023 02:42:42 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:aa7:d044:0:b0:53d:beed:e28f with SMTP id n4-20020aa7d044000000b0053dbeede28fls656694edo.1.-pod-prod-02-eu; Sat, 11 Nov 2023 02:42:40 -0800 (PST) X-Received: by 2002:a17:906:4351:b0:9df:bc50:2508 with SMTP id z17-20020a170906435100b009dfbc502508mr882314ejm.57.1699699360446; Sat, 11 Nov 2023 02:42:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699699360; cv=none; d=google.com; s=arc-20160816; b=LWk2EbIiVrBtahTm/KAUv44JVv8fI/QhyJ/JarXA51TF3BZQOxQbZDt2I6Fk8AMnZ0 HY0Yy2hfKMJSc08vBLksCROfo8zt5EWYeS5l22NyN+WkHx9ZDNncte0WTxC5yZADgHF8 lF7PIZW+my75BZwNaFikH2InS/rhSfZut9D95mv64QKfm7d8u0GDvROvOm51fFAvQEqG gpNKaBAalW9SyEcA98yriELiThT5Wk+kR/mv601V0bv8UG5yttzl/gGLD1GWiFx+4sgS 2VKOy3hnCxysNoYwUJ7y7HixCBprXA5nBXORulh8KvPlV3mcygf1VGw1FGu+Ay0ptpWl ocFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=GD7GxvQQhDBqOuYxhMX/0KhWBgo/RCUVCo38r5g0tkk=; fh=CRQFspQ+XVmz3jTpDmawxjgq3paXQGVEDP+3Wpr+FXU=; b=snDga3HSS4FRja4gmt24pJsBsSCx5fIx3m2G/dgk044cquJpMTcoz/A8slWMwbtSgi Mftp40i/OFT71QINxXo03627LcwH/7SYkQmBdTBjU6ZkXGMZFbKWheRfHbasM+3qM1Tn 66BFQ5QaV0jo0TrMOaaVYnMnnZrrRnt/cpAuYg9D+YIK1cIglzCW9/b3ie7l0WseyrrR z4tVEpXPydqWNAvwcFxuzbtAYwqB1LMEGbWgB1RfI9Tzq3nn31WBVamm3WRnbD4mR6qJ Q3jnYvjMCB4Vfk0LmYqumLcy8E3mgEP3cxSvhA9xkCaM7EqYsuQz78YxaEn+X2wUuEtw 3TvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EQ2oF+Wo; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 20-20020a17090602d400b009ae5d029dadsor250255ejk.18.2023.11.11.02.42.40 for (Google Transport Security); Sat, 11 Nov 2023 02:42:40 -0800 (PST) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:906:7f94:b0:9c4:67f:3ef5 with SMTP id f20-20020a1709067f9400b009c4067f3ef5mr1052700ejr.50.1699699359971; Sat, 11 Nov 2023 02:42:39 -0800 (PST) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-79-20-97-182.retail.telecomitalia.it. [79.20.97.182]) by smtp.gmail.com with ESMTPSA id ga33-20020a1709070c2100b0099e12a49c8fsm872183ejc.173.2023.11.11.02.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Nov 2023 02:42:39 -0800 (PST) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: linux-amarula@amarulasolutions.com, Dario Binacchi , Fabio Estevam , Helge Deller , NXP Linux Team , Pengutronix Kernel Team , Sascha Hauer , Shawn Guo , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-fbdev@vger.kernel.org Subject: [PATCH 03/10] fbdev: imxfb: use BIT, FIELD_{GET, PREP} and GENMASK macros Date: Sat, 11 Nov 2023 11:41:52 +0100 Message-ID: <20231111104225.136512-4-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231111104225.136512-1-dario.binacchi@amarulasolutions.com> References: <20231111104225.136512-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EQ2oF+Wo; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Replace opencoded masking and shifting, with BIT(), GENMASK(), FIELD_GET() and FIELD_PREP() macros. Signed-off-by: Dario Binacchi --- drivers/video/fbdev/imxfb.c | 113 +++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c index 6af5f09d9c85..b7ef43a7930a 100644 --- a/drivers/video/fbdev/imxfb.c +++ b/drivers/video/fbdev/imxfb.c @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -58,48 +59,49 @@ struct imx_fb_videomode { #define LCDC_SSA 0x00 #define LCDC_SIZE 0x04 -#define SIZE_XMAX(x) ((((x) >> 4) & 0x3f) << 20) +#define SIZE_XMAX_MASK GENMASK(25, 20) -#define YMAX_MASK_IMX1 0x1ff -#define YMAX_MASK_IMX21 0x3ff +#define YMAX_MASK_IMX1 GENMASK(8, 0) +#define YMAX_MASK_IMX21 GENMASK(9, 0) #define LCDC_VPW 0x08 -#define VPW_VPW(x) ((x) & 0x3ff) +#define VPW_VPW_MASK GENMASK(9, 0) #define LCDC_CPOS 0x0C -#define CPOS_CC1 (1<<31) -#define CPOS_CC0 (1<<30) -#define CPOS_OP (1<<28) -#define CPOS_CXP(x) (((x) & 3ff) << 16) +#define CPOS_CC1 BIT(31) +#define CPOS_CC0 BIT(30) +#define CPOS_OP BIT(28) +#define CPOS_CXP_MASK GENMASK(25, 16) #define LCDC_LCWHB 0x10 -#define LCWHB_BK_EN (1<<31) -#define LCWHB_CW(w) (((w) & 0x1f) << 24) -#define LCWHB_CH(h) (((h) & 0x1f) << 16) -#define LCWHB_BD(x) ((x) & 0xff) +#define LCWHB_BK_EN BIT(31) +#define LCWHB_CW_MASK GENMASK(28, 24) +#define LCWHB_CH_MASK GENMASK(20, 16) +#define LCWHB_BD_MASK GENMASK(7, 0) #define LCDC_LCHCC 0x14 #define LCDC_PCR 0x18 -#define PCR_TFT (1 << 31) -#define PCR_COLOR (1 << 30) -#define PCR_BPIX_8 (3 << 25) -#define PCR_BPIX_12 (4 << 25) -#define PCR_BPIX_16 (5 << 25) -#define PCR_BPIX_18 (6 << 25) +#define PCR_TFT BIT(31) +#define PCR_COLOR BIT(30) +#define PCR_BPIX_MASK GENMASK(27, 25) +#define PCR_BPIX_8 3 +#define PCR_BPIX_12 4 +#define PCR_BPIX_16 5 +#define PCR_BPIX_18 6 #define LCDC_HCR 0x1C -#define HCR_H_WIDTH(x) (((x) & 0x3f) << 26) -#define HCR_H_WAIT_1(x) (((x) & 0xff) << 8) -#define HCR_H_WAIT_2(x) ((x) & 0xff) +#define HCR_H_WIDTH_MASK GENMASK(31, 26) +#define HCR_H_WAIT_1_MASK GENMASK(15, 8) +#define HCR_H_WAIT_2_MASK GENMASK(7, 0) #define LCDC_VCR 0x20 -#define VCR_V_WIDTH(x) (((x) & 0x3f) << 26) -#define VCR_V_WAIT_1(x) (((x) & 0xff) << 8) -#define VCR_V_WAIT_2(x) ((x) & 0xff) +#define VCR_V_WIDTH_MASK GENMASK(31, 26) +#define VCR_V_WAIT_1_MASK GENMASK(15, 8) +#define VCR_V_WAIT_2_MASK GENMASK(7, 0) #define LCDC_POS 0x24 -#define POS_POS(x) ((x) & 1f) +#define POS_POS_MASK GENMASK(4, 0) #define LCDC_LSCR1 0x28 /* bit fields in imxfb.h */ @@ -112,24 +114,24 @@ struct imx_fb_videomode { #define LCDC_RMCR 0x34 -#define RMCR_LCDC_EN_MX1 (1<<1) +#define RMCR_LCDC_EN_MX1 BIT(1) -#define RMCR_SELF_REF (1<<0) +#define RMCR_SELF_REF BIT(0) #define LCDC_LCDICR 0x38 -#define LCDICR_INT_SYN (1<<2) -#define LCDICR_INT_CON (1) +#define LCDICR_INT_SYN BIT(2) +#define LCDICR_INT_CON BIT(0) #define LCDC_LCDISR 0x40 -#define LCDISR_UDR_ERR (1<<3) -#define LCDISR_ERR_RES (1<<2) -#define LCDISR_EOF (1<<1) -#define LCDISR_BOF (1<<0) +#define LCDISR_UDR_ERR BIT(3) +#define LCDISR_ERR_RES BIT(2) +#define LCDISR_EOF BIT(1) +#define LCDISR_BOF BIT(0) #define IMXFB_LSCR1_DEFAULT 0x00120300 #define LCDC_LAUSCR 0x80 -#define LAUSCR_AUS_MODE (1<<31) +#define LAUSCR_AUS_MODE BIT(31) /* Used fb-mode. Can be set on kernel command line, therefore file-static. */ static const char *fb_mode; @@ -420,15 +422,15 @@ static int imxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) switch (var->bits_per_pixel) { case 32: - pcr |= PCR_BPIX_18; + pcr |= FIELD_PREP(PCR_BPIX_MASK, PCR_BPIX_18); rgb = &def_rgb_18; break; case 16: default: if (is_imx1_fb(fbi)) - pcr |= PCR_BPIX_12; + pcr |= FIELD_PREP(PCR_BPIX_MASK, PCR_BPIX_12); else - pcr |= PCR_BPIX_16; + pcr |= FIELD_PREP(PCR_BPIX_MASK, PCR_BPIX_16); if (imxfb_mode->pcr & PCR_TFT) rgb = &def_rgb_16_tft; @@ -436,7 +438,7 @@ static int imxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) rgb = &def_rgb_16_stn; break; case 8: - pcr |= PCR_BPIX_8; + pcr |= FIELD_PREP(PCR_BPIX_MASK, PCR_BPIX_8); rgb = &def_rgb_8; break; } @@ -520,7 +522,7 @@ static int imxfb_enable_controller(struct imxfb_info *fbi) writel(fbi->map_dma, fbi->regs + LCDC_SSA); /* panning offset 0 (0 pixel offset) */ - writel(0x00000000, fbi->regs + LCDC_POS); + writel(FIELD_PREP(POS_POS_MASK, 0), fbi->regs + LCDC_POS); /* disable hardware cursor */ writel(readl(fbi->regs + LCDC_CPOS) & ~(CPOS_CC0 | CPOS_CC1), @@ -654,21 +656,24 @@ static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *inf #endif /* physical screen start address */ - writel(VPW_VPW(var->xres * var->bits_per_pixel / 8 / 4), - fbi->regs + LCDC_VPW); - - writel(HCR_H_WIDTH(var->hsync_len - 1) | - HCR_H_WAIT_1(var->right_margin - 1) | - HCR_H_WAIT_2(var->left_margin - left_margin_low), - fbi->regs + LCDC_HCR); - - writel(VCR_V_WIDTH(var->vsync_len) | - VCR_V_WAIT_1(var->lower_margin) | - VCR_V_WAIT_2(var->upper_margin), - fbi->regs + LCDC_VCR); - - writel(SIZE_XMAX(var->xres) | (var->yres & ymax_mask), - fbi->regs + LCDC_SIZE); + writel(FIELD_PREP(VPW_VPW_MASK, + var->xres * var->bits_per_pixel / 8 / 4), + fbi->regs + LCDC_VPW); + + writel(FIELD_PREP(HCR_H_WIDTH_MASK, var->hsync_len - 1) | + FIELD_PREP(HCR_H_WAIT_1_MASK, var->right_margin - 1) | + FIELD_PREP(HCR_H_WAIT_2_MASK, + var->left_margin - left_margin_low), + fbi->regs + LCDC_HCR); + + writel(FIELD_PREP(VCR_V_WIDTH_MASK, var->vsync_len) | + FIELD_PREP(VCR_V_WAIT_1_MASK, var->lower_margin) | + FIELD_PREP(VCR_V_WAIT_2_MASK, var->upper_margin), + fbi->regs + LCDC_VCR); + + writel(FIELD_PREP(SIZE_XMAX_MASK, var->xres >> 4) | + (var->yres & ymax_mask), + fbi->regs + LCDC_SIZE); writel(fbi->pcr, fbi->regs + LCDC_PCR); if (fbi->pwmr)