ethernet: arc: Add support for Rockchip SoC layer device tree bindings
Subsystems (4)
PATCH v5 1/4 ethernet: arc: Add support for Rockchip SoC layer device tree bindings
This patch defines a platform glue layer for Rockchip SoCs which support arc-emac driver. It ensures that regulator for the rmii is on before trying to connect to the ethernet controller. It applies right speed and mode changes to the grf when ethernet settings change.
--- drivers/net/ethernet/arc/Kconfig | 10 ++ drivers/net/ethernet/arc/Makefile | 1 + drivers/net/ethernet/arc/emac.h | 4 +- drivers/net/ethernet/arc/emac_main.c | 2 + drivers/net/ethernet/arc/emac_rockchip.c | 228 +++++++++++++++++++++++++++++++ 5 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/arc/emac_rockchip.c
drivers/net/ethernet/arc/Kconfig +10 -0
@@ -32,4 +32,14 @@ config ARC_EMAC non-standard on-chip ethernet device ARC EMAC 10/100 is used. Say Y here if you have such a board. If unsure, say N. +config EMAC_ROCKCHIP + tristate "Rockchip EMAC support" + select ARC_EMAC_CORE + depends on OF_IRQ && OF_NET && REGULATOR + ---help--- + Support for Rockchip RK3066/RK3188 EMAC ethernet controllers. + This selects Rockchip SoC glue layer support for the + emac device driver. This driver is used for RK3066/RK3188 + EMAC ethernet controller. + endif # NET_VENDOR_ARC
drivers/net/ethernet/arc/Makefile +1 -0
@@ -5,3 +5,4 @@ arc_emac-objs := emac_main.o emac_mdio.o obj-$(CONFIG_ARC_EMAC_CORE) += arc_emac.o obj-$(CONFIG_ARC_EMAC) += emac_arc.o +obj-$(CONFIG_EMAC_ROCKCHIP) += emac_rockchip.o
drivers/net/ethernet/arc/emac.h +3 -1
@@ -123,9 +123,11 @@ struct buffer_state {* @speed: PHY's last set speed. */ struct arc_emac_priv { -/* Devices */ const char *drv_name;const char *drv_version; +void (*set_mac_speed)(void *priv,unsigned int speed); + +/* Devices */ struct device *dev;struct phy_device *phy_dev;struct mii_bus *bus;
drivers/net/ethernet/arc/emac_main.c +2 -0
@@ -48,6 +48,8 @@ static void arc_emac_adjust_link(struct net_device *ndev)if (priv->speed != phy_dev->speed) { priv->speed = phy_dev->speed; state_changed =1 ; +if (priv->set_mac_speed) + priv->set_mac_speed (priv, priv->speed); }if (priv->duplex != phy_dev->duplex) {
drivers/net/ethernet/arc/emac_rockchip.c new file +228 -0
228 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 2/4 dt-bindings: Document EMAC Rockchip
This adds the necessary binding documentation for the EMAC Rockchip platform driver found in RK3066 and RK3188 SoCs.
--- .../devicetree/bindings/net/emac_rockchip.txt | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/emac_rockchip.txt
Documentation/devicetree/bindings/net/emac_rockchip.txt new file +50 -0
@@ -0,0 +1,50 @@ +* ARC EMAC 10/100 Ethernet platform driver for Rockchip Rk3066/RK3188 SoCs + +Required properties: +- compatible: Should be "rockchip,rk3066-emac" or "rockchip,rk3188-emac" + according to the target SoC. +- reg: Address and length of the register set for the device +- interrupts: Should contain the EMAC interrupts +- rockchip,grf: phandle to the syscon grf used to control speed and mode + for emac. +- phy: see ethernet.txt file in the same directory. +- phy-mode: see ethernet.txt file in the same directory. + +Optional properties: +- phy-supply: phandle to a regulator if the PHY needs one + +Clock handling: +- clocks: Must contain an entry for each entry in clock-names. +- clock-names: Shall be "hclk" for the host clock needed to calculate and set + polling period of EMAC and "macref" for the reference clock needed to transfer + data to and from the phy. + +Child nodes of the driver are the individual PHY devices connected to the +MDIO bus. They must have a "reg" property given the PHY address on the MDIO bus. + +Examples: + +ethernet@10204000 { + compatible = "rockchip,rk3188-emac"; + reg = <0xc0fc2000 0x3c>; + interrupts = <6>; + mac-address = [ 00 11 22 33 44 55 ]; + + clocks = <&cru HCLK_EMAC>, <&cru SCLK_MAC>; + clock-names = "hclk", "macref"; + + pinctrl-names = "default"; + pinctrl-0 = <&emac_xfer>, <&emac_mdio>, <&phy_int>; + + rockchip,grf = <&grf>; + + phy = <&phy0>; + phy-mode = "rmii"; + phy-supply = <&vcc_rmii>; + + #address-cells = <1>; + #size-cells = <0>; + phy0: ethernet-phy@0 { + reg = <1>; + }; +};
Signature · 1 line
1.9.1
Re: [PATCH v2 2/4] dt-bindings: Document EMAC Rockchip
see "[PATCH v5 1/4] ethernet: arc: Add support for Rockchip SoC layer device tree bindings" for acceptance
2014-09-03 18:52 GMT+02:00 Romain Perier <[email protected]>:
Quoted 68 lines
This adds the necessary binding documentation for the EMAC Rockchip platform driver found in RK3066 and RK3188 SoCs.
Signed-off-by Romain Perier <[email protected]>--- .../devicetree/bindings/net/emac_rockchip.txt | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/emac_rockchip.txtDocumentation/devicetree/bindings/net/emac_rockchip.txt new file +50
-1@@ -0,0 +1,50 @@ +* ARC EMAC 10/100 Ethernet platform driver for Rockchip Rk3066/RK3188 SoCs + +Required properties: +- compatible: Should be "rockchip,rk3066-emac" or "rockchip,rk3188-emac" + according to the target SoC. +- reg: Address and length of the register set for the device +- interrupts: Should contain the EMAC interrupts +- rockchip,grf: phandle to the syscon grf used to control speed and mode + for emac. +- phy: see ethernet.txt file in the same directory. +- phy-mode: see ethernet.txt file in the same directory. + +Optional properties: +- phy-supply: phandle to a regulator if the PHY needs one + +Clock handling: +- clocks: Must contain an entry for each entry in clock-names. +- clock-names: Shall be "hclk" for the host clock needed to calculate and set + polling period of EMAC and "macref" for the reference clock needed to transfer + data to and from the phy. + +Child nodes of the driver are the individual PHY devices connected to the +MDIO bus. They must have a "reg" property given the PHY address on the MDIO bus. + +Examples: + +ethernet@10204000 { + compatible = "rockchip,rk3188-emac"; + reg = <0xc0fc2000 0x3c>; + interrupts = <6>; + mac-address = [ 00 11 22 33 44 55 ]; + + clocks = <&cru HCLK_EMAC>, <&cru SCLK_MAC>; + clock-names = "hclk", "macref"; + + pinctrl-names = "default"; + pinctrl-0 = <&emac_xfer>, <&emac_mdio>, <&phy_int>; + + rockchip,grf = <&grf>; + + phy = <&phy0>; + phy-mode = "rmii"; + phy-supply = <&vcc_rmii>; + + #address-cells = <1>; + #size-cells = <0>; + phy0: ethernet-phy@0 { + reg = <1>; + }; +}; --1.9.1
Re: [PATCH v2 2/4] dt-bindings: Document EMAC Rockchip
In reply to Romain PerierAm Mittwoch, 3. September 2014, 16:52:43 schrieb Romain Perier:
Quoted 4 lines
This adds the necessary binding documentation for the EMAC Rockchip platform driver found in RK3066 and RK3188 SoCs.
Signed-off-by Romain Perier <[email protected]>
Quoted 62 lines
--- .../devicetree/bindings/net/emac_rockchip.txt | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/emac_rockchip.txt(quoted diff) +0
-0
b/Documentation/devicetree/bindings/net/emac_rockchip.txtnew file mode 100644
index 0000000..8dc1c79Documentation/devicetree/bindings/net/emac_rockchip.txt new file +18
-0@@ -0,0 +1,50 @@ +* ARC EMAC 10/100 Ethernet platform driver for Rockchip Rk3066/RK3188 SoCs + +Required properties: +- compatible: Should be "rockchip,rk3066-emac" or "rockchip,rk3188-emac" + according to the target SoC. +- reg: Address and length of the register set for the device +- interrupts: Should contain the EMAC interrupts +- rockchip,grf: phandle to the syscon grf used to control speed and mode + for emac. +- phy: see ethernet.txt file in the same directory. +- phy-mode: see ethernet.txt file in the same directory. + +Optional properties: +- phy-supply: phandle to a regulator if the PHY needs one + +Clock handling: +- clocks: Must contain an entry for each entry in clock-names. +- clock-names: Shall be "hclk" for the host clock needed to calculate andset + polling period of EMAC and "macref" for the reference clock needed to transfer + data to and from the phy.
Documentation/devicetree/bindings/net/emac_rockchip.txt new file +3
-0+ +Child nodes of the driver are the individual PHY devices connected to the +MDIO bus. They must have a "reg" property given the PHY address on the MDIObus. +
Documentation/devicetree/bindings/net/emac_rockchip.txt new file +26
-0+Examples: + +ethernet@10204000 { + compatible = "rockchip,rk3188-emac"; + reg = <0xc0fc2000 0x3c>; + interrupts = <6>; + mac-address = [ 00 11 22 33 44 55 ]; + + clocks = <&cru HCLK_EMAC>, <&cru SCLK_MAC>; + clock-names = "hclk", "macref"; + + pinctrl-names = "default"; + pinctrl-0 = <&emac_xfer>, <&emac_mdio>, <&phy_int>; + + rockchip,grf = <&grf>; + + phy = <&phy0>; + phy-mode = "rmii"; + phy-supply = <&vcc_rmii>; + + #address-cells = <1>; + #size-cells = <0>; + phy0: ethernet-phy@0 { + reg = <1>; + }; +};
PATCH 3/4 ARM: dts: Add emac nodes to the rk3188 device tree
In reply to Romain PerierThis adds support for EMAC Rockchip driver on RK3188 SoCs.
--- arch/arm/boot/dts/rk3188.dtsi | 18 ++++++++++++++++++ arch/arm/boot/dts/rk3xxx.dtsi | 17 +++++++++++++++++ 2 files changed, 35 insertions(+)
arch/arm/boot/dts/rk3188.dtsi +18 -0
@@ -147,6 +147,24 @@ bias-disable; }; + emac { + emac_xfer: emac-xfer { + rockchip,pins = <RK_GPIO3 16 RK_FUNC_2 &pcfg_pull_none>, //tx_en + <RK_GPIO3 17 RK_FUNC_2 &pcfg_pull_none>, //txd1 + <RK_GPIO3 18 RK_FUNC_2 &pcfg_pull_none>, //txd0 + <RK_GPIO3 19 RK_FUNC_2 &pcfg_pull_none>, //rxd0 + <RK_GPIO3 20 RK_FUNC_2 &pcfg_pull_none>, //rxd1 + <RK_GPIO3 21 RK_FUNC_2 &pcfg_pull_none>, //mac_clk + <RK_GPIO3 22 RK_FUNC_2 &pcfg_pull_none>, //rx_err + <RK_GPIO3 23 RK_FUNC_2 &pcfg_pull_none>; //crs_dvalid + }; + + emac_mdio: emac-mdio { + rockchip,pins = <RK_GPIO3 24 RK_FUNC_2 &pcfg_pull_none>, + <RK_GPIO3 25 RK_FUNC_2 &pcfg_pull_none>; + }; + }; + i2c0 { i2c0_xfer: i2c0-xfer { rockchip,pins = <RK_GPIO1 24 RK_FUNC_1 &pcfg_pull_none>,
arch/arm/boot/dts/rk3xxx.dtsi +17 -0
@@ -91,6 +91,23 @@ status = "disabled"; }; + emac: ethernet@10204000 { + compatible = "snps,arc-emac"; + reg = <0x10204000 0x3c>; + interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <1>; + #size-cells = <0>; + + rockchip,grf = <&grf>; + + clocks = <&cru HCLK_EMAC>, <&cru SCLK_MAC>; + clock-names = "hclk", "macref"; + max-speed = <100>; + phy-mode = "rmii"; + + status = "disabled"; + }; + mmc0: dwmmc@10214000 { compatible = "rockchip,rk2928-dw-mshc"; reg = <0x10214000 0x1000>;
Signature · 1 line
1.9.1
Heiko Stübner
maintainerRe: [PATCH 3/4] ARM: dts: Add emac nodes to the rk3188 device tree
Am Mittwoch, 3. September 2014, 16:52:44 schrieb Romain Perier:
Quoted 3 lines
This adds support for EMAC Rockchip driver on RK3188 SoCs.
Signed-off-by Romain Perier <[email protected]>
could you think about changing patches 3 and 4 with the diff below?
For one the comment style is not really following the coding style. I guess either remove the comments completely or switch to a /* ... */ form.
More importantly, I think the compatible is a property of the SoC and does not need to be replicated into every board, so it should live in a small &emac node in the rk3188.dtsi to adapt the property.
Heiko
arch/arm/boot/dts/rk3188-radxarock.dts +0 -1
@@ -100,7 +100,6 @@ &emac { status = "okay"; - compatible = "rockchip,rk3188-emac"; pinctrl-names = "default"; pinctrl-0 = <&emac_xfer>, <&emac_mdio>, <&phy_int>;
arch/arm/boot/dts/rk3188.dtsi +12 -8
@@ -193,14 +193,14 @@ emac { emac_xfer: emac-xfer { - rockchip,pins = <RK_GPIO3 16 RK_FUNC_2 &pcfg_pull_none>, //tx_en - <RK_GPIO3 17 RK_FUNC_2 &pcfg_pull_none>, //txd1 - <RK_GPIO3 18 RK_FUNC_2 &pcfg_pull_none>, //txd0 - <RK_GPIO3 19 RK_FUNC_2 &pcfg_pull_none>, //rxd0 - <RK_GPIO3 20 RK_FUNC_2 &pcfg_pull_none>, //rxd1 - <RK_GPIO3 21 RK_FUNC_2 &pcfg_pull_none>, //mac_clk - <RK_GPIO3 22 RK_FUNC_2 &pcfg_pull_none>, //rx_err - <RK_GPIO3 23 RK_FUNC_2 &pcfg_pull_none>; //crs_dvalid + rockchip,pins = <RK_GPIO3 16 RK_FUNC_2 &pcfg_pull_none>, /* tx_en */ + <RK_GPIO3 17 RK_FUNC_2 &pcfg_pull_none>, /* txd1 */ + <RK_GPIO3 18 RK_FUNC_2 &pcfg_pull_none>, /* txd0 */ + <RK_GPIO3 19 RK_FUNC_2 &pcfg_pull_none>, /* rxd0 */ + <RK_GPIO3 20 RK_FUNC_2 &pcfg_pull_none>, /* rxd1 */ + <RK_GPIO3 21 RK_FUNC_2 &pcfg_pull_none>, /* mac_clk */ + <RK_GPIO3 22 RK_FUNC_2 &pcfg_pull_none>, /* rx_err */ + <RK_GPIO3 23 RK_FUNC_2 &pcfg_pull_none>; /* crs_dvalid */ }; emac_mdio: emac-mdio {
@@ -385,6 +385,10 @@ }; }; +&emac { + compatible = "rockchip,rk3188-emac"; +}; + &global_timer { interrupts = <GIC_PPI 11 0xf04>; };
Quoted 62 lines
--- arch/arm/boot/dts/rk3188.dtsi | 18 ++++++++++++++++++ arch/arm/boot/dts/rk3xxx.dtsi | 17 +++++++++++++++++ 2 files changed, 35 insertions(+)arch/arm/boot/dts/rk3188.dtsi +18
-0@@ -147,6 +147,24 @@ bias-disable; }; + emac { + emac_xfer: emac-xfer { + rockchip,pins = <RK_GPIO3 16 RK_FUNC_2 &pcfg_pull_none>, //tx_en + <RK_GPIO3 17 RK_FUNC_2 &pcfg_pull_none>, //txd1 + <RK_GPIO3 18 RK_FUNC_2 &pcfg_pull_none>, //txd0 + <RK_GPIO3 19 RK_FUNC_2 &pcfg_pull_none>, //rxd0 + <RK_GPIO3 20 RK_FUNC_2 &pcfg_pull_none>, //rxd1 + <RK_GPIO3 21 RK_FUNC_2 &pcfg_pull_none>, //mac_clk + <RK_GPIO3 22 RK_FUNC_2 &pcfg_pull_none>, //rx_err + <RK_GPIO3 23 RK_FUNC_2 &pcfg_pull_none>; //crs_dvalid + }; + + emac_mdio: emac-mdio { + rockchip,pins = <RK_GPIO3 24 RK_FUNC_2 &pcfg_pull_none>, + <RK_GPIO3 25 RK_FUNC_2 &pcfg_pull_none>; + }; + }; + i2c0 { i2c0_xfer: i2c0-xfer { rockchip,pins = <RK_GPIO1 24 RK_FUNC_1 &pcfg_pull_none>,arch/arm/boot/dts/rk3xxx.dtsi +17
-0@@ -91,6 +91,23 @@ status = "disabled"; }; + emac: ethernet@10204000 { + compatible = "snps,arc-emac"; + reg = <0x10204000 0x3c>; + interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <1>; + #size-cells = <0>; + + rockchip,grf = <&grf>; + + clocks = <&cru HCLK_EMAC>, <&cru SCLK_MAC>; + clock-names = "hclk", "macref"; + max-speed = <100>; + phy-mode = "rmii"; + + status = "disabled"; + }; + mmc0: dwmmc@10214000 { compatible = "rockchip,rk2928-dw-mshc"; reg = <0x10214000 0x1000>;
PATCH v2 4/4 ARM: dts: Enable emac node on the rk3188-radxarock boards
In reply to Romain PerierThis enables EMAC Rockchip support on radxa rock boards.
--- arch/arm/boot/dts/rk3188-radxarock.dts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
arch/arm/boot/dts/rk3188-radxarock.dts +23 -0
@@ -76,6 +76,23 @@ }; }; +&emac { + status = "okay"; + compatible = "rockchip,rk3188-emac"; + + pinctrl-names = "default"; + pinctrl-0 = <&emac_xfer>, <&emac_mdio>, <&phy_int>; + + phy = <&phy0>; + phy-supply = <&vcc_rmii>; + + phy0: ethernet-phy@0 { + reg = <0>; + interrupt-parent = <&gpio3>; + interrupts = <26 IRQ_TYPE_LEVEL_LOW>; + }; +}; + &i2c1 { status = "okay"; clock-frequency = <400000>;
@@ -201,6 +218,12 @@ }; }; + lan8720a { + phy_int: phy-int { + rockchip,pins = <RK_GPIO3 26 RK_FUNC_GPIO &pcfg_pull_up>; + }; + }; + ir-receiver { ir_recv_pin: ir-recv-pin { rockchip,pins = <RK_GPIO0 10 RK_FUNC_GPIO &pcfg_pull_none>;
Signature · 1 line
1.9.1
Quoted 7 lines · On Wednesday 03 September 2014 16:52:42 Romain Perier wrote:
This patch defines a platform glue layer for Rockchip SoCs which support arc-emac driver. It ensures that regulator for the rmii is on before trying to connect to the ethernet controller. It applies right speed and mode changes to the grf when ethernet settings change.
Signed-off-by Romain Perier <[email protected]>
Whole series
Quoted 4 lines · Romain Perier
This patch defines a platform glue layer for Rockchip SoCs which support arc-emac driver. It ensures that regulator for the rmii is on before trying to connect to the ethernet controller. It applies right speed and mode changes to the grf when ethernet settings change.
Hi Romain,
on a Radxa Rock when I try to remove the emac_rockchip module the board locks up when calling clk_disable_unprepare(priv->refclk). The tree is a net-next + your series, I don't know if I need some other patches.
There is also the following build warning due to the emac dependency on REGULATOR which in principle seems correct, but looking at other drivers I wonder why they use the regulator APIs but don't have the same dependency.
drivers/regulator/Kconfig:1:error: recursive dependency detected!
drivers/regulator/Kconfig:1: symbol REGULATOR is selected by MDIO_SUN4I drivers/net/phy/Kconfig:159: symbol MDIO_SUN4I depends on PHYLIB drivers/net/phy/Kconfig:5: symbol PHYLIB is selected by ARC_EMAC_CORE
drivers/net/ethernet/arc/Kconfig:20: symbol ARC_EMAC_CORE is selected by EMAC_ROCKCHIPdrivers/net/ethernet/arc/Kconfig:35: symbol EMAC_ROCKCHIP depends on REGULATOR
Regards,
Beniamino
PATCH v5 1/4 ethernet: arc: Add support for Rockchip SoC layer device tree bindings
Hi Beniamino,
I will investigate. Could you please :
- Load the module
- Show me the output of lsmod
- Use your ethernet a bit
- Try to unload the module
- If your board did not freeze or if your kernel did not panic , show me your dmesg (if it is impossible show me the dmesg before unloading the module)
Perhaps, we could continue this discussion in private (by email or IRC). What do you think ?
I will investigate this evening and tomorrow. Thanks for your feedbacks .
2014-09-03 23:12 GMT+02:00 Beniamino Galvani <[email protected]>:
Quoted 27 lines · Romain Perier
Quoted 4 lines
This patch defines a platform glue layer for Rockchip SoCs which support arc-emac driver. It ensures that regulator for the rmii is on before trying to connect to the ethernet controller. It applies right speed and mode changes to the grf when ethernet settings change.
Hi Romain,
on a Radxa Rock when I try to remove the
emac_rockchipmodule the board locks up when callingclk_disable_unprepare(priv->refclk). The tree is a net-next + your series, I don't know if I need some other patches.There is also the following build warning due to the emac dependency on REGULATOR which in principle seems correct, but looking at other drivers I wonder why they use the regulator APIs but don't have the same dependency.
drivers/regulator/Kconfig:1:error: recursive dependency detected!
drivers/regulator/Kconfig:1: symbol REGULATOR is selected by MDIO_SUN4I drivers/net/phy/Kconfig:159: symbol MDIO_SUN4I depends on PHYLIB drivers/net/phy/Kconfig:5: symbol PHYLIB is selected by ARC_EMAC_CORE
drivers/net/ethernet/arc/Kconfig:20: symbolARC_EMAC_COREis selected byEMAC_ROCKCHIPdrivers/net/ethernet/arc/Kconfig:35: symbolEMAC_ROCKCHIPdepends on REGULATORRegards,
Beniamino
Quoted 12 lines · PERIER Romain
Hi Beniamino,
I will investigate. Could you please :
- Load the module
- Show me the output of lsmod
- Use your ethernet a bit
- Try to unload the module
- If your board did not freeze or if your kernel did not panic , show me your dmesg (if it is impossible show me the dmesg before unloading the module)
Quoted 4 lines
Perhaps, we could continue this discussion in private (by email or IRC). What do you think ?
I will investigate this evening and tomorrow. Thanks for your feedbacks .
Hi Romain,
the freeze happens in clk_disable_unprepare(), which disables the macref clock parents up to the dpll, needed by the DDR.
As suggested by Heiko on IRC, the patch "clk: rockchip: protect critical clocks from getting disabled" [1], modified to include ddrphy in the list of critical clocks, solves the problem.
During the module unload, if you move the call to arc_emac_remove() before clk_disable_unprepare() you can avoid a delay of 4-5 seconds caused by the timeout of the function phy_disconnect(). In any case:
Quoted 30 lines
2014-09-03 23:12 GMT+02:00 Beniamino Galvani <[email protected]>:
Quoted 27 lines · Romain Perier
Quoted 4 lines
This patch defines a platform glue layer for Rockchip SoCs which support arc-emac driver. It ensures that regulator for the rmii is on before trying to connect to the ethernet controller. It applies right speed and mode changes to the grf when ethernet settings change.
Hi Romain,
on a Radxa Rock when I try to remove the
emac_rockchipmodule the board locks up when callingclk_disable_unprepare(priv->refclk). The tree is a net-next + your series, I don't know if I need some other patches.There is also the following build warning due to the emac dependency on REGULATOR which in principle seems correct, but looking at other drivers I wonder why they use the regulator APIs but don't have the same dependency.
drivers/regulator/Kconfig:1:error: recursive dependency detected!
drivers/regulator/Kconfig:1: symbol REGULATOR is selected by MDIO_SUN4I drivers/net/phy/Kconfig:159: symbol MDIO_SUN4I depends on PHYLIB drivers/net/phy/Kconfig:5: symbol PHYLIB is selected by ARC_EMAC_CORE
drivers/net/ethernet/arc/Kconfig:20: symbolARC_EMAC_COREis selected byEMAC_ROCKCHIPdrivers/net/ethernet/arc/Kconfig:35: symbolEMAC_ROCKCHIPdepends on REGULATORRegards,
Beniamino
PATCH v5 1/4 ethernet: arc: Add support for Rockchip SoC layer device tree bindings
In reply to Beniamino GalvaniQuoted 11 lines · On Wednesday 03 September 2014 23:12:20 Beniamino Galvani wrote:
There is also the following build warning due to the emac dependency on REGULATOR which in principle seems correct, but looking at other drivers I wonder why they use the regulator APIs but don't have the same dependency.
drivers/regulator/Kconfig:1:error: recursive dependency detected!
drivers/regulator/Kconfig:1: symbol REGULATOR is selected by MDIO_SUN4I drivers/net/phy/Kconfig:159: symbol MDIO_SUN4I depends on PHYLIB drivers/net/phy/Kconfig:5: symbol PHYLIB is selected by ARC_EMAC_CORE
drivers/net/ethernet/arc/Kconfig:20: symbolARC_EMAC_COREis selected byEMAC_ROCKCHIPdrivers/net/ethernet/arc/Kconfig:35: symbolEMAC_ROCKCHIPdepends on REGULATOR
This is a recurring problem:
driver a depends on x and selects y
driver b depends on y and selects x
Maybe we should teach Kconfig to not worry about it when x and y are both user-selectable as well.
However, a nicer solution would be if we could agree for each symbol on who is supposed to 'select' or 'depends on' it. In particular, we are inconsistent about CONFIG_REGULATOR:
MDIO_SUN4I probably should not 'select' it but instead 'depends on' this symbol if anything. It would be nice if someone could submit a patch to that effect. EMAC_ROCKCHIP could also drop the dependency on REGULATOR: you can still build the driver without that subsystem being enabled, but then all the regulators have to be set up by the boot loader.
There isn't much we can do about the PHYLIB dependency, unless we turn it into a silent symbol that gets selected by all phy drivers, or we change all network drivers that currently 'select' it to 'depends on'. I don't really want to get involved in that discussion ;-)
Arnd
Quoted 12 lines · Arnd Bergmann
This is a recurring problem:
driver a depends on x and selects y
driver b depends on y and selects xMaybe we should teach
Kconfigto not worry about it when x and y are both user-selectable as well.However, a nicer solution would be if we could agree for each symbol on who is supposed to 'select' or 'depends on' it. In particular, we are inconsistent about
CONFIG_REGULATOR:
Quoted 6 lines
MDIO_SUN4Iprobably should not 'select' it but instead 'depends on' this symbol if anything. It would be nice if someone could submit a patch to that effect.EMAC_ROCKCHIPcould also drop the dependency on REGULATOR: you can still build the driver without that subsystem being enabled, but then all the regulators have to be set up by the boot loader.
Thanks, things are clearer now.
If I understand correctly the dependency of MDIO_SUN4I on REGULATOR can be dropped as well for the same reason; I will send a patch for that.
Beniamino
Quoted 7 lines
There isn't much we can do about the PHYLIB dependency, unless we turn it into a silent symbol that gets selected by all phy drivers, or we change all network drivers that currently 'select' it to 'depends on'. I don't really want to get involved in that discussion ;-)
Arnd
Am Mittwoch, 3. September 2014, 16:52:42 schrieb Romain Perier:
Quoted 6 lines
This patch defines a platform glue layer for Rockchip SoCs which support arc-emac driver. It ensures that regulator for the rmii is on before trying to connect to the ethernet controller. It applies right speed and mode changes to the grf when ethernet settings change.
Signed-off-by Romain Perier <[email protected]>
Quoted 302 lines
--- drivers/net/ethernet/arc/Kconfig | 10 ++ drivers/net/ethernet/arc/Makefile | 1 + drivers/net/ethernet/arc/emac.h | 4 +- drivers/net/ethernet/arc/emac_main.c | 2 + drivers/net/ethernet/arc/emac_rockchip.c | 228 +++++++++++++++++++++++++++++++ 5 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/arc/emac_rockchip.c(quoted diff) +0
-0b/drivers/net/ethernet/arc/Kconfig index 89e04fd..8e262e2 100644
drivers/net/ethernet/arc/Kconfig +10
-0@@ -32,4 +32,14 @@ config ARC_EMAC non-standard on-chip ethernet device ARC EMAC 10/100 is used. Say Y here if you have such a board. If unsure, say N. +config EMAC_ROCKCHIP + tristate "Rockchip EMAC support" + select ARC_EMAC_CORE + depends on OF_IRQ && OF_NET && REGULATOR + ---help--- + Support for Rockchip RK3066/RK3188 EMAC ethernet controllers. + This selects Rockchip SoC glue layer support for the + emac device driver. This driver is used for RK3066/RK3188 + EMAC ethernet controller. + endif # NET_VENDOR_ARC(quoted diff) +0
-0b/drivers/net/ethernet/arc/Makefile index 241bb80..79108af 100644
drivers/net/ethernet/arc/Makefile +1
-0@@ -5,3 +5,4 @@ arc_emac-objs := emac_main.o emac_mdio.o obj-$(CONFIG_ARC_EMAC_CORE) += arc_emac.o obj-$(CONFIG_ARC_EMAC) += emac_arc.o +obj-$(CONFIG_EMAC_ROCKCHIP) += emac_rockchip.o(quoted diff) +0
-0
b/drivers/net/ethernet/arc/emac.hindex eb2ba67..dae1ac3 100644drivers/net/ethernet/arc/emac.h +3
-1@@ -123,9 +123,11 @@ struct buffer_state {* @speed: PHY's last set speed. */ struct arc_emac_priv { -/* Devices */ const char *drv_name;const char *drv_version; +void (*set_mac_speed)(void *priv,unsigned int speed); + +/* Devices */ struct device *dev;struct phy_device *phy_dev;struct mii_bus *bus;(quoted diff) +0
-0
b/drivers/net/ethernet/arc/emac_main.cindex b35c69e..a08f343 100644drivers/net/ethernet/arc/emac_main.c +2
-0@@ -48,6 +48,8 @@ static void arc_emac_adjust_link(struct net_device *ndev)if (priv->speed != phy_dev->speed) { priv->speed = phy_dev->speed; state_changed =1 ; +if (priv->set_mac_speed) + priv->set_mac_speed (priv, priv->speed); }if (priv->duplex != phy_dev->duplex) {(quoted diff) +0
-0
b/drivers/net/ethernet/arc/emac_rockchip.cnew file mode 100644 index 0000000..51d0585drivers/net/ethernet/arc/emac_rockchip.c new file +81
-0@@ -0,0 +1,228 @@ +/** +* emac-rockchip.c - Rockchip EMAC specific glue layer +* +* Copyright (C) 2014 Romain Perier <[email protected]> +* +* 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. +*/ + +#include <linux/etherdevice.h> +#include <linux/mfd/syscon.h> +#include <linux/module.h> +#include <linux/of_net.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/regulator/consumer.h> + +#include "emac.h" + +#define DRV_NAME "rockchip_emac" +#define DRV_VERSION "1.0" + +#define GRF_MODE_MII (1UL << 0) +#define GRF_MODE_RMII (0UL << 0) +#define GRF_SPEED_10M (0UL << 1) +#define GRF_SPEED_100M (1UL << 1) +#define GRF_SPEED_ENABLE_BIT (1UL << 17) +#define GRF_MODE_ENABLE_BIT (1UL << 16) + +struct emac_rockchip_soc_data { +int grf_offset; +}; + +struct rockchip_priv_data { +struct arc_emac_priv emac; +struct regmap *grf; +const struct emac_rockchip_soc_data *soc_data; +struct regulator *regulator; +struct clk *refclk; +}; + +static void emac_rockchip_set_mac_speed (void *priv,unsigned int speed) +{ +struct rockchip_priv_data *emac = priv; +u32 data; +int err =0 ; + +/* write-enable bits */ + data =GRF_SPEED_ENABLE_BIT ; + +switch (speed) { +case 10 : + data |=GRF_SPEED_10M ; +break ; +case 100 : + data |=GRF_SPEED_100M ; +break ; +default : +pr_err ("speed %u not supported\n" , speed); +return ; + } + + err =regmap_write (emac->grf, emac->soc_data->grf_offset, data); +if (err) +pr_err ("unable to apply speed %u to grf (%d)\n" , speed, err); +} + +static const struct emac_rockchip_soc_data emac_rockchip_dt_data[] = { + { .grf_offset =0x154 },/* rk3066 */ + { .grf_offset =0x0a4 },/* rk3188 */ +}; + +static const struct of_device_id emac_rockchip_dt_ids[] = { + { .compatible ="rockchip,rk3066-emac" , .data = &emac_rockchip_dt_data[0 ]}, + { .compatible = "rockchip,rk3188-emac", .data =
&emac_rockchip_dt_data[1] }, + { /* Sentinel */ }drivers/net/ethernet/arc/emac_rockchip.c new file +39
-0+}; + +MODULE_DEVICE_TABLE (of, emac_rockchip_dt_ids); + +static int emac_rockchip_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct net_device *ndev; +struct rockchip_priv_data *priv; +const struct of_device_id *match; +u32 data; +int err, interface; + +if (!pdev->dev.of_node) +return -ENODEV ; + + ndev =alloc_etherdev (sizeof (struct rockchip_priv_data )); +if (!ndev) +return -ENOMEM ; +platform_set_drvdata (pdev, ndev); +SET_NETDEV_DEV (ndev, dev); + + priv =netdev_priv (ndev); + priv->emac.drv_name =DRV_NAME ; + priv->emac.drv_version =DRV_VERSION ; + priv->emac.set_mac_speed = emac_rockchip_set_mac_speed; + + interface =of_get_phy_mode (dev->of_node); + +/* RK3066 and RK3188 SoCs only support RMII */ +if (interface !=PHY_INTERFACE_MODE_RMII ) { +dev_err (dev,"unsupported phy interface mode %d\n" , interface); + err = -ENOTSUPP ; + goto out_netdev; + } + + priv->grf =syscon_regmap_lookup_by_phandle (dev->of_node,"rockchip,grf" ); +if (IS_ERR (priv->grf)) { + dev_err(dev, "failed to retrieve global register file (%ld)\n",
PTR_ERR(priv->grf)); + err =PTR_ERR(priv->grf);drivers/net/ethernet/arc/emac_rockchip.c new file +9
-0+ goto out_netdev; + } + + match =of_match_node (emac_rockchip_dt_ids, dev->of_node); + priv->soc_data = match->data; + + priv->emac.clk =devm_clk_get (dev,"hclk" ); +if (IS_ERR (priv->emac.clk)) { + dev_err(dev, "failed to retrieve host clock (%ld)\n",
PTR_ERR(priv->emac.clk)); + err =PTR_ERR(priv->emac.clk);drivers/net/ethernet/arc/emac_rockchip.c new file +6
-0+ goto out_netdev; + } + + priv->refclk =devm_clk_get (dev,"macref" ); +if (IS_ERR (priv->refclk)) { + dev_err(dev, "failed to retrieve reference clock (%ld)\n",
PTR_ERR(priv->refclk)); + err =PTR_ERR(priv->refclk);drivers/net/ethernet/arc/emac_rockchip.c new file +88
-0+ goto out_netdev; + } + + err =clk_prepare_enable (priv->refclk); +if (err) { +dev_err (dev,"failed to enable reference clock (%d)\n" , err); + goto out_netdev; + } + +/* Optional regulator for PHY */ + priv->regulator =devm_regulator_get_optional (dev,"phy" ); +if (IS_ERR (priv->regulator)) { +if (PTR_ERR (priv->regulator) == -EPROBE_DEFER ) +return -EPROBE_DEFER ; +dev_err (dev,"no regulator found\n" ); + priv->regulator =NULL ; + } + +if (priv->regulator) { + err =regulator_enable (priv->regulator); +if (err) { +dev_err (dev,"failed to enable phy-supply (%d)\n" , err); + goto out_clk_disable; + } + } + + err =arc_emac_probe (ndev, interface); +if (err) + goto out_regulator_disable; + +/* write-enable bits */ + data =GRF_MODE_ENABLE_BIT |GRF_SPEED_ENABLE_BIT ; + + data |=GRF_SPEED_100M ; + data |=GRF_MODE_RMII ; + + err =regmap_write (priv->grf, priv->soc_data->grf_offset, data); +if (err) { +dev_err (dev,"unable to apply initial settings to grf (%d)\n" , err); + goto out_regulator_disable; + } + +/* RMII interface needs always a rate of 50MHz */ + err =clk_set_rate (priv->refclk,50000000 ); +if (err) +dev_err (dev,"failed to change reference clock rate (%d)\n" , err); +return 0 ; + +out_regulator_disable: +if (priv->regulator) +regulator_disable (priv->regulator); +out_clk_disable: +clk_disable_unprepare (priv->refclk); +out_netdev: +free_netdev (ndev); +return err; +} + +static int emac_rockchip_remove (struct platform_device *pdev) +{ +struct net_device *ndev =platform_get_drvdata (pdev); +struct rockchip_priv_data *priv =netdev_priv (ndev); +int err; + +clk_disable_unprepare (priv->refclk); + +if (priv->regulator) +regulator_disable (priv->regulator); + + err =arc_emac_remove (ndev); +free_netdev (ndev); +return err; +} + +static struct platform_driver emac_rockchip_driver = { + .probe = emac_rockchip_probe, + .remove = emac_rockchip_remove, + .driver = { + .name =DRV_NAME , + .of_match_table = emac_rockchip_dt_ids, + }, +}; + +module_platform_driver (emac_rockchip_driver); + +MODULE_AUTHOR ("Romain Perier <[email protected]>" ); +MODULE_DESCRIPTION ("Rockchip EMAC platform driver" ); +MODULE_LICENSE ("GPL" );
David Miller
maintainerFrom: Romain Perier <[email protected]>
Date: Wed, 3 Sep 2014 16:52:42 +0000
Quoted 6 lines
This patch defines a platform glue layer for Rockchip SoCs which support arc-emac driver. It ensures that regulator for the rmii is on before trying to connect to the ethernet controller. It applies right speed and mode changes to the grf when ethernet settings change.
Signed-off-by Romain Perier <[email protected]>
You'll need to resubmit this series with the Kconfig warnings fixed.