Simplify registration of the three refclk-related clocks by building their struct clk_init_data on the stack instead of keeping a clk_init_data member in each clock structure. parent_names becomes a fixed-size stack array, dropping a devm_kzalloc().
struct cdns_torrent_derived_refclk and struct cdns_torrent_received_refclk are removed; each clock now embeds a plain struct clk_hw in struct tp_data. The container_of helpers are replaced so the clock ops reach struct tp_data directly and use the phy_pipe_cmn_ctrl1_0/cmn_cdiag_refclk_ovrd_4 fields already stored there, instead of going through a per-clock wrapper. No functional change intended. Signed-off-by: Benjamin Robin <[email protected]> --- drivers/phy/cadence/phy-cadence-torrent.c | 144 +++++++++++------------------- 1 file changed, 51 insertions(+), 93 deletions(-) diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c index 2bdc63caec1e..d626e3780cf6 100644 --- a/drivers/phy/cadence/phy-cadence-torrent.c +++ b/drivers/phy/cadence/phy-cadence-torrent.c @@ -276,32 +276,17 @@ static const u32 tp_refclk_driver_mux_table[] = { 1, 0 }; struct tp_refclk_driver { struct clk_hw hw; struct tp_reg_field fields[TP_REFCLK_OUT_NUM_CMN_CONFIG]; - struct clk_init_data clk_data; u8 parent_index; }; #define tp_refclk_driver_to_clk_data(_hw) \ container_of(_hw, struct tp_refclk_driver, hw) -struct cdns_torrent_derived_refclk { - struct clk_hw hw; - struct tp_reg_field *phy_pipe_cmn_ctrl1_0; - struct tp_reg_field *cmn_cdiag_refclk_ovrd_4; - struct clk_init_data clk_data; -}; +#define tp_derived_refclk_to_tp_data(_hw) \ + container_of(_hw, struct tp_data, derived_refclk) -#define to_cdns_torrent_derived_refclk(_hw) \ - container_of(_hw, struct cdns_torrent_derived_refclk, hw) - -struct cdns_torrent_received_refclk { - struct clk_hw hw; - struct tp_reg_field *phy_pipe_cmn_ctrl1_0; - struct tp_reg_field *cmn_cdiag_refclk_ovrd_4; - struct clk_init_data clk_data; -}; - -#define to_cdns_torrent_received_refclk(_hw) \ - container_of(_hw, struct cdns_torrent_received_refclk, hw) +#define tp_received_refclk_to_tp_data(_hw) \ + container_of(_hw, struct tp_data, received_refclk) enum cdns_torrent_phy_type { TYPE_NONE, @@ -394,8 +379,8 @@ struct tp_data { struct clk_hw_onecell_data *clk_hw_data; struct tp_refclk_driver refclk_driver; - struct cdns_torrent_derived_refclk derived_refclk; - struct cdns_torrent_received_refclk received_refclk; + struct clk_hw derived_refclk; + struct clk_hw received_refclk; }; enum phy_powerstate { @@ -1665,28 +1650,28 @@ static int cdns_torrent_dp_multilink_init(struct tp_data *tp_data, static int tp_derived_refclk_enable(struct clk_hw *hw) { - struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw); + struct tp_data *tp_data = tp_derived_refclk_to_tp_data(hw); - tp_reg_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 1); - tp_reg_field_write(derived_refclk->phy_pipe_cmn_ctrl1_0, 1); + tp_reg_field_write(&tp_data->cmn_cdiag_refclk_ovrd_4, 1); + tp_reg_field_write(&tp_data->phy_pipe_cmn_ctrl1_0, 1); return 0; } static void tp_derived_refclk_disable(struct clk_hw *hw) { - struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw); + struct tp_data *tp_data = tp_derived_refclk_to_tp_data(hw); - tp_reg_field_write(derived_refclk->phy_pipe_cmn_ctrl1_0, 0); - tp_reg_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 0); + tp_reg_field_write(&tp_data->phy_pipe_cmn_ctrl1_0, 0); + tp_reg_field_write(&tp_data->cmn_cdiag_refclk_ovrd_4, 0); } static int tp_derived_refclk_is_enabled(struct clk_hw *hw) { - struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw); + struct tp_data *tp_data = tp_derived_refclk_to_tp_data(hw); u16 val; - val = tp_reg_field_read(derived_refclk->cmn_cdiag_refclk_ovrd_4); + val = tp_reg_field_read(&tp_data->cmn_cdiag_refclk_ovrd_4); return !!val; } @@ -1698,17 +1683,14 @@ static const struct clk_ops tp_derived_refclk_ops = { static int tp_derived_refclk_register(struct tp_data *tp_data) { - struct cdns_torrent_derived_refclk *derived_refclk; + struct clk_init_data init_data = { .flags = 0 }; struct device *dev = tp_data->dev; - struct clk_init_data *init; const char *parent_name; char clk_name[100]; struct clk_hw *hw; struct clk *clk; int ret; - derived_refclk = &tp_data->derived_refclk; - snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), tp_clk_names[CDNS_TORRENT_DERIVED_REFCLK]); @@ -1718,23 +1700,16 @@ static int tp_derived_refclk_register(struct tp_data *tp_data) return PTR_ERR(clk); } - init = &derived_refclk->clk_data; - if (clk) { parent_name = __clk_get_name(clk); - init->parent_names = &parent_name; - init->num_parents = 1; + init_data.parent_names = &parent_name; + init_data.num_parents = 1; } - init->ops = &tp_derived_refclk_ops; - init->flags = 0; - init->name = clk_name; + init_data.ops = &tp_derived_refclk_ops; + init_data.name = clk_name; - derived_refclk->phy_pipe_cmn_ctrl1_0 = &tp_data->phy_pipe_cmn_ctrl1_0; - derived_refclk->cmn_cdiag_refclk_ovrd_4 = &tp_data->cmn_cdiag_refclk_ovrd_4; - - derived_refclk->hw.init = init; - - hw = &derived_refclk->hw; + hw = &tp_data->derived_refclk; + hw->init = &init_data; ret = devm_clk_hw_register(dev, hw); if (ret) return ret; @@ -1746,26 +1721,26 @@ static int tp_derived_refclk_register(struct tp_data *tp_data) static int tp_received_refclk_enable(struct clk_hw *hw) { - struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw); + struct tp_data *tp_data = tp_received_refclk_to_tp_data(hw); - tp_reg_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 1); + tp_reg_field_write(&tp_data->phy_pipe_cmn_ctrl1_0, 1); return 0; } static void tp_received_refclk_disable(struct clk_hw *hw) { - struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw); + struct tp_data *tp_data = tp_received_refclk_to_tp_data(hw); - tp_reg_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 0); + tp_reg_field_write(&tp_data->phy_pipe_cmn_ctrl1_0, 0); } static int tp_received_refclk_is_enabled(struct clk_hw *hw) { - struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw); + struct tp_data *tp_data = tp_received_refclk_to_tp_data(hw); u16 val, cmn_val; - val = tp_reg_field_read(received_refclk->phy_pipe_cmn_ctrl1_0); - cmn_val = tp_reg_field_read(received_refclk->cmn_cdiag_refclk_ovrd_4); + val = tp_reg_field_read(&tp_data->phy_pipe_cmn_ctrl1_0); + cmn_val = tp_reg_field_read(&tp_data->cmn_cdiag_refclk_ovrd_4); return val && !cmn_val; } @@ -1778,17 +1753,14 @@ static const struct clk_ops tp_received_refclk_ops = { static int tp_received_refclk_register(struct tp_data *tp_data) { - struct cdns_torrent_received_refclk *received_refclk; + struct clk_init_data init_data = { .flags = 0 }; struct device *dev = tp_data->dev; - struct clk_init_data *init; const char *parent_name; char clk_name[100]; struct clk_hw *hw; struct clk *clk; int ret; - received_refclk = &tp_data->received_refclk; - snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), tp_clk_names[CDNS_TORRENT_RECEIVED_REFCLK]); @@ -1798,23 +1770,16 @@ static int tp_received_refclk_register(struct tp_data *tp_data) return PTR_ERR(clk); } - init = &received_refclk->clk_data; - if (clk) { parent_name = __clk_get_name(clk); - init->parent_names = &parent_name; - init->num_parents = 1; + init_data.parent_names = &parent_name; + init_data.num_parents = 1; } - init->ops = &tp_received_refclk_ops; - init->flags = 0; - init->name = clk_name; + init_data.ops = &tp_received_refclk_ops; + init_data.name = clk_name; - received_refclk->phy_pipe_cmn_ctrl1_0 = &tp_data->phy_pipe_cmn_ctrl1_0; - received_refclk->cmn_cdiag_refclk_ovrd_4 = &tp_data->cmn_cdiag_refclk_ovrd_4; - - received_refclk->hw.init = init; - - hw = &received_refclk->hw; + hw = &tp_data->received_refclk; + hw->init = &init_data; ret = devm_clk_hw_register(dev, hw); if (ret) return ret; @@ -1865,6 +1830,9 @@ static int tp_refclk_driver_set_parent(struct clk_hw *hw, u8 index) struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw); u16 val; + if (index >= ARRAY_SIZE(tp_refclk_driver_mux_table)) + return -EINVAL; + val = tp_refclk_driver_mux_table[index]; tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], val); return 0; @@ -1881,23 +1849,16 @@ static const struct clk_ops tp_refclk_driver_ops = { static int tp_refclk_driver_register(struct tp_data *tp_data) { - struct tp_refclk_driver *refclk_driver; + struct clk_init_data init_data = { .flags = 0 }; struct device *dev = tp_data->dev; - struct clk_init_data *init; - const char **parent_names; - unsigned int num_parents; + const char *parent_names[ARRAY_SIZE(tp_refclk_driver_parent_idx)]; + u32 num_parents; char clk_name[100]; struct clk_hw *hw; - int i, ret; - - refclk_driver = &tp_data->refclk_driver; + int ret; num_parents = ARRAY_SIZE(tp_refclk_driver_parent_idx); - parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents), GFP_KERNEL); - if (!parent_names) - return -ENOMEM; - - for (i = 0; i < num_parents; i++) { + for (u32 i = 0; i < num_parents; ++i) { hw = tp_data->clk_hw_data->hws[tp_refclk_driver_parent_idx[i]]; if (IS_ERR_OR_NULL(hw)) { dev_err(dev, "No parent clock for refclk driver clock\n"); @@ -1909,20 +1870,17 @@ static int tp_refclk_driver_register(struct tp_data *tp_data) snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), tp_clk_names[CDNS_TORRENT_REFCLK_DRIVER]); - init = &refclk_driver->clk_data; - - init->ops = &tp_refclk_driver_ops; - init->flags = CLK_SET_RATE_NO_REPARENT; - init->parent_names = parent_names; - init->num_parents = num_parents; - init->name = clk_name; + init_data.ops = &tp_refclk_driver_ops; + init_data.flags = CLK_SET_RATE_NO_REPARENT; + init_data.parent_names = parent_names; + init_data.num_parents = num_parents; + init_data.name = clk_name; /* Enable Derived reference clock as default */ - tp_reg_field_write(&refclk_driver->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], 1); + tp_reg_field_write(&tp_data->refclk_driver.fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], 1); - refclk_driver->hw.init = init; - - hw = &refclk_driver->hw; + hw = &tp_data->refclk_driver.hw; + hw->init = &init_data; ret = devm_clk_hw_register(dev, hw); if (ret) return ret; -- 2.56.1
