Skip to content

Commit 1d472eb

Browse files
Ryceancurrydavem330
authored andcommitted
net: bcmasp: Add support for ASP 2.2
ASP 2.2 improves power savings during low power modes. A new register was added to toggle to a slower clock during low power modes. EEE was broken for ASP 2.0/2.1. A HW workaround was added for ASP 2.2 that requires toggling a chicken bit. Signed-off-by: Justin Chen <justin.chen@broadcom.com> Acked-by: Florian Fainelli <florian.fainelli@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5682a87 commit 1d472eb

3 files changed

Lines changed: 87 additions & 10 deletions

File tree

drivers/net/ethernet/broadcom/asp2/bcmasp.c

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,26 @@ static void bcmasp_core_init(struct bcmasp_priv *priv)
972972
ASP_INTR2_CLEAR);
973973
}
974974

975-
static void bcmasp_core_clock_select(struct bcmasp_priv *priv, bool slow)
975+
static void bcmasp_core_clock_select_many(struct bcmasp_priv *priv, bool slow)
976+
{
977+
u32 reg;
978+
979+
reg = ctrl2_core_rl(priv, ASP_CTRL2_CORE_CLOCK_SELECT);
980+
if (slow)
981+
reg &= ~ASP_CTRL2_CORE_CLOCK_SELECT_MAIN;
982+
else
983+
reg |= ASP_CTRL2_CORE_CLOCK_SELECT_MAIN;
984+
ctrl2_core_wl(priv, reg, ASP_CTRL2_CORE_CLOCK_SELECT);
985+
986+
reg = ctrl2_core_rl(priv, ASP_CTRL2_CPU_CLOCK_SELECT);
987+
if (slow)
988+
reg &= ~ASP_CTRL2_CPU_CLOCK_SELECT_MAIN;
989+
else
990+
reg |= ASP_CTRL2_CPU_CLOCK_SELECT_MAIN;
991+
ctrl2_core_wl(priv, reg, ASP_CTRL2_CPU_CLOCK_SELECT);
992+
}
993+
994+
static void bcmasp_core_clock_select_one(struct bcmasp_priv *priv, bool slow)
976995
{
977996
u32 reg;
978997

@@ -1166,6 +1185,24 @@ static void bcmasp_wol_irq_destroy_per_intf(struct bcmasp_priv *priv)
11661185
}
11671186
}
11681187

1188+
static void bcmasp_eee_fixup(struct bcmasp_intf *intf, bool en)
1189+
{
1190+
u32 reg, phy_lpi_overwrite;
1191+
1192+
reg = rx_edpkt_core_rl(intf->parent, ASP_EDPKT_SPARE_REG);
1193+
phy_lpi_overwrite = intf->internal_phy ? ASP_EDPKT_SPARE_REG_EPHY_LPI :
1194+
ASP_EDPKT_SPARE_REG_GPHY_LPI;
1195+
1196+
if (en)
1197+
reg |= phy_lpi_overwrite;
1198+
else
1199+
reg &= ~phy_lpi_overwrite;
1200+
1201+
rx_edpkt_core_wl(intf->parent, reg, ASP_EDPKT_SPARE_REG);
1202+
1203+
usleep_range(50, 100);
1204+
}
1205+
11691206
static struct bcmasp_hw_info v20_hw_info = {
11701207
.rx_ctrl_flush = ASP_RX_CTRL_FLUSH,
11711208
.umac2fb = UMAC2FB_OFFSET,
@@ -1178,6 +1215,7 @@ static const struct bcmasp_plat_data v20_plat_data = {
11781215
.init_wol = bcmasp_init_wol_per_intf,
11791216
.enable_wol = bcmasp_enable_wol_per_intf,
11801217
.destroy_wol = bcmasp_wol_irq_destroy_per_intf,
1218+
.core_clock_select = bcmasp_core_clock_select_one,
11811219
.hw_info = &v20_hw_info,
11821220
};
11831221

@@ -1194,17 +1232,39 @@ static const struct bcmasp_plat_data v21_plat_data = {
11941232
.init_wol = bcmasp_init_wol_shared,
11951233
.enable_wol = bcmasp_enable_wol_shared,
11961234
.destroy_wol = bcmasp_wol_irq_destroy_shared,
1235+
.core_clock_select = bcmasp_core_clock_select_one,
11971236
.hw_info = &v21_hw_info,
11981237
};
11991238

1239+
static const struct bcmasp_plat_data v22_plat_data = {
1240+
.init_wol = bcmasp_init_wol_shared,
1241+
.enable_wol = bcmasp_enable_wol_shared,
1242+
.destroy_wol = bcmasp_wol_irq_destroy_shared,
1243+
.core_clock_select = bcmasp_core_clock_select_many,
1244+
.hw_info = &v21_hw_info,
1245+
.eee_fixup = bcmasp_eee_fixup,
1246+
};
1247+
1248+
static void bcmasp_set_pdata(struct bcmasp_priv *priv, const struct bcmasp_plat_data *pdata)
1249+
{
1250+
priv->init_wol = pdata->init_wol;
1251+
priv->enable_wol = pdata->enable_wol;
1252+
priv->destroy_wol = pdata->destroy_wol;
1253+
priv->core_clock_select = pdata->core_clock_select;
1254+
priv->eee_fixup = pdata->eee_fixup;
1255+
priv->hw_info = pdata->hw_info;
1256+
}
1257+
12001258
static const struct of_device_id bcmasp_of_match[] = {
12011259
{ .compatible = "brcm,asp-v2.0", .data = &v20_plat_data },
12021260
{ .compatible = "brcm,asp-v2.1", .data = &v21_plat_data },
1261+
{ .compatible = "brcm,asp-v2.2", .data = &v22_plat_data },
12031262
{ /* sentinel */ },
12041263
};
12051264
MODULE_DEVICE_TABLE(of, bcmasp_of_match);
12061265

12071266
static const struct of_device_id bcmasp_mdio_of_match[] = {
1267+
{ .compatible = "brcm,asp-v2.2-mdio", },
12081268
{ .compatible = "brcm,asp-v2.1-mdio", },
12091269
{ .compatible = "brcm,asp-v2.0-mdio", },
12101270
{ /* sentinel */ },
@@ -1265,16 +1325,13 @@ static int bcmasp_probe(struct platform_device *pdev)
12651325
if (!pdata)
12661326
return dev_err_probe(dev, -EINVAL, "unable to find platform data\n");
12671327

1268-
priv->init_wol = pdata->init_wol;
1269-
priv->enable_wol = pdata->enable_wol;
1270-
priv->destroy_wol = pdata->destroy_wol;
1271-
priv->hw_info = pdata->hw_info;
1328+
bcmasp_set_pdata(priv, pdata);
12721329

12731330
/* Enable all clocks to ensure successful probing */
12741331
bcmasp_core_clock_set(priv, ASP_CTRL_CLOCK_CTRL_ASP_ALL_DISABLE, 0);
12751332

12761333
/* Switch to the main clock */
1277-
bcmasp_core_clock_select(priv, false);
1334+
priv->core_clock_select(priv, false);
12781335

12791336
bcmasp_intr2_mask_set_all(priv);
12801337
bcmasp_intr2_clear_all(priv);
@@ -1381,7 +1438,7 @@ static int __maybe_unused bcmasp_suspend(struct device *d)
13811438
*/
13821439
bcmasp_core_clock_set(priv, 0, ASP_CTRL_CLOCK_CTRL_ASP_TX_DISABLE);
13831440

1384-
bcmasp_core_clock_select(priv, true);
1441+
priv->core_clock_select(priv, true);
13851442

13861443
clk_disable_unprepare(priv->clk);
13871444

@@ -1399,7 +1456,7 @@ static int __maybe_unused bcmasp_resume(struct device *d)
13991456
return ret;
14001457

14011458
/* Switch to the main clock domain */
1402-
bcmasp_core_clock_select(priv, false);
1459+
priv->core_clock_select(priv, false);
14031460

14041461
/* Re-enable all clocks for re-initialization */
14051462
bcmasp_core_clock_set(priv, ASP_CTRL_CLOCK_CTRL_ASP_ALL_DISABLE, 0);

drivers/net/ethernet/broadcom/asp2/bcmasp.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
#define ASP_WAKEUP_INTR2_FILT_1 BIT(3)
3434
#define ASP_WAKEUP_INTR2_FW BIT(4)
3535

36+
#define ASP_CTRL2_OFFSET 0x2000
37+
#define ASP_CTRL2_CORE_CLOCK_SELECT 0x0
38+
#define ASP_CTRL2_CORE_CLOCK_SELECT_MAIN BIT(0)
39+
#define ASP_CTRL2_CPU_CLOCK_SELECT 0x4
40+
#define ASP_CTRL2_CPU_CLOCK_SELECT_MAIN BIT(0)
41+
3642
#define ASP_TX_ANALYTICS_OFFSET 0x4c000
3743
#define ASP_TX_ANALYTICS_CTRL 0x0
3844

@@ -134,8 +140,11 @@ enum asp_rx_net_filter_block {
134140
#define ASP_EDPKT_RX_PKT_CNT 0x138
135141
#define ASP_EDPKT_HDR_EXTR_CNT 0x13c
136142
#define ASP_EDPKT_HDR_OUT_CNT 0x140
143+
#define ASP_EDPKT_SPARE_REG 0x174
144+
#define ASP_EDPKT_SPARE_REG_EPHY_LPI BIT(4)
145+
#define ASP_EDPKT_SPARE_REG_GPHY_LPI BIT(3)
137146

138-
#define ASP_CTRL 0x101000
147+
#define ASP_CTRL_OFFSET 0x101000
139148
#define ASP_CTRL_ASP_SW_INIT 0x04
140149
#define ASP_CTRL_ASP_SW_INIT_ACPUSS_CORE BIT(0)
141150
#define ASP_CTRL_ASP_SW_INIT_ASP_TX BIT(1)
@@ -372,6 +381,8 @@ struct bcmasp_plat_data {
372381
void (*init_wol)(struct bcmasp_priv *priv);
373382
void (*enable_wol)(struct bcmasp_intf *intf, bool en);
374383
void (*destroy_wol)(struct bcmasp_priv *priv);
384+
void (*core_clock_select)(struct bcmasp_priv *priv, bool slow);
385+
void (*eee_fixup)(struct bcmasp_intf *priv, bool en);
375386
struct bcmasp_hw_info *hw_info;
376387
};
377388

@@ -390,6 +401,8 @@ struct bcmasp_priv {
390401
void (*init_wol)(struct bcmasp_priv *priv);
391402
void (*enable_wol)(struct bcmasp_intf *intf, bool en);
392403
void (*destroy_wol)(struct bcmasp_priv *priv);
404+
void (*core_clock_select)(struct bcmasp_priv *priv, bool slow);
405+
void (*eee_fixup)(struct bcmasp_intf *intf, bool en);
393406

394407
void __iomem *base;
395408
struct bcmasp_hw_info *hw_info;
@@ -530,7 +543,8 @@ BCMASP_CORE_IO_MACRO(rx_analytics, ASP_RX_ANALYTICS_OFFSET);
530543
BCMASP_CORE_IO_MACRO(rx_ctrl, ASP_RX_CTRL_OFFSET);
531544
BCMASP_CORE_IO_MACRO(rx_filter, ASP_RX_FILTER_OFFSET);
532545
BCMASP_CORE_IO_MACRO(rx_edpkt, ASP_EDPKT_OFFSET);
533-
BCMASP_CORE_IO_MACRO(ctrl, ASP_CTRL);
546+
BCMASP_CORE_IO_MACRO(ctrl, ASP_CTRL_OFFSET);
547+
BCMASP_CORE_IO_MACRO(ctrl2, ASP_CTRL2_OFFSET);
534548

535549
struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
536550
struct device_node *ndev_dn, int i);

drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,9 @@ static void bcmasp_suspend_to_wol(struct bcmasp_intf *intf)
13331333
ASP_WAKEUP_INTR2_MASK_CLEAR);
13341334
}
13351335

1336+
if (intf->eee.eee_enabled && intf->parent->eee_fixup)
1337+
intf->parent->eee_fixup(intf, true);
1338+
13361339
netif_dbg(intf, wol, ndev, "entered WOL mode\n");
13371340
}
13381341

@@ -1381,6 +1384,9 @@ static void bcmasp_resume_from_wol(struct bcmasp_intf *intf)
13811384
{
13821385
u32 reg;
13831386

1387+
if (intf->eee.eee_enabled && intf->parent->eee_fixup)
1388+
intf->parent->eee_fixup(intf, false);
1389+
13841390
reg = umac_rl(intf, UMC_MPD_CTRL);
13851391
reg &= ~UMC_MPD_CTRL_MPD_EN;
13861392
umac_wl(intf, reg, UMC_MPD_CTRL);

0 commit comments

Comments
 (0)