Commit 6c0d09d9 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'dt-bindings-dp83867-add-binding-for-io_impedance_ctrl-nvmem-cell'

Rasmus Villemoes says:

====================
dt-bindings: dp83867: add binding for io_impedance_ctrl nvmem cell

We have a board where measurements indicate that the current three
options - leaving IO_IMPEDANCE_CTRL at the reset value (which is
factory calibrated to a value corresponding to approximately 50 ohms)
or using one of the two boolean properties to set it to the min/max
value - are too coarse.

This series adds a device tree binding for an nvmem cell which can be
populated during production with a suitable value calibrated for each
board, and corresponding support in the driver. The second patch adds
a trivial phy wrapper for dev_err_probe(), used in the third.
====================

Link: https://lore.kernel.org/r/20220614084612.325229-1-linux@rasmusvillemoes.dkSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 9cbc9911 5c2d0a6a
......@@ -31,6 +31,16 @@ properties:
reg:
maxItems: 1
nvmem-cells:
maxItems: 1
description:
Nvmem data cell containing the value to write to the
IO_IMPEDANCE_CTRL field of the IO_MUX_CFG register.
nvmem-cell-names:
items:
- const: io_impedance_ctrl
ti,min-output-impedance:
type: boolean
description: |
......@@ -42,9 +52,11 @@ properties:
description: |
MAC Interface Impedance control to set the programmable output impedance
to a maximum value (70 ohms).
Note: ti,min-output-impedance and ti,max-output-impedance are mutually
exclusive. When both properties are present ti,max-output-impedance
takes precedence.
Note: Specifying an io_impedance_ctrl nvmem cell or one of the
ti,min-output-impedance, ti,max-output-impedance properties
are mutually exclusive. If more than one is present, an nvmem
cell takes precedence over ti,max-output-impedance, which in
turn takes precedence over ti,min-output-impedance.
tx-fifo-depth:
$ref: /schemas/types.yaml#/definitions/uint32
......
......@@ -14,6 +14,7 @@
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/bitfield.h>
#include <linux/nvmem-consumer.h>
#include <dt-bindings/net/ti-dp83867.h>
......@@ -522,6 +523,51 @@ static int dp83867_verify_rgmii_cfg(struct phy_device *phydev)
}
#if IS_ENABLED(CONFIG_OF_MDIO)
static int dp83867_of_init_io_impedance(struct phy_device *phydev)
{
struct dp83867_private *dp83867 = phydev->priv;
struct device *dev = &phydev->mdio.dev;
struct device_node *of_node = dev->of_node;
struct nvmem_cell *cell;
u8 *buf, val;
int ret;
cell = of_nvmem_cell_get(of_node, "io_impedance_ctrl");
if (IS_ERR(cell)) {
ret = PTR_ERR(cell);
if (ret != -ENOENT)
return phydev_err_probe(phydev, ret,
"failed to get nvmem cell io_impedance_ctrl\n");
/* If no nvmem cell, check for the boolean properties. */
if (of_property_read_bool(of_node, "ti,max-output-impedance"))
dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX;
else if (of_property_read_bool(of_node, "ti,min-output-impedance"))
dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN;
else
dp83867->io_impedance = -1; /* leave at default */
return 0;
}
buf = nvmem_cell_read(cell, NULL);
nvmem_cell_put(cell);
if (IS_ERR(buf))
return PTR_ERR(buf);
val = *buf;
kfree(buf);
if ((val & DP83867_IO_MUX_CFG_IO_IMPEDANCE_MASK) != val) {
phydev_err(phydev, "nvmem cell 'io_impedance_ctrl' contents out of range\n");
return -ERANGE;
}
dp83867->io_impedance = val;
return 0;
}
static int dp83867_of_init(struct phy_device *phydev)
{
struct dp83867_private *dp83867 = phydev->priv;
......@@ -549,12 +595,9 @@ static int dp83867_of_init(struct phy_device *phydev)
}
}
if (of_property_read_bool(of_node, "ti,max-output-impedance"))
dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX;
else if (of_property_read_bool(of_node, "ti,min-output-impedance"))
dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN;
else
dp83867->io_impedance = -1; /* leave at default */
ret = dp83867_of_init_io_impedance(phydev);
if (ret)
return ret;
dp83867->rxctrl_strap_quirk = of_property_read_bool(of_node,
"ti,dp83867-rxctrl-strap-quirk");
......
......@@ -1539,6 +1539,9 @@ static inline void phy_device_reset(struct phy_device *phydev, int value)
#define phydev_err(_phydev, format, args...) \
dev_err(&_phydev->mdio.dev, format, ##args)
#define phydev_err_probe(_phydev, err, format, args...) \
dev_err_probe(&_phydev->mdio.dev, err, format, ##args)
#define phydev_info(_phydev, format, args...) \
dev_info(&_phydev->mdio.dev, format, ##args)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment