Skip to content

Commit

Permalink
Merge branch 'sh_eth-optimize-mdio'
Browse files Browse the repository at this point in the history
Sergei Shtylyov says:

====================
sh_eth: optimize MDIO code

Here's a set of 3 patches against DaveM's 'net-next.git' repo which
gets rid of ~35 LoCs in the MDIO bitbang methods.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Dec 9, 2015
2 parents 3cdb730 + 78fa3c5 commit bc0b8b6
Showing 1 changed file with 15 additions and 49 deletions.
64 changes: 15 additions & 49 deletions drivers/net/ethernet/renesas/sh_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,56 +1013,34 @@ struct bb_info {
void (*set_gate)(void *addr);
struct mdiobb_ctrl ctrl;
void *addr;
u32 mmd_msk;/* MMD */
u32 mdo_msk;
u32 mdi_msk;
u32 mdc_msk;
};

/* PHY bit set */
static void bb_set(void *addr, u32 msk)
static void sh_mdio_ctrl(struct mdiobb_ctrl *ctrl, u32 mask, int set)
{
iowrite32(ioread32(addr) | msk, addr);
}
struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
u32 pir;

/* PHY bit clear */
static void bb_clr(void *addr, u32 msk)
{
iowrite32((ioread32(addr) & ~msk), addr);
}
if (bitbang->set_gate)
bitbang->set_gate(bitbang->addr);

/* PHY bit read */
static int bb_read(void *addr, u32 msk)
{
return (ioread32(addr) & msk) != 0;
pir = ioread32(bitbang->addr);
if (set)
pir |= mask;
else
pir &= ~mask;
iowrite32(pir, bitbang->addr);
}

/* Data I/O pin control */
static void sh_mmd_ctrl(struct mdiobb_ctrl *ctrl, int bit)
{
struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);

if (bitbang->set_gate)
bitbang->set_gate(bitbang->addr);

if (bit)
bb_set(bitbang->addr, bitbang->mmd_msk);
else
bb_clr(bitbang->addr, bitbang->mmd_msk);
sh_mdio_ctrl(ctrl, PIR_MMD, bit);
}

/* Set bit data*/
static void sh_set_mdio(struct mdiobb_ctrl *ctrl, int bit)
{
struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);

if (bitbang->set_gate)
bitbang->set_gate(bitbang->addr);

if (bit)
bb_set(bitbang->addr, bitbang->mdo_msk);
else
bb_clr(bitbang->addr, bitbang->mdo_msk);
sh_mdio_ctrl(ctrl, PIR_MDO, bit);
}

/* Get bit data*/
Expand All @@ -1073,21 +1051,13 @@ static int sh_get_mdio(struct mdiobb_ctrl *ctrl)
if (bitbang->set_gate)
bitbang->set_gate(bitbang->addr);

return bb_read(bitbang->addr, bitbang->mdi_msk);
return (ioread32(bitbang->addr) & PIR_MDI) != 0;
}

/* MDC pin control */
static void sh_mdc_ctrl(struct mdiobb_ctrl *ctrl, int bit)
{
struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);

if (bitbang->set_gate)
bitbang->set_gate(bitbang->addr);

if (bit)
bb_set(bitbang->addr, bitbang->mdc_msk);
else
bb_clr(bitbang->addr, bitbang->mdc_msk);
sh_mdio_ctrl(ctrl, PIR_MDC, bit);
}

/* mdio bus control struct */
Expand Down Expand Up @@ -2899,10 +2869,6 @@ static int sh_mdio_init(struct sh_eth_private *mdp,
/* bitbang init */
bitbang->addr = mdp->addr + mdp->reg_offset[PIR];
bitbang->set_gate = pd->set_mdio_gate;
bitbang->mdi_msk = PIR_MDI;
bitbang->mdo_msk = PIR_MDO;
bitbang->mmd_msk = PIR_MMD;
bitbang->mdc_msk = PIR_MDC;
bitbang->ctrl.ops = &bb_ops;

/* MII controller setting */
Expand Down

0 comments on commit bc0b8b6

Please sign in to comment.