Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * DWMAC glue for NXP LPC18xx/LPC43xx Ethernet
0003  *
0004  * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
0005  *
0006  * This file is licensed under the terms of the GNU General Public
0007  * License version 2. This program is licensed "as is" without any
0008  * warranty of any kind, whether express or implied.
0009  */
0010 
0011 #include <linux/mfd/syscon.h>
0012 #include <linux/module.h>
0013 #include <linux/of.h>
0014 #include <linux/of_net.h>
0015 #include <linux/phy.h>
0016 #include <linux/platform_device.h>
0017 #include <linux/regmap.h>
0018 #include <linux/stmmac.h>
0019 
0020 #include "stmmac_platform.h"
0021 
0022 /* Register defines for CREG syscon */
0023 #define LPC18XX_CREG_CREG6          0x12c
0024 # define LPC18XX_CREG_CREG6_ETHMODE_MASK    0x7
0025 # define LPC18XX_CREG_CREG6_ETHMODE_MII     0x0
0026 # define LPC18XX_CREG_CREG6_ETHMODE_RMII    0x4
0027 
0028 static int lpc18xx_dwmac_probe(struct platform_device *pdev)
0029 {
0030     struct plat_stmmacenet_data *plat_dat;
0031     struct stmmac_resources stmmac_res;
0032     struct regmap *reg;
0033     u8 ethmode;
0034     int ret;
0035 
0036     ret = stmmac_get_platform_resources(pdev, &stmmac_res);
0037     if (ret)
0038         return ret;
0039 
0040     plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
0041     if (IS_ERR(plat_dat))
0042         return PTR_ERR(plat_dat);
0043 
0044     plat_dat->has_gmac = true;
0045 
0046     reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
0047     if (IS_ERR(reg)) {
0048         dev_err(&pdev->dev, "syscon lookup failed\n");
0049         ret = PTR_ERR(reg);
0050         goto err_remove_config_dt;
0051     }
0052 
0053     if (plat_dat->interface == PHY_INTERFACE_MODE_MII) {
0054         ethmode = LPC18XX_CREG_CREG6_ETHMODE_MII;
0055     } else if (plat_dat->interface == PHY_INTERFACE_MODE_RMII) {
0056         ethmode = LPC18XX_CREG_CREG6_ETHMODE_RMII;
0057     } else {
0058         dev_err(&pdev->dev, "Only MII and RMII mode supported\n");
0059         ret = -EINVAL;
0060         goto err_remove_config_dt;
0061     }
0062 
0063     regmap_update_bits(reg, LPC18XX_CREG_CREG6,
0064                LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode);
0065 
0066     ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
0067     if (ret)
0068         goto err_remove_config_dt;
0069 
0070     return 0;
0071 
0072 err_remove_config_dt:
0073     stmmac_remove_config_dt(pdev, plat_dat);
0074 
0075     return ret;
0076 }
0077 
0078 static const struct of_device_id lpc18xx_dwmac_match[] = {
0079     { .compatible = "nxp,lpc1850-dwmac" },
0080     { }
0081 };
0082 MODULE_DEVICE_TABLE(of, lpc18xx_dwmac_match);
0083 
0084 static struct platform_driver lpc18xx_dwmac_driver = {
0085     .probe  = lpc18xx_dwmac_probe,
0086     .remove = stmmac_pltfr_remove,
0087     .driver = {
0088         .name           = "lpc18xx-dwmac",
0089         .pm     = &stmmac_pltfr_pm_ops,
0090         .of_match_table = lpc18xx_dwmac_match,
0091     },
0092 };
0093 module_platform_driver(lpc18xx_dwmac_driver);
0094 
0095 MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>");
0096 MODULE_DESCRIPTION("DWMAC glue for LPC18xx/43xx Ethernet");
0097 MODULE_LICENSE("GPL v2");