Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp409486rdb; Mon, 29 Jan 2024 06:10:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+jusZQUNPRhbJ5s7dEIB0SEpmsWirq+8lY28A+AfbxuXeALOH05QUsDqqUdhxl6TDVGWq X-Received: by 2002:a05:6808:308f:b0:3be:700a:eed0 with SMTP id bl15-20020a056808308f00b003be700aeed0mr1048404oib.26.1706537440230; Mon, 29 Jan 2024 06:10:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706537440; cv=pass; d=google.com; s=arc-20160816; b=cmmrcC5lzc/HG1cWZ72cB3CyLvojgzYn4WuumtiLM9Mfs8wcQO3FtnSc0UKjMTeev6 BvlItgFynaHeU1fgsuZyd+16wbAYbGcj21tq4wOQ79kHM5+lLMImLel3oSY7vsLAJJIy 8++0hVN+0Ku75b2ftg0FrX+w33Y5yRfgGNTJnrsOBfez9apc6TocAPYypzmWvTUWDE7v OAmV5K14TnKH2canV1Z2kdUn1rWGQEj2O66Tx5nc3cnxdiOB2zdcoFF9BfDxCZNhxdEO R+cDXDuqjZIM8CWM4V85haZrnS/6NEI2hmRsfVpmfbPRLvS47gQ6eCzTXHAHSYpby/Gf Skxw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=GfIWoQHy7z0V0yUTX2XoUCJ/M52iXXotNEoKtHwDMZA=; fh=9jERyHaBVkSYjvKDLj7G39aR/G88vFciZPp35CZ8FfY=; b=lxhnNvhduhckdgBt3k57xGmLcnBMEnoZ1PbnIZ73UPGXOkEoId9Ljk3wfOAIELLHsG t4bWvgQddg7U/NapmqKR+2Q+pAaQMdXDDqHtj1qEJDqVLccyyFgxaI7eio+4nx/1+/yw /BECbIi4VESk+ZkvgMmqP/d5Hhytj+C2j5vVxIgSCC55x3dM6Lc4s0oJF7mkADXGLgPy CNlY8ViLyeBF9ll5MLDSM0pX1FMCm2IuSl6clgNXjIB1XjM0DcHhPpAYPSCk50maVqg6 HNqvy9h3GrI7wo/wdMNwk9yyEMQBV4JfVA0EenMsY0iTJoXOVIdidpJOuUibsvQOIvX6 9CNg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OVVbshUu; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-42843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42843-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id a18-20020a637f12000000b005d8b7053276si3884490pgd.160.2024.01.29.06.10.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 06:10:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OVVbshUu; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-42843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42843-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4245BB26468 for ; Mon, 29 Jan 2024 13:56:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2CD6F65BC6; Mon, 29 Jan 2024 13:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OVVbshUu" Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A371657B9; Mon, 29 Jan 2024 13:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706536588; cv=none; b=Nrx0a+FMr6NKFoy/BapEQQ8zxtN0np5ETaRg2cjYcxR2toYrp32B5x1t1PD86Iyr7GxZOP+Mez4AU8C5awaaVD0Tbs+QIZ7FVeMYgxEVIWvCz7ouNkv9Vbw0UnZ5IqKVSIJFzq7lFKjvh+S+XiiZMlqtDcpInGNKhR4iSK++abk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706536588; c=relaxed/simple; bh=mTtSqAY9WSHR3XRmwFrnCt/54qdX28p1oaTlKRQzAag=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qScrprobfrfW7DgRLHUZcpuekPLuMJsfJ0C4IT+YMnlzW/f3tvXW12cvwLuoCWwgCvK/roEp7rCGBx/A/oCAWM7U5dhQIZ/8vOZ3oQweNXZcY5dWiZT4NWJ0Z0MPtrmxJGgouVqYQXjZZi/BBYRf0MW4H2OzAu2foai2Gt3TzTI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OVVbshUu; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3392b045e0aso2281215f8f.2; Mon, 29 Jan 2024 05:56:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706536584; x=1707141384; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GfIWoQHy7z0V0yUTX2XoUCJ/M52iXXotNEoKtHwDMZA=; b=OVVbshUuD3zfDF7w1oNuJCbLqPLhUQjgDM6Tr8ahzjcBnircVLRhnQTzXvnd4zLXpW kNiryUNjMykz3dsnLT8Yk/CmxFvSN9Fb8jRvKrPiHlkd6xrxJN+Q66kgHvTyf0+MVRGc Kuh8zVRGT0v0yghOZ2rUOg2TSF1LeKft43L7UqQwlQpDp0fdnW7IqJ08NrsLq0oyuRbj /psNxUSfOia9/4zndKMJusWnUgYT3d4gcRvLGQaUvigbvr2eiciSJxM4wdFUmJFjTdWO OENjkdpib1dEaf9v0XGtiJJLm20e0wxoAAo9yUYyrcy/mfvVE80DR+TZhs50ABu7T/zl 4FwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706536584; x=1707141384; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GfIWoQHy7z0V0yUTX2XoUCJ/M52iXXotNEoKtHwDMZA=; b=Mk7mrPIesuhAEx+ttoGLGj4zBrX6yJt539tBsJtaLPUmcRXljtMzAFyc8wbxLKplKj uEdzGesdz1kbiN61zMMP53yYiMudGmEcVXm70Dg/16tvLJplGMYynEyt7nbXxxvyyaUj G/vlVCs9usqx7vLYDW4Bizp7HnfKWhrUYT25rPTFKrGESBsAZZBamRCqJuz8eeg2w4S7 qQv45KAr5AN8pB9nrED7ScGt1TREqdHI2g2dpsKjbyhytgCq3fR7LT4C85b8LCWtRKnj vqFL/rv0KIHplbguI4S62O6agTRjW0uPmANO8eyI3c4gjLCdr6qfg0EfriMwaHPJfVqY ngvg== X-Gm-Message-State: AOJu0YwmtK71ExUl/oyglzyDoFQCd0pcfH8DgpY1rcyR3g6eC9v7Wh8Y HQC/zjRcroc3LQNp2eC/mZGlHH5RQtMn+40MGGbOK5hzMOtsU+IY X-Received: by 2002:a5d:6692:0:b0:33a:e773:5f3c with SMTP id l18-20020a5d6692000000b0033ae7735f3cmr2922585wru.3.1706536583999; Mon, 29 Jan 2024 05:56:23 -0800 (PST) Received: from prasmi.home ([2a00:23c8:2500:a01:5616:a18c:ea50:2995]) by smtp.gmail.com with ESMTPSA id bh5-20020a05600005c500b0033aed46956csm3058057wrb.80.2024.01.29.05.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 05:56:23 -0800 (PST) From: Prabhakar X-Google-Original-From: Prabhakar To: Geert Uytterhoeven , Magnus Damm , Linus Walleij Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Prabhakar , Biju Das , Claudiu Beznea , Lad Prabhakar Subject: [PATCH v6 1/4] pinctrl: renesas: rzg2l: Improve code for readability Date: Mon, 29 Jan 2024 13:55:53 +0000 Message-Id: <20240129135556.63466-2-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240129135556.63466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20240129135556.63466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Lad Prabhakar As the RZ/G2L pinctrl driver is extensively utilized by numerous SoCs and has experienced substantial growth, enhance code readability by incorporating FIELD_PREP_CONST/FIELD_GET macros wherever necessary. Signed-off-by: Lad Prabhakar --- drivers/pinctrl/renesas/pinctrl-rzg2l.c | 41 +++++++++++++++---------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/drivers/pinctrl/renesas/pinctrl-rzg2l.c b/drivers/pinctrl/renesas/pinctrl-rzg2l.c index 80fb5011c7bb..c7dc32176bfe 100644 --- a/drivers/pinctrl/renesas/pinctrl-rzg2l.c +++ b/drivers/pinctrl/renesas/pinctrl-rzg2l.c @@ -5,6 +5,7 @@ * Copyright (C) 2021 Renesas Electronics Corporation. */ +#include #include #include #include @@ -38,8 +39,6 @@ */ #define MUX_PIN_ID_MASK GENMASK(15, 0) #define MUX_FUNC_MASK GENMASK(31, 16) -#define MUX_FUNC_OFFS 16 -#define MUX_FUNC(pinconf) (((pinconf) & MUX_FUNC_MASK) >> MUX_FUNC_OFFS) /* PIN capabilities */ #define PIN_CFG_IOLH_A BIT(0) @@ -81,8 +80,12 @@ * n indicates number of pins in the port, a is the register index * and f is pin configuration capabilities supported. */ -#define RZG2L_GPIO_PORT_PACK(n, a, f) (((n) << 28) | ((a) << 20) | (f)) -#define RZG2L_GPIO_PORT_GET_PINCNT(x) (((x) & GENMASK(30, 28)) >> 28) +#define PIN_CFG_PIN_CNT_MASK GENMASK(30, 28) +#define PIN_CFG_PIN_REG_MASK GENMASK(27, 20) +#define PIN_CFG_MASK GENMASK(19, 0) +#define RZG2L_GPIO_PORT_PACK(n, a, f) (FIELD_PREP_CONST(PIN_CFG_PIN_CNT_MASK, (n)) | \ + FIELD_PREP_CONST(PIN_CFG_PIN_REG_MASK, (a)) | \ + FIELD_PREP_CONST(PIN_CFG_MASK, (f))) /* * BIT(31) indicates dedicated pin, p is the register index while @@ -90,14 +93,18 @@ * (b * 8) and f is the pin configuration capabilities supported. */ #define RZG2L_SINGLE_PIN BIT(31) +#define RZG2L_SINGLE_PIN_INDEX_MASK GENMASK(30, 24) +#define RZG2L_SINGLE_PIN_BITS_MASK GENMASK(22, 20) + #define RZG2L_SINGLE_PIN_PACK(p, b, f) (RZG2L_SINGLE_PIN | \ - ((p) << 24) | ((b) << 20) | (f)) -#define RZG2L_SINGLE_PIN_GET_BIT(x) (((x) & GENMASK(22, 20)) >> 20) + FIELD_PREP_CONST(RZG2L_SINGLE_PIN_INDEX_MASK, (p)) | \ + FIELD_PREP_CONST(RZG2L_SINGLE_PIN_BITS_MASK, (b)) | \ + FIELD_PREP_CONST(PIN_CFG_MASK, (f))) -#define RZG2L_PIN_CFG_TO_CAPS(cfg) ((cfg) & GENMASK(19, 0)) +#define RZG2L_PIN_CFG_TO_CAPS(cfg) ((cfg) & PIN_CFG_MASK) #define RZG2L_PIN_CFG_TO_PORT_OFFSET(cfg) ((cfg) & RZG2L_SINGLE_PIN ? \ - (((cfg) & GENMASK(30, 24)) >> 24) : \ - (((cfg) & GENMASK(26, 20)) >> 20)) + FIELD_GET(RZG2L_SINGLE_PIN_INDEX_MASK, (cfg)) : \ + FIELD_GET(PIN_CFG_PIN_REG_MASK, (cfg))) #define P(off) (0x0000 + (off)) #define PM(off) (0x0100 + (off) * 2) @@ -432,8 +439,8 @@ static int rzg2l_dt_subnode_to_map(struct pinctrl_dev *pctldev, ret = of_property_read_u32_index(np, "pinmux", i, &value); if (ret) goto done; - pins[i] = value & MUX_PIN_ID_MASK; - psel_val[i] = MUX_FUNC(value); + pins[i] = FIELD_GET(MUX_PIN_ID_MASK, value); + psel_val[i] = FIELD_GET(MUX_FUNC_MASK, value); } if (parent) { @@ -560,7 +567,7 @@ static int rzg2l_dt_node_to_map(struct pinctrl_dev *pctldev, static int rzg2l_validate_gpio_pin(struct rzg2l_pinctrl *pctrl, u32 cfg, u32 port, u8 bit) { - u8 pincount = RZG2L_GPIO_PORT_GET_PINCNT(cfg); + u8 pincount = FIELD_GET(PIN_CFG_PIN_CNT_MASK, cfg); u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(cfg); u32 data; @@ -868,7 +875,7 @@ static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev, off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data); cfg = RZG2L_PIN_CFG_TO_CAPS(*pin_data); if (*pin_data & RZG2L_SINGLE_PIN) { - bit = RZG2L_SINGLE_PIN_GET_BIT(*pin_data); + bit = FIELD_GET(RZG2L_SINGLE_PIN_BITS_MASK, *pin_data); } else { bit = RZG2L_PIN_ID_TO_PIN(_pin); @@ -972,7 +979,7 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev, off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data); cfg = RZG2L_PIN_CFG_TO_CAPS(*pin_data); if (*pin_data & RZG2L_SINGLE_PIN) { - bit = RZG2L_SINGLE_PIN_GET_BIT(*pin_data); + bit = FIELD_GET(RZG2L_SINGLE_PIN_BITS_MASK, *pin_data); } else { bit = RZG2L_PIN_ID_TO_PIN(_pin); @@ -1608,12 +1615,12 @@ static int rzg2l_gpio_get_gpioint(unsigned int virq, const struct rzg2l_pinctrl_ bit = virq % 8; if (port >= data->n_ports || - bit >= RZG2L_GPIO_PORT_GET_PINCNT(data->port_pin_configs[port])) + bit >= FIELD_GET(PIN_CFG_PIN_CNT_MASK, data->port_pin_configs[port])) return -EINVAL; gpioint = bit; for (i = 0; i < port; i++) - gpioint += RZG2L_GPIO_PORT_GET_PINCNT(data->port_pin_configs[i]); + gpioint += FIELD_GET(PIN_CFG_PIN_CNT_MASK, data->port_pin_configs[i]); return gpioint; } @@ -1788,7 +1795,7 @@ static void rzg2l_init_irq_valid_mask(struct gpio_chip *gc, bit = offset % 8; if (port >= pctrl->data->n_ports || - bit >= RZG2L_GPIO_PORT_GET_PINCNT(pctrl->data->port_pin_configs[port])) + bit >= FIELD_GET(PIN_CFG_PIN_CNT_MASK, pctrl->data->port_pin_configs[port])) clear_bit(offset, valid_mask); } } -- 2.34.1