From nobody Tue Dec 16 14:24:36 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6F8F1D416E; Tue, 27 May 2025 05:23:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748323411; cv=none; b=bN60u96soJwB4FQRLlKV5wlz0d3n3T4hVXHVt8Jgwl4lLwVCFsY8ForXfdsJetJCRADhdtT8ZhM5SmRBcErHEU0wMYQMLfs2eP9L3dbXpninwNDloS/Cc7/C+pZAOZfyzLMmvfNH5nIAfGsC9PPcKGCmn6CtwYv7YDYA5VqCxBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748323411; c=relaxed/simple; bh=quOporxfDNGe0WOCFU1wm8cDs1FXS8mPxsye1M2mYFw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Y1ZXvNSce36ebqC6D68BrWEnpp6MVYv6BioQdxi4O7jRad5vJ3VgNEeKmQ+rB0V/357mXpfwitV/8lnp4DNxnu2ss09jJEQslB3Q1o9NQQba9TlmqzySIzw5ptw7Jh0zFmf/yCD8cd4CZ1N7t/byvUhvbQ/3OYjmyrnOiVbdkGY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YVw7eiD6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YVw7eiD6" Received: by smtp.kernel.org (Postfix) with ESMTPS id 8061AC4CEF1; Tue, 27 May 2025 05:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1748323410; bh=quOporxfDNGe0WOCFU1wm8cDs1FXS8mPxsye1M2mYFw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=YVw7eiD6TqtTeRTJiO0dec0wkPnIo3p7s3qkedCOyUh3rm0lVs63uo3LnNahvHQNi vY/DChRLi311KgQM3teuG/KoDkUTRjKmRvV7+JnaEZ1wmeCpyIrY0c3LoHDBLHYIlo AIcEkFbFp0A5lYcbyE8I5RI8TSC1DKIRjnarmgjavfvAkkE+IRVAxggKvmdlx3ICWE jO1zobcYQJOqK19Zl1sAHZlnQxOvIMprcnMAeilVqXTtte92TaXo8P+zU5VtZlfb7O ap967/OB1YlfOlrQenBjjQXT9djohKQJsNuRhBTrGG2EYkph2fLwePqsTz+F2t8OHF wkB4IBGvnxsTg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72C2FC5B549; Tue, 27 May 2025 05:23:30 +0000 (UTC) From: Xianwei Zhao via B4 Relay Date: Tue, 27 May 2025 13:23:30 +0800 Subject: [PATCH v3 3/6] pinctrl: meson: support amlogic S6/S7/S7D SoC Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250527-s6-s7-pinctrl-v3-3-44f6a0451519@amlogic.com> References: <20250527-s6-s7-pinctrl-v3-0-44f6a0451519@amlogic.com> In-Reply-To: <20250527-s6-s7-pinctrl-v3-0-44f6a0451519@amlogic.com> To: Linus Walleij , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl Cc: linux-amlogic@lists.infradead.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Xianwei Zhao X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1748323408; l=5341; i=xianwei.zhao@amlogic.com; s=20231208; h=from:subject:message-id; bh=qwVCVEAnoBSq9I7w3IY19mvHAyrHN1ELUryPfTi/kbc=; b=wbXtugHHTmGqqZwpfNa/C/9aeKyj4bIAOBY4DnAoW0oG+TN4aXTn7R3nqUieW0QUjmfJIT7wb vYnp2NKxsUUDxljc3ltoSPRo+FEyBJPIGunqQaOlgk/7K6TDw0HA5ss X-Developer-Key: i=xianwei.zhao@amlogic.com; a=ed25519; pk=o4fDH8ZXL6xQg5h17eNzRljf6pwZHWWjqcOSsj3dW24= X-Endpoint-Received: by B4 Relay for xianwei.zhao@amlogic.com/20231208 with auth_id=107 X-Original-From: Xianwei Zhao Reply-To: xianwei.zhao@amlogic.com From: Xianwei Zhao In some Amlogic SoCs, to save register space or due to some abnormal arrangements, two sets of pins share one mux register. A group starting from pin0 is the main pin group, which acquires the register address through DTS and has management permissions, but the register bit offset is undetermined. Another GPIO group as a subordinate group. Some pins mux use share register and bit offset from bit0 . But this group do not have register management permissions. This submission implements this situation. Signed-off-by: Xianwei Zhao --- drivers/pinctrl/meson/pinctrl-amlogic-a4.c | 101 +++++++++++++++++++++++++= +++- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/meson/pinctrl-amlogic-a4.c b/drivers/pinctrl/m= eson/pinctrl-amlogic-a4.c index 11f68224342e..2541c864086d 100644 --- a/drivers/pinctrl/meson/pinctrl-amlogic-a4.c +++ b/drivers/pinctrl/meson/pinctrl-amlogic-a4.c @@ -50,8 +50,23 @@ struct aml_pio_control { u32 bit_offset[AML_NUM_REG]; }; =20 +/* + * partial bank(subordinate) pins mux config use other bank(main) mux regi= stgers + * m_bank_id: the main bank which pin_id from 0, but register bit not from= bit 0 + * m_bit_offs: bit offset the main bank mux register + * sid: start pin_id of subordinate bank + * eid: end pin_id of subordinate bank + */ +struct multi_mux { + unsigned int m_bank_id; + unsigned int m_bit_offs; + unsigned int sid; + unsigned int eid; +}; + struct aml_pctl_data { unsigned int number; + const struct multi_mux *p_mux; }; =20 struct aml_pmx_func { @@ -71,10 +86,12 @@ struct aml_gpio_bank { struct gpio_chip gpio_chip; struct aml_pio_control pc; u32 bank_id; + u32 mux_bit_offs; unsigned int pin_base; struct regmap *reg_mux; struct regmap *reg_gpio; struct regmap *reg_ds; + const struct multi_mux *p_mux; }; =20 struct aml_pinctrl { @@ -106,13 +123,46 @@ static const char *aml_bank_name[31] =3D { "GPIOCC", "TEST_N", "ANALOG" }; =20 +const struct multi_mux multi_mux_s7[] =3D { + { + .m_bank_id =3D AMLOGIC_GPIO_CC, + .m_bit_offs =3D 24, + .sid =3D (AMLOGIC_GPIO_X << 8) + 16, + .eid =3D (AMLOGIC_GPIO_X << 8) + 19, + }, +}; + +const struct aml_pctl_data s7_priv_data =3D { + .number =3D ARRAY_SIZE(multi_mux_s7), + .p_mux =3D multi_mux_s7, +}; + +const struct multi_mux multi_mux_s6[] =3D { + { + .m_bank_id =3D AMLOGIC_GPIO_CC, + .m_bit_offs =3D 24, + .sid =3D (AMLOGIC_GPIO_X << 8) + 16, + .eid =3D (AMLOGIC_GPIO_X << 8) + 19, + }, { + .m_bank_id =3D AMLOGIC_GPIO_F, + .m_bit_offs =3D 4, + .sid =3D (AMLOGIC_GPIO_D << 8) + 6, + .eid =3D (AMLOGIC_GPIO_D << 8) + 6, + }, +}; + +const struct aml_pctl_data s6_priv_data =3D { + .number =3D ARRAY_SIZE(multi_mux_s6), + .p_mux =3D multi_mux_s6, +}; + static int aml_pmx_calc_reg_and_offset(struct pinctrl_gpio_range *range, unsigned int pin, unsigned int *reg, unsigned int *offset) { unsigned int shift; =20 - shift =3D (pin - range->pin_base) << 2; + shift =3D ((pin - range->pin_base) << 2) + *offset; *reg =3D (shift / 32) * 4; *offset =3D shift % 32; =20 @@ -124,9 +174,36 @@ static int aml_pctl_set_function(struct aml_pinctrl *i= nfo, int pin_id, int func) { struct aml_gpio_bank *bank =3D gpio_chip_to_bank(range->gc); + unsigned int shift; int reg; - int offset; + int i; + unsigned int offset =3D bank->mux_bit_offs; + const struct multi_mux *p_mux; + + /* peculiar mux reg set */ + if (bank->p_mux) { + p_mux =3D bank->p_mux; + if (pin_id >=3D p_mux->sid && pin_id <=3D p_mux->eid) { + bank =3D NULL; + for (i =3D 0; i < info->nbanks; i++) { + if (info->banks[i].bank_id =3D=3D p_mux->m_bank_id) { + bank =3D &info->banks[i]; + break; + } + } + + if (!bank || !bank->reg_mux) + return -EINVAL; + + shift =3D (pin_id - p_mux->sid) << 2; + reg =3D (shift / 32) * 4; + offset =3D shift % 32; + return regmap_update_bits(bank->reg_mux, reg, + 0xf << offset, (func & 0xf) << offset); + } + } =20 + /* normal mux reg set */ if (!bank->reg_mux) return 0; =20 @@ -822,12 +899,30 @@ static const struct gpio_chip aml_gpio_template =3D { static void init_bank_register_bit(struct aml_pinctrl *info, struct aml_gpio_bank *bank) { + const struct aml_pctl_data *data =3D info->data; + const struct multi_mux *p_mux; int i; =20 for (i =3D 0; i < AML_NUM_REG; i++) { bank->pc.reg_offset[i] =3D aml_def_regoffs[i]; bank->pc.bit_offset[i] =3D 0; } + + bank->mux_bit_offs =3D 0; + + if (data) { + for (i =3D 0; i < data->number; i++) { + p_mux =3D &data->p_mux[i]; + if (bank->bank_id =3D=3D p_mux->m_bank_id) { + bank->mux_bit_offs =3D p_mux->m_bit_offs; + break; + } + if (p_mux->sid >> 8 =3D=3D bank->bank_id) { + bank->p_mux =3D p_mux; + break; + } + } + } } =20 static int aml_gpiolib_register_bank(struct aml_pinctrl *info, @@ -994,6 +1089,8 @@ static int aml_pctl_probe(struct platform_device *pdev) =20 static const struct of_device_id aml_pctl_of_match[] =3D { { .compatible =3D "amlogic,pinctrl-a4", }, + { .compatible =3D "amlogic,pinctrl-s7", .data =3D &s7_priv_data, }, + { .compatible =3D "amlogic,pinctrl-s6", .data =3D &s6_priv_data, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, aml_pctl_dt_match); --=20 2.37.1