Re: [PATCH 7/9] net: mvmdio: add xmdio support
From: Florian Fainelli <f.fainelli@gmail.com>
Date: 2017-06-07 15:48:06
Also in:
linux-arm-kernel
On 06/07/2017 01:38 AM, Antoine Tenart wrote:
This patch adds the xMDIO interface support in the mvmdio driver. This interface is used in Ethernet controllers on Marvell 370, 7k and 8k (as of now). The xSMI interface supported by this driver complies with the IEEE 802.3 clause 45 (while the SMI interface complies with the clause 22). The xSMI interface is used by 10GbE devices. Signed-off-by: Antoine Tenart <redacted> ---
+ if (of_device_is_compatible(np, "marvell,orion-mdio")) {
+ ops->is_done = smi_is_done;
+ ops->is_read_valid = smi_is_read_valid;
+ ops->start_read = smi_start_read_op;
+ ops->read = smi_read_op;
+ ops->write = smi_write_op;
+
+ dev->poll_interval_min = MVMDIO_SMI_POLL_INTERVAL_MIN;
+ dev->poll_interval_max = MVMDIO_SMI_POLL_INTERVAL_MAX;
+ } else if (of_device_is_compatible(np, "marvell,xmdio")) {
+ ops->is_done = xsmi_is_done;
+ ops->is_read_valid = xsmi_is_read_valid;
+ ops->start_read = xsmi_start_read_op;
+ ops->read = xsmi_read_op;
+ ops->write = xsmi_write_op;
+
+ dev->poll_interval_min = MVMDIO_XSMI_POLL_INTERVAL_MIN;
+ dev->poll_interval_max = MVMDIO_XSMI_POLL_INTERVAL_MAX;
+ } else {
+ return -EINVAL;
+ }
Instead of doing this, you could have the ops structure declared e.g: a
static global variables in the driver and reference them from the
of_device_id .data field, something like:
static struct orion_mdio_ops mdio_ops = {
...
};
static struct orion_mdio_data mdio_data = {
.ops = &mdio_ops,
.poll_intervall_min = ...,
.poll_interfave_max = ...,
};
static struct orion_mdio_ops xmdio_ops = {
...
};
static strcut orion_mdio_data xmdio_ data = {
};
and then reference those using of_id->data in the probe function
quoted hunk ↗ jump to hunk
+ + dev->ops = ops; + return 0; +} + static int orion_mdio_probe(struct platform_device *pdev) { struct resource *r; struct mii_bus *bus; struct orion_mdio_dev *dev; - struct orion_mdio_ops *ops; int i, ret; r = platform_get_resource(pdev, IORESOURCE_MEM, 0);@@ -278,18 +367,9 @@ static int orion_mdio_probe(struct platform_device *pdev) mutex_init(&dev->lock); - ops = devm_kzalloc(&pdev->dev, sizeof(*ops), GFP_KERNEL); - if (!ops) - return -ENOMEM; - - dev->poll_interval_min = MVMDIO_SMI_POLL_INTERVAL_MIN; - dev->poll_interval_max = MVMDIO_SMI_POLL_INTERVAL_MAX; - ops->is_done = orion_mdio_smi_is_done; - ops->is_read_valid = orion_mdio_smi_is_read_valid; - ops->start_read = orion_mdio_start_read_op; - ops->read = orion_mdio_read_op; - ops->write = orion_mdio_write_op; - dev->ops = ops; + ret = orion_mdio_populate_ops(pdev, dev); + if (ret) + return ret; if (pdev->dev.of_node) ret = of_mdiobus_register(bus, pdev->dev.of_node);@@ -340,6 +420,7 @@ static int orion_mdio_remove(struct platform_device *pdev) static const struct of_device_id orion_mdio_match[] = { { .compatible = "marvell,orion-mdio" },
and do .data = &mdio_data
+ { .compatible = "marvell,xmdio" },and .data = &xmdio_data
{ }
};
MODULE_DEVICE_TABLE(of, orion_mdio_match);-- Florian