embedded linux - how to retrieve bus pointer from device tree -


question:

i'm trying find way retrieve dev object mdio_bus has been added device tree. i'm sure i'm going rapidly applying palm forehead when past this, life of me, can't find answer anywhere. i've seen how find objects on bus using bus_find_device_by_name(), can't seem find how bus itself.

background:

we providing network access our host using micrel ksz8863 ethernet switch attached macb on at919g20. rather using fixed phy option, i've spoofed mdio address 0 "fake" phy representing fixed mii link switch. i'm writing driver switch receive interrupts , monitor outward facing phys , control link state of "fake" phy host. in order configure switch beyond basic miim configuration, need use smi on mdio bus access full array of registers in switch. through further tweaking of mii_read/write functions in macb, adding header reg address, believe can use macb's mdio/mii controller right thing smi requests. because bus no longer gets addressed phy:reg, need able issue raw read/write commands straight bus switch driver. , brings me question: how request dev object of mdio_bus device tree name?

thanks, brian

after hunting around, fruitlessly, way retrieve device pointer mii_bus object, ended coming following solution. i'm not sure best way go it, seems pretty clean. ended adding helper function mdio_bus.c allows driver search bus name using class_find_device(). i'm sure there better way this, doesn't involve adding onto bus' driver, doesn't seem worst way either.

-brian

here functions added mdio_bus.c:

/**  * mdiobus_match_name - compares specified string device name   * @dev: device object examined  * @data: pointer string compare device name  *  * description: matching function used in call class_find_device() find  *              device specified name  */ static int mdiobus_match_name( struct device * dev, void * data ) {     const char * name = data;      return sysfs_streq( name, dev_name( dev ) ); }  /**  * mdiobus_find_by_name - convenience function retrieving mii_bus pointer  *                        name  * @name: name of bus being searched  */ struct mii_bus * mdiobus_find_by_name( char * name ) {     struct device * dev;      /* search devices registered mdio_bus_class using device        name matching criteria */     dev = class_find_device( &mdio_bus_class,                              null,                              (void *)name,                              mdiobus_match_name );      /* return mii_bus pointer or null if none found */     return dev ? container_of( dev, struct mii_bus, dev ) : null; } export_symbol( mdiobus_find_by_name ); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -