From nobody Sun Sep 22 03:21:40 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F194EC433F5 for ; Mon, 16 May 2022 12:47:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233155AbiEPMrq (ORCPT ); Mon, 16 May 2022 08:47:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234855AbiEPMrJ (ORCPT ); Mon, 16 May 2022 08:47:09 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ADBB39177 for ; Mon, 16 May 2022 05:47:08 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: kholk11) with ESMTPSA id B8BD01F42F50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1652705227; bh=rU3HMUqW9dWRUgBD1kOKJz9+OYOFxEoj5qLLiVQ3VwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UuUqWrd/NaLBeyNWs6OBsad9vy+o0FVY9Y2FKgELcvowSX9hwr5AE/ZgoP6o6Bl2x t9H7zK8cK4MH2ROSyB28un3Lqizky0z+uOlDcH9aRrQVEd7p6eFFjpqoLv1D2+K+jR jl4rWD6Zqec11tb8TcQ8mSCpi8Ooy4cvI7im+zLiSnmnkB+XOfBWbQHD+xZl6rWqzU atJdOBeji2TQ7NNJVlZWCecjyWASFEu/Fkej0up15/n9UfOax1sJOHj94J3PjXq61R o2AeiIMxByFFPxajf/G2YNQVzofoXzoEQ/3Ct8YO4VzotN7iKWzR4hBpUJZGih3Zvd lJO+Ich+NgTBw== From: AngeloGioacchino Del Regno To: matthias.bgg@gmail.com Cc: linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, nfraprado@collabora.com, rex-bc.chen@mediatek.com, zhiyong.tao@mediatek.com, AngeloGioacchino Del Regno Subject: [PATCH v3 4/5] soc: mediatek: pwrap: Move IO pointers to new structure Date: Mon, 16 May 2022 14:46:58 +0200 Message-Id: <20220516124659.69484-5-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220516124659.69484-1-angelogioacchino.delregno@collabora.com> References: <20220516124659.69484-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In the PMIC Wrapper driver each PMIC has its own regmap configuration and its own pwrap_{read/write}() callbacks, but it's just about either a 32 bits vs 16 bits register, and only one of them uses 32bits regs: this means that the same ops are assigned over and over again to all of the supported PMICs. It is therefore possible to avoid reassigning the same things over and over, reducing the amount of lines, without any impact on human readability of this driver: add a pwrap_slv_regops structure and move the callbacks and regmap_config pointer in there instead. This allows to assign just one pointer to that shared data in the per-pmic struct pwrap_slv_type. Signed-off-by: AngeloGioacchino Del Regno --- drivers/soc/mediatek/mtk-pmic-wrap.c | 61 +++++++++++++++------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c b/drivers/soc/mediatek/mt= k-pmic-wrap.c index 332cbcabc299..7d02e1d4faf4 100644 --- a/drivers/soc/mediatek/mtk-pmic-wrap.c +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c @@ -1143,12 +1143,9 @@ enum pwrap_type { }; =20 struct pmic_wrapper; -struct pwrap_slv_type { - const u32 *dew_regs; - enum pmic_type type; + +struct pwrap_slv_regops { const struct regmap_config *regmap; - /* Flags indicating the capability for the target slave */ - u32 caps; /* * pwrap operations are highly associated with the PMIC types, * so the pointers added increases flexibility allowing determination @@ -1158,6 +1155,14 @@ struct pwrap_slv_type { int (*pwrap_write)(struct pmic_wrapper *wrp, u32 adr, u32 wdata); }; =20 +struct pwrap_slv_type { + const u32 *dew_regs; + enum pmic_type type; + const struct pwrap_slv_regops *regops; + /* Flags indicating the capability for the target slave */ + u32 caps; +}; + struct pmic_wrapper { struct device *dev; void __iomem *base; @@ -1313,7 +1318,7 @@ static int pwrap_read32(struct pmic_wrapper *wrp, u32= adr, u32 *rdata) =20 static int pwrap_read(struct pmic_wrapper *wrp, u32 adr, u32 *rdata) { - return wrp->slave->pwrap_read(wrp, adr, rdata); + return wrp->slave->regops->pwrap_read(wrp, adr, rdata); } =20 static int pwrap_write16(struct pmic_wrapper *wrp, u32 adr, u32 wdata) @@ -1372,7 +1377,7 @@ static int pwrap_write32(struct pmic_wrapper *wrp, u3= 2 adr, u32 wdata) =20 static int pwrap_write(struct pmic_wrapper *wrp, u32 adr, u32 wdata) { - return wrp->slave->pwrap_write(wrp, adr, wdata); + return wrp->slave->regops->pwrap_write(wrp, adr, wdata); } =20 static int pwrap_regmap_read(void *context, u32 adr, u32 *rdata) @@ -1891,69 +1896,67 @@ static const struct regmap_config pwrap_regmap_conf= ig32 =3D { .max_register =3D 0xffff, }; =20 +static const struct pwrap_slv_regops pwrap_regops16 =3D { + .pwrap_read =3D pwrap_read16, + .pwrap_write =3D pwrap_write16, + .regmap =3D &pwrap_regmap_config16, +}; + +static const struct pwrap_slv_regops pwrap_regops32 =3D { + .pwrap_read =3D pwrap_read32, + .pwrap_write =3D pwrap_write32, + .regmap =3D &pwrap_regmap_config32, +}; + static const struct pwrap_slv_type pmic_mt6323 =3D { .dew_regs =3D mt6323_regs, .type =3D PMIC_MT6323, - .regmap =3D &pwrap_regmap_config16, + .regops =3D &pwrap_regops16, .caps =3D PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO | PWRAP_SLV_CAP_SECURITY, - .pwrap_read =3D pwrap_read16, - .pwrap_write =3D pwrap_write16, }; =20 static const struct pwrap_slv_type pmic_mt6351 =3D { .dew_regs =3D mt6351_regs, .type =3D PMIC_MT6351, - .regmap =3D &pwrap_regmap_config16, + .regops =3D &pwrap_regops16, .caps =3D 0, - .pwrap_read =3D pwrap_read16, - .pwrap_write =3D pwrap_write16, }; =20 static const struct pwrap_slv_type pmic_mt6357 =3D { .dew_regs =3D mt6357_regs, .type =3D PMIC_MT6357, - .regmap =3D &pwrap_regmap_config16, + .regops =3D &pwrap_regops16, .caps =3D 0, - .pwrap_read =3D pwrap_read16, - .pwrap_write =3D pwrap_write16, }; =20 static const struct pwrap_slv_type pmic_mt6358 =3D { .dew_regs =3D mt6358_regs, .type =3D PMIC_MT6358, - .regmap =3D &pwrap_regmap_config16, + .regops =3D &pwrap_regops16, .caps =3D PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO, - .pwrap_read =3D pwrap_read16, - .pwrap_write =3D pwrap_write16, }; =20 static const struct pwrap_slv_type pmic_mt6359 =3D { .dew_regs =3D mt6359_regs, .type =3D PMIC_MT6359, - .regmap =3D &pwrap_regmap_config16, + .regops =3D &pwrap_regops16, .caps =3D PWRAP_SLV_CAP_DUALIO, - .pwrap_read =3D pwrap_read16, - .pwrap_write =3D pwrap_write16, }; =20 static const struct pwrap_slv_type pmic_mt6380 =3D { .dew_regs =3D NULL, .type =3D PMIC_MT6380, - .regmap =3D &pwrap_regmap_config32, + .regops =3D &pwrap_regops32, .caps =3D 0, - .pwrap_read =3D pwrap_read32, - .pwrap_write =3D pwrap_write32, }; =20 static const struct pwrap_slv_type pmic_mt6397 =3D { .dew_regs =3D mt6397_regs, .type =3D PMIC_MT6397, - .regmap =3D &pwrap_regmap_config16, + .regops =3D &pwrap_regops16, .caps =3D PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO | PWRAP_SLV_CAP_SECURITY, - .pwrap_read =3D pwrap_read16, - .pwrap_write =3D pwrap_write16, }; =20 static const struct of_device_id of_slave_match_tbl[] =3D { @@ -2326,7 +2329,7 @@ static int pwrap_probe(struct platform_device *pdev) if (ret) goto err_out2; =20 - wrp->regmap =3D devm_regmap_init(wrp->dev, NULL, wrp, wrp->slave->regmap); + wrp->regmap =3D devm_regmap_init(wrp->dev, NULL, wrp, wrp->slave->regops-= >regmap); if (IS_ERR(wrp->regmap)) { ret =3D PTR_ERR(wrp->regmap); goto err_out2; --=20 2.35.1