Re: [net-next PATCH v1 1/3] net: stmmac: dwmac-meson8b: simplify clock registration

2018-02-17 Thread Jerome Brunet
On Sat, 2018-02-17 at 15:08 +0100, Martin Blumenstingl wrote:
> To goal of this patch is to simplify the registration of the RGMII TX
> clock (and it's parent clocks). This is achieved by:
> - introducing the meson8b_dwmac_register_clk helper-function to remove
>   code duplication when registering a single clock (this saves a few
>   lines since we have 4 clocks internally)
> - using devm_add_action_or_reset to disable the RGMII TX clock
>   automatically when needed. This also allows us to re-use the standard
>   stmmac_pltfr_remove function.
> - devm_kasprintf() and devm_kstrdup() are not used anymore to generate
>   the clock name (these are replaced by a variable on the stack) because
>   the common clock framework already uses kstrdup() internally.
> 
> No functional changes intended.
> 
> Signed-off-by: Martin Blumenstingl 

Reviewed-by: Jerome Brunet 


[net-next PATCH v1 1/3] net: stmmac: dwmac-meson8b: simplify clock registration

2018-02-17 Thread Martin Blumenstingl
To goal of this patch is to simplify the registration of the RGMII TX
clock (and it's parent clocks). This is achieved by:
- introducing the meson8b_dwmac_register_clk helper-function to remove
  code duplication when registering a single clock (this saves a few
  lines since we have 4 clocks internally)
- using devm_add_action_or_reset to disable the RGMII TX clock
  automatically when needed. This also allows us to re-use the standard
  stmmac_pltfr_remove function.
- devm_kasprintf() and devm_kstrdup() are not used anymore to generate
  the clock name (these are replaced by a variable on the stack) because
  the common clock framework already uses kstrdup() internally.

No functional changes intended.

Signed-off-by: Martin Blumenstingl 
---
 .../net/ethernet/stmicro/stmmac/dwmac-meson8b.c| 156 +
 1 file changed, 65 insertions(+), 91 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
index 5270d26f0bc6..84a9a900e74e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
@@ -55,17 +55,11 @@ struct meson8b_dwmac {
phy_interface_t phy_mode;
 
struct clk_mux  m250_mux;
-   struct clk  *m250_mux_clk;
-   struct clk  *m250_mux_parent[MUX_CLK_NUM_PARENTS];
-
struct clk_divider  m250_div;
-   struct clk  *m250_div_clk;
-
struct clk_fixed_factor fixed_div2;
-   struct clk  *fixed_div2_clk;
-
struct clk_gate rgmii_tx_en;
-   struct clk  *rgmii_tx_en_clk;
+
+   struct clk  *rgmii_tx_clk;
 
u32 tx_delay_ns;
 };
@@ -82,106 +76,95 @@ static void meson8b_dwmac_mask_bits(struct meson8b_dwmac 
*dwmac, u32 reg,
writel(data, dwmac->regs + reg);
 }
 
-static int meson8b_init_rgmii_tx_clk(struct meson8b_dwmac *dwmac)
+static struct clk *meson8b_dwmac_register_clk(struct meson8b_dwmac *dwmac,
+ const char *name_suffix,
+ const char **parent_names,
+ int num_parents,
+ const struct clk_ops *ops,
+ struct clk_hw *hw)
 {
+   struct device *dev = >pdev->dev;
struct clk_init_data init;
+   char clk_name[32];
+
+   snprintf(clk_name, sizeof(clk_name), "%s#%s", dev_name(dev),
+name_suffix);
+
+   init.name = clk_name;
+   init.ops = ops;
+   init.flags = CLK_SET_RATE_PARENT;
+   init.parent_names = parent_names;
+   init.num_parents = num_parents;
+
+   hw->init = 
+
+   return devm_clk_register(dev, hw);
+}
+
+static int meson8b_init_rgmii_tx_clk(struct meson8b_dwmac *dwmac)
+{
int i, ret;
+   struct clk *clk;
struct device *dev = >pdev->dev;
-   char clk_name[32];
-   const char *clk_div_parents[1];
-   const char *mux_parent_names[MUX_CLK_NUM_PARENTS];
+   const char *parent_name, *mux_parent_names[MUX_CLK_NUM_PARENTS];
 
/* get the mux parents from DT */
for (i = 0; i < MUX_CLK_NUM_PARENTS; i++) {
char name[16];
 
snprintf(name, sizeof(name), "clkin%d", i);
-   dwmac->m250_mux_parent[i] = devm_clk_get(dev, name);
-   if (IS_ERR(dwmac->m250_mux_parent[i])) {
-   ret = PTR_ERR(dwmac->m250_mux_parent[i]);
+   clk = devm_clk_get(dev, name);
+   if (IS_ERR(clk)) {
+   ret = PTR_ERR(clk);
if (ret != -EPROBE_DEFER)
dev_err(dev, "Missing clock %s\n", name);
return ret;
}
 
-   mux_parent_names[i] =
-   __clk_get_name(dwmac->m250_mux_parent[i]);
+   mux_parent_names[i] = __clk_get_name(clk);
}
 
-   /* create the m250_mux */
-   snprintf(clk_name, sizeof(clk_name), "%s#m250_sel", dev_name(dev));
-   init.name = clk_name;
-   init.ops = _mux_ops;
-   init.flags = CLK_SET_RATE_PARENT;
-   init.parent_names = mux_parent_names;
-   init.num_parents = MUX_CLK_NUM_PARENTS;
-
dwmac->m250_mux.reg = dwmac->regs + PRG_ETH0;
dwmac->m250_mux.shift = PRG_ETH0_CLK_M250_SEL_SHIFT;
dwmac->m250_mux.mask = PRG_ETH0_CLK_M250_SEL_MASK;
-   dwmac->m250_mux.flags = 0;
-   dwmac->m250_mux.table = NULL;
-   dwmac->m250_mux.hw.init = 
-
-   dwmac->m250_mux_clk = devm_clk_register(dev, >m250_mux.hw);
-   if (WARN_ON(IS_ERR(dwmac->m250_mux_clk)))
-   return PTR_ERR(dwmac->m250_mux_clk);
-
-   /* create the m250_div */
-   snprintf(clk_name, sizeof(clk_name), "%s#m250_div",