All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eddie James <eajames@linux.ibm.com>
To: linux-fsi@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org, alistair@popple.id.au,
	joel@jms.id.au, jk@ozlabs.org,
	Eddie James <eajames@linux.ibm.com>
Subject: [PATCH] fsi: Add aliased device numbering
Date: Thu, 26 Jan 2023 16:38:50 -0600	[thread overview]
Message-ID: <20230126223850.901302-1-eajames@linux.ibm.com> (raw)

The I2C and SPI subsystems can use an aliased name to number the device.
Add similar support to the FSI subsystem for any device type.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
 drivers/fsi/fsi-core.c    | 31 +++++++++++++++++++++++++++++++
 drivers/fsi/fsi-sbefifo.c |  5 ++---
 drivers/fsi/fsi-scom.c    |  3 ++-
 include/linux/fsi.h       |  1 +
 4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index 694e80c06665..c3c139c31341 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -971,9 +971,40 @@ static int __fsi_get_new_minor(struct fsi_slave *slave, enum fsi_dev_type type,
 	return 0;
 }
 
+static const char *const fsi_dev_type_names[] = {
+	"cfam",
+	"sbefifo",
+	"scom",
+	"occ",
+};
+
+const char *fsi_get_dev_type_name(enum fsi_dev_type type)
+{
+	return fsi_dev_type_names[type];
+}
+EXPORT_SYMBOL_GPL(fsi_get_dev_type_name);
+
 int fsi_get_new_minor(struct fsi_device *fdev, enum fsi_dev_type type,
 		      dev_t *out_dev, int *out_index)
 {
+	if (fdev->dev.of_node) {
+		int aid = of_alias_get_id(fdev->dev.of_node, fsi_dev_type_names[type]);
+
+		if (aid >= 0) {
+			int id = (aid << 4) | type;
+
+			id = ida_simple_get(&fsi_minor_ida, id, id + 1, GFP_KERNEL);
+			if (id >= 0) {
+				*out_index = aid;
+				*out_dev = fsi_base_dev + id;
+				return 0;
+			}
+
+			if (id != -ENOSPC)
+				return id;
+		}
+	}
+
 	return __fsi_get_new_minor(fdev->slave, type, out_dev, out_index);
 }
 EXPORT_SYMBOL_GPL(fsi_get_new_minor);
diff --git a/drivers/fsi/fsi-sbefifo.c b/drivers/fsi/fsi-sbefifo.c
index 9912b7a6a4b9..c79396ba982e 100644
--- a/drivers/fsi/fsi-sbefifo.c
+++ b/drivers/fsi/fsi-sbefifo.c
@@ -39,7 +39,6 @@
  * the self boot engine on POWER processors.
  */
 
-#define DEVICE_NAME		"sbefifo"
 #define FSI_ENGID_SBE		0x22
 
 /*
@@ -1046,7 +1045,7 @@ static int sbefifo_probe(struct device *dev)
 	if (rc)
 		goto err;
 
-	dev_set_name(&sbefifo->dev, "sbefifo%d", didx);
+	dev_set_name(&sbefifo->dev, "%s%d", fsi_get_dev_type_name(fsi_dev_sbefifo), didx);
 	cdev_init(&sbefifo->cdev, &sbefifo_fops);
 	rc = cdev_device_add(&sbefifo->cdev, &sbefifo->dev);
 	if (rc) {
@@ -1117,7 +1116,7 @@ static const struct fsi_device_id sbefifo_ids[] = {
 static struct fsi_driver sbefifo_drv = {
 	.id_table = sbefifo_ids,
 	.drv = {
-		.name = DEVICE_NAME,
+		.name = "sbefifo",
 		.bus = &fsi_bus_type,
 		.probe = sbefifo_probe,
 		.remove = sbefifo_remove,
diff --git a/drivers/fsi/fsi-scom.c b/drivers/fsi/fsi-scom.c
index bcb756dc9866..ee2c70906d06 100644
--- a/drivers/fsi/fsi-scom.c
+++ b/drivers/fsi/fsi-scom.c
@@ -556,7 +556,8 @@ static int scom_probe(struct device *dev)
 	if (rc)
 		goto err;
 
-	dev_set_name(&scom->dev, "scom%d", didx);
+	dev_set_name(&scom->dev, "%s%d", fsi_get_dev_type_name(fsi_dev_scom),
+		     didx);
 	cdev_init(&scom->cdev, &scom_fops);
 	rc = cdev_device_add(&scom->cdev, &scom->dev);
 	if (rc) {
diff --git a/include/linux/fsi.h b/include/linux/fsi.h
index 3df8c54868df..a6c6c57e146f 100644
--- a/include/linux/fsi.h
+++ b/include/linux/fsi.h
@@ -78,6 +78,7 @@ enum fsi_dev_type {
 	fsi_dev_occ
 };
 
+const char *fsi_get_dev_type_name(enum fsi_dev_type type);
 extern int fsi_get_new_minor(struct fsi_device *fdev, enum fsi_dev_type type,
 			     dev_t *out_dev, int *out_index);
 extern void fsi_free_minor(dev_t dev);
-- 
2.31.1


             reply	other threads:[~2023-01-26 22:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-26 22:38 Eddie James [this message]
2023-01-27  1:03 ` [PATCH] fsi: Add aliased device numbering Jeremy Kerr
2023-01-27 14:40   ` Eddie James

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230126223850.901302-1-eajames@linux.ibm.com \
    --to=eajames@linux.ibm.com \
    --cc=alistair@popple.id.au \
    --cc=jk@ozlabs.org \
    --cc=joel@jms.id.au \
    --cc=linux-fsi@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.