From: Alexander Holler <holler@ahsoftware.de>
To: linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Russell King <linux@arm.linux.org.uk>,
Grant Likely <grant.likely@linaro.org>,
Alexander Holler <holler@ahsoftware.de>
Subject: [PATCH 05/14] init: deps: order I2C bus drivers by their ID
Date: Sat, 17 Oct 2015 19:14:18 +0200 [thread overview]
Message-ID: <1445102067-11519-6-git-send-email-holler@ahsoftware.de> (raw)
In-Reply-To: <1445102067-11519-1-git-send-email-holler@ahsoftware.de>
In order to provide a stable I2C bus numbering, we order I2C bus drivers
according to their driver ID.
If that is better or worse than ordering by link order might have to be
discussed, but for now, it's good to provide an example about how to order
something based on driver IDs.
Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
include/linux/driver_ids.h | 9 +++++++++
init/dependencies.c | 25 +++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/include/linux/driver_ids.h b/include/linux/driver_ids.h
index 1133a68..330080e 100644
--- a/include/linux/driver_ids.h
+++ b/include/linux/driver_ids.h
@@ -17,6 +17,15 @@ enum {
/* To be filled */
/*
+ * I2C bus drivers will be ordered according to their ID (which
+ * means according to their appearance here).
+ * This provides stable I2C bus numbers.
+ * Therefor their IDs have to be in the following block.
+ */
+ drvid_i2c_busses_start,
+ drvid_i2c_busses_end,
+
+ /*
* Network drivers will be ordered according to the link order
* (which means not necessarily according to their appearance
* here).
diff --git a/init/dependencies.c b/init/dependencies.c
index 027fc4b..d20d6fc 100644
--- a/init/dependencies.c
+++ b/init/dependencies.c
@@ -298,10 +298,22 @@ static int __init add_dependencies(void)
return 0;
}
+static int __init compare_unsigned(const void *lhs, const void *rhs)
+{
+ if (*(unsigned *)lhs < *(unsigned *)rhs)
+ return -1;
+ if (*(unsigned *)lhs > *(unsigned *)rhs)
+ return 1;
+ return 0;
+}
+
static void __init build_inventory(void)
{
const struct _annotated_initcall *ac;
unsigned id_last_network_driver = 0;
+ unsigned id_i2c_bus_driver[drvid_i2c_busses_end
+ - drvid_i2c_busses_start];
+ unsigned count_i2c_bus_drivers = 0;
ac = __annotated_initcall_start;
for (; ac < __annotated_initcall_end; ++ac) {
@@ -316,6 +328,19 @@ static void __init build_inventory(void)
id_last_network_driver);
id_last_network_driver = ac->id;
}
+ /* order I2C bus drivers by their ID */
+ if (ac->id > drvid_i2c_busses_start &&
+ ac->id < drvid_i2c_busses_end)
+ id_i2c_bus_driver[count_i2c_bus_drivers++] = ac->id;
+ }
+ if (count_i2c_bus_drivers > 1) {
+ unsigned i;
+
+ sort(id_i2c_bus_driver, count_i2c_bus_drivers,
+ sizeof(unsigned), &compare_unsigned, NULL);
+ for (i = 1; i < count_i2c_bus_drivers; ++i)
+ add_initcall_dependency(id_i2c_bus_driver[i],
+ id_i2c_bus_driver[i-1]);
}
}
--
2.1.0
next prev parent reply other threads:[~2015-10-17 17:15 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-17 17:14 [PATCH 0/14] init: deps: dependency based (parallelized) init Alexander Holler
2015-10-17 17:14 ` [PATCH 01/14] init: deps: introduce annotated initcalls Alexander Holler
2015-10-17 17:14 ` [PATCH 02/14] init: deps: use annotated initcalls for a dependency based (optionally parallelized) init Alexander Holler
2015-10-17 17:14 ` [PATCH 03/14] init: deps: dt: use (HW-specific) dependencies provided by the DT too Alexander Holler
2015-10-19 12:37 ` Mark Brown
2015-10-19 16:27 ` Rob Herring
2015-10-19 17:24 ` Alexander Holler
2015-10-19 17:10 ` Alexander Holler
2015-10-17 17:14 ` [PATCH 04/14] init: deps: order network interfaces by link order Alexander Holler
2015-10-17 18:23 ` Linus Torvalds
2015-10-17 18:37 ` Alexander Holler
2015-10-17 18:52 ` Linus Torvalds
2015-10-17 19:01 ` Alexander Holler
2015-10-17 19:08 ` Linus Torvalds
2015-10-17 19:14 ` Alexander Holler
2015-10-17 19:36 ` Greg Kroah-Hartman
2015-10-17 19:58 ` Alexander Holler
2015-10-17 21:20 ` Alexander Holler
2015-10-18 4:59 ` Alexander Holler
2015-10-18 5:14 ` Greg Kroah-Hartman
2015-10-18 5:20 ` Alexander Holler
2015-10-18 5:59 ` Greg Kroah-Hartman
2015-10-18 10:11 ` Alexander Holler
2015-10-19 10:57 ` Alexander Holler
2015-10-19 11:31 ` Alexander Holler
2015-10-22 6:47 ` Alexander Holler
2015-10-17 19:37 ` Linus Torvalds
2015-10-17 21:32 ` Alexander Holler
2015-10-17 18:55 ` Greg Kroah-Hartman
2015-10-17 19:03 ` Linus Torvalds
2015-10-17 19:07 ` Alexander Holler
2015-10-17 17:14 ` Alexander Holler [this message]
2015-10-17 17:14 ` [PATCH 06/14] dtc: deps: Automatically add new property 'dependencies' which contains a list of referenced phandles Alexander Holler
2015-10-17 17:14 ` [PATCH 07/14] dtc: deps: introduce new (virtual) property no-dependencies Alexander Holler
2015-10-17 17:14 ` [PATCH 08/14] dtc: deps: Add option to print initialization order Alexander Holler
2015-10-17 17:14 ` [PATCH 09/14] dtc: deps: Add option to print dependency graph as dot (Graphviz) Alexander Holler
2015-10-17 17:14 ` [PATCH 10/14] init: deps: IDs for annotated initcalls Alexander Holler
2015-10-17 17:45 ` Greg Kroah-Hartman
2015-10-17 17:55 ` Alexander Holler
2015-10-17 18:29 ` Greg Kroah-Hartman
2015-10-17 18:46 ` Alexander Holler
2015-10-19 13:12 ` Mark Brown
2015-10-20 10:30 ` Alexander Holler
2015-10-20 10:42 ` Alexander Holler
2015-10-20 10:50 ` Alexander Holler
2015-10-20 10:57 ` Alexander Holler
2015-10-17 17:14 ` [PATCH 11/14] init: deps: annotate various initcalls Alexander Holler
2015-10-17 18:47 ` Linus Torvalds
2015-10-17 18:59 ` Alexander Holler
2015-10-17 17:14 ` [PATCH 12/14] dt: dts: deps: kirkwood: dockstar: add dependency ehci -> usb power regulator Alexander Holler
2015-10-17 17:14 ` [PATCH 13/14] dt: dts: deps: imx6q: make some remote-endpoints non-dependencies Alexander Holler
2015-10-17 17:14 ` [PATCH 14/14] dt: dts: deps: omap: beagle: " Alexander Holler
2015-10-17 17:44 ` [PATCH 0/14] init: deps: dependency based (parallelized) init Greg Kroah-Hartman
2015-10-17 18:19 ` Alexander Holler
2015-10-17 18:38 ` Greg Kroah-Hartman
2015-10-17 19:43 ` Alexander Holler
2015-10-17 20:20 ` Greg Kroah-Hartman
2015-10-17 20:37 ` Alexander Holler
2015-11-06 16:07 ` Alexander Holler
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=1445102067-11519-6-git-send-email-holler@ahsoftware.de \
--to=holler@ahsoftware.de \
--cc=akpm@linux-foundation.org \
--cc=grant.likely@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=torvalds@linux-foundation.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®