From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Hershberger Date: Wed, 27 Apr 2016 23:44:00 -0500 Subject: [U-Boot] [RFC PATCH] dm: ensure device names are unique In-Reply-To: <572107A5.40807@wwwdotorg.org> References: <1461706228-3092-1-git-send-email-swarren@wwwdotorg.org> <571FDF66.8020607@wwwdotorg.org> <572107A5.40807@wwwdotorg.org> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Wed, Apr 27, 2016 at 1:40 PM, Stephen Warren wrote: > On 04/26/2016 03:36 PM, Stephen Warren wrote: >> >> On 04/26/2016 03:30 PM, Stephen Warren wrote: >>> >>> From: Stephen Warren >>> >>> It is possible for HW to contain multiple instances of the same >>> device. In >>> this case, the name passed to device_bind() may not be unique across all >>> devices within its uclass. One example is a system with multiple >>> identical >>> PCI Ethernet devices. Another might be a system with multiple identical >>> I2C GPIO expanders, each connected to a separate I2C bus, yet using the >>> same I2C address on that bus and hence having the same DT node name. >>> >>> Enhance the code to detect this situation, and append a sequence >>> number so >>> the device name to ensure uniqueness. >>> >>> Signed-off-by: Stephen Warren >>> --- >>> Some possible issues with this patch: >>> >>> 1) Doing this in bind() rather than probe() means dev->seq isn't >>> available, so can't be used to generate the unique name. This process >>> should be done during bind() rather than probe() though, since devices >>> can >>> be seen (e.g. by running "dm tree") before they're probed. Perhaps the >>> uclass_resolve_seq() should be called by bind() not probe(). >>> >>> 2) uclass_find_device_by_name() needs to look up the uclass pointer again >>> even though device_bind() already knows it. >>> >>> 3) Iterating over the list to find the count of devices in the uclass >>> is a >>> bit annoying. Should the uclass maintain this count so it doesn't need to >>> be re-calculated each time? >> >> >> 4) This causes "ut dm autobind" to fail. I'll investigate that locally, >> but won't bother reposting until the questions above are considered. > > > It looks like that's because I need to add "gd->dm_root && " to the start of > the following condition: > >> @@ -62,6 +62,23 @@ int device_bind(struct udevice *parent, const struct >> driver *drv, >> dev->driver = drv; >> dev->uclass = uc; >> >> + if (!uclass_find_device_by_name(uc->uc_drv->id, dev->name, &dev2)) >> { > > > ... otherwise, the uc_class_get/find() nested inside that end up creating a > second root uclass. Makes sense. > I can fold that into v2, pending any other comments. > > _______________________________________________ > U-Boot mailing list > U-Boot at lists.denx.de > http://lists.denx.de/mailman/listinfo/u-boot