Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3242898imu; Sat, 24 Nov 2018 00:55:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/V6yGcq0FKd1cropq7IBUbTazLpvdVPxS5ABiAZ5CU1RtXtyYwdYyXU7Er6rW4YQVhEAUeQ X-Received: by 2002:a17:902:b701:: with SMTP id d1-v6mr18231089pls.29.1543049719152; Sat, 24 Nov 2018 00:55:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543049719; cv=none; d=google.com; s=arc-20160816; b=cTreRjDljxAjW54eXhoXFc4wg0IPFWK471l1TFCqhq9JjIV4gPklD2szCjXnU2yqOq qUrujVXlTyZiZuogxsAKTH8ykAqD30ICMAbKW+hiIvjxWqP5qpodmtAmGFBVZPJaSHwj FkHpfoiw00UzvoU8TEZ1Afo+t6yYM3uQCkb8mHDMcPGz79a4LUxewN3uEnHbVQPVcMaz 7GsUSTjYHAC2A1Pkqvm5OsirzIT17Z7WtvqH1QwU66YkYq8pfqaFbRDcRNzzrmaHLvsa 4MQ4dxCKwrTHSXszJcHIL4h7kBbnXpLDHcXaDGlYn+avDsuZDMIOopavQ+aJOaX8ti+2 8V5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=5hn8QyLV53KfTj8TSZxKFEiF2d3t53n213nmb376iXM=; b=ramiBPsI0/w5h1THcjmA+8nDRIoQ9kqAWXKje2K9QeZK8B/rx7e+OCXSDgORewzkv5 KZtSH9XcvYkFXqwyA8i17/o8UgyLqqF4OMiF4Loc/HVW5/++AFXUJUmSDeuQaWKJluhN J8JxdIRWmc1bhNGVnC80Z3mTISTZB+CwWRtaxdWCVDi60vUlIiCIHqBHdb5zZvstFPFZ o0V8UoW68UHbzA7Cm4pvhnpB7hvMSwLD08HKwx+wbyb/mowJZ6ps2OUBzwHwbQaqxePR HqOqMDqVszIj7sPe1dP1kZuh3r4ntCSixyLSTC/h00CSGlDKO9GRCayNrURCWt6N3OpD wsFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@usp-br.20150623.gappssmtp.com header.s=20150623 header.b=Sve25buH; 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=fail (p=NONE sp=NONE dis=NONE) header.from=usp.br Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g10si40192003pll.428.2018.11.24.00.55.05; Sat, 24 Nov 2018 00:55:19 -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=@usp-br.20150623.gappssmtp.com header.s=20150623 header.b=Sve25buH; 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=fail (p=NONE sp=NONE dis=NONE) header.from=usp.br Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728293AbeKXLKB (ORCPT + 99 others); Sat, 24 Nov 2018 06:10:01 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:36971 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728230AbeKXLKA (ORCPT ); Sat, 24 Nov 2018 06:10:00 -0500 Received: by mail-qt1-f194.google.com with SMTP id z16so12044499qtq.4 for ; Fri, 23 Nov 2018 16:23:39 -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=5hn8QyLV53KfTj8TSZxKFEiF2d3t53n213nmb376iXM=; b=Sve25buHyKAXVnsqGlNQdjsWiFBcs4WBwtUm+K7XC/FuWEpfVXHJ9qmR9+mvw0EniD WCd05thH3TKNycbEkH9NHiLN+tUEx3QrbbkCKAM8zlXM00wK96XIhZqHFMmFxIrTJzQC GgJQC65D41JbgKvUCm7K12WEd2MZeYMdmvnlh2iIR89e9M9pVLkuuoVF7tYzdJ9U1Mhh 6zVeWQHn3+X/ynGQZyaZij62cTYD8Kk8CpFyBuZg2Eia6AHc+bWp/o+EFbLrf7KO1ID6 9NRtRbCV4m2eYZB0T1FL3U19Owod4gL1hy2mqC0G0pe8VJwH6so4IuL+rNrCnTK+MHuF tqKQ== 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=5hn8QyLV53KfTj8TSZxKFEiF2d3t53n213nmb376iXM=; b=RmDeo2vID0Z9zHMy5GWpwCtbBxCoCuwFjquqo5jnMrSJFaNosA7B7cf1dDGqKWddqj IyykRcIoOYpdhz9ZOiI8ELcc7WOJ/FCJL/jGxZNGqVvoZNNYeXc1Q/Bl6wCNOPXwGEw8 ITUMNc394SJVEh6eHwDywYYkDAUMMx1puXoElMtfg20ta2uK/jMcdqYFf57ECDYaIrQl e/oc5F6eW3rokPy2mmmgkeUEhFzQ4Ri3xuB4DKExNbU+hIJ5oEHCy2xUZ3Tr2K9mwYyz polw9OAhCEMxc074cizvj5bHzNXBRzeeEyBvioxUklbtl+FS8QN7oYwyRV9XTTG6rOz/ M14Q== X-Gm-Message-State: AGRZ1gKTopSUK9OTdF82qAl238qf+xrtd28EbAdi56k0UZpbbG2BxG3d lS+DBUurj2QQvUYerwmFmzZ22g== X-Received: by 2002:ac8:4258:: with SMTP id r24mr16959175qtm.213.1543019018603; Fri, 23 Nov 2018 16:23:38 -0800 (PST) Received: from mango.spo.virtua.com.br ([2804:14c:81:942d::3]) by smtp.gmail.com with ESMTPSA id o34sm26707515qte.4.2018.11.23.16.23.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Nov 2018 16:23:38 -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 v3 3/7] staging:iio:ad2s90: Add max frequency check at probe Date: Fri, 23 Nov 2018 22:23:08 -0200 Message-Id: <20181124002312.6923-4-matheus.bernardino@usp.br> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181124002312.6923-1-matheus.bernardino@usp.br> References: <20181124002312.6923-1-matheus.bernardino@usp.br> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexandru Ardelean 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: Alexandru Ardelean Signed-off-by: Matheus Tavares --- Changes in v3: - none Changes in v2: - Correctly credit Alexandru as the patch's author 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 abb9b9147ee6..4721e9bbb8b0 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; -- 2.18.0