* [PATCH v2 00/13] musb: Add support for the Allwinner sunxi musb controller
@ 2015-03-20 19:11 Hans de Goede
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw
Hi All,
Here is v2 of my patch-set to add support for the musb variant found on
Allwinner sunxi SoCs.
Changes since the original posting:
-Removed the sunxi specific phy functions, instead the id / vbus gpio polling
has been moved to the phy-sun4i-usb driver and their status is exported
through extcon for the sunxi-musb glue
-Stop using syscon, instead Maxime Ripard's sunxi SRAM controller driver is now
used
This should address all review remarks against v1 of this patch-set, so
hopefully we can start merging this upstream.
The "musb: Add support for the Allwinner sunxi musb" commit relies on
Maxime's SRAM controller patches, so those need to get merged first,
but the phy-sun4i-usb and musb preparation patches can be merged already
(assuming there are no objections).
And then once the SRAM controller patches are in next we can also merge
the "musb: Add support for the Allwinner sunxi musb" commit and the dts
changes.
Regards,
Hans
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v2 01/13] phy-sun4i-usb: Add full support for usb0 phy / OTG
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2015-03-20 19:11 ` Hans de Goede
2015-03-20 19:11 ` [PATCH v2 02/13] musb: Make musb_write_rxfun* and musb_write_rxhub* work like their tx versions Hans de Goede
` (12 subsequent siblings)
13 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
The usb0 phy is connected to an OTG controller, and as such needs some special
handling:
1) It allows explicit control over the pullups, enable these on phy_init and
disable them on phy_exit.
2) It has bits to signal id and vbus detect to the musb-core, add support for
for monitoring id and vbus detect gpio-s for use in dual role mode, and set
these bits to the correct values for operating in host only mode when no
gpios are specified in the devicetree.
3) When in dual role mode the musb sunxi glue needs to know if the a host or
device cable is plugged in, so when in dual role mode register an extcon.
While updating the devicetree binding documentation also add documentation
for the sofar undocumented usage of regulators for vbus for all 3 phys.
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
.../devicetree/bindings/phy/sun4i-usb-phy.txt | 18 +-
drivers/phy/Kconfig | 1 +
drivers/phy/phy-sun4i-usb.c | 269 ++++++++++++++++++++-
3 files changed, 277 insertions(+), 11 deletions(-)
diff --git a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
index 16528b9..557fa99 100644
--- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
+++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
@@ -23,6 +23,13 @@ Required properties:
* "usb1_reset"
* "usb2_reset" for sun4i, sun6i or sun7i
+Optional properties:
+- usb0_id_det-gpios : gpio phandle for reading the otg id pin value
+- usb0_vbus_det-gpios : gpio phandle for detecting the presence of usb0 vbus
+- usb0_vbus-supply : regulator phandle for controller usb0 vbus
+- usb1_vbus-supply : regulator phandle for controller usb1 vbus
+- usb2_vbus-supply : regulator phandle for controller usb2 vbus
+
Example:
usbphy: phy@0x01c13400 {
#phy-cells = <1>;
@@ -32,6 +39,13 @@ Example:
reg-names = "phy_ctrl", "pmu1", "pmu2";
clocks = <&usb_clk 8>;
clock-names = "usb_phy";
- resets = <&usb_clk 1>, <&usb_clk 2>;
- reset-names = "usb1_reset", "usb2_reset";
+ resets = <&usb_clk 0>, <&usb_clk 1>, <&usb_clk 2>;
+ reset-names = "usb0_reset", "usb1_reset", "usb2_reset";
+ pinctrl-names = "default";
+ pinctrl-0 = <&usb0_id_detect_pin>, <&usb0_vbus_detect_pin>;
+ usb0_id_det-gpios = <&pio 7 19 GPIO_ACTIVE_HIGH>; /* PH19 */
+ usb0_vbus_det-gpios = <&pio 7 22 GPIO_ACTIVE_HIGH>; /* PH22 */
+ usb0_vbus-supply = <®_usb0_vbus>;
+ usb1_vbus-supply = <®_usb1_vbus>;
+ usb2_vbus-supply = <®_usb2_vbus>;
};
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 3e6b176..0795b3a 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -166,6 +166,7 @@ config PHY_SUN4I_USB
tristate "Allwinner sunxi SoC USB PHY driver"
depends on ARCH_SUNXI && HAS_IOMEM && OF
depends on RESET_CONTROLLER
+ select EXTCON
select GENERIC_PHY
help
Enable this to support the transceiver that is part of Allwinner
diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index a2b08f3c..221e8ab 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -1,7 +1,7 @@
/*
* Allwinner sun4i USB phy driver
*
- * Copyright (C) 2014 Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
+ * Copyright (C) 2014-2015 Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
*
* Based on code from
* Allwinner Technology Co., Ltd. <www.allwinnertech.com>
@@ -23,16 +23,22 @@
#include <linux/clk.h>
#include <linux/err.h>
+#include <linux/extcon.h>
#include <linux/io.h>
+#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/of_address.h>
+#include <linux/of_gpio.h>
#include <linux/phy/phy.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <linux/reset.h>
+#include <linux/workqueue.h>
+
+#define DRIVER_NAME "sun4i-usb-phy"
#define REG_ISCR 0x00
#define REG_PHYCTL 0x04
@@ -46,6 +52,17 @@
#define SUNXI_AHB_INCRX_ALIGN_EN BIT(8)
#define SUNXI_ULPI_BYPASS_EN BIT(0)
+/* ISCR, Interface Status and Control bits */
+#define ISCR_ID_PULLUP_EN (1 << 17)
+#define ISCR_DPDM_PULLUP_EN (1 << 16)
+/* sunxi has the phy id/vbus pins not connected, so we use the force bits */
+#define ISCR_FORCE_ID_MASK (3 << 14)
+#define ISCR_FORCE_ID_LOW (2 << 14)
+#define ISCR_FORCE_ID_HIGH (3 << 14)
+#define ISCR_FORCE_VBUS_MASK (3 << 12)
+#define ISCR_FORCE_VBUS_LOW (2 << 12)
+#define ISCR_FORCE_VBUS_HIGH (3 << 12)
+
/* Common Control Bits for Both PHYs */
#define PHY_PLL_BW 0x03
#define PHY_RES45_CAL_EN 0x0c
@@ -61,6 +78,13 @@
#define MAX_PHYS 3
+/*
+ * Note do not raise the debounce time, we must report Vusb high within 100ms
+ * otherwise we get Vbus errors
+ */
+#define DEBOUNCE_TIME msecs_to_jiffies(50)
+#define POLL_TIME msecs_to_jiffies(250)
+
struct sun4i_usb_phy_data {
void __iomem *base;
struct mutex mutex;
@@ -74,11 +98,55 @@ struct sun4i_usb_phy_data {
struct clk *clk;
int index;
} phys[MAX_PHYS];
+ /* phy0 / otg related variables */
+ struct extcon_dev extcon;
+ const char *extcon_cable_names[3];
+ bool phy0_init;
+ bool phy0_poll;
+ struct gpio_desc *id_det_gpio;
+ struct gpio_desc *vbus_det_gpio;
+ int id_det_irq;
+ int vbus_det_irq;
+ int id_det;
+ int vbus_det;
+ struct delayed_work detect;
};
#define to_sun4i_usb_phy_data(phy) \
container_of((phy), struct sun4i_usb_phy_data, phys[(phy)->index])
+static void sun4i_usb_phy0_update_iscr(struct phy *_phy, u32 clr, u32 set)
+{
+ struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
+ struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
+ u32 iscr;
+
+ iscr = readl(data->base + REG_ISCR);
+ iscr &= ~clr;
+ iscr |= set;
+ writel(iscr, data->base + REG_ISCR);
+}
+
+static void sun4i_usb_phy0_set_id_detect(struct phy *phy, u32 val)
+{
+ if (val)
+ val = ISCR_FORCE_ID_HIGH;
+ else
+ val = ISCR_FORCE_ID_LOW;
+
+ sun4i_usb_phy0_update_iscr(phy, ISCR_FORCE_ID_MASK, val);
+}
+
+static void sun4i_usb_phy0_set_vbus_detect(struct phy *phy, u32 val)
+{
+ if (val)
+ val = ISCR_FORCE_VBUS_HIGH;
+ else
+ val = ISCR_FORCE_VBUS_LOW;
+
+ sun4i_usb_phy0_update_iscr(phy, ISCR_FORCE_VBUS_MASK, val);
+}
+
static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data,
int len)
{
@@ -169,12 +237,39 @@ static int sun4i_usb_phy_init(struct phy *_phy)
sun4i_usb_phy_passby(phy, 1);
+ if (phy->index == 0) {
+ data->phy0_init = true;
+
+ /* Enable pull-ups */
+ sun4i_usb_phy0_update_iscr(_phy, 0, ISCR_DPDM_PULLUP_EN);
+ sun4i_usb_phy0_update_iscr(_phy, 0, ISCR_ID_PULLUP_EN);
+
+ if (data->id_det_gpio) {
+ /* OTG mode, force ISCR and cable state updates */
+ data->id_det = -1;
+ data->vbus_det = -1;
+ queue_delayed_work(system_wq, &data->detect, 0);
+ } else {
+ /* Host only mode */
+ sun4i_usb_phy0_set_id_detect(_phy, 0);
+ sun4i_usb_phy0_set_vbus_detect(_phy, 1);
+ }
+ }
+
return 0;
}
static int sun4i_usb_phy_exit(struct phy *_phy)
{
struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
+ struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
+
+ if (phy->index == 0) {
+ /* Disable pull-ups */
+ sun4i_usb_phy0_update_iscr(_phy, ISCR_DPDM_PULLUP_EN, 0);
+ sun4i_usb_phy0_update_iscr(_phy, ISCR_ID_PULLUP_EN, 0);
+ data->phy0_init = false;
+ }
sun4i_usb_phy_passby(phy, 0);
reset_control_assert(phy->reset);
@@ -186,20 +281,43 @@ static int sun4i_usb_phy_exit(struct phy *_phy)
static int sun4i_usb_phy_power_on(struct phy *_phy)
{
struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
- int ret = 0;
+ struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
+ int ret;
+
+ if (!phy->vbus)
+ return 0;
- if (phy->vbus)
- ret = regulator_enable(phy->vbus);
+ /* For phy0 only turn on Vbus if we don't have an ext. Vbus */
+ if (phy->index == 0 && data->vbus_det)
+ return 0;
- return ret;
+ ret = regulator_enable(phy->vbus);
+ if (ret)
+ return ret;
+
+ /* We must report Vbus high within OTG_TIME_A_WAIT_VRISE msec. */
+ if (phy->index == 0 && data->phy0_poll)
+ mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
+
+ return 0;
}
static int sun4i_usb_phy_power_off(struct phy *_phy)
{
struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
+ struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
+
+ if (!phy->vbus)
+ return 0;
- if (phy->vbus)
- regulator_disable(phy->vbus);
+ regulator_disable(phy->vbus);
+
+ /*
+ * phy0 vbus typically slowly discharges, sometimes this causes the
+ * Vbus gpio to not trigger an edge irq on Vbus off, so force a rescan.
+ */
+ if (phy->index == 0 && !data->phy0_poll)
+ mod_delayed_work(system_wq, &data->detect, POLL_TIME);
return 0;
}
@@ -212,6 +330,61 @@ static struct phy_ops sun4i_usb_phy_ops = {
.owner = THIS_MODULE,
};
+static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
+{
+ struct sun4i_usb_phy_data *data =
+ container_of(work, struct sun4i_usb_phy_data, detect.work);
+ struct phy *phy0 = data->phys[0].phy;
+ int id_det, vbus_det, id_notify = 0, vbus_notify = 0;
+
+ id_det = gpiod_get_value_cansleep(data->id_det_gpio);
+ vbus_det = gpiod_get_value_cansleep(data->vbus_det_gpio);
+
+ mutex_lock(&phy0->mutex);
+
+ if (!data->phy0_init) {
+ mutex_unlock(&phy0->mutex);
+ return;
+ }
+
+ if (id_det != data->id_det) {
+ sun4i_usb_phy0_set_id_detect(phy0, id_det);
+ data->id_det = id_det;
+ id_notify = 1;
+ }
+
+ if (vbus_det != data->vbus_det) {
+ sun4i_usb_phy0_set_vbus_detect(phy0, vbus_det);
+ data->vbus_det = vbus_det;
+ vbus_notify = 1;
+ }
+
+ mutex_unlock(&phy0->mutex);
+
+ if (id_notify)
+ extcon_set_cable_state(&data->extcon,
+ extcon_cable_name[EXTCON_USB_HOST],
+ !id_det);
+
+ if (vbus_notify)
+ extcon_set_cable_state(&data->extcon,
+ extcon_cable_name[EXTCON_USB],
+ vbus_det);
+
+ if (data->phy0_poll)
+ queue_delayed_work(system_wq, &data->detect, POLL_TIME);
+}
+
+static irqreturn_t sun4i_usb_phy0_id_vbus_det_irq(int irq, void *dev_id)
+{
+ struct sun4i_usb_phy_data *data = dev_id;
+
+ /* vbus or id changed, let the pins settle and then scan them */
+ mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
+
+ return IRQ_HANDLED;
+}
+
static struct phy *sun4i_usb_phy_xlate(struct device *dev,
struct of_phandle_args *args)
{
@@ -231,13 +404,20 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
struct phy_provider *phy_provider;
bool dedicated_clocks;
struct resource *res;
- int i;
+ int i, ret;
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
mutex_init(&data->mutex);
+ INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan);
+ data->extcon_cable_names[0] = extcon_cable_name[EXTCON_USB_HOST];
+ data->extcon_cable_names[1] = extcon_cable_name[EXTCON_USB];
+ data->extcon_cable_names[2] = NULL;
+ data->extcon.name = DRIVER_NAME;
+ data->extcon.supported_cable = data->extcon_cable_names;
+ data->extcon.dev.parent = dev;
if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy"))
data->num_phys = 2;
@@ -260,6 +440,34 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
if (IS_ERR(data->base))
return PTR_ERR(data->base);
+ data->id_det_gpio = devm_gpiod_get(dev, "usb0_id_det", GPIOD_IN);
+ if (IS_ERR(data->id_det_gpio)) {
+ if (PTR_ERR(data->id_det_gpio) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+ data->id_det_gpio = NULL;
+ }
+
+ data->vbus_det_gpio = devm_gpiod_get(dev, "usb0_vbus_det", GPIOD_IN);
+ if (IS_ERR(data->vbus_det_gpio)) {
+ if (PTR_ERR(data->vbus_det_gpio) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+ data->vbus_det_gpio = NULL;
+ }
+
+ /* We either want both gpio pins or neither (when in host mode) */
+ if (!data->id_det_gpio != !data->vbus_det_gpio) {
+ dev_err(dev, "failed to get id or vbus detect pin\n");
+ return -ENODEV;
+ }
+
+ if (data->id_det_gpio) {
+ ret = devm_extcon_dev_register(dev, &data->extcon);
+ if (ret) {
+ dev_err(dev, "failed to register extcon: %d\n", ret);
+ return ret;
+ }
+ }
+
for (i = 0; i < data->num_phys; i++) {
struct sun4i_usb_phy *phy = data->phys + i;
char name[16];
@@ -309,12 +517,54 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
phy_set_drvdata(phy->phy, &data->phys[i]);
}
+ data->id_det_irq = gpiod_to_irq(data->id_det_gpio);
+ data->vbus_det_irq = gpiod_to_irq(data->vbus_det_gpio);
+ if (data->id_det_irq < 0 || data->vbus_det_irq < 0)
+ data->phy0_poll = true;
+
+ if (data->id_det_irq >= 0) {
+ ret = devm_request_irq(dev, data->id_det_irq,
+ sun4i_usb_phy0_id_vbus_det_irq,
+ IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+ "usb0-id-det", data);
+ if (ret) {
+ dev_err(dev, "Err requesting id-det-irq: %d\n", ret);
+ return ret;
+ }
+ }
+
+ if (data->vbus_det_irq >= 0) {
+ ret = devm_request_irq(dev, data->vbus_det_irq,
+ sun4i_usb_phy0_id_vbus_det_irq,
+ IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+ "usb0-vbus-det", data);
+ if (ret) {
+ dev_err(dev, "Err requesting vbus-det-irq: %d\n", ret);
+ return ret;
+ }
+ }
+
dev_set_drvdata(dev, data);
phy_provider = devm_of_phy_provider_register(dev, sun4i_usb_phy_xlate);
return PTR_ERR_OR_ZERO(phy_provider);
}
+static int sun4i_usb_phy_remove(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
+
+ if (data->id_det_irq >= 0)
+ devm_free_irq(dev, data->id_det_irq, data);
+ if (data->vbus_det_irq >= 0)
+ devm_free_irq(dev, data->vbus_det_irq, data);
+
+ cancel_delayed_work_sync(&data->detect);
+
+ return 0;
+}
+
static const struct of_device_id sun4i_usb_phy_of_match[] = {
{ .compatible = "allwinner,sun4i-a10-usb-phy" },
{ .compatible = "allwinner,sun5i-a13-usb-phy" },
@@ -326,9 +576,10 @@ MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match);
static struct platform_driver sun4i_usb_phy_driver = {
.probe = sun4i_usb_phy_probe,
+ .remove = sun4i_usb_phy_remove,
.driver = {
.of_match_table = sun4i_usb_phy_of_match,
- .name = "sun4i-usb-phy",
+ .name = DRIVER_NAME,
}
};
module_platform_driver(sun4i_usb_phy_driver);
--
2.3.3
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v2 02/13] musb: Make musb_write_rxfun* and musb_write_rxhub* work like their tx versions
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-03-20 19:11 ` [PATCH v2 01/13] phy-sun4i-usb: Add full support for usb0 phy / OTG Hans de Goede
@ 2015-03-20 19:11 ` Hans de Goede
2015-03-20 19:11 ` [PATCH v2 03/13] musb: Make busctl_offset an io-op rather then a define Hans de Goede
` (11 subsequent siblings)
13 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
For some reason the musb_write_rxfun* and musb_write_rxhub* functions had
a different function prototype and some extra magic needed on the caller side
compared to their tx counterparts, this commit makes them work the same as
their tx counterparts.
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
drivers/usb/musb/musb_core.c | 11 +++--------
drivers/usb/musb/musb_core.h | 2 --
drivers/usb/musb/musb_host.c | 12 ++++++------
drivers/usb/musb/musb_regs.h | 31 ++++++++++++-------------------
4 files changed, 21 insertions(+), 35 deletions(-)
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 067920f..e2892fa 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1546,7 +1546,6 @@ static int musb_core_init(u16 musb_type, struct musb *musb)
#endif
hw_ep->regs = musb->io.ep_offset(i, 0) + mbase;
- hw_ep->target_regs = musb_read_target_reg_base(i, mbase);
hw_ep->rx_reinit = 1;
hw_ep->tx_reinit = 1;
@@ -2334,7 +2333,6 @@ static void musb_restore_context(struct musb *musb)
{
int i;
void __iomem *musb_base = musb->mregs;
- void __iomem *ep_target_regs;
void __iomem *epio;
u8 power;
@@ -2402,14 +2400,11 @@ static void musb_restore_context(struct musb *musb)
musb_write_txhubport(musb_base, i,
musb->context.index_regs[i].txhubport);
- ep_target_regs =
- musb_read_target_reg_base(i, musb_base);
-
- musb_write_rxfunaddr(ep_target_regs,
+ musb_write_rxfunaddr(musb_base, i,
musb->context.index_regs[i].rxfunaddr);
- musb_write_rxhubaddr(ep_target_regs,
+ musb_write_rxhubaddr(musb_base, i,
musb->context.index_regs[i].rxhubaddr);
- musb_write_rxhubport(ep_target_regs,
+ musb_write_rxhubport(musb_base, i,
musb->context.index_regs[i].rxhubport);
}
musb_writeb(musb_base, MUSB_INDEX, musb->context.index);
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 5e65958..a31d709 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -240,8 +240,6 @@ struct musb_hw_ep {
void __iomem *fifo_sync_va;
#endif
- void __iomem *target_regs;
-
/* currently scheduled peripheral endpoint */
struct musb_qh *in_qh;
struct musb_qh *out_qh;
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index c3d5fc9..c4732a7 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -555,8 +555,9 @@ musb_host_packet_rx(struct musb *musb, struct urb *urb, u8 epnum, u8 iso_err)
* the busy/not-empty tests are basically paranoia.
*/
static void
-musb_rx_reinit(struct musb *musb, struct musb_qh *qh, struct musb_hw_ep *ep)
+musb_rx_reinit(struct musb *musb, struct musb_qh *qh, u8 epnum)
{
+ struct musb_hw_ep *ep = musb->endpoints + epnum;
u16 csr;
/* NOTE: we know the "rx" fifo reinit never triggers for ep0.
@@ -594,10 +595,9 @@ musb_rx_reinit(struct musb *musb, struct musb_qh *qh, struct musb_hw_ep *ep)
/* target addr and (for multipoint) hub addr/port */
if (musb->is_multipoint) {
- musb_write_rxfunaddr(ep->target_regs, qh->addr_reg);
- musb_write_rxhubaddr(ep->target_regs, qh->h_addr_reg);
- musb_write_rxhubport(ep->target_regs, qh->h_port_reg);
-
+ musb_write_rxfunaddr(musb->mregs, epnum, qh->addr_reg);
+ musb_write_rxhubaddr(musb->mregs, epnum, qh->h_addr_reg);
+ musb_write_rxhubport(musb->mregs, epnum, qh->h_port_reg);
} else
musb_writeb(musb->mregs, MUSB_FADDR, qh->addr_reg);
@@ -875,7 +875,7 @@ finish:
u16 csr;
if (hw_ep->rx_reinit) {
- musb_rx_reinit(musb, qh, hw_ep);
+ musb_rx_reinit(musb, qh, epnum);
/* init new state: toggle and NYET, maybe DMA later */
if (usb_gettoggle(urb->dev, qh->epnum, 0))
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h
index 11f0be0..edfc730 100644
--- a/drivers/usb/musb/musb_regs.h
+++ b/drivers/usb/musb/musb_regs.h
@@ -364,27 +364,25 @@ static inline u16 musb_read_hwvers(void __iomem *mbase)
return musb_readw(mbase, MUSB_HWVERS);
}
-static inline void __iomem *musb_read_target_reg_base(u8 i, void __iomem *mbase)
-{
- return (MUSB_BUSCTL_OFFSET(i, 0) + mbase);
-}
-
-static inline void musb_write_rxfunaddr(void __iomem *ep_target_regs,
+static inline void musb_write_rxfunaddr(void __iomem *mbase, u8 epnum,
u8 qh_addr_reg)
{
- musb_writeb(ep_target_regs, MUSB_RXFUNCADDR, qh_addr_reg);
+ musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXFUNCADDR),
+ qh_addr_reg);
}
-static inline void musb_write_rxhubaddr(void __iomem *ep_target_regs,
+static inline void musb_write_rxhubaddr(void __iomem *mbase, u8 epnum,
u8 qh_h_addr_reg)
{
- musb_writeb(ep_target_regs, MUSB_RXHUBADDR, qh_h_addr_reg);
+ musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXHUBADDR),
+ qh_h_addr_reg);
}
-static inline void musb_write_rxhubport(void __iomem *ep_target_regs,
+static inline void musb_write_rxhubport(void __iomem *mbase, u8 epnum,
u8 qh_h_port_reg)
{
- musb_writeb(ep_target_regs, MUSB_RXHUBPORT, qh_h_port_reg);
+ musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXHUBPORT),
+ qh_h_port_reg);
}
static inline void musb_write_txfunaddr(void __iomem *mbase, u8 epnum,
@@ -556,22 +554,17 @@ static inline u16 musb_read_hwvers(void __iomem *mbase)
return MUSB_HWVERS_1900;
}
-static inline void __iomem *musb_read_target_reg_base(u8 i, void __iomem *mbase)
-{
- return NULL;
-}
-
-static inline void musb_write_rxfunaddr(void __iomem *ep_target_regs,
+static inline void musb_write_rxfunaddr(void __iomem *mbase, u8 epnum,
u8 qh_addr_req)
{
}
-static inline void musb_write_rxhubaddr(void __iomem *ep_target_regs,
+static inline void musb_write_rxhubaddr(void __iomem *mbase, u8 epnum,
u8 qh_h_addr_reg)
{
}
-static inline void musb_write_rxhubport(void __iomem *ep_target_regs,
+static inline void musb_write_rxhubport(void __iomem *mbase, u8 epnum,
u8 qh_h_port_reg)
{
}
--
2.3.3
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v2 03/13] musb: Make busctl_offset an io-op rather then a define
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-03-20 19:11 ` [PATCH v2 01/13] phy-sun4i-usb: Add full support for usb0 phy / OTG Hans de Goede
2015-03-20 19:11 ` [PATCH v2 02/13] musb: Make musb_write_rxfun* and musb_write_rxhub* work like their tx versions Hans de Goede
@ 2015-03-20 19:11 ` Hans de Goede
2015-03-20 19:11 ` [PATCH v2 04/13] musb: Do not use musb_read[b|w] / _write[b|w] wrappers in generic fifo functions Hans de Goede
` (10 subsequent siblings)
13 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
The Allwinner (sunxi) implementation of the musb has its busctl registers
indexed by the MUSB_INDEX register rather then in a flat address space.
This commit turns MUSB_BUSCTL_OFFSET from a macro into an io-op which can
be overridden from the platform ops.
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
drivers/usb/musb/musb_core.c | 34 +++++++++++++++---------
drivers/usb/musb/musb_core.h | 5 +++-
drivers/usb/musb/musb_host.c | 12 ++++-----
drivers/usb/musb/musb_io.h | 2 ++
drivers/usb/musb/musb_regs.h | 63 ++++++++++++++++++++++++--------------------
5 files changed, 68 insertions(+), 48 deletions(-)
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index e2892fa..01ed3a6 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -250,6 +250,11 @@ static u32 musb_indexed_ep_offset(u8 epnum, u16 offset)
return 0x10 + offset;
}
+static u32 musb_default_busctl_offset(u8 epnum, u16 offset)
+{
+ return 0x80 + (0x08 * epnum) + offset;
+}
+
static u8 musb_default_readb(const void __iomem *addr, unsigned offset)
{
return __raw_readb(addr + offset);
@@ -2041,6 +2046,11 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
else
musb->io.fifo_offset = musb_default_fifo_offset;
+ if (musb->ops->busctl_offset)
+ musb->io.busctl_offset = musb->ops->busctl_offset;
+ else
+ musb->io.busctl_offset = musb_default_busctl_offset;
+
if (musb->ops->readb)
musb_readb = musb->ops->readb;
if (musb->ops->writeb)
@@ -2314,18 +2324,18 @@ static void musb_save_context(struct musb *musb)
musb_readb(epio, MUSB_RXINTERVAL);
musb->context.index_regs[i].txfunaddr =
- musb_read_txfunaddr(musb_base, i);
+ musb_read_txfunaddr(musb, i);
musb->context.index_regs[i].txhubaddr =
- musb_read_txhubaddr(musb_base, i);
+ musb_read_txhubaddr(musb, i);
musb->context.index_regs[i].txhubport =
- musb_read_txhubport(musb_base, i);
+ musb_read_txhubport(musb, i);
musb->context.index_regs[i].rxfunaddr =
- musb_read_rxfunaddr(musb_base, i);
+ musb_read_rxfunaddr(musb, i);
musb->context.index_regs[i].rxhubaddr =
- musb_read_rxhubaddr(musb_base, i);
+ musb_read_rxhubaddr(musb, i);
musb->context.index_regs[i].rxhubport =
- musb_read_rxhubport(musb_base, i);
+ musb_read_rxhubport(musb, i);
}
}
@@ -2393,18 +2403,18 @@ static void musb_restore_context(struct musb *musb)
musb_writeb(epio, MUSB_RXINTERVAL,
musb->context.index_regs[i].rxinterval);
- musb_write_txfunaddr(musb_base, i,
+ musb_write_txfunaddr(musb, i,
musb->context.index_regs[i].txfunaddr);
- musb_write_txhubaddr(musb_base, i,
+ musb_write_txhubaddr(musb, i,
musb->context.index_regs[i].txhubaddr);
- musb_write_txhubport(musb_base, i,
+ musb_write_txhubport(musb, i,
musb->context.index_regs[i].txhubport);
- musb_write_rxfunaddr(musb_base, i,
+ musb_write_rxfunaddr(musb, i,
musb->context.index_regs[i].rxfunaddr);
- musb_write_rxhubaddr(musb_base, i,
+ musb_write_rxhubaddr(musb, i,
musb->context.index_regs[i].rxhubaddr);
- musb_write_rxhubport(musb_base, i,
+ musb_write_rxhubport(musb, i,
musb->context.index_regs[i].rxhubport);
}
musb_writeb(musb_base, MUSB_INDEX, musb->context.index);
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index a31d709..ba8dd78 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -67,7 +67,6 @@ struct musb_ep;
#include "musb_dma.h"
#include "musb_io.h"
-#include "musb_regs.h"
#include "musb_gadget.h"
#include <linux/usb/hcd.h>
@@ -186,6 +185,7 @@ struct musb_platform_ops {
void (*ep_select)(void __iomem *mbase, u8 epnum);
u16 fifo_mode;
u32 (*fifo_offset)(u8 epnum);
+ u32 (*busctl_offset)(u8 epnum, u16 offset);
u8 (*readb)(const void __iomem *addr, unsigned offset);
void (*writeb)(void __iomem *addr, unsigned offset, u8 data);
u16 (*readw)(const void __iomem *addr, unsigned offset);
@@ -435,6 +435,9 @@ struct musb {
#endif
};
+/* This must be included after struct musb is defined */
+#include "musb_regs.h"
+
static inline struct musb *gadget_to_musb(struct usb_gadget *g)
{
return container_of(g, struct musb, g);
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index c4732a7..cae14e3 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -595,9 +595,9 @@ musb_rx_reinit(struct musb *musb, struct musb_qh *qh, u8 epnum)
/* target addr and (for multipoint) hub addr/port */
if (musb->is_multipoint) {
- musb_write_rxfunaddr(musb->mregs, epnum, qh->addr_reg);
- musb_write_rxhubaddr(musb->mregs, epnum, qh->h_addr_reg);
- musb_write_rxhubport(musb->mregs, epnum, qh->h_port_reg);
+ musb_write_rxfunaddr(musb, epnum, qh->addr_reg);
+ musb_write_rxhubaddr(musb, epnum, qh->h_addr_reg);
+ musb_write_rxhubport(musb, epnum, qh->h_port_reg);
} else
musb_writeb(musb->mregs, MUSB_FADDR, qh->addr_reg);
@@ -801,9 +801,9 @@ static void musb_ep_program(struct musb *musb, u8 epnum,
/* target addr and (for multipoint) hub addr/port */
if (musb->is_multipoint) {
- musb_write_txfunaddr(mbase, epnum, qh->addr_reg);
- musb_write_txhubaddr(mbase, epnum, qh->h_addr_reg);
- musb_write_txhubport(mbase, epnum, qh->h_port_reg);
+ musb_write_txfunaddr(musb, epnum, qh->addr_reg);
+ musb_write_txhubaddr(musb, epnum, qh->h_addr_reg);
+ musb_write_txhubport(musb, epnum, qh->h_port_reg);
/* FIXME if !epnum, do the same for RX ... */
} else
musb_writeb(mbase, MUSB_FADDR, qh->addr_reg);
diff --git a/drivers/usb/musb/musb_io.h b/drivers/usb/musb/musb_io.h
index 8a57a6f..17a80ae 100644
--- a/drivers/usb/musb/musb_io.h
+++ b/drivers/usb/musb/musb_io.h
@@ -47,6 +47,7 @@
* @fifo_offset: platform specific function to get fifo offset
* @read_fifo: platform specific function to read fifo
* @write_fifo: platform specific function to write fifo
+ * @busctl_offset: platform specific function to get busctl offset
*/
struct musb_io {
u32 quirks;
@@ -55,6 +56,7 @@ struct musb_io {
u32 (*fifo_offset)(u8 epnum);
void (*read_fifo)(struct musb_hw_ep *hw_ep, u16 len, u8 *buf);
void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf);
+ u32 (*busctl_offset)(u8 epnum, u16 offset);
};
/* Do not add new entries here, add them the struct musb_io instead */
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h
index edfc730..cff5bcf 100644
--- a/drivers/usb/musb/musb_regs.h
+++ b/drivers/usb/musb/musb_regs.h
@@ -300,9 +300,6 @@
#define MUSB_RXHUBADDR 0x06
#define MUSB_RXHUBPORT 0x07
-#define MUSB_BUSCTL_OFFSET(_epnum, _offset) \
- (0x80 + (8*(_epnum)) + (_offset))
-
static inline void musb_write_txfifosz(void __iomem *mbase, u8 c_size)
{
musb_writeb(mbase, MUSB_TXFIFOSZ, c_size);
@@ -364,76 +361,84 @@ static inline u16 musb_read_hwvers(void __iomem *mbase)
return musb_readw(mbase, MUSB_HWVERS);
}
-static inline void musb_write_rxfunaddr(void __iomem *mbase, u8 epnum,
+static inline void musb_write_rxfunaddr(struct musb *musb, u8 epnum,
u8 qh_addr_reg)
{
- musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXFUNCADDR),
- qh_addr_reg);
+ musb_writeb(musb->mregs,
+ musb->io.busctl_offset(epnum, MUSB_RXFUNCADDR),
+ qh_addr_reg);
}
-static inline void musb_write_rxhubaddr(void __iomem *mbase, u8 epnum,
+static inline void musb_write_rxhubaddr(struct musb *musb, u8 epnum,
u8 qh_h_addr_reg)
{
- musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXHUBADDR),
+ musb_writeb(musb->mregs, musb->io.busctl_offset(epnum, MUSB_RXHUBADDR),
qh_h_addr_reg);
}
-static inline void musb_write_rxhubport(void __iomem *mbase, u8 epnum,
+static inline void musb_write_rxhubport(struct musb *musb, u8 epnum,
u8 qh_h_port_reg)
{
- musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXHUBPORT),
+ musb_writeb(musb->mregs, musb->io.busctl_offset(epnum, MUSB_RXHUBPORT),
qh_h_port_reg);
}
-static inline void musb_write_txfunaddr(void __iomem *mbase, u8 epnum,
+static inline void musb_write_txfunaddr(struct musb *musb, u8 epnum,
u8 qh_addr_reg)
{
- musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXFUNCADDR),
- qh_addr_reg);
+ musb_writeb(musb->mregs,
+ musb->io.busctl_offset(epnum, MUSB_TXFUNCADDR),
+ qh_addr_reg);
}
-static inline void musb_write_txhubaddr(void __iomem *mbase, u8 epnum,
+static inline void musb_write_txhubaddr(struct musb *musb, u8 epnum,
u8 qh_addr_reg)
{
- musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBADDR),
+ musb_writeb(musb->mregs, musb->io.busctl_offset(epnum, MUSB_TXHUBADDR),
qh_addr_reg);
}
-static inline void musb_write_txhubport(void __iomem *mbase, u8 epnum,
+static inline void musb_write_txhubport(struct musb *musb, u8 epnum,
u8 qh_h_port_reg)
{
- musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBPORT),
+ musb_writeb(musb->mregs, musb->io.busctl_offset(epnum, MUSB_TXHUBPORT),
qh_h_port_reg);
}
-static inline u8 musb_read_rxfunaddr(void __iomem *mbase, u8 epnum)
+static inline u8 musb_read_rxfunaddr(struct musb *musb, u8 epnum)
{
- return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXFUNCADDR));
+ return musb_readb(musb->mregs,
+ musb->io.busctl_offset(epnum, MUSB_RXFUNCADDR));
}
-static inline u8 musb_read_rxhubaddr(void __iomem *mbase, u8 epnum)
+static inline u8 musb_read_rxhubaddr(struct musb *musb, u8 epnum)
{
- return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXHUBADDR));
+ return musb_readb(musb->mregs,
+ musb->io.busctl_offset(epnum, MUSB_RXHUBADDR));
}
-static inline u8 musb_read_rxhubport(void __iomem *mbase, u8 epnum)
+static inline u8 musb_read_rxhubport(struct musb *musb, u8 epnum)
{
- return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXHUBPORT));
+ return musb_readb(musb->mregs,
+ musb->io.busctl_offset(epnum, MUSB_RXHUBPORT));
}
-static inline u8 musb_read_txfunaddr(void __iomem *mbase, u8 epnum)
+static inline u8 musb_read_txfunaddr(struct musb *musb, u8 epnum)
{
- return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXFUNCADDR));
+ return musb_readb(musb->mregs,
+ musb->io.busctl_offset(epnum, MUSB_TXFUNCADDR));
}
-static inline u8 musb_read_txhubaddr(void __iomem *mbase, u8 epnum)
+static inline u8 musb_read_txhubaddr(struct musb *musb, u8 epnum)
{
- return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBADDR));
+ return musb_readb(musb->mregs,
+ musb->io.busctl_offset(epnum, MUSB_TXHUBADDR));
}
-static inline u8 musb_read_txhubport(void __iomem *mbase, u8 epnum)
+static inline u8 musb_read_txhubport(struct musb *musb, u8 epnum)
{
- return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBPORT));
+ return musb_readb(musb->mregs,
+ musb->io.busctl_offset(epnum, MUSB_TXHUBPORT));
}
#else /* CONFIG_BLACKFIN */
--
2.3.3
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v2 04/13] musb: Do not use musb_read[b|w] / _write[b|w] wrappers in generic fifo functions
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
` (2 preceding siblings ...)
2015-03-20 19:11 ` [PATCH v2 03/13] musb: Make busctl_offset an io-op rather then a define Hans de Goede
@ 2015-03-20 19:11 ` Hans de Goede
[not found] ` <1426878682-14521-5-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-03-20 19:11 ` [PATCH v2 05/13] musb: Fix platform code being unable to override ep access ops Hans de Goede
` (9 subsequent siblings)
13 siblings, 1 reply; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
The generic fifo functions already use non wrapped accesses in various
cases through the iowrite#_rep functions, and all platforms which override
the default musb_read[b|w] / _write[b|w] functions also provide their own
fifo access functions, so we can safely drop the unnecessary indirection
from the fifo access functions.
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
drivers/usb/musb/musb_core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 01ed3a6..016b5b9 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -313,7 +313,7 @@ static void musb_default_write_fifo(struct musb_hw_ep *hw_ep, u16 len,
index += len & ~0x03;
}
if (len & 0x02) {
- musb_writew(fifo, 0, *(u16 *)&src[index]);
+ __raw_writew(*(u16 *)&src[index], fifo);
index += 2;
}
} else {
@@ -323,7 +323,7 @@ static void musb_default_write_fifo(struct musb_hw_ep *hw_ep, u16 len,
}
}
if (len & 0x01)
- musb_writeb(fifo, 0, src[index]);
+ __raw_writeb(src[index], fifo);
} else {
/* byte aligned */
iowrite8_rep(fifo, src, len);
@@ -355,7 +355,7 @@ static void musb_default_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
index = len & ~0x03;
}
if (len & 0x02) {
- *(u16 *)&dst[index] = musb_readw(fifo, 0);
+ *(u16 *)&dst[index] = __raw_readw(fifo);
index += 2;
}
} else {
@@ -365,7 +365,7 @@ static void musb_default_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
}
}
if (len & 0x01)
- dst[index] = musb_readb(fifo, 0);
+ dst[index] = __raw_readb(fifo);
} else {
/* byte aligned */
ioread8_rep(fifo, dst, len);
--
2.3.3
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v2 05/13] musb: Fix platform code being unable to override ep access ops
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
` (3 preceding siblings ...)
2015-03-20 19:11 ` [PATCH v2 04/13] musb: Do not use musb_read[b|w] / _write[b|w] wrappers in generic fifo functions Hans de Goede
@ 2015-03-20 19:11 ` Hans de Goede
2015-03-20 19:11 ` [PATCH v2 06/13] musb: Add support for the Allwinner sunxi musb controller Hans de Goede
` (8 subsequent siblings)
13 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
musb-core was setting the ops to the default indexed or flat handlers after
checking for platform overrides. Reverse the order of this so that platform
overrides actually work.
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
drivers/usb/musb/musb_core.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 016b5b9..6e9b839 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -2021,13 +2021,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
if (musb->ops->quirks)
musb->io.quirks = musb->ops->quirks;
- /* At least tusb6010 has it's own offsets.. */
- if (musb->ops->ep_offset)
- musb->io.ep_offset = musb->ops->ep_offset;
- if (musb->ops->ep_select)
- musb->io.ep_select = musb->ops->ep_select;
-
- /* ..and some devices use indexed offset or flat offset */
+ /* Set default ep access to indexed offset or flat offset ops */
if (musb->io.quirks & MUSB_INDEXED_EP) {
musb->io.ep_offset = musb_indexed_ep_offset;
musb->io.ep_select = musb_indexed_ep_select;
@@ -2035,6 +2029,11 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
musb->io.ep_offset = musb_flat_ep_offset;
musb->io.ep_select = musb_flat_ep_select;
}
+ /* And override them with platform specific ops if specified. */
+ if (musb->ops->ep_offset)
+ musb->io.ep_offset = musb->ops->ep_offset;
+ if (musb->ops->ep_select)
+ musb->io.ep_select = musb->ops->ep_select;
if (musb->ops->fifo_mode)
fifo_mode = musb->ops->fifo_mode;
--
2.3.3
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v2 06/13] musb: Add support for the Allwinner sunxi musb controller
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
` (4 preceding siblings ...)
2015-03-20 19:11 ` [PATCH v2 05/13] musb: Fix platform code being unable to override ep access ops Hans de Goede
@ 2015-03-20 19:11 ` Hans de Goede
[not found] ` <1426878682-14521-7-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-03-20 19:11 ` [PATCH v2 07/13] ARM: dts: sun4i: Add USB Dual Role Controller Hans de Goede
` (7 subsequent siblings)
13 siblings, 1 reply; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
This is based on initial code to get the Allwinner sunxi musb controller
supported by Chen-Yu Tsai and Roman Byshko.
This adds support for the Allwinner sunxi musb controller in both host only
and otg mode. Peripheral only mode is not supported, as no boards use that.
This has been tested on a cubietruck (A20 SoC) and an UTOO P66 tablet
(A13 SoC) with a variety of devices in host mode and with the g_serial gadget
driver in peripheral mode, plugging otg / host cables in/out a lot of times
in all possible imaginable plug orders.
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
.../bindings/usb/allwinner,sun4i-a10-musb.txt | 25 +
drivers/usb/musb/Kconfig | 12 +-
drivers/usb/musb/Makefile | 1 +
drivers/usb/musb/musb_core.h | 1 +
drivers/usb/musb/musb_gadget.c | 6 +
drivers/usb/musb/musb_virthub.c | 6 +
drivers/usb/musb/sunxi.c | 671 +++++++++++++++++++++
7 files changed, 721 insertions(+), 1 deletion(-)
create mode 100644 Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
create mode 100644 drivers/usb/musb/sunxi.c
diff --git a/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
new file mode 100644
index 0000000..21dfc7f
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
@@ -0,0 +1,25 @@
+Allwinner sun4i A10 musb DRC/OTG controller
+-------------------------------------------
+
+Required properties:
+ - compatible : "allwinner,sun4i-a10-musb"
+ - reg : mmio address range of the musb controller
+ - clocks : clock specifier for the musb controller ahb gate clock
+ - interrupts : interrupt to which the musb controller is connected
+ - interrupt-names : must be "mc"
+ - phys : phy specifier for the otg phy
+ - phy-names : must be "usb"
+ - dr_mode : Dual-Role mode must be "host" or "otg"
+
+Example:
+
+ usb_otg: usb@01c13000 {
+ compatible = "allwinner,sun4i-a10-musb";
+ reg = <0x01c13000 0x0400>;
+ clocks = <&ahb_gates 0>;
+ interrupts = <38>;
+ interrupt-names = "mc";
+ phys = <&usbphy 0>;
+ phy-names = "usb";
+ status = "disabled";
+ };
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 14e1628..c83cad1 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -5,7 +5,7 @@
# (M)HDRC = (Multipoint) Highspeed Dual-Role Controller
config USB_MUSB_HDRC
- tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
+ tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, AW, ...)'
depends on (USB || USB_GADGET)
help
Say Y here if your system has a dual role high speed USB
@@ -20,6 +20,8 @@ config USB_MUSB_HDRC
Analog Devices parts using this IP include Blackfin BF54x,
BF525 and BF527.
+ Allwinner SoCs using this IP include A10, A13, A20, ...
+
If you do not know what this is, please say N.
To compile this driver as a module, choose M here; the
@@ -60,6 +62,14 @@ endchoice
comment "Platform Glue Layer"
+config USB_MUSB_SUNXI
+ tristate "Allwinner (sunxi)"
+ depends on ARCH_SUNXI
+ depends on NOP_USB_XCEIV
+ select EXTCON
+ select GENERIC_PHY
+ select SUNXI_SRAM
+
config USB_MUSB_DAVINCI
tristate "DaVinci"
depends on ARCH_DAVINCI_DMx
diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
index ba49501..f95befe 100644
--- a/drivers/usb/musb/Makefile
+++ b/drivers/usb/musb/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o
obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o
obj-$(CONFIG_USB_MUSB_UX500) += ux500.o
obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o
+obj-$(CONFIG_USB_MUSB_SUNXI) += sunxi.o
obj-$(CONFIG_USB_MUSB_AM335X_CHILD) += musb_am335x.o
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index ba8dd78..444b936 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -166,6 +166,7 @@ struct musb_io;
*/
struct musb_platform_ops {
+#define MUSB_SUN4I BIT(7)
#define MUSB_DMA_UX500 BIT(6)
#define MUSB_DMA_CPPI41 BIT(5)
#define MUSB_DMA_CPPI BIT(4)
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index b2d9040..7d13eb9 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -2041,6 +2041,12 @@ void musb_g_disconnect(struct musb *musb)
spin_lock(&musb->lock);
}
+ /* On sunxi ep0 FADDR must be 0 when (re)entering peripheral mode */
+ if (musb->io.quirks & MUSB_SUN4I) {
+ musb_ep_select(musb->mregs, 0);
+ musb_writeb(musb->mregs, MUSB_FADDR, 0);
+ }
+
switch (musb->xceiv->otg->state) {
default:
dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n",
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index 294e159..3c87fd7 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -224,6 +224,12 @@ void musb_root_disconnect(struct musb *musb)
usb_hcd_poll_rh_status(musb->hcd);
musb->is_active = 0;
+ /* On sunxi ep0 FADDR must be 0 when (re)entering peripheral mode */
+ if (musb->io.quirks & MUSB_SUN4I) {
+ musb_ep_select(musb->mregs, 0);
+ musb_writeb(musb->mregs, MUSB_FADDR, 0);
+ }
+
switch (musb->xceiv->otg->state) {
case OTG_STATE_A_SUSPEND:
if (otg->host->b_hnp_enable) {
diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
new file mode 100644
index 0000000..64a95e4
--- /dev/null
+++ b/drivers/usb/musb/sunxi.c
@@ -0,0 +1,671 @@
+/*
+ * Allwinner sun4i MUSB Glue Layer
+ *
+ * Copyright (C) 2015 Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
+ *
+ * Based on code from
+ * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
+ *
+ * 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/clk.h>
+#include <linux/err.h>
+#include <linux/extcon.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/soc/sunxi/sunxi_sram.h>
+#include <linux/usb/musb.h>
+#include <linux/usb/of.h>
+#include <linux/usb/usb_phy_generic.h>
+#include <linux/workqueue.h>
+#include "musb_core.h"
+
+/*
+ * Register offsets, note sunxi musb has a different layout then most
+ * musb implementations, we translate the layout in musb_readb & friends.
+ */
+#define SUNXI_MUSB_POWER 0x0040
+#define SUNXI_MUSB_DEVCTL 0x0041
+#define SUNXI_MUSB_INDEX 0x0042
+#define SUNXI_MUSB_VEND0 0x0043
+#define SUNXI_MUSB_INTRTX 0x0044
+#define SUNXI_MUSB_INTRRX 0x0046
+#define SUNXI_MUSB_INTRTXE 0x0048
+#define SUNXI_MUSB_INTRRXE 0x004a
+#define SUNXI_MUSB_INTRUSB 0x004c
+#define SUNXI_MUSB_INTRUSBE 0x0050
+#define SUNXI_MUSB_FRAME 0x0054
+#define SUNXI_MUSB_TXFIFOSZ 0x0090
+#define SUNXI_MUSB_TXFIFOADD 0x0092
+#define SUNXI_MUSB_RXFIFOSZ 0x0094
+#define SUNXI_MUSB_RXFIFOADD 0x0096
+#define SUNXI_MUSB_FADDR 0x0098
+#define SUNXI_MUSB_TXFUNCADDR 0x0098
+#define SUNXI_MUSB_TXHUBADDR 0x009a
+#define SUNXI_MUSB_TXHUBPORT 0x009b
+#define SUNXI_MUSB_RXFUNCADDR 0x009c
+#define SUNXI_MUSB_RXHUBADDR 0x009e
+#define SUNXI_MUSB_RXHUBPORT 0x009f
+#define SUNXI_MUSB_CONFIGDATA 0x00c0
+
+/* VEND0 bits */
+#define SUNXI_MUSB_VEND0_PIO_MODE 0
+
+/* flags */
+#define SUNXI_MUSB_FL_ENABLED 0
+#define SUNXI_MUSB_FL_HOSTMODE 1
+#define SUNXI_MUSB_FL_HOSTMODE_PEND 2
+#define SUNXI_MUSB_FL_VBUS_ON 3
+#define SUNXI_MUSB_FL_PHY_ON 4
+
+/* Our read/write methods need access and do not get passed in a musb ref :| */
+struct musb *sunxi_musb;
+
+struct sunxi_glue {
+ struct device *dev;
+ struct platform_device *musb;
+ struct clk *clk;
+ struct phy *phy;
+ struct platform_device *usb_phy;
+ struct usb_phy *xceiv;
+ unsigned long flags;
+ struct work_struct work;
+ struct extcon_specific_cable_nb host_cable_nb;
+ struct notifier_block host_nb;
+};
+
+/* phy_power_on / off may sleep, so we use a workqueue */
+static void sunxi_musb_work(struct work_struct *work)
+{
+ struct sunxi_glue *glue = container_of(work, struct sunxi_glue, work);
+ bool vbus_on, phy_on;
+
+ if (!test_bit(SUNXI_MUSB_FL_ENABLED, &glue->flags))
+ return;
+
+ if (test_and_clear_bit(SUNXI_MUSB_FL_HOSTMODE_PEND, &glue->flags)) {
+ struct musb *musb = platform_get_drvdata(glue->musb);
+ unsigned long flags;
+ u8 devctl;
+
+ spin_lock_irqsave(&musb->lock, flags);
+
+ devctl = readb(musb->mregs + SUNXI_MUSB_DEVCTL);
+ if (test_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags)) {
+ set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
+ musb->xceiv->otg->default_a = 1;
+ musb->xceiv->otg->state = OTG_STATE_A_IDLE;
+ MUSB_HST_MODE(musb);
+ devctl |= MUSB_DEVCTL_SESSION;
+ } else {
+ clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
+ musb->xceiv->otg->default_a = 0;
+ musb->xceiv->otg->state = OTG_STATE_B_IDLE;
+ MUSB_DEV_MODE(musb);
+ devctl &= ~MUSB_DEVCTL_SESSION;
+ }
+ writeb(devctl, musb->mregs + SUNXI_MUSB_DEVCTL);
+
+ spin_unlock_irqrestore(&musb->lock, flags);
+ }
+
+ vbus_on = test_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
+ phy_on = test_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
+
+ if (phy_on != vbus_on) {
+ if (vbus_on) {
+ phy_power_on(glue->phy);
+ set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
+ } else {
+ phy_power_off(glue->phy);
+ clear_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
+ }
+ }
+}
+
+static void sunxi_musb_set_vbus(struct musb *musb, int is_on)
+{
+ struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
+
+ if (is_on)
+ set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
+ else
+ clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
+
+ schedule_work(&glue->work);
+}
+
+static irqreturn_t sunxi_musb_interrupt(int irq, void *__hci)
+{
+ struct musb *musb = __hci;
+ unsigned long flags;
+
+ spin_lock_irqsave(&musb->lock, flags);
+
+ musb->int_usb = readb(musb->mregs + SUNXI_MUSB_INTRUSB);
+ if (musb->int_usb)
+ writeb(musb->int_usb, musb->mregs + SUNXI_MUSB_INTRUSB);
+
+ /*
+ * sunxi musb often signals babble on low / full speed device
+ * disconnect, without ever raising MUSB_INTR_DISCONNECT, since
+ * normally babble never happens treat it as disconnect.
+ */
+ if ((musb->int_usb & MUSB_INTR_BABBLE) && is_host_active(musb)) {
+ musb->int_usb &= ~MUSB_INTR_BABBLE;
+ musb->int_usb |= MUSB_INTR_DISCONNECT;
+ }
+
+ musb->int_tx = readw(musb->mregs + SUNXI_MUSB_INTRTX);
+ if (musb->int_tx)
+ writew(musb->int_tx, musb->mregs + SUNXI_MUSB_INTRTX);
+
+ musb->int_rx = readw(musb->mregs + SUNXI_MUSB_INTRRX);
+ if (musb->int_rx)
+ writew(musb->int_rx, musb->mregs + SUNXI_MUSB_INTRRX);
+
+ musb_interrupt(musb);
+
+ spin_unlock_irqrestore(&musb->lock, flags);
+
+ return IRQ_HANDLED;
+}
+
+static int sunxi_musb_host_notifier(struct notifier_block *nb,
+ unsigned long event, void *ptr)
+{
+ struct sunxi_glue *glue = container_of(nb, struct sunxi_glue, host_nb);
+
+ if (event)
+ set_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags);
+ else
+ clear_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags);
+
+ set_bit(SUNXI_MUSB_FL_HOSTMODE_PEND, &glue->flags);
+ schedule_work(&glue->work);
+
+ return NOTIFY_DONE;
+}
+
+static int sunxi_musb_init(struct musb *musb)
+{
+ struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
+ int ret;
+
+ sunxi_musb = musb;
+ musb->phy = glue->phy;
+ musb->xceiv = glue->xceiv;
+
+ ret = sunxi_sram_claim(SUNXI_SRAM_USB_OTG, "usb-otg");
+ if (ret)
+ return ret;
+
+ ret = clk_prepare_enable(glue->clk);
+ if (ret)
+ goto error_sram_release;
+
+ writeb(SUNXI_MUSB_VEND0_PIO_MODE, musb->mregs + SUNXI_MUSB_VEND0);
+
+ /* Register interest before calling phy_init() */
+ if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) {
+ ret = extcon_register_interest(&glue->host_cable_nb,
+ "sun4i-usb-phy",
+ extcon_cable_name[EXTCON_USB_HOST],
+ &glue->host_nb);
+ if (ret)
+ goto error_clk_disable;
+ }
+
+ ret = phy_init(glue->phy);
+ if (ret)
+ goto error_unregister_interest;
+
+ if (musb->port_mode == MUSB_PORT_MODE_HOST) {
+ ret = phy_power_on(glue->phy);
+ if (ret)
+ goto error_phy_exit;
+ set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
+ }
+
+ musb->isr = sunxi_musb_interrupt;
+
+ /* Stop the musb-core from doing runtime pm (not supported on sunxi) */
+ pm_runtime_get(musb->controller);
+
+ return 0;
+
+error_phy_exit:
+ phy_exit(glue->phy);
+error_unregister_interest:
+ if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
+ extcon_unregister_interest(&glue->host_cable_nb);
+error_clk_disable:
+ clk_disable_unprepare(glue->clk);
+error_sram_release:
+ sunxi_sram_release(SUNXI_SRAM_USB_OTG);
+ return ret;
+}
+
+static int sunxi_musb_exit(struct musb *musb)
+{
+ struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
+
+ pm_runtime_put(musb->controller);
+
+ cancel_work_sync(&glue->work);
+ if (test_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags))
+ phy_power_off(glue->phy);
+
+ phy_exit(glue->phy);
+
+ if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
+ extcon_unregister_interest(&glue->host_cable_nb);
+
+ clk_disable_unprepare(glue->clk);
+ sunxi_sram_release(SUNXI_SRAM_USB_OTG);
+
+ return 0;
+}
+
+static void sunxi_musb_enable(struct musb *musb)
+{
+ struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
+
+ /* musb_core does not call us in a balanced manner */
+ if (test_and_set_bit(SUNXI_MUSB_FL_ENABLED, &glue->flags))
+ return;
+
+ schedule_work(&glue->work);
+}
+
+static void sunxi_musb_disable(struct musb *musb)
+{
+ struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
+
+ clear_bit(SUNXI_MUSB_FL_ENABLED, &glue->flags);
+}
+
+/*
+ * sunxi musb register layout
+ * 0x00 - 0x17 fifo regs, 1 long per fifo
+ * 0x40 - 0x57 generic control regs (power - frame)
+ * 0x80 - 0x8f ep control regs (addressed through hw_ep->regs, indexed)
+ * 0x90 - 0x97 fifo control regs (indexed)
+ * 0x98 - 0x9f multipoint / busctl regs (indexed)
+ * 0xc0 configdata reg
+ */
+
+static u32 sunxi_musb_fifo_offset(u8 epnum)
+{
+ return (epnum * 4);
+}
+
+static u32 sunxi_musb_ep_offset(u8 epnum, u16 offset)
+{
+ WARN_ONCE(offset != 0,
+ "sunxi_musb_ep_offset called with non 0 offset\n");
+
+ return 0x80; /* indexed, so ignore epnum */
+}
+
+static u32 sunxi_musb_busctl_offset(u8 epnum, u16 offset)
+{
+ return SUNXI_MUSB_TXFUNCADDR + offset;
+}
+
+static u8 sunxi_musb_readb(const void __iomem *addr, unsigned offset)
+{
+ if (addr == sunxi_musb->mregs) {
+ /* generic control or fifo control reg access */
+ switch (offset) {
+ case MUSB_FADDR:
+ return readb(addr + SUNXI_MUSB_FADDR);
+ case MUSB_POWER:
+ return readb(addr + SUNXI_MUSB_POWER);
+ case MUSB_INTRUSB:
+ return readb(addr + SUNXI_MUSB_INTRUSB);
+ case MUSB_INTRUSBE:
+ return readb(addr + SUNXI_MUSB_INTRUSBE);
+ case MUSB_INDEX:
+ return readb(addr + SUNXI_MUSB_INDEX);
+ case MUSB_TESTMODE:
+ return 0; /* No testmode on sunxi */
+ case MUSB_DEVCTL:
+ return readb(addr + SUNXI_MUSB_DEVCTL);
+ case MUSB_TXFIFOSZ:
+ return readb(addr + SUNXI_MUSB_TXFIFOSZ);
+ case MUSB_RXFIFOSZ:
+ return readb(addr + SUNXI_MUSB_RXFIFOSZ);
+ case MUSB_CONFIGDATA + 0x10: /* See musb_read_configdata() */
+ return readb(addr + SUNXI_MUSB_CONFIGDATA);
+ /* Offset for these is fixed by sunxi_musb_busctl_offset() */
+ case SUNXI_MUSB_TXFUNCADDR:
+ case SUNXI_MUSB_TXHUBADDR:
+ case SUNXI_MUSB_TXHUBPORT:
+ case SUNXI_MUSB_RXFUNCADDR:
+ case SUNXI_MUSB_RXHUBADDR:
+ case SUNXI_MUSB_RXHUBPORT:
+ /* multipoint / busctl reg access */
+ return readb(addr + offset);
+ default:
+ dev_err(sunxi_musb->controller->parent,
+ "Error unknown readb offset %u\n", offset);
+ return 0;
+ }
+ } else if (addr == (sunxi_musb->mregs + 0x80)) {
+ /* ep control reg access */
+ /* sunxi has a 2 byte hole before the txtype register */
+ if (offset >= MUSB_TXTYPE)
+ offset += 2;
+ return readb(addr + offset);
+ }
+
+ dev_err(sunxi_musb->controller->parent,
+ "Error unknown readb at 0x%x bytes offset\n",
+ (int)(addr - sunxi_musb->mregs));
+ return 0;
+}
+
+static void sunxi_musb_writeb(void __iomem *addr, unsigned offset, u8 data)
+{
+ if (addr == sunxi_musb->mregs) {
+ /* generic control or fifo control reg access */
+ switch (offset) {
+ case MUSB_FADDR:
+ return writeb(data, addr + SUNXI_MUSB_FADDR);
+ case MUSB_POWER:
+ return writeb(data, addr + SUNXI_MUSB_POWER);
+ case MUSB_INTRUSB:
+ return writeb(data, addr + SUNXI_MUSB_INTRUSB);
+ case MUSB_INTRUSBE:
+ return writeb(data, addr + SUNXI_MUSB_INTRUSBE);
+ case MUSB_INDEX:
+ return writeb(data, addr + SUNXI_MUSB_INDEX);
+ case MUSB_TESTMODE:
+ if (data)
+ dev_warn(sunxi_musb->controller->parent,
+ "sunxi-musb does not have testmode\n");
+ return;
+ case MUSB_DEVCTL:
+ return writeb(data, addr + SUNXI_MUSB_DEVCTL);
+ case MUSB_TXFIFOSZ:
+ return writeb(data, addr + SUNXI_MUSB_TXFIFOSZ);
+ case MUSB_RXFIFOSZ:
+ return writeb(data, addr + SUNXI_MUSB_RXFIFOSZ);
+ /* Offset for these is fixed by sunxi_musb_busctl_offset() */
+ case SUNXI_MUSB_TXFUNCADDR:
+ case SUNXI_MUSB_TXHUBADDR:
+ case SUNXI_MUSB_TXHUBPORT:
+ case SUNXI_MUSB_RXFUNCADDR:
+ case SUNXI_MUSB_RXHUBADDR:
+ case SUNXI_MUSB_RXHUBPORT:
+ /* multipoint / busctl reg access */
+ return writeb(data, addr + offset);
+ default:
+ dev_err(sunxi_musb->controller->parent,
+ "Error unknown writeb offset %u\n", offset);
+ return;
+ }
+ } else if (addr == (sunxi_musb->mregs + 0x80)) {
+ /* ep control reg access */
+ if (offset >= MUSB_TXTYPE)
+ offset += 2;
+ return writeb(data, addr + offset);
+ }
+
+ dev_err(sunxi_musb->controller->parent,
+ "Error unknown writeb at 0x%x bytes offset\n",
+ (int)(addr - sunxi_musb->mregs));
+}
+
+static u16 sunxi_musb_readw(const void __iomem *addr, unsigned offset)
+{
+ if (addr == sunxi_musb->mregs) {
+ /* generic control or fifo control reg access */
+ switch (offset) {
+ case MUSB_INTRTX:
+ return readw(addr + SUNXI_MUSB_INTRTX);
+ case MUSB_INTRRX:
+ return readw(addr + SUNXI_MUSB_INTRRX);
+ case MUSB_INTRTXE:
+ return readw(addr + SUNXI_MUSB_INTRTXE);
+ case MUSB_INTRRXE:
+ return readw(addr + SUNXI_MUSB_INTRRXE);
+ case MUSB_FRAME:
+ return readw(addr + SUNXI_MUSB_FRAME);
+ case MUSB_TXFIFOADD:
+ return readw(addr + SUNXI_MUSB_TXFIFOADD);
+ case MUSB_RXFIFOADD:
+ return readw(addr + SUNXI_MUSB_RXFIFOADD);
+ case MUSB_HWVERS:
+ return 0; /* sunxi musb version is not known */
+ default:
+ dev_err(sunxi_musb->controller->parent,
+ "Error unknown readw offset %u\n", offset);
+ return 0;
+ }
+ } else if (addr == (sunxi_musb->mregs + 0x80)) {
+ /* ep control reg access */
+ return readw(addr + offset);
+ }
+
+ dev_err(sunxi_musb->controller->parent,
+ "Error unknown readw at 0x%x bytes offset\n",
+ (int)(addr - sunxi_musb->mregs));
+ return 0;
+}
+
+static void sunxi_musb_writew(void __iomem *addr, unsigned offset, u16 data)
+{
+ if (addr == sunxi_musb->mregs) {
+ /* generic control or fifo control reg access */
+ switch (offset) {
+ case MUSB_INTRTX:
+ return writew(data, addr + SUNXI_MUSB_INTRTX);
+ case MUSB_INTRRX:
+ return writew(data, addr + SUNXI_MUSB_INTRRX);
+ case MUSB_INTRTXE:
+ return writew(data, addr + SUNXI_MUSB_INTRTXE);
+ case MUSB_INTRRXE:
+ return writew(data, addr + SUNXI_MUSB_INTRRXE);
+ case MUSB_FRAME:
+ return writew(data, addr + SUNXI_MUSB_FRAME);
+ case MUSB_TXFIFOADD:
+ return writew(data, addr + SUNXI_MUSB_TXFIFOADD);
+ case MUSB_RXFIFOADD:
+ return writew(data, addr + SUNXI_MUSB_RXFIFOADD);
+ default:
+ dev_err(sunxi_musb->controller->parent,
+ "Error unknown writew offset %u\n", offset);
+ return;
+ }
+ } else if (addr == (sunxi_musb->mregs + 0x80)) {
+ /* ep control reg access */
+ return writew(data, addr + offset);
+ }
+
+ dev_err(sunxi_musb->controller->parent,
+ "Error unknown writew at 0x%x bytes offset\n",
+ (int)(addr - sunxi_musb->mregs));
+}
+
+static const struct musb_platform_ops sunxi_musb_ops = {
+ .quirks = MUSB_INDEXED_EP | MUSB_SUN4I,
+ .init = sunxi_musb_init,
+ .exit = sunxi_musb_exit,
+ .enable = sunxi_musb_enable,
+ .disable = sunxi_musb_disable,
+ .fifo_offset = sunxi_musb_fifo_offset,
+ .ep_offset = sunxi_musb_ep_offset,
+ .busctl_offset = sunxi_musb_busctl_offset,
+ .readb = sunxi_musb_readb,
+ .writeb = sunxi_musb_writeb,
+ .readw = sunxi_musb_readw,
+ .writew = sunxi_musb_writew,
+ .set_vbus = sunxi_musb_set_vbus,
+};
+
+/* Allwinner OTG supports up to 5 endpoints */
+#define SUNXI_MUSB_MAX_EP_NUM 6
+#define SUNXI_MUSB_RAM_BITS 11
+
+static struct musb_fifo_cfg sunxi_musb_mode_cfg[] = {
+ MUSB_EP_FIFO_SINGLE(1, FIFO_TX, 512),
+ MUSB_EP_FIFO_SINGLE(1, FIFO_RX, 512),
+ MUSB_EP_FIFO_SINGLE(2, FIFO_TX, 512),
+ MUSB_EP_FIFO_SINGLE(2, FIFO_RX, 512),
+ MUSB_EP_FIFO_SINGLE(3, FIFO_TX, 512),
+ MUSB_EP_FIFO_SINGLE(3, FIFO_RX, 512),
+ MUSB_EP_FIFO_SINGLE(4, FIFO_TX, 512),
+ MUSB_EP_FIFO_SINGLE(4, FIFO_RX, 512),
+ MUSB_EP_FIFO_SINGLE(5, FIFO_TX, 512),
+ MUSB_EP_FIFO_SINGLE(5, FIFO_RX, 512),
+};
+
+static struct musb_hdrc_config sunxi_musb_hdrc_config = {
+ .fifo_cfg = sunxi_musb_mode_cfg,
+ .fifo_cfg_size = ARRAY_SIZE(sunxi_musb_mode_cfg),
+ .multipoint = true,
+ .dyn_fifo = true,
+ .soft_con = true,
+ .num_eps = SUNXI_MUSB_MAX_EP_NUM,
+ .ram_bits = SUNXI_MUSB_RAM_BITS,
+ .dma = 0,
+};
+
+static int sunxi_musb_probe(struct platform_device *pdev)
+{
+ struct musb_hdrc_platform_data pdata;
+ struct platform_device_info pinfo;
+ struct sunxi_glue *glue;
+ struct device_node *np = pdev->dev.of_node;
+ int ret;
+
+ if (!np) {
+ dev_err(&pdev->dev, "Error no device tree node found\n");
+ return -EINVAL;
+ }
+
+ memset(&pdata, 0, sizeof(pdata));
+ switch (of_usb_get_dr_mode(np)) {
+ case USB_DR_MODE_HOST:
+ pdata.mode = MUSB_PORT_MODE_HOST;
+ break;
+ case USB_DR_MODE_PERIPHERAL:
+ dev_err(&pdev->dev,
+ "Error peripheral only mode is not supported\n");
+ return -EINVAL;
+ case USB_DR_MODE_OTG:
+ pdata.mode = MUSB_PORT_MODE_DUAL_ROLE;
+ break;
+ default:
+ dev_err(&pdev->dev, "No 'dr_mode' property found\n");
+ return -EINVAL;
+ }
+ pdata.platform_ops = &sunxi_musb_ops;
+ pdata.config = &sunxi_musb_hdrc_config;
+
+ glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
+ if (!glue)
+ return -ENOMEM;
+
+ glue->dev = &pdev->dev;
+ INIT_WORK(&glue->work, sunxi_musb_work);
+ glue->host_nb.notifier_call = sunxi_musb_host_notifier;
+
+ glue->clk = devm_clk_get(&pdev->dev, NULL);
+ if (IS_ERR(glue->clk)) {
+ dev_err(&pdev->dev, "Error getting clock: %ld\n",
+ PTR_ERR(glue->clk));
+ return PTR_ERR(glue->clk);
+ }
+
+ glue->phy = devm_phy_get(&pdev->dev, "usb");
+ if (IS_ERR(glue->phy)) {
+ if (PTR_ERR(glue->phy) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+ dev_err(&pdev->dev, "Error getting phy %ld\n",
+ PTR_ERR(glue->phy));
+ return PTR_ERR(glue->phy);
+ }
+
+ glue->usb_phy = usb_phy_generic_register();
+ if (IS_ERR(glue->usb_phy)) {
+ dev_err(&pdev->dev, "Error registering usb-phy %ld\n",
+ PTR_ERR(glue->usb_phy));
+ return PTR_ERR(glue->usb_phy);
+ }
+
+ glue->xceiv = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
+ if (IS_ERR(glue->xceiv)) {
+ ret = PTR_ERR(glue->xceiv);
+ dev_err(&pdev->dev, "Error getting usb-phy %d\n", ret);
+ goto err_unregister_usb_phy;
+ }
+
+ platform_set_drvdata(pdev, glue);
+
+ memset(&pinfo, 0, sizeof(pinfo));
+ pinfo.name = "musb-hdrc";
+ pinfo.id = PLATFORM_DEVID_AUTO;
+ pinfo.parent = &pdev->dev;
+ pinfo.res = pdev->resource;
+ pinfo.num_res = pdev->num_resources;
+ pinfo.data = &pdata;
+ pinfo.size_data = sizeof(pdata);
+
+ glue->musb = platform_device_register_full(&pinfo);
+ if (IS_ERR(glue->musb)) {
+ ret = PTR_ERR(glue->musb);
+ dev_err(&pdev->dev, "Error registering musb dev: %d\n", ret);
+ goto err_unregister_usb_phy;
+ }
+
+ return 0;
+
+err_unregister_usb_phy:
+ usb_phy_generic_unregister(glue->usb_phy);
+ return ret;
+}
+
+static int sunxi_musb_remove(struct platform_device *pdev)
+{
+ struct sunxi_glue *glue = platform_get_drvdata(pdev);
+ struct platform_device *usb_phy = glue->usb_phy;
+
+ platform_device_unregister(glue->musb); /* Frees glue ! */
+ usb_phy_generic_unregister(usb_phy);
+
+ return 0;
+}
+
+static const struct of_device_id sunxi_musb_match[] = {
+ { .compatible = "allwinner,sun4i-a10-musb", },
+ {}
+};
+
+static struct platform_driver sunxi_musb_driver = {
+ .probe = sunxi_musb_probe,
+ .remove = sunxi_musb_remove,
+ .driver = {
+ .name = "musb-sunxi",
+ .of_match_table = sunxi_musb_match,
+ },
+};
+module_platform_driver(sunxi_musb_driver);
+
+MODULE_DESCRIPTION("Allwinner sunxi MUSB Glue Layer");
+MODULE_AUTHOR("Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>");
+MODULE_LICENSE("GPL v2");
--
2.3.3
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v2 07/13] ARM: dts: sun4i: Add USB Dual Role Controller
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
` (5 preceding siblings ...)
2015-03-20 19:11 ` [PATCH v2 06/13] musb: Add support for the Allwinner sunxi musb controller Hans de Goede
@ 2015-03-20 19:11 ` Hans de Goede
2015-03-20 19:11 ` [PATCH v2 08/13] ARM: dts: sun5i: " Hans de Goede
` (6 subsequent siblings)
13 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
Add a node for the otg/drc usb controller to sun4i-a10.dtsi.
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
arch/arm/boot/dts/sun4i-a10.dtsi | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
index a932c1c..88f57b4 100644
--- a/arch/arm/boot/dts/sun4i-a10.dtsi
+++ b/arch/arm/boot/dts/sun4i-a10.dtsi
@@ -611,6 +611,17 @@
#size-cells = <0>;
};
+ usb_otg: usb@01c13000 {
+ compatible = "allwinner,sun4i-a10-musb";
+ reg = <0x01c13000 0x0400>;
+ clocks = <&ahb_gates 0>;
+ interrupts = <38>;
+ interrupt-names = "mc";
+ phys = <&usbphy 0>;
+ phy-names = "usb";
+ status = "disabled";
+ };
+
usbphy: phy@01c13400 {
#phy-cells = <1>;
compatible = "allwinner,sun4i-a10-usb-phy";
--
2.3.3
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v2 08/13] ARM: dts: sun5i: Add USB Dual Role Controller
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
` (6 preceding siblings ...)
2015-03-20 19:11 ` [PATCH v2 07/13] ARM: dts: sun4i: Add USB Dual Role Controller Hans de Goede
@ 2015-03-20 19:11 ` Hans de Goede
2015-03-20 19:11 ` [PATCH v2 09/13] ARM: dts: sun7i: " Hans de Goede
` (5 subsequent siblings)
13 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
Add a node for the otg/drc usb controller to sun5i-a1*.dtsi.
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
arch/arm/boot/dts/sun5i.dtsi | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/arch/arm/boot/dts/sun5i.dtsi b/arch/arm/boot/dts/sun5i.dtsi
index c3e11ec..eb5bce5 100644
--- a/arch/arm/boot/dts/sun5i.dtsi
+++ b/arch/arm/boot/dts/sun5i.dtsi
@@ -425,6 +425,17 @@
#size-cells = <0>;
};
+ usb_otg: usb@01c13000 {
+ compatible = "allwinner,sun4i-a10-musb";
+ reg = <0x01c13000 0x0400>;
+ clocks = <&ahb_gates 0>;
+ interrupts = <38>;
+ interrupt-names = "mc";
+ phys = <&usbphy 0>;
+ phy-names = "usb";
+ status = "disabled";
+ };
+
usbphy: phy@01c13400 {
#phy-cells = <1>;
compatible = "allwinner,sun5i-a13-usb-phy";
--
2.3.3
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v2 09/13] ARM: dts: sun7i: Add USB Dual Role Controller
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
` (7 preceding siblings ...)
2015-03-20 19:11 ` [PATCH v2 08/13] ARM: dts: sun5i: " Hans de Goede
@ 2015-03-20 19:11 ` Hans de Goede
2015-03-20 19:11 ` [PATCH v2 10/13] ARM: dts: sun4i: Enable USB DRC on Chuwi V7 CW0825 Hans de Goede
` (4 subsequent siblings)
13 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
From: Roman Byshko <rbyshko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Add a node for the otg/drc usb controller to sun7i-a20.dtsi
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
arch/arm/boot/dts/sun7i-a20.dtsi | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index fb911c9..7c04a24 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -696,6 +696,17 @@
#size-cells = <0>;
};
+ usb_otg: usb@01c13000 {
+ compatible = "allwinner,sun4i-a10-musb";
+ reg = <0x01c13000 0x0400>;
+ clocks = <&ahb_gates 0>;
+ interrupts = <0 38 4>;
+ interrupt-names = "mc";
+ phys = <&usbphy 0>;
+ phy-names = "usb";
+ status = "disabled";
+ };
+
usbphy: phy@01c13400 {
#phy-cells = <1>;
compatible = "allwinner,sun7i-a20-usb-phy";
--
2.3.3
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v2 10/13] ARM: dts: sun4i: Enable USB DRC on Chuwi V7 CW0825
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
` (8 preceding siblings ...)
2015-03-20 19:11 ` [PATCH v2 09/13] ARM: dts: sun7i: " Hans de Goede
@ 2015-03-20 19:11 ` Hans de Goede
2015-03-20 19:11 ` [PATCH v2 11/13] ARM: dts: sun5i: Enable USB DRC on UTOO P66 Hans de Goede
` (3 subsequent siblings)
13 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
Enable the otg/drc usb controller on the Chuwi V7 CW0825 tablet.
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
arch/arm/boot/dts/sun4i-a10-chuwi-v7-cw0825.dts | 31 +++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/arch/arm/boot/dts/sun4i-a10-chuwi-v7-cw0825.dts b/arch/arm/boot/dts/sun4i-a10-chuwi-v7-cw0825.dts
index 97fca89..8a2f4c5 100644
--- a/arch/arm/boot/dts/sun4i-a10-chuwi-v7-cw0825.dts
+++ b/arch/arm/boot/dts/sun4i-a10-chuwi-v7-cw0825.dts
@@ -111,6 +111,26 @@
status = "okay";
};
+&pio {
+ usb0_id_detect_pin: usb0_id_detect_pin@0 {
+ allwinner,pins = "PH4";
+ allwinner,function = "gpio_in";
+ allwinner,drive = <SUN4I_PINCTRL_10_MA>;
+ allwinner,pull = <SUN4I_PINCTRL_PULL_UP>;
+ };
+
+ usb0_vbus_detect_pin: usb0_vbus_detect_pin@0 {
+ allwinner,pins = "PH5";
+ allwinner,function = "gpio_in";
+ allwinner,drive = <SUN4I_PINCTRL_10_MA>;
+ allwinner,pull = <SUN4I_PINCTRL_PULL_DOWN>;
+ };
+};
+
+®_usb0_vbus {
+ status = "okay";
+};
+
®_usb2_vbus {
status = "okay";
};
@@ -121,7 +141,18 @@
status = "okay";
};
+&usb_otg {
+ dr_mode = "otg";
+ status = "okay";
+};
+
&usbphy {
+ pinctrl-names = "default";
+ pinctrl-0 = <&usb0_id_detect_pin
+ &usb0_vbus_detect_pin>;
+ usb0_id_det-gpio = <&pio 7 4 GPIO_ACTIVE_HIGH>; /* PH4 */
+ usb0_vbus_det-gpio = <&pio 7 5 GPIO_ACTIVE_HIGH>; /* PH5 */
+ usb0_vbus-supply = <®_usb0_vbus>;
usb2_vbus-supply = <®_usb2_vbus>;
status = "okay";
};
--
2.3.3
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v2 11/13] ARM: dts: sun5i: Enable USB DRC on UTOO P66
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
` (9 preceding siblings ...)
2015-03-20 19:11 ` [PATCH v2 10/13] ARM: dts: sun4i: Enable USB DRC on Chuwi V7 CW0825 Hans de Goede
@ 2015-03-20 19:11 ` Hans de Goede
2015-03-20 19:11 ` [PATCH v2 12/13] ARM: dts: sun7i: Enable USB DRC on Cubietruck Hans de Goede
` (2 subsequent siblings)
13 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
Enable the OTG controller on the UTOO P66 tablet.
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
arch/arm/boot/dts/sun5i-a13-utoo-p66.dts | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/arch/arm/boot/dts/sun5i-a13-utoo-p66.dts b/arch/arm/boot/dts/sun5i-a13-utoo-p66.dts
index d1d4d30..6c9f5f3 100644
--- a/arch/arm/boot/dts/sun5i-a13-utoo-p66.dts
+++ b/arch/arm/boot/dts/sun5i-a13-utoo-p66.dts
@@ -160,6 +160,20 @@
allwinner,pull = <SUN4I_PINCTRL_PULL_UP>;
};
+ usb0_vbus_detect_pin: usb0_vbus_detect_pin@0 {
+ allwinner,pins = "PG1";
+ allwinner,function = "gpio_in";
+ allwinner,drive = <SUN4I_PINCTRL_10_MA>;
+ allwinner,pull = <SUN4I_PINCTRL_PULL_DOWN>;
+ };
+
+ usb0_id_detect_pin: usb0_id_detect_pin@0 {
+ allwinner,pins = "PG2";
+ allwinner,function = "gpio_in";
+ allwinner,drive = <SUN4I_PINCTRL_10_MA>;
+ allwinner,pull = <SUN4I_PINCTRL_PULL_UP>;
+ };
+
i2c_lcd_pins: i2c_lcd_pin@0 {
allwinner,pins = "PG10", "PG12";
allwinner,function = "gpio_out";
@@ -218,7 +232,16 @@
status = "okay";
};
+&usb_otg {
+ dr_mode = "otg";
+ status = "okay";
+};
+
&usbphy {
+ pinctrl-names = "default";
+ pinctrl-0 = <&usb0_id_detect_pin>, <&usb0_vbus_detect_pin>;
+ usb0_id_det-gpio = <&pio 6 2 GPIO_ACTIVE_HIGH>; /* PG2 */
+ usb0_vbus_det-gpio = <&pio 6 1 GPIO_ACTIVE_HIGH>; /* PG1 */
usb0_vbus-supply = <®_usb0_vbus>;
usb1_vbus-supply = <®_ldo3>;
status = "okay";
--
2.3.3
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v2 12/13] ARM: dts: sun7i: Enable USB DRC on Cubietruck
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
` (10 preceding siblings ...)
2015-03-20 19:11 ` [PATCH v2 11/13] ARM: dts: sun5i: Enable USB DRC on UTOO P66 Hans de Goede
@ 2015-03-20 19:11 ` Hans de Goede
2015-03-20 19:11 ` [PATCH v2 13/13] ARM: dts: sun7i: Enable USB DRC on A20-OLinuxIno-Lime Hans de Goede
2015-03-23 16:49 ` [PATCH v2 00/13] musb: Add support for the Allwinner sunxi musb controller Maxime Ripard
13 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
From: Roman Byshko <rbyshko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Enable the otg/drc usb controller on the cubietruck.
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
arch/arm/boot/dts/sun7i-a20-cubietruck.dts | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index 5af1df7..e14c1a6 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -224,6 +224,20 @@
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
+
+ usb0_id_detect_pin: usb0_id_detect_pin@0 {
+ allwinner,pins = "PH19";
+ allwinner,function = "gpio_in";
+ allwinner,drive = <SUN4I_PINCTRL_10_MA>;
+ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
+ };
+
+ usb0_vbus_detect_pin: usb0_vbus_detect_pin@0 {
+ allwinner,pins = "PH22";
+ allwinner,function = "gpio_in";
+ allwinner,drive = <SUN4I_PINCTRL_10_MA>;
+ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
+ };
};
&pwm {
@@ -285,7 +299,16 @@
status = "okay";
};
+&usb_otg {
+ dr_mode = "otg";
+ status = "okay";
+};
+
&usbphy {
+ pinctrl-names = "default";
+ pinctrl-0 = <&usb0_id_detect_pin>, <&usb0_vbus_detect_pin>;
+ usb0_id_det-gpios = <&pio 7 19 GPIO_ACTIVE_HIGH>; /* PH19 */
+ usb0_vbus_det-gpios = <&pio 7 22 GPIO_ACTIVE_HIGH>; /* PH22 */
usb0_vbus-supply = <®_usb0_vbus>;
usb1_vbus-supply = <®_usb1_vbus>;
usb2_vbus-supply = <®_usb2_vbus>;
--
2.3.3
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v2 13/13] ARM: dts: sun7i: Enable USB DRC on A20-OLinuxIno-Lime
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
` (11 preceding siblings ...)
2015-03-20 19:11 ` [PATCH v2 12/13] ARM: dts: sun7i: Enable USB DRC on Cubietruck Hans de Goede
@ 2015-03-20 19:11 ` Hans de Goede
2015-03-23 16:49 ` [PATCH v2 00/13] musb: Add support for the Allwinner sunxi musb controller Maxime Ripard
13 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-03-20 19:11 UTC (permalink / raw)
To: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard
Cc: Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede
Enable the otg/drc usb controller on the A20-OLinuxIno-Lime.
Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
arch/arm/boot/dts/sun7i-a20-olinuxino-lime.dts | 28 ++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/arch/arm/boot/dts/sun7i-a20-olinuxino-lime.dts b/arch/arm/boot/dts/sun7i-a20-olinuxino-lime.dts
index 68efd2f..e3812e9 100644
--- a/arch/arm/boot/dts/sun7i-a20-olinuxino-lime.dts
+++ b/arch/arm/boot/dts/sun7i-a20-olinuxino-lime.dts
@@ -146,6 +146,20 @@
allwinner,drive = <SUN4I_PINCTRL_20_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
+
+ usb0_id_detect_pin: usb0_id_detect_pin@0 {
+ allwinner,pins = "PH4";
+ allwinner,function = "gpio_in";
+ allwinner,drive = <SUN4I_PINCTRL_10_MA>;
+ allwinner,pull = <SUN4I_PINCTRL_PULL_UP>;
+ };
+
+ usb0_vbus_detect_pin: usb0_vbus_detect_pin@0 {
+ allwinner,pins = "PH5";
+ allwinner,function = "gpio_in";
+ allwinner,drive = <SUN4I_PINCTRL_10_MA>;
+ allwinner,pull = <SUN4I_PINCTRL_PULL_DOWN>;
+ };
};
®_ahci_5v {
@@ -154,6 +168,10 @@
status = "okay";
};
+®_usb0_vbus {
+ status = "okay";
+};
+
®_usb1_vbus {
status = "okay";
};
@@ -168,7 +186,17 @@
status = "okay";
};
+&usb_otg {
+ dr_mode = "otg";
+ status = "okay";
+};
+
&usbphy {
+ pinctrl-names = "default";
+ pinctrl-0 = <&usb0_id_detect_pin>, <&usb0_vbus_detect_pin>;
+ usb0_id_det-gpio = <&pio 7 4 GPIO_ACTIVE_HIGH>; /* PH4 */
+ usb0_vbus_det-gpio = <&pio 7 5 GPIO_ACTIVE_HIGH>; /* PH5 */
+ usb0_vbus-supply = <®_usb0_vbus>;
usb1_vbus-supply = <®_usb1_vbus>;
usb2_vbus-supply = <®_usb2_vbus>;
status = "okay";
--
2.3.3
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH v2 06/13] musb: Add support for the Allwinner sunxi musb controller
[not found] ` <1426878682-14521-7-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2015-03-21 2:04 ` Chen-Yu Tsai
[not found] ` <CAGb2v661EFghwEPER5LEib5RSy1r=dhwBewebJCUO_1sWa5sFQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-26 15:48 ` Felipe Balbi
1 sibling, 1 reply; 25+ messages in thread
From: Chen-Yu Tsai @ 2015-03-21 2:04 UTC (permalink / raw)
To: Hans de Goede
Cc: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard, Chen-Yu Tsai,
Roman Byshko, linux-usb, linux-arm-kernel, devicetree,
linux-sunxi
Hi,
On Sat, Mar 21, 2015 at 3:11 AM, Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
> This is based on initial code to get the Allwinner sunxi musb controller
> supported by Chen-Yu Tsai and Roman Byshko.
>
> This adds support for the Allwinner sunxi musb controller in both host only
> and otg mode. Peripheral only mode is not supported, as no boards use that.
>
> This has been tested on a cubietruck (A20 SoC) and an UTOO P66 tablet
> (A13 SoC) with a variety of devices in host mode and with the g_serial gadget
> driver in peripheral mode, plugging otg / host cables in/out a lot of times
> in all possible imaginable plug orders.
>
> Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> ---
> .../bindings/usb/allwinner,sun4i-a10-musb.txt | 25 +
> drivers/usb/musb/Kconfig | 12 +-
> drivers/usb/musb/Makefile | 1 +
> drivers/usb/musb/musb_core.h | 1 +
> drivers/usb/musb/musb_gadget.c | 6 +
> drivers/usb/musb/musb_virthub.c | 6 +
> drivers/usb/musb/sunxi.c | 671 +++++++++++++++++++++
> 7 files changed, 721 insertions(+), 1 deletion(-)
> create mode 100644 Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
> create mode 100644 drivers/usb/musb/sunxi.c
>
> diff --git a/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
> new file mode 100644
> index 0000000..21dfc7f
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
> @@ -0,0 +1,25 @@
> +Allwinner sun4i A10 musb DRC/OTG controller
> +-------------------------------------------
> +
> +Required properties:
> + - compatible : "allwinner,sun4i-a10-musb"
> + - reg : mmio address range of the musb controller
> + - clocks : clock specifier for the musb controller ahb gate clock
> + - interrupts : interrupt to which the musb controller is connected
> + - interrupt-names : must be "mc"
> + - phys : phy specifier for the otg phy
> + - phy-names : must be "usb"
> + - dr_mode : Dual-Role mode must be "host" or "otg"
> +
> +Example:
> +
> + usb_otg: usb@01c13000 {
> + compatible = "allwinner,sun4i-a10-musb";
> + reg = <0x01c13000 0x0400>;
> + clocks = <&ahb_gates 0>;
> + interrupts = <38>;
> + interrupt-names = "mc";
> + phys = <&usbphy 0>;
> + phy-names = "usb";
> + status = "disabled";
> + };
> diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
> index 14e1628..c83cad1 100644
> --- a/drivers/usb/musb/Kconfig
> +++ b/drivers/usb/musb/Kconfig
> @@ -5,7 +5,7 @@
>
> # (M)HDRC = (Multipoint) Highspeed Dual-Role Controller
> config USB_MUSB_HDRC
> - tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
> + tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, AW, ...)'
> depends on (USB || USB_GADGET)
> help
> Say Y here if your system has a dual role high speed USB
> @@ -20,6 +20,8 @@ config USB_MUSB_HDRC
> Analog Devices parts using this IP include Blackfin BF54x,
> BF525 and BF527.
>
> + Allwinner SoCs using this IP include A10, A13, A20, ...
> +
> If you do not know what this is, please say N.
>
> To compile this driver as a module, choose M here; the
> @@ -60,6 +62,14 @@ endchoice
>
> comment "Platform Glue Layer"
>
> +config USB_MUSB_SUNXI
> + tristate "Allwinner (sunxi)"
> + depends on ARCH_SUNXI
> + depends on NOP_USB_XCEIV
> + select EXTCON
> + select GENERIC_PHY
> + select SUNXI_SRAM
> +
> config USB_MUSB_DAVINCI
> tristate "DaVinci"
> depends on ARCH_DAVINCI_DMx
> diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
> index ba49501..f95befe 100644
> --- a/drivers/usb/musb/Makefile
> +++ b/drivers/usb/musb/Makefile
> @@ -20,6 +20,7 @@ obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o
> obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o
> obj-$(CONFIG_USB_MUSB_UX500) += ux500.o
> obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o
> +obj-$(CONFIG_USB_MUSB_SUNXI) += sunxi.o
>
>
> obj-$(CONFIG_USB_MUSB_AM335X_CHILD) += musb_am335x.o
> diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
> index ba8dd78..444b936 100644
> --- a/drivers/usb/musb/musb_core.h
> +++ b/drivers/usb/musb/musb_core.h
> @@ -166,6 +166,7 @@ struct musb_io;
> */
> struct musb_platform_ops {
>
> +#define MUSB_SUN4I BIT(7)
> #define MUSB_DMA_UX500 BIT(6)
> #define MUSB_DMA_CPPI41 BIT(5)
> #define MUSB_DMA_CPPI BIT(4)
> diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
> index b2d9040..7d13eb9 100644
> --- a/drivers/usb/musb/musb_gadget.c
> +++ b/drivers/usb/musb/musb_gadget.c
> @@ -2041,6 +2041,12 @@ void musb_g_disconnect(struct musb *musb)
> spin_lock(&musb->lock);
> }
>
> + /* On sunxi ep0 FADDR must be 0 when (re)entering peripheral mode */
> + if (musb->io.quirks & MUSB_SUN4I) {
> + musb_ep_select(musb->mregs, 0);
> + musb_writeb(musb->mregs, MUSB_FADDR, 0);
> + }
> +
> switch (musb->xceiv->otg->state) {
> default:
> dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n",
> diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
> index 294e159..3c87fd7 100644
> --- a/drivers/usb/musb/musb_virthub.c
> +++ b/drivers/usb/musb/musb_virthub.c
> @@ -224,6 +224,12 @@ void musb_root_disconnect(struct musb *musb)
> usb_hcd_poll_rh_status(musb->hcd);
> musb->is_active = 0;
>
> + /* On sunxi ep0 FADDR must be 0 when (re)entering peripheral mode */
> + if (musb->io.quirks & MUSB_SUN4I) {
> + musb_ep_select(musb->mregs, 0);
> + musb_writeb(musb->mregs, MUSB_FADDR, 0);
> + }
> +
> switch (musb->xceiv->otg->state) {
> case OTG_STATE_A_SUSPEND:
> if (otg->host->b_hnp_enable) {
> diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
> new file mode 100644
> index 0000000..64a95e4
> --- /dev/null
> +++ b/drivers/usb/musb/sunxi.c
> @@ -0,0 +1,671 @@
> +/*
> + * Allwinner sun4i MUSB Glue Layer
> + *
> + * Copyright (C) 2015 Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> + *
> + * Based on code from
> + * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
> + *
> + * 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/clk.h>
> +#include <linux/err.h>
> +#include <linux/extcon.h>
> +#include <linux/io.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/soc/sunxi/sunxi_sram.h>
> +#include <linux/usb/musb.h>
> +#include <linux/usb/of.h>
> +#include <linux/usb/usb_phy_generic.h>
> +#include <linux/workqueue.h>
> +#include "musb_core.h"
> +
> +/*
> + * Register offsets, note sunxi musb has a different layout then most
> + * musb implementations, we translate the layout in musb_readb & friends.
> + */
> +#define SUNXI_MUSB_POWER 0x0040
> +#define SUNXI_MUSB_DEVCTL 0x0041
> +#define SUNXI_MUSB_INDEX 0x0042
> +#define SUNXI_MUSB_VEND0 0x0043
> +#define SUNXI_MUSB_INTRTX 0x0044
> +#define SUNXI_MUSB_INTRRX 0x0046
> +#define SUNXI_MUSB_INTRTXE 0x0048
> +#define SUNXI_MUSB_INTRRXE 0x004a
> +#define SUNXI_MUSB_INTRUSB 0x004c
> +#define SUNXI_MUSB_INTRUSBE 0x0050
> +#define SUNXI_MUSB_FRAME 0x0054
> +#define SUNXI_MUSB_TXFIFOSZ 0x0090
> +#define SUNXI_MUSB_TXFIFOADD 0x0092
> +#define SUNXI_MUSB_RXFIFOSZ 0x0094
> +#define SUNXI_MUSB_RXFIFOADD 0x0096
> +#define SUNXI_MUSB_FADDR 0x0098
> +#define SUNXI_MUSB_TXFUNCADDR 0x0098
> +#define SUNXI_MUSB_TXHUBADDR 0x009a
> +#define SUNXI_MUSB_TXHUBPORT 0x009b
> +#define SUNXI_MUSB_RXFUNCADDR 0x009c
> +#define SUNXI_MUSB_RXHUBADDR 0x009e
> +#define SUNXI_MUSB_RXHUBPORT 0x009f
> +#define SUNXI_MUSB_CONFIGDATA 0x00c0
> +
> +/* VEND0 bits */
> +#define SUNXI_MUSB_VEND0_PIO_MODE 0
> +
> +/* flags */
> +#define SUNXI_MUSB_FL_ENABLED 0
> +#define SUNXI_MUSB_FL_HOSTMODE 1
> +#define SUNXI_MUSB_FL_HOSTMODE_PEND 2
> +#define SUNXI_MUSB_FL_VBUS_ON 3
> +#define SUNXI_MUSB_FL_PHY_ON 4
> +
> +/* Our read/write methods need access and do not get passed in a musb ref :| */
> +struct musb *sunxi_musb;
> +
> +struct sunxi_glue {
> + struct device *dev;
> + struct platform_device *musb;
> + struct clk *clk;
> + struct phy *phy;
> + struct platform_device *usb_phy;
> + struct usb_phy *xceiv;
> + unsigned long flags;
> + struct work_struct work;
> + struct extcon_specific_cable_nb host_cable_nb;
> + struct notifier_block host_nb;
> +};
> +
> +/* phy_power_on / off may sleep, so we use a workqueue */
> +static void sunxi_musb_work(struct work_struct *work)
> +{
> + struct sunxi_glue *glue = container_of(work, struct sunxi_glue, work);
> + bool vbus_on, phy_on;
> +
> + if (!test_bit(SUNXI_MUSB_FL_ENABLED, &glue->flags))
> + return;
> +
> + if (test_and_clear_bit(SUNXI_MUSB_FL_HOSTMODE_PEND, &glue->flags)) {
> + struct musb *musb = platform_get_drvdata(glue->musb);
> + unsigned long flags;
> + u8 devctl;
> +
> + spin_lock_irqsave(&musb->lock, flags);
> +
> + devctl = readb(musb->mregs + SUNXI_MUSB_DEVCTL);
> + if (test_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags)) {
> + set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
> + musb->xceiv->otg->default_a = 1;
> + musb->xceiv->otg->state = OTG_STATE_A_IDLE;
> + MUSB_HST_MODE(musb);
> + devctl |= MUSB_DEVCTL_SESSION;
> + } else {
> + clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
> + musb->xceiv->otg->default_a = 0;
> + musb->xceiv->otg->state = OTG_STATE_B_IDLE;
> + MUSB_DEV_MODE(musb);
> + devctl &= ~MUSB_DEVCTL_SESSION;
> + }
> + writeb(devctl, musb->mregs + SUNXI_MUSB_DEVCTL);
> +
> + spin_unlock_irqrestore(&musb->lock, flags);
> + }
> +
> + vbus_on = test_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
> + phy_on = test_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
> +
> + if (phy_on != vbus_on) {
> + if (vbus_on) {
> + phy_power_on(glue->phy);
> + set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
> + } else {
> + phy_power_off(glue->phy);
> + clear_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
> + }
> + }
> +}
> +
> +static void sunxi_musb_set_vbus(struct musb *musb, int is_on)
> +{
> + struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
> +
> + if (is_on)
> + set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
> + else
> + clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
> +
> + schedule_work(&glue->work);
> +}
> +
> +static irqreturn_t sunxi_musb_interrupt(int irq, void *__hci)
> +{
> + struct musb *musb = __hci;
> + unsigned long flags;
> +
> + spin_lock_irqsave(&musb->lock, flags);
> +
> + musb->int_usb = readb(musb->mregs + SUNXI_MUSB_INTRUSB);
> + if (musb->int_usb)
> + writeb(musb->int_usb, musb->mregs + SUNXI_MUSB_INTRUSB);
> +
> + /*
> + * sunxi musb often signals babble on low / full speed device
> + * disconnect, without ever raising MUSB_INTR_DISCONNECT, since
> + * normally babble never happens treat it as disconnect.
> + */
> + if ((musb->int_usb & MUSB_INTR_BABBLE) && is_host_active(musb)) {
> + musb->int_usb &= ~MUSB_INTR_BABBLE;
> + musb->int_usb |= MUSB_INTR_DISCONNECT;
> + }
> +
> + musb->int_tx = readw(musb->mregs + SUNXI_MUSB_INTRTX);
> + if (musb->int_tx)
> + writew(musb->int_tx, musb->mregs + SUNXI_MUSB_INTRTX);
> +
> + musb->int_rx = readw(musb->mregs + SUNXI_MUSB_INTRRX);
> + if (musb->int_rx)
> + writew(musb->int_rx, musb->mregs + SUNXI_MUSB_INTRRX);
> +
> + musb_interrupt(musb);
> +
> + spin_unlock_irqrestore(&musb->lock, flags);
> +
> + return IRQ_HANDLED;
> +}
> +
> +static int sunxi_musb_host_notifier(struct notifier_block *nb,
> + unsigned long event, void *ptr)
> +{
> + struct sunxi_glue *glue = container_of(nb, struct sunxi_glue, host_nb);
> +
> + if (event)
> + set_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags);
> + else
> + clear_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags);
> +
> + set_bit(SUNXI_MUSB_FL_HOSTMODE_PEND, &glue->flags);
> + schedule_work(&glue->work);
> +
> + return NOTIFY_DONE;
> +}
> +
> +static int sunxi_musb_init(struct musb *musb)
> +{
> + struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
> + int ret;
> +
> + sunxi_musb = musb;
> + musb->phy = glue->phy;
> + musb->xceiv = glue->xceiv;
> +
> + ret = sunxi_sram_claim(SUNXI_SRAM_USB_OTG, "usb-otg");
> + if (ret)
> + return ret;
> +
> + ret = clk_prepare_enable(glue->clk);
> + if (ret)
> + goto error_sram_release;
> +
> + writeb(SUNXI_MUSB_VEND0_PIO_MODE, musb->mregs + SUNXI_MUSB_VEND0);
Nit: a comment would make it clear you're settings PIO/DMA mode.
> +
> + /* Register interest before calling phy_init() */
> + if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) {
> + ret = extcon_register_interest(&glue->host_cable_nb,
> + "sun4i-usb-phy",
> + extcon_cable_name[EXTCON_USB_HOST],
> + &glue->host_nb);
> + if (ret)
> + goto error_clk_disable;
> + }
> +
> + ret = phy_init(glue->phy);
> + if (ret)
> + goto error_unregister_interest;
> +
> + if (musb->port_mode == MUSB_PORT_MODE_HOST) {
> + ret = phy_power_on(glue->phy);
> + if (ret)
> + goto error_phy_exit;
> + set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
> + }
> +
> + musb->isr = sunxi_musb_interrupt;
> +
> + /* Stop the musb-core from doing runtime pm (not supported on sunxi) */
> + pm_runtime_get(musb->controller);
> +
> + return 0;
> +
> +error_phy_exit:
> + phy_exit(glue->phy);
> +error_unregister_interest:
> + if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
> + extcon_unregister_interest(&glue->host_cable_nb);
> +error_clk_disable:
> + clk_disable_unprepare(glue->clk);
> +error_sram_release:
> + sunxi_sram_release(SUNXI_SRAM_USB_OTG);
> + return ret;
> +}
> +
> +static int sunxi_musb_exit(struct musb *musb)
> +{
> + struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
> +
> + pm_runtime_put(musb->controller);
> +
> + cancel_work_sync(&glue->work);
> + if (test_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags))
> + phy_power_off(glue->phy);
> +
> + phy_exit(glue->phy);
> +
> + if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
> + extcon_unregister_interest(&glue->host_cable_nb);
> +
> + clk_disable_unprepare(glue->clk);
> + sunxi_sram_release(SUNXI_SRAM_USB_OTG);
> +
> + return 0;
> +}
> +
> +static void sunxi_musb_enable(struct musb *musb)
> +{
> + struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
> +
> + /* musb_core does not call us in a balanced manner */
> + if (test_and_set_bit(SUNXI_MUSB_FL_ENABLED, &glue->flags))
> + return;
> +
> + schedule_work(&glue->work);
> +}
> +
> +static void sunxi_musb_disable(struct musb *musb)
> +{
> + struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
> +
> + clear_bit(SUNXI_MUSB_FL_ENABLED, &glue->flags);
> +}
> +
> +/*
> + * sunxi musb register layout
> + * 0x00 - 0x17 fifo regs, 1 long per fifo
> + * 0x40 - 0x57 generic control regs (power - frame)
Extra spaces.
> + * 0x80 - 0x8f ep control regs (addressed through hw_ep->regs, indexed)
> + * 0x90 - 0x97 fifo control regs (indexed)
> + * 0x98 - 0x9f multipoint / busctl regs (indexed)
> + * 0xc0 configdata reg
> + */
> +
> +static u32 sunxi_musb_fifo_offset(u8 epnum)
> +{
> + return (epnum * 4);
> +}
> +
> +static u32 sunxi_musb_ep_offset(u8 epnum, u16 offset)
> +{
> + WARN_ONCE(offset != 0,
> + "sunxi_musb_ep_offset called with non 0 offset\n");
> +
> + return 0x80; /* indexed, so ignore epnum */
> +}
> +
> +static u32 sunxi_musb_busctl_offset(u8 epnum, u16 offset)
> +{
> + return SUNXI_MUSB_TXFUNCADDR + offset;
> +}
> +
> +static u8 sunxi_musb_readb(const void __iomem *addr, unsigned offset)
> +{
> + if (addr == sunxi_musb->mregs) {
> + /* generic control or fifo control reg access */
> + switch (offset) {
> + case MUSB_FADDR:
> + return readb(addr + SUNXI_MUSB_FADDR);
> + case MUSB_POWER:
> + return readb(addr + SUNXI_MUSB_POWER);
> + case MUSB_INTRUSB:
> + return readb(addr + SUNXI_MUSB_INTRUSB);
> + case MUSB_INTRUSBE:
> + return readb(addr + SUNXI_MUSB_INTRUSBE);
> + case MUSB_INDEX:
> + return readb(addr + SUNXI_MUSB_INDEX);
> + case MUSB_TESTMODE:
> + return 0; /* No testmode on sunxi */
> + case MUSB_DEVCTL:
> + return readb(addr + SUNXI_MUSB_DEVCTL);
> + case MUSB_TXFIFOSZ:
> + return readb(addr + SUNXI_MUSB_TXFIFOSZ);
> + case MUSB_RXFIFOSZ:
> + return readb(addr + SUNXI_MUSB_RXFIFOSZ);
> + case MUSB_CONFIGDATA + 0x10: /* See musb_read_configdata() */
> + return readb(addr + SUNXI_MUSB_CONFIGDATA);
> + /* Offset for these is fixed by sunxi_musb_busctl_offset() */
> + case SUNXI_MUSB_TXFUNCADDR:
> + case SUNXI_MUSB_TXHUBADDR:
> + case SUNXI_MUSB_TXHUBPORT:
> + case SUNXI_MUSB_RXFUNCADDR:
> + case SUNXI_MUSB_RXHUBADDR:
> + case SUNXI_MUSB_RXHUBPORT:
> + /* multipoint / busctl reg access */
> + return readb(addr + offset);
> + default:
> + dev_err(sunxi_musb->controller->parent,
> + "Error unknown readb offset %u\n", offset);
> + return 0;
> + }
> + } else if (addr == (sunxi_musb->mregs + 0x80)) {
> + /* ep control reg access */
> + /* sunxi has a 2 byte hole before the txtype register */
> + if (offset >= MUSB_TXTYPE)
> + offset += 2;
> + return readb(addr + offset);
> + }
> +
> + dev_err(sunxi_musb->controller->parent,
> + "Error unknown readb at 0x%x bytes offset\n",
> + (int)(addr - sunxi_musb->mregs));
> + return 0;
> +}
> +
> +static void sunxi_musb_writeb(void __iomem *addr, unsigned offset, u8 data)
> +{
> + if (addr == sunxi_musb->mregs) {
> + /* generic control or fifo control reg access */
> + switch (offset) {
> + case MUSB_FADDR:
> + return writeb(data, addr + SUNXI_MUSB_FADDR);
> + case MUSB_POWER:
> + return writeb(data, addr + SUNXI_MUSB_POWER);
> + case MUSB_INTRUSB:
> + return writeb(data, addr + SUNXI_MUSB_INTRUSB);
> + case MUSB_INTRUSBE:
> + return writeb(data, addr + SUNXI_MUSB_INTRUSBE);
> + case MUSB_INDEX:
> + return writeb(data, addr + SUNXI_MUSB_INDEX);
> + case MUSB_TESTMODE:
> + if (data)
> + dev_warn(sunxi_musb->controller->parent,
> + "sunxi-musb does not have testmode\n");
> + return;
> + case MUSB_DEVCTL:
> + return writeb(data, addr + SUNXI_MUSB_DEVCTL);
> + case MUSB_TXFIFOSZ:
> + return writeb(data, addr + SUNXI_MUSB_TXFIFOSZ);
> + case MUSB_RXFIFOSZ:
> + return writeb(data, addr + SUNXI_MUSB_RXFIFOSZ);
> + /* Offset for these is fixed by sunxi_musb_busctl_offset() */
> + case SUNXI_MUSB_TXFUNCADDR:
> + case SUNXI_MUSB_TXHUBADDR:
> + case SUNXI_MUSB_TXHUBPORT:
> + case SUNXI_MUSB_RXFUNCADDR:
> + case SUNXI_MUSB_RXHUBADDR:
> + case SUNXI_MUSB_RXHUBPORT:
> + /* multipoint / busctl reg access */
> + return writeb(data, addr + offset);
> + default:
> + dev_err(sunxi_musb->controller->parent,
> + "Error unknown writeb offset %u\n", offset);
> + return;
> + }
> + } else if (addr == (sunxi_musb->mregs + 0x80)) {
> + /* ep control reg access */
> + if (offset >= MUSB_TXTYPE)
> + offset += 2;
> + return writeb(data, addr + offset);
> + }
> +
> + dev_err(sunxi_musb->controller->parent,
> + "Error unknown writeb at 0x%x bytes offset\n",
> + (int)(addr - sunxi_musb->mregs));
> +}
> +
> +static u16 sunxi_musb_readw(const void __iomem *addr, unsigned offset)
> +{
> + if (addr == sunxi_musb->mregs) {
> + /* generic control or fifo control reg access */
> + switch (offset) {
> + case MUSB_INTRTX:
> + return readw(addr + SUNXI_MUSB_INTRTX);
> + case MUSB_INTRRX:
> + return readw(addr + SUNXI_MUSB_INTRRX);
> + case MUSB_INTRTXE:
> + return readw(addr + SUNXI_MUSB_INTRTXE);
> + case MUSB_INTRRXE:
> + return readw(addr + SUNXI_MUSB_INTRRXE);
> + case MUSB_FRAME:
> + return readw(addr + SUNXI_MUSB_FRAME);
> + case MUSB_TXFIFOADD:
> + return readw(addr + SUNXI_MUSB_TXFIFOADD);
> + case MUSB_RXFIFOADD:
> + return readw(addr + SUNXI_MUSB_RXFIFOADD);
> + case MUSB_HWVERS:
> + return 0; /* sunxi musb version is not known */
> + default:
> + dev_err(sunxi_musb->controller->parent,
> + "Error unknown readw offset %u\n", offset);
> + return 0;
> + }
> + } else if (addr == (sunxi_musb->mregs + 0x80)) {
> + /* ep control reg access */
> + return readw(addr + offset);
> + }
> +
> + dev_err(sunxi_musb->controller->parent,
> + "Error unknown readw at 0x%x bytes offset\n",
> + (int)(addr - sunxi_musb->mregs));
> + return 0;
> +}
> +
> +static void sunxi_musb_writew(void __iomem *addr, unsigned offset, u16 data)
> +{
> + if (addr == sunxi_musb->mregs) {
> + /* generic control or fifo control reg access */
> + switch (offset) {
> + case MUSB_INTRTX:
> + return writew(data, addr + SUNXI_MUSB_INTRTX);
> + case MUSB_INTRRX:
> + return writew(data, addr + SUNXI_MUSB_INTRRX);
> + case MUSB_INTRTXE:
> + return writew(data, addr + SUNXI_MUSB_INTRTXE);
> + case MUSB_INTRRXE:
> + return writew(data, addr + SUNXI_MUSB_INTRRXE);
> + case MUSB_FRAME:
> + return writew(data, addr + SUNXI_MUSB_FRAME);
> + case MUSB_TXFIFOADD:
> + return writew(data, addr + SUNXI_MUSB_TXFIFOADD);
> + case MUSB_RXFIFOADD:
> + return writew(data, addr + SUNXI_MUSB_RXFIFOADD);
> + default:
> + dev_err(sunxi_musb->controller->parent,
> + "Error unknown writew offset %u\n", offset);
> + return;
> + }
> + } else if (addr == (sunxi_musb->mregs + 0x80)) {
> + /* ep control reg access */
> + return writew(data, addr + offset);
> + }
> +
> + dev_err(sunxi_musb->controller->parent,
> + "Error unknown writew at 0x%x bytes offset\n",
> + (int)(addr - sunxi_musb->mregs));
> +}
> +
> +static const struct musb_platform_ops sunxi_musb_ops = {
> + .quirks = MUSB_INDEXED_EP | MUSB_SUN4I,
> + .init = sunxi_musb_init,
> + .exit = sunxi_musb_exit,
> + .enable = sunxi_musb_enable,
> + .disable = sunxi_musb_disable,
> + .fifo_offset = sunxi_musb_fifo_offset,
> + .ep_offset = sunxi_musb_ep_offset,
> + .busctl_offset = sunxi_musb_busctl_offset,
> + .readb = sunxi_musb_readb,
> + .writeb = sunxi_musb_writeb,
> + .readw = sunxi_musb_readw,
> + .writew = sunxi_musb_writew,
> + .set_vbus = sunxi_musb_set_vbus,
> +};
> +
> +/* Allwinner OTG supports up to 5 endpoints */
> +#define SUNXI_MUSB_MAX_EP_NUM 6
> +#define SUNXI_MUSB_RAM_BITS 11
> +
> +static struct musb_fifo_cfg sunxi_musb_mode_cfg[] = {
> + MUSB_EP_FIFO_SINGLE(1, FIFO_TX, 512),
> + MUSB_EP_FIFO_SINGLE(1, FIFO_RX, 512),
> + MUSB_EP_FIFO_SINGLE(2, FIFO_TX, 512),
> + MUSB_EP_FIFO_SINGLE(2, FIFO_RX, 512),
> + MUSB_EP_FIFO_SINGLE(3, FIFO_TX, 512),
> + MUSB_EP_FIFO_SINGLE(3, FIFO_RX, 512),
> + MUSB_EP_FIFO_SINGLE(4, FIFO_TX, 512),
> + MUSB_EP_FIFO_SINGLE(4, FIFO_RX, 512),
> + MUSB_EP_FIFO_SINGLE(5, FIFO_TX, 512),
> + MUSB_EP_FIFO_SINGLE(5, FIFO_RX, 512),
> +};
> +
> +static struct musb_hdrc_config sunxi_musb_hdrc_config = {
> + .fifo_cfg = sunxi_musb_mode_cfg,
> + .fifo_cfg_size = ARRAY_SIZE(sunxi_musb_mode_cfg),
> + .multipoint = true,
> + .dyn_fifo = true,
> + .soft_con = true,
> + .num_eps = SUNXI_MUSB_MAX_EP_NUM,
> + .ram_bits = SUNXI_MUSB_RAM_BITS,
> + .dma = 0,
> +};
> +
> +static int sunxi_musb_probe(struct platform_device *pdev)
> +{
> + struct musb_hdrc_platform_data pdata;
> + struct platform_device_info pinfo;
> + struct sunxi_glue *glue;
> + struct device_node *np = pdev->dev.of_node;
> + int ret;
> +
> + if (!np) {
> + dev_err(&pdev->dev, "Error no device tree node found\n");
> + return -EINVAL;
> + }
> +
> + memset(&pdata, 0, sizeof(pdata));
> + switch (of_usb_get_dr_mode(np)) {
> + case USB_DR_MODE_HOST:
> + pdata.mode = MUSB_PORT_MODE_HOST;
> + break;
> + case USB_DR_MODE_PERIPHERAL:
> + dev_err(&pdev->dev,
> + "Error peripheral only mode is not supported\n");
> + return -EINVAL;
> + case USB_DR_MODE_OTG:
> + pdata.mode = MUSB_PORT_MODE_DUAL_ROLE;
> + break;
Do we want to have some #ifdefs or IS_ENABLED() around this to handle
cases where musb is built in host only or peripheral only modes?
I tested v1 with a host only build and "otg" in the DT, which resulted
in a oops somewhere. (Building host only is because I don't want to have
to load a module to get a usb host on my tablet.)
> + default:
> + dev_err(&pdev->dev, "No 'dr_mode' property found\n");
> + return -EINVAL;
> + }
> + pdata.platform_ops = &sunxi_musb_ops;
> + pdata.config = &sunxi_musb_hdrc_config;
> +
> + glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
> + if (!glue)
> + return -ENOMEM;
> +
> + glue->dev = &pdev->dev;
> + INIT_WORK(&glue->work, sunxi_musb_work);
> + glue->host_nb.notifier_call = sunxi_musb_host_notifier;
> +
> + glue->clk = devm_clk_get(&pdev->dev, NULL);
> + if (IS_ERR(glue->clk)) {
> + dev_err(&pdev->dev, "Error getting clock: %ld\n",
> + PTR_ERR(glue->clk));
> + return PTR_ERR(glue->clk);
> + }
> +
> + glue->phy = devm_phy_get(&pdev->dev, "usb");
> + if (IS_ERR(glue->phy)) {
> + if (PTR_ERR(glue->phy) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
> + dev_err(&pdev->dev, "Error getting phy %ld\n",
> + PTR_ERR(glue->phy));
> + return PTR_ERR(glue->phy);
> + }
> +
> + glue->usb_phy = usb_phy_generic_register();
> + if (IS_ERR(glue->usb_phy)) {
> + dev_err(&pdev->dev, "Error registering usb-phy %ld\n",
> + PTR_ERR(glue->usb_phy));
> + return PTR_ERR(glue->usb_phy);
> + }
> +
> + glue->xceiv = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
> + if (IS_ERR(glue->xceiv)) {
> + ret = PTR_ERR(glue->xceiv);
> + dev_err(&pdev->dev, "Error getting usb-phy %d\n", ret);
> + goto err_unregister_usb_phy;
> + }
> +
> + platform_set_drvdata(pdev, glue);
> +
> + memset(&pinfo, 0, sizeof(pinfo));
> + pinfo.name = "musb-hdrc";
> + pinfo.id = PLATFORM_DEVID_AUTO;
> + pinfo.parent = &pdev->dev;
> + pinfo.res = pdev->resource;
> + pinfo.num_res = pdev->num_resources;
> + pinfo.data = &pdata;
> + pinfo.size_data = sizeof(pdata);
> +
> + glue->musb = platform_device_register_full(&pinfo);
> + if (IS_ERR(glue->musb)) {
> + ret = PTR_ERR(glue->musb);
> + dev_err(&pdev->dev, "Error registering musb dev: %d\n", ret);
> + goto err_unregister_usb_phy;
> + }
> +
> + return 0;
> +
> +err_unregister_usb_phy:
> + usb_phy_generic_unregister(glue->usb_phy);
> + return ret;
> +}
> +
> +static int sunxi_musb_remove(struct platform_device *pdev)
> +{
> + struct sunxi_glue *glue = platform_get_drvdata(pdev);
> + struct platform_device *usb_phy = glue->usb_phy;
> +
> + platform_device_unregister(glue->musb); /* Frees glue ! */
> + usb_phy_generic_unregister(usb_phy);
> +
> + return 0;
> +}
> +
> +static const struct of_device_id sunxi_musb_match[] = {
> + { .compatible = "allwinner,sun4i-a10-musb", },
> + {}
> +};
> +
> +static struct platform_driver sunxi_musb_driver = {
> + .probe = sunxi_musb_probe,
> + .remove = sunxi_musb_remove,
> + .driver = {
> + .name = "musb-sunxi",
> + .of_match_table = sunxi_musb_match,
> + },
> +};
> +module_platform_driver(sunxi_musb_driver);
> +
> +MODULE_DESCRIPTION("Allwinner sunxi MUSB Glue Layer");
> +MODULE_AUTHOR("Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>");
> +MODULE_LICENSE("GPL v2");
> --
> 2.3.3
>
Thanks!
ChenYu
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v2 06/13] musb: Add support for the Allwinner sunxi musb controller
[not found] ` <CAGb2v661EFghwEPER5LEib5RSy1r=dhwBewebJCUO_1sWa5sFQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2015-03-21 9:30 ` Hans de Goede
0 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-03-21 9:30 UTC (permalink / raw)
To: Chen-Yu Tsai
Cc: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard, Roman Byshko,
linux-usb, linux-arm-kernel, devicetree, linux-sunxi
Hi,
On 21-03-15 03:04, Chen-Yu Tsai wrote:
> Hi,
>
> On Sat, Mar 21, 2015 at 3:11 AM, Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
>> This is based on initial code to get the Allwinner sunxi musb controller
>> supported by Chen-Yu Tsai and Roman Byshko.
>>
>> This adds support for the Allwinner sunxi musb controller in both host only
>> and otg mode. Peripheral only mode is not supported, as no boards use that.
>>
>> This has been tested on a cubietruck (A20 SoC) and an UTOO P66 tablet
>> (A13 SoC) with a variety of devices in host mode and with the g_serial gadget
>> driver in peripheral mode, plugging otg / host cables in/out a lot of times
>> in all possible imaginable plug orders.
>>
>> Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>> ---
>> .../bindings/usb/allwinner,sun4i-a10-musb.txt | 25 +
>> drivers/usb/musb/Kconfig | 12 +-
>> drivers/usb/musb/Makefile | 1 +
>> drivers/usb/musb/musb_core.h | 1 +
>> drivers/usb/musb/musb_gadget.c | 6 +
>> drivers/usb/musb/musb_virthub.c | 6 +
>> drivers/usb/musb/sunxi.c | 671 +++++++++++++++++++++
>> 7 files changed, 721 insertions(+), 1 deletion(-)
>> create mode 100644 Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
>> create mode 100644 drivers/usb/musb/sunxi.c
>>
>> diff --git a/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
>> new file mode 100644
>> index 0000000..21dfc7f
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
>> @@ -0,0 +1,25 @@
>> +Allwinner sun4i A10 musb DRC/OTG controller
>> +-------------------------------------------
>> +
>> +Required properties:
>> + - compatible : "allwinner,sun4i-a10-musb"
>> + - reg : mmio address range of the musb controller
>> + - clocks : clock specifier for the musb controller ahb gate clock
>> + - interrupts : interrupt to which the musb controller is connected
>> + - interrupt-names : must be "mc"
>> + - phys : phy specifier for the otg phy
>> + - phy-names : must be "usb"
>> + - dr_mode : Dual-Role mode must be "host" or "otg"
>> +
>> +Example:
>> +
>> + usb_otg: usb@01c13000 {
>> + compatible = "allwinner,sun4i-a10-musb";
>> + reg = <0x01c13000 0x0400>;
>> + clocks = <&ahb_gates 0>;
>> + interrupts = <38>;
>> + interrupt-names = "mc";
>> + phys = <&usbphy 0>;
>> + phy-names = "usb";
>> + status = "disabled";
>> + };
>> diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
>> index 14e1628..c83cad1 100644
>> --- a/drivers/usb/musb/Kconfig
>> +++ b/drivers/usb/musb/Kconfig
>> @@ -5,7 +5,7 @@
>>
>> # (M)HDRC = (Multipoint) Highspeed Dual-Role Controller
>> config USB_MUSB_HDRC
>> - tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
>> + tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, AW, ...)'
>> depends on (USB || USB_GADGET)
>> help
>> Say Y here if your system has a dual role high speed USB
>> @@ -20,6 +20,8 @@ config USB_MUSB_HDRC
>> Analog Devices parts using this IP include Blackfin BF54x,
>> BF525 and BF527.
>>
>> + Allwinner SoCs using this IP include A10, A13, A20, ...
>> +
>> If you do not know what this is, please say N.
>>
>> To compile this driver as a module, choose M here; the
>> @@ -60,6 +62,14 @@ endchoice
>>
>> comment "Platform Glue Layer"
>>
>> +config USB_MUSB_SUNXI
>> + tristate "Allwinner (sunxi)"
>> + depends on ARCH_SUNXI
>> + depends on NOP_USB_XCEIV
>> + select EXTCON
>> + select GENERIC_PHY
>> + select SUNXI_SRAM
>> +
>> config USB_MUSB_DAVINCI
>> tristate "DaVinci"
>> depends on ARCH_DAVINCI_DMx
>> diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
>> index ba49501..f95befe 100644
>> --- a/drivers/usb/musb/Makefile
>> +++ b/drivers/usb/musb/Makefile
>> @@ -20,6 +20,7 @@ obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o
>> obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o
>> obj-$(CONFIG_USB_MUSB_UX500) += ux500.o
>> obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o
>> +obj-$(CONFIG_USB_MUSB_SUNXI) += sunxi.o
>>
>>
>> obj-$(CONFIG_USB_MUSB_AM335X_CHILD) += musb_am335x.o
>> diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
>> index ba8dd78..444b936 100644
>> --- a/drivers/usb/musb/musb_core.h
>> +++ b/drivers/usb/musb/musb_core.h
>> @@ -166,6 +166,7 @@ struct musb_io;
>> */
>> struct musb_platform_ops {
>>
>> +#define MUSB_SUN4I BIT(7)
>> #define MUSB_DMA_UX500 BIT(6)
>> #define MUSB_DMA_CPPI41 BIT(5)
>> #define MUSB_DMA_CPPI BIT(4)
>> diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
>> index b2d9040..7d13eb9 100644
>> --- a/drivers/usb/musb/musb_gadget.c
>> +++ b/drivers/usb/musb/musb_gadget.c
>> @@ -2041,6 +2041,12 @@ void musb_g_disconnect(struct musb *musb)
>> spin_lock(&musb->lock);
>> }
>>
>> + /* On sunxi ep0 FADDR must be 0 when (re)entering peripheral mode */
>> + if (musb->io.quirks & MUSB_SUN4I) {
>> + musb_ep_select(musb->mregs, 0);
>> + musb_writeb(musb->mregs, MUSB_FADDR, 0);
>> + }
>> +
>> switch (musb->xceiv->otg->state) {
>> default:
>> dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n",
>> diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
>> index 294e159..3c87fd7 100644
>> --- a/drivers/usb/musb/musb_virthub.c
>> +++ b/drivers/usb/musb/musb_virthub.c
>> @@ -224,6 +224,12 @@ void musb_root_disconnect(struct musb *musb)
>> usb_hcd_poll_rh_status(musb->hcd);
>> musb->is_active = 0;
>>
>> + /* On sunxi ep0 FADDR must be 0 when (re)entering peripheral mode */
>> + if (musb->io.quirks & MUSB_SUN4I) {
>> + musb_ep_select(musb->mregs, 0);
>> + musb_writeb(musb->mregs, MUSB_FADDR, 0);
>> + }
>> +
>> switch (musb->xceiv->otg->state) {
>> case OTG_STATE_A_SUSPEND:
>> if (otg->host->b_hnp_enable) {
>> diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
>> new file mode 100644
>> index 0000000..64a95e4
>> --- /dev/null
>> +++ b/drivers/usb/musb/sunxi.c
>> @@ -0,0 +1,671 @@
>> +/*
>> + * Allwinner sun4i MUSB Glue Layer
>> + *
>> + * Copyright (C) 2015 Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>> + *
>> + * Based on code from
>> + * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
>> + *
>> + * 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/clk.h>
>> +#include <linux/err.h>
>> +#include <linux/extcon.h>
>> +#include <linux/io.h>
>> +#include <linux/kernel.h>
>> +#include <linux/module.h>
>> +#include <linux/of.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/soc/sunxi/sunxi_sram.h>
>> +#include <linux/usb/musb.h>
>> +#include <linux/usb/of.h>
>> +#include <linux/usb/usb_phy_generic.h>
>> +#include <linux/workqueue.h>
>> +#include "musb_core.h"
>> +
>> +/*
>> + * Register offsets, note sunxi musb has a different layout then most
>> + * musb implementations, we translate the layout in musb_readb & friends.
>> + */
>> +#define SUNXI_MUSB_POWER 0x0040
>> +#define SUNXI_MUSB_DEVCTL 0x0041
>> +#define SUNXI_MUSB_INDEX 0x0042
>> +#define SUNXI_MUSB_VEND0 0x0043
>> +#define SUNXI_MUSB_INTRTX 0x0044
>> +#define SUNXI_MUSB_INTRRX 0x0046
>> +#define SUNXI_MUSB_INTRTXE 0x0048
>> +#define SUNXI_MUSB_INTRRXE 0x004a
>> +#define SUNXI_MUSB_INTRUSB 0x004c
>> +#define SUNXI_MUSB_INTRUSBE 0x0050
>> +#define SUNXI_MUSB_FRAME 0x0054
>> +#define SUNXI_MUSB_TXFIFOSZ 0x0090
>> +#define SUNXI_MUSB_TXFIFOADD 0x0092
>> +#define SUNXI_MUSB_RXFIFOSZ 0x0094
>> +#define SUNXI_MUSB_RXFIFOADD 0x0096
>> +#define SUNXI_MUSB_FADDR 0x0098
>> +#define SUNXI_MUSB_TXFUNCADDR 0x0098
>> +#define SUNXI_MUSB_TXHUBADDR 0x009a
>> +#define SUNXI_MUSB_TXHUBPORT 0x009b
>> +#define SUNXI_MUSB_RXFUNCADDR 0x009c
>> +#define SUNXI_MUSB_RXHUBADDR 0x009e
>> +#define SUNXI_MUSB_RXHUBPORT 0x009f
>> +#define SUNXI_MUSB_CONFIGDATA 0x00c0
>> +
>> +/* VEND0 bits */
>> +#define SUNXI_MUSB_VEND0_PIO_MODE 0
>> +
>> +/* flags */
>> +#define SUNXI_MUSB_FL_ENABLED 0
>> +#define SUNXI_MUSB_FL_HOSTMODE 1
>> +#define SUNXI_MUSB_FL_HOSTMODE_PEND 2
>> +#define SUNXI_MUSB_FL_VBUS_ON 3
>> +#define SUNXI_MUSB_FL_PHY_ON 4
>> +
>> +/* Our read/write methods need access and do not get passed in a musb ref :| */
>> +struct musb *sunxi_musb;
>> +
>> +struct sunxi_glue {
>> + struct device *dev;
>> + struct platform_device *musb;
>> + struct clk *clk;
>> + struct phy *phy;
>> + struct platform_device *usb_phy;
>> + struct usb_phy *xceiv;
>> + unsigned long flags;
>> + struct work_struct work;
>> + struct extcon_specific_cable_nb host_cable_nb;
>> + struct notifier_block host_nb;
>> +};
>> +
>> +/* phy_power_on / off may sleep, so we use a workqueue */
>> +static void sunxi_musb_work(struct work_struct *work)
>> +{
>> + struct sunxi_glue *glue = container_of(work, struct sunxi_glue, work);
>> + bool vbus_on, phy_on;
>> +
>> + if (!test_bit(SUNXI_MUSB_FL_ENABLED, &glue->flags))
>> + return;
>> +
>> + if (test_and_clear_bit(SUNXI_MUSB_FL_HOSTMODE_PEND, &glue->flags)) {
>> + struct musb *musb = platform_get_drvdata(glue->musb);
>> + unsigned long flags;
>> + u8 devctl;
>> +
>> + spin_lock_irqsave(&musb->lock, flags);
>> +
>> + devctl = readb(musb->mregs + SUNXI_MUSB_DEVCTL);
>> + if (test_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags)) {
>> + set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
>> + musb->xceiv->otg->default_a = 1;
>> + musb->xceiv->otg->state = OTG_STATE_A_IDLE;
>> + MUSB_HST_MODE(musb);
>> + devctl |= MUSB_DEVCTL_SESSION;
>> + } else {
>> + clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
>> + musb->xceiv->otg->default_a = 0;
>> + musb->xceiv->otg->state = OTG_STATE_B_IDLE;
>> + MUSB_DEV_MODE(musb);
>> + devctl &= ~MUSB_DEVCTL_SESSION;
>> + }
>> + writeb(devctl, musb->mregs + SUNXI_MUSB_DEVCTL);
>> +
>> + spin_unlock_irqrestore(&musb->lock, flags);
>> + }
>> +
>> + vbus_on = test_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
>> + phy_on = test_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
>> +
>> + if (phy_on != vbus_on) {
>> + if (vbus_on) {
>> + phy_power_on(glue->phy);
>> + set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
>> + } else {
>> + phy_power_off(glue->phy);
>> + clear_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
>> + }
>> + }
>> +}
>> +
>> +static void sunxi_musb_set_vbus(struct musb *musb, int is_on)
>> +{
>> + struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
>> +
>> + if (is_on)
>> + set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
>> + else
>> + clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
>> +
>> + schedule_work(&glue->work);
>> +}
>> +
>> +static irqreturn_t sunxi_musb_interrupt(int irq, void *__hci)
>> +{
>> + struct musb *musb = __hci;
>> + unsigned long flags;
>> +
>> + spin_lock_irqsave(&musb->lock, flags);
>> +
>> + musb->int_usb = readb(musb->mregs + SUNXI_MUSB_INTRUSB);
>> + if (musb->int_usb)
>> + writeb(musb->int_usb, musb->mregs + SUNXI_MUSB_INTRUSB);
>> +
>> + /*
>> + * sunxi musb often signals babble on low / full speed device
>> + * disconnect, without ever raising MUSB_INTR_DISCONNECT, since
>> + * normally babble never happens treat it as disconnect.
>> + */
>> + if ((musb->int_usb & MUSB_INTR_BABBLE) && is_host_active(musb)) {
>> + musb->int_usb &= ~MUSB_INTR_BABBLE;
>> + musb->int_usb |= MUSB_INTR_DISCONNECT;
>> + }
>> +
>> + musb->int_tx = readw(musb->mregs + SUNXI_MUSB_INTRTX);
>> + if (musb->int_tx)
>> + writew(musb->int_tx, musb->mregs + SUNXI_MUSB_INTRTX);
>> +
>> + musb->int_rx = readw(musb->mregs + SUNXI_MUSB_INTRRX);
>> + if (musb->int_rx)
>> + writew(musb->int_rx, musb->mregs + SUNXI_MUSB_INTRRX);
>> +
>> + musb_interrupt(musb);
>> +
>> + spin_unlock_irqrestore(&musb->lock, flags);
>> +
>> + return IRQ_HANDLED;
>> +}
>> +
>> +static int sunxi_musb_host_notifier(struct notifier_block *nb,
>> + unsigned long event, void *ptr)
>> +{
>> + struct sunxi_glue *glue = container_of(nb, struct sunxi_glue, host_nb);
>> +
>> + if (event)
>> + set_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags);
>> + else
>> + clear_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags);
>> +
>> + set_bit(SUNXI_MUSB_FL_HOSTMODE_PEND, &glue->flags);
>> + schedule_work(&glue->work);
>> +
>> + return NOTIFY_DONE;
>> +}
>> +
>> +static int sunxi_musb_init(struct musb *musb)
>> +{
>> + struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
>> + int ret;
>> +
>> + sunxi_musb = musb;
>> + musb->phy = glue->phy;
>> + musb->xceiv = glue->xceiv;
>> +
>> + ret = sunxi_sram_claim(SUNXI_SRAM_USB_OTG, "usb-otg");
>> + if (ret)
>> + return ret;
>> +
>> + ret = clk_prepare_enable(glue->clk);
>> + if (ret)
>> + goto error_sram_release;
>> +
>> + writeb(SUNXI_MUSB_VEND0_PIO_MODE, musb->mregs + SUNXI_MUSB_VEND0);
>
> Nit: a comment would make it clear you're settings PIO/DMA mode.
I actually removed such a comment after I changed the magic "0" being written
to SUNXI_MUSB_VEND0_PIO_MODE as that to me already makes it clear what is
happening here.
>
>> +
>> + /* Register interest before calling phy_init() */
>> + if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) {
>> + ret = extcon_register_interest(&glue->host_cable_nb,
>> + "sun4i-usb-phy",
>> + extcon_cable_name[EXTCON_USB_HOST],
>> + &glue->host_nb);
>> + if (ret)
>> + goto error_clk_disable;
>> + }
>> +
>> + ret = phy_init(glue->phy);
>> + if (ret)
>> + goto error_unregister_interest;
>> +
>> + if (musb->port_mode == MUSB_PORT_MODE_HOST) {
>> + ret = phy_power_on(glue->phy);
>> + if (ret)
>> + goto error_phy_exit;
>> + set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
>> + }
>> +
>> + musb->isr = sunxi_musb_interrupt;
>> +
>> + /* Stop the musb-core from doing runtime pm (not supported on sunxi) */
>> + pm_runtime_get(musb->controller);
>> +
>> + return 0;
>> +
>> +error_phy_exit:
>> + phy_exit(glue->phy);
>> +error_unregister_interest:
>> + if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
>> + extcon_unregister_interest(&glue->host_cable_nb);
>> +error_clk_disable:
>> + clk_disable_unprepare(glue->clk);
>> +error_sram_release:
>> + sunxi_sram_release(SUNXI_SRAM_USB_OTG);
>> + return ret;
>> +}
>> +
>> +static int sunxi_musb_exit(struct musb *musb)
>> +{
>> + struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
>> +
>> + pm_runtime_put(musb->controller);
>> +
>> + cancel_work_sync(&glue->work);
>> + if (test_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags))
>> + phy_power_off(glue->phy);
>> +
>> + phy_exit(glue->phy);
>> +
>> + if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
>> + extcon_unregister_interest(&glue->host_cable_nb);
>> +
>> + clk_disable_unprepare(glue->clk);
>> + sunxi_sram_release(SUNXI_SRAM_USB_OTG);
>> +
>> + return 0;
>> +}
>> +
>> +static void sunxi_musb_enable(struct musb *musb)
>> +{
>> + struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
>> +
>> + /* musb_core does not call us in a balanced manner */
>> + if (test_and_set_bit(SUNXI_MUSB_FL_ENABLED, &glue->flags))
>> + return;
>> +
>> + schedule_work(&glue->work);
>> +}
>> +
>> +static void sunxi_musb_disable(struct musb *musb)
>> +{
>> + struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
>> +
>> + clear_bit(SUNXI_MUSB_FL_ENABLED, &glue->flags);
>> +}
>> +
>> +/*
>> + * sunxi musb register layout
>> + * 0x00 - 0x17 fifo regs, 1 long per fifo
>> + * 0x40 - 0x57 generic control regs (power - frame)
>
> Extra spaces.
Actually it is caused by a tab directly after the 0x40 instead of a space,
I've fixed this in my personal tree, I will send a v3 later.
>> + * 0x80 - 0x8f ep control regs (addressed through hw_ep->regs, indexed)
>> + * 0x90 - 0x97 fifo control regs (indexed)
>> + * 0x98 - 0x9f multipoint / busctl regs (indexed)
>> + * 0xc0 configdata reg
>> + */
>> +
>> +static u32 sunxi_musb_fifo_offset(u8 epnum)
>> +{
>> + return (epnum * 4);
>> +}
>> +
>> +static u32 sunxi_musb_ep_offset(u8 epnum, u16 offset)
>> +{
>> + WARN_ONCE(offset != 0,
>> + "sunxi_musb_ep_offset called with non 0 offset\n");
>> +
>> + return 0x80; /* indexed, so ignore epnum */
>> +}
>> +
>> +static u32 sunxi_musb_busctl_offset(u8 epnum, u16 offset)
>> +{
>> + return SUNXI_MUSB_TXFUNCADDR + offset;
>> +}
>> +
>> +static u8 sunxi_musb_readb(const void __iomem *addr, unsigned offset)
>> +{
>> + if (addr == sunxi_musb->mregs) {
>> + /* generic control or fifo control reg access */
>> + switch (offset) {
>> + case MUSB_FADDR:
>> + return readb(addr + SUNXI_MUSB_FADDR);
>> + case MUSB_POWER:
>> + return readb(addr + SUNXI_MUSB_POWER);
>> + case MUSB_INTRUSB:
>> + return readb(addr + SUNXI_MUSB_INTRUSB);
>> + case MUSB_INTRUSBE:
>> + return readb(addr + SUNXI_MUSB_INTRUSBE);
>> + case MUSB_INDEX:
>> + return readb(addr + SUNXI_MUSB_INDEX);
>> + case MUSB_TESTMODE:
>> + return 0; /* No testmode on sunxi */
>> + case MUSB_DEVCTL:
>> + return readb(addr + SUNXI_MUSB_DEVCTL);
>> + case MUSB_TXFIFOSZ:
>> + return readb(addr + SUNXI_MUSB_TXFIFOSZ);
>> + case MUSB_RXFIFOSZ:
>> + return readb(addr + SUNXI_MUSB_RXFIFOSZ);
>> + case MUSB_CONFIGDATA + 0x10: /* See musb_read_configdata() */
>> + return readb(addr + SUNXI_MUSB_CONFIGDATA);
>> + /* Offset for these is fixed by sunxi_musb_busctl_offset() */
>> + case SUNXI_MUSB_TXFUNCADDR:
>> + case SUNXI_MUSB_TXHUBADDR:
>> + case SUNXI_MUSB_TXHUBPORT:
>> + case SUNXI_MUSB_RXFUNCADDR:
>> + case SUNXI_MUSB_RXHUBADDR:
>> + case SUNXI_MUSB_RXHUBPORT:
>> + /* multipoint / busctl reg access */
>> + return readb(addr + offset);
>> + default:
>> + dev_err(sunxi_musb->controller->parent,
>> + "Error unknown readb offset %u\n", offset);
>> + return 0;
>> + }
>> + } else if (addr == (sunxi_musb->mregs + 0x80)) {
>> + /* ep control reg access */
>> + /* sunxi has a 2 byte hole before the txtype register */
>> + if (offset >= MUSB_TXTYPE)
>> + offset += 2;
>> + return readb(addr + offset);
>> + }
>> +
>> + dev_err(sunxi_musb->controller->parent,
>> + "Error unknown readb at 0x%x bytes offset\n",
>> + (int)(addr - sunxi_musb->mregs));
>> + return 0;
>> +}
>> +
>> +static void sunxi_musb_writeb(void __iomem *addr, unsigned offset, u8 data)
>> +{
>> + if (addr == sunxi_musb->mregs) {
>> + /* generic control or fifo control reg access */
>> + switch (offset) {
>> + case MUSB_FADDR:
>> + return writeb(data, addr + SUNXI_MUSB_FADDR);
>> + case MUSB_POWER:
>> + return writeb(data, addr + SUNXI_MUSB_POWER);
>> + case MUSB_INTRUSB:
>> + return writeb(data, addr + SUNXI_MUSB_INTRUSB);
>> + case MUSB_INTRUSBE:
>> + return writeb(data, addr + SUNXI_MUSB_INTRUSBE);
>> + case MUSB_INDEX:
>> + return writeb(data, addr + SUNXI_MUSB_INDEX);
>> + case MUSB_TESTMODE:
>> + if (data)
>> + dev_warn(sunxi_musb->controller->parent,
>> + "sunxi-musb does not have testmode\n");
>> + return;
>> + case MUSB_DEVCTL:
>> + return writeb(data, addr + SUNXI_MUSB_DEVCTL);
>> + case MUSB_TXFIFOSZ:
>> + return writeb(data, addr + SUNXI_MUSB_TXFIFOSZ);
>> + case MUSB_RXFIFOSZ:
>> + return writeb(data, addr + SUNXI_MUSB_RXFIFOSZ);
>> + /* Offset for these is fixed by sunxi_musb_busctl_offset() */
>> + case SUNXI_MUSB_TXFUNCADDR:
>> + case SUNXI_MUSB_TXHUBADDR:
>> + case SUNXI_MUSB_TXHUBPORT:
>> + case SUNXI_MUSB_RXFUNCADDR:
>> + case SUNXI_MUSB_RXHUBADDR:
>> + case SUNXI_MUSB_RXHUBPORT:
>> + /* multipoint / busctl reg access */
>> + return writeb(data, addr + offset);
>> + default:
>> + dev_err(sunxi_musb->controller->parent,
>> + "Error unknown writeb offset %u\n", offset);
>> + return;
>> + }
>> + } else if (addr == (sunxi_musb->mregs + 0x80)) {
>> + /* ep control reg access */
>> + if (offset >= MUSB_TXTYPE)
>> + offset += 2;
>> + return writeb(data, addr + offset);
>> + }
>> +
>> + dev_err(sunxi_musb->controller->parent,
>> + "Error unknown writeb at 0x%x bytes offset\n",
>> + (int)(addr - sunxi_musb->mregs));
>> +}
>> +
>> +static u16 sunxi_musb_readw(const void __iomem *addr, unsigned offset)
>> +{
>> + if (addr == sunxi_musb->mregs) {
>> + /* generic control or fifo control reg access */
>> + switch (offset) {
>> + case MUSB_INTRTX:
>> + return readw(addr + SUNXI_MUSB_INTRTX);
>> + case MUSB_INTRRX:
>> + return readw(addr + SUNXI_MUSB_INTRRX);
>> + case MUSB_INTRTXE:
>> + return readw(addr + SUNXI_MUSB_INTRTXE);
>> + case MUSB_INTRRXE:
>> + return readw(addr + SUNXI_MUSB_INTRRXE);
>> + case MUSB_FRAME:
>> + return readw(addr + SUNXI_MUSB_FRAME);
>> + case MUSB_TXFIFOADD:
>> + return readw(addr + SUNXI_MUSB_TXFIFOADD);
>> + case MUSB_RXFIFOADD:
>> + return readw(addr + SUNXI_MUSB_RXFIFOADD);
>> + case MUSB_HWVERS:
>> + return 0; /* sunxi musb version is not known */
>> + default:
>> + dev_err(sunxi_musb->controller->parent,
>> + "Error unknown readw offset %u\n", offset);
>> + return 0;
>> + }
>> + } else if (addr == (sunxi_musb->mregs + 0x80)) {
>> + /* ep control reg access */
>> + return readw(addr + offset);
>> + }
>> +
>> + dev_err(sunxi_musb->controller->parent,
>> + "Error unknown readw at 0x%x bytes offset\n",
>> + (int)(addr - sunxi_musb->mregs));
>> + return 0;
>> +}
>> +
>> +static void sunxi_musb_writew(void __iomem *addr, unsigned offset, u16 data)
>> +{
>> + if (addr == sunxi_musb->mregs) {
>> + /* generic control or fifo control reg access */
>> + switch (offset) {
>> + case MUSB_INTRTX:
>> + return writew(data, addr + SUNXI_MUSB_INTRTX);
>> + case MUSB_INTRRX:
>> + return writew(data, addr + SUNXI_MUSB_INTRRX);
>> + case MUSB_INTRTXE:
>> + return writew(data, addr + SUNXI_MUSB_INTRTXE);
>> + case MUSB_INTRRXE:
>> + return writew(data, addr + SUNXI_MUSB_INTRRXE);
>> + case MUSB_FRAME:
>> + return writew(data, addr + SUNXI_MUSB_FRAME);
>> + case MUSB_TXFIFOADD:
>> + return writew(data, addr + SUNXI_MUSB_TXFIFOADD);
>> + case MUSB_RXFIFOADD:
>> + return writew(data, addr + SUNXI_MUSB_RXFIFOADD);
>> + default:
>> + dev_err(sunxi_musb->controller->parent,
>> + "Error unknown writew offset %u\n", offset);
>> + return;
>> + }
>> + } else if (addr == (sunxi_musb->mregs + 0x80)) {
>> + /* ep control reg access */
>> + return writew(data, addr + offset);
>> + }
>> +
>> + dev_err(sunxi_musb->controller->parent,
>> + "Error unknown writew at 0x%x bytes offset\n",
>> + (int)(addr - sunxi_musb->mregs));
>> +}
>> +
>> +static const struct musb_platform_ops sunxi_musb_ops = {
>> + .quirks = MUSB_INDEXED_EP | MUSB_SUN4I,
>> + .init = sunxi_musb_init,
>> + .exit = sunxi_musb_exit,
>> + .enable = sunxi_musb_enable,
>> + .disable = sunxi_musb_disable,
>> + .fifo_offset = sunxi_musb_fifo_offset,
>> + .ep_offset = sunxi_musb_ep_offset,
>> + .busctl_offset = sunxi_musb_busctl_offset,
>> + .readb = sunxi_musb_readb,
>> + .writeb = sunxi_musb_writeb,
>> + .readw = sunxi_musb_readw,
>> + .writew = sunxi_musb_writew,
>> + .set_vbus = sunxi_musb_set_vbus,
>> +};
>> +
>> +/* Allwinner OTG supports up to 5 endpoints */
>> +#define SUNXI_MUSB_MAX_EP_NUM 6
>> +#define SUNXI_MUSB_RAM_BITS 11
>> +
>> +static struct musb_fifo_cfg sunxi_musb_mode_cfg[] = {
>> + MUSB_EP_FIFO_SINGLE(1, FIFO_TX, 512),
>> + MUSB_EP_FIFO_SINGLE(1, FIFO_RX, 512),
>> + MUSB_EP_FIFO_SINGLE(2, FIFO_TX, 512),
>> + MUSB_EP_FIFO_SINGLE(2, FIFO_RX, 512),
>> + MUSB_EP_FIFO_SINGLE(3, FIFO_TX, 512),
>> + MUSB_EP_FIFO_SINGLE(3, FIFO_RX, 512),
>> + MUSB_EP_FIFO_SINGLE(4, FIFO_TX, 512),
>> + MUSB_EP_FIFO_SINGLE(4, FIFO_RX, 512),
>> + MUSB_EP_FIFO_SINGLE(5, FIFO_TX, 512),
>> + MUSB_EP_FIFO_SINGLE(5, FIFO_RX, 512),
>> +};
>> +
>> +static struct musb_hdrc_config sunxi_musb_hdrc_config = {
>> + .fifo_cfg = sunxi_musb_mode_cfg,
>> + .fifo_cfg_size = ARRAY_SIZE(sunxi_musb_mode_cfg),
>> + .multipoint = true,
>> + .dyn_fifo = true,
>> + .soft_con = true,
>> + .num_eps = SUNXI_MUSB_MAX_EP_NUM,
>> + .ram_bits = SUNXI_MUSB_RAM_BITS,
>> + .dma = 0,
>> +};
>> +
>> +static int sunxi_musb_probe(struct platform_device *pdev)
>> +{
>> + struct musb_hdrc_platform_data pdata;
>> + struct platform_device_info pinfo;
>> + struct sunxi_glue *glue;
>> + struct device_node *np = pdev->dev.of_node;
>> + int ret;
>> +
>> + if (!np) {
>> + dev_err(&pdev->dev, "Error no device tree node found\n");
>> + return -EINVAL;
>> + }
>> +
>> + memset(&pdata, 0, sizeof(pdata));
>> + switch (of_usb_get_dr_mode(np)) {
>> + case USB_DR_MODE_HOST:
>> + pdata.mode = MUSB_PORT_MODE_HOST;
>> + break;
>> + case USB_DR_MODE_PERIPHERAL:
>> + dev_err(&pdev->dev,
>> + "Error peripheral only mode is not supported\n");
>> + return -EINVAL;
>> + case USB_DR_MODE_OTG:
>> + pdata.mode = MUSB_PORT_MODE_DUAL_ROLE;
>> + break;
>
> Do we want to have some #ifdefs or IS_ENABLED() around this to handle
> cases where musb is built in host only or peripheral only modes?
Good point, I've simply made it error out if the dr_mode conflicts with the
USB_MUSB_foo seleection.
>
> I tested v1 with a host only build and "otg" in the DT, which resulted
> in a oops somewhere. (Building host only is because I don't want to have
> to load a module to get a usb host on my tablet.)
>
>> + default:
>> + dev_err(&pdev->dev, "No 'dr_mode' property found\n");
>> + return -EINVAL;
>> + }
>> + pdata.platform_ops = &sunxi_musb_ops;
>> + pdata.config = &sunxi_musb_hdrc_config;
>> +
>> + glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
>> + if (!glue)
>> + return -ENOMEM;
>> +
>> + glue->dev = &pdev->dev;
>> + INIT_WORK(&glue->work, sunxi_musb_work);
>> + glue->host_nb.notifier_call = sunxi_musb_host_notifier;
>> +
>> + glue->clk = devm_clk_get(&pdev->dev, NULL);
>> + if (IS_ERR(glue->clk)) {
>> + dev_err(&pdev->dev, "Error getting clock: %ld\n",
>> + PTR_ERR(glue->clk));
>> + return PTR_ERR(glue->clk);
>> + }
>> +
>> + glue->phy = devm_phy_get(&pdev->dev, "usb");
>> + if (IS_ERR(glue->phy)) {
>> + if (PTR_ERR(glue->phy) == -EPROBE_DEFER)
>> + return -EPROBE_DEFER;
>> + dev_err(&pdev->dev, "Error getting phy %ld\n",
>> + PTR_ERR(glue->phy));
>> + return PTR_ERR(glue->phy);
>> + }
>> +
>> + glue->usb_phy = usb_phy_generic_register();
>> + if (IS_ERR(glue->usb_phy)) {
>> + dev_err(&pdev->dev, "Error registering usb-phy %ld\n",
>> + PTR_ERR(glue->usb_phy));
>> + return PTR_ERR(glue->usb_phy);
>> + }
>> +
>> + glue->xceiv = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
>> + if (IS_ERR(glue->xceiv)) {
>> + ret = PTR_ERR(glue->xceiv);
>> + dev_err(&pdev->dev, "Error getting usb-phy %d\n", ret);
>> + goto err_unregister_usb_phy;
>> + }
>> +
>> + platform_set_drvdata(pdev, glue);
>> +
>> + memset(&pinfo, 0, sizeof(pinfo));
>> + pinfo.name = "musb-hdrc";
>> + pinfo.id = PLATFORM_DEVID_AUTO;
>> + pinfo.parent = &pdev->dev;
>> + pinfo.res = pdev->resource;
>> + pinfo.num_res = pdev->num_resources;
>> + pinfo.data = &pdata;
>> + pinfo.size_data = sizeof(pdata);
>> +
>> + glue->musb = platform_device_register_full(&pinfo);
>> + if (IS_ERR(glue->musb)) {
>> + ret = PTR_ERR(glue->musb);
>> + dev_err(&pdev->dev, "Error registering musb dev: %d\n", ret);
>> + goto err_unregister_usb_phy;
>> + }
>> +
>> + return 0;
>> +
>> +err_unregister_usb_phy:
>> + usb_phy_generic_unregister(glue->usb_phy);
>> + return ret;
>> +}
>> +
>> +static int sunxi_musb_remove(struct platform_device *pdev)
>> +{
>> + struct sunxi_glue *glue = platform_get_drvdata(pdev);
>> + struct platform_device *usb_phy = glue->usb_phy;
>> +
>> + platform_device_unregister(glue->musb); /* Frees glue ! */
>> + usb_phy_generic_unregister(usb_phy);
>> +
>> + return 0;
>> +}
>> +
>> +static const struct of_device_id sunxi_musb_match[] = {
>> + { .compatible = "allwinner,sun4i-a10-musb", },
>> + {}
>> +};
>> +
>> +static struct platform_driver sunxi_musb_driver = {
>> + .probe = sunxi_musb_probe,
>> + .remove = sunxi_musb_remove,
>> + .driver = {
>> + .name = "musb-sunxi",
>> + .of_match_table = sunxi_musb_match,
>> + },
>> +};
>> +module_platform_driver(sunxi_musb_driver);
>> +
>> +MODULE_DESCRIPTION("Allwinner sunxi MUSB Glue Layer");
>> +MODULE_AUTHOR("Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>");
>> +MODULE_LICENSE("GPL v2");
>> --
>> 2.3.3
>>
>
> Thanks!
You're welcome and thanks for the review.
Regards,
Hans
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v2 00/13] musb: Add support for the Allwinner sunxi musb controller
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
` (12 preceding siblings ...)
2015-03-20 19:11 ` [PATCH v2 13/13] ARM: dts: sun7i: Enable USB DRC on A20-OLinuxIno-Lime Hans de Goede
@ 2015-03-23 16:49 ` Maxime Ripard
13 siblings, 0 replies; 25+ messages in thread
From: Maxime Ripard @ 2015-03-23 16:49 UTC (permalink / raw)
To: Hans de Goede
Cc: Felipe Balbi, Kishon Vijay Abraham I, Chen-Yu Tsai, Roman Byshko,
linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 1278 bytes --]
Hi Hans,
On Fri, Mar 20, 2015 at 08:11:09PM +0100, Hans de Goede wrote:
> Hi All,
>
> Here is v2 of my patch-set to add support for the musb variant found on
> Allwinner sunxi SoCs.
>
> Changes since the original posting:
> -Removed the sunxi specific phy functions, instead the id / vbus gpio polling
> has been moved to the phy-sun4i-usb driver and their status is exported
> through extcon for the sunxi-musb glue
> -Stop using syscon, instead Maxime Ripard's sunxi SRAM controller driver is now
> used
>
> This should address all review remarks against v1 of this patch-set, so
> hopefully we can start merging this upstream.
>
> The "musb: Add support for the Allwinner sunxi musb" commit relies on
> Maxime's SRAM controller patches, so those need to get merged first,
> but the phy-sun4i-usb and musb preparation patches can be merged already
> (assuming there are no objections).
>
> And then once the SRAM controller patches are in next we can also merge
> the "musb: Add support for the Allwinner sunxi musb" commit and the dts
> changes.
All the DT bits look fine to me. I'll wait for Felipe and Kishon
comments before merging those.
Thanks!
Maxime
--
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v2 04/13] musb: Do not use musb_read[b|w] / _write[b|w] wrappers in generic fifo functions
[not found] ` <1426878682-14521-5-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2015-05-11 15:58 ` Felipe Balbi
[not found] ` <20150511155846.GH19476-HgARHv6XitJaoMGHk7MhZQC/G2K4zDHf@public.gmane.org>
0 siblings, 1 reply; 25+ messages in thread
From: Felipe Balbi @ 2015-05-11 15:58 UTC (permalink / raw)
To: Hans de Goede
Cc: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard, Chen-Yu Tsai,
Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 1089 bytes --]
On Fri, Mar 20, 2015 at 08:11:13PM +0100, Hans de Goede wrote:
> The generic fifo functions already use non wrapped accesses in various
> cases through the iowrite#_rep functions, and all platforms which override
> the default musb_read[b|w] / _write[b|w] functions also provide their own
> fifo access functions, so we can safely drop the unnecessary indirection
> from the fifo access functions.
>
> Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> ---
> drivers/usb/musb/musb_core.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
> index 01ed3a6..016b5b9 100644
> --- a/drivers/usb/musb/musb_core.c
> +++ b/drivers/usb/musb/musb_core.c
> @@ -313,7 +313,7 @@ static void musb_default_write_fifo(struct musb_hw_ep *hw_ep, u16 len,
> index += len & ~0x03;
> }
> if (len & 0x02) {
> - musb_writew(fifo, 0, *(u16 *)&src[index]);
> + __raw_writew(*(u16 *)&src[index], fifo);
not all architectures provide __raw_* accessors, right ?
--
balbi
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v2 04/13] musb: Do not use musb_read[b|w] / _write[b|w] wrappers in generic fifo functions
[not found] ` <20150511155846.GH19476-HgARHv6XitJaoMGHk7MhZQC/G2K4zDHf@public.gmane.org>
@ 2015-05-11 16:21 ` Arnd Bergmann
2015-05-11 18:14 ` Hans de Goede
1 sibling, 0 replies; 25+ messages in thread
From: Arnd Bergmann @ 2015-05-11 16:21 UTC (permalink / raw)
To: balbi-l0cyMroinI0
Cc: Hans de Goede, Kishon Vijay Abraham I, Maxime Ripard,
Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw
On Monday 11 May 2015 10:58:46 Felipe Balbi wrote:
> On Fri, Mar 20, 2015 at 08:11:13PM +0100, Hans de Goede wrote:
> > The generic fifo functions already use non wrapped accesses in various
> > cases through the iowrite#_rep functions, and all platforms which override
> > the default musb_read[b|w] / _write[b|w] functions also provide their own
> > fifo access functions, so we can safely drop the unnecessary indirection
> > from the fifo access functions.
> >
> > Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> > ---
> > drivers/usb/musb/musb_core.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
> > index 01ed3a6..016b5b9 100644
> > --- a/drivers/usb/musb/musb_core.c
> > +++ b/drivers/usb/musb/musb_core.c
> > @@ -313,7 +313,7 @@ static void musb_default_write_fifo(struct musb_hw_ep *hw_ep, u16 len,
> > index += len & ~0x03;
> > }
> > if (len & 0x02) {
> > - musb_writew(fifo, 0, *(u16 *)&src[index]);
> > + __raw_writew(*(u16 *)&src[index], fifo);
>
> not all architectures provide __raw_* accessors, right ?
>
>
They do, but you shouldn't use them for MMIO registers normall because of
endianess concerns.
However, FIFOs are special, and I'd assume that the code before this patch
does not work on big-endian systems on which musb_writew is defined
as a little-endian accessor (writew, writew_relaxed, or iowrite16).
The reason is that a FIFO generally exposes bytes in streaming order,
so the first byte in the FIFO has to be copied from a memory buffer
first, while writew would do a byte swap here that is used for MMIO.
This should be reflected in the changelog, and possibly tested with a
big-endian kernel, but the patch looks correct to me.
Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Re: [PATCH v2 04/13] musb: Do not use musb_read[b|w] / _write[b|w] wrappers in generic fifo functions
[not found] ` <20150511155846.GH19476-HgARHv6XitJaoMGHk7MhZQC/G2K4zDHf@public.gmane.org>
2015-05-11 16:21 ` Arnd Bergmann
@ 2015-05-11 18:14 ` Hans de Goede
[not found] ` <5550F174.6000709-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
1 sibling, 1 reply; 25+ messages in thread
From: Hans de Goede @ 2015-05-11 18:14 UTC (permalink / raw)
To: balbi-l0cyMroinI0
Cc: Kishon Vijay Abraham I, Maxime Ripard, Chen-Yu Tsai, Roman Byshko,
linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw
Hi,
On 11-05-15 17:58, Felipe Balbi wrote:
> On Fri, Mar 20, 2015 at 08:11:13PM +0100, Hans de Goede wrote:
>> The generic fifo functions already use non wrapped accesses in various
>> cases through the iowrite#_rep functions, and all platforms which override
>> the default musb_read[b|w] / _write[b|w] functions also provide their own
>> fifo access functions, so we can safely drop the unnecessary indirection
>> from the fifo access functions.
>>
>> Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>> ---
>> drivers/usb/musb/musb_core.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
>> index 01ed3a6..016b5b9 100644
>> --- a/drivers/usb/musb/musb_core.c
>> +++ b/drivers/usb/musb/musb_core.c
>> @@ -313,7 +313,7 @@ static void musb_default_write_fifo(struct musb_hw_ep *hw_ep, u16 len,
>> index += len & ~0x03;
>> }
>> if (len & 0x02) {
>> - musb_writew(fifo, 0, *(u16 *)&src[index]);
>> + __raw_writew(*(u16 *)&src[index], fifo);
>
> not all architectures provide __raw_* accessors, right ?
As Arnd mentions in his reply, these are available everywhere.
Also note, that as I've tried to explain in the commit message already this commit
makes no functional changes what so ever, the generic musb_default_read/write_fifo
functions are only used by musb platforms which do not overwrite musb_write* /
musb_read* and musb_write* / musb_read* are already just thin wrappers around
the __raw_* functions.
Regards,
Hans
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [linux-sunxi] Re: [PATCH v2 04/13] musb: Do not use musb_read[b|w] / _write[b|w] wrappers in generic fifo functions
[not found] ` <5550F174.6000709-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2015-05-11 18:53 ` Arnd Bergmann
2015-05-11 19:11 ` Hans de Goede
0 siblings, 1 reply; 25+ messages in thread
From: Arnd Bergmann @ 2015-05-11 18:53 UTC (permalink / raw)
To: Hans de Goede
Cc: balbi-l0cyMroinI0, Kishon Vijay Abraham I, Maxime Ripard,
Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw
On Monday 11 May 2015 20:14:12 Hans de Goede wrote:
> Also note, that as I've tried to explain in the commit message already this commit
> makes no functional changes what so ever, the generic musb_default_read/write_fifo
> functions are only used by musb platforms which do not overwrite musb_write* /
> musb_read* and musb_write* / musb_read* are already just thin wrappers around
> the __raw_* functions.
Oh, that's a bit odd: That would mean that the defaults are also broken on
big-endian platforms, and fixing them would introduce the bug here, unless your
patch is applied.
Any idea why musb uses the __raw_* functions to start with? Can we change
them to read?_relaxed()/write?_relaxed() now that those are available on
all architectures?
Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [linux-sunxi] Re: [PATCH v2 04/13] musb: Do not use musb_read[b|w] / _write[b|w] wrappers in generic fifo functions
2015-05-11 18:53 ` [linux-sunxi] " Arnd Bergmann
@ 2015-05-11 19:11 ` Hans de Goede
0 siblings, 0 replies; 25+ messages in thread
From: Hans de Goede @ 2015-05-11 19:11 UTC (permalink / raw)
To: Arnd Bergmann
Cc: balbi-l0cyMroinI0, Kishon Vijay Abraham I, Maxime Ripard,
Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw
Hi,
On 11-05-15 20:53, Arnd Bergmann wrote:
> On Monday 11 May 2015 20:14:12 Hans de Goede wrote:
>> Also note, that as I've tried to explain in the commit message already this commit
>> makes no functional changes what so ever, the generic musb_default_read/write_fifo
>> functions are only used by musb platforms which do not overwrite musb_write* /
>> musb_read* and musb_write* / musb_read* are already just thin wrappers around
>> the __raw_* functions.
>
> Oh, that's a bit odd: That would mean that the defaults are also broken on
> big-endian platforms, and fixing them would introduce the bug here, unless your
> patch is applied.
>
> Any idea why musb uses the __raw_* functions to start with? Can we change
> them to read?_relaxed()/write?_relaxed() now that those are available on
> all architectures?
I'm afraid I've no idea, since the musb code is somewhat obscure / tricky
in places I've done my best to not make any functional changes what so ever
in the entire set, chances are things will work fine with just readl / writel
but verifying that is hard, so I've gone for the better safe then sorry approach.
Regards,
Hans
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v2 06/13] musb: Add support for the Allwinner sunxi musb controller
[not found] ` <1426878682-14521-7-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-03-21 2:04 ` Chen-Yu Tsai
@ 2015-05-26 15:48 ` Felipe Balbi
[not found] ` <20150526154802.GL26599-HgARHv6XitJaoMGHk7MhZQC/G2K4zDHf@public.gmane.org>
1 sibling, 1 reply; 25+ messages in thread
From: Felipe Balbi @ 2015-05-26 15:48 UTC (permalink / raw)
To: Hans de Goede
Cc: Felipe Balbi, Kishon Vijay Abraham I, Maxime Ripard, Chen-Yu Tsai,
Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 1198 bytes --]
On Fri, Mar 20, 2015 at 08:11:15PM +0100, Hans de Goede wrote:
> This is based on initial code to get the Allwinner sunxi musb controller
> supported by Chen-Yu Tsai and Roman Byshko.
>
> This adds support for the Allwinner sunxi musb controller in both host only
> and otg mode. Peripheral only mode is not supported, as no boards use that.
>
> This has been tested on a cubietruck (A20 SoC) and an UTOO P66 tablet
> (A13 SoC) with a variety of devices in host mode and with the g_serial gadget
> driver in peripheral mode, plugging otg / host cables in/out a lot of times
> in all possible imaginable plug orders.
>
> Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
drivers/usb/musb/sunxi.c:28:11: error: unable to open 'linux/soc/sunxi/sunxi_sram.h'
scripts/Makefile.build:264: recipe for target 'drivers/usb/musb/sunxi.o' failed
make[2]: *** [drivers/usb/musb/sunxi.o] Error 1
make[2]: *** Waiting for unfinished jobs....
scripts/Makefile.build:403: recipe for target 'drivers/usb/musb' failed
make[1]: *** [drivers/usb/musb] Error 2
Makefile:1548: recipe for target 'drivers/usb/' failed
make: *** [drivers/usb/] Error 2
What is the dependency ?
--
balbi
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v2 06/13] musb: Add support for the Allwinner sunxi musb controller
[not found] ` <20150526154802.GL26599-HgARHv6XitJaoMGHk7MhZQC/G2K4zDHf@public.gmane.org>
@ 2015-05-26 16:36 ` Hans de Goede
[not found] ` <5564A10E.3040402-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 25+ messages in thread
From: Hans de Goede @ 2015-05-26 16:36 UTC (permalink / raw)
To: balbi-l0cyMroinI0
Cc: Kishon Vijay Abraham I, Maxime Ripard, Chen-Yu Tsai, Roman Byshko,
linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Arnd Bergmann
Hi,
On 05/26/2015 05:48 PM, Felipe Balbi wrote:
> On Fri, Mar 20, 2015 at 08:11:15PM +0100, Hans de Goede wrote:
>> This is based on initial code to get the Allwinner sunxi musb controller
>> supported by Chen-Yu Tsai and Roman Byshko.
>>
>> This adds support for the Allwinner sunxi musb controller in both host only
>> and otg mode. Peripheral only mode is not supported, as no boards use that.
>>
>> This has been tested on a cubietruck (A20 SoC) and an UTOO P66 tablet
>> (A13 SoC) with a variety of devices in host mode and with the g_serial gadget
>> driver in peripheral mode, plugging otg / host cables in/out a lot of times
>> in all possible imaginable plug orders.
>>
>> Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>
> drivers/usb/musb/sunxi.c:28:11: error: unable to open 'linux/soc/sunxi/sunxi_sram.h'
> scripts/Makefile.build:264: recipe for target 'drivers/usb/musb/sunxi.o' failed
> make[2]: *** [drivers/usb/musb/sunxi.o] Error 1
> make[2]: *** Waiting for unfinished jobs....
> scripts/Makefile.build:403: recipe for target 'drivers/usb/musb' failed
> make[1]: *** [drivers/usb/musb] Error 2
> Makefile:1548: recipe for target 'drivers/usb/' failed
> make: *** [drivers/usb/] Error 2
>
> What is the dependency ?
Thanks you that you're working on this, the dependency is the sunxi sram
controller driver which was supposed to get pulled for 4.1, but like many
other ARM related pull-reqs did not get pulled. And now for 4.2 Arnd
has decided that he does not like the driver even though it was
ok for 4.1, and has not yet answered how else we should solve this...
Arnd, we would really like to move forward with musb support for sunxi
which means we need a solution for the sram controller, can you please
answer Maxime's latest mails on this, or accept the driver as is ?
Regards,
Hans
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v2 06/13] musb: Add support for the Allwinner sunxi musb controller
[not found] ` <5564A10E.3040402-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2015-05-26 17:06 ` Felipe Balbi
0 siblings, 0 replies; 25+ messages in thread
From: Felipe Balbi @ 2015-05-26 17:06 UTC (permalink / raw)
To: Hans de Goede
Cc: balbi-l0cyMroinI0, Kishon Vijay Abraham I, Maxime Ripard,
Chen-Yu Tsai, Roman Byshko, linux-usb-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Arnd Bergmann
[-- Attachment #1: Type: text/plain, Size: 2113 bytes --]
On Tue, May 26, 2015 at 06:36:30PM +0200, Hans de Goede wrote:
> Hi,
>
> On 05/26/2015 05:48 PM, Felipe Balbi wrote:
> >On Fri, Mar 20, 2015 at 08:11:15PM +0100, Hans de Goede wrote:
> >>This is based on initial code to get the Allwinner sunxi musb controller
> >>supported by Chen-Yu Tsai and Roman Byshko.
> >>
> >>This adds support for the Allwinner sunxi musb controller in both host only
> >>and otg mode. Peripheral only mode is not supported, as no boards use that.
> >>
> >>This has been tested on a cubietruck (A20 SoC) and an UTOO P66 tablet
> >>(A13 SoC) with a variety of devices in host mode and with the g_serial gadget
> >>driver in peripheral mode, plugging otg / host cables in/out a lot of times
> >>in all possible imaginable plug orders.
> >>
> >>Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> >
> >drivers/usb/musb/sunxi.c:28:11: error: unable to open 'linux/soc/sunxi/sunxi_sram.h'
> >scripts/Makefile.build:264: recipe for target 'drivers/usb/musb/sunxi.o' failed
> >make[2]: *** [drivers/usb/musb/sunxi.o] Error 1
> >make[2]: *** Waiting for unfinished jobs....
> >scripts/Makefile.build:403: recipe for target 'drivers/usb/musb' failed
> >make[1]: *** [drivers/usb/musb] Error 2
> >Makefile:1548: recipe for target 'drivers/usb/' failed
> >make: *** [drivers/usb/] Error 2
> >
> >What is the dependency ?
>
> Thanks you that you're working on this, the dependency is the sunxi sram
> controller driver which was supposed to get pulled for 4.1, but like many
> other ARM related pull-reqs did not get pulled. And now for 4.2 Arnd
> has decided that he does not like the driver even though it was
> ok for 4.1, and has not yet answered how else we should solve this...
>
> Arnd, we would really like to move forward with musb support for sunxi
> which means we need a solution for the sram controller, can you please
> answer Maxime's latest mails on this, or accept the driver as is ?
all right, most of the other patches are in my testing/next (please have
a look when you have some extra time) so ony this patch will be pending
for v4.2.
--
balbi
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2015-05-26 17:06 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-20 19:11 [PATCH v2 00/13] musb: Add support for the Allwinner sunxi musb controller Hans de Goede
[not found] ` <1426878682-14521-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-03-20 19:11 ` [PATCH v2 01/13] phy-sun4i-usb: Add full support for usb0 phy / OTG Hans de Goede
2015-03-20 19:11 ` [PATCH v2 02/13] musb: Make musb_write_rxfun* and musb_write_rxhub* work like their tx versions Hans de Goede
2015-03-20 19:11 ` [PATCH v2 03/13] musb: Make busctl_offset an io-op rather then a define Hans de Goede
2015-03-20 19:11 ` [PATCH v2 04/13] musb: Do not use musb_read[b|w] / _write[b|w] wrappers in generic fifo functions Hans de Goede
[not found] ` <1426878682-14521-5-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-05-11 15:58 ` Felipe Balbi
[not found] ` <20150511155846.GH19476-HgARHv6XitJaoMGHk7MhZQC/G2K4zDHf@public.gmane.org>
2015-05-11 16:21 ` Arnd Bergmann
2015-05-11 18:14 ` Hans de Goede
[not found] ` <5550F174.6000709-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-05-11 18:53 ` [linux-sunxi] " Arnd Bergmann
2015-05-11 19:11 ` Hans de Goede
2015-03-20 19:11 ` [PATCH v2 05/13] musb: Fix platform code being unable to override ep access ops Hans de Goede
2015-03-20 19:11 ` [PATCH v2 06/13] musb: Add support for the Allwinner sunxi musb controller Hans de Goede
[not found] ` <1426878682-14521-7-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-03-21 2:04 ` Chen-Yu Tsai
[not found] ` <CAGb2v661EFghwEPER5LEib5RSy1r=dhwBewebJCUO_1sWa5sFQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-21 9:30 ` Hans de Goede
2015-05-26 15:48 ` Felipe Balbi
[not found] ` <20150526154802.GL26599-HgARHv6XitJaoMGHk7MhZQC/G2K4zDHf@public.gmane.org>
2015-05-26 16:36 ` Hans de Goede
[not found] ` <5564A10E.3040402-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-05-26 17:06 ` Felipe Balbi
2015-03-20 19:11 ` [PATCH v2 07/13] ARM: dts: sun4i: Add USB Dual Role Controller Hans de Goede
2015-03-20 19:11 ` [PATCH v2 08/13] ARM: dts: sun5i: " Hans de Goede
2015-03-20 19:11 ` [PATCH v2 09/13] ARM: dts: sun7i: " Hans de Goede
2015-03-20 19:11 ` [PATCH v2 10/13] ARM: dts: sun4i: Enable USB DRC on Chuwi V7 CW0825 Hans de Goede
2015-03-20 19:11 ` [PATCH v2 11/13] ARM: dts: sun5i: Enable USB DRC on UTOO P66 Hans de Goede
2015-03-20 19:11 ` [PATCH v2 12/13] ARM: dts: sun7i: Enable USB DRC on Cubietruck Hans de Goede
2015-03-20 19:11 ` [PATCH v2 13/13] ARM: dts: sun7i: Enable USB DRC on A20-OLinuxIno-Lime Hans de Goede
2015-03-23 16:49 ` [PATCH v2 00/13] musb: Add support for the Allwinner sunxi musb controller Maxime Ripard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).