Пример #1
0
int __devinit zmii_attach(struct platform_device *ofdev, int input, int *mode)
{
	struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
	struct zmii_regs __iomem *p = dev->base;

	ZMII_DBG(dev, "init(%d, %d)" NL, input, *mode);

	if (!zmii_valid_mode(*mode)) {
		dev->users++;
		return 0;
	}

	mutex_lock(&dev->lock);

	if (dev->mode == PHY_MODE_NA) {
		if (*mode == PHY_MODE_NA) {
			u32 r = dev->fer_save;

			ZMII_DBG(dev, "autodetecting mode, FER = 0x%08x" NL, r);

			if (r & (ZMII_FER_MII(0) | ZMII_FER_MII(1)))
				dev->mode = PHY_MODE_MII;
			else if (r & (ZMII_FER_RMII(0) | ZMII_FER_RMII(1)))
				dev->mode = PHY_MODE_RMII;
			else
				dev->mode = PHY_MODE_SMII;
		} else
			dev->mode = *mode;

		printk(KERN_NOTICE "%s: bridge in %s mode\n",
		       ofdev->dev.of_node->full_name,
		       zmii_mode_name(dev->mode));
	} else {
		
		if (*mode != PHY_MODE_NA && *mode != dev->mode) {
			printk(KERN_ERR
			       "%s: invalid mode %d specified for input %d\n",
			       ofdev->dev.of_node->full_name, *mode, input);
			mutex_unlock(&dev->lock);
			return -EINVAL;
		}
	}

	*mode = dev->mode;

	
	out_be32(&p->fer, in_be32(&p->fer) | zmii_mode_mask(dev->mode, input));
	++dev->users;

	mutex_unlock(&dev->lock);

	return 0;
}
Пример #2
0
int __devinit zmii_attach(struct of_device *ofdev, int input, int *mode)
{
    struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
    struct zmii_regs __iomem *p = dev->base;

    ZMII_DBG(dev, "init(%d, %d)" NL, input, *mode);

    if (!zmii_valid_mode(*mode)) {
        /* Probably an EMAC connected to RGMII,
         * but it still may need ZMII for MDIO so
         * we don't fail here.
         */
        dev->users++;
        return 0;
    }

    mutex_lock(&dev->lock);

    /* Autodetect ZMII mode if not specified.
     * This is only for backward compatibility with the old driver.
     * Please, always specify PHY mode in your board port to avoid
     * any surprises.
     */
    if (dev->mode == PHY_MODE_NA) {
        if (*mode == PHY_MODE_NA) {
            u32 r = dev->fer_save;

            ZMII_DBG(dev, "autodetecting mode, FER = 0x%08x" NL, r);

            if (r & (ZMII_FER_MII(0) | ZMII_FER_MII(1)))
                dev->mode = PHY_MODE_MII;
            else if (r & (ZMII_FER_RMII(0) | ZMII_FER_RMII(1)))
                dev->mode = PHY_MODE_RMII;
            else
                dev->mode = PHY_MODE_SMII;
        } else
            dev->mode = *mode;

        printk(KERN_NOTICE "%s: bridge in %s mode\n",
               ofdev->dev.of_node->full_name,
               zmii_mode_name(dev->mode));
    } else {
        /* All inputs must use the same mode */
        if (*mode != PHY_MODE_NA && *mode != dev->mode) {
            printk(KERN_ERR
                   "%s: invalid mode %d specified for input %d\n",
                   ofdev->dev.of_node->full_name, *mode, input);
            mutex_unlock(&dev->lock);
            return -EINVAL;
        }
    }

    /* Report back correct PHY mode,
     * it may be used during PHY initialization.
     */
    *mode = dev->mode;

    /* Enable this input */
    out_be32(&p->fer, in_be32(&p->fer) | zmii_mode_mask(dev->mode, input));
    ++dev->users;

    mutex_unlock(&dev->lock);

    return 0;
}
Пример #3
0
static int __init zmii_init(struct ocp_device *ocpdev, int input, int *mode)
{
	struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev);
	struct zmii_regs __iomem *p;

	ZMII_DBG("%d: init(%d, %d)" NL, ocpdev->def->index, input, *mode);

	if (!dev) {
		dev = kzalloc(sizeof(struct ibm_ocp_zmii), GFP_KERNEL);
		if (!dev) {
			printk(KERN_ERR
			       "zmii%d: couldn't allocate device structure!\n",
			       ocpdev->def->index);
			return -ENOMEM;
		}
		dev->mode = PHY_MODE_NA;

		p = ioremap(ocpdev->def->paddr, sizeof(struct zmii_regs));
		if (!p) {
			printk(KERN_ERR
			       "zmii%d: could not ioremap device registers!\n",
			       ocpdev->def->index);
			kfree(dev);
			return -ENOMEM;
		}
		dev->base = p;
		ocp_set_drvdata(ocpdev, dev);
		
		/* We may need FER value for autodetection later */
		dev->fer_save = in_be32(&p->fer);

		/* Disable all inputs by default */
		out_be32(&p->fer, 0);
	} else
		p = dev->base;

	if (!zmii_valid_mode(*mode)) {
		/* Probably an EMAC connected to RGMII, 
		 * but it still may need ZMII for MDIO 
		 */
		goto out;
	}

	/* Autodetect ZMII mode if not specified.
	 * This is only for backward compatibility with the old driver.
	 * Please, always specify PHY mode in your board port to avoid
	 * any surprises.
	 */
	if (dev->mode == PHY_MODE_NA) {
		if (*mode == PHY_MODE_NA) {
			u32 r = dev->fer_save;

			ZMII_DBG("%d: autodetecting mode, FER = 0x%08x" NL,
				 ocpdev->def->index, r);
			
			if (r & (ZMII_FER_MII(0) | ZMII_FER_MII(1)))
				dev->mode = PHY_MODE_MII;
			else if (r & (ZMII_FER_RMII(0) | ZMII_FER_RMII(1)))
				dev->mode = PHY_MODE_RMII;
			else
				dev->mode = PHY_MODE_SMII;
		} else
			dev->mode = *mode;

		printk(KERN_NOTICE "zmii%d: bridge in %s mode\n",
		       ocpdev->def->index, zmii_mode_name(dev->mode));
	} else {
		/* All inputs must use the same mode */
		if (*mode != PHY_MODE_NA && *mode != dev->mode) {
			printk(KERN_ERR
			       "zmii%d: invalid mode %d specified for input %d\n",
			       ocpdev->def->index, *mode, input);
			return -EINVAL;
		}
	}

	/* Report back correct PHY mode, 
	 * it may be used during PHY initialization.
	 */
	*mode = dev->mode;

	/* Enable this input */
	out_be32(&p->fer, in_be32(&p->fer) | zmii_mode_mask(dev->mode, input));
      out:
	++dev->users;
	return 0;
}