Exemplo n.º 1
0
static int __devinit fs_enet_mdio_probe(struct device *dev)
{
    struct platform_device *pdev = to_platform_device(dev);
    struct fs_mii_bb_platform_info *pdata;
    struct mii_bus *new_bus;
    struct bb_info *bitbang;
    int err = 0;

    if (NULL == dev)
        return -EINVAL;

    bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);

    if (NULL == bitbang)
        return -ENOMEM;

    bitbang->ctrl.ops = &bb_ops;

    new_bus = alloc_mdio_bitbang(&bitbang->ctrl);

    if (NULL == new_bus)
        return -ENOMEM;

    new_bus->name = "BB MII Bus",
    snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id);

    new_bus->phy_mask = ~0x9;
    pdata = (struct fs_mii_bb_platform_info *)pdev->dev.platform_data;

    if (NULL == pdata) {
        printk(KERN_ERR "gfar mdio %d: Missing platform data!\n", pdev->id);
        return -ENODEV;
    }

    /*set up workspace*/
    fs_mii_bitbang_init(bitbang, pdata);

    new_bus->priv = bitbang;

    new_bus->irq = pdata->irq;

    new_bus->dev = dev;
    dev_set_drvdata(dev, new_bus);

    err = mdiobus_register(new_bus);

    if (0 != err) {
        printk (KERN_ERR "%s: Cannot register as MDIO bus\n",
                new_bus->name);
        goto bus_register_fail;
    }

    return 0;

bus_register_fail:
    free_mdio_bitbang(new_bus);
    kfree(bitbang);

    return err;
}
static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
                                        const struct of_device_id *match)
{
	struct device_node *np = NULL;
	struct mii_bus *new_bus;
	struct bb_info *bitbang;
	int ret = -ENOMEM;
	int i;

	bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);
	if (!bitbang)
		goto out;

	bitbang->ctrl.ops = &bb_ops;

	new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
	if (!new_bus)
		goto out_free_priv;

	new_bus->name = "CPM2 Bitbanged MII",

	ret = fs_mii_bitbang_init(new_bus, ofdev->node);
	if (ret)
		goto out_free_bus;

	new_bus->phy_mask = ~0;
	new_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
	if (!new_bus->irq)
		goto out_unmap_regs;

	for (i = 0; i < PHY_MAX_ADDR; i++)
		new_bus->irq[i] = -1;

	while ((np = of_get_next_child(ofdev->node, np)))
		if (!strcmp(np->type, "ethernet-phy"))
			add_phy(new_bus, np);

	new_bus->parent = &ofdev->dev;
	dev_set_drvdata(&ofdev->dev, new_bus);

	ret = mdiobus_register(new_bus);
	if (ret)
		goto out_free_irqs;

	return 0;

out_free_irqs:
	dev_set_drvdata(&ofdev->dev, NULL);
	kfree(new_bus->irq);
out_unmap_regs:
	iounmap(bitbang->dir);
out_free_bus:
	free_mdio_bitbang(new_bus);
out_free_priv:
	kfree(bitbang);
out:
	return ret;
}
Exemplo n.º 3
0
static struct mii_bus * __devinit mdio_gpio_bus_init(struct device *dev,
					struct mdio_gpio_platform_data *pdata,
					int bus_id)
{
	struct mii_bus *new_bus;
	struct mdio_gpio_info *bitbang;
	int i;

	bitbang = kzalloc(sizeof(*bitbang), GFP_KERNEL);
	if (!bitbang)
		goto out;

	bitbang->ctrl.ops = &mdio_gpio_ops;
	bitbang->ctrl.reset = pdata->reset;
	bitbang->mdc = pdata->mdc;
	bitbang->mdio = pdata->mdio;

	new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
	if (!new_bus)
		goto out_free_bitbang;

	new_bus->name = "GPIO Bitbanged MDIO",

	new_bus->phy_mask = pdata->phy_mask;
	new_bus->irq = pdata->irqs;
	new_bus->parent = dev;

	if (new_bus->phy_mask == ~0)
		goto out_free_bus;

	for (i = 0; i < PHY_MAX_ADDR; i++)
		if (!new_bus->irq[i])
			new_bus->irq[i] = PHY_POLL;

	snprintf(new_bus->id, MII_BUS_ID_SIZE, "gpio-%x", bus_id);

	if (gpio_request(bitbang->mdc, "mdc"))
		goto out_free_bus;

	if (gpio_request(bitbang->mdio, "mdio"))
		goto out_free_mdc;

	gpio_direction_output(bitbang->mdc, 0);

	dev_set_drvdata(dev, new_bus);

	return new_bus;

out_free_mdc:
	gpio_free(bitbang->mdc);
out_free_bus:
	free_mdio_bitbang(new_bus);
out_free_bitbang:
	kfree(bitbang);
out:
	return NULL;
}
Exemplo n.º 4
0
static void mdio_gpio_bus_deinit(struct device *dev)
{
	struct mii_bus *bus = dev_get_drvdata(dev);
	struct mdio_gpio_info *bitbang = bus->priv;

	dev_set_drvdata(dev, NULL);
	gpio_free(bitbang->mdio);
	gpio_free(bitbang->mdc);
	free_mdio_bitbang(bus);
	kfree(bitbang);
}
Exemplo n.º 5
0
static int fs_enet_mdio_remove(struct device *dev)
{
    struct mii_bus *bus = dev_get_drvdata(dev);

    mdiobus_unregister(bus);

    dev_set_drvdata(dev, NULL);

    free_mdio_bitbang(bus);

    return 0;
}
Exemplo n.º 6
0
static int fs_enet_mdio_remove(struct platform_device *ofdev)
{
	struct mii_bus *bus = platform_get_drvdata(ofdev);
	struct bb_info *bitbang = bus->priv;

	mdiobus_unregister(bus);
	free_mdio_bitbang(bus);
	iounmap(bitbang->dir);
	kfree(bitbang);

	return 0;
}
static int fs_enet_mdio_remove(struct of_device *ofdev)
{
	struct mii_bus *bus = dev_get_drvdata(&ofdev->dev);
	struct bb_info *bitbang = bus->priv;

	mdiobus_unregister(bus);
	dev_set_drvdata(&ofdev->dev, NULL);
	kfree(bus->irq);
	free_mdio_bitbang(bus);
	iounmap(bitbang->dir);
	kfree(bitbang);

	return 0;
}
Exemplo n.º 8
0
static int __devinit fs_enet_mdio_probe(struct platform_device *ofdev)
{
	struct mii_bus *new_bus;
	struct bb_info *bitbang;
	int ret = -ENOMEM;

	bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);
	if (!bitbang)
		goto out;

	bitbang->ctrl.ops = &bb_ops;

	new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
	if (!new_bus)
		goto out_free_priv;

	new_bus->name = "CPM2 Bitbanged MII",

	ret = fs_mii_bitbang_init(new_bus, ofdev->dev.of_node);
	if (ret)
		goto out_free_bus;

	new_bus->phy_mask = ~0;
	new_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
	if (!new_bus->irq) {
		ret = -ENOMEM;
		goto out_unmap_regs;
	}

	new_bus->parent = &ofdev->dev;
	dev_set_drvdata(&ofdev->dev, new_bus);

	ret = of_mdiobus_register(new_bus, ofdev->dev.of_node);
	if (ret)
		goto out_free_irqs;

	return 0;

out_free_irqs:
	dev_set_drvdata(&ofdev->dev, NULL);
	kfree(new_bus->irq);
out_unmap_regs:
	iounmap(bitbang->dir);
out_free_bus:
	free_mdio_bitbang(new_bus);
out_free_priv:
	kfree(bitbang);
out:
	return ret;
}
Exemplo n.º 9
0
/* MDIO bus release function */
static int sh_mdio_release(struct net_device *ndev)
{
    struct mii_bus *bus = dev_get_drvdata(&ndev->dev);

    /* unregister mdio bus */
    mdiobus_unregister(bus);

    /* remove mdio bus info from net_device */
    dev_set_drvdata(&ndev->dev, NULL);

    /* free bitbang info */
    free_mdio_bitbang(bus);

    return 0;
}
Exemplo n.º 10
0
static int __devinit ep8248e_mdio_probe(struct platform_device *ofdev,
                                        const struct of_device_id *match)
{
	struct mii_bus *bus;
	struct resource res;
	struct device_node *node;
	int ret;

	node = of_get_parent(ofdev->dev.of_node);
	of_node_put(node);
	if (node != ep8248e_bcsr_node)
		return -ENODEV;

	ret = of_address_to_resource(ofdev->dev.of_node, 0, &res);
	if (ret)
		return ret;

	bus = alloc_mdio_bitbang(&ep8248e_mdio_ctrl);
	if (!bus)
		return -ENOMEM;

	bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
	if (bus->irq == NULL) {
		ret = -ENOMEM;
		goto err_free_bus;
	}

	bus->name = "ep8248e-mdio-bitbang";
	bus->parent = &ofdev->dev;
	snprintf(bus->id, MII_BUS_ID_SIZE, "%x", res.start);

	ret = of_mdiobus_register(bus, ofdev->dev.of_node);
	if (ret)
		goto err_free_irq;

	return 0;
err_free_irq:
	kfree(bus->irq);
err_free_bus:
	free_mdio_bitbang(bus);
	return ret;
}
Exemplo n.º 11
0
static void mdio_gpio_bus_deinit(struct device *dev)
{
	struct mii_bus *bus = dev_get_drvdata(dev);

	free_mdio_bitbang(bus);
}
Exemplo n.º 12
0
/* MDIO bus init function */
static int sh_mdio_init(struct net_device *ndev, int id)
{
    int ret, i;
    struct bb_info *bitbang;
    struct sh_eth_private *mdp = netdev_priv(ndev);

    /* create bit control struct for PHY */
    bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);
    if (!bitbang) {
        ret = -ENOMEM;
        goto out;
    }

    /* bitbang init */
    bitbang->addr = ndev->base_addr + PIR;
    bitbang->mdi_msk = 0x08;
    bitbang->mdo_msk = 0x04;
    bitbang->mmd_msk = 0x02;/* MMD */
    bitbang->mdc_msk = 0x01;
    bitbang->ctrl.ops = &bb_ops;

    /* MII contorller setting */
    mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl);
    if (!mdp->mii_bus) {
        ret = -ENOMEM;
        goto out_free_bitbang;
    }

    /* Hook up MII support for ethtool */
    mdp->mii_bus->name = "sh_mii";
    mdp->mii_bus->parent = &ndev->dev;
    snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%x", id);

    /* PHY IRQ */
    mdp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
    if (!mdp->mii_bus->irq) {
        ret = -ENOMEM;
        goto out_free_bus;
    }

    for (i = 0; i < PHY_MAX_ADDR; i++)
        mdp->mii_bus->irq[i] = PHY_POLL;

    /* regist mdio bus */
    ret = mdiobus_register(mdp->mii_bus);
    if (ret)
        goto out_free_irq;

    dev_set_drvdata(&ndev->dev, mdp->mii_bus);

    return 0;

out_free_irq:
    kfree(mdp->mii_bus->irq);

out_free_bus:
    free_mdio_bitbang(mdp->mii_bus);

out_free_bitbang:
    kfree(bitbang);

out:
    return ret;
}
Exemplo n.º 13
0
static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
					  struct mdio_gpio_platform_data *pdata,
					  int bus_id)
{
	struct mii_bus *new_bus;
	struct mdio_gpio_info *bitbang;
	int i;

	bitbang = devm_kzalloc(dev, sizeof(*bitbang), GFP_KERNEL);
	if (!bitbang)
		goto out;

	bitbang->ctrl.ops = &mdio_gpio_ops;
	bitbang->ctrl.reset = pdata->reset;
	bitbang->mdc = pdata->mdc;
	bitbang->mdc_active_low = pdata->mdc_active_low;
	bitbang->mdio = pdata->mdio;
	bitbang->mdio_active_low = pdata->mdio_active_low;
	bitbang->mdo = pdata->mdo;
	bitbang->mdo_active_low = pdata->mdo_active_low;

	new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
	if (!new_bus)
		goto out;

	new_bus->name = "GPIO Bitbanged MDIO",

	new_bus->phy_mask = pdata->phy_mask;
	new_bus->irq = pdata->irqs;
	new_bus->parent = dev;

	if (new_bus->phy_mask == ~0)
		goto out_free_bus;

	for (i = 0; i < PHY_MAX_ADDR; i++)
		if (!new_bus->irq[i])
			new_bus->irq[i] = PHY_POLL;

	if (bus_id != -1)
		snprintf(new_bus->id, MII_BUS_ID_SIZE, "gpio-%x", bus_id);
	else
		strncpy(new_bus->id, "gpio", MII_BUS_ID_SIZE);

	if (devm_gpio_request(dev, bitbang->mdc, "mdc"))
		goto out_free_bus;

	if (devm_gpio_request(dev, bitbang->mdio, "mdio"))
		goto out_free_bus;

	if (bitbang->mdo) {
		if (devm_gpio_request(dev, bitbang->mdo, "mdo"))
			goto out_free_bus;
		gpio_direction_output(bitbang->mdo, 1);
		gpio_direction_input(bitbang->mdio);
	}

	gpio_direction_output(bitbang->mdc, 0);

	dev_set_drvdata(dev, new_bus);

	return new_bus;

out_free_bus:
	free_mdio_bitbang(new_bus);
out:
	return NULL;
}