[U-Boot] [PATCH] 7/12 Multiadapter/multibus I2C, drivers part 4

Wolfgang Denk wd at denx.de
Wed Feb 18 23:09:35 CET 2009


Dear ksi at koi8.net,

In message <Pine.LNX.4.64ksi.0902181112400.5002 at home-gw.koi8.net> you wrote:
> 
> > Duplicating the source code (and thus the object code, too) to create
> > additional instances of basicly the same driver seems to be the wrong
> > approach to me.
> > 
> > It doesn't scale well, to say the least.
> 
> It is _NOT_ the same driver. Every bitbaged I2C driver is _DIFFERENT_. Only
> the _NAME_ is the same.

This is one way to implement it, but not the only one.

Just to give  an  example  of  a  different  implementation  (without
claiming  that that would be a better one): we could provide an array
of functions (instead of macros) for each such adapter, so  we  could
use  just  a single instance of the driver which takes the address of
the respective array as argument.

> The soft_i2c.c is _NOT_ a driver _SOURCE_. It is a _TEMPLATE_ that makes a

This is your implementation. It is not the  only  possible  implemen-
tation.  Please  try  and  open  your  mind  to  discuss  alternative
possibilities as well.

> And it can _NOT_ scale because it is impossible to make a generic driver
> _SOURCE_ for each and every hardware configuration imaginable. That existing

Impossible. Famous last words.

> soft_i2c.c makes _GENERATION_ of such a driver trivial. The only problem
> with it is it only makes _ONE_ such interface.

And it duplicates the source code for each additional instance that is
needed.

> And no, we are _NOT_ duplicating source code. Source code is _DIFFERENT_ for
> different adapters. We just creating several _INSTANCES_ using that template
> with _DIFFERENT_ parameters. And those instances are all different. The
> template itself does _NOT_ go into the final code.

Call it what you want, I call it duplication of code.

> > Is this theory or did you perform code size measurements?
> 
> It is obvious. Furthermore, it doesn't make sence to count size difference
> here because it is miniscule -- how many I2C adapters do we have on a board?

It is obvious. Famous last words again.


> The former does not require additional adapter struct member, hwadap_no.
> And, unlike the latter, it is self-contained, it doesn't require any
> external global variable to decide what to do. One can initialize all
> adapters by:
> 
> 	for (i = 0; i < NUM_I2C_ADAPTERS; i++)
> 		i2c_adap[i]->init(...);

Most probably we never *want* to initialize all adapters...


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
CONSUMER NOTICE:  Because  of  the  "Uncertainty  Principle,"  It  Is
Impossible  for  the  Consumer  to  Find  Out  at  the Same Time Both
Precisely Where This Product Is and How Fast It Is Moving.


More information about the U-Boot mailing list