cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

dwmac-lpc18xx.c (2561B)


      1/*
      2 * DWMAC glue for NXP LPC18xx/LPC43xx Ethernet
      3 *
      4 * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
      5 *
      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.
      9 */
     10
     11#include <linux/mfd/syscon.h>
     12#include <linux/module.h>
     13#include <linux/of.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>
     19
     20#include "stmmac_platform.h"
     21
     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
     27
     28static int lpc18xx_dwmac_probe(struct platform_device *pdev)
     29{
     30	struct plat_stmmacenet_data *plat_dat;
     31	struct stmmac_resources stmmac_res;
     32	struct regmap *reg;
     33	u8 ethmode;
     34	int ret;
     35
     36	ret = stmmac_get_platform_resources(pdev, &stmmac_res);
     37	if (ret)
     38		return ret;
     39
     40	plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
     41	if (IS_ERR(plat_dat))
     42		return PTR_ERR(plat_dat);
     43
     44	plat_dat->has_gmac = true;
     45
     46	reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
     47	if (IS_ERR(reg)) {
     48		dev_err(&pdev->dev, "syscon lookup failed\n");
     49		ret = PTR_ERR(reg);
     50		goto err_remove_config_dt;
     51	}
     52
     53	if (plat_dat->interface == PHY_INTERFACE_MODE_MII) {
     54		ethmode = LPC18XX_CREG_CREG6_ETHMODE_MII;
     55	} else if (plat_dat->interface == PHY_INTERFACE_MODE_RMII) {
     56		ethmode = LPC18XX_CREG_CREG6_ETHMODE_RMII;
     57	} else {
     58		dev_err(&pdev->dev, "Only MII and RMII mode supported\n");
     59		ret = -EINVAL;
     60		goto err_remove_config_dt;
     61	}
     62
     63	regmap_update_bits(reg, LPC18XX_CREG_CREG6,
     64			   LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode);
     65
     66	ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
     67	if (ret)
     68		goto err_remove_config_dt;
     69
     70	return 0;
     71
     72err_remove_config_dt:
     73	stmmac_remove_config_dt(pdev, plat_dat);
     74
     75	return ret;
     76}
     77
     78static const struct of_device_id lpc18xx_dwmac_match[] = {
     79	{ .compatible = "nxp,lpc1850-dwmac" },
     80	{ }
     81};
     82MODULE_DEVICE_TABLE(of, lpc18xx_dwmac_match);
     83
     84static struct platform_driver lpc18xx_dwmac_driver = {
     85	.probe  = lpc18xx_dwmac_probe,
     86	.remove = stmmac_pltfr_remove,
     87	.driver = {
     88		.name           = "lpc18xx-dwmac",
     89		.pm		= &stmmac_pltfr_pm_ops,
     90		.of_match_table = lpc18xx_dwmac_match,
     91	},
     92};
     93module_platform_driver(lpc18xx_dwmac_driver);
     94
     95MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>");
     96MODULE_DESCRIPTION("DWMAC glue for LPC18xx/43xx Ethernet");
     97MODULE_LICENSE("GPL v2");