From patchwork Wed Nov 27 13:54:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11264077 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90A1214DB for ; Wed, 27 Nov 2019 13:54:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6BDDC20678 for ; Wed, 27 Nov 2019 13:54:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hdOIu4tv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726603AbfK0NyW (ORCPT ); Wed, 27 Nov 2019 08:54:22 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:40519 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726320AbfK0NyV (ORCPT ); Wed, 27 Nov 2019 08:54:21 -0500 Received: by mail-lf1-f68.google.com with SMTP id y5so4525443lfy.7 for ; Wed, 27 Nov 2019 05:54:20 -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=44702Gw3ZAM2iREdSIkTlwApDDVA5N67h6DOU9Ptf4I=; b=hdOIu4tv6tllw/KWE2yRviLR61rwCfpLpUHi5G9WBuFmm9quzNH+avKQZC7QukVlSd S8Xn9EU5RmJKJTad/mZc3A37j8SMokiwphzSGnB8JmsTgxE5TqbftomZlNUOO1AQhpnm fmtYyWA5ZTxjh0rEymmo3KtvVnU7Rt19yI5/zrXUSAASNS1x0V3b6aPozhO7zrvilji2 czH+s90iXRqYlerl5GIt2tLsr1DYsKnd6qFSjyHH3ClCANYXXRrIMZ6MyvDGpKoJ76qL 37xS8mnHU9Z+DQdw7ZqJb7SzaeQkHnyCi52rQ9uUlzj1L7i0ifIY2ypUUA2Y6Kn/73xc hMJQ== 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=44702Gw3ZAM2iREdSIkTlwApDDVA5N67h6DOU9Ptf4I=; b=BWFnm6I6c2ZmhvGk9yqVKhPny1CeHIphJMDE2TB/HOVFUWTY/nEI00GjG2N6Gl3dOA Sw+Pjtj8FJqSMS57SSYh4TkV77TroaqjR0L/88D2fmLC6uWWkyse9DAjZAaiVa/hWIAC t17Vu+yXoLLv57IZCrPfB/AVhHZ06DgAotPH4Z7kJtPmx3lIf+9guinr0fgDcL/svkUC 6lMEfpfOKcCk9ia7TPCnmHPkNrjkLJxnpI1kU3y4gU7CiL7m0e7hhhf3qqNk/73XWDOn bX5oEbXGg9L92ChY0a9UbU1r7MVfdMHc65pUidZSp+QFpakK2rxz1bT6VGdYryR1acIN Ib7Q== X-Gm-Message-State: APjAAAWDpoSGaK3eypm8ziaMFR7IdRj+aol8eE7jllLtd77X06skg2yU zx0KXoqBL9u+WHY5qyaLv1jTQw== X-Google-Smtp-Source: APXvYqzdBzf7ut1/0PTCCMX+tHlGncPt21Pjc/XWXrRIJyp2zmA3XK4MzfHdrJ1WmguGg4CFBTfxtQ== X-Received: by 2002:ac2:455c:: with SMTP id j28mr25414287lfm.184.1574862859524; Wed, 27 Nov 2019 05:54:19 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id j18sm2343561lfh.6.2019.11.27.05.54.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 05:54:17 -0800 (PST) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org Cc: Linus Walleij , Christophe Leroy Subject: [PATCH 1/3 v2] spi: fsl: Fix GPIO descriptor support Date: Wed, 27 Nov 2019 14:54:08 +0100 Message-Id: <20191127135410.156430-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 This makes the driver actually support looking up GPIO descriptor. A coding mistake in the initial descriptor support patch was that it was failing to turn on the very feature it was implementing. Mea culpa. Cc: Christophe Leroy Reported-by: Christophe Leroy Fixes: 0f0581b24bd0 ("spi: fsl: Convert to use CS GPIO descriptors") Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - New patch fixing this specific problem. --- drivers/spi/spi-fsl-spi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 114801a32371..c87e9c4506c2 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -611,6 +611,7 @@ static struct spi_master * fsl_spi_probe(struct device *dev, master->setup = fsl_spi_setup; master->cleanup = fsl_spi_cleanup; master->transfer_one_message = fsl_spi_do_one_msg; + master->use_gpio_descriptors = true; mpc8xxx_spi = spi_master_get_devdata(master); mpc8xxx_spi->max_bits_per_word = 32; From patchwork Wed Nov 27 13:54: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: 11264079 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20BDB1390 for ; Wed, 27 Nov 2019 13:54:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 00876206F0 for ; Wed, 27 Nov 2019 13:54:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ZCGKYWsi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727073AbfK0NyZ (ORCPT ); Wed, 27 Nov 2019 08:54:25 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:35663 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726947AbfK0NyZ (ORCPT ); Wed, 27 Nov 2019 08:54:25 -0500 Received: by mail-lj1-f193.google.com with SMTP id j6so15571638lja.2 for ; Wed, 27 Nov 2019 05:54:23 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ze5hvXCplepJyWjwgkySScV2FO5TtWlZUcDiUJMYMsA=; b=ZCGKYWsiinnFBhR/ovPRoqpJ/8qXeVhMLeaVJqOoLLtY27y18Jgl9k7T/cKKtZMB4a VrbOK7iw0tueIbg5MRQAWVKXQEHoc/CofCoQmbIRpV9+oI09ZpN/zddGl/kCYDF4R7hG JxYdioLqxcYKl2UxjQrDA41oSTHVobiWPAHokFH3/ARoiRk6fdfsO0mcT87r0dVKcKyT r6S03KPMvdgLhfFOC3Dp66wvZJOeKhsNycoN6YEpKMxKKDqnoe8Hw5uS81bTr1hhN6SH hSpvUqo6o0aWplpDR2yzWKEQQkigJUXULDvnl2YxMhxF6nslImbWIawkYG4bL2snPPod ql9A== 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:mime-version:content-transfer-encoding; bh=Ze5hvXCplepJyWjwgkySScV2FO5TtWlZUcDiUJMYMsA=; b=UEV7AdppGJOueGJkxvbQmg4yYYDkWOCBVxEcb79BqUDLpt6xnm/at9zeyj2dJkTwI3 F3QWneCNOnDKfl2g/cJArAXZ1MGEL0vpVwAD0T5xzEvcGdjEWqHw1iOP1NYux0MMq5De Kyy1i/BaqDPLhh6HBo9PYE5t02y/+wBlAioTjFe9DffAcxyZMl8xW+XI3ZrK5B8j3T4d YSQIUsIPeGOCFbMVS+ARVj7VGZwG1E/NXhjE6Y9ffa2mYxgswzE3WOfKtxrz8jmhGHXG WFkRSYeaTM7u3EuyF7PYjMV3JQEwi98WGOTnEf2enRvAdc1gImMofaAZHvwTK0Xp7J0U ptag== X-Gm-Message-State: APjAAAVoIB4/ITfcI3dIHhu9IXz0JLECFpPZ4j0zDXP0DhzPjch0RZ4Y q3L65K8Lda+uXcosLsVsG98C4w== X-Google-Smtp-Source: APXvYqy5G9Qe61FwrBDY81vBK9yvLEcm322VcPBc8TfK5f0dS83aglr8v/6o8ZgLLooHFAe6c2T7BQ== X-Received: by 2002:a2e:2201:: with SMTP id i1mr17841502lji.110.1574862862903; Wed, 27 Nov 2019 05:54:22 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id j18sm2343561lfh.6.2019.11.27.05.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 05:54:21 -0800 (PST) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org Cc: Linus Walleij , Christophe Leroy Subject: [PATCH 2/3 v2] gpio: Handle counting of Freescale chipselects Date: Wed, 27 Nov 2019 14:54:09 +0100 Message-Id: <20191127135410.156430-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191127135410.156430-1-linus.walleij@linaro.org> References: <20191127135410.156430-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org We have a special quirk to handle the Freescale nonstandard SPI chipselect GPIOs in the gpiolib-of.c file, but it currently only handles the case where the GPIOs are actually requested (gpiod_*get()). We also need to handle that the SPI core attempts to count the GPIOs before use, and that needs a similar quirk in the OF part of the library. Cc: Christophe Leroy Reported-by: Christophe Leroy Fixes: 0f0581b24bd0 ("spi: fsl: Convert to use CS GPIO descriptors") Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Hardcode the quirk to look for "gpios" as this is all we support and else the call would just recurse back and fail again. - Provide a proper NULL check so we don't upset strcmp(). Mark: I change my mind, better to keep the patches together, once Christophe has it working with my patch stack let's just merge all of it. --- drivers/gpio/gpiolib-of.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 80ea49f570f4..ae8b296160bf 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -23,6 +23,29 @@ #include "gpiolib.h" #include "gpiolib-of.h" +/** + * of_gpio_spi_cs_get_count() - special GPIO counting for SPI + * Some elder GPIO controllers need special quirks. Currently we handle + * the Freescale GPIO controller with bindings that doesn't use the + * established "cs-gpios" for chip selects but instead rely on + * "gpios" for the chip select lines. If we detect this, we redirect + * the counting of "cs-gpios" to count "gpios" transparent to the + * driver. + */ +int of_gpio_spi_cs_get_count(struct device *dev, const char *con_id) +{ + struct device_node *np = dev->of_node; + + if (!IS_ENABLED(CONFIG_SPI_MASTER)) + return 0; + if (!con_id || strcmp(con_id, "cs")) + return 0; + if (!of_device_is_compatible(np, "fsl,spi") && + !of_device_is_compatible(np, "aeroflexgaisler,spictrl")) + return 0; + return of_gpio_get_count(dev, "gpios"); +} + /* * This is used by external users of of_gpio_count() from * @@ -35,6 +58,10 @@ int of_gpio_get_count(struct device *dev, const char *con_id) char propname[32]; unsigned int i; + ret = of_gpio_spi_cs_get_count(dev, con_id); + if (ret > 0) + return ret; + for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) { if (con_id) snprintf(propname, sizeof(propname), "%s-%s", From patchwork Wed Nov 27 13:54:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11264081 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B7F9914DB for ; Wed, 27 Nov 2019 13:54:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 98AF72075C for ; Wed, 27 Nov 2019 13:54:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fj1gtrBw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726947AbfK0Ny2 (ORCPT ); Wed, 27 Nov 2019 08:54:28 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:46239 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbfK0Ny2 (ORCPT ); Wed, 27 Nov 2019 08:54:28 -0500 Received: by mail-lf1-f68.google.com with SMTP id a17so17206687lfi.13 for ; Wed, 27 Nov 2019 05:54:27 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=OmjuVawMhvfVD9JOPWyCm3fewK5I8v6LD5uaG6j2MhM=; b=fj1gtrBw/+KHGWourkrK2BexXQtWwQO6TEvDijehjCAUBZRzPtpWiONgne8uaVlPNL +sxrWRQobCmSBcRcYIuSUhsPuyFDSKCDgWZDMO6Juu673NcXquk/IfarAB0H6T3JBi1V o7aClwqZiiy35WtXtwtMJXN58kWCKOnZJRZXLB04DXh2zV9ToYPpZBJtabcDcgcX4t12 6fzXFFlHiLx6fZqRQ51sNIdVrWoIZaupC2pkFIvPwxmIJ0onVlB60MbaUyiO5XzinOoE d0PE+OlOBw99h8SQDYG5HkyhnRWu3YoDX/Q8rW20NRuJHb+SdoNNkV2A0HqIxJMan6jM IBng== 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:mime-version:content-transfer-encoding; bh=OmjuVawMhvfVD9JOPWyCm3fewK5I8v6LD5uaG6j2MhM=; b=LGytNFo7yZuuyANCwmLPQssbjLdH5u5lFkrpdfu3xTKnxbTgb1X2Xp3bekSZ6VKEsO aUaaSE4ornaBOtBgz0VJAuMarTeAcJsB0n7lSqujuZOyT8PdQt9O6l0sQi5NDPRcS/Oq QAyoD0Sd+mlmfeI2+jzSaSYTsBqRm0lR70XcuAN+wz4xZytF/6VwGvEG0O4cSStb57tT f7VWmSJYozmm8SUyPQrFpnL+AJX3B6S2PcznBHjs3h2eSHdDAZKynj3YFZ3RtYx/qUcz mHIgTzx0yB3bbrsmemJMabMKefD2H2GGpBEFc3Svav0DcPIVRD/gXYD1MY5aVScY6pPW 6+KA== X-Gm-Message-State: APjAAAVc3hrJBGBgHKb7HIlSZUxm3yz4guoOU/pvMBG0Yd0bFQSAiDza IvSRNhhblVNrumLAGGSZVUUVlQ== X-Google-Smtp-Source: APXvYqwJ1jbbJMIu5K7QbN703ikVZ96WfMsH9zjZHYd3+3Sd5a69DUJH+JIdG0d7HJdwwyOnbsvtFg== X-Received: by 2002:ac2:5c09:: with SMTP id r9mr26635541lfp.136.1574862866457; Wed, 27 Nov 2019 05:54:26 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id j18sm2343561lfh.6.2019.11.27.05.54.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 05:54:24 -0800 (PST) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org Cc: Linus Walleij , Christophe Leroy Subject: [PATCH 3/3 v2] spi: fsl: Handle the single hardwired chipselect case Date: Wed, 27 Nov 2019 14:54:10 +0100 Message-Id: <20191127135410.156430-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191127135410.156430-1-linus.walleij@linaro.org> References: <20191127135410.156430-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org The Freescale MPC8xxx had a special quirk for handling a single hardwired chipselect, the case when we're using neither GPIO nor native chip select: when inspecting the device tree and finding zero "cs-gpios" on the device node the code would assume we have a single hardwired chipselect that leaves the device always selected. This quirk is not handled by the new core code, so we need to check the "cs-gpios" explicitly in the driver and set pdata->max_chipselect = 1 which will later fall through to the SPI master ->num_chipselect. Make sure not to assign the chip select handler in this case: there is no handling needed since the chip is always selected, and this is what the old code did as well. Cc: Christophe Leroy Reported-by: Christophe Leroy Fixes: 0f0581b24bd0 ("spi: fsl: Convert to use CS GPIO descriptors") Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Reordered patches. - Expanded comment a bit. --- drivers/spi/spi-fsl-spi.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index c87e9c4506c2..4b70887cf443 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -728,8 +728,18 @@ static int of_fsl_spi_probe(struct platform_device *ofdev) } } #endif - - pdata->cs_control = fsl_spi_cs_control; + /* + * Handle the case where we have one hardwired (always selected) + * device on the first "chipselect". Else we let the core code + * handle any GPIOs or native chip selects and assign the + * appropriate callback for dealing with the CS lines. This isn't + * supported on the GRLIB variant. + */ + ret = gpiod_count(dev, "cs"); + if (ret <= 0) + pdata->max_chipselect = 1; + else + pdata->cs_control = fsl_spi_cs_control; } ret = of_address_to_resource(np, 0, &mem);