diff mbox

[U-Boot,08/71] serial: Implement serial_initfunc() macro

Message ID 1347837696-3192-9-git-send-email-marex@denx.de
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Marek Vasut Sept. 16, 2012, 11:20 p.m. UTC
This macro simplifies declaration of weak aliases for per-driver
functions, which register these drivers with the serial subsystem.
The idea here is to push serial_register() calls from serial.c into
the drivers. To avoid pile of ifdef construct as it is now, create
weak aliases to these functions, which in case the driver is not
present alias onto an empty function, which is in turn optimized out
altogether.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Marek Vasut <marek.vasut@gmail.com>
Cc: Tom Rini <trini@ti.com>
Cc: Anatolij Gustschin <agust@denx.de>
Cc: Stefan Roese <sr@denx.de>
Cc: Mike Frysinger <vapier@gentoo.org>
---
 common/serial.c |    8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Tom Rini Sept. 18, 2012, 5:31 p.m. UTC | #1
On Mon, Sep 17, 2012 at 01:20:33AM +0200, Marek Vasut wrote:

> This macro simplifies declaration of weak aliases for per-driver
> functions, which register these drivers with the serial subsystem.
> The idea here is to push serial_register() calls from serial.c into
> the drivers. To avoid pile of ifdef construct as it is now, create
> weak aliases to these functions, which in case the driver is not
> present alias onto an empty function, which is in turn optimized out
> altogether.

So, did you consider and throw out the idea of something like:
common/serial.c:
void serial_initalize(void) {
  platform_serial_register();
  serial_assign(default_serial_console()->name);
}

And then every serial driver, instead of having to add a new weak
function to common/serial.c and a new function call just defines
platform_serial_register.

Or do you run into platforms that want two different serial drivers AND
you couldn't solve that with a combination of weak functions and
board-specific platform_serial_register?
Marek Vasut Sept. 18, 2012, 5:57 p.m. UTC | #2
Dear Tom Rini,

> On Mon, Sep 17, 2012 at 01:20:33AM +0200, Marek Vasut wrote:
> > This macro simplifies declaration of weak aliases for per-driver
> > functions, which register these drivers with the serial subsystem.
> > The idea here is to push serial_register() calls from serial.c into
> > the drivers. To avoid pile of ifdef construct as it is now, create
> > weak aliases to these functions, which in case the driver is not
> > present alias onto an empty function, which is in turn optimized out
> > altogether.
> 
> So, did you consider and throw out the idea of something like:
> common/serial.c:
> void serial_initalize(void) {
>   platform_serial_register();
>   serial_assign(default_serial_console()->name);
> }
> 
> And then every serial driver, instead of having to add a new weak
> function to common/serial.c and a new function call just defines
> platform_serial_register.

Yes

> Or do you run into platforms that want two different serial drivers AND
> you couldn't solve that with a combination of weak functions and
> board-specific platform_serial_register?

The point is to allow compiling in any possible combination of serial drivers, 
thus the per-driver separate init call. I'd like to get rid of this once the DM 
is present, since there'll be a method of generating the driver list 
automagically, thus dissolving this all.

So this is pretty much temporary. Yet, you are right, there are a few boards 
(really minor amount, some PPC ancient goo) that do need two drivers in.

Best regards,
Marek Vasut
diff mbox

Patch

diff --git a/common/serial.c b/common/serial.c
index 5740d4f..84dbe50 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -32,6 +32,14 @@  DECLARE_GLOBAL_DATA_PTR;
 static struct serial_device *serial_devices;
 static struct serial_device *serial_current;
 
+static void serial_null(void)
+{
+}
+
+#define serial_initfunc(name)					\
+	void name(void)						\
+		__attribute__((weak, alias("serial_null")));
+
 void serial_register(struct serial_device *dev)
 {
 #ifdef CONFIG_NEEDS_MANUAL_RELOC