Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2619038pxb; Tue, 24 Aug 2021 03:42:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZjhD2PcbIfKgRUsYBzAOt+7SDvJcFypeWPk7tMnBQOwDkzlZTvtbAFAqi36oX1ei1YS6T X-Received: by 2002:a05:6e02:1d1a:: with SMTP id i26mr25931306ila.96.1629801731412; Tue, 24 Aug 2021 03:42:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629801731; cv=none; d=google.com; s=arc-20160816; b=iF2IWsfJAvlZmpYmaftOJeUjMlQv0BhwkIaIwDi6gTBXGnB5neT/zMioRCrNkEUz5c mWfneMprIO9Vku6V67FkU7csjrmRr98zrUd2Kq9fRTiLjQSwd2y1n+wCcQt5E83uNaqV hkSuB/CnFNk7lf9QUv0VCBWdqj9wUREDwNrGz/eGyDcdkklqNAfRy9ImpKD3g+vK4cH0 qXOlPTlw97ArRXUcwUTIqhAvPp/m1dylYB5nyDxO+0p5MxY2uQtRNAAjRfXD3fIT4/KC MNFYvvpce+d+6aPGEHD+gkxAbyHtgMhtcOfp/WB9Eq0gJ1l2po1p4Vpm4eeIf7VUZnKt Xs7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wmJd13U/MiNXR0MpF3vqHT3p3GrmbatpUhQguV8vWF8=; b=jyt+/j14whRPZW6S/yN/30/9wVUS4x4Di8+DcEoxzGl4xUci7pFkSIhvTB+Xc8AkNt hU4gjScDheLDNNwpJwlEXPoPqwsGjNTOlU34jQVUkdrn2AARXQ55W8Fgasok+WSoj+O1 wM/hgX4vQQUh7SUCAfQOlHe11NLDdk2sLzERZOxi7O2gWlPm07H5yazUbfSuWioI7NLT /JEqgv8CPEAk9u8/GDR4UCmEj5m6z3etYnGsDClcPwnaBTkIPnj8OTVYSp2MD/n2wpLq j4gdprPv4v8NivEjwFD4ciza8ugMzMLmJQWmm2hmg05kfn9GLLo3sUelXWAGoU8TsEyQ BcHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=ovOIWCkx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si18312139ilh.9.2021.08.24.03.42.00; Tue, 24 Aug 2021 03:42:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=ovOIWCkx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236454AbhHXKlw (ORCPT + 99 others); Tue, 24 Aug 2021 06:41:52 -0400 Received: from mx0a-001ae601.pphosted.com ([67.231.149.25]:36010 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236379AbhHXKls (ORCPT ); Tue, 24 Aug 2021 06:41:48 -0400 Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 17OA050R016652; Tue, 24 Aug 2021 05:41:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=wmJd13U/MiNXR0MpF3vqHT3p3GrmbatpUhQguV8vWF8=; b=ovOIWCkxW7yRmTHDYJc5kamF/EeyASI8hn+fQrRPmDZDP1y/X25XsTOpCHLaLqX+bVaA ixOO6cb+Fj9Ii5YxeEzEUxmWhGaolfFytfO8HCaia0S83GSxuOJWtOpDJ4BauV4P+3U9 Q8yz7UfC/H/JMs0uwMIMX8Kog/wmuP5TwxYxKMowiEggh4vjNJccg4KnCE8vGKVhbpE/ We51CI3UGaH2iZ5z/IfbbCFICRM9/bqSefbMdyd+/awvmR/LxEwNcbdG09+disygX4B7 yomFbZtTWchXG09FqEKeYuOF4UXytCyTNHRbpVhtqcvZxD663UeTG5wIOasnCF7ZvWJJ dQ== Received: from ediex01.ad.cirrus.com ([87.246.76.36]) by mx0a-001ae601.pphosted.com with ESMTP id 3amjmq8wmh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Tue, 24 Aug 2021 05:41:01 -0500 Received: from EDIEX01.ad.cirrus.com (198.61.84.80) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Tue, 24 Aug 2021 11:40:59 +0100 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.1.2242.12 via Frontend Transport; Tue, 24 Aug 2021 11:40:59 +0100 Received: from aryzen.ad.cirrus.com (unknown [198.61.65.58]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 431BC2BA; Tue, 24 Aug 2021 10:40:59 +0000 (UTC) From: Lucas Tanure To: Mark Brown , Greg Kroah-Hartman , "Rafael J . Wysocki" , Sanjay R Mehta , Nehal Bakulchandra Shah CC: , , , Lucas Tanure Subject: [PATCH 3/9] regmap: spi: SPI_CONTROLLER_CS_PER_TRANSFER affects max read/write Date: Tue, 24 Aug 2021 11:40:35 +0100 Message-ID: <20210824104041.708945-4-tanureal@opensource.cirrus.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210824104041.708945-1-tanureal@opensource.cirrus.com> References: <20210824104041.708945-1-tanureal@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: pxnmr8H-9zsF7uLpZWYAKrXmKDKXbhu7 X-Proofpoint-GUID: pxnmr8H-9zsF7uLpZWYAKrXmKDKXbhu7 X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org regmap-spi will split data and address between two transfers in the same message so use addr_affects_max_raw_rw to flag that the number bytes to read or write should be a little less (address + padding size), so that the SPI controller can merge the entire message into a single CS period Signed-off-by: Lucas Tanure --- drivers/base/regmap/regmap-spi.c | 14 ++++++++++++-- drivers/base/regmap/regmap.c | 9 +++++++++ include/linux/regmap.h | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/base/regmap/regmap-spi.c b/drivers/base/regmap/regmap-spi.c index 603a4c1c2066..0c1f2e51c0c7 100644 --- a/drivers/base/regmap/regmap-spi.c +++ b/drivers/base/regmap/regmap-spi.c @@ -115,12 +115,22 @@ static const struct regmap_bus *regmap_get_spi_bus(struct spi_device *spi, struct spi_master *master = spi->master; struct regmap_bus *bus = NULL; - if (master->max_transfer_size) { + if (master->max_transfer_size || (master->flags & SPI_CONTROLLER_CS_PER_TRANSFER)) { bus = kmemdup(®map_spi, sizeof(*bus), GFP_KERNEL); if (!bus) return ERR_PTR(-ENOMEM); bus->free_on_exit = true; - bus->max_raw_read = bus->max_raw_write = master->max_transfer_size(spi); + + /* regmap-spi will split data and address between two transfers in the same message + * so use addr_affects_max_raw_rw to flag that the number bytes to read or write + * should be a little less (address + padding size), so the controller can + * fit both transfers in a single CS period + */ + bus->addr_affects_max_raw_rw = master->flags & SPI_CONTROLLER_CS_PER_TRANSFER; + + if (master->max_transfer_size) + bus->max_raw_read = bus->max_raw_write = master->max_transfer_size(spi); + return bus; } diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 6ad41d0720ba..31d0949b6c2f 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -815,6 +815,15 @@ struct regmap *__regmap_init(struct device *dev, if (bus) { map->max_raw_read = bus->max_raw_read; map->max_raw_write = bus->max_raw_write; + if (bus->addr_affects_max_raw_rw) { + if (map->max_raw_read < map->format.buf_size || + map->max_raw_write < map->format.buf_size) { + ret = -EINVAL; + goto err_name; + } + map->max_raw_read -= (map->format.reg_bytes + map->format.pad_bytes); + map->max_raw_write -= (map->format.reg_bytes + map->format.pad_bytes); + } } map->dev = dev; map->bus = bus; diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 77755196277c..a90d1e270b1f 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -504,6 +504,7 @@ typedef void (*regmap_hw_free_context)(void *context); * @max_raw_read: Max raw read size that can be used on the bus. * @max_raw_write: Max raw write size that can be used on the bus. * @free_on_exit: kfree this on exit of regmap + * @addr_affects_max_raw_rw: max_raw_[read|write] must include the address and padding preamble */ struct regmap_bus { bool fast_io; @@ -522,6 +523,7 @@ struct regmap_bus { size_t max_raw_read; size_t max_raw_write; bool free_on_exit; + bool addr_affects_max_raw_rw; }; /* -- 2.33.0