3
3
* Copyright (C) 2014 Renesas Electronics Corporation
4
4
* Copyright (C) 2006-2012 Nobuhiro Iwamatsu
5
5
* Copyright (C) 2008-2014 Renesas Solutions Corp.
6
- * Copyright (C) 2013-2014 Cogent Embedded, Inc.
6
+ * Copyright (C) 2013-2016 Cogent Embedded, Inc.
7
7
* Copyright (C) 2014 Codethink Limited
8
8
*
9
9
* This program is free software; you can redistribute it and/or modify it
@@ -428,6 +428,13 @@ static u32 sh_eth_read(struct net_device *ndev, int enum_index)
428
428
return ioread32 (mdp -> addr + offset );
429
429
}
430
430
431
+ static void sh_eth_modify (struct net_device * ndev , int enum_index , u32 clear ,
432
+ u32 set )
433
+ {
434
+ sh_eth_write (ndev , (sh_eth_read (ndev , enum_index ) & ~clear ) | set ,
435
+ enum_index );
436
+ }
437
+
431
438
static bool sh_eth_is_gether (struct sh_eth_private * mdp )
432
439
{
433
440
return mdp -> reg_offset == sh_eth_offset_gigabit ;
@@ -467,10 +474,7 @@ static void sh_eth_set_duplex(struct net_device *ndev)
467
474
{
468
475
struct sh_eth_private * mdp = netdev_priv (ndev );
469
476
470
- if (mdp -> duplex ) /* Full */
471
- sh_eth_write (ndev , sh_eth_read (ndev , ECMR ) | ECMR_DM , ECMR );
472
- else /* Half */
473
- sh_eth_write (ndev , sh_eth_read (ndev , ECMR ) & ~ECMR_DM , ECMR );
477
+ sh_eth_modify (ndev , ECMR , ECMR_DM , mdp -> duplex ? ECMR_DM : 0 );
474
478
}
475
479
476
480
static void sh_eth_chip_reset (struct net_device * ndev )
@@ -583,10 +587,10 @@ static void sh_eth_set_rate_r8a777x(struct net_device *ndev)
583
587
584
588
switch (mdp -> speed ) {
585
589
case 10 : /* 10BASE */
586
- sh_eth_write (ndev , sh_eth_read ( ndev , ECMR ) & ~ ECMR_ELB , ECMR );
590
+ sh_eth_modify (ndev , ECMR , ECMR_ELB , 0 );
587
591
break ;
588
592
case 100 :/* 100BASE */
589
- sh_eth_write (ndev , sh_eth_read ( ndev , ECMR ) | ECMR_ELB , ECMR );
593
+ sh_eth_modify (ndev , ECMR , ECMR_ELB , ECMR_ELB );
590
594
break ;
591
595
default :
592
596
break ;
@@ -649,10 +653,10 @@ static void sh_eth_set_rate_sh7724(struct net_device *ndev)
649
653
650
654
switch (mdp -> speed ) {
651
655
case 10 : /* 10BASE */
652
- sh_eth_write (ndev , sh_eth_read ( ndev , ECMR ) & ~ ECMR_RTM , ECMR );
656
+ sh_eth_modify (ndev , ECMR , ECMR_RTM , 0 );
653
657
break ;
654
658
case 100 :/* 100BASE */
655
- sh_eth_write (ndev , sh_eth_read ( ndev , ECMR ) | ECMR_RTM , ECMR );
659
+ sh_eth_modify (ndev , ECMR , ECMR_RTM , ECMR_RTM );
656
660
break ;
657
661
default :
658
662
break ;
@@ -924,8 +928,7 @@ static int sh_eth_reset(struct net_device *ndev)
924
928
925
929
if (sh_eth_is_gether (mdp ) || sh_eth_is_rz_fast_ether (mdp )) {
926
930
sh_eth_write (ndev , EDSR_ENALL , EDSR );
927
- sh_eth_write (ndev , sh_eth_read (ndev , EDMR ) | EDMR_SRST_GETHER ,
928
- EDMR );
931
+ sh_eth_modify (ndev , EDMR , EDMR_SRST_GETHER , EDMR_SRST_GETHER );
929
932
930
933
ret = sh_eth_check_reset (ndev );
931
934
if (ret )
@@ -949,11 +952,9 @@ static int sh_eth_reset(struct net_device *ndev)
949
952
if (mdp -> cd -> select_mii )
950
953
sh_eth_select_mii (ndev );
951
954
} else {
952
- sh_eth_write (ndev , sh_eth_read (ndev , EDMR ) | EDMR_SRST_ETHER ,
953
- EDMR );
955
+ sh_eth_modify (ndev , EDMR , EDMR_SRST_ETHER , EDMR_SRST_ETHER );
954
956
mdelay (3 );
955
- sh_eth_write (ndev , sh_eth_read (ndev , EDMR ) & ~EDMR_SRST_ETHER ,
956
- EDMR );
957
+ sh_eth_modify (ndev , EDMR , EDMR_SRST_ETHER , 0 );
957
958
}
958
959
959
960
return ret ;
@@ -1285,7 +1286,7 @@ static int sh_eth_dev_init(struct net_device *ndev, bool start)
1285
1286
sh_eth_write (ndev , ndev -> mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN ,
1286
1287
RFLR );
1287
1288
1288
- sh_eth_write (ndev , sh_eth_read ( ndev , EESR ), EESR );
1289
+ sh_eth_modify (ndev , EESR , 0 , 0 );
1289
1290
if (start ) {
1290
1291
mdp -> irq_enabled = true;
1291
1292
sh_eth_write (ndev , mdp -> cd -> eesipr_value , EESIPR );
@@ -1532,15 +1533,13 @@ static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
1532
1533
static void sh_eth_rcv_snd_disable (struct net_device * ndev )
1533
1534
{
1534
1535
/* disable tx and rx */
1535
- sh_eth_write (ndev , sh_eth_read (ndev , ECMR ) &
1536
- ~(ECMR_RE | ECMR_TE ), ECMR );
1536
+ sh_eth_modify (ndev , ECMR , ECMR_RE | ECMR_TE , 0 );
1537
1537
}
1538
1538
1539
1539
static void sh_eth_rcv_snd_enable (struct net_device * ndev )
1540
1540
{
1541
1541
/* enable tx and rx */
1542
- sh_eth_write (ndev , sh_eth_read (ndev , ECMR ) |
1543
- (ECMR_RE | ECMR_TE ), ECMR );
1542
+ sh_eth_modify (ndev , ECMR , ECMR_RE | ECMR_TE , ECMR_RE | ECMR_TE );
1544
1543
}
1545
1544
1546
1545
/* error control function */
@@ -1569,13 +1568,11 @@ static void sh_eth_error(struct net_device *ndev, u32 intr_status)
1569
1568
sh_eth_rcv_snd_disable (ndev );
1570
1569
} else {
1571
1570
/* Link Up */
1572
- sh_eth_write (ndev , sh_eth_read (ndev , EESIPR ) &
1573
- ~DMAC_M_ECI , EESIPR );
1571
+ sh_eth_modify (ndev , EESIPR , DMAC_M_ECI , 0 );
1574
1572
/* clear int */
1575
- sh_eth_write (ndev , sh_eth_read (ndev , ECSR ),
1576
- ECSR );
1577
- sh_eth_write (ndev , sh_eth_read (ndev , EESIPR ) |
1578
- DMAC_M_ECI , EESIPR );
1573
+ sh_eth_modify (ndev , ECSR , 0 , 0 );
1574
+ sh_eth_modify (ndev , EESIPR , DMAC_M_ECI ,
1575
+ DMAC_M_ECI );
1579
1576
/* enable tx and rx */
1580
1577
sh_eth_rcv_snd_enable (ndev );
1581
1578
}
@@ -1765,9 +1762,7 @@ static void sh_eth_adjust_link(struct net_device *ndev)
1765
1762
mdp -> cd -> set_rate (ndev );
1766
1763
}
1767
1764
if (!mdp -> link ) {
1768
- sh_eth_write (ndev ,
1769
- sh_eth_read (ndev , ECMR ) & ~ECMR_TXF ,
1770
- ECMR );
1765
+ sh_eth_modify (ndev , ECMR , ECMR_TXF , 0 );
1771
1766
new_state = 1 ;
1772
1767
mdp -> link = phydev -> link ;
1773
1768
if (mdp -> cd -> no_psr || mdp -> no_ether_link )
0 commit comments