Skip to contentSkip to conversation

Syscon early initialization

RFC PATCH Superseded Michal Simek 6 participants 11 messages Feb 19, 2014 – May 9, 2014

Subsystems (7)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Syscon early initialization

Hi,

this series come from my discussion with Arnd at KS and then on some other threads/IRCs(Arnd and Mark) that SoC vendors are more and more try to add misc functionality to
one memory region. For this purpose syscon driver is in the kernel. But regular syscon driver is initialized too late
and platforms are trying to create specific code to handle it.

For this purpose the series have been created to provide early syscon initialization and regmap creation first and then attaching device.

The last patch is zynq specific patch to clear slcr driver and clock driver can profit from it too when clk regmap is ready.

Also moving syscon driver from mfs should be consider.

Mark already applied the first part to his regmap repo
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git tags/nodev

Thanks for your comments,
Michal

Changes in v2:
- Fix bad logic in early_syscon_probe
- Fix compilation failure for x86_64 reported by zero day testing system
- Regmap change available here
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git tags/nodev

Michal Simek (2):
mfd: syscon: Support early initialization
ARM: zynq: Use early syscon initialization

 arch/arm/boot/dts/zynq-7000.dtsi |   1 +
 arch/arm/mach-zynq/common.c      |   6 +-
 arch/arm/mach-zynq/slcr.c        |  42 +------------
 drivers/clk/zynq/clkc.c          |  57 ++++++-----------
 drivers/mfd/syscon.c             | 128 +++++++++++++++++++++++++++++++++------
 include/linux/mfd/syscon.h       |  11 ++++
 6 files changed, 145 insertions(+), 100 deletions(-)

--
1.8.2.3

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140219/87c965c7/attachment.sig>

#1 lore raw

RFC PATCH v2 1/2 mfd: syscon: Support early initialization

Some platforms need to get system controller ready as soon as possible.
The patch provides early_syscon_initialization which create early mapping for all syscon compatible devices in early_syscon_probe.
Regmap is get via syscon_early_regmap_lookup_by_phandle()

Regular device probes attach device to regmap via regmap_attach_dev().

For early syscon initialization is necessary to extend struct syscon and provide remove function which unmap all early init structures.

---

Changes in v2:
- Fix bad logic in early_syscon_probe
- Fix compilation failure for x86_64 reported by zero day testing system
- Regmap change available here
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git tags/nodev

 drivers/mfd/syscon.c       | 128 +++++++++++++++++++++++++++++++++++++++------
 include/linux/mfd/syscon.h |  11 ++++
 2 files changed, 122 insertions(+), 17 deletions(-)
drivers/mfd/syscon.c +111 -17
index 71841f9..8e6c611 100644
@@ -20,12 +20,15 @@
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
+#include <linux/slab.h>
 #include <linux/mfd/syscon.h>
 
 static struct platform_driver syscon_driver;
 
 struct syscon {
+	void __iomem *base;
 	struct regmap *regmap;
+	struct resource res;
 };
 
 static int syscon_match_node(struct device *dev, void *data)
@@ -95,6 +98,24 @@ struct regmap *syscon_regmap_lookup_by_pdevname(const char *s)
 }
 EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_pdevname);
 
+struct regmap *syscon_early_regmap_lookup_by_phandle(struct device_node *np,
+						     const char *property)
+{
+	struct device_node *syscon_np;
+	struct syscon *syscon;
+
+	syscon_np = of_parse_phandle(np, property, 0);
+	if (!syscon_np)
+		return ERR_PTR(-ENODEV);
+
+	syscon = syscon_np->data;
+
+	of_node_put(syscon_np);
+
+	return syscon->regmap;
+}
+EXPORT_SYMBOL_GPL(syscon_early_regmap_lookup_by_phandle);
+
 struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np,
 					const char *property)
 {
@@ -128,40 +149,112 @@ static int syscon_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct syscon *syscon;
 	struct resource *res;
-	void __iomem *base;
 
-	syscon = devm_kzalloc(dev, sizeof(*syscon), GFP_KERNEL);
+	/* Early syscon init */
+	if (pdev->dev.of_node && pdev->dev.of_node->data) {
+		syscon = pdev->dev.of_node->data;
+		res = &syscon->res;
+		regmap_attach_dev(dev, syscon->regmap, &syscon_regmap_config);
+	} else {
+
+		syscon = devm_kzalloc(dev, sizeof(*syscon), GFP_KERNEL);
+		if (!syscon)
+			return -ENOMEM;
+
+		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+		if (!res)
+			return -ENOENT;
+
+		syscon->base = devm_ioremap(dev, res->start,
+					    resource_size(res));
+		if (!syscon->base)
+			return -ENOMEM;
+
+		syscon_regmap_config.max_register = res->end - res->start - 3;
+		syscon->regmap = devm_regmap_init_mmio(dev, syscon->base,
+						&syscon_regmap_config);
+		if (IS_ERR(syscon->regmap)) {
+			dev_err(dev, "regmap init failed\n");
+			return PTR_ERR(syscon->regmap);
+		}
+	}
+
+	platform_set_drvdata(pdev, syscon);
+
+	dev_info(dev, "regmap %pR registered\n", res);
+
+	return 0;
+}
+
+static const struct platform_device_id syscon_ids[] = {
+	{ "syscon", },
+	{ }
+};
+
+static int syscon_remove(struct platform_device *pdev)
+{
+	struct syscon *syscon = platform_get_drvdata(pdev);
+
+	if (pdev->dev.of_node && pdev->dev.of_node->data) {
+		iounmap(syscon->base);
+		kfree(syscon);
+	}
+
+	return 0;
+}
+
+#ifdef CONFIG_OF
+static int early_syscon_probe(struct device_node *np)
+{
+	struct syscon *syscon;
+
+	syscon = kzalloc(sizeof(*syscon), GFP_KERNEL);
 	if (!syscon)
 		return -ENOMEM;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENOENT;
+	if (of_address_to_resource(np, 0, &syscon->res))
+		return -EINVAL;
 
-	base = devm_ioremap(dev, res->start, resource_size(res));
-	if (!base)
-		return -ENOMEM;
+	syscon->base = ioremap(syscon->res.start, resource_size(&syscon->res));
+	if (!syscon->base) {
+		pr_err("%s: Unable to map I/O memory\n", __func__);
+		return PTR_ERR(syscon->base);
+	}
 
-	syscon_regmap_config.max_register = res->end - res->start - 3;
-	syscon->regmap = devm_regmap_init_mmio(dev, base,
-					&syscon_regmap_config);
+	syscon_regmap_config.max_register = syscon->res.end -
+					    syscon->res.start - 3;
+	syscon->regmap = regmap_init_mmio(NULL, syscon->base,
+					  &syscon_regmap_config);
 	if (IS_ERR(syscon->regmap)) {
-		dev_err(dev, "regmap init failed\n");
+		pr_err("regmap init failed\n");
 		return PTR_ERR(syscon->regmap);
 	}
 
-	platform_set_drvdata(pdev, syscon);
+	np->data = syscon;
 
-	dev_info(dev, "regmap %pR registered\n", res);
+	of_node_put(np);
+
+	pr_info("%s: regmap %pR registered\n", np->full_name, &syscon->res);
 
 	return 0;
 }
 
-static const struct platform_device_id syscon_ids[] = {
-	{ "syscon", },
-	{ }
+static struct of_device_id of_syscon_ids[] = {
+	{ .compatible = "syscon" },
+	{},
 };
 
+void __init early_syscon_init(void)
+{
+	struct device_node *np;
+
+	for_each_matching_node_and_match(np, of_syscon_ids, NULL) {
+		if (early_syscon_probe(np))
+			BUG();
+	}
+}
+#endif
+
 static struct platform_driver syscon_driver = {
 	.driver = {
 		.name = "syscon",
@@ -169,6 +262,7 @@ static struct platform_driver syscon_driver = {
 		.of_match_table = of_syscon_match,
 	},
 	.probe		= syscon_probe,
+	.remove		= syscon_remove,
 	.id_table	= syscon_ids,
 };
 
include/linux/mfd/syscon.h +11 -0
index 8789fa3..465c092 100644
@@ -24,6 +24,10 @@ extern struct regmap *syscon_regmap_lookup_by_pdevname(const char *s);
 extern struct regmap *syscon_regmap_lookup_by_phandle(
 					struct device_node *np,
 					const char *property);
+extern struct regmap *syscon_early_regmap_lookup_by_phandle(
+					struct device_node *np,
+					const char *property);
+extern void early_syscon_init(void);
 #else
 static inline struct regmap *syscon_node_to_regmap(struct device_node *np)
 {
@@ -46,6 +50,13 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle(
 {
 	return ERR_PTR(-ENOSYS);
 }
+
+static struct regmap *syscon_early_regmap_lookup_by_phandle(
+					struct device_node *np,
+					const char *property)
+{
+	return ERR_PTR(-ENOSYS);
+}
 #endif
 
 #endif /* __LINUX_MFD_SYSCON_H__ */

--
1.8.2.3

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140219/f9a07fb5/attachment-0001.sig>

#10 lore raw

RFC PATCH v2 2/2 ARM: zynq: Use early syscon initialization

In reply to Michal Simek

Use early syscon initialization to simplify slcr code.
- Remove two slcr inits (zynq_slcr_init, zynq_early_slcr_init)
- Directly use regmap accesses in zynq_slcr_read/write
- Remove zynq_clock_init() and use addresses from syscon (This is the most problematic part now because clock doesn't support regmap accesses that's why reading slcr base is ugly. There are some attempts to get clk regmap to work - for example:
https://lkml.org/lkml/2013/10/16/112)

---

Changes in v2: None

Especially look at slcr.c which is much simpler than was before. clkc.c will be simpler when regmap support is added because then syscon_early_regmap_lookup_by_phandle() will be called without zynq_slcr_base search.

---
 arch/arm/boot/dts/zynq-7000.dtsi |  1 +
 arch/arm/mach-zynq/common.c      |  6 ++---
 arch/arm/mach-zynq/slcr.c        | 42 ++---------------------------
 drivers/clk/zynq/clkc.c          | 57 ++++++++++++----------------------------
 4 files changed, 23 insertions(+), 83 deletions(-)
arch/arm/boot/dts/zynq-7000.dtsi +1 -0
index 7284499..e414489 100644
@@ -135,6 +135,7 @@
 			compatible = "xlnx,zynq-slcr", "syscon";
 			reg = <0xF8000000 0x1000>;
 			ranges;
+			syscon = <&slcr>;
 			clkc: clkc at 100 {
 				#clock-cells = <1>;
 				compatible = "xlnx,ps7-clkc";
arch/arm/mach-zynq/common.c +3 -3
index 9d3c88e..78589e3 100644
@@ -28,6 +28,7 @@
 #include <linux/of.h>
 #include <linux/irqchip.h>
 #include <linux/irqchip/arm-gic.h>
+#include <linux/mfd/syscon.h>
 #include <linux/slab.h>
 #include <linux/sys_soc.h>
 
@@ -130,15 +131,14 @@ out:
 	of_platform_populate(NULL, of_default_bus_match_table, NULL, parent);
 
 	platform_device_register(&zynq_cpuidle_device);
-
-	zynq_slcr_init();
 }
 
 static void __init zynq_timer_init(void)
 {
+	early_syscon_init();
+
 	zynq_early_slcr_init();
 
-	zynq_clock_init();
 	of_clk_init(NULL);
 	clocksource_of_init();
 }
arch/arm/mach-zynq/slcr.c +2 -40

76 lines not on this page · raw message

drivers/clk/zynq/clkc.c +17 -40

72 lines not on this page · raw message

--
1.8.2.3

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140219/ab2df6b8/attachment.sig>

#2 lore raw

Re: [RFC PATCH v2 1/2] mfd: syscon: Support early initialization

In reply to Michal Simek

?????, 19 ??????? 2014, 12:04 +01:00 ?? Michal Simek <[email protected]>:

Quoted 16 lines

Some platforms need to get system controller ready as soon as possible.
The patch provides early_syscon_initialization which create early mapping for all syscon compatible devices in early_syscon_probe.
Regmap is get via syscon_early_regmap_lookup_by_phandle()

Regular device probes attach device to regmap via regmap_attach_dev().

For early syscon initialization is necessary to extend struct syscon and provide remove function which unmap all early init structures.

---

...

drivers/mfd/syscon.c static int syscon_probe(struct platform_device *pdev) · line 245

Quoted 4 lines
drivers/mfd/syscon.c +3 -0
+static struct of_device_id of_syscon_ids[] = {
+	{ .compatible = "syscon" },
+	{},
 };

You should move syscon_ids out of #ifdef CONFIG_OF

---

#3 lore raw

Re: [RFC PATCH v2 1/2] mfd: syscon: Support early initialization

?????, 19 ??????? 2014, 15:14 +04:00 ?? Alexander Shiyan <[email protected]>:

Quoted 17 lines

?????, 19 ??????? 2014, 12:04 +01:00 ?? Michal Simek <[email protected]>:

Quoted 10 lines

Some platforms need to get system controller ready as soon as possible.
The patch provides early_syscon_initialization which create early mapping for all syscon compatible devices in early_syscon_probe.
Regmap is get via syscon_early_regmap_lookup_by_phandle()

Regular device probes attach device to regmap via regmap_attach_dev().

Quoted 6 lines

For early syscon initialization is necessary to extend struct syscon and provide remove function which unmap all early init structures.

---

Quoted 8 lines

...

drivers/mfd/syscon.c static int syscon_probe(struct platform_device *pdev) · line 245

Quoted 4 lines
drivers/mfd/syscon.c +3 -0
+static struct of_device_id of_syscon_ids[] = {
+	{ .compatible = "syscon" },
+	{},
 };

You should move syscon_ids out of #ifdef CONFIG_OF

Oh, confused, sorry for noise.

---

#4 lore raw

Re: [RFC PATCH v2 1/2] mfd: syscon: Support early initialization

In reply to Michal Simek

FAO Arnd, Mark,

Quoted 23 lines

Some platforms need to get system controller ready as soon as possible.
The patch provides early_syscon_initialization which create early mapping for all syscon compatible devices in early_syscon_probe.
Regmap is get via syscon_early_regmap_lookup_by_phandle()

Regular device probes attach device to regmap via regmap_attach_dev().

For early syscon initialization is necessary to extend struct syscon and provide remove function which unmap all early init structures.

---

Changes in v2:
- Fix bad logic in early_syscon_probe
- Fix compilation failure for x86_64 reported by zero day testing system
- Regmap change available here
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git tags/nodev

Quoted 3 lines
 drivers/mfd/syscon.c       | 128 +++++++++++++++++++++++++++++++++++++++------
 include/linux/mfd/syscon.h |  11 ++++
 2 files changed, 122 insertions(+), 17 deletions(-)

I have the same reservations as last time:

http://archive.arm.linux.org.uk/lurker/message/20140212.095424.96cb7281.html

I believe you were waiting for Arnd and/or Mark to comment.

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#5 lore raw

Re: [RFC PATCH v2 1/2] mfd: syscon: Support early initialization

Quoted 29 lines · Lee Jones

FAO Arnd, Mark,

Quoted 23 lines

Some platforms need to get system controller ready as soon as possible.
The patch provides early_syscon_initialization which create early mapping for all syscon compatible devices in early_syscon_probe.
Regmap is get via syscon_early_regmap_lookup_by_phandle()

Regular device probes attach device to regmap via regmap_attach_dev().

For early syscon initialization is necessary to extend struct syscon and provide remove function which unmap all early init structures.

---

Changes in v2:
- Fix bad logic in early_syscon_probe
- Fix compilation failure for x86_64 reported by zero day testing system
- Regmap change available here
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git tags/nodev

Quoted 3 lines
 drivers/mfd/syscon.c       | 128 +++++++++++++++++++++++++++++++++++++++------
 include/linux/mfd/syscon.h |  11 ++++
 2 files changed, 122 insertions(+), 17 deletions(-)
Quoted 5 lines

I have the same reservations as last time:

http://archive.arm.linux.org.uk/lurker/message/20140212.095424.96cb7281.html

I believe you were waiting for Arnd and/or Mark to comment.

yes on Arnd because Mark already applied that regmap part. But of course any input how to get this done will be helpful.

Thanks,
Michal

Signature · 14 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/
Maintainer of Linux kernel - Xilinx Zynq ARM architecture
Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 263 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140219/df6ad924/attachment.sig>
#6 lore raw

Re: [RFC PATCH v2 1/2] mfd: syscon: Support early initialization

Quoted 6 lines · Michal Simek
Quoted 1 line · Lee Jones

I believe you were waiting for Arnd and/or Mark to comment.

yes on Arnd because Mark already applied that regmap part. But of course any input how to get this done will be helpful.

Like I said I've never seen the user you're adding for the regmap API so
I've no particular opinion on it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140219/ceafad17/attachment.sig>

#7 lore raw

Re: [RFC PATCH v2 1/2] mfd: syscon: Support early initialization

Quoted 10 lines · Mark Brown
Quoted 6 lines · Michal Simek
Quoted 1 line · Lee Jones

I believe you were waiting for Arnd and/or Mark to comment.

yes on Arnd because Mark already applied that regmap part. But of course any input how to get this done will be helpful.

Like I said I've never seen the user you're adding for the regmap API so I've no particular opinion on it.

2/2 is the code where I would like to use this when clk subsystem start to use better io helper functions then just static inline clk_readl/clk_writel.

Then my 2/2 driver will be just nicer than current implementation.

Regarding syscon changes. I think the right question is if this driver should be still in drivers/mfd/ or should be moved to somewhere else (drivers/base for example).

Thanks,
Michal

Signature · 14 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/
Maintainer of Linux kernel - Xilinx Zynq ARM architecture
Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 263 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140219/05fbfdcf/attachment.sig>
#8 lore raw

Re: [RFC PATCH v2 1/2] mfd: syscon: Support early initialization

Quoted 10 lines · Michal Simek
Quoted 2 lines · Mark Brown

Like I said I've never seen the user you're adding for the regmap API so I've no particular opinion on it.

2/2 is the code where I would like to use this when clk subsystem start to use better io helper functions then just static inline clk_readl/clk_writel.

Then my 2/2 driver will be just nicer than current implementation.

OK, but I still haven't seen the code (or Lee's concerns for that
matter).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140219/beb72790/attachment.sig>

#9 lore raw

Re: [RFC PATCH v2 1/2] mfd: syscon: Support early initialization

In reply to Michal Simek

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 6 lines · Michal Simek

Some platforms need to get system controller ready as soon as possible. The patch provides early_syscon_initialization which create early mapping for all syscon compatible devices in early_syscon_probe. Regmap is get via syscon_early_regmap_lookup_by_phandle()

Quoted 9 lines

Regular device probes attach device to regmap via
regmap_attach_dev().

For early syscon initialization is necessary to extend struct syscon and provide remove function which unmap all early init structures.

I don't have V3 in my mailbox, hence replying to this thread. The content is applicable to V3.

[...]

Quoted 10 lines
drivers/mfd/syscon.c +1 -0
@@ -95,6 +98,24 @@ struct regmap
 *syscon_regmap_lookup_by_pdevname(const char *s) } 
 EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_pdevname);
 
+struct regmap *syscon_early_regmap_lookup_by_phandle(struct

device_node *np, + const char *property) +{ + struct
device_node *syscon_np; + struct syscon *syscon; + + syscon_np =
of_parse_phandle(np, property, 0); + if (!syscon_np) + return
ERR_PTR(-ENODEV); + + syscon = syscon_np->data; + +
of_node_put(syscon_np); + + return syscon->regmap;

This fails while derefencing syscon if if early_syscon_init() has not yet been not yet been called. Something like this would be helpful.

struct regmap *regmap = ERR_PTR(-ENODEV);

syscon = syscon_np->data;
if (syscon)

	regmap = syscon->regmap;

return regmap;

- --
Tushar Behera
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJTbMZMAAoJELqclMPPkq4NoZEH/j/vTBLu0VmKm01jZqJUUC59 siD+DvRclRcdRGCzsf7iN9Zjw2g+abDtEBynBNdC6swTJJUwDyMtkcguiHn/ytPN B/5bli3rKpRkDlg9i/Cfgqd2KmYh1U6Q2LJ3+pyRAQqe0zm+bI5+fp/cn1PGLBIW 1R2rexJO98GhGO/Yhh62FD366rB15bgApC2+XjYb2Wcka3f8VY47gqkxnAwxZzvU ovG/rqXEuGW7H3o/+BLDtmQREEjKg20ggRo2FEj0WozhTo6Sn2YUJg70DKioguu0 eteP+X4DsShluJfxq9/51bfFutlXPPYZIbLIZxwyiFSJiAIR8hjLO/Ed/GicybQ= =HCI5
-----END PGP SIGNATURE-----