Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1349783ybj; Tue, 5 May 2020 18:45:50 -0700 (PDT) X-Google-Smtp-Source: APiQypKCg8RZDlvNtb5a+DMhbCKoydGGmX+2OJzoM1oDRnJ/Tchil1mZeC/JMXpDUBXj+q8erZZm X-Received: by 2002:a17:906:16ca:: with SMTP id t10mr5510889ejd.122.1588729550090; Tue, 05 May 2020 18:45:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588729550; cv=none; d=google.com; s=arc-20160816; b=mHQRtzXO+cb5veDllvFoZ2EGFV/vDmtkurVSq/NcH3yfcMrC4coo+UuBfULex9gYG3 OoZUH8JFlNxqVM0lvJZFewGHZM9XJLE2H41/PxNbfi7VvKymjJ9aWKJX5F+hI/Qm6evg sK6noBLEfpCxHBBDFxVX5Dg1JGUVkauQ2PI1Ny73ZIQj4CNz1JSaVWejcH/d3VCdtoiw vIe/kRwEwMnDtZThDE5iX1yB8Miv+6LdvANZuPXIq1yZw1hB9iVoPChmSP9356K0kOAH VS+vJ/9p4ZLUQUoB4wvQ9rxkO4qCRc0x9kCIA550gJ8eeICoDDrNO8M+ysZ4i4k0qyEC /bHA== 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:dkim-signature; bh=6qof28feycOj7oXv4ybcTJHnjdqJ6zUx8IqfTWIbE1I=; b=efy5v69rq9KFPfmty4G5jGxRvEeZ2MczY7YI8dFJZYEPHX9QTBR4N+8jbFUM7p5+73 sAzt18zvXlLjXxJrUKy6/1al5gK/3CF7NIJJiagRnLLdGJCqL73DCAMSp2q6+ZxpJWo2 AFZQFVdwwyH73K7vbmJHPtp+u6yGbdFr6Xyfz5X+E1tKrB1VrJvu11/Ze9KOmCR1ITQc FZ93sZaIUEueFmyBUnoaeWcPpuBVFIgzVZ4WxxcFssD/zxVLQ5d4FhQgaKGIuWeIKUIC j7+Sw6u6tXZJvA4fu5XzFRrOt/V++LMdmhkdUYjoSb5PWbWRYxain7lAMB5Qpj/J7qN+ C8Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alistair23.me header.s=fm1 header.b=UmLgQNSZ; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=AyPqnU6V; 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 h2si182809edz.585.2020.05.05.18.45.27; Tue, 05 May 2020 18:45:50 -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=@alistair23.me header.s=fm1 header.b=UmLgQNSZ; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=AyPqnU6V; 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 S1729778AbgEFBlm (ORCPT + 99 others); Tue, 5 May 2020 21:41:42 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:48881 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729515AbgEFBlm (ORCPT ); Tue, 5 May 2020 21:41:42 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id DB70C5C0194; Tue, 5 May 2020 21:41:40 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 05 May 2020 21:41:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alistair23.me; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm1; bh=6qof28feycOj7oXv4ybcTJHnjd qJ6zUx8IqfTWIbE1I=; b=UmLgQNSZr83RxSjsk/oMMVG/Fv6CFzYFJdYaKQN47X Qd6kBINKPkMQWIWeEI9vlKC+59gIcOeTJPxn0gNfplW6B+ClsMSGXNnSDsNb9Zej SolI1ozO5NsjzsIEwI7QyDi1gOKUZ6C6tVDOiaHxr/AqTwVRi8UsDOfk2PtanBnq vHMtCRIFOTISHTZ1iQZA73N8ltjsuMj0A2JaHkbGhXwI3qd5IopC9vX3ULvBq8MR 9ZZUN+q+uoUyggGtgiquCi7YoVhMI3aBenOq/FYS72KzoxubMIk16R3uYXsv4mgk +YMG9p3i76Tf6hJVNM6RlmVvPG91Zd/RFaWZjtL/X8bg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=6qof28feycOj7oXv4 ybcTJHnjdqJ6zUx8IqfTWIbE1I=; b=AyPqnU6ViPiTRpOqgOcOE1RV0vSeFzoM9 jKdq1aIUyHJdIoA3GwkJjbGmc4zwXkajr+cJFhzmY8wbYn4FaONr2F6CphmULmby tYnwbwcY+UeBGZ0TcqrgngNVNe9rxqDJFwBtnu4pHYu4fPC2Iz1IvCufuWugOSya XR3+oHhMdGyySo4GDebg6VN4hnJWSRxkMhFJ2hNKDif3RnepE2uT/FwE0nVxGzGV XD3kaHZqdTuKwHITPDev5lGCDOQW11WRYXV6M7V3K2ziIuBmBW1EskclaaCnkwJw 6mR/l95uv/0AiYoGOlT1y6SbGOxnC39aIeaUi9KpB//cXXGWt0mNA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrjeejgdejiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffoggfgsedtkeertdertd dtnecuhfhrohhmpeetlhhishhtrghirhcuhfhrrghntghishcuoegrlhhishhtrghirhes rghlihhsthgrihhrvdefrdhmvgeqnecuggftrfgrthhtvghrnhepjeeliefhvdetgfdtte fhtdegffdtiefffeejiefffeevueeljeehjeevhfffueeknecukfhppeejfedrleefrdek gedrvddtkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpegrlhhishhtrghirhesrghlihhsthgrihhrvdefrdhmvg X-ME-Proxy: Received: from alistair-xps-14z.alistair23.me (c-73-93-84-208.hsd1.ca.comcast.net [73.93.84.208]) by mail.messagingengine.com (Postfix) with ESMTPA id 9D3D630660F2; Tue, 5 May 2020 21:41:38 -0400 (EDT) From: Alistair Francis To: broonie@kernel.org, linux-spi@vger.kernel.org Cc: mripard@kernel.org, wens@csie.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, alistair23@gmail.com, Alistair Francis Subject: [PATCH] spi: sun6i: Add support for GPIO chip select lines Date: Tue, 5 May 2020 18:41:35 -0700 Message-Id: <20200506014135.2941967-1-alistair@alistair23.me> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.26.2