Skip to content

Commit d61d42a

Browse files
Danielmachonvinodkoul
authored andcommitted
phy: sparx5-serdes: add ops to match data
We need to handle code differently in a few places. Add a struct: sparx5_serdes_ops for this purpose, and populate it a with function to set the SERDES type. Signed-off-by: Daniel Machon <daniel.machon@microchip.com> Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com> Link: https://lore.kernel.org/r/20240909-sparx5-lan969x-serdes-driver-v2-4-d695bcb57b84@microchip.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 5206ba9 commit d61d42a

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

drivers/phy/microchip/sparx5_serdes.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,20 @@ static const struct phy_ops sparx5_serdes_ops = {
23732373
.owner = THIS_MODULE,
23742374
};
23752375

2376+
static void sparx5_serdes_type_set(struct sparx5_serdes_macro *macro, int sidx)
2377+
{
2378+
if (sidx < SPX5_SERDES_10G_START) {
2379+
macro->serdestype = SPX5_SDT_6G;
2380+
macro->stpidx = macro->sidx;
2381+
} else if (sidx < SPX5_SERDES_25G_START) {
2382+
macro->serdestype = SPX5_SDT_10G;
2383+
macro->stpidx = macro->sidx - SPX5_SERDES_10G_START;
2384+
} else {
2385+
macro->serdestype = SPX5_SDT_25G;
2386+
macro->stpidx = macro->sidx - SPX5_SERDES_25G_START;
2387+
}
2388+
}
2389+
23762390
static int sparx5_phy_create(struct sparx5_serdes_private *priv,
23772391
int idx, struct phy **phy)
23782392
{
@@ -2389,16 +2403,8 @@ static int sparx5_phy_create(struct sparx5_serdes_private *priv,
23892403
macro->sidx = idx;
23902404
macro->priv = priv;
23912405
macro->speed = SPEED_UNKNOWN;
2392-
if (idx < SPX5_SERDES_10G_START) {
2393-
macro->serdestype = SPX5_SDT_6G;
2394-
macro->stpidx = macro->sidx;
2395-
} else if (idx < SPX5_SERDES_25G_START) {
2396-
macro->serdestype = SPX5_SDT_10G;
2397-
macro->stpidx = macro->sidx - SPX5_SERDES_10G_START;
2398-
} else {
2399-
macro->serdestype = SPX5_SDT_25G;
2400-
macro->stpidx = macro->sidx - SPX5_SERDES_25G_START;
2401-
}
2406+
2407+
priv->data->ops.serdes_type_set(macro, idx);
24022408

24032409
phy_set_drvdata(*phy, macro);
24042410

@@ -2512,6 +2518,9 @@ static const struct sparx5_serdes_match_data sparx5_desc = {
25122518
.sd_max = 33,
25132519
.cmu_max = 14,
25142520
},
2521+
.ops = {
2522+
.serdes_type_set = &sparx5_serdes_type_set,
2523+
},
25152524
};
25162525

25172526
/* Client lookup function, uses serdes index */

drivers/phy/microchip/sparx5_serdes.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,29 @@ enum sparx5_serdes_mode {
2626
SPX5_SD_MODE_SFI,
2727
};
2828

29+
struct sparx5_serdes_macro {
30+
struct sparx5_serdes_private *priv;
31+
u32 sidx;
32+
u32 stpidx;
33+
enum sparx5_serdes_type serdestype;
34+
enum sparx5_serdes_mode serdesmode;
35+
phy_interface_t portmode;
36+
int speed;
37+
enum phy_media media;
38+
};
39+
2940
struct sparx5_serdes_consts {
3041
int sd_max;
3142
int cmu_max;
3243
};
3344

45+
struct sparx5_serdes_ops {
46+
void (*serdes_type_set)(struct sparx5_serdes_macro *macro, int sidx);
47+
};
48+
3449
struct sparx5_serdes_match_data {
3550
const struct sparx5_serdes_consts consts;
51+
const struct sparx5_serdes_ops ops;
3652
const struct sparx5_serdes_io_resource *iomap;
3753
int iomap_size;
3854
};
@@ -45,17 +61,6 @@ struct sparx5_serdes_private {
4561
const struct sparx5_serdes_match_data *data;
4662
};
4763

48-
struct sparx5_serdes_macro {
49-
struct sparx5_serdes_private *priv;
50-
u32 sidx;
51-
u32 stpidx;
52-
enum sparx5_serdes_type serdestype;
53-
enum sparx5_serdes_mode serdesmode;
54-
phy_interface_t portmode;
55-
int speed;
56-
enum phy_media media;
57-
};
58-
5964
/* Read, Write and modify registers content.
6065
* The register definition macros start at the id
6166
*/

0 commit comments

Comments
 (0)