Received: by 10.223.185.116 with SMTP id b49csp5962742wrg; Wed, 7 Mar 2018 22:45:22 -0800 (PST) X-Google-Smtp-Source: AG47ELthUnr6EQEeo7Q2DrkC99UesWbJgbwv3KDgYfYXk245A4wpWYZTR79u5ptJ4nZaKidNXJ/H X-Received: by 2002:a17:902:52c1:: with SMTP id a59-v6mr22967696pli.37.1520491522478; Wed, 07 Mar 2018 22:45:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520491522; cv=none; d=google.com; s=arc-20160816; b=mSJxevsR9EYjnQEbiSYQP5NEGt4bTFeANaz+pmexLFd7uRbTelTVjQk2A1e6UeKUR5 8WpL8Zc4x8y6mwYGiq3nk4mMiFZy1qShGangz0Zrwmw9WoN9m3hOPr/+xVJYcv7hAbBh SciM9wx/fYSGPdDe/akiBxqdQfHoyRxgXsQOeyX+P84YKixwUjvg9WGfPvVe75IxsuTP cgSTO4l1rREU+TcuWMoiqBCx9RnpRzXOLzDwlDlP4trpdKeiZI9bmxVi6GSS+9AKlbJw 0GUCc8U8QkIxgaSwoOEUDZJej9srB+ngYOuK4OYRZNZJt5CCHUOsi2EtHusrKa1JCHI6 lC4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=plMtU7X17hriuG/J/4La4ZA9DV9FIO962JiVa2FZubA=; b=wIhPmV3O8zOqGLtz1OtI/fF19ocHcRLWUB+8bPVpFkiidFESOst0rYKO6/HEpOkhp5 YYBBYbUU21FNOXZdTEtYhc9DGEzvGwHRTXRJBlmntIfw8piMIVcgPLSpRCH3ERffODAr 7SFkpck5MGisfuHX4V9G69M3FTeDYvBpOR3MC/gESFV2jY8rfFsxH2m7ZfM0tjLFMW7/ zZFdavLwhMbhViDgv6VYeD9dKpIF2FYQxM6LUJXJWVfm7mJlq5E5X57Mw+DWJtLyW40E FSxR2XrFR3+vguYn7597VV8ofWI1cTamITOcXzDyWDnpCVL8DUAI9Zjg09NFTR5Oo+6M dpdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=oDKuqnU1; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13-v6si14150752plo.537.2018.03.07.22.45.08; Wed, 07 Mar 2018 22:45:22 -0800 (PST) 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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=oDKuqnU1; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935340AbeCHE6f (ORCPT + 99 others); Wed, 7 Mar 2018 23:58:35 -0500 Received: from mail-co1nam03on0091.outbound.protection.outlook.com ([104.47.40.91]:60295 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965053AbeCHE6N (ORCPT ); Wed, 7 Mar 2018 23:58:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=plMtU7X17hriuG/J/4La4ZA9DV9FIO962JiVa2FZubA=; b=oDKuqnU1rQWWpxdqcvZ1LKRU8du2AugsmJ0eO7ovX+9qBNEjIrdkcC9wVYb2ewEW/D1hKAkS8ET9ngPnIDzX6sLX6tvEebGIKkuI0hAQ6714QdwVWzdDWHfruGhDnPwLwBBeNgUVrSWw+ObVEoDAOQcyrYKUcI6ZkXrCq69I5jA= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0888.namprd21.prod.outlook.com (52.132.132.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.588.3; Thu, 8 Mar 2018 04:58:10 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8063:c68a:b210:7446]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8063:c68a:b210:7446%2]) with mapi id 15.20.0588.008; Thu, 8 Mar 2018 04:58:10 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Geert Uytterhoeven , Mark Brown , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 13/67] spi: sh-msiof: Avoid writing to registers from spi_master.setup() Thread-Topic: [PATCH AUTOSEL for 4.14 13/67] spi: sh-msiof: Avoid writing to registers from spi_master.setup() Thread-Index: AQHTtpn6UmDy1mi050+etHEqWe6e/Q== Date: Thu, 8 Mar 2018 04:57:37 +0000 Message-ID: <20180308045641.7814-13-alexander.levin@microsoft.com> References: <20180308045641.7814-1-alexander.levin@microsoft.com> In-Reply-To: <20180308045641.7814-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0888;20:N2vq4vLXecSXgJfU5LrEUDNDCXZCjRCez1xhxkhyZplO+ZI0Jo/wQkPOc0/9PFHH9CHs57Qc8Ha9tNPiB8EtROBgXCFlyiixTWFewefwi0ewWjB2dRY2G77tSo3CZ14Q7KqN5Ehacr1pV00Vu9UJeOfdOAVw+KBOR9nUkpPLSwo= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: cfe6db6b-9e99-457c-12de-08d584b130a2 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0888; x-ms-traffictypediagnostic: DM5PR2101MB0888: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231220)(944501244)(52105095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0888;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0888; x-forefront-prvs: 060503E79B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(366004)(346002)(376002)(39380400002)(396003)(189003)(199004)(6116002)(99286004)(2950100002)(6512007)(6666003)(10290500003)(36756003)(5660300001)(106356001)(1076002)(22452003)(3846002)(97736004)(316002)(53936002)(68736007)(105586002)(4326008)(25786009)(54906003)(478600001)(2501003)(186003)(66066001)(76176011)(3280700002)(86362001)(575784001)(14454004)(2900100001)(5250100002)(110136005)(305945005)(7736002)(72206003)(3660700001)(6436002)(2906002)(26005)(6486002)(10090500001)(8676002)(81156014)(107886003)(81166006)(86612001)(6506007)(8936002)(102836004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0888;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: ry+Y0HE3jcOo86J/PzphMcHBlGvuwBzWqmGoQX3ZdT6Nu8b+aPcQh2USZOnQDecrN/mo2WcxP/J4WAESzmBKsFm/eiS75bt9JAiUZ0Tu1VitX4NLeHisMAT4uIa1EUBCM91PYjjtKVCWCVA0ZXFitrdeCOjlf6uNssY5HxU0IeefDVWNlo56PHNHnIMIZImpVQopE7kJlo0RTASdL3vfFfWMqMYo5OR8fWXt+/wcjqqXwX911PDpEwg4uOmB4yufVN74MzVIIoSTGoHWIKwwJFJOnvWRHsFEHJU0rLm+a+XfgtNiII2MLYy4vVpY0DTrRqZO2gRmLEo4WQJ1WWQ2vQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: cfe6db6b-9e99-457c-12de-08d584b130a2 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2018 04:57:37.0597 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0888 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/spi/spi-sh-msiof.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c index 837bb95eea62..092a5fc85b9a 100644 --- 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; }; =20 @@ -528,8 +530,7 @@ static int sh_msiof_spi_setup(struct spi_device *spi) { struct device_node *np =3D spi->master->dev.of_node; struct sh_msiof_spi_priv *p =3D spi_master_get_devdata(spi->master); - - pm_runtime_get_sync(&p->pdev->dev); + u32 clr, set, tmp; =20 if (!np) { /* @@ -539,19 +540,31 @@ static int sh_msiof_spi_setup(struct spi_device *spi) spi->cs_gpio =3D (uintptr_t)spi->controller_data; } =20 - /* 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 >=3D 0) + if (spi->cs_gpio >=3D 0) { gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); + return 0; + } =20 + if (spi_controller_is_slave(p->master)) + return 0; =20 - pm_runtime_put(&p->pdev->dev); + if (p->native_cs_inited && + (p->native_cs_high =3D=3D !!(spi->mode & SPI_CS_HIGH))) + return 0; =20 + /* Configure native chip select mode/polarity early */ + clr =3D MDR1_SYNCMD_MASK; + set =3D MDR1_TRMD | TMDR1_PCON | MDR1_SYNCMD_SPI; + if (spi->mode & SPI_CS_HIGH) + clr |=3D BIT(MDR1_SYNCAC_SHIFT); + else + set |=3D BIT(MDR1_SYNCAC_SHIFT); + pm_runtime_get_sync(&p->pdev->dev); + tmp =3D sh_msiof_read(p, TMDR1) & ~clr; + sh_msiof_write(p, TMDR1, tmp | set); + pm_runtime_put(&p->pdev->dev); + p->native_cs_high =3D spi->mode & SPI_CS_HIGH; + p->native_cs_inited =3D true; return 0; } =20 --=20 2.14.1