Skip to content

Commit f573c0b

Browse files
jpintodavem330
authored andcommitted
stmmac: move stmmac_clk, pclk, clk_ptp_ref and stmmac_rst to platform structure
This patch moves stmmac_clk, pclk, clk_ptp_ref and stmmac_rst to the plat_stmmacenet_data structure. It also moves these platform variables initialization to stmmac_platform. This was done for two reasons: a) If PCI is used, platform related code is being executed in stmmac_main resulting in warnings that have no sense and conceptually was not right b) stmmac as a synopsys reference ethernet driver stack will be hosting more and more drivers to its structure like synopsys/dwc_eth_qos.c. These drivers have their own DT bindings that are not compatible with stmmac's. One of the most important are the clock names, and so they need to be parsed in the glue logic and initialized there, and that is the main reason why the clocks were passed to the platform structure. Signed-off-by: Joao Pinto <jpinto@synopsys.com> Tested-by: Niklas Cassel <niklas.cassel@axis.com> Reviewed-by: Lars Persson <larper@axis.com> Acked-by: Alexandre TORGUE <alexandre.torgue@st.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b4b7b77 commit f573c0b

File tree

6 files changed

+70
-75
lines changed

6 files changed

+70
-75
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
341341
* mode. Create a copy of the core reset handle so it can be used by
342342
* the driver later.
343343
*/
344-
dwmac->stmmac_rst = stpriv->stmmac_rst;
344+
dwmac->stmmac_rst = stpriv->plat->stmmac_rst;
345345

346346
ret = socfpga_dwmac_set_phy_mode(dwmac);
347347
if (ret)

drivers/net/ethernet/stmicro/stmmac/stmmac.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ struct stmmac_priv {
106106
u32 msg_enable;
107107
int wolopts;
108108
int wol_irq;
109-
struct clk *stmmac_clk;
110-
struct clk *pclk;
111-
struct reset_control *stmmac_rst;
112109
int clk_csr;
113110
struct timer_list eee_ctrl_timer;
114111
int lpi_irq;
@@ -120,8 +117,6 @@ struct stmmac_priv {
120117
struct ptp_clock *ptp_clock;
121118
struct ptp_clock_info ptp_clock_ops;
122119
unsigned int default_addend;
123-
struct clk *clk_ptp_ref;
124-
unsigned int clk_ptp_rate;
125120
u32 adv_ts;
126121
int use_riwt;
127122
int irq_wake;

drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev,
712712

713713
static u32 stmmac_usec2riwt(u32 usec, struct stmmac_priv *priv)
714714
{
715-
unsigned long clk = clk_get_rate(priv->stmmac_clk);
715+
unsigned long clk = clk_get_rate(priv->plat->stmmac_clk);
716716

717717
if (!clk)
718718
return 0;
@@ -722,7 +722,7 @@ static u32 stmmac_usec2riwt(u32 usec, struct stmmac_priv *priv)
722722

723723
static u32 stmmac_riwt2usec(u32 riwt, struct stmmac_priv *priv)
724724
{
725-
unsigned long clk = clk_get_rate(priv->stmmac_clk);
725+
unsigned long clk = clk_get_rate(priv->plat->stmmac_clk);
726726

727727
if (!clk)
728728
return 0;

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static void stmmac_clk_csr_set(struct stmmac_priv *priv)
158158
{
159159
u32 clk_rate;
160160

161-
clk_rate = clk_get_rate(priv->stmmac_clk);
161+
clk_rate = clk_get_rate(priv->plat->stmmac_clk);
162162

163163
/* Platform provided default clk_csr would be assumed valid
164164
* for all other cases except for the below mentioned ones.
@@ -607,7 +607,7 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
607607

608608
/* program Sub Second Increment reg */
609609
sec_inc = priv->hw->ptp->config_sub_second_increment(
610-
priv->ptpaddr, priv->clk_ptp_rate,
610+
priv->ptpaddr, priv->plat->clk_ptp_rate,
611611
priv->plat->has_gmac4);
612612
temp = div_u64(1000000000ULL, sec_inc);
613613

@@ -617,7 +617,7 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
617617
* where, freq_div_ratio = 1e9ns/sec_inc
618618
*/
619619
temp = (u64)(temp << 32);
620-
priv->default_addend = div_u64(temp, priv->clk_ptp_rate);
620+
priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate);
621621
priv->hw->ptp->config_addend(priv->ptpaddr,
622622
priv->default_addend);
623623

@@ -645,18 +645,6 @@ static int stmmac_init_ptp(struct stmmac_priv *priv)
645645
if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))
646646
return -EOPNOTSUPP;
647647

648-
/* Fall-back to main clock in case of no PTP ref is passed */
649-
priv->clk_ptp_ref = devm_clk_get(priv->device, "clk_ptp_ref");
650-
if (IS_ERR(priv->clk_ptp_ref)) {
651-
priv->clk_ptp_rate = clk_get_rate(priv->stmmac_clk);
652-
priv->clk_ptp_ref = NULL;
653-
netdev_dbg(priv->dev, "PTP uses main clock\n");
654-
} else {
655-
clk_prepare_enable(priv->clk_ptp_ref);
656-
priv->clk_ptp_rate = clk_get_rate(priv->clk_ptp_ref);
657-
netdev_dbg(priv->dev, "PTP rate %d\n", priv->clk_ptp_rate);
658-
}
659-
660648
priv->adv_ts = 0;
661649
/* Check if adv_ts can be enabled for dwmac 4.x core */
662650
if (priv->plat->has_gmac4 && priv->dma_cap.atime_stamp)
@@ -683,8 +671,8 @@ static int stmmac_init_ptp(struct stmmac_priv *priv)
683671

684672
static void stmmac_release_ptp(struct stmmac_priv *priv)
685673
{
686-
if (priv->clk_ptp_ref)
687-
clk_disable_unprepare(priv->clk_ptp_ref);
674+
if (priv->plat->clk_ptp_ref)
675+
clk_disable_unprepare(priv->plat->clk_ptp_ref);
688676
stmmac_ptp_unregister(priv);
689677
}
690678

@@ -3278,44 +3266,8 @@ int stmmac_dvr_probe(struct device *device,
32783266
if ((phyaddr >= 0) && (phyaddr <= 31))
32793267
priv->plat->phy_addr = phyaddr;
32803268

3281-
priv->stmmac_clk = devm_clk_get(priv->device, STMMAC_RESOURCE_NAME);
3282-
if (IS_ERR(priv->stmmac_clk)) {
3283-
netdev_warn(priv->dev, "%s: warning: cannot get CSR clock\n",
3284-
__func__);
3285-
/* If failed to obtain stmmac_clk and specific clk_csr value
3286-
* is NOT passed from the platform, probe fail.
3287-
*/
3288-
if (!priv->plat->clk_csr) {
3289-
ret = PTR_ERR(priv->stmmac_clk);
3290-
goto error_clk_get;
3291-
} else {
3292-
priv->stmmac_clk = NULL;
3293-
}
3294-
}
3295-
clk_prepare_enable(priv->stmmac_clk);
3296-
3297-
priv->pclk = devm_clk_get(priv->device, "pclk");
3298-
if (IS_ERR(priv->pclk)) {
3299-
if (PTR_ERR(priv->pclk) == -EPROBE_DEFER) {
3300-
ret = -EPROBE_DEFER;
3301-
goto error_pclk_get;
3302-
}
3303-
priv->pclk = NULL;
3304-
}
3305-
clk_prepare_enable(priv->pclk);
3306-
3307-
priv->stmmac_rst = devm_reset_control_get(priv->device,
3308-
STMMAC_RESOURCE_NAME);
3309-
if (IS_ERR(priv->stmmac_rst)) {
3310-
if (PTR_ERR(priv->stmmac_rst) == -EPROBE_DEFER) {
3311-
ret = -EPROBE_DEFER;
3312-
goto error_hw_init;
3313-
}
3314-
dev_info(priv->device, "no reset control found\n");
3315-
priv->stmmac_rst = NULL;
3316-
}
3317-
if (priv->stmmac_rst)
3318-
reset_control_deassert(priv->stmmac_rst);
3269+
if (priv->plat->stmmac_rst)
3270+
reset_control_deassert(priv->plat->stmmac_rst);
33193271

33203272
/* Init MAC and get the capabilities */
33213273
ret = stmmac_hw_init(priv);
@@ -3409,10 +3361,6 @@ int stmmac_dvr_probe(struct device *device,
34093361
error_mdio_register:
34103362
netif_napi_del(&priv->napi);
34113363
error_hw_init:
3412-
clk_disable_unprepare(priv->pclk);
3413-
error_pclk_get:
3414-
clk_disable_unprepare(priv->stmmac_clk);
3415-
error_clk_get:
34163364
free_netdev(ndev);
34173365

34183366
return ret;
@@ -3438,10 +3386,10 @@ int stmmac_dvr_remove(struct device *dev)
34383386
stmmac_set_mac(priv->ioaddr, false);
34393387
netif_carrier_off(ndev);
34403388
unregister_netdev(ndev);
3441-
if (priv->stmmac_rst)
3442-
reset_control_assert(priv->stmmac_rst);
3443-
clk_disable_unprepare(priv->pclk);
3444-
clk_disable_unprepare(priv->stmmac_clk);
3389+
if (priv->plat->stmmac_rst)
3390+
reset_control_assert(priv->plat->stmmac_rst);
3391+
clk_disable_unprepare(priv->plat->pclk);
3392+
clk_disable_unprepare(priv->plat->stmmac_clk);
34453393
if (priv->hw->pcs != STMMAC_PCS_RGMII &&
34463394
priv->hw->pcs != STMMAC_PCS_TBI &&
34473395
priv->hw->pcs != STMMAC_PCS_RTBI)
@@ -3490,8 +3438,8 @@ int stmmac_suspend(struct device *dev)
34903438
stmmac_set_mac(priv->ioaddr, false);
34913439
pinctrl_pm_select_sleep_state(priv->device);
34923440
/* Disable clock in case of PWM is off */
3493-
clk_disable(priv->pclk);
3494-
clk_disable(priv->stmmac_clk);
3441+
clk_disable(priv->plat->pclk);
3442+
clk_disable(priv->plat->stmmac_clk);
34953443
}
34963444
spin_unlock_irqrestore(&priv->lock, flags);
34973445

@@ -3531,8 +3479,8 @@ int stmmac_resume(struct device *dev)
35313479
} else {
35323480
pinctrl_pm_select_default_state(priv->device);
35333481
/* enable the clk prevously disabled */
3534-
clk_enable(priv->stmmac_clk);
3535-
clk_enable(priv->pclk);
3482+
clk_enable(priv->plat->stmmac_clk);
3483+
clk_enable(priv->plat->pclk);
35363484
/* reset the phy so that it's ready */
35373485
if (priv->mii)
35383486
stmmac_mdio_reset(priv->mii);

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,54 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
335335

336336
plat->axi = stmmac_axi_setup(pdev);
337337

338+
/* clock setup */
339+
plat->stmmac_clk = devm_clk_get(&pdev->dev,
340+
STMMAC_RESOURCE_NAME);
341+
if (IS_ERR(plat->stmmac_clk)) {
342+
dev_warn(&pdev->dev, "Cannot get CSR clock\n");
343+
plat->stmmac_clk = NULL;
344+
}
345+
clk_prepare_enable(plat->stmmac_clk);
346+
347+
plat->pclk = devm_clk_get(&pdev->dev, "pclk");
348+
if (IS_ERR(plat->pclk)) {
349+
if (PTR_ERR(plat->pclk) == -EPROBE_DEFER)
350+
goto error_pclk_get;
351+
352+
plat->pclk = NULL;
353+
}
354+
clk_prepare_enable(plat->pclk);
355+
356+
/* Fall-back to main clock in case of no PTP ref is passed */
357+
plat->clk_ptp_ref = devm_clk_get(&pdev->dev, "clk_ptp_ref");
358+
if (IS_ERR(plat->clk_ptp_ref)) {
359+
plat->clk_ptp_rate = clk_get_rate(plat->stmmac_clk);
360+
plat->clk_ptp_ref = NULL;
361+
dev_warn(&pdev->dev, "PTP uses main clock\n");
362+
} else {
363+
clk_prepare_enable(plat->clk_ptp_ref);
364+
plat->clk_ptp_rate = clk_get_rate(plat->clk_ptp_ref);
365+
dev_info(&pdev->dev, "No reset control found\n");
366+
}
367+
368+
plat->stmmac_rst = devm_reset_control_get(&pdev->dev,
369+
STMMAC_RESOURCE_NAME);
370+
if (IS_ERR(plat->stmmac_rst)) {
371+
if (PTR_ERR(plat->stmmac_rst) == -EPROBE_DEFER)
372+
goto error_hw_init;
373+
374+
dev_info(&pdev->dev, "no reset control found\n");
375+
plat->stmmac_rst = NULL;
376+
}
377+
338378
return plat;
379+
380+
error_hw_init:
381+
clk_disable_unprepare(plat->pclk);
382+
error_pclk_get:
383+
clk_disable_unprepare(plat->stmmac_clk);
384+
385+
return ERR_PTR(-EPROBE_DEFER);
339386
}
340387

341388
/**

include/linux/stmmac.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ struct plat_stmmacenet_data {
138138
int (*init)(struct platform_device *pdev, void *priv);
139139
void (*exit)(struct platform_device *pdev, void *priv);
140140
void *bsp_priv;
141+
struct clk *stmmac_clk;
142+
struct clk *pclk;
143+
struct clk *clk_ptp_ref;
144+
unsigned int clk_ptp_rate;
145+
struct reset_control *stmmac_rst;
141146
struct stmmac_axi *axi;
142147
int has_gmac4;
143148
bool tso_en;

0 commit comments

Comments
 (0)