2019-05-27 06:55:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-11-18 08:47:01 +00:00
|
|
|
/*
|
2014-02-11 09:59:57 +00:00
|
|
|
* dwmac-sti.c - STMicroelectronics DWMAC Specific Glue layer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003-2014 STMicroelectronics (R&D) Limited
|
|
|
|
* Author: Srinivas Kandagatla <srinivas.kandagatla@st.com>
|
2014-10-14 06:12:56 +00:00
|
|
|
* Contributors: Giuseppe Cavallaro <peppe.cavallaro@st.com>
|
2014-02-11 09:59:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/stmmac.h>
|
|
|
|
#include <linux/phy.h>
|
|
|
|
#include <linux/mfd/syscon.h>
|
2015-05-14 10:11:04 +00:00
|
|
|
#include <linux/module.h>
|
2014-02-11 09:59:57 +00:00
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_net.h>
|
|
|
|
|
2014-11-07 14:46:42 +00:00
|
|
|
#include "stmmac_platform.h"
|
|
|
|
|
2014-10-14 06:12:56 +00:00
|
|
|
#define DWMAC_125MHZ 125000000
|
|
|
|
#define DWMAC_50MHZ 50000000
|
|
|
|
#define DWMAC_25MHZ 25000000
|
|
|
|
#define DWMAC_2_5MHZ 2500000
|
|
|
|
|
|
|
|
#define IS_PHY_IF_MODE_RGMII(iface) (iface == PHY_INTERFACE_MODE_RGMII || \
|
|
|
|
iface == PHY_INTERFACE_MODE_RGMII_ID || \
|
|
|
|
iface == PHY_INTERFACE_MODE_RGMII_RXID || \
|
|
|
|
iface == PHY_INTERFACE_MODE_RGMII_TXID)
|
|
|
|
|
|
|
|
#define IS_PHY_IF_MODE_GBIT(iface) (IS_PHY_IF_MODE_RGMII(iface) || \
|
|
|
|
iface == PHY_INTERFACE_MODE_GMII)
|
|
|
|
|
2023-04-16 19:55:23 +00:00
|
|
|
/* STiH4xx register definitions (STiH407/STiH410 families)
|
2014-11-18 08:47:01 +00:00
|
|
|
*
|
2014-02-11 09:59:57 +00:00
|
|
|
* Below table summarizes the clock requirement and clock sources for
|
|
|
|
* supported phy interface modes with link speeds.
|
|
|
|
* ________________________________________________
|
|
|
|
*| PHY_MODE | 1000 Mbit Link | 100 Mbit Link |
|
|
|
|
* ------------------------------------------------
|
|
|
|
*| MII | n/a | 25Mhz |
|
|
|
|
*| | | txclk |
|
|
|
|
* ------------------------------------------------
|
|
|
|
*| GMII | 125Mhz | 25Mhz |
|
|
|
|
*| | clk-125/txclk | txclk |
|
|
|
|
* ------------------------------------------------
|
|
|
|
*| RGMII | 125Mhz | 25Mhz |
|
|
|
|
*| | clk-125/txclk | clkgen |
|
2014-10-14 06:12:56 +00:00
|
|
|
*| | clkgen | |
|
2014-02-11 09:59:57 +00:00
|
|
|
* ------------------------------------------------
|
|
|
|
*| RMII | n/a | 25Mhz |
|
|
|
|
*| | |clkgen/phyclk-in |
|
|
|
|
* ------------------------------------------------
|
|
|
|
*
|
2014-10-14 06:12:56 +00:00
|
|
|
* Register Configuration
|
|
|
|
*-------------------------------
|
|
|
|
* src |BIT(8)| BIT(7)| BIT(6)|
|
|
|
|
*-------------------------------
|
|
|
|
* txclk | 0 | n/a | 1 |
|
|
|
|
*-------------------------------
|
|
|
|
* ck_125| 0 | n/a | 0 |
|
|
|
|
*-------------------------------
|
|
|
|
* phyclk| 1 | 0 | n/a |
|
|
|
|
*-------------------------------
|
|
|
|
* clkgen| 1 | 1 | n/a |
|
|
|
|
*-------------------------------
|
2014-02-11 09:59:57 +00:00
|
|
|
*/
|
|
|
|
|
2014-10-14 06:12:56 +00:00
|
|
|
#define STIH4XX_RETIME_SRC_MASK GENMASK(8, 6)
|
|
|
|
#define STIH4XX_ETH_SEL_TX_RETIME_CLK BIT(8)
|
|
|
|
#define STIH4XX_ETH_SEL_INTERNAL_NOTEXT_PHYCLK BIT(7)
|
|
|
|
#define STIH4XX_ETH_SEL_TXCLK_NOT_CLK125 BIT(6)
|
|
|
|
|
|
|
|
#define ENMII_MASK GENMASK(5, 5)
|
|
|
|
#define ENMII BIT(5)
|
|
|
|
#define EN_MASK GENMASK(1, 1)
|
|
|
|
#define EN BIT(1)
|
2014-02-11 09:59:57 +00:00
|
|
|
|
2014-11-18 08:47:01 +00:00
|
|
|
/*
|
2014-02-11 09:59:57 +00:00
|
|
|
* 3 bits [4:2]
|
|
|
|
* 000-GMII/MII
|
|
|
|
* 001-RGMII
|
|
|
|
* 010-SGMII
|
|
|
|
* 100-RMII
|
2014-11-18 08:47:01 +00:00
|
|
|
*/
|
2014-10-14 06:12:56 +00:00
|
|
|
#define MII_PHY_SEL_MASK GENMASK(4, 2)
|
|
|
|
#define ETH_PHY_SEL_RMII BIT(4)
|
|
|
|
#define ETH_PHY_SEL_SGMII BIT(3)
|
|
|
|
#define ETH_PHY_SEL_RGMII BIT(2)
|
|
|
|
#define ETH_PHY_SEL_GMII 0x0
|
|
|
|
#define ETH_PHY_SEL_MII 0x0
|
2014-02-11 09:59:57 +00:00
|
|
|
|
|
|
|
struct sti_dwmac {
|
net: of_get_phy_mode: Change API to solve int/unit warnings
Before this change of_get_phy_mode() returned an enum,
phy_interface_t. On error, -ENODEV etc, is returned. If the result of
the function is stored in a variable of type phy_interface_t, and the
compiler has decided to represent this as an unsigned int, comparision
with -ENODEV etc, is a signed vs unsigned comparision.
Fix this problem by changing the API. Make the function return an
error, or 0 on success, and pass a pointer, of type phy_interface_t,
where the phy mode should be stored.
v2:
Return with *interface set to PHY_INTERFACE_MODE_NA on error.
Add error checks to all users of of_get_phy_mode()
Fixup a few reverse christmas tree errors
Fixup a few slightly malformed reverse christmas trees
v3:
Fix 0-day reported errors.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-04 01:40:33 +00:00
|
|
|
phy_interface_t interface; /* MII interface */
|
2014-10-14 06:12:56 +00:00
|
|
|
bool ext_phyclk; /* Clock from external PHY */
|
|
|
|
u32 tx_retime_src; /* TXCLK Retiming*/
|
|
|
|
struct clk *clk; /* PHY clock */
|
2015-01-07 15:04:12 +00:00
|
|
|
u32 ctrl_reg; /* GMAC glue-logic control register */
|
2014-10-14 06:12:56 +00:00
|
|
|
int clk_sel_reg; /* GMAC ext clk selection register */
|
2014-02-11 09:59:57 +00:00
|
|
|
struct regmap *regmap;
|
2016-11-04 17:54:08 +00:00
|
|
|
bool gmac_en;
|
2014-10-14 06:12:56 +00:00
|
|
|
u32 speed;
|
2015-07-28 22:09:04 +00:00
|
|
|
void (*fix_retime_src)(void *priv, unsigned int speed);
|
2014-02-11 09:59:57 +00:00
|
|
|
};
|
|
|
|
|
2015-07-28 22:08:59 +00:00
|
|
|
struct sti_dwmac_of_data {
|
2015-07-28 22:09:04 +00:00
|
|
|
void (*fix_retime_src)(void *priv, unsigned int speed);
|
2015-07-28 22:08:59 +00:00
|
|
|
};
|
|
|
|
|
2014-02-11 09:59:57 +00:00
|
|
|
static u32 phy_intf_sels[] = {
|
|
|
|
[PHY_INTERFACE_MODE_MII] = ETH_PHY_SEL_MII,
|
|
|
|
[PHY_INTERFACE_MODE_GMII] = ETH_PHY_SEL_GMII,
|
|
|
|
[PHY_INTERFACE_MODE_RGMII] = ETH_PHY_SEL_RGMII,
|
|
|
|
[PHY_INTERFACE_MODE_RGMII_ID] = ETH_PHY_SEL_RGMII,
|
|
|
|
[PHY_INTERFACE_MODE_SGMII] = ETH_PHY_SEL_SGMII,
|
|
|
|
[PHY_INTERFACE_MODE_RMII] = ETH_PHY_SEL_RMII,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TX_RETIME_SRC_NA = 0,
|
|
|
|
TX_RETIME_SRC_TXCLK = 1,
|
|
|
|
TX_RETIME_SRC_CLK_125,
|
|
|
|
TX_RETIME_SRC_PHYCLK,
|
|
|
|
TX_RETIME_SRC_CLKGEN,
|
|
|
|
};
|
|
|
|
|
2014-10-14 06:12:56 +00:00
|
|
|
static u32 stih4xx_tx_retime_val[] = {
|
|
|
|
[TX_RETIME_SRC_TXCLK] = STIH4XX_ETH_SEL_TXCLK_NOT_CLK125,
|
2014-02-11 09:59:57 +00:00
|
|
|
[TX_RETIME_SRC_CLK_125] = 0x0,
|
2014-10-14 06:12:56 +00:00
|
|
|
[TX_RETIME_SRC_PHYCLK] = STIH4XX_ETH_SEL_TX_RETIME_CLK,
|
|
|
|
[TX_RETIME_SRC_CLKGEN] = STIH4XX_ETH_SEL_TX_RETIME_CLK
|
|
|
|
| STIH4XX_ETH_SEL_INTERNAL_NOTEXT_PHYCLK,
|
2014-02-11 09:59:57 +00:00
|
|
|
};
|
|
|
|
|
2014-10-14 06:12:56 +00:00
|
|
|
static void stih4xx_fix_retime_src(void *priv, u32 spd)
|
2014-02-11 09:59:57 +00:00
|
|
|
{
|
2014-10-14 06:12:56 +00:00
|
|
|
struct sti_dwmac *dwmac = priv;
|
|
|
|
u32 src = dwmac->tx_retime_src;
|
|
|
|
u32 reg = dwmac->ctrl_reg;
|
|
|
|
u32 freq = 0;
|
|
|
|
|
|
|
|
if (dwmac->interface == PHY_INTERFACE_MODE_MII) {
|
|
|
|
src = TX_RETIME_SRC_TXCLK;
|
|
|
|
} else if (dwmac->interface == PHY_INTERFACE_MODE_RMII) {
|
|
|
|
if (dwmac->ext_phyclk) {
|
|
|
|
src = TX_RETIME_SRC_PHYCLK;
|
|
|
|
} else {
|
2014-02-11 09:59:57 +00:00
|
|
|
src = TX_RETIME_SRC_CLKGEN;
|
2014-10-14 06:12:56 +00:00
|
|
|
freq = DWMAC_50MHZ;
|
2014-02-11 09:59:57 +00:00
|
|
|
}
|
2014-10-14 06:12:56 +00:00
|
|
|
} else if (IS_PHY_IF_MODE_RGMII(dwmac->interface)) {
|
|
|
|
/* On GiGa clk source can be either ext or from clkgen */
|
|
|
|
if (spd == SPEED_1000) {
|
|
|
|
freq = DWMAC_125MHZ;
|
|
|
|
} else {
|
|
|
|
/* Switch to clkgen for these speeds */
|
|
|
|
src = TX_RETIME_SRC_CLKGEN;
|
|
|
|
if (spd == SPEED_100)
|
|
|
|
freq = DWMAC_25MHZ;
|
|
|
|
else if (spd == SPEED_10)
|
|
|
|
freq = DWMAC_2_5MHZ;
|
|
|
|
}
|
|
|
|
}
|
2014-02-11 09:59:57 +00:00
|
|
|
|
2016-11-04 17:54:06 +00:00
|
|
|
if (src == TX_RETIME_SRC_CLKGEN && freq)
|
2014-10-14 06:12:56 +00:00
|
|
|
clk_set_rate(dwmac->clk, freq);
|
2014-02-11 09:59:57 +00:00
|
|
|
|
2014-10-14 06:12:56 +00:00
|
|
|
regmap_update_bits(dwmac->regmap, reg, STIH4XX_RETIME_SRC_MASK,
|
|
|
|
stih4xx_tx_retime_val[src]);
|
|
|
|
}
|
|
|
|
|
2016-11-04 17:54:10 +00:00
|
|
|
static int sti_dwmac_set_mode(struct sti_dwmac *dwmac)
|
2014-02-11 09:59:57 +00:00
|
|
|
{
|
2014-10-14 06:12:56 +00:00
|
|
|
struct regmap *regmap = dwmac->regmap;
|
|
|
|
int iface = dwmac->interface;
|
|
|
|
u32 reg = dwmac->ctrl_reg;
|
|
|
|
u32 val;
|
2014-02-11 09:59:57 +00:00
|
|
|
|
2016-11-04 17:54:08 +00:00
|
|
|
if (dwmac->gmac_en)
|
2014-10-14 06:12:56 +00:00
|
|
|
regmap_update_bits(regmap, reg, EN_MASK, EN);
|
|
|
|
|
|
|
|
regmap_update_bits(regmap, reg, MII_PHY_SEL_MASK, phy_intf_sels[iface]);
|
|
|
|
|
|
|
|
val = (iface == PHY_INTERFACE_MODE_REVMII) ? 0 : ENMII;
|
|
|
|
regmap_update_bits(regmap, reg, ENMII_MASK, val);
|
|
|
|
|
2016-11-04 17:54:10 +00:00
|
|
|
dwmac->fix_retime_src(dwmac, dwmac->speed);
|
2014-10-14 06:12:56 +00:00
|
|
|
|
|
|
|
return 0;
|
2014-02-11 09:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
|
|
|
|
struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct resource *res;
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct device_node *np = dev->of_node;
|
|
|
|
struct regmap *regmap;
|
|
|
|
int err;
|
|
|
|
|
2014-10-14 06:12:56 +00:00
|
|
|
/* clk selection from extra syscfg register */
|
|
|
|
dwmac->clk_sel_reg = -ENXIO;
|
|
|
|
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sti-clkconf");
|
|
|
|
if (res)
|
|
|
|
dwmac->clk_sel_reg = res->start;
|
2014-02-11 09:59:57 +00:00
|
|
|
|
|
|
|
regmap = syscon_regmap_lookup_by_phandle(np, "st,syscon");
|
|
|
|
if (IS_ERR(regmap))
|
|
|
|
return PTR_ERR(regmap);
|
|
|
|
|
2015-01-07 15:04:12 +00:00
|
|
|
err = of_property_read_u32_index(np, "st,syscon", 1, &dwmac->ctrl_reg);
|
|
|
|
if (err) {
|
|
|
|
dev_err(dev, "Can't get sysconfig ctrl offset (%d)\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
net: of_get_phy_mode: Change API to solve int/unit warnings
Before this change of_get_phy_mode() returned an enum,
phy_interface_t. On error, -ENODEV etc, is returned. If the result of
the function is stored in a variable of type phy_interface_t, and the
compiler has decided to represent this as an unsigned int, comparision
with -ENODEV etc, is a signed vs unsigned comparision.
Fix this problem by changing the API. Make the function return an
error, or 0 on success, and pass a pointer, of type phy_interface_t,
where the phy mode should be stored.
v2:
Return with *interface set to PHY_INTERFACE_MODE_NA on error.
Add error checks to all users of of_get_phy_mode()
Fixup a few reverse christmas tree errors
Fixup a few slightly malformed reverse christmas trees
v3:
Fix 0-day reported errors.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-04 01:40:33 +00:00
|
|
|
err = of_get_phy_mode(np, &dwmac->interface);
|
|
|
|
if (err && err != -ENODEV) {
|
|
|
|
dev_err(dev, "Can't get phy-mode\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-02-11 09:59:57 +00:00
|
|
|
dwmac->regmap = regmap;
|
2016-11-04 17:54:08 +00:00
|
|
|
dwmac->gmac_en = of_property_read_bool(np, "st,gmac_en");
|
2014-02-11 09:59:57 +00:00
|
|
|
dwmac->ext_phyclk = of_property_read_bool(np, "st,ext-phyclk");
|
2014-10-14 06:12:56 +00:00
|
|
|
dwmac->tx_retime_src = TX_RETIME_SRC_NA;
|
|
|
|
dwmac->speed = SPEED_100;
|
2014-02-11 09:59:57 +00:00
|
|
|
|
|
|
|
if (IS_PHY_IF_MODE_GBIT(dwmac->interface)) {
|
|
|
|
const char *rs;
|
|
|
|
|
2015-11-26 07:35:43 +00:00
|
|
|
dwmac->tx_retime_src = TX_RETIME_SRC_CLKGEN;
|
|
|
|
|
2014-02-11 09:59:57 +00:00
|
|
|
err = of_property_read_string(np, "st,tx-retime-src", &rs);
|
2014-12-15 11:25:51 +00:00
|
|
|
if (err < 0) {
|
2014-10-14 06:12:56 +00:00
|
|
|
dev_warn(dev, "Use internal clock source\n");
|
2015-11-26 07:35:43 +00:00
|
|
|
} else {
|
|
|
|
if (!strcasecmp(rs, "clk_125"))
|
|
|
|
dwmac->tx_retime_src = TX_RETIME_SRC_CLK_125;
|
|
|
|
else if (!strcasecmp(rs, "txclk"))
|
|
|
|
dwmac->tx_retime_src = TX_RETIME_SRC_TXCLK;
|
2014-12-15 11:25:51 +00:00
|
|
|
}
|
2014-10-14 06:12:56 +00:00
|
|
|
dwmac->speed = SPEED_1000;
|
2014-02-11 09:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dwmac->clk = devm_clk_get(dev, "sti-ethclk");
|
2014-10-14 06:12:56 +00:00
|
|
|
if (IS_ERR(dwmac->clk)) {
|
|
|
|
dev_warn(dev, "No phy clock provided...\n");
|
2014-02-11 09:59:57 +00:00
|
|
|
dwmac->clk = NULL;
|
2014-10-14 06:12:56 +00:00
|
|
|
}
|
2014-02-11 09:59:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-28 22:08:55 +00:00
|
|
|
static int sti_dwmac_probe(struct platform_device *pdev)
|
2014-02-11 09:59:57 +00:00
|
|
|
{
|
2015-07-28 22:08:55 +00:00
|
|
|
struct plat_stmmacenet_data *plat_dat;
|
2015-07-28 22:08:59 +00:00
|
|
|
const struct sti_dwmac_of_data *data;
|
2015-07-28 22:08:55 +00:00
|
|
|
struct stmmac_resources stmmac_res;
|
2014-02-11 09:59:57 +00:00
|
|
|
struct sti_dwmac *dwmac;
|
|
|
|
int ret;
|
|
|
|
|
2015-07-28 22:08:58 +00:00
|
|
|
data = of_device_get_match_data(&pdev->dev);
|
|
|
|
if (!data) {
|
|
|
|
dev_err(&pdev->dev, "No OF match data provided\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-07-28 22:08:55 +00:00
|
|
|
ret = stmmac_get_platform_resources(pdev, &stmmac_res);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
of: net: pass the dst buffer to of_get_mac_address()
of_get_mac_address() returns a "const void*" pointer to a MAC address.
Lately, support to fetch the MAC address by an NVMEM provider was added.
But this will only work with platform devices. It will not work with
PCI devices (e.g. of an integrated root complex) and esp. not with DSA
ports.
There is an of_* variant of the nvmem binding which works without
devices. The returned data of a nvmem_cell_read() has to be freed after
use. On the other hand the return of_get_mac_address() points to some
static data without a lifetime. The trick for now, was to allocate a
device resource managed buffer which is then returned. This will only
work if we have an actual device.
Change it, so that the caller of of_get_mac_address() has to supply a
buffer where the MAC address is written to. Unfortunately, this will
touch all drivers which use the of_get_mac_address().
Usually the code looks like:
const char *addr;
addr = of_get_mac_address(np);
if (!IS_ERR(addr))
ether_addr_copy(ndev->dev_addr, addr);
This can then be simply rewritten as:
of_get_mac_address(np, ndev->dev_addr);
Sometimes is_valid_ether_addr() is used to test the MAC address.
of_get_mac_address() already makes sure, it just returns a valid MAC
address. Thus we can just test its return code. But we have to be
careful if there are still other sources for the MAC address before the
of_get_mac_address(). In this case we have to keep the
is_valid_ether_addr() call.
The following coccinelle patch was used to convert common cases to the
new style. Afterwards, I've manually gone over the drivers and fixed the
return code variable: either used a new one or if one was already
available use that. Mansour Moufid, thanks for that coccinelle patch!
<spml>
@a@
identifier x;
expression y, z;
@@
- x = of_get_mac_address(y);
+ x = of_get_mac_address(y, z);
<...
- ether_addr_copy(z, x);
...>
@@
identifier a.x;
@@
- if (<+... x ...+>) {}
@@
identifier a.x;
@@
if (<+... x ...+>) {
...
}
- else {}
@@
identifier a.x;
expression e;
@@
- if (<+... x ...+>@e)
- {}
- else
+ if (!(e))
{...}
@@
expression x, y, z;
@@
- x = of_get_mac_address(y, z);
+ of_get_mac_address(y, z);
... when != x
</spml>
All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
compile-time tested.
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-12 17:47:17 +00:00
|
|
|
plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
|
2015-07-28 22:08:55 +00:00
|
|
|
if (IS_ERR(plat_dat))
|
|
|
|
return PTR_ERR(plat_dat);
|
|
|
|
|
2014-02-11 09:59:57 +00:00
|
|
|
dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
|
2016-11-30 14:29:55 +00:00
|
|
|
if (!dwmac) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_remove_config_dt;
|
|
|
|
}
|
2014-02-11 09:59:57 +00:00
|
|
|
|
|
|
|
ret = sti_dwmac_parse_data(dwmac, pdev);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Unable to parse OF data\n");
|
2016-11-30 14:29:55 +00:00
|
|
|
goto err_remove_config_dt;
|
2014-02-11 09:59:57 +00:00
|
|
|
}
|
|
|
|
|
2015-07-28 22:09:04 +00:00
|
|
|
dwmac->fix_retime_src = data->fix_retime_src;
|
|
|
|
|
2015-07-28 22:08:55 +00:00
|
|
|
plat_dat->bsp_priv = dwmac;
|
2015-07-28 22:09:04 +00:00
|
|
|
plat_dat->fix_mac_speed = data->fix_retime_src;
|
2015-07-28 22:08:55 +00:00
|
|
|
|
2016-11-04 17:54:09 +00:00
|
|
|
ret = clk_prepare_enable(dwmac->clk);
|
2015-07-28 22:08:55 +00:00
|
|
|
if (ret)
|
2016-11-30 14:29:55 +00:00
|
|
|
goto err_remove_config_dt;
|
2015-07-28 22:08:55 +00:00
|
|
|
|
2016-11-04 17:54:10 +00:00
|
|
|
ret = sti_dwmac_set_mode(dwmac);
|
2016-11-04 17:54:09 +00:00
|
|
|
if (ret)
|
|
|
|
goto disable_clk;
|
|
|
|
|
|
|
|
ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
|
|
|
|
if (ret)
|
|
|
|
goto disable_clk;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
disable_clk:
|
|
|
|
clk_disable_unprepare(dwmac->clk);
|
2016-11-30 14:29:55 +00:00
|
|
|
err_remove_config_dt:
|
|
|
|
stmmac_remove_config_dt(pdev, plat_dat);
|
2016-11-30 14:29:50 +00:00
|
|
|
|
2016-11-04 17:54:09 +00:00
|
|
|
return ret;
|
2014-02-11 09:59:57 +00:00
|
|
|
}
|
|
|
|
|
2023-05-08 14:26:34 +00:00
|
|
|
static void sti_dwmac_remove(struct platform_device *pdev)
|
2016-11-04 17:54:07 +00:00
|
|
|
{
|
|
|
|
struct sti_dwmac *dwmac = get_stmmac_bsp_priv(&pdev->dev);
|
2023-02-11 11:24:30 +00:00
|
|
|
|
|
|
|
stmmac_dvr_remove(&pdev->dev);
|
2016-11-04 17:54:07 +00:00
|
|
|
|
|
|
|
clk_disable_unprepare(dwmac->clk);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int sti_dwmac_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct sti_dwmac *dwmac = get_stmmac_bsp_priv(dev);
|
|
|
|
int ret = stmmac_suspend(dev);
|
|
|
|
|
|
|
|
clk_disable_unprepare(dwmac->clk);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sti_dwmac_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct sti_dwmac *dwmac = get_stmmac_bsp_priv(dev);
|
|
|
|
|
2016-11-04 17:54:09 +00:00
|
|
|
clk_prepare_enable(dwmac->clk);
|
2016-11-04 17:54:10 +00:00
|
|
|
sti_dwmac_set_mode(dwmac);
|
2016-11-04 17:54:07 +00:00
|
|
|
|
|
|
|
return stmmac_resume(dev);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_PM_SLEEP */
|
|
|
|
|
|
|
|
static SIMPLE_DEV_PM_OPS(sti_dwmac_pm_ops, sti_dwmac_suspend,
|
|
|
|
sti_dwmac_resume);
|
|
|
|
|
2015-07-28 22:08:59 +00:00
|
|
|
static const struct sti_dwmac_of_data stih4xx_dwmac_data = {
|
2015-07-28 22:09:04 +00:00
|
|
|
.fix_retime_src = stih4xx_fix_retime_src,
|
2014-10-14 06:12:56 +00:00
|
|
|
};
|
|
|
|
|
2015-05-14 10:11:04 +00:00
|
|
|
static const struct of_device_id sti_dwmac_match[] = {
|
|
|
|
{ .compatible = "st,stih407-dwmac", .data = &stih4xx_dwmac_data},
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, sti_dwmac_match);
|
|
|
|
|
|
|
|
static struct platform_driver sti_dwmac_driver = {
|
2015-07-28 22:08:55 +00:00
|
|
|
.probe = sti_dwmac_probe,
|
2023-05-08 14:26:34 +00:00
|
|
|
.remove_new = sti_dwmac_remove,
|
2015-05-14 10:11:04 +00:00
|
|
|
.driver = {
|
|
|
|
.name = "sti-dwmac",
|
2016-11-04 17:54:07 +00:00
|
|
|
.pm = &sti_dwmac_pm_ops,
|
2015-05-14 10:11:04 +00:00
|
|
|
.of_match_table = sti_dwmac_match,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
module_platform_driver(sti_dwmac_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@st.com>");
|
|
|
|
MODULE_DESCRIPTION("STMicroelectronics DWMAC Specific Glue layer");
|
|
|
|
MODULE_LICENSE("GPL");
|