-- Sean Cross On Monday, August 5, 2013 at 3:41 PM, Duan Fugang-B38611 wrote: > From: Sean Cross [mailto:xobs@xxxxxxxxxx] > Data: Monday, August 05, 2013 3:04 PM > > To: Sascha Hauer; Duan Fugang-B38611; netdev@xxxxxxxxxxxxxxx (mailto:netdev@xxxxxxxxxxxxxxx); > > devicetree@xxxxxxxxxxxxxxx (mailto:devicetree@xxxxxxxxxxxxxxx) > > Cc: David Miller; stephen@xxxxxxxxxxxxxxxxxx (mailto:stephen@xxxxxxxxxxxxxxxxxx); Steven Rostedt; Sean Cross > > Subject: [PATCH v5] net/phy: micrel: Add OF configuration support for > > ksz9021 > > > > Some boards require custom PHY configuration, for example due to trace > > length differences. Add the ability to configure these registers in order > > to get the PHY to function on boards that need it. > > > > Because PHYs are auto-detected based on MDIO device IDs, allow PHY > > configuration to be specified in the parent Ethernet device node if no PHY > > device node is present. > > > > Signed-off-by: Sean Cross <xobs@xxxxxxxxxx (mailto:xobs@xxxxxxxxxx)> > > --- > > +static int ksz9021_load_values_from_of(struct phy_device *phydev, > > + struct device_node *of_node, u16 reg, > > + char *field1, char *field2, > > + char *field3, char *field4) > > +{ > > + int val1 = -1; > > + int val2 = -2; > > + int val3 = -3; > > + int val4 = -4; > > + int newval; > > + int matches = 0; > > + > > + if (!of_property_read_u32(of_node, field1, &val1)) > > + matches++; > > + > > + if (!of_property_read_u32(of_node, field2, &val2)) > > + matches++; > > + > > + if (!of_property_read_u32(of_node, field3, &val3)) > > + matches++; > > + > > + if (!of_property_read_u32(of_node, field4, &val4)) > > + matches++; > > + > > + if (!matches) > > + return 0; > > + > > + if (matches < 4) > > + newval = kszphy_extended_read(phydev, reg); > > + else > > + newval = 0; > > + > > + if (val1 != -1) > > + newval = ((newval & 0xfff0) | ((val1/200)&0xf) << 0); > > + > > + if (val2 != -1) > > + newval = ((newval & 0xff0f) | ((val2/200)&0xf) << 4); > > > Must be : Newval |= ... > > + > > + if (val3 != -1) > > + newval = ((newval & 0xf0ff) | ((val3/200)&0xf) << 8); > > > Must be : Newval |= ... > > + > > + if (val4 != -1) > > + newval = ((newval & 0x0fff) | ((val4/200)&0xf) << 12); > > > Must be : Newval |= ... > > + > > + return kszphy_extended_write(phydev, reg, newval); } > If all four fields are updated, then newval will start out as 0. If only a few fields are updated, then newval will start out with the previous value. If a given field is mentioned in the device tree file, then its value will change to something other than -1. If the value remains at -1, then that particular field could not be found, and it should not be modified. -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html