/* Returns 0 if write succeed, -EINVAL on bad parameters -ETIME on timeout  */
static int mvneta_mdio_write(struct mii_dev *bus, int addr, int devad, int reg, u16 value)
/* Returns 0 if write succeed, -EINVAL on bad parameters -ETIME on timeout  */
static int mvneta_mdio_write(struct mii_dev *bus, int addr, int devad, int reg, u16 value)
{
	struct mvneta_port *pp = bus->priv;
	u32 smi_reg;
	if (addr > MVNETA_PHY_ADDR_MASK) {
		printf("Error: Invalid PHY address %d\n", addr);
		return -EFAULT;
	}
	if (reg > MVNETA_PHY_REG_MASK) {
		printf("Err: Invalid register offset %d\n", reg);
		return -EFAULT;
	}
	if (smi_wait_ready(pp) < 0)
		return -EFAULT;
	smi_reg = value << MVNETA_SMI_DATA_OFFS;
	smi_reg |= (addr << MVNETA_SMI_DEV_ADDR_OFFS)
		| (reg << MVNETA_SMI_REG_ADDR_OFFS);
	smi_reg &= ~MVNETA_SMI_OPCODE_READ;
	mvreg_write(pp, MVNETA_SMI, smi_reg);
	return 0;
}