From: Wolfgang Denk Date: Wed, 18 Feb 2009 23:09:35 +0100 Subject: [U-Boot] [PATCH] 7/12 Multiadapter/multibus I2C, drivers part 4 In-Reply-To: References: <499548C2.7060305@denx.de> <49967FAC.6090905@denx.de> <20090216221151.08966832E893@gemini.denx.de> <20090217224940.02BC6832E893@gemini.denx.de> <20090218001322.4A43C832E893@gemini.denx.de> <499BBD25.4070907@denx.de> <20090218182625.22E71832E43F@gemini.denx.de> Message-ID: <20090218220935.13639832E43F@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear ksi at koi8.net, In message 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.