From patchwork Wed Apr 3 04:01:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10882677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E3C413B5 for ; Wed, 3 Apr 2019 04:01:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB27728989 for ; Wed, 3 Apr 2019 04:01:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF7C8289A2; Wed, 3 Apr 2019 04:01:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96FEE28989 for ; Wed, 3 Apr 2019 04:01:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725879AbfDCEBx (ORCPT ); Wed, 3 Apr 2019 00:01:53 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38237 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725936AbfDCEBw (ORCPT ); Wed, 3 Apr 2019 00:01:52 -0400 Received: by mail-pg1-f194.google.com with SMTP id j26so7609521pgl.5; Tue, 02 Apr 2019 21:01:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ktalrU7lzEY152yeF8ZuBQGbifejPdnTZhkabhS1hK4=; b=t9KUxFX0gu4WSgsOITBpSRXx2mZvjAXkPDLjwtp3bh7igjgCsK4jWa/YYyP4GPYliR 3qSce8Em6Rma/t1/80OQH+tqAMjsBav6eHHn0KOK2Ge6ZJsSDjRogQl2X6KDrDtgsLTD XuVf8wLfWPzkBaPX3ANZ162rs3txZI7ZGjlLgMff9RkNp0FpZ/yD4rNnOaWfZe9EHWFJ 5jtmdcJF5Z71FnR7Hiz0ZP64cyx36TDPCHUdT9I+h27z1sCzoQPacAZG6NE333sYjWTi 8SxRfHqoawoAXkO1c1PCh7tqov274XKELvrR49QmGOBqBr03IZ1b9Hc632j9bhk2WvRH 7XLQ== 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=ktalrU7lzEY152yeF8ZuBQGbifejPdnTZhkabhS1hK4=; b=STZ6O8CE88w/4imD6rfEab5J8yKCir0E9YfhxDF/Fl/nQoM0Fbw8z/7DTMy2pbR+3/ 8iIQv0iqfuNYWv66m52isdWm41rOsXBjUb/VPqiDpZFBSJzeBbcJKFJUQ6DboJgE+eXB Y63en5evLOdanIcZM5pXdrQtSxCXPGpuwz8/LIGPfZufw/XZQhXVKfnZIHIyVMaNZkFZ MDEj5nyElSGoaxe7XVV/4cqamenYgz9PWNviPk9DjJQaHUI8kTqbVqxvXhZ4wHErB8zw 6FQK54RmEULslObojGkVGDy97mp+Qgz5gtvFPJDMkLamoHS+cMgLFdhDAITuF6CfQ3ZT vAvQ== X-Gm-Message-State: APjAAAWLB4zCaOK3+fnmZQlIP00GtZJ2baWnnYQCFFk+5G51vCiH6g7s uao6J3uDti4wZsPV/9epeaol1LZ7 X-Google-Smtp-Source: APXvYqwC39yYkO3uLgjz1mDhkVoRIUCGwX+dkYpHqzFoVEsB0FkIRIlQF/mhfNwxRJzQKPCKqWSllQ== X-Received: by 2002:aa7:8ac8:: with SMTP id b8mr10430910pfd.234.1554264111336; Tue, 02 Apr 2019 21:01:51 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id k14sm16278064pfb.125.2019.04.02.21.01.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 21:01:50 -0700 (PDT) From: Andrey Smirnov To: linux-spi@vger.kernel.org Cc: Andrey Smirnov , Mark Brown , Chris Healy , linux-kernel@vger.kernel.org Subject: [PATCH 01/12] spi: gpio: Drop unused spi_to_pdata() Date: Tue, 2 Apr 2019 21:01:22 -0700 Message-Id: <20190403040133.1459-2-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403040133.1459-1-andrew.smirnov@gmail.com> References: <20190403040133.1459-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Spi_to_pdata() is not used anywhere in the code. Drop it. Signed-off-by: Andrey Smirnov Cc: Mark Brown Cc: Chris Healy Cc: linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi-gpio.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 53b35c56a557..675fd65ebf1d 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -96,12 +96,6 @@ spi_to_spi_gpio(const struct spi_device *spi) return spi_gpio; } -static inline struct spi_gpio_platform_data *__pure -spi_to_pdata(const struct spi_device *spi) -{ - return &spi_to_spi_gpio(spi)->pdata; -} - /* These helpers are in turn called by the bitbang inlines */ static inline void setsck(const struct spi_device *spi, int is_on) { From patchwork Wed Apr 3 04:01:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10882699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D32D1800 for ; Wed, 3 Apr 2019 04:02:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 173D628989 for ; Wed, 3 Apr 2019 04:02:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B7A0289B5; Wed, 3 Apr 2019 04:02:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A92DD289B9 for ; Wed, 3 Apr 2019 04:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726411AbfDCEBy (ORCPT ); Wed, 3 Apr 2019 00:01:54 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:45032 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726183AbfDCEBy (ORCPT ); Wed, 3 Apr 2019 00:01:54 -0400 Received: by mail-pf1-f195.google.com with SMTP id y13so7441246pfm.11; Tue, 02 Apr 2019 21:01:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VXdsa+2KWn8DAZgbfHHYyO+0se1bIoGL2CFNu28TrmY=; b=a7j6MPR7XLKdGlqUQuEnwGPzcOTUBmf9eLl0p5ceJwDl6DF/dLwa0iON/Wo3bHD8IJ pt/YCBBNjrtSySM76empw64qwzk8JBfOryyse3zj5mO2t7Vhrf4laSF6EOKU3UhLGLUY o6Pzb9TqXD5Plj9H25j3UDQmVopFjcdB2UU7An7VJtsvsNIG7FGEveIG3uSv79eYmZYi q0WPUq3MyW3N271Rs5erfJTnDhMslZTN7DrRkizvY4C5B2fMbSxsOzyill+hGRUgXni5 aqzxeDSPk038NcvYNYIJsB+78UyRXFC7/g4UEckMgzjWLKJPczhUnR7BgSntSM2GvKFT slww== 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=VXdsa+2KWn8DAZgbfHHYyO+0se1bIoGL2CFNu28TrmY=; b=auaUOU/PsaBKnXxToe26xw3WfvdoUBuEzq4r7kFR9RKucC9rDk3dvjGH9TUIIibHTn 4Da4gr4Ns3HypZ8HaQIaUd3zCGU0lAx1lSt9AD95JdRg+eBHIipDZHxHNybvMaKd/1r2 j5vbvqhtEA6PFbwo9VQUCcU4jGwM9yIXfBkQH83GmO0kt13M3/FCZCE9cbKIH03P6A7s J2I4e9pnLv2dMeJ8ILzAd4DZ8Psl16CivZVciBxAwpyDcuJQFd7zEXAESaOYAnykYELr bR6dXdOaexUTE79OD8Lszo4N7q8RHdZXepciNgqXZmJrlTRU4vz6DQl0g9MarBN+SzjV GJ7A== X-Gm-Message-State: APjAAAWNLHo7IGE9/7b88+udivnBFd+29lOGO5F8/LG+7ZUtuzCxPM+J B/9FkNYwwvMT+3fA2Sd0404S6z7n X-Google-Smtp-Source: APXvYqx/JygKJndt7MjAfGuoPWrbcrV+adfQo/TrlVGGlJvLtg1o+1mtz7iqwqukMbay6Mdy+GOSBA== X-Received: by 2002:a63:5e43:: with SMTP id s64mr9729024pgb.15.1554264112696; Tue, 02 Apr 2019 21:01:52 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id k14sm16278064pfb.125.2019.04.02.21.01.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 21:01:51 -0700 (PDT) From: Andrey Smirnov To: linux-spi@vger.kernel.org Cc: Andrey Smirnov , Mark Brown , Chris Healy , linux-kernel@vger.kernel.org Subject: [PATCH 02/12] spi: gpio: Add local struct device pointer in spi_gpio_probe() Date: Tue, 2 Apr 2019 21:01:23 -0700 Message-Id: <20190403040133.1459-3-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403040133.1459-1-andrew.smirnov@gmail.com> References: <20190403040133.1459-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use a local "struct device *dev" in spi_gpio_probe() for brevity. No functional change intended. Signed-off-by: Andrey Smirnov Cc: Mark Brown Cc: Chris Healy Cc: linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi-gpio.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 675fd65ebf1d..2869af5ff936 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -379,6 +379,7 @@ static int spi_gpio_probe(struct platform_device *pdev) struct spi_master *master; struct spi_gpio *spi_gpio; struct spi_gpio_platform_data *pdata; + struct device *dev = &pdev->dev; u16 master_flags = 0; bool use_of = 0; @@ -388,19 +389,19 @@ static int spi_gpio_probe(struct platform_device *pdev) if (status > 0) use_of = 1; - pdata = dev_get_platdata(&pdev->dev); + pdata = dev_get_platdata(dev); #ifdef GENERIC_BITBANG if (!pdata || (!use_of && !pdata->num_chipselect)) return -ENODEV; #endif - master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio)); + master = spi_alloc_master(dev, sizeof(*spi_gpio)); if (!master) return -ENOMEM; spi_gpio = spi_master_get_devdata(master); - spi_gpio->cs_gpios = devm_kcalloc(&pdev->dev, + spi_gpio->cs_gpios = devm_kcalloc(dev, pdata->num_chipselect, sizeof(*spi_gpio->cs_gpios), GFP_KERNEL); @@ -416,7 +417,7 @@ static int spi_gpio_probe(struct platform_device *pdev) if (pdata) spi_gpio->pdata = *pdata; - status = spi_gpio_request(&pdev->dev, spi_gpio, + status = spi_gpio_request(dev, spi_gpio, pdata->num_chipselect, &master_flags); if (status) return status; @@ -431,7 +432,7 @@ static int spi_gpio_probe(struct platform_device *pdev) master->setup = spi_gpio_setup; master->cleanup = spi_gpio_cleanup; #ifdef CONFIG_OF - master->dev.of_node = pdev->dev.of_node; + master->dev.of_node = dev->of_node; #endif spi_gpio->bitbang.master = master; From patchwork Wed Apr 3 04:01:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10882697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D82F213B5 for ; Wed, 3 Apr 2019 04:02:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFBA528989 for ; Wed, 3 Apr 2019 04:02:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B38F6289BA; Wed, 3 Apr 2019 04:02:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5911C28989 for ; Wed, 3 Apr 2019 04:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726330AbfDCECp (ORCPT ); Wed, 3 Apr 2019 00:02:45 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:46951 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726376AbfDCEBz (ORCPT ); Wed, 3 Apr 2019 00:01:55 -0400 Received: by mail-pl1-f195.google.com with SMTP id y6so7326219pll.13; Tue, 02 Apr 2019 21:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3jy4yvhUe/wOfMugw4ZT/NujP1DfOs+r6jOZ3EbRTWA=; b=i9+qnXCpX4OPa9W2N7S/TZZO0QiyI/b9x72Vonoiqoll1KcrBEtyZ5YF1GT6Ja9kDJ 53rTcOl7kolC2qA/MBPFucM8X1w7lKekL3t6OAecjDOWIDPsH6C818t44dMExyTZxT5J MF5B3P00qFAwLBrZM6Xad6uGEtN0RarEsJ7O/SOkvE+AjzIHqN/811drcgRuob53m5CT F6IOQwTjfDmEOR8Kg0ha2fEXCFwrbBP3xihVM0E05Yc29KmKh2Q3KbmxRdHUgrscpFAz uH41AmAEU4Sp5sqj4zfrReFl0QvpQTweinWXGiO42UVk/5qaLenfYV6Q5KKVjCEE1bOY hFfg== 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=3jy4yvhUe/wOfMugw4ZT/NujP1DfOs+r6jOZ3EbRTWA=; b=WJYL0VHaGgqYa3v9OXUrzS5NwUwmGSPUPyzhXLdYAzPSkzg2GmBvst0haTHxm9Cbnl QekxWmf7l3/WIHwcv3mJCpUZG2Pruk7X3y6vLw+0tqKzBTM4BVZAO19Dh54EQGCJ/srK fUv/yRSEyVxmCVHxQloc2S4mBaqIJJv6WvivN13Zk8LGkNk1x64ofEx+aihu1QiwfpcO TQB4Z+Sy4BXhP75f2zN3IT9diICqgLfRxEBm3jnBvgOW1PrlNJN8AAlZJUYGrVMK0af/ X+1Xc2ftXoYoSPxmLTSNvuvJDAnDZjW9wt3R4r0ekvOmv6VzODIyU4ZrBqeewxvJ3TqF ZcRQ== X-Gm-Message-State: APjAAAW6PY/H9L8x4CQvU1LyIkPkP6QxGFOiPDktNmlHzxkXrSz8k1gb dupwDWz95sM9gbSWti1Y3kjUwoTi X-Google-Smtp-Source: APXvYqybv+XCRVSAHIKSd9Qf4och78Mi6wj1QhdOEmSf+W18CLu7zI0M7Nol7ORD0pBqzoJS/NM6OA== X-Received: by 2002:a17:902:9a0b:: with SMTP id v11mr74492018plp.194.1554264113956; Tue, 02 Apr 2019 21:01:53 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id k14sm16278064pfb.125.2019.04.02.21.01.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 21:01:52 -0700 (PDT) From: Andrey Smirnov To: linux-spi@vger.kernel.org Cc: Andrey Smirnov , Mark Brown , Chris Healy , linux-kernel@vger.kernel.org Subject: [PATCH 03/12] spi: gpio: Add local struct spi_bitbang pointer in spi_gpio_probe() Date: Tue, 2 Apr 2019 21:01:24 -0700 Message-Id: <20190403040133.1459-4-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403040133.1459-1-andrew.smirnov@gmail.com> References: <20190403040133.1459-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use a local "struct spi_bitbang *bb" in spi_gpio_probe() for brevity. No functional change intended. Signed-off-by: Andrey Smirnov Cc: Mark Brown Cc: Chris Healy Cc: linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi-gpio.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 2869af5ff936..ca97b861c625 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -380,6 +380,7 @@ static int spi_gpio_probe(struct platform_device *pdev) struct spi_gpio *spi_gpio; struct spi_gpio_platform_data *pdata; struct device *dev = &pdev->dev; + struct spi_bitbang *bb; u16 master_flags = 0; bool use_of = 0; @@ -434,23 +435,23 @@ static int spi_gpio_probe(struct platform_device *pdev) #ifdef CONFIG_OF master->dev.of_node = dev->of_node; #endif - - spi_gpio->bitbang.master = master; - spi_gpio->bitbang.chipselect = spi_gpio_chipselect; - spi_gpio->bitbang.set_line_direction = spi_gpio_set_direction; + bb = &spi_gpio->bitbang; + bb->master = master; + bb->chipselect = spi_gpio_chipselect; + bb->set_line_direction = spi_gpio_set_direction; if ((master_flags & SPI_MASTER_NO_TX) == 0) { - spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; - spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; - spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2; - spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_word_mode3; + bb->txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; + bb->txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; + bb->txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2; + bb->txrx_word[SPI_MODE_3] = spi_gpio_txrx_word_mode3; } else { - spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_spec_txrx_word_mode0; - spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_spec_txrx_word_mode1; - spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_spec_txrx_word_mode2; - spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_spec_txrx_word_mode3; + bb->txrx_word[SPI_MODE_0] = spi_gpio_spec_txrx_word_mode0; + bb->txrx_word[SPI_MODE_1] = spi_gpio_spec_txrx_word_mode1; + bb->txrx_word[SPI_MODE_2] = spi_gpio_spec_txrx_word_mode2; + bb->txrx_word[SPI_MODE_3] = spi_gpio_spec_txrx_word_mode3; } - spi_gpio->bitbang.setup_transfer = spi_bitbang_setup_transfer; + bb->setup_transfer = spi_bitbang_setup_transfer; status = spi_bitbang_start(&spi_gpio->bitbang); if (status) From patchwork Wed Apr 3 04:01:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10882691 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B973313B5 for ; Wed, 3 Apr 2019 04:02:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A37E128989 for ; Wed, 3 Apr 2019 04:02:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97E53289A2; Wed, 3 Apr 2019 04:02:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47EF728989 for ; Wed, 3 Apr 2019 04:02:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726698AbfDCEB7 (ORCPT ); Wed, 3 Apr 2019 00:01:59 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41732 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbfDCEB4 (ORCPT ); Wed, 3 Apr 2019 00:01:56 -0400 Received: by mail-pf1-f196.google.com with SMTP id 188so7451790pfd.8; Tue, 02 Apr 2019 21:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dLfVSAt3KtcR71MR0EBWnUHcnDCLOACqvXbjCjoihCk=; b=uifbI/QXjzTmlNBZBYOK5jyrhzsTCeGJJwETGxfRuOvyBUzcpxQpY2IKQszNHsrXpd jx9eM/cJUL0CXL8Om39dMQhH+FM8zK/Y+Qwtvr7Qhei7Al/cBamq3JmNm7HipE3NO8sz M4yMEWb49hVkklCiYWd92GcTj/rEQzb225Y43XVxCOkmWb/hTcVt+0X6vc/vaQuSIQrp Bux9FnT3wnEyoWOMHoVfx0f6lwa3PqagOo3T3HuZY7CoKteDHS3V/US6vJ2Q0hVm3Qby S5bjkgCaLyErTB7+H1ORZEJ4kSUG4JAeIm3cz138o3RGp+QNYBM/8R6ngHzWkSGiYj28 pPaA== 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=dLfVSAt3KtcR71MR0EBWnUHcnDCLOACqvXbjCjoihCk=; b=iIwLiQyaVlO6JXhw1iUrCKdG1rULgjFlZbl/jwt5zQbJMJkshEz7m8OFVK7ROoaehl X5TO3Kej6wAqq4V/QVzvx9l7y+mbjjYfhs2EM7uZhd8GXVLF2Ryp3tAcEYDjxbwF58yy Tg0gt7D1kXP4Z+Rz5KN1dGLutVKauEIfwBR8QnY85ve8dJEQdSw+UsFySMAKQGsKh3I6 vK9mGcQpBlHXsfvGIF1oICpOp+O9bVG3xm18aaN7ttoq/X0Ue6PpiZNsgTqbI1PAaZbF JTJClqHzCjqc0lZkqeLK5AlrMe6dq45cc0LhbqH3w7rG+fhDUFYRMRl1Kkxjav3kQLp0 yxng== X-Gm-Message-State: APjAAAV09aghtBUaL38GyCgGlIr6sAb3LGq9KqVhOJcnH2KIz0LpW0QR q7ZLEolNAZbLKgwa3RTiEqnSmo2/ X-Google-Smtp-Source: APXvYqwOmOY7Fj6lcVIr2+RYH5XWq9tndFXJr0zQh76ISErXHVz5Fu/Ef3TT5H2ozmmUxJwmFbYAyg== X-Received: by 2002:a65:524a:: with SMTP id q10mr58023109pgp.224.1554264115251; Tue, 02 Apr 2019 21:01:55 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id k14sm16278064pfb.125.2019.04.02.21.01.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 21:01:54 -0700 (PDT) From: Andrey Smirnov To: linux-spi@vger.kernel.org Cc: Andrey Smirnov , Mark Brown , Chris Healy , linux-kernel@vger.kernel.org Subject: [PATCH 04/12] spi: gpio: Simplify SPI_MASTER_NO_TX check in spi_gpio_probe() Date: Tue, 2 Apr 2019 21:01:25 -0700 Message-Id: <20190403040133.1459-5-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403040133.1459-1-andrew.smirnov@gmail.com> References: <20190403040133.1459-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Swap branches of the if statement in order to simplify it's logical condition being checked. No functional change intended. Signed-off-by: Andrey Smirnov Cc: Mark Brown Cc: Chris Healy Cc: linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi-gpio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index ca97b861c625..137f47e271dc 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -440,16 +440,16 @@ static int spi_gpio_probe(struct platform_device *pdev) bb->chipselect = spi_gpio_chipselect; bb->set_line_direction = spi_gpio_set_direction; - if ((master_flags & SPI_MASTER_NO_TX) == 0) { - bb->txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; - bb->txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; - bb->txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2; - bb->txrx_word[SPI_MODE_3] = spi_gpio_txrx_word_mode3; - } else { + if (master_flags & SPI_MASTER_NO_TX) { bb->txrx_word[SPI_MODE_0] = spi_gpio_spec_txrx_word_mode0; bb->txrx_word[SPI_MODE_1] = spi_gpio_spec_txrx_word_mode1; bb->txrx_word[SPI_MODE_2] = spi_gpio_spec_txrx_word_mode2; bb->txrx_word[SPI_MODE_3] = spi_gpio_spec_txrx_word_mode3; + } else { + bb->txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; + bb->txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; + bb->txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2; + bb->txrx_word[SPI_MODE_3] = spi_gpio_txrx_word_mode3; } bb->setup_transfer = spi_bitbang_setup_transfer; From patchwork Wed Apr 3 04:01:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10882695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2076D1708 for ; Wed, 3 Apr 2019 04:02:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08C9A28989 for ; Wed, 3 Apr 2019 04:02:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1492289A2; Wed, 3 Apr 2019 04:02:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 918DF28989 for ; Wed, 3 Apr 2019 04:02:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726676AbfDCECi (ORCPT ); Wed, 3 Apr 2019 00:02:38 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:35133 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726183AbfDCEB5 (ORCPT ); Wed, 3 Apr 2019 00:01:57 -0400 Received: by mail-pl1-f195.google.com with SMTP id w24so939960plp.2; Tue, 02 Apr 2019 21:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iJNmAhM2XNyQoO7XUgJsBxESauSJO4qHq5kgj9WqMZU=; b=KvhzMUAR2lSW4esbyEYh5b4AsJIl8g7BeQPj98AU4WWMcL4wNMILvGwUp+cvFXv19i 6GUMKfW7YYTeWKt9t8ZrkjpERjfz95eYwjhslLA19flayKrpd2WU1QG+SdR3LX0EMK1I BTdMJb7ilpe41gOaYpbA0cgnxNUJS1ABHSohXp++WfHuTcYOJeNn0OMee38LBKkAOSsc Y9zJUdHe2SRrdWz6eWbtuSLv0r64mCGa6F7maJsNTvzFGQs8MYuNSJ81HrEyWvoNhmO5 LCLszeHOAlz1FT7ngANz7ze8+jMloroG++86ElnFHq3VMmgwXO0GV4o/m4OIiyYpXJE+ Bj2g== 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=iJNmAhM2XNyQoO7XUgJsBxESauSJO4qHq5kgj9WqMZU=; b=GbC9UMZxdjbduzlHWisfF77rz9mU2CMRPs7KZ9DESZmGA1A26y+6cy4FxM6dVxklhK WfnOswHA//ldnVvlq6Jfd6vR1r4+BOLZgl+WnXGmuyeZqcHPJaYdsgLqRQatfkGHAsfv QPxEaBheyaPsGFvg/M1wFS7XnT71uOA574iXijPTLFdhdUyz8dXe1Up4zGSDPyF35O14 6d3x7NJpl8365tI2KP0S7Oe7GN9GL+yhCMrPzQUZuwMQ54+zdr1tFOqmFNMP9fe7WP07 AcMVVN62ONX9TBjFpK0LUltAFHI0MkYYfmP2Ra34h3CmMaRkCIG6gnAjMKXADzhY7mKC 8YeQ== X-Gm-Message-State: APjAAAXhzVcMPZhorDzD0NJ1G+RLsiBuxgaEjoQJBTFd+ptlnd5rrtow xYwYpfqctJdub9PtULB7ZzqQIPF8 X-Google-Smtp-Source: APXvYqyrdZ271nYyFVZz+2ECRLdtBpFfP4Wa5aB4PcONyIjEHRUVzCkrDIhb2nYD9G9ppwl4+Rc+yg== X-Received: by 2002:a17:902:868e:: with SMTP id g14mr9916862plo.183.1554264116609; Tue, 02 Apr 2019 21:01:56 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id k14sm16278064pfb.125.2019.04.02.21.01.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 21:01:55 -0700 (PDT) From: Andrey Smirnov To: linux-spi@vger.kernel.org Cc: Andrey Smirnov , Mark Brown , Chris Healy , linux-kernel@vger.kernel.org Subject: [PATCH 05/12] spi: gpio: Drop unused pdata copy in struct spi_gpio Date: Tue, 2 Apr 2019 21:01:26 -0700 Message-Id: <20190403040133.1459-6-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403040133.1459-1-andrew.smirnov@gmail.com> References: <20190403040133.1459-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Drop unused pdata copy in struct spi_gpio. No functional change intended. Signed-off-by: Andrey Smirnov Cc: Mark Brown Cc: Chris Healy Cc: linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi-gpio.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 137f47e271dc..1cff30adc836 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -42,7 +42,6 @@ struct spi_gpio { struct spi_bitbang bitbang; - struct spi_gpio_platform_data pdata; struct platform_device *pdev; struct gpio_desc *sck; struct gpio_desc *miso; @@ -415,8 +414,6 @@ static int spi_gpio_probe(struct platform_device *pdev) spi_gpio->has_cs = !!pdata->num_chipselect; spi_gpio->pdev = pdev; - if (pdata) - spi_gpio->pdata = *pdata; status = spi_gpio_request(dev, spi_gpio, pdata->num_chipselect, &master_flags); From patchwork Wed Apr 3 04:01:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10882693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1261E1708 for ; Wed, 3 Apr 2019 04:02:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFB9528989 for ; Wed, 3 Apr 2019 04:02:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E41A0289A2; Wed, 3 Apr 2019 04:02:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DCD228989 for ; Wed, 3 Apr 2019 04:02:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728637AbfDCECd (ORCPT ); Wed, 3 Apr 2019 00:02:33 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44623 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726676AbfDCEB7 (ORCPT ); Wed, 3 Apr 2019 00:01:59 -0400 Received: by mail-pg1-f193.google.com with SMTP id i2so7597633pgj.11; Tue, 02 Apr 2019 21:01:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k5jU7J6gngl6LDGofHSVbyCNiUUURALHXTXqSnIy//Y=; b=URM2vygSQZoXSUSf2WTB0DROBZio8y2w2FijAlLbD7GHGEFv3KjT+3gZ1cfFhanTm8 eaYO2CPcfLp6OceNniO6pCEf29kDKeg6x32GI9z902pAJ4q1Wl6y5RPeAzqBOgbR6EO+ e3PGCdATK1oQ0nJdKkQ4mBY9Oi8nzXhLupFUWhHJSe4JvekB9mF8US1p7pl7+6diiqnp RJXPas8NU7xwjdEMq7xK+Jekzwgr9jW9hSfsMjsEcndzYcxABM1Xq50/171/93ocjV93 qR2vdoMycfZkM8XNoWnYzEK2Wot1/ysIC9Dpc6T/afVXGFjAjMdz/b/2Gj3yvIVUS4l1 4A5Q== 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=k5jU7J6gngl6LDGofHSVbyCNiUUURALHXTXqSnIy//Y=; b=lU+8GMgwmtaQ4L9oaDj43WVtOSubk2Zd3puUaxMYuxAPdIr3DTJvnQDlWGaiVbesqY rdrY19nPsmbs9s6yB16/pf56cpBxKiOvjTcGgH0a5d+2pMZOV7G612tNgPaSe2V1TkRB 4X5Db1a+pPRuUFRKSlQ3dKRozUosVU+/U9m+jMtlhZgjLQiVzrIJbyHQIb6V45p5DSIK RurJZvk5aErNh6ioPpNGnk+P3i2C4xSgEh/fi3JuirD7rneye82jR8QcQPum1EYW32Jt By/mgg9PlrD995VfqUEED/ZgWBbgB2Snqx19B0pyv+czaaT4SLkdJxyxdZLOkjcKGgUQ 4tIQ== X-Gm-Message-State: APjAAAXLO/JcvXyl8gsN5O+AIG3w17IOCw47XnNw30GdJtFb60+wVC/E 6S9wi+OSRZFpcYsXgerdWZmnGWeq X-Google-Smtp-Source: APXvYqw3nAlNAn5rxsM50tR3al9WlArBKXES4t/jjWJl6aj+DzekLqgdr6WWwheddHpPZKixZLQ00g== X-Received: by 2002:a63:c149:: with SMTP id p9mr68403936pgi.362.1554264117984; Tue, 02 Apr 2019 21:01:57 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id k14sm16278064pfb.125.2019.04.02.21.01.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 21:01:57 -0700 (PDT) From: Andrey Smirnov To: linux-spi@vger.kernel.org Cc: Andrey Smirnov , Mark Brown , Chris Healy , linux-kernel@vger.kernel.org Subject: [PATCH 06/12] spi: gpio: Don't request CS GPIO in DT use-case Date: Tue, 2 Apr 2019 21:01:27 -0700 Message-Id: <20190403040133.1459-7-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403040133.1459-1-andrew.smirnov@gmail.com> References: <20190403040133.1459-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP DT use-case already relies on SPI core to control CS (requested by of_spi_register_master() and controlled spi_set_cs()), so there's no need to try to request those GPIO in spi-gpio code. Change the code such that spi-gpio's CS related code is only used if device is probed via pdata. Signed-off-by: Andrey Smirnov Cc: Mark Brown Cc: Chris Healy Cc: linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi-gpio.c | 134 ++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 75 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 1cff30adc836..8feb036aaf36 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -47,7 +47,6 @@ struct spi_gpio { struct gpio_desc *miso; struct gpio_desc *mosi; struct gpio_desc **cs_gpios; - bool has_cs; }; /*----------------------------------------------------------------------*/ @@ -217,7 +216,7 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active) gpiod_set_value_cansleep(spi_gpio->sck, spi->mode & SPI_CPOL); /* Drive chip select line, if we have one */ - if (spi_gpio->has_cs) { + if (spi_gpio->cs_gpios) { struct gpio_desc *cs = spi_gpio->cs_gpios[spi->chip_select]; /* SPI chip selects are normally active-low */ @@ -235,10 +234,12 @@ static int spi_gpio_setup(struct spi_device *spi) * The CS GPIOs have already been * initialized from the descriptor lookup. */ - cs = spi_gpio->cs_gpios[spi->chip_select]; - if (!spi->controller_state && cs) - status = gpiod_direction_output(cs, - !(spi->mode & SPI_CS_HIGH)); + if (spi_gpio->cs_gpios) { + cs = spi_gpio->cs_gpios[spi->chip_select]; + if (!spi->controller_state && cs) + status = gpiod_direction_output(cs, + !(spi->mode & SPI_CS_HIGH)); + } if (!status) status = spi_bitbang_setup(spi); @@ -291,11 +292,8 @@ static void spi_gpio_cleanup(struct spi_device *spi) */ static int spi_gpio_request(struct device *dev, struct spi_gpio *spi_gpio, - unsigned int num_chipselects, u16 *mflags) { - int i; - spi_gpio->mosi = devm_gpiod_get_optional(dev, "mosi", GPIOD_OUT_LOW); if (IS_ERR(spi_gpio->mosi)) return PTR_ERR(spi_gpio->mosi); @@ -316,13 +314,6 @@ static int spi_gpio_request(struct device *dev, if (IS_ERR(spi_gpio->sck)) return PTR_ERR(spi_gpio->sck); - for (i = 0; i < num_chipselects; i++) { - spi_gpio->cs_gpios[i] = devm_gpiod_get_index(dev, "cs", - i, GPIOD_OUT_HIGH); - if (IS_ERR(spi_gpio->cs_gpios[i])) - return PTR_ERR(spi_gpio->cs_gpios[i]); - } - return 0; } @@ -333,90 +324,87 @@ static const struct of_device_id spi_gpio_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, spi_gpio_dt_ids); -static int spi_gpio_probe_dt(struct platform_device *pdev) +static int spi_gpio_probe_dt(struct platform_device *pdev, + struct spi_master *master) { - int ret; - u32 tmp; - struct spi_gpio_platform_data *pdata; - struct device_node *np = pdev->dev.of_node; - const struct of_device_id *of_id = - of_match_device(spi_gpio_dt_ids, &pdev->dev); - - if (!of_id) - return 0; + master->dev.of_node = pdev->dev.of_node; + master->use_gpio_descriptors = true; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); - if (!pdata) - return -ENOMEM; + return 0; +} +#else +static inline int spi_gpio_probe_dt(struct platform_device *pdev, + struct spi_master *master) +{ + return 0; +} +#endif +static int spi_gpio_probe_pdata(struct platform_device *pdev, + struct spi_master *master) +{ + struct device *dev = &pdev->dev; + struct spi_gpio_platform_data *pdata = dev_get_platdata(dev); + struct spi_gpio *spi_gpio = spi_master_get_devdata(master); + int i; - ret = of_property_read_u32(np, "num-chipselects", &tmp); - if (ret < 0) { - dev_err(&pdev->dev, "num-chipselects property not found\n"); - goto error_free; - } +#ifdef GENERIC_BITBANG + if (!pdata || !pdata->num_chipselect) + return -ENODEV; +#endif + /* + * The master needs to think there is a chipselect even if not + * connected + */ + master->num_chipselect = pdata->num_chipselect ?: 1; - pdata->num_chipselect = tmp; - pdev->dev.platform_data = pdata; + spi_gpio->cs_gpios = devm_kcalloc(dev, master->num_chipselect, + sizeof(*spi_gpio->cs_gpios), + GFP_KERNEL); + if (!spi_gpio->cs_gpios) + return -ENOMEM; - return 1; + for (i = 0; i < master->num_chipselect; i++) { + spi_gpio->cs_gpios[i] = devm_gpiod_get_index(dev, "cs", i, + GPIOD_OUT_HIGH); + if (IS_ERR(spi_gpio->cs_gpios[i])) + return PTR_ERR(spi_gpio->cs_gpios[i]); + } -error_free: - devm_kfree(&pdev->dev, pdata); - return ret; -} -#else -static inline int spi_gpio_probe_dt(struct platform_device *pdev) -{ return 0; } -#endif static int spi_gpio_probe(struct platform_device *pdev) { int status; struct spi_master *master; struct spi_gpio *spi_gpio; - struct spi_gpio_platform_data *pdata; struct device *dev = &pdev->dev; struct spi_bitbang *bb; + const struct of_device_id *of_id; u16 master_flags = 0; - bool use_of = 0; - - status = spi_gpio_probe_dt(pdev); - if (status < 0) - return status; - if (status > 0) - use_of = 1; - pdata = dev_get_platdata(dev); -#ifdef GENERIC_BITBANG - if (!pdata || (!use_of && !pdata->num_chipselect)) - return -ENODEV; -#endif + of_id = of_match_device(spi_gpio_dt_ids, &pdev->dev); master = spi_alloc_master(dev, sizeof(*spi_gpio)); if (!master) return -ENOMEM; - spi_gpio = spi_master_get_devdata(master); + if (of_id) + status = spi_gpio_probe_dt(pdev, master); + else + status = spi_gpio_probe_pdata(pdev, master); - spi_gpio->cs_gpios = devm_kcalloc(dev, - pdata->num_chipselect, - sizeof(*spi_gpio->cs_gpios), - GFP_KERNEL); - if (!spi_gpio->cs_gpios) - return -ENOMEM; + if (status) + return status; - platform_set_drvdata(pdev, spi_gpio); + spi_gpio = spi_master_get_devdata(master); - /* Determine if we have chip selects connected */ - spi_gpio->has_cs = !!pdata->num_chipselect; + platform_set_drvdata(pdev, spi_gpio); spi_gpio->pdev = pdev; - status = spi_gpio_request(dev, spi_gpio, - pdata->num_chipselect, &master_flags); + status = spi_gpio_request(dev, spi_gpio, &master_flags); if (status) return status; @@ -425,13 +413,9 @@ static int spi_gpio_probe(struct platform_device *pdev) SPI_CS_HIGH; master->flags = master_flags; master->bus_num = pdev->id; - /* The master needs to think there is a chipselect even if not connected */ - master->num_chipselect = spi_gpio->has_cs ? pdata->num_chipselect : 1; master->setup = spi_gpio_setup; master->cleanup = spi_gpio_cleanup; -#ifdef CONFIG_OF - master->dev.of_node = dev->of_node; -#endif + bb = &spi_gpio->bitbang; bb->master = master; bb->chipselect = spi_gpio_chipselect; From patchwork Wed Apr 3 04:01:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10882679 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17F2D1708 for ; Wed, 3 Apr 2019 04:02:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00FE928989 for ; Wed, 3 Apr 2019 04:02:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E96B5289A2; Wed, 3 Apr 2019 04:02:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D283528989 for ; Wed, 3 Apr 2019 04:02:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726330AbfDCECB (ORCPT ); Wed, 3 Apr 2019 00:02:01 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42065 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726879AbfDCECA (ORCPT ); Wed, 3 Apr 2019 00:02:00 -0400 Received: by mail-pg1-f193.google.com with SMTP id p6so7595747pgh.9; Tue, 02 Apr 2019 21:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XIvhZvEfkbeo4H9XjoKPljUa+D7k5vhWMpbvGBotaLs=; b=bMGdznHsx81EYZ4yET0F5yuaCpdXWqVJqtRm0dWFMLds6gvJCZGg6DDGkk+5h8optw P9htPS1IQXxEkPQu9RTPLHI2n5xtDhtfXdYmF1Wouz5XCVBg9Uabx+LqbiUO7ORGVRf2 NbAhvvE/1RdhpfMlHiWpbPhAhKqYOgNTiV+p0rDMUytZpblSM3jEUozJZlydjL7x46bm Aa6Ziz4MdvcDgheZWN0DfGSVpmrseQRgHlbKWEZl4pwMLUqVxYp5W745FTdMwakO6QTn BjMOgKLvburc8LQKWXCS1mXS2FPrMIa3gECZGLyAY7ex9/BMfwUTEDgxCdY+DIRaT2Hb QmDg== 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=XIvhZvEfkbeo4H9XjoKPljUa+D7k5vhWMpbvGBotaLs=; b=L6Wj/GKcCxk75/zS8+yWIUTv47ZjXtUoeWqWy2jpsuHWG93EbTOHTqBCOmUeN3Rv+Q eFm/qdoQZoAD7i8L4t91cTz5W1UuhF4OygSoRoT2+alHcmgsHa+XhvfWHPl8rO2bfkF7 9kRBNuLE/9SgbkLLgHLE7UYkEc+fjMFvWOzgq56dYesS0DkRyNZRtuSF4Lpr0sVXfla4 lEps7cJRnsYm+9f67SAcP/+jE57ewjfVzgzxPbr6jhIiUe/ohHfllsrxEmGqlZepaY87 tLKUVnmkAbpz/HgeLG4j2MfbbXTORLNf4SodpBOWIquegY1v20Q90UJcpnEhWTWG5J2b 758Q== X-Gm-Message-State: APjAAAWXxultlxqtnJdY6sEybjy6CP5kkZnYp5uRvF7WzuOMEOln3heD hxZRN831e3zTfJ7EJBHDzltDKcVD X-Google-Smtp-Source: APXvYqx+Xz6lSUAlH4ppEZuZZgS80Abtb6x6Jc6jy3asPFa4TqW4p8ewRFreevY1zBelFGxU/MDbPQ== X-Received: by 2002:a63:c706:: with SMTP id n6mr37001089pgg.310.1554264119436; Tue, 02 Apr 2019 21:01:59 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id k14sm16278064pfb.125.2019.04.02.21.01.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 21:01:58 -0700 (PDT) From: Andrey Smirnov To: linux-spi@vger.kernel.org Cc: Andrey Smirnov , Mark Brown , Chris Healy , linux-kernel@vger.kernel.org Subject: [PATCH 07/12] spi: Don't call spi_get_gpio_descs() before device name is set Date: Tue, 2 Apr 2019 21:01:28 -0700 Message-Id: <20190403040133.1459-8-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403040133.1459-1-andrew.smirnov@gmail.com> References: <20190403040133.1459-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move code calling spi_get_gpio_descs() to happen after ctlr->dev's name is set in order to have proper GPIO consumer names. Before: cat /sys/kernel/debug/gpio gpiochip0: GPIOs 0-31, parent: platform/40049000.gpio, vf610-gpio: gpio-6 ( |regulator-usb0-vbus ) out lo gpiochip1: GPIOs 32-63, parent: platform/4004a000.gpio, vf610-gpio: gpio-36 ( |scl ) in hi gpio-37 ( |sda ) in hi gpio-40 ( |(null) CS1 ) out lo gpio-41 ( |(null) CS0 ) out lo ACTIVE LOW gpio-42 ( |miso ) in hi gpio-43 ( |mosi ) in lo gpio-44 ( |sck ) out lo After: cat /sys/kernel/debug/gpio gpiochip0: GPIOs 0-31, parent: platform/40049000.gpio, vf610-gpio: gpio-6 ( |regulator-usb0-vbus ) out lo gpiochip1: GPIOs 32-63, parent: platform/4004a000.gpio, vf610-gpio: gpio-36 ( |scl ) in hi gpio-37 ( |sda ) in hi gpio-40 ( |spi0 CS1 ) out lo gpio-41 ( |spi0 CS0 ) out lo ACTIVE LOW gpio-42 ( |miso ) in hi gpio-43 ( |mosi ) in lo gpio-44 ( |sck ) out lo Signed-off-by: Andrey Smirnov Cc: Mark Brown Cc: Chris Healy Cc: linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index bd2a424672df..19d663435b8c 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2279,24 +2279,6 @@ int spi_register_controller(struct spi_controller *ctlr) if (status) return status; - if (!spi_controller_is_slave(ctlr)) { - if (ctlr->use_gpio_descriptors) { - status = spi_get_gpio_descs(ctlr); - if (status) - return status; - /* - * A controller using GPIO descriptors always - * supports SPI_CS_HIGH if need be. - */ - ctlr->mode_bits |= SPI_CS_HIGH; - } else { - /* Legacy code path for GPIOs from DT */ - status = of_spi_register_master(ctlr); - if (status) - return status; - } - } - /* even if it's just one always-selected device, there must * be at least one chipselect */ @@ -2353,6 +2335,25 @@ int spi_register_controller(struct spi_controller *ctlr) * registration fails if the bus ID is in use. */ dev_set_name(&ctlr->dev, "spi%u", ctlr->bus_num); + + if (!spi_controller_is_slave(ctlr)) { + if (ctlr->use_gpio_descriptors) { + status = spi_get_gpio_descs(ctlr); + if (status) + return status; + /* + * A controller using GPIO descriptors always + * supports SPI_CS_HIGH if need be. + */ + ctlr->mode_bits |= SPI_CS_HIGH; + } else { + /* Legacy code path for GPIOs from DT */ + status = of_spi_register_master(ctlr); + if (status) + return status; + } + } + status = device_add(&ctlr->dev); if (status < 0) { /* free bus id */ From patchwork Wed Apr 3 04:01:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10882689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A31FB13B5 for ; Wed, 3 Apr 2019 04:02:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C25628989 for ; Wed, 3 Apr 2019 04:02:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80AA3289A2; Wed, 3 Apr 2019 04:02:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D19528989 for ; Wed, 3 Apr 2019 04:02:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728591AbfDCEC0 (ORCPT ); Wed, 3 Apr 2019 00:02:26 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42067 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726882AbfDCECB (ORCPT ); Wed, 3 Apr 2019 00:02:01 -0400 Received: by mail-pg1-f193.google.com with SMTP id p6so7595771pgh.9; Tue, 02 Apr 2019 21:02:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=39NNYeOrV7mh6FA8OvJAbA6NUD0BCyEWK7Cku8gU+xE=; b=JXTR7nmBJTUYf6ab5jmfTGZ6v93ePKFKj37s2ZTn8Ylr9G6b8pOpvQH0DFJ68ovTza YYAzzQg9vGGuDs/PYBqQ8r5DeIW6PDlmPXXgaBh9PycVbzFtBc4S2j6K8fw+PnCVSc1Q iXLuuxTHGItceaxPhvzApe6uHUh9ve5y2jxo2uvtMWieboNUv4wX9xMxLrtVSdu1xfwp MVJ9kUPcPakH20gzEH6P/Ni++UzI66YBZo3nxnn2lq29JQZ12Jqmhjl60f2Sxct5ekML s7d92ornq5srbj4LjNGnP4OauELne7Os5FkmTe7CEUDmTkLVLIi27YORoZX0ivju+lw9 6SQg== 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=39NNYeOrV7mh6FA8OvJAbA6NUD0BCyEWK7Cku8gU+xE=; b=Icvze9zPfCtVWOKynyH1r5/ud0WGzCOdAdFiGRvXm60bgsMNRzeDggiXZe33FqIBtt GRKD/xwgyJa1UyvT0gWeb7QFpQIJO1JfUNmmkkSNe4iEf/DI/wbBHNlbvwk9wNTJ3mDb W4cQ5gbpU756RE/qaCPDUm+3Gop86XoNWXSLMqeic2QnQmftRN0GxcXxATVZOnm/T35b vn6NgcL3MSbYMDUjpxjpAzD8MS7eYr6bdGeF1h6qT+9GS1EVOh71+ALIOED3/TPbzoZq 2uyPACCjg1gGEQPgGNY9C1j512DW0AvJkvoHxm5EBkdUXtFkxn9VBEZ+GRaLUDXdrJ0a OibQ== X-Gm-Message-State: APjAAAU/6Oh93VvMlpIw8uNoYK/ko8wOFmDs/CxFSXD+8qhpRFXnaEAm mWBehcka9KMn6kc4VKtDhLVLD+Vl X-Google-Smtp-Source: APXvYqyD8xKZZX6LmOLIiIG3Fy8Go8G4Yo60sWe1jZgd7VW1jEw09FjTrNuzka7oQow2bJPObaC8xQ== X-Received: by 2002:a63:450f:: with SMTP id s15mr69435269pga.157.1554264120464; Tue, 02 Apr 2019 21:02:00 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id k14sm16278064pfb.125.2019.04.02.21.01.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 21:01:59 -0700 (PDT) From: Andrey Smirnov To: linux-spi@vger.kernel.org Cc: Andrey Smirnov , Mark Brown , Chris Healy , linux-kernel@vger.kernel.org Subject: [PATCH 08/12] spi: gpio: Drop mflags argument from spi_gpio_request() Date: Tue, 2 Apr 2019 21:01:29 -0700 Message-Id: <20190403040133.1459-9-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403040133.1459-1-andrew.smirnov@gmail.com> References: <20190403040133.1459-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The logic of setting mflags in spi_gpio_request() is very simple and there isn't much benefit in having it in that function. Move all of that code outside into spi_gpio_probe() in order to simplify things. Signed-off-by: Andrey Smirnov Cc: Mark Brown Cc: Chris Healy Cc: linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi-gpio.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 8feb036aaf36..84ca803f6f69 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -290,25 +290,15 @@ static void spi_gpio_cleanup(struct spi_device *spi) * floating signals. (A weak pulldown would save power too, but many * drivers expect to see all-ones data as the no slave "response".) */ -static int spi_gpio_request(struct device *dev, - struct spi_gpio *spi_gpio, - u16 *mflags) +static int spi_gpio_request(struct device *dev, struct spi_gpio *spi_gpio) { spi_gpio->mosi = devm_gpiod_get_optional(dev, "mosi", GPIOD_OUT_LOW); if (IS_ERR(spi_gpio->mosi)) return PTR_ERR(spi_gpio->mosi); - if (!spi_gpio->mosi) - /* HW configuration without MOSI pin */ - *mflags |= SPI_MASTER_NO_TX; spi_gpio->miso = devm_gpiod_get_optional(dev, "miso", GPIOD_IN); if (IS_ERR(spi_gpio->miso)) return PTR_ERR(spi_gpio->miso); - /* - * No setting SPI_MASTER_NO_RX here - if there is only a MOSI - * pin connected the host can still do RX by changing the - * direction of the line. - */ spi_gpio->sck = devm_gpiod_get(dev, "sck", GPIOD_OUT_LOW); if (IS_ERR(spi_gpio->sck)) @@ -382,7 +372,6 @@ static int spi_gpio_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct spi_bitbang *bb; const struct of_device_id *of_id; - u16 master_flags = 0; of_id = of_match_device(spi_gpio_dt_ids, &pdev->dev); @@ -404,14 +393,23 @@ static int spi_gpio_probe(struct platform_device *pdev) spi_gpio->pdev = pdev; - status = spi_gpio_request(dev, spi_gpio, &master_flags); + status = spi_gpio_request(dev, spi_gpio); if (status) return status; master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); master->mode_bits = SPI_3WIRE | SPI_3WIRE_HIZ | SPI_CPHA | SPI_CPOL | SPI_CS_HIGH; - master->flags = master_flags; + if (!spi_gpio->mosi) { + /* HW configuration without MOSI pin + * + * No setting SPI_MASTER_NO_RX here - if there is only + * a MOSI pin connected the host can still do RX by + * changing the direction of the line. + */ + master->flags = SPI_MASTER_NO_TX; + } + master->bus_num = pdev->id; master->setup = spi_gpio_setup; master->cleanup = spi_gpio_cleanup; @@ -421,7 +419,7 @@ static int spi_gpio_probe(struct platform_device *pdev) bb->chipselect = spi_gpio_chipselect; bb->set_line_direction = spi_gpio_set_direction; - if (master_flags & SPI_MASTER_NO_TX) { + if (master->flags & SPI_MASTER_NO_TX) { bb->txrx_word[SPI_MODE_0] = spi_gpio_spec_txrx_word_mode0; bb->txrx_word[SPI_MODE_1] = spi_gpio_spec_txrx_word_mode1; bb->txrx_word[SPI_MODE_2] = spi_gpio_spec_txrx_word_mode2; From patchwork Wed Apr 3 04:01:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10882681 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 929851708 for ; Wed, 3 Apr 2019 04:02:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C8A728989 for ; Wed, 3 Apr 2019 04:02:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70613289A2; Wed, 3 Apr 2019 04:02:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1988D28989 for ; Wed, 3 Apr 2019 04:02:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727082AbfDCECE (ORCPT ); Wed, 3 Apr 2019 00:02:04 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:45141 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727019AbfDCECC (ORCPT ); Wed, 3 Apr 2019 00:02:02 -0400 Received: by mail-pg1-f193.google.com with SMTP id y3so7593959pgk.12; Tue, 02 Apr 2019 21:02:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tQnPRHBYBncms8D+H1okMWZ+MjeILBMAYDZbMM2hsC8=; b=RVqf+s0WgJTl4KGO1hALttS6DkfOn+T5OuGU1CTG98d2u2NOBOUzSJj578cvPL5psn 9Y5oPqXUdOla+AHFksxvWWuVRRlLpo+ATmD+bUiCD5deNsXfsDSo9g4PfYdr75y3bHoJ wMoROOs7uRPUHRA+BQABEPWRy7dOKNwtOiE/Hu+3cF58De64FqEsW4oU+Fzk8iF/BH+K HxhYJwI+DQ/A7ERQ67bkUJDJXA+2aMZmlbzwFYmS5MuZPDqG2K6cOXIcvQ6Sgb7Cd5wv cW3o7UqPRzLMup2NDmmBn+3njwFS1++PK/EYh7Qfa/dZlcN9TTusVsFrhUoBxEyEVs8M tjFw== 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=tQnPRHBYBncms8D+H1okMWZ+MjeILBMAYDZbMM2hsC8=; b=rOHYLAh3TGamaefr0244oPNBVMSivmJb2/giDN7NLz/0LIbPUnWbRtZNCqDAfuLffK mdA7ryceJ36UsN95O0ZdKFc+No44+p6sc4ylIdB+Mzl+6f14+2ZrN1tkMP5R4h7ebkAX p3b0Dv5662beqYgNB6kOfBrKdChoD66CVNdr1fItuWkgTf/KNTNpFcwLw+oJ06qly551 josLcYTCNF+ts3bscyUutWFNTg4WNOpO1X+PCRlJuy1OdNBoUeYXPkS9W2+k1g1dME+J SBPVdC9T1eiWuJAKNn6uCBaezqrEdNg1J41q85mkZK/PSKy1kWIr4uZeMghNchJ/16KC 836g== X-Gm-Message-State: APjAAAVT0lzH9qY7c5ci2cRyhLBFaZbYvgKxIjbxqHeSPTeTNJcEiRvk g0azZBiazfCGhk0HV06+J5Z/BqTP X-Google-Smtp-Source: APXvYqyiU76RxdOYmcXJysoHeQ7fASKhbnbSoV2Ep7nsLyRO95wjHhNlwUw2h3xHMIsRBk2eM5PB8Q== X-Received: by 2002:a63:4b21:: with SMTP id y33mr17899629pga.37.1554264121792; Tue, 02 Apr 2019 21:02:01 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id k14sm16278064pfb.125.2019.04.02.21.02.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 21:02:00 -0700 (PDT) From: Andrey Smirnov To: linux-spi@vger.kernel.org Cc: Andrey Smirnov , Mark Brown , Chris Healy , linux-kernel@vger.kernel.org Subject: [PATCH 09/12] spi: gpio: Drop unused pdev field in struct spi_gpio Date: Tue, 2 Apr 2019 21:01:30 -0700 Message-Id: <20190403040133.1459-10-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403040133.1459-1-andrew.smirnov@gmail.com> References: <20190403040133.1459-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There's no code using 'pdev' field in struct spi_gpio. Drop it. Signed-off-by: Andrey Smirnov Cc: Mark Brown Cc: Chris Healy Cc: linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi-gpio.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 84ca803f6f69..3a6a9c6966c0 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -42,7 +42,6 @@ struct spi_gpio { struct spi_bitbang bitbang; - struct platform_device *pdev; struct gpio_desc *sck; struct gpio_desc *miso; struct gpio_desc *mosi; @@ -391,8 +390,6 @@ static int spi_gpio_probe(struct platform_device *pdev) platform_set_drvdata(pdev, spi_gpio); - spi_gpio->pdev = pdev; - status = spi_gpio_request(dev, spi_gpio); if (status) return status; From patchwork Wed Apr 3 04:01:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10882687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA5C21708 for ; Wed, 3 Apr 2019 04:02:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D145428989 for ; Wed, 3 Apr 2019 04:02:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5CFC289A2; Wed, 3 Apr 2019 04:02:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7430628989 for ; Wed, 3 Apr 2019 04:02:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727659AbfDCECT (ORCPT ); Wed, 3 Apr 2019 00:02:19 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36206 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727074AbfDCECE (ORCPT ); Wed, 3 Apr 2019 00:02:04 -0400 Received: by mail-pg1-f195.google.com with SMTP id 85so7613142pgc.3; Tue, 02 Apr 2019 21:02:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QyOnTBJf/kTDbr8sbHX90kGMHGeBMmlt7qQvUMBV6R8=; b=AXwCGDl8j7mR0lj+I7+AvreG5NKPpLssswWxd3yx2MFt1Ol2xIyDe9VwRf5b3cEqZT 1q8nx/SRn2MNYA2XltmPs+ryqoOpLPFYQaL685BW5wPRms/rHTgI08oHETew5amhTQqk Rc6Koo/xh3hDysvUWsoKS8XQb2zK0f18qTmx3dasRHfBXbCPgvu9DtTZxoOSQCuzpL9Z E2WsJCt6D7bngVuqy4KHeoYMef5Q9vVD093MkztIPvqIlbsOBRJhBsTPljVY9eG97s/z 6a45dyRRe/us04vM3eMJg0DOIAKO8phT+rxso6M4vosqtd9v3L/BUCQW1qp4x5BGo+20 bmgw== 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=QyOnTBJf/kTDbr8sbHX90kGMHGeBMmlt7qQvUMBV6R8=; b=pTh3MnuU06vy3i6aaWSMPLv8HFcaxkLsaPcpDhymftKGHA39h89Fp5aD2XjzbnY9UU JNyyMG8ERQcbzi+8fQLZnz/lLrOcbZB83rfuGMnadvihJ2B5dNiNj33EmunSzbl/2+zB az7aF0vmsRp3oMRWqk1jGvx01HIF2GdHvTs291pwL2EzgfL0D0LpB3HvoL3/zhr2ze/w ahxQdik7QaNqoFNlB76sS/8+0H+0h4omyT96B5h0bigNA0IWHZ7YEdjTwiH6BrEdtNSL OMs8/ach+F7JzQwuxVBTJ3XbYl3p+lFO+Skk3AYHJbajBfUdDl2wnpjed19alzKZloPN x2Lw== X-Gm-Message-State: APjAAAVF+W31xtr8Zicx8rTzLgYx3SlPF1oXeuzBcxXgiv+nfZh5zLGi pcqn4C5fNpGR4IoKKuJL6kShpIqI X-Google-Smtp-Source: APXvYqxeUsVilA9Lr7txbpx+AndJ5LWeIK/Em8v+1oBU1sC5ufT8eWQ7DcmuVPTTpWayUO3ehoQvCA== X-Received: by 2002:a63:4e64:: with SMTP id o36mr69081973pgl.213.1554264123069; Tue, 02 Apr 2019 21:02:03 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id k14sm16278064pfb.125.2019.04.02.21.02.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 21:02:02 -0700 (PDT) From: Andrey Smirnov To: linux-spi@vger.kernel.org Cc: Andrey Smirnov , Mark Brown , Chris Healy , linux-kernel@vger.kernel.org Subject: [PATCH 10/12] spi: gpio: Make sure spi_master_put() is called in every error path Date: Tue, 2 Apr 2019 21:01:31 -0700 Message-Id: <20190403040133.1459-11-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403040133.1459-1-andrew.smirnov@gmail.com> References: <20190403040133.1459-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There's a number of failure paths in spi_gpio_probe() that do not call spi_master_put() potentially leaking memory. Fix this problem by registering a cleanup funciont via devm_add_action_or_reset() right after SPI controller is allocated. Signed-off-by: Andrey Smirnov Cc: Mark Brown Cc: Chris Healy Cc: linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi-gpio.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 3a6a9c6966c0..668f2cd82d98 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -363,6 +363,11 @@ static int spi_gpio_probe_pdata(struct platform_device *pdev, return 0; } +static void spi_gpio_put(void *data) +{ + spi_master_put(data); +} + static int spi_gpio_probe(struct platform_device *pdev) { int status; @@ -378,6 +383,10 @@ static int spi_gpio_probe(struct platform_device *pdev) if (!master) return -ENOMEM; + status = devm_add_action_or_reset(&pdev->dev, spi_gpio_put, master); + if (status) + return status; + if (of_id) status = spi_gpio_probe_dt(pdev, master); else @@ -429,11 +438,7 @@ static int spi_gpio_probe(struct platform_device *pdev) } bb->setup_transfer = spi_bitbang_setup_transfer; - status = spi_bitbang_start(&spi_gpio->bitbang); - if (status) - spi_master_put(master); - - return status; + return spi_bitbang_start(&spi_gpio->bitbang); } static int spi_gpio_remove(struct platform_device *pdev) @@ -445,8 +450,6 @@ static int spi_gpio_remove(struct platform_device *pdev) /* stop() unregisters child devices too */ spi_bitbang_stop(&spi_gpio->bitbang); - spi_master_put(spi_gpio->bitbang.master); - return 0; } From patchwork Wed Apr 3 04:01:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10882685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15DA61708 for ; Wed, 3 Apr 2019 04:02:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F328C2898B for ; Wed, 3 Apr 2019 04:02:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E77CE289A2; Wed, 3 Apr 2019 04:02:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81C5728989 for ; Wed, 3 Apr 2019 04:02:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727629AbfDCECG (ORCPT ); Wed, 3 Apr 2019 00:02:06 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44632 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727441AbfDCECF (ORCPT ); Wed, 3 Apr 2019 00:02:05 -0400 Received: by mail-pg1-f193.google.com with SMTP id i2so7597782pgj.11; Tue, 02 Apr 2019 21:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lQ5TRqsl7OK4dEO30Fxm7obK/gnvpQsYkNAdZjHgD1Y=; b=ptrpgFFFBW0XMvWarVP6hSin6Cp1WxSuNsLKB7TAFV5pdPCxGk5HFmcE5f3/WTZ8FD syQqXCDq1sKD6aYHBAhmgJ4ftW4OilbWAKA2lhusyQ2lKsYFKiQmZjnMsFMhlydEOptC 5f4ozgwH/vCLKc3xj/0aPzTxfFPH6iAyK6G11ilREhLnNUEVDbIeCD8tImioTuG/5hZX yAdk1/8vTvTNLDjIf5zd+8F43IXnX/QkxNKW3Bax0zuLcHI5IQhktinJLNTJab58NIeG VmrY1zGFU4EM/uxXzypQGcJffxFsd2f+IQ1cWOrEAtKdN3ZdbcY+IV3KlD31i9UGaAWC DQIA== 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=lQ5TRqsl7OK4dEO30Fxm7obK/gnvpQsYkNAdZjHgD1Y=; b=JuF7aPcJbpZ2HvWhu0Z8AzeE8Ff4+LP40q2IyTZ4zzoUG8ksnkcqi20NDQR/5uoZwN R5Ac/BhnJ94hS+INanDs70QmIgUwNTe/IHGZDehxiSgkeScpzp9QbittLbRVc6a3wz+J YYDPJv8mWsRpXVpHEoXGvLjnAhYsINGGLM0uYtGSyJ2ISFoS9hfTn4FseXusL8RFSOdR H5ljpymCU5I41jmM3VfAFdin+SDh3v1YRNymTwREoMxCqiKNTXmjRHep6Oy9QbnR1ne6 CJp4tTmPFLilsRzPc5Jip2ExHC47Zu2/w6UelBY/NjYB5aF4qQ/3faQDpZSRw7y5fTrB ohkA== X-Gm-Message-State: APjAAAV1htW+dKE+9RSBo4sxanHwtFVOJgv7zJzULvBC916PgB5JxMa5 BjQq7iennGgEGu7mX2a8++es0ZHB X-Google-Smtp-Source: APXvYqxFnxsBSlLgCTkoKsjb5WiZfgpz43mL3z0eSIukGuN54vp1cQf2g/tu8wffxkwZbNq8luvsMw== X-Received: by 2002:a63:554b:: with SMTP id f11mr11742738pgm.77.1554264124585; Tue, 02 Apr 2019 21:02:04 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id k14sm16278064pfb.125.2019.04.02.21.02.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 21:02:03 -0700 (PDT) From: Andrey Smirnov To: linux-spi@vger.kernel.org Cc: Andrey Smirnov , Mark Brown , Chris Healy , linux-kernel@vger.kernel.org Subject: [PATCH 11/12] spi: bitbang: Introduce spi_bitbang_init() Date: Tue, 2 Apr 2019 21:01:32 -0700 Message-Id: <20190403040133.1459-12-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403040133.1459-1-andrew.smirnov@gmail.com> References: <20190403040133.1459-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move all of the code doing struct spi_bitbang initialization, so that it can be paired with devm_spi_register_master() in order to avoid having to call spi_bitbang_stop() explicitly. Signed-off-by: Andrey Smirnov Cc: Mark Brown Cc: Chris Healy Cc: linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi-bitbang.c | 66 +++++++++++++++++++-------------- include/linux/spi/spi_bitbang.h | 1 + 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c index dd9a8c54a693..4243e53f9f7b 100644 --- a/drivers/spi/spi-bitbang.c +++ b/drivers/spi/spi-bitbang.c @@ -335,6 +335,42 @@ static void spi_bitbang_set_cs(struct spi_device *spi, bool enable) /*----------------------------------------------------------------------*/ +int spi_bitbang_init(struct spi_bitbang *bitbang) +{ + struct spi_master *master = bitbang->master; + + if (!master || !bitbang->chipselect) + return -EINVAL; + + mutex_init(&bitbang->lock); + + if (!master->mode_bits) + master->mode_bits = SPI_CPOL | SPI_CPHA | bitbang->flags; + + if (master->transfer || master->transfer_one_message) + return -EINVAL; + + master->prepare_transfer_hardware = spi_bitbang_prepare_hardware; + master->unprepare_transfer_hardware = spi_bitbang_unprepare_hardware; + master->transfer_one = spi_bitbang_transfer_one; + master->set_cs = spi_bitbang_set_cs; + + if (!bitbang->txrx_bufs) { + bitbang->use_dma = 0; + bitbang->txrx_bufs = spi_bitbang_bufs; + if (!master->setup) { + if (!bitbang->setup_transfer) + bitbang->setup_transfer = + spi_bitbang_setup_transfer; + master->setup = spi_bitbang_setup; + master->cleanup = spi_bitbang_cleanup; + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(spi_bitbang_init); + /** * spi_bitbang_start - start up a polled/bitbanging SPI master driver * @bitbang: driver handle @@ -368,33 +404,9 @@ int spi_bitbang_start(struct spi_bitbang *bitbang) struct spi_master *master = bitbang->master; int ret; - if (!master || !bitbang->chipselect) - return -EINVAL; - - mutex_init(&bitbang->lock); - - if (!master->mode_bits) - master->mode_bits = SPI_CPOL | SPI_CPHA | bitbang->flags; - - if (master->transfer || master->transfer_one_message) - return -EINVAL; - - master->prepare_transfer_hardware = spi_bitbang_prepare_hardware; - master->unprepare_transfer_hardware = spi_bitbang_unprepare_hardware; - master->transfer_one = spi_bitbang_transfer_one; - master->set_cs = spi_bitbang_set_cs; - - if (!bitbang->txrx_bufs) { - bitbang->use_dma = 0; - bitbang->txrx_bufs = spi_bitbang_bufs; - if (!master->setup) { - if (!bitbang->setup_transfer) - bitbang->setup_transfer = - spi_bitbang_setup_transfer; - master->setup = spi_bitbang_setup; - master->cleanup = spi_bitbang_cleanup; - } - } + ret = spi_bitbang_init(bitbang); + if (ret) + return ret; /* driver may get busy before register() returns, especially * if someone registered boardinfo for devices diff --git a/include/linux/spi/spi_bitbang.h b/include/linux/spi/spi_bitbang.h index b7e021b274dc..4444c2a992cb 100644 --- a/include/linux/spi/spi_bitbang.h +++ b/include/linux/spi/spi_bitbang.h @@ -44,6 +44,7 @@ extern int spi_bitbang_setup_transfer(struct spi_device *spi, /* start or stop queue processing */ extern int spi_bitbang_start(struct spi_bitbang *spi); +extern int spi_bitbang_init(struct spi_bitbang *spi); extern void spi_bitbang_stop(struct spi_bitbang *spi); #endif /* __SPI_BITBANG_H */ From patchwork Wed Apr 3 04:01:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10882683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F17D913B5 for ; Wed, 3 Apr 2019 04:02:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA88A28989 for ; Wed, 3 Apr 2019 04:02:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CECCF289A2; Wed, 3 Apr 2019 04:02:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C99A28989 for ; Wed, 3 Apr 2019 04:02:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727019AbfDCECH (ORCPT ); Wed, 3 Apr 2019 00:02:07 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:37702 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727659AbfDCECH (ORCPT ); Wed, 3 Apr 2019 00:02:07 -0400 Received: by mail-pf1-f193.google.com with SMTP id 8so7459715pfr.4; Tue, 02 Apr 2019 21:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/HOj5AcsPPIUP9eNWZ5uQOH1gzbtnepnAaSzlGF2WO8=; b=mshvlYNL7Y3Ctd1PpKGF/38N3zF4DnPDyUJmXs7lu14zGu+fgPkReT7E8vx3wEBIIi LRMXuv5JsRITmYy+5R0uGqhF2D5wsvZp4HKiQwi7eIWPS/0el7yIw0lRN5OOFnrGPQs6 EY+eAXlZQMlegGl8GD8wApevIG9qwr3yl8YB14Daa08F49bvnv0+tSiyFo0aff2j4G9T WESqkAK7u/9VuBjJf9kmRUPAEQxtCb1Vywv14hPfbbLqTYJQyciHWzwV5nBgpUxRaI9T 1TT/5StA8t9A+PPXtdulLhUMMYZe5NnvWstvrL1eUUdxY6EQOUTNKEP1xNXaKb13lhdL 0bXw== 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=/HOj5AcsPPIUP9eNWZ5uQOH1gzbtnepnAaSzlGF2WO8=; b=mWns6ZRQsPjmoKIB8fiFyr3J36dnERek1JmQcv8nr14dV0cKmVrKv9850t7PCJlUzw 2jk4jdNjMCOHAzJUethEFlXSC5vhYHL8yhyu1DPapZQlqDJk7B54ZRcBRrWJOWC4rSur feH6Ct/pMLSkQmRkpmQuOgIYROUPg81NyM86u43MSn3Eb3F8cKjYIjhqrEPywX6+9IXJ xrzAPN0ZdYD/9FiGHcA5/deod+NXciePWCt/fz5tRVEAPZ5gVvxeKzjKCXaSc2ARHMxo KqUyi9MIAQ4JM5C+3omLUodGi9O41iTysllrOZFlgzjp/k86zvqgXXtfY1pnZpbOgJI8 VPiw== X-Gm-Message-State: APjAAAUi6d7V1xUhI41SnSmS3FVCu1VUCpvt4RpruibvZ9oHF95Jy1E4 KR3AGsApz+X7uaWgGCv7V591bLet X-Google-Smtp-Source: APXvYqwVaJX8j3M/byMDW7Q8RRDk3NV2jI8WNad7Iz7Y92HtWj+VNLoxmtQdPklCl8I8wky/Zps6vQ== X-Received: by 2002:a63:c706:: with SMTP id n6mr37001637pgg.310.1554264125998; Tue, 02 Apr 2019 21:02:05 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id k14sm16278064pfb.125.2019.04.02.21.02.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 21:02:05 -0700 (PDT) From: Andrey Smirnov To: linux-spi@vger.kernel.org Cc: Andrey Smirnov , Mark Brown , Chris Healy , linux-kernel@vger.kernel.org Subject: [PATCH 12/12] spi: gpio: Use devm_spi_register_master() Date: Tue, 2 Apr 2019 21:01:33 -0700 Message-Id: <20190403040133.1459-13-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403040133.1459-1-andrew.smirnov@gmail.com> References: <20190403040133.1459-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace spi_bitbang_start() with a combination of spi_bitbang_init() and devm_spi_register_master() and drop all of the explicit cleanup-related code that's no longer necessary. Signed-off-by: Andrey Smirnov Cc: Mark Brown Cc: Chris Healy Cc: linux-spi@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi-gpio.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 668f2cd82d98..674432bbbbc2 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -397,8 +397,6 @@ static int spi_gpio_probe(struct platform_device *pdev) spi_gpio = spi_master_get_devdata(master); - platform_set_drvdata(pdev, spi_gpio); - status = spi_gpio_request(dev, spi_gpio); if (status) return status; @@ -438,19 +436,11 @@ static int spi_gpio_probe(struct platform_device *pdev) } bb->setup_transfer = spi_bitbang_setup_transfer; - return spi_bitbang_start(&spi_gpio->bitbang); -} - -static int spi_gpio_remove(struct platform_device *pdev) -{ - struct spi_gpio *spi_gpio; - - spi_gpio = platform_get_drvdata(pdev); - - /* stop() unregisters child devices too */ - spi_bitbang_stop(&spi_gpio->bitbang); + status = spi_bitbang_init(&spi_gpio->bitbang); + if (status) + return status; - return 0; + return devm_spi_register_master(&pdev->dev, spi_master_get(master)); } MODULE_ALIAS("platform:" DRIVER_NAME); @@ -461,7 +451,6 @@ static struct platform_driver spi_gpio_driver = { .of_match_table = of_match_ptr(spi_gpio_dt_ids), }, .probe = spi_gpio_probe, - .remove = spi_gpio_remove, }; module_platform_driver(spi_gpio_driver);