From patchwork Wed Mar 27 14:30:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10873563 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BBE7E1708 for ; Wed, 27 Mar 2019 14:31:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A863E28DF1 for ; Wed, 27 Mar 2019 14:31:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6FBC28E14; Wed, 27 Mar 2019 14:31:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5030428E18 for ; Wed, 27 Mar 2019 14:31:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728530AbfC0Oaz (ORCPT ); Wed, 27 Mar 2019 10:30:55 -0400 Received: from mail-eopbgr70113.outbound.protection.outlook.com ([40.107.7.113]:35543 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727972AbfC0Oay (ORCPT ); Wed, 27 Mar 2019 10:30:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.se; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gdjVWfpKaEvk96aAb9OOjnieMh6+4UP3G9ErD3SwCOk=; b=gjIlz0/WHeor3g/tQEnG2rfY/GhyZJ79dPiu9BSaarJupYFe27My7WN0FcTlVvaRoLvy2jMZt7CVpjZwtUqawy4K/U/R/GvYbW1wpDsN9jwAt+ZUJJd6i4bbVmGcfR0bpvYDHcbcacUCtMaXDGkjqDu5zULEXgDYiji7arwu+q8= Received: from AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM (20.179.1.31) by AM6PR10MB1877.EURPRD10.PROD.OUTLOOK.COM (52.134.117.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1730.18; Wed, 27 Mar 2019 14:30:50 +0000 Received: from AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM ([fe80::a442:a35b:115a:ef14]) by AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM ([fe80::a442:a35b:115a:ef14%2]) with mapi id 15.20.1750.014; Wed, 27 Mar 2019 14:30:50 +0000 From: Rasmus Villemoes To: Mark Brown , "linux-spi@vger.kernel.org" CC: "linux-kernel@vger.kernel.org" , Fabio Estevam , Rasmus Villemoes Subject: [RFC PATCH 1/4] spi: spi-fsl-spi: remove always-true conditional in fsl_spi_do_one_msg Thread-Topic: [RFC PATCH 1/4] spi: spi-fsl-spi: remove always-true conditional in fsl_spi_do_one_msg Thread-Index: AQHU5KmslSS7/P637kGSh+cRRYuD0g== Date: Wed, 27 Mar 2019 14:30:50 +0000 Message-ID: <20190327143040.16013-2-rasmus.villemoes@prevas.dk> References: <20190327143040.16013-1-rasmus.villemoes@prevas.dk> In-Reply-To: <20190327143040.16013-1-rasmus.villemoes@prevas.dk> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1PR0402CA0055.eurprd04.prod.outlook.com (2603:10a6:7:7c::44) To AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:a5::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Rasmus.Villemoes@prevas.se; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-originating-ip: [81.216.59.226] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ccc19e32-f820-4422-6464-08d6b2c0cefc x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600127)(711020)(4605104)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:AM6PR10MB1877; x-ms-traffictypediagnostic: AM6PR10MB1877: x-microsoft-antispam-prvs: x-forefront-prvs: 0989A7979C x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(396003)(136003)(39850400004)(376002)(346002)(199004)(189003)(386003)(7736002)(72206003)(5660300002)(186003)(76176011)(8936002)(2906002)(4326008)(305945005)(102836004)(26005)(42882007)(97736004)(68736007)(71200400001)(71190400001)(99286004)(25786009)(66066001)(6506007)(52116002)(53936002)(81166006)(3846002)(256004)(105586002)(107886003)(486006)(446003)(14444005)(6436002)(106356001)(2501003)(6116002)(11346002)(1076003)(6512007)(6486002)(54906003)(81156014)(110136005)(8676002)(74482002)(316002)(50226002)(14454004)(36756003)(2616005)(44832011)(476003)(478600001)(8976002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM6PR10MB1877;H:AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: prevas.se does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: wUr3bzxgeR39SQdm27QZYgUSEOOh609QE3/JYW/atnA+iBuKjeSPf1NoQzrRv6F0aEmE3/AioHjtKNLQMIXJuAn8dirVfcRHERuMh7y3GwTs4/GvY2d8BBSfeox8+D2hGTtukUzV9AUzb691SBF/rwi//yl10ofk0YyW8h1JsWtS/AfEoI945GkF9cVLLNbNxjQ1duTR1XaO6pBLgDIWh76fvppTLvFjGHeDJBnsqa2KKJDoZm4Tn6S4Sdt1Of3QBauYBfio8+sQfszS3KCv6G7F/kn+lHARATEh6he8kDTwcNlAHaO7sEa6PWax1rKz5PdTapmah1kJ50cKNkalbapVJPnkkqaIOGM3+ygppBuuikFB2OUc/efbAdMZY3jWYNjgSkynK/I+Qsr/UF0VqJ6bpb6BTlhNnQA/FmVyvm0= MIME-Version: 1.0 X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: ccc19e32-f820-4422-6464-08d6b2c0cefc X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Mar 2019 14:30:50.0859 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR10MB1877 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP __spi_validate() in the generic SPI code sets ->speed_hz and ->bits_per_word to non-zero values, so this condition is always true. Signed-off-by: Rasmus Villemoes --- This of course relies on no spi_message reaching ->transfer_one_message without having been through __spi_validate. I believe that's ok. drivers/spi/spi-fsl-spi.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 3d7b50c65f36..6d114daa178a 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -384,12 +384,10 @@ static int fsl_spi_do_one_msg(struct spi_master *master, cs_change = 1; status = -EINVAL; list_for_each_entry(t, &m->transfers, transfer_list) { - if (t->bits_per_word || t->speed_hz) { - if (cs_change) - status = fsl_spi_setup_transfer(spi, t); - if (status < 0) - break; - } + if (cs_change) + status = fsl_spi_setup_transfer(spi, t); + if (status < 0) + break; if (cs_change) { fsl_spi_chipselect(spi, BITBANG_CS_ACTIVE); From patchwork Wed Mar 27 14:30:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10873561 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 709AB922 for ; Wed, 27 Mar 2019 14:31:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59A5728DA7 for ; Wed, 27 Mar 2019 14:31:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57B3E28E19; Wed, 27 Mar 2019 14:31:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24CEB28DA7 for ; Wed, 27 Mar 2019 14:31:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728609AbfC0Oa4 (ORCPT ); Wed, 27 Mar 2019 10:30:56 -0400 Received: from mail-eopbgr70113.outbound.protection.outlook.com ([40.107.7.113]:35543 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728349AbfC0Oa4 (ORCPT ); Wed, 27 Mar 2019 10:30:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.se; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JVnuYrZwY9ZJ5Fjgt34t0Djxbar20i/E1BPSEJkgNdk=; b=U1fJ9z6q0LRelk8dDZYaHKwXJPmyRcI3i3a2pLCYOJPFSpEN935hOLtEftTP44csmCnLdQIoxCaiypxpmuyn08Y/xfJm5uz4xR3I5UVvk0njaanI0tODQeWiR0eun8OkeKUz4gktD7xDHVfeL/YvkPnajslzGK7SCr6GvcggQXE= Received: from AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM (20.179.1.31) by AM6PR10MB1877.EURPRD10.PROD.OUTLOOK.COM (52.134.117.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1730.18; Wed, 27 Mar 2019 14:30:51 +0000 Received: from AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM ([fe80::a442:a35b:115a:ef14]) by AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM ([fe80::a442:a35b:115a:ef14%2]) with mapi id 15.20.1750.014; Wed, 27 Mar 2019 14:30:51 +0000 From: Rasmus Villemoes To: Mark Brown , "linux-spi@vger.kernel.org" CC: "linux-kernel@vger.kernel.org" , Fabio Estevam , Rasmus Villemoes Subject: [RFC PATCH 2/4] spi: spi-fsl-spi: relax message sanity checking a little Thread-Topic: [RFC PATCH 2/4] spi: spi-fsl-spi: relax message sanity checking a little Thread-Index: AQHU5KmtUp6fohYQCkCUFzODOvwphA== Date: Wed, 27 Mar 2019 14:30:51 +0000 Message-ID: <20190327143040.16013-3-rasmus.villemoes@prevas.dk> References: <20190327143040.16013-1-rasmus.villemoes@prevas.dk> In-Reply-To: <20190327143040.16013-1-rasmus.villemoes@prevas.dk> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1PR0402CA0055.eurprd04.prod.outlook.com (2603:10a6:7:7c::44) To AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:a5::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Rasmus.Villemoes@prevas.se; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-originating-ip: [81.216.59.226] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 2e01c5ec-167e-4c54-7b1d-08d6b2c0cfa8 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600127)(711020)(4605104)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:AM6PR10MB1877; x-ms-traffictypediagnostic: AM6PR10MB1877: x-microsoft-antispam-prvs: x-forefront-prvs: 0989A7979C x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(396003)(136003)(39850400004)(376002)(346002)(199004)(189003)(386003)(7736002)(72206003)(5660300002)(186003)(76176011)(8936002)(2906002)(4326008)(305945005)(102836004)(26005)(42882007)(97736004)(68736007)(71200400001)(71190400001)(99286004)(25786009)(66066001)(6506007)(52116002)(53936002)(81166006)(3846002)(256004)(105586002)(107886003)(486006)(446003)(6436002)(106356001)(2501003)(6116002)(11346002)(1076003)(6512007)(6486002)(54906003)(81156014)(110136005)(8676002)(74482002)(316002)(50226002)(14454004)(36756003)(2616005)(44832011)(476003)(478600001)(8976002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM6PR10MB1877;H:AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: prevas.se does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: SlRhxXh1XQnDD3ZgQxN5H7z9TG9fZqvR+OwtZSSdtqDcbkuI0/m18bTfVhNMr8YaMIbX0xTdQ+XOP5kQ0ILRtyjlw7mjLSY4Cs74dJpE77++NNjCGF7ksXMCIURE1m9PnjYZsYAURE9+v2XealrcZoMLEAaBBaX/V2LmnXbYDXZtPSLvVjGme1auG9bvSFtEwX8BY8u02y1xlSM1mxwZXm0/gT/rPHblH3KPmA57cMycVnoq9XZEDcb9tqkEnZR8BhaD0BG6g6G+y6hdwkF0v61raZ1exfIy5nawrRXHNHXnl7NdL5bbc+Nh8ib5GGMMpp7gLPdb7eI2bN9uOqXd1VcgvaAW83m1xypzFryBs//lWMzy2vik9pW1JiKyUgoj3Gno/sa5GOan+5m/o0i4t217qU0ZWU48FEBgBL3ms6g= MIME-Version: 1.0 X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 2e01c5ec-167e-4c54-7b1d-08d6b2c0cfa8 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Mar 2019 14:30:51.0946 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR10MB1877 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The comment says that we should not allow changes (to bits_per_word/speed_hz) while CS is active, and indeed the code below does fsl_spi_setup_transfer() when the ->cs_change of the previous spi_transfer was set (and for the very first transfer). So the sanity checking is a bit too strict - we can change it to follow the same logic as is used by the actual transfer loop. Signed-off-by: Rasmus Villemoes --- drivers/spi/spi-fsl-spi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 6d114daa178a..481b075689b5 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -370,13 +370,15 @@ static int fsl_spi_do_one_msg(struct spi_master *master, int status; /* Don't allow changes if CS is active */ - first = list_first_entry(&m->transfers, struct spi_transfer, - transfer_list); + cs_change = 1; list_for_each_entry(t, &m->transfers, transfer_list) { + if (cs_change) + first = t; + cs_change = t->cs_change; if ((first->bits_per_word != t->bits_per_word) || (first->speed_hz != t->speed_hz)) { dev_err(&spi->dev, - "bits_per_word/speed_hz should be same for the same SPI transfer\n"); + "bits_per_word/speed_hz cannot change while CS is active\n"); return -EINVAL; } } From patchwork Wed Mar 27 14:30:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10873559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 13CE8922 for ; Wed, 27 Mar 2019 14:31:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0023428BE6 for ; Wed, 27 Mar 2019 14:31:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F24A328E08; Wed, 27 Mar 2019 14:31:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9196B28BE6 for ; Wed, 27 Mar 2019 14:31:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728776AbfC0ObB (ORCPT ); Wed, 27 Mar 2019 10:31:01 -0400 Received: from mail-eopbgr70113.outbound.protection.outlook.com ([40.107.7.113]:35543 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728588AbfC0Oa6 (ORCPT ); Wed, 27 Mar 2019 10:30:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.se; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qHj/08tgktO7OGiX91vK1lw4a50Xf/wTD6czHxmcRxg=; b=dl31YhMPbd+EJcKKLZ4ThoTkNSF+R8fVHOf7RMAibeMo9EMzoiWJKllGbOnmLA9tyxT3Rardj4jeH9TzaBSf3uS6lSPE1vCbHxj8DOfI42qukV4Rg/5n7UZGmFVLGWKMw7txBNyrDNqzuF5UOJbDgKKgCDYT2seKCajjsr7lBWE= Received: from AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM (20.179.1.31) by AM6PR10MB1877.EURPRD10.PROD.OUTLOOK.COM (52.134.117.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1730.18; Wed, 27 Mar 2019 14:30:52 +0000 Received: from AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM ([fe80::a442:a35b:115a:ef14]) by AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM ([fe80::a442:a35b:115a:ef14%2]) with mapi id 15.20.1750.014; Wed, 27 Mar 2019 14:30:52 +0000 From: Rasmus Villemoes To: Mark Brown , "linux-spi@vger.kernel.org" CC: "linux-kernel@vger.kernel.org" , Fabio Estevam , Rasmus Villemoes Subject: [RFC PATCH 3/4] spi: spi-fsl-spi: allow changing bits_per_word while CS is still active Thread-Topic: [RFC PATCH 3/4] spi: spi-fsl-spi: allow changing bits_per_word while CS is still active Thread-Index: AQHU5KmtcGfHbrXiqki/KvhP3QsOXw== Date: Wed, 27 Mar 2019 14:30:51 +0000 Message-ID: <20190327143040.16013-4-rasmus.villemoes@prevas.dk> References: <20190327143040.16013-1-rasmus.villemoes@prevas.dk> In-Reply-To: <20190327143040.16013-1-rasmus.villemoes@prevas.dk> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1PR0402CA0055.eurprd04.prod.outlook.com (2603:10a6:7:7c::44) To AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:a5::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Rasmus.Villemoes@prevas.se; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-originating-ip: [81.216.59.226] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 81f6e81a-5bea-4d80-e6df-08d6b2c0d03c x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600127)(711020)(4605104)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:AM6PR10MB1877; x-ms-traffictypediagnostic: AM6PR10MB1877: x-microsoft-antispam-prvs: x-forefront-prvs: 0989A7979C x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(396003)(136003)(39850400004)(376002)(346002)(199004)(189003)(386003)(7736002)(72206003)(5660300002)(186003)(76176011)(8936002)(2906002)(4326008)(305945005)(102836004)(26005)(42882007)(97736004)(68736007)(71200400001)(71190400001)(99286004)(25786009)(66066001)(6506007)(52116002)(53936002)(81166006)(3846002)(256004)(105586002)(107886003)(486006)(446003)(6436002)(106356001)(2501003)(6116002)(11346002)(1076003)(6512007)(6486002)(54906003)(81156014)(110136005)(8676002)(74482002)(316002)(50226002)(14454004)(36756003)(2616005)(44832011)(476003)(478600001)(8976002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM6PR10MB1877;H:AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: prevas.se does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: DRj/FXXbVNwPurmqv8L4o8jTHpQj04EW99f38Y1NkG3a+41qfR13sbqJHndifJVUkBSkxnumXLt+he4Xk6JzW1MnvNCMel/Y1ua4IfWx0a4LgYvDngUpL825/dedsyMS4IzBSkC8aVQmzf+ulKyQ7/qIa++0hgRX92yctO1g17rKZNDvAan2FPrKMPWRRvYJgbv0KU5p4O13hSaH6SqGPEdDShfi/v8x4ZhvMiU0pxvWpZgN7KiCMum7PvlG5N7X1Mu02B9F9UXZqtZeiCrJEpnCSc71jJ2tabjDLmYEpJYdARWUmXnquQTTswOQT0gIds1E7aE4AWKjZhN8LQFn9z3VhuCrmmZEDvC1TGKhWl8lzxeRQC6T0hDc+pXXbdOyEB0/oQe86jLY8FS3nI+szHf4jczwIg3MC944yjYaEUI= MIME-Version: 1.0 X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 81f6e81a-5bea-4d80-e6df-08d6b2c0d03c X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Mar 2019 14:30:52.0043 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR10MB1877 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit c9bfcb315104 (spi_mpc83xx: much improved driver) introduced logic to ensure bits_per_word and speed_hz stay the same for a series of spi_transfers with CS active, arguing that The current driver may cause glitches on SPI CLK line since one must disable the SPI controller before changing any HW settings. This sounds quite reasonable. So this is a quite naive attempt at relaxing this sanity checking to only ensure that speed_hz is constant - in the faint hope that if we do not causes changes to the clock-related fields of the SPMODE register (DIV16 and PM), those glitches won't appear. The purpose of this change is to allow automatically optimizing large transfers to use 32 bits-per-word; taking one interrupt for every byte is extremely slow. Signed-off-by: Rasmus Villemoes --- drivers/spi/spi-fsl-spi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 481b075689b5..e2b341943796 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -367,7 +367,7 @@ static int fsl_spi_do_one_msg(struct spi_master *master, struct spi_transfer *t, *first; unsigned int cs_change; const int nsecs = 50; - int status; + int status, last_bpw; /* Don't allow changes if CS is active */ cs_change = 1; @@ -375,21 +375,22 @@ static int fsl_spi_do_one_msg(struct spi_master *master, if (cs_change) first = t; cs_change = t->cs_change; - if ((first->bits_per_word != t->bits_per_word) || - (first->speed_hz != t->speed_hz)) { + if (first->speed_hz != t->speed_hz) { dev_err(&spi->dev, - "bits_per_word/speed_hz cannot change while CS is active\n"); + "speed_hz cannot change while CS is active\n"); return -EINVAL; } } + last_bpw = -1; cs_change = 1; status = -EINVAL; list_for_each_entry(t, &m->transfers, transfer_list) { - if (cs_change) + if (cs_change || last_bpw != t->bits_per_word) status = fsl_spi_setup_transfer(spi, t); if (status < 0) break; + last_bpw = t->bits_per_word; if (cs_change) { fsl_spi_chipselect(spi, BITBANG_CS_ACTIVE); From patchwork Wed Mar 27 14:30:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10873565 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65676922 for ; Wed, 27 Mar 2019 14:31:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5041828DFB for ; Wed, 27 Mar 2019 14:31:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D4A728E11; Wed, 27 Mar 2019 14:31:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D410328DF9 for ; Wed, 27 Mar 2019 14:31:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728349AbfC0ObL (ORCPT ); Wed, 27 Mar 2019 10:31:11 -0400 Received: from mail-eopbgr50132.outbound.protection.outlook.com ([40.107.5.132]:15327 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727709AbfC0Oaz (ORCPT ); Wed, 27 Mar 2019 10:30:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.se; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mTy2Yqlb0ksCKbuvBwJDDfOMe7ESWB83Ex/4UpntVdQ=; b=VgpML7xtVsjpJqHZIZglcMQgiDt/XJvsMRBEyRa8Ah93hBS17/Q0drg6m4l14ohs1acrSMCFlKbt9lqzoNfBs1oyTrP3vgpJxhceVORNfci7k6hComEvXdE8FsrzI2Vaz+sobWJZS0C9D9xoEEfS8QUhquaMTaXrIvxEkwU05Sw= Received: from AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM (20.179.1.31) by AM6PR10MB1894.EURPRD10.PROD.OUTLOOK.COM (52.134.117.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.15; Wed, 27 Mar 2019 14:30:52 +0000 Received: from AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM ([fe80::a442:a35b:115a:ef14]) by AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM ([fe80::a442:a35b:115a:ef14%2]) with mapi id 15.20.1750.014; Wed, 27 Mar 2019 14:30:52 +0000 From: Rasmus Villemoes To: Mark Brown , "linux-spi@vger.kernel.org" CC: "linux-kernel@vger.kernel.org" , Fabio Estevam , Rasmus Villemoes Subject: [RFC PATCH 4/4] spi: spi-fsl-spi: automatically adapt bits-per-word in cpu mode Thread-Topic: [RFC PATCH 4/4] spi: spi-fsl-spi: automatically adapt bits-per-word in cpu mode Thread-Index: AQHU5KmutKOAcVt2iECfNjtmXOx7lA== Date: Wed, 27 Mar 2019 14:30:52 +0000 Message-ID: <20190327143040.16013-5-rasmus.villemoes@prevas.dk> References: <20190327143040.16013-1-rasmus.villemoes@prevas.dk> In-Reply-To: <20190327143040.16013-1-rasmus.villemoes@prevas.dk> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1PR0402CA0055.eurprd04.prod.outlook.com (2603:10a6:7:7c::44) To AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:a5::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Rasmus.Villemoes@prevas.se; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-originating-ip: [81.216.59.226] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ceb9f35c-7e0a-4a34-adc4-08d6b2c0d0c0 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600127)(711020)(4605104)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:AM6PR10MB1894; x-ms-traffictypediagnostic: AM6PR10MB1894: x-microsoft-antispam-prvs: x-forefront-prvs: 0989A7979C x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(376002)(366004)(346002)(396003)(136003)(199004)(189003)(99286004)(72206003)(74482002)(66066001)(2501003)(14454004)(44832011)(6512007)(25786009)(256004)(5660300002)(53936002)(107886003)(7736002)(4326008)(305945005)(478600001)(6486002)(105586002)(106356001)(81166006)(8676002)(81156014)(68736007)(42882007)(54906003)(110136005)(71200400001)(102836004)(8976002)(50226002)(8936002)(186003)(26005)(6506007)(386003)(2906002)(36756003)(97736004)(71190400001)(76176011)(6436002)(3846002)(6116002)(1076003)(52116002)(446003)(11346002)(2616005)(316002)(486006)(476003);DIR:OUT;SFP:1102;SCL:1;SRVR:AM6PR10MB1894;H:AM6PR10MB2661.EURPRD10.PROD.OUTLOOK.COM;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: prevas.se does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: ri7o7yBT+iVSxKbDma2ovoPY0K0PHJztcIbgbKzgvWPxgM3WimQ8DxfjBJoAFC5Ss0YT2RzkxZJq8hn8y+oQusHpwZNYkL8e/uBwNFccrAb9/4VZudkviWEI6tpWxRafKxht5eHG3ab66iW6cIUsuUAVDOWF7p9EKQ4j0jS8TQ2Yq+q/eiwjjkZ+zVH/St3eo/TZC5GfobxKiXoppcCKI6SZiDnX08k8UYwjev1qmAGo6ljkTIEG+/dnmeyYmZ7MavmRPCbkoN2NWQQ32Ec5ZAW9rYU9Bsw798h5sDOLnD2uuRmysW3E7r2wtHyxRFdIva9gvue1mawK/1sTXKTpvfk7jOpZ09Dz4TAX9HGgUMPjhXh4TfmTlzvEaLitJHezGA8jSKL4FPyC4pMi2X3D75FmaFjgE6f5c3DyRXYVFZo= MIME-Version: 1.0 X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: ceb9f35c-7e0a-4a34-adc4-08d6b2c0d0c0 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Mar 2019 14:30:52.8829 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR10MB1894 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Taking one interrupt for every byte is rather slow. Since the controller is perfectly capable of transmitting 32 bits at a time, change t->bits_per-word to 32 when the length is divisible by 4 and large enough that the reduced number of interrupts easily compensates for the one or two extra fsl_spi_setup_transfer() calls this causes. Signed-off-by: Rasmus Villemoes --- drivers/spi/spi-fsl-spi.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index e2b341943796..b36ac6aa3b1f 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -363,12 +363,28 @@ static int fsl_spi_bufs(struct spi_device *spi, struct spi_transfer *t, static int fsl_spi_do_one_msg(struct spi_master *master, struct spi_message *m) { + struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(master); struct spi_device *spi = m->spi; struct spi_transfer *t, *first; unsigned int cs_change; const int nsecs = 50; int status, last_bpw; + /* + * In CPU mode, optimize large byte transfers to use larger + * bits_per_word values to reduce number of interrupts taken. + */ + if (!(mpc8xxx_spi->flags & SPI_CPM_MODE)) { + list_for_each_entry(t, &m->transfers, transfer_list) { + if (t->len < 256 || t->bits_per_word != 8) + continue; + if ((t->len & 3) == 0) + t->bits_per_word = 32; + else if ((t->len & 1) == 0) + t->bits_per_word = 16; + } + } + /* Don't allow changes if CS is active */ cs_change = 1; list_for_each_entry(t, &m->transfers, transfer_list) {