Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1600265ybj; Wed, 6 May 2020 01:31:26 -0700 (PDT) X-Google-Smtp-Source: APiQypKQHTeBiv1ctpJcSP8Bdb7rUB4HRXjVUPniCc5KDpWh1R904O3HZ50LleWoiI007UIt3AfQ X-Received: by 2002:a17:906:496:: with SMTP id f22mr6191181eja.311.1588753886042; Wed, 06 May 2020 01:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588753886; cv=none; d=google.com; s=arc-20160816; b=PIv6k4xyGjlNXemrifPKhPLifNZlcpDy71+8kuQZopdJxfNg3Vd6VtEcNQ8UPVSuXO 6A9IupZbfJ7kWOAlrzyGuYtE+EpRbAlEE+vA6SUXEaaOqtZT400myMKzHXOj9RLV0/ht ldziS66ACx/xlOOMt3YqPiLIA9UUR8M69pWCOuUEz9JLX/9uSNpyMq8HZgNFMH4t1KQr GZJPR0O6qnlCIBYM5sx6Cg7h3K1YLkkug8UGLlIQ2zFlvB81iYqrDEgf8DUEX3Sn27Tm mPVhwdyYMrV80m0DFbyr7L7dT29w89v2ZCqOrl+/ftoHNRCd9YOm+/F7CxIGhJWvpchq zNPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=vCxRIS23FoOP0c2W/2eOvh5VSv4P5EkgKVxWMleJAFA=; b=hwBsOJycAOJ+1qppPjNoAryqPIcoqNa/UeVJyog2Alq8u1MzP5mVOYFrjIWm0VtlI1 MrwvMNHYBe5s//KKO8O15t+Da5hqgOgthF02tIybGmHcNB2yM91kR/15uuNAHyS3zDHQ pJ7LRy23K4vapXvXD0ZoDk/pCsYN19dJdhtDsOw/sQ9sKvUy8XWwSpiizKTetry1Kd2E TZz+RpL221eXZIaWrZmIwHnrHIANTB7u7hxLqpC8HXxpiRwNGL0cZI6798mGBy7ypkRf /v+wAvNJ/g1Y5Lq08xJHnZRvtu7dP+0hHs30TIJfiUGdZd4513gUk79BhuSz98yliLKS IuIQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f23si708377ejf.414.2020.05.06.01.31.02; Wed, 06 May 2020 01:31:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728728AbgEFI1g (ORCPT + 99 others); Wed, 6 May 2020 04:27:36 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:40656 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728436AbgEFI1f (ORCPT ); Wed, 6 May 2020 04:27:35 -0400 Received: by mail-ot1-f67.google.com with SMTP id i27so691825ota.7; Wed, 06 May 2020 01:27:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vCxRIS23FoOP0c2W/2eOvh5VSv4P5EkgKVxWMleJAFA=; b=XtK74gnw9shrUVLTG2rtJOuI+clhWnXbq2X3iTJK8lS+YQ4hwR5pvrvizAgJHmPzhL uRpclv1Lg/XZosFN4UpwYY0AcBwCFZ0MyKz6t7eQycyKjtSlRtHe5AJ+UK48+phQFTDA oP9Hi8tTvOxRYpPFdfe4Fe6LtpTXfGC4YFzJYCQFBB679MigjNgrox4txLAkG/JOHsw5 KDBGxZhJn5h6Y/qWp/9V8Agt6A/pUU/Fex38qFVO+cu6RPiv4zo+JfGcXLZ620xQI1by piyMul+GdU2BTXg5rxZqB05f91hSzhiwY8gAadO0eFHDKp6ljOPpwbbbOcRYiVHnL38I wsyQ== X-Gm-Message-State: AGi0PuZsluczeOTDx2xRX52PT05FK1HROB1Lp+ogQu2BOyWKVYyxi7gf kxkYOdxQk3/S0DCBwO0sh5YDjh707R/ebiguwd8= X-Received: by 2002:a9d:63da:: with SMTP id e26mr44857otl.107.1588753654870; Wed, 06 May 2020 01:27:34 -0700 (PDT) MIME-Version: 1.0 References: <20200506014135.2941967-1-alistair@alistair23.me> In-Reply-To: <20200506014135.2941967-1-alistair@alistair23.me> From: Geert Uytterhoeven Date: Wed, 6 May 2020 10:27:23 +0200 Message-ID: Subject: Re: [PATCH] spi: sun6i: Add support for GPIO chip select lines To: Alistair Francis Cc: Mark Brown , linux-spi , Linux Kernel Mailing List , Maxime Ripard , Chen-Yu Tsai , alistair23@gmail.com, Linux ARM Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alistair, On Wed, May 6, 2020 at 3:41 AM Alistair Francis wrote: > Add a setup function that can be used to support using generic GPIO > lines for the chip select. > > Signed-off-by: Alistair Francis > --- > drivers/spi/spi-sun6i.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c > index ec7967be9e2f..fd4e19434942 100644 > --- a/drivers/spi/spi-sun6i.c > +++ b/drivers/spi/spi-sun6i.c > @@ -10,6 +10,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -171,6 +172,31 @@ static inline void sun6i_spi_fill_fifo(struct sun6i_spi *sspi, int len) > } > } > > +static int sun6i_spi_setup(struct spi_device *spi) > +{ > + int ret; > + > + /* sanity check for native cs */ > + if (spi->mode & SPI_NO_CS) > + return 0; > + if (gpio_is_valid(spi->cs_gpio)) { > + /* with gpio-cs set the GPIO to the correct level > + * and as output (in case the dt has the gpio not configured > + * as output but native cs) > + */ > + ret = gpio_direction_output(spi->cs_gpio, > + (spi->mode & SPI_CS_HIGH) ? 0 : 1); > + if (ret) > + dev_err(&spi->dev, > + "could not set gpio %i as output: %i\n", > + spi->cs_gpio, ret); > + > + return ret; > + } > + > + return 0; > +} > + > static void sun6i_spi_set_cs(struct spi_device *spi, bool enable) > { > struct sun6i_spi *sspi = spi_master_get_devdata(spi->master); > @@ -470,6 +496,7 @@ static int sun6i_spi_probe(struct platform_device *pdev) > > master->max_speed_hz = 100 * 1000 * 1000; > master->min_speed_hz = 3 * 1000; > + master->setup = sun6i_spi_setup; > master->set_cs = sun6i_spi_set_cs; > master->transfer_one = sun6i_spi_transfer_one; > master->num_chipselect = 4; Can't you just set master->use_gpio_descriptors = true; instead and be done with it? Then drivers/spi/spi.c:spi_get_gpio_descs() will configure the GPIO line as output for you. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds