From patchwork Fri Nov 9 22:00:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 10676585 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 EF80214DB for ; Fri, 9 Nov 2018 22:01:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDAD12F1FA for ; Fri, 9 Nov 2018 22:01:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D18AC2F2F4; Fri, 9 Nov 2018 22:01:27 +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 734B72F1FA for ; Fri, 9 Nov 2018 22:01:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728329AbeKJHn4 (ORCPT ); Sat, 10 Nov 2018 02:43:56 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:45338 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728492AbeKJHn4 (ORCPT ); Sat, 10 Nov 2018 02:43:56 -0500 Received: by mail-qk1-f195.google.com with SMTP id d135so4341704qkc.12 for ; Fri, 09 Nov 2018 14:01:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gyA4qzOls2dsDUjH6ST4e0OKCIbB05c/8v+y7nhk1V4=; b=HGwpQeCLEUulEQrOBOVKkjGIqghtUITOC0ckE/3SfPwmVOobwnI32YUbh85q0awaBQ J+KI1prFWJ98s0gcXVtKOxj/de+HEo+maYiAwDD8g17xuRZQNdZkxqzs55kpE97rWo+R bty1WvAgGS70IJlhXRI4rBWBoIhIGbgFn+shZQMIHMIMIcX3w3c+PYtPLUzR0ywXRp9O 8A2I5r4l0TaCUn1vQn9SufQKeZ3qfBZ5B5tAqvHHwXz10V0O2W+9rvE9tTxKHFDvFZZm bOSyjHRrqGomfR7bIZyjpuAqi+9z7iTFc/xqJoknzS50lmtDwjCBynp/Jobvv8swNAWU n8+Q== 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=gyA4qzOls2dsDUjH6ST4e0OKCIbB05c/8v+y7nhk1V4=; b=M3ijcjh8+GHOK4GZys9k3eMTY3Y2KZNU1R6xS7nV+LZDf0xJBH3xMLoynrYUaIdbj/ rF6BeDngoY4frtpMAahOGaEeqOVYTg3Zg2WVJnoGd6h/ifnGEelPXsMoE7lqAWgrQqBX bftkNi26SZFvWdGykRjSI9+zYTbTkYD5qzKIyLmPf1G9dI65QGBOp41wGceYL9O21M3D AvJ6bjx2OWSTVbc4ABI9B7X33l0oEkWzve1QbSPpmhZsi5ctYI33wty4nUz4MlNHSk22 QF8iPDZXg5MulAOKx7B2CJlyv9C0ZOHwq3EcmRZwTq18xEClySxBC5ghN6Rc/qc1DZl5 imwQ== X-Gm-Message-State: AGRZ1gIiUhdRtIZ7e2yR2C1a7JfYAcVnRHiJGS27BGqRv8yEfkd7etca Uw3lRCEyrdUm4hTq0hudSPKdmcnlCJd9sg== X-Google-Smtp-Source: AJdET5f/KLCnyHZgNED3vTKjaHsL92kTxzZbo0naegSsvxqoT1sye/7PBziFZKD7fn84V6S3TfMUWQ== X-Received: by 2002:ac8:2b99:: with SMTP id m25mr7214545qtm.36.1541800885112; Fri, 09 Nov 2018 14:01:25 -0800 (PST) Received: from mango.spo.virtua.com.br ([2804:14c:81:942d::1]) by smtp.gmail.com with ESMTPSA id k6sm6082723qtk.41.2018.11.09.14.01.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 14:01:24 -0800 (PST) From: Matheus Tavares To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Hartmut Knaack , Peter Meerwald-Stadler , Greg Kroah-Hartman , Rob Herring , Mark Rutland Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandru Ardelean , kernel-usp@googlegroups.com, victorcolombo@gmail.com Subject: [PATCH 3/6] staging:iio:ad2s90: Add max frequency check at probe Date: Fri, 9 Nov 2018 20:00:41 -0200 Message-Id: <20181109220044.24843-4-matheus.bernardino@usp.br> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181109220044.24843-1-matheus.bernardino@usp.br> References: <20181109220044.24843-1-matheus.bernardino@usp.br> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a max frequency check at the beginning of ad2s90_probe function so that when it is set to a value above 0.83Mhz, dev_err is called with an appropriate message and -EINVAL is returned. The defined limit is 0.83Mhz instead of 2Mhz, which is the chip's max frequency as specified in the datasheet, because, as also specified in the datasheet, a 600ns delay is expected between the application of a logic LO to CS and the application of SCLK. Since the delay is not implemented in the spi code, to satisfy it, SCLK's period should be at most 2 * 600ns, so the max frequency should be 1 / (2 * 6e-7), which gives roughly 830000Hz. Signed-off-by: Matheus Tavares Signed-off-by: Alexandru Ardelean --- Alex's S-o-B was added because he gave the code suggestion for this patch. drivers/staging/iio/resolver/ad2s90.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c index 95c118c48400..949ff55ac6b0 100644 --- a/drivers/staging/iio/resolver/ad2s90.c +++ b/drivers/staging/iio/resolver/ad2s90.c @@ -19,6 +19,12 @@ #include #include +/* + * Although chip's max frequency is 2Mhz, it needs 600ns between CS and the + * first falling edge of SCLK, so frequency should be at most 1 / (2 * 6e-7) + */ +#define AD2S90_MAX_SPI_FREQ_HZ 830000 + struct ad2s90_state { struct mutex lock; struct spi_device *sdev; @@ -78,6 +84,12 @@ static int ad2s90_probe(struct spi_device *spi) struct iio_dev *indio_dev; struct ad2s90_state *st; + if (spi->max_speed_hz > AD2S90_MAX_SPI_FREQ_HZ) { + dev_err(&spi->dev, "SPI CLK, %d Hz exceeds %d Hz\n", + spi->max_speed_hz, AD2S90_MAX_SPI_FREQ_HZ); + return -EINVAL; + } + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) return -ENOMEM;