2014-04-25 14:07:34

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 00/18] USB support for Armada 38x and Armada 375

Hello,

This patch set adds the USB support for the Armada 38x Armada
375. These SoCs use an xHCI but still need specific initialization,
mainly to setup the windows memory on the mbus. They also use the same
controller that the other mvebu SoC for EHCI.

Since the 1st version this patch set add xHCI support for Armada 375
but also EHCI support for Armada 375 and Armada 38x. For EHCI it was
mainly a matter of updating the device tree.

The first patch is just a small clean-up

The second patch extend the xhci-plat driver to allow to use the
clocks if they are available.

The third patch add support the Armada 38x by introducing a quirk to
setup the memory windows on the mbus for Armada 38x.

Then the forth patch update the binding documentation.

The 10th patch add support for the Armada 375 using what have been
done for Armada 38x

The 11th patch update the binding documentation with Armada 375 binding.

This patches 1 to 4 and 10 to 11 should go through the xhci subsystem.

The rest of the series is more platform specific and should go through
the mvebu tree, except the patch 9 that should be taken directly by
the arm-soc maintainer.

Thanks,

Gregory CLEMENT (18):
usb: host: xhci-plat: Sort the headers in alphabetic order
usb: host: xhci-plat: Add clocks support
usb: host: xhci-plat: Add support for the Armada 38x
xhci-platform: Add a new controller using xhci: Armada 38x
ARM: mvebu: Add Device Tree description of xHCI hosts on Armada 38x
ARM: mvebu: Add Device Tree description of EHCI hosts on Armada 38x
ARM: mvebu: Add USB3 support for Armada 38x
ARM: configs: Add usb_xhci_mvebu to mvebu_v7_defconfig
ARM: configs: Add usb_xhci_mvebu to multi_v7_defconfig
usb: host: xhci-plat: Add support for the Armada 375
xhci-platform: Add a new controller using xhci: Armada 375
ARM: mvebu: Add Device Tree description of USB cluster controller on
Armada 375
dt: binding: Armada 375 USB cluster
ARM: mvebu: Add support for USB cluster on the Armada 375 SoC
ARM: mvebu: Add USB3 support for Armada 375
ARM: mvebu: add USB3 controller Device Tree details for Armada 375
ARM: mvebu: dts: Enable USB3 in Armada 375 DB
ARM: mvebu: Add Device Tree description of EHCI hosts on Armada 375

.../bindings/arm/armada-375-usb-cluster.txt | 17 ++++
Documentation/devicetree/bindings/usb/usb-xhci.txt | 4 +-
arch/arm/boot/dts/armada-375-db.dts | 10 ++-
arch/arm/boot/dts/armada-375.dtsi | 41 +++++++++
arch/arm/boot/dts/armada-385-db.dts | 12 +++
arch/arm/boot/dts/armada-385-rd.dts | 4 +
arch/arm/boot/dts/armada-38x.dtsi | 25 ++++++
arch/arm/configs/multi_v7_defconfig | 1 +
arch/arm/configs/mvebu_v7_defconfig | 1 +
arch/arm/mach-mvebu/Kconfig | 2 +
arch/arm/mach-mvebu/Makefile | 2 +-
arch/arm/mach-mvebu/usb-cluster.c | 96 ++++++++++++++++++++++
drivers/usb/host/Kconfig | 7 ++
drivers/usb/host/Makefile | 1 +
drivers/usb/host/xhci-mvebu.c | 71 ++++++++++++++++
drivers/usb/host/xhci-mvebu.h | 22 +++++
drivers/usb/host/xhci-plat.c | 67 +++++++++++++--
17 files changed, 374 insertions(+), 9 deletions(-)
create mode 100644 Documentation/devicetree/bindings/arm/armada-375-usb-cluster.txt
create mode 100644 arch/arm/mach-mvebu/usb-cluster.c
create mode 100644 drivers/usb/host/xhci-mvebu.c
create mode 100644 drivers/usb/host/xhci-mvebu.h

--
1.8.1.2


2014-04-25 14:07:43

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 06/18] ARM: mvebu: Add Device Tree description of EHCI hosts on Armada 38x

The Marvell Armada 38x SoCs contain one EHCI host. This commit adds
the Device Tree description of this interface at the SoC level, and
also enables the USB2 port on the Armada 385 DB platform.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
arch/arm/boot/dts/armada-385-db.dts | 4 ++++
arch/arm/boot/dts/armada-38x.dtsi | 8 ++++++++
2 files changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/armada-385-db.dts b/arch/arm/boot/dts/armada-385-db.dts
index d5db1466da82..91e3e449067f 100644
--- a/arch/arm/boot/dts/armada-385-db.dts
+++ b/arch/arm/boot/dts/armada-385-db.dts
@@ -65,6 +65,10 @@
phy-mode = "rgmii-id";
};

+ usb@50000 {
+ status = "ok";
+ };
+
ethernet@70000 {
status = "okay";
phy = <&phy0>;
diff --git a/arch/arm/boot/dts/armada-38x.dtsi b/arch/arm/boot/dts/armada-38x.dtsi
index 5913ce1cc601..11f1f9e28cbc 100644
--- a/arch/arm/boot/dts/armada-38x.dtsi
+++ b/arch/arm/boot/dts/armada-38x.dtsi
@@ -283,6 +283,14 @@
status = "disabled";
};

+ usb@50000 {
+ compatible = "marvell,orion-ehci";
+ reg = <0x58000 0x500>;
+ interrupts = <GIC_SPI 18 IRQ_TYPE_LEVEL_HIGH>;
+ clocks = <&gateclk 18>;
+ status = "disabled";
+ };
+
xor@60800 {
compatible = "marvell,orion-xor";
reg = <0x60800 0x100
--
1.8.1.2

2014-04-25 14:07:48

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 11/18] xhci-platform: Add a new controller using xhci: Armada 375

Extend the compatible string list with armada-375-xhci. It is used to
describe xhci controller which is in the Armada 375 SoC.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
Documentation/devicetree/bindings/usb/usb-xhci.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/usb-xhci.txt b/Documentation/devicetree/bindings/usb/usb-xhci.txt
index cbc91414fd59..87d150ca58cc 100644
--- a/Documentation/devicetree/bindings/usb/usb-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/usb-xhci.txt
@@ -2,7 +2,8 @@ USB xHCI controllers

Required properties:
- compatible: should be on of "generic-xhci",
- "marvell,armada-380-xhci" (deprecated: "xhci-platform").
+ "marvell,armada-375-xhci", "marvell,armada-380-xhci" (deprecated:
+ "xhci-platform").
- reg: should contain address and length of the standard XHCI
register set for the device.
- interrupts: one XHCI interrupt should be described here.
--
1.8.1.2

2014-04-25 14:07:53

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 14/18] ARM: mvebu: Add support for USB cluster on the Armada 375 SoC

The Armada 375 SoC comes with an USB2 host and device controller and
an USB3 controller. The USB cluster control register allows to manage
common features of both USB controllers.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
arch/arm/mach-mvebu/Makefile | 2 +-
arch/arm/mach-mvebu/usb-cluster.c | 96 +++++++++++++++++++++++++++++++++++++++
2 files changed, 97 insertions(+), 1 deletion(-)
create mode 100644 arch/arm/mach-mvebu/usb-cluster.c

diff --git a/arch/arm/mach-mvebu/Makefile b/arch/arm/mach-mvebu/Makefile
index a63e43b6b451..dec05e7e1802 100644
--- a/arch/arm/mach-mvebu/Makefile
+++ b/arch/arm/mach-mvebu/Makefile
@@ -4,7 +4,7 @@ ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \
AFLAGS_coherency_ll.o := -Wa,-march=armv7-a

obj-y += system-controller.o mvebu-soc-id.o
-obj-$(CONFIG_MACH_MVEBU_V7) += board-v7.o
+obj-$(CONFIG_MACH_MVEBU_V7) += board-v7.o usb-cluster.o
obj-$(CONFIG_MACH_DOVE) += dove.o
obj-$(CONFIG_ARCH_MVEBU) += coherency.o coherency_ll.o pmsu.o
obj-$(CONFIG_SMP) += platsmp.o headsmp.o
diff --git a/arch/arm/mach-mvebu/usb-cluster.c b/arch/arm/mach-mvebu/usb-cluster.c
new file mode 100644
index 000000000000..4c15d282db23
--- /dev/null
+++ b/arch/arm/mach-mvebu/usb-cluster.c
@@ -0,0 +1,96 @@
+/*
+ * USB cluster support for Armada 375 platform.
+ *
+ * Copyright (C) 2014 Marvell
+ *
+ * Gregory CLEMENT <[email protected]>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ *
+ * Armada 375 comes with an USB2 host and device controller and an
+ * USB3 controller. The USB cluster control register allows to manage
+ * common features of both USB controller.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/of_address.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+
+#define USB2_PHY_CONFIG_ENABLE BIT(0) /* active low */
+
+static struct of_device_id of_usb_cluster_table[] = {
+ { .compatible = "marvell,armada-375-usb-cluster", },
+ { /* end of list */ },
+};
+
+static int __init mvebu_usb_cluster_init(void)
+{
+ struct device_node *np;
+
+ np = of_find_matching_node(NULL, of_usb_cluster_table);
+ if (np) {
+ void __iomem *usb_cluster_base;
+ u32 reg;
+ struct device_node *ehci_node, *xhci_node;
+ struct property *ehci_status;
+ bool use_usb3 = false;
+
+ usb_cluster_base = of_iomap(np, 0);
+ BUG_ON(!usb_cluster_base);
+
+ xhci_node = of_find_compatible_node(NULL, NULL,
+ "marvell,armada-375-xhci");
+
+ if (xhci_node && of_device_is_available(xhci_node))
+ use_usb3 = true;
+
+ ehci_node = of_find_compatible_node(NULL, NULL,
+ "marvell,orion-ehci");
+
+ if (ehci_node && of_device_is_available(ehci_node)
+ && use_usb3) {
+ /*
+ * We can't use usb2 and usb3 in the same time, so let's
+ * disbale usb2 and complain about it to the user askinf
+ * to fix the device tree.
+ */
+
+ ehci_status = kzalloc(sizeof(struct property),
+ GFP_KERNEL);
+ WARN_ON(!ehci_status);
+
+ ehci_status->value = kstrdup("disabled", GFP_KERNEL);
+ WARN_ON(!ehci_status->value);
+
+ ehci_status->length = 8;
+ ehci_status->name = kstrdup("status", GFP_KERNEL);
+ WARN_ON(!ehci_status->name);
+
+ of_update_property(ehci_node, ehci_status);
+ pr_err("%s: armada-375-xhci and orion-ehci are incompatible for this SoC.\n",
+ __func__);
+ pr_err("Please fix your dts!\n");
+ pr_err("orion-ehci have been disabled by default...\n");
+
+ }
+
+ reg = readl(usb_cluster_base);
+ if (use_usb3)
+ reg |= USB2_PHY_CONFIG_ENABLE;
+ else
+ reg &= ~USB2_PHY_CONFIG_ENABLE;
+ writel(reg, usb_cluster_base);
+
+ of_node_put(ehci_node);
+ of_node_put(xhci_node);
+ of_node_put(np);
+ iounmap(usb_cluster_base);
+ }
+
+ return 0;
+}
+postcore_initcall(mvebu_usb_cluster_init);
--
1.8.1.2

2014-04-25 14:08:22

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 18/18] ARM: mvebu: Add Device Tree description of EHCI hosts on Armada 375

The Marvell Armada 375 SoC contains one EHCI host. This commit adds
the Device Tree description of this interface at the SoC level.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
arch/arm/boot/dts/armada-375.dtsi | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/arch/arm/boot/dts/armada-375.dtsi b/arch/arm/boot/dts/armada-375.dtsi
index cbe64ba9eb65..349b9635bf3a 100644
--- a/arch/arm/boot/dts/armada-375.dtsi
+++ b/arch/arm/boot/dts/armada-375.dtsi
@@ -320,6 +320,24 @@
clocks = <&coreclk 0>;
};

+ /*
+ * On Armada 375, USB2 host controller and
+ * USB3 host controller are incompatible. That
+ * means that in the dts of your board, you
+ * can either select the USB2 controller:
+ * marvell,orion-ehci or the USB3 controller:
+ * marvell,armada-375-xhci, but not both. If
+ * both controllers are selected, then the
+ * kernel will select the USB3 by default.
+ */
+ usb@50000 {
+ compatible = "marvell,orion-ehci";
+ reg = <0x50000 0x500>;
+ interrupts = <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
+ clocks = <&gateclk 18>;
+ status = "disabled";
+ };
+
usb-cluster@18400 {
compatible = "marvell,armada-375-usb-cluster";
reg = <0x18400 0x4>;
--
1.8.1.2

2014-04-25 14:09:33

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 17/18] ARM: mvebu: dts: Enable USB3 in Armada 375 DB

In order to enable the USB3 host controller on the Armada 375 DB
platform, we need to create a ranges at the soc node level to describe
the special static window for USB3.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
arch/arm/boot/dts/armada-375-db.dts | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/armada-375-db.dts b/arch/arm/boot/dts/armada-375-db.dts
index 9378d3136b41..928de536a0ff 100644
--- a/arch/arm/boot/dts/armada-375-db.dts
+++ b/arch/arm/boot/dts/armada-375-db.dts
@@ -30,8 +30,9 @@
};

soc {
- ranges = <MBUS_ID(0xf0, 0x01) 0 0xf1000000 0x100000
- MBUS_ID(0x01, 0x1d) 0 0xfff00000 0x100000>;
+ ranges = <MBUS_ID(0xf0, 0x01) 0 0xf1000000 0x100000 /* internal regs */
+ MBUS_ID(0x05, 0x00) 0 0xff100000 0x20000 /* USB3 XHCI */
+ MBUS_ID(0x01, 0x1d) 0 0xfff00000 0x100000 /* bootrom */>;

internal-regs {
spi@10600 {
@@ -126,5 +127,10 @@
status = "okay";
};
};
+
+ usb3-controller {
+ status = "okay";
+ };
+
};
};
--
1.8.1.2

2014-04-25 14:10:23

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 15/18] ARM: mvebu: Add USB3 support for Armada 375

This patch add the selection of the config symbol to build the USB3
support for Armada 375.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
arch/arm/mach-mvebu/Kconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
index 7960f218702b..95afc7677ee1 100644
--- a/arch/arm/mach-mvebu/Kconfig
+++ b/arch/arm/mach-mvebu/Kconfig
@@ -41,6 +41,7 @@ config MACH_ARMADA_375
select CPU_V7
select MACH_MVEBU_V7
select PINCTRL_ARMADA_375
+ select USB_ARCH_HAS_XHCI
help
Say 'Y' here if you want your kernel to support boards based
on the Marvell Armada 375 SoC with device tree.
--
1.8.1.2

2014-04-25 14:10:22

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 16/18] ARM: mvebu: add USB3 controller Device Tree details for Armada 375

This commit adds the support for the USB3 controller in the Armada 375
SoC. The following things have been taken in consideration:

- The usb3-controller node has to be *outside* of the internal-regs{}
node, because this device needs to access special windows.

- The usb3-controller node has one ranges to describe the special
window to be created but it must be done at the board level in the
dts.

- The usb3-controller node has two entries in the reg property, the
first for XHCI, the second for the internal registers

Signed-off-by: Gregory CLEMENT <[email protected]>
---
arch/arm/boot/dts/armada-375.dtsi | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/arch/arm/boot/dts/armada-375.dtsi b/arch/arm/boot/dts/armada-375.dtsi
index 0e0036800071..cbe64ba9eb65 100644
--- a/arch/arm/boot/dts/armada-375.dtsi
+++ b/arch/arm/boot/dts/armada-375.dtsi
@@ -465,5 +465,23 @@
};

};
+
+ /*
+ * On Armada 375, USB2 host controller and USB3 host
+ * controller are incompatible. That means that in the
+ * dts of your board, you can either select the USB2
+ * controller: marvell,orion-ehci or the USB3
+ * controller: marvell,armada-375-xhci, but not
+ * both. If both controllers are selected, then the
+ * kernel will select the USB3 by default.
+ */
+ usb3-controller {
+ compatible = "marvell,armada-375-xhci";
+ reg = <MBUS_ID(0x05, 0x00) 0 0x20000>,
+ <MBUS_ID(0xf0, 0x01) 0x5ff80 0x80>;
+ interrupts = <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>;
+ clocks = <&gateclk 16>;
+ status = "disabled";
+ };
};
};
--
1.8.1.2

2014-04-25 14:12:09

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 13/18] dt: binding: Armada 375 USB cluster

Armada 375 comes with an USB2 host and device controller and an USB3
controller. The USB cluster control register allows to manage common
features of both USB controllers.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
.../devicetree/bindings/arm/armada-375-usb-cluster.txt | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
create mode 100644 Documentation/devicetree/bindings/arm/armada-375-usb-cluster.txt

diff --git a/Documentation/devicetree/bindings/arm/armada-375-usb-cluster.txt b/Documentation/devicetree/bindings/arm/armada-375-usb-cluster.txt
new file mode 100644
index 000000000000..71feb8fb4434
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/armada-375-usb-cluster.txt
@@ -0,0 +1,17 @@
+Armada 375 USB cluster
+----------------------
+
+Armada 375 comes with an USB2 host and device controller and an USB3
+controller. The USB cluster control register allows to manage common
+features of both USB controllers.
+
+Required properties:
+
+- compatible: "marvell,armada-375-usb-cluster"
+- reg: Should contain usb cluster register location and length.
+
+Example:
+ usb-cluster@18400 {
+ compatible = "marvell,armada-375-usb-cluster";
+ reg = <0x18400 0x4>;
+ };
--
1.8.1.2

2014-04-25 14:12:54

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 12/18] ARM: mvebu: Add Device Tree description of USB cluster controller on Armada 375

On Armada 375, the USB cluster allows to control the cluster composed
of the USB2 and USB3 host controllers.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
arch/arm/boot/dts/armada-375.dtsi | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/arch/arm/boot/dts/armada-375.dtsi b/arch/arm/boot/dts/armada-375.dtsi
index 3877693fb2d8..0e0036800071 100644
--- a/arch/arm/boot/dts/armada-375.dtsi
+++ b/arch/arm/boot/dts/armada-375.dtsi
@@ -320,6 +320,11 @@
clocks = <&coreclk 0>;
};

+ usb-cluster@18400 {
+ compatible = "marvell,armada-375-usb-cluster";
+ reg = <0x18400 0x4>;
+ };
+
xor@60800 {
compatible = "marvell,orion-xor";
reg = <0x60800 0x100
--
1.8.1.2

2014-04-25 14:13:32

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 10/18] usb: host: xhci-plat: Add support for the Armada 375

For the Armada 375 SoC which comes with an xhci controller. Currently
the quirk is the same that the Armada 380/385 one, but by introducing
a new compatible string it will allow to make the driver evolve
seamless.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
drivers/usb/host/xhci-plat.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index c0e835b49e0d..679b21f30458 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -152,6 +152,9 @@ static int xhci_plat_probe(struct platform_device *pdev)
if (of_device_is_compatible(pdev->dev.of_node, "marvell,armada-380-xhci"))
xhci_mvebu_mbus_init_quirk(pdev);

+ if (of_device_is_compatible(pdev->dev.of_node, "marvell,armada-375-xhci"))
+ xhci_mvebu_mbus_init_quirk(pdev);
+
/* Initialize dma_mask and coherent_dma_mask to 32-bits */
ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
if (ret)
@@ -284,6 +287,7 @@ static const struct of_device_id usb_xhci_of_match[] = {
{ .compatible = "generic-xhci" },
{ .compatible = "xhci-platform" },
{ .compatible = "marvell,armada-380-xhci"},
+ { .compatible = "marvell,armada-375-xhci"},
{ },
};
MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
--
1.8.1.2

2014-04-25 14:14:54

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 09/18] ARM: configs: Add usb_xhci_mvebu to multi_v7_defconfig

The Marvell Armada 38x platform needs the xhci_mvebu driver enabled
for the xHCI USB hosts, so this commit enables the corresponding
Kconfig option in multi_v7_defconfig.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
arch/arm/configs/multi_v7_defconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig
index d4e8a47a2f7c..820cc35d40cf 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -254,6 +254,7 @@ CONFIG_SND_SOC_TEGRA_ALC5632=y
CONFIG_SND_SOC_TEGRA_MAX98090=y
CONFIG_USB=y
CONFIG_USB_XHCI_HCD=y
+CONFIG_USB_XHCI_MVEBU=y
CONFIG_USB_EHCI_HCD=y
CONFIG_USB_EHCI_TEGRA=y
CONFIG_USB_EHCI_HCD_PLATFORM=y
--
1.8.1.2

2014-04-25 14:15:26

by Thomas Petazzoni

[permalink] [raw]
Subject: Re: [PATCH v2 02/18] usb: host: xhci-plat: Add clocks support

Dear Gregory CLEMENT,

On Fri, 25 Apr 2014 16:07:00 +0200, Gregory CLEMENT wrote:
> Some platform (such as the Armada 38x ones) can gate the clock of
> their USB controller. This patch add the support for the clock, by
> enabling them during probe and disabling them on remove.
>
> As not all platforms have clock support then enabling and disabling
> the clocks have been placed in separate functions. Then if the clocks
> are not supported we still can use the same calls, and there is no
>
> Signed-off-by: Gregory CLEMENT <[email protected]>
> ---
> drivers/usb/host/xhci-plat.c | 52 ++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 50 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index f5351af4b2c5..bb5d563f729c 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -11,6 +11,7 @@
> * version 2 as published by the Free Software Foundation.
> */
>
> +#include <linux/clk.h>
> #include <linux/dma-mapping.h>
> #include <linux/module.h>
> #include <linux/of.h>
> @@ -85,6 +86,42 @@ static const struct hc_driver xhci_plat_xhci_driver = {
> .bus_resume = xhci_bus_resume,
> };
>
> +#if defined(CONFIG_HAVE_CLK)
> +static int try_enable_clk(struct platform_device *pdev)
> +{
> + struct clk *clk = devm_clk_get(&pdev->dev, NULL);
> +
> + /* Not all platforms have a clk so it is not an error if the clock
> + does not exists. */
> + if (!IS_ERR(clk))

Instead, do:

if (IS_ERR(clk))
return 0;

return clk_prepare_enable(clk);

> + if (clk_prepare_enable(clk))
> + return -ENODEV;
> + return 0;
> +}
> +
> +static int try_disable_clk(struct platform_device *pdev)
> +{
> + struct clk *clk = devm_clk_get(&pdev->dev, NULL);

No, this isn't correct: you shouldn't be getting the clock to
disable/unprepare it, otherwise you have an unbalanced number of
get()/put() calls on the clocks.

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

2014-04-25 14:07:38

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 02/18] usb: host: xhci-plat: Add clocks support

Some platform (such as the Armada 38x ones) can gate the clock of
their USB controller. This patch add the support for the clock, by
enabling them during probe and disabling them on remove.

As not all platforms have clock support then enabling and disabling
the clocks have been placed in separate functions. Then if the clocks
are not supported we still can use the same calls, and there is no

Signed-off-by: Gregory CLEMENT <[email protected]>
---
drivers/usb/host/xhci-plat.c | 52 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index f5351af4b2c5..bb5d563f729c 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -11,6 +11,7 @@
* version 2 as published by the Free Software Foundation.
*/

+#include <linux/clk.h>
#include <linux/dma-mapping.h>
#include <linux/module.h>
#include <linux/of.h>
@@ -85,6 +86,42 @@ static const struct hc_driver xhci_plat_xhci_driver = {
.bus_resume = xhci_bus_resume,
};

+#if defined(CONFIG_HAVE_CLK)
+static int try_enable_clk(struct platform_device *pdev)
+{
+ struct clk *clk = devm_clk_get(&pdev->dev, NULL);
+
+ /* Not all platforms have a clk so it is not an error if the clock
+ does not exists. */
+ if (!IS_ERR(clk))
+ if (clk_prepare_enable(clk))
+ return -ENODEV;
+ return 0;
+}
+
+static int try_disable_clk(struct platform_device *pdev)
+{
+ struct clk *clk = devm_clk_get(&pdev->dev, NULL);
+
+ /* Not all platforms have a clk so it is not an error if the clock
+ does not exists. */
+ if (!IS_ERR(clk))
+ clk_disable_unprepare(clk);
+
+ return 0;
+}
+#else
+static inline int try_enable_clk(struct platform_device *pdev)
+{
+ return 0;
+}
+
+static inline int try_disable_clk(struct platform_device *pdev)
+{
+ return 0;
+}
+#endif
+
static int xhci_plat_probe(struct platform_device *pdev)
{
const struct hc_driver *driver;
@@ -107,6 +144,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
if (!res)
return -ENODEV;

+ ret = try_enable_clk(pdev);
+ if (ret)
+ return ret;
+
/* Initialize dma_mask and coherent_dma_mask to 32-bits */
ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
if (ret)
@@ -117,8 +158,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));

hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
- if (!hcd)
- return -ENOMEM;
+ if (!hcd) {
+ ret = -ENOMEM;
+ goto disable_clk;
+ }

hcd->rsrc_start = res->start;
hcd->rsrc_len = resource_size(res);
@@ -182,6 +225,9 @@ release_mem_region:
put_hcd:
usb_put_hcd(hcd);

+disable_clk:
+ try_disable_clk(pdev);
+
return ret;
}

@@ -199,6 +245,8 @@ static int xhci_plat_remove(struct platform_device *dev)
usb_put_hcd(hcd);
kfree(xhci);

+ try_disable_clk(dev);
+
return 0;
}

--
1.8.1.2

2014-04-25 14:16:17

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 07/18] ARM: mvebu: Add USB3 support for Armada 38x

This patch add the selection of the config symbol to build the USB3
support for Armada 38x.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
arch/arm/mach-mvebu/Kconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
index 3f73eecbcfb0..7960f218702b 100644
--- a/arch/arm/mach-mvebu/Kconfig
+++ b/arch/arm/mach-mvebu/Kconfig
@@ -54,6 +54,7 @@ config MACH_ARMADA_38X
select CPU_V7
select MACH_MVEBU_V7
select PINCTRL_ARMADA_38X
+ select USB_ARCH_HAS_XHCI
help
Say 'Y' here if you want your kernel to support boards based
on the Marvell Armada 380/385 SoC with device tree.
--
1.8.1.2

2014-04-25 14:16:14

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 08/18] ARM: configs: Add usb_xhci_mvebu to mvebu_v7_defconfig

The Marvell Armada 38x platform needs the xhci_mvebu driver enabled
for the xHCI USB hosts, so this commit enables the corresponding
Kconfig option in mvebu_v7_defconfig.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
arch/arm/configs/mvebu_v7_defconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/mvebu_v7_defconfig b/arch/arm/configs/mvebu_v7_defconfig
index a34713d8db9f..e8811066b8e4 100644
--- a/arch/arm/configs/mvebu_v7_defconfig
+++ b/arch/arm/configs/mvebu_v7_defconfig
@@ -78,6 +78,7 @@ CONFIG_USB_EHCI_HCD=y
CONFIG_USB_EHCI_ROOT_HUB_TT=y
CONFIG_USB_STORAGE=y
CONFIG_USB_XHCI_HCD=y
+CONFIG_USB_XHCI_MVEBU=y
CONFIG_MMC=y
CONFIG_MMC_MVSDIO=y
CONFIG_NEW_LEDS=y
--
1.8.1.2

2014-04-25 14:18:21

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 05/18] ARM: mvebu: Add Device Tree description of xHCI hosts on Armada 38x

The Marvell Armada 38x SoCs contain two xHCI host. This commit adds
the Device Tree description of those interfaces at the SoC level, and
also enables the two USB3 ports on the Armada 385 DB platform and one
USB3 port on the Armada 385 RD platforms.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
arch/arm/boot/dts/armada-385-db.dts | 8 ++++++++
arch/arm/boot/dts/armada-385-rd.dts | 4 ++++
arch/arm/boot/dts/armada-38x.dtsi | 17 +++++++++++++++++
3 files changed, 29 insertions(+)

diff --git a/arch/arm/boot/dts/armada-385-db.dts b/arch/arm/boot/dts/armada-385-db.dts
index 6828d77696a6..d5db1466da82 100644
--- a/arch/arm/boot/dts/armada-385-db.dts
+++ b/arch/arm/boot/dts/armada-385-db.dts
@@ -101,6 +101,14 @@
reg = <0x1000000 0x3f000000>;
};
};
+
+ usb3@f0000 {
+ status = "okay";
+ };
+
+ usb3@f8000 {
+ status = "okay";
+ };
};

pcie-controller {
diff --git a/arch/arm/boot/dts/armada-385-rd.dts b/arch/arm/boot/dts/armada-385-rd.dts
index 45250c88814b..a505fe94ff37 100644
--- a/arch/arm/boot/dts/armada-385-rd.dts
+++ b/arch/arm/boot/dts/armada-385-rd.dts
@@ -77,6 +77,10 @@
reg = <1>;
};
};
+
+ usb3@f0000 {
+ status = "okay";
+ };
};

pcie-controller {
diff --git a/arch/arm/boot/dts/armada-38x.dtsi b/arch/arm/boot/dts/armada-38x.dtsi
index a064f59da02d..5913ce1cc601 100644
--- a/arch/arm/boot/dts/armada-38x.dtsi
+++ b/arch/arm/boot/dts/armada-38x.dtsi
@@ -355,6 +355,23 @@
clocks = <&coredivclk 0>;
status = "disabled";
};
+
+ usb3@f0000 {
+ compatible = "marvell,armada-380-xhci";
+ reg = <0xf0000 0x3fff>,<0xf4000 0x3fff>;
+ interrupts = <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>;
+ clocks = <&gateclk 9>;
+ status = "disabled";
+ };
+
+ usb3@f8000 {
+ compatible = "marvell,armada-380-xhci";
+ reg = <0xf8000 0x3fff>,<0xfc000 0x3fff>;
+ interrupts = <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
+ clocks = <&gateclk 10>;
+ status = "disabled";
+ };
+
};
};

--
1.8.1.2

2014-04-25 14:07:37

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 01/18] usb: host: xhci-plat: Sort the headers in alphabetic order

Sorting the headers in alphabetic order will help to reduce the conflict
when adding new headers later.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
drivers/usb/host/xhci-plat.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 151901ce1ba9..f5351af4b2c5 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -11,11 +11,11 @@
* version 2 as published by the Free Software Foundation.
*/

-#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
#include <linux/module.h>
-#include <linux/slab.h>
#include <linux/of.h>
-#include <linux/dma-mapping.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>

#include "xhci.h"

--
1.8.1.2

2014-04-25 14:19:05

by Thomas Petazzoni

[permalink] [raw]
Subject: Re: [PATCH v2 03/18] usb: host: xhci-plat: Add support for the Armada 38x

Dear Gregory CLEMENT,

On Fri, 25 Apr 2014 16:07:01 +0200, Gregory CLEMENT wrote:

> +#define USB3_MAX_WINDOWS 4
> +#define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
> +#define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
> +
> +static void __init mv_usb3_conf_mbus_windows(void __iomem *base,
> + const struct mbus_dram_target_info *dram)

That's a nitpick, but the name of this function looks like it was
copy/pasted from the Marvell LSP, and isn't very consistent with the
other function name. What about:

xhci_mvebu_mbus_config()

instead, or something like that?

> +int xhci_mvebu_mbus_init_quirk(struct platform_device *pdev)

I believe this should give you a warning about section mismatch: you
have a non-init function calling an __init function, no?

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

2014-04-25 14:20:29

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 04/18] xhci-platform: Add a new controller using xhci: Armada 38x

Extend the compatible string list with armada-380-xhci. It is used to
describe xhci controller which is in the Armada 38x SoCs.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
Documentation/devicetree/bindings/usb/usb-xhci.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/usb-xhci.txt b/Documentation/devicetree/bindings/usb/usb-xhci.txt
index 90f8f607d125..cbc91414fd59 100644
--- a/Documentation/devicetree/bindings/usb/usb-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/usb-xhci.txt
@@ -1,7 +1,8 @@
USB xHCI controllers

Required properties:
- - compatible: should be "generic-xhci" (deprecated: "xhci-platform").
+ - compatible: should be on of "generic-xhci",
+ "marvell,armada-380-xhci" (deprecated: "xhci-platform").
- reg: should contain address and length of the standard XHCI
register set for the device.
- interrupts: one XHCI interrupt should be described here.
--
1.8.1.2

2014-04-25 14:20:26

by Gregory CLEMENT

[permalink] [raw]
Subject: [PATCH v2 03/18] usb: host: xhci-plat: Add support for the Armada 38x

For the Armada 38x SoCs which come with an xhci controller, specific
initialization must be done during probe related to the MBus windows
configuration. This patch adds the support of this quirk.

Signed-off-by: Gregory CLEMENT <[email protected]>
---
drivers/usb/host/Kconfig | 7 +++++
drivers/usb/host/Makefile | 1 +
drivers/usb/host/xhci-mvebu.c | 71 +++++++++++++++++++++++++++++++++++++++++++
drivers/usb/host/xhci-mvebu.h | 22 ++++++++++++++
drivers/usb/host/xhci-plat.c | 5 +++
5 files changed, 106 insertions(+)
create mode 100644 drivers/usb/host/xhci-mvebu.c
create mode 100644 drivers/usb/host/xhci-mvebu.h

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 3d9e54062d62..e70943fac4a1 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -29,6 +29,13 @@ if USB_XHCI_HCD
config USB_XHCI_PLATFORM
tristate

+config USB_XHCI_MVEBU
+ tristate "xHCI support for Marvell Armada 38x"
+ select USB_XHCI_PLATFORM
+ ---help---
+ Say 'Y' to enable the support for the xHCI host controller
+ found in Marvell Armada 38x ARM SOCs.
+
endif # USB_XHCI_HCD

config USB_EHCI_HCD
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 7530468c9a4f..7a8db7f7dc01 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -19,6 +19,7 @@ xhci-hcd-$(CONFIG_PCI) += xhci-pci.o

ifneq ($(CONFIG_USB_XHCI_PLATFORM), )
xhci-hcd-y += xhci-plat.o
+ xhci-hcd-$(CONFIG_USB_XHCI_MVEBU) += xhci-mvebu.o
endif

obj-$(CONFIG_USB_WHCI_HCD) += whci/
diff --git a/drivers/usb/host/xhci-mvebu.c b/drivers/usb/host/xhci-mvebu.c
new file mode 100644
index 000000000000..09cf437499fb
--- /dev/null
+++ b/drivers/usb/host/xhci-mvebu.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2014 Marvell
+ * Author: Gregory CLEMENT <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+
+#include <linux/io.h>
+#include <linux/mbus.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+
+#define USB3_MAX_WINDOWS 4
+#define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
+#define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
+
+static void __init mv_usb3_conf_mbus_windows(void __iomem *base,
+ const struct mbus_dram_target_info *dram)
+{
+ int win;
+
+ /* Clear all existing windows */
+ for (win = 0; win < USB3_MAX_WINDOWS; win++) {
+ writel(0, base + USB3_WIN_CTRL(win));
+ writel(0, base + USB3_WIN_BASE(win));
+ }
+
+ /* Program each DRAM CS in a seperate window */
+ for (win = 0; win < dram->num_cs; win++) {
+ const struct mbus_dram_window *cs = dram->cs + win;
+
+ writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
+ (dram->mbus_dram_target_id << 4) | 1,
+ base + USB3_WIN_CTRL(win));
+
+ writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(win));
+ }
+}
+
+int xhci_mvebu_mbus_init_quirk(struct platform_device *pdev)
+{
+ struct resource *res;
+ void __iomem *base;
+ const struct mbus_dram_target_info *dram;
+ int ret = 0;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+ if (!res)
+ return -ENODEV;
+
+ /*
+ * We don't use devm_ioremap() because this mapping should
+ * only exists for the duration of this probe function.
+ */
+ base = ioremap(res->start, resource_size(res));
+ if (!base)
+ return -ENODEV;
+
+ dram = mv_mbus_dram_info();
+ mv_usb3_conf_mbus_windows(base, dram);
+
+ /*
+ * This memory area was only needed to configure the MBus
+ * windows, and is therefore no longer useful.
+ */
+ iounmap(base);
+
+ return ret;
+}
diff --git a/drivers/usb/host/xhci-mvebu.h b/drivers/usb/host/xhci-mvebu.h
new file mode 100644
index 000000000000..5d7e647b3d27
--- /dev/null
+++ b/drivers/usb/host/xhci-mvebu.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2014 Marvell
+ *
+ * Gregory Clement <[email protected]>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __LINUX_XHCI_MVEBU_H
+#define __LINUX_XHCI_MVEBU_H
+
+#ifdef CONFIG_USB_XHCI_MVEBU
+int xhci_mvebu_mbus_init_quirk(struct platform_device *pdev);
+#else
+static inline int xhci_mvebu_mbus_init_quirk(struct device dev)
+{
+ return 0;
+}
+#endif
+#endif /* __LINUX_XHCI_MVEBU_H */
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index bb5d563f729c..c0e835b49e0d 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -19,6 +19,7 @@
#include <linux/slab.h>

#include "xhci.h"
+#include "xhci-mvebu.h"

static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
{
@@ -148,6 +149,9 @@ static int xhci_plat_probe(struct platform_device *pdev)
if (ret)
return ret;

+ if (of_device_is_compatible(pdev->dev.of_node, "marvell,armada-380-xhci"))
+ xhci_mvebu_mbus_init_quirk(pdev);
+
/* Initialize dma_mask and coherent_dma_mask to 32-bits */
ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
if (ret)
@@ -279,6 +283,7 @@ static const struct dev_pm_ops xhci_plat_pm_ops = {
static const struct of_device_id usb_xhci_of_match[] = {
{ .compatible = "generic-xhci" },
{ .compatible = "xhci-platform" },
+ { .compatible = "marvell,armada-380-xhci"},
{ },
};
MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
--
1.8.1.2

2014-04-25 14:21:54

by Russell King - ARM Linux

[permalink] [raw]
Subject: Re: [PATCH v2 02/18] usb: host: xhci-plat: Add clocks support

On Fri, Apr 25, 2014 at 04:07:00PM +0200, Gregory CLEMENT wrote:
> +#if defined(CONFIG_HAVE_CLK)
> +static int try_enable_clk(struct platform_device *pdev)
> +{
> + struct clk *clk = devm_clk_get(&pdev->dev, NULL);
> +
> + /* Not all platforms have a clk so it is not an error if the clock
> + does not exists. */
> + if (!IS_ERR(clk))
> + if (clk_prepare_enable(clk))
> + return -ENODEV;
> + return 0;
> +}
> +
> +static int try_disable_clk(struct platform_device *pdev)
> +{
> + struct clk *clk = devm_clk_get(&pdev->dev, NULL);
> +
> + /* Not all platforms have a clk so it is not an error if the clock
> + does not exists. */
> + if (!IS_ERR(clk))
> + clk_disable_unprepare(clk);
> +
> + return 0;
> +}

OMG.

You do realise that clk_get() ref-counts against the module which
provided the clock, so this is akin to an explicit leaking module
ref-counts.

--
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.

2014-04-25 14:45:05

by Gregory CLEMENT

[permalink] [raw]
Subject: Re: [PATCH v2 02/18] usb: host: xhci-plat: Add clocks support

On 25/04/2014 16:15, Thomas Petazzoni wrote:
> Dear Gregory CLEMENT,
>
> On Fri, 25 Apr 2014 16:07:00 +0200, Gregory CLEMENT wrote:
>> Some platform (such as the Armada 38x ones) can gate the clock of
>> their USB controller. This patch add the support for the clock, by
>> enabling them during probe and disabling them on remove.
>>
>> As not all platforms have clock support then enabling and disabling
>> the clocks have been placed in separate functions. Then if the clocks
>> are not supported we still can use the same calls, and there is no
>>
>> Signed-off-by: Gregory CLEMENT <[email protected]>
>> ---
>> drivers/usb/host/xhci-plat.c | 52 ++++++++++++++++++++++++++++++++++++++++++--
>> 1 file changed, 50 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
>> index f5351af4b2c5..bb5d563f729c 100644
>> --- a/drivers/usb/host/xhci-plat.c
>> +++ b/drivers/usb/host/xhci-plat.c
>> @@ -11,6 +11,7 @@
>> * version 2 as published by the Free Software Foundation.
>> */
>>
>> +#include <linux/clk.h>
>> #include <linux/dma-mapping.h>
>> #include <linux/module.h>
>> #include <linux/of.h>
>> @@ -85,6 +86,42 @@ static const struct hc_driver xhci_plat_xhci_driver = {
>> .bus_resume = xhci_bus_resume,
>> };
>>
>> +#if defined(CONFIG_HAVE_CLK)
>> +static int try_enable_clk(struct platform_device *pdev)
>> +{
>> + struct clk *clk = devm_clk_get(&pdev->dev, NULL);
>> +
>> + /* Not all platforms have a clk so it is not an error if the clock
>> + does not exists. */
>> + if (!IS_ERR(clk))
>
> Instead, do:
>
> if (IS_ERR(clk))
> return 0;

As explained in the comment: Not all platforms have a clk so it is not an
error if the clock does not exists.

>
> return clk_prepare_enable(clk);
>
>> + if (clk_prepare_enable(clk))
>> + return -ENODEV;
>> + return 0;
>> +}
>> +
>> +static int try_disable_clk(struct platform_device *pdev)
>> +{
>> + struct clk *clk = devm_clk_get(&pdev->dev, NULL);
>
> No, this isn't correct: you shouldn't be getting the clock to
> disable/unprepare it, otherwise you have an unbalanced number of
> get()/put() calls on the clocks.
>
> Thomas
>


--
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

2014-04-25 14:49:06

by Gregory CLEMENT

[permalink] [raw]
Subject: Re: [PATCH v2 02/18] usb: host: xhci-plat: Add clocks support

On 25/04/2014 16:44, Gregory CLEMENT wrote:
> On 25/04/2014 16:15, Thomas Petazzoni wrote:
>> Dear Gregory CLEMENT,
>>
>> On Fri, 25 Apr 2014 16:07:00 +0200, Gregory CLEMENT wrote:
>>> Some platform (such as the Armada 38x ones) can gate the clock of
>>> their USB controller. This patch add the support for the clock, by
>>> enabling them during probe and disabling them on remove.
>>>
>>> As not all platforms have clock support then enabling and disabling
>>> the clocks have been placed in separate functions. Then if the clocks
>>> are not supported we still can use the same calls, and there is no
>>>
>>> Signed-off-by: Gregory CLEMENT <[email protected]>
>>> ---
>>> drivers/usb/host/xhci-plat.c | 52 ++++++++++++++++++++++++++++++++++++++++++--
>>> 1 file changed, 50 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
>>> index f5351af4b2c5..bb5d563f729c 100644
>>> --- a/drivers/usb/host/xhci-plat.c
>>> +++ b/drivers/usb/host/xhci-plat.c
>>> @@ -11,6 +11,7 @@
>>> * version 2 as published by the Free Software Foundation.
>>> */
>>>
>>> +#include <linux/clk.h>
>>> #include <linux/dma-mapping.h>
>>> #include <linux/module.h>
>>> #include <linux/of.h>
>>> @@ -85,6 +86,42 @@ static const struct hc_driver xhci_plat_xhci_driver = {
>>> .bus_resume = xhci_bus_resume,
>>> };
>>>
>>> +#if defined(CONFIG_HAVE_CLK)
>>> +static int try_enable_clk(struct platform_device *pdev)
>>> +{
>>> + struct clk *clk = devm_clk_get(&pdev->dev, NULL);
>>> +
>>> + /* Not all platforms have a clk so it is not an error if the clock
>>> + does not exists. */
>>> + if (!IS_ERR(clk))
>>
>> Instead, do:
>>
>> if (IS_ERR(clk))
>> return 0;
>
> As explained in the comment: Not all platforms have a clk so it is not an
> error if the clock does not exists.

Sorry you were right with the return 0. I misread the value

>
>>
>> return clk_prepare_enable(clk);
>>
>>> + if (clk_prepare_enable(clk))
>>> + return -ENODEV;
>>> + return 0;
>>> +}
>>> +
>>> +static int try_disable_clk(struct platform_device *pdev)
>>> +{
>>> + struct clk *clk = devm_clk_get(&pdev->dev, NULL);
>>
>> No, this isn't correct: you shouldn't be getting the clock to
>> disable/unprepare it, otherwise you have an unbalanced number of
>> get()/put() calls on the clocks.
>>
>> Thomas
>>
>
>


--
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

2014-04-25 14:56:24

by Felipe Balbi

[permalink] [raw]
Subject: Re: [PATCH v2 01/18] usb: host: xhci-plat: Sort the headers in alphabetic order

On Fri, Apr 25, 2014 at 04:06:59PM +0200, Gregory CLEMENT wrote:
> Sorting the headers in alphabetic order will help to reduce the conflict
> when adding new headers later.
>
> Signed-off-by: Gregory CLEMENT <[email protected]>
> ---

Acked-by: Felipe Balbi <[email protected]>

> drivers/usb/host/xhci-plat.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index 151901ce1ba9..f5351af4b2c5 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -11,11 +11,11 @@
> * version 2 as published by the Free Software Foundation.
> */
>
> -#include <linux/platform_device.h>
> +#include <linux/dma-mapping.h>
> #include <linux/module.h>
> -#include <linux/slab.h>
> #include <linux/of.h>
> -#include <linux/dma-mapping.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
>
> #include "xhci.h"
>
> --
> 1.8.1.2
>

--
balbi


Attachments:
(No filename) (986.00 B)
signature.asc (819.00 B)
Digital signature
Download all attachments

2014-04-25 15:02:58

by Felipe Balbi

[permalink] [raw]
Subject: Re: [PATCH v2 02/18] usb: host: xhci-plat: Add clocks support

Hi,

On Fri, Apr 25, 2014 at 04:07:00PM +0200, Gregory CLEMENT wrote:
> Some platform (such as the Armada 38x ones) can gate the clock of
> their USB controller. This patch add the support for the clock, by
> enabling them during probe and disabling them on remove.
>
> As not all platforms have clock support then enabling and disabling
> the clocks have been placed in separate functions. Then if the clocks
> are not supported we still can use the same calls, and there is no
>
> Signed-off-by: Gregory CLEMENT <[email protected]>
> ---
> drivers/usb/host/xhci-plat.c | 52 ++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 50 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index f5351af4b2c5..bb5d563f729c 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -11,6 +11,7 @@
> * version 2 as published by the Free Software Foundation.
> */
>
> +#include <linux/clk.h>
> #include <linux/dma-mapping.h>
> #include <linux/module.h>
> #include <linux/of.h>
> @@ -85,6 +86,42 @@ static const struct hc_driver xhci_plat_xhci_driver = {
> .bus_resume = xhci_bus_resume,
> };
>
> +#if defined(CONFIG_HAVE_CLK)

I don't think this ifdef is necessary, clk api provides stubs.

> +static int try_enable_clk(struct platform_device *pdev)

prepend this with xhci_plat_ as all other definitions here.

> +{
> + struct clk *clk = devm_clk_get(&pdev->dev, NULL);

you need to create a private xhci_plat structure and save a clock
pointer there.

> +
> + /* Not all platforms have a clk so it is not an error if the clock
> + does not exists. */

comment style is wrong.

> + if (!IS_ERR(clk))

even though some don't like it, the clk API is safe against NULL
pointers, one trick you could use is to set the clk pointer to NULL when
you fail to get it, then you'll have a single place where you check for
IS_ERR().

> + if (clk_prepare_enable(clk))
> + return -ENODEV;
> + return 0;

these three lines could be rewritten as:

return clk_prepare_enable(clk);

> +}
> +
> +static int try_disable_clk(struct platform_device *pdev)
> +{
> + struct clk *clk = devm_clk_get(&pdev->dev, NULL);
> +
> + /* Not all platforms have a clk so it is not an error if the clock
> + does not exists. */
> + if (!IS_ERR(clk))
> + clk_disable_unprepare(clk);

similar comments to previous function.

> static int xhci_plat_probe(struct platform_device *pdev)
> {
> const struct hc_driver *driver;
> @@ -107,6 +144,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
> if (!res)
> return -ENODEV;
>
> + ret = try_enable_clk(pdev);
> + if (ret)
> + return ret;
> +
> /* Initialize dma_mask and coherent_dma_mask to 32-bits */
> ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
> if (ret)
> @@ -117,8 +158,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
> dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
>
> hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
> - if (!hcd)
> - return -ENOMEM;
> + if (!hcd) {
> + ret = -ENOMEM;
> + goto disable_clk;
> + }
>
> hcd->rsrc_start = res->start;
> hcd->rsrc_len = resource_size(res);
> @@ -182,6 +225,9 @@ release_mem_region:
> put_hcd:
> usb_put_hcd(hcd);
>
> +disable_clk:
> + try_disable_clk(pdev);
> +
> return ret;
> }
>
> @@ -199,6 +245,8 @@ static int xhci_plat_remove(struct platform_device *dev)
> usb_put_hcd(hcd);
> kfree(xhci);
>
> + try_disable_clk(dev);

you never call clk_put(). what gives ?

--
balbi


Attachments:
(No filename) (3.49 kB)
signature.asc (819.00 B)
Digital signature
Download all attachments

2014-04-25 15:05:26

by Felipe Balbi

[permalink] [raw]
Subject: Re: [PATCH v2 03/18] usb: host: xhci-plat: Add support for the Armada 38x

On Fri, Apr 25, 2014 at 04:07:01PM +0200, Gregory CLEMENT wrote:
> For the Armada 38x SoCs which come with an xhci controller, specific
> initialization must be done during probe related to the MBus windows
> configuration. This patch adds the support of this quirk.
>
> Signed-off-by: Gregory CLEMENT <[email protected]>
> ---
> drivers/usb/host/Kconfig | 7 +++++
> drivers/usb/host/Makefile | 1 +
> drivers/usb/host/xhci-mvebu.c | 71 +++++++++++++++++++++++++++++++++++++++++++
> drivers/usb/host/xhci-mvebu.h | 22 ++++++++++++++
> drivers/usb/host/xhci-plat.c | 5 +++
> 5 files changed, 106 insertions(+)
> create mode 100644 drivers/usb/host/xhci-mvebu.c
> create mode 100644 drivers/usb/host/xhci-mvebu.h
>
> diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
> index 3d9e54062d62..e70943fac4a1 100644
> --- a/drivers/usb/host/Kconfig
> +++ b/drivers/usb/host/Kconfig
> @@ -29,6 +29,13 @@ if USB_XHCI_HCD
> config USB_XHCI_PLATFORM
> tristate
>
> +config USB_XHCI_MVEBU
> + tristate "xHCI support for Marvell Armada 38x"
> + select USB_XHCI_PLATFORM
> + ---help---
> + Say 'Y' to enable the support for the xHCI host controller
> + found in Marvell Armada 38x ARM SOCs.
> +
> endif # USB_XHCI_HCD
>
> config USB_EHCI_HCD
> diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
> index 7530468c9a4f..7a8db7f7dc01 100644
> --- a/drivers/usb/host/Makefile
> +++ b/drivers/usb/host/Makefile
> @@ -19,6 +19,7 @@ xhci-hcd-$(CONFIG_PCI) += xhci-pci.o
>
> ifneq ($(CONFIG_USB_XHCI_PLATFORM), )
> xhci-hcd-y += xhci-plat.o
> + xhci-hcd-$(CONFIG_USB_XHCI_MVEBU) += xhci-mvebu.o
> endif
>
> obj-$(CONFIG_USB_WHCI_HCD) += whci/
> diff --git a/drivers/usb/host/xhci-mvebu.c b/drivers/usb/host/xhci-mvebu.c
> new file mode 100644
> index 000000000000..09cf437499fb
> --- /dev/null
> +++ b/drivers/usb/host/xhci-mvebu.c
> @@ -0,0 +1,71 @@
> +/*
> + * Copyright (C) 2014 Marvell
> + * Author: Gregory CLEMENT <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + */
> +
> +#include <linux/io.h>
> +#include <linux/mbus.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +
> +#define USB3_MAX_WINDOWS 4
> +#define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
> +#define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
> +
> +static void __init mv_usb3_conf_mbus_windows(void __iomem *base,
> + const struct mbus_dram_target_info *dram)
> +{
> + int win;
> +
> + /* Clear all existing windows */
> + for (win = 0; win < USB3_MAX_WINDOWS; win++) {
> + writel(0, base + USB3_WIN_CTRL(win));
> + writel(0, base + USB3_WIN_BASE(win));
> + }
> +
> + /* Program each DRAM CS in a seperate window */
> + for (win = 0; win < dram->num_cs; win++) {
> + const struct mbus_dram_window *cs = dram->cs + win;
> +
> + writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
> + (dram->mbus_dram_target_id << 4) | 1,
> + base + USB3_WIN_CTRL(win));
> +
> + writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(win));
> + }
> +}
> +
> +int xhci_mvebu_mbus_init_quirk(struct platform_device *pdev)
> +{
> + struct resource *res;
> + void __iomem *base;
> + const struct mbus_dram_target_info *dram;
> + int ret = 0;
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> + if (!res)
> + return -ENODEV;
> +
> + /*
> + * We don't use devm_ioremap() because this mapping should
> + * only exists for the duration of this probe function.
> + */
> + base = ioremap(res->start, resource_size(res));
> + if (!base)
> + return -ENODEV;
> +
> + dram = mv_mbus_dram_info();
> + mv_usb3_conf_mbus_windows(base, dram);
> +
> + /*
> + * This memory area was only needed to configure the MBus
> + * windows, and is therefore no longer useful.
> + */
> + iounmap(base);
> +
> + return ret;
> +}
> diff --git a/drivers/usb/host/xhci-mvebu.h b/drivers/usb/host/xhci-mvebu.h
> new file mode 100644
> index 000000000000..5d7e647b3d27
> --- /dev/null
> +++ b/drivers/usb/host/xhci-mvebu.h
> @@ -0,0 +1,22 @@
> +/*
> + * Copyright (C) 2014 Marvell
> + *
> + * Gregory Clement <[email protected]>
> + *
> + * This file is licensed under the terms of the GNU General Public
> + * License version 2. This program is licensed "as is" without any
> + * warranty of any kind, whether express or implied.
> + */
> +
> +#ifndef __LINUX_XHCI_MVEBU_H
> +#define __LINUX_XHCI_MVEBU_H
> +
> +#ifdef CONFIG_USB_XHCI_MVEBU

this is a tristate symbol, you're not treating the case where this is a
module. Have you really build-tested this patch ? It would give you
redefinition errors. Switch over to:

#if IS_ENABLED(CONFIG_USB_XHCI_MVEBU)

> +int xhci_mvebu_mbus_init_quirk(struct platform_device *pdev);
> +#else
> +static inline int xhci_mvebu_mbus_init_quirk(struct device dev)
> +{
> + return 0;
> +}
> +#endif
> +#endif /* __LINUX_XHCI_MVEBU_H */
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index bb5d563f729c..c0e835b49e0d 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -19,6 +19,7 @@
> #include <linux/slab.h>
>
> #include "xhci.h"
> +#include "xhci-mvebu.h"
>
> static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
> {
> @@ -148,6 +149,9 @@ static int xhci_plat_probe(struct platform_device *pdev)
> if (ret)
> return ret;
>
> + if (of_device_is_compatible(pdev->dev.of_node, "marvell,armada-380-xhci"))

break the line at that , character

> + xhci_mvebu_mbus_init_quirk(pdev);
> +
> /* Initialize dma_mask and coherent_dma_mask to 32-bits */
> ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
> if (ret)
> @@ -279,6 +283,7 @@ static const struct dev_pm_ops xhci_plat_pm_ops = {
> static const struct of_device_id usb_xhci_of_match[] = {
> { .compatible = "generic-xhci" },
> { .compatible = "xhci-platform" },
> + { .compatible = "marvell,armada-380-xhci"},
> { },
> };
> MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
> --
> 1.8.1.2
>

--
balbi


Attachments:
(No filename) (6.02 kB)
signature.asc (819.00 B)
Digital signature
Download all attachments

2014-04-25 15:43:57

by Ezequiel Garcia

[permalink] [raw]
Subject: Re: [PATCH v2 14/18] ARM: mvebu: Add support for USB cluster on the Armada 375 SoC

On Apr 25, Gregory CLEMENT wrote:
> The Armada 375 SoC comes with an USB2 host and device controller and
> an USB3 controller. The USB cluster control register allows to manage
> common features of both USB controllers.
>
> Signed-off-by: Gregory CLEMENT <[email protected]>
> ---
> arch/arm/mach-mvebu/Makefile | 2 +-
> arch/arm/mach-mvebu/usb-cluster.c | 96 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 97 insertions(+), 1 deletion(-)
> create mode 100644 arch/arm/mach-mvebu/usb-cluster.c
>
> diff --git a/arch/arm/mach-mvebu/Makefile b/arch/arm/mach-mvebu/Makefile
> index a63e43b6b451..dec05e7e1802 100644
> --- a/arch/arm/mach-mvebu/Makefile
> +++ b/arch/arm/mach-mvebu/Makefile
> @@ -4,7 +4,7 @@ ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \
> AFLAGS_coherency_ll.o := -Wa,-march=armv7-a
>
> obj-y += system-controller.o mvebu-soc-id.o
> -obj-$(CONFIG_MACH_MVEBU_V7) += board-v7.o
> +obj-$(CONFIG_MACH_MVEBU_V7) += board-v7.o usb-cluster.o
> obj-$(CONFIG_MACH_DOVE) += dove.o
> obj-$(CONFIG_ARCH_MVEBU) += coherency.o coherency_ll.o pmsu.o
> obj-$(CONFIG_SMP) += platsmp.o headsmp.o
> diff --git a/arch/arm/mach-mvebu/usb-cluster.c b/arch/arm/mach-mvebu/usb-cluster.c
> new file mode 100644
> index 000000000000..4c15d282db23
> --- /dev/null
> +++ b/arch/arm/mach-mvebu/usb-cluster.c
> @@ -0,0 +1,96 @@
> +/*
> + * USB cluster support for Armada 375 platform.
> + *
> + * Copyright (C) 2014 Marvell
> + *
> + * Gregory CLEMENT <[email protected]>
> + *
> + * This file is licensed under the terms of the GNU General Public
> + * License version 2. This program is licensed "as is" without any
> + * warranty of any kind, whether express or implied.
> + *
> + * Armada 375 comes with an USB2 host and device controller and an
> + * USB3 controller. The USB cluster control register allows to manage
> + * common features of both USB controller.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/of_address.h>
> +#include <linux/io.h>
> +#include <linux/slab.h>
> +
> +#define USB2_PHY_CONFIG_ENABLE BIT(0) /* active low */
> +

If it's active low, maybe you can simply call this USB2_PHY_DISABLE?

> +static struct of_device_id of_usb_cluster_table[] = {
> + { .compatible = "marvell,armada-375-usb-cluster", },
> + { /* end of list */ },
> +};
> +
> +static int __init mvebu_usb_cluster_init(void)
> +{
> + struct device_node *np;
> +
> + np = of_find_matching_node(NULL, of_usb_cluster_table);
> + if (np) {

I think that writing:

if (!np)
return 0;

Will allow to write the rest with less indentation, which is usually cleaner.

> + void __iomem *usb_cluster_base;
> + u32 reg;
> + struct device_node *ehci_node, *xhci_node;
> + struct property *ehci_status;
> + bool use_usb3 = false;
> +
> + usb_cluster_base = of_iomap(np, 0);
> + BUG_ON(!usb_cluster_base);
> +
> + xhci_node = of_find_compatible_node(NULL, NULL,
> + "marvell,armada-375-xhci");
> +
> + if (xhci_node && of_device_is_available(xhci_node))
> + use_usb3 = true;
> +
> + ehci_node = of_find_compatible_node(NULL, NULL,
> + "marvell,orion-ehci");
> +
> + if (ehci_node && of_device_is_available(ehci_node)
> + && use_usb3) {
> + /*
> + * We can't use usb2 and usb3 in the same time, so let's
> + * disbale usb2 and complain about it to the user askinf

typos: disable, asking

> + * to fix the device tree.
> + */
> +
> + ehci_status = kzalloc(sizeof(struct property),
> + GFP_KERNEL);
> + WARN_ON(!ehci_status);
> +
> + ehci_status->value = kstrdup("disabled", GFP_KERNEL);

Unless I'm missing something, warning about allocation error but then still
using the pointer will cause very nasty problems. Maybe you can simply
bail out?

> + WARN_ON(!ehci_status->value);
> +
> + ehci_status->length = 8;
> + ehci_status->name = kstrdup("status", GFP_KERNEL);
> + WARN_ON(!ehci_status->name);
> +
> + of_update_property(ehci_node, ehci_status);
> + pr_err("%s: armada-375-xhci and orion-ehci are incompatible for this SoC.\n",
> + __func__);
> + pr_err("Please fix your dts!\n");
> + pr_err("orion-ehci have been disabled by default...\n");
> +

We've been using a WARN(1, FW_BUG "") to notify the user of a broken DT.
Arnd suggested to use WARN() to really catch the user's attention.

> + }
> +
> + reg = readl(usb_cluster_base);
> + if (use_usb3)
> + reg |= USB2_PHY_CONFIG_ENABLE;
> + else
> + reg &= ~USB2_PHY_CONFIG_ENABLE;
> + writel(reg, usb_cluster_base);
> +
> + of_node_put(ehci_node);
> + of_node_put(xhci_node);
> + of_node_put(np);
> + iounmap(usb_cluster_base);
> + }
> +
> + return 0;
> +}
> +postcore_initcall(mvebu_usb_cluster_init);
> --
> 1.8.1.2
>

--
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

2014-04-25 15:50:37

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH v2 02/18] usb: host: xhci-plat: Add clocks support

On Fri, Apr 25, 2014 at 04:07:00PM +0200, Gregory CLEMENT wrote:
> Some platform (such as the Armada 38x ones) can gate the clock of
> their USB controller. This patch add the support for the clock, by
> enabling them during probe and disabling them on remove.
>
> As not all platforms have clock support then enabling and disabling
> the clocks have been placed in separate functions. Then if the clocks
> are not supported we still can use the same calls, and there is no
>
> Signed-off-by: Gregory CLEMENT <[email protected]>
> ---
> drivers/usb/host/xhci-plat.c | 52 ++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 50 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index f5351af4b2c5..bb5d563f729c 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -11,6 +11,7 @@
> * version 2 as published by the Free Software Foundation.
> */
>
> +#include <linux/clk.h>
> #include <linux/dma-mapping.h>
> #include <linux/module.h>
> #include <linux/of.h>
> @@ -85,6 +86,42 @@ static const struct hc_driver xhci_plat_xhci_driver = {
> .bus_resume = xhci_bus_resume,
> };
>
> +#if defined(CONFIG_HAVE_CLK)

Hi Gregory

You probably don't need to do this conditional on CONFIG_HAVE_CLK.
There are stub functions in clk.h for when CONFIG_HAVE_CLK is not
defined. So the compiler knows devm_clk_get() will return NULL, it can
evaluate IS_ERR is false, clk_prepare() returns 0 and so the whole
function collapses to "return 0;"

> +static int try_enable_clk(struct platform_device *pdev)
> +{
> + struct clk *clk = devm_clk_get(&pdev->dev, NULL);
> +
> + /* Not all platforms have a clk so it is not an error if the clock
> + does not exists. */
> + if (!IS_ERR(clk))
> + if (clk_prepare_enable(clk))
> + return -ENODEV;

Is ENODEV the correct error code? It would probably be better to
return the return value of clk_prepare_enable()

> + return 0;
> +}

2014-04-25 15:56:23

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH v2 05/18] ARM: mvebu: Add Device Tree description of xHCI hosts on Armada 38x

On Fri, Apr 25, 2014 at 04:07:03PM +0200, Gregory CLEMENT wrote:
> The Marvell Armada 38x SoCs contain two xHCI host. This commit adds
> the Device Tree description of those interfaces at the SoC level, and
> also enables the two USB3 ports on the Armada 385 DB platform and one
> USB3 port on the Armada 385 RD platforms.
>
> Signed-off-by: Gregory CLEMENT <[email protected]>
> ---
> arch/arm/boot/dts/armada-385-db.dts | 8 ++++++++
> arch/arm/boot/dts/armada-385-rd.dts | 4 ++++
> arch/arm/boot/dts/armada-38x.dtsi | 17 +++++++++++++++++
> 3 files changed, 29 insertions(+)
>
> diff --git a/arch/arm/boot/dts/armada-385-db.dts b/arch/arm/boot/dts/armada-385-db.dts
> index 6828d77696a6..d5db1466da82 100644
> --- a/arch/arm/boot/dts/armada-385-db.dts
> +++ b/arch/arm/boot/dts/armada-385-db.dts
> @@ -101,6 +101,14 @@
> reg = <0x1000000 0x3f000000>;
> };
> };
> +
> + usb3@f0000 {
> + status = "okay";
> + };
> +
> + usb3@f8000 {
> + status = "okay";
> + };
> };
>
> pcie-controller {
> diff --git a/arch/arm/boot/dts/armada-385-rd.dts b/arch/arm/boot/dts/armada-385-rd.dts
> index 45250c88814b..a505fe94ff37 100644
> --- a/arch/arm/boot/dts/armada-385-rd.dts
> +++ b/arch/arm/boot/dts/armada-385-rd.dts
> @@ -77,6 +77,10 @@
> reg = <1>;
> };
> };
> +
> + usb3@f0000 {
> + status = "okay";
> + };
> };
>
> pcie-controller {
> diff --git a/arch/arm/boot/dts/armada-38x.dtsi b/arch/arm/boot/dts/armada-38x.dtsi
> index a064f59da02d..5913ce1cc601 100644
> --- a/arch/arm/boot/dts/armada-38x.dtsi
> +++ b/arch/arm/boot/dts/armada-38x.dtsi
> @@ -355,6 +355,23 @@
> clocks = <&coredivclk 0>;
> status = "disabled";
> };
> +
> + usb3@f0000 {
> + compatible = "marvell,armada-380-xhci";
> + reg = <0xf0000 0x3fff>,<0xf4000 0x3fff>;

s/0x3fff/0x4000/g ?

Andrew

> + interrupts = <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>;
> + clocks = <&gateclk 9>;
> + status = "disabled";
> + };
> +
> + usb3@f8000 {
> + compatible = "marvell,armada-380-xhci";
> + reg = <0xf8000 0x3fff>,<0xfc000 0x3fff>;
> + interrupts = <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
> + clocks = <&gateclk 10>;
> + status = "disabled";
> + };
> +
> };
> };
>
> --
> 1.8.1.2
>

2014-04-25 16:02:07

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH v2 14/18] ARM: mvebu: Add support for USB cluster on the Armada 375 SoC

> > + * We can't use usb2 and usb3 in the same time, so let's
> > + * disbale usb2 and complain about it to the user askinf
>
> typos: disable, asking

And it should be "at the same time", not in.

Andrew

2014-04-25 16:09:48

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH v2 14/18] ARM: mvebu: Add support for USB cluster on the Armada 375 SoC

On Fri, Apr 25, 2014 at 04:07:12PM +0200, Gregory CLEMENT wrote:
> The Armada 375 SoC comes with an USB2 host and device controller and
> an USB3 controller. The USB cluster control register allows to manage
> common features of both USB controllers.
>
> Signed-off-by: Gregory CLEMENT <[email protected]>
> ---
> arch/arm/mach-mvebu/Makefile | 2 +-
> arch/arm/mach-mvebu/usb-cluster.c | 96 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 97 insertions(+), 1 deletion(-)
> create mode 100644 arch/arm/mach-mvebu/usb-cluster.c
>
> diff --git a/arch/arm/mach-mvebu/Makefile b/arch/arm/mach-mvebu/Makefile
> index a63e43b6b451..dec05e7e1802 100644
> --- a/arch/arm/mach-mvebu/Makefile
> +++ b/arch/arm/mach-mvebu/Makefile
> @@ -4,7 +4,7 @@ ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \
> AFLAGS_coherency_ll.o := -Wa,-march=armv7-a
>
> obj-y += system-controller.o mvebu-soc-id.o
> -obj-$(CONFIG_MACH_MVEBU_V7) += board-v7.o
> +obj-$(CONFIG_MACH_MVEBU_V7) += board-v7.o usb-cluster.o
> obj-$(CONFIG_MACH_DOVE) += dove.o
> obj-$(CONFIG_ARCH_MVEBU) += coherency.o coherency_ll.o pmsu.o
> obj-$(CONFIG_SMP) += platsmp.o headsmp.o
> diff --git a/arch/arm/mach-mvebu/usb-cluster.c b/arch/arm/mach-mvebu/usb-cluster.c
> new file mode 100644
> index 000000000000..4c15d282db23
> --- /dev/null
> +++ b/arch/arm/mach-mvebu/usb-cluster.c
> @@ -0,0 +1,96 @@
> +/*
> + * USB cluster support for Armada 375 platform.
> + *
> + * Copyright (C) 2014 Marvell
> + *
> + * Gregory CLEMENT <[email protected]>
> + *
> + * This file is licensed under the terms of the GNU General Public
> + * License version 2. This program is licensed "as is" without any
> + * warranty of any kind, whether express or implied.
> + *
> + * Armada 375 comes with an USB2 host and device controller and an
> + * USB3 controller. The USB cluster control register allows to manage
> + * common features of both USB controller.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/of_address.h>
> +#include <linux/io.h>
> +#include <linux/slab.h>
> +
> +#define USB2_PHY_CONFIG_ENABLE BIT(0) /* active low */
> +
> +static struct of_device_id of_usb_cluster_table[] = {
> + { .compatible = "marvell,armada-375-usb-cluster", },
> + { /* end of list */ },
> +};
> +
> +static int __init mvebu_usb_cluster_init(void)
> +{
> + struct device_node *np;
> +
> + np = of_find_matching_node(NULL, of_usb_cluster_table);
> + if (np) {
> + void __iomem *usb_cluster_base;
> + u32 reg;
> + struct device_node *ehci_node, *xhci_node;
> + struct property *ehci_status;
> + bool use_usb3 = false;
> +
> + usb_cluster_base = of_iomap(np, 0);
> + BUG_ON(!usb_cluster_base);
> +
> + xhci_node = of_find_compatible_node(NULL, NULL,
> + "marvell,armada-375-xhci");
> +
> + if (xhci_node && of_device_is_available(xhci_node))
> + use_usb3 = true;
> +
> + ehci_node = of_find_compatible_node(NULL, NULL,
> + "marvell,orion-ehci");
> +
> + if (ehci_node && of_device_is_available(ehci_node)
> + && use_usb3) {
> + /*
> + * We can't use usb2 and usb3 in the same time, so let's
> + * disbale usb2 and complain about it to the user askinf
> + * to fix the device tree.
> + */
> +
> + ehci_status = kzalloc(sizeof(struct property),
> + GFP_KERNEL);
> + WARN_ON(!ehci_status);
> +
> + ehci_status->value = kstrdup("disabled", GFP_KERNEL);
> + WARN_ON(!ehci_status->value);
> +
> + ehci_status->length = 8;
> + ehci_status->name = kstrdup("status", GFP_KERNEL);
> + WARN_ON(!ehci_status->name);
> +
> + of_update_property(ehci_node, ehci_status);
> + pr_err("%s: armada-375-xhci and orion-ehci are incompatible for this SoC.\n",
> + __func__);
> + pr_err("Please fix your dts!\n");
> + pr_err("orion-ehci have been disabled by default...\n");
> +
> + }
> +
> + reg = readl(usb_cluster_base);
> + if (use_usb3)
> + reg |= USB2_PHY_CONFIG_ENABLE;
> + else
> + reg &= ~USB2_PHY_CONFIG_ENABLE;
> + writel(reg, usb_cluster_base);

Am i right in saying this in the end is about enabling the USB2 phy or
a USB3 why? So why not just implement a phy driver?

Andrew

2014-04-25 16:14:19

by Felipe Balbi

[permalink] [raw]
Subject: Re: [PATCH v2 14/18] ARM: mvebu: Add support for USB cluster on the Armada 375 SoC

On Fri, Apr 25, 2014 at 06:07:05PM +0200, Andrew Lunn wrote:
> On Fri, Apr 25, 2014 at 04:07:12PM +0200, Gregory CLEMENT wrote:
> > The Armada 375 SoC comes with an USB2 host and device controller and
> > an USB3 controller. The USB cluster control register allows to manage
> > common features of both USB controllers.
> >
> > Signed-off-by: Gregory CLEMENT <[email protected]>
> > ---
> > arch/arm/mach-mvebu/Makefile | 2 +-
> > arch/arm/mach-mvebu/usb-cluster.c | 96 +++++++++++++++++++++++++++++++++++++++
> > 2 files changed, 97 insertions(+), 1 deletion(-)
> > create mode 100644 arch/arm/mach-mvebu/usb-cluster.c
> >
> > diff --git a/arch/arm/mach-mvebu/Makefile b/arch/arm/mach-mvebu/Makefile
> > index a63e43b6b451..dec05e7e1802 100644
> > --- a/arch/arm/mach-mvebu/Makefile
> > +++ b/arch/arm/mach-mvebu/Makefile
> > @@ -4,7 +4,7 @@ ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \
> > AFLAGS_coherency_ll.o := -Wa,-march=armv7-a
> >
> > obj-y += system-controller.o mvebu-soc-id.o
> > -obj-$(CONFIG_MACH_MVEBU_V7) += board-v7.o
> > +obj-$(CONFIG_MACH_MVEBU_V7) += board-v7.o usb-cluster.o
> > obj-$(CONFIG_MACH_DOVE) += dove.o
> > obj-$(CONFIG_ARCH_MVEBU) += coherency.o coherency_ll.o pmsu.o
> > obj-$(CONFIG_SMP) += platsmp.o headsmp.o
> > diff --git a/arch/arm/mach-mvebu/usb-cluster.c b/arch/arm/mach-mvebu/usb-cluster.c
> > new file mode 100644
> > index 000000000000..4c15d282db23
> > --- /dev/null
> > +++ b/arch/arm/mach-mvebu/usb-cluster.c
> > @@ -0,0 +1,96 @@
> > +/*
> > + * USB cluster support for Armada 375 platform.
> > + *
> > + * Copyright (C) 2014 Marvell
> > + *
> > + * Gregory CLEMENT <[email protected]>
> > + *
> > + * This file is licensed under the terms of the GNU General Public
> > + * License version 2. This program is licensed "as is" without any
> > + * warranty of any kind, whether express or implied.
> > + *
> > + * Armada 375 comes with an USB2 host and device controller and an
> > + * USB3 controller. The USB cluster control register allows to manage
> > + * common features of both USB controller.
> > + */
> > +
> > +#include <linux/kernel.h>
> > +#include <linux/init.h>
> > +#include <linux/of_address.h>
> > +#include <linux/io.h>
> > +#include <linux/slab.h>
> > +
> > +#define USB2_PHY_CONFIG_ENABLE BIT(0) /* active low */
> > +
> > +static struct of_device_id of_usb_cluster_table[] = {
> > + { .compatible = "marvell,armada-375-usb-cluster", },
> > + { /* end of list */ },
> > +};
> > +
> > +static int __init mvebu_usb_cluster_init(void)
> > +{
> > + struct device_node *np;
> > +
> > + np = of_find_matching_node(NULL, of_usb_cluster_table);
> > + if (np) {
> > + void __iomem *usb_cluster_base;
> > + u32 reg;
> > + struct device_node *ehci_node, *xhci_node;
> > + struct property *ehci_status;
> > + bool use_usb3 = false;
> > +
> > + usb_cluster_base = of_iomap(np, 0);
> > + BUG_ON(!usb_cluster_base);
> > +
> > + xhci_node = of_find_compatible_node(NULL, NULL,
> > + "marvell,armada-375-xhci");
> > +
> > + if (xhci_node && of_device_is_available(xhci_node))
> > + use_usb3 = true;
> > +
> > + ehci_node = of_find_compatible_node(NULL, NULL,
> > + "marvell,orion-ehci");
> > +
> > + if (ehci_node && of_device_is_available(ehci_node)
> > + && use_usb3) {
> > + /*
> > + * We can't use usb2 and usb3 in the same time, so let's
> > + * disbale usb2 and complain about it to the user askinf
> > + * to fix the device tree.
> > + */
> > +
> > + ehci_status = kzalloc(sizeof(struct property),
> > + GFP_KERNEL);
> > + WARN_ON(!ehci_status);
> > +
> > + ehci_status->value = kstrdup("disabled", GFP_KERNEL);
> > + WARN_ON(!ehci_status->value);
> > +
> > + ehci_status->length = 8;
> > + ehci_status->name = kstrdup("status", GFP_KERNEL);
> > + WARN_ON(!ehci_status->name);
> > +
> > + of_update_property(ehci_node, ehci_status);
> > + pr_err("%s: armada-375-xhci and orion-ehci are incompatible for this SoC.\n",
> > + __func__);
> > + pr_err("Please fix your dts!\n");
> > + pr_err("orion-ehci have been disabled by default...\n");
> > +
> > + }
> > +
> > + reg = readl(usb_cluster_base);
> > + if (use_usb3)
> > + reg |= USB2_PHY_CONFIG_ENABLE;
> > + else
> > + reg &= ~USB2_PHY_CONFIG_ENABLE;
> > + writel(reg, usb_cluster_base);
>
> Am i right in saying this in the end is about enabling the USB2 phy or
> a USB3 why? So why not just implement a phy driver?

+1 we have a generic phy layer (drivers/phy) for that.

--
balbi


Attachments:
(No filename) (4.47 kB)
signature.asc (819.00 B)
Digital signature
Download all attachments

2014-04-25 17:55:18

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH v2 04/18] xhci-platform: Add a new controller using xhci: Armada 38x

Hello.

On 04/25/2014 06:07 PM, Gregory CLEMENT wrote:

> Extend the compatible string list with armada-380-xhci. It is used to
> describe xhci controller which is in the Armada 38x SoCs.

> Signed-off-by: Gregory CLEMENT <[email protected]>
> ---
> Documentation/devicetree/bindings/usb/usb-xhci.txt | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)

> diff --git a/Documentation/devicetree/bindings/usb/usb-xhci.txt b/Documentation/devicetree/bindings/usb/usb-xhci.txt
> index 90f8f607d125..cbc91414fd59 100644
> --- a/Documentation/devicetree/bindings/usb/usb-xhci.txt
> +++ b/Documentation/devicetree/bindings/usb/usb-xhci.txt
> @@ -1,7 +1,8 @@
> USB xHCI controllers
>
> Required properties:
> - - compatible: should be "generic-xhci" (deprecated: "xhci-platform").
> + - compatible: should be on of "generic-xhci",

s/on/one/

> + "marvell,armada-380-xhci" (deprecated: "xhci-platform").

What's the difference of "marvell,armada-380-xhci" to "generic-xhci"?

WBR, Sergei

2014-04-25 20:02:55

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH v2 03/18] usb: host: xhci-plat: Add support for the Armada 38x

On Friday 25 April 2014 16:07:01 Gregory CLEMENT wrote:
> @@ -148,6 +149,9 @@ static int xhci_plat_probe(struct platform_device *pdev)
> if (ret)
> return ret;
>
> + if (of_device_is_compatible(pdev->dev.of_node, "marvell,armada-380-xhci"))
> + xhci_mvebu_mbus_init_quirk(pdev);
> +
> /* Initialize dma_mask and coherent_dma_mask to 32-bits */
> ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
> if (ret)

I think you're doing it the wrong way around: You have a specialized
version of the generic xhci-plat driver. The normal way to handle this
is to have a loadable module that contains all the Armada specific
code and that registers a platform_driver. In the probe() function of
that driver, you can do the platform specific setup and then call
the generic xhci_plat_probe() function, which of course has to
be provided using EXPORT_SYMBOL_GPL.

We have just spent a lot of effort converting the EHCI and OHCI drivers
to the more generic model, so we shouldn't do it the wrong way for
xhci. I just noticed that we already have this creeping into the
xhci driver in the from of a common xhci_hcd_init() function calling
xhci_register_pci() and xhci_register_plat(). It would be good to
clean that up at the same time, it should only require exporting
a few symbols from xhci.c for use by the two front-ends.

Arnd

2014-04-25 20:11:41

by Felipe Balbi

[permalink] [raw]
Subject: Re: [PATCH v2 03/18] usb: host: xhci-plat: Add support for the Armada 38x

Hi,

On Fri, Apr 25, 2014 at 10:01:51PM +0200, Arnd Bergmann wrote:
> On Friday 25 April 2014 16:07:01 Gregory CLEMENT wrote:
> > @@ -148,6 +149,9 @@ static int xhci_plat_probe(struct platform_device *pdev)
> > if (ret)
> > return ret;
> >
> > + if (of_device_is_compatible(pdev->dev.of_node, "marvell,armada-380-xhci"))
> > + xhci_mvebu_mbus_init_quirk(pdev);
> > +
> > /* Initialize dma_mask and coherent_dma_mask to 32-bits */
> > ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
> > if (ret)
>
> I think you're doing it the wrong way around: You have a specialized

no, it's the correct way around.

> version of the generic xhci-plat driver. The normal way to handle this
> is to have a loadable module that contains all the Armada specific
> code and that registers a platform_driver. In the probe() function of

no, that'll cause too much duplication of boilerplate code. I asked him
to write it as a quirk because then we won't end up with and xhci
platform_driver for each of the ARM licensees when all they have are
small quirks here and there.

Imagine if you had one PCI driver for each possible XHCI PCI controller
out there.

It's pointless maintainenance burden.

> that driver, you can do the platform specific setup and then call
> the generic xhci_plat_probe() function, which of course has to
> be provided using EXPORT_SYMBOL_GPL.

yeah, that sucks. Exposing a probe() function like that. I rather have
probe() actually *probe* for the HW differences.

--
balbi


Attachments:
(No filename) (1.53 kB)
signature.asc (819.00 B)
Digital signature
Download all attachments

2014-04-25 20:25:43

by Thomas Petazzoni

[permalink] [raw]
Subject: Re: [PATCH v2 03/18] usb: host: xhci-plat: Add support for the Armada 38x

Dear Arnd Bergmann,

On Fri, 25 Apr 2014 22:01:51 +0200, Arnd Bergmann wrote:

> I think you're doing it the wrong way around: You have a specialized
> version of the generic xhci-plat driver. The normal way to handle this
> is to have a loadable module that contains all the Armada specific
> code and that registers a platform_driver. In the probe() function of
> that driver, you can do the platform specific setup and then call
> the generic xhci_plat_probe() function, which of course has to
> be provided using EXPORT_SYMBOL_GPL.

You should have a look at the v1 Gregory sent: it was implementing
exactly what you suggest here, but Felipe explicitly requested the
patches to be changed like is now proposed in v2.

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com