From: Davide Ciminaghi <ciminaghi@gnudd.com>
To: linux-kernel@vger.kernel.org
Cc: rubini@gnudd.com, Giancarlo Asnaghi <giancarlo.asnaghi@st.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Ingo Molnar <mingo@redhat.com>,
Russell King <linux@arm.linux.org.uk>,
Thomas Gleixner <tglx@linutronix.de>,
devicetree@vger.kernel.org
Subject: [PATCH 16/26] x86 STA2X11 platform: add sta2x11_platform_init()
Date: Wed, 7 Aug 2013 12:20:15 +0200 [thread overview]
Message-ID: <bb52ae56c1148e8b19337859e8ebfb69f0737e41.1375867291.git.rubini@gnudd.com> (raw)
In-Reply-To: <cover.1375867291.git.rubini@gnudd.com>
This patch adds an init function which looks for connext nodes in the
device tree (compatible "pci104a,cc17") and creates a list of sta2x11
related data structures (struct sta2x11_instance_data). For each sta2x11,
the relevant four platform devices are also created (scr, apbreg,
apb-soc-regs, sctl).
Finally, of_match_tables are added to the four struct platform_driver.
Signed-off-by: Davide Ciminaghi <ciminaghi@gnudd.com>
Acked-by: Giancarlo Asnaghi <giancarlo.asnaghi@st.com>
---
arch/x86/include/asm/sta2x11.h | 17 +++++-
arch/x86/platform/sta2x11/sta2x11.c | 111 ++++++++++++++++++++++++++++++++++-
2 files changed, 125 insertions(+), 3 deletions(-)
diff --git a/arch/x86/include/asm/sta2x11.h b/arch/x86/include/asm/sta2x11.h
index cd76923..30dd761 100644
--- a/arch/x86/include/asm/sta2x11.h
+++ b/arch/x86/include/asm/sta2x11.h
@@ -21,7 +21,7 @@
#define __ASM_STA2X11_H
#include <linux/types.h>
-#include <linux/pci.h>
+#include <linux/of.h>
enum sta2x11_plat_dev {
sta2x11_sctl = 0,
@@ -34,6 +34,21 @@ enum sta2x11_plat_dev {
sta2x11_n_plat_devs,
};
+/*
+ * Data structure representing a connext instance.
+ */
+struct sta2x11_instance_data {
+ /* Instance id */
+ int id;
+ /* Registers data */
+ struct sta2x11_platform_drv_data *sctl;
+ struct sta2x11_platform_drv_data *scr;
+ struct sta2x11_platform_drv_data *apbreg;
+ struct sta2x11_platform_drv_data *apb_soc_regs;
+ /* Do not touch this from outside arch/x86/platform/sta2x11/sta2x11.c */
+ struct list_head list;
+};
+
#define STA2X11_SCTL_NAME "sta2x11-sctl"
#define STA2X11_GPIO_NAME "sta2x11-gpio"
#define STA2X11_SCR_NAME "sta2x11-scr"
diff --git a/arch/x86/platform/sta2x11/sta2x11.c b/arch/x86/platform/sta2x11/sta2x11.c
index ab3bc62..936a7ab 100644
--- a/arch/x86/platform/sta2x11/sta2x11.c
+++ b/arch/x86/platform/sta2x11/sta2x11.c
@@ -30,9 +30,14 @@
#include <linux/seq_file.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
+#include <linux/list.h>
+#include <linux/of_pci.h>
+#include <linux/of_platform.h>
#include <asm/sta2x11.h>
+static LIST_HEAD(connext_instances);
+
static inline int __reg_within_range(unsigned int r,
unsigned int start,
unsigned int end)
@@ -213,10 +218,16 @@ static int sta2x11_scr_probe(struct platform_device *dev)
}
/* The three platform drivers */
+static const struct of_device_id sctl_ids[] = {
+ { .compatible = "st,sta2x11-sctl" },
+ {}
+};
+
static struct platform_driver sta2x11_sctl_platform_driver = {
.driver = {
.name = STA2X11_SCTL_NAME,
.owner = THIS_MODULE,
+ .of_match_table = sctl_ids,
},
.probe = sta2x11_sctl_probe,
};
@@ -227,10 +238,16 @@ static int __init sta2x11_sctl_init(void)
return platform_driver_register(&sta2x11_sctl_platform_driver);
}
-static struct platform_driver sta2x11_platform_driver = {
+static const struct of_device_id apbreg_ids[] = {
+ { .compatible = "st,sta2x11-apb-regs" },
+ {}
+};
+
+static struct platform_driver sta2x11_apbreg_platform_driver = {
.driver = {
.name = STA2X11_APBREG_NAME,
.owner = THIS_MODULE,
+ .of_match_table = apbreg_ids
},
.probe = sta2x11_apbreg_probe,
};
@@ -238,13 +255,19 @@ static struct platform_driver sta2x11_platform_driver = {
static int __init sta2x11_apbreg_init(void)
{
pr_info("%s\n", __func__);
- return platform_driver_register(&sta2x11_platform_driver);
+ return platform_driver_register(&sta2x11_apbreg_platform_driver);
}
+static const struct of_device_id apb_soc_regs_ids[] = {
+ { .compatible = "st,sta2x11-apb-soc-regs" },
+ {}
+};
+
static struct platform_driver sta2x11_apb_soc_regs_platform_driver = {
.driver = {
.name = STA2X11_APB_SOC_REGS_NAME,
.owner = THIS_MODULE,
+ .of_match_table = apb_soc_regs_ids,
},
.probe = sta2x11_apb_soc_regs_probe,
};
@@ -255,10 +278,16 @@ static int __init sta2x11_apb_soc_regs_init(void)
return platform_driver_register(&sta2x11_apb_soc_regs_platform_driver);
}
+static const struct of_device_id scr_ids[] = {
+ { .compatible = "st,sta2x11-scr" },
+ {}
+};
+
static struct platform_driver sta2x11_scr_platform_driver = {
.driver = {
.name = STA2X11_SCR_NAME,
.owner = THIS_MODULE,
+ .of_match_table = scr_ids,
},
.probe = sta2x11_scr_probe,
};
@@ -269,10 +298,88 @@ static int __init sta2x11_scr_init(void)
return platform_driver_register(&sta2x11_scr_platform_driver);
}
+
+static struct platform_device *
+do_create(const char *c, struct device_node *from,
+ struct sta2x11_instance_data *idata)
+{
+ struct device_node *n;
+ struct platform_device *out = NULL;
+ int name_size;
+ char *name;
+
+ n = of_find_compatible_node(of_node_get(from), NULL, c);
+ if (!n)
+ return out;
+ /* %s.%1d */
+ name_size = strlen(n->name) + 3;
+ name = kzalloc(name_size, GFP_KERNEL);
+ if (!name)
+ return out;
+ snprintf(name, name_size, "%s.%1d", n->name, idata->id);
+
+ out = of_platform_device_create(n, name, NULL);
+ of_node_put(n);
+
+ if (!out) {
+ kfree(name);
+ return out;
+ }
+ /*
+ Avoid the node to be re-instantiated later on
+ by the pci-amba bridge
+ */
+ of_detach_node(n);
+ return out;
+}
+
+static int new_connext(struct device_node *from,
+ struct sta2x11_instance_data *idata)
+{
+ int i;
+ /* Create platform devices belonging to this connext instance */
+ const char *devs[] = {
+ "st,sta2x11-scr",
+ "st,sta2x11-apb-soc-regs",
+ "st,sta2x11-apb-regs",
+ "st,sta2x11-sctl",
+ };
+ for (i = 0; i < ARRAY_SIZE(devs); i++)
+ WARN_ON(!do_create(devs[i], from, idata));
+ return 0;
+}
+
+static int __init sta2x11_platform_init(void)
+{
+ struct device_node *n;
+ int ret = 0, stat;
+ struct sta2x11_instance_data *idata;
+ struct resource r;
+
+ for_each_compatible_node(n, NULL, "pci104a,cc17") {
+ if (of_pci_parse_bus_range(of_node_get(n), &r) < 0) {
+ ret = -EINVAL;
+ continue;
+ }
+ idata = kzalloc(sizeof(*idata), GFP_KERNEL);
+ if (!idata) {
+ ret = -ENOMEM;
+ continue;
+ }
+ idata->id = r.start + 1;
+ list_add(&idata->list, &connext_instances);
+ stat = new_connext(n, idata);
+ if (stat < 0)
+ ret = stat;
+ }
+ return ret;
+}
+
subsys_initcall(sta2x11_apbreg_init);
subsys_initcall(sta2x11_sctl_init);
subsys_initcall(sta2x11_apb_soc_regs_init);
subsys_initcall(sta2x11_scr_init);
+rootfs_initcall(sta2x11_platform_init);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Wind River");
--
1.7.7.2
next prev parent reply other threads:[~2013-08-07 10:26 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-07 10:16 [PATCH 00/26] STA2X11 devicetree support for amba/pci Alessandro Rubini
2013-08-07 10:16 ` [PATCH 01/26] x86: fix warning for sta2x11 Alessandro Rubini
2013-08-07 10:16 ` [PATCH 02/26] DMA: PL330: use prefix in reg names to build under x86 Alessandro Rubini
2013-08-07 10:16 ` [PATCH 03/26] mmc: Use the new <linux/sizes.h> Alessandro Rubini
2013-08-07 10:17 ` [PATCH 04/26] x86: add CONFIG_ARM_AMBA, selected by STA2X11 Alessandro Rubini
2013-08-07 10:17 ` [PATCH 05/26] drivers/amba: add support for a PCI bridge Alessandro Rubini
2013-08-07 10:17 ` [PATCH 06/26] x86 STA2X11: select devicetree related config items Davide Ciminaghi
2013-08-07 10:17 ` [PATCH 07/26] OF platform: export of_amba_device_create() Davide Ciminaghi
2013-08-07 10:17 ` [PATCH 08/26] OF platform, of_amba_device_create(): add parent resource to parameters Davide Ciminaghi
2013-08-07 10:17 ` [PATCH 09/26] kernel irqdomain: export irq_domain_disassociate() Davide Ciminaghi
2013-08-07 10:19 ` [PATCH 10/26] x86 devicetree: add irq domain for msi irqs Davide Ciminaghi
2013-08-07 10:19 ` [PATCH 11/26] x86 devicetree: add functions for handling setup/teardown of MSI irqs Davide Ciminaghi
2013-08-07 10:19 ` [PATCH 12/26] x86 kernel apic: notify MSI irqdomain(s) on etup/teardown of MSI IRQs Davide Ciminaghi
2013-08-07 10:19 ` [PATCH 13/26] drivers/amba/pci-amba.c: use devicetree for amba device creation Davide Ciminaghi
2013-08-07 10:19 ` [PATCH 14/26] gpio: remove sta2x11-gpio Davide Ciminaghi
2013-08-07 19:49 ` Linus Walleij
2013-08-07 10:20 ` [PATCH 15/26] x86 STA2X11: remove the sta2x11-mfd driver Davide Ciminaghi
2013-08-07 10:20 ` Davide Ciminaghi [this message]
2013-08-07 10:20 ` [PATCH 17/26] x86 STA2X11 platform: add sta2x11_instance_data helpers Davide Ciminaghi
2013-08-07 10:20 ` [PATCH 18/26] x86 STA2X11 platform: add a common probe function for platform devices Davide Ciminaghi
2013-08-07 10:20 ` [PATCH 19/26] x86 STA2X11 platform: create sta2x11-clock-regs device Davide Ciminaghi
2013-08-07 10:20 ` [PATCH 20/26] x86 STA2X11 platform: remove useless pr_info()'s Davide Ciminaghi
2013-08-07 10:21 ` [PATCH 21/26] AMBA: pci-amba bridge: improve code readability Davide Ciminaghi
2013-08-07 10:21 ` [PATCH 22/26] AMBA: pci-amba bridge: extend number of amba devs per pci device Davide Ciminaghi
2013-08-07 10:21 ` [PATCH 23/26] AMBA: pci-amba bridge: export function creating pci-amba device names Davide Ciminaghi
2013-08-07 10:21 ` [PATCH 24/26] x86 STA2X11: add dts for Intel's Northville board Davide Ciminaghi
2013-08-07 10:21 ` [PATCH 25/26] drivers/clk: sta2x11 common clock framework implementation Davide Ciminaghi
2013-08-07 10:22 ` [PATCH 26/26] pinctrl: add support for sta2x11 (via pinctrl-nomadik) Davide Ciminaghi
2013-08-07 19:47 ` Linus Walleij
2013-08-07 20:43 ` Alessandro Rubini
2013-08-07 15:41 ` [PATCH 00/26] STA2X11 devicetree support for amba/pci H. Peter Anvin
2013-08-07 21:12 ` Alessandro Rubini
2013-08-07 21:15 ` H. Peter Anvin
2013-08-07 22:05 ` H. Peter Anvin
2013-08-07 22:12 ` H. Peter Anvin
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=bb52ae56c1148e8b19337859e8ebfb69f0737e41.1375867291.git.rubini@gnudd.com \
--to=ciminaghi@gnudd.com \
--cc=devicetree@vger.kernel.org \
--cc=giancarlo.asnaghi@st.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=mingo@redhat.com \
--cc=rubini@gnudd.com \
--cc=tglx@linutronix.de \
--cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®