[U-Boot] [PATCH v2 12/13] drivers: net: add Microchip PIC32 ethernet controller driver.
Purna Chandra Mandal
purna.mandal at microchip.com
Wed Jan 6 12:01:27 CET 2016
On 01/06/2016 02:32 AM, Daniel Schwierzeck wrote:
> [...]
> +
> +static int _pic32eth_init(struct pic32eth_device *pedev, u8 *macaddr)
> +{
> + int ret;
> +
> + /* configure controller */
> + _eth_ctrl_reset(pedev);
> +
> + /* reset mac_regs */
> + _mac_reset(pedev);
> +
> + /* configure the PHY */
> + phy_config(pedev->phydev);
> +
> + /* initialize MAC */
> + _mac_init(pedev, macaddr);
> +
> + /* init RX descriptor; TX descriptors are handled in xmit */
> + _eth_desc_init(pedev);
> I am not sure if there is a convention but I would replace all
> function names with a leading underscore to pic32_*
>
ack. Rename functions accordingly.
>> +
>> + /* Start up & update link status of PHY */
>> + phy_startup(pedev->phydev);
>> +
>> + /* adjust mac with phy link status */
>> + ret = _mac_adjust_link(pedev);
>> + if (ret) {
>> + _pic32eth_halt(pedev);
>> + return ret;
>> + }
>> +
>> + return 0;
>> +}
>> +
>> [...]
>> +
>> +static int pic32_eth_probe(struct udevice *dev)
>> +{
>> + struct eth_pdata *pdata = dev_get_platdata(dev);
>> + struct pic32eth_device *priv = dev_get_priv(dev);
>> + void __iomem *iobase;
>> + int phy_addr = 0;
>> +
>> +#if defined(CONFIG_PHY_ADDR)
>> + phy_addr = CONFIG_PHY_ADDR;
>> +#endif
>> + iobase = pic32_ioremap((ulong)pdata->iobase);
>> +
>> + /* initialize */
>> + priv->phy_addr = phy_addr;
>> + priv->phyif = pdata->phy_interface;
>> + priv->ectl_regs = (struct pic32_ectl_regs *)(iobase);
>> + priv->emac_regs = (struct pic32_emac_regs *)(iobase + PIC32_EMAC1CFG1);
>> +
>> + gpio_request_by_name_nodev(gd->fdt_blob, dev->of_offset,
>> + "reset-gpios", 0,
>> + &priv->rst_gpio, GPIOD_IS_OUT);
>> + _mdio_init(priv);
>> +
>> + return _phy_init(priv, dev);
>> +}
>> +
>> +static int pic32_eth_remove(struct udevice *dev)
>> +{
>> + struct pic32eth_device *priv = dev_get_priv(dev);
>> + struct mii_dev *bus;
>> +
>> + dm_gpio_free(dev, &priv->rst_gpio);
>> + phy_shutdown(priv->phydev);
>> + free(priv->phydev);
>> + bus = miiphy_get_dev_by_name(PIC32_MDIO_NAME);
>> + mdio_unregister(bus);
>> + mdio_free(bus);
>> +
>> + return 0;
>> +}
>> +
>> +static int pic32_eth_ofdata_to_platdata(struct udevice *dev)
>> +{
>> + struct eth_pdata *pdata = dev_get_platdata(dev);
>> + const char *phy_mode;
>> +
>> + pdata->iobase = dev_get_addr(dev);
>> + pdata->phy_interface = -1;
>> + phy_mode = fdt_getprop(gd->fdt_blob, dev->of_offset, "phy-mode", NULL);
>> + if (phy_mode)
>> + pdata->phy_interface = phy_get_interface_by_name(phy_mode);
>> +
>> + if (pdata->phy_interface == -1) {
>> + debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
>> + return -EINVAL;
>> + }
>> +
>> + return 0;
> all that code could be moved to pic32_eth_probe()
ack. Will update.
>> +}
>> +
>> +static const struct udevice_id pic32_eth_ids[] = {
>> + { .compatible = "microchip,pic32mzda-eth" },
>> + { }
>> +};
>> +
>> +U_BOOT_DRIVER(pic32_ethernet) = {
>> + .name = "pic32_ethernet",
>> + .id = UCLASS_ETH,
>> + .of_match = pic32_eth_ids,
>> + .ofdata_to_platdata = pic32_eth_ofdata_to_platdata,
>> + .probe = pic32_eth_probe,
>> + .remove = pic32_eth_remove,
>> + .ops = &pic32_eth_ops,
>> + .priv_auto_alloc_size = sizeof(struct pic32eth_device),
>> + .platdata_auto_alloc_size = sizeof(struct eth_pdata),
>> +};
>> diff --git a/drivers/net/pic32_eth.h b/drivers/net/pic32_eth.h
>> new file mode 100644
>> index 0000000..5933661
[...]
More information about the U-Boot
mailing list