2023-07-04 07:10:09

by Michael Haener

[permalink] [raw]
Subject: [PATCH v2 2/3] net: dsa: mv88e632x: Refactor serdes write

From: Michael Haener <[email protected]>

To avoid code duplication, the serdes write functions
have been combined.

Signed-off-by: Michael Haener <[email protected]>
---
drivers/net/dsa/mv88e6xxx/chip.c | 4 ++++
drivers/net/dsa/mv88e6xxx/chip.h | 2 ++
drivers/net/dsa/mv88e6xxx/serdes.c | 6 +++---
drivers/net/dsa/mv88e6xxx/serdes.h | 11 +++++++++++
4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index d2a320c6bed7..11b98546b938 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -4375,6 +4375,7 @@ static const struct mv88e6xxx_ops mv88e6172_ops = {
.stu_getnext = mv88e6352_g1_stu_getnext,
.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
.serdes_read = mv88e6352_serdes_read,
+ .serdes_write = mv88e6352_serdes_write,
.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
.serdes_get_regs = mv88e6352_serdes_get_regs,
.gpio_ops = &mv88e6352_gpio_ops,
@@ -4476,6 +4477,7 @@ static const struct mv88e6xxx_ops mv88e6176_ops = {
.stu_getnext = mv88e6352_g1_stu_getnext,
.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
.serdes_read = mv88e6352_serdes_read,
+ .serdes_write = mv88e6352_serdes_write,
.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
.serdes_get_regs = mv88e6352_serdes_get_regs,
@@ -4747,6 +4749,7 @@ static const struct mv88e6xxx_ops mv88e6240_ops = {
.stu_getnext = mv88e6352_g1_stu_getnext,
.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
.serdes_read = mv88e6352_serdes_read,
+ .serdes_write = mv88e6352_serdes_write,
.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
.serdes_get_regs = mv88e6352_serdes_get_regs,
@@ -5160,6 +5163,7 @@ static const struct mv88e6xxx_ops mv88e6352_ops = {
.stu_getnext = mv88e6352_g1_stu_getnext,
.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
.serdes_read = mv88e6352_serdes_read,
+ .serdes_write = mv88e6352_serdes_write,
.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
.gpio_ops = &mv88e6352_gpio_ops,
.avb_ops = &mv88e6352_avb_ops,
diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h
index bbf1e7f6f343..7e9b6eb11216 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.h
+++ b/drivers/net/dsa/mv88e6xxx/chip.h
@@ -595,6 +595,8 @@ struct mv88e6xxx_ops {

int (*serdes_read)(struct mv88e6xxx_chip *chip, int lane, int device,
int reg, u16 *val);
+ int (*serdes_write)(struct mv88e6xxx_chip *chip, int lane, int reg,
+ u16 val);

/* SERDES interrupt handling */
unsigned int (*serdes_irq_mapping)(struct mv88e6xxx_chip *chip,
diff --git a/drivers/net/dsa/mv88e6xxx/serdes.c b/drivers/net/dsa/mv88e6xxx/serdes.c
index 5696b94c9155..b988d47ecbdd 100644
--- a/drivers/net/dsa/mv88e6xxx/serdes.c
+++ b/drivers/net/dsa/mv88e6xxx/serdes.c
@@ -25,8 +25,8 @@ int mv88e6352_serdes_read(struct mv88e6xxx_chip *chip, int lane,
reg, val);
}

-static int mv88e6352_serdes_write(struct mv88e6xxx_chip *chip, int reg,
- u16 val)
+int mv88e6352_serdes_write(struct mv88e6xxx_chip *chip, int lane, int reg,
+ u16 val)
{
return mv88e6xxx_phy_page_write(chip, MV88E6352_ADDR_SERDES,
MV88E6352_SERDES_PAGE_FIBER,
@@ -549,5 +549,5 @@ int mv88e6352_serdes_set_tx_amplitude(struct mv88e6xxx_chip *chip, int port,
ctrl &= ~MV88E6352_SERDES_OUT_AMP_MASK;
ctrl |= reg;

- return mv88e6352_serdes_write(chip, MV88E6352_SERDES_SPEC_CTRL2, ctrl);
+ return mv88e6xxx_serdes_write(chip, lane, MV88E6352_SERDES_SPEC_CTRL2, ctrl);
}
diff --git a/drivers/net/dsa/mv88e6xxx/serdes.h b/drivers/net/dsa/mv88e6xxx/serdes.h
index 9b3a5ece33e7..d3e83c674ef7 100644
--- a/drivers/net/dsa/mv88e6xxx/serdes.h
+++ b/drivers/net/dsa/mv88e6xxx/serdes.h
@@ -124,6 +124,8 @@ int mv88e6352_serdes_read(struct mv88e6xxx_chip *chip, int lane, int device,
int reg, u16 *val);
int mv88e6390_serdes_read(struct mv88e6xxx_chip *chip, int lane, int device,
int reg, u16 *val);
+int mv88e6352_serdes_write(struct mv88e6xxx_chip *chip, int lane, int reg,
+ u16 val);
unsigned int mv88e6352_serdes_irq_mapping(struct mv88e6xxx_chip *chip,
int port);
unsigned int mv88e6390_serdes_irq_mapping(struct mv88e6xxx_chip *chip,
@@ -166,6 +168,15 @@ static inline int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int lane,
return chip->info->ops->serdes_read(chip, lane, device, reg, val);
}

+static inline int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int lane,
+ int reg, u16 val)
+{
+ if (!chip->info->ops->serdes_write)
+ return -EOPNOTSUPP;
+
+ return chip->info->ops->serdes_write(chip, lane, reg, val);
+}
+
static inline unsigned int
mv88e6xxx_serdes_irq_mapping(struct mv88e6xxx_chip *chip, int port)
{
--
2.41.0



2023-07-04 07:45:20

by Sverdlin, Alexander

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] net: dsa: mv88e632x: Refactor serdes write

On Tue, 2023-07-04 at 08:59 +0200, M. Haener wrote:
> From: Michael Haener <[email protected]>
>
> To avoid code duplication, the serdes write functions
> have been combined.
>
> Signed-off-by: Michael Haener <[email protected]>

Reviewed-by: Alexander Sverdlin <[email protected]>

> ---
>  drivers/net/dsa/mv88e6xxx/chip.c   |  4 ++++
>  drivers/net/dsa/mv88e6xxx/chip.h   |  2 ++
>  drivers/net/dsa/mv88e6xxx/serdes.c |  6 +++---
>  drivers/net/dsa/mv88e6xxx/serdes.h | 11 +++++++++++
>  4 files changed, 20 insertions(+), 3 deletions(-)

--
Alexander Sverdlin
Siemens AG
http://www.siemens.com