mbox series

[0/5] PHY: Add support to output derived and received reference clock from Torrent

Message ID 20210908182628.28364-1-sjakhade@cadence.com
Headers show
Series PHY: Add support to output derived and received reference clock from Torrent | expand

Message

Swapnil Jakhade Sept. 8, 2021, 6:26 p.m. UTC
This patch series updates reference clock driver implementation for Torrent
by adding support to output derived as well as received reference clock.
When reference clock driver is enabled, either derived or received refclk
is output on cmn_refclk_p/m.

In derived reference clock mode, cmn_refclk_p/m outputs the refclk derived
from internal PLLs while when received refclk is selected to output on
cmn_refclk_p/m, this is the internal reference clock driven on the
pma_cmn_refclk_int.

Swapnil Jakhade (5):
  phy: cadence-torrent: Migrate to clk_hw based registration and OF APIs
  dt-bindings: phy: cadence-torrent: Add clock IDs for derived and
    received refclk
  phy: cadence-torrent: Add support for derived reference clock output
  phy: cadence-torrent: Add support for received reference clock output
  phy: cadence-torrent: Model reference clock driver as a gate and mux
    clock

 drivers/phy/cadence/phy-cadence-torrent.c | 316 +++++++++++++++++++---
 include/dt-bindings/phy/phy-cadence.h     |   2 +
 2 files changed, 286 insertions(+), 32 deletions(-)

Comments

Kishon Vijay Abraham I Sept. 15, 2021, 3:51 a.m. UTC | #1
Hi Swapnil,

On 08/09/21 11:56 pm, Swapnil Jakhade wrote:
> Use clk_hw based provider APIs to register clks.


Please explain the reasoning for moving to clk_hw based API.

Thanks,
Kishon
> 

> Signed-off-by: Swapnil Jakhade <sjakhade@cadence.com>

> ---

>  drivers/phy/cadence/phy-cadence-torrent.c | 30 ++++++++++++++---------

>  1 file changed, 19 insertions(+), 11 deletions(-)

> 

> diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c

> index 415ace64adc5..ecb1aa883c05 100644

> --- a/drivers/phy/cadence/phy-cadence-torrent.c

> +++ b/drivers/phy/cadence/phy-cadence-torrent.c

> @@ -235,6 +235,8 @@

>  #define PHY_PMA_CMN_CTRL2		0x0001U

>  #define PHY_PMA_PLL_RAW_CTRL		0x0003U

>  

> +#define CDNS_TORRENT_OUTPUT_CLOCKS	1

> +

>  static const char * const clk_names[] = {

>  	[CDNS_TORRENT_REFCLK_DRIVER] = "refclk-driver",

>  };

> @@ -333,8 +335,7 @@ struct cdns_torrent_phy {

>  	struct regmap_field *phy_pma_pll_raw_ctrl;

>  	struct regmap_field *phy_reset_ctrl;

>  	struct regmap_field *phy_pcs_iso_link_ctrl_1[MAX_NUM_LANES];

> -	struct clk *clks[CDNS_TORRENT_REFCLK_DRIVER + 1];

> -	struct clk_onecell_data clk_data;

> +	struct clk_hw_onecell_data *clk_hw_data;

>  };

>  

>  enum phy_powerstate {

> @@ -1659,8 +1660,9 @@ static int cdns_torrent_derived_refclk_register(struct cdns_torrent_phy *cdns_ph

>  	const char *parent_name;

>  	struct regmap *regmap;

>  	char clk_name[100];

> +	struct clk_hw *hw;

>  	struct clk *clk;

> -	int i;

> +	int i, ret;

>  

>  	derived_refclk = devm_kzalloc(dev, sizeof(*derived_refclk), GFP_KERNEL);

>  	if (!derived_refclk)

> @@ -1706,11 +1708,12 @@ static int cdns_torrent_derived_refclk_register(struct cdns_torrent_phy *cdns_ph

>  

>  	derived_refclk->hw.init = init;

>  

> -	clk = devm_clk_register(dev, &derived_refclk->hw);

> -	if (IS_ERR(clk))

> -		return PTR_ERR(clk);

> +	hw = &derived_refclk->hw;

> +	ret = devm_clk_hw_register(dev, hw);

> +	if (ret)

> +		return ret;

>  

> -	cdns_phy->clks[CDNS_TORRENT_REFCLK_DRIVER] = clk;

> +	cdns_phy->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER] = hw;

>  

>  	return 0;

>  }

> @@ -2188,18 +2191,23 @@ static int cdns_torrent_clk_register(struct cdns_torrent_phy *cdns_phy)

>  {

>  	struct device *dev = cdns_phy->dev;

>  	struct device_node *node = dev->of_node;

> +	struct clk_hw_onecell_data *data;

>  	int ret;

>  

> +	data = devm_kzalloc(dev, struct_size(data, hws, CDNS_TORRENT_OUTPUT_CLOCKS), GFP_KERNEL);

> +	if (!data)

> +		return -ENOMEM;

> +

> +	data->num = CDNS_TORRENT_OUTPUT_CLOCKS;

> +	cdns_phy->clk_hw_data = data;

> +

>  	ret = cdns_torrent_derived_refclk_register(cdns_phy);

>  	if (ret) {

>  		dev_err(dev, "failed to register derived refclk\n");

>  		return ret;

>  	}

>  

> -	cdns_phy->clk_data.clks = cdns_phy->clks;

> -	cdns_phy->clk_data.clk_num = CDNS_TORRENT_REFCLK_DRIVER + 1;

> -

> -	ret = of_clk_add_provider(node, of_clk_src_onecell_get, &cdns_phy->clk_data);

> +	ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, data);

>  	if (ret) {

>  		dev_err(dev, "Failed to add clock provider: %s\n", node->name);

>  		return ret;

>