From patchwork Tue May 9 12:24:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seraphime Kirkovski X-Patchwork-Id: 9717841 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8CDDA60237 for ; Tue, 9 May 2017 12:24:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74A1528401 for ; Tue, 9 May 2017 12:24:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6966C28405; Tue, 9 May 2017 12:24:46 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable 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 E40B328401 for ; Tue, 9 May 2017 12:24:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753944AbdEIMY0 (ORCPT ); Tue, 9 May 2017 08:24:26 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:34444 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752552AbdEIMYY (ORCPT ); Tue, 9 May 2017 08:24:24 -0400 Received: by mail-wr0-f195.google.com with SMTP id 6so13285608wrb.1; Tue, 09 May 2017 05:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5vthlHQko8yquU3UZf8HJJDbaxKE6A54tj6GA1GNx+E=; b=owLAAK9HXSZp3I+m1V30b9uwJIt5mSnRWxmEPhvDqyJLkLYGPX2eDHyChTJ1NbmQIz rwACe8fQmjy9sEHt01B8T0tZ03J6H7BOx/JgAr62cYyktJQg/M5NetzCuQwM9XUAC/cx xtjk43fBxQMgrzt3K3RaarrvP+FDR1yNqDJjpx4h39FNujsW4vgS77FV7FgU48OBMYrz Z/ufWW+5OvFVRjfVv20o4uiZjMopGrbHB3e3JK/uB4wZGQyxxYQIpTP5ANwsuskU64I7 Ojr+3GiQhbev2kphedLxFtG5aAQr6GiEJ74fgWVylTkwbo2k9KxcDeHszK5X4cz4yMNR UJPg== 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=5vthlHQko8yquU3UZf8HJJDbaxKE6A54tj6GA1GNx+E=; b=Z1wxIS8PNVFPQMIx5JoaGaKoan4ETq38wVqvb8oCFxZARzHs9DRY8WMuviHfQOgqOR gkrrqijO82KgFPjcSTpct8/Xw9y0M9d2WfZdqB1TswCrwwDxDSS/ZP5eOClaJSjSy0BR t86cbJR0VuL1xHTQsJUYYkaC0td948NXctjephygUziY4qIPtyNCQXEvR/nZL1vaL1rl ozTuSGaIm6WhhZoj3WKTROIfiqC+OnTPOmNeytPb+DwmCKpiRF67NzqlwTawRnp4QL6g b0/sU7utEPtxNs5DFlZJCRCK2XpATnDHA9PLPKV0gpf4hPh19GPm2GRN5Yvr3zn4lHCW nmag== X-Gm-Message-State: AODbwcAz5jUyjNgYCB17hM4V3qCRx3k/q3G2iV7X8CDnqaXsgACNJ+oj xLZv2oXSKREtRA== X-Received: by 10.28.47.88 with SMTP id v85mr1027171wmv.110.1494332662342; Tue, 09 May 2017 05:24:22 -0700 (PDT) Received: from macchiaveli (cha92-19-78-239-153-115.fbx.proxad.net. [78.239.153.115]) by smtp.gmail.com with ESMTPSA id o20sm14908946wro.61.2017.05.09.05.24.20 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 09 May 2017 05:24:21 -0700 (PDT) Received: by macchiaveli (sSMTP sendmail emulation); Tue, 09 May 2017 14:24:20 +0200 From: Seraphime Kirkovski To: linux-kernel@vger.kernel.org Cc: linux-spi@vger.kernel.org, broonie@kernel.org, Seraphime Kirkovski Subject: [PATCH 1/2] spi: spidev: introduce SPI_IOC_WR_DEFAULT_MAX_SPEED_HZ command Date: Tue, 9 May 2017 14:24:00 +0200 Message-Id: <20170509122401.2561-2-kirkseraph@gmail.com> X-Mailer: git-send-email 2.13.0.rc1 In-Reply-To: <20170509122401.2561-1-kirkseraph@gmail.com> References: <20170509122401.2561-1-kirkseraph@gmail.com> 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 Historically SPI_IOC_WR_MAX_SPEED_HZ was changing the ->max_speed_hz field of the underlying struct spi_dev, which made the effects last way after releasing one particular /dev/spidev* fd. This changed in 9169051617df7 ("spi: spidev: Don't mangle max_speed_hz in underlying spi device") or 7 years after the introduction of SPI_IOC_WR_MAX_SPEED_HZ ! In the mean time there were userspace tools developped with the assumptions that the effects of this particular command are system-wide. [1] is a suite of two small programs for reading, writing and configuring SPI interfaces. The `spi-config -s` part was working good in our setup with old 3.x kernels. We discovered this "regression" when we tried to port our workflow to newer kernels. I think, this change is necessary, on the one hand, because there are still a lot of longterm[2] supported kernels out there, whose users may be relying on SPI_IOC_WR_MAX_SPEED being system-wide and, on the other hand, this same command has been exhibiting a different behaviour for 3 years now, so its users may break, if 9169051617df7 is reverted in one way or another. The semantics of the proposed command are the same as the old SPI_IOC_WR_MAX_SPEED_HZ. [1] https://github.com/cpb-/spi-tools [2] A quick check on kernel.org shows that all 3.x with longterm support have not applied 9169051617df7 Signed-off-by: Seraphime Kirkovski (Haapie) --- drivers/spi/spidev.c | 8 ++++++-- include/uapi/linux/spi/spidev.h | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index 9a2a79a871ba..18d310db90ab 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c @@ -474,6 +474,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) dev_dbg(&spi->dev, "%d bits per word\n", tmp); } break; + case SPI_IOC_WR_DEFAULT_MAX_SPEED_HZ: case SPI_IOC_WR_MAX_SPEED_HZ: retval = __get_user(tmp, (__u32 __user *)arg); if (retval == 0) { @@ -483,9 +484,12 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) retval = spi_setup(spi); if (retval >= 0) spidev->speed_hz = tmp; - else + else { dev_dbg(&spi->dev, "%d Hz (max)\n", tmp); - spi->max_speed_hz = save; + spi->max_speed_hz = save; + } + if (cmd != SPI_IOC_WR_DEFAULT_MAX_SPEED_HZ) + spi->max_speed_hz = save; } break; diff --git a/include/uapi/linux/spi/spidev.h b/include/uapi/linux/spi/spidev.h index dd5f21e75805..91ed22154bc0 100644 --- a/include/uapi/linux/spi/spidev.h +++ b/include/uapi/linux/spi/spidev.h @@ -128,7 +128,7 @@ struct spi_ioc_transfer { #define SPI_IOC_RD_BITS_PER_WORD _IOR(SPI_IOC_MAGIC, 3, __u8) #define SPI_IOC_WR_BITS_PER_WORD _IOW(SPI_IOC_MAGIC, 3, __u8) -/* Read / Write SPI device default max speed hz */ +/* Read / Write SPI device max speed hz */ #define SPI_IOC_RD_MAX_SPEED_HZ _IOR(SPI_IOC_MAGIC, 4, __u32) #define SPI_IOC_WR_MAX_SPEED_HZ _IOW(SPI_IOC_MAGIC, 4, __u32) @@ -136,6 +136,8 @@ struct spi_ioc_transfer { #define SPI_IOC_RD_MODE32 _IOR(SPI_IOC_MAGIC, 5, __u32) #define SPI_IOC_WR_MODE32 _IOW(SPI_IOC_MAGIC, 5, __u32) +/* Write SPI device default max speed hz */ +#define SPI_IOC_WR_DEFAULT_MAX_SPEED_HZ _IOW(SPI_IOC_MAGIC, 6, __u32) #endif /* SPIDEV_H */