All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liviu Dudau <liviu.dudau@arm.com>
To: Rob Herring <robh@kernel.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Lee Jones <lee.jones@linaro.org>,
	Sebastian Reichel <sre@kernel.org>,
	Stephen Boyd <sboyd@kernel.org>, Will Deacon <will@kernel.org>,
	Kevin Brodsky <Kevin.Brodsky@arm.com>,
	linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
	linux-pm@vger.kernel.org
Subject: Re: [PATCH 13/17] bus: vexpress-config: Merge vexpress-syscfg into vexpress-config
Date: Wed, 22 Apr 2020 12:22:10 +0100	[thread overview]
Message-ID: <20200422112210.GX364558@e110455-lin.cambridge.arm.com> (raw)
In-Reply-To: <20200419170810.5738-14-robh@kernel.org>

On Sun, Apr 19, 2020 at 12:08:06PM -0500, Rob Herring wrote:
> The only thing that vexpress-syscfg does is provide a regmap to
> vexpress-config bus child devices. There's little reason to have 2
> components for this. The current structure with initcall ordering
> requirements makes turning these components into modules more difficult.
> 
> So let's start to simplify things and merge vexpress-syscfg into
> vexpress-config. There's no functional change in this commit and it's
> still separate components until subsequent commits.
> 
> Cc: Liviu Dudau <liviu.dudau@arm.com>

Acked-by: Liviu Dudau <liviu.dudau@arm.com>

> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  arch/arm/mach-vexpress/Kconfig |   1 -
>  drivers/bus/vexpress-config.c  | 283 +++++++++++++++++++++++++++++++--
>  drivers/misc/Kconfig           |   9 --
>  drivers/misc/Makefile          |   1 -
>  drivers/misc/vexpress-syscfg.c | 280 --------------------------------
>  include/linux/vexpress.h       |  17 --
>  6 files changed, 274 insertions(+), 317 deletions(-)
>  delete mode 100644 drivers/misc/vexpress-syscfg.c
> 
> diff --git a/arch/arm/mach-vexpress/Kconfig b/arch/arm/mach-vexpress/Kconfig
> index 2d1fdec4c230..065e12991663 100644
> --- a/arch/arm/mach-vexpress/Kconfig
> +++ b/arch/arm/mach-vexpress/Kconfig
> @@ -20,7 +20,6 @@ menuconfig ARCH_VEXPRESS
>  	select REGULATOR if MMC_ARMMMCI
>  	select REGULATOR_FIXED_VOLTAGE if REGULATOR
>  	select VEXPRESS_CONFIG
> -	select VEXPRESS_SYSCFG
>  	help
>  	  This option enables support for systems using Cortex processor based
>  	  ARM core and logic (FPGA) tiles on the Versatile Express motherboard,
> diff --git a/drivers/bus/vexpress-config.c b/drivers/bus/vexpress-config.c
> index ff70575b2db6..43f5beac9811 100644
> --- a/drivers/bus/vexpress-config.c
> +++ b/drivers/bus/vexpress-config.c
> @@ -6,10 +6,48 @@
>  
>  #include <linux/err.h>
>  #include <linux/init.h>
> +#include <linux/io.h>
>  #include <linux/of.h>
> +#include <linux/platform_device.h>
>  #include <linux/of_device.h>
> +#include <linux/sched/signal.h>
> +#include <linux/slab.h>
>  #include <linux/vexpress.h>
>  
> +#define SYS_CFGDATA		0x0
> +
> +#define SYS_CFGCTRL		0x4
> +#define SYS_CFGCTRL_START	(1 << 31)
> +#define SYS_CFGCTRL_WRITE	(1 << 30)
> +#define SYS_CFGCTRL_DCC(n)	(((n) & 0xf) << 26)
> +#define SYS_CFGCTRL_FUNC(n)	(((n) & 0x3f) << 20)
> +#define SYS_CFGCTRL_SITE(n)	(((n) & 0x3) << 16)
> +#define SYS_CFGCTRL_POSITION(n)	(((n) & 0xf) << 12)
> +#define SYS_CFGCTRL_DEVICE(n)	(((n) & 0xfff) << 0)
> +
> +#define SYS_CFGSTAT		0x8
> +#define SYS_CFGSTAT_ERR		(1 << 1)
> +#define SYS_CFGSTAT_COMPLETE	(1 << 0)
> +
> +
> +struct vexpress_syscfg {
> +	struct device *dev;
> +	void __iomem *base;
> +	struct list_head funcs;
> +};
> +
> +struct vexpress_syscfg_func {
> +	struct list_head list;
> +	struct vexpress_syscfg *syscfg;
> +	struct regmap *regmap;
> +	int num_templates;
> +	u32 template[]; /* Keep it last! */
> +};
> +
> +struct vexpress_config_bridge_ops {
> +	struct regmap * (*regmap_init)(struct device *dev, void *context);
> +	void (*regmap_exit)(struct regmap *regmap, void *context);
> +};
>  
>  struct vexpress_config_bridge {
>  	struct vexpress_config_bridge_ops *ops;
> @@ -27,17 +65,12 @@ void vexpress_config_set_master(u32 site)
>  	vexpress_config_site_master = site;
>  }
>  
> -u32 vexpress_config_get_master(void)
> -{
> -	return vexpress_config_site_master;
> -}
> -
> -void vexpress_config_lock(void *arg)
> +static void vexpress_config_lock(void *arg)
>  {
>  	mutex_lock(&vexpress_config_mutex);
>  }
>  
> -void vexpress_config_unlock(void *arg)
> +static void vexpress_config_unlock(void *arg)
>  {
>  	mutex_unlock(&vexpress_config_mutex);
>  }
> @@ -59,7 +92,7 @@ static void vexpress_config_find_prop(struct device_node *node,
>  	}
>  }
>  
> -int vexpress_config_get_topo(struct device_node *node, u32 *site,
> +static int vexpress_config_get_topo(struct device_node *node, u32 *site,
>  		u32 *position, u32 *dcc)
>  {
>  	vexpress_config_find_prop(node, "arm,vexpress,site", site);
> @@ -113,7 +146,7 @@ struct regmap *devm_regmap_init_vexpress_config(struct device *dev)
>  }
>  EXPORT_SYMBOL_GPL(devm_regmap_init_vexpress_config);
>  
> -struct device *vexpress_config_bridge_register(struct device *parent,
> +static struct device *vexpress_config_bridge_register(struct device *parent,
>  		struct vexpress_config_bridge_ops *ops, void *context)
>  {
>  	struct device *dev;
> @@ -201,3 +234,235 @@ static int __init vexpress_config_init(void)
>  }
>  postcore_initcall(vexpress_config_init);
>  
> +static int vexpress_syscfg_exec(struct vexpress_syscfg_func *func,
> +		int index, bool write, u32 *data)
> +{
> +	struct vexpress_syscfg *syscfg = func->syscfg;
> +	u32 command, status;
> +	int tries;
> +	long timeout;
> +
> +	if (WARN_ON(index >= func->num_templates))
> +		return -EINVAL;
> +
> +	command = readl(syscfg->base + SYS_CFGCTRL);
> +	if (WARN_ON(command & SYS_CFGCTRL_START))
> +		return -EBUSY;
> +
> +	command = func->template[index];
> +	command |= SYS_CFGCTRL_START;
> +	command |= write ? SYS_CFGCTRL_WRITE : 0;
> +
> +	/* Use a canary for reads */
> +	if (!write)
> +		*data = 0xdeadbeef;
> +
> +	dev_dbg(syscfg->dev, "func %p, command %x, data %x\n",
> +			func, command, *data);
> +	writel(*data, syscfg->base + SYS_CFGDATA);
> +	writel(0, syscfg->base + SYS_CFGSTAT);
> +	writel(command, syscfg->base + SYS_CFGCTRL);
> +	mb();
> +
> +	/* The operation can take ages... Go to sleep, 100us initially */
> +	tries = 100;
> +	timeout = 100;
> +	do {
> +		if (!irqs_disabled()) {
> +			set_current_state(TASK_INTERRUPTIBLE);
> +			schedule_timeout(usecs_to_jiffies(timeout));
> +			if (signal_pending(current))
> +				return -EINTR;
> +		} else {
> +			udelay(timeout);
> +		}
> +
> +		status = readl(syscfg->base + SYS_CFGSTAT);
> +		if (status & SYS_CFGSTAT_ERR)
> +			return -EFAULT;
> +
> +		if (timeout > 20)
> +			timeout -= 20;
> +	} while (--tries && !(status & SYS_CFGSTAT_COMPLETE));
> +	if (WARN_ON_ONCE(!tries))
> +		return -ETIMEDOUT;
> +
> +	if (!write) {
> +		*data = readl(syscfg->base + SYS_CFGDATA);
> +		dev_dbg(syscfg->dev, "func %p, read data %x\n", func, *data);
> +	}
> +
> +	return 0;
> +}
> +
> +static int vexpress_syscfg_read(void *context, unsigned int index,
> +		unsigned int *val)
> +{
> +	struct vexpress_syscfg_func *func = context;
> +
> +	return vexpress_syscfg_exec(func, index, false, val);
> +}
> +
> +static int vexpress_syscfg_write(void *context, unsigned int index,
> +		unsigned int val)
> +{
> +	struct vexpress_syscfg_func *func = context;
> +
> +	return vexpress_syscfg_exec(func, index, true, &val);
> +}
> +
> +static struct regmap_config vexpress_syscfg_regmap_config = {
> +	.lock = vexpress_config_lock,
> +	.unlock = vexpress_config_unlock,
> +	.reg_bits = 32,
> +	.val_bits = 32,
> +	.reg_read = vexpress_syscfg_read,
> +	.reg_write = vexpress_syscfg_write,
> +	.reg_format_endian = REGMAP_ENDIAN_LITTLE,
> +	.val_format_endian = REGMAP_ENDIAN_LITTLE,
> +};
> +
> +
> +static struct regmap *vexpress_syscfg_regmap_init(struct device *dev,
> +		void *context)
> +{
> +	int err;
> +	struct vexpress_syscfg *syscfg = context;
> +	struct vexpress_syscfg_func *func;
> +	struct property *prop;
> +	const __be32 *val = NULL;
> +	__be32 energy_quirk[4];
> +	int num;
> +	u32 site, position, dcc;
> +	int i;
> +
> +	err = vexpress_config_get_topo(dev->of_node, &site,
> +				&position, &dcc);
> +	if (err)
> +		return ERR_PTR(err);
> +
> +	prop = of_find_property(dev->of_node,
> +			"arm,vexpress-sysreg,func", NULL);
> +	if (!prop)
> +		return ERR_PTR(-EINVAL);
> +
> +	num = prop->length / sizeof(u32) / 2;
> +	val = prop->value;
> +
> +	/*
> +	 * "arm,vexpress-energy" function used to be described
> +	 * by its first device only, now it requires both
> +	 */
> +	if (num == 1 && of_device_is_compatible(dev->of_node,
> +			"arm,vexpress-energy")) {
> +		num = 2;
> +		energy_quirk[0] = *val;
> +		energy_quirk[2] = *val++;
> +		energy_quirk[1] = *val;
> +		energy_quirk[3] = cpu_to_be32(be32_to_cpup(val) + 1);
> +		val = energy_quirk;
> +	}
> +
> +	func = kzalloc(struct_size(func, template, num), GFP_KERNEL);
> +	if (!func)
> +		return ERR_PTR(-ENOMEM);
> +
> +	func->syscfg = syscfg;
> +	func->num_templates = num;
> +
> +	for (i = 0; i < num; i++) {
> +		u32 function, device;
> +
> +		function = be32_to_cpup(val++);
> +		device = be32_to_cpup(val++);
> +
> +		dev_dbg(dev, "func %p: %u/%u/%u/%u/%u\n",
> +				func, site, position, dcc,
> +				function, device);
> +
> +		func->template[i] = SYS_CFGCTRL_DCC(dcc);
> +		func->template[i] |= SYS_CFGCTRL_SITE(site);
> +		func->template[i] |= SYS_CFGCTRL_POSITION(position);
> +		func->template[i] |= SYS_CFGCTRL_FUNC(function);
> +		func->template[i] |= SYS_CFGCTRL_DEVICE(device);
> +	}
> +
> +	vexpress_syscfg_regmap_config.max_register = num - 1;
> +
> +	func->regmap = regmap_init(dev, NULL, func,
> +			&vexpress_syscfg_regmap_config);
> +
> +	if (IS_ERR(func->regmap)) {
> +		void *err = func->regmap;
> +
> +		kfree(func);
> +		return err;
> +	}
> +
> +	list_add(&func->list, &syscfg->funcs);
> +
> +	return func->regmap;
> +}
> +
> +static void vexpress_syscfg_regmap_exit(struct regmap *regmap, void *context)
> +{
> +	struct vexpress_syscfg *syscfg = context;
> +	struct vexpress_syscfg_func *func, *tmp;
> +
> +	regmap_exit(regmap);
> +
> +	list_for_each_entry_safe(func, tmp, &syscfg->funcs, list) {
> +		if (func->regmap == regmap) {
> +			list_del(&syscfg->funcs);
> +			kfree(func);
> +			break;
> +		}
> +	}
> +}
> +
> +static struct vexpress_config_bridge_ops vexpress_syscfg_bridge_ops = {
> +	.regmap_init = vexpress_syscfg_regmap_init,
> +	.regmap_exit = vexpress_syscfg_regmap_exit,
> +};
> +
> +
> +static int vexpress_syscfg_probe(struct platform_device *pdev)
> +{
> +	struct vexpress_syscfg *syscfg;
> +	struct resource *res;
> +	struct device *bridge;
> +
> +	syscfg = devm_kzalloc(&pdev->dev, sizeof(*syscfg), GFP_KERNEL);
> +	if (!syscfg)
> +		return -ENOMEM;
> +	syscfg->dev = &pdev->dev;
> +	INIT_LIST_HEAD(&syscfg->funcs);
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	syscfg->base = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(syscfg->base))
> +		return PTR_ERR(syscfg->base);
> +
> +	/* Must use dev.parent (MFD), as that's where DT phandle points at... */
> +	bridge = vexpress_config_bridge_register(pdev->dev.parent,
> +			&vexpress_syscfg_bridge_ops, syscfg);
> +
> +	return PTR_ERR_OR_ZERO(bridge);
> +}
> +
> +static const struct platform_device_id vexpress_syscfg_id_table[] = {
> +	{ "vexpress-syscfg", },
> +	{},
> +};
> +
> +static struct platform_driver vexpress_syscfg_driver = {
> +	.driver.name = "vexpress-syscfg",
> +	.id_table = vexpress_syscfg_id_table,
> +	.probe = vexpress_syscfg_probe,
> +};
> +
> +static int __init vexpress_syscfg_init(void)
> +{
> +	return platform_driver_register(&vexpress_syscfg_driver);
> +}
> +core_initcall(vexpress_syscfg_init);
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 99e151475d8f..edd5dd5ebfdc 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -423,15 +423,6 @@ config SRAM
>  config SRAM_EXEC
>  	bool
>  
> -config VEXPRESS_SYSCFG
> -	bool "Versatile Express System Configuration driver"
> -	depends on VEXPRESS_CONFIG
> -	default y
> -	help
> -	  ARM Ltd. Versatile Express uses specialised platform configuration
> -	  bus. System Configuration interface is one of the possible means
> -	  of generating transactions on this bus.
> -
>  config PCI_ENDPOINT_TEST
>  	depends on PCI
>  	select CRC32
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index 9abf2923d831..c7bd01ac6291 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -49,7 +49,6 @@ obj-$(CONFIG_SRAM_EXEC)		+= sram-exec.o
>  obj-y				+= mic/
>  obj-$(CONFIG_GENWQE)		+= genwqe/
>  obj-$(CONFIG_ECHO)		+= echo/
> -obj-$(CONFIG_VEXPRESS_SYSCFG)	+= vexpress-syscfg.o
>  obj-$(CONFIG_CXL_BASE)		+= cxl/
>  obj-$(CONFIG_PCI_ENDPOINT_TEST)	+= pci_endpoint_test.o
>  obj-$(CONFIG_OCXL)		+= ocxl/
> diff --git a/drivers/misc/vexpress-syscfg.c b/drivers/misc/vexpress-syscfg.c
> deleted file mode 100644
> index a431787c0898..000000000000
> --- a/drivers/misc/vexpress-syscfg.c
> +++ /dev/null
> @@ -1,280 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0-only
> -/*
> - *
> - * Copyright (C) 2014 ARM Limited
> - */
> -
> -#include <linux/delay.h>
> -#include <linux/err.h>
> -#include <linux/io.h>
> -#include <linux/of.h>
> -#include <linux/platform_device.h>
> -#include <linux/sched/signal.h>
> -#include <linux/slab.h>
> -#include <linux/syscore_ops.h>
> -#include <linux/vexpress.h>
> -
> -
> -#define SYS_CFGDATA		0x0
> -
> -#define SYS_CFGCTRL		0x4
> -#define SYS_CFGCTRL_START	(1 << 31)
> -#define SYS_CFGCTRL_WRITE	(1 << 30)
> -#define SYS_CFGCTRL_DCC(n)	(((n) & 0xf) << 26)
> -#define SYS_CFGCTRL_FUNC(n)	(((n) & 0x3f) << 20)
> -#define SYS_CFGCTRL_SITE(n)	(((n) & 0x3) << 16)
> -#define SYS_CFGCTRL_POSITION(n)	(((n) & 0xf) << 12)
> -#define SYS_CFGCTRL_DEVICE(n)	(((n) & 0xfff) << 0)
> -
> -#define SYS_CFGSTAT		0x8
> -#define SYS_CFGSTAT_ERR		(1 << 1)
> -#define SYS_CFGSTAT_COMPLETE	(1 << 0)
> -
> -
> -struct vexpress_syscfg {
> -	struct device *dev;
> -	void __iomem *base;
> -	struct list_head funcs;
> -};
> -
> -struct vexpress_syscfg_func {
> -	struct list_head list;
> -	struct vexpress_syscfg *syscfg;
> -	struct regmap *regmap;
> -	int num_templates;
> -	u32 template[]; /* Keep it last! */
> -};
> -
> -
> -static int vexpress_syscfg_exec(struct vexpress_syscfg_func *func,
> -		int index, bool write, u32 *data)
> -{
> -	struct vexpress_syscfg *syscfg = func->syscfg;
> -	u32 command, status;
> -	int tries;
> -	long timeout;
> -
> -	if (WARN_ON(index >= func->num_templates))
> -		return -EINVAL;
> -
> -	command = readl(syscfg->base + SYS_CFGCTRL);
> -	if (WARN_ON(command & SYS_CFGCTRL_START))
> -		return -EBUSY;
> -
> -	command = func->template[index];
> -	command |= SYS_CFGCTRL_START;
> -	command |= write ? SYS_CFGCTRL_WRITE : 0;
> -
> -	/* Use a canary for reads */
> -	if (!write)
> -		*data = 0xdeadbeef;
> -
> -	dev_dbg(syscfg->dev, "func %p, command %x, data %x\n",
> -			func, command, *data);
> -	writel(*data, syscfg->base + SYS_CFGDATA);
> -	writel(0, syscfg->base + SYS_CFGSTAT);
> -	writel(command, syscfg->base + SYS_CFGCTRL);
> -	mb();
> -
> -	/* The operation can take ages... Go to sleep, 100us initially */
> -	tries = 100;
> -	timeout = 100;
> -	do {
> -		if (!irqs_disabled()) {
> -			set_current_state(TASK_INTERRUPTIBLE);
> -			schedule_timeout(usecs_to_jiffies(timeout));
> -			if (signal_pending(current))
> -				return -EINTR;
> -		} else {
> -			udelay(timeout);
> -		}
> -
> -		status = readl(syscfg->base + SYS_CFGSTAT);
> -		if (status & SYS_CFGSTAT_ERR)
> -			return -EFAULT;
> -
> -		if (timeout > 20)
> -			timeout -= 20;
> -	} while (--tries && !(status & SYS_CFGSTAT_COMPLETE));
> -	if (WARN_ON_ONCE(!tries))
> -		return -ETIMEDOUT;
> -
> -	if (!write) {
> -		*data = readl(syscfg->base + SYS_CFGDATA);
> -		dev_dbg(syscfg->dev, "func %p, read data %x\n", func, *data);
> -	}
> -
> -	return 0;
> -}
> -
> -static int vexpress_syscfg_read(void *context, unsigned int index,
> -		unsigned int *val)
> -{
> -	struct vexpress_syscfg_func *func = context;
> -
> -	return vexpress_syscfg_exec(func, index, false, val);
> -}
> -
> -static int vexpress_syscfg_write(void *context, unsigned int index,
> -		unsigned int val)
> -{
> -	struct vexpress_syscfg_func *func = context;
> -
> -	return vexpress_syscfg_exec(func, index, true, &val);
> -}
> -
> -static struct regmap_config vexpress_syscfg_regmap_config = {
> -	.lock = vexpress_config_lock,
> -	.unlock = vexpress_config_unlock,
> -	.reg_bits = 32,
> -	.val_bits = 32,
> -	.reg_read = vexpress_syscfg_read,
> -	.reg_write = vexpress_syscfg_write,
> -	.reg_format_endian = REGMAP_ENDIAN_LITTLE,
> -	.val_format_endian = REGMAP_ENDIAN_LITTLE,
> -};
> -
> -
> -static struct regmap *vexpress_syscfg_regmap_init(struct device *dev,
> -		void *context)
> -{
> -	int err;
> -	struct vexpress_syscfg *syscfg = context;
> -	struct vexpress_syscfg_func *func;
> -	struct property *prop;
> -	const __be32 *val = NULL;
> -	__be32 energy_quirk[4];
> -	int num;
> -	u32 site, position, dcc;
> -	int i;
> -
> -	err = vexpress_config_get_topo(dev->of_node, &site,
> -				&position, &dcc);
> -	if (err)
> -		return ERR_PTR(err);
> -
> -	prop = of_find_property(dev->of_node,
> -			"arm,vexpress-sysreg,func", NULL);
> -	if (!prop)
> -		return ERR_PTR(-EINVAL);
> -
> -	num = prop->length / sizeof(u32) / 2;
> -	val = prop->value;
> -
> -	/*
> -	 * "arm,vexpress-energy" function used to be described
> -	 * by its first device only, now it requires both
> -	 */
> -	if (num == 1 && of_device_is_compatible(dev->of_node,
> -			"arm,vexpress-energy")) {
> -		num = 2;
> -		energy_quirk[0] = *val;
> -		energy_quirk[2] = *val++;
> -		energy_quirk[1] = *val;
> -		energy_quirk[3] = cpu_to_be32(be32_to_cpup(val) + 1);
> -		val = energy_quirk;
> -	}
> -
> -	func = kzalloc(struct_size(func, template, num), GFP_KERNEL);
> -	if (!func)
> -		return ERR_PTR(-ENOMEM);
> -
> -	func->syscfg = syscfg;
> -	func->num_templates = num;
> -
> -	for (i = 0; i < num; i++) {
> -		u32 function, device;
> -
> -		function = be32_to_cpup(val++);
> -		device = be32_to_cpup(val++);
> -
> -		dev_dbg(dev, "func %p: %u/%u/%u/%u/%u\n",
> -				func, site, position, dcc,
> -				function, device);
> -
> -		func->template[i] = SYS_CFGCTRL_DCC(dcc);
> -		func->template[i] |= SYS_CFGCTRL_SITE(site);
> -		func->template[i] |= SYS_CFGCTRL_POSITION(position);
> -		func->template[i] |= SYS_CFGCTRL_FUNC(function);
> -		func->template[i] |= SYS_CFGCTRL_DEVICE(device);
> -	}
> -
> -	vexpress_syscfg_regmap_config.max_register = num - 1;
> -
> -	func->regmap = regmap_init(dev, NULL, func,
> -			&vexpress_syscfg_regmap_config);
> -
> -	if (IS_ERR(func->regmap)) {
> -		void *err = func->regmap;
> -
> -		kfree(func);
> -		return err;
> -	}
> -
> -	list_add(&func->list, &syscfg->funcs);
> -
> -	return func->regmap;
> -}
> -
> -static void vexpress_syscfg_regmap_exit(struct regmap *regmap, void *context)
> -{
> -	struct vexpress_syscfg *syscfg = context;
> -	struct vexpress_syscfg_func *func, *tmp;
> -
> -	regmap_exit(regmap);
> -
> -	list_for_each_entry_safe(func, tmp, &syscfg->funcs, list) {
> -		if (func->regmap == regmap) {
> -			list_del(&syscfg->funcs);
> -			kfree(func);
> -			break;
> -		}
> -	}
> -}
> -
> -static struct vexpress_config_bridge_ops vexpress_syscfg_bridge_ops = {
> -	.regmap_init = vexpress_syscfg_regmap_init,
> -	.regmap_exit = vexpress_syscfg_regmap_exit,
> -};
> -
> -
> -static int vexpress_syscfg_probe(struct platform_device *pdev)
> -{
> -	struct vexpress_syscfg *syscfg;
> -	struct resource *res;
> -	struct device *bridge;
> -
> -	syscfg = devm_kzalloc(&pdev->dev, sizeof(*syscfg), GFP_KERNEL);
> -	if (!syscfg)
> -		return -ENOMEM;
> -	syscfg->dev = &pdev->dev;
> -	INIT_LIST_HEAD(&syscfg->funcs);
> -
> -	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	syscfg->base = devm_ioremap_resource(&pdev->dev, res);
> -	if (IS_ERR(syscfg->base))
> -		return PTR_ERR(syscfg->base);
> -
> -	/* Must use dev.parent (MFD), as that's where DT phandle points at... */
> -	bridge = vexpress_config_bridge_register(pdev->dev.parent,
> -			&vexpress_syscfg_bridge_ops, syscfg);
> -
> -	return PTR_ERR_OR_ZERO(bridge);
> -}
> -
> -static const struct platform_device_id vexpress_syscfg_id_table[] = {
> -	{ "vexpress-syscfg", },
> -	{},
> -};
> -
> -static struct platform_driver vexpress_syscfg_driver = {
> -	.driver.name = "vexpress-syscfg",
> -	.id_table = vexpress_syscfg_id_table,
> -	.probe = vexpress_syscfg_probe,
> -};
> -
> -static int __init vexpress_syscfg_init(void)
> -{
> -	return platform_driver_register(&vexpress_syscfg_driver);
> -}
> -core_initcall(vexpress_syscfg_init);
> diff --git a/include/linux/vexpress.h b/include/linux/vexpress.h
> index 2ec7992b054c..65096c792d57 100644
> --- a/include/linux/vexpress.h
> +++ b/include/linux/vexpress.h
> @@ -18,23 +18,6 @@
>  /* Config infrastructure */
>  
>  void vexpress_config_set_master(u32 site);
> -u32 vexpress_config_get_master(void);
> -
> -void vexpress_config_lock(void *arg);
> -void vexpress_config_unlock(void *arg);
> -
> -int vexpress_config_get_topo(struct device_node *node, u32 *site,
> -		u32 *position, u32 *dcc);
> -
> -/* Config bridge API */
> -
> -struct vexpress_config_bridge_ops {
> -	struct regmap * (*regmap_init)(struct device *dev, void *context);
> -	void (*regmap_exit)(struct regmap *regmap, void *context);
> -};
> -
> -struct device *vexpress_config_bridge_register(struct device *parent,
> -		struct vexpress_config_bridge_ops *ops, void *context);
>  
>  /* Config regmap API */
>  
> -- 
> 2.20.1
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

WARNING: multiple messages have this Message-ID (diff)
From: Liviu Dudau <liviu.dudau@arm.com>
To: Rob Herring <robh@kernel.org>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Arnd Bergmann <arnd@arndb.de>,
	linux-pm@vger.kernel.org, Stephen Boyd <sboyd@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Sebastian Reichel <sre@kernel.org>,
	Kevin Brodsky <Kevin.Brodsky@arm.com>,
	Will Deacon <will@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Lee Jones <lee.jones@linaro.org>,
	linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 13/17] bus: vexpress-config: Merge vexpress-syscfg into vexpress-config
Date: Wed, 22 Apr 2020 12:22:10 +0100	[thread overview]
Message-ID: <20200422112210.GX364558@e110455-lin.cambridge.arm.com> (raw)
In-Reply-To: <20200419170810.5738-14-robh@kernel.org>

On Sun, Apr 19, 2020 at 12:08:06PM -0500, Rob Herring wrote:
> The only thing that vexpress-syscfg does is provide a regmap to
> vexpress-config bus child devices. There's little reason to have 2
> components for this. The current structure with initcall ordering
> requirements makes turning these components into modules more difficult.
> 
> So let's start to simplify things and merge vexpress-syscfg into
> vexpress-config. There's no functional change in this commit and it's
> still separate components until subsequent commits.
> 
> Cc: Liviu Dudau <liviu.dudau@arm.com>

Acked-by: Liviu Dudau <liviu.dudau@arm.com>

> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  arch/arm/mach-vexpress/Kconfig |   1 -
>  drivers/bus/vexpress-config.c  | 283 +++++++++++++++++++++++++++++++--
>  drivers/misc/Kconfig           |   9 --
>  drivers/misc/Makefile          |   1 -
>  drivers/misc/vexpress-syscfg.c | 280 --------------------------------
>  include/linux/vexpress.h       |  17 --
>  6 files changed, 274 insertions(+), 317 deletions(-)
>  delete mode 100644 drivers/misc/vexpress-syscfg.c
> 
> diff --git a/arch/arm/mach-vexpress/Kconfig b/arch/arm/mach-vexpress/Kconfig
> index 2d1fdec4c230..065e12991663 100644
> --- a/arch/arm/mach-vexpress/Kconfig
> +++ b/arch/arm/mach-vexpress/Kconfig
> @@ -20,7 +20,6 @@ menuconfig ARCH_VEXPRESS
>  	select REGULATOR if MMC_ARMMMCI
>  	select REGULATOR_FIXED_VOLTAGE if REGULATOR
>  	select VEXPRESS_CONFIG
> -	select VEXPRESS_SYSCFG
>  	help
>  	  This option enables support for systems using Cortex processor based
>  	  ARM core and logic (FPGA) tiles on the Versatile Express motherboard,
> diff --git a/drivers/bus/vexpress-config.c b/drivers/bus/vexpress-config.c
> index ff70575b2db6..43f5beac9811 100644
> --- a/drivers/bus/vexpress-config.c
> +++ b/drivers/bus/vexpress-config.c
> @@ -6,10 +6,48 @@
>  
>  #include <linux/err.h>
>  #include <linux/init.h>
> +#include <linux/io.h>
>  #include <linux/of.h>
> +#include <linux/platform_device.h>
>  #include <linux/of_device.h>
> +#include <linux/sched/signal.h>
> +#include <linux/slab.h>
>  #include <linux/vexpress.h>
>  
> +#define SYS_CFGDATA		0x0
> +
> +#define SYS_CFGCTRL		0x4
> +#define SYS_CFGCTRL_START	(1 << 31)
> +#define SYS_CFGCTRL_WRITE	(1 << 30)
> +#define SYS_CFGCTRL_DCC(n)	(((n) & 0xf) << 26)
> +#define SYS_CFGCTRL_FUNC(n)	(((n) & 0x3f) << 20)
> +#define SYS_CFGCTRL_SITE(n)	(((n) & 0x3) << 16)
> +#define SYS_CFGCTRL_POSITION(n)	(((n) & 0xf) << 12)
> +#define SYS_CFGCTRL_DEVICE(n)	(((n) & 0xfff) << 0)
> +
> +#define SYS_CFGSTAT		0x8
> +#define SYS_CFGSTAT_ERR		(1 << 1)
> +#define SYS_CFGSTAT_COMPLETE	(1 << 0)
> +
> +
> +struct vexpress_syscfg {
> +	struct device *dev;
> +	void __iomem *base;
> +	struct list_head funcs;
> +};
> +
> +struct vexpress_syscfg_func {
> +	struct list_head list;
> +	struct vexpress_syscfg *syscfg;
> +	struct regmap *regmap;
> +	int num_templates;
> +	u32 template[]; /* Keep it last! */
> +};
> +
> +struct vexpress_config_bridge_ops {
> +	struct regmap * (*regmap_init)(struct device *dev, void *context);
> +	void (*regmap_exit)(struct regmap *regmap, void *context);
> +};
>  
>  struct vexpress_config_bridge {
>  	struct vexpress_config_bridge_ops *ops;
> @@ -27,17 +65,12 @@ void vexpress_config_set_master(u32 site)
>  	vexpress_config_site_master = site;
>  }
>  
> -u32 vexpress_config_get_master(void)
> -{
> -	return vexpress_config_site_master;
> -}
> -
> -void vexpress_config_lock(void *arg)
> +static void vexpress_config_lock(void *arg)
>  {
>  	mutex_lock(&vexpress_config_mutex);
>  }
>  
> -void vexpress_config_unlock(void *arg)
> +static void vexpress_config_unlock(void *arg)
>  {
>  	mutex_unlock(&vexpress_config_mutex);
>  }
> @@ -59,7 +92,7 @@ static void vexpress_config_find_prop(struct device_node *node,
>  	}
>  }
>  
> -int vexpress_config_get_topo(struct device_node *node, u32 *site,
> +static int vexpress_config_get_topo(struct device_node *node, u32 *site,
>  		u32 *position, u32 *dcc)
>  {
>  	vexpress_config_find_prop(node, "arm,vexpress,site", site);
> @@ -113,7 +146,7 @@ struct regmap *devm_regmap_init_vexpress_config(struct device *dev)
>  }
>  EXPORT_SYMBOL_GPL(devm_regmap_init_vexpress_config);
>  
> -struct device *vexpress_config_bridge_register(struct device *parent,
> +static struct device *vexpress_config_bridge_register(struct device *parent,
>  		struct vexpress_config_bridge_ops *ops, void *context)
>  {
>  	struct device *dev;
> @@ -201,3 +234,235 @@ static int __init vexpress_config_init(void)
>  }
>  postcore_initcall(vexpress_config_init);
>  
> +static int vexpress_syscfg_exec(struct vexpress_syscfg_func *func,
> +		int index, bool write, u32 *data)
> +{
> +	struct vexpress_syscfg *syscfg = func->syscfg;
> +	u32 command, status;
> +	int tries;
> +	long timeout;
> +
> +	if (WARN_ON(index >= func->num_templates))
> +		return -EINVAL;
> +
> +	command = readl(syscfg->base + SYS_CFGCTRL);
> +	if (WARN_ON(command & SYS_CFGCTRL_START))
> +		return -EBUSY;
> +
> +	command = func->template[index];
> +	command |= SYS_CFGCTRL_START;
> +	command |= write ? SYS_CFGCTRL_WRITE : 0;
> +
> +	/* Use a canary for reads */
> +	if (!write)
> +		*data = 0xdeadbeef;
> +
> +	dev_dbg(syscfg->dev, "func %p, command %x, data %x\n",
> +			func, command, *data);
> +	writel(*data, syscfg->base + SYS_CFGDATA);
> +	writel(0, syscfg->base + SYS_CFGSTAT);
> +	writel(command, syscfg->base + SYS_CFGCTRL);
> +	mb();
> +
> +	/* The operation can take ages... Go to sleep, 100us initially */
> +	tries = 100;
> +	timeout = 100;
> +	do {
> +		if (!irqs_disabled()) {
> +			set_current_state(TASK_INTERRUPTIBLE);
> +			schedule_timeout(usecs_to_jiffies(timeout));
> +			if (signal_pending(current))
> +				return -EINTR;
> +		} else {
> +			udelay(timeout);
> +		}
> +
> +		status = readl(syscfg->base + SYS_CFGSTAT);
> +		if (status & SYS_CFGSTAT_ERR)
> +			return -EFAULT;
> +
> +		if (timeout > 20)
> +			timeout -= 20;
> +	} while (--tries && !(status & SYS_CFGSTAT_COMPLETE));
> +	if (WARN_ON_ONCE(!tries))
> +		return -ETIMEDOUT;
> +
> +	if (!write) {
> +		*data = readl(syscfg->base + SYS_CFGDATA);
> +		dev_dbg(syscfg->dev, "func %p, read data %x\n", func, *data);
> +	}
> +
> +	return 0;
> +}
> +
> +static int vexpress_syscfg_read(void *context, unsigned int index,
> +		unsigned int *val)
> +{
> +	struct vexpress_syscfg_func *func = context;
> +
> +	return vexpress_syscfg_exec(func, index, false, val);
> +}
> +
> +static int vexpress_syscfg_write(void *context, unsigned int index,
> +		unsigned int val)
> +{
> +	struct vexpress_syscfg_func *func = context;
> +
> +	return vexpress_syscfg_exec(func, index, true, &val);
> +}
> +
> +static struct regmap_config vexpress_syscfg_regmap_config = {
> +	.lock = vexpress_config_lock,
> +	.unlock = vexpress_config_unlock,
> +	.reg_bits = 32,
> +	.val_bits = 32,
> +	.reg_read = vexpress_syscfg_read,
> +	.reg_write = vexpress_syscfg_write,
> +	.reg_format_endian = REGMAP_ENDIAN_LITTLE,
> +	.val_format_endian = REGMAP_ENDIAN_LITTLE,
> +};
> +
> +
> +static struct regmap *vexpress_syscfg_regmap_init(struct device *dev,
> +		void *context)
> +{
> +	int err;
> +	struct vexpress_syscfg *syscfg = context;
> +	struct vexpress_syscfg_func *func;
> +	struct property *prop;
> +	const __be32 *val = NULL;
> +	__be32 energy_quirk[4];
> +	int num;
> +	u32 site, position, dcc;
> +	int i;
> +
> +	err = vexpress_config_get_topo(dev->of_node, &site,
> +				&position, &dcc);
> +	if (err)
> +		return ERR_PTR(err);
> +
> +	prop = of_find_property(dev->of_node,
> +			"arm,vexpress-sysreg,func", NULL);
> +	if (!prop)
> +		return ERR_PTR(-EINVAL);
> +
> +	num = prop->length / sizeof(u32) / 2;
> +	val = prop->value;
> +
> +	/*
> +	 * "arm,vexpress-energy" function used to be described
> +	 * by its first device only, now it requires both
> +	 */
> +	if (num == 1 && of_device_is_compatible(dev->of_node,
> +			"arm,vexpress-energy")) {
> +		num = 2;
> +		energy_quirk[0] = *val;
> +		energy_quirk[2] = *val++;
> +		energy_quirk[1] = *val;
> +		energy_quirk[3] = cpu_to_be32(be32_to_cpup(val) + 1);
> +		val = energy_quirk;
> +	}
> +
> +	func = kzalloc(struct_size(func, template, num), GFP_KERNEL);
> +	if (!func)
> +		return ERR_PTR(-ENOMEM);
> +
> +	func->syscfg = syscfg;
> +	func->num_templates = num;
> +
> +	for (i = 0; i < num; i++) {
> +		u32 function, device;
> +
> +		function = be32_to_cpup(val++);
> +		device = be32_to_cpup(val++);
> +
> +		dev_dbg(dev, "func %p: %u/%u/%u/%u/%u\n",
> +				func, site, position, dcc,
> +				function, device);
> +
> +		func->template[i] = SYS_CFGCTRL_DCC(dcc);
> +		func->template[i] |= SYS_CFGCTRL_SITE(site);
> +		func->template[i] |= SYS_CFGCTRL_POSITION(position);
> +		func->template[i] |= SYS_CFGCTRL_FUNC(function);
> +		func->template[i] |= SYS_CFGCTRL_DEVICE(device);
> +	}
> +
> +	vexpress_syscfg_regmap_config.max_register = num - 1;
> +
> +	func->regmap = regmap_init(dev, NULL, func,
> +			&vexpress_syscfg_regmap_config);
> +
> +	if (IS_ERR(func->regmap)) {
> +		void *err = func->regmap;
> +
> +		kfree(func);
> +		return err;
> +	}
> +
> +	list_add(&func->list, &syscfg->funcs);
> +
> +	return func->regmap;
> +}
> +
> +static void vexpress_syscfg_regmap_exit(struct regmap *regmap, void *context)
> +{
> +	struct vexpress_syscfg *syscfg = context;
> +	struct vexpress_syscfg_func *func, *tmp;
> +
> +	regmap_exit(regmap);
> +
> +	list_for_each_entry_safe(func, tmp, &syscfg->funcs, list) {
> +		if (func->regmap == regmap) {
> +			list_del(&syscfg->funcs);
> +			kfree(func);
> +			break;
> +		}
> +	}
> +}
> +
> +static struct vexpress_config_bridge_ops vexpress_syscfg_bridge_ops = {
> +	.regmap_init = vexpress_syscfg_regmap_init,
> +	.regmap_exit = vexpress_syscfg_regmap_exit,
> +};
> +
> +
> +static int vexpress_syscfg_probe(struct platform_device *pdev)
> +{
> +	struct vexpress_syscfg *syscfg;
> +	struct resource *res;
> +	struct device *bridge;
> +
> +	syscfg = devm_kzalloc(&pdev->dev, sizeof(*syscfg), GFP_KERNEL);
> +	if (!syscfg)
> +		return -ENOMEM;
> +	syscfg->dev = &pdev->dev;
> +	INIT_LIST_HEAD(&syscfg->funcs);
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	syscfg->base = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(syscfg->base))
> +		return PTR_ERR(syscfg->base);
> +
> +	/* Must use dev.parent (MFD), as that's where DT phandle points at... */
> +	bridge = vexpress_config_bridge_register(pdev->dev.parent,
> +			&vexpress_syscfg_bridge_ops, syscfg);
> +
> +	return PTR_ERR_OR_ZERO(bridge);
> +}
> +
> +static const struct platform_device_id vexpress_syscfg_id_table[] = {
> +	{ "vexpress-syscfg", },
> +	{},
> +};
> +
> +static struct platform_driver vexpress_syscfg_driver = {
> +	.driver.name = "vexpress-syscfg",
> +	.id_table = vexpress_syscfg_id_table,
> +	.probe = vexpress_syscfg_probe,
> +};
> +
> +static int __init vexpress_syscfg_init(void)
> +{
> +	return platform_driver_register(&vexpress_syscfg_driver);
> +}
> +core_initcall(vexpress_syscfg_init);
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 99e151475d8f..edd5dd5ebfdc 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -423,15 +423,6 @@ config SRAM
>  config SRAM_EXEC
>  	bool
>  
> -config VEXPRESS_SYSCFG
> -	bool "Versatile Express System Configuration driver"
> -	depends on VEXPRESS_CONFIG
> -	default y
> -	help
> -	  ARM Ltd. Versatile Express uses specialised platform configuration
> -	  bus. System Configuration interface is one of the possible means
> -	  of generating transactions on this bus.
> -
>  config PCI_ENDPOINT_TEST
>  	depends on PCI
>  	select CRC32
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index 9abf2923d831..c7bd01ac6291 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -49,7 +49,6 @@ obj-$(CONFIG_SRAM_EXEC)		+= sram-exec.o
>  obj-y				+= mic/
>  obj-$(CONFIG_GENWQE)		+= genwqe/
>  obj-$(CONFIG_ECHO)		+= echo/
> -obj-$(CONFIG_VEXPRESS_SYSCFG)	+= vexpress-syscfg.o
>  obj-$(CONFIG_CXL_BASE)		+= cxl/
>  obj-$(CONFIG_PCI_ENDPOINT_TEST)	+= pci_endpoint_test.o
>  obj-$(CONFIG_OCXL)		+= ocxl/
> diff --git a/drivers/misc/vexpress-syscfg.c b/drivers/misc/vexpress-syscfg.c
> deleted file mode 100644
> index a431787c0898..000000000000
> --- a/drivers/misc/vexpress-syscfg.c
> +++ /dev/null
> @@ -1,280 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0-only
> -/*
> - *
> - * Copyright (C) 2014 ARM Limited
> - */
> -
> -#include <linux/delay.h>
> -#include <linux/err.h>
> -#include <linux/io.h>
> -#include <linux/of.h>
> -#include <linux/platform_device.h>
> -#include <linux/sched/signal.h>
> -#include <linux/slab.h>
> -#include <linux/syscore_ops.h>
> -#include <linux/vexpress.h>
> -
> -
> -#define SYS_CFGDATA		0x0
> -
> -#define SYS_CFGCTRL		0x4
> -#define SYS_CFGCTRL_START	(1 << 31)
> -#define SYS_CFGCTRL_WRITE	(1 << 30)
> -#define SYS_CFGCTRL_DCC(n)	(((n) & 0xf) << 26)
> -#define SYS_CFGCTRL_FUNC(n)	(((n) & 0x3f) << 20)
> -#define SYS_CFGCTRL_SITE(n)	(((n) & 0x3) << 16)
> -#define SYS_CFGCTRL_POSITION(n)	(((n) & 0xf) << 12)
> -#define SYS_CFGCTRL_DEVICE(n)	(((n) & 0xfff) << 0)
> -
> -#define SYS_CFGSTAT		0x8
> -#define SYS_CFGSTAT_ERR		(1 << 1)
> -#define SYS_CFGSTAT_COMPLETE	(1 << 0)
> -
> -
> -struct vexpress_syscfg {
> -	struct device *dev;
> -	void __iomem *base;
> -	struct list_head funcs;
> -};
> -
> -struct vexpress_syscfg_func {
> -	struct list_head list;
> -	struct vexpress_syscfg *syscfg;
> -	struct regmap *regmap;
> -	int num_templates;
> -	u32 template[]; /* Keep it last! */
> -};
> -
> -
> -static int vexpress_syscfg_exec(struct vexpress_syscfg_func *func,
> -		int index, bool write, u32 *data)
> -{
> -	struct vexpress_syscfg *syscfg = func->syscfg;
> -	u32 command, status;
> -	int tries;
> -	long timeout;
> -
> -	if (WARN_ON(index >= func->num_templates))
> -		return -EINVAL;
> -
> -	command = readl(syscfg->base + SYS_CFGCTRL);
> -	if (WARN_ON(command & SYS_CFGCTRL_START))
> -		return -EBUSY;
> -
> -	command = func->template[index];
> -	command |= SYS_CFGCTRL_START;
> -	command |= write ? SYS_CFGCTRL_WRITE : 0;
> -
> -	/* Use a canary for reads */
> -	if (!write)
> -		*data = 0xdeadbeef;
> -
> -	dev_dbg(syscfg->dev, "func %p, command %x, data %x\n",
> -			func, command, *data);
> -	writel(*data, syscfg->base + SYS_CFGDATA);
> -	writel(0, syscfg->base + SYS_CFGSTAT);
> -	writel(command, syscfg->base + SYS_CFGCTRL);
> -	mb();
> -
> -	/* The operation can take ages... Go to sleep, 100us initially */
> -	tries = 100;
> -	timeout = 100;
> -	do {
> -		if (!irqs_disabled()) {
> -			set_current_state(TASK_INTERRUPTIBLE);
> -			schedule_timeout(usecs_to_jiffies(timeout));
> -			if (signal_pending(current))
> -				return -EINTR;
> -		} else {
> -			udelay(timeout);
> -		}
> -
> -		status = readl(syscfg->base + SYS_CFGSTAT);
> -		if (status & SYS_CFGSTAT_ERR)
> -			return -EFAULT;
> -
> -		if (timeout > 20)
> -			timeout -= 20;
> -	} while (--tries && !(status & SYS_CFGSTAT_COMPLETE));
> -	if (WARN_ON_ONCE(!tries))
> -		return -ETIMEDOUT;
> -
> -	if (!write) {
> -		*data = readl(syscfg->base + SYS_CFGDATA);
> -		dev_dbg(syscfg->dev, "func %p, read data %x\n", func, *data);
> -	}
> -
> -	return 0;
> -}
> -
> -static int vexpress_syscfg_read(void *context, unsigned int index,
> -		unsigned int *val)
> -{
> -	struct vexpress_syscfg_func *func = context;
> -
> -	return vexpress_syscfg_exec(func, index, false, val);
> -}
> -
> -static int vexpress_syscfg_write(void *context, unsigned int index,
> -		unsigned int val)
> -{
> -	struct vexpress_syscfg_func *func = context;
> -
> -	return vexpress_syscfg_exec(func, index, true, &val);
> -}
> -
> -static struct regmap_config vexpress_syscfg_regmap_config = {
> -	.lock = vexpress_config_lock,
> -	.unlock = vexpress_config_unlock,
> -	.reg_bits = 32,
> -	.val_bits = 32,
> -	.reg_read = vexpress_syscfg_read,
> -	.reg_write = vexpress_syscfg_write,
> -	.reg_format_endian = REGMAP_ENDIAN_LITTLE,
> -	.val_format_endian = REGMAP_ENDIAN_LITTLE,
> -};
> -
> -
> -static struct regmap *vexpress_syscfg_regmap_init(struct device *dev,
> -		void *context)
> -{
> -	int err;
> -	struct vexpress_syscfg *syscfg = context;
> -	struct vexpress_syscfg_func *func;
> -	struct property *prop;
> -	const __be32 *val = NULL;
> -	__be32 energy_quirk[4];
> -	int num;
> -	u32 site, position, dcc;
> -	int i;
> -
> -	err = vexpress_config_get_topo(dev->of_node, &site,
> -				&position, &dcc);
> -	if (err)
> -		return ERR_PTR(err);
> -
> -	prop = of_find_property(dev->of_node,
> -			"arm,vexpress-sysreg,func", NULL);
> -	if (!prop)
> -		return ERR_PTR(-EINVAL);
> -
> -	num = prop->length / sizeof(u32) / 2;
> -	val = prop->value;
> -
> -	/*
> -	 * "arm,vexpress-energy" function used to be described
> -	 * by its first device only, now it requires both
> -	 */
> -	if (num == 1 && of_device_is_compatible(dev->of_node,
> -			"arm,vexpress-energy")) {
> -		num = 2;
> -		energy_quirk[0] = *val;
> -		energy_quirk[2] = *val++;
> -		energy_quirk[1] = *val;
> -		energy_quirk[3] = cpu_to_be32(be32_to_cpup(val) + 1);
> -		val = energy_quirk;
> -	}
> -
> -	func = kzalloc(struct_size(func, template, num), GFP_KERNEL);
> -	if (!func)
> -		return ERR_PTR(-ENOMEM);
> -
> -	func->syscfg = syscfg;
> -	func->num_templates = num;
> -
> -	for (i = 0; i < num; i++) {
> -		u32 function, device;
> -
> -		function = be32_to_cpup(val++);
> -		device = be32_to_cpup(val++);
> -
> -		dev_dbg(dev, "func %p: %u/%u/%u/%u/%u\n",
> -				func, site, position, dcc,
> -				function, device);
> -
> -		func->template[i] = SYS_CFGCTRL_DCC(dcc);
> -		func->template[i] |= SYS_CFGCTRL_SITE(site);
> -		func->template[i] |= SYS_CFGCTRL_POSITION(position);
> -		func->template[i] |= SYS_CFGCTRL_FUNC(function);
> -		func->template[i] |= SYS_CFGCTRL_DEVICE(device);
> -	}
> -
> -	vexpress_syscfg_regmap_config.max_register = num - 1;
> -
> -	func->regmap = regmap_init(dev, NULL, func,
> -			&vexpress_syscfg_regmap_config);
> -
> -	if (IS_ERR(func->regmap)) {
> -		void *err = func->regmap;
> -
> -		kfree(func);
> -		return err;
> -	}
> -
> -	list_add(&func->list, &syscfg->funcs);
> -
> -	return func->regmap;
> -}
> -
> -static void vexpress_syscfg_regmap_exit(struct regmap *regmap, void *context)
> -{
> -	struct vexpress_syscfg *syscfg = context;
> -	struct vexpress_syscfg_func *func, *tmp;
> -
> -	regmap_exit(regmap);
> -
> -	list_for_each_entry_safe(func, tmp, &syscfg->funcs, list) {
> -		if (func->regmap == regmap) {
> -			list_del(&syscfg->funcs);
> -			kfree(func);
> -			break;
> -		}
> -	}
> -}
> -
> -static struct vexpress_config_bridge_ops vexpress_syscfg_bridge_ops = {
> -	.regmap_init = vexpress_syscfg_regmap_init,
> -	.regmap_exit = vexpress_syscfg_regmap_exit,
> -};
> -
> -
> -static int vexpress_syscfg_probe(struct platform_device *pdev)
> -{
> -	struct vexpress_syscfg *syscfg;
> -	struct resource *res;
> -	struct device *bridge;
> -
> -	syscfg = devm_kzalloc(&pdev->dev, sizeof(*syscfg), GFP_KERNEL);
> -	if (!syscfg)
> -		return -ENOMEM;
> -	syscfg->dev = &pdev->dev;
> -	INIT_LIST_HEAD(&syscfg->funcs);
> -
> -	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	syscfg->base = devm_ioremap_resource(&pdev->dev, res);
> -	if (IS_ERR(syscfg->base))
> -		return PTR_ERR(syscfg->base);
> -
> -	/* Must use dev.parent (MFD), as that's where DT phandle points at... */
> -	bridge = vexpress_config_bridge_register(pdev->dev.parent,
> -			&vexpress_syscfg_bridge_ops, syscfg);
> -
> -	return PTR_ERR_OR_ZERO(bridge);
> -}
> -
> -static const struct platform_device_id vexpress_syscfg_id_table[] = {
> -	{ "vexpress-syscfg", },
> -	{},
> -};
> -
> -static struct platform_driver vexpress_syscfg_driver = {
> -	.driver.name = "vexpress-syscfg",
> -	.id_table = vexpress_syscfg_id_table,
> -	.probe = vexpress_syscfg_probe,
> -};
> -
> -static int __init vexpress_syscfg_init(void)
> -{
> -	return platform_driver_register(&vexpress_syscfg_driver);
> -}
> -core_initcall(vexpress_syscfg_init);
> diff --git a/include/linux/vexpress.h b/include/linux/vexpress.h
> index 2ec7992b054c..65096c792d57 100644
> --- a/include/linux/vexpress.h
> +++ b/include/linux/vexpress.h
> @@ -18,23 +18,6 @@
>  /* Config infrastructure */
>  
>  void vexpress_config_set_master(u32 site);
> -u32 vexpress_config_get_master(void);
> -
> -void vexpress_config_lock(void *arg);
> -void vexpress_config_unlock(void *arg);
> -
> -int vexpress_config_get_topo(struct device_node *node, u32 *site,
> -		u32 *position, u32 *dcc);
> -
> -/* Config bridge API */
> -
> -struct vexpress_config_bridge_ops {
> -	struct regmap * (*regmap_init)(struct device *dev, void *context);
> -	void (*regmap_exit)(struct regmap *regmap, void *context);
> -};
> -
> -struct device *vexpress_config_bridge_register(struct device *parent,
> -		struct vexpress_config_bridge_ops *ops, void *context);
>  
>  /* Config regmap API */
>  
> -- 
> 2.20.1
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2020-04-22 11:22 UTC|newest]

Thread overview: 136+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-19 17:07 [PATCH 00/17] Modularizing Versatile Express Rob Herring
2020-04-19 17:07 ` Rob Herring
2020-04-19 17:07 ` [PATCH 01/17] ARM: vexpress: Move vexpress_flags_set() into arch code Rob Herring
2020-04-19 17:07   ` Rob Herring
2020-04-20 15:17   ` Arnd Bergmann
2020-04-20 15:17     ` Arnd Bergmann
2020-04-22 10:15   ` Liviu Dudau
2020-04-22 10:15     ` Liviu Dudau
2020-04-22 19:04   ` Sudeep Holla
2020-04-22 19:04     ` Sudeep Holla
2020-04-19 17:07 ` [PATCH 02/17] arm64: vexpress: Don't select CONFIG_POWER_RESET_VEXPRESS Rob Herring
2020-04-19 17:07   ` Rob Herring
2020-04-20 15:18   ` Arnd Bergmann
2020-04-20 15:18     ` Arnd Bergmann
2020-04-22 10:16   ` Liviu Dudau
2020-04-22 10:16     ` Liviu Dudau
2020-04-22 19:08   ` Sudeep Holla
2020-04-22 19:08     ` Sudeep Holla
2020-04-19 17:07 ` [PATCH 03/17] arm64: vexpress: Don't select CONFIG_VEXPRESS_CONFIG Rob Herring
2020-04-19 17:07   ` Rob Herring
2020-04-20 15:18   ` Arnd Bergmann
2020-04-20 15:18     ` Arnd Bergmann
2020-04-22 19:09   ` Sudeep Holla
2020-04-22 19:09     ` Sudeep Holla
2020-04-19 17:07 ` [PATCH 04/17] power/reset: vexpress: Support building as a module Rob Herring
2020-04-19 17:07   ` Rob Herring
2020-04-20 15:23   ` Arnd Bergmann
2020-04-20 15:23     ` Arnd Bergmann
2020-04-20 17:23     ` Rob Herring
2020-04-20 17:23       ` Rob Herring
2020-04-28 19:31       ` Sebastian Reichel
2020-04-28 19:31         ` Sebastian Reichel
2020-04-22 19:11   ` Sudeep Holla
2020-04-22 19:11     ` Sudeep Holla
2020-04-19 17:07 ` [PATCH 05/17] clk: versatile: Kill CONFIG_COMMON_CLK_VERSATILE Rob Herring
2020-04-19 17:07   ` Rob Herring
2020-04-20  6:44   ` Linus Walleij
2020-04-20  6:44     ` Linus Walleij
2020-04-22  9:47   ` Stephen Boyd
2020-04-22  9:47     ` Stephen Boyd
2020-04-22 22:34     ` Rob Herring
2020-04-22 22:34       ` Rob Herring
2020-04-22 19:17   ` Sudeep Holla
2020-04-22 19:17     ` Sudeep Holla
2020-04-19 17:07 ` [PATCH 06/17] clk: versatile: Only enable SP810 on 32-bit by default Rob Herring
2020-04-19 17:07   ` Rob Herring
2020-04-20 15:26   ` Arnd Bergmann
2020-04-20 15:26     ` Arnd Bergmann
2020-04-20 17:48     ` Rob Herring
2020-04-20 17:48       ` Rob Herring
2020-04-20 20:07       ` Arnd Bergmann
2020-04-20 20:07         ` Arnd Bergmann
2020-04-22  9:48   ` Stephen Boyd
2020-04-22  9:48     ` Stephen Boyd
2020-04-22 10:20   ` Liviu Dudau
2020-04-22 10:20     ` Liviu Dudau
2020-04-22 20:52   ` Sudeep Holla
2020-04-22 20:52     ` Sudeep Holla
2020-04-23 15:38     ` Rob Herring
2020-04-23 15:38       ` Rob Herring
2020-04-19 17:08 ` [PATCH 07/17] clk: vexpress-osc: Use the devres clock API variants Rob Herring
2020-04-19 17:08   ` Rob Herring
2020-04-20 15:26   ` Arnd Bergmann
2020-04-20 15:26     ` Arnd Bergmann
2020-04-22  9:51   ` Stephen Boyd
2020-04-22  9:51     ` Stephen Boyd
2020-04-22 10:21   ` Liviu Dudau
2020-04-22 10:21     ` Liviu Dudau
2020-04-22 20:56   ` Sudeep Holla
2020-04-22 20:56     ` Sudeep Holla
2020-04-19 17:08 ` [PATCH 08/17] clk: vexpress-osc: Support building as a module Rob Herring
2020-04-19 17:08   ` Rob Herring
2020-04-20 15:27   ` Arnd Bergmann
2020-04-20 15:27     ` Arnd Bergmann
2020-04-20 17:18     ` Rob Herring
2020-04-20 17:18       ` Rob Herring
2020-04-22 11:01   ` Liviu Dudau
2020-04-22 11:01     ` Liviu Dudau
2020-04-22 21:08   ` Sudeep Holla
2020-04-22 21:08     ` Sudeep Holla
2020-04-23 13:45     ` Sudeep Holla
2020-04-23 13:45       ` Sudeep Holla
2020-04-23 15:53       ` Rob Herring
2020-04-23 15:53         ` Rob Herring
2020-04-23 16:58         ` Sudeep Holla
2020-04-23 16:58           ` Sudeep Holla
2020-04-19 17:08 ` [PATCH 09/17] mfd: vexpress-sysreg: Drop selecting CONFIG_CLKSRC_MMIO Rob Herring
2020-04-19 17:08   ` Rob Herring
2020-04-20 15:29   ` Arnd Bergmann
2020-04-20 15:29     ` Arnd Bergmann
2020-04-22 11:02   ` Liviu Dudau
2020-04-22 11:02     ` Liviu Dudau
2020-04-19 17:08 ` [PATCH 10/17] mfd: vexpress-sysreg: Drop unused syscon child devices Rob Herring
2020-04-19 17:08   ` Rob Herring
2020-04-20 15:30   ` Arnd Bergmann
2020-04-20 15:30     ` Arnd Bergmann
2020-04-22 11:18   ` Liviu Dudau
2020-04-22 11:18     ` Liviu Dudau
2020-04-19 17:08 ` [PATCH 11/17] mfd: vexpress-sysreg: Use devres API variants Rob Herring
2020-04-19 17:08   ` Rob Herring
2020-04-20 15:31   ` Arnd Bergmann
2020-04-20 15:31     ` Arnd Bergmann
2020-04-22 11:18   ` Liviu Dudau
2020-04-22 11:18     ` Liviu Dudau
2020-04-19 17:08 ` [PATCH 12/17] mfd: vexpress-sysreg: Support building as a module Rob Herring
2020-04-19 17:08   ` Rob Herring
2020-04-20 15:32   ` Arnd Bergmann
2020-04-20 15:32     ` Arnd Bergmann
2020-04-20 17:05     ` Rob Herring
2020-04-20 17:05       ` Rob Herring
2020-04-19 17:08 ` [PATCH 13/17] bus: vexpress-config: Merge vexpress-syscfg into vexpress-config Rob Herring
2020-04-19 17:08   ` Rob Herring
2020-04-20 11:45   ` Greg Kroah-Hartman
2020-04-20 11:45     ` Greg Kroah-Hartman
2020-04-22 11:22   ` Liviu Dudau [this message]
2020-04-22 11:22     ` Liviu Dudau
2020-04-19 17:08 ` [PATCH 14/17] bus: vexpress-config: simplify config bus probing Rob Herring
2020-04-19 17:08   ` Rob Herring
2020-04-22 11:58   ` Liviu Dudau
2020-04-22 11:58     ` Liviu Dudau
2020-04-19 17:08 ` [PATCH 15/17] vexpress: Move site master init to vexpress-config bus Rob Herring
2020-04-19 17:08   ` Rob Herring
2020-04-22  9:51   ` Stephen Boyd
2020-04-22  9:51     ` Stephen Boyd
2020-04-22 12:03     ` Liviu Dudau
2020-04-22 12:03       ` Liviu Dudau
2020-04-23  0:54     ` Rob Herring
2020-04-23  0:54       ` Rob Herring
2020-04-19 17:08 ` [PATCH 16/17] bus: vexpress-config: Support building as module Rob Herring
2020-04-19 17:08   ` Rob Herring
2020-04-22 12:04   ` Liviu Dudau
2020-04-22 12:04     ` Liviu Dudau
2020-04-19 17:08 ` [PATCH 17/17] ARM: vexpress: Don't select VEXPRESS_CONFIG Rob Herring
2020-04-19 17:08   ` Rob Herring
2020-04-22 12:05   ` Liviu Dudau
2020-04-22 12:05     ` Liviu Dudau

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=20200422112210.GX364558@e110455-lin.cambridge.arm.com \
    --to=liviu.dudau@arm.com \
    --cc=Kevin.Brodsky@arm.com \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=lee.jones@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=robh@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=sre@kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=will@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.