regmap: add generic indirect regmap support
Subsystems (2)
PATCH 1/1 regmap: add generic indirect regmap support
From: Matthew Gerlach <[email protected]>
This patch adds support for regmap APIs that are intended to be used by the drivers of some devices which support generic indirect register access, for example PMCI (Platform Management Control Interface) device, HSSI (High Speed Serial Interface) device in FPGA.
--- drivers/base/regmap/Kconfig | 3 + drivers/base/regmap/Makefile | 1 + .../base/regmap/regmap-indirect-register.c | 133 ++++++++++++++++++ include/linux/regmap.h | 12 ++ 4 files changed, 149 insertions(+) create mode 100644 drivers/base/regmap/regmap-indirect-register.c
drivers/base/regmap/Kconfig +3 -0
@@ -65,3 +65,6 @@ config REGMAP_I3C config REGMAP_SPI_AVMM tristate depends on SPI + +config REGMAP_INDIRECT_REGISTER + tristate
drivers/base/regmap/Makefile +1 -0
@@ -20,3 +20,4 @@ obj-$(CONFIG_REGMAP_SCCB) += regmap-sccb.o obj-$(CONFIG_REGMAP_I3C) += regmap-i3c.o obj-$(CONFIG_REGMAP_SPI_AVMM) += regmap-spi-avmm.o obj-$(CONFIG_REGMAP_MDIO) += regmap-mdio.o +obj-$(CONFIG_REGMAP_INDIRECT_REGISTER) += regmap-indirect-register.o
drivers/base/regmap/regmap-indirect-register.c new file +133 -0
133 lines not on this page · raw message
include/linux/regmap.h +12 -0
@@ -670,6 +670,18 @@ struct regmap *__devm_regmap_init_spi_avmm(struct spi_device *spi,const struct regmap_config *config, struct lock_class_key *lock_key, const char *lock_name); +/** +* devm_regmap_init_indirect_register - create a regmap for indirect register access +* @dev: device creating the regmap +* @base: __iomem point to base of memory with mailbox +* @cfg: regmap_config describing interface +* +* Return: 0 on success, negative error code otherwise. +*/ +struct regmap *devm_regmap_init_indirect_register (struct device *dev, +void __iomem *base, +struct regmap_config *cfg); +/* * Wrapper for regmap_init macros to include a unique lockdep key and name * for each call. No-op if CONFIG_LOCKDEP is not set.
Signature · 1 line
2.26.2
Greg KH
maintainerQuoted 9 lines · Tianfei Zhang
From: Matthew Gerlach <[email protected]>
This patch adds support for regmap APIs that are intended to be used by the drivers of some devices which support generic indirect register access, for example PMCI (Platform Management Control Interface) device, HSSI (High Speed Serial Interface) device in FPGA.
Signed-off-by Matthew Gerlach <[email protected]>Signed-off-by Tianfei Zhang <[email protected]>
Quoted 7 lines
--- drivers/base/regmap/Kconfig | 3 + drivers/base/regmap/Makefile | 1 + .../base/regmap/regmap-indirect-register.c | 133 ++++++++++++++++++ include/linux/regmap.h | 12 ++ 4 files changed, 149 insertions(+) create mode 100644 drivers/base/regmap/regmap-indirect-register.c
Don't we need users of these before we can take them?
thanks,
greg k-h
Quoted 30 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Tuesday, June 7, 2022 12:50 PM
To: Zhang, Tianfei <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Wu, Hao <[email protected]>; [email protected]; Xu, Yilun <[email protected]>; Weight, Russell H <[email protected]>; Matthew Gerlach <[email protected]>
Subject: Re: [PATCH v1] regmap: add generic indirect regmap supportQuoted 9 lines · Tianfei Zhang
From: Matthew Gerlach <[email protected]>
This patch adds support for regmap APIs that are intended to be used by the drivers of some devices which support generic indirect register access, for example PMCI (Platform Management Control Interface) device, HSSI (High Speed Serial Interface) device in FPGA.
Signed-off-by Matthew Gerlach <[email protected]>Signed-off-by Tianfei Zhang <[email protected]>Quoted 7 lines
--- drivers/base/regmap/Kconfig | 3 + drivers/base/regmap/Makefile | 1 + .../base/regmap/regmap-indirect-register.c | 133 ++++++++++++++++++ include/linux/regmap.h | 12 ++ 4 files changed, 149 insertions(+) create mode 100644 drivers/base/regmap/regmap-indirect-register.c
Quoted 1 line
Don't we need users of these before we can take them?
One of user is the PMCI (Platform Management Control Interface) driver of Intel FPGA PAC Card, PMCI device was connected to card BMC which provided telemetry and mailbox functionalities.
The PMCI driver is under review now:
https://lore.kernel.org/all/[email protected]/
Mark Brown
maintainerQuoted 6 lines · Tianfei Zhang
From: Matthew Gerlach <[email protected]>
This patch adds support for regmap APIs that are intended to be used by the drivers of some devices which support generic indirect register access, for example PMCI (Platform Management Control Interface) device, HSSI (High Speed Serial Interface) device in FPGA.
What is "generic indirect register access"? I'm not clear what this is intended to support...
drivers/base/regmap/regmap-indirect-register.c line 37
Quoted 10 lines
drivers/base/regmap/regmap-indirect-register.c new file +10
-0+static int indirect_bus_clr_cmd (struct indirect_ctx *ctx) +{ +unsigned int cmd; +int ret; + +writel (0 , ctx->base +INDIRECT_CMD_OFF ); + ret =readl_poll_timeout ((ctx->base +INDIRECT_CMD_OFF ), cmd, + (!cmd),INDIRECT_INT_US ,INDIRECT_TIMEOUT_US ); +if (ret) +dev_err (ctx->dev,"%s timed out on clearing cmd 0x%xn" , __func__, cmd);
...and this doesn't look particularly generic, it looks like it's for some particular controller/bridge?
Quoted 10 lines · Mark Brown
Quoted 6 lines · Tianfei Zhang
From: Matthew Gerlach <[email protected]>
This patch adds support for regmap APIs that are intended to be used by the drivers of some devices which support generic indirect register access, for example PMCI (Platform Management Control Interface) device, HSSI (High Speed Serial Interface) device in FPGA.
What is "generic indirect register access"? I'm not clear what this is intended to support...
"indirect register access" is a RTL design pattern we use in FPGAs frequently. The design pattern involves a small number of registers plus a little handshake code to access various register spaces inside the FPGA fabric. The design pattern is "generic" in the sense that the same small number of registers and handshake can be used with many different IP components in the FPGA. Historically, the bit definitions and handshaking was slightly different for each IP component. This is an attempt at a consistent usage across IP components.
Would a different name help?
Quoted 15 lines
drivers/base/regmap/regmap-indirect-register.c line 37
Quoted 11 lines
drivers/base/regmap/regmap-indirect-register.c new file +10
-0+static int indirect_bus_clr_cmd (struct indirect_ctx *ctx) +{ +unsigned int cmd; +int ret; + +writel (0 , ctx->base +INDIRECT_CMD_OFF ); + ret =readl_poll_timeout ((ctx->base +INDIRECT_CMD_OFF ), cmd, + (!cmd),INDIRECT_INT_US ,INDIRECT_TIMEOUT_US ); +if (ret) +dev_err (ctx->dev,"%s timed out on clearing cmd 0x%xn" , __func__, cmd);...and this doesn't look particularly generic, it looks like it's for some particular controller/bridge?
Mark Brown
maintainerQuoted 21 lines · On Tue, Jun 07, 2022 at 05:27:38PM -0700, [email protected] wrote:
Quoted 10 lines · Mark Brown
Quoted 6 lines · Tianfei Zhang
From: Matthew Gerlach <[email protected]>
This patch adds support for regmap APIs that are intended to be used by the drivers of some devices which support generic indirect register access, for example PMCI (Platform Management Control Interface) device, HSSI (High Speed Serial Interface) device in FPGA.
What is "generic indirect register access"? I'm not clear what this is intended to support...
"indirect register access" is a RTL design pattern we use in FPGAs frequently. The design pattern involves a small number of registers plus a little handshake code to access various register spaces inside the FPGA fabric. The design pattern is "generic" in the sense that the same small number of registers and handshake can be used with many different IP components in the FPGA. Historically, the bit definitions and handshaking was slightly different for each IP component. This is an attempt at a consistent usage across IP components.
Quoted 1 line
Would a different name help?
This wouldn't address the major problem which is...
Quoted 8 lines
Quoted 8 lines
drivers/base/regmap/regmap-indirect-register.c line 37
Quoted 5 lines
drivers/base/regmap/regmap-indirect-register.c new file +5
-0+writel (0 , ctx->base +INDIRECT_CMD_OFF ); + ret =readl_poll_timeout ((ctx->base +INDIRECT_CMD_OFF ), cmd, + (!cmd),INDIRECT_INT_US ,INDIRECT_TIMEOUT_US ); +if (ret) +dev_err (ctx->dev,"%s timed out on clearing cmd 0x%xn" , __func__, cmd);...and this doesn't look particularly generic, it looks like it's for some particular controller/bridge?
...that this appears to be entirely specific to some particular device, it's got things like hard coded register addresses and timeouts which mean it can't be reused.
Quoted 50 lines
-----Original Message-----
From: Mark Brown <[email protected]>
Sent: Wednesday, June 8, 2022 6:43 PM
To: [email protected]
Cc: Zhang, Tianfei <[email protected]>; [email protected]; [email protected]; [email protected]; Wu, Hao <[email protected]>; [email protected]; Xu, Yilun <[email protected]>; Weight, Russell H <[email protected]>
Subject: Re: [PATCH v1] regmap: add generic indirect regmap supportQuoted 21 lines · On Tue, Jun 07, 2022 at 05:27:38PM -0700, [email protected] wrote:
Quoted 10 lines · Mark Brown
Quoted 6 lines · Tianfei Zhang
From: Matthew Gerlach <[email protected]>
This patch adds support for regmap APIs that are intended to be used by the drivers of some devices which support generic indirect register access, for example PMCI (Platform Management Control Interface) device, HSSI (High Speed Serial Interface) device in FPGA.
What is "generic indirect register access"? I'm not clear what this is intended to support...
"indirect register access" is a RTL design pattern we use in FPGAs frequently. The design pattern involves a small number of registers plus a little handshake code to access various register spaces inside the FPGA fabric. The design pattern is "generic" in the sense that the same small number of registers and handshake can be used with many different IP components in the FPGA. Historically, the bit definitions and handshaking was slightly different for each IP component. This is an attempt at a consistent usage across IP components.
Quoted 1 line
Would a different name help?
This wouldn't address the major problem which is...
Quoted 3 lines
Quoted 3 lines
drivers/base/regmap/regmap-indirect-register.c
Quoted 3 lines
drivers/base/regmap/regmap-indirect-register.c new file +3
-0+writel (0 , ctx->base +INDIRECT_CMD_OFF ); + ret = readl_poll_timeout((ctx->base + INDIRECT_CMD_OFF), cmd, + (!cmd), INDIRECT_INT_US,
INDIRECT_TIMEOUT_US);Quoted 6 lines
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ if (ret) + dev_err(ctx->dev, "%s timed out on clearing cmd 0x%xn", +__func__, cmd);...and this doesn't look particularly generic, it looks like it's for some particular controller/bridge?
Quoted 3 lines
...that this appears to be entirely specific to some particular device, it's got things like hard coded register addresses and timeouts which mean it can't be reused.
Yet, this is a register access hardware controller/bridge widely used in FPGA IP blocks, like PMCI, HSSI. How about we change the patch title like this:
regmap: add indirect register controller support
Mark Brown
maintainerQuoted 15 lines · Tianfei
Quoted 15 lines
Quoted 1 line
Would a different name help?
This wouldn't address the major problem which is...
Quoted 3 lines
Quoted 3 lines
drivers/base/regmap/regmap-indirect-register.c
Quoted 3 lines
drivers/base/regmap/regmap-indirect-register.c new file +3
-0+writel (0 , ctx->base +INDIRECT_CMD_OFF ); + ret = readl_poll_timeout((ctx->base + INDIRECT_CMD_OFF), cmd, + (!cmd), INDIRECT_INT_US,
INDIRECT_TIMEOUT_US);Quoted 6 lines
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ if (ret) + dev_err(ctx->dev, "%s timed out on clearing cmd 0x%xn", +__func__, cmd);...and this doesn't look particularly generic, it looks like it's for some particular controller/bridge?
Quoted 8 lines
Quoted 3 lines
...that this appears to be entirely specific to some particular device, it's got things like hard coded register addresses and timeouts which mean it can't be reused.
Yet, this is a register access hardware controller/bridge widely used in FPGA IP blocks, like PMCI, HSSI. How about we change the patch title like this:
regmap: add indirect register controller support
No, please enage with my feedback above.
Quoted 21 lines · Mark Brown
Quoted 19 lines · Tianfei
Quoted 18 lines
Quoted 1 line
Would a different name help?
This wouldn't address the major problem which is...
Quoted 3 lines
Quoted 3 lines
drivers/base/regmap/regmap-indirect-register.c
Quoted 3 lines
drivers/base/regmap/regmap-indirect-register.c new file +3
-0+writel (0 , ctx->base +INDIRECT_CMD_OFF ); + ret = readl_poll_timeout((ctx->base + INDIRECT_CMD_OFF), cmd, + (!cmd), INDIRECT_INT_US,
INDIRECT_TIMEOUT_US);Quoted 6 lines
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ if (ret) + dev_err(ctx->dev, "%s timed out on clearing cmd 0x%xn", +__func__, cmd);...and this doesn't look particularly generic, it looks like it's for some particular controller/bridge?
...that this appears to be entirely specific to some particular device, it's got things like hard coded register addresses and timeouts which mean it can't be reused.
Quoted 7 lines
Quoted 4 lines
Yet, this is a register access hardware controller/bridge widely used in FPGA IP blocks, like PMCI, HSSI. How about we change the patch title like this:
regmap: add indirect register controller support
No, please enage with my feedback above.
Hi Mark,
I think part of the confusion is that this patch should have been included in a patch set that actually uses this regmap. This patch really should be included with the following:
https://lore.kernel.org/all/[email protected]
The hard coded register definitions are offsets to the passed in void __iomem base address. This set of registers provides the semantics of indirect register read/write to whatever the register set is connected to on the back end. Conceptually this could be considered a specific type indirect register access controller, but currently we have very different backend implementations in RTL. Part of our intent is to have consistent register interfaces for our FPGA IP so multiple drivers can reuse this regmap.
I totally agree the hardcoded timeout values used for polling should be parameterized.
We would like to submit a v2 patch set that combines this patch with the first consumer of the regmap, PMCI. We would also parameterize the timeout values, but most importantly the name must be better. It is a long name, but how about something like "Intel FPGA Indirect Register Interface"?
Matthew Gerlach
Mark Brown
maintainerQuoted 13 lines · On Thu, Jun 09, 2022 at 05:30:43PM -0700, [email protected] wrote:
Quoted 5 lines · Mark Brown
Quoted 3 lines · Tianfei
Quoted 3 lines
...that this appears to be entirely specific to some particular device, it's got things like hard coded register addresses and timeouts which mean it can't be reused.
I think part of the confusion is that this patch should have been included in a patch set that actually uses this regmap. This patch really should be included with the following:
Quoted 8 lines
The hard coded register definitions are offsets to the passed in void
__iomembase address. This set of registers provides the semantics of indirect register read/write to whatever the register set is connected to on the back end. Conceptually this could be considered a specific type indirect register access controller, but currently we have very different backend implementations in RTL. Part of our intent is to have consistent register interfaces for our FPGA IP so multiple drivers can reuse this regmap.
...which is all specific to your particular implmentation of this and not a generic thing that will work for anyone else who implements the concept of indirected register access and happens to use a different control mechanism. If you have to use the same register interfaces to reuse this code then the code isn't generic.
Quoted 70 lines · Tianfei Zhang
From: Matthew Gerlach <[email protected]>
This patch adds support for regmap APIs that are intended to be used by the drivers of some devices which support generic indirect register access, for example PMCI (Platform Management Control Interface) device, HSSI (High Speed Serial Interface) device in FPGA.
Signed-off-by Matthew Gerlach <[email protected]>Signed-off-by Tianfei Zhang <[email protected]>--- drivers/base/regmap/Kconfig | 3 + drivers/base/regmap/Makefile | 1 + .../base/regmap/regmap-indirect-register.c | 133 ++++++++++++++++++ include/linux/regmap.h | 12 ++ 4 files changed, 149 insertions(+) create mode 100644 drivers/base/regmap/regmap-indirect-register.cdrivers/base/regmap/Kconfig +3
-0@@ -65,3 +65,6 @@ config REGMAP_I3C config REGMAP_SPI_AVMM tristate depends on SPI + +config REGMAP_INDIRECT_REGISTER + tristatedrivers/base/regmap/Makefile +1
-0@@ -20,3 +20,4 @@ obj-$(CONFIG_REGMAP_SCCB) += regmap-sccb.o obj-$(CONFIG_REGMAP_I3C) += regmap-i3c.o obj-$(CONFIG_REGMAP_SPI_AVMM) += regmap-spi-avmm.o obj-$(CONFIG_REGMAP_MDIO) += regmap-mdio.o +obj-$(CONFIG_REGMAP_INDIRECT_REGISTER) += regmap-indirect-register.odrivers/base/regmap/regmap-indirect-register.c new file +27
-0@@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Indirect Register Access. +// +// Copyright (C) 2022 Intel Corporation, Inc. + +#include <linux/device.h> +#include <linux/module.h> +#include <linux/regmap.h> + +#define INDIRECT_CMD_OFF 0x0 +#define INDIRECT_CMD_RD BIT(0) +#define INDIRECT_CMD_WR BIT(1) +#define INDIRECT_CMD_ACK BIT(2) + +#define INDIRECT_ADDR_OFF 0x4 +#define INDIRECT_RD_OFF 0x8 +#define INDIRECT_WR_OFF 0xc + +#define INDIRECT_INT_US 1 +#define INDIRECT_TIMEOUT_US 10000 + +struct indirect_ctx { +void __iomem *base; +struct device *dev; +}; +
drivers/base/regmap/regmap-indirect-register.c line 37
Quoted 10 lines
drivers/base/regmap/regmap-indirect-register.c new file +10
-0+static int indirect_bus_clr_cmd (struct indirect_ctx *ctx) +{ +unsigned int cmd; +int ret; + +writel (0 , ctx->base +INDIRECT_CMD_OFF ); + ret =readl_poll_timeout ((ctx->base +INDIRECT_CMD_OFF ), cmd, + (!cmd),INDIRECT_INT_US ,INDIRECT_TIMEOUT_US ); +if (ret) +dev_err (ctx->dev,"%s timed out on clearing cmd 0x%xn" , __func__, cmd);
The line-return in the above dev_err() is missing a forward slash: \n
- Russ
Quoted 119 lines
drivers/base/regmap/regmap-indirect-register.c new file +96
-0+ +return ret; +} + +static int indirect_bus_reg_read (void *context,unsigned int reg, +unsigned int *val) +{ +struct indirect_ctx *ctx = context; +unsigned int cmd; +int ret; + + cmd =readl (ctx->base +INDIRECT_CMD_OFF ); +if (cmd) +dev_warn (ctx->dev,"%s non-zero cmd 0x%x\n" , __func__, cmd); + +writel (reg, ctx->base +INDIRECT_ADDR_OFF ); +writel (INDIRECT_CMD_RD , ctx->base +INDIRECT_CMD_OFF ); + ret =readl_poll_timeout ((ctx->base +INDIRECT_CMD_OFF ), cmd, + (cmd &INDIRECT_CMD_ACK ),INDIRECT_INT_US , +INDIRECT_TIMEOUT_US ); +if (ret) { +dev_err (ctx->dev,"%s timed out on reg 0x%x cmd 0x%x\n" , __func__, reg, cmd); + goto out; + } + + *val =readl (ctx->base +INDIRECT_RD_OFF ); + +if (indirect_bus_clr_cmd (ctx)) + ret = -ETIMEDOUT ; + +out: +return ret; +} + +static int indirect_bus_reg_write (void *context,unsigned int reg, +unsigned int val) +{ +struct indirect_ctx *ctx = context; +unsigned int cmd; +int ret; + + cmd =readl (ctx->base +INDIRECT_CMD_OFF ); +if (cmd) +dev_warn (ctx->dev,"%s non-zero cmd 0x%x\n" , __func__, cmd); + +writel (val, ctx->base +INDIRECT_WR_OFF ); +writel (reg, ctx->base +INDIRECT_ADDR_OFF ); +writel (INDIRECT_CMD_WR , ctx->base +INDIRECT_CMD_OFF ); + ret =readl_poll_timeout ((ctx->base +INDIRECT_CMD_OFF ), cmd, + (cmd &INDIRECT_CMD_ACK ),INDIRECT_INT_US , +INDIRECT_TIMEOUT_US ); +if (ret) { +dev_err (ctx->dev,"%s timed out on reg 0x%x cmd 0x%x\n" , __func__, reg, cmd); + goto out; + } + +if (indirect_bus_clr_cmd (ctx)) + ret = -ETIMEDOUT ; + +out: +return ret; +} + +static const struct regmap_bus indirect_bus = { + .reg_write = indirect_bus_reg_write, + .reg_read = indirect_bus_reg_read, +}; + +/** +* devm_regmap_init_indirect_register - create a regmap for indirect register access +* @dev: device creating the regmap +* @base: __iomem point to base of memory with mailbox +* @cfg: regmap_config describing interface +* +* Return: 0 on success, negative error code otherwise. +*/ +struct regmap *devm_regmap_init_indirect_register (struct device *dev, +void __iomem *base, +struct regmap_config *cfg) +{ +struct indirect_ctx *ctx; + + ctx =devm_kzalloc (dev,sizeof (*ctx),GFP_KERNEL ); +if (!ctx) +return NULL ; + + ctx->base = base; + ctx->dev = dev; + +return devm_regmap_init (dev, &indirect_bus, ctx, cfg); +} +EXPORT_SYMBOL_GPL (devm_regmap_init_indirect_register); + +MODULE_DESCRIPTION ("Indirect Register Access" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL" );include/linux/regmap.h +12
-0@@ -670,6 +670,18 @@ struct regmap *__devm_regmap_init_spi_avmm(struct spi_device *spi,const struct regmap_config *config, struct lock_class_key *lock_key, const char *lock_name); +/** +* devm_regmap_init_indirect_register - create a regmap for indirect register access +* @dev: device creating the regmap +* @base: __iomem point to base of memory with mailbox +* @cfg: regmap_config describing interface +* +* Return: 0 on success, negative error code otherwise. +*/ +struct regmap *devm_regmap_init_indirect_register (struct device *dev, +void __iomem *base, +struct regmap_config *cfg); +/* * Wrapper for regmap_init macros to include a unique lockdep key and name * for each call. No-op if CONFIG_LOCKDEP is not set.