From: Benjamin Gaignard Date: Tue, 27 Nov 2018 13:49:53 +0100 Subject: [U-Boot] [PATCH v5 4/4] pinctrl: stm32: make pinctrl use hwspinlock In-Reply-To: <20181127124953.4458-1-benjamin.gaignard@st.com> References: <20181127124953.4458-1-benjamin.gaignard@st.com> Message-ID: <20181127124953.4458-5-benjamin.gaignard@st.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Protect configuration registers with a hardware spinlock. If a hwspinlock is defined in the device-tree node used it to be sure that none of the others processors on the SoC could change the configuration at the same time. Signed-off-by: Benjamin Gaignard Reviewed-by: Simon Glass Reviewed-by: Patrice Chotard --- version 5: =C2=B2- rebased on top of master branch arch/arm/dts/stm32mp157c-ed1.dts | 4 ++++ drivers/pinctrl/pinctrl_stm32.c | 27 +++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/arch/arm/dts/stm32mp157c-ed1.dts b/arch/arm/dts/stm32mp157c-ed= 1.dts index fc277dd7d2..7a9b742d36 100644 --- a/arch/arm/dts/stm32mp157c-ed1.dts +++ b/arch/arm/dts/stm32mp157c-ed1.dts @@ -369,6 +369,10 @@ status =3D "okay"; }; =20 +&pinctrl { + hwlocks =3D <&hwspinlock 0>; +}; + &usbphyc_port0 { phy-supply =3D <&vdd_usb>; vdda1v1-supply =3D <®11>; diff --git a/drivers/pinctrl/pinctrl_stm32.c b/drivers/pinctrl/pinctrl_stm3= 2.c index 6d4117d941..bb63da3739 100644 --- a/drivers/pinctrl/pinctrl_stm32.c +++ b/drivers/pinctrl/pinctrl_stm32.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -14,8 +15,8 @@ DECLARE_GLOBAL_DATA_PTR; #define OTYPE_MSK 1 #define AFR_MASK 0xF =20 -#ifndef CONFIG_SPL_BUILD struct stm32_pinctrl_priv { + struct hwspinlock hws; int pinctrl_ngpios; struct list_head gpio_dev; }; @@ -25,6 +26,8 @@ struct stm32_gpio_bank { struct list_head list; }; =20 +#ifndef CONFIG_SPL_BUILD + #define MAX_PIN_PER_BANK 16 =20 static char pin_name[PINNAME_SIZE]; @@ -166,6 +169,8 @@ static int stm32_pinctrl_get_pin_muxing(struct udevice = *dev, return 0; } =20 +#endif + int stm32_pinctrl_probe(struct udevice *dev) { struct stm32_pinctrl_priv *priv =3D dev_get_priv(dev); @@ -198,21 +203,35 @@ int stm32_pinctrl_probe(struct udevice *dev) list_add_tail(&gpio_bank->list, &priv->gpio_dev); } =20 + /* hwspinlock property is optional, just log the error */ + ret =3D hwspinlock_get_by_index(dev, 0, &priv->hws); + if (ret) + debug("%s: hwspinlock_get_by_index may have failed (%d)\n", + __func__, ret); + return 0; } -#endif =20 static int stm32_gpio_config(struct gpio_desc *desc, const struct stm32_gpio_ctl *ctl) { struct stm32_gpio_priv *priv =3D dev_get_priv(desc->dev); struct stm32_gpio_regs *regs =3D priv->regs; + struct stm32_pinctrl_priv *ctrl_priv; + int ret; u32 index; =20 if (!ctl || ctl->af > 15 || ctl->mode > 3 || ctl->otype > 1 || ctl->pupd > 2 || ctl->speed > 3) return -EINVAL; =20 + ctrl_priv =3D dev_get_priv(dev_get_parent(desc->dev)); + ret =3D hwspinlock_lock_timeout(&ctrl_priv->hws, 10); + if (ret =3D=3D -ETIME) { + dev_err(desc->dev, "HWSpinlock timeout\n"); + return ret; + } + index =3D (desc->offset & 0x07) * 4; clrsetbits_le32(®s->afr[desc->offset >> 3], AFR_MASK << index, ctl->af << index); @@ -227,6 +246,8 @@ static int stm32_gpio_config(struct gpio_desc *desc, index =3D desc->offset; clrsetbits_le32(®s->otyper, OTYPE_MSK << index, ctl->otype << index); =20 + hwspinlock_unlock(&ctrl_priv->hws); + return 0; } =20 @@ -393,8 +414,6 @@ U_BOOT_DRIVER(pinctrl_stm32) =3D { .of_match =3D stm32_pinctrl_ids, .ops =3D &stm32_pinctrl_ops, .bind =3D dm_scan_fdt_dev, -#ifndef CONFIG_SPL_BUILD .probe =3D stm32_pinctrl_probe, .priv_auto_alloc_size =3D sizeof(struct stm32_pinctrl_priv), -#endif }; --=20 2.15.0