Commit 009722a2 authored by David S. Miller's avatar David S. Miller

Merge branch 'hisilicon-mdio-femac'

Dongpo Li says:

====================
Add Hisilicon MDIO bus driver and FEMAC driver

This patch set adds a Hisilicon MDIO bus driver and
a Fast Ethernet MAC(FEMAC) driver.
We also abstract a general interface "of_phy_get_and_connect"
for PHY connect. User will have no bother with getting
"phy-mode" and "phy-handle" any more.

Changes in v1:
- Pass private data structure instead of struct mii_bus
  in MDIO read and write operation.
- Return the error which devm_clk_get() gives when MDIO probe.
- Leave the clock unprepared and disabled on error when MDIO probe.
- Abstract a general interface "of_phy_get_and_connect" for PHY connect.
- Remove the "_reset" suffixes in "reset-names" property.
- Enable tx per-packet interrupt when tx fifo full.
- Remove pointless compatible and add SoC specific compatible.
- Declare only one clock in MAC dts documentation.
- Add standard unit suffixes for "phy-reset-delays".
- Use a smaller NAPI poll weight 16 for our Fast Ethernet MAC.
- Use phy_ethtool_{get|set}_link_ksettings for ethtool ops.
- Use phydev from struct net_device in MAC driver.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 8d8836d4 542ae60a
Hisilicon Fast Ethernet MDIO Controller interface
Required properties:
- compatible: should be "hisilicon,hisi-femac-mdio".
- reg: address and length of the register set for the device.
- clocks: A phandle to the reference clock for this device.
- PHY subnode: inherits from phy binding [1]
[1] Documentation/devicetree/bindings/net/phy.txt
Example:
mdio: mdio@10091100 {
compatible = "hisilicon,hisi-femac-mdio";
reg = <0x10091100 0x10>;
clocks = <&crg HI3516CV300_MDIO_CLK>;
#address-cells = <1>;
#size-cells = <0>;
phy0: phy@1 {
reg = <1>;
};
};
Hisilicon Fast Ethernet MAC controller
Required properties:
- compatible: should contain one of the following version strings:
* "hisilicon,hisi-femac-v1"
* "hisilicon,hisi-femac-v2"
and the soc string "hisilicon,hi3516cv300-femac".
- reg: specifies base physical address(s) and size of the device registers.
The first region is the MAC core register base and size.
The second region is the global MAC control register.
- interrupts: should contain the MAC interrupt.
- clocks: A phandle to the MAC main clock.
- resets: should contain the phandle to the MAC reset signal(required) and
the PHY reset signal(optional).
- reset-names: should contain the reset signal name "mac"(required)
and "phy"(optional).
- mac-address: see ethernet.txt [1].
- phy-mode: see ethernet.txt [1].
- phy-handle: see ethernet.txt [1].
- hisilicon,phy-reset-delays-us: triplet of delays if PHY reset signal given.
The 1st cell is reset pre-delay in micro seconds.
The 2nd cell is reset pulse in micro seconds.
The 3rd cell is reset post-delay in micro seconds.
[1] Documentation/devicetree/bindings/net/ethernet.txt
Example:
hisi_femac: ethernet@10090000 {
compatible = "hisilicon,hi3516cv300-femac","hisilicon,hisi-femac-v2";
reg = <0x10090000 0x1000>,<0x10091300 0x200>;
interrupts = <12>;
clocks = <&crg HI3518EV200_ETH_CLK>;
resets = <&crg 0xec 0>,<&crg 0xec 3>;
reset-names = "mac","phy";
mac-address = [00 00 00 00 00 00];
phy-mode = "mii";
phy-handle = <&phy0>;
hisilicon,phy-reset-delays-us = <10000 20000 20000>;
};
...@@ -23,6 +23,18 @@ config HIX5HD2_GMAC ...@@ -23,6 +23,18 @@ config HIX5HD2_GMAC
help help
This selects the hix5hd2 mac family network device. This selects the hix5hd2 mac family network device.
config HISI_FEMAC
tristate "Hisilicon Fast Ethernet MAC device support"
depends on HAS_IOMEM
select PHYLIB
select RESET_CONTROLLER
help
This selects the Hisilicon Fast Ethernet MAC device(FEMAC).
The FEMAC receives and transmits data over Ethernet
ports at 10/100 Mbps in full-duplex or half-duplex mode.
The FEMAC exchanges data with the CPU, and supports
the energy efficient Ethernet (EEE).
config HIP04_ETH config HIP04_ETH
tristate "HISILICON P04 Ethernet support" tristate "HISILICON P04 Ethernet support"
depends on HAS_IOMEM # For MFD_SYSCON depends on HAS_IOMEM # For MFD_SYSCON
......
...@@ -6,3 +6,4 @@ obj-$(CONFIG_HIX5HD2_GMAC) += hix5hd2_gmac.o ...@@ -6,3 +6,4 @@ obj-$(CONFIG_HIX5HD2_GMAC) += hix5hd2_gmac.o
obj-$(CONFIG_HIP04_ETH) += hip04_eth.o obj-$(CONFIG_HIP04_ETH) += hip04_eth.o
obj-$(CONFIG_HNS_MDIO) += hns_mdio.o obj-$(CONFIG_HNS_MDIO) += hns_mdio.o
obj-$(CONFIG_HNS) += hns/ obj-$(CONFIG_HNS) += hns/
obj-$(CONFIG_HISI_FEMAC) += hisi_femac.o
This diff is collapsed.
...@@ -294,6 +294,13 @@ config INTEL_XWAY_PHY ...@@ -294,6 +294,13 @@ config INTEL_XWAY_PHY
PEF 7061, PEF 7071 and PEF 7072 or integrated into the Intel PEF 7061, PEF 7071 and PEF 7072 or integrated into the Intel
SoCs xRX200, xRX300, xRX330, xRX350 and xRX550. SoCs xRX200, xRX300, xRX330, xRX350 and xRX550.
config MDIO_HISI_FEMAC
tristate "Hisilicon FEMAC MDIO bus controller"
depends on HAS_IOMEM && OF_MDIO
help
This module provides a driver for the MDIO busses found in the
Hisilicon SoC that have an Fast Ethernet MAC.
endif # PHYLIB endif # PHYLIB
config MICREL_KS8995MA config MICREL_KS8995MA
......
...@@ -47,3 +47,4 @@ obj-$(CONFIG_MDIO_BCM_UNIMAC) += mdio-bcm-unimac.o ...@@ -47,3 +47,4 @@ obj-$(CONFIG_MDIO_BCM_UNIMAC) += mdio-bcm-unimac.o
obj-$(CONFIG_MICROCHIP_PHY) += microchip.o obj-$(CONFIG_MICROCHIP_PHY) += microchip.o
obj-$(CONFIG_MDIO_BCM_IPROC) += mdio-bcm-iproc.o obj-$(CONFIG_MDIO_BCM_IPROC) += mdio-bcm-iproc.o
obj-$(CONFIG_INTEL_XWAY_PHY) += intel-xway.o obj-$(CONFIG_INTEL_XWAY_PHY) += intel-xway.o
obj-$(CONFIG_MDIO_HISI_FEMAC) += mdio-hisi-femac.o
/*
* Hisilicon Fast Ethernet MDIO Bus Driver
*
* Copyright (c) 2016 HiSilicon Technologies Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/clk.h>
#include <linux/iopoll.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of_address.h>
#include <linux/of_mdio.h>
#include <linux/platform_device.h>
#define MDIO_RWCTRL 0x00
#define MDIO_RO_DATA 0x04
#define MDIO_WRITE BIT(13)
#define MDIO_RW_FINISH BIT(15)
#define BIT_PHY_ADDR_OFFSET 8
#define BIT_WR_DATA_OFFSET 16
struct hisi_femac_mdio_data {
struct clk *clk;
void __iomem *membase;
};
static int hisi_femac_mdio_wait_ready(struct hisi_femac_mdio_data *data)
{
u32 val;
return readl_poll_timeout(data->membase + MDIO_RWCTRL,
val, val & MDIO_RW_FINISH, 20, 10000);
}
static int hisi_femac_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
{
struct hisi_femac_mdio_data *data = bus->priv;
int ret;
ret = hisi_femac_mdio_wait_ready(data);
if (ret)
return ret;
writel((mii_id << BIT_PHY_ADDR_OFFSET) | regnum,
data->membase + MDIO_RWCTRL);
ret = hisi_femac_mdio_wait_ready(data);
if (ret)
return ret;
return readl(data->membase + MDIO_RO_DATA) & 0xFFFF;
}
static int hisi_femac_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
u16 value)
{
struct hisi_femac_mdio_data *data = bus->priv;
int ret;
ret = hisi_femac_mdio_wait_ready(data);
if (ret)
return ret;
writel(MDIO_WRITE | (value << BIT_WR_DATA_OFFSET) |
(mii_id << BIT_PHY_ADDR_OFFSET) | regnum,
data->membase + MDIO_RWCTRL);
return hisi_femac_mdio_wait_ready(data);
}
static int hisi_femac_mdio_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct mii_bus *bus;
struct hisi_femac_mdio_data *data;
struct resource *res;
int ret;
bus = mdiobus_alloc_size(sizeof(*data));
if (!bus)
return -ENOMEM;
bus->name = "hisi_femac_mii_bus";
bus->read = &hisi_femac_mdio_read;
bus->write = &hisi_femac_mdio_write;
snprintf(bus->id, MII_BUS_ID_SIZE, "%s", pdev->name);
bus->parent = &pdev->dev;
data = bus->priv;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
data->membase = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(data->membase)) {
ret = PTR_ERR(data->membase);
goto err_out_free_mdiobus;
}
data->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(data->clk)) {
ret = PTR_ERR(data->clk);
goto err_out_free_mdiobus;
}
ret = clk_prepare_enable(data->clk);
if (ret)
goto err_out_free_mdiobus;
ret = of_mdiobus_register(bus, np);
if (ret)
goto err_out_disable_clk;
platform_set_drvdata(pdev, bus);
return 0;
err_out_disable_clk:
clk_disable_unprepare(data->clk);
err_out_free_mdiobus:
mdiobus_free(bus);
return ret;
}
static int hisi_femac_mdio_remove(struct platform_device *pdev)
{
struct mii_bus *bus = platform_get_drvdata(pdev);
struct hisi_femac_mdio_data *data = bus->priv;
mdiobus_unregister(bus);
clk_disable_unprepare(data->clk);
mdiobus_free(bus);
return 0;
}
static const struct of_device_id hisi_femac_mdio_dt_ids[] = {
{ .compatible = "hisilicon,hisi-femac-mdio" },
{ }
};
MODULE_DEVICE_TABLE(of, hisi_femac_mdio_dt_ids);
static struct platform_driver hisi_femac_mdio_driver = {
.probe = hisi_femac_mdio_probe,
.remove = hisi_femac_mdio_remove,
.driver = {
.name = "hisi-femac-mdio",
.of_match_table = hisi_femac_mdio_dt_ids,
},
};
module_platform_driver(hisi_femac_mdio_driver);
MODULE_DESCRIPTION("Hisilicon Fast Ethernet MAC MDIO interface driver");
MODULE_AUTHOR("Dongpo Li <lidongpo@hisilicon.com>");
MODULE_LICENSE("GPL v2");
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/of_mdio.h> #include <linux/of_mdio.h>
#include <linux/of_net.h>
#include <linux/module.h> #include <linux/module.h>
MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>"); MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
...@@ -331,6 +332,41 @@ struct phy_device *of_phy_connect(struct net_device *dev, ...@@ -331,6 +332,41 @@ struct phy_device *of_phy_connect(struct net_device *dev,
} }
EXPORT_SYMBOL(of_phy_connect); EXPORT_SYMBOL(of_phy_connect);
/**
* of_phy_get_and_connect
* - Get phy node and connect to the phy described in the device tree
* @dev: pointer to net_device claiming the phy
* @np: Pointer to device tree node for the net_device claiming the phy
* @hndlr: Link state callback for the network device
*
* If successful, returns a pointer to the phy_device with the embedded
* struct device refcount incremented by one, or NULL on failure. The
* refcount must be dropped by calling phy_disconnect() or phy_detach().
*/
struct phy_device *of_phy_get_and_connect(struct net_device *dev,
struct device_node *np,
void (*hndlr)(struct net_device *))
{
phy_interface_t iface;
struct device_node *phy_np;
struct phy_device *phy;
iface = of_get_phy_mode(np);
if (iface < 0)
return NULL;
phy_np = of_parse_phandle(np, "phy-handle", 0);
if (!phy_np)
return NULL;
phy = of_phy_connect(dev, phy_np, hndlr, 0, iface);
of_node_put(phy_np);
return phy;
}
EXPORT_SYMBOL(of_phy_get_and_connect);
/** /**
* of_phy_attach - Attach to a PHY without starting the state machine * of_phy_attach - Attach to a PHY without starting the state machine
* @dev: pointer to net_device claiming the phy * @dev: pointer to net_device claiming the phy
......
...@@ -19,6 +19,9 @@ extern struct phy_device *of_phy_connect(struct net_device *dev, ...@@ -19,6 +19,9 @@ extern struct phy_device *of_phy_connect(struct net_device *dev,
struct device_node *phy_np, struct device_node *phy_np,
void (*hndlr)(struct net_device *), void (*hndlr)(struct net_device *),
u32 flags, phy_interface_t iface); u32 flags, phy_interface_t iface);
extern struct phy_device *
of_phy_get_and_connect(struct net_device *dev, struct device_node *np,
void (*hndlr)(struct net_device *));
struct phy_device *of_phy_attach(struct net_device *dev, struct phy_device *of_phy_attach(struct net_device *dev,
struct device_node *phy_np, u32 flags, struct device_node *phy_np, u32 flags,
phy_interface_t iface); phy_interface_t iface);
...@@ -52,6 +55,13 @@ static inline struct phy_device *of_phy_connect(struct net_device *dev, ...@@ -52,6 +55,13 @@ static inline struct phy_device *of_phy_connect(struct net_device *dev,
return NULL; return NULL;
} }
static inline struct phy_device *
of_phy_get_and_connect(struct net_device *dev, struct device_node *np,
void (*hndlr)(struct net_device *))
{
return NULL;
}
static inline struct phy_device *of_phy_attach(struct net_device *dev, static inline struct phy_device *of_phy_attach(struct net_device *dev,
struct device_node *phy_np, struct device_node *phy_np,
u32 flags, phy_interface_t iface) u32 flags, phy_interface_t iface)
......
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