From patchwork Sat Apr 20 11:08:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 162591 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp461320jan; Sat, 20 Apr 2019 04:10:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxX8oBkR/tFVrKdKGOkUoRRZGTHNJOLJgyhFym32M8re+b4IBuyF0S/wLZxg92RDBHXfPff X-Received: by 2002:aa7:9466:: with SMTP id t6mr9288484pfq.246.1555758617253; Sat, 20 Apr 2019 04:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555758617; cv=none; d=google.com; s=arc-20160816; b=Aawil7kcnwthnMElk5Nq25Irchd1B4VKpnNkQBm/C3CabGc4Yl5VVRhZD5apbL3NQ2 nzAEV8MakPT6zC3fPJ5bCh8EMs/thu4tFUbn7xidT4rc8auphk+7ah819zgOtYjQP6pk HxRfemE5vp970E3FrYEZuZc9QE7kvJ/c4tTRpx5bdU8x/1aGBNDywSLgyXXewZZLHJKj eHt/k08t56pa41mILZd/3ucAPru0o9S2NqDpFz9WIawzgbmuezhpck0RkH8k2YhoFNE9 zoRjMvzBKY+0ByPuRsbvAsJmfRaneesncZMMGfvnqKCQprU2w68bG2Wr3etzUAPONuEq mxjg== 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=cuVq7cKNKVRapmWC1ujPQEg8efHGa8UKb8kOjcj/mbU=; b=FAXqXLRgpYVDMbGz/2bF3e8MEzfeXFnh1aJEEB7SSM4MCM78ekHmL99iDrzRxnZbxl uThjInSp/GZ5SlfTj1clGpRsPyg1/0rDZiHd7VbIsQgLHaIORXSsmtUq108mN2FMLo31 SZkXbKOZzuMijKl0mJF8aE+2mzGy5VkYk8B6eSomU+jfh727CTK0F1uKYYzcGp+YiQwP 61pOhRK84PNg+SnO4TYFxhLcznqjBGyl7fyF8k8sWzNHq1uEVIzVrplRc1031afhdzvl M4Lhr2+Akv7+GZRqHRZkadKsFpiSPDT3OfLD/h15pGLyMBA+JJhReMiK1Hqpu0QKvwNz pBOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P5QG2Zmn; 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 p14si7814545pfn.267.2019.04.20.04.10.17; Sat, 20 Apr 2019 04:10:17 -0700 (PDT) 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=P5QG2Zmn; 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 S1726267AbfDTLKQ (ORCPT + 1 other); Sat, 20 Apr 2019 07:10:16 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:32874 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726071AbfDTLKQ (ORCPT ); Sat, 20 Apr 2019 07:10:16 -0400 Received: by mail-lf1-f65.google.com with SMTP id j11so5713857lfm.0 for ; Sat, 20 Apr 2019 04:10:14 -0700 (PDT) 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=cuVq7cKNKVRapmWC1ujPQEg8efHGa8UKb8kOjcj/mbU=; b=P5QG2ZmnnirEZQovPOziaJG+vWJKJObRsD7jbCNY6KIyNWpfEgCz79rU9pbZh7wAEl j+IVp/XAFnfgZFUppD+kBhsxtbdkHj+qK6RhHKkSmznXEApMpkNaSXY2dm7RhT40XhDa uZNRUHxSmi97y8QhSzhHIRj5kJig8GJUJ8OruX0Zs9hKz8anDRCXr/OdFV2/fwyPk8sK 39cwj6oi0Kfpqav/M313zlDw+/zlAaGxU2mJZvylPERRQXNnZiHzPTB3jSi5jJJNswW6 tbJlWmQwWM5F2S/G5KFoT2ULMYQSa4rrxjDajxpE4cKh6KDXxiSwCYW6DJIfPkArdM/A HG1w== 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=cuVq7cKNKVRapmWC1ujPQEg8efHGa8UKb8kOjcj/mbU=; b=XoHrhkcDS7MbY0m4nUAbQz9vq9kFjzrtQ58AY1FL2mw1an8pdisRv0JkZopPcGbPyq Mp8c3ulyanQTGBPkWD0Oj7c+Y4nrIMIWUwnLPsCHCftKELVlzVUEoqz8bm2gu+aSXebq saBr2npGKkiv81ZG8hCOXLRqrFjc3eLp9vE8CbM3v+QVYrtSIDWGZRaV4Moe6iZyL/hQ fweMrenYJvWPLuNozXcx1PfL+xp0GKuAhK+VnBJXAIIawQjuAlSptEGrPOjvehvufiPy EtXbkhn92od07y3nlzD72yIK7xIcgONZZyTcGRumxI3oKEdROt1z9R5BBZLaVhwPxAPo u4zg== X-Gm-Message-State: APjAAAXHWPrT1a3SZW+vj1yVfxKPvFCKMwf5dqcO0zl7wi4cpSeGvIb/ Er9tyRsnUs0F+yGe7dq/4vjqeg== X-Received: by 2002:ac2:523a:: with SMTP id i26mr545045lfl.118.1555758613738; Sat, 20 Apr 2019 04:10:13 -0700 (PDT) Received: from localhost.localdomain (c-c5d3225c.014-348-6c756e10.bbcust.telenor.se. [92.34.211.197]) by smtp.gmail.com with ESMTPSA id r136sm1787888lff.65.2019.04.20.04.10.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Apr 2019 04:10:12 -0700 (PDT) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski , Linus Walleij , Lukas Wunner , Stefan Wahren , Martin Sperl , Chris Boot Subject: [PATCH] spi: bcm2835: Convert to use CS GPIO descriptors Date: Sat, 20 Apr 2019 13:08:09 +0200 Message-Id: <20190420110809.5325-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org This converts the BCM2835 SPI master driver to use GPIO descriptors for chip select handling. The BCM2835 driver was relying on the core to drive the CS high/low so very small changes were needed for this part. If it managed to request the CS from the device tree node, all is pretty straight forward. However for native GPIOs this driver has a quite unorthodox loopback to request some GPIOs from the SoC GPIO chip by looking it up from the device tree using gpiochip_find() and then offseting hard into its numberspace. This has been augmented a bit by using gpiochip_request_own_desc() but this code really needs to be verified. If "native CS" is actually an SoC GPIO, why is it even done this way? Should this GPIO not just be defined in the device tree like any other CS GPIO? I'm confused. Cc: Lukas Wunner Cc: Stefan Wahren Cc: Martin Sperl Cc: Chris Boot Signed-off-by: Linus Walleij --- ChangeLog RFT->v2: - Rebased on v5.1-rc1 I would very much appreciate if someone took this for a ride on top of linux-next (there are some fixes in the -rcs you need) and see if all still works as expected. --- drivers/spi/spi-bcm2835.c | 42 ++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) -- 2.20.1 diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index 35aebdfd3b4e..464cbfe70778 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -33,7 +33,8 @@ #include #include #include -#include +#include +#include /* FIXME: using chip internals */ #include #include @@ -881,12 +882,17 @@ static int bcm2835_spi_setup(struct spi_device *spi) { int err; struct gpio_chip *chip; + enum gpiod_flags flags; /* * sanity checking the native-chipselects */ if (spi->mode & SPI_NO_CS) return 0; - if (gpio_is_valid(spi->cs_gpio)) + /* + * The SPI core has successfully requested the CS GPIO line from the + * device tree, so we are done. + */ + if (spi->cs_gpiod) return 0; if (spi->chip_select > 1) { /* error in the case of native CS requested with CS > 1 @@ -897,7 +903,15 @@ static int bcm2835_spi_setup(struct spi_device *spi) "setup: only two native chip-selects are supported\n"); return -EINVAL; } - /* now translate native cs to GPIO */ + + /* + * Translate native CS to GPIO + * + * FIXME: poking around in the gpiolib internals like this is + * not very good practice. Find a way to locate the real problem + * and fix it. Why is the GPIO descriptor in spi->cs_gpiod + * sometimes not assigned correctly? Erroneous device trees? + */ /* get the gpio chip for the base */ chip = gpiochip_find("pinctrl-bcm2835", chip_match_name); @@ -905,21 +919,16 @@ static int bcm2835_spi_setup(struct spi_device *spi) return 0; /* and calculate the real CS */ - spi->cs_gpio = chip->base + 8 - spi->chip_select; + flags = (spi->mode & SPI_CS_HIGH) ? GPIOD_OUT_LOW : GPIOD_OUT_HIGH; + spi->cs_gpiod = gpiochip_request_own_desc(chip, 8 + spi->chip_select, + DRV_NAME, + flags); + if (IS_ERR(spi->cs_gpiod)) + return PTR_ERR(spi->cs_gpiod); /* and set up the "mode" and level */ - dev_info(&spi->dev, "setting up native-CS%i as GPIO %i\n", - spi->chip_select, spi->cs_gpio); - - /* set up GPIO as output and pull to the correct level */ - err = gpio_direction_output(spi->cs_gpio, - (spi->mode & SPI_CS_HIGH) ? 0 : 1); - if (err) { - dev_err(&spi->dev, - "could not set CS%i gpio %i as output: %i", - spi->chip_select, spi->cs_gpio, err); - return err; - } + dev_info(&spi->dev, "FIXME: setting up native-CS%i as GPIO\n", + spi->chip_select); return 0; } @@ -939,6 +948,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev) platform_set_drvdata(pdev, master); + master->use_gpio_descriptors = true; master->mode_bits = BCM2835_SPI_MODE_BITS; master->bits_per_word_mask = SPI_BPW_MASK(8); master->num_chipselect = 3;