Skip to contentSkip to conversation

misc: Add Renesas Synchronization Management Unit (SMU) support

PATCH In review [email protected] 3 participants 8 messages Sep 2, 2021 – Sep 15, 2021 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: Add Renesas Synchronization Management Unit (SMU) support

From: Min Li <[email protected]>

This driver is developed for the IDT ClockMatrix(TM) and 82P33xxx families of timing and synchronization devices.It will be used by Renesas PTP Clock Manager for Linux (pcm4l) software to provide support to GNSS assisted partial timing support (APTS) and other networking timing functions.

Current version provides kernel API's to support the following functions -set combomode to enable SYNCE clock support
-read dpll's state to determine if the dpll is locked to the GNSS channel -read dpll's ffo (fractional frequency offset) in ppqt

---
 drivers/misc/Kconfig      |   9 ++
 drivers/misc/Makefile     |   2 +
 drivers/misc/rsmu_cdev.c  | 239 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/rsmu_cdev.h  |  77 +++++++++++++++
 drivers/misc/rsmu_cm.c    | 164 +++++++++++++++++++++++++++++++
 drivers/misc/rsmu_sabre.c | 133 ++++++++++++++++++++++++++
 include/uapi/linux/rsmu.h |  66 +++++++++++++
 7 files changed, 690 insertions(+)
 create mode 100644 drivers/misc/rsmu_cdev.c
 create mode 100644 drivers/misc/rsmu_cdev.h
 create mode 100644 drivers/misc/rsmu_cm.c
 create mode 100644 drivers/misc/rsmu_sabre.c
 create mode 100644 include/uapi/linux/rsmu.h
drivers/misc/Kconfig +9 -0
index 85ba901..6ed5a18 100644
@@ -469,6 +469,15 @@ config HISI_HIKEY_USB
 	  switching between the dual-role USB-C port and the USB-A host ports
 	  using only one USB controller.
 
+config RSMU
+	tristate "Renesas Synchronization Management Unit (SMU)"
+	help
+	  This option enables support for the IDT ClockMatrix(TM) and 82P33xxx
+	  families of timing and synchronization devices. It will be used by
+	  Renesas PTP Clock Manager for Linux (pcm4l) software to provide support
+	  for GNSS assisted partial timing support (APTS) and other networking
+	  timing functions.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +2 -0
index a086197..bde748d 100644
@@ -59,3 +59,5 @@ obj-$(CONFIG_UACCE)		+= uacce/
 obj-$(CONFIG_XILINX_SDFEC)	+= xilinx_sdfec.o
 obj-$(CONFIG_HISI_HIKEY_USB)	+= hisi_hikey_usb.o
 obj-$(CONFIG_HI6421V600_IRQ)	+= hi6421v600-irq.o
+rsmu-objs			:= rsmu_cdev.o rsmu_cm.o rsmu_sabre.o
+obj-$(CONFIG_RSMU)		+= rsmu.o
drivers/misc/rsmu_cdev.c new file +239 -0

239 lines not on this page · raw message

drivers/misc/rsmu_cdev.h new file +77 -0

77 lines not on this page · raw message

drivers/misc/rsmu_cm.c new file +164 -0

164 lines not on this page · raw message

drivers/misc/rsmu_sabre.c new file +133 -0

133 lines not on this page · raw message

include/uapi/linux/rsmu.h new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 12 lines · On Thu, Sep 02, 2021 at 02:45:53PM -0400, [email protected] wrote:

From: Min Li <[email protected]>

This driver is developed for the IDT ClockMatrix(TM) and 82P33xxx families of timing and synchronization devices.It will be used by Renesas PTP Clock Manager for Linux (pcm4l) software to provide support to GNSS assisted partial timing support (APTS) and other networking timing functions.

Current version provides kernel API's to support the following functions

(quoted diff) +0 -3
-set combomode to enable SYNCE clock support
-read dpll's state to determine if the dpll is locked to the GNSS channel
-read dpll's ffo (fractional frequency offset) in ppqt
Quoted 8 lines
---
 drivers/misc/Kconfig      |   9 ++
 drivers/misc/Makefile     |   2 +
 drivers/misc/rsmu_cdev.c  | 239 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/rsmu_cdev.h  |  77 +++++++++++++++
 drivers/misc/rsmu_cm.c    | 164 +++++++++++++++++++++++++++++++
 drivers/misc/rsmu_sabre.c | 133 ++++++++++++++++++++++++++

If you make this all one .c file, the .h file can go away and it will be much simpler in the end. And will get rid of the global symbols.

Quoted 14 lines
 include/uapi/linux/rsmu.h |  66 +++++++++++++
 7 files changed, 690 insertions(+)
 create mode 100644 drivers/misc/rsmu_cdev.c
 create mode 100644 drivers/misc/rsmu_cdev.h
 create mode 100644 drivers/misc/rsmu_cm.c
 create mode 100644 drivers/misc/rsmu_sabre.c
 create mode 100644 include/uapi/linux/rsmu.h
drivers/misc/Kconfig +0 -0
index 85ba901..6ed5a18 100644
@@ -469,6 +469,15 @@ config HISI_HIKEY_USB
 	  switching between the dual-role USB-C port and the USB-A host ports

drivers/misc/Kconfig config HISI_HIKEY_USB · line 479

Quoted 10 lines
drivers/misc/Kconfig +8 -0
 	  using only one USB controller.
 
+config RSMU
+	tristate "Renesas Synchronization Management Unit (SMU)"
+	help
+	  This option enables support for the IDT ClockMatrix(TM) and 82P33xxx
+	  families of timing and synchronization devices. It will be used by
+	  Renesas PTP Clock Manager for Linux (pcm4l) software to provide support
+	  for GNSS assisted partial timing support (APTS) and other networking
+	  timing functions.

No driver name listed?

Quoted 9 lines
drivers/misc/Kconfig +1 -0
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +0 -0
index a086197..bde748d 100644

drivers/misc/Makefile obj-$(CONFIG_UACCE) += uacce/ · line 63

Quoted 5 lines
drivers/misc/Makefile +2 -0
@@ -59,3 +59,5 @@ obj-$(CONFIG_UACCE)		+= uacce/
 obj-$(CONFIG_XILINX_SDFEC)	+= xilinx_sdfec.o
 obj-$(CONFIG_HISI_HIKEY_USB)	+= hisi_hikey_usb.o
 obj-$(CONFIG_HI6421V600_IRQ)	+= hi6421v600-irq.o
+rsmu-objs			:= rsmu_cdev.o rsmu_cm.o rsmu_sabre.o
+obj-$(CONFIG_RSMU)		+= rsmu.o

Just one .c file please.

drivers/misc/rsmu_cdev.c line 1

Quoted 7 lines
drivers/misc/rsmu_cdev.c new file +1 -0
new file mode 100644
index 0000000..8e856a6
@@ -0,0 +1,239 @@
+// SPDX-License-Identifier: GPL-2.0+

Are you sure about "+"? I have to ask.

drivers/misc/rsmu_cdev.c line 11

Quoted 10 lines
drivers/misc/rsmu_cdev.c new file +10 -0
+/*
+ * This driver is developed for the IDT ClockMatrix(TM) and 82P33xxx families
+ * of timing and synchronization devices. It will be used by Renesas PTP Clock
+ * Manager for Linux (pcm4l) software to provide support to GNSS assisted
+ * partial timing support (APTS) and other networking timing functions.
+ *
+ * Please note it must work with Renesas MFD driver to access device through
+ * I2C/SPI.
+ *
+ * Copyright (C) 2019 Integrated Device Technology, Inc., a Renesas Company.

Are you sure about that date?

Quoted 10 lines
drivers/misc/rsmu_cdev.c new file +10 -0
+ */
+
+#include <linux/cdev.h>
+#include <linux/device.h>
+#include <linux/fs.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>

drivers/misc/rsmu_cdev.c line 31

Quoted 10 lines
drivers/misc/rsmu_cdev.c new file +10 -0
+#include <linux/uaccess.h>
+#include <linux/mfd/rsmu.h>
+#include <uapi/linux/rsmu.h>
+#include "rsmu_cdev.h"
+
+static DEFINE_IDA(rsmu_cdev_map);
+
+static struct rsmu_ops *ops_array[] = {
+	[0] = &cm_ops,
+	[1] = &sabre_ops,

0 and 1 don't define much. Why are they needed?

No NULL at the end of the list?

Quoted 7 lines
drivers/misc/rsmu_cdev.c new file +7 -0
+};
+
+static int
+rsmu_set_combomode(struct rsmu_cdev *rsmu, void __user *arg)
+{
+	struct rsmu_ops *ops = rsmu->ops;
+	struct rsmu_combomode mode;

drivers/misc/rsmu_cdev.c line 48

Quoted 10 lines
drivers/misc/rsmu_cdev.c new file +10 -0
+	int err;
+
+	if (copy_from_user(&mode, arg, sizeof(mode)))
+		return -EFAULT;
+
+	if (ops->set_combomode == NULL)
+		return -EOPNOTSUPP;
+
+	mutex_lock(rsmu->lock);
+	err = ops->set_combomode(rsmu, mode.dpll, mode.mode);

No error checking of the userspace values?

Quoted 8 lines
drivers/misc/rsmu_cdev.c new file +8 -0
+	mutex_unlock(rsmu->lock);
+
+	return err;
+}
+
+static int
+rsmu_get_dpll_state(struct rsmu_cdev *rsmu, void __user *arg)
+{

drivers/misc/rsmu_cdev.c line 66

Quoted 10 lines
drivers/misc/rsmu_cdev.c new file +10 -0
+	struct rsmu_ops *ops = rsmu->ops;
+	struct rsmu_get_state state_request;
+	u8 state;
+	int err;
+
+	if (copy_from_user(&state_request, arg, sizeof(state_request)))
+		return -EFAULT;
+
+	if (ops->get_dpll_state == NULL)
+		return -EOPNOTSUPP;

No error checking of the userspace values?

Quoted 17 lines
drivers/misc/rsmu_cdev.c new file +17 -0
+
+	mutex_lock(rsmu->lock);
+	err = ops->get_dpll_state(rsmu, state_request.dpll, &state);
+	mutex_unlock(rsmu->lock);
+
+	state_request.state = state;
+	if (copy_to_user(arg, &state_request, sizeof(state_request)))
+		return -EFAULT;
+
+	return err;
+}
+
+static int
+rsmu_get_dpll_ffo(struct rsmu_cdev *rsmu, void __user *arg)
+{
+	struct rsmu_ops *ops = rsmu->ops;
+	struct rsmu_get_ffo ffo_request;

drivers/misc/rsmu_cdev.c line 93

Quoted 10 lines
drivers/misc/rsmu_cdev.c new file +10 -0
+	int err;
+
+	if (copy_from_user(&ffo_request, arg, sizeof(ffo_request)))
+		return -EFAULT;
+
+	if (ops->get_dpll_ffo == NULL)
+		return -EOPNOTSUPP;
+
+	mutex_lock(rsmu->lock);
+	err = ops->get_dpll_ffo(rsmu, ffo_request.dpll, &ffo_request);

Again, no checking of the userspace values?

Quoted 23 lines
drivers/misc/rsmu_cdev.c new file +23 -0
+	mutex_unlock(rsmu->lock);
+
+	if (copy_to_user(arg, &ffo_request, sizeof(ffo_request)))
+		return -EFAULT;
+
+	return err;
+}
+
+static struct rsmu_cdev *file2rsmu(struct file *file)
+{
+	return container_of(file->private_data, struct rsmu_cdev, miscdev);
+}
+
+static long
+rsmu_ioctl(struct file *fptr, unsigned int cmd, unsigned long data)
+{
+	struct rsmu_cdev *rsmu = file2rsmu(fptr);
+	void __user *arg = (void __user *)data;
+	int err = 0;
+
+	switch (cmd) {
+	case RSMU_SET_COMBOMODE:
+		err = rsmu_set_combomode(rsmu, arg);

drivers/misc/rsmu_cdev.c line 126

Quoted 10 lines
drivers/misc/rsmu_cdev.c new file +10 -0
+		break;
+	case RSMU_GET_STATE:
+		err = rsmu_get_dpll_state(rsmu, arg);
+		break;
+	case RSMU_GET_FFO:
+		err = rsmu_get_dpll_ffo(rsmu, arg);
+		break;
+	default:
+		/* Should not get here */
+		dev_err(rsmu->dev, "Undefined RSMU IOCTL");

Do not allow userspace to flood the kernel log with messages like this.

drivers/misc/rsmu_cdev.c line 127

Quoted 1 line
drivers/misc/rsmu_cdev.c new file +1 -0
+		err = -EINVAL;

Wrong value.

drivers/misc/rsmu_cdev.c line 132

Quoted 5 lines
drivers/misc/rsmu_cdev.c new file +5 -0
+		break;
+	}
+
+	return err;
+}

What userspace tool is making these ioctl calls?

drivers/misc/rsmu_cdev.c line 139

Quoted 7 lines
drivers/misc/rsmu_cdev.c new file +7 -0
+
+static long rsmu_compat_ioctl(struct file *fptr, unsigned int cmd,
+			      unsigned long data)
+{
+	return rsmu_ioctl(fptr, cmd, data);
+}
+

Why is the compat ioctl needed at all?

Quoted 56 lines
drivers/misc/rsmu_cdev.c new file +56 -0
+static const struct file_operations rsmu_fops = {
+	.owner = THIS_MODULE,
+	.unlocked_ioctl = rsmu_ioctl,
+	.compat_ioctl =	rsmu_compat_ioctl,
+};
+
+static int rsmu_init_ops(struct rsmu_cdev *rsmu)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(ops_array); i++)
+		if (ops_array[i]->type == rsmu->type)
+			break;
+
+	if (i == ARRAY_SIZE(ops_array))
+		return -EINVAL;
+
+	rsmu->ops = ops_array[i];
+	return 0;
+}
+
+static int
+rsmu_probe(struct platform_device *pdev)
+{
+	struct rsmu_ddata *ddata = dev_get_drvdata(pdev->dev.parent);
+	struct rsmu_cdev *rsmu;
+	int err;
+
+	rsmu = devm_kzalloc(&pdev->dev, sizeof(*rsmu), GFP_KERNEL);
+	if (!rsmu)
+		return -ENOMEM;
+
+	/* Save driver private data */
+	platform_set_drvdata(pdev, rsmu);
+
+	rsmu->dev = &pdev->dev;
+	rsmu->mfd = pdev->dev.parent;
+	rsmu->type = ddata->type;
+	rsmu->lock = &ddata->lock;
+	rsmu->regmap = ddata->regmap;
+	rsmu->index = ida_simple_get(&rsmu_cdev_map, 0, MINORMASK + 1, GFP_KERNEL);
+	if (rsmu->index < 0) {
+		dev_err(rsmu->dev, "Unable to get index %d\n", rsmu->index);
+		return rsmu->index;
+	}
+	snprintf(rsmu->name, sizeof(rsmu->name), "rsmu%d", rsmu->index);
+
+	err = rsmu_init_ops(rsmu);
+	if (err) {
+		dev_err(rsmu->dev, "Unknown SMU type %d", rsmu->type);
+		ida_simple_remove(&rsmu_cdev_map, rsmu->index);
+		return err;
+	}
+
+	/* Initialize and register the miscdev */
+	rsmu->miscdev.minor = MISC_DYNAMIC_MINOR;

drivers/misc/rsmu_cdev.c line 205

Quoted 10 lines
drivers/misc/rsmu_cdev.c new file +10 -0
+	rsmu->miscdev.fops = &rsmu_fops;
+	rsmu->miscdev.name = rsmu->name;
+	err = misc_register(&rsmu->miscdev);
+	if (err) {
+		dev_err(rsmu->dev, "Unable to register device\n");
+		ida_simple_remove(&rsmu_cdev_map, rsmu->index);
+		return -ENODEV;
+	}
+
+	dev_info(rsmu->dev, "Probe %s successful\n", rsmu->name);

When drivers work, they are totally quiet. Please remove.

Quoted 60 lines
drivers/misc/rsmu_cdev.c new file +34 -0
+	return 0;
+}
+
+static int
+rsmu_remove(struct platform_device *pdev)
+{
+	struct rsmu_cdev *rsmu = platform_get_drvdata(pdev);
+
+	misc_deregister(&rsmu->miscdev);
+	ida_simple_remove(&rsmu_cdev_map, rsmu->index);
+
+	return 0;
+}
+
+static const struct platform_device_id rsmu_id_table[] = {
+	{ "8a3400x-cdev", RSMU_CM},
+	{ "82p33x1x-cdev", RSMU_SABRE},
+	{}
+};
+MODULE_DEVICE_TABLE(platform, rsmu_id_table);
+
+static struct platform_driver rsmu_driver = {
+	.driver = {
+		.name = "rsmu-cdev",
+	},
+	.probe = rsmu_probe,
+	.remove =  rsmu_remove,
+	.id_table = rsmu_id_table,
+};
+
+module_platform_driver(rsmu_driver);
+
+MODULE_DESCRIPTION("Renesas SMU character device driver");
+MODULE_LICENSE("GPL");
drivers/misc/rsmu_cdev.h new file +20 -0
new file mode 100644
index 0000000..d67f71a
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * This driver is developed for the IDT ClockMatrix(TM) of
+ * timing and synchronization devices.
+ *
+ * Copyright (C) 2019 Integrated Device Technology, Inc., a Renesas Company.
+ */
+#ifndef __LINUX_RSMU_CDEV_H
+#define __LINUX_RSMU_CDEV_H
+
+#include <linux/miscdevice.h>
+#include <linux/regmap.h>
+
+struct rsmu_ops;
+
+/**
+ * struct rsmu_cdev - Driver data for RSMU character device
+ * @name: rsmu device name as rsmu[index]
+ * @dev: pointer to device
+ * @mfd: pointer to MFD device

drivers/misc/rsmu_cdev.h line 30

Quoted 10 lines
drivers/misc/rsmu_cdev.h new file +10 -0
+ * @miscdev: character device handle
+ * @regmap: I2C/SPI regmap handle
+ * @lock: mutex to protect operations from being interrupted
+ * @type: rsmu device type, passed through platform data
+ * @ops: rsmu device methods
+ * @index: rsmu device index
+ */
+struct rsmu_cdev {
+	char name[16];
+	struct device *dev;

What device is this pointing to?

drivers/misc/rsmu_cdev.h line 31

Quoted 1 line
drivers/misc/rsmu_cdev.h new file +1 -0
+	struct device *mfd;

What is this for?

drivers/misc/rsmu_cdev.h

Quoted 9 lines
drivers/misc/rsmu_cdev.h new file +9 -0
+	struct miscdevice miscdev;
+	struct regmap *regmap;
+	struct mutex *lock;
+	enum rsmu_type type;
+	struct rsmu_ops *ops;
+	int index;
+};
+
+/* Get dpll ffo (fractional frequency offset) in ppqt*/

Need a space at the end of your comment string.

drivers/misc/rsmu_cdev.h line 49

Quoted 9 lines
drivers/misc/rsmu_cdev.h new file +9 -0
+struct rsmu_get_ffo {
+	__u8 dpll;
+	__s64 ffo;
+};
+d
+/*
+ * RSMU IOCTL List
+ */
+#define RSMU_MAGIC '?'

Where did you get this value from?

Where did you reserve it?

drivers/misc/rsmu_cdev.h line 52

Quoted 3 lines
drivers/misc/rsmu_cdev.h new file +3 -0
+
+/**
+ * @Description

What is this format? It is not kernel-doc :(

drivers/misc/rsmu_cdev.h line 56

Quoted 4 lines
drivers/misc/rsmu_cdev.h new file +4 -0
+ * ioctl to set SMU combo mode.Combo mode provides physical layer frequency
+ * support from the Ethernet Equipment Clock to the PTP clock
+ *
+ * @Parameters

Same here and elsewhere in this file.

thanks,

greg k-h

author
#2 lore raw

Hi Greg

Thanks for the review

Quoted 11 lines
Quoted 7 lines
 drivers/misc/Kconfig      |   9 ++
 drivers/misc/Makefile     |   2 +
 drivers/misc/rsmu_cdev.c  | 239
++++++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/rsmu_cdev.h  |  77 +++++++++++++++
 drivers/misc/rsmu_cm.c    | 164 +++++++++++++++++++++++++++++++
 drivers/misc/rsmu_sabre.c | 133 ++++++++++++++++++++++++++

If you make this all one .c file, the .h file can go away and it will be much simpler in the end. And will get rid of the global symbols.

That is doable. But <linux/mfd/idt8a340_reg.h> and <linux/mfd/idt82p33_reg.h> have naming confliction. To make this change one file, I have to include both of them and therefore I have to change them to resolve Conflicts. Can I include this

Quoted 6 lines

drivers/misc/Kconfig config HISI_HIKEY_USB

Quoted 5 lines
drivers/misc/Kconfig +4 -0
+config RSMU
+	tristate "Renesas Synchronization Management Unit (SMU)"
+	help
+	  This option enables support for the IDT ClockMatrix(TM) and

82P33xxx

Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	  families of timing and synchronization devices. It will be used by
+	  Renesas PTP Clock Manager for Linux (pcm4l) software to provide

support

Review

Quoted 1 line
(quoted diff) +1 -0
+	  for GNSS assisted partial timing support (APTS) and other

networking

drivers/misc/Kconfig config HISI_HIKEY_USB · line 479

Quoted 1 line
drivers/misc/Kconfig +1 -0
+	  timing functions.

No driver name listed?

Sorry, what do you mean by driver name in this context?

Quoted 9 lines

drivers/misc/rsmu_cdev.c line 1

Quoted 7 lines
drivers/misc/rsmu_cdev.c new renamed from drivers/misc/rsmu_cdev.c +0 -0

file mode 100644 index 0000000..8e856a6

drivers/misc/rsmu_cdev.c new file +1 -0
@@ -0,0 +1,239 @@
+// SPDX-License-Identifier: GPL-2.0+

Are you sure about "+"? I have to ask.

All of our Linux kernel code have this license. I don't know what is the catch here.

Quoted 10 lines
Quoted 10 lines
drivers/misc/rsmu_cdev.c new file +10 -0
+
+/**
+ * struct rsmu_cdev - Driver data for RSMU character device
+ * @name: rsmu device name as rsmu[index]
+ * @dev: pointer to device
+ * @mfd: pointer to MFD device
+ * @miscdev: character device handle
+ * @regmap: I2C/SPI regmap handle
+ * @lock: mutex to protect operations from being interrupted
+ * @type: rsmu device type, passed through platform data
Quoted 8 lines

drivers/misc/rsmu_cdev.c line 17

Quoted 6 lines
drivers/misc/rsmu_cdev.c new file +6 -0
+ * @ops: rsmu device methods
+ * @index: rsmu device index
+ */
+struct rsmu_cdev {
+	char name[16];
+	struct device *dev;

What device is this pointing to?

It is the platform device from rsmu_probe(struct platform_device *pdev)

Quoted 4 lines

drivers/misc/rsmu_cdev.c line 18

Quoted 2 lines
drivers/misc/rsmu_cdev.c new file +1 -0
+	struct device *mfd;

What is this for?

It is the multi-functional device from driver/mfd/rsmu_core.c The mfd driver is responsible for spawn this platform device and spi/i2c bus access

Quoted 8 lines

drivers/misc/rsmu_cdev.c line 22

Quoted 4 lines
drivers/misc/rsmu_cdev.c new file +4 -0
+/*
+ * RSMU IOCTL List
+ */
+#define RSMU_MAGIC '?'

Where did you get this value from?

Where did you reserve it?

No I didn't reserve it. I checked other code and they all seem to use a random character

Quoted 7 lines

drivers/misc/rsmu_cdev.c line 25

Quoted 4 lines
drivers/misc/rsmu_cdev.c new file +3 -0
+
+/**
+ * @Description

What is this format? It is not kernel-doc :(

Quoted 7 lines

drivers/misc/rsmu_cdev.c line 30

Quoted 5 lines
drivers/misc/rsmu_cdev.c new file +5 -0
+ * ioctl to set SMU combo mode.Combo mode provides physical layer
+ frequency
+ * support from the Ethernet Equipment Clock to the PTP clock
+ *
+ * @Parameters

Same here and elsewhere in this file.

I was copying the format from xilinx_sdfec.h

Is there a place that tells me how to properly document ioctl or can you give me an code example?

Thanks

Min

maintainer
#3 lore raw
Quoted 12 lines · Min Li

Hi Greg

Thanks for the review

Quoted 8 lines
Quoted 7 lines
 drivers/misc/Kconfig      |   9 ++
 drivers/misc/Makefile     |   2 +
 drivers/misc/rsmu_cdev.c  | 239
++++++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/rsmu_cdev.h  |  77 +++++++++++++++
 drivers/misc/rsmu_cm.c    | 164 +++++++++++++++++++++++++++++++
 drivers/misc/rsmu_sabre.c | 133 ++++++++++++++++++++++++++
Quoted 7 lines
Quoted 3 lines

If you make this all one .c file, the .h file can go away and it will be much simpler in the end. And will get rid of the global symbols.

That is doable. But <linux/mfd/idt8a340_reg.h> and <linux/mfd/idt82p33_reg.h> have naming confliction. To make this change one file, I have to include both of them and therefore I have to change them to resolve Conflicts. Can I include this

Yes, that should be fine, do it as patch 1/X in a series.

Quoted 9 lines
Quoted 9 lines

drivers/misc/Kconfig config HISI_HIKEY_USB

Quoted 5 lines
drivers/misc/Kconfig +4 -0
+config RSMU
+	tristate "Renesas Synchronization Management Unit (SMU)"
+	help
+	  This option enables support for the IDT ClockMatrix(TM) and

82P33xxx

Review

Quoted 2 lines
(quoted diff) +2 -0
+	  families of timing and synchronization devices. It will be used by
+	  Renesas PTP Clock Manager for Linux (pcm4l) software to provide

support

Quoted 7 lines
Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	  for GNSS assisted partial timing support (APTS) and other

networking

drivers/misc/Kconfig config HISI_HIKEY_USB · line 479

Quoted 1 line
drivers/misc/Kconfig +1 -0
+	  timing functions.

No driver name listed?

Sorry, what do you mean by driver name in this context?

Most Kconfig help texts say the driver name if it is built as a module.

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
drivers/misc/rsmu_cdev.h new file +10 -0
+
+/**
+ * struct rsmu_cdev - Driver data for RSMU character device
+ * @name: rsmu device name as rsmu[index]
+ * @dev: pointer to device
+ * @mfd: pointer to MFD device
+ * @miscdev: character device handle
+ * @regmap: I2C/SPI regmap handle
+ * @lock: mutex to protect operations from being interrupted
+ * @type: rsmu device type, passed through platform data
Quoted 8 lines

drivers/misc/rsmu_cdev.h line 30

Quoted 6 lines

+ * @ops: rsmu device methods
+ * @index: rsmu device index
+ */

drivers/misc/rsmu_cdev.h new file +3 -0
+struct rsmu_cdev {
+	char name[16];
+	struct device *dev;

What device is this pointing to?

Quoted 1 line

It is the platform device from rsmu_probe(struct platform_device *pdev)

Then why not just point to the platform device?

Quoted 8 lines
Quoted 4 lines

drivers/misc/rsmu_cdev.h line 31

Quoted 2 lines
drivers/misc/rsmu_cdev.h new file +1 -0
+	struct device *mfd;

What is this for?

It is the multi-functional device from driver/mfd/rsmu_core.c The mfd driver is responsible for spawn this platform device and spi/i2c bus access

Why do you need to mess with that if you have a pointer to the platform device instead?

Quoted 10 lines
Quoted 8 lines

include/uapi/linux/rsmu.h line 36

Quoted 4 lines
include/uapi/linux/rsmu.h new file +4 -0
+/*
+ * RSMU IOCTL List
+ */
+#define RSMU_MAGIC '?'

Where did you get this value from?

Where did you reserve it?

No I didn't reserve it. I checked other code and they all seem to use a random character

That's not the best way to do this.

Why do you need ioctls at all anyway? What userspace tools will be accessing this driver? Do you have a link to where they are located at?

Quoted 12 lines
Quoted 12 lines

include/uapi/linux/rsmu.h line 39

Quoted 3 lines
include/uapi/linux/rsmu.h new file +3 -0
+
+/**
+ * @Description

What is this format? It is not kernel-doc :(

Quoted 5 lines

+ * ioctl to set SMU combo mode.Combo mode provides physical layer
+ frequency
+ * support from the Ethernet Equipment Clock to the PTP clock
+ *
+ * @Parameters

Quoted 5 lines
Quoted 1 line

Same here and elsewhere in this file.

I was copying the format from xilinx_sdfec.h

Is there a place that tells me how to properly document ioctl or can you give me an code example?

The kerneldoc format should be described in Documentation/ somewhere...

thanks,

greg k-h

#4 lore raw
Quoted 31 lines · Greg KH
Quoted 30 lines · Min Li

Hi Greg

Thanks for the review

Quoted 26 lines
Quoted 7 lines
  drivers/misc/Kconfig      |   9 ++
  drivers/misc/Makefile     |   2 +
  drivers/misc/rsmu_cdev.c  | 239
++++++++++++++++++++++++++++++++++++++++++++++
  drivers/misc/rsmu_cdev.h  |  77 +++++++++++++++
  drivers/misc/rsmu_cm.c    | 164 +++++++++++++++++++++++++++++++
  drivers/misc/rsmu_sabre.c | 133 ++++++++++++++++++++++++++

If you make this all one .c file, the .h file can go away and it will be much simpler in the end. And will get rid of the global symbols.

include/uapi/linux/rsmu.h line 39

Quoted 3 lines
include/uapi/linux/rsmu.h new file +3 -0
+
+/**
+ * @Description

What is this format? It is not kernel-doc :(

Quoted 5 lines

+ * ioctl to set SMU combo mode.Combo mode provides physical layer
+ frequency
+ * support from the Ethernet Equipment Clock to the PTP clock
+ *
+ * @Parameters

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Same here and elsewhere in this file.

I was copying the format from xilinx_sdfec.h

Is there a place that tells me how to properly document ioctl or can you give me an code example?

The kerneldoc format should be described in Documentation/ somewhere...

See Documentation/doc-guide/kernel-doc.rst.

Signature · 1 line
~Randy
author
#5 lore raw
In reply to Greg KH
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

include/uapi/linux/rsmu.h line 36

Quoted 4 lines
include/uapi/linux/rsmu.h new file +4 -0
+/*
+ * RSMU IOCTL List
+ */
+#define RSMU_MAGIC '?'

Where did you get this value from?

Where did you reserve it?

Quoted 7 lines
Quoted 2 lines

No I didn't reserve it. I checked other code and they all seem to use a random character

That's not the best way to do this.

Why do you need ioctls at all anyway? What userspace tools will be accessing this driver? Do you have a link to where they are located at?

Hi Greg

The userspace tool is called PCM4L (PTP Clock Manager for Linux) from Renesas

https://www.renesas.com/us/en/software-tool/ptp-clock-manager-linux

But the functions of this misc driver is not ptp related. It is meant for being called by pcm4l to support GNSS assisted partial timing support (APTS), which doesn't have abstracted/dedicated Linux Kernel API's. That is why I went for IOCTL in the first place.

Thanks

Min

maintainer
#6 lore raw
Quoted 19 lines · Min Li
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

include/uapi/linux/rsmu.h line 36

Quoted 4 lines
include/uapi/linux/rsmu.h new file +4 -0
+/*
+ * RSMU IOCTL List
+ */
+#define RSMU_MAGIC '?'

Where did you get this value from?

Where did you reserve it?

Quoted 7 lines
Quoted 2 lines

No I didn't reserve it. I checked other code and they all seem to use a random character

That's not the best way to do this.

Why do you need ioctls at all anyway? What userspace tools will be accessing this driver? Do you have a link to where they are located at?

Hi Greg

Quoted 7 lines

The userspace tool is called PCM4L (PTP Clock Manager for Linux) from Renesas

https://www.renesas.com/us/en/software-tool/ptp-clock-manager-linux

But the functions of this misc driver is not ptp related. It is meant for being called by pcm4l to support GNSS assisted partial timing support (APTS), which doesn't have abstracted/dedicated Linux Kernel API's. That is why I went for IOCTL in the first place.

Why not work on a real set of apis for this type of thing so that all devices of this type will work properly?

thanks,

greg k-h

author
#7 lore raw
Quoted 28 lines · Min Li
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

include/uapi/linux/rsmu.h line 36

Quoted 4 lines
include/uapi/linux/rsmu.h new file +4 -0
+/*
+ * RSMU IOCTL List
+ */
+#define RSMU_MAGIC '?'

Where did you get this value from?

Where did you reserve it?

Quoted 7 lines
Quoted 2 lines

No I didn't reserve it. I checked other code and they all seem to use a random character

That's not the best way to do this.

Why do you need ioctls at all anyway? What userspace tools will be accessing this driver? Do you have a link to where they are located at?

Hi Greg

Quoted 8 lines

The userspace tool is called PCM4L (PTP Clock Manager for Linux) from Renesas

https://www.renesas.com/us/en/software-tool/ptp-clock-manager-linux

But the functions of this misc driver is not ptp related. It is meant for being called by pcm4l to support GNSS assisted partial timing support (APTS), which doesn't have abstracted/dedicated Linux Kernel

Quoted 8 lines

API's. That is why I went for IOCTL in the first place.

Why not work on a real set of apis for this type of thing so that all devices of this type will work properly?

thanks,

greg k-h

Hi Greg

That plan is on our roadmap. On the other hand, this is a new area that different company has its own hw/sw solution and it takes time to abstract functions to kernel. Also, our APTS first release was already out. Right now we are actively developing another release that we will try out best to come up with better solution.