Commit f6bb3e9d authored by Serge Semin's avatar Serge Semin Committed by David S. Miller

net: pcs: xpcs: Add Synopsys DW xPCS platform device driver

Synopsys DesignWare XPCS IP-core can be synthesized with the device CSRs
being accessible over the MCI or APB3 interface instead of the MDIO bus
(see the CSR_INTERFACE HDL parameter). Thus all the PCS registers can be
just memory mapped and be a subject of the standard MMIO operations of
course taking into account the peculiarities of the Clause C45 CSRs
mapping. From that perspective the DW XPCS devices would look as just
normal platform devices for the kernel.

On the other hand in order to have the DW XPCS devices handled by the
pcs-xpcs.c driver they need to be registered in the framework of the
MDIO-subsystem. So the suggested change is about providing a DW XPCS
platform device driver registering a virtual MDIO-bus with a single
MDIO-device representing the DW XPCS device.

DW XPCS platform device is supposed to be described by the respective
compatible string "snps,dw-xpcs" (or with the PMA-specific compatible
string), CSRs memory space and optional peripheral bus and reference clock
sources. Depending on the INDIRECT_ACCESS IP-core synthesize parameter the
memory-mapped reg-space can be represented as either directly or
indirectly mapped Clause 45 space. In the former case the particular
address is determined based on the MMD device and the registers offset (5
+ 16 bits all together) within the device reg-space. In the later case
there is only 8 lower address bits are utilized for the registers mapping
(255 CSRs). The upper bits are supposed to be written into the respective
viewport CSR in order to select the respective MMD sub-page.

Note, only the peripheral bus clock source is requested in the platform
device probe procedure. The core and pad clocks handling has been
implemented in the framework of the xpcs_create() method intentionally
since the clocks-related setups are supposed to be performed later, during
the DW XPCS main configuration procedures. (For instance they will be
required for the DW Gen5 10G PMA configuration.)
Signed-off-by: default avatarSerge Semin <fancer.lancer@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 664690eb
......@@ -6,11 +6,11 @@
menu "PCS device drivers"
config PCS_XPCS
tristate
tristate "Synopsys DesignWare Ethernet XPCS"
select PHYLINK
help
This module provides helper functions for Synopsys DesignWare XPCS
controllers.
This module provides a driver and helper functions for Synopsys
DesignWare XPCS controllers.
config PCS_LYNX
tristate
......
# SPDX-License-Identifier: GPL-2.0
# Makefile for Linux PCS drivers
pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-nxp.o pcs-xpcs-wx.o
pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-plat.o \
pcs-xpcs-nxp.o pcs-xpcs-wx.o
obj-$(CONFIG_PCS_XPCS) += pcs_xpcs.o
obj-$(CONFIG_PCS_LYNX) += pcs-lynx.o
......
This diff is collapsed.
......@@ -6,6 +6,7 @@
* Author: Jose Abreu <Jose.Abreu@synopsys.com>
*/
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/pcs/pcs-xpcs.h>
#include <linux/mdio.h>
......@@ -1244,7 +1245,9 @@ static int xpcs_get_id(struct dw_xpcs *xpcs)
id |= ret;
}
xpcs->info.pcs = id;
/* Set the PCS ID if it hasn't been pre-initialized */
if (xpcs->info.pcs == DW_XPCS_ID_NATIVE)
xpcs->info.pcs = id;
/* Find out PMA/PMD ID from MMD 1 device ID registers */
ret = xpcs_read(xpcs, MDIO_MMD_PMAPMD, MDIO_DEVID1);
......@@ -1263,7 +1266,9 @@ static int xpcs_get_id(struct dw_xpcs *xpcs)
ret = (ret >> 10) & 0x3F;
id |= ret << 16;
xpcs->info.pma = id;
/* Set the PMA ID if it hasn't been pre-initialized */
if (xpcs->info.pma == DW_XPCS_PMA_ID_NATIVE)
xpcs->info.pma = id;
return 0;
}
......@@ -1387,10 +1392,49 @@ static void xpcs_free_data(struct dw_xpcs *xpcs)
kfree(xpcs);
}
static int xpcs_init_clks(struct dw_xpcs *xpcs)
{
static const char *ids[DW_XPCS_NUM_CLKS] = {
[DW_XPCS_CORE_CLK] = "core",
[DW_XPCS_PAD_CLK] = "pad",
};
struct device *dev = &xpcs->mdiodev->dev;
int ret, i;
for (i = 0; i < DW_XPCS_NUM_CLKS; ++i)
xpcs->clks[i].id = ids[i];
ret = clk_bulk_get_optional(dev, DW_XPCS_NUM_CLKS, xpcs->clks);
if (ret)
return dev_err_probe(dev, ret, "Failed to get clocks\n");
ret = clk_bulk_prepare_enable(DW_XPCS_NUM_CLKS, xpcs->clks);
if (ret)
return dev_err_probe(dev, ret, "Failed to enable clocks\n");
return 0;
}
static void xpcs_clear_clks(struct dw_xpcs *xpcs)
{
clk_bulk_disable_unprepare(DW_XPCS_NUM_CLKS, xpcs->clks);
clk_bulk_put(DW_XPCS_NUM_CLKS, xpcs->clks);
}
static int xpcs_init_id(struct dw_xpcs *xpcs)
{
const struct dw_xpcs_info *info;
int i, ret;
info = dev_get_platdata(&xpcs->mdiodev->dev);
if (!info) {
xpcs->info.pcs = DW_XPCS_ID_NATIVE;
xpcs->info.pma = DW_XPCS_PMA_ID_NATIVE;
} else {
xpcs->info = *info;
}
ret = xpcs_get_id(xpcs);
if (ret < 0)
return ret;
......@@ -1438,17 +1482,24 @@ static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev,
if (IS_ERR(xpcs))
return xpcs;
ret = xpcs_init_clks(xpcs);
if (ret)
goto out_free_data;
ret = xpcs_init_id(xpcs);
if (ret)
goto out;
goto out_clear_clks;
ret = xpcs_init_iface(xpcs, interface);
if (ret)
goto out;
goto out_clear_clks;
return xpcs;
out:
out_clear_clks:
xpcs_clear_clks(xpcs);
out_free_data:
xpcs_free_data(xpcs);
return ERR_PTR(ret);
......@@ -1483,6 +1534,8 @@ void xpcs_destroy(struct dw_xpcs *xpcs)
if (!xpcs)
return;
xpcs_clear_clks(xpcs);
xpcs_free_data(xpcs);
}
EXPORT_SYMBOL_GPL(xpcs_destroy);
......
......@@ -6,6 +6,9 @@
* Author: Jose Abreu <Jose.Abreu@synopsys.com>
*/
#include <linux/bits.h>
#include <linux/pcs/pcs-xpcs.h>
/* Vendor regs access */
#define DW_VENDOR BIT(15)
......@@ -117,6 +120,9 @@
/* VR MII EEE Control 1 defines */
#define DW_VR_MII_EEE_TRN_LPI BIT(0) /* Transparent Mode Enable */
#define DW_XPCS_INFO_DECLARE(_name, _pcs, _pma) \
static const struct dw_xpcs_info _name = { .pcs = _pcs, .pma = _pma }
int xpcs_read(struct dw_xpcs *xpcs, int dev, u32 reg);
int xpcs_write(struct dw_xpcs *xpcs, int dev, u32 reg, u16 val);
int xpcs_read_vpcs(struct dw_xpcs *xpcs, int reg);
......
......@@ -7,6 +7,8 @@
#ifndef __LINUX_PCS_XPCS_H
#define __LINUX_PCS_XPCS_H
#include <linux/clk.h>
#include <linux/mdio.h>
#include <linux/phy.h>
#include <linux/phylink.h>
#include <linux/types.h>
......@@ -21,6 +23,7 @@
struct dw_xpcs_desc;
enum dw_xpcs_pcs_id {
DW_XPCS_ID_NATIVE = 0,
NXP_SJA1105_XPCS_ID = 0x00000010,
NXP_SJA1110_XPCS_ID = 0x00000020,
DW_XPCS_ID = 0x7996ced0,
......@@ -28,6 +31,14 @@ enum dw_xpcs_pcs_id {
};
enum dw_xpcs_pma_id {
DW_XPCS_PMA_ID_NATIVE = 0,
DW_XPCS_PMA_GEN1_3G_ID,
DW_XPCS_PMA_GEN2_3G_ID,
DW_XPCS_PMA_GEN2_6G_ID,
DW_XPCS_PMA_GEN4_3G_ID,
DW_XPCS_PMA_GEN4_6G_ID,
DW_XPCS_PMA_GEN5_10G_ID,
DW_XPCS_PMA_GEN5_12G_ID,
WX_TXGBE_XPCS_PMA_10G_ID = 0x0018fc80,
};
......@@ -36,10 +47,17 @@ struct dw_xpcs_info {
u32 pma;
};
enum dw_xpcs_clock {
DW_XPCS_CORE_CLK,
DW_XPCS_PAD_CLK,
DW_XPCS_NUM_CLKS,
};
struct dw_xpcs {
struct dw_xpcs_info info;
const struct dw_xpcs_desc *desc;
struct mdio_device *mdiodev;
struct clk_bulk_data clks[DW_XPCS_NUM_CLKS];
struct phylink_pcs pcs;
phy_interface_t interface;
};
......
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