Skip to contentSkip to conversation

mfd: Add Renesas Synchronization Management Unit (SMU) support

PATCH Superseded [email protected] 2 participants 15 messages Apr 7, 2021 – Apr 8, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 mfd: Add Renesas Synchronization Management Unit (SMU) support

From: Min Li <[email protected]>

Add support for ClockMatrix(TM) and 82P33xxx families of timing and synchronization devices. The access interface can be either SPI or I2C. Currently, it will create 2 types of MFD devices, which are to be used by the corresponding rsmu character device driver and the PTP hardware clock driver, respectively.

---
Change log
-rebase change to linux-next tree
-add log to inform driver loading success

 drivers/mfd/Kconfig              |  28 ++
 drivers/mfd/Makefile             |   3 +
 drivers/mfd/rsmu_i2c.c           | 349 +++++++++++++++++
 drivers/mfd/rsmu_private.h       |  32 ++
 drivers/mfd/rsmu_spi.c           | 376 ++++++++++++++++++
 include/linux/mfd/idt82p33_reg.h | 116 ++++++
 include/linux/mfd/idt8a340_reg.h | 817 +++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rsmu.h         |  54 +++
 8 files changed, 1775 insertions(+)
 create mode 100644 drivers/mfd/rsmu_i2c.c
 create mode 100644 drivers/mfd/rsmu_private.h
 create mode 100644 drivers/mfd/rsmu_spi.c
 create mode 100644 include/linux/mfd/idt82p33_reg.h
 create mode 100644 include/linux/mfd/idt8a340_reg.h
 create mode 100644 include/linux/mfd/rsmu.h
drivers/mfd/Kconfig +28 -0
index 21a131d..63b18b3 100644
@@ -2172,5 +2172,33 @@ config MFD_INTEL_M10_BMC
 	  additional drivers must be enabled in order to use the functionality
 	  of the device.
 
+config MFD_RSMU_I2C
+	tristate "Renesas Synchronization Management Unit with I2C"
+	depends on I2C && OF
+	depends on MFD_RSMU_SPI=n
+	select MFD_CORE
+	select REGMAP_I2C
+	help
+	  Support for the Renesas synchronization management unit, such as
+	  Clockmatrix and 82P33XXX series. This option supports I2C as
+	  the control interface.
+
+	  This driver provides common support for accessing the device,
+	  additional drivers must be enabled in order to use the functionality
+	  of the device.
+
+config MFD_RSMU_SPI
+	tristate "Renesas Synchronization Management Unit with SPI"
+	depends on SPI && OF
+	select MFD_CORE
+	help
+	  Support for the Renesas synchronization management unit, such as
+	  Clockmatrix and 82P33XXX series. This option supports SPI as
+	  the control interface.
+
+	  This driver provides common support for accessing the device,
+	  additional drivers must be enabled in order to use the functionality
+	  of the device.
+
 endmenu
 endif
drivers/mfd/Makefile +3 -0
index 4f6d2b8..4ab32ef 100644
@@ -271,3 +271,6 @@ obj-$(CONFIG_MFD_INTEL_M10_BMC)   += intel-m10-bmc.o
 
 obj-$(CONFIG_MFD_ATC260X)	+= atc260x-core.o
 obj-$(CONFIG_MFD_ATC260X_I2C)	+= atc260x-i2c.o
+
+obj-$(CONFIG_MFD_RSMU_I2C)	+= rsmu_i2c.o
+obj-$(CONFIG_MFD_RSMU_SPI)	+= rsmu_spi.o
drivers/mfd/rsmu_i2c.c new file +349 -0

349 lines not on this page · raw message

drivers/mfd/rsmu_private.h new file +32 -0
new file mode 100644
index 0000000..8841a24
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Multi-function driver for the IDT ClockMatrix(TM) and 82p33xxx families of
+ * timing and synchronization devices.
+ *
+ * Copyright (C) 2019 Integrated Device Technology, Inc., a Renesas Company.
+ */
+
+#ifndef __RSMU_MFD_PRIVATE_H
+#define __RSMU_MFD_PRIVATE_H
+
+#include <linux/mfd/rsmu.h>
+
+/* Maximum number of mfd devices */
+#define RSMU_MAX_MFD_DEV		4
+
+struct rsmu_dev {
+	struct device *dev;
+	void *client;
+	struct regmap *regmap;
+	struct mutex lock;
+	enum rsmu_type type;
+	u8 index;
+	u16 page;
+};
+
+enum rsmu_mfd_type {
+	RSMU_MFD_PTP		= 0,
+	RSMU_MFD_CDEV		= 1,
+	RSMU_MFD_NUM		= 2,
+};
+#endif /*  __LINUX_MFD_RSMU_H */
drivers/mfd/rsmu_spi.c new file +376 -0

376 lines not on this page · raw message

include/linux/mfd/idt82p33_reg.h new file +116 -0

116 lines not on this page · raw message

include/linux/mfd/idt8a340_reg.h new file +817 -0

817 lines not on this page · raw message

include/linux/mfd/rsmu.h new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 2/2 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

---
Change log
-rebase change to linux-next tree
-remove uncessary condition checks suggested by Greg -fix compile error for x86_64
-register device through misc_register suggested by Greg

 drivers/misc/Kconfig      |   9 ++
 drivers/misc/Makefile     |   2 +
 drivers/misc/rsmu_cdev.c  | 266 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/rsmu_cdev.h  |  74 +++++++++++++
 drivers/misc/rsmu_cm.c    | 166 +++++++++++++++++++++++++++++
 drivers/misc/rsmu_sabre.c | 133 +++++++++++++++++++++++
 include/uapi/linux/rsmu.h |  64 +++++++++++
 7 files changed, 714 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 f532c59..49b523a 100644
@@ -445,6 +445,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 99b6f15..21b8ed4 100644
@@ -56,3 +56,5 @@ obj-$(CONFIG_HABANA_AI)		+= habanalabs/
 obj-$(CONFIG_UACCE)		+= uacce/
 obj-$(CONFIG_XILINX_SDFEC)	+= xilinx_sdfec.o
 obj-$(CONFIG_HISI_HIKEY_USB)	+= hisi_hikey_usb.o
+rsmu-objs			:= rsmu_cdev.o rsmu_cm.o rsmu_sabre.o
+obj-$(CONFIG_RSMU)		+= rsmu.o
drivers/misc/rsmu_cdev.c new file +266 -0

266 lines not on this page · raw message

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

74 lines not on this page · raw message

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

166 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 +64 -0

64 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

Quoted 16 lines · On Wed, Apr 07, 2021 at 01:33:35PM -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

---
Change log

(quoted diff) +0 -1
-rebase change to linux-next tree

Review

Quoted 10 lines
(quoted diff) +0 -3
-remove uncessary condition checks suggested by Greg
-fix compile error for x86_64
-register device through misc_register suggested by Greg
 
 drivers/misc/Kconfig      |   9 ++
 drivers/misc/Makefile     |   2 +
 drivers/misc/rsmu_cdev.c  | 266 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/rsmu_cdev.h  |  74 +++++++++++++
 drivers/misc/rsmu_cm.c    | 166 +++++++++++++++++++++++++++++
 drivers/misc/rsmu_sabre.c | 133 +++++++++++++++++++++++

Why do you need 4 files here? Can't you do this all in one? There's no need for such a small driver to be split up, that just causes added complexity and makes things harder to review and understand.

Quoted 1 line
 include/uapi/linux/rsmu.h |  64 +++++++++++

Where are you documenting these new custom ioctls? And why do you even need them?

thanks,

greg k-h

author
#3 lore raw

RE: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

Quoted 5 lines

Why do you need 4 files here? Can't you do this all in one? There's no need for such a small driver to be split up, that just causes added complexity and makes things harder to review and understand.

We will add more functions and boards down the road. So the abstraction here is for future consideration

Quoted 5 lines
Quoted 1 line
 include/uapi/linux/rsmu.h |  64 +++++++++++

Where are you documenting these new custom ioctls? And why do you even need them?

Other than comments in the header itself, no additional documenting. Do you know if Linux has specific place to document custom ioctls? Renesas software needs to access these ioctls to provide GNSS assisted partial timing support. More specifically, RSMU_GET_STATE would tell us if a specific DPLL is locked to GNSS and RSMU_GET_FFO would tell us how much of frequency offset for the DPLL to lock to the GNSS.

Thanks

Min

maintainer
#4 lore raw

Re: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

Quoted 7 lines · Min Li
Quoted 5 lines

Why do you need 4 files here? Can't you do this all in one? There's no need for such a small driver to be split up, that just causes added complexity and makes things harder to review and understand.

We will add more functions and boards down the road. So the abstraction here is for future consideration

Do not add additional complexity today for stuff that you do not need today. Add it when you need it.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line
 include/uapi/linux/rsmu.h |  64 +++++++++++

Where are you documenting these new custom ioctls? And why do you even need them?

Other than comments in the header itself, no additional documenting. Do you know if Linux has specific place to document custom ioctls? Renesas software needs to access these ioctls to provide GNSS assisted partial timing support. More specifically, RSMU_GET_STATE would tell us if a specific DPLL is locked to GNSS and RSMU_GET_FFO would tell us how much of frequency offset for the DPLL to lock to the GNSS.

Please provide some sort of documentation and at the least, a pointer to the software that uses this so that we can see how it all ties together.

thanks,

greg k-h

author
#5 lore raw

RE: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

Quoted 4 lines

Please provide some sort of documentation and at the least, a pointer to the software that uses this so that we can see how it all ties together.

Hi Greg, I will withdraw this review for misc and focus on MFD part review for now. I will re-submit the misc review after mfd change is in.

Thanks

Min

maintainer
#6 lore raw

Re: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

In reply to [email protected]

drivers/misc/rsmu_cdev.c line 1

Quoted 4 lines · On Wed, Apr 07, 2021 at 01:33:35PM -0400, [email protected] wrote:
drivers/misc/rsmu_cdev.c new file +1 -0
@@ -0,0 +1,266 @@
+// SPDX-License-Identifier: GPL-2.0+

Do you really meen "+" here? (sorry, have to ask.)

drivers/misc/rsmu_cdev.c line 14

Quoted 13 lines
drivers/misc/rsmu_cdev.c new file +13 -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.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

You should not need this as it's a driver, so you should only use the dev_dbg() family of print message functions, no need for pr_*() calls.

Quoted 5 lines
drivers/misc/rsmu_cdev.c new file +5 -0
+
+#include <linux/cdev.h>
+#include <linux/device.h>
+#include <linux/fs.h>
+#include <linux/kernel.h>

drivers/misc/rsmu_cdev.c line 29

Quoted 10 lines
drivers/misc/rsmu_cdev.c new file +10 -0
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+#include <linux/mfd/rsmu.h>
+#include <uapi/linux/rsmu.h>
+#include "rsmu_cdev.h"
+
+#define DRIVER_NAME	"rsmu"

KBUILD_MODNAME instead? But you really only need this in one place, so no need for it at all, just use KBUILD_MODNAME here:

drivers/misc/rsmu_cdev.c line 239

Quoted 3 lines
drivers/misc/rsmu_cdev.c new file +3 -0
+static struct platform_driver rsmu_driver = {
+	.driver = {
+		.name = DRIVER_NAME,

Right there.

Quoted 14 lines
drivers/misc/rsmu_cdev.c new file +14 -0
+	},
+	.probe = rsmu_probe,
+	.remove =  rsmu_remove,
+	.id_table = rsmu_id_table,
+};
+
+static int __init rsmu_init(void)
+{
+	int err;
+
+	err = platform_driver_register(&rsmu_driver);
+	if (err < 0)
+		pr_err("Unabled to register %s platform driver", DRIVER_NAME);
+

drivers/misc/rsmu_cdev.c line 263

Quoted 10 lines
drivers/misc/rsmu_cdev.c new file +10 -0
+	return err;
+}
+
+static void __exit rsmu_exit(void)
+{
+	platform_driver_unregister(&rsmu_driver);
+}
+
+module_init(rsmu_init);
+module_exit(rsmu_exit);

module_platform_driver() instead?

thanks,

greg k-h

author
#7 lore raw

RE: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

Quoted 3 lines

Do you really meen "+" here? (sorry, have to ask.)

I don't know. All of our Linux kernel code has GPL-2.0+ and I just blindly inherit it.

Quoted 5 lines
Quoted 1 line

+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

You should not need this as it's a driver, so you should only use the dev_dbg() family of print message functions, no need for pr_*() calls.

I have one call to pr_err in rsmu_init

pr_err("Unabled to register %s platform driver", DRIVER_NAME);

maintainer
#8 lore raw

Re: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

Quoted 5 lines · Min Li
Quoted 3 lines

Do you really meen "+" here? (sorry, have to ask.)

I don't know. All of our Linux kernel code has GPL-2.0+ and I just blindly inherit it.

You should ask your managers :)

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

You should not need this as it's a driver, so you should only use the dev_dbg() family of print message functions, no need for pr_*() calls.

I have one call to pr_err in rsmu_init

pr_err("Unabled to register %s platform driver", DRIVER_NAME);

My recommendation in another email shows that the line above is not needed...

thanks,

greg k-h

maintainer
#9 lore raw

Re: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

In reply to [email protected]

drivers/misc/rsmu_cdev.c line 119

Quoted 11 lines · On Wed, Apr 07, 2021 at 01:33:35PM -0400, [email protected] wrote:
drivers/misc/rsmu_cdev.c new file +11 -0
+static int
+rsmu_open(struct inode *iptr, struct file *fptr)
+{
+	return 0;
+}
+
+static int
+rsmu_release(struct inode *iptr, struct file *fptr)
+{
+	return 0;
+}

If you do nothing in an open/release function, then there is no need to have them at all, you can remove them.

But this feels odd, how do you know what device you are using in your ioctl command?

thanks,

greg k-h

author
#10 lore raw

RE: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

Quoted 7 lines

If you do nothing in an open/release function, then there is no need to have them at all, you can remove them.

But this feels odd, how do you know what device you are using in your ioctl command?

The type of board is passed by mfd driver through platform data

rsmu->type = pdata->type;

maintainer
#11 lore raw

Re: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

In reply to [email protected]
Quoted 3 lines · On Wed, Apr 07, 2021 at 01:33:35PM -0400, [email protected] wrote:

+/**
+ * struct rsmu_cdev - Driver data for RSMU character device
+ * @name: rsmu device name

Why not use the miscdev name field?

Quoted 1 line

+ * @dev: pointer to platform device

So it's a parent? Why not make this a real platform_device pointer and not a device pointer?

Quoted 1 line

+ * @mfd: pointer to MFD device

You are properly handling the reference count of this and the platform device pointer when you save it off, right? Please check.

Quoted 2 lines

+ * @miscdev: character device handle
+ * @lock: mutex to protect operations from being interrupted

What operations?

Quoted 3 lines

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

Index into what?

drivers/misc/rsmu_cm.c line 6

Quoted 9 lines
drivers/misc/rsmu_cm.c new file +6 -0
@@ -0,0 +1,166 @@
+// 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.

Note, it's 2021 :)

thanks,

greg k-h

author
#12 lore raw

RE: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

Quoted 3 lines

Why not use the miscdev name field?

miscdev name field is just a char pointer and I need an static array to manipulate the name with index

Quoted 4 lines

So it's a parent? Why not make this a real platform_device pointer and not a device pointer?

It is not parent and mfd field is the parent

Quoted 3 lines

What operations?

The MFD driver will create 2 devices, one is for phc driver and another one is this driver. The lock is to make sure these 2 driver's operations are synchronized.

Quoted 3 lines

Index into what?

index is passed by mfd driver and will be used as part of device name such as "rsmu0"

maintainer
#13 lore raw

Re: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

Quoted 4 lines · Min Li
Quoted 3 lines

Why not use the miscdev name field?

miscdev name field is just a char pointer and I need an static array to manipulate the name with index

Why?

Quoted 5 lines
Quoted 3 lines

So it's a parent? Why not make this a real platform_device pointer and not a device pointer?

It is not parent and mfd field is the parent

Then why are you saving it off?

Quoted 5 lines
Quoted 2 lines

What operations?

The MFD driver will create 2 devices, one is for phc driver and another one is this driver. The lock is to make sure these 2 driver's operations are synchronized.

Ok, that should be documented a bit, it wasn't obvious :)

Quoted 4 lines
Quoted 2 lines

Index into what?

index is passed by mfd driver and will be used as part of device name such as "rsmu0"

So you can just look it up from the name?

thanks,

greg k-h

author
#14 lore raw

RE: [PATCH net-next v2 2/2] misc: Add Renesas Synchronization Management Unit (SMU) support

Quoted 3 lines

Why?

Because I need to manipulate name by adding the index to it during run time and use it as miscdev's name

	snprintf(rsmu->name, sizeof(rsmu->name), "rsmu%d", rsmu->index);
	rsmu->miscdev.name = rsmu->name;
Quoted 3 lines

Then why are you saving it off?

For things like dev_err(rsmu->dev, "Undefined RSMU IOCTL");

Quoted 3 lines

Ok, that should be documented a bit, it wasn't obvious :)

Will do for the next patch

Quoted 3 lines

So you can just look it up from the name?

name is based on this index in the first place