Received: by 2002:ab2:7444:0:b0:1ef:eae8:a797 with SMTP id f4csp30526lqn; Fri, 15 Mar 2024 11:50:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWmw5C97rkCzNMVf2D/Ann3fdFBH6rPa8s3RWjrSM2HxQvZQeMw2hVKmsW1ti2L90JWRcon2FaUmXvago05JTtJKd/fPbHUWduVkct9mg== X-Google-Smtp-Source: AGHT+IF4jZpY6qdo/QFw/Mm7FON64pBZ7luH7lArY5NS3qiF3I1rvlFFxhUkEy9Y/DOnnOGgMiFZ X-Received: by 2002:a05:6a21:670b:b0:1a3:4794:547b with SMTP id wh11-20020a056a21670b00b001a34794547bmr4820926pzb.7.1710528634891; Fri, 15 Mar 2024 11:50:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710528634; cv=pass; d=google.com; s=arc-20160816; b=DOGld2X5gLV8/aBTtyEPET1klGj2Ukvn+QKXHO73l77YE/0mCCvNaF58rjN0xnrL8W JsBB0od5hr5uN3Nzq2oClqsxeggQRyGwiP1byk7hGNr2P5vLFHIxuLVa74O4PGB8tc5g qu5WNjLJ93qmvtgp2mPXbw03AYKd17lgZ7sHQbb4g406cdtk2bTuA85jTvaFX6qmZVKj VQ7zfb/34cBJd+AaP1Mclx7749jvbI3PH6aSnGmEczKst1XXHVvVxZnZA/7tCQhbiCMP MLgY///PgkCe9kFY7QItYEKKAc0hYra3/g07g7A4XNqbQmJmc9pY90dHmYuVY5KF20Rw xlGA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zcNxWNH5QzToDPbBOtHvsfB896+SEBZGOEHaE/ifDKQ=; fh=xxhT2cQIu9dCwuo8IzcWRuQa+xfSLh2RcqIKC/UbYnk=; b=ksmg075dpIBBdYCOv2NZpxa78GNQHMSb9IYfYxe2SQcaBhYcTAhKxIon7Cfrv5pPbs tQS40PNczR7fQoKGUg3g3yGvbex+frjideIcHpLp0kT8VXP8oZVI1+NRQMEs3RhUdcwr ZbtJU6RzVuxPCrM7pqTtpaS6xuCGoL3y96I2f8m9rJ/Km+r6yMhZmZQW8fsPVOrHvIBh 419GA945/gdCUbfmR1FBE/9K2vp+cKxeGmV1VAcyxuPFO4uhon3AyB6SwtgADsmlsEuR TdzSZ8nSAgj9g0NZguDbNsqHto/lmaTpVvzYOdZsTVeqkkFesYSK72cPGDz2hfC/i7Bf MmBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kSGypwHG; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-104807-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104807-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ei44-20020a056a0080ec00b006e700af1fefsi866281pfb.95.2024.03.15.11.50.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 11:50:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104807-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kSGypwHG; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-104807-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104807-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 87CB72851A5 for ; Fri, 15 Mar 2024 18:50:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B781524DC; Fri, 15 Mar 2024 18:49:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kSGypwHG" Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5044524C3; Fri, 15 Mar 2024 18:49:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710528596; cv=none; b=oWGZrtVrgv8nqMnJQJ7BJnkPLv/Wm02VyerG/Gwm3H7KugXx99aoYfZNrKdvYbzvmevsFymk1FIhdXyRLXb+GNBtQSWwvsy2Xr7zBWbdf1p+4iUzRVwmJTkTb0L5b9AcBzcCWvagdmIYejde8sB+Xso551bXQRNQLhIWoS76hHk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710528596; c=relaxed/simple; bh=qME2ktJXCyLreJLQ5k66cQS2skuPHFzR24V3ciu5bhQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kwEBZIlNAS4So7KCrKpLmQwLR+eoVZTngIH59pKaarPgi9u5GNuK94HsD2vTp1Ji+W/RH4hDtf4ZjlcXDz6pT9MIRoZISmveFcEsDX40E5BndpRB6owHProfNH/8ghEOEAT4Wjsj9X6PWa3aggYtVLPR056qlQWwV3PW8rOLRDU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kSGypwHG; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-5d8b276979aso1706414a12.2; Fri, 15 Mar 2024 11:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710528594; x=1711133394; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zcNxWNH5QzToDPbBOtHvsfB896+SEBZGOEHaE/ifDKQ=; b=kSGypwHGOS6xFv6Gi8VTR3reSR/0G1JIMS4jJKkfmXPGBAra+PGrsv1uEgdZA65k3c D5blYL+MMmcTx+dIE22VDKhxvnUK0NpUOgdZRkW8tR9dWNgLw2xxl5mqPLOyoUUyACnP 51+VN05+cgC60lTzYFIDxDFago3qXgvgWjk4eyLkdrzzq5g22Z+lW7doA7StfMQ9nuWe loP2aARZG9DEs6Vv0uorkVhMniQmfa5xFcW/dB+DAwIcxdtkhnEwddQq42jSDJDEvluA mzWURBRh7EmTyRLhB4xoJa1ICluQnrBuyRdJ43S2s0ssCQNA0WO/BoR03V4Tcm6mERG9 S83w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710528594; x=1711133394; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zcNxWNH5QzToDPbBOtHvsfB896+SEBZGOEHaE/ifDKQ=; b=EpQx0FiAWbLj0JrMTEI28Xu+6AjD0fVhD9z2qifEnwm7yUZEfw/anz7f3N57tKJPZv w3wJed57EeHrXTsK2Rch9WFANex4HmVTqgaxPoHN3t4Umil7HzzCen1GmRP/4mRJGcyp +MEls6+zQwLCfi3phVvPBSmU9BvNubK9+cuE5Q+zABPxrjaoxPAum5hjCWfEZpENL9EB 7Uq5RwBPK2eGqYJZNo7P12/sZs5HATYhoBi3f2ejU6jdDDEWJfHowFAX6LGL86YDP+gO xaqSd0N7X2Nrm/lnFGQIAxLu7UFLDfhMG4LzXc86lVQhonYt6zSncVrNgEnu8x+OocFy maVg== X-Forwarded-Encrypted: i=1; AJvYcCVDpNQwl3Ts3mJt7mF5zUDImU9kbXP1dBx8/LgBykNtljBR61U8waWfMo00qAaL48VzzeoL7r0O5z3tytUUg9lY2ULUlIqRTljPWo0vNQVSKEYAXjuFX0/Trm6x0q+vNTl+3sMg+8YPt1bQxOQEsmxjgAotpWegzNyLRCphtdkosohXnA== X-Gm-Message-State: AOJu0YwzGIcAKED75aAonD8G+N4oEPwUXSTqhb62lQydF70/N9u81c9T fcd76eOv/xJvVE5zjkc8luQv7chIy95Gab/kgwGSlGs+IhxG/e10MuyjIxDytQ6MPA== X-Received: by 2002:a05:6a20:9f95:b0:1a3:51fc:a62d with SMTP id mm21-20020a056a209f9500b001a351fca62dmr2182876pzb.26.1710528593624; Fri, 15 Mar 2024 11:49:53 -0700 (PDT) Received: from toolbox.iitism.net ([103.15.228.94]) by smtp.gmail.com with ESMTPSA id f17-20020a056a0022d100b006e6cc998be8sm3580784pfj.207.2024.03.15.11.49.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 11:49:53 -0700 (PDT) From: Ayush Singh To: linux-kernel@vger.kernel.org Cc: Ayush Singh , jkridner@beagleboard.org, robertcnelson@beagleboard.org, Vaishnav M A , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Liam Girdwood , Mark Brown , Jiri Slaby , Johan Hovold , Alex Elder , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org, linux-serial@vger.kernel.org, greybus-dev@lists.linaro.org Subject: [PATCH v3 3/8] spi: Make of_find_spi_controller_by_node() available Date: Sat, 16 Mar 2024 00:19:01 +0530 Message-ID: <20240315184908.500352-4-ayushdevel1325@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240315184908.500352-1-ayushdevel1325@gmail.com> References: <20240315184908.500352-1-ayushdevel1325@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This externalizes and exports the symbol of_find_spi_controller_by_node() from the SPI core akin to how of_find_i2c_adapter_by_node() is already available. As we will need this also for non-dynamic OF setups, we move it under a CONFIG_OF check. 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 ba4d3fde2054..9ec507d92f80 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2320,6 +2320,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) @@ -2543,6 +2630,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 @@ -2942,20 +3046,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 @@ -2983,79 +3073,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 @@ -4749,21 +4766,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 e400d454b3f0..f6fb7bad9a90 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 */ -- 2.44.0