Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1348810 > unrolled thread
| Started by | Lu Baolu <baolu.lu@linux.intel.com> |
|---|---|
| First post | 2016-03-03 07:40 +0100 |
| Last post | 2016-03-04 03:00 +0100 |
| Articles | 7 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux Lu Baolu <baolu.lu@linux.intel.com> - 2016-03-03 07:40 +0100
Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-03-03 17:20 +0100
Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux Lu Baolu <baolu.lu@linux.intel.com> - 2016-03-04 02:50 +0100
Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-03-03 17:20 +0100
Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux Lu Baolu <baolu.lu@linux.intel.com> - 2016-03-04 02:40 +0100
Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-03-04 02:50 +0100
Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux Lu Baolu <baolu.lu@linux.intel.com> - 2016-03-04 03:00 +0100
| From | Lu Baolu <baolu.lu@linux.intel.com> |
|---|---|
| Date | 2016-03-03 07:40 +0100 |
| Subject | [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux |
| Message-ID | <r8v5w-37I-1@gated-at.bofh.it> |
Several Intel PCHs and SOCs have an internal mux that is used to
share one USB port between device controller and host controller.
The mux is handled through the Dual Role Configuration Register.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Wu Hao <hao.wu@intel.com>
Reviewed-by: Felipe Balbi <balbi@kernel.org>
---
MAINTAINERS | 1 +
drivers/usb/misc/Kconfig | 7 ++
drivers/usb/misc/Makefile | 1 +
drivers/usb/misc/intel-mux-drcfg.c | 174 +++++++++++++++++++++++++++++++++++++
4 files changed, 183 insertions(+)
create mode 100644 drivers/usb/misc/intel-mux-drcfg.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 0f321e4..20eb873 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11396,6 +11396,7 @@ S: Supported
F: drivers/usb/misc/mux.c
F: include/linux/usb/mux.h
F: drivers/usb/misc/intel-mux-gpio.c
+F: drivers/usb/misc/intel-mux-drcfg.c
USB PRINTER DRIVER (usblp)
M: Pete Zaitcev <zaitcev@redhat.com>
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index 33e6386..befd910 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -281,3 +281,10 @@ config INTEL_MUX_GPIO
help
Say Y here to enable support for Intel dual role port mux
controlled by GPIOs.
+
+config INTEL_MUX_DRCFG
+ tristate "Intel dual role port mux controlled by register"
+ select USB_MUX
+ help
+ Say Y here to enable support for Intel dual role port mux
+ controlled by the Dual Role Configuration Registers.
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index da4fb4e..c4d19a0 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -32,3 +32,4 @@ obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o
obj-$(CONFIG_USB_MUX) += mux.o
obj-$(CONFIG_INTEL_MUX_GPIO) += intel-mux-gpio.o
+obj-$(CONFIG_INTEL_MUX_DRCFG) += intel-mux-drcfg.o
diff --git a/drivers/usb/misc/intel-mux-drcfg.c b/drivers/usb/misc/intel-mux-drcfg.c
new file mode 100644
index 0000000..29081c5
--- /dev/null
+++ b/drivers/usb/misc/intel-mux-drcfg.c
@@ -0,0 +1,174 @@
+/**
+ * intel-mux-drcfg.c - Driver for Intel USB mux via register
+ *
+ * Copyright (C) 2016 Intel Corporation
+ * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
+ * Author: Lu Baolu <baolu.lu@linux.intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/property.h>
+#include <linux/usb/mux.h>
+#include <linux/platform_device.h>
+
+#define INTEL_MUX_CFG0 0x00
+#define INTEL_MUX_CFG1 0x04
+#define CFG0_SW_IDPIN BIT(20)
+#define CFG0_SW_IDPIN_EN BIT(21)
+#define CFG0_SW_VBUS_VALID BIT(24)
+#define CFG1_SW_MODE BIT(29)
+#define CFG1_POLL_TIMEOUT 1000
+
+struct intel_usb_mux {
+ struct usb_mux_dev umdev;
+ void __iomem *regs;
+ u32 cfg0_ctx;
+};
+
+static inline int intel_mux_drcfg_switch(struct usb_mux_dev *umdev, bool host)
+{
+ struct intel_usb_mux *mux;
+ unsigned long timeout;
+ u32 data;
+
+ mux = container_of(umdev, struct intel_usb_mux, umdev);
+
+ /* Check and set mux to SW controlled mode */
+ data = readl(mux->regs + INTEL_MUX_CFG0);
+ if (!(data & CFG0_SW_IDPIN_EN)) {
+ data |= CFG0_SW_IDPIN_EN;
+ writel(data, mux->regs + INTEL_MUX_CFG0);
+ }
+
+ /*
+ * Configure CFG0 to switch the mux and VBUS_VALID bit is
+ * required for device mode.
+ */
+ data = readl(mux->regs + INTEL_MUX_CFG0);
+ if (host)
+ data &= ~(CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
+ else
+ data |= (CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
+ writel(data, mux->regs + INTEL_MUX_CFG0);
+
+ /*
+ * Polling CFG1 for safety, most case it takes about 600ms
+ * to finish mode switching, set TIMEOUT long enough.
+ */
+ timeout = jiffies + msecs_to_jiffies(CFG1_POLL_TIMEOUT);
+
+ /* Polling on CFG1 register to confirm mode switch. */
+ while (!time_after(jiffies, timeout)) {
+ data = readl(mux->regs + INTEL_MUX_CFG1);
+ if (!(host ^ (data & CFG1_SW_MODE)))
+ return 0;
+ /* interval for polling is set to about 5ms */
+ usleep_range(5000, 5100);
+ }
+
+ return -ETIMEDOUT;
+}
+
+static int intel_mux_drcfg_cable_set(struct usb_mux_dev *umdev)
+{
+ dev_dbg(umdev->dev, "drcfg mux switch to HOST\n");
+
+ return intel_mux_drcfg_switch(umdev, true);
+}
+
+static int intel_mux_drcfg_cable_unset(struct usb_mux_dev *umdev)
+{
+ dev_dbg(umdev->dev, "drcfg mux switch to DEVICE\n");
+
+ return intel_mux_drcfg_switch(umdev, false);
+}
+
+static int intel_mux_drcfg_probe(struct platform_device *pdev)
+{
+ struct intel_usb_mux *mux;
+ struct usb_mux_dev *umdev;
+ struct device *dev = &pdev->dev;
+ u64 start, size;
+ int ret;
+
+ mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
+ if (!mux)
+ return -ENOMEM;
+
+ ret = device_property_read_u64(dev, "reg-start", &start);
+ ret |= device_property_read_u64(dev, "reg-size", &size);
+ if (ret)
+ return -ENODEV;
+
+ mux->regs = devm_ioremap_nocache(dev, start, size);
+ if (!mux->regs)
+ return -ENOMEM;
+
+ mux->cfg0_ctx = readl(mux->regs + INTEL_MUX_CFG0);
+
+ umdev = &mux->umdev;
+ umdev->dev = dev;
+ umdev->cable_name = "USB-HOST";
+ umdev->cable_set_cb = intel_mux_drcfg_cable_set;
+ umdev->cable_unset_cb = intel_mux_drcfg_cable_unset;
+
+ ret = usb_mux_register(umdev);
+ if (ret)
+ writel(mux->cfg0_ctx, mux->regs + INTEL_MUX_CFG0);
+
+ return ret;
+}
+
+static int intel_mux_drcfg_remove(struct platform_device *pdev)
+{
+ struct usb_mux_dev *umdev = usb_mux_get_dev(&pdev->dev);
+ struct intel_usb_mux *mux = container_of(umdev,
+ struct intel_usb_mux, umdev);
+
+ writel(mux->cfg0_ctx, mux->regs + INTEL_MUX_CFG0);
+
+ return usb_mux_unregister(&pdev->dev);
+}
+
+#ifdef CONFIG_PM_SLEEP
+/*
+ * In case a micro A cable was plugged in while device was sleeping,
+ * we missed the interrupt. We need to poll usb id state when waking
+ * the driver to detect the missed event.
+ * We use 'complete' callback to give time to all extcon listeners to
+ * resume before we send new events.
+ */
+static const struct dev_pm_ops intel_mux_drcfg_pm_ops = {
+ .complete = usb_mux_complete,
+};
+#endif
+
+static const struct platform_device_id intel_mux_drcfg_platform_ids[] = {
+ { .name = "intel-mux-drcfg", },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(platform, intel_mux_drcfg_platform_ids);
+
+static struct platform_driver intel_mux_drcfg_driver = {
+ .probe = intel_mux_drcfg_probe,
+ .remove = intel_mux_drcfg_remove,
+ .driver = {
+ .name = "intel-mux-drcfg",
+#ifdef CONFIG_PM_SLEEP
+ .pm = &intel_mux_drcfg_pm_ops,
+#endif
+ },
+ .id_table = intel_mux_drcfg_platform_ids,
+};
+
+module_platform_driver(intel_mux_drcfg_driver);
+
+MODULE_AUTHOR("Heikki Krogerus <heikki.krogerus@linux.intel.com>");
+MODULE_AUTHOR("Lu Baolu <baolu.lu@linux.intel.com>");
+MODULE_DESCRIPTION("Intel USB drcfg mux driver");
+MODULE_LICENSE("GPL v2");
--
2.1.4
[toc] | [next] | [standalone]
| From | Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
|---|---|
| Date | 2016-03-03 17:20 +0100 |
| Subject | Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux |
| Message-ID | <r8E8N-1eD-11@gated-at.bofh.it> |
| In reply to | #1348810 |
On Thu, Mar 03, 2016 at 02:37:42PM +0800, Lu Baolu wrote: > Several Intel PCHs and SOCs have an internal mux that is used to > share one USB port between device controller and host controller. > The mux is handled through the Dual Role Configuration Register. > > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> > Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> > Signed-off-by: Wu Hao <hao.wu@intel.com> > Reviewed-by: Felipe Balbi <balbi@kernel.org> > --- > MAINTAINERS | 1 + > drivers/usb/misc/Kconfig | 7 ++ > drivers/usb/misc/Makefile | 1 + > drivers/usb/misc/intel-mux-drcfg.c | 174 +++++++++++++++++++++++++++++++++++++ If you are going to start having a bunch of these, please make a new directory, drivers/usb/mux/ ?
[toc] | [prev] | [next] | [standalone]
| From | Lu Baolu <baolu.lu@linux.intel.com> |
|---|---|
| Date | 2016-03-04 02:50 +0100 |
| Subject | Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux |
| Message-ID | <r8N2p-7A3-1@gated-at.bofh.it> |
| In reply to | #1349328 |
On 03/04/2016 12:12 AM, Greg Kroah-Hartman wrote: > On Thu, Mar 03, 2016 at 02:37:42PM +0800, Lu Baolu wrote: >> Several Intel PCHs and SOCs have an internal mux that is used to >> share one USB port between device controller and host controller. >> The mux is handled through the Dual Role Configuration Register. >> >> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> >> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> >> Signed-off-by: Wu Hao <hao.wu@intel.com> >> Reviewed-by: Felipe Balbi <balbi@kernel.org> >> --- >> MAINTAINERS | 1 + >> drivers/usb/misc/Kconfig | 7 ++ >> drivers/usb/misc/Makefile | 1 + >> drivers/usb/misc/intel-mux-drcfg.c | 174 +++++++++++++++++++++++++++++++++++++ > If you are going to start having a bunch of these, please make a new > directory, drivers/usb/mux/ ? Sure. I can put them in drivers/usb/mux.
[toc] | [prev] | [next] | [standalone]
| From | Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
|---|---|
| Date | 2016-03-03 17:20 +0100 |
| Subject | Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux |
| Message-ID | <r8E8O-1eD-17@gated-at.bofh.it> |
| In reply to | #1348810 |
On Thu, Mar 03, 2016 at 02:37:42PM +0800, Lu Baolu wrote:
> Several Intel PCHs and SOCs have an internal mux that is used to
> share one USB port between device controller and host controller.
> The mux is handled through the Dual Role Configuration Register.
>
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> Signed-off-by: Wu Hao <hao.wu@intel.com>
> Reviewed-by: Felipe Balbi <balbi@kernel.org>
> ---
> MAINTAINERS | 1 +
> drivers/usb/misc/Kconfig | 7 ++
> drivers/usb/misc/Makefile | 1 +
> drivers/usb/misc/intel-mux-drcfg.c | 174 +++++++++++++++++++++++++++++++++++++
> 4 files changed, 183 insertions(+)
> create mode 100644 drivers/usb/misc/intel-mux-drcfg.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 0f321e4..20eb873 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -11396,6 +11396,7 @@ S: Supported
> F: drivers/usb/misc/mux.c
> F: include/linux/usb/mux.h
> F: drivers/usb/misc/intel-mux-gpio.c
> +F: drivers/usb/misc/intel-mux-drcfg.c
>
> USB PRINTER DRIVER (usblp)
> M: Pete Zaitcev <zaitcev@redhat.com>
> diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
> index 33e6386..befd910 100644
> --- a/drivers/usb/misc/Kconfig
> +++ b/drivers/usb/misc/Kconfig
> @@ -281,3 +281,10 @@ config INTEL_MUX_GPIO
> help
> Say Y here to enable support for Intel dual role port mux
> controlled by GPIOs.
> +
> +config INTEL_MUX_DRCFG
> + tristate "Intel dual role port mux controlled by register"
> + select USB_MUX
> + help
> + Say Y here to enable support for Intel dual role port mux
> + controlled by the Dual Role Configuration Registers.
> diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
> index da4fb4e..c4d19a0 100644
> --- a/drivers/usb/misc/Makefile
> +++ b/drivers/usb/misc/Makefile
> @@ -32,3 +32,4 @@ obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o
>
> obj-$(CONFIG_USB_MUX) += mux.o
> obj-$(CONFIG_INTEL_MUX_GPIO) += intel-mux-gpio.o
> +obj-$(CONFIG_INTEL_MUX_DRCFG) += intel-mux-drcfg.o
> diff --git a/drivers/usb/misc/intel-mux-drcfg.c b/drivers/usb/misc/intel-mux-drcfg.c
> new file mode 100644
> index 0000000..29081c5
> --- /dev/null
> +++ b/drivers/usb/misc/intel-mux-drcfg.c
> @@ -0,0 +1,174 @@
> +/**
> + * intel-mux-drcfg.c - Driver for Intel USB mux via register
> + *
> + * Copyright (C) 2016 Intel Corporation
> + * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> + * Author: Lu Baolu <baolu.lu@linux.intel.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#include <linux/slab.h>
> +#include <linux/module.h>
> +#include <linux/property.h>
> +#include <linux/usb/mux.h>
> +#include <linux/platform_device.h>
> +
> +#define INTEL_MUX_CFG0 0x00
> +#define INTEL_MUX_CFG1 0x04
> +#define CFG0_SW_IDPIN BIT(20)
> +#define CFG0_SW_IDPIN_EN BIT(21)
> +#define CFG0_SW_VBUS_VALID BIT(24)
> +#define CFG1_SW_MODE BIT(29)
> +#define CFG1_POLL_TIMEOUT 1000
> +
> +struct intel_usb_mux {
> + struct usb_mux_dev umdev;
> + void __iomem *regs;
> + u32 cfg0_ctx;
> +};
> +
> +static inline int intel_mux_drcfg_switch(struct usb_mux_dev *umdev, bool host)
> +{
> + struct intel_usb_mux *mux;
> + unsigned long timeout;
> + u32 data;
> +
> + mux = container_of(umdev, struct intel_usb_mux, umdev);
> +
> + /* Check and set mux to SW controlled mode */
> + data = readl(mux->regs + INTEL_MUX_CFG0);
> + if (!(data & CFG0_SW_IDPIN_EN)) {
> + data |= CFG0_SW_IDPIN_EN;
> + writel(data, mux->regs + INTEL_MUX_CFG0);
> + }
> +
> + /*
> + * Configure CFG0 to switch the mux and VBUS_VALID bit is
> + * required for device mode.
> + */
> + data = readl(mux->regs + INTEL_MUX_CFG0);
> + if (host)
> + data &= ~(CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
> + else
> + data |= (CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
> + writel(data, mux->regs + INTEL_MUX_CFG0);
> +
> + /*
> + * Polling CFG1 for safety, most case it takes about 600ms
> + * to finish mode switching, set TIMEOUT long enough.
> + */
> + timeout = jiffies + msecs_to_jiffies(CFG1_POLL_TIMEOUT);
> +
> + /* Polling on CFG1 register to confirm mode switch. */
> + while (!time_after(jiffies, timeout)) {
> + data = readl(mux->regs + INTEL_MUX_CFG1);
> + if (!(host ^ (data & CFG1_SW_MODE)))
> + return 0;
> + /* interval for polling is set to about 5ms */
> + usleep_range(5000, 5100);
> + }
> +
> + return -ETIMEDOUT;
> +}
> +
> +static int intel_mux_drcfg_cable_set(struct usb_mux_dev *umdev)
> +{
> + dev_dbg(umdev->dev, "drcfg mux switch to HOST\n");
> +
> + return intel_mux_drcfg_switch(umdev, true);
> +}
> +
> +static int intel_mux_drcfg_cable_unset(struct usb_mux_dev *umdev)
> +{
> + dev_dbg(umdev->dev, "drcfg mux switch to DEVICE\n");
> +
> + return intel_mux_drcfg_switch(umdev, false);
> +}
> +
> +static int intel_mux_drcfg_probe(struct platform_device *pdev)
> +{
> + struct intel_usb_mux *mux;
> + struct usb_mux_dev *umdev;
> + struct device *dev = &pdev->dev;
> + u64 start, size;
> + int ret;
> +
> + mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
> + if (!mux)
> + return -ENOMEM;
> +
> + ret = device_property_read_u64(dev, "reg-start", &start);
> + ret |= device_property_read_u64(dev, "reg-size", &size);
> + if (ret)
> + return -ENODEV;
And you leaked memory :(
> +
> + mux->regs = devm_ioremap_nocache(dev, start, size);
> + if (!mux->regs)
> + return -ENOMEM;
Memory gone :(
> +
> + mux->cfg0_ctx = readl(mux->regs + INTEL_MUX_CFG0);
> +
> + umdev = &mux->umdev;
> + umdev->dev = dev;
> + umdev->cable_name = "USB-HOST";
> + umdev->cable_set_cb = intel_mux_drcfg_cable_set;
> + umdev->cable_unset_cb = intel_mux_drcfg_cable_unset;
> +
> + ret = usb_mux_register(umdev);
> + if (ret)
> + writel(mux->cfg0_ctx, mux->regs + INTEL_MUX_CFG0);
So if an error happens you just keep going?
[toc] | [prev] | [next] | [standalone]
| From | Lu Baolu <baolu.lu@linux.intel.com> |
|---|---|
| Date | 2016-03-04 02:40 +0100 |
| Subject | Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux |
| Message-ID | <r8MSK-7vn-3@gated-at.bofh.it> |
| In reply to | #1349332 |
On 03/04/2016 12:14 AM, Greg Kroah-Hartman wrote:
> On Thu, Mar 03, 2016 at 02:37:42PM +0800, Lu Baolu wrote:
>> Several Intel PCHs and SOCs have an internal mux that is used to
>> share one USB port between device controller and host controller.
>> The mux is handled through the Dual Role Configuration Register.
>>
>> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>> Signed-off-by: Wu Hao <hao.wu@intel.com>
>> Reviewed-by: Felipe Balbi <balbi@kernel.org>
>> ---
>> MAINTAINERS | 1 +
>> drivers/usb/misc/Kconfig | 7 ++
>> drivers/usb/misc/Makefile | 1 +
>> drivers/usb/misc/intel-mux-drcfg.c | 174 +++++++++++++++++++++++++++++++++++++
>> 4 files changed, 183 insertions(+)
>> create mode 100644 drivers/usb/misc/intel-mux-drcfg.c
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 0f321e4..20eb873 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -11396,6 +11396,7 @@ S: Supported
>> F: drivers/usb/misc/mux.c
>> F: include/linux/usb/mux.h
>> F: drivers/usb/misc/intel-mux-gpio.c
>> +F: drivers/usb/misc/intel-mux-drcfg.c
>>
>> USB PRINTER DRIVER (usblp)
>> M: Pete Zaitcev <zaitcev@redhat.com>
>> diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
>> index 33e6386..befd910 100644
>> --- a/drivers/usb/misc/Kconfig
>> +++ b/drivers/usb/misc/Kconfig
>> @@ -281,3 +281,10 @@ config INTEL_MUX_GPIO
>> help
>> Say Y here to enable support for Intel dual role port mux
>> controlled by GPIOs.
>> +
>> +config INTEL_MUX_DRCFG
>> + tristate "Intel dual role port mux controlled by register"
>> + select USB_MUX
>> + help
>> + Say Y here to enable support for Intel dual role port mux
>> + controlled by the Dual Role Configuration Registers.
>> diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
>> index da4fb4e..c4d19a0 100644
>> --- a/drivers/usb/misc/Makefile
>> +++ b/drivers/usb/misc/Makefile
>> @@ -32,3 +32,4 @@ obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o
>>
>> obj-$(CONFIG_USB_MUX) += mux.o
>> obj-$(CONFIG_INTEL_MUX_GPIO) += intel-mux-gpio.o
>> +obj-$(CONFIG_INTEL_MUX_DRCFG) += intel-mux-drcfg.o
>> diff --git a/drivers/usb/misc/intel-mux-drcfg.c b/drivers/usb/misc/intel-mux-drcfg.c
>> new file mode 100644
>> index 0000000..29081c5
>> --- /dev/null
>> +++ b/drivers/usb/misc/intel-mux-drcfg.c
>> @@ -0,0 +1,174 @@
>> +/**
>> + * intel-mux-drcfg.c - Driver for Intel USB mux via register
>> + *
>> + * Copyright (C) 2016 Intel Corporation
>> + * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>> + * Author: Lu Baolu <baolu.lu@linux.intel.com>
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2 as
>> + * published by the Free Software Foundation.
>> + */
>> +
>> +#include <linux/slab.h>
>> +#include <linux/module.h>
>> +#include <linux/property.h>
>> +#include <linux/usb/mux.h>
>> +#include <linux/platform_device.h>
>> +
>> +#define INTEL_MUX_CFG0 0x00
>> +#define INTEL_MUX_CFG1 0x04
>> +#define CFG0_SW_IDPIN BIT(20)
>> +#define CFG0_SW_IDPIN_EN BIT(21)
>> +#define CFG0_SW_VBUS_VALID BIT(24)
>> +#define CFG1_SW_MODE BIT(29)
>> +#define CFG1_POLL_TIMEOUT 1000
>> +
>> +struct intel_usb_mux {
>> + struct usb_mux_dev umdev;
>> + void __iomem *regs;
>> + u32 cfg0_ctx;
>> +};
>> +
>> +static inline int intel_mux_drcfg_switch(struct usb_mux_dev *umdev, bool host)
>> +{
>> + struct intel_usb_mux *mux;
>> + unsigned long timeout;
>> + u32 data;
>> +
>> + mux = container_of(umdev, struct intel_usb_mux, umdev);
>> +
>> + /* Check and set mux to SW controlled mode */
>> + data = readl(mux->regs + INTEL_MUX_CFG0);
>> + if (!(data & CFG0_SW_IDPIN_EN)) {
>> + data |= CFG0_SW_IDPIN_EN;
>> + writel(data, mux->regs + INTEL_MUX_CFG0);
>> + }
>> +
>> + /*
>> + * Configure CFG0 to switch the mux and VBUS_VALID bit is
>> + * required for device mode.
>> + */
>> + data = readl(mux->regs + INTEL_MUX_CFG0);
>> + if (host)
>> + data &= ~(CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
>> + else
>> + data |= (CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
>> + writel(data, mux->regs + INTEL_MUX_CFG0);
>> +
>> + /*
>> + * Polling CFG1 for safety, most case it takes about 600ms
>> + * to finish mode switching, set TIMEOUT long enough.
>> + */
>> + timeout = jiffies + msecs_to_jiffies(CFG1_POLL_TIMEOUT);
>> +
>> + /* Polling on CFG1 register to confirm mode switch. */
>> + while (!time_after(jiffies, timeout)) {
>> + data = readl(mux->regs + INTEL_MUX_CFG1);
>> + if (!(host ^ (data & CFG1_SW_MODE)))
>> + return 0;
>> + /* interval for polling is set to about 5ms */
>> + usleep_range(5000, 5100);
>> + }
>> +
>> + return -ETIMEDOUT;
>> +}
>> +
>> +static int intel_mux_drcfg_cable_set(struct usb_mux_dev *umdev)
>> +{
>> + dev_dbg(umdev->dev, "drcfg mux switch to HOST\n");
>> +
>> + return intel_mux_drcfg_switch(umdev, true);
>> +}
>> +
>> +static int intel_mux_drcfg_cable_unset(struct usb_mux_dev *umdev)
>> +{
>> + dev_dbg(umdev->dev, "drcfg mux switch to DEVICE\n");
>> +
>> + return intel_mux_drcfg_switch(umdev, false);
>> +}
>> +
>> +static int intel_mux_drcfg_probe(struct platform_device *pdev)
>> +{
>> + struct intel_usb_mux *mux;
>> + struct usb_mux_dev *umdev;
>> + struct device *dev = &pdev->dev;
>> + u64 start, size;
>> + int ret;
>> +
>> + mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
>> + if (!mux)
>> + return -ENOMEM;
>> +
>> + ret = device_property_read_u64(dev, "reg-start", &start);
>> + ret |= device_property_read_u64(dev, "reg-size", &size);
>> + if (ret)
>> + return -ENODEV;
> And you leaked memory :(
Did you mean device_property_read_*() allocated memory
and I need to release it before return error?
>
>> +
>> + mux->regs = devm_ioremap_nocache(dev, start, size);
>> + if (!mux->regs)
>> + return -ENOMEM;
> Memory gone :(
devm interface will manage the resources by itself, or not?
>
>> +
>> + mux->cfg0_ctx = readl(mux->regs + INTEL_MUX_CFG0);
>> +
>> + umdev = &mux->umdev;
>> + umdev->dev = dev;
>> + umdev->cable_name = "USB-HOST";
>> + umdev->cable_set_cb = intel_mux_drcfg_cable_set;
>> + umdev->cable_unset_cb = intel_mux_drcfg_cable_unset;
>> +
>> + ret = usb_mux_register(umdev);
>> + if (ret)
>> + writel(mux->cfg0_ctx, mux->regs + INTEL_MUX_CFG0);
> So if an error happens you just keep going?
No. If error happens, I will restore the register and return error.
Thanks,
-Baolu
[toc] | [prev] | [next] | [standalone]
| From | Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
|---|---|
| Date | 2016-03-04 02:50 +0100 |
| Subject | Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux |
| Message-ID | <r8N2q-7A3-3@gated-at.bofh.it> |
| In reply to | #1349758 |
On Fri, Mar 04, 2016 at 09:38:58AM +0800, Lu Baolu wrote:
>
>
> On 03/04/2016 12:14 AM, Greg Kroah-Hartman wrote:
> > On Thu, Mar 03, 2016 at 02:37:42PM +0800, Lu Baolu wrote:
> >> Several Intel PCHs and SOCs have an internal mux that is used to
> >> share one USB port between device controller and host controller.
> >> The mux is handled through the Dual Role Configuration Register.
> >>
> >> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> >> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> >> Signed-off-by: Wu Hao <hao.wu@intel.com>
> >> Reviewed-by: Felipe Balbi <balbi@kernel.org>
> >> ---
> >> MAINTAINERS | 1 +
> >> drivers/usb/misc/Kconfig | 7 ++
> >> drivers/usb/misc/Makefile | 1 +
> >> drivers/usb/misc/intel-mux-drcfg.c | 174 +++++++++++++++++++++++++++++++++++++
> >> 4 files changed, 183 insertions(+)
> >> create mode 100644 drivers/usb/misc/intel-mux-drcfg.c
> >>
> >> diff --git a/MAINTAINERS b/MAINTAINERS
> >> index 0f321e4..20eb873 100644
> >> --- a/MAINTAINERS
> >> +++ b/MAINTAINERS
> >> @@ -11396,6 +11396,7 @@ S: Supported
> >> F: drivers/usb/misc/mux.c
> >> F: include/linux/usb/mux.h
> >> F: drivers/usb/misc/intel-mux-gpio.c
> >> +F: drivers/usb/misc/intel-mux-drcfg.c
> >>
> >> USB PRINTER DRIVER (usblp)
> >> M: Pete Zaitcev <zaitcev@redhat.com>
> >> diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
> >> index 33e6386..befd910 100644
> >> --- a/drivers/usb/misc/Kconfig
> >> +++ b/drivers/usb/misc/Kconfig
> >> @@ -281,3 +281,10 @@ config INTEL_MUX_GPIO
> >> help
> >> Say Y here to enable support for Intel dual role port mux
> >> controlled by GPIOs.
> >> +
> >> +config INTEL_MUX_DRCFG
> >> + tristate "Intel dual role port mux controlled by register"
> >> + select USB_MUX
> >> + help
> >> + Say Y here to enable support for Intel dual role port mux
> >> + controlled by the Dual Role Configuration Registers.
> >> diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
> >> index da4fb4e..c4d19a0 100644
> >> --- a/drivers/usb/misc/Makefile
> >> +++ b/drivers/usb/misc/Makefile
> >> @@ -32,3 +32,4 @@ obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o
> >>
> >> obj-$(CONFIG_USB_MUX) += mux.o
> >> obj-$(CONFIG_INTEL_MUX_GPIO) += intel-mux-gpio.o
> >> +obj-$(CONFIG_INTEL_MUX_DRCFG) += intel-mux-drcfg.o
> >> diff --git a/drivers/usb/misc/intel-mux-drcfg.c b/drivers/usb/misc/intel-mux-drcfg.c
> >> new file mode 100644
> >> index 0000000..29081c5
> >> --- /dev/null
> >> +++ b/drivers/usb/misc/intel-mux-drcfg.c
> >> @@ -0,0 +1,174 @@
> >> +/**
> >> + * intel-mux-drcfg.c - Driver for Intel USB mux via register
> >> + *
> >> + * Copyright (C) 2016 Intel Corporation
> >> + * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> >> + * Author: Lu Baolu <baolu.lu@linux.intel.com>
> >> + *
> >> + * This program is free software; you can redistribute it and/or modify
> >> + * it under the terms of the GNU General Public License version 2 as
> >> + * published by the Free Software Foundation.
> >> + */
> >> +
> >> +#include <linux/slab.h>
> >> +#include <linux/module.h>
> >> +#include <linux/property.h>
> >> +#include <linux/usb/mux.h>
> >> +#include <linux/platform_device.h>
> >> +
> >> +#define INTEL_MUX_CFG0 0x00
> >> +#define INTEL_MUX_CFG1 0x04
> >> +#define CFG0_SW_IDPIN BIT(20)
> >> +#define CFG0_SW_IDPIN_EN BIT(21)
> >> +#define CFG0_SW_VBUS_VALID BIT(24)
> >> +#define CFG1_SW_MODE BIT(29)
> >> +#define CFG1_POLL_TIMEOUT 1000
> >> +
> >> +struct intel_usb_mux {
> >> + struct usb_mux_dev umdev;
> >> + void __iomem *regs;
> >> + u32 cfg0_ctx;
> >> +};
> >> +
> >> +static inline int intel_mux_drcfg_switch(struct usb_mux_dev *umdev, bool host)
> >> +{
> >> + struct intel_usb_mux *mux;
> >> + unsigned long timeout;
> >> + u32 data;
> >> +
> >> + mux = container_of(umdev, struct intel_usb_mux, umdev);
> >> +
> >> + /* Check and set mux to SW controlled mode */
> >> + data = readl(mux->regs + INTEL_MUX_CFG0);
> >> + if (!(data & CFG0_SW_IDPIN_EN)) {
> >> + data |= CFG0_SW_IDPIN_EN;
> >> + writel(data, mux->regs + INTEL_MUX_CFG0);
> >> + }
> >> +
> >> + /*
> >> + * Configure CFG0 to switch the mux and VBUS_VALID bit is
> >> + * required for device mode.
> >> + */
> >> + data = readl(mux->regs + INTEL_MUX_CFG0);
> >> + if (host)
> >> + data &= ~(CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
> >> + else
> >> + data |= (CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
> >> + writel(data, mux->regs + INTEL_MUX_CFG0);
> >> +
> >> + /*
> >> + * Polling CFG1 for safety, most case it takes about 600ms
> >> + * to finish mode switching, set TIMEOUT long enough.
> >> + */
> >> + timeout = jiffies + msecs_to_jiffies(CFG1_POLL_TIMEOUT);
> >> +
> >> + /* Polling on CFG1 register to confirm mode switch. */
> >> + while (!time_after(jiffies, timeout)) {
> >> + data = readl(mux->regs + INTEL_MUX_CFG1);
> >> + if (!(host ^ (data & CFG1_SW_MODE)))
> >> + return 0;
> >> + /* interval for polling is set to about 5ms */
> >> + usleep_range(5000, 5100);
> >> + }
> >> +
> >> + return -ETIMEDOUT;
> >> +}
> >> +
> >> +static int intel_mux_drcfg_cable_set(struct usb_mux_dev *umdev)
> >> +{
> >> + dev_dbg(umdev->dev, "drcfg mux switch to HOST\n");
> >> +
> >> + return intel_mux_drcfg_switch(umdev, true);
> >> +}
> >> +
> >> +static int intel_mux_drcfg_cable_unset(struct usb_mux_dev *umdev)
> >> +{
> >> + dev_dbg(umdev->dev, "drcfg mux switch to DEVICE\n");
> >> +
> >> + return intel_mux_drcfg_switch(umdev, false);
> >> +}
> >> +
> >> +static int intel_mux_drcfg_probe(struct platform_device *pdev)
> >> +{
> >> + struct intel_usb_mux *mux;
> >> + struct usb_mux_dev *umdev;
> >> + struct device *dev = &pdev->dev;
> >> + u64 start, size;
> >> + int ret;
> >> +
> >> + mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
> >> + if (!mux)
> >> + return -ENOMEM;
> >> +
> >> + ret = device_property_read_u64(dev, "reg-start", &start);
> >> + ret |= device_property_read_u64(dev, "reg-size", &size);
> >> + if (ret)
> >> + return -ENODEV;
> > And you leaked memory :(
>
> Did you mean device_property_read_*() allocated memory
> and I need to release it before return error?
>
> >
> >> +
> >> + mux->regs = devm_ioremap_nocache(dev, start, size);
> >> + if (!mux->regs)
> >> + return -ENOMEM;
> > Memory gone :(
>
> devm interface will manage the resources by itself, or not?
Ugh, you are right, nevermind, these both are fine, sorry for the noise.
> >> + mux->cfg0_ctx = readl(mux->regs + INTEL_MUX_CFG0);
> >> +
> >> + umdev = &mux->umdev;
> >> + umdev->dev = dev;
> >> + umdev->cable_name = "USB-HOST";
> >> + umdev->cable_set_cb = intel_mux_drcfg_cable_set;
> >> + umdev->cable_unset_cb = intel_mux_drcfg_cable_unset;
> >> +
> >> + ret = usb_mux_register(umdev);
> >> + if (ret)
> >> + writel(mux->cfg0_ctx, mux->regs + INTEL_MUX_CFG0);
> > So if an error happens you just keep going?
>
> No. If error happens, I will restore the register and return error.
That seems a bit "odd", and will change when you fix up the api...
thanks,
greg k-h
[toc] | [prev] | [next] | [standalone]
| From | Lu Baolu <baolu.lu@linux.intel.com> |
|---|---|
| Date | 2016-03-04 03:00 +0100 |
| Subject | Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux |
| Message-ID | <r8Nc7-7Fq-35@gated-at.bofh.it> |
| In reply to | #1349762 |
On 03/04/2016 09:44 AM, Greg Kroah-Hartman wrote:
> On Fri, Mar 04, 2016 at 09:38:58AM +0800, Lu Baolu wrote:
>>
>> On 03/04/2016 12:14 AM, Greg Kroah-Hartman wrote:
>>> On Thu, Mar 03, 2016 at 02:37:42PM +0800, Lu Baolu wrote:
>>>> Several Intel PCHs and SOCs have an internal mux that is used to
>>>> share one USB port between device controller and host controller.
>>>> The mux is handled through the Dual Role Configuration Register.
>>>>
>>>> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>>>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>>>> Signed-off-by: Wu Hao <hao.wu@intel.com>
>>>> Reviewed-by: Felipe Balbi <balbi@kernel.org>
>>>> ---
>>>> MAINTAINERS | 1 +
>>>> drivers/usb/misc/Kconfig | 7 ++
>>>> drivers/usb/misc/Makefile | 1 +
>>>> drivers/usb/misc/intel-mux-drcfg.c | 174 +++++++++++++++++++++++++++++++++++++
>>>> 4 files changed, 183 insertions(+)
>>>> create mode 100644 drivers/usb/misc/intel-mux-drcfg.c
>>>>
>>>> diff --git a/MAINTAINERS b/MAINTAINERS
>>>> index 0f321e4..20eb873 100644
>>>> --- a/MAINTAINERS
>>>> +++ b/MAINTAINERS
>>>> @@ -11396,6 +11396,7 @@ S: Supported
>>>> F: drivers/usb/misc/mux.c
>>>> F: include/linux/usb/mux.h
>>>> F: drivers/usb/misc/intel-mux-gpio.c
>>>> +F: drivers/usb/misc/intel-mux-drcfg.c
>>>>
>>>> USB PRINTER DRIVER (usblp)
>>>> M: Pete Zaitcev <zaitcev@redhat.com>
>>>> diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
>>>> index 33e6386..befd910 100644
>>>> --- a/drivers/usb/misc/Kconfig
>>>> +++ b/drivers/usb/misc/Kconfig
>>>> @@ -281,3 +281,10 @@ config INTEL_MUX_GPIO
>>>> help
>>>> Say Y here to enable support for Intel dual role port mux
>>>> controlled by GPIOs.
>>>> +
>>>> +config INTEL_MUX_DRCFG
>>>> + tristate "Intel dual role port mux controlled by register"
>>>> + select USB_MUX
>>>> + help
>>>> + Say Y here to enable support for Intel dual role port mux
>>>> + controlled by the Dual Role Configuration Registers.
>>>> diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
>>>> index da4fb4e..c4d19a0 100644
>>>> --- a/drivers/usb/misc/Makefile
>>>> +++ b/drivers/usb/misc/Makefile
>>>> @@ -32,3 +32,4 @@ obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o
>>>>
>>>> obj-$(CONFIG_USB_MUX) += mux.o
>>>> obj-$(CONFIG_INTEL_MUX_GPIO) += intel-mux-gpio.o
>>>> +obj-$(CONFIG_INTEL_MUX_DRCFG) += intel-mux-drcfg.o
>>>> diff --git a/drivers/usb/misc/intel-mux-drcfg.c b/drivers/usb/misc/intel-mux-drcfg.c
>>>> new file mode 100644
>>>> index 0000000..29081c5
>>>> --- /dev/null
>>>> +++ b/drivers/usb/misc/intel-mux-drcfg.c
>>>> @@ -0,0 +1,174 @@
>>>> +/**
>>>> + * intel-mux-drcfg.c - Driver for Intel USB mux via register
>>>> + *
>>>> + * Copyright (C) 2016 Intel Corporation
>>>> + * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>>>> + * Author: Lu Baolu <baolu.lu@linux.intel.com>
>>>> + *
>>>> + * This program is free software; you can redistribute it and/or modify
>>>> + * it under the terms of the GNU General Public License version 2 as
>>>> + * published by the Free Software Foundation.
>>>> + */
>>>> +
>>>> +#include <linux/slab.h>
>>>> +#include <linux/module.h>
>>>> +#include <linux/property.h>
>>>> +#include <linux/usb/mux.h>
>>>> +#include <linux/platform_device.h>
>>>> +
>>>> +#define INTEL_MUX_CFG0 0x00
>>>> +#define INTEL_MUX_CFG1 0x04
>>>> +#define CFG0_SW_IDPIN BIT(20)
>>>> +#define CFG0_SW_IDPIN_EN BIT(21)
>>>> +#define CFG0_SW_VBUS_VALID BIT(24)
>>>> +#define CFG1_SW_MODE BIT(29)
>>>> +#define CFG1_POLL_TIMEOUT 1000
>>>> +
>>>> +struct intel_usb_mux {
>>>> + struct usb_mux_dev umdev;
>>>> + void __iomem *regs;
>>>> + u32 cfg0_ctx;
>>>> +};
>>>> +
>>>> +static inline int intel_mux_drcfg_switch(struct usb_mux_dev *umdev, bool host)
>>>> +{
>>>> + struct intel_usb_mux *mux;
>>>> + unsigned long timeout;
>>>> + u32 data;
>>>> +
>>>> + mux = container_of(umdev, struct intel_usb_mux, umdev);
>>>> +
>>>> + /* Check and set mux to SW controlled mode */
>>>> + data = readl(mux->regs + INTEL_MUX_CFG0);
>>>> + if (!(data & CFG0_SW_IDPIN_EN)) {
>>>> + data |= CFG0_SW_IDPIN_EN;
>>>> + writel(data, mux->regs + INTEL_MUX_CFG0);
>>>> + }
>>>> +
>>>> + /*
>>>> + * Configure CFG0 to switch the mux and VBUS_VALID bit is
>>>> + * required for device mode.
>>>> + */
>>>> + data = readl(mux->regs + INTEL_MUX_CFG0);
>>>> + if (host)
>>>> + data &= ~(CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
>>>> + else
>>>> + data |= (CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
>>>> + writel(data, mux->regs + INTEL_MUX_CFG0);
>>>> +
>>>> + /*
>>>> + * Polling CFG1 for safety, most case it takes about 600ms
>>>> + * to finish mode switching, set TIMEOUT long enough.
>>>> + */
>>>> + timeout = jiffies + msecs_to_jiffies(CFG1_POLL_TIMEOUT);
>>>> +
>>>> + /* Polling on CFG1 register to confirm mode switch. */
>>>> + while (!time_after(jiffies, timeout)) {
>>>> + data = readl(mux->regs + INTEL_MUX_CFG1);
>>>> + if (!(host ^ (data & CFG1_SW_MODE)))
>>>> + return 0;
>>>> + /* interval for polling is set to about 5ms */
>>>> + usleep_range(5000, 5100);
>>>> + }
>>>> +
>>>> + return -ETIMEDOUT;
>>>> +}
>>>> +
>>>> +static int intel_mux_drcfg_cable_set(struct usb_mux_dev *umdev)
>>>> +{
>>>> + dev_dbg(umdev->dev, "drcfg mux switch to HOST\n");
>>>> +
>>>> + return intel_mux_drcfg_switch(umdev, true);
>>>> +}
>>>> +
>>>> +static int intel_mux_drcfg_cable_unset(struct usb_mux_dev *umdev)
>>>> +{
>>>> + dev_dbg(umdev->dev, "drcfg mux switch to DEVICE\n");
>>>> +
>>>> + return intel_mux_drcfg_switch(umdev, false);
>>>> +}
>>>> +
>>>> +static int intel_mux_drcfg_probe(struct platform_device *pdev)
>>>> +{
>>>> + struct intel_usb_mux *mux;
>>>> + struct usb_mux_dev *umdev;
>>>> + struct device *dev = &pdev->dev;
>>>> + u64 start, size;
>>>> + int ret;
>>>> +
>>>> + mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
>>>> + if (!mux)
>>>> + return -ENOMEM;
>>>> +
>>>> + ret = device_property_read_u64(dev, "reg-start", &start);
>>>> + ret |= device_property_read_u64(dev, "reg-size", &size);
>>>> + if (ret)
>>>> + return -ENODEV;
>>> And you leaked memory :(
>> Did you mean device_property_read_*() allocated memory
>> and I need to release it before return error?
>>
>>>> +
>>>> + mux->regs = devm_ioremap_nocache(dev, start, size);
>>>> + if (!mux->regs)
>>>> + return -ENOMEM;
>>> Memory gone :(
>> devm interface will manage the resources by itself, or not?
> Ugh, you are right, nevermind, these both are fine, sorry for the noise.
>
>>>> + mux->cfg0_ctx = readl(mux->regs + INTEL_MUX_CFG0);
>>>> +
>>>> + umdev = &mux->umdev;
>>>> + umdev->dev = dev;
>>>> + umdev->cable_name = "USB-HOST";
>>>> + umdev->cable_set_cb = intel_mux_drcfg_cable_set;
>>>> + umdev->cable_unset_cb = intel_mux_drcfg_cable_unset;
>>>> +
>>>> + ret = usb_mux_register(umdev);
>>>> + if (ret)
>>>> + writel(mux->cfg0_ctx, mux->regs + INTEL_MUX_CFG0);
>>> So if an error happens you just keep going?
>> No. If error happens, I will restore the register and return error.
> That seems a bit "odd", and will change when you fix up the api...
Sure.
>
> thanks,
>
> greg k-h
>
Thank you for your time.
Best Regards,
baolu
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web