Re: [PATCH v5 1/2] phy: Add new Exynos5 USB 3.0 PHY driver

2014-04-27 Thread Vivek Gautam
Hi Tomasz,


On Sat, Apr 26, 2014 at 4:33 AM, Tomasz Figa tomasz.f...@gmail.com wrote:
 Hi Vivek,


 On 22.04.2014 10:03, Vivek Gautam wrote:

 Add a new driver for the USB 3.0 PHY on Exynos5 series of SoCs.
 The new driver uses the generic PHY framework and will interact
 with DWC3 controller present on Exynos5 series of SoCs.
 Thereby, removing old phy-samsung-usb3 driver and related code
 used untill now which was based on usb/phy framework.

 Signed-off-by: Vivek Gautam gautam.vi...@samsung.com
 ---
   .../devicetree/bindings/phy/samsung-phy.txt|   40 ++
   drivers/phy/Kconfig|   11 +
   drivers/phy/Makefile   |1 +
   drivers/phy/phy-exynos5-usbdrd.c   |  629
 
   4 files changed, 681 insertions(+)
   create mode 100644 drivers/phy/phy-exynos5-usbdrd.c

 diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt
 b/Documentation/devicetree/bindings/phy/samsung-phy.txt
 index b422e38..51efe4c 100644
 --- a/Documentation/devicetree/bindings/phy/samsung-phy.txt
 +++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt
 @@ -114,3 +114,43 @@ Example:
 compatible = samsung,exynos-sataphy-i2c;
 reg = 0x38;
 };
 +
 +Samsung Exynos5 SoC series USB DRD PHY controller

[snip]

 diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
 index 3bb05f1..8a5d2b4 100644
 --- a/drivers/phy/Kconfig
 +++ b/drivers/phy/Kconfig
 @@ -166,4 +166,15 @@ config PHY_XGENE
 help
   This option enables support for APM X-Gene SoC multi-purpose
 PHY.

 +config PHY_EXYNOS5_USBDRD
 +   tristate Exynos5 SoC series USB DRD PHY driver
 +   depends on ARCH_EXYNOS5  OF
 +   depends on HAS_IOMEM
 +   select GENERIC_PHY
 +   select MFD_SYSCON
 +   help
 + Enable USB DRD PHY support for Exynos 5 SoC series.
 + This driver provides PHY interface for USB 3.0 DRD controller
 + present on Exynos5 SoC series.
 +


 I think you should probably keep the entries sorted, so this one should be
 somewhere around other EXYNOS PHYs.

Right, thanks for pointing this out.
Will move this along with other PHY_EXYNOS USB* configs.



   endmenu
 diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
 index 2faf78e..31baa0c 100644
 --- a/drivers/phy/Makefile
 +++ b/drivers/phy/Makefile
 @@ -18,3 +18,4 @@ obj-$(CONFIG_PHY_EXYNOS4210_USB2) +=
 phy-exynos4210-usb2.o
   obj-$(CONFIG_PHY_EXYNOS4X12_USB2) += phy-exynos4x12-usb2.o
   obj-$(CONFIG_PHY_EXYNOS5250_USB2) += phy-exynos5250-usb2.o
   obj-$(CONFIG_PHY_XGENE)   += phy-xgene.o
 +obj-$(CONFIG_PHY_EXYNOS5_USBDRD)   += phy-exynos5-usbdrd.o


 Ditto.

Ok



 diff --git a/drivers/phy/phy-exynos5-usbdrd.c
 b/drivers/phy/phy-exynos5-usbdrd.c
 new file mode 100644
 index 000..89d7ae8
 --- /dev/null
 +++ b/drivers/phy/phy-exynos5-usbdrd.c
 @@ -0,0 +1,629 @@
 +/*
 + * Samsung EXYNOS5 SoC series USB DRD PHY driver
 + *
 + * Phy provider for USB 3.0 DRD controller on Exynos5 SoC series
 + *
 + * Copyright (C) 2014 Samsung Electronics Co., Ltd.
 + * Author: Vivek Gautam gautam.vi...@samsung.com
 + *

[snip]

 +   } phys[EXYNOS5_DRDPHYS_NUM];
 +   unsigned int extrefclk;
 +   struct clk *ref_clk;
 +   unsigned long ref_rate;
 +};
 +
 +#define to_usbdrd_phy(inst) \
 +   container_of((inst), struct exynos5_usbdrd_phy, \
 +phys[(inst)-index]);


 This should be made a static inline to enforce type checking.

Ok, will make this as static inline routine, so that compiler don't
skip type checking.



 +
 +/*
 + * exynos5_rate_to_clk() converts the supplied clock rate to the value
 that
 + * can be written to the phy register.
 + */
 +static unsigned int exynos5_rate_to_clk(unsigned long rate)
 +{
 +   unsigned int clksel;
 +
 +   /* EXYNOS5_FSEL_MASK */
 +
 +   switch (rate) {
 +   case 9600 * KHZ:
 +   clksel = EXYNOS5_FSEL_9MHZ6;
 +   break;
 +   case 10 * MHZ:
 +   clksel = EXYNOS5_FSEL_10MHZ;
 +   break;
 +   case 12 * MHZ:
 +   clksel = EXYNOS5_FSEL_12MHZ;
 +   break;
 +   case 19200 * KHZ:
 +   clksel = EXYNOS5_FSEL_19MHZ2;
 +   break;
 +   case 20 * MHZ:
 +   clksel = EXYNOS5_FSEL_20MHZ;
 +   break;
 +   case 24 * MHZ:
 +   clksel = EXYNOS5_FSEL_24MHZ;
 +   break;
 +   case 50 * MHZ:
 +   clksel = EXYNOS5_FSEL_50MHZ;
 +   break;
 +   default:
 +   clksel = -EINVAL;


 Based on clksel (and return value of this function) being unsigned I don't
 think this is a good idea. You should probably adapt the approach from
 Exynos USB 2 PHY, where a function like this return an integer status code
 and returns the bitfield value through a pointer passed as another argument.

Right, will amend this as suggested.



 + 

Re: [PATCH v5 1/2] phy: Add new Exynos5 USB 3.0 PHY driver

2014-04-25 Thread Tomasz Figa

Hi Vivek,

On 22.04.2014 10:03, Vivek Gautam wrote:

Add a new driver for the USB 3.0 PHY on Exynos5 series of SoCs.
The new driver uses the generic PHY framework and will interact
with DWC3 controller present on Exynos5 series of SoCs.
Thereby, removing old phy-samsung-usb3 driver and related code
used untill now which was based on usb/phy framework.

Signed-off-by: Vivek Gautam gautam.vi...@samsung.com
---
  .../devicetree/bindings/phy/samsung-phy.txt|   40 ++
  drivers/phy/Kconfig|   11 +
  drivers/phy/Makefile   |1 +
  drivers/phy/phy-exynos5-usbdrd.c   |  629 
  4 files changed, 681 insertions(+)
  create mode 100644 drivers/phy/phy-exynos5-usbdrd.c

diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt 
b/Documentation/devicetree/bindings/phy/samsung-phy.txt
index b422e38..51efe4c 100644
--- a/Documentation/devicetree/bindings/phy/samsung-phy.txt
+++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt
@@ -114,3 +114,43 @@ Example:
compatible = samsung,exynos-sataphy-i2c;
reg = 0x38;
};
+
+Samsung Exynos5 SoC series USB DRD PHY controller
+--
+
+Required properties:
+- compatible : Should be set to one of the following supported values:
+   - samsung,exynos5250-usbdrd-phy - for exynos5250 SoC,
+   - samsung,exynos5420-usbdrd-phy - for exynos5420 SoC.
+- reg : Register offset and length of USB DRD PHY register set;
+- clocks: Clock IDs array as required by the controller
+- clock-names: names of clocks correseponding to IDs in the clock property;
+  Required clocks:
+   - phy: main PHY clock (same as USB DRD controller i.e. DWC3 IP clock),
+  used for register access.
+   - ref: PHY's reference clock (usually crystal clock), used for
+  PHY operations, associated by phy name. It is used to
+  determine bit values for clock settings register.
+  For Exynos5420 this is given as 'sclk_usbphy30' in CMU.
+- samsung,pmu-syscon: phandle for PMU system controller interface, used to
+ control pmu registers for power isolation.
+- samsung,pmu-offset: phy power control register offset to 
pmu-system-controller
+ base.
+- #phy-cells : from the generic PHY bindings, must be 1;
+
+For samsung,exynos5250-usbdrd-phy and samsung,exynos5420-usbdrd-phy
+compatible PHYs, the second cell in the PHY specifier identifies the
+PHY id, which is interpreted as follows:
+  0 - UTMI+ type phy,
+  1 - PIPE3 type phy,
+
+Example:
+   usb3_phy: usbphy@1210 {
+   compatible = samsung,exynos5250-usbdrd-phy;
+   reg = 0x1210 0x100;
+   clocks = clock 286, clock 1;
+   clock-names = phy, ref;
+   samsung,pmu-syscon = pmu_system_controller;
+   samsung,pmu-offset = 0x704;
+   #phy-cells = 1;
+   };
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 3bb05f1..8a5d2b4 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -166,4 +166,15 @@ config PHY_XGENE
help
  This option enables support for APM X-Gene SoC multi-purpose PHY.

+config PHY_EXYNOS5_USBDRD
+   tristate Exynos5 SoC series USB DRD PHY driver
+   depends on ARCH_EXYNOS5  OF
+   depends on HAS_IOMEM
+   select GENERIC_PHY
+   select MFD_SYSCON
+   help
+ Enable USB DRD PHY support for Exynos 5 SoC series.
+ This driver provides PHY interface for USB 3.0 DRD controller
+ present on Exynos5 SoC series.
+


I think you should probably keep the entries sorted, so this one should 
be somewhere around other EXYNOS PHYs.



  endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 2faf78e..31baa0c 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -18,3 +18,4 @@ obj-$(CONFIG_PHY_EXYNOS4210_USB2) += phy-exynos4210-usb2.o
  obj-$(CONFIG_PHY_EXYNOS4X12_USB2) += phy-exynos4x12-usb2.o
  obj-$(CONFIG_PHY_EXYNOS5250_USB2) += phy-exynos5250-usb2.o
  obj-$(CONFIG_PHY_XGENE)   += phy-xgene.o
+obj-$(CONFIG_PHY_EXYNOS5_USBDRD)   += phy-exynos5-usbdrd.o


Ditto.


diff --git a/drivers/phy/phy-exynos5-usbdrd.c b/drivers/phy/phy-exynos5-usbdrd.c
new file mode 100644
index 000..89d7ae8
--- /dev/null
+++ b/drivers/phy/phy-exynos5-usbdrd.c
@@ -0,0 +1,629 @@
+/*
+ * Samsung EXYNOS5 SoC series USB DRD PHY driver
+ *
+ * Phy provider for USB 3.0 DRD controller on Exynos5 SoC series
+ *
+ * Copyright (C) 2014 Samsung Electronics Co., Ltd.
+ * Author: Vivek Gautam gautam.vi...@samsung.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/clk.h
+#include linux/delay.h

[PATCH v5 1/2] phy: Add new Exynos5 USB 3.0 PHY driver

2014-04-22 Thread Vivek Gautam
Add a new driver for the USB 3.0 PHY on Exynos5 series of SoCs.
The new driver uses the generic PHY framework and will interact
with DWC3 controller present on Exynos5 series of SoCs.
Thereby, removing old phy-samsung-usb3 driver and related code
used untill now which was based on usb/phy framework.

Signed-off-by: Vivek Gautam gautam.vi...@samsung.com
---
 .../devicetree/bindings/phy/samsung-phy.txt|   40 ++
 drivers/phy/Kconfig|   11 +
 drivers/phy/Makefile   |1 +
 drivers/phy/phy-exynos5-usbdrd.c   |  629 
 4 files changed, 681 insertions(+)
 create mode 100644 drivers/phy/phy-exynos5-usbdrd.c

diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt 
b/Documentation/devicetree/bindings/phy/samsung-phy.txt
index b422e38..51efe4c 100644
--- a/Documentation/devicetree/bindings/phy/samsung-phy.txt
+++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt
@@ -114,3 +114,43 @@ Example:
compatible = samsung,exynos-sataphy-i2c;
reg = 0x38;
};
+
+Samsung Exynos5 SoC series USB DRD PHY controller
+--
+
+Required properties:
+- compatible : Should be set to one of the following supported values:
+   - samsung,exynos5250-usbdrd-phy - for exynos5250 SoC,
+   - samsung,exynos5420-usbdrd-phy - for exynos5420 SoC.
+- reg : Register offset and length of USB DRD PHY register set;
+- clocks: Clock IDs array as required by the controller
+- clock-names: names of clocks correseponding to IDs in the clock property;
+  Required clocks:
+   - phy: main PHY clock (same as USB DRD controller i.e. DWC3 IP clock),
+  used for register access.
+   - ref: PHY's reference clock (usually crystal clock), used for
+  PHY operations, associated by phy name. It is used to
+  determine bit values for clock settings register.
+  For Exynos5420 this is given as 'sclk_usbphy30' in CMU.
+- samsung,pmu-syscon: phandle for PMU system controller interface, used to
+ control pmu registers for power isolation.
+- samsung,pmu-offset: phy power control register offset to 
pmu-system-controller
+ base.
+- #phy-cells : from the generic PHY bindings, must be 1;
+
+For samsung,exynos5250-usbdrd-phy and samsung,exynos5420-usbdrd-phy
+compatible PHYs, the second cell in the PHY specifier identifies the
+PHY id, which is interpreted as follows:
+  0 - UTMI+ type phy,
+  1 - PIPE3 type phy,
+
+Example:
+   usb3_phy: usbphy@1210 {
+   compatible = samsung,exynos5250-usbdrd-phy;
+   reg = 0x1210 0x100;
+   clocks = clock 286, clock 1;
+   clock-names = phy, ref;
+   samsung,pmu-syscon = pmu_system_controller;
+   samsung,pmu-offset = 0x704;
+   #phy-cells = 1;
+   };
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 3bb05f1..8a5d2b4 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -166,4 +166,15 @@ config PHY_XGENE
help
  This option enables support for APM X-Gene SoC multi-purpose PHY.
 
+config PHY_EXYNOS5_USBDRD
+   tristate Exynos5 SoC series USB DRD PHY driver
+   depends on ARCH_EXYNOS5  OF
+   depends on HAS_IOMEM
+   select GENERIC_PHY
+   select MFD_SYSCON
+   help
+ Enable USB DRD PHY support for Exynos 5 SoC series.
+ This driver provides PHY interface for USB 3.0 DRD controller
+ present on Exynos5 SoC series.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 2faf78e..31baa0c 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -18,3 +18,4 @@ obj-$(CONFIG_PHY_EXYNOS4210_USB2) += phy-exynos4210-usb2.o
 obj-$(CONFIG_PHY_EXYNOS4X12_USB2)  += phy-exynos4x12-usb2.o
 obj-$(CONFIG_PHY_EXYNOS5250_USB2)  += phy-exynos5250-usb2.o
 obj-$(CONFIG_PHY_XGENE)+= phy-xgene.o
+obj-$(CONFIG_PHY_EXYNOS5_USBDRD)   += phy-exynos5-usbdrd.o
diff --git a/drivers/phy/phy-exynos5-usbdrd.c b/drivers/phy/phy-exynos5-usbdrd.c
new file mode 100644
index 000..89d7ae8
--- /dev/null
+++ b/drivers/phy/phy-exynos5-usbdrd.c
@@ -0,0 +1,629 @@
+/*
+ * Samsung EXYNOS5 SoC series USB DRD PHY driver
+ *
+ * Phy provider for USB 3.0 DRD controller on Exynos5 SoC series
+ *
+ * Copyright (C) 2014 Samsung Electronics Co., Ltd.
+ * Author: Vivek Gautam gautam.vi...@samsung.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/clk.h
+#include linux/delay.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/of.h
+#include linux/of_address.h
+#include linux/phy/phy.h
+#include linux/platform_device.h
+#include