Commit b2b14d2f authored by Sergei Shtylyov's avatar Sergei Shtylyov Committed by David S. Miller

sh_eth: factor out register bit twiddling code

The  driver has often repeated pattern of reading a register,  AND'ing and/or
OR'ing some bits  and writing  the  value back. Factor the pattern out into
sh_eth_modify() -- this saves  84 bytes of code with ARM gcc 4.7.3.

While at it, update Cogent Embedded's copyright.
Signed-off-by: default avatarSergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 568b3ce7
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Copyright (C) 2014 Renesas Electronics Corporation * Copyright (C) 2014 Renesas Electronics Corporation
* Copyright (C) 2006-2012 Nobuhiro Iwamatsu * Copyright (C) 2006-2012 Nobuhiro Iwamatsu
* Copyright (C) 2008-2014 Renesas Solutions Corp. * Copyright (C) 2008-2014 Renesas Solutions Corp.
* Copyright (C) 2013-2014 Cogent Embedded, Inc. * Copyright (C) 2013-2016 Cogent Embedded, Inc.
* Copyright (C) 2014 Codethink Limited * Copyright (C) 2014 Codethink Limited
* *
* This program is free software; you can redistribute it and/or modify it * 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,6 +428,13 @@ static u32 sh_eth_read(struct net_device *ndev, int enum_index)
return ioread32(mdp->addr + offset); return ioread32(mdp->addr + offset);
} }
static void sh_eth_modify(struct net_device *ndev, int enum_index, u32 clear,
u32 set)
{
sh_eth_write(ndev, (sh_eth_read(ndev, enum_index) & ~clear) | set,
enum_index);
}
static bool sh_eth_is_gether(struct sh_eth_private *mdp) static bool sh_eth_is_gether(struct sh_eth_private *mdp)
{ {
return mdp->reg_offset == sh_eth_offset_gigabit; return mdp->reg_offset == sh_eth_offset_gigabit;
...@@ -467,10 +474,7 @@ static void sh_eth_set_duplex(struct net_device *ndev) ...@@ -467,10 +474,7 @@ static void sh_eth_set_duplex(struct net_device *ndev)
{ {
struct sh_eth_private *mdp = netdev_priv(ndev); struct sh_eth_private *mdp = netdev_priv(ndev);
if (mdp->duplex) /* Full */ sh_eth_modify(ndev, ECMR, ECMR_DM, mdp->duplex ? ECMR_DM : 0);
sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_DM, ECMR);
else /* Half */
sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_DM, ECMR);
} }
static void sh_eth_chip_reset(struct net_device *ndev) 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,10 +587,10 @@ static void sh_eth_set_rate_r8a777x(struct net_device *ndev)
switch (mdp->speed) { switch (mdp->speed) {
case 10: /* 10BASE */ case 10: /* 10BASE */
sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_ELB, ECMR); sh_eth_modify(ndev, ECMR, ECMR_ELB, 0);
break; break;
case 100:/* 100BASE */ case 100:/* 100BASE */
sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_ELB, ECMR); sh_eth_modify(ndev, ECMR, ECMR_ELB, ECMR_ELB);
break; break;
default: default:
break; break;
...@@ -649,10 +653,10 @@ static void sh_eth_set_rate_sh7724(struct net_device *ndev) ...@@ -649,10 +653,10 @@ static void sh_eth_set_rate_sh7724(struct net_device *ndev)
switch (mdp->speed) { switch (mdp->speed) {
case 10: /* 10BASE */ case 10: /* 10BASE */
sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_RTM, ECMR); sh_eth_modify(ndev, ECMR, ECMR_RTM, 0);
break; break;
case 100:/* 100BASE */ case 100:/* 100BASE */
sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_RTM, ECMR); sh_eth_modify(ndev, ECMR, ECMR_RTM, ECMR_RTM);
break; break;
default: default:
break; break;
...@@ -924,8 +928,7 @@ static int sh_eth_reset(struct net_device *ndev) ...@@ -924,8 +928,7 @@ static int sh_eth_reset(struct net_device *ndev)
if (sh_eth_is_gether(mdp) || sh_eth_is_rz_fast_ether(mdp)) { if (sh_eth_is_gether(mdp) || sh_eth_is_rz_fast_ether(mdp)) {
sh_eth_write(ndev, EDSR_ENALL, EDSR); sh_eth_write(ndev, EDSR_ENALL, EDSR);
sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_GETHER, sh_eth_modify(ndev, EDMR, EDMR_SRST_GETHER, EDMR_SRST_GETHER);
EDMR);
ret = sh_eth_check_reset(ndev); ret = sh_eth_check_reset(ndev);
if (ret) if (ret)
...@@ -949,11 +952,9 @@ static int sh_eth_reset(struct net_device *ndev) ...@@ -949,11 +952,9 @@ static int sh_eth_reset(struct net_device *ndev)
if (mdp->cd->select_mii) if (mdp->cd->select_mii)
sh_eth_select_mii(ndev); sh_eth_select_mii(ndev);
} else { } else {
sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_ETHER, sh_eth_modify(ndev, EDMR, EDMR_SRST_ETHER, EDMR_SRST_ETHER);
EDMR);
mdelay(3); mdelay(3);
sh_eth_write(ndev, sh_eth_read(ndev, EDMR) & ~EDMR_SRST_ETHER, sh_eth_modify(ndev, EDMR, EDMR_SRST_ETHER, 0);
EDMR);
} }
return ret; return ret;
...@@ -1285,7 +1286,7 @@ static int sh_eth_dev_init(struct net_device *ndev, bool start) ...@@ -1285,7 +1286,7 @@ static int sh_eth_dev_init(struct net_device *ndev, bool start)
sh_eth_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN, sh_eth_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN,
RFLR); RFLR);
sh_eth_write(ndev, sh_eth_read(ndev, EESR), EESR); sh_eth_modify(ndev, EESR, 0, 0);
if (start) { if (start) {
mdp->irq_enabled = true; mdp->irq_enabled = true;
sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR); 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,15 +1533,13 @@ static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
static void sh_eth_rcv_snd_disable(struct net_device *ndev) static void sh_eth_rcv_snd_disable(struct net_device *ndev)
{ {
/* disable tx and rx */ /* disable tx and rx */
sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & sh_eth_modify(ndev, ECMR, ECMR_RE | ECMR_TE, 0);
~(ECMR_RE | ECMR_TE), ECMR);
} }
static void sh_eth_rcv_snd_enable(struct net_device *ndev) static void sh_eth_rcv_snd_enable(struct net_device *ndev)
{ {
/* enable tx and rx */ /* enable tx and rx */
sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | sh_eth_modify(ndev, ECMR, ECMR_RE | ECMR_TE, ECMR_RE | ECMR_TE);
(ECMR_RE | ECMR_TE), ECMR);
} }
/* error control function */ /* error control function */
...@@ -1569,13 +1568,11 @@ static void sh_eth_error(struct net_device *ndev, u32 intr_status) ...@@ -1569,13 +1568,11 @@ static void sh_eth_error(struct net_device *ndev, u32 intr_status)
sh_eth_rcv_snd_disable(ndev); sh_eth_rcv_snd_disable(ndev);
} else { } else {
/* Link Up */ /* Link Up */
sh_eth_write(ndev, sh_eth_read(ndev, EESIPR) & sh_eth_modify(ndev, EESIPR, DMAC_M_ECI, 0);
~DMAC_M_ECI, EESIPR);
/* clear int */ /* clear int */
sh_eth_write(ndev, sh_eth_read(ndev, ECSR), sh_eth_modify(ndev, ECSR, 0, 0);
ECSR); sh_eth_modify(ndev, EESIPR, DMAC_M_ECI,
sh_eth_write(ndev, sh_eth_read(ndev, EESIPR) | DMAC_M_ECI);
DMAC_M_ECI, EESIPR);
/* enable tx and rx */ /* enable tx and rx */
sh_eth_rcv_snd_enable(ndev); sh_eth_rcv_snd_enable(ndev);
} }
...@@ -1765,9 +1762,7 @@ static void sh_eth_adjust_link(struct net_device *ndev) ...@@ -1765,9 +1762,7 @@ static void sh_eth_adjust_link(struct net_device *ndev)
mdp->cd->set_rate(ndev); mdp->cd->set_rate(ndev);
} }
if (!mdp->link) { if (!mdp->link) {
sh_eth_write(ndev, sh_eth_modify(ndev, ECMR, ECMR_TXF, 0);
sh_eth_read(ndev, ECMR) & ~ECMR_TXF,
ECMR);
new_state = 1; new_state = 1;
mdp->link = phydev->link; mdp->link = phydev->link;
if (mdp->cd->no_psr || mdp->no_ether_link) if (mdp->cd->no_psr || mdp->no_ether_link)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment