net: dsa: mv88e6xxx: Refactor mv88e6352 SERDES code into an op
The mv88e6390 family has a different SERDES implementation. Refactor the mv88e6352 code into an ops function, so we can later add the mv88e6390 code. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

zatwierdzone przez
David S. Miller

rodzic
10fa5bfcd6
commit
6d91782f0f
75
drivers/net/dsa/mv88e6xxx/serdes.c
Normal file
75
drivers/net/dsa/mv88e6xxx/serdes.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Marvell 88E6xxx SERDES manipulation, via SMI bus
|
||||
*
|
||||
* Copyright (c) 2008 Marvell Semiconductor
|
||||
*
|
||||
* Copyright (c) 2017 Andrew Lunn <andrew@lunn.ch>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include <linux/mii.h>
|
||||
|
||||
#include "mv88e6xxx.h"
|
||||
#include "phy.h"
|
||||
#include "port.h"
|
||||
#include "serdes.h"
|
||||
|
||||
static int mv88e6352_serdes_read(struct mv88e6xxx_chip *chip, int reg,
|
||||
u16 *val)
|
||||
{
|
||||
return mv88e6xxx_phy_page_read(chip, MV88E6352_ADDR_SERDES,
|
||||
MV88E6352_SERDES_PAGE_FIBER,
|
||||
reg, val);
|
||||
}
|
||||
|
||||
static int mv88e6352_serdes_write(struct mv88e6xxx_chip *chip, int reg,
|
||||
u16 val)
|
||||
{
|
||||
return mv88e6xxx_phy_page_write(chip, MV88E6352_ADDR_SERDES,
|
||||
MV88E6352_SERDES_PAGE_FIBER,
|
||||
reg, val);
|
||||
}
|
||||
|
||||
static int mv88e6352_serdes_power_set(struct mv88e6xxx_chip *chip, bool on)
|
||||
{
|
||||
u16 val, new_val;
|
||||
int err;
|
||||
|
||||
err = mv88e6352_serdes_read(chip, MII_BMCR, &val);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (on)
|
||||
new_val = val & ~BMCR_PDOWN;
|
||||
else
|
||||
new_val = val | BMCR_PDOWN;
|
||||
|
||||
if (val != new_val)
|
||||
err = mv88e6352_serdes_write(chip, MII_BMCR, new_val);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int mv88e6352_serdes_power(struct mv88e6xxx_chip *chip, int port, bool on)
|
||||
{
|
||||
int err;
|
||||
u8 cmode;
|
||||
|
||||
err = mv88e6xxx_port_get_cmode(chip, port, &cmode);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if ((cmode == PORT_STATUS_CMODE_100BASE_X) ||
|
||||
(cmode == PORT_STATUS_CMODE_1000BASE_X) ||
|
||||
(cmode == PORT_STATUS_CMODE_SGMII)) {
|
||||
err = mv88e6352_serdes_power_set(chip, on);
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user