2 * DWMAC glue for NXP LPC18xx/LPC43xx Ethernet
4 * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
11 #include <linux/mfd/syscon.h>
12 #include <linux/module.h>
14 #include <linux/of_net.h>
15 #include <linux/phy.h>
16 #include <linux/platform_device.h>
17 #include <linux/regmap.h>
18 #include <linux/stmmac.h>
20 #include "stmmac_platform.h"
22 /* Register defines for CREG syscon */
23 #define LPC18XX_CREG_CREG6 0x12c
24 # define LPC18XX_CREG_CREG6_ETHMODE_MASK 0x7
25 # define LPC18XX_CREG_CREG6_ETHMODE_MII 0x0
26 # define LPC18XX_CREG_CREG6_ETHMODE_RMII 0x4
28 struct lpc18xx_dwmac_priv_data {
33 static void *lpc18xx_dwmac_setup(struct platform_device *pdev)
35 struct lpc18xx_dwmac_priv_data *dwmac;
37 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
39 return ERR_PTR(-ENOMEM);
41 dwmac->interface = of_get_phy_mode(pdev->dev.of_node);
42 if (dwmac->interface < 0)
43 return ERR_PTR(dwmac->interface);
45 dwmac->reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
46 if (IS_ERR(dwmac->reg)) {
47 dev_err(&pdev->dev, "Syscon lookup failed\n");
54 static int lpc18xx_dwmac_init(struct platform_device *pdev, void *priv)
56 struct lpc18xx_dwmac_priv_data *dwmac = priv;
59 if (dwmac->interface == PHY_INTERFACE_MODE_MII) {
60 ethmode = LPC18XX_CREG_CREG6_ETHMODE_MII;
61 } else if (dwmac->interface == PHY_INTERFACE_MODE_RMII) {
62 ethmode = LPC18XX_CREG_CREG6_ETHMODE_RMII;
64 dev_err(&pdev->dev, "Only MII and RMII mode supported\n");
68 regmap_update_bits(dwmac->reg, LPC18XX_CREG_CREG6,
69 LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode);
74 static const struct stmmac_of_data lpc18xx_dwmac_data = {
76 .setup = lpc18xx_dwmac_setup,
77 .init = lpc18xx_dwmac_init,
80 static const struct of_device_id lpc18xx_dwmac_match[] = {
81 { .compatible = "nxp,lpc1850-dwmac", .data = &lpc18xx_dwmac_data },
84 MODULE_DEVICE_TABLE(of, lpc18xx_dwmac_match);
86 static struct platform_driver lpc18xx_dwmac_driver = {
87 .probe = stmmac_pltfr_probe,
88 .remove = stmmac_pltfr_remove,
90 .name = "lpc18xx-dwmac",
91 .pm = &stmmac_pltfr_pm_ops,
92 .of_match_table = lpc18xx_dwmac_match,
95 module_platform_driver(lpc18xx_dwmac_driver);
97 MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>");
98 MODULE_DESCRIPTION("DWMAC glue for LPC18xx/43xx Ethernet");
99 MODULE_LICENSE("GPL v2");