mbox series

[v2,0/3] net: mdio: mdio-thunder: MDIO clock related changes for Marvell Octeon Family.

Message ID 20220530125329.30717-1-pmalgujar@marvell.com
Headers show
Series net: mdio: mdio-thunder: MDIO clock related changes for Marvell Octeon Family. | expand

Message

Piyush Malgujar May 30, 2022, 12:53 p.m. UTC
This patch series mdio changes are pertaining to Marvell Octeon family.

1) clock gating:
	The purpose of this change is to apply clock gating for MDIO clock
	when there is no transaction happening. This will stop the MDC
	clock toggling in idle scenario.

2) Marvell MDIO clock frequency attribute change:
	This MDIO change provides an option for user to have the bus speed
	set to their needs. The clock-freq for Marvell Octeon defaults to
	3.125 MHz and not 2.5 MHz as standard. In case someone needs to use
	this attribute, they have to add an extra attribute
	"clock-frequency" in the mdio entry in their DTS and this driver
	will do the rest.
        The changes are made in a way that the clock will set to the
	nearest possible value based on the clock calculation and required
	frequency from DTS.
        
These changes has been verified internally with Marvell Octeon series.

Changes since V1:
* Separated the logical changes in separate patches
* Replaced macros with functions
* Used proper property name for DTS
* Updated DTS binding

Piyush Malgujar (3):
  net: mdio: mdio-thunder: stop toggling SMI clock on idle
  dt-bindings: net: cavium-mdio.txt: add clock-frequency attribute
  net: mdio: mdio-thunder: support for clock-freq attribute

 .../devicetree/bindings/net/cavium-mdio.txt   |  5 ++
 drivers/net/mdio/mdio-cavium.h                |  1 +
 drivers/net/mdio/mdio-thunder.c               | 68 +++++++++++++++++++
 3 files changed, 74 insertions(+)

Comments

Andrew Lunn June 5, 2022, 3:24 a.m. UTC | #1
> +static inline u32 clk_freq(u32 phase)

Please keep with the naming scheme in the rest of the driver, 
thunder_mdiobus_clk_freq()

> +{
> +	return (100000000U / (2 * (phase)));
> +}
> +
> +static inline u32 calc_sample(u32 phase)
> +{

thunder_mdiobus_calc_sample()

> +	return (2 * (phase) - 3);
> +}
> +
> +static u32 _config_clk(u32 req_freq, u32 *phase, u32 *sample)

thunder_mdiobus_config_clk().

> +{
> +	unsigned int p;
> +	u32 freq = 0, freq_prev;
> +
> +	for (p = PHASE_MIN; p < PHASE_DFLT; p++) {
> +		freq_prev = freq;
> +		freq = clk_freq(p);
> +
> +		if (req_freq >= freq)
> +			break;
> +	}
> +
> +	if (p == PHASE_DFLT)
> +		freq = clk_freq(PHASE_DFLT);
> +
> +	if (p == PHASE_MIN || p == PHASE_DFLT)
> +		goto out;
> +
> +	/* Check which clock value from the identified range
> +	 * is closer to the requested value
> +	 */
> +	if ((freq_prev - req_freq) < (req_freq - freq)) {
> +		p = p - 1;
> +		freq = freq_prev;
> +	}
> +out:
> +	*phase = p;
> +	*sample = calc_sample(p);
> +	return freq;
> +}
> +
>  static int thunder_mdiobus_pci_probe(struct pci_dev *pdev,
>  				     const struct pci_device_id *ent)
>  {
> @@ -56,6 +101,7 @@ static int thunder_mdiobus_pci_probe(struct pci_dev *pdev,
>  	i = 0;
>  	device_for_each_child_node(&pdev->dev, fwn) {
>  		struct resource r;
> +		u32 req_clk_freq;
>  		struct mii_bus *mii_bus;
>  		struct cavium_mdiobus *bus;
>  		union cvmx_smix_clk smi_clk;
> @@ -90,6 +136,23 @@ static int thunder_mdiobus_pci_probe(struct pci_dev *pdev,
>  
>  		smi_clk.u64 = oct_mdio_readq(bus->register_base + SMI_CLK);
>  		smi_clk.s.clk_idle = 1;
> +
> +		if (!of_property_read_u32(node, "clock-frequency", &req_clk_freq)) {
> +			u32 phase, sample;
> +
> +			dev_dbg(&pdev->dev, "requested bus clock frequency=%d\n",
> +				req_clk_freq);
> +
> +			bus->clk_freq = _config_clk(req_clk_freq,
> +						    &phase, &sample);
> +
> +			smi_clk.s.phase = phase;
> +			smi_clk.s.sample_hi = (sample >> 4) & 0x1f;
> +			smi_clk.s.sample = sample & 0xf;
> +		} else {
> +			bus->clk_freq = clk_freq(PHASE_DFLT);
> +		}

You can make this simpler by setting req_clk_freq to your odd
default. Then call of_property_read_u32(). If the property is not
defined, the value of req_clk_freq will not be changed, and the
calculation should come out with the correct value.

	    Andrew