From patchwork Thu Dec 5 09:13:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 180862 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1705912ile; Thu, 5 Dec 2019 01:13:46 -0800 (PST) X-Google-Smtp-Source: APXvYqwT4RP3g4/ONkwDSyxsRLNcO644Fe7l5Cd0/99HKPhUU5hLuT5pZOCakfcV7C27KJWVZBkd X-Received: by 2002:a9d:630d:: with SMTP id q13mr5456033otk.31.1575537226009; Thu, 05 Dec 2019 01:13:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575537226; cv=none; d=google.com; s=arc-20160816; b=s9C3BDfjAgErMwxqQJJ7kHh+8Yn0ovkRWZAb0BN/I5njPDF01AGx+0y4zbUqDnqHXZ KGf4uMsMLQLTtLAIsKbKHEbttUuMohRjwuPULjV7yH/PQW4VCutnyNfwX/AKwrFVi4wB TixhY1/fgvMpGWmFCTYVj02tOLS4Khv9Px4DtP0iA1C6JHqwWo+nloKSZBN4Shb4DdDj /cox6VI1nZDA2jaRYzztvkLnbH6BMY/nyNs+ndR/G7OVQwaHlzH+0ISE4Rw8iPpWkF2r 180xCHdSFrK1gydKZZo6XawQn9b8HBsvj2V1N8QYdw0WH53856qiHp5hGCce7bvJIQij HDzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=RR1kjg9Kjz7rF3zhZSvGyA6Bp/21tr6u4LK78prBW84=; b=jvSaXMLNDmGBKGcjCtFoTi5ZshtpNeZcwl1vDqaLaiah0zxhiSuZ80P5dIlJU0Bkjf LEpIHrODdbagwmB6aWFrDGEMEmYbNNv7uROxGdxGmQ7YyrzsAk5rxjyVdfOFOqtMhFlU t6qzog+/movIoCD/Bpe2AsPqwnJeBkaCumFROWO3gJ5jZB5begQTN12um6kdAXdD3z7I m2w9Azqqk8YdMnE8RMj4ar5B87rPHIqxUhjISnV3VQxyUuG8b3eyTlj4rvxaw8ExHeUa OIiiyRPRudDj76XkTRjylXffQO3K2ycwbbN+TVGNH7Coavtc2uBMwmR4hiDW0KEJxNMk AlQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a8MWHdts; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c12si4793756otn.7.2019.12.05.01.13.45; Thu, 05 Dec 2019 01:13:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-spi-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=@linaro.org header.s=google header.b=a8MWHdts; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729010AbfLEJNp (ORCPT + 2 others); Thu, 5 Dec 2019 04:13:45 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:45775 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728991AbfLEJNp (ORCPT ); Thu, 5 Dec 2019 04:13:45 -0500 Received: by mail-lj1-f194.google.com with SMTP id d20so2618905ljc.12 for ; Thu, 05 Dec 2019 01:13:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RR1kjg9Kjz7rF3zhZSvGyA6Bp/21tr6u4LK78prBW84=; b=a8MWHdts9ofTS15DWm7UPuPce9kKC1/Mv17/S/JkjS6hfR8te7LFOYM5TuYq7Y0fy1 WaWTrLhPa97EHI05XJOSOREeeKkeoWJgvGVrWPu5TezrdmeKHsR6nwRcyOYco2URyVMo 2yaL1CT+fEk4sThYvzUi8AejGoG0AZk8/XO9zQSu7CrlantfY0g48SL/HZzPWkL9bvpM BAbYN0wsDUpuLv7ZeYZuUWdl8i4DpckRdKH74SKIdjCpmopM0WxEAsPe+Z3LeUEk48D7 UBAg9WdY2ZVlqcN1jH55YX/X8JgHGX5nAtI6mc5EZg+5RoAg5s6kgM73teBwHa6dt4dl 1Ezg== 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:mime-version :content-transfer-encoding; bh=RR1kjg9Kjz7rF3zhZSvGyA6Bp/21tr6u4LK78prBW84=; b=mzs3EWvLa79SV9qHxVgzfNxbkC/ClnS1UTriJUvOrvRSoJEfYbPeN9Sj4kCxR6tbWU jBhFWtPUfUz73NDaTNyjRzt5m8QVjXlC2raBa7aB7UNSbVVxU8WNpuXRC8mRrdrXZxc0 91nb/M0qYHXf5h6W/ePUPtrCnvfnrByKdEcf5BTChNnp+pJFaMlmOOWHOh9I86uP2WSP 2hCkbEbcp/ISumeI5yy2msdsY/AqMTM2GXGTQ/g6zgtXqZANKzIQgQfC39RFUp7tyNbw 8DFb57uclQ6kwh8AcAioB8Rqweflb9rE6h2feDAWmS2EmIq3od/EgqHT6L5hl0HvNB0u nJLw== X-Gm-Message-State: APjAAAUnvKmtVT0Nw2YsOasxPhcVbULl0XWM3u6QnjP8EzsR5j3ayG0k k6VMvUXCtZ5JfeQjCPBqrg8pfg== X-Received: by 2002:a2e:8016:: with SMTP id j22mr4875779ljg.24.1575537223428; Thu, 05 Dec 2019 01:13:43 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t9sm4521708ljj.19.2019.12.05.01.13.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2019 01:13:42 -0800 (PST) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org Cc: Linus Walleij Subject: [PATCH] spi: bitbang: Make chipselect callback optional Date: Thu, 5 Dec 2019 10:13:40 +0100 Message-Id: <20191205091340.59850-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org The ->chipselect() callback on the bit-banged SPI library master is optional if using GPIO descriptors: when using descriptors exclusively without any native chipselects, the core does not even call out the the native ->set_cs() and therefore ->chipselect() on a bit-banged SPI master will not even be called in this case. Make sure to respect the SPI_MASTER_GPIO_SS as used by e.g. spi-gpio.c though: this setting will make the core handle the chip select using GPIO descriptors *AND* call the local chipselect handler. Signed-off-by: Linus Walleij --- drivers/spi/spi-bitbang.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) -- 2.23.0 diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c index d84e22dd6f9f..68491a8bf7b5 100644 --- a/drivers/spi/spi-bitbang.c +++ b/drivers/spi/spi-bitbang.c @@ -329,8 +329,20 @@ static void spi_bitbang_set_cs(struct spi_device *spi, bool enable) int spi_bitbang_init(struct spi_bitbang *bitbang) { struct spi_master *master = bitbang->master; + bool custom_cs; - if (!master || !bitbang->chipselect) + if (!master) + return -EINVAL; + /* + * We only need the chipselect callback if we are actually using it. + * If we just use GPIO descriptors, it is surplus. If the + * SPI_MASTER_GPIO_SS flag is set, we always need to call the + * driver-specific chipselect routine. + */ + custom_cs = (!master->use_gpio_descriptors || + (master->flags & SPI_MASTER_GPIO_SS)); + + if (custom_cs && !bitbang->chipselect) return -EINVAL; mutex_init(&bitbang->lock); @@ -344,7 +356,12 @@ int spi_bitbang_init(struct spi_bitbang *bitbang) master->prepare_transfer_hardware = spi_bitbang_prepare_hardware; master->unprepare_transfer_hardware = spi_bitbang_unprepare_hardware; master->transfer_one = spi_bitbang_transfer_one; - master->set_cs = spi_bitbang_set_cs; + /* + * When using GPIO descriptors, the ->set_cs() callback doesn't even + * get called unless SPI_MASTER_GPIO_SS is set. + */ + if (custom_cs) + master->set_cs = spi_bitbang_set_cs; if (!bitbang->txrx_bufs) { bitbang->use_dma = 0;