Re: [PATCH 5/6] DT bindings documentation for Broadcom IPROC USB Device controller.

2017-02-02 Thread Raviteja Garimella
Hi Rob,

On Wed, Feb 1, 2017 at 9:43 PM, Rob Herring <r...@kernel.org> wrote:
> On Mon, Jan 30, 2017 at 01:26:12PM +0530, Raviteja Garimella wrote:
>> The device node is used for UDCs integrated into Broadcom's
>> iProc family of SoCs'. The UDC is based on Synopsys Designware
>> Cores AHB Subsystem USB Device Controller IP.
>>
>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>> ---
>>  .../bindings/usb/brcm,iproc-snps-udc.txt   | 24 
>> ++
>>  1 file changed, 24 insertions(+)
>>  create mode 100644 
>> Documentation/devicetree/bindings/usb/brcm,iproc-snps-udc.txt
>>
>> diff --git a/Documentation/devicetree/bindings/usb/brcm,iproc-snps-udc.txt 
>> b/Documentation/devicetree/bindings/usb/brcm,iproc-snps-udc.txt
>> new file mode 100644
>> index 000..537dd4d
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/usb/brcm,iproc-snps-udc.txt
>> @@ -0,0 +1,24 @@
>> +Broadcom IPROC USB Device controller.
>> +
>> +The device node is used for UDCs integrated into Broadcom's
>> +iProc family of SoCs'. The UDC is based on Synopsys Designware
>> +Cores AHB Subsystem Device Controller.
>> +
>> +Required properties:
>> + - compatible: should be "brcm,iproc-snps-udc"
>
> Adding "snps" in here adds nothing really. Again, please use per SoC
> compatible strings.

Will do.

>
>> + - reg: Offset and length of UDC register set
>> + - interrupts: description of interrupt line
>> + - phys: phandle to phy node.
>> + - extcon: phandle to the extcon device. This is optional and
>> +   not required for those that don't require extcon support.
>> +   Extcon support will be required if the UDC is connected to
>> +   a Dual Role Device Phy that supports both Host and Device
>> +   mode based on the external cable.
>
> Drop this property.

Ok.

Thanks,
Ravi
>
>> +
>> +Example:
>> + udc_dwc: usb@664e {
>> + compatible = "brcm,iproc-snps-udc";
>> + reg = <0x664e 0x2000>;
>> + interrupts = ;
>> + phys = <_phy>;
>> + extcon = <_phy>";
>> --
>> 2.1.0
>>


Re: [RFC v2 1/5] UDC: Split the driver into amd (pci) and Synopsys core driver

2017-01-23 Thread Raviteja Garimella
Hi Florian,

On Fri, Jan 20, 2017 at 12:58 AM, Florian Fainelli <f.faine...@gmail.com> wrote:
> On 01/19/2017 02:44 AM, Raviteja Garimella wrote:
>> Hi,
>>
>> On Thu, Jan 19, 2017 at 12:15 AM, Florian Fainelli <f.faine...@gmail.com> 
>> wrote:
>>> On 01/17/2017 12:05 AM, Raviteja Garimella wrote:
>>>> This patch splits the amd5536udc driver into two -- one that does
>>>> pci device registration and the other file that does the rest of
>>>> the driver tasks like the gadget/ep ops etc for Synopsys UDC.
>>>>
>>>> This way of splitting helps in exporting core driver symbols which
>>>> can be used by any other platform/pci driver that is written for
>>>> the same Synopsys USB device controller.
>>>>
>>>> The current patch also includes a change in the Kconfig and Makefile.
>>>> A new config option USB_SNP_CORE will be selected automatically when
>>>> any one of the platform or pci driver for the same UDC is selected.
>>>>
>>>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>>>
>>> Although the changes you have done make sense and it is most certainly a
>>> good idea to split udc core from bus specific glue logic, it is really
>>> hard to review the changes per-se because of the file rename, could that
>>> happen at a later time?
>>
>> If you start looking at this specific patch from the header file 
>> (amd5536udc.h),
>> the additions in there comprise of:
>> - 9 function declarations
>> - some module parameter variable declarations that's moved out from the older
>>   common file amd5536udc.c
>> - 2 #includes that are needed by all files.
>
> Well, I don't really question the changes themselves, rather how this is
> presented as a patch series to reviewers.
>
> What I would do, to help introduce both the rename, and the splitting of
> core vs. bus-glue specific changes is:
>
> - have an initial patch which extracts the core functionality of the
> driver and the PCI bus glue logic into adm5536udc_pci.c and left
> adm5536udc.c intact (that would be a small delta to review)
>
> - have a second patch that performs the file rename from adm5536udc.c
> into snps_udc_core.c and updates adm5536udc_pci.c eventually as a result
> of that, then again, a reviewer can ignore the rename part (don't format
> to generate your patches with git format-patch -M in that case) and just
> focus on the conversion part for adm5536udc_pci.c
>

Just waited for any more comments coming in. I will submit the next version
as PATCH like the way you suggested.

>>
>> So, basically what's done for this split is that:
>> 1. the static keyword is removed from those 9 functions in the new file
>> snps_udc_core.c and are exported.
>> 2. The module parameters declarations (since they are used in both core
>> and pci file) are moved to the header file now.
>
> These should really be part of the commit messages for each commit doing
> the changes, this is meant to help a reviewer understand what you are
> doing, and to some degree, will help him/her make an educated decision
> as to what part of the code the focus should be put on.
>

Will do.

Thanks,
Ravi

> Thanks
> --
> Florian


[PATCH v3 2/3] Broadcom USB DRD Phy driver for Northstar2

2017-01-30 Thread Raviteja Garimella
This is driver for USB DRD Phy used in Broadcom's Northstar2
SoC. The phy can be configured to be in Device mode or Host
mode based on the type of cable connected to the port. The
driver registers to  extcon framework to get appropriate
connect events for Host/Device cables connect/disconnect
states based on VBUS and ID interrupts.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/phy/Kconfig  |  13 +
 drivers/phy/Makefile |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c | 576 +++
 3 files changed, 590 insertions(+)
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index e8eb7f2..1b3de42 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -463,6 +463,19 @@ config PHY_CYGNUS_PCIE
  Enable this to support the Broadcom Cygnus PCIe PHY.
  If unsure, say N.
 
+config PHY_NS2_USB_DRD
+   tristate "Broadcom Northstar2 USB DRD PHY support"
+   depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
+   select GENERIC_PHY
+   select EXTCON
+   default ARCH_BCM_IPROC
+   help
+ Enable this to support the Broadcom Northstar2 USB DRD PHY.
+ This driver initializes the PHY in either HOST or DEVICE mode.
+ The host or device configuration is read from device tree.
+
+ If unsure, say N.
+
 source "drivers/phy/tegra/Kconfig"
 
 config PHY_NS2_PCIE
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 65eb2f4..cfbdd9a 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -56,6 +56,7 @@ obj-$(CONFIG_PHY_TUSB1210)+= phy-tusb1210.o
 obj-$(CONFIG_PHY_BRCM_SATA)+= phy-brcm-sata.o
 obj-$(CONFIG_PHY_PISTACHIO_USB)+= phy-pistachio-usb.o
 obj-$(CONFIG_PHY_CYGNUS_PCIE)  += phy-bcm-cygnus-pcie.o
+obj-$(CONFIG_PHY_NS2_USB_DRD)  += phy-bcm-ns2-usbdrd.o
 obj-$(CONFIG_ARCH_TEGRA) += tegra/
 obj-$(CONFIG_PHY_NS2_PCIE) += phy-bcm-ns2-pcie.o
 obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o
diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c b/drivers/phy/phy-bcm-ns2-usbdrd.c
new file mode 100644
index 000..6436225
--- /dev/null
+++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
@@ -0,0 +1,576 @@
+/*
+ * Copyright (C) 2016 Broadcom
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ICFG_DRD_AFE   0x0
+#define ICFG_MISC_STAT 0x18
+#define ICFG_DRD_P0CTL 0x1C
+#define ICFG_STRAP_CTRL0x20
+#define ICFG_FSM_CTRL  0x24
+
+#define IDM_RST_BITBIT(0)
+#define AFE_CORERDY_VDDC   BIT(18)
+#define PHY_PLL_RESETB BIT(15)
+#define PHY_RESETB BIT(14)
+#define PHY_PLL_LOCK   BIT(0)
+
+#define DRD_DEV_MODE   BIT(20)
+#define OHCI_OVRCUR_POLBIT(11)
+#define ICFG_OFF_MODE  BIT(6)
+#define PLL_LOCK_RETRY 1000
+
+#define EVT_DEVICE 0
+#define EVT_HOST   1
+#define EVT_IDLE   2
+
+#define DRD_HOST_MODE  (BIT(2) | BIT(3))
+#define DRD_DEVICE_MODE(BIT(4) | BIT(5))
+#define DRD_HOST_VAL   0x803
+#define DRD_DEV_VAL0x807
+#define GPIO_DELAY 20
+#define PHY_WQ_DELAY   msecs_to_jiffies(600)
+
+struct ns2_phy_data;
+struct ns2_phy_driver {
+   void __iomem *icfgdrd_regs;
+   void __iomem *idmdrd_rst_ctrl;
+   void __iomem *crmu_usb2_ctrl;
+   void __iomem *usb2h_strap_reg;
+   spinlock_t lock; /* spin lock for phy driver */
+   bool host_mode;
+   struct ns2_phy_data *data;
+   struct extcon_specific_cable_nb extcon_dev;
+   struct extcon_specific_cable_nb extcon_host;
+   struct notifier_block host_nb;
+   struct notifier_block dev_nb;
+   struct delayed_work conn_work;
+   struct extcon_dev *edev;
+   struct gpio_desc *vbus_gpiod;
+   struct gpio_desc *id_gpiod;
+   int id_irq;
+   int vbus_irq;
+   unsigned long debounce_jiffies;
+   struct delayed_work wq_extcon;
+};
+
+struct ns2_phy_data {
+   struct ns2_phy_driver *driver;
+   struct phy *phy;
+   int new_state;
+};
+
+static const unsigned int usb_extcon_cable[] = {
+   EXTCON_USB,
+   EXTCON_USB_HOST,
+   EXTCON_NONE,
+};
+
+static inline

[PATCH v3 1/3] Add DT bindings documentation for NS2 USB DRD phy

2017-01-30 Thread Raviteja Garimella
This patch adds documentation for NS2 DRD Phy driver DT bindings

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
Acked-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   | 30 ++
 1 file changed, 30 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt

diff --git a/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt 
b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
new file mode 100644
index 000..04f063a
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
@@ -0,0 +1,30 @@
+BROADCOM NORTHSTAR2 USB2 (DUAL ROLE DEVICE) PHY
+
+Required properties:
+ - compatible: brcm,ns2-drd-phy
+ - reg: offset and length of the NS2 PHY related registers.
+ - reg-names
+   The below registers must be provided.
+   icfg - for DRD ICFG configurations
+   rst-ctrl - for DRD IDM reset
+   crmu-ctrl - for CRMU core vdd, PHY and PHY PLL reset
+   usb2-strap - for port over current polarity reversal
+ - #phy-cells: Must be 0. No args required.
+ - vbus-gpios: vbus gpio binding
+ - id-gpios: id gpio binding
+
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+Example:
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   };
-- 
2.1.0



[PATCH v3 0/3] Support for USB DRD Phy driver for NS2

2017-01-30 Thread Raviteja Garimella
Changes from v2:
===
Remove unnecessary checks for poweron as suggested in review.


Changes from v1:
===
1. Initialize file operations .owner field with THIS_MODULE.
2. Remove unnecessary gpio example in DT bindings documentation.
   This is previously acked by Rob Herring <r...@kernel.org>

Introduction:

This patch adds support for USB Dual Role Device Phy for Broadcom
Northstar2 SoC. Apart from the new phy driver, this patchset contains
changes to Kconfig, Makefile, and Device tree files.

This patchset is tested on Broadcom NS2 BCM958712K reference board.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: ns2_drdphy_v3

Raviteja Garimella (3):
  Add DT bindings documentation for NS2 USB DRD phy
  Broadcom USB DRD Phy driver for Northstar2
  DT nodes for Broadcom Northstar2 USB DRD Phy

 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   |  30 ++
 arch/arm64/boot/dts/broadcom/ns2.dtsi  |  14 +
 drivers/phy/Kconfig|  13 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c   | 576 +
 5 files changed, 634 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

-- 
2.1.0



[PATCH v3 3/3] DT nodes for Broadcom Northstar2 USB DRD Phy

2017-01-30 Thread Raviteja Garimella
This patch adds device tree nodes for USB Dual Role Device Phy for
Broadcom's Northstar2 SoC.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 arch/arm64/boot/dts/broadcom/ns2.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm64/boot/dts/broadcom/ns2.dtsi 
b/arch/arm64/boot/dts/broadcom/ns2.dtsi
index 4fcdeca..d9f701c 100644
--- a/arch/arm64/boot/dts/broadcom/ns2.dtsi
+++ b/arch/arm64/boot/dts/broadcom/ns2.dtsi
@@ -353,6 +353,20 @@
};
};
 
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   status = "disabled";
+   };
+
pwm: pwm@6601 {
compatible = "brcm,iproc-pwm";
reg = <0x6601 0x28>;
-- 
2.1.0



[PATCH 6/6] UDC: Add Synopsys UDC Platform driver

2017-01-29 Thread Raviteja Garimella
This patch adds platform driver support for Synopsys UDC.

A new driver file (snps_udc_plat.c) is created for this purpose
where the platform driver registration is done based on OF
node.

Currently, UDC integrated into Broadcom's iProc SoCs (Northstar2
and Cygnus) work with this driver.

New members are added to the UDC data structure for having platform
device support along with extcon and phy support.

Kconfig and Makefiles are modified to select platform driver for
compilation.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/Kconfig |  14 ++
 drivers/usb/gadget/udc/Makefile|   1 +
 drivers/usb/gadget/udc/amd5536udc.h|  14 ++
 drivers/usb/gadget/udc/snps_udc_core.c |  54 --
 drivers/usb/gadget/udc/snps_udc_plat.c | 342 +
 5 files changed, 406 insertions(+), 19 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/snps_udc_plat.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 9178dd2..ff62339 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -253,6 +253,20 @@ config USB_SNP_CORE
  This IP is different to the High Speed OTG IP that can be enabled
  by selecting USB_DWC2 or USB_DWC3 options.
 
+config USB_SNP_UDC_PLAT
+   tristate "Synopsys USB 2.0 Device controller"
+   select USB_SNP_CORE
+   select USB_GADGET_DUALSPEED
+   depends on (USB_GADGET && OF)
+   default ARCH_BCM_IPROC
+   help
+ This adds Platform Device support for Synopsys Designware core
+ AHB subsystem USB2.0 Device Controller (UDC).
+
+ This driver works with UDCs integrated into Broadcom's Northstar2
+ and Cygnus SoCs.
+
+ If unsure, say N.
 #
 # Controllers available in both integrated and discrete versions
 #
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 4f4fd62..ea9e1c7 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -37,4 +37,5 @@ obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
 obj-$(CONFIG_USB_MV_U3D)   += mv_u3d_core.o
 obj-$(CONFIG_USB_GR_UDC)   += gr_udc.o
 obj-$(CONFIG_USB_GADGET_XILINX)+= udc-xilinx.o
+obj-$(CONFIG_USB_SNP_UDC_PLAT) += snps_udc_plat.o
 obj-$(CONFIG_USB_BDC_UDC)  += bdc/
diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index c252457..7884281 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -16,6 +16,7 @@
 /* debug control */
 /* #define UDC_VERBOSE */
 
+#include 
 #include 
 #include 
 
@@ -28,6 +29,9 @@
 #define UDC_HSA0_REV 1
 #define UDC_HSB1_REV 2
 
+/* Broadcom chip rev. */
+#define UDC_BCM_REV 10
+
 /*
  * SETUP usb commands
  * needed, because some SETUP's are handled in hw, but must be passed to
@@ -112,6 +116,7 @@
 #define UDC_DEVCTL_BRLEN_MASK  0x00ff
 #define UDC_DEVCTL_BRLEN_OFS   16
 
+#define UDC_DEVCTL_SRX_FLUSH   14
 #define UDC_DEVCTL_CSR_DONE13
 #define UDC_DEVCTL_DEVNAK  12
 #define UDC_DEVCTL_SD  10
@@ -564,7 +569,15 @@ struct udc {
u16 cur_intf;
u16 cur_alt;
 
+   /* for platform device and extcon support */
struct device   *dev;
+   struct phy  *udc_phy;
+   struct extcon_dev   *edev;
+   struct extcon_specific_cable_nb extcon_nb;
+   struct notifier_block   nb;
+   struct delayed_work drd_work;
+   struct workqueue_struct *drd_wq;
+   u32 conn_type;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -580,6 +593,7 @@ int udc_enable_dev_setup_interrupts(struct udc *dev);
 int udc_mask_unused_interrupts(struct udc *dev);
 irqreturn_t udc_irq(int irq, void *pdev);
 void gadget_release(struct device *pdev);
+void empty_req_queue(struct udc_ep *ep);
 void udc_basic_init(struct udc *dev);
 void free_dma_pools(struct udc *dev);
 int init_dma_pools(struct udc *dev);
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 5f95a65..98de074 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -41,7 +41,6 @@
 #include "amd5536udc.h"
 
 static void udc_tasklet_disconnect(unsigned long);
-static void empty_req_queue(struct udc_ep *);
 static void udc_setup_endpoints(struct udc *dev);
 static void udc_soft_reset(struct udc *dev);
 static struct udc_request *udc_alloc_bna_dummy(struct udc_ep *ep);
@@ -1248,7 +1247,7 @@ udc_queue(struct usb_ep *usbep, struct usb_request 
*usbreq, gfp_t gfp)
 }
 
 /* Empty request queue of an endpoint; caller holds spinlock */
-static void empty_req_queue(struct

[PATCH 5/6] DT bindings documentation for Broadcom IPROC USB Device controller.

2017-01-29 Thread Raviteja Garimella
The device node is used for UDCs integrated into Broadcom's
iProc family of SoCs'. The UDC is based on Synopsys Designware
Cores AHB Subsystem USB Device Controller IP.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 .../bindings/usb/brcm,iproc-snps-udc.txt   | 24 ++
 1 file changed, 24 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/usb/brcm,iproc-snps-udc.txt

diff --git a/Documentation/devicetree/bindings/usb/brcm,iproc-snps-udc.txt 
b/Documentation/devicetree/bindings/usb/brcm,iproc-snps-udc.txt
new file mode 100644
index 000..537dd4d
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/brcm,iproc-snps-udc.txt
@@ -0,0 +1,24 @@
+Broadcom IPROC USB Device controller.
+
+The device node is used for UDCs integrated into Broadcom's
+iProc family of SoCs'. The UDC is based on Synopsys Designware
+Cores AHB Subsystem Device Controller.
+
+Required properties:
+ - compatible: should be "brcm,iproc-snps-udc"
+ - reg: Offset and length of UDC register set
+ - interrupts: description of interrupt line
+ - phys: phandle to phy node.
+ - extcon: phandle to the extcon device. This is optional and
+   not required for those that don't require extcon support.
+   Extcon support will be required if the UDC is connected to
+   a Dual Role Device Phy that supports both Host and Device
+   mode based on the external cable.
+
+Example:
+   udc_dwc: usb@664e {
+   compatible = "brcm,iproc-snps-udc";
+   reg = <0x664e 0x2000>;
+   interrupts = ;
+   phys = <_phy>;
+   extcon = <_phy>";
-- 
2.1.0



[PATCH 0/6] Platform driver support for 'amd5536udc' driver

2017-01-30 Thread Raviteja Garimella
The changes are being submitted as PATCH this time. Below are the
details of main changes with respect to previous RFC versions.

Changes from RFC v2:
===
Patch 1/6 now splits the driver into amd5536udc_pci_.c (which
contains only the PCI device registration part), and amd5536udc.c
will still be driver that does the rest of UDC driver functionality.

Patch 2/6 renames amd5536udc.c to snps_udc_core.c.

The DT compatibilty string is changed to "brcm,iproc-snps-udc"
as per review comments for RFCv2. The driver and bindings
documentation is modified to reflect this.



This is RFC for the changes made as per the review comments made for
the previous version. I would like to know  if this approach (the way
the driver is split and the naming and all)looks good to be submitted.


Changes from RFC v1:
===
1. Split the driver into platform/pci specific drivers with a core driver
   file that handles the common driver routines that are exported.

2. Split the driver into number of patches as suggested in previous
   review comments.

3. Added the devicetree bindings documentation for Synopsys platform
   driver.

Introduction from previous version:
===
This patch adds platform device support to the existing 'amd5536udc'
driver.

The UDC is based on Synopsys Designware core USB (2.0) Device controller
IP.

The driver so far supports UDCs that are a part of AMD southbridge
and is connected through PCI bus.

The same driver can be used with UDCs that are integrated into SoCs
like Broadcom's Northstar2/Cygnus platforms by adding platform device
suooprt.

This patch contains all the changes that were required to get the driver
functional on Broadcom's Northstar2 platform. 

This is a request for comments from maintainers/others regarding approach
on whether to have 2 different drivers (one each for AMD and Broadcom)
with a common library (3 files in total), or have a single driver like
it's done in this patch and have the driver filename changed to some
common name based on ther underlying IP, like snps_udc.c.

Below are the main changes done:

1. Added OF based platform device registration -- so that the driver gets
   probed based on the device tree entry. Like wise, remove routine and
   platform PM ops are supported.

2. Modified debug prints to be compatible with both pci and platform
   devices.

3. Added members to 'struct udc' in header file for extcon and phy support.
   This is required if the UDC is connected to a Dual Role Device Phy
   where the Phy can be configured to be in Device mode or Host mode based
   on the type of external cable that is connected to the port.
 
4. Added checks in udc connect/disconnect routines so as to return if the
   routine is already called.

5. Modified the arguments passed to dma_pool_create routine -- which
   expects struct device, whereas NULL is passed in the existing version.
 
6. Kconfig changes are done so that the driver now depends on either of
   CONFIG_OF or CONFIG_PCI. More description about the Synopsys IP is
   provided.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: snps_udc

Raviteja Garimella (6):
  UDC: Split the driver into amd (pci) and Synopsys core IP driver
  UDC: Rename amd5536udc driver file based on IP
  UDC: make debug prints compatible with both pci and platform devices
  UDC: Provide correct arguments for 'dma_pool_create'
  DT bindings documentation for Broadcom IPROC USB Device controller.
  UDC: Add Synopsys UDC Platform driver

 .../bindings/usb/brcm,iproc-snps-udc.txt   |   24 +
 drivers/usb/gadget/udc/Kconfig |   32 +
 drivers/usb/gadget/udc/Makefile|4 +-
 drivers/usb/gadget/udc/amd5536udc.c| 3413 
 drivers/usb/gadget/udc/amd5536udc.h|   54 +-
 drivers/usb/gadget/udc/amd5536udc_pci.c|  218 ++
 drivers/usb/gadget/udc/snps_udc_core.c | 3239 +++
 drivers/usb/gadget/udc/snps_udc_plat.c |  342 ++
 8 files changed, 3911 insertions(+), 3415 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/usb/brcm,iproc-snps-udc.txt
 delete mode 100644 drivers/usb/gadget/udc/amd5536udc.c
 create mode 100644 drivers/usb/gadget/udc/amd5536udc_pci.c
 create mode 100644 drivers/usb/gadget/udc/snps_udc_core.c
 create mode 100644 drivers/usb/gadget/udc/snps_udc_plat.c

-- 
2.1.0



[PATCH 1/6] UDC: Split the driver into amd (pci) and Synopsys core IP driver

2017-01-30 Thread Raviteja Garimella
This patch splits the amd5536udc driver into two -- one that does
pci device registration and the other file that does the rest of
the driver tasks like the gadget/ep ops etc for Synopsys UDC.

This way of splitting helps in exporting core driver symbols which
can be used by any other platform/pci driver that is written for
the same Synopsys USB device controller.

The current patch also includes a change in the Kconfig and Makefile.
A new config option USB_SNP_CORE will be selected automatically when
any one of the platform or pci driver for the same UDC is selected.

Main changes:
- amd5536udc_pci.c: PCI device registration is moved to this file.

- amd5536udc.c:
  This file does rest of the core UDC fucntionality.
  9 symbols are exported so as to be used by amd5536udc_pci.c.
  Module parameter definitions are moved to header file.

- amd5536udc.h:
  Function declarations, module parameters definitions and few common
  header file includes are added to this file

- Kconfig:
  New USB_SNP_CORE option is added which will be auto selected when
  any pci or platform driver config option for the UDC is chosen.

- Makefile:
  Compiles the core and pci files separately.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/Kconfig  |  18 +++
 drivers/usb/gadget/udc/Makefile |   3 +-
 drivers/usb/gadget/udc/amd5536udc.c | 238 
 drivers/usb/gadget/udc/amd5536udc.h |  36 +
 drivers/usb/gadget/udc/amd5536udc_pci.c | 217 +
 5 files changed, 297 insertions(+), 215 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/amd5536udc_pci.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 658b8da..9178dd2 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -239,6 +239,20 @@ config USB_MV_U3D
  MARVELL PXA2128 Processor series include a super speed USB3.0 device
  controller, which support super speed USB peripheral.
 
+config USB_SNP_CORE
+   depends on PCI
+   tristate
+   help
+ This enables core driver support for Synopsys USB 2.0 Device
+ controller.
+
+ This will be enabled when PCI or Platform driver for this UDC is
+ selected. Currently, this will be enabled by USB_SNP_UDC_PLAT or
+ USB_AMD5536UDC options.
+
+ This IP is different to the High Speed OTG IP that can be enabled
+ by selecting USB_DWC2 or USB_DWC3 options.
+
 #
 # Controllers available in both integrated and discrete versions
 #
@@ -263,6 +277,7 @@ source "drivers/usb/gadget/udc/bdc/Kconfig"
 
 config USB_AMD5536UDC
tristate "AMD5536 UDC"
+   select USB_SNP_CORE
depends on PCI
help
   The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge.
@@ -271,6 +286,9 @@ config USB_AMD5536UDC
   The UDC port supports OTG operation, and may be used as a host port
   if it's not being used to implement peripheral or OTG roles.
 
+  This UDC is based on Synopsys USB device controller IP and selects
+  CONFIG_USB_SNP_CORE option to build the core driver.
+
   Say "y" to link the driver statically, or "m" to build a
   dynamically linked module called "amd5536udc" and force all
   gadget drivers to also be dynamically linked.
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 98e74ed..626e1f1 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -10,7 +10,8 @@ obj-$(CONFIG_USB_GADGET)  += udc-core.o
 obj-$(CONFIG_USB_DUMMY_HCD)+= dummy_hcd.o
 obj-$(CONFIG_USB_NET2272)  += net2272.o
 obj-$(CONFIG_USB_NET2280)  += net2280.o
-obj-$(CONFIG_USB_AMD5536UDC)   += amd5536udc.o
+obj-$(CONFIG_USB_SNP_CORE) += amd5536udc.o
+obj-$(CONFIG_USB_AMD5536UDC)   += amd5536udc_pci.o
 obj-$(CONFIG_USB_PXA25X)   += pxa25x_udc.o
 obj-$(CONFIG_USB_PXA27X)   += pxa27x_udc.o
 obj-$(CONFIG_USB_GOKU) += goku_udc.o
diff --git a/drivers/usb/gadget/udc/amd5536udc.c 
b/drivers/usb/gadget/udc/amd5536udc.c
index ea03ca7..72f3c8f 100644
--- a/drivers/usb/gadget/udc/amd5536udc.c
+++ b/drivers/usb/gadget/udc/amd5536udc.c
@@ -11,27 +11,15 @@
  */
 
 /*
- * The AMD5536 UDC is part of the x86 southbridge AMD Geode CS5536.
- * It is a USB Highspeed DMA capable USB device controller. Beside ep0 it
- * provides 4 IN and 4 OUT endpoints (bulk or interrupt type).
- *
- * Make sure that UDC is assigned to port 4 by BIOS settings (port can also
- * be used as host port) and UOC bits PAD_EN and APU are set (should be done
- * by BIOS init).
- *
- * UDC DMA requires 32-bit aligned buffers so DMA with gadget ether does not
- * work without updating NET_IP_ALIGN. Or PIO mode (module param "use_dma=0")
- * can be used with gadget ether.
+ * This file does the core driv

[PATCH 3/6] UDC: make debug prints compatible with both pci and platform devices

2017-01-30 Thread Raviteja Garimella
This patch adds a struct device member to UDC data structure and
makes changes to the arguments of dev_err and dev_dbg calls so that
the debug prints work for both pci and platform devices.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/amd5536udc.h |  4 +++-
 drivers/usb/gadget/udc/amd5536udc_pci.c |  1 +
 drivers/usb/gadget/udc/snps_udc_core.c  | 28 ++--
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index bd2a18e..c252457 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -563,6 +563,8 @@ struct udc {
u16 cur_config;
u16 cur_intf;
u16 cur_alt;
+
+   struct device   *dev;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -639,7 +641,7 @@ MODULE_PARM_DESC(use_fullspeed, "true for fullspeed only");
 
 /* debug macros */
 
-#define DBG(udc , args...) dev_dbg(&(udc)->pdev->dev, args)
+#define DBG(udc , args...) dev_dbg(udc->dev, args)
 
 #ifdef UDC_VERBOSE
 #define VDBG   DBG
diff --git a/drivers/usb/gadget/udc/amd5536udc_pci.c 
b/drivers/usb/gadget/udc/amd5536udc_pci.c
index 2a2d0a9..57a13f0 100644
--- a/drivers/usb/gadget/udc/amd5536udc_pci.c
+++ b/drivers/usb/gadget/udc/amd5536udc_pci.c
@@ -168,6 +168,7 @@ static int udc_pci_probe(
dev->phys_addr = resource;
dev->irq = pdev->irq;
dev->pdev = pdev;
+   dev->dev = >dev;
 
/* general probing */
if (udc_probe(dev)) {
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 72f3c8f..c778d51 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -209,18 +209,18 @@ static void print_regs(struct udc *dev)
if (use_dma && use_dma_ppb && !use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBNDU (packet per buffer "
"WITHOUT desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBNDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBNDU");
} else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBDU (packet per buffer "
"WITH desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBDU");
}
if (use_dma && use_dma_bufferfill_mode) {
DBG(dev, "DMA mode   = BF (buffer fill mode)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "BF");
+   dev_info(dev->dev, "DMA mode (%s)\n", "BF");
}
if (!use_dma)
-   dev_info(>pdev->dev, "FIFO mode\n");
+   dev_info(dev->dev, "FIFO mode\n");
DBG(dev, "---\n");
 }
 
@@ -1628,7 +1628,7 @@ static void udc_setup_endpoints(struct udc *dev)
 static void usb_connect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Connect\n");
+   dev_info(dev->dev, "USB Connect\n");
 
dev->connected = 1;
 
@@ -1646,7 +1646,7 @@ static void usb_connect(struct udc *dev)
 static void usb_disconnect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Disconnect\n");
+   dev_info(dev->dev, "USB Disconnect\n");
 
dev->connected = 0;
 
@@ -2110,7 +2110,7 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int 
ep_ix)
}
/* HE event ? */
if (tmp & AMD_BIT(UDC_EPSTS_HE)) {
-   dev_err(>pdev->dev, "HE ep%dout occurred\n", ep->num);
+   dev_err(dev->dev, "HE ep%dout occurred\n", ep->num);
 
/* clear HE */
writel(tmp | AMD_BIT(UDC_EPSTS_HE), >regs->sts);
@@ -2309,7 +2309,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int 
ep_ix)
if (use_dma) {
/* BNA ? */
if (epsts & AMD_BIT(UDC_EPSTS_BNA)) {
-   dev_err(>pdev->dev,
+   dev_err(dev->dev,
"BNA ep%din occurred - DESPTR = %08lx\n",
ep->num,
(unsigned long) readl(>regs->desptr

[PATCH 4/6] UDC: Provide correct arguments for 'dma_pool_create'

2017-01-30 Thread Raviteja Garimella
Change the argument from NULL to a struct device for the
dma_pool_create call during dma init.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/snps_udc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index c778d51..5f95a65 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -3101,7 +3101,7 @@ int init_dma_pools(struct udc *dev)
}
 
/* DMA setup */
-   dev->data_requests = dma_pool_create("data_requests", NULL,
+   dev->data_requests = dma_pool_create("data_requests", dev->dev,
sizeof(struct udc_data_dma), 0, 0);
if (!dev->data_requests) {
DBG(dev, "can't get request data pool\n");
@@ -3112,7 +3112,7 @@ int init_dma_pools(struct udc *dev)
dev->ep[UDC_EP0IN_IX].dma = >regs->ctl;
 
/* dma desc for setup data */
-   dev->stp_requests = dma_pool_create("setup requests", NULL,
+   dev->stp_requests = dma_pool_create("setup requests", dev->dev,
sizeof(struct udc_stp_dma), 0, 0);
if (!dev->stp_requests) {
DBG(dev, "can't get stp request pool\n");
-- 
2.1.0



Re: [PATCH v2 2/3] Broadcom USB DRD Phy driver for Northstar2

2017-01-27 Thread Raviteja Garimella
Hi Kishon,

On Thu, Jan 26, 2017 at 9:13 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
> Hi,
>
> On Wednesday 18 January 2017 05:50 PM, Raviteja Garimella wrote:
>> This is driver for USB DRD Phy used in Broadcom's Northstar2
>> SoC. The phy can be configured to be in Device mode or Host
>> mode based on the type of cable connected to the port. The
>> driver registers to  extcon framework to get appropriate
>> connect events for Host/Device cables connect/disconnect
>> states based on VBUS and ID interrupts.
>>
>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>> ---
>>  drivers/phy/Kconfig  |  13 +
>>  drivers/phy/Makefile |   1 +
>>  drivers/phy/phy-bcm-ns2-usbdrd.c | 588 
>> +++
>>  3 files changed, 602 insertions(+)
>>  create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c
>>
>> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
>> index e8eb7f2..1b3de42 100644
>> --- a/drivers/phy/Kconfig
>> +++ b/drivers/phy/Kconfig
>> @@ -463,6 +463,19 @@ config PHY_CYGNUS_PCIE
>> Enable this to support the Broadcom Cygnus PCIe PHY.
>> If unsure, say N.
>>
>> +config PHY_NS2_USB_DRD
>> + tristate "Broadcom Northstar2 USB DRD PHY support"
>> + depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
>> + select GENERIC_PHY
>> + select EXTCON
>> + default ARCH_BCM_IPROC
>> + help
>> +   Enable this to support the Broadcom Northstar2 USB DRD PHY.
>> +   This driver initializes the PHY in either HOST or DEVICE mode.
>> +   The host or device configuration is read from device tree.
>> +
>> +   If unsure, say N.
>> +
>>  source "drivers/phy/tegra/Kconfig"
>>
>>  config PHY_NS2_PCIE
>> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
>> index 65eb2f4..cfbdd9a 100644
>> --- a/drivers/phy/Makefile
>> +++ b/drivers/phy/Makefile
>> @@ -56,6 +56,7 @@ obj-$(CONFIG_PHY_TUSB1210)  += phy-tusb1210.o
>>  obj-$(CONFIG_PHY_BRCM_SATA)  += phy-brcm-sata.o
>>  obj-$(CONFIG_PHY_PISTACHIO_USB)  += phy-pistachio-usb.o
>>  obj-$(CONFIG_PHY_CYGNUS_PCIE)+= phy-bcm-cygnus-pcie.o
>> +obj-$(CONFIG_PHY_NS2_USB_DRD)+= phy-bcm-ns2-usbdrd.o
>>  obj-$(CONFIG_ARCH_TEGRA) += tegra/
>>  obj-$(CONFIG_PHY_NS2_PCIE)   += phy-bcm-ns2-pcie.o
>>  obj-$(CONFIG_PHY_MESON8B_USB2)   += phy-meson8b-usb2.o
>> diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c 
>> b/drivers/phy/phy-bcm-ns2-usbdrd.c
>> new file mode 100644
>> index 000..e9478d1
>> --- /dev/null
>> +++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
>> @@ -0,0 +1,588 @@
>> +/*
>> + * Copyright (C) 2016 Broadcom
>> + *
>> + * 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 version 2.
>> + *
>> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
>> + * kind, whether express or implied; without even the implied warranty
>> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define ICFG_DRD_AFE 0x0
>> +#define ICFG_MISC_STAT   0x18
>> +#define ICFG_DRD_P0CTL   0x1C
>> +#define ICFG_STRAP_CTRL  0x20
>> +#define ICFG_FSM_CTRL0x24
>> +
>> +#define IDM_RST_BIT  BIT(0)
>> +#define AFE_CORERDY_VDDC BIT(18)
>> +#define PHY_PLL_RESETB   BIT(15)
>> +#define PHY_RESETB   BIT(14)
>> +#define PHY_PLL_LOCK BIT(0)
>> +
>> +#define DRD_DEV_MODE BIT(20)
>> +#define OHCI_OVRCUR_POL  BIT(11)
>> +#define ICFG_OFF_MODEBIT(6)
>> +#define PLL_LOCK_RETRY   1000
>> +
>> +#define EVT_DEVICE   0
>> +#define EVT_HOST 1
>> +#define EVT_IDLE 2
>> +
>> +#define DRD_HOST_MODE(BIT(2) | BIT(3))
>> +#define DRD_DEVICE_MODE  (BIT(4

[PATCH v2 6/6] UDC: Add Synopsys UDC Platform driver

2017-02-21 Thread Raviteja Garimella
This patch adds platform driver support for Synopsys UDC.

A new driver file (snps_udc_plat.c) is created for this purpose
where the platform driver registration is done based on OF
node.

Currently, UDC integrated into Broadcom's iProc SoCs (Northstar2
and Cygnus) work with this driver.

New members are added to the UDC data structure for having platform
device support along with extcon and phy support.

Kconfig and Makefiles are modified to select platform driver for
compilation.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/Kconfig |  16 +-
 drivers/usb/gadget/udc/Makefile|   1 +
 drivers/usb/gadget/udc/amd5536udc.h|  14 ++
 drivers/usb/gadget/udc/snps_udc_core.c |  54 --
 drivers/usb/gadget/udc/snps_udc_plat.c | 343 +
 5 files changed, 408 insertions(+), 20 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/snps_udc_plat.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 72e6234..5bc3305 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -240,7 +240,7 @@ config USB_MV_U3D
  controller, which support super speed USB peripheral.
 
 config USB_SNP_CORE
-   depends on USB_AMD5536UDC
+   depends on (USB_SNP_UDC_PLAT || USB_AMD5536UDC)
depends on PCI
tristate
help
@@ -254,6 +254,20 @@ config USB_SNP_CORE
  This IP is different to the High Speed OTG IP that can be enabled
  by selecting USB_DWC2 or USB_DWC3 options.
 
+config USB_SNP_UDC_PLAT
+   tristate "Synopsys USB 2.0 Device controller"
+   depends on (USB_GADGET && OF)
+   select USB_GADGET_DUALSPEED
+   select USB_SNP_CORE
+   default ARCH_BCM_IPROC
+   help
+ This adds Platform Device support for Synopsys Designware core
+ AHB subsystem USB2.0 Device Controller (UDC).
+
+ This driver works with UDCs integrated into Broadcom's Northstar2
+ and Cygnus SoCs.
+
+ If unsure, say N.
 #
 # Controllers available in both integrated and discrete versions
 #
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 4f4fd62..ea9e1c7 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -37,4 +37,5 @@ obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
 obj-$(CONFIG_USB_MV_U3D)   += mv_u3d_core.o
 obj-$(CONFIG_USB_GR_UDC)   += gr_udc.o
 obj-$(CONFIG_USB_GADGET_XILINX)+= udc-xilinx.o
+obj-$(CONFIG_USB_SNP_UDC_PLAT) += snps_udc_plat.o
 obj-$(CONFIG_USB_BDC_UDC)  += bdc/
diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index c252457..7884281 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -16,6 +16,7 @@
 /* debug control */
 /* #define UDC_VERBOSE */
 
+#include 
 #include 
 #include 
 
@@ -28,6 +29,9 @@
 #define UDC_HSA0_REV 1
 #define UDC_HSB1_REV 2
 
+/* Broadcom chip rev. */
+#define UDC_BCM_REV 10
+
 /*
  * SETUP usb commands
  * needed, because some SETUP's are handled in hw, but must be passed to
@@ -112,6 +116,7 @@
 #define UDC_DEVCTL_BRLEN_MASK  0x00ff
 #define UDC_DEVCTL_BRLEN_OFS   16
 
+#define UDC_DEVCTL_SRX_FLUSH   14
 #define UDC_DEVCTL_CSR_DONE13
 #define UDC_DEVCTL_DEVNAK  12
 #define UDC_DEVCTL_SD  10
@@ -564,7 +569,15 @@ struct udc {
u16 cur_intf;
u16 cur_alt;
 
+   /* for platform device and extcon support */
struct device   *dev;
+   struct phy  *udc_phy;
+   struct extcon_dev   *edev;
+   struct extcon_specific_cable_nb extcon_nb;
+   struct notifier_block   nb;
+   struct delayed_work drd_work;
+   struct workqueue_struct *drd_wq;
+   u32 conn_type;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -580,6 +593,7 @@ int udc_enable_dev_setup_interrupts(struct udc *dev);
 int udc_mask_unused_interrupts(struct udc *dev);
 irqreturn_t udc_irq(int irq, void *pdev);
 void gadget_release(struct device *pdev);
+void empty_req_queue(struct udc_ep *ep);
 void udc_basic_init(struct udc *dev);
 void free_dma_pools(struct udc *dev);
 int init_dma_pools(struct udc *dev);
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 5f95a65..98de074 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -41,7 +41,6 @@
 #include "amd5536udc.h"
 
 static void udc_tasklet_disconnect(unsigned long);
-static void empty_req_queue(struct udc_ep *);
 static void udc_setup_endpoints(struct udc *dev);
 static void udc_soft_reset(struct udc

[PATCH v2 5/6] DT bindings documentation for Broadcom IPROC USB Device controller.

2017-02-21 Thread Raviteja Garimella
The device node is used for UDCs integrated into Broadcom's
iProc family of SoCs'. The UDC is based on Synopsys Designware
Cores AHB Subsystem USB Device Controller IP.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 Documentation/devicetree/bindings/usb/iproc-udc.txt | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/iproc-udc.txt

diff --git a/Documentation/devicetree/bindings/usb/iproc-udc.txt 
b/Documentation/devicetree/bindings/usb/iproc-udc.txt
new file mode 100644
index 000..c2ce803
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/iproc-udc.txt
@@ -0,0 +1,21 @@
+Broadcom IPROC USB Device controller.
+
+The device node is used for UDCs integrated into Broadcom's
+iProc family (Northstar2, Cygnus) of SoCs'. The UDC is based
+on Synopsys Designware Cores AHB Subsystem Device Controller
+IP.
+
+Required properties:
+ - compatible: Add the compatibility strings for supported platforms.
+   For Broadcom NS2 platform, add "brcm,ns2-udc".
+   For Broadcom Cygnus platform, add "brcm,cygnus-udc".
+ - reg: Offset and length of UDC register set
+ - interrupts: description of interrupt line
+ - phys: phandle to phy node.
+
+Example:
+   udc_dwc: usb@664e {
+   compatible = "brcm,ns2-udc", "brcm,cygnus-udc";
+   reg = <0x664e 0x2000>;
+   interrupts = ;
+   phys = <_phy>;
-- 
2.1.0



[PATCH v2 1/6] UDC: Split the driver into amd (pci) and Synopsys core IP driver

2017-02-21 Thread Raviteja Garimella
This patch splits the amd5536udc driver into two -- one that does
pci device registration and the other file that does the rest of
the driver tasks like the gadget/ep ops etc for Synopsys UDC.

This way of splitting helps in exporting core driver symbols which
can be used by any other platform/pci driver that is written for
the same Synopsys USB device controller.

The current patch also includes a change in the Kconfig and Makefile.
A new config option USB_SNP_CORE will be selected automatically when
any one of the platform or pci driver for the same UDC is selected.

Main changes:
- amd5536udc_pci.c: PCI device registration is moved to this file.

- amd5536udc.c:
  This file does rest of the core UDC fucntionality.
  9 symbols are exported so as to be used by amd5536udc_pci.c.
  Module parameter definitions are moved to header file.

- amd5536udc.h:
  Function declarations, module parameters definitions and few common
  header file includes are added to this file

- Kconfig:
  New USB_SNP_CORE option is added which will be auto selected when
  any pci or platform driver config option for the UDC is chosen.

- Makefile:
  Compiles the core and pci files separately.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/Kconfig  |  19 +++
 drivers/usb/gadget/udc/Makefile |   3 +-
 drivers/usb/gadget/udc/amd5536udc.c | 238 
 drivers/usb/gadget/udc/amd5536udc.h |  36 +
 drivers/usb/gadget/udc/amd5536udc_pci.c | 217 +
 5 files changed, 298 insertions(+), 215 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/amd5536udc_pci.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 658b8da..72e6234 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -239,6 +239,21 @@ config USB_MV_U3D
  MARVELL PXA2128 Processor series include a super speed USB3.0 device
  controller, which support super speed USB peripheral.
 
+config USB_SNP_CORE
+   depends on USB_AMD5536UDC
+   depends on PCI
+   tristate
+   help
+ This enables core driver support for Synopsys USB 2.0 Device
+ controller.
+
+ This will be enabled when PCI or Platform driver for this UDC is
+ selected. Currently, this will be enabled by USB_SNP_UDC_PLAT or
+ USB_AMD5536UDC options.
+
+ This IP is different to the High Speed OTG IP that can be enabled
+ by selecting USB_DWC2 or USB_DWC3 options.
+
 #
 # Controllers available in both integrated and discrete versions
 #
@@ -264,6 +279,7 @@ source "drivers/usb/gadget/udc/bdc/Kconfig"
 config USB_AMD5536UDC
tristate "AMD5536 UDC"
depends on PCI
+   select USB_SNP_CORE
help
   The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge.
   It is a USB Highspeed DMA capable USB device controller. Beside ep0
@@ -271,6 +287,9 @@ config USB_AMD5536UDC
   The UDC port supports OTG operation, and may be used as a host port
   if it's not being used to implement peripheral or OTG roles.
 
+  This UDC is based on Synopsys USB device controller IP and selects
+  CONFIG_USB_SNP_CORE option to build the core driver.
+
   Say "y" to link the driver statically, or "m" to build a
   dynamically linked module called "amd5536udc" and force all
   gadget drivers to also be dynamically linked.
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 98e74ed..626e1f1 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -10,7 +10,8 @@ obj-$(CONFIG_USB_GADGET)  += udc-core.o
 obj-$(CONFIG_USB_DUMMY_HCD)+= dummy_hcd.o
 obj-$(CONFIG_USB_NET2272)  += net2272.o
 obj-$(CONFIG_USB_NET2280)  += net2280.o
-obj-$(CONFIG_USB_AMD5536UDC)   += amd5536udc.o
+obj-$(CONFIG_USB_SNP_CORE) += amd5536udc.o
+obj-$(CONFIG_USB_AMD5536UDC)   += amd5536udc_pci.o
 obj-$(CONFIG_USB_PXA25X)   += pxa25x_udc.o
 obj-$(CONFIG_USB_PXA27X)   += pxa27x_udc.o
 obj-$(CONFIG_USB_GOKU) += goku_udc.o
diff --git a/drivers/usb/gadget/udc/amd5536udc.c 
b/drivers/usb/gadget/udc/amd5536udc.c
index ea03ca7..72f3c8f 100644
--- a/drivers/usb/gadget/udc/amd5536udc.c
+++ b/drivers/usb/gadget/udc/amd5536udc.c
@@ -11,27 +11,15 @@
  */
 
 /*
- * The AMD5536 UDC is part of the x86 southbridge AMD Geode CS5536.
- * It is a USB Highspeed DMA capable USB device controller. Beside ep0 it
- * provides 4 IN and 4 OUT endpoints (bulk or interrupt type).
- *
- * Make sure that UDC is assigned to port 4 by BIOS settings (port can also
- * be used as host port) and UOC bits PAD_EN and APU are set (should be done
- * by BIOS init).
- *
- * UDC DMA requires 32-bit aligned buffers so DMA with gadget ether does not
- * work without updating NET_IP_ALIGN. Or PIO mod

[PATCH v2 0/6] Platform driver support for 'amd5536udc' driver

2017-02-21 Thread Raviteja Garimella
Changes from PATCH v1:
==
1. Updated bindings documentation:
   -- compatibility string for each supported SoC
   -- removed extcon node
   -- rename the file name to just iproc-udc.txt

2. Modified comptability strings in platform driver file
   to reflect the change made in 1.

3 Kconfig
   -- Resolved warnings shown by kbuild-test-robot  



The changes are being submitted as PATCH this time. Below are the
details of main changes with respect to previous RFC versions.

Changes from RFC v2:
===
Patch 1/6 now splits the driver into amd5536udc_pci_.c (which
contains only the PCI device registration part), and amd5536udc.c
will still be driver that does the rest of UDC driver functionality.

Patch 2/6 renames amd5536udc.c to snps_udc_core.c.

The DT compatibilty string is changed to "brcm,iproc-snps-udc"
as per review comments for RFCv2. The driver and bindings
documentation is modified to reflect this.

This is RFC for the changes made as per the review comments made for
the previous version. I would like to know  if this approach (the way
the driver is split and the naming and all)looks good to be submitted.


Changes from RFC v1:
===
1. Split the driver into platform/pci specific drivers with a core driver
   file that handles the common driver routines that are exported.

2. Split the driver into number of patches as suggested in previous
   review comments.

3. Added the devicetree bindings documentation for Synopsys platform
   driver.

Introduction from previous version:
===
This patch adds platform device support to the existing 'amd5536udc'
driver.

The UDC is based on Synopsys Designware core USB (2.0) Device controller
IP.

The driver so far supports UDCs that are a part of AMD southbridge
and is connected through PCI bus.

The same driver can be used with UDCs that are integrated into SoCs
like Broadcom's Northstar2/Cygnus platforms by adding platform device
suooprt.

This patch contains all the changes that were required to get the driver
functional on Broadcom's Northstar2 platform. 

This is a request for comments from maintainers/others regarding approach
on whether to have 2 different drivers (one each for AMD and Broadcom)
with a common library (3 files in total), or have a single driver like
it's done in this patch and have the driver filename changed to some
common name based on ther underlying IP, like snps_udc.c.

Below are the main changes done:

1. Added OF based platform device registration -- so that the driver gets
   probed based on the device tree entry. Like wise, remove routine and
   platform PM ops are supported.

2. Modified debug prints to be compatible with both pci and platform
   devices.

3. Added members to 'struct udc' in header file for extcon and phy support.
   This is required if the UDC is connected to a Dual Role Device Phy
   where the Phy can be configured to be in Device mode or Host mode based
   on the type of external cable that is connected to the port.
 
4. Added checks in udc connect/disconnect routines so as to return if the
   routine is already called.

5. Modified the arguments passed to dma_pool_create routine -- which
   expects struct device, whereas NULL is passed in the existing version.
 
6. Kconfig changes are done so that the driver now depends on either of
   CONFIG_OF or CONFIG_PCI. More description about the Synopsys IP is
   provided.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: snps_udc_v2

Raviteja Garimella (6):
  UDC: Split the driver into amd (pci) and Synopsys core IP driver
  UDC: Rename amd5536udc driver file based on IP
  UDC: make debug prints compatible with both pci and platform devices
  UDC: Provide correct arguments for 'dma_pool_create'
  DT bindings documentation for Broadcom IPROC USB Device controller.
  UDC: Add Synopsys UDC Platform driver

 .../devicetree/bindings/usb/iproc-udc.txt  |   21 +
 drivers/usb/gadget/udc/Kconfig |   33 +
 drivers/usb/gadget/udc/Makefile|4 +-
 drivers/usb/gadget/udc/amd5536udc.c| 3413 
 drivers/usb/gadget/udc/amd5536udc.h|   54 +-
 drivers/usb/gadget/udc/amd5536udc_pci.c|  218 ++
 drivers/usb/gadget/udc/snps_udc_core.c | 3239 +++
 drivers/usb/gadget/udc/snps_udc_plat.c |  343 ++
 8 files changed, 3910 insertions(+), 3415 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/iproc-udc.txt
 delete mode 100644 drivers/usb/gadget/udc/amd5536udc.c
 create mode 100644 drivers/usb/gadget/udc/amd5536udc_pci.c
 create mode 100644 drivers/usb/gadget/udc/snps_udc_core.c
 create mode 100644 drivers/usb/gadget/udc/snps_udc_plat.c

-- 
2.1.0



[PATCH v2 3/6] UDC: make debug prints compatible with both pci and platform devices

2017-02-21 Thread Raviteja Garimella
This patch adds a struct device member to UDC data structure and
makes changes to the arguments of dev_err and dev_dbg calls so that
the debug prints work for both pci and platform devices.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/amd5536udc.h |  4 +++-
 drivers/usb/gadget/udc/amd5536udc_pci.c |  1 +
 drivers/usb/gadget/udc/snps_udc_core.c  | 28 ++--
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index bd2a18e..c252457 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -563,6 +563,8 @@ struct udc {
u16 cur_config;
u16 cur_intf;
u16 cur_alt;
+
+   struct device   *dev;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -639,7 +641,7 @@ MODULE_PARM_DESC(use_fullspeed, "true for fullspeed only");
 
 /* debug macros */
 
-#define DBG(udc , args...) dev_dbg(&(udc)->pdev->dev, args)
+#define DBG(udc , args...) dev_dbg(udc->dev, args)
 
 #ifdef UDC_VERBOSE
 #define VDBG   DBG
diff --git a/drivers/usb/gadget/udc/amd5536udc_pci.c 
b/drivers/usb/gadget/udc/amd5536udc_pci.c
index 2a2d0a9..57a13f0 100644
--- a/drivers/usb/gadget/udc/amd5536udc_pci.c
+++ b/drivers/usb/gadget/udc/amd5536udc_pci.c
@@ -168,6 +168,7 @@ static int udc_pci_probe(
dev->phys_addr = resource;
dev->irq = pdev->irq;
dev->pdev = pdev;
+   dev->dev = >dev;
 
/* general probing */
if (udc_probe(dev)) {
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 72f3c8f..c778d51 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -209,18 +209,18 @@ static void print_regs(struct udc *dev)
if (use_dma && use_dma_ppb && !use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBNDU (packet per buffer "
"WITHOUT desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBNDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBNDU");
} else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBDU (packet per buffer "
"WITH desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBDU");
}
if (use_dma && use_dma_bufferfill_mode) {
DBG(dev, "DMA mode   = BF (buffer fill mode)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "BF");
+   dev_info(dev->dev, "DMA mode (%s)\n", "BF");
}
if (!use_dma)
-   dev_info(>pdev->dev, "FIFO mode\n");
+   dev_info(dev->dev, "FIFO mode\n");
DBG(dev, "---\n");
 }
 
@@ -1628,7 +1628,7 @@ static void udc_setup_endpoints(struct udc *dev)
 static void usb_connect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Connect\n");
+   dev_info(dev->dev, "USB Connect\n");
 
dev->connected = 1;
 
@@ -1646,7 +1646,7 @@ static void usb_connect(struct udc *dev)
 static void usb_disconnect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Disconnect\n");
+   dev_info(dev->dev, "USB Disconnect\n");
 
dev->connected = 0;
 
@@ -2110,7 +2110,7 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int 
ep_ix)
}
/* HE event ? */
if (tmp & AMD_BIT(UDC_EPSTS_HE)) {
-   dev_err(>pdev->dev, "HE ep%dout occurred\n", ep->num);
+   dev_err(dev->dev, "HE ep%dout occurred\n", ep->num);
 
/* clear HE */
writel(tmp | AMD_BIT(UDC_EPSTS_HE), >regs->sts);
@@ -2309,7 +2309,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int 
ep_ix)
if (use_dma) {
/* BNA ? */
if (epsts & AMD_BIT(UDC_EPSTS_BNA)) {
-   dev_err(>pdev->dev,
+   dev_err(dev->dev,
"BNA ep%din occurred - DESPTR = %08lx\n",
ep->num,
(unsigned long) readl(>regs->desptr

[PATCH v2 4/6] UDC: Provide correct arguments for 'dma_pool_create'

2017-02-21 Thread Raviteja Garimella
Change the argument from NULL to a struct device for the
dma_pool_create call during dma init.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/snps_udc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index c778d51..5f95a65 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -3101,7 +3101,7 @@ int init_dma_pools(struct udc *dev)
}
 
/* DMA setup */
-   dev->data_requests = dma_pool_create("data_requests", NULL,
+   dev->data_requests = dma_pool_create("data_requests", dev->dev,
sizeof(struct udc_data_dma), 0, 0);
if (!dev->data_requests) {
DBG(dev, "can't get request data pool\n");
@@ -3112,7 +3112,7 @@ int init_dma_pools(struct udc *dev)
dev->ep[UDC_EP0IN_IX].dma = >regs->ctl;
 
/* dma desc for setup data */
-   dev->stp_requests = dma_pool_create("setup requests", NULL,
+   dev->stp_requests = dma_pool_create("setup requests", dev->dev,
sizeof(struct udc_stp_dma), 0, 0);
if (!dev->stp_requests) {
DBG(dev, "can't get stp request pool\n");
-- 
2.1.0



[PATCH v2 2/3] Broadcom USB DRD Phy driver for Northstar2

2017-01-18 Thread Raviteja Garimella
This is driver for USB DRD Phy used in Broadcom's Northstar2
SoC. The phy can be configured to be in Device mode or Host
mode based on the type of cable connected to the port. The
driver registers to  extcon framework to get appropriate
connect events for Host/Device cables connect/disconnect
states based on VBUS and ID interrupts.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/phy/Kconfig  |  13 +
 drivers/phy/Makefile |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c | 588 +++
 3 files changed, 602 insertions(+)
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index e8eb7f2..1b3de42 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -463,6 +463,19 @@ config PHY_CYGNUS_PCIE
  Enable this to support the Broadcom Cygnus PCIe PHY.
  If unsure, say N.
 
+config PHY_NS2_USB_DRD
+   tristate "Broadcom Northstar2 USB DRD PHY support"
+   depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
+   select GENERIC_PHY
+   select EXTCON
+   default ARCH_BCM_IPROC
+   help
+ Enable this to support the Broadcom Northstar2 USB DRD PHY.
+ This driver initializes the PHY in either HOST or DEVICE mode.
+ The host or device configuration is read from device tree.
+
+ If unsure, say N.
+
 source "drivers/phy/tegra/Kconfig"
 
 config PHY_NS2_PCIE
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 65eb2f4..cfbdd9a 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -56,6 +56,7 @@ obj-$(CONFIG_PHY_TUSB1210)+= phy-tusb1210.o
 obj-$(CONFIG_PHY_BRCM_SATA)+= phy-brcm-sata.o
 obj-$(CONFIG_PHY_PISTACHIO_USB)+= phy-pistachio-usb.o
 obj-$(CONFIG_PHY_CYGNUS_PCIE)  += phy-bcm-cygnus-pcie.o
+obj-$(CONFIG_PHY_NS2_USB_DRD)  += phy-bcm-ns2-usbdrd.o
 obj-$(CONFIG_ARCH_TEGRA) += tegra/
 obj-$(CONFIG_PHY_NS2_PCIE) += phy-bcm-ns2-pcie.o
 obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o
diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c b/drivers/phy/phy-bcm-ns2-usbdrd.c
new file mode 100644
index 000..e9478d1
--- /dev/null
+++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
@@ -0,0 +1,588 @@
+/*
+ * Copyright (C) 2016 Broadcom
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ICFG_DRD_AFE   0x0
+#define ICFG_MISC_STAT 0x18
+#define ICFG_DRD_P0CTL 0x1C
+#define ICFG_STRAP_CTRL0x20
+#define ICFG_FSM_CTRL  0x24
+
+#define IDM_RST_BITBIT(0)
+#define AFE_CORERDY_VDDC   BIT(18)
+#define PHY_PLL_RESETB BIT(15)
+#define PHY_RESETB BIT(14)
+#define PHY_PLL_LOCK   BIT(0)
+
+#define DRD_DEV_MODE   BIT(20)
+#define OHCI_OVRCUR_POLBIT(11)
+#define ICFG_OFF_MODE  BIT(6)
+#define PLL_LOCK_RETRY 1000
+
+#define EVT_DEVICE 0
+#define EVT_HOST   1
+#define EVT_IDLE   2
+
+#define DRD_HOST_MODE  (BIT(2) | BIT(3))
+#define DRD_DEVICE_MODE(BIT(4) | BIT(5))
+#define DRD_HOST_VAL   0x803
+#define DRD_DEV_VAL0x807
+#define GPIO_DELAY 20
+#define PHY_WQ_DELAY   msecs_to_jiffies(600)
+
+struct ns2_phy_data;
+struct ns2_phy_driver {
+   void __iomem *icfgdrd_regs;
+   void __iomem *idmdrd_rst_ctrl;
+   void __iomem *crmu_usb2_ctrl;
+   void __iomem *usb2h_strap_reg;
+   spinlock_t lock; /* spin lock for phy driver */
+   bool host_mode;
+   struct ns2_phy_data *data;
+   struct extcon_specific_cable_nb extcon_dev;
+   struct extcon_specific_cable_nb extcon_host;
+   struct notifier_block host_nb;
+   struct notifier_block dev_nb;
+   struct delayed_work conn_work;
+   struct extcon_dev *edev;
+   struct gpio_desc *vbus_gpiod;
+   struct gpio_desc *id_gpiod;
+   int id_irq;
+   int vbus_irq;
+   unsigned long debounce_jiffies;
+   struct delayed_work wq_extcon;
+};
+
+struct ns2_phy_data {
+   struct ns2_phy_driver *driver;
+   struct phy *phy;
+   int new_state;
+   bool poweron;
+};
+
+static const unsigned int usb_extcon_cable[] = {
+   EXTCON_USB,
+   EXTCON_USB_HOST,
+   EXTCON_NONE

[PATCH v2 1/3] Add DT bindings documentation for NS2 USB DRD phy

2017-01-18 Thread Raviteja Garimella
This patch adds documentation for NS2 DRD Phy driver DT bindings

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
Acked-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   | 30 ++
 1 file changed, 30 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt

diff --git a/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt 
b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
new file mode 100644
index 000..04f063a
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
@@ -0,0 +1,30 @@
+BROADCOM NORTHSTAR2 USB2 (DUAL ROLE DEVICE) PHY
+
+Required properties:
+ - compatible: brcm,ns2-drd-phy
+ - reg: offset and length of the NS2 PHY related registers.
+ - reg-names
+   The below registers must be provided.
+   icfg - for DRD ICFG configurations
+   rst-ctrl - for DRD IDM reset
+   crmu-ctrl - for CRMU core vdd, PHY and PHY PLL reset
+   usb2-strap - for port over current polarity reversal
+ - #phy-cells: Must be 0. No args required.
+ - vbus-gpios: vbus gpio binding
+ - id-gpios: id gpio binding
+
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+Example:
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   };
-- 
2.1.0



[PATCH v2 3/3] DT nodes for Broadcom Northstar2 USB DRD Phy

2017-01-18 Thread Raviteja Garimella
This patch adds device tree nodes for USB Dual Role Device Phy for
Broadcom's Northstar2 SoC.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 arch/arm64/boot/dts/broadcom/ns2.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm64/boot/dts/broadcom/ns2.dtsi 
b/arch/arm64/boot/dts/broadcom/ns2.dtsi
index 4fcdeca..d9f701c 100644
--- a/arch/arm64/boot/dts/broadcom/ns2.dtsi
+++ b/arch/arm64/boot/dts/broadcom/ns2.dtsi
@@ -353,6 +353,20 @@
};
};
 
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   status = "disabled";
+   };
+
pwm: pwm@6601 {
compatible = "brcm,iproc-pwm";
reg = <0x6601 0x28>;
-- 
2.1.0



[PATCH v2 0/3] Support for USB DRD Phy driver for NS2

2017-01-18 Thread Raviteja Garimella
Changes from v1:
===
1. Initialize file operatiosn .owner field with THIS_MODULE
2. Remove unnecessary gpio example in DT bindings documentation.
   This is previously acked by Rob Herring <r...@kernel.org>.

Introduction:

This patch adds support for USB Dual Role Device Phy for Broadcom
Northstar2 SoC. Apart from the new phy driver, this patchset contains
changes to Kconfig, Makefile, and Device tree files.

This patchset is tested on Broadcom NS2 BCM958712K reference board.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: ns2_drdphy_v2

Raviteja Garimella (3):
  Add DT bindings documentation for NS2 USB DRD phy
  Broadcom USB DRD Phy driver for Northstar2
  DT nodes for Broadcom Northstar2 USB DRD Phy

 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   |  30 ++
 arch/arm64/boot/dts/broadcom/ns2.dtsi  |  14 +
 drivers/phy/Kconfig|  13 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c   | 588 +
 5 files changed, 646 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

-- 
2.1.0



Re: [RFC v2 1/5] UDC: Split the driver into amd (pci) and Synopsys core driver

2017-01-19 Thread Raviteja Garimella
Hi,

On Thu, Jan 19, 2017 at 12:15 AM, Florian Fainelli <f.faine...@gmail.com> wrote:
> On 01/17/2017 12:05 AM, Raviteja Garimella wrote:
>> This patch splits the amd5536udc driver into two -- one that does
>> pci device registration and the other file that does the rest of
>> the driver tasks like the gadget/ep ops etc for Synopsys UDC.
>>
>> This way of splitting helps in exporting core driver symbols which
>> can be used by any other platform/pci driver that is written for
>> the same Synopsys USB device controller.
>>
>> The current patch also includes a change in the Kconfig and Makefile.
>> A new config option USB_SNP_CORE will be selected automatically when
>> any one of the platform or pci driver for the same UDC is selected.
>>
>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>
> Although the changes you have done make sense and it is most certainly a
> good idea to split udc core from bus specific glue logic, it is really
> hard to review the changes per-se because of the file rename, could that
> happen at a later time?

If you start looking at this specific patch from the header file (amd5536udc.h),
the additions in there comprise of:
- 9 function declarations
- some module parameter variable declarations that's moved out from the older
  common file amd5536udc.c
- 2 #includes that are needed by all files.

So, basically what's done for this split is that:
1. the static keyword is removed from those 9 functions in the new file
snps_udc_core.c and are exported.
2. The module parameters declarations (since they are used in both core
and pci file) are moved to the header file now.

Rest all is same as in old amd5536udc.c common file. It's just a copy from the
old file.

And, the file amd5536udc.c will now only do the pci device probe and
remove functions.

I hope this helps. Please let me know of any clarifications needed.
Since both the files are required to be reviewed, I think renaming is
inevitable.

Thanks,
Ravi

>
> Also, keep in mind that anytime a driver file is renamed, this poses a
> backport/maintenance issue where backporting fixes from latest upstream
> to a kernel version that has a different file/directory structure is a
> major pain.
> --
> Florian


Re: [PATCH 2/3] Broadcom USB DRD Phy driver for Northstar2

2017-01-16 Thread Raviteja Garimella
Hi Kishon,

On Mon, Jan 16, 2017 at 2:52 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
> Hi,
>
> On Wednesday 30 November 2016 11:25 AM, Raviteja Garimella wrote:
>> This is driver for USB DRD Phy used in Broadcom's Northstar2
>> SoC. The phy can be configured to be in Device mode or Host
>> mode based on the type of cable connected to the port. The
>> driver registers to  extcon framework to get appropriate
>> connect events for Host/Device cables connect/disconnect
>> states based on VBUS and ID interrupts.
>>
>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>> ---
>>  drivers/phy/Kconfig  |  13 +
>>  drivers/phy/Makefile |   1 +
>>  drivers/phy/phy-bcm-ns2-usbdrd.c | 587 
>> +++
>>  3 files changed, 601 insertions(+)
>>  create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c
>>
>> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
>> index fe00f91..b3b6a73 100644
>> --- a/drivers/phy/Kconfig
>> +++ b/drivers/phy/Kconfig
>> @@ -479,6 +479,19 @@ config PHY_CYGNUS_PCIE
>> Enable this to support the Broadcom Cygnus PCIe PHY.
>> If unsure, say N.
>>
>> +config PHY_NS2_USB_DRD
>> + tristate "Broadcom Northstar2 USB DRD PHY support"
>> + depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
>> + select GENERIC_PHY
>> + select EXTCON
>> + default ARCH_BCM_IPROC
>> + help
>> +   Enable this to support the Broadcom Northstar2 USB DRD PHY.
>> +   This driver initializes the PHY in either HOST or DEVICE mode.
>> +   The host or device configuration is read from device tree.
>> +
>> +   If unsure, say N.
>> +
>>  source "drivers/phy/tegra/Kconfig"
>>
>>  config PHY_NS2_PCIE
>> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
>> index a534cf5..b733ba2 100644
>> --- a/drivers/phy/Makefile
>> +++ b/drivers/phy/Makefile
>> @@ -58,5 +58,6 @@ obj-$(CONFIG_PHY_TUSB1210)  += phy-tusb1210.o
>>  obj-$(CONFIG_PHY_BRCM_SATA)  += phy-brcm-sata.o
>>  obj-$(CONFIG_PHY_PISTACHIO_USB)  += phy-pistachio-usb.o
>>  obj-$(CONFIG_PHY_CYGNUS_PCIE)+= phy-bcm-cygnus-pcie.o
>> +obj-$(CONFIG_PHY_NS2_USB_DRD)+= phy-bcm-ns2-usbdrd.o
>>  obj-$(CONFIG_ARCH_TEGRA) += tegra/
>>  obj-$(CONFIG_PHY_NS2_PCIE)   += phy-bcm-ns2-pcie.o
>> diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c 
>> b/drivers/phy/phy-bcm-ns2-usbdrd.c
>> new file mode 100644
>> index 000..460040d
>> --- /dev/null
>> +++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
>> @@ -0,0 +1,587 @@
>> +/*
>> + * Copyright (C) 2016 Broadcom
>> + *
>> + * 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 version 2.
>> + *
>> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
>> + * kind, whether express or implied; without even the implied warranty
>> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define ICFG_DRD_AFE 0x0
>> +#define ICFG_MISC_STAT   0x18
>> +#define ICFG_DRD_P0CTL   0x1C
>> +#define ICFG_STRAP_CTRL  0x20
>> +#define ICFG_FSM_CTRL0x24
>> +
>> +#define IDM_RST_BIT  BIT(0)
>> +#define AFE_CORERDY_VDDC BIT(18)
>> +#define PHY_PLL_RESETB   BIT(15)
>> +#define PHY_RESETB   BIT(14)
>> +#define PHY_PLL_LOCK BIT(0)
>> +
>> +#define DRD_DEV_MODE BIT(20)
>> +#define OHCI_OVRCUR_POL  BIT(11)
>> +#define ICFG_OFF_MODEBIT(6)
>> +#define PLL_LOCK_RETRY   1000
>> +
>> +#define EVT_DEVICE   0
>> +#define EVT_HOST 1
>> +#define EVT_IDLE 2
>> +
>> +#define DRD_HOST_MODE(BIT(2) | BIT(3))
>> +#define DRD_DEVICE_MODE  (BIT(4) | BIT(5))
>> +#define DRD_HOST_VAL 0x803
>> +#define DRD_

[RFC v2 5/5] UDC: Add Synopsys UDC Platform driver

2017-01-17 Thread Raviteja Garimella
This patch adds platform driver support for Synopsys UDC.

A new driver file (snps_udc_plat.c) is created for this purpose,
where the platform driver registration is done based on the OF
node.

New members are added to the UDC data structure for having platform
device support along with extcon and phy support.

Kconfig and Makefile have the required changes to compile the same.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/Kconfig |  15 ++
 drivers/usb/gadget/udc/Makefile|   1 +
 drivers/usb/gadget/udc/amd5536udc.h|  14 ++
 drivers/usb/gadget/udc/snps_udc_core.c |  54 --
 drivers/usb/gadget/udc/snps_udc_plat.c | 342 +
 5 files changed, 407 insertions(+), 19 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/snps_udc_plat.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 9d889bb..44a2058 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -252,6 +252,21 @@ config USB_SNP_CORE
  This IP is different to the High Speed OTG IP that can be enabled
  by selecting USB_DWC2 or USB_DWC3 options.
 
+config USB_SNP_UDC_PLAT
+   tristate "Synopsys USB 2.0 Device controller"
+   select USB_SNP_CORE
+   select USB_GADGET_DUALSPEED
+   depends on (USB_GADGET && OF)
+   default ARCH_BCM_IPROC
+   help
+ This adds Platform Device support for Synopsys Designware core
+ AHB subsystem USB2.0 Device Controller (UDC).
+
+ This driver works with UDCs integrated into Broadcom's Northstar2
+ and Cygnus SoCs.
+
+ If unsure, say N.
+
 #
 # Controllers available in both integrated and discrete versions
 #
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 3929f6f1..7451516 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -37,4 +37,5 @@ obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
 obj-$(CONFIG_USB_MV_U3D)   += mv_u3d_core.o
 obj-$(CONFIG_USB_GR_UDC)   += gr_udc.o
 obj-$(CONFIG_USB_GADGET_XILINX)+= udc-xilinx.o
+obj-$(CONFIG_USB_SNP_UDC_PLAT) += snps_udc_plat.o
 obj-$(CONFIG_USB_BDC_UDC)  += bdc/
diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index c252457..7884281 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -16,6 +16,7 @@
 /* debug control */
 /* #define UDC_VERBOSE */
 
+#include 
 #include 
 #include 
 
@@ -28,6 +29,9 @@
 #define UDC_HSA0_REV 1
 #define UDC_HSB1_REV 2
 
+/* Broadcom chip rev. */
+#define UDC_BCM_REV 10
+
 /*
  * SETUP usb commands
  * needed, because some SETUP's are handled in hw, but must be passed to
@@ -112,6 +116,7 @@
 #define UDC_DEVCTL_BRLEN_MASK  0x00ff
 #define UDC_DEVCTL_BRLEN_OFS   16
 
+#define UDC_DEVCTL_SRX_FLUSH   14
 #define UDC_DEVCTL_CSR_DONE13
 #define UDC_DEVCTL_DEVNAK  12
 #define UDC_DEVCTL_SD  10
@@ -564,7 +569,15 @@ struct udc {
u16 cur_intf;
u16 cur_alt;
 
+   /* for platform device and extcon support */
struct device   *dev;
+   struct phy  *udc_phy;
+   struct extcon_dev   *edev;
+   struct extcon_specific_cable_nb extcon_nb;
+   struct notifier_block   nb;
+   struct delayed_work drd_work;
+   struct workqueue_struct *drd_wq;
+   u32 conn_type;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -580,6 +593,7 @@ int udc_enable_dev_setup_interrupts(struct udc *dev);
 int udc_mask_unused_interrupts(struct udc *dev);
 irqreturn_t udc_irq(int irq, void *pdev);
 void gadget_release(struct device *pdev);
+void empty_req_queue(struct udc_ep *ep);
 void udc_basic_init(struct udc *dev);
 void free_dma_pools(struct udc *dev);
 int init_dma_pools(struct udc *dev);
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 556fa0e..59e2d6a 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -34,7 +34,6 @@
 #include "amd5536udc.h"
 
 static void udc_tasklet_disconnect(unsigned long);
-static void empty_req_queue(struct udc_ep *);
 static void udc_setup_endpoints(struct udc *dev);
 static void udc_soft_reset(struct udc *dev);
 static struct udc_request *udc_alloc_bna_dummy(struct udc_ep *ep);
@@ -1241,7 +1240,7 @@ udc_queue(struct usb_ep *usbep, struct usb_request 
*usbreq, gfp_t gfp)
 }
 
 /* Empty request queue of an endpoint; caller holds spinlock */
-static void empty_req_queue(struct udc_ep *ep)
+void empty_req_queue(struct udc_ep *ep)
 {
struct udc_request  *req;
 

[RFC v2 4/5] DT bindings documentation for Synopsys UDC platform driver

2017-01-17 Thread Raviteja Garimella
This patch adds device tree bindings documentation for Synopsys
USB device controller platform driver.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 .../devicetree/bindings/usb/snps,dw-ahb-udc.txt| 27 ++
 1 file changed, 27 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt

diff --git a/Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt 
b/Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt
new file mode 100644
index 000..0c18327
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt
@@ -0,0 +1,27 @@
+Synopsys USB Device controller.
+
+The device node is used for Synopsys Designware Cores AHB
+Subsystem Device Controller (UDC).
+
+This device node is used by UDCs integrated it Broadcom's
+Northstar2 and Cygnus SoC's.
+
+Required properties:
+ - compatible: should be "snps,dw-ahb-udc"
+ - reg: Offset and length of UDC register set
+ - interrupts: description of interrupt line
+ - phys: phandle to phy node.
+ - extcon: phandle to the extcon device. This is optional and
+   not required for those that don't require extcon support.
+   Extcon support will be required if the UDC is connected to
+   a Dual Role Device Phy that supports both Host and Device
+   mode based on the external cable.
+
+Example:
+   udc_dwc: usb@664e {
+   compatible = "snps,dw-ahb-udc";
+   reg = <0x664e 0x2000>;
+   interrupts = ;
+   phys = <_phy>;
+   extcon = <_phy>";
+   };
-- 
2.1.0



[RFC v2 3/5] UDC: Provide correct arguments for 'dma_pool_create'

2017-01-17 Thread Raviteja Garimella
Change the argument from NULL to a struct device for the
dma_pool_create call during dma init.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/snps_udc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index b7a6218..556fa0e 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -3094,7 +3094,7 @@ int init_dma_pools(struct udc *dev)
}
 
/* DMA setup */
-   dev->data_requests = dma_pool_create("data_requests", NULL,
+   dev->data_requests = dma_pool_create("data_requests", dev->dev,
sizeof(struct udc_data_dma), 0, 0);
if (!dev->data_requests) {
DBG(dev, "can't get request data pool\n");
@@ -3105,7 +3105,7 @@ int init_dma_pools(struct udc *dev)
dev->ep[UDC_EP0IN_IX].dma = >regs->ctl;
 
/* dma desc for setup data */
-   dev->stp_requests = dma_pool_create("setup requests", NULL,
+   dev->stp_requests = dma_pool_create("setup requests", dev->dev,
sizeof(struct udc_stp_dma), 0, 0);
if (!dev->stp_requests) {
DBG(dev, "can't get stp request pool\n");
-- 
2.1.0



[RFC v2 2/5] UDC: make debug prints compatible with both pci and platform devices

2017-01-17 Thread Raviteja Garimella
This patch adds a struct device member to UDC data structure and
makes changes to the arguments of dev_err and dev_dbg calls so that
the debug prints work for both pci and platform devices.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/amd5536udc.c|  1 +
 drivers/usb/gadget/udc/amd5536udc.h|  4 +++-
 drivers/usb/gadget/udc/snps_udc_core.c | 28 ++--
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/udc/amd5536udc.c 
b/drivers/usb/gadget/udc/amd5536udc.c
index c0acb80..3e66b08 100644
--- a/drivers/usb/gadget/udc/amd5536udc.c
+++ b/drivers/usb/gadget/udc/amd5536udc.c
@@ -166,6 +166,7 @@ static int udc_pci_probe(
dev->phys_addr = resource;
dev->irq = pdev->irq;
dev->pdev = pdev;
+   dev->dev = >dev;
 
/* general probing */
if (udc_probe(dev)) {
diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index bd2a18e..c252457 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -563,6 +563,8 @@ struct udc {
u16 cur_config;
u16 cur_intf;
u16 cur_alt;
+
+   struct device   *dev;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -639,7 +641,7 @@ MODULE_PARM_DESC(use_fullspeed, "true for fullspeed only");
 
 /* debug macros */
 
-#define DBG(udc , args...) dev_dbg(&(udc)->pdev->dev, args)
+#define DBG(udc , args...) dev_dbg(udc->dev, args)
 
 #ifdef UDC_VERBOSE
 #define VDBG   DBG
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 69a94bc..b7a6218 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -202,18 +202,18 @@ static void print_regs(struct udc *dev)
if (use_dma && use_dma_ppb && !use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBNDU (packet per buffer "
"WITHOUT desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBNDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBNDU");
} else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBDU (packet per buffer "
"WITH desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBDU");
}
if (use_dma && use_dma_bufferfill_mode) {
DBG(dev, "DMA mode   = BF (buffer fill mode)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "BF");
+   dev_info(dev->dev, "DMA mode (%s)\n", "BF");
}
if (!use_dma)
-   dev_info(>pdev->dev, "FIFO mode\n");
+   dev_info(dev->dev, "FIFO mode\n");
DBG(dev, "---\n");
 }
 
@@ -1621,7 +1621,7 @@ static void udc_setup_endpoints(struct udc *dev)
 static void usb_connect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Connect\n");
+   dev_info(dev->dev, "USB Connect\n");
 
dev->connected = 1;
 
@@ -1639,7 +1639,7 @@ static void usb_connect(struct udc *dev)
 static void usb_disconnect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Disconnect\n");
+   dev_info(dev->dev, "USB Disconnect\n");
 
dev->connected = 0;
 
@@ -2103,7 +2103,7 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int 
ep_ix)
}
/* HE event ? */
if (tmp & AMD_BIT(UDC_EPSTS_HE)) {
-   dev_err(>pdev->dev, "HE ep%dout occurred\n", ep->num);
+   dev_err(dev->dev, "HE ep%dout occurred\n", ep->num);
 
/* clear HE */
writel(tmp | AMD_BIT(UDC_EPSTS_HE), >regs->sts);
@@ -2302,7 +2302,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int 
ep_ix)
if (use_dma) {
/* BNA ? */
if (epsts & AMD_BIT(UDC_EPSTS_BNA)) {
-   dev_err(>pdev->dev,
+   dev_err(dev->dev,
"BNA ep%din occurred - DESPTR = %08lx\n",
ep->num,
(unsigned long) readl(>regs->desptr));
@@ -2315,7 +2315,7 @@ static irqreturn_

[RFC v2 0/5] Platform driver support for 'amd5536udc' driver

2017-01-17 Thread Raviteja Garimella
This is RFC for the changes made as per the review comments made for
the previous version. I would like to know  if this approach (the way
the driver is split and the naming and all)looks good to be submitted.

Changes from v1:
===
1. Split the driver into platform/pci specific drivers with a core driver
   file that handles the common driver routines that are exported.

2. Split the driver into number of patches as suggested in previous
   review comments.

3. Added the devicetree bindings documentation for Synopsys platform
   driver.

Introduction from previous version:
===
This patch adds platform device support to the existing 'amd5536udc'
driver.

The UDC is based on Synopsys Designware core USB (2.0) Device controller
IP.

The driver so far supports UDCs that are a part of AMD southbridge
and is connected through PCI bus.

The same driver can be used with UDCs that are integrated into SoCs
like Broadcom's Northstar2/Cygnus platforms by adding platform device
suooprt.

This patch contains all the changes that were required to get the driver
functional on Broadcom's Northstar2 platform. 

This is a request for comments from maintainers/others regarding approach
on whether to have 2 different drivers (one each for AMD and Broadcom)
with a common library (3 files in total), or have a single driver like
it's done in this patch and have the driver filename changed to some
common name based on ther underlying IP, like snps_udc.c.

Below are the main changes done:

1. Added OF based platform device registration -- so that the driver gets
   probed based on the device tree entry. Like wise, remove routine and
   platform PM ops are supported.

2. Modified debug prints to be compatible with both pci and platform
   devices.

3. Added members to 'struct udc' in header file for extcon and phy support.
   This is required if the UDC is connected to a Dual Role Device Phy
   where the Phy can be configured to be in Device mode or Host mode based
   on the type of external cable that is connected to the port.
 
4. Added checks in udc connect/disconnect routines so as to return if the
   routine is already called.

5. Modified the arguments passed to dma_pool_create routine -- which
   expects struct device, whereas NULL is passed in the existing version.
 
6. Kconfig changes are done so that the driver now depends on either of
   CONFIG_OF or CONFIG_PCI. More description about the Synopsys IP is
   provided.

Raviteja Garimella (5):
  UDC: Split the driver into amd (pci) and Synopsys core driver
  UDC: make debug prints compatible with both pci and platform devices
  UDC: Provide correct arguments for 'dma_pool_create'
  DT bindings documentation for Synopsys UDC platform driver
  UDC: Add Synopsys UDC Platform driver

 .../devicetree/bindings/usb/snps,dw-ahb-udc.txt|   27 +
 drivers/usb/gadget/udc/Kconfig |   32 +
 drivers/usb/gadget/udc/Makefile|2 +
 drivers/usb/gadget/udc/amd5536udc.c| 3249 +---
 drivers/usb/gadget/udc/amd5536udc.h|   54 +-
 drivers/usb/gadget/udc/snps_udc_core.c | 3232 +++
 drivers/usb/gadget/udc/snps_udc_plat.c |  342 +++
 7 files changed, 3714 insertions(+), 3224 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt
 create mode 100644 drivers/usb/gadget/udc/snps_udc_core.c
 create mode 100644 drivers/usb/gadget/udc/snps_udc_plat.c

-- 
2.1.0



Re: [RFC v2 4/5] DT bindings documentation for Synopsys UDC platform driver

2017-01-20 Thread Raviteja Garimella
Hi Rob,

On Thu, Jan 19, 2017 at 11:06 PM, Rob Herring <r...@kernel.org> wrote:
> On Tue, Jan 17, 2017 at 01:35:07PM +0530, Raviteja Garimella wrote:
>> This patch adds device tree bindings documentation for Synopsys
>> USB device controller platform driver.
>
> Bindings describe h/w, not drivers.

 Will correct the commit message.

>>
>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>> ---
>>  .../devicetree/bindings/usb/snps,dw-ahb-udc.txt| 27 
>> ++
>>  1 file changed, 27 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt
>>
>> diff --git a/Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt 
>> b/Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt
>> new file mode 100644
>> index 000..0c18327
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt
>> @@ -0,0 +1,27 @@
>> +Synopsys USB Device controller.
>> +
>> +The device node is used for Synopsys Designware Cores AHB
>> +Subsystem Device Controller (UDC).
>> +
>> +This device node is used by UDCs integrated it Broadcom's
>> +Northstar2 and Cygnus SoC's.
>
> You need compatible strings for these in addition.

Is it fine to have "brcm,iproc-udc"?
iProc refers to a Broadcom family of processors that includes
above mentioned SoCs.

I see there are some compatible strings that are based on the IP,
and some based on the SoCs. I chose to have the IP based string.
Please let me know which one would be agreeable in this case.

I will also correct the typo in the above notes -- it meant to be
UDCs integrated into Broadcom's Northstar2 and Cygnus SoC's.

>
>> +
>> +Required properties:
>> + - compatible: should be "snps,dw-ahb-udc"
>
> This is a different IP than DWC2?

Yes, this is different IP. DWC2 is HS OTG.

>
>> + - reg: Offset and length of UDC register set
>> + - interrupts: description of interrupt line
>> + - phys: phandle to phy node.
>> + - extcon: phandle to the extcon device. This is optional and
>> +   not required for those that don't require extcon support.
>> +   Extcon support will be required if the UDC is connected to
>> +   a Dual Role Device Phy that supports both Host and Device
>> +   mode based on the external cable.
>
> Drop this. It should be a part of the phy. Also, I don't care to see new
> users of extcon binding because it needs redoing.

Currently we can't get the extcon node from Phy.
"extcon_get_edev_by_phandle" requires "extcon" property, else would fail.
As Scott said in one of the comments, we can drop this when we get that
support in kernel. Is it fine?

Thanks,
Ravi


[PATCH 3/3] DT nodes for Broadcom Northstar2 USB DRD Phy

2016-11-29 Thread Raviteja Garimella
This patch adds device tree nodes for USB Dual Role Device Phy for
Broadcom's Northstar2 SoC.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 arch/arm64/boot/dts/broadcom/ns2.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm64/boot/dts/broadcom/ns2.dtsi 
b/arch/arm64/boot/dts/broadcom/ns2.dtsi
index d95dc40..e9d3496 100644
--- a/arch/arm64/boot/dts/broadcom/ns2.dtsi
+++ b/arch/arm64/boot/dts/broadcom/ns2.dtsi
@@ -299,6 +299,20 @@
};
};
 
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   status = "disabled";
+   };
+
pwm: pwm@6601 {
compatible = "brcm,iproc-pwm";
reg = <0x6601 0x28>;
-- 
2.1.0



[PATCH 2/2] Synopsys USB 2.0 Device Controller (UDC) Driver

2016-11-29 Thread Raviteja Garimella
This is driver for Synopsys Designware Cores USB Device
Controller (UDC) Subsystem with the AMBA Advanced High-Performance
Bus (AHB). This driver works with Synopsys UDC20 products.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/Kconfig|   12 +
 drivers/usb/gadget/udc/Makefile   |1 +
 drivers/usb/gadget/udc/snps_udc.c | 1751 +
 drivers/usb/gadget/udc/snps_udc.h | 1071 +++
 4 files changed, 2835 insertions(+)
 create mode 100644 drivers/usb/gadget/udc/snps_udc.c
 create mode 100644 drivers/usb/gadget/udc/snps_udc.h

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 658b8da..28cd679 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -239,6 +239,18 @@ config USB_MV_U3D
  MARVELL PXA2128 Processor series include a super speed USB3.0 device
  controller, which support super speed USB peripheral.
 
+config USB_SNP_UDC
+   tristate "Synopsys USB 2.0 Device controller"
+   select USB_GADGET_DUALSPEED
+   depends on (ARM || ARM64) && USB_GADGET
+   default ARCH_BCM_IPROC
+   help
+ This adds Device support for Synopsys Designware core
+ AHB subsystem USB2.0 Device Controller(UDC) .
+
+ This driver works with Synopsys UDC20 products.
+ If unsure, say N.
+
 #
 # Controllers available in both integrated and discrete versions
 #
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 98e74ed..2b63a2b 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -36,4 +36,5 @@ obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
 obj-$(CONFIG_USB_MV_U3D)   += mv_u3d_core.o
 obj-$(CONFIG_USB_GR_UDC)   += gr_udc.o
 obj-$(CONFIG_USB_GADGET_XILINX)+= udc-xilinx.o
+obj-$(CONFIG_USB_SNP_UDC)  += snps_udc.o
 obj-$(CONFIG_USB_BDC_UDC)  += bdc/
diff --git a/drivers/usb/gadget/udc/snps_udc.c 
b/drivers/usb/gadget/udc/snps_udc.c
new file mode 100644
index 000..d8c46ce
--- /dev/null
+++ b/drivers/usb/gadget/udc/snps_udc.c
@@ -0,0 +1,1751 @@
+/*
+ * snps_udc.c - Synopsys USB 2.0 Device Controller driver
+ *
+ * Copyright (C) 2016 Broadcom
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "snps_udc.h"
+
+#define DRIVER_DESC "Driver for Synopsys Designware core UDC"
+
+static void ep0_setup_init(struct snps_udc_ep *ep, int status)
+{
+   struct snps_udc *udc = ep->udc;
+
+   ep->dma.virt->setup.status = DMA_STS_BUF_HOST_READY;
+   ep->dirn = USB_DIR_OUT;
+   ep->stopped = 0;
+
+   if (!status) {
+   clear_ep_nak(udc->regs, ep->num, USB_DIR_OUT);
+   clear_ep_nak(udc->regs, ep->num, USB_DIR_IN);
+   } else {
+   enable_ep_stall(udc->regs, ep->num, USB_DIR_IN);
+   enable_ep_stall(udc->regs, ep->num, USB_DIR_OUT);
+   }
+
+   enable_udc_ep_irq(udc->regs, ep->num, USB_DIR_OUT);
+   enable_ep_dma(udc->regs, ep->num, USB_DIR_OUT);
+
+   dev_dbg(udc->dev, "%s setup buffer initialized\n", ep->name);
+}
+
+static void ep_dma_init(struct snps_udc_ep *ep)
+{
+   struct snps_udc *udc = ep->udc;
+   u32 desc_cnt = (DESC_CNT - 1);
+   u32 i;
+
+   ep->dma.virt = >udc->dma.virt->ep[ep->num];
+   ep->dma.phys = >udc->dma.phys->ep[ep->num];
+
+   ep->dma.virt->setup.status = DMA_STS_BUF_HOST_BUSY;
+   set_setup_buf_ptr(udc->regs, ep->num, USB_DIR_OUT,
+ >dma.phys->setup);
+
+   for (i = 0; i < DESC_CNT; i++) {
+   ep->dma.virt->desc[i].status = DMA_STS_BUF_HOST_BUSY;
+   ep->dma.virt->desc[i].next_desc_addr =
+   (dma_addr_t)>dma.phys->desc[i + 1];
+   }
+   ep->dma.virt->desc[desc_cnt].next_desc_addr =
+   (dma_addr_t)>dma.phys->desc[0];
+
+   set_data_desc_ptr(udc->regs, ep->num, USB_DIR_OUT,
+ >dma.phys->desc[0]);
+   set_data_desc_ptr(udc->regs, ep->num, USB_DIR_IN,
+ >dma.phys->desc[0]);
+
+

[PATCH 1/2] Add DT bindings documentation for Synopsys UDC driver

2016-11-29 Thread Raviteja Garimella
This patch adds documentation for Synopsis Designware Cores AHB
Subsystem Device Controller (UDC).

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 .../devicetree/bindings/usb/snps,dw-ahb-udc.txt| 29 ++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt

diff --git a/Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt 
b/Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt
new file mode 100644
index 000..64e1fbf
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt
@@ -0,0 +1,29 @@
+Synopsys USB Device controller.
+
+The device node is used for Synopsys Designware Cores AHB
+Subsystem Device Controller (UDC).
+
+Required properties:
+ - compatible: should be "snps,dw-ahbudc"
+ - reg: Offset and length of UDC register set
+ - interrupts: description of interrupt line
+ - phys: phandle to phy node.
+ - phy-names: name of phy node. Must be usb2drd.
+ - extcon: phandle to the extcon device
+
+Example:
+
+   usbdrd_phy: phy@6501c000 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x6600 0x1000>,
+   }
+
+   udc_dwc: usb@664e {
+   compatible = "snps,dw-ahb-udc";
+   reg = <0x664e 0x2000>;
+   interrupts = ;
+   phys = <_phy>;
+   phy-names = "usb2drd";
+   extcon = <_phy>";
+   };
-- 
2.1.0



[PATCH 0/3] Support for USB DRD Phy driver for NS2

2016-11-29 Thread Raviteja Garimella
This patch adds support for USB Dual Role Device Phy for Broadcom
Northstar2 SoC. Apart from the new phy driver, this patchset contains
changes to Kconfig, Makefile, and Device tree files.

This patchset is tested on Broadcom NS2 BCM958712K reference board.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: ns2_drdphy

Raviteja Garimella (3):
  Add DT bindings documentation for NS2 USB DRD phy
  Broadcom USB DRD Phy driver for Northstar2
  DT nodes for Broadcom Northstar2 USB DRD Phy

 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   |  40 ++
 arch/arm64/boot/dts/broadcom/ns2.dtsi  |  14 +
 drivers/phy/Kconfig|  13 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c   | 587 +
 5 files changed, 655 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

-- 
2.1.0



[PATCH 1/3] Add DT bindings documentation for NS2 USB DRD phy

2016-11-29 Thread Raviteja Garimella
This patch adds documentation for NS2 DRD Phy driver DT bindings

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   | 40 ++
 1 file changed, 40 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt

diff --git a/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt 
b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
new file mode 100644
index 000..5857f99
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
@@ -0,0 +1,40 @@
+BROADCOM NORTHSTAR2 USB2 (DUAL ROLE DEVICE) PHY
+
+Required properties:
+ - compatible: brcm,ns2-drd-phy
+ - reg: offset and length of the NS2 PHY related registers.
+ - reg-names
+   The below registers must be provided.
+   icfg - for DRD ICFG configurations
+   rst-ctrl - for DRD IDM reset
+   crmu-ctrl - for CRMU core vdd, PHY and PHY PLL reset
+   usb2-strap - for port over current polarity reversal
+ - #phy-cells: Must be 0. No args required.
+ - vbus-gpios: vbus gpio binding
+ - id-gpios: id gpio binding
+
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+Example:
+   gpio_g: gpio@660a {
+   compatible = "brcm,iproc-gpio";
+   reg = <0x660a 0x50>;
+   ngpios = <32>;
+   #gpio-cells = <2>;
+   gpio-controller;
+   interrupt-controller;
+   interrupts = ;
+   };
+
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   };
-- 
2.1.0



[PATCH 2/3] Broadcom USB DRD Phy driver for Northstar2

2016-11-29 Thread Raviteja Garimella
This is driver for USB DRD Phy used in Broadcom's Northstar2
SoC. The phy can be configured to be in Device mode or Host
mode based on the type of cable connected to the port. The
driver registers to  extcon framework to get appropriate
connect events for Host/Device cables connect/disconnect
states based on VBUS and ID interrupts.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/phy/Kconfig  |  13 +
 drivers/phy/Makefile |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c | 587 +++
 3 files changed, 601 insertions(+)
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index fe00f91..b3b6a73 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -479,6 +479,19 @@ config PHY_CYGNUS_PCIE
  Enable this to support the Broadcom Cygnus PCIe PHY.
  If unsure, say N.
 
+config PHY_NS2_USB_DRD
+   tristate "Broadcom Northstar2 USB DRD PHY support"
+   depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
+   select GENERIC_PHY
+   select EXTCON
+   default ARCH_BCM_IPROC
+   help
+ Enable this to support the Broadcom Northstar2 USB DRD PHY.
+ This driver initializes the PHY in either HOST or DEVICE mode.
+ The host or device configuration is read from device tree.
+
+ If unsure, say N.
+
 source "drivers/phy/tegra/Kconfig"
 
 config PHY_NS2_PCIE
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index a534cf5..b733ba2 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -58,5 +58,6 @@ obj-$(CONFIG_PHY_TUSB1210)+= phy-tusb1210.o
 obj-$(CONFIG_PHY_BRCM_SATA)+= phy-brcm-sata.o
 obj-$(CONFIG_PHY_PISTACHIO_USB)+= phy-pistachio-usb.o
 obj-$(CONFIG_PHY_CYGNUS_PCIE)  += phy-bcm-cygnus-pcie.o
+obj-$(CONFIG_PHY_NS2_USB_DRD)  += phy-bcm-ns2-usbdrd.o
 obj-$(CONFIG_ARCH_TEGRA) += tegra/
 obj-$(CONFIG_PHY_NS2_PCIE) += phy-bcm-ns2-pcie.o
diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c b/drivers/phy/phy-bcm-ns2-usbdrd.c
new file mode 100644
index 000..460040d
--- /dev/null
+++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
@@ -0,0 +1,587 @@
+/*
+ * Copyright (C) 2016 Broadcom
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ICFG_DRD_AFE   0x0
+#define ICFG_MISC_STAT 0x18
+#define ICFG_DRD_P0CTL 0x1C
+#define ICFG_STRAP_CTRL0x20
+#define ICFG_FSM_CTRL  0x24
+
+#define IDM_RST_BITBIT(0)
+#define AFE_CORERDY_VDDC   BIT(18)
+#define PHY_PLL_RESETB BIT(15)
+#define PHY_RESETB BIT(14)
+#define PHY_PLL_LOCK   BIT(0)
+
+#define DRD_DEV_MODE   BIT(20)
+#define OHCI_OVRCUR_POLBIT(11)
+#define ICFG_OFF_MODE  BIT(6)
+#define PLL_LOCK_RETRY 1000
+
+#define EVT_DEVICE 0
+#define EVT_HOST   1
+#define EVT_IDLE   2
+
+#define DRD_HOST_MODE  (BIT(2) | BIT(3))
+#define DRD_DEVICE_MODE(BIT(4) | BIT(5))
+#define DRD_HOST_VAL   0x803
+#define DRD_DEV_VAL0x807
+#define GPIO_DELAY 20
+#define PHY_WQ_DELAY   msecs_to_jiffies(600)
+
+struct ns2_phy_data;
+struct ns2_phy_driver {
+   void __iomem *icfgdrd_regs;
+   void __iomem *idmdrd_rst_ctrl;
+   void __iomem *crmu_usb2_ctrl;
+   void __iomem *usb2h_strap_reg;
+   spinlock_t lock; /* spin lock for phy driver */
+   bool host_mode;
+   struct ns2_phy_data *data;
+   struct extcon_specific_cable_nb extcon_dev;
+   struct extcon_specific_cable_nb extcon_host;
+   struct notifier_block host_nb;
+   struct notifier_block dev_nb;
+   struct delayed_work conn_work;
+   struct extcon_dev *edev;
+   struct gpio_desc *vbus_gpiod;
+   struct gpio_desc *id_gpiod;
+   int id_irq;
+   int vbus_irq;
+   unsigned long debounce_jiffies;
+   struct delayed_work wq_extcon;
+};
+
+struct ns2_phy_data {
+   struct ns2_phy_driver *driver;
+   struct phy *phy;
+   int new_state;
+   bool poweron;
+};
+
+static const unsigned int usb_extcon_cable[] = {
+   EXTCON_USB,
+   EXTCON_USB_HOST,
+   EXTCON_NONE,
+};
+
+static inline int pll_lock_stat(u32 usb_reg, int reg_

[PATCH 0/2] Support for Synopsys UDC for ARM platforms

2016-11-29 Thread Raviteja Garimella
This patchset adds support for Synposys Designware core AHB-UDC
(USB Device controller) for Arm platfoms.

New UDC driver is added to drivers/usb/gadget directory along with
updating the Kconfig and Makefile. 
DT bindings documentation is also added for the same.
Device tree entry for the same in NS2 dtsi will be sent for review
once the DRD phy driver code is pushed (which is being reviewed in a
separate patch series).

This patchset is tested on Broadcom NS2 BCM958712K reference board.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: udc_v1

Raviteja Garimella (2):
  Add DT bindings documentation for Synopsys UDC driver
  Synopsys USB 2.0 Device Controller (UDC) Driver

 .../devicetree/bindings/usb/snps,dw-ahb-udc.txt|   29 +
 drivers/usb/gadget/udc/Kconfig |   12 +
 drivers/usb/gadget/udc/Makefile|1 +
 drivers/usb/gadget/udc/snps_udc.c  | 1751 
 drivers/usb/gadget/udc/snps_udc.h  | 1071 
 5 files changed, 2864 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt
 create mode 100644 drivers/usb/gadget/udc/snps_udc.c
 create mode 100644 drivers/usb/gadget/udc/snps_udc.h

-- 
2.1.0



Re: [PATCH 2/2] Synopsys USB 2.0 Device Controller (UDC) Driver

2016-11-30 Thread Raviteja Garimella
Hi Balbi,

On Wed, Nov 30, 2016 at 4:10 PM, Felipe Balbi <ba...@kernel.org> wrote:
>
> Hi,
>
> Raviteja Garimella <raviteja.garime...@broadcom.com> writes:
>> This is driver for Synopsys Designware Cores USB Device
>> Controller (UDC) Subsystem with the AMBA Advanced High-Performance
>> Bus (AHB). This driver works with Synopsys UDC20 products.
>>
>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>
> use drivers/usb/dwc2 instead of duplicating it.

The ones we have in drivers/usb/dwc2 is for Designware high speed OTG
controller IP. The one that I submitted for review is for USB Device
controller IP (UDC). The IPs are different.

Thanks,
Ravi
>
> --
> balbi


Re: [PATCH 1/2] Add DT bindings documentation for Synopsys UDC driver

2016-12-06 Thread Raviteja Garimella
Hi Rob,

On Tue, Dec 6, 2016 at 4:34 AM, Rob Herring <r...@kernel.org> wrote:
> On Wed, Nov 30, 2016 at 11:35:09AM +0530, Raviteja Garimella wrote:
>> This patch adds documentation for Synopsis Designware Cores AHB
>> Subsystem Device Controller (UDC).
>>
>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>> ---
>>  .../devicetree/bindings/usb/snps,dw-ahb-udc.txt| 29 
>> ++
>>  1 file changed, 29 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt
>>
>> diff --git a/Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt 
>> b/Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt
>> new file mode 100644
>> index 000..64e1fbf
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/usb/snps,dw-ahb-udc.txt
>> @@ -0,0 +1,29 @@
>> +Synopsys USB Device controller.
>> +
>> +The device node is used for Synopsys Designware Cores AHB
>> +Subsystem Device Controller (UDC).
>> +
>> +Required properties:
>> + - compatible: should be "snps,dw-ahbudc"
>
> Needs an SoC specific compatible string.

This will be changed. I am working on using amd5536udc.c driver
which's already in Kernel tree and can be used for this UDC(as per
review comments from Felipe/John).
>
>> + - reg: Offset and length of UDC register set
>> + - interrupts: description of interrupt line
>> + - phys: phandle to phy node.
>> + - phy-names: name of phy node. Must be usb2drd.
>
> A name is pointless when there's only 1 phy. Is this a device or dual
> role device(DRD)?

This is DRD phy that's is connected to a Host Controller and a Device
Controller.
>
>> + - extcon: phandle to the extcon device
>
> I don't think extcon should be required. If this is UDC only, I'm not
> sure why you'd need it.

This Phy will be initialized in Host/Device mode based on the external
connector that's plugged in. That's reason for having extcon node.
>
>> +
>> +Example:
>> +
>> + usbdrd_phy: phy@6501c000 {
>> + #phy-cells = <0>;
>> + compatible = "brcm,ns2-drd-phy";
>> + reg = <0x6600 0x1000>,
>> + }
>> +
>> + udc_dwc: usb@664e {
>> + compatible = "snps,dw-ahb-udc";
>
> Doesn't match above.

This will be changed.
>
>> + reg = <0x664e 0x2000>;
>> + interrupts = ;
>> + phys = <_phy>;
>> + phy-names = "usb2drd";
>> + extcon = <_phy>";
>
> You are already describing the phy connection, you shouldn't need both.

"extcon_get_edev_by_phandle" requires extcon phandle. I see that's the
only way to get the extcon device, since generic Phy device doesn't
have any extcon member.
The current driver will not go as-is after the suggestion I got in UDC
driver review (to use amd5536udc driver). I will work on the changes
and submit the patches once again.

Thanks,
Ravi
>
>> + };
>> --
>> 2.1.0
>>


[RFC 0/1] Platform driver support for 'amd5536udc' driver

2017-01-05 Thread Raviteja Garimella
This patch adds platform device support to the existing 'amd5536udc'
driver.

The UDC is based on Synopsys Designware core USB (2.0) Device controller
IP.

The driver so far supports UDCs that are a part of AMD southbridge
and is connected through PCI bus.

The same driver can be used with UDCs that are integrated into SoCs
like Broadcom's Northstar2/Cygnus platforms by adding platform device
suooprt.

This patch contains all the changes that were required to get the driver
functional on Broadcom's Northstar2 platform. 

This is a request for comments from maintainers/others regarding approach
on whether to have 2 different drivers (one each for AMD and Broadcom)
with a common library (3 files in total), or have a single driver like
it's done in this patch and have the driver filename changed to some
common name based on ther underlying IP, like snps_udc.c.

Below are the main changes done:

1. Added OF based platform device registration -- so that the driver gets
   probed based on the device tree entry. Like wise, remove routine and
   platform PM ops are supported.

2. Modified debug prints to be compatible with both pci and platform
   devices.

3. Added members to 'struct udc' in header file for extcon and phy support.
   This is required if the UDC is connected to a Dual Role Device Phy
   where the Phy can be configured to be in Device mode or Host mode based
   on the type of external cable that is connected to the port.
 
4. Added checks in udc connect/disconnect routines so as to return if the
   routine is already called.

5. Modified the arguments passed to dma_pool_create routine -- which
   expects struct device, whereas NULL is passed in the existing version.
 
6. Kconfig changes are done so that the driver now depends on either of
   CONFIG_OF or CONFIG_PCI. More description about the Synopsys IP is
   provided.

Raviteja Garimella (1):
  Changes to support the driver for platform device registration

 drivers/usb/gadget/udc/Kconfig  |   6 +-
 drivers/usb/gadget/udc/amd5536udc.c | 397 +---
 drivers/usb/gadget/udc/amd5536udc.h |  17 +-
 3 files changed, 387 insertions(+), 33 deletions(-)

-- 
2.1.0



[RFC 1/1] Changes to support the driver for platform device registration

2017-01-05 Thread Raviteja Garimella
-- Add OF based platform device registration
-- Modify debug prints to be compatible with both pci and platform devices
-- Add members to 'struct udc' for extcon and phy support
-- Add checks to not process repeated calls to udc connect and
   disconnect routines
-- Kconfig changes

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/Kconfig  |   6 +-
 drivers/usb/gadget/udc/amd5536udc.c | 397 +---
 drivers/usb/gadget/udc/amd5536udc.h |  17 +-
 3 files changed, 387 insertions(+), 33 deletions(-)

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 658b8da..7728fec 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -263,7 +263,7 @@ source "drivers/usb/gadget/udc/bdc/Kconfig"
 
 config USB_AMD5536UDC
tristate "AMD5536 UDC"
-   depends on PCI
+   depends on PCI || OF
help
   The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge.
   It is a USB Highspeed DMA capable USB device controller. Beside ep0
@@ -271,6 +271,10 @@ config USB_AMD5536UDC
   The UDC port supports OTG operation, and may be used as a host port
   if it's not being used to implement peripheral or OTG roles.
 
+  This UDC is based on Synopsis Designware core USB Device controller
+  IP. The driver also supports UDCs integrated to ARM based SoC's like
+  Broadcom's Northstar2 and Cygnus platforms.
+
   Say "y" to link the driver statically, or "m" to build a
   dynamically linked module called "amd5536udc" and force all
   gadget drivers to also be dynamically linked.
diff --git a/drivers/usb/gadget/udc/amd5536udc.c 
b/drivers/usb/gadget/udc/amd5536udc.c
index ea03ca7..b086cf1 100644
--- a/drivers/usb/gadget/udc/amd5536udc.c
+++ b/drivers/usb/gadget/udc/amd5536udc.c
@@ -22,16 +22,25 @@
  * UDC DMA requires 32-bit aligned buffers so DMA with gadget ether does not
  * work without updating NET_IP_ALIGN. Or PIO mode (module param "use_dma=0")
  * can be used with gadget ether.
+ *
+ * This driver is compatible for Broadcom's UDC for Northstar2 and Cygnus
+ * SOCs. The UDC is based on Synopsys designware core USB device controller IP.
  */
 
 /* debug control */
 /* #define UDC_VERBOSE */
 
 /* Driver strings */
-#define UDC_MOD_DESCRIPTION"AMD 5536 UDC - USB Device Controller"
+#define UDC_MOD_DESCRIPTION"AMD 5536 UDC - Synopsys USB Device Controller"
 #define UDC_DRIVER_VERSION_STRING  "01.00.0206"
 
 /* system */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -251,18 +260,18 @@ static void print_regs(struct udc *dev)
if (use_dma && use_dma_ppb && !use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBNDU (packet per buffer "
"WITHOUT desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBNDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBNDU");
} else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBDU (packet per buffer "
"WITH desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBDU");
}
if (use_dma && use_dma_bufferfill_mode) {
DBG(dev, "DMA mode   = BF (buffer fill mode)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "BF");
+   dev_info(dev->dev, "DMA mode (%s)\n", "BF");
}
if (!use_dma)
-   dev_info(>pdev->dev, "FIFO mode\n");
+   dev_info(dev->dev, "FIFO mode\n");
DBG(dev, "---\n");
 }
 
@@ -1666,8 +1675,11 @@ static void udc_setup_endpoints(struct udc *dev)
 /* Bringup after Connect event, initial bringup to be ready for ep0 events */
 static void usb_connect(struct udc *dev)
 {
+   /* Return if already connected */
+   if (dev->connected)
+   return;
 
-   dev_info(>pdev->dev, "USB Connect\n");
+   dev_info(dev->dev, "USB Connect\n");
 
dev->connected = 1;
 
@@ -1684,8 +1696,11 @@ static void usb_connect(struct udc *dev)
  */
 static void usb_disconnect(struct udc *dev)
 {
+   /* Return if already disconnected */
+   if (!dev->connected)
+   return;
 
-   dev_info(>pdev->dev, "USB Disconnect\n");
+   dev_info(dev->

Re: [RFC 0/1] Platform driver support for 'amd5536udc' driver

2017-01-05 Thread Raviteja Garimella
Hi Arnd,

On Fri, Jan 6, 2017 at 3:33 AM, Arnd Bergmann <a...@arndb.de> wrote:
> On Thursday, January 5, 2017 1:53:16 PM CET Raviteja Garimella wrote:
>> The UDC is based on Synopsys Designware core USB (2.0) Device controller
>> IP.
> ...
>> This is a request for comments from maintainers/others regarding approach
>> on whether to have 2 different drivers (one each for AMD and Broadcom)
>> with a common library (3 files in total), or have a single driver like
>> it's done in this patch and have the driver filename changed to some
>> common name based on ther underlying IP, like snps_udc.c.
>
> I have not looked at the code at all, so sorry for my ignorance, but
> isn't the IP block you describe the one that drivers/usb/dwc2/ is for?
> Could you add support for the Broadcom hardware there instead?

The current driver I submitted is for a different Synopsys IP (USB
Device Controller IP,
not the HS OTG). It's confirmed by John Youn (from Synopsys) earlier.

Thanks,
Ravi
>
> Arnd


Re: [RFC 1/1] Changes to support the driver for platform device registration

2017-01-05 Thread Raviteja Garimella
Hi Florian,

On Thu, Jan 5, 2017 at 11:13 PM, Florian Fainelli <f.faine...@gmail.com> wrote:
> On 01/05/2017 12:23 AM, Raviteja Garimella wrote:
>> -- Add OF based platform device registration
>> -- Modify debug prints to be compatible with both pci and platform devices
>> -- Add members to 'struct udc' for extcon and phy support
>> -- Add checks to not process repeated calls to udc connect and
>>disconnect routines
>> -- Kconfig changes
>
> What you are doing in this patch is all well and good, but since you are
> listing these changes, that means we should see 4/5 patches submitted to
> this driver each one doing what you have as a bullet point.
>
> Since you are adding Device Tree probing support to the driver, you also
> need to create a proper binding document which describes the properties
> and nodes.

I will split this patch into multiple patches, and also create the
binding document.
Thanks. I will wait a bit for any other comments.

Ravi

>
> Thank you
> --
> Florian


[PATCH v3 7/7] UDC: Add Synopsys UDC Platform driver

2017-03-28 Thread Raviteja Garimella
This patch adds platform driver support for Synopsys UDC.

A new driver file (snps_udc_plat.c) is created for this purpose
where the platform driver registration is done based on OF
node.

Currently, UDC integrated into Broadcom's iProc SoCs (Northstar2
and Cygnus) work with this driver.

New members are added to the UDC data structure for having platform
device support along with extcon and phy support.

Kconfig and Makefiles are modified to select platform driver for
compilation.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/Kconfig |  16 +-
 drivers/usb/gadget/udc/Makefile|   1 +
 drivers/usb/gadget/udc/amd5536udc.h|  14 ++
 drivers/usb/gadget/udc/snps_udc_core.c |  54 --
 drivers/usb/gadget/udc/snps_udc_plat.c | 344 +
 5 files changed, 409 insertions(+), 20 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/snps_udc_plat.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 2cee076..fe87523 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -254,7 +254,7 @@ config USB_MV_U3D
  controller, which support super speed USB peripheral.
 
 config USB_SNP_CORE
-   depends on USB_AMD5536UDC
+   depends on (USB_AMD5536UDC || USB_SNP_UDC_PLAT)
tristate
help
  This enables core driver support for Synopsys USB 2.0 Device
@@ -267,6 +267,20 @@ config USB_SNP_CORE
  This IP is different to the High Speed OTG IP that can be enabled
  by selecting USB_DWC2 or USB_DWC3 options.
 
+config USB_SNP_UDC_PLAT
+   tristate "Synopsys USB 2.0 Device controller"
+   depends on (USB_GADGET && OF)
+   select USB_GADGET_DUALSPEED
+   select USB_SNP_CORE
+   default ARCH_BCM_IPROC
+   help
+ This adds Platform Device support for Synopsys Designware core
+ AHB subsystem USB2.0 Device Controller (UDC).
+
+ This driver works with UDCs integrated into Broadcom's Northstar2
+ and Cygnus SoCs.
+
+ If unsure, say N.
 #
 # Controllers available in both integrated and discrete versions
 #
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 4f4fd62..ea9e1c7 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -37,4 +37,5 @@ obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
 obj-$(CONFIG_USB_MV_U3D)   += mv_u3d_core.o
 obj-$(CONFIG_USB_GR_UDC)   += gr_udc.o
 obj-$(CONFIG_USB_GADGET_XILINX)+= udc-xilinx.o
+obj-$(CONFIG_USB_SNP_UDC_PLAT) += snps_udc_plat.o
 obj-$(CONFIG_USB_BDC_UDC)  += bdc/
diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index 91aae23..4fe22d4 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -16,6 +16,7 @@
 /* debug control */
 /* #define UDC_VERBOSE */
 
+#include 
 #include 
 #include 
 
@@ -28,6 +29,9 @@
 #define UDC_HSA0_REV 1
 #define UDC_HSB1_REV 2
 
+/* Broadcom chip rev. */
+#define UDC_BCM_REV 10
+
 /*
  * SETUP usb commands
  * needed, because some SETUP's are handled in hw, but must be passed to
@@ -112,6 +116,7 @@
 #define UDC_DEVCTL_BRLEN_MASK  0x00ff
 #define UDC_DEVCTL_BRLEN_OFS   16
 
+#define UDC_DEVCTL_SRX_FLUSH   14
 #define UDC_DEVCTL_CSR_DONE13
 #define UDC_DEVCTL_DEVNAK  12
 #define UDC_DEVCTL_SD  10
@@ -564,7 +569,15 @@ struct udc {
u16 cur_intf;
u16 cur_alt;
 
+   /* for platform device and extcon support */
struct device   *dev;
+   struct phy  *udc_phy;
+   struct extcon_dev   *edev;
+   struct extcon_specific_cable_nb extcon_nb;
+   struct notifier_block   nb;
+   struct delayed_work drd_work;
+   struct workqueue_struct *drd_wq;
+   u32 conn_type;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -580,6 +593,7 @@ int udc_enable_dev_setup_interrupts(struct udc *dev);
 int udc_mask_unused_interrupts(struct udc *dev);
 irqreturn_t udc_irq(int irq, void *pdev);
 void gadget_release(struct device *pdev);
+void empty_req_queue(struct udc_ep *ep);
 void udc_basic_init(struct udc *dev);
 void free_dma_pools(struct udc *dev);
 int init_dma_pools(struct udc *dev);
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 9d3861b..b5f772e 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -41,7 +41,6 @@
 #include "amd5536udc.h"
 
 static void udc_tasklet_disconnect(unsigned long);
-static void empty_req_queue(struct udc_ep *);
 static void udc_setup_endpoints(struct udc 

[PATCH v3 0/7] Platform driver support for 'amd5536udc' driver

2017-03-28 Thread Raviteja Garimella
Changes in PATCH v3:
===
1. Updated bindings documentation and platform driver to add
   "brcm,iproc-udc" compatibility string.

2. Added a patch to replace references of struct pci_pool with
   struct dma_pool so that it is compatibile with non-pci drivers.

Changes in PATCH v2:
===
1. Updated bindings documentation:
   -- compatibility string for each supported SoC
   -- removed extcon node
   -- rename the file name to just iproc-udc.txt

2. Modified comptability strings in platform driver file
   to reflect the change made in 1.

3 Kconfig
   -- Resolved warnings shown by kbuild-test-robot  

The changes are being submitted as PATCH this time. Below are the
details of main changes with respect to previous RFC versions.

Changes in PATCH v1:
===
Patch 1/6 now splits the driver into amd5536udc_pci_.c (which
contains only the PCI device registration part), and amd5536udc.c
will still be driver that does the rest of UDC driver functionality.

Patch 2/6 renames amd5536udc.c to snps_udc_core.c.

The DT compatibilty string is changed to "brcm,iproc-snps-udc"
as per review comments for RFCv2. The driver and bindings
documentation is modified to reflect this.

This is RFC for the changes made as per the review comments made for
the previous version. I would like to know  if this approach (the way
the driver is split and the naming and all)looks good to be submitted.


Changes in RFC v2:
=
1. Split the driver into platform/pci specific drivers with a core driver
   file that handles the common driver routines that are exported.

2. Split the driver into number of patches as suggested in previous
   review comments.

3. Added the devicetree bindings documentation for Synopsys platform
   driver.

Introduction (RFC v1):
=
This patch adds platform device support to the existing 'amd5536udc'
driver.

The UDC is based on Synopsys Designware core USB (2.0) Device controller
IP.

The driver so far supports UDCs that are a part of AMD southbridge
and is connected through PCI bus.

The same driver can be used with UDCs that are integrated into SoCs
like Broadcom's Northstar2/Cygnus platforms by adding platform device
suooprt.

This patch contains all the changes that were required to get the driver
functional on Broadcom's Northstar2 platform. 

This is a request for comments from maintainers/others regarding approach
on whether to have 2 different drivers (one each for AMD and Broadcom)
with a common library (3 files in total), or have a single driver like
it's done in this patch and have the driver filename changed to some
common name based on ther underlying IP, like snps_udc.c.

Below are the main changes done:

1. Added OF based platform device registration -- so that the driver gets
   probed based on the device tree entry. Like wise, remove routine and
   platform PM ops are supported.

2. Modified debug prints to be compatible with both pci and platform
   devices.

3. Added members to 'struct udc' in header file for extcon and phy support.
   This is required if the UDC is connected to a Dual Role Device Phy
   where the Phy can be configured to be in Device mode or Host mode based
   on the type of external cable that is connected to the port.
 
4. Added checks in udc connect/disconnect routines so as to return if the
   routine is already called.

5. Modified the arguments passed to dma_pool_create routine -- which
   expects struct device, whereas NULL is passed in the existing version.
 
6. Kconfig changes are done so that the driver now depends on either of
   CONFIG_OF or CONFIG_PCI. More description about the Synopsys IP is
   provided.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: udc_snps_v3

Raviteja Garimella (7):
  UDC: Split the driver into amd (pci) and Synopsys core IP driver
  UDC: Rename amd5536udc driver file based on IP
  UDC: make debug prints compatible with both pci and platform devices
  UDC: Provide correct arguments for 'dma_pool_create'
  UDC: Use struct dma_pool instead of pci_pool
  DT bindings documentation for Broadcom IPROC USB Device controller.
  UDC: Add Synopsys UDC Platform driver

 .../devicetree/bindings/usb/iproc-udc.txt  |   21 +
 drivers/usb/gadget/udc/Kconfig |   32 +
 drivers/usb/gadget/udc/Makefile|4 +-
 drivers/usb/gadget/udc/amd5536udc.c| 3413 
 drivers/usb/gadget/udc/amd5536udc.h|   58 +-
 drivers/usb/gadget/udc/amd5536udc_pci.c|  218 ++
 drivers/usb/gadget/udc/snps_udc_core.c | 3239 +++
 drivers/usb/gadget/udc/snps_udc_plat.c |  344 ++
 8 files changed, 3912 insertions(+), 3417 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/iproc-udc.txt
 delete mode 100644 drivers/usb/gadget/udc/amd5536udc.c
 create mode 100644 drivers/usb/gadget/udc/amd5536udc_pci.c
 create mode 10064

[PATCH v3 6/7] DT bindings documentation for Broadcom IPROC USB Device controller.

2017-03-28 Thread Raviteja Garimella
The device node is used for UDCs integrated into Broadcom's
iProc family of SoCs'. The UDC is based on Synopsys Designware
Cores AHB Subsystem USB Device Controller IP.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 Documentation/devicetree/bindings/usb/iproc-udc.txt | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/iproc-udc.txt

diff --git a/Documentation/devicetree/bindings/usb/iproc-udc.txt 
b/Documentation/devicetree/bindings/usb/iproc-udc.txt
new file mode 100644
index 000..272d7fa
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/iproc-udc.txt
@@ -0,0 +1,21 @@
+Broadcom IPROC USB Device controller.
+
+The device node is used for UDCs integrated into Broadcom's
+iProc family (Northstar2, Cygnus) of SoCs'. The UDC is based
+on Synopsys Designware Cores AHB Subsystem Device Controller
+IP.
+
+Required properties:
+ - compatible: Add the compatibility strings for supported platforms.
+   For Broadcom NS2 platform, add "brcm,ns2-udc","brcm,iproc-udc".
+   For Broadcom Cygnus platform, add "brcm,cygnus-udc", "brcm,iproc-udc".
+ - reg: Offset and length of UDC register set
+ - interrupts: description of interrupt line
+ - phys: phandle to phy node.
+
+Example:
+   udc_dwc: usb@664e {
+   compatible = "brcm,ns2-udc", "brcm,iproc-udc";
+   reg = <0x664e 0x2000>;
+   interrupts = ;
+   phys = <_phy>;
-- 
2.1.0



[PATCH v3 5/7] UDC: Use struct dma_pool instead of pci_pool

2017-03-28 Thread Raviteja Garimella
Using dma_pool instead of pci_pool will make snps_udc_core driver
to be compatible with non-pci platforms.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/amd5536udc.h| 4 ++--
 drivers/usb/gadget/udc/snps_udc_core.c | 8 
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index c252457..91aae23 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -551,8 +551,8 @@ struct udc {
u32 __iomem *txfifo;
 
/* DMA desc pools */
-   struct pci_pool *data_requests;
-   struct pci_pool *stp_requests;
+   struct dma_pool *data_requests;
+   struct dma_pool *stp_requests;
 
/* device data */
unsigned long   phys_addr;
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 5f95a65..9d3861b 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -543,7 +543,7 @@ udc_alloc_request(struct usb_ep *usbep, gfp_t gfp)
 
if (ep->dma) {
/* ep0 in requests are allocated from data pool here */
-   dma_desc = pci_pool_alloc(ep->dev->data_requests, gfp,
+   dma_desc = dma_pool_alloc(ep->dev->data_requests, gfp,
>td_phys);
if (!dma_desc) {
kfree(req);
@@ -582,7 +582,7 @@ static int udc_free_dma_chain(struct udc *dev, struct 
udc_request *req)
td = phys_to_virt(td_last->next);
 
for (i = 1; i < req->chain_len; i++) {
-   pci_pool_free(dev->data_requests, td,
+   dma_pool_free(dev->data_requests, td,
  (dma_addr_t)td_last->next);
td_last = td;
td = phys_to_virt(td_last->next);
@@ -612,7 +612,7 @@ udc_free_request(struct usb_ep *usbep, struct usb_request 
*usbreq)
if (req->chain_len > 1)
udc_free_dma_chain(ep->dev, req);
 
-   pci_pool_free(ep->dev->data_requests, req->td_data,
+   dma_pool_free(ep->dev->data_requests, req->td_data,
req->td_phys);
}
kfree(req);
@@ -807,7 +807,7 @@ static int udc_create_dma_chain(
for (i = buf_len; i < bytes; i += buf_len) {
/* create or determine next desc. */
if (create_new_chain) {
-   td = pci_pool_alloc(ep->dev->data_requests,
+   td = dma_pool_alloc(ep->dev->data_requests,
gfp_flags, _addr);
if (!td)
return -ENOMEM;
-- 
2.1.0



[PATCH v3 3/7] UDC: make debug prints compatible with both pci and platform devices

2017-03-28 Thread Raviteja Garimella
This patch adds a struct device member to UDC data structure and
makes changes to the arguments of dev_err and dev_dbg calls so that
the debug prints work for both pci and platform devices.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/amd5536udc.h |  4 +++-
 drivers/usb/gadget/udc/amd5536udc_pci.c |  1 +
 drivers/usb/gadget/udc/snps_udc_core.c  | 28 ++--
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index bd2a18e..c252457 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -563,6 +563,8 @@ struct udc {
u16 cur_config;
u16 cur_intf;
u16 cur_alt;
+
+   struct device   *dev;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -639,7 +641,7 @@ MODULE_PARM_DESC(use_fullspeed, "true for fullspeed only");
 
 /* debug macros */
 
-#define DBG(udc , args...) dev_dbg(&(udc)->pdev->dev, args)
+#define DBG(udc , args...) dev_dbg(udc->dev, args)
 
 #ifdef UDC_VERBOSE
 #define VDBG   DBG
diff --git a/drivers/usb/gadget/udc/amd5536udc_pci.c 
b/drivers/usb/gadget/udc/amd5536udc_pci.c
index 2a2d0a9..57a13f0 100644
--- a/drivers/usb/gadget/udc/amd5536udc_pci.c
+++ b/drivers/usb/gadget/udc/amd5536udc_pci.c
@@ -168,6 +168,7 @@ static int udc_pci_probe(
dev->phys_addr = resource;
dev->irq = pdev->irq;
dev->pdev = pdev;
+   dev->dev = >dev;
 
/* general probing */
if (udc_probe(dev)) {
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 72f3c8f..c778d51 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -209,18 +209,18 @@ static void print_regs(struct udc *dev)
if (use_dma && use_dma_ppb && !use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBNDU (packet per buffer "
"WITHOUT desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBNDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBNDU");
} else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBDU (packet per buffer "
"WITH desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBDU");
}
if (use_dma && use_dma_bufferfill_mode) {
DBG(dev, "DMA mode   = BF (buffer fill mode)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "BF");
+   dev_info(dev->dev, "DMA mode (%s)\n", "BF");
}
if (!use_dma)
-   dev_info(>pdev->dev, "FIFO mode\n");
+   dev_info(dev->dev, "FIFO mode\n");
DBG(dev, "---\n");
 }
 
@@ -1628,7 +1628,7 @@ static void udc_setup_endpoints(struct udc *dev)
 static void usb_connect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Connect\n");
+   dev_info(dev->dev, "USB Connect\n");
 
dev->connected = 1;
 
@@ -1646,7 +1646,7 @@ static void usb_connect(struct udc *dev)
 static void usb_disconnect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Disconnect\n");
+   dev_info(dev->dev, "USB Disconnect\n");
 
dev->connected = 0;
 
@@ -2110,7 +2110,7 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int 
ep_ix)
}
/* HE event ? */
if (tmp & AMD_BIT(UDC_EPSTS_HE)) {
-   dev_err(>pdev->dev, "HE ep%dout occurred\n", ep->num);
+   dev_err(dev->dev, "HE ep%dout occurred\n", ep->num);
 
/* clear HE */
writel(tmp | AMD_BIT(UDC_EPSTS_HE), >regs->sts);
@@ -2309,7 +2309,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int 
ep_ix)
if (use_dma) {
/* BNA ? */
if (epsts & AMD_BIT(UDC_EPSTS_BNA)) {
-   dev_err(>pdev->dev,
+   dev_err(dev->dev,
"BNA ep%din occurred - DESPTR = %08lx\n",
ep->num,
(unsigned long) readl(>regs->desptr

[PATCH v4 0/3] Support for USB DRD Phy driver for NS2

2017-03-28 Thread Raviteja Garimella
Changes in v4:
=
Remove references to edev->name in debug prints.


Changes in v3:
=
Remove unnecessary checks for poweron as suggested in review.

Changes in v2:
=
1. Initialize file operations .owner field with THIS_MODULE.
2. Remove unnecessary gpio example in DT bindings documentation.
   This is previously acked by Rob Herring <r...@kernel.org>

Introduction for PATCH v1:

This patch adds support for USB Dual Role Device Phy for Broadcom
Northstar2 SoC. Apart from the new phy driver, this patchset contains
changes to Kconfig, Makefile, and Device tree files.

This patchset is tested on Broadcom NS2 BCM958712K reference board.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: ns2_drdphy_v4

Raviteja Garimella (3):
  Add DT bindings documentation for NS2 USB DRD phy
  Broadcom USB DRD Phy driver for Northstar2
  DT nodes for Broadcom Northstar2 USB DRD Phy

 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   |  30 ++
 arch/arm64/boot/dts/broadcom/ns2.dtsi  |  14 +
 drivers/phy/Kconfig|  13 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c   | 567 +
 5 files changed, 625 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

-- 
2.1.0



[PATCH v4 1/3] Add DT bindings documentation for NS2 USB DRD phy

2017-03-28 Thread Raviteja Garimella
This patch adds documentation for NS2 DRD Phy driver DT bindings

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
Acked-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   | 30 ++
 1 file changed, 30 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt

diff --git a/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt 
b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
new file mode 100644
index 000..04f063a
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
@@ -0,0 +1,30 @@
+BROADCOM NORTHSTAR2 USB2 (DUAL ROLE DEVICE) PHY
+
+Required properties:
+ - compatible: brcm,ns2-drd-phy
+ - reg: offset and length of the NS2 PHY related registers.
+ - reg-names
+   The below registers must be provided.
+   icfg - for DRD ICFG configurations
+   rst-ctrl - for DRD IDM reset
+   crmu-ctrl - for CRMU core vdd, PHY and PHY PLL reset
+   usb2-strap - for port over current polarity reversal
+ - #phy-cells: Must be 0. No args required.
+ - vbus-gpios: vbus gpio binding
+ - id-gpios: id gpio binding
+
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+Example:
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   };
-- 
2.1.0



[PATCH v4 3/3] DT nodes for Broadcom Northstar2 USB DRD Phy

2017-03-28 Thread Raviteja Garimella
This patch adds device tree nodes for USB Dual Role Device Phy for
Broadcom's Northstar2 SoC.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 arch/arm64/boot/dts/broadcom/ns2.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm64/boot/dts/broadcom/ns2.dtsi 
b/arch/arm64/boot/dts/broadcom/ns2.dtsi
index 9f9e203..97c35c4 100644
--- a/arch/arm64/boot/dts/broadcom/ns2.dtsi
+++ b/arch/arm64/boot/dts/broadcom/ns2.dtsi
@@ -428,6 +428,20 @@
};
};
 
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   status = "disabled";
+   };
+
pwm: pwm@6601 {
compatible = "brcm,iproc-pwm";
reg = <0x6601 0x28>;
-- 
2.1.0



[PATCH v4 2/3] Broadcom USB DRD Phy driver for Northstar2

2017-03-28 Thread Raviteja Garimella
This is driver for USB DRD Phy used in Broadcom's Northstar2
SoC. The phy can be configured to be in Device mode or Host
mode based on the type of cable connected to the port. The
driver registers to  extcon framework to get appropriate
connect events for Host/Device cables connect/disconnect
states based on VBUS and ID interrupts.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/phy/Kconfig  |  13 +
 drivers/phy/Makefile |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c | 567 +++
 3 files changed, 581 insertions(+)
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index dc5277a..001bc33 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -487,6 +487,19 @@ config PHY_CYGNUS_PCIE
  Enable this to support the Broadcom Cygnus PCIe PHY.
  If unsure, say N.
 
+config PHY_NS2_USB_DRD
+   tristate "Broadcom Northstar2 USB DRD PHY support"
+   depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
+   select GENERIC_PHY
+   select EXTCON
+   default ARCH_BCM_IPROC
+   help
+ Enable this to support the Broadcom Northstar2 USB DRD PHY.
+ This driver initializes the PHY in either HOST or DEVICE mode.
+ The host or device configuration is read from device tree.
+
+ If unsure, say N.
+
 source "drivers/phy/tegra/Kconfig"
 
 config PHY_NS2_PCIE
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index e7b0feb..122eee6 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -59,6 +59,7 @@ obj-$(CONFIG_PHY_TUSB1210)+= phy-tusb1210.o
 obj-$(CONFIG_PHY_BRCM_SATA)+= phy-brcm-sata.o
 obj-$(CONFIG_PHY_PISTACHIO_USB)+= phy-pistachio-usb.o
 obj-$(CONFIG_PHY_CYGNUS_PCIE)  += phy-bcm-cygnus-pcie.o
+obj-$(CONFIG_PHY_NS2_USB_DRD)  += phy-bcm-ns2-usbdrd.o
 obj-$(CONFIG_ARCH_TEGRA) += tegra/
 obj-$(CONFIG_PHY_NS2_PCIE) += phy-bcm-ns2-pcie.o
 obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o
diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c b/drivers/phy/phy-bcm-ns2-usbdrd.c
new file mode 100644
index 000..f41763f
--- /dev/null
+++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
@@ -0,0 +1,567 @@
+/*
+ * Copyright (C) 2016 Broadcom
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ICFG_DRD_AFE   0x0
+#define ICFG_MISC_STAT 0x18
+#define ICFG_DRD_P0CTL 0x1C
+#define ICFG_STRAP_CTRL0x20
+#define ICFG_FSM_CTRL  0x24
+
+#define IDM_RST_BITBIT(0)
+#define AFE_CORERDY_VDDC   BIT(18)
+#define PHY_PLL_RESETB BIT(15)
+#define PHY_RESETB BIT(14)
+#define PHY_PLL_LOCK   BIT(0)
+
+#define DRD_DEV_MODE   BIT(20)
+#define OHCI_OVRCUR_POLBIT(11)
+#define ICFG_OFF_MODE  BIT(6)
+#define PLL_LOCK_RETRY 1000
+
+#define EVT_DEVICE 0
+#define EVT_HOST   1
+#define EVT_IDLE   2
+
+#define DRD_HOST_MODE  (BIT(2) | BIT(3))
+#define DRD_DEVICE_MODE(BIT(4) | BIT(5))
+#define DRD_HOST_VAL   0x803
+#define DRD_DEV_VAL0x807
+#define GPIO_DELAY 20
+#define PHY_WQ_DELAY   msecs_to_jiffies(600)
+
+struct ns2_phy_data;
+struct ns2_phy_driver {
+   void __iomem *icfgdrd_regs;
+   void __iomem *idmdrd_rst_ctrl;
+   void __iomem *crmu_usb2_ctrl;
+   void __iomem *usb2h_strap_reg;
+   spinlock_t lock; /* spin lock for phy driver */
+   struct ns2_phy_data *data;
+   struct extcon_specific_cable_nb extcon_dev;
+   struct extcon_specific_cable_nb extcon_host;
+   struct notifier_block host_nb;
+   struct notifier_block dev_nb;
+   struct delayed_work conn_work;
+   struct extcon_dev *edev;
+   struct gpio_desc *vbus_gpiod;
+   struct gpio_desc *id_gpiod;
+   int id_irq;
+   int vbus_irq;
+   unsigned long debounce_jiffies;
+   struct delayed_work wq_extcon;
+};
+
+struct ns2_phy_data {
+   struct ns2_phy_driver *driver;
+   struct phy *phy;
+   int new_state;
+};
+
+static const unsigned int usb_extcon_cable[] = {
+   EXTCON_USB,
+   EXTCON_USB_HOST,
+   EXTCON_NONE,
+};
+
+static inline

[PATCH v3 1/7] UDC: Split the driver into amd (pci) and Synopsys core IP driver

2017-03-28 Thread Raviteja Garimella
This patch splits the amd5536udc driver into two -- one that does
pci device registration and the other file that does the rest of
the driver tasks like the gadget/ep ops etc for Synopsys UDC.

This way of splitting helps in exporting core driver symbols which
can be used by any other platform/pci driver that is written for
the same Synopsys USB device controller.

The current patch also includes a change in the Kconfig and Makefile.
A new config option USB_SNP_CORE will be selected automatically when
any one of the platform or pci driver for the same UDC is selected.

Main changes:
- amd5536udc_pci.c: PCI device registration is moved to this file.

- amd5536udc.c:
  This file does rest of the core UDC fucntionality.
  9 symbols are exported so as to be used by amd5536udc_pci.c.
  Module parameter definitions are moved to header file.

- amd5536udc.h:
  Function declarations, module parameters definitions and few common
  header file includes are added to this file

- Kconfig:
  New USB_SNP_CORE option is added which will be auto selected when
  any pci or platform driver config option for the UDC is chosen.

- Makefile:
  Compiles the core and pci files separately.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/Kconfig  |  18 +++
 drivers/usb/gadget/udc/Makefile |   3 +-
 drivers/usb/gadget/udc/amd5536udc.c | 238 
 drivers/usb/gadget/udc/amd5536udc.h |  36 +
 drivers/usb/gadget/udc/amd5536udc_pci.c | 217 +
 5 files changed, 297 insertions(+), 215 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/amd5536udc_pci.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 4b69f28..2cee076 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -253,6 +253,20 @@ config USB_MV_U3D
  MARVELL PXA2128 Processor series include a super speed USB3.0 device
  controller, which support super speed USB peripheral.
 
+config USB_SNP_CORE
+   depends on USB_AMD5536UDC
+   tristate
+   help
+ This enables core driver support for Synopsys USB 2.0 Device
+ controller.
+
+ This will be enabled when PCI or Platform driver for this UDC is
+ selected. Currently, this will be enabled by USB_SNP_UDC_PLAT or
+ USB_AMD5536UDC options.
+
+ This IP is different to the High Speed OTG IP that can be enabled
+ by selecting USB_DWC2 or USB_DWC3 options.
+
 #
 # Controllers available in both integrated and discrete versions
 #
@@ -278,6 +292,7 @@ source "drivers/usb/gadget/udc/bdc/Kconfig"
 config USB_AMD5536UDC
tristate "AMD5536 UDC"
depends on PCI
+   select USB_SNP_CORE
help
   The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge.
   It is a USB Highspeed DMA capable USB device controller. Beside ep0
@@ -285,6 +300,9 @@ config USB_AMD5536UDC
   The UDC port supports OTG operation, and may be used as a host port
   if it's not being used to implement peripheral or OTG roles.
 
+  This UDC is based on Synopsys USB device controller IP and selects
+  CONFIG_USB_SNP_CORE option to build the core driver.
+
   Say "y" to link the driver statically, or "m" to build a
   dynamically linked module called "amd5536udc" and force all
   gadget drivers to also be dynamically linked.
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 98e74ed..626e1f1 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -10,7 +10,8 @@ obj-$(CONFIG_USB_GADGET)  += udc-core.o
 obj-$(CONFIG_USB_DUMMY_HCD)+= dummy_hcd.o
 obj-$(CONFIG_USB_NET2272)  += net2272.o
 obj-$(CONFIG_USB_NET2280)  += net2280.o
-obj-$(CONFIG_USB_AMD5536UDC)   += amd5536udc.o
+obj-$(CONFIG_USB_SNP_CORE) += amd5536udc.o
+obj-$(CONFIG_USB_AMD5536UDC)   += amd5536udc_pci.o
 obj-$(CONFIG_USB_PXA25X)   += pxa25x_udc.o
 obj-$(CONFIG_USB_PXA27X)   += pxa27x_udc.o
 obj-$(CONFIG_USB_GOKU) += goku_udc.o
diff --git a/drivers/usb/gadget/udc/amd5536udc.c 
b/drivers/usb/gadget/udc/amd5536udc.c
index ea03ca7..72f3c8f 100644
--- a/drivers/usb/gadget/udc/amd5536udc.c
+++ b/drivers/usb/gadget/udc/amd5536udc.c
@@ -11,27 +11,15 @@
  */
 
 /*
- * The AMD5536 UDC is part of the x86 southbridge AMD Geode CS5536.
- * It is a USB Highspeed DMA capable USB device controller. Beside ep0 it
- * provides 4 IN and 4 OUT endpoints (bulk or interrupt type).
- *
- * Make sure that UDC is assigned to port 4 by BIOS settings (port can also
- * be used as host port) and UOC bits PAD_EN and APU are set (should be done
- * by BIOS init).
- *
- * UDC DMA requires 32-bit aligned buffers so DMA with gadget ether does not
- * work without updating NET_IP_ALIGN. Or PIO mode (module param "

[PATCH v3 4/7] UDC: Provide correct arguments for 'dma_pool_create'

2017-03-28 Thread Raviteja Garimella
Change the argument from NULL to a struct device for the
dma_pool_create call during dma init.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/snps_udc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index c778d51..5f95a65 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -3101,7 +3101,7 @@ int init_dma_pools(struct udc *dev)
}
 
/* DMA setup */
-   dev->data_requests = dma_pool_create("data_requests", NULL,
+   dev->data_requests = dma_pool_create("data_requests", dev->dev,
sizeof(struct udc_data_dma), 0, 0);
if (!dev->data_requests) {
DBG(dev, "can't get request data pool\n");
@@ -3112,7 +3112,7 @@ int init_dma_pools(struct udc *dev)
dev->ep[UDC_EP0IN_IX].dma = >regs->ctl;
 
/* dma desc for setup data */
-   dev->stp_requests = dma_pool_create("setup requests", NULL,
+   dev->stp_requests = dma_pool_create("setup requests", dev->dev,
sizeof(struct udc_stp_dma), 0, 0);
if (!dev->stp_requests) {
DBG(dev, "can't get stp request pool\n");
-- 
2.1.0



[RESEND PATCH v3 7/7] UDC: Add Synopsys UDC Platform driver

2017-03-31 Thread Raviteja Garimella
This patch adds platform driver support for Synopsys UDC.

A new driver file (snps_udc_plat.c) is created for this purpose
where the platform driver registration is done based on OF
node.

Currently, UDC integrated into Broadcom's iProc SoCs (Northstar2
and Cygnus) work with this driver.

New members are added to the UDC data structure for having platform
device support along with extcon and phy support.

Kconfig and Makefiles are modified to select platform driver for
compilation.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/Kconfig |  16 +-
 drivers/usb/gadget/udc/Makefile|   1 +
 drivers/usb/gadget/udc/amd5536udc.h|  14 ++
 drivers/usb/gadget/udc/snps_udc_core.c |  54 --
 drivers/usb/gadget/udc/snps_udc_plat.c | 344 +
 5 files changed, 409 insertions(+), 20 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/snps_udc_plat.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 707814d..b788caf 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -255,7 +255,7 @@ config USB_MV_U3D
  controller, which support super speed USB peripheral.
 
 config USB_SNP_CORE
-   depends on USB_AMD5536UDC
+   depends on (USB_AMD5536UDC || USB_SNP_UDC_PLAT)
tristate
help
  This enables core driver support for Synopsys USB 2.0 Device
@@ -268,6 +268,20 @@ config USB_SNP_CORE
  This IP is different to the High Speed OTG IP that can be enabled
  by selecting USB_DWC2 or USB_DWC3 options.
 
+config USB_SNP_UDC_PLAT
+   tristate "Synopsys USB 2.0 Device controller"
+   depends on (USB_GADGET && OF)
+   select USB_GADGET_DUALSPEED
+   select USB_SNP_CORE
+   default ARCH_BCM_IPROC
+   help
+ This adds Platform Device support for Synopsys Designware core
+ AHB subsystem USB2.0 Device Controller (UDC).
+
+ This driver works with UDCs integrated into Broadcom's Northstar2
+ and Cygnus SoCs.
+
+ If unsure, say N.
 #
 # Controllers available in both integrated and discrete versions
 #
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 4f4fd62..ea9e1c7 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -37,4 +37,5 @@ obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
 obj-$(CONFIG_USB_MV_U3D)   += mv_u3d_core.o
 obj-$(CONFIG_USB_GR_UDC)   += gr_udc.o
 obj-$(CONFIG_USB_GADGET_XILINX)+= udc-xilinx.o
+obj-$(CONFIG_USB_SNP_UDC_PLAT) += snps_udc_plat.o
 obj-$(CONFIG_USB_BDC_UDC)  += bdc/
diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index c252457..7884281 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -16,6 +16,7 @@
 /* debug control */
 /* #define UDC_VERBOSE */
 
+#include 
 #include 
 #include 
 
@@ -28,6 +29,9 @@
 #define UDC_HSA0_REV 1
 #define UDC_HSB1_REV 2
 
+/* Broadcom chip rev. */
+#define UDC_BCM_REV 10
+
 /*
  * SETUP usb commands
  * needed, because some SETUP's are handled in hw, but must be passed to
@@ -112,6 +116,7 @@
 #define UDC_DEVCTL_BRLEN_MASK  0x00ff
 #define UDC_DEVCTL_BRLEN_OFS   16
 
+#define UDC_DEVCTL_SRX_FLUSH   14
 #define UDC_DEVCTL_CSR_DONE13
 #define UDC_DEVCTL_DEVNAK  12
 #define UDC_DEVCTL_SD  10
@@ -564,7 +569,15 @@ struct udc {
u16 cur_intf;
u16 cur_alt;
 
+   /* for platform device and extcon support */
struct device   *dev;
+   struct phy  *udc_phy;
+   struct extcon_dev   *edev;
+   struct extcon_specific_cable_nb extcon_nb;
+   struct notifier_block   nb;
+   struct delayed_work drd_work;
+   struct workqueue_struct *drd_wq;
+   u32 conn_type;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -580,6 +593,7 @@ int udc_enable_dev_setup_interrupts(struct udc *dev);
 int udc_mask_unused_interrupts(struct udc *dev);
 irqreturn_t udc_irq(int irq, void *pdev);
 void gadget_release(struct device *pdev);
+void empty_req_queue(struct udc_ep *ep);
 void udc_basic_init(struct udc *dev);
 void free_dma_pools(struct udc *dev);
 int init_dma_pools(struct udc *dev);
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index d592f77..38a165d 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -41,7 +41,6 @@
 #include "amd5536udc.h"
 
 static void udc_tasklet_disconnect(unsigned long);
-static void empty_req_queue(struct udc_ep *);
 static void udc_setup_endpoints(struct udc 

[RESEND PATCH v3 6/7] DT bindings documentation for Broadcom IPROC USB Device controller.

2017-03-31 Thread Raviteja Garimella
The device node is used for UDCs integrated into Broadcom's
iProc family of SoCs'. The UDC is based on Synopsys Designware
Cores AHB Subsystem USB Device Controller IP.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 Documentation/devicetree/bindings/usb/iproc-udc.txt | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/iproc-udc.txt

diff --git a/Documentation/devicetree/bindings/usb/iproc-udc.txt 
b/Documentation/devicetree/bindings/usb/iproc-udc.txt
new file mode 100644
index 000..272d7fa
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/iproc-udc.txt
@@ -0,0 +1,21 @@
+Broadcom IPROC USB Device controller.
+
+The device node is used for UDCs integrated into Broadcom's
+iProc family (Northstar2, Cygnus) of SoCs'. The UDC is based
+on Synopsys Designware Cores AHB Subsystem Device Controller
+IP.
+
+Required properties:
+ - compatible: Add the compatibility strings for supported platforms.
+   For Broadcom NS2 platform, add "brcm,ns2-udc","brcm,iproc-udc".
+   For Broadcom Cygnus platform, add "brcm,cygnus-udc", "brcm,iproc-udc".
+ - reg: Offset and length of UDC register set
+ - interrupts: description of interrupt line
+ - phys: phandle to phy node.
+
+Example:
+   udc_dwc: usb@664e {
+   compatible = "brcm,ns2-udc", "brcm,iproc-udc";
+   reg = <0x664e 0x2000>;
+   interrupts = ;
+   phys = <_phy>;
-- 
2.1.0



[RESEND PATCH v3 5/7] UDC: Use struct dma_pool instead of pci_pool

2017-03-31 Thread Raviteja Garimella
Using dma_pool instead of pci_pool will make snps_udc_core driver
to be compatible with non-pci platforms.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/snps_udc_core.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 5ca8b7b..d592f77 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -543,7 +543,7 @@ udc_alloc_request(struct usb_ep *usbep, gfp_t gfp)
 
if (ep->dma) {
/* ep0 in requests are allocated from data pool here */
-   dma_desc = pci_pool_alloc(ep->dev->data_requests, gfp,
+   dma_desc = dma_pool_alloc(ep->dev->data_requests, gfp,
>td_phys);
if (!dma_desc) {
kfree(req);
@@ -582,7 +582,7 @@ static void udc_free_dma_chain(struct udc *dev, struct 
udc_request *req)
for (i = 1; i < req->chain_len; i++) {
td = phys_to_virt(addr);
addr_next = (dma_addr_t)td->next;
-   pci_pool_free(dev->data_requests, td, addr);
+   dma_pool_free(dev->data_requests, td, addr);
addr = addr_next;
}
 }
@@ -608,7 +608,7 @@ udc_free_request(struct usb_ep *usbep, struct usb_request 
*usbreq)
if (req->chain_len > 1)
udc_free_dma_chain(ep->dev, req);
 
-   pci_pool_free(ep->dev->data_requests, req->td_data,
+   dma_pool_free(ep->dev->data_requests, req->td_data,
req->td_phys);
}
kfree(req);
@@ -803,7 +803,7 @@ static int udc_create_dma_chain(
for (i = buf_len; i < bytes; i += buf_len) {
/* create or determine next desc. */
if (create_new_chain) {
-   td = pci_pool_alloc(ep->dev->data_requests,
+   td = dma_pool_alloc(ep->dev->data_requests,
gfp_flags, _addr);
if (!td)
return -ENOMEM;
-- 
2.1.0



[RESEND PATCH v3 3/7] UDC: make debug prints compatible with both pci and platform devices

2017-03-31 Thread Raviteja Garimella
This patch adds a struct device member to UDC data structure and
makes changes to the arguments of dev_err and dev_dbg calls so that
the debug prints work for both pci and platform devices.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/amd5536udc.h |  4 +++-
 drivers/usb/gadget/udc/amd5536udc_pci.c |  1 +
 drivers/usb/gadget/udc/snps_udc_core.c  | 28 ++--
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index bd2a18e..c252457 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -563,6 +563,8 @@ struct udc {
u16 cur_config;
u16 cur_intf;
u16 cur_alt;
+
+   struct device   *dev;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -639,7 +641,7 @@ MODULE_PARM_DESC(use_fullspeed, "true for fullspeed only");
 
 /* debug macros */
 
-#define DBG(udc , args...) dev_dbg(&(udc)->pdev->dev, args)
+#define DBG(udc , args...) dev_dbg(udc->dev, args)
 
 #ifdef UDC_VERBOSE
 #define VDBG   DBG
diff --git a/drivers/usb/gadget/udc/amd5536udc_pci.c 
b/drivers/usb/gadget/udc/amd5536udc_pci.c
index 2a2d0a9..57a13f0 100644
--- a/drivers/usb/gadget/udc/amd5536udc_pci.c
+++ b/drivers/usb/gadget/udc/amd5536udc_pci.c
@@ -168,6 +168,7 @@ static int udc_pci_probe(
dev->phys_addr = resource;
dev->irq = pdev->irq;
dev->pdev = pdev;
+   dev->dev = >dev;
 
/* general probing */
if (udc_probe(dev)) {
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 91d0f1a..a35fef9 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -209,18 +209,18 @@ static void print_regs(struct udc *dev)
if (use_dma && use_dma_ppb && !use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBNDU (packet per buffer "
"WITHOUT desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBNDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBNDU");
} else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBDU (packet per buffer "
"WITH desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBDU");
}
if (use_dma && use_dma_bufferfill_mode) {
DBG(dev, "DMA mode   = BF (buffer fill mode)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "BF");
+   dev_info(dev->dev, "DMA mode (%s)\n", "BF");
}
if (!use_dma)
-   dev_info(>pdev->dev, "FIFO mode\n");
+   dev_info(dev->dev, "FIFO mode\n");
DBG(dev, "---\n");
 }
 
@@ -1624,7 +1624,7 @@ static void udc_setup_endpoints(struct udc *dev)
 static void usb_connect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Connect\n");
+   dev_info(dev->dev, "USB Connect\n");
 
dev->connected = 1;
 
@@ -1642,7 +1642,7 @@ static void usb_connect(struct udc *dev)
 static void usb_disconnect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Disconnect\n");
+   dev_info(dev->dev, "USB Disconnect\n");
 
dev->connected = 0;
 
@@ -2106,7 +2106,7 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int 
ep_ix)
}
/* HE event ? */
if (tmp & AMD_BIT(UDC_EPSTS_HE)) {
-   dev_err(>pdev->dev, "HE ep%dout occurred\n", ep->num);
+   dev_err(dev->dev, "HE ep%dout occurred\n", ep->num);
 
/* clear HE */
writel(tmp | AMD_BIT(UDC_EPSTS_HE), >regs->sts);
@@ -2305,7 +2305,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int 
ep_ix)
if (use_dma) {
/* BNA ? */
if (epsts & AMD_BIT(UDC_EPSTS_BNA)) {
-   dev_err(>pdev->dev,
+   dev_err(dev->dev,
"BNA ep%din occurred - DESPTR = %08lx\n",
ep->num,
(unsigned long) readl(>regs->desptr

[RESEND PATCH v3 4/7] UDC: Provide correct arguments for 'dma_pool_create'

2017-03-31 Thread Raviteja Garimella
Change the argument from NULL to a struct device for the
dma_pool_create call during dma init.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/snps_udc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index a35fef9..5ca8b7b 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -3097,7 +3097,7 @@ int init_dma_pools(struct udc *dev)
}
 
/* DMA setup */
-   dev->data_requests = dma_pool_create("data_requests", NULL,
+   dev->data_requests = dma_pool_create("data_requests", dev->dev,
sizeof(struct udc_data_dma), 0, 0);
if (!dev->data_requests) {
DBG(dev, "can't get request data pool\n");
@@ -3108,7 +3108,7 @@ int init_dma_pools(struct udc *dev)
dev->ep[UDC_EP0IN_IX].dma = >regs->ctl;
 
/* dma desc for setup data */
-   dev->stp_requests = dma_pool_create("setup requests", NULL,
+   dev->stp_requests = dma_pool_create("setup requests", dev->dev,
sizeof(struct udc_stp_dma), 0, 0);
if (!dev->stp_requests) {
DBG(dev, "can't get stp request pool\n");
-- 
2.1.0



Re: [PATCH v3 2/7] UDC: Rename amd5536udc driver file based on IP

2017-03-31 Thread Raviteja Garimella
Hi Felipe,

On Fri, Mar 31, 2017 at 3:19 PM, Felipe Balbi <ba...@kernel.org> wrote:
>
> Hi,
>
> Raviteja Garimella <raviteja.garime...@broadcom.com> writes:
>
>> This patch renames the amd5536udc.c that has the core driver
>> functionality of Synopsys UDC to snps_udc_core.c
>>
>> The symbols exported here can be used by any UDC driver that uses
>> the same Synopsys IP.
>>
>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>
> unfortunately, this patch doesn't apply:
>
> Applying: UDC: Rename amd5536udc driver file based on IP
> error: corrupt patch at line 235
> Patch failed at 0001 UDC: Rename amd5536udc driver file based on IP
> The copy of the patch that failed is found in: .git/rebase-apply/patch
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".
>
> Can you rebase on testing/next and resend?

I rebased my patches against testing/next branch, resolved the merge conflicts.
Just resent the patches 2/7 to 7/7. Please use them. I verified they are getting
applied without issues now.

Thanks,
Ravi
>
> --
> balbi


[RESEND PATCH v3 0/7] Platform driver support for 'amd5536udc' driver

2017-03-31 Thread Raviteja Garimella
Resending PATCH v3 after rebasing with testing/next branch in 
Felipe Balbi's git tree. Resolved few merge conflicts. 
Tested applying all patches. Patch 1/7 can be ignored since it's
already applied.

Changes in PATCH v3:
===
1. Updated bindings documentation and platform driver to add
   "brcm,iproc-udc" compatibility string.

2. Added a patch to replace references of struct pci_pool with
   struct dma_pool so that it is compatibile with non-pci drivers.

Changes in PATCH v2:
===
1. Updated bindings documentation:
   -- compatibility string for each supported SoC
   -- removed extcon node
   -- rename the file name to just iproc-udc.txt

2. Modified comptability strings in platform driver file
   to reflect the change made in 1.

3 Kconfig
   -- Resolved warnings shown by kbuild-test-robot  

The changes are being submitted as PATCH this time. Below are the
details of main changes with respect to previous RFC versions.

Changes in PATCH v1:
===
Patch 1/6 now splits the driver into amd5536udc_pci_.c (which
contains only the PCI device registration part), and amd5536udc.c
will still be driver that does the rest of UDC driver functionality.

Patch 2/6 renames amd5536udc.c to snps_udc_core.c.

The DT compatibilty string is changed to "brcm,iproc-snps-udc"
as per review comments for RFCv2. The driver and bindings
documentation is modified to reflect this.

This is RFC for the changes made as per the review comments made for
the previous version. I would like to know  if this approach (the way
the driver is split and the naming and all)looks good to be submitted.


Changes in RFC v2:
=
1. Split the driver into platform/pci specific drivers with a core driver
   file that handles the common driver routines that are exported.

2. Split the driver into number of patches as suggested in previous
   review comments.

3. Added the devicetree bindings documentation for Synopsys platform
   driver.

Introduction (RFC v1):
=
This patch adds platform device support to the existing 'amd5536udc'
driver.

The UDC is based on Synopsys Designware core USB (2.0) Device controller
IP.

The driver so far supports UDCs that are a part of AMD southbridge
and is connected through PCI bus.

The same driver can be used with UDCs that are integrated into SoCs
like Broadcom's Northstar2/Cygnus platforms by adding platform device
suooprt.

This patch contains all the changes that were required to get the driver
functional on Broadcom's Northstar2 platform. 

This is a request for comments from maintainers/others regarding approach
on whether to have 2 different drivers (one each for AMD and Broadcom)
with a common library (3 files in total), or have a single driver like
it's done in this patch and have the driver filename changed to some
common name based on ther underlying IP, like snps_udc.c.

Below are the main changes done:

1. Added OF based platform device registration -- so that the driver gets
   probed based on the device tree entry. Like wise, remove routine and
   platform PM ops are supported.

2. Modified debug prints to be compatible with both pci and platform
   devices.

3. Added members to 'struct udc' in header file for extcon and phy support.
   This is required if the UDC is connected to a Dual Role Device Phy
   where the Phy can be configured to be in Device mode or Host mode based
   on the type of external cable that is connected to the port.
 
4. Added checks in udc connect/disconnect routines so as to return if the
   routine is already called.

5. Modified the arguments passed to dma_pool_create routine -- which
   expects struct device, whereas NULL is passed in the existing version.
 
6. Kconfig changes are done so that the driver now depends on either of
   CONFIG_OF or CONFIG_PCI. More description about the Synopsys IP is
   provided.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: snps_udc_v3

Raviteja Garimella (7):
  usb: gadget: udc: amd5536: split core and PCI layer
  UDC: Rename amd5536udc driver file based on IP
  UDC: make debug prints compatible with both pci and platform devices
  UDC: Provide correct arguments for 'dma_pool_create'
  UDC: Use struct dma_pool instead of pci_pool
  DT bindings documentation for Broadcom IPROC USB Device controller.
  UDC: Add Synopsys UDC Platform driver

 .../devicetree/bindings/usb/iproc-udc.txt  |   21 +
 drivers/usb/gadget/udc/Kconfig |   32 +
 drivers/usb/gadget/udc/Makefile|4 +-
 drivers/usb/gadget/udc/amd5536udc.c| 3409 
 drivers/usb/gadget/udc/amd5536udc.h|   54 +-
 drivers/usb/gadget/udc/amd5536udc_pci.c|  218 ++
 drivers/usb/gadget/udc/snps_udc_core.c | 3235 +++
 drivers/usb/gadget/udc/snps_udc_plat.c |  344 ++
 8 files changed, 3906 insertions(+), 3411 deletions(-)
 create mode 

[PATCH v5 0/3] Support for USB DRD Phy driver for NS2

2017-04-12 Thread Raviteja Garimella
Changes in v5:
=
Removed references to phy_ops in the same driver by connect_work
event handler to change the phy modes.

To support dynamically changing the mode of the phy, it does
not require doing a phy reset/programming of PHY PLL. Changes
are made to the connect_work routine to just program the required
register bits to achieve this purpose.


Changes in v4:
=
Remove references to edev->name in debug prints.

Changes in v3:
=
Remove unnecessary checks for poweron as suggested in review.

Changes in v2:
=
1. Initialize file operations .owner field with THIS_MODULE.
2. Remove unnecessary gpio example in DT bindings documentation.
   This is previously acked by Rob Herring <r...@kernel.org>

Introduction for PATCH v1:

This patch adds support for USB Dual Role Device Phy for Broadcom
Northstar2 SoC. Apart from the new phy driver, this patchset contains
changes to Kconfig, Makefile, and Device tree files.

This patchset is tested on Broadcom NS2 BCM958712K reference board.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: ns2_drdphy_v5

Raviteja Garimella (3):
  dt-bindings:phy:Add DT bindings documentation for NS2 USB DRD phy
  phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2
  DT nodes for Broadcom Northstar2 USB DRD Phy

 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   |  30 ++
 arch/arm64/boot/dts/broadcom/ns2.dtsi  |  14 +
 drivers/phy/Kconfig|  13 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c   | 595 +
 5 files changed, 653 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

-- 
2.1.0



Re: [PATCH v4 2/3] Broadcom USB DRD Phy driver for Northstar2

2017-04-12 Thread Raviteja Garimella
Hi,

On Mon, Apr 10, 2017 at 2:07 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
> Hi,
>
> On Wednesday 05 April 2017 07:40 PM, Raviteja Garimella wrote:
>> Hi Kishon,
>>
>> On Wed, Apr 5, 2017 at 7:04 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
>>> Hi Ravi,
>>>
>>> On Wednesday 05 April 2017 06:30 PM, Raviteja Garimella wrote:
>>>> Hi Kishon,
>>>>
>>>> On Wed, Apr 5, 2017 at 4:30 PM, Kishon Vijay Abraham I <kis...@ti.com> 
>>>> wrote:
>>>>> Hi,
>>>>>
>>>>> On Tuesday 28 March 2017 05:57 PM, Raviteja Garimella wrote:
>>>>>> This is driver for USB DRD Phy used in Broadcom's Northstar2
>>>>>> SoC. The phy can be configured to be in Device mode or Host
>>>>>> mode based on the type of cable connected to the port. The
>>>>>> driver registers to  extcon framework to get appropriate
>>>>>> connect events for Host/Device cables connect/disconnect
>>>>>> states based on VBUS and ID interrupts.
>>>>>
>>>>> $patch should be phy: phy-bcm-ns2-usbdrd: USB DRD Phy driver for Broadcoms
>>>>> Northstar2.
>>>>>
>>>>
>>>> Will do.
>>>>
>>>>> Sorry for not letting you know this earlier. But I feel the design of the
>>>>> driver should be changed. Extcon shouldn't be used here. The extcon
>>>>> notifications should be sent to the consumer driver and the consumer 
>>>>> driver
>>>>> should be responsible for invoking the phy ops.
>>>>>
>>>>
>>>> The consumer drivers here would be a UDC driver (USB device
>>>> controller), EHCI and OHCI host controller drivers.
>>>> I was already suggested in UDC driver review to deal with extcon in Phy 
>>>> driver.
>>>>
>>>> This phy connects to 2 host controllers, and one device controller.
>>>> That's the design in Broadcom Northstar2
>>>> platform. The values of the VBUS and ID pins of this port are
>>>> determined based on the type of the cable (device cable
>>>> or host cable). And. phy has to be configured accordingly.
>>>>
>>>>> The phy ops being invoked during extcon events doesn't look right.
>>>>
>>>> Could you please elaborate on the concern, so that we can think of
>>>> mitigating those issues in this driver?
>>>> Since we are dealing with phy init/shutdown in this driver itself, are
>>>> you okay with moving the extcon handling code
>>>> out of phy ops ?
>>>
>>> yeah, For e.g., ns2_drd_phy_init is part of phy_ops and is being invoked 
>>> from
>>> extcon events too. Can a phy which is initialized by a phy consumer (say 
>>> your
>>> UDC invokes phy_init) can be shutdown by an extcon event?
>>>
>>> Maybe a clear explanation of when phy_ops here will be invoked and when it 
>>> will
>>> set using extcon events might help.
>>>
>>
>> Say, we have a USB pendrive which is connected to the DRD port through
>> a host cable.
>> Now the PHY will be initialized to be in host mode.
>> When the pendrive is unplugged, and we now connect the NS2 device to
>> some linux PC,
>> now the PHY has to be shutdown, and re-initialized to be in Device mode.
>>
>> On unplug event, it is set neither to Host nor Device mode (basically
>> shutdown). Next time which ever cable is connected, the PHY is
>> initialized to the respective
>> mode.
>>
>> Please let me know if it's fine to do these initializations outside
>> phy ops, because those will
>> be irrelevant for phy consumers (the controllers) as it's anyways
>> dealt in the phy driver through
>> extcon.
>
> Yes. We shouldn't add phy_ops just for the sake of it. I think this should be
> made as a purely extcon driver (though there are a couple of bits that looks
> like initializing PHY) and keep it in drivers/extcon.
>

Actually phy_ops would be required when we want phy to be shutdown/init
during power management, where USB controllers would call them.

I reworked on this driver to address the concerns raised here. Please check
PATCH v5 that I will submit shortly.
If we want to dynamically change the mode of PHY either to be in host mode
or device mode or idle, we don't have to do a full PHY init/power on (that
earlier required doing a PHY PLL lock and other resets). We just have to
program couple of register bits that are dedicated for this purpose.
I made those changes, now we don't have to call phy ops in the driver.
Phy_ops will be called only by the consumer drivers.

Thanks,
Ravi

> Thanks
> Kishon


[PATCH v5 1/3] dt-bindings:phy:Add DT bindings documentation for NS2 USB DRD phy

2017-04-12 Thread Raviteja Garimella
This patch adds documentation for NS2 DRD Phy driver DT bindings

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
Acked-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   | 30 ++
 1 file changed, 30 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt

diff --git a/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt 
b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
new file mode 100644
index 000..04f063a
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
@@ -0,0 +1,30 @@
+BROADCOM NORTHSTAR2 USB2 (DUAL ROLE DEVICE) PHY
+
+Required properties:
+ - compatible: brcm,ns2-drd-phy
+ - reg: offset and length of the NS2 PHY related registers.
+ - reg-names
+   The below registers must be provided.
+   icfg - for DRD ICFG configurations
+   rst-ctrl - for DRD IDM reset
+   crmu-ctrl - for CRMU core vdd, PHY and PHY PLL reset
+   usb2-strap - for port over current polarity reversal
+ - #phy-cells: Must be 0. No args required.
+ - vbus-gpios: vbus gpio binding
+ - id-gpios: id gpio binding
+
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+Example:
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   };
-- 
2.1.0



[PATCH v5 2/3] phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2

2017-04-12 Thread Raviteja Garimella
This is driver for USB DRD Phy used in Broadcom's Northstar2
SoC. The phy can be configured to be in Device mode or Host
mode based on the type of cable connected to the port. The
driver registers to  extcon framework to get appropriate
connect events for Host/Device cables connect/disconnect
states based on VBUS and ID interrupts.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/phy/Kconfig  |  13 +
 drivers/phy/Makefile |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c | 595 +++
 3 files changed, 609 insertions(+)
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 005cadb..c9de9a9 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -488,6 +488,19 @@ config PHY_CYGNUS_PCIE
  Enable this to support the Broadcom Cygnus PCIe PHY.
  If unsure, say N.
 
+config PHY_NS2_USB_DRD
+   tristate "Broadcom Northstar2 USB DRD PHY support"
+   depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
+   select GENERIC_PHY
+   select EXTCON
+   default ARCH_BCM_IPROC
+   help
+ Enable this to support the Broadcom Northstar2 USB DRD PHY.
+ This driver initializes the PHY in either HOST or DEVICE mode.
+ The host or device configuration is read from device tree.
+
+ If unsure, say N.
+
 source "drivers/phy/tegra/Kconfig"
 
 config PHY_NS2_PCIE
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index dd8f3b5..9285f88 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -59,6 +59,7 @@ obj-$(CONFIG_PHY_TUSB1210)+= phy-tusb1210.o
 obj-$(CONFIG_PHY_BRCM_SATA)+= phy-brcm-sata.o
 obj-$(CONFIG_PHY_PISTACHIO_USB)+= phy-pistachio-usb.o
 obj-$(CONFIG_PHY_CYGNUS_PCIE)  += phy-bcm-cygnus-pcie.o
+obj-$(CONFIG_PHY_NS2_USB_DRD)  += phy-bcm-ns2-usbdrd.o
 obj-$(CONFIG_ARCH_TEGRA) += tegra/
 obj-$(CONFIG_PHY_NS2_PCIE) += phy-bcm-ns2-pcie.o
 obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o
diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c b/drivers/phy/phy-bcm-ns2-usbdrd.c
new file mode 100644
index 000..92b68b1
--- /dev/null
+++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
@@ -0,0 +1,595 @@
+/*
+ * Copyright (C) 2016 Broadcom
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ICFG_DRD_AFE   0x0
+#define ICFG_MISC_STAT 0x18
+#define ICFG_DRD_P0CTL 0x1C
+#define ICFG_STRAP_CTRL0x20
+#define ICFG_FSM_CTRL  0x24
+
+#define ICFG_DEV_BIT   BIT(2)
+#define IDM_RST_BITBIT(0)
+#define AFE_CORERDY_VDDC   BIT(18)
+#define PHY_PLL_RESETB BIT(15)
+#define PHY_RESETB BIT(14)
+#define PHY_PLL_LOCK   BIT(0)
+
+#define DRD_DEV_MODE   BIT(20)
+#define OHCI_OVRCUR_POLBIT(11)
+#define ICFG_OFF_MODE  BIT(6)
+#define PLL_LOCK_RETRY 1000
+
+#define EVT_DEVICE 0
+#define EVT_HOST   1
+#define EVT_IDLE   2
+
+#define DRD_HOST_MODE  (BIT(2) | BIT(3))
+#define DRD_DEVICE_MODE(BIT(4) | BIT(5))
+#define DRD_HOST_VAL   0x803
+#define DRD_DEV_VAL0x807
+#define GPIO_DELAY 20
+#define PHY_WQ_DELAY   msecs_to_jiffies(600)
+
+struct ns2_phy_data;
+struct ns2_phy_driver {
+   void __iomem *icfgdrd_regs;
+   void __iomem *idmdrd_rst_ctrl;
+   void __iomem *crmu_usb2_ctrl;
+   void __iomem *usb2h_strap_reg;
+   spinlock_t lock; /* spin lock for phy driver */
+   struct ns2_phy_data *data;
+   struct extcon_specific_cable_nb extcon_dev;
+   struct extcon_specific_cable_nb extcon_host;
+   struct notifier_block host_nb;
+   struct notifier_block dev_nb;
+   struct delayed_work conn_work;
+   struct extcon_dev *edev;
+   struct gpio_desc *vbus_gpiod;
+   struct gpio_desc *id_gpiod;
+   int id_irq;
+   int vbus_irq;
+   unsigned long debounce_jiffies;
+   struct delayed_work wq_extcon;
+};
+
+struct ns2_phy_data {
+   struct ns2_phy_driver *driver;
+   struct phy *phy;
+   int new_state;
+};
+
+static const unsigned int usb_extcon_cable[] = {
+   EXTCON_USB,
+   EXTCON_USB_HOST,
+   EXTCON_NONE,
+};
+

[PATCH v5 3/3] DT nodes for Broadcom Northstar2 USB DRD Phy

2017-04-12 Thread Raviteja Garimella
This patch adds device tree nodes for USB Dual Role Device Phy for
Broadcom's Northstar2 SoC.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 arch/arm64/boot/dts/broadcom/ns2.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm64/boot/dts/broadcom/ns2.dtsi 
b/arch/arm64/boot/dts/broadcom/ns2.dtsi
index bcb03fc..c71f330 100644
--- a/arch/arm64/boot/dts/broadcom/ns2.dtsi
+++ b/arch/arm64/boot/dts/broadcom/ns2.dtsi
@@ -436,6 +436,20 @@
};
};
 
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   status = "disabled";
+   };
+
pwm: pwm@6601 {
compatible = "brcm,iproc-pwm";
reg = <0x6601 0x28>;
-- 
2.1.0



Re: [PATCH v4 2/3] Broadcom USB DRD Phy driver for Northstar2

2017-04-05 Thread Raviteja Garimella
Hi Kishon,

On Wed, Apr 5, 2017 at 7:04 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
> Hi Ravi,
>
> On Wednesday 05 April 2017 06:30 PM, Raviteja Garimella wrote:
>> Hi Kishon,
>>
>> On Wed, Apr 5, 2017 at 4:30 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
>>> Hi,
>>>
>>> On Tuesday 28 March 2017 05:57 PM, Raviteja Garimella wrote:
>>>> This is driver for USB DRD Phy used in Broadcom's Northstar2
>>>> SoC. The phy can be configured to be in Device mode or Host
>>>> mode based on the type of cable connected to the port. The
>>>> driver registers to  extcon framework to get appropriate
>>>> connect events for Host/Device cables connect/disconnect
>>>> states based on VBUS and ID interrupts.
>>>
>>> $patch should be phy: phy-bcm-ns2-usbdrd: USB DRD Phy driver for Broadcoms
>>> Northstar2.
>>>
>>
>> Will do.
>>
>>> Sorry for not letting you know this earlier. But I feel the design of the
>>> driver should be changed. Extcon shouldn't be used here. The extcon
>>> notifications should be sent to the consumer driver and the consumer driver
>>> should be responsible for invoking the phy ops.
>>>
>>
>> The consumer drivers here would be a UDC driver (USB device
>> controller), EHCI and OHCI host controller drivers.
>> I was already suggested in UDC driver review to deal with extcon in Phy 
>> driver.
>>
>> This phy connects to 2 host controllers, and one device controller.
>> That's the design in Broadcom Northstar2
>> platform. The values of the VBUS and ID pins of this port are
>> determined based on the type of the cable (device cable
>> or host cable). And. phy has to be configured accordingly.
>>
>>> The phy ops being invoked during extcon events doesn't look right.
>>
>> Could you please elaborate on the concern, so that we can think of
>> mitigating those issues in this driver?
>> Since we are dealing with phy init/shutdown in this driver itself, are
>> you okay with moving the extcon handling code
>> out of phy ops ?
>
> yeah, For e.g., ns2_drd_phy_init is part of phy_ops and is being invoked from
> extcon events too. Can a phy which is initialized by a phy consumer (say your
> UDC invokes phy_init) can be shutdown by an extcon event?
>
> Maybe a clear explanation of when phy_ops here will be invoked and when it 
> will
> set using extcon events might help.
>

Say, we have a USB pendrive which is connected to the DRD port through
a host cable.
Now the PHY will be initialized to be in host mode.
When the pendrive is unplugged, and we now connect the NS2 device to
some linux PC,
now the PHY has to be shutdown, and re-initialized to be in Device mode.

On unplug event, it is set neither to Host nor Device mode (basically
shutdown). Next time which ever cable is connected, the PHY is
initialized to the respective
mode.

Please let me know if it's fine to do these initializations outside
phy ops, because those will
be irrelevant for phy consumers (the controllers) as it's anyways
dealt in the phy driver through
extcon.

Thanks,
Ravi


> Thanks
> Kishon


Re: [PATCH v4 2/3] Broadcom USB DRD Phy driver for Northstar2

2017-04-10 Thread Raviteja Garimella
Hi,

On Mon, Apr 10, 2017 at 10:55 AM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
> Hi,
>
> On Wednesday 05 April 2017 07:40 PM, Raviteja Garimella wrote:
>> Hi Kishon,
>>
>> On Wed, Apr 5, 2017 at 7:04 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
>>> Hi Ravi,
>>>
>>> On Wednesday 05 April 2017 06:30 PM, Raviteja Garimella wrote:
>>>> Hi Kishon,
>>>>
>>>> On Wed, Apr 5, 2017 at 4:30 PM, Kishon Vijay Abraham I <kis...@ti.com> 
>>>> wrote:
>>>>> Hi,
>>>>>
>>>>> On Tuesday 28 March 2017 05:57 PM, Raviteja Garimella wrote:
>>>>>> This is driver for USB DRD Phy used in Broadcom's Northstar2
>>>>>> SoC. The phy can be configured to be in Device mode or Host
>>>>>> mode based on the type of cable connected to the port. The
>>>>>> driver registers to  extcon framework to get appropriate
>>>>>> connect events for Host/Device cables connect/disconnect
>>>>>> states based on VBUS and ID interrupts.
>>>>>
>>>>> $patch should be phy: phy-bcm-ns2-usbdrd: USB DRD Phy driver for Broadcoms
>>>>> Northstar2.
>>>>>
>>>>
>>>> Will do.
>>>>
>>>>> Sorry for not letting you know this earlier. But I feel the design of the
>>>>> driver should be changed. Extcon shouldn't be used here. The extcon
>>>>> notifications should be sent to the consumer driver and the consumer 
>>>>> driver
>>>>> should be responsible for invoking the phy ops.
>>>>>
>>>>
>>>> The consumer drivers here would be a UDC driver (USB device
>>>> controller), EHCI and OHCI host controller drivers.
>>>> I was already suggested in UDC driver review to deal with extcon in Phy 
>>>> driver.
>>>>
>>>> This phy connects to 2 host controllers, and one device controller.
>>>> That's the design in Broadcom Northstar2
>>>> platform. The values of the VBUS and ID pins of this port are
>>>> determined based on the type of the cable (device cable
>>>> or host cable). And. phy has to be configured accordingly.
>>>>
>>>>> The phy ops being invoked during extcon events doesn't look right.
>>>>
>>>> Could you please elaborate on the concern, so that we can think of
>>>> mitigating those issues in this driver?
>>>> Since we are dealing with phy init/shutdown in this driver itself, are
>>>> you okay with moving the extcon handling code
>>>> out of phy ops ?
>>>
>>> yeah, For e.g., ns2_drd_phy_init is part of phy_ops and is being invoked 
>>> from
>>> extcon events too. Can a phy which is initialized by a phy consumer (say 
>>> your
>>> UDC invokes phy_init) can be shutdown by an extcon event?
>>>
>>> Maybe a clear explanation of when phy_ops here will be invoked and when it 
>>> will
>>> set using extcon events might help.
>>>
>>
>> Say, we have a USB pendrive which is connected to the DRD port through
>> a host cable.
>> Now the PHY will be initialized to be in host mode.
>> When the pendrive is unplugged, and we now connect the NS2 device to
>> some linux PC,
>> now the PHY has to be shutdown, and re-initialized to be in Device mode.
>>
>> On unplug event, it is set neither to Host nor Device mode (basically
>> shutdown). Next time which ever cable is connected, the PHY is
>> initialized to the respective
>> mode.
>>
>> Please let me know if it's fine to do these initializations outside
>> phy ops, because those will
>> be irrelevant for phy consumers (the controllers) as it's anyways
>> dealt in the phy driver through
>> extcon.
>
> How does the consumer get to know whether they have to operate in host mode or
> device mode?
>
In NS2, we have host controllers and device controller (not OTG/other
that can switch
between host and device mode). It's only phy that can be in host/device mode.
Since both Host Controllers and Device Controller are connected to the same PHY,
it is based on the extcon logic (the type of cable connected) that PHY
will be in one
of the modes host/device and the respective controller will operate.

> Thanks
> Kishon


Re: [PATCH v4 2/3] Broadcom USB DRD Phy driver for Northstar2

2017-04-10 Thread Raviteja Garimella
Hi

On Mon, Apr 10, 2017 at 1:57 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
> Hi,
>
> On Monday 10 April 2017 12:57 PM, Raviteja Garimella wrote:
>> Hi,
>>
>> On Mon, Apr 10, 2017 at 10:55 AM, Kishon Vijay Abraham I <kis...@ti.com> 
>> wrote:
>>> Hi,
>>>
>>> On Wednesday 05 April 2017 07:40 PM, Raviteja Garimella wrote:
>>>> Hi Kishon,
>>>>
>>>> On Wed, Apr 5, 2017 at 7:04 PM, Kishon Vijay Abraham I <kis...@ti.com> 
>>>> wrote:
>>>>> Hi Ravi,
>>>>>
>>>>> On Wednesday 05 April 2017 06:30 PM, Raviteja Garimella wrote:
>>>>>> Hi Kishon,
>>>>>>
>>>>>> On Wed, Apr 5, 2017 at 4:30 PM, Kishon Vijay Abraham I <kis...@ti.com> 
>>>>>> wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> On Tuesday 28 March 2017 05:57 PM, Raviteja Garimella wrote:
>>>>>>>> This is driver for USB DRD Phy used in Broadcom's Northstar2
>>>>>>>> SoC. The phy can be configured to be in Device mode or Host
>>>>>>>> mode based on the type of cable connected to the port. The
>>>>>>>> driver registers to  extcon framework to get appropriate
>>>>>>>> connect events for Host/Device cables connect/disconnect
>>>>>>>> states based on VBUS and ID interrupts.
>>>>>>>
>>>>>>> $patch should be phy: phy-bcm-ns2-usbdrd: USB DRD Phy driver for 
>>>>>>> Broadcoms
>>>>>>> Northstar2.
>>>>>>>
>>>>>>
>>>>>> Will do.
>>>>>>
>>>>>>> Sorry for not letting you know this earlier. But I feel the design of 
>>>>>>> the
>>>>>>> driver should be changed. Extcon shouldn't be used here. The extcon
>>>>>>> notifications should be sent to the consumer driver and the consumer 
>>>>>>> driver
>>>>>>> should be responsible for invoking the phy ops.
>>>>>>>
>>>>>>
>>>>>> The consumer drivers here would be a UDC driver (USB device
>>>>>> controller), EHCI and OHCI host controller drivers.
>>>>>> I was already suggested in UDC driver review to deal with extcon in Phy 
>>>>>> driver.
>>>>>>
>>>>>> This phy connects to 2 host controllers, and one device controller.
>>>>>> That's the design in Broadcom Northstar2
>>>>>> platform. The values of the VBUS and ID pins of this port are
>>>>>> determined based on the type of the cable (device cable
>>>>>> or host cable). And. phy has to be configured accordingly.
>>>>>>
>>>>>>> The phy ops being invoked during extcon events doesn't look right.
>>>>>>
>>>>>> Could you please elaborate on the concern, so that we can think of
>>>>>> mitigating those issues in this driver?
>>>>>> Since we are dealing with phy init/shutdown in this driver itself, are
>>>>>> you okay with moving the extcon handling code
>>>>>> out of phy ops ?
>>>>>
>>>>> yeah, For e.g., ns2_drd_phy_init is part of phy_ops and is being invoked 
>>>>> from
>>>>> extcon events too. Can a phy which is initialized by a phy consumer (say 
>>>>> your
>>>>> UDC invokes phy_init) can be shutdown by an extcon event?
>>>>>
>>>>> Maybe a clear explanation of when phy_ops here will be invoked and when 
>>>>> it will
>>>>> set using extcon events might help.
>>>>>
>>>>
>>>> Say, we have a USB pendrive which is connected to the DRD port through
>>>> a host cable.
>>>> Now the PHY will be initialized to be in host mode.
>>>> When the pendrive is unplugged, and we now connect the NS2 device to
>>>> some linux PC,
>>>> now the PHY has to be shutdown, and re-initialized to be in Device mode.
>>>>
>>>> On unplug event, it is set neither to Host nor Device mode (basically
>>>> shutdown). Next time which ever cable is connected, the PHY is
>>>> initialized to the respective
>>>> mode.
>>>>
>>>> Please let me know if it's fine to do these initializations outside
>>>> phy ops, because those will
>>>> be irrelevant for phy consumers (the controllers) as it's anyways
>>>> dealt in the phy driver through
>>>> extcon.
>>>
>>> How does the consumer get to know whether they have to operate in host mode 
>>> or
>>> device mode?
>>>
>> In NS2, we have host controllers and device controller (not OTG/other
>> that can switch
>> between host and device mode). It's only phy that can be in host/device mode.
>> Since both Host Controllers and Device Controller are connected to the same 
>> PHY,
>> it is based on the extcon logic (the type of cable connected) that PHY
>> will be in one
>> of the modes host/device and the respective controller will operate.
>
> So at a point of time either the host controller or the device controller will
> be active? and the PHY decides which of them should be active? Is that right?
>

Yes

Thanks,
Ravi

> Thanks
> Kishon


Re: [PATCH v4 2/3] Broadcom USB DRD Phy driver for Northstar2

2017-04-05 Thread Raviteja Garimella
Hi Kishon,

On Wed, Apr 5, 2017 at 4:30 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
> Hi,
>
> On Tuesday 28 March 2017 05:57 PM, Raviteja Garimella wrote:
>> This is driver for USB DRD Phy used in Broadcom's Northstar2
>> SoC. The phy can be configured to be in Device mode or Host
>> mode based on the type of cable connected to the port. The
>> driver registers to  extcon framework to get appropriate
>> connect events for Host/Device cables connect/disconnect
>> states based on VBUS and ID interrupts.
>
> $patch should be phy: phy-bcm-ns2-usbdrd: USB DRD Phy driver for Broadcoms
> Northstar2.
>

Will do.

> Sorry for not letting you know this earlier. But I feel the design of the
> driver should be changed. Extcon shouldn't be used here. The extcon
> notifications should be sent to the consumer driver and the consumer driver
> should be responsible for invoking the phy ops.
>

The consumer drivers here would be a UDC driver (USB device
controller), EHCI and OHCI host controller drivers.
I was already suggested in UDC driver review to deal with extcon in Phy driver.

This phy connects to 2 host controllers, and one device controller.
That's the design in Broadcom Northstar2
platform. The values of the VBUS and ID pins of this port are
determined based on the type of the cable (device cable
or host cable). And. phy has to be configured accordingly.

> The phy ops being invoked during extcon events doesn't look right.

Could you please elaborate on the concern, so that we can think of
mitigating those issues in this driver?
Since we are dealing with phy init/shutdown in this driver itself, are
you okay with moving the extcon handling code
out of phy ops ?

Thanks,
Ravi
>
> Thanks
> Kishon


[RESEND PATCH v4 5/5] usb: gadget: udc: Add Synopsys UDC Platform driver

2017-05-10 Thread Raviteja Garimella
This patch adds platform driver support for Synopsys UDC.

A new driver file (snps_udc_plat.c) is created for this purpose
where the platform driver registration is done based on OF
node.

Currently, UDC integrated into Broadcom's iProc SoCs (Northstar2
and Cygnus) work with this driver.

New members are added to the UDC data structure for having platform
device support along with extcon and phy support.

Kconfig and Makefiles are modified to select platform driver for
compilation.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/Kconfig |  16 +-
 drivers/usb/gadget/udc/Makefile|   1 +
 drivers/usb/gadget/udc/amd5536udc.h|  14 ++
 drivers/usb/gadget/udc/snps_udc_core.c |  54 --
 drivers/usb/gadget/udc/snps_udc_plat.c | 344 +
 5 files changed, 409 insertions(+), 20 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/snps_udc_plat.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 1c14c28..e5d3ba9 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -256,7 +256,7 @@ config USB_MV_U3D
  controller, which support super speed USB peripheral.
 
 config USB_SNP_CORE
-   depends on USB_AMD5536UDC
+   depends on (USB_AMD5536UDC || USB_SNP_UDC_PLAT)
tristate
help
  This enables core driver support for Synopsys USB 2.0 Device
@@ -269,6 +269,20 @@ config USB_SNP_CORE
  This IP is different to the High Speed OTG IP that can be enabled
  by selecting USB_DWC2 or USB_DWC3 options.
 
+config USB_SNP_UDC_PLAT
+   tristate "Synopsys USB 2.0 Device controller"
+   depends on (USB_GADGET && OF)
+   select USB_GADGET_DUALSPEED
+   select USB_SNP_CORE
+   default ARCH_BCM_IPROC
+   help
+ This adds Platform Device support for Synopsys Designware core
+ AHB subsystem USB2.0 Device Controller (UDC).
+
+ This driver works with UDCs integrated into Broadcom's Northstar2
+ and Cygnus SoCs.
+
+ If unsure, say N.
 #
 # Controllers available in both integrated and discrete versions
 #
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 4f4fd62..ea9e1c7 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -37,4 +37,5 @@ obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
 obj-$(CONFIG_USB_MV_U3D)   += mv_u3d_core.o
 obj-$(CONFIG_USB_GR_UDC)   += gr_udc.o
 obj-$(CONFIG_USB_GADGET_XILINX)+= udc-xilinx.o
+obj-$(CONFIG_USB_SNP_UDC_PLAT) += snps_udc_plat.o
 obj-$(CONFIG_USB_BDC_UDC)  += bdc/
diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index 91aae23..4fe22d4 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -16,6 +16,7 @@
 /* debug control */
 /* #define UDC_VERBOSE */
 
+#include 
 #include 
 #include 
 
@@ -28,6 +29,9 @@
 #define UDC_HSA0_REV 1
 #define UDC_HSB1_REV 2
 
+/* Broadcom chip rev. */
+#define UDC_BCM_REV 10
+
 /*
  * SETUP usb commands
  * needed, because some SETUP's are handled in hw, but must be passed to
@@ -112,6 +116,7 @@
 #define UDC_DEVCTL_BRLEN_MASK  0x00ff
 #define UDC_DEVCTL_BRLEN_OFS   16
 
+#define UDC_DEVCTL_SRX_FLUSH   14
 #define UDC_DEVCTL_CSR_DONE13
 #define UDC_DEVCTL_DEVNAK  12
 #define UDC_DEVCTL_SD  10
@@ -564,7 +569,15 @@ struct udc {
u16 cur_intf;
u16 cur_alt;
 
+   /* for platform device and extcon support */
struct device   *dev;
+   struct phy  *udc_phy;
+   struct extcon_dev   *edev;
+   struct extcon_specific_cable_nb extcon_nb;
+   struct notifier_block   nb;
+   struct delayed_work drd_work;
+   struct workqueue_struct *drd_wq;
+   u32 conn_type;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -580,6 +593,7 @@ int udc_enable_dev_setup_interrupts(struct udc *dev);
 int udc_mask_unused_interrupts(struct udc *dev);
 irqreturn_t udc_irq(int irq, void *pdev);
 void gadget_release(struct device *pdev);
+void empty_req_queue(struct udc_ep *ep);
 void udc_basic_init(struct udc *dev);
 void free_dma_pools(struct udc *dev);
 int init_dma_pools(struct udc *dev);
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index d592f77..38a165d 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -41,7 +41,6 @@
 #include "amd5536udc.h"
 
 static void udc_tasklet_disconnect(unsigned long);
-static void empty_req_queue(struct udc_ep *);
 static void udc_setup_endpoints(struct udc 

[RESEND PATCH v4 3/5] usb: gadget: udc: Provide correct arguments for 'dma_pool_create'

2017-05-10 Thread Raviteja Garimella
Change the argument from NULL to a struct device for the
dma_pool_create call during dma init.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/snps_udc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 4c43ce2..d592f77 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -3097,7 +3097,7 @@ int init_dma_pools(struct udc *dev)
}
 
/* DMA setup */
-   dev->data_requests = dma_pool_create("data_requests", NULL,
+   dev->data_requests = dma_pool_create("data_requests", dev->dev,
sizeof(struct udc_data_dma), 0, 0);
if (!dev->data_requests) {
DBG(dev, "can't get request data pool\n");
@@ -3108,7 +3108,7 @@ int init_dma_pools(struct udc *dev)
dev->ep[UDC_EP0IN_IX].dma = >regs->ctl;
 
/* dma desc for setup data */
-   dev->stp_requests = dma_pool_create("setup requests", NULL,
+   dev->stp_requests = dma_pool_create("setup requests", dev->dev,
sizeof(struct udc_stp_dma), 0, 0);
if (!dev->stp_requests) {
DBG(dev, "can't get stp request pool\n");
-- 
2.1.0



[RESEND PATCH v4 0/5] Platform driver support for 'amd5536udc' driver

2017-05-10 Thread Raviteja Garimella
Resending PATCH v4 since one of the patches is missing
signature.

Changes in PATCH v4:
===
-- Rebased with Balbi's git repo testing/next branch.
-- Removed a patch that replaces pci_pool calls with dma_pool
   since the change is already pushed by other submitter.


Resending PATCH v3 after rebasing with testing/next branch in 
Felipe Balbi's git tree. Resolved few merge conflicts. 
Tested applying all patches. Patch 1/7 can be ignored since it's
already applied.

Changes in PATCH v3:
===
1. Updated bindings documentation and platform driver to add
   "brcm,iproc-udc" compatibility string.

2. Added a patch to replace references of struct pci_pool with
   struct dma_pool so that it is compatibile with non-pci drivers.

Changes in PATCH v2:
===
1. Updated bindings documentation:
   -- compatibility string for each supported SoC
   -- removed extcon node
   -- rename the file name to just iproc-udc.txt

2. Modified comptability strings in platform driver file
   to reflect the change made in 1.

3 Kconfig
   -- Resolved warnings shown by kbuild-test-robot  

The changes are being submitted as PATCH this time. Below are the
details of main changes with respect to previous RFC versions.

Changes in PATCH v1:
===
Patch 1/6 now splits the driver into amd5536udc_pci_.c (which
contains only the PCI device registration part), and amd5536udc.c
will still be driver that does the rest of UDC driver functionality.

Patch 2/6 renames amd5536udc.c to snps_udc_core.c.

The DT compatibilty string is changed to "brcm,iproc-snps-udc"
as per review comments for RFCv2. The driver and bindings
documentation is modified to reflect this.

This is RFC for the changes made as per the review comments made for
the previous version. I would like to know  if this approach (the way
the driver is split and the naming and all)looks good to be submitted.


Changes in RFC v2:
=
1. Split the driver into platform/pci specific drivers with a core driver
   file that handles the common driver routines that are exported.

2. Split the driver into number of patches as suggested in previous
   review comments.

3. Added the devicetree bindings documentation for Synopsys platform
   driver.

Introduction (RFC v1):
=
This patch adds platform device support to the existing 'amd5536udc'
driver.

The UDC is based on Synopsys Designware core USB (2.0) Device controller
IP.

The driver so far supports UDCs that are a part of AMD southbridge
and is connected through PCI bus.

The same driver can be used with UDCs that are integrated into SoCs
like Broadcom's Northstar2/Cygnus platforms by adding platform device
suooprt.

This patch contains all the changes that were required to get the driver
functional on Broadcom's Northstar2 platform. 

This is a request for comments from maintainers/others regarding approach
on whether to have 2 different drivers (one each for AMD and Broadcom)
with a common library (3 files in total), or have a single driver like
it's done in this patch and have the driver filename changed to some
common name based on ther underlying IP, like snps_udc.c.

Below are the main changes done:

1. Added OF based platform device registration -- so that the driver gets
   probed based on the device tree entry. Like wise, remove routine and
   platform PM ops are supported.

2. Modified debug prints to be compatible with both pci and platform
   devices.

3. Added members to 'struct udc' in header file for extcon and phy support.
   This is required if the UDC is connected to a Dual Role Device Phy
   where the Phy can be configured to be in Device mode or Host mode based
   on the type of external cable that is connected to the port.
 
4. Added checks in udc connect/disconnect routines so as to return if the
   routine is already called.

5. Modified the arguments passed to dma_pool_create routine -- which
   expects struct device, whereas NULL is passed in the existing version.
 
6. Kconfig changes are done so that the driver now depends on either of
   CONFIG_OF or CONFIG_PCI. More description about the Synopsys IP is
   provided.

Raviteja Garimella (5):
  usb: gadget: udc: Rename amd5536udc driver file based on IP
  usb: gadget: udc: make debug prints compatible with both pci and
platform devices
  usb: gadget: udc: Provide correct arguments for 'dma_pool_create'
  dt-bindings: usb: DT bindings documentation for Broadcom IPROC USB
Device controller.
  usb: gadget: udc: Add Synopsys UDC Platform driver

 .../devicetree/bindings/usb/iproc-udc.txt  |   21 +
 drivers/usb/gadget/udc/Kconfig |   16 +-
 drivers/usb/gadget/udc/Makefile|3 +-
 drivers/usb/gadget/udc/amd5536udc.c| 3219 ---
 drivers/usb/gadget/udc/amd5536udc.h|   18 +-
 drivers/usb/gadget/udc/amd5536udc_pci.c|1 +
 drivers/usb/gadget

[RESEND PATCH v4 4/5] dt-bindings: usb: DT bindings documentation for Broadcom IPROC USB Device controller.

2017-05-10 Thread Raviteja Garimella
The device node is used for UDCs integrated into Broadcom's
iProc family of SoCs'. The UDC is based on Synopsys Designware
Cores AHB Subsystem USB Device Controller IP.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 Documentation/devicetree/bindings/usb/iproc-udc.txt | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/iproc-udc.txt

diff --git a/Documentation/devicetree/bindings/usb/iproc-udc.txt 
b/Documentation/devicetree/bindings/usb/iproc-udc.txt
new file mode 100644
index 000..272d7fa
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/iproc-udc.txt
@@ -0,0 +1,21 @@
+Broadcom IPROC USB Device controller.
+
+The device node is used for UDCs integrated into Broadcom's
+iProc family (Northstar2, Cygnus) of SoCs'. The UDC is based
+on Synopsys Designware Cores AHB Subsystem Device Controller
+IP.
+
+Required properties:
+ - compatible: Add the compatibility strings for supported platforms.
+   For Broadcom NS2 platform, add "brcm,ns2-udc","brcm,iproc-udc".
+   For Broadcom Cygnus platform, add "brcm,cygnus-udc", "brcm,iproc-udc".
+ - reg: Offset and length of UDC register set
+ - interrupts: description of interrupt line
+ - phys: phandle to phy node.
+
+Example:
+   udc_dwc: usb@664e {
+   compatible = "brcm,ns2-udc", "brcm,iproc-udc";
+   reg = <0x664e 0x2000>;
+   interrupts = ;
+   phys = <_phy>;
-- 
2.1.0



[PATCH v4 3/5] usb: gadget: udc: Provide correct arguments for 'dma_pool_create'

2017-05-10 Thread Raviteja Garimella
Change the argument from NULL to a struct device for the
dma_pool_create call during dma init.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/snps_udc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 4c43ce2..d592f77 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -3097,7 +3097,7 @@ int init_dma_pools(struct udc *dev)
}
 
/* DMA setup */
-   dev->data_requests = dma_pool_create("data_requests", NULL,
+   dev->data_requests = dma_pool_create("data_requests", dev->dev,
sizeof(struct udc_data_dma), 0, 0);
if (!dev->data_requests) {
DBG(dev, "can't get request data pool\n");
@@ -3108,7 +3108,7 @@ int init_dma_pools(struct udc *dev)
dev->ep[UDC_EP0IN_IX].dma = >regs->ctl;
 
/* dma desc for setup data */
-   dev->stp_requests = dma_pool_create("setup requests", NULL,
+   dev->stp_requests = dma_pool_create("setup requests", dev->dev,
sizeof(struct udc_stp_dma), 0, 0);
if (!dev->stp_requests) {
DBG(dev, "can't get stp request pool\n");
-- 
2.1.0



[PATCH v4 5/5] usb: gadget: udc: Add Synopsys UDC Platform driver

2017-05-10 Thread Raviteja Garimella
This patch adds platform driver support for Synopsys UDC.

A new driver file (snps_udc_plat.c) is created for this purpose
where the platform driver registration is done based on OF
node.

Currently, UDC integrated into Broadcom's iProc SoCs (Northstar2
and Cygnus) work with this driver.

New members are added to the UDC data structure for having platform
device support along with extcon and phy support.

Kconfig and Makefiles are modified to select platform driver for
compilation.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/Kconfig |  16 +-
 drivers/usb/gadget/udc/Makefile|   1 +
 drivers/usb/gadget/udc/amd5536udc.h|  14 ++
 drivers/usb/gadget/udc/snps_udc_core.c |  54 --
 drivers/usb/gadget/udc/snps_udc_plat.c | 344 +
 5 files changed, 409 insertions(+), 20 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/snps_udc_plat.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 1c14c28..e5d3ba9 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -256,7 +256,7 @@ config USB_MV_U3D
  controller, which support super speed USB peripheral.
 
 config USB_SNP_CORE
-   depends on USB_AMD5536UDC
+   depends on (USB_AMD5536UDC || USB_SNP_UDC_PLAT)
tristate
help
  This enables core driver support for Synopsys USB 2.0 Device
@@ -269,6 +269,20 @@ config USB_SNP_CORE
  This IP is different to the High Speed OTG IP that can be enabled
  by selecting USB_DWC2 or USB_DWC3 options.
 
+config USB_SNP_UDC_PLAT
+   tristate "Synopsys USB 2.0 Device controller"
+   depends on (USB_GADGET && OF)
+   select USB_GADGET_DUALSPEED
+   select USB_SNP_CORE
+   default ARCH_BCM_IPROC
+   help
+ This adds Platform Device support for Synopsys Designware core
+ AHB subsystem USB2.0 Device Controller (UDC).
+
+ This driver works with UDCs integrated into Broadcom's Northstar2
+ and Cygnus SoCs.
+
+ If unsure, say N.
 #
 # Controllers available in both integrated and discrete versions
 #
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 4f4fd62..ea9e1c7 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -37,4 +37,5 @@ obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
 obj-$(CONFIG_USB_MV_U3D)   += mv_u3d_core.o
 obj-$(CONFIG_USB_GR_UDC)   += gr_udc.o
 obj-$(CONFIG_USB_GADGET_XILINX)+= udc-xilinx.o
+obj-$(CONFIG_USB_SNP_UDC_PLAT) += snps_udc_plat.o
 obj-$(CONFIG_USB_BDC_UDC)  += bdc/
diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index 91aae23..4fe22d4 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -16,6 +16,7 @@
 /* debug control */
 /* #define UDC_VERBOSE */
 
+#include 
 #include 
 #include 
 
@@ -28,6 +29,9 @@
 #define UDC_HSA0_REV 1
 #define UDC_HSB1_REV 2
 
+/* Broadcom chip rev. */
+#define UDC_BCM_REV 10
+
 /*
  * SETUP usb commands
  * needed, because some SETUP's are handled in hw, but must be passed to
@@ -112,6 +116,7 @@
 #define UDC_DEVCTL_BRLEN_MASK  0x00ff
 #define UDC_DEVCTL_BRLEN_OFS   16
 
+#define UDC_DEVCTL_SRX_FLUSH   14
 #define UDC_DEVCTL_CSR_DONE13
 #define UDC_DEVCTL_DEVNAK  12
 #define UDC_DEVCTL_SD  10
@@ -564,7 +569,15 @@ struct udc {
u16 cur_intf;
u16 cur_alt;
 
+   /* for platform device and extcon support */
struct device   *dev;
+   struct phy  *udc_phy;
+   struct extcon_dev   *edev;
+   struct extcon_specific_cable_nb extcon_nb;
+   struct notifier_block   nb;
+   struct delayed_work drd_work;
+   struct workqueue_struct *drd_wq;
+   u32 conn_type;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -580,6 +593,7 @@ int udc_enable_dev_setup_interrupts(struct udc *dev);
 int udc_mask_unused_interrupts(struct udc *dev);
 irqreturn_t udc_irq(int irq, void *pdev);
 void gadget_release(struct device *pdev);
+void empty_req_queue(struct udc_ep *ep);
 void udc_basic_init(struct udc *dev);
 void free_dma_pools(struct udc *dev);
 int init_dma_pools(struct udc *dev);
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index d592f77..38a165d 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -41,7 +41,6 @@
 #include "amd5536udc.h"
 
 static void udc_tasklet_disconnect(unsigned long);
-static void empty_req_queue(struct udc_ep *);
 static void udc_setup_endpoints(struct udc 

[PATCH v4 2/5] usb: gadget: udc: make debug prints compatible with both pci and platform devices

2017-05-10 Thread Raviteja Garimella
This patch adds a struct device member to UDC data structure and
makes changes to the arguments of dev_err and dev_dbg calls so that
the debug prints work for both pci and platform devices.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/amd5536udc.h |  4 +++-
 drivers/usb/gadget/udc/amd5536udc_pci.c |  1 +
 drivers/usb/gadget/udc/snps_udc_core.c  | 28 ++--
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index fae49bf..91aae23 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -563,6 +563,8 @@ struct udc {
u16 cur_config;
u16 cur_intf;
u16 cur_alt;
+
+   struct device   *dev;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -639,7 +641,7 @@ MODULE_PARM_DESC(use_fullspeed, "true for fullspeed only");
 
 /* debug macros */
 
-#define DBG(udc , args...) dev_dbg(&(udc)->pdev->dev, args)
+#define DBG(udc , args...) dev_dbg(udc->dev, args)
 
 #ifdef UDC_VERBOSE
 #define VDBG   DBG
diff --git a/drivers/usb/gadget/udc/amd5536udc_pci.c 
b/drivers/usb/gadget/udc/amd5536udc_pci.c
index 2a2d0a9..57a13f0 100644
--- a/drivers/usb/gadget/udc/amd5536udc_pci.c
+++ b/drivers/usb/gadget/udc/amd5536udc_pci.c
@@ -168,6 +168,7 @@ static int udc_pci_probe(
dev->phys_addr = resource;
dev->irq = pdev->irq;
dev->pdev = pdev;
+   dev->dev = >dev;
 
/* general probing */
if (udc_probe(dev)) {
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 4ecd2f2..4c43ce2 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -209,18 +209,18 @@ static void print_regs(struct udc *dev)
if (use_dma && use_dma_ppb && !use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBNDU (packet per buffer "
"WITHOUT desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBNDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBNDU");
} else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBDU (packet per buffer "
"WITH desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBDU");
}
if (use_dma && use_dma_bufferfill_mode) {
DBG(dev, "DMA mode   = BF (buffer fill mode)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "BF");
+   dev_info(dev->dev, "DMA mode (%s)\n", "BF");
}
if (!use_dma)
-   dev_info(>pdev->dev, "FIFO mode\n");
+   dev_info(dev->dev, "FIFO mode\n");
DBG(dev, "---\n");
 }
 
@@ -1624,7 +1624,7 @@ static void udc_setup_endpoints(struct udc *dev)
 static void usb_connect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Connect\n");
+   dev_info(dev->dev, "USB Connect\n");
 
dev->connected = 1;
 
@@ -1642,7 +1642,7 @@ static void usb_connect(struct udc *dev)
 static void usb_disconnect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Disconnect\n");
+   dev_info(dev->dev, "USB Disconnect\n");
 
dev->connected = 0;
 
@@ -2106,7 +2106,7 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int 
ep_ix)
}
/* HE event ? */
if (tmp & AMD_BIT(UDC_EPSTS_HE)) {
-   dev_err(>pdev->dev, "HE ep%dout occurred\n", ep->num);
+   dev_err(dev->dev, "HE ep%dout occurred\n", ep->num);
 
/* clear HE */
writel(tmp | AMD_BIT(UDC_EPSTS_HE), >regs->sts);
@@ -2305,7 +2305,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int 
ep_ix)
if (use_dma) {
/* BNA ? */
if (epsts & AMD_BIT(UDC_EPSTS_BNA)) {
-   dev_err(>pdev->dev,
+   dev_err(dev->dev,
"BNA ep%din occurred - DESPTR = %08lx\n",
ep->num,
(unsigned long) readl(>regs->desptr

[PATCH v4 4/5] dt-bindings: usb: DT bindings documentation for Broadcom IPROC USB Device controller.

2017-05-10 Thread Raviteja Garimella
The device node is used for UDCs integrated into Broadcom's
iProc family of SoCs'. The UDC is based on Synopsys Designware
Cores AHB Subsystem USB Device Controller IP.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 Documentation/devicetree/bindings/usb/iproc-udc.txt | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/iproc-udc.txt

diff --git a/Documentation/devicetree/bindings/usb/iproc-udc.txt 
b/Documentation/devicetree/bindings/usb/iproc-udc.txt
new file mode 100644
index 000..272d7fa
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/iproc-udc.txt
@@ -0,0 +1,21 @@
+Broadcom IPROC USB Device controller.
+
+The device node is used for UDCs integrated into Broadcom's
+iProc family (Northstar2, Cygnus) of SoCs'. The UDC is based
+on Synopsys Designware Cores AHB Subsystem Device Controller
+IP.
+
+Required properties:
+ - compatible: Add the compatibility strings for supported platforms.
+   For Broadcom NS2 platform, add "brcm,ns2-udc","brcm,iproc-udc".
+   For Broadcom Cygnus platform, add "brcm,cygnus-udc", "brcm,iproc-udc".
+ - reg: Offset and length of UDC register set
+ - interrupts: description of interrupt line
+ - phys: phandle to phy node.
+
+Example:
+   udc_dwc: usb@664e {
+   compatible = "brcm,ns2-udc", "brcm,iproc-udc";
+   reg = <0x664e 0x2000>;
+   interrupts = ;
+   phys = <_phy>;
-- 
2.1.0



[RESEND PATCH v4 2/5] usb: gadget: udc: make debug prints compatible with both pci and platform devices

2017-05-10 Thread Raviteja Garimella
This patch adds a struct device member to UDC data structure and
makes changes to the arguments of dev_err and dev_dbg calls so that
the debug prints work for both pci and platform devices.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/usb/gadget/udc/amd5536udc.h |  4 +++-
 drivers/usb/gadget/udc/amd5536udc_pci.c |  1 +
 drivers/usb/gadget/udc/snps_udc_core.c  | 28 ++--
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index fae49bf..91aae23 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -563,6 +563,8 @@ struct udc {
u16 cur_config;
u16 cur_intf;
u16 cur_alt;
+
+   struct device   *dev;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -639,7 +641,7 @@ MODULE_PARM_DESC(use_fullspeed, "true for fullspeed only");
 
 /* debug macros */
 
-#define DBG(udc , args...) dev_dbg(&(udc)->pdev->dev, args)
+#define DBG(udc , args...) dev_dbg(udc->dev, args)
 
 #ifdef UDC_VERBOSE
 #define VDBG   DBG
diff --git a/drivers/usb/gadget/udc/amd5536udc_pci.c 
b/drivers/usb/gadget/udc/amd5536udc_pci.c
index 2a2d0a9..57a13f0 100644
--- a/drivers/usb/gadget/udc/amd5536udc_pci.c
+++ b/drivers/usb/gadget/udc/amd5536udc_pci.c
@@ -168,6 +168,7 @@ static int udc_pci_probe(
dev->phys_addr = resource;
dev->irq = pdev->irq;
dev->pdev = pdev;
+   dev->dev = >dev;
 
/* general probing */
if (udc_probe(dev)) {
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 4ecd2f2..4c43ce2 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -209,18 +209,18 @@ static void print_regs(struct udc *dev)
if (use_dma && use_dma_ppb && !use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBNDU (packet per buffer "
"WITHOUT desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBNDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBNDU");
} else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBDU (packet per buffer "
"WITH desc. update)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "PPBDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBDU");
}
if (use_dma && use_dma_bufferfill_mode) {
DBG(dev, "DMA mode   = BF (buffer fill mode)\n");
-   dev_info(>pdev->dev, "DMA mode (%s)\n", "BF");
+   dev_info(dev->dev, "DMA mode (%s)\n", "BF");
}
if (!use_dma)
-   dev_info(>pdev->dev, "FIFO mode\n");
+   dev_info(dev->dev, "FIFO mode\n");
DBG(dev, "---\n");
 }
 
@@ -1624,7 +1624,7 @@ static void udc_setup_endpoints(struct udc *dev)
 static void usb_connect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Connect\n");
+   dev_info(dev->dev, "USB Connect\n");
 
dev->connected = 1;
 
@@ -1642,7 +1642,7 @@ static void usb_connect(struct udc *dev)
 static void usb_disconnect(struct udc *dev)
 {
 
-   dev_info(>pdev->dev, "USB Disconnect\n");
+   dev_info(dev->dev, "USB Disconnect\n");
 
dev->connected = 0;
 
@@ -2106,7 +2106,7 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int 
ep_ix)
}
/* HE event ? */
if (tmp & AMD_BIT(UDC_EPSTS_HE)) {
-   dev_err(>pdev->dev, "HE ep%dout occurred\n", ep->num);
+   dev_err(dev->dev, "HE ep%dout occurred\n", ep->num);
 
/* clear HE */
writel(tmp | AMD_BIT(UDC_EPSTS_HE), >regs->sts);
@@ -2305,7 +2305,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int 
ep_ix)
if (use_dma) {
/* BNA ? */
if (epsts & AMD_BIT(UDC_EPSTS_BNA)) {
-   dev_err(>pdev->dev,
+   dev_err(dev->dev,
"BNA ep%din occurred - DESPTR = %08lx\n",
ep->num,
(unsigned long) readl(>regs->desptr

[PATCH v4 0/5] Platform driver support for 'amd5536udc' driver

2017-05-10 Thread Raviteja Garimella
Changes in PATCH v4:
===
-- Rebased with Balbi's git repo testing/next branch.
-- Removed a patch that replaces pci_pool calls with dma_pool
   since the change is already pushed by other submitter.


Resending PATCH v3 after rebasing with testing/next branch in 
Felipe Balbi's git tree. Resolved few merge conflicts. 
Tested applying all patches. Patch 1/7 can be ignored since it's
already applied.

Changes in PATCH v3:
===
1. Updated bindings documentation and platform driver to add
   "brcm,iproc-udc" compatibility string.

2. Added a patch to replace references of struct pci_pool with
   struct dma_pool so that it is compatibile with non-pci drivers.

Changes in PATCH v2:
===
1. Updated bindings documentation:
   -- compatibility string for each supported SoC
   -- removed extcon node
   -- rename the file name to just iproc-udc.txt

2. Modified comptability strings in platform driver file
   to reflect the change made in 1.

3 Kconfig
   -- Resolved warnings shown by kbuild-test-robot  

The changes are being submitted as PATCH this time. Below are the
details of main changes with respect to previous RFC versions.

Changes in PATCH v1:
===
Patch 1/6 now splits the driver into amd5536udc_pci_.c (which
contains only the PCI device registration part), and amd5536udc.c
will still be driver that does the rest of UDC driver functionality.

Patch 2/6 renames amd5536udc.c to snps_udc_core.c.

The DT compatibilty string is changed to "brcm,iproc-snps-udc"
as per review comments for RFCv2. The driver and bindings
documentation is modified to reflect this.

This is RFC for the changes made as per the review comments made for
the previous version. I would like to know  if this approach (the way
the driver is split and the naming and all)looks good to be submitted.


Changes in RFC v2:
=
1. Split the driver into platform/pci specific drivers with a core driver
   file that handles the common driver routines that are exported.

2. Split the driver into number of patches as suggested in previous
   review comments.

3. Added the devicetree bindings documentation for Synopsys platform
   driver.

Introduction (RFC v1):
=
This patch adds platform device support to the existing 'amd5536udc'
driver.

The UDC is based on Synopsys Designware core USB (2.0) Device controller
IP.

The driver so far supports UDCs that are a part of AMD southbridge
and is connected through PCI bus.

The same driver can be used with UDCs that are integrated into SoCs
like Broadcom's Northstar2/Cygnus platforms by adding platform device
suooprt.

This patch contains all the changes that were required to get the driver
functional on Broadcom's Northstar2 platform. 

This is a request for comments from maintainers/others regarding approach
on whether to have 2 different drivers (one each for AMD and Broadcom)
with a common library (3 files in total), or have a single driver like
it's done in this patch and have the driver filename changed to some
common name based on ther underlying IP, like snps_udc.c.

Below are the main changes done:

1. Added OF based platform device registration -- so that the driver gets
   probed based on the device tree entry. Like wise, remove routine and
   platform PM ops are supported.

2. Modified debug prints to be compatible with both pci and platform
   devices.

3. Added members to 'struct udc' in header file for extcon and phy support.
   This is required if the UDC is connected to a Dual Role Device Phy
   where the Phy can be configured to be in Device mode or Host mode based
   on the type of external cable that is connected to the port.
 
4. Added checks in udc connect/disconnect routines so as to return if the
   routine is already called.

5. Modified the arguments passed to dma_pool_create routine -- which
   expects struct device, whereas NULL is passed in the existing version.
 
6. Kconfig changes are done so that the driver now depends on either of
   CONFIG_OF or CONFIG_PCI. More description about the Synopsys IP is
   provided.

Raviteja Garimella (5):
  usb: gadget: udc: Rename amd5536udc driver file based on IP
  usb: gadget: udc: make debug prints compatible with both pci and
platform devices
  usb: gadget: udc: Provide correct arguments for 'dma_pool_create'
  dt-bindings: usb: DT bindings documentation for Broadcom IPROC USB
Device controller.
  usb: gadget: udc: Add Synopsys UDC Platform driver

 .../devicetree/bindings/usb/iproc-udc.txt  |   21 +
 drivers/usb/gadget/udc/Kconfig |   16 +-
 drivers/usb/gadget/udc/Makefile|3 +-
 drivers/usb/gadget/udc/amd5536udc.c| 3219 ---
 drivers/usb/gadget/udc/amd5536udc.h|   18 +-
 drivers/usb/gadget/udc/amd5536udc_pci.c|1 +
 drivers/usb/gadget/udc/snps_udc_core.c | 3235 
 dr

[RESEND PATCH v5 0/3] Support for USB DRD Phy driver for NS2

2017-05-10 Thread Raviteja Garimella
Resending the patchset v5.
Commit message for dts patch is edited as suggested by Florian.

Changes in v5:
=
Removed references to phy_ops in the same driver by connect_work
event handler to change the phy modes.

To support dynamically changing the mode of the phy, it does
not require doing a phy reset/programming of PHY PLL. Changes
are made to the connect_work routine to just program the required
register bits to achieve this purpose.

Changes in v4:
=
Remove references to edev->name in debug prints.

Changes in v3:
=
Remove unnecessary checks for poweron as suggested in review.

Changes in v2:
=
1. Initialize file operations .owner field with THIS_MODULE.
2. Remove unnecessary gpio example in DT bindings documentation.
   This is previously acked by Rob Herring <r...@kernel.org>

Introduction for PATCH v1:

This patch adds support for USB Dual Role Device Phy for Broadcom
Northstar2 SoC. Apart from the new phy driver, this patchset contains
changes to Kconfig, Makefile, and Device tree files.

This patchset is tested on Broadcom NS2 BCM958712K reference board.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: ns2_drdphy_v5

Raviteja Garimella (3):
  dt-bindings:phy:Add DT bindings documentation for NS2 USB DRD phy
  phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2
  arm64: dts: NS2: Add USB DRD PHY device tree node

 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   |  30 ++
 arch/arm64/boot/dts/broadcom/ns2.dtsi  |  14 +
 drivers/phy/Kconfig|  13 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c   | 595 +
 5 files changed, 653 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

-- 
2.1.0



[RESEND PATCH v5 1/3] dt-bindings:phy:Add DT bindings documentation for NS2 USB DRD phy

2017-05-10 Thread Raviteja Garimella
This patch adds documentation for NS2 DRD Phy driver DT bindings

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
Acked-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   | 30 ++
 1 file changed, 30 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt

diff --git a/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt 
b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
new file mode 100644
index 000..04f063a
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
@@ -0,0 +1,30 @@
+BROADCOM NORTHSTAR2 USB2 (DUAL ROLE DEVICE) PHY
+
+Required properties:
+ - compatible: brcm,ns2-drd-phy
+ - reg: offset and length of the NS2 PHY related registers.
+ - reg-names
+   The below registers must be provided.
+   icfg - for DRD ICFG configurations
+   rst-ctrl - for DRD IDM reset
+   crmu-ctrl - for CRMU core vdd, PHY and PHY PLL reset
+   usb2-strap - for port over current polarity reversal
+ - #phy-cells: Must be 0. No args required.
+ - vbus-gpios: vbus gpio binding
+ - id-gpios: id gpio binding
+
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+Example:
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   };
-- 
2.1.0



[RESEND PATCH v5 2/3] phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2

2017-05-10 Thread Raviteja Garimella
This is driver for USB DRD Phy used in Broadcom's Northstar2
SoC. The phy can be configured to be in Device mode or Host
mode based on the type of cable connected to the port. The
driver registers to  extcon framework to get appropriate
connect events for Host/Device cables connect/disconnect
states based on VBUS and ID interrupts.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/phy/Kconfig  |  13 +
 drivers/phy/Makefile |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c | 595 +++
 3 files changed, 609 insertions(+)
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 005cadb..c9de9a9 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -488,6 +488,19 @@ config PHY_CYGNUS_PCIE
  Enable this to support the Broadcom Cygnus PCIe PHY.
  If unsure, say N.
 
+config PHY_NS2_USB_DRD
+   tristate "Broadcom Northstar2 USB DRD PHY support"
+   depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
+   select GENERIC_PHY
+   select EXTCON
+   default ARCH_BCM_IPROC
+   help
+ Enable this to support the Broadcom Northstar2 USB DRD PHY.
+ This driver initializes the PHY in either HOST or DEVICE mode.
+ The host or device configuration is read from device tree.
+
+ If unsure, say N.
+
 source "drivers/phy/tegra/Kconfig"
 
 config PHY_NS2_PCIE
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index dd8f3b5..9285f88 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -59,6 +59,7 @@ obj-$(CONFIG_PHY_TUSB1210)+= phy-tusb1210.o
 obj-$(CONFIG_PHY_BRCM_SATA)+= phy-brcm-sata.o
 obj-$(CONFIG_PHY_PISTACHIO_USB)+= phy-pistachio-usb.o
 obj-$(CONFIG_PHY_CYGNUS_PCIE)  += phy-bcm-cygnus-pcie.o
+obj-$(CONFIG_PHY_NS2_USB_DRD)  += phy-bcm-ns2-usbdrd.o
 obj-$(CONFIG_ARCH_TEGRA) += tegra/
 obj-$(CONFIG_PHY_NS2_PCIE) += phy-bcm-ns2-pcie.o
 obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o
diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c b/drivers/phy/phy-bcm-ns2-usbdrd.c
new file mode 100644
index 000..92b68b1
--- /dev/null
+++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
@@ -0,0 +1,595 @@
+/*
+ * Copyright (C) 2016 Broadcom
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ICFG_DRD_AFE   0x0
+#define ICFG_MISC_STAT 0x18
+#define ICFG_DRD_P0CTL 0x1C
+#define ICFG_STRAP_CTRL0x20
+#define ICFG_FSM_CTRL  0x24
+
+#define ICFG_DEV_BIT   BIT(2)
+#define IDM_RST_BITBIT(0)
+#define AFE_CORERDY_VDDC   BIT(18)
+#define PHY_PLL_RESETB BIT(15)
+#define PHY_RESETB BIT(14)
+#define PHY_PLL_LOCK   BIT(0)
+
+#define DRD_DEV_MODE   BIT(20)
+#define OHCI_OVRCUR_POLBIT(11)
+#define ICFG_OFF_MODE  BIT(6)
+#define PLL_LOCK_RETRY 1000
+
+#define EVT_DEVICE 0
+#define EVT_HOST   1
+#define EVT_IDLE   2
+
+#define DRD_HOST_MODE  (BIT(2) | BIT(3))
+#define DRD_DEVICE_MODE(BIT(4) | BIT(5))
+#define DRD_HOST_VAL   0x803
+#define DRD_DEV_VAL0x807
+#define GPIO_DELAY 20
+#define PHY_WQ_DELAY   msecs_to_jiffies(600)
+
+struct ns2_phy_data;
+struct ns2_phy_driver {
+   void __iomem *icfgdrd_regs;
+   void __iomem *idmdrd_rst_ctrl;
+   void __iomem *crmu_usb2_ctrl;
+   void __iomem *usb2h_strap_reg;
+   spinlock_t lock; /* spin lock for phy driver */
+   struct ns2_phy_data *data;
+   struct extcon_specific_cable_nb extcon_dev;
+   struct extcon_specific_cable_nb extcon_host;
+   struct notifier_block host_nb;
+   struct notifier_block dev_nb;
+   struct delayed_work conn_work;
+   struct extcon_dev *edev;
+   struct gpio_desc *vbus_gpiod;
+   struct gpio_desc *id_gpiod;
+   int id_irq;
+   int vbus_irq;
+   unsigned long debounce_jiffies;
+   struct delayed_work wq_extcon;
+};
+
+struct ns2_phy_data {
+   struct ns2_phy_driver *driver;
+   struct phy *phy;
+   int new_state;
+};
+
+static const unsigned int usb_extcon_cable[] = {
+   EXTCON_USB,
+   EXTCON_USB_HOST,
+   EXTCON_NONE,
+};
+

[RESEND PATCH v5 3/3] arm64: dts: NS2: Add USB DRD PHY device tree node

2017-05-10 Thread Raviteja Garimella
This patch adds device tree node for USB Dual Role Device Phy for
Broadcom's Northstar2 SoC.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 arch/arm64/boot/dts/broadcom/ns2.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm64/boot/dts/broadcom/ns2.dtsi 
b/arch/arm64/boot/dts/broadcom/ns2.dtsi
index bcb03fc..c71f330 100644
--- a/arch/arm64/boot/dts/broadcom/ns2.dtsi
+++ b/arch/arm64/boot/dts/broadcom/ns2.dtsi
@@ -436,6 +436,20 @@
};
};
 
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   status = "disabled";
+   };
+
pwm: pwm@6601 {
compatible = "brcm,iproc-pwm";
reg = <0x6601 0x28>;
-- 
2.1.0



Re: [PATCH v8 0/3] Support for USB DRD PHY driver for NS2

2017-06-09 Thread Raviteja Garimella
Hi,

On Fri, Jun 9, 2017 at 2:25 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
> Hi,
>
> On Thursday 08 June 2017 04:05 PM, Raviteja Garimella wrote:
>> Changes in v8:
>> =
>> -Renamed phy shutdown routine
>> -Used devm_request_irq in stead of threaded irq
>
> That's not what I intended. Continue to use threaded irq but remove delayed 
> work.
>

Yes I get that. We see intermittent connection issues without delayed
work. Debounce delay matters there.

Thanks,
Ravi

> Thanks
> Kishon
>> -Removed devm_unregister calls in probe routine
>>
>> Changes in v7:
>> =
>> Cleaned up unused variables in phy private data structure that's
>> missed out in v6.
>> Setting of phy mode to device/host is removed from phy power on.
>> routine.
>>
>> Changes in v6:
>> =
>> Removed spin locks which are not required as the references
>> to phy_ops in the same driver were removed in v5.
>>
>> Removed host/device 'notify' routines which are registered
>> using 'extcon_register_notifier'. The irq handler is sufficient
>> to deal with the change in extcon events within the same driver.
>>
>> Changes in v5:
>> =
>> Removed references to phy_ops in the same driver by connect_work
>> event handler to change the phy modes.
>>
>> To support dynamically changing the mode of the phy, it does
>> not require doing a phy reset/programming of PHY PLL. Changes
>> are made to the connect_work routine to just program the required
>> register bits to achieve this purpose.
>>
>> Changes in v4:
>> =
>> Remove references to edev->name in debug prints.
>>
>> Changes in v3:
>> =
>> Remove unnecessary checks for poweron as suggested in review.
>>
>> Changes in v2:
>> =
>> 1. Initialize file operations .owner field with THIS_MODULE.
>> 2. Remove unnecessary gpio example in DT bindings documentation.
>>This is previously acked by Rob Herring <r...@kernel.org>
>>
>> Introduction for PATCH v1:
>>
>> This patch adds support for USB Dual Role Device Phy for Broadcom
>> Northstar2 SoC. Apart from the new phy driver, this patchset contains
>> changes to Kconfig, Makefile, and Device tree files.
>>
>> This patchset is tested on Broadcom NS2 BCM958712K reference board.
>>
>> Repo: https://github.com/Broadcom/arm64-linux.git
>> Branch: ns2_drdphy_v8
>>
>> Raviteja Garimella (3):
>>   dt-bindings: phy: Add DT bindings documentation for NS2 USB DRD PHY
>>   phy: phy-bcm-ns2-usbdrd: Broadcom USB DRD PHY driver for Northstar2
>>   arm64: dts: NS2: Add USB DRD PHY device tree node
>>
>>  .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   |  30 ++
>>  arch/arm64/boot/dts/broadcom/ns2.dtsi  |  14 +
>>  drivers/phy/Kconfig|  13 +
>>  drivers/phy/Makefile   |   1 +
>>  drivers/phy/phy-bcm-ns2-usbdrd.c   | 437 
>> +
>>  5 files changed, 495 insertions(+)
>>  create mode 100644 
>> Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
>>  create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c
>>


Re: [RFC PATCH linux-next] usb: gadget: udc: start_udc() can be static

2017-06-23 Thread Raviteja Garimella
Looks good to me.

Thanks,
Ravi

On Fri, Jun 23, 2017 at 4:50 PM, kbuild test robot
 wrote:
>
> Signed-off-by: Fengguang Wu 
> ---
>  snps_udc_plat.c |6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/gadget/udc/snps_udc_plat.c 
> b/drivers/usb/gadget/udc/snps_udc_plat.c
> index 2e11f19..f7b4d0f 100644
> --- a/drivers/usb/gadget/udc/snps_udc_plat.c
> +++ b/drivers/usb/gadget/udc/snps_udc_plat.c
> @@ -28,7 +28,7 @@
>  /* description */
>  #define UDC_MOD_DESCRIPTION "Synopsys UDC platform driver"
>
> -void start_udc(struct udc *udc)
> +static void start_udc(struct udc *udc)
>  {
> if (udc->driver) {
> dev_info(udc->dev, "Connecting...\n");
> @@ -38,7 +38,7 @@ void start_udc(struct udc *udc)
> }
>  }
>
> -void stop_udc(struct udc *udc)
> +static void stop_udc(struct udc *udc)
>  {
> int tmp;
> u32 reg;
> @@ -76,7 +76,7 @@ void stop_udc(struct udc *udc)
> dev_info(udc->dev, "Device disconnected\n");
>  }
>
> -void udc_drd_work(struct work_struct *work)
> +static void udc_drd_work(struct work_struct *work)
>  {
> struct udc *udc;
>


[PATCH v6 3/3] arm64: dts: NS2: Add USB DRD PHY device tree node

2017-05-31 Thread Raviteja Garimella
This patch adds device tree node for USB Dual Role Device Phy for
Broadcom's Northstar2 SoC.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 arch/arm64/boot/dts/broadcom/ns2.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm64/boot/dts/broadcom/ns2.dtsi 
b/arch/arm64/boot/dts/broadcom/ns2.dtsi
index 35a309a..35c8457 100644
--- a/arch/arm64/boot/dts/broadcom/ns2.dtsi
+++ b/arch/arm64/boot/dts/broadcom/ns2.dtsi
@@ -460,6 +460,20 @@
};
};
 
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   status = "disabled";
+   };
+
pwm: pwm@6601 {
compatible = "brcm,iproc-pwm";
reg = <0x6601 0x28>;
-- 
2.1.0



[PATCH v6 0/3] Support for USB DRD Phy driver for NS2

2017-05-31 Thread Raviteja Garimella
Changes in v6:
=
Removed spin locks which are not required as the references
to phy_ops in the same driver were removed in v5.

Removed host/device 'notify' routines which are registered
using 'extcon_register_notifier'. The irq handler is sufficient
to deal with the change in extcon events within the same driver.


Changes in v5:
=
Removed references to phy_ops in the same driver by connect_work
event handler to change the phy modes.

To support dynamically changing the mode of the phy, it does
not require doing a phy reset/programming of PHY PLL. Changes
are made to the connect_work routine to just program the required
register bits to achieve this purpose.

Changes in v4:
=
Remove references to edev->name in debug prints.

Changes in v3:
=
Remove unnecessary checks for poweron as suggested in review.

Changes in v2:
=
1. Initialize file operations .owner field with THIS_MODULE.
2. Remove unnecessary gpio example in DT bindings documentation.
   This is previously acked by Rob Herring <r...@kernel.org>

Introduction for PATCH v1:

This patch adds support for USB Dual Role Device Phy for Broadcom
Northstar2 SoC. Apart from the new phy driver, this patchset contains
changes to Kconfig, Makefile, and Device tree files.

This patchset is tested on Broadcom NS2 BCM958712K reference board.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: ns2_drdphy_v6

Raviteja Garimella (3):
  dt-bindings:phy:Add DT bindings documentation for NS2 USB DRD phy
  phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2
  arm64: dts: NS2: Add USB DRD PHY device tree node

 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   |  30 ++
 arch/arm64/boot/dts/broadcom/ns2.dtsi  |  14 +
 drivers/phy/Kconfig|  13 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c   | 466 +
 5 files changed, 524 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

-- 
2.1.0



[PATCH v6 1/3] dt-bindings:phy:Add DT bindings documentation for NS2 USB DRD phy

2017-05-31 Thread Raviteja Garimella
This patch adds documentation for NS2 DRD Phy driver DT bindings

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
Acked-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   | 30 ++
 1 file changed, 30 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt

diff --git a/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt 
b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
new file mode 100644
index 000..04f063a
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
@@ -0,0 +1,30 @@
+BROADCOM NORTHSTAR2 USB2 (DUAL ROLE DEVICE) PHY
+
+Required properties:
+ - compatible: brcm,ns2-drd-phy
+ - reg: offset and length of the NS2 PHY related registers.
+ - reg-names
+   The below registers must be provided.
+   icfg - for DRD ICFG configurations
+   rst-ctrl - for DRD IDM reset
+   crmu-ctrl - for CRMU core vdd, PHY and PHY PLL reset
+   usb2-strap - for port over current polarity reversal
+ - #phy-cells: Must be 0. No args required.
+ - vbus-gpios: vbus gpio binding
+ - id-gpios: id gpio binding
+
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+Example:
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   };
-- 
2.1.0



[PATCH v6 2/3] phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2

2017-05-31 Thread Raviteja Garimella
This is driver for USB DRD Phy used in Broadcom's Northstar2
SoC. The phy can be configured to be in Device mode or Host
mode based on the type of cable connected to the port. The
driver registers to  extcon framework to get appropriate
connect events for Host/Device cables connect/disconnect
states based on VBUS and ID interrupts.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/phy/Kconfig  |  13 ++
 drivers/phy/Makefile |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c | 466 +++
 3 files changed, 480 insertions(+)
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index afaf7b6..8028da7 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -507,6 +507,19 @@ config PHY_CYGNUS_PCIE
  Enable this to support the Broadcom Cygnus PCIe PHY.
  If unsure, say N.
 
+config PHY_NS2_USB_DRD
+   tristate "Broadcom Northstar2 USB DRD PHY support"
+   depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
+   select GENERIC_PHY
+   select EXTCON
+   default ARCH_BCM_IPROC
+   help
+ Enable this to support the Broadcom Northstar2 USB DRD PHY.
+ This driver initializes the PHY in either HOST or DEVICE mode.
+ The host or device configuration is read from device tree.
+
+ If unsure, say N.
+
 source "drivers/phy/tegra/Kconfig"
 
 config PHY_NS2_PCIE
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index f8047b4..e5fbb0e 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_PHY_TUSB1210)+= phy-tusb1210.o
 obj-$(CONFIG_PHY_BRCM_SATA)+= phy-brcm-sata.o
 obj-$(CONFIG_PHY_PISTACHIO_USB)+= phy-pistachio-usb.o
 obj-$(CONFIG_PHY_CYGNUS_PCIE)  += phy-bcm-cygnus-pcie.o
+obj-$(CONFIG_PHY_NS2_USB_DRD)  += phy-bcm-ns2-usbdrd.o
 obj-$(CONFIG_ARCH_TEGRA) += tegra/
 obj-$(CONFIG_PHY_NS2_PCIE) += phy-bcm-ns2-pcie.o
 obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o
diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c b/drivers/phy/phy-bcm-ns2-usbdrd.c
new file mode 100644
index 000..8e05c70
--- /dev/null
+++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
@@ -0,0 +1,466 @@
+/*
+ * Copyright (C) 2017 Broadcom
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ICFG_DRD_AFE   0x0
+#define ICFG_MISC_STAT 0x18
+#define ICFG_DRD_P0CTL 0x1C
+#define ICFG_STRAP_CTRL0x20
+#define ICFG_FSM_CTRL  0x24
+
+#define ICFG_DEV_BIT   BIT(2)
+#define IDM_RST_BITBIT(0)
+#define AFE_CORERDY_VDDC   BIT(18)
+#define PHY_PLL_RESETB BIT(15)
+#define PHY_RESETB BIT(14)
+#define PHY_PLL_LOCK   BIT(0)
+
+#define DRD_DEV_MODE   BIT(20)
+#define OHCI_OVRCUR_POLBIT(11)
+#define ICFG_OFF_MODE  BIT(6)
+#define PLL_LOCK_RETRY 1000
+
+#define EVT_DEVICE 0
+#define EVT_HOST   1
+
+#define DRD_HOST_MODE  (BIT(2) | BIT(3))
+#define DRD_DEVICE_MODE(BIT(4) | BIT(5))
+#define DRD_HOST_VAL   0x803
+#define DRD_DEV_VAL0x807
+#define GPIO_DELAY 20
+
+struct ns2_phy_data;
+struct ns2_phy_driver {
+   void __iomem *icfgdrd_regs;
+   void __iomem *idmdrd_rst_ctrl;
+   void __iomem *crmu_usb2_ctrl;
+   void __iomem *usb2h_strap_reg;
+   struct ns2_phy_data *data;
+   struct extcon_specific_cable_nb extcon_dev;
+   struct extcon_specific_cable_nb extcon_host;
+   struct extcon_dev *edev;
+   struct gpio_desc *vbus_gpiod;
+   struct gpio_desc *id_gpiod;
+   int id_irq;
+   int vbus_irq;
+   unsigned long debounce_jiffies;
+   struct delayed_work wq_extcon;
+};
+
+struct ns2_phy_data {
+   struct ns2_phy_driver *driver;
+   struct phy *phy;
+   int new_state;
+};
+
+static const unsigned int usb_extcon_cable[] = {
+   EXTCON_USB,
+   EXTCON_USB_HOST,
+   EXTCON_NONE,
+};
+
+static inline int pll_lock_stat(u32 usb_reg, int reg_mask,
+   struct ns2_phy_driver *driver)
+{
+   int retry = PLL_LOCK_RETRY;
+   u32 val;
+
+   do {
+   udelay(1);
+   val = readl(driver->i

Re: [RESEND PATCH v5 2/3] phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2

2017-05-31 Thread Raviteja Garimella
Hi Kishon,

On Tue, May 16, 2017 at 6:33 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
> Hi,
>
> On Wednesday 10 May 2017 12:24 PM, Raviteja Garimella wrote:
>> This is driver for USB DRD Phy used in Broadcom's Northstar2
>> SoC. The phy can be configured to be in Device mode or Host
>> mode based on the type of cable connected to the port. The
>> driver registers to  extcon framework to get appropriate
>> connect events for Host/Device cables connect/disconnect
>> states based on VBUS and ID interrupts.
>>
>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>> ---
>>  drivers/phy/Kconfig  |  13 +
>>  drivers/phy/Makefile |   1 +
>>  drivers/phy/phy-bcm-ns2-usbdrd.c | 595 
>> +++
>>  3 files changed, 609 insertions(+)
>>  create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c
>>
>> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
>> index 005cadb..c9de9a9 100644
>> --- a/drivers/phy/Kconfig
>> +++ b/drivers/phy/Kconfig
>> @@ -488,6 +488,19 @@ config PHY_CYGNUS_PCIE
>> Enable this to support the Broadcom Cygnus PCIe PHY.
>> If unsure, say N.
>>
>> +config PHY_NS2_USB_DRD
>> + tristate "Broadcom Northstar2 USB DRD PHY support"
>> + depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
>> + select GENERIC_PHY
>> + select EXTCON
>> + default ARCH_BCM_IPROC
>> + help
>> +   Enable this to support the Broadcom Northstar2 USB DRD PHY.
>> +   This driver initializes the PHY in either HOST or DEVICE mode.
>> +   The host or device configuration is read from device tree.
>> +
>> +   If unsure, say N.
>> +
>>  source "drivers/phy/tegra/Kconfig"
>>
>>  config PHY_NS2_PCIE
>> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
>> index dd8f3b5..9285f88 100644
>> --- a/drivers/phy/Makefile
>> +++ b/drivers/phy/Makefile
>> @@ -59,6 +59,7 @@ obj-$(CONFIG_PHY_TUSB1210)  += phy-tusb1210.o
>>  obj-$(CONFIG_PHY_BRCM_SATA)  += phy-brcm-sata.o
>>  obj-$(CONFIG_PHY_PISTACHIO_USB)  += phy-pistachio-usb.o
>>  obj-$(CONFIG_PHY_CYGNUS_PCIE)+= phy-bcm-cygnus-pcie.o
>> +obj-$(CONFIG_PHY_NS2_USB_DRD)+= phy-bcm-ns2-usbdrd.o
>>  obj-$(CONFIG_ARCH_TEGRA) += tegra/
>>  obj-$(CONFIG_PHY_NS2_PCIE)   += phy-bcm-ns2-pcie.o
>>  obj-$(CONFIG_PHY_MESON8B_USB2)   += phy-meson8b-usb2.o
>> diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c 
>> b/drivers/phy/phy-bcm-ns2-usbdrd.c
>> new file mode 100644
>> index 000..92b68b1
>> --- /dev/null
>> +++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
>> @@ -0,0 +1,595 @@
>> +/*
>> + * Copyright (C) 2016 Broadcom
>> + *
>> + * 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 version 2.
>> + *
>> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
>> + * kind, whether express or implied; without even the implied warranty
>> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define ICFG_DRD_AFE 0x0
>> +#define ICFG_MISC_STAT   0x18
>> +#define ICFG_DRD_P0CTL   0x1C
>> +#define ICFG_STRAP_CTRL  0x20
>> +#define ICFG_FSM_CTRL0x24
>> +
>> +#define ICFG_DEV_BIT BIT(2)
>> +#define IDM_RST_BIT  BIT(0)
>> +#define AFE_CORERDY_VDDC BIT(18)
>> +#define PHY_PLL_RESETB   BIT(15)
>> +#define PHY_RESETB   BIT(14)
>> +#define PHY_PLL_LOCK BIT(0)
>> +
>> +#define DRD_DEV_MODE BIT(20)
>> +#define OHCI_OVRCUR_POL  BIT(11)
>> +#define ICFG_OFF_MODEBIT(6)
>> +#define PLL_LOCK_RETRY   1000
>> +
>> +#define EVT_DEVICE   0
>> +#define EVT_HOST 1
>> +#define EVT_IDLE 2
>> +
>> +#define DRD_HOST_MODE(BIT(2) | BIT(3))
>> +#d

Re: [PATCH v6 2/3] phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2

2017-06-02 Thread Raviteja Garimella
Hi,

On Fri, Jun 2, 2017 at 5:26 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
> Hi,
>
> On Friday 02 June 2017 05:21 PM, Raviteja Garimella wrote:
>> Hi,
>>
>> On Fri, Jun 2, 2017 at 5:18 PM, Raviteja Garimella
>> <raviteja.garime...@broadcom.com> wrote:
>>> Hi Kishon,
>>>
>>> On Fri, Jun 2, 2017 at 3:59 PM, Kishon Vijay Abraham I <kis...@ti.com> 
>>> wrote:
>>>> Hi,
>>>>
>>>> On Wednesday 31 May 2017 03:42 PM, Raviteja Garimella wrote:
>>>>> This is driver for USB DRD Phy used in Broadcom's Northstar2
>>>>> SoC. The phy can be configured to be in Device mode or Host
>>>>> mode based on the type of cable connected to the port. The
>>>>> driver registers to  extcon framework to get appropriate
>>>>> connect events for Host/Device cables connect/disconnect
>>>>> states based on VBUS and ID interrupts.
>>>>>
>>>>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>>>>> ---
>>>>>  drivers/phy/Kconfig  |  13 ++
>>>>>  drivers/phy/Makefile |   1 +
>>>>>  drivers/phy/phy-bcm-ns2-usbdrd.c | 466 
>>>>> +++
>>>>>  3 files changed, 480 insertions(+)
>>>>>  create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c
>>>>>
>>>>> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
>>>>> index afaf7b6..8028da7 100644
>>>>> --- a/drivers/phy/Kconfig
>>>>> +++ b/drivers/phy/Kconfig
>>>>> @@ -507,6 +507,19 @@ config PHY_CYGNUS_PCIE
>>>>> Enable this to support the Broadcom Cygnus PCIe PHY.
>>>>> If unsure, say N.
>>>>>
>>>>> +config PHY_NS2_USB_DRD
>>>>> + tristate "Broadcom Northstar2 USB DRD PHY support"
>>>>> + depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
>>>>> + select GENERIC_PHY
>>>>> + select EXTCON
>>>>> + default ARCH_BCM_IPROC
>>>>> + help
>>>>> +   Enable this to support the Broadcom Northstar2 USB DRD PHY.
>>>>> +   This driver initializes the PHY in either HOST or DEVICE mode.
>>>>> +   The host or device configuration is read from device tree.
>>>>> +
>>>>> +   If unsure, say N.
>>>>> +
>>>>>  source "drivers/phy/tegra/Kconfig"
>>>>>
>>>>>  config PHY_NS2_PCIE
>>>>> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
>>>>> index f8047b4..e5fbb0e 100644
>>>>> --- a/drivers/phy/Makefile
>>>>> +++ b/drivers/phy/Makefile
>>>>> @@ -61,6 +61,7 @@ obj-$(CONFIG_PHY_TUSB1210)  += phy-tusb1210.o
>>>>>  obj-$(CONFIG_PHY_BRCM_SATA)  += phy-brcm-sata.o
>>>>>  obj-$(CONFIG_PHY_PISTACHIO_USB)  += phy-pistachio-usb.o
>>>>>  obj-$(CONFIG_PHY_CYGNUS_PCIE)+= phy-bcm-cygnus-pcie.o
>>>>> +obj-$(CONFIG_PHY_NS2_USB_DRD)+= phy-bcm-ns2-usbdrd.o
>>>>>  obj-$(CONFIG_ARCH_TEGRA) += tegra/
>>>>>  obj-$(CONFIG_PHY_NS2_PCIE)   += phy-bcm-ns2-pcie.o
>>>>>  obj-$(CONFIG_PHY_MESON8B_USB2)   += phy-meson8b-usb2.o
>>>>> diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c 
>>>>> b/drivers/phy/phy-bcm-ns2-usbdrd.c
>>>>> new file mode 100644
>>>>> index 000..8e05c70
>>>>> --- /dev/null
>>>>> +++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
>>>>> @@ -0,0 +1,466 @@
>>>>> +/*
>>>>> + * Copyright (C) 2017 Broadcom
>>>>> + *
>>>>> + * 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 version 2.
>>>>> + *
>>>>> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
>>>>> + * kind, whether express or implied; without even the implied warranty
>>>>> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>>>>> + * GNU General Public License for more details.
>>>>> + */
>>>>> +
>>>>> +#include 
>>>>> +#include 
>>>>&

[PATCH v7 1/3] dt-bindings:phy:Add DT bindings documentation for NS2 USB DRD phy

2017-06-02 Thread Raviteja Garimella
This patch adds documentation for NS2 DRD Phy driver DT bindings

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
Acked-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   | 30 ++
 1 file changed, 30 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt

diff --git a/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt 
b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
new file mode 100644
index 000..04f063a
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
@@ -0,0 +1,30 @@
+BROADCOM NORTHSTAR2 USB2 (DUAL ROLE DEVICE) PHY
+
+Required properties:
+ - compatible: brcm,ns2-drd-phy
+ - reg: offset and length of the NS2 PHY related registers.
+ - reg-names
+   The below registers must be provided.
+   icfg - for DRD ICFG configurations
+   rst-ctrl - for DRD IDM reset
+   crmu-ctrl - for CRMU core vdd, PHY and PHY PLL reset
+   usb2-strap - for port over current polarity reversal
+ - #phy-cells: Must be 0. No args required.
+ - vbus-gpios: vbus gpio binding
+ - id-gpios: id gpio binding
+
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+Example:
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   };
-- 
2.1.0



[PATCH v7 2/3] phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2

2017-06-02 Thread Raviteja Garimella
This is driver for USB DRD Phy used in Broadcom's Northstar2
SoC. The phy can be configured to be in Device mode or Host
mode based on the type of cable connected to the port. The
driver registers to  extcon framework to get appropriate
connect events for Host/Device cables connect/disconnect
states based on VBUS and ID interrupts.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 drivers/phy/Kconfig  |  13 ++
 drivers/phy/Makefile |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c | 450 +++
 3 files changed, 464 insertions(+)
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index afaf7b6..8028da7 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -507,6 +507,19 @@ config PHY_CYGNUS_PCIE
  Enable this to support the Broadcom Cygnus PCIe PHY.
  If unsure, say N.
 
+config PHY_NS2_USB_DRD
+   tristate "Broadcom Northstar2 USB DRD PHY support"
+   depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
+   select GENERIC_PHY
+   select EXTCON
+   default ARCH_BCM_IPROC
+   help
+ Enable this to support the Broadcom Northstar2 USB DRD PHY.
+ This driver initializes the PHY in either HOST or DEVICE mode.
+ The host or device configuration is read from device tree.
+
+ If unsure, say N.
+
 source "drivers/phy/tegra/Kconfig"
 
 config PHY_NS2_PCIE
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index f8047b4..e5fbb0e 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_PHY_TUSB1210)+= phy-tusb1210.o
 obj-$(CONFIG_PHY_BRCM_SATA)+= phy-brcm-sata.o
 obj-$(CONFIG_PHY_PISTACHIO_USB)+= phy-pistachio-usb.o
 obj-$(CONFIG_PHY_CYGNUS_PCIE)  += phy-bcm-cygnus-pcie.o
+obj-$(CONFIG_PHY_NS2_USB_DRD)  += phy-bcm-ns2-usbdrd.o
 obj-$(CONFIG_ARCH_TEGRA) += tegra/
 obj-$(CONFIG_PHY_NS2_PCIE) += phy-bcm-ns2-pcie.o
 obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o
diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c b/drivers/phy/phy-bcm-ns2-usbdrd.c
new file mode 100644
index 000..4a1e181
--- /dev/null
+++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
@@ -0,0 +1,450 @@
+/*
+ * Copyright (C) 2017 Broadcom
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ICFG_DRD_AFE   0x0
+#define ICFG_MISC_STAT 0x18
+#define ICFG_DRD_P0CTL 0x1C
+#define ICFG_STRAP_CTRL0x20
+#define ICFG_FSM_CTRL  0x24
+
+#define ICFG_DEV_BIT   BIT(2)
+#define IDM_RST_BITBIT(0)
+#define AFE_CORERDY_VDDC   BIT(18)
+#define PHY_PLL_RESETB BIT(15)
+#define PHY_RESETB BIT(14)
+#define PHY_PLL_LOCK   BIT(0)
+
+#define DRD_DEV_MODE   BIT(20)
+#define OHCI_OVRCUR_POLBIT(11)
+#define ICFG_OFF_MODE  BIT(6)
+#define PLL_LOCK_RETRY 1000
+
+#define EVT_DEVICE 0
+#define EVT_HOST   1
+
+#define DRD_HOST_MODE  (BIT(2) | BIT(3))
+#define DRD_DEVICE_MODE(BIT(4) | BIT(5))
+#define DRD_HOST_VAL   0x803
+#define DRD_DEV_VAL0x807
+#define GPIO_DELAY 20
+
+struct ns2_phy_data;
+struct ns2_phy_driver {
+   void __iomem *icfgdrd_regs;
+   void __iomem *idmdrd_rst_ctrl;
+   void __iomem *crmu_usb2_ctrl;
+   void __iomem *usb2h_strap_reg;
+   struct ns2_phy_data *data;
+   struct extcon_dev *edev;
+   struct gpio_desc *vbus_gpiod;
+   struct gpio_desc *id_gpiod;
+   int id_irq;
+   int vbus_irq;
+   unsigned long debounce_jiffies;
+   struct delayed_work wq_extcon;
+};
+
+struct ns2_phy_data {
+   struct ns2_phy_driver *driver;
+   struct phy *phy;
+   int new_state;
+};
+
+static const unsigned int usb_extcon_cable[] = {
+   EXTCON_USB,
+   EXTCON_USB_HOST,
+   EXTCON_NONE,
+};
+
+static inline int pll_lock_stat(u32 usb_reg, int reg_mask,
+   struct ns2_phy_driver *driver)
+{
+   int retry = PLL_LOCK_RETRY;
+   u32 val;
+
+   do {
+   udelay(1);
+   val = readl(driver->icfgdrd_regs + usb_reg);
+   if (val & reg_mask)
+   return 0;
+  

[PATCH v7 0/3] Support for USB DRD Phy driver for NS2

2017-06-02 Thread Raviteja Garimella
Changes in v7:
=
Cleaned up unused variables in phy private data structure that's
missed out in v6.
Setting of phy mode to device/host is removed from phy power on.
routine.

Changes in v6:
=
Removed spin locks which are not required as the references
to phy_ops in the same driver were removed in v5.

Removed host/device 'notify' routines which are registered
using 'extcon_register_notifier'. The irq handler is sufficient
to deal with the change in extcon events within the same driver.

Changes in v5:
=
Removed references to phy_ops in the same driver by connect_work
event handler to change the phy modes.

To support dynamically changing the mode of the phy, it does
not require doing a phy reset/programming of PHY PLL. Changes
are made to the connect_work routine to just program the required
register bits to achieve this purpose.

Changes in v4:
=
Remove references to edev->name in debug prints.

Changes in v3:
=
Remove unnecessary checks for poweron as suggested in review.

Changes in v2:
=
1. Initialize file operations .owner field with THIS_MODULE.
2. Remove unnecessary gpio example in DT bindings documentation.
   This is previously acked by Rob Herring <r...@kernel.org>

Introduction for PATCH v1:

This patch adds support for USB Dual Role Device Phy for Broadcom
Northstar2 SoC. Apart from the new phy driver, this patchset contains
changes to Kconfig, Makefile, and Device tree files.

This patchset is tested on Broadcom NS2 BCM958712K reference board.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: ns2_drdphy_v7

*** BLURB HERE ***

Raviteja Garimella (3):
  dt-bindings:phy:Add DT bindings documentation for NS2 USB DRD phy
  phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2
  arm64: dts: NS2: Add USB DRD PHY device tree node

 .../devicetree/bindings/phy/brcm,ns2-drd-phy.txt   |  30 ++
 arch/arm64/boot/dts/broadcom/ns2.dtsi  |  14 +
 drivers/phy/Kconfig|  13 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-bcm-ns2-usbdrd.c   | 450 +
 5 files changed, 508 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,ns2-drd-phy.txt
 create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c

-- 
2.1.0



[PATCH v7 3/3] arm64: dts: NS2: Add USB DRD PHY device tree node

2017-06-02 Thread Raviteja Garimella
This patch adds device tree node for USB Dual Role Device Phy for
Broadcom's Northstar2 SoC.

Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
---
 arch/arm64/boot/dts/broadcom/ns2.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm64/boot/dts/broadcom/ns2.dtsi 
b/arch/arm64/boot/dts/broadcom/ns2.dtsi
index 35a309a..35c8457 100644
--- a/arch/arm64/boot/dts/broadcom/ns2.dtsi
+++ b/arch/arm64/boot/dts/broadcom/ns2.dtsi
@@ -460,6 +460,20 @@
};
};
 
+   usbdrd_phy: phy@66000960 {
+   #phy-cells = <0>;
+   compatible = "brcm,ns2-drd-phy";
+   reg = <0x66000960 0x24>,
+ <0x67012800 0x4>,
+ <0x6501d148 0x4>,
+ <0x664d0700 0x4>;
+   reg-names = "icfg", "rst-ctrl",
+   "crmu-ctrl", "usb2-strap";
+   id-gpios = <_g 30 0>;
+   vbus-gpios = <_g 31 0>;
+   status = "disabled";
+   };
+
pwm: pwm@6601 {
compatible = "brcm,iproc-pwm";
reg = <0x6601 0x28>;
-- 
2.1.0



Re: [PATCH v6 2/3] phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2

2017-06-02 Thread Raviteja Garimella
Hi Kishon,

On Fri, Jun 2, 2017 at 3:59 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
> Hi,
>
> On Wednesday 31 May 2017 03:42 PM, Raviteja Garimella wrote:
>> This is driver for USB DRD Phy used in Broadcom's Northstar2
>> SoC. The phy can be configured to be in Device mode or Host
>> mode based on the type of cable connected to the port. The
>> driver registers to  extcon framework to get appropriate
>> connect events for Host/Device cables connect/disconnect
>> states based on VBUS and ID interrupts.
>>
>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>> ---
>>  drivers/phy/Kconfig  |  13 ++
>>  drivers/phy/Makefile |   1 +
>>  drivers/phy/phy-bcm-ns2-usbdrd.c | 466 
>> +++
>>  3 files changed, 480 insertions(+)
>>  create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c
>>
>> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
>> index afaf7b6..8028da7 100644
>> --- a/drivers/phy/Kconfig
>> +++ b/drivers/phy/Kconfig
>> @@ -507,6 +507,19 @@ config PHY_CYGNUS_PCIE
>> Enable this to support the Broadcom Cygnus PCIe PHY.
>> If unsure, say N.
>>
>> +config PHY_NS2_USB_DRD
>> + tristate "Broadcom Northstar2 USB DRD PHY support"
>> + depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
>> + select GENERIC_PHY
>> + select EXTCON
>> + default ARCH_BCM_IPROC
>> + help
>> +   Enable this to support the Broadcom Northstar2 USB DRD PHY.
>> +   This driver initializes the PHY in either HOST or DEVICE mode.
>> +   The host or device configuration is read from device tree.
>> +
>> +   If unsure, say N.
>> +
>>  source "drivers/phy/tegra/Kconfig"
>>
>>  config PHY_NS2_PCIE
>> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
>> index f8047b4..e5fbb0e 100644
>> --- a/drivers/phy/Makefile
>> +++ b/drivers/phy/Makefile
>> @@ -61,6 +61,7 @@ obj-$(CONFIG_PHY_TUSB1210)  += phy-tusb1210.o
>>  obj-$(CONFIG_PHY_BRCM_SATA)  += phy-brcm-sata.o
>>  obj-$(CONFIG_PHY_PISTACHIO_USB)  += phy-pistachio-usb.o
>>  obj-$(CONFIG_PHY_CYGNUS_PCIE)+= phy-bcm-cygnus-pcie.o
>> +obj-$(CONFIG_PHY_NS2_USB_DRD)+= phy-bcm-ns2-usbdrd.o
>>  obj-$(CONFIG_ARCH_TEGRA) += tegra/
>>  obj-$(CONFIG_PHY_NS2_PCIE)   += phy-bcm-ns2-pcie.o
>>  obj-$(CONFIG_PHY_MESON8B_USB2)   += phy-meson8b-usb2.o
>> diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c 
>> b/drivers/phy/phy-bcm-ns2-usbdrd.c
>> new file mode 100644
>> index 000..8e05c70
>> --- /dev/null
>> +++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
>> @@ -0,0 +1,466 @@
>> +/*
>> + * Copyright (C) 2017 Broadcom
>> + *
>> + * 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 version 2.
>> + *
>> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
>> + * kind, whether express or implied; without even the implied warranty
>> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define ICFG_DRD_AFE 0x0
>> +#define ICFG_MISC_STAT   0x18
>> +#define ICFG_DRD_P0CTL   0x1C
>> +#define ICFG_STRAP_CTRL  0x20
>> +#define ICFG_FSM_CTRL0x24
>> +
>> +#define ICFG_DEV_BIT BIT(2)
>> +#define IDM_RST_BIT  BIT(0)
>> +#define AFE_CORERDY_VDDC BIT(18)
>> +#define PHY_PLL_RESETB   BIT(15)
>> +#define PHY_RESETB   BIT(14)
>> +#define PHY_PLL_LOCK BIT(0)
>> +
>> +#define DRD_DEV_MODE BIT(20)
>> +#define OHCI_OVRCUR_POL  BIT(11)
>> +#define ICFG_OFF_MODEBIT(6)
>> +#define PLL_LOCK_RETRY   1000
>> +
>> +#define EVT_DEVICE   0
>> +#define EVT_HOST 1
>> +
>> +#define DRD_HOST_MODE(BIT(2) | BIT(3))
>> +#define DRD_DEVICE_MODE  (BIT(4) |

Re: [PATCH v6 2/3] phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2

2017-06-02 Thread Raviteja Garimella
Hi,

On Fri, Jun 2, 2017 at 5:18 PM, Raviteja Garimella
<raviteja.garime...@broadcom.com> wrote:
> Hi Kishon,
>
> On Fri, Jun 2, 2017 at 3:59 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
>> Hi,
>>
>> On Wednesday 31 May 2017 03:42 PM, Raviteja Garimella wrote:
>>> This is driver for USB DRD Phy used in Broadcom's Northstar2
>>> SoC. The phy can be configured to be in Device mode or Host
>>> mode based on the type of cable connected to the port. The
>>> driver registers to  extcon framework to get appropriate
>>> connect events for Host/Device cables connect/disconnect
>>> states based on VBUS and ID interrupts.
>>>
>>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>>> ---
>>>  drivers/phy/Kconfig  |  13 ++
>>>  drivers/phy/Makefile |   1 +
>>>  drivers/phy/phy-bcm-ns2-usbdrd.c | 466 
>>> +++
>>>  3 files changed, 480 insertions(+)
>>>  create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c
>>>
>>> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
>>> index afaf7b6..8028da7 100644
>>> --- a/drivers/phy/Kconfig
>>> +++ b/drivers/phy/Kconfig
>>> @@ -507,6 +507,19 @@ config PHY_CYGNUS_PCIE
>>> Enable this to support the Broadcom Cygnus PCIe PHY.
>>> If unsure, say N.
>>>
>>> +config PHY_NS2_USB_DRD
>>> + tristate "Broadcom Northstar2 USB DRD PHY support"
>>> + depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
>>> + select GENERIC_PHY
>>> + select EXTCON
>>> + default ARCH_BCM_IPROC
>>> + help
>>> +   Enable this to support the Broadcom Northstar2 USB DRD PHY.
>>> +   This driver initializes the PHY in either HOST or DEVICE mode.
>>> +   The host or device configuration is read from device tree.
>>> +
>>> +   If unsure, say N.
>>> +
>>>  source "drivers/phy/tegra/Kconfig"
>>>
>>>  config PHY_NS2_PCIE
>>> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
>>> index f8047b4..e5fbb0e 100644
>>> --- a/drivers/phy/Makefile
>>> +++ b/drivers/phy/Makefile
>>> @@ -61,6 +61,7 @@ obj-$(CONFIG_PHY_TUSB1210)  += phy-tusb1210.o
>>>  obj-$(CONFIG_PHY_BRCM_SATA)  += phy-brcm-sata.o
>>>  obj-$(CONFIG_PHY_PISTACHIO_USB)  += phy-pistachio-usb.o
>>>  obj-$(CONFIG_PHY_CYGNUS_PCIE)+= phy-bcm-cygnus-pcie.o
>>> +obj-$(CONFIG_PHY_NS2_USB_DRD)+= phy-bcm-ns2-usbdrd.o
>>>  obj-$(CONFIG_ARCH_TEGRA) += tegra/
>>>  obj-$(CONFIG_PHY_NS2_PCIE)   += phy-bcm-ns2-pcie.o
>>>  obj-$(CONFIG_PHY_MESON8B_USB2)   += phy-meson8b-usb2.o
>>> diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c 
>>> b/drivers/phy/phy-bcm-ns2-usbdrd.c
>>> new file mode 100644
>>> index 000..8e05c70
>>> --- /dev/null
>>> +++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
>>> @@ -0,0 +1,466 @@
>>> +/*
>>> + * Copyright (C) 2017 Broadcom
>>> + *
>>> + * 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 version 2.
>>> + *
>>> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
>>> + * kind, whether express or implied; without even the implied warranty
>>> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>>> + * GNU General Public License for more details.
>>> + */
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +#define ICFG_DRD_AFE 0x0
>>> +#define ICFG_MISC_STAT   0x18
>>> +#define ICFG_DRD_P0CTL   0x1C
>>> +#define ICFG_STRAP_CTRL  0x20
>>> +#define ICFG_FSM_CTRL0x24
>>> +
>>> +#define ICFG_DEV_BIT BIT(2)
>>> +#define IDM_RST_BIT  BIT(0)
>>> +#define AFE_CORERDY_VDDC BIT(18)
>>> +#define PHY_PLL_RESETB   BIT(15)
>>&

Re: [PATCH v7 2/3] phy:phy-bcm-ns2-usbdrd:Broadcom USB DRD Phy driver for Northstar2

2017-06-08 Thread Raviteja Garimella
Hi Kishon,

On Wed, Jun 7, 2017 at 7:08 PM, Kishon Vijay Abraham I <kis...@ti.com> wrote:
> Hi,
>
> On Friday 02 June 2017 06:30 PM, Raviteja Garimella wrote:
>> This is driver for USB DRD Phy used in Broadcom's Northstar2
>> SoC. The phy can be configured to be in Device mode or Host
>> mode based on the type of cable connected to the port. The
>> driver registers to  extcon framework to get appropriate
>> connect events for Host/Device cables connect/disconnect
>> states based on VBUS and ID interrupts.
>>
>> Signed-off-by: Raviteja Garimella <raviteja.garime...@broadcom.com>
>> ---
>>  drivers/phy/Kconfig  |  13 ++
>>  drivers/phy/Makefile |   1 +
>>  drivers/phy/phy-bcm-ns2-usbdrd.c | 450 
>> +++
>>  3 files changed, 464 insertions(+)
>>  create mode 100644 drivers/phy/phy-bcm-ns2-usbdrd.c
>>
>> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
>> index afaf7b6..8028da7 100644
>> --- a/drivers/phy/Kconfig
>> +++ b/drivers/phy/Kconfig
>> @@ -507,6 +507,19 @@ config PHY_CYGNUS_PCIE
>> Enable this to support the Broadcom Cygnus PCIe PHY.
>> If unsure, say N.
>>
>> +config PHY_NS2_USB_DRD
>> + tristate "Broadcom Northstar2 USB DRD PHY support"
>> + depends on OF && (ARCH_BCM_IPROC || COMPILE_TEST)
>> + select GENERIC_PHY
>> + select EXTCON
>> + default ARCH_BCM_IPROC
>> + help
>> +   Enable this to support the Broadcom Northstar2 USB DRD PHY.
>> +   This driver initializes the PHY in either HOST or DEVICE mode.
>> +   The host or device configuration is read from device tree.
>> +
>> +   If unsure, say N.
>> +
>>  source "drivers/phy/tegra/Kconfig"
>>
>>  config PHY_NS2_PCIE
>> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
>> index f8047b4..e5fbb0e 100644
>> --- a/drivers/phy/Makefile
>> +++ b/drivers/phy/Makefile
>> @@ -61,6 +61,7 @@ obj-$(CONFIG_PHY_TUSB1210)  += phy-tusb1210.o
>>  obj-$(CONFIG_PHY_BRCM_SATA)  += phy-brcm-sata.o
>>  obj-$(CONFIG_PHY_PISTACHIO_USB)  += phy-pistachio-usb.o
>>  obj-$(CONFIG_PHY_CYGNUS_PCIE)+= phy-bcm-cygnus-pcie.o
>> +obj-$(CONFIG_PHY_NS2_USB_DRD)+= phy-bcm-ns2-usbdrd.o
>>  obj-$(CONFIG_ARCH_TEGRA) += tegra/
>>  obj-$(CONFIG_PHY_NS2_PCIE)   += phy-bcm-ns2-pcie.o
>>  obj-$(CONFIG_PHY_MESON8B_USB2)   += phy-meson8b-usb2.o
>> diff --git a/drivers/phy/phy-bcm-ns2-usbdrd.c 
>> b/drivers/phy/phy-bcm-ns2-usbdrd.c
>> new file mode 100644
>> index 000..4a1e181
>> --- /dev/null
>> +++ b/drivers/phy/phy-bcm-ns2-usbdrd.c
>> @@ -0,0 +1,450 @@
>> +/*
>> + * Copyright (C) 2017 Broadcom
>> + *
>> + * 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 version 2.
>> + *
>> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
>> + * kind, whether express or implied; without even the implied warranty
>> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define ICFG_DRD_AFE 0x0
>> +#define ICFG_MISC_STAT   0x18
>> +#define ICFG_DRD_P0CTL   0x1C
>> +#define ICFG_STRAP_CTRL  0x20
>> +#define ICFG_FSM_CTRL0x24
>> +
>> +#define ICFG_DEV_BIT BIT(2)
>> +#define IDM_RST_BIT  BIT(0)
>> +#define AFE_CORERDY_VDDC BIT(18)
>> +#define PHY_PLL_RESETB   BIT(15)
>> +#define PHY_RESETB   BIT(14)
>> +#define PHY_PLL_LOCK BIT(0)
>> +
>> +#define DRD_DEV_MODE BIT(20)
>> +#define OHCI_OVRCUR_POL  BIT(11)
>> +#define ICFG_OFF_MODEBIT(6)
>> +#define PLL_LOCK_RETRY   1000
>> +
>> +#define EVT_DEVICE   0
>> +#define EVT_HOST 1
>> +
>> +#define DRD_HOST_MODE(BIT(2) | BIT(3))
>> +#define DRD_DEVICE_MODE  (BIT(4

  1   2   3   >