From patchwork Mon Jan 7 15:51:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 154893 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3630521ljp; Mon, 7 Jan 2019 07:56:49 -0800 (PST) X-Google-Smtp-Source: ALg8bN6Ucc3bFNxKOyNdj3IhJoJpblHTUj5QcNe9CKBg8VEUMfdB05FcPQItI4jgsJS3Fpi4EAqU X-Received: by 2002:a63:e21:: with SMTP id d33mr11369496pgl.272.1546876609639; Mon, 07 Jan 2019 07:56:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546876609; cv=none; d=google.com; s=arc-20160816; b=jDJChNoEa2S/Vlw5ZOjTPByneCNgPe/NLYijF14y0wLqouMoH0LYEVV/IPaxtcwfGv M44BuX4Z/zPU+UxkVftmZ9ftccCuCPx6vlOpXjO6CsUPu/hR/de971GsGRSggyXXvWqL FSTw/xJEIuHmPi9cqS2ALneTS2gPobces5Dq7gUOH6VEAwkw66eKOfljBqfXrZo1yWOC tAfg+xHB6hfWQVnJUCW1W4E7AV8SfqmoUT19pwH3p7a3cHqa6xvnz7C8PGKN/e7lD6Ia llgmfSjwyI91DlqdKKFpeSLSPbu5k3k3zXTo/g7TZtOOqT8SDHp4fMGijH9npXHa/r6u 3BcQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dyc209MkU26DsHhcTstxC4XkO3ZgBkaOKbCSbkZ/s8Y=; b=JXSEiJ2BQBSljqa0RhTHU/f+ZhA/mKfjJGfI+eDRa6yV+kdSYE7sYm0uzJZaOfX56o iO27iQX+JoKgRmEtw6Khlxj9Ygrj76WEjl7Ypm2eiExHsJiRD7tmAaSAjobk5GGAJlRp B+o8aZVtIWgP5V/2U1UqhcI71jsCyqR9re23QnBXu7XOwYeLC3t9GZd0vVI8wMVXAd+S kTL9SzAezH2O35ebRAVY1o2MgnpFJJkenkcRc+MOl7Jyu0Shx7tIM73nETQ8u9Oj4FQT /piw8JAycesVhB4cIQA9NEENDJfo0JLA2JUVRCf0NO9CEu6TajYQyqVeI4fvHdkBQGXw zntQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FhXDTNWD; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-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 l7si3021110pgk.169.2019.01.07.07.56.49; Mon, 07 Jan 2019 07:56:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-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=FhXDTNWD; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-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 S1727401AbfAGP4s (ORCPT + 5 others); Mon, 7 Jan 2019 10:56:48 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:39990 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbfAGP4s (ORCPT ); Mon, 7 Jan 2019 10:56:48 -0500 Received: by mail-lj1-f195.google.com with SMTP id n18-v6so750836lji.7 for ; Mon, 07 Jan 2019 07:56:46 -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=dyc209MkU26DsHhcTstxC4XkO3ZgBkaOKbCSbkZ/s8Y=; b=FhXDTNWDW2kYR1E0Ka0ictK08cm07X1LltpJXFWMPJD7eoPuDMyzaqbdRn807FwFZr vu//JB4C3xrxT7Xfj9tSxy7jL10GWw1r6K1z4I+JHqxkdoevhoiXsGlA4K5FxnYglK2y Suw78IhkvW38UeAyxcHWXFRoL/4AoCofL09m4= 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=dyc209MkU26DsHhcTstxC4XkO3ZgBkaOKbCSbkZ/s8Y=; b=OV1jO5BpvdMKpjlSXoYpiihHOugVG99tHdS29mSn/B5jpNSWDb2yJtsfvFQTO/nAbU oSpSd2L90RzTXvOgYbKVi4vuRX7Kdm8qX4hNvZj03E/ats+2umYO9Le3b17Sk3nzPBlQ vXFLIXOq2ekWtViOgiAYd16jRjqqZrsroec0BtkCtjbrr9F+IKbM/MNmM27iUO/oh5tz XiucGEF1TsotBXgtWPVpoiMfaQ6zKxJJuBa+LYmt+YfbFDxwHMwFx44cYioD4XquwGnj WS1ovLAr1SJ9JVL1Ihm4nlb9tQf5nFhnkGZh8I/t9RLPAO2PGBD27nfudeM9SoA86RwJ 811g== X-Gm-Message-State: AJcUukc2ouVCPKheZNlFGN7KRZMDa4US3yEF9KSggT+rFyOeaz+yaO+D wHWe/yhOA24nj0wv4wa8qmL/EQ== X-Received: by 2002:a2e:9a16:: with SMTP id o22-v6mr34479934lji.112.1546876605297; Mon, 07 Jan 2019 07:56:45 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id t22sm13269164lfb.0.2019.01.07.07.56.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Jan 2019 07:56:44 -0800 (PST) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski , linuxarm@huawei.com, Linus Walleij , Wei Yongjun , Janek Kotas Subject: [PATCH 4/7 v2] spi: cadence: Convert to use CS GPIO descriptors Date: Mon, 7 Jan 2019 16:51:53 +0100 Message-Id: <20190107155156.3738-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190107155156.3738-1-linus.walleij@linaro.org> References: <20190107155156.3738-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This converts the Cadence SPI master driver to use GPIO descriptors for chip select handling. The Cadence driver was allocating a state container just to hold the requested GPIO line and contained lots of polarity inversion code. As this is all handled by gpiolib and a simple devm_* request in the core, and as the driver is fully device tree only, most of this code chunk goes away in favour of central handling. The setup/cleanup callbacks goes away. This driver does NOT drive the CS line by setting the value of the GPIO so it relies on the SPI core to do this, which should work just fine with the descriptors. Cc: Wei Yongjun Cc: Janek Kotas Cc: Linuxarm Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebase on v5.0-rc1 --- drivers/spi/spi-cadence.c | 67 ++------------------------------------- 1 file changed, 2 insertions(+), 65 deletions(-) -- 2.19.2 diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c index 7c88f74f7f47..e332d173dbf9 100644 --- a/drivers/spi/spi-cadence.c +++ b/drivers/spi/spi-cadence.c @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include #include @@ -128,10 +128,6 @@ struct cdns_spi { u32 is_decoded_cs; }; -struct cdns_spi_device_data { - bool gpio_requested; -}; - /* Macros for the SPI controller read/write */ static inline u32 cdns_spi_read(struct cdns_spi *xspi, u32 offset) { @@ -469,64 +465,6 @@ static int cdns_unprepare_transfer_hardware(struct spi_master *master) return 0; } -static int cdns_spi_setup(struct spi_device *spi) -{ - - int ret = -EINVAL; - struct cdns_spi_device_data *cdns_spi_data = spi_get_ctldata(spi); - - /* this is a pin managed by the controller, leave it alone */ - if (spi->cs_gpio == -ENOENT) - return 0; - - /* this seems to be the first time we're here */ - if (!cdns_spi_data) { - cdns_spi_data = kzalloc(sizeof(*cdns_spi_data), GFP_KERNEL); - if (!cdns_spi_data) - return -ENOMEM; - cdns_spi_data->gpio_requested = false; - spi_set_ctldata(spi, cdns_spi_data); - } - - /* if we haven't done so, grab the gpio */ - if (!cdns_spi_data->gpio_requested && gpio_is_valid(spi->cs_gpio)) { - ret = gpio_request_one(spi->cs_gpio, - (spi->mode & SPI_CS_HIGH) ? - GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH, - dev_name(&spi->dev)); - if (ret) - dev_err(&spi->dev, "can't request chipselect gpio %d\n", - spi->cs_gpio); - else - cdns_spi_data->gpio_requested = true; - } else { - if (gpio_is_valid(spi->cs_gpio)) { - int mode = ((spi->mode & SPI_CS_HIGH) ? - GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH); - - ret = gpio_direction_output(spi->cs_gpio, mode); - if (ret) - dev_err(&spi->dev, "chipselect gpio %d setup failed (%d)\n", - spi->cs_gpio, ret); - } - } - - return ret; -} - -static void cdns_spi_cleanup(struct spi_device *spi) -{ - struct cdns_spi_device_data *cdns_spi_data = spi_get_ctldata(spi); - - if (cdns_spi_data) { - if (cdns_spi_data->gpio_requested) - gpio_free(spi->cs_gpio); - kfree(cdns_spi_data); - spi_set_ctldata(spi, NULL); - } - -} - /** * cdns_spi_probe - Probe method for the SPI driver * @pdev: Pointer to the platform_device structure @@ -621,13 +559,12 @@ static int cdns_spi_probe(struct platform_device *pdev) goto clk_dis_all; } + master->use_gpio_descriptors = true; master->prepare_transfer_hardware = cdns_prepare_transfer_hardware; master->prepare_message = cdns_prepare_message; master->transfer_one = cdns_transfer_one; master->unprepare_transfer_hardware = cdns_unprepare_transfer_hardware; master->set_cs = cdns_spi_chipselect; - master->setup = cdns_spi_setup; - master->cleanup = cdns_spi_cleanup; master->auto_runtime_pm = true; master->mode_bits = SPI_CPOL | SPI_CPHA;