From patchwork Fri Nov 16 14:00:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 151341 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp469152ljp; Fri, 16 Nov 2018 06:06:20 -0800 (PST) X-Google-Smtp-Source: AJdET5eoVAkxATFS6gjz+EcKDjfzB54XS5SI1PJ3029rNsMXeonVHGiZmf5DLN7vkoS9Lgx0SCEl X-Received: by 2002:a50:940b:: with SMTP id p11mr9402647eda.135.1542377180858; Fri, 16 Nov 2018 06:06:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542377180; cv=none; d=google.com; s=arc-20160816; b=vQtIDmUwrI96T11my9BIsk5hAF4kjJSu8qLW2xUqBGAUcYBrbBRlQ2f/JwlQNZ2TCi Z/vPWFO1pJ4Nc+yaEMtQNLnebD/4U+xDpJlXqhHsLkXsgJK3AZQC6XZ+eUF4RbaRiaVz aEDKpaLjsKDUlNxtJ5/SMhevza64WzYt2MLdVZarBn5SsZPGvTR1vfkAfcc44Cj1PqeL czDIRYfci8oIg3Q7R6t5zoqkm3koj61Lyw8iXJAm+q6Va0Q/MU1ooffDg2TV7AmWjwY/ zQ+nzw1QN0fUdvvZQbiq8jLviay33lfMPeeY9VWDMdTRcCD8reAVMR3S4zsXk2L4UvFt 2eaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature; bh=lOMoY3gq5YPKZtwMLOqXgdeJ3l++0tJd8LOg1dN2PVg=; b=od9l3GaMXH3+t8Xu6rbDyvPJe5BlDPLTpYz+eJJ++wz36zZ8P4qaVJGQdayHwDFMdS pGmZU4c6poV5361CSRcgSbm4SoEuK6mq8OoP7gxtD1IsWwwFOLppHy9bEbwhIUd+ixtP OmBz5spGfIqI6w6tFQHMM788Zho2mvyr1OB+ozdth5l2ul8InYdDH8V4JeRCWzZjHpy+ 3zn3N4OxwQNwAlMgQVBYZrOY4qDIAjgW9EWlF0DXtX7KrRUCnSn/rk5ZYfnkT9Rs4c5u Y8E2Msx1L1nOWMbQhpMmKUs5RulqkrkV4115jg15Lx7KIGIP6HzWm05ijr8NI4Ybe6U1 MNxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QRlCpQWB; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id c1si1284184edy.52.2018.11.16.06.06.20; Fri, 16 Nov 2018 06:06:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QRlCpQWB; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 66F31C224F5; Fri, 16 Nov 2018 14:04:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D57CEC224F7; Fri, 16 Nov 2018 14:02:11 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3FD50C2231E; Fri, 16 Nov 2018 14:01:33 +0000 (UTC) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by lists.denx.de (Postfix) with ESMTPS id 21AE5C22512 for ; Fri, 16 Nov 2018 14:01:04 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id f10-v6so22140711wme.3 for ; Fri, 16 Nov 2018 06:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ejct8UX6bJFOwwcKpqlnsgVAZ2Zlsuz1xmZoHn47dBQ=; b=QRlCpQWBoQN76NJ5JbbWOtu2l2wf/5oKUHlUS3inu+9RInTd4Ig6rGfL+fxYvuoPL5 KEDHAA9GKxY6GLOmxChv2AfCh0x/JEAbYH+WR/k7c6LL3F+1Vaz5FrnJsi1bDHUTkqe0 zK27EL9hrOTPPOw6sA0b6hNqHyrBnzZZBEn1I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ejct8UX6bJFOwwcKpqlnsgVAZ2Zlsuz1xmZoHn47dBQ=; b=d07CqGlmZyzVAlrP08CrqY9RJa8JoBOvblym0bZ2gTkCvHm6TJP15sk/8uret1UbQZ m2/NmpXa5p1gLc9swwQzTJanTDzoG2uZXv2gMguaTSTdKkj69RO16Vg7dFsOulGE3H4p 07aEsbxT8VUIvxZC6CpFCP8tFNA+EeWga8pMuo1yrrM1sJQrLh2MryQL5DwdLu0XZDuV X2C+yuthsrQVeuaEr6NeS+y7nWn5xzxN5hFNXC4S3SbETFOdroPGd2rygpNAUXrhGhEy JY68ZnfZ7Abc/mN4zeAsuws6LGk/3kAVppZaphi6X4CxD48UQzYnIwarx04131Hbp0BY 2wEA== X-Gm-Message-State: AGRZ1gLaVqUtTRAo4zoMauJ65pGLI6ISwrCflu8an3ChHpF7cBT6dZN4 mpxjlC2Hp94dBUKofwxh02DUKA== X-Received: by 2002:a1c:248b:: with SMTP id k133-v6mr8423407wmk.148.1542376863785; Fri, 16 Nov 2018 06:01:03 -0800 (PST) Received: from lmecxl0911.lme.st.com ([2a04:cec0:105d:3df6:606e:fa38:9819:9c69]) by smtp.gmail.com with ESMTPSA id s81sm11208060wmf.14.2018.11.16.06.01.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Nov 2018 06:01:03 -0800 (PST) From: Benjamin Gaignard X-Google-Original-From: Benjamin Gaignard To: patrick.delaunay@st.com, albert.u.boot@aribaud.net, sjg@chromium.org, christophe.kerello@st.com, patrice.chotard@st.com Date: Fri, 16 Nov 2018 15:00:39 +0100 Message-Id: <20181116140039.11628-5-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20181116140039.11628-1-benjamin.gaignard@st.com> References: <20181116140039.11628-1-benjamin.gaignard@st.com> Cc: uboot-stm32@st-md-mailman.stormreply.com, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v4 4/4] pinctrl: stm32: make pinctrl use hwspinlock X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Benjamin Gaignard 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 --- arch/arm/dts/stm32mp157c-ed1.dts | 4 ++++ drivers/pinctrl/pinctrl_stm32.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/arch/arm/dts/stm32mp157c-ed1.dts b/arch/arm/dts/stm32mp157c-ed1.dts index fc277dd7d2..7a9b742d36 100644 --- a/arch/arm/dts/stm32mp157c-ed1.dts +++ b/arch/arm/dts/stm32mp157c-ed1.dts @@ -369,6 +369,10 @@ status = "okay"; }; +&pinctrl { + hwlocks = <&hwspinlock 0>; +}; + &usbphyc_port0 { phy-supply = <&vdd_usb>; vdda1v1-supply = <®11>; diff --git a/drivers/pinctrl/pinctrl_stm32.c b/drivers/pinctrl/pinctrl_stm32.c index 31285cdd57..402b7803fc 100644 --- a/drivers/pinctrl/pinctrl_stm32.c +++ b/drivers/pinctrl/pinctrl_stm32.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -19,12 +20,20 @@ static int stm32_gpio_config(struct gpio_desc *desc, { struct stm32_gpio_priv *priv = dev_get_priv(desc->dev); struct stm32_gpio_regs *regs = priv->regs; + struct hwspinlock *hws = dev_get_priv(dev_get_parent(desc->dev)); u32 index; + int ret; if (!ctl || ctl->af > 15 || ctl->mode > 3 || ctl->otype > 1 || ctl->pupd > 2 || ctl->speed > 3) return -EINVAL; + ret = hwspinlock_lock_timeout(hws, 1); + if (ret == -ETIME) { + dev_err(desc->dev, "HWSpinlock timeout\n"); + return ret; + } + index = (desc->offset & 0x07) * 4; clrsetbits_le32(®s->afr[desc->offset >> 3], AFR_MASK << index, ctl->af << index); @@ -39,6 +48,8 @@ static int stm32_gpio_config(struct gpio_desc *desc, index = desc->offset; clrsetbits_le32(®s->otyper, OTYPE_MSK << index, ctl->otype << index); + hwspinlock_unlock(hws); + return 0; } @@ -176,6 +187,20 @@ static int stm32_pinctrl_set_state_simple(struct udevice *dev, } #endif /* PINCTRL_FULL */ +static int stm32_pinctrl_probe(struct udevice *dev) +{ + struct hwspinlock *hws = dev_get_priv(dev); + int err; + + /* hwspinlock property is optional, just log the error */ + err = hwspinlock_get_by_index(dev, 0, hws); + if (err) + debug("%s: hwspinlock_get_by_index may have failed (%d)\n", + __func__, err); + + return 0; +} + static struct pinctrl_ops stm32_pinctrl_ops = { #if CONFIG_IS_ENABLED(PINCTRL_FULL) .set_state = stm32_pinctrl_set_state, @@ -200,4 +225,6 @@ U_BOOT_DRIVER(pinctrl_stm32) = { .of_match = stm32_pinctrl_ids, .ops = &stm32_pinctrl_ops, .bind = dm_scan_fdt_dev, + .probe = stm32_pinctrl_probe, + .priv_auto_alloc_size = sizeof(struct hwspinlock), };