This patch makes stmmac driver support SBSA compatible Phytium
SoC's on-chip RGMII.
Signed-off-by: wangzhimin <wangzhimin1179@phytium.com.cn>
(cherry picked from commit 4611897533
)
Signed-off-by: Alex Shi <alexsshi@tencent.com>
This commit is contained in:
parent
43dd0e35f4
commit
b4e38c43b9
|
@ -9,6 +9,7 @@
|
|||
* warranty of any kind, whether express or implied.
|
||||
*/
|
||||
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
@ -32,6 +33,12 @@ static int dwmac_generic_probe(struct platform_device *pdev)
|
|||
dev_err(&pdev->dev, "dt configuration failed\n");
|
||||
return PTR_ERR(plat_dat);
|
||||
}
|
||||
} else if (has_acpi_companion(&pdev->dev)) {
|
||||
plat_dat = stmmac_probe_config_acpi(pdev, &stmmac_res.mac);
|
||||
if (!plat_dat) {
|
||||
dev_err(&pdev->dev, "acpi configuration failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
} else {
|
||||
plat_dat = dev_get_platdata(&pdev->dev);
|
||||
if (!plat_dat) {
|
||||
|
@ -84,6 +91,17 @@ static const struct of_device_id dwmac_generic_match[] = {
|
|||
};
|
||||
MODULE_DEVICE_TABLE(of, dwmac_generic_match);
|
||||
|
||||
#ifdef CONFIG_ACPI
|
||||
static const struct acpi_device_id dwmac_acpi_ids[] = {
|
||||
{ .id = "PHYT0004" },
|
||||
{},
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(acpi, dwmac_acpi_ids);
|
||||
#else
|
||||
#define dwmac_acpi_ids NULL
|
||||
#endif
|
||||
|
||||
static struct platform_driver dwmac_generic_driver = {
|
||||
.probe = dwmac_generic_probe,
|
||||
.remove = stmmac_pltfr_remove,
|
||||
|
@ -91,6 +109,7 @@ static struct platform_driver dwmac_generic_driver = {
|
|||
.name = STMMAC_RESOURCE_NAME,
|
||||
.pm = &stmmac_pltfr_pm_ops,
|
||||
.of_match_table = of_match_ptr(dwmac_generic_match),
|
||||
.acpi_match_table = ACPI_PTR(dwmac_acpi_ids),
|
||||
},
|
||||
};
|
||||
module_platform_driver(dwmac_generic_driver);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
https://bugzilla.stlinux.com/
|
||||
*******************************************************************************/
|
||||
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/interrupt.h>
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
|
||||
*******************************************************************************/
|
||||
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/clk-provider.h>
|
||||
#include <linux/clkdev.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/io.h>
|
||||
|
@ -642,6 +645,242 @@ void stmmac_remove_config_dt(struct platform_device *pdev,
|
|||
EXPORT_SYMBOL_GPL(stmmac_probe_config_dt);
|
||||
EXPORT_SYMBOL_GPL(stmmac_remove_config_dt);
|
||||
|
||||
#ifdef CONFIG_ACPI
|
||||
/* Parse ACPI _DSD to setup AXI register */
|
||||
static struct stmmac_axi *stmmac_axi_setup_acpi(struct platform_device *pdev)
|
||||
{
|
||||
struct fwnode_handle *np = dev_fwnode(&pdev->dev);
|
||||
struct stmmac_axi *axi;
|
||||
|
||||
axi = devm_kzalloc(&pdev->dev, sizeof(*axi), GFP_KERNEL);
|
||||
if (!axi)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
axi->axi_lpi_en = fwnode_property_read_bool(np, "snps,lpi_en");
|
||||
axi->axi_xit_frm = fwnode_property_read_bool(np, "snps,xit_frm");
|
||||
axi->axi_kbbe = fwnode_property_read_bool(np, "snps,axi_kbbe");
|
||||
axi->axi_fb = fwnode_property_read_bool(np, "snps,axi_fb");
|
||||
axi->axi_mb = fwnode_property_read_bool(np, "snps,axi_mb");
|
||||
axi->axi_rb = fwnode_property_read_bool(np, "snps,axi_rb");
|
||||
|
||||
if (fwnode_property_read_u32(np, "snps,wr_osr_lmt", &axi->axi_wr_osr_lmt))
|
||||
axi->axi_wr_osr_lmt = 1;
|
||||
if (fwnode_property_read_u32(np, "snps,rd_osr_lmt", &axi->axi_rd_osr_lmt))
|
||||
axi->axi_rd_osr_lmt = 1;
|
||||
fwnode_property_read_u32_array(np, "snps,blen", axi->axi_blen, AXI_BLEN);
|
||||
|
||||
return axi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse ACPI _DSD parameters for multiple queues configuration
|
||||
*/
|
||||
static void stmmac_mtl_setup_acpi(struct platform_device *pdev,
|
||||
struct plat_stmmacenet_data *plat)
|
||||
{
|
||||
plat->rx_queues_to_use = 1;
|
||||
plat->tx_queues_to_use = 1;
|
||||
|
||||
/**
|
||||
* First Queue must always be in DCB mode. As MTL_QUEUE_DCB=1 we need
|
||||
* to always set this, otherwise Queue will be classified as AVB
|
||||
* (because MTL_QUEUE_AVB = 0).
|
||||
*/
|
||||
plat->rx_queues_cfg[0].mode_to_use = MTL_QUEUE_DCB;
|
||||
plat->tx_queues_cfg[0].mode_to_use = MTL_QUEUE_DCB;
|
||||
|
||||
plat->rx_queues_cfg[0].use_prio = true;
|
||||
|
||||
plat->rx_queues_cfg[0].pkt_route = 0x0;
|
||||
|
||||
plat->rx_sched_algorithm = MTL_RX_ALGORITHM_SP;
|
||||
plat->tx_sched_algorithm = MTL_TX_ALGORITHM_SP;
|
||||
|
||||
plat->tx_queues_cfg[0].use_prio = true;
|
||||
}
|
||||
|
||||
static int stmmac_acpi_phy(struct plat_stmmacenet_data *plat,
|
||||
struct fwnode_handle *np, struct device *dev)
|
||||
{
|
||||
plat->mdio_bus_data = devm_kzalloc(dev,
|
||||
sizeof(struct stmmac_mdio_bus_data),
|
||||
GFP_KERNEL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fw_get_phy_mode(struct fwnode_handle *np)
|
||||
{
|
||||
const char *pm;
|
||||
int err, i;
|
||||
|
||||
err = fwnode_property_read_string(np, "phy-mode", &pm);
|
||||
if (err < 0)
|
||||
err = fwnode_property_read_string(np, "phy-connection-mode", &pm);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++) {
|
||||
if (!strcasecmp(pm, phy_modes(i)))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
int stmmac_acpi_clock_setup(struct plat_stmmacenet_data *plat,
|
||||
struct platform_device *pdev)
|
||||
{
|
||||
struct fwnode_handle *np = dev_fwnode(&pdev->dev);
|
||||
struct device *dev = &pdev->dev;
|
||||
u64 clk_freq = 0;
|
||||
int err;
|
||||
|
||||
err = fwnode_property_read_u64(np, "clock-frequency", &clk_freq);
|
||||
if (err < 0)
|
||||
clk_freq = 125000000; /* default to 125MHz */
|
||||
|
||||
plat->stmmac_clk = clk_register_fixed_rate(dev, dev_name(dev),
|
||||
NULL, 0, clk_freq);
|
||||
if (IS_ERR(plat->stmmac_clk)) {
|
||||
dev_warn(&pdev->dev, "Fail to register CSR clock\n");
|
||||
plat->stmmac_clk = NULL;
|
||||
}
|
||||
clk_prepare_enable(plat->stmmac_clk);
|
||||
|
||||
plat->pclk = devm_clk_get(dev, "pclk");
|
||||
if (IS_ERR(plat->pclk))
|
||||
plat->pclk = NULL;
|
||||
clk_prepare_enable(plat->pclk);
|
||||
|
||||
plat->clk_ptp_ref = devm_clk_get(dev, "ptp_ref");
|
||||
if (IS_ERR(plat->clk_ptp_ref)) {
|
||||
plat->clk_ptp_rate = clk_get_rate(plat->stmmac_clk);
|
||||
plat->clk_ptp_ref = NULL;
|
||||
}
|
||||
|
||||
plat->stmmac_rst = devm_reset_control_get(dev, STMMAC_RESOURCE_NAME);
|
||||
if (IS_ERR(plat->stmmac_rst)) {
|
||||
dev_info(dev, "no reset control found\n");
|
||||
plat->stmmac_rst = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse ACPI driver parameters
|
||||
*/
|
||||
struct plat_stmmacenet_data *
|
||||
stmmac_probe_config_acpi(struct platform_device *pdev, const char **mac)
|
||||
{
|
||||
struct fwnode_handle *np;
|
||||
struct plat_stmmacenet_data *plat;
|
||||
struct stmmac_dma_cfg *dma_cfg;
|
||||
|
||||
plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
|
||||
if (!plat)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
np = dev_fwnode(&pdev->dev);
|
||||
|
||||
plat->interface = fw_get_phy_mode(np);
|
||||
|
||||
/* Get max speed of operation from device tree */
|
||||
if (fwnode_property_read_u32(np, "max-speed", &plat->max_speed))
|
||||
plat->max_speed = -1;
|
||||
|
||||
if (fwnode_property_read_u32(np, "bus_id", &plat->bus_id))
|
||||
plat->bus_id = 2;
|
||||
|
||||
/* Default to PHY auto-detection */
|
||||
plat->phy_addr = -1;
|
||||
|
||||
/* "snps,phy-addr" is not a standard property. Mark it as deprecated
|
||||
* and warn of its use. Remove this when PHY node support is added.
|
||||
*/
|
||||
if (fwnode_property_read_u32(np, "snps,phy-addr", &plat->phy_addr) == 0)
|
||||
dev_warn(&pdev->dev, "snps,phy-addr property is deprecated\n");
|
||||
|
||||
if (stmmac_acpi_phy(plat, np, &pdev->dev))
|
||||
return ERR_PTR(-ENODEV);
|
||||
|
||||
fwnode_property_read_u32(np, "tx-fifo-depth", &plat->tx_fifo_size);
|
||||
fwnode_property_read_u32(np, "rx-fifo-depth", &plat->rx_fifo_size);
|
||||
if (plat->tx_fifo_size == 0)
|
||||
plat->tx_fifo_size = 0x10000;
|
||||
if (plat->rx_fifo_size == 0)
|
||||
plat->rx_fifo_size = 0x10000;
|
||||
|
||||
plat->force_sf_dma_mode =
|
||||
fwnode_property_read_bool(np, "snps,force_sf_dma_mode");
|
||||
plat->en_tx_lpi_clockgating =
|
||||
fwnode_property_read_bool(np, "snps,en-tx-lpi-clockgating");
|
||||
|
||||
/* Set the maxmtu to a default of JUMBO_LEN in case the
|
||||
* parameter is not present.
|
||||
*/
|
||||
plat->maxmtu = JUMBO_LEN;
|
||||
|
||||
/* Set default value for multicast hash bins */
|
||||
plat->multicast_filter_bins = HASH_TABLE_SIZE;
|
||||
|
||||
/* Set default value for unicast filter entries */
|
||||
plat->unicast_filter_entries = 1;
|
||||
|
||||
/* Only to "snps,dwmac" */
|
||||
fwnode_property_read_u32(np, "max-frame-size", &plat->maxmtu);
|
||||
fwnode_property_read_u32(np, "snps,multicast-filter-bins",
|
||||
&plat->multicast_filter_bins);
|
||||
fwnode_property_read_u32(np, "snps,perfect-filter-entries",
|
||||
&plat->unicast_filter_entries);
|
||||
plat->unicast_filter_entries =
|
||||
dwmac1000_validate_ucast_entries(&pdev->dev,plat->unicast_filter_entries);
|
||||
plat->multicast_filter_bins =
|
||||
dwmac1000_validate_mcast_bins(&pdev->dev,plat->multicast_filter_bins);
|
||||
plat->has_gmac = 1;
|
||||
plat->pmt = 1;
|
||||
|
||||
dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*dma_cfg), GFP_KERNEL);
|
||||
if (!dma_cfg)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
plat->dma_cfg = dma_cfg;
|
||||
|
||||
fwnode_property_read_u32(np, "snps,pbl", &dma_cfg->pbl);
|
||||
if (!dma_cfg->pbl)
|
||||
dma_cfg->pbl = DEFAULT_DMA_PBL;
|
||||
|
||||
fwnode_property_read_u32(np, "snps,txpbl", &dma_cfg->txpbl);
|
||||
fwnode_property_read_u32(np, "snps,rxpbl", &dma_cfg->rxpbl);
|
||||
dma_cfg->pblx8 = !fwnode_property_read_bool(np, "snps,no-pbl-x8");
|
||||
|
||||
dma_cfg->aal = fwnode_property_read_bool(np, "snps,aal");
|
||||
dma_cfg->fixed_burst = fwnode_property_read_bool(np, "snps,fixed-burst");
|
||||
dma_cfg->mixed_burst = fwnode_property_read_bool(np, "snps,mixed-burst");
|
||||
|
||||
plat->force_thresh_dma_mode = fwnode_property_read_bool(np, "snps,force_thresh_dma_mode");
|
||||
if (plat->force_thresh_dma_mode)
|
||||
plat->force_sf_dma_mode = 0;
|
||||
|
||||
fwnode_property_read_u32(np, "snps,ps-speed", &plat->mac_port_sel_speed);
|
||||
|
||||
plat->axi = stmmac_axi_setup_acpi(pdev);
|
||||
|
||||
stmmac_mtl_setup_acpi(pdev, plat);
|
||||
|
||||
stmmac_acpi_clock_setup(plat, pdev);
|
||||
|
||||
return plat;
|
||||
}
|
||||
#else
|
||||
struct plat_stmmacenet_data *
|
||||
stmmac_probe_config_acpi(struct platform_device *pdev, const char **mac)
|
||||
{
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
#endif /* CONFIG_ACPI */
|
||||
EXPORT_SYMBOL_GPL(stmmac_probe_config_acpi);
|
||||
|
||||
int stmmac_get_platform_resources(struct platform_device *pdev,
|
||||
struct stmmac_resources *stmmac_res)
|
||||
{
|
||||
|
@ -652,32 +891,41 @@ int stmmac_get_platform_resources(struct platform_device *pdev,
|
|||
/* Get IRQ information early to have an ability to ask for deferred
|
||||
* probe if needed before we went too far with resource allocation.
|
||||
*/
|
||||
stmmac_res->irq = platform_get_irq_byname(pdev, "macirq");
|
||||
if (stmmac_res->irq < 0)
|
||||
return stmmac_res->irq;
|
||||
|
||||
/* On some platforms e.g. SPEAr the wake up irq differs from the mac irq
|
||||
* The external wake up irq can be passed through the platform code
|
||||
* named as "eth_wake_irq"
|
||||
*
|
||||
* In case the wake up interrupt is not passed from the platform
|
||||
* so the driver will continue to use the mac irq (ndev->irq)
|
||||
*/
|
||||
stmmac_res->wol_irq =
|
||||
platform_get_irq_byname_optional(pdev, "eth_wake_irq");
|
||||
if (stmmac_res->wol_irq < 0) {
|
||||
if (stmmac_res->wol_irq == -EPROBE_DEFER)
|
||||
return -EPROBE_DEFER;
|
||||
dev_info(&pdev->dev, "IRQ eth_wake_irq not found\n");
|
||||
if (pdev->dev.of_node) {
|
||||
stmmac_res->irq = platform_get_irq_byname(pdev, "macirq");
|
||||
if (stmmac_res->irq < 0)
|
||||
return stmmac_res->irq;
|
||||
|
||||
/* On some platforms e.g. SPEAr the wake up irq differs from the mac irq
|
||||
* The external wake up irq can be passed through the platform code
|
||||
* named as "eth_wake_irq"
|
||||
*
|
||||
* In case the wake up interrupt is not passed from the platform
|
||||
* so the driver will continue to use the mac irq (ndev->irq)
|
||||
*/
|
||||
stmmac_res->wol_irq =
|
||||
platform_get_irq_byname_optional(pdev, "eth_wake_irq");
|
||||
if (stmmac_res->wol_irq < 0) {
|
||||
if (stmmac_res->wol_irq == -EPROBE_DEFER)
|
||||
return -EPROBE_DEFER;
|
||||
dev_info(&pdev->dev, "IRQ eth_wake_irq not found\n");
|
||||
stmmac_res->wol_irq = stmmac_res->irq;
|
||||
}
|
||||
|
||||
stmmac_res->lpi_irq =
|
||||
platform_get_irq_byname_optional(pdev, "eth_lpi");
|
||||
if (stmmac_res->lpi_irq < 0) {
|
||||
if (stmmac_res->lpi_irq == -EPROBE_DEFER)
|
||||
return -EPROBE_DEFER;
|
||||
dev_info(&pdev->dev, "IRQ eth_lpi not found\n");
|
||||
}
|
||||
} else if (has_acpi_companion(&pdev->dev)) {
|
||||
stmmac_res->irq = platform_get_irq(pdev, 0);
|
||||
if (stmmac_res->irq < 0)
|
||||
dev_err(&pdev->dev,
|
||||
"MAC IRQ configuration information not found\n");
|
||||
stmmac_res->wol_irq = stmmac_res->irq;
|
||||
}
|
||||
|
||||
stmmac_res->lpi_irq =
|
||||
platform_get_irq_byname_optional(pdev, "eth_lpi");
|
||||
if (stmmac_res->lpi_irq < 0) {
|
||||
if (stmmac_res->lpi_irq == -EPROBE_DEFER)
|
||||
return -EPROBE_DEFER;
|
||||
dev_info(&pdev->dev, "IRQ eth_lpi not found\n");
|
||||
stmmac_res->lpi_irq = -1;
|
||||
}
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
|
@ -703,6 +951,9 @@ int stmmac_pltfr_remove(struct platform_device *pdev)
|
|||
if (plat->exit)
|
||||
plat->exit(pdev, plat->bsp_priv);
|
||||
|
||||
if (has_acpi_companion(&pdev->dev))
|
||||
clk_unregister_fixed_rate(priv->plat->stmmac_clk);
|
||||
|
||||
stmmac_remove_config_dt(pdev, plat);
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
struct plat_stmmacenet_data *
|
||||
stmmac_probe_config_dt(struct platform_device *pdev, const char **mac);
|
||||
struct plat_stmmacenet_data *
|
||||
stmmac_probe_config_acpi(struct platform_device *pdev, const char **mac);
|
||||
void stmmac_remove_config_dt(struct platform_device *pdev,
|
||||
struct plat_stmmacenet_data *plat);
|
||||
|
||||
|
|
Loading…
Reference in New Issue