From patchwork Thu Jun 27 16:26:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Singh X-Patchwork-Id: 13714800 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EAB90C2BD09 for ; Thu, 27 Jun 2024 16:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dJ1Q8KLXbBvPejPRGDLYr/bC1HXbn69hKei2CLRD37M=; b=Sg0+GXdX/u6ph7B7WECmBFQ2Gj vDmH/Ifrp2C+Nkqd9p5IirW7Sstk0++kMA56z7gJf0CLt6i1VCZPPLrlcYRFjU7B9u/se76O7Uw4g fS9YZHICz5S2FSRhjf90gWLpJAXAUhYVZZUIknqm1GzmZsD/Sxx8p0DNlTn24zogYaaTWHaqsZiRh T/tfQc7fFrPJhfM13906gwUCMGC7fQ5mzm6IBwrn4CqthM7dBNoW5aWf8hgU7sigjUB5O3unrj1WG kwlakxbvmTLvyKz1Dd3UnOBhrmqY1pyVS+XxbdRlpXwNr6FZSs7wOqE0uH+wUur6wd6UgdC+VFQuD /vVQIprg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMs01-0000000B2xt-0Ypq; Thu, 27 Jun 2024 16:29:29 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMrzl-0000000B2mo-12nG for linux-arm-kernel@lists.infradead.org; Thu, 27 Jun 2024 16:29:15 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-7068fe9f98aso411444b3a.0 for ; Thu, 27 Jun 2024 09:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beagleboard-org.20230601.gappssmtp.com; s=20230601; t=1719505752; x=1720110552; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=dJ1Q8KLXbBvPejPRGDLYr/bC1HXbn69hKei2CLRD37M=; b=rq+2PaJM4O8tJ3+NWJNTVw0xyaQHRVegU8eDy9n3lbtZPURyc2A/q/ZMVhgjcjV9nh 7xzvb3wQ+D+Lmln+6Tfqcm6MHAPYh1tWau2V/LLbELGDXpIxaCwrR2U1vevR3K7QOIBs OWW7M4beMEA1al67Od8J9njv50dbZPznzhoLK+xYzQiNI7LwqNL/M3e/tbGnbQ5YClFp DmZb+p+3fXTk2mWsf631Sf2UU35nmxDMuYhTdHlokuub51q6tOtNnp/6FHtq14TA4fVn 9qx/vKwALxU8oaUR1dzvooHOz9K3kNdBhKthRI+ucSr41FB6r6DoywOgYi885hxD4ycm WuWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719505752; x=1720110552; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dJ1Q8KLXbBvPejPRGDLYr/bC1HXbn69hKei2CLRD37M=; b=UaKnDyDvdoFeWc4rn9djx/I3/nhcIhQXRs3wKDILop6VjL0t8C4uwGAbS54HBxwH/o fMHry0p9GN2lVmeYf79+1qF1iOLK1Nmr5/KDavqhZQbtbD76Wn52DYnVdM90JGH2DZ+R EsdG+Bh7zhObtFOurZkIr38zOH+olrL0bwtpJBnOMU02AmsDfd+0OcpwaIhOtrRnL2i5 VSYN7FEFRYVx//Vq8zuYRRNp+PwXFUgp0iWDMxZ+ATaWJGccaJ3Ohw3x7We51frB4f72 ygNv2HMcqVJ6HYeu3IU5jhuKaXXeo/sH4EXDjhoLPdGRkOPAAkjAELOAcbBiSd/nZWGQ dz5g== X-Forwarded-Encrypted: i=1; AJvYcCWr1/WofkXos+kUiX+lg864CWlh7ObYUZOX6cllROol+Wf3EnMxbxUCnC2eTOm4IcPNjeLeEtHei7sImVUyh/FStt8+q1pKZ8MN7f1qYr8xugzIius= X-Gm-Message-State: AOJu0Yy1HPJzklTSi15ISxfs2z+gas449/YIGtHKdnMgUaGIAbCnz9Qa 4eTswXbFloZbAIkD8tMegoVOAUcb1glgO90LIdmIi8mu/B9fzxN+2aoyX3ttJg== X-Google-Smtp-Source: AGHT+IH3omPFHGGPxV7skDlndGJ9S2ClJpc2MTVM8kooRW3+wAtdW3I1lvFLR5DYyPEFczJdm/1zgg== X-Received: by 2002:a05:6a00:8c0d:b0:704:21c2:ae92 with SMTP id d2e1a72fcca58-706649a6b01mr16098893b3a.2.1719505752619; Thu, 27 Jun 2024 09:29:12 -0700 (PDT) Received: from [127.0.0.1] ([2401:4900:1f3e:18b0:e4e6:ed1:4c03:dcec]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706b4a58dbdsm1560739b3a.198.2024.06.27.09.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 09:29:12 -0700 (PDT) From: Ayush Singh Date: Thu, 27 Jun 2024 21:56:14 +0530 Subject: [PATCH v5 4/7] spi: Make of_find_spi_controller_by_node() available MIME-Version: 1.0 Message-Id: <20240627-mikrobus-scratch-spi-v5-4-9e6c148bf5f0@beagleboard.org> References: <20240627-mikrobus-scratch-spi-v5-0-9e6c148bf5f0@beagleboard.org> In-Reply-To: <20240627-mikrobus-scratch-spi-v5-0-9e6c148bf5f0@beagleboard.org> To: Mark Brown , Vaishnav M A , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Michael Walle , Andrew Lunn , jkridner@beagleboard.org, robertcnelson@beagleboard.org Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ayush Singh , Ayush Singh X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=7524; i=ayush@beagleboard.org; h=from:subject:message-id; bh=Q5G1t+bBT76IayXqh+ct3R0Xwy8Q7gI2MQZpDn6U4Tw=; b=owEBbQKS/ZANAwAIAQXO9ceJ5Vp0AcsmYgBmfZM39ts1Hz8di1m0tcwk+aba8fgbKzU2sWFfL dDxLIgR2WOJAjMEAAEIAB0WIQTfzBMe8k8tZW+lBNYFzvXHieVadAUCZn2TNwAKCRAFzvXHieVa dM2AD/93OV2TFiw4AdubUbDptdezyFQRUOt4vbb1yBRSJbVpqw0STGvI8pwCR6VRNxbd8NrQtX8 kuxOz63jbSsu6ob+kNVJjeH6wHJB4nelVuf7T3JhjBMv0qTdAc/75f2pklRQx6gJVYTNNmCgfHU 9Oid495FxS1D8AHZCTp7Ungr+CwIdqTTUyTsUaav9tvrSSoVFqgGDso3URiVi86Xyraa6+aGjbW pI2d03Iua9sZOaQ2fmjsoi0mh7+zJzfhDlYLHmRIR+pqPR07zgv4MXoKwPtG+I3mEdLOcBKi7wg ZO9d3j0hZFcSqOIpey4mmMrtfT1DpckFEb0smR3mb3p6cmSkgZ53z4ALiIxW+g9NtQhtlBRQT11 RpAaRWVoRq4jrrqLxrG5/QtA7+begIYPCKmueTZgN6blJ//gU93cOctHEU+MmtptAmPjhNtB9oT HCVLZ7vvlZcckDE8i/YP/VKepTVKrkgNxOw21DMYkZo+Pa7uWUjHH6CTtgmNFa0XmeRCEIUqM1v BDFmWAhz7lTAxCm2ZMuc/+NxaJCg4/3uhrd5zScJKtS8intFDwaAMKK3NbZKGxX0gZK3G91PHvV AB4xqkIebulFZvYJg9kevmPttx3R7mLHeVOMyWednW8m+kQhTGKx6Q5qPqa6RbkQ3o4LS27e5mk YOdbHuiZ3uUdyiw== X-Developer-Key: i=ayush@beagleboard.org; a=openpgp; fpr=DFCC131EF24F2D656FA504D605CEF5C789E55A74 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240627_092913_439776_D3D25F1A X-CRM114-Status: GOOD ( 19.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ayush Singh DONOTMERGE Externalize and export the symbol of_find_spi_controller_by_node() from the SPI core akin to how of_find_i2c_adapter_by_node() is already available. Also, move it under a CONFIG_OF. Signed-off-by: Ayush Singh --- drivers/spi/spi.c | 206 ++++++++++++++++++++++++------------------------ include/linux/spi/spi.h | 4 + 2 files changed, 108 insertions(+), 102 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 54cbe652a4df..565b2e2dd5b9 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2340,6 +2340,93 @@ void spi_flush_queue(struct spi_controller *ctlr) /*-------------------------------------------------------------------------*/ +static void spi_controller_release(struct device *dev) +{ + struct spi_controller *ctlr; + + ctlr = container_of(dev, struct spi_controller, dev); + kfree(ctlr); +} + +static struct class spi_master_class = { + .name = "spi_master", + .dev_release = spi_controller_release, + .dev_groups = spi_master_groups, +}; + +static ssize_t slave_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct spi_controller *ctlr = container_of(dev, struct spi_controller, + dev); + struct device *child; + + child = device_find_any_child(&ctlr->dev); + return sysfs_emit(buf, "%s\n", child ? to_spi_device(child)->modalias : NULL); +} + +static ssize_t slave_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct spi_controller *ctlr = container_of(dev, struct spi_controller, + dev); + struct spi_device *spi; + struct device *child; + char name[32]; + int rc; + + rc = sscanf(buf, "%31s", name); + if (rc != 1 || !name[0]) + return -EINVAL; + + child = device_find_any_child(&ctlr->dev); + if (child) { + /* Remove registered slave */ + device_unregister(child); + put_device(child); + } + + if (strcmp(name, "(null)")) { + /* Register new slave */ + spi = spi_alloc_device(ctlr); + if (!spi) + return -ENOMEM; + + strscpy(spi->modalias, name, sizeof(spi->modalias)); + + rc = spi_add_device(spi); + if (rc) { + spi_dev_put(spi); + return rc; + } + } + + return count; +} + +static DEVICE_ATTR_RW(slave); + +static struct attribute *spi_slave_attrs[] = { + &dev_attr_slave.attr, + NULL, +}; + +static const struct attribute_group spi_slave_group = { + .attrs = spi_slave_attrs, +}; + +static const struct attribute_group *spi_slave_groups[] = { + &spi_controller_statistics_group, + &spi_slave_group, + NULL, +}; + +static struct class spi_slave_class = { + .name = "spi_slave", + .dev_release = spi_controller_release, + .dev_groups = spi_slave_groups, +}; + #if defined(CONFIG_OF) static void of_spi_parse_dt_cs_delay(struct device_node *nc, struct spi_delay *delay, const char *prop) @@ -2549,6 +2636,23 @@ static void of_register_spi_devices(struct spi_controller *ctlr) } } } + +/* The spi controllers are not using spi_bus, so we find it with another way */ +struct spi_controller *of_find_spi_controller_by_node(struct device_node *node) +{ + struct device *dev; + + dev = class_find_device_by_of_node(&spi_master_class, node); + if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE)) + dev = class_find_device_by_of_node(&spi_slave_class, node); + if (!dev) + return NULL; + + /* Reference got in class_find_device */ + return container_of(dev, struct spi_controller, dev); +} +EXPORT_SYMBOL_GPL(of_find_spi_controller_by_node); + #else static void of_register_spi_devices(struct spi_controller *ctlr) { } #endif @@ -2917,20 +3021,6 @@ static void acpi_register_spi_devices(struct spi_controller *ctlr) static inline void acpi_register_spi_devices(struct spi_controller *ctlr) {} #endif /* CONFIG_ACPI */ -static void spi_controller_release(struct device *dev) -{ - struct spi_controller *ctlr; - - ctlr = container_of(dev, struct spi_controller, dev); - kfree(ctlr); -} - -static struct class spi_master_class = { - .name = "spi_master", - .dev_release = spi_controller_release, - .dev_groups = spi_master_groups, -}; - #ifdef CONFIG_SPI_SLAVE /** * spi_slave_abort - abort the ongoing transfer request on an SPI slave @@ -2958,79 +3048,6 @@ int spi_target_abort(struct spi_device *spi) return -ENOTSUPP; } EXPORT_SYMBOL_GPL(spi_target_abort); - -static ssize_t slave_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct spi_controller *ctlr = container_of(dev, struct spi_controller, - dev); - struct device *child; - - child = device_find_any_child(&ctlr->dev); - return sysfs_emit(buf, "%s\n", child ? to_spi_device(child)->modalias : NULL); -} - -static ssize_t slave_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct spi_controller *ctlr = container_of(dev, struct spi_controller, - dev); - struct spi_device *spi; - struct device *child; - char name[32]; - int rc; - - rc = sscanf(buf, "%31s", name); - if (rc != 1 || !name[0]) - return -EINVAL; - - child = device_find_any_child(&ctlr->dev); - if (child) { - /* Remove registered slave */ - device_unregister(child); - put_device(child); - } - - if (strcmp(name, "(null)")) { - /* Register new slave */ - spi = spi_alloc_device(ctlr); - if (!spi) - return -ENOMEM; - - strscpy(spi->modalias, name, sizeof(spi->modalias)); - - rc = spi_add_device(spi); - if (rc) { - spi_dev_put(spi); - return rc; - } - } - - return count; -} - -static DEVICE_ATTR_RW(slave); - -static struct attribute *spi_slave_attrs[] = { - &dev_attr_slave.attr, - NULL, -}; - -static const struct attribute_group spi_slave_group = { - .attrs = spi_slave_attrs, -}; - -static const struct attribute_group *spi_slave_groups[] = { - &spi_controller_statistics_group, - &spi_slave_group, - NULL, -}; - -static struct class spi_slave_class = { - .name = "spi_slave", - .dev_release = spi_controller_release, - .dev_groups = spi_slave_groups, -}; #else extern struct class spi_slave_class; /* dummy */ #endif @@ -4720,21 +4737,6 @@ static struct spi_device *of_find_spi_device_by_node(struct device_node *node) return dev ? to_spi_device(dev) : NULL; } -/* The spi controllers are not using spi_bus, so we find it with another way */ -static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node) -{ - struct device *dev; - - dev = class_find_device_by_of_node(&spi_master_class, node); - if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE)) - dev = class_find_device_by_of_node(&spi_slave_class, node); - if (!dev) - return NULL; - - /* Reference got in class_find_device */ - return container_of(dev, struct spi_controller, dev); -} - static int of_spi_notify(struct notifier_block *nb, unsigned long action, void *arg) { diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 85785bcd20c1..58e692226475 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -1684,4 +1684,8 @@ spi_transfer_is_last(struct spi_controller *ctlr, struct spi_transfer *xfer) return list_is_last(&xfer->transfer_list, &ctlr->cur_msg->transfers); } +#if IS_ENABLED(CONFIG_OF) +struct spi_controller *of_find_spi_controller_by_node(struct device_node *node); +#endif + #endif /* __LINUX_SPI_H */