Received: by 10.213.65.68 with SMTP id h4csp311615imn; Fri, 23 Mar 2018 05:18:40 -0700 (PDT) X-Google-Smtp-Source: AG47ELsEjVWm230MNKHJkxXkxaLJoeSd9NDJO49hfEUvNk1yfCDmxTqGHsR5I2XcdsPTlVzWOviT X-Received: by 10.98.165.4 with SMTP id v4mr23974604pfm.51.1521807520060; Fri, 23 Mar 2018 05:18:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521807520; cv=none; d=google.com; s=arc-20160816; b=boGB0OaQB03g7buhzFDM9NcJgSAsKZRmKb+egRwfypcDUdXSqZqdRAoxWqx72H7t85 7bddFrY9uk22Ssv6DZvSgo29hkOqNlF7Pea4odoqyP5Jn9Yreu9mIW3dYzaRsKBobabj 9Fuyu/pPfuqMt16dkCeeI7uRR6UYDGe6jJk4ZEefZthtaJj0roi98Sf1EknbFjeeIusQ W5PwjDeWJ+N2/Wb9BeCyhUUe1/HbYdbvRM7gGRu5LGYEIPKdRsW1SFEBpHeQORgNTdNj AmbIMPlmluWKzZJ0KEDGtbP3gcfh+iivu7oemibeL+8gi1MwSy3y8snoDhGifGsLQcEF dyFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=AppRCNAaYPmvqQVZJDB9/C9HoYJIo3p9CjkQW/IY1AI=; b=ssZp2UEATarulKoW9Ig79yLlVmDRqCDPXD24Qho/QXWACzHecGFnU/795Geft9HH15 RGB+H0zgfiQ3WAxCNf9I+yf8QvjopsuL3EOGiqq/5PFDqunZAfWRsrD7cEqB+gSEU0CW QdwrKtLaXQfOSZOb1i46+cXe5xhn0Fs4RqF3dql+FWvEGTA6bSo6I8rcWx1Lj+evw1lp 90z0XjQiElkm5eAdZ08G+vTuZ4Fs7jDxvapsbztgBKXSUfWdi7xu2HisehgSkXe1g95X 3d4mYsYEESn98RCZt0FFpzqAhRiccRhdRe+ViGfrrUx0QBAnizoPhtsskh0wv9dnH8Tu A7AQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h90-v6si4398692plb.377.2018.03.23.05.18.25; Fri, 23 Mar 2018 05:18:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752785AbeCWMRg (ORCPT + 99 others); Fri, 23 Mar 2018 08:17:36 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33900 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752555AbeCWJ4M (ORCPT ); Fri, 23 Mar 2018 05:56:12 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 01D44E78; Fri, 23 Mar 2018 09:56:11 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Uytterhoeven , Mark Brown , Sasha Levin Subject: [PATCH 4.15 15/84] spi: sh-msiof: Avoid writing to registers from spi_master.setup() Date: Fri, 23 Mar 2018 10:53:29 +0100 Message-Id: <20180323095414.213323284@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323095411.913234798@linuxfoundation.org> References: <20180323095411.913234798@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Geert Uytterhoeven [ Upstream commit 7ff0b53c4051145d1cf992d2f60987e6447eed4f ] The spi_master.setup() callback must not change configuration registers, as that could corrupt I/O that is in progress for other SPI slaves. The only exception is the configuration of the native chip select polarity in SPI master mode, as a wrong chip select polarity will cause havoc during all future transfers to any other SPI slave. Hence stop writing to registers in sh_msiof_spi_setup(), unless it is the first call for a controller using a native chip select, or unless native chip select polarity has changed (note that you'll loose anyway if I/O is in progress). Even then, only do what is strictly necessary, instead of calling sh_msiof_spi_set_pin_regs(). Signed-off-by: Geert Uytterhoeven Signed-off-by: Mark Brown Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-sh-msiof.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) --- a/drivers/spi/spi-sh-msiof.c +++ b/drivers/spi/spi-sh-msiof.c @@ -55,6 +55,8 @@ struct sh_msiof_spi_priv { void *rx_dma_page; dma_addr_t tx_dma_addr; dma_addr_t rx_dma_addr; + bool native_cs_inited; + bool native_cs_high; bool slave_aborted; }; @@ -528,8 +530,7 @@ static int sh_msiof_spi_setup(struct spi { struct device_node *np = spi->master->dev.of_node; struct sh_msiof_spi_priv *p = spi_master_get_devdata(spi->master); - - pm_runtime_get_sync(&p->pdev->dev); + u32 clr, set, tmp; if (!np) { /* @@ -539,19 +540,31 @@ static int sh_msiof_spi_setup(struct spi spi->cs_gpio = (uintptr_t)spi->controller_data; } - /* Configure pins before deasserting CS */ - sh_msiof_spi_set_pin_regs(p, !!(spi->mode & SPI_CPOL), - !!(spi->mode & SPI_CPHA), - !!(spi->mode & SPI_3WIRE), - !!(spi->mode & SPI_LSB_FIRST), - !!(spi->mode & SPI_CS_HIGH)); - - if (spi->cs_gpio >= 0) + if (spi->cs_gpio >= 0) { gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); + return 0; + } + + if (spi_controller_is_slave(p->master)) + return 0; + if (p->native_cs_inited && + (p->native_cs_high == !!(spi->mode & SPI_CS_HIGH))) + return 0; + /* Configure native chip select mode/polarity early */ + clr = MDR1_SYNCMD_MASK; + set = MDR1_TRMD | TMDR1_PCON | MDR1_SYNCMD_SPI; + if (spi->mode & SPI_CS_HIGH) + clr |= BIT(MDR1_SYNCAC_SHIFT); + else + set |= BIT(MDR1_SYNCAC_SHIFT); + pm_runtime_get_sync(&p->pdev->dev); + tmp = sh_msiof_read(p, TMDR1) & ~clr; + sh_msiof_write(p, TMDR1, tmp | set); pm_runtime_put(&p->pdev->dev); - + p->native_cs_high = spi->mode & SPI_CS_HIGH; + p->native_cs_inited = true; return 0; }