2015-05-14 12:10:56 +02:00
/*
* DWMAC glue for NXP LPC18xx / LPC43xx Ethernet
*
* Copyright ( C ) 2015 Joachim Eastwood < manabian @ gmail . com >
*
* This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed " as is " without any
* warranty of any kind , whether express or implied .
*/
# include <linux/mfd/syscon.h>
2015-05-14 12:11:00 +02:00
# include <linux/module.h>
2015-05-14 12:10:56 +02:00
# include <linux/of.h>
# include <linux/of_net.h>
# include <linux/phy.h>
2015-05-14 12:11:00 +02:00
# include <linux/platform_device.h>
2015-05-14 12:10:56 +02:00
# include <linux/regmap.h>
# include <linux/stmmac.h>
2015-05-14 12:11:00 +02:00
# include "stmmac_platform.h"
2015-05-14 12:10:56 +02:00
/* Register defines for CREG syscon */
# define LPC18XX_CREG_CREG6 0x12c
# define LPC18XX_CREG_CREG6_ETHMODE_MASK 0x7
# define LPC18XX_CREG_CREG6_ETHMODE_MII 0x0
# define LPC18XX_CREG_CREG6_ETHMODE_RMII 0x4
2015-07-17 00:26:10 +02:00
static int lpc18xx_dwmac_probe ( struct platform_device * pdev )
{
struct plat_stmmacenet_data * plat_dat ;
struct stmmac_resources stmmac_res ;
2015-05-14 12:10:56 +02:00
struct regmap * reg ;
2015-07-17 00:26:10 +02:00
u8 ethmode ;
int ret ;
2015-05-14 12:10:56 +02:00
2015-07-17 00:26:10 +02:00
ret = stmmac_get_platform_resources ( pdev , & stmmac_res ) ;
if ( ret )
return ret ;
2015-05-14 12:10:56 +02:00
2015-07-17 00:26:10 +02:00
plat_dat = stmmac_probe_config_dt ( pdev , & stmmac_res . mac ) ;
if ( IS_ERR ( plat_dat ) )
return PTR_ERR ( plat_dat ) ;
2015-05-14 12:10:56 +02:00
2015-07-17 00:26:10 +02:00
plat_dat - > has_gmac = true ;
2015-05-14 12:10:56 +02:00
2015-07-17 00:26:10 +02:00
reg = syscon_regmap_lookup_by_compatible ( " nxp,lpc1850-creg " ) ;
if ( IS_ERR ( reg ) ) {
dev_err ( & pdev - > dev , " syscon lookup failed \n " ) ;
2016-11-30 15:29:55 +01:00
ret = PTR_ERR ( reg ) ;
goto err_remove_config_dt ;
2015-05-14 12:10:56 +02:00
}
2015-07-17 00:26:10 +02:00
if ( plat_dat - > interface = = PHY_INTERFACE_MODE_MII ) {
2015-05-14 12:10:56 +02:00
ethmode = LPC18XX_CREG_CREG6_ETHMODE_MII ;
2015-07-17 00:26:10 +02:00
} else if ( plat_dat - > interface = = PHY_INTERFACE_MODE_RMII ) {
2015-05-14 12:10:56 +02:00
ethmode = LPC18XX_CREG_CREG6_ETHMODE_RMII ;
} else {
dev_err ( & pdev - > dev , " Only MII and RMII mode supported \n " ) ;
2016-11-30 15:29:55 +01:00
ret = - EINVAL ;
goto err_remove_config_dt ;
2015-05-14 12:10:56 +02:00
}
2015-07-17 00:26:10 +02:00
regmap_update_bits ( reg , LPC18XX_CREG_CREG6 ,
2015-05-14 12:10:56 +02:00
LPC18XX_CREG_CREG6_ETHMODE_MASK , ethmode ) ;
2016-11-30 15:29:55 +01:00
ret = stmmac_dvr_probe ( & pdev - > dev , plat_dat , & stmmac_res ) ;
if ( ret )
goto err_remove_config_dt ;
return 0 ;
err_remove_config_dt :
stmmac_remove_config_dt ( pdev , plat_dat ) ;
return ret ;
2015-05-14 12:10:56 +02:00
}
2015-05-14 12:11:00 +02:00
static const struct of_device_id lpc18xx_dwmac_match [ ] = {
2015-07-17 00:26:10 +02:00
{ . compatible = " nxp,lpc1850-dwmac " } ,
2015-05-14 12:11:00 +02:00
{ }
} ;
MODULE_DEVICE_TABLE ( of , lpc18xx_dwmac_match ) ;
static struct platform_driver lpc18xx_dwmac_driver = {
2015-07-17 00:26:10 +02:00
. probe = lpc18xx_dwmac_probe ,
2015-05-14 12:11:00 +02:00
. remove = stmmac_pltfr_remove ,
. driver = {
. name = " lpc18xx-dwmac " ,
. pm = & stmmac_pltfr_pm_ops ,
. of_match_table = lpc18xx_dwmac_match ,
} ,
} ;
module_platform_driver ( lpc18xx_dwmac_driver ) ;
MODULE_AUTHOR ( " Joachim Eastwood <manabian@gmail.com> " ) ;
MODULE_DESCRIPTION ( " DWMAC glue for LPC18xx/43xx Ethernet " ) ;
MODULE_LICENSE ( " GPL v2 " ) ;